Java Code Examples for org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder#contentType()
The following examples show how to use
org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder#contentType() .
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: JobConfigControllerTestIT.java From blackduck-alert with Apache License 2.0 | 6 votes |
@Test @WithMockUser(roles = AlertIntegrationTest.ROLE_ALERT_ADMIN) public void testSaveConfig() throws Exception { addGlobalConfiguration(blackDuckProviderKey, Map.of( BlackDuckDescriptor.KEY_BLACKDUCK_URL, List.of("BLACKDUCK_URL"), BlackDuckDescriptor.KEY_BLACKDUCK_API_KEY, List.of("BLACKDUCK_API"))); MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(url) .with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTest.ROLE_ALERT_ADMIN)) .with(SecurityMockMvcRequestPostProcessors.csrf()); JobFieldModel fieldModel = createTestJobFieldModel(null, null); request.content(gson.toJson(fieldModel)); request.contentType(contentType); MvcResult mvcResult = mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isCreated()).andReturn(); String response = mvcResult.getResponse().getContentAsString(); checkResponse(response); }
Example 2
Source File: JobConfigControllerTestIT.java From blackduck-alert with Apache License 2.0 | 6 votes |
@Test @WithMockUser(roles = AlertIntegrationTest.ROLE_ALERT_ADMIN) public void testValidateConfig() throws Exception { final String urlPath = url + "/validate"; addGlobalConfiguration(blackDuckProviderKey, Map.of( BlackDuckDescriptor.KEY_BLACKDUCK_URL, List.of("BLACKDUCK_URL"), BlackDuckDescriptor.KEY_BLACKDUCK_API_KEY, List.of("BLACKDUCK_API"))); MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(urlPath) .with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTest.ROLE_ALERT_ADMIN)) .with(SecurityMockMvcRequestPostProcessors.csrf()); JobFieldModel fieldModel = createTestJobFieldModel(null, null); request.content(gson.toJson(fieldModel)); request.contentType(contentType); mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk()); }
Example 3
Source File: SystemControllerTestIT.java From blackduck-alert with Apache License 2.0 | 5 votes |
@Test @WithMockUser(roles = AlertIntegrationTest.ROLE_ALERT_ADMIN) public void testPostInitialSystemSetup() throws Exception { final HashMap<String, FieldValueModel> valueModelMap = new HashMap<>(); final FieldModel configuration = new FieldModel("a_key", ConfigContextEnum.GLOBAL.name(), valueModelMap); final MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(SYSTEM_INITIAL_SETUP_BASE_URL) .with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTest.ROLE_ALERT_ADMIN)) .with(SecurityMockMvcRequestPostProcessors.csrf()); request.content(gson.toJson(configuration)); request.contentType(contentType); mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isNotFound()); }
Example 4
Source File: AuthenticationControllerTestIT.java From blackduck-alert with Apache License 2.0 | 5 votes |
@Test public void testLogin() throws Exception { MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(loginUrl); TestProperties testProperties = new TestProperties(); MockLoginRestModel mockLoginRestModel = new MockLoginRestModel(); mockLoginRestModel.setBlackDuckUsername(testProperties.getProperty(TestPropertyKey.TEST_BLACKDUCK_PROVIDER_USERNAME)); mockLoginRestModel.setBlackDuckPassword(testProperties.getProperty(TestPropertyKey.TEST_BLACKDUCK_PROVIDER_PASSWORD)); ReflectionTestUtils.setField(alertProperties, "alertTrustCertificate", Boolean.valueOf(testProperties.getProperty(TestPropertyKey.TEST_BLACKDUCK_PROVIDER_TRUST_HTTPS_CERT))); String restModel = mockLoginRestModel.getRestModelJson(); request.content(restModel); request.contentType(contentType); mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk()); }
Example 5
Source File: JobConfigControllerTestIT.java From blackduck-alert with Apache License 2.0 | 5 votes |
@Test @WithMockUser(roles = AlertIntegrationTest.ROLE_ALERT_ADMIN) public void testUpdateConfig() throws Exception { JobFieldModel fieldModel = createTestJobFieldModel("1", "2"); Map<String, Collection<String>> fieldValueModels = new HashMap<>(); for (FieldModel newFieldModel : fieldModel.getFieldModels()) { fieldValueModels.putAll(newFieldModel.getKeyToValues().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().getValues()))); } ConfigurationJobModel emptyConfigurationModel = addJob(slackChannelKey.getUniversalKey(), blackDuckProviderKey.getUniversalKey(), fieldValueModels); addGlobalConfiguration(blackDuckProviderKey, Map.of( BlackDuckDescriptor.KEY_BLACKDUCK_URL, List.of("BLACKDUCK_URL"), BlackDuckDescriptor.KEY_BLACKDUCK_API_KEY, List.of("BLACKDUCK_API"))); String configId = String.valueOf(emptyConfigurationModel.getJobId()); String urlPath = url + "/" + configId; MockHttpServletRequestBuilder request = MockMvcRequestBuilders.put(urlPath) .with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTest.ROLE_ALERT_ADMIN)) .with(SecurityMockMvcRequestPostProcessors.csrf()); fieldModel.setJobId(configId); request.content(gson.toJson(fieldModel)); request.contentType(contentType); MvcResult mvcResult = mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isAccepted()).andReturn(); String response = mvcResult.getResponse().getContentAsString(); checkResponse(response); }
Example 6
Source File: UnipayControllerTest.java From unionpay with MIT License | 5 votes |
/** * Method: pay(HttpServletRequest request, HttpServletResponse response) */ @Test public void testPay() throws Exception { MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post("/union/pay"); request.contentType(MediaType.APPLICATION_FORM_URLENCODED); mockMvc.perform(request) .andExpect(status().isOk()) .andDo(MockMvcResultHandlers.print()); }
Example 7
Source File: TaxReceiptMobileControllerTest.java From nfscan with MIT License | 5 votes |
private ResultResponse manualDonate(TaxReceipt taxReceipt) throws Exception { MockHttpServletRequestBuilder builder = post("/fe/taxreceipts/manual/donate.action"); builder.contentType(MediaType.APPLICATION_FORM_URLENCODED); builder.param("cnpj", taxReceipt.getCnpj()); builder.param("date", new SimpleDateFormat(DATE_FORMAT).format(taxReceipt.getDate())); builder.param("coo", taxReceipt.getCoo()); builder.param("total", String.valueOf(taxReceipt.getTotal())); Gson gson = new Gson(); return gson.fromJson( mockMvc.perform(builder).andExpect(status().isOk()).andReturn().getResponse().getContentAsString(), ResultResponse.class ); }
Example 8
Source File: ElectronicTaxReceiptMobileControllerTest.java From nfscan with MIT License | 5 votes |
private ResultResponse donateRequest(String accessKey, double total) throws Exception { MockHttpServletRequestBuilder builder = post("/fe/electronictaxreceipts/donate.action"); builder.contentType(MediaType.APPLICATION_FORM_URLENCODED); builder.param("accessKey", accessKey); builder.param("total", String.valueOf(total)); Gson gson = new Gson(); return gson.fromJson( mockMvc.perform(builder).andExpect(status().isOk()).andReturn().getResponse().getContentAsString(), ResultResponse.class ); }
Example 9
Source File: MockMvcHelper.java From entando-core with GNU Lesser General Public License v3.0 | 5 votes |
/** * receives a MockHttpServletRequestBuilder, puts standard headers into it and returns it * * @param requestBuilder the MockHttpServletRequestBuilder to which add headers * @return the MockHttpServletRequestBuilder with standard headers */ private MockHttpServletRequestBuilder addStandardHeaders(MockHttpServletRequestBuilder requestBuilder) { if (! StringUtils.isEmpty(this.accessToken)) { requestBuilder = requestBuilder.header("Authorization", "Bearer " + this.accessToken); } return requestBuilder.contentType(MediaType.APPLICATION_JSON_VALUE); }