summaryrefslogtreecommitdiffstats
path: root/dcaedt_be/src/test
diff options
context:
space:
mode:
authorManor, Yanir (ym903w) <ym903w@intl.att.com>2018-10-21 10:20:53 +0300
committerManor, Yanir (ym903w) <ym903w@intl.att.com>2018-10-21 13:35:08 +0300
commitf53d4650e18007ab7820efd84638edac90b61090 (patch)
treeb27d22bd8ad1343f9ed69091f9d6496a174f6c89 /dcaedt_be/src/test
parentb1b380c5e83b044605bddfc390b80bedafd359f5 (diff)
upgrade dace-be
Change-Id: Iaef6ef0d37e2e216321f141d10692edcaf26ffab Issue-ID: DCAEGEN2-836 Signed-off-by: Manor, Yanir (ym903w) <ym903w@intl.att.com>
Diffstat (limited to 'dcaedt_be/src/test')
-rw-r--r--dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/BlueprintBusinessLogicTest.java3
-rw-r--r--dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/CompositionBusinessLogicTest.java59
-rw-r--r--dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/CompositionCatalogBusinessLogicTest.java9
-rw-r--r--dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/ReferenceBusinessLogicTest.java47
-rw-r--r--dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/ServiceBusinessLogicTest.java4
-rw-r--r--dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/VfcmtBusinessLogicTest.java1
6 files changed, 96 insertions, 27 deletions
diff --git a/dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/BlueprintBusinessLogicTest.java b/dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/BlueprintBusinessLogicTest.java
index 9150c59..d04a92e 100644
--- a/dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/BlueprintBusinessLogicTest.java
+++ b/dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/BlueprintBusinessLogicTest.java
@@ -5,13 +5,12 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
import org.onap.sdc.dcae.client.ISdcClient;
import org.onap.sdc.dcae.composition.restmodels.sdc.Artifact;
import org.onap.sdc.dcae.composition.restmodels.sdc.ResourceDetailed;
import org.onap.sdc.dcae.errormng.ErrorConfigurationLoader;
import org.springframework.http.ResponseEntity;
-
+import org.mockito.MockitoAnnotations;
import java.util.ArrayList;
import static org.mockito.ArgumentMatchers.eq;
diff --git a/dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/CompositionBusinessLogicTest.java b/dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/CompositionBusinessLogicTest.java
index 5e6d2a3..fbecd71 100644
--- a/dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/CompositionBusinessLogicTest.java
+++ b/dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/CompositionBusinessLogicTest.java
@@ -192,12 +192,48 @@ public class CompositionBusinessLogicTest {
verify(sdcClientMock).changeResourceLifecycleState(anyString(),anyString(),anyString(),anyString(),anyString());
}
- private void emulateListOfArtifactsWithCompositionYml() {
+ @Test
+ public void overwriteRevertedMcSuccess() throws Exception {
+ String latestUuid = "uuid2";
+ emulateListOfRuleArtifacts();
+ when(vfcmt.getLifecycleState()).thenReturn("CERTIFIED");
+ ResourceDetailed latestMc = buildLatestMcVersion();
+ latestMc.setUuid(latestUuid);
+ when(sdcClientMock.getResource(anyString(),anyString())).thenReturn(vfcmt).thenReturn(latestMc);
+ when(sdcClientMock.changeResourceLifecycleState(anyString(), anyString(), anyString(), anyString(), anyString())).thenReturn(latestMc);
+ when(sdcClientMock.getResourceArtifact(anyString(), anyString(), anyString())).thenReturn(justAString);
+ compositionBusinessLogic.overwriteRevertedMC(justAString, justAString, latestUuid, justAString, justAString);
+ verify(sdcClientMock, times(3)).getResource(anyString(),anyString());
+ verify(sdcClientMock, times(0)).createResourceArtifact(anyString(),anyString(),any(),anyString());
+ verify(sdcClientMock).getResourceArtifact(anyString(), anyString(), anyString());
+ verify(sdcClientMock, times(2)).updateResourceArtifact(anyString(), anyString(), any(), anyString());
+ verify(sdcClientMock).deleteResourceArtifact(anyString(), anyString(), any(), anyString());
+ verify(sdcClientMock).changeResourceLifecycleState(anyString(),anyString(),anyString(),anyString(),anyString());
+ }
+
+ private List<Artifact> emulateListOfArtifactsWithCompositionYml() {
List<Artifact> listOfArtifactCompositionYml = new ArrayList<>();
Artifact compositionArtifact = Mockito.mock(Artifact.class);
when(compositionArtifact.getArtifactName()).thenReturn(DcaeBeConstants.Composition.fileNames.COMPOSITION_YML);
listOfArtifactCompositionYml.add(compositionArtifact);
when(vfcmt.getArtifacts()).thenReturn(listOfArtifactCompositionYml);
+ return listOfArtifactCompositionYml;
+ }
+
+ private void emulateListOfRuleArtifacts() {
+ List<Artifact> artifacts = emulateListOfArtifactsWithCompositionYml();
+ Artifact rulesArtifact = Mockito.mock(Artifact.class);
+ when(rulesArtifact.getArtifactName()).thenReturn("rulesArtifact.json");
+ when(rulesArtifact.getArtifactChecksum()).thenReturn("rules_checksum");
+ Artifact rulesArtifact2 = Mockito.mock(Artifact.class);
+ when(rulesArtifact2.getArtifactName()).thenReturn("rulesArtifact2.json");
+ when(rulesArtifact2.getArtifactChecksum()).thenReturn("rules2_checksum");
+ when(rulesArtifact2.getArtifactDescription()).thenReturn(justAString);
+ when(rulesArtifact2.getArtifactType()).thenReturn(justAString);
+ when(rulesArtifact2.getArtifactLabel()).thenReturn(justAString);
+ when(rulesArtifact2.getArtifactUUID()).thenReturn(justAString);
+ artifacts.add(rulesArtifact);
+ artifacts.add(rulesArtifact2);
}
private void mockVfiList(String vfiName) {
@@ -218,4 +254,25 @@ public class CompositionBusinessLogicTest {
when(service.getResources().get(0).getArtifacts()).thenReturn(instanceArtifacts);
}
+ private ResourceDetailed buildLatestMcVersion() {
+ ResourceDetailed latestMc = new ResourceDetailed();
+ latestMc.setLifecycleState("NOT_CERTIFIED_CHECKOUT");
+ latestMc.setResourceType("VFCMT");
+ latestMc.setCategory("Template");
+ latestMc.setLastUpdaterUserId(justAString);
+ Artifact cdump = new Artifact();
+ cdump.setArtifactName(DcaeBeConstants.Composition.fileNames.COMPOSITION_YML);
+ Artifact rules = new Artifact();
+ rules.setArtifactName("rulesArtifact.json");
+ rules.setArtifactChecksum("rules_checksum");
+ Artifact rules2 = new Artifact();
+ rules2.setArtifactName("rulesArtifact2.json");
+ rules2.setArtifactChecksum("rules_checksum_xxx");
+ Artifact rules3 = new Artifact();
+ rules3.setArtifactName("rules.json");
+ rules3.setArtifactUUID(justAString);
+ latestMc.setArtifacts(Arrays.asList(cdump, rules, rules2, rules3));
+ return latestMc;
+ }
+
} \ No newline at end of file
diff --git a/dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/CompositionCatalogBusinessLogicTest.java b/dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/CompositionCatalogBusinessLogicTest.java
index 7c773ee..a1b7478 100644
--- a/dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/CompositionCatalogBusinessLogicTest.java
+++ b/dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/CompositionCatalogBusinessLogicTest.java
@@ -18,7 +18,6 @@ import org.springframework.http.ResponseEntity;
import java.util.Arrays;
import java.util.List;
-import java.util.UUID;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*;
@@ -59,14 +58,6 @@ public class CompositionCatalogBusinessLogicTest {
assertEquals("Invalid UUID string: invalidId", ((ResponseFormat)result.getBody()).getNotes());
}
- @Test
- public void getTypeInfoModelNotLoadedFailureTest() {
- String uuid = UUID.randomUUID().toString();
- // this is pretty awful. you cannot call 'getTypeInfo' unless it is preceded by a 'getModel' call of the containing model, so that the 'catalogs' item is populated by the container model id.
- ResponseEntity result = compositionCatalogBusinessLogic.getTypeInfo(uuid, "tosca.nodes.Root");
- assertEquals("No catalog available for resource " + uuid + ". You might want to fetch the model first.", ((ResponseFormat)result.getBody()).getNotes());
- }
-
private void mockCatalog() {
String subcategory1 = "subcategory1";
String subcategory2 = "subcategory2";
diff --git a/dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/ReferenceBusinessLogicTest.java b/dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/ReferenceBusinessLogicTest.java
index f69f660..f3299aa 100644
--- a/dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/ReferenceBusinessLogicTest.java
+++ b/dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/ReferenceBusinessLogicTest.java
@@ -17,12 +17,10 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.client.HttpClientErrorException;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
-import java.util.List;
import java.util.Map;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.*;
public class ReferenceBusinessLogicTest {
@@ -34,8 +32,6 @@ public class ReferenceBusinessLogicTest {
@Mock
private ISdcClient sdcClientMock;
- @Mock
- private ResourceDetailed templateMC;
@InjectMocks
private ReferenceBusinessLogic classUnderTest;
@@ -49,25 +45,42 @@ public class ReferenceBusinessLogicTest {
@Test
public void successfulFetchMonitoringComponents() throws Exception {
- when(sdcClientMock.getResource(anyString(),anyString())).thenReturn(templateMC);
+ ResourceDetailed mock_b = mockMcDetails("a", "b", "NOT_CERTIFIED_CHECKOUT");
+ ResourceDetailed mock_u = mockMcDetails("u", "u", "CERTIFIED");
+ ResourceDetailed mock_w = mockMcDetails("w", "w", "NOT_CERTIFIED_CHECKIN");
+ MonitoringComponent expected_b = new MonitoringComponent(mock_b, "vfi1");
+ expected_b.setSubmittedUuid("a");
+ expected_b.setStatus("Submitted");
+ MonitoringComponent expected_u = new MonitoringComponent(mock_u, "vfi2");
+ expected_u.setUuid("u/v");
+ MonitoringComponent expected_w = new MonitoringComponent(mock_w, "vfi2");
+ when(sdcClientMock.getResource(eq("a"),anyString())).thenReturn(mockMcDetails("a", "a", "CERTIFIED"));
+ when(sdcClientMock.getResource(eq("b"),anyString())).thenReturn(mock_b);
+ when(sdcClientMock.getResource(eq("u"),anyString())).thenReturn(mock_u);
+ when(sdcClientMock.getResource(eq("v"),anyString())).thenReturn(mockMcDetails("u", "v", "NOT_CERTIFIED_CHECKIN"));
+ when(sdcClientMock.getResource(eq("w"),anyString())).thenReturn(mock_w);
ExternalReferencesMap refs = new ExternalReferencesMap();
- refs.put("vfi1", Arrays.asList("a","b","c","d"));
- refs.put("vfi2", Arrays.asList("u","v","w","x","y","z"));
- Map<String, List<MonitoringComponent>> result = classUnderTest.fetchMonitoringComponents(refs, requestId);
- verify(sdcClientMock,times(10)).getResource(anyString(),anyString());
+ refs.put("vfi1", Arrays.asList("a","b"));
+ refs.put("vfi2", Arrays.asList("u","v_reverted","w"));
+ Map<String, Collection<MonitoringComponent>> result = classUnderTest.fetchMonitoringComponents(refs, requestId);
+ verify(sdcClientMock,times(5)).getResource(anyString(),anyString());
Assert.assertEquals(1, result.size());
- Assert.assertEquals(10, result.get("monitoringComponents").size());
+ Assert.assertEquals(3, result.get("monitoringComponents").size());
+ Assert.assertTrue(result.get("monitoringComponents").contains(expected_b));
+ Assert.assertTrue(result.get("monitoringComponents").contains(expected_u));
+ Assert.assertTrue(result.get("monitoringComponents").contains(expected_w));
}
@Test
public void partialSuccessfulFetchMonitoringComponents() throws Exception {
- when(sdcClientMock.getResource(anyString(),anyString())).thenReturn(templateMC);
+ when(sdcClientMock.getResource(eq("abc"),anyString())).thenReturn(mockMcDetails("abc", "abc", "CERTIFIED"));
+ when(sdcClientMock.getResource(eq("xyz"),anyString())).thenReturn(mockMcDetails("xyz", "xyz", "CERTIFIED"));
when(sdcClientMock.getResource(eq("no_such_uuid"),anyString())).thenThrow(new HttpClientErrorException(HttpStatus.NOT_FOUND));
ExternalReferencesMap refs = new ExternalReferencesMap();
refs.put("vfi1", Collections.singletonList("abc"));
refs.put("vfi2", Collections.singletonList("xyz"));
refs.put("vfi3", Collections.singletonList("no_such_uuid"));
- Map<String, List<MonitoringComponent>> result = classUnderTest.fetchMonitoringComponents(refs, requestId);
+ Map<String, Collection<MonitoringComponent>> result = classUnderTest.fetchMonitoringComponents(refs, requestId);
verify(sdcClientMock,times(3)).getResource(anyString(),anyString());
Assert.assertEquals(2, result.size());
Assert.assertEquals(2, result.get("monitoringComponents").size());
@@ -123,4 +136,12 @@ public class ReferenceBusinessLogicTest {
Assert.assertEquals("The request was partially successful. Removing the attached Blueprint from the service has failed. You must manually delete the artifact.", responseEntity.getBody().getRequestError().getServiceException().getFormattedErrorMessage());
}
+
+ private ResourceDetailed mockMcDetails(String invariantUuid, String uuid, String lifecycleState) {
+ ResourceDetailed res = new ResourceDetailed();
+ res.setUuid(uuid);
+ res.setInvariantUUID(invariantUuid);
+ res.setLifecycleState(lifecycleState);
+ return res;
+ }
}
diff --git a/dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/ServiceBusinessLogicTest.java b/dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/ServiceBusinessLogicTest.java
index 15c460a..671927c 100644
--- a/dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/ServiceBusinessLogicTest.java
+++ b/dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/ServiceBusinessLogicTest.java
@@ -28,9 +28,9 @@ import java.util.stream.Collectors;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Matchers.anyString;
+import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;
+import static org.mockito.ArgumentMatchers.any;
import static org.testng.Assert.assertNotEquals;
public class ServiceBusinessLogicTest {
diff --git a/dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/VfcmtBusinessLogicTest.java b/dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/VfcmtBusinessLogicTest.java
index c347c34..bf1cbbe 100644
--- a/dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/VfcmtBusinessLogicTest.java
+++ b/dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/VfcmtBusinessLogicTest.java
@@ -21,6 +21,7 @@ import org.onap.sdc.dcae.errormng.RequestError;
import org.onap.sdc.dcae.errormng.ResponseFormat;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
+import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import java.util.ArrayList;
import java.util.Arrays;