Handle lazy init of activitySpecs
[so.git] / asdc-controller / src / test / java / org / onap / asdc / activity / DeployActivitySpecsITTest.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.assertTrue;
27 import static org.mockito.Mockito.when;
28 import org.junit.Test;
29 import org.mockito.Mock;
30 import org.onap.so.asdc.BaseTest;
31 import org.onap.so.asdc.activity.DeployActivitySpecs;
32 import org.onap.so.asdc.activity.beans.ActivitySpecCreateResponse;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.beans.factory.annotation.Value;
35 import org.springframework.core.env.Environment;
36 import org.springframework.http.HttpHeaders;
37 import com.fasterxml.jackson.databind.ObjectMapper;
38 import javax.ws.rs.core.MediaType;
39
40 public class DeployActivitySpecsITTest extends BaseTest {
41     @Mock
42     protected Environment env;
43
44     @Value("${wiremock.server.port}")
45     private String wiremockPort;
46
47     @Autowired
48     private DeployActivitySpecs deployActivitySpecs;
49
50     @Test
51     public void deployActivitySpecsIT_Test() throws Exception {
52         ActivitySpecCreateResponse activitySpecCreateResponse = new ActivitySpecCreateResponse();
53         activitySpecCreateResponse.setId("testActivityId");
54         HttpHeaders headers = new HttpHeaders();
55         headers.set("Accept", MediaType.APPLICATION_JSON);
56         headers.set("Content-Type", MediaType.APPLICATION_JSON);
57
58         ObjectMapper mapper = new ObjectMapper();
59         String body = mapper.writeValueAsString(activitySpecCreateResponse);
60
61         wireMockServer.stubFor(post(urlPathMatching("/v1.0/activity-spec"))
62                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
63                         .withStatus(org.springframework.http.HttpStatus.OK.value()).withBody(body)));
64
65         when(env.getProperty("mso.asdc.config.activity.endpoint")).thenReturn("http://localhost:8090");
66
67         String urlPath = "/v1.0/activity-spec/testActivityId/versions/latest/actions";
68
69         wireMockServer.stubFor(
70                 put(urlPathMatching(urlPath)).willReturn(aResponse().withHeader("Content-Type", "application/json")
71                         .withStatus(org.springframework.http.HttpStatus.OK.value())));
72
73         deployActivitySpecs.deployActivities();
74         assertTrue(activitySpecCreateResponse.getId().equals("testActivityId"));
75     }
76 }