Search in sources :

Example 21 with InfraActiveRequests

use of org.onap.so.db.request.beans.InfraActiveRequests in project so by onap.

the class ActivateVnfStatusOperationalEnvironmentTest method executionTest_ERROR_Status_And_RETRY_And_ErrorSdc.

@Test
public void executionTest_ERROR_Status_And_RETRY_And_ErrorSdc() throws JsonProcessingException {
    OperationalEnvServiceModelStatus serviceModelDb = new OperationalEnvServiceModelStatus();
    serviceModelDb.setRequestId(requestIdOrig);
    serviceModelDb.setServiceModelVersionId(serviceModelVersionId);
    serviceModelDb.setWorkloadContext(workloadContext);
    serviceModelDb.setRecoveryAction(recoveryActionRetry);
    serviceModelDb.setOperationalEnvId(operationalEnvironmentId);
    serviceModelDb.setRetryCount(retryCountThree);
    serviceModelDb.setServiceModelVersionDistrStatus(statusError);
    serviceModelDb.setVnfOperationalEnvId(vnfOperationalEnvironmentId);
    OperationalEnvDistributionStatus distributionDb = new OperationalEnvDistributionStatus();
    distributionDb.setDistributionId(sdcDistributionId);
    distributionDb.setRequestId(requestIdOrig);
    distributionDb.setOperationalEnvId(operationalEnvironmentId);
    distributionDb.setDistributionIdStatus(statusError);
    distributionDb.setServiceModelVersionId(serviceModelVersionId);
    distributionDb.setDistributionIdErrorReason(null);
    // prepare distribution obj
    Distribution distribution = new Distribution();
    distribution.setStatus(Status.DISTRIBUTION_COMPLETE_ERROR);
    distribution.setErrorReason("Unable to process.");
    request.setDistribution(distribution);
    request.setDistributionId(sdcDistributionId);
    request.setOperationalEnvironmentId(operationalEnvironmentId);
    // ERROR in sdc
    JSONObject jsonMessages = new JSONObject();
    jsonMessages.put("statusCode", "409");
    jsonMessages.put("message", "Undefined Error Message!");
    jsonMessages.put("messageId", "SVC4675");
    jsonMessages.put("text", "Error: Service state is invalid for this action.");
    JSONObject jsonServException = new JSONObject();
    jsonServException.put("serviceException", jsonMessages);
    JSONObject jsonErrorRequest = new JSONObject();
    jsonErrorRequest.put("requestError", jsonServException);
    InfraActiveRequests iar = new InfraActiveRequests();
    iar.setRequestId(requestIdOrig);
    iar.setRequestStatus("PENDING");
    wireMockServer.stubFor(get(urlPathEqualTo("/operationalEnvServiceModelStatus/search/findOneByOperationalEnvIdAndServiceModelVersionIdAndRequestId")).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withBody(mapper.writeValueAsString(serviceModelDb)).withStatus(HttpStatus.SC_OK)));
    wireMockServer.stubFor(get(urlPathEqualTo("/operationalEnvDistributionStatus/" + sdcDistributionId)).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withBody(mapper.writeValueAsString(distributionDb)).withStatus(HttpStatus.SC_OK)));
    wireMockServer.stubFor(get(urlPathEqualTo("/infraActiveRequests/" + requestIdOrig)).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withBody(mapper.writeValueAsString(iar)).withStatus(HttpStatus.SC_OK)));
    wireMockServer.stubFor(post(urlPathEqualTo("/infraActiveRequests/")).withRequestBody(containing("operationalEnvId\":\"VNF_operationalEnvironmentId\"")).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withStatus(HttpStatus.SC_OK)));
    wireMockServer.stubFor(post(urlPathMatching("/sdc/v1/catalog/services/.*")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(jsonMessages.toString()).withStatus(HttpStatus.SC_CONFLICT)));
    wireMockServer.stubFor(get(urlPathMatching("/aai/" + AAIVersion.LATEST + "/cloud-infrastructure/operational-environments/.*")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(json).withStatus(HttpStatus.SC_ACCEPTED)));
    wireMockServer.stubFor(put(urlPathMatching("/aai/" + AAIVersion.LATEST + "/cloud-infrastructure/operational-environments/.*")).willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_ACCEPTED)));
    try {
        activateVnfStatus.execute(requestId, request);
    } catch (ApiException e) {
        assertThat(e.getMessage(), startsWith("Failure calling SDC: statusCode: "));
        assertEquals(e.getHttpResponseCode(), HttpStatus.SC_BAD_REQUEST);
        assertEquals(e.getMessageID(), ErrorNumbers.SVC_DETAILED_SERVICE_ERROR);
    }
}
Also used : JSONObject(org.json.JSONObject) OperationalEnvDistributionStatus(org.onap.so.db.request.beans.OperationalEnvDistributionStatus) Distribution(org.onap.so.apihandlerinfra.tenantisolationbeans.Distribution) OperationalEnvServiceModelStatus(org.onap.so.db.request.beans.OperationalEnvServiceModelStatus) InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException) BaseTest(org.onap.so.apihandlerinfra.BaseTest) Test(org.junit.Test)

Example 22 with InfraActiveRequests

use of org.onap.so.db.request.beans.InfraActiveRequests in project so by onap.

the class ActivateVnfStatusOperationalEnvironmentTest method executionTest_ERROR_Status_And_SKIP.

@Test
public void executionTest_ERROR_Status_And_SKIP() throws Exception {
    OperationalEnvServiceModelStatus serviceModelDb = new OperationalEnvServiceModelStatus();
    serviceModelDb.setRequestId(requestIdOrig);
    serviceModelDb.setServiceModelVersionId(serviceModelVersionId);
    serviceModelDb.setWorkloadContext(workloadContext);
    serviceModelDb.setRecoveryAction(recoveryActionSkip);
    serviceModelDb.setOperationalEnvId(operationalEnvironmentId);
    serviceModelDb.setRetryCount(retryCountThree);
    serviceModelDb.setServiceModelVersionDistrStatus(statusError);
    serviceModelDb.setVnfOperationalEnvId(vnfOperationalEnvironmentId);
    OperationalEnvDistributionStatus distributionDb = new OperationalEnvDistributionStatus();
    distributionDb.setDistributionId(sdcDistributionId);
    distributionDb.setRequestId(requestIdOrig);
    distributionDb.setOperationalEnvId(operationalEnvironmentId);
    distributionDb.setDistributionIdStatus(statusError);
    distributionDb.setServiceModelVersionId(serviceModelVersionId);
    distributionDb.setDistributionIdErrorReason(null);
    // prepare distribution obj
    OperationalEnvDistributionStatus distributionStatus = new OperationalEnvDistributionStatus(sdcDistributionId, operationalEnvironmentId, serviceModelVersionId);
    distributionStatus.setDistributionIdStatus(Status.DISTRIBUTION_COMPLETE_ERROR.name());
    Distribution distribution = new Distribution();
    distribution.setStatus(Status.DISTRIBUTION_COMPLETE_ERROR);
    request.setDistribution(distribution);
    request.setDistributionId(sdcDistributionId);
    request.setOperationalEnvironmentId(operationalEnvironmentId);
    InfraActiveRequests iar = new InfraActiveRequests();
    iar.setRequestId(requestIdOrig);
    iar.setRequestStatus("PENDING");
    wireMockServer.stubFor(get(urlPathEqualTo("/operationalEnvServiceModelStatus/search/findOneByOperationalEnvIdAndServiceModelVersionIdAndRequestId")).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withBody(mapper.writeValueAsString(serviceModelDb)).withStatus(HttpStatus.SC_OK)));
    wireMockServer.stubFor(get(urlPathEqualTo("/operationalEnvDistributionStatus/" + sdcDistributionId)).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withBody(mapper.writeValueAsString(distributionDb)).withStatus(HttpStatus.SC_OK)));
    wireMockServer.stubFor(get(urlPathEqualTo("/infraActiveRequests/" + requestIdOrig)).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withBody(mapper.writeValueAsString(iar)).withStatus(HttpStatus.SC_OK)));
    wireMockServer.stubFor(post(urlPathEqualTo("/operationalEnvServiceModelStatus/")).withRequestBody(equalTo("{\"requestId\":\"TEST_requestIdOrig\",\"operationalEnvId\":\"TEST_operationalEnvironmentId\",\"serviceModelVersionId\":\"TEST_serviceModelVersionId\",\"serviceModelVersionDistrStatus\":\"DISTRIBUTION_COMPLETE_OK\",\"recoveryAction\":\"SKIP\",\"retryCount\":0,\"workloadContext\":\"TEST_workloadContext\",\"createTime\":null,\"modifyTime\":null,\"vnfOperationalEnvId\":\"VNF_operationalEnvironmentId\"}")).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withStatus(HttpStatus.SC_OK)));
    wireMockServer.stubFor(post(urlPathEqualTo("/operationalEnvDistributionStatus/")).withRequestBody(equalTo("{\"distributionId\":\"TEST_distributionId\",\"operationalEnvId\":\"TEST_operationalEnvironmentId\",\"serviceModelVersionId\":\"TEST_serviceModelVersionId\",\"requestId\":\"TEST_requestIdOrig\",\"distributionIdStatus\":\"DISTRIBUTION_COMPLETE_OK\",\"distributionIdErrorReason\":\"\",\"createTime\":null,\"modifyTime\":null}")).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withStatus(HttpStatus.SC_OK)));
    wireMockServer.stubFor(get(urlPathMatching("/aai/" + AAIVersion.LATEST + "/cloud-infrastructure/operational-environments/.*")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(json).withStatus(HttpStatus.SC_ACCEPTED)));
    wireMockServer.stubFor(put(urlPathMatching("/aai/" + AAIVersion.LATEST + "/cloud-infrastructure/operational-environments/.*")).willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_ACCEPTED)));
    activateVnfStatus.execute(requestId, request);
}
Also used : OperationalEnvDistributionStatus(org.onap.so.db.request.beans.OperationalEnvDistributionStatus) Distribution(org.onap.so.apihandlerinfra.tenantisolationbeans.Distribution) OperationalEnvServiceModelStatus(org.onap.so.db.request.beans.OperationalEnvServiceModelStatus) InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) BaseTest(org.onap.so.apihandlerinfra.BaseTest) Test(org.junit.Test)

Example 23 with InfraActiveRequests

use of org.onap.so.db.request.beans.InfraActiveRequests in project so by onap.

the class ActivateVnfStatusOperationalEnvironmentTest method executionTest_ERROR_Status_And_RETRY_And_RetryZero.

@Test
public void executionTest_ERROR_Status_And_RETRY_And_RetryZero() throws JsonProcessingException {
    OperationalEnvServiceModelStatus serviceModelDb = new OperationalEnvServiceModelStatus();
    serviceModelDb.setRequestId(requestIdOrig);
    serviceModelDb.setServiceModelVersionId(serviceModelVersionId);
    serviceModelDb.setWorkloadContext(workloadContext);
    serviceModelDb.setRecoveryAction(recoveryActionRetry);
    serviceModelDb.setOperationalEnvId(operationalEnvironmentId);
    serviceModelDb.setRetryCount(retryCountZero);
    serviceModelDb.setServiceModelVersionDistrStatus(statusError);
    serviceModelDb.setVnfOperationalEnvId(vnfOperationalEnvironmentId);
    OperationalEnvDistributionStatus distributionDb = new OperationalEnvDistributionStatus();
    distributionDb.setDistributionId(sdcDistributionId);
    distributionDb.setRequestId(requestIdOrig);
    distributionDb.setOperationalEnvId(operationalEnvironmentId);
    distributionDb.setDistributionIdStatus(statusError);
    distributionDb.setServiceModelVersionId(serviceModelVersionId);
    distributionDb.setDistributionIdErrorReason(null);
    // prepare distribution obj
    Distribution distribution = new Distribution();
    distribution.setStatus(Status.DISTRIBUTION_COMPLETE_ERROR);
    request.setDistribution(distribution);
    request.setDistributionId(sdcDistributionId);
    request.setOperationalEnvironmentId(operationalEnvironmentId);
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("statusCode", "202");
    jsonObject.put("message", "Success");
    jsonObject.put("distributionId", sdcDistributionId);
    InfraActiveRequests iar = new InfraActiveRequests();
    iar.setRequestId(requestIdOrig);
    iar.setRequestStatus("PENDING");
    wireMockServer.stubFor(get(urlPathEqualTo("/operationalEnvServiceModelStatus/search/findOneByOperationalEnvIdAndServiceModelVersionIdAndRequestId")).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withBody(mapper.writeValueAsString(serviceModelDb)).withStatus(HttpStatus.SC_OK)));
    wireMockServer.stubFor(get(urlPathEqualTo("/operationalEnvDistributionStatus/" + sdcDistributionId)).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withBody(mapper.writeValueAsString(distributionDb)).withStatus(HttpStatus.SC_OK)));
    wireMockServer.stubFor(get(urlPathEqualTo("/infraActiveRequests/" + requestIdOrig)).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withBody(mapper.writeValueAsString(iar)).withStatus(HttpStatus.SC_OK)));
    wireMockServer.stubFor(post(urlPathMatching("/sdc/v1/catalog/services/.*")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(jsonObject.toString()).withStatus(HttpStatus.SC_ACCEPTED)));
    wireMockServer.stubFor(post(urlPathEqualTo("/operationalEnvServiceModelStatus/")).withRequestBody(equalTo("{\"requestId\":\"TEST_requestIdOrig\",\"operationalEnvId\":\"TEST_operationalEnvironmentId\",\"serviceModelVersionId\":\"TEST_serviceModelVersionId\",\"serviceModelVersionDistrStatus\":\"SENT\",\"recoveryAction\":\"RETRY\",\"retryCount\":2,\"workloadContext\":\"TEST_workloadContext\",\"createTime\":null,\"modifyTime\":null,\"handler\":{}}")).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withStatus(HttpStatus.SC_OK)));
    wireMockServer.stubFor(get(urlPathMatching("/aai/" + AAIVersion.LATEST + "/cloud-infrastructure/operational-environments/.*")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(json).withStatus(HttpStatus.SC_ACCEPTED)));
    wireMockServer.stubFor(put(urlPathMatching("/aai/" + AAIVersion.LATEST + "/cloud-infrastructure/operational-environments/.*")).willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_ACCEPTED)));
    try {
        activateVnfStatus.execute(requestId, request);
    } catch (ApiException e) {
        assertThat(e.getMessage(), startsWith("Overall Activation process is a Failure. "));
        assertEquals(e.getHttpResponseCode(), HttpStatus.SC_BAD_REQUEST);
        assertEquals(e.getMessageID(), ErrorNumbers.SVC_DETAILED_SERVICE_ERROR);
    }
}
Also used : JSONObject(org.json.JSONObject) OperationalEnvDistributionStatus(org.onap.so.db.request.beans.OperationalEnvDistributionStatus) Distribution(org.onap.so.apihandlerinfra.tenantisolationbeans.Distribution) OperationalEnvServiceModelStatus(org.onap.so.db.request.beans.OperationalEnvServiceModelStatus) InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException) BaseTest(org.onap.so.apihandlerinfra.BaseTest) Test(org.junit.Test)

Example 24 with InfraActiveRequests

use of org.onap.so.db.request.beans.InfraActiveRequests in project so by onap.

the class RequestHandlerUtilsUnitTest method setInstanceIdAndNameServiceTest.

@Test
public void setInstanceIdAndNameServiceTest() throws ApiException {
    InfraActiveRequests serviceRequest = new InfraActiveRequests();
    InfraActiveRequests expected = new InfraActiveRequests();
    expected.setServiceInstanceId(SERVICE_INSTANCE_ID);
    expected.setServiceInstanceName(SERVICE_INSTANCE_NAME);
    requestHandler.setInstanceIdAndName(infraActiveRequest, serviceRequest);
    assertThat(serviceRequest, sameBeanAs(expected));
}
Also used : InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) Test(org.junit.Test)

Example 25 with InfraActiveRequests

use of org.onap.so.db.request.beans.InfraActiveRequests in project so by onap.

the class RequestHandlerUtilsUnitTest method setInstanceIdAndNameServiceNullInstanceNameTest.

@Test
public void setInstanceIdAndNameServiceNullInstanceNameTest() throws ApiException {
    InfraActiveRequests serviceRequest = new InfraActiveRequests();
    InfraActiveRequests request = new InfraActiveRequests();
    request.setServiceInstanceId(SERVICE_INSTANCE_ID);
    request.setRequestScope(ModelType.service.toString());
    InfraActiveRequests expected = new InfraActiveRequests();
    expected.setServiceInstanceId(SERVICE_INSTANCE_ID);
    requestHandler.setInstanceIdAndName(request, serviceRequest);
    assertThat(serviceRequest, sameBeanAs(expected));
}
Also used : InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) Test(org.junit.Test)

Aggregations

InfraActiveRequests (org.onap.so.db.request.beans.InfraActiveRequests)214 Test (org.junit.Test)119 BaseTaskTest (org.onap.so.bpmn.BaseTaskTest)29 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)26 Timestamp (java.sql.Timestamp)23 HttpEntity (org.springframework.http.HttpEntity)21 IOException (java.io.IOException)20 HashMap (java.util.HashMap)20 ApiException (org.onap.so.apihandlerinfra.exceptions.ApiException)20 ValidateException (org.onap.so.apihandlerinfra.exceptions.ValidateException)19 ServiceInstancesRequest (org.onap.so.serviceinstancebeans.ServiceInstancesRequest)19 BaseTest (org.onap.so.apihandlerinfra.BaseTest)18 ErrorLoggerInfo (org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo)18 ArrayList (java.util.ArrayList)16 ValidationException (org.onap.so.exceptions.ValidationException)15 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)13 Transactional (javax.transaction.Transactional)13 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)12 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)11 ResponseBuilder (org.onap.so.apihandler.common.ResponseBuilder)11