[Minor] there is no getDefaultRealm() method anymore

This commit is contained in:
Robert von Burg 2014-02-13 22:22:11 +01:00
parent 5ce91bfe4b
commit bb3f3e7854
4 changed files with 34 additions and 45 deletions

View File

@ -1,6 +1,7 @@
package li.strolch.testbase.runtime;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.runtime.StrolchConstants;
import org.junit.Test;
@ -10,7 +11,7 @@ public abstract class AbstractModelTest {
@Test
public void shouldStartContainer() {
try (StrolchTransaction tx = getRuntimeMock().getDefaultRealm().openTx()) {
try (StrolchTransaction tx = getRuntimeMock().getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
tx.getOrderMap().getAllKeys(tx);
}
}

View File

@ -21,6 +21,7 @@ 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 {
@ -39,7 +40,7 @@ public class OrderModelTestRunner {
// create
Order newOrder = createOrder("MyTestOrder", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
tx.getOrderMap().add(tx, newOrder);
}
}
@ -47,7 +48,7 @@ public class OrderModelTestRunner {
public void runQuerySizeTest() {
// remove all
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
tx.getOrderMap().removeAll(tx, tx.getOrderMap().getAllElements(tx));
}
@ -55,14 +56,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.getDefaultRealm().openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
tx.getOrderMap().add(tx, order1);
tx.getOrderMap().add(tx, order2);
tx.getOrderMap().add(tx, order3);
}
// query size
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
long size = tx.getOrderMap().querySize(tx);
assertEquals("Should have three objects", 3, size);
@ -84,13 +85,13 @@ public class OrderModelTestRunner {
// create
Order newOrder = createOrder(ID, NAME, TYPE);
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
tx.getOrderMap().add(tx, newOrder);
}
// read
Order readOrder = null;
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
readOrder = tx.getOrderMap().getBy(tx, TYPE, ID);
}
assertNotNull("Should read Order with id " + ID, readOrder);
@ -99,13 +100,13 @@ public class OrderModelTestRunner {
Parameter<String> sParam = readOrder.getParameter(BAG_ID, PARAM_STRING_ID);
String newStringValue = "Giddiya!";
sParam.setValue(newStringValue);
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
tx.getOrderMap().update(tx, readOrder);
}
// read updated
Order updatedOrder = null;
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
updatedOrder = tx.getOrderMap().getBy(tx, TYPE, ID);
}
assertNotNull("Should read Order with id " + ID, updatedOrder);
@ -115,12 +116,12 @@ public class OrderModelTestRunner {
assertEquals(newStringValue, updatedParam.getValue());
// delete
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
tx.getOrderMap().remove(tx, readOrder);
}
// fail to re-read
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
Order order = tx.getOrderMap().getBy(tx, TYPE, ID);
assertNull("Should no read Order with id " + ID, order);
}
@ -141,12 +142,12 @@ public class OrderModelTestRunner {
};
Collections.sort(orders, comparator);
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
OrderMap orderMap = tx.getOrderMap();
orderMap.removeAll(tx, orderMap.getAllElements(tx));
}
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
tx.getOrderMap().addAll(tx, orders);
}
@ -155,13 +156,13 @@ public class OrderModelTestRunner {
expectedTypes.add("MyType2");
expectedTypes.add("MyType3");
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
List<Order> allOrders = tx.getOrderMap().getAllElements(tx);
Collections.sort(allOrders, comparator);
assertEquals(orders, allOrders);
}
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
OrderMap orderMap = tx.getOrderMap();
Set<String> types = orderMap.getTypes(tx);
@ -179,7 +180,7 @@ public class OrderModelTestRunner {
}
}
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
Order order = tx.getOrderMap().getBy(tx, "MyType1", "@_00000001");
assertNotNull(order);
order = tx.getOrderMap().getBy(tx, "MyType2", "@_00000006");

View File

@ -21,6 +21,7 @@ import li.strolch.agent.impl.DataStoreMode;
import li.strolch.model.Resource;
import li.strolch.model.parameter.Parameter;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.runtime.StrolchConstants;
@SuppressWarnings("nls")
public class ResourceModelTestRunner {
@ -39,7 +40,7 @@ public class ResourceModelTestRunner {
// create
Resource newResource = createResource("MyTestResource", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
tx.getResourceMap().add(tx, newResource);
}
}
@ -47,7 +48,7 @@ public class ResourceModelTestRunner {
public void runQuerySizeTest() {
// remove all
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
tx.getResourceMap().removeAll(tx, tx.getResourceMap().getAllElements(tx));
}
@ -55,14 +56,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.getDefaultRealm().openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
tx.getResourceMap().add(tx, resource1);
tx.getResourceMap().add(tx, resource2);
tx.getResourceMap().add(tx, resource3);
}
// query size
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
long size = tx.getResourceMap().querySize(tx);
assertEquals("Should have three objects", 3, size);
@ -84,13 +85,13 @@ public class ResourceModelTestRunner {
// create
Resource newResource = createResource(ID, NAME, TYPE);
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
tx.getResourceMap().add(tx, newResource);
}
// read
Resource readResource = null;
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
readResource = tx.getResourceMap().getBy(tx, TYPE, ID);
}
assertNotNull("Should read Resource with id " + ID, readResource); //$NON-NLS-1$
@ -99,13 +100,13 @@ 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.getDefaultRealm().openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
tx.getResourceMap().update(tx, readResource);
}
// read updated
Resource updatedResource = null;
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
updatedResource = tx.getResourceMap().getBy(tx, TYPE, ID);
}
assertNotNull("Should read Resource with id " + ID, updatedResource); //$NON-NLS-1$
@ -115,12 +116,12 @@ public class ResourceModelTestRunner {
assertEquals(newStringValue, updatedParam.getValue());
// delete
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
tx.getResourceMap().remove(tx, readResource);
}
// fail to re-read
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) {
Resource resource = tx.getResourceMap().getBy(tx, TYPE, ID);
assertNull("Should no read Resource with id " + ID, resource); //$NON-NLS-1$
}
@ -141,12 +142,12 @@ public class ResourceModelTestRunner {
};
Collections.sort(resources, comparator);
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
ResourceMap resourceMap = tx.getResourceMap();
resourceMap.removeAll(tx, resourceMap.getAllElements(tx));
}
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
tx.getResourceMap().addAll(tx, resources);
}
@ -155,13 +156,13 @@ public class ResourceModelTestRunner {
expectedTypes.add("MyType2");
expectedTypes.add("MyType3");
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
List<Resource> allResources = tx.getResourceMap().getAllElements(tx);
Collections.sort(allResources, comparator);
assertEquals(resources, allResources);
}
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
ResourceMap resourceMap = tx.getResourceMap();
Set<String> types = resourceMap.getTypes(tx);
@ -179,7 +180,7 @@ public class ResourceModelTestRunner {
}
}
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) {
try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
Resource resource = tx.getResourceMap().getBy(tx, "MyType1", "@_00000001");
assertNotNull(resource);
resource = tx.getResourceMap().getBy(tx, "MyType2", "@_00000006");

View File

@ -28,7 +28,6 @@ import li.strolch.service.api.ServiceHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ch.eitchnet.utils.dbc.DBC;
import ch.eitchnet.utils.helper.FileHelper;
public final class RuntimeMock {
@ -57,10 +56,6 @@ public final class RuntimeMock {
return this.container.getComponent(ServiceHandler.class);
}
public StrolchRealm getDefaultRealm() {
return this.container.getDefaultRealm();
}
public StrolchRealm getRealm(String realm) {
return this.container.getRealm(realm);
}
@ -109,15 +104,6 @@ public final class RuntimeMock {
}
}
/**
* @deprecated use parameterless {@link #startContainer()}
*/
@Deprecated
public void startContainer(File rootPathF) {
DBC.PRE.assertEquals("Starting a different runtime than was mocked!", this.rootPath, rootPathF); //$NON-NLS-1$
startContainer();
}
public void startContainer() {
try {