diff options
Diffstat (limited to 'src/test/java/org/onap/dmaap/mr/tools')
12 files changed, 1103 insertions, 998 deletions
diff --git a/src/test/java/org/onap/dmaap/mr/tools/ApiKeyCommandTest.java b/src/test/java/org/onap/dmaap/mr/tools/ApiKeyCommandTest.java index f86d4f2..cd801c3 100644 --- a/src/test/java/org/onap/dmaap/mr/tools/ApiKeyCommandTest.java +++ b/src/test/java/org/onap/dmaap/mr/tools/ApiKeyCommandTest.java @@ -4,12 +4,14 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright © 2021 Orange. + * ================================================================================ * 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. @@ -20,14 +22,10 @@ package org.onap.dmaap.mr.tools; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.io.PrintStream; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - +import com.att.nsa.apiClient.credentials.ApiCredential; +import com.att.nsa.apiClient.http.HttpException; +import com.att.nsa.apiClient.http.HttpObjectNotFoundException; +import com.att.nsa.cmdtool.CommandNotReadyException; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -35,185 +33,188 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.onap.dmaap.mr.client.MRClient.MRApiException; +import org.onap.dmaap.mr.client.MRClientFactory; +import org.onap.dmaap.mr.client.MRIdentityManager; +import org.onap.dmaap.mr.client.MRIdentityManager.ApiKey; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; -import com.att.nsa.apiClient.credentials.ApiCredential; -import com.att.nsa.apiClient.http.HttpException; -import com.att.nsa.apiClient.http.HttpObjectNotFoundException; -import com.att.nsa.cmdtool.CommandNotReadyException; -import org.onap.dmaap.mr.client.MRClient.MRApiException; -import org.onap.dmaap.mr.client.MRClientFactory; -import org.onap.dmaap.mr.client.MRIdentityManager; -import org.onap.dmaap.mr.client.MRIdentityManager.ApiKey; +import java.io.IOException; +import java.io.PrintStream; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; + +import static org.junit.Assert.assertTrue; @RunWith(PowerMockRunner.class) @PowerMockIgnore("jdk.internal.reflect.*") -@PrepareForTest({ MRClientFactory.class }) +@PrepareForTest({MRClientFactory.class}) public class ApiKeyCommandTest { - @InjectMocks - private ApiKeyCommand command; - @Mock - private MRIdentityManager tm; - @Mock - private ApiKey ti; - @Mock - private ApiKey key; - @Mock - private ApiCredential ac; - @Mock - private PrintStream printStream; - - @Before - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - PowerMockito.mockStatic(MRClientFactory.class); - PowerMockito.when(MRClientFactory.createIdentityManager(Arrays.asList("localhost"), null, null)).thenReturn(tm); - PowerMockito.when(tm.getApiKey("testtopic")).thenReturn(key); - PowerMockito.when(tm.createApiKey("testtopic", "1")).thenReturn(ac); - - } - - @After - public void tearDown() throws Exception { - - } - - @Test - public void testGetMatches() { - - command.getMatches(); - assertTrue(true); - - } - - @Test - public void testCheckReady() { - - try { - command.checkReady(new MRCommandContext()); - } catch (CommandNotReadyException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - assertTrue(true); - - } - - @Test - public void testExecute() { - - String[] parts1 = { "create", "testtopic", "1" }; - String[] parts2 = { "list", "testtopic", "1" }; - String[] parts3 = { "revoke", "write", "read" }; - List<String[]> parts = Arrays.asList(parts1, parts2, parts3); - for (Iterator iterator = parts.iterator(); iterator.hasNext();) { - String[] part = (String[]) iterator.next(); - - try { - command.execute(part, new MRCommandContext(), printStream); - } catch (CommandNotReadyException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - assertTrue(true); - - } - } - - @Test - public void testExecute_error1() throws HttpObjectNotFoundException, HttpException, MRApiException, IOException { - PowerMockito.when(tm.getApiKey("testtopic")).thenThrow(new IOException("error")); - String[] parts1 = { "create", "testtopic", "1" }; - String[] parts2 = { "list", "testtopic", "1" }; - String[] parts3 = { "revoke", "write", "read" }; - List<String[]> parts = Arrays.asList(parts1, parts2, parts3); - for (Iterator iterator = parts.iterator(); iterator.hasNext();) { - String[] part = (String[]) iterator.next(); - - try { - command.execute(part, new MRCommandContext(), printStream); - } catch (CommandNotReadyException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - assertTrue(true); - } - - } - - @Test - public void testExecute_error2() throws HttpObjectNotFoundException, HttpException, MRApiException, IOException { - PowerMockito.when(tm.getApiKey("testtopic")).thenThrow(new MRApiException("error")); - String[] parts1 = { "create", "testtopic", "1" }; - String[] parts2 = { "list", "testtopic", "1" }; - String[] parts3 = { "revoke", "write", "read" }; - List<String[]> parts = Arrays.asList(parts1, parts2, parts3); - for (Iterator iterator = parts.iterator(); iterator.hasNext();) { - String[] part = (String[]) iterator.next(); - - try { - command.execute(part, new MRCommandContext(),printStream); - } catch (CommandNotReadyException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - assertTrue(true); - - } - } - - @Test - public void testExecute_error3() throws HttpObjectNotFoundException, HttpException, MRApiException, IOException { - PowerMockito.when(tm.getApiKey("testtopic")).thenThrow(new HttpException(500, "error")); - String[] parts1 = { "create", "testtopic", "1" }; - String[] parts2 = { "list", "testtopic", "1" }; - String[] parts3 = { "revoke", "write", "read" }; - List<String[]> parts = Arrays.asList(parts1, parts2, parts3); - for (Iterator iterator = parts.iterator(); iterator.hasNext();) { - String[] part = (String[]) iterator.next(); - - try { - command.execute(part, new MRCommandContext(), printStream); - } catch (CommandNotReadyException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - assertTrue(true); - } - - } - - @Test - public void testExecute_error4() throws HttpObjectNotFoundException, HttpException, MRApiException, IOException { - PowerMockito.when(tm.getApiKey("testtopic")).thenThrow(new HttpObjectNotFoundException("error")); - String[] parts1 = { "create", "testtopic", "1" }; - String[] parts2 = { "list", "testtopic", "1" }; - String[] parts3 = { "revoke", "write", "read" }; - List<String[]> parts = Arrays.asList(parts1, parts2, parts3); - for (Iterator iterator = parts.iterator(); iterator.hasNext();) { - String[] part = (String[]) iterator.next(); - - try { - command.execute(part, new MRCommandContext(), printStream); - } catch (CommandNotReadyException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - assertTrue(true); - - } - } - - @Test - public void testDisplayHelp() { - - command.displayHelp(printStream); - assertTrue(true); - - } + @InjectMocks + private ApiKeyCommand command; + @Mock + private MRIdentityManager tm; + @Mock + private ApiKey ti; + @Mock + private ApiKey key; + @Mock + private ApiCredential ac; + @Mock + private PrintStream printStream; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + PowerMockito.mockStatic(MRClientFactory.class); + PowerMockito.when(MRClientFactory.createIdentityManager(Arrays.asList("localhost"), null, null)).thenReturn(tm); + PowerMockito.when(tm.getApiKey("testtopic")).thenReturn(key); + PowerMockito.when(tm.createApiKey("testtopic", "1")).thenReturn(ac); + + } + + @After + public void tearDown() throws Exception { + + } + + @Test + public void testGetMatches() { + + command.getMatches(); + assertTrue(true); + + } + + @Test + public void testCheckReady() { + + try { + command.checkReady(new MRCommandContext()); + } catch (CommandNotReadyException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + assertTrue(true); + + } + + @Test + public void testExecute() { + + String[] parts1 = {"create", "testtopic", "1"}; + String[] parts2 = {"list", "testtopic", "1"}; + String[] parts3 = {"revoke", "write", "read"}; + List<String[]> parts = Arrays.asList(parts1, parts2, parts3); + for (Iterator iterator = parts.iterator(); iterator.hasNext(); ) { + String[] part = (String[]) iterator.next(); + + try { + command.execute(part, new MRCommandContext(), printStream); + } catch (CommandNotReadyException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + assertTrue(true); + + } + } + + @Test + public void testExecute_error1() throws HttpObjectNotFoundException, HttpException, MRApiException, IOException { + PowerMockito.when(tm.getApiKey("testtopic")).thenThrow(new IOException("error")); + String[] parts1 = {"create", "testtopic", "1"}; + String[] parts2 = {"list", "testtopic", "1"}; + String[] parts3 = {"revoke", "write", "read"}; + List<String[]> parts = Arrays.asList(parts1, parts2, parts3); + for (Iterator iterator = parts.iterator(); iterator.hasNext(); ) { + String[] part = (String[]) iterator.next(); + + try { + command.execute(part, new MRCommandContext(), printStream); + } catch (CommandNotReadyException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + assertTrue(true); + } + + } + + @Test + public void testExecute_error2() throws HttpObjectNotFoundException, HttpException, MRApiException, IOException { + PowerMockito.when(tm.getApiKey("testtopic")).thenThrow(new MRApiException("error")); + String[] parts1 = {"create", "testtopic", "1"}; + String[] parts2 = {"list", "testtopic", "1"}; + String[] parts3 = {"revoke", "write", "read"}; + List<String[]> parts = Arrays.asList(parts1, parts2, parts3); + for (Iterator iterator = parts.iterator(); iterator.hasNext(); ) { + String[] part = (String[]) iterator.next(); + + try { + command.execute(part, new MRCommandContext(), printStream); + } catch (CommandNotReadyException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + assertTrue(true); + + } + } + + @Test + public void testExecute_error3() throws HttpObjectNotFoundException, HttpException, MRApiException, IOException { + PowerMockito.when(tm.getApiKey("testtopic")).thenThrow(new HttpException(500, "error")); + String[] parts1 = {"create", "testtopic", "1"}; + String[] parts2 = {"list", "testtopic", "1"}; + String[] parts3 = {"revoke", "write", "read"}; + List<String[]> parts = Arrays.asList(parts1, parts2, parts3); + for (Iterator iterator = parts.iterator(); iterator.hasNext(); ) { + String[] part = (String[]) iterator.next(); + + try { + command.execute(part, new MRCommandContext(), printStream); + } catch (CommandNotReadyException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + assertTrue(true); + } + + } + + @Test + public void testExecute_error4() throws HttpObjectNotFoundException, HttpException, MRApiException, IOException { + PowerMockito.when(tm.getApiKey("testtopic")).thenThrow(new HttpObjectNotFoundException("error")); + String[] parts1 = {"create", "testtopic", "1"}; + String[] parts2 = {"list", "testtopic", "1"}; + String[] parts3 = {"revoke", "write", "read"}; + List<String[]> parts = Arrays.asList(parts1, parts2, parts3); + for (Iterator iterator = parts.iterator(); iterator.hasNext(); ) { + String[] part = (String[]) iterator.next(); + + try { + command.execute(part, new MRCommandContext(), printStream); + } catch (CommandNotReadyException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + assertTrue(true); + + } + } + + @Test + public void testDisplayHelp() { + + command.displayHelp(printStream); + assertTrue(true); + + } } diff --git a/src/test/java/org/onap/dmaap/mr/tools/AuthCommandTest.java b/src/test/java/org/onap/dmaap/mr/tools/AuthCommandTest.java index e312d9b..4966f30 100644 --- a/src/test/java/org/onap/dmaap/mr/tools/AuthCommandTest.java +++ b/src/test/java/org/onap/dmaap/mr/tools/AuthCommandTest.java @@ -4,12 +4,14 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright © 2021 Orange. + * ================================================================================ * 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. @@ -20,10 +22,7 @@ package org.onap.dmaap.mr.tools; -import static org.junit.Assert.assertTrue; - -import java.io.PrintStream; - +import com.att.nsa.cmdtool.CommandNotReadyException; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -34,82 +33,84 @@ import org.mockito.MockitoAnnotations; import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.modules.junit4.PowerMockRunner; -import com.att.nsa.cmdtool.CommandNotReadyException; +import java.io.PrintStream; + +import static org.junit.Assert.assertTrue; @RunWith(PowerMockRunner.class) @PowerMockIgnore("jdk.internal.reflect.*") public class AuthCommandTest { - @InjectMocks - private AuthCommand command = null; - @Mock - private PrintStream printStream; + @InjectMocks + private AuthCommand command = null; + @Mock + private PrintStream printStream; - @Before - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); - } + } - @After - public void tearDown() throws Exception { + @After + public void tearDown() throws Exception { - } + } - @Test - public void testGetMatches() { + @Test + public void testGetMatches() { - command.getMatches(); - assertTrue(true); + command.getMatches(); + assertTrue(true); - } + } - @Test - public void testCheckReady() { + @Test + public void testCheckReady() { - try { - command.checkReady(new MRCommandContext()); - } catch (CommandNotReadyException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - assertTrue(true); + try { + command.checkReady(new MRCommandContext()); + } catch (CommandNotReadyException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + assertTrue(true); - } + } - @Test - public void testExecute() { + @Test + public void testExecute() { - try { - String[] parts = new String[5]; - command.execute(parts, new MRCommandContext(), printStream); - } catch (CommandNotReadyException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - assertTrue(true); + try { + String[] parts = new String[5]; + command.execute(parts, new MRCommandContext(), printStream); + } catch (CommandNotReadyException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + assertTrue(true); - } + } - @Test - public void testExecute1() { + @Test + public void testExecute1() { - try { - String[] parts = { "userName", "password" }; - command.execute(parts, new MRCommandContext(), printStream); - } catch (CommandNotReadyException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - assertTrue(true); + try { + String[] parts = {"userName", "password"}; + command.execute(parts, new MRCommandContext(), printStream); + } catch (CommandNotReadyException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + assertTrue(true); - } + } - @Test - public void testDisplayHelp() { + @Test + public void testDisplayHelp() { - command.displayHelp(printStream); - assertTrue(true); + command.displayHelp(printStream); + assertTrue(true); - } + } } diff --git a/src/test/java/org/onap/dmaap/mr/tools/ClusterCommandTest.java b/src/test/java/org/onap/dmaap/mr/tools/ClusterCommandTest.java index 5d78488..e503e21 100644 --- a/src/test/java/org/onap/dmaap/mr/tools/ClusterCommandTest.java +++ b/src/test/java/org/onap/dmaap/mr/tools/ClusterCommandTest.java @@ -4,12 +4,14 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright © 2021 Orange. + * ================================================================================ * 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. @@ -20,12 +22,7 @@ package org.onap.dmaap.mr.tools; -import static org.junit.Assert.assertTrue; - -import java.io.FileNotFoundException; -import java.io.PrintStream; -import java.util.Arrays; - +import com.att.nsa.cmdtool.CommandNotReadyException; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -37,72 +34,76 @@ import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.modules.junit4.PowerMockRunner; -import com.att.nsa.cmdtool.CommandNotReadyException; +import java.io.FileNotFoundException; +import java.io.PrintStream; +import java.util.Arrays; + +import static org.junit.Assert.assertTrue; @RunWith(PowerMockRunner.class) @PowerMockIgnore("jdk.internal.reflect.*") public class ClusterCommandTest { - @InjectMocks - private ClusterCommand command; - @Mock - private MRCommandContext context; - @Mock - private PrintStream printStream; + @InjectMocks + private ClusterCommand command; + @Mock + private MRCommandContext context; + @Mock + private PrintStream printStream; - @Before - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - PowerMockito.when(context.getCluster()).thenReturn(Arrays.asList("localhost")); - } + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + PowerMockito.when(context.getCluster()).thenReturn(Arrays.asList("localhost")); + } - @After - public void tearDown() throws Exception { + @After + public void tearDown() throws Exception { - } + } - @Test - public void testGetMatches() { + @Test + public void testGetMatches() { - command.getMatches(); - assertTrue(true); + command.getMatches(); + assertTrue(true); - } + } - @Test - public void testCheckReady() { + @Test + public void testCheckReady() { - try { - command.checkReady(context); - } catch (CommandNotReadyException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - assertTrue(true); + try { + command.checkReady(context); + } catch (CommandNotReadyException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + assertTrue(true); - } + } - @Test - public void testExecute() throws FileNotFoundException, CommandNotReadyException { - String[] parts = { "create", "testtopic", "1", "1" }; - command.execute(parts, context, printStream); - assertTrue(true); + @Test + public void testExecute() throws FileNotFoundException, CommandNotReadyException { + String[] parts = {"create", "testtopic", "1", "1"}; + command.execute(parts, context, printStream); + assertTrue(true); - } + } - @Test - public void testExecute1() throws FileNotFoundException, CommandNotReadyException { - String[] parts = {}; - command.execute(parts, context, printStream); - assertTrue(true); + @Test + public void testExecute1() throws FileNotFoundException, CommandNotReadyException { + String[] parts = {}; + command.execute(parts, context, printStream); + assertTrue(true); - } + } - @Test - public void testDisplayHelp() { + @Test + public void testDisplayHelp() { - command.displayHelp(printStream); - assertTrue(true); + command.displayHelp(printStream); + assertTrue(true); - } + } } diff --git a/src/test/java/org/onap/dmaap/mr/tools/JUnitTestSuite.java b/src/test/java/org/onap/dmaap/mr/tools/JUnitTestSuite.java index 782dbb0..a0642ff 100644 --- a/src/test/java/org/onap/dmaap/mr/tools/JUnitTestSuite.java +++ b/src/test/java/org/onap/dmaap/mr/tools/JUnitTestSuite.java @@ -4,12 +4,14 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright © 2021 Orange. + * ================================================================================ * 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. @@ -21,7 +23,6 @@ package org.onap.dmaap.mr.tools; import junit.framework.TestSuite; - import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; @@ -29,18 +30,18 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; @RunWith(Suite.class) -@SuiteClasses({ ApiKeyCommandTest.class, AuthCommandTest.class, ClusterCommandTest.class, - MessageCommandTest.class, MRCommandContextTest.class, TopicCommandTest.class, TraceCommandTest.class,}) +@SuiteClasses({ApiKeyCommandTest.class, AuthCommandTest.class, ClusterCommandTest.class, + MessageCommandTest.class, MRCommandContextTest.class, TopicCommandTest.class, TraceCommandTest.class,}) public class JUnitTestSuite { - private static final Logger LOGGER = LoggerFactory.getLogger(JUnitTestSuite.class); + private static final Logger logger = LoggerFactory.getLogger(JUnitTestSuite.class); + + public static void main(String[] args) { + logger.info("Running the test suite"); - public static void main(String[] args) { - LOGGER.info("Running the test suite"); - - TestSuite tstSuite = new TestSuite(); - LOGGER.info("Total Test Counts " + tstSuite.countTestCases()); - } + TestSuite tstSuite = new TestSuite(); + logger.info("Total Test Counts " + tstSuite.countTestCases()); + } } diff --git a/src/test/java/org/onap/dmaap/mr/tools/MRCommandContextTest.java b/src/test/java/org/onap/dmaap/mr/tools/MRCommandContextTest.java index 8e778d4..806f302 100644 --- a/src/test/java/org/onap/dmaap/mr/tools/MRCommandContextTest.java +++ b/src/test/java/org/onap/dmaap/mr/tools/MRCommandContextTest.java @@ -4,12 +4,14 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright © 2021 Orange. + * ================================================================================ * 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. @@ -20,135 +22,134 @@ package org.onap.dmaap.mr.tools; -import static org.junit.Assert.assertTrue; - - import org.junit.After; import org.junit.Before; import org.junit.Test; +import static org.junit.Assert.assertTrue; + public class MRCommandContextTest { - private MRCommandContext command = null; - private String[] parts = new String[5]; + private MRCommandContext command = null; + private String[] parts = new String[5]; - @Before - public void setUp() throws Exception { - command = new MRCommandContext(); + @Before + public void setUp() throws Exception { + command = new MRCommandContext(); - for (int i = 0; i < parts.length; i++) { - parts[i] = "String" + (i + 1); - } + for (int i = 0; i < parts.length; i++) { + parts[i] = "String" + (i + 1); + } - } + } - @After - public void tearDown() throws Exception { + @After + public void tearDown() throws Exception { - } + } - @Test - public void testRequestShutdown() { + @Test + public void testRequestShutdown() { - command.requestShutdown(); - assertTrue(true); + command.requestShutdown(); + assertTrue(true); - } + } - @Test - public void testShouldContinue() { + @Test + public void testShouldContinue() { - command.shouldContinue(); - assertTrue(true); + command.shouldContinue(); + assertTrue(true); - } + } - @Test - public void testSetAuth() { + @Test + public void testSetAuth() { - command.setAuth("key", "pwd"); - assertTrue(true); + command.setAuth("key", "pwd"); + assertTrue(true); - } + } - @Test - public void testClearAuth() { + @Test + public void testClearAuth() { - command.clearAuth(); - assertTrue(true); + command.clearAuth(); + assertTrue(true); - } + } - @Test - public void testCheckClusterReady() { + @Test + public void testCheckClusterReady() { - command.checkClusterReady(); - assertTrue(true); + command.checkClusterReady(); + assertTrue(true); - } + } - @Test - public void testGetCluster() { + @Test + public void testGetCluster() { - command.getCluster(); - assertTrue(true); + command.getCluster(); + assertTrue(true); - } + } - @Test - public void testClearCluster() { + @Test + public void testClearCluster() { - command.clearCluster(); - assertTrue(true); + command.clearCluster(); + assertTrue(true); - } + } - @Test - public void testAddClusterHost() { + @Test + public void testAddClusterHost() { - command.addClusterHost("host"); - assertTrue(true); + command.addClusterHost("host"); + assertTrue(true); - } + } - @Test - public void testGetApiKey() { + @Test + public void testGetApiKey() { - command.getApiKey(); - assertTrue(true); + command.getApiKey(); + assertTrue(true); - } + } - @Test - public void testGetApiPwd() { + @Test + public void testGetApiPwd() { - command.getApiPwd(); - assertTrue(true); + command.getApiPwd(); + assertTrue(true); - } + } - @Test - public void testUseTracer() { + @Test + public void testUseTracer() { - command.useTracer(null); - assertTrue(true); + command.useTracer(null); + assertTrue(true); - } + } - @Test - public void testNoTracer() { + @Test + public void testNoTracer() { - command.noTracer(); - assertTrue(true); + command.noTracer(); + assertTrue(true); - } + } - @Test - public void testApplyTracer() { + @Test + public void testApplyTracer() { - command.applyTracer(null); - assertTrue(true); + command.applyTracer(null); + assertTrue(true); - } + } } diff --git a/src/test/java/org/onap/dmaap/mr/tools/MRTool.java b/src/test/java/org/onap/dmaap/mr/tools/MRTool.java new file mode 100644 index 0000000..022f2ee --- /dev/null +++ b/src/test/java/org/onap/dmaap/mr/tools/MRTool.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Modifications Copyright © 2021 Orange. + * ================================================================================ + * 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========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * + *******************************************************************************/ + +package org.onap.dmaap.mr.tools; + +import com.att.nsa.cmdtool.CommandLineTool; +import org.onap.dmaap.mr.client.impl.MRClientVersionInfo; + +import java.io.IOException; + +public class MRTool extends CommandLineTool<MRCommandContext> { + protected MRTool() { + super("MR Tool (" + MRClientVersionInfo.getVersion() + ")", "MR> "); + + registerCommand(new ApiKeyCommand()); + registerCommand(new AuthCommand()); + registerCommand(new ClusterCommand()); + registerCommand(new MessageCommand()); + registerCommand(new TopicCommand()); + registerCommand(new TraceCommand()); + } + + public static void main(String[] args) throws IOException { + final MRTool ct = new MRTool(); + final MRCommandContext ccc = new MRCommandContext(); + ct.runFromMain(args, ccc); + } +} diff --git a/src/test/java/org/onap/dmaap/mr/tools/MessageCommandTest.java b/src/test/java/org/onap/dmaap/mr/tools/MessageCommandTest.java index 933ee48..c6c9af4 100644 --- a/src/test/java/org/onap/dmaap/mr/tools/MessageCommandTest.java +++ b/src/test/java/org/onap/dmaap/mr/tools/MessageCommandTest.java @@ -4,12 +4,14 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright © 2021 Orange. + * ================================================================================ * 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. @@ -20,15 +22,7 @@ package org.onap.dmaap.mr.tools; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.io.PrintStream; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; -import java.util.concurrent.TimeUnit; - +import com.att.nsa.cmdtool.CommandNotReadyException; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -36,181 +30,188 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.onap.dmaap.mr.client.MRBatchingPublisher; +import org.onap.dmaap.mr.client.MRClientFactory; +import org.onap.dmaap.mr.client.MRConsumer; +import org.onap.dmaap.mr.client.MRTopicManager.TopicInfo; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; -import com.att.nsa.cmdtool.CommandNotReadyException; -import org.onap.dmaap.mr.client.MRBatchingPublisher; -import org.onap.dmaap.mr.client.MRClientFactory; -import org.onap.dmaap.mr.client.MRConsumer; -import org.onap.dmaap.mr.client.MRTopicManager.TopicInfo; +import java.io.IOException; +import java.io.PrintStream; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import static org.junit.Assert.assertTrue; @RunWith(PowerMockRunner.class) @PowerMockIgnore("jdk.internal.reflect.*") -@PrepareForTest({ MRClientFactory.class, ToolsUtil.class }) +@PrepareForTest({MRClientFactory.class, ToolsUtil.class}) public class MessageCommandTest { - @InjectMocks - private MessageCommand command; - @Mock - private MRConsumer tm; - @Mock - private TopicInfo ti; - @Mock - private MRBatchingPublisher pub; - @Mock - private MRConsumer cc; - @Mock - private PrintStream printStream; - - @Before - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - PowerMockito.mockStatic(MRClientFactory.class); - PowerMockito.mockStatic(ToolsUtil.class); - PowerMockito.when(MRClientFactory.createConsumer(Arrays.asList("localhost"), "testtopic", "2", "3", -1, -1, - null, null, null)).thenReturn(cc); - - } - - @After - public void tearDown() throws Exception { - - } - - @Test - public void testGetMatches() { - - command.getMatches(); - assertTrue(true); - - } - - @Test - public void testCheckReady() { - - try { - command.checkReady(new MRCommandContext()); - } catch (CommandNotReadyException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - assertTrue(true); - - } - - @Test - public void testExecute() { - - String[] parts1 = { "read", "testtopic", "2", "3" }; - String[] parts2 = { "write", "testtopic", "2", "3" }; - List<String[]> parts = Arrays.asList(parts1, parts2); - for (Iterator iterator = parts.iterator(); iterator.hasNext();) { - String[] part = (String[]) iterator.next(); - - MRCommandContext context = new MRCommandContext(); - PowerMockito.when(ToolsUtil.createBatchPublisher(context, "testtopic")).thenReturn(pub); - try { - command.execute(part, context, printStream); - } catch (CommandNotReadyException e) { - assertTrue(true); - } - } - assertTrue(true); - - } - - @Test - public void testExecute_error1() { - try { - PowerMockito.doThrow(new Exception()).when(cc).fetch(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - String[] parts1 = { "read", "testtopic", "2", "3" }; - String[] parts2 = { "write", "testtopic", "2", "3" }; - List<String[]> parts = Arrays.asList(parts1, parts2); - for (Iterator iterator = parts.iterator(); iterator.hasNext();) { - String[] part = (String[]) iterator.next(); - - MRCommandContext context = new MRCommandContext(); - PowerMockito.when(ToolsUtil.createBatchPublisher(context, "testtopic")).thenReturn(pub); - try { - command.execute(part, context, printStream); - } catch (CommandNotReadyException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - assertTrue(true); - - } - - @Test - public void testExecute_error2() { - try { - PowerMockito.doThrow(new IOException()).when(pub).close(500, TimeUnit.MILLISECONDS); - PowerMockito.doThrow(new IOException()).when(pub).send("2", "3"); - - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - String[] parts1 = { "read", "testtopic", "2", "3" }; - String[] parts2 = { "write", "testtopic", "2", "3" }; - List<String[]> parts = Arrays.asList(parts1, parts2); - for (Iterator iterator = parts.iterator(); iterator.hasNext();) { - String[] part = (String[]) iterator.next(); - - MRCommandContext context = new MRCommandContext(); - PowerMockito.when(ToolsUtil.createBatchPublisher(context, "testtopic")).thenReturn(pub); - try { - command.execute(part, context, printStream); - } catch (CommandNotReadyException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - assertTrue(true); - - } - - /* - * @Test public void testExecute_error3() { - * - * try { PowerMockito.doThrow(new IOException()).when(pub).send("2", "3"); - * PowerMockito.doThrow(new InterruptedException()).when(pub).close(500, - * TimeUnit.MILLISECONDS); } catch (IOException e) { // TODO Auto-generated - * catch block e.printStackTrace(); } catch (InterruptedException e) { // - * TODO Auto-generated catch block e.printStackTrace(); } String[] parts1 = - * { "read", "testtopic", "2", "3" }; String[] parts2 = { "write", - * "testtopic", "2", "3" }; List<String[]> parts = Arrays.asList(parts1, - * parts2); for (Iterator iterator = parts.iterator(); iterator.hasNext();) - * { String[] part = (String[]) iterator.next(); PrintStream printStream = - * new PrintStream(System.out); - * - * MRCommandContext context = new MRCommandContext(); - * PowerMockito.when(ToolsUtil.createBatchPublisher(context, - * "testtopic")).thenReturn(pub); try { command.execute(part, context, - * printStream); } catch (CommandNotReadyException e) { // TODO - * Auto-generated catch block e.printStackTrace(); } } assertTrue(true); - * - * } - */ - - @Test - public void testDisplayHelp() { - - command.displayHelp(printStream); - - } + @InjectMocks + private MessageCommand command; + @Mock + private MRConsumer tm; + @Mock + private TopicInfo ti; + @Mock + private MRBatchingPublisher pub; + @Mock + private MRConsumer cc; + @Mock + private PrintStream printStream; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + PowerMockito.mockStatic(MRClientFactory.class); + PowerMockito.mockStatic(ToolsUtil.class); + PowerMockito.when(MRClientFactory.createConsumer(Arrays.asList("localhost"), "testtopic", "2", "3", -1, -1, + null, null, null)).thenReturn(cc); + + } + + @After + public void tearDown() throws Exception { + + } + + @Test + public void testGetMatches() { + + command.getMatches(); + assertTrue(true); + + } + + @Test + public void testCheckReady() { + + try { + command.checkReady(new MRCommandContext()); + } catch (CommandNotReadyException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + assertTrue(true); + + } + + @Test + public void testExecute() { + + String[] parts1 = {"read", "testtopic", "2", "3"}; + String[] parts2 = {"write", "testtopic", "2", "3"}; + List<String[]> parts = Arrays.asList(parts1, parts2); + for (Iterator iterator = parts.iterator(); iterator.hasNext(); ) { + String[] part = (String[]) iterator.next(); + + MRCommandContext context = new MRCommandContext(); + PowerMockito.when(ToolsUtil.createBatchPublisher(context, "testtopic")).thenReturn(pub); + try { + command.execute(part, context, printStream); + } catch (CommandNotReadyException e) { + assertTrue(true); + } + } + assertTrue(true); + + } + + @Test + public void testExecute_error1() { + try { + PowerMockito.doThrow(new Exception()).when(cc).fetch(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + String[] parts1 = {"read", "testtopic", "2", "3"}; + String[] parts2 = {"write", "testtopic", "2", "3"}; + List<String[]> parts = Arrays.asList(parts1, parts2); + for (Iterator iterator = parts.iterator(); iterator.hasNext(); ) { + String[] part = (String[]) iterator.next(); + + MRCommandContext context = new MRCommandContext(); + PowerMockito.when(ToolsUtil.createBatchPublisher(context, "testtopic")).thenReturn(pub); + try { + command.execute(part, context, printStream); + } catch (CommandNotReadyException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + assertTrue(true); + + } + + @Test + public void testExecute_error2() { + try { + PowerMockito.doThrow(new IOException()).when(pub).close(500, TimeUnit.MILLISECONDS); + PowerMockito.doThrow(new IOException()).when(pub).send("2", "3"); + + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + String[] parts1 = {"read", "testtopic", "2", "3"}; + String[] parts2 = {"write", "testtopic", "2", "3"}; + List<String[]> parts = Arrays.asList(parts1, parts2); + for (Iterator iterator = parts.iterator(); iterator.hasNext(); ) { + String[] part = (String[]) iterator.next(); + + MRCommandContext context = new MRCommandContext(); + PowerMockito.when(ToolsUtil.createBatchPublisher(context, "testtopic")).thenReturn(pub); + try { + command.execute(part, context, printStream); + } catch (CommandNotReadyException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + assertTrue(true); + + } + + /* + * @Test public void testExecute_error3() { + * + * try { PowerMockito.doThrow(new IOException()).when(pub).send("2", "3"); + * PowerMockito.doThrow(new InterruptedException()).when(pub).close(500, + * TimeUnit.MILLISECONDS); } catch (IOException e) { // TODO Auto-generated + * catch block e.printStackTrace(); } catch (InterruptedException e) { // + * TODO Auto-generated catch block e.printStackTrace(); } String[] parts1 = + * { "read", "testtopic", "2", "3" }; String[] parts2 = { "write", + * "testtopic", "2", "3" }; List<String[]> parts = Arrays.asList(parts1, + * parts2); for (Iterator iterator = parts.iterator(); iterator.hasNext();) + * { String[] part = (String[]) iterator.next(); PrintStream printStream = + * new PrintStream(System.out); + * + * MRCommandContext context = new MRCommandContext(); + * PowerMockito.when(ToolsUtil.createBatchPublisher(context, + * "testtopic")).thenReturn(pub); try { command.execute(part, context, + * printStream); } catch (CommandNotReadyException e) { // TODO + * Auto-generated catch block e.printStackTrace(); } } assertTrue(true); + * + * } + */ + + @Test + public void testDisplayHelp() { + + command.displayHelp(printStream); + assertTrue(true); + } } diff --git a/src/test/java/org/onap/dmaap/mr/tools/TestRunner.java b/src/test/java/org/onap/dmaap/mr/tools/TestRunner.java index 2fd831b..3e2380f 100644 --- a/src/test/java/org/onap/dmaap/mr/tools/TestRunner.java +++ b/src/test/java/org/onap/dmaap/mr/tools/TestRunner.java @@ -4,12 +4,14 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright © 2021 Orange. + * ================================================================================ * 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. @@ -28,17 +30,17 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class TestRunner { - private static final Logger LOGGER = LoggerFactory.getLogger(TestRunner.class); + private static final Logger logger = LoggerFactory.getLogger(TestRunner.class); + + public static void main(String[] args) { + // TODO Auto-generated method stub + Result result = JUnitCore.runClasses(JUnitTestSuite.class); + for (Failure failure : result.getFailures()) { + logger.info(failure.toString()); - public static void main(String[] args) { - // TODO Auto-generated method stub - Result result = JUnitCore.runClasses(JUnitTestSuite.class); - for (Failure failure : result.getFailures()) { - LOGGER.info(failure.toString()); - - } - LOGGER.info(String.valueOf(result.wasSuccessful())); - } + } + logger.info(String.valueOf(result.wasSuccessful())); + } } diff --git a/src/test/java/org/onap/dmaap/mr/tools/ToolsUtilTest.java b/src/test/java/org/onap/dmaap/mr/tools/ToolsUtilTest.java index 080d6d5..115e007 100644 --- a/src/test/java/org/onap/dmaap/mr/tools/ToolsUtilTest.java +++ b/src/test/java/org/onap/dmaap/mr/tools/ToolsUtilTest.java @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2018 Nokia * ================================================================================ + * Modifications Copyright © 2021 Orange. + * ================================================================================ * 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 @@ -23,12 +25,13 @@ */ package org.onap.dmaap.mr.tools; -import org.onap.dmaap.mr.client.MRBatchingPublisher; -import java.util.Arrays; -import java.util.List; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; +import org.onap.dmaap.mr.client.MRBatchingPublisher; + +import java.util.Arrays; +import java.util.List; public class ToolsUtilTest { diff --git a/src/test/java/org/onap/dmaap/mr/tools/TopicCommandTest.java b/src/test/java/org/onap/dmaap/mr/tools/TopicCommandTest.java index 4abd1e4..bcb95cd 100644 --- a/src/test/java/org/onap/dmaap/mr/tools/TopicCommandTest.java +++ b/src/test/java/org/onap/dmaap/mr/tools/TopicCommandTest.java @@ -4,12 +4,14 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright © 2021 Orange. + * ================================================================================ * 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. @@ -20,14 +22,9 @@ package org.onap.dmaap.mr.tools; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.io.PrintStream; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - +import com.att.nsa.apiClient.http.HttpException; +import com.att.nsa.apiClient.http.HttpObjectNotFoundException; +import com.att.nsa.cmdtool.CommandNotReadyException; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -35,192 +32,196 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.onap.dmaap.mr.client.MRClientFactory; +import org.onap.dmaap.mr.client.MRTopicManager; +import org.onap.dmaap.mr.client.MRTopicManager.TopicInfo; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; -import com.att.nsa.apiClient.http.HttpException; -import com.att.nsa.apiClient.http.HttpObjectNotFoundException; -import com.att.nsa.cmdtool.CommandNotReadyException; -import org.onap.dmaap.mr.client.MRClientFactory; -import org.onap.dmaap.mr.client.MRTopicManager.TopicInfo; -import org.onap.dmaap.mr.client.MRTopicManager; +import java.io.IOException; +import java.io.PrintStream; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; + +import static org.junit.Assert.assertTrue; @RunWith(PowerMockRunner.class) @PowerMockIgnore("jdk.internal.reflect.*") -@PrepareForTest({ MRClientFactory.class }) +@PrepareForTest({MRClientFactory.class}) public class TopicCommandTest { - @InjectMocks - private TopicCommand command; - @Mock - private MRTopicManager tm; - @Mock - private TopicInfo ti; - @Mock - private PrintStream printStream; - - @Before - public void setUp() throws Exception { - - MockitoAnnotations.initMocks(this); - PowerMockito.mockStatic(MRClientFactory.class); - PowerMockito.when(MRClientFactory.createTopicManager(Arrays.asList("localhost"), null, null)).thenReturn(tm); - PowerMockito.when(tm.getTopicMetadata("testtopic")).thenReturn(ti); - - } - - @After - public void tearDown() throws Exception { - - } - - @Test - public void testGetMatches() { - - command.getMatches(); - assertTrue(true); - - } - - @Test - public void testCheckReady() { - - try { - command.checkReady(new MRCommandContext()); - } catch (CommandNotReadyException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - assertTrue(true); - - } - - @Test - public void testExecute() { - - String[] parts1 = { "create", "testtopic", "1", "1" }; - String[] parts2 = { "grant", "write", "read", "1" }; - String[] parts3 = { "revoke", "write", "read", "1" }; - String[] parts4 = { "list", "testtopic", "1", "1" }; - List<String[]> parts = Arrays.asList(parts1, parts2, parts3, parts4); - for (Iterator iterator = parts.iterator(); iterator.hasNext();) { - String[] part = (String[]) iterator.next(); - - try { - command.execute(part, new MRCommandContext(), printStream); - } catch (CommandNotReadyException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - assertTrue(true); - - } - - } - - @Test - public void testExecute_error() { - - String[] parts1 = { "create", "testtopic", "1", "1" }; - String[] parts2 = { "grant", "write", "read", "1" }; - String[] parts3 = { "revoke", "write", "read", "1" }; - String[] parts4 = { "list", "testtopic", "1", "1" }; - List<String[]> parts = Arrays.asList(parts1, parts2, parts3, parts4); - for (Iterator iterator = parts.iterator(); iterator.hasNext();) { - String[] part = (String[]) iterator.next(); - - try { - command.execute(part, new MRCommandContext(), printStream); - } catch (CommandNotReadyException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - assertTrue(true); - - } - - } - - @Test - public void testExecute_error_1() throws com.att.nsa.apiClient.http.HttpException, IOException { - PowerMockito.when(tm.getTopicMetadata("testtopic")).thenThrow(new IOException("error")); - PowerMockito.doThrow(new IOException()).when(tm).createTopic("testtopic", "", 1, 1); - PowerMockito.doThrow(new IOException()).when(tm).revokeProducer("read", "1"); - String[] parts1 = { "create", "testtopic", "1", "1" }; - String[] parts2 = { "grant", "read", "read", "1" }; - String[] parts3 = { "revoke", "write", "read", "1" }; - String[] parts4 = { "list", "testtopic", "1", "1" }; - List<String[]> parts = Arrays.asList(parts1, parts2, parts3, parts4); - for (Iterator iterator = parts.iterator(); iterator.hasNext();) { - String[] part = (String[]) iterator.next(); - - try { - command.execute(part, new MRCommandContext(), printStream); - } catch (CommandNotReadyException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - assertTrue(true); - - } - - } - - @Test - public void testExecute_error_2() throws com.att.nsa.apiClient.http.HttpException, IOException { - PowerMockito.when(tm.getTopicMetadata("testtopic")).thenThrow(new HttpObjectNotFoundException("error")); - PowerMockito.doThrow(new HttpException(500, "error")).when(tm).createTopic("testtopic", "", 1, 1); - PowerMockito.doThrow(new HttpException(500, "error")).when(tm).revokeConsumer("read", "1"); - PowerMockito.doThrow(new HttpException(500, "error")).when(tm).allowConsumer("read", "1"); - String[] parts1 = { "create", "testtopic", "1", "1" }; - String[] parts2 = { "grant", "write", "write", "1" }; - String[] parts3 = { "revoke", "read", "read", "1" }; - String[] parts4 = { "list", "testtopic", "1", "1" }; - List<String[]> parts = Arrays.asList(parts1, parts2, parts3, parts4); - for (Iterator iterator = parts.iterator(); iterator.hasNext();) { - String[] part = (String[]) iterator.next(); - - try { - command.execute(part, new MRCommandContext(), printStream); - } catch (CommandNotReadyException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - assertTrue(true); - - } - - } - - @Test - public void testExecute_error_3() throws com.att.nsa.apiClient.http.HttpException, IOException { - PowerMockito.doThrow(new HttpException(500, "error")).when(tm).createTopic("testtopic", "", 1, 1); - PowerMockito.doThrow(new HttpException(500, "error")).when(tm).allowProducer("read", "1"); - String[] parts1 = { "create", "testtopic", "1a", "1a" }; - String[] parts2 = { "grant", "write", "read", "1" }; - List<String[]> parts = Arrays.asList(parts1, parts2); - for (Iterator iterator = parts.iterator(); iterator.hasNext();) { - String[] part = (String[]) iterator.next(); - - try { - command.execute(part, new MRCommandContext(), printStream); - } catch (CommandNotReadyException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - assertTrue(true); - - } - - } - - @Test - public void testDisplayHelp() { - - command.displayHelp(printStream); - assertTrue(true); - - } + @InjectMocks + private TopicCommand command; + @Mock + private MRTopicManager tm; + @Mock + private TopicInfo ti; + @Mock + private PrintStream printStream; + + @Before + public void setUp() throws Exception { + + MockitoAnnotations.initMocks(this); + PowerMockito.mockStatic(MRClientFactory.class); + PowerMockito.when(MRClientFactory.createTopicManager(Arrays.asList("localhost"), null, null)).thenReturn(tm); + PowerMockito.when(tm.getTopicMetadata("testtopic")).thenReturn(ti); + + } + + @After + public void tearDown() throws Exception { + + } + + @Test + public void testGetMatches() { + + command.getMatches(); + assertTrue(true); + + } + + @Test + public void testCheckReady() { + + try { + command.checkReady(new MRCommandContext()); + } catch (CommandNotReadyException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + assertTrue(true); + + } + + @Test + public void testExecute() { + + String[] parts1 = {"create", "testtopic", "1", "1"}; + String[] parts2 = {"grant", "write", "read", "1"}; + String[] parts3 = {"revoke", "write", "read", "1"}; + String[] parts4 = {"list", "testtopic", "1", "1"}; + List<String[]> parts = Arrays.asList(parts1, parts2, parts3, parts4); + for (Iterator iterator = parts.iterator(); iterator.hasNext(); ) { + String[] part = (String[]) iterator.next(); + + try { + command.execute(part, new MRCommandContext(), printStream); + } catch (CommandNotReadyException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + assertTrue(true); + + } + + } + + @Test + public void testExecute_error() { + + String[] parts1 = {"create", "testtopic", "1", "1"}; + String[] parts2 = {"grant", "write", "read", "1"}; + String[] parts3 = {"revoke", "write", "read", "1"}; + String[] parts4 = {"list", "testtopic", "1", "1"}; + List<String[]> parts = Arrays.asList(parts1, parts2, parts3, parts4); + for (Iterator iterator = parts.iterator(); iterator.hasNext(); ) { + String[] part = (String[]) iterator.next(); + + try { + command.execute(part, new MRCommandContext(), printStream); + } catch (CommandNotReadyException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + assertTrue(true); + + } + + } + + @Test + public void testExecute_error_1() throws com.att.nsa.apiClient.http.HttpException, IOException { + PowerMockito.when(tm.getTopicMetadata("testtopic")).thenThrow(new IOException("error")); + PowerMockito.doThrow(new IOException()).when(tm).createTopic("testtopic", "", 1, 1); + PowerMockito.doThrow(new IOException()).when(tm).revokeProducer("read", "1"); + String[] parts1 = {"create", "testtopic", "1", "1"}; + String[] parts2 = {"grant", "read", "read", "1"}; + String[] parts3 = {"revoke", "write", "read", "1"}; + String[] parts4 = {"list", "testtopic", "1", "1"}; + List<String[]> parts = Arrays.asList(parts1, parts2, parts3, parts4); + for (Iterator iterator = parts.iterator(); iterator.hasNext(); ) { + String[] part = (String[]) iterator.next(); + + try { + command.execute(part, new MRCommandContext(), printStream); + } catch (CommandNotReadyException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + assertTrue(true); + + } + + } + + @Test + public void testExecute_error_2() throws com.att.nsa.apiClient.http.HttpException, IOException { + PowerMockito.when(tm.getTopicMetadata("testtopic")).thenThrow(new HttpObjectNotFoundException("error")); + PowerMockito.doThrow(new HttpException(500, "error")).when(tm).createTopic("testtopic", "", 1, 1); + PowerMockito.doThrow(new HttpException(500, "error")).when(tm).revokeConsumer("read", "1"); + PowerMockito.doThrow(new HttpException(500, "error")).when(tm).allowConsumer("read", "1"); + String[] parts1 = {"create", "testtopic", "1", "1"}; + String[] parts2 = {"grant", "write", "write", "1"}; + String[] parts3 = {"revoke", "read", "read", "1"}; + String[] parts4 = {"list", "testtopic", "1", "1"}; + List<String[]> parts = Arrays.asList(parts1, parts2, parts3, parts4); + for (Iterator iterator = parts.iterator(); iterator.hasNext(); ) { + String[] part = (String[]) iterator.next(); + + try { + command.execute(part, new MRCommandContext(), printStream); + } catch (CommandNotReadyException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + assertTrue(true); + + } + + } + + @Test + public void testExecute_error_3() throws com.att.nsa.apiClient.http.HttpException, IOException { + PowerMockito.doThrow(new HttpException(500, "error")).when(tm).createTopic("testtopic", "", 1, 1); + PowerMockito.doThrow(new HttpException(500, "error")).when(tm).allowProducer("read", "1"); + String[] parts1 = {"create", "testtopic", "1a", "1a"}; + String[] parts2 = {"grant", "write", "read", "1"}; + List<String[]> parts = Arrays.asList(parts1, parts2); + for (Iterator iterator = parts.iterator(); iterator.hasNext(); ) { + String[] part = (String[]) iterator.next(); + + try { + command.execute(part, new MRCommandContext(), printStream); + } catch (CommandNotReadyException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + assertTrue(true); + + } + + } + + @Test + public void testDisplayHelp() { + + command.displayHelp(printStream); + assertTrue(true); + + } } diff --git a/src/test/java/org/onap/dmaap/mr/tools/TraceCommandTest.java b/src/test/java/org/onap/dmaap/mr/tools/TraceCommandTest.java index ab4d670..ae97c1e 100644 --- a/src/test/java/org/onap/dmaap/mr/tools/TraceCommandTest.java +++ b/src/test/java/org/onap/dmaap/mr/tools/TraceCommandTest.java @@ -4,12 +4,14 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright © 2021 Orange. + * ================================================================================ * 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. @@ -20,10 +22,7 @@ package org.onap.dmaap.mr.tools; -import static org.junit.Assert.assertTrue; - -import java.io.PrintStream; - +import com.att.nsa.cmdtool.CommandNotReadyException; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -34,71 +33,73 @@ import org.mockito.MockitoAnnotations; import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.modules.junit4.PowerMockRunner; -import com.att.nsa.cmdtool.CommandNotReadyException; +import java.io.PrintStream; + +import static org.junit.Assert.assertTrue; @RunWith(PowerMockRunner.class) @PowerMockIgnore("jdk.internal.reflect.*") public class TraceCommandTest { - @InjectMocks - private TraceCommand command; - private String[] parts = new String[5]; - @Mock - private PrintStream printStream; + @InjectMocks + private TraceCommand command; + private String[] parts = new String[5]; + @Mock + private PrintStream printStream; - @Before - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - for (int i = 0; i < parts.length; i++) { - parts[i] = "String" + (i + 1); - } + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + for (int i = 0; i < parts.length; i++) { + parts[i] = "String" + (i + 1); + } - } + } - @After - public void tearDown() throws Exception { + @After + public void tearDown() throws Exception { - } + } - @Test - public void testGetMatches() { + @Test + public void testGetMatches() { - command.getMatches(); - assertTrue(true); + command.getMatches(); + assertTrue(true); - } + } - @Test - public void testCheckReady() { + @Test + public void testCheckReady() { - try { - command.checkReady(new MRCommandContext()); - } catch (CommandNotReadyException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - assertTrue(true); + try { + command.checkReady(new MRCommandContext()); + } catch (CommandNotReadyException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + assertTrue(true); - } + } - @Test - public void testExecute() { + @Test + public void testExecute() { - try { - command.execute(parts, new MRCommandContext(), printStream); - } catch (CommandNotReadyException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - assertTrue(true); + try { + command.execute(parts, new MRCommandContext(), printStream); + } catch (CommandNotReadyException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + assertTrue(true); - } + } - @Test - public void testDisplayHelp() { + @Test + public void testDisplayHelp() { - command.displayHelp(printStream); - assertTrue(true); + command.displayHelp(printStream); + assertTrue(true); - } + } } diff --git a/src/test/java/org/onap/dmaap/mr/tools/ValidatorUtilTest.java b/src/test/java/org/onap/dmaap/mr/tools/ValidatorUtilTest.java index baa5440..198f828 100644 --- a/src/test/java/org/onap/dmaap/mr/tools/ValidatorUtilTest.java +++ b/src/test/java/org/onap/dmaap/mr/tools/ValidatorUtilTest.java @@ -4,11 +4,13 @@ * ================================================================================ * Copyright © 2018 IBM Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright © 2021 Orange. + * ================================================================================ * 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. @@ -17,192 +19,244 @@ * ============LICENSE_END========================================================= * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * + * *******************************************************************************/ package org.onap.dmaap.mr.tools; -import static org.junit.Assert.assertEquals; +import org.junit.Test; +import org.onap.dmaap.mr.client.ProtocolType; import java.util.Properties; -import org.junit.Test; - -import org.onap.dmaap.mr.test.clients.ProtocolTypeConstants; +import static org.junit.Assert.*; public class ValidatorUtilTest { @Test public void testValidateForDME2WithNullServiceName() { Properties props = new Properties(); - props.setProperty("TransportType", ProtocolTypeConstants.DME2.getValue()); - try{ + props.setProperty("TransportType", ProtocolType.DME2.getValue()); + try { ValidatorUtil.validatePublisher(props); - } catch(IllegalArgumentException e) { - assertEquals(e.getMessage(), "Servicename is needed"); + fail(); + } catch (IllegalArgumentException e) { + assertEquals("ServiceName is needed", e.getMessage()); } } - + @Test public void testValidateForDME2WithNullTopic() { Properties props = new Properties(); - props.setProperty("TransportType", ProtocolTypeConstants.DME2.getValue()); + props.setProperty("TransportType", ProtocolType.DME2.getValue()); props.setProperty("ServiceName", "ServiceName"); - try{ + try { ValidatorUtil.validatePublisher(props); - } catch(IllegalArgumentException e) { - assertEquals(e.getMessage(), "topic is needed"); + fail(); + } catch (IllegalArgumentException e) { + assertEquals("topic is needed", e.getMessage()); } - + } - + @Test public void testValidateForDME2WithNullUserName() { Properties props = new Properties(); - props.setProperty("TransportType", ProtocolTypeConstants.DME2.getValue()); + props.setProperty("TransportType", ProtocolType.DME2.getValue()); props.setProperty("ServiceName", "ServiceName"); props.setProperty("topic", "topic"); - try{ + try { ValidatorUtil.validatePublisher(props); - } catch(IllegalArgumentException e) { - assertEquals(e.getMessage(), "username is needed"); + fail(); + } catch (IllegalArgumentException e) { + assertEquals("username is needed", e.getMessage()); } - + } - + @Test public void testValidateForDME2WithNullPassword() { Properties props = new Properties(); - props.setProperty("TransportType", ProtocolTypeConstants.DME2.getValue()); + props.setProperty("TransportType", ProtocolType.DME2.getValue()); props.setProperty("ServiceName", "ServiceName"); props.setProperty("topic", "topic"); props.setProperty("username", "username"); - - try{ + + try { ValidatorUtil.validatePublisher(props); - } catch(IllegalArgumentException e) { - assertEquals(e.getMessage(), "password is needed"); + fail(); + } catch (IllegalArgumentException e) { + assertEquals("password is needed", e.getMessage()); } - + } - - - - + + @Test public void testValidateForNonDME2WithNullServiceName() { Properties props = new Properties(); - props.setProperty("TransportType", ProtocolTypeConstants.AUTH_KEY.getValue()); - try{ + props.setProperty("TransportType", ProtocolType.AUTH_KEY.getValue()); + try { ValidatorUtil.validatePublisher(props); - } catch(IllegalArgumentException e) { - assertEquals(e.getMessage(), "Servicename is needed"); + fail(); + } catch (IllegalArgumentException e) { + assertEquals("host is needed", e.getMessage()); } - + } - + @Test public void testValidateForNonDME2WithNullTopic() { Properties props = new Properties(); - props.setProperty("TransportType", ProtocolTypeConstants.AUTH_KEY.getValue()); + props.setProperty("TransportType", ProtocolType.AUTH_KEY.getValue()); props.setProperty("host", "ServiceName"); - try{ + try { ValidatorUtil.validatePublisher(props); - } catch(IllegalArgumentException e) { - assertEquals(e.getMessage(), "topic is needed"); + fail(); + } catch (IllegalArgumentException e) { + assertEquals("topic is needed", e.getMessage()); } - + } - + @Test public void testValidateForNonDME2WithNullContenttype() { Properties props = new Properties(); - props.setProperty("TransportType", ProtocolTypeConstants.AUTH_KEY.getValue()); + props.setProperty("TransportType", ProtocolType.AUTH_KEY.getValue()); props.setProperty("host", "ServiceName"); props.setProperty("topic", "topic"); - try{ + try { ValidatorUtil.validatePublisher(props); - } catch(IllegalArgumentException e) { - assertEquals(e.getMessage(), "contenttype is needed"); + fail(); + } catch (IllegalArgumentException e) { + assertEquals("contenttype is needed", e.getMessage()); } - + } - + @Test public void testValidateForNonDME2WithNullUserName() { Properties props = new Properties(); - props.setProperty("TransportType", ProtocolTypeConstants.AUTH_KEY.getValue()); + props.setProperty("TransportType", ProtocolType.AUTH_KEY.getValue()); props.setProperty("host", "ServiceName"); props.setProperty("topic", "topic"); props.setProperty("contenttype", "contenttype"); - try{ + try { ValidatorUtil.validatePublisher(props); - } catch(IllegalArgumentException e) { - assertEquals(e.getMessage(), "username is needed"); + fail(); + } catch (IllegalArgumentException e) { + assertEquals("username is needed", e.getMessage()); } - + } - + @Test public void testValidateForNonDME2WithNullPassword() { Properties props = new Properties(); - props.setProperty("TransportType", ProtocolTypeConstants.AUTH_KEY.getValue()); + props.setProperty("TransportType", ProtocolType.AUTH_KEY.getValue()); props.setProperty("host", "ServiceName"); props.setProperty("topic", "topic"); props.setProperty("username", "username"); props.setProperty("contenttype", "contenttype"); - - try{ + + try { ValidatorUtil.validatePublisher(props); - } catch(IllegalArgumentException e) { - assertEquals(e.getMessage(), "password is needed"); + fail(); + } catch (IllegalArgumentException e) { + assertEquals("password is needed", e.getMessage()); } - + } - + @Test public void testValidateForNonDME2WithAuthKey() { Properties props = new Properties(); - props.setProperty("TransportType", ProtocolTypeConstants.AUTH_KEY.getValue()); + props.setProperty("TransportType", ProtocolType.AUTH_KEY.getValue()); props.setProperty("host", "ServiceName"); props.setProperty("topic", "topic"); props.setProperty("username", "username"); props.setProperty("contenttype", "contenttype"); props.setProperty("password", "password"); - - try{ + + try { ValidatorUtil.validatePublisher(props); - } catch(IllegalArgumentException e) { - assertEquals(e.getMessage(), "authKey is needed"); + fail(); + } catch (IllegalArgumentException e) { + assertEquals("authKey is needed", e.getMessage()); } - + } - + @Test public void testValidateForNonDME2WithOutAuthDate() { Properties props = new Properties(); - props.setProperty("TransportType", ProtocolTypeConstants.AUTH_KEY.getValue()); + props.setProperty("TransportType", ProtocolType.AUTH_KEY.getValue()); props.setProperty("host", "ServiceName"); props.setProperty("topic", "topic"); props.setProperty("username", "username"); props.setProperty("contenttype", "contenttype"); props.setProperty("password", "password"); props.setProperty("authKey", "authKey"); - - - try{ + + + try { ValidatorUtil.validatePublisher(props); - } catch(IllegalArgumentException e) { - assertEquals(e.getMessage(), "authDate is needed"); + fail(); + } catch (IllegalArgumentException e) { + assertEquals("authDate is needed", e.getMessage()); } } - + @Test public void testValidateForNonDME2WithAuthDate() { Properties props = new Properties(); - props.setProperty("TransportType", ProtocolTypeConstants.AUTH_KEY.getValue()); + props.setProperty("TransportType", ProtocolType.AUTH_KEY.getValue()); + props.setProperty("host", "ServiceName"); + props.setProperty("topic", "topic"); + props.setProperty("username", "username"); + props.setProperty("contenttype", "contenttype"); + props.setProperty("password", "password"); + props.setProperty("authKey", "authKey"); + props.setProperty("authDate", "authDate"); + + try { + ValidatorUtil.validatePublisher(props); + fail(); + } catch (IllegalArgumentException e) { + assertEquals("maxBatchSize is needed", e.getMessage()); + } + } + + + @Test + public void testValidateForNonDME2WithMaxAgeMs() { + Properties props = new Properties(); + props.setProperty("TransportType", ProtocolType.AUTH_KEY.getValue()); + props.setProperty("host", "ServiceName"); + props.setProperty("topic", "topic"); + props.setProperty("username", "username"); + props.setProperty("contenttype", "contenttype"); + props.setProperty("password", "password"); + props.setProperty("authKey", "authKey"); + props.setProperty("authDate", "authDate"); + props.setProperty("maxBatchSize", "maxBatchSize"); + + try { + ValidatorUtil.validatePublisher(props); + fail(); + } catch (IllegalArgumentException e) { + assertEquals("maxAgeMs is needed", e.getMessage()); + } + + + } + + @Test + public void testValidateForNonDME2WithMessageSentThreadOccurrence() { + Properties props = new Properties(); + props.setProperty("TransportType", ProtocolType.AUTH_KEY.getValue()); props.setProperty("host", "ServiceName"); props.setProperty("topic", "topic"); props.setProperty("username", "username"); @@ -210,106 +264,95 @@ public class ValidatorUtilTest { props.setProperty("password", "password"); props.setProperty("authKey", "authKey"); props.setProperty("authDate", "authDate"); - - try{ + props.setProperty("maxBatchSize", "maxBatchSize"); + props.setProperty("maxAgeMs", "maxAgeMs"); + + try { ValidatorUtil.validatePublisher(props); - } catch(IllegalArgumentException e) { - assertEquals(e.getMessage(), "maxBatchSize is needed"); + fail(); + } catch (IllegalArgumentException e) { + assertEquals("MessageSentThreadOccurrence is needed", e.getMessage()); } + } - - - @Test - public void testValidateForNonDME2WithMaxAgeMs() { - Properties props = new Properties(); - props.setProperty("TransportType", ProtocolTypeConstants.AUTH_KEY.getValue()); - props.setProperty("host", "ServiceName"); - props.setProperty("topic", "topic"); - props.setProperty("username", "username"); - props.setProperty("contenttype", "contenttype"); - props.setProperty("password", "password"); - props.setProperty("authKey", "authKey"); - props.setProperty("authDate", "authDate"); - props.setProperty("maxBatchSize", "maxBatchSize"); - - try{ - ValidatorUtil.validatePublisher(props); - } catch(IllegalArgumentException e) { - assertEquals(e.getMessage(), "maxAgeMs is needed"); - } - - - + + + @Test + public void testValidateSubscriberWithoutGroup() { + Properties props = new Properties(); + props.setProperty("TransportType", ProtocolType.AUTH_KEY.getValue()); + props.setProperty("host", "ServiceName"); + props.setProperty("topic", "topic"); + props.setProperty("username", "username"); + props.setProperty("contenttype", "contenttype"); + props.setProperty("password", "password"); + props.setProperty("authKey", "authKey"); + props.setProperty("authDate", "authDate"); + props.setProperty("maxBatchSize", "maxBatchSize"); + props.setProperty("maxAgeMs", "maxAgeMs"); + + try { + ValidatorUtil.validateSubscriber(props); + fail(); + } catch (IllegalArgumentException e) { + assertEquals("group is needed", e.getMessage()); + } } - - @Test - public void testValidateForNonDME2WithMessageSentThreadOccurance() { - Properties props = new Properties(); - props.setProperty("TransportType", ProtocolTypeConstants.AUTH_KEY.getValue()); - props.setProperty("host", "ServiceName"); - props.setProperty("topic", "topic"); - props.setProperty("username", "username"); - props.setProperty("contenttype", "contenttype"); - props.setProperty("password", "password"); - props.setProperty("authKey", "authKey"); - props.setProperty("authDate", "authDate"); - props.setProperty("maxBatchSize", "maxBatchSize"); - props.setProperty("maxAgeMs", "maxAgeMs"); - - try{ - ValidatorUtil.validatePublisher(props); - } catch(IllegalArgumentException e) { - assertEquals(e.getMessage(), "MessageSentThreadOccurance is needed"); - } - + + @Test + public void testValidateSubscriberWithoutCustomer() { + Properties props = new Properties(); + props.setProperty("TransportType", ProtocolType.AUTH_KEY.getValue()); + props.setProperty("host", "ServiceName"); + props.setProperty("topic", "topic"); + props.setProperty("username", "username"); + props.setProperty("contenttype", "contenttype"); + props.setProperty("password", "password"); + props.setProperty("authKey", "authKey"); + props.setProperty("authDate", "authDate"); + props.setProperty("maxBatchSize", "maxBatchSize"); + props.setProperty("maxAgeMs", "maxAgeMs"); + props.setProperty("group", "group"); + + try { + ValidatorUtil.validateSubscriber(props); + fail(); + } catch (IllegalArgumentException e) { + assertEquals("Consumer (id) is needed", e.getMessage()); } - - - @Test - public void testValidateSubscriberWithoutGroup() { - Properties props = new Properties(); - props.setProperty("TransportType", ProtocolTypeConstants.AUTH_KEY.getValue()); - props.setProperty("host", "ServiceName"); - props.setProperty("topic", "topic"); - props.setProperty("username", "username"); - props.setProperty("contenttype", "contenttype"); - props.setProperty("password", "password"); - props.setProperty("authKey", "authKey"); - props.setProperty("authDate", "authDate"); - props.setProperty("maxBatchSize", "maxBatchSize"); - props.setProperty("maxAgeMs", "maxAgeMs"); - - try{ - ValidatorUtil.validateSubscriber(props); - } catch(IllegalArgumentException e) { - assertEquals(e.getMessage(), "group is needed"); - } - } - - @Test - public void testValidateSubscriberWithoutCustomer() { - Properties props = new Properties(); - props.setProperty("TransportType", ProtocolTypeConstants.AUTH_KEY.getValue()); - props.setProperty("host", "ServiceName"); - props.setProperty("topic", "topic"); - props.setProperty("username", "username"); - props.setProperty("contenttype", "contenttype"); - props.setProperty("password", "password"); - props.setProperty("authKey", "authKey"); - props.setProperty("authDate", "authDate"); - props.setProperty("maxBatchSize", "maxBatchSize"); - props.setProperty("maxAgeMs", "maxAgeMs"); - props.setProperty("group", "group"); - - try{ - ValidatorUtil.validateSubscriber(props); - } catch(IllegalArgumentException e) { - assertEquals(e.getMessage(), "Consumer (Id) is needed"); - } - } - - - - - + } + + @Test + public void testValidatePublisher() { + Properties props = new Properties(); + props.setProperty("TransportType", ProtocolType.AUTH_KEY.getValue()); + props.setProperty("host", "ServiceName"); + props.setProperty("topic", "topic"); + props.setProperty("username", "username"); + props.setProperty("contenttype", "contenttype"); + props.setProperty("password", "password"); + props.setProperty("authKey", "authKey"); + props.setProperty("authDate", "authDate"); + props.setProperty("maxBatchSize", "maxBatchSize"); + props.setProperty("maxAgeMs", "maxAgeMs"); + props.setProperty("MessageSentThreadOccurrence", "10"); + + try { + ValidatorUtil.validatePublisher(props); + } catch (IllegalArgumentException e) { + fail(); + return; + } + + props.remove("MessageSentThreadOccurrence"); + props.setProperty("MessageSentThreadOccurance", "10"); + try { + ValidatorUtil.validatePublisher(props); + } catch (IllegalArgumentException e) { + fail(); + } + } + + + } |