From 95751fdf0e69dec1c2850136447679ac344c9230 Mon Sep 17 00:00:00 2001 From: ramverma Date: Tue, 28 Aug 2018 14:09:39 +0100 Subject: Adding usage of openpojo in policy common * Changing TestHealthCheckReport to use openpojo for testing the HealthCheckReport class. * Adding a custom Tester implementation called ToStringTester as a utility to test toString() method of classes using openpojo. Change-Id: I491a23c471d50454b4d5591c6c09c6758e2c0624 Issue-ID: POLICY-1035 Signed-off-by: ramverma --- policy-endpoints/pom.xml | 5 +++ .../endpoints/report/TestHealthCheckReport.java | 38 ++++++++-------------- 2 files changed, 19 insertions(+), 24 deletions(-) (limited to 'policy-endpoints') diff --git a/policy-endpoints/pom.xml b/policy-endpoints/pom.xml index fb546a5a..aedb56d8 100644 --- a/policy-endpoints/pom.xml +++ b/policy-endpoints/pom.xml @@ -189,6 +189,11 @@ test + + com.openpojo + openpojo + + diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/report/TestHealthCheckReport.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/report/TestHealthCheckReport.java index 72bae0cf..fd4cefb0 100644 --- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/report/TestHealthCheckReport.java +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/report/TestHealthCheckReport.java @@ -20,9 +20,16 @@ package org.onap.policy.common.endpoints.report; -import static org.junit.Assert.assertEquals; +import com.openpojo.reflection.filters.FilterClassName; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.rule.impl.SetterMustExistRule; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; import org.junit.Test; +import org.onap.policy.common.utils.validation.ToStringTester; /** * Class to perform unit test of HealthCheckReport. @@ -32,28 +39,11 @@ import org.junit.Test; public class TestHealthCheckReport { @Test - public void testReport() { - final String name = "Policy"; - final String url = "self"; - final boolean healthy = true; - final int code = 200; - final String message = "alive"; - final HealthCheckReport report = new HealthCheckReport(); - report.setName(name); - report.setUrl(url); - report.setHealthy(healthy); - report.setCode(code); - report.setMessage(message); - validateReport(name, url, healthy, code, message, report); - } - - private void validateReport(final String name, final String url, final boolean healthy, final int code, - final String message, final HealthCheckReport report) { - assertEquals(name, report.getName()); - assertEquals(url, report.getUrl()); - assertEquals(healthy, report.isHealthy()); - assertEquals(code, report.getCode()); - assertEquals(message, report.getMessage()); - assertEquals("Report [name=Policy, url=self, healthy=true, code=200, message=alive]", report.toString()); + public void testHealthCheckReport() { + final Validator validator = + ValidatorBuilder.create().with(new GetterMustExistRule()).with(new SetterMustExistRule()) + .with(new GetterTester()).with(new SetterTester()).with(new ToStringTester()).build(); + validator.validate(HealthCheckReport.class.getPackage().getName(), + new FilterClassName(HealthCheckReport.class.getName())); } } -- cgit 1.2.3-korg