diff options
author | 2017-10-01 21:36:35 -0400 | |
---|---|---|
committer | 2017-10-01 22:26:36 -0400 | |
commit | fd8f9858fe2c7dfdee55a1e136a63fb01d1a3162 (patch) | |
tree | a94e58e1bac32562d0cb30f65663563a5d783d13 /src/test/java/com/att/nsa/cambria/service/impl | |
parent | 2881443ed939d6d3c1a55719cca95ee9e7483165 (diff) |
commiting code for test coveragev1.0.01.0.0-ONAP1.0.0-Amsterdam
changed testcases
DMAAP-149
Signed-off-by: rn509j <rn509j@att.com>
Change-Id: I4dfeb3df44f85bfbd3a10ec1659c8618e31a10fb
Diffstat (limited to 'src/test/java/com/att/nsa/cambria/service/impl')
4 files changed, 153 insertions, 101 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 94598f8..d1c2d2a 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 @@ -20,89 +20,125 @@ package com.att.nsa.cambria.service.impl;
-
-import static org.junit.Assert.*;
+import static org.mockito.Mockito.when;
+import static org.mockito.Matchers.anyString;
+import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-
-import javax.servlet.http.HttpServletRequest;
+import java.util.Map;
+import java.util.Properties;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.mock.web.MockHttpServletRequest;
+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.backends.Publisher.message;
+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.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.db.simple.NsaSimpleApiKey;
-public class EventsServiceImplTest {
+import kafka.admin.AdminUtils;
+
+
+public class EventsServiceImplTest {
private InputStream iStream = null;
+ DMaaPContext dMaapContext = new DMaaPContext();
+ EventsServiceImpl service = new EventsServiceImpl();
+ DMaaPErrorMessages pErrorMessages = new DMaaPErrorMessages();
+
+ ConfigurationReader configurationReader;
+ EmbedConfigurationReader embedConfigurationReader = new EmbedConfigurationReader();
+
@Before
public void setUp() throws Exception {
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);
+ dMaapContext.setConfigReader(configurationReader);
+
+ service.setErrorMessages(pErrorMessages);
+
+ Map<String, String> map = com.att.ajsc.filemonitor.AJSCPropertiesMap.getProperties(CambriaConstants.msgRtr_prop);
+ map.put("timeout", "1000");
+
}
@After
public void tearDown() throws Exception {
+ embedConfigurationReader.tearDown();
}
- @Test
- public void testGetEvents() {
-
- EventsServiceImpl service = new EventsServiceImpl();
- try {
- service.getEvents(new DMaaPContext(), "testTopic", "CG1", "23");
- } 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 (UnavailableException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (NullPointerException e) {
- // TODO Auto-generated catch block
- // e.printStackTrace();
- assertTrue(true);
- }
-
+ @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 testGetEventsForNoTopic() throws DMaaPAccessDeniedException, CambriaApiException, ConfigDbException, TopicExistsException, AccessDeniedException, UnavailableException, IOException {
+
+ 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()));
+
+ service.pushEvents(dMaapContext, "testTopic", iStream, "3", "12:00:00");
+
+ service.getEvents(dMaapContext, "testTopic", "CG1", "23");
+
String trueValue = "True";
assertTrue(trueValue.equalsIgnoreCase("True"));
}
- @Test
+ /*@Test
public void testPushEvents() {
EventsServiceImpl service = new EventsServiceImpl();
@@ -426,5 +462,5 @@ public class EventsServiceImplTest { assertTrue(true);
}
-
+*/
}
diff --git a/src/test/java/com/att/nsa/cambria/service/impl/ShowConsumerCacheTest.java b/src/test/java/com/att/nsa/cambria/service/impl/ShowConsumerCacheTest.java index c473138..1193fe3 100644 --- a/src/test/java/com/att/nsa/cambria/service/impl/ShowConsumerCacheTest.java +++ b/src/test/java/com/att/nsa/cambria/service/impl/ShowConsumerCacheTest.java @@ -20,14 +20,14 @@ package com.att.nsa.cambria.service.impl;
import static org.junit.Assert.assertEquals;
-/*import static org.mockito.Matchers.anyBoolean;
+import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-*/
+
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
@@ -41,20 +41,20 @@ import org.junit.Assert; import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-/*import org.mockito.InjectMocks;
+import org.mockito.InjectMocks;
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;
-import org.mockito.runners.MockitoJUnitRunner;*/
+import org.mockito.runners.MockitoJUnitRunner;
import com.att.aft.dme2.internal.jettison.json.JSONArray;
import com.att.aft.dme2.internal.jettison.json.JSONException;
import com.att.aft.dme2.internal.jettison.json.JSONObject;
import com.att.ajsc.beans.PropertiesMapBean;
-/*import com.att.nsa.cambria.CambriaApiException;
+import com.att.nsa.cambria.CambriaApiException;
import com.att.nsa.cambria.beans.DMaaPContext;
import com.att.nsa.cambria.beans.DMaaPKafkaMetaBroker;
import com.att.nsa.cambria.CambriaApiException;
@@ -68,7 +68,7 @@ import com.att.nsa.cambria.metabroker.Topic; import com.att.nsa.cambria.security.DMaaPAuthenticator;
import com.att.nsa.cambria.utils.ConfigurationReader;
import com.att.nsa.cambria.utils.DMaaPResponseBuilder;
-import com.att.nsa.security.NsaApiKey;*/
+import com.att.nsa.security.NsaApiKey;
import com.att.nsa.security.db.simple.NsaSimpleApiKey;
import jline.internal.Log;
@@ -77,10 +77,10 @@ import kafka.consumer.Consumer; //@RunWith(MockitoJUnitRunner.class)
-/*@RunWith(PowerMockRunner.class)
-@PrepareForTest(PropertiesMapBean.class)*/
-public class ShowConsumerCacheTest {/*
-
+//@RunWith(PowerMockRunner.class)
+//@PrepareForTest(PropertiesMapBean.class)
+public class ShowConsumerCacheTest {
+/*
@InjectMocks
TopicServiceImpl topicService;
@@ -143,7 +143,7 @@ when(consumers.put("consumers", jsonConsumersList)).thenReturn(consumerObject); -}
+}*/
-*/}
\ No newline at end of file +}
\ No newline at end of file diff --git a/src/test/java/com/att/nsa/cambria/service/impl/TopicServiceImplTest.java b/src/test/java/com/att/nsa/cambria/service/impl/TopicServiceImplTest.java index f3af9b0..c1267b3 100644 --- a/src/test/java/com/att/nsa/cambria/service/impl/TopicServiceImplTest.java +++ b/src/test/java/com/att/nsa/cambria/service/impl/TopicServiceImplTest.java @@ -20,12 +20,12 @@ package com.att.nsa.cambria.service.impl;
-/*import static org.mockito.Matchers.anyBoolean;
+import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;*/
+import static org.mockito.Mockito.when;
import java.io.IOException;
import java.util.Arrays;
@@ -40,14 +40,20 @@ import org.json.JSONException; import org.json.JSONObject;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-/*import org.mockito.InjectMocks;
+import org.mockito.InjectMocks;
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;
+import org.powermock.modules.junit4.rule.PowerMockRule;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.att.ajsc.beans.PropertiesMapBean;
import com.att.nsa.cambria.CambriaApiException;
@@ -63,19 +69,24 @@ import com.att.nsa.cambria.security.DMaaPAAFAuthenticator; import com.att.nsa.cambria.security.DMaaPAuthenticator;
import com.att.nsa.cambria.utils.ConfigurationReader;
import com.att.nsa.cambria.utils.DMaaPResponseBuilder;
-import com.att.nsa.configs.ConfigDbException;*/
+import com.att.nsa.configs.ConfigDbException;
import com.att.nsa.security.NsaAcl;
import com.att.nsa.security.NsaApiKey;
import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;
import com.att.nsa.security.db.simple.NsaSimpleApiKey;
//@RunWith(MockitoJUnitRunner.class)
-/*@RunWith(PowerMockRunner.class)
-@PrepareForTest({ PropertiesMapBean.class })*/
-public class TopicServiceImplTest {/*
-
- @InjectMocks
- TopicServiceImpl topicService;
+//@RunWith(PowerMockRunner.class)
+//@RunWith(SpringJUnit4ClassRunner.class)
+//@ContextConfiguration("classpath:/spring-context.xml")
+//@PrepareForTest({ PropertiesMapBean.class })
+public class TopicServiceImplTest {
+
+ /*@Rule
+ public PowerMockRule rule = new PowerMockRule();*/
+
+ //@Autowired
+ /*TopicServiceImpl topicService;
@Mock
private DMaaPErrorMessages errorMessages;
@@ -124,6 +135,8 @@ public class TopicServiceImplTest {/* @Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ topicService = new TopicServiceImpl();
+ topicService.setErrorMessages(errorMessages);
}
@Test(expected = DMaaPAccessDeniedException.class)
@@ -582,5 +595,5 @@ public class TopicServiceImplTest {/* topicService.denyConsumerForTopic(dmaapContext, "topicNamespace.name", "consumerID");
- }
-*/}
+ }*/
+}
diff --git a/src/test/java/com/att/nsa/cambria/service/impl/TopicServiceImplTest22.java b/src/test/java/com/att/nsa/cambria/service/impl/TopicServiceImplTest22.java index 9ea0aee..d9361f9 100644 --- a/src/test/java/com/att/nsa/cambria/service/impl/TopicServiceImplTest22.java +++ b/src/test/java/com/att/nsa/cambria/service/impl/TopicServiceImplTest22.java @@ -20,12 +20,12 @@ package com.att.nsa.cambria.service.impl;
-/*import static org.mockito.Matchers.anyBoolean;
+import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;*/
+import static org.mockito.Mockito.when;
import java.io.IOException;
import java.util.Arrays;
@@ -42,7 +42,7 @@ import org.junit.Assert; import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-/*import org.mockito.InjectMocks;
+import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.powermock.api.mockito.PowerMockito;
@@ -50,6 +50,7 @@ import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner;
import com.att.ajsc.beans.PropertiesMapBean;
+import com.att.ajsc.filemonitor.AJSCPropertiesMap;
import com.att.nsa.cambria.CambriaApiException;
import com.att.nsa.cambria.beans.DMaaPContext;
import com.att.nsa.cambria.beans.DMaaPKafkaMetaBroker;
@@ -63,18 +64,18 @@ import com.att.nsa.cambria.security.DMaaPAAFAuthenticator; import com.att.nsa.cambria.security.DMaaPAuthenticator;
import com.att.nsa.cambria.utils.ConfigurationReader;
import com.att.nsa.cambria.utils.DMaaPResponseBuilder;
-import com.att.nsa.configs.ConfigDbException;*/
+import com.att.nsa.configs.ConfigDbException;
import com.att.nsa.security.NsaAcl;
import com.att.nsa.security.NsaApiKey;
import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;
import com.att.nsa.security.db.simple.NsaSimpleApiKey;
//@RunWith(MockitoJUnitRunner.class)
-/*@RunWith(PowerMockRunner.class)
-@PrepareForTest({ PropertiesMapBean.class })*/
-public class TopicServiceImplTest22 {/*
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({ PropertiesMapBean.class })
+public class TopicServiceImplTest22 {
- @InjectMocks
+
TopicServiceImpl topicService;
@Mock
@@ -124,6 +125,8 @@ public class TopicServiceImplTest22 {/* @Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ topicService = new TopicServiceImpl();
+ topicService.setErrorMessages(errorMessages);
}
@Test(expected = DMaaPAccessDeniedException.class)
@@ -394,29 +397,29 @@ public class TopicServiceImplTest22 {/* //
//
- * @Test public void testdeleteTopic() throws DMaaPAccessDeniedException,
- * CambriaApiException, IOException, TopicExistsException, JSONException,
- * ConfigDbException, AccessDeniedException {
- *
- * Assert.assertNotNull(topicService);
- *
- * //PowerMockito.mockStatic(AJSCPropertiesMap.class);
- * PowerMockito.mockStatic(AJSCPropertiesMap.class);
- * PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.
- * msgRtr_prop,"msgRtr.topicfactory.aaf")) .thenReturn("hello");
- *
- * when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
- * when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
- * when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
- * when(dmaapContext.getRequest()).thenReturn(httpServReq);
- *
- * when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
- * when(dmaapContext.getConfigReader()).thenReturn(configReader);
- *
- * TopicBean topicBean = new TopicBean();
- * topicBean.setTopicName("enfTopicNamePlusExtra");
- *
- * topicService.deleteTopic(dmaapContext, "topicNamespace.topic"); }
+ /*@Test public void testdeleteTopic() throws DMaaPAccessDeniedException,
+ CambriaApiException, IOException, TopicExistsException, JSONException,
+ ConfigDbException, AccessDeniedException {
+
+ Assert.assertNotNull(topicService);
+
+ //PowerMockito.mockStatic(AJSCPropertiesMap.class);
+ PowerMockito.mockStatic(AJSCPropertiesMap.class);
+ PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.
+ msgRtr_prop,"msgRtr.topicfactory.aaf")) .thenReturn("hello");
+
+ when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
+ when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
+ when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
+ when(dmaapContext.getRequest()).thenReturn(httpServReq);
+
+ when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
+ when(dmaapContext.getConfigReader()).thenReturn(configReader);
+
+ TopicBean topicBean = new TopicBean();
+ topicBean.setTopicName("enfTopicNamePlusExtra");
+
+ topicService.deleteTopic(dmaapContext, "topicNamespace.topic"); }*/
-*/}
+}
|