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 2019/06/06 10:19:11 UTC
[isis] branch 2112_SpringBoot updated: ISIS-2112: integrate with
Spring's transaction infrastructure
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch 2112_SpringBoot
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/2112_SpringBoot by this push:
new 7120e16 ISIS-2112: integrate with Spring's transaction infrastructure
7120e16 is described below
commit 7120e160c27ad25f1fb1efeba2d35d83bd053e54
Author: Andi Huber <ah...@apache.org>
AuthorDate: Thu Jun 6 12:19:03 2019 +0200
ISIS-2112: integrate with Spring's transaction infrastructure
- sprint-tx integration as proof of concept for integration testing
Task-Url: https://issues.apache.org/jira/browse/ISIS-2112
---
example/misc/smoketest/pom.xml | 7 +
.../incubator/IsisTransactionManagerForJdo.java | 89 ++++++++++
.../isis/testdomain/tests/AuditerServiceTest.java | 181 ++++++++++-----------
.../testdomain/tests/JdoBootstrappingTest.java | 124 ++++++--------
.../tests/JdoBootstrappingTest_usingFixtures.java | 131 +++++++--------
.../testdomain/tests/PublisherServiceTest.java | 177 ++++++++++----------
.../tests/SpringEventPublishingTest.java | 150 ++++++++---------
.../tests/SpringServiceProvisioningTest.java | 100 ++++++------
.../isis/testdomain/tests/Util_H2Console.java | 20 ++-
9 files changed, 516 insertions(+), 463 deletions(-)
diff --git a/example/misc/smoketest/pom.xml b/example/misc/smoketest/pom.xml
index d328001..6231c78 100644
--- a/example/misc/smoketest/pom.xml
+++ b/example/misc/smoketest/pom.xml
@@ -51,6 +51,13 @@
<scope>provided</scope>
</dependency>
+<!-- experimental -->
+<dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-tx</artifactId>
+ <version>5.1.7.RELEASE</version>
+</dependency>
+
<!-- ISIS API -->
<dependency>
<groupId>org.apache.isis.core</groupId>
diff --git a/example/misc/smoketest/src/main/java/org/apache/isis/incubator/IsisTransactionManagerForJdo.java b/example/misc/smoketest/src/main/java/org/apache/isis/incubator/IsisTransactionManagerForJdo.java
new file mode 100644
index 0000000..3fde53e
--- /dev/null
+++ b/example/misc/smoketest/src/main/java/org/apache/isis/incubator/IsisTransactionManagerForJdo.java
@@ -0,0 +1,89 @@
+/*
+ * 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.incubator;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.apache.isis.applib.services.xactn.TransactionService;
+import org.apache.isis.core.runtime.system.internal.InitialisationSession;
+import org.apache.isis.core.runtime.system.session.IsisSession;
+import org.apache.isis.core.runtime.system.session.IsisSessionFactory;
+import org.springframework.transaction.PlatformTransactionManager;
+import org.springframework.transaction.TransactionDefinition;
+import org.springframework.transaction.TransactionException;
+import org.springframework.transaction.TransactionStatus;
+import org.springframework.transaction.support.SimpleTransactionStatus;
+
+import lombok.val;
+import lombok.extern.log4j.Log4j2;
+
+@Singleton @Log4j2
+public class IsisTransactionManagerForJdo implements PlatformTransactionManager {
+
+ @Inject private IsisSessionFactory isisSessionFactory;
+ @Inject private TransactionService transactionService;
+
+ @Override
+ public TransactionStatus getTransaction(TransactionDefinition definition) throws TransactionException {
+
+ log.debug("get a transaction {}", ()->""+definition);
+
+ if(!IsisSession.isInSession()) {
+ isisSessionFactory.openSession(new InitialisationSession());
+ }
+
+ transactionService.nextTransaction();
+
+ val isNewTransaction = true;
+
+ return new SimpleTransactionStatus(isNewTransaction) {
+
+ @Override
+ public void flush() {
+ val tx = transactionService.currentTransaction();
+ if(tx.getTransactionState().canFlush()) {
+ tx.flush();
+ }
+ }
+
+ @Override
+ public boolean isCompleted() {
+ val tx = transactionService.currentTransaction();
+ return tx.getTransactionState().isComplete();
+ }
+ };
+ }
+
+ @Override
+ public void commit(TransactionStatus status) throws TransactionException {
+ log.debug("about to commit {}", ()->""+status);
+
+ transactionService.nextTransaction();
+ ((SimpleTransactionStatus)status).setCompleted();
+ }
+
+ @Override
+ public void rollback(TransactionStatus status) throws TransactionException {
+ log.debug("about to rollback {}", ()->""+status);
+ log.warn("not implemented yet");
+ }
+
+
+}
diff --git a/example/misc/smoketest/src/test/java/org/apache/isis/testdomain/tests/AuditerServiceTest.java b/example/misc/smoketest/src/test/java/org/apache/isis/testdomain/tests/AuditerServiceTest.java
index d7edf12..8d8c056 100644
--- a/example/misc/smoketest/src/test/java/org/apache/isis/testdomain/tests/AuditerServiceTest.java
+++ b/example/misc/smoketest/src/test/java/org/apache/isis/testdomain/tests/AuditerServiceTest.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.tests;
@@ -43,88 +45,77 @@ import lombok.val;
/**
* Depends on {@link JdoBootstrappingTest_usingFixtures} to succeed.
*/
-@Disabled //TODO[2112] activate tests
+@Disabled // TODO[2112] activate tests
class AuditerServiceTest {
-
- @Inject FixtureScripts fixtureScripts;
-
- @BeforeEach
- void setUp() {
-
- // cleanup
- fixtureScripts.runBuilderScript(
- JdoTestDomainPersona.PurgeAll.builder());
-
- // given
- fixtureScripts.runBuilderScript(
- JdoTestDomainPersona.InventoryWith1Book.builder());
- }
-
- @Test
- void auditerServiceShouldBeAwareOfInventoryChanges() {
-
- val auditerServiceAny = IsisContext.getServiceRegistry()
- .lookupServiceElseFail(AuditerService.class);
-
- // priority based service lookup (could be a test on its own)
- assertEquals(AuditerServiceStub.class, auditerServiceAny.getClass());
-
-
- // given
- val auditerService = (AuditerServiceStub) auditerServiceAny;
- val repository = IsisContext.getServiceRegistry()
- .lookupServiceElseFail(RepositoryService.class);
- val txMan = IsisContext.getPersistenceSession().get().getTransactionManager();
- val book = repository.allInstances(Book.class).listIterator().next();
-
- // when
- auditerService.clearHistory();
- book.setName("Book #2");
- repository.persist(book);
- txMan.endTransaction();
-
- // then
- assertEquals(
- "targetClassName=Book,propertyName=name,preValue=Sample Book,postValue=Book #2;",
- auditerService.getHistory());
- }
-
- // -- HELPER
-
- @DomainService(menuOrder="1.0", nature=NatureOfService.DOMAIN)
- @DomainServiceLayout()
- public static class AuditerServiceStub implements AuditerService {
-
- private StringBuilder history = new StringBuilder();
-
- @Override
- public boolean isEnabled() {
- return true;
- }
-
- @Override
- public void audit(
- UUID interactionId, int sequence, String targetClassName, Bookmark target,
- String memberIdentifier, String propertyName,
- String preValue, String postValue, String user,
- Timestamp timestamp) {
-
- history
- .append("targetClassName=").append(targetClassName).append(",")
- .append("propertyName=").append(propertyName).append(",")
- .append("preValue=").append(preValue).append(",")
- .append("postValue=").append(postValue).append(";")
- ;
- }
-
- void clearHistory() {
- history = new StringBuilder();
- }
-
- String getHistory() {
- return history.toString();
- }
-
- }
-
+
+ @Inject private FixtureScripts fixtureScripts;
+
+ @BeforeEach
+ void setUp() {
+
+ // cleanup
+ fixtureScripts.runBuilderScript(JdoTestDomainPersona.PurgeAll.builder());
+
+ // given
+ fixtureScripts.runBuilderScript(JdoTestDomainPersona.InventoryWith1Book.builder());
+ }
+
+ @Test
+ void auditerServiceShouldBeAwareOfInventoryChanges() {
+
+ val auditerServiceAny = IsisContext.getServiceRegistry().lookupServiceElseFail(AuditerService.class);
+
+ // priority based service lookup (could be a test on its own)
+ assertEquals(AuditerServiceStub.class, auditerServiceAny.getClass());
+
+ // given
+ val auditerService = (AuditerServiceStub) auditerServiceAny;
+ val repository = IsisContext.getServiceRegistry().lookupServiceElseFail(RepositoryService.class);
+ val txMan = IsisContext.getPersistenceSession().get().getTransactionManager();
+ val book = repository.allInstances(Book.class).listIterator().next();
+
+ // when
+ auditerService.clearHistory();
+ book.setName("Book #2");
+ repository.persist(book);
+ txMan.endTransaction();
+
+ // then
+ assertEquals("targetClassName=Book,propertyName=name,preValue=Sample Book,postValue=Book #2;",
+ auditerService.getHistory());
+ }
+
+ // -- HELPER
+
+ @DomainService(menuOrder = "1.0", nature = NatureOfService.DOMAIN)
+ @DomainServiceLayout()
+ public static class AuditerServiceStub implements AuditerService {
+
+ private StringBuilder history = new StringBuilder();
+
+ @Override
+ public boolean isEnabled() {
+ return true;
+ }
+
+ @Override
+ public void audit(UUID interactionId, int sequence, String targetClassName, Bookmark target,
+ String memberIdentifier, String propertyName, String preValue, String postValue, String user,
+ Timestamp timestamp) {
+
+ history.append("targetClassName=").append(targetClassName).append(",").append("propertyName=")
+ .append(propertyName).append(",").append("preValue=").append(preValue).append(",")
+ .append("postValue=").append(postValue).append(";");
+ }
+
+ void clearHistory() {
+ history = new StringBuilder();
+ }
+
+ String getHistory() {
+ return history.toString();
+ }
+
+ }
+
}
diff --git a/example/misc/smoketest/src/test/java/org/apache/isis/testdomain/tests/JdoBootstrappingTest.java b/example/misc/smoketest/src/test/java/org/apache/isis/testdomain/tests/JdoBootstrappingTest.java
index 9338808..276a8c6 100644
--- a/example/misc/smoketest/src/test/java/org/apache/isis/testdomain/tests/JdoBootstrappingTest.java
+++ b/example/misc/smoketest/src/test/java/org/apache/isis/testdomain/tests/JdoBootstrappingTest.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.tests;
@@ -25,111 +27,82 @@ import java.util.Set;
import javax.inject.Inject;
-import org.apache.isis.applib.services.fixturespec.FixtureScriptsDefault;
import org.apache.isis.applib.services.repository.RepositoryService;
-import org.apache.isis.applib.services.xactn.TransactionService;
-import org.apache.isis.core.commons.collections.Bin;
-import org.apache.isis.core.runtime.system.internal.InitialisationSession;
-import org.apache.isis.core.runtime.system.session.IsisSessionFactory;
+import org.apache.isis.incubator.IsisTransactionManagerForJdo;
import org.apache.isis.runtime.spring.IsisBoot;
import org.apache.isis.testdomain.jdo.Book;
import org.apache.isis.testdomain.jdo.Inventory;
import org.apache.isis.testdomain.jdo.JdoTestDomainModule;
import org.apache.isis.testdomain.jdo.Product;
-import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.context.junit.jupiter.SpringExtension;
+import org.springframework.test.annotation.Rollback;
+import org.springframework.transaction.annotation.Transactional;
import lombok.val;
-@ExtendWith(SpringExtension.class)
@SpringBootTest(
- classes = {
- IsisBoot.class,
- FixtureScriptsDefault.class,
- JdoTestDomainModule.class,
- },
- properties = {
- "logging.config=log4j2-test.xml",
- //"isis.reflector.introspector.parallelize=false",
- //"logging.level.org.apache.isis.core.metamodel.specloader.specimpl.ObjectSpecificationAbstract=TRACE"
- }
- )
+ classes = {
+ IsisBoot.class,
+ JdoTestDomainModule.class,
+ IsisTransactionManagerForJdo.class,
+ },
+ properties = {
+ "logging.config=log4j2-test.xml",
+ // "isis.reflector.introspector.parallelize=false",
+ "logging.level.org.apache.isis.incubator.IsisTransactionManagerForJdo=DEBUG"
+ //"logging.level.org.apache.isis.core.metamodel.specloader.specimpl.ObjectSpecificationAbstract=TRACE"
+})
+@Transactional
class JdoBootstrappingTest {
- @Inject private IsisSessionFactory isisSessionFactory;
- @Inject private TransactionService transactionService;
@Inject private RepositoryService repository;
@BeforeAll
static void launchH2Console() throws SQLException {
- // for troubleshooting ...
- //Util_H2Console.main(null);
+ // for troubleshooting ...
+ // Util_H2Console.main(null);
}
-
- @BeforeEach
- void beforeEach() {
- isisSessionFactory.openSession(new InitialisationSession());
- transactionService.nextTransaction();
- }
-
- @AfterEach
- void afterEach() {
- isisSessionFactory.closeSession();
- }
-
+
void cleanUp() {
- repository.allInstances(Inventory.class)
- .forEach(repository::remove);
-
- repository.allInstances(Book.class)
- .forEach(repository::remove);
-
- repository.allInstances(Product.class)
- .forEach(repository::remove);
+ repository.allInstances(Inventory.class).forEach(repository::remove);
+ repository.allInstances(Book.class).forEach(repository::remove);
+ repository.allInstances(Product.class).forEach(repository::remove);
}
-
- void setUp() {
-
+
+ void setUp() {
+
// setup sample Inventory
Set<Product> products = new HashSet<>();
- products.add(Book.of(
- "Sample Book", "A sample book for testing.", 99.,
- "Sample Author", "Sample ISBN", "Sample Publisher"));
+ products.add(Book.of("Sample Book", "A sample book for testing.", 99., "Sample Author", "Sample ISBN",
+ "Sample Publisher"));
val inventory = Inventory.of("Sample Inventory", products);
repository.persist(inventory);
}
- @Test
+ @Test @Rollback(false)
void sampleInventoryShouldBeSetUp() {
// given - expected pre condition: no inventories
-
- cleanUp();
+
+ cleanUp();
assertEquals(0, repository.allInstances(Inventory.class).size());
-
+
// when
-
- transactionService.nextTransaction();
- setUp();
+ setUp();
// then - expected post condition: ONE inventory
- transactionService.nextTransaction();
-
- val inventories = Bin.ofCollection(repository.allInstances(Inventory.class));
+ val inventories =repository.allInstances(Inventory.class);
assertEquals(1, inventories.size());
-
- val inventory = inventories.getSingleton().get();
+
+ val inventory = inventories.get(0);
assertNotNull(inventory);
assertNotNull(inventory.getProducts());
assertEquals(1, inventory.getProducts().size());
@@ -139,5 +112,4 @@ class JdoBootstrappingTest {
}
-
}
diff --git a/example/misc/smoketest/src/test/java/org/apache/isis/testdomain/tests/JdoBootstrappingTest_usingFixtures.java b/example/misc/smoketest/src/test/java/org/apache/isis/testdomain/tests/JdoBootstrappingTest_usingFixtures.java
index 41089c0..75be252 100644
--- a/example/misc/smoketest/src/test/java/org/apache/isis/testdomain/tests/JdoBootstrappingTest_usingFixtures.java
+++ b/example/misc/smoketest/src/test/java/org/apache/isis/testdomain/tests/JdoBootstrappingTest_usingFixtures.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.tests;
@@ -24,81 +26,60 @@ import javax.inject.Inject;
import org.apache.isis.applib.fixturescripts.FixtureScripts;
import org.apache.isis.applib.services.fixturespec.FixtureScriptsDefault;
import org.apache.isis.applib.services.repository.RepositoryService;
-import org.apache.isis.applib.services.xactn.TransactionService;
-import org.apache.isis.core.commons.collections.Bin;
-import org.apache.isis.core.runtime.system.internal.InitialisationSession;
-import org.apache.isis.core.runtime.system.session.IsisSessionFactory;
+import org.apache.isis.incubator.IsisTransactionManagerForJdo;
import org.apache.isis.runtime.spring.IsisBoot;
import org.apache.isis.testdomain.jdo.Inventory;
import org.apache.isis.testdomain.jdo.JdoTestDomainModule;
import org.apache.isis.testdomain.jdo.JdoTestDomainPersona;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.context.junit.jupiter.SpringExtension;
+import org.springframework.test.annotation.Rollback;
+import org.springframework.transaction.annotation.Transactional;
import lombok.val;
-@ExtendWith(SpringExtension.class)
@SpringBootTest(
- classes = {
- IsisBoot.class,
- FixtureScriptsDefault.class,
- JdoTestDomainModule.class,
- },
- properties = {
- "logging.config=log4j2-test.xml",
- //"isis.reflector.introspector.parallelize=false",
- //"logging.level.org.apache.isis.core.metamodel.specloader.specimpl.ObjectSpecificationAbstract=TRACE"
- }
- )
+ classes = {
+ IsisBoot.class,
+ FixtureScriptsDefault.class,
+ JdoTestDomainModule.class,
+ IsisTransactionManagerForJdo.class,
+ },
+ properties = {
+ "logging.config=log4j2-test.xml",
+ // "isis.reflector.introspector.parallelize=false",
+ // "logging.level.org.apache.isis.core.metamodel.specloader.specimpl.ObjectSpecificationAbstract=TRACE"
+})
+@Transactional
class JdoBootstrappingTest_usingFixtures {
- @Inject IsisSessionFactory isisSessionFactory;
- @Inject TransactionService transactionService;
- @Inject FixtureScripts fixtureScripts;
- @Inject RepositoryService repository;
-
- @BeforeEach
- void beforeEach() {
- isisSessionFactory.openSession(new InitialisationSession());
- transactionService.nextTransaction();
- }
-
- @AfterEach
- void afterEach() {
- isisSessionFactory.closeSession();
- }
-
- void setUp() {
- // cleanup
- fixtureScripts.runBuilderScript(
- JdoTestDomainPersona.PurgeAll.builder());
-
- // given
- fixtureScripts.runBuilderScript(
- JdoTestDomainPersona.InventoryWith1Book.builder());
- }
-
- @Test
- void sampleInventoryShouldBeSetUp() {
-
- setUp();
-
- val inventories = Bin.ofCollection(repository.allInstances(Inventory.class));
+ @Inject private FixtureScripts fixtureScripts;
+ @Inject private RepositoryService repository;
+
+ void setUp() {
+ // cleanup
+ fixtureScripts.runBuilderScript(JdoTestDomainPersona.PurgeAll.builder());
+
+ // given
+ fixtureScripts.runBuilderScript(JdoTestDomainPersona.InventoryWith1Book.builder());
+ }
+
+ @Test @Rollback(false)
+ void sampleInventoryShouldBeSetUp() {
+
+ setUp();
+
+ val inventories = repository.allInstances(Inventory.class);
assertEquals(1, inventories.size());
-
- val inventory = inventories.getSingleton().get();
- assertNotNull(inventory);
- assertNotNull(inventory.getProducts());
- assertEquals(1, inventory.getProducts().size());
-
- val product = inventory.getProducts().iterator().next();
- assertEquals("Sample Book", product.getName());
-
- }
-
+ val inventory = inventories.get(0);
+ assertNotNull(inventory);
+ assertNotNull(inventory.getProducts());
+ assertEquals(1, inventory.getProducts().size());
+
+ val product = inventory.getProducts().iterator().next();
+ assertEquals("Sample Book", product.getName());
+
+ }
+
}
diff --git a/example/misc/smoketest/src/test/java/org/apache/isis/testdomain/tests/PublisherServiceTest.java b/example/misc/smoketest/src/test/java/org/apache/isis/testdomain/tests/PublisherServiceTest.java
index 0fe096c..d78e535 100644
--- a/example/misc/smoketest/src/test/java/org/apache/isis/testdomain/tests/PublisherServiceTest.java
+++ b/example/misc/smoketest/src/test/java/org/apache/isis/testdomain/tests/PublisherServiceTest.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.tests;
@@ -44,86 +46,81 @@ import lombok.val;
/**
* Depends on {@link JdoBootstrappingTest_usingFixtures} to succeed.
*/
-class PublisherServiceTest {
-
- @Inject FixtureScripts fixtureScripts;
-
- @BeforeEach
- void setUp() {
-
- // cleanup
- fixtureScripts.runBuilderScript(
- JdoTestDomainPersona.PurgeAll.builder());
-
- // given
- fixtureScripts.runBuilderScript(
- JdoTestDomainPersona.InventoryWith1Book.builder());
- }
-
- @Test @Disabled("service lookup fails")
- void publisherServiceShouldBeAwareOfInventoryChanges() {
-
-
- val serviceRegistry = IsisContext.getServiceRegistry();
-
- Map<Class<? extends PublisherService>, PublisherService> map =
- serviceRegistry.select(PublisherService.class)
- .stream()
- .collect(Collectors.toMap(ps->ps.getClass(), ps->ps));
-
- // TODO any instance type lookup (should be a test on its own)
- assertTrue(map.containsKey(PublisherServiceStub.class));
-
- // priority based service lookup (could be a test on its own)
- val publisherService = (PublisherServiceStub) map.get(PublisherServiceStub.class);
-
- // given
+class PublisherServiceTest {
+
+ @Inject private FixtureScripts fixtureScripts;
+
+ @BeforeEach
+ void setUp() {
+
+ // cleanup
+ fixtureScripts.runBuilderScript(JdoTestDomainPersona.PurgeAll.builder());
+
+ // given
+ fixtureScripts.runBuilderScript(JdoTestDomainPersona.InventoryWith1Book.builder());
+ }
+
+ @Test
+ @Disabled("service lookup fails")
+ void publisherServiceShouldBeAwareOfInventoryChanges() {
+
+ val serviceRegistry = IsisContext.getServiceRegistry();
+
+ Map<Class<? extends PublisherService>, PublisherService> map = serviceRegistry.select(PublisherService.class)
+ .stream().collect(Collectors.toMap(ps -> ps.getClass(), ps -> ps));
+
+ // TODO any instance type lookup (should be a test on its own)
+ assertTrue(map.containsKey(PublisherServiceStub.class));
+
+ // priority based service lookup (could be a test on its own)
+ val publisherService = (PublisherServiceStub) map.get(PublisherServiceStub.class);
+
+ // given
// val publisherService = (PublisherServiceStub) publisherServiceAny;
- val repository = IsisContext.getServiceRegistry()
- .lookupServiceElseFail(RepositoryService.class);
- val txMan = IsisContext.getPersistenceSession().get().getTransactionManager();
- val book = repository.allInstances(Book.class).listIterator().next();
-
- // when
- publisherService.clearHistory();
- book.setName("Book #2");
- repository.persist(book);
- txMan.endTransaction();
-
- // then TODO
+ val repository = IsisContext.getServiceRegistry().lookupServiceElseFail(RepositoryService.class);
+ val txMan = IsisContext.getPersistenceSession().get().getTransactionManager();
+ val book = repository.allInstances(Book.class).listIterator().next();
+
+ // when
+ publisherService.clearHistory();
+ book.setName("Book #2");
+ repository.persist(book);
+ txMan.endTransaction();
+
+ // then TODO
// assertEquals(
// "...",
// publisherService.getHistory());
- }
-
- // -- HELPER
-
- @DomainService(menuOrder="1.0", nature=NatureOfService.DOMAIN)
- @DomainServiceLayout()
- public static class PublisherServiceStub implements PublisherService {
-
- private StringBuilder history = new StringBuilder();
-
- void clearHistory() {
- history = new StringBuilder();
- }
-
- String getHistory() {
- return history.toString();
- }
-
- @Override
- public void publish(Execution<?, ?> execution) {
- history.append("execution=").append(execution).append(",");
- System.out.println("h1: " + history);
- }
-
- @Override
- public void publish(PublishedObjects publishedObjects) {
- history.append("publishedObjects=").append(publishedObjects).append(",");
- System.out.println("h2: " + history);
- }
-
- }
-
+ }
+
+ // -- HELPER
+
+ @DomainService(menuOrder = "1.0", nature = NatureOfService.DOMAIN)
+ @DomainServiceLayout()
+ public static class PublisherServiceStub implements PublisherService {
+
+ private StringBuilder history = new StringBuilder();
+
+ void clearHistory() {
+ history = new StringBuilder();
+ }
+
+ String getHistory() {
+ return history.toString();
+ }
+
+ @Override
+ public void publish(Execution<?, ?> execution) {
+ history.append("execution=").append(execution).append(",");
+ System.out.println("h1: " + history);
+ }
+
+ @Override
+ public void publish(PublishedObjects publishedObjects) {
+ history.append("publishedObjects=").append(publishedObjects).append(",");
+ System.out.println("h2: " + history);
+ }
+
+ }
+
}
diff --git a/example/misc/smoketest/src/test/java/org/apache/isis/testdomain/tests/SpringEventPublishingTest.java b/example/misc/smoketest/src/test/java/org/apache/isis/testdomain/tests/SpringEventPublishingTest.java
index 4f38039..2721847 100644
--- a/example/misc/smoketest/src/test/java/org/apache/isis/testdomain/tests/SpringEventPublishingTest.java
+++ b/example/misc/smoketest/src/test/java/org/apache/isis/testdomain/tests/SpringEventPublishingTest.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.tests;
@@ -23,79 +25,79 @@ import javax.enterprise.event.Observes;
import javax.inject.Inject;
import javax.inject.Singleton;
+import org.apache.isis.commons.internal.spring._Spring;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;
-import org.springframework.test.context.junit.jupiter.SpringExtension;
-
-import org.apache.isis.commons.internal.spring._Spring;
import lombok.Getter;
import lombok.Value;
import lombok.val;
-@ExtendWith(SpringExtension.class)
-@SpringBootTest(classes = {
- SpringEventPublishingTest.TestConfig.class,
- SpringEventPublishingTest.TestPublisher.class,
- SpringEventPublishingTest.TestListener.class})
+@SpringBootTest(
+ classes = {
+ SpringEventPublishingTest.TestConfig.class,
+ SpringEventPublishingTest.TestPublisher.class,
+ SpringEventPublishingTest.TestListener.class
+})
class SpringEventPublishingTest {
- @Inject TestPublisher testPublisher;
- @Inject TestListener testListener;
-
- @Test
- void firedEventShouldBeReceivedImmediately() {
-
- val history = testListener.getHistory();
-
- testPublisher.fireHelloWorld();
-
- assertEquals("Hello World!", history.toString());
- }
-
- // -- HELPER
-
- @Configuration
- static class TestConfig {
-
- @Bean
- Event<GenericSpringEvent<String>> createEvent(ApplicationEventPublisher publisher) {
- return _Spring.event(publisher);
- }
-
- }
-
- @Singleton
- public static class TestPublisher {
-
- @Inject Event<GenericSpringEvent<String>> genericEvent;
-
- public void fireHelloWorld() {
- genericEvent.fire(GenericSpringEvent.of("Hello World!"));
- }
-
- }
-
- @Singleton
- public static class TestListener {
-
- @Getter private final StringBuilder history = new StringBuilder();
-
- @EventListener(GenericSpringEvent.class)
- public void receiveHelloWorld(@Observes GenericSpringEvent<String> event) {
- history.append(event.what);
- }
-
- }
-
- @Value(staticConstructor = "of")
- static class GenericSpringEvent<T> {
- private T what;
- }
-
+ @Inject private TestPublisher testPublisher;
+ @Inject private TestListener testListener;
+
+ @Test
+ void firedEventShouldBeReceivedImmediately() {
+
+ val history = testListener.getHistory();
+
+ testPublisher.fireHelloWorld();
+
+ assertEquals("Hello World!", history.toString());
+ }
+
+ // -- HELPER
+
+ @Configuration
+ static class TestConfig {
+
+ @Bean
+ Event<GenericSpringEvent<String>> createEvent(ApplicationEventPublisher publisher) {
+ return _Spring.event(publisher);
+ }
+
+ }
+
+ @Singleton
+ public static class TestPublisher {
+
+ @Inject
+ Event<GenericSpringEvent<String>> genericEvent;
+
+ public void fireHelloWorld() {
+ genericEvent.fire(GenericSpringEvent.of("Hello World!"));
+ }
+
+ }
+
+ @Singleton
+ public static class TestListener {
+
+ @Getter
+ private final StringBuilder history = new StringBuilder();
+
+ @EventListener(GenericSpringEvent.class)
+ public void receiveHelloWorld(@Observes GenericSpringEvent<String> event) {
+ history.append(event.what);
+ }
+
+ }
+
+ @Value(staticConstructor = "of")
+ static class GenericSpringEvent<T> {
+ private T what;
+ }
+
}
diff --git a/example/misc/smoketest/src/test/java/org/apache/isis/testdomain/tests/SpringServiceProvisioningTest.java b/example/misc/smoketest/src/test/java/org/apache/isis/testdomain/tests/SpringServiceProvisioningTest.java
index 740f093..202f891 100644
--- a/example/misc/smoketest/src/test/java/org/apache/isis/testdomain/tests/SpringServiceProvisioningTest.java
+++ b/example/misc/smoketest/src/test/java/org/apache/isis/testdomain/tests/SpringServiceProvisioningTest.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.tests;
@@ -33,51 +35,45 @@ import org.apache.isis.runtime.spring.IsisBoot;
import org.apache.isis.testdomain.jdo.JdoTestDomainModule;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.context.junit.jupiter.SpringExtension;
import lombok.val;
-@ExtendWith(SpringExtension.class)
@SpringBootTest(
- classes = {
- IsisBoot.class,
- JdoTestDomainModule.class,
- },
- properties = {
- "logging.config=log4j2-test.xml",
- //"isis.reflector.introspector.parallelize=false",
- //"logging.level.org.apache.isis.core.metamodel.specloader.specimpl.ObjectSpecificationAbstract=TRACE"
- }
- )
+ classes = {
+ IsisBoot.class,
+ JdoTestDomainModule.class,
+ },
+ properties = {
+ "logging.config=log4j2-test.xml",
+ // "isis.reflector.introspector.parallelize=false",
+ // "logging.level.org.apache.isis.core.metamodel.specloader.specimpl.ObjectSpecificationAbstract=TRACE"
+})
class SpringServiceProvisioningTest {
- @BeforeEach
- void beforeEach() {
- System.out.println("================== START ====================");
- }
-
- @Test
- void builtInServicesShouldBeSetUp() throws IOException {
-
- val serviceRegistry = IsisContext.getServiceRegistry();
- val managedServices = serviceRegistry.streamRegisteredBeans()
- .map(BeanAdapter::getBeanClass)
- .map(Class::getName)
- .collect(Collectors.toCollection(TreeSet::new));
-
- val singletonJson = _Resources.loadAsString(this.getClass(), "builtin-IsisBoot.json", StandardCharsets.UTF_8);
- val singletonSet = new TreeSet<>(_Json.readJsonList(String.class, singletonJson));
-
- // same as managedServices.containsAll(singletonSet) but more verbose in case of failure
- assertEquals(
- toStringJoiningNewLine(singletonSet),
- toStringJoiningNewLine(intersectSorted(managedServices, singletonSet)));
-
- //TODO also test for request-scoped service (requires a means to mock a request-context)
-
- }
-
-
+ @BeforeEach
+ void beforeEach() {
+
+ }
+
+ @Test
+ void builtInServicesShouldBeSetUp() throws IOException {
+
+ val serviceRegistry = IsisContext.getServiceRegistry();
+ val managedServices = serviceRegistry.streamRegisteredBeans().map(BeanAdapter::getBeanClass).map(Class::getName)
+ .collect(Collectors.toCollection(TreeSet::new));
+
+ val singletonJson = _Resources.loadAsString(this.getClass(), "builtin-IsisBoot.json", StandardCharsets.UTF_8);
+ val singletonSet = new TreeSet<>(_Json.readJsonList(String.class, singletonJson));
+
+ // same as managedServices.containsAll(singletonSet) but more verbose in case of
+ // failure
+ assertEquals(toStringJoiningNewLine(singletonSet),
+ toStringJoiningNewLine(intersectSorted(managedServices, singletonSet)));
+
+ // TODO also test for request-scoped service (requires a means to mock a
+ // request-context)
+
+ }
+
}
diff --git a/example/misc/smoketest/src/test/java/org/apache/isis/testdomain/tests/Util_H2Console.java b/example/misc/smoketest/src/test/java/org/apache/isis/testdomain/tests/Util_H2Console.java
index b90897d..4b264bb 100644
--- a/example/misc/smoketest/src/test/java/org/apache/isis/testdomain/tests/Util_H2Console.java
+++ b/example/misc/smoketest/src/test/java/org/apache/isis/testdomain/tests/Util_H2Console.java
@@ -1,3 +1,21 @@
+/*
+ * 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.tests;
import java.sql.SQLException;
@@ -7,5 +25,5 @@ public class Util_H2Console {
public static void main(String[] args) throws SQLException {
org.h2.tools.Console.main(args);
}
-
+
}