\r
package com.att.nsa.dmaap.service;\r
\r
-import static org.junit.Assert.*;\r
+import static org.junit.Assert.assertTrue;\r
+import static org.junit.Assert.fail;\r
+import static org.mockito.Matchers.anyString;\r
+\r
+import java.io.FileInputStream;\r
\r
//import static org.mockito.Matchers.anyString;\r
//import static org.mockito.Mockito.when;\r
import javax.servlet.http.HttpServletRequest;\r
import javax.servlet.http.HttpServletResponse;\r
\r
-import org.junit.After;\r
+import org.apache.commons.io.IOUtils;\r
import org.json.JSONArray;\r
import org.json.JSONException;\r
import org.json.JSONObject;\r
+import org.junit.After;\r
import org.junit.Assert;\r
import org.junit.Before;\r
import org.junit.Test;\r
-\r
import org.junit.runner.RunWith;\r
-/*import org.mockito.InjectMocks;\r
+import org.mockito.InjectMocks;\r
import org.mockito.Mock;\r
import org.mockito.MockitoAnnotations;\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.powermock.modules.junit4.PowerMockRunner;\r
\r
import com.att.ajsc.beans.PropertiesMapBean;\r
import com.att.ajsc.filemonitor.AJSCPropertiesMap;\r
import com.att.nsa.security.NsaAcl;\r
import com.att.nsa.security.NsaApiKey;\r
import com.att.nsa.security.db.simple.NsaSimpleApiKey;\r
+import com.google.gson.Gson;\r
\r
//@RunWith(MockitoJUnitRunner.class)\r
-/*@RunWith(PowerMockRunner.class)\r
-@PrepareForTest({ PropertiesMapBean.class, AJSCPropertiesMap.class })*/\r
-public class MMRestServiceTest {/*\r
+@RunWith(PowerMockRunner.class)\r
+@PrepareForTest({ PropertiesMapBean.class, AJSCPropertiesMap.class })\r
+public class MMRestServiceTest {\r
\r
@InjectMocks\r
MMRestService mmRestService;\r
public void tearDown() throws Exception {\r
}\r
\r
-\r
@Test\r
public void testCallCreateMirrorMaker() throws DMaaPAccessDeniedException, CambriaApiException, IOException,\r
TopicExistsException, JSONException, ConfigDbException {\r
-\r
- Assert.assertNotNull(mmRestService);\r
- when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
- when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin")).thenReturn(true);\r
- when(httpServReq.isUserInRole("admin")).thenReturn(true);\r
-\r
- PowerMockito.mockStatic(AJSCPropertiesMap.class);\r
-\r
+ prepareForTestCommon();\r
+ mmRestService.callCreateMirrorMaker(iStream);\r
assertTrue(true);\r
- when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormakeradmin.aaf"))\r
- .thenReturn("admin");\r
-\r
- when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormaker.timeout"))\r
- .thenReturn("100");\r
-\r
- when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormaker.topic"))\r
- .thenReturn("mirrormaker.topic");\r
-\r
- when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormaker.consumergroup"))\r
- .thenReturn("mirrormaker.consumergroup");\r
-\r
- when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormaker.consumerid"))\r
- .thenReturn("mirrormaker.consumerid");\r
-\r
- when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
-\r
- when(httpServReq.isUserInRole("admin")).thenReturn(true);\r
- \r
-\r
- // when(httpServReq.getHeader("Authorization")).thenReturn("Admin");\r
- when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin.aaf")).thenReturn(true);\r
- when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin")).thenReturn(true);\r
- when(httpServReq.getHeader("Authorization")).thenReturn("Admin");\r
- when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin")).thenReturn(true);\r
+ }\r
\r
- when(cMirroMaker.getCreateMirrorMaker()).thenReturn(mMaker);\r
+ @Test\r
+ public void testCallListAllMirrorMaker() throws DMaaPAccessDeniedException, CambriaApiException, IOException,\r
+ TopicExistsException, JSONException, ConfigDbException {\r
+ prepareForTestCommon();\r
+ mmRestService.callListAllMirrorMaker(iStream);\r
+ assertTrue(true);\r
+ }\r
\r
- when(mMaker.getName()).thenReturn("mirroMakerName");\r
- when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
- when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
- when(httpServReq.getHeader("Authorization")).thenReturn("Authorization");\r
+ @Test\r
+ public void testCallUpdateMirrorMaker() throws ConfigDbException, CambriaApiException {\r
+ prepareForTestCommon();\r
+ mmRestService.callUpdateMirrorMaker(iStream);\r
+ assertTrue(true);\r
+ }\r
\r
- when(dmaapContext.getResponse()).thenReturn(httpServRes);\r
- when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);\r
- when(httpServReq.getMethod()).thenReturn("HEAD");\r
+ @Test\r
+ public void testCallDeleteMirrorMaker() throws ConfigDbException, CambriaApiException {\r
+ prepareForTestCommon();\r
+ mmRestService.callDeleteMirrorMaker(iStream);\r
+ assertTrue(true);\r
+ }\r
\r
- when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);\r
+ @Test\r
+ public void testListWhiteList() throws ConfigDbException {\r
+ prepareForTestCommon();\r
+ mmRestService.listWhiteList(iStream);\r
+ assertTrue(true);\r
+ }\r
\r
- mmRestService.callCreateMirrorMaker(iStream);\r
+ @Test\r
+ public void testCreateWhiteList() throws ConfigDbException {\r
+ prepareForTestCommon();\r
+ mmRestService.createWhiteList(iStream);\r
+ assertTrue(true);\r
}\r
\r
@Test\r
- public void testCallListAllMirrorMaker() throws DMaaPAccessDeniedException, CambriaApiException, IOException,\r
- TopicExistsException, JSONException, ConfigDbException {\r
+ public void testDeleteWhiteList() throws ConfigDbException {\r
+ prepareForTestCommon();\r
+ mmRestService.deleteWhiteList(iStream);\r
+ assertTrue(true);\r
+ }\r
\r
+ private void prepareForTestCommon() throws ConfigDbException {\r
Assert.assertNotNull(mmRestService);\r
- when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
- when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin")).thenReturn(true);\r
- when(httpServReq.isUserInRole("admin")).thenReturn(true);\r
+ PowerMockito.when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
+ PowerMockito.when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin")).thenReturn(true);\r
+ PowerMockito.when(httpServReq.isUserInRole("admin")).thenReturn(true);\r
\r
PowerMockito.mockStatic(AJSCPropertiesMap.class);\r
\r
assertTrue(true);\r
- when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormakeradmin.aaf"))\r
+\r
+ PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormakeradmin.aaf"))\r
+ .thenReturn("admin");\r
+\r
+ PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormakeruser.aaf"))\r
.thenReturn("admin");\r
\r
- when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormaker.timeout"))\r
+ PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormaker.timeout"))\r
.thenReturn("100");\r
\r
- when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormaker.topic"))\r
+ PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormaker.topic"))\r
.thenReturn("mirrormaker.topic");\r
\r
- when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormaker.consumergroup"))\r
+ PowerMockito\r
+ .when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormaker.consumergroup"))\r
.thenReturn("mirrormaker.consumergroup");\r
\r
- when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormaker.consumerid"))\r
+ PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormaker.consumerid"))\r
.thenReturn("mirrormaker.consumerid");\r
\r
- when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
+ PowerMockito.when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
\r
- when(httpServReq.isUserInRole("admin")).thenReturn(true);\r
- \r
+ PowerMockito.when(httpServReq.isUserInRole("admin")).thenReturn(true);\r
\r
- // when(httpServReq.getHeader("Authorization")).thenReturn("Admin");\r
- when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin.aaf")).thenReturn(true);\r
- when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin")).thenReturn(true);\r
- when(httpServReq.getHeader("Authorization")).thenReturn("Admin");\r
- when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin")).thenReturn(true);\r
+ // PowerMockito.when(httpServReq.getHeader("Authorization")).thenReturn("Admin");\r
+ PowerMockito.when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin.aaf")).thenReturn(true);\r
+ PowerMockito.when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin")).thenReturn(true);\r
+ PowerMockito.when(httpServReq.getHeader("Authorization")).thenReturn("Admin");\r
+ PowerMockito.when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin")).thenReturn(true);\r
\r
- when(cMirroMaker.getCreateMirrorMaker()).thenReturn(mMaker);\r
+ PowerMockito.when(cMirroMaker.getCreateMirrorMaker()).thenReturn(mMaker);\r
\r
- when(mMaker.getName()).thenReturn("mirroMakerName");\r
- when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
- when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
- when(httpServReq.getHeader("Authorization")).thenReturn("Authorization");\r
+ PowerMockito.when(mMaker.getName()).thenReturn("mirroMakerName");\r
+ PowerMockito.when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
+ PowerMockito.when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
+ PowerMockito.when(httpServReq.getHeader("Authorization")).thenReturn("Authorization");\r
\r
- when(dmaapContext.getResponse()).thenReturn(httpServRes);\r
- when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);\r
- when(httpServReq.getMethod()).thenReturn("HEAD");\r
+ PowerMockito.when(dmaapContext.getResponse()).thenReturn(httpServRes);\r
+ PowerMockito.when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);\r
+ PowerMockito.when(httpServReq.getMethod()).thenReturn("HEAD");\r
\r
- when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);\r
-\r
- mmRestService.callListAllMirrorMaker(iStream);\r
+ PowerMockito.when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);\r
}\r
\r
-\r
-*/}\r
+}\r