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 2021/06/09 13:37:55 UTC
[isis] branch ISIS-2727 updated (2cf9ef6 -> 5315fb1)
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a change to branch ISIS-2727
in repository https://gitbox.apache.org/repos/asf/isis.git.
from 2cf9ef6 ISIS-2727: fixes jdk11 dependency, javadoc is all
new 11fd859 ISIS-2727: changes InteractionLayer#getInteraction() to return Interaction
new 5afc51c ISIS-2727: javadoc only
new 7ccabd8 ISIS-2727: adds InteractionFactory#call and #run
new 5315fb1 ISIS-2727: decouples common from ThrowingRunnable
The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../org/apache/isis/commons/functional/Result.java | 4 -
.../isis/commons/functional/ThrowingRunnable.java | 7 +-
.../apache/isis/commons/functions/ResultTest.java | 95 +++++++++++-----------
.../interaction/session/InteractionFactory.java | 39 ++++++---
.../core/interaction/session/InteractionLayer.java | 30 +++++--
.../core/interaction/session/IsisInteraction.java | 8 +-
.../session/InteractionFactoryDefault.java | 40 ++++++---
...xceptionTranslationTest_usingTransactional.java | 63 +++++++-------
...xceptionTranslationTest_usingTransactional.java | 63 +++++++-------
9 files changed, 197 insertions(+), 152 deletions(-)
[isis] 03/04: ISIS-2727: adds InteractionFactory#call and #run
Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch ISIS-2727
in repository https://gitbox.apache.org/repos/asf/isis.git
commit 7ccabd8a626e83c669c84f7580f473d632fb08c9
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Wed Jun 9 14:32:54 2021 +0100
ISIS-2727: adds InteractionFactory#call and #run
that use only an InteractionContext, not an Authenticated
---
.../interaction/session/InteractionFactory.java | 39 ++++++++++++++++------
.../session/InteractionFactoryDefault.java | 30 ++++++++++++-----
2 files changed, 51 insertions(+), 18 deletions(-)
diff --git a/core/interaction/src/main/java/org/apache/isis/core/interaction/session/InteractionFactory.java b/core/interaction/src/main/java/org/apache/isis/core/interaction/session/InteractionFactory.java
index e3b3221..fa0b6a3 100644
--- a/core/interaction/src/main/java/org/apache/isis/core/interaction/session/InteractionFactory.java
+++ b/core/interaction/src/main/java/org/apache/isis/core/interaction/session/InteractionFactory.java
@@ -75,33 +75,51 @@ extends AnonymousInteractionFactory {
boolean isInInteraction();
/**
- * Executes a block of code with a new or reused {@link Authentication} using a new or
+ * Executes a block of code with a new or reused {@link InteractionContext} using a new or
* reused {@link InteractionLayer}.
+ *
* <p>
* If there is currently no {@link InteractionLayer} a new one is created.
+ * </p>
+ *
* <p>
- * If there is currently an {@link InteractionLayer} that has an equal {@link Authentication}
+ * If there is currently an {@link InteractionLayer} that has an equal {@link InteractionContext}
* to the given one, it is reused, otherwise a new one is created.
+ * </p>
*
- * @param authentication - the user details to run under (non-null)
+ * @param interactionContext - the context to run under (non-null)
* @param callable - the piece of code to run (non-null)
+ */
+ <R> R call(@NonNull InteractionContext interactionContext, @NonNull Callable<R> callable);
+
+ /**
+ * As per {@link #call(InteractionContext, Callable)}, using the {@link InteractionContext}
+ * {@link Authentication#getInteractionContext() obtained} from the provided {@link Authentication}.
*
+ * @param authentication - the user details to run under (non-null)
+ * @param callable - the piece of code to run (non-null)
*/
<R> R callAuthenticated(@NonNull Authentication authentication, @NonNull Callable<R> callable);
/**
- * Variant of {@link #callAuthenticated(Authentication, Callable)} that takes a runnable.
+ * Variant of {@link #call(InteractionContext, Callable)} that takes a runnable.
+ *
+ * @param interactionContext - the user details to run under (non-null)
+ * @param runnable (non-null)
+ */
+ void run(@NonNull InteractionContext interactionContext, @NonNull ThrowingRunnable runnable);
+
+ /**
+ * As per {@link #callAuthenticated(Authentication, Callable)}, but for a runnable.
+ *
* @param authentication - the user details to run under (non-null)
* @param runnable (non-null)
*/
void runAuthenticated(@NonNull Authentication authentication, @NonNull ThrowingRunnable runnable);
/**
- * Executes a block of code with a new or reused {@link Authentication} using a new or
- * reused {@link InteractionLayer}.
- * <p>
- * If there is currently no {@link InteractionLayer} a new one is created and a new
- * anonymous {@link InteractionLayer} is returned. Otherwise both, session and layer are reused.
+ * As per {@link #call(InteractionContext, Callable)}, but using an {@link InteractionContext}
+ * {@link Authentication#getInteractionContext() obtained} from an anonymous {@link Authentication}.
*
* @param <R>
* @param callable (non-null)
@@ -109,7 +127,8 @@ extends AnonymousInteractionFactory {
<R> R callAnonymous(@NonNull Callable<R> callable);
/**
- * Variant of {@link #callAnonymous(Callable)} that takes a runnable.
+ * As per {@link #callAnonymous(Callable)}, but for a runnable.
+ *
* @param runnable (non-null)
*/
@Override
diff --git a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/session/InteractionFactoryDefault.java b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/session/InteractionFactoryDefault.java
index 56df972..e807c7d 100644
--- a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/session/InteractionFactoryDefault.java
+++ b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/session/InteractionFactoryDefault.java
@@ -241,12 +241,10 @@ implements
@Override
@SneakyThrows
- public <R> R callAuthenticated(
- @NonNull final Authentication authentication,
- @NonNull final Callable<R> callable) {
+ public <R> R call(@NonNull InteractionContext interactionContext, @NonNull Callable<R> callable) {
final int stackSizeWhenEntering = interactionLayerStack.get().size();
- openInteraction(authentication.getInteractionContext());
+ openInteraction(interactionContext);
try {
serviceInjector.injectServicesInto(callable);
@@ -254,17 +252,23 @@ implements
} finally {
closeInteractionLayerStackDownToStackSize(stackSizeWhenEntering);
}
-
}
+
@Override
@SneakyThrows
- public void runAuthenticated(
+ public <R> R callAuthenticated(
@NonNull final Authentication authentication,
- @NonNull final ThrowingRunnable runnable) {
+ @NonNull final Callable<R> callable) {
+
+ return call(authentication.getInteractionContext(), callable);
+ }
+ @Override
+ @SneakyThrows
+ public void run(@NonNull InteractionContext interactionContext, @NonNull ThrowingRunnable runnable) {
final int stackSizeWhenEntering = interactionLayerStack.get().size();
- openInteraction(authentication.getInteractionContext());
+ openInteraction(interactionContext);
try {
serviceInjector.injectServicesInto(runnable);
@@ -272,6 +276,16 @@ implements
} finally {
closeInteractionLayerStackDownToStackSize(stackSizeWhenEntering);
}
+
+ }
+
+ @Override
+ @SneakyThrows
+ public void runAuthenticated(
+ @NonNull final Authentication authentication,
+ @NonNull final ThrowingRunnable runnable) {
+
+ run(authentication.getInteractionContext(), runnable);
}
[isis] 02/04: ISIS-2727: javadoc only
Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch ISIS-2727
in repository https://gitbox.apache.org/repos/asf/isis.git
commit 5afc51ccbdde47de459c6d08f15e76628fb130b9
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Wed Jun 9 14:12:38 2021 +0100
ISIS-2727: javadoc only
---
.../core/interaction/session/InteractionLayer.java | 27 +++++++++++++++++-----
1 file changed, 21 insertions(+), 6 deletions(-)
diff --git a/core/interaction/src/main/java/org/apache/isis/core/interaction/session/InteractionLayer.java b/core/interaction/src/main/java/org/apache/isis/core/interaction/session/InteractionLayer.java
index a548290..80c9560 100644
--- a/core/interaction/src/main/java/org/apache/isis/core/interaction/session/InteractionLayer.java
+++ b/core/interaction/src/main/java/org/apache/isis/core/interaction/session/InteractionLayer.java
@@ -23,28 +23,43 @@ import org.apache.isis.applib.services.iactnlayer.InteractionContext;
import lombok.Getter;
import lombok.NonNull;
+import lombok.RequiredArgsConstructor;
/**
- * Provides the environment for an (or parts of an) user interaction to be executed.
+ * Binds the {@link Interaction} ("what" is being executed) with
+ * an {@link InteractionContext} ("who" is executing, "when" and "where").
*
* <p>
- * These may be nested (held in a stack), for example for the {@link org.apache.isis.applib.services.sudo.SudoService},
- * or for fixtures that mock the clock.
+ * {@link InteractionLayer}s are so called because they may be nested (held in a stack). For example the
+ * {@link org.apache.isis.applib.services.sudo.SudoService} creates a new temporary layer with a different
+ * {@link InteractionContext#getUser() user}, while fixtures that mock the clock switch out the
+ * {@link InteractionContext#getClock() clock}.
+ * </p>
*
- * @since 2.0
+ * <p>
+ * The stack of layers is per-thread, managed by {@link InteractionFactory} as a thread-local).
+ * </p>
*
+ * @since 2.0
*/
+@RequiredArgsConstructor
public class InteractionLayer {
+ /**
+ *
+ * Current thread's {@link Interaction} which this layer belongs to.
+ */
@Getter private final Interaction interaction;
+ /**
+ * Represents the // binds given interaction context (which normally would hold the Authentication in its attribute map)
+ * // to this layer
+ */
@Getter private final InteractionContext interactionContext;
public InteractionLayer(
final @NonNull IsisInteraction interaction,
final @NonNull InteractionContext interactionContext) {
- // current thread's Interaction which this layer belongs to,
- // meaning the Interaction that holds the stack containing this layer
this.interaction = interaction;
// binds given interaction context (which normally would hold the Authentication in its attribute map)
[isis] 01/04: ISIS-2727: changes InteractionLayer#getInteraction()
to return Interaction
Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch ISIS-2727
in repository https://gitbox.apache.org/repos/asf/isis.git
commit 11fd859af4bd250da0bdb8cb0b2b3c19e15abd97
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Wed Jun 9 14:05:52 2021 +0100
ISIS-2727: changes InteractionLayer#getInteraction() to return Interaction
(in the applib) rather than IsisInteraction (internal).
This should let us now move it up into the applib. There were only 2 downcasts required for this
---
.../apache/isis/core/interaction/session/InteractionLayer.java | 3 ++-
.../apache/isis/core/interaction/session/IsisInteraction.java | 8 ++------
.../runtimeservices/session/InteractionFactoryDefault.java | 10 ++++++----
3 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/core/interaction/src/main/java/org/apache/isis/core/interaction/session/InteractionLayer.java b/core/interaction/src/main/java/org/apache/isis/core/interaction/session/InteractionLayer.java
index e0626ab..a548290 100644
--- a/core/interaction/src/main/java/org/apache/isis/core/interaction/session/InteractionLayer.java
+++ b/core/interaction/src/main/java/org/apache/isis/core/interaction/session/InteractionLayer.java
@@ -18,6 +18,7 @@
*/
package org.apache.isis.core.interaction.session;
+import org.apache.isis.applib.services.iactn.Interaction;
import org.apache.isis.applib.services.iactnlayer.InteractionContext;
import lombok.Getter;
@@ -35,7 +36,7 @@ import lombok.NonNull;
*/
public class InteractionLayer {
- @Getter private final IsisInteraction interaction;
+ @Getter private final Interaction interaction;
@Getter private final InteractionContext interactionContext;
public InteractionLayer(
diff --git a/core/interaction/src/main/java/org/apache/isis/core/interaction/session/IsisInteraction.java b/core/interaction/src/main/java/org/apache/isis/core/interaction/session/IsisInteraction.java
index e280fa2..bed59cb 100644
--- a/core/interaction/src/main/java/org/apache/isis/core/interaction/session/IsisInteraction.java
+++ b/core/interaction/src/main/java/org/apache/isis/core/interaction/session/IsisInteraction.java
@@ -247,16 +247,12 @@ implements InteractionInternal {
@Override
public <T> T getAttribute(Class<T> type) {
- return (attributes!=null)
- ? _Casts.uncheckedCast(attributes.get(type))
- : null;
+ return _Casts.uncheckedCast(attributes.get(type));
}
@Override
public void removeAttribute(Class<?> type) {
- if(attributes!=null) {
- attributes.remove(type);
- }
+ attributes.remove(type);
}
diff --git a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/session/InteractionFactoryDefault.java b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/session/InteractionFactoryDefault.java
index 3787072..56df972 100644
--- a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/session/InteractionFactoryDefault.java
+++ b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/session/InteractionFactoryDefault.java
@@ -51,6 +51,7 @@ import org.apache.isis.applib.util.schema.ChangesDtoUtils;
import org.apache.isis.applib.util.schema.CommandDtoUtils;
import org.apache.isis.applib.util.schema.InteractionDtoUtils;
import org.apache.isis.commons.functional.ThrowingRunnable;
+import org.apache.isis.commons.internal.base._Casts;
import org.apache.isis.commons.internal.concurrent._ConcurrentContext;
import org.apache.isis.commons.internal.concurrent._ConcurrentTaskList;
import org.apache.isis.commons.internal.debug._Probe;
@@ -207,9 +208,10 @@ implements
private IsisInteraction getOrCreateIsisInteraction() {
- return interactionLayerStack.get().isEmpty()
+ final Stack<InteractionLayer> interactionLayers = interactionLayerStack.get();
+ return interactionLayers.isEmpty()
? new IsisInteraction(UUID.randomUUID())
- : interactionLayerStack.get().firstElement().getInteraction();
+ : _Casts.uncheckedCast(interactionLayers.firstElement().getInteraction());
}
@Override
@@ -324,7 +326,7 @@ implements
interactionScopeLifecycleHandler.onTopLevelInteractionOpened();
}
- private void preSessionClosed(IsisInteraction interaction) {
+ private void preInteractionClosed(IsisInteraction interaction) {
completeAndPublishCurrentCommand();
interactionScopeLifecycleHandler.onTopLevelInteractionClosing(); // cleanup the isis-session scope
val isSynchronizationActive = TransactionSynchronizationManager.isSynchronizationActive();
@@ -346,7 +348,7 @@ implements
while(stack.size()>downToStackSize) {
if(isInBaseLayer()) {
// keep the stack unmodified yet, to allow for callbacks to properly operate
- preSessionClosed(stack.peek().getInteraction());
+ preInteractionClosed(_Casts.uncheckedCast(stack.peek().getInteraction()));
}
_Xray.closeInteractionLayer(stack);
stack.pop();
[isis] 04/04: ISIS-2727: decouples common from ThrowingRunnable
Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch ISIS-2727
in repository https://gitbox.apache.org/repos/asf/isis.git
commit 5315fb12cd5b4eca84023a43d87318c520137778
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Wed Jun 9 14:37:36 2021 +0100
ISIS-2727: decouples common from ThrowingRunnable
... preparing to move ThrowingRunnable into applib
... moves Result.ofVoid(ThrowingRunnable) to ThrowingRunnable.resultOf(ThrowingRunnable)
---
.../org/apache/isis/commons/functional/Result.java | 4 -
.../isis/commons/functional/ThrowingRunnable.java | 7 +-
.../apache/isis/commons/functions/ResultTest.java | 95 +++++++++++-----------
...xceptionTranslationTest_usingTransactional.java | 63 +++++++-------
...xceptionTranslationTest_usingTransactional.java | 63 +++++++-------
5 files changed, 115 insertions(+), 117 deletions(-)
diff --git a/commons/src/main/java/org/apache/isis/commons/functional/Result.java b/commons/src/main/java/org/apache/isis/commons/functional/Result.java
index 0197c68..5ad15d6 100644
--- a/commons/src/main/java/org/apache/isis/commons/functional/Result.java
+++ b/commons/src/main/java/org/apache/isis/commons/functional/Result.java
@@ -61,10 +61,6 @@ public final class Result<L> {
}
}
- public static Result<Void> ofVoid(final @NonNull ThrowingRunnable runnable) {
- return of(ThrowingRunnable.toCallable(runnable));
- }
-
public static <L> Result<L> success(final @Nullable L value) {
return of(value, null, true);
}
diff --git a/commons/src/main/java/org/apache/isis/commons/functional/ThrowingRunnable.java b/commons/src/main/java/org/apache/isis/commons/functional/ThrowingRunnable.java
index ffe8df7..988aa21 100644
--- a/commons/src/main/java/org/apache/isis/commons/functional/ThrowingRunnable.java
+++ b/commons/src/main/java/org/apache/isis/commons/functional/ThrowingRunnable.java
@@ -25,6 +25,7 @@ import lombok.NonNull;
@FunctionalInterface
public interface ThrowingRunnable {
+
// -- INTERFACE
void run() throws Exception;
@@ -32,11 +33,13 @@ public interface ThrowingRunnable {
// -- UTILITY
static Callable<Void> toCallable(final @NonNull ThrowingRunnable runnable) {
- final Callable<Void> callable = ()->{
+ return ()->{
runnable.run();
return null;
};
- return callable;
}
+ static Result<Void> resultOf(final @NonNull ThrowingRunnable runnable) {
+ return Result.of(toCallable(runnable));
+ }
}
diff --git a/commons/src/test/java/org/apache/isis/commons/functions/ResultTest.java b/commons/src/test/java/org/apache/isis/commons/functions/ResultTest.java
index 6821e06..94efa4c 100644
--- a/commons/src/test/java/org/apache/isis/commons/functions/ResultTest.java
+++ b/commons/src/test/java/org/apache/isis/commons/functions/ResultTest.java
@@ -30,85 +30,86 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import org.apache.isis.commons.functional.Result;
+import org.apache.isis.commons.functional.ThrowingRunnable;
import lombok.val;
class ResultTest {
// -- TEST DUMMIES
-
+
String hello_happy() {
return "hello";
}
-
+
String hello_nullable() {
return null;
}
-
+
String hello_throwing_uncatched() {
throw new RuntimeException("hello failed");
}
-
+
String hello_throwing_catched() throws Exception {
throw new Exception("hello failed");
}
void void_happy() {
-
+
}
-
+
void void_throwing_uncatched() {
throw new RuntimeException("void failed");
}
-
+
void void_throwing_catched() throws Exception {
throw new Exception("void failed");
}
-
-
+
+
// -- TESTS
-
+
@Test
void hello_happy_case() {
-
+
val result = Result.<String>of(this::hello_happy);
assertTrue(result.isSuccess());
assertFalse(result.isFailure());
assertEquals("hello", result.presentElse(""));
assertEquals("hello", result.getValue().orElse(null));
assertEquals("hello", result.presentElseFail());
-
+
// non-evaluated code-path
result.presentElseGet(()->fail("unexpected code reach"));
-
+
// default value is not allowed to be null
assertThrows(NullPointerException.class, ()->result.presentElse(null));
-
+
val mandatory = result.mapSuccessWithEmptyValueToNoSuchElement();
assertTrue(mandatory.isSuccess());
assertEquals("hello", mandatory.presentElse(""));
-
+
}
-
+
@Test
void hello_nullable_case() {
-
+
val result = Result.<String>of(this::hello_nullable);
assertTrue(result.isSuccess());
assertFalse(result.isFailure());
assertEquals("no value", result.getValue().orElse("no value"));
assertThrows(NoSuchElementException.class, ()->result.presentElseFail());
assertEquals(Optional.empty(), result.optionalElseFail());
-
+
val mandatory = result.mapSuccessWithEmptyValueToNoSuchElement();
assertTrue(mandatory.isFailure());
assertThrows(NoSuchElementException.class, ()->mandatory.optionalElseFail());
-
+
}
-
+
@Test
void hello_throwing_uncatched_case() {
-
+
val result = Result.<String>of(this::hello_throwing_uncatched);
assertFalse(result.isSuccess());
assertTrue(result.isFailure());
@@ -117,15 +118,15 @@ class ResultTest {
assertEquals("it failed", result.presentElseGet(()->"it failed"));
assertThrows(RuntimeException.class, ()->result.presentElseFail());
assertEquals(Optional.empty(), result.getValue());
-
+
val mandatory = result.mapSuccessWithEmptyValueToNoSuchElement();
assertTrue(mandatory.isFailure());
-
+
}
-
+
@Test
void hello_throwing_catched_case() {
-
+
val result = Result.<String>of(this::hello_throwing_catched);
assertFalse(result.isSuccess());
assertTrue(result.isFailure());
@@ -134,63 +135,63 @@ class ResultTest {
assertEquals("it failed", result.presentElseGet(()->"it failed"));
assertThrows(Exception.class, ()->result.presentElseFail());
assertEquals(Optional.empty(), result.getValue());
-
+
val mandatory = result.mapSuccessWithEmptyValueToNoSuchElement();
assertTrue(mandatory.isFailure());
-
+
}
-
+
@Test
void void_happy_case() {
-
- val result = Result.ofVoid(this::void_happy);
+
+ val result = ThrowingRunnable.resultOf(this::void_happy);
assertTrue(result.isSuccess());
assertFalse(result.isFailure());
assertEquals(null, result.getValue().orElse(null));
-
+
assertThrows(NoSuchElementException.class, ()->result.presentElseFail());
-
+
// default value is not allowed to be null
assertThrows(NullPointerException.class, ()->result.presentElse(null));
-
+
}
-
-
+
+
@Test
void void_throwing_uncatched_case() {
-
- val result = Result.ofVoid(this::void_throwing_uncatched);
+
+ val result = ThrowingRunnable.resultOf(this::void_throwing_uncatched);
assertFalse(result.isSuccess());
assertTrue(result.isFailure());
assertEquals("void failed", result.getFailure().get().getMessage());
-
+
// default value is not allowed to be null
assertThrows(NullPointerException.class, ()->result.presentElse(null));
assertThrows(NoSuchElementException.class, ()->result.presentElseGet(()->null));
assertThrows(Exception.class, ()->result.presentElseFail());
assertEquals(Optional.empty(), result.getValue());
-
+
val mandatory = result.mapSuccessWithEmptyValueToNoSuchElement();
assertTrue(mandatory.isFailure());
}
-
+
@Test
void void_throwing_catched_case() {
-
- val result = Result.ofVoid(this::void_throwing_catched);
+
+ val result = ThrowingRunnable.resultOf(this::void_throwing_catched);
assertFalse(result.isSuccess());
assertTrue(result.isFailure());
assertEquals("void failed", result.getFailure().get().getMessage());
-
+
// default value is not allowed to be null
assertThrows(NullPointerException.class, ()->result.presentElse(null));
assertThrows(NoSuchElementException.class, ()->result.presentElseGet(()->null));
assertThrows(Exception.class, ()->result.presentElseFail());
assertEquals(Optional.empty(), result.getValue());
-
+
val mandatory = result.mapSuccessWithEmptyValueToNoSuchElement();
assertTrue(mandatory.isFailure());
}
-
-
-}
\ No newline at end of file
+
+
+}
diff --git a/regressiontests/stable-persistence-jdo/src/test/java/org/apache/isis/testdomain/persistence/jdo/JdoExceptionTranslationTest_usingTransactional.java b/regressiontests/stable-persistence-jdo/src/test/java/org/apache/isis/testdomain/persistence/jdo/JdoExceptionTranslationTest_usingTransactional.java
index 927e3ec..d3a499e 100644
--- a/regressiontests/stable-persistence-jdo/src/test/java/org/apache/isis/testdomain/persistence/jdo/JdoExceptionTranslationTest_usingTransactional.java
+++ b/regressiontests/stable-persistence-jdo/src/test/java/org/apache/isis/testdomain/persistence/jdo/JdoExceptionTranslationTest_usingTransactional.java
@@ -42,7 +42,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import org.apache.isis.applib.services.repository.RepositoryService;
-import org.apache.isis.commons.functional.Result;
import org.apache.isis.commons.functional.ThrowingRunnable;
import org.apache.isis.core.config.presets.IsisPresets;
import org.apache.isis.core.interaction.session.InteractionFactory;
@@ -54,12 +53,12 @@ import org.apache.isis.testdomain.jdo.entities.JdoInventory;
import lombok.val;
@SpringBootTest(
- classes = {
+ classes = {
Configuration_usingJdo.class,
JdoInventoryDao.class,
})
@TestPropertySources({
- @TestPropertySource(IsisPresets.UseLog4j2Test)
+ @TestPropertySource(IsisPresets.UseLog4j2Test)
})
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class JdoExceptionTranslationTest_usingTransactional
@@ -77,77 +76,77 @@ class JdoExceptionTranslationTest_usingTransactional
// launch H2Console for troubleshooting ...
// Util_H2Console.main(null);
}
-
- @Test @Order(1)
+
+ @Test @Order(1)
@Transactional @Rollback(false)
void booksUniqueByIsbn_setupPhase() {
interactionFactory.runAnonymous(()->{
-
+
_TestFixtures.setUp3Books(repositoryService);
-
+
});
}
- @Test @Order(2)
+ @Test @Order(2)
void booksUniqueByIsbn_whenViolated_shouldThrowTranslatedException() {
// when adding a book for which one with same ISBN already exists in the database,
// we expect to see a Spring recognized DataAccessException been thrown
-
- final ThrowingRunnable uniqueConstraintViolator =
+
+ final ThrowingRunnable uniqueConstraintViolator =
()->inventoryDao.get().addBook_havingIsbnA_usingRepositoryService();
-
+
assertThrows(DataIntegrityViolationException.class, ()->{
-
+
interactionFactory.runAnonymous(()->{
-
- Result.ofVoid(uniqueConstraintViolator)
+
+ ThrowingRunnable.resultOf(uniqueConstraintViolator)
.ifSuccess(__->fail("expected to fail, but did not"))
//.mapFailure(ex->_JdoExceptionTranslator.translate(ex, txManager))
.ifFailure(ex->assertTrue(ex instanceof DataIntegrityViolationException))
.optionalElseFail();
-
+
});
-
+
});
-
- }
-
- @Test @Order(3)
+
+ }
+
+ @Test @Order(3)
@Transactional @Rollback(false)
void booksUniqueByIsbn_verifyPhase() {
// expected post condition: ONE inventory with 3 books
-
+
interactionFactory.runAnonymous(()->{
-
+
val inventories = repositoryService.allInstances(JdoInventory.class);
assertEquals(1, inventories.size());
-
+
val inventory = inventories.get(0);
assertNotNull(inventory);
-
+
assertNotNull(inventory);
assertNotNull(inventory.getProducts());
assertEquals(3, inventory.getProducts().size());
_TestFixtures.assertInventoryHasBooks(inventory.getProducts(), 1, 2, 3);
-
+
});
-
+
}
-
- @Test @Order(4)
+
+ @Test @Order(4)
@Transactional @Rollback(false)
void booksUniqueByIsbn_cleanupPhase() {
interactionFactory.runAnonymous(()->{
_TestFixtures.cleanUp(repositoryService);
-
+
});
-
+
}
-
-
+
+
}
diff --git a/regressiontests/stable-persistence-jpa/src/test/java/org/apache/isis/testdomain/persistence/jpa/JpaExceptionTranslationTest_usingTransactional.java b/regressiontests/stable-persistence-jpa/src/test/java/org/apache/isis/testdomain/persistence/jpa/JpaExceptionTranslationTest_usingTransactional.java
index fef6619..ec4d9d0 100644
--- a/regressiontests/stable-persistence-jpa/src/test/java/org/apache/isis/testdomain/persistence/jpa/JpaExceptionTranslationTest_usingTransactional.java
+++ b/regressiontests/stable-persistence-jpa/src/test/java/org/apache/isis/testdomain/persistence/jpa/JpaExceptionTranslationTest_usingTransactional.java
@@ -43,7 +43,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import org.apache.isis.applib.services.repository.RepositoryService;
-import org.apache.isis.commons.functional.Result;
import org.apache.isis.commons.functional.ThrowingRunnable;
import org.apache.isis.core.config.presets.IsisPresets;
import org.apache.isis.core.interaction.session.InteractionFactory;
@@ -54,12 +53,12 @@ import org.apache.isis.testdomain.jpa.entities.JpaInventory;
import lombok.val;
@SpringBootTest(
- classes = {
+ classes = {
Configuration_usingJpa.class,
JpaInventoryDao.class
})
@TestPropertySources({
- @TestPropertySource(IsisPresets.UseLog4j2Test)
+ @TestPropertySource(IsisPresets.UseLog4j2Test)
})
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class JpaExceptionTranslationTest_usingTransactional
@@ -77,66 +76,66 @@ class JpaExceptionTranslationTest_usingTransactional
// launch H2Console for troubleshooting ...
// Util_H2Console.main(null);
}
-
- @Test @Order(1)
+
+ @Test @Order(1)
@Transactional @Rollback(false)
void booksUniqueByIsbn_setupPhase() {
interactionFactory.runAnonymous(()->{
-
+
_TestFixtures.setUp3Books(repositoryService);
-
+
});
}
-
+
@Test @Order(2)
void booksUniqueByIsbn_whenViolated_shouldThrowTranslatedException() {
// when adding a book for which one with same ISBN already exists in the database,
- // we expect to see a Spring recognized DataAccessException been thrown
-
- final ThrowingRunnable uniqueConstraintViolator =
+ // we expect to see a Spring recognized DataAccessException been thrown
+
+ final ThrowingRunnable uniqueConstraintViolator =
()->inventoryDao.get().addBook_havingIsbnA_usingRepositoryService();
-
+
assertThrows(DataIntegrityViolationException.class, ()->{
-
+
interactionFactory.runAnonymous(()->{
-
- Result.ofVoid(uniqueConstraintViolator)
+
+ ThrowingRunnable.resultOf(uniqueConstraintViolator)
.ifSuccess(__->fail("expected to fail, but did not"))
- // .mapFailure(ex->_JpaExceptionTranslator.translate(ex, txManager))
+ // .mapFailure(ex->_JpaExceptionTranslator.translate(ex, txManager))
.ifFailure(ex->assertTrue(ex instanceof DataIntegrityViolationException))
.optionalElseFail();
-
+
});
-
+
});
-
- }
-
+
+ }
+
@Test @Order(3)
@Transactional @Rollback(false)
void booksUniqueByIsbn_verifyPhase() {
// expected post condition: ONE inventory with 3 books
-
+
interactionFactory.runAnonymous(()->{
-
+
val inventories = repositoryService.allInstances(JpaInventory.class);
assertEquals(1, inventories.size());
-
+
val inventory = inventories.get(0);
assertNotNull(inventory);
-
+
assertNotNull(inventory);
assertNotNull(inventory.getProducts());
assertEquals(3, inventory.getProducts().size());
_TestFixtures.assertInventoryHasBooks(inventory.getProducts(), 1, 2, 3);
-
+
});
-
+
}
-
+
@Test @Order(4)
@Transactional @Rollback(false)
void booksUniqueByIsbn_cleanupPhase() {
@@ -144,10 +143,10 @@ class JpaExceptionTranslationTest_usingTransactional
interactionFactory.runAnonymous(()->{
_TestFixtures.cleanUp(repositoryService);
-
+
});
-
+
}
-
-
+
+
}