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)));
}
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);
}
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);
}
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;
}
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"));
}
Aggregations