1e8b72d145809d55c7ff198120a54fbdd0753e28
[so.git] / asdc-controller / src / test / java / org / onap / so / asdc / installer / ToscaResourceStructureTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
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
21 package org.onap.so.asdc.installer;
22
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
30 import java.util.ArrayList;
31 import java.util.HashMap;
32
33 import org.junit.Rule;
34 import org.junit.Test;
35 import org.junit.rules.ExpectedException;
36 import org.onap.sdc.tosca.parser.impl.SdcCsarHelperImpl;
37 import org.onap.sdc.toscaparser.api.NodeTemplate;
38 import org.onap.sdc.toscaparser.api.elements.Metadata;
39 import org.onap.so.asdc.client.exceptions.ASDCDownloadException;
40 import org.onap.so.asdc.client.test.emulators.ArtifactInfoImpl;
41 import org.onap.so.db.catalog.beans.AllottedResource;
42 import org.onap.so.db.catalog.beans.AllottedResourceCustomization;
43 import org.onap.so.db.catalog.beans.NetworkResource;
44 import org.onap.so.db.catalog.beans.NetworkResourceCustomization;
45 import org.onap.so.db.catalog.beans.Service;
46 import org.onap.so.db.catalog.beans.TempNetworkHeatTemplateLookup;
47 import org.onap.so.db.catalog.beans.ToscaCsar;
48 import org.onap.so.db.catalog.beans.VfModule;
49 import org.onap.so.db.catalog.beans.VfModuleCustomization;
50 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
51
52 public class ToscaResourceStructureTest {
53         private ArtifactInfoImpl artifactInfo;
54         private SdcCsarHelperImpl sdcCsarHelper;
55         
56         private ToscaResourceStructure toscaResourceStructure;
57         
58         @Rule
59         public ExpectedException expectedException = ExpectedException.none();
60         
61         @Test
62         public void toscaResourceStructureBeanTest() {
63                 artifactInfo = mock(ArtifactInfoImpl.class);
64                 sdcCsarHelper = mock(SdcCsarHelperImpl.class);
65                 
66                 toscaResourceStructure = new ToscaResourceStructure();
67                 toscaResourceStructure.setHeatTemplateUUID("heatTemplateUUID");
68                 toscaResourceStructure.setAllottedList(new ArrayList<NodeTemplate>());
69                 toscaResourceStructure.setSdcCsarHelper(sdcCsarHelper);
70                 toscaResourceStructure.setServiceMetadata(new Metadata(new HashMap<>()));
71                 toscaResourceStructure.setCatalogService(new Service());
72                 toscaResourceStructure.setNetworkTypes(new ArrayList<>());
73                 toscaResourceStructure.setVfTypes(new ArrayList<>());
74                 toscaResourceStructure.setCatalogResourceCustomization(new AllottedResourceCustomization());
75                 toscaResourceStructure.setCatalogNetworkResourceCustomization(new NetworkResourceCustomization());
76                 toscaResourceStructure.setCatalogNetworkResource(new NetworkResource());
77                 toscaResourceStructure.setCatalogVfModule(new VfModule());
78                 toscaResourceStructure.setVnfResourceCustomization(new VnfResourceCustomization());
79                 toscaResourceStructure.setVfModuleCustomization(new VfModuleCustomization());
80                 toscaResourceStructure.setAllottedResource(new AllottedResource());
81                 toscaResourceStructure.setAllottedResourceCustomization(new AllottedResourceCustomization());
82                 toscaResourceStructure.setCatalogTempNetworkHeatTemplateLookup(new TempNetworkHeatTemplateLookup());
83                 toscaResourceStructure.setHeatFilesUUID("heatFilesUUID");
84                 toscaResourceStructure.setToscaArtifact(artifactInfo);
85                 toscaResourceStructure.setToscaCsar(new ToscaCsar());
86                 toscaResourceStructure.setVolHeatTemplateUUID("volHeatTemplateUUID");
87                 toscaResourceStructure.setEnvHeatTemplateUUID("envHeatTemplateUUID");
88                 toscaResourceStructure.setServiceVersion("serviceVersion");
89                 toscaResourceStructure.setWorkloadPerformance("workloadPerformance");
90                 toscaResourceStructure.setVfModule(new VfModule());
91                 toscaResourceStructure.setTempNetworkHeatTemplateLookup(new TempNetworkHeatTemplateLookup());
92                 toscaResourceStructure.setSuccessfulDeployment();
93                 
94                 assertEquals("heatTemplateUUID", toscaResourceStructure.getHeatTemplateUUID());
95                 assertThat(toscaResourceStructure.getAllottedList(), sameBeanAs(new ArrayList<NodeTemplate>()));
96                 assertEquals(sdcCsarHelper, toscaResourceStructure.getSdcCsarHelper());
97                 assertThat(toscaResourceStructure.getServiceMetadata(), sameBeanAs(new Metadata(new HashMap<>())));
98                 assertThat(toscaResourceStructure.getCatalogService(), sameBeanAs(new Service()));
99                 assertThat(toscaResourceStructure.getNetworkTypes(), sameBeanAs(new ArrayList<>()));
100                 assertThat(toscaResourceStructure.getVfTypes(), sameBeanAs(new ArrayList<>()));
101                 assertThat(toscaResourceStructure.getCatalogResourceCustomization(), sameBeanAs(new AllottedResourceCustomization()));
102                 assertThat(toscaResourceStructure.getCatalogNetworkResourceCustomization(), 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(), sameBeanAs(new AllottedResourceCustomization()));
109                 assertThat(toscaResourceStructure.getCatalogTempNetworkHeatTemplateLookup(), sameBeanAs(new TempNetworkHeatTemplateLookup()));
110                 assertEquals("heatFilesUUID", toscaResourceStructure.getHeatFilesUUID());
111                 assertEquals(artifactInfo, toscaResourceStructure.getToscaArtifact());
112                 assertThat(toscaResourceStructure.getToscaCsar(), sameBeanAs(new ToscaCsar()));
113                 assertEquals("volHeatTemplateUUID", toscaResourceStructure.getVolHeatTemplateUUID());
114                 assertEquals("envHeatTemplateUUID", toscaResourceStructure.getEnvHeatTemplateUUID());
115                 assertEquals("serviceVersion", toscaResourceStructure.getServiceVersion());
116                 assertEquals("workloadPerformance", toscaResourceStructure.getWorkloadPerformance());
117                 assertThat(toscaResourceStructure.getVfModule(), sameBeanAs(new VfModule()));
118                 assertThat(toscaResourceStructure.getTempNetworkHeatTemplateLookup(), sameBeanAs(new TempNetworkHeatTemplateLookup()));
119                 assertEquals(true, toscaResourceStructure.isDeployedSuccessfully());
120         }
121         
122         @Test
123         public void updateResourceStructureExceptionTest() throws Exception {
124                 expectedException.expect(ASDCDownloadException.class);
125                 
126                 artifactInfo = mock(ArtifactInfoImpl.class);
127                 toscaResourceStructure = new ToscaResourceStructure();
128
129                 doReturn("artifactName").when(artifactInfo).getArtifactName();
130                 
131                 toscaResourceStructure.updateResourceStructure(artifactInfo);
132         }
133 }