summaryrefslogtreecommitdiffstats
path: root/src/test/java/com/att/nsa/cambria/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/com/att/nsa/cambria/utils')
-rw-r--r--src/test/java/com/att/nsa/cambria/utils/ConfigurationReaderTest.java56
-rw-r--r--src/test/java/com/att/nsa/cambria/utils/DMaaPCuratorFactoryTest.java70
-rw-r--r--src/test/java/com/att/nsa/cambria/utils/DMaaPResponseBuilderTest.java141
-rw-r--r--src/test/java/com/att/nsa/cambria/utils/UtilsTest.java125
4 files changed, 0 insertions, 392 deletions
diff --git a/src/test/java/com/att/nsa/cambria/utils/ConfigurationReaderTest.java b/src/test/java/com/att/nsa/cambria/utils/ConfigurationReaderTest.java
deleted file mode 100644
index 907b935..0000000
--- a/src/test/java/com/att/nsa/cambria/utils/ConfigurationReaderTest.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP Policy Engine
- * ================================================================================
- * Copyright (C) 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=========================================================
- */
-
-package com.att.nsa.cambria.utils;
-
-import static org.junit.Assert.assertNotNull;
-
-import org.junit.After;
-import org.junit.Test;
-
-import com.att.nsa.cambria.embed.EmbedConfigurationReader;
-import com.att.dmf.mr.utils.ConfigurationReader;
-
-public class ConfigurationReaderTest {
-
- EmbedConfigurationReader embedConfigurationReader = new EmbedConfigurationReader();
-
- @After
- public void tearDown() throws Exception {
- embedConfigurationReader.tearDown();
- }
-
- @Test
- public void testConfigurationReader() throws Exception {
-
- ConfigurationReader configurationReader = embedConfigurationReader.buildConfigurationReader();
-
- assertNotNull(configurationReader);
- assertNotNull(configurationReader.getfApiKeyDb());
- assertNotNull(configurationReader.getfConfigDb());
- assertNotNull(configurationReader.getfConsumerFactory());
- assertNotNull(configurationReader.getfIpBlackList());
- assertNotNull(configurationReader.getfMetaBroker());
- assertNotNull(configurationReader.getfMetrics());
- assertNotNull(configurationReader.getfPublisher());
- assertNotNull(configurationReader.getfSecurityManager());
- }
-
-}
diff --git a/src/test/java/com/att/nsa/cambria/utils/DMaaPCuratorFactoryTest.java b/src/test/java/com/att/nsa/cambria/utils/DMaaPCuratorFactoryTest.java
deleted file mode 100644
index 90e6f6f..0000000
--- a/src/test/java/com/att/nsa/cambria/utils/DMaaPCuratorFactoryTest.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP Policy Engine
- * ================================================================================
- * Copyright (C) 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=========================================================
- */
-
-package com.att.nsa.cambria.utils;
-
-import static org.junit.Assert.*;
-
-import java.io.File;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.curator.framework.CuratorFramework;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.att.ajsc.filemonitor.AJSCPropertiesMap;
-import com.att.dmf.mr.constants.CambriaConstants;
-import com.att.dmf.mr.utils.DMaaPCuratorFactory;
-import com.att.dmf.mr.utils.PropertyReader;
-import com.att.nsa.drumlin.till.nv.rrNvReadable.loadException;
-import com.att.nsa.drumlin.till.nv.impl.nvPropertiesFile;
-import com.att.nsa.drumlin.till.nv.impl.nvReadableTable;
-
-public class DMaaPCuratorFactoryTest {
-
- @Before
- public void setUp() throws Exception {
- ClassLoader classLoader = getClass().getClassLoader();
- AJSCPropertiesMap.refresh(new File(classLoader.getResource(CambriaConstants.msgRtr_prop).getFile()));
-
- }
-
- @After
- public void tearDown() throws Exception {
- }
-
- @Test
- public void testgetCurator() throws loadException {
- CuratorFramework curatorFramework = DMaaPCuratorFactory.getCurator(new PropertyReader());
- assertNotNull(curatorFramework);
-
- Map<String, String> map = com.att.ajsc.filemonitor.AJSCPropertiesMap.getProperties(CambriaConstants.msgRtr_prop);
- map.remove(CambriaConstants.kSetting_ZkConfigDbServers);
- map.remove(CambriaConstants.kSetting_ZkSessionTimeoutMs);
-
-
-
- curatorFramework = DMaaPCuratorFactory.getCurator(new PropertyReader());
- assertNotNull(curatorFramework);
- }
-
-}
diff --git a/src/test/java/com/att/nsa/cambria/utils/DMaaPResponseBuilderTest.java b/src/test/java/com/att/nsa/cambria/utils/DMaaPResponseBuilderTest.java
deleted file mode 100644
index 66e4405..0000000
--- a/src/test/java/com/att/nsa/cambria/utils/DMaaPResponseBuilderTest.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP Policy Engine
- * ================================================================================
- * Copyright (C) 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=========================================================
- */
-
-package com.att.nsa.cambria.utils;
-
-import static org.junit.Assert.*;
-
-import java.io.IOException;
-
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.springframework.mock.web.MockHttpServletRequest;
-import org.springframework.mock.web.MockHttpServletResponse;
-
-import com.att.dmf.mr.beans.DMaaPContext;
-import com.att.dmf.mr.utils.DMaaPResponseBuilder;
-
-public class DMaaPResponseBuilderTest {
-
- DMaaPContext dMaapContext;
- MockHttpServletRequest request;
- MockHttpServletResponse response;
-
- @Before
- public void setUp() throws Exception {
-
- dMaapContext = new DMaaPContext();
- request = new MockHttpServletRequest();
- response = new MockHttpServletResponse();
- dMaapContext.setRequest(request);
- dMaapContext.setResponse(response);
- }
-
- @After
- public void tearDown() throws Exception {
- }
-
- @Test
- public void testsetNoCacheHeadings(){
- DMaaPResponseBuilder.setNoCacheHeadings(dMaapContext);
- assertEquals("no-cache", response.getHeader("Pragma"));
- }
-
- @Test
- public void testrespondOk() throws JSONException, IOException{
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("Name", "Test");
-
- DMaaPResponseBuilder.respondOk(dMaapContext, jsonObject);
- assertEquals("application/json", response.getContentType());
- assertEquals(200, response.getStatus());
-
- request.setMethod("HEAD");
-
- DMaaPResponseBuilder.respondOk(dMaapContext, jsonObject);
- assertEquals("application/json", response.getContentType());
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void testrespondOkNoContent(){
- DMaaPResponseBuilder.respondOkNoContent(dMaapContext);
- assertEquals(204, response.getStatus());
- }
-
- @Test
- public void testrespondOkWithHtml(){
- DMaaPResponseBuilder.respondOkWithHtml(dMaapContext, "<head></head>");
-
- assertEquals("text/html", response.getContentType());
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void testrespondWithError(){
- DMaaPResponseBuilder.respondWithError(dMaapContext, 500, "InternalServerError");
- assertEquals(500, response.getStatus());
- }
-
- @Test
- public void testrespondWithJsonError(){
- JSONObject o = new JSONObject();
- o.put("status", 500);
- o.put("message", "InternalServerError");
- DMaaPResponseBuilder.respondWithError(dMaapContext, 500, o);
- assertEquals(500, response.getStatus());
- }
-
- @Test
- public void testrespondWithErrorInJson(){
- DMaaPResponseBuilder.respondWithErrorInJson(dMaapContext, 500, "InternalServerError");
-
- assertEquals("application/json", response.getContentType());
- assertEquals(500, response.getStatus());
- }
-
- @Test
- public void testsendErrorAndBody(){
- DMaaPResponseBuilder.sendErrorAndBody(dMaapContext, 500, "InternalServerError", "text/html");
-
- assertEquals("text/html", response.getContentType());
- assertEquals(500, response.getStatus());
-
- request.setMethod("HEAD");
-
- DMaaPResponseBuilder.sendErrorAndBody(dMaapContext, 500, "InternalServerError", "text/html");
-
- assertEquals("text/html", response.getContentType());
- assertEquals(500, response.getStatus());
-
- }
-
- @Test
- public void testgetStreamForBinaryResponse() throws IOException{
- DMaaPResponseBuilder.getStreamForBinaryResponse(dMaapContext);
-
- assertEquals("application/octet-stream", response.getContentType());
- assertEquals(200, response.getStatus());
- }
-
-}
diff --git a/src/test/java/com/att/nsa/cambria/utils/UtilsTest.java b/src/test/java/com/att/nsa/cambria/utils/UtilsTest.java
deleted file mode 100644
index bff4d48..0000000
--- a/src/test/java/com/att/nsa/cambria/utils/UtilsTest.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*******************************************************************************
-/*-
- * ============LICENSE_START=======================================================
- * ONAP Policy Engine
- * ================================================================================
- * Copyright (C) 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=========================================================
- */
-
-package com.att.nsa.cambria.utils;
-
-import static org.junit.Assert.*;
-
-import java.security.Principal;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.http.auth.BasicUserPrincipal;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.springframework.mock.web.MockHttpServletRequest;
-
-import com.att.dmf.mr.beans.DMaaPContext;
-import com.att.dmf.mr.utils.Utils;
-
-public class UtilsTest {
-
- private static final String DATE_FORMAT = "dd-MM-yyyy::hh:mm:ss:SSS";
-
- @Before
- public void setUp() throws Exception {
- }
-
- @After
- public void tearDown() throws Exception {
- }
-
- @Test
- public void testGetFormattedDate() {
- Date now = new Date();
- String dateStr = Utils.getFormattedDate(now);
- SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
- String expectedStr = sdf.format(now);
- assertNotNull(dateStr);
- assertTrue("Formatted date does not match - expected [" + expectedStr
- + "] received [" + dateStr + "]",
- dateStr.equalsIgnoreCase(expectedStr));
- }
-
- @Test
- public void testgetUserApiKey(){
- MockHttpServletRequest request = new MockHttpServletRequest();
- request.addHeader(Utils.CAMBRIA_AUTH_HEADER, "User:Password");
- assertEquals("User", Utils.getUserApiKey(request));
-
- MockHttpServletRequest request2 = new MockHttpServletRequest();
- Principal principal = new BasicUserPrincipal("User@Test");
- request2.setUserPrincipal(principal);
- request2.addHeader("Authorization", "test");
- assertEquals("User", Utils.getUserApiKey(request2));
-
- MockHttpServletRequest request3 = new MockHttpServletRequest();
- assertNull(Utils.getUserApiKey(request3));
- }
-
- @Test
- public void testgetFromattedBatchSequenceId(){
- Long x = new Long(1234);
- String str = Utils.getFromattedBatchSequenceId(x);
- assertEquals("001234", str);
- }
-
- @Test
- public void testmessageLengthInBytes(){
- String str = "TestString";
- long length = Utils.messageLengthInBytes(str);
- assertEquals(10, length);
- assertEquals(0, Utils.messageLengthInBytes(null));
- }
-
- @Test
- public void testgetResponseTransactionId(){
- String transactionId = "test123::sampleResponseMessage";
- assertEquals("test123",Utils.getResponseTransactionId(transactionId));
- assertNull(Utils.getResponseTransactionId(null));
- assertNull(Utils.getResponseTransactionId(""));
- }
-
- @Test
- public void testgetSleepMsForRate(){
- long x = Utils.getSleepMsForRate(1024.124);
- assertEquals(1000, x);
- assertEquals(0, Utils.getSleepMsForRate(-1));
- }
-
- @Test
- public void testgetRemoteAddress(){
- DMaaPContext dMaapContext = new DMaaPContext();
- MockHttpServletRequest request = new MockHttpServletRequest();
-
- dMaapContext.setRequest(request);
-
- assertEquals(request.getRemoteAddr(), Utils.getRemoteAddress(dMaapContext));
-
- request.addHeader("X-Forwarded-For", "XForward");
- assertEquals("XForward", Utils.getRemoteAddress(dMaapContext));
-
-
- }
-}