summaryrefslogtreecommitdiffstats
path: root/catalog-model
diff options
context:
space:
mode:
authorTal Gitelman <tg851x@intl.att.com>2018-06-10 18:05:18 +0300
committerTal Gitelman <tg851x@intl.att.com>2018-06-10 18:06:21 +0300
commit907753f90f876574efdc4c4153ef7516e0bcf8b3 (patch)
tree639f855f78bfa6063bddf0f2606b682ea1efbde3 /catalog-model
parent3e20c00529a3208f32c8814cc6420b8a0f11bb66 (diff)
new unit tests for sdc-model
Change-Id: I31489f5e9bc83aaa5b18ebf2e519a13216f49332 Issue-ID: SDC-1333 Signed-off-by: Tal Gitelman <tg851x@intl.att.com>
Diffstat (limited to 'catalog-model')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/ComponentCache.java92
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/cache/ComponentCacheTest.java593
2 files changed, 460 insertions, 225 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/ComponentCache.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/ComponentCache.java
index eb33a50e0b..439b4346ef 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/ComponentCache.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/ComponentCache.java
@@ -74,7 +74,7 @@ public class ComponentCache {
@Autowired
ComponentCassandraDao componentCassandraDao;
-
+
@Autowired
ToscaOperationFacade toscaOperationFacade;
@@ -157,64 +157,6 @@ public class ComponentCache {
}
/**
- * get components for catalog
- *
- * @param components
- * @param componentTypeEnum
- * @return
- */
- @Deprecated
- public Either<ImmutableTriple<List<Component>, List<Component>, Set<String>>, ActionStatus> getComponentsForCatalog(
- Set<String> components, ComponentTypeEnum componentTypeEnum) {
-
- if (false == isEnabled()) {
- logger.debug("In getComponentsForCatalog for type {}. Cache is disabled.",
- componentTypeEnum.name().toLowerCase());
- return Either.right(ActionStatus.NOT_ALLOWED);
- }
- logger.debug("In getComponentsForCatalog for type {}", componentTypeEnum.name().toLowerCase());
-
- Function<List<Component>, List<Component>> filterFieldsFunc = x -> filterForCatalog(x);
-
- Set<String> leftComponentsForSearch = new HashSet<>();
- leftComponentsForSearch.addAll(components);
-
- // get components from inmemory cache
- List<Component> componentsFromMemory = null;
- if (true == catalogInMemoryEnabled) {
- componentsFromMemory = getDataFromInMemoryCache(components, componentTypeEnum);
- logger.debug("The number of components of type {} fetched from memory is {}",
- componentTypeEnum.name().toLowerCase(),
- componentsFromMemory == null ? 0 : componentsFromMemory.size());
- if (componentsFromMemory != null) {
- componentsFromMemory.forEach(p -> leftComponentsForSearch.remove(p.getUniqueId()));
- }
- } else {
- logger.debug("Catalog InMemory cache is disabled");
- }
-
- logger.debug("Number of components from type {} needed to fetch is {}", componentTypeEnum.name().toLowerCase(),
- leftComponentsForSearch.size());
-
- // get components from cassandra cache and filter each component
- Either<ImmutableTriple<List<Component>, List<Component>, Set<String>>, ActionStatus> result = getComponents(
- leftComponentsForSearch, filterFieldsFunc);
-
- if (result.isLeft()) {
- // add inmemory components to the valid components(not dirty)
- List<Component> foundComponents = result.left().value().getLeft();
- if (componentsFromMemory != null) {
- foundComponents.addAll(componentsFromMemory);
- }
- if (true == catalogInMemoryEnabled) {
- updateCatalogInMemoryCacheWithCertified(foundComponents, componentTypeEnum);
- }
- }
-
- return result;
- }
-
- /**
* @param foundComponents
* @param componentTypeEnum
*/
@@ -267,13 +209,13 @@ public class ComponentCache {
/**
*
- * get full components from cassandra. On each component apply filter
- * function in order to remove unused members
+ * get full components from cassandra. On each component apply filter function
+ * in order to remove unused members
*
* @param components
* @param filterFieldsFunc
- * @return <found components, found dirty components, not found components
- * list> or Error
+ * @return <found components, found dirty components, not found components list>
+ * or Error
*/
public Either<ImmutableTriple<List<Component>, List<Component>, Set<String>>, ActionStatus> getComponents(
Set<String> components, Function<List<Component>, List<Component>> filterFieldsFunc) {
@@ -466,8 +408,8 @@ public class ComponentCache {
*
* @param filteredResources
* @return ImmutableTripple or ActionStatus. | |-- components |-- dirty
- * components - components with dirty flag = true. |-- set of non
- * cached components
+ * components - components with dirty flag = true. |-- set of non cached
+ * components
*
*/
private Either<ImmutableTriple<List<Component>, List<Component>, Set<String>>, ActionStatus> getComponentsFull(
@@ -546,11 +488,9 @@ public class ComponentCache {
.collect(Collectors.toSet());
notFoundResources.addAll(notCachedResources);
- if (logger.isDebugEnabled()) {
- logger.debug("Number of components fetched is {}", foundResources.size());
- logger.debug("Number of components fetched dirty is {}", foundDirtyResources.size());
- logger.debug("Number of components non cached is {}", notCachedResources.size());
- }
+ logger.debug("Number of components fetched is {}", foundResources.size());
+ logger.debug("Number of components fetched dirty is {}", foundDirtyResources.size());
+ logger.debug("Number of components non cached is {}", notCachedResources.size());
return Either.left(result);
}
@@ -603,7 +543,6 @@ public class ComponentCache {
public Either<Component, ActionStatus> getComponent(String componentUid) {
return getComponent(componentUid, null, Function.identity());
-
}
public Either<Component, ActionStatus> getComponent(String componentUid, Long lastModificationTime) {
@@ -663,9 +602,6 @@ public class ComponentCache {
} catch (IOException e) {
logger.debug("Failed to prepare component {} of type {} for cache", componentUid,
nodeTypeEnum.name().toLowerCase());
- if (logger.isTraceEnabled()) {
- logger.trace("Failed to prepare component {} of type {} for cache",componentUid,nodeTypeEnum.name().toLowerCase());
- }
}
} else {
logger.debug("Failed to serialize component {} of type {} for cache", componentUid,
@@ -768,10 +704,8 @@ public class ComponentCache {
Set<String> notFoundInCache = immutablePair.getRight();
notFoundResources.addAll(notFoundInCache);
- if (logger.isDebugEnabled()) {
- logger.debug("Number of components fetched is {}", foundResources.size());
- logger.debug("Number of components non cached is {}", notFoundResources.size());
- }
+ logger.debug("Number of components fetched is {}", foundResources.size());
+ logger.debug("Number of components non cached is {}", notFoundResources.size());
return Either.left(result);
}
@@ -955,7 +889,7 @@ public class ComponentCache {
if (false == isEnabled()) {
return ActionStatus.NOT_ALLOWED;
}
- CassandraOperationStatus status = this.componentCassandraDao.deleteComponent(id);
+ CassandraOperationStatus status = componentCassandraDao.deleteComponent(id);
if (CassandraOperationStatus.OK.equals(status)) {
return ActionStatus.OK;
} else {
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 419666b686..1fe8d6d764 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,5 +1,12 @@
package org.openecomp.sdc.be.model.cache;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+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;
@@ -8,378 +15,672 @@ import java.util.function.Function;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.ImmutableTriple;
import org.junit.Assert;
-import org.junit.Ignore;
+import org.junit.Before;
import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
+import org.openecomp.sdc.be.dao.cassandra.ComponentCassandraDao;
+import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.model.Component;
+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;
-@Ignore
-public class ComponentCacheTest {
+public class ComponentCacheTest extends ModelConfDependentTest {
- private ComponentCache createTestSubject() {
- return new ComponentCache();
+ @InjectMocks
+ ComponentCache testSubject;
+
+ @Mock
+ ComponentCassandraDao componentCassandraDao;
+
+ @Mock
+ ToscaOperationFacade toscaOperationFacade;
+
+ @Before
+ public void setUpMocks() throws Exception {
+ MockitoAnnotations.initMocks(this);
}
@Test
public void testInit() throws Exception {
- ComponentCache testSubject;
-
// default test
- testSubject = createTestSubject();
testSubject.init();
}
@Test
public void testIsEnabled() throws Exception {
- ComponentCache testSubject;
+
boolean result;
// default test
- testSubject = createTestSubject();
+
result = testSubject.isEnabled();
}
@Test
public void testSetEnabled() throws Exception {
- ComponentCache testSubject;
+
boolean enabled = false;
// default test
- testSubject = createTestSubject();
+
testSubject.setEnabled(enabled);
}
@Test
- public void testGetComponent() throws Exception {
- ComponentCache testSubject;
- String componentUid = "";
+ 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
- testSubject = createTestSubject();
result = testSubject.getComponent(componentUid, lastModificationTime, filterFieldsFunc);
}
@Test
- public void testGetAllComponentIdTimeAndType() throws Exception {
- ComponentCache testSubject;
- Either<List<ComponentCacheData>, ActionStatus> result;
+ 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
- testSubject = createTestSubject();
- result = testSubject.getAllComponentIdTimeAndType();
+ result = testSubject.getComponent(componentUid, lastModificationTime, filterFieldsFunc);
}
@Test
- public void testGetComponentsForCatalog() throws Exception {
- ComponentCache testSubject;
- Set<String> components = null;
- ComponentTypeEnum componentTypeEnum = null;
- Either<ImmutableTriple<List<Component>, List<Component>, Set<String>>, ActionStatus> result;
+ 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 testGetComponent() 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());
+ 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 testGetAllComponentIdTimeAndType() throws Exception {
+
+ Either<List<ComponentCacheData>, ActionStatus> result;
// default test
- testSubject = createTestSubject();
- result = testSubject.getComponentsForCatalog(components, componentTypeEnum);
+
+ result = testSubject.getAllComponentIdTimeAndType();
+ testSubject.setEnabled(false);
+ result = testSubject.getAllComponentIdTimeAndType();
}
@Test
public void testUpdateCatalogInMemoryCacheWithCertified() throws Exception {
- ComponentCache testSubject;
- List<Component> foundComponents = null;
- ComponentTypeEnum componentTypeEnum = null;
+
+ List<Component> foundComponents = new LinkedList<>();
// default test
- testSubject = createTestSubject();
- Deencapsulation.invoke(testSubject, "updateCatalogInMemoryCacheWithCertified", List.class,
- ComponentTypeEnum.class);
+ testSubject.init();
+ Deencapsulation.invoke(testSubject, "updateCatalogInMemoryCacheWithCertified", foundComponents,
+ ComponentTypeEnum.RESOURCE);
}
@Test
public void testGetDataFromInMemoryCache() throws Exception {
- ComponentCache testSubject;
- Set<String> components = null;
+
+ Set<String> components = new HashSet<>();
+ components.add("mock");
ComponentTypeEnum componentTypeEnum = null;
List<Component> result;
// default test
- testSubject = createTestSubject();
- result = Deencapsulation.invoke(testSubject, "getDataFromInMemoryCache", Set.class, ComponentTypeEnum.class);
+ testSubject.init();
+ result = Deencapsulation.invoke(testSubject, "getDataFromInMemoryCache", components,
+ ComponentTypeEnum.RESOURCE);
}
@Test
public void testGetComponents() throws Exception {
- ComponentCache testSubject;
- Set<String> components = null;
+
+ 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 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));
+
// default test
- testSubject = createTestSubject();
+ testSubject.init();
result = testSubject.getComponents(components, filterFieldsFunc);
}
@Test
public void testGetComponentsForLeftPanel() throws Exception {
- ComponentCache testSubject;
+
ComponentTypeEnum componentTypeEnum = null;
- String internalComponentType = "";
- Set<String> filteredResources = null;
+ String internalComponentType = "mock";
+ Set<String> filteredResources = new HashSet<>();
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 = createTestSubject();
- result = testSubject.getComponentsForLeftPanel(componentTypeEnum, internalComponentType, filteredResources);
+ result = testSubject.getComponentsForLeftPanel(ComponentTypeEnum.RESOURCE, internalComponentType,
+ filteredResources);
}
@Test
public void testFilterForLeftPanel() throws Exception {
- ComponentCache testSubject;
- List<Component> components = null;
+
+ List<Component> components = new LinkedList<>();
List<Component> result;
// test 1
- testSubject = createTestSubject();
- components = null;
- result = Deencapsulation.invoke(testSubject, "filterForLeftPanel", List.class);
- Assert.assertEquals(null, result);
+
+ result = Deencapsulation.invoke(testSubject, "filterForLeftPanel", components);
+ Assert.assertNotEquals(null, result);
}
@Test
public void testFilterForCatalog() throws Exception {
- ComponentCache testSubject;
- List<Component> components = null;
+
+ List<Component> components = new LinkedList<>();
List<Component> result;
// test 1
- testSubject = createTestSubject();
- components = null;
- result = Deencapsulation.invoke(testSubject, "filterForCatalog", List.class);
- Assert.assertEquals(null, result);
+ result = Deencapsulation.invoke(testSubject, "filterForCatalog", components);
+ Assert.assertNotEquals(null, result);
}
@Test
public void testFilterFieldsForLeftPanel() throws Exception {
- ComponentCache testSubject;
- Component component = null;
Component result;
// default test
- testSubject = createTestSubject();
- result = Deencapsulation.invoke(testSubject, "filterFieldsForLeftPanel", new Object[] { Component.class });
+ result = Deencapsulation.invoke(testSubject, "filterFieldsForLeftPanel", new Resource());
+ result = Deencapsulation.invoke(testSubject, "filterFieldsForLeftPanel", new Service());
}
@Test
public void testFilterFieldsForCatalog() throws Exception {
- ComponentCache testSubject;
- Component component = null;
Component result;
// default test
- testSubject = createTestSubject();
- result = Deencapsulation.invoke(testSubject, "filterFieldsForCatalog", new Object[] { Component.class });
+ result = Deencapsulation.invoke(testSubject, "filterFieldsForCatalog", new Resource());
+ result = Deencapsulation.invoke(testSubject, "filterFieldsForCatalog", new Service());
+ result = Deencapsulation.invoke(testSubject, "filterFieldsForCatalog", new Product());
}
@Test
public void testCopyFieldsForLeftPanel() throws Exception {
- ComponentCache testSubject;
- Component component = null;
- Component filteredComponent = null;
+ Component component = new Resource();
+ Component filteredComponent = new Resource();
+ ((ResourceMetadataDataDefinition) component.getComponentMetadataDefinition().getMetadataDataDefinition())
+ .setResourceType(ResourceTypeEnum.VL);
// default test
- testSubject = createTestSubject();
- Deencapsulation.invoke(testSubject, "copyFieldsForLeftPanel",
- new Object[] { Component.class, Component.class });
+
+ Deencapsulation.invoke(testSubject, "copyFieldsForLeftPanel", component, filteredComponent);
}
@Test
- public void testCopyFieldsForCatalog() throws Exception {
- ComponentCache testSubject;
- Component component = null;
- Component filteredComponent = null;
+ public void testGetComponentsFullDisabled() throws Exception {
+
+ Set<String> filteredResources = null;
+ Either<ImmutableTriple<List<Component>, List<Component>, Set<String>>, ActionStatus> result;
// default test
- testSubject = createTestSubject();
- Deencapsulation.invoke(testSubject, "copyFieldsForCatalog", new Object[] { Component.class, Component.class });
+ testSubject.setEnabled(false);
+ result = Deencapsulation.invoke(testSubject, "getComponentsFull", Set.class);
}
@Test
public void testGetComponentsFull() throws Exception {
- ComponentCache testSubject;
- Set<String> filteredResources = null;
+
+ Set<String> filteredResources = new HashSet<>();
+ filteredResources.add("mock");
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());
+ 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
- testSubject = createTestSubject();
- result = Deencapsulation.invoke(testSubject, "getComponentsFull", Set.class);
+
+ result = Deencapsulation.invoke(testSubject, "getComponentsFull", filteredResources);
+ }
+
+ @Test
+ public void testGetComponentsFullDesirializeError() throws Exception {
+
+ Set<String> filteredResources = new HashSet<>();
+ filteredResources.add("mock");
+ 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));
+
+ // default test
+
+ result = Deencapsulation.invoke(testSubject, "getComponentsFull", filteredResources);
}
@Test
- public void testConvertComponentCacheToComponent() throws Exception {
- ComponentCache testSubject;
- ComponentCacheData componentCacheData = null;
+ public void testConvertComponentCacheToComponentServiceZipped() throws Exception {
+
+ ComponentCacheData componentCacheData = new ComponentCacheData();
Either<? extends Component, Boolean> result;
+ 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();
+
+ componentCacheData.setData(ByteBuffer.wrap(ZipUtil.zipBytes(value)));
+
// default test
- testSubject = createTestSubject();
- result = Deencapsulation.invoke(testSubject, "convertComponentCacheToComponent",
- new Object[] { ComponentCacheData.class });
+
+ result = Deencapsulation.invoke(testSubject, "convertComponentCacheToComponent", componentCacheData);
}
@Test
- public void testDeserializeComponent() throws Exception {
- ComponentCache testSubject;
- ComponentCacheData componentCacheData = null;
- byte[] dataAsArray = new byte[] { ' ' };
+ public void testConvertComponentCacheToComponentProductZipped() throws Exception {
+
+ ComponentCacheData componentCacheData = new ComponentCacheData();
Either<? extends Component, Boolean> result;
+ 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();
+
+ componentCacheData.setData(ByteBuffer.wrap(ZipUtil.zipBytes(value)));
+
// default test
- testSubject = createTestSubject();
- result = Deencapsulation.invoke(testSubject, "deserializeComponent",
- new Object[] { ComponentCacheData.class, dataAsArray });
+
+ result = Deencapsulation.invoke(testSubject, "convertComponentCacheToComponent", componentCacheData);
}
@Test
public void testGetComponent_1() throws Exception {
- ComponentCache testSubject;
- String componentUid = "";
+
+ String componentUid = "mock";
Either<Component, ActionStatus> result;
+ Mockito.when(componentCassandraDao.getComponent("mock"))
+ .thenReturn(Either.right(ActionStatus.ARTIFACT_NOT_FOUND));
+
// default test
- testSubject = createTestSubject();
result = testSubject.getComponent(componentUid);
}
@Test
public void testGetComponent_2() throws Exception {
- ComponentCache testSubject;
- String componentUid = "";
+
+ String componentUid = "mock";
Long lastModificationTime = null;
Either<Component, ActionStatus> result;
+ Mockito.when(componentCassandraDao.getComponent("mock"))
+ .thenReturn(Either.right(ActionStatus.ARTIFACT_NOT_FOUND));
+
// default test
- testSubject = createTestSubject();
+
result = testSubject.getComponent(componentUid, lastModificationTime);
}
@Test
- public void testSetComponent() throws Exception {
- ComponentCache testSubject;
+ public void testSetComponentDisabled() throws Exception {
+
String componentUid = "";
Long lastModificationTime = null;
NodeTypeEnum nodeTypeEnum = null;
boolean result;
// default test
- testSubject = createTestSubject();
+ testSubject.setEnabled(false);
result = testSubject.setComponent(componentUid, lastModificationTime, nodeTypeEnum);
}
@Test
- public void testSaveComponent() throws Exception {
- ComponentCache testSubject;
+ public void testSetComponentNotFound() throws Exception {
+
String componentUid = "";
Long lastModificationTime = null;
- NodeTypeEnum nodeTypeEnum = null;
- Component component = null;
boolean result;
// default test
- testSubject = createTestSubject();
- result = Deencapsulation.invoke(testSubject, "saveComponent", componentUid, Long.class, NodeTypeEnum.class,
- Component.class);
+ 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 {
- ComponentCache testSubject;
- Component component = null;
- NodeTypeEnum nodeTypeEnum = null;
+
+ Component component = new Resource();
+ component.setLastUpdateDate(0L);
boolean result;
// default test
- testSubject = createTestSubject();
- result = testSubject.setComponent(component, nodeTypeEnum);
+
+ result = testSubject.setComponent(component, NodeTypeEnum.Resource);
}
@Test
public void testGetComponentsFull_1() throws Exception {
- ComponentCache testSubject;Map<String,Long> filteredResources = null;
- Either<ImmutablePair<List<Component>,Set<String>>,ActionStatus> result;
+ 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);
+ }
- // default test
- testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "getComponentsFull", Map.class);
+ @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 testGetComponentsForCatalog_1() throws Exception {
- ComponentCache testSubject;
+ 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;
- ComponentTypeEnum componentTypeEnum = null;
Either<ImmutablePair<List<Component>, Set<String>>, ActionStatus> result;
// default test
- testSubject = createTestSubject();
- result = testSubject.getComponentsForCatalog(components, componentTypeEnum);
+ 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_1() throws Exception {
- ComponentCache testSubject;
+ 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 = createTestSubject();
+ testSubject.setEnabled(false);
result = testSubject.getComponents(components, filterFieldsFunc);
}
@Test
public void testGetComponentAndTime() throws Exception {
- ComponentCache testSubject;
+
String componentUid = "";
Function<Component, Component> filterFieldsFunc = null;
Either<ImmutablePair<Component, Long>, ActionStatus> result;
// default test
- testSubject = createTestSubject();
+ 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 testGetComponentFromCache() throws Exception {
- ComponentCache testSubject;String componentUid = "";
- Long lastModificationTime = null;
- Function<Component,Component> filterFieldsFunc = null;
- Either<ImmutablePair<Component,ComponentCacheData>,ActionStatus> result;
-
- // test 1
- testSubject=createTestSubject();lastModificationTime = null;
- result=Deencapsulation.invoke(testSubject, "getComponentFromCache", new Object[]{componentUid, Long.class, Function.class});
- Assert.assertEquals(null, result);
+ 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 2
- testSubject=createTestSubject();filterFieldsFunc = null;
- result=Deencapsulation.invoke(testSubject, "getComponentFromCache", new Object[]{componentUid, Long.class, Function.class});
- Assert.assertEquals(null, result);
+ @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 {
- ComponentCache testSubject;
+
String id = "";
ActionStatus result;
// default test
- testSubject = createTestSubject();
+ Mockito.when(componentCassandraDao.deleteComponent(Mockito.anyString())).thenReturn(CassandraOperationStatus.OK);
result = testSubject.deleteComponentFromCache(id);
}
} \ No newline at end of file