use of com.haulmont.cuba.testsupport.TestUserSessionSource in project cuba by cuba-platform.
the class InMemoryConstraintTest method testConstraintByAttributeNotInView.
@Test
public void testConstraintByAttributeNotInView() throws LoginException {
LoginWorker lw = AppBeans.get(LoginWorker.NAME);
UserSession userSession = lw.login("constraintUser4", 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.MINIMAL);
loadContext.setQuery(new LoadContext.Query("select u from sec$User u where u.login = 'constraintUser4' order by u.login desc"));
loadContext.getQuery().setMaxResults(30);
loadContext.getQuery().setFirstResult(0);
List<User> resultList = dataManager.loadList(loadContext);
assertEquals(1, resultList.size());
assertEquals("constraintUser4", resultList.get(0).getLogin());
} finally {
((TestUserSessionSource) uss).setUserSession(savedUserSession);
}
}
use of com.haulmont.cuba.testsupport.TestUserSessionSource in project cuba by cuba-platform.
the class InMemoryConstraintTest method testConstraintsOnMiddlePage.
@Test
public void testConstraintsOnMiddlePage() throws LoginException {
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 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(11, resultList.size());
assertEquals(11, dataManager.getCount(loadContext));
} finally {
((TestUserSessionSource) uss).setUserSession(savedUserSession);
}
}
use of com.haulmont.cuba.testsupport.TestUserSessionSource in project cuba by cuba-platform.
the class InMemoryConstraintTest method testConstraintsOnMoreThanOnePage.
@Test
public void testConstraintsOnMoreThanOnePage() 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(0);
List resultList = dataManager.loadList(loadContext);
assertEquals(30, resultList.size());
assertEquals(38, dataManager.getCount(loadContext));
} finally {
((TestUserSessionSource) uss).setUserSession(savedUserSession);
}
}
use of com.haulmont.cuba.testsupport.TestUserSessionSource in project cuba by cuba-platform.
the class NonEntityQueryTest method testIdentificationVariableDeniedSecurity.
@Test
public void testIdentificationVariableDeniedSecurity() throws Exception {
ConfigStorageService configStorageService = AppBeans.get(ConfigStorageService.class);
configStorageService.setDbProperty("cuba.disableLoadValuesIfConstraints", "true");
LoginWorker lw = AppBeans.get(LoginWorker.NAME);
UserSession userSession = lw.login(USER_NAME_1, passwordEncryption.getPlainHash(USER_PASSWORD), Locale.getDefault());
assertNotNull(userSession);
UserSessionSource uss = AppBeans.get(UserSessionSource.class);
UserSession savedUserSession = uss.getUserSession();
((TestUserSessionSource) uss).setUserSession(userSession);
try {
ValueLoadContext context = ValueLoadContext.create();
context.setQueryString("select s from sys$EntitySnapshot s");
context.addProperty("snapshot");
List result = dataManager.secure().loadValues(context);
assertTrue(result.isEmpty());
} finally {
((TestUserSessionSource) uss).setUserSession(savedUserSession);
}
}
Aggregations