Search in sources :

Example 6 with Request

use of org.onap.so.serviceinstancebeans.Request in project so by onap.

the class OrchestrationRequestsTest method testGetOrchestrationRequestWithOpenstackDetails.

@Test
public void testGetOrchestrationRequestWithOpenstackDetails() throws Exception {
    setupTestGetOrchestrationRequestOpenstackDetails("00032ab7-3fb3-42e5-965d-8ea592502017", "COMPLETED");
    // Test request with modelInfo request body
    GetOrchestrationResponse testResponse = new GetOrchestrationResponse();
    Request request = ORCHESTRATION_LIST.getRequestList().get(0).getRequest();
    List<CloudRequestData> cloudRequestData = new ArrayList<>();
    CloudRequestData cloudData = new CloudRequestData();
    cloudData.setCloudIdentifier("heatstackName/123123");
    ObjectMapper mapper = new ObjectMapper();
    Object reqData = mapper.readValue("{\r\n  \"test\": \"00032ab7-3fb3-42e5-965d-8ea592502016\",\r\n  \"test2\": \"deleteInstance\",\r\n  \"test3\": \"COMPLETE\",\r\n  \"test4\": \"Vf Module has been deleted successfully.\",\r\n  \"test5\": 100\r\n}", Object.class);
    cloudData.setCloudRequest(reqData);
    cloudRequestData.add(cloudData);
    request.setCloudRequestData(cloudRequestData);
    testResponse.setRequest(request);
    String testRequestId = request.getRequestId();
    testResponse.getRequest().setRequestProcessingData(new ArrayList<RequestProcessingData>());
    RequestProcessingData e = new RequestProcessingData();
    e.setGroupingId("7d2e8c07-4d10-456d-bddc-37abf38ca714");
    List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();
    HashMap<String, String> data1 = new HashMap<String, String>();
    data1.put("requestAction", "assign");
    data.add(data1);
    e.setDataPairs(data);
    testResponse.getRequest().getRequestProcessingData().add(e);
    HttpHeaders headers = new HttpHeaders();
    headers.set("Accept", MediaType.APPLICATION_JSON);
    headers.set("Content-Type", MediaType.APPLICATION_JSON);
    headers.set(ONAPLogConstants.Headers.REQUEST_ID, "0321e28d-3dde-4b31-9b28-1e0f07231b93");
    HttpEntity<Request> entity = new HttpEntity<Request>(null, headers);
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort("/onap/so/infra/orchestrationRequests/v7/" + testRequestId + "?includeCloudRequest=true"));
    ResponseEntity<GetOrchestrationResponse> response = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, GetOrchestrationResponse.class);
    System.out.println("Response :" + response.getBody().toString());
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
    assertThat(response.getBody(), sameBeanAs(testResponse).ignoring("request.startTime").ignoring("request.finishTime").ignoring("request.requestStatus.timeStamp"));
    assertEquals("application/json", response.getHeaders().get(HttpHeaders.CONTENT_TYPE).get(0));
    assertEquals("0", response.getHeaders().get("X-MinorVersion").get(0));
    assertEquals("0", response.getHeaders().get("X-PatchVersion").get(0));
    assertEquals("7.0.0", response.getHeaders().get("X-LatestVersion").get(0));
    assertEquals("0321e28d-3dde-4b31-9b28-1e0f07231b93", response.getHeaders().get("X-TransactionID").get(0));
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) HashMap(java.util.HashMap) Request(org.onap.so.serviceinstancebeans.Request) ArrayList(java.util.ArrayList) GetOrchestrationResponse(org.onap.so.serviceinstancebeans.GetOrchestrationResponse) RequestProcessingData(org.onap.so.serviceinstancebeans.RequestProcessingData) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) CloudRequestData(org.onap.so.serviceinstancebeans.CloudRequestData) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 7 with Request

use of org.onap.so.serviceinstancebeans.Request in project so by onap.

