diff options
Diffstat (limited to 'src/test/java')
13 files changed, 1156 insertions, 0 deletions
diff --git a/src/test/java/org/onap/dmaap/dbcapi/model/DRNodeTest.java b/src/test/java/org/onap/dmaap/dbcapi/model/DRNodeTest.java new file mode 100644 index 0000000..ce23656 --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/model/DRNodeTest.java @@ -0,0 +1,86 @@ +/*- + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.dmaap.dbcapi.model; + +import static org.junit.Assert.*; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +public class DRNodeTest { + String f, d, h, v; + + @Before + public void setUp() throws Exception { + v = "1"; + f = "node01.onap.org"; + h = "zlpdrns01.cloud.onap.org"; + d = "central-onap"; + } + + @After + public void tearDown() throws Exception { + } + + + @Test + public void testDRNodeClassDefaultConstructor() { + + DR_Node t = new DR_Node(); + + assertTrue( t.getFqdn() == null ); + assertTrue( t.getDcaeLocationName() == null ); + assertTrue( t.getHostName() == null ); + assertTrue( t.getVersion() == null ); + + } + + @Test + public void testDRNodeClassConstructor() { + + DR_Node t = new DR_Node( f, d, h, v ); + + assertTrue( f.equals( t.getFqdn() )); + assertTrue( d.equals( t.getDcaeLocationName() )); + assertTrue( h.equals( t.getHostName() )); + assertTrue( v.equals( t.getVersion() )); + + } + + @Test + public void testDRNodeClassSetters() { + + DR_Node t = new DR_Node(); + + t.setFqdn( f ); + assertTrue( f.equals( t.getFqdn() )); + t.setDcaeLocationName( d ); + assertTrue( d.equals( t.getDcaeLocationName() )); + t.setHostName( h ); + assertTrue( h.equals( t.getHostName() )); + t.setVersion( v ); + assertTrue( v.equals( t.getVersion() )); + + } +} diff --git a/src/test/java/org/onap/dmaap/dbcapi/model/DRPubTest.java b/src/test/java/org/onap/dmaap/dbcapi/model/DRPubTest.java new file mode 100644 index 0000000..191f364 --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/model/DRPubTest.java @@ -0,0 +1,90 @@ +/*- + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.dmaap.dbcapi.model; + +import static org.junit.Assert.*; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +public class DRPubTest { + String d, un, up, f, p; + + @Before + public void setUp() throws Exception { + d = "central-onap"; + un = "user1"; + up = "secretW0rd"; + f = "234"; + p = "678"; + } + + @After + public void tearDown() throws Exception { + } + + + @Test + public void testDRPubClassDefaultConstructor() { + + DR_Pub t = new DR_Pub(); + + assertTrue( t.getDcaeLocationName() == null ); + assertTrue( t.getUsername() == null ); + assertTrue( t.getUserpwd() == null ); + assertTrue( t.getFeedId() == null ); + assertTrue( t.getPubId() == null ); + + } + + @Test + public void testDRPubClassConstructor() { + + DR_Pub t = new DR_Pub( d, un, up, f, p ); + + assertTrue( d.equals( t.getDcaeLocationName() )); + assertTrue( un.equals( t.getUsername() )); + assertTrue( up.equals( t.getUserpwd() )); + assertTrue( f.equals( t.getFeedId() )); + assertTrue( p.equals( t.getPubId() )); + } + + @Test + public void testDRPubClassSetters() { + + DR_Pub t = new DR_Pub(); + + t.setDcaeLocationName( d ); + assertTrue( d.equals( t.getDcaeLocationName() )); + t.setUsername( un ); + assertTrue( un.equals( t.getUsername() )); + t.setUserpwd( up ); + assertTrue( up.equals( t.getUserpwd() )); + t.setFeedId( f ); + assertTrue( f.equals( t.getFeedId() )); + t.setPubId( p ); + assertTrue( p.equals( t.getPubId() )); + + } +} diff --git a/src/test/java/org/onap/dmaap/dbcapi/model/DRSubTest.java b/src/test/java/org/onap/dmaap/dbcapi/model/DRSubTest.java new file mode 100644 index 0000000..251d975 --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/model/DRSubTest.java @@ -0,0 +1,108 @@ +/*- + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.dmaap.dbcapi.model; + +import static org.junit.Assert.*; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +public class DRSubTest { + String d, un, up, f, du, lu, s, o; + Boolean u100, susp; + + @Before + public void setUp() throws Exception { + d = "central-onap"; + un = "user1"; + up = "secretW0rd"; + f = "234"; + s = "sub123"; + du = "sub.server.onap.org:8443/deliver/here"; + lu = "https://drps.onap.org:8443/sublog/123"; + u100 = true; + susp = false; + o = "joe"; + } + + @After + public void tearDown() throws Exception { + } + + + @Test + public void testDRSubClassDefaultConstructor() { + + DR_Sub t = new DR_Sub(); + + assertTrue( t.getDcaeLocationName() == null ); + assertTrue( t.getUsername() == null ); + assertTrue( t.getUserpwd() == null ); + assertTrue( t.getFeedId() == null ); + assertTrue( t.getDeliveryURL() == null ); + assertTrue( t.getLogURL() == null ); + assertTrue( t.getSubId() == null ); + assertTrue( ! t.isUse100() ); + assertTrue( ! t.isSuspended() ); + assertTrue( t.getOwner() == null ); + + } + + @Test + public void testDRSubClassConstructor() { + + DR_Sub t = new DR_Sub( d, un, up, f, du, lu, u100 ); + + assertTrue( d.equals( t.getDcaeLocationName() )); + assertTrue( un.equals( t.getUsername() )); + assertTrue( up.equals( t.getUserpwd() )); + assertTrue( f.equals( t.getFeedId() )); + assertTrue( du.equals( t.getDeliveryURL() ) ); + assertTrue( lu.equals( t.getLogURL() ) ); + assertTrue( t.isUse100() ); + assertTrue( ! t.isSuspended() ); + } + + @Test + public void testDRSubClassSetters() { + + DR_Sub t = new DR_Sub(); + + t.setDcaeLocationName( d ); + assertTrue( d.equals( t.getDcaeLocationName() )); + t.setUsername( un ); + assertTrue( un.equals( t.getUsername() )); + t.setUserpwd( up ); + assertTrue( up.equals( t.getUserpwd() )); + t.setFeedId( f ); + assertTrue( f.equals( t.getFeedId() )); + t.setSubId( s ); + assertTrue( s.equals( t.getSubId() )); + t.setDeliveryURL( du ); + assertTrue( du.equals( t.getDeliveryURL() ) ); + t.setLogURL( lu ); + assertTrue( lu.equals( t.getLogURL() ) ); + + } +} diff --git a/src/test/java/org/onap/dmaap/dbcapi/model/DcaeLocationTest.java b/src/test/java/org/onap/dmaap/dbcapi/model/DcaeLocationTest.java new file mode 100644 index 0000000..6652bb0 --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/model/DcaeLocationTest.java @@ -0,0 +1,94 @@ +/*- + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.dmaap.dbcapi.model; + +import static org.junit.Assert.*; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +public class DcaeLocationTest { + String c, dl, dln, osz, s, edge; + + @Before + public void setUp() throws Exception { + c = "ABCDE888NJ"; + dl = "central-node"; + edge = "local-node"; + dln = "hollywood"; + osz = "california"; + s = "10.10.10.1"; + } + + @After + public void tearDown() throws Exception { + } + + + @Test + public void testDcaeLocationDefaultConstructor() { + + DcaeLocation t = new DcaeLocation(); + + assertTrue( t.getClli() == null ); + assertTrue( t.getDcaeLayer() == null ); + assertTrue( t.getDcaeLocationName() == null ); + assertTrue( t.getOpenStackAvailabilityZone() == null ); + assertTrue( t.getSubnet() == null ); + + } + + @Test + public void testDcaeLocationClassConstructor() { + + DcaeLocation t = new DcaeLocation( c, dl, dln, osz, s ); + + assertTrue( c.equals( t.getClli() )); + assertTrue( dl.equals( t.getDcaeLayer() )); + assertTrue( dln.equals( t.getDcaeLocationName() )); + assertTrue( osz.equals( t.getOpenStackAvailabilityZone() )); + assertTrue( s.equals( t.getSubnet() )); + } + + @Test + public void testDmaapClassSetters() { + + DcaeLocation t = new DcaeLocation(); + + t.setClli( c ); + assertTrue( c.equals( t.getClli() )); + t.setDcaeLayer( dl ); + assertTrue( dl.equals( t.getDcaeLayer() )); + assertTrue( t.isCentral() ); + t.setDcaeLayer( edge ); + assertTrue( edge.equals( t.getDcaeLayer() )); + assertTrue( t.isLocal() ); + t.setDcaeLocationName( dln ); + assertTrue( dln.equals( t.getDcaeLocationName() )); + t.setOpenStackAvailabilityZone( osz ); + assertTrue( osz.equals( t.getOpenStackAvailabilityZone() )); + t.setSubnet( s ); + assertTrue( s.equals( t.getSubnet() )); + } +} diff --git a/src/test/java/org/onap/dmaap/dbcapi/model/DmaapTest.java b/src/test/java/org/onap/dmaap/dbcapi/model/DmaapTest.java new file mode 100644 index 0000000..fb83fe9 --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/model/DmaapTest.java @@ -0,0 +1,106 @@ +/*- + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.dmaap.dbcapi.model; + +import static org.junit.Assert.*; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +public class DmaapTest { + String ver, tnr, dn, dpu, lu, bat, nk, ako; + + @Before + public void setUp() throws Exception { + ver = "1"; + tnr = "org.onap.dmaap"; + dn = "onap"; + dpu = "https://drps.dmaap.onap.org:8081"; + lu = "http://drps.dmaap.onap.org:8080/feedlog"; + bat = "org.onap.dcae.dmaap.MM_AGENT_TOPIC"; + nk = "foo"; + ako = "bar"; + } + + @After + public void tearDown() throws Exception { + } + + + @Test + public void testDmaapClassDefaultConstructor() { + + Dmaap t = new Dmaap(); + + assertTrue( t.getVersion() == null ); + assertTrue( t.getTopicNsRoot() == null ); + assertTrue( t.getDmaapName() == null ); + assertTrue( t.getDrProvUrl() == null ); + assertTrue( t.getLoggingUrl() == null ); + assertTrue( t.getBridgeAdminTopic() == null ); + assertTrue( t.getNodeKey() == null ); + assertTrue( t.getAccessKeyOwner() == null ); + + } + + @Test + public void testDmaapClassConstructor() { + + Dmaap t = new Dmaap( ver, tnr, dn, dpu, lu, bat, nk, ako ); + + assertTrue( ver.equals( t.getVersion() )); + assertTrue( tnr.equals( t.getTopicNsRoot() )); + assertTrue( dn.equals( t.getDmaapName() )); + assertTrue( dpu.equals( t.getDrProvUrl() )); + assertTrue( lu.equals( t.getLoggingUrl() )); + assertTrue( bat.equals( t.getBridgeAdminTopic() )); + assertTrue( nk.equals( t.getNodeKey() )); + assertTrue( ako.equals( t.getAccessKeyOwner() )); + + } + + @Test + public void testDmaapClassSetters() { + + Dmaap t = new Dmaap(); + + t.setVersion( ver ); + assertTrue( ver.equals( t.getVersion() )); + t.setTopicNsRoot( tnr ); + assertTrue( tnr.equals( t.getTopicNsRoot() )); + t.setDmaapName( dn ); + assertTrue( dn.equals( t.getDmaapName() )); + t.setDrProvUrl( dpu ); + assertTrue( dpu.equals( t.getDrProvUrl() )); + t.setLoggingUrl( lu ); + assertTrue( lu.equals( t.getLoggingUrl() )); + t.setBridgeAdminTopic( bat ); + assertTrue( bat.equals( t.getBridgeAdminTopic() )); + t.setNodeKey( nk ); + assertTrue( nk.equals( t.getNodeKey() )); + t.setAccessKeyOwner( ako ); + assertTrue( ako.equals( t.getAccessKeyOwner() )); + + } +} diff --git a/src/test/java/org/onap/dmaap/dbcapi/model/FeedTest.java b/src/test/java/org/onap/dmaap/dbcapi/model/FeedTest.java new file mode 100644 index 0000000..cc8b259 --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/model/FeedTest.java @@ -0,0 +1,79 @@ +/*- + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.dmaap.dbcapi.model; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + + +public class FeedTest { + + private static final String fmt = "%24s: %s%n"; + + ReflectionHarness rh = new ReflectionHarness(); + + String n, v, d, o, a; + + @Before + public void setUp() throws Exception { + n = "Chicken Feed"; + v = "1.0"; + d = "A daily helping of chicken eating metrics"; + o = "ab123"; + a = "Unrestricted"; + } + + @After + public void tearDown() throws Exception { + } + + + @Test + public void test1() { + + + rh.reflect( "org.onap.dmaap.dbcapi.model.Feed", "get", null ); + + } + + @Test + public void test2() { + Feed t = new Feed( n, v, d, o, a ); + + + assertTrue( n.equals( t.getFeedName() )); + assertTrue( v.equals( t.getFeedVersion() )); + assertTrue( d.equals( t.getFeedDescription() )); + assertTrue( o.equals( t.getOwner() )); + assertTrue( a.equals( t.getAsprClassification() ) ); + assertTrue( ! t.isSuspended() ); + } + + @Test + public void test3() { + + String v = "Validate"; + rh.reflect( "org.onap.dmaap.dbcapi.model.Feed", "set", v ); + } + +} diff --git a/src/test/java/org/onap/dmaap/dbcapi/model/JUnitTestSuite.java b/src/test/java/org/onap/dmaap/dbcapi/model/JUnitTestSuite.java new file mode 100644 index 0000000..1c8edc0 --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/model/JUnitTestSuite.java @@ -0,0 +1,40 @@ +/*- + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.dmaap.dbcapi.model; + +import junit.framework.TestSuite; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; +import org.apache.log4j.Logger; + +@RunWith(Suite.class) +@SuiteClasses({ DmaapTest.class + }) +public class JUnitTestSuite { + private static final Logger LOGGER = Logger.getLogger(JUnitTestSuite.class); + public static void main(String[] args) { + LOGGER.info("Running the test suite"); + + TestSuite tstSuite = new TestSuite(); + LOGGER.info("Total Test Counts " + tstSuite.countTestCases()); + } +} diff --git a/src/test/java/org/onap/dmaap/dbcapi/model/MRClientTest.java b/src/test/java/org/onap/dmaap/dbcapi/model/MRClientTest.java new file mode 100644 index 0000000..dd57348 --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/model/MRClientTest.java @@ -0,0 +1,91 @@ +/*- + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.dmaap.dbcapi.model; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + + +public class MRClientTest { + + private static final String fmt = "%24s: %s%n"; + + ReflectionHarness rh = new ReflectionHarness(); + + String d, t, f, c, m; + + @Before + public void setUp() throws Exception { + d = "central-onap"; + t = "org.onap.dmaap.interestingTopic"; + f = "mrc.onap.org:3904/events/org.onap.dmaap.interestingTopic"; + c = "publisher"; + m = "m12345"; + } + + @After + public void tearDown() throws Exception { + } + + + @Test + public void test1() { + + // can't use simple reflection to test for null since null constructor initializes some fields. + //rh.reflect( "org.onap.dmaap.dbcapi.model.MR_Client", "get", null ); + // so brute force instead... + String[] a = { "put", "view" }; + MR_Client m = new MR_Client(); + + + assertTrue( null == m.getDcaeLocationName() ); + assertTrue( null == m.getFqtn() ); + assertTrue( null == m.getClientRole() ); + assertTrue( null == m.getAction() ); + + } + + @Test + public void test2() { + String[] a = { "put", "view" }; + MR_Client m = new MR_Client( d, f, c, a ); + + + assertTrue( d.equals( m.getDcaeLocationName() )); + assertTrue( f.equals( m.getFqtn() )); + assertTrue( c.equals( m.getClientRole() )); + String[] ma = m.getAction(); + assertTrue( a.length == ma.length ); + for( int i = 0; i < a.length; i++ ) { + assertTrue( a[i].equals( ma[i] ) ); + } + } + + @Test + public void test3() { + + String v = "Validate"; + rh.reflect( "org.onap.dmaap.dbcapi.model.MR_Client", "set", v ); + } + +} diff --git a/src/test/java/org/onap/dmaap/dbcapi/model/MirrorMakerTest.java b/src/test/java/org/onap/dmaap/dbcapi/model/MirrorMakerTest.java new file mode 100644 index 0000000..1949820 --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/model/MirrorMakerTest.java @@ -0,0 +1,72 @@ +/*- + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.dmaap.dbcapi.model; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + + +public class MirrorMakerTest { + + private static final String fmt = "%24s: %s%n"; + + ReflectionHarness rh = new ReflectionHarness(); + + String s, t; + + @Before + public void setUp() throws Exception { + s = "source"; + t = "target"; + } + + @After + public void tearDown() throws Exception { + } + + + @Test + public void test1() { + + + rh.reflect( "org.onap.dmaap.dbcapi.model.MirrorMaker", "get", null ); + + } + + @Test + public void test2() { + MirrorMaker m = new MirrorMaker( s, t ); + + + assertTrue( s.equals( m.getSourceCluster() )); + assertTrue( t.equals( m.getTargetCluster() )); + } + + @Test + public void test3() { + + String v = "Validate"; + rh.reflect( "org.onap.dmaap.dbcapi.model.MirrorMaker", "set", v ); + } + +} diff --git a/src/test/java/org/onap/dmaap/dbcapi/model/ReflectionHarness.java b/src/test/java/org/onap/dmaap/dbcapi/model/ReflectionHarness.java new file mode 100644 index 0000000..76167ce --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/model/ReflectionHarness.java @@ -0,0 +1,175 @@ +/*- + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.dmaap.dbcapi.model; + +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 ReflectionHarness { + private static final String fmt = "%24s: %s%n"; + + + // following 2 functions taken from: http://tutorials.jenkov.com/java-reflection/getters-setters.html + public static boolean isGetter(Method method){ + if(!method.getName().startsWith("get")) return false; + if(method.getParameterTypes().length != 0) return false; + if(void.class.equals(method.getReturnType())) return false; + return true; + } + + public static boolean isSetter(Method method){ + if(!method.getName().startsWith("set")) return false; + if(method.getParameterTypes().length != 1) return false; + return true; + } + + private void testGetter( Class<?> c, Method m, Class<?>[] pType, String val ) { + //out.format( fmt, "testGetter: Method Name", m.getName() ); + Class retType = m.getReturnType(); + //out.format( fmt, "testGetter: Return Type ", retType ); + //out.format( fmt, "testGetter: val ", (val != null)?val:"null" ); + assertTrue( pType.length == 0 ); + + try { + Object t = c.newInstance(); + + try { + m.setAccessible(true); + Object o = m.invoke( t ); + + if( retType.equals( Class.forName( "java.lang.String" ) ) ) { + if ( val == null ) { + //out.format( fmt, "testGetter: expected null, got ", (o != null)?o:"null" ); + assert( o == null ); + } else { + //out.format( fmt, "testGetter: expected val, got ", (o != null)?o:"null" ); + assert( o.equals( val ) ); + } + } else { + out.format( fmt, "testGetter: " + m.getName() + " untested retType", retType ); + + } + + } catch (InvocationTargetException e ) { + Throwable cause = e.getCause(); + err.format( "%s() returned %x%n", m.getName(), cause.getMessage() ); + } + + } catch (ClassNotFoundException nfe ){ + nfe.printStackTrace(); + } catch (IllegalArgumentException ae ) { + ae.printStackTrace(); + } catch (InstantiationException ie ) { + ie.printStackTrace(); + } catch (IllegalAccessException iae ) { + iae.printStackTrace(); + } + } + + private void testSetter( Class<?> c, Method m, Class<?>[] pType ) { + //out.format( fmt, "testSetter: Method Name", m.getName() ); + Class retType = m.getReturnType(); + //out.format( fmt, "testSetter: Return Type ", retType ); + //out.format( fmt, "testSetter: val ", (val != null)?val:"null" ); + assertTrue( pType.length == 1 ); + + try { + Object t = c.newInstance(); + + try { + m.setAccessible(true); + //out.format( fmt, "testSetter: " + m.getName() + " to try pType", pType[0] ); + if ( pType[0].equals( Class.forName( "java.lang.String" ) ) ) { + String val = "Validate123"; + Object o = m.invoke( t, val ); + } else if ( pType[0].equals( boolean.class ) ) { // note primitive class notation + boolean b = true; + Object o = m.invoke( t, b ); + } else { + out.format( fmt, "testSetter: " + m.getName() + " untested pType", pType[0] ); + } + + } catch (InvocationTargetException e ) { + Throwable cause = e.getCause(); + err.format( "%s() returned %x%n", m.getName(), cause.getMessage() ); + } + + } catch (ClassNotFoundException nfe ){ + nfe.printStackTrace(); + } catch (IllegalArgumentException ae ) { + ae.printStackTrace(); + } catch (InstantiationException ie ) { + ie.printStackTrace(); + } catch (IllegalAccessException iae ) { + iae.printStackTrace(); + } + } + + public void reflect(String... args) { + try { + Class<?> c = Class.forName(args[0]); + Method[] allMethods = c.getDeclaredMethods(); + String methodPrefix = args[1]; + for (Method m : allMethods) { + if (!m.getName().startsWith(methodPrefix)) { + continue; + } + //out.format("%s%n", m.toGenericString()); + + //out.format(fmt, "ReturnType", m.getReturnType()); + //out.format(fmt, "GenericReturnType", m.getGenericReturnType()); + + Class<?>[] pType = m.getParameterTypes(); + Type[] gpType = m.getGenericParameterTypes(); + for (int i = 0; i < pType.length; i++) { + //out.format(fmt,"ParameterType", pType[i]); + //out.format(fmt,"GenericParameterType", gpType[i]); + } + if ( isGetter( m ) ) { + testGetter( c, m, pType , args[2]); + } else if ( isSetter( m ) ) { + testSetter( c, m, pType ); + } + + Class<?>[] xType = m.getExceptionTypes(); + Type[] gxType = m.getGenericExceptionTypes(); + for (int i = 0; i < xType.length; i++) { + //out.format(fmt,"ExceptionType", xType[i]); + //out.format(fmt,"GenericExceptionType", gxType[i]); + } + } + + // production code should handle these exceptions more gracefully + } catch (ClassNotFoundException x) { + x.printStackTrace(); + } + } +} diff --git a/src/test/java/org/onap/dmaap/dbcapi/model/TestRunner.java b/src/test/java/org/onap/dmaap/dbcapi/model/TestRunner.java new file mode 100644 index 0000000..fcab3e1 --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/model/TestRunner.java @@ -0,0 +1,36 @@ +/*- + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.dmaap.dbcapi.model; +import org.junit.runner.JUnitCore; +import org.junit.runner.Result; +import org.junit.runner.notification.Failure; +import org.apache.log4j.Logger; +public class TestRunner { + private static final Logger LOGGER = Logger.getLogger(TestRunner.class); + public static void main(String[] args) { + + Result result = JUnitCore.runClasses(JUnitTestSuite.class); + for (Failure failure : result.getFailures()) { + LOGGER.info(failure.toString()); + + } + LOGGER.info(result.wasSuccessful()); + } +} diff --git a/src/test/java/org/onap/dmaap/dbcapi/model/TopicTest.java b/src/test/java/org/onap/dmaap/dbcapi/model/TopicTest.java new file mode 100644 index 0000000..1f8b3b2 --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/model/TopicTest.java @@ -0,0 +1,79 @@ +/*- + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.dmaap.dbcapi.model; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + + +public class TopicTest { + + private static final String fmt = "%24s: %s%n"; + + ReflectionHarness rh = new ReflectionHarness(); + + String f, t, d, e, o; + + @Before + public void setUp() throws Exception { + f = "org.onap.dmaap.interestingTopic"; + t = "interestingTopic"; + d = "A so very interesting topic"; + e = "Yes"; + o = "m12345"; + } + + @After + public void tearDown() throws Exception { + } + + + @Test + public void test1() { + + + rh.reflect( "org.onap.dmaap.dbcapi.model.Topic", "get", null ); + + } + + @Test + public void test2() { + String[] a = { "put", "view" }; + Topic obj = new Topic( f, t, d, e, o ); + + + assertTrue( f.equals( obj.getFqtn() )); + assertTrue( t.equals( obj.getTopicName() )); + assertTrue( d.equals( obj.getTopicDescription() )); + assertTrue( e.equals( obj.getTnxEnabled() )); + assertTrue( o.equals( obj.getOwner() )); + } + + @Test + public void test3() { + + String v = "Validate"; + rh.reflect( "org.onap.dmaap.dbcapi.model.Topic", "set", v ); + } + +} diff --git a/src/test/java/org/onap/dmaap/dbcapi/service/TopicServiceTest.java b/src/test/java/org/onap/dmaap/dbcapi/service/TopicServiceTest.java new file mode 100644 index 0000000..0d39350 --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/service/TopicServiceTest.java @@ -0,0 +1,100 @@ +/*- + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.dmaap.dbcapi.service; +import org.onap.dmaap.dbcapi.model.*; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import java.util.List; + +public class TopicServiceTest { + + private static final String fmt = "%24s: %s%n"; + + ReflectionHarness rh = new ReflectionHarness(); + + TopicService ts; + + @Before + public void setUp() throws Exception { + ts = new TopicService(); + } + + @After + public void tearDown() throws Exception { + } + + + @Test + public void test1() { + + + rh.reflect( "org.onap.dmaap.dbcapi.service.TopicService", "get", null ); + + } + + @Test + public void test2() { + String v = "Validate"; + rh.reflect( "org.onap.dmaap.dbcapi.service.TopicService", "set", v ); + + } + + @Test + public void test3() { + Topic topic = new Topic(); + ApiError err = new ApiError(); + topic.setTopicName( "test3" ); + topic.setFqtnStyle( FqtnType.Validator("none") ); + topic.getFqtn(); + Topic nTopic = ts.addTopic( topic, err ); + if ( nTopic != null ) { + assertTrue( nTopic.getTopicName().equals( topic.getTopicName() )); + } + + } + + @Test + public void test4() { + List<Topic> l = ts.getAllTopics(); + + } + +/* + @Test + public void test5() { + Topic topic = new Topic(); + ApiError err = new ApiError(); + topic.setTopicName( "test5" ); + topic.setFqtnStyle( FqtnType.Validator("none") ); + topic.setReplicationCase( ReplicationType.Validator("none") ); + topic.getFqtn(); + Topic nTopic = ts.updateTopic( topic, err ); + if ( nTopic != null ) { + assertTrue( nTopic.getTopicName().equals( topic.getTopicName() )); + } + + } +*/ + +} |