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/08/05 11:00:18 UTC
[isis] branch v2 updated: ISIS-2158 fixes transaction related
smoketests
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch v2
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/v2 by this push:
new 52e6680 ISIS-2158 fixes transaction related smoketests
52e6680 is described below
commit 52e6680870bdaa37682acbaa8f2a1a85688e63b3
Author: Andi Huber <ah...@apache.org>
AuthorDate: Mon Aug 5 13:00:05 2019 +0200
ISIS-2158 fixes transaction related smoketests
- also bumps h2/hsqldb to their latest versions
consecutive smoketest runs might run into an issue with jdo/schema
creation failing due to schema not found, but running test classes
individually does work
---
.../java/org/apache/isis/config/IsisPresets.java | 3 +
.../resources/presets/DebugPersistence.properties | 20 ++
.../jdo/persistence/IsisTransactionManagerJdo.java | 1 -
core/pom.xml | 6 +-
examples/smoketests/pom.xml | 21 ---
.../isis/testdomain/jdo/JdoTestDomainPersona.java | 60 +++++-
.../bootstrapping/JdoBootstrappingTest.java | 7 +-
.../JdoBootstrappingTest_usingFixtures.java | 6 +-
.../isis/testdomain/shiro/AbstractShiroTest.java | 19 +-
.../isis/testdomain/shiro/ShiroLdapTest.java | 8 +-
.../isis/testdomain/shiro/ShiroSecmanLdapTest.java | 28 ++-
.../shiro/ShiroSecmanLdap_restfulStressTest.java | 23 +--
.../isis/testdomain/shiro/ShiroSecmanTest.java | 4 +-
.../isis/testdomain/shiro/ShiroSimpleTest.java | 4 +-
.../transactions/TransactionRollbackTest.java | 33 ++--
...TransactionRollbackTest_withTransactional.java} | 66 +++----
.../secman/api/user/ApplicationUserRepository.java | 3 +
.../jdo/dom/user/ApplicationUserRepository.java | 17 ++
.../secman/jdo/seed/SeedSecurityModuleService.java | 11 +-
mavendeps/testing/pom.xml | 205 ++++++++++-----------
20 files changed, 283 insertions(+), 262 deletions(-)
diff --git a/core/config/src/main/java/org/apache/isis/config/IsisPresets.java b/core/config/src/main/java/org/apache/isis/config/IsisPresets.java
index 0326c82..a160e20 100644
--- a/core/config/src/main/java/org/apache/isis/config/IsisPresets.java
+++ b/core/config/src/main/java/org/apache/isis/config/IsisPresets.java
@@ -95,6 +95,9 @@ public final class IsisPresets {
public static final String HsqlDbInMemory = "classpath:/presets/HsqlDbInMemory.properties";
public static final String DataNucleusAutoCreate = "classpath:/presets/DataNucleusAutoCreate.properties";
+ public static final String DebugPersistence = "classpath:/presets/DebugPersistence.properties";
+
+
/**
* @deprecated seems no longer required anyway
*/
diff --git a/core/config/src/main/resources/presets/DebugPersistence.properties b/core/config/src/main/resources/presets/DebugPersistence.properties
new file mode 100644
index 0000000..02d2985
--- /dev/null
+++ b/core/config/src/main/resources/presets/DebugPersistence.properties
@@ -0,0 +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
+#
+# 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.
+
+logging.level.org.apache.isis.jdo.persistence.IsisPlatformTransactionManagerForJdo = DEBUG
+logging.level.org.apache.isis.jdo.persistence.PersistenceSession5 = DEBUG
+logging.level.org.apache.isis.jdo.persistence.IsisTransactionJdo = DEBUG
\ No newline at end of file
diff --git a/core/plugins/jdo-common/src/main/java/org/apache/isis/jdo/persistence/IsisTransactionManagerJdo.java b/core/plugins/jdo-common/src/main/java/org/apache/isis/jdo/persistence/IsisTransactionManagerJdo.java
index 78668b4..83e6a29 100644
--- a/core/plugins/jdo-common/src/main/java/org/apache/isis/jdo/persistence/IsisTransactionManagerJdo.java
+++ b/core/plugins/jdo-common/src/main/java/org/apache/isis/jdo/persistence/IsisTransactionManagerJdo.java
@@ -308,7 +308,6 @@ class IsisTransactionManagerJdo implements SessionScopedComponent {
public void abortTransaction(IsisTransactionObject txObject) {
val transaction = (IsisTransactionJdo) txObject.getCurrentTransaction();
if (transaction != null) {
- System.out.println("!!!!!!!!!!! " + transaction.getState());
transaction.markAsAborted();
persistenceSession.abortTransaction();
txObject.clear();
diff --git a/core/pom.xml b/core/pom.xml
index 00e9fc5..95e82e6 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -135,12 +135,10 @@
<gson.version>2.7</gson.version>
<swagger-core.version>1.5.21</swagger-core.version>
- <hsqldb.version>2.4.1</hsqldb.version>
- <h2.version>1.4.197</h2.version>
+ <hsqldb.version>2.5.0</hsqldb.version>
+ <h2.version>1.4.199</h2.version>
<log4jdbc-remix.version>0.2.7</log4jdbc-remix.version>
- <jetty.version>9.4.19.v20190610</jetty.version>
-
<spring-framework.version>5.1.7.RELEASE</spring-framework.version>
<spring-boot.version>2.1.5.RELEASE</spring-boot.version>
<slf4j-api.version>1.7.26</slf4j-api.version> <!-- as provided by spring-boot, needed to solve convergence issues -->
diff --git a/examples/smoketests/pom.xml b/examples/smoketests/pom.xml
index 46d5909..a9f1fc3 100644
--- a/examples/smoketests/pom.xml
+++ b/examples/smoketests/pom.xml
@@ -147,27 +147,6 @@
<version>${isis.version}</version>
</dependency>
- <!-- OTHER DEPENDENCIES -->
- <!-- <dependency> <groupId>org.hsqldb</groupId> <artifactId>hsqldb</artifactId>
- </dependency> -->
- <dependency>
- <groupId>com.h2database</groupId>
- <artifactId>h2</artifactId>
- </dependency>
-
-<!-- <dependency> -->
-<!-- <groupId>org.apache.isis.mavendeps</groupId> -->
-<!-- <artifactId>isis-mavendeps-webapp</artifactId> -->
-<!-- <type>pom</type> -->
-<!-- <exclusions> -->
-<!-- <exclusion> -->
-<!-- <groupId>org.slf4j</groupId> -->
-<!-- <artifactId>slf4j-api</artifactId> -->
-<!-- </exclusion> -->
-<!-- </exclusions> -->
-<!-- </dependency> -->
-
-
<!-- TEST DEPENDENCIES -->
<dependency>
diff --git a/examples/smoketests/src/main/java/org/apache/isis/testdomain/jdo/JdoTestDomainPersona.java b/examples/smoketests/src/main/java/org/apache/isis/testdomain/jdo/JdoTestDomainPersona.java
index ff76643..b72892c 100644
--- a/examples/smoketests/src/main/java/org/apache/isis/testdomain/jdo/JdoTestDomainPersona.java
+++ b/examples/smoketests/src/main/java/org/apache/isis/testdomain/jdo/JdoTestDomainPersona.java
@@ -25,6 +25,10 @@ import javax.inject.Inject;
import org.apache.isis.applib.services.repository.RepositoryService;
import org.apache.isis.extensions.fixtures.api.PersonaWithBuilderScript;
import org.apache.isis.extensions.fixtures.fixturescripts.BuilderScriptAbstract;
+import org.apache.isis.extensions.secman.api.SecurityModuleConfig;
+import org.apache.isis.extensions.secman.api.role.ApplicationRoleRepository;
+import org.apache.isis.extensions.secman.api.user.ApplicationUserRepository;
+import org.apache.isis.testdomain.ldap.LdapConstants;
import lombok.val;
@@ -71,7 +75,13 @@ implements PersonaWithBuilderScript<BuilderScriptAbstract<Inventory>> {
@Override
protected void execute(ExecutionContext ec) {
- inventory = sampleInventoryWith1Book();
+ val products = new HashSet<Product>();
+
+ products.add(Book.of(
+ "Sample Book", "A sample book for testing.", 99.,
+ "Sample Author", "Sample ISBN", "Sample Publisher"));
+
+ inventory = Inventory.of("Sample Inventory", products);
repository.persist(inventory);
}
@@ -85,19 +95,49 @@ implements PersonaWithBuilderScript<BuilderScriptAbstract<Inventory>> {
};
}
- }
+ },
+
+ SvenApplicationUser {
+ @Override
+ public BuilderScriptAbstract<Inventory> builder() {
+ return new BuilderScriptAbstract<Inventory>() {
- ;
+ private Inventory inventory;
+
+ @Override
+ protected void execute(ExecutionContext ec) {
+
+ val regularUserRoleName = securityConfig.getRegularUserRoleName();
+ val regularUserRole = applicationRoleRepository.findByName(regularUserRoleName);
+ val enabled = true;
+ val username = LdapConstants.SVEN_PRINCIPAL;
+ val svenUser = applicationUserRepository.findByUsername(username);
+ if(svenUser==null) {
+ applicationUserRepository
+ .newDelegateUser(username, regularUserRole, enabled);
+ } else {
+ applicationUserRepository.enable(svenUser);
+ }
- private static Inventory sampleInventoryWith1Book() {
- val products = new HashSet<Product>();
+ }
+
+ @Override
+ public Inventory getObject() {
+ return inventory;
+ }
+
+ @Inject private ApplicationUserRepository applicationUserRepository;
+ @Inject private ApplicationRoleRepository applicationRoleRepository;
+ @Inject private SecurityModuleConfig securityConfig;
+
+ };
+ }
+
+
+ },
- products.add(Book.of(
- "Sample Book", "A sample book for testing.", 99.,
- "Sample Author", "Sample ISBN", "Sample Publisher"));
- return Inventory.of("Sample Inventory", products);
- }
+ ;
}
diff --git a/examples/smoketests/src/test/java/org/apache/isis/testdomain/bootstrapping/JdoBootstrappingTest.java b/examples/smoketests/src/test/java/org/apache/isis/testdomain/bootstrapping/JdoBootstrappingTest.java
index 6404138..db561d5 100644
--- a/examples/smoketests/src/test/java/org/apache/isis/testdomain/bootstrapping/JdoBootstrappingTest.java
+++ b/examples/smoketests/src/test/java/org/apache/isis/testdomain/bootstrapping/JdoBootstrappingTest.java
@@ -35,6 +35,7 @@ import org.springframework.test.annotation.Rollback;
import org.springframework.transaction.annotation.Transactional;
import org.apache.isis.applib.services.repository.RepositoryService;
+import org.apache.isis.config.IsisPresets;
import org.apache.isis.testdomain.jdo.Book;
import org.apache.isis.testdomain.jdo.Inventory;
import org.apache.isis.testdomain.jdo.JdoTestDomainModule;
@@ -51,11 +52,7 @@ import lombok.val;
},
properties = {
"logging.config=log4j2-test.xml",
- "logging.level.org.apache.isis.jdo.persistence.IsisPlatformTransactionManagerForJdo=DEBUG",
- "logging.level.org.apache.isis.jdo.persistence.PersistenceSession5=DEBUG",
- "logging.level.org.apache.isis.jdo.persistence.IsisTransactionJdo=DEBUG",
- // "isis.reflector.introspector.parallelize=false",
- //"logging.level.org.apache.isis.metamodel.specloader.specimpl.ObjectSpecificationAbstract=TRACE"
+ IsisPresets.DebugPersistence,
})
@Transactional @TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class JdoBootstrappingTest {
diff --git a/examples/smoketests/src/test/java/org/apache/isis/testdomain/bootstrapping/JdoBootstrappingTest_usingFixtures.java b/examples/smoketests/src/test/java/org/apache/isis/testdomain/bootstrapping/JdoBootstrappingTest_usingFixtures.java
index 393ab1a..62775ef 100644
--- a/examples/smoketests/src/test/java/org/apache/isis/testdomain/bootstrapping/JdoBootstrappingTest_usingFixtures.java
+++ b/examples/smoketests/src/test/java/org/apache/isis/testdomain/bootstrapping/JdoBootstrappingTest_usingFixtures.java
@@ -23,10 +23,10 @@ import javax.inject.Inject;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.annotation.Rollback;
import org.springframework.transaction.annotation.Transactional;
import org.apache.isis.applib.services.repository.RepositoryService;
+import org.apache.isis.config.IsisPresets;
import org.apache.isis.extensions.fixtures.fixturescripts.FixtureScripts;
import org.apache.isis.testdomain.jdo.Inventory;
import org.apache.isis.testdomain.jdo.JdoTestDomainModule;
@@ -43,7 +43,7 @@ import lombok.val;
},
properties = {
"logging.config=log4j2-debug-persistence.xml",
- "logging.level.org.apache.isis.jdo.persistence.PersistenceSession5=DEBUG"
+ IsisPresets.DebugPersistence,
})
@Transactional
class JdoBootstrappingTest_usingFixtures {
@@ -61,7 +61,7 @@ class JdoBootstrappingTest_usingFixtures {
fixtureScripts.runPersona(JdoTestDomainPersona.InventoryWith1Book);
}
- @Test @Rollback(false)
+ @Test
void sampleInventoryShouldBeSetUp() {
val inventories = repository.allInstances(Inventory.class);
diff --git a/examples/smoketests/src/test/java/org/apache/isis/testdomain/shiro/AbstractShiroTest.java b/examples/smoketests/src/test/java/org/apache/isis/testdomain/shiro/AbstractShiroTest.java
index 472e1e7..79d2769 100644
--- a/examples/smoketests/src/test/java/org/apache/isis/testdomain/shiro/AbstractShiroTest.java
+++ b/examples/smoketests/src/test/java/org/apache/isis/testdomain/shiro/AbstractShiroTest.java
@@ -20,6 +20,7 @@ package org.apache.isis.testdomain.shiro;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.UnavailableSecurityManagerException;
+import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.subject.support.SubjectThreadState;
@@ -27,8 +28,17 @@ import org.apache.shiro.util.LifecycleUtils;
import org.apache.shiro.util.ThreadContext;
import org.apache.shiro.util.ThreadState;
-/** This class was initially copied over from the ApacheDS user Guide,
- * however it has/had some glitches with inconsistent LocalThread (subjectThreadState) context.*/
+import lombok.val;
+
+/**
+ *
+ * This class was initially copied over from the ApacheDS user Guide, however it has/had
+ * some glitches with inconsistent LocalThread (subjectThreadState) context.
+ * <p>
+ * IniSecurityManagerFactory was deprecated in Shiro 1.4, but we could not find a migration guide yet.
+ *
+ */
+@SuppressWarnings("deprecation")
class AbstractShiroTest {
private static ThreadState subjectThreadState;
@@ -76,6 +86,11 @@ class AbstractShiroTest {
}
}
+ protected static void setSecurityManager(String iniResource) {
+ val factory = new IniSecurityManagerFactory(iniResource);
+ setSecurityManager(factory.getInstance());
+ }
+
protected static void setSecurityManager(SecurityManager securityManager) {
try {
// guard against SecurityManager already being set
diff --git a/examples/smoketests/src/test/java/org/apache/isis/testdomain/shiro/ShiroLdapTest.java b/examples/smoketests/src/test/java/org/apache/isis/testdomain/shiro/ShiroLdapTest.java
index 5deea53..3deef90 100644
--- a/examples/smoketests/src/test/java/org/apache/isis/testdomain/shiro/ShiroLdapTest.java
+++ b/examples/smoketests/src/test/java/org/apache/isis/testdomain/shiro/ShiroLdapTest.java
@@ -24,13 +24,13 @@ import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
-import org.apache.shiro.config.IniSecurityManagerFactory;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Import;
+import org.apache.isis.config.IsisPresets;
import org.apache.isis.testdomain.jdo.JdoTestDomainModule_withShiro;
import org.apache.isis.testdomain.ldap.LdapConstants;
import org.apache.isis.testdomain.ldap.LdapServerService;
@@ -49,7 +49,8 @@ import lombok.extern.log4j.Log4j2;
},
properties = {
"logging.config=log4j2-test.xml",
- "smoketest.withShiro=true", // enable shiro specific config to be picked up by Spring
+ "smoketest.withShiro=true", // enable shiro specific config to be picked up by Spring
+ IsisPresets.DebugPersistence,
})
@Import({
LdapServerService.class,
@@ -64,8 +65,7 @@ class ShiroLdapTest extends AbstractShiroTest {
// Build and set the SecurityManager used to build Subject instances used in your tests
// This typically only needs to be done once per class if your shiro.ini doesn't change,
// otherwise, you'll need to do this logic in each test that is different
- val factory = new IniSecurityManagerFactory("classpath:shiro-ldap.ini");
- setSecurityManager(factory.getInstance());
+ setSecurityManager("classpath:shiro-ldap.ini");
}
@AfterAll
diff --git a/examples/smoketests/src/test/java/org/apache/isis/testdomain/shiro/ShiroSecmanLdapTest.java b/examples/smoketests/src/test/java/org/apache/isis/testdomain/shiro/ShiroSecmanLdapTest.java
index 7c8affc..0568a22 100644
--- a/examples/smoketests/src/test/java/org/apache/isis/testdomain/shiro/ShiroSecmanLdapTest.java
+++ b/examples/smoketests/src/test/java/org/apache/isis/testdomain/shiro/ShiroSecmanLdapTest.java
@@ -25,7 +25,6 @@ import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.CredentialsException;
import org.apache.shiro.authc.DisabledAccountException;
import org.apache.shiro.authc.UsernamePasswordToken;
-import org.apache.shiro.config.IniSecurityManagerFactory;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
@@ -33,14 +32,18 @@ import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Import;
+import org.apache.isis.config.IsisPresets;
+import org.apache.isis.extensions.fixtures.fixturescripts.FixtureScripts;
import org.apache.isis.extensions.secman.api.SecurityModuleConfig;
import org.apache.isis.extensions.secman.api.role.ApplicationRoleRepository;
import org.apache.isis.extensions.secman.api.user.ApplicationUserRepository;
import org.apache.isis.extensions.secman.encryption.jbcrypt.IsisBootSecmanEncryptionJbcrypt;
import org.apache.isis.extensions.secman.jdo.IsisBootSecmanPersistenceJdo;
+import org.apache.isis.extensions.secman.jdo.seed.SeedSecurityModuleService;
import org.apache.isis.extensions.secman.model.IsisBootSecmanModel;
import org.apache.isis.extensions.secman.shiro.IsisBootSecmanRealmShiro;
import org.apache.isis.testdomain.jdo.JdoTestDomainModule_withShiro;
+import org.apache.isis.testdomain.jdo.JdoTestDomainPersona;
import org.apache.isis.testdomain.ldap.LdapConstants;
import org.apache.isis.testdomain.ldap.LdapServerService;
@@ -57,8 +60,11 @@ import lombok.val;
JdoTestDomainModule_withShiro.class,
},
properties = {
- "logging.config=log4j2-test.xml",
- "smoketest.withShiro=true", // enable shiro specific config to be picked up by Spring
+ //"logging.config=log4j2-test.xml",
+ "logging.config=log4j2-debug-persistence.xml",
+ "smoketest.withShiro=true", // enable shiro specific config to be picked up by Spring
+ IsisPresets.DebugPersistence,
+ "isis.persistor.datanucleus.impl.datanucleus.schema.autoCreateDatabase=true",
})
@Import({
@@ -73,6 +79,7 @@ import lombok.val;
})
class ShiroSecmanLdapTest extends AbstractShiroTest {
+ @Inject FixtureScripts fixtureScripts;
@Inject LdapServerService ldapServerService;
@Inject ApplicationUserRepository applicationUserRepository;
@Inject ApplicationRoleRepository applicationRoleRepository;
@@ -83,8 +90,7 @@ class ShiroSecmanLdapTest extends AbstractShiroTest {
// Build and set the SecurityManager used to build Subject instances used in your tests
// This typically only needs to be done once per class if your shiro.ini doesn't change,
// otherwise, you'll need to do this logic in each test that is different
- val factory = new IniSecurityManagerFactory("classpath:shiro-secman-ldap.ini");
- setSecurityManager(factory.getInstance());
+ setSecurityManager("classpath:shiro-secman-ldap.ini");
}
@AfterAll
@@ -94,16 +100,8 @@ class ShiroSecmanLdapTest extends AbstractShiroTest {
@BeforeEach
void setupSvenInDb() {
- // only setup once per test run, consecutive calls have no effect
- val regularUserRoleName = securityConfig.getRegularUserRoleName();
- val regularUserRole = applicationRoleRepository.findByName(regularUserRoleName);
- val enabled = true;
- val username = LdapConstants.SVEN_PRINCIPAL;
- val svenUser = applicationUserRepository.findByUsername(username);
- if(svenUser==null) {
- applicationUserRepository
- .newDelegateUser(username, regularUserRole, enabled);
- }
+ // given
+ fixtureScripts.runPersona(JdoTestDomainPersona.SvenApplicationUser);
}
diff --git a/examples/smoketests/src/test/java/org/apache/isis/testdomain/shiro/ShiroSecmanLdap_restfulStressTest.java b/examples/smoketests/src/test/java/org/apache/isis/testdomain/shiro/ShiroSecmanLdap_restfulStressTest.java
index 9eccda3..be95cdf 100644
--- a/examples/smoketests/src/test/java/org/apache/isis/testdomain/shiro/ShiroSecmanLdap_restfulStressTest.java
+++ b/examples/smoketests/src/test/java/org/apache/isis/testdomain/shiro/ShiroSecmanLdap_restfulStressTest.java
@@ -27,6 +27,8 @@ import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Import;
+import org.apache.isis.config.IsisPresets;
+import org.apache.isis.extensions.fixtures.fixturescripts.FixtureScripts;
import org.apache.isis.extensions.secman.api.SecurityModuleConfig;
import org.apache.isis.extensions.secman.api.role.ApplicationRoleRepository;
import org.apache.isis.extensions.secman.api.user.ApplicationUserRepository;
@@ -36,7 +38,7 @@ import org.apache.isis.extensions.secman.model.IsisBootSecmanModel;
import org.apache.isis.extensions.secman.shiro.IsisBootSecmanRealmShiro;
import org.apache.isis.security.shiro.WebModuleShiro;
import org.apache.isis.testdomain.jdo.JdoTestDomainModule_withShiro;
-import org.apache.isis.testdomain.ldap.LdapConstants;
+import org.apache.isis.testdomain.jdo.JdoTestDomainPersona;
import org.apache.isis.testdomain.ldap.LdapServerService;
import org.apache.isis.testdomain.rest.RestService;
import org.apache.isis.viewer.restfulobjects.IsisBootWebRestfulObjects;
@@ -54,8 +56,11 @@ import lombok.val;
JdoTestDomainModule_withShiro.class
},
properties = {
- "logging.config=log4j2-test.xml",
+ //"logging.config=log4j2-test.xml",
+ "logging.config=log4j2-debug-persistence.xml",
"smoketest.withShiro=true", // enable shiro specific config to be picked up by Spring
+ IsisPresets.DataNucleusAutoCreate,
+ "datanucleus.schema.autoCreateDatabase=true",
"server.servlet.session.persistent=false", // defaults to false
},
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@@ -76,12 +81,12 @@ import lombok.val;
})
class ShiroSecmanLdap_restfulStressTest extends AbstractShiroTest {
+ @Inject FixtureScripts fixtureScripts;
@Inject RestService restService;
@Inject LdapServerService ldapServerService;
@Inject ApplicationUserRepository applicationUserRepository;
@Inject ApplicationRoleRepository applicationRoleRepository;
@Inject SecurityModuleConfig securityConfig;
-
@BeforeAll
static void beforeClass() {
@@ -96,16 +101,8 @@ class ShiroSecmanLdap_restfulStressTest extends AbstractShiroTest {
@BeforeEach
void setupSvenInDb() {
- // only setup once per test run, consecutive calls have no effect
- val regularUserRoleName = securityConfig.getRegularUserRoleName();
- val regularUserRole = applicationRoleRepository.findByName(regularUserRoleName);
- val enabled = true;
- val username = LdapConstants.SVEN_PRINCIPAL;
- val svenUser = applicationUserRepository.findByUsername(username);
- if(svenUser==null) {
- applicationUserRepository
- .newDelegateUser(username, regularUserRole, enabled);
- }
+ // given
+ fixtureScripts.runPersona(JdoTestDomainPersona.SvenApplicationUser);
}
@Test
diff --git a/examples/smoketests/src/test/java/org/apache/isis/testdomain/shiro/ShiroSecmanTest.java b/examples/smoketests/src/test/java/org/apache/isis/testdomain/shiro/ShiroSecmanTest.java
index e12eedb..235296e 100644
--- a/examples/smoketests/src/test/java/org/apache/isis/testdomain/shiro/ShiroSecmanTest.java
+++ b/examples/smoketests/src/test/java/org/apache/isis/testdomain/shiro/ShiroSecmanTest.java
@@ -24,7 +24,6 @@ import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.CredentialsException;
import org.apache.shiro.authc.UsernamePasswordToken;
-import org.apache.shiro.config.IniSecurityManagerFactory;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -69,8 +68,7 @@ class ShiroSecmanTest extends AbstractShiroTest {
// Build and set the SecurityManager used to build Subject instances used in your tests
// This typically only needs to be done once per class if your shiro.ini doesn't change,
// otherwise, you'll need to do this logic in each test that is different
- val factory = new IniSecurityManagerFactory("classpath:shiro-secman.ini");
- setSecurityManager(factory.getInstance());
+ setSecurityManager("classpath:shiro-secman.ini");
}
@AfterAll
diff --git a/examples/smoketests/src/test/java/org/apache/isis/testdomain/shiro/ShiroSimpleTest.java b/examples/smoketests/src/test/java/org/apache/isis/testdomain/shiro/ShiroSimpleTest.java
index e01b3d8..498b4fb 100644
--- a/examples/smoketests/src/test/java/org/apache/isis/testdomain/shiro/ShiroSimpleTest.java
+++ b/examples/smoketests/src/test/java/org/apache/isis/testdomain/shiro/ShiroSimpleTest.java
@@ -21,7 +21,6 @@ package org.apache.isis.testdomain.shiro;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
-import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.subject.Subject;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
@@ -42,8 +41,7 @@ class ShiroSimpleTest extends AbstractShiroTest {
//0. Build and set the SecurityManager used to build Subject instances used in your tests
// This typically only needs to be done once per class if your shiro.ini doesn't change,
// otherwise, you'll need to do this logic in each test that is different
- val factory = new IniSecurityManagerFactory("classpath:shiro-simple.ini");
- setSecurityManager(factory.getInstance());
+ setSecurityManager("classpath:shiro-simple.ini");
}
@AfterAll
diff --git a/examples/smoketests/src/test/java/org/apache/isis/testdomain/transactions/TransactionRollbackTest.java b/examples/smoketests/src/test/java/org/apache/isis/testdomain/transactions/TransactionRollbackTest.java
index b32f9e6..0733d2a 100644
--- a/examples/smoketests/src/test/java/org/apache/isis/testdomain/transactions/TransactionRollbackTest.java
+++ b/examples/smoketests/src/test/java/org/apache/isis/testdomain/transactions/TransactionRollbackTest.java
@@ -21,20 +21,20 @@ package org.apache.isis.testdomain.transactions;
import javax.inject.Inject;
import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.TestMethodOrder;
import org.springframework.boot.test.context.SpringBootTest;
import org.apache.isis.applib.services.repository.RepositoryService;
import org.apache.isis.applib.services.xactn.TransactionService;
import org.apache.isis.commons.internal.exceptions._Exceptions;
+import org.apache.isis.config.IsisPresets;
import org.apache.isis.extensions.fixtures.fixturescripts.FixtureScripts;
import org.apache.isis.testdomain.jdo.Book;
import org.apache.isis.testdomain.jdo.JdoTestDomainModule;
import org.apache.isis.testdomain.jdo.JdoTestDomainPersona;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
@SpringBootTest(
classes = {
@@ -42,16 +42,13 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
},
properties = {
"logging.config=log4j2-test.xml",
- "logging.level.org.apache.isis.jdo.persistence.IsisPlatformTransactionManagerForJdo=DEBUG",
- "logging.level.org.apache.isis.jdo.persistence.PersistenceSession5=DEBUG",
- "logging.level.org.apache.isis.jdo.persistence.IsisTransactionJdo=DEBUG",
+ IsisPresets.DebugPersistence,
})
-@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class TransactionRollbackTest {
@Inject FixtureScripts fixtureScripts;
- @Inject private TransactionService transactionService;
- @Inject private RepositoryService repository;
+ @Inject TransactionService transactionService;
+ @Inject RepositoryService repository;
@BeforeEach
void setUp() {
@@ -83,22 +80,18 @@ class TransactionRollbackTest {
// expected pre condition
assertEquals(0, repository.allInstances(Book.class).size());
- System.out.println("!!! ROLLBACK TEST TX IN");
-
- transactionService.executeWithinTransaction(()->{
-
- System.out.println("!!! PRE FIXTURE");
-
- fixtureScripts.runPersona(JdoTestDomainPersona.InventoryWith1Book);
-
- System.out.println("!!! POST FIXTURE");
+ assertThrows(RuntimeException.class, ()->{
- throw _Exceptions.unrecoverable("Test: force current tx to rollback");
+ transactionService.executeWithinTransaction(()->{
+
+ fixtureScripts.runPersona(JdoTestDomainPersona.InventoryWith1Book);
+
+ throw _Exceptions.unrecoverable("Test: force current tx to rollback");
+
+ });
});
- System.out.println("!!! ROLLBACK TEST TX OUT");
-
// expected post condition
assertEquals(0, repository.allInstances(Book.class).size());
diff --git a/examples/smoketests/src/test/java/org/apache/isis/testdomain/transactions/TransactionRollbackTest.java b/examples/smoketests/src/test/java/org/apache/isis/testdomain/transactions/TransactionRollbackTest_withTransactional.java
similarity index 59%
copy from examples/smoketests/src/test/java/org/apache/isis/testdomain/transactions/TransactionRollbackTest.java
copy to examples/smoketests/src/test/java/org/apache/isis/testdomain/transactions/TransactionRollbackTest_withTransactional.java
index b32f9e6..334a578 100644
--- a/examples/smoketests/src/test/java/org/apache/isis/testdomain/transactions/TransactionRollbackTest.java
+++ b/examples/smoketests/src/test/java/org/apache/isis/testdomain/transactions/TransactionRollbackTest_withTransactional.java
@@ -20,15 +20,16 @@ package org.apache.isis.testdomain.transactions;
import javax.inject.Inject;
-import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.MethodOrderer;
+import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.transaction.annotation.Transactional;
import org.apache.isis.applib.services.repository.RepositoryService;
import org.apache.isis.applib.services.xactn.TransactionService;
-import org.apache.isis.commons.internal.exceptions._Exceptions;
+import org.apache.isis.config.IsisPresets;
import org.apache.isis.extensions.fixtures.fixturescripts.FixtureScripts;
import org.apache.isis.testdomain.jdo.Book;
import org.apache.isis.testdomain.jdo.JdoTestDomainModule;
@@ -36,73 +37,48 @@ import org.apache.isis.testdomain.jdo.JdoTestDomainPersona;
import static org.junit.jupiter.api.Assertions.assertEquals;
+/**
+ * These tests use the {@code @Transactional} annotation as provided by Spring.
+ * <p>
+ * We test whether JUnit Tests are automatically rolled back by Spring.
+ */
@SpringBootTest(
classes = {
JdoTestDomainModule.class,
},
properties = {
"logging.config=log4j2-test.xml",
- "logging.level.org.apache.isis.jdo.persistence.IsisPlatformTransactionManagerForJdo=DEBUG",
- "logging.level.org.apache.isis.jdo.persistence.PersistenceSession5=DEBUG",
- "logging.level.org.apache.isis.jdo.persistence.IsisTransactionJdo=DEBUG",
+ IsisPresets.DebugPersistence,
})
+@Transactional
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
-class TransactionRollbackTest {
+class TransactionRollbackTest_withTransactional {
@Inject FixtureScripts fixtureScripts;
- @Inject private TransactionService transactionService;
- @Inject private RepositoryService repository;
-
- @BeforeEach
- void setUp() {
- // cleanup
- fixtureScripts.runPersona(JdoTestDomainPersona.PurgeAll);
-
- }
+ @Inject TransactionService transactionService;
+ @Inject RepositoryService repository;
- @Test
+ @Test @Order(1)
void happyCaseTx_shouldCommit() {
+ // cleanup just in case
+ fixtureScripts.runPersona(JdoTestDomainPersona.PurgeAll);
+
// expected pre condition
assertEquals(0, repository.allInstances(Book.class).size());
-
- transactionService.executeWithinTransaction(()->{
-
- fixtureScripts.runPersona(JdoTestDomainPersona.InventoryWith1Book);
- });
+ fixtureScripts.runPersona(JdoTestDomainPersona.InventoryWith1Book);
// expected post condition
assertEquals(1, repository.allInstances(Book.class).size());
}
- @Test
- void whenExceptionWithinTx_shouldRollback() {
+ @Test @Order(2)
+ void previousTest_shouldHaveBeenRolledBack() {
- // expected pre condition
+ // expected condition
assertEquals(0, repository.allInstances(Book.class).size());
-
- System.out.println("!!! ROLLBACK TEST TX IN");
-
- transactionService.executeWithinTransaction(()->{
-
- System.out.println("!!! PRE FIXTURE");
-
- fixtureScripts.runPersona(JdoTestDomainPersona.InventoryWith1Book);
-
- System.out.println("!!! POST FIXTURE");
-
- throw _Exceptions.unrecoverable("Test: force current tx to rollback");
-
- });
-
- System.out.println("!!! ROLLBACK TEST TX OUT");
-
- // expected post condition
- assertEquals(0, repository.allInstances(Book.class).size());
-
}
-
}
diff --git a/extensions/secman/api/src/main/java/org/apache/isis/extensions/secman/api/user/ApplicationUserRepository.java b/extensions/secman/api/src/main/java/org/apache/isis/extensions/secman/api/user/ApplicationUserRepository.java
index 9720a95..0cab3b9 100644
--- a/extensions/secman/api/src/main/java/org/apache/isis/extensions/secman/api/user/ApplicationUserRepository.java
+++ b/extensions/secman/api/src/main/java/org/apache/isis/extensions/secman/api/user/ApplicationUserRepository.java
@@ -41,4 +41,7 @@ public interface ApplicationUserRepository {
ApplicationUser newDelegateUser(String username, ApplicationRole initialRole, Boolean enabled);
+ void enable(ApplicationUser svenUser);
+ void disable(ApplicationUser svenUser);
+
}
diff --git a/extensions/secman/persistence-jdo/src/main/java/org/apache/isis/extensions/secman/jdo/dom/user/ApplicationUserRepository.java b/extensions/secman/persistence-jdo/src/main/java/org/apache/isis/extensions/secman/jdo/dom/user/ApplicationUserRepository.java
index f81f566..5c75773 100644
--- a/extensions/secman/persistence-jdo/src/main/java/org/apache/isis/extensions/secman/jdo/dom/user/ApplicationUserRepository.java
+++ b/extensions/secman/persistence-jdo/src/main/java/org/apache/isis/extensions/secman/jdo/dom/user/ApplicationUserRepository.java
@@ -213,6 +213,22 @@ implements org.apache.isis.extensions.secman.api.user.ApplicationUserRepository
}
return _Lists.newArrayList();
}
+
+ // -- UPDATE USER STATE
+
+ @Override
+ public void enable(org.apache.isis.extensions.secman.api.user.ApplicationUser user) {
+ if(user.getStatus() != ApplicationUserStatus.ENABLED) {
+ ((ApplicationUser) user).unlock();
+ }
+ }
+
+ @Override
+ public void disable(org.apache.isis.extensions.secman.api.user.ApplicationUser user) {
+ if(user.getStatus() != ApplicationUserStatus.DISABLED) {
+ ((ApplicationUser) user).lock();
+ }
+ }
// -- DEPENDENCIES
@@ -225,4 +241,5 @@ implements org.apache.isis.extensions.secman.api.user.ApplicationUserRepository
+
}
diff --git a/extensions/secman/persistence-jdo/src/main/java/org/apache/isis/extensions/secman/jdo/seed/SeedSecurityModuleService.java b/extensions/secman/persistence-jdo/src/main/java/org/apache/isis/extensions/secman/jdo/seed/SeedSecurityModuleService.java
index 87bb912..0db45e7 100644
--- a/extensions/secman/persistence-jdo/src/main/java/org/apache/isis/extensions/secman/jdo/seed/SeedSecurityModuleService.java
+++ b/extensions/secman/persistence-jdo/src/main/java/org/apache/isis/extensions/secman/jdo/seed/SeedSecurityModuleService.java
@@ -22,12 +22,8 @@ import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Singleton;
-import org.springframework.transaction.TransactionStatus;
-
import org.apache.isis.extensions.fixtures.fixturescripts.FixtureScripts;
-import org.apache.isis.runtime.system.context.IsisContext;
-import lombok.val;
import lombok.extern.log4j.Log4j2;
@Singleton @Log4j2
@@ -40,12 +36,7 @@ public class SeedSecurityModuleService {
log.info("SEED");
- val txTemplate = IsisContext.createTransactionTemplate();
-
- txTemplate.execute((TransactionStatus status) -> {
- fixtureScripts.runFixtureScript(new SeedUsersAndRolesFixtureScript(), null);
- return null;
- });
+ fixtureScripts.run(new SeedUsersAndRolesFixtureScript());
}
diff --git a/mavendeps/testing/pom.xml b/mavendeps/testing/pom.xml
index 4cfee94..68cf4ae 100644
--- a/mavendeps/testing/pom.xml
+++ b/mavendeps/testing/pom.xml
@@ -1,25 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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 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. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- 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.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-
- <modelVersion>4.0.0</modelVersion>
+ <modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.isis.mavendeps</groupId>
@@ -28,96 +22,101 @@
<relativePath>../pom.xml</relativePath>
</parent>
- <artifactId>isis-mavendeps-testing</artifactId>
+ <artifactId>isis-mavendeps-testing</artifactId>
+
+ <packaging>pom</packaging>
- <packaging>pom</packaging>
-
- <name>Apache Isis Maven Dependencies for Testing</name>
- <description>
+ <name>Apache Isis Maven Dependencies for Testing</name>
+ <description>
Defines a module that can be used as a single dependency for a set of common testing libraries.
</description>
-
- <profiles>
- <profile>
- <id>isis-mavendeps-testing</id>
- <activation>
- <property>
- <name>!skip.isis-mavendeps-testing</name>
- </property>
- </activation>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.isis.core</groupId>
- <artifactId>isis-unittestsupport</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.isis.core</groupId>
- <artifactId>isis-integtestsupport</artifactId>
- </dependency>
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>hamcrest-library</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.assertj</groupId>
- <artifactId>assertj-core</artifactId>
- </dependency>
-
- <dependency>
+
+ <profiles>
+ <profile>
+ <id>isis-mavendeps-testing</id>
+ <activation>
+ <property>
+ <name>!skip.isis-mavendeps-testing</name>
+ </property>
+ </activation>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.isis.core</groupId>
+ <artifactId>isis-unittestsupport</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.isis.core</groupId>
+ <artifactId>isis-integtestsupport</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>org.picocontainer</groupId>
<artifactId>picocontainer</artifactId>
</dependency>
- <dependency>
- <groupId>org.hsqldb</groupId>
- <artifactId>hsqldb</artifactId>
- </dependency>
+ <dependency>
+ <groupId>org.hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ </dependency>
- </dependencies>
- </profile>
- <profile>
- <id>flatten</id>
- <activation>
- <property>
- <name>!skip.flatten</name>
- </property>
- </activation>
- <build>
- <plugins>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>flatten-maven-plugin</artifactId>
- <version>1.0.0</version>
- <executions>
- <execution>
- <id>flatten</id>
- <phase>process-resources</phase>
- <goals>
- <goal>flatten</goal>
- </goals>
- <configuration>
- <flattenMode>bom</flattenMode>
- <updatePomFile>true</updatePomFile>
- <pomElements>
- <parent>resolve</parent>
- <profiles>resolve</profiles>
- </pomElements>
- </configuration>
- </execution>
- <execution>
- <id>flatten.clean</id>
- <phase>clean</phase>
- <goals>
- <goal>clean</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </profile>
- </profiles>
+ </dependencies>
+ </profile>
+ <profile>
+ <id>flatten</id>
+ <activation>
+ <property>
+ <name>!skip.flatten</name>
+ </property>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>flatten-maven-plugin</artifactId>
+ <version>1.0.0</version>
+ <executions>
+ <execution>
+ <id>flatten</id>
+ <phase>process-resources</phase>
+ <goals>
+ <goal>flatten</goal>
+ </goals>
+ <configuration>
+ <flattenMode>bom</flattenMode>
+ <updatePomFile>true</updatePomFile>
+ <pomElements>
+ <parent>resolve</parent>
+ <profiles>resolve</profiles>
+ </pomElements>
+ </configuration>
+ </execution>
+ <execution>
+ <id>flatten.clean</id>
+ <phase>clean</phase>
+ <goals>
+ <goal>clean</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
</project>