2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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=========================================================
23 import com.openpojo.reflection.PojoClass;
24 import com.openpojo.reflection.PojoClassFilter;
25 import com.openpojo.reflection.filters.FilterEnum;
26 import com.openpojo.reflection.filters.FilterNonConcrete;
27 import com.openpojo.reflection.filters.FilterPackageInfo;
28 import com.openpojo.validation.Validator;
29 import com.openpojo.validation.ValidatorBuilder;
30 import com.openpojo.validation.rule.impl.*;
31 import com.openpojo.validation.test.impl.*;
32 import org.junit.Test;
33 import org.onap.so.openpojo.rules.ToStringTester;
34 import org.springframework.stereotype.Component;
37 public class BeansTest {
39 private final PojoClassFilter filterTestClasses = new FilterTestClasses();
41 private final PojoClassFilter enumFilter = new FilterEnum();
43 private final PojoClassFilter noNestedClasses = new FilterTestNestedClasses();
48 public void pojoStructure() {
49 test("org.onap.so.adapters.network.async.client");
50 test("org.onap.so.adapters.vnf.async.client");
51 test("org.onap.so.adapters.network");
52 test("org.onap.so.adapters.vnf");
53 test("org.onap.so.adapters.valet");
54 test("org.onap.so.adapters.valet.beans");
55 test("org.onap.so.vdu.utils");
58 private void test(String pojoPackage) {
59 Validator validator = ValidatorBuilder.create()
60 .with(new NoStaticExceptFinalRule())
61 .with(new SerializableMustHaveSerialVersionUIDRule())
62 .with(new NoPublicFieldsExceptStaticFinalRule())
63 .with(new SetterTester())
64 .with(new GetterTester())
65 .with(new ToStringTester())
70 validator.validate(pojoPackage, new FilterPackageInfo(), filterTestClasses,enumFilter,new FilterNonConcrete(), noNestedClasses, new FilterBeans());
72 private static class FilterTestClasses implements PojoClassFilter {
73 public boolean include(PojoClass pojoClass) {
74 return !pojoClass.getSourcePath().contains("/test-classes/");
78 private static class FilterTestNestedClasses implements PojoClassFilter {
79 public boolean include(PojoClass pojoClass) {
80 return !pojoClass.isNestedClass();
84 private static class FilterBeans implements PojoClassFilter {
85 public boolean include(PojoClass pojoClass) {
86 return pojoClass.getAnnotations().stream().filter(o -> o instanceof Component).count() <= 0;