aboutsummaryrefslogtreecommitdiffstats
path: root/models-interactions/model-impl/rest/src
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2021-02-10 16:17:10 -0500
committerJim Hahn <jrh3@att.com>2021-02-10 17:17:34 -0500
commitb7097d21c25a48c9d209548ac8afdc09b1679457 (patch)
treeee7a911622c333818a9ac30f2cae68aee7eb6601 /models-interactions/model-impl/rest/src
parentf04d89c55ab4dfa94dfed1cc9b65471d1d3140c5 (diff)
More sonars in models
Addressed the following: - make constructors protected - check exception type - too many assertions - remove annotation lists - use "<>" - reduce cognitive complexity - extract constant - multiple method calls in one assert - don't use eq() in verify() - indentation Issue-ID: POLICY-2905 Change-Id: I25bb3951f781250e9cdfe8f5f3b80cb63e129184 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-impl/rest/src')
-rw-r--r--models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/RestTest.java159
1 files changed, 36 insertions, 123 deletions
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 21df853f4..e5a887429 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
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* rest
* ================================================================================
- * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -145,60 +145,39 @@ public class RestTest {
RestManager mgr = new RestManager();
Pair<Integer, String> result = mgr.get(getUri, null, null, null);
-
- assertEquals((Integer) 200, result.getLeft());
- assertNotNull(result.getRight());
- assertTrue(result.getRight().length() > 0);
- assertEquals("GOT: " + EXPECT_STRING, result.getRight());
+ checkResult(result, "GOT: " + EXPECT_STRING);
result = mgr.delete(deleteUri, null, null, null, null, null);
- assertEquals((Integer) 200, result.getLeft());
- assertNotNull(result.getRight());
- assertTrue(result.getRight().length() > 0);
- assertEquals("DELETE: " + EXPECT_STRING, result.getRight());
+ checkResult(result, "DELETE: " + EXPECT_STRING);
result = mgr.delete(deleteUri, null, null, null);
- assertEquals((Integer) 200, result.getLeft());
- assertNotNull(result.getRight());
- assertTrue(result.getRight().length() > 0);
- assertEquals("DELETE: " + EXPECT_STRING, result.getRight());
+ checkResult(result, "DELETE: " + EXPECT_STRING);
result = mgr.put(putUri, null, null, null, MediaType.TEXT_PLAIN, PAYLOAD);
- assertEquals((Integer) 200, result.getLeft());
- assertNotNull(result.getRight());
- assertTrue(result.getRight().length() > 0);
- assertEquals("PUT: " + PAYLOAD + EXPECT_STRING, result.getRight());
+ checkResult(result, "PUT: " + PAYLOAD + EXPECT_STRING);
result = mgr.put(putUriBlank, null, null, null, MediaType.TEXT_PLAIN, PAYLOAD);
- assertEquals((Integer) 200, result.getLeft());
- assertNotNull(result.getRight());
- assertTrue(result.getRight().length() > 0);
- assertEquals("PUT: " + PAYLOAD + RETURN_STRING, result.getRight());
+ checkResult(result, "PUT: " + PAYLOAD + RETURN_STRING);
result = mgr.post(postUri, null, null, null, MediaType.TEXT_PLAIN, PAYLOAD);
- assertEquals((Integer) 200, result.getLeft());
- assertNotNull(result.getRight());
- assertTrue(result.getRight().length() > 0);
- assertEquals("POST: " + PAYLOAD + EXPECT_STRING, result.getRight());
+ checkResult(result, "POST: " + PAYLOAD + EXPECT_STRING);
result = mgr.post(postUriBlank, null, null, null, MediaType.TEXT_PLAIN, PAYLOAD);
- assertEquals((Integer) 200, result.getLeft());
- assertNotNull(result.getRight());
- assertTrue(result.getRight().length() > 0);
- assertEquals("POST: " + PAYLOAD + RETURN_STRING, result.getRight());
+ checkResult(result, "POST: " + PAYLOAD + RETURN_STRING);
result = mgr.patch(patchUri, null, null, null, PAYLOAD);
- assertEquals((Integer) 200, result.getLeft());
- assertNotNull(result.getRight());
- assertTrue(result.getRight().length() > 0);
- assertEquals("PATCH: " + PAYLOAD + EXPECT_STRING, result.getRight());
+ checkResult(result, "PATCH: " + PAYLOAD + EXPECT_STRING);
result = mgr.patch(patchUriBlank, null, null, null, PAYLOAD);
+ checkResult(result, "PATCH: " + PAYLOAD + RETURN_STRING);
+
+ }
+
+ private void checkResult(Pair<Integer, String> result, String expectedText) {
assertEquals((Integer) 200, result.getLeft());
assertNotNull(result.getRight());
assertTrue(result.getRight().length() > 0);
- assertEquals("PATCH: " + PAYLOAD + RETURN_STRING, result.getRight());
-
+ assertEquals(expectedText, result.getRight());
}
@Test
@@ -206,53 +185,28 @@ public class RestTest {
RestManager mgr = new RestManager();
Pair<Integer, String> result = mgr.get(getUri, "", null, null);
-
- assertEquals((Integer) 200, result.getLeft());
- assertNotNull(result.getRight());
- assertTrue(result.getRight().length() > 0);
- assertEquals("GOT: " + EXPECT_STRING, result.getRight());
+ checkResult(result, "GOT: " + EXPECT_STRING);
result = mgr.delete(deleteUri, "", null, null, null, null);
- assertEquals((Integer) 200, result.getLeft());
- assertNotNull(result.getRight());
- assertTrue(result.getRight().length() > 0);
- assertEquals("DELETE: " + EXPECT_STRING, result.getRight());
+ checkResult(result, "DELETE: " + EXPECT_STRING);
result = mgr.put(putUri, "", null, null, MediaType.TEXT_PLAIN, PAYLOAD);
- assertEquals((Integer) 200, result.getLeft());
- assertNotNull(result.getRight());
- assertTrue(result.getRight().length() > 0);
- assertEquals("PUT: " + PAYLOAD + EXPECT_STRING, result.getRight());
+ checkResult(result, "PUT: " + PAYLOAD + EXPECT_STRING);
result = mgr.put(putUriBlank, "", null, null, MediaType.TEXT_PLAIN, PAYLOAD);
- assertEquals((Integer) 200, result.getLeft());
- assertNotNull(result.getRight());
- assertTrue(result.getRight().length() > 0);
- assertEquals("PUT: " + PAYLOAD + RETURN_STRING, result.getRight());
+ checkResult(result, "PUT: " + PAYLOAD + RETURN_STRING);
result = mgr.post(postUri, "", null, null, MediaType.TEXT_PLAIN, PAYLOAD);
- assertEquals((Integer) 200, result.getLeft());
- assertNotNull(result.getRight());
- assertTrue(result.getRight().length() > 0);
- assertEquals("POST: " + PAYLOAD + EXPECT_STRING, result.getRight());
+ checkResult(result, "POST: " + PAYLOAD + EXPECT_STRING);
result = mgr.post(postUriBlank, "", null, null, MediaType.TEXT_PLAIN, PAYLOAD);
- assertEquals((Integer) 200, result.getLeft());
- assertNotNull(result.getRight());
- assertTrue(result.getRight().length() > 0);
- assertEquals("POST: " + PAYLOAD + RETURN_STRING, result.getRight());
+ checkResult(result, "POST: " + PAYLOAD + RETURN_STRING);
result = mgr.patch(patchUri, "", null, null, PAYLOAD);
- assertEquals((Integer) 200, result.getLeft());
- assertNotNull(result.getRight());
- assertTrue(result.getRight().length() > 0);
- assertEquals("PATCH: " + PAYLOAD + EXPECT_STRING, result.getRight());
+ checkResult(result, "PATCH: " + PAYLOAD + EXPECT_STRING);
result = mgr.patch(patchUriBlank, "", null, null, PAYLOAD);
- assertEquals((Integer) 200, result.getLeft());
- assertNotNull(result.getRight());
- assertTrue(result.getRight().length() > 0);
- assertEquals("PATCH: " + PAYLOAD + RETURN_STRING, result.getRight());
+ checkResult(result, "PATCH: " + PAYLOAD + RETURN_STRING);
}
@@ -261,53 +215,28 @@ public class RestTest {
RestManager mgr = new RestManager();
Pair<Integer, String> result = mgr.get(getUri, "user", null, null);
-
- assertEquals((Integer) 200, result.getLeft());
- assertNotNull(result.getRight());
- assertTrue(result.getRight().length() > 0);
- assertEquals("GOT: " + EXPECT_STRING, result.getRight());
+ checkResult(result, "GOT: " + EXPECT_STRING);
result = mgr.delete(deleteUri, "user", null, null, null, null);
- assertEquals((Integer) 200, result.getLeft());
- assertNotNull(result.getRight());
- assertTrue(result.getRight().length() > 0);
- assertEquals("DELETE: " + EXPECT_STRING, result.getRight());
+ checkResult(result, "DELETE: " + EXPECT_STRING);
result = mgr.put(putUri, "user", null, null, MediaType.TEXT_PLAIN, PAYLOAD);
- assertEquals((Integer) 200, result.getLeft());
- assertNotNull(result.getRight());
- assertTrue(result.getRight().length() > 0);
- assertEquals("PUT: " + PAYLOAD + EXPECT_STRING, result.getRight());
+ checkResult(result, "PUT: " + PAYLOAD + EXPECT_STRING);
result = mgr.put(putUriBlank, "user", null, null, MediaType.TEXT_PLAIN, PAYLOAD);
- assertEquals((Integer) 200, result.getLeft());
- assertNotNull(result.getRight());
- assertTrue(result.getRight().length() > 0);
- assertEquals("PUT: " + PAYLOAD + RETURN_STRING, result.getRight());
+ checkResult(result, "PUT: " + PAYLOAD + RETURN_STRING);
result = mgr.post(postUri, "user", null, null, MediaType.TEXT_PLAIN, PAYLOAD);
- assertEquals((Integer) 200, result.getLeft());
- assertNotNull(result.getRight());
- assertTrue(result.getRight().length() > 0);
- assertEquals("POST: " + PAYLOAD + EXPECT_STRING, result.getRight());
+ checkResult(result, "POST: " + PAYLOAD + EXPECT_STRING);
result = mgr.post(postUriBlank, "user", null, null, MediaType.TEXT_PLAIN, PAYLOAD);
- assertEquals((Integer) 200, result.getLeft());
- assertNotNull(result.getRight());
- assertTrue(result.getRight().length() > 0);
- assertEquals("POST: " + PAYLOAD + RETURN_STRING, result.getRight());
+ checkResult(result, "POST: " + PAYLOAD + RETURN_STRING);
result = mgr.patch(patchUri, "user", null, null, PAYLOAD);
- assertEquals((Integer) 200, result.getLeft());
- assertNotNull(result.getRight());
- assertTrue(result.getRight().length() > 0);
- assertEquals("PATCH: " + PAYLOAD + EXPECT_STRING, result.getRight());
+ checkResult(result, "PATCH: " + PAYLOAD + EXPECT_STRING);
result = mgr.patch(patchUriBlank, "user", null, null, PAYLOAD);
- assertEquals((Integer) 200, result.getLeft());
- assertNotNull(result.getRight());
- assertTrue(result.getRight().length() > 0);
- assertEquals("PATCH: " + PAYLOAD + RETURN_STRING, result.getRight());
+ checkResult(result, "PATCH: " + PAYLOAD + RETURN_STRING);
}
@@ -338,37 +267,21 @@ public class RestTest {
RestManager mgr = new RestManager();
Pair<Integer, String> result = mgr.get(baseUri + "RestTest/GetHello/" + NAME_PARAM, null, null, null);
-
- assertEquals((Integer) 200, result.getLeft());
- assertNotNull(result.getRight());
- assertTrue(result.getRight().length() > 0);
- assertEquals("GOT: " + RETURN_STRING + NAME_PARAM + " aged 90", result.getRight());
+ checkResult(result, "GOT: " + RETURN_STRING + NAME_PARAM + " aged 90");
result = mgr.delete(baseUri + "RestTest/DeleteHello/" + NAME_PARAM, null, null, null, null, null);
- assertEquals((Integer) 200, result.getLeft());
- assertNotNull(result.getRight());
- assertTrue(result.getRight().length() > 0);
- assertEquals("DELETE: " + RETURN_STRING + NAME_PARAM + " aged 90", result.getRight());
+ checkResult(result, "DELETE: " + RETURN_STRING + NAME_PARAM + " aged 90");
result = mgr.put(baseUri + "RestTest/PutHello/" + NAME_PARAM, null, null, null, MediaType.TEXT_PLAIN, PAYLOAD);
- assertEquals((Integer) 200, result.getLeft());
- assertNotNull(result.getRight());
- assertTrue(result.getRight().length() > 0);
- assertEquals("PUT: " + PAYLOAD + RETURN_STRING + NAME_PARAM + " aged 90", result.getRight());
+ checkResult(result, "PUT: " + PAYLOAD + RETURN_STRING + NAME_PARAM + " aged 90");
result = mgr.post(baseUri + "RestTest/PostHello/" + NAME_PARAM, null, null,
null, MediaType.TEXT_PLAIN, PAYLOAD);
- assertEquals((Integer) 200, result.getLeft());
- assertNotNull(result.getRight());
- assertTrue(result.getRight().length() > 0);
- assertEquals("POST: " + PAYLOAD + RETURN_STRING + NAME_PARAM + " aged 90", result.getRight());
+ checkResult(result, "POST: " + PAYLOAD + RETURN_STRING + NAME_PARAM + " aged 90");
result = mgr.patch(baseUri + "RestTest/PatchHello/" + NAME_PARAM, null, null,
null, PAYLOAD);
- assertEquals((Integer) 200, result.getLeft());
- assertNotNull(result.getRight());
- assertTrue(result.getRight().length() > 0);
- assertEquals("PATCH: " + PAYLOAD + RETURN_STRING + NAME_PARAM + " aged 90", result.getRight());
+ checkResult(result, "PATCH: " + PAYLOAD + RETURN_STRING + NAME_PARAM + " aged 90");
}