Search in sources :

Example 1 with ActivitySpec

use of org.onap.so.asdc.activity.beans.ActivitySpec in project so by onap.

the class ActivitySpecsActionsTest method CreateActivitySpecReturnsCreated_Test.

@Test
public void CreateActivitySpecReturnsCreated_Test() throws Exception {
    String HOSTNAME = createURLWithPort("");
    ActivitySpec activitySpec = new ActivitySpec();
    activitySpec.setName("testActivitySpec");
    activitySpec.setDescription("Test Activity Spec");
    ActivitySpecCreateResponse activitySpecCreateResponse = new ActivitySpecCreateResponse();
    activitySpecCreateResponse.setId("testActivityId");
    ObjectMapper mapper = new ObjectMapper();
    String body = mapper.writeValueAsString(activitySpecCreateResponse);
    wireMockServer.stubFor(post(urlPathMatching("/v1.0/activity-spec")).willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(org.springframework.http.HttpStatus.CREATED.value()).withBody(body)));
    String activitySpecId = activitySpecsActions.createActivitySpec(HOSTNAME, activitySpec);
    assertEquals("testActivityId", activitySpecId);
}
Also used : ActivitySpecCreateResponse(org.onap.so.asdc.activity.beans.ActivitySpecCreateResponse) ActivitySpec(org.onap.so.asdc.activity.beans.ActivitySpec) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BaseTest(org.onap.so.asdc.BaseTest) Test(org.junit.Test)

Example 2 with ActivitySpec

use of org.onap.so.asdc.activity.beans.ActivitySpec in project so by onap.

the class DeployActivitySpecsTest method mapActivitySpecFromCatalogToSdc_Test.

@Test
public void mapActivitySpecFromCatalogToSdc_Test() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    org.onap.so.db.catalog.beans.ActivitySpec catalogActivitySpec = mapper.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/ActivitySpecFromCatalog.json"))), org.onap.so.db.catalog.beans.ActivitySpec.class);
    ActivitySpec activitySpec = deployActivitySpecs.mapActivitySpecFromCatalogToSdc(catalogActivitySpec);
    ActivitySpec expected = mapper.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/ActivitySpec.json"))), ActivitySpec.class);
    assertThat(expected, sameBeanAs(activitySpec));
}
Also used : ActivitySpec(org.onap.so.asdc.activity.beans.ActivitySpec) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 3 with ActivitySpec

use of org.onap.so.asdc.activity.beans.ActivitySpec in project so by onap.

the class DeployActivitySpecs method mapActivitySpecFromCatalogToSdc.

public ActivitySpec mapActivitySpecFromCatalogToSdc(org.onap.so.db.catalog.beans.ActivitySpec activitySpecFromCatalog) {
    ActivitySpec activitySpec = new ActivitySpec();
    activitySpec.setName(activitySpecFromCatalog.getName());
    activitySpec.setDescription(activitySpecFromCatalog.getDescription());
    mapCategoryList(activitySpecFromCatalog.getActivitySpecActivitySpecCategories(), activitySpec);
    mapInputsAndOutputs(activitySpecFromCatalog.getActivitySpecActivitySpecParameters(), activitySpec);
    return activitySpec;
}
Also used : ActivitySpec(org.onap.so.asdc.activity.beans.ActivitySpec)

Example 4 with ActivitySpec

use of org.onap.so.asdc.activity.beans.ActivitySpec in project so by onap.

the class DeployActivitySpecs method deployActivities.

@Transactional
public void deployActivities() {
    String hostname = env.getProperty(SDC_ENDPOINT);
    logger.debug("{} {}", "SDC ActivitySpec endpoint: ", hostname);
    if (hostname == null || hostname.isEmpty()) {
        logger.warn("The hostname for SDC activities deployment is not configured in SO");
        return;
    }
    if (!checkHttpServerUp(hostname)) {
        logger.warn("The sdc end point is not alive");
        return;
    }
    List<org.onap.so.db.catalog.beans.ActivitySpec> activitySpecsFromCatalog = activitySpecRepository.findAll();
    for (org.onap.so.db.catalog.beans.ActivitySpec activitySpecFromCatalog : activitySpecsFromCatalog) {
        logger.debug("{} {}", "Attempting to create activity ", activitySpecFromCatalog.getName());
        ActivitySpec activitySpec = mapActivitySpecFromCatalogToSdc(activitySpecFromCatalog);
        String activitySpecId = activitySpecsActions.createActivitySpec(hostname, activitySpec);
        if (activitySpecId == null) {
            logger.info(LoggingAnchor.TWO, "Failed to create activitySpec", activitySpec.getName());
            continue;
        }
        logger.info(LoggingAnchor.TWO, "Successfully created activitySpec", activitySpec.getName());
        boolean certificationResult = activitySpecsActions.certifyActivitySpec(hostname, activitySpecId);
        if (!certificationResult) {
            logger.info(LoggingAnchor.TWO, "Failed to certify activitySpec", activitySpec.getName());
            continue;
        }
        logger.info(LoggingAnchor.TWO, "Successfully certified activitySpec", activitySpec.getName());
    }
}
Also used : ActivitySpec(org.onap.so.asdc.activity.beans.ActivitySpec) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with ActivitySpec

use of org.onap.so.asdc.activity.beans.ActivitySpec in project so by onap.

the class ActivitySpecsActionsTest method CreateActivitySpecReturnsExists_Test.

@Test
public void CreateActivitySpecReturnsExists_Test() throws Exception {
    String HOSTNAME = createURLWithPort("");
    ActivitySpec activitySpec = new ActivitySpec();
    activitySpec.setName("testActivitySpec");
    activitySpec.setDescription("Test Activity Spec");
    ActivitySpecCreateResponse activitySpecCreateResponse = new ActivitySpecCreateResponse();
    activitySpecCreateResponse.setId("testActivityId");
    ObjectMapper mapper = new ObjectMapper();
    String body = mapper.writeValueAsString(activitySpecCreateResponse);
    wireMockServer.stubFor(post(urlPathMatching("/v1.0/activity-spec")).willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY.value()).withBody(body)));
    String activitySpecId = activitySpecsActions.createActivitySpec(HOSTNAME, activitySpec);
    assertEquals(null, activitySpecId);
}
Also used : ActivitySpecCreateResponse(org.onap.so.asdc.activity.beans.ActivitySpecCreateResponse) ActivitySpec(org.onap.so.asdc.activity.beans.ActivitySpec) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BaseTest(org.onap.so.asdc.BaseTest) Test(org.junit.Test)

Aggregations

ActivitySpec (org.onap.so.asdc.activity.beans.ActivitySpec)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 Test (org.junit.Test)4 BaseTest (org.onap.so.asdc.BaseTest)3 ActivitySpecCreateResponse (org.onap.so.asdc.activity.beans.ActivitySpecCreateResponse)3 Transactional (org.springframework.transaction.annotation.Transactional)1