[Minor] code cleanup
This commit is contained in:
parent
a8d25c2dd1
commit
a703361db0
|
@ -55,12 +55,12 @@ public class AuditModelTestRunner {
|
|||
this.realmName = realmName;
|
||||
|
||||
PrivilegeHandler privilegeHandler = runtimeMock.getContainer().getPrivilegeHandler();
|
||||
certificate = privilegeHandler.authenticate("test", "test".getBytes());
|
||||
this.certificate = privilegeHandler.authenticate("test", "test".getBytes());
|
||||
}
|
||||
|
||||
public void runTestForAudits() {
|
||||
|
||||
StrolchRealm realm = runtimeMock.getRealm(realmName);
|
||||
StrolchRealm realm = this.runtimeMock.getRealm(this.realmName);
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
|
||||
|
@ -89,12 +89,12 @@ public class AuditModelTestRunner {
|
|||
audit.setDate(current);
|
||||
|
||||
// add
|
||||
try (StrolchTransaction tx = realm.openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
|
||||
AuditTrail auditTrail = tx.getAuditTrail();
|
||||
auditTrail.add(tx, audit);
|
||||
}
|
||||
|
||||
try (StrolchTransaction tx = realm.openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
|
||||
AuditTrail auditTrail = tx.getAuditTrail();
|
||||
Set<String> types = auditTrail.getTypes(tx);
|
||||
assertEquals(1, types.size());
|
||||
|
@ -102,7 +102,7 @@ public class AuditModelTestRunner {
|
|||
}
|
||||
|
||||
// has
|
||||
try (StrolchTransaction tx = realm.openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
|
||||
AuditTrail auditTrail = tx.getAuditTrail();
|
||||
assertTrue(auditTrail.hasAudit(tx, audit.getElementType(), audit.getId()));
|
||||
|
||||
|
@ -115,28 +115,28 @@ public class AuditModelTestRunner {
|
|||
}
|
||||
|
||||
// remove
|
||||
try (StrolchTransaction tx = realm.openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
|
||||
AuditTrail auditTrail = tx.getAuditTrail();
|
||||
auditTrail.remove(tx, audit);
|
||||
}
|
||||
try (StrolchTransaction tx = realm.openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
|
||||
AuditTrail auditTrail = tx.getAuditTrail();
|
||||
Audit dbAudit = auditTrail.getBy(tx, audit.getElementType(), audit.getId());
|
||||
assertNull(dbAudit);
|
||||
}
|
||||
|
||||
// update
|
||||
try (StrolchTransaction tx = realm.openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
|
||||
AuditTrail auditTrail = tx.getAuditTrail();
|
||||
auditTrail.add(tx, audit);
|
||||
}
|
||||
try (StrolchTransaction tx = realm.openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
|
||||
AuditTrail auditTrail = tx.getAuditTrail();
|
||||
Audit dbAudit = auditTrail.getBy(tx, audit.getElementType(), audit.getId());
|
||||
dbAudit.setAction("Foo");
|
||||
auditTrail.update(tx, dbAudit);
|
||||
}
|
||||
try (StrolchTransaction tx = realm.openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
|
||||
AuditTrail auditTrail = tx.getAuditTrail();
|
||||
Audit dbAudit = auditTrail.getBy(tx, audit.getElementType(), audit.getId());
|
||||
assertEquals("Foo", dbAudit.getAction());
|
||||
|
@ -149,7 +149,7 @@ public class AuditModelTestRunner {
|
|||
audit.setDate(current);
|
||||
|
||||
// querySize
|
||||
try (StrolchTransaction tx = realm.openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
|
||||
AuditTrail auditTrail = tx.getAuditTrail();
|
||||
assertEquals(1, auditTrail.querySize(tx, audit.getElementType(), equalsRange));
|
||||
assertEquals(1, auditTrail.querySize(tx, audit.getElementType(), containsRange));
|
||||
|
@ -169,12 +169,12 @@ public class AuditModelTestRunner {
|
|||
}
|
||||
Collections.sort(audits, new AuditByIdComparator());
|
||||
|
||||
try (StrolchTransaction tx = realm.openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
|
||||
AuditTrail auditTrail = tx.getAuditTrail();
|
||||
auditTrail.addAll(tx, audits);
|
||||
}
|
||||
|
||||
try (StrolchTransaction tx = realm.openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
|
||||
AuditTrail auditTrail = tx.getAuditTrail();
|
||||
assertEquals(100, auditTrail.querySize(tx, "FooBar", containsRange));
|
||||
|
||||
|
@ -188,13 +188,13 @@ public class AuditModelTestRunner {
|
|||
assertEquals(0, allElements.size());
|
||||
}
|
||||
|
||||
try (StrolchTransaction tx = realm.openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
|
||||
AuditTrail auditTrail = tx.getAuditTrail();
|
||||
auditTrail.removeAll(tx, audits);
|
||||
assertEquals(0, auditTrail.querySize(tx, "FooBar", containsRange));
|
||||
}
|
||||
|
||||
try (StrolchTransaction tx = realm.openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
|
||||
AuditTrail auditTrail = tx.getAuditTrail();
|
||||
assertEquals(0, auditTrail.querySize(tx, "FooBar", containsRange));
|
||||
}
|
||||
|
@ -212,12 +212,12 @@ public class AuditModelTestRunner {
|
|||
}
|
||||
Collections.sort(audits, new AuditByIdComparator());
|
||||
|
||||
try (StrolchTransaction tx = realm.openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
|
||||
AuditTrail auditTrail = tx.getAuditTrail();
|
||||
auditTrail.addAll(tx, audits);
|
||||
}
|
||||
|
||||
try (StrolchTransaction tx = realm.openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
|
||||
AuditTrail auditTrail = tx.getAuditTrail();
|
||||
List<Audit> allElements = auditTrail.getAllElements(tx, "Bar", containsRange);
|
||||
Collections.sort(allElements, new AuditByIdComparator());
|
||||
|
@ -234,7 +234,7 @@ public class AuditModelTestRunner {
|
|||
auditTrail.updateAll(tx, allElements);
|
||||
}
|
||||
|
||||
try (StrolchTransaction tx = realm.openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
|
||||
AuditTrail auditTrail = tx.getAuditTrail();
|
||||
List<Audit> allElements = auditTrail.getAllElements(tx, "Bar", containsRange);
|
||||
for (Audit dbAudit : allElements) {
|
||||
|
@ -268,12 +268,12 @@ public class AuditModelTestRunner {
|
|||
audits.add(randomAudit);
|
||||
}
|
||||
|
||||
try (StrolchTransaction tx = realm.openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
|
||||
AuditTrail auditTrail = tx.getAuditTrail();
|
||||
auditTrail.addAll(tx, audits);
|
||||
}
|
||||
|
||||
try (StrolchTransaction tx = realm.openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
|
||||
AuditTrail auditTrail = tx.getAuditTrail();
|
||||
assertEquals(15, auditTrail.querySize(tx, containsRange));
|
||||
assertEquals(5, auditTrail.querySize(tx, "BarBarBar", containsRange));
|
||||
|
@ -281,7 +281,7 @@ public class AuditModelTestRunner {
|
|||
assertEquals(5, auditTrail.querySize(tx, "BarFooBar", containsRange));
|
||||
}
|
||||
|
||||
try (StrolchTransaction tx = realm.openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
|
||||
AuditTrail auditTrail = tx.getAuditTrail();
|
||||
assertEquals(5, auditTrail.removeAll(tx, "BarBarBar", containsRange));
|
||||
assertEquals(10, auditTrail.querySize(tx, containsRange));
|
||||
|
@ -299,7 +299,7 @@ public class AuditModelTestRunner {
|
|||
|
||||
DateRange dateRange = new DateRange().from(new Date(0), true).to(new Date((long) Math.pow(2, 50)), true);
|
||||
|
||||
try (StrolchTransaction tx = realm.openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
|
||||
AuditTrail auditTrail = tx.getAuditTrail();
|
||||
Set<String> types = auditTrail.getTypes(tx);
|
||||
for (String type : types) {
|
||||
|
|
|
@ -40,14 +40,14 @@ public class OrderModelTestRunner {
|
|||
this.realmName = realmName;
|
||||
|
||||
PrivilegeHandler privilegeHandler = runtimeMock.getContainer().getPrivilegeHandler();
|
||||
certificate = privilegeHandler.authenticate("test", "test".getBytes());
|
||||
this.certificate = privilegeHandler.authenticate("test", "test".getBytes());
|
||||
}
|
||||
|
||||
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(this.realmName).openTx(certificate, "test");) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
|
||||
tx.getOrderMap().add(tx, newOrder);
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ public class OrderModelTestRunner {
|
|||
public void runQuerySizeTest() {
|
||||
|
||||
// remove all
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
|
||||
tx.getOrderMap().removeAll(tx, tx.getOrderMap().getAllElements(tx));
|
||||
}
|
||||
|
||||
|
@ -63,14 +63,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(this.realmName).openTx(certificate, "test");) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
|
||||
tx.getOrderMap().add(tx, order1);
|
||||
tx.getOrderMap().add(tx, order2);
|
||||
tx.getOrderMap().add(tx, order3);
|
||||
}
|
||||
|
||||
// query size
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
|
||||
long size = tx.getOrderMap().querySize(tx);
|
||||
assertEquals("Should have three objects", 3, size);
|
||||
|
||||
|
@ -92,13 +92,13 @@ public class OrderModelTestRunner {
|
|||
|
||||
// create
|
||||
Order newOrder = createOrder(ID, NAME, TYPE);
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
|
||||
tx.getOrderMap().add(tx, newOrder);
|
||||
}
|
||||
|
||||
// read
|
||||
Order readOrder = null;
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
|
||||
readOrder = tx.getOrderMap().getBy(tx, TYPE, ID);
|
||||
}
|
||||
assertNotNull("Should read Order with id " + ID, readOrder);
|
||||
|
@ -107,13 +107,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.getRealm(this.realmName).openTx(certificate, "test");) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
|
||||
tx.getOrderMap().update(tx, readOrder);
|
||||
}
|
||||
|
||||
// read updated
|
||||
Order updatedOrder = null;
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
|
||||
updatedOrder = tx.getOrderMap().getBy(tx, TYPE, ID);
|
||||
}
|
||||
assertNotNull("Should read Order with id " + ID, updatedOrder);
|
||||
|
@ -123,12 +123,12 @@ public class OrderModelTestRunner {
|
|||
assertEquals(newStringValue, updatedParam.getValue());
|
||||
|
||||
// delete
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
|
||||
tx.getOrderMap().remove(tx, readOrder);
|
||||
}
|
||||
|
||||
// fail to re-read
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
|
||||
Order order = tx.getOrderMap().getBy(tx, TYPE, ID);
|
||||
assertNull("Should no read Order with id " + ID, order);
|
||||
}
|
||||
|
@ -152,57 +152,57 @@ public class OrderModelTestRunner {
|
|||
Collections.sort(orders, comparator);
|
||||
|
||||
// first clear the map, so that we have a clean state
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
|
||||
OrderMap orderMap = tx.getOrderMap();
|
||||
orderMap.removeAll(tx, orderMap.getAllElements(tx));
|
||||
}
|
||||
|
||||
{
|
||||
// make sure it is empty
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
|
||||
OrderMap orderMap = tx.getOrderMap();
|
||||
assertEquals(0, orderMap.querySize(tx));
|
||||
}
|
||||
|
||||
// now add some orders
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
|
||||
tx.getOrderMap().addAll(tx, orders);
|
||||
}
|
||||
|
||||
// make sure we have our expected size
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
|
||||
OrderMap orderMap = tx.getOrderMap();
|
||||
assertEquals(orders.size(), orderMap.querySize(tx));
|
||||
assertEquals(5, orderMap.querySize(tx, "MyType3"));
|
||||
}
|
||||
|
||||
// now use the remove all by type
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
|
||||
tx.getOrderMap().removeAllBy(tx, "MyType3");
|
||||
}
|
||||
|
||||
// again make sure we have our expected size
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
|
||||
OrderMap orderMap = tx.getOrderMap();
|
||||
assertEquals(orders.size() - 5, orderMap.querySize(tx));
|
||||
assertEquals(0, orderMap.querySize(tx, "MyType3"));
|
||||
}
|
||||
|
||||
// now use the remove all
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
|
||||
long removed = tx.getOrderMap().removeAll(tx);
|
||||
assertEquals(orders.size() - 5, removed);
|
||||
}
|
||||
|
||||
// again make sure we have our expected size
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
|
||||
OrderMap orderMap = tx.getOrderMap();
|
||||
assertEquals(0, orderMap.querySize(tx));
|
||||
}
|
||||
}
|
||||
|
||||
// now add all again
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
|
||||
tx.getOrderMap().addAll(tx, orders);
|
||||
}
|
||||
|
||||
|
@ -211,13 +211,13 @@ public class OrderModelTestRunner {
|
|||
expectedTypes.add("MyType2");
|
||||
expectedTypes.add("MyType3");
|
||||
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
|
||||
List<Order> allOrders = tx.getOrderMap().getAllElements(tx);
|
||||
Collections.sort(allOrders, comparator);
|
||||
assertEquals(orders, allOrders);
|
||||
}
|
||||
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
|
||||
OrderMap orderMap = tx.getOrderMap();
|
||||
|
||||
Set<String> types = orderMap.getTypes(tx);
|
||||
|
@ -235,7 +235,7 @@ public class OrderModelTestRunner {
|
|||
}
|
||||
}
|
||||
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
|
||||
Order order = tx.getOrderMap().getBy(tx, "MyType1", "@00000001");
|
||||
assertNotNull(order);
|
||||
order = tx.getOrderMap().getBy(tx, "MyType2", "@00000006");
|
||||
|
|
|
@ -40,14 +40,14 @@ public class ResourceModelTestRunner {
|
|||
this.realmName = realmName;
|
||||
|
||||
PrivilegeHandler privilegeHandler = runtimeMock.getContainer().getPrivilegeHandler();
|
||||
certificate = privilegeHandler.authenticate("test", "test".getBytes());
|
||||
this.certificate = privilegeHandler.authenticate("test", "test".getBytes());
|
||||
}
|
||||
|
||||
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(this.realmName).openTx(certificate, "test");) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
|
||||
tx.getResourceMap().add(tx, newResource);
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ public class ResourceModelTestRunner {
|
|||
public void runQuerySizeTest() {
|
||||
|
||||
// remove all
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
|
||||
tx.getResourceMap().removeAll(tx, tx.getResourceMap().getAllElements(tx));
|
||||
}
|
||||
|
||||
|
@ -63,14 +63,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(this.realmName).openTx(certificate, "test");) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
|
||||
tx.getResourceMap().add(tx, resource1);
|
||||
tx.getResourceMap().add(tx, resource2);
|
||||
tx.getResourceMap().add(tx, resource3);
|
||||
}
|
||||
|
||||
// query size
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
|
||||
long size = tx.getResourceMap().querySize(tx);
|
||||
assertEquals("Should have three objects", 3, size);
|
||||
|
||||
|
@ -92,13 +92,13 @@ public class ResourceModelTestRunner {
|
|||
|
||||
// create
|
||||
Resource newResource = createResource(ID, NAME, TYPE);
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
|
||||
tx.getResourceMap().add(tx, newResource);
|
||||
}
|
||||
|
||||
// read
|
||||
Resource readResource = null;
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
|
||||
readResource = tx.getResourceMap().getBy(tx, TYPE, ID);
|
||||
}
|
||||
assertNotNull("Should read Resource with id " + ID, readResource); //$NON-NLS-1$
|
||||
|
@ -107,13 +107,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.getRealm(this.realmName).openTx(certificate, "test");) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
|
||||
tx.getResourceMap().update(tx, readResource);
|
||||
}
|
||||
|
||||
// read updated
|
||||
Resource updatedResource = null;
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
|
||||
updatedResource = tx.getResourceMap().getBy(tx, TYPE, ID);
|
||||
}
|
||||
assertNotNull("Should read Resource with id " + ID, updatedResource); //$NON-NLS-1$
|
||||
|
@ -123,12 +123,12 @@ public class ResourceModelTestRunner {
|
|||
assertEquals(newStringValue, updatedParam.getValue());
|
||||
|
||||
// delete
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
|
||||
tx.getResourceMap().remove(tx, readResource);
|
||||
}
|
||||
|
||||
// fail to re-read
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
|
||||
Resource resource = tx.getResourceMap().getBy(tx, TYPE, ID);
|
||||
assertNull("Should no read Resource with id " + ID, resource); //$NON-NLS-1$
|
||||
}
|
||||
|
@ -152,57 +152,57 @@ public class ResourceModelTestRunner {
|
|||
Collections.sort(resources, comparator);
|
||||
|
||||
// first clear the map, so that we have a clean state
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
|
||||
ResourceMap resourceMap = tx.getResourceMap();
|
||||
resourceMap.removeAll(tx, resourceMap.getAllElements(tx));
|
||||
}
|
||||
|
||||
{
|
||||
// make sure it is empty
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
|
||||
ResourceMap resourceMap = tx.getResourceMap();
|
||||
assertEquals(0, resourceMap.querySize(tx));
|
||||
}
|
||||
|
||||
// now add some resources
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
|
||||
tx.getResourceMap().addAll(tx, resources);
|
||||
}
|
||||
|
||||
// make sure we have our expected size
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
|
||||
ResourceMap resourceMap = tx.getResourceMap();
|
||||
assertEquals(resources.size(), resourceMap.querySize(tx));
|
||||
assertEquals(5, resourceMap.querySize(tx, "MyType3"));
|
||||
}
|
||||
|
||||
// now use the remove all by type
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
|
||||
tx.getResourceMap().removeAllBy(tx, "MyType3");
|
||||
}
|
||||
|
||||
// again make sure we have our expected size
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
|
||||
ResourceMap resourceMap = tx.getResourceMap();
|
||||
assertEquals(resources.size() - 5, resourceMap.querySize(tx));
|
||||
assertEquals(0, resourceMap.querySize(tx, "MyType3"));
|
||||
}
|
||||
|
||||
// now use the remove all
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
|
||||
long removed = tx.getResourceMap().removeAll(tx);
|
||||
assertEquals(resources.size() - 5, removed);
|
||||
}
|
||||
|
||||
// again make sure we have our expected size
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
|
||||
ResourceMap resourceMap = tx.getResourceMap();
|
||||
assertEquals(0, resourceMap.querySize(tx));
|
||||
}
|
||||
}
|
||||
|
||||
// now add all again
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
|
||||
tx.getResourceMap().addAll(tx, resources);
|
||||
}
|
||||
|
||||
|
@ -211,13 +211,13 @@ public class ResourceModelTestRunner {
|
|||
expectedTypes.add("MyType2");
|
||||
expectedTypes.add("MyType3");
|
||||
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
|
||||
List<Resource> allResources = tx.getResourceMap().getAllElements(tx);
|
||||
Collections.sort(allResources, comparator);
|
||||
assertEquals(resources, allResources);
|
||||
}
|
||||
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
|
||||
ResourceMap resourceMap = tx.getResourceMap();
|
||||
|
||||
Set<String> types = resourceMap.getTypes(tx);
|
||||
|
@ -235,7 +235,7 @@ public class ResourceModelTestRunner {
|
|||
}
|
||||
}
|
||||
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
|
||||
Resource resource = tx.getResourceMap().getBy(tx, "MyType1", "@00000001");
|
||||
assertNotNull(resource);
|
||||
resource = tx.getResourceMap().getBy(tx, "MyType2", "@00000006");
|
||||
|
|
Loading…
Reference in New Issue