@Before public void setUp() throws Exception { System.setProperty("BUCKET", "MYBUCKET"); System.setProperty("CONNECTIONS", "30"); System.setProperty("ENABLED", "true"); System.setProperty("ALLOW_ENV_PARAMETRIZATION", "true"); ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("appContextTestS3.xml"); GeoWebCacheExtensions gse = new GeoWebCacheExtensions(); gse.setApplicationContext(context); }
protected void setUp() throws Exception { super.setUp(); System.setProperty("TEST_JDBC_DRIVER", "org.postgresql.Driver"); System.setProperty("TEST_JDBC_URL", "jdbc:postgresql:gttest"); System.setProperty("TEST_JDBC_USER", "test"); System.setProperty("TEST_JDBC_PASSWORD", "toast"); System.setProperty("ALLOW_ENV_PARAMETRIZATION", "true"); GeoWebCacheExtensions gse = new GeoWebCacheExtensions(); GeoWebCacheEnvironment genv = new GeoWebCacheEnvironment(); gse.setApplicationContext(appContext); expect(appContext.getBeanNamesForType(GeoWebCacheEnvironment.class)) .andReturn(new String[] {"environment"}); expect(appContext.getBean("environment")).andReturn(genv); Map<String, GeoWebCacheEnvironment> genvMap = new HashMap<>(); genvMap.put("environment", genv); expect(appContext.getBeansOfType(GeoWebCacheEnvironment.class)) .andReturn(genvMap) .anyTimes(); expect(appContext.getBean("environment")).andReturn(genv).anyTimes(); replay(appContext); }
@Test public void testExtensionsWithPriority() { // creating a spring context with some beans that will implements priority interface ApplicationContext appContext = createMock(ApplicationContext.class); BeanWithPriority beanA = new BeanWithPriority(15, "beanA"); BeanWithPriority beanB = new BeanWithPriority(3, "beanB"); BeanWithPriority beanC = new BeanWithPriority(27, "beanC"); Map<String, BeanWithPriority> beans = new HashMap<>(); beans.put("beanA", beanA); beans.put("beanB", beanB); beans.put("beanC", beanC); // defining invocations expectations expect(appContext.getBeansOfType(BeanWithPriority.class)).andReturn(beans); expect(appContext.getBean("beanA")).andReturn(beanA); expect(appContext.getBean("beanB")).andReturn(beanB); expect(appContext.getBean("beanC")).andReturn(beanC); replay(appContext); // registering our mocked spring application context GeoWebCacheExtensions gwcExtensions = new GeoWebCacheExtensions(); gwcExtensions.setApplicationContext(appContext); // the cache should be empty assertThat(GeoWebCacheExtensions.extensionsCache.size(), is(0)); // we should get beans ordered by their priority List<BeanWithPriority> extensions = GeoWebCacheExtensions.extensions(BeanWithPriority.class); assertThat(extensions.size(), is(3)); assertThat(extensions, Matchers.contains(beanB, beanA, beanC)); verify(appContext); }
@Test public void testBeanString() { ApplicationContext appContext = createMock(ApplicationContext.class); GeoWebCacheExtensions gse = new GeoWebCacheExtensions(); gse.setApplicationContext(null); assertNull(GeoWebCacheExtensions.bean("beanName")); gse.setApplicationContext(appContext); expect(appContext.getBean("beanName")).andReturn(null); // call #1 expect(appContext.getBean("beanName")).andReturn(this); // call #2 replay(appContext); assertNull(GeoWebCacheExtensions.bean("beanName")); // call #1 assertSame(this, GeoWebCacheExtensions.bean("beanName")); // call #2 verify(appContext); }
public void testEnvironment() { ApplicationContext appContext = createMock(ApplicationContext.class); GeoWebCacheEnvironment genv = new GeoWebCacheEnvironment(); assertEquals(0, GeoWebCacheExtensions.extensionsCache.size()); expect(appContext.getBeanNamesForType(GeoWebCacheEnvironment.class)) .andReturn(new String[] {"geoWebCacheEnvironment"}); expect(appContext.getBean("geoWebCacheEnvironment")).andReturn(genv); Map<String, GeoWebCacheEnvironment> genvMap = new HashMap<>(); genvMap.put("geoWebCacheEnvironment", genv); expect(appContext.getBeansOfType(GeoWebCacheEnvironment.class)) .andReturn(genvMap) .anyTimes(); replay(appContext); GeoWebCacheExtensions gse = new GeoWebCacheExtensions(); gse.setApplicationContext(appContext); List<GeoWebCacheEnvironment> extensions = GeoWebCacheExtensions.extensions(GeoWebCacheEnvironment.class); assertNotNull(extensions); assertEquals(1, extensions.size()); assertTrue(extensions.contains(genv)); assertTrue(GeoWebCacheEnvironment.ALLOW_ENV_PARAMETRIZATION); }
/** * If a context is explicitly provided that is not the one set through setApplicationContext(), * the extensions() method shall look into it and bypass the cache */ @Test public void testExtensionsApplicationContext() { ApplicationContext appContext = createMock(ApplicationContext.class); ApplicationContext customAppContext = createMock(ApplicationContext.class); GeoWebCacheExtensions gse = new GeoWebCacheExtensions(); gse.setApplicationContext(appContext); // context beans Map<String, GeoWebCacheExtensionsTest> beans = new HashMap<>(); beans.put("itDoesntMatterForThePurpose", this); // setApplicationContext cleared the static cache assertEquals(0, GeoWebCacheExtensions.extensionsCache.size()); // set the expectation over the app context used as argument expect(customAppContext.getBeansOfType(GeoWebCacheExtensionsTest.class)).andReturn(beans); expect(customAppContext.getBean("itDoesntMatterForThePurpose")).andReturn(this); replay(customAppContext); replay(appContext); List<GeoWebCacheExtensionsTest> extensions = GeoWebCacheExtensions.extensions(GeoWebCacheExtensionsTest.class, customAppContext); assertNotNull(extensions); assertEquals(1, extensions.size()); assertSame(this, extensions.get(0)); // cache should be untouched after this since our own context were used assertEquals(0, GeoWebCacheExtensions.extensionsCache.size()); verify(appContext); verify(customAppContext); }
@Test public void testSetApplicationContext() { ApplicationContext appContext1 = createMock(ApplicationContext.class); ApplicationContext appContext2 = createMock(ApplicationContext.class); GeoWebCacheExtensions gse = new GeoWebCacheExtensions(); gse.setApplicationContext(appContext1); GeoWebCacheExtensions.extensionsCache.put( GeoWebCacheExtensionsTest.class, new String[] {"fake"}); assertSame(appContext1, GeoWebCacheExtensions.context); gse.setApplicationContext(appContext2); assertSame(appContext2, GeoWebCacheExtensions.context); assertEquals(0, GeoWebCacheExtensions.extensionsCache.size()); }
@Test public void testExtensions() { ApplicationContext appContext = createMock(ApplicationContext.class); GeoWebCacheExtensions gse = new GeoWebCacheExtensions(); gse.setApplicationContext(appContext);
replay(appContext); GeoWebCacheExtensions gwcExtensions = new GeoWebCacheExtensions(); gwcExtensions.setApplicationContext(appContext);