aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/MSOCommonBPMN/src/test
diff options
context:
space:
mode:
authorAndrei Barcovschi <andrei.barcovschi@ericsson.com>2019-03-26 15:25:44 +0000
committerAndrei Barcovschi <andrei.barcovschi@ericsson.com>2019-03-26 15:25:55 +0000
commitbefc44d1b17d92b5417aa121714152a898236a7b (patch)
treece4be44f30119ee55c9b36d65a00a12b944ee817 /bpmn/MSOCommonBPMN/src/test
parentaf46c0d4b30ecb5c8f36992e74adb86d7d5bbe06 (diff)
Fix serialize DelegateExecutionImpl object bug
Change-Id: I140796717f9e8a365650355d92df60b85bc7a8e2 Issue-ID: SO-1690 Signed-off-by: Andrei Barcovschi <andrei.barcovschi@ericsson.com>
Diffstat (limited to 'bpmn/MSOCommonBPMN/src/test')
-rw-r--r--bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/DelegateExecutionImplTest.java208
1 files changed, 109 insertions, 99 deletions
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/DelegateExecutionImplTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/DelegateExecutionImplTest.java
index 32a18d5a7a..a30aadc1f8 100644
--- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/DelegateExecutionImplTest.java
+++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/DelegateExecutionImplTest.java
@@ -20,19 +20,15 @@
package org.onap.so.bpmn.common;
-import static org.hamcrest.CoreMatchers.hasItems;
-import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
-import static org.mockito.ArgumentMatchers.contains;
+import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import java.io.Serializable;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -46,101 +42,115 @@ import org.onap.so.bpmn.common.exceptions.MissingBuildingBlockInputException;
import org.onap.so.bpmn.common.exceptions.RequiredExecutionVariableExeception;
import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
public class DelegateExecutionImplTest {
- @Rule
- public ExpectedException thrown= ExpectedException.none();
-
-
- @Test
- public void getVariable() throws RequiredExecutionVariableExeception {
- Map<String, Serializable> map = new HashMap<>();
- map.put("var1", "value1");
- map.put("var2", "value2");
- map.put("list1", (Serializable)Arrays.asList("value1", "value2"));
- DelegateExecutionImpl impl = create(map);
-
- assertEquals("value1", impl.getVariable("var1"));
- assertEquals("value2", impl.getRequiredVariable("var2"));
- assertThat(impl.getVariable("list1"), IsIterableContainingInOrder.contains("value1", "value2"));
-
- }
-
-
- @Test
- public void getRequiredVariableNotFound() throws RequiredExecutionVariableExeception {
- DelegateExecutionImpl impl = create();
-
- thrown.expect(RequiredExecutionVariableExeception.class);
- impl.getRequiredVariable("var1");
- }
-
-
- @Test
- public void setVariable() {
- DelegateExecutionImpl impl = create();
- impl.setVariable("var1", "value1");
-
- assertEquals("value1", impl.get("var1"));
- }
-
- @Test
- public void getGeneralBuildingBlock() {
- GeneralBuildingBlock gBB = mock(GeneralBuildingBlock.class);
- Map<String, Serializable> map = new HashMap<>();
- map.put("gBBInput", gBB);
- DelegateExecutionImpl impl = create(map);
-
- assertEquals(gBB, impl.getGeneralBuildingBlock());
- }
-
- @Test
- public void getGeneralBuildingBlockNotFound() {
-
- DelegateExecutionImpl impl = create();
-
- thrown.expect(MissingBuildingBlockInputException.class);
- impl.getGeneralBuildingBlock();
- }
-
- @Test
- public void getGeneralBuildingBlockCastException() {
- Map<String, Serializable> map = new HashMap<>();
- map.put("gBBInput", new DelegateExecutionFake());
- DelegateExecutionImpl impl = create(map);
-
- thrown.expect(MalformedBuildingBlockInputException.class);
- impl.getGeneralBuildingBlock();
- }
-
- @Test
- public void getDelegateExecution() {
- DelegateExecutionImpl impl = create();
-
- assertNotNull(impl.getDelegateExecution());
- }
-
- @Test
- public void getLookupMap() {
- Map<String, Serializable> lookup = new HashMap<>();
- Map<String, Serializable> map = new HashMap<>();
- map.put("lookupKeyMap", (Serializable) lookup);
- DelegateExecutionImpl impl = create(map);
-
- assertEquals(lookup, impl.getLookupMap());
- }
-
- private DelegateExecutionImpl create() {
- return create(new HashMap<String, Serializable>());
- }
-
- private DelegateExecutionImpl create(Map<String, Serializable> map) {
- DelegateExecutionFake fake = new DelegateExecutionFake();
-
- for (Entry<String, Serializable> entry : map.entrySet()) {
- fake.setVariable(entry.getKey(), entry.getValue());
- }
- return new DelegateExecutionImpl(fake);
- }
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+
+ @Test
+ public void getVariable() throws RequiredExecutionVariableExeception {
+ final Map<String, Serializable> map = new HashMap<>();
+ map.put("var1", "value1");
+ map.put("var2", "value2");
+ map.put("list1", (Serializable) Arrays.asList("value1", "value2"));
+ final DelegateExecutionImpl impl = create(map);
+
+ assertEquals("value1", impl.getVariable("var1"));
+ assertEquals("value2", impl.getRequiredVariable("var2"));
+ assertThat(impl.getVariable("list1"), IsIterableContainingInOrder.contains("value1", "value2"));
+
+ }
+
+
+ @Test
+ public void getRequiredVariableNotFound() throws RequiredExecutionVariableExeception {
+ final DelegateExecutionImpl impl = create();
+
+ thrown.expect(RequiredExecutionVariableExeception.class);
+ impl.getRequiredVariable("var1");
+ }
+
+
+ @Test
+ public void setVariable() {
+ final DelegateExecutionImpl impl = create();
+ impl.setVariable("var1", "value1");
+
+ assertEquals("value1", impl.get("var1"));
+ }
+
+ @Test
+ public void getGeneralBuildingBlock() {
+ final GeneralBuildingBlock gBB = mock(GeneralBuildingBlock.class);
+ final Map<String, Serializable> map = new HashMap<>();
+ map.put("gBBInput", gBB);
+ final DelegateExecutionImpl impl = create(map);
+
+ assertEquals(gBB, impl.getGeneralBuildingBlock());
+ }
+
+ @Test
+ public void getGeneralBuildingBlockNotFound() {
+ final DelegateExecutionImpl impl = create();
+ thrown.expect(MissingBuildingBlockInputException.class);
+ impl.getGeneralBuildingBlock();
+ }
+
+ @Test
+ public void getGeneralBuildingBlockCastException() {
+ final Map<String, Serializable> map = new HashMap<>();
+ map.put("gBBInput", new DelegateExecutionFake());
+ final DelegateExecutionImpl impl = create(map);
+
+ thrown.expect(MalformedBuildingBlockInputException.class);
+ impl.getGeneralBuildingBlock();
+ }
+
+ @Test
+ public void getDelegateExecution() {
+ final DelegateExecutionImpl impl = create();
+
+ assertNotNull(impl.getDelegateExecution());
+ }
+
+ @Test
+ public void getLookupMap() {
+ final Map<String, Serializable> lookup = new HashMap<>();
+ final Map<String, Serializable> map = new HashMap<>();
+ map.put("lookupKeyMap", (Serializable) lookup);
+ final DelegateExecutionImpl impl = create(map);
+
+ assertEquals(lookup, impl.getLookupMap());
+ }
+
+ @Test
+ public void testDelegateExecutionImpl_serializeDelegateExecutionImplObject_shouldNotThrowAnyExceptionWhenSerializing() {
+ final DelegateExecutionImpl objectUnderTest = create();
+
+ try {
+ final ObjectMapper objectMapper = new ObjectMapper();
+ objectMapper.writeValueAsString(objectUnderTest);
+ } catch (final JsonProcessingException e) {
+ fail("Should be possible to serialize DelegateExecutionImpl object");
+ }
+
+ }
+
+ private DelegateExecutionImpl create() {
+ return create(new HashMap<String, Serializable>());
+ }
+
+ private DelegateExecutionImpl create(final Map<String, Serializable> map) {
+ final DelegateExecutionFake fake = new DelegateExecutionFake();
+
+ for (final Entry<String, Serializable> entry : map.entrySet()) {
+ fake.setVariable(entry.getKey(), entry.getValue());
+ }
+ return new DelegateExecutionImpl(fake);
+ }
}