From 03248c4de4197dac33c156e6a7a6538c9943305c Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Tue, 3 Mar 2020 21:02:13 -0500 Subject: Add SO VF Module Delete Operation Redesigned the SO Operation classes; moved some code from the subclass to the superclass so it could be reused by the VF Module Delete Operation. JerseyClient does not support DELETE with a request body, so had to implement a delete() method using java11 HttpClient. Fix some issues found while testing with drools-apps. Added "delete" operation to SO simulator. Issue-ID: POLICY-2371 Signed-off-by: Jim Hahn Change-Id: I269fe13cf90c295ec2bbac92bc5a59b3820ea265 --- .../onap/policy/simulators/SoSimulatorJaxRs.java | 37 ++++++++++++++++++++-- .../onap/policy/simulators/SoSimulatorTest.java | 14 +++++++- 2 files changed, 48 insertions(+), 3 deletions(-) (limited to 'models-interactions/model-simulators') diff --git a/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/SoSimulatorJaxRs.java b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/SoSimulatorJaxRs.java index 1af0b767c..b06a66f41 100644 --- a/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/SoSimulatorJaxRs.java +++ b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/SoSimulatorJaxRs.java @@ -25,6 +25,7 @@ import com.google.gson.Gson; import java.util.UUID; import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; @@ -36,7 +37,7 @@ import org.onap.policy.so.SoRequestStatus; import org.onap.policy.so.SoResponse; -@Path("/serviceInstantiation") +@Path("/") public class SoSimulatorJaxRs { /** @@ -47,7 +48,7 @@ public class SoSimulatorJaxRs { * @return the response */ @POST - @Path("/v7/serviceInstances/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModules/scaleOut") + @Path("/serviceInstantiation/v7/serviceInstances/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModules/scaleOut") @Consumes(MediaType.APPLICATION_JSON) @Produces("application/json") public String soPostQuery(@PathParam("serviceInstanceId") final String serviceInstanceId, @@ -69,4 +70,36 @@ public class SoSimulatorJaxRs { return new Gson().toJson(response); } + + /** + * SO Delete. + * + * @param serviceInstanceId the service instance Id + * @param vnfInstanceId the VNF Id + * @return the response + */ + @DELETE + @Path("/serviceInstances/v7/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModules/{vfModuleInstanceId}") + @Consumes(MediaType.APPLICATION_JSON) + @Produces("application/json") + public String soDelete(@PathParam("serviceInstanceId") final String serviceInstanceId, + @PathParam("vnfInstanceId") final String vnfInstanceId, + @PathParam("vfModuleInstanceId") final String vfModuleInstanceId) { + final SoRequest request = new SoRequest(); + final SoRequestStatus requestStatus = new SoRequestStatus(); + requestStatus.setRequestState("COMPLETE"); + request.setRequestStatus(requestStatus); + request.setRequestId(UUID.randomUUID()); + + final SoResponse response = new SoResponse(); + + final SoRequestReferences requestReferences = new SoRequestReferences(); + final String requestId = UUID.randomUUID().toString(); + requestReferences.setRequestId(requestId); + response.setRequestReferences(requestReferences); + + response.setRequest(request); + + return new Gson().toJson(response); + } } diff --git a/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/SoSimulatorTest.java b/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/SoSimulatorTest.java index b287e3d81..723619e1c 100644 --- a/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/SoSimulatorTest.java +++ b/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/SoSimulatorTest.java @@ -134,7 +134,7 @@ public class SoSimulatorTest { } @Test - public void testResponse() { + public void testPost() { final String request = Serialization.gsonPretty.toJson(this.createTestRequest()); final Pair httpDetails = new RestManager().post( "http://localhost:6667/serviceInstantiation/v7/serviceInstances/12345/vnfs/12345/vfModules/scaleOut", @@ -144,4 +144,16 @@ public class SoSimulatorTest { final SoResponse response = Serialization.gsonPretty.fromJson(httpDetails.second, SoResponse.class); assertNotNull(response); } + + @Test + public void testDelete() { + final String request = Serialization.gsonPretty.toJson(this.createTestRequest()); + final Pair httpDetails = new RestManager().delete( + "http://localhost:6667/serviceInstances/v7/12345/vnfs/12345/vfModules/12345", + "username", + "password", new HashMap<>(), "application/json", request); + assertNotNull(httpDetails); + final SoResponse response = Serialization.gsonPretty.fromJson(httpDetails.second, SoResponse.class); + assertNotNull(response); + } } -- cgit 1.2.3-korg