\r
\r
package com.att.nsa.cambria.service.impl;\r
-\r
-import static org.junit.Assert.*;\r
+import static org.mockito.Mockito.when;\r
+import static org.mockito.Matchers.anyString;\r
+import static org.junit.Assert.assertTrue;\r
\r
import java.io.ByteArrayInputStream;\r
+import java.io.File;\r
import java.io.IOException;\r
import java.io.InputStream;\r
import java.lang.reflect.Constructor;\r
import java.lang.reflect.InvocationTargetException;\r
import java.lang.reflect.Method;\r
-\r
-import javax.servlet.http.HttpServletRequest;\r
+import java.util.Map;\r
+import java.util.Properties;\r
\r
import org.junit.After;\r
import org.junit.Before;\r
import org.junit.Test;\r
-\r
+import org.junit.runner.RunWith;\r
+import org.mockito.Mock;\r
+import org.powermock.api.mockito.PowerMockito;\r
+import org.powermock.core.classloader.annotations.PrepareForTest;\r
+import org.powermock.modules.junit4.PowerMockRunner;\r
+import org.springframework.beans.factory.annotation.Autowired;\r
+import org.springframework.mock.web.MockHttpServletRequest;\r
+import org.springframework.mock.web.MockHttpServletResponse;\r
+\r
+import com.att.ajsc.beans.PropertiesMapBean;\r
+import com.att.ajsc.filemonitor.AJSCPropertiesMap;\r
import com.att.nsa.cambria.CambriaApiException;\r
import com.att.nsa.cambria.backends.ConsumerFactory.UnavailableException;\r
-import com.att.nsa.cambria.backends.Publisher.message;\r
+import com.att.nsa.cambria.beans.DMaaPCambriaLimiter;\r
import com.att.nsa.cambria.beans.DMaaPContext;\r
+import com.att.nsa.cambria.constants.CambriaConstants;\r
+import com.att.nsa.cambria.embed.EmbedConfigurationReader;\r
import com.att.nsa.cambria.exception.DMaaPAccessDeniedException;\r
+import com.att.nsa.cambria.exception.DMaaPErrorMessages;\r
+import com.att.nsa.cambria.metabroker.Topic;\r
import com.att.nsa.cambria.metabroker.Broker.TopicExistsException;\r
+import com.att.nsa.cambria.security.DMaaPAuthenticator;\r
+import com.att.nsa.cambria.security.DMaaPAuthenticatorImpl;\r
+import com.att.nsa.cambria.utils.ConfigurationReader;\r
+import com.att.nsa.cambria.utils.PropertyReader;\r
import com.att.nsa.configs.ConfigDbException;\r
+import com.att.nsa.drumlin.till.nv.rrNvReadable.invalidSettingValue;\r
+import com.att.nsa.drumlin.till.nv.rrNvReadable.loadException;\r
import com.att.nsa.drumlin.till.nv.rrNvReadable.missingReqdSetting;\r
+import com.att.nsa.limits.Blacklist;\r
import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;\r
+import com.att.nsa.security.db.simple.NsaSimpleApiKey;\r
\r
-public class EventsServiceImplTest {\r
+import kafka.admin.AdminUtils;\r
+\r
+\r
+public class EventsServiceImplTest { \r
\r
private InputStream iStream = null;\r
+ DMaaPContext dMaapContext = new DMaaPContext();\r
+ EventsServiceImpl service = new EventsServiceImpl();\r
+ DMaaPErrorMessages pErrorMessages = new DMaaPErrorMessages();\r
+ \r
+ ConfigurationReader configurationReader;\r
+ EmbedConfigurationReader embedConfigurationReader = new EmbedConfigurationReader();\r
+ \r
\r
@Before\r
public void setUp() throws Exception {\r
\r
String source = "source of my InputStream";\r
iStream = new ByteArrayInputStream(source.getBytes("UTF-8"));\r
+ \r
+ configurationReader = embedConfigurationReader.buildConfigurationReader();\r
+ \r
+ MockHttpServletRequest request = new MockHttpServletRequest();\r
+ MockHttpServletResponse response = new MockHttpServletResponse();\r
+ dMaapContext.setRequest(request);\r
+ dMaapContext.setResponse(response);\r
+ dMaapContext.setConfigReader(configurationReader);\r
+ \r
+ service.setErrorMessages(pErrorMessages);\r
+ \r
+ Map<String, String> map = com.att.ajsc.filemonitor.AJSCPropertiesMap.getProperties(CambriaConstants.msgRtr_prop);\r
+ map.put("timeout", "1000");\r
+ \r
}\r
\r
@After\r
public void tearDown() throws Exception {\r
+ embedConfigurationReader.tearDown();\r
}\r
\r
- @Test\r
- public void testGetEvents() {\r
-\r
- EventsServiceImpl service = new EventsServiceImpl();\r
- try {\r
- service.getEvents(new DMaaPContext(), "testTopic", "CG1", "23");\r
- } catch (org.json.JSONException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- } catch (IOException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- } catch (DMaaPAccessDeniedException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- } catch (CambriaApiException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- } catch (ConfigDbException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- } catch (TopicExistsException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- } catch (AccessDeniedException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- } catch (UnavailableException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- } catch (NullPointerException e) {\r
- // TODO Auto-generated catch block\r
- // e.printStackTrace();\r
- assertTrue(true);\r
- }\r
-\r
+ @Test(expected=NullPointerException.class)\r
+ public void testGetEventsForCambriaApiException() throws DMaaPAccessDeniedException, CambriaApiException, ConfigDbException, TopicExistsException, AccessDeniedException, UnavailableException, IOException {\r
+ service.getEvents(dMaapContext, "testTopic", "CG1", null);\r
+ }\r
+ \r
+ @Test(expected=CambriaApiException.class)\r
+ public void testGetEventsForNoTopic() throws DMaaPAccessDeniedException, CambriaApiException, ConfigDbException, TopicExistsException, AccessDeniedException, UnavailableException, IOException {\r
+ \r
+ service.getEvents(dMaapContext, "testTopic", "CG1", "23");\r
+ }\r
+ \r
+ \r
+ @Test(expected=CambriaApiException.class)\r
+ public void testPushEvents() throws DMaaPAccessDeniedException, CambriaApiException, ConfigDbException, TopicExistsException, AccessDeniedException, UnavailableException, IOException, missingReqdSetting, invalidSettingValue, loadException {\r
+ \r
+ //AdminUtils.createTopic(configurationReader.getZk(), "testTopic", 10, 1, new Properties());\r
+ \r
+ configurationReader.setfRateLimiter(new DMaaPCambriaLimiter(new PropertyReader()));\r
+ \r
+ service.pushEvents(dMaapContext, "testTopic", iStream, "3", "12:00:00");\r
+ \r
+ service.getEvents(dMaapContext, "testTopic", "CG1", "23");\r
+ \r
String trueValue = "True";\r
assertTrue(trueValue.equalsIgnoreCase("True"));\r
\r
}\r
\r
- @Test\r
+ /*@Test\r
public void testPushEvents() {\r
\r
EventsServiceImpl service = new EventsServiceImpl();\r
assertTrue(true);\r
\r
}\r
-\r
+*/\r
}\r