Ejemplo n.º 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testSentryWithIfPart()
        public virtual void testSentryWithIfPart()
        {
            // given
            IfPart ifPart = createElement(sentry, "abc", typeof(IfPart));
            ConditionExpression conditionExpression = createElement(ifPart, "def", typeof(ConditionExpression));
            Body   body       = createElement(conditionExpression, null, typeof(Body));
            string expression = "${test}";

            body.TextContent = expression;

            // when
            CmmnSentryDeclaration sentryDeclaration = sentryHandler.handleElement(sentry, context);

            // then
            assertNotNull(sentryDeclaration);

            CmmnIfPartDeclaration ifPartDeclaration = sentryDeclaration.IfPart;

            assertNotNull(ifPartDeclaration);

            Expression condition = ifPartDeclaration.Condition;

            assertNotNull(condition);
            assertEquals(expression, condition.ExpressionText);

            assertTrue(sentryDeclaration.OnParts.Count == 0);
        }
 public CriteriaBuilder SetIfPart(string condition)
 {
     _ifPart = new IfPart
     {
         Condition = condition
     };
     return(this);
 }
Ejemplo n.º 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testSentryWithOnPartReferencesSentry()
        public virtual void testSentryWithOnPartReferencesSentry()
        {
            // given
            Sentry exitSentry = createElement(casePlanModel, "anotherSentry", typeof(Sentry));
            IfPart ifPart     = createElement(exitSentry, "IfPart_1", typeof(IfPart));
            ConditionExpression conditionExpression = createElement(ifPart, "con_1", typeof(ConditionExpression));
            Body body = createElement(conditionExpression, null, typeof(Body));

            body.TextContent = "${test}";

            onPart.Sentry = exitSentry;

            CmmnActivity casePlanModelActivity = (new CasePlanModelHandler()).handleElement(casePlanModel, context);

            context.Parent = casePlanModelActivity;

            CmmnSentryDeclaration sentryDeclaration     = sentryHandler.handleElement(sentry, context);
            CmmnSentryDeclaration exitSentryDeclaration = sentryHandler.handleElement(exitSentry, context);
            CmmnActivity          source = taskItemHandler.handleElement(planItem, context);

            // when
            sentryHandler.initializeOnParts(sentry, context);

            // then
            assertNotNull(sentryDeclaration);

            IList <CmmnOnPartDeclaration> onParts = sentryDeclaration.OnParts;

            assertNotNull(onParts);
            assertFalse(onParts.Count == 0);
            assertEquals(1, onParts.Count);

            IList <CmmnOnPartDeclaration> onPartsAssociatedWithSource = sentryDeclaration.getOnParts(source.Id);

            assertNotNull(onPartsAssociatedWithSource);
            assertFalse(onPartsAssociatedWithSource.Count == 0);
            assertEquals(1, onParts.Count);

            CmmnOnPartDeclaration onPartDeclaration = onPartsAssociatedWithSource[0];

            assertNotNull(onPartDeclaration);
            // source
            assertEquals(source, onPartDeclaration.Source);
            assertEquals(onPart.Source.Id, onPartDeclaration.Source.Id);
            // standardEvent
            assertEquals(onPart.StandardEvent.name(), onPartDeclaration.StandardEvent);
            // sentry
            assertNotNull(onPartDeclaration.Sentry);
            assertEquals(exitSentryDeclaration, onPartDeclaration.Sentry);

            assertNull(sentryDeclaration.IfPart);
        }
Ejemplo n.º 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testMultipleEntryCriteria()
        public virtual void testMultipleEntryCriteria()
        {
            // given

            // create first sentry containing ifPart
            Sentry sentry1 = createElement(casePlanModel, "Sentry_1", typeof(Sentry));
            IfPart ifPart1 = createElement(sentry1, "abc", typeof(IfPart));
            ConditionExpression conditionExpression1 = createElement(ifPart1, "def", typeof(ConditionExpression));
            Body body1 = createElement(conditionExpression1, null, typeof(Body));

            body1.TextContent = "${test}";

            // set first entryCriteria
            EntryCriterion criterion1 = createElement(planItem, typeof(EntryCriterion));

            criterion1.Sentry = sentry1;

            // create first sentry containing ifPart
            Sentry sentry2 = createElement(casePlanModel, "Sentry_2", typeof(Sentry));
            IfPart ifPart2 = createElement(sentry2, "ghi", typeof(IfPart));
            ConditionExpression conditionExpression2 = createElement(ifPart2, "jkl", typeof(ConditionExpression));
            Body body2 = createElement(conditionExpression2, null, typeof(Body));

            body2.TextContent = "${test}";

            // set second entryCriteria
            EntryCriterion criterion2 = createElement(planItem, typeof(EntryCriterion));

            criterion2.Sentry = sentry2;

            // transform casePlanModel as parent
            CmmnActivity parent = (new CasePlanModelHandler()).handleElement(casePlanModel, context);

            context.Parent = 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.ExitCriteria.Count == 0);

            assertFalse(newActivity.EntryCriteria.Count == 0);
            assertEquals(2, newActivity.EntryCriteria.Count);

            assertTrue(newActivity.EntryCriteria.Contains(firstSentryDeclaration));
            assertTrue(newActivity.EntryCriteria.Contains(secondSentryDeclaration));
        }
Ejemplo n.º 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testEntryCriteriaAndExitCriteria()
        public virtual void testEntryCriteriaAndExitCriteria()
        {
            // given

            // create sentry containing ifPart
            Sentry sentry = createElement(casePlanModel, "Sentry_1", typeof(Sentry));
            IfPart ifPart = createElement(sentry, "abc", typeof(IfPart));
            ConditionExpression conditionExpression = createElement(ifPart, "def", typeof(ConditionExpression));
            Body body = createElement(conditionExpression, null, typeof(Body));

            body.TextContent = "${test}";

            // set entry-/exitCriteria
            EntryCriterion criterion1 = createElement(planItem, typeof(EntryCriterion));

            criterion1.Sentry = sentry;
            ExitCriterion criterion2 = createElement(planItem, typeof(ExitCriterion));

            criterion2.Sentry = sentry;

            // transform casePlanModel as parent
            CmmnActivity parent = (new CasePlanModelHandler()).handleElement(casePlanModel, context);

            context.Parent = parent;

            // transform Sentry
            CmmnSentryDeclaration sentryDeclaration = (new SentryHandler()).handleElement(sentry, context);

            // when
            CmmnActivity newActivity = handler.handleElement(planItem, context);

            // then
            assertFalse(newActivity.ExitCriteria.Count == 0);
            assertEquals(1, newActivity.ExitCriteria.Count);
            assertEquals(sentryDeclaration, newActivity.ExitCriteria[0]);

            assertFalse(newActivity.EntryCriteria.Count == 0);
            assertEquals(1, newActivity.EntryCriteria.Count);
            assertEquals(sentryDeclaration, newActivity.EntryCriteria[0]);
        }
Ejemplo n.º 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testSentryWithIfPartWithMultipleCondition()
        public virtual void testSentryWithIfPartWithMultipleCondition()
        {
            // given
            IfPart ifPart = createElement(sentry, "abc", typeof(IfPart));

            ConditionExpression firstConditionExpression = createElement(ifPart, "con_1", typeof(ConditionExpression));
            Body   firstBody       = createElement(firstConditionExpression, null, typeof(Body));
            string firstExpression = "${firstExpression}";

            firstBody.TextContent = firstExpression;

            ConditionExpression secondConditionExpression = createElement(ifPart, "con_2", typeof(ConditionExpression));
            Body   secondBody       = createElement(secondConditionExpression, null, typeof(Body));
            string secondExpression = "${secondExpression}";

            secondBody.TextContent = secondExpression;

            // when
            CmmnSentryDeclaration sentryDeclaration = sentryHandler.handleElement(sentry, context);

            // then
            assertNotNull(sentryDeclaration);

            CmmnIfPartDeclaration ifPartDeclaration = sentryDeclaration.IfPart;

            assertNotNull(ifPartDeclaration);

            Expression condition = ifPartDeclaration.Condition;

            assertNotNull(condition);
            assertEquals(firstExpression, condition.ExpressionText);

            // the second condition will be ignored!

            assertTrue(sentryDeclaration.OnParts.Count == 0);
        }
Ejemplo n.º 7
0
        protected internal virtual void initializeIfPart(IfPart ifPart, CmmnSentryDeclaration sentryDeclaration, CmmnHandlerContext context)
        {
            if (ifPart == null)
            {
                return;
            }

            ICollection <ConditionExpression> conditions = ifPart.Conditions;

            if (conditions.Count > 1)
            {
                string id = sentryDeclaration.Id;
                LOG.multipleIgnoredConditions(id);
            }

            ExpressionManager   expressionManager   = context.ExpressionManager;
            ConditionExpression condition           = conditions.GetEnumerator().next();
            Expression          conditionExpression = expressionManager.createExpression(condition.Text);

            CmmnIfPartDeclaration ifPartDeclaration = new CmmnIfPartDeclaration();

            ifPartDeclaration.Condition = conditionExpression;
            sentryDeclaration.IfPart    = ifPartDeclaration;
        }
Ejemplo n.º 8
0
        public virtual CmmnSentryDeclaration handleElement(Sentry element, CmmnHandlerContext context)
        {
            string id = element.Id;
            ICollection <OnPart> onParts = element.OnParts;
            IfPart ifPart = element.IfPart;
            IList <CamundaVariableOnPart> variableOnParts = queryExtensionElementsByClass(element, typeof(CamundaVariableOnPart));

            if ((ifPart == null || ifPart.Conditions.Empty) && variableOnParts.Count == 0)
            {
                if (onParts == null || onParts.Count == 0)
                {
                    LOG.ignoredSentryWithMissingCondition(id);
                    return(null);
                }
                else
                {
                    bool atLeastOneOnPartsValid = false;

                    foreach (OnPart onPart in onParts)
                    {
                        if (onPart is PlanItemOnPart)
                        {
                            PlanItemOnPart planItemOnPart = (PlanItemOnPart)onPart;
                            if (planItemOnPart.Source != null && planItemOnPart.StandardEvent != null)
                            {
                                atLeastOneOnPartsValid = true;
                                break;
                            }
                        }
                    }

                    if (!atLeastOneOnPartsValid)
                    {
                        LOG.ignoredSentryWithInvalidParts(id);
                        return(null);
                    }
                }
            }

            CmmnSentryDeclaration sentryDeclaration = new CmmnSentryDeclaration(id);

            // the ifPart will be initialized immediately
            initializeIfPart(ifPart, sentryDeclaration, context);

            // the variableOnParts will be initialized immediately as it does not have any dependency
            initializeVariableOnParts(element, sentryDeclaration, context, variableOnParts);

            // ...whereas the onParts will be initialized later because the
            // the reference to the plan items (sourceRef) and the reference
            // to the sentry (sentryRef) cannot be set in this step. To set
            // the corresponding reference (sourceRef or sentryRef) on the
            // transformed sentry all planned items and all sentries inside
            // the current stage should be already transformed.

            CmmnActivity parent = context.Parent;

            if (parent != null)
            {
                parent.addSentry(sentryDeclaration);
            }

            return(sentryDeclaration);
        }