summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorsg481n <sg481n@att.com>2017-10-03 05:04:02 +0000
committersg481n <sg481n@att.com>2017-10-03 05:15:48 +0000
commite3b6ff2139523fab0090e165b313cb31911c7232 (patch)
tree0473372de7aa4122b8d34a76b3fc1af8f74e3bec /src
parent93eb44a5932f40e5179e1356e2c51483b6aea3be (diff)
Improve coverage for dmaap messageservice
Modified content length interceptor class. Issue-ID: DMAAP-151 Change-Id: Ifeaa6f54032da583ec5df3b4b29078d1c4b8648a Signed-off-by: sg481n <sg481n@att.com>
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/att/nsa/dmaap/util/ContentLengthInterceptor.java262
-rw-r--r--src/test/java/com/att/nsa/dmaap/DMaaPCambriaExceptionMapperTest.java16
-rw-r--r--src/test/java/com/att/nsa/dmaap/DMaaPWebExceptionMapperTest.java16
-rw-r--r--src/test/java/com/att/nsa/dmaap/DummyTest.java90
-rw-r--r--src/test/java/com/att/nsa/dmaap/HelloWorldTest.java13
-rw-r--r--src/test/java/com/att/nsa/dmaap/JaxrsUserServiceTest.java2
-rw-r--r--src/test/java/com/att/nsa/dmaap/service/ApiKeysRestServiceTest.java2
-rw-r--r--src/test/java/com/att/nsa/dmaap/service/MMRestServiceTest.java165
-rw-r--r--src/test/java/com/att/nsa/dmaap/util/ContentLengthInterceptorTest.java52
-rw-r--r--src/test/java/com/att/nsa/dmaap/util/DMaaPAuthFilterTest.java66
-rw-r--r--src/test/java/com/att/nsa/dmaap/util/ServicePropertiesMapBeanTest.java10
11 files changed, 333 insertions, 361 deletions
diff --git a/src/main/java/com/att/nsa/dmaap/util/ContentLengthInterceptor.java b/src/main/java/com/att/nsa/dmaap/util/ContentLengthInterceptor.java
index 7b0dda1..98bc86e 100644
--- a/src/main/java/com/att/nsa/dmaap/util/ContentLengthInterceptor.java
+++ b/src/main/java/com/att/nsa/dmaap/util/ContentLengthInterceptor.java
@@ -1,131 +1,131 @@
-/*******************************************************************************
- * ============LICENSE_START=======================================================
- * org.onap.dmaap
- * ================================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- *
- *******************************************************************************/
-package com.att.nsa.dmaap.util;
-
-import java.util.Map;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import org.apache.http.HttpStatus;
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.springframework.stereotype.Component;
-import com.att.nsa.cambria.CambriaApiException;
-import com.att.nsa.cambria.exception.DMaaPResponseCode;
-import com.att.nsa.cambria.exception.ErrorResponse;
-import ajsc.beans.interceptors.AjscInterceptor;
-
-/**
- * AJSC Intercepter implementation of ContentLengthFilter
- */
-@Component
-public class ContentLengthInterceptor implements AjscInterceptor{
-
-
- private String defLength;
- private static final EELFLogger log = EELFManager.getInstance().getLogger(ContentLengthInterceptor.class);
-
-
- /**
- * Intercepter method to intercept requests before processing
- */
- @Override
- public boolean allowOrReject(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse,
- Map map) throws Exception {
-
- log.info("inside Interceptor allowOrReject content length checking before pub/sub");
-
- JSONObject jsonObj = null;
- int requestLength = 0;
- setDefLength(System.getProperty("maxcontentlength"));
- try {
- // retrieving content length from message header
-
- if (null != httpservletrequest.getHeader("Content-Length")) {
- requestLength = Integer.parseInt(httpservletrequest.getHeader("Content-Length"));
- }
- // retrieving encoding from message header
- String transferEncoding = httpservletrequest.getHeader("Transfer-Encoding");
- // checking for no encoding, chunked and requestLength greater then
- // default length
- if (null != transferEncoding && !(transferEncoding.contains("chunked"))
- && (requestLength > Integer.parseInt(getDefLength()))) {
- jsonObj = new JSONObject().append("defaultlength", getDefLength())
- .append("requestlength", requestLength);
- log.error("message length is greater than default");
- throw new CambriaApiException(jsonObj);
- }
- else if (null == transferEncoding && (requestLength > Integer.parseInt(getDefLength())))
- {
- jsonObj = new JSONObject().append("defaultlength", getDefLength()).append(
- "requestlength", requestLength);
- log.error("Request message is not chunked or request length is greater than default length");
- throw new CambriaApiException(jsonObj);
-
-
- }
- else
- {
- //chain.doFilter(req, res);
- return true;
- }
-
- } catch (CambriaApiException | NumberFormatException | JSONException e) {
-
- log.info("Exception obj--"+e);
- log.error("message size is greater then default"+e.getMessage());
- ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_REQUEST_TOO_LONG,
- DMaaPResponseCode.MSG_SIZE_EXCEEDS_MSG_LIMIT.getResponseCode(), System.getProperty("msg_size_exceeds")
- + e.toString());
- log.info(errRes.toString());
-
-
- map.put(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,"test");
- httpservletresponse.setStatus(HttpStatus.SC_REQUEST_TOO_LONG);
- httpservletresponse.getOutputStream().write(errRes.toString().getBytes());
- return false;
- }
-
-
-
- }
-
-
- /**
- * Get Default Content Length
- * @return defLength
- */
- public String getDefLength() {
- return defLength;
- }
- /**
- * Set Default Content Length
- * @param defLength
- */
- public void setDefLength(String defLength) {
- this.defLength = defLength;
- }
-
-
-
-}
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * org.onap.dmaap
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ *
+ *******************************************************************************/
+package com.att.nsa.dmaap.util;
+
+import java.util.Map;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.http.HttpStatus;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.springframework.stereotype.Component;
+import com.att.nsa.cambria.CambriaApiException;
+import com.att.nsa.cambria.exception.DMaaPResponseCode;
+import com.att.nsa.cambria.exception.ErrorResponse;
+import ajsc.beans.interceptors.AjscInterceptor;
+
+/**
+ * AJSC Intercepter implementation of ContentLengthFilter
+ */
+@Component
+public class ContentLengthInterceptor implements AjscInterceptor{
+
+
+ private String defLength;
+ private static final EELFLogger log = EELFManager.getInstance().getLogger(ContentLengthInterceptor.class);
+
+
+ /**
+ * Intercepter method to intercept requests before processing
+ */
+ @Override
+ public boolean allowOrReject(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse,
+ Map map) throws Exception {
+
+ log.info("inside Interceptor allowOrReject content length checking before pub/sub");
+
+ JSONObject jsonObj = null;
+ int requestLength = 0;
+ setDefLength(System.getProperty("maxcontentlength"));
+ try {
+ // retrieving content length from message header
+
+ if (null != httpservletrequest.getHeader("Content-Length")) {
+ requestLength = Integer.parseInt(httpservletrequest.getHeader("Content-Length"));
+ }
+ // retrieving encoding from message header
+ String transferEncoding = httpservletrequest.getHeader("Transfer-Encoding");
+ // checking for no encoding, chunked and requestLength greater then
+ // default length
+ if (null != transferEncoding && !(transferEncoding.contains("chunked"))
+ && (getDefLength() !=null && requestLength > Integer.parseInt(getDefLength()))) {
+ jsonObj = new JSONObject().append("defaultlength", getDefLength())
+ .append("requestlength", requestLength);
+ log.error("message length is greater than default");
+ throw new CambriaApiException(jsonObj);
+ }
+ else if (null == transferEncoding && (getDefLength() !=null && requestLength > Integer.parseInt(getDefLength())))
+ {
+ jsonObj = new JSONObject().append("defaultlength", getDefLength()).append(
+ "requestlength", requestLength);
+ log.error("Request message is not chunked or request length is greater than default length");
+ throw new CambriaApiException(jsonObj);
+
+
+ }
+ else
+ {
+ //chain.doFilter(req, res);
+ return true;
+ }
+
+ } catch (CambriaApiException | NumberFormatException | JSONException e) {
+
+ log.info("Exception obj--"+e);
+ log.error("message size is greater then default"+e.getMessage());
+ ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_REQUEST_TOO_LONG,
+ DMaaPResponseCode.MSG_SIZE_EXCEEDS_MSG_LIMIT.getResponseCode(), System.getProperty("msg_size_exceeds")
+ + e.toString());
+ log.info(errRes.toString());
+
+
+ map.put(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,"test");
+ httpservletresponse.setStatus(HttpStatus.SC_REQUEST_TOO_LONG);
+ httpservletresponse.getOutputStream().write(errRes.toString().getBytes());
+ return false;
+ }
+
+
+
+ }
+
+
+ /**
+ * Get Default Content Length
+ * @return defLength
+ */
+ public String getDefLength() {
+ return defLength;
+ }
+ /**
+ * Set Default Content Length
+ * @param defLength
+ */
+ public void setDefLength(String defLength) {
+ this.defLength = defLength;
+ }
+
+
+
+}
diff --git a/src/test/java/com/att/nsa/dmaap/DMaaPCambriaExceptionMapperTest.java b/src/test/java/com/att/nsa/dmaap/DMaaPCambriaExceptionMapperTest.java
index 80c999f..eeeca29 100644
--- a/src/test/java/com/att/nsa/dmaap/DMaaPCambriaExceptionMapperTest.java
+++ b/src/test/java/com/att/nsa/dmaap/DMaaPCambriaExceptionMapperTest.java
@@ -38,23 +38,15 @@ public class DMaaPCambriaExceptionMapperTest {
@Test
public void testToResponse() {
-
+
DMaaPCambriaExceptionMapper mapper = new DMaaPCambriaExceptionMapper();
-
+
try {
mapper.toResponse(null);
- } catch(NullPointerException e) {
+ } catch (NullPointerException e) {
assertTrue(true);
}
-
-
-
-
-
+
}
-
-
-
-
} \ No newline at end of file
diff --git a/src/test/java/com/att/nsa/dmaap/DMaaPWebExceptionMapperTest.java b/src/test/java/com/att/nsa/dmaap/DMaaPWebExceptionMapperTest.java
index b791349..8569044 100644
--- a/src/test/java/com/att/nsa/dmaap/DMaaPWebExceptionMapperTest.java
+++ b/src/test/java/com/att/nsa/dmaap/DMaaPWebExceptionMapperTest.java
@@ -38,23 +38,15 @@ public class DMaaPWebExceptionMapperTest {
@Test
public void testToResponse() {
-
+
DMaaPWebExceptionMapper mapper = new DMaaPWebExceptionMapper();
-
+
try {
mapper.toResponse(null);
- } catch(NullPointerException e) {
+ } catch (NullPointerException e) {
assertTrue(true);
}
-
-
-
-
-
+
}
-
-
-
-
} \ No newline at end of file
diff --git a/src/test/java/com/att/nsa/dmaap/DummyTest.java b/src/test/java/com/att/nsa/dmaap/DummyTest.java
index 60e3931..ea5bac9 100644
--- a/src/test/java/com/att/nsa/dmaap/DummyTest.java
+++ b/src/test/java/com/att/nsa/dmaap/DummyTest.java
@@ -1,45 +1,45 @@
-/*******************************************************************************
- * ============LICENSE_START=======================================================
- * org.onap.dmaap
- * ================================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- *
- *******************************************************************************/
-package com.att.nsa.dmaap;
-
-import static org.junit.Assert.*;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-public class DummyTest {
-
- @Before
- public void setUp() throws Exception {
- }
-
- @After
- public void tearDown() throws Exception {
- }
-
- @Test
- public void test() {
- assertTrue("Dummy test case", true);
- }
-
-}
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * org.onap.dmaap
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ *
+ *******************************************************************************/
+package com.att.nsa.dmaap;
+
+import static org.junit.Assert.*;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class DummyTest {
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void test() {
+ assertTrue("Dummy test case", true);
+ }
+
+}
diff --git a/src/test/java/com/att/nsa/dmaap/HelloWorldTest.java b/src/test/java/com/att/nsa/dmaap/HelloWorldTest.java
index a821119..6191cf1 100644
--- a/src/test/java/com/att/nsa/dmaap/HelloWorldTest.java
+++ b/src/test/java/com/att/nsa/dmaap/HelloWorldTest.java
@@ -38,20 +38,15 @@ public class HelloWorldTest {
@Test
public void testToResponse() {
-
+
HelloWorld hello = new HelloWorld();
-
+
try {
hello.speak(null);
- } catch(NullPointerException e) {
+ } catch (NullPointerException e) {
assertTrue(true);
}
-
-
+
}
-
-
-
-
} \ No newline at end of file
diff --git a/src/test/java/com/att/nsa/dmaap/JaxrsUserServiceTest.java b/src/test/java/com/att/nsa/dmaap/JaxrsUserServiceTest.java
index 6a1c37b..acff4de 100644
--- a/src/test/java/com/att/nsa/dmaap/JaxrsUserServiceTest.java
+++ b/src/test/java/com/att/nsa/dmaap/JaxrsUserServiceTest.java
@@ -47,6 +47,4 @@ public class JaxrsUserServiceTest {
}
-
-
} \ No newline at end of file
diff --git a/src/test/java/com/att/nsa/dmaap/service/ApiKeysRestServiceTest.java b/src/test/java/com/att/nsa/dmaap/service/ApiKeysRestServiceTest.java
index f7aa278..225d434 100644
--- a/src/test/java/com/att/nsa/dmaap/service/ApiKeysRestServiceTest.java
+++ b/src/test/java/com/att/nsa/dmaap/service/ApiKeysRestServiceTest.java
@@ -123,7 +123,7 @@ public class ApiKeysRestServiceTest {
Class clazz = null;
Method method = null;
try {
- clazz = Class.forName("ApiKeysRestService");
+ clazz = Class.forName("com.att.nsa.dmaap.service.ApiKeysRestService");
Object obj = clazz.newInstance();
method = clazz.getDeclaredMethod("getDmaapContext", null);
method.setAccessible(true);
diff --git a/src/test/java/com/att/nsa/dmaap/service/MMRestServiceTest.java b/src/test/java/com/att/nsa/dmaap/service/MMRestServiceTest.java
index ed4c780..fbd9376 100644
--- a/src/test/java/com/att/nsa/dmaap/service/MMRestServiceTest.java
+++ b/src/test/java/com/att/nsa/dmaap/service/MMRestServiceTest.java
@@ -20,7 +20,11 @@
package com.att.nsa.dmaap.service;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.anyString;
+
+import java.io.FileInputStream;
//import static org.mockito.Matchers.anyString;
//import static org.mockito.Mockito.when;
@@ -32,21 +36,21 @@ import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import org.junit.After;
+import org.apache.commons.io.IOUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
+import org.junit.After;
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.powermock.modules.junit4.PowerMockRunner;
import com.att.ajsc.beans.PropertiesMapBean;
import com.att.ajsc.filemonitor.AJSCPropertiesMap;
@@ -70,11 +74,12 @@ import com.att.nsa.dmaap.mmagent.UpdateMirrorMaker;
import com.att.nsa.security.NsaAcl;
import com.att.nsa.security.NsaApiKey;
import com.att.nsa.security.db.simple.NsaSimpleApiKey;
+import com.google.gson.Gson;
//@RunWith(MockitoJUnitRunner.class)
-/*@RunWith(PowerMockRunner.class)
-@PrepareForTest({ PropertiesMapBean.class, AJSCPropertiesMap.class })*/
-public class MMRestServiceTest {/*
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({ PropertiesMapBean.class, AJSCPropertiesMap.class })
+public class MMRestServiceTest {
@InjectMocks
MMRestService mmRestService;
@@ -153,114 +158,108 @@ public class MMRestServiceTest {/*
public void tearDown() throws Exception {
}
-
@Test
public void testCallCreateMirrorMaker() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
TopicExistsException, JSONException, ConfigDbException {
-
- Assert.assertNotNull(mmRestService);
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
- when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin")).thenReturn(true);
- when(httpServReq.isUserInRole("admin")).thenReturn(true);
-
- PowerMockito.mockStatic(AJSCPropertiesMap.class);
-
+ prepareForTestCommon();
+ mmRestService.callCreateMirrorMaker(iStream);
assertTrue(true);
- when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormakeradmin.aaf"))
- .thenReturn("admin");
-
- when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormaker.timeout"))
- .thenReturn("100");
-
- when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormaker.topic"))
- .thenReturn("mirrormaker.topic");
-
- when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormaker.consumergroup"))
- .thenReturn("mirrormaker.consumergroup");
-
- when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormaker.consumerid"))
- .thenReturn("mirrormaker.consumerid");
-
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
-
- when(httpServReq.isUserInRole("admin")).thenReturn(true);
-
-
- // when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
- when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin.aaf")).thenReturn(true);
- when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin")).thenReturn(true);
- when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
- when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin")).thenReturn(true);
+ }
- when(cMirroMaker.getCreateMirrorMaker()).thenReturn(mMaker);
+ @Test
+ public void testCallListAllMirrorMaker() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
+ TopicExistsException, JSONException, ConfigDbException {
+ prepareForTestCommon();
+ mmRestService.callListAllMirrorMaker(iStream);
+ assertTrue(true);
+ }
- when(mMaker.getName()).thenReturn("mirroMakerName");
- when(dmaapContext.getConfigReader()).thenReturn(configReader);
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
- when(httpServReq.getHeader("Authorization")).thenReturn("Authorization");
+ @Test
+ public void testCallUpdateMirrorMaker() throws ConfigDbException, CambriaApiException {
+ prepareForTestCommon();
+ mmRestService.callUpdateMirrorMaker(iStream);
+ assertTrue(true);
+ }
- when(dmaapContext.getResponse()).thenReturn(httpServRes);
- when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- when(httpServReq.getMethod()).thenReturn("HEAD");
+ @Test
+ public void testCallDeleteMirrorMaker() throws ConfigDbException, CambriaApiException {
+ prepareForTestCommon();
+ mmRestService.callDeleteMirrorMaker(iStream);
+ assertTrue(true);
+ }
- when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);
+ @Test
+ public void testListWhiteList() throws ConfigDbException {
+ prepareForTestCommon();
+ mmRestService.listWhiteList(iStream);
+ assertTrue(true);
+ }
- mmRestService.callCreateMirrorMaker(iStream);
+ @Test
+ public void testCreateWhiteList() throws ConfigDbException {
+ prepareForTestCommon();
+ mmRestService.createWhiteList(iStream);
+ assertTrue(true);
}
@Test
- public void testCallListAllMirrorMaker() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
- TopicExistsException, JSONException, ConfigDbException {
+ public void testDeleteWhiteList() throws ConfigDbException {
+ prepareForTestCommon();
+ mmRestService.deleteWhiteList(iStream);
+ assertTrue(true);
+ }
+ private void prepareForTestCommon() throws ConfigDbException {
Assert.assertNotNull(mmRestService);
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
- when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin")).thenReturn(true);
- when(httpServReq.isUserInRole("admin")).thenReturn(true);
+ PowerMockito.when(dmaapContext.getRequest()).thenReturn(httpServReq);
+ PowerMockito.when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin")).thenReturn(true);
+ PowerMockito.when(httpServReq.isUserInRole("admin")).thenReturn(true);
PowerMockito.mockStatic(AJSCPropertiesMap.class);
assertTrue(true);
- when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormakeradmin.aaf"))
+
+ PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormakeradmin.aaf"))
+ .thenReturn("admin");
+
+ PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormakeruser.aaf"))
.thenReturn("admin");
- when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormaker.timeout"))
+ PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormaker.timeout"))
.thenReturn("100");
- when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormaker.topic"))
+ PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormaker.topic"))
.thenReturn("mirrormaker.topic");
- when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormaker.consumergroup"))
+ PowerMockito
+ .when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormaker.consumergroup"))
.thenReturn("mirrormaker.consumergroup");
- when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormaker.consumerid"))
+ PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormaker.consumerid"))
.thenReturn("mirrormaker.consumerid");
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
+ PowerMockito.when(dmaapContext.getRequest()).thenReturn(httpServReq);
- when(httpServReq.isUserInRole("admin")).thenReturn(true);
-
+ PowerMockito.when(httpServReq.isUserInRole("admin")).thenReturn(true);
- // when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
- when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin.aaf")).thenReturn(true);
- when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin")).thenReturn(true);
- when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
- when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin")).thenReturn(true);
+ // PowerMockito.when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
+ PowerMockito.when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin.aaf")).thenReturn(true);
+ PowerMockito.when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin")).thenReturn(true);
+ PowerMockito.when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
+ PowerMockito.when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin")).thenReturn(true);
- when(cMirroMaker.getCreateMirrorMaker()).thenReturn(mMaker);
+ PowerMockito.when(cMirroMaker.getCreateMirrorMaker()).thenReturn(mMaker);
- when(mMaker.getName()).thenReturn("mirroMakerName");
- when(dmaapContext.getConfigReader()).thenReturn(configReader);
- when(dmaapContext.getRequest()).thenReturn(httpServReq);
- when(httpServReq.getHeader("Authorization")).thenReturn("Authorization");
+ PowerMockito.when(mMaker.getName()).thenReturn("mirroMakerName");
+ PowerMockito.when(dmaapContext.getConfigReader()).thenReturn(configReader);
+ PowerMockito.when(dmaapContext.getRequest()).thenReturn(httpServReq);
+ PowerMockito.when(httpServReq.getHeader("Authorization")).thenReturn("Authorization");
- when(dmaapContext.getResponse()).thenReturn(httpServRes);
- when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
- when(httpServReq.getMethod()).thenReturn("HEAD");
+ PowerMockito.when(dmaapContext.getResponse()).thenReturn(httpServRes);
+ PowerMockito.when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
+ PowerMockito.when(httpServReq.getMethod()).thenReturn("HEAD");
- when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);
-
- mmRestService.callListAllMirrorMaker(iStream);
+ PowerMockito.when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);
}
-
-*/}
+}
diff --git a/src/test/java/com/att/nsa/dmaap/util/ContentLengthInterceptorTest.java b/src/test/java/com/att/nsa/dmaap/util/ContentLengthInterceptorTest.java
index 5d9a3a6..36d52e0 100644
--- a/src/test/java/com/att/nsa/dmaap/util/ContentLengthInterceptorTest.java
+++ b/src/test/java/com/att/nsa/dmaap/util/ContentLengthInterceptorTest.java
@@ -20,19 +20,41 @@
package com.att.nsa.dmaap.util;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({ System.class })
public class ContentLengthInterceptorTest {
+ @InjectMocks
+ ContentLengthInterceptor interceptor = null;
+
+ @Mock
+ Map map;
- private ContentLengthInterceptor interceptor = null;
+ @Mock
+ HttpServletRequest req;
+
+ @Mock
+ HttpServletResponse res;
@Before
public void setUp() throws Exception {
- interceptor = new ContentLengthInterceptor();
+ // interceptor = new ContentLengthInterceptor();
}
@After
@@ -40,34 +62,22 @@ public class ContentLengthInterceptorTest {
}
@Test
- public void testAllowOrReject() {
-
- try {
- interceptor.allowOrReject(null, null, null);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
+ public void testAllowOrReject() throws Exception {
+ PowerMockito.when(req.getHeader("Transfer-Encoding")).thenReturn("UTF-8");
+ PowerMockito.when(req.getHeader("Content-Length")).thenReturn("1027");
+ interceptor.allowOrReject(req, res, map);
assertTrue(true);
-
}
@Test
public void testGetDefLength() {
-
interceptor.getDefLength();
-
assertTrue(true);
-
-
}
-
+
@Test
public void testSetDefLength() {
-
interceptor.setDefLength("defLength");
-
assertTrue(true);
}
diff --git a/src/test/java/com/att/nsa/dmaap/util/DMaaPAuthFilterTest.java b/src/test/java/com/att/nsa/dmaap/util/DMaaPAuthFilterTest.java
index 33cd6af..baf5d74 100644
--- a/src/test/java/com/att/nsa/dmaap/util/DMaaPAuthFilterTest.java
+++ b/src/test/java/com/att/nsa/dmaap/util/DMaaPAuthFilterTest.java
@@ -20,50 +20,47 @@
package com.att.nsa.dmaap.util;
+import java.io.IOException;
+
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
import org.junit.After;
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 com.att.ajsc.beans.PropertiesMapBean;
-import static org.mockito.Mockito.when;
-*/
-import java.io.IOException;
-import javax.servlet.FilterChain;
-import javax.servlet.ServletException;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletRequest;
-
import com.att.nsa.cambria.beans.DMaaPContext;
import com.att.nsa.cambria.exception.DMaaPResponseCode;
-/*@RunWith(PowerMockRunner.class)
-@PrepareForTest({ PropertiesMapBean.class, DMaaPResponseCode.class })*/
-public class DMaaPAuthFilterTest {/*
-
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({ PropertiesMapBean.class, DMaaPResponseCode.class })
+public class DMaaPAuthFilterTest {
+
@InjectMocks
DMaaPAuthFilter filter;
-
+
@Mock
- HttpServletRequest req;
-
+ HttpServletRequest req;
+
@Mock
ServletResponse res;
-
-
+
@Mock
FilterChain chain;
-
+
@Mock
DMaaPContext dmaapContext;
-
+
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
@@ -75,28 +72,23 @@ public class DMaaPAuthFilterTest {/*
@Test
public void testDoFilter() throws IOException, ServletException {
-
- when(dmaapContext.getRequest()).thenReturn(req);
- when(req.getHeader("Authorization")).thenReturn("Authorization");
-
- //when(dmaapContext.getResponse()).thenReturn(res);
- filter.doFilter(req, res, chain);
+ PowerMockito.when(dmaapContext.getRequest()).thenReturn(req);
+ PowerMockito.when(req.getHeader("Authorization")).thenReturn("Authorization");
+ // when(dmaapContext.getResponse()).thenReturn(res);
+ filter.doFilter(req, res, chain);
}
-
+
@Test
public void testDoFilter_nullAuth() throws IOException, ServletException {
-
- when(dmaapContext.getRequest()).thenReturn(req);
- //when(req.getHeader("Authorization")).thenReturn("Authorization");
-
- //when(dmaapContext.getResponse()).thenReturn(res);
- filter.doFilter(req, res, chain);
+ PowerMockito.when(dmaapContext.getRequest()).thenReturn(req);
+ PowerMockito.when(req.getHeader("Authorization")).thenReturn("Authorization");
+
+ // when(dmaapContext.getResponse()).thenReturn(res);
+ filter.doFilter(req, res, chain);
}
-
-
-*/} \ No newline at end of file
+} \ No newline at end of file
diff --git a/src/test/java/com/att/nsa/dmaap/util/ServicePropertiesMapBeanTest.java b/src/test/java/com/att/nsa/dmaap/util/ServicePropertiesMapBeanTest.java
index cb9cf38..da3eaf0 100644
--- a/src/test/java/com/att/nsa/dmaap/util/ServicePropertiesMapBeanTest.java
+++ b/src/test/java/com/att/nsa/dmaap/util/ServicePropertiesMapBeanTest.java
@@ -28,11 +28,9 @@ import org.junit.Test;
public class ServicePropertiesMapBeanTest {
-
-
@Before
public void setUp() throws Exception {
-
+
}
@After
@@ -41,12 +39,10 @@ public class ServicePropertiesMapBeanTest {
@Test
public void testGetProperty() {
-
-
+
try {
ServicePropertiesMapBean.getProperty(null, null);
} catch (Exception e) {
- // TODO Auto-generated catch block
e.printStackTrace();
}
@@ -54,6 +50,4 @@ public class ServicePropertiesMapBeanTest {
}
-
-
} \ No newline at end of file