List of usage examples for org.springframework.http HttpHeaders AUTHORIZATION
String AUTHORIZATION
To view the source code for org.springframework.http HttpHeaders AUTHORIZATION.
Click Source Link
From source file:io.syndesis.runtime.EventsITCase.java
@Test public void wsEventsWithToken() throws Exception { OkHttpClient client = new OkHttpClient(); ResponseEntity<EventMessage> r1 = post("/api/v1/event/reservations", null, EventMessage.class); assertThat(r1.getBody().getEvent().get()).as("event").isEqualTo("uuid"); String uuid = (String) r1.getBody().getData().get(); assertThat(uuid).as("data").isNotNull(); String uriTemplate = EventBusToWebSocket.DEFAULT_PATH + "/" + uuid; String url = resolveURI(uriTemplate).toString().replaceFirst("^http", "ws"); Request request = new Request.Builder().url(url) .addHeader(HttpHeaders.AUTHORIZATION, "Bearer " + tokenRule.validToken()).build(); // lets setup an event handler that we can inspect events on.. WebSocketListener listener = recorder(mock(WebSocketListener.class), WebSocketListener.class); List<Recordings.Invocation> invocations = recordedInvocations(listener); CountDownLatch countDownLatch = resetRecorderLatch(listener, 2); WebSocket ws = client.newWebSocket(request, listener); // We auto get a message letting us know we connected. assertThat(countDownLatch.await(1000, TimeUnit.SECONDS)).isTrue(); assertThat(invocations.get(0).getMethod().getName()).isEqualTo("onOpen"); assertThat(invocations.get(1).getMethod().getName()).isEqualTo("onMessage"); assertThat(invocations.get(1).getArgs()[1]).isEqualTo(EventMessage.of("message", "connected").toJson()); ///////////////////////////////////////////////////// // Test that we get notified of created entities ///////////////////////////////////////////////////// invocations.clear();// w w w . j a va 2 s . c o m countDownLatch = resetRecorderLatch(listener, 1); Integration integration = new Integration.Builder().id("1002").name("test") .desiredStatus(Integration.Status.Draft).currentStatus(Integration.Status.Draft).build(); post("/api/v1/integrations", integration, Integration.class); assertThat(countDownLatch.await(1000, TimeUnit.SECONDS)).isTrue(); assertThat(invocations.get(0).getMethod().getName()).isEqualTo("onMessage"); assertThat(invocations.get(0).getArgs()[1]).isEqualTo(EventMessage .of("change-event", ChangeEvent.of("created", "integration", "1002").toJson()).toJson()); ws.close(1000, "closing"); }
From source file:org.openlmis.fulfillment.web.TemplateControllerIntegrationTest.java
@Test public void shouldGetAllTemplates() { TemplateDto[] response = restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()) .contentType(MediaType.APPLICATION_JSON_VALUE).when().get(RESOURCE_URL).then().statusCode(200) .extract().as(TemplateDto[].class); Iterable<TemplateDto> templates = Arrays.asList(response); assertTrue(templates.iterator().hasNext()); assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); }
From source file:org.openlmis.fulfillment.web.OrderFileTemplateControllerIntegrationTest.java
@Test public void shouldNotUpdateOrderFileTemplateWhenIdNull() { // given/*from w w w . j av a2s .c o m*/ OrderFileTemplate originalTemplate = new OrderFileTemplate(); originalTemplate.setOrderFileColumns(new ArrayList<>()); originalTemplate.setId(orderFileTemplate.getId()); orderFileTemplateDto = OrderFileTemplateDto.newInstance(orderFileTemplate); orderFileTemplateDto.setId(null); when(orderFileTemplateService.getOrderFileTemplate()).thenReturn(originalTemplate); // when restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()) .contentType(MediaType.APPLICATION_JSON_VALUE).body(orderFileTemplateDto).when().put(RESOURCE_URL) .then().statusCode(400).extract().as(OrderFileTemplateDto.class); // then assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); }
From source file:org.openlmis.fulfillment.web.BaseTransferPropertiesControllerIntegrationTest.java
@Test public void shouldNotDeletePropertiesWithConflicts() { // given//from w ww .j a v a 2 s . c o m T properties = generateProperties(); given(transferPropertiesRepository.findOne(properties.getId())) .willThrow(new DataIntegrityViolationException("This exception is required by IT")); // when restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()) .contentType(MediaType.APPLICATION_JSON_VALUE).pathParam("id", properties.getId()).when() .delete(ID_URL).then().statusCode(409); // then assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); }
From source file:org.openlmis.fulfillment.web.ShipmentControllerIntegrationTest.java
@Test public void shouldCreateShipment() { Order shipmentOrder = shipment.getOrder(); shipmentOrder.setStatus(OrderStatus.ORDERED); when(orderRepository.findOne(shipment.getOrder().getId())).thenReturn(shipment.getOrder()); //necessary as SaveAnswer change shipment id value also in captor when(shipmentRepository.save(any(Shipment.class))).thenReturn(shipment); when(proofOfDeliveryRepository.save(any(ProofOfDelivery.class))).thenReturn(proofOfDelivery); ShipmentDto extracted = restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()) .contentType(APPLICATION_JSON_VALUE).body(shipmentDto).when().post(RESOURCE_URL).then() .statusCode(201).extract().as(ShipmentDto.class); shipmentOrder.setStatus(OrderStatus.SHIPPED); shipmentOrder.setUpdateDetails(new UpdateDetails(INITIAL_USER_ID, ZonedDateTime.of(2015, 5, 7, 10, 5, 20, 500, ZoneId.systemDefault()))); assertEquals(shipmentDtoExpected, extracted); verify(orderRepository).save(shipmentOrder); verify(shipmentRepository).save(captor.capture()); verify(stockEventBuilder).fromShipment(any(Shipment.class)); verify(stockEventService).submit(any(StockEventDto.class)); assertTrue(reflectionEquals(shipment, captor.getValue(), singletonList("id"))); assertNull(captor.getValue().getId()); assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.responseChecks()); }
From source file:org.openlmis.fulfillment.web.ShipmentDraftControllerIntegrationTest.java
@Test public void shouldReturnBadRequestIfOrderStatusIsNotOrdered() { Order order = new OrderDataBuilder().withFulfillingStatus().build(); when(orderRepository.findOne(any())).thenReturn(order); restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()).contentType(APPLICATION_JSON_VALUE) .body(shipmentDraftDto).when().post(RESOURCE_URL).then().statusCode(400) .body(MESSAGE_KEY, equalTo(MessageKeys.CANNOT_CREATE_SHIPMENT_DRAFT_FOR_ORDER_WITH_WRONG_STATUS)); verify(shipmentDraftRepository, never()).save(any(ShipmentDraft.class)); assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.responseChecks()); }
From source file:org.openlmis.fulfillment.web.TemplateControllerIntegrationTest.java
@Test public void shouldGetChosenTemplate() { TemplateDto response = restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()) .contentType(MediaType.APPLICATION_JSON_VALUE).pathParam("id", template.getId()).when().get(ID_URL) .then().statusCode(200).extract().as(TemplateDto.class); assertEquals(template.getId(), response.getId()); assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); }
From source file:it.reply.orchestrator.controller.ResourceControllerTest.java
@Test public void getResourceByIdAndDeploymentIdSuccesfully() throws Exception { Deployment deployment = ControllerTestUtils.createDeployment(); Resource resource = ControllerTestUtils.createResource(deployment); Mockito.when(resourceService.getResource(resource.getId(), deployment.getId())).thenReturn(resource); mockMvc.perform(get("/deployments/" + deployment.getId() + "/resources/" + resource.getId()) .header(HttpHeaders.AUTHORIZATION, OAuth2AccessToken.BEARER_TYPE + " <access token>")) .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.uuid", equalTo(resource.getId()))) .andExpect(jsonPath("$.links[1].rel", equalTo("self"))) .andExpect(jsonPath("$.links[1].href", endsWith("/deployments/" + deployment.getId() + "/resources/" + resource.getId()))) .andDo(document("get-resource", preprocessResponse(prettyPrint()), responseFields( fieldWithPath("uuid").description("The unique identifier of a resource"), fieldWithPath("creationTime").description( "Creation date-time (http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14)"), fieldWithPath("state").description( "The status of the resource. (http://indigo-dc.github.io/orchestrator/apidocs/it/reply/orchestrator/enums/NodeStates.html)"), fieldWithPath("toscaNodeType").optional() .description("The type of the represented TOSCA node"), fieldWithPath("toscaNodeName").optional() .description("The name of the represented TOSCA node"), fieldWithPath("requiredBy").description("A list of nodes that require this resource"), fieldWithPath("links[]").ignored()))); }
From source file:org.openlmis.fulfillment.web.OrderNumberConfigurationControllerIntegrationTest.java
private void postForOrderNumberConfiguration(OrderNumberConfigurationDto orderNumberConfiguration, Integer code) {//from ww w . java2 s . c o m restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()) .contentType(MediaType.APPLICATION_JSON_VALUE).body(orderNumberConfiguration).when() .post(RESOURCE_URL).then().statusCode(code); }