Search in sources :

Example 11 with TestUserSessionSource

use of com.haulmont.cuba.testsupport.TestUserSessionSource in project cuba by cuba-platform.

the class InMemoryConstraintTest method testConstraintsOnFirst.

@Test
public void testConstraintsOnFirst() throws LoginException {
    LoginWorker lw = AppBeans.get(LoginWorker.NAME);
    UserSession userSession = lw.login("constraintUser2", passwordEncryption.getPlainHash(PASSWORD), Locale.getDefault());
    assertNotNull(userSession);
    UserSessionSource uss = AppBeans.get(UserSessionSource.class);
    UserSession savedUserSession = uss.getUserSession();
    ((TestUserSessionSource) uss).setUserSession(userSession);
    try {
        DataManager dataManager = AppBeans.get(DataManager.NAME);
        dataManager = dataManager.secure();
        LoadContext loadContext = new LoadContext(User.class).setView(View.LOCAL);
        loadContext.setQuery(new LoadContext.Query("select u from sec$User u where (u.login like 'user%' or u.login like 'constraintUser%') order by u.login asc"));
        loadContext.getQuery().setMaxResults(30);
        loadContext.getQuery().setFirstResult(0);
        List resultList = dataManager.loadList(loadContext);
        assertEquals(9, resultList.size());
        assertEquals(9, dataManager.getCount(loadContext));
    } finally {
        ((TestUserSessionSource) uss).setUserSession(savedUserSession);
    }
}
Also used : LoginWorker(com.haulmont.cuba.security.app.LoginWorker) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) UserSession(com.haulmont.cuba.security.global.UserSession) ArrayList(java.util.ArrayList) List(java.util.List)

Example 12 with TestUserSessionSource

use of com.haulmont.cuba.testsupport.TestUserSessionSource in project cuba by cuba-platform.

the class InMemoryConstraintTest method testLoadingLastPage.

@Test
public void testLoadingLastPage() throws LoginException {
    LoginWorker lw = AppBeans.get(LoginWorker.NAME);
    UserSession userSession = lw.login("constraintUser3", passwordEncryption.getPlainHash(PASSWORD), Locale.getDefault());
    assertNotNull(userSession);
    UserSessionSource uss = AppBeans.get(UserSessionSource.class);
    UserSession savedUserSession = uss.getUserSession();
    ((TestUserSessionSource) uss).setUserSession(userSession);
    try {
        DataManager dataManager = AppBeans.get(DataManager.NAME);
        dataManager = dataManager.secure();
        LoadContext loadContext = new LoadContext(User.class).setView(View.LOCAL);
        loadContext.setQuery(new LoadContext.Query("select u from sec$User u where (u.login like 'user%' or u.login like 'constraintUser%') order by u.login desc"));
        loadContext.getQuery().setMaxResults(30);
        loadContext.getQuery().setFirstResult(30);
        List<User> resultList = dataManager.loadList(loadContext);
        assertEquals(8, resultList.size());
        assertEquals("user133", resultList.get(0).getLogin());
        assertEquals("user132", resultList.get(1).getLogin());
        assertEquals("user131", resultList.get(2).getLogin());
    } finally {
        ((TestUserSessionSource) uss).setUserSession(savedUserSession);
    }
}
Also used : LoginWorker(com.haulmont.cuba.security.app.LoginWorker) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) UserSession(com.haulmont.cuba.security.global.UserSession)

Example 13 with TestUserSessionSource

use of com.haulmont.cuba.testsupport.TestUserSessionSource in project cuba by cuba-platform.

the class ParentClassConstraintTest method testConstraintsOnParentAndCurrentMetaClass.

@Test
public void testConstraintsOnParentAndCurrentMetaClass() throws LoginException {
    DataManager dataManager = AppBeans.get(DataManager.NAME);
    LoadContext<SearchFolder> loadContext = new LoadContext<>(SearchFolder.class).setView(View.LOCAL);
    loadContext.setQueryString("select f from sec$SearchFolder f");
    List resultList = dataManager.loadList(loadContext);
    assertEquals(2, resultList.size());
    LoginWorker lw = AppBeans.get(LoginWorker.NAME);
    UserSession userSession = lw.login("constraintUser2", passwordEncryption.getPlainHash(PASSWORD), Locale.getDefault());
    assertNotNull(userSession);
    UserSessionSource uss = AppBeans.get(UserSessionSource.class);
    UserSession savedUserSession = uss.getUserSession();
    ((TestUserSessionSource) uss).setUserSession(userSession);
    try {
        dataManager = AppBeans.get(DataManager.NAME);
        dataManager = dataManager.secure();
        loadContext = new LoadContext<>(SearchFolder.class).setView(View.LOCAL);
        loadContext.setQueryString("select f from sec$SearchFolder f");
        resultList = dataManager.loadList(loadContext);
        assertEquals(0, resultList.size());
    } finally {
        ((TestUserSessionSource) uss).setUserSession(savedUserSession);
    }
}
Also used : LoginWorker(com.haulmont.cuba.security.app.LoginWorker) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) UserSession(com.haulmont.cuba.security.global.UserSession) ArrayList(java.util.ArrayList) List(java.util.List)

Example 14 with TestUserSessionSource

use of com.haulmont.cuba.testsupport.TestUserSessionSource in project cuba by cuba-platform.

the class ParentClassConstraintTest method testConstraintsOnMappedSuperClass.

@Test
public void testConstraintsOnMappedSuperClass() throws LoginException {
    DataManager dataManager = AppBeans.get(DataManager.NAME);
    LoadContext<SearchFolder> loadContext = new LoadContext<>(SearchFolder.class).setView(View.LOCAL);
    loadContext.setQueryString("select f from sec$SearchFolder f");
    List resultList = dataManager.loadList(loadContext);
    assertEquals(2, resultList.size());
    LoginWorker lw = AppBeans.get(LoginWorker.NAME);
    UserSession userSession = lw.login("constraintUser3", passwordEncryption.getPlainHash(PASSWORD), Locale.getDefault());
    assertNotNull(userSession);
    UserSessionSource uss = AppBeans.get(UserSessionSource.class);
    UserSession savedUserSession = uss.getUserSession();
    ((TestUserSessionSource) uss).setUserSession(userSession);
    try {
        dataManager = AppBeans.get(DataManager.NAME);
        dataManager = dataManager.secure();
        loadContext = new LoadContext<>(SearchFolder.class).setView(View.LOCAL);
        loadContext.setQueryString("select f from sec$SearchFolder f");
        resultList = dataManager.loadList(loadContext);
        assertEquals(0, resultList.size());
    } finally {
        ((TestUserSessionSource) uss).setUserSession(savedUserSession);
    }
}
Also used : LoginWorker(com.haulmont.cuba.security.app.LoginWorker) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) UserSession(com.haulmont.cuba.security.global.UserSession) ArrayList(java.util.ArrayList) List(java.util.List)

Example 15 with TestUserSessionSource

use of com.haulmont.cuba.testsupport.TestUserSessionSource in project cuba by cuba-platform.

the class ParentClassConstraintTest method testConstraintsOnParentClass.

@Test
public void testConstraintsOnParentClass() throws LoginException {
    DataManager dataManager = AppBeans.get(DataManager.NAME);
    LoadContext<SearchFolder> loadContext = new LoadContext<>(SearchFolder.class).setView(View.LOCAL);
    loadContext.setQueryString("select f from sec$SearchFolder f");
    List resultList = dataManager.loadList(loadContext);
    assertEquals(2, resultList.size());
    LoginWorker lw = AppBeans.get(LoginWorker.NAME);
    UserSession userSession = lw.login("constraintUser1", passwordEncryption.getPlainHash(PASSWORD), Locale.getDefault());
    assertNotNull(userSession);
    UserSessionSource uss = AppBeans.get(UserSessionSource.class);
    UserSession savedUserSession = uss.getUserSession();
    ((TestUserSessionSource) uss).setUserSession(userSession);
    try {
        dataManager = AppBeans.get(DataManager.NAME);
        dataManager = dataManager.secure();
        loadContext = new LoadContext<>(SearchFolder.class).setView(View.LOCAL);
        loadContext.setQueryString("select f from sec$SearchFolder f");
        resultList = dataManager.loadList(loadContext);
        assertEquals(1, resultList.size());
    } finally {
        ((TestUserSessionSource) uss).setUserSession(savedUserSession);
    }
}
Also used : LoginWorker(com.haulmont.cuba.security.app.LoginWorker) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) UserSession(com.haulmont.cuba.security.global.UserSession) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

TestUserSessionSource (com.haulmont.cuba.testsupport.TestUserSessionSource)24 LoginWorker (com.haulmont.cuba.security.app.LoginWorker)23 UserSession (com.haulmont.cuba.security.global.UserSession)23 Test (org.junit.Test)15 List (java.util.List)8 ArrayList (java.util.ArrayList)7 ConfigStorageService (com.haulmont.cuba.core.app.ConfigStorageService)4 KeyValueEntity (com.haulmont.cuba.core.entity.KeyValueEntity)3 Server (com.haulmont.cuba.core.entity.Server)2 DataService (com.haulmont.cuba.core.app.DataService)1 Executions (com.haulmont.cuba.core.app.execution.Executions)1 UserSessionSource (com.haulmont.cuba.core.global.UserSessionSource)1 ConstraintData (com.haulmont.cuba.security.global.ConstraintData)1