7aa86da237f866500d7178e5980ca843fab158d5
[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()
60                                  .with(new NoStaticExceptFinalRule())
61                 .with(new SerializableMustHaveSerialVersionUIDRule())
62                                 .with(new NoPublicFieldsExceptStaticFinalRule())                         
63                                 .with(new SetterTester())
64                                 .with(new GetterTester())
65                                 .with(new ToStringTester())
66                                 
67                                 .build();
68                 
69         
70                 validator.validate(pojoPackage, new FilterPackageInfo(), filterTestClasses,enumFilter,new FilterNonConcrete(), noNestedClasses, new FilterBeans());
71         }
72         private static class FilterTestClasses implements PojoClassFilter {
73                 public boolean include(PojoClass pojoClass) {
74                         return !pojoClass.getSourcePath().contains("/test-classes/");
75                 }
76         }
77
78         private static class FilterTestNestedClasses implements PojoClassFilter {
79                 public boolean include(PojoClass pojoClass) {
80                         return !pojoClass.isNestedClass();
81                 }
82         }
83
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;
87                 }
88         }
89
90 }