From f43b3e32fdf4cdb3361c584491730af18ef46baf Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Mon, 27 Aug 2018 15:32:14 -0400 Subject: use new SO API for scale-out Updated licenses and serialization IDs. Moved hashCode() and equals() methods to be in same location as in the original code so it can be more easily compared. Changed vDNS yaml timeout and retry to 1200 and 0, respectively, to match the original values. Removed extra newline from yaml, to match original yaml. Reformatted source to wrap lines at 120 characters and removing trailing white space. Change-Id: I3f5e59a1f44750347de49164f587d4ffefdee8b4 Issue-ID: POLICY-962 Signed-off-by: Jim Hahn --- .../java/org/onap/policy/so/TestSOManager.java | 102 +++++++++++---------- .../java/org/onap/policy/so/TestSoDummyServer.java | 87 +++++++----------- 2 files changed, 87 insertions(+), 102 deletions(-) (limited to 'controlloop/common/model-impl/so/src/test/java') diff --git a/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSOManager.java b/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSOManager.java index 864362649..4a7fdda8d 100644 --- a/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSOManager.java +++ b/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSOManager.java @@ -7,9 +7,9 @@ * 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. @@ -24,12 +24,10 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; - import java.io.IOException; import java.net.URI; import java.util.UUID; import java.util.concurrent.Future; - import org.apache.http.client.ClientProtocolException; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; @@ -46,14 +44,14 @@ import org.junit.Test; import org.onap.policy.drools.system.PolicyEngine; public class TestSOManager { - private static final String BASE_URI = "http://localhost:46553/TestSOManager"; + private static final String BASE_URI = "http://localhost:46553/TestSOManager"; private static final String BASE_SO_URI = BASE_URI + "/SO"; private static HttpServer server; @BeforeClass public static void setUp() { final ResourceConfig rc = new ResourceConfig(TestSoDummyServer.class); - server = GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc); + server = GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc); } @AfterClass @@ -77,13 +75,16 @@ public class TestSOManager { assertNotNull(manager); manager.setRestGetTimeout(100); - SOResponse response = manager.createModuleInstance("http:/localhost:99999999", BASE_SO_URI, "sean", "citizen", null); + SOResponse response = + manager.createModuleInstance("http:/localhost:99999999", BASE_SO_URI, "sean", "citizen", null); assertNull(response); - response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstances/v5", BASE_SO_URI, "sean", "citizen", null); + response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstantiation/v7", BASE_SO_URI, "sean", + "citizen", null); assertNull(response); - response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstances/v5", BASE_SO_URI, "sean", "citizen", new SORequest()); + response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstantiation/v7", BASE_SO_URI, "sean", + "citizen", new SORequest()); assertNull(response); SORequest request = new SORequest(); @@ -94,16 +95,19 @@ public class TestSOManager { request.setRequestStatus(new SORequestStatus()); request.getRequestStatus().setRequestState("ONGOING"); - response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstances/v5", BASE_SO_URI, "sean", "citizen", request); + response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstantiation/v7", BASE_SO_URI, "sean", + "citizen", request); assertNull(response); request.setRequestType("ReturnCompleted"); - response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstances/v5", BASE_SO_URI, "sean", "citizen", request); + response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstantiation/v7", BASE_SO_URI, "sean", + "citizen", request); assertNotNull(response); assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState()); request.setRequestType("ReturnFailed"); - response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstances/v5", BASE_SO_URI, "sean", "citizen", request); + response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstantiation/v7", BASE_SO_URI, "sean", + "citizen", request); assertNotNull(response); assertEquals("FAILED", response.getRequest().getRequestStatus().getRequestState()); @@ -111,14 +115,16 @@ public class TestSOManager { request.setRequestType("ReturnOnging200"); request.setRequestScope(new Integer(10).toString()); - response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstances/v5", BASE_SO_URI, "sean", "citizen", request); + response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstantiation/v7", BASE_SO_URI, "sean", + "citizen", request); assertNotNull(response); assertNotNull(response.getRequest()); assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState()); request.setRequestType("ReturnOnging202"); request.setRequestScope(new Integer(20).toString()); - response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstances/v5", BASE_SO_URI, "sean", "citizen", request); + response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstantiation/v7", BASE_SO_URI, "sean", + "citizen", request); assertNotNull(response); assertNotNull(response.getRequest()); assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState()); @@ -126,13 +132,15 @@ public class TestSOManager { // Test timeout after 20 attempts for a response request.setRequestType("ReturnOnging202"); request.setRequestScope(new Integer(21).toString()); - response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstances/v5", BASE_SO_URI, "sean", "citizen", request); + response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstantiation/v7", BASE_SO_URI, "sean", + "citizen", request); assertNull(response); // Test bad response after 3 attempts for a response request.setRequestType("ReturnBadAfterWait"); request.setRequestScope(new Integer(3).toString()); - response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstances/v5", BASE_SO_URI, "sean", "citizen", request); + response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstantiation/v7", BASE_SO_URI, "sean", + "citizen", request); assertNull(response); } @@ -148,31 +156,31 @@ public class TestSOManager { WorkingMemory wm = new DummyWorkingMemory(); PolicyEngine.manager.setEnvironmentProperty("so.url", "http:/localhost:99999999"); - Future asyncRestCallFuture = manager.asyncSORestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), UUID.randomUUID().toString(), null); + Future asyncRestCallFuture = manager.asyncSORestCall(UUID.randomUUID().toString(), wm, + UUID.randomUUID().toString(), UUID.randomUUID().toString(), null); try { SOResponse response = asyncRestCallFuture.get(); assertEquals(999, response.getHttpResponseCode()); - } - catch (Exception e) { + } catch (Exception e) { fail("test should not throw an exception"); } - + PolicyEngine.manager.setEnvironmentProperty("so.url", BASE_SO_URI); - asyncRestCallFuture = manager.asyncSORestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), UUID.randomUUID().toString(), null); + asyncRestCallFuture = manager.asyncSORestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + UUID.randomUUID().toString(), null); try { SOResponse response = asyncRestCallFuture.get(); assertEquals(999, response.getHttpResponseCode()); - } - catch (Exception e) { + } catch (Exception e) { fail("test should not throw an exception"); } - asyncRestCallFuture = manager.asyncSORestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), UUID.randomUUID().toString(), new SORequest()); + asyncRestCallFuture = manager.asyncSORestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + UUID.randomUUID().toString(), new SORequest()); try { SOResponse response = asyncRestCallFuture.get(); assertEquals(999, response.getHttpResponseCode()); - } - catch (Exception e) { + } catch (Exception e) { fail("test should not throw an exception"); } @@ -184,33 +192,33 @@ public class TestSOManager { request.setRequestStatus(new SORequestStatus()); request.getRequestStatus().setRequestState("ONGOING"); - asyncRestCallFuture = manager.asyncSORestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), UUID.randomUUID().toString(), request); + asyncRestCallFuture = manager.asyncSORestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + UUID.randomUUID().toString(), request); try { SOResponse response = asyncRestCallFuture.get(); assertEquals(999, response.getHttpResponseCode()); - } - catch (Exception e) { + } catch (Exception e) { fail("test should not throw an exception"); } request.setRequestType("ReturnCompleted"); - asyncRestCallFuture = manager.asyncSORestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), UUID.randomUUID().toString(), request); + asyncRestCallFuture = manager.asyncSORestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + UUID.randomUUID().toString(), request); try { SOResponse response = asyncRestCallFuture.get(); assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState()); - } - catch (Exception e) { + } catch (Exception e) { fail("test should not throw an exception"); } request.setRequestType("ReturnFailed"); - asyncRestCallFuture = manager.asyncSORestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), UUID.randomUUID().toString(), request); + asyncRestCallFuture = manager.asyncSORestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + UUID.randomUUID().toString(), request); try { SOResponse response = asyncRestCallFuture.get(); assertEquals("FAILED", response.getRequest().getRequestStatus().getRequestState()); - } - catch (Exception e) { + } catch (Exception e) { fail("test should not throw an exception"); } @@ -218,49 +226,49 @@ public class TestSOManager { request.setRequestType("ReturnOnging200"); request.setRequestScope(new Integer(10).toString()); - asyncRestCallFuture = manager.asyncSORestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), UUID.randomUUID().toString(), request); + asyncRestCallFuture = manager.asyncSORestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + UUID.randomUUID().toString(), request); try { SOResponse response = asyncRestCallFuture.get(); assertNotNull(response.getRequest()); assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState()); - } - catch (Exception e) { + } catch (Exception e) { fail("test should not throw an exception"); } request.setRequestType("ReturnOnging202"); request.setRequestScope(new Integer(20).toString()); - asyncRestCallFuture = manager.asyncSORestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), UUID.randomUUID().toString(), request); + asyncRestCallFuture = manager.asyncSORestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + UUID.randomUUID().toString(), request); try { SOResponse response = asyncRestCallFuture.get(); assertNotNull(response.getRequest()); assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState()); - } - catch (Exception e) { + } catch (Exception e) { fail("test should not throw an exception"); } // Test timeout after 20 attempts for a response request.setRequestType("ReturnOnging202"); request.setRequestScope(new Integer(21).toString()); - asyncRestCallFuture = manager.asyncSORestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), UUID.randomUUID().toString(), request); + asyncRestCallFuture = manager.asyncSORestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + UUID.randomUUID().toString(), request); try { SOResponse response = asyncRestCallFuture.get(); assertEquals(999, response.getHttpResponseCode()); - } - catch (Exception e) { + } catch (Exception e) { fail("test should not throw an exception"); } // Test bad response after 3 attempts for a response request.setRequestType("ReturnBadAfterWait"); request.setRequestScope(new Integer(3).toString()); - asyncRestCallFuture = manager.asyncSORestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), UUID.randomUUID().toString(), request); + asyncRestCallFuture = manager.asyncSORestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + UUID.randomUUID().toString(), request); try { SOResponse response = asyncRestCallFuture.get(); assertEquals(999, response.getHttpResponseCode()); - } - catch (Exception e) { + } catch (Exception e) { fail("test should not throw an exception"); } } diff --git a/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoDummyServer.java b/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoDummyServer.java index 907ca69bc..348523140 100644 --- a/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoDummyServer.java +++ b/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoDummyServer.java @@ -4,12 +4,14 @@ * ================================================================================ * Copyright (C) 2018 Ericsson. All rights reserved. * ================================================================================ + * Modifications Copyright (C) 2018 AT&T. 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. @@ -22,13 +24,11 @@ package org.onap.policy.so; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; - import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.core.Response; - import com.google.gson.Gson; @Path("/SO") @@ -45,7 +45,8 @@ public class TestSoDummyServer { @Path("/Stats") public Response serviceGetStats() { statMessagesReceived++; - return Response.status(200).entity("{\"GET\": " + getMessagesReceived + ",\"STAT\": " + statMessagesReceived + ",\"POST\": " + postMessagesReceived + ",\"PUT\": " + putMessagesReceived + "}").build(); + return Response.status(200).entity("{\"GET\": " + getMessagesReceived + ",\"STAT\": " + statMessagesReceived + + ",\"POST\": " + postMessagesReceived + ",\"PUT\": " + putMessagesReceived + "}").build(); } @GET @@ -56,7 +57,7 @@ public class TestSoDummyServer { } @POST - @Path("/serviceInstances/v5") + @Path("/serviceInstantiation/v7") public Response servicePostRequest(final String jsonString) { postMessagesReceived++; @@ -67,8 +68,7 @@ public class TestSoDummyServer { SORequest request = null; try { request = new Gson().fromJson(jsonString, SORequest.class); - } - catch (Exception e) { + } catch (Exception e) { return Response.status(400).build(); } @@ -82,8 +82,10 @@ public class TestSoDummyServer { if ("ReturnBadJson".equals(request.getRequestType())) { return Response.status(200) - .entity("{\"GET\": , " + getMessagesReceived + ",\"STAT\": " + statMessagesReceived + ",\"POST\": , " + postMessagesReceived + ",\"PUT\": " + putMessagesReceived + "}") - .build(); + .entity("{\"GET\": , " + getMessagesReceived + ",\"STAT\": " + statMessagesReceived + + ",\"POST\": , " + postMessagesReceived + ",\"PUT\": " + + putMessagesReceived + "}") + .build(); } SOResponse response = new SOResponse(); @@ -95,18 +97,14 @@ public class TestSoDummyServer { response.getRequest().getRequestStatus().setRequestState("COMPLETE"); response.setHttpResponseCode(200); String responseString = new Gson().toJson(response, SOResponse.class); - return Response.status(response.getHttpResponseCode()) - .entity(responseString) - .build(); + return Response.status(response.getHttpResponseCode()).entity(responseString).build(); } if ("ReturnFailed".equals(request.getRequestType())) { response.getRequest().getRequestStatus().setRequestState("FAILED"); response.setHttpResponseCode(200); String responseString = new Gson().toJson(response, SOResponse.class); - return Response.status(response.getHttpResponseCode()) - .entity(responseString) - .build(); + return Response.status(response.getHttpResponseCode()).entity(responseString).build(); } if ("ReturnOnging202".equals(request.getRequestType())) { @@ -115,9 +113,7 @@ public class TestSoDummyServer { response.getRequest().getRequestStatus().setRequestState("ONGOING"); response.setHttpResponseCode(202); String responseString = new Gson().toJson(response, SOResponse.class); - return Response.status(response.getHttpResponseCode()) - .entity(responseString) - .build(); + return Response.status(response.getHttpResponseCode()).entity(responseString).build(); } if ("ReturnOnging200".equals(request.getRequestType())) { @@ -126,9 +122,7 @@ public class TestSoDummyServer { response.getRequest().getRequestStatus().setRequestState("ONGOING"); response.setHttpResponseCode(200); String responseString = new Gson().toJson(response, SOResponse.class); - return Response.status(response.getHttpResponseCode()) - .entity(responseString) - .build(); + return Response.status(response.getHttpResponseCode()).entity(responseString).build(); } @@ -138,20 +132,16 @@ public class TestSoDummyServer { response.getRequest().getRequestStatus().setRequestState("ONGOING"); response.setHttpResponseCode(200); String responseString = new Gson().toJson(response, SOResponse.class); - return Response.status(response.getHttpResponseCode()) - .entity(responseString) - .build(); + return Response.status(response.getHttpResponseCode()).entity(responseString).build(); } return null; } @POST - @Path("/serviceInstances/v5/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModules") - public Response servicePostRequestVfModules( - @PathParam("serviceInstanceId") final String serviceInstanceId, - @PathParam("vnfInstanceId") final String vnfInstanceId, - final String jsonString) { + @Path("/serviceInstantiation/v7/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModules/scaleOut") + public Response servicePostRequestVfModules(@PathParam("serviceInstanceId") final String serviceInstanceId, + @PathParam("vnfInstanceId") final String vnfInstanceId, final String jsonString) { postMessagesReceived++; if (jsonString == null) { @@ -161,8 +151,7 @@ public class TestSoDummyServer { SORequest request = null; try { request = new Gson().fromJson(jsonString, SORequest.class); - } - catch (Exception e) { + } catch (Exception e) { return Response.status(400).build(); } @@ -176,8 +165,10 @@ public class TestSoDummyServer { if ("ReturnBadJson".equals(request.getRequestType())) { return Response.status(200) - .entity("{\"GET\": , " + getMessagesReceived + ",\"STAT\": " + statMessagesReceived + ",\"POST\": , " + postMessagesReceived + ",\"PUT\": " + putMessagesReceived + "}") - .build(); + .entity("{\"GET\": , " + getMessagesReceived + ",\"STAT\": " + statMessagesReceived + + ",\"POST\": , " + postMessagesReceived + ",\"PUT\": " + + putMessagesReceived + "}") + .build(); } SOResponse response = new SOResponse(); @@ -189,18 +180,14 @@ public class TestSoDummyServer { response.getRequest().getRequestStatus().setRequestState("COMPLETE"); response.setHttpResponseCode(200); String responseString = new Gson().toJson(response, SOResponse.class); - return Response.status(response.getHttpResponseCode()) - .entity(responseString) - .build(); + return Response.status(response.getHttpResponseCode()).entity(responseString).build(); } if ("ReturnFailed".equals(request.getRequestType())) { response.getRequest().getRequestStatus().setRequestState("FAILED"); response.setHttpResponseCode(200); String responseString = new Gson().toJson(response, SOResponse.class); - return Response.status(response.getHttpResponseCode()) - .entity(responseString) - .build(); + return Response.status(response.getHttpResponseCode()).entity(responseString).build(); } if ("ReturnOnging202".equals(request.getRequestType())) { @@ -209,9 +196,7 @@ public class TestSoDummyServer { response.getRequest().getRequestStatus().setRequestState("ONGOING"); response.setHttpResponseCode(202); String responseString = new Gson().toJson(response, SOResponse.class); - return Response.status(response.getHttpResponseCode()) - .entity(responseString) - .build(); + return Response.status(response.getHttpResponseCode()).entity(responseString).build(); } if ("ReturnOnging200".equals(request.getRequestType())) { @@ -220,9 +205,7 @@ public class TestSoDummyServer { response.getRequest().getRequestStatus().setRequestState("ONGOING"); response.setHttpResponseCode(200); String responseString = new Gson().toJson(response, SOResponse.class); - return Response.status(response.getHttpResponseCode()) - .entity(responseString) - .build(); + return Response.status(response.getHttpResponseCode()).entity(responseString).build(); } @@ -232,9 +215,7 @@ public class TestSoDummyServer { response.getRequest().getRequestStatus().setRequestState("ONGOING"); response.setHttpResponseCode(200); String responseString = new Gson().toJson(response, SOResponse.class); - return Response.status(response.getHttpResponseCode()) - .entity(responseString) - .build(); + return Response.status(response.getHttpResponseCode()).entity(responseString).build(); } return null; @@ -250,9 +231,7 @@ public class TestSoDummyServer { if (--iterationsLeft > 0) { response.getRequest().setRequestScope(new Integer(iterationsLeft).toString()); String responseString = new Gson().toJson(response, SOResponse.class); - return Response.status(response.getHttpResponseCode()) - .entity(responseString) - .build(); + return Response.status(response.getHttpResponseCode()).entity(responseString).build(); } ongoingRequestMap.remove(nsInstanceId); @@ -265,8 +244,6 @@ public class TestSoDummyServer { response.getRequest().setRequestScope("0"); response.setHttpResponseCode(200); String responseString = new Gson().toJson(response, SOResponse.class); - return Response.status(response.getHttpResponseCode()) - .entity(responseString) - .build(); + return Response.status(response.getHttpResponseCode()).entity(responseString).build(); } } -- cgit 1.2.3-korg