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.OrderNumberConfigurationControllerIntegrationTest.java

@Test
public void shouldReturn403WhenUserHasNoRightsToUpdateOrderNumberConfiguration() {
    denyUserAllRights();//from   w w  w .  j ava  2  s  .c o m
    OrderNumberConfiguration orderNumberConfiguration = generate("stuff", true, true, true);
    OrderNumberConfigurationDto orderNumberConfigurationDto = OrderNumberConfigurationDto
            .newInstance(orderNumberConfiguration);

    restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader())
            .contentType(MediaType.APPLICATION_JSON_VALUE).body(orderNumberConfigurationDto).when()
            .post(RESOURCE_URL).then().statusCode(403);

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

}

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

@Test
public void shouldReturn403WhenUserHasNoRightsToViewOrderFileTemplate() {
    denyUserAllRights();/*from  w w  w.  j  av  a2 s.c om*/

    restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader())
            .contentType(MediaType.APPLICATION_JSON_VALUE).when().get(RESOURCE_URL).then().statusCode(403);

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

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

@Test
public void shouldReturnForbiddenIfUserHasNoRightsToEditShipmentDrafts() {
    stubMissingPermission();//  ww  w  .jav a 2 s.  c  om

    restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()).contentType(APPLICATION_JSON_VALUE)
            .body(shipmentDraftDto).when().post(RESOURCE_URL).then().statusCode(403)
            .body(MESSAGE_KEY, equalTo(MessageKeys.PERMISSION_MISSING));

    verify(shipmentDraftRepository, never()).save(any(ShipmentDraft.class));
    assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations());
}

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

@Test
public void shouldFindPropertiesByFacilityId() {
    T properties = generateProperties();
    given(transferPropertiesRepository.findFirstByFacilityId(properties.getFacilityId()))
            .willReturn(properties);/*ww  w  .ja  va  2s.  c o m*/

    TransferPropertiesDto response = restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader())
            .queryParam(FACILITY, properties.getFacilityId()).when().get(SEARCH).then().statusCode(200)
            .extract().as(TransferPropertiesDto.class);

    assertTransferProperties((T) TransferPropertiesFactory.newInstance(response));
    assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations());
}

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

@Test
public void getPagedDeployments() throws Exception {

    List<Deployment> deployments = ControllerTestUtils.createDeployments(5, true);
    Pageable pageable = new PageRequest(1, 2,
            new Sort(Direction.DESC, AbstractResourceEntity.CREATED_COLUMN_NAME));
    Mockito.when(deploymentService.getDeployments(pageable))
            .thenReturn(new PageImpl<Deployment>(deployments, pageable, deployments.size()));

    mockMvc.perform(get("/deployments?page=1&size=2").accept(MediaType.APPLICATION_JSON)
            .header(HttpHeaders.AUTHORIZATION, OAuth2AccessToken.BEARER_TYPE + " <access token>"))
            .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON))
            .andDo(document("deployment-paged", preprocessResponse(prettyPrint()),
                    links(atomLinks(), linkWithRel("first").description("Hyperlink to the first page"),
                            linkWithRel("prev").description("Hyperlink to the previous page"),
                            linkWithRel("self").description("Self-referencing hyperlink"),
                            linkWithRel("next").description("Self-referencing hyperlink"),
                            linkWithRel("last").description("Hyperlink to the last page")),
                    responseFields(fieldWithPath("links[]").ignored(), fieldWithPath("content").ignored(),
                            fieldWithPath("page.").ignored())));

    // .andExpect(jsonPath("$.content", org.hamcrest.Matchers.hasSize(1)));
}

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

@Test
public void shouldReturnBadRequestIfShipmentOrderHasInvalidStatus() {
    when(order.canBeFulfilled()).thenReturn(false);
    when(order.getStatus()).thenReturn(OrderStatus.IN_ROUTE);

    restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()).contentType(APPLICATION_JSON_VALUE)
            .body(shipmentDto).when().post(RESOURCE_URL).then().statusCode(400)
            .body(MESSAGE_KEY, equalTo(MessageKeys.SHIPMENT_ORDER_STATUS_INVALID));

    verify(shipmentRepository, never()).save(any(Shipment.class));
    verify(stockEventBuilder, never()).fromShipment(any(Shipment.class));
    verify(stockEventService, never()).submit(any(StockEventDto.class));
    assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.responseChecks());
}

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

@Test
public void shouldCreateShipmentDraftIfNotFoundById() {
    when(shipmentDraftRepository.findOne(any(UUID.class))).thenReturn(null);
    shipmentDraftDto.setId(draftIdFromUser);

    ShipmentDraftDto extracted = restAssured.given().pathParam(ID, draftIdFromUser)
            .header(HttpHeaders.AUTHORIZATION, getTokenHeader()).contentType(APPLICATION_JSON_VALUE)
            .body(shipmentDraftDto).when().put(ID_RESOURCE_URL).then().statusCode(200).extract()
            .as(ShipmentDraftDto.class);

    verifyAfterPut(extracted);/*from  ww w. j  a  v a  2s .  c  om*/
}

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

@Test
public void shouldReturnEmptyListIfPropertiesCannotBeFound() {
    given(transferPropertiesRepository.findFirstByFacilityId(any(UUID.class))).willReturn(null);

    restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader())
            .queryParam(FACILITY, UUID.randomUUID()).when().get(SEARCH).then().statusCode(404);

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

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

@Test
public void shouldReturn403WhenUserHasNoRightsToViewTransferProperties() {
    denyUserAllRights();/*  ww  w  .  j  a va2  s.  co  m*/
    T properties = generateProperties();

    restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader())
            .contentType(MediaType.APPLICATION_JSON_VALUE).pathParam("id", properties.getId()).when()
            .get(ID_URL).then().statusCode(403);

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

}