From 1cfb08779ea0e00be69e072a940b3063e049fe6b Mon Sep 17 00:00:00 2001 From: Ofir Sonsino Date: Wed, 31 Jan 2018 17:19:00 +0200 Subject: org.onap migration Change-Id: I52f0b2851f2c765752b6d21f49b32136d7d72a3d Issue-ID: VID-86 Signed-off-by: Ofir Sonsino --- .../automation/test/services/BulkRegistration.java | 94 +++++++++++++++++++++ .../automation/test/services/ServicesService.java | 47 +++++++++++ .../vid/automation/test/services/SimulatorApi.java | 98 ++++++++++++++++++++++ .../vid/automation/test/services/UsersService.java | 31 +++++++ 4 files changed, 270 insertions(+) create mode 100644 vid-automation/src/main/java/vid/automation/test/services/BulkRegistration.java create mode 100644 vid-automation/src/main/java/vid/automation/test/services/ServicesService.java create mode 100644 vid-automation/src/main/java/vid/automation/test/services/SimulatorApi.java create mode 100644 vid-automation/src/main/java/vid/automation/test/services/UsersService.java (limited to 'vid-automation/src/main/java/vid/automation/test/services') diff --git a/vid-automation/src/main/java/vid/automation/test/services/BulkRegistration.java b/vid-automation/src/main/java/vid/automation/test/services/BulkRegistration.java new file mode 100644 index 000000000..4cdd85d24 --- /dev/null +++ b/vid-automation/src/main/java/vid/automation/test/services/BulkRegistration.java @@ -0,0 +1,94 @@ +package vid.automation.test.services; + +import com.google.common.collect.ImmutableMap; +import vid.automation.test.Constants; + +public class BulkRegistration { + + public static void searchExistingServiceInstance() { + searchExistingServiceInstance("Active"); + } + public static void searchExistingServiceInstance(String orchStatus) { + SimulatorApi.registerExpectation( + new String [] { + Constants.RegisterToSimulator.genericRequest.ECOMP_PORTAL_GET_SESSION_SLOT_CHECK_INTERVAL, + Constants.RegisterToSimulator.SearchForServiceInstance.GET_FULL_SUBSCRIBERS, + Constants.RegisterToSimulator.SearchForServiceInstance.GET_SERVICES, + Constants.RegisterToSimulator.SearchForServiceInstance.GET_SUBSCRIBERS_FOR_CUSTOMER, + Constants.RegisterToSimulator.SearchForServiceInstance.FILTER_SERVICE_INSTANCE_BY_ID, + Constants.RegisterToSimulator.SearchForServiceInstance.NAMED_QUERY_VIEW_EDIT + + }, ImmutableMap.of("", orchStatus)); + } + + public static void searchExistingServiceInstance2(String orchStatus) { + SimulatorApi.registerExpectation( + new String [] { + Constants.RegisterToSimulator.SearchForServiceInstance.GET_FULL_SUBSCRIBERS, + Constants.RegisterToSimulator.SearchForServiceInstance.GET_SERVICES, + Constants.RegisterToSimulator.SearchForServiceInstance.GET_SUBSCRIBERS_FOR_CUSTOMER_2, + Constants.RegisterToSimulator.SearchForServiceInstance.FILTER_SERVICE_INSTANCE_BY_ID_2, + Constants.RegisterToSimulator.SearchForServiceInstance.NAMED_QUERY_VIEW_EDIT_2 + }, ImmutableMap.of("", orchStatus)); + } + + public static void associatePnf() { + SimulatorApi.registerExpectation( + new String [] { + Constants.RegisterToSimulator.pProbe.GET_SERVICE_INSTANCE_WITH_LOGICAL_LINKS, + Constants.RegisterToSimulator.pProbe.GET_SPECIFIC_PNF, + Constants.RegisterToSimulator.pProbe.ADD_PNF_RELATIONSHIP, + Constants.RegisterToSimulator.pProbe.GET_ADD_PNF_RELATIONSHIP_ORCH_REQ + }, ImmutableMap.of()); + } + + public static void searchPnfError() { + SimulatorApi.registerExpectation( + new String [] { + Constants.RegisterToSimulator.pProbe.GET_SERVICE_INSTANCE_WITH_LOGICAL_LINKS, + Constants.RegisterToSimulator.pProbe.GET_SPECIFIC_PNF_ERROR + }, ImmutableMap.of()); + } + public static void associatePnfError() { + SimulatorApi.registerExpectation( + new String [] { + Constants.RegisterToSimulator.pProbe.GET_SERVICE_INSTANCE_WITH_LOGICAL_LINKS, + Constants.RegisterToSimulator.pProbe.GET_SPECIFIC_PNF, + Constants.RegisterToSimulator.pProbe.ADD_PNF_RELATIONSHIP_ERROR + }, ImmutableMap.of()); + } + + public static void dissociatePnf() { + SimulatorApi.registerExpectation( + new String [] { + Constants.RegisterToSimulator.pProbe.REMOVE_PNF_RELATIONSHIP, + Constants.RegisterToSimulator.pProbe.GET_REMOVE_PNF_RELATIONSHIP_ORCH_REQ + }, ImmutableMap.of()); + } + + public static void getAssociatedPnfs() { + SimulatorApi.registerExpectation( + new String [] { + Constants.RegisterToSimulator.pProbe.GET_SERVICE_INSTANCE_WITH_LOGICAL_LINKS, + Constants.RegisterToSimulator.pProbe.GET_LOGICAL_LINK + }, ImmutableMap.of()); + } + + public static void activateServiceInstance(String action) { + SimulatorApi.registerExpectation( + new String [] { + Constants.RegisterToSimulator.pProbe.GET_SERVICE_INSTANCE_WITH_LOGICAL_LINKS, + Constants.RegisterToSimulator.activateDeactivate.ACTIVATE_SERVICE_INSTANCE, + Constants.RegisterToSimulator.activateDeactivate.ACTIVATE_SERVICE_INSTANCE_ORCH_REQUEST + }, ImmutableMap.of("", action)); + } + + public static void activateServiceInstanceError(String action) { + SimulatorApi.registerExpectation( + new String []{ + Constants.RegisterToSimulator.pProbe.GET_SERVICE_INSTANCE_WITH_LOGICAL_LINKS, + Constants.RegisterToSimulator.activateDeactivate.ACTIVATE_SERVICE_INSTANCE_ERROR + } , ImmutableMap.of("", action)); + } + +} diff --git a/vid-automation/src/main/java/vid/automation/test/services/ServicesService.java b/vid-automation/src/main/java/vid/automation/test/services/ServicesService.java new file mode 100644 index 000000000..39f235b9e --- /dev/null +++ b/vid-automation/src/main/java/vid/automation/test/services/ServicesService.java @@ -0,0 +1,47 @@ +package vid.automation.test.services; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.openecomp.sdc.ci.tests.utilities.FileHandling; +import vid.automation.test.model.Service; +import vid.automation.test.model.ServicesObject; + +import java.io.File; +import java.io.IOException; +import java.util.HashMap; + +/** + * Created by itzikliderman on 08/09/2017. + */ +public class ServicesService { + private HashMap services; + + public ServicesService() throws IOException { + services = getServicesFromJson(); + + } + + HashMap getServicesFromJson() throws IOException { + String fileName = "services"; + ObjectMapper mapper = new ObjectMapper(); + ServicesObject servicesObject; + try { + File servicesFile = FileHandling.getConfigFile(fileName); + if(!servicesFile.exists()) { + String basePath = System.getProperty("BASE_PATH"); + servicesFile = new File( basePath + File.separator + "conf" + File.separator + fileName); + } + servicesObject = mapper.readValue(servicesFile, ServicesObject.class); + return servicesObject.services; + } catch (IOException e) { + e.printStackTrace(); + return null; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + public Service getService(String serviceId) { + return services.get(serviceId); + } +} diff --git a/vid-automation/src/main/java/vid/automation/test/services/SimulatorApi.java b/vid-automation/src/main/java/vid/automation/test/services/SimulatorApi.java new file mode 100644 index 000000000..95370fc82 --- /dev/null +++ b/vid-automation/src/main/java/vid/automation/test/services/SimulatorApi.java @@ -0,0 +1,98 @@ +package vid.automation.test.services; + +import com.google.common.collect.ImmutableMap; +import org.apache.commons.io.IOUtils; +import org.apache.log4j.Logger; +import org.glassfish.jersey.client.ClientProperties; +import org.glassfish.jersey.uri.internal.JerseyUriBuilder; +import org.springframework.http.HttpStatus; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Map; + +import static org.testng.Assert.assertEquals; + +public class SimulatorApi { + + private static Logger logger = Logger.getLogger(SimulatorApi.class.getName()); + + public enum RegistrationStrategy { + APPEND, CLEAR_THEN_SET + } + + private static final URI uri; + private static final Client client; + + static { + String host = System.getProperty("VID_HOST", "127.0.0.1" ); + Integer port = Integer.valueOf(System.getProperty("VID_PORT", "8080")); + uri = new JerseyUriBuilder().host(host).port(port).scheme("http").path("vidSimulator").build(); + client = ClientBuilder.newClient(); + client.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true); + } + + public static void registerExpectation(String expectationFilename) { + registerExpectation(expectationFilename, ImmutableMap.of(), RegistrationStrategy.APPEND); + } + + public static void registerExpectation(String expectationFilename, RegistrationStrategy registrationStrategy) { + registerExpectation(expectationFilename, ImmutableMap.of(), registrationStrategy); + } + + public static void registerExpectation(String expectationTemplateFilename, ImmutableMap templateParams) { + registerExpectation(expectationTemplateFilename, templateParams, RegistrationStrategy.APPEND); + } + + public static void registerExpectation(String... expectationTemplateFilenames) { + registerExpectation(expectationTemplateFilenames, ImmutableMap.of()); + } + + public static void registerExpectation(String[] expectationTemplateFilenames, ImmutableMap templateParams) { + for (String expectationTemplateFilename: expectationTemplateFilenames) { + registerExpectation(expectationTemplateFilename, templateParams); + } + } + + public static void registerExpectation(String expectationTemplateFilename, ImmutableMap templateParams, RegistrationStrategy registrationStrategy) { + + try { + final InputStream resource = SimulatorApi.class.getClassLoader().getResourceAsStream("registration_to_simulator/" + expectationTemplateFilename); + if (resource == null) throw new RuntimeException("template file not found: " + "/registration_to_simulator/" + expectationTemplateFilename); + String content = IOUtils.toString(resource, "UTF-8"); + + for (Map.Entry templateParam : templateParams.entrySet()) { + content = content.replaceAll(templateParam.getKey(), templateParam.getValue().toString()); + } + + registerToSimulatorAndAssertSuccess(content, registrationStrategy); + + } catch (IOException e) { + logger.error("couldn't read " + expectationTemplateFilename, e); +// throw new RuntimeException("couldn't read " + expectationTemplateFilename, e); + } + } + + private static void registerToSimulatorAndAssertSuccess(String content, RegistrationStrategy registrationStrategy) { + WebTarget webTarget = client.target(uri).path("registerToVidSimulator"); + Response response; + if (registrationStrategy == RegistrationStrategy.CLEAR_THEN_SET) { + response = webTarget.request().delete(); + assertEquals(response.getStatus(), HttpStatus.OK.value()); + } + response = webTarget.request(MediaType.APPLICATION_JSON_TYPE).post(Entity.json(content)); + assertEquals(response.getStatus(), HttpStatus.OK.value()); + } + + public static void clearAll() { + WebTarget webTarget = client.target(uri).path("registerToVidSimulator"); + webTarget.request().delete(); + } +} diff --git a/vid-automation/src/main/java/vid/automation/test/services/UsersService.java b/vid-automation/src/main/java/vid/automation/test/services/UsersService.java new file mode 100644 index 000000000..e8df17764 --- /dev/null +++ b/vid-automation/src/main/java/vid/automation/test/services/UsersService.java @@ -0,0 +1,31 @@ +package vid.automation.test.services; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.openecomp.sdc.ci.tests.utilities.FileHandling; +import vid.automation.test.model.User; +import vid.automation.test.model.UsersObject; +import vid.automation.test.utils.ReadFile; + +import java.io.File; +import java.io.IOException; +import java.util.HashMap; + +/** + * Created by itzikliderman on 08/09/2017. + */ +public class UsersService { + private HashMap users; + + public UsersService() throws IOException { + users = getUsersFromJson(); + } + + HashMap getUsersFromJson() throws IOException { + UsersObject usersObject = ReadFile.getJsonFile("users", UsersObject.class); + return usersObject.users; + } + + public User getUser(String userId) { + return users.get(userId); + } +} -- cgit 1.2.3-korg