null
if the test succeeded, else an error message for use in JUnit report.
- */
- String executeTest();
- }
-
- /** ===================================================================================
- * Test failure behaviour
- */
-
- /**
- * Test sync failure behaviour
- */
- @Test
- public void testSyncFailureBehaviour()
- {
- // Create an action that is going to fail
- Action action = createFailingMoveAction(true);
-
- try
- {
- this.actionService.executeAction(action, this.nodeRef);
-
- // Fail if we get there since the exception should have been raised
- fail("An exception should have been raised.");
- }
- catch (RuntimeException exception)
- {
- // Good! The exception was raised correctly
- }
-
- // Test what happens when a element of a composite action fails (should raise and bubble up to parent bahviour)
- // Create the composite action
- Action action1 = this.actionService.createAction(AddFeaturesActionExecuter.NAME);
- action1.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_LOCKABLE);
- Action action2 = this.actionService.createAction(AddFeaturesActionExecuter.NAME);
- action2.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, QName.createQName("{test}badDogAspect"));
- CompositeAction compAction = this.actionService.createCompositeAction();
- compAction.setTitle("title");
- compAction.setDescription("description");
- compAction.addAction(action1);
- compAction.addAction(action2);
-
- try
- {
- // Execute the composite action
- this.actionService.executeAction(compAction, this.nodeRef);
-
- fail("An exception should have been raised here !!");
- }
- catch (RuntimeException runtimeException)
- {
- // Good! The exception was raised
- }
- }
-
- /**
- * Test the compensating action
- */
- @Test
- public void testCompensatingAction()
- {
- // Create actions that are going to fail
- final Action fatalAction = createFailingMoveAction(true);
- final Action nonfatalAction = createFailingMoveAction(false);
- fatalAction.setTitle("fatal title");
- nonfatalAction.setTitle("non-fatal title");
-
- // Create the compensating actions
- Action compensatingAction = actionService.createAction(AddFeaturesActionExecuter.NAME);
- compensatingAction.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_CLASSIFIABLE);
- compensatingAction.setTitle("title");
- fatalAction.setCompensatingAction(compensatingAction);
-
- Action compensatingAction2 = actionService.createAction(AddFeaturesActionExecuter.NAME);
- compensatingAction2.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_TEMPORARY);
- compensatingAction2.setTitle("title");
- nonfatalAction.setCompensatingAction(compensatingAction2);
-
-
- // Set the actions to execute asynchronously
- fatalAction.setExecuteAsynchronously(true);
- nonfatalAction.setExecuteAsynchronously(true);
-
- this.actionService.executeAction(fatalAction, this.nodeRef);
- this.actionService.executeAction(nonfatalAction, this.nodeRef);
-
- TestTransaction.flagForCommit();
- TestTransaction.end();
-
- postAsyncActionTest(
- this.transactionService,
- 1000,
- 10,
- new AsyncTest()
- {
- public String executeTest()
- {
- boolean fatalCompensatingActionRun = ActionServiceImplTest.this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_CLASSIFIABLE);
-
- boolean nonFatalCompensatingActionRun = ActionServiceImplTest.this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_TEMPORARY);
-
- StringBuilder result = new StringBuilder();
- if (!fatalCompensatingActionRun)
- {
- result.append("Expected aspect Classifiable.");
- }
- if (nonFatalCompensatingActionRun)
- {
- result.append(" Did not expect aspect Temporary");
- }
-
- return ( !fatalCompensatingActionRun || nonFatalCompensatingActionRun ? result.toString() : null);
- };
- });
-
- // Modify the compensating action so that it will also fail
- compensatingAction.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, QName.createQName("{test}badAspect"));
-
- this.transactionService.getRetryingTransactionHelper().doInTransaction(
- new RetryingTransactionCallback