Example usage for org.springframework.http HttpHeaders AUTHORIZATION

List of usage examples for org.springframework.http HttpHeaders AUTHORIZATION

Introduction

In this page you can find the example usage for org.springframework.http HttpHeaders AUTHORIZATION.

Prototype

String AUTHORIZATION

To view the source code for org.springframework.http HttpHeaders AUTHORIZATION.

Click Source Link

Document

The HTTP Authorization header field name.

Usage

From source file:org.openlmis.fulfillment.web.ShipmentControllerIntegrationTest.java

@Test
public void shouldReturnNotFoundIfShipmentIsNotFound() {
    when(shipmentRepository.findOne(shipmentDtoExpected.getId())).thenReturn(null);

    restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()).contentType(APPLICATION_JSON_VALUE)
            .pathParam(ID, shipmentDtoExpected.getId()).when().get(ID_RESOURCE_URL).then().statusCode(404)
            .body(MESSAGE_KEY, equalTo(MessageKeys.SHIPMENT_NOT_FOUND));

    assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations());
}

From source file:org.openlmis.fulfillment.web.OrderControllerIntegrationTest.java

@Test
public void shouldPrintOrderAsPdf() {
    restAssured.given().queryParam(FORMAT, "pdf").header(HttpHeaders.AUTHORIZATION, getTokenHeader())
            .pathParam("id", thirdOrder.getId().toString()).when().get(PRINT_URL).then().statusCode(200);

    assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations());
}

From source file:org.openlmis.fulfillment.web.ShipmentDraftControllerIntegrationTest.java

@Test
public void shouldFindShipmentDraftBasedOnOrder() {
    when(orderRepository.findOne(shipmentDraftDtoExpected.getOrder().getId()))
            .thenReturn(shipmentDraft.getOrder());
    when(shipmentDraftRepository.findByOrder(eq(shipmentDraft.getOrder()), any(Pageable.class)))
            .thenReturn(new PageImpl<>(singletonList(shipmentDraft)));

    PageDto response = restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader())
            .queryParam("page", 2).queryParam("size", 10).contentType(APPLICATION_JSON_VALUE)
            .queryParam(ORDER_ID, shipmentDraftDtoExpected.getOrder().getId()).when().get(RESOURCE_URL).then()
            .statusCode(200).extract().as(PageDto.class);

    assertEquals(10, response.getSize());
    assertEquals(2, response.getNumber());
    assertEquals(1, response.getContent().size());
    assertEquals(1, response.getNumberOfElements());
    assertEquals(21, response.getTotalElements());
    assertEquals(3, response.getTotalPages());
    assertEquals(shipmentDraftDtoExpected, getPageContent(response, ShipmentDraftDto.class).get(0));

    assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations());
}

From source file:org.openlmis.fulfillment.web.OrderControllerIntegrationTest.java

@Test
public void shouldReturnNotFoundErrorIfThereIsNoOrderToPrint() {
    given(orderRepository.findOne(firstOrder.getId())).willReturn(null);

    restAssured.given().queryParam(FORMAT, "pdf").header(HttpHeaders.AUTHORIZATION, getTokenHeader())
            .pathParam("id", firstOrder.getId().toString()).when().get(PRINT_URL).then().statusCode(404);

    assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations());
}

From source file:org.openlmis.fulfillment.web.ShipmentControllerIntegrationTest.java

@Test
public void shouldReturnForbiddenIfUserHasNoRightsToGetShipment() {
    doThrow(new MissingPermissionException("test")).when(permissionService).canViewShipment(shipment);

    restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()).contentType(APPLICATION_JSON_VALUE)
            .body(shipmentDto).pathParam(ID, shipmentDtoExpected.getId()).when().get(ID_RESOURCE_URL).then()
            .statusCode(403).body(MESSAGE_KEY, equalTo(MessageKeys.PERMISSION_MISSING));

    assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.responseChecks());
}

From source file:it.reply.orchestrator.controller.DeploymentControllerTest.java

@Test
public void getDeploymentWithOutputSuccessfully() throws Exception {

    String deploymentId = "mmd34483-d937-4578-bfdb-ebe196bf82dd";
    Deployment deployment = ControllerTestUtils.createDeployment(deploymentId);
    Map<String, String> outputs = Maps.newHashMap();
    String key = "server_ip";
    String value = "10.0.0.1";
    outputs.put(key, JsonUtility.serializeJson(value));
    deployment.setOutputs(outputs);// ww  w .java 2 s .  co m
    deployment.setStatus(Status.CREATE_FAILED);
    deployment.setStatusReason("Some reason");
    Mockito.when(deploymentService.getDeployment(deploymentId)).thenReturn(deployment);

    mockMvc.perform(get("/deployments/" + deploymentId).header(HttpHeaders.AUTHORIZATION,
            OAuth2AccessToken.BEARER_TYPE + " <access token>")).andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON))
            .andExpect(jsonPath("$.outputs", Matchers.hasEntry(key, value)))

            .andDo(document("deployment", preprocessResponse(prettyPrint()),

                    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"),
                            fieldWithPath("status").description(
                                    "The status of the deployment. (http://indigo-dc.github.io/orchestrator/apidocs/it/reply/orchestrator/enums/Status.html)"),
                            fieldWithPath("statusReason").description(
                                    "Verbose explanation of reason that lead to the deployment status (Present only if the deploy is in some error status)"),
                            fieldWithPath("task").description(
                                    "The current step of the deployment process. (http://indigo-dc.github.io/orchestrator/apidocs/it/reply/orchestrator/enums/Task.html)"),
                            fieldWithPath("callback").description(
                                    "The endpoint used by the orchestrator to notify the progress of the deployment process."),
                            fieldWithPath("outputs").description("The outputs of the TOSCA document"),
                            fieldWithPath("links[]").ignored())));
}

From source file:org.openlmis.fulfillment.web.ShipmentDraftControllerIntegrationTest.java

@Test
public void shouldReturnBadRequestIfOrderIsNotFoundWhenGetShipmentDrafts() {
    restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()).contentType(APPLICATION_JSON_VALUE)
            .queryParam("orderId", shipmentDraftDtoExpected.getOrder().getId()).when().get(RESOURCE_URL).then()
            .statusCode(400).body(MESSAGE_KEY, equalTo(MessageKeys.SHIPMENT_DRAFT_ORDER_NOT_FOUND));

    assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations());
}

From source file:org.openlmis.fulfillment.web.ShipmentDraftControllerIntegrationTest.java

@Test
public void shouldReturnBadRequestIfOrderIsNotGivenWhenGetShipmentDrafts() {
    restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()).contentType(APPLICATION_JSON_VALUE)
            .when().get(RESOURCE_URL).then().statusCode(400)
            .body(MESSAGE_KEY, equalTo(MessageKeys.SHIPMENT_DRAFT_ORDER_REQUIRED));

    assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.responseChecks());
}

From source file:org.openlmis.fulfillment.web.OrderControllerIntegrationTest.java

@Test
public void shouldFindOrdersByAllParameters() {
    OrderSearchParams params = new OrderSearchParams(firstOrder.getSupplyingFacilityId(),
            firstOrder.getRequestingFacilityId(), firstOrder.getProgramId(), firstOrder.getProcessingPeriodId(),
            Sets.newHashSet(READY_TO_PACK.toString()), LocalDate.of(2018, 4, 5), LocalDate.of(2018, 5, 5));

    given(orderService.searchOrders(params, pageable))
            .willReturn(new PageImpl<>(Lists.newArrayList(firstOrder), pageable, 2));

    PageDto response = restAssured.given().queryParam(SUPPLYING_FACILITY, firstOrder.getSupplyingFacilityId())
            .queryParam(REQUESTING_FACILITY, firstOrder.getRequestingFacilityId())
            .queryParam(PROGRAM, firstOrder.getProgramId())
            .queryParam(PROCESSING_PERIOD, firstOrder.getProcessingPeriodId())
            .queryParam(ORDER_STATUS, READY_TO_PACK.toString()).queryParam(PERIOD_START_DATE, "2018-04-05")
            .queryParam(PERIOD_END_DATE, "2018-05-05").queryParam(PAGE, 0).queryParam(SIZE, 10)
            .header(HttpHeaders.AUTHORIZATION, getTokenHeader()).when().get(RESOURCE_URL).then().statusCode(200)
            .extract().as(PageDto.class);

    List<BasicOrderDto> content = getPageContent(response, BasicOrderDto.class);

    assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations());
    assertThat(content, hasSize(1));/*from  ww  w  .ja va2  s. co  m*/

    for (BasicOrderDto order : content) {
        assertEquals(order.getSupplyingFacility().getId(), firstOrder.getSupplyingFacilityId());
        assertEquals(order.getRequestingFacility().getId(), firstOrder.getRequestingFacilityId());
        assertEquals(order.getProgram().getId(), firstOrder.getProgramId());
        assertEquals(order.getStatus(), firstOrder.getStatus());
        assertEquals(order.getId(), firstOrder.getId());
    }
}

From source file:org.openlmis.fulfillment.web.ShipmentDraftControllerIntegrationTest.java

@Test
public void shouldReturnForbiddenIfUserHasNoRightsToGetDrafts() {
    when(orderRepository.findOne(orderId)).thenReturn(shipmentDraft.getOrder());
    doThrow(new MissingPermissionException(PERMISSION_NAME)).when(permissionService)
            .canViewShipmentDraft(shipmentDraft.getOrder());

    restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()).contentType(APPLICATION_JSON_VALUE)
            .queryParam("orderId", orderId).when().get(RESOURCE_URL).then().statusCode(403)
            .body(MESSAGE_KEY, equalTo(MessageKeys.PERMISSION_MISSING));

    verify(shipmentDraftRepository, never()).findByOrder(any(Order.class), any(Pageable.class));
    assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations());
}