diff options
author | mark.j.leonard <mark.j.leonard@gmail.com> | 2019-01-15 14:35:55 +0000 |
---|---|---|
committer | mark.j.leonard <mark.j.leonard@gmail.com> | 2019-01-16 13:42:36 +0000 |
commit | 3ec58a16f80426968919fe5da42732bf693909e0 (patch) | |
tree | 292f966636e48eeec9cd1f0b0f018cec76973997 /src/test | |
parent | 715e009fa1b0b148fc64f8cf1bc2f536e4e2cb23 (diff) |
Refactor - create a ValidationResult Builder class
In anticipation of the Validation Result output adopting the common
event payload, add an interface to provide a greater level of
abstraction between the current implementation and the classes that
create validation results.
Change-Id: Ie81228dff19a124011e77097768b44be5a3844b6
Issue-ID: AAI-2057
Signed-off-by: mark.j.leonard <mark.j.leonard@gmail.com>
Diffstat (limited to 'src/test')
6 files changed, 124 insertions, 107 deletions
diff --git a/src/test/java/org/onap/aai/validation/controller/TestValidationController.java b/src/test/java/org/onap/aai/validation/controller/TestValidationController.java index ff67181..b35ed17 100644 --- a/src/test/java/org/onap/aai/validation/controller/TestValidationController.java +++ b/src/test/java/org/onap/aai/validation/controller/TestValidationController.java @@ -1,12 +1,12 @@ -/* +/** * ============LICENSE_START=================================================== - * Copyright (c) 2018 Amdocs + * Copyright (c) 2018-2019 European Software Marketing Ltd. * ============================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -22,7 +22,6 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import com.google.gson.JsonArray; -import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import java.util.ArrayList; @@ -39,9 +38,7 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.runners.MockitoJUnitRunner; import org.onap.aai.validation.Validator; -import org.onap.aai.validation.config.EventReaderConfig; import org.onap.aai.validation.config.ValidationControllerConfig; -import org.onap.aai.validation.controller.ValidationController; import org.onap.aai.validation.exception.ValidationServiceError; import org.onap.aai.validation.exception.ValidationServiceException; import org.onap.aai.validation.publisher.MessagePublisher; @@ -49,6 +46,7 @@ import org.onap.aai.validation.reader.EventReader; import org.onap.aai.validation.reader.data.Entity; import org.onap.aai.validation.reader.data.EntityId; import org.onap.aai.validation.result.ValidationResult; +import org.onap.aai.validation.result.ValidationResultBuilder; import org.onap.aai.validation.result.Violation; @RunWith(MockitoJUnitRunner.class) @@ -172,12 +170,11 @@ public class TestValidationController { when(eventReader.getEntity(TESTDATA_EXCEPTION_EVENT)).thenReturn(entity); when(eventReader.getEntityType(TESTDATA_HANDLE_EXCEPTION_EXCEPTION_EVENT)).thenThrow( new RuntimeException("Error during handling the exception for an event that couldn't be validated")); - //@formatter:off - Mockito.doThrow(new ValidationServiceException(ValidationServiceError.EVENT_CLIENT_PUBLISHER_INIT_ERROR)) - .when(messagePublisher) - .publishMessage( - Mockito.contains("\"entityId\":\"[vserver-id=instanceid1]\",\"entityType\":\"entitytype1\",\"resourceVersion\":\"resourceVersion1\"")); - //@formatter:on + + Mockito.doThrow(new ValidationServiceException(ValidationServiceError.EVENT_CLIENT_PUBLISHER_INIT_ERROR)) + .when(messagePublisher).publishMessage( + Mockito.contains("\"entityId\":\"[vserver-id=instanceid1]\",\"entityType\":\"entitytype1\"," + + "\"resourceVersion\":\"resourceVersion1\"")); } private Map<String, List<String>> setupEventTypeData() { @@ -196,66 +193,72 @@ public class TestValidationController { } private Map<String, List<ValidationResult>> setupTestData() throws ValidationServiceException { + final Map<String, List<ValidationResult>> validationResultsMap = new HashMap<>(); - Map<String, List<ValidationResult>> validationResultsMap = new HashMap<>(); - - List<ValidationResult> aaiEventValidationResults = new ArrayList<>(); - + when(eventReader.getEntity(VSERVER)).thenReturn(entity); setUpEntityMock("20160525162737-61c49d41-5338-4755-af54-06cee9fe4aca", VSERVER, "1464193654"); - aaiEventValidationResults.add(new ValidationResult(entity)); - aaiEventValidationResults.add(new ValidationResult(entity)); + ValidationResultBuilder builder = new ValidationResultBuilder(eventReader, VSERVER); + List<ValidationResult> aaiEventValidationResults = new ArrayList<>(); + aaiEventValidationResults.add(builder.build()); + aaiEventValidationResults.add(builder.build()); validationResultsMap.put(TESTDATA_EVENTTYPE_AAI, aaiEventValidationResults); List<ValidationResult> apiEventValidationResults = new ArrayList<>(); setUpEntityMock("20160525162737-61c49d41-5338-4755-af54-06cee9fe4acb", VSERVER, "1464193655"); - apiEventValidationResults.add(new ValidationResult(entity)); + apiEventValidationResults.add(builder.build()); validationResultsMap.put(TESTDATA_EVENTTYPE_API, apiEventValidationResults); List<ValidationResult> namedQueryEventValidationResults = new ArrayList<>(); setUpEntityMock("20160525162737-61c49d41-5338-4755-af54-06cee9fe4acc", VSERVER, "1464193656"); - namedQueryEventValidationResults.add(new ValidationResult(entity)); + namedQueryEventValidationResults.add(builder.build()); validationResultsMap.put(TESTDATA_EVENTTYPE_NAMEDQUERY, namedQueryEventValidationResults); List<ValidationResult> messagePublishExceptionValidationResults = new ArrayList<>(); setUpEntityMock("instanceid1", "entitytype1", "resourceVersion1"); - messagePublishExceptionValidationResults.add(new ValidationResult(entity)); + messagePublishExceptionValidationResults.add(builder.build()); validationResultsMap.put(TESTDATA_VALIDATION_RESULT_PUBLISH_ERROR, messagePublishExceptionValidationResults); return validationResultsMap; } @Test - public void testExecuteForAAIEvent() throws Exception { + public void testExecuteForAaiEvent() throws Exception { // Test for AAI-EVENT validationController.execute(TESTDATA_EVENTTYPE_AAI, TEST); verify(ruleDrivenValidator, times(1)).validate(TESTDATA_EVENTTYPE_AAI); - verify(messagePublisher, times(2)).publishMessage(Mockito.contains( - "\"entityId\":{\"vserver-id\":\"20160525162737-61c49d41-5338-4755-af54-06cee9fe4aca\"},\"entityType\":\"vserver\",\"entityLink\":\"entityLink\",\"resourceVersion\":\"1464193654\",\"entity\":{},\"violations\":[]}")); + verify(messagePublisher, times(2)).publishMessage(Mockito + .contains("\"entityId\":{\"vserver-id\":\"20160525162737-61c49d41-5338-4755-af54-06cee9fe4aca\"}," + + "\"entityType\":\"vserver\",\"entityLink\":\"entityLink\"," + + "\"resourceVersion\":\"1464193654\",\"entity\":{},\"violations\":[]}")); } @Test - public void testExecuteForAPIEvent() throws Exception { + public void testExecuteForApiEvent() throws Exception { // Test for AAI-DATA-EXPORT-API validationController.execute(TESTDATA_EVENTTYPE_API, TEST); verify(ruleDrivenValidator, times(1)).validate(TESTDATA_EVENTTYPE_API); - verify(messagePublisher, times(1)).publishMessage(Mockito.contains( - "\"entityId\":{\"vserver-id\":\"20160525162737-61c49d41-5338-4755-af54-06cee9fe4acb\"},\"entityType\":\"vserver\",\"entityLink\":\"entityLink\",\"resourceVersion\":\"1464193655\",\"entity\":{},\"violations\":[]}")); + verify(messagePublisher, times(1)).publishMessage(Mockito + .contains("\"entityId\":{\"vserver-id\":\"20160525162737-61c49d41-5338-4755-af54-06cee9fe4acb\"}," + + "\"entityType\":\"vserver\",\"entityLink\":\"entityLink\"," + + "\"resourceVersion\":\"1464193655\",\"entity\":{},\"violations\":[]}")); } @Test - public void testExecuteForNQEvent() throws Exception { + public void testExecuteForNqEvent() throws Exception { // Test for AAI-DATA-EXPORT-NQ validationController.execute(TESTDATA_EVENTTYPE_NAMEDQUERY, TEST); verify(modelDrivenValidator, times(1)).validate(TESTDATA_EVENTTYPE_NAMEDQUERY); - verify(messagePublisher, times(1)).publishMessage(Mockito.contains( - "\"entityId\":{\"vserver-id\":\"20160525162737-61c49d41-5338-4755-af54-06cee9fe4acc\"},\"entityType\":\"vserver\",\"entityLink\":\"entityLink\",\"resourceVersion\":\"1464193656\",\"entity\":{},\"violations\":[]}")); + verify(messagePublisher, times(1)).publishMessage(Mockito + .contains("\"entityId\":{\"vserver-id\":\"20160525162737-61c49d41-5338-4755-af54-06cee9fe4acc\"}," + + "\"entityType\":\"vserver\",\"entityLink\":\"entityLink\"," + + "\"resourceVersion\":\"1464193656\",\"entity\":{},\"violations\":[]}")); } @Test @@ -332,26 +335,25 @@ public class TestValidationController { verify(ruleDrivenValidator, times(1)).validate(TESTDATA_EXCEPTION_EVENT); // @formatter:off - Violation violation = new Violation.Builder(entity) - .category("CANNOT_VALIDATE") - .severity("CRITICAL") - .violationType("NONE") - .errorMessage("Failed to validate") - .build(); - // @formatter:on + Violation violation = new Violation.Builder(entity) + .category("CANNOT_VALIDATE") + .severity("CRITICAL") + .violationType("NONE") + .errorMessage("Failed to validate") + .build(); + // @formatter:on JsonObject violationObject = new JsonParser().parse(violation.toString()).getAsJsonObject(); violationObject.remove("validationRule"); // Not set JsonObject validationResult = new JsonObject(); JsonObject entityIdObject = new JsonObject(); - JsonElement entity = new JsonObject(); entityIdObject.addProperty(primaryKey, value); validationResult.add(Violation.ENTITY_ID_PROPERTY, entityIdObject); validationResult.addProperty(Violation.ENTITY_TYPE_PROPERTY, "entitytype1"); validationResult.addProperty(ENTITY_LINK, ENTITY_LINK); validationResult.addProperty("resourceVersion", resourceVersion); - validationResult.add("entity", entity); + validationResult.add("entity", new JsonObject()); JsonArray violations = new JsonArray(); violations.add(violationObject); validationResult.add("violations", violations); @@ -376,12 +378,13 @@ public class TestValidationController { // This test is here for code coverage. validationController.execute(TESTDATA_VALIDATION_RESULT_PUBLISH_ERROR, TEST); verify(ruleDrivenValidator, times(1)).validate(TESTDATA_VALIDATION_RESULT_PUBLISH_ERROR); - verify(messagePublisher, times(1)).publishMessage(Mockito.contains( - "\"entityId\":{\"vserver-id\":\"instanceid1\"},\"entityType\":\"entitytype1\",\"entityLink\":\"entityLink\",\"resourceVersion\":\"resourceVersion1\",\"entity\":{},\"violations\":[]}")); + verify(messagePublisher, times(1)).publishMessage( + Mockito.contains("\"entityId\":{\"vserver-id\":\"instanceid1\"},\"entityType\":\"entitytype1\"," + + "\"entityLink\":\"entityLink\",\"resourceVersion\":\"resourceVersion1\"," + + "\"entity\":{},\"violations\":[]}")); } private void setUpEntityMock(String id, String type, String resourceVersion) throws ValidationServiceException { - when(eventReader.getEventReaderConfig()).thenReturn(new EventReaderConfig()); when(entity.getType()).thenReturn(type); EntityId entityId = new EntityId("vserver-id", id); when(entity.getIds()).thenReturn(Collections.singletonList(entityId)); diff --git a/src/test/java/org/onap/aai/validation/publisher/MockEventPublisher.java b/src/test/java/org/onap/aai/validation/publisher/MockEventPublisher.java index d1cfae0..f09f6d5 100644 --- a/src/test/java/org/onap/aai/validation/publisher/MockEventPublisher.java +++ b/src/test/java/org/onap/aai/validation/publisher/MockEventPublisher.java @@ -1,12 +1,12 @@ -/* +/** * ============LICENSE_START=================================================== - * Copyright (c) 2018 Amdocs + * Copyright (c) 2018-2019 European Software Marketing Ltd. * ============================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -17,15 +17,14 @@ */ package org.onap.aai.validation.publisher; -import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import java.io.IOException; import java.net.URISyntaxException; import java.util.Collection; import org.onap.aai.validation.exception.ValidationServiceException; -import org.onap.aai.validation.publisher.MessagePublisher; import org.onap.aai.validation.result.ValidationResult; +import org.onap.aai.validation.result.ValidationResultBuilder; import org.onap.aai.validation.test.util.TestEntity; import org.onap.aai.validation.test.util.ValidationResultIsEqual; @@ -54,8 +53,8 @@ public class MockEventPublisher implements MessagePublisher { @Override public void publishMessage(String message) throws ValidationServiceException { - ValidationResult validationResult = ValidationResult.fromJson(message); - assertThat(testDescription, validationResult, is(ValidationResultIsEqual.equalTo(expectedValidationResult))); + assertThat(testDescription, ValidationResultBuilder.fromJson(message), + ValidationResultIsEqual.equalTo(expectedValidationResult)); publishedMessage = true; } diff --git a/src/test/java/org/onap/aai/validation/result/TestValidationResult.java b/src/test/java/org/onap/aai/validation/result/TestValidationResult.java index 32f85fe..e262ef1 100644 --- a/src/test/java/org/onap/aai/validation/result/TestValidationResult.java +++ b/src/test/java/org/onap/aai/validation/result/TestValidationResult.java @@ -1,6 +1,6 @@ -/* +/** * ============LICENSE_START=================================================== - * Copyright (c) 2018-2019 Amdocs + * Copyright (c) 2018-2019 European Software Marketing Ltd. * ============================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -59,12 +59,16 @@ public class TestValidationResult { System.setProperty("APP_HOME", "."); } + private static final DateTimeFormatter formatter = + DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmssX").withZone(ZoneOffset.UTC); + @Inject private EventReader eventReader; private static String vserverEvent; private static Entity entity; + @BeforeClass public static void setUpBeforeClass() throws Exception { vserverEvent = TestUtil.getFileAsString(TestData.VSERVER.getFilename()); @@ -76,13 +80,19 @@ public class TestValidationResult { } enum TestData { - // @formatter:off - VSERVER ("validation-result/vserver-create-event.json"); + VSERVER( + "validation-result/vserver-create-event.json" + ); private String filename; - TestData(String filename) {this.filename = filename;} - public String getFilename() {return this.filename;} - // @formatter:on + + TestData(String filename) { + this.filename = filename; + } + + public String getFilename() { + return this.filename; + } } @Test @@ -96,8 +106,8 @@ public class TestValidationResult { ValidationResult transformedVr = toAndFromJson(validationResult); assertThatValidationResultIsValid(transformedVr); - Violation v = assertThatViolationIsValid(transformedVr, validationResult.getViolations().get(0)); - assertThat(v.getViolationDetails(), is(violationDetails)); + Violation violation = assertThatViolationIsValid(transformedVr, validationResult.getViolations().get(0)); + assertThat(violation.getViolationDetails(), is(violationDetails)); } @Test @@ -112,8 +122,8 @@ public class TestValidationResult { // Check assertThatValidationResultIsValid(transformedVr); - Violation v = assertThatViolationIsValid(transformedVr, validationResult.getViolations().get(0)); - assertThat(v.getViolationDetails(), is(violationDetails)); + Violation violation = assertThatViolationIsValid(transformedVr, validationResult.getViolations().get(0)); + assertThat(violation.getViolationDetails(), is(violationDetails)); } @Test @@ -128,8 +138,8 @@ public class TestValidationResult { // Check assertThatValidationResultIsValid(transformedVr); - Violation v = assertThatViolationIsValid(transformedVr, validationResult.getViolations().get(0)); - assertThat(v.getViolationDetails(), is(violationDetails)); + Violation violation = assertThatViolationIsValid(transformedVr, validationResult.getViolations().get(0)); + assertThat(violation.getViolationDetails(), is(violationDetails)); } @Test @@ -140,13 +150,13 @@ public class TestValidationResult { violationDetails.put("attr2", 2); ValidationResult validationResult = getValidationResult(violationDetails); - ValidationResult vr = toAndFromJson(validationResult); + ValidationResult transformedVr = toAndFromJson(validationResult); // Check - assertThatValidationResultIsValid(vr); - Violation v = assertThatViolationIsValid(vr, validationResult.getViolations().get(0)); - assertThat(v.getViolationDetails().get("attr1"), is(1.0)); - assertThat(v.getViolationDetails().get("attr2"), is(2.0)); + assertThatValidationResultIsValid(transformedVr); + Violation violation = assertThatViolationIsValid(transformedVr, validationResult.getViolations().get(0)); + assertThat(violation.getViolationDetails().get("attr1"), is(1.0)); + assertThat(violation.getViolationDetails().get("attr2"), is(2.0)); } @Test @@ -165,8 +175,8 @@ public class TestValidationResult { // Check assertThatValidationResultIsValid(transformedVr); - Violation v = assertThatViolationIsValid(transformedVr, validationResult.getViolations().get(0)); - String jsonDetails = v.getViolationDetails().get("attr1").toString(); + Violation violation = assertThatViolationIsValid(transformedVr, validationResult.getViolations().get(0)); + String jsonDetails = violation.getViolationDetails().get("attr1").toString(); JsonParser jsonParser = new JsonParser(); JsonElement jsonElement = jsonParser.parse(jsonDetails); assertThat(jsonObject, is(jsonElement)); @@ -174,13 +184,14 @@ public class TestValidationResult { @Test public void testCompareObjects() throws Exception { - ValidationResult validationResult = new ValidationResult(entity); + ValidationResultBuilder builder = new ValidationResultBuilder(eventReader, vserverEvent); + ValidationResult validationResult = builder.build(); assertThat(validationResult, is(not(equalTo(null)))); validationResult.setEntityId(new JsonObject()); assertThat(validationResult, is(not(equalTo(null)))); - ValidationResult other = new ValidationResult(entity); + ValidationResult other = builder.build(); assertThat(validationResult, is(not(equalTo(other)))); validationResult.setEntityType("type"); @@ -254,9 +265,12 @@ public class TestValidationResult { * Generate various violations using the supplied builders and assert the expected equality of the generated * Violation IDs whenever the values supplied to the builders are the same. * - * @param b1 a builder - * @param b2 another builder - * @param expectedResult whether or not the two builders should produce identical violations + * @param b1 + * a builder + * @param b2 + * another builder + * @param expectedResult + * whether or not the two builders should produce identical violations * @throws ValidationServiceException */ private void testViolationIdsForEquality(Builder b1, Builder b2, Boolean expectedResult) @@ -370,7 +384,7 @@ public class TestValidationResult { private ValidationResult getValidationResult(Map<String, Object> violationDetails) throws ValidationServiceException { - ValidationResult validationResult = new ValidationResult(entity); + ValidationResult validationResult = new ValidationResultBuilder(eventReader, vserverEvent).build(); //@formatter:off Violation violation = new Violation.Builder(entity) @@ -388,29 +402,29 @@ public class TestValidationResult { } private ValidationResult toAndFromJson(ValidationResult validationResult) { - return JsonUtil.toAnnotatedClassfromJson(validationResult.toJson(), ValidationResult.class); + return JsonUtil.toAnnotatedClassfromJson(validationResult.toJson(), ValidationResultImpl.class); } - private void assertThatValidationResultIsValid(ValidationResult vr) { - assertTrue("Expected valid UUID", isValidEventId(vr.getValidationId())); - assertIsValidTimestamp(vr.getValidationTimestamp()); + private void assertThatValidationResultIsValid(ValidationResult validationResult) { + assertTrue("Expected valid UUID", isValidEventId(validationResult.getValidationId())); + assertIsValidTimestamp(validationResult.getValidationTimestamp()); JsonObject expectedEntityId = new JsonObject(); expectedEntityId.addProperty("vserver-id", "example-vserver-id-val-34666"); - assertThat(vr.getEntityId(), is(expectedEntityId)); - assertThat(vr.getEntityType(), is("vserver")); - assertThat(vr.getResourceVersion(), is("1464193654")); - assertThat(vr.getEntityLink(), is( - "cloud-infrastructure/cloud-regions/cloud-region/region1/AAIregion1/tenants/tenant/example-tenant-id-val-88551/vservers/vserver/example-vserver-id-val-34666")); + assertThat(validationResult.getEntityId(), is(expectedEntityId)); + assertThat(validationResult.getEntityType(), is("vserver")); + assertThat(validationResult.getResourceVersion(), is("1464193654")); + assertThat(validationResult.getEntityLink(), is("cloud-infrastructure/cloud-regions/cloud-region/region1/" + + "AAIregion1/tenants/tenant/example-tenant-id-val-88551/vservers/vserver/example-vserver-id-val-34666")); } - private Violation assertThatViolationIsValid(ValidationResult vr, Violation expectedViolation) { - Violation v = vr.getViolations().get(0); - assertThat(v.getViolationId(), is(expectedViolation.getViolationId())); - assertThat(v.getCategory(), is("category")); - assertThat(v.getSeverity(), is("severity")); - assertThat(v.getViolationType(), is("violationType")); - assertThat(v.getErrorMessage(), is("errorMessage")); - return v; + private Violation assertThatViolationIsValid(ValidationResult validationResult, Violation expectedViolation) { + Violation violation = validationResult.getViolations().get(0); + assertThat(violation.getViolationId(), is(expectedViolation.getViolationId())); + assertThat(violation.getCategory(), is("category")); + assertThat(violation.getSeverity(), is("severity")); + assertThat(violation.getViolationType(), is("violationType")); + assertThat(violation.getErrorMessage(), is("errorMessage")); + return violation; } private void assertThatViolationsAreEqual(Violation v1, Violation v2, Boolean expectedResult) { @@ -429,14 +443,13 @@ public class TestValidationResult { private boolean isValidEventId(String eventId) { try { UUID.fromString(eventId); + return true; } catch (IllegalArgumentException exception) { return false; } - return true; } private void assertIsValidTimestamp(String date) { - DateTimeFormatter f = DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmssX").withZone(ZoneOffset.UTC); - Instant.from(f.parse(date)); + Instant.from(formatter.parse(date)); } } diff --git a/src/test/java/org/onap/aai/validation/ruledriven/rule/TestConfigurationLoader.java b/src/test/java/org/onap/aai/validation/ruledriven/rule/TestConfigurationLoader.java index f226252..a70d908 100644 --- a/src/test/java/org/onap/aai/validation/ruledriven/rule/TestConfigurationLoader.java +++ b/src/test/java/org/onap/aai/validation/ruledriven/rule/TestConfigurationLoader.java @@ -29,7 +29,6 @@ import org.junit.Test; import org.onap.aai.validation.reader.OxmReader; import org.onap.aai.validation.reader.data.AttributeValues; import org.onap.aai.validation.ruledriven.RuleDrivenValidator; -import org.onap.aai.validation.ruledriven.rule.Rule; public class TestConfigurationLoader { @@ -77,7 +76,7 @@ public class TestConfigurationLoader { // Find the trinity rule Rule trinityRule = null; - for (Rule rule : validator.getRulesForEntity("vserver", "aai-event")) { + for (Rule rule : validator.getRulesForEntity("vserver", "aai-event").get()) { if (rule.getName().contains("TRINITY") && rule.getName().contains("generic-vnf")) { trinityRule = rule; } diff --git a/src/test/java/org/onap/aai/validation/test/util/TestEntity.java b/src/test/java/org/onap/aai/validation/test/util/TestEntity.java index e42873a..b94a875 100644 --- a/src/test/java/org/onap/aai/validation/test/util/TestEntity.java +++ b/src/test/java/org/onap/aai/validation/test/util/TestEntity.java @@ -1,4 +1,4 @@ -/* +/** * ============LICENSE_START=================================================== * Copyright (c) 2018 Amdocs * ============================================================================ @@ -6,7 +6,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -25,6 +25,7 @@ import java.net.URISyntaxException; import java.nio.file.NoSuchFileException; import java.nio.file.Path; import org.onap.aai.validation.result.ValidationResult; +import org.onap.aai.validation.result.ValidationResultBuilder; public class TestEntity { @@ -44,6 +45,8 @@ public class TestEntity { } /** + * Fetch the expected JSON output from the test resources. + * * @return the contents of the file that stores the expected JSON, or an empty string if there is no expected JSON * @throws URISyntaxException * @throws IOException @@ -57,7 +60,7 @@ public class TestEntity { } public ValidationResult getExpectedValidationResult() throws JsonSyntaxException, URISyntaxException, IOException { - return ValidationResult.fromJson(getExpectedJson()); + return ValidationResultBuilder.fromJson(getExpectedJson()); } @Override @@ -79,10 +82,10 @@ public class TestEntity { } private String getErrorFileContents() throws URISyntaxException, IOException { - return TestUtil.getFileAsString(new URI(getErrorFileURI()).getPath()); + return TestUtil.getFileAsString(new URI(getErrorFileUri()).getPath()); } - private String getErrorFileURI() { + private String getErrorFileUri() { return expectedResultsFile.replaceAll("\\.exp\\.json$", ".error"); } } diff --git a/src/test/java/org/onap/aai/validation/test/util/ValidationResultIsEqual.java b/src/test/java/org/onap/aai/validation/test/util/ValidationResultIsEqual.java index aa6471f..2ef1e1e 100644 --- a/src/test/java/org/onap/aai/validation/test/util/ValidationResultIsEqual.java +++ b/src/test/java/org/onap/aai/validation/test/util/ValidationResultIsEqual.java @@ -1,4 +1,4 @@ -/* +/** * ============LICENSE_START=================================================== * Copyright (c) 2018 Amdocs * ============================================================================ @@ -6,7 +6,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -23,7 +23,7 @@ import org.hamcrest.Matcher; import org.onap.aai.validation.result.ValidationResult; /** - * Matcher for comparing actual and expected ValidationResults + * Matcher for comparing actual and expected ValidationResults. * */ public class ValidationResultIsEqual extends BaseMatcher<ValidationResult> { @@ -38,11 +38,11 @@ public class ValidationResultIsEqual extends BaseMatcher<ValidationResult> { } @Override - public boolean matches(Object o) { + public boolean matches(Object obj) { if (expected == null) { return false; } - ValidationResult actual = (ValidationResult) o; + ValidationResult actual = (ValidationResult) obj; return actual.getEntityId().equals(expected.getEntityId()) && // actual.getEntityType().equals(expected.getEntityType()) && // (actual.getEntityLink() == null ? "" : actual.getEntityLink()).equals(expected.getEntityLink()) && // |