summaryrefslogtreecommitdiffstats
path: root/bpmn/MSOCommonBPMN/src/test
diff options
context:
space:
mode:
authorLukasz Muszkieta <lukasz.muszkieta@nokia.com>2019-10-21 08:14:44 +0000
committerGerrit Code Review <gerrit@onap.org>2019-10-21 08:14:44 +0000
commit1d6c9fde4bb1abead317f217c636ab6a61dbd7df (patch)
treefb17cdf72d6c7fb61f09b5f13cff8e05b3575574 /bpmn/MSOCommonBPMN/src/test
parent3af51ce9259f3dde295afe28fb1e313d747c7cb6 (diff)
parentbcf93e74a01c1618455b675ae1613890a7d1718f (diff)
Merge "Removed unused SerializableChecker class; updated imports in SerializationTest class"
Diffstat (limited to 'bpmn/MSOCommonBPMN/src/test')
-rw-r--r--bpmn/MSOCommonBPMN/src/test/java/org/onap/so/SerializableChecker.java163
-rw-r--r--bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/SerializationTest.java4
2 files changed, 1 insertions, 166 deletions
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/SerializableChecker.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/SerializableChecker.java
deleted file mode 100644
index 47ddea1b4f..0000000000
--- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/SerializableChecker.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.so;
-
-import java.io.Serializable;
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-public final class SerializableChecker {
- public static class SerializationFailure {
- private final String mContainingClass;
- private final String mMemberName;
-
- public SerializationFailure(String inNonSerializableClass, String inMemberName) {
- mContainingClass = inNonSerializableClass;
- mMemberName = inMemberName;
- }
-
- public String getContainingClass() {
- return mContainingClass;
- }
-
- public String getMemberName() {
- return mMemberName;
- }
-
- public String getBadMemberString() {
- if (mMemberName == null)
- return mContainingClass;
- return mContainingClass + "." + mMemberName;
- }
-
- @Override
- public String toString() {
- return "SerializationFailure [mNonSerializableClass=" + mContainingClass + ", mMemberName=" + mMemberName
- + "]";
- }
- }
-
- private static class SerializationCheckerData {
- private Set<Class<?>> mSerializableClasses;
-
- SerializationCheckerData() {
- mSerializableClasses = new HashSet<Class<?>>();
- }
-
- boolean isAlreadyChecked(Class<?> inClass) {
- return mSerializableClasses.contains(inClass);
- }
-
- void addSerializableClass(Class<?> inClass) {
- mSerializableClasses.add(inClass);
- }
- }
-
- private SerializableChecker() {}
-
- public static SerializationFailure isFullySerializable(Class<?> inClass) {
- if (!isSerializable(inClass))
- return new SerializationFailure(inClass.getName(), null);
-
- return isFullySerializable(inClass, new SerializationCheckerData());
- }
-
- private static SerializationFailure isFullySerializable(Class<?> inClass,
- SerializationCheckerData inSerializationCheckerData) {
- for (Field field : declaredFields(inClass)) {
- Class<?> fieldDeclaringClass = field.getType();
-
- if (field.getType() == Object.class)
- continue;
-
- if (Modifier.isStatic(field.getModifiers()))
- continue;
-
- if (field.isSynthetic())
- continue;
-
- if (fieldDeclaringClass.isInterface() || fieldDeclaringClass.isPrimitive())
- continue;
-
- if (Modifier.isAbstract(field.getType().getModifiers()))
- continue;
-
- if (inSerializationCheckerData.isAlreadyChecked(fieldDeclaringClass))
- continue;
-
- if (isSerializable(fieldDeclaringClass)) {
- inSerializationCheckerData.addSerializableClass(inClass);
-
- SerializationFailure failure = isFullySerializable(field.getType(), inSerializationCheckerData);
- if (failure != null)
- return failure;
- else
- continue;
- }
-
- if (Modifier.isTransient(field.getModifiers()))
- continue;
-
- return new SerializationFailure(field.getDeclaringClass().getName(), field.getName());
- }
- return null;
- }
-
- private static boolean isSerializable(Class<?> inClass) {
- Set<Class<?>> interfaces = getInterfaces(inClass);
- if (interfaces == null)
- return false;
- boolean isSerializable = interfaces.contains(Serializable.class);
- if (isSerializable)
- return true;
-
- for (Class<?> classInterface : interfaces) {
- if (isSerializable(classInterface))
- return true;
- }
-
- if (inClass.getSuperclass() != null && isSerializable(inClass.getSuperclass()))
- return true;
-
- return false;
- }
-
- private static Set<Class<?>> getInterfaces(Class<?> inFieldDeclaringClass) {
- return new HashSet<Class<?>>(Arrays.asList(inFieldDeclaringClass.getInterfaces()));
- }
-
- private static List<Field> declaredFields(Class<?> inClass) {
- List<Field> fields = new ArrayList<Field>(Arrays.asList(inClass.getDeclaredFields()));
-
- Class<?> parentClasses = inClass.getSuperclass();
-
- if (parentClasses == null)
- return fields;
- fields.addAll(declaredFields(parentClasses));
-
- return fields;
- }
-}
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/SerializationTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/SerializationTest.java
index b970b95b97..e9e83a59ae 100644
--- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/SerializationTest.java
+++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/SerializationTest.java
@@ -20,7 +20,6 @@
package org.onap.so.bpmn.servicedecomposition;
-import static org.junit.Assert.assertEquals;
import java.io.ByteArrayOutputStream;
import java.io.Externalizable;
import java.io.File;
@@ -33,8 +32,7 @@ import java.util.Map;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.impl.pvm.runtime.ExecutionImpl;
import org.junit.Test;
-import org.onap.so.SerializableChecker;
-import org.onap.so.SerializableChecker.SerializationFailure;
+import static org.junit.Assert.assertEquals;
import org.onap.so.bpmn.common.BuildingBlockExecution;
import org.onap.so.bpmn.common.DelegateExecutionImpl;
import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;