From f2b425d077b4256ccdf2accab4e4e08186415ff6 Mon Sep 17 00:00:00 2001 From: Francis Toth Date: Fri, 10 Jul 2020 07:48:56 -0400 Subject: [PATCH] Fix minor sonar issues Signed-off-by: Francis Toth Change-Id: Iea540bb663429d55ce90879f9d9a22888c583833 Issue-ID: AAI-2128 --- .../java/org/onap/aai/rest/RestHandlerService.java | 11 ++--- .../serialization/engines/query/QueryEngine.java | 5 +- .../test/java/org/onap/aai/dbmap/AAIGraphTest.java | 6 +-- .../java/org/onap/aai/util/HbaseSaltPrefixer.java | 19 ++------ .../org/onap/aai/logging/LoggingContextTest.java | 8 ++-- .../java/org/onap/aai/restclient/ClientType.java | 11 +++-- .../java/org/onap/aai/schemaif/SchemaProvider.java | 48 ++++++++++---------- .../aai/schemaif/definitions/types/DataType.java | 16 +++---- .../aai/schemaif/json/SchemaServiceResponse.java | 17 +++---- .../onap/aai/schemaif/oxm/OxmSchemaProvider.java | 22 ++++----- .../org/onap/aai/nodes/NodeIngestorLocalTest.java | 53 ++++++++++++---------- .../java/org/onap/aai/nodes/NodeIngestorTest.java | 51 +++++++++++---------- 12 files changed, 127 insertions(+), 140 deletions(-) diff --git a/aai-core/src/main/java/org/onap/aai/rest/RestHandlerService.java b/aai-core/src/main/java/org/onap/aai/rest/RestHandlerService.java index aeb58c4b..e3ac2b26 100644 --- a/aai-core/src/main/java/org/onap/aai/rest/RestHandlerService.java +++ b/aai-core/src/main/java/org/onap/aai/rest/RestHandlerService.java @@ -1,4 +1,4 @@ -/** +/* * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ @@ -24,10 +24,9 @@ import java.util.concurrent.Executors; import java.util.concurrent.ThreadPoolExecutor; public class RestHandlerService { - private static RestHandlerService single_instance = null; + private static RestHandlerService singleInstance = null; public ThreadPoolExecutor executor; - // private constructor restricted to this class itself private RestHandlerService() { executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(50); } @@ -38,9 +37,9 @@ public class RestHandlerService { * @return single instance of RestHandlerService */ public static RestHandlerService getInstance() { - if (single_instance == null) { - single_instance = new RestHandlerService(); + if (singleInstance == null) { + singleInstance = new RestHandlerService(); } - return single_instance; + return singleInstance; } } diff --git a/aai-core/src/main/java/org/onap/aai/serialization/engines/query/QueryEngine.java b/aai-core/src/main/java/org/onap/aai/serialization/engines/query/QueryEngine.java index b250d8f3..41d97077 100644 --- a/aai-core/src/main/java/org/onap/aai/serialization/engines/query/QueryEngine.java +++ b/aai-core/src/main/java/org/onap/aai/serialization/engines/query/QueryEngine.java @@ -1,4 +1,4 @@ -/** +/* * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ @@ -34,7 +34,7 @@ import org.onap.aai.introspection.Loader; public abstract class QueryEngine { - final protected GraphTraversalSource g; + protected final GraphTraversalSource g; protected double dbTimeMsecs = 0; /** @@ -177,5 +177,4 @@ public abstract class QueryEngine { public abstract List findCousinsAsPath(Vertex start); public abstract double getDBTimeMsecs(); - } diff --git a/aai-core/src/test/java/org/onap/aai/dbmap/AAIGraphTest.java b/aai-core/src/test/java/org/onap/aai/dbmap/AAIGraphTest.java index f2c7b27c..cc420018 100644 --- a/aai-core/src/test/java/org/onap/aai/dbmap/AAIGraphTest.java +++ b/aai-core/src/test/java/org/onap/aai/dbmap/AAIGraphTest.java @@ -1,4 +1,4 @@ -/** +/* * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ @@ -55,7 +55,7 @@ public class AAIGraphTest extends AAISetup { } @Test - public void getRealtimeInstanceConnectionName() throws Exception { + public void getRealtimeInstanceConnectionName() { JanusGraphManagement graphMgt = AAIGraph.getInstance().getGraph().openManagement(); String connectionInstanceName = @@ -96,7 +96,7 @@ public class AAIGraphTest extends AAISetup { @Ignore("Need to create schema specific to the test") @Test - public void checkIndexOfAliasedIndexedProps() throws Exception { + public void checkIndexOfAliasedIndexedProps() { Set aliasedIndexedProps = getAliasedIndexedProps(); JanusGraphManagement graphMgt = AAIGraph.getInstance().getGraph().openManagement(); for (String aliasedIndexedProp : aliasedIndexedProps) { diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/util/HbaseSaltPrefixer.java b/aai-els-onap-logging/src/main/java/org/onap/aai/util/HbaseSaltPrefixer.java index fef10a77..95f9c1b7 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/aai/util/HbaseSaltPrefixer.java +++ b/aai-els-onap-logging/src/main/java/org/onap/aai/util/HbaseSaltPrefixer.java @@ -1,4 +1,4 @@ -/** +/* * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ @@ -27,33 +27,20 @@ package org.onap.aai.util; * as these keys are generated in a couple places, I made a class to contain that logic */ public class HbaseSaltPrefixer { - private int NUM_REGION_BUCKETS = 3; // the number of hbase region servers per cluster + // the number of hbase region servers per cluster + private static int NUM_REGION_BUCKETS = 3; private static class SingletonHolder { private static final HbaseSaltPrefixer INSTANCE = new HbaseSaltPrefixer(); } - /** - * Instantiates a new hbase salt prefixer. - */ private HbaseSaltPrefixer() { } - /** - * Gets the single instance of HbaseSaltPrefixer. - * - * @return single instance of HbaseSaltPrefixer - */ public static HbaseSaltPrefixer getInstance() { return SingletonHolder.INSTANCE; } - /** - * Prepend salt. - * - * @param key the key - * @return the string - */ public String prependSalt(String key) { int salt = Math.abs(key.hashCode()) % NUM_REGION_BUCKETS; return salt + "-" + key; diff --git a/aai-els-onap-logging/src/test/java/org/onap/aai/logging/LoggingContextTest.java b/aai-els-onap-logging/src/test/java/org/onap/aai/logging/LoggingContextTest.java index 245840bc..4fe60315 100644 --- a/aai-els-onap-logging/src/test/java/org/onap/aai/logging/LoggingContextTest.java +++ b/aai-els-onap-logging/src/test/java/org/onap/aai/logging/LoggingContextTest.java @@ -1,4 +1,4 @@ -/** +/* * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ @@ -39,7 +39,7 @@ public class LoggingContextTest { LoggingContext.elapsedTime(300, TimeUnit.MILLISECONDS); assertEquals(MDC.get(LoggingContext.LoggingField.ELAPSED_TIME.toString()), "300"); LoggingContext.init(); - assertTrue(MDC.get(LoggingContext.LoggingField.ELAPSED_TIME.toString()) == null); + assertNull(MDC.get(LoggingContext.LoggingField.ELAPSED_TIME.toString())); } @Test public void stopWatchTest() { @@ -60,7 +60,7 @@ public class LoggingContextTest { assertEquals(testServiceName, MDC.get(LoggingContext.LoggingField.SERVICE_NAME.toString())); LoggingContext.clear(); - assertTrue(MDC.get(LoggingContext.LoggingField.SERVICE_NAME.toString()) == null); + assertNull(MDC.get(LoggingContext.LoggingField.SERVICE_NAME.toString())); } @@ -71,7 +71,7 @@ public class LoggingContextTest { assertEquals(testServiceName, MDC.get(LoggingContext.LoggingField.SERVICE_NAME.toString())); LoggingContext.remove(LoggingContext.LoggingField.SERVICE_NAME.toString()); - assertTrue(MDC.get(LoggingContext.LoggingField.SERVICE_NAME.toString()) == null); + assertNull(MDC.get(LoggingContext.LoggingField.SERVICE_NAME.toString())); } diff --git a/aai-rest/src/main/java/org/onap/aai/restclient/ClientType.java b/aai-rest/src/main/java/org/onap/aai/restclient/ClientType.java index 4633b425..9ca9a7c2 100644 --- a/aai-rest/src/main/java/org/onap/aai/restclient/ClientType.java +++ b/aai-rest/src/main/java/org/onap/aai/restclient/ClientType.java @@ -1,4 +1,4 @@ -/** +/* * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ @@ -7,9 +7,9 @@ * 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. @@ -22,4 +22,7 @@ package org.onap.aai.restclient; public class ClientType { public static final String AAI = "aai-rest-client"; + + private ClientType() { + } } diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/SchemaProvider.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/SchemaProvider.java index 1e798196..5aa8d688 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/SchemaProvider.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/SchemaProvider.java @@ -21,77 +21,75 @@ package org.onap.aai.schemaif; -import java.util.List; -import java.util.Map; -import java.util.Set; - import org.onap.aai.schemaif.definitions.EdgeSchema; import org.onap.aai.schemaif.definitions.VertexSchema; +import java.util.Map; +import java.util.Set; + public interface SchemaProvider { - + /** * Load the schema into memory */ - public void loadSchema() throws SchemaProviderException; - + void loadSchema() throws SchemaProviderException; + /** * Get the identifier for the more recent version of the schema * * @return The schema version identifier */ - public String getLatestSchemaVersion() throws SchemaProviderException; - + String getLatestSchemaVersion() throws SchemaProviderException; + /** * Get the schema definition for a vertex * * @param vertexName - Name of the vertex * @param schemaVersion - Version of the schema to use - * + * * @return The vertex schema definition */ - public VertexSchema getVertexSchema(String vertexName, String schemaVersion) throws SchemaProviderException; - + VertexSchema getVertexSchema(String vertexName, String schemaVersion) throws SchemaProviderException; + /** * Get the schema definition for an edge * * @param edgeType - Type of the edge * @param sourceVertex - The source vertex for the edge * @param targetVertex - The target vertex for the edge - * @param schemaVersion - Version of the schema to use - * + * @param version - Version of the schema to use + * * @return The edge schema definition */ - public EdgeSchema getEdgeSchema(String edgeType, String sourceVertex, String targetVertex, String version) throws SchemaProviderException; + EdgeSchema getEdgeSchema(String edgeType, String sourceVertex, String targetVertex, String version) throws SchemaProviderException; /** * Get the list of edge definitions which are adjacent to the given vertex * * @param vertexType - Type of the vertex - * @param schemaVersion - Version of the schema to use - * + * @param version - Version of the schema to use + * * @return The list of edge schema definitions */ - public Set getAdjacentEdgeSchema(String vertexType, String version) throws SchemaProviderException; - + Set getAdjacentEdgeSchema(String vertexType, String version) throws SchemaProviderException; + /** * Get the list of edge definitions which are valid for the given source and target * * @param sourceType - Type of the source vertex * @param targetType - Type of the target vertex - * @param schemaVersion - Version of the schema to use - * + * @param version - Version of the schema to use + * * @return The list of edge schema definitions */ - public Set getEdgeSchemaForSourceTarget(String sourceType, String targetType, String version) throws SchemaProviderException; + Set getEdgeSchemaForSourceTarget(String sourceType, String targetType, String version) throws SchemaProviderException; /** * Get vertex map for a schema version * * @param schemaVersion - Version of the schema to use - * + * * @return The list of vertex types */ - public Map getVertexMap(String schemaVersion) throws SchemaProviderException; - + Map getVertexMap(String schemaVersion) throws SchemaProviderException; } diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/DataType.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/DataType.java index a0586037..2e2884b4 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/DataType.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/definitions/types/DataType.java @@ -1,4 +1,4 @@ -/** +/* * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ @@ -21,11 +21,9 @@ package org.onap.aai.schemaif.definitions.types; -import org.onap.aai.schemaif.SchemaProviderException; - public abstract class DataType { public enum Type { - STRING, + STRING, BOOL, INT, LONG, @@ -34,9 +32,9 @@ public abstract class DataType { MAP, COMPLEX } - - private Type type; - + + private final Type type; + public DataType(Type type) { this.type = type; } @@ -44,9 +42,9 @@ public abstract class DataType { public Type getType() { return type; } - + public abstract Object validateValue(String value); - + public String toString() { return getType().toString(); } diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/SchemaServiceResponse.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/SchemaServiceResponse.java index 7fa123a5..0bc1760b 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/SchemaServiceResponse.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/SchemaServiceResponse.java @@ -1,4 +1,4 @@ -/** +/* * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ @@ -20,26 +20,24 @@ */ package org.onap.aai.schemaif.json; -import org.onap.aai.schemaif.SchemaProviderException; -import org.onap.aai.schemaif.json.definitions.JsonSchema; - import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import com.google.gson.JsonObject; import com.google.gson.annotations.SerializedName; +import org.onap.aai.schemaif.SchemaProviderException; +import org.onap.aai.schemaif.json.definitions.JsonSchema; public class SchemaServiceResponse { public static final String SCHEMA_TYPE_OXM = "oxm"; public static final String SCHEMA_TYPE_JSON = "json"; - + private static final Gson gson = new GsonBuilder().create(); @SerializedName("schema-version") private String version; - + @SerializedName("schema-content") private JsonSchema data; - + public String getVersion() { return version; } @@ -57,11 +55,10 @@ public class SchemaServiceResponse { if (json == null || json.isEmpty()) { throw new SchemaProviderException("Empty schema-service response"); } - + return gson.fromJson(json, SchemaServiceResponse.class); } catch (Exception ex) { throw new SchemaProviderException("Invalid response from schema service: " + ex.getMessage()); } } - } diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/oxm/OxmSchemaProvider.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/oxm/OxmSchemaProvider.java index 0ad8bf45..bced602c 100644 --- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/oxm/OxmSchemaProvider.java +++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/oxm/OxmSchemaProvider.java @@ -1,4 +1,4 @@ -/** +/* * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ @@ -40,7 +40,7 @@ public class OxmSchemaProvider implements SchemaProvider { OxmEdgeRulesLoader.loadModels(); OxmSchemaLoader.loadModels(); } - + @Override public String getLatestSchemaVersion() throws SchemaProviderException { return OxmSchemaLoader.getLatestVersion(); @@ -72,41 +72,41 @@ public class OxmSchemaProvider implements SchemaProvider { if (edgeRule == null) { return null; } - + FromOxmEdgeSchema es = new FromOxmEdgeSchema(); es.fromEdgeRule(edgeRule); - + return es; } @Override public Set getAdjacentEdgeSchema(String vertexType, String version) throws SchemaProviderException { RelationshipSchema relSchema = OxmEdgeRulesLoader.getSchemaForVersion(version); - Set edges = new HashSet(); + Set edges = new HashSet<>(); List rules = relSchema.lookupAdjacentEdges(vertexType); - + for (EdgeRule rule : rules) { FromOxmEdgeSchema es = new FromOxmEdgeSchema(); es.fromEdgeRule(rule); edges.add(es); } - + return edges; } - + @Override public Set getEdgeSchemaForSourceTarget(String sourceType, String targetType, String version) throws SchemaProviderException { RelationshipSchema relSchema = OxmEdgeRulesLoader.getSchemaForVersion(version); - Set edges = new HashSet(); + Set edges = new HashSet<>(); Set relTypes = relSchema.getValidRelationTypes(sourceType, targetType); - + for (String type : relTypes) { EdgeSchema edgeSchema = getEdgeSchema(type, sourceType, targetType, version); if (edgeSchema != null) { edges.add(edgeSchema); } } - + return edges; } diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/nodes/NodeIngestorLocalTest.java b/aai-schema-ingest/src/test/java/org/onap/aai/nodes/NodeIngestorLocalTest.java index dca21f2d..83d7dc44 100644 --- a/aai-schema-ingest/src/test/java/org/onap/aai/nodes/NodeIngestorLocalTest.java +++ b/aai-schema-ingest/src/test/java/org/onap/aai/nodes/NodeIngestorLocalTest.java @@ -1,4 +1,4 @@ -/** +/* * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ @@ -20,18 +20,6 @@ package org.onap.aai.nodes; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.*; - -import java.io.*; -import java.nio.file.Files; -import java.nio.file.Paths; - -import javax.xml.bind.SchemaOutputResolver; -import javax.xml.transform.*; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; - import org.eclipse.persistence.dynamic.DynamicEntity; import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext; import org.junit.Rule; @@ -39,7 +27,6 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.onap.aai.config.NodesConfiguration; -import org.onap.aai.restclient.MockProvider; import org.onap.aai.setup.SchemaVersion; import org.onap.aai.testutils.TestUtilConfigTranslator; import org.springframework.beans.factory.annotation.Autowired; @@ -47,10 +34,29 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringRunner; import org.w3c.dom.Document; +import javax.xml.bind.SchemaOutputResolver; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Result; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.nio.file.Files; +import java.nio.file.Paths; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.*; + @RunWith(SpringRunner.class) @TestPropertySource( properties = { @@ -69,7 +75,7 @@ public class NodeIngestorLocalTest { @Autowired NodeIngestor nodeIngestor; - public static void printDocument(Document doc, OutputStream out) throws IOException, TransformerException { + public static void printDocument(Document doc, OutputStream out) throws TransformerException { TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); @@ -78,7 +84,7 @@ public class NodeIngestorLocalTest { transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); - transformer.transform(new DOMSource(doc), new StreamResult(new OutputStreamWriter(out, "UTF-8"))); + transformer.transform(new DOMSource(doc), new StreamResult(new OutputStreamWriter(out, UTF_8))); } @Test @@ -89,12 +95,12 @@ public class NodeIngestorLocalTest { DynamicEntity foo10 = ctx10.newDynamicEntity("Foo"); foo10.set("fooId", "bar"); - assertTrue("bar".equals(foo10.get("fooId"))); + assertEquals("bar", foo10.get("fooId")); // should work bc Bar is valid in test_business_v10 schema DynamicEntity bar10 = ctx10.newDynamicEntity("Bar"); bar10.set("barId", "bar2"); - assertTrue("bar2".equals(bar10.get("barId"))); + assertEquals("bar2", bar10.get("barId")); XSDOutputResolver outputResolver10 = new XSDOutputResolver(); ctx10.generateSchema(outputResolver10); @@ -103,11 +109,11 @@ public class NodeIngestorLocalTest { // should work bc Foo.quantity is valid in test_network_v11 schema DynamicEntity foo11 = ctx11.newDynamicEntity("Foo"); foo11.set("quantity", "12"); - assertTrue("12".equals(foo11.get("quantity"))); + assertEquals("12", foo11.get("quantity")); DynamicEntity quux11 = ctx11.newDynamicEntity("Quux"); quux11.set("qManagerName", "some guy"); - assertTrue("some guy".equals(quux11.get("qManagerName"))); + assertEquals("some guy", quux11.get("qManagerName")); XSDOutputResolver outputResolver11 = new XSDOutputResolver(); ctx11.generateSchema(outputResolver11); @@ -126,19 +132,16 @@ public class NodeIngestorLocalTest { @Test public void testGetVersionFromClassName() { assertEquals(nodeIngestor.getVersionFromClassName("inventory.aai.onap.org.v13.Evc"), new SchemaVersion("v13")); - } @Test public void testGetVersionFromClassNameNull() { assertEquals(nodeIngestor.getVersionFromClassName("blah"), new SchemaVersion("v15")); - } @Test public void testGetObjectsInVersion() { assertEquals(nodeIngestor.getObjectsInVersion(new SchemaVersion("v13")).size(), 148); - } @Test @@ -155,7 +158,7 @@ public class NodeIngestorLocalTest { assertThat("OXM:\n" + expected, expected, is(content)); } - private class XSDOutputResolver extends SchemaOutputResolver { + private static class XSDOutputResolver extends SchemaOutputResolver { @Override public Result createOutput(String namespaceUri, String suggestedFileName) throws IOException { diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/nodes/NodeIngestorTest.java b/aai-schema-ingest/src/test/java/org/onap/aai/nodes/NodeIngestorTest.java index dc4e1e46..b70b1bfc 100644 --- a/aai-schema-ingest/src/test/java/org/onap/aai/nodes/NodeIngestorTest.java +++ b/aai-schema-ingest/src/test/java/org/onap/aai/nodes/NodeIngestorTest.java @@ -1,4 +1,4 @@ -/** +/* * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ @@ -20,18 +20,6 @@ package org.onap.aai.nodes; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.*; - -import java.io.*; -import java.nio.file.Files; -import java.nio.file.Paths; - -import javax.xml.bind.SchemaOutputResolver; -import javax.xml.transform.*; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; - import org.eclipse.persistence.dynamic.DynamicEntity; import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext; import org.junit.Rule; @@ -49,6 +37,26 @@ import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.w3c.dom.Document; +import javax.xml.bind.SchemaOutputResolver; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Result; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.nio.file.Files; +import java.nio.file.Paths; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.*; + @RunWith(SpringJUnit4ClassRunner.class) @TestPropertySource( properties = { @@ -76,12 +84,12 @@ public class NodeIngestorTest { DynamicEntity foo10 = ctx10.newDynamicEntity("Foo"); foo10.set("fooId", "bar"); - assertTrue("bar".equals(foo10.get("fooId"))); + assertEquals("bar", foo10.get("fooId")); // should work bc Bar is valid in test_business_v10 schema DynamicEntity bar10 = ctx10.newDynamicEntity("Bar"); bar10.set("barId", "bar2"); - assertTrue("bar2".equals(bar10.get("barId"))); + assertEquals("bar2", bar10.get("barId")); XSDOutputResolver outputResolver10 = new XSDOutputResolver(); ctx10.generateSchema(outputResolver10); @@ -90,11 +98,11 @@ public class NodeIngestorTest { // should work bc Foo.quantity is valid in test_network_v11 schema DynamicEntity foo11 = ctx11.newDynamicEntity("Foo"); foo11.set("quantity", "12"); - assertTrue("12".equals(foo11.get("quantity"))); + assertEquals("12", foo11.get("quantity")); DynamicEntity quux11 = ctx11.newDynamicEntity("Quux"); quux11.set("qManagerName", "some guy"); - assertTrue("some guy".equals(quux11.get("qManagerName"))); + assertEquals("some guy", quux11.get("qManagerName")); XSDOutputResolver outputResolver11 = new XSDOutputResolver(); ctx11.generateSchema(outputResolver11); @@ -154,24 +162,19 @@ public class NodeIngestorTest { transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); - transformer.transform(new DOMSource(doc), new StreamResult(new OutputStreamWriter(out, "UTF-8"))); + transformer.transform(new DOMSource(doc), new StreamResult(new OutputStreamWriter(out, UTF_8))); } - private class XSDOutputResolver extends SchemaOutputResolver { + private static class XSDOutputResolver extends SchemaOutputResolver { @Override public Result createOutput(String namespaceUri, String suggestedFileName) throws IOException { - - // create new file - // create stream result File temp = File.createTempFile("schema", ".xsd"); StreamResult result = new StreamResult(temp); System.out.println("Schema file: " + temp.getAbsolutePath()); - // set system id result.setSystemId(temp.toURI().toURL().toString()); - // return result return result; } } -- 2.16.6