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=========================================================
22 package org.openecomp.mso.asdc.client.tests;
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;
31 import java.util.Collections;
32 import java.util.UUID;
34 import org.junit.Test;
35 import org.mockito.Mockito;
37 import org.openecomp.sdc.api.notification.IArtifactInfo;
38 import org.openecomp.sdc.api.notification.INotificationData;
39 import org.openecomp.sdc.api.notification.IResourceInstance;
40 import org.openecomp.sdc.api.notification.IVfModuleMetadata;
41 import org.openecomp.mso.asdc.client.ASDCConfiguration;
42 import org.openecomp.mso.asdc.client.exceptions.ArtifactInstallerException;
43 import org.openecomp.mso.asdc.installer.ASDCElementInfo;
44 import org.openecomp.mso.asdc.installer.VfModuleStructure;
45 import org.openecomp.mso.asdc.installer.VfResourceStructure;
48 public class ASDCElementInfoTest {
51 public void createASDCElementInfoWithNullParameterTest() {
52 ASDCElementInfo elementInfoFromNullVfArtifact = ASDCElementInfo.createElementFromVfArtifactInfo(null);
53 ASDCElementInfo elementInfoFromNullVfModuleStructure = ASDCElementInfo.createElementFromVfModuleStructure(null);
54 ASDCElementInfo elementInfoFromNullVfResourceStructure = ASDCElementInfo.createElementFromVfResourceStructure(null);
56 elementInfoFromNullVfArtifact.addElementInfo(null, null);
57 elementInfoFromNullVfModuleStructure.addElementInfo(null, "someValue");
58 elementInfoFromNullVfResourceStructure.addElementInfo("someKey", null);
60 assertEquals(elementInfoFromNullVfArtifact.toString(), "");
61 assertEquals(elementInfoFromNullVfModuleStructure.toString(), "");
62 assertEquals(elementInfoFromNullVfResourceStructure.toString(), "");
64 assertNotNull(elementInfoFromNullVfArtifact);
65 assertNotNull(elementInfoFromNullVfModuleStructure);
66 assertNotNull(elementInfoFromNullVfResourceStructure);
68 assertNotNull(ASDCElementInfo.EMPTY_INSTANCE);
70 assertEquals(elementInfoFromNullVfArtifact, ASDCElementInfo.EMPTY_INSTANCE);
71 assertEquals(elementInfoFromNullVfModuleStructure, ASDCElementInfo.EMPTY_INSTANCE);
72 assertEquals(elementInfoFromNullVfResourceStructure, ASDCElementInfo.EMPTY_INSTANCE);
74 assertEquals(ASDCElementInfo.EMPTY_INSTANCE.getType(), "");
75 assertEquals(ASDCElementInfo.EMPTY_INSTANCE.toString(), "");
77 assertEquals(elementInfoFromNullVfArtifact.getType(), ASDCElementInfo.EMPTY_INSTANCE.getType());
78 assertEquals(elementInfoFromNullVfModuleStructure.getType(), ASDCElementInfo.EMPTY_INSTANCE.getType());
79 assertEquals(elementInfoFromNullVfResourceStructure.getType(), ASDCElementInfo.EMPTY_INSTANCE.getType());
83 public void createASDCElementInfoFromVfResourceTest() {
85 String resourceInstanceName = "Resource 1";
87 UUID generatedUUID = UUID.randomUUID();
89 INotificationData notificationData = Mockito.mock(INotificationData.class);
90 IResourceInstance resourceInstance = Mockito.mock(IResourceInstance.class);
92 Mockito.when(resourceInstance.getResourceInstanceName()).thenReturn(resourceInstanceName);
93 Mockito.when(resourceInstance.getResourceInvariantUUID()).thenReturn(generatedUUID.toString());
95 VfResourceStructure vfResourceStructure = new VfResourceStructure(notificationData, resourceInstance);
97 ASDCElementInfo elementInfoFromVfResource = ASDCElementInfo.createElementFromVfResourceStructure(vfResourceStructure);
99 assertTrue(elementInfoFromVfResource.toString().contains(resourceInstanceName));
100 assertTrue(elementInfoFromVfResource.toString().contains(generatedUUID.toString()));
102 assertFalse(ASDCConfiguration.VF_MODULES_METADATA.equals(elementInfoFromVfResource.getType()));
103 assertEquals(ASDCElementInfo.ASDCElementTypeEnum.VNF_RESOURCE.name(), elementInfoFromVfResource.getType());
105 assertFalse(elementInfoFromVfResource.toString().contains("MyInfo1: someValue"));
106 elementInfoFromVfResource.addElementInfo("MyInfo1", "someValue");
107 assertTrue(elementInfoFromVfResource.toString().contains("MyInfo1: someValue"));
111 public void createASDCElementInfoFromVfModuleTest() throws ArtifactInstallerException {
113 String resourceInstanceName = "Resource 1";
115 UUID generatedUUID = UUID.randomUUID();
117 INotificationData notificationData = Mockito.mock(INotificationData.class);
118 IResourceInstance resourceInstance = Mockito.mock(IResourceInstance.class);
120 Mockito.when(resourceInstance.getResourceInstanceName()).thenReturn(resourceInstanceName);
121 Mockito.when(resourceInstance.getResourceInvariantUUID()).thenReturn(generatedUUID.toString());
123 VfResourceStructure vfResourceStructure = new VfResourceStructure(notificationData, resourceInstance);
125 // Create module structure now
127 String vfModuleModelName = "Module Model XYZ";
129 UUID generatedUUIDForModule = UUID.randomUUID();
131 IVfModuleMetadata moduleMetadata = Mockito.mock(IVfModuleMetadata.class);
132 Mockito.when(moduleMetadata.getVfModuleModelName()).thenReturn(vfModuleModelName);
133 Mockito.when(moduleMetadata.getVfModuleModelInvariantUUID()).thenReturn(generatedUUIDForModule.toString());
134 Mockito.when(moduleMetadata.getArtifacts()).thenReturn(Collections.<String> emptyList());
136 VfModuleStructure vfModuleStructure = new VfModuleStructure(vfResourceStructure, moduleMetadata);
138 ASDCElementInfo elementInfoFromVfModule = ASDCElementInfo.createElementFromVfModuleStructure(vfModuleStructure);
140 assertTrue(elementInfoFromVfModule.toString().contains(vfModuleModelName));
141 assertTrue(elementInfoFromVfModule.toString().contains(generatedUUIDForModule.toString()));
143 assertFalse(ASDCElementInfo.ASDCElementTypeEnum.VNF_RESOURCE.name().equals(elementInfoFromVfModule.getType()));
144 assertEquals(ASDCConfiguration.VF_MODULES_METADATA, elementInfoFromVfModule.getType());
146 assertFalse(elementInfoFromVfModule.toString().contains("MyInfo2: someValue"));
147 elementInfoFromVfModule.addElementInfo("MyInfo2", "someValue");
148 assertTrue(elementInfoFromVfModule.toString().contains("MyInfo2: someValue"));
152 public void createASDCElementInfoFromArtifact() {
153 for (String eVal : ASDCConfiguration.SUPPORTED_ARTIFACT_TYPES_LIST) {
154 String generatedArtifactName = eVal + " 1";
155 UUID generatedUUIDForArtifact = UUID.randomUUID();
157 IArtifactInfo artifactInfo = Mockito.mock(IArtifactInfo.class);
158 Mockito.when(artifactInfo.getArtifactType()).thenReturn(eVal);
159 Mockito.when(artifactInfo.getArtifactName()).thenReturn(generatedArtifactName);
160 Mockito.when(artifactInfo.getArtifactUUID()).thenReturn(generatedUUIDForArtifact.toString());
162 ASDCElementInfo elementInfoFromArtifact = ASDCElementInfo.createElementFromVfArtifactInfo(artifactInfo);
164 assertTrue(elementInfoFromArtifact.toString().contains(generatedArtifactName));
165 assertTrue(elementInfoFromArtifact.toString().contains(generatedUUIDForArtifact.toString()));
167 assertFalse(ASDCElementInfo.ASDCElementTypeEnum.VNF_RESOURCE.name().equals(elementInfoFromArtifact.getType()));
168 assertEquals(eVal, elementInfoFromArtifact.getType());
170 assertFalse(elementInfoFromArtifact.toString().contains("MyInfo3: someValue"));
171 elementInfoFromArtifact.addElementInfo("MyInfo3", "someValue");
172 assertTrue(elementInfoFromArtifact.toString().contains("MyInfo3: someValue"));