org.springframework.test.web.servlet.MockMvc Java Examples
The following examples show how to use
org.springframework.test.web.servlet.MockMvc.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpittleControllerTest.java From Project with Apache License 2.0 | 6 votes |
@Test public void shouldShowPagedSpittles() throws Exception { List<Spittle> expectedSpittles = createSpittleList(50); SpittleRepository mockRepository = mock(SpittleRepository.class); when(mockRepository.findSpittles(238900, 50)) .thenReturn(expectedSpittles); SpittleController controller = new SpittleController(mockRepository); MockMvc mockMvc = standaloneSetup(controller) .setSingleView(new InternalResourceView("/WEB-INF/views/spittles.jsp")) .build(); mockMvc.perform(get("/spittles?max=238900&count=50")) .andExpect(view().name("spittles")) .andExpect(model().attributeExists("spittleList")) .andExpect(model().attribute("spittleList", hasItems(expectedSpittles.toArray()))); }
Example #2
Source File: WebConfigurerTest.java From cubeai with Apache License 2.0 | 6 votes |
@Test public void testCorsFilterOnOtherPath() throws Exception { props.getCors().setAllowedOrigins(Collections.singletonList("*")); props.getCors().setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE")); props.getCors().setAllowedHeaders(Collections.singletonList("*")); props.getCors().setMaxAge(1800L); props.getCors().setAllowCredentials(true); MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()) .addFilters(webConfigurer.corsFilter()) .build(); mockMvc.perform( get("/test/test-cors") .header(HttpHeaders.ORIGIN, "other.domain.com")) .andExpect(status().isOk()) .andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)); }
Example #3
Source File: DiffSyncControllerTest.java From spring-sync with Apache License 2.0 | 6 votes |
@Test @Ignore public void noChangesFromClientSide_itemDeletedFromServer() throws Exception { TodoRepository todoRepository = todoRepository(); MockMvc mvc = mockMvc(todoRepository); performNoOpRequestToSetupShadow(mvc); repository.delete(2L); mvc.perform( patch(RESOURCE_PATH) .content("[]") .accept(JSON_PATCH) .contentType(JSON_PATCH)) .andExpect(content().string(resource("patch-remove-item"))) .andExpect(content().contentType(JSON_PATCH)) .andExpect(status().isOk()); List<Todo> all = (List<Todo>) repository.findAll(); assertEquals(2, all.size()); assertEquals(new Todo(1L, "A", false), all.get(0)); assertEquals(new Todo(3L, "C", false), all.get(1)); }
Example #4
Source File: WebConfigurerTest.java From cubeai with Apache License 2.0 | 6 votes |
@Test public void testCorsFilterOnOtherPath() throws Exception { props.getCors().setAllowedOrigins(Collections.singletonList("*")); props.getCors().setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE")); props.getCors().setAllowedHeaders(Collections.singletonList("*")); props.getCors().setMaxAge(1800L); props.getCors().setAllowCredentials(true); MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()) .addFilters(webConfigurer.corsFilter()) .build(); mockMvc.perform( get("/test/test-cors") .header(HttpHeaders.ORIGIN, "other.domain.com")) .andExpect(status().isOk()) .andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)); }
Example #5
Source File: FilterTests.java From java-technology-stack with MIT License | 6 votes |
@Test // SPR-16067, SPR-16695 public void filterWrapsRequestResponseAndPerformsAsyncDispatch() throws Exception { MockMvc mockMvc = standaloneSetup(new PersonController()) .addFilters(new WrappingRequestResponseFilter(), new ShallowEtagHeaderFilter()) .build(); MvcResult mvcResult = mockMvc.perform(get("/persons/1").accept(MediaType.APPLICATION_JSON)) .andExpect(request().asyncStarted()) .andExpect(request().asyncResult(new Person("Lukas"))) .andReturn(); mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isOk()) .andExpect(header().longValue("Content-Length", 53)) .andExpect(header().string("ETag", "\"0e37becb4f0c90709cb2e1efcc61eaa00\"")) .andExpect(content().string("{\"name\":\"Lukas\",\"someDouble\":0.0,\"someBoolean\":false}")); }
Example #6
Source File: DelegatingWebConnectionTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void verifyExampleInClassLevelJavadoc() throws Exception { Assume.group(TestGroup.PERFORMANCE); WebClient webClient = new WebClient(); MockMvc mockMvc = MockMvcBuilders.standaloneSetup().build(); MockMvcWebConnection mockConnection = new MockMvcWebConnection(mockMvc, webClient); WebRequestMatcher cdnMatcher = new UrlRegexRequestMatcher(".*?//code.jquery.com/.*"); WebConnection httpConnection = new HttpWebConnection(webClient); webClient.setWebConnection( new DelegatingWebConnection(mockConnection, new DelegateWebConnection(cdnMatcher, httpConnection))); Page page = webClient.getPage("https://code.jquery.com/jquery-1.11.0.min.js"); assertThat(page.getWebResponse().getStatusCode(), equalTo(200)); assertThat(page.getWebResponse().getContentAsString(), not(isEmptyString())); }
Example #7
Source File: DiffSyncControllerTest.java From spring-sync with Apache License 2.0 | 6 votes |
@Test public void patchSendsEntityStatusChange() throws Exception { TodoRepository todoRepository = todoRepository(); MockMvc mvc = mockMvc(todoRepository); mvc.perform( patch(RESOURCE_PATH + "/2") .content(resource("patch-change-entity-status")) .accept(JSON_PATCH) .contentType(JSON_PATCH)) .andExpect(status().isOk()) .andExpect(content().string("[]")) .andExpect(content().contentType(JSON_PATCH)); List<Todo> all = (List<Todo>) repository.findAll(); assertEquals(3, all.size()); assertEquals(new Todo(1L, "A", false), all.get(0)); assertEquals(new Todo(2L, "B", true), all.get(1)); assertEquals(new Todo(3L, "C", false), all.get(2)); }
Example #8
Source File: WebConfigurerTest.java From jhipster-microservices-example with Apache License 2.0 | 6 votes |
@Test public void testCorsFilterOnOtherPath() throws Exception { props.getCors().setAllowedOrigins(Collections.singletonList("*")); props.getCors().setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE")); props.getCors().setAllowedHeaders(Collections.singletonList("*")); props.getCors().setMaxAge(1800L); props.getCors().setAllowCredentials(true); MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()) .addFilters(webConfigurer.corsFilter()) .build(); mockMvc.perform( get("/test/test-cors") .header(HttpHeaders.ORIGIN, "other.domain.com")) .andExpect(status().isOk()) .andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)); }
Example #9
Source File: FileTestUtils.java From full-teaching with Apache License 2.0 | 6 votes |
public static FileGroup uploadTestFile(MockMvc mvc, HttpSession httpSession, FileGroup fg, Course c, MockMultipartFile file) { try { MvcResult result = mvc.perform(MockMvcRequestBuilders.fileUpload(upload_uri.replace("{courseId}",""+c.getId())+fg.getId()) .file(file) .session((MockHttpSession) httpSession) ).andReturn(); String content = result.getResponse().getContentAsString(); System.out.println(content); return json2FileGroup(content); } catch (Exception e) { e.printStackTrace(); fail("EXCEPTION: //FileTestUtils.uploadTestFile ::"+e.getClass().getName()); } return null; }
Example #10
Source File: TranslationSourceAPITest.java From singleton with Eclipse Public License 2.0 | 6 votes |
@Test public void test002v2createsource() throws Exception { MockMvc mockMvc = MockMvcBuilders.webAppContextSetup( webApplicationContext).build(); String API = L10nI18nAPI.TRANSLATION_SOURCE_APIV2 .replace("{" + APIParamName.PRODUCT_NAME + "}", "devCenter") .replace("{" + APIParamName.VERSION + "}", "2.2.0") .replace("{" + APIParamName.COMPONENT + "}", "test") .replace("{" + APIParamName.LOCALE + "}", "en"); MvcResult mvcRS =mockMvc.perform( MockMvcRequestBuilders.post(API) .param(APIParamName.SOURCE_FORMAT, "") .param(APIParamName.COLLECT_SOURCE, "true") .content("this a test v2 source ") .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()).andReturn(); String resultStr = mvcRS.getResponse().getContentAsString(); logger.info(resultStr); }
Example #11
Source File: RecordControllerTest.java From singleton with Eclipse Public License 2.0 | 6 votes |
@Test public void test003synchRecoredModel() throws Exception { String l10nsynchUrl =GATEWAYPREF+ L10NAPIV1.API_L10N+"/synchrecord"; MockMvc mockMvc = MockMvcBuilders.webAppContextSetup( webApplicationContext).build(); MvcResult mvcRS =mockMvc.perform( post(l10nsynchUrl).param("product", "unittest") .param("version", "1.0.0") .param("component", "default") .param("locale", "EN") .param("status", "2") .accept(MediaType.APPLICATION_JSON)).andReturn(); String resultStr = mvcRS.getResponse().getContentAsString(); logger.info(resultStr); }
Example #12
Source File: WebConfigurerTest.java From 21-points with Apache License 2.0 | 6 votes |
@Test public void testCorsFilterOnOtherPath() throws Exception { props.getCors().setAllowedOrigins(Collections.singletonList("*")); props.getCors().setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE")); props.getCors().setAllowedHeaders(Collections.singletonList("*")); props.getCors().setMaxAge(1800L); props.getCors().setAllowCredentials(true); MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()) .addFilters(webConfigurer.corsFilter()) .build(); mockMvc.perform( get("/test/test-cors") .header(HttpHeaders.ORIGIN, "other.domain.com")) .andExpect(status().isOk()) .andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)); }
Example #13
Source File: SpittleControllerTest.java From Project with Apache License 2.0 | 6 votes |
@Test public void houldShowRecentSpittles() throws Exception { List<Spittle> expectedSpittles = createSpittleList(20); SpittleRepository mockRepository = mock(SpittleRepository.class); when(mockRepository.findSpittles(Long.MAX_VALUE, 20)) .thenReturn(expectedSpittles); SpittleController controller = new SpittleController(mockRepository); MockMvc mockMvc = standaloneSetup(controller) .setSingleView(new InternalResourceView("/WEB-INF/views/spittles.jsp")) .build(); mockMvc.perform(get("/spittles")) .andExpect(view().name("spittles")) .andExpect(model().attributeExists("spittleList")) .andExpect(model().attribute("spittleList", hasItems(expectedSpittles.toArray()))); }
Example #14
Source File: WebConfigurerTest.java From albedo with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testCorsFilterOnOtherPath() throws Exception { props.getCors().setAllowedOrigins(Collections.singletonList("*")); props.getCors().setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE")); props.getCors().setAllowedHeaders(Collections.singletonList("*")); props.getCors().setMaxAge(1800L); props.getCors().setAllowCredentials(true); MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()) .addFilters(webConfigurer.corsFilter()) .build(); mockMvc.perform( get("/test/test-cors") .header(HttpHeaders.ORIGIN, "other.domain.com")) .andExpect(status().isOk()) .andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)); }
Example #15
Source File: RecordControllerTest.java From singleton with Eclipse Public License 2.0 | 6 votes |
@Test public void test002getSourceComponentModel() throws Exception { RecordModel record = new RecordModel(); record.setProduct("unittest"); record.setVersion("1.0.0"); record.setComponent("default"); record.setLocale("EN"); String getComponentUrl = GATEWAYPREF+L10NAPIV1.API_L10N + "/sourcecomponent/" + record.getProduct() + "/" + record.getVersion() + "/" + record.getComponent() + "/" + record.getLocale() + "/"; MockMvc mockMvc = MockMvcBuilders.webAppContextSetup( webApplicationContext).build(); MvcResult mvcRS = mockMvc.perform(MockMvcRequestBuilders.get(getComponentUrl)).andExpect(MockMvcResultMatchers.status().isOk()).andReturn(); String resultStr = mvcRS.getResponse().getContentAsString(); logger.info(resultStr); }
Example #16
Source File: TranslationCollectKeyAPITest.java From singleton with Eclipse Public License 2.0 | 6 votes |
@Test public void test004collectV2KeyTranslation() throws Exception { MockMvc mockMvc = MockMvcBuilders.webAppContextSetup( webApplicationContext).build(); String API = L10nI18nAPI.KEY_TRANSLATION_APIV2 .replace("{" + APIParamName.PRODUCT_NAME + "}", "TestCenter") .replace("{" + APIParamName.VERSION + "}", "2.0.0") .replace("{" + APIParamName.COMPONENT + "}", "testing") .replace("{" + APIParamName.LOCALE + "}", "en") .replace("{" +APIParamName.KEY+ "}", "testkey"); logger.info(API); MvcResult mvcRS =mockMvc.perform( MockMvcRequestBuilders.post(API) .content("this open3's value") .param(APIParamName.COMMENT_SOURCE, "dc new string") .param(APIParamName.SOURCE_FORMAT, "") .param(APIParamName.COLLECT_SOURCE, "true") .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()).andReturn(); String resultStr = mvcRS.getResponse().getContentAsString(); logger.info(resultStr); }
Example #17
Source File: SpittleControllerTest.java From Project with Apache License 2.0 | 6 votes |
@Test public void houldShowRecentSpittles() throws Exception { List<Spittle> expectedSpittles = createSpittleList(20); SpittleRepository mockRepository = mock(SpittleRepository.class); when(mockRepository.findSpittles(Long.MAX_VALUE, 20)) .thenReturn(expectedSpittles); SpittleController controller = new SpittleController(mockRepository); MockMvc mockMvc = standaloneSetup(controller) .setSingleView(new InternalResourceView("/WEB-INF/views/spittles.jsp")) .build(); mockMvc.perform(get("/spittles")) .andExpect(view().name("spittles")) .andExpect(model().attributeExists("spittleList")) .andExpect(model().attribute("spittleList", hasItems(expectedSpittles.toArray()))); }
Example #18
Source File: WebConfigurerTest.java From okta-jhipster-microservices-oauth-example with Apache License 2.0 | 5 votes |
@Test public void testCorsFilterDeactivated2() throws Exception { props.getCors().setAllowedOrigins(new ArrayList<>()); MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()) .addFilters(webConfigurer.corsFilter()) .build(); mockMvc.perform( get("/api/test-cors") .header(HttpHeaders.ORIGIN, "other.domain.com")) .andExpect(status().isOk()) .andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)); }
Example #19
Source File: WebConfigurerTest.java From e-commerce-microservice with Apache License 2.0 | 5 votes |
@Test public void testCorsFilterOnApiPath() throws Exception { props.getCors().setAllowedOrigins(Collections.singletonList("*")); props.getCors().setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE")); props.getCors().setAllowedHeaders(Collections.singletonList("*")); props.getCors().setMaxAge(1800L); props.getCors().setAllowCredentials(true); MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()) .addFilters(webConfigurer.corsFilter()) .build(); mockMvc.perform( options("/api/test-cors") .header(HttpHeaders.ORIGIN, "other.domain.com") .header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "POST")) .andExpect(status().isOk()) .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, "other.domain.com")) .andExpect(header().string(HttpHeaders.VARY, "Origin")) .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS, "GET,POST,PUT,DELETE")) .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true")) .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_MAX_AGE, "1800")); mockMvc.perform( get("/api/test-cors") .header(HttpHeaders.ORIGIN, "other.domain.com")) .andExpect(status().isOk()) .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, "other.domain.com")); }
Example #20
Source File: EnvironmentControllerTests.java From spring-cloud-config with Apache License 2.0 | 5 votes |
@Test public void mappingForLabelledYamlWithHyphen() throws Exception { when(this.repository.findOne("foo-bar-foo2-bar2", "spam", "other", false)) .thenReturn(this.environment); MockMvc mvc = MockMvcBuilders.standaloneSetup(this.controller).build(); mvc.perform(MockMvcRequestBuilders.get("/other/foo-bar-foo2-bar2-spam.yml")) .andExpect(MockMvcResultMatchers.content() .contentType(MediaType.TEXT_PLAIN)); }
Example #21
Source File: WebConfigurerTest.java From albedo with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void testCorsFilterDeactivated2() throws Exception { props.getCors().setAllowedOrigins(new ArrayList<>()); MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()) .addFilters(webConfigurer.corsFilter()) .build(); mockMvc.perform( get("/api/test-cors") .header(HttpHeaders.ORIGIN, "other.domain.com")) .andExpect(status().isOk()) .andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)); }
Example #22
Source File: HtmlUnitRequestBuilderTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void mergeRequestAttribute() throws Exception { String attrName = "PARENT"; String attrValue = "VALUE"; MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new HelloController()) .defaultRequest(get("/").requestAttr(attrName, attrValue)) .build(); assertThat(mockMvc.perform(requestBuilder).andReturn().getRequest().getAttribute(attrName), equalTo(attrValue)); }
Example #23
Source File: MockHttpRequestHelper.java From jfilter with Apache License 2.0 | 5 votes |
private static String getContent(MockMvc mockMvc, MockHttpServletRequestBuilder requestBuilder) { final StringBuilder result = new StringBuilder(); try { mockMvc.perform(requestBuilder) .andDo(print()) .andExpect(mvcResult -> result.append(mvcResult.getResponse().getContentAsString())); } catch (Exception e) { return result.toString(); } return result.toString(); }
Example #24
Source File: TranslationCollectKeyAPITest.java From singleton with Eclipse Public License 2.0 | 5 votes |
@Test public void test001collectV1StringTranslation() throws Exception { MockMvc mockMvc = MockMvcBuilders.webAppContextSetup( webApplicationContext).build(); String API =L10nI18nAPI.TRANSLATION_KEY_APIV1; MvcResult mvcRS =mockMvc.perform( MockMvcRequestBuilders.post(API).param(Constants.VERSION, "1.0.0") .param(APIParamName.PRODUCT_NAME, "PRODUCTTEST") .param(APIParamName.COMPONENT, "testComp") .param(APIParamName.LOCALE, "en") .param(APIParamName.KEY, "testsourcekey") .param(APIParamName.SOURCE_FORMAT, "") .param(APIParamName.COLLECT_SOURCE, "true") .param(Constants.SOURCE, "this open3's value") .param(Constants.COMMENT_FOR_SOURCE, "dc new string") .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()).andReturn(); String resultStr = mvcRS.getResponse().getContentAsString(); logger.info(resultStr); MvcResult mvcRS2 =mockMvc.perform( MockMvcRequestBuilders.post(API).param(Constants.VERSION, "1.0.0") .param(APIParamName.PRODUCT_NAME, "PRODUCTTEST") .param(APIParamName.COMPONENT, "testComp") /// .param(APIParamName.LOCALE, "en") .param(APIParamName.KEY, "testsourcenullkey") // .param(APIParamName.SOURCE_FORMAT, "") .param(APIParamName.COLLECT_SOURCE, "true") //.param(Constants.SOURCE, "this open3's value") //.param(Constants.COMMENT_FOR_SOURCE, "dc new string") .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()).andReturn(); String resultStr2 = mvcRS2.getResponse().getContentAsString(); logger.info(resultStr2); }
Example #25
Source File: WebConfigurerTest.java From jhipster-microservices-example with Apache License 2.0 | 5 votes |
@Test public void testCorsFilterOnApiPath() throws Exception { props.getCors().setAllowedOrigins(Collections.singletonList("*")); props.getCors().setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE")); props.getCors().setAllowedHeaders(Collections.singletonList("*")); props.getCors().setMaxAge(1800L); props.getCors().setAllowCredentials(true); MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()) .addFilters(webConfigurer.corsFilter()) .build(); mockMvc.perform( options("/api/test-cors") .header(HttpHeaders.ORIGIN, "other.domain.com") .header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "POST")) .andExpect(status().isOk()) .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, "other.domain.com")) .andExpect(header().string(HttpHeaders.VARY, "Origin")) .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS, "GET,POST,PUT,DELETE")) .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true")) .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_MAX_AGE, "1800")); mockMvc.perform( get("/api/test-cors") .header(HttpHeaders.ORIGIN, "other.domain.com")) .andExpect(status().isOk()) .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, "other.domain.com")); }
Example #26
Source File: WebConfigurerTest.java From Full-Stack-Development-with-JHipster with MIT License | 5 votes |
@Test public void testCorsFilterOnApiPath() throws Exception { props.getCors().setAllowedOrigins(Collections.singletonList("*")); props.getCors().setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE")); props.getCors().setAllowedHeaders(Collections.singletonList("*")); props.getCors().setMaxAge(1800L); props.getCors().setAllowCredentials(true); MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()) .addFilters(webConfigurer.corsFilter()) .build(); mockMvc.perform( options("/api/test-cors") .header(HttpHeaders.ORIGIN, "other.domain.com") .header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "POST")) .andExpect(status().isOk()) .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, "other.domain.com")) .andExpect(header().string(HttpHeaders.VARY, "Origin")) .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS, "GET,POST,PUT,DELETE")) .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true")) .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_MAX_AGE, "1800")); mockMvc.perform( get("/api/test-cors") .header(HttpHeaders.ORIGIN, "other.domain.com")) .andExpect(status().isOk()) .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, "other.domain.com")); }
Example #27
Source File: SpitterControllerTest.java From Project with Apache License 2.0 | 5 votes |
@Test public void shouldShowRegistration() throws Exception { SpitterRepository mockRepository = mock(SpitterRepository.class); SpitterController controller = new SpitterController(mockRepository); MockMvc mockMvc = standaloneSetup(controller).build(); mockMvc.perform(get("/spitter/register")) .andExpect(view().name("registerForm")); }
Example #28
Source File: WebConfigurerTest.java From TeamDojo with Apache License 2.0 | 5 votes |
@Test public void testCorsFilterOnApiPath() throws Exception { props.getCors().setAllowedOrigins(Collections.singletonList("*")); props.getCors().setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE")); props.getCors().setAllowedHeaders(Collections.singletonList("*")); props.getCors().setMaxAge(1800L); props.getCors().setAllowCredentials(true); MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()) .addFilters(webConfigurer.corsFilter()) .build(); mockMvc.perform( options("/api/test-cors") .header(HttpHeaders.ORIGIN, "other.domain.com") .header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "POST")) .andExpect(status().isOk()) .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, "other.domain.com")) .andExpect(header().string(HttpHeaders.VARY, "Origin")) .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS, "GET,POST,PUT,DELETE")) .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true")) .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_MAX_AGE, "1800")); mockMvc.perform( get("/api/test-cors") .header(HttpHeaders.ORIGIN, "other.domain.com")) .andExpect(status().isOk()) .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, "other.domain.com")); }
Example #29
Source File: WebConfigurerTest.java From cubeai with Apache License 2.0 | 5 votes |
@Test public void testCorsFilterOnApiPath() throws Exception { props.getCors().setAllowedOrigins(Collections.singletonList("*")); props.getCors().setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE")); props.getCors().setAllowedHeaders(Collections.singletonList("*")); props.getCors().setMaxAge(1800L); props.getCors().setAllowCredentials(true); MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()) .addFilters(webConfigurer.corsFilter()) .build(); mockMvc.perform( options("/api/test-cors") .header(HttpHeaders.ORIGIN, "other.domain.com") .header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "POST")) .andExpect(status().isOk()) .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, "other.domain.com")) .andExpect(header().string(HttpHeaders.VARY, "Origin")) .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS, "GET,POST,PUT,DELETE")) .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true")) .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_MAX_AGE, "1800")); mockMvc.perform( get("/api/test-cors") .header(HttpHeaders.ORIGIN, "other.domain.com")) .andExpect(status().isOk()) .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, "other.domain.com")); }
Example #30
Source File: WebConfigurerTest.java From cubeai with Apache License 2.0 | 5 votes |
@Test public void testCorsFilterDeactivated() throws Exception { props.getCors().setAllowedOrigins(null); MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()) .addFilters(webConfigurer.corsFilter()) .build(); mockMvc.perform( get("/api/test-cors") .header(HttpHeaders.ORIGIN, "other.domain.com")) .andExpect(status().isOk()) .andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)); }