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

@Test
public void shouldUpdateShipmentDraftIfFoundById() {
    ShipmentDraft existingDraft = new ShipmentDraftDataBuilder().withId(draftIdFromUser).withNotes("old notes")
            .build();//from w w  w.  jav  a  2  s  . co  m
    when(shipmentDraftRepository.findOne(any(UUID.class))).thenReturn(existingDraft);
    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 source file:org.openlmis.fulfillment.web.ShipmentControllerIntegrationTest.java

@Test
public void shouldReturnForbiddenIfUserHasNoRightsToEditShipments() {
    doThrow(new MissingPermissionException("test")).when(permissionService)
            .canEditShipment(any(ShipmentDto.class));

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

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

@Test
public void shouldReturn403WhenUserHasNoRightsToCreateOrderFileTemplate() {
    denyUserAllRights();//  www . java  2s .  c  o  m
    T properties = generateProperties();

    restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader())
            .contentType(MediaType.APPLICATION_JSON_VALUE).body(toDto(properties)).when().post(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 shouldReturnBadRequestIfIdMismatch() {
    shipmentDraftDto.setId(UUID.randomUUID());

    restAssured.given().pathParam(ID, draftIdFromUser).header(HttpHeaders.AUTHORIZATION, getTokenHeader())
            .contentType(APPLICATION_JSON_VALUE).body(shipmentDraftDto).when().put(ID_RESOURCE_URL).then()
            .statusCode(400).body(MESSAGE_KEY, equalTo(MessageKeys.SHIPMENT_DRAFT_ID_MISMATCH));

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

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

@Test
public void deploymentsPagination() throws Exception {

    List<Deployment> deployments = ControllerTestUtils.createDeployments(5, true);
    Pageable pageable = ControllerTestUtils.createDefaultPageable();
    Mockito.when(deploymentService.getDeployments(pageable)).thenReturn(new PageImpl<Deployment>(deployments));

    mockMvc.perform(get("/deployments").header(HttpHeaders.AUTHORIZATION,
            OAuth2AccessToken.BEARER_TYPE + " <access token>")).andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON))
            .andDo(document("deployment-pagination", preprocessResponse(prettyPrint()), responseFields(
                    fieldWithPath("links[]").ignored(), fieldWithPath("content[].links[]").ignored(),

                    fieldWithPath("page.size").description("The size of the page"),
                    fieldWithPath("page.totalElements").description("The total number of elements"),
                    fieldWithPath("page.totalPages").description("The total number of the page"),
                    fieldWithPath("page.number").description("The current page"),
                    fieldWithPath("content[].uuid").ignored(),
                    fieldWithPath("content[].creationTime").ignored(),
                    fieldWithPath("content[].updateTime").ignored(),
                    fieldWithPath("content[].status").ignored(), fieldWithPath("content[].outputs").ignored(),
                    fieldWithPath("content[].task").ignored(), fieldWithPath("content[].callback").ignored())));
}

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

@Test
public void shouldFindShipmentBasedOnOrder() {
    when(orderRepository.findOne(orderId)).thenReturn(shipment.getOrder());
    when(shipmentRepository.findByOrder(eq(shipment.getOrder()), any(Pageable.class)))
            .thenReturn(new PageImpl<>(singletonList(shipment)));

    PageDto response = restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader())
            .queryParam("page", 2).queryParam("size", 10).contentType(APPLICATION_JSON_VALUE)
            .queryParam(ORDER_ID, orderId).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(shipmentDtoExpected, getPageContent(response, ShipmentDto.class).get(0));

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

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

@Test
public void shouldReturn403WhenUserHasNoRightsToUpdateOrderFileTemplate() {
    denyUserAllRights();/*w w  w  . j a  v  a 2 s  .  com*/
    T oldProperties = generateProperties();
    T newProperties = generateProperties();

    restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader())
            .contentType(MediaType.APPLICATION_JSON_VALUE).pathParam("id", oldProperties.getId())
            .body(toDto(newProperties)).when().put(ID_URL).then().statusCode(403);

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

}

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

@Test
public void shouldReturnBadRequestIfShipmentDraftOrderIsNotGivenWhenPut() {
    shipmentDraftDto.setOrder((OrderObjectReferenceDto) null);
    shipmentDraftDto.setId(draftIdFromUser);

    restAssured.given().pathParam(ID, draftIdFromUser).header(HttpHeaders.AUTHORIZATION, getTokenHeader())
            .contentType(APPLICATION_JSON_VALUE).body(shipmentDraftDto).when().put(ID_RESOURCE_URL).then()
            .statusCode(400).body(MESSAGE_KEY, equalTo(MessageKeys.SHIPMENT_ORDERLESS_NOT_SUPPORTED));

    verify(shipmentDraftRepository, never()).findOne(any(UUID.class));
    assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.responseChecks());
}

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

@Test
public void shouldReturn403WhenUserHasNoRightsToDeleteOrderFileTemplate() {
    denyUserAllRights();/* w  w w . j  ava2  s  .  co  m*/
    T properties = generateProperties();

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

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

}

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

@Test
public void shouldReturnForbiddenIfUserHasNoRightsToEditShipmentDraftsWhenPut() {
    stubMissingPermission();//from w  w w.  j a  v a2 s . c o  m
    shipmentDraftDto.setId(draftIdFromUser);

    restAssured.given().pathParam(ID, draftIdFromUser).header(HttpHeaders.AUTHORIZATION, getTokenHeader())
            .contentType(APPLICATION_JSON_VALUE).body(shipmentDraftDto).when().put(ID_RESOURCE_URL).then()
            .statusCode(403).body(MESSAGE_KEY, equalTo(MessageKeys.PERMISSION_MISSING));

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