Java Code Examples for com.haulmont.cuba.security.entity.User#setLogin()
The following examples show how to use
com.haulmont.cuba.security.entity.User#setLogin() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BeforeCommitTransactionListenerTest.java From cuba with Apache License 2.0 | 6 votes |
@Test public void testQueryWithFlush() throws Exception { User u1 = metadata.create(User.class); u1.setLogin("TxLstnrTst-2-" + u1.getId()); u1.setGroup(companyGroup); TestBeforeCommitTxListener.test = "testQueryWithFlush"; try (Transaction tx = persistence.createTransaction()) { persistence.getEntityManager().persist(u1); tx.commit(); } finally { TestBeforeCommitTxListener.test = null; } try (Transaction tx = persistence.createTransaction()) { User user = persistence.getEntityManager().find(User.class, u1.getId()); assertEquals(u1, user); } }
Example 2
Source File: EclipseLinkDetachedTest.java From cuba with Apache License 2.0 | 6 votes |
@BeforeEach public void setUp() throws Exception { Transaction tx = cont.persistence().createTransaction(); try { EntityManager em = cont.persistence().getEntityManager(); User user = new User(); userId = user.getId(); user.setName("testUser"); user.setLogin("testLogin"); user.setPosition("manager"); user.setGroup(em.find(Group.class, UUID.fromString("0fa2b1a5-1d68-4d69-9fbd-dff348347f93"))); em.persist(user); UserRole userRole = new UserRole(); userRoleId = userRole.getId(); userRole.setUser(user); userRole.setRoleName("test-role"); em.persist(userRole); tx.commit(); } finally { tx.end(); } }
Example 3
Source File: HsqlLikeNullFailTest.java From cuba with Apache License 2.0 | 6 votes |
@BeforeEach public void setUp() throws Exception { DataManager dataManager = AppBeans.get(DataManager.NAME); Group group = dataManager.load(new LoadContext<>(Group.class) .setId(UUID.fromString("0fa2b1a5-1d68-4d69-9fbd-dff348347f93"))); User user = new User(); user.setGroup(group); user.setId(UUID.fromString("de0f39d2-e60a-11e1-9b55-3860770d7eaf")); user.setName("Test"); user.setLogin("tEst"); user.setLoginLowerCase("test"); dataManager.commit(user); }
Example 4
Source File: EntityManagerTest.java From cuba with Apache License 2.0 | 6 votes |
@Test public void testMerge() throws Exception { UUID newUserId = UUID.randomUUID(); Transaction tx = cont.persistence().createTransaction(); try { EntityManager em = cont.persistence().getEntityManager(); User user = new User(); user.setId(newUserId); user.setName("testMerge"); user.setLogin("testMerge"); user.setPassword("testMerge"); user.setGroup(em.getReference(Group.class, groupId)); user = em.merge(user); User userFromPersistentContext = em.find(User.class, newUserId); assertEquals(user, userFromPersistentContext); tx.commit(); } finally { tx.end(); cont.deleteRecord("SEC_USER", newUserId); } }
Example 5
Source File: PersistenceTest.java From cuba with Apache License 2.0 | 6 votes |
@BeforeEach public void setUp() throws Exception { QueryRunner runner = new QueryRunner(cont.persistence().getDataSource()); runner.update("delete from SYS_SERVER"); Transaction tx = cont.persistence().createTransaction(); try { EntityManager em = cont.persistence().getEntityManager(); User user = new User(); userId = user.getId(); user.setName("testUser"); user.setLogin("testLogin"); user.setGroup(em.find(Group.class, UUID.fromString("0fa2b1a5-1d68-4d69-9fbd-dff348347f93"))); em.persist(user); tx.commit(); } finally { tx.end(); } }
Example 6
Source File: BeforeCommitTransactionListenerTest.java From cuba with Apache License 2.0 | 6 votes |
@Test public void testCreateEntity() throws Exception { User u = metadata.create(User.class); u.setLogin("u-" + u.getId()); u.setGroup(companyGroup); TestBeforeCommitTxListener.test = "testCreateEntity"; try (Transaction tx = persistence.createTransaction()) { persistence.getEntityManager().persist(u); tx.commit(); } finally { TestBeforeCommitTxListener.test = null; } try (Transaction tx = persistence.createTransaction()) { User user = persistence.getEntityManager().find(User.class, TestBeforeCommitTxListener.createdEntityId); assertNotNull(user); } }
Example 7
Source File: PickerFieldTest.java From cuba with Apache License 2.0 | 6 votes |
@Test public void testSetToReadonlyFromValueListener() { final PickerField component = uiComponents.create(PickerField.class); component.setMetaClass(metadata.getClass(User.class)); assertTrue(component.isEditable()); component.addValueChangeListener(e -> component.setEditable(false)); User user = new User(); user.setLogin("admin"); component.setValue(user); assertEquals(user, component.getValue()); assertFalse(component.isEditable()); }
Example 8
Source File: PickerFieldTest.java From cuba with Apache License 2.0 | 6 votes |
@Test public void testGetSetValue() { PickerField component = uiComponents.create(PickerField.class); assertNull(component.getValue()); boolean thrown = false; try { component.setValue("One"); } catch (ClassCastException e) { thrown = true; } assertTrue(thrown); assertNull(component.getValue()); User user = new User(); user.setLogin("admin"); component.setMetaClass(metadata.getClass(User.class)); component.setValue(user); assertEquals(user, component.getValue()); }
Example 9
Source File: BeforeCommitTransactionListenerTest.java From cuba with Apache License 2.0 | 6 votes |
@Test public void testChangeEntity() throws Exception { User u1 = metadata.create(User.class); u1.setLogin("TxLstnrTst-1-" + u1.getId()); u1.setGroup(companyGroup); TestBeforeCommitTxListener.test = "testChangeEntity"; try (Transaction tx = persistence.createTransaction()) { persistence.getEntityManager().persist(u1); tx.commit(); } finally { TestBeforeCommitTxListener.test = null; } try (Transaction tx = persistence.createTransaction()) { User user = persistence.getEntityManager().find(User.class, u1.getId()); assertEquals("set by tx listener", user.getName()); } }
Example 10
Source File: LookupPickerFieldTest.java From cuba with Apache License 2.0 | 6 votes |
@Test public void testSetToReadonly() { LookupPickerField component = uiComponents.create(LookupPickerField.class); component.setEditable(false); assertFalse(component.isEditable()); User one = new User(); one.setLogin("one"); User two = new User(); two.setLogin("two"); User three = new User(); three.setLogin("three"); component.setOptionsList(Arrays.asList(one, two, three)); component.setValue(one); assertEquals(one, component.getValue()); assertFalse(component.isEditable()); }
Example 11
Source File: LookupPickerFieldTest.java From cuba with Apache License 2.0 | 6 votes |
@Test public void testGetSetValue() { LookupPickerField component = uiComponents.create(LookupPickerField.class); assertNull(component.getValue()); User one = new User(); one.setLogin("one"); User two = new User(); two.setLogin("two"); User three = new User(); three.setLogin("three"); component.setOptionsList(Arrays.asList(one, two, three)); component.setValue(one); assertEquals(one, component.getValue()); }
Example 12
Source File: TestUserSessionSource.java From cuba with Apache License 2.0 | 6 votes |
@Override public synchronized UserSession getUserSession() { if (exceptionOnGetUserSession) { throw new NoUserSessionException(UUID.fromString(USER_ID)); } if (session == null) { User user = new User(); user.setId(UUID.fromString(USER_ID)); user.setLogin("test_admin"); user.setName("Test Administrator"); user.setPassword(DigestUtils.md5Hex("test_admin")); session = new UserSession(UUID.randomUUID(), user, Collections.emptyList(), Locale.forLanguageTag("en"), false); session.setJoinedRole(new TestFullAccessRole()); } return session; }
Example 13
Source File: StaticServerSelectorTest.java From cuba with Apache License 2.0 | 6 votes |
public StaticServerSelectorTest() { User user1 = new User(); user1.setLogin("user1"); session1 = new UserSession(UUID.randomUUID(), user1, Collections.emptyList(), Locale.ENGLISH, false); User user2 = new User(); user2.setLogin("user2"); session2 = new UserSession(UUID.randomUUID(), user2, Collections.emptyList(), Locale.ENGLISH, false); User user3 = new User(); user3.setLogin("user3"); session3 = new UserSession(UUID.randomUUID(), user3, Collections.emptyList(), Locale.ENGLISH, false); User user4 = new User(); user4.setLogin("user4"); session4 = new UserSession(UUID.randomUUID(), user4, Collections.emptyList(), Locale.ENGLISH, false); }
Example 14
Source File: PickerFieldTest.java From cuba with Apache License 2.0 | 5 votes |
@Test public void testSetToReadonly() { PickerField component = uiComponents.create(PickerField.class); component.setEditable(false); component.setMetaClass(metadata.getClass(User.class)); assertFalse(component.isEditable()); User user = new User(); user.setLogin("admin"); component.setValue(user); assertEquals(user, component.getValue()); assertFalse(component.isEditable()); }
Example 15
Source File: UserSessions.java From cuba with Apache License 2.0 | 5 votes |
public UserSessions() { User noUser = new User(); noUser.setLogin("server"); NO_USER_SESSION = new UserSession( UUID.fromString("a66abe96-3b9d-11e2-9db2-3860770d7eaf"), noUser, Collections.emptyList(), Locale.ENGLISH, true) { @Override public UUID getId() { return AppContext.NO_USER_CONTEXT.getSessionId(); } }; }
Example 16
Source File: AuthenticationManagerBean.java From cuba with Apache License 2.0 | 5 votes |
public AuthenticationManagerBean() { //noinspection IncorrectCreateEntity User noUser = new User(); noUser.setLogin("server"); serverSession = new UserSession( UUID.fromString("a66abe96-3b9d-11e2-9db2-3860770d7eaf"), noUser, Collections.emptyList(), Locale.ENGLISH, true) { @Override public UUID getId() { return AppContext.NO_USER_CONTEXT.getSessionId(); } }; }
Example 17
Source File: UserRoleTest.java From cuba with Apache License 2.0 | 5 votes |
@Test public void test() { Transaction tx = cont.persistence().createTransaction(); try { EntityManager em = cont.persistence().getEntityManager(); Role role = new Role(); role.setName("testRole1"); em.persist(role); Group group = new Group(); group.setName("testGroup1"); em.persist(group); User user = new User(); UUID userId = user.getId(); user.setLogin("testUser1"); user.setName("Test User 1"); user.setGroup(group); em.persist(user); UserRole userRole = new UserRole(); userRole.setUser(user); userRole.setRole(role); em.persist(userRole); tx.commitRetaining(); em = cont.persistence().getEntityManager(); user = em.find(User.class, userId); List<UserRole> userRoles = user.getUserRoles(); assertEquals(1, userRoles.size()); for (UserRole ur : userRoles) { Role r = ur.getRole(); assertEquals(role.getName(), r.getName()); } } finally { tx.end(); } }
Example 18
Source File: LoginTest.java From cuba with Apache License 2.0 | 5 votes |
@BeforeEach public void setUp() throws Exception { PasswordEncryption passwordEncryption = AppBeans.get(PasswordEncryption.NAME); authenticationManager = AppBeans.get(AuthenticationManager.NAME); userSessionSource = AppBeans.get(UserSessionSource.NAME); standardTestUserSession = userSessionSource.getUserSession(); Transaction tx = cont.persistence().createTransaction(); try { EntityManager em = cont.persistence().getEntityManager(); Group group = em.getReference(Group.class, UUID.fromString("0fa2b1a5-1d68-4d69-9fbd-dff348347f93")); User user1 = new User(); user1Id = user1.getId(); user1.setGroup(group); user1.setLogin("user1"); user1.setPassword(passwordEncryption.getPasswordHash(user1.getId(), "1")); em.persist(user1); User user2 = new User(); user2Id = user2.getId(); user2.setGroup(group); user2.setLogin("user2"); user2.setPassword(passwordEncryption.getPasswordHash(user2.getId(), "2")); em.persist(user2); tx.commit(); } finally { tx.end(); } }
Example 19
Source File: PersistenceTest.java From cuba with Apache License 2.0 | 5 votes |
/** * OpenJPA silently ignores setting null in nullable=false attribute. */ @Test public void testNonNullAttribute() throws Exception { Transaction tx = cont.persistence().createTransaction(); try { EntityManager em = cont.persistence().getEntityManager(); User user = em.find(User.class, userId); assertNotNull(user); user.setLogin(null); user.setName(null); tx.commitRetaining(); fail(); // Old OpenJPA behaviour // em = cont.persistence().getEntityManager(); // user = em.find(User.class, userId); // assertNotNull(user); // assertNotNull(user.getLogin()); // null was not saved // assertNull(user.getName()); // null was saved tx.commit(); } catch (Exception e) { assertTrue(e.getMessage().contains("NOT NULL check constraint")); } finally { tx.end(); } }
Example 20
Source File: DataManagerDistinctResultsTest.java From cuba with Apache License 2.0 | 4 votes |
@BeforeEach public void setUp() throws Exception { Transaction tx = cont.persistence().createTransaction(); try { EntityManager em = cont.persistence().getEntityManager(); Group group = new Group(); groupId = group.getId(); group.setName("testGroup"); em.persist(group); Role role1 = new Role(); role1Id = role1.getId(); role1.setName("role1"); em.persist(role1); Role role2 = new Role(); role2Id = role2.getId(); role2.setName("role2"); em.persist(role2); for (int i = 0; i < QTY; i++) { User user = new User(); user.setName("user" + StringUtils.leftPad(String.valueOf(i), 2, '0')); user.setLogin(user.getName()); user.setGroup(group); em.persist(user); UserRole userRole1 = new UserRole(); userRole1.setUser(user); userRole1.setRole(role1); em.persist(userRole1); UserRole userRole2 = new UserRole(); userRole2.setUser(user); userRole2.setRole(role2); em.persist(userRole2); } tx.commit(); } finally { tx.end(); } }