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:org.openlmis.fulfillment.web.OrderControllerIntegrationTest.java
@Test public void shouldCreateOrder() { firstOrderDto.setStatusChanges(sampleStatusChanges()); given(orderService.createOrder(any(OrderDto.class), eq(user.getId()))).willReturn(firstOrder); restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()).contentType(APPLICATION_JSON_VALUE) .body(firstOrderDto).when().post(RESOURCE_URL).then().statusCode(201); assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); ArgumentCaptor<OrderDto> orderCaptor = ArgumentCaptor.forClass(OrderDto.class); verify(orderService, times(1)).createOrder(orderCaptor.capture(), eq(user.getId())); assertThat(orderCaptor.getAllValues().get(0).getExternalId(), is(firstOrderDto.getExternalId())); }
From source file:it.reply.orchestrator.controller.DeploymentControllerTest.java
@Test public void getDeploymentNotFound() throws Exception { String deploymentId = "mmd34483-d937-4578-bfdb-ebe196bf82dd"; Mockito.when(deploymentService.getDeployment(deploymentId)).thenThrow(new NotFoundException("Message")); mockMvc.perform(get("/deployments/" + deploymentId).header(HttpHeaders.AUTHORIZATION, OAuth2AccessToken.BEARER_TYPE + " <access token>")).andExpect(status().isNotFound()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)).andExpect(jsonPath("$.code", is(404))) .andDo(document("deployment-not-found", preprocessResponse(prettyPrint()), responseFields(fieldWithPath("code").description("The HTTP status code"), fieldWithPath("title").description("The HTTP status name"), fieldWithPath("message") .description("A displayable message describing the error")))) .andExpect(jsonPath("$.title", is("Not Found"))).andExpect(jsonPath("$.message", is("Message"))); }
From source file:org.openlmis.fulfillment.web.ShipmentDraftControllerIntegrationTest.java
@Test public void shouldDeleteShipmentDraft() { when(shipmentDraftRepository.findOne(draftIdFromUser)).thenReturn(shipmentDraft); when(dateHelper.getCurrentDateTimeWithSystemZone()).thenReturn(modifiedDate); Order order = new OrderDataBuilder().build(); when(orderRepository.findOne(any())).thenReturn(order); restAssured.given().pathParam(ID, draftIdFromUser).header(HttpHeaders.AUTHORIZATION, getTokenHeader()) .contentType(APPLICATION_JSON_VALUE).when().delete(ID_RESOURCE_URL).then().statusCode(204); order.setStatus(OrderStatus.ORDERED); order.setUpdateDetails(new UpdateDetails(INITIAL_USER_ID, modifiedDate)); verify(shipmentDraftRepository).delete(draftIdFromUser); verify(orderRepository).save(order); assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); }
From source file:org.openlmis.fulfillment.web.OrderControllerIntegrationTest.java
@Test public void shouldCreateMultipleOrders() { given(orderService.createOrder(any(OrderDto.class), eq(user.getId()))).willReturn(firstOrder); restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()).contentType(APPLICATION_JSON_VALUE) .body(asList(firstOrderDto, secondOrderDto)).when().post(BATCH_URL).then().statusCode(201); assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); ArgumentCaptor<OrderDto> orderCaptor = ArgumentCaptor.forClass(OrderDto.class); verify(orderService, times(2)).createOrder(orderCaptor.capture(), eq(user.getId())); assertThat(orderCaptor.getAllValues().get(0).getExternalId(), is(firstOrderDto.getExternalId())); assertThat(orderCaptor.getAllValues().get(1).getExternalId(), is(secondOrderDto.getExternalId())); }
From source file:org.openlmis.fulfillment.web.ShipmentDraftControllerIntegrationTest.java
@Test public void shouldReturnNotFoundIfShipmentDraftIsNotFoundWhenDelete() { when(shipmentDraftRepository.findOne(draftIdFromUser)).thenReturn(null); restAssured.given().pathParam(ID, draftIdFromUser).header(HttpHeaders.AUTHORIZATION, getTokenHeader()) .contentType(APPLICATION_JSON_VALUE).when().delete(ID_RESOURCE_URL).then().statusCode(404) .body(MESSAGE_KEY, equalTo(MessageKeys.SHIPMENT_NOT_FOUND)); verify(shipmentDraftRepository, never()).delete(any(UUID.class)); assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); }
From source file:org.openlmis.fulfillment.web.OrderControllerIntegrationTest.java
@Test public void shouldGetChosenOrder() { OrderDto response = restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()) .contentType(APPLICATION_JSON_VALUE).pathParam("id", firstOrder.getId()).when().get(ID_URL).then() .statusCode(200).extract().as(OrderDto.class); assertTrue(orderRepository.exists(response.getId())); assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); }
From source file:org.openlmis.fulfillment.web.ShipmentDraftControllerIntegrationTest.java
@Test public void shouldReturnForbiddenIfUserHasNoRightsToDeleteShipmentDraft() { when(shipmentDraftRepository.findOne(draftIdFromUser)).thenReturn(shipmentDraft); doThrow(new MissingPermissionException(PERMISSION_NAME)).when(permissionService) .canEditShipmentDraft(shipmentDraft); restAssured.given().pathParam(ID, draftIdFromUser).header(HttpHeaders.AUTHORIZATION, getTokenHeader()) .contentType(APPLICATION_JSON_VALUE).when().delete(ID_RESOURCE_URL).then().statusCode(403) .body(MESSAGE_KEY, equalTo(MessageKeys.PERMISSION_MISSING)); verify(shipmentDraftRepository, never()).delete(any(UUID.class)); assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); }
From source file:org.openlmis.fulfillment.web.OrderControllerIntegrationTest.java
@Test public void shouldGetOrderWithExpandedLastUpdater() { restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()).contentType(APPLICATION_JSON_VALUE) .pathParam(ID, firstOrder.getId()).queryParam(EXPAND, LAST_UPDATER).when().get(ID_URL).then() .statusCode(200).extract().as(OrderDto.class); ArgumentCaptor<OrderDto> captor = ArgumentCaptor.forClass(OrderDto.class); verify(objReferenceExpander).expandDto(captor.capture(), eq(singleton(LAST_UPDATER))); assertEquals(firstOrder.getId(), captor.getValue().getId()); assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); }
From source file:it.reply.orchestrator.controller.DeploymentControllerTest.java
@Test public void createDeploymentSuccessfully() throws Exception { DeploymentRequest request = new DeploymentRequest(); Map<String, Object> parameters = new HashMap<>(); parameters.put("cpus", 1); request.setParameters(parameters);// w w w. j a v a2 s.c o m request.setTemplate("template"); request.setCallback("http://localhost:8080/callback"); Deployment deployment = ControllerTestUtils.createDeployment(); deployment.setCallback(request.getCallback()); deployment.setStatus(Status.CREATE_IN_PROGRESS); Mockito.when(deploymentService.createDeployment(request)).thenReturn(deployment); mockMvc.perform(post("/deployments").contentType(MediaType.APPLICATION_JSON) .content(TestUtil.convertObjectToJsonBytes(request)) .header(HttpHeaders.AUTHORIZATION, OAuth2AccessToken.BEARER_TYPE + " <access token>")) .andDo(document("create-deployment", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()), requestFields( fieldWithPath("template") .description("A string containing a TOSCA YAML-formatted template"), fieldWithPath("parameters").optional().description( "The input parameters of the deployment(Map of String, Object)"), fieldWithPath("callback").description("The deployment callback URL (optional)")), responseFields(fieldWithPath("links[]").ignored(), 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("updateTime").description( "Update date-time (http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14)"), fieldWithPath("status").description( "The status of the deployment. (http://indigo-dc.github.io/orchestrator/apidocs/it/reply/orchestrator/enums/Status.html)"), fieldWithPath("task").description( "The current step of the deployment process. (http://indigo-dc.github.io/orchestrator/apidocs/it/reply/orchestrator/enums/Task.html)"), fieldWithPath("outputs").description("The outputs of the TOSCA document"), fieldWithPath("callback").description( "The endpoint used by the orchestrator to notify the progress of the deployment process."), fieldWithPath("links[]").ignored()))); }
From source file:org.openlmis.fulfillment.web.OrderControllerIntegrationTest.java
@Test public void shouldNotGetNonexistentOrder() { given(orderRepository.findOne(firstOrder.getId())).willReturn(null); restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()).contentType(APPLICATION_JSON_VALUE) .pathParam("id", firstOrder.getId()).when().get(ID_URL).then().statusCode(404); assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); }