Replaced all tabs with spaces in java and pom.xml
[so.git] / adapters / mso-openstack-adapters / src / test / java / org / onap / so / BeansTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.so;
22
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;
35
36
37 public class BeansTest {
38
39     private final PojoClassFilter filterTestClasses = new FilterTestClasses();
40
41     private final PojoClassFilter enumFilter = new FilterEnum();
42
43     private final PojoClassFilter noNestedClasses = new FilterTestNestedClasses();
44
45
46
47     @Test
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");
56     }
57
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())
62
63                 .build();
64
65
66         validator.validate(pojoPackage, new FilterPackageInfo(), filterTestClasses, enumFilter, new FilterNonConcrete(),
67                 noNestedClasses, new FilterBeans());
68     }
69
70     private static class FilterTestClasses implements PojoClassFilter {
71         public boolean include(PojoClass pojoClass) {
72             return !pojoClass.getSourcePath().contains("/test-classes/");
73         }
74     }
75
76     private static class FilterTestNestedClasses implements PojoClassFilter {
77         public boolean include(PojoClass pojoClass) {
78             return !pojoClass.isNestedClass();
79         }
80     }
81
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;
85         }
86     }
87
88 }