diff options
author | Francis Toth <francis.toth@yoppworks.com> | 2020-07-10 07:48:56 -0400 |
---|---|---|
committer | Francis Toth <francis.toth@yoppworks.com> | 2020-07-10 07:57:42 -0400 |
commit | f2b425d077b4256ccdf2accab4e4e08186415ff6 (patch) | |
tree | 13f62aeed3be483dd03e93d6c8718a0912b7b4c7 /aai-schema-ingest/src/test | |
parent | c38fadd8e9ef0e14ea47b027bc44f5b32ca0d11d (diff) |
Fix minor sonar issues
Signed-off-by: Francis Toth <francis.toth@yoppworks.com>
Change-Id: Iea540bb663429d55ce90879f9d9a22888c583833
Issue-ID: AAI-2128
Diffstat (limited to 'aai-schema-ingest/src/test')
-rw-r--r-- | aai-schema-ingest/src/test/java/org/onap/aai/nodes/NodeIngestorLocalTest.java | 53 | ||||
-rw-r--r-- | aai-schema-ingest/src/test/java/org/onap/aai/nodes/NodeIngestorTest.java | 51 |
2 files changed, 55 insertions, 49 deletions
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; } } |