2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.asdc.activity;
22 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
23 import static com.github.tomakehurst.wiremock.client.WireMock.post;
24 import static com.github.tomakehurst.wiremock.client.WireMock.put;
25 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching;
26 import static org.junit.Assert.*;
27 import org.junit.Test;
28 import org.onap.so.asdc.BaseTest;
29 import org.onap.so.asdc.activity.ActivitySpecsActions;
30 import org.onap.so.asdc.activity.beans.ActivitySpec;
31 import org.onap.so.asdc.activity.beans.ActivitySpecCreateResponse;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import com.fasterxml.jackson.databind.ObjectMapper;
35 public class ActivitySpecsActionsTest extends BaseTest {
37 ActivitySpecsActions activitySpecsActions;
40 public void CreateActivitySpec_Test() throws Exception {
41 String HOSTNAME = createURLWithPort("");
43 ActivitySpec activitySpec = new ActivitySpec();
44 activitySpec.setName("testActivitySpec");
45 activitySpec.setDescription("Test Activity Spec");
46 ActivitySpecCreateResponse activitySpecCreateResponse = new ActivitySpecCreateResponse();
47 activitySpecCreateResponse.setId("testActivityId");
48 ObjectMapper mapper = new ObjectMapper();
49 String body = mapper.writeValueAsString(activitySpecCreateResponse);
50 wireMockServer.stubFor(post(urlPathMatching("/v1.0/activity-spec"))
51 .willReturn(aResponse().withHeader("Content-Type", "application/json")
52 .withStatus(org.springframework.http.HttpStatus.OK.value()).withBody(body)));
54 String activitySpecId = activitySpecsActions.createActivitySpec(HOSTNAME, activitySpec);
55 assertEquals("testActivityId", activitySpecId);
59 public void CreateActivitySpecReturnsCreated_Test() throws Exception {
60 String HOSTNAME = createURLWithPort("");
62 ActivitySpec activitySpec = new ActivitySpec();
63 activitySpec.setName("testActivitySpec");
64 activitySpec.setDescription("Test Activity Spec");
65 ActivitySpecCreateResponse activitySpecCreateResponse = new ActivitySpecCreateResponse();
66 activitySpecCreateResponse.setId("testActivityId");
67 ObjectMapper mapper = new ObjectMapper();
68 String body = mapper.writeValueAsString(activitySpecCreateResponse);
69 wireMockServer.stubFor(post(urlPathMatching("/v1.0/activity-spec"))
70 .willReturn(aResponse().withHeader("Content-Type", "application/json")
71 .withStatus(org.springframework.http.HttpStatus.CREATED.value()).withBody(body)));
73 String activitySpecId = activitySpecsActions.createActivitySpec(HOSTNAME, activitySpec);
74 assertEquals("testActivityId", activitySpecId);
78 public void CreateActivitySpecReturnsExists_Test() throws Exception {
79 String HOSTNAME = createURLWithPort("");
81 ActivitySpec activitySpec = new ActivitySpec();
82 activitySpec.setName("testActivitySpec");
83 activitySpec.setDescription("Test Activity Spec");
84 ActivitySpecCreateResponse activitySpecCreateResponse = new ActivitySpecCreateResponse();
85 activitySpecCreateResponse.setId("testActivityId");
86 ObjectMapper mapper = new ObjectMapper();
87 String body = mapper.writeValueAsString(activitySpecCreateResponse);
88 wireMockServer.stubFor(post(urlPathMatching("/v1.0/activity-spec"))
89 .willReturn(aResponse().withHeader("Content-Type", "application/json")
90 .withStatus(org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY.value()).withBody(body)));
92 String activitySpecId = activitySpecsActions.createActivitySpec(HOSTNAME, activitySpec);
93 assertEquals(null, activitySpecId);
97 public void CertifyActivitySpec_Test() throws Exception {
98 String HOSTNAME = createURLWithPort("");
100 String activitySpecId = "testActivitySpec";
101 String urlPath = "/v1.0/activity-spec/testActivitySpec/versions/latest/actions";
103 wireMockServer.stubFor(
104 put(urlPathMatching(urlPath)).willReturn(aResponse().withHeader("Content-Type", "application/json")
105 .withStatus(org.springframework.http.HttpStatus.OK.value())));
107 boolean certificationResult = activitySpecsActions.certifyActivitySpec(HOSTNAME, activitySpecId);
108 assertTrue(certificationResult);
112 public void CertifyActivitySpecReturnsExists_Test() throws Exception {
113 String HOSTNAME = createURLWithPort("");
115 String activitySpecId = "testActivitySpec";
116 String urlPath = "/v1.0/activity-spec/testActivitySpec/versions/latest/actions";
118 wireMockServer.stubFor(
119 put(urlPathMatching(urlPath)).willReturn(aResponse().withHeader("Content-Type", "application/json")
120 .withStatus(org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY.value())));
122 boolean certificationResult = activitySpecsActions.certifyActivitySpec(HOSTNAME, activitySpecId);
123 assertFalse(certificationResult);
126 private String createURLWithPort(String uri) {
127 return "http://localhost:" + wireMockPort + uri;