[New] added tests for ElementMap.removeAll()
This commit is contained in:
parent
88e3c6961e
commit
c16685dfc6
|
@ -130,11 +130,13 @@ public class OrderModelTestRunner {
|
||||||
|
|
||||||
public void runBulkOperationTests() {
|
public void runBulkOperationTests() {
|
||||||
|
|
||||||
|
// create 15 orders
|
||||||
List<Order> orders = new ArrayList<>();
|
List<Order> orders = new ArrayList<>();
|
||||||
orders.addAll(createOrders(orders.size(), 5, "@", "My Order ", "MyType1"));
|
orders.addAll(createOrders(orders.size(), 5, "@", "My Order ", "MyType1"));
|
||||||
orders.addAll(createOrders(orders.size(), 5, "@", "Other Order ", "MyType2"));
|
orders.addAll(createOrders(orders.size(), 5, "@", "Other Order ", "MyType2"));
|
||||||
orders.addAll(createOrders(orders.size(), 5, "@", "Further Order ", "MyType3"));
|
orders.addAll(createOrders(orders.size(), 5, "@", "Further Order ", "MyType3"));
|
||||||
|
|
||||||
|
// sort them so we know which order our objects are
|
||||||
Comparator<Order> comparator = new Comparator<Order>() {
|
Comparator<Order> comparator = new Comparator<Order>() {
|
||||||
@Override
|
@Override
|
||||||
public int compare(Order o1, Order o2) {
|
public int compare(Order o1, Order o2) {
|
||||||
|
@ -143,11 +145,57 @@ public class OrderModelTestRunner {
|
||||||
};
|
};
|
||||||
Collections.sort(orders, comparator);
|
Collections.sort(orders, comparator);
|
||||||
|
|
||||||
|
// first clear the map, so that we have a clean state
|
||||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) {
|
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) {
|
||||||
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
|
||||||
|
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) {
|
||||||
|
OrderMap orderMap = tx.getOrderMap();
|
||||||
|
assertEquals(0, orderMap.querySize(tx));
|
||||||
|
}
|
||||||
|
|
||||||
|
// now add some orders
|
||||||
|
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) {
|
||||||
|
tx.getOrderMap().addAll(tx, orders);
|
||||||
|
}
|
||||||
|
|
||||||
|
// make sure we have our expected size
|
||||||
|
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) {
|
||||||
|
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()) {
|
||||||
|
tx.getOrderMap().removeAllBy(tx, "MyType3");
|
||||||
|
}
|
||||||
|
|
||||||
|
// again make sure we have our expected size
|
||||||
|
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) {
|
||||||
|
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()) {
|
||||||
|
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()) {
|
||||||
|
OrderMap orderMap = tx.getOrderMap();
|
||||||
|
assertEquals(0, orderMap.querySize(tx));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// now add all again
|
||||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) {
|
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) {
|
||||||
tx.getOrderMap().addAll(tx, orders);
|
tx.getOrderMap().addAll(tx, orders);
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,11 +130,13 @@ public class ResourceModelTestRunner {
|
||||||
|
|
||||||
public void runBulkOperationTests() {
|
public void runBulkOperationTests() {
|
||||||
|
|
||||||
|
// create 15 resources
|
||||||
List<Resource> resources = new ArrayList<>();
|
List<Resource> resources = new ArrayList<>();
|
||||||
resources.addAll(createResources(resources.size(), 5, "@", "My Resource ", "MyType1"));
|
resources.addAll(createResources(resources.size(), 5, "@", "My Resource ", "MyType1"));
|
||||||
resources.addAll(createResources(resources.size(), 5, "@", "Other Resource ", "MyType2"));
|
resources.addAll(createResources(resources.size(), 5, "@", "Other Resource ", "MyType2"));
|
||||||
resources.addAll(createResources(resources.size(), 5, "@", "Further Resource ", "MyType3"));
|
resources.addAll(createResources(resources.size(), 5, "@", "Further Resource ", "MyType3"));
|
||||||
|
|
||||||
|
// sort them so we know which order our objects are
|
||||||
Comparator<Resource> comparator = new Comparator<Resource>() {
|
Comparator<Resource> comparator = new Comparator<Resource>() {
|
||||||
@Override
|
@Override
|
||||||
public int compare(Resource o1, Resource o2) {
|
public int compare(Resource o1, Resource o2) {
|
||||||
|
@ -143,11 +145,57 @@ public class ResourceModelTestRunner {
|
||||||
};
|
};
|
||||||
Collections.sort(resources, comparator);
|
Collections.sort(resources, comparator);
|
||||||
|
|
||||||
|
// first clear the map, so that we have a clean state
|
||||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) {
|
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) {
|
||||||
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
|
||||||
|
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) {
|
||||||
|
ResourceMap resourceMap = tx.getResourceMap();
|
||||||
|
assertEquals(0, resourceMap.querySize(tx));
|
||||||
|
}
|
||||||
|
|
||||||
|
// now add some resources
|
||||||
|
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) {
|
||||||
|
tx.getResourceMap().addAll(tx, resources);
|
||||||
|
}
|
||||||
|
|
||||||
|
// make sure we have our expected size
|
||||||
|
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) {
|
||||||
|
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()) {
|
||||||
|
tx.getResourceMap().removeAllBy(tx, "MyType3");
|
||||||
|
}
|
||||||
|
|
||||||
|
// again make sure we have our expected size
|
||||||
|
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) {
|
||||||
|
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()) {
|
||||||
|
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()) {
|
||||||
|
ResourceMap resourceMap = tx.getResourceMap();
|
||||||
|
assertEquals(0, resourceMap.querySize(tx));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// now add all again
|
||||||
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) {
|
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) {
|
||||||
tx.getResourceMap().addAll(tx, resources);
|
tx.getResourceMap().addAll(tx, resources);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue