From bcf93e74a01c1618455b675ae1613890a7d1718f Mon Sep 17 00:00:00 2001 From: Oleksandr Moliavko Date: Wed, 9 Oct 2019 13:39:11 +0300 Subject: Removed unused SerializableChecker class; updated imports in SerializationTest class Issue-ID: SO-1841 Signed-off-by: Oleksandr Moliavko Change-Id: Ifcbe5352bf5710a3527eeb394e516d3d864537db --- .../test/java/org/onap/so/SerializableChecker.java | 163 --------------------- .../servicedecomposition/SerializationTest.java | 4 +- 2 files changed, 1 insertion(+), 166 deletions(-) delete mode 100644 bpmn/MSOCommonBPMN/src/test/java/org/onap/so/SerializableChecker.java (limited to 'bpmn/MSOCommonBPMN/src') 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> mSerializableClasses; - - SerializationCheckerData() { - mSerializableClasses = new HashSet>(); - } - - 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> 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> getInterfaces(Class inFieldDeclaringClass) { - return new HashSet>(Arrays.asList(inFieldDeclaringClass.getInterfaces())); - } - - private static List declaredFields(Class inClass) { - List fields = new ArrayList(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; -- cgit 1.2.3-korg