@Override protected ApplicationContext getApplicationContext() { return new GenericXmlApplicationContext( "/org/springframework/cache/jcache/config/jCacheStandaloneConfig.xml"); }
@Override protected ConfigurableApplicationContext getApplicationContext() { return new GenericXmlApplicationContext( "/org/springframework/cache/config/annotationDrivenCacheConfig.xml"); }
@Override protected ConfigurableApplicationContext getApplicationContext() { return new GenericXmlApplicationContext( "/org/springframework/cache/config/annotation-cache-aspectj.xml"); }
@Override protected ConfigurableApplicationContext getApplicationContext() { return new GenericXmlApplicationContext( "/org/springframework/cache/config/annotationDrivenCacheNamespace.xml"); }
@Override protected ApplicationContext getApplicationContext() { return new GenericXmlApplicationContext( "/org/springframework/cache/jcache/config/jCacheNamespaceDriven.xml"); }
@Override protected ConfigurableApplicationContext getApplicationContext() { return new GenericXmlApplicationContext( "/org/springframework/cache/config/cache-advice.xml"); }
@Override protected ApplicationContext getApplicationContext() { return new GenericXmlApplicationContext( "/org/springframework/cache/config/annotation-jcache-aspectj.xml"); }
@Test public void fullyQualifiedResourceLoading_ctor() { ApplicationContext ctx = new GenericXmlApplicationContext(FQ_RESOURCE_PATH); assertThat(ctx.containsBean(TEST_BEAN_NAME), is(true)); }
@Test public void classRelativeResourceLoading_ctor() { ApplicationContext ctx = new GenericXmlApplicationContext(RELATIVE_CLASS, RESOURCE_NAME); assertThat(ctx.containsBean(TEST_BEAN_NAME), is(true)); }
@Test public void control() { GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(getClass(), "EnableLoadTimeWeavingTests-context.xml"); ctx.getBean("loadTimeWeaver", LoadTimeWeaver.class); }
@Test public void cacheResolver() { ConfigurableApplicationContext context = new GenericXmlApplicationContext( "/org/springframework/cache/config/annotationDrivenCacheNamespace-resolver.xml"); CacheInterceptor ci = context.getBean(CacheInterceptor.class); assertSame(context.getBean("cacheResolver"), ci.getCacheResolver()); context.close(); }
@Test public void cacheResolver() { ConfigurableApplicationContext context = new GenericXmlApplicationContext( "/org/springframework/cache/jcache/config/jCacheNamespaceDriven-resolver.xml"); DefaultJCacheOperationSource ci = context.getBean(DefaultJCacheOperationSource.class); assertSame(context.getBean("cacheResolver"), ci.getCacheResolver()); context.close(); }
@Test(timeout = 5000) public void checkTarget() { Task task = new GenericXmlApplicationContext( LazyScheduledTasksBeanDefinitionParserTests.class, "lazyScheduledTasksContext.xml") .getBean(Task.class); while (!task.executed) { try { Thread.sleep(10); } catch (Exception ex) { /* Do Nothing */ } } }
@Test public void bothSetOnlyResolverIsUsed() { ConfigurableApplicationContext context = new GenericXmlApplicationContext( "/org/springframework/cache/config/annotationDrivenCacheNamespace-manager-resolver.xml"); CacheInterceptor ci = context.getBean(CacheInterceptor.class); assertSame(context.getBean("cacheResolver"), ci.getCacheResolver()); context.close(); }
@Test public void keyAndKeyGeneratorCannotBeSetTogether() { try { new GenericXmlApplicationContext("/org/springframework/cache/config/cache-advice-invalid.xml"); fail("Should have failed to load context, one advise define both a key and a key generator"); } catch (BeanDefinitionStoreException ex) { // TODO better exception handling } }
@Test public void classRelativeResourceLoading_load() { GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(); ctx.load(RELATIVE_CLASS, RESOURCE_NAME); ctx.refresh(); assertThat(ctx.containsBean(TEST_BEAN_NAME), is(true)); }
@Test public void fullyQualifiedResourceLoading_load() { GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(); ctx.load(FQ_RESOURCE_PATH); ctx.refresh(); assertThat(ctx.containsBean(TEST_BEAN_NAME), is(true)); } }
@Test public void testGroovyBeanInterface() { context = new GenericXmlApplicationContext(getClass(), getClass().getSimpleName()+"-groovy-interface-context.xml"); TestService bean = context.getBean("groovyBean", TestService.class); LogUserAdvice logAdvice = context.getBean(LogUserAdvice.class); assertEquals(0, logAdvice.getCountThrows()); try { bean.sayHello(); fail("Expected exception"); } catch (RuntimeException ex) { assertEquals("GroovyServiceImpl", ex.getMessage()); } assertEquals(1, logAdvice.getCountThrows()); }
@Test public void propertyPlaceholderEnvironmentProperties() throws Exception { MockEnvironment env = new MockEnvironment().withProperty("foo", "spam"); GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext(); applicationContext.setEnvironment(env); applicationContext.load(new ClassPathResource("contextNamespaceHandlerTests-simple.xml", getClass())); applicationContext.refresh(); assertEquals("spam", applicationContext.getBean("string")); assertEquals("none", applicationContext.getBean("fallback")); }
@Test public void genericXmlApplicationContext() { GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(); assertHasStandardEnvironment(ctx); ctx.setEnvironment(prodEnv); ctx.load(XML_PATH); ctx.refresh(); assertHasEnvironment(ctx, prodEnv); assertEnvironmentBeanRegistered(ctx); assertEnvironmentAwareInvoked(ctx, prodEnv); assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false)); assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true)); }