@Configuration @ComponentScan(...) public class TestConfig { @Bean public CustomScopeConfigurer customScopeConfigurer(){ CustomScopeConfigurer scopeConfigurer = new CustomScopeConfigurer(); HashMap<String, Object> scopes = new HashMap<String, Object>(); scopes.put(WebApplicationContext.SCOPE_REQUEST, new SimpleThreadScope()); scopes.put(WebApplicationContext.SCOPE_SESSION, new SimpleThreadScope()); scopeConfigurer.setScopes(scopes); return scopeConfigurer }
@Test(expected = IllegalArgumentException.class) public void testWhereScopeMapHasNullScopeValueInEntrySet() { Map<String, Object> scopes = new HashMap<>(); scopes.put(FOO_SCOPE, null); CustomScopeConfigurer figurer = new CustomScopeConfigurer(); figurer.setScopes(scopes); figurer.postProcessBeanFactory(factory); }
@Test(expected = IllegalArgumentException.class) public void testWhereScopeMapHasNonScopeInstanceInEntrySet() { Map<String, Object> scopes = new HashMap<>(); scopes.put(FOO_SCOPE, this); // <-- not a valid value... CustomScopeConfigurer figurer = new CustomScopeConfigurer(); figurer.setScopes(scopes); figurer.postProcessBeanFactory(factory); }
@SuppressWarnings("unchecked") @Test(expected = ClassCastException.class) public void testWhereScopeMapHasNonStringTypedScopeNameInKeySet() { Map scopes = new HashMap(); scopes.put(this, new NoOpScope()); // <-- not a valid value (the key)... CustomScopeConfigurer figurer = new CustomScopeConfigurer(); figurer.setScopes(scopes); figurer.postProcessBeanFactory(factory); }
@Test public void testSunnyDayWithBonaFideScopeClassName() { Map<String, Object> scopes = new HashMap<>(); scopes.put(FOO_SCOPE, NoOpScope.class.getName()); CustomScopeConfigurer figurer = new CustomScopeConfigurer(); figurer.setScopes(scopes); figurer.postProcessBeanFactory(factory); assertTrue(factory.getRegisteredScope(FOO_SCOPE) instanceof NoOpScope); }
@Test public void testSunnyDayWithBonaFideScopeClass() { Map<String, Object> scopes = new HashMap<>(); scopes.put(FOO_SCOPE, NoOpScope.class); CustomScopeConfigurer figurer = new CustomScopeConfigurer(); figurer.setScopes(scopes); figurer.postProcessBeanFactory(factory); assertTrue(factory.getRegisteredScope(FOO_SCOPE) instanceof NoOpScope); }
@Test public void testSunnyDayWithBonaFideScopeInstance() { Scope scope = mock(Scope.class); factory.registerScope(FOO_SCOPE, scope); Map<String, Object> scopes = new HashMap<>(); scopes.put(FOO_SCOPE, scope); CustomScopeConfigurer figurer = new CustomScopeConfigurer(); figurer.setScopes(scopes); figurer.postProcessBeanFactory(factory); }
@Bean public static CustomScopeConfigurer getScenarioScopeConfigurer(SpringThreadLocalScope scope) { CustomScopeConfigurer customScopeConfigurer = new CustomScopeConfigurer(); customScopeConfigurer.setScopes(Collections.<String, Object>singletonMap(ScenarioScoped.SCOPE_NAME, scope)); return customScopeConfigurer; } }
@SuppressWarnings("serial") @Bean public org.springframework.beans.factory.config.CustomScopeConfigurer customScopeConfigurer(){ CustomScopeConfigurer csc = new CustomScopeConfigurer(); csc.setScopes(new HashMap<String, Object>() {{ put("view", new com.liferay.faces.demos.spring.ViewScope()); }}); return csc; }