This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository observe. See http://git.codelutin.com/observe.git commit 1668a7b1a9b95f83b4bf3d7cb71e421aff71ed4d Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Aug 23 01:55:57 2015 +0200 Ajout d'une classe avec les méthodes utiles (à finir selon les besoins des tests (See #7466) --- observe-test-data/pom.xml | 5 +- .../main/java/fr/ird/observe/test/TestHelper.java | 246 +++++++++++++++++++++ 2 files changed, 249 insertions(+), 2 deletions(-) diff --git a/observe-test-data/pom.xml b/observe-test-data/pom.xml index a2f175d..a43fad1 100644 --- a/observe-test-data/pom.xml +++ b/observe-test-data/pom.xml @@ -81,8 +81,9 @@ <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> + <scope>compile</scope> </dependency> - <dependency> + <!--dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-jcl</artifactId> <scope>test</scope> @@ -91,7 +92,7 @@ <groupId>log4j</groupId> <artifactId>log4j</artifactId> <scope>test</scope> - </dependency> + </dependency--> </dependencies> diff --git a/observe-test-data/src/main/java/fr/ird/observe/test/TestHelper.java b/observe-test-data/src/main/java/fr/ird/observe/test/TestHelper.java new file mode 100644 index 0000000..dd0cfbf --- /dev/null +++ b/observe-test-data/src/main/java/fr/ird/observe/test/TestHelper.java @@ -0,0 +1,246 @@ +/* + * #%L + * ObServe :: Business + * %% + * Copyright (C) 2008 - 2010 IRD, Codelutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ird.observe.test; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.io.File; +import java.util.Date; + +/** + * @author Tony Chemit - chemit@codelutin.com + */ +public abstract class TestHelper { + + /** Logger */ + private static final Log log = LogFactory.getLog(TestHelper.class); + + static private final String TEST_BASEDIR_PATTERN = "target%1$ssurefire-workdir%1$s%2$td_%2$tm_%2$tY%1$s%2$tH_%2$tM_%2$tS"; + + public static final String TEST_H2_LOGIN = "sa"; + + public static final char[] TEST_H2_PASSWORD = "sa".toCharArray(); + + public static final String TEST_REMOTE_URL = "jdbc:postgresql://localhost/obstuna-test"; +// public static final String TEST_REMOTE_URL = "jdbc:postgresql://demo.codelutin.com/obstuna"; + + public static final String TEST_REMOTE_ADMIN_LOGIN = "admin"; + + public static final String TEST_REMOTE_UTILISATEUR_LOGIN = "utilisateur"; + + public static final String TEST_REMOTE_REFERENTIEL_LOGIN = "referentiel"; + + public static final String[] TEST_REMOTE_TECHNICIENS_LOGIN = {"technicien1", "technicien2", "technicien3"}; + + public static final char[] TEST_REMOTE_PASSWORD = "a".toCharArray(); + + static private Long testsTimeStamp; + + static private File testsBasedir; + + static private File basedir; + + public static File TEST_BASEDIR; + + public static boolean canUsePG; + + public static Class<?> testClass; + +// public static void assertSchemaCreated(DataSource service, boolean noData) { +// +// // on verifie que le schema a bien ete cree +// for (Class<? extends TopiaEntity> c : +// ObserveDAOHelper.getContractClasses()) { +// if (Modifier.isAbstract(c.getModifiers())) { +// continue; +// } +// List<?> r = dataService.getList(service, c); +// Assert.assertNotNull(r); +// if (noData) { +// Assert.assertEquals(0, r.size()); +// } +// } +// } +// +// public static void assertReferentiel(DataSource localService, +// DataSource importService, +// ObserveEntityEnum... empty) +// throws DataSourceException { +// +// try { +// if (importService != null && !importService.isOpen()) { +// importService.doOpen(); +// } +// List<ObserveEntityEnum> observeEntityEnums = +// Arrays.asList(empty); +// // on verifie que le referentiel existe sur la nouvelle base +// for (ObserveEntityEnum constant : +// Entities.REFERENCE_ENTITIES) { +// Class<? extends TopiaEntity> c = constant.getContract(); +// List<?> actual = dataService.getList(localService, c); +// Assert.assertNotNull(actual); +// if (!observeEntityEnums.contains(constant)) { +// // FIXME Remove the empty reference list when all references will be filled +// if (!REFERENCE_TO_FILL.contains(constant)) +// // must not be empty +// Assert.assertFalse("la donnee de type " + c + +// " ne devrait pas etre vide...", +// actual.isEmpty()); +// } +//// Assert.assertFalse(c.getName(), actual.isEmpty()); +// if (importService != null) { +// List<?> expected = dataService.getList(importService, c); +// Assert.assertNotNull(expected); +// Assert.assertEquals(expected.size(), actual.size()); +// } +// } +// } finally { +// if (importService != null) { +// importService.doClose(false); +// } +// } +// } + +// protected static final Set<ObserveEntityEnum> REFERENCE_TO_FILL = Sets.newHashSet( +// Arrays.asList(ObserveEntityEnum.FpaZone, +// ObserveEntityEnum.BaitHaulingStatus, +// ObserveEntityEnum.BaitSettingStatus, +// ObserveEntityEnum.BaitType, +// ObserveEntityEnum.CatchFateLongline, +// ObserveEntityEnum.EncounterType, +// ObserveEntityEnum.Healthness, +// ObserveEntityEnum.HookPosition, +// ObserveEntityEnum.HookSize, +// ObserveEntityEnum.HookType, +// ObserveEntityEnum.ItemVerticalPosition, +// ObserveEntityEnum.ItemHorizontalPosition, +// ObserveEntityEnum.LightsticksColor, +// ObserveEntityEnum.LightsticksType, +// ObserveEntityEnum.LineType, +// ObserveEntityEnum.MaturityStatus, +// ObserveEntityEnum.MitigationType, +// ObserveEntityEnum.SensorBrand, +// ObserveEntityEnum.SensorDataFormat, +// ObserveEntityEnum.SensorType, +// ObserveEntityEnum.SettingShape, +// ObserveEntityEnum.SizeMeasureType, +// ObserveEntityEnum.StomacFullness, +// ObserveEntityEnum.TripType, +// ObserveEntityEnum.VesselActivityLongline, +// ObserveEntityEnum.WeightMeasureType +// )); +// +// public static PGDataSourceConfig createPGConfig(String dbName, +// boolean canMigrate, +// boolean canConnect, +// boolean isvalid) { +// +// PGDataSourceConfig config = DataSourceFactory.newPGConfig( +// dbName, +// TestHelper.TEST_REMOTE_ADMIN_LOGIN, +// TestHelper.TEST_REMOTE_PASSWORD, +// TestHelper.TEST_REMOTE_URL, +// canMigrate +// ); +// +// if (log.isInfoEnabled()) { +// log.info("==== create remotedb config : " + config.getLabel()); +// } +// if (canConnect) { +// Assert.assertEquals(canConnect, config.canConnect()); +// Assert.assertEquals(isvalid, config.isValid()); +// } +// Assert.assertEquals(canMigrate, config.isCanMigrate()); +// +// return config; +// } + + public static Long getTestsTimeStamp() { + if (testsTimeStamp == null) { + testsTimeStamp = System.currentTimeMillis(); + if (log.isInfoEnabled()) { + log.info("tests timestamp : " + testsTimeStamp); + } + } + return testsTimeStamp; + } + + public static File getTestDir(Class<?> testClass) { + if (testsBasedir == null) { + String tmp = System.getProperty("basedir"); + if (tmp == null) { + tmp = new File("").getAbsolutePath(); + } + basedir = new File(tmp); + String name = String.format(TEST_BASEDIR_PATTERN, + File.separator, + new Date(getTestsTimeStamp()) + ); + testsBasedir = new File(new File(tmp), name); + if (log.isInfoEnabled()) { + log.info("tests basedir : " + testsBasedir); + } + } + return new File(testsBasedir, testClass.getSimpleName()); + } + + public static File newLocalDB(String name) { + return new File(TEST_BASEDIR, "localDB_" + name); + } + + public static File getBasedir() { + return basedir; + } + +// public static void setConfig(String key, String value) { +// DefaultApplicationContext context = +// ObserveServiceHelper.get(); +// ApplicationConfig config = +// context.getContextValue(ApplicationConfig.class); +// config.setOption(key, value); +// } +// +// public static void createApplicationContext() { +// +// ObserveServiceHelper.close(); +// ObserveApplicationContext context = new ObserveApplicationContext(); +// ApplicationConfig conf = new ApplicationConfig(); +// context.setContextValue(conf); +// ObserveServiceHelper.set(context); +// } + + public static void initTest(Class<?> testClass) { + TEST_BASEDIR = getTestDir(testClass); + } + +// public static SecurityModel createTestSecurityModel() { +// +// SecurityModel securityModel = new SecurityModel(); +// +// securityModel.setAdministrateur(TEST_REMOTE_ADMIN_LOGIN); +//// securityModel.setRole(Arrays.asList(TEST_REMOTE_TECHNICIENS_LOGIN), SecurityModel.Role.technicien); +// securityModel.setRole(TEST_REMOTE_UTILISATEUR_LOGIN, SecurityModel.Role.utilisateur, false); +// securityModel.setRole(TEST_REMOTE_REFERENTIEL_LOGIN, SecurityModel.Role.referentiel, false); +// return securityModel; +// } +} -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.