use of javax.faces.context.ExternalContext in project ART-TIME by Artezio.
the class CalendarUtilsTest method testGetLocale_ifRuLocale.
@Test
public void testGetLocale_ifRuLocale() {
FacesContext facesContext = createMock(FacesContext.class);
ExternalContext externalContext = createMock(ExternalContext.class);
PowerMock.mockStatic(FacesContext.class);
expect(FacesContext.getCurrentInstance()).andReturn(facesContext);
expect(facesContext.getExternalContext()).andReturn(externalContext);
expect(externalContext.getRequestLocale()).andReturn(new Locale("ru"));
PowerMock.replayAll(FacesContext.class, facesContext, externalContext);
Locale actual = CalendarUtils.getLocale();
PowerMock.verifyAll();
assertEquals(new Locale("ru", "RU"), actual);
}
use of javax.faces.context.ExternalContext in project ART-TIME by Artezio.
the class CalendarUtilsTest method testGetLocale_ifFacesContextNotNull.
@Test
public void testGetLocale_ifFacesContextNotNull() {
FacesContext facesContext = createMock(FacesContext.class);
ExternalContext externalContext = createMock(ExternalContext.class);
PowerMock.mockStatic(FacesContext.class);
expect(FacesContext.getCurrentInstance()).andReturn(facesContext);
expect(facesContext.getExternalContext()).andReturn(externalContext);
expect(externalContext.getRequestLocale()).andReturn(Locale.CANADA);
PowerMock.replayAll(FacesContext.class, facesContext, externalContext);
Locale actual = CalendarUtils.getLocale();
PowerMock.verifyAll();
assertEquals(Locale.CANADA, actual);
}
use of javax.faces.context.ExternalContext in project ART-TIME by Artezio.
the class WebCachedInterceptorTest method testProcess_resetCache.
@Test
public void testProcess_resetCache() throws Exception {
InvocationContext context = createMock(InvocationContext.class);
Method method = this.getClass().getMethod("getTestValue1");
Map<String, Object> contextProperties = new HashMap<String, Object>();
Object[] parameters = new Object[2];
String targetInstance = "targetInstance";
ExternalContext externalContext = createMock(ExternalContext.class);
expect(context.getMethod()).andReturn(method);
expect(context.getTarget()).andReturn(targetInstance);
expect(facesContextMock.getExternalContext()).andReturn(externalContext);
expect(externalContext.getRequestMap()).andReturn(contextProperties);
expect(context.getParameters()).andReturn(parameters);
expect(context.proceed()).andReturn(getTestValue());
replay(context, facesContextMock, externalContext);
interceptor.process(context);
verify(context, facesContextMock, externalContext);
String cacheId = "_webCache:" + targetInstance.getClass().getName();
@SuppressWarnings("unchecked") Map<String, Object> cache = (Map<String, Object>) contextProperties.get(cacheId);
assertNull(cache);
}
use of javax.faces.context.ExternalContext in project ART-TIME by Artezio.
the class WebCachedInterceptorTest method testProcess_getFromCache.
@SuppressWarnings("unchecked")
@Test
public void testProcess_getFromCache() throws Exception {
InvocationContext context = createMock(InvocationContext.class);
Method method = this.getClass().getMethod("getTestValue");
Map<String, Object> contextProperties = new HashMap<String, Object>();
Object[] parameters = new Object[2];
String targetInstance = "targetInstance";
ExternalContext externalContext = createMock(ExternalContext.class);
expect(context.getMethod()).andReturn(method).times(2);
expect(context.getTarget()).andReturn(targetInstance).times(2);
expect(facesContextMock.getExternalContext()).andReturn(externalContext).times(2);
expect(externalContext.getRequestMap()).andReturn(contextProperties).times(2);
expect(context.getParameters()).andReturn(parameters).times(2);
expect(context.proceed()).andReturn(getTestValue()).once();
replay(context, facesContextMock, externalContext);
Object actual = interceptor.process(context);
actual = interceptor.process(context);
verify(context, facesContextMock, externalContext);
String cacheId = "_webCache:" + targetInstance.getClass().getName();
Map<String, Object> cache = (Map<String, Object>) contextProperties.get(cacheId);
WebCachedInterceptor.CacheKey cacheKey = interceptor.new CacheKey(targetInstance.getClass(), method, parameters);
assertEquals(cache.get(cacheKey.toString()), actual);
}
use of javax.faces.context.ExternalContext in project ART-TIME by Artezio.
the class WebCachedInterceptorTest method testGetContextProperties_forSessionScope.
@Test
public void testGetContextProperties_forSessionScope() {
Map<String, Object> contextProperties = new HashMap<String, Object>();
ExternalContext externalContext = createMock(ExternalContext.class);
expect(facesContextMock.getExternalContext()).andReturn(externalContext);
expect(externalContext.getSessionMap()).andReturn(contextProperties);
replay(facesContextMock, externalContext);
Map<String, Object> actual = interceptor.getContextProperties(Scope.SESSION_SCOPED);
verify(facesContextMock, externalContext);
assertEquals(contextProperties, actual);
}
Aggregations