aboutsummaryrefslogtreecommitdiffstats
path: root/adapters/mso-openstack-adapters/src/test
diff options
context:
space:
mode:
authorSmokowski, Steven <steve.smokowski@att.com>2020-02-12 11:13:08 -0500
committerBenjamin, Max (mb388a) <mb388a@att.com>2020-02-12 11:13:09 -0500
commit5ba5518f6b9dffbf0fed7f3655b1635cd818bc1e (patch)
tree417a3b906a03726a760ffbfc3c543f20022ff707 /adapters/mso-openstack-adapters/src/test
parent1980195d94d2208c8f5c8951885cfe345fbc8dd1 (diff)
mso to add support for creating the cloud region
Initial check in to support cloud region create Add additional junit tests Add additional integration tests Updated junit to use spy and removed setter method Issue-ID: SO-2657 Signed-off-by: Benjamin, Max (mb388a) <mb388a@att.com> Change-Id: I6a93f3b4caf7d640ffa5842981247d284b9013ad
Diffstat (limited to 'adapters/mso-openstack-adapters/src/test')
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/cloudregion/CloudRegionRestImplTest.java96
1 files changed, 96 insertions, 0 deletions
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/cloudregion/CloudRegionRestImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/cloudregion/CloudRegionRestImplTest.java
new file mode 100644
index 0000000000..9c62c286ac
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/cloudregion/CloudRegionRestImplTest.java
@@ -0,0 +1,96 @@
+package org.onap.so.adapters.cloudregion;
+
+import static com.shazam.shazamcrest.MatcherAssert.assertThat;
+import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import java.util.Optional;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.aai.domain.yang.CloudRegion;
+import org.onap.so.client.aai.AAIObjectType;
+import org.onap.so.client.aai.AAIResourcesClient;
+import org.onap.so.client.aai.entities.uri.AAIResourceUri;
+import org.onap.so.client.aai.entities.uri.AAIUriFactory;
+import org.onap.so.db.catalog.beans.CloudSite;
+import org.onap.so.db.catalog.client.CatalogDbClient;
+
+
+@RunWith(MockitoJUnitRunner.class)
+public class CloudRegionRestImplTest {
+
+ @Spy
+ @InjectMocks
+ private CloudRestImpl cloudRestImpl;
+
+ @Mock
+ private CatalogDbClient catalogDbClientMock;
+
+ @Mock
+ private AAIResourcesClient aaiResClientMock;
+
+ private CloudSite cloudSite = new CloudSite();
+
+ private CloudRegion testCloudRegion = new CloudRegion();
+
+ @Before
+ public void setup() {
+ cloudSite.setCloudVersion("1.0");
+ cloudSite.setRegionId("region1");
+ Mockito.doReturn(aaiResClientMock).when(cloudRestImpl).getAaiClient();
+ testCloudRegion.setCloudOwner("bob");
+ testCloudRegion.setCloudRegionId("region1");
+ testCloudRegion.setCloudRegionVersion("1.0");
+ testCloudRegion.setInMaint(false);
+ testCloudRegion.setOrchestrationDisabled(false);
+ testCloudRegion.setComplexName("NA");
+ testCloudRegion.setCloudRegionVersion("1.0");
+ testCloudRegion.setOwnerDefinedType("cLCP");
+ testCloudRegion.setCloudType("openstack");
+ }
+
+ @Test
+ public void mapCloudRegionTest() {
+ CloudRegion mappedRegion = cloudRestImpl.mapCloudRegion(cloudSite, "bob");
+ assertThat(mappedRegion, sameBeanAs(testCloudRegion));
+ }
+
+ @Test
+ public void createCloudRegionTest() {
+ when(catalogDbClientMock.getCloudSite("region1")).thenReturn(null);
+ when(catalogDbClientMock.postCloudSite(cloudSite)).thenReturn(cloudSite);
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION, "bob", "region1");
+ cloudRestImpl.createCloudRegion(cloudSite, "bob");
+ ArgumentCaptor<AAIResourceUri> actualURI = ArgumentCaptor.forClass(AAIResourceUri.class);
+ ArgumentCaptor<Optional<Object>> actualCloudRegion = ArgumentCaptor.forClass(Optional.class);
+ verify(catalogDbClientMock, times(1)).getCloudSite("region1");
+ verify(catalogDbClientMock, times(1)).postCloudSite(cloudSite);
+ verify(aaiResClientMock, times(1)).createIfNotExists(Mockito.eq(uri), Mockito.any());
+ verify(aaiResClientMock, times(1)).createIfNotExists(actualURI.capture(), actualCloudRegion.capture());
+ assertThat((CloudRegion) actualCloudRegion.getValue().get(), sameBeanAs(testCloudRegion));
+ }
+
+ @Test
+ public void updateCloudRegionTest() {
+ when(catalogDbClientMock.updateCloudSite(cloudSite)).thenReturn(cloudSite);
+ cloudRestImpl.updateCloudRegion(cloudSite, "bob");
+ verify(catalogDbClientMock, times(1)).updateCloudSite(cloudSite);
+ }
+
+ @Test
+ public void deleteCloudRegionTest() {
+ doNothing().when(catalogDbClientMock).deleteCloudSite("region1");
+ cloudRestImpl.deleteCloudRegion(cloudSite.getRegionId());
+ verify(catalogDbClientMock, times(1)).deleteCloudSite("region1");
+ }
+
+}