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.TemplateControllerIntegrationTest.java
@Test public void shouldNotDeleteNonexistentTemplate() { given(templateRepository.findOne(template.getId())).willReturn(null); given(templateRepository.exists(template.getId())).willReturn(false); restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()) .contentType(MediaType.APPLICATION_JSON_VALUE).pathParam("id", template.getId()).when() .delete(ID_URL).then().statusCode(404); assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); }
From source file:org.openlmis.fulfillment.web.BaseTransferPropertiesControllerIntegrationTest.java
@Test public void shouldGet400IfPropertiesHasDifferentFacilityIdWhenUpdate() { // given//from w w w. j a v a 2s . co m T oldProperties = generateProperties(); T newProperties = generateProperties(); T otherProperties = generateProperties(); newProperties.setId(oldProperties.getId()); newProperties.setFacilityId(oldProperties.getFacilityId()); given(transferPropertiesRepository.findOne(newProperties.getId())).willReturn(otherProperties); given(transferPropertiesRepository.save(any(TransferProperties.class))) .willAnswer(new SaveAnswer<TransferProperties>()); // when TransferPropertiesDto object = toDto(newProperties); object.getFacility().setId(UUID.randomUUID()); restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()) .contentType(MediaType.APPLICATION_JSON_VALUE).pathParam("id", oldProperties.getId()).body(object) .when().put(ID_URL).then().statusCode(400); // then assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); }
From source file:org.openlmis.fulfillment.web.OrderFileTemplateControllerIntegrationTest.java
@Test public void shouldReturn403WhenUserHasNoRightsToUpdateOrderFileTemplate() { denyUserAllRights();// www.ja v a2s . c om orderFileTemplateDto = OrderFileTemplateDto.newInstance(orderFileTemplate); restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()) .contentType(MediaType.APPLICATION_JSON_VALUE).body(orderFileTemplateDto).when().put(RESOURCE_URL) .then().statusCode(403); assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); }
From source file:org.openlmis.fulfillment.web.TemplateControllerIntegrationTest.java
@Test public void shouldUpdateTemplate() { templateDto.setDescription(TEMPLATE_CONTROLLER_TEST); TemplateDto response = restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()) .contentType(MediaType.APPLICATION_JSON_VALUE).pathParam("id", template.getId()).body(templateDto) .when().put(ID_URL).then().statusCode(200).extract().as(TemplateDto.class); assertEquals(response.getDescription(), TEMPLATE_CONTROLLER_TEST); assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); }
From source file:org.openlmis.fulfillment.web.BaseTransferPropertiesControllerIntegrationTest.java
@Test public void shouldDeleteProperties() { // given//from www.j a va2s . c om T properties = generateProperties(); given(transferPropertiesRepository.findOne(properties.getId())).willReturn(properties); // when restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()) .contentType(MediaType.APPLICATION_JSON_VALUE).pathParam("id", properties.getId()).when() .delete(ID_URL).then().statusCode(204); // then assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); }
From source file:org.openlmis.fulfillment.web.OrderFileTemplateControllerIntegrationTest.java
@Test public void shouldNotUpdateOrderFileTemplateWhenIdNotMatching() { // given//from ww w . j a v a 2 s .c om OrderFileTemplate originalTemplate = new OrderFileTemplate(); originalTemplate.setOrderFileColumns(new ArrayList<>()); originalTemplate.setId(getNonMatchingUuid(orderFileTemplate.getId())); orderFileTemplateDto = OrderFileTemplateDto.newInstance(orderFileTemplate); 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 shouldNotDeleteNonexistentProperties() { // given/*from w w w. jav a 2 s . c o m*/ T properties = generateProperties(); given(transferPropertiesRepository.findOne(properties.getId())).willReturn(null); // when restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()) .contentType(MediaType.APPLICATION_JSON_VALUE).pathParam("id", properties.getId()).when() .delete(ID_URL).then().statusCode(404); // then assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); }
From source file:org.openlmis.fulfillment.web.TemplateControllerIntegrationTest.java
@Test public void shouldCreateNewTemplateIfDoesNotExist() { given(templateRepository.findOne(template.getId())).willReturn(template); given(templateRepository.exists(template.getId())).willReturn(true); templateDto.setDescription(TEMPLATE_CONTROLLER_TEST); TemplateDto response = restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()) .contentType(MediaType.APPLICATION_JSON_VALUE).pathParam("id", ID).body(templateDto).when() .put(ID_URL).then().statusCode(200).extract().as(TemplateDto.class); assertEquals(response.getDescription(), TEMPLATE_CONTROLLER_TEST); assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); }
From source file:org.openlmis.fulfillment.web.ShipmentDraftControllerIntegrationTest.java
@Test public void shouldCreateShipmentDraft() { //necessary as SaveAnswer change shipment id value also in captor when(shipmentDraftRepository.save(any(ShipmentDraft.class))).thenReturn(shipmentDraft); when(dateHelper.getCurrentDateTimeWithSystemZone()).thenReturn(modifiedDate); Order order = new OrderDataBuilder().withOrderedStatus().build(); when(orderRepository.findOne(any())).thenReturn(order); ShipmentDraftDto extracted = restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()) .contentType(APPLICATION_JSON_VALUE).body(shipmentDraftDto).when().post(RESOURCE_URL).then() .statusCode(201).extract().as(ShipmentDraftDto.class); order.setStatus(OrderStatus.FULFILLING); order.setUpdateDetails(new UpdateDetails(INITIAL_USER_ID, modifiedDate)); assertEquals(shipmentDraftDtoExpected, extracted); verify(shipmentDraftRepository).save(captor.capture()); verify(orderRepository).save(order); assertTrue(reflectionEquals(shipmentDraft, captor.getValue(), singletonList("id"))); assertNull(captor.getValue().getId()); assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); }
From source file:it.reply.orchestrator.controller.DeploymentControllerTest.java
@Test public void getDeployments() throws Exception { List<Deployment> deployments = ControllerTestUtils.createDeployments(2, true); deployments.get(0).setStatus(Status.CREATE_FAILED); deployments.get(0).setStatusReason("Some reason"); deployments.get(1).setStatus(Status.CREATE_COMPLETE); Pageable pageable = ControllerTestUtils.createDefaultPageable(); Mockito.when(deploymentService.getDeployments(pageable)).thenReturn(new PageImpl<Deployment>(deployments)); mockMvc.perform(get("/deployments").accept(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, OAuth2AccessToken.BEARER_TYPE + " <access token>")).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andDo(document("authentication", requestHeaders(/*from w w w. j ava 2 s. com*/ headerWithName(HttpHeaders.AUTHORIZATION).description("OAuth2 bearer token")))) .andDo(document("deployments", preprocessResponse(prettyPrint()), responseFields(fieldWithPath("links[]").ignored(), fieldWithPath("content[].uuid").description("The unique identifier of a resource"), fieldWithPath("content[].creationTime").description( "Creation date-time (http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14)"), fieldWithPath("content[].updateTime").description("Update date-time"), fieldWithPath("content[].status").description( "The status of the deployment. (http://indigo-dc.github.io/orchestrator/apidocs/it/reply/orchestrator/enums/Status.html)"), fieldWithPath("content[].statusReason").description( "Verbose explanation of reason that lead to the deployment status (Present only if the deploy is in some error status)"), fieldWithPath("content[].task").description( "The current step of the deployment process. (http://indigo-dc.github.io/orchestrator/apidocs/it/reply/orchestrator/enums/Task.html)"), fieldWithPath("content[].callback").description( "The endpoint used by the orchestrator to notify the progress of the deployment process."), fieldWithPath("content[].outputs").description("The outputs of the TOSCA document"), fieldWithPath("content[].links[]").ignored(), fieldWithPath("page").ignored()))); }