Change the header to SO
[so.git] / asdc-controller / src / test / java / org / openecomp / mso / asdc / client / tests / ASDCElementInfoTest.java
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * ONAP - SO\r
4  * ================================================================================\r
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  *\r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  *\r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ============LICENSE_END=========================================================\r
19  */\r
20 \r
21 \r
22 package org.openecomp.mso.asdc.client.tests;\r
23 \r
24 \r
25 \r
26 import static org.junit.Assert.assertEquals;\r
27 import static org.junit.Assert.assertFalse;\r
28 import static org.junit.Assert.assertNotNull;\r
29 import static org.junit.Assert.assertTrue;\r
30 \r
31 import java.util.Collections;\r
32 import java.util.UUID;\r
33 \r
34 import org.junit.Test;\r
35 import org.mockito.Mockito;\r
36 import org.openecomp.sdc.api.notification.IArtifactInfo;\r
37 import org.openecomp.sdc.api.notification.INotificationData;\r
38 import org.openecomp.sdc.api.notification.IResourceInstance;\r
39 import org.openecomp.sdc.api.notification.IVfModuleMetadata;\r
40 import org.openecomp.mso.asdc.client.ASDCConfiguration;\r
41 import org.openecomp.mso.asdc.client.exceptions.ArtifactInstallerException;\r
42 import org.openecomp.mso.asdc.installer.ASDCElementInfo;\r
43 import org.openecomp.mso.asdc.installer.VfModuleStructure;\r
44 import org.openecomp.mso.asdc.installer.VfResourceStructure;\r
45 import org.openecomp.mso.asdc.installer.IVfModuleData;\r
46 \r
47 public class ASDCElementInfoTest {\r
48 \r
49         @Test\r
50         public void createASDCElementInfoWithNullParameterTest() {\r
51                 ASDCElementInfo elementInfoFromNullVfArtifact = ASDCElementInfo.createElementFromVfArtifactInfo(null);\r
52                 ASDCElementInfo elementInfoFromNullVfModuleStructure = ASDCElementInfo.createElementFromVfModuleStructure(null);\r
53                 ASDCElementInfo elementInfoFromNullVfResourceStructure = ASDCElementInfo.createElementFromVfResourceStructure(null);\r
54 \r
55                 elementInfoFromNullVfArtifact.addElementInfo(null, null);\r
56                 elementInfoFromNullVfModuleStructure.addElementInfo(null, "someValue");\r
57                 elementInfoFromNullVfResourceStructure.addElementInfo("someKey", null);\r
58 \r
59                 assertEquals(elementInfoFromNullVfArtifact.toString(), "");\r
60                 assertEquals(elementInfoFromNullVfModuleStructure.toString(), "");\r
61                 assertEquals(elementInfoFromNullVfResourceStructure.toString(), "");\r
62 \r
63                 assertNotNull(elementInfoFromNullVfArtifact);\r
64                 assertNotNull(elementInfoFromNullVfModuleStructure);\r
65                 assertNotNull(elementInfoFromNullVfResourceStructure);\r
66 \r
67                 assertNotNull(ASDCElementInfo.EMPTY_INSTANCE);\r
68 \r
69                 assertEquals(elementInfoFromNullVfArtifact, ASDCElementInfo.EMPTY_INSTANCE);\r
70                 assertEquals(elementInfoFromNullVfModuleStructure, ASDCElementInfo.EMPTY_INSTANCE);\r
71                 assertEquals(elementInfoFromNullVfResourceStructure, ASDCElementInfo.EMPTY_INSTANCE);\r
72 \r
73                 assertEquals(ASDCElementInfo.EMPTY_INSTANCE.getType(), "");\r
74                 assertEquals(ASDCElementInfo.EMPTY_INSTANCE.toString(), "");\r
75 \r
76                 assertEquals(elementInfoFromNullVfArtifact.getType(), ASDCElementInfo.EMPTY_INSTANCE.getType());\r
77                 assertEquals(elementInfoFromNullVfModuleStructure.getType(), ASDCElementInfo.EMPTY_INSTANCE.getType());\r
78                 assertEquals(elementInfoFromNullVfResourceStructure.getType(), ASDCElementInfo.EMPTY_INSTANCE.getType());\r
79         }\r
80 \r
81         @Test\r
82         public void createASDCElementInfoFromVfResourceTest() {\r
83 \r
84                 String resourceInstanceName = "Resource 1";\r
85 \r
86                 UUID generatedUUID = UUID.randomUUID();\r
87 \r
88                 INotificationData notificationData = Mockito.mock(INotificationData.class);\r
89                 IResourceInstance resourceInstance = Mockito.mock(IResourceInstance.class);\r
90 \r
91                 Mockito.when(resourceInstance.getResourceInstanceName()).thenReturn(resourceInstanceName);\r
92                 Mockito.when(resourceInstance.getResourceInvariantUUID()).thenReturn(generatedUUID.toString());\r
93 \r
94                 VfResourceStructure vfResourceStructure = new VfResourceStructure(notificationData, resourceInstance);\r
95 \r
96                 ASDCElementInfo elementInfoFromVfResource = ASDCElementInfo.createElementFromVfResourceStructure(vfResourceStructure);\r
97 \r
98                 assertTrue(elementInfoFromVfResource.toString().contains(resourceInstanceName));\r
99                 assertTrue(elementInfoFromVfResource.toString().contains(generatedUUID.toString()));\r
100 \r
101                 assertFalse(ASDCConfiguration.VF_MODULES_METADATA.equals(elementInfoFromVfResource.getType()));\r
102                 assertEquals(ASDCElementInfo.ASDCElementTypeEnum.VNF_RESOURCE.name(), elementInfoFromVfResource.getType());\r
103 \r
104                 assertFalse(elementInfoFromVfResource.toString().contains("MyInfo1: someValue"));\r
105                 elementInfoFromVfResource.addElementInfo("MyInfo1", "someValue");\r
106                 assertTrue(elementInfoFromVfResource.toString().contains("MyInfo1: someValue"));\r
107         }\r
108 \r
109         @Test\r
110         public void createASDCElementInfoFromVfModuleTest() throws ArtifactInstallerException {\r
111 \r
112                 String resourceInstanceName = "Resource 1";\r
113 \r
114                 UUID generatedUUID = UUID.randomUUID();\r
115 \r
116                 INotificationData notificationData = Mockito.mock(INotificationData.class);\r
117                 IResourceInstance resourceInstance = Mockito.mock(IResourceInstance.class);\r
118 \r
119                 Mockito.when(resourceInstance.getResourceInstanceName()).thenReturn(resourceInstanceName);\r
120                 Mockito.when(resourceInstance.getResourceInvariantUUID()).thenReturn(generatedUUID.toString());\r
121 \r
122                 VfResourceStructure vfResourceStructure = new VfResourceStructure(notificationData, resourceInstance);\r
123 \r
124                 // Create module structure now\r
125 \r
126                 String vfModuleModelName = "Module Model XYZ";\r
127 \r
128                 UUID generatedUUIDForModule = UUID.randomUUID();\r
129 \r
130                 IVfModuleData moduleMetadata = Mockito.mock(IVfModuleData.class);\r
131                 Mockito.when(moduleMetadata.getVfModuleModelName()).thenReturn(vfModuleModelName);\r
132                 Mockito.when(moduleMetadata.getVfModuleModelInvariantUUID()).thenReturn(generatedUUIDForModule.toString());\r
133                 Mockito.when(moduleMetadata.getArtifacts()).thenReturn(Collections.<String> emptyList());\r
134 \r
135                 VfModuleStructure vfModuleStructure = new VfModuleStructure(vfResourceStructure, moduleMetadata);\r
136 \r
137                 ASDCElementInfo elementInfoFromVfModule = ASDCElementInfo.createElementFromVfModuleStructure(vfModuleStructure);\r
138 \r
139                 assertTrue(elementInfoFromVfModule.toString().contains(vfModuleModelName));\r
140                 assertTrue(elementInfoFromVfModule.toString().contains(generatedUUIDForModule.toString()));\r
141 \r
142                 assertFalse(ASDCElementInfo.ASDCElementTypeEnum.VNF_RESOURCE.name().equals(elementInfoFromVfModule.getType()));\r
143                 assertEquals(ASDCConfiguration.VF_MODULES_METADATA, elementInfoFromVfModule.getType());\r
144 \r
145                 assertFalse(elementInfoFromVfModule.toString().contains("MyInfo2: someValue"));\r
146                 elementInfoFromVfModule.addElementInfo("MyInfo2", "someValue");\r
147                 assertTrue(elementInfoFromVfModule.toString().contains("MyInfo2: someValue"));\r
148         }\r
149 \r
150         @Test\r
151         public void createASDCElementInfoFromArtifact() {\r
152                 for (String eVal : ASDCConfiguration.SUPPORTED_ARTIFACT_TYPES_LIST) {\r
153                         String generatedArtifactName = eVal + " 1";\r
154                         UUID generatedUUIDForArtifact = UUID.randomUUID();\r
155 \r
156                         IArtifactInfo artifactInfo = Mockito.mock(IArtifactInfo.class);\r
157                         Mockito.when(artifactInfo.getArtifactType()).thenReturn(eVal);\r
158                         Mockito.when(artifactInfo.getArtifactName()).thenReturn(generatedArtifactName);\r
159                         Mockito.when(artifactInfo.getArtifactUUID()).thenReturn(generatedUUIDForArtifact.toString());\r
160 \r
161                         ASDCElementInfo elementInfoFromArtifact = ASDCElementInfo.createElementFromVfArtifactInfo(artifactInfo);\r
162 \r
163                         assertTrue(elementInfoFromArtifact.toString().contains(generatedArtifactName));\r
164                         assertTrue(elementInfoFromArtifact.toString().contains(generatedUUIDForArtifact.toString()));\r
165 \r
166                         assertFalse(ASDCElementInfo.ASDCElementTypeEnum.VNF_RESOURCE.name().equals(elementInfoFromArtifact.getType()));\r
167                         assertEquals(eVal, elementInfoFromArtifact.getType());\r
168 \r
169                         assertFalse(elementInfoFromArtifact.toString().contains("MyInfo3: someValue"));\r
170                         elementInfoFromArtifact.addElementInfo("MyInfo3", "someValue");\r
171                         assertTrue(elementInfoFromArtifact.toString().contains("MyInfo3: someValue"));\r
172                 }\r
173         }\r
174 }\r