diff options
author | 2018-08-14 09:34:46 -0400 | |
---|---|---|
committer | 2018-08-14 09:39:23 -0400 | |
commit | b32effcaf5684d5e2f338a4537b71a2375c534e5 (patch) | |
tree | e1b80407f414509ffcc766b987ec6a95f7254b4e /src/test/java/com/att/nsa/cambria/service/impl/EventsServiceImplTest.java | |
parent | 0823cb186012c8e6b7de3d979dfabb9f838da7c2 (diff) |
update the testcases after the kafka 11 changes
Issue-ID: DMAAP-526
Change-Id: I477a8ee05fb3cdd76af726b6ca0d1a69aa9eef93
Signed-off-by: sunil unnava <su622b@att.com>
Diffstat (limited to 'src/test/java/com/att/nsa/cambria/service/impl/EventsServiceImplTest.java')
-rw-r--r-- | src/test/java/com/att/nsa/cambria/service/impl/EventsServiceImplTest.java | 556 |
1 files changed, 201 insertions, 355 deletions
diff --git a/src/test/java/com/att/nsa/cambria/service/impl/EventsServiceImplTest.java b/src/test/java/com/att/nsa/cambria/service/impl/EventsServiceImplTest.java index d1c2d2a..8cd560d 100644 --- a/src/test/java/com/att/nsa/cambria/service/impl/EventsServiceImplTest.java +++ b/src/test/java/com/att/nsa/cambria/service/impl/EventsServiceImplTest.java @@ -18,10 +18,11 @@ * ============LICENSE_END=========================================================
*/
-
package com.att.nsa.cambria.service.impl;
+
import static org.mockito.Mockito.when;
import static org.mockito.Matchers.anyString;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
@@ -31,6 +32,7 @@ import java.io.InputStream; import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.ConcurrentModificationException;
import java.util.Map;
import java.util.Properties;
@@ -39,6 +41,7 @@ import org.junit.Before; import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@@ -48,419 +51,262 @@ import org.springframework.mock.web.MockHttpServletResponse; import com.att.ajsc.beans.PropertiesMapBean;
import com.att.ajsc.filemonitor.AJSCPropertiesMap;
-import com.att.nsa.cambria.CambriaApiException;
-import com.att.nsa.cambria.backends.ConsumerFactory.UnavailableException;
-import com.att.nsa.cambria.beans.DMaaPCambriaLimiter;
-import com.att.nsa.cambria.beans.DMaaPContext;
-import com.att.nsa.cambria.constants.CambriaConstants;
-import com.att.nsa.cambria.embed.EmbedConfigurationReader;
-import com.att.nsa.cambria.exception.DMaaPAccessDeniedException;
-import com.att.nsa.cambria.exception.DMaaPErrorMessages;
-import com.att.nsa.cambria.metabroker.Topic;
-import com.att.nsa.cambria.metabroker.Broker.TopicExistsException;
-import com.att.nsa.cambria.security.DMaaPAuthenticator;
-import com.att.nsa.cambria.security.DMaaPAuthenticatorImpl;
-import com.att.nsa.cambria.utils.ConfigurationReader;
-import com.att.nsa.cambria.utils.PropertyReader;
+import com.att.dmf.mr.CambriaApiException;
+import com.att.dmf.mr.security.DMaaPAAFAuthenticator;
+import com.att.dmf.mr.security.DMaaPAuthenticator;
+import com.att.dmf.mr.security.DMaaPAuthenticatorImpl;
+import com.att.dmf.mr.utils.ConfigurationReader;
+import com.att.dmf.mr.backends.ConsumerFactory.UnavailableException;
+import com.att.dmf.mr.beans.DMaaPCambriaLimiter;
+import com.att.dmf.mr.backends.ConsumerFactory;
+import com.att.dmf.mr.beans.DMaaPContext;
+import com.att.dmf.mr.beans.DMaaPKafkaMetaBroker;
+import com.att.dmf.mr.constants.CambriaConstants;
+import com.att.dmf.mr.exception.DMaaPAccessDeniedException;
+import com.att.dmf.mr.exception.DMaaPErrorMessages;
+import com.att.dmf.mr.metabroker.Topic;
+import com.att.dmf.mr.metabroker.Broker.TopicExistsException;
+import com.att.dmf.mr.service.impl.EventsServiceImpl;
+import com.att.dmf.mr.utils.PropertyReader;
import com.att.nsa.configs.ConfigDbException;
import com.att.nsa.drumlin.till.nv.rrNvReadable.invalidSettingValue;
import com.att.nsa.drumlin.till.nv.rrNvReadable.loadException;
import com.att.nsa.drumlin.till.nv.rrNvReadable.missingReqdSetting;
import com.att.nsa.limits.Blacklist;
import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;
+import com.att.nsa.security.NsaApiKey;
import com.att.nsa.security.db.simple.NsaSimpleApiKey;
import kafka.admin.AdminUtils;
-
-public class EventsServiceImplTest {
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({ DMaaPAuthenticatorImpl.class, AJSCPropertiesMap.class })
+public class EventsServiceImplTest {
private InputStream iStream = null;
DMaaPContext dMaapContext = new DMaaPContext();
EventsServiceImpl service = new EventsServiceImpl();
DMaaPErrorMessages pErrorMessages = new DMaaPErrorMessages();
-
+ @Mock
ConfigurationReader configurationReader;
- EmbedConfigurationReader embedConfigurationReader = new EmbedConfigurationReader();
-
+ @Mock
+ Blacklist blacklist;
+ @Mock
+ DMaaPAuthenticator<NsaSimpleApiKey> dmaaPAuthenticator;
+ @Mock
+ DMaaPAAFAuthenticator dmaapAAFauthenticator;
+ @Mock
+ NsaApiKey user;
+ @Mock
+ NsaSimpleApiKey nsaSimpleApiKey;
+ @Mock
+ DMaaPKafkaMetaBroker dmaapKafkaMetaBroker;
+ @Mock
+ Topic createdTopic;
+ @Mock
+ ConsumerFactory factory;
@Before
public void setUp() throws Exception {
-
+ MockitoAnnotations.initMocks(this);
String source = "source of my InputStream";
iStream = new ByteArrayInputStream(source.getBytes("UTF-8"));
-
- configurationReader = embedConfigurationReader.buildConfigurationReader();
-
+
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
dMaapContext.setRequest(request);
dMaapContext.setResponse(response);
+ when(blacklist.contains(anyString())).thenReturn(false);
+ when(configurationReader.getfIpBlackList()).thenReturn(blacklist);
dMaapContext.setConfigReader(configurationReader);
-
+
service.setErrorMessages(pErrorMessages);
-
- Map<String, String> map = com.att.ajsc.filemonitor.AJSCPropertiesMap.getProperties(CambriaConstants.msgRtr_prop);
- map.put("timeout", "1000");
-
+ PowerMockito.mockStatic(AJSCPropertiesMap.class);
+ when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "timeout")).thenReturn("100");
+
+ AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "timeout");
+
}
- @After
- public void tearDown() throws Exception {
- embedConfigurationReader.tearDown();
+ @Test(expected = CambriaApiException.class)
+ public void testGetEvents() throws DMaaPAccessDeniedException, CambriaApiException, ConfigDbException,
+ TopicExistsException, AccessDeniedException, UnavailableException, IOException {
+ when(dmaaPAuthenticator.authenticate(dMaapContext)).thenReturn(nsaSimpleApiKey);
+ when(configurationReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
+ when(configurationReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
+ when(dmaapKafkaMetaBroker.getTopic("testTopic")).thenReturn(createdTopic);
+ PowerMockito.when(configurationReader.getfConsumerFactory()).thenReturn(factory);
+ service.getEvents(dMaapContext, "testTopic", "CG1", "23");
}
- @Test(expected=NullPointerException.class)
- public void testGetEventsForCambriaApiException() throws DMaaPAccessDeniedException, CambriaApiException, ConfigDbException, TopicExistsException, AccessDeniedException, UnavailableException, IOException {
- service.getEvents(dMaapContext, "testTopic", "CG1", null);
+ @Test(expected = CambriaApiException.class)
+ public void testGetEventsBlackListErr() throws DMaaPAccessDeniedException, CambriaApiException, ConfigDbException,
+ TopicExistsException, AccessDeniedException, UnavailableException, IOException {
+ when(blacklist.contains(anyString())).thenReturn(true);
+ when(configurationReader.getfIpBlackList()).thenReturn(blacklist);
+ dMaapContext.setConfigReader(configurationReader);
+ service.getEvents(dMaapContext, "testTopic", "CG1", "23");
}
-
- @Test(expected=CambriaApiException.class)
- public void testGetEventsForNoTopic() throws DMaaPAccessDeniedException, CambriaApiException, ConfigDbException, TopicExistsException, AccessDeniedException, UnavailableException, IOException {
-
+
+ @Test(expected = CambriaApiException.class)
+ public void testGetEventsNoTopicError() throws DMaaPAccessDeniedException, CambriaApiException, ConfigDbException,
+ TopicExistsException, AccessDeniedException, UnavailableException, IOException {
+ when(dmaaPAuthenticator.authenticate(dMaapContext)).thenReturn(nsaSimpleApiKey);
+ when(configurationReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
+ when(configurationReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
+ when(dmaapKafkaMetaBroker.getTopic("testTopic")).thenReturn(null);
+ PowerMockito.when(configurationReader.getfConsumerFactory()).thenReturn(factory);
service.getEvents(dMaapContext, "testTopic", "CG1", "23");
}
-
-
- @Test(expected=CambriaApiException.class)
- public void testPushEvents() throws DMaaPAccessDeniedException, CambriaApiException, ConfigDbException, TopicExistsException, AccessDeniedException, UnavailableException, IOException, missingReqdSetting, invalidSettingValue, loadException {
-
- //AdminUtils.createTopic(configurationReader.getZk(), "testTopic", 10, 1, new Properties());
-
+
+ @Test(expected = CambriaApiException.class)
+ public void testGetEventsuserNull() throws DMaaPAccessDeniedException, CambriaApiException, ConfigDbException,
+ TopicExistsException, AccessDeniedException, UnavailableException, IOException {
+ when(dmaaPAuthenticator.authenticate(dMaapContext)).thenReturn(null);
+ when(configurationReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
+ when(configurationReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
+ when(dmaapKafkaMetaBroker.getTopic("testTopic")).thenReturn(createdTopic);
+ PowerMockito.when(configurationReader.getfConsumerFactory()).thenReturn(factory);
+ MockHttpServletRequest mockRequest = new MockHttpServletRequest();
+ mockRequest.addHeader("Authorization", "passed");
+ dMaapContext.setRequest(mockRequest);
+ dMaapContext.getRequest().getHeader("Authorization");
+ service.getEvents(dMaapContext, "testTopic", "CG1", "23");
+ }
+
+ @Test(expected = CambriaApiException.class)
+ public void testGetEventsExcp2() throws DMaaPAccessDeniedException, CambriaApiException, ConfigDbException,
+ TopicExistsException, AccessDeniedException, UnavailableException, IOException {
+ when(dmaaPAuthenticator.authenticate(dMaapContext)).thenReturn(nsaSimpleApiKey);
+ when(configurationReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
+ when(configurationReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
+ when(dmaapKafkaMetaBroker.getTopic("testTopic")).thenReturn(createdTopic);
+ PowerMockito.when(configurationReader.getfConsumerFactory()).thenReturn(factory);
+ when(configurationReader.getfRateLimiter()).thenThrow(new ConcurrentModificationException("Error occurred"));
+ service.getEvents(dMaapContext, "testTopic", "CG1", "23");
+ }
+
+ @Test(expected = CambriaApiException.class)
+ public void testPushEvents() throws DMaaPAccessDeniedException, CambriaApiException, ConfigDbException,
+ TopicExistsException, AccessDeniedException, UnavailableException, IOException, missingReqdSetting,
+ invalidSettingValue, loadException {
+
+ // AdminUtils.createTopic(configurationReader.getZk(), "testTopic", 10,
+ // 1, new Properties());
+
configurationReader.setfRateLimiter(new DMaaPCambriaLimiter(new PropertyReader()));
-
+
+ when(dmaaPAuthenticator.authenticate(dMaapContext)).thenReturn(nsaSimpleApiKey);
+ when(configurationReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
+ when(configurationReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
+ when(dmaapKafkaMetaBroker.getTopic("testTopic")).thenReturn(createdTopic);
+ PowerMockito.when(configurationReader.getfConsumerFactory()).thenReturn(factory);
+
service.pushEvents(dMaapContext, "testTopic", iStream, "3", "12:00:00");
-
+
service.getEvents(dMaapContext, "testTopic", "CG1", "23");
-
- String trueValue = "True";
- assertTrue(trueValue.equalsIgnoreCase("True"));
+
+ /*
+ * String trueValue = "True";
+ * assertTrue(trueValue.equalsIgnoreCase("True"));
+ */
}
- /*@Test
- public void testPushEvents() {
-
- EventsServiceImpl service = new EventsServiceImpl();
-
- try {
-
- // InputStream iStream = new
- // ByteArrayInputStream(source.getBytes("UTF-8"));
- service.pushEvents(new DMaaPContext(), "testTopic", iStream, "3", "12:00:00");
-
- } catch (org.json.JSONException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (DMaaPAccessDeniedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (CambriaApiException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (ConfigDbException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (TopicExistsException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (AccessDeniedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (missingReqdSetting e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (NullPointerException e) {
- // TODO Auto-generated catch block
- // e.printStackTrace();
- assertTrue(true);
- }
-
- String trueValue = "True";
- assertTrue(trueValue.equalsIgnoreCase("True"));
+ @Test(expected = CambriaApiException.class)
+ public void testPushEventsBlackListedIp() throws DMaaPAccessDeniedException, CambriaApiException, ConfigDbException,
+ TopicExistsException, AccessDeniedException, UnavailableException, IOException, missingReqdSetting,
+ invalidSettingValue, loadException {
- }
+ // AdminUtils.createTopic(configurationReader.getZk(), "testTopic", 10,
+ // 1, new Properties());
+ when(blacklist.contains(anyString())).thenReturn(true);
+ when(configurationReader.getfIpBlackList()).thenReturn(blacklist);
+ configurationReader.setfRateLimiter(new DMaaPCambriaLimiter(new PropertyReader()));
+ when(dmaaPAuthenticator.authenticate(dMaapContext)).thenReturn(nsaSimpleApiKey);
+ when(configurationReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
+ when(configurationReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
+ when(dmaapKafkaMetaBroker.getTopic("testTopic")).thenReturn(createdTopic);
+ PowerMockito.when(configurationReader.getfConsumerFactory()).thenReturn(factory);
- @Test
- public void testPushEvents2() {
- Class clazz;
- try {
- clazz = Class.forName("EventsServiceImpl");
- Object obj = clazz.newInstance();
- Method method = clazz.getDeclaredMethod("pushEvents", null);
- method.setAccessible(true);
- method.invoke(obj, new DMaaPContext(), "testTopic", iStream, "partition", true, "media");
-
- } catch (ClassNotFoundException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- } catch (InstantiationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (NoSuchMethodException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (SecurityException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalArgumentException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- String trueValue = "True";
- assertTrue(trueValue.equalsIgnoreCase("True"));
+ service.pushEvents(dMaapContext, "testTopic", iStream, "3", "12:00:00");
}
-
- @Test
- public void testPushEvents3() {
- Class clazz;
- try {
- clazz = Class.forName("EventsServiceImpl");
- Object obj = clazz.newInstance();
- Method method = clazz.getDeclaredMethod("pushEvents", null);
- method.setAccessible(true);
- method.invoke(obj, new DMaaPContext(), iStream, "testTopic", iStream, "partition", true, "media");
-
- } catch (ClassNotFoundException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- } catch (InstantiationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (NoSuchMethodException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (SecurityException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalArgumentException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- String trueValue = "True";
- assertTrue(trueValue.equalsIgnoreCase("True"));
- }
+ @Test(expected = NullPointerException.class)
+ public void testPushEventsNoUser() throws DMaaPAccessDeniedException, CambriaApiException, ConfigDbException,
+ TopicExistsException, AccessDeniedException, UnavailableException, IOException, missingReqdSetting,
+ invalidSettingValue, loadException {
- @Test
- public void testAddTransactionDetailsToMessage() {
- Class clazz;
- try {
- clazz = Class.forName("EventsServiceImpl");
- Object obj = clazz.newInstance();
- Method method = clazz.getDeclaredMethod("addTransactionDetailsToMessage", null);
- method.setAccessible(true);
- method.invoke(obj, new MessageTest(), "testTopic", null, "11:00:00", 1234, 100l, true);
-
- } catch (ClassNotFoundException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- } catch (InstantiationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (NoSuchMethodException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (SecurityException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalArgumentException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- String trueValue = "True";
- assertTrue(trueValue.equalsIgnoreCase("True"));
+ configurationReader.setfRateLimiter(new DMaaPCambriaLimiter(new PropertyReader()));
+
+ when(dmaaPAuthenticator.authenticate(dMaapContext)).thenReturn(null);
+ when(configurationReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
+ when(configurationReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
+ when(dmaapKafkaMetaBroker.getTopic("testTopic")).thenReturn(createdTopic);
+ PowerMockito.when(configurationReader.getfConsumerFactory()).thenReturn(factory);
+ MockHttpServletRequest mockRequest = new MockHttpServletRequest();
+ mockRequest.addHeader("Authorization", "passed");
+ mockRequest.addHeader("Authorization", "passed");
+ dMaapContext.setRequest(mockRequest);
+ dMaapContext.getRequest().getHeader("Authorization");
+ service.pushEvents(dMaapContext, "testTopic", iStream, "3", "12:00:00");
}
- @Test
- public void testIsTransEnabled() {
- Class clazz;
- try {
- clazz = Class.forName("EventsServiceImpl");
- Object obj = clazz.newInstance();
- Method method = clazz.getDeclaredMethod("isTransEnabled", null);
- method.setAccessible(true);
- method.invoke(obj, null);
-
- } catch (ClassNotFoundException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- } catch (InstantiationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (NoSuchMethodException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (SecurityException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalArgumentException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- String trueValue = "True";
- assertTrue(trueValue.equalsIgnoreCase("True"));
+ @Test(expected = CambriaApiException.class)
+ public void testPushEventsWtTransaction() throws DMaaPAccessDeniedException, CambriaApiException, ConfigDbException,
+ TopicExistsException, AccessDeniedException, UnavailableException, IOException, missingReqdSetting,
+ invalidSettingValue, loadException {
- }
+ configurationReader.setfRateLimiter(new DMaaPCambriaLimiter(new PropertyReader()));
- @Test
- public void testGenerateLogDetails() {
- Class clazz;
- try {
- clazz = Class.forName("EventsServiceImpl");
- Object obj = clazz.newInstance();
- Method method = clazz.getDeclaredMethod("generateLogDetails", null);
- method.setAccessible(true);
- method.invoke(obj, "testTopic", null, "11:00:00", 1234, 100l, true);
-
- } catch (ClassNotFoundException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- } catch (InstantiationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (NoSuchMethodException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (SecurityException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalArgumentException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- String trueValue = "True";
- assertTrue(trueValue.equalsIgnoreCase("True"));
+ when(dmaaPAuthenticator.authenticate(dMaapContext)).thenReturn(nsaSimpleApiKey);
+ when(configurationReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
+ when(configurationReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
+ when(dmaapKafkaMetaBroker.getTopic("testTopic")).thenReturn(createdTopic);
+ PowerMockito.when(configurationReader.getfConsumerFactory()).thenReturn(factory);
+ when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "transidUEBtopicreqd")).thenReturn("true");
+
+ service.pushEvents(dMaapContext, "testTopic", iStream, "3", "12:00:00");
}
+ @Test(expected = CambriaApiException.class)
+ public void testPushEventsWtTransactionError() throws DMaaPAccessDeniedException, CambriaApiException, ConfigDbException,
+ TopicExistsException, AccessDeniedException, UnavailableException, IOException, missingReqdSetting,
+ invalidSettingValue, loadException {
- @Test
- public void testInfo() {
-
- String foreNameString = "EventsServiceImpl" + "$" + "LogWrap";
- Object parent = new EventsServiceImpl();
-
- Class<?> innerClass;
- try {
- innerClass = Class.forName(foreNameString);
- Constructor<?> constructor = innerClass.getDeclaredConstructor(EventsServiceImpl.class);
- constructor.setAccessible(true);
- Object child = constructor.newInstance(parent);
-
- // invoking method on inner class object
- Method method = innerClass.getDeclaredMethod("info", null);
- method.setAccessible(true);// in case of unaccessible method
- method.invoke(child, "msg");
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (NoSuchMethodException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (SecurityException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InstantiationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalArgumentException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- assertTrue(true);
+ configurationReader.setfRateLimiter(new DMaaPCambriaLimiter(new PropertyReader()));
+
+ when(dmaaPAuthenticator.authenticate(dMaapContext)).thenReturn(nsaSimpleApiKey);
+ when(configurationReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
+ when(configurationReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
+ when(dmaapKafkaMetaBroker.getTopic("testTopic")).thenReturn(createdTopic);
+ PowerMockito.when(configurationReader.getfConsumerFactory()).thenReturn(factory);
+ when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "transidUEBtopicreqd")).thenReturn("true");
+ when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "event.batch.length")).thenReturn("0");
+ when(configurationReader.getfPublisher()).thenThrow(new ConcurrentModificationException("Error occurred"));
+
+ service.pushEvents(dMaapContext, "testTopic", iStream, "3", "12:00:00");
}
@Test
- public void testWarn() {
-
- String foreNameString = "EventsServiceImpl" + "$" + "LogWrap";
- Object parent = new EventsServiceImpl();
-
- Class<?> innerClass;
- try {
- innerClass = Class.forName(foreNameString);
- Constructor<?> constructor = innerClass.getDeclaredConstructor(EventsServiceImpl.class);
- constructor.setAccessible(true);
- Object child = constructor.newInstance(parent);
-
- // invoking method on inner class object
- Method method = innerClass.getDeclaredMethod("warn", null);
- method.setAccessible(true);// in case of unaccessible method
- method.invoke(child, "msg", null);
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (NoSuchMethodException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (SecurityException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InstantiationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalArgumentException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- assertTrue(true);
+ public void testIsTransEnabled1() {
+
+ when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop,
+ "transidUEBtopicreqd")).thenReturn("true");
+ assertTrue(service.isTransEnabled());
}
-*/
+ @Test
+ public void testIsTransEnabled2() {
+
+ when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop,
+ "transidUEBtopicreqd")).thenReturn("false");
+ assertFalse(service.isTransEnabled());
+
+ }
+
}
|