From 0c9c3008ac34fbf908c62ff5c99a0d844583b908 Mon Sep 17 00:00:00 2001 From: "Balaji, Ramya (rb111y)" Date: Fri, 23 Nov 2018 13:25:21 -0500 Subject: Possible fix for NoClassDefFoundError Changed package structure, pom file for Utils classto expose it under export-package for DMaap adapter bundle Issue-ID: APPC-1247 Change-Id: I1662d3af027982a87c063cabee77a645f2bc3afa Signed-off-by: Balaji, Ramya (rb111y) --- .../messaging/dmaap/SimpleExamplePublisher.java | 2 +- .../messaging/dmaap/impl/TestDmaapUtil.java | 268 --------------------- .../messaging/dmaap/utils/TestDmaapUtil.java | 268 +++++++++++++++++++++ 3 files changed, 269 insertions(+), 269 deletions(-) delete mode 100644 appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/impl/TestDmaapUtil.java create mode 100644 appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/utils/TestDmaapUtil.java (limited to 'appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org') diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/SimpleExamplePublisher.java b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/SimpleExamplePublisher.java index 16cd5d832..3d50ea588 100644 --- a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/SimpleExamplePublisher.java +++ b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/SimpleExamplePublisher.java @@ -31,7 +31,7 @@ import java.util.concurrent.TimeUnit; import com.att.nsa.mr.client.MRConsumer; import org.json.JSONObject; -import org.onap.appc.adapter.messaging.dmaap.impl.DmaapUtil; +import org.onap.appc.adapter.messaging.dmaap.utils.DmaapUtil; import com.att.nsa.mr.client.MRBatchingPublisher; import com.att.nsa.mr.client.MRClientFactory; diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/impl/TestDmaapUtil.java b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/impl/TestDmaapUtil.java deleted file mode 100644 index 03e61916b..000000000 --- a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/impl/TestDmaapUtil.java +++ /dev/null @@ -1,268 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 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.appc.adapter.messaging.dmaap.impl; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.lang.reflect.Field; -import java.util.Properties; - -import org.junit.BeforeClass; -import org.junit.Test; -import org.onap.appc.configuration.ConfigurationFactory; - -public class TestDmaapUtil { - private static Class configurationFactoryClass; - private static Field configField; - - @Test - public void testCreateConsumerPropFile() { - String topic = "JunitTopicOne"; - Properties junitProps = new Properties(); - junitProps.put("host", "192.168.10.10"); - junitProps.put("group", "junit-client"); - junitProps.put("id", "junit-consumer-one"); - junitProps.put("filter", "none"); - - String junitFile = null; - - // ensure file path property is not set - if (System.getProperty(DmaapUtil.DMAAP_PROPERTIES_PATH) != null) { - System.clearProperty(DmaapUtil.DMAAP_PROPERTIES_PATH); - - // set configuration to null to force reloading of properties - try { - configField.set(null, null); - } catch (IllegalArgumentException | IllegalAccessException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - } - try { - junitFile = DmaapUtil.createConsumerPropFile(topic, junitProps); - } catch (IOException e) { - e.printStackTrace(); - fail("Exception creating consumer property file"); - } - - assertNotNull(junitFile); - - // open file and verify properties - File testFile = new File(junitFile); - assertTrue(testFile.exists()); - - InputStream is = null; - Properties testProps = new Properties(); - try { - is = new FileInputStream(testFile); - testProps.load(is); - } catch (FileNotFoundException e) { - e.printStackTrace(); - fail("Exception opening consumer property file"); - } catch (IOException e) { - e.printStackTrace(); - fail("Exception opening consumer property file"); - } finally { - try { - if (is != null) { - is.close(); - } - } catch (IOException ex) { - ex.printStackTrace(); - fail("Exception closing consumer property file"); - } - } - - assertFalse(testProps.isEmpty()); - - assertEquals(testProps.get("host"), "192.168.10.10"); - assertEquals(testProps.get("group"), "junit-client"); - assertEquals(testProps.get("id"), "junit-consumer-one"); - assertEquals(testProps.get("filter"), "none"); - assertEquals(testProps.get("TransportType"), "HTTPNOAUTH"); - } - - @Test - public void testCreateConsumerPropFileWithCustomProfile() { - String topic = "JunitTopicOne"; - Properties junitProps = new Properties(); - junitProps.put("host", "192.168.10.10"); - junitProps.put("group", "junit-client"); - junitProps.put("id", "junit-consumer-two"); - junitProps.put("filter", "none"); - - String junitFile = null; - - // set property for DMaaP profile - System.setProperty(DmaapUtil.DMAAP_PROPERTIES_PATH, "src/test/resources/org/onap/appc"); - - // set configuration to null to force reloading of properties - try { - configField.set(null, null); - } catch (IllegalArgumentException | IllegalAccessException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - - try { - junitFile = DmaapUtil.createConsumerPropFile(topic, junitProps); - } catch (IOException e) { - e.printStackTrace(); - fail("Exception creating consumer property file"); - } - - assertNotNull(junitFile); - - // open file and verify properties - File testFile = new File(junitFile); - assertTrue(testFile.exists()); - - InputStream is = null; - Properties testProps = new Properties(); - try { - is = new FileInputStream(testFile); - testProps.load(is); - } catch (FileNotFoundException e) { - e.printStackTrace(); - fail("Exception opening consumer property file"); - } catch (IOException e) { - e.printStackTrace(); - fail("Exception opening consumer property file"); - } finally { - try { - if (is != null) { - is.close(); - } - } catch (IOException ex) { - ex.printStackTrace(); - fail("Exception closing consumer property file"); - } - } - - assertFalse(testProps.isEmpty()); - - assertEquals(testProps.get("host"), "192.168.10.10"); - assertEquals(testProps.get("group"), "junit-client"); - assertEquals(testProps.get("id"), "junit-consumer-two"); - assertEquals(testProps.get("filter"), "none"); - assertEquals(testProps.get("TransportType"), "HTTPAAF"); - } - - @Test - public void testCreateProducerPropFile() { - String topic = "JunitTopicOne"; - Properties junitProps = new Properties(); - junitProps.put("host", "192.168.10.10"); - junitProps.put("group", "junit-client"); - junitProps.put("id", "junit-producer-one"); - junitProps.put("filter", "none"); - - String junitFile = null; - - // ensure file path property is not set - if (System.getProperty(DmaapUtil.DMAAP_PROPERTIES_PATH) != null) { - System.clearProperty(DmaapUtil.DMAAP_PROPERTIES_PATH); - - // set configuration to null to force reloading of properties - try { - configField.set(null, null); - } catch (IllegalArgumentException | IllegalAccessException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - } - - try { - junitFile = DmaapUtil.createProducerPropFile(topic, junitProps); - } catch (IOException e) { - e.printStackTrace(); - fail("Exception creating consumer property file"); - } - - assertNotNull(junitFile); - - // open file and verify properties - File testFile = new File(junitFile); - assertTrue(testFile.exists()); - - InputStream is = null; - Properties testProps = new Properties(); - try { - is = new FileInputStream(testFile); - testProps.load(is); - } catch (FileNotFoundException e) { - e.printStackTrace(); - fail("Exception opening consumer property file"); - } catch (IOException e) { - e.printStackTrace(); - fail("Exception opening consumer property file"); - } finally { - try { - if (is != null) { - is.close(); - } - } catch (IOException ex) { - ex.printStackTrace(); - fail("Exception closing consumer property file"); - } - } - - assertFalse(testProps.isEmpty()); - - assertEquals(testProps.get("host"), "192.168.10.10"); - assertEquals(testProps.get("group"), "junit-client"); - assertEquals(testProps.get("id"), "junit-producer-one"); - assertEquals(testProps.get("filter"), "none"); - assertEquals("HTTPNOAUTH", testProps.get("TransportType")); - } - - /** - * Use reflection to locate fields and methods so that they can be - * manipulated during the test to change the internal state accordingly. - * - * @throws NoSuchFieldException - * if the field(s) dont exist - * @throws SecurityException - * if reflective access is not allowed - * @throws NoSuchMethodException - * If the method(s) dont exist - */ - @SuppressWarnings("nls") - @BeforeClass - public static void once() throws NoSuchFieldException, SecurityException, NoSuchMethodException { - configurationFactoryClass = ConfigurationFactory.class; - - configField = configurationFactoryClass.getDeclaredField("config"); - configField.setAccessible(true); - } -} diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/utils/TestDmaapUtil.java b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/utils/TestDmaapUtil.java new file mode 100644 index 000000000..1567242b5 --- /dev/null +++ b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/utils/TestDmaapUtil.java @@ -0,0 +1,268 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 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.appc.adapter.messaging.dmaap.utils; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Field; +import java.util.Properties; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.appc.configuration.ConfigurationFactory; + +public class TestDmaapUtil { + private static Class configurationFactoryClass; + private static Field configField; + + @Test + public void testCreateConsumerPropFile() { + String topic = "JunitTopicOne"; + Properties junitProps = new Properties(); + junitProps.put("host", "192.168.10.10"); + junitProps.put("group", "junit-client"); + junitProps.put("id", "junit-consumer-one"); + junitProps.put("filter", "none"); + + String junitFile = null; + + // ensure file path property is not set + if (System.getProperty(DmaapUtil.DMAAP_PROPERTIES_PATH) != null) { + System.clearProperty(DmaapUtil.DMAAP_PROPERTIES_PATH); + + // set configuration to null to force reloading of properties + try { + configField.set(null, null); + } catch (IllegalArgumentException | IllegalAccessException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + try { + junitFile = DmaapUtil.createConsumerPropFile(topic, junitProps); + } catch (IOException e) { + e.printStackTrace(); + fail("Exception creating consumer property file"); + } + + assertNotNull(junitFile); + + // open file and verify properties + File testFile = new File(junitFile); + assertTrue(testFile.exists()); + + InputStream is = null; + Properties testProps = new Properties(); + try { + is = new FileInputStream(testFile); + testProps.load(is); + } catch (FileNotFoundException e) { + e.printStackTrace(); + fail("Exception opening consumer property file"); + } catch (IOException e) { + e.printStackTrace(); + fail("Exception opening consumer property file"); + } finally { + try { + if (is != null) { + is.close(); + } + } catch (IOException ex) { + ex.printStackTrace(); + fail("Exception closing consumer property file"); + } + } + + assertFalse(testProps.isEmpty()); + + assertEquals(testProps.get("host"), "192.168.10.10"); + assertEquals(testProps.get("group"), "junit-client"); + assertEquals(testProps.get("id"), "junit-consumer-one"); + assertEquals(testProps.get("filter"), "none"); + assertEquals(testProps.get("TransportType"), "HTTPNOAUTH"); + } + + @Test + public void testCreateConsumerPropFileWithCustomProfile() { + String topic = "JunitTopicOne"; + Properties junitProps = new Properties(); + junitProps.put("host", "192.168.10.10"); + junitProps.put("group", "junit-client"); + junitProps.put("id", "junit-consumer-two"); + junitProps.put("filter", "none"); + + String junitFile = null; + + // set property for DMaaP profile + System.setProperty(DmaapUtil.DMAAP_PROPERTIES_PATH, "src/test/resources/org/onap/appc"); + + // set configuration to null to force reloading of properties + try { + configField.set(null, null); + } catch (IllegalArgumentException | IllegalAccessException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + try { + junitFile = DmaapUtil.createConsumerPropFile(topic, junitProps); + } catch (IOException e) { + e.printStackTrace(); + fail("Exception creating consumer property file"); + } + + assertNotNull(junitFile); + + // open file and verify properties + File testFile = new File(junitFile); + assertTrue(testFile.exists()); + + InputStream is = null; + Properties testProps = new Properties(); + try { + is = new FileInputStream(testFile); + testProps.load(is); + } catch (FileNotFoundException e) { + e.printStackTrace(); + fail("Exception opening consumer property file"); + } catch (IOException e) { + e.printStackTrace(); + fail("Exception opening consumer property file"); + } finally { + try { + if (is != null) { + is.close(); + } + } catch (IOException ex) { + ex.printStackTrace(); + fail("Exception closing consumer property file"); + } + } + + assertFalse(testProps.isEmpty()); + + assertEquals(testProps.get("host"), "192.168.10.10"); + assertEquals(testProps.get("group"), "junit-client"); + assertEquals(testProps.get("id"), "junit-consumer-two"); + assertEquals(testProps.get("filter"), "none"); + assertEquals(testProps.get("TransportType"), "HTTPAAF"); + } + + @Test + public void testCreateProducerPropFile() { + String topic = "JunitTopicOne"; + Properties junitProps = new Properties(); + junitProps.put("host", "192.168.10.10"); + junitProps.put("group", "junit-client"); + junitProps.put("id", "junit-producer-one"); + junitProps.put("filter", "none"); + + String junitFile = null; + + // ensure file path property is not set + if (System.getProperty(DmaapUtil.DMAAP_PROPERTIES_PATH) != null) { + System.clearProperty(DmaapUtil.DMAAP_PROPERTIES_PATH); + + // set configuration to null to force reloading of properties + try { + configField.set(null, null); + } catch (IllegalArgumentException | IllegalAccessException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + + try { + junitFile = DmaapUtil.createProducerPropFile(topic, junitProps); + } catch (IOException e) { + e.printStackTrace(); + fail("Exception creating consumer property file"); + } + + assertNotNull(junitFile); + + // open file and verify properties + File testFile = new File(junitFile); + assertTrue(testFile.exists()); + + InputStream is = null; + Properties testProps = new Properties(); + try { + is = new FileInputStream(testFile); + testProps.load(is); + } catch (FileNotFoundException e) { + e.printStackTrace(); + fail("Exception opening consumer property file"); + } catch (IOException e) { + e.printStackTrace(); + fail("Exception opening consumer property file"); + } finally { + try { + if (is != null) { + is.close(); + } + } catch (IOException ex) { + ex.printStackTrace(); + fail("Exception closing consumer property file"); + } + } + + assertFalse(testProps.isEmpty()); + + assertEquals(testProps.get("host"), "192.168.10.10"); + assertEquals(testProps.get("group"), "junit-client"); + assertEquals(testProps.get("id"), "junit-producer-one"); + assertEquals(testProps.get("filter"), "none"); + assertEquals("HTTPNOAUTH", testProps.get("TransportType")); + } + + /** + * Use reflection to locate fields and methods so that they can be + * manipulated during the test to change the internal state accordingly. + * + * @throws NoSuchFieldException + * if the field(s) dont exist + * @throws SecurityException + * if reflective access is not allowed + * @throws NoSuchMethodException + * If the method(s) dont exist + */ + @SuppressWarnings("nls") + @BeforeClass + public static void once() throws NoSuchFieldException, SecurityException, NoSuchMethodException { + configurationFactoryClass = ConfigurationFactory.class; + + configField = configurationFactoryClass.getDeclaredField("config"); + configField.setAccessible(true); + } +} -- cgit 1.2.3-korg