diff --git a/arc-core/pom.xml b/arc-core/pom.xml index b1b38e013..a71ff04f1 100644 --- a/arc-core/pom.xml +++ b/arc-core/pom.xml @@ -77,14 +77,6 @@ opencsv 3.9 - - - - org.json - json - ${project.org.json} - - org.mockito diff --git a/arc-core/src/main/java/fr/insee/arc/core/service/p0initialisation/metadata/SynchronizeRulesAndMetadataOperation.java b/arc-core/src/main/java/fr/insee/arc/core/service/p0initialisation/metadata/SynchronizeRulesAndMetadataOperation.java index e0664bc70..e4377b91c 100644 --- a/arc-core/src/main/java/fr/insee/arc/core/service/p0initialisation/metadata/SynchronizeRulesAndMetadataOperation.java +++ b/arc-core/src/main/java/fr/insee/arc/core/service/p0initialisation/metadata/SynchronizeRulesAndMetadataOperation.java @@ -90,8 +90,7 @@ private void copyMetadataToSandbox() throws ArcException { /** * Instanciate the metadata required into all executors pod - * - * @param envExecution + * @return number of executor pod * @throws ArcException */ protected int copyMetadataToExecutorsAllNods() throws ArcException { diff --git a/arc-core/src/test/java/fr/insee/arc/core/service/engine/initialisation/BddPatcherTest.java b/arc-core/src/test/java/fr/insee/arc/core/service/engine/initialisation/BddPatcherTest.java index 3bbbe92c8..ac9369516 100644 --- a/arc-core/src/test/java/fr/insee/arc/core/service/engine/initialisation/BddPatcherTest.java +++ b/arc-core/src/test/java/fr/insee/arc/core/service/engine/initialisation/BddPatcherTest.java @@ -247,6 +247,15 @@ public void retrieveRulesTablesFromSchemaTest() throws ArcException { assertEquals(4, result.size()); result = BddPatcher.retrieveModelTablesFromSchema(c, testSandbox3); + assertTrue(result.contains("arc.ihm_famille")); + assertTrue(result.contains("arc.ihm_mod_table_metier")); + assertTrue(result.contains("arc.ihm_mod_variable_metier")); + assertEquals(3, result.size()); + + result = BddPatcher.retrieveMappingTablesFromSchema(c, testSandbox3); + assertTrue(result.contains(testSandbox3+".mapping_dsn_employeur_ok")); + assertEquals(1, result.size()); + u.executeImmediate(c, "DROP SCHEMA IF EXISTS "+testSandbox3+" CASCADE;"); diff --git a/arc-core/src/test/java/fr/insee/arc/core/service/p0initialisation/metadata/SynchronizeUserRulesAndMetadataTest.java b/arc-core/src/test/java/fr/insee/arc/core/service/p0initialisation/metadata/SynchronizeUserRulesAndMetadataTest.java index 06710b06f..9661a810c 100644 --- a/arc-core/src/test/java/fr/insee/arc/core/service/p0initialisation/metadata/SynchronizeUserRulesAndMetadataTest.java +++ b/arc-core/src/test/java/fr/insee/arc/core/service/p0initialisation/metadata/SynchronizeUserRulesAndMetadataTest.java @@ -33,6 +33,7 @@ public void copyMetadataToExecutorsTestScalable() throws SQLException, ArcExcept int result=synchronizationInstance.copyMetadataToExecutorsAllNods(); // copy should be a success + // return that there is 1 executor nod assertEquals(1, result); u.executeImmediate(c, "DROP SCHEMA IF EXISTS "+BddPatcherTest.testSandbox3+" CASCADE;"); diff --git a/arc-utils/src/main/java/fr/insee/arc/utils/dao/UtilitaireDao.java b/arc-utils/src/main/java/fr/insee/arc/utils/dao/UtilitaireDao.java index 5ac55ca29..cb4981527 100644 --- a/arc-utils/src/main/java/fr/insee/arc/utils/dao/UtilitaireDao.java +++ b/arc-utils/src/main/java/fr/insee/arc/utils/dao/UtilitaireDao.java @@ -35,6 +35,7 @@ import fr.insee.arc.utils.exception.ArcException; import fr.insee.arc.utils.exception.ArcExceptionMessage; import fr.insee.arc.utils.files.CompressedUtils; +import fr.insee.arc.utils.ressourceUtils.ConnectionAttribute; import fr.insee.arc.utils.ressourceUtils.PropertiesHandler; import fr.insee.arc.utils.structure.GenericBean; import fr.insee.arc.utils.textUtils.IConstanteCaractere; @@ -53,9 +54,6 @@ public class UtilitaireDao implements IConstanteNumerique, IConstanteCaractere { private static final Logger LOGGER = LogManager.getLogger(UtilitaireDao.class); - public static final String CONNECTION_SEPARATOR_RAW = "|||"; - private static final String CONNECTION_SEPARATOR = "\\|\\|\\|"; - /** * execute request returns a table with headers, type and data provide the * indexes of these elements @@ -90,20 +88,8 @@ public static final UtilitaireDao get(Integer aPool) { * @return */ public int numberOfNods() { - return numberOfNods(properties.getDatabaseUsername()); + return properties.getConnectionProperties().size(); } - - /** - * Compute the number of element split ||| . See regexp - * {@value #CONNECTION_SEPARATOR} - * - * @param databaseUserName - * @return - */ - public static int numberOfNods(String databaseUserName) { - return databaseUserName.split(CONNECTION_SEPARATOR).length; - } - /** return a valid connection index according to the given connection in properties * @param aPool @@ -130,10 +116,11 @@ public final Connection getDriverConnexion() throws ArcException { int validConnectionIndex=validConnectionIndex(this.pool); - String driver = properties.getDatabaseDriverClassName().split(CONNECTION_SEPARATOR)[validConnectionIndex]; - String uri = properties.getDatabaseUrl().split(CONNECTION_SEPARATOR)[validConnectionIndex]; - String user = properties.getDatabaseUsername().split(CONNECTION_SEPARATOR)[validConnectionIndex]; - String password = properties.getDatabasePassword().split(CONNECTION_SEPARATOR)[validConnectionIndex]; + ConnectionAttribute currentConnectionAttributes = properties.getConnectionProperties().get(validConnectionIndex); + String driver = currentConnectionAttributes.getDatabaseDriverClassName(); + String uri = currentConnectionAttributes.getDatabaseUrl(); + String user = currentConnectionAttributes.getDatabaseUsername(); + String password = currentConnectionAttributes.getDatabasePassword(); Class.forName(driver); Connection c = null; diff --git a/arc-utils/src/main/java/fr/insee/arc/utils/ressourceUtils/ConnectionAttribute.java b/arc-utils/src/main/java/fr/insee/arc/utils/ressourceUtils/ConnectionAttribute.java new file mode 100644 index 000000000..71cf216fc --- /dev/null +++ b/arc-utils/src/main/java/fr/insee/arc/utils/ressourceUtils/ConnectionAttribute.java @@ -0,0 +1,112 @@ +package fr.insee.arc.utils.ressourceUtils; + +import java.util.ArrayList; +import java.util.List; + +import org.json.JSONObject; + +public class ConnectionAttribute { + + private String databaseUrl; + private String databaseUsername; + private String databasePassword; + private String databaseDriverClassName; + + public ConnectionAttribute(String databaseUrl, String databaseUsername, String databasePassword, + String databaseDriverClassName) { + super(); + this.databaseUrl = databaseUrl; + this.databaseUsername = databaseUsername; + this.databasePassword = databasePassword; + this.databaseDriverClassName = databaseDriverClassName; + } + + + + /** + * Ruby map from ci/cd : {0=>"zzz"},{1=>"xxxx"},{2=>"pass\"ji\""} + * No ruby parser in java :( + * Change string to json {0:"zzz",1:"xxxx",2:"pass\"ji\""} to be parsable in java + * replace },{ by , + * replace => by : + * then cast to json + * @param rubyMapToken + * @return + */ + + public static String[] unserialize(String rubyMapToken) + { + // the rubyMapToken must begin with starString or it is not an expected rubyMapToken + String startString = "{0=>"; + if (!rubyMapToken.startsWith(startString)) + { + // it is not a ruby map key, no parsing required, return the provided string + return new String[] {rubyMapToken}; + } + + String inputToken = "{0:" + rubyMapToken.substring(startString.length()); + + // transform ruby in json to parse that correctly + // replace },{ by , + // replace => by : + int numberOfToken=1; + for (int tokenId=1; tokenId < Integer.MAX_VALUE; tokenId++) + { + String toFind="\"},{"+tokenId+"=>\""; + if (inputToken.contains(toFind)) + { + inputToken = inputToken.replace(toFind, "\","+tokenId+":\""); + } + else + { + numberOfToken= numberOfToken + tokenId -1; + break; + } + } + + // cast to json + JSONObject parsedMapTokens = new JSONObject(inputToken); + + // extract tokens + List resultToken = new ArrayList<>(); + for (int tokenId=0; tokenId < numberOfToken; tokenId++) + { + resultToken.add(parsedMapTokens.getString(tokenId+"")); + } + + return resultToken.toArray(new String[0]); + + } + + + + + public String getDatabaseUrl() { + return databaseUrl; + } + public void setDatabaseUrl(String databaseUrl) { + this.databaseUrl = databaseUrl; + } + public String getDatabaseUsername() { + return databaseUsername; + } + public void setDatabaseUsername(String databaseUsername) { + this.databaseUsername = databaseUsername; + } + public String getDatabasePassword() { + return databasePassword; + } + public void setDatabasePassword(String databasePassword) { + this.databasePassword = databasePassword; + } + public String getDatabaseDriverClassName() { + return databaseDriverClassName; + } + public void setDatabaseDriverClassName(String databaseDriverClassName) { + this.databaseDriverClassName = databaseDriverClassName; + } + + + + +} diff --git a/arc-utils/src/main/java/fr/insee/arc/utils/ressourceUtils/PropertiesHandler.java b/arc-utils/src/main/java/fr/insee/arc/utils/ressourceUtils/PropertiesHandler.java index 00785b442..a26d8444e 100644 --- a/arc-utils/src/main/java/fr/insee/arc/utils/ressourceUtils/PropertiesHandler.java +++ b/arc-utils/src/main/java/fr/insee/arc/utils/ressourceUtils/PropertiesHandler.java @@ -1,7 +1,8 @@ package fr.insee.arc.utils.ressourceUtils; - +import java.util.ArrayList; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import org.springframework.stereotype.Component; @@ -12,307 +13,270 @@ @Component("properties") public class PropertiesHandler { - - /* Database */ - private String databasePoolName; - private String databaseRestrictedUsername; - private String databaseUrl; - private String databaseUsername; - private String databasePassword; - private String databaseDriverClassName; - private String databaseSchema; - /* Authentication directory */ - private String ldapDirectoryUri; - private String ldapDirectoryIdent; - private String ldapDirectoryPassword; - /* Log */ - private String logDirectory; - private String logLevel; - private String logFileName; - private String logConfiguration; - /* Batch */ - private String batchParametersDirectory; - private String batchExecutionEnvironment; - /* Miscellaneous */ - private String version; - private String versionDate; - private String application; - private String tn; - /* Directories */ - private String registrationDirectory; - private String loadingDirectory; - private String storageDirectory; - - private String authorizedRoles; - private String disableDebugGui; - - private String gitCommitId; - - private static PropertiesHandler instanceOfPropertiesHandler; - - - public void initializeLog() { - LogConfigurator logConf = new LogConfigurator(logConfiguration); - - // if logDirectory (fr.insee.arc.log.directory) is set - if (logDirectory != null && !logDirectory.trim().isEmpty()) { - logConf.configureRollingFileAppender(logDirectory, logFileName); - } - - if (logLevel != null && !logLevel.trim().isEmpty()) { - logConf.configureLogLevel(logLevel); - } - } - - - public static PropertiesHandler getInstance() { - if (instanceOfPropertiesHandler==null) - { - try { - instanceOfPropertiesHandler= (PropertiesHandler) SpringApplicationContext.getBean("properties"); - } catch( NullPointerException e ) { - ArcException ex= new ArcException(ArcExceptionMessage.SPRING_BEAN_PROPERTIES_NOTFOUND); - ex.logMessageException(); - // create a blank instance singleton - instanceOfPropertiesHandler=new PropertiesHandler(); - } - } - return instanceOfPropertiesHandler; - } - - - public String getDatabasePoolName() { - return databasePoolName; - } - - - public void setDatabasePoolName(String databasePoolName) { - this.databasePoolName = databasePoolName; - } - - - public String getDatabaseUrl() { - return databaseUrl; - } - - public void setDatabaseUrl(String databaseUrl) { - this.databaseUrl = databaseUrl; - } + /* Database */ + private String databasePoolName; + private String databaseRestrictedUsername; + private String databaseUrl; + private String databaseUsername; + private String databasePassword; + private String databaseDriverClassName; + private String databaseSchema; + + /** + * List of connection attributes + */ + private List connectionProperties; + + /* Authentication directory */ + private String ldapDirectoryUri; + private String ldapDirectoryIdent; + private String ldapDirectoryPassword; + /* Log */ + private String logDirectory; + private String logLevel; + private String logFileName; + private String logConfiguration; + /* Batch */ + private String batchParametersDirectory; + private String batchExecutionEnvironment; + /* Miscellaneous */ + private String version; + private String versionDate; + private String application; + private String tn; + /* Directories */ + private String registrationDirectory; + private String loadingDirectory; + private String storageDirectory; + + private String authorizedRoles; + private String disableDebugGui; + + private String gitCommitId; + + private static PropertiesHandler instanceOfPropertiesHandler; + public void initializeLog() { + LogConfigurator logConf = new LogConfigurator(logConfiguration); - public String getDatabaseUsername() { - return databaseUsername; - } - - - public void setDatabaseUsername(String databaseUsername) { - this.databaseUsername = databaseUsername; - } - - - public String getDatabasePassword() { - return databasePassword; - } - + // if logDirectory (fr.insee.arc.log.directory) is set + if (logDirectory != null && !logDirectory.trim().isEmpty()) { + logConf.configureRollingFileAppender(logDirectory, logFileName); + } - public void setDatabasePassword(String databasePassword) { - this.databasePassword = databasePassword; - } + if (logLevel != null && !logLevel.trim().isEmpty()) { + logConf.configureLogLevel(logLevel); + } + } + public static PropertiesHandler getInstance() { + if (instanceOfPropertiesHandler == null) { + try { + instanceOfPropertiesHandler = (PropertiesHandler) SpringApplicationContext.getBean("properties"); + } catch (NullPointerException e) { + ArcException ex = new ArcException(ArcExceptionMessage.SPRING_BEAN_PROPERTIES_NOTFOUND); + ex.logMessageException(); + // create a blank instance singleton + instanceOfPropertiesHandler = new PropertiesHandler(); + } + } + return instanceOfPropertiesHandler; + } - public String getDatabaseDriverClassName() { - return databaseDriverClassName; - } + public String getDatabasePoolName() { + return databasePoolName; + } + public void setDatabasePoolName(String databasePoolName) { + this.databasePoolName = databasePoolName; + } - public void setDatabaseDriverClassName(String databaseDriverClassName) { - this.databaseDriverClassName = databaseDriverClassName; - } + public String getDatabaseUrl() { + return databaseUrl; + } + public void setDatabaseUrl(String databaseUrl) { + this.databaseUrl = databaseUrl; + } - public String getDatabaseSchema() { - return databaseSchema; - } + public String getDatabaseUsername() { + return databaseUsername; + } + public void setDatabaseUsername(String databaseUsername) { + this.databaseUsername = databaseUsername; + } - public void setDatabaseSchema(String databaseSchema) { - this.databaseSchema = databaseSchema; - } + public String getDatabasePassword() { + return databasePassword; + } - - public boolean isLdapActive() { - return !ldapDirectoryUri.isEmpty(); - } - - public String getLdapApplicatioName() { - if (ldapDirectoryIdent.isEmpty()){ - return ""; - } - return ldapDirectoryIdent.substring("appli_".length()); - } + public void setDatabasePassword(String databasePassword) { + this.databasePassword = databasePassword; + } - public String getLdapDirectoryUri() { - return ldapDirectoryUri; - } + public String getDatabaseDriverClassName() { + return databaseDriverClassName; + } + public void setDatabaseDriverClassName(String databaseDriverClassName) { + this.databaseDriverClassName = databaseDriverClassName; + } - public void setLdapDirectoryUri(String ldapDirectoryUri) { - this.ldapDirectoryUri = ldapDirectoryUri; - } + public String getDatabaseSchema() { + return databaseSchema; + } + public void setDatabaseSchema(String databaseSchema) { + this.databaseSchema = databaseSchema; + } - public String getLdapDirectoryIdent() { - return ldapDirectoryIdent; - } + public boolean isLdapActive() { + return !ldapDirectoryUri.isEmpty(); + } + public String getLdapApplicatioName() { + if (ldapDirectoryIdent.isEmpty()) { + return ""; + } + return ldapDirectoryIdent.substring("appli_".length()); + } - public void setLdapDirectoryIdent(String ldapDirectoryIdent) { - this.ldapDirectoryIdent = ldapDirectoryIdent; - } + public String getLdapDirectoryUri() { + return ldapDirectoryUri; + } + public void setLdapDirectoryUri(String ldapDirectoryUri) { + this.ldapDirectoryUri = ldapDirectoryUri; + } - public String getLdapDirectoryPassword() { - return ldapDirectoryPassword; - } + public String getLdapDirectoryIdent() { + return ldapDirectoryIdent; + } + public void setLdapDirectoryIdent(String ldapDirectoryIdent) { + this.ldapDirectoryIdent = ldapDirectoryIdent; + } - public void setLdapDirectoryPassword(String ldapDirectoryPassword) { - this.ldapDirectoryPassword = ldapDirectoryPassword; - } + public String getLdapDirectoryPassword() { + return ldapDirectoryPassword; + } + public void setLdapDirectoryPassword(String ldapDirectoryPassword) { + this.ldapDirectoryPassword = ldapDirectoryPassword; + } public String getLogDirectory() { return logDirectory; } - public void setLogDirectory(String logDirectory) { this.logDirectory = logDirectory; } - - - public String getLogLevel() { + + public String getLogLevel() { return logLevel; } - public void setLogLevel(String logLevel) { this.logLevel = logLevel; } - public String getLogFileName() { return logFileName; } - public void setLogFileName(String logFileName) { this.logFileName = logFileName; } - public String getLogConfiguration() { - return logConfiguration; - } - - - public void setLogConfiguration(String logConfiguration) { - this.logConfiguration = logConfiguration; - initializeLog(); - } - - - public String getBatchParametersDirectory() { - return batchParametersDirectory; - } - + return logConfiguration; + } - public void setBatchParametersDirectory(String batchParametersDirectory) { - this.batchParametersDirectory = batchParametersDirectory; - } + public void setLogConfiguration(String logConfiguration) { + this.logConfiguration = logConfiguration; + initializeLog(); + } + public String getBatchParametersDirectory() { + return batchParametersDirectory; + } - public String getBatchExecutionEnvironment() { - return batchExecutionEnvironment; - } + public void setBatchParametersDirectory(String batchParametersDirectory) { + this.batchParametersDirectory = batchParametersDirectory; + } + public String getBatchExecutionEnvironment() { + return batchExecutionEnvironment; + } - public void setBatchExecutionEnvironment(String batchExecutionEnvironment) { - this.batchExecutionEnvironment = batchExecutionEnvironment; - } + public void setBatchExecutionEnvironment(String batchExecutionEnvironment) { + this.batchExecutionEnvironment = batchExecutionEnvironment; + } - public String getVersion() { - return version; - } + public String getVersion() { + return version; + } + public void setVersion(String version) { + this.version = ManipString.substringAfterFirst(version, "version-"); + } - public void setVersion(String version) { - this.version = ManipString.substringAfterFirst(version, "version-"); - } - - public String getVersionDate() { + public String getVersionDate() { return versionDate; } - - public void setVersionDate(String versionDate) { + + public void setVersionDate(String versionDate) { this.versionDate = versionDate; } + public String getApplication() { + return application; + } - public String getApplication() { - return application; - } - - - public void setApplication(String application) { - this.application = application; - } - - - public String getTn() { - return tn; - } - - - public void setTn(String tn) { - this.tn = tn; - } - - public String getRegistrationDirectory() { - return registrationDirectory; - } + public void setApplication(String application) { + this.application = application; + } + public String getTn() { + return tn; + } - public void setRegistrationDirectory(String registrationDirectory) { - this.registrationDirectory = registrationDirectory; - } + public void setTn(String tn) { + this.tn = tn; + } + public String getRegistrationDirectory() { + return registrationDirectory; + } - public String getLoadingDirectory() { - return loadingDirectory; - } + public void setRegistrationDirectory(String registrationDirectory) { + this.registrationDirectory = registrationDirectory; + } + public String getLoadingDirectory() { + return loadingDirectory; + } - public void setLoadingDirectory(String loadingDirectory) { - this.loadingDirectory = loadingDirectory; - } + public void setLoadingDirectory(String loadingDirectory) { + this.loadingDirectory = loadingDirectory; + } + public String getStorageDirectory() { + return storageDirectory; + } - public String getStorageDirectory() { - return storageDirectory; - } + public void setStorageDirectory(String storageDirectory) { + this.storageDirectory = storageDirectory; + } + public void setAuthorizedRoles(String authorizedRoles) { + this.authorizedRoles = authorizedRoles; + } - public void setStorageDirectory(String storageDirectory) { - this.storageDirectory = storageDirectory; - } - - public void setAuthorizedRoles(String authorizedRoles) { - this.authorizedRoles = authorizedRoles; - } - - public String[] getAuthorizedRoles() { + public String[] getAuthorizedRoles() { if (authorizedRoles == null || authorizedRoles.isEmpty()) { return new String[0]; } @@ -335,19 +299,16 @@ public void setDisableDebugGui(String disableDebugGui) { this.disableDebugGui = disableDebugGui; } - public String getGitCommitId() { return gitCommitId; } - public void setGitCommitId(String gitCommitId) { this.gitCommitId = gitCommitId; } - - public Map fullVersionInformation() - { - Map map = new LinkedHashMap<>(); + + public Map fullVersionInformation() { + Map map = new LinkedHashMap<>(); map.put("version", getVersion()); map.put("buildDate", getVersionDate()); map.put("gitCommitId", getGitCommitId()); @@ -355,5 +316,37 @@ public Map fullVersionInformation() map.put("databaseUserName", getDatabaseUsername()); return map; } - + + + /** + * Unserialize the connection data found in properties + * + * @return + */ + public List getConnectionProperties() { + + if (this.connectionProperties == null) { + connectionProperties = new ArrayList<>(); + + String[] databaseUrls = ConnectionAttribute.unserialize(this.databaseUrl); + String[] databaseUsernames = ConnectionAttribute.unserialize(this.databaseUsername); + String[] databasePasswords = ConnectionAttribute.unserialize(this.databasePassword); + String[] databaseDriverClassNames = ConnectionAttribute.unserialize(this.databaseDriverClassName); + + for (int tokenIndex = 0; tokenIndex < databaseUrls.length; tokenIndex++) { + connectionProperties + .add(new ConnectionAttribute(databaseUrls[tokenIndex], databaseUsernames[tokenIndex], + databasePasswords[tokenIndex], databaseDriverClassNames[tokenIndex])); + } + } + + return this.connectionProperties; + } + + public void setConnectionProperties(List connectionProperties) { + this.connectionProperties = connectionProperties; + } + + + } diff --git a/arc-utils/src/test/java/fr/insee/arc/utils/query/InitializeQueryTest.java b/arc-utils/src/test/java/fr/insee/arc/utils/query/InitializeQueryTest.java index 38c2da614..c7272f770 100644 --- a/arc-utils/src/test/java/fr/insee/arc/utils/query/InitializeQueryTest.java +++ b/arc-utils/src/test/java/fr/insee/arc/utils/query/InitializeQueryTest.java @@ -48,42 +48,45 @@ protected static void buildProperties(String repertoire, Connection[] connection { PropertiesHandler testProperties=PropertiesHandler.getInstance(); - boolean first=true; + // reset connection properties + testProperties.setConnectionProperties(null); + StringBuilder url=new StringBuilder(); StringBuilder username=new StringBuilder(); StringBuilder password=new StringBuilder(); StringBuilder driver=new StringBuilder(); + int index=0; for (Connection singleConnection:connections) { - if (first) - { - first=false; - } - else - { - url.append(UtilitaireDao.CONNECTION_SEPARATOR_RAW); - username.append(UtilitaireDao.CONNECTION_SEPARATOR_RAW); - password.append(UtilitaireDao.CONNECTION_SEPARATOR_RAW); - driver.append(UtilitaireDao.CONNECTION_SEPARATOR_RAW); - } - url.append(singleConnection.getMetaData().getURL()); - username.append(singleConnection.getMetaData().getUserName()); + url.append(buildRuby(index,singleConnection.getMetaData().getURL())); + username.append(buildRuby(index,singleConnection.getMetaData().getUserName())); // user password is not relevant in zonky - password.append("NA"); - driver.append("org.postgresql.Driver"); + password.append(buildRuby(index,"NA")); + driver.append(buildRuby(index,"org.postgresql.Driver")); + index ++; } + url.setLength(url.length()-1); + username.setLength(username.length()-1); + password.setLength(password.length()-1); + driver.setLength(driver.length()-1); + testProperties.setDatabaseUrl(url.toString()); testProperties.setDatabaseUsername(username.toString()); testProperties.setDatabasePassword(password.toString()); testProperties.setDatabaseDriverClassName(driver.toString()); - + testProperties.setBatchParametersDirectory(repertoire); u.setProperties(testProperties); } + + private static String buildRuby(int index, String inputString) + { + return "{"+index+"=>\""+inputString+"\"},"; + } /** * check the table columns and the number of lines in the table diff --git a/arc-utils/src/test/java/fr/insee/arc/utils/ressourceUtils/ConnectionAttributeTest.java b/arc-utils/src/test/java/fr/insee/arc/utils/ressourceUtils/ConnectionAttributeTest.java new file mode 100644 index 000000000..06f3bb393 --- /dev/null +++ b/arc-utils/src/test/java/fr/insee/arc/utils/ressourceUtils/ConnectionAttributeTest.java @@ -0,0 +1,31 @@ +package fr.insee.arc.utils.ressourceUtils; + +import static org.junit.Assert.*; + +import java.util.Arrays; +import java.util.List; + +import org.junit.Test; + +public class ConnectionAttributeTest { + + @Test + public void testUnserialize() { + List zz; + + zz = Arrays.asList(ConnectionAttribute.unserialize("{0=>\"zzz\"},{1=>\"xxxx\"}")); + assertTrue(zz.contains("zzz")); + assertTrue(zz.contains("xxxx")); + assertEquals(2, zz.size()); + + zz = Arrays.asList(ConnectionAttribute.unserialize("{0=>\"zzz\"}")); + assertTrue(zz.contains("zzz")); + assertEquals(1, zz.size()); + + zz = Arrays.asList(ConnectionAttribute.unserialize("zzz=>")); + assertTrue(zz.contains("zzz=>")); + assertEquals(1, zz.size()); + + } + +} diff --git a/pom.xml b/pom.xml index 61432d51f..710b85ca6 100644 --- a/pom.xml +++ b/pom.xml @@ -290,6 +290,13 @@ 2.8.0 + + + org.json + json + ${project.org.json} + + io.zonky.test embedded-postgres