Search in sources :

Example 6 with OperationalEnvServiceModelStatus

use of org.onap.so.db.request.beans.OperationalEnvServiceModelStatus 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 7 with OperationalEnvServiceModelStatus

use of org.onap.so.db.request.beans.OperationalEnvServiceModelStatus 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 8 with OperationalEnvServiceModelStatus

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

the class ActivateVnfDBHelperTest method testOperationalEnvServiceModelStatusDbMethods.

@Test
public void testOperationalEnvServiceModelStatusDbMethods() throws Exception {
    // test insert method
    OperationalEnvServiceModelStatus serviceModelStatus1 = dbHelper.insertRecordToOperationalEnvServiceModelStatus(requestId, operationalEnvironmentId, serviceModelVersionId1, statusOk, recoveryActionRetry, retryCountThree, workloadContext1, vnfOperationalEnvironmentId);
    assertThat(serviceModelStatus1, sameBeanAs(expectedServiceModelStatus));
    // prepare updated expected object
    OperationalEnvServiceModelStatus expectedUpdatedServiceModelStatus = serviceModelStatus1;
    expectedUpdatedServiceModelStatus.setServiceModelVersionDistrStatus(statusError);
    expectedUpdatedServiceModelStatus.setRetryCount(new Integer(retryCountZero));
    // test update method - update statusOk to statusError & retryCountThree to retryCountZero
    OperationalEnvServiceModelStatus serviceModelStatus2 = dbHelper.updateRetryCountAndStatusInOperationalEnvServiceModelStatus(serviceModelStatus1, statusError, retryCountZero);
    assertThat(serviceModelStatus2, sameBeanAs(expectedUpdatedServiceModelStatus));
}
Also used : OperationalEnvServiceModelStatus(org.onap.so.db.request.beans.OperationalEnvServiceModelStatus) BaseTest(org.onap.so.apihandlerinfra.BaseTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with OperationalEnvServiceModelStatus

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

the class OperationalEnvServiceModelStatusTest method updateWithoutAllKeys.

@Test
public void updateWithoutAllKeys() throws Exception {
    OperationalEnvServiceModelStatus status = new OperationalEnvServiceModelStatus();
    status.setRequestId("request-id-1");
    status.setOperationalEnvId("oper-env-id-1");
    status.setServiceModelVersionId("service-model-ver-id-1");
    status.setVnfOperationalEnvId("vnf-oper-env-id-1");
    status.setRetryCount(0);
    repository.saveAndFlush(status);
    OperationalEnvServiceModelStatus status2 = repository.findOneByOperationalEnvIdAndServiceModelVersionIdAndRequestId("oper-env-id-1", "service-model-ver-id-1", "request-id-1");
    status2.setRetryCount(1);
    assertEquals("request-id-1", status2.getRequestId());
    assertEquals("vnf-oper-env-id-1", status2.getVnfOperationalEnvId());
    repository.saveAndFlush(status2);
    OperationalEnvServiceModelStatus status3 = new OperationalEnvServiceModelStatus();
    status3.setRequestId("request-id-2");
    status3.setOperationalEnvId("oper-env-id-1");
    status3.setServiceModelVersionId("service-model-ver-id-2");
    status3.setVnfOperationalEnvId("vnf-oper-env-id-2");
    status3.setRetryCount(2);
    repository.saveAndFlush(status3);
    OperationalEnvServiceModelStatus exampleObj = new OperationalEnvServiceModelStatus();
    exampleObj.setOperationalEnvId("oper-env-id-1");
    exampleObj.setServiceModelVersionId("service-model-ver-id-1");
    ExampleMatcher matcher = ExampleMatcher.matching().withIgnorePaths("requestId");
    OperationalEnvServiceModelStatus foundStatus = repository.findOne(Example.of(exampleObj, matcher)).orElseThrow(() -> new NoEntityFoundException("Cannot Find Operation"));
    if (foundStatus == null)
        throw new Exception("No status found");
    assertEquals(new Integer(1), foundStatus.getRetryCount());
}
Also used : NoEntityFoundException(org.onap.so.db.request.exceptions.NoEntityFoundException) ExampleMatcher(org.springframework.data.domain.ExampleMatcher) OperationalEnvServiceModelStatus(org.onap.so.db.request.beans.OperationalEnvServiceModelStatus) NoEntityFoundException(org.onap.so.db.request.exceptions.NoEntityFoundException) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with OperationalEnvServiceModelStatus

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

the class ActivateVnfStatusOperationalEnvironmentTest method executionTest_ERROR_Status_And_RETRY.

@Test
public void executionTest_ERROR_Status_And_RETRY() throws Exception {
    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);
    wireMockServer.stubFor(get(urlPathEqualTo("/operationalEnvServiceModelStatus/search/findOneByOperationalEnvIdAndServiceModelVersionIdAndRequestId")).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withBody(mapper.writeValueAsString(serviceModelDb)).withStatus(HttpStatus.SC_OK)));
    OperationalEnvDistributionStatus distributionDb = new OperationalEnvDistributionStatus();
    distributionDb.setDistributionId(sdcDistributionId);
    distributionDb.setRequestId(requestIdOrig);
    distributionDb.setOperationalEnvId(operationalEnvironmentId);
    distributionDb.setDistributionIdStatus(statusError);
    distributionDb.setServiceModelVersionId(serviceModelVersionId);
    distributionDb.setDistributionIdErrorReason(null);
    // prepare new 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);
    // prepare sdc return data
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("statusCode", "202");
    jsonObject.put("message", "Success");
    jsonObject.put("distributionId", sdcDistributionId1);
    wireMockServer.stubFor(post(urlPathMatching("/sdc/v1/catalog/services/.*")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(jsonObject.toString()).withStatus(HttpStatus.SC_ACCEPTED)));
    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(post(urlPathEqualTo("/operationalEnvDistributionStatus/")).withRequestBody(equalTo("{\"distributionId\":\"TEST_distributionId\",\"operationalEnvId\":\"TEST_operationalEnvironmentId\",\"serviceModelVersionId\":\"TEST_serviceModelVersionId\",\"requestId\":\"TEST_requestIdOrig\",\"distributionIdStatus\":\"DISTRIBUTION_COMPLETE_ERROR\",\"distributionIdErrorReason\":\"Unable to process.\",\"createTime\":null,\"modifyTime\":null,\"handler\":{}}")).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withStatus(HttpStatus.SC_OK)));
    wireMockServer.stubFor(post(urlPathEqualTo("/operationalEnvDistributionStatus/")).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withStatus(HttpStatus.SC_OK)));
    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,\"vnfOperationalEnvId\":\"VNF_operationalEnvironmentId\"}")).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 : 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) BaseTest(org.onap.so.apihandlerinfra.BaseTest) Test(org.junit.Test)

Aggregations

OperationalEnvServiceModelStatus (org.onap.so.db.request.beans.OperationalEnvServiceModelStatus)20 Test (org.junit.Test)13 BaseTest (org.onap.so.apihandlerinfra.BaseTest)11 OperationalEnvDistributionStatus (org.onap.so.db.request.beans.OperationalEnvDistributionStatus)11 JSONObject (org.json.JSONObject)7 Distribution (org.onap.so.apihandlerinfra.tenantisolationbeans.Distribution)7 InfraActiveRequests (org.onap.so.db.request.beans.InfraActiveRequests)7 ApiException (org.onap.so.apihandlerinfra.exceptions.ApiException)4 ErrorLoggerInfo (org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo)3 ValidateException (org.onap.so.apihandlerinfra.exceptions.ValidateException)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 Before (org.junit.Before)1 Ignore (org.junit.Ignore)1 AAIFluentTypeBuilder (org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder)1 ServiceModelList (org.onap.so.apihandlerinfra.tenantisolationbeans.ServiceModelList)1 NoEntityFoundException (org.onap.so.db.request.exceptions.NoEntityFoundException)1 ExampleMatcher (org.springframework.data.domain.ExampleMatcher)1