Java Code Examples for com.haulmont.cuba.security.entity.User#setId()

The following examples show how to use com.haulmont.cuba.security.entity.User#setId() . 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: TestUserSessionSource.java    From cuba with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: HsqlLikeNullFailTest.java    From cuba with Apache License 2.0 6 votes vote down vote up
@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 3
Source File: EntityManagerTest.java    From cuba with Apache License 2.0 6 votes vote down vote up
@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 4
Source File: TestUserSessionSource.java    From cuba with Apache License 2.0 5 votes vote down vote up
public User createTestUser() {
    User user = new User();
    user.setId(UUID.fromString(USER_ID));
    user.setLogin("test_admin");
    user.setName("Test Administrator");
    user.setPassword(DigestUtils.md5Hex("test_admin"));
    return user;
}
 
Example 5
Source File: TestUiEnvironment.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected User createUser() {
    User user = container.getBean(Metadata.class).create(User.class);
    user.setId(UUID.fromString(USER_ID));
    user.setLogin(userLogin);
    user.setName(userName);
    user.setPassword(DigestUtils.md5Hex(userLogin));
    return user;
}
 
Example 6
Source File: PersistenceTest.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Test
public void testMergeNotLoaded() throws Exception {
    User user;
    Group group;

    Transaction tx = cont.persistence().createTransaction();
    try {
        User transientUser = new User();
        transientUser.setId(userId);
        transientUser.setName("testUser1");

        EntityManager em = cont.persistence().getEntityManager();
        em.merge(transientUser);

        tx.commitRetaining();

        em = cont.persistence().getEntityManager();
        user = em.find(User.class, userId);
        assertNotNull(user);
        group = user.getGroup();
    } finally {
        tx.end();
    }

    assertEquals(userId, user.getId());
    assertEquals("testUser1", user.getName());
    assertEquals("testLogin", user.getLogin());
    assertNotNull(group);
}
 
Example 7
Source File: NonDetachedTest.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateNew_DM() throws Exception {
    // check versioned entity
    Group companyGroupCopy = metadata.getTools().copy(companyGroup);
    assertTrue(PersistenceHelper.isNew(companyGroupCopy));
    PersistenceHelper.makeDetached(companyGroupCopy);

    User user = persistence.callInTransaction((em) -> em.find(User.class, this.user.getId()));
    User userCopy = metadata.getTools().copy(user);
    assertNull(userCopy.getGroup());

    assertTrue(PersistenceHelper.isNew(userCopy));
    PersistenceHelper.makeDetached(userCopy);

    userCopy.setId(UuidProvider.createUuid());
    userCopy.setVersion(null);
    userCopy.setGroup(companyGroupCopy);
    userCopy.setName("new name");
    try {
        AppBeans.get(DataManager.class).commit(userCopy);

        user = persistence.callInTransaction((em) -> em.find(User.class, userCopy.getId()));
        assertEquals("new name", user.getName());
    } finally {
        cont.deleteRecord(userCopy);
    }

    // check non-versioned entity
    Server server = metadata.create(Server.class);
    server.setName("server-" + server.getId());
    assertTrue(PersistenceHelper.isNew(server));
    PersistenceHelper.makeDetached(server);
    try {
        AppBeans.get(DataManager.class).commit(server);
        Server loaded = persistence.callInTransaction(em -> em.find(Server.class, server.getId()));
        assertNotNull(loaded);
    } finally {
        cont.deleteRecord(server);
    }
}