Replaced all tabs with spaces in java and pom.xml
[so.git] / asdc-controller / src / test / java / org / onap / so / asdc / client / ASDCElementInfoTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2018 Huawei 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
22 package org.onap.so.asdc.client;
23
24
25
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertFalse;
28 import static org.junit.Assert.assertNotNull;
29 import static org.junit.Assert.assertTrue;
30 import java.util.Collections;
31 import java.util.UUID;
32 import org.junit.Test;
33 import org.mockito.Mockito;
34 import org.onap.sdc.api.notification.IArtifactInfo;
35 import org.onap.sdc.api.notification.INotificationData;
36 import org.onap.sdc.api.notification.IResourceInstance;
37 import org.onap.sdc.api.notification.IVfModuleMetadata;
38 import org.onap.so.asdc.client.ASDCConfiguration;
39 import org.onap.so.asdc.client.exceptions.ArtifactInstallerException;
40 import org.onap.so.asdc.installer.ASDCElementInfo;
41 import org.onap.so.asdc.installer.VfModuleStructure;
42 import org.onap.so.asdc.installer.VfResourceStructure;
43 import org.onap.so.asdc.installer.IVfModuleData;
44
45 public class ASDCElementInfoTest {
46
47     @Test
48     public void createASDCElementInfoWithNullParameterTest() {
49         ASDCElementInfo elementInfoFromNullVfArtifact = ASDCElementInfo.createElementFromVfArtifactInfo(null);
50         ASDCElementInfo elementInfoFromNullVfModuleStructure = ASDCElementInfo.createElementFromVfModuleStructure(null);
51         ASDCElementInfo elementInfoFromNullVfResourceStructure =
52                 ASDCElementInfo.createElementFromVfResourceStructure(null);
53
54         elementInfoFromNullVfArtifact.addElementInfo(null, null);
55         elementInfoFromNullVfModuleStructure.addElementInfo(null, "someValue");
56         elementInfoFromNullVfResourceStructure.addElementInfo("someKey", null);
57
58         assertEquals(elementInfoFromNullVfArtifact.toString(), "");
59         assertEquals(elementInfoFromNullVfModuleStructure.toString(), "");
60         assertEquals(elementInfoFromNullVfResourceStructure.toString(), "");
61
62         assertNotNull(elementInfoFromNullVfArtifact);
63         assertNotNull(elementInfoFromNullVfModuleStructure);
64         assertNotNull(elementInfoFromNullVfResourceStructure);
65
66         assertNotNull(ASDCElementInfo.EMPTY_INSTANCE);
67
68         assertEquals(elementInfoFromNullVfArtifact, ASDCElementInfo.EMPTY_INSTANCE);
69         assertEquals(elementInfoFromNullVfModuleStructure, ASDCElementInfo.EMPTY_INSTANCE);
70         assertEquals(elementInfoFromNullVfResourceStructure, ASDCElementInfo.EMPTY_INSTANCE);
71
72         assertEquals(ASDCElementInfo.EMPTY_INSTANCE.getType(), "");
73         assertEquals(ASDCElementInfo.EMPTY_INSTANCE.toString(), "");
74
75         assertEquals(elementInfoFromNullVfArtifact.getType(), ASDCElementInfo.EMPTY_INSTANCE.getType());
76         assertEquals(elementInfoFromNullVfModuleStructure.getType(), ASDCElementInfo.EMPTY_INSTANCE.getType());
77         assertEquals(elementInfoFromNullVfResourceStructure.getType(), ASDCElementInfo.EMPTY_INSTANCE.getType());
78     }
79
80     @Test
81     public void createASDCElementInfoFromVfResourceTest() {
82
83         String resourceInstanceName = "Resource 1";
84
85         UUID generatedUUID = UUID.randomUUID();
86
87         INotificationData notificationData = Mockito.mock(INotificationData.class);
88         IResourceInstance resourceInstance = Mockito.mock(IResourceInstance.class);
89
90         Mockito.when(resourceInstance.getResourceInstanceName()).thenReturn(resourceInstanceName);
91         Mockito.when(resourceInstance.getResourceInvariantUUID()).thenReturn(generatedUUID.toString());
92
93         VfResourceStructure vfResourceStructure = new VfResourceStructure(notificationData, resourceInstance);
94
95         ASDCElementInfo elementInfoFromVfResource =
96                 ASDCElementInfo.createElementFromVfResourceStructure(vfResourceStructure);
97
98         assertTrue(elementInfoFromVfResource.toString().contains(resourceInstanceName));
99         assertTrue(elementInfoFromVfResource.toString().contains(generatedUUID.toString()));
100
101         assertFalse(ASDCConfiguration.VF_MODULES_METADATA.equals(elementInfoFromVfResource.getType()));
102         assertEquals(ASDCElementInfo.ASDCElementTypeEnum.VNF_RESOURCE.name(), elementInfoFromVfResource.getType());
103
104         assertFalse(elementInfoFromVfResource.toString().contains("MyInfo1: someValue"));
105         elementInfoFromVfResource.addElementInfo("MyInfo1", "someValue");
106         assertTrue(elementInfoFromVfResource.toString().contains("MyInfo1: someValue"));
107     }
108
109     @Test
110     public void createASDCElementInfoFromVfModuleTest() throws ArtifactInstallerException {
111
112         String resourceInstanceName = "Resource 1";
113
114         UUID generatedUUID = UUID.randomUUID();
115
116         INotificationData notificationData = Mockito.mock(INotificationData.class);
117         IResourceInstance resourceInstance = Mockito.mock(IResourceInstance.class);
118
119         Mockito.when(resourceInstance.getResourceInstanceName()).thenReturn(resourceInstanceName);
120         Mockito.when(resourceInstance.getResourceInvariantUUID()).thenReturn(generatedUUID.toString());
121
122         VfResourceStructure vfResourceStructure = new VfResourceStructure(notificationData, resourceInstance);
123
124         // Create module structure now
125
126         String vfModuleModelName = "Module Model XYZ";
127
128         UUID generatedUUIDForModule = UUID.randomUUID();
129
130         IVfModuleData moduleMetadata = Mockito.mock(IVfModuleData.class);
131         Mockito.when(moduleMetadata.getVfModuleModelName()).thenReturn(vfModuleModelName);
132         Mockito.when(moduleMetadata.getVfModuleModelInvariantUUID()).thenReturn(generatedUUIDForModule.toString());
133         Mockito.when(moduleMetadata.getArtifacts()).thenReturn(Collections.<String>emptyList());
134
135         VfModuleStructure vfModuleStructure = new VfModuleStructure(vfResourceStructure, moduleMetadata);
136
137         ASDCElementInfo elementInfoFromVfModule = ASDCElementInfo.createElementFromVfModuleStructure(vfModuleStructure);
138
139         assertTrue(elementInfoFromVfModule.toString().contains(vfModuleModelName));
140         assertTrue(elementInfoFromVfModule.toString().contains(generatedUUIDForModule.toString()));
141
142         assertFalse(ASDCElementInfo.ASDCElementTypeEnum.VNF_RESOURCE.name().equals(elementInfoFromVfModule.getType()));
143         assertEquals(ASDCConfiguration.VF_MODULES_METADATA, elementInfoFromVfModule.getType());
144
145         assertFalse(elementInfoFromVfModule.toString().contains("MyInfo2: someValue"));
146         elementInfoFromVfModule.addElementInfo("MyInfo2", "someValue");
147         assertTrue(elementInfoFromVfModule.toString().contains("MyInfo2: someValue"));
148     }
149
150     @Test
151     public void createASDCElementInfoFromArtifact() {
152         for (String eVal : ASDCConfiguration.SUPPORTED_ARTIFACT_TYPES_LIST) {
153             String generatedArtifactName = eVal + " 1";
154             UUID generatedUUIDForArtifact = UUID.randomUUID();
155
156             IArtifactInfo artifactInfo = Mockito.mock(IArtifactInfo.class);
157             Mockito.when(artifactInfo.getArtifactType()).thenReturn(eVal);
158             Mockito.when(artifactInfo.getArtifactName()).thenReturn(generatedArtifactName);
159             Mockito.when(artifactInfo.getArtifactUUID()).thenReturn(generatedUUIDForArtifact.toString());
160
161             ASDCElementInfo elementInfoFromArtifact = ASDCElementInfo.createElementFromVfArtifactInfo(artifactInfo);
162
163             assertTrue(elementInfoFromArtifact.toString().contains(generatedArtifactName));
164             assertTrue(elementInfoFromArtifact.toString().contains(generatedUUIDForArtifact.toString()));
165
166             assertFalse(
167                     ASDCElementInfo.ASDCElementTypeEnum.VNF_RESOURCE.name().equals(elementInfoFromArtifact.getType()));
168             assertEquals(eVal, elementInfoFromArtifact.getType());
169
170             assertFalse(elementInfoFromArtifact.toString().contains("MyInfo3: someValue"));
171             elementInfoFromArtifact.addElementInfo("MyInfo3", "someValue");
172             assertTrue(elementInfoFromArtifact.toString().contains("MyInfo3: someValue"));
173         }
174     }
175 }