diff options
author | 2018-03-01 13:38:34 -0500 | |
---|---|---|
committer | 2018-03-01 13:38:52 -0500 | |
commit | e4b4698dd337651821a0a8bfc4b207e80ac0520e (patch) | |
tree | 683b854c55c15b49e28b9c4b53d58c0dc25cf1cb /src/test/java/com/att/nsa/cambria/service/impl/TopicServiceImplTest.java | |
parent | 907bb776273e1bf41331609c51dc520c3d4fa181 (diff) |
added testcases for code coverage
Issue-ID: DMAAP-271
Change-Id: Ied157de1ed476c67bcc6d5f7b13a90127e036533
Signed-off-by: Sunil Unnava <su622b@att.com>
Diffstat (limited to 'src/test/java/com/att/nsa/cambria/service/impl/TopicServiceImplTest.java')
-rw-r--r-- | src/test/java/com/att/nsa/cambria/service/impl/TopicServiceImplTest.java | 444 |
1 files changed, 305 insertions, 139 deletions
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 c1267b3..2341a7f 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 @@ -40,22 +40,16 @@ 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.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.ajsc.filemonitor.AJSCPropertiesMap;
import com.att.nsa.cambria.CambriaApiException;
import com.att.nsa.cambria.beans.DMaaPContext;
import com.att.nsa.cambria.beans.DMaaPKafkaMetaBroker;
@@ -67,6 +61,7 @@ import com.att.nsa.cambria.metabroker.Broker.TopicExistsException; import com.att.nsa.cambria.metabroker.Topic;
import com.att.nsa.cambria.security.DMaaPAAFAuthenticator;
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.DMaaPResponseBuilder;
import com.att.nsa.configs.ConfigDbException;
@@ -76,17 +71,11 @@ import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException; import com.att.nsa.security.db.simple.NsaSimpleApiKey;
//@RunWith(MockitoJUnitRunner.class)
-//@RunWith(PowerMockRunner.class)
-//@RunWith(SpringJUnit4ClassRunner.class)
-//@ContextConfiguration("classpath:/spring-context.xml")
-//@PrepareForTest({ PropertiesMapBean.class })
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({ PropertiesMapBean.class, DMaaPAuthenticatorImpl.class,AJSCPropertiesMap.class,DMaaPResponseBuilder.class })
public class TopicServiceImplTest {
- /*@Rule
- public PowerMockRule rule = new PowerMockRule();*/
-
- //@Autowired
- /*TopicServiceImpl topicService;
+ TopicServiceImpl topicService;
@Mock
private DMaaPErrorMessages errorMessages;
@@ -137,6 +126,9 @@ public class TopicServiceImplTest { MockitoAnnotations.initMocks(this);
topicService = new TopicServiceImpl();
topicService.setErrorMessages(errorMessages);
+ NsaSimpleApiKey user = new NsaSimpleApiKey("admin", "password");
+ PowerMockito.mockStatic(DMaaPAuthenticatorImpl.class);
+ PowerMockito.when(DMaaPAuthenticatorImpl.getAuthenticatedUser(dmaapContext)).thenReturn(user);
}
@Test(expected = DMaaPAccessDeniedException.class)
@@ -337,7 +329,7 @@ public class TopicServiceImplTest { when(createdTopic.getWriterAcl()).thenReturn(nsaAcl);
topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
}
-
+
@Test(expected = TopicExistsException.class)
public void testGetConsumersByTopicName_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
@@ -371,54 +363,51 @@ public class TopicServiceImplTest { when(httpServReq.getMethod()).thenReturn("HEAD");
when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
-
+
when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
topicService.getConsumersByTopicName(dmaapContext, "topicNamespace.name");
}
-
-// @Test
-// public void testDeleteTopic() throws DMaaPAccessDeniedException, CambriaApiException,
-// IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
-//
-// Assert.assertNotNull(topicService);
-//
-// PowerMockito.mockStatic(DMaaPResponseBuilder.class);
-//
-// PowerMockito.mockStatic(AJSCPropertiesMap.class);
-//
-// PowerMockito.when(AJSCPropertiesMap.
-// getProperty(CambriaConstants.msgRtr_prop,"msgRtr.topicfactory.aaf")).thenReturn("topicFactoryAAF");
-//
-//
-// when(dmaapContext.getConfigReader()).thenReturn(configReader);
-// when(dmaapContext.getRequest()).thenReturn(httpServReq);
-// when(dmaapContext.getResponse()).thenReturn(httpServRes);
-// when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
-// when(httpServReq.getMethod()).thenReturn("HEAD");
-//
-// when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
-//
-// when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
-//
-// topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
-// }
-//
-//
-//
-
- @Test(expected = TopicExistsException.class)
- public void testPermitPublisherForTopic_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
- IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
+
+ @Test
+ public void testGetPublishersByTopicName() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
+ TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
Assert.assertNotNull(topicService);
- when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
+ PowerMockito.mockStatic(DMaaPResponseBuilder.class);
+
+ PowerMockito.mockStatic(AJSCPropertiesMap.class);
+
+ PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
+ .thenReturn("topicFactoryAAF");
+
+ when(dmaapContext.getConfigReader()).thenReturn(configReader);
when(dmaapContext.getRequest()).thenReturn(httpServReq);
- when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
- when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
-
+ when(dmaapContext.getResponse()).thenReturn(httpServRes);
+ when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
+ when(httpServReq.getMethod()).thenReturn("HEAD");
+
+ when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
+
+ when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
+
+ topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
+ }
+
+ @Test(expected=TopicExistsException.class)
+ public void testGetPublishersByTopicNameError() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
+ TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
+
+ Assert.assertNotNull(topicService);
+
PowerMockito.mockStatic(DMaaPResponseBuilder.class);
+
+ PowerMockito.mockStatic(AJSCPropertiesMap.class);
+
+ PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
+ .thenReturn("topicFactoryAAF");
+
when(dmaapContext.getConfigReader()).thenReturn(configReader);
when(dmaapContext.getRequest()).thenReturn(httpServReq);
when(dmaapContext.getResponse()).thenReturn(httpServRes);
@@ -427,173 +416,350 @@ public class TopicServiceImplTest { when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
- topicService.permitPublisherForTopic(dmaapContext, "topicNamespace.name", "producerId");
+ when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
+
+ topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
}
-
+
@Test
- public void testPermitPublisherForTopic_NonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
- IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
+ 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(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
-
- PowerMockito.mockStatic(DMaaPResponseBuilder.class);
when(dmaapContext.getConfigReader()).thenReturn(configReader);
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
- when(dmaapContext.getResponse()).thenReturn(httpServRes);
when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- when(httpServReq.getMethod()).thenReturn("HEAD");
+ when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
+ TopicBean topicBean = new TopicBean();
+ topicBean.setTopicName("enfTopicNamePlusExtra");
- when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
-
-
- topicService.permitPublisherForTopic(dmaapContext, "topicNamespace.name", "producerId");
+ topicService.deleteTopic(dmaapContext, "topicNamespace.topic");
}
-
- @Test(expected = TopicExistsException.class)
- public void testDenyPublisherForTopic_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
- IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
+ @Test(expected=TopicExistsException.class)
+ public void testdeleteTopic_nulltopic() 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(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
-
- PowerMockito.mockStatic(DMaaPResponseBuilder.class);
when(dmaapContext.getConfigReader()).thenReturn(configReader);
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
- when(dmaapContext.getResponse()).thenReturn(httpServRes);
when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- when(httpServReq.getMethod()).thenReturn("HEAD");
+ when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
+ TopicBean topicBean = new TopicBean();
+ topicBean.setTopicName("enfTopicNamePlusExtra");
- when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
+ topicService.deleteTopic(dmaapContext, "topicNamespace.topic");
+ }
+
+ @Test(expected=DMaaPAccessDeniedException.class)
+ public void testdeleteTopic_authHeader() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
+ TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
+
+ Assert.assertNotNull(topicService);
- topicService.denyPublisherForTopic(dmaapContext, "topicNamespace.name", "producerId");
+ // 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);
+ when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
+ when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
+ TopicBean topicBean = new TopicBean();
+ topicBean.setTopicName("enfTopicNamePlusExtra");
+ PowerMockito.when(DMaaPAuthenticatorImpl.getAuthenticatedUser(dmaapContext)).thenReturn(null);
+ topicService.deleteTopic(dmaapContext, "topicNamespace.topic");
}
@Test
- public void testDenyPublisherForTopic_NonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
- IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
+ public void testPermitConsumerForTopic() 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(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
-
- PowerMockito.mockStatic(DMaaPResponseBuilder.class);
when(dmaapContext.getConfigReader()).thenReturn(configReader);
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
- when(dmaapContext.getResponse()).thenReturn(httpServRes);
when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- when(httpServReq.getMethod()).thenReturn("HEAD");
+ when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
+ TopicBean topicBean = new TopicBean();
+ topicBean.setTopicName("enfTopicNamePlusExtra");
- when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
-
-
- topicService.denyPublisherForTopic(dmaapContext, "topicNamespace.name", "producerId");
+ topicService.permitConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
}
- @Test(expected = TopicExistsException.class)
- public void testPermitConsumerForTopic_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
- IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
+ @Test(expected=TopicExistsException.class)
+ public void testPermitConsumerForTopic_nulltopic() 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(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
-
- PowerMockito.mockStatic(DMaaPResponseBuilder.class);
when(dmaapContext.getConfigReader()).thenReturn(configReader);
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
- when(dmaapContext.getResponse()).thenReturn(httpServRes);
when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- when(httpServReq.getMethod()).thenReturn("HEAD");
-
- when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
+ when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
+ TopicBean topicBean = new TopicBean();
+ topicBean.setTopicName("enfTopicNamePlusExtra");
- topicService.permitConsumerForTopic(dmaapContext, "topicNamespace.name", "consumerID");
+ topicService.permitConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
}
@Test
- public void testPermitConsumerForTopic_NonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
- IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
+ public void testdenyConsumerForTopic() 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(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
-
- PowerMockito.mockStatic(DMaaPResponseBuilder.class);
when(dmaapContext.getConfigReader()).thenReturn(configReader);
+ when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
+ when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
+ TopicBean topicBean = new TopicBean();
+ topicBean.setTopicName("enfTopicNamePlusExtra");
+
+ topicService.denyConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
+ }
+
+ @Test(expected=TopicExistsException.class)
+ public void testdenyConsumerForTopic_nulltopic() 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(dmaapContext.getResponse()).thenReturn(httpServRes);
+
+ when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
+ when(dmaapContext.getConfigReader()).thenReturn(configReader);
when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- when(httpServReq.getMethod()).thenReturn("HEAD");
+ when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
+ TopicBean topicBean = new TopicBean();
+ topicBean.setTopicName("enfTopicNamePlusExtra");
- when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
-
-
- topicService.permitConsumerForTopic(dmaapContext, "topicNamespace.name", "consumerID");
+ topicService.denyConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
}
- @Test(expected = TopicExistsException.class)
- public void testDenyConsumerForTopic_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
- IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
+ @Test
+ public void testPermitPublisherForTopic() 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(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
-
- PowerMockito.mockStatic(DMaaPResponseBuilder.class);
when(dmaapContext.getConfigReader()).thenReturn(configReader);
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
- when(dmaapContext.getResponse()).thenReturn(httpServRes);
when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- when(httpServReq.getMethod()).thenReturn("HEAD");
+ when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
+ TopicBean topicBean = new TopicBean();
+ topicBean.setTopicName("enfTopicNamePlusExtra");
- when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
+ topicService.permitPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");
+ }
+
+ @Test(expected=TopicExistsException.class)
+ public void testPermitPublisherForTopic_nulltopic() 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);
+ when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
+ when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
+ TopicBean topicBean = new TopicBean();
+ topicBean.setTopicName("enfTopicNamePlusExtra");
- topicService.denyConsumerForTopic(dmaapContext, "topicNamespace.name", "consumerID");
+ topicService.permitPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");
}
@Test
- public void testDenyConsumerForTopic_NonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
- IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
+ public void testDenyPublisherForTopic() 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(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
-
+ when(dmaapContext.getConfigReader()).thenReturn(configReader);
+ when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
+ when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
+ TopicBean topicBean = new TopicBean();
+ topicBean.setTopicName("enfTopicNamePlusExtra");
+
+ topicService.denyPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");;
+ }
+
+ @Test(expected=TopicExistsException.class)
+ public void testDenyPublisherForTopic_nulltopic() 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);
+ when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
+ when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
+ TopicBean topicBean = new TopicBean();
+ topicBean.setTopicName("enfTopicNamePlusExtra");
+
+ topicService.denyPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");;
+ }
+
+ @Test
+ public void testGetAllTopics() 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");
PowerMockito.mockStatic(DMaaPResponseBuilder.class);
+ 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);
+ when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
+ when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
+ TopicBean topicBean = new TopicBean();
+ topicBean.setTopicName("enfTopicNamePlusExtra");
+
+ topicService.getAllTopics(dmaapContext);
+ }
+
+ @Test
+ public void testGetTopics() 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");
+ PowerMockito.mockStatic(DMaaPResponseBuilder.class);
+ when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
+ when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
+ when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
when(dmaapContext.getRequest()).thenReturn(httpServReq);
- when(dmaapContext.getResponse()).thenReturn(httpServRes);
+
+ when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
+ when(dmaapContext.getConfigReader()).thenReturn(configReader);
when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- when(httpServReq.getMethod()).thenReturn("HEAD");
+ when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
+ TopicBean topicBean = new TopicBean();
+ topicBean.setTopicName("enfTopicNamePlusExtra");
+
+ topicService.getTopics(dmaapContext);
+ }
+
+
- when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
-
-
- topicService.denyConsumerForTopic(dmaapContext, "topicNamespace.name", "consumerID");
- }*/
}
|