diff options
author | Sonsino, Ofir (os0695) <os0695@intl.att.com> | 2018-08-12 14:51:28 +0300 |
---|---|---|
committer | Sonsino, Ofir (os0695) <os0695@intl.att.com> | 2018-08-12 15:02:57 +0300 |
commit | 4a4dcc5185f8ba5a28c7f9fef509f32c0c2389e6 (patch) | |
tree | 23e55ee7e1ad9b91bcc3ef1dbe1fb7b183f8b2b6 /vid-automation/src/main/java/vid/automation/test/services | |
parent | 661a24fd57de02869a9771761e0fcba7eb77d121 (diff) |
vid-automation selenium tests
Change-Id: I6c1b0a0cf3bbfa4314c81f0cc72507db805ec632
Issue-ID: VID-281
Signed-off-by: Sonsino, Ofir (os0695) <os0695@intl.att.com>
Diffstat (limited to 'vid-automation/src/main/java/vid/automation/test/services')
7 files changed, 728 insertions, 63 deletions
diff --git a/vid-automation/src/main/java/vid/automation/test/services/AsyncJobsService.java b/vid-automation/src/main/java/vid/automation/test/services/AsyncJobsService.java new file mode 100644 index 000000000..01158fa66 --- /dev/null +++ b/vid-automation/src/main/java/vid/automation/test/services/AsyncJobsService.java @@ -0,0 +1,44 @@ +package vid.automation.test.services; + +import vid.automation.test.utils.DB_CONFIG; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.sql.Statement; + +public class AsyncJobsService { + + public void dropAllAsyncJobs() { + System.out.println("Connecting database..."); + + try (Connection connection = DriverManager.getConnection(DB_CONFIG.url, DB_CONFIG.username, DB_CONFIG.password)) { + System.out.println("Database connected!"); + + Statement stmt = connection.createStatement(); + stmt.addBatch("DELETE FROM `vid_service_info`"); + stmt.addBatch("DELETE FROM `vid_job`"); + stmt.addBatch("DELETE FROM `vid_job_audit_status`"); + int[] executeBatch = stmt.executeBatch(); + + } catch (SQLException e) { + throw new IllegalStateException("Cannot connect the database!", e); + } + } + + public void muteAllAsyncJobs() { + System.out.println("Connecting database..."); + + try (Connection connection = DriverManager.getConnection(DB_CONFIG.url, DB_CONFIG.username, DB_CONFIG.password)) { + System.out.println("Database connected!"); + + Statement stmt = connection.createStatement(); + stmt.addBatch("UPDATE `vid_job` set `TAKEN_BY`='muteAllAsyncJobs', `AGE`=`AGE`+5"); + int[] executeBatch = stmt.executeBatch(); + + } catch (SQLException e) { + throw new IllegalStateException("Cannot connect the database!", e); + } + } + +} 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 index 4cdd85d24..b142195e5 100644 --- a/vid-automation/src/main/java/vid/automation/test/services/BulkRegistration.java +++ b/vid-automation/src/main/java/vid/automation/test/services/BulkRegistration.java @@ -1,35 +1,109 @@ package vid.automation.test.services; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import org.opencomp.simulator.presetGenerator.presets.aai.*; +import org.opencomp.simulator.presetGenerator.presets.mso.*; +import org.opencomp.simulator.presetGenerator.presets.sdc.PresetSDCGetServiceMetadataGet; +import org.opencomp.simulator.presetGenerator.presets.sdc.PresetSDCGetServiceToscaModelGet; import vid.automation.test.Constants; +import static vid.automation.test.services.SimulatorApi.RegistrationStrategy.APPEND; + public class BulkRegistration { public static void searchExistingServiceInstance() { searchExistingServiceInstance("Active"); } + public static void searchExistingServiceInstance(String orchStatus) { + genericSearchExistingServiceInstance(); + SimulatorApi.registerExpectation( + new String [] { + Constants.RegisterToSimulator.SearchForServiceInstance.GET_SUBSCRIBERS_FOR_CUSTOMER_USP_VOICE, + Constants.RegisterToSimulator.SearchForServiceInstance.FILTER_SERVICE_INSTANCE_BY_ID, + Constants.RegisterToSimulator.SearchForServiceInstance.NAMED_QUERY_VIEW_EDIT, + Constants.RegisterToSimulator.SearchForServiceInstance.GET_SDC_CATALOG_SERVICE_VID_TEST_444, + Constants.RegisterToSimulator.CreateNewServiceInstance.deploy.GET_AIC_ZONES + }, ImmutableMap.<String, Object>of("<ORCH_STATUS>", orchStatus), SimulatorApi.RegistrationStrategy.APPEND); + } + + public static void searchExistingServiceInstanceByOEAndProject(){ + SimulatorApi.registerExpectationFromPresets(ImmutableList.of( + new PresetAAIGetModelsByOwningEntity("Wireline"), + new PresetAAIGetModelsByProject("x1"), + new PresetAAIGetModelsByProject("yyy1") + ), APPEND); + } + + public static void searchExistingCRServiceInstance(String orchStatus) { + genericSearchExistingServiceInstance(); + SimulatorApi.registerExpectation( + new String [] { + Constants.RegisterToSimulator.SearchForServiceInstance.GET_SUBSCRIBERS_FOR_CUSTOMER_USP_VOICE_CR, + Constants.RegisterToSimulator.SearchForServiceInstance.FILTER_CR_SERVICE_INSTANCE_BY_ID, + Constants.RegisterToSimulator.SearchForServiceInstance.NAMED_QUERY_CR_VIEW_EDIT, + Constants.RegisterToSimulator.SearchForServiceInstance.GET_SDC_CATALOG_SERVICE_VID_TEST_CR, + Constants.RegisterToSimulator.SearchForServiceInstance.GET_MSO_INSTANCE_ORCH_STATUS_REQ, + Constants.RegisterToSimulator.CreateNewServiceInstance.deploy.GET_AIC_ZONES + }, ImmutableMap.<String, Object>of("<ORCH_STATUS>", orchStatus, "<SERVICE_INSTANCE_ID>", "3f93c7cb-2fd0-4557-9514-e189b7testCR"), SimulatorApi.RegistrationStrategy.APPEND); + } + + public static void searchExistingVFServiceWithVFCInstanceGroupInstance(String orchStatus) { + genericSearchExistingServiceInstance(); + SimulatorApi.registerExpectation( + new String [] { + Constants.RegisterToSimulator.AddSubinterface.GET_SUBSCRIBERS_FOR_CUSTOMER_USP_VOICE_VFC_IG, + Constants.RegisterToSimulator.AddSubinterface.FILTER_VFC_IG_SERVICE_INSTANCE_BY_ID, + Constants.RegisterToSimulator.AddSubinterface.NAMED_QUERY_VFC_IG_VIEW_EDIT, + Constants.RegisterToSimulator.AddSubinterface.GET_SDC_CATALOG_SERVICE_VID_TEST_444, + Constants.RegisterToSimulator.AddSubinterface.GET_MSO_VFC_IG_INSTANCE_ORCH_STATUS_REQ, + }, ImmutableMap.<String, Object>of("<ORCH_STATUS>", orchStatus), SimulatorApi.RegistrationStrategy.APPEND); + } + + public static void genericSearchExistingServiceInstance() { 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 + Constants.RegisterToSimulator.SearchForServiceInstance.GET_SERVICES - }, ImmutableMap.<String, Object>of("<ORCH_STATUS>", orchStatus)); + }, ImmutableMap.<String, Object>of(), SimulatorApi.RegistrationStrategy.APPEND); } public static void searchExistingServiceInstance2(String orchStatus) { + genericSearchExistingServiceInstance(); 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.GET_SUBSCRIBERS_FOR_CUSTOMER_FIREWALL_MISC, Constants.RegisterToSimulator.SearchForServiceInstance.FILTER_SERVICE_INSTANCE_BY_ID_2, Constants.RegisterToSimulator.SearchForServiceInstance.NAMED_QUERY_VIEW_EDIT_2 - }, ImmutableMap.<String, Object>of("<ORCH_STATUS>", orchStatus)); + }, ImmutableMap.<String, Object>of("<ORCH_STATUS>", orchStatus), SimulatorApi.RegistrationStrategy.APPEND); + } + + public static void searchExistingServiceInstancePortMirroring(String orchStatus, String desiredCloudRegionId) { + searchExistingServiceInstancePortMirroring(orchStatus, true, desiredCloudRegionId); + } + + public static void searchExistingServiceInstancePortMirroring(String orchStatus, boolean isMirrored, String desiredCloudRegionId) { + genericSearchExistingServiceInstance(); + final String configurationId = "9533-config-LB1113"; + final String portInterfaceId = "d35bf534-7d8e-4cb4-87f9-0a8bb6cd47b2"; + final String modelToReplaceWith ="pm1111_equip_model_rename.zip"; + + SimulatorApi.registerExpectationFromPreset(new PresetAAICloudRegionAndSourceFromConfigurationPut(configurationId, desiredCloudRegionId), APPEND); + SimulatorApi.registerExpectationFromPreset(new PresetAAIGetPortMirroringSourcePorts(configurationId, portInterfaceId, "i'm a port", isMirrored), APPEND); + SimulatorApi.registerExpectation( + new String [] { + Constants.RegisterToSimulator.SearchForServiceInstance.GET_SUBSCRIBERS_FOR_CUSTOMER_USP_VOICE, + Constants.RegisterToSimulator.SearchForServiceInstance.FILTER_SERVICE_INSTANCE_BY_ID_PM, + Constants.RegisterToSimulator.SearchForServiceInstance.NAMED_QUERY_VIEW_EDIT_PM, + Constants.RegisterToSimulator.SearchForServiceInstance.GET_SDC_CATALOG_SERVICE_PM, + Constants.RegisterToSimulator.CreateNewServiceInstance.deploy.GET_AIC_ZONES + }, ImmutableMap.<String, Object>of( + "<ORCH_STATUS>", orchStatus, "<IS_MIRRORED>", isMirrored, + "pm1111.zip", modelToReplaceWith + ), SimulatorApi.RegistrationStrategy.APPEND); } public static void associatePnf() { @@ -39,7 +113,7 @@ public class BulkRegistration { Constants.RegisterToSimulator.pProbe.GET_SPECIFIC_PNF, Constants.RegisterToSimulator.pProbe.ADD_PNF_RELATIONSHIP, Constants.RegisterToSimulator.pProbe.GET_ADD_PNF_RELATIONSHIP_ORCH_REQ - }, ImmutableMap.<String, Object>of()); + }, ImmutableMap.<String, Object>of(), SimulatorApi.RegistrationStrategy.APPEND); } public static void searchPnfError() { @@ -47,7 +121,7 @@ public class BulkRegistration { new String [] { Constants.RegisterToSimulator.pProbe.GET_SERVICE_INSTANCE_WITH_LOGICAL_LINKS, Constants.RegisterToSimulator.pProbe.GET_SPECIFIC_PNF_ERROR - }, ImmutableMap.<String, Object>of()); + }, ImmutableMap.<String, Object>of(), SimulatorApi.RegistrationStrategy.APPEND); } public static void associatePnfError() { SimulatorApi.registerExpectation( @@ -55,7 +129,7 @@ public class BulkRegistration { Constants.RegisterToSimulator.pProbe.GET_SERVICE_INSTANCE_WITH_LOGICAL_LINKS, Constants.RegisterToSimulator.pProbe.GET_SPECIFIC_PNF, Constants.RegisterToSimulator.pProbe.ADD_PNF_RELATIONSHIP_ERROR - }, ImmutableMap.<String, Object>of()); + }, ImmutableMap.<String, Object>of(), SimulatorApi.RegistrationStrategy.APPEND); } public static void dissociatePnf() { @@ -63,7 +137,7 @@ public class BulkRegistration { new String [] { Constants.RegisterToSimulator.pProbe.REMOVE_PNF_RELATIONSHIP, Constants.RegisterToSimulator.pProbe.GET_REMOVE_PNF_RELATIONSHIP_ORCH_REQ - }, ImmutableMap.<String, Object>of()); + }, ImmutableMap.<String, Object>of(), SimulatorApi.RegistrationStrategy.APPEND); } public static void getAssociatedPnfs() { @@ -71,7 +145,7 @@ public class BulkRegistration { new String [] { Constants.RegisterToSimulator.pProbe.GET_SERVICE_INSTANCE_WITH_LOGICAL_LINKS, Constants.RegisterToSimulator.pProbe.GET_LOGICAL_LINK - }, ImmutableMap.<String, Object>of()); + }, ImmutableMap.<String, Object>of(), SimulatorApi.RegistrationStrategy.APPEND); } public static void activateServiceInstance(String action) { @@ -80,15 +154,234 @@ public class BulkRegistration { Constants.RegisterToSimulator.pProbe.GET_SERVICE_INSTANCE_WITH_LOGICAL_LINKS, Constants.RegisterToSimulator.activateDeactivate.ACTIVATE_SERVICE_INSTANCE, Constants.RegisterToSimulator.activateDeactivate.ACTIVATE_SERVICE_INSTANCE_ORCH_REQUEST - }, ImmutableMap.<String, Object>of("<ACTIVE_ACTION>", action)); + }, ImmutableMap.<String, Object>of("<ACTIVE_ACTION>", action), SimulatorApi.RegistrationStrategy.APPEND); } + + public static void activateDeactivateConfiguration(String orchStatus, String action, String desiredCloudRegionId) { + SimulatorApi.registerExpectation( + new String [] { + Constants.RegisterToSimulator.createConfiguration.MSO_ACTIVATE_CONFIGURATION, + }, ImmutableMap.<String, Object>of("<ACTION>",action,"mdt1", desiredCloudRegionId), SimulatorApi.RegistrationStrategy.APPEND); + } + + public static void deleteConfiguration(String desiredCloudRegionId) { + SimulatorApi.registerExpectation( + new String [] { + Constants.RegisterToSimulator.createConfiguration.MSO_DELETE_CONFIGURATION, + Constants.RegisterToSimulator.createConfiguration.MSO_CREATE_CONFIGURATION_ORCH_REQ + }, ImmutableMap.of("mdt1", desiredCloudRegionId), SimulatorApi.RegistrationStrategy.APPEND); + } + + public static void enableDisablePort(String action, String desiredCloudRegionId){ + SimulatorApi.registerExpectation( + new String [] { + Constants.RegisterToSimulator.createConfiguration.MSO_ACTIVATE_CONFIGURATION, + Constants.RegisterToSimulator.createConfiguration.MSO_ENABLE_DISABLE_PORT, + }, ImmutableMap.<String, Object>of("<ACTION>", action,"mdt1", desiredCloudRegionId), SimulatorApi.RegistrationStrategy.APPEND); + } + + public static void addNetwork() { + SimulatorApi.registerExpectation( + new String [] { + Constants.RegisterToSimulator.SearchForServiceInstance.GET_SUBSCRIBERS_FOR_CUSTOMER_Mobility, + Constants.RegisterToSimulator.addNetwork.AAI_GET_TENANTS, + Constants.RegisterToSimulator.addNetwork.AAI_NAMED_QUERY_FOR_VIEW_EDIT, + Constants.RegisterToSimulator.addNetwork.FILTER_SERVICE_INSTANCE_BY_ID, + //Constants.RegisterToSimulator.addNetwork.FILTER_SERVICE_INSTANCE_BY_NAME, + Constants.RegisterToSimulator.addNetwork.GET_SDC_CATALOG_SERVICES_NETWORK, + + }, ImmutableMap.<String, Object>of(), SimulatorApi.RegistrationStrategy.APPEND); + } + public static void msoAddNetwork(String instanceName){ + SimulatorApi.registerExpectation( + new String [] { + Constants.RegisterToSimulator.addNetwork.MSO_ADD_NETWORK_ORCH_REQ, + Constants.RegisterToSimulator.addNetwork.MSO_ADD_NETWORK + }, ImmutableMap.<String, Object>of("<SERVICE_INSTANCE_NAME>",instanceName), SimulatorApi.RegistrationStrategy.APPEND); + } + public static void msoAddNetworkError(String instanceName){ + SimulatorApi.registerExpectation( + new String [] { + Constants.RegisterToSimulator.addNetwork.MSO_ADD_NETWORK_ERROR + }, ImmutableMap.<String, Object>of("<SERVICE_INSTANCE_NAME>",instanceName), SimulatorApi.RegistrationStrategy.APPEND); + } 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.<String, Object>of("<ACTIVE_ACTION>", action)); + } , ImmutableMap.<String, Object>of("<ACTIVE_ACTION>", action), SimulatorApi.RegistrationStrategy.APPEND); + } + + + public static void createPolicyConfiguration(boolean isSuccessFlow, String desiredCloudRegionId) { + createConfiguration(); + SimulatorApi.registerExpectation( + new String []{ + Constants.RegisterToSimulator.createConfiguration.GET_PNF_INSTANCES, + Constants.RegisterToSimulator.createConfiguration.GET_MODEL_BY_ONE_INVARIANT_ID + } , ImmutableMap.<String, Object>of("mdt1", desiredCloudRegionId), SimulatorApi.RegistrationStrategy.APPEND); + if (isSuccessFlow) { + msoCreatePProbeConfiguration(); + } else { + msoCreatePProbeConfigurationError(); + } + } + + public static void deletePolicyConfiguration(boolean isSuccessFlow, String desiredCloudRegionId) { + createConfiguration(); + SimulatorApi.registerExpectation( + new String []{ + Constants.RegisterToSimulator.createConfiguration.GET_PNF_INSTANCES, + Constants.RegisterToSimulator.createConfiguration.GET_MODEL_BY_ONE_INVARIANT_ID, + Constants.RegisterToSimulator.createConfiguration.MSO_DELETE_CONFIGURATION, + + } , ImmutableMap.<String, Object>of("mdt1", desiredCloudRegionId), SimulatorApi.RegistrationStrategy.APPEND); + if (isSuccessFlow) { + msoCreatePProbeConfiguration(); + } else { + msoCreatePProbeConfigurationError(); + } } + + + + private static void msoCreatePProbeConfiguration() { + SimulatorApi.registerExpectation( + new String []{ + Constants.RegisterToSimulator.createConfiguration.MSO_CREATE_CONFIGURATION, + Constants.RegisterToSimulator.createConfiguration.MSO_CREATE_CONFIGURATION_ORCH_REQ + } , ImmutableMap.<String, Object>of(), SimulatorApi.RegistrationStrategy.APPEND); + } + + private static void msoCreatePProbeConfigurationError() { + SimulatorApi.registerExpectation( + new String []{ + Constants.RegisterToSimulator.createConfiguration.MSO_CREATE_CONFIGURATION_ERROR + } , ImmutableMap.<String, Object>of(), SimulatorApi.RegistrationStrategy.APPEND); + } + + public static void createConfiguration() { + createConfiguration("model-version-id=2a2ea15f-07c6-4b89-bfca-e8aba39a34d6&model-invariant-id=a7eac2b3-8444-40ee-92e3-b3359b32445c"); + } + + public static void createConfiguration(String model) { + SimulatorApi.registerExpectation( + new String []{ + Constants.RegisterToSimulator.createConfiguration.GET_VNF_INSTANCES, + Constants.RegisterToSimulator.createConfiguration.GET_MODEL_BY_2_INVARIANT_IDS + } , ImmutableMap.of("model-version-id=2a2ea15f-07c6-4b89-bfca-e8aba39a34d6&model-invariant-id=a7eac2b3-8444-40ee-92e3-b3359b32445c", model), SimulatorApi.RegistrationStrategy.APPEND); + } + + public static void getNetworkNodeFormData() { + SimulatorApi.registerExpectation( + new String []{ + Constants.RegisterToSimulator.createConfiguration.GET_TENANTS + } , ImmutableMap.<String, Object>of(), SimulatorApi.RegistrationStrategy.APPEND); + } + + public static void createNewServiceInstance(String subscriber) { + SimulatorApi.registerExpectation( + new String []{ + Constants.RegisterToSimulator.CreateNewServiceInstance.GET_FULL_SUBSCRIBES, + Constants.RegisterToSimulator.CreateNewServiceInstance.GET_SERVICES + } , ImmutableMap.<String, Object>of(), SimulatorApi.RegistrationStrategy.APPEND); + + switch (subscriber) { + case "USP VOICE": createNewServiceInstanceUspVoice(); break; + case "MSO_1610_ST": createNewServiceInstanceMso1610ST(); break; + } + } + + private static void createNewServiceInstanceMso1610ST() { + SimulatorApi.registerExpectation( + new String []{ + Constants.RegisterToSimulator.CreateNewServiceInstance.GET_SUBSCRIBERS_FOR_CUSTOMER_MSO_1610_ST, + Constants.RegisterToSimulator.CreateNewServiceInstance.GET_MODELS_BY_SERVICE_TYPE_MSO_1610_ST + } , ImmutableMap.<String, Object>of(), SimulatorApi.RegistrationStrategy.APPEND); + } + + private static void createNewServiceInstanceUspVoice() { + SimulatorApi.registerExpectation( + new String []{ + Constants.RegisterToSimulator.CreateNewServiceInstance.GET_SUBSCRIBERS_FOR_CUSTOMER_USP_VOICE, + Constants.RegisterToSimulator.CreateNewServiceInstance.GET_MODELS_BY_SERVICE_TYPE_USP_VOICE + } , ImmutableMap.<String, Object>of(), SimulatorApi.RegistrationStrategy.APPEND); + } + + public static void deployNewServiceInstance(String instanceName) { + SimulatorApi.registerExpectation( + new String []{ + Constants.RegisterToSimulator.CreateNewServiceInstance.deploy.SDC_GET_CATALOG, + Constants.RegisterToSimulator.CreateNewServiceInstance.deploy.GET_AIC_ZONES, + Constants.RegisterToSimulator.CreateNewServiceInstance.deploy.MSO_CREATE_SVC_INSTANCE, + Constants.RegisterToSimulator.CreateNewServiceInstance.deploy.MSO_CREATE_SVC_INSTANCE_ORCH_REQ + } , ImmutableMap.<String, Object>of("<INSTANCE_NAME>", instanceName), SimulatorApi.RegistrationStrategy.APPEND); + } + + public static void searchExistingServiceInstanceWithoutModelVerId() { + SimulatorApi.registerExpectation( + new String []{ + Constants.RegisterToSimulator.SearchForServiceInstance.GET_SUBSCRIBERS_FOR_CUSTOMER_FIREWALL_MISC, + Constants.RegisterToSimulator.SearchForServiceInstance.FILTER_SERVICE_INSTANCE_BY_ID_NO_MODEL_VER_ID, + // Constants.RegisterToSimulator.SearchForServiceInstance.NAMED_QUERY_VIEW_EDIT_NO_MODEL_VER_ID + } , ImmutableMap.<String, Object>of(), SimulatorApi.RegistrationStrategy.APPEND); + } + + public static void deleteExistingInstance(String orchStatus, String type) { + genericSearchExistingServiceInstance(); + SimulatorApi.registerExpectation( + new String [] { + Constants.RegisterToSimulator.SearchForServiceInstance.GET_SUBSCRIBERS_FOR_CUSTOMER_USP_VOICE, + Constants.RegisterToSimulator.SearchForServiceInstance.NAMED_QUERY_VIEW_EDIT, + Constants.RegisterToSimulator.CreateNewServiceInstance.deploy.GET_AIC_ZONES + }, ImmutableMap.<String, Object>of("<ORCH_STATUS>", orchStatus), SimulatorApi.RegistrationStrategy.APPEND); + SimulatorApi.registerExpectationFromPresets( + ImmutableList.of( + new PresetAAIGetTenants(), + new PresetMSODeleteInstanceOrchestrationRequestGet(type), + new PresetSDCGetServiceMetadataGet("7a6ee536-f052-46fa-aa7e-2fca9d674c44", "e49fbd11-e60c-4a8e-b4bf-30fbe8f4fcc0", "service-Complexservice-aLaCarte-csar.zip"), + new PresetSDCGetServiceToscaModelGet("7a6ee536-f052-46fa-aa7e-2fca9d674c44", "service-Complexservice-aLaCarte-csar.zip")), + SimulatorApi.RegistrationStrategy.APPEND); + } + + public static void deleteExistingVolumeGroupInstance(String orchStatus) { + deleteExistingInstance(orchStatus, "Volume Group"); + SimulatorApi.registerExpectationFromPreset(new PresetMSODeleteVolumeGroup(), SimulatorApi.RegistrationStrategy.APPEND); + } + + public static void deleteExistingVfModuleInstance(String orchStatus) { + deleteExistingInstance(orchStatus, "VF Module"); + SimulatorApi.registerExpectationFromPreset(new PresetMSODeleteVfModule(), SimulatorApi.RegistrationStrategy.APPEND); + } + + public static void deleteExistingVnfInstance(String orchStatus) { + deleteExistingInstance(orchStatus, "Vnf"); + SimulatorApi.registerExpectationFromPreset(new PresetMSODeleteVnf(), SimulatorApi.RegistrationStrategy.APPEND); + } + + public static void deleteExistingNetworkInstance(String orchStatus) { + deleteExistingInstance(orchStatus, "Network"); + SimulatorApi.registerExpectationFromPreset(new PresetMSODeleteNetwork(), SimulatorApi.RegistrationStrategy.APPEND); + } + + public static void deleteExistingServiceInstance(String orchStatus) { + deleteExistingInstance(orchStatus, "Service"); + SimulatorApi.registerExpectationFromPresets(ImmutableList.of( + new PresetMSODeleteService(), + new PresetAAIPostNamedQueryForViewEdit("3f93c7cb-2fd0-4557-9514-e189b7b04f9d", false)), SimulatorApi.RegistrationStrategy.APPEND); + } + + public static void resumeVfModule(String serviceInstanceId, String vnfInstanceId ){ + BulkRegistration.searchExistingServiceInstance(); + SimulatorApi.registerExpectationFromPresets( + ImmutableList.of ( + new PresetAAIGetTenants(), + new PresetMSOCreateVfModuleInstancePost(serviceInstanceId,vnfInstanceId), + new PresetMSOOrchestrationRequestGet("COMPLETE","c0011670-0e1a-4b74-945d-8bf5aede1d9c",Constants.ViewEdit.VF_MODULE_CREATED_SUCCESSFULLY_TEXT)), + SimulatorApi.RegistrationStrategy.APPEND); + + } } diff --git a/vid-automation/src/main/java/vid/automation/test/services/CategoryParamsService.java b/vid-automation/src/main/java/vid/automation/test/services/CategoryParamsService.java new file mode 100644 index 000000000..4fef91fff --- /dev/null +++ b/vid-automation/src/main/java/vid/automation/test/services/CategoryParamsService.java @@ -0,0 +1,90 @@ +package vid.automation.test.services; + +import com.google.common.primitives.Ints; +import vid.automation.test.model.CategoryOption; +import vid.automation.test.model.CategoryOptionList; +import vid.automation.test.utils.DB_CONFIG; +import vid.automation.test.utils.ReadFile; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.List; + +import static org.hamcrest.CoreMatchers.everyItem; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.greaterThan; + +/** + * Created by itzikliderman on 08/09/2017. + */ +public class CategoryParamsService { + private List<CategoryOption> categoryParams; + + public CategoryParamsService() { + categoryParams = getCategoryParamsFromJson(); + categoryParams.forEach(this::prepareCategoryParam); + } + + List<CategoryOption> getCategoryParamsFromJson() { + CategoryOptionList categoryParamsObject = null; + categoryParamsObject = ReadFile.getJsonFile("categoryParams", CategoryOptionList.class); + return categoryParamsObject.categories; + } + + private void prepareCategoryParam(CategoryOption categoryParam) { + /* + Creates a category parameter option in the DB. + */ + + dropCategoryParam(categoryParam); + + System.out.println("Preparing category parameter '" + categoryParam.categoryId + "': " + categoryParam.name); + System.out.println("Connecting database..."); + + try (Connection connection = DriverManager.getConnection(DB_CONFIG.url, DB_CONFIG.username, DB_CONFIG.password)) { + + System.out.println("Database connected!"); + + /////////////////////////////// + // Add category param option + Statement stmt = connection.createStatement(); + + int id = getId(categoryParam.name); + stmt.addBatch("INSERT INTO `vid_category_parameter_option` (`CATEGORY_OPT_DB_ID`, `CATEGORY_OPT_APP_ID`, `NAME`, `CATEGORY_ID`) " + + "VALUES (" + id + ", '" + (categoryParam.appId != null ? categoryParam.appId : categoryParam.name) + "', '" + categoryParam.name + "', '" + categoryParam.categoryId + "') " + + "ON DUPLICATE KEY UPDATE NAME='"+categoryParam.name+"'"); + + int[] executeBatch = stmt.executeBatch(); + assertThat(Ints.asList(executeBatch), everyItem(greaterThan(0))); + + } catch (SQLException e) { + throw new IllegalStateException("Cannot connect the database!", e); + } + + } + + private void dropCategoryParam(CategoryOption categoryParam) { + System.out.println("Dropping categoryParam '" + categoryParam.name + "'"); + System.out.println("Connecting database..."); + + try (Connection connection = DriverManager.getConnection(DB_CONFIG.url, DB_CONFIG.username, DB_CONFIG.password)) { + + System.out.println("Database connected!"); + + Statement stmt = connection.createStatement(); + int id = getId(categoryParam.name); + stmt.addBatch("DELETE FROM `vid_category_parameter_option` WHERE `CATEGORY_OPT_DB_ID` = '" + id + "'"); + int[] executeBatch = stmt.executeBatch(); + + } catch (SQLException e) { + throw new IllegalStateException("Cannot connect the database!", e); + } + } + + private int getId(String id) { + return (Math.abs(id.hashCode()) % 100000) * 1000; + } + +} diff --git a/vid-automation/src/main/java/vid/automation/test/services/DropTestApiField.java b/vid-automation/src/main/java/vid/automation/test/services/DropTestApiField.java new file mode 100644 index 000000000..e175b88b1 --- /dev/null +++ b/vid-automation/src/main/java/vid/automation/test/services/DropTestApiField.java @@ -0,0 +1,64 @@ +package vid.automation.test.services; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; +import vid.automation.test.infra.Features; + +import java.io.IOException; +import java.util.Arrays; +import java.util.function.UnaryOperator; + +public class DropTestApiField { + + public static UnaryOperator<String> dropTestApiFieldFromString() { + if (Features.FLAG_ADD_MSO_TESTAPI_FIELD.isActive()) { + // do nothing + return in -> in; + } else { + final ObjectMapper objectMapper = new ObjectMapper(); + return in -> { + if (!in.contains("testApi")) { + // short circuit + return in; + } + + try { + final JsonNode tree = objectMapper.readTree(in); + final JsonNode node = tree.path("simulatorRequest"); + if (removePath(node, "body", "requestDetails", "requestParameters", "testApi") != null) { + // tree modified, write back to string + return objectMapper.writeValueAsString(tree); + } else { + // else... + return in; + } + } catch (IOException e) { + return in; + } + }; + } + } + + private static JsonNode removePath(JsonNode tree, String... nodes) { + // remove the nodes; remove also the parent, if an empty object was left + // returns the removed node + // returns null if no modification to tree + if (nodes.length > 1) { + final JsonNode node = tree.path(nodes[0]); + final JsonNode removed = removePath(node, Arrays.copyOfRange(nodes, 1, nodes.length)); + if (removed != null && node.size() == 0) { + return removePath(tree, nodes[0]); + } else { + return removed; // non-null if node.size() != 0 + } + } else { + if (tree instanceof ObjectNode) { + return ((ObjectNode) tree).remove(nodes[0]); + } else { + return null; + } + } + } + +} 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 index 39f235b9e..34303a972 100644 --- a/vid-automation/src/main/java/vid/automation/test/services/ServicesService.java +++ b/vid-automation/src/main/java/vid/automation/test/services/ServicesService.java @@ -3,7 +3,10 @@ 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.ServiceModel; +import vid.automation.test.model.ServiceModelsList; import vid.automation.test.model.ServicesObject; +import vid.automation.test.utils.ReadFile; import java.io.File; import java.io.IOException; @@ -14,13 +17,14 @@ import java.util.HashMap; */ public class ServicesService { private HashMap<String, Service> services; + private HashMap<String, ServiceModel> serviceModels; - public ServicesService() throws IOException { + public ServicesService() { services = getServicesFromJson(); - + serviceModels = getServiceInstancesFromJson(); } - HashMap<String, Service> getServicesFromJson() throws IOException { + HashMap<String, Service> getServicesFromJson() { String fileName = "services"; ObjectMapper mapper = new ObjectMapper(); ServicesObject servicesObject; @@ -41,7 +45,15 @@ public class ServicesService { } } + HashMap<String, ServiceModel> getServiceInstancesFromJson() { + return ReadFile.getJsonFile("serviceModels", ServiceModelsList.class).serviceModels; + } + public Service getService(String serviceId) { return services.get(serviceId); } + + public ServiceModel getServiceModel(String modelUUID) { + return (ServiceModel) serviceModels.get(modelUUID); + } } 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 index 95370fc82..74cda7990 100644 --- a/vid-automation/src/main/java/vid/automation/test/services/SimulatorApi.java +++ b/vid-automation/src/main/java/vid/automation/test/services/SimulatorApi.java @@ -1,11 +1,15 @@ package vid.automation.test.services; +import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider; +import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider; +import com.google.common.collect.ImmutableList; 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.opencomp.simulator.presetGenerator.presets.BasePresets.BasePreset; +import org.opencomp.simulator.presetGenerator.presets.model.RegistrationRequest; import org.springframework.http.HttpStatus; +import vid.automation.test.utils.ReadFile; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; @@ -13,86 +17,136 @@ 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.Collection; +import java.util.List; import java.util.Map; +import java.util.function.UnaryOperator; import static org.testng.Assert.assertEquals; +import static vid.automation.test.services.DropTestApiField.dropTestApiFieldFromString; 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 URI uri; //uri for registration + private static final URI simulationUri; //uri for getting simulated responses private static final Client client; + private static final List<UnaryOperator<String>> presetStringPostProccessors = + ImmutableList.of(dropTestApiFieldFromString()); + static { String host = System.getProperty("VID_HOST", "127.0.0.1" ); - Integer port = Integer.valueOf(System.getProperty("VID_PORT", "8080")); + Integer port = Integer.valueOf(System.getProperty("SIM_PORT", System.getProperty("VID_PORT", "8080"))); //port for registration uri = new JerseyUriBuilder().host(host).port(port).scheme("http").path("vidSimulator").build(); client = ClientBuilder.newClient(); client.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true); + //registering jacksonJsonProvider for avoiding exceptions like : + // org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: + // MessageBodyWriter not found for media type=application/json + JacksonJsonProvider jacksonJsonProvider = new JacksonJaxbJsonProvider(); + client.register(jacksonJsonProvider); + + Integer simulationPort = Integer.valueOf(System.getProperty("SIMULATION_PORT", "1080")); //port getting simulated responses + simulationUri = new JerseyUriBuilder().host(host).port(simulationPort).scheme("http").build(); } - public static void registerExpectation(String expectationFilename) { - registerExpectation(expectationFilename, ImmutableMap.<String, Object>of(), RegistrationStrategy.APPEND); + public static URI getSimulationUri() { + return simulationUri; } public static void registerExpectation(String expectationFilename, RegistrationStrategy registrationStrategy) { registerExpectation(expectationFilename, ImmutableMap.<String, Object>of(), registrationStrategy); } - public static void registerExpectation(String expectationTemplateFilename, ImmutableMap<String, Object> templateParams) { - registerExpectation(expectationTemplateFilename, templateParams, RegistrationStrategy.APPEND); - } - - public static void registerExpectation(String... expectationTemplateFilenames) { - registerExpectation(expectationTemplateFilenames, ImmutableMap.of()); + public static void registerExpectation(RegistrationStrategy strategy, String... expectationTemplateFilenames) { + registerExpectation(expectationTemplateFilenames, ImmutableMap.of(), strategy); } - public static void registerExpectation(String[] expectationTemplateFilenames, ImmutableMap<String, Object> templateParams) { + public static void registerExpectation(String[] expectationTemplateFilenames, ImmutableMap<String, Object> templateParams, RegistrationStrategy strategy) { + if (strategy.equals(RegistrationStrategy.CLEAR_THEN_SET)) { + clearRegistrations(); + } for (String expectationTemplateFilename: expectationTemplateFilenames) { - registerExpectation(expectationTemplateFilename, templateParams); + registerExpectation(expectationTemplateFilename, templateParams, RegistrationStrategy.APPEND); } } public static void registerExpectation(String expectationTemplateFilename, ImmutableMap<String, Object> 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"); + String content = ReadFile.loadResourceAsString("registration_to_simulator/" + expectationTemplateFilename); - for (Map.Entry<String, Object> templateParam : templateParams.entrySet()) { - content = content.replaceAll(templateParam.getKey(), templateParam.getValue().toString()); - } + for (Map.Entry<String, Object> templateParam : templateParams.entrySet()) { + content = content.replaceAll(templateParam.getKey(), templateParam.getValue().toString()); + } - registerToSimulatorAndAssertSuccess(content, registrationStrategy); + registerToSimulatorAndAssertSuccess(content, registrationStrategy); - } catch (IOException e) { - logger.error("couldn't read " + expectationTemplateFilename, e); -// throw new RuntimeException("couldn't read " + expectationTemplateFilename, e); + } + + public static void registerExpectationFromPreset(BasePreset preset, RegistrationStrategy registrationStrategy) { + RegistrationRequest content = preset.generateScenario(); + registerToSimulatorAndAssertSuccess(content, registrationStrategy); + } + + public static void registerExpectationFromPresets(Collection<BasePreset> presets, RegistrationStrategy registrationStrategy) { + if (registrationStrategy == RegistrationStrategy.CLEAR_THEN_SET) { + clearRegistrations(); } + presets.forEach( + preset-> { + try {registerToSimulatorAndAssertSuccess(preset.generateScenario());} + catch (RuntimeException e) { + throw new RuntimeException("Failed to register preset "+preset.getClass().getName(), e); + } + } + ); } - private static void registerToSimulatorAndAssertSuccess(String content, RegistrationStrategy registrationStrategy) { - WebTarget webTarget = client.target(uri).path("registerToVidSimulator"); - Response response; + private static void registerToSimulatorAndAssertSuccess(Object content, RegistrationStrategy registrationStrategy) { if (registrationStrategy == RegistrationStrategy.CLEAR_THEN_SET) { - response = webTarget.request().delete(); - assertEquals(response.getStatus(), HttpStatus.OK.value()); + clearRegistrations(); + } + registerToSimulatorAndAssertSuccess(content); + } + + private static void registerToSimulatorAndAssertSuccess(Object content) { + + content = postProccessContent(content); + + Response response = createSimulatorRegistrationWebTarget().request(MediaType.APPLICATION_JSON_TYPE).post(Entity.json(content)); + assertEquals(response.getStatus(), HttpStatus.OK.value()); + } + + private static Object postProccessContent(Object content) { + if (content instanceof String) { + for (UnaryOperator<String> presetStringPostProccessor : presetStringPostProccessors) { + content = presetStringPostProccessor.apply((String) content); + } } - response = webTarget.request(MediaType.APPLICATION_JSON_TYPE).post(Entity.json(content)); + + return content; + } + + public static void clearExpectations() { + clearRegistrations(); + } + + private static void clearRegistrations() { + Response response = createSimulatorRegistrationWebTarget().request().delete(); assertEquals(response.getStatus(), HttpStatus.OK.value()); } + private static WebTarget createSimulatorRegistrationWebTarget() { + return client.target(uri).path("registerToVidSimulator"); + } + public static void clearAll() { - WebTarget webTarget = client.target(uri).path("registerToVidSimulator"); + WebTarget webTarget = createSimulatorRegistrationWebTarget(); 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 index e8df17764..282be9067 100644 --- a/vid-automation/src/main/java/vid/automation/test/services/UsersService.java +++ b/vid-automation/src/main/java/vid/automation/test/services/UsersService.java @@ -1,14 +1,25 @@ package vid.automation.test.services; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.openecomp.sdc.ci.tests.utilities.FileHandling; +import com.att.automation.common.report_portal_integration.annotations.Step; +import com.google.common.primitives.Ints; +import org.apache.commons.lang3.StringUtils; import vid.automation.test.model.User; import vid.automation.test.model.UsersObject; +import vid.automation.test.utils.DB_CONFIG; import vid.automation.test.utils.ReadFile; -import java.io.File; -import java.io.IOException; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.sql.Statement; import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.ListIterator; + +import static org.hamcrest.CoreMatchers.everyItem; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.greaterThan; /** * Created by itzikliderman on 08/09/2017. @@ -16,16 +27,113 @@ import java.util.HashMap; public class UsersService { private HashMap<String, User> users; - public UsersService() throws IOException { + public UsersService() { users = getUsersFromJson(); + users.forEach(this::prepareUser); } - HashMap<String, User> getUsersFromJson() throws IOException { - UsersObject usersObject = ReadFile.getJsonFile("users", UsersObject.class); + HashMap<String, User> getUsersFromJson() { + UsersObject usersObject = null; + usersObject = ReadFile.getJsonFile("users", UsersObject.class); return usersObject.users; } + @Step("${method} with id: ${userId}") public User getUser(String userId) { - return users.get(userId); + User res = users.get(userId); + System.out.println("getUser userId='" + userId + "' returned: " + res); + + if (res == null) { + throw new RuntimeException("user id '" + userId + "' is not defined (these ARE defined: " + users.keySet() + ")"); + } + + return res; } + + + private void prepareUser(String userId, User user) { + /* + Creates a user in the DB, were: + - Login user name is a deterministic number, hashed from the userId string, with 3 trailing zeroes, + and two leading letters from the userId itself; e.g. "mo26063000" for mobility. + - Login user name == user password + - 'user.credentials.userId' and 'user.credentials.password' input fields are overridden with the generated values. + - Roles are "read" (roleId==16) and all other roles in object (like subscriberName___serviceType___tenant). + - Yielded role ids are the successive numbers after the user name. e.g "57174000", "57174001", "57174002". + */ + + dropUser(userId); + + System.out.println("Preparing user '" + userId + "': " + user); + System.out.println("Connecting database..."); + + try (Connection connection = DriverManager.getConnection(DB_CONFIG.url, DB_CONFIG.username, DB_CONFIG.password)) { + + System.out.println("Database connected!"); + + /////////////////////////////// + // Add user with specific roles + Statement stmt = connection.createStatement(); + int userNumber = getUserNumber(userId); + user.credentials.userId = getLoginId(userId); + user.credentials.password = getLoginId(userId); + + stmt.addBatch("INSERT INTO `fn_user` (`USER_ID`, `ORG_USER_ID`, `FIRST_NAME`, `LOGIN_ID`, `LOGIN_PWD`) " + + "VALUES (" + userNumber + ", '" + userId + "', '" + userId + "', '" + user.credentials.userId + "', '" + user.credentials.password + "')"); + + List<String> roles = user.roles != null ? user.roles : new LinkedList<>(); + roles.add("Standard User"); + + ListIterator<String> iter = roles.listIterator(); + while (iter.hasNext()) { + int roleNumber = userNumber + iter.nextIndex(); + + String sql = "INSERT INTO `fn_role` (`ROLE_ID`, `ROLE_NAME`, `ACTIVE_YN`, `PRIORITY`) VALUES (" + roleNumber + ", '" + iter.next() + "', 'Y', " + 5 + ")"; + System.out.println(sql); + stmt.addBatch(sql); + String sql2 = "INSERT INTO `fn_user_role` (`USER_ID`, `ROLE_ID`, `PRIORITY`, `APP_ID`) VALUES (" + userNumber + ", " + roleNumber + ", NULL, 1)"; + System.out.println(sql2); + stmt.addBatch(sql2); + } + stmt.addBatch("INSERT INTO `fn_user_role` (`USER_ID`, `ROLE_ID`, `PRIORITY`, `APP_ID`) VALUES (" + userNumber + ", 16, NULL, 1)"); + + int[] executeBatch = stmt.executeBatch(); + assertThat(Ints.asList(executeBatch), everyItem(greaterThan(0))); + + } catch (SQLException e) { + throw new IllegalStateException("Cannot connect the database!", e); + } + + } + + private void dropUser(String userId) { + System.out.println("Dropping user '" + userId + "'"); + System.out.println("Connecting database..."); + + try (Connection connection = DriverManager.getConnection(DB_CONFIG.url, DB_CONFIG.username, DB_CONFIG.password)) { + + System.out.println("Database connected!"); + + int userNumber = getUserNumber(userId); + Statement stmt = connection.createStatement(); + stmt.addBatch("DELETE FROM `fn_user_role` WHERE `USER_ID` = " + userNumber); + stmt.addBatch("DELETE FROM `fn_role` WHERE `ROLE_ID` BETWEEN " + userNumber + " AND " + (userNumber + 100)); + stmt.addBatch("DELETE FROM `fn_user` WHERE `USER_ID` = " + userNumber); + int[] executeBatch = stmt.executeBatch(); + + } catch (SQLException e) { + throw new IllegalStateException("Cannot connect the database!", e); + } + } + + private int getUserNumber(String userId) { + return (Math.abs(userId.hashCode()) % 100000) * 1000; + } + + private String getLoginId(String userId) { + int userNumber = getUserNumber(userId); + final String twoCharacters = StringUtils.substring(userId,0, 2).toLowerCase(); + return String.format("%s%d", twoCharacters, userNumber); + } + } |