Tony CHEMIT pushed to branch develop at ultreiaio / ird-t3
Commits:
-
179ad7bb
by Tony CHEMIT at 2018-03-23T15:01:26Z
10 changed files:
- t3-actions/src/main/java/fr/ird/t3/FakeT3ServiceContext.java
- t3-domain/pom.xml
- t3-domain/src/main/java/fr/ird/t3/entities/cache/WeightCategoryTreatmentCache.java
- t3-domain/src/main/java/fr/ird/t3/entities/cache/ZoneStratumCache.java
- t3-domain/src/main/java/fr/ird/t3/entities/reference/AbstractOceanTopiaDao.java
- t3-domain/src/main/java/fr/ird/t3/test/T3H2Database.java
- t3-domain/src/main/resources/db/migration/V2_1_09_fill-Harbour-ocean.sql
- + t3-domain/src/test/java/fr/ird/t3/entities/cache/WeightCategoryTreatmentCacheTest.java
- + t3-domain/src/test/java/fr/ird/t3/entities/cache/ZoneStratumCacheTest.java
- t3-domain/src/test/java/fr/ird/t3/entities/reference/OceanTopiaDaoPgTest.java
Changes:
| ... | ... | @@ -21,28 +21,16 @@ |
| 21 | 21 |
package fr.ird.t3;
|
| 22 | 22 |
|
| 23 | 23 |
import fr.ird.t3.entities.T3TopiaApplicationContext;
|
| 24 |
-import fr.ird.t3.entities.T3TopiaApplicationContextBuilder;
|
|
| 25 | 24 |
import fr.ird.t3.entities.T3TopiaPersistenceContext;
|
| 26 | 25 |
import fr.ird.t3.entities.user.T3Users;
|
| 27 | 26 |
import fr.ird.t3.services.T3Service;
|
| 28 | 27 |
import fr.ird.t3.services.T3ServiceContext;
|
| 29 | 28 |
import fr.ird.t3.services.T3ServiceFactory;
|
| 30 |
-import org.apache.commons.logging.Log;
|
|
| 31 |
-import org.apache.commons.logging.LogFactory;
|
|
| 32 |
-import org.junit.Assume;
|
|
| 33 |
-import org.junit.rules.TestRule;
|
|
| 34 |
-import org.junit.runner.Description;
|
|
| 35 |
-import org.junit.runners.model.Statement;
|
|
| 36 |
-import org.mockito.Mockito;
|
|
| 29 |
+import fr.ird.t3.test.T3H2Database;
|
|
| 37 | 30 |
import org.nuiton.topia.persistence.TopiaException;
|
| 38 |
-import org.nuiton.util.FileUtil;
|
|
| 39 |
-import org.nuiton.version.Version;
|
|
| 40 | 31 |
|
| 41 |
-import java.io.Closeable;
|
|
| 42 |
-import java.io.File;
|
|
| 43 | 32 |
import java.util.Date;
|
| 44 | 33 |
import java.util.Locale;
|
| 45 |
-import java.util.Properties;
|
|
| 46 | 34 |
import java.util.function.Supplier;
|
| 47 | 35 |
|
| 48 | 36 |
/**
|
| ... | ... | @@ -51,25 +39,19 @@ import java.util.function.Supplier; |
| 51 | 39 |
* @author Tony Chemit - dev@tchemit.fr
|
| 52 | 40 |
* @since 1.1.1
|
| 53 | 41 |
*/
|
| 54 |
-public class FakeT3ServiceContext implements TestRule, T3ServiceContext, Closeable {
|
|
| 55 |
- |
|
| 56 |
- private static final Log log = LogFactory.getLog(FakeT3ServiceContext.class);
|
|
| 42 |
+public class FakeT3ServiceContext extends T3H2Database implements T3ServiceContext {
|
|
| 57 | 43 |
|
| 58 | 44 |
private final T3ServiceFactory serviceFactory = new T3ServiceFactory();
|
| 59 |
- private final boolean injectReferential;
|
|
| 60 | 45 |
protected T3TopiaPersistenceContext transaction;
|
| 61 |
- private T3TopiaApplicationContext rootContext;
|
|
| 62 |
- private File testDir;
|
|
| 63 |
- private T3Config applicationConfiguration;
|
|
| 64 | 46 |
private Locale locale;
|
| 65 |
- private boolean initOk;
|
|
| 47 |
+ |
|
| 66 | 48 |
|
| 67 | 49 |
public FakeT3ServiceContext() {
|
| 68 | 50 |
this(false);
|
| 69 | 51 |
}
|
| 70 | 52 |
|
| 71 | 53 |
public FakeT3ServiceContext(boolean injectReferential) {
|
| 72 |
- this.injectReferential = injectReferential;
|
|
| 54 |
+ super(injectReferential);
|
|
| 73 | 55 |
setLocale(Locale.FRANCE);
|
| 74 | 56 |
}
|
| 75 | 57 |
|
| ... | ... | @@ -78,10 +60,6 @@ public class FakeT3ServiceContext implements TestRule, T3ServiceContext, Closeab |
| 78 | 60 |
return null;
|
| 79 | 61 |
}
|
| 80 | 62 |
|
| 81 |
- public boolean isInitOk() {
|
|
| 82 |
- return initOk;
|
|
| 83 |
- }
|
|
| 84 |
- |
|
| 85 | 63 |
/** May be used in test to get a fresh transaction. */
|
| 86 | 64 |
@Override
|
| 87 | 65 |
public Supplier<T3TopiaPersistenceContext> getT3TopiaPersistenceContext() {
|
| ... | ... | @@ -90,11 +68,11 @@ public class FakeT3ServiceContext implements TestRule, T3ServiceContext, Closeab |
| 90 | 68 |
|
| 91 | 69 |
@Override
|
| 92 | 70 |
public T3TopiaApplicationContext getApplicationContext() {
|
| 93 |
- return rootContext;
|
|
| 71 |
+ return topiaApplicationContext;
|
|
| 94 | 72 |
}
|
| 95 | 73 |
|
| 96 |
- public T3TopiaPersistenceContext newTransaction() throws TopiaException {
|
|
| 97 |
- return rootContext.newPersistenceContext();
|
|
| 74 |
+ private T3TopiaPersistenceContext newTransaction() throws TopiaException {
|
|
| 75 |
+ return topiaApplicationContext.newPersistenceContext();
|
|
| 98 | 76 |
}
|
| 99 | 77 |
|
| 100 | 78 |
@Override
|
| ... | ... | @@ -108,11 +86,6 @@ public class FakeT3ServiceContext implements TestRule, T3ServiceContext, Closeab |
| 108 | 86 |
}
|
| 109 | 87 |
|
| 110 | 88 |
@Override
|
| 111 |
- public T3Config getApplicationConfiguration() {
|
|
| 112 |
- return applicationConfiguration;
|
|
| 113 |
- }
|
|
| 114 |
- |
|
| 115 |
- @Override
|
|
| 116 | 89 |
public T3ServiceFactory getServiceFactory() {
|
| 117 | 90 |
return serviceFactory;
|
| 118 | 91 |
}
|
| ... | ... | @@ -132,58 +105,4 @@ public class FakeT3ServiceContext implements TestRule, T3ServiceContext, Closeab |
| 132 | 105 |
return new Date();
|
| 133 | 106 |
}
|
| 134 | 107 |
|
| 135 |
- public File getTestDir() {
|
|
| 136 |
- return testDir;
|
|
| 137 |
- }
|
|
| 138 |
- |
|
| 139 |
- private void starting(Description description) {
|
|
| 140 |
- testDir = T3IOUtil.getTestSpecificDirectory(description.getTestClass(), description.getMethodName());
|
|
| 141 |
- log.info(String.format("Test dir = %s", testDir));
|
|
| 142 |
- Properties defaultProps = new Properties();
|
|
| 143 |
- defaultProps.put(T3ConfigOption.DATA_DIRECTORY.getKey(), testDir);
|
|
| 144 |
- File treatmentDirectory = new File(testDir, "treatment");
|
|
| 145 |
- FileUtil.createDirectoryIfNecessary(treatmentDirectory);
|
|
| 146 |
- T3Config realConfiguration = new T3Config(defaultProps) {
|
|
| 147 |
- @Override
|
|
| 148 |
- public void init() {
|
|
| 149 |
- parse();
|
|
| 150 |
- }
|
|
| 151 |
- };
|
|
| 152 |
- realConfiguration.init();
|
|
| 153 |
- Version t3DataVersion = realConfiguration.getT3DataVersion();
|
|
| 154 |
- applicationConfiguration = Mockito.mock(T3Config.class);
|
|
| 155 |
- Mockito.when(applicationConfiguration.getDataDirectory()).thenReturn(testDir);
|
|
| 156 |
- Mockito.when(applicationConfiguration.getTreatmentWorkingDirectory()).thenReturn(treatmentDirectory);
|
|
| 157 |
- Mockito.when(applicationConfiguration.getT3DataVersion()).thenReturn(t3DataVersion);
|
|
| 158 |
- Mockito.when(applicationConfiguration.getTreatmentWorkingDirectory(Mockito.anyString(), Mockito.anyBoolean())).thenCallRealMethod();
|
|
| 159 |
- Mockito.when(applicationConfiguration.getApplicationVersion()).thenReturn(realConfiguration.getApplicationVersion());
|
|
| 160 |
- rootContext = T3TopiaApplicationContextBuilder.forH2Referential(testDir.toPath(), injectReferential ? t3DataVersion : null).build();
|
|
| 161 |
- }
|
|
| 162 |
- |
|
| 163 |
- @Override
|
|
| 164 |
- public void close() {
|
|
| 165 |
- if (transaction != null) {
|
|
| 166 |
- transaction.close();
|
|
| 167 |
- }
|
|
| 168 |
- }
|
|
| 169 |
- |
|
| 170 |
- @Override
|
|
| 171 |
- public Statement apply(Statement base, Description description) {
|
|
| 172 |
- return new Statement() {
|
|
| 173 |
- @Override
|
|
| 174 |
- public void evaluate() throws Throwable {
|
|
| 175 |
- try {
|
|
| 176 |
- starting(description);
|
|
| 177 |
- initOk=true;
|
|
| 178 |
- } catch (Exception e) {
|
|
| 179 |
- Assume.assumeNoException("Can't start test: " + e.getMessage(), e);
|
|
| 180 |
- }
|
|
| 181 |
- try {
|
|
| 182 |
- base.evaluate();
|
|
| 183 |
- } finally {
|
|
| 184 |
- close();
|
|
| 185 |
- }
|
|
| 186 |
- }
|
|
| 187 |
- };
|
|
| 188 |
- }
|
|
| 189 | 108 |
}
|
| ... | ... | @@ -178,6 +178,12 @@ |
| 178 | 178 |
<!--we have a test api in source-->
|
| 179 | 179 |
<scope>provided</scope>
|
| 180 | 180 |
</dependency>
|
| 181 |
+ <dependency>
|
|
| 182 |
+ <groupId>org.mockito</groupId>
|
|
| 183 |
+ <artifactId>mockito-core</artifactId>
|
|
| 184 |
+ <!--We don't want to create yet another module for tests, so just embedded them inside sources-->
|
|
| 185 |
+ <scope>provided</scope>
|
|
| 186 |
+ </dependency>
|
|
| 181 | 187 |
|
| 182 | 188 |
<dependency>
|
| 183 | 189 |
<groupId>com.h2database</groupId>
|
| ... | ... | @@ -56,24 +56,29 @@ public class WeightCategoryTreatmentCache { |
| 56 | 56 |
return forOceanAndSchoolType(activity.getOcean(), activity.getSchoolType());
|
| 57 | 57 |
}
|
| 58 | 58 |
|
| 59 |
- private List<WeightCategoryTreatment> forOceanAndSchoolType(Ocean ocean, SchoolType schoolType) {
|
|
| 59 |
+ List<WeightCategoryTreatment> forOceanAndSchoolType(Ocean ocean, SchoolType schoolType) {
|
|
| 60 | 60 |
String key = ocean.getLabel1() + "#" + schoolType.getLabel1();
|
| 61 |
- List<WeightCategoryTreatment> weightCategoryTreatments = cache.get(key);
|
|
| 62 |
- if (weightCategoryTreatments == null) {
|
|
| 63 |
- weightCategoryTreatments = dao.forOceanEquals(ocean).addEquals(WeightCategoryTreatment.PROPERTY_SCHOOL_TYPE, schoolType).findAll();
|
|
| 64 |
- WeightCategories.sort(weightCategoryTreatments);
|
|
| 65 |
- cache.putAll(key, weightCategoryTreatments);
|
|
| 61 |
+ List<WeightCategoryTreatment> result;
|
|
| 62 |
+ if (cache.containsKey(key)) {
|
|
| 63 |
+ result = cache.get(key);
|
|
| 64 |
+ } else {
|
|
| 65 |
+ result = dao.forOceanEquals(ocean).addEquals(WeightCategoryTreatment.PROPERTY_SCHOOL_TYPE, schoolType).findAll();
|
|
| 66 |
+ WeightCategories.sort(result);
|
|
| 67 |
+ cache.putAll(key, result);
|
|
| 68 |
+ log.info(String.format("Cache WeightCategoryTreatment [%d] for %s (%d categories)", cache.keySet().size(), key, result.size()));
|
|
| 66 | 69 |
}
|
| 67 |
- return weightCategoryTreatments;
|
|
| 70 |
+ return result;
|
|
| 68 | 71 |
}
|
| 69 | 72 |
|
| 70 | 73 |
public List<WeightCategoryTreatment> forOceansAndSchoolType(Collection<Ocean> oceans, SchoolType schoolType) {
|
| 71 | 74 |
String key = Joiner.on("#").join(oceans.stream().map(Ocean::getLabel1).collect(Collectors.toList())) + "#" + schoolType.getLabel1();
|
| 72 |
- List<WeightCategoryTreatment> result = cache.get(key);
|
|
| 73 |
- if (result == null) {
|
|
| 75 |
+ List<WeightCategoryTreatment> result;
|
|
| 76 |
+ if (cache.containsKey(key)) {
|
|
| 77 |
+ result = cache.get(key);
|
|
| 78 |
+ } else {
|
|
| 74 | 79 |
result = dao.forOceanIn(oceans).addEquals(WeightCategoryTreatment.PROPERTY_SCHOOL_TYPE, schoolType).findAll();
|
| 75 | 80 |
WeightCategories.sort(result);
|
| 76 |
- log.info(String.format("Cache WeightCategoryTreatment [%d] for %s (%d categories)", cache.size(), key, result.size()));
|
|
| 81 |
+ log.info(String.format("Cache WeightCategoryTreatment [%d] for %s (%d categories)", cache.keySet().size(), key, result.size()));
|
|
| 77 | 82 |
cache.putAll(key, result);
|
| 78 | 83 |
}
|
| 79 | 84 |
return result;
|
| 1 | 1 |
package fr.ird.t3.entities.cache;
|
| 2 | 2 |
|
| 3 |
+/*-
|
|
| 4 |
+ * #%L
|
|
| 5 |
+ * T3 :: Domain
|
|
| 6 |
+ * %%
|
|
| 7 |
+ * Copyright (C) 2010 - 2018 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
+ * %%
|
|
| 9 |
+ * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
+ * it under the terms of the GNU Affero General Public License as published by
|
|
| 11 |
+ * the Free Software Foundation, either version 3 of the License, or
|
|
| 12 |
+ * (at your option) any later version.
|
|
| 13 |
+ *
|
|
| 14 |
+ * This program is distributed in the hope that it will be useful,
|
|
| 15 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
+ * GNU General Public License for more details.
|
|
| 18 |
+ *
|
|
| 19 |
+ * You should have received a copy of the GNU Affero General Public License
|
|
| 20 |
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
| 21 |
+ * #L%
|
|
| 22 |
+ */
|
|
| 23 |
+ |
|
| 3 | 24 |
import com.google.common.base.Joiner;
|
| 4 | 25 |
import com.google.common.collect.ArrayListMultimap;
|
| 5 | 26 |
import fr.ird.t3.entities.T3TopiaPersistenceContext;
|
| ... | ... | @@ -39,10 +60,12 @@ public class ZoneStratumCache { |
| 39 | 60 |
|
| 40 | 61 |
public List<ZoneStratumAware> forOceansAndSchoolType(Collection<Ocean> oceans, SchoolType schoolType) {
|
| 41 | 62 |
String key = Joiner.on("#").join(oceans.stream().map(Ocean::getLabel1).collect(Collectors.toList())) + "#" + schoolType.getLabel1();
|
| 42 |
- List<ZoneStratumAware> result = cache.get(key);
|
|
| 43 |
- if (result == null) {
|
|
| 63 |
+ List<ZoneStratumAware> result;
|
|
| 64 |
+ if (cache.containsKey(key)) {
|
|
| 65 |
+ result = cache.get(key);
|
|
| 66 |
+ } else {
|
|
| 44 | 67 |
result = zoneMeta.getZones(oceans, schoolType, zoneVersion, persistenceContext);
|
| 45 |
- log.info(String.format("Cache Zone [%d] for %s (%d zones)", cache.size(), key, result.size()));
|
|
| 68 |
+ log.info(String.format("Cache Zone [%d] for %s (%d zones)", cache.keySet().size(), key, result.size()));
|
|
| 46 | 69 |
cache.putAll(key, result);
|
| 47 | 70 |
}
|
| 48 | 71 |
return result;
|
| ... | ... | @@ -84,7 +84,7 @@ public class AbstractOceanTopiaDao<E extends Ocean> extends GeneratedOceanTopiaD |
| 84 | 84 |
public PreparedStatement prepareQuery(Connection connection) throws SQLException {
|
| 85 | 85 |
@SuppressWarnings("SqlResolve")
|
| 86 | 86 |
PreparedStatement ps = connection.prepareStatement(
|
| 87 |
- String.format("SELECT o.topiaid FROM %s a, Ocean o WHERE a.topiaId = ? AND ST_Contains(o.the_geom, a.%s)", tableName, geoColumnName));
|
|
| 87 |
+ String.format("SELECT o.topiaid FROM %s a, Ocean o WHERE a.topiaId = ? AND ST_DWithin(a.the_geom, o.%s, 1)", tableName, geoColumnName));
|
|
| 88 | 88 |
ps.setString(1, id);
|
| 89 | 89 |
return ps;
|
| 90 | 90 |
}
|
| ... | ... | @@ -21,18 +21,27 @@ package fr.ird.t3.test; |
| 21 | 21 |
* #L%
|
| 22 | 22 |
*/
|
| 23 | 23 |
|
| 24 |
+import fr.ird.t3.T3Config;
|
|
| 25 |
+import fr.ird.t3.T3ConfigOption;
|
|
| 24 | 26 |
import fr.ird.t3.T3IOUtil;
|
| 25 | 27 |
import fr.ird.t3.entities.T3EntityHelper;
|
| 26 | 28 |
import fr.ird.t3.entities.T3TopiaApplicationContext;
|
| 27 | 29 |
import fr.ird.t3.entities.T3TopiaApplicationContextBuilder;
|
| 28 | 30 |
import fr.ird.t3.entities.T3TopiaPersistenceContext;
|
| 29 |
-import org.junit.rules.TestWatcher;
|
|
| 31 |
+import org.junit.Assume;
|
|
| 32 |
+import org.junit.rules.TestRule;
|
|
| 30 | 33 |
import org.junit.runner.Description;
|
| 34 |
+import org.junit.runners.model.Statement;
|
|
| 35 |
+import org.mockito.Mockito;
|
|
| 31 | 36 |
import org.nuiton.topia.persistence.TopiaException;
|
| 37 |
+import org.nuiton.util.FileUtil;
|
|
| 38 |
+import org.nuiton.version.Version;
|
|
| 32 | 39 |
|
| 40 |
+import java.io.Closeable;
|
|
| 33 | 41 |
import java.io.File;
|
| 34 | 42 |
import java.io.IOException;
|
| 35 | 43 |
import java.io.InputStream;
|
| 44 |
+import java.util.Properties;
|
|
| 36 | 45 |
|
| 37 | 46 |
/**
|
| 38 | 47 |
* A new database created for each test.
|
| ... | ... | @@ -40,21 +49,48 @@ import java.io.InputStream; |
| 40 | 49 |
* @author Tony Chemit - dev@tchemit.fr
|
| 41 | 50 |
* @since 1.0
|
| 42 | 51 |
*/
|
| 43 |
-public class T3H2Database extends TestWatcher {
|
|
| 52 |
+public class T3H2Database implements TestRule, Closeable {
|
|
| 44 | 53 |
|
| 54 |
+ private final boolean injectReferential;
|
|
| 45 | 55 |
private File testBasedir;
|
| 56 |
+ protected T3TopiaApplicationContext topiaApplicationContext;
|
|
| 57 |
+ private T3Config applicationConfiguration;
|
|
| 58 |
+ private boolean initOk;
|
|
| 59 |
+ public T3H2Database() {
|
|
| 60 |
+ this(false);
|
|
| 61 |
+ }
|
|
| 46 | 62 |
|
| 47 |
- private T3TopiaApplicationContext topiaApplicationContext;
|
|
| 63 |
+ public T3H2Database(boolean injectReferential) {
|
|
| 64 |
+ this.injectReferential = injectReferential;
|
|
| 65 |
+ }
|
|
| 48 | 66 |
|
| 49 |
- @Override
|
|
| 50 |
- protected void starting(Description description) {
|
|
| 67 |
+ private void starting(Description description) {
|
|
| 51 | 68 |
testBasedir = T3IOUtil.getTestSpecificDirectory(description.getTestClass(), description.getMethodName());
|
| 52 |
- topiaApplicationContext = T3TopiaApplicationContextBuilder.forH2(testBasedir.toPath()).build();
|
|
| 53 |
- }
|
|
| 54 | 69 |
|
| 55 |
- @Override
|
|
| 56 |
- public void finished(Description description) {
|
|
| 57 |
- T3EntityHelper.releaseRootContext(topiaApplicationContext);
|
|
| 70 |
+ Properties defaultProps = new Properties();
|
|
| 71 |
+ defaultProps.put(T3ConfigOption.DATA_DIRECTORY.getKey(), testBasedir);
|
|
| 72 |
+ File treatmentDirectory = new File(testBasedir, "treatment");
|
|
| 73 |
+ FileUtil.createDirectoryIfNecessary(treatmentDirectory);
|
|
| 74 |
+ T3Config realConfiguration = new T3Config(defaultProps) {
|
|
| 75 |
+ @Override
|
|
| 76 |
+ public void init() {
|
|
| 77 |
+ parse();
|
|
| 78 |
+ }
|
|
| 79 |
+ };
|
|
| 80 |
+ realConfiguration.init();
|
|
| 81 |
+ Version t3DataVersion = realConfiguration.getT3DataVersion();
|
|
| 82 |
+ applicationConfiguration = Mockito.mock(T3Config.class);
|
|
| 83 |
+ Mockito.when(applicationConfiguration.getDataDirectory()).thenReturn(testBasedir);
|
|
| 84 |
+ Mockito.when(applicationConfiguration.getTreatmentWorkingDirectory()).thenReturn(treatmentDirectory);
|
|
| 85 |
+ Mockito.when(applicationConfiguration.getT3DataVersion()).thenReturn(t3DataVersion);
|
|
| 86 |
+ Mockito.when(applicationConfiguration.getTreatmentWorkingDirectory(Mockito.anyString(), Mockito.anyBoolean())).thenCallRealMethod();
|
|
| 87 |
+ Mockito.when(applicationConfiguration.getApplicationVersion()).thenReturn(realConfiguration.getApplicationVersion());
|
|
| 88 |
+ |
|
| 89 |
+ if (injectReferential) {
|
|
| 90 |
+ topiaApplicationContext = T3TopiaApplicationContextBuilder.forH2Referential(testBasedir.toPath(), t3DataVersion).build();
|
|
| 91 |
+ } else {
|
|
| 92 |
+ topiaApplicationContext = T3TopiaApplicationContextBuilder.forH2(testBasedir.toPath()).build();
|
|
| 93 |
+ }
|
|
| 58 | 94 |
}
|
| 59 | 95 |
|
| 60 | 96 |
public T3TopiaPersistenceContext beginTransaction() throws TopiaException {
|
| ... | ... | @@ -69,7 +105,43 @@ public class T3H2Database extends TestWatcher { |
| 69 | 105 |
}
|
| 70 | 106 |
}
|
| 71 | 107 |
|
| 108 |
+ @SuppressWarnings("unused")
|
|
| 72 | 109 |
public File getTestBasedir() {
|
| 73 | 110 |
return testBasedir;
|
| 74 | 111 |
}
|
| 112 |
+ |
|
| 113 |
+ public T3Config getApplicationConfiguration() {
|
|
| 114 |
+ return applicationConfiguration;
|
|
| 115 |
+ }
|
|
| 116 |
+ |
|
| 117 |
+ @Override
|
|
| 118 |
+ public void close() {
|
|
| 119 |
+ if (topiaApplicationContext != null) {
|
|
| 120 |
+ T3EntityHelper.releaseRootContext(topiaApplicationContext);
|
|
| 121 |
+ }
|
|
| 122 |
+ }
|
|
| 123 |
+ |
|
| 124 |
+ @Override
|
|
| 125 |
+ public Statement apply(Statement base, Description description) {
|
|
| 126 |
+ return new Statement() {
|
|
| 127 |
+ @Override
|
|
| 128 |
+ public void evaluate() throws Throwable {
|
|
| 129 |
+ try {
|
|
| 130 |
+ starting(description);
|
|
| 131 |
+ initOk=true;
|
|
| 132 |
+ } catch (Exception e) {
|
|
| 133 |
+ Assume.assumeNoException("Can't start test: " + e.getMessage(), e);
|
|
| 134 |
+ }
|
|
| 135 |
+ try {
|
|
| 136 |
+ base.evaluate();
|
|
| 137 |
+ } finally {
|
|
| 138 |
+ close();
|
|
| 139 |
+ }
|
|
| 140 |
+ }
|
|
| 141 |
+ };
|
|
| 142 |
+ }
|
|
| 143 |
+ |
|
| 144 |
+ public boolean isInitOk() {
|
|
| 145 |
+ return initOk;
|
|
| 146 |
+ }
|
|
| 75 | 147 |
}
|
| ... | ... | @@ -53,3 +53,27 @@ UPDATE Harbour SET ocean='fr.ird.t3.entities.reference.Ocean#1297580528924#0.024 |
| 53 | 53 |
UPDATE Harbour SET ocean='fr.ird.t3.entities.reference.Ocean#1297580528924#0.02462443299831396' WHERE topiaId = 'fr.ird.t3.entities.reference.Harbour#1297580528933#0.4894751387384305';
|
| 54 | 54 |
UPDATE Harbour SET ocean='fr.ird.t3.entities.reference.Ocean#1297580528924#0.02462443299831396' WHERE topiaId = 'fr.ird.t3.entities.reference.Harbour#1297580528934#0.17822915599428157';
|
| 55 | 55 |
UPDATE Harbour SET ocean='fr.ird.t3.entities.reference.Ocean#1297580528924#0.02462443299831396' WHERE topiaId = 'fr.ird.t3.entities.reference.Harbour#1297580528932#0.21164070994041773';
|
| 56 |
+ |
|
| 57 |
+UPDATE Harbour SET ocean ='fr.ird.t3.entities.reference.Ocean#1297580528924#0.4917298410119624' WHERE topiaId ='fr.ird.t3.entities.reference.Harbour#1297580528930#0.09848580496276282';
|
|
| 58 |
+UPDATE Harbour SET ocean ='fr.ird.t3.entities.reference.Ocean#1297580528924#0.4917298410119624' WHERE topiaId ='fr.ird.t3.entities.reference.Harbour#1297580528930#0.4358849181824964';
|
|
| 59 |
+UPDATE Harbour SET ocean ='fr.ird.t3.entities.reference.Ocean#1297580528924#0.4917298410119624' WHERE topiaId ='fr.ird.t3.entities.reference.Harbour#1297580528930#0.5213952546445324';
|
|
| 60 |
+UPDATE Harbour SET ocean ='fr.ird.t3.entities.reference.Ocean#1297580528924#0.4917298410119624' WHERE topiaId ='fr.ird.t3.entities.reference.Harbour#1297580528932#0.05217800949850426';
|
|
| 61 |
+UPDATE Harbour SET ocean ='fr.ird.t3.entities.reference.Ocean#1297580528924#0.4917298410119624' WHERE topiaId ='fr.ird.t3.entities.reference.Harbour#1297580528932#0.09458236901561745';
|
|
| 62 |
+UPDATE Harbour SET ocean ='fr.ird.t3.entities.reference.Ocean#1297580528924#0.4917298410119624' WHERE topiaId ='fr.ird.t3.entities.reference.Harbour#1464000000000#0.00115115';
|
|
| 63 |
+UPDATE Harbour SET ocean ='fr.ird.t3.entities.reference.Ocean#1297580528924#0.4917298410119624' WHERE topiaId ='fr.ird.t3.entities.reference.Harbour#1464000000000#0.00116116';
|
|
| 64 |
+UPDATE Harbour SET ocean ='fr.ird.t3.entities.reference.Ocean#1297580528924#0.4917298410119624' WHERE topiaId ='fr.ird.t3.entities.reference.Harbour#1464000000000#0.00117117';
|
|
| 65 |
+UPDATE Harbour SET ocean ='fr.ird.t3.entities.reference.Ocean#1297580528924#0.4917298410119624' WHERE topiaId ='fr.ird.t3.entities.reference.Harbour#1297580528935#0.5032524703497515';
|
|
| 66 |
+UPDATE Harbour SET ocean ='fr.ird.t3.entities.reference.Ocean#1297580528924#0.4917298410119624' WHERE topiaId ='fr.ird.t3.entities.reference.Harbour#1297580528930#0.3128607487452171';
|
|
| 67 |
+UPDATE Harbour SET ocean ='fr.ird.t3.entities.reference.Ocean#1297580528924#0.4917298410119624' WHERE topiaId ='fr.ird.t3.entities.reference.Harbour#1297580528930#0.7077375683910743';
|
|
| 68 |
+UPDATE Harbour SET ocean ='fr.ird.t3.entities.reference.Ocean#1297580528924#0.4917298410119624' WHERE topiaId ='fr.ird.t3.entities.reference.Harbour#1297580528930#0.37146946328714225';
|
|
| 69 |
+UPDATE Harbour SET ocean ='fr.ird.t3.entities.reference.Ocean#1297580528924#0.4917298410119624' WHERE topiaId ='fr.ird.t3.entities.reference.Harbour#1297580528930#0.1776110119020825';
|
|
| 70 |
+UPDATE Harbour SET ocean ='fr.ird.t3.entities.reference.Ocean#1297580528924#0.4917298410119624' WHERE topiaId ='fr.ird.t3.entities.reference.Harbour#1297580528930#0.10672736119748483';
|
|
| 71 |
+UPDATE Harbour SET ocean ='fr.ird.t3.entities.reference.Ocean#1297580528924#0.4917298410119624' WHERE topiaId ='fr.ird.t3.entities.reference.Harbour#1297580528929#0.29263430155373604';
|
|
| 72 |
+UPDATE Harbour SET ocean ='fr.ird.t3.entities.reference.Ocean#1297580528924#0.4917298410119624' WHERE topiaId ='fr.ird.t3.entities.reference.Harbour#1297580528932#0.23227601066196246';
|
|
| 73 |
+UPDATE Harbour SET ocean ='fr.ird.t3.entities.reference.Ocean#1297580528924#0.4917298410119624' WHERE topiaId ='fr.ird.t3.entities.reference.Harbour#1297580528934#0.5223852489420004';
|
|
| 74 |
+UPDATE Harbour SET ocean ='fr.ird.t3.entities.reference.Ocean#1297580528924#0.4917298410119624' WHERE topiaId ='fr.ird.t3.entities.reference.Harbour#1297580528929#0.037238377699795766';
|
|
| 75 |
+UPDATE Harbour SET ocean ='fr.ird.t3.entities.reference.Ocean#1297580528924#0.4917298410119624' WHERE topiaId ='fr.ird.t3.entities.reference.Harbour#1297580528934#0.9698949751160373';
|
|
| 76 |
+UPDATE Harbour SET ocean ='fr.ird.t3.entities.reference.Ocean#1297580528924#0.4917298410119624' WHERE topiaId ='fr.ird.t3.entities.reference.Harbour#1297580528933#0.2600646486222412';
|
|
| 77 |
+UPDATE Harbour SET ocean ='fr.ird.t3.entities.reference.Ocean#1297580528924#0.4917298410119624' WHERE topiaId ='fr.ird.t3.entities.reference.Harbour#1297580528934#0.35235641408050444';
|
|
| 78 |
+UPDATE Harbour SET ocean ='fr.ird.t3.entities.reference.Ocean#1297580528924#0.4917298410119624' WHERE topiaId ='fr.ird.t3.entities.reference.Harbour#1297580528934#0.45885264373047663';
|
|
| 79 |
+UPDATE Harbour SET ocean ='fr.ird.t3.entities.reference.Ocean#1297580528924#0.4917298410119624' WHERE topiaId ='fr.ird.t3.entities.reference.Harbour#1460000000000#0.19';
|
| 1 |
+package fr.ird.t3.entities.cache;
|
|
| 2 |
+ |
|
| 3 |
+/*-
|
|
| 4 |
+ * #%L
|
|
| 5 |
+ * T3 :: Domain
|
|
| 6 |
+ * %%
|
|
| 7 |
+ * Copyright (C) 2010 - 2018 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
+ * %%
|
|
| 9 |
+ * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
+ * it under the terms of the GNU Affero General Public License as published by
|
|
| 11 |
+ * the Free Software Foundation, either version 3 of the License, or
|
|
| 12 |
+ * (at your option) any later version.
|
|
| 13 |
+ *
|
|
| 14 |
+ * This program is distributed in the hope that it will be useful,
|
|
| 15 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
+ * GNU General Public License for more details.
|
|
| 18 |
+ *
|
|
| 19 |
+ * You should have received a copy of the GNU Affero General Public License
|
|
| 20 |
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
| 21 |
+ * #L%
|
|
| 22 |
+ */
|
|
| 23 |
+ |
|
| 24 |
+import com.google.common.collect.ImmutableSet;
|
|
| 25 |
+import fr.ird.t3.entities.T3TopiaPersistenceContext;
|
|
| 26 |
+import fr.ird.t3.entities.reference.Ocean;
|
|
| 27 |
+import fr.ird.t3.entities.reference.SchoolType;
|
|
| 28 |
+import fr.ird.t3.entities.reference.WeightCategoryTreatment;
|
|
| 29 |
+import fr.ird.t3.test.T3H2Database;
|
|
| 30 |
+import org.junit.Assert;
|
|
| 31 |
+import org.junit.Before;
|
|
| 32 |
+import org.junit.ClassRule;
|
|
| 33 |
+import org.junit.Test;
|
|
| 34 |
+ |
|
| 35 |
+import java.util.List;
|
|
| 36 |
+import java.util.Set;
|
|
| 37 |
+ |
|
| 38 |
+/**
|
|
| 39 |
+ * Created by tchemit on 23/03/2018.
|
|
| 40 |
+ *
|
|
| 41 |
+ * @author Tony Chemit - dev@tchemit.fr
|
|
| 42 |
+ */
|
|
| 43 |
+public class WeightCategoryTreatmentCacheTest {
|
|
| 44 |
+ |
|
| 45 |
+ @ClassRule
|
|
| 46 |
+ public static final T3H2Database db = new T3H2Database(true);
|
|
| 47 |
+ |
|
| 48 |
+ private WeightCategoryTreatmentCache cache;
|
|
| 49 |
+ private T3TopiaPersistenceContext persistenceContext;
|
|
| 50 |
+ |
|
| 51 |
+ @Before
|
|
| 52 |
+ public void setUp() {
|
|
| 53 |
+ persistenceContext = db.beginTransaction();
|
|
| 54 |
+ cache = persistenceContext.newWeightCategoryTreatmentCache();
|
|
| 55 |
+ }
|
|
| 56 |
+ |
|
| 57 |
+ @Test
|
|
| 58 |
+ public void forOceanAndSchoolType() {
|
|
| 59 |
+ List<Ocean> oceans = persistenceContext.getOceanDao().findAll();
|
|
| 60 |
+ List<SchoolType> schoolTypes = persistenceContext.getSchoolTypeDao().findAll();
|
|
| 61 |
+ Set<Integer> oceanCodesWithCategories = ImmutableSet.of(1, 2);
|
|
| 62 |
+ for (Ocean ocean : oceans) {
|
|
| 63 |
+ for (SchoolType schoolType : schoolTypes) {
|
|
| 64 |
+ List<WeightCategoryTreatment> weightCategoryTreatments = cache.forOceanAndSchoolType(ocean, schoolType);
|
|
| 65 |
+ Assert.assertNotNull(weightCategoryTreatments);
|
|
| 66 |
+ if (oceanCodesWithCategories.contains(ocean.getCode())) {
|
|
| 67 |
+ Assert.assertFalse(weightCategoryTreatments.isEmpty());
|
|
| 68 |
+ }
|
|
| 69 |
+ }
|
|
| 70 |
+ }
|
|
| 71 |
+ }
|
|
| 72 |
+ |
|
| 73 |
+ @Test
|
|
| 74 |
+ public void forOceansAndSchoolType() {
|
|
| 75 |
+ List<Ocean> oceans = persistenceContext.getOceanDao().findAll();
|
|
| 76 |
+ List<SchoolType> schoolTypes = persistenceContext.getSchoolTypeDao().findAll();
|
|
| 77 |
+ for (SchoolType schoolType : schoolTypes) {
|
|
| 78 |
+ List<WeightCategoryTreatment> weightCategoryTreatments = cache.forOceansAndSchoolType(oceans, schoolType);
|
|
| 79 |
+ Assert.assertNotNull(weightCategoryTreatments);
|
|
| 80 |
+ Assert.assertFalse(weightCategoryTreatments.isEmpty());
|
|
| 81 |
+ }
|
|
| 82 |
+ }
|
|
| 83 |
+}
|
| 1 |
+package fr.ird.t3.entities.cache;
|
|
| 2 |
+ |
|
| 3 |
+/*-
|
|
| 4 |
+ * #%L
|
|
| 5 |
+ * T3 :: Domain
|
|
| 6 |
+ * %%
|
|
| 7 |
+ * Copyright (C) 2010 - 2018 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
+ * %%
|
|
| 9 |
+ * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
+ * it under the terms of the GNU Affero General Public License as published by
|
|
| 11 |
+ * the Free Software Foundation, either version 3 of the License, or
|
|
| 12 |
+ * (at your option) any later version.
|
|
| 13 |
+ *
|
|
| 14 |
+ * This program is distributed in the hope that it will be useful,
|
|
| 15 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
+ * GNU General Public License for more details.
|
|
| 18 |
+ *
|
|
| 19 |
+ * You should have received a copy of the GNU Affero General Public License
|
|
| 20 |
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
| 21 |
+ * #L%
|
|
| 22 |
+ */
|
|
| 23 |
+ |
|
| 24 |
+import fr.ird.t3.entities.T3TopiaPersistenceContext;
|
|
| 25 |
+import fr.ird.t3.entities.reference.Ocean;
|
|
| 26 |
+import fr.ird.t3.entities.reference.SchoolType;
|
|
| 27 |
+import fr.ird.t3.entities.reference.zone.ZoneETMeta;
|
|
| 28 |
+import fr.ird.t3.entities.reference.zone.ZoneStratumAware;
|
|
| 29 |
+import fr.ird.t3.test.T3PostgresqlDatabase;
|
|
| 30 |
+import org.junit.Assert;
|
|
| 31 |
+import org.junit.Before;
|
|
| 32 |
+import org.junit.ClassRule;
|
|
| 33 |
+import org.junit.Test;
|
|
| 34 |
+ |
|
| 35 |
+import java.util.List;
|
|
| 36 |
+ |
|
| 37 |
+/**
|
|
| 38 |
+ * Created by tchemit on 23/03/2018.
|
|
| 39 |
+ *
|
|
| 40 |
+ * @author Tony Chemit - dev@tchemit.fr
|
|
| 41 |
+ */
|
|
| 42 |
+public class ZoneStratumCacheTest {
|
|
| 43 |
+ |
|
| 44 |
+ @ClassRule
|
|
| 45 |
+ public static final T3PostgresqlDatabase db = new T3PostgresqlDatabase();
|
|
| 46 |
+ |
|
| 47 |
+ private ZoneStratumCache cache;
|
|
| 48 |
+ private T3TopiaPersistenceContext persistenceContext;
|
|
| 49 |
+ |
|
| 50 |
+ @Before
|
|
| 51 |
+ public void setUp() {
|
|
| 52 |
+ persistenceContext = db.beginTransaction();
|
|
| 53 |
+ cache = persistenceContext.newZoneStratumCache(new ZoneETMeta(), "v2011");
|
|
| 54 |
+ }
|
|
| 55 |
+ |
|
| 56 |
+ @Test
|
|
| 57 |
+ public void forOceansAndSchoolType() {
|
|
| 58 |
+ List<Ocean> oceans = persistenceContext.getOceanDao().findAll();
|
|
| 59 |
+ List<SchoolType> schoolTypes = persistenceContext.getSchoolTypeDao().findAll();
|
|
| 60 |
+ for (SchoolType schoolType : schoolTypes) {
|
|
| 61 |
+ List<ZoneStratumAware> zones = cache.forOceansAndSchoolType(oceans, schoolType);
|
|
| 62 |
+ Assert.assertNotNull(zones);
|
|
| 63 |
+ Assert.assertFalse(zones.isEmpty());
|
|
| 64 |
+ }
|
|
| 65 |
+ }
|
|
| 66 |
+}
|
| ... | ... | @@ -43,6 +43,8 @@ public class OceanTopiaDaoPgTest { |
| 43 | 43 |
|
| 44 | 44 |
@Test
|
| 45 | 45 |
public void findOceanByHarbour() {
|
| 46 |
+ int wrongOcean = 0;
|
|
| 47 |
+ int fixOcean = 0;
|
|
| 46 | 48 |
StringBuilder queryBuilder = new StringBuilder();
|
| 47 | 49 |
try (T3TopiaPersistenceContext persistenceContext = db.beginTransaction()) {
|
| 48 | 50 |
OceanTopiaDao oceanDao = persistenceContext.getOceanDao();
|
| ... | ... | @@ -55,11 +57,13 @@ public class OceanTopiaDaoPgTest { |
| 55 | 57 |
if (harbour.getOcean() == null) {
|
| 56 | 58 |
log.warn(String.format("Harbour %s [%s] with no ocean, can use now %s [%s]", harbour.getLabel1(), harbour.getTopiaId(), oceanByHarbour.getLabel1(), oceanByHarbour.getTopiaId()));
|
| 57 | 59 |
queryBuilder.append(String.format("UPDATE Harbour SET ocean ='%s' WHERE topiaId ='%s';\n", oceanByHarbour.getTopiaId(), harbour.getTopiaId()));
|
| 60 |
+ fixOcean++;
|
|
| 58 | 61 |
} else {
|
| 59 | 62 |
try {
|
| 60 | 63 |
Assert.assertEquals(String.format("Wrong ocean for %s", harbour.getLabel1()), harbour.getOcean().getLabel1(), oceanByHarbour.getLabel1());
|
| 61 | 64 |
} catch (Throwable e) {
|
| 62 | 65 |
log.error(e.getMessage());
|
| 66 |
+ wrongOcean++;
|
|
| 63 | 67 |
}
|
| 64 | 68 |
}
|
| 65 | 69 |
}
|
| ... | ... | @@ -68,5 +72,7 @@ public class OceanTopiaDaoPgTest { |
| 68 | 72 |
if (queryBuilder.length() > 0) {
|
| 69 | 73 |
log.warn("You can update your database with thoses queries to fill missing harbour ocean:\n" + queryBuilder.toString());
|
| 70 | 74 |
}
|
| 75 |
+ log.info("Number of wrong oceans: " + wrongOcean);
|
|
| 76 |
+ log.info("Number of fixed oceans: " + fixOcean);
|
|
| 71 | 77 |
}
|
| 72 | 78 |
}
|