2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2018 Ericsson. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
20 package org.onap.so.monitoring.configuration;
22 import static org.junit.Assert.assertFalse;
24 import java.util.regex.Pattern;
25 import org.junit.Test;
26 import org.onap.so.openpojo.rules.ToStringTester;
27 import org.springframework.beans.factory.config.BeanDefinition;
28 import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
29 import org.springframework.core.type.filter.RegexPatternTypeFilter;
30 import com.openpojo.reflection.filters.FilterPackageInfo;
31 import com.openpojo.validation.Validator;
32 import com.openpojo.validation.ValidatorBuilder;
33 import com.openpojo.validation.test.impl.GetterTester;
34 import com.openpojo.validation.test.impl.SetterTester;
35 import nl.jqno.equalsverifier.EqualsVerifier;
36 import nl.jqno.equalsverifier.Warning;
39 * @author waqas.ikram@ericsson.com
41 public class PojoClassesTests {
44 public void test_camunda_module_pojo_classes() throws ClassNotFoundException {
45 test("org.onap.so.monitoring.camunda.model");
46 assertEqualMethod("org.onap.so.monitoring.camunda.model");
50 public void test_so_monitoring_pojo_classes() throws ClassNotFoundException {
51 test("org.onap.so.monitoring.model");
52 assertEqualMethod("org.onap.so.monitoring.model");
55 public void assertEqualMethod(final String pojoPackage) throws ClassNotFoundException {
56 final Set<BeanDefinition> classes = getBeanDefinition(pojoPackage);
57 assertFalse(classes.isEmpty());
58 for (final BeanDefinition bean : classes) {
59 final Class<?> clazz = Class.forName(bean.getBeanClassName());
60 if (!clazz.getName().endsWith("Builder")) {
61 EqualsVerifier.forClass(clazz).suppress(Warning.STRICT_INHERITANCE, Warning.NONFINAL_FIELDS).verify();
66 private Set<BeanDefinition> getBeanDefinition(final String pojoPackage) {
67 final ClassPathScanningCandidateComponentProvider provider =
68 new ClassPathScanningCandidateComponentProvider(false);
69 provider.addIncludeFilter(new RegexPatternTypeFilter(Pattern.compile(pojoPackage + ".*")));
70 return provider.findCandidateComponents(pojoPackage);
73 private void test(final String pojoPackage) {
74 final Validator validator = ValidatorBuilder.create().with(new SetterTester()).with(new GetterTester())
75 .with(new ToStringTester()).build();
76 validator.validate(pojoPackage, new FilterPackageInfo());