use of org.jaffa.session.IContextManager in project jaffa-framework by jaffa-projects.
the class ContextManagerTest method testContextManager.
/**
* testContextManager - Verifies that the application rules have been loaded correctly for both global and variation
* specific rules files.
*
* @throws Exception
*/
@Test
public void testContextManager() throws Exception {
ApplicationRulesManager applicationRulesManager = xmlLoaderConfig.getBean(ApplicationRulesManager.class);
assertNotNull(applicationRulesManager.getApplicationRulesRepository());
MockHttpServletRequest request = new MockHttpServletRequest();
// creating user session
UserSession us = UserSession.getUserSession(request);
us.setUserId(USER);
us.setVariation(VARIATION);
// creating mock http session for the same use session
MockHttpSession session = new MockHttpSession();
session.setAttribute(USER_ATTRIBUTE, us);
// setting the mock session into request
request.setSession(session);
ContextManagerFactory.instance().setThreadContext(request);
// Property from global
IContextManager iContextManager = ContextManagerFactory.instance();
assertNotNull(iContextManager.getProperty("org.jaffa.config.global"));
assertNull(iContextManager.getProperty("nonExistentKey"));
// Property from variation
assertNotNull(iContextManager.getProperty("org.jaffa.config.variation"));
// Property from variation
assertEquals("true", iContextManager.getProperty("org.jaffa.config.hidepanel"));
// Property from variation
assertEquals("true", iContextManager.getProperty("org.jaffa.config.hidemaintenancepanel"));
assertEquals("datadist_root/outbound", iContextManager.getProperty("datadist.outboundFolder"));
assertEquals("datadist_root/outbound/fragments", iContextManager.getProperty("datadist.outboundFolder.fragments"));
assertEquals("c:/test/interfaces_root/outbound/test", iContextManager.getProperty("interfaces.outboundTestFolder"));
assertEquals("http://pentaho_host.mypentaho.com:80967/pentaho", iContextManager.getProperty("pentaho.url"));
assertEquals("C:/apache-tomcat-8.5.16/server/Goldesp/conf/report-security.txt", iContextManager.getProperty("usersecurity.reportsecurity.securityFilterKeyFile"));
}
use of org.jaffa.session.IContextManager in project jaffa-framework by jaffa-projects.
the class UserContextWrapperTest method testContextManager.
/**
* Make sure the Context Manager is set
*/
public void testContextManager() throws Exception {
log.info("RUN: " + getName());
try {
UserContextWrapper ucw = new UserContextWrapper(UserDataWrapper.USER1, DummyPortletFilter.class);
IContextManager cm = ContextManagerFactory.instance();
// Test Global Rules
assertEquals("Bad value in : test.rule.1", "global", cm.getProperty("test.rule.1"));
// Test Variation Rules
assertEquals("Bad value in : test.rule.2", "TEST1", cm.getProperty("test.rule.2"));
// Test stuff from the User Rules
assertEquals("Bad value in : user.id", UserDataWrapper.USER1, cm.getProperty("user.id"));
assertEquals("Bad value in : user.principal", UserDataWrapper.USER1, ((Principal) cm.getProperty("user.principal")).getName());
assertEquals("Bad value in : user.hostname", null, cm.getProperty("user.hostname"));
assertNotNull("Bad value in : user.data", cm.getProperty("user.data"));
assertEquals("Bad value in : user.data:email", UserDataWrapper.EMAIL, ((Properties) cm.getProperty("user.data")).getProperty("email"));
assertEquals("Bad value in : user.sessionId", "1", cm.getProperty("user.sessionId"));
assertEquals("Bad value in : user.locale", Locale.getDefault(), cm.getProperty("user.locale"));
assertEquals("Bad value in : user.variation", DummyPortletFilter.VARIATION, cm.getProperty("user.variation"));
// Test stuff from the thread rules
assertNotNull("Bad value in : request", cm.getProperty("request"));
ucw.unsetContext();
cm = ContextManagerFactory.instance();
// Test Global Rules
assertNull("Bad value in : test.rule.1", cm.getProperty("test.rule.1"));
// Test Variation Rules
assertNull("Bad value in : test.rule.2", cm.getProperty("test.rule.2"));
// Test stuff from the User Rules
assertNull("Bad value in : user.id", cm.getProperty("user.id"));
// Test stuff from the thread rules
assertNull("Bad value in : request", cm.getProperty("request"));
} catch (Exception e) {
log.fatal("Test Failed", e);
}
}
use of org.jaffa.session.IContextManager in project jaffa-framework by jaffa-projects.
the class SOAEventServer method findSleepTimeMillis.
/**
* Reads the "jaffa.soa.SOAEventServer.sleepTimeMillis" business-rule.
*/
private static int findSleepTimeMillis() {
// Determine the sleep time
int sleepTimeMillis = 0;
IContextManager contextManager = null;
try {
contextManager = ContextManagerFactory.instance();
contextManager.setThreadContext(null);
sleepTimeMillis = Integer.parseInt((String) contextManager.getProperty(RULE_FREQUENCY));
if (log.isDebugEnabled())
log.debug("Sleep time in milliseconds is " + sleepTimeMillis);
} catch (NumberFormatException e) {
log.warn("Rule '" + RULE_FREQUENCY + "' should be a valid number", e);
} finally {
if (contextManager != null)
contextManager.unsetThreadContext();
}
return sleepTimeMillis;
}
Aggregations