diff options
author | Tian Lee <TianL@amdocs.com> | 2019-03-12 11:18:12 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-03-12 11:18:12 +0000 |
commit | 9296c447784848703e043b7ac3d32b4385d03d0f (patch) | |
tree | 59c616a97eb26f00191db18320a987bef5dea7f1 | |
parent | 26531322fa59f89c9e3c670206f2349e2ac4de90 (diff) | |
parent | a92189c6161f7bb8494cb8ea519885533bc34f53 (diff) |
Merge "Increase code coverage to 55% for Dublin"
-rw-r--r-- | src/main/java/org/onap/aai/spike/schema/OxmConfigTranslator.java | 101 | ||||
-rw-r--r-- | src/test/java/org/onap/aai/spike/event/incoming/GizmoGraphEventTest.java | 38 |
2 files changed, 38 insertions, 101 deletions
diff --git a/src/main/java/org/onap/aai/spike/schema/OxmConfigTranslator.java b/src/main/java/org/onap/aai/spike/schema/OxmConfigTranslator.java deleted file mode 100644 index 389781f..0000000 --- a/src/main/java/org/onap/aai/spike/schema/OxmConfigTranslator.java +++ /dev/null @@ -1,101 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * ================================================================================ - * 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 - * - * 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========================================================= - */ -package org.onap.aai.spike.schema; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.PathMatcher; -import java.nio.file.Paths; -import java.util.List; -import java.util.Map; -import java.util.ServiceConfigurationError; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.onap.aai.setup.ConfigTranslator; -import org.onap.aai.setup.SchemaLocationsBean; -import org.onap.aai.setup.SchemaVersion; -import org.onap.aai.setup.SchemaVersions; - -public class OxmConfigTranslator extends ConfigTranslator { - public OxmConfigTranslator(SchemaLocationsBean bean, SchemaVersions schemaVersions) { - super(bean, schemaVersions); - } - - @Override - public Map<SchemaVersion, List<String>> getNodeFiles() { - String nodeDirectory = bean.getNodeDirectory(); - if (nodeDirectory == null) { - throw new ServiceConfigurationError( - "Node(s) directory is empty in the schema location bean (" + bean.getSchemaConfigLocation() + ")"); - } - try { - return getVersionMap(Paths.get(nodeDirectory), "*_v*.xml"); - } catch (IOException e) { - throw new ServiceConfigurationError("Failed to read node(s) directory " + getPath(nodeDirectory), e); - } - } - - @Override - public Map<SchemaVersion, List<String>> getEdgeFiles() { - String edgeDirectory = bean.getEdgeDirectory(); - if (edgeDirectory == null) { - throw new ServiceConfigurationError( - "Edge(s) directory is empty in the schema location bean (" + bean.getSchemaConfigLocation() + ")"); - } - try { - return getVersionMap(Paths.get(edgeDirectory), "*_v*.json"); - } catch (IOException e) { - throw new ServiceConfigurationError("Failed to read edge(s) directory " + getPath(edgeDirectory), e); - } - } - - private String getPath(String nodeDirectory) { - return Paths.get(nodeDirectory).toAbsolutePath().toString(); - } - - /** - * Creates a map containing each OXM Version and the matching OXM file path(s) - * - * @param folderPath the folder/directory containing the OXM files - * @param fileSuffix - * @return a new Map object (may be empty) - * @throws IOException if there is a problem reading the specified directory path - */ - private Map<SchemaVersion, List<String>> getVersionMap(Path folderPath, String globPattern) throws IOException { - final PathMatcher filter = folderPath.getFileSystem().getPathMatcher("glob:**/" + globPattern); - try (final Stream<Path> stream = Files.list(folderPath)) { - return stream.filter(filter::matches).map(Path::toString).filter(p -> getVersionFromPath(p) != null) - .collect(Collectors.groupingBy(this::getVersionFromPath)); - } - } - - private SchemaVersion getVersionFromPath(String pathName) { - String version = "V" + pathName.replaceAll("^.*\\/", "").replaceAll("\\D+", ""); - try { - SchemaVersion schemaVersion = schemaVersions.getVersions().stream() - .filter(s -> s.toString().equalsIgnoreCase(version)).findAny().orElse(null); - return schemaVersion; - } catch (IllegalArgumentException e) { - return null; - } - } -} diff --git a/src/test/java/org/onap/aai/spike/event/incoming/GizmoGraphEventTest.java b/src/test/java/org/onap/aai/spike/event/incoming/GizmoGraphEventTest.java index 87b298f..49fb5ef 100644 --- a/src/test/java/org/onap/aai/spike/event/incoming/GizmoGraphEventTest.java +++ b/src/test/java/org/onap/aai/spike/event/incoming/GizmoGraphEventTest.java @@ -24,7 +24,10 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import java.io.IOException; import java.net.URISyntaxException; + +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.mockito.junit.MockitoJUnitRunner; import org.onap.aai.spike.OXMModelLoaderSetup; @@ -36,6 +39,11 @@ import org.onap.aai.spike.test.util.TestFileReader; @RunWith(MockitoJUnitRunner.Silent.class) public class GizmoGraphEventTest extends OXMModelLoaderSetup { + private static final String SPIKE_EXCEPTION_MESSAGE = "Unable to parse JSON string: Empty or null JSON string."; + + @Rule + public ExpectedException exceptionRule = ExpectedException.none(); + @Test public void TestToSpikeGraphEvent() throws SpikeException, IOException, URISyntaxException { String champNotification = @@ -63,6 +71,8 @@ public class GizmoGraphEventTest extends OXMModelLoaderSetup { gizmoGraphEvent = new GizmoGraphEvent(); GizmoEdge relationship = new GizmoEdge(); + relationship.setSource(vertex); + relationship.setTarget(vertex); relationship.setId("909d"); gizmoGraphEvent.setRelationship(relationship); @@ -99,4 +109,32 @@ public class GizmoGraphEventTest extends OXMModelLoaderSetup { objectType = gizmoGraphEvent.getObjectType(); assertNull(objectType); } + + @Test + public void TestGizmoEdgeExceptionEmpty() throws SpikeException { + exceptionRule.expect(SpikeException.class); + exceptionRule.expectMessage(SPIKE_EXCEPTION_MESSAGE); + GizmoEdge.fromJson(""); + } + + @Test + public void TestGizmoEdgeExceptionNull() throws SpikeException { + exceptionRule.expect(SpikeException.class); + exceptionRule.expectMessage(SPIKE_EXCEPTION_MESSAGE); + GizmoEdge.fromJson(null); + } + + @Test + public void TestGizmoVertexExceptionEmpty() throws SpikeException { + exceptionRule.expect(SpikeException.class); + exceptionRule.expectMessage(SPIKE_EXCEPTION_MESSAGE); + GizmoVertex.fromJson(""); + } + + @Test + public void TestGizmoVertexExceptionNull() throws SpikeException { + exceptionRule.expect(SpikeException.class); + exceptionRule.expectMessage(SPIKE_EXCEPTION_MESSAGE); + GizmoVertex.fromJson(null); + } } |