protected void checkAndFireEntryCriteria(List<String> satisfiedSentries) { if (isAvailable() || isNew()) { // do that only, when this child case execution // is available CmmnActivity activity = getActivity(); ensureNotNull( PvmException.class, "Case execution '" + getId() + "': has no current activity.", "activity", activity); List<CmmnSentryDeclaration> criteria = activity.getEntryCriteria(); for (CmmnSentryDeclaration sentryDeclaration : criteria) { if (sentryDeclaration != null && satisfiedSentries.contains(sentryDeclaration.getId())) { if (isAvailable()) { fireEntryCriteria(); } else { entryCriterionSatisfied = true; } break; } } } }
@Test public void testEntryCriteria() { // given // create sentry containing ifPart Sentry sentry = createElement(casePlanModel, "Sentry_1", Sentry.class); IfPart ifPart = createElement(sentry, "abc", IfPart.class); ConditionExpression conditionExpression = createElement(ifPart, "def", ConditionExpression.class); Body body = createElement(conditionExpression, null, Body.class); body.setTextContent("${test}"); // set exitCriteria planItem.getEntryCriterias().add(sentry); // transform casePlanModel as parent CmmnActivity parent = new CasePlanModelHandler().handleElement(casePlanModel, context); context.setParent(parent); // transform Sentry CmmnSentryDeclaration sentryDeclaration = new SentryHandler().handleElement(sentry, context); // when CmmnActivity newActivity = handler.handleElement(planItem, context); // then assertTrue(newActivity.getExitCriteria().isEmpty()); assertFalse(newActivity.getEntryCriteria().isEmpty()); assertEquals(1, newActivity.getEntryCriteria().size()); assertEquals(sentryDeclaration, newActivity.getEntryCriteria().get(0)); }
@Test public void testOutputSourceExpression() { // given: String source = "${a}"; ExtensionElements extensionElements = addExtensionElements(caseTask); CamundaOut sourceElement = createElement(extensionElements, null, CamundaOut.class); sourceElement.setCamundaSourceExpression(source); // when CmmnActivity activity = handler.handleElement(planItem, context); // then CaseTaskActivityBehavior behavior = (CaseTaskActivityBehavior) activity.getActivityBehavior(); CallableElement callableElement = behavior.getCallableElement(); CallableElementParameter parameter = callableElement.getOutputs().get(0); assertNotNull(parameter); assertFalse(parameter.isAllVariables()); ParameterValueProvider sourceExpressionValueProvider = parameter.getSourceValueProvider(); assertNotNull(sourceExpressionValueProvider); assertTrue(sourceExpressionValueProvider instanceof ElValueProvider); ElValueProvider valueProvider = (ElValueProvider) sourceExpressionValueProvider; assertEquals(source, valueProvider.getExpression().getExpressionText()); }
public void createSentryParts() { CmmnActivity activity = getActivity(); ensureNotNull("Case execution '" + id + "': has no current activity", "activity", activity); List<CmmnSentryDeclaration> sentries = activity.getSentries(); if (sentries != null && !sentries.isEmpty()) { for (CmmnSentryDeclaration sentryDeclaration : sentries) { CmmnIfPartDeclaration ifPartDeclaration = sentryDeclaration.getIfPart(); if (ifPartDeclaration != null) { CmmnSentryPart ifPart = createIfPart(sentryDeclaration, ifPartDeclaration); addSentryPart(ifPart); } List<CmmnOnPartDeclaration> onPartDeclarations = sentryDeclaration.getOnParts(); for (CmmnOnPartDeclaration onPartDeclaration : onPartDeclarations) { CmmnSentryPart onPart = createOnPart(sentryDeclaration, onPartDeclaration); addSentryPart(onPart); } List<CmmnVariableOnPartDeclaration> variableOnPartDeclarations = sentryDeclaration.getVariableOnParts(); for (CmmnVariableOnPartDeclaration variableOnPartDeclaration : variableOnPartDeclarations) { CmmnSentryPart variableOnPart = createVariableOnPart(sentryDeclaration, variableOnPartDeclaration); addSentryPart(variableOnPart); } } } }
public void initializeExitCriterias( CasePlanModel casePlanModel, CmmnActivity activity, CmmnHandlerContext context) { Collection<Sentry> exitCriterias = casePlanModel.getExitCriterias(); for (Sentry sentry : exitCriterias) { String sentryId = sentry.getId(); CmmnSentryDeclaration sentryDeclaration = activity.getSentry(sentryId); activity.addExitCriteria(sentryDeclaration); } }
@Test public void testWithoutParent() { // given: a casePlanModel // when CmmnActivity activity = handler.handleElement(casePlanModel, context); // then assertNull(activity.getParent()); }
@Test public void testWithoutParent() { // given: a planItem // when CmmnActivity activity = handler.handleElement(planItem, context); // then assertNull(activity.getParent()); }
@Test public void testIsBlockingEqualsTrueProperty() { // given: a caseTask with isBlocking = true (defaultValue) // when CmmnActivity activity = handler.handleElement(planItem, context); // then Boolean isBlocking = (Boolean) activity.getProperty(PROPERTY_IS_BLOCKING); assertTrue(isBlocking); }
@Test public void testActivityBehavior() { // given: a planItem // when CmmnActivity activity = handler.handleElement(planItem, context); // then CmmnActivityBehavior behavior = activity.getActivityBehavior(); assertTrue(behavior instanceof CaseTaskActivityBehavior); }
@Test public void testCaseTaskActivityType() { // given // when CmmnActivity activity = handler.handleElement(planItem, context); // then String activityType = (String) activity.getProperty(PROPERTY_ACTIVITY_TYPE); assertEquals("caseTask", activityType); }
@Test public void testActivityBehavior() { // given: a case plan model // when CmmnActivity activity = handler.handleElement(casePlanModel, context); // then CmmnActivityBehavior behavior = activity.getActivityBehavior(); assertTrue(behavior instanceof StageActivityBehavior); }
@Test public void testPlanItemDescription() { // given String description = "This is a planItem"; planItem.setDescription(description); // when CmmnActivity activity = handler.handleElement(planItem, context); // then assertEquals(description, (String) activity.getProperty(PROPERTY_ACTIVITY_DESCRIPTION)); }
@Test public void testIsBlockingEqualsFalseProperty() { // given: // a caseTask with isBlocking = false caseTask.setIsBlocking(false); // when CmmnActivity activity = handler.handleElement(planItem, context); // then Boolean isBlocking = (Boolean) activity.getProperty(PROPERTY_IS_BLOCKING); assertFalse(isBlocking); }
@Test public void testCallableElement() { // given: a plan item // when CmmnActivity activity = handler.handleElement(planItem, context); // then // there exists a callableElement CaseTaskActivityBehavior behavior = (CaseTaskActivityBehavior) activity.getActivityBehavior(); assertNotNull(behavior.getCallableElement()); }
@Test public void testCasePlanModelActivityName() { // given: // the case plan model has a name "A CasePlanModel" String name = "A CasePlanModel"; casePlanModel.setName(name); // when CmmnActivity activity = handler.handleElement(casePlanModel, context); // then assertEquals(name, activity.getName()); }
@Test public void testCaseTaskActivityName() { // given: // the caseTask has a name "A CaseTask" String name = "A CaseTask"; caseTask.setName(name); // when CmmnActivity activity = handler.handleElement(planItem, context); // then assertEquals(name, activity.getName()); }
@Test public void testWithParent() { // given: // a new activity as parent CmmnCaseDefinition parent = new CmmnCaseDefinition("aParentActivity"); context.setParent(parent); // when CmmnActivity activity = handler.handleElement(planItem, context); // then assertEquals(parent, activity.getParent()); assertTrue(parent.getActivities().contains(activity)); }
@Test public void testMultipleEntryCriteria() { // given // create first sentry containing ifPart Sentry sentry1 = createElement(casePlanModel, "Sentry_1", Sentry.class); IfPart ifPart1 = createElement(sentry1, "abc", IfPart.class); ConditionExpression conditionExpression1 = createElement(ifPart1, "def", ConditionExpression.class); Body body1 = createElement(conditionExpression1, null, Body.class); body1.setTextContent("${test}"); // set first entryCriteria planItem.getEntryCriterias().add(sentry1); // create first sentry containing ifPart Sentry sentry2 = createElement(casePlanModel, "Sentry_2", Sentry.class); IfPart ifPart2 = createElement(sentry2, "ghi", IfPart.class); ConditionExpression conditionExpression2 = createElement(ifPart2, "jkl", ConditionExpression.class); Body body2 = createElement(conditionExpression2, null, Body.class); body2.setTextContent("${test}"); // set second entryCriteria planItem.getEntryCriterias().add(sentry2); // transform casePlanModel as parent CmmnActivity parent = new CasePlanModelHandler().handleElement(casePlanModel, context); context.setParent(parent); // transform Sentry CmmnSentryDeclaration firstSentryDeclaration = new SentryHandler().handleElement(sentry1, context); CmmnSentryDeclaration secondSentryDeclaration = new SentryHandler().handleElement(sentry2, context); // when CmmnActivity newActivity = handler.handleElement(planItem, context); // then assertTrue(newActivity.getExitCriteria().isEmpty()); assertFalse(newActivity.getEntryCriteria().isEmpty()); assertEquals(2, newActivity.getEntryCriteria().size()); assertTrue(newActivity.getEntryCriteria().contains(firstSentryDeclaration)); assertTrue(newActivity.getEntryCriteria().contains(secondSentryDeclaration)); }
@Test public void testBinding() { // given: CallableElementBinding caseBinding = CallableElementBinding.LATEST; caseTask.setCamundaCaseBinding(caseBinding.getValue()); // when CmmnActivity activity = handler.handleElement(planItem, context); // then CaseTaskActivityBehavior behavior = (CaseTaskActivityBehavior) activity.getActivityBehavior(); CallableElement callableElement = behavior.getCallableElement(); CallableElementBinding binding = callableElement.getBinding(); assertNotNull(binding); assertEquals(caseBinding, binding); }
@Test public void testPlanItemActivityName() { // given: // the caseTask has a name "A CaseTask" String name = "A CaseTask"; caseTask.setName(name); // the planItem has an own name "My LocalName" String planItemName = "My LocalName"; planItem.setName(planItemName); // when CmmnActivity activity = handler.handleElement(planItem, context); // then assertNotEquals(name, activity.getName()); assertEquals(planItemName, activity.getName()); }
@Test public void testOutputVariables() { // given: ExtensionElements extensionElements = addExtensionElements(caseTask); CamundaOut variablesElement = createElement(extensionElements, null, CamundaOut.class); variablesElement.setCamundaVariables("all"); // when CmmnActivity activity = handler.handleElement(planItem, context); // then CaseTaskActivityBehavior behavior = (CaseTaskActivityBehavior) activity.getActivityBehavior(); CallableElement callableElement = behavior.getCallableElement(); CallableElementParameter parameter = callableElement.getOutputs().get(0); assertNotNull(parameter); assertTrue(parameter.isAllVariables()); }
@Test public void testVersionConstant() { // given: String caseVersion = "2"; caseTask.setCamundaCaseVersion(caseVersion); // when CmmnActivity activity = handler.handleElement(planItem, context); // then CaseTaskActivityBehavior behavior = (CaseTaskActivityBehavior) activity.getActivityBehavior(); CallableElement callableElement = behavior.getCallableElement(); ParameterValueProvider caseVersionValueProvider = callableElement.getVersionValueProvider(); assertNotNull(caseVersionValueProvider); assertTrue(caseVersionValueProvider instanceof ConstantValueProvider); assertEquals(caseVersion, caseVersionValueProvider.getValue(null)); }
@Test public void testRequiredRuleByDefaultPlanItemControl() { // given PlanItemControl defaultControl = createElement(caseTask, "ItemControl_1", DefaultControl.class); RequiredRule requiredRule = createElement(defaultControl, "RequiredRule_1", RequiredRule.class); ConditionExpression expression = createElement(requiredRule, "Expression_1", ConditionExpression.class); Body body = createElement(expression, Body.class); body.setTextContent("${true}"); Cmmn.validateModel(modelInstance); // when CmmnActivity newActivity = handler.handleElement(planItem, context); // then Object rule = newActivity.getProperty(PROPERTY_REQUIRED_RULE); assertNotNull(rule); assertTrue(rule instanceof CaseControlRule); }
protected CmmnSentryPart createOnPart( CmmnSentryDeclaration sentryDeclaration, CmmnOnPartDeclaration onPartDeclaration) { CmmnSentryPart sentryPart = createSentryPart(sentryDeclaration, PLAN_ITEM_ON_PART); // set the standard event String standardEvent = onPartDeclaration.getStandardEvent(); sentryPart.setStandardEvent(standardEvent); // set source case execution CmmnActivity source = onPartDeclaration.getSource(); ensureNotNull( "The source of sentry '" + sentryDeclaration.getId() + "' is null.", "source", source); String sourceActivityId = source.getId(); sentryPart.setSource(sourceActivityId); // TODO: handle also sentryRef!!! (currently not implemented on purpose) return sentryPart; }
protected void checkAndFireExitCriteria(List<String> satisfiedSentries) { if (isActive()) { CmmnActivity activity = getActivity(); ensureNotNull( PvmException.class, "Case execution '" + getId() + "': has no current activity.", "activity", activity); // trigger first exitCriteria List<CmmnSentryDeclaration> exitCriteria = activity.getExitCriteria(); for (CmmnSentryDeclaration sentryDeclaration : exitCriteria) { if (sentryDeclaration != null && satisfiedSentries.contains(sentryDeclaration.getId())) { fireExitCriteria(); break; } } } }
@Test public void testCaseRefExpression() { // given: String caseRef = "${aCaseToCall}"; caseTask.setCase(caseRef); // when CmmnActivity activity = handler.handleElement(planItem, context); // then CaseTaskActivityBehavior behavior = (CaseTaskActivityBehavior) activity.getActivityBehavior(); CallableElement callableElement = behavior.getCallableElement(); ParameterValueProvider caseRefValueProvider = callableElement.getDefinitionKeyValueProvider(); assertNotNull(caseRefValueProvider); assertTrue(caseRefValueProvider instanceof ElValueProvider); ElValueProvider valueProvider = (ElValueProvider) caseRefValueProvider; assertEquals(caseRef, valueProvider.getExpression().getExpressionText()); }
@Test public void testManualActivationRule() { // given ItemControl itemControl = createElement(planItem, "ItemControl_1", ItemControl.class); ManualActivationRule manualActivationRule = createElement(itemControl, "ManualActivationRule_1", ManualActivationRule.class); ConditionExpression expression = createElement(manualActivationRule, "Expression_1", ConditionExpression.class); Body body = createElement(expression, Body.class); body.setTextContent("${true}"); Cmmn.validateModel(modelInstance); // when CmmnActivity newActivity = handler.handleElement(planItem, context); // then Object rule = newActivity.getProperty(PROPERTY_MANUAL_ACTIVATION_RULE); assertNotNull(rule); assertTrue(rule instanceof CaseControlRule); }
@Test public void testOutputTarget() { // given: String target = "b"; ExtensionElements extensionElements = addExtensionElements(caseTask); CamundaOut sourceElement = createElement(extensionElements, null, CamundaOut.class); sourceElement.setCamundaTarget(target); // when CmmnActivity activity = handler.handleElement(planItem, context); // then CaseTaskActivityBehavior behavior = (CaseTaskActivityBehavior) activity.getActivityBehavior(); CallableElement callableElement = behavior.getCallableElement(); CallableElementParameter parameter = callableElement.getOutputs().get(0); assertNotNull(parameter); assertFalse(parameter.isAllVariables()); assertEquals(target, parameter.getTarget()); }
@Test public void testBusinessKeyConstant() { // given: String businessKey = "myBusinessKey"; ExtensionElements extensionElements = addExtensionElements(caseTask); CamundaIn businessKeyElement = createElement(extensionElements, null, CamundaIn.class); businessKeyElement.setCamundaBusinessKey(businessKey); // when CmmnActivity activity = handler.handleElement(planItem, context); // then CaseTaskActivityBehavior behavior = (CaseTaskActivityBehavior) activity.getActivityBehavior(); CallableElement callableElement = behavior.getCallableElement(); ParameterValueProvider businessKeyValueProvider = callableElement.getBusinessKeyValueProvider(); assertNotNull(businessKeyValueProvider); assertTrue(businessKeyValueProvider instanceof ConstantValueProvider); assertEquals(businessKey, businessKeyValueProvider.getValue(null)); }
@Test public void testOutputs() { // given: ExtensionElements extensionElements = addExtensionElements(caseTask); CamundaOut variablesElement = createElement(extensionElements, null, CamundaOut.class); variablesElement.setCamundaVariables("all"); CamundaOut sourceElement = createElement(extensionElements, null, CamundaOut.class); sourceElement.setCamundaSource("a"); CamundaOut sourceExpressionElement = createElement(extensionElements, null, CamundaOut.class); sourceExpressionElement.setCamundaSourceExpression("${b}"); // when CmmnActivity activity = handler.handleElement(planItem, context); // then CaseTaskActivityBehavior behavior = (CaseTaskActivityBehavior) activity.getActivityBehavior(); CallableElement callableElement = behavior.getCallableElement(); List<CallableElementParameter> outputs = callableElement.getOutputs(); assertNotNull(outputs); assertFalse(outputs.isEmpty()); assertEquals(3, outputs.size()); }