2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2018 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=========================================================
21 package org.onap.so.asdc.installer;
23 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertThat;
26 import static org.mockito.Mockito.doReturn;
27 import static org.mockito.Mockito.doThrow;
28 import static org.mockito.Mockito.mock;
29 import java.util.ArrayList;
30 import java.util.HashMap;
31 import org.junit.Rule;
32 import org.junit.Test;
33 import org.junit.rules.ExpectedException;
34 import org.onap.sdc.tosca.parser.impl.SdcCsarHelperImpl;
35 import org.onap.sdc.toscaparser.api.NodeTemplate;
36 import org.onap.sdc.toscaparser.api.elements.Metadata;
37 import org.onap.so.asdc.client.exceptions.ASDCDownloadException;
38 import org.onap.so.asdc.client.test.emulators.ArtifactInfoImpl;
39 import org.onap.so.db.catalog.beans.AllottedResource;
40 import org.onap.so.db.catalog.beans.AllottedResourceCustomization;
41 import org.onap.so.db.catalog.beans.NetworkResource;
42 import org.onap.so.db.catalog.beans.NetworkResourceCustomization;
43 import org.onap.so.db.catalog.beans.Service;
44 import org.onap.so.db.catalog.beans.TempNetworkHeatTemplateLookup;
45 import org.onap.so.db.catalog.beans.ToscaCsar;
46 import org.onap.so.db.catalog.beans.VfModule;
47 import org.onap.so.db.catalog.beans.VfModuleCustomization;
48 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
50 public class ToscaResourceStructureTest {
51 private ArtifactInfoImpl artifactInfo;
52 private SdcCsarHelperImpl sdcCsarHelper;
54 private ToscaResourceStructure toscaResourceStructure;
57 public ExpectedException expectedException = ExpectedException.none();
60 public void toscaResourceStructureBeanTest() {
61 artifactInfo = mock(ArtifactInfoImpl.class);
62 sdcCsarHelper = mock(SdcCsarHelperImpl.class);
64 toscaResourceStructure = new ToscaResourceStructure();
65 toscaResourceStructure.setHeatTemplateUUID("heatTemplateUUID");
66 toscaResourceStructure.setAllottedList(new ArrayList<NodeTemplate>());
67 toscaResourceStructure.setSdcCsarHelper(sdcCsarHelper);
68 toscaResourceStructure.setServiceMetadata(new Metadata(new HashMap<>()));
69 toscaResourceStructure.setCatalogService(new Service());
70 toscaResourceStructure.setNetworkTypes(new ArrayList<>());
71 toscaResourceStructure.setVfTypes(new ArrayList<>());
72 toscaResourceStructure.setCatalogResourceCustomization(new AllottedResourceCustomization());
73 toscaResourceStructure.setCatalogNetworkResourceCustomization(new NetworkResourceCustomization());
74 toscaResourceStructure.setCatalogNetworkResource(new NetworkResource());
75 toscaResourceStructure.setCatalogVfModule(new VfModule());
76 toscaResourceStructure.setVnfResourceCustomization(new VnfResourceCustomization());
77 toscaResourceStructure.setVfModuleCustomization(new VfModuleCustomization());
78 toscaResourceStructure.setAllottedResource(new AllottedResource());
79 toscaResourceStructure.setAllottedResourceCustomization(new AllottedResourceCustomization());
80 toscaResourceStructure.setCatalogTempNetworkHeatTemplateLookup(new TempNetworkHeatTemplateLookup());
81 toscaResourceStructure.setHeatFilesUUID("heatFilesUUID");
82 toscaResourceStructure.setToscaArtifact(artifactInfo);
83 toscaResourceStructure.setToscaCsar(new ToscaCsar());
84 toscaResourceStructure.setVolHeatTemplateUUID("volHeatTemplateUUID");
85 toscaResourceStructure.setEnvHeatTemplateUUID("envHeatTemplateUUID");
86 toscaResourceStructure.setServiceVersion("serviceVersion");
87 toscaResourceStructure.setWorkloadPerformance("workloadPerformance");
88 toscaResourceStructure.setVfModule(new VfModule());
89 toscaResourceStructure.setTempNetworkHeatTemplateLookup(new TempNetworkHeatTemplateLookup());
90 toscaResourceStructure.setSuccessfulDeployment();
92 assertEquals("heatTemplateUUID", toscaResourceStructure.getHeatTemplateUUID());
93 assertThat(toscaResourceStructure.getAllottedList(), sameBeanAs(new ArrayList<NodeTemplate>()));
94 assertEquals(sdcCsarHelper, toscaResourceStructure.getSdcCsarHelper());
95 assertThat(toscaResourceStructure.getServiceMetadata(), sameBeanAs(new Metadata(new HashMap<>())));
96 assertThat(toscaResourceStructure.getCatalogService(), sameBeanAs(new Service()));
97 assertThat(toscaResourceStructure.getNetworkTypes(), sameBeanAs(new ArrayList<>()));
98 assertThat(toscaResourceStructure.getVfTypes(), sameBeanAs(new ArrayList<>()));
99 assertThat(toscaResourceStructure.getCatalogResourceCustomization(),
100 sameBeanAs(new AllottedResourceCustomization()));
101 assertThat(toscaResourceStructure.getCatalogNetworkResourceCustomization(),
102 sameBeanAs(new NetworkResourceCustomization()));
103 assertThat(toscaResourceStructure.getCatalogNetworkResource(), sameBeanAs(new NetworkResource()));
104 assertThat(toscaResourceStructure.getCatalogVfModule(), sameBeanAs(new VfModule()));
105 assertThat(toscaResourceStructure.getVnfResourceCustomization(), sameBeanAs(new VnfResourceCustomization()));
106 assertThat(toscaResourceStructure.getVfModuleCustomization(), sameBeanAs(new VfModuleCustomization()));
107 assertThat(toscaResourceStructure.getAllottedResource(), sameBeanAs(new AllottedResource()));
108 assertThat(toscaResourceStructure.getAllottedResourceCustomization(),
109 sameBeanAs(new AllottedResourceCustomization()));
110 assertThat(toscaResourceStructure.getCatalogTempNetworkHeatTemplateLookup(),
111 sameBeanAs(new TempNetworkHeatTemplateLookup()));
112 assertEquals("heatFilesUUID", toscaResourceStructure.getHeatFilesUUID());
113 assertEquals(artifactInfo, toscaResourceStructure.getToscaArtifact());
114 assertThat(toscaResourceStructure.getToscaCsar(), sameBeanAs(new ToscaCsar()));
115 assertEquals("volHeatTemplateUUID", toscaResourceStructure.getVolHeatTemplateUUID());
116 assertEquals("envHeatTemplateUUID", toscaResourceStructure.getEnvHeatTemplateUUID());
117 assertEquals("serviceVersion", toscaResourceStructure.getServiceVersion());
118 assertEquals("workloadPerformance", toscaResourceStructure.getWorkloadPerformance());
119 assertThat(toscaResourceStructure.getVfModule(), sameBeanAs(new VfModule()));
120 assertThat(toscaResourceStructure.getTempNetworkHeatTemplateLookup(),
121 sameBeanAs(new TempNetworkHeatTemplateLookup()));
122 assertEquals(true, toscaResourceStructure.isDeployedSuccessfully());
126 public void updateResourceStructureExceptionTest() throws Exception {
127 expectedException.expect(ASDCDownloadException.class);
129 artifactInfo = mock(ArtifactInfoImpl.class);
130 toscaResourceStructure = new ToscaResourceStructure();
132 doReturn("artifactName").when(artifactInfo).getArtifactName();
134 toscaResourceStructure.updateResourceStructure(artifactInfo);