aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt/apigateway/provider/src/test/java
diff options
context:
space:
mode:
authorhighstreetherbert <herbert.eiselt@highstreet-technologies.com>2020-07-10 12:45:37 +0200
committerhighstreetherbert <herbert.eiselt@highstreet-technologies.com>2020-07-10 15:09:50 +0200
commit4a2409623b1744028abf6d5d8d1b6546919aec61 (patch)
tree47e88fda15215b5ff8e8dd17bce597d968c36ac2 /sdnr/wt/apigateway/provider/src/test/java
parent23c27ddcd79913d11eac16eb42c5a43899de97a1 (diff)
Reformat sdnr apigateway to ONAP code style
Reformat to ONAP code style Issue-ID: SDNC-1271 Signed-off-by: highstreetherbert <herbert.eiselt@highstreet-technologies.com> Change-Id: I18f7e93e461b94949cf5a7d9262eaf33b17c6ac9 Signed-off-by: highstreetherbert <herbert.eiselt@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/apigateway/provider/src/test/java')
-rw-r--r--sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestAaiServlet.java99
-rw-r--r--sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestDatabaseServlet.java120
-rw-r--r--sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestProperties.java155
-rw-r--r--sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpAaiServlet.java60
-rw-r--r--sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpEsServlet.java56
-rw-r--r--sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpServlet.java44
-rw-r--r--sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpServletBase.java337
-rw-r--r--sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/IPublicServlet.java14
8 files changed, 454 insertions, 431 deletions
diff --git a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestAaiServlet.java b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestAaiServlet.java
index 0af4d69df..06bf2c17e 100644
--- a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestAaiServlet.java
+++ b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestAaiServlet.java
@@ -34,53 +34,56 @@ import org.onap.ccsdk.features.sdnr.wt.apigateway.test.helper.HelpAaiServlet;
import org.onap.ccsdk.features.sdnr.wt.apigateway.test.helper.HelpEsServlet;
import org.onap.ccsdk.features.sdnr.wt.apigateway.test.helper.HelpServletBase;
-public class TestAaiServlet extends HelpServletBase{
+public class TestAaiServlet extends HelpServletBase {
- private static final int PORT = 40001;
- public TestAaiServlet() {
- super("/aai",PORT);
- }
-
- @Test
- public void test() throws ServletException, IOException {
-
- String tmpFilename = "tmp.cfg";
- File tmpFile = new File(tmpFilename);
- if (tmpFile.exists())
- tmpFile.delete();
- MyProperties properties = MyProperties.Instantiate(tmpFile,true);
- String query = "{\"query\":{\"match_all\":{}}}";
- String tmpconfigcontent = "aai=off" + LR + "aaiHeaders=[]" + LR + "database=off" + LR + "insecure=0" + LR
- + "cors=0";
- String tmpconfigcontent2 = "aai=http://" + HOST + ":" + PORT + LR + "aaiHeaders=[]" + LR + "database=off"+ LR
- + "insecure=1" + LR + "cors=1";
- this.setServlet(new HelpAaiServlet());
- // test disabled message
- properties.load(new ByteArrayInputStream(tmpconfigcontent.getBytes()));
- String expectedResponse = "offline";
- testrequest(HTTPMETHOD_GET, query, expectedResponse, false);
- testrequest(HTTPMETHOD_POST, query, expectedResponse, false);
- testrequest(HTTPMETHOD_PUT, query, expectedResponse, false);
- testrequest(HTTPMETHOD_DELETE, query, expectedResponse, false);
-
- // initEsTestWebserver(port);
- properties.load(new ByteArrayInputStream(tmpconfigcontent2.getBytes()));
- testrequest(HTTPMETHOD_GET, query, HelpEsServlet.RESPONSE_GET, true);
- testrequest(HTTPMETHOD_POST, query, HelpEsServlet.RESPONSE_POST, true);
- testrequest(HTTPMETHOD_PUT, query, HelpEsServlet.RESPONSE_PUT, true);
- testrequest(HTTPMETHOD_DELETE, query, HelpEsServlet.RESPONSE_DELETE, true);
- testrequest(HTTPMETHOD_OPTIONS, query, "", false);
- // stopTestWebserver();
- if (tmpFile.exists())
- tmpFile.delete();
-
- }
- @Before
- public void init() throws IOException{
- HelpServletBase.initEsTestWebserver(PORT);
- }
- @After
- public void deinit() {
- HelpServletBase.stopTestWebserver();
- }
+ private static final int PORT = 40001;
+
+ public TestAaiServlet() {
+ super("/aai", PORT);
+ }
+
+ @Test
+ public void test() throws ServletException, IOException {
+
+ String tmpFilename = "tmp.cfg";
+ File tmpFile = new File(tmpFilename);
+ if (tmpFile.exists())
+ tmpFile.delete();
+ MyProperties properties = MyProperties.Instantiate(tmpFile, true);
+ String query = "{\"query\":{\"match_all\":{}}}";
+ String tmpconfigcontent =
+ "aai=off" + LR + "aaiHeaders=[]" + LR + "database=off" + LR + "insecure=0" + LR + "cors=0";
+ String tmpconfigcontent2 = "aai=http://" + HOST + ":" + PORT + LR + "aaiHeaders=[]" + LR + "database=off" + LR
+ + "insecure=1" + LR + "cors=1";
+ this.setServlet(new HelpAaiServlet());
+ // test disabled message
+ properties.load(new ByteArrayInputStream(tmpconfigcontent.getBytes()));
+ String expectedResponse = "offline";
+ testrequest(HTTPMETHOD_GET, query, expectedResponse, false);
+ testrequest(HTTPMETHOD_POST, query, expectedResponse, false);
+ testrequest(HTTPMETHOD_PUT, query, expectedResponse, false);
+ testrequest(HTTPMETHOD_DELETE, query, expectedResponse, false);
+
+ // initEsTestWebserver(port);
+ properties.load(new ByteArrayInputStream(tmpconfigcontent2.getBytes()));
+ testrequest(HTTPMETHOD_GET, query, HelpEsServlet.RESPONSE_GET, true);
+ testrequest(HTTPMETHOD_POST, query, HelpEsServlet.RESPONSE_POST, true);
+ testrequest(HTTPMETHOD_PUT, query, HelpEsServlet.RESPONSE_PUT, true);
+ testrequest(HTTPMETHOD_DELETE, query, HelpEsServlet.RESPONSE_DELETE, true);
+ testrequest(HTTPMETHOD_OPTIONS, query, "", false);
+ // stopTestWebserver();
+ if (tmpFile.exists())
+ tmpFile.delete();
+
+ }
+
+ @Before
+ public void init() throws IOException {
+ HelpServletBase.initEsTestWebserver(PORT);
+ }
+
+ @After
+ public void deinit() {
+ HelpServletBase.stopTestWebserver();
+ }
}
diff --git a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestDatabaseServlet.java b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestDatabaseServlet.java
index d7b4c1511..bc6859ac1 100644
--- a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestDatabaseServlet.java
+++ b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestDatabaseServlet.java
@@ -30,63 +30,65 @@ import org.onap.ccsdk.features.sdnr.wt.apigateway.test.helper.HelpServletBase;
import java.io.*;
import javax.servlet.ServletException;
-public class TestDatabaseServlet extends HelpServletBase{
-
- private static final int PORT = 40002;
-
- public TestDatabaseServlet() {
- super("/database",PORT);
- }
-
-
-
- final String LR = "\n";
-
-
-
- @Test
- public void test() throws ServletException, IOException {
-
- String tmpFilename = "tmp1.cfg";
- File tmpFile = new File(tmpFilename);
- if (tmpFile.exists())
- tmpFile.delete();
- MyProperties properties = MyProperties.Instantiate(tmpFile,true);
- String query = "{\"query\":{\"match_all\":{}}}";
- String tmpconfigcontent = "aai=off" + LR + "aaiHeaders=[]" + LR + "database=off" + LR + "insecure=0" + LR
- + "cors=0";
- String tmpconfigcontent2 = "aai=off" + LR + "aaiHeaders=[]" + LR + "database=http://" + HOST + ":" + PORT + LR
- + "insecure=1" + LR + "cors=1";
- this.setServlet(new HelpEsServlet());
- // test diabled message
- properties.load(new ByteArrayInputStream(tmpconfigcontent.getBytes()));
- String expectedResponse = "offline";
- testrequest(HTTPMETHOD_GET, query, expectedResponse, false);
- testrequest(HTTPMETHOD_POST, query, expectedResponse, false);
- testrequest(HTTPMETHOD_PUT, query, expectedResponse, false);
- testrequest(HTTPMETHOD_DELETE, query, expectedResponse, false);
-
- // initEsTestWebserver(port);
- properties.load(new ByteArrayInputStream(tmpconfigcontent2.getBytes()));
- testrequest(HTTPMETHOD_GET, query, HelpEsServlet.RESPONSE_GET, true);
- testrequest(HTTPMETHOD_POST, query, HelpEsServlet.RESPONSE_POST, true);
- testrequest(HTTPMETHOD_PUT, query, HelpEsServlet.RESPONSE_PUT, true);
- testrequest(HTTPMETHOD_DELETE, query, HelpEsServlet.RESPONSE_DELETE, true);
- testrequest(HTTPMETHOD_OPTIONS, query, "", false);
- // stopTestWebserver();
-
-
- if (tmpFile.exists())
- tmpFile.delete();
-
-
- }
- @Before
- public void init() throws IOException{
- HelpServletBase.initEsTestWebserver(PORT);
- }
- @After
- public void deinit() {
- HelpServletBase.stopTestWebserver();
- }
+public class TestDatabaseServlet extends HelpServletBase {
+
+ private static final int PORT = 40002;
+
+ public TestDatabaseServlet() {
+ super("/database", PORT);
+ }
+
+
+
+ final String LR = "\n";
+
+
+
+ @Test
+ public void test() throws ServletException, IOException {
+
+ String tmpFilename = "tmp1.cfg";
+ File tmpFile = new File(tmpFilename);
+ if (tmpFile.exists())
+ tmpFile.delete();
+ MyProperties properties = MyProperties.Instantiate(tmpFile, true);
+ String query = "{\"query\":{\"match_all\":{}}}";
+ String tmpconfigcontent =
+ "aai=off" + LR + "aaiHeaders=[]" + LR + "database=off" + LR + "insecure=0" + LR + "cors=0";
+ String tmpconfigcontent2 = "aai=off" + LR + "aaiHeaders=[]" + LR + "database=http://" + HOST + ":" + PORT + LR
+ + "insecure=1" + LR + "cors=1";
+ this.setServlet(new HelpEsServlet());
+ // test diabled message
+ properties.load(new ByteArrayInputStream(tmpconfigcontent.getBytes()));
+ String expectedResponse = "offline";
+ testrequest(HTTPMETHOD_GET, query, expectedResponse, false);
+ testrequest(HTTPMETHOD_POST, query, expectedResponse, false);
+ testrequest(HTTPMETHOD_PUT, query, expectedResponse, false);
+ testrequest(HTTPMETHOD_DELETE, query, expectedResponse, false);
+
+ // initEsTestWebserver(port);
+ properties.load(new ByteArrayInputStream(tmpconfigcontent2.getBytes()));
+ testrequest(HTTPMETHOD_GET, query, HelpEsServlet.RESPONSE_GET, true);
+ testrequest(HTTPMETHOD_POST, query, HelpEsServlet.RESPONSE_POST, true);
+ testrequest(HTTPMETHOD_PUT, query, HelpEsServlet.RESPONSE_PUT, true);
+ testrequest(HTTPMETHOD_DELETE, query, HelpEsServlet.RESPONSE_DELETE, true);
+ testrequest(HTTPMETHOD_OPTIONS, query, "", false);
+ // stopTestWebserver();
+
+
+ if (tmpFile.exists())
+ tmpFile.delete();
+
+
+ }
+
+ @Before
+ public void init() throws IOException {
+ HelpServletBase.initEsTestWebserver(PORT);
+ }
+
+ @After
+ public void deinit() {
+ HelpServletBase.stopTestWebserver();
+ }
}
diff --git a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestProperties.java b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestProperties.java
index 6efd06feb..6fad884ff 100644
--- a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestProperties.java
+++ b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestProperties.java
@@ -34,82 +34,83 @@ import org.onap.ccsdk.features.sdnr.wt.apigateway.MyProperties;
public class TestProperties {
- private static final boolean DEFAULT_CORSENABLED = false;
- private static final boolean DEFAULT_AAIOFF = true;
- private static final boolean DEFAULT_ESOFF = false;
- private static final boolean DEFAULT_TRUSTINSECURE = false;
- private static final String DEFAULT_AAIBASEURL = "off";
- private static Map<String, String> DEFAULT_AAIHEADERS = new HashMap<String, String>();
- private static final String DEFAULT_ESBASEURL = "http://sdnrdb:9200";
-
- private static final boolean CUSTOM_CORSENABLED = true;
- private static final boolean CUSTOM_AAIOFF = false;
- private static final boolean CUSTOM_ESOFF = false;
- private static final boolean CUSTOM_TRUSTINSECURE = true;
- private static final String CUSTOM_AAIBASEURL = "https://aai.tld:2214";
- private static Map<String, String> CUSTOM_AAIHEADERS = new HashMap<String, String>();
- private static final String CUSTOM_ESBASEURL = "http://localhost:9200";
-
- private static final String LR = "\n";
- final String tmpFilename = "tmp2.cfg";
-
- @Before
- @After
- public void init() {
- File f = new File(tmpFilename);
- if(f.exists()) {
- f.delete();
- }
- }
- @Test
- public void test() {
- DEFAULT_AAIHEADERS.put("X-FromAppId", "SDNR");
- DEFAULT_AAIHEADERS.put("Authorization", "Basic QUFJOkFBSQ==");
- CUSTOM_AAIHEADERS.put("X-FromAppId", "SDNC");
- CUSTOM_AAIHEADERS.put("Authorization", "Basic 1234");
- final String TESTPROPERTYFILECONTENT = "aai=" + CUSTOM_AAIBASEURL + LR + "aaiHeaders=[\"X-FromAppId:"
- + CUSTOM_AAIHEADERS.get("X-FromAppId") + "\",\"Authorization:" + CUSTOM_AAIHEADERS.get("Authorization")
- + "\"]" + LR + "database=" + CUSTOM_ESBASEURL + LR + "insecure=" + (CUSTOM_TRUSTINSECURE ? "1" : "0")
- + LR + "cors=" + (CUSTOM_CORSENABLED ? "1" : "0");
- File ftest = new File(tmpFilename);
- MyProperties prop = null;
- ftest = new File(tmpFilename);
- try {
- prop = MyProperties.Instantiate(ftest, true);
- } catch (Exception e) {
- fail("error instantiating properties");
- }
- assertNotNull("problem without exception instantiating properties", prop);
-
- assertEquals("default config file was not created", true, ftest.exists());
-
- // test default values
- assertEquals("default value is not correct", DEFAULT_CORSENABLED, prop.corsEnabled());
- assertEquals("default value is not correct", DEFAULT_AAIOFF, prop.isAAIOff());
- assertEquals("default value is not correct", DEFAULT_ESOFF, prop.isEsOff());
- assertEquals("default value is not correct", DEFAULT_TRUSTINSECURE, prop.trustInsecure());
- assertEquals("default value is not correct", DEFAULT_AAIBASEURL, prop.getAAIBaseUrl());
- assertEquals("default value is not correct", DEFAULT_AAIHEADERS, prop.getAAIHeaders());
- assertEquals("default value is not correct", DEFAULT_ESBASEURL, prop.getEsBaseUrl());
-
- try {
- prop.load(new ByteArrayInputStream(TESTPROPERTYFILECONTENT.getBytes()));
- } catch (Exception e) {
- fail("error loading custom values into properties");
- }
-
- // test custom values
- assertEquals("custom value is not correct", CUSTOM_CORSENABLED, prop.corsEnabled());
- assertEquals("custom value is not correct", CUSTOM_AAIOFF, prop.isAAIOff());
- assertEquals("custom value is not correct", CUSTOM_ESOFF, prop.isEsOff());
- assertEquals("custom value is not correct", CUSTOM_TRUSTINSECURE, prop.trustInsecure());
- assertEquals("custom value is not correct", CUSTOM_AAIBASEURL, prop.getAAIBaseUrl());
- assertEquals("custom value is not correct", CUSTOM_AAIHEADERS, prop.getAAIHeaders());
- assertEquals("custom value is not correct", CUSTOM_ESBASEURL, prop.getEsBaseUrl());
-
- // delete autogenerated testfile
- ftest.delete();
-
- }
+ private static final boolean DEFAULT_CORSENABLED = false;
+ private static final boolean DEFAULT_AAIOFF = true;
+ private static final boolean DEFAULT_ESOFF = false;
+ private static final boolean DEFAULT_TRUSTINSECURE = false;
+ private static final String DEFAULT_AAIBASEURL = "off";
+ private static Map<String, String> DEFAULT_AAIHEADERS = new HashMap<String, String>();
+ private static final String DEFAULT_ESBASEURL = "http://sdnrdb:9200";
+
+ private static final boolean CUSTOM_CORSENABLED = true;
+ private static final boolean CUSTOM_AAIOFF = false;
+ private static final boolean CUSTOM_ESOFF = false;
+ private static final boolean CUSTOM_TRUSTINSECURE = true;
+ private static final String CUSTOM_AAIBASEURL = "https://aai.tld:2214";
+ private static Map<String, String> CUSTOM_AAIHEADERS = new HashMap<String, String>();
+ private static final String CUSTOM_ESBASEURL = "http://localhost:9200";
+
+ private static final String LR = "\n";
+ final String tmpFilename = "tmp2.cfg";
+
+ @Before
+ @After
+ public void init() {
+ File f = new File(tmpFilename);
+ if (f.exists()) {
+ f.delete();
+ }
+ }
+
+ @Test
+ public void test() {
+ DEFAULT_AAIHEADERS.put("X-FromAppId", "SDNR");
+ DEFAULT_AAIHEADERS.put("Authorization", "Basic QUFJOkFBSQ==");
+ CUSTOM_AAIHEADERS.put("X-FromAppId", "SDNC");
+ CUSTOM_AAIHEADERS.put("Authorization", "Basic 1234");
+ final String TESTPROPERTYFILECONTENT = "aai=" + CUSTOM_AAIBASEURL + LR + "aaiHeaders=[\"X-FromAppId:"
+ + CUSTOM_AAIHEADERS.get("X-FromAppId") + "\",\"Authorization:" + CUSTOM_AAIHEADERS.get("Authorization")
+ + "\"]" + LR + "database=" + CUSTOM_ESBASEURL + LR + "insecure=" + (CUSTOM_TRUSTINSECURE ? "1" : "0")
+ + LR + "cors=" + (CUSTOM_CORSENABLED ? "1" : "0");
+ File ftest = new File(tmpFilename);
+ MyProperties prop = null;
+ ftest = new File(tmpFilename);
+ try {
+ prop = MyProperties.Instantiate(ftest, true);
+ } catch (Exception e) {
+ fail("error instantiating properties");
+ }
+ assertNotNull("problem without exception instantiating properties", prop);
+
+ assertEquals("default config file was not created", true, ftest.exists());
+
+ // test default values
+ assertEquals("default value is not correct", DEFAULT_CORSENABLED, prop.corsEnabled());
+ assertEquals("default value is not correct", DEFAULT_AAIOFF, prop.isAAIOff());
+ assertEquals("default value is not correct", DEFAULT_ESOFF, prop.isEsOff());
+ assertEquals("default value is not correct", DEFAULT_TRUSTINSECURE, prop.trustInsecure());
+ assertEquals("default value is not correct", DEFAULT_AAIBASEURL, prop.getAAIBaseUrl());
+ assertEquals("default value is not correct", DEFAULT_AAIHEADERS, prop.getAAIHeaders());
+ assertEquals("default value is not correct", DEFAULT_ESBASEURL, prop.getEsBaseUrl());
+
+ try {
+ prop.load(new ByteArrayInputStream(TESTPROPERTYFILECONTENT.getBytes()));
+ } catch (Exception e) {
+ fail("error loading custom values into properties");
+ }
+
+ // test custom values
+ assertEquals("custom value is not correct", CUSTOM_CORSENABLED, prop.corsEnabled());
+ assertEquals("custom value is not correct", CUSTOM_AAIOFF, prop.isAAIOff());
+ assertEquals("custom value is not correct", CUSTOM_ESOFF, prop.isEsOff());
+ assertEquals("custom value is not correct", CUSTOM_TRUSTINSECURE, prop.trustInsecure());
+ assertEquals("custom value is not correct", CUSTOM_AAIBASEURL, prop.getAAIBaseUrl());
+ assertEquals("custom value is not correct", CUSTOM_AAIHEADERS, prop.getAAIHeaders());
+ assertEquals("custom value is not correct", CUSTOM_ESBASEURL, prop.getEsBaseUrl());
+
+ // delete autogenerated testfile
+ ftest.delete();
+
+ }
}
diff --git a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpAaiServlet.java b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpAaiServlet.java
index 5c28c8544..f6987b2fa 100644
--- a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpAaiServlet.java
+++ b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpAaiServlet.java
@@ -28,32 +28,36 @@ import javax.servlet.http.HttpServletResponse;
import org.onap.ccsdk.features.sdnr.wt.apigateway.AaiServlet;
-public class HelpAaiServlet extends AaiServlet implements IPublicServlet{
-
- public static final String RESPONSE_GET = "This is the response get";
- public static final String RESPONSE_POST = "This is the response post";
- public static final String RESPONSE_PUT = "This is the response put";
- public static final String RESPONSE_DELETE = "This is the response delete";
- public static final String RESPONSE_OPTIONS = "This is the response options";
-
- @Override
- public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- super.doGet(req, resp);
- }
- @Override
- public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- super.doPost(req, resp);
- }
- @Override
- public void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- super.doPut(req, resp);
- }
- @Override
- public void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- super.doOptions(req, resp);
- }
- @Override
- public void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- super.doDelete(req, resp);
- }
+public class HelpAaiServlet extends AaiServlet implements IPublicServlet {
+
+ public static final String RESPONSE_GET = "This is the response get";
+ public static final String RESPONSE_POST = "This is the response post";
+ public static final String RESPONSE_PUT = "This is the response put";
+ public static final String RESPONSE_DELETE = "This is the response delete";
+ public static final String RESPONSE_OPTIONS = "This is the response options";
+
+ @Override
+ public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ super.doGet(req, resp);
+ }
+
+ @Override
+ public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ super.doPost(req, resp);
+ }
+
+ @Override
+ public void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ super.doPut(req, resp);
+ }
+
+ @Override
+ public void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ super.doOptions(req, resp);
+ }
+
+ @Override
+ public void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ super.doDelete(req, resp);
+ }
}
diff --git a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpEsServlet.java b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpEsServlet.java
index a9cb06b10..901dd5810 100644
--- a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpEsServlet.java
+++ b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpEsServlet.java
@@ -30,30 +30,34 @@ import org.onap.ccsdk.features.sdnr.wt.apigateway.EsServlet;
public class HelpEsServlet extends EsServlet implements IPublicServlet {
- public static final String RESPONSE_GET = "This is the response get";
- public static final String RESPONSE_POST = "This is the response post";
- public static final String RESPONSE_PUT = "This is the response put";
- public static final String RESPONSE_DELETE = "This is the response delete";
- public static final String RESPONSE_OPTIONS = "This is the response options";
-
- @Override
- public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- super.doGet(req, resp);
- }
- @Override
- public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- super.doPost(req, resp);
- }
- @Override
- public void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- super.doPut(req, resp);
- }
- @Override
- public void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- super.doOptions(req, resp);
- }
- @Override
- public void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- super.doDelete(req, resp);
- }
+ public static final String RESPONSE_GET = "This is the response get";
+ public static final String RESPONSE_POST = "This is the response post";
+ public static final String RESPONSE_PUT = "This is the response put";
+ public static final String RESPONSE_DELETE = "This is the response delete";
+ public static final String RESPONSE_OPTIONS = "This is the response options";
+
+ @Override
+ public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ super.doGet(req, resp);
+ }
+
+ @Override
+ public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ super.doPost(req, resp);
+ }
+
+ @Override
+ public void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ super.doPut(req, resp);
+ }
+
+ @Override
+ public void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ super.doOptions(req, resp);
+ }
+
+ @Override
+ public void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ super.doDelete(req, resp);
+ }
}
diff --git a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpServlet.java b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpServlet.java
index ea7690c75..ddab06add 100644
--- a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpServlet.java
+++ b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpServlet.java
@@ -30,24 +30,28 @@ import org.onap.ccsdk.features.sdnr.wt.apigateway.EsServlet;
public class HelpServlet extends EsServlet {
- @Override
- public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- super.doGet(req, resp);
- }
- @Override
- public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- super.doPost(req, resp);
- }
- @Override
- public void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- super.doPut(req, resp);
- }
- @Override
- public void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- super.doOptions(req, resp);
- }
- @Override
- public void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- super.doDelete(req, resp);
- }
+ @Override
+ public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ super.doGet(req, resp);
+ }
+
+ @Override
+ public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ super.doPost(req, resp);
+ }
+
+ @Override
+ public void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ super.doPut(req, resp);
+ }
+
+ @Override
+ public void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ super.doOptions(req, resp);
+ }
+
+ @Override
+ public void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ super.doDelete(req, resp);
+ }
}
diff --git a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpServletBase.java b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpServletBase.java
index f89ca4dcf..0bc42c342 100644
--- a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpServletBase.java
+++ b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpServletBase.java
@@ -51,172 +51,173 @@ import com.sun.net.httpserver.HttpServer;
public class HelpServletBase {
- public static final String HTTPMETHOD_GET = "GET";
- public static final String HTTPMETHOD_POST = "POST";
- public static final String HTTPMETHOD_PUT = "PUT";
- public static final String HTTPMETHOD_DELETE = "DELETE";
- public static final String HTTPMETHOD_OPTIONS = "OPTIONS";
- private IPublicServlet servlet;
- private static HttpServer server;
- private static ExecutorService httpThreadPool;
-
- public final String HOST = "localhost";
- protected static int testPort;
- private final String baseUri;
- protected static final String LR = "\n";
-
- public HelpServletBase(String baseuri, int port) {
- this.baseUri=baseuri;
- testPort = port;
- }
-
- public void setServlet(IPublicServlet s)
- {
- this.servlet=s;
- }
-
- protected void testrequest(String method, String data, String expectedResponse, boolean exact) {
- this.testrequest("/mwtn/test",method, data, expectedResponse, exact, null);
- }
- protected void testrequest(String uri,String method, String data, String expectedResponse, boolean exact) {
- this.testrequest(uri,method, data, expectedResponse, exact, null);
- }
-
- protected void testrequest(String uri,String method, String data, String expectedResponse, boolean exact,
- Map<String, String> headersToCheck) {
-
- HttpServletRequest mockRequest = mock(HttpServletRequest.class);
- HttpServletResponse mockResponse = mock(HttpServletResponse.class);
-
- StringWriter out = new StringWriter();
- ServletOutputStream printOut = new ServletOutputStream() {
-
- @Override
- public void write(int arg0) throws IOException {
- out.write(arg0);
- }
- };
- ByteArrayInputStream bis = new ByteArrayInputStream(data.getBytes());
- ServletInputStream inputStream= new ServletInputStream() {
- @Override
- public int read() throws IOException {
- return bis.read();
- }
- };
- Vector<String> headers=new Vector<String>();
- headers.addElement("Accept");
- headers.add("User-Agent");
- Enumeration<String> headerNames = headers.elements();
- try {
- when(mockRequest.getRequestURI()).thenReturn(this.baseUri+uri);
- when(mockRequest.getHeaderNames()).thenReturn(headerNames);
- when(mockRequest.getHeader("Accept")).thenReturn("application/json");
- when(mockRequest.getHeader("User-Agent")).thenReturn("Gecko abc");
- when(mockRequest.getInputStream()).thenReturn(inputStream);
- when(mockResponse.getOutputStream()).thenReturn(printOut);
- System.out.println("do a " + method + " request");
- if (method == HTTPMETHOD_GET)
- this.servlet.doGet(mockRequest, mockResponse);
- else if (method == HTTPMETHOD_POST)
- this.servlet.doPost(mockRequest, mockResponse);
- else if (method == HTTPMETHOD_PUT)
- this.servlet.doPut(mockRequest, mockResponse);
- else if (method == HTTPMETHOD_DELETE)
- this.servlet.doDelete(mockRequest, mockResponse);
- else if (method == HTTPMETHOD_OPTIONS)
- this.servlet.doOptions(mockRequest, mockResponse);
- else
- fail("http request method " + method + " test not implemented");
- } catch (Exception e) {
- System.err.println(e.getMessage());
- }
-
- verify(mockResponse).setStatus(200);
- if (exact)
- assertEquals(expectedResponse, out.toString());
- else
- assertTrue("response not for method " + method + "correct", out.toString().contains(expectedResponse));
- // currently unable to check extra headers
- if (headersToCheck != null) {
-
- }
- }
- @Before
- private void init() throws IOException{
-
-
- initEsTestWebserver(testPort);
- }
- @After
- private void deinit() {
- stopTestWebserver();
- }
-
- public static void initEsTestWebserver(int port) throws IOException {
- initEsTestWebserver(port, "/mwtn/test");
- }
- public static void initEsTestWebserver(int port,String baseUri) throws IOException {
- server = HttpServer.create(new InetSocketAddress("127.0.0.1", port), 0);
- httpThreadPool = Executors.newFixedThreadPool(5);
- server.setExecutor(httpThreadPool);
- server.createContext(baseUri, new MyHandler());
- //server.createContext("/", new MyRootHandler());
- server.setExecutor(null); // creates a default executor
- server.start();
- System.out.println("http server started");
- }
-
- public static void stopTestWebserver() {
- if (server != null) {
- server.stop(0);
- httpThreadPool.shutdownNow();
- System.out.println("http server stopped" );
- }
- }
-
-
-
- public static class MyHandler implements HttpHandler {
- @Override
- public void handle(HttpExchange t) throws IOException {
- String method = t.getRequestMethod();
- System.out.println(String.format("req received: %s %s" ,method,t.getRequestURI()));
- OutputStream os = null;
- try {
- if (method.equals(HTTPMETHOD_GET)) {
- t.sendResponseHeaders(200, HelpEsServlet.RESPONSE_GET.length());
- os = t.getResponseBody();
- os.write(HelpEsServlet.RESPONSE_GET.getBytes());
- } else if (method.equals(HTTPMETHOD_POST)) {
- t.sendResponseHeaders(200, HelpEsServlet.RESPONSE_POST.length());
- os = t.getResponseBody();
- os.write(HelpEsServlet.RESPONSE_POST.getBytes());
- } else if (method.equals(HTTPMETHOD_PUT)) {
- t.sendResponseHeaders(200, HelpEsServlet.RESPONSE_PUT.length());
- os = t.getResponseBody();
- os.write(HelpEsServlet.RESPONSE_PUT.getBytes());
- } else if (method.equals(HTTPMETHOD_DELETE)) {
- t.sendResponseHeaders(200, HelpEsServlet.RESPONSE_DELETE.length());
- os = t.getResponseBody();
- os.write(HelpEsServlet.RESPONSE_DELETE.getBytes());
- } else if (method.equals(HTTPMETHOD_OPTIONS)) {
- t.sendResponseHeaders(200, HelpEsServlet.RESPONSE_OPTIONS.length());
- //os = t.getResponseBody();
- //os.write(RESPONSE_OPTIONS.getBytes());
- } else {
- t.sendResponseHeaders(404, 0);
- }
- System.out.println("req handled successful");
-
- } catch (Exception e) {
- System.out.println(e.getMessage());
- }
- finally {
- if (os != null)
- {
- os.close();
- }
- }
- }
- }
+ public static final String HTTPMETHOD_GET = "GET";
+ public static final String HTTPMETHOD_POST = "POST";
+ public static final String HTTPMETHOD_PUT = "PUT";
+ public static final String HTTPMETHOD_DELETE = "DELETE";
+ public static final String HTTPMETHOD_OPTIONS = "OPTIONS";
+ private IPublicServlet servlet;
+ private static HttpServer server;
+ private static ExecutorService httpThreadPool;
+
+ public final String HOST = "localhost";
+ protected static int testPort;
+ private final String baseUri;
+ protected static final String LR = "\n";
+
+ public HelpServletBase(String baseuri, int port) {
+ this.baseUri = baseuri;
+ testPort = port;
+ }
+
+ public void setServlet(IPublicServlet s) {
+ this.servlet = s;
+ }
+
+ protected void testrequest(String method, String data, String expectedResponse, boolean exact) {
+ this.testrequest("/mwtn/test", method, data, expectedResponse, exact, null);
+ }
+
+ protected void testrequest(String uri, String method, String data, String expectedResponse, boolean exact) {
+ this.testrequest(uri, method, data, expectedResponse, exact, null);
+ }
+
+ protected void testrequest(String uri, String method, String data, String expectedResponse, boolean exact,
+ Map<String, String> headersToCheck) {
+
+ HttpServletRequest mockRequest = mock(HttpServletRequest.class);
+ HttpServletResponse mockResponse = mock(HttpServletResponse.class);
+
+ StringWriter out = new StringWriter();
+ ServletOutputStream printOut = new ServletOutputStream() {
+
+ @Override
+ public void write(int arg0) throws IOException {
+ out.write(arg0);
+ }
+ };
+ ByteArrayInputStream bis = new ByteArrayInputStream(data.getBytes());
+ ServletInputStream inputStream = new ServletInputStream() {
+ @Override
+ public int read() throws IOException {
+ return bis.read();
+ }
+ };
+ Vector<String> headers = new Vector<String>();
+ headers.addElement("Accept");
+ headers.add("User-Agent");
+ Enumeration<String> headerNames = headers.elements();
+ try {
+ when(mockRequest.getRequestURI()).thenReturn(this.baseUri + uri);
+ when(mockRequest.getHeaderNames()).thenReturn(headerNames);
+ when(mockRequest.getHeader("Accept")).thenReturn("application/json");
+ when(mockRequest.getHeader("User-Agent")).thenReturn("Gecko abc");
+ when(mockRequest.getInputStream()).thenReturn(inputStream);
+ when(mockResponse.getOutputStream()).thenReturn(printOut);
+ System.out.println("do a " + method + " request");
+ if (method == HTTPMETHOD_GET)
+ this.servlet.doGet(mockRequest, mockResponse);
+ else if (method == HTTPMETHOD_POST)
+ this.servlet.doPost(mockRequest, mockResponse);
+ else if (method == HTTPMETHOD_PUT)
+ this.servlet.doPut(mockRequest, mockResponse);
+ else if (method == HTTPMETHOD_DELETE)
+ this.servlet.doDelete(mockRequest, mockResponse);
+ else if (method == HTTPMETHOD_OPTIONS)
+ this.servlet.doOptions(mockRequest, mockResponse);
+ else
+ fail("http request method " + method + " test not implemented");
+ } catch (Exception e) {
+ System.err.println(e.getMessage());
+ }
+
+ verify(mockResponse).setStatus(200);
+ if (exact)
+ assertEquals(expectedResponse, out.toString());
+ else
+ assertTrue("response not for method " + method + "correct", out.toString().contains(expectedResponse));
+ // currently unable to check extra headers
+ if (headersToCheck != null) {
+
+ }
+ }
+
+ @Before
+ private void init() throws IOException {
+
+
+ initEsTestWebserver(testPort);
+ }
+
+ @After
+ private void deinit() {
+ stopTestWebserver();
+ }
+
+ public static void initEsTestWebserver(int port) throws IOException {
+ initEsTestWebserver(port, "/mwtn/test");
+ }
+
+ public static void initEsTestWebserver(int port, String baseUri) throws IOException {
+ server = HttpServer.create(new InetSocketAddress("127.0.0.1", port), 0);
+ httpThreadPool = Executors.newFixedThreadPool(5);
+ server.setExecutor(httpThreadPool);
+ server.createContext(baseUri, new MyHandler());
+ //server.createContext("/", new MyRootHandler());
+ server.setExecutor(null); // creates a default executor
+ server.start();
+ System.out.println("http server started");
+ }
+
+ public static void stopTestWebserver() {
+ if (server != null) {
+ server.stop(0);
+ httpThreadPool.shutdownNow();
+ System.out.println("http server stopped");
+ }
+ }
+
+
+
+ public static class MyHandler implements HttpHandler {
+ @Override
+ public void handle(HttpExchange t) throws IOException {
+ String method = t.getRequestMethod();
+ System.out.println(String.format("req received: %s %s", method, t.getRequestURI()));
+ OutputStream os = null;
+ try {
+ if (method.equals(HTTPMETHOD_GET)) {
+ t.sendResponseHeaders(200, HelpEsServlet.RESPONSE_GET.length());
+ os = t.getResponseBody();
+ os.write(HelpEsServlet.RESPONSE_GET.getBytes());
+ } else if (method.equals(HTTPMETHOD_POST)) {
+ t.sendResponseHeaders(200, HelpEsServlet.RESPONSE_POST.length());
+ os = t.getResponseBody();
+ os.write(HelpEsServlet.RESPONSE_POST.getBytes());
+ } else if (method.equals(HTTPMETHOD_PUT)) {
+ t.sendResponseHeaders(200, HelpEsServlet.RESPONSE_PUT.length());
+ os = t.getResponseBody();
+ os.write(HelpEsServlet.RESPONSE_PUT.getBytes());
+ } else if (method.equals(HTTPMETHOD_DELETE)) {
+ t.sendResponseHeaders(200, HelpEsServlet.RESPONSE_DELETE.length());
+ os = t.getResponseBody();
+ os.write(HelpEsServlet.RESPONSE_DELETE.getBytes());
+ } else if (method.equals(HTTPMETHOD_OPTIONS)) {
+ t.sendResponseHeaders(200, HelpEsServlet.RESPONSE_OPTIONS.length());
+ //os = t.getResponseBody();
+ //os.write(RESPONSE_OPTIONS.getBytes());
+ } else {
+ t.sendResponseHeaders(404, 0);
+ }
+ System.out.println("req handled successful");
+
+ } catch (Exception e) {
+ System.out.println(e.getMessage());
+ } finally {
+ if (os != null) {
+ os.close();
+ }
+ }
+ }
+ }
}
diff --git a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/IPublicServlet.java b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/IPublicServlet.java
index 77267e793..86a9467ec 100644
--- a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/IPublicServlet.java
+++ b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/IPublicServlet.java
@@ -30,9 +30,13 @@ import javax.servlet.http.HttpServletResponse;
public interface IPublicServlet {
- public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException;
- public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException;
- public void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException;
- public void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException ;
- public void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException ;
+ public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException;
+
+ public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException;
+
+ public void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException;
+
+ public void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException;
+
+ public void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException;
}