2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.bpmn.servicedecomposition;
23 import static org.junit.Assert.assertEquals;
25 import java.io.ByteArrayOutputStream;
26 import java.io.Externalizable;
28 import java.io.IOException;
29 import java.io.ObjectOutputStream;
30 import java.io.OutputStream;
31 import java.io.Serializable;
32 import java.util.HashMap;
35 import org.camunda.bpm.engine.delegate.DelegateExecution;
36 import org.camunda.bpm.engine.impl.pvm.runtime.ExecutionImpl;
37 import org.junit.Test;
38 import org.onap.so.SerializableChecker;
39 import org.onap.so.SerializableChecker.SerializationFailure;
40 import org.onap.so.bpmn.common.BuildingBlockExecution;
41 import org.onap.so.bpmn.common.DelegateExecutionImpl;
42 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
43 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
45 import com.fasterxml.jackson.databind.ObjectMapper;
47 public class SerializationTest {
49 private static final String RESOURCE_PATH = "src/test/resources/__files/ExecuteBuildingBlock/";
50 private static final String FLOW_VAR_NAME = "flowToBeCalled";
51 private static final String LOOKUP_KEY_MAP_VAR_NAME = "lookupKeyMap";
52 private static final String GBB_INPUT_VAR_NAME = "gBBInput";
53 protected ObjectMapper mapper = new ObjectMapper();
56 public void testSerializationOfAllPojos() throws IOException {
57 GeneralBuildingBlock gbb = mapper.readValue(new File(RESOURCE_PATH + "GeneralBuildingBlockExpected.json"),
58 GeneralBuildingBlock.class);
59 Map<ResourceKey, String> lookupKeyMap = new HashMap<>();
60 DelegateExecution execution = new ExecutionImpl();
61 execution.setVariable(FLOW_VAR_NAME, "AssignServiceInstanceBB");
62 execution.setVariable(GBB_INPUT_VAR_NAME, gbb);
63 execution.setVariable(LOOKUP_KEY_MAP_VAR_NAME, lookupKeyMap);
64 System.out.println(execution.getVariables());
65 BuildingBlockExecution gBuildingBlockExecution = new DelegateExecutionImpl(execution);
66 boolean isSerializable = SerializationTest.isSerializable(gBuildingBlockExecution);
67 assertEquals(true, isSerializable);
70 public static boolean isSerializable(final Object o)
74 if(implementsInterface(o))
76 retVal = attemptToSerialize(o);
86 private static boolean implementsInterface(final Object o)
90 retVal = ((o instanceof Serializable) || (o instanceof Externalizable));
95 private static boolean attemptToSerialize(final Object o)
97 final OutputStream sink;
98 ObjectOutputStream stream;
104 sink = new ByteArrayOutputStream();
105 stream = new ObjectOutputStream(sink);
106 stream.writeObject(o);
107 // could also re-serilalize at this point too
109 catch(final IOException ex)
121 catch(final IOException ex)
123 // should not be able to happen