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.montoring.configuration;
22 import static org.junit.Assert.assertFalse;
25 import java.util.regex.Pattern;
27 import org.junit.Test;
28 import org.onap.so.openpojo.rules.ToStringTester;
29 import org.springframework.beans.factory.config.BeanDefinition;
30 import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
31 import org.springframework.core.type.filter.RegexPatternTypeFilter;
33 import com.openpojo.reflection.filters.FilterPackageInfo;
34 import com.openpojo.validation.Validator;
35 import com.openpojo.validation.ValidatorBuilder;
36 import com.openpojo.validation.test.impl.GetterTester;
37 import com.openpojo.validation.test.impl.SetterTester;
39 import nl.jqno.equalsverifier.EqualsVerifier;
40 import nl.jqno.equalsverifier.Warning;
43 * @author waqas.ikram@ericsson.com
45 public class PojoClassesTests {
48 public void test_camunda_module_pojo_classes() throws ClassNotFoundException {
49 test("org.onap.so.montoring.camunda.model");
50 assertEqualMethod("org.onap.so.montoring.camunda.model");
54 public void test_so_monitoring_pojo_classes() throws ClassNotFoundException {
55 test("org.onap.so.montoring.model");
56 assertEqualMethod("org.onap.so.montoring.model");
59 public void assertEqualMethod(final String pojoPackage) throws ClassNotFoundException {
60 final Set<BeanDefinition> classes = getBeanDefinition(pojoPackage);
61 assertFalse(classes.isEmpty());
62 for (final BeanDefinition bean : classes) {
63 final Class<?> clazz = Class.forName(bean.getBeanClassName());
64 if (!clazz.getName().endsWith("Builder")) {
65 EqualsVerifier.forClass(clazz).suppress(Warning.STRICT_INHERITANCE, Warning.NONFINAL_FIELDS).verify();
70 private Set<BeanDefinition> getBeanDefinition(final String pojoPackage) {
71 final ClassPathScanningCandidateComponentProvider provider =
72 new ClassPathScanningCandidateComponentProvider(false);
73 provider.addIncludeFilter(new RegexPatternTypeFilter(Pattern.compile(pojoPackage + ".*")));
74 return provider.findCandidateComponents(pojoPackage);
77 private void test(final String pojoPackage) {
78 final Validator validator = ValidatorBuilder.create().with(new SetterTester()).with(new GetterTester())
79 .with(new ToStringTester()).build();
80 validator.validate(pojoPackage, new FilterPackageInfo());