7a876a67a2e795032f90f1a1a6ff64f5c8bce8d0
[so.git] / asdc-controller / src / test / java / org / onap / asdc / activity / DeployActivitySpecsTest.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 java.nio.file.Files;
23 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
24 import static org.junit.Assert.assertThat;
25 import static org.junit.Assert.assertTrue;
26 import static org.mockito.Mockito.doReturn;
27 import static org.mockito.Mockito.when;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import org.mockito.InjectMocks;
31 import org.mockito.Mock;
32 import org.mockito.Mockito;
33 import org.mockito.Spy;
34 import org.mockito.junit.MockitoJUnitRunner;
35 import org.onap.so.asdc.activity.ActivitySpecsActions;
36 import org.onap.so.asdc.activity.DeployActivitySpecs;
37 import org.onap.so.asdc.activity.beans.ActivitySpec;
38 import org.onap.so.asdc.activity.beans.ActivitySpecCreateResponse;
39 import org.onap.so.db.catalog.data.repository.ActivitySpecRepository;
40 import org.springframework.core.env.Environment;
41 import com.fasterxml.jackson.databind.ObjectMapper;
42 import java.nio.file.Paths;
43 import java.util.ArrayList;
44 import java.util.List;
45
46 @RunWith(MockitoJUnitRunner.class)
47 public class DeployActivitySpecsTest {
48     @Mock
49     protected Environment env;
50
51     @Mock
52     protected ActivitySpecRepository activitySpecRepository;
53
54     @Mock
55     protected ActivitySpecsActions activitySpecsActions;
56
57     @InjectMocks
58     @Spy
59     private DeployActivitySpecs deployActivitySpecs;
60
61     @Test
62     public void deployActivitySpecs_Test() throws Exception {
63         boolean deploymentSuccessful = true;
64         ActivitySpecCreateResponse activitySpecCreateResponse = new ActivitySpecCreateResponse();
65         activitySpecCreateResponse.setId("testActivityId");
66         ObjectMapper mapper = new ObjectMapper();
67         org.onap.so.db.catalog.beans.ActivitySpec catalogActivitySpec = mapper.readValue(
68                 new String(Files.readAllBytes(Paths.get("src/test/resources/ActivitySpecFromCatalog.json"))),
69                 org.onap.so.db.catalog.beans.ActivitySpec.class);
70         List<org.onap.so.db.catalog.beans.ActivitySpec> catalogActivitySpecList =
71                 new ArrayList<org.onap.so.db.catalog.beans.ActivitySpec>();
72         catalogActivitySpecList.add(catalogActivitySpec);
73         when(env.getProperty("mso.asdc.config.activity.endpoint")).thenReturn("http://testEndpoint");
74         doReturn(true).when(deployActivitySpecs).checkHttpOk("http://testEndpoint");
75         when(activitySpecRepository.findAll()).thenReturn(catalogActivitySpecList);
76         doReturn("testActivityId").when(activitySpecsActions).createActivitySpec(Mockito.any(), Mockito.any());
77         doReturn(true).when(activitySpecsActions).certifyActivitySpec(Mockito.any(), Mockito.any());
78         deployActivitySpecs.deployActivities();
79         assertTrue(deploymentSuccessful);
80     }
81
82     @Test
83     public void mapActivitySpecFromCatalogToSdc_Test() throws Exception {
84         ObjectMapper mapper = new ObjectMapper();
85         org.onap.so.db.catalog.beans.ActivitySpec catalogActivitySpec = mapper.readValue(
86                 new String(Files.readAllBytes(Paths.get("src/test/resources/ActivitySpecFromCatalog.json"))),
87                 org.onap.so.db.catalog.beans.ActivitySpec.class);
88         ActivitySpec activitySpec = deployActivitySpecs.mapActivitySpecFromCatalogToSdc(catalogActivitySpec);
89         ActivitySpec expected = mapper.readValue(
90                 new String(Files.readAllBytes(Paths.get("src/test/resources/ActivitySpec.json"))), ActivitySpec.class);
91         assertThat(expected, sameBeanAs(activitySpec));
92     }
93 }