From f7da60fabf647665d61f142a0d6ba9a9fc940106 Mon Sep 17 00:00:00 2001 From: waynedunican Date: Fri, 19 Jun 2020 15:30:59 +0100 Subject: Clean up of Pair classes - models Removed Pair class from policy-models and replaced with Aoache Common Pair class Issue-ID: POLICY-2202 Change-Id: I786467ac02ecb2d433dba94deba45785be3dcf23 Signed-off-by: waynedunican --- .../test/java/org/onap/policy/rest/PairTest.java | 43 --- .../test/java/org/onap/policy/rest/RestTest.java | 290 +++++++++++---------- 2 files changed, 152 insertions(+), 181 deletions(-) delete mode 100644 models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/PairTest.java (limited to 'models-interactions/model-impl/rest/src/test/java') diff --git a/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/PairTest.java b/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/PairTest.java deleted file mode 100644 index 2db9ebca0..000000000 --- a/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/PairTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * rest - * ================================================================================ - * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved - * Modifications Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * 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 org.onap.policy.rest; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; -import org.onap.policy.rest.RestManager.Pair; - -public class PairTest { - - @Test - public void testPair() { - RestManager mgr = new RestManager(); - - Pair pii = mgr.new Pair<>(1, 2); - assertEquals((Integer) 1, pii.first); - assertEquals((Integer) 2, pii.second); - - Pair pis = mgr.new Pair<>(1, "test"); - assertEquals((Integer) 1, pis.first); - assertEquals("test", pis.second); - } -} diff --git a/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/RestTest.java b/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/RestTest.java index 8c241c83e..52c0912e3 100644 --- a/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/RestTest.java +++ b/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/RestTest.java @@ -3,7 +3,7 @@ * rest * ================================================================================ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,13 +41,13 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; +import org.apache.commons.lang3.tuple.Pair; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.onap.policy.common.endpoints.http.server.HttpServletServer; import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance; import org.onap.policy.common.utils.network.NetworkUtil; -import org.onap.policy.rest.RestManager.Pair; @Path("RestTest") public class RestTest { @@ -144,58 +144,60 @@ public class RestTest { RestManager mgr = new RestManager(); Pair result = mgr.get(getUri, null, null, null); - assertEquals((Integer) 200, result.first); - assertTrue(result.second != null); - assertTrue(result.second.length() > 0); - assertEquals("GOT: " + EXPECT_STRING, result.second); + + assertEquals((Integer) 200, result.getLeft()); + assertTrue(result.getRight() != null); + assertTrue(result.getRight().length() > 0); + assertEquals("GOT: " + EXPECT_STRING, result.getRight()); result = mgr.delete(deleteUri, null, null, null, null, null); - assertEquals((Integer) 200, result.first); - assertTrue(result.second != null); - assertTrue(result.second.length() > 0); - assertEquals("DELETE: " + EXPECT_STRING, result.second); + assertEquals((Integer) 200, result.getLeft()); + assertTrue(result.getRight() != null); + assertTrue(result.getRight().length() > 0); + assertEquals("DELETE: " + EXPECT_STRING, result.getRight()); result = mgr.delete(deleteUri, null, null, null); - assertEquals((Integer) 200, result.first); - assertTrue(result.second != null); - assertTrue(result.second.length() > 0); - assertEquals("DELETE: " + EXPECT_STRING, result.second); + assertEquals((Integer) 200, result.getLeft()); + assertTrue(result.getRight() != null); + assertTrue(result.getRight().length() > 0); + assertEquals("DELETE: " + EXPECT_STRING, result.getRight()); result = mgr.put(putUri, null, null, null, MediaType.TEXT_PLAIN, PAYLOAD); - assertEquals((Integer) 200, result.first); - assertTrue(result.second != null); - assertTrue(result.second.length() > 0); - assertEquals("PUT: " + PAYLOAD + EXPECT_STRING, result.second); + assertEquals((Integer) 200, result.getLeft()); + assertTrue(result.getRight() != null); + assertTrue(result.getRight().length() > 0); + assertEquals("PUT: " + PAYLOAD + EXPECT_STRING, result.getRight()); result = mgr.put(putUriBlank, null, null, null, MediaType.TEXT_PLAIN, PAYLOAD); - assertEquals((Integer) 200, result.first); - assertTrue(result.second != null); - assertTrue(result.second.length() > 0); - assertEquals("PUT: " + PAYLOAD + RETURN_STRING, result.second); + assertEquals((Integer) 200, result.getLeft()); + assertTrue(result.getRight() != null); + assertTrue(result.getRight().length() > 0); + assertEquals("PUT: " + PAYLOAD + RETURN_STRING, result.getRight()); result = mgr.post(postUri, null, null, null, MediaType.TEXT_PLAIN, PAYLOAD); - assertEquals((Integer) 200, result.first); - assertTrue(result.second != null); - assertTrue(result.second.length() > 0); - assertEquals("POST: " + PAYLOAD + EXPECT_STRING, result.second); + assertEquals((Integer) 200, result.getLeft()); + assertTrue(result.getRight() != null); + assertTrue(result.getRight().length() > 0); + assertEquals("POST: " + PAYLOAD + EXPECT_STRING, result.getRight()); result = mgr.post(postUriBlank, null, null, null, MediaType.TEXT_PLAIN, PAYLOAD); - assertEquals((Integer) 200, result.first); - assertTrue(result.second != null); - assertTrue(result.second.length() > 0); - assertEquals("POST: " + PAYLOAD + RETURN_STRING, result.second); + assertEquals((Integer) 200, result.getLeft()); + assertTrue(result.getRight() != null); + assertTrue(result.getRight().length() > 0); + assertEquals("POST: " + PAYLOAD + RETURN_STRING, result.getRight()); result = mgr.patch(patchUri, null, null, null, PAYLOAD); - assertEquals((Integer) 200, result.first); - assertTrue(result.second != null); - assertTrue(result.second.length() > 0); - assertEquals("PATCH: " + PAYLOAD + EXPECT_STRING, result.second); + assertEquals((Integer) 200, result.getLeft()); + assertTrue(result.getRight() != null); + assertTrue(result.getRight().length() > 0); + assertEquals("PATCH: " + PAYLOAD + EXPECT_STRING, result.getRight()); result = mgr.patch(patchUriBlank, null, null, null, PAYLOAD); - assertEquals((Integer) 200, result.first); - assertTrue(result.second != null); - assertTrue(result.second.length() > 0); - assertEquals("PATCH: " + PAYLOAD + RETURN_STRING, result.second); + assertEquals((Integer) 200, result.getLeft()); + assertTrue(result.getRight() != null); + assertTrue(result.getRight().length() > 0); + assertEquals("PATCH: " + PAYLOAD + RETURN_STRING, result.getRight()); + } @Test @@ -203,52 +205,54 @@ public class RestTest { RestManager mgr = new RestManager(); Pair result = mgr.get(getUri, "", null, null); - assertEquals((Integer) 200, result.first); - assertTrue(result.second != null); - assertTrue(result.second.length() > 0); - assertEquals("GOT: " + EXPECT_STRING, result.second); + + assertEquals((Integer) 200, result.getLeft()); + assertTrue(result.getRight() != null); + assertTrue(result.getRight().length() > 0); + assertEquals("GOT: " + EXPECT_STRING, result.getRight()); result = mgr.delete(deleteUri, "", null, null, null, null); - assertEquals((Integer) 200, result.first); - assertTrue(result.second != null); - assertTrue(result.second.length() > 0); - assertEquals("DELETE: " + EXPECT_STRING, result.second); + assertEquals((Integer) 200, result.getLeft()); + assertTrue(result.getRight() != null); + assertTrue(result.getRight().length() > 0); + assertEquals("DELETE: " + EXPECT_STRING, result.getRight()); result = mgr.put(putUri, "", null, null, MediaType.TEXT_PLAIN, PAYLOAD); - assertEquals((Integer) 200, result.first); - assertTrue(result.second != null); - assertTrue(result.second.length() > 0); - assertEquals("PUT: " + PAYLOAD + EXPECT_STRING, result.second); + assertEquals((Integer) 200, result.getLeft()); + assertTrue(result.getRight() != null); + assertTrue(result.getRight().length() > 0); + assertEquals("PUT: " + PAYLOAD + EXPECT_STRING, result.getRight()); result = mgr.put(putUriBlank, "", null, null, MediaType.TEXT_PLAIN, PAYLOAD); - assertEquals((Integer) 200, result.first); - assertTrue(result.second != null); - assertTrue(result.second.length() > 0); - assertEquals("PUT: " + PAYLOAD + RETURN_STRING, result.second); + assertEquals((Integer) 200, result.getLeft()); + assertTrue(result.getRight() != null); + assertTrue(result.getRight().length() > 0); + assertEquals("PUT: " + PAYLOAD + RETURN_STRING, result.getRight()); result = mgr.post(postUri, "", null, null, MediaType.TEXT_PLAIN, PAYLOAD); - assertEquals((Integer) 200, result.first); - assertTrue(result.second != null); - assertTrue(result.second.length() > 0); - assertEquals("POST: " + PAYLOAD + EXPECT_STRING, result.second); + assertEquals((Integer) 200, result.getLeft()); + assertTrue(result.getRight() != null); + assertTrue(result.getRight().length() > 0); + assertEquals("POST: " + PAYLOAD + EXPECT_STRING, result.getRight()); result = mgr.post(postUriBlank, "", null, null, MediaType.TEXT_PLAIN, PAYLOAD); - assertEquals((Integer) 200, result.first); - assertTrue(result.second != null); - assertTrue(result.second.length() > 0); - assertEquals("POST: " + PAYLOAD + RETURN_STRING, result.second); + assertEquals((Integer) 200, result.getLeft()); + assertTrue(result.getRight() != null); + assertTrue(result.getRight().length() > 0); + assertEquals("POST: " + PAYLOAD + RETURN_STRING, result.getRight()); result = mgr.patch(patchUri, "", null, null, PAYLOAD); - assertEquals((Integer) 200, result.first); - assertTrue(result.second != null); - assertTrue(result.second.length() > 0); - assertEquals("PATCH: " + PAYLOAD + EXPECT_STRING, result.second); + assertEquals((Integer) 200, result.getLeft()); + assertTrue(result.getRight() != null); + assertTrue(result.getRight().length() > 0); + assertEquals("PATCH: " + PAYLOAD + EXPECT_STRING, result.getRight()); result = mgr.patch(patchUriBlank, "", null, null, PAYLOAD); - assertEquals((Integer) 200, result.first); - assertTrue(result.second != null); - assertTrue(result.second.length() > 0); - assertEquals("PATCH: " + PAYLOAD + RETURN_STRING, result.second); + assertEquals((Integer) 200, result.getLeft()); + assertTrue(result.getRight() != null); + assertTrue(result.getRight().length() > 0); + assertEquals("PATCH: " + PAYLOAD + RETURN_STRING, result.getRight()); + } @Test @@ -256,52 +260,54 @@ public class RestTest { RestManager mgr = new RestManager(); Pair result = mgr.get(getUri, "user", null, null); - assertEquals((Integer) 200, result.first); - assertTrue(result.second != null); - assertTrue(result.second.length() > 0); - assertEquals("GOT: " + EXPECT_STRING, result.second); + + assertEquals((Integer) 200, result.getLeft()); + assertTrue(result.getRight() != null); + assertTrue(result.getRight().length() > 0); + assertEquals("GOT: " + EXPECT_STRING, result.getRight()); result = mgr.delete(deleteUri, "user", null, null, null, null); - assertEquals((Integer) 200, result.first); - assertTrue(result.second != null); - assertTrue(result.second.length() > 0); - assertEquals("DELETE: " + EXPECT_STRING, result.second); + assertEquals((Integer) 200, result.getLeft()); + assertTrue(result.getRight() != null); + assertTrue(result.getRight().length() > 0); + assertEquals("DELETE: " + EXPECT_STRING, result.getRight()); result = mgr.put(putUri, "user", null, null, MediaType.TEXT_PLAIN, PAYLOAD); - assertEquals((Integer) 200, result.first); - assertTrue(result.second != null); - assertTrue(result.second.length() > 0); - assertEquals("PUT: " + PAYLOAD + EXPECT_STRING, result.second); + assertEquals((Integer) 200, result.getLeft()); + assertTrue(result.getRight() != null); + assertTrue(result.getRight().length() > 0); + assertEquals("PUT: " + PAYLOAD + EXPECT_STRING, result.getRight()); result = mgr.put(putUriBlank, "user", null, null, MediaType.TEXT_PLAIN, PAYLOAD); - assertEquals((Integer) 200, result.first); - assertTrue(result.second != null); - assertTrue(result.second.length() > 0); - assertEquals("PUT: " + PAYLOAD + RETURN_STRING, result.second); + assertEquals((Integer) 200, result.getLeft()); + assertTrue(result.getRight() != null); + assertTrue(result.getRight().length() > 0); + assertEquals("PUT: " + PAYLOAD + RETURN_STRING, result.getRight()); result = mgr.post(postUri, "user", null, null, MediaType.TEXT_PLAIN, PAYLOAD); - assertEquals((Integer) 200, result.first); - assertTrue(result.second != null); - assertTrue(result.second.length() > 0); - assertEquals("POST: " + PAYLOAD + EXPECT_STRING, result.second); + assertEquals((Integer) 200, result.getLeft()); + assertTrue(result.getRight() != null); + assertTrue(result.getRight().length() > 0); + assertEquals("POST: " + PAYLOAD + EXPECT_STRING, result.getRight()); result = mgr.post(postUriBlank, "user", null, null, MediaType.TEXT_PLAIN, PAYLOAD); - assertEquals((Integer) 200, result.first); - assertTrue(result.second != null); - assertTrue(result.second.length() > 0); - assertEquals("POST: " + PAYLOAD + RETURN_STRING, result.second); + assertEquals((Integer) 200, result.getLeft()); + assertTrue(result.getRight() != null); + assertTrue(result.getRight().length() > 0); + assertEquals("POST: " + PAYLOAD + RETURN_STRING, result.getRight()); result = mgr.patch(patchUri, "user", null, null, PAYLOAD); - assertEquals((Integer) 200, result.first); - assertTrue(result.second != null); - assertTrue(result.second.length() > 0); - assertEquals("PATCH: " + PAYLOAD + EXPECT_STRING, result.second); + assertEquals((Integer) 200, result.getLeft()); + assertTrue(result.getRight() != null); + assertTrue(result.getRight().length() > 0); + assertEquals("PATCH: " + PAYLOAD + EXPECT_STRING, result.getRight()); result = mgr.patch(patchUriBlank, "user", null, null, PAYLOAD); - assertEquals((Integer) 200, result.first); - assertTrue(result.second != null); - assertTrue(result.second.length() > 0); - assertEquals("PATCH: " + PAYLOAD + RETURN_STRING, result.second); + assertEquals((Integer) 200, result.getLeft()); + assertTrue(result.getRight() != null); + assertTrue(result.getRight().length() > 0); + assertEquals("PATCH: " + PAYLOAD + RETURN_STRING, result.getRight()); + } @Test @@ -309,19 +315,21 @@ public class RestTest { RestManager mgr = new RestManager(); Pair result = mgr.get(baseUri + "RestTest/GetHello/", null, null, null); - assertEquals((Integer) 404, result.first); + + assertEquals((Integer) 404, result.getLeft()); result = mgr.delete(baseUri + "RestTest/DeleteHello/", null, null, null, null, null); - assertEquals((Integer) 404, result.first); + assertEquals((Integer) 404, result.getLeft()); result = mgr.put(baseUri + "RestTest/PutHello/", null, null, null, MediaType.TEXT_PLAIN, PAYLOAD); - assertEquals((Integer) 404, result.first); + assertEquals((Integer) 404, result.getLeft()); result = mgr.post(baseUri + "RestTest/PostHello/", null, null, null, MediaType.TEXT_PLAIN, PAYLOAD); - assertEquals((Integer) 404, result.first); + assertEquals((Integer) 404, result.getLeft()); result = mgr.patch(baseUri + "RestTest/PatchHello/", null, null, null, PAYLOAD); - assertEquals((Integer) 404, result.first); + assertEquals((Integer) 404, result.getLeft()); + } @Test @@ -329,36 +337,38 @@ public class RestTest { RestManager mgr = new RestManager(); Pair result = mgr.get(baseUri + "RestTest/GetHello/" + NAME_PARAM, null, null, null); - assertEquals((Integer) 200, result.first); - assertTrue(result.second != null); - assertTrue(result.second.length() > 0); - assertEquals("GOT: " + RETURN_STRING + NAME_PARAM + " aged 90", result.second); + + assertEquals((Integer) 200, result.getLeft()); + assertTrue(result.getRight() != null); + assertTrue(result.getRight().length() > 0); + assertEquals("GOT: " + RETURN_STRING + NAME_PARAM + " aged 90", result.getRight()); result = mgr.delete(baseUri + "RestTest/DeleteHello/" + NAME_PARAM, null, null, null, null, null); - assertEquals((Integer) 200, result.first); - assertTrue(result.second != null); - assertTrue(result.second.length() > 0); - assertEquals("DELETE: " + RETURN_STRING + NAME_PARAM + " aged 90", result.second); + assertEquals((Integer) 200, result.getLeft()); + assertTrue(result.getRight() != null); + assertTrue(result.getRight().length() > 0); + assertEquals("DELETE: " + RETURN_STRING + NAME_PARAM + " aged 90", result.getRight()); result = mgr.put(baseUri + "RestTest/PutHello/" + NAME_PARAM, null, null, null, MediaType.TEXT_PLAIN, PAYLOAD); - assertEquals((Integer) 200, result.first); - assertTrue(result.second != null); - assertTrue(result.second.length() > 0); - assertEquals("PUT: " + PAYLOAD + RETURN_STRING + NAME_PARAM + " aged 90", result.second); + assertEquals((Integer) 200, result.getLeft()); + assertTrue(result.getRight() != null); + assertTrue(result.getRight().length() > 0); + assertEquals("PUT: " + PAYLOAD + RETURN_STRING + NAME_PARAM + " aged 90", result.getRight()); result = mgr.post(baseUri + "RestTest/PostHello/" + NAME_PARAM, null, null, null, MediaType.TEXT_PLAIN, PAYLOAD); - assertEquals((Integer) 200, result.first); - assertTrue(result.second != null); - assertTrue(result.second.length() > 0); - assertEquals("POST: " + PAYLOAD + RETURN_STRING + NAME_PARAM + " aged 90", result.second); + assertEquals((Integer) 200, result.getLeft()); + assertTrue(result.getRight() != null); + assertTrue(result.getRight().length() > 0); + assertEquals("POST: " + PAYLOAD + RETURN_STRING + NAME_PARAM + " aged 90", result.getRight()); result = mgr.patch(baseUri + "RestTest/PatchHello/" + NAME_PARAM, null, null, null, PAYLOAD); - assertEquals((Integer) 200, result.first); - assertTrue(result.second != null); - assertTrue(result.second.length() > 0); - assertEquals("PATCH: " + PAYLOAD + RETURN_STRING + NAME_PARAM + " aged 90", result.second); + assertEquals((Integer) 200, result.getLeft()); + assertTrue(result.getRight() != null); + assertTrue(result.getRight().length() > 0); + assertEquals("PATCH: " + PAYLOAD + RETURN_STRING + NAME_PARAM + " aged 90", result.getRight()); + } @Test @@ -366,19 +376,21 @@ public class RestTest { RestManager mgr = new RestManager(); Pair result = mgr.get(baseUri + "NonExistant/URL/", null, null, null); - assertEquals((Integer) 404, result.first); + + assertEquals((Integer) 404, result.getLeft()); result = mgr.delete(baseUri + "NonExistant/URL/", null, null, null, null, null); - assertEquals((Integer) 404, result.first); + assertEquals((Integer) 404, result.getLeft()); result = mgr.put(baseUri + "NonExistant/URL/", null, null, null, MediaType.TEXT_PLAIN, PAYLOAD); - assertEquals((Integer) 404, result.first); + assertEquals((Integer) 404, result.getLeft()); result = mgr.post(baseUri + "NonExistant/URL/", null, null, null, MediaType.TEXT_PLAIN, PAYLOAD); - assertEquals((Integer) 404, result.first); + assertEquals((Integer) 404, result.getLeft()); result = mgr.patch(baseUri + "NonExistant/URL/", null, null, null, PAYLOAD); - assertEquals((Integer) 404, result.first); + assertEquals((Integer) 404, result.getLeft()); + } @Test @@ -386,22 +398,24 @@ public class RestTest { RestManager mgr = new RestManager(); Pair result = mgr.get(deleteUri, null, null, null); - assertEquals((Integer) 405, result.first); + + assertEquals((Integer) 405, result.getLeft()); result = mgr.delete(getUri, null, null, null, null, null); - assertEquals((Integer) 405, result.first); + assertEquals((Integer) 405, result.getLeft()); result = mgr.delete(getUri, null, null, null); - assertEquals((Integer) 405, result.first); + assertEquals((Integer) 405, result.getLeft()); result = mgr.put(getUri, null, null, null, MediaType.TEXT_PLAIN, PAYLOAD); - assertEquals((Integer) 405, result.first); + assertEquals((Integer) 405, result.getLeft()); result = mgr.post(getUri, null, null, null, MediaType.TEXT_PLAIN, PAYLOAD); - assertEquals((Integer) 405, result.first); + assertEquals((Integer) 405, result.getLeft()); result = mgr.patch(getUri, null, null, null, PAYLOAD); - assertEquals((Integer) 405, result.first); + assertEquals((Integer) 405, result.getLeft()); + } @GET -- cgit 1.2.3-korg