@Test
public void testRecursivelyPerformOperation()
{
// Persist operation
NodeState state = new TransientState();
Node storeNode = StoreBuilder.buildStoreNode(pc, state, CascadeType.PERSIST);
state.recursivelyPerformOperation(storeNode, OPERATION.PERSIST);
Assert.assertEquals(TransientState.class, storeNode.getCurrentNodeState().getClass());
for (Node childNode : storeNode.getChildren().values())
{
Assert.assertEquals(BillingCounter.class, childNode.getDataClass());
// Assert.assertEquals(ManagedState.class, childNode.getCurrentNodeState().getClass());
}
// Merge operation
state = new DetachedState();
storeNode = StoreBuilder.buildStoreNode(pc, state, CascadeType.MERGE);
state.recursivelyPerformOperation(storeNode, OPERATION.MERGE);
Assert.assertEquals(DetachedState.class, storeNode.getCurrentNodeState().getClass());
for (Node childNode : storeNode.getChildren().values())
{
Assert.assertEquals(BillingCounter.class, childNode.getDataClass());
// Assert.assertEquals(ManagedState.class, childNode.getCurrentNodeState().getClass());
}
// Remove Operation
state = new ManagedState();
storeNode = StoreBuilder.buildStoreNode(pc, state, CascadeType.REMOVE);
state.recursivelyPerformOperation(storeNode, OPERATION.REMOVE);
Assert.assertEquals(ManagedState.class, storeNode.getCurrentNodeState().getClass());
for (Node childNode : storeNode.getChildren().values())
{
Assert.assertEquals(BillingCounter.class, childNode.getDataClass());
// Assert.assertEquals(RemovedState.class, childNode.getCurrentNodeState().getClass());
}
// Refresh Operation
state = new DetachedState();
storeNode = StoreBuilder.buildStoreNode(pc, state, CascadeType.REFRESH);
try
{
state.recursivelyPerformOperation(storeNode, OPERATION.REFRESH);
Assert.fail("Refresh operation in Detached state should have thrown an exception");
}
catch (Exception e)
{
Assert.assertEquals(IllegalArgumentException.class, e.getClass());
}
// Remove Operation
state = new ManagedState();
storeNode = StoreBuilder.buildStoreNode(pc, state, CascadeType.DETACH);
state.recursivelyPerformOperation(storeNode, OPERATION.DETACH);
Assert.assertEquals(ManagedState.class, storeNode.getCurrentNodeState().getClass());
for (Node childNode : storeNode.getChildren().values())
{
Assert.assertEquals(BillingCounter.class, childNode.getDataClass());
// Assert.assertEquals(DetachedState.class, childNode.getCurrentNodeState().getClass());
}