From 27c413afda86e55dd66e3c7c472ae81b69b0ed68 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Tue, 23 Apr 2019 17:20:48 +0200 Subject: [PATCH] [Fix] Throw exception if modifying a read-only TX --- .../persistence/api/AbstractTransaction.java | 20 +++++- .../inmemory/InMemoryActivityQueryTest.java | 65 +++++++++---------- .../inmemory/InMemoryOrderQueryTest.java | 65 +++++++++---------- .../inmemory/InMemoryResourceQueryTest.java | 63 +++++++++--------- 4 files changed, 111 insertions(+), 102 deletions(-) diff --git a/li.strolch.agent/src/main/java/li/strolch/persistence/api/AbstractTransaction.java b/li.strolch.agent/src/main/java/li/strolch/persistence/api/AbstractTransaction.java index cee29ce73..b82026b5e 100644 --- a/li.strolch.agent/src/main/java/li/strolch/persistence/api/AbstractTransaction.java +++ b/li.strolch.agent/src/main/java/li/strolch/persistence/api/AbstractTransaction.java @@ -311,9 +311,15 @@ public abstract class AbstractTransaction implements StrolchTransaction { @Override public void addCommand(Command command) { + assertNotReadOnly(); this.commands.add(command); } + private void assertNotReadOnly() { + DBC.PRE.assertFalse("TX is marked as read-only, can not add commands!", + this.closeStrategy == TransactionCloseStrategy.READ_ONLY); + } + @Override public ResourceMap getResourceMap() { if (this.resourceMap == null) { @@ -958,6 +964,7 @@ public abstract class AbstractTransaction implements StrolchTransaction { @Override public void addOrUpdate(Resource resource) throws StrolchModelException { + assertNotReadOnly(); DBC.PRE.assertNotNull("resource must not be null", resource); if (hasResource(resource.getType(), resource.getId()) && !getObjectFilter() .hasElement(Tags.RESOURCE, resource.getLocator())) @@ -968,6 +975,7 @@ public abstract class AbstractTransaction implements StrolchTransaction { @Override public void addOrUpdate(Order order) throws StrolchModelException { + assertNotReadOnly(); DBC.PRE.assertNotNull("order must not be null", order); if (hasOrder(order.getType(), order.getId()) && !getObjectFilter().hasElement(Tags.ORDER, order.getLocator())) getObjectFilter().update(Tags.ORDER, order.getLocator(), order); @@ -977,6 +985,7 @@ public abstract class AbstractTransaction implements StrolchTransaction { @Override public void addOrUpdate(Activity activity) throws StrolchModelException { + assertNotReadOnly(); DBC.PRE.assertNotNull("activity must not be null", activity); if (hasActivity(activity.getType(), activity.getId()) && !getObjectFilter() .hasElement(Tags.ACTIVITY, activity.getLocator())) @@ -987,42 +996,49 @@ public abstract class AbstractTransaction implements StrolchTransaction { @Override public void add(Resource resource) throws StrolchModelException { + assertNotReadOnly(); DBC.PRE.assertNotNull("resource must not be null", resource); getObjectFilter().add(Tags.RESOURCE, resource.getLocator(), resource); } @Override public void add(Order order) throws StrolchException { + assertNotReadOnly(); DBC.PRE.assertNotNull("order must not be null", order); getObjectFilter().add(Tags.ORDER, order.getLocator(), order); } @Override public void add(Activity activity) throws StrolchException { + assertNotReadOnly(); DBC.PRE.assertNotNull("activity must not be null", activity); getObjectFilter().add(Tags.ACTIVITY, activity.getLocator(), activity); } @Override public void update(Resource resource) throws StrolchException { + assertNotReadOnly(); DBC.PRE.assertNotNull("resource must not be null", resource); getObjectFilter().update(Tags.RESOURCE, resource.getLocator(), resource); } @Override public void update(Order order) { + assertNotReadOnly(); DBC.PRE.assertNotNull("order must not be null", order); getObjectFilter().update(Tags.ORDER, order.getLocator(), order); } @Override public void update(Activity activity) throws StrolchException { + assertNotReadOnly(); DBC.PRE.assertNotNull("activity must not be null", activity); getObjectFilter().update(Tags.ACTIVITY, activity.getLocator(), activity); } @Override public void remove(Resource resource) throws StrolchException { + assertNotReadOnly(); DBC.PRE.assertNotNull("resource must not be null", resource); getObjectFilter().remove(Tags.RESOURCE, resource.getLocator(), resource); if (this.resourceCache != null) { @@ -1032,6 +1048,7 @@ public abstract class AbstractTransaction implements StrolchTransaction { @Override public void remove(Order order) throws StrolchException { + assertNotReadOnly(); DBC.PRE.assertNotNull("order must not be null", order); getObjectFilter().remove(Tags.ORDER, order.getLocator(), order); if (this.orderCache != null) { @@ -1041,6 +1058,7 @@ public abstract class AbstractTransaction implements StrolchTransaction { @Override public void remove(Activity activity) throws StrolchException { + assertNotReadOnly(); DBC.PRE.assertNotNull("activity must not be null", activity); getObjectFilter().remove(Tags.ACTIVITY, activity.getLocator(), activity); if (this.activityCache != null) { @@ -1273,7 +1291,7 @@ public abstract class AbstractTransaction implements StrolchTransaction { try { this.txResult.setState(TransactionState.CLOSING); - if (this.closeStrategy == TransactionCloseStrategy.READ_ONLY) { + if (this.closeStrategy != TransactionCloseStrategy.READ_ONLY) { if (!this.commands.isEmpty()) { autoCloseableRollback(); String msg = "There are commands registered on a read-only transaction. Changing to rollback! Did you forget to commit?"; diff --git a/li.strolch.agent/src/test/java/li/strolch/runtime/query/inmemory/InMemoryActivityQueryTest.java b/li.strolch.agent/src/test/java/li/strolch/runtime/query/inmemory/InMemoryActivityQueryTest.java index 132bfdcce..a6f75ba3b 100644 --- a/li.strolch.agent/src/test/java/li/strolch/runtime/query/inmemory/InMemoryActivityQueryTest.java +++ b/li.strolch.agent/src/test/java/li/strolch/runtime/query/inmemory/InMemoryActivityQueryTest.java @@ -1,5 +1,6 @@ package li.strolch.runtime.query.inmemory; +import static java.util.Arrays.asList; import static li.strolch.agent.ComponentContainerTest.PATH_EMPTY_CONTAINER; import static li.strolch.model.query.ParameterSelection.*; import static li.strolch.utils.StringMatchMode.ci; @@ -7,7 +8,6 @@ import static li.strolch.utils.StringMatchMode.es; import static org.junit.Assert.assertEquals; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import li.strolch.RuntimeMock; @@ -48,16 +48,16 @@ public class InMemoryActivityQueryTest { certificate = login(runtimeMock.getAgent()); - try (StrolchTransaction tx = openTx()) { + try (StrolchTransaction tx = openTx(false)) { getActivities().forEach(tx::add); tx.add(getBallActivity()); tx.commitOnClose(); } } - private static StrolchTransaction openTx() { + private static StrolchTransaction openTx(boolean readOnly) { return runtimeMock.getAgent().getContainer().getRealm(StrolchConstants.DEFAULT_REALM) - .openTx(certificate, "test", true); + .openTx(certificate, "test", readOnly); } @AfterClass @@ -69,7 +69,7 @@ public class InMemoryActivityQueryTest { @Test public void shouldQueryById() { - try (StrolchTransaction tx = openTx()) { + try (StrolchTransaction tx = openTx(true)) { ActivityQuery activityQuery = ActivityQuery.query("MyType1"); activityQuery.with(new IdSelection("@1")); @@ -83,7 +83,7 @@ public class InMemoryActivityQueryTest { @Test public void shouldQueryByIdOr() { - try (StrolchTransaction tx = openTx()) { + try (StrolchTransaction tx = openTx(true)) { ActivityQuery activityQuery = ActivityQuery.query("MyType2"); activityQuery.or().with(new IdSelection("@3"), new IdSelection("@4")); @@ -98,7 +98,7 @@ public class InMemoryActivityQueryTest { @Test public void shouldQueryByIdAnd() { - try (StrolchTransaction tx = openTx()) { + try (StrolchTransaction tx = openTx(true)) { ActivityQuery activityQuery = ActivityQuery.query("MyType2"); activityQuery.and().with(new IdSelection("@3"), new NameSelection("Activity 3", es())); @@ -112,7 +112,7 @@ public class InMemoryActivityQueryTest { @Test public void shouldNotQueryByIdAnd() { - try (StrolchTransaction tx = openTx()) { + try (StrolchTransaction tx = openTx(true)) { ActivityQuery activityQuery = ActivityQuery.query("MyType1"); activityQuery.and().with(new IdSelection("@3"), new NameSelection("@4", es())); @@ -125,7 +125,7 @@ public class InMemoryActivityQueryTest { @Test public void shouldQueryByParameter() { - try (StrolchTransaction tx = openTx()) { + try (StrolchTransaction tx = openTx(true)) { ActivityQuery ballQuery = ActivityQuery.query("Ball"); ballQuery.and().with( @@ -142,7 +142,7 @@ public class InMemoryActivityQueryTest { @Test public void shouldQueryByListParameter() { - try (StrolchTransaction tx = openTx()) { + try (StrolchTransaction tx = openTx(true)) { ActivityQuery ballQuery; List result; @@ -150,18 +150,17 @@ public class InMemoryActivityQueryTest { // string list { ballQuery = ActivityQuery.query("Ball"); - ballQuery.and().with(stringListSelection("parameters", "stringListValues", Arrays.asList("a", "z"))); + ballQuery.and().with(stringListSelection("parameters", "stringListValues", asList("a", "z"))); result = tx.doQuery(ballQuery); assertEquals(0, result.size()); ballQuery = ActivityQuery.query("Ball"); - ballQuery.and().with(stringListSelection("parameters", "stringListValues", Arrays.asList("a"))); + ballQuery.and().with(stringListSelection("parameters", "stringListValues", asList("a"))); result = tx.doQuery(ballQuery); assertEquals(1, result.size()); ballQuery = ActivityQuery.query("Ball"); - ballQuery.and() - .with(stringListSelection("parameters", "stringListValues", Arrays.asList("c", "b", "a"))); + ballQuery.and().with(stringListSelection("parameters", "stringListValues", asList("c", "b", "a"))); result = tx.doQuery(ballQuery); assertEquals(1, result.size()); } @@ -169,17 +168,17 @@ public class InMemoryActivityQueryTest { // integer list { ballQuery = ActivityQuery.query("Ball"); - ballQuery.and().with(integerListSelection("parameters", "intListValues", Arrays.asList(1, 5))); + ballQuery.and().with(integerListSelection("parameters", "intListValues", asList(1, 5))); result = tx.doQuery(ballQuery); assertEquals(0, result.size()); ballQuery = ActivityQuery.query("Ball"); - ballQuery.and().with(integerListSelection("parameters", "intListValues", Arrays.asList(1))); + ballQuery.and().with(integerListSelection("parameters", "intListValues", asList(1))); result = tx.doQuery(ballQuery); assertEquals(1, result.size()); ballQuery = ActivityQuery.query("Ball"); - ballQuery.and().with(integerListSelection("parameters", "intListValues", Arrays.asList(3, 2, 1))); + ballQuery.and().with(integerListSelection("parameters", "intListValues", asList(3, 2, 1))); result = tx.doQuery(ballQuery); assertEquals(1, result.size()); } @@ -187,17 +186,17 @@ public class InMemoryActivityQueryTest { // float list { ballQuery = ActivityQuery.query("Ball"); - ballQuery.and().with(floatListSelection("parameters", "floatListValues", Arrays.asList(4.0, 8.0))); + ballQuery.and().with(floatListSelection("parameters", "floatListValues", asList(4.0, 8.0))); result = tx.doQuery(ballQuery); assertEquals(0, result.size()); ballQuery = ActivityQuery.query("Ball"); - ballQuery.and().with(floatListSelection("parameters", "floatListValues", Arrays.asList(4.0))); + ballQuery.and().with(floatListSelection("parameters", "floatListValues", asList(4.0))); result = tx.doQuery(ballQuery); assertEquals(1, result.size()); ballQuery = ActivityQuery.query("Ball"); - ballQuery.and().with(floatListSelection("parameters", "floatListValues", Arrays.asList(6.2, 5.1, 4.0))); + ballQuery.and().with(floatListSelection("parameters", "floatListValues", asList(6.2, 5.1, 4.0))); result = tx.doQuery(ballQuery); assertEquals(1, result.size()); } @@ -205,17 +204,17 @@ public class InMemoryActivityQueryTest { // long list { ballQuery = ActivityQuery.query("Ball"); - ballQuery.and().with(longListSelection("parameters", "longListValues", Arrays.asList(8L, 11L))); + ballQuery.and().with(longListSelection("parameters", "longListValues", asList(8L, 11L))); result = tx.doQuery(ballQuery); assertEquals(0, result.size()); ballQuery = ActivityQuery.query("Ball"); - ballQuery.and().with(longListSelection("parameters", "longListValues", Arrays.asList(8L))); + ballQuery.and().with(longListSelection("parameters", "longListValues", asList(8L))); result = tx.doQuery(ballQuery); assertEquals(1, result.size()); ballQuery = ActivityQuery.query("Ball"); - ballQuery.and().with(longListSelection("parameters", "longListValues", Arrays.asList(10L, 9L, 8L))); + ballQuery.and().with(longListSelection("parameters", "longListValues", asList(10L, 9L, 8L))); result = tx.doQuery(ballQuery); assertEquals(1, result.size()); } @@ -225,7 +224,7 @@ public class InMemoryActivityQueryTest { @Test public void shouldQueryByNullParameter1() { - try (StrolchTransaction tx = openTx()) { + try (StrolchTransaction tx = openTx(true)) { ActivityQuery ballQuery = ActivityQuery.query("Ball"); ballQuery.and().with( // @@ -238,7 +237,7 @@ public class InMemoryActivityQueryTest { @Test public void shouldQueryByNullParameter2() { - try (StrolchTransaction tx = openTx()) { + try (StrolchTransaction tx = openTx(true)) { ActivityQuery ballQuery = ActivityQuery.query("Ball"); ballQuery.and().with( // @@ -251,7 +250,7 @@ public class InMemoryActivityQueryTest { @Test public void shouldQueryByNullParameter3() { - try (StrolchTransaction tx = openTx()) { + try (StrolchTransaction tx = openTx(true)) { ActivityQuery ballQuery = ActivityQuery.query("Ball"); ballQuery.and().with( // @@ -265,7 +264,7 @@ public class InMemoryActivityQueryTest { @Test public void shouldQueryByName() { - try (StrolchTransaction tx = openTx()) { + try (StrolchTransaction tx = openTx(true)) { ActivityQuery ballQuery = ActivityQuery.query("Ball"); ballQuery.with(new NameSelection("ball ", ci())); @@ -278,7 +277,7 @@ public class InMemoryActivityQueryTest { @Test public void shouldQueryByState() { - try (StrolchTransaction tx = openTx()) { + try (StrolchTransaction tx = openTx(true)) { ActivityQuery ballQuery = ActivityQuery.query("MyType1"); ballQuery.with(new ActivityStateSelection(State.STOPPED)); @@ -300,12 +299,10 @@ public class InMemoryActivityQueryTest { bag.addParameter(new StringParameter("color", "Color", "red")); bag.addParameter(new BooleanParameter("forChildren", "Color", true)); bag.addParameter(new FloatParameter("diameter", "Color", 22.0)); - bag.addParameter( - new StringListParameter("stringListValues", "List of String Values", Arrays.asList("a", "b", "c"))); - bag.addParameter(new IntegerListParameter("intListValues", "List of Integer Values", Arrays.asList(1, 2, 3))); - bag.addParameter( - new FloatListParameter("floatListValues", "List of Float Values", Arrays.asList(4.0, 5.1, 6.2))); - bag.addParameter(new LongListParameter("longListValues", "List of Long Values", Arrays.asList(8L, 9L, 10L))); + bag.addParameter(new StringListParameter("stringListValues", "List of String Values", asList("a", "b", "c"))); + bag.addParameter(new IntegerListParameter("intListValues", "List of Integer Values", asList(1, 2, 3))); + bag.addParameter(new FloatListParameter("floatListValues", "List of Float Values", asList(4.0, 5.1, 6.2))); + bag.addParameter(new LongListParameter("longListValues", "List of Long Values", asList(8L, 9L, 10L))); res1.addParameterBag(bag); return res1; } diff --git a/li.strolch.agent/src/test/java/li/strolch/runtime/query/inmemory/InMemoryOrderQueryTest.java b/li.strolch.agent/src/test/java/li/strolch/runtime/query/inmemory/InMemoryOrderQueryTest.java index fbb3b0615..ca2ab5fdd 100644 --- a/li.strolch.agent/src/test/java/li/strolch/runtime/query/inmemory/InMemoryOrderQueryTest.java +++ b/li.strolch.agent/src/test/java/li/strolch/runtime/query/inmemory/InMemoryOrderQueryTest.java @@ -15,6 +15,7 @@ */ package li.strolch.runtime.query.inmemory; +import static java.util.Arrays.asList; import static li.strolch.agent.ComponentContainerTest.PATH_EMPTY_CONTAINER; import static li.strolch.model.query.ParameterSelection.*; import static li.strolch.utils.StringMatchMode.ci; @@ -22,7 +23,6 @@ import static li.strolch.utils.StringMatchMode.es; import static org.junit.Assert.assertEquals; import java.util.ArrayList; -import java.util.Arrays; import java.util.Date; import java.util.List; @@ -62,16 +62,16 @@ public class InMemoryOrderQueryTest { certificate = login(runtimeMock.getAgent()); - try (StrolchTransaction tx = openTx()) { + try (StrolchTransaction tx = openTx(false)) { getOrders().forEach(tx::add); tx.add(getBallOrder()); tx.commitOnClose(); } } - private static StrolchTransaction openTx() { + private static StrolchTransaction openTx(boolean readOnly) { return runtimeMock.getAgent().getContainer().getRealm(StrolchConstants.DEFAULT_REALM) - .openTx(certificate, "test", true); + .openTx(certificate, "test", readOnly); } @AfterClass @@ -83,7 +83,7 @@ public class InMemoryOrderQueryTest { @Test public void shouldQueryById() { - try (StrolchTransaction tx = openTx()) { + try (StrolchTransaction tx = openTx(true)) { OrderQuery orderQuery = OrderQuery.query("MyType1"); orderQuery.with(new IdSelection("@1")); @@ -97,7 +97,7 @@ public class InMemoryOrderQueryTest { @Test public void shouldQueryByIdOr() { - try (StrolchTransaction tx = openTx()) { + try (StrolchTransaction tx = openTx(true)) { OrderQuery orderQuery = OrderQuery.query("MyType2"); orderQuery.or().with(new IdSelection("@3"), new IdSelection("@4")); @@ -112,7 +112,7 @@ public class InMemoryOrderQueryTest { @Test public void shouldQueryByIdAnd() { - try (StrolchTransaction tx = openTx()) { + try (StrolchTransaction tx = openTx(true)) { OrderQuery orderQuery = OrderQuery.query("MyType2"); orderQuery.and().with(new IdSelection("@3"), new NameSelection("Order 3", es())); @@ -126,7 +126,7 @@ public class InMemoryOrderQueryTest { @Test public void shouldNotQueryByIdAnd() { - try (StrolchTransaction tx = openTx()) { + try (StrolchTransaction tx = openTx(true)) { OrderQuery orderQuery = OrderQuery.query("MyType1"); orderQuery.and().with(new IdSelection("@3"), new NameSelection("@4", es())); @@ -139,7 +139,7 @@ public class InMemoryOrderQueryTest { @Test public void shouldQueryByParameter() { - try (StrolchTransaction tx = openTx()) { + try (StrolchTransaction tx = openTx(true)) { OrderQuery ballQuery = OrderQuery.query("Ball"); ballQuery.and().with( @@ -156,7 +156,7 @@ public class InMemoryOrderQueryTest { @Test public void shouldQueryByListParameter() { - try (StrolchTransaction tx = openTx()) { + try (StrolchTransaction tx = openTx(true)) { OrderQuery ballQuery; List result; @@ -164,18 +164,17 @@ public class InMemoryOrderQueryTest { // string list { ballQuery = OrderQuery.query("Ball"); - ballQuery.and().with(stringListSelection("parameters", "stringListValues", Arrays.asList("a", "z"))); + ballQuery.and().with(stringListSelection("parameters", "stringListValues", asList("a", "z"))); result = tx.doQuery(ballQuery); assertEquals(0, result.size()); ballQuery = OrderQuery.query("Ball"); - ballQuery.and().with(stringListSelection("parameters", "stringListValues", Arrays.asList("a"))); + ballQuery.and().with(stringListSelection("parameters", "stringListValues", asList("a"))); result = tx.doQuery(ballQuery); assertEquals(1, result.size()); ballQuery = OrderQuery.query("Ball"); - ballQuery.and() - .with(stringListSelection("parameters", "stringListValues", Arrays.asList("c", "b", "a"))); + ballQuery.and().with(stringListSelection("parameters", "stringListValues", asList("c", "b", "a"))); result = tx.doQuery(ballQuery); assertEquals(1, result.size()); } @@ -183,17 +182,17 @@ public class InMemoryOrderQueryTest { // integer list { ballQuery = OrderQuery.query("Ball"); - ballQuery.and().with(integerListSelection("parameters", "intListValues", Arrays.asList(1, 5))); + ballQuery.and().with(integerListSelection("parameters", "intListValues", asList(1, 5))); result = tx.doQuery(ballQuery); assertEquals(0, result.size()); ballQuery = OrderQuery.query("Ball"); - ballQuery.and().with(integerListSelection("parameters", "intListValues", Arrays.asList(1))); + ballQuery.and().with(integerListSelection("parameters", "intListValues", asList(1))); result = tx.doQuery(ballQuery); assertEquals(1, result.size()); ballQuery = OrderQuery.query("Ball"); - ballQuery.and().with(integerListSelection("parameters", "intListValues", Arrays.asList(3, 2, 1))); + ballQuery.and().with(integerListSelection("parameters", "intListValues", asList(3, 2, 1))); result = tx.doQuery(ballQuery); assertEquals(1, result.size()); } @@ -201,17 +200,17 @@ public class InMemoryOrderQueryTest { // float list { ballQuery = OrderQuery.query("Ball"); - ballQuery.and().with(floatListSelection("parameters", "floatListValues", Arrays.asList(4.0, 8.0))); + ballQuery.and().with(floatListSelection("parameters", "floatListValues", asList(4.0, 8.0))); result = tx.doQuery(ballQuery); assertEquals(0, result.size()); ballQuery = OrderQuery.query("Ball"); - ballQuery.and().with(floatListSelection("parameters", "floatListValues", Arrays.asList(4.0))); + ballQuery.and().with(floatListSelection("parameters", "floatListValues", asList(4.0))); result = tx.doQuery(ballQuery); assertEquals(1, result.size()); ballQuery = OrderQuery.query("Ball"); - ballQuery.and().with(floatListSelection("parameters", "floatListValues", Arrays.asList(6.2, 5.1, 4.0))); + ballQuery.and().with(floatListSelection("parameters", "floatListValues", asList(6.2, 5.1, 4.0))); result = tx.doQuery(ballQuery); assertEquals(1, result.size()); } @@ -219,17 +218,17 @@ public class InMemoryOrderQueryTest { // long list { ballQuery = OrderQuery.query("Ball"); - ballQuery.and().with(longListSelection("parameters", "longListValues", Arrays.asList(8L, 11L))); + ballQuery.and().with(longListSelection("parameters", "longListValues", asList(8L, 11L))); result = tx.doQuery(ballQuery); assertEquals(0, result.size()); ballQuery = OrderQuery.query("Ball"); - ballQuery.and().with(longListSelection("parameters", "longListValues", Arrays.asList(8L))); + ballQuery.and().with(longListSelection("parameters", "longListValues", asList(8L))); result = tx.doQuery(ballQuery); assertEquals(1, result.size()); ballQuery = OrderQuery.query("Ball"); - ballQuery.and().with(longListSelection("parameters", "longListValues", Arrays.asList(10L, 9L, 8L))); + ballQuery.and().with(longListSelection("parameters", "longListValues", asList(10L, 9L, 8L))); result = tx.doQuery(ballQuery); assertEquals(1, result.size()); } @@ -239,7 +238,7 @@ public class InMemoryOrderQueryTest { @Test public void shouldQueryByNullParameter1() { - try (StrolchTransaction tx = openTx()) { + try (StrolchTransaction tx = openTx(true)) { OrderQuery ballQuery = OrderQuery.query("Ball"); ballQuery.and().with( // @@ -252,7 +251,7 @@ public class InMemoryOrderQueryTest { @Test public void shouldQueryByNullParameter2() { - try (StrolchTransaction tx = openTx()) { + try (StrolchTransaction tx = openTx(true)) { OrderQuery ballQuery = OrderQuery.query("Ball"); ballQuery.and().with( // @@ -265,7 +264,7 @@ public class InMemoryOrderQueryTest { @Test public void shouldQueryByNullParameter3() { - try (StrolchTransaction tx = openTx()) { + try (StrolchTransaction tx = openTx(true)) { OrderQuery ballQuery = OrderQuery.query("Ball"); ballQuery.and().with( // @@ -279,7 +278,7 @@ public class InMemoryOrderQueryTest { @Test public void shouldQueryByName() { - try (StrolchTransaction tx = openTx()) { + try (StrolchTransaction tx = openTx(true)) { OrderQuery ballQuery = OrderQuery.query("Ball"); ballQuery.with(new NameSelection("ball ", ci())); @@ -292,7 +291,7 @@ public class InMemoryOrderQueryTest { @Test public void shouldQueryByState() { - try (StrolchTransaction tx = openTx()) { + try (StrolchTransaction tx = openTx(true)) { OrderQuery ballQuery = OrderQuery.query("MyType1"); ballQuery.with(new OrderStateSelection(State.STOPPED)); @@ -314,12 +313,10 @@ public class InMemoryOrderQueryTest { bag.addParameter(new StringParameter("color", "Color", "red")); bag.addParameter(new BooleanParameter("forChildren", "Color", true)); bag.addParameter(new FloatParameter("diameter", "Color", 22.0)); - bag.addParameter( - new StringListParameter("stringListValues", "List of String Values", Arrays.asList("a", "b", "c"))); - bag.addParameter(new IntegerListParameter("intListValues", "List of Integer Values", Arrays.asList(1, 2, 3))); - bag.addParameter( - new FloatListParameter("floatListValues", "List of Float Values", Arrays.asList(4.0, 5.1, 6.2))); - bag.addParameter(new LongListParameter("longListValues", "List of Long Values", Arrays.asList(8L, 9L, 10L))); + bag.addParameter(new StringListParameter("stringListValues", "List of String Values", asList("a", "b", "c"))); + bag.addParameter(new IntegerListParameter("intListValues", "List of Integer Values", asList(1, 2, 3))); + bag.addParameter(new FloatListParameter("floatListValues", "List of Float Values", asList(4.0, 5.1, 6.2))); + bag.addParameter(new LongListParameter("longListValues", "List of Long Values", asList(8L, 9L, 10L))); o1.addParameterBag(bag); return o1; } diff --git a/li.strolch.agent/src/test/java/li/strolch/runtime/query/inmemory/InMemoryResourceQueryTest.java b/li.strolch.agent/src/test/java/li/strolch/runtime/query/inmemory/InMemoryResourceQueryTest.java index b4a88a41b..1735e0b47 100644 --- a/li.strolch.agent/src/test/java/li/strolch/runtime/query/inmemory/InMemoryResourceQueryTest.java +++ b/li.strolch.agent/src/test/java/li/strolch/runtime/query/inmemory/InMemoryResourceQueryTest.java @@ -1,5 +1,6 @@ package li.strolch.runtime.query.inmemory; +import static java.util.Arrays.asList; import static li.strolch.agent.ComponentContainerTest.PATH_EMPTY_CONTAINER; import static li.strolch.model.query.ParameterSelection.*; import static li.strolch.utils.StringMatchMode.ci; @@ -7,7 +8,6 @@ import static li.strolch.utils.StringMatchMode.es; import static org.junit.Assert.assertEquals; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import li.strolch.RuntimeMock; @@ -48,16 +48,16 @@ public class InMemoryResourceQueryTest { certificate = login(runtimeMock.getAgent()); - try (StrolchTransaction tx = openTx()) { + try (StrolchTransaction tx = openTx(false)) { getResources().forEach(tx::add); tx.add(getBallResource()); tx.commitOnClose(); } } - private static StrolchTransaction openTx() { + private static StrolchTransaction openTx(boolean readOnly) { return runtimeMock.getAgent().getContainer().getRealm(StrolchConstants.DEFAULT_REALM) - .openTx(certificate, "test", true); + .openTx(certificate, "test", readOnly); } @AfterClass @@ -69,7 +69,7 @@ public class InMemoryResourceQueryTest { @Test public void shouldQueryById() { - try (StrolchTransaction tx = openTx()) { + try (StrolchTransaction tx = openTx(true)) { ResourceQuery resourceQuery = ResourceQuery.query("MyType1"); resourceQuery.with(new IdSelection("@1")); @@ -83,7 +83,7 @@ public class InMemoryResourceQueryTest { @Test public void shouldQueryByIdOr() { - try (StrolchTransaction tx = openTx()) { + try (StrolchTransaction tx = openTx(true)) { ResourceQuery resourceQuery = ResourceQuery.query("MyType2"); resourceQuery.or().with(new IdSelection("@3"), new IdSelection("@4")); @@ -98,7 +98,7 @@ public class InMemoryResourceQueryTest { @Test public void shouldQueryByIdAnd() { - try (StrolchTransaction tx = openTx()) { + try (StrolchTransaction tx = openTx(true)) { ResourceQuery resourceQuery = ResourceQuery.query("MyType2"); resourceQuery.and().with(new IdSelection("@3"), new NameSelection("Res 3", es())); @@ -112,7 +112,7 @@ public class InMemoryResourceQueryTest { @Test public void shouldNotQueryByIdAnd() { - try (StrolchTransaction tx = openTx()) { + try (StrolchTransaction tx = openTx(true)) { ResourceQuery resourceQuery = ResourceQuery.query("MyType1"); resourceQuery.and().with(new IdSelection("@3"), new NameSelection("@4", es())); @@ -125,7 +125,7 @@ public class InMemoryResourceQueryTest { @Test public void shouldQueryByParameter() { - try (StrolchTransaction tx = openTx()) { + try (StrolchTransaction tx = openTx(true)) { ResourceQuery ballQuery = ResourceQuery.query("Ball"); ballQuery.and().with( @@ -142,7 +142,7 @@ public class InMemoryResourceQueryTest { @Test public void shouldQueryByListParameter() { - try (StrolchTransaction tx = openTx()) { + try (StrolchTransaction tx = openTx(true)) { ResourceQuery ballQuery; List result; @@ -150,18 +150,17 @@ public class InMemoryResourceQueryTest { // string list { ballQuery = ResourceQuery.query("Ball"); - ballQuery.and().with(stringListSelection("parameters", "stringListValues", Arrays.asList("a", "z"))); + ballQuery.and().with(stringListSelection("parameters", "stringListValues", asList("a", "z"))); result = tx.doQuery(ballQuery); assertEquals(0, result.size()); ballQuery = ResourceQuery.query("Ball"); - ballQuery.and().with(stringListSelection("parameters", "stringListValues", Arrays.asList("a"))); + ballQuery.and().with(stringListSelection("parameters", "stringListValues", asList("a"))); result = tx.doQuery(ballQuery); assertEquals(1, result.size()); ballQuery = ResourceQuery.query("Ball"); - ballQuery.and() - .with(stringListSelection("parameters", "stringListValues", Arrays.asList("c", "b", "a"))); + ballQuery.and().with(stringListSelection("parameters", "stringListValues", asList("c", "b", "a"))); result = tx.doQuery(ballQuery); assertEquals(1, result.size()); } @@ -169,17 +168,17 @@ public class InMemoryResourceQueryTest { // integer list { ballQuery = ResourceQuery.query("Ball"); - ballQuery.and().with(integerListSelection("parameters", "intListValues", Arrays.asList(1, 5))); + ballQuery.and().with(integerListSelection("parameters", "intListValues", asList(1, 5))); result = tx.doQuery(ballQuery); assertEquals(0, result.size()); ballQuery = ResourceQuery.query("Ball"); - ballQuery.and().with(integerListSelection("parameters", "intListValues", Arrays.asList(1))); + ballQuery.and().with(integerListSelection("parameters", "intListValues", asList(1))); result = tx.doQuery(ballQuery); assertEquals(1, result.size()); ballQuery = ResourceQuery.query("Ball"); - ballQuery.and().with(integerListSelection("parameters", "intListValues", Arrays.asList(3, 2, 1))); + ballQuery.and().with(integerListSelection("parameters", "intListValues", asList(3, 2, 1))); result = tx.doQuery(ballQuery); assertEquals(1, result.size()); } @@ -187,17 +186,17 @@ public class InMemoryResourceQueryTest { // float list { ballQuery = ResourceQuery.query("Ball"); - ballQuery.and().with(floatListSelection("parameters", "floatListValues", Arrays.asList(4.0, 8.0))); + ballQuery.and().with(floatListSelection("parameters", "floatListValues", asList(4.0, 8.0))); result = tx.doQuery(ballQuery); assertEquals(0, result.size()); ballQuery = ResourceQuery.query("Ball"); - ballQuery.and().with(floatListSelection("parameters", "floatListValues", Arrays.asList(4.0))); + ballQuery.and().with(floatListSelection("parameters", "floatListValues", asList(4.0))); result = tx.doQuery(ballQuery); assertEquals(1, result.size()); ballQuery = ResourceQuery.query("Ball"); - ballQuery.and().with(floatListSelection("parameters", "floatListValues", Arrays.asList(6.2, 5.1, 4.0))); + ballQuery.and().with(floatListSelection("parameters", "floatListValues", asList(6.2, 5.1, 4.0))); result = tx.doQuery(ballQuery); assertEquals(1, result.size()); } @@ -205,17 +204,17 @@ public class InMemoryResourceQueryTest { // long list { ballQuery = ResourceQuery.query("Ball"); - ballQuery.and().with(longListSelection("parameters", "longListValues", Arrays.asList(8L, 11L))); + ballQuery.and().with(longListSelection("parameters", "longListValues", asList(8L, 11L))); result = tx.doQuery(ballQuery); assertEquals(0, result.size()); ballQuery = ResourceQuery.query("Ball"); - ballQuery.and().with(longListSelection("parameters", "longListValues", Arrays.asList(8L))); + ballQuery.and().with(longListSelection("parameters", "longListValues", asList(8L))); result = tx.doQuery(ballQuery); assertEquals(1, result.size()); ballQuery = ResourceQuery.query("Ball"); - ballQuery.and().with(longListSelection("parameters", "longListValues", Arrays.asList(10L, 9L, 8L))); + ballQuery.and().with(longListSelection("parameters", "longListValues", asList(10L, 9L, 8L))); result = tx.doQuery(ballQuery); assertEquals(1, result.size()); } @@ -225,7 +224,7 @@ public class InMemoryResourceQueryTest { @Test public void shouldQueryByNullParameter1() { - try (StrolchTransaction tx = openTx()) { + try (StrolchTransaction tx = openTx(true)) { ResourceQuery ballQuery = ResourceQuery.query("Ball"); ballQuery.and().with( // @@ -239,7 +238,7 @@ public class InMemoryResourceQueryTest { @Test public void shouldQueryByNullParameter2() { - try (StrolchTransaction tx = openTx()) { + try (StrolchTransaction tx = openTx(true)) { ResourceQuery ballQuery = ResourceQuery.query("Ball"); ballQuery.and().with( // @@ -253,7 +252,7 @@ public class InMemoryResourceQueryTest { @Test public void shouldQueryByNullParameter3() { - try (StrolchTransaction tx = openTx()) { + try (StrolchTransaction tx = openTx(true)) { ResourceQuery ballQuery = ResourceQuery.query("Ball"); ballQuery.and().with( // @@ -267,7 +266,7 @@ public class InMemoryResourceQueryTest { @Test public void shouldQueryByName() { - try (StrolchTransaction tx = openTx()) { + try (StrolchTransaction tx = openTx(true)) { ResourceQuery ballQuery = ResourceQuery.query("Ball"); ballQuery.with(new NameSelection("ball ", ci())); @@ -284,12 +283,10 @@ public class InMemoryResourceQueryTest { bag.addParameter(new StringParameter("color", "Color", "red")); bag.addParameter(new BooleanParameter("forChildren", "Color", true)); bag.addParameter(new FloatParameter("diameter", "Color", 22.0)); - bag.addParameter( - new StringListParameter("stringListValues", "List of String Values", Arrays.asList("a", "b", "c"))); - bag.addParameter(new IntegerListParameter("intListValues", "List of Integer Values", Arrays.asList(1, 2, 3))); - bag.addParameter( - new FloatListParameter("floatListValues", "List of Float Values", Arrays.asList(4.0, 5.1, 6.2))); - bag.addParameter(new LongListParameter("longListValues", "List of Long Values", Arrays.asList(8L, 9L, 10L))); + bag.addParameter(new StringListParameter("stringListValues", "List of String Values", asList("a", "b", "c"))); + bag.addParameter(new IntegerListParameter("intListValues", "List of Integer Values", asList(1, 2, 3))); + bag.addParameter(new FloatListParameter("floatListValues", "List of Float Values", asList(4.0, 5.1, 6.2))); + bag.addParameter(new LongListParameter("longListValues", "List of Long Values", asList(8L, 9L, 10L))); res1.addParameterBag(bag); return res1; }