You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2018/05/31 14:14:40 UTC
[isis] branch master updated: ISIS-1958: Integration Tests: allows
to override default config
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/master by this push:
new ed3a07a ISIS-1958: Integration Tests: allows to override default config
ed3a07a is described below
commit ed3a07a2398dd87a1caa94d46d7527674b09547a
Author: Andi Huber <ah...@apache.org>
AuthorDate: Thu May 31 16:14:36 2018 +0200
ISIS-1958: Integration Tests: allows to override default config
Task-Url: https://issues.apache.org/jira/browse/ISIS-1958
---
.../java/org/apache/isis/applib/AppManifest.java | 6 +-
.../isis/applib/ModuleOrBuilderAbstract.java | 4 +-
.../integtestsupport/IntegrationTestAbstract3.java | 6 +-
.../integtestsupport/IntegrationTestJupiter.java | 6 +-
.../apache/isis/core/integtestsupport/Util.java | 183 +++++++++++++--------
.../runtime/headless/IsisSystemBootstrapper.java | 16 +-
.../core/runtime/system/context/IsisContext.java | 17 ++
7 files changed, 147 insertions(+), 91 deletions(-)
diff --git a/core/applib/src/main/java/org/apache/isis/applib/AppManifest.java b/core/applib/src/main/java/org/apache/isis/applib/AppManifest.java
index e392790..696545c 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/AppManifest.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/AppManifest.java
@@ -24,6 +24,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.UUID;
import javax.jdo.annotations.PersistenceCapable;
@@ -238,7 +239,7 @@ public interface AppManifest {
public static Map<String,String> withJavaxJdoRunInMemoryProperties(final Map<String, String> map) {
- map.put(ISIS_PERSISTOR_DATANUCLEUS_IMPL + "javax.jdo.option.ConnectionURL", "jdbc:hsqldb:mem:test");
+ map.put(ISIS_PERSISTOR_DATANUCLEUS_IMPL + "javax.jdo.option.ConnectionURL", "jdbc:hsqldb:mem:test-" + UUID.randomUUID().toString());
map.put(ISIS_PERSISTOR_DATANUCLEUS_IMPL + "javax.jdo.option.ConnectionDriverName", "org.hsqldb.jdbcDriver");
map.put(ISIS_PERSISTOR_DATANUCLEUS_IMPL + "javax.jdo.option.ConnectionUserName", "sa");
map.put(ISIS_PERSISTOR_DATANUCLEUS_IMPL + "javax.jdo.option.ConnectionPassword", "");
@@ -271,8 +272,7 @@ public interface AppManifest {
return map;
}
-
-
+
}
}
diff --git a/core/applib/src/main/java/org/apache/isis/applib/ModuleOrBuilderAbstract.java b/core/applib/src/main/java/org/apache/isis/applib/ModuleOrBuilderAbstract.java
index 527951e..10e76e6 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/ModuleOrBuilderAbstract.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/ModuleOrBuilderAbstract.java
@@ -26,6 +26,7 @@ import java.util.Set;
import javax.xml.bind.annotation.XmlTransient;
+import org.apache.isis.commons.internal.base._Casts;
import org.apache.isis.commons.internal.collections._Lists;
import org.apache.isis.commons.internal.collections._Maps;
import org.apache.isis.commons.internal.collections._Sets;
@@ -162,9 +163,8 @@ abstract class ModuleOrBuilderAbstract<B extends ModuleOrBuilderAbstract<B>> {
// -- HELPER
- @SuppressWarnings("unchecked") //[ahuber] it's safe to assume this object is an instance of B
protected B self() {
- return (B) this;
+ return _Casts.uncheckedCast(this);
}
}
diff --git a/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IntegrationTestAbstract3.java b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IntegrationTestAbstract3.java
index 2394f74..05a2614 100644
--- a/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IntegrationTestAbstract3.java
+++ b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IntegrationTestAbstract3.java
@@ -81,7 +81,11 @@ public abstract class IntegrationTestAbstract3 extends HeadlessWithBootstrapping
protected IntegrationTestAbstract3(
final LogConfig logConfig,
final Module module) {
- super(logConfig, Util.addHeadlessTransactionSupport(module));
+ super(logConfig,
+ Util.moduleBuilder(module)
+ .withHeadlessTransactionSupport()
+ .withIntegrationTestConfigIfAbsent()
+ .build() );
}
@Override
diff --git a/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IntegrationTestJupiter.java b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IntegrationTestJupiter.java
index 342871c..b966ab8 100644
--- a/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IntegrationTestJupiter.java
+++ b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IntegrationTestJupiter.java
@@ -76,7 +76,11 @@ public abstract class IntegrationTestJupiter extends HeadlessWithBootstrappingAb
protected IntegrationTestJupiter(
final LogConfig logConfig,
final Module module) {
- super(logConfig, Util.addHeadlessTransactionSupport(module));
+ super(logConfig,
+ Util.moduleBuilder(module)
+ .withHeadlessTransactionSupport()
+ .withIntegrationTestConfigIfAbsent()
+ .build() );
}
@Override
diff --git a/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/Util.java b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/Util.java
index 9c28bfe..89dc859 100644
--- a/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/Util.java
+++ b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/Util.java
@@ -19,8 +19,11 @@
package org.apache.isis.core.integtestsupport;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import org.apache.isis.applib.AppManifest;
import org.apache.isis.applib.Module;
import org.apache.isis.applib.NonRecoverableException;
import org.apache.isis.applib.RecoverableException;
@@ -31,86 +34,120 @@ import org.apache.isis.core.integtestsupport.components.DefaultHeadlessTransacti
import org.apache.isis.core.runtime.headless.IsisSystem;
class Util {
+
+ // -- MODULE BUILDER
+
+ public static class ModuleBuilder {
+ final Module module;
+ private ModuleBuilder(Module module) {
+ this.module = module;
+ }
+ public Module build() {
+ return module;
+ }
+ /**
+ * Registers DefaultHeadlessTransactionSupport as an additional service.
+ */
+ public ModuleBuilder withHeadlessTransactionSupport() {
+ module.getAdditionalServices().add(DefaultHeadlessTransactionSupport.class);
+ return this;
+ }
+ /**
+ * Adds default config values for integration tests, without overriding any existing keys.
+ */
+ public ModuleBuilder withIntegrationTestConfigIfAbsent() {
+ final Map<String, String> integrationTestDefaultConfig = new HashMap<>();
+ AppManifest.Util.withJavaxJdoRunInMemoryProperties(integrationTestDefaultConfig);
+ AppManifest.Util.withDataNucleusProperties(integrationTestDefaultConfig);
+ AppManifest.Util.withIsisIntegTestProperties(integrationTestDefaultConfig);
+
+ integrationTestDefaultConfig.forEach((k, v)->{
+ module.getIndividualConfigProps().computeIfAbsent(k, __->v);
+ });
+ return this;
+ }
+ }
- //[ahuber] hooks into the bootstrapping, such that the
- // DefaultHeadlessTransactionSupport is registered as an additional service
- public static Module addHeadlessTransactionSupport(Module module) {
- module.getAdditionalServices().add(DefaultHeadlessTransactionSupport.class);
- return module;
+ public static ModuleBuilder moduleBuilder(Module module) {
+ return new ModuleBuilder(module);
}
+
+ // -- HANDLING EXCEPTIONS
public static void handleTransactionContextException(Exception e) throws Exception {
// determine if underlying cause is an applib-defined exception,
- final RecoverableException recoverableException =
- determineIfRecoverableException(e);
- final NonRecoverableException nonRecoverableException =
- determineIfNonRecoverableException(e);
-
- if(recoverableException != null) {
- try {
- final IsisSystem isft = IsisSystem.get();
- isft.getService(TransactionService.class).flushTransaction(); // don't care if npe
- isft.getService(IsisJdoSupport.class).getJdoPersistenceManager().flush();
- } catch (Exception ignore) {
- // ignore
- }
- }
- // attempt to close this
- try {
- final IsisSystem isft = IsisSystem.getElseNull();
- isft.closeSession(); // don't care if npe
- } catch(Exception ignore) {
- // ignore
- }
-
- // attempt to start another
- try {
- final IsisSystem isft = IsisSystem.getElseNull();
- isft.openSession(); // don't care if npe
- } catch(Exception ignore) {
- // ignore
- }
-
-
- // if underlying cause is an applib-defined, then
- // throw that rather than Isis' wrapper exception
- if(recoverableException != null) {
- throw recoverableException;
- }
- if(nonRecoverableException != null) {
- throw nonRecoverableException;
- }
-
- // report on the error that caused
- // a problem for *this* test
- throw e;
- }
+ final RecoverableException recoverableException =
+ determineIfRecoverableException(e);
+ final NonRecoverableException nonRecoverableException =
+ determineIfNonRecoverableException(e);
- private static NonRecoverableException determineIfNonRecoverableException(final Exception e) {
- NonRecoverableException nonRecoverableException = null;
- final List<Throwable> causalChain2 = _Exceptions.getCausalChain(e);
- for (final Throwable cause : causalChain2) {
- if(cause instanceof NonRecoverableException) {
- nonRecoverableException = (NonRecoverableException) cause;
- break;
- }
- }
- return nonRecoverableException;
- }
-
- private static RecoverableException determineIfRecoverableException(final Exception e) {
- RecoverableException recoverableException = null;
- final List<Throwable> causalChain = _Exceptions.getCausalChain(e);
- for (final Throwable cause : causalChain) {
- if(cause instanceof RecoverableException) {
- recoverableException = (RecoverableException) cause;
- break;
- }
- }
- return recoverableException;
- }
+ if(recoverableException != null) {
+ try {
+ final IsisSystem isft = IsisSystem.get();
+ isft.getService(TransactionService.class).flushTransaction(); // don't care if npe
+ isft.getService(IsisJdoSupport.class).getJdoPersistenceManager().flush();
+ } catch (Exception ignore) {
+ // ignore
+ }
+ }
+ // attempt to close this
+ try {
+ final IsisSystem isft = IsisSystem.getElseNull();
+ isft.closeSession(); // don't care if npe
+ } catch(Exception ignore) {
+ // ignore
+ }
+ // attempt to start another
+ try {
+ final IsisSystem isft = IsisSystem.getElseNull();
+ isft.openSession(); // don't care if npe
+ } catch(Exception ignore) {
+ // ignore
+ }
+
+ // if underlying cause is an applib-defined, then
+ // throw that rather than Isis' wrapper exception
+ if(recoverableException != null) {
+ throw recoverableException;
+ }
+ if(nonRecoverableException != null) {
+ throw nonRecoverableException;
+ }
+
+ // report on the error that caused
+ // a problem for *this* test
+ throw e;
+ }
+
+ // -- HELPER
-
+ private static NonRecoverableException determineIfNonRecoverableException(final Exception e) {
+ NonRecoverableException nonRecoverableException = null;
+ final List<Throwable> causalChain2 = _Exceptions.getCausalChain(e);
+ for (final Throwable cause : causalChain2) {
+ if(cause instanceof NonRecoverableException) {
+ nonRecoverableException = (NonRecoverableException) cause;
+ break;
+ }
+ }
+ return nonRecoverableException;
+ }
+
+ private static RecoverableException determineIfRecoverableException(final Exception e) {
+ RecoverableException recoverableException = null;
+ final List<Throwable> causalChain = _Exceptions.getCausalChain(e);
+ for (final Throwable cause : causalChain) {
+ if(cause instanceof RecoverableException) {
+ recoverableException = (RecoverableException) cause;
+ break;
+ }
+ }
+ return recoverableException;
+ }
+
+
+
+
}
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/headless/IsisSystemBootstrapper.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/headless/IsisSystemBootstrapper.java
index e587ec5..a606192 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/headless/IsisSystemBootstrapper.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/headless/IsisSystemBootstrapper.java
@@ -19,7 +19,6 @@
package org.apache.isis.core.runtime.headless;
import java.util.List;
-import java.util.UUID;
import javax.jdo.PersistenceManagerFactory;
@@ -36,7 +35,6 @@ import org.apache.isis.applib.services.registry.ServiceRegistry;
import org.apache.isis.core.runtime.headless.logging.LogConfig;
import org.apache.isis.core.runtime.system.context.IsisContext;
import org.apache.isis.core.runtime.system.session.IsisSessionFactory;
-import org.apache.isis.objectstore.jdo.datanucleus.IsisConfigurationForJdoIntegTests;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -148,20 +146,16 @@ public class IsisSystemBootstrapper {
private static IsisSystem setupSystem(final AppManifest2 appManifest2) {
- final IsisConfigurationForJdoIntegTests configuration = new IsisConfigurationForJdoIntegTests();
- configuration.putDataNucleusProperty("javax.jdo.option.ConnectionURL","jdbc:hsqldb:mem:test-" + UUID.randomUUID()
- .toString());
- final IsisSystem.Builder isftBuilder =
- new IsisSystem.Builder()
+ final IsisSystem isft =
+ IsisSystem.builder()
.withLoggingAt(org.apache.log4j.Level.INFO)
.with(appManifest2)
- .with(configuration);
-
- IsisSystem isft = isftBuilder.build();
+ .build();
+
isft.setUpSystem();
// save both the system and the manifest
- // used to bootstrap the system onto thread-loca
+ // used to bootstrap the system onto thread-local
IsisSystem.set(isft);
isftAppManifest.set(appManifest2);
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/context/IsisContext.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/context/IsisContext.java
index 3c8ebb8..ef29773 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/context/IsisContext.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/context/IsisContext.java
@@ -19,7 +19,9 @@
package org.apache.isis.core.runtime.system.context;
+import java.util.Map;
import java.util.Optional;
+import java.util.TreeMap;
import org.apache.isis.commons.internal.context._Context;
import org.apache.isis.core.commons.config.IsisConfiguration;
@@ -110,6 +112,19 @@ public interface IsisContext {
public static ServicesInjector getServicesInjector() {
return getSessionFactory().getServicesInjector();
}
+
+ public static void dumpConfig() {
+
+ final Map<String, String> map = new TreeMap<>(getConfiguration().asMap());
+
+ System.out.println("=============================================");
+ System.out.println("= ISIS 2.0.0 =");
+ System.out.println("=============================================");
+ map.forEach((k,v)->{
+ System.out.println(k+" -> "+v);
+ });
+ System.out.println("=============================================");
+ }
// -- HELPER
@@ -125,5 +140,7 @@ public interface IsisContext {
// at least we tried
}
}
+
+
}
--
To stop receiving notification emails like this one, please contact
ahuber@apache.org.