diff options
Diffstat (limited to 'dcaedt_tools/src/test')
-rw-r--r-- | dcaedt_tools/src/test/java/BaseTest.java | 67 | ||||
-rw-r--r-- | dcaedt_tools/src/test/java/EntitiesRetrieverTest.java | 29 | ||||
-rw-r--r-- | dcaedt_tools/src/test/java/TemplateContainerTest.java | 35 |
3 files changed, 34 insertions, 97 deletions
diff --git a/dcaedt_tools/src/test/java/BaseTest.java b/dcaedt_tools/src/test/java/BaseTest.java index f618f2d..d3a6ed5 100644 --- a/dcaedt_tools/src/test/java/BaseTest.java +++ b/dcaedt_tools/src/test/java/BaseTest.java @@ -1,17 +1,16 @@ -import json.response.ElementsResponse.Element; -import json.response.ItemsResponse.Item; -import json.response.ItemsResponse.Model; import org.junit.Before; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; +import org.onap.sdc.dcae.composition.restmodels.sdc.Resource; import org.onap.sdc.dcae.composition.restmodels.sdc.ResourceDetailed; import utilities.IDcaeRestClient; import utilities.IReport; import java.util.ArrayList; -import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyString; @@ -47,8 +46,7 @@ abstract class BaseTest { public void setup() { when(dcaeRestClient.getUserId()).thenReturn(USER_ID); mockGetAllVfcmt(); - mockGetElements(); - mockGetItems(); + mockGetCatalog(); mockGetItemModel(); mockGetItemType(); mockCheckoutVfcmtAndCreateResource(); @@ -70,46 +68,29 @@ abstract class BaseTest { } private void mockGetItemModel() { - when(dcaeRestClient.getItemModel(anyString())).thenReturn("{\"data\":{\"model\":{\"nodes\":[{\"capability\":{\"type\":\"someType\"}, \"type\":\"type\", \"name\":\"SomeNameFromRequirement\", \"requirements\":[{\"name\":\"SomeNameFromRequirement\"}], \"properties\":[{}], \"capabilities\":[{\"name\":\"SomeNameToCapability\"}],\"type\":\"type\"}]}}}", - "{\"data\":{\"model\":{\"nodes\":[{\"capability\":{\"type\":\"someType\"}, \"type\":\"type\", \"name\":\"SomeNameToCapability\", \"requirements\":[{\"name\":\"SomeNameFromRequirement\"}], \"properties\":[{}], \"capabilities\":[{\"name\":\"SomeNameToCapability\"}],\"type\":\"type\"}]}}}"); + when(dcaeRestClient.getItemModel(anyString())).thenReturn("{\"data\":{\"model\":{\"itemId\":\"\",\"nodes\":[{\"capability\":{\"type\":\"someType\"}, \"type\":\"type\", \"name\":\"SomeNameFromRequirement\", \"requirements\":[{\"name\":\"SomeNameFromRequirement\"}], \"properties\":[{}], \"capabilities\":[{\"name\":\"SomeNameToCapability\"}],\"type\":\"type\"}]}}}", + "{\"data\":{\"model\":{\"itemId\":\"\",\"nodes\":[{\"capability\":{\"type\":\"someType\"}, \"type\":\"type\", \"name\":\"SomeNameToCapability\", \"requirements\":[{\"name\":\"SomeNameFromRequirement\"}], \"properties\":[{}], \"capabilities\":[{\"name\":\"SomeNameToCapability\"}],\"type\":\"type\"}]}}}"); } - private void mockGetItems() { - when(dcaeRestClient.getItem(ELEMENT_NAME1)).thenReturn(null); - List<Item> items = new ArrayList<>(); - Item item = new Item(); - item.setName(ITEM_NAME1); - Model model = new Model(); - model.setItemId(""); - List<Model> models = Collections.singletonList(model); - item.setModels(models); - items.add(item); - item = new Item(); - item.setName(ITEM_NAME2); - item.setModels(models); - items.add(item); - when(dcaeRestClient.getItem(ELEMENT_NAME2)).thenReturn(items); - items = new ArrayList<>(); - item = new Item(); - item.setName(ITEM_NAME3); - item.setModels(models); - items.add(item); - when(dcaeRestClient.getItem(ELEMENT_NAME3)).thenReturn(items); - } + private void mockGetCatalog() { + Map<String, List<Resource>> catalog = new HashMap<>(); + catalog.put(ELEMENT_NAME1, null); + List<Resource> items = new ArrayList<>(); + Resource item = new Resource(); + item.setName(ITEM_NAME1); + items.add(item); + item = new Resource(); + item.setName(ITEM_NAME2); + items.add(item); + catalog.put(ELEMENT_NAME2, items); + items = new ArrayList<>(); + item = new Resource(); + item.setName(ITEM_NAME3); + items.add(item); + catalog.put(ELEMENT_NAME3, items); + when(dcaeRestClient.getDcaeCatalog()).thenReturn(catalog); + } - private void mockGetElements() { - List<Element> elements = new ArrayList<>(); - Element element = new Element(); - element.setName(ELEMENT_NAME1); - elements.add(element); - element = new Element(); - element.setName(ELEMENT_NAME2); - elements.add(element); - element = new Element(); - element.setName(ELEMENT_NAME3); - elements.add(element); - when(dcaeRestClient.getElements()).thenReturn(elements); - } private void mockGetAllVfcmt() { List<ResourceDetailed> resourceDetaileds = new ArrayList<>(); diff --git a/dcaedt_tools/src/test/java/EntitiesRetrieverTest.java b/dcaedt_tools/src/test/java/EntitiesRetrieverTest.java deleted file mode 100644 index ea7eb2b..0000000 --- a/dcaedt_tools/src/test/java/EntitiesRetrieverTest.java +++ /dev/null @@ -1,29 +0,0 @@ - -import json.response.ItemsResponse.Item; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.mockito.InjectMocks; -import tools.EntitiesRetriever; - -import java.util.List; -import java.util.Map; - - -public class EntitiesRetrieverTest extends BaseTest { - - @InjectMocks - EntitiesRetriever entitiesRetriever; - - @Before - @Override - public void setup() { - super.setup(); - } - - @Test - public void getElementsByFolder_returns2Items() { - Map<String, List<Item>> result = entitiesRetriever.getElementsByFolder(); - Assert.assertTrue(result.size() == 2); - } -} diff --git a/dcaedt_tools/src/test/java/TemplateContainerTest.java b/dcaedt_tools/src/test/java/TemplateContainerTest.java index b4ddc17..6b09991 100644 --- a/dcaedt_tools/src/test/java/TemplateContainerTest.java +++ b/dcaedt_tools/src/test/java/TemplateContainerTest.java @@ -1,6 +1,4 @@ import com.google.gson.JsonObject; -import json.response.ItemsResponse.Item; -import json.response.ItemsResponse.Model; import json.templateInfo.Composition; import json.templateInfo.NodeToDelete; import json.templateInfo.Relation; @@ -8,6 +6,7 @@ import json.templateInfo.TemplateInfo; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import org.onap.sdc.dcae.composition.restmodels.sdc.Resource; import tools.TemplateContainer; import java.util.*; @@ -21,7 +20,7 @@ public class TemplateContainerTest extends BaseTest { private TemplateContainer templateContainer; private List<TemplateInfo> templateInfos; - private Map<String, List<Item>> elementsByFolderNames; + private Map<String, List<Resource>> elementsByFolderNames; @Before @Override public void setup() { @@ -36,14 +35,9 @@ public class TemplateContainerTest extends BaseTest { templateInfo.setComposition(Collections.singletonList(composition)); templateInfos.add(templateInfo); elementsByFolderNames = new HashMap<>(); - Item item = new Item(); + Resource item = new Resource(); item.setName(ELEMENT_NAME3); - item.setItemId(""); - Model model = new Model(); - model.setItemId(""); - List<Model> models = Collections.singletonList(model); - item.setModels(models); - List<Item> items = new ArrayList<>(Collections.singletonList(item)); + List<Resource> items = new ArrayList<>(Collections.singletonList(item)); elementsByFolderNames.put(TEMPLATE_INFO_NAME, items); } @@ -60,9 +54,9 @@ public class TemplateContainerTest extends BaseTest { @Test public void getCdumps_returnNotFoundEmptyList() { elementsByFolderNames = new HashMap<>(); - Item item = new Item(); + Resource item = new Resource(); item.setName(ELEMENT_NAME2); - List<Item> items = new ArrayList<>(Collections.singletonList(item)); + List<Resource> items = new ArrayList<>(Collections.singletonList(item)); elementsByFolderNames.put(TEMPLATE_INFO_NAME, items); templateContainer = new TemplateContainer(report, dcaeRestClient, templateInfos, elementsByFolderNames); @@ -126,22 +120,13 @@ public class TemplateContainerTest extends BaseTest { templateInfo.setRelations(Collections.singletonList(relation)); templateInfos.add(templateInfo); elementsByFolderNames = new HashMap<>(); - List<Item> itemList = new ArrayList<>(); - Item item = new Item(); + List<Resource> itemList = new ArrayList<>(); + Resource item = new Resource(); item.setName(ELEMENT_NAME3); - item.setItemId(""); - Model model = new Model(); - model.setItemId(""); - List<Model> models = Collections.singletonList(model); - item.setModels(models); itemList.add(item); - item = new Item(); + item = new Resource(); item.setName(ELEMENT_NAME2); - item.setItemId(""); - model = new Model(); - model.setItemId(""); - models = Collections.singletonList(model); - item.setModels(models); + itemList.add(item); elementsByFolderNames.put(TEMPLATE_INFO_NAME, itemList); templateContainer = new TemplateContainer(report, dcaeRestClient, templateInfos, elementsByFolderNames); |