List of usage examples for org.springframework.http MediaType APPLICATION_JSON
MediaType APPLICATION_JSON
To view the source code for org.springframework.http MediaType APPLICATION_JSON.
Click Source Link
From source file:org.zalando.boot.etcd.EtcdClientTest.java
@Test(expected = EtcdException.class) public void getWithResourceAccessException() throws EtcdException { server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample")) .andExpect(MockRestRequestMatchers.method(HttpMethod.GET)) .andRespond(MockRestResponseCreators.withStatus(HttpStatus.NOT_FOUND) .contentType(MediaType.APPLICATION_JSON) .body(new ClassPathResource("EtcdClientTest_get.json"))); try {/*from www . j av a 2 s . c o m*/ client.get("sample"); } finally { server.verify(); } }
From source file:demo.service.RemoteVehicleDetailsServiceTest.java
@Test public void getVehicleDetailsWhenResultIsSuccessShouldReturnDetails() throws Exception { this.server.expect(requestTo("http://example.com/vehicle/" + VIN + "/details")) .andRespond(withSuccess(getClassPathResource("vehicledetails.json"), MediaType.APPLICATION_JSON)); VehicleDetails details = this.service.getVehicleDetails(new VehicleIdentificationNumber(VIN)); assertThat(details.getMake()).isEqualTo("Honda"); assertThat(details.getModel()).isEqualTo("Civic"); }
From source file:org.openwms.tms.PrioritizeTODocumentation.java
public @Test void prioritizeTO() throws Exception { // setup .../*from www .jav a 2s . c om*/ CreateTransportOrderVO vo = createTO(); postTOAndValidate(vo, NOTLOGGED); given(commonGateway.getTransportUnit(KNOWN)) .willReturn(Optional.of(new TransportUnit(KNOWN, INIT_LOC, ERR_LOC_STRING))); mockMvc.perform(get(TMSConstants.ROOT_ENTITIES + "/" + vo.getpKey())).andExpect(status().isOk()) .andExpect(jsonPath("priority", is("HIGHEST"))); // test ... vo.setPriority(PriorityLevel.NORMAL.toString()); mockMvc.perform(patch(TMSConstants.ROOT_ENTITIES).contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(vo))).andExpect(status().isNoContent()) .andDo(document("to-patch-priority-ok")); mockMvc.perform(get(TMSConstants.ROOT_ENTITIES + "/" + vo.getpKey())).andExpect(status().isOk()) .andExpect(jsonPath("priority", is("NORMAL"))); }
From source file:com.orange.cepheus.cep.EventSinkListenerTest.java
/** * Check that an updateContext is fired when a new event bean arrives *///from www .j av a 2 s .c o m @Test public void postMessageOnEventUpdate() { HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setContentType(MediaType.APPLICATION_JSON); httpHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); when(statement.getText()).thenReturn("statement"); when(ngsiClient.getRequestHeaders(any())).thenReturn(httpHeaders); // Trigger event update List<ContextAttribute> attributes = new LinkedList<>(); attributes.add(new ContextAttribute("id", "string", "OUT1234")); attributes.add(new ContextAttribute("avgTemp", "double", 10.25)); attributes.add(new ContextAttribute("avgTemp_unit", "string", "celcius")); EventBean[] beans = { buildEventBean("TempSensorAvg", attributes) }; eventSinkListener.update(beans, null, statement, provider); // Capture updateContext when postUpdateContextRequest is called on updateContextRequest, ArgumentCaptor<UpdateContext> updateContextArg = ArgumentCaptor.forClass(UpdateContext.class); ArgumentCaptor<HttpHeaders> headersArg = ArgumentCaptor.forClass(HttpHeaders.class); verify(ngsiClient).updateContext(eq(broker.getUrl()), headersArg.capture(), updateContextArg.capture()); // Check updateContext is valid UpdateContext updateContext = updateContextArg.getValue(); assertEquals(UpdateAction.APPEND, updateContext.getUpdateAction()); assertEquals(1, updateContext.getContextElements().size()); // Check headers are valid HttpHeaders headers = headersArg.getValue(); assertEquals(MediaType.APPLICATION_JSON, headers.getContentType()); assertTrue(headers.getAccept().contains(MediaType.APPLICATION_JSON)); assertEquals("SN", headers.getFirst("Fiware-Service")); assertEquals("SP", headers.getFirst("Fiware-ServicePath")); assertEquals("AUTH_TOKEN", headers.getFirst("X-Auth-Token")); ContextElement contextElement = updateContext.getContextElements().get(0); assertEquals("OUT1234", contextElement.getEntityId().getId()); assertEquals("TempSensorAvg", contextElement.getEntityId().getType()); assertFalse(contextElement.getEntityId().getIsPattern()); assertEquals(1, contextElement.getContextAttributeList().size()); ContextAttribute attr = contextElement.getContextAttributeList().get(0); assertEquals("avgTemp", attr.getName()); assertEquals("double", attr.getType()); assertEquals(10.25, attr.getValue()); assertEquals(1, attr.getMetadata().size()); assertEquals("unit", attr.getMetadata().get(0).getName()); assertEquals("string", attr.getMetadata().get(0).getType()); assertEquals("celcius", attr.getMetadata().get(0).getValue()); }
From source file:fi.helsinki.opintoni.web.rest.privateapi.UsefulLinksResourcePermissionsTest.java
@Test public void thatUserCannotReorderUsefulLinksThatSheDoesNotOwn() throws Exception { OrderUsefulLinksDto orderUsefulLinksDto = new OrderUsefulLinksDto(); orderUsefulLinksDto.usefulLinkIds = Lists.newArrayList(1L, 2L, 3L); mockMvc.perform(post("/api/private/v1/usefullinks/order").with(securityContext(studentSecurityContext())) .characterEncoding("UTF-8").contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON).content(WebTestUtils.toJsonBytes(orderUsefulLinksDto))) .andExpect(status().isForbidden()); }
From source file:com.parivero.swagger.demo.controller.PaisControllerTest.java
@Test public void alta_conRecursoInValido_retornaBadRequest() throws Exception { this.mockMvc/*from www . j ava2 s . co m*/ .perform(post("/paises").contentType(MediaType.APPLICATION_JSON) .content("{\"id\":0\"nombre\":\"Argentina\"}")) .andDo(print()).andExpect(status().isBadRequest()); }
From source file:org.ow2.proactive.procci.Application.java
@Override public void configureContentNegotiation(ContentNegotiationConfigurer configurer) { configurer.favorPathExtension(false).favorParameter(true).parameterName("format").ignoreAcceptHeader(true) .useJaf(false).defaultContentType(MediaType.APPLICATION_JSON) .mediaType("json", MediaType.APPLICATION_JSON); }
From source file:com.sinespera.GreetingControllerTest.java
@Test public void greetingUnauthorized() throws Exception { // @formatter:off mvc.perform(get("/greeting").accept(MediaType.APPLICATION_JSON)).andExpect(status().isUnauthorized()) .andExpect(jsonPath("$.error", is("unauthorized"))); // @formatter:on }
From source file:com.pepaproch.gtswsdlclient.AuthTokenProviderImplTest.java
/** * Test of getAuthorisationToken method, of class AuthTokenProviderImpl. *//*from w w w . j av a 2 s . c o m*/ @Test public void testGetAuthorisationTokenExpired() { AuthTokenProvider instance = new AuthTokenProviderImpl(BASE_URL, "test", "test", restTemplate, 0); mockServer = MockRestServiceServer.createServer(restTemplate); this.mockServer.expect(requestTo(BASE_URL + AUTH_PATH)).andExpect(method(HttpMethod.POST)) .andRespond(withSuccess("{\"accessToken\" : \"testtoken\" }", MediaType.APPLICATION_JSON)); this.mockServer.expect(requestTo(BASE_URL + AUTH_PATH)).andExpect(method(HttpMethod.POST)) .andRespond(withSuccess("{\"accessToken\" : \"testtoken-1\" }", MediaType.APPLICATION_JSON)); String authorisationToken = instance.getAuthorisationToken().getToken(); String authorisationToken2 = instance.getAuthorisationToken().getToken(); this.mockServer.verify(); assertNotSame(authorisationToken, authorisationToken2); }