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 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.junit.MockitoJUnitRunner;
34 import org.onap.so.asdc.activity.ActivitySpecsActions;
35 import org.onap.so.asdc.activity.DeployActivitySpecs;
36 import org.onap.so.asdc.activity.beans.ActivitySpec;
37 import org.onap.so.asdc.activity.beans.ActivitySpecCreateResponse;
38 import org.onap.so.db.catalog.data.repository.ActivitySpecRepository;
39 import org.springframework.core.env.Environment;
40 import com.fasterxml.jackson.databind.ObjectMapper;
41 import java.nio.file.Paths;
42 import java.util.ArrayList;
43 import java.util.List;
45 @RunWith(MockitoJUnitRunner.class)
46 public class DeployActivitySpecsTest {
48 protected Environment env;
51 protected ActivitySpecRepository activitySpecRepository;
54 protected ActivitySpecsActions activitySpecsActions;
57 private DeployActivitySpecs deployActivitySpecs;
60 public void deployActivitySpecs_Test() throws Exception {
61 boolean deploymentSuccessful = true;
62 ActivitySpecCreateResponse activitySpecCreateResponse = new ActivitySpecCreateResponse();
63 activitySpecCreateResponse.setId("testActivityId");
64 ObjectMapper mapper = new ObjectMapper();
65 org.onap.so.db.catalog.beans.ActivitySpec catalogActivitySpec = mapper.readValue(
66 new String(Files.readAllBytes(Paths.get("src/test/resources/ActivitySpecFromCatalog.json"))),
67 org.onap.so.db.catalog.beans.ActivitySpec.class);
68 List<org.onap.so.db.catalog.beans.ActivitySpec> catalogActivitySpecList =
69 new ArrayList<org.onap.so.db.catalog.beans.ActivitySpec>();
70 catalogActivitySpecList.add(catalogActivitySpec);
71 when(env.getProperty("mso.asdc.config.activity.endpoint")).thenReturn("testEndpoint");
72 when(activitySpecRepository.findAll()).thenReturn(catalogActivitySpecList);
73 doReturn("testActivityId").when(activitySpecsActions).createActivitySpec(Mockito.any(), Mockito.any());
74 doReturn(true).when(activitySpecsActions).certifyActivitySpec(Mockito.any(), Mockito.any());
75 deployActivitySpecs.deployActivities();
76 assertTrue(deploymentSuccessful);
80 public void mapActivitySpecFromCatalogToSdc_Test() throws Exception {
81 ObjectMapper mapper = new ObjectMapper();
82 org.onap.so.db.catalog.beans.ActivitySpec catalogActivitySpec = mapper.readValue(
83 new String(Files.readAllBytes(Paths.get("src/test/resources/ActivitySpecFromCatalog.json"))),
84 org.onap.so.db.catalog.beans.ActivitySpec.class);
85 ActivitySpec activitySpec = deployActivitySpecs.mapActivitySpecFromCatalogToSdc(catalogActivitySpec);
86 ActivitySpec expected = mapper.readValue(
87 new String(Files.readAllBytes(Paths.get("src/test/resources/ActivitySpec.json"))), ActivitySpec.class);
88 assertThat(expected, sameBeanAs(activitySpec));