From c4e0ca667a62902b8d681ee5ecb1dc60a1e2b83e Mon Sep 17 00:00:00 2001 From: Vodafone Date: Tue, 9 Apr 2019 15:18:21 +0530 Subject: VSP Compliance Check for Compute Flavor-BE Change-Id: Ife3eb83ab49e50fde1b0eb128e7e1abd5043432f Issue-ID: SDC-2051 Co-authored-by: jguistwite@iconectiv.com Signed-off-by: Vodafone --- .../externaltesting/rest/ExternalTesting.java | 10 +++++ .../rest/services/ExternalTestingImpl.java | 44 ++++++++++++++++++---- .../externaltesting/rest/services/ApiTests.java | 18 +++++++-- 3 files changed, 61 insertions(+), 11 deletions(-) (limited to 'openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/src') diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/src/main/java/org/openecomp/sdcrests/externaltesting/rest/ExternalTesting.java b/openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/src/main/java/org/openecomp/sdcrests/externaltesting/rest/ExternalTesting.java index 14c45fbdbe..21cab55dc0 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/src/main/java/org/openecomp/sdcrests/externaltesting/rest/ExternalTesting.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/src/main/java/org/openecomp/sdcrests/externaltesting/rest/ExternalTesting.java @@ -17,6 +17,8 @@ package org.openecomp.sdcrests.externaltesting.rest; import io.swagger.annotations.Api; +import org.openecomp.core.externaltesting.api.ClientConfiguration; +import org.openecomp.core.externaltesting.api.RemoteTestingEndpointDefinition; import org.openecomp.core.externaltesting.api.VtpTestExecutionRequest; import org.springframework.validation.annotation.Validated; @@ -38,6 +40,10 @@ public interface ExternalTesting { @Path("/config") Response getConfig(); + @PUT + @Path("/config") + Response setConfig(ClientConfiguration config); + @GET @Path("/testcasetree") Response getTestCasesAsTree(); @@ -46,6 +52,10 @@ public interface ExternalTesting { @Path("/endpoints") Response getEndpoints(); + @PUT + @Path("/endpoints") + Response setEndpoints(List endpoints); + @GET @Path("/endpoints/{endpointId}/scenarios") Response getScenarios(@PathParam("endpointId") String endpointId); diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/src/main/java/org/openecomp/sdcrests/externaltesting/rest/services/ExternalTestingImpl.java b/openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/src/main/java/org/openecomp/sdcrests/externaltesting/rest/services/ExternalTestingImpl.java index 206eb4986b..4e8134ff69 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/src/main/java/org/openecomp/sdcrests/externaltesting/rest/services/ExternalTestingImpl.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/src/main/java/org/openecomp/sdcrests/externaltesting/rest/services/ExternalTestingImpl.java @@ -24,6 +24,7 @@ import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdcrests.externaltesting.rest.ExternalTesting; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; +import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import javax.inject.Named; @@ -61,6 +62,22 @@ public class ExternalTestingImpl implements ExternalTesting { } } + /** + * To enable automated functional testing, allow + * a put for the client configuration. + * @return JSON response content. + */ + @Override + public Response setConfig(ClientConfiguration config) { + try { + return Response.ok(testingManager.setConfig(config)).build(); + } + catch (ExternalTestingException e) { + return convertTestingException(e); + } + } + + /** * Return the test tree structure created by the testing manager. * @return JSON response content. @@ -83,8 +100,22 @@ public class ExternalTestingImpl implements ExternalTesting { catch (ExternalTestingException e) { return convertTestingException(e); } + } + /** + * To enable automated functional testing, allow a put of the endpoints. + * @return JSON response content. + */ + @Override + public Response setEndpoints(List endpoints) { + try { + return Response.ok(testingManager.setEndpoints(endpoints)).build(); + } + catch (ExternalTestingException e) { + return convertTestingException(e); + } } + @Override public Response getScenarios(String endpoint) { try { @@ -130,13 +161,12 @@ public class ExternalTestingImpl implements ExternalTesting { public Response execute(List req, String requestId) { try { List responses = testingManager.execute(req, requestId); - List statuses = responses.stream().map(r-> Optional.ofNullable(r.getHttpStatus()).orElse(200)).distinct().collect(Collectors.toList()); + List statuses = responses.stream().map(r-> Optional.ofNullable(r.getHttpStatus()).orElse(HttpStatus.OK.value())).distinct().collect(Collectors.toList()); if (statuses.size() == 1) { - // 1 status so use it... - return Response.status(statuses.get(0)).entity(responses).build(); + return Response.status(HttpStatus.OK.value()).entity(responses).build(); } else { - return Response.status(207).entity(responses).build(); + return Response.status(HttpStatus.MULTI_STATUS.value()).entity(responses).build(); } } catch (ExternalTestingException e) { @@ -156,9 +186,9 @@ public class ExternalTestingImpl implements ExternalTesting { private Response convertTestingException(ExternalTestingException e) { if (logger.isErrorEnabled()) { - logger.error("testing exception {} {} {}", e.getTitle(), e.getCode(), e.getDetail(), e); + logger.error("testing exception {} {} {}", e.getMessageCode(), e.getHttpStatus(), e.getDetail(), e); } - TestErrorBody body = new TestErrorBody(e.getTitle(), e.getCode(), e.getDetail()); - return Response.status(e.getCode()).entity(body).build(); + TestErrorBody body = new TestErrorBody(e.getMessageCode(), e.getHttpStatus(), e.getDetail()); + return Response.status(e.getHttpStatus()).entity(body).build(); } } diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/src/test/java/org/openecomp/sdcrests/externaltesting/rest/services/ApiTests.java b/openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/src/test/java/org/openecomp/sdcrests/externaltesting/rest/services/ApiTests.java index d9da7e9006..411be2f150 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/src/test/java/org/openecomp/sdcrests/externaltesting/rest/services/ApiTests.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/src/test/java/org/openecomp/sdcrests/externaltesting/rest/services/ApiTests.java @@ -58,13 +58,23 @@ public class ApiTests { Assert.assertNotNull(testing.getTestCasesAsTree()); List requests = - Arrays.asList(new VtpTestExecutionRequest(), new VtpTestExecutionRequest()); + Arrays.asList(new VtpTestExecutionRequest(), new VtpTestExecutionRequest()); Assert.assertNotNull(testing.execute(requests, "requestId")); } class ApiTestExternalTestingManager implements ExternalTestingManager { @Override - public String getConfig() { + public ClientConfiguration getConfig() { + throw new ExternalTestingException(EXPECTED, 500, EXPECTED); + } + + @Override + public ClientConfiguration setConfig(ClientConfiguration config) { + throw new ExternalTestingException(EXPECTED, 500, EXPECTED); + } + + @Override + public List setEndpoints(List endpoints) { throw new ExternalTestingException(EXPECTED, 500, EXPECTED); } @@ -74,7 +84,7 @@ public class ApiTests { } @Override - public List getEndpoints() { + public List getEndpoints() { throw new ExternalTestingException(EXPECTED, 500, EXPECTED); } @@ -177,7 +187,7 @@ public class ApiTests { } List requestsF = - Arrays.asList(new VtpTestExecutionRequest(), new VtpTestExecutionRequest()); + Arrays.asList(new VtpTestExecutionRequest(), new VtpTestExecutionRequest()); try { testingF.execute(requestsF, null); -- cgit 1.2.3-korg