Search in sources :

Example 1 with ActivitySpecCreateResponse

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

the class DeployActivitySpecsITTest method deployActivitySpecsIT_SDCEndpointDown_Test.

@Test
public void deployActivitySpecsIT_SDCEndpointDown_Test() throws Exception {
    ActivitySpecCreateResponse activitySpecCreateResponse = new ActivitySpecCreateResponse();
    activitySpecCreateResponse.setId("testActivityId");
    HttpHeaders headers = new HttpHeaders();
    headers.set("Accept", MediaType.APPLICATION_JSON);
    headers.set("Content-Type", MediaType.APPLICATION_JSON);
    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.OK.value()).withBody(body)));
    when(env.getProperty("mso.asdc.config.activity.endpoint")).thenReturn("http://localhost:8090");
    String urlPath = "/v1.0/activity-spec/testActivityId/versions/latest/actions";
    wireMockServer.stubFor(put(urlPathMatching(urlPath)).willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(org.springframework.http.HttpStatus.OK.value())));
    String host = "http://localhost:8090";
    when(deployActivitySpecsM.checkHttpServerUp(host)).thenReturn(false);
    deployActivitySpecsM.deployActivities();
    verify(0, putRequestedFor(urlEqualTo(urlPath)));
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ActivitySpecCreateResponse(org.onap.so.asdc.activity.beans.ActivitySpecCreateResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BaseTest(org.onap.so.asdc.BaseTest) Test(org.junit.Test)

Example 2 with ActivitySpecCreateResponse

use of org.onap.so.asdc.activity.beans.ActivitySpecCreateResponse 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 3 with ActivitySpecCreateResponse

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

the class DeployActivitySpecsTest method deployActivitySpecs_Test.

@Test
public void deployActivitySpecs_Test() throws Exception {
    boolean deploymentSuccessful = true;
    ActivitySpecCreateResponse activitySpecCreateResponse = new ActivitySpecCreateResponse();
    activitySpecCreateResponse.setId("testActivityId");
    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);
    List<org.onap.so.db.catalog.beans.ActivitySpec> catalogActivitySpecList = new ArrayList<org.onap.so.db.catalog.beans.ActivitySpec>();
    catalogActivitySpecList.add(catalogActivitySpec);
    when(env.getProperty("mso.asdc.config.activity.endpoint")).thenReturn("http://testEndpoint");
    doReturn(true).when(deployActivitySpecs).checkHttpServerUp("http://testEndpoint");
    when(activitySpecRepository.findAll()).thenReturn(catalogActivitySpecList);
    doReturn("testActivityId").when(activitySpecsActions).createActivitySpec(Mockito.any(), Mockito.any());
    doReturn(true).when(activitySpecsActions).certifyActivitySpec(Mockito.any(), Mockito.any());
    deployActivitySpecs.deployActivities();
    assertTrue(deploymentSuccessful);
}
Also used : ActivitySpecCreateResponse(org.onap.so.asdc.activity.beans.ActivitySpecCreateResponse) ArrayList(java.util.ArrayList) ActivitySpec(org.onap.so.asdc.activity.beans.ActivitySpec) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 4 with ActivitySpecCreateResponse

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

the class ActivitySpecsActions method createActivitySpec.

public String createActivitySpec(String hostname, ActivitySpec activitySpec) {
    if (activitySpec == null) {
        return null;
    }
    try {
        ObjectMapper mapper = new ObjectMapper();
        mapper.setSerializationInclusion(Include.NON_NULL);
        String payload = mapper.writer().writeValueAsString(activitySpec);
        String urlString = UriBuilder.fromUri(hostname).path(ACTIVITY_SPEC_URI).build().toString();
        URL url = new URL(urlString);
        HttpClient httpClient = httpClientFactory.newJsonClient(url, ONAPComponents.SDC);
        httpClient.addAdditionalHeader("Content-Type", ContentType.APPLICATION_JSON.toString());
        Response response = httpClient.post(payload);
        int statusCode = response.getStatus();
        if (statusCode == HttpStatus.SC_UNPROCESSABLE_ENTITY) {
            logger.warn(LoggingAnchor.THREE, "ActivitySpec", activitySpec.getName(), "already exists in SDC");
            return null;
        }
        if (statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_CREATED) {
            logger.warn(LoggingAnchor.THREE, "Error creating activity spec", activitySpec.getName(), statusCode);
            return null;
        }
        if (response.getEntity() == null) {
            logger.warn(LoggingAnchor.TWO, "No activity spec response returned", activitySpec.getName());
            return null;
        }
        ActivitySpecCreateResponse activitySpecCreateResponse = response.readEntity(ActivitySpecCreateResponse.class);
        if (activitySpecCreateResponse == null) {
            logger.warn(LoggingAnchor.TWO, "Unable to read activity spec", activitySpec.getName());
            return null;
        }
        return activitySpecCreateResponse.getId();
    } catch (Exception e) {
        logger.warn(LoggingAnchor.TWO, "Exception creating activitySpec", e);
    }
    return null;
}
Also used : ActivitySpecCreateResponse(org.onap.so.asdc.activity.beans.ActivitySpecCreateResponse) Response(javax.ws.rs.core.Response) ActivitySpecCreateResponse(org.onap.so.asdc.activity.beans.ActivitySpecCreateResponse) HttpClient(org.onap.so.client.HttpClient) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) URL(java.net.URL)

Example 5 with ActivitySpecCreateResponse

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

the class DeployActivitySpecsITTest method deployActivitySpecsIT_Test.

@Test
public void deployActivitySpecsIT_Test() throws Exception {
    ActivitySpecCreateResponse activitySpecCreateResponse = new ActivitySpecCreateResponse();
    activitySpecCreateResponse.setId("testActivityId");
    HttpHeaders headers = new HttpHeaders();
    headers.set("Accept", MediaType.APPLICATION_JSON);
    headers.set("Content-Type", MediaType.APPLICATION_JSON);
    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.OK.value()).withBody(body)));
    when(env.getProperty("mso.asdc.config.activity.endpoint")).thenReturn("http://localhost:8090");
    String urlPath = "/v1.0/activity-spec/testActivityId/versions/latest/actions";
    wireMockServer.stubFor(put(urlPathMatching(urlPath)).willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(org.springframework.http.HttpStatus.OK.value())));
    deployActivitySpecs.deployActivities();
    assertTrue(activitySpecCreateResponse.getId().equals("testActivityId"));
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ActivitySpecCreateResponse(org.onap.so.asdc.activity.beans.ActivitySpecCreateResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BaseTest(org.onap.so.asdc.BaseTest) Test(org.junit.Test)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 ActivitySpecCreateResponse (org.onap.so.asdc.activity.beans.ActivitySpecCreateResponse)7 Test (org.junit.Test)6 BaseTest (org.onap.so.asdc.BaseTest)5 ActivitySpec (org.onap.so.asdc.activity.beans.ActivitySpec)4 HttpHeaders (org.springframework.http.HttpHeaders)2 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Response (javax.ws.rs.core.Response)1 HttpClient (org.onap.so.client.HttpClient)1