the class OrchestrationRequestsTest method testUnlockOrchestrationRequest_Valid_Status.

@Test
public void testUnlockOrchestrationRequest_Valid_Status() throws JsonParseException, JsonMappingException, IOException, ValidationException {
    setupTestUnlockOrchestrationRequest_Valid_Status("5ffbabd6-b793-4377-a1ab-082670fbc7ac", "PENDING");
    String requestJSON = new String(Files.readAllBytes(Paths.get("src/test/resources/OrchestrationRequest/Request.json")));
    HttpHeaders headers = new HttpHeaders();
    headers.set("Accept", MediaType.APPLICATION_JSON);
    headers.set("Content-Type", MediaType.APPLICATION_JSON);
    HttpEntity<String> entity = new HttpEntity<String>(requestJSON, headers);
    UriComponentsBuilder builder;
    ResponseEntity<String> response;
    Request request;
    // Test valid status
    request = ORCHESTRATION_LIST.getRequestList().get(1).getRequest();
    builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort("/onap/so/infra/orchestrationRequests/v7/" + "5ffbabd6-b793-4377-a1ab-082670fbc7ac" + "/unlock"));
    response = restTemplate.exchange(builder.toUriString(), HttpMethod.POST, entity, String.class);
// Cannot assert anything further here, already have a wiremock in place
// which ensures that the post was
// properly called to update.
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) Request(org.onap.so.serviceinstancebeans.Request) Test(org.junit.Test)

Example 8 with Request

use of org.onap.so.serviceinstancebeans.Request in project so by onap.

the class OrchestrationRequestsTest method testGetOrchestrationRequestInvalidRequestID.

@Test
public void testGetOrchestrationRequestInvalidRequestID() throws Exception {
    setupTestGetOrchestrationRequest();
    // TEST INVALID REQUESTID
    GetOrchestrationResponse testResponse = new GetOrchestrationResponse();
    Request request = ORCHESTRATION_LIST.getRequestList().get(1).getRequest();
    testResponse.setRequest(request);
    String testRequestId = "00032ab7-pfb3-42e5-965d-8ea592502016";
    HttpHeaders headers = new HttpHeaders();
    headers.set("Accept", MediaType.APPLICATION_JSON);
    headers.set("Content-Type", MediaType.APPLICATION_JSON);
    HttpEntity<Request> entity = new HttpEntity<Request>(null, headers);
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort("/onap/so/infra/orchestrationRequests/v7/" + testRequestId));
    ResponseEntity<GetOrchestrationResponse> response = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, GetOrchestrationResponse.class);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) Request(org.onap.so.serviceinstancebeans.Request) GetOrchestrationResponse(org.onap.so.serviceinstancebeans.GetOrchestrationResponse) Test(org.junit.Test)

Example 9 with Request

use of org.onap.so.serviceinstancebeans.Request in project so by onap.

the class OrchestrationRequestsUnitTest method mapRequestStatusAndExtSysErrSrcToRequestNoFlowStatusTest.

@Test
public void mapRequestStatusAndExtSysErrSrcToRequestNoFlowStatusTest() throws ApiException {
    InstanceReferences instanceReferences = new InstanceReferences();
    instanceReferences.setServiceInstanceId(SERVICE_INSTANCE_ID);
    RequestStatus requestStatus = new RequestStatus();
    requestStatus.setRequestState(iar.getRequestStatus());
    requestStatus.setStatusMessage(String.format("RETRY STATUS: %s ROLLBACK STATUS: %s", RETRY_STATUS_MESSAGE, ROLLBACK_STATUS_MESSAGE));
    Request expected = new Request();
    expected.setRequestId(REQUEST_ID);
    expected.setInstanceReferences(instanceReferences);
    expected.setRequestStatus(requestStatus);
    expected.setRequestScope(SERVICE);
    expected.setStartTime(new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(startTime) + " GMT");
    includeCloudRequest = false;
    iar.setFlowStatus(null);
    iar.setResourceStatusMessage(null);
    Request actual = orchestrationRequests.mapInfraActiveRequestToRequest(iar, includeCloudRequest, OrchestrationRequestFormat.DETAIL.toString(), "v7");
    assertThat(actual, sameBeanAs(expected));
}
Also used : InstanceReferences(org.onap.so.serviceinstancebeans.InstanceReferences) Request(org.onap.so.serviceinstancebeans.Request) SimpleDateFormat(java.text.SimpleDateFormat) RequestStatus(org.onap.so.serviceinstancebeans.RequestStatus) Test(org.junit.Test)

Example 10 with Request

use of org.onap.so.serviceinstancebeans.Request in project so by onap.

the class OrchestrationRequestsUnitTest method mapRequestStatusAndExtSysErrSrcToRequestDetailTest.

@Test
public void mapRequestStatusAndExtSysErrSrcToRequestDetailTest() throws ApiException {
    doReturn("Last task executed: Call SDNC").when(camundaRequestHandler).getTaskName(REQUEST_ID);
    InstanceReferences instanceReferences = new InstanceReferences();
    instanceReferences.setServiceInstanceId(SERVICE_INSTANCE_ID);
    RequestStatus requestStatus = new RequestStatus();
    requestStatus.setRequestState(iar.getRequestStatus());
    requestStatus.setStatusMessage(String.format("FLOW STATUS: %s RETRY STATUS: %s ROLLBACK STATUS: %s RESOURCE STATUS: %s", FLOW_STATUS + TASK_INFORMATION, RETRY_STATUS_MESSAGE, ROLLBACK_STATUS_MESSAGE, "The vf module already exist"));
    Request expected = new Request();
    expected.setRequestId(REQUEST_ID);
    expected.setInstanceReferences(instanceReferences);
    expected.setRequestStatus(requestStatus);
    expected.setRequestScope(SERVICE);
    expected.setStartTime(new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(startTime) + " GMT");
    includeCloudRequest = false;
    Request actual = orchestrationRequests.mapInfraActiveRequestToRequest(iar, includeCloudRequest, OrchestrationRequestFormat.DETAIL.toString(), "v7");
    assertThat(actual, sameBeanAs(expected));
}
Also used : InstanceReferences(org.onap.so.serviceinstancebeans.InstanceReferences) Request(org.onap.so.serviceinstancebeans.Request) SimpleDateFormat(java.text.SimpleDateFormat) RequestStatus(org.onap.so.serviceinstancebeans.RequestStatus) Test(org.junit.Test)

Aggregations

Request (org.onap.so.serviceinstancebeans.Request)25 Test (org.junit.Test)22 InstanceReferences (org.onap.so.serviceinstancebeans.InstanceReferences)15 SimpleDateFormat (java.text.SimpleDateFormat)14 RequestStatus (org.onap.so.serviceinstancebeans.RequestStatus)14 HttpEntity (org.springframework.http.HttpEntity)8 HttpHeaders (org.springframework.http.HttpHeaders)8 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)8 GetOrchestrationResponse (org.onap.so.serviceinstancebeans.GetOrchestrationResponse)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ValidateException (org.onap.so.apihandlerinfra.exceptions.ValidateException)3 InfraActiveRequests (org.onap.so.db.request.beans.InfraActiveRequests)3 ValidationException (org.onap.so.exceptions.ValidationException)3 GetOrchestrationListResponse (org.onap.so.serviceinstancebeans.GetOrchestrationListResponse)3 RequestProcessingData (org.onap.so.serviceinstancebeans.RequestProcessingData)3 ServiceInstancesRequest (org.onap.so.serviceinstancebeans.ServiceInstancesRequest)3 Operation (io.swagger.v3.oas.annotations.Operation)2 IOException (java.io.IOException)2