[Minor] allow for overriding the realm in which the tests run

This commit is contained in:
Robert von Burg 2014-02-19 00:11:46 +01:00
parent 0189eab99a
commit 9d72df10b1
3 changed files with 50 additions and 45 deletions

View File

@ -9,9 +9,11 @@ public abstract class AbstractModelTest {
protected abstract RuntimeMock getRuntimeMock();
protected String realmName = StrolchConstants.DEFAULT_REALM;
@Test
public void shouldStartContainer() {
try (StrolchTransaction tx = getRuntimeMock().getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
try (StrolchTransaction tx = getRuntimeMock().getRealm(this.realmName).openTx()) {
tx.getOrderMap().getAllKeys(tx);
}
}
@ -19,56 +21,56 @@ public abstract class AbstractModelTest {
@Test
public void shouldCreateOrders() {
OrderModelTestRunner testRunner = new OrderModelTestRunner(getRuntimeMock());
OrderModelTestRunner testRunner = new OrderModelTestRunner(getRuntimeMock(), this.realmName);
testRunner.runCreateOrderTest();
}
@Test
public void shouldQueryOrderSizes() {
OrderModelTestRunner testRunner = new OrderModelTestRunner(getRuntimeMock());
OrderModelTestRunner testRunner = new OrderModelTestRunner(getRuntimeMock(), this.realmName);
testRunner.runQuerySizeTest();
}
@Test
public void shouldOrderCrud() {
OrderModelTestRunner testRunner = new OrderModelTestRunner(getRuntimeMock());
OrderModelTestRunner testRunner = new OrderModelTestRunner(getRuntimeMock(), this.realmName);
testRunner.runCrudTests();
}
@Test
public void shouldOrderPerformBulkOperations() {
OrderModelTestRunner testRunner = new OrderModelTestRunner(getRuntimeMock());
OrderModelTestRunner testRunner = new OrderModelTestRunner(getRuntimeMock(), this.realmName);
testRunner.runBulkOperationTests();
}
@Test
public void shouldCreateResources() {
ResourceModelTestRunner testRunner = new ResourceModelTestRunner(getRuntimeMock());
ResourceModelTestRunner testRunner = new ResourceModelTestRunner(getRuntimeMock(), this.realmName);
testRunner.runCreateResourceTest();
}
@Test
public void shouldQueryResourceSizes() {
ResourceModelTestRunner testRunner = new ResourceModelTestRunner(getRuntimeMock());
ResourceModelTestRunner testRunner = new ResourceModelTestRunner(getRuntimeMock(), this.realmName);
testRunner.runQuerySizeTest();
}
@Test
public void shouldResourceCrud() {
ResourceModelTestRunner testRunner = new ResourceModelTestRunner(getRuntimeMock());
ResourceModelTestRunner testRunner = new ResourceModelTestRunner(getRuntimeMock(), this.realmName);
testRunner.runCrudTests();
}
@Test
public void shouldResourcePerformBulkOperations() {
ResourceModelTestRunner testRunner = new ResourceModelTestRunner(getRuntimeMock());
ResourceModelTestRunner testRunner = new ResourceModelTestRunner(getRuntimeMock(), this.realmName);
testRunner.runBulkOperationTests();
}
}

View File

@ -21,7 +21,6 @@ import li.strolch.agent.impl.DataStoreMode;
import li.strolch.model.Order;
import li.strolch.model.parameter.Parameter;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.runtime.StrolchConstants;
@SuppressWarnings("nls")
public class OrderModelTestRunner {
@ -31,24 +30,26 @@ public class OrderModelTestRunner {
private static final String TYPE = "ToStock";
private RuntimeMock runtimeMock;
private String realmName;
public OrderModelTestRunner(RuntimeMock runtimeMock) {
public OrderModelTestRunner(RuntimeMock runtimeMock, String realmName) {
this.runtimeMock = runtimeMock;
this.realmName = realmName;
}
public void runCreateOrderTest() {
// create
Order newOrder = createOrder("MyTestOrder", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) {
tx.getOrderMap().add(tx, newOrder);
}
}
public void runQuerySizeTest() {
// remove all
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) {
tx.getOrderMap().removeAll(tx, tx.getOrderMap().getAllElements(tx));
}
@ -56,14 +57,14 @@ public class OrderModelTestRunner {
Order order1 = createOrder("myTestOrder1", "Test Name", "QTestType1"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
Order order2 = createOrder("myTestOrder2", "Test Name", "QTestType2"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
Order order3 = createOrder("myTestOrder3", "Test Name", "QTestType3"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) {
tx.getOrderMap().add(tx, order1);
tx.getOrderMap().add(tx, order2);
tx.getOrderMap().add(tx, order3);
}
// query size
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) {
long size = tx.getOrderMap().querySize(tx);
assertEquals("Should have three objects", 3, size);
@ -85,13 +86,13 @@ public class OrderModelTestRunner {
// create
Order newOrder = createOrder(ID, NAME, TYPE);
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) {
tx.getOrderMap().add(tx, newOrder);
}
// read
Order readOrder = null;
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) {
readOrder = tx.getOrderMap().getBy(tx, TYPE, ID);
}
assertNotNull("Should read Order with id " + ID, readOrder);
@ -100,28 +101,28 @@ public class OrderModelTestRunner {
Parameter<String> sParam = readOrder.getParameter(BAG_ID, PARAM_STRING_ID);
String newStringValue = "Giddiya!";
sParam.setValue(newStringValue);
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) {
tx.getOrderMap().update(tx, readOrder);
}
// read updated
Order updatedOrder = null;
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) {
updatedOrder = tx.getOrderMap().getBy(tx, TYPE, ID);
}
assertNotNull("Should read Order with id " + ID, updatedOrder);
if (this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).getMode() != DataStoreMode.CACHED)
if (this.runtimeMock.getRealm(this.realmName).getMode() != DataStoreMode.CACHED)
assertFalse("Objects can't be the same reference after re-reading!", readOrder == updatedOrder);
Parameter<String> updatedParam = readOrder.getParameter(BAG_ID, PARAM_STRING_ID);
assertEquals(newStringValue, updatedParam.getValue());
// delete
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) {
tx.getOrderMap().remove(tx, readOrder);
}
// fail to re-read
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) {
Order order = tx.getOrderMap().getBy(tx, TYPE, ID);
assertNull("Should no read Order with id " + ID, order);
}
@ -142,12 +143,12 @@ public class OrderModelTestRunner {
};
Collections.sort(orders, comparator);
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) {
OrderMap orderMap = tx.getOrderMap();
orderMap.removeAll(tx, orderMap.getAllElements(tx));
}
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) {
tx.getOrderMap().addAll(tx, orders);
}
@ -156,13 +157,13 @@ public class OrderModelTestRunner {
expectedTypes.add("MyType2");
expectedTypes.add("MyType3");
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) {
List<Order> allOrders = tx.getOrderMap().getAllElements(tx);
Collections.sort(allOrders, comparator);
assertEquals(orders, allOrders);
}
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) {
OrderMap orderMap = tx.getOrderMap();
Set<String> types = orderMap.getTypes(tx);
@ -180,7 +181,7 @@ public class OrderModelTestRunner {
}
}
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) {
Order order = tx.getOrderMap().getBy(tx, "MyType1", "@_00000001");
assertNotNull(order);
order = tx.getOrderMap().getBy(tx, "MyType2", "@_00000006");

View File

@ -31,16 +31,18 @@ public class ResourceModelTestRunner {
private static final String TYPE = "Box"; //$NON-NLS-1$
private RuntimeMock runtimeMock;
private String realmName;
public ResourceModelTestRunner(RuntimeMock runtimeMock) {
public ResourceModelTestRunner(RuntimeMock runtimeMock, String realmName) {
this.runtimeMock = runtimeMock;
this.realmName = realmName;
}
public void runCreateResourceTest() {
// create
Resource newResource = createResource("MyTestResource", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) {
tx.getResourceMap().add(tx, newResource);
}
}
@ -48,7 +50,7 @@ public class ResourceModelTestRunner {
public void runQuerySizeTest() {
// remove all
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) {
tx.getResourceMap().removeAll(tx, tx.getResourceMap().getAllElements(tx));
}
@ -56,14 +58,14 @@ public class ResourceModelTestRunner {
Resource resource1 = createResource("myTestResource1", "Test Name", "QTestType1"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
Resource resource2 = createResource("myTestResource2", "Test Name", "QTestType2"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
Resource resource3 = createResource("myTestResource3", "Test Name", "QTestType3"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) {
tx.getResourceMap().add(tx, resource1);
tx.getResourceMap().add(tx, resource2);
tx.getResourceMap().add(tx, resource3);
}
// query size
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) {
long size = tx.getResourceMap().querySize(tx);
assertEquals("Should have three objects", 3, size);
@ -85,13 +87,13 @@ public class ResourceModelTestRunner {
// create
Resource newResource = createResource(ID, NAME, TYPE);
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) {
tx.getResourceMap().add(tx, newResource);
}
// read
Resource readResource = null;
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) {
readResource = tx.getResourceMap().getBy(tx, TYPE, ID);
}
assertNotNull("Should read Resource with id " + ID, readResource); //$NON-NLS-1$
@ -100,28 +102,28 @@ public class ResourceModelTestRunner {
Parameter<String> sParam = readResource.getParameter(BAG_ID, PARAM_STRING_ID);
String newStringValue = "Giddiya!"; //$NON-NLS-1$
sParam.setValue(newStringValue);
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) {
tx.getResourceMap().update(tx, readResource);
}
// read updated
Resource updatedResource = null;
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) {
updatedResource = tx.getResourceMap().getBy(tx, TYPE, ID);
}
assertNotNull("Should read Resource with id " + ID, updatedResource); //$NON-NLS-1$
if (this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).getMode() != DataStoreMode.CACHED)
if (this.runtimeMock.getRealm(this.realmName).getMode() != DataStoreMode.CACHED)
assertFalse("Objects can't be the same reference after re-reading!", readResource == updatedResource); //$NON-NLS-1$
Parameter<String> updatedParam = readResource.getParameter(BAG_ID, PARAM_STRING_ID);
assertEquals(newStringValue, updatedParam.getValue());
// delete
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) {
tx.getResourceMap().remove(tx, readResource);
}
// fail to re-read
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) {
Resource resource = tx.getResourceMap().getBy(tx, TYPE, ID);
assertNull("Should no read Resource with id " + ID, resource); //$NON-NLS-1$
}
@ -142,12 +144,12 @@ public class ResourceModelTestRunner {
};
Collections.sort(resources, comparator);
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) {
ResourceMap resourceMap = tx.getResourceMap();
resourceMap.removeAll(tx, resourceMap.getAllElements(tx));
}
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) {
tx.getResourceMap().addAll(tx, resources);
}
@ -156,13 +158,13 @@ public class ResourceModelTestRunner {
expectedTypes.add("MyType2");
expectedTypes.add("MyType3");
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) {
List<Resource> allResources = tx.getResourceMap().getAllElements(tx);
Collections.sort(allResources, comparator);
assertEquals(resources, allResources);
}
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) {
ResourceMap resourceMap = tx.getResourceMap();
Set<String> types = resourceMap.getTypes(tx);
@ -180,7 +182,7 @@ public class ResourceModelTestRunner {
}
}
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) {
Resource resource = tx.getResourceMap().getBy(tx, "MyType1", "@_00000001");
assertNotNull(resource);
resource = tx.getResourceMap().getBy(tx, "MyType2", "@_00000006");