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