438120924af16d27c9ab6af3ae3f5e46967fd32d
[so.git] / asdc-controller / src / test / java / org / onap / asdc / activity / ActivitySpecsActionsTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20 package org.onap.asdc.activity;
21
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;
34
35 public class ActivitySpecsActionsTest extends BaseTest {
36     @Autowired
37     ActivitySpecsActions activitySpecsActions;
38
39     @Test
40     public void CreateActivitySpec_Test() throws Exception {
41         String HOSTNAME = createURLWithPort("");
42
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)));
53
54         String activitySpecId = activitySpecsActions.createActivitySpec(HOSTNAME, activitySpec);
55         assertEquals("testActivityId", activitySpecId);
56     }
57
58     @Test
59     public void CertifyActivitySpec_Test() throws Exception {
60         String HOSTNAME = createURLWithPort("");
61
62         String activitySpecId = "testActivitySpec";
63         String urlPath = "/v1.0/activity-spec/testActivitySpec/versions/latest/actions";
64
65         wireMockServer.stubFor(
66                 put(urlPathMatching(urlPath)).willReturn(aResponse().withHeader("Content-Type", "application/json")
67                         .withStatus(org.springframework.http.HttpStatus.OK.value())));
68
69         boolean certificationResult = activitySpecsActions.certifyActivitySpec(HOSTNAME, activitySpecId);
70         assertTrue(certificationResult);
71     }
72
73     private String createURLWithPort(String uri) {
74         return "http://localhost:" + wireMockPort + uri;
75     }
76 }