From da8e738a75e8cfe9a8a8e2863a4a643c3ac367ba Mon Sep 17 00:00:00 2001 From: "r.bogacki" Date: Thu, 28 Mar 2019 14:08:45 +0100 Subject: JUnit tests for NetworkAdapterRest Increased junit tests coverage according to Sonar analyses. Added test for a network rollback. Change-Id: I85622f62246b4bf3cc8d2ad253facaa2823923e7 Issue-ID: SO-1692 Signed-off-by: Robert Bogacki --- .../adapters/network/NetworkAdapterRestTest.java | 37 +++++++++++++++++++++- .../resources/__files/RollbackNetworkResponse.json | 5 +++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 adapters/mso-openstack-adapters/src/test/resources/__files/RollbackNetworkResponse.json diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/NetworkAdapterRestTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/NetworkAdapterRestTest.java index 3910d9ec44..4e2d5e5da2 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/NetworkAdapterRestTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/NetworkAdapterRestTest.java @@ -51,9 +51,10 @@ import org.onap.so.adapters.nwrest.CreateNetworkRequest; import org.onap.so.adapters.nwrest.CreateNetworkResponse; import org.onap.so.adapters.nwrest.DeleteNetworkRequest; import org.onap.so.adapters.nwrest.DeleteNetworkResponse; -import org.onap.so.adapters.nwrest.NetworkTechnology; import org.onap.so.adapters.nwrest.QueryNetworkError; import org.onap.so.adapters.nwrest.QueryNetworkResponse; +import org.onap.so.adapters.nwrest.RollbackNetworkRequest; +import org.onap.so.adapters.nwrest.RollbackNetworkResponse; import org.onap.so.adapters.nwrest.UpdateNetworkRequest; import org.onap.so.adapters.nwrest.UpdateNetworkResponse; import org.onap.so.adapters.vnf.BaseRestTestUtils; @@ -192,6 +193,40 @@ public class NetworkAdapterRestTest extends BaseRestTestUtils { } + @Test + public void testRollbackNetwork() throws IOException { + + RollbackNetworkRequest request = new RollbackNetworkRequest(); + + MsoRequest msoReq = new MsoRequest(); + + msoReq.setRequestId(MSO_REQUEST_ID); + msoReq.setServiceInstanceId(MSO_SERVICE_INSTANCE_ID); + + mockOpenStackResponseAccess(wireMockPort); + + mockOpenStackPublicUrlStackByID_200(wireMockPort); + + mockOpenStackGetPublicUrlStackByNameAndID_204(wireMockPort); + + mockOpenStackDeletePublicUrlStackByNameAndID_204(); + + headers.add("Accept", MediaType.APPLICATION_JSON); + + HttpEntity entity = new HttpEntity<>(request, headers); + + ResponseEntity response = restTemplate + .exchange(createURLWithPort("/services/rest/v1/networks/da886914-efb2-4917-b335-c8381528d90b/rollback"), + HttpMethod.DELETE, entity, RollbackNetworkResponse.class); + + RollbackNetworkResponse expectedResponse = jettisonTypeObjectMapper.getMapper() + .readValue(new File("src/test/resources/__files/RollbackNetworkResponse.json"), RollbackNetworkResponse.class); + + assertThat(response.getBody(), sameBeanAs(expectedResponse)); + assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); + + } + @Test public void testQueryNetwork_Exception() throws IOException{ MsoRequest msoReq = new MsoRequest(); diff --git a/adapters/mso-openstack-adapters/src/test/resources/__files/RollbackNetworkResponse.json b/adapters/mso-openstack-adapters/src/test/resources/__files/RollbackNetworkResponse.json new file mode 100644 index 0000000000..d319fedecd --- /dev/null +++ b/adapters/mso-openstack-adapters/src/test/resources/__files/RollbackNetworkResponse.json @@ -0,0 +1,5 @@ +{ + "rollbackNetworkResponse" : { + "networkRolledBack" : true + } +} -- cgit 1.2.3-korg