@Test public void testNodeCount() throws Exception { this.mockMvc.perform(get("/music/people")) .andExpect(xpath("/ns:people/composers/composer", musicNamespace).nodeCount(4)) .andExpect(xpath("/ns:people/performers/performer", musicNamespace).nodeCount(2)) .andExpect(xpath("/ns:people/composers/composer", musicNamespace).nodeCount(equalTo(4))) // Hamcrest.. .andExpect(xpath("/ns:people/performers/performer", musicNamespace).nodeCount(equalTo(2))); }
@Test public void testDoesNotExist() throws Exception { String composer = "/ns:people/composers/composer[%s]"; String performer = "/ns:people/performers/performer[%s]"; this.mockMvc.perform(get("/music/people")) .andExpect(xpath(composer, musicNamespace, 0).doesNotExist()) .andExpect(xpath(composer, musicNamespace, 5).doesNotExist()) .andExpect(xpath(performer, musicNamespace, 0).doesNotExist()) .andExpect(xpath(performer, musicNamespace, 3).doesNotExist()) .andExpect(xpath(composer, musicNamespace, 0).node(nullValue())); }
@Test public void testExists() throws Exception { String composer = "/ns:people/composers/composer[%s]"; String performer = "/ns:people/performers/performer[%s]"; this.mockMvc.perform(get("/music/people")) .andExpect(xpath(composer, musicNamespace, 1).exists()) .andExpect(xpath(composer, musicNamespace, 2).exists()) .andExpect(xpath(composer, musicNamespace, 3).exists()) .andExpect(xpath(composer, musicNamespace, 4).exists()) .andExpect(xpath(performer, musicNamespace, 1).exists()) .andExpect(xpath(performer, musicNamespace, 2).exists()) .andExpect(xpath(composer, musicNamespace, 1).node(notNullValue())); }
@Test public void testNumber() throws Exception { String composerDouble = "/ns:people/composers/composer[%s]/someDouble"; this.mockMvc.perform(get("/music/people")) .andExpect(xpath(composerDouble, musicNamespace, 1).number(21d)) .andExpect(xpath(composerDouble, musicNamespace, 2).number(.0025)) .andExpect(xpath(composerDouble, musicNamespace, 3).number(1.6035)) .andExpect(xpath(composerDouble, musicNamespace, 4).number(Double.NaN)) .andExpect(xpath(composerDouble, musicNamespace, 1).number(equalTo(21d))) // Hamcrest.. .andExpect(xpath(composerDouble, musicNamespace, 3).number(closeTo(1.6, .01))); }
@Test public void testString() throws Exception { String composerName = "/ns:people/composers/composer[%s]/name"; String performerName = "/ns:people/performers/performer[%s]/name"; this.mockMvc.perform(get("/music/people")) .andExpect(xpath(composerName, musicNamespace, 1).string("Johann Sebastian Bach")) .andExpect(xpath(composerName, musicNamespace, 2).string("Johannes Brahms")) .andExpect(xpath(composerName, musicNamespace, 3).string("Edvard Grieg")) .andExpect(xpath(composerName, musicNamespace, 4).string("Robert Schumann")) .andExpect(xpath(performerName, musicNamespace, 1).string("Vladimir Ashkenazy")) .andExpect(xpath(performerName, musicNamespace, 2).string("Yehudi Menuhin")) .andExpect(xpath(composerName, musicNamespace, 1).string(equalTo("Johann Sebastian Bach"))) // Hamcrest.. .andExpect(xpath(composerName, musicNamespace, 1).string(startsWith("Johann"))) .andExpect(xpath(composerName, musicNamespace, 1).string(notNullValue())); }
@Test public void testBoolean() throws Exception { String performerBooleanValue = "/ns:people/performers/performer[%s]/someBoolean"; this.mockMvc.perform(get("/music/people")) .andExpect(xpath(performerBooleanValue, musicNamespace, 1).booleanValue(false)) .andExpect(xpath(performerBooleanValue, musicNamespace, 2).booleanValue(true)); }
@Test void testExternalizedBranding(@Autowired MockMvc mockMvc) throws Exception { mockMvc.perform(MockMvcRequestBuilders.get("/login")) .andExpect(xpath("//head/link[@rel='shortcut icon']/@href").string("//cdn.example.com/pivotal/images/square-logo.png")) .andExpect(xpath("//head/link[@href='//cdn.example.com/pivotal/stylesheets/application.css']").exists()) .andExpect(xpath("//head/style[text()[contains(.,'//cdn.example.com/pivotal/images/product-logo.png')]]").exists()); } }
@Test public void tilesFromClientMetadataAndTilesConfigShown_forOtherZone() throws Exception { IdentityZone identityZone = MultitenancyFixture.identityZone("test", "test"); IdentityZoneHolder.set(identityZone); mockMvc.perform(get("/")) .andExpect(xpath("//*[@id='tile-1'][text()[contains(.,'client-1')]]").exists()) .andExpect(xpath("//*[@class='tile-1']/@href").string("http://app.launch/url")) .andExpect(xpath("//head/style[1]").string(".tile-1 .tile-icon {background-image: url(\"data:image/png;base64," + base64EncodedImg + "\")}")) .andExpect(xpath("//*[@id='tile-2'][text()[contains(.,'Client 2 Name')]]").exists()) .andExpect(xpath("//*[@class='tile-2']/@href").string("http://second.url/")) .andExpect(xpath("//*[@class='tile-3']").doesNotExist()); }
@Test void testDefaultBranding() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get("/login")) .andExpect(xpath("//head/link[@rel='shortcut icon']/@href").string("/resources/oss/images/square-logo.png")) .andExpect(xpath("//head/link[@href='/resources/oss/stylesheets/application.css']").exists()) .andExpect(xpath("//head/style[text()[contains(.,'/resources/oss/images/product-logo.png')]]").exists()); }
@Test public void testFeedWithLinefeedChars() throws Exception { // Map<String, String> namespace = Collections.singletonMap("ns", ""); standaloneSetup(new BlogFeedController()).build() .perform(get("/blog.atom").accept(MediaType.APPLICATION_ATOM_XML)) .andExpect(status().isOk()) .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_ATOM_XML)) .andExpect(xpath("//feed/title").string("Test Feed")) .andExpect(xpath("//feed/icon").string("http://www.example.com/favicon.ico")); }
@Test void testSignupsAndResetPasswordDisabledWithNoLinksConfigured() throws Exception { MockMvcUtils.setSelfServiceLinksEnabled(webApplicationContext, getUaa().getId(), false); mockMvc.perform(MockMvcRequestBuilders.get("/login")) .andExpect(xpath("//a[text()='Create account']").doesNotExist()) .andExpect(xpath("//a[text()='Reset password']").doesNotExist()); }
@Test public void testXmlOnly() throws Exception { Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); marshaller.setClassesToBeBound(Person.class); standaloneSetup(new PersonController()).setSingleView(new MarshallingView(marshaller)).build() .perform(get("/person/Corea")) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_XML)) .andExpect(xpath("/person/name/text()").string(equalTo("Corea"))); }
@Test void testActivationEmailSentPage() throws Exception { mockMvc.perform(get("/accounts/email_sent")) .andExpect(status().isOk()) .andExpect(content().string(containsString("Create your account"))) .andExpect(xpath("//input[@disabled='disabled']/@value").string("Email successfully sent")); }
@Test void resetPasswordNotEnabled() throws Exception { mockMvc.perform(get("/login")) .andExpect(status().isOk()) .andExpect(xpath("//a[@href='/forgot_password']").doesNotExist()); } }
@Test void createAccountNotEnabled() throws Exception { mockMvc.perform(get("/login")) .andExpect(status().isOk()) .andExpect(xpath("//a[@href='/create_account']").doesNotExist()); }
@Test void testSignupsAndResetPasswordEnabledWithCustomLinks() throws Exception { identityZoneConfiguration.getLinks().getSelfService().setSignup("http://example.com/signup"); identityZoneConfiguration.getLinks().getSelfService().setPasswd("http://example.com/reset_passwd"); identityZoneConfiguration.getLinks().getSelfService().setSelfServiceLinksEnabled(true); MockMvcUtils.setZoneConfiguration(webApplicationContext, getUaa().getId(), identityZoneConfiguration); mockMvc.perform(MockMvcRequestBuilders.get("/login")) .andExpect(xpath("//a[text()='Create account']/@href").string("http://example.com/signup")) .andExpect(xpath("//a[text()='Reset password']/@href").string("http://example.com/reset_passwd")); }
@Test void testSignupsAndResetPasswordDisabledWithSomeLinksConfigured() throws Exception { identityZoneConfiguration.getLinks().getSelfService().setSignup("http://example.com/signup"); identityZoneConfiguration.getLinks().getSelfService().setPasswd("http://example.com/reset_passwd"); identityZoneConfiguration.getLinks().getSelfService().setSelfServiceLinksEnabled(false); MockMvcUtils.setZoneConfiguration(webApplicationContext, getUaa().getId(), identityZoneConfiguration); mockMvc.perform(MockMvcRequestBuilders.get("/login")) .andExpect(xpath("//a[text()='Create account']").doesNotExist()) .andExpect(xpath("//a[text()='Reset password']").doesNotExist()); }
@Test void testActivationEmailSentPageWithinZone() throws Exception { String subdomain = generator.generate(); MockMvcUtils.createOtherIdentityZone(subdomain, mockMvc, webApplicationContext); mockMvc.perform(get("/accounts/email_sent") .with(new SetServerNameRequestPostProcessor(subdomain + ".localhost"))) .andExpect(status().isOk()) .andExpect(content().string(containsString("Create your account"))) .andExpect(xpath("//input[@disabled='disabled']/@value").string("Email successfully sent")) .andExpect(content().string(containsString("Cloud Foundry"))); }
@Test public void testChangeEmailPage() throws Exception { setupSecurityContext(); mockMvc.perform(get("/change_email").param("client_id", "client-id").param("redirect_uri", "http://example.com/redirect")) .andExpect(status().isOk()) .andExpect(view().name("change_email")) .andExpect(model().attribute("email", "user@example.com")) .andExpect(model().attribute("client_id", "client-id")) .andExpect(model().attribute("redirect_uri", "http://example.com/redirect")) .andExpect(xpath("//*[@type='hidden' and @value='client-id']").exists()) .andExpect(xpath("//*[@type='hidden' and @value='http://example.com/redirect']").exists()); }
.andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_XML)) .andExpect(xpath("/person/name/text()").string(equalTo("Corea")));