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().with(new NoStaticExceptFinalRule())
60 .with(new SerializableMustHaveSerialVersionUIDRule()).with(new NoPublicFieldsExceptStaticFinalRule())
61 .with(new SetterTester()).with(new GetterTester()).with(new ToStringTester())
66 validator.validate(pojoPackage, new FilterPackageInfo(), filterTestClasses, enumFilter, new FilterNonConcrete(),
67 noNestedClasses, new FilterBeans());
70 private static class FilterTestClasses implements PojoClassFilter {
71 public boolean include(PojoClass pojoClass) {
72 return !pojoClass.getSourcePath().contains("/test-classes/");
76 private static class FilterTestNestedClasses implements PojoClassFilter {
77 public boolean include(PojoClass pojoClass) {
78 return !pojoClass.isNestedClass();
82 private static class FilterBeans implements PojoClassFilter {
83 public boolean include(PojoClass pojoClass) {
84 return pojoClass.getAnnotations().stream().filter(o -> o instanceof Component).count() <= 0;