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

The following examples show how to use com.haulmont.cuba.security.entity.User#setName() . 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: 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 2
Source File: NonDetachedTest.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Test
public void testSaveNotDetached_DM() throws Exception {
    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.setGroup(companyGroupCopy);
    userCopy.setName("new name");
    AppBeans.get(DataManager.class).commit(userCopy);

    user = persistence.callInTransaction((em) -> em.find(User.class, this.user.getId()));
    assertEquals("new name", user.getName());
}
 
Example 3
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 4
Source File: LabelDsTest.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Test
public void testUnsubscribeComponentListener() {
    Label label = uiComponents.create(Label.NAME);

    Datasource<User> userDs = getTestUserDatasource();
    User user = userDs.getItem();
    user.setName("testName");
    label.setDatasource(userDs, "name");

    // unbind
    label.setDatasource(null, null);
    assertNotNull(label.getValue());

    Consumer<HasValue.ValueChangeEvent> listener = e -> {
        throw new RuntimeException("Value was changed externally");
    };
    label.addValueChangeListener(listener);

    user.setName("anotherName");
    assertEquals("testName", label.getValue());
}
 
Example 5
Source File: LabelDsTest.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Test
public void testUnsubscribeDsListener() {
    Label label = uiComponents.create(Label.NAME);

    Datasource<User> userDs = getTestUserDatasource();
    User user = userDs.getItem();
    user.setName("testName");
    label.setDatasource(userDs, "name");

    // unbind
    label.setDatasource(null, null);
    assertNotNull(label.getValue());

    Datasource.ItemPropertyChangeListener<User> propertyChangeListener = e -> {
        throw new RuntimeException("Value was changed externally");
    };
    userDs.addItemPropertyChangeListener(propertyChangeListener);

    label.setValue("anotherName");
    assertEquals("testName", user.getName());
}
 
Example 6
Source File: TextFieldDsTest.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Test
public void testUnsubscribeComponentListener() {
    TextField textField = uiComponents.create(TextField.NAME);

    Datasource<User> userDs = getTestUserDatasource();
    User user = userDs.getItem();
    user.setName("testName");
    textField.setDatasource(userDs, "name");

    // unbind
    textField.setDatasource(null, null);

    Consumer<HasValue.ValueChangeEvent> listener = e -> {
        throw new RuntimeException("Value was changed externally");
    };
    textField.addValueChangeListener(listener);
    user.setName("anotherName");
}
 
Example 7
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 8
Source File: PersistenceTest.java    From cuba with Apache License 2.0 5 votes vote down vote up
/**
     * 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 9
Source File: PersistenceAttributeLoadedCheckTest.java    From cuba with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void setUp() throws Exception {
    dataManager = AppBeans.get(DataManager.class);
    persistence = AppBeans.get(Persistence.class);

    try (Transaction tx = persistence.createTransaction()) {
        EntityManager em = persistence.getEntityManager();

        ScheduledTask task = new ScheduledTask();
        task.setBeanName("BeanName");
        task.setMethodName("MethodName");
        taskId = task.getId();

        User user = new User();
        userId = user.getId();
        user.setName("testUser");
        user.setLogin("login" + userId);
        user.setPassword("000");
        user.setGroup(em.find(Group.class, groupId));
        em.persist(user);

        em.persist(task);
        em.persist(user);
        tx.commit();
    }

    taskView = new View(ScheduledTask.class, true)
            .addProperty("beanName");

    userView = new View(User.class, true)
            .addProperty("login")
            .addProperty("loginLowerCase")
            .addProperty("name")
            .addProperty("password")
            .addProperty("group", new View(Group.class).addProperty("name"))
            .addProperty("userRoles", new View(UserRole.class));
}
 
Example 10
Source File: EntityListenerCascadingTest.java    From cuba with Apache License 2.0 5 votes vote down vote up
private void doQueryInListener() {
    try (Transaction tx = persistence.createTransaction()) {
        User u = persistence.getEntityManager().find(User.class, user.getId());
        assertNotNull(u);
        u.setName(u.getLogin());
        tx.commit();
    }
    System.out.println("\n" + TestCascadingEntityListener.events + "\n");
    assertEquals(2, TestCascadingEntityListener.events.size());
    assertTrue(TestCascadingEntityListener.events.get(0).contains("onBeforeUpdate"));
    assertTrue(TestCascadingEntityListener.events.get(1).contains("onAfterUpdate"));
}
 
Example 11
Source File: LookupFieldDsTest.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetValueWithoutOptions() {
    LookupField lookupField = uiComponents.create(LookupField.NAME);

    Datasource<User> userDs = getTestUserDatasource();

    User user = userDs.getItem();
    user.setName("Test name");

    lookupField.setDatasource(userDs, "name");
    assertEquals("Test name", lookupField.getValue());
}
 
Example 12
Source File: TextFieldDsTest.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Test
public void testUnsubscribeSubscribeComponentListener() {
    TextField textField = uiComponents.create(TextField.NAME);

    Datasource<User> userDs = getTestUserDatasource();
    User user = userDs.getItem();
    user.setName("testName");
    textField.setDatasource(userDs, "name");

    // unbind
    textField.setDatasource(null, null);

    // setup
    boolean[] valueWasChanged = {false};
    Consumer<HasValue.ValueChangeEvent> listener = e -> valueWasChanged[0] = true;

    // datasource before listener

    textField.setDatasource(userDs, "name");
    textField.addValueChangeListener(listener);
    user.setName("anotherName");
    assertEquals(true, valueWasChanged[0]);

    // reset state
    textField.removeValueChangeListener(listener);
    textField.setDatasource(null, null);
    valueWasChanged[0] = false;
    textField.setValue("testName");

    // listener before datasource
    textField.addValueChangeListener(listener);
    textField.setDatasource(userDs, "name");
    assertEquals(true, valueWasChanged[0]);
}
 
Example 13
Source File: LookupScreenFacetTestScreen.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Subscribe
public void onInit(InitEvent event) {
    User testUser = metadata.create(User.class);
    testUser.setName("Test user");

    pickerField.setValue(testUser);
}
 
Example 14
Source File: LabelDsTest.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Test
public void testUnsubscribeSubscribeComponentListener() {
    Label label = uiComponents.create(Label.NAME);

    Datasource<User> userDs = getTestUserDatasource();
    User user = userDs.getItem();
    user.setName("testName");
    label.setDatasource(userDs, "name");

    label.setDatasource(null, null);

    // datasource before listener
    label.setDatasource(userDs, "name");
    assertEquals("testName", label.getValue());

    boolean[] valueWasChanged = {false};
    Consumer<HasValue.ValueChangeEvent> listener = e -> valueWasChanged[0] = true;
    label.addValueChangeListener(listener);

    user.setName("anotherName");
    assertEquals(true, valueWasChanged[0]);
    assertEquals("anotherName", label.getValue());

    // reset state
    label.removeValueChangeListener(listener);
    label.setDatasource(null, null);
    valueWasChanged[0] = false;
    label.setValue("testName");

    // listener before datasource
    label.addValueChangeListener(listener);
    label.setDatasource(userDs, "name");
    assertEquals(true, valueWasChanged[0]);
    assertEquals("anotherName", label.getValue());
}
 
Example 15
Source File: LabelDsTest.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Test
public void testValueChangeListener() {
    Label label = uiComponents.create(Label.NAME);

    Datasource<User> userDs = getTestUserDatasource();
    User user = userDs.getItem();
    user.setName("testName");
    label.setDatasource(userDs, "name");

    // listener after datasource
    boolean[] valueWasChanged = {false};
    Consumer<HasValue.ValueChangeEvent> listener = e -> valueWasChanged[0] = true;
    label.addValueChangeListener(listener);

    user.setName("anotherName");
    assertEquals(true, valueWasChanged[0]);

    // reset state
    label.removeValueChangeListener(listener);
    label.setDatasource(null, null);
    valueWasChanged[0] = false;
    label.setValue("testName");

    // datasource after listener
    label.addValueChangeListener(listener);
    label.setDatasource(userDs, "name");

    assertEquals(true, valueWasChanged[0]);
}
 
Example 16
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 17
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 18
Source File: OrmBehaviorTest.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Test
public void testPersistWithUnManagedAttribute() throws Exception {
    Group group = new Group();
    groupId = group.getId();
    group.setName("Old Name");
    Transaction tx = cont.persistence().createTransaction();
    try {
        cont.persistence().getEntityManager().persist(group);
        tx.commit();
    } finally {
        tx.end();
    }

    // Let's imagine that this entity was loaded with MyBatis
    Group g = new Group();
    g.setId(groupId);
    g.setName("Old Name");

    User user = new User();
    userId = user.getId();
    user.setLogin("typednativesqlquery");
    user.setGroup(g);
    user.setName("Test");

    tx = cont.persistence().createTransaction();
    try {
        cont.persistence().getEntityManager().persist(user);
        tx.commitRetaining();

        user = cont.persistence().getEntityManager().find(User.class, userId,
                new View(User.class).addProperty("group"));
        tx.commit();
    } finally {
        tx.end();
    }

    user = reserialize(user);
    assertEquals(groupId, user.getGroup().getId());
}
 
Example 19
Source File: EditorScreenFacetTestScreen.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Install(to = "editorScreenFacet", subject = "entityProvider")
public User provideEntity() {
    User testUser = metadata.create(User.class);
    testUser.setName("Test user");

    return testUser;
}
 
Example 20
Source File: DataManagerCommitTest.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Test
public void testViewAfterCommit() throws Exception {
    LoadContext<User> loadContext = LoadContext.create(User.class).setId(userId).setView(view);
    User user = dataManager.load(loadContext);
    assertNotNull(user);
    user = TestSupport.reserialize(user);
    assertEquals(groupId, user.getGroup().getId());
    assertEquals(1, user.getUserRoles().size());
    assertEquals(userRoleId, user.getUserRoles().get(0).getId());

    Integer version = user.getVersion();
    user.setName("testUser-changed");
    user = dataManager.commit(user, view);
    assertNotNull(user);

    //do check loaded before serialization
    assertTrue(PersistenceHelper.isLoaded(user, "group"));
    assertTrue(PersistenceHelper.isLoaded(user, "userRoles"));
    assertTrue(!PersistenceHelper.isLoaded(user, "substitutions"));
    //do second check to make sure isLoaded did not affect attribute fetch status
    assertTrue(!PersistenceHelper.isLoaded(user, "substitutions"));

    user = TestSupport.reserialize(user);

    assertTrue(PersistenceHelper.isDetached(user));
    assertTrue(!PersistenceHelper.isNew(user));
    assertTrue(!PersistenceHelper.isManaged(user));

    assertEquals(version + 1, (int) user.getVersion());
    assertEquals("testUser-changed", user.getName());
    assertEquals(groupId, user.getGroup().getId());
    assertEquals(1, user.getUserRoles().size());
    assertEquals(userRoleId, user.getUserRoles().get(0).getId());

    //do check loaded after serialization
    assertTrue(PersistenceHelper.isLoaded(user, "group"));
    assertTrue(PersistenceHelper.isLoaded(user, "userRoles"));
    assertTrue(!PersistenceHelper.isLoaded(user, "substitutions"));
    //do second check to make sure isLoaded did not affect attribute fetch status
    assertTrue(!PersistenceHelper.isLoaded(user, "substitutions"));
}