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 2022/08/30 21:53:46 UTC
[isis-app-simpleapp] 03/03: no joy yet
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch attempting-to-bring-in-bdd-specs
in repository https://gitbox.apache.org/repos/asf/isis-app-simpleapp.git
commit 70d13bc3e563ce942c4a2c40586df1d388ef0c10
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Tue Aug 30 22:53:34 2022 +0100
no joy yet
---
.../webapp/bdd/specs/CucumberTestAbstract.java | 81 ++++++++++++-
.../testdomain/conf/Configuration_headless.java | 130 +++++++++++++++++++++
.../isis/testdomain/cucumber/CucumberTest.java} | 27 +++--
.../apache/isis/testdomain/cucumber/StepDefs.java | 61 ++++++++++
.../src/test/resources/application-test.properties | 8 +-
.../webapp/bdd/specs/is_it_friday_yet.feature | 8 ++
.../src/test/resources/junit-platform.properties | 27 ++++-
.../testdomain/cucumber/is_it_friday_yet.feature | 8 ++
8 files changed, 333 insertions(+), 17 deletions(-)
diff --git a/webapp-tests/src/test/java/domainapp/webapp/bdd/specs/CucumberTestAbstract.java b/webapp-tests/src/test/java/domainapp/webapp/bdd/specs/CucumberTestAbstract.java
index d19ba11..2471ebe 100644
--- a/webapp-tests/src/test/java/domainapp/webapp/bdd/specs/CucumberTestAbstract.java
+++ b/webapp-tests/src/test/java/domainapp/webapp/bdd/specs/CucumberTestAbstract.java
@@ -18,7 +18,30 @@
*/
package domainapp.webapp.bdd.specs;
+import org.springframework.boot.SpringBootConfiguration;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Import;
+import org.springframework.context.annotation.PropertySource;
+import org.springframework.context.annotation.PropertySources;
+import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
+import org.springframework.test.context.ActiveProfiles;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.apache.isis.core.config.presets.IsisPresets;
+import org.apache.isis.core.runtimeservices.IsisModuleCoreRuntimeServices;
+import org.apache.isis.persistence.jpa.eclipselink.IsisModulePersistenceJpaEclipselink;
+import org.apache.isis.security.bypass.IsisModuleSecurityBypass;
+import org.apache.isis.testing.fixtures.applib.IsisModuleTestingFixturesApplib;
+import org.apache.isis.testing.integtestsupport.applib.IsisIntegrationTestAbstract;
+
+import domainapp.modules.simple.SimpleModule;
+import domainapp.webapp.application.ApplicationModule;
import domainapp.webapp.integtests.WebAppIntegTestAbstract;
+import io.cucumber.java.en.Given;
+import io.cucumber.java.en.Then;
+import io.cucumber.java.en.When;
import io.cucumber.spring.CucumberContextConfiguration;
/**
@@ -26,9 +49,63 @@ import io.cucumber.spring.CucumberContextConfiguration;
* Provides the App's Spring Context for testing with Cucumber.
*
*/
+@SpringBootTest(
+ classes = {
+ // we use a slightly different configuration compared to the production (AppManifest/webapp)
+ domainapp.webapp.integtests.WebAppIntegTestAbstract.TestApp.class,
+ BddStepDefsModule.class,
+ ApplicationModule.class,
+ }
+)
@CucumberContextConfiguration
-public abstract class CucumberTestAbstract extends WebAppIntegTestAbstract {
+@ActiveProfiles("test")
+public abstract class CucumberTestAbstract extends IsisIntegrationTestAbstract {
+
+ /**
+ * Compared to the production app manifest <code>domainapp.webapp.AppManifest</code>,
+ * here we in effect disable security checks, and we exclude any web/UI modules.
+ */
+ @SpringBootConfiguration
+ @EnableAutoConfiguration
+ @EnableJpaRepositories
+ @Import({
+
+ IsisModuleCoreRuntimeServices.class,
+ IsisModuleSecurityBypass.class,
+ IsisModulePersistenceJpaEclipselink.class,
+ IsisModuleTestingFixturesApplib.class,
+
+ SimpleModule.class
+ })
+ @PropertySources({
+ @PropertySource(IsisPresets.H2InMemory_withUniqueSchema),
+ @PropertySource(IsisPresets.UseLog4j2Test),
+ })
+ public static class TestApp {
+
+ }
+
+ private String today;
+ private String actualAnswer;
+
+// @Given("today is Sunday")
+// public void today_is_sunday() {
+// this.today = "Sunday";
+// }
+
+ @Given("^today is (.+)$")
+ public void today_is(final String today) {
+ this.today = today;
+ }
+
+ @When("I ask whether it's Friday yet")
+ public void i_ask_whether_it_s_Friday_yet() {
+ actualAnswer = "Friday".equals(today) ? "TGIF" : "Nope";
+ }
- // any cucumber specific stuff might go here
+ @Then("I should be told {string}")
+ public void i_should_be_told(final String expectedAnswer) {
+ assertEquals(expectedAnswer, actualAnswer);
+ }
}
diff --git a/webapp-tests/src/test/java/org/apache/isis/testdomain/conf/Configuration_headless.java b/webapp-tests/src/test/java/org/apache/isis/testdomain/conf/Configuration_headless.java
new file mode 100644
index 0000000..ba14c24
--- /dev/null
+++ b/webapp-tests/src/test/java/org/apache/isis/testdomain/conf/Configuration_headless.java
@@ -0,0 +1,130 @@
+/*
+ * 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.testdomain.conf;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+import org.springframework.context.annotation.PropertySource;
+import org.springframework.context.annotation.PropertySources;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.PlatformTransactionManager;
+import org.springframework.transaction.TransactionDefinition;
+import org.springframework.transaction.TransactionException;
+import org.springframework.transaction.TransactionStatus;
+
+import org.apache.isis.applib.annotation.PriorityPrecedence;
+import org.apache.isis.applib.services.iactn.Interaction;
+import org.apache.isis.applib.services.metrics.MetricsService;
+import org.apache.isis.core.config.presets.IsisPresets;
+import org.apache.isis.core.interaction.scope.TransactionBoundaryAware;
+import org.apache.isis.core.runtimeservices.IsisModuleCoreRuntimeServices;
+import org.apache.isis.security.bypass.IsisModuleSecurityBypass;
+//import org.apache.isis.testdomain.util.interaction.DomainObjectTesterFactory;
+//import org.apache.isis.testdomain.util.kv.KVStoreForTesting;
+
+import lombok.RequiredArgsConstructor;
+
+@Configuration
+@Import({
+ IsisModuleCoreRuntimeServices.class,
+ IsisModuleSecurityBypass.class,
+ Configuration_headless.HeadlessCommandSupport.class,
+// KVStoreForTesting.class, // Helper for JUnit Tests
+// DomainObjectTesterFactory.class // Helper for JUnit Tests
+})
+@PropertySources({
+ @PropertySource(IsisPresets.NoTranslations),
+})
+public class Configuration_headless {
+
+ @Service
+ @javax.annotation.Priority(PriorityPrecedence.MIDPOINT)
+ @RequiredArgsConstructor(onConstructor_ = {@Inject})
+ public static class HeadlessCommandSupport
+ implements TransactionBoundaryAware {
+
+ @Override
+ public void beforeEnteringTransactionalBoundary(final Interaction interaction) {
+// _Probe.errOut("Interaction HAS_STARTED conversationId=%s", interaction.getInteractionId());
+ setupCommandCreateIfMissing();
+ }
+
+ @Override
+ public void afterLeavingTransactionalBoundary(final Interaction interaction) {
+// _Probe.errOut("Interaction IS_ENDING conversationId=%s", interaction.getInteractionId());
+ }
+
+ public void setupCommandCreateIfMissing() {
+
+// val interactionProvider = interactionProviderProvider.get();
+// @SuppressWarnings("unused")
+// final Interaction interaction = Optional.ofNullable(interactionContext.getInteraction())
+// .orElseGet(()->{
+// val newCommand = new Command();
+// val newInteraction = new Interaction(newCommand);
+// interactionProvider.setInteraction(newInteraction);
+// return newInteraction;
+// });
+ }
+
+ }
+
+ @Bean @Singleton
+ public PlatformTransactionManager platformTransactionManager() {
+ return new PlatformTransactionManager() {
+
+ @Override
+ public void rollback(final TransactionStatus status) throws TransactionException {
+ }
+
+ @Override
+ public TransactionStatus getTransaction(final TransactionDefinition definition) throws TransactionException {
+ return null;
+ }
+
+ @Override
+ public void commit(final TransactionStatus status) throws TransactionException {
+ }
+ };
+ }
+
+
+ @Bean @Singleton
+ public MetricsService metricsService() {
+ return new MetricsService() {
+
+ @Override
+ public int numberEntitiesLoaded() {
+ return 0;
+ }
+
+ @Override
+ public int numberEntitiesDirtied() {
+ return 0;
+ }
+
+ };
+ }
+
+
+}
diff --git a/webapp-tests/src/test/java/domainapp/webapp/bdd/specs/CucumberTestAbstract.java b/webapp-tests/src/test/java/org/apache/isis/testdomain/cucumber/CucumberTest.java
similarity index 51%
copy from webapp-tests/src/test/java/domainapp/webapp/bdd/specs/CucumberTestAbstract.java
copy to webapp-tests/src/test/java/org/apache/isis/testdomain/cucumber/CucumberTest.java
index d19ba11..7a7c373 100644
--- a/webapp-tests/src/test/java/domainapp/webapp/bdd/specs/CucumberTestAbstract.java
+++ b/webapp-tests/src/test/java/org/apache/isis/testdomain/cucumber/CucumberTest.java
@@ -16,19 +16,28 @@
* specific language governing permissions and limitations
* under the License.
*/
-package domainapp.webapp.bdd.specs;
+package org.apache.isis.testdomain.cucumber;
+
+import org.junit.platform.suite.api.IncludeEngines;
+import org.junit.platform.suite.api.SelectClasspathResource;
+import org.junit.platform.suite.api.Suite;
-import domainapp.webapp.integtests.WebAppIntegTestAbstract;
-import io.cucumber.spring.CucumberContextConfiguration;
/**
- *
- * Provides the App's Spring Context for testing with Cucumber.
- *
+ * Cucumber will scan this package for feature files.
+ * <p>
+ * Make sure this class name ends with Test, as Surefire when bundled with Apache Isis
+ * filters JUnit tests also by class name.
*/
-@CucumberContextConfiguration
-public abstract class CucumberTestAbstract extends WebAppIntegTestAbstract {
+@Suite
+@IncludeEngines("cucumber")
+@SelectClasspathResource("org/apache/isis/testdomain/cucumber")
+public class CucumberTest {
- // any cucumber specific stuff might go here
+ // See 7.x:
+ // https://github.com/cucumber/cucumber-jvm/blob/main/release-notes/v7.0.0.md
+ // See 6.x:
+ // https://github.com/cucumber/cucumber-jvm/issues/1149
+ // https://github.com/cucumber/cucumber-jvm/tree/master/junit-platform-engine
}
diff --git a/webapp-tests/src/test/java/org/apache/isis/testdomain/cucumber/StepDefs.java b/webapp-tests/src/test/java/org/apache/isis/testdomain/cucumber/StepDefs.java
new file mode 100644
index 0000000..13c587e
--- /dev/null
+++ b/webapp-tests/src/test/java/org/apache/isis/testdomain/cucumber/StepDefs.java
@@ -0,0 +1,61 @@
+/*
+ * 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.testdomain.cucumber;
+
+import org.springframework.boot.test.context.SpringBootTest;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+
+import org.apache.isis.testdomain.conf.Configuration_headless;
+
+import io.cucumber.java.en.Given;
+import io.cucumber.java.en.Then;
+import io.cucumber.java.en.When;
+import io.cucumber.spring.CucumberContextConfiguration;
+
+@CucumberContextConfiguration
+@SpringBootTest(
+ classes = {
+ Configuration_headless.class,
+ })
+public class StepDefs {
+ private String today;
+ private String actualAnswer;
+
+// @Given("today is Sunday")
+// public void today_is_sunday() {
+// this.today = "Sunday";
+// }
+
+ @Given("^today is (.+)$")
+ public void today_is(final String today) {
+ this.today = today;
+ }
+
+ @When("I ask whether it's Friday yet")
+ public void i_ask_whether_it_s_Friday_yet() {
+ actualAnswer = "Friday".equals(today) ? "TGIF" : "Nope";
+ }
+
+ @Then("I should be told {string}")
+ public void i_should_be_told(final String expectedAnswer) {
+ assertEquals(expectedAnswer, actualAnswer);
+ }
+}
diff --git a/webapp-tests/src/test/resources/application-test.properties b/webapp-tests/src/test/resources/application-test.properties
index eaf3275..7951c94 100644
--- a/webapp-tests/src/test/resources/application-test.properties
+++ b/webapp-tests/src/test/resources/application-test.properties
@@ -1,4 +1,4 @@
-eclipselink.weaving=false
-eclipselink.weaving.changetracking=false
-eclipselink.weaving.internal=false
-eclipselink.weaving.lazy=false
+#eclipselink.weaving=false
+#eclipselink.weaving.changetracking=false
+#eclipselink.weaving.internal=false
+#eclipselink.weaving.lazy=false
diff --git a/webapp-tests/src/test/resources/domainapp/webapp/bdd/specs/is_it_friday_yet.feature b/webapp-tests/src/test/resources/domainapp/webapp/bdd/specs/is_it_friday_yet.feature
new file mode 100644
index 0000000..b93e94b
--- /dev/null
+++ b/webapp-tests/src/test/resources/domainapp/webapp/bdd/specs/is_it_friday_yet.feature
@@ -0,0 +1,8 @@
+Feature: Is it Friday yet?
+ Everybody wants to know when it's Friday
+
+ Scenario: Sunday isn't Friday
+ Given today is Sunday
+ When I ask whether it's Friday yet
+ Then I should be told "Nope"
+
diff --git a/webapp-tests/src/test/resources/junit-platform.properties b/webapp-tests/src/test/resources/junit-platform.properties
index d4347d9..2d2392b 100644
--- a/webapp-tests/src/test/resources/junit-platform.properties
+++ b/webapp-tests/src/test/resources/junit-platform.properties
@@ -1,8 +1,31 @@
+## as per https://github.com/cucumber/cucumber-jvm/tree/master/junit-platform-engine#configuration-options
+#cucumber.publish.quiet=true
+#cucumber.filter.tags=not @backlog and not @ignore
+#
+#cucumber.glue=domainapp.webapp.bdd.specs
+##we are using built-in reporting plugins
+#cucumber.plugin=pretty, html:target/cucumber-reports/cucumber-report.html
+#
+#cucumber.junit-platform.naming-strategy=long
+#
+## WARNING:
+##
+## cucumber.plugin=..., json:target/cucumber-reports/cucumber-report.json, ...
+##
+## will cause an empty file to be created when running from mvn.
+##
+## this is why the maven configuration to execute cucumber using the CLI (antrun:run@cucumber-cli)
+## is configured to use --plugins json:target/cucumber-no-clobber.json
+##
+
+
+
+
# as per https://github.com/cucumber/cucumber-jvm/tree/master/junit-platform-engine#configuration-options
cucumber.publish.quiet=true
cucumber.filter.tags=not @backlog and not @ignore
-
-cucumber.glue=domainapp.webapp.bdd.specs
+#we are using @Cucumber annotated classes and restrict classpath search to
+cucumber.glue=org.apache.isis.testdomain.cucumber
#we are using built-in reporting plugins
cucumber.plugin=pretty, html:target/cucumber-reports/cucumber-report.html
diff --git a/webapp-tests/src/test/resources/org/apache/isis/testdomain/cucumber/is_it_friday_yet.feature b/webapp-tests/src/test/resources/org/apache/isis/testdomain/cucumber/is_it_friday_yet.feature
new file mode 100644
index 0000000..b93e94b
--- /dev/null
+++ b/webapp-tests/src/test/resources/org/apache/isis/testdomain/cucumber/is_it_friday_yet.feature
@@ -0,0 +1,8 @@
+Feature: Is it Friday yet?
+ Everybody wants to know when it's Friday
+
+ Scenario: Sunday isn't Friday
+ Given today is Sunday
+ When I ask whether it's Friday yet
+ Then I should be told "Nope"
+