diff options
author | Dominic Lunanuova <dgl@research.att.com> | 2019-05-08 13:53:03 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-05-08 13:53:03 +0000 |
commit | 9a8bdf20dbaf2f7e5ad473a60f9b083505ad908c (patch) | |
tree | a301b5977901f7e5c31ae6ef88541f3f65e915d7 /src | |
parent | d2bbcddda062c7e0737b7311490b05e3d8d0fe4f (diff) | |
parent | f4088bd4e2a872f5a10b58df00d6811351f8c265 (diff) |
Merge "Fix sonar issues in dmaap-dbcpi"
Diffstat (limited to 'src')
8 files changed, 77 insertions, 63 deletions
diff --git a/src/main/java/org/onap/dmaap/dbcapi/database/DatabaseClass.java b/src/main/java/org/onap/dmaap/dbcapi/database/DatabaseClass.java index c853782..14bacc4 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/database/DatabaseClass.java +++ b/src/main/java/org/onap/dmaap/dbcapi/database/DatabaseClass.java @@ -109,7 +109,7 @@ public class DatabaseClass extends BaseLoggingClass { break; } - dmaap.init(new Dmaap("0", "", "", "", "", "", "", "")); + dmaap.init(new Dmaap.DmaapBuilder().setVer("0").setTnr("").setDn("").setDpu("").setLu("").setBat("").setNk("").setAko("").createDmaap()); // force initial read from DB, if it exists @SuppressWarnings("unused") Dmaap dmx = dmaap.get(); diff --git a/src/main/java/org/onap/dmaap/dbcapi/model/Dmaap.java b/src/main/java/org/onap/dmaap/dbcapi/model/Dmaap.java index ba7fd42..96248f3 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/model/Dmaap.java +++ b/src/main/java/org/onap/dmaap/dbcapi/model/Dmaap.java @@ -22,8 +22,6 @@ package org.onap.dmaap.dbcapi.model; import javax.xml.bind.annotation.XmlRootElement; -import org.apache.log4j.Logger; - @XmlRootElement public class Dmaap extends DmaapObject { @@ -42,26 +40,74 @@ public class Dmaap extends DmaapObject { } - public Dmaap( String ver, - String tnr, - String dn, - String dpu, - String lu, - String bat, - String nk, - String ako ) { - this.version = ver; - this.topicNsRoot = tnr; - this.dmaapName = dn; - this.drProvUrl = dpu; - this.bridgeAdminTopic = bat; - this.loggingUrl = lu; - this.nodeKey = nk; - this.accessKeyOwner = ako; + public Dmaap( DmaapBuilder builder ) { + this.version = builder.ver; + this.topicNsRoot = builder.tnr; + this.dmaapName = builder.dn; + this.drProvUrl = builder.dpu; + this.bridgeAdminTopic = builder.bat; + this.loggingUrl = builder.lu; + this.nodeKey = builder.nk; + this.accessKeyOwner = builder.ako; this.setStatus( DmaapObject_Status.NEW ); } + public static class DmaapBuilder { + private String ver; + private String tnr; + private String dn; + private String dpu; + private String lu; + private String bat; + private String nk; + private String ako; + + public DmaapBuilder setVer(String ver) { + this.ver = ver; + return this; + } + + public DmaapBuilder setTnr(String tnr) { + this.tnr = tnr; + return this; + } + + public DmaapBuilder setDn(String dn) { + this.dn = dn; + return this; + } + + public DmaapBuilder setDpu(String dpu) { + this.dpu = dpu; + return this; + } + + public DmaapBuilder setLu(String lu) { + this.lu = lu; + return this; + } + + public DmaapBuilder setBat(String bat) { + this.bat = bat; + return this; + } + + public DmaapBuilder setNk(String nk) { + this.nk = nk; + return this; + } + + public DmaapBuilder setAko(String ako) { + this.ako = ako; + return this; + } + + public Dmaap createDmaap() { + return new Dmaap(this); + } + } + public String getVersion() { return version; } diff --git a/src/test/java/org/onap/dmaap/dbcapi/database/DBMapTest.java b/src/test/java/org/onap/dmaap/dbcapi/database/DBMapTest.java index 338479d..abd4aee 100644 --- a/src/test/java/org/onap/dmaap/dbcapi/database/DBMapTest.java +++ b/src/test/java/org/onap/dmaap/dbcapi/database/DBMapTest.java @@ -19,19 +19,14 @@ */ package org.onap.dmaap.dbcapi.database; -import org.onap.dmaap.dbcapi.database.DBMap; -import org.onap.dmaap.dbcapi.database.DBSingleton; import org.onap.dmaap.dbcapi.model.*; import org.onap.dmaap.dbcapi.testframework.ReflectionHarness; import org.onap.dmaap.dbcapi.util.Singleton; -import static org.junit.Assert.*; - import org.junit.After; import org.junit.Before; import org.junit.Test; import java.util.*; -import java.sql.*; public class DBMapTest { @@ -72,7 +67,7 @@ public class DBMapTest { public void test3() { try { dmaap = new DBSingleton<Dmaap>(Dmaap.class, "dmaap"); - Dmaap nd = new Dmaap(); + Dmaap nd = new Dmaap.DmaapBuilder().createDmaap(); dmaap.update(nd); } catch (Exception e ) { } diff --git a/src/test/java/org/onap/dmaap/dbcapi/database/DBSingletonTest.java b/src/test/java/org/onap/dmaap/dbcapi/database/DBSingletonTest.java index 18eff64..003f250 100644 --- a/src/test/java/org/onap/dmaap/dbcapi/database/DBSingletonTest.java +++ b/src/test/java/org/onap/dmaap/dbcapi/database/DBSingletonTest.java @@ -20,17 +20,12 @@ */ package org.onap.dmaap.dbcapi.database; -import org.onap.dmaap.dbcapi.database.DBSingleton; import org.onap.dmaap.dbcapi.model.*; import org.onap.dmaap.dbcapi.testframework.ReflectionHarness; -import static org.junit.Assert.*; - import org.junit.After; import org.junit.Before; import org.junit.Test; -import java.util.*; -import java.sql.*; public class DBSingletonTest { @@ -54,7 +49,7 @@ public class DBSingletonTest { try { DBSingleton<Dmaap> dmaap = new DBSingleton<Dmaap>(Dmaap.class, "dmaap"); - Dmaap d = new Dmaap(); + Dmaap d = new Dmaap.DmaapBuilder().createDmaap(); dmaap.init( d ); d = dmaap.get(); d.setDmaapName( "foo" ); diff --git a/src/test/java/org/onap/dmaap/dbcapi/model/DmaapTest.java b/src/test/java/org/onap/dmaap/dbcapi/model/DmaapTest.java index c0f3bef..cb0c22f 100644 --- a/src/test/java/org/onap/dmaap/dbcapi/model/DmaapTest.java +++ b/src/test/java/org/onap/dmaap/dbcapi/model/DmaapTest.java @@ -48,7 +48,7 @@ public class DmaapTest { @Test public void testDmaapClassDefaultConstructor() { - Dmaap t = new Dmaap(); + Dmaap t = new Dmaap.DmaapBuilder().createDmaap(); assertTrue( t.getVersion() == null ); assertTrue( t.getTopicNsRoot() == null ); @@ -64,7 +64,7 @@ public class DmaapTest { @Test public void testDmaapClassConstructor() { - Dmaap t = new Dmaap( ver, tnr, dn, dpu, lu, bat, nk, ako ); + Dmaap t = new Dmaap.DmaapBuilder().setVer(ver).setTnr(tnr).setDn(dn).setDpu(dpu).setLu(lu).setBat(bat).setNk(nk).setAko(ako).createDmaap(); assertTrue( ver.equals( t.getVersion() )); assertTrue( tnr.equals( t.getTopicNsRoot() )); @@ -80,7 +80,7 @@ public class DmaapTest { @Test public void testDmaapClassSetters() { - Dmaap t = new Dmaap(); + Dmaap t = new Dmaap.DmaapBuilder().createDmaap(); t.setVersion( ver ); assertTrue( ver.equals( t.getVersion() )); diff --git a/src/test/java/org/onap/dmaap/dbcapi/service/DmaapServiceTest.java b/src/test/java/org/onap/dmaap/dbcapi/service/DmaapServiceTest.java index c1fa0fd..b8b660f 100644 --- a/src/test/java/org/onap/dmaap/dbcapi/service/DmaapServiceTest.java +++ b/src/test/java/org/onap/dmaap/dbcapi/service/DmaapServiceTest.java @@ -60,7 +60,7 @@ public class DmaapServiceTest { @Test public void test3() { - Dmaap nd = new Dmaap( "1", "org.onap.dmaap", "onap-demo", "drps.demo.onap.org", "", "MMAGENT_TOPIC", "", "" ); + Dmaap nd = new Dmaap.DmaapBuilder().setVer("1").setTnr("org.onap.dmaap").setDn("onap-demo").setDpu("drps.demo.onap.org").setLu("").setBat("MMAGENT_TOPIC").setNk("").setAko("").createDmaap(); ds.addDmaap( nd ); } @@ -72,7 +72,7 @@ public class DmaapServiceTest { @Test public void test5() { - Dmaap nd = new Dmaap( "2", "org.onap.dmaap", "onap-demo", "drps.demo.onap.org", "", "MMAGENT_TOPIC", "", "" ); + Dmaap nd = new Dmaap.DmaapBuilder().setVer("2").setTnr("org.onap.dmaap").setDn("onap-demo").setDpu("drps.demo.onap.org").setLu("").setBat("MMAGENT_TOPIC").setNk("").setAko("").createDmaap(); ds.updateDmaap( nd ); } diff --git a/src/test/java/org/onap/dmaap/dbcapi/testframework/DmaapObjectFactory.java b/src/test/java/org/onap/dmaap/dbcapi/testframework/DmaapObjectFactory.java index 901b4ea..9d45a54 100644 --- a/src/test/java/org/onap/dmaap/dbcapi/testframework/DmaapObjectFactory.java +++ b/src/test/java/org/onap/dmaap/dbcapi/testframework/DmaapObjectFactory.java @@ -19,30 +19,9 @@ */ package org.onap.dmaap.dbcapi.testframework; -import org.onap.dmaap.dbcapi.model.DR_Node; -import org.onap.dmaap.dbcapi.model.DR_Sub; -import org.onap.dmaap.dbcapi.model.DcaeLocation; -import org.onap.dmaap.dbcapi.model.Dmaap; -import org.onap.dmaap.dbcapi.model.FqtnType; -import org.onap.dmaap.dbcapi.model.MR_Client; -import org.onap.dmaap.dbcapi.model.MR_Cluster; -import org.onap.dmaap.dbcapi.model.Topic; +import org.onap.dmaap.dbcapi.model.*; import org.onap.dmaap.dbcapi.util.RandomInteger; -import static org.junit.Assert.*; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Type; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import static java.lang.System.out; -import static java.lang.System.err; - public class DmaapObjectFactory { /* @@ -75,7 +54,7 @@ public class DmaapObjectFactory { private static final String prot = "http"; public Dmaap genDmaap() { - return new Dmaap( dmaap_ver, dmaap_topic_root, dmaap_name, dmaap_dr, dmaap_log_url, dmaap_mm_topic, "nk", "ako" ); + return new Dmaap.DmaapBuilder().setVer(dmaap_ver).setTnr(dmaap_topic_root).setDn(dmaap_name).setDpu(dmaap_dr).setLu(dmaap_log_url).setBat(dmaap_mm_topic).setNk("nk").setAko("ako").createDmaap(); } public DcaeLocation genDcaeLocation( String layer ) { diff --git a/src/test/java/org/onap/dmaap/dbcapi/util/PermissionBuilderTest.java b/src/test/java/org/onap/dmaap/dbcapi/util/PermissionBuilderTest.java index 1858e47..61bb4b6 100644 --- a/src/test/java/org/onap/dmaap/dbcapi/util/PermissionBuilderTest.java +++ b/src/test/java/org/onap/dmaap/dbcapi/util/PermissionBuilderTest.java @@ -19,12 +19,11 @@ */ package org.onap.dmaap.dbcapi.util; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.atMost; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; - import javax.servlet.http.HttpServletRequest; import org.junit.Test; import org.junit.runner.RunWith; @@ -139,11 +138,11 @@ public class PermissionBuilderTest { } private Dmaap provideDefaultInstance() { - return new Dmaap("0", "", "", "", "", "", "", ""); + return new Dmaap.DmaapBuilder().setVer("0").setTnr("").setDn("").setDpu("").setLu("").setBat("").setNk("").setAko("").createDmaap(); } private Dmaap provideRealInstance(String dmaapName) { - Dmaap dmaap = new Dmaap("1", "org.onap.dmaap", dmaapName, "https://dmaap-dr-prov:8443", "", "DCAE_MM_AGENT", "", ""); + Dmaap dmaap = new Dmaap.DmaapBuilder().setVer("1").setTnr("org.onap.dmaap").setDn(dmaapName).setDpu("https://dmaap-dr-prov:8443").setLu("").setBat("DCAE_MM_AGENT").setNk("").setAko("").createDmaap(); dmaap.setStatus(DmaapObject_Status.VALID); return dmaap; } |