summaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap/aai/validation/ruledriven/validator/TestRuleDrivenValidator.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org/onap/aai/validation/ruledriven/validator/TestRuleDrivenValidator.java')
-rw-r--r--src/test/java/org/onap/aai/validation/ruledriven/validator/TestRuleDrivenValidator.java86
1 files changed, 54 insertions, 32 deletions
diff --git a/src/test/java/org/onap/aai/validation/ruledriven/validator/TestRuleDrivenValidator.java b/src/test/java/org/onap/aai/validation/ruledriven/validator/TestRuleDrivenValidator.java
index 643e2e3..27039a0 100644
--- a/src/test/java/org/onap/aai/validation/ruledriven/validator/TestRuleDrivenValidator.java
+++ b/src/test/java/org/onap/aai/validation/ruledriven/validator/TestRuleDrivenValidator.java
@@ -1,20 +1,24 @@
-/*
- * ============LICENSE_START===================================================
- * Copyright (c) 2018-2019 Amdocs
- * ============================================================================
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright (c) 2018-2019 AT&T Intellectual Property. All rights reserved.
+ * 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- * ============LICENSE_END=====================================================
+ * ============LICENSE_END=========================================================
*/
+
package org.onap.aai.validation.ruledriven.validator;
import static org.hamcrest.CoreMatchers.is;
@@ -24,11 +28,13 @@ import static org.hamcrest.MatcherAssert.assertThat;
import com.google.gson.JsonSyntaxException;
import java.io.IOException;
import java.net.URISyntaxException;
+import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.function.BiPredicate;
import java.util.stream.Stream;
@@ -36,6 +42,8 @@ import javax.inject.Inject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.aai.validation.exception.ValidationServiceException;
+import org.onap.aai.validation.reader.EventReader;
+import org.onap.aai.validation.reader.OxmReader;
import org.onap.aai.validation.result.ValidationResult;
import org.onap.aai.validation.ruledriven.RuleDrivenValidator;
import org.onap.aai.validation.test.util.TestEntity;
@@ -45,9 +53,9 @@ import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
-@TestPropertySource(locations = { "classpath:oxm-reader/schemaIngest.properties" })
-@ContextConfiguration(locations = {
- "classpath:" + TestRuleDrivenValidator.UNIT_TEST_FOLDER + "/test-rule-driven-validator-beans.xml" })
+@TestPropertySource(locations = {"classpath:oxm-reader/schemaIngest.properties"})
+@ContextConfiguration(
+ locations = {"classpath:" + TestRuleDrivenValidator.UNIT_TEST_FOLDER + "/test-rule-driven-validator-beans.xml"})
public class TestRuleDrivenValidator {
static {
@@ -60,16 +68,12 @@ public class TestRuleDrivenValidator {
@Inject
private RuleDrivenValidator validator;
- /**
- * @param testEntitiesPath
- * @param testEventsPath
- * @param resultsPath
- * @return all test entities
- * @throws URISyntaxException
- */
+ @Inject
+ private OxmReader oxmReader;
+
public static List<TestEntity> getEntities(String testEntitiesPath, String testEventsPath, String resultsPath)
throws URISyntaxException {
- Path testEvents = Paths.get(ClassLoader.getSystemResource(testEntitiesPath + testEventsPath).toURI());
+ Path testEvents = findResource(testEntitiesPath, testEventsPath);
BiPredicate<Path, BasicFileAttributes> jsonMatcher =
(path, basicFileAttributes) -> path.toFile().getName().matches(".*\\.json");
@@ -84,26 +88,44 @@ public class TestRuleDrivenValidator {
return entitiesList;
}
- /**
- * @throws ValidationServiceException
- * @throws JsonSyntaxException
- * @throws URISyntaxException
- * @throws IOException
- */
+ @Test
+ public void testInvalidRulesPath() throws ValidationServiceException, URISyntaxException {
+ validator = buildValidator(null, "/non-existent-folder");
+ validator.initialise();
+ }
+
+ @Test
+ public void testNoRulesFilesExist() throws ValidationServiceException, URISyntaxException {
+ validator = buildValidator(null, "/test_events");
+ validator.initialise();
+ }
+
+ @Test(expected = ValidationServiceException.class)
+ public void testEntityMissingFromOxm() throws ValidationServiceException, URISyntaxException {
+ validator = buildValidator(oxmReader, "/missing_oxm");
+ validator.initialise();
+ }
+
@Test
public void testValidateUnitTestInstances()
throws ValidationServiceException, JsonSyntaxException, URISyntaxException, IOException {
validateEntities(UNIT_TEST_FOLDER, TEST_EVENTS_PATH, "/results/expected");
}
- /**
- * @param inputEventsFolder
- * @param testEventsPath
- * @param resultsPath
- * @throws URISyntaxException
- * @throws ValidationServiceException
- * @throws IOException
- */
+ private static Path findResource(String path, String subPath) throws URISyntaxException {
+ URL resource = ClassLoader.getSystemResource(path + subPath);
+ if (resource == null) {
+ return Paths.get(path, subPath);
+ } else {
+ return Paths.get(resource.toURI());
+ }
+ }
+
+ private RuleDrivenValidator buildValidator(OxmReader oxmReader, String rulesFolder) throws URISyntaxException {
+ return new RuleDrivenValidator(Collections.singletonList(findResource(UNIT_TEST_FOLDER, rulesFolder)),
+ oxmReader, new EventReader(null, null, null), null);
+ }
+
private void validateEntities(String inputEventsFolder, String testEventsPath, String resultsPath)
throws URISyntaxException, ValidationServiceException, IOException {
for (TestEntity entity : getEntities(inputEventsFolder, testEventsPath, resultsPath)) {
@@ -111,7 +133,7 @@ public class TestRuleDrivenValidator {
assertThat(results.size(), is(1));
ValidationResult expectedResult = entity.getExpectedValidationResult();
if (expectedResult == null) {
- Path testEvents = Paths.get(ClassLoader.getSystemResource(inputEventsFolder + resultsPath).toURI());
+ Path testEvents = findResource(inputEventsFolder, resultsPath);
StringBuilder sb = new StringBuilder();
Files.walk(testEvents).forEach((path) -> sb.append(path).append("\n"));
assertThat("Expected results missing (" + entity.expectedResultsFile + ")\n" + sb.toString(),