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 CertifyActivitySpec_Test() throws Exception {
60 String HOSTNAME = createURLWithPort("");
62 String activitySpecId = "testActivitySpec";
63 String urlPath = "/v1.0/activity-spec/testActivitySpec/versions/latest/actions";
65 wireMockServer.stubFor(
66 put(urlPathMatching(urlPath)).willReturn(aResponse().withHeader("Content-Type", "application/json")
67 .withStatus(org.springframework.http.HttpStatus.OK.value())));
69 boolean certificationResult = activitySpecsActions.certifyActivitySpec(HOSTNAME, activitySpecId);
70 assertTrue(certificationResult);
73 private String createURLWithPort(String uri) {
74 return "http://localhost:" + wireMockPort + uri;