You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2017/12/07 15:01:14 UTC
[isis] 18/18: ISIS-1794: simplifies and unifies the bootstrapping
for BDD and integ tests.
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
commit 8f212bce35e74b91376411d3e9a1eaa2e5f57cb9
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Thu Dec 7 15:00:37 2017 +0000
ISIS-1794: simplifies and unifies the bootstrapping for BDD and integ tests.
Also:
- for IsisSystem, remove all the listener stuff
- deprecates ScenarioExecution
- fixes up/simplifies the simpleapp bdd features
---
.../apache/isis/applib/AppManifestAbstract2.java | 29 ++-
.../core/integtestsupport/IntegrationAbstract.java | 134 ++++++++++++
.../IntegrationBootstrapAbstract.java | 148 ++++++++++++++
.../integtestsupport/IntegrationTestAbstract3.java | 227 ++-------------------
.../isis/core/integtestsupport/IsisSystem.java | 199 ++----------------
.../scenarios/ObjectFactoryForIntegration.java | 8 +-
.../scenarios/ScenarioExecutionForIntegration.java | 5 +-
.../specsupport/scenarios/ScenarioExecution.java | 3 +
.../scenarios/ScenarioExecutionForUnit.java | 3 +
.../bdd/specglue/BootstrappingGlue.java | 16 +-
.../bdd/specglue/BootstrappingGlueAbstract.java | 60 ------
.../bdd/specglue/CatalogOfFixturesGlue.java | 6 +-
.../SimpleObjectSpec_listAllAndCreate.feature | 1 -
.../simple/specglue/SimpleObjectMenuGlue.java | 13 +-
14 files changed, 375 insertions(+), 477 deletions(-)
diff --git a/core/applib/src/main/java/org/apache/isis/applib/AppManifestAbstract2.java b/core/applib/src/main/java/org/apache/isis/applib/AppManifestAbstract2.java
index 5719c7a..a5bce36 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/AppManifestAbstract2.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/AppManifestAbstract2.java
@@ -38,7 +38,10 @@ public abstract class AppManifestAbstract2 extends AppManifestAbstract implement
}
}
- public static class Builder extends AppManifestAbstract.Builder {
+ interface ModuleProvider {
+ Module getModule();
+ }
+ public static class Builder extends AppManifestAbstract.Builder implements ModuleProvider {
public static AppManifestAbstract.Builder forModule(Module module) {
return module instanceof ModuleAbstract
@@ -48,6 +51,11 @@ public abstract class AppManifestAbstract2 extends AppManifestAbstract implement
private final Module module;
+ @Override
+ public Module getModule() {
+ return module;
+ }
+
private Builder(Module module) {
this.module = module;
@@ -81,7 +89,7 @@ public abstract class AppManifestAbstract2 extends AppManifestAbstract implement
* A {@link AppManifestAbstract.Builder} implementation that delegates to the wrapped {@link ModuleAbstract} for transitive modules,
* services and configuration properties, but continues to manage fixture scripts and auth mechanisms.
*/
- public static class BuilderWrappingModuleAbstract extends AppManifestAbstract.Builder {
+ public static class BuilderWrappingModuleAbstract extends AppManifestAbstract.Builder implements ModuleProvider {
private final ModuleAbstract moduleAbstract;
@@ -90,6 +98,11 @@ public abstract class AppManifestAbstract2 extends AppManifestAbstract implement
}
@Override
+ public Module getModule() {
+ return moduleAbstract;
+ }
+
+ @Override
public AppManifestAbstract.Builder withAdditionalModules(final Class<?>... modules) {
moduleAbstract.withAdditionalModules(modules);
return this;
@@ -170,16 +183,10 @@ public abstract class AppManifestAbstract2 extends AppManifestAbstract implement
private final Module module;
public AppManifestAbstract2(final AppManifestAbstract.Builder builder) {
super(builder);
- if (!(builder instanceof Builder)) {
- throw new IllegalArgumentException("Requires an AppManifestAbstract2.Builder2");
+ if (!(builder instanceof ModuleProvider)) {
+ throw new IllegalArgumentException("Requires a Builder that implements ModuleProvider");
}
- Builder builder2 = (Builder) builder;
- this.module = builder2.module;
- }
-
- public <M extends Module & AppManifestBuilder<?>> AppManifestAbstract2(final M module) {
- super(module);
- this.module = module;
+ this.module = ((ModuleProvider)builder).getModule();
}
@Programmatic
diff --git a/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IntegrationAbstract.java b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IntegrationAbstract.java
new file mode 100644
index 0000000..73ad894
--- /dev/null
+++ b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IntegrationAbstract.java
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.core.integtestsupport;
+
+import javax.inject.Inject;
+
+import org.joda.time.LocalDate;
+
+import org.apache.isis.applib.clock.Clock;
+import org.apache.isis.applib.clock.TickingFixtureClock;
+import org.apache.isis.applib.fixtures.FixtureClock;
+import org.apache.isis.applib.fixturescripts.BuilderScriptAbstract;
+import org.apache.isis.applib.fixturescripts.FixtureScript;
+import org.apache.isis.applib.fixturescripts.FixtureScripts;
+import org.apache.isis.applib.services.clock.ClockService;
+import org.apache.isis.applib.services.factory.FactoryService;
+import org.apache.isis.applib.services.metamodel.MetaModelService4;
+import org.apache.isis.applib.services.registry.ServiceRegistry2;
+import org.apache.isis.applib.services.repository.RepositoryService;
+import org.apache.isis.applib.services.sessmgmt.SessionManagementService;
+import org.apache.isis.applib.services.user.UserService;
+import org.apache.isis.applib.services.wrapper.WrapperFactory;
+import org.apache.isis.applib.services.xactn.TransactionService;
+
+/**
+ * Reworked base class for integration tests or BDD spec glue.
+ */
+public abstract class IntegrationAbstract {
+
+
+
+ protected void runFixtureScript(final FixtureScript... fixtureScriptList) {
+ this.fixtureScripts.runFixtureScript(fixtureScriptList);
+ }
+
+
+ protected <T,F extends BuilderScriptAbstract<T,F>> T runBuilderScript(final F fixtureScript) {
+ return this.fixtureScripts.runBuilderScript(fixtureScript);
+ }
+
+
+ /**
+ * For convenience of subclasses, remove some boilerplate
+ */
+ protected <T> T wrap(final T obj) {
+ return wrapperFactory.wrap(obj);
+ }
+
+ /**
+ * For convenience of subclasses, remove some boilerplate
+ */
+ protected <T> T mixin(final Class<T> mixinClass, final Object mixedIn) {
+ return factoryService.mixin(mixinClass, mixedIn);
+ }
+
+
+ /**
+ * To use instead of {@link #getFixtureClock()}'s {@link FixtureClock#setDate(int, int, int)} ()}.
+ */
+ protected void setFixtureClockDate(final LocalDate date) {
+ if(date == null) {
+ return;
+ }
+ setFixtureClockDate(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth());
+ }
+
+ /**
+ * To use instead of {@link #getFixtureClock()}'s {@link FixtureClock#setDate(int, int, int)} ()}.
+ */
+ protected void setFixtureClockDate(final int year, final int month, final int day) {
+ final Clock instance = Clock.getInstance();
+
+ if(instance instanceof TickingFixtureClock) {
+ TickingFixtureClock.reinstateExisting();
+ getFixtureClock().setDate(year, month, day);
+ TickingFixtureClock.replaceExisting();
+ }
+
+ if(instance instanceof FixtureClock) {
+ getFixtureClock().setDate(year, month, day);
+ }
+ }
+
+ /**
+ * If just require the current time, use {@link ClockService}
+ */
+ private FixtureClock getFixtureClock() {
+ return ((FixtureClock)FixtureClock.getInstance());
+ }
+
+
+ /**
+ * For convenience of subclasses, remove some boilerplate
+ */
+ protected <T> T unwrap(final T obj) {
+ return wrapperFactory.unwrap(obj);
+ }
+
+ @Inject
+ protected MetaModelService4 metaModelService4;
+ @Inject
+ protected FixtureScripts fixtureScripts;
+ @Inject
+ protected FactoryService factoryService;
+ @Inject
+ protected ServiceRegistry2 serviceRegistry;
+ @Inject
+ protected RepositoryService repositoryService;
+ @Inject
+ protected UserService userService;
+ @Inject
+ protected WrapperFactory wrapperFactory;
+ @Inject
+ protected TransactionService transactionService;
+ @Inject
+ protected SessionManagementService sessionManagementService;
+
+}
\ No newline at end of file
diff --git a/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IntegrationBootstrapAbstract.java b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IntegrationBootstrapAbstract.java
new file mode 100644
index 0000000..6f0b420
--- /dev/null
+++ b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IntegrationBootstrapAbstract.java
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.core.integtestsupport;
+
+import java.io.PrintStream;
+
+import com.google.common.base.Strings;
+
+import org.apache.log4j.PropertyConfigurator;
+import org.joda.time.LocalDate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.event.Level;
+
+import org.apache.isis.applib.Module;
+import org.apache.isis.applib.clock.Clock;
+import org.apache.isis.core.commons.factory.InstanceUtil;
+import org.apache.isis.core.integtestsupport.logging.LogConfig;
+import org.apache.isis.core.integtestsupport.logging.LogStream;
+
+public abstract class IntegrationBootstrapAbstract extends IntegrationAbstract {
+
+ private static final Logger LOG = LoggerFactory.getLogger(IntegrationBootstrapAbstract.class);
+
+ private final LogConfig logConfig;
+ protected static PrintStream logPrintStream(Level level) {
+ return LogStream.logPrintStream(LOG, level);
+ }
+
+ private final static ThreadLocal<Boolean> setupLogging = new ThreadLocal<Boolean>() {{
+ set(false);
+ }};
+
+
+ private final IsisSystemBootstrapper isisSystemBootstrapper;
+
+ protected Long t0;
+
+ protected IntegrationBootstrapAbstract(
+ final Module module,
+ final Class... additionalModuleClasses) {
+ this(new LogConfig(Level.INFO), module, additionalModuleClasses);
+ }
+
+ protected IntegrationBootstrapAbstract(
+ final LogConfig logConfig,
+ final Module module,
+ final Class... additionalModuleClasses) {
+
+ this.logConfig = logConfig;
+
+ final boolean firstTime = !setupLogging.get();
+ if(firstTime) {
+ PropertyConfigurator.configure(logConfig.getLoggingPropertyFile());
+ System.setOut(logConfig.getFixtureTracing());
+ setupLogging.set(true);
+ t0 = System.currentTimeMillis();
+ }
+
+ final String moduleFqcn = System.getProperty("isis.integTest.module");
+
+ final Module moduleToUse;
+ final Class[] additionalModuleClassesToUse;
+ if(!Strings.isNullOrEmpty(moduleFqcn)) {
+ moduleToUse = InstanceUtil.createInstance(moduleFqcn, Module.class);
+ additionalModuleClassesToUse = new Class<?>[] { };
+ } else {
+ moduleToUse = module;
+ additionalModuleClassesToUse = additionalModuleClasses;
+ }
+ this.isisSystemBootstrapper =
+ new IsisSystemBootstrapper(logConfig, moduleToUse, additionalModuleClassesToUse);
+ }
+
+
+ private LocalDate timeBeforeTest;
+
+ protected void bootstrapAndSetupIfRequired() {
+
+ System.setProperty("isis.integTest", "true");
+
+ isisSystemBootstrapper.bootstrapIfRequired(t0);
+ isisSystemBootstrapper.injectServicesInto(this);
+
+ beginTransaction();
+
+ isisSystemBootstrapper.setupModuleRefData();
+
+ timeBeforeTest = Clock.getTimeAsLocalDate();
+ }
+
+ private void beginTransaction() {
+ final IsisSystem isft = IsisSystem.get();
+ isft.beginTran();
+ }
+
+ protected void tearDownAllModules() {
+
+ final boolean testHealthy = transactionService != null;
+ if(!testHealthy) {
+ // avoid throwing an NPE here if something unexpected has occurred...
+ return;
+ }
+
+ transactionService.nextTransaction();
+
+ isisSystemBootstrapper.tearDownAllModules();
+
+ // reinstate clock
+ setFixtureClockDate(timeBeforeTest);
+ }
+
+ protected void log(final String message) {
+ switch (logConfig.getTestLoggingLevel()) {
+ case ERROR:
+ LOG.error(message);
+ break;
+ case WARN:
+ LOG.warn(message);
+ break;
+ case INFO:
+ LOG.info(message);
+ break;
+ case DEBUG:
+ LOG.debug(message);
+ break;
+ case TRACE:
+ LOG.trace(message);
+ break;
+ }
+ }
+}
\ No newline at end of file
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 f87111e..d7672f3 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
@@ -18,16 +18,10 @@
*/
package org.apache.isis.core.integtestsupport;
-import java.io.PrintStream;
import java.util.List;
-import javax.inject.Inject;
-
-import com.google.common.base.Strings;
import com.google.common.base.Throwables;
-import org.apache.log4j.PropertyConfigurator;
-import org.joda.time.LocalDate;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
@@ -43,42 +37,15 @@ import org.apache.isis.applib.AppManifest;
import org.apache.isis.applib.Module;
import org.apache.isis.applib.NonRecoverableException;
import org.apache.isis.applib.RecoverableException;
-import org.apache.isis.applib.clock.Clock;
-import org.apache.isis.applib.clock.TickingFixtureClock;
-import org.apache.isis.applib.fixtures.FixtureClock;
-import org.apache.isis.applib.fixturescripts.BuilderScriptAbstract;
-import org.apache.isis.applib.fixturescripts.FixtureScript;
-import org.apache.isis.applib.fixturescripts.FixtureScripts;
-import org.apache.isis.applib.services.clock.ClockService;
-import org.apache.isis.applib.services.factory.FactoryService;
import org.apache.isis.applib.services.jdosupport.IsisJdoSupport;
-import org.apache.isis.applib.services.metamodel.MetaModelService4;
-import org.apache.isis.applib.services.registry.ServiceRegistry2;
-import org.apache.isis.applib.services.repository.RepositoryService;
-import org.apache.isis.applib.services.sessmgmt.SessionManagementService;
-import org.apache.isis.applib.services.user.UserService;
-import org.apache.isis.applib.services.wrapper.WrapperFactory;
-import org.apache.isis.applib.services.xactn.TransactionService;
-import org.apache.isis.core.commons.factory.InstanceUtil;
import org.apache.isis.core.integtestsupport.logging.LogConfig;
-import org.apache.isis.core.integtestsupport.logging.LogStream;
/**
* Reworked base class for integration tests, uses a {@link Module} to bootstrap, rather than an {@link AppManifest}.
*/
-public abstract class IntegrationTestAbstract3 {
+public abstract class IntegrationTestAbstract3 extends IntegrationBootstrapAbstract {
private static final Logger LOG = LoggerFactory.getLogger(IntegrationTestAbstract3.class);
- private final LogConfig logConfig;
- private final IsisSystemBootstrapper isisSystemBootstrapper;
-
-
- protected static PrintStream logPrintStream() {
- return logPrintStream(Level.DEBUG);
- }
- protected static PrintStream logPrintStream(Level level) {
- return LogStream.logPrintStream(LOG, level);
- }
@Rule
public ExpectedException expectedExceptions = ExpectedException.none();
@@ -90,64 +57,6 @@ public abstract class IntegrationTestAbstract3 {
@Rule
public IntegrationTestAbstract3.IsisTransactionRule isisTransactionRule = new IntegrationTestAbstract3.IsisTransactionRule();
- private final static ThreadLocal<Boolean> setupLogging = new ThreadLocal<Boolean>() {{
- set(false);
- }};
-
- protected final Module module;
- private final Class[] additionalModuleClasses;
-
- public IntegrationTestAbstract3(final Module module, final Class... additionalModuleClasses) {
- this(new LogConfig(Level.INFO), module, additionalModuleClasses);
- }
-
- private Long t0;
- public IntegrationTestAbstract3(
- final LogConfig logConfig,
- final Module module,
- final Class... additionalModuleClasses) {
- this.logConfig = logConfig;
-
- final boolean firstTime = !setupLogging.get();
- if(firstTime) {
- PropertyConfigurator.configure(logConfig.getLoggingPropertyFile());
- System.setOut(logConfig.getFixtureTracing());
- setupLogging.set(true);
- t0 = System.currentTimeMillis();
- }
-
- final String moduleFqcn = System.getProperty("isis.integTest.module");
-
- if(!Strings.isNullOrEmpty(moduleFqcn)) {
- this.module = InstanceUtil.createInstance(moduleFqcn, Module.class);
- this.additionalModuleClasses = new Class<?>[] { };
- } else {
- this.module = module;
- this.additionalModuleClasses = additionalModuleClasses;
- }
- this.isisSystemBootstrapper = new IsisSystemBootstrapper(logConfig, module, additionalModuleClasses);
- }
-
- private LocalDate timeBeforeTest;
-
- @Before
- public void bootstrapAndSetupIfRequired() {
-
- System.setProperty("isis.integTest", "true");
-
- isisSystemBootstrapper.bootstrapIfRequired(t0);
- isisSystemBootstrapper.injectServicesInto(this);
-
- beginTransaction();
-
- isisSystemBootstrapper.setupModuleRefData();
-
- log("### TEST: " + this.getClass().getCanonicalName());
-
- timeBeforeTest = Clock.getTimeAsLocalDate();
- }
-
-
private static class IsisTransactionRule implements MethodRule {
@Override
@@ -238,133 +147,31 @@ public abstract class IntegrationTestAbstract3 {
}
}
- private void beginTransaction() {
- final IsisSystem isft = IsisSystem.get();
- isft.beginTran();
- }
-
- @After
- public void tearDownAllModules() {
-
- final boolean testHealthy = transactionService != null;
- if(!testHealthy) {
- // avoid throwing an NPE here if something unexpected has occurred...
- return;
- }
-
- transactionService.nextTransaction();
-
- isisSystemBootstrapper.tearDownAllModules();
-
- // reinstate clock
- setFixtureClockDate(timeBeforeTest);
- }
-
-
- protected void runFixtureScript(final FixtureScript... fixtureScriptList) {
- this.fixtureScripts.runFixtureScript(fixtureScriptList);
- }
-
-
- protected <T,F extends BuilderScriptAbstract<T,F>> T runBuilderScript(final F fixtureScript) {
- return this.fixtureScripts.runBuilderScript(fixtureScript);
- }
-
-
- /**
- * For convenience of subclasses, remove some boilerplate
- */
- protected <T> T wrap(final T obj) {
- return wrapperFactory.wrap(obj);
- }
- /**
- * For convenience of subclasses, remove some boilerplate
- */
- protected <T> T mixin(final Class<T> mixinClass, final Object mixedIn) {
- return factoryService.mixin(mixinClass, mixedIn);
- }
-
-
- /**
- * To use instead of {@link #getFixtureClock()}'s {@link FixtureClock#setDate(int, int, int)} ()}.
- */
- protected void setFixtureClockDate(final LocalDate date) {
- if(date == null) {
- return;
- }
- setFixtureClockDate(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth());
+ protected IntegrationTestAbstract3(
+ final Module module,
+ final Class... additionalModuleClasses) {
+ this(new LogConfig(Level.INFO), module, additionalModuleClasses);
}
- /**
- * To use instead of {@link #getFixtureClock()}'s {@link FixtureClock#setDate(int, int, int)} ()}.
- */
- protected void setFixtureClockDate(final int year, final int month, final int day) {
- final Clock instance = Clock.getInstance();
-
- if(instance instanceof TickingFixtureClock) {
- TickingFixtureClock.reinstateExisting();
- getFixtureClock().setDate(year, month, day);
- TickingFixtureClock.replaceExisting();
- }
-
- if(instance instanceof FixtureClock) {
- getFixtureClock().setDate(year, month, day);
- }
+ protected IntegrationTestAbstract3(
+ final LogConfig logConfig,
+ final Module module,
+ final Class... additionalModuleClasses) {
+ super(logConfig, module, additionalModuleClasses);
}
- /**
- * If just require the current time, use {@link ClockService}
- */
- private FixtureClock getFixtureClock() {
- return ((FixtureClock)FixtureClock.getInstance());
- }
+ @Before
+ public void beforeTest() {
+ super.bootstrapAndSetupIfRequired();
- private void log(final String message) {
- switch (logConfig.getTestLoggingLevel()) {
- case ERROR:
- LOG.error(message);
- break;
- case WARN:
- LOG.warn(message);
- break;
- case INFO:
- LOG.info(message);
- break;
- case DEBUG:
- LOG.debug(message);
- break;
- case TRACE:
- LOG.trace(message);
- break;
- }
+ log("### TEST: " + this.getClass().getCanonicalName());
}
- /**
- * For convenience of subclasses, remove some boilerplate
- */
- protected <T> T unwrap(final T obj) {
- return wrapperFactory.unwrap(obj);
+ @After
+ public void afterTest() {
+ super.tearDownAllModules();
}
- @Inject
- protected MetaModelService4 metaModelService4;
- @Inject
- protected FixtureScripts fixtureScripts;
- @Inject
- protected FactoryService factoryService;
- @Inject
- protected ServiceRegistry2 serviceRegistry;
- @Inject
- protected RepositoryService repositoryService;
- @Inject
- protected UserService userService;
- @Inject
- protected WrapperFactory wrapperFactory;
- @Inject
- protected TransactionService transactionService;
- @Inject
- protected SessionManagementService sessionManagementService;
-
}
\ No newline at end of file
diff --git a/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IsisSystem.java b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IsisSystem.java
index cb16ed6..e5f790b 100644
--- a/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IsisSystem.java
+++ b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IsisSystem.java
@@ -19,11 +19,9 @@
package org.apache.isis.core.integtestsupport;
-import java.util.List;
import java.util.Set;
import com.google.common.base.Joiner;
-import com.google.common.collect.Lists;
import org.apache.isis.applib.AppManifest;
import org.apache.isis.applib.DomainObjectContainer;
@@ -51,7 +49,6 @@ import org.apache.isis.core.runtime.system.transaction.IsisTransactionManager;
import org.apache.isis.core.runtime.systemusinginstallers.IsisComponentProvider;
import org.apache.isis.core.security.authentication.AuthenticationRequestNameOnly;
-import static org.junit.Assert.fail;
/**
* Wraps a plain {@link IsisSessionFactoryBuilder}.
@@ -62,60 +59,6 @@ import static org.junit.Assert.fail;
*/
public class IsisSystem {
- //region > Listener, ListenerAdapter
- public interface Listener {
-
- void init(IsisConfiguration configuration) throws Exception;
-
- void preOpenSession(boolean firstTime) throws Exception;
- void postOpenSession(boolean firstTime) throws Exception;
-
- void preNextSession() throws Exception;
- void postNextSession() throws Exception;
-
- void preCloseSession() throws Exception;
- void postCloseSession() throws Exception;
- }
-
- public static abstract class ListenerAdapter implements Listener {
-
- private IsisConfiguration configuration;
-
- public void init(IsisConfiguration configuration) throws Exception {
- this.configuration = configuration;
- }
-
- protected IsisConfiguration getConfiguration() {
- return configuration;
- }
-
- @Override
- public void preOpenSession(boolean firstTime) throws Exception {
- }
-
- @Override
- public void postOpenSession(boolean firstTime) throws Exception {
- }
-
- @Override
- public void preNextSession() throws Exception {
- }
-
- @Override
- public void postNextSession() throws Exception {
- }
-
- @Override
- public void preCloseSession() throws Exception {
- }
-
- @Override
- public void postCloseSession() throws Exception {
- }
- }
-
- //endregion
-
//region > getElseNull, get, set
protected static ThreadLocal<IsisSystem> ISFT = new ThreadLocal<>();
@@ -149,8 +92,6 @@ public class IsisSystem {
protected AppManifest appManifestIfAny;
- protected final List <Listener> listeners = Lists.newArrayList();
-
protected org.apache.log4j.Level level;
public T with(IsisConfiguration configuration) {
@@ -178,8 +119,7 @@ public class IsisSystem {
new IsisSystem(
appManifestIfAny,
configuration,
- authenticationRequest,
- listeners);
+ authenticationRequest);
return (S)configure(isisSystem);
}
@@ -210,13 +150,6 @@ public class IsisSystem {
return isisSystem;
}
- public Builder with(Listener listener) {
- if(listener != null) {
- listeners.add(listener);
- }
- return this;
- }
-
}
public static Builder builder() {
@@ -238,12 +171,10 @@ public class IsisSystem {
protected IsisSystem(
final AppManifest appManifestIfAny,
final IsisConfiguration configurationOverride,
- final AuthenticationRequest authenticationRequestIfAny,
- final List<Listener> listeners) {
+ final AuthenticationRequest authenticationRequestIfAny) {
this.appManifestIfAny = appManifestIfAny;
this.configurationOverride = configurationOverride;
this.authenticationRequestIfAny = authenticationRequestIfAny;
- this.listeners = listeners;
}
//endregion
@@ -271,29 +202,24 @@ public class IsisSystem {
IsisSystem setUpSystem() throws RuntimeException {
try {
- initIfRequiredThenOpenSession(FireListeners.FIRE);
+ initIfRequiredThenOpenSession();
} catch (Exception e) {
throw new RuntimeException(e);
}
return this;
}
- protected void initIfRequiredThenOpenSession(FireListeners fireListeners) throws Exception {
+ protected void initIfRequiredThenOpenSession() throws Exception {
// exit as quickly as possible for this case...
final MetaModelInvalidException mmie = IsisContext.getMetaModelInvalidExceptionIfAny();
if(mmie != null) {
final Set<String> validationErrors = mmie.getValidationErrors();
final String validationMsg = Joiner.on("\n").join(validationErrors);
- fail(validationMsg);
- return;
+ throw new AssertionError(validationMsg);
}
boolean firstTime = isisSessionFactory == null;
- if(fireListeners.shouldFire()) {
- fireInitAndPreOpenSession(firstTime);
- }
-
if(firstTime) {
IsisLoggingConfigurer isisLoggingConfigurer = new IsisLoggingConfigurer(getLevel());
isisLoggingConfigurer.configureLogging(".", new String[] {});
@@ -326,7 +252,7 @@ public class IsisSystem {
for (String validationError : validationErrors) {
buf.append(validationError).append("\n");
}
- fail("Metamodel is invalid: \n" + buf.toString());
+ throw new AssertionError("Metamodel is invalid: \n" + buf.toString());
}
}
@@ -334,10 +260,6 @@ public class IsisSystem {
authenticationSession = authenticationManager.authenticate(authenticationRequestIfAny);
openSession();
-
- if(fireListeners.shouldFire()) {
- firePostOpenSession(firstTime);
- }
}
public DomainObjectContainer getContainer() {
@@ -365,33 +287,16 @@ public class IsisSystem {
//endregion
- //region > teardown
+ //region > openSession, closeSession, nextSession
- private void closeSession(final FireListeners fireListeners) throws Exception {
- if(fireListeners.shouldFire()) {
- firePreCloseSession();
- }
- if(isisSessionFactory.inSession()) {
- isisSessionFactory.closeSession();
- }
- if(fireListeners.shouldFire()) {
- firePostCloseSession();
- }
- }
public void nextSession() throws Exception {
- firePreNextSession();
closeSession();
openSession();
- firePostNextSession();
}
- //endregion
-
- //region > openSession, closeSession
public void openSession() throws Exception {
openSession(authenticationSession);
-
}
public void openSession(AuthenticationSession authenticationSession) throws Exception {
@@ -399,67 +304,13 @@ public class IsisSystem {
}
public void closeSession() throws Exception {
- closeSession(FireListeners.FIRE);
- }
-
- //endregion
-
- //region > listeners
-
- private List <Listener> listeners;
-
- protected enum FireListeners {
- FIRE,
- DONT_FIRE;
- public boolean shouldFire() {
- return this == FIRE;
- }
- }
-
-
- private void fireInitAndPreOpenSession(boolean firstTime) throws Exception {
- if(firstTime) {
- for(Listener listener: listeners) {
- listener.init(componentProvider.getConfiguration());
- }
- }
- for(Listener listener: listeners) {
- listener.preOpenSession(firstTime);
- }
- }
-
- private void firePostOpenSession(boolean firstTime) throws Exception {
- for(Listener listener: listeners) {
- listener.postOpenSession(firstTime);
- }
- }
-
- private void firePreCloseSession() throws Exception {
- for(Listener listener: listeners) {
- listener.preCloseSession();
- }
- }
-
- private void firePostCloseSession() throws Exception {
- for(Listener listener: listeners) {
- listener.postCloseSession();
- }
- }
-
- private void firePreNextSession() throws Exception {
- for(Listener listener: listeners) {
- listener.preNextSession();
+ if(isisSessionFactory.inSession()) {
+ isisSessionFactory.closeSession();
}
}
- private void firePostNextSession() throws Exception {
- for(Listener listener: listeners) {
- listener.postNextSession();
- }
- }
//endregion
-
//region > beginTran, endTran, commitTran, abortTran
/**
@@ -485,10 +336,9 @@ public class IsisSystem {
// nothing to do
break;
case MUST_ABORT:
- fail("Transaction is in state of '" + state + "'");
- break;
+ throw new AssertionError("Transaction is in state of '" + state + "'");
default:
- fail("Unknown transaction state '" + state + "'");
+ throw new AssertionError("Unknown transaction state '" + state + "'");
}
}
@@ -512,8 +362,7 @@ public class IsisSystem {
final IsisTransactionManager transactionManager = getTransactionManager();
final IsisTransaction transaction = transactionManager.getCurrentTransaction();
if(transaction == null) {
- fail("No transaction exists");
- return;
+ throw new AssertionError("No transaction exists");
}
transactionManager.endTransaction();
@@ -525,13 +374,11 @@ public class IsisSystem {
case ABORTED:
break;
case IN_PROGRESS:
- fail("Transaction is still in state of '" + state + "'");
- break;
+ throw new AssertionError("Transaction is still in state of '" + state + "'");
case MUST_ABORT:
- fail("Transaction is still in state of '" + state + "'");
- break;
+ throw new AssertionError("Transaction is still in state of '" + state + "'");
default:
- fail("Unknown transaction state '" + state + "'");
+ throw new AssertionError("Unknown transaction state '" + state + "'");
}
}
@@ -545,21 +392,19 @@ public class IsisSystem {
final IsisTransactionManager transactionManager = getTransactionManager();
final IsisTransaction transaction = transactionManager.getCurrentTransaction();
if(transaction == null) {
- fail("No transaction exists");
- return;
+ throw new AssertionError("No transaction exists");
}
final State state = transaction.getState();
switch(state) {
case COMMITTED:
case ABORTED:
case MUST_ABORT:
- fail("Transaction is in state of '" + state + "'");
- break;
+ throw new AssertionError("Transaction is in state of '" + state + "'");
case IN_PROGRESS:
transactionManager.endTransaction();
break;
default:
- fail("Unknown transaction state '" + state + "'");
+ throw new AssertionError("Unknown transaction state '" + state + "'");
}
}
@@ -573,22 +418,20 @@ public class IsisSystem {
final IsisTransactionManager transactionManager = getTransactionManager();
final IsisTransaction transaction = transactionManager.getCurrentTransaction();
if(transaction == null) {
- fail("No transaction exists");
- return;
+ throw new AssertionError("No transaction exists");
}
final State state = transaction.getState();
switch(state) {
case ABORTED:
break;
case COMMITTED:
- fail("Transaction is in state of '" + state + "'");
- break;
+ throw new AssertionError("Transaction is in state of '" + state + "'");
case MUST_ABORT:
case IN_PROGRESS:
transactionManager.abortTransaction();
break;
default:
- fail("Unknown transaction state '" + state + "'");
+ throw new AssertionError("Unknown transaction state '" + state + "'");
}
}
diff --git a/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/scenarios/ObjectFactoryForIntegration.java b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/scenarios/ObjectFactoryForIntegration.java
index a52868a..5740214 100644
--- a/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/scenarios/ObjectFactoryForIntegration.java
+++ b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/scenarios/ObjectFactoryForIntegration.java
@@ -5,7 +5,8 @@ import java.util.Map;
import com.google.common.collect.Maps;
-import org.apache.isis.core.specsupport.scenarios.ScenarioExecution;
+import org.apache.isis.applib.services.registry.ServiceRegistry2;
+import org.apache.isis.core.integtestsupport.IsisSystem;
import cucumber.api.java.ObjectFactory;
import cucumber.runtime.CucumberException;
@@ -27,9 +28,10 @@ public class ObjectFactoryForIntegration implements ObjectFactory {
T instance = type.cast(this.instances.get(type));
if (instance == null) {
instance = this.newInstance(type);
- if(ScenarioExecution.peek() != null) {
+ IsisSystem isisSystem = IsisSystem.getElseNull();
+ if(isisSystem != null) {
instance = this.cacheInstance(type, instance);
- ScenarioExecution.current().injectServices(instance);
+ isisSystem.getService(ServiceRegistry2.class).injectServicesInto(instance);
} else {
// don't cache
}
diff --git a/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/scenarios/ScenarioExecutionForIntegration.java b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/scenarios/ScenarioExecutionForIntegration.java
index 07a52b5..fbc9151 100644
--- a/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/scenarios/ScenarioExecutionForIntegration.java
+++ b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/scenarios/ScenarioExecutionForIntegration.java
@@ -19,11 +19,11 @@ package org.apache.isis.core.integtestsupport.scenarios;
import org.apache.isis.applib.fixtures.InstallableFixture;
import org.apache.isis.applib.services.wrapper.WrapperFactory;
import org.apache.isis.core.commons.authentication.AuthenticationSession;
+import org.apache.isis.core.integtestsupport.IntegrationBootstrapAbstract;
import org.apache.isis.core.integtestsupport.IsisSystemForTest;
import org.apache.isis.core.specsupport.scenarios.ScenarioExecution;
import org.apache.isis.core.specsupport.scenarios.ScenarioExecutionScope;
-
/**
* An extension of {@link ScenarioExecution} for use within (coarse grained)
* integration tests and Cucumber specs where there is back-end database.
@@ -33,7 +33,10 @@ import org.apache.isis.core.specsupport.scenarios.ScenarioExecutionScope;
* {@link #install(InstallableFixture...)} (to tear down/setup data)
* and of {@link #beginTran() begin} and {@link #endTran(boolean) end} (
* for transaction management.
+ *
+ * @deprecated - subclass glue from {@link IntegrationBootstrapAbstract} instead, and inject services into glue
*/
+@Deprecated
public class ScenarioExecutionForIntegration extends ScenarioExecution {
private IsisSystemForTest isft;
diff --git a/core/specsupport/src/main/java/org/apache/isis/core/specsupport/scenarios/ScenarioExecution.java b/core/specsupport/src/main/java/org/apache/isis/core/specsupport/scenarios/ScenarioExecution.java
index 511e3cb..a3c7f33 100644
--- a/core/specsupport/src/main/java/org/apache/isis/core/specsupport/scenarios/ScenarioExecution.java
+++ b/core/specsupport/src/main/java/org/apache/isis/core/specsupport/scenarios/ScenarioExecution.java
@@ -61,7 +61,10 @@ import static org.junit.Assert.fail;
* Subclasses may tailor the world for specific types of tests; for example the
* <tt>IntegrationScenarioExecution</tt> provides additional support for fixtures and
* transaction management, used both by integration-scoped specs and by integration tests.
+ *
+ * @deprecated - to be removed in 2.0, will support BDD for integration tests only
*/
+@Deprecated
public abstract class ScenarioExecution {
private static ThreadLocal<ScenarioExecution> current = new ThreadLocal<ScenarioExecution>();
diff --git a/core/specsupport/src/main/java/org/apache/isis/core/specsupport/scenarios/ScenarioExecutionForUnit.java b/core/specsupport/src/main/java/org/apache/isis/core/specsupport/scenarios/ScenarioExecutionForUnit.java
index 9b336ee..7614209 100644
--- a/core/specsupport/src/main/java/org/apache/isis/core/specsupport/scenarios/ScenarioExecutionForUnit.java
+++ b/core/specsupport/src/main/java/org/apache/isis/core/specsupport/scenarios/ScenarioExecutionForUnit.java
@@ -29,7 +29,10 @@ import org.jmock.internal.ExpectationBuilder;
* Expectations can be {@link Mockery#checking(org.jmock.internal.ExpectationBuilder) set}
* and interactions {@link Mockery#assertIsSatisfied() verified} by accessing
* the underlying {@link Mockery}.
+ *
+ * @deprecated - to be removed in 2.0, will support BDD for integration tests only
*/
+@Deprecated
public class ScenarioExecutionForUnit extends ScenarioExecution {
private final DomainServiceProviderMockery dspm;
diff --git a/example/application/simpleapp/application/src/test/java/domainapp/application/bdd/specglue/BootstrappingGlue.java b/example/application/simpleapp/application/src/test/java/domainapp/application/bdd/specglue/BootstrappingGlue.java
index 379afdc..f7515f4 100644
--- a/example/application/simpleapp/application/src/test/java/domainapp/application/bdd/specglue/BootstrappingGlue.java
+++ b/example/application/simpleapp/application/src/test/java/domainapp/application/bdd/specglue/BootstrappingGlue.java
@@ -16,12 +16,26 @@ O * Licensed to the Apache Software Foundation (ASF) under one or more
*/
package domainapp.application.bdd.specglue;
+import org.apache.isis.core.integtestsupport.IntegrationBootstrapAbstract;
+
+import cucumber.api.java.After;
+import cucumber.api.java.Before;
import domainapp.application.DomainAppApplicationModule;
-public class BootstrappingGlue extends BootstrappingGlueAbstract {
+public class BootstrappingGlue extends IntegrationBootstrapAbstract {
public BootstrappingGlue() {
super(new DomainAppApplicationModule());
}
+ @Before(order=100)
+ public void beforeScenario() {
+ super.bootstrapAndSetupIfRequired();
+ }
+
+ @After
+ public void afterScenario(cucumber.api.Scenario sc) {
+ super.tearDownAllModules();
+ }
+
}
diff --git a/example/application/simpleapp/application/src/test/java/domainapp/application/bdd/specglue/BootstrappingGlueAbstract.java b/example/application/simpleapp/application/src/test/java/domainapp/application/bdd/specglue/BootstrappingGlueAbstract.java
deleted file mode 100644
index 2ba0542..0000000
--- a/example/application/simpleapp/application/src/test/java/domainapp/application/bdd/specglue/BootstrappingGlueAbstract.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/**
-O * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package domainapp.application.bdd.specglue;
-
-import org.apache.isis.applib.Module;
-import org.apache.isis.core.integtestsupport.IntegrationTestAbstract3;
-import org.apache.isis.core.specsupport.scenarios.ScenarioExecutionScope;
-import org.apache.isis.core.specsupport.specs.CukeGlueAbstract;
-
-import cucumber.api.java.After;
-import cucumber.api.java.Before;
-
-public abstract class BootstrappingGlueAbstract extends CukeGlueAbstract {
-
- private final Module module;
- private final Class[] additionalModuleClasses;
-
- public BootstrappingGlueAbstract(final Module module, final Class... additionalModuleClasses) {
- this.module = module;
- this.additionalModuleClasses = additionalModuleClasses;
- }
-
- @Before(value={"@integration"}, order=100)
- public void beforeScenarioIntegrationScope() {
-
- IntegrationTestAbstract3 integTest =
- new IntegrationTestAbstract3(module, additionalModuleClasses) {};
- integTest.bootstrapAndSetupIfRequired();
-
- before(ScenarioExecutionScope.INTEGRATION);
-
- scenarioExecution().putVar(IntegrationTestAbstract3.class.getName(), "current", integTest);
- }
-
- @After
- public void afterScenario(cucumber.api.Scenario sc) {
- assertMocksSatisfied();
-
- IntegrationTestAbstract3 integTest =
- scenarioExecution().getVar(IntegrationTestAbstract3.class.getName(), "current",
- IntegrationTestAbstract3.class);
- integTest.tearDownAllModules();
-
- after(sc);
- }
-}
diff --git a/example/application/simpleapp/application/src/test/java/domainapp/application/bdd/specglue/CatalogOfFixturesGlue.java b/example/application/simpleapp/application/src/test/java/domainapp/application/bdd/specglue/CatalogOfFixturesGlue.java
index 9d6b816..0fb8a81 100644
--- a/example/application/simpleapp/application/src/test/java/domainapp/application/bdd/specglue/CatalogOfFixturesGlue.java
+++ b/example/application/simpleapp/application/src/test/java/domainapp/application/bdd/specglue/CatalogOfFixturesGlue.java
@@ -19,14 +19,14 @@ package domainapp.application.bdd.specglue;
import javax.inject.Inject;
import org.apache.isis.applib.fixturescripts.FixtureScripts;
-import org.apache.isis.core.specsupport.specs.CukeGlueAbstract;
+import org.apache.isis.core.integtestsupport.IntegrationAbstract;
import cucumber.api.java.Before;
import domainapp.application.fixture.scenarios.DomainAppDemo;
-public class CatalogOfFixturesGlue extends CukeGlueAbstract {
+public class CatalogOfFixturesGlue extends IntegrationAbstract {
- @Before(value={"@integration", "@DomainAppDemo"}, order=20000)
+ @Before(value={"@DomainAppDemo"}, order=20000)
public void integrationFixtures() throws Throwable {
fixtureScripts.runFixtureScript(new DomainAppDemo(), null);
}
diff --git a/example/application/simpleapp/application/src/test/java/domainapp/application/bdd/specs/SimpleObjectSpec_listAllAndCreate.feature b/example/application/simpleapp/application/src/test/java/domainapp/application/bdd/specs/SimpleObjectSpec_listAllAndCreate.feature
index 24d69b7..f164d92 100644
--- a/example/application/simpleapp/application/src/test/java/domainapp/application/bdd/specs/SimpleObjectSpec_listAllAndCreate.feature
+++ b/example/application/simpleapp/application/src/test/java/domainapp/application/bdd/specs/SimpleObjectSpec_listAllAndCreate.feature
@@ -17,7 +17,6 @@
@DomainAppDemo
Feature: List and Create New Simple Objects
- @integration
Scenario: Existing simple objects can be listed and new ones created
Given there are initially 10 simple objects
When I create a new simple object
diff --git a/example/application/simpleapp/module-simple/src/test/java/domainapp/modules/simple/specglue/SimpleObjectMenuGlue.java b/example/application/simpleapp/module-simple/src/test/java/domainapp/modules/simple/specglue/SimpleObjectMenuGlue.java
index ffa3ba2..66816fb 100644
--- a/example/application/simpleapp/module-simple/src/test/java/domainapp/modules/simple/specglue/SimpleObjectMenuGlue.java
+++ b/example/application/simpleapp/module-simple/src/test/java/domainapp/modules/simple/specglue/SimpleObjectMenuGlue.java
@@ -21,7 +21,7 @@ import java.util.UUID;
import javax.inject.Inject;
-import org.apache.isis.core.specsupport.specs.CukeGlueAbstract;
+import org.apache.isis.core.integtestsupport.IntegrationAbstract;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.When;
@@ -30,17 +30,12 @@ import domainapp.modules.simple.dom.impl.SimpleObjectMenu;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
-public class SimpleObjectMenuGlue extends CukeGlueAbstract {
+public class SimpleObjectMenuGlue extends IntegrationAbstract {
@Given("^there are.* (\\d+) simple objects$")
public void there_are_N_simple_objects(int n) throws Throwable {
- try {
- final List<SimpleObject> list = wrap(simpleObjectMenu).listAll();
- assertThat(list.size(), is(n));
- putVar("java.util.List", "simpleObjects", list);
- } finally {
- assertMocksSatisfied();
- }
+ final List<SimpleObject> list = wrap(simpleObjectMenu).listAll();
+ assertThat(list.size(), is(n));
}
@When("^.*create a .*simple object$")
--
To stop receiving notification emails like this one, please contact
"commits@isis.apache.org" <co...@isis.apache.org>.