aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-model/src/test/java/org/openecomp/sdc/be/model/cache/ComponentCacheTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-model/src/test/java/org/openecomp/sdc/be/model/cache/ComponentCacheTest.java')
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/cache/ComponentCacheTest.java973
1 files changed, 411 insertions, 562 deletions
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/cache/ComponentCacheTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/cache/ComponentCacheTest.java
index f9a696bf8d..49e847acf6 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/cache/ComponentCacheTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/cache/ComponentCacheTest.java
@@ -1,15 +1,7 @@
package org.openecomp.sdc.be.model.cache;
-import java.nio.ByteBuffer;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.function.Function;
-
+import fj.data.Either;
+import mockit.Deencapsulation;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.ImmutableTriple;
import org.junit.Assert;
@@ -31,654 +23,511 @@ import org.openecomp.sdc.be.model.Product;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.resources.data.ComponentCacheData;
import org.openecomp.sdc.be.unittests.utils.ModelConfDependentTest;
-import org.openecomp.sdc.common.util.SerializationUtils;
-import org.openecomp.sdc.common.util.ZipUtil;
-import fj.data.Either;
-import mockit.Deencapsulation;
+import java.util.*;
+import java.util.function.Function;
public class ComponentCacheTest extends ModelConfDependentTest {
- @InjectMocks
- ComponentCache testSubject;
-
- @Mock
- ComponentCassandraDao componentCassandraDao;
+ @InjectMocks
+ ComponentCache testSubject;
+
+ @Mock
+ ComponentCassandraDao componentCassandraDao;
+
+ @Mock
+ ToscaOperationFacade toscaOperationFacade;
+
+ @Before
+ public void setUpMocks() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void testInit() throws Exception {
+ // default test
+ testSubject.init();
+ }
+
+ @Test
+ public void testIsEnabled() throws Exception {
+
+ boolean result;
+
+ // default test
+
+ result = testSubject.isEnabled();
+ }
+
+ @Test
+ public void testSetEnabled() throws Exception {
+
+ boolean enabled = false;
+
+ // default test
+
+ testSubject.setEnabled(enabled);
+ }
+
+ @Test
+ public void testGetComponentNotFound() throws Exception {
+
+ String componentUid = "mock";
+ Long lastModificationTime = null;
+ Function<Component, Component> filterFieldsFunc = null;
+ Either<Component, ActionStatus> result;
+
+ Mockito.when(componentCassandraDao.getComponent("mock"))
+ .thenReturn(Either.right(ActionStatus.ARTIFACT_NOT_FOUND));
+ // default test
+ result = testSubject.getComponent(componentUid, lastModificationTime, filterFieldsFunc);
+ }
+
+ @Test
+ public void testGetComponentInvalidDate() throws Exception {
+
+ String componentUid = "mock";
+ Long lastModificationTime = 0L;
+ Function<Component, Component> filterFieldsFunc = null;
+ Either<Component, ActionStatus> result;
+
+ ComponentCacheData a = new ComponentCacheData();
+ a.setModificationTime(new Date());
+ Mockito.when(componentCassandraDao.getComponent("mock")).thenReturn(Either.left(a));
+ // default test
+ result = testSubject.getComponent(componentUid, lastModificationTime, filterFieldsFunc);
+ }
+
+ @Test
+ public void testGetComponentDeserializeError() throws Exception {
+
+ String componentUid = "mock";
+ Long lastModificationTime = 0L;
+ Function<Component, Component> filterFieldsFunc = null;
+ Either<Component, ActionStatus> result;
+
+ ComponentCacheData a = new ComponentCacheData();
+ a.setModificationTime(new Date(0L));
+ a.setType(NodeTypeEnum.Resource.getName());
+ Mockito.when(componentCassandraDao.getComponent("mock")).thenReturn(Either.left(a));
+ // default test
+ result = testSubject.getComponent(componentUid, lastModificationTime, filterFieldsFunc);
+ }
+
+ @Test
+ public void testGetAllComponentIdTimeAndType() throws Exception {
+
+ Either<List<ComponentCacheData>, ActionStatus> result;
+
+ // default test
+
+ result = testSubject.getAllComponentIdTimeAndType();
+ testSubject.setEnabled(false);
+ result = testSubject.getAllComponentIdTimeAndType();
+ }
+
+ @Test
+ public void testUpdateCatalogInMemoryCacheWithCertified() throws Exception {
+
+ List<Component> foundComponents = new LinkedList<>();
- @Mock
- ToscaOperationFacade toscaOperationFacade;
+ // default test
+ testSubject.init();
+ Deencapsulation.invoke(testSubject, "updateCatalogInMemoryCacheWithCertified", foundComponents,
+ ComponentTypeEnum.RESOURCE);
+ }
- @Before
- public void setUpMocks() throws Exception {
- MockitoAnnotations.initMocks(this);
- }
+ @Test
+ public void testGetDataFromInMemoryCache() throws Exception {
- @Test
- public void testInit() throws Exception {
- // default test
- testSubject.init();
- }
+ Set<String> components = new HashSet<>();
+ components.add("mock");
+ ComponentTypeEnum componentTypeEnum = null;
+ List<Component> result;
- @Test
- public void testIsEnabled() throws Exception {
+ // default test
+ testSubject.init();
+ result = Deencapsulation.invoke(testSubject, "getDataFromInMemoryCache", components,
+ ComponentTypeEnum.RESOURCE);
+ }
- boolean result;
+ @Test
+ public void testGetComponents() throws Exception {
- // default test
+ Set<String> components = new HashSet<>();
+ Function<List<Component>, List<Component>> filterFieldsFunc = new Function<List<Component>, List<Component>>() {
- result = testSubject.isEnabled();
- }
+ @Override
+ public List<Component> apply(List<Component> t) {
+ return t;
+ }
+ };
+ Either<ImmutableTriple<List<Component>, List<Component>, Set<String>>, ActionStatus> result;
- @Test
- public void testSetEnabled() throws Exception {
+ List<ComponentCacheData> list = new LinkedList<>();
+ Mockito.when(componentCassandraDao.getComponents(Mockito.any(List.class))).thenReturn(Either.left(list));
+
+ // default test
+ testSubject.init();
+ result = testSubject.getComponents(components, filterFieldsFunc);
+ }
+
+ @Test
+ public void testGetComponentsNotAllowed() throws Exception {
+
+ Set<String> components = new HashSet<>();
+ Function<List<Component>, List<Component>> filterFieldsFunc = null;
+
+ Either<ImmutableTriple<List<Component>, List<Component>, Set<String>>, ActionStatus> result;
+
+ // default test
+ testSubject.setEnabled(false);
+ result = testSubject.getComponents(components, filterFieldsFunc);
+ }
+
+ @Test
+ public void testGetComponentsCassndraError() throws Exception {
+
+ Set<String> components = new HashSet<>();
+ Function<List<Component>, List<Component>> filterFieldsFunc = null;
+ Either<ImmutableTriple<List<Component>, List<Component>, Set<String>>, ActionStatus> result;
+
+ Mockito.when(componentCassandraDao.getComponents(Mockito.any(List.class)))
+ .thenReturn(Either.right(ActionStatus.GENERAL_ERROR));
- boolean enabled = false;
+ // default test
+ testSubject.init();
+ result = testSubject.getComponents(components, filterFieldsFunc);
+ }
- // default test
+ @Test
+ public void testGetComponentsForLeftPanel() throws Exception {
- testSubject.setEnabled(enabled);
- }
+ ComponentTypeEnum componentTypeEnum = null;
+ String internalComponentType = "mock";
+ Set<String> filteredResources = new HashSet<>();
+ Either<ImmutableTriple<List<Component>, List<Component>, Set<String>>, ActionStatus> result;
- @Test
- public void testGetComponentNotFound() throws Exception {
+ List<ComponentCacheData> list = new LinkedList<>();
+ Mockito.when(componentCassandraDao.getComponents(Mockito.any(List.class))).thenReturn(Either.left(list));
- String componentUid = "mock";
- Long lastModificationTime = null;
- Function<Component, Component> filterFieldsFunc = null;
- Either<Component, ActionStatus> result;
+ // default test
+ result = testSubject.getComponentsForLeftPanel(ComponentTypeEnum.RESOURCE, internalComponentType,
+ filteredResources);
+ }
- Mockito.when(componentCassandraDao.getComponent("mock"))
- .thenReturn(Either.right(ActionStatus.ARTIFACT_NOT_FOUND));
- // default test
- result = testSubject.getComponent(componentUid, lastModificationTime, filterFieldsFunc);
- }
+ @Test
+ public void testFilterForLeftPanel() throws Exception {
- @Test
- public void testGetComponentInvalidDate() throws Exception {
+ List<Component> components = new LinkedList<>();
+ List<Component> result;
- String componentUid = "mock";
- Long lastModificationTime = 0L;
- Function<Component, Component> filterFieldsFunc = null;
- Either<Component, ActionStatus> result;
+ // test 1
- ComponentCacheData a = new ComponentCacheData();
- a.setModificationTime(new Date());
- Mockito.when(componentCassandraDao.getComponent("mock")).thenReturn(Either.left(a));
- // default test
- result = testSubject.getComponent(componentUid, lastModificationTime, filterFieldsFunc);
- }
+ result = Deencapsulation.invoke(testSubject, "filterForLeftPanel", components);
+ Assert.assertNotEquals(null, result);
+ }
- @Test
- public void testGetComponentDeserializeError() throws Exception {
+ @Test
+ public void testFilterForCatalog() throws Exception {
- String componentUid = "mock";
- Long lastModificationTime = 0L;
- Function<Component, Component> filterFieldsFunc = null;
- Either<Component, ActionStatus> result;
+ List<Component> components = new LinkedList<>();
+ List<Component> result;
- ComponentCacheData a = new ComponentCacheData();
- a.setModificationTime(new Date(0L));
- a.setType(NodeTypeEnum.Resource.getName());
- Mockito.when(componentCassandraDao.getComponent("mock")).thenReturn(Either.left(a));
- // default test
- result = testSubject.getComponent(componentUid, lastModificationTime, filterFieldsFunc);
- }
+ // test 1
+ result = Deencapsulation.invoke(testSubject, "filterForCatalog", components);
+ Assert.assertNotEquals(null, result);
+ }
- @Test
- public void testGetComponent() throws Exception {
+ @Test
+ public void testFilterFieldsForLeftPanel() throws Exception {
+ Component result;
- String componentUid = "mock";
- Long lastModificationTime = 0L;
- Function<Component, Component> filterFieldsFunc = null;
- Either<Component, ActionStatus> result;
+ // default test
+ Resource resource = new Resource();
+ resource.setComponentType(ComponentTypeEnum.RESOURCE);
+ result = Deencapsulation.invoke(testSubject, "filterFieldsForLeftPanel", resource);
+ Service service = new Service();
+ service.setComponentType(ComponentTypeEnum.SERVICE);
+ result = Deencapsulation.invoke(testSubject, "filterFieldsForLeftPanel", service);
+ }
- ComponentCacheData a = new ComponentCacheData();
- a.setModificationTime(new Date(0L));
- a.setType(NodeTypeEnum.Resource.getName());
- Resource resource = new Resource();
- Either<byte[], Boolean> serialize = SerializationUtils.serializeExt(resource);
- byte[] value = serialize.left().value();
- a.setData(ByteBuffer.wrap(value));
- Mockito.when(componentCassandraDao.getComponent("mock")).thenReturn(Either.left(a));
- // default test
- result = testSubject.getComponent(componentUid, lastModificationTime, filterFieldsFunc);
- }
+ @Test
+ public void testFilterFieldsForCatalog() throws Exception {
+ Component result;
- @Test
- public void testGetAllComponentIdTimeAndType() throws Exception {
+ // default test
- Either<List<ComponentCacheData>, ActionStatus> result;
+ Resource resource = new Resource();
+ resource.setComponentType(ComponentTypeEnum.RESOURCE);
+ result = Deencapsulation.invoke(testSubject, "filterFieldsForCatalog", resource);
+ Service service = new Service();
+ service.setComponentType(ComponentTypeEnum.SERVICE);
+ result = Deencapsulation.invoke(testSubject, "filterFieldsForCatalog", service);
+ Product product = new Product();
+ product.setComponentType(ComponentTypeEnum.PRODUCT);
+ result = Deencapsulation.invoke(testSubject, "filterFieldsForCatalog", product);
+ }
- // default test
+ @Test
+ public void testCopyFieldsForLeftPanel() throws Exception {
- result = testSubject.getAllComponentIdTimeAndType();
- testSubject.setEnabled(false);
- result = testSubject.getAllComponentIdTimeAndType();
- }
+ Component component = new Resource();
+ Component filteredComponent = new Resource();
+ ((ResourceMetadataDataDefinition) component.getComponentMetadataDefinition().getMetadataDataDefinition())
+ .setResourceType(ResourceTypeEnum.VL);
+ // default test
- @Test
- public void testUpdateCatalogInMemoryCacheWithCertified() throws Exception {
+ Deencapsulation.invoke(testSubject, "copyFieldsForLeftPanel", component, filteredComponent);
+ }
- List<Component> foundComponents = new LinkedList<>();
+ @Test
+ public void testGetComponentsFullDisabled() throws Exception {
- // default test
- testSubject.init();
- Deencapsulation.invoke(testSubject, "updateCatalogInMemoryCacheWithCertified", foundComponents,
- ComponentTypeEnum.RESOURCE);
- }
+ Set<String> filteredResources = null;
+ Either<ImmutableTriple<List<Component>, List<Component>, Set<String>>, ActionStatus> result;
- @Test
- public void testGetDataFromInMemoryCache() throws Exception {
+ // default test
+ testSubject.setEnabled(false);
+ result = Deencapsulation.invoke(testSubject, "getComponentsFull", Set.class);
+ }
- Set<String> components = new HashSet<>();
- components.add("mock");
- ComponentTypeEnum componentTypeEnum = null;
- List<Component> result;
-
- // default test
- testSubject.init();
- result = Deencapsulation.invoke(testSubject, "getDataFromInMemoryCache", components,
- ComponentTypeEnum.RESOURCE);
- }
-
- @Test
- public void testGetComponents() throws Exception {
-
- Set<String> components = new HashSet<>();
- Function<List<Component>, List<Component>> filterFieldsFunc = new Function<List<Component>, List<Component>>() {
-
- @Override
- public List<Component> apply(List<Component> t) {
- return t;
- }
- };
- Either<ImmutableTriple<List<Component>, List<Component>, Set<String>>, ActionStatus> result;
-
- List<ComponentCacheData> list = new LinkedList<>();
- Mockito.when(componentCassandraDao.getComponents(Mockito.any(List.class))).thenReturn(Either.left(list));
-
- // default test
- testSubject.init();
- result = testSubject.getComponents(components, filterFieldsFunc);
- }
-
- @Test
- public void testGetComponentsNotAllowed() throws Exception {
-
- Set<String> components = new HashSet<>();
- Function<List<Component>, List<Component>> filterFieldsFunc = null;
- Either<ImmutableTriple<List<Component>, List<Component>, Set<String>>, ActionStatus> result;
-
- // default test
- testSubject.setEnabled(false);
- result = testSubject.getComponents(components, filterFieldsFunc);
- }
+ @Test
+ public void testGetComponentsFullDesirializeError() throws Exception {
- @Test
- public void testGetComponentsCassndraError() throws Exception {
+ Set<String> filteredResources = new HashSet<>();
+ filteredResources.add("mock");
+ Either<ImmutableTriple<List<Component>, List<Component>, Set<String>>, ActionStatus> result;
- Set<String> components = new HashSet<>();
- Function<List<Component>, List<Component>> filterFieldsFunc = null;
- Either<ImmutableTriple<List<Component>, List<Component>, Set<String>>, ActionStatus> result;
+ List<ComponentCacheData> a = new LinkedList<>();
+ ComponentCacheData e = new ComponentCacheData();
+ e.setId("mock");
+ e.setType(NodeTypeEnum.Resource.getName());
+ a.add(e);
+ Mockito.when(componentCassandraDao.getComponents(Mockito.any(List.class))).thenReturn(Either.left(a));
- Mockito.when(componentCassandraDao.getComponents(Mockito.any(List.class)))
- .thenReturn(Either.right(ActionStatus.GENERAL_ERROR));
-
- // default test
- testSubject.init();
- result = testSubject.getComponents(components, filterFieldsFunc);
- }
-
- @Test
- public void testGetComponentsForLeftPanel() throws Exception {
-
- ComponentTypeEnum componentTypeEnum = null;
- String internalComponentType = "mock";
- Set<String> filteredResources = new HashSet<>();
- Either<ImmutableTriple<List<Component>, List<Component>, Set<String>>, ActionStatus> result;
+ // default test
- List<ComponentCacheData> list = new LinkedList<>();
- Mockito.when(componentCassandraDao.getComponents(Mockito.any(List.class))).thenReturn(Either.left(list));
+ result = Deencapsulation.invoke(testSubject, "getComponentsFull", filteredResources);
+ }
- // default test
- result = testSubject.getComponentsForLeftPanel(ComponentTypeEnum.RESOURCE, internalComponentType,
- filteredResources);
- }
- @Test
- public void testFilterForLeftPanel() throws Exception {
+ @Test
+ public void testGetComponent_1() throws Exception {
- List<Component> components = new LinkedList<>();
- List<Component> result;
+ String componentUid = "mock";
+ Either<Component, ActionStatus> result;
- // test 1
+ Mockito.when(componentCassandraDao.getComponent("mock"))
+ .thenReturn(Either.right(ActionStatus.ARTIFACT_NOT_FOUND));
- result = Deencapsulation.invoke(testSubject, "filterForLeftPanel", components);
- Assert.assertNotEquals(null, result);
- }
+ // default test
+ result = testSubject.getComponent(componentUid);
+ }
- @Test
- public void testFilterForCatalog() throws Exception {
+ @Test
+ public void testGetComponent_2() throws Exception {
- List<Component> components = new LinkedList<>();
- List<Component> result;
+ String componentUid = "mock";
+ Long lastModificationTime = null;
+ Either<Component, ActionStatus> result;
- // test 1
- result = Deencapsulation.invoke(testSubject, "filterForCatalog", components);
- Assert.assertNotEquals(null, result);
- }
+ Mockito.when(componentCassandraDao.getComponent("mock"))
+ .thenReturn(Either.right(ActionStatus.ARTIFACT_NOT_FOUND));
- @Test
- public void testFilterFieldsForLeftPanel() throws Exception {
- Component result;
+ // default test
+ Function<Component, Component> filterFieldsFunc = new Function<Component, Component>() {
+ @Override
+ public Component apply(Component component) {
+ return new Resource();
+ }
+ };
+ result = testSubject.getComponent(componentUid, lastModificationTime, filterFieldsFunc);
+ }
- // default test
- result = Deencapsulation.invoke(testSubject, "filterFieldsForLeftPanel", new Resource());
- result = Deencapsulation.invoke(testSubject, "filterFieldsForLeftPanel", new Service());
- }
+ @Test
+ public void testSaveComponent() throws Exception {
- @Test
- public void testFilterFieldsForCatalog() throws Exception {
- Component result;
+ String componentUid = "";
+ Component component = new Resource();
+ boolean result;
- // default test
- result = Deencapsulation.invoke(testSubject, "filterFieldsForCatalog", new Resource());
- result = Deencapsulation.invoke(testSubject, "filterFieldsForCatalog", new Service());
- result = Deencapsulation.invoke(testSubject, "filterFieldsForCatalog", new Product());
- }
+ // default test
+ Mockito.when(componentCassandraDao.saveComponent(Mockito.any(ComponentCacheData.class)))
+ .thenReturn(CassandraOperationStatus.OK);
- @Test
- public void testCopyFieldsForLeftPanel() throws Exception {
+ result = Deencapsulation.invoke(testSubject, "saveComponent", componentUid, 0L, NodeTypeEnum.Resource,
+ component);
+ }
- Component component = new Resource();
- Component filteredComponent = new Resource();
- ((ResourceMetadataDataDefinition) component.getComponentMetadataDefinition().getMetadataDataDefinition())
- .setResourceType(ResourceTypeEnum.VL);
- // default test
+ @Test
+ public void testSetComponent_1Disabled() throws Exception {
- Deencapsulation.invoke(testSubject, "copyFieldsForLeftPanel", component, filteredComponent);
- }
+ Component component = new Resource();
+ component.setLastUpdateDate(0L);
+ boolean result;
- @Test
- public void testGetComponentsFullDisabled() throws Exception {
+ // default test
+ testSubject.setEnabled(false);
+ result = testSubject.setComponent(component, NodeTypeEnum.Resource);
+ }
- Set<String> filteredResources = null;
- Either<ImmutableTriple<List<Component>, List<Component>, Set<String>>, ActionStatus> result;
+ @Test
+ public void testSetComponent_1() throws Exception {
- // default test
- testSubject.setEnabled(false);
- result = Deencapsulation.invoke(testSubject, "getComponentsFull", Set.class);
- }
+ Component component = new Resource();
+ component.setLastUpdateDate(0L);
+ boolean result;
- @Test
- public void testGetComponentsFull() throws Exception {
+ // default test
- Set<String> filteredResources = new HashSet<>();
- filteredResources.add("mock");
- Either<ImmutableTriple<List<Component>, List<Component>, Set<String>>, ActionStatus> result;
+ result = testSubject.setComponent(component, NodeTypeEnum.Resource);
+ }
- List<ComponentCacheData> a = new LinkedList<>();
- ComponentCacheData e = new ComponentCacheData();
- e.setId("mock");
- e.setType(NodeTypeEnum.Resource.getName());
- Resource resource = new Resource();
- Either<byte[], Boolean> serialize = SerializationUtils.serializeExt(resource);
- byte[] value = serialize.left().value();
- e.setData(ByteBuffer.wrap(value));
- a.add(e);
- Mockito.when(componentCassandraDao.getComponents(Mockito.any(List.class))).thenReturn(Either.left(a));
- // default test
+ @Test
+ public void testGetComponentsFull_1CannotDeserialize() throws Exception {
+ Map<String, Long> filteredResources = new HashMap<>();
+ Either<ImmutablePair<List<Component>, Set<String>>, ActionStatus> result;
- result = Deencapsulation.invoke(testSubject, "getComponentsFull", filteredResources);
- }
+ // default test
+ LinkedList<ComponentCacheData> left = new LinkedList<>();
+ ComponentCacheData e = new ComponentCacheData();
+ e.setType(NodeTypeEnum.Resource.getName());
+ left.add(e);
+ ImmutablePair<List<ComponentCacheData>, Set<String>> immutablePair = ImmutablePair.of(left, new HashSet<>());
+ Mockito.when(componentCassandraDao.getComponents(Mockito.any(Map.class))).thenReturn(Either.left(immutablePair));
- @Test
- public void testGetComponentsFullDesirializeError() throws Exception {
+ result = Deencapsulation.invoke(testSubject, "getComponentsFull", filteredResources);
+ }
- Set<String> filteredResources = new HashSet<>();
- filteredResources.add("mock");
- Either<ImmutableTriple<List<Component>, List<Component>, Set<String>>, ActionStatus> result;
+ @Test
+ public void testGetComponentsFull_1Disabled() throws Exception {
+ Map<String, Long> filteredResources = new HashMap<>();
+ Either<ImmutablePair<List<Component>, Set<String>>, ActionStatus> result;
- List<ComponentCacheData> a = new LinkedList<>();
- ComponentCacheData e = new ComponentCacheData();
- e.setId("mock");
- e.setType(NodeTypeEnum.Resource.getName());
- a.add(e);
- Mockito.when(componentCassandraDao.getComponents(Mockito.any(List.class))).thenReturn(Either.left(a));
+ // default test
+ testSubject.setEnabled(false);
+ result = Deencapsulation.invoke(testSubject, "getComponentsFull", filteredResources);
+ }
- // default test
+ @Test
+ public void testGetComponentsFull_1NotFound() throws Exception {
+ Map<String, Long> filteredResources = new HashMap<>();
+ Either<ImmutablePair<List<Component>, Set<String>>, ActionStatus> result;
- result = Deencapsulation.invoke(testSubject, "getComponentsFull", filteredResources);
- }
+ // default test
+ Mockito.when(componentCassandraDao.getComponents(Mockito.any(Map.class))).thenReturn(Either.right(ActionStatus.ARTIFACT_NOT_FOUND));
- @Test
- public void testConvertComponentCacheToComponentServiceZipped() throws Exception {
+ result = Deencapsulation.invoke(testSubject, "getComponentsFull", filteredResources);
+ }
- ComponentCacheData componentCacheData = new ComponentCacheData();
- Either<? extends Component, Boolean> result;
+ @Test
+ public void testGetComponentsForCatalog_1Disabled() throws Exception {
- componentCacheData.setId("mock");
- componentCacheData.setType(NodeTypeEnum.Service.getName());
- componentCacheData.setIsZipped(true);
- Service service = new Service();
- Either<byte[], Boolean> serialize = SerializationUtils.serializeExt(service);
- byte[] value = serialize.left().value();
+ Map<String, Long> components = null;
+ Either<ImmutablePair<List<Component>, Set<String>>, ActionStatus> result;
- componentCacheData.setData(ByteBuffer.wrap(ZipUtil.zipBytes(value)));
+ // default test
+ testSubject.setEnabled(false);
+ result = testSubject.getComponentsForCatalog(components, ComponentTypeEnum.RESOURCE);
+ }
- // default test
+ @Test
+ public void testGetComponentsForCatalog_1() throws Exception {
+ Map<String, Long> components = new HashMap<>();
+ Either<ImmutablePair<List<Component>, Set<String>>, ActionStatus> result;
- result = Deencapsulation.invoke(testSubject, "convertComponentCacheToComponent", componentCacheData);
- }
+ // default test
+ ImmutablePair<List<ComponentCacheData>, Set<String>> value = ImmutablePair.of(new LinkedList<>(), new HashSet<>());
+ Mockito.when(componentCassandraDao.getComponents(Mockito.any(Map.class))).thenReturn(Either.left(value));
+ testSubject.init();
+ result = testSubject.getComponentsForCatalog(components, ComponentTypeEnum.RESOURCE);
+ }
- @Test
- public void testConvertComponentCacheToComponentProductZipped() throws Exception {
+ @Test
+ public void testGetComponentsForCatalog_1Error() throws Exception {
+ Map<String, Long> components = new HashMap<>();
+ Either<ImmutablePair<List<Component>, Set<String>>, ActionStatus> result;
- ComponentCacheData componentCacheData = new ComponentCacheData();
- Either<? extends Component, Boolean> result;
+ // default test
+ Mockito.when(componentCassandraDao.getComponents(Mockito.any(Map.class))).thenReturn(Either.right(ActionStatus.COMPONENT_NOT_FOUND));
- componentCacheData.setId("mock");
- componentCacheData.setType(NodeTypeEnum.Product.getName());
- componentCacheData.setIsZipped(true);
- Product product = new Product();
- Either<byte[], Boolean> serialize = SerializationUtils.serializeExt(product);
- byte[] value = serialize.left().value();
+ result = testSubject.getComponentsForCatalog(components, ComponentTypeEnum.RESOURCE);
+ }
- componentCacheData.setData(ByteBuffer.wrap(ZipUtil.zipBytes(value)));
+ @Test
+ public void testGetComponents_1Disabled() throws Exception {
- // default test
+ Map<String, Long> components = null;
+ Function<List<Component>, List<Component>> filterFieldsFunc = null;
+ Either<ImmutablePair<List<Component>, Set<String>>, ActionStatus> result;
- result = Deencapsulation.invoke(testSubject, "convertComponentCacheToComponent", componentCacheData);
- }
+ // default test
+ testSubject.setEnabled(false);
+ result = testSubject.getComponents(components, filterFieldsFunc);
+ }
- @Test
- public void testGetComponent_1() throws Exception {
+ @Test
+ public void testGetComponentAndTimeNotFound() throws Exception {
- String componentUid = "mock";
- Either<Component, ActionStatus> result;
+ String componentUid = "";
+ Function<Component, Component> filterFieldsFunc = null;
+ Either<ImmutablePair<Component, Long>, ActionStatus> result;
- Mockito.when(componentCassandraDao.getComponent("mock"))
- .thenReturn(Either.right(ActionStatus.ARTIFACT_NOT_FOUND));
+ // default test
+ Mockito.when(componentCassandraDao.getComponent(Mockito.anyString())).thenReturn(Either.right(ActionStatus.API_RESOURCE_NOT_FOUND));
- // default test
- result = testSubject.getComponent(componentUid);
- }
+ result = testSubject.getComponentAndTime(componentUid, filterFieldsFunc);
+ }
- @Test
- public void testGetComponent_2() throws Exception {
+ @Test
+ public void testGetComponentFromCacheDisabled() throws Exception {
+ String componentUid = "";
+ Long lastModificationTime = null;
+ Function<Component, Component> filterFieldsFunc = null;
+ Either<ImmutablePair<Component, ComponentCacheData>, ActionStatus> result;
+
+ // test 1
+ lastModificationTime = null;
+ testSubject.setEnabled(false);
+ result = Deencapsulation.invoke(testSubject, "getComponentFromCache",
+ new Object[]{componentUid, Long.class, Function.class});
+ }
- String componentUid = "mock";
- Long lastModificationTime = null;
- Either<Component, ActionStatus> result;
+ @Test
+ public void testDeleteComponentFromCacheFails() throws Exception {
- Mockito.when(componentCassandraDao.getComponent("mock"))
- .thenReturn(Either.right(ActionStatus.ARTIFACT_NOT_FOUND));
+ String id = "";
+ ActionStatus result;
- // default test
+ // default test
- result = testSubject.getComponent(componentUid, lastModificationTime);
- }
+ result = testSubject.deleteComponentFromCache(id);
+ }
- @Test
- public void testSetComponentDisabled() throws Exception {
+ @Test
+ public void testDeleteComponentFromCacheDisabled() throws Exception {
- String componentUid = "";
- Long lastModificationTime = null;
- NodeTypeEnum nodeTypeEnum = null;
- boolean result;
+ String id = "";
+ ActionStatus result;
- // default test
- testSubject.setEnabled(false);
- result = testSubject.setComponent(componentUid, lastModificationTime, nodeTypeEnum);
- }
+ // default test
+ testSubject.setEnabled(false);
+ result = testSubject.deleteComponentFromCache(id);
+ }
- @Test
- public void testSetComponentNotFound() throws Exception {
+ @Test
+ public void testDeleteComponentFromCache() throws Exception {
- String componentUid = "";
- Long lastModificationTime = null;
- boolean result;
+ String id = "";
+ ActionStatus result;
- // default test
- Mockito.when(toscaOperationFacade.getToscaElement(componentUid))
- .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
-
- result = testSubject.setComponent(componentUid, lastModificationTime, NodeTypeEnum.Resource);
- }
-
- @Test
- public void testSetComponent() throws Exception {
-
- String componentUid = "";
- Long lastModificationTime = 0L;
- boolean result;
-
- // default test
- Mockito.when(toscaOperationFacade.getToscaElement(componentUid)).thenReturn(Either.left(new Resource()));
-
- result = testSubject.setComponent(componentUid, lastModificationTime, NodeTypeEnum.Resource);
- }
-
- @Test
- public void testSaveComponent() throws Exception {
-
- String componentUid = "";
- Component component = new Resource();
- boolean result;
-
- // default test
- Mockito.when(componentCassandraDao.saveComponent(Mockito.any(ComponentCacheData.class)))
- .thenReturn(CassandraOperationStatus.OK);
-
- result = Deencapsulation.invoke(testSubject, "saveComponent", componentUid, 0L, NodeTypeEnum.Resource,
- component);
- }
-
- @Test
- public void testSetComponent_1Disabled() throws Exception {
-
- Component component = new Resource();
- component.setLastUpdateDate(0L);
- boolean result;
-
- // default test
- testSubject.setEnabled(false);
- result = testSubject.setComponent(component, NodeTypeEnum.Resource);
- }
-
- @Test
- public void testSetComponent_1() throws Exception {
-
- Component component = new Resource();
- component.setLastUpdateDate(0L);
- boolean result;
-
- // default test
-
- result = testSubject.setComponent(component, NodeTypeEnum.Resource);
- }
-
- @Test
- public void testGetComponentsFull_1() throws Exception {
- Map<String, Long> filteredResources = new HashMap<>();
- Either<ImmutablePair<List<Component>, Set<String>>, ActionStatus> result;
-
- // default test
- LinkedList<ComponentCacheData> left = new LinkedList<>();
- ComponentCacheData e = new ComponentCacheData();
- Either<byte[], Boolean> serializeExt = SerializationUtils.serializeExt(new Resource());
- e.setData(ByteBuffer.wrap(serializeExt.left().value()));
- e.setType(NodeTypeEnum.Resource.getName());
- left.add(e);
- ImmutablePair<List<ComponentCacheData>, Set<String>> immutablePair = ImmutablePair.of(left, new HashSet<>());
- Mockito.when(componentCassandraDao.getComponents(Mockito.any(Map.class))).thenReturn(Either.left(immutablePair));
-
- result = Deencapsulation.invoke(testSubject, "getComponentsFull", filteredResources);
- }
-
- @Test
- public void testGetComponentsFull_1CannotDeserialize() throws Exception {
- Map<String, Long> filteredResources = new HashMap<>();
- Either<ImmutablePair<List<Component>, Set<String>>, ActionStatus> result;
-
- // default test
- LinkedList<ComponentCacheData> left = new LinkedList<>();
- ComponentCacheData e = new ComponentCacheData();
- e.setType(NodeTypeEnum.Resource.getName());
- left.add(e);
- ImmutablePair<List<ComponentCacheData>, Set<String>> immutablePair = ImmutablePair.of(left, new HashSet<>());
- Mockito.when(componentCassandraDao.getComponents(Mockito.any(Map.class))).thenReturn(Either.left(immutablePair));
-
- result = Deencapsulation.invoke(testSubject, "getComponentsFull", filteredResources);
- }
-
- @Test
- public void testGetComponentsFull_1Disabled() throws Exception {
- Map<String, Long> filteredResources = new HashMap<>();
- Either<ImmutablePair<List<Component>, Set<String>>, ActionStatus> result;
-
- // default test
- testSubject.setEnabled(false);
- result = Deencapsulation.invoke(testSubject, "getComponentsFull", filteredResources);
- }
-
- @Test
- public void testGetComponentsFull_1NotFound() throws Exception {
- Map<String, Long> filteredResources = new HashMap<>();
- Either<ImmutablePair<List<Component>, Set<String>>, ActionStatus> result;
-
- // default test
- Mockito.when(componentCassandraDao.getComponents(Mockito.any(Map.class))).thenReturn(Either.right(ActionStatus.ARTIFACT_NOT_FOUND));
-
- result = Deencapsulation.invoke(testSubject, "getComponentsFull", filteredResources);
- }
-
- @Test
- public void testGetComponentsForCatalog_1Disabled() throws Exception {
-
- Map<String, Long> components = null;
- Either<ImmutablePair<List<Component>, Set<String>>, ActionStatus> result;
-
- // default test
- testSubject.setEnabled(false);
- result = testSubject.getComponentsForCatalog(components, ComponentTypeEnum.RESOURCE);
- }
-
- @Test
- public void testGetComponentsForCatalog_1() throws Exception {
- Map<String, Long> components = new HashMap<>();
- Either<ImmutablePair<List<Component>, Set<String>>, ActionStatus> result;
-
- // default test
- ImmutablePair<List<ComponentCacheData>, Set<String>> value = ImmutablePair.of(new LinkedList<>(), new HashSet<>());
- Mockito.when(componentCassandraDao.getComponents(Mockito.any(Map.class))).thenReturn(Either.left(value));
- testSubject.init();
- result = testSubject.getComponentsForCatalog(components, ComponentTypeEnum.RESOURCE);
- }
-
- @Test
- public void testGetComponentsForCatalog_1Error() throws Exception {
- Map<String, Long> components = new HashMap<>();
- Either<ImmutablePair<List<Component>, Set<String>>, ActionStatus> result;
-
- // default test
- Mockito.when(componentCassandraDao.getComponents(Mockito.any(Map.class))).thenReturn(Either.right(ActionStatus.COMPONENT_NOT_FOUND));
-
- result = testSubject.getComponentsForCatalog(components, ComponentTypeEnum.RESOURCE);
- }
-
- @Test
- public void testGetComponents_1Disabled() throws Exception {
-
- Map<String, Long> components = null;
- Function<List<Component>, List<Component>> filterFieldsFunc = null;
- Either<ImmutablePair<List<Component>, Set<String>>, ActionStatus> result;
-
- // default test
- testSubject.setEnabled(false);
- result = testSubject.getComponents(components, filterFieldsFunc);
- }
-
- @Test
- public void testGetComponentAndTime() throws Exception {
-
- String componentUid = "";
- Function<Component, Component> filterFieldsFunc = null;
- Either<ImmutablePair<Component, Long>, ActionStatus> result;
-
- // default test
- ComponentCacheData a = new ComponentCacheData();
- a.setModificationTime(new Date());
- a.setType(NodeTypeEnum.Resource.getName());
- Either<byte[], Boolean> serializeExt = SerializationUtils.serializeExt(new Resource());
- a.setData(ByteBuffer.wrap(serializeExt.left().value()));
- Mockito.when(componentCassandraDao.getComponent(Mockito.anyString())).thenReturn(Either.left(a));
-
- result = testSubject.getComponentAndTime(componentUid, filterFieldsFunc);
- }
-
- @Test
- public void testGetComponentAndTimeNotFound() throws Exception {
-
- String componentUid = "";
- Function<Component, Component> filterFieldsFunc = null;
- Either<ImmutablePair<Component, Long>, ActionStatus> result;
-
- // default test
- Mockito.when(componentCassandraDao.getComponent(Mockito.anyString())).thenReturn(Either.right(ActionStatus.API_RESOURCE_NOT_FOUND));
-
- result = testSubject.getComponentAndTime(componentUid, filterFieldsFunc);
- }
-
- @Test
- public void testGetComponentFromCacheDisabled() throws Exception {
- String componentUid = "";
- Long lastModificationTime = null;
- Function<Component, Component> filterFieldsFunc = null;
- Either<ImmutablePair<Component, ComponentCacheData>, ActionStatus> result;
-
- // test 1
- lastModificationTime = null;
- testSubject.setEnabled(false);
- result = Deencapsulation.invoke(testSubject, "getComponentFromCache",
- new Object[] { componentUid, Long.class, Function.class });
- }
-
- @Test
- public void testDeleteComponentFromCacheFails() throws Exception {
-
- String id = "";
- ActionStatus result;
-
- // default test
-
- result = testSubject.deleteComponentFromCache(id);
- }
-
- @Test
- public void testDeleteComponentFromCacheDisabled() throws Exception {
-
- String id = "";
- ActionStatus result;
-
- // default test
- testSubject.setEnabled(false);
- result = testSubject.deleteComponentFromCache(id);
- }
-
- @Test
- public void testDeleteComponentFromCache() throws Exception {
-
- String id = "";
- ActionStatus result;
-
- // default test
- Mockito.when(componentCassandraDao.deleteComponent(Mockito.anyString())).thenReturn(CassandraOperationStatus.OK);
- result = testSubject.deleteComponentFromCache(id);
- }
+ // default test
+ Mockito.when(componentCassandraDao.deleteComponent(Mockito.anyString())).thenReturn(CassandraOperationStatus.OK);
+ result = testSubject.deleteComponentFromCache(id);
+ }
} \ No newline at end of file