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