@Test public void onSetContextCalledOnce() throws Exception { TestView tv = (TestView) rb.resolveViewName("test", Locale.ENGLISH); tv = (TestView) rb.resolveViewName("test", Locale.ENGLISH); tv = (TestView) rb.resolveViewName("test", Locale.ENGLISH); assertEquals("test has correct name", "test", tv.getBeanName()); assertEquals("test should have been initialized once, not ", 1, tv.initCount); }
@Test public void parentsAreAbstract() throws Exception { try { rb.resolveViewName("debug.Parent", Locale.ENGLISH); fail("Should have thrown BeanIsAbstractException"); } catch (BeanIsAbstractException ex) { // expected } try { rb.resolveViewName("testParent", Locale.ENGLISH); fail("Should have thrown BeanIsAbstractException"); } catch (BeanIsAbstractException ex) { // expected } }
@Test public void sameBundleOnlyCachedOnce() throws Exception { assumeTrue(rb.isCache()); View v1 = rb.resolveViewName("debugView", Locale.ENGLISH); View v2 = rb.resolveViewName("debugView", Locale.UK); assertSame(v1, v2); }
@Test(expected = MissingResourceException.class) public void noSuchBasename() throws Exception { rb.setBasename("weoriwoierqupowiuer"); rb.resolveViewName("debugView", Locale.ENGLISH); }
@Test public void noSuchViewEnglish() throws Exception { assertNull(rb.resolveViewName("xxxxxxweorqiwuopeir", Locale.ENGLISH)); }
@Test public void debugViewEnglish() throws Exception { View v = rb.resolveViewName("debugView", Locale.ENGLISH); assertThat(v, instanceOf(InternalResourceView.class)); InternalResourceView jv = (InternalResourceView) v; assertEquals("debugView must have correct URL", "jsp/debug/debug.jsp", jv.getUrl()); Map<String, Object> m = jv.getStaticAttributes(); assertEquals("Must have 2 static attributes", 2, m.size()); assertEquals("attribute foo", "bar", m.get("foo")); assertEquals("attribute postcode", "SE10 9JY", m.get("postcode")); assertEquals("Correct default content type", AbstractView.DEFAULT_CONTENT_TYPE, jv.getContentType()); }
@Test public void debugViewFrench() throws Exception { View v = rb.resolveViewName("debugView", Locale.FRENCH); assertThat(v, instanceOf(InternalResourceView.class)); InternalResourceView jv = (InternalResourceView) v; assertEquals("French debugView must have correct URL", "jsp/debug/deboug.jsp", jv.getUrl()); assertEquals("Correct overridden (XML) content type", "text/xml;charset=ISO-8859-1", jv.getContentType()); }
@Test public void eagerInitialization() throws Exception { ResourceBundleViewResolver rb = new ResourceBundleViewResolver(); rb.setBasename(PROPS_FILE); rb.setCache(getCache()); rb.setDefaultParentView("testParent"); rb.setLocalesToInitialize(new Locale[] {Locale.ENGLISH, Locale.FRENCH}); rb.setApplicationContext(wac); View v = rb.resolveViewName("debugView", Locale.FRENCH); assertThat(v, instanceOf(InternalResourceView.class)); InternalResourceView jv = (InternalResourceView) v; assertEquals("French debugView must have correct URL", "jsp/debug/deboug.jsp", jv.getUrl()); assertEquals("Correct overridden (XML) content type", "text/xml;charset=ISO-8859-1", jv.getContentType()); }