Beispiel #1
0
        public void ValidateFunctionalTest()
        {
            UmlModel model = null; // TODO: Initialize to an appropriate value

            model = new UmlModel("Model X");
            UmlActivityDiagram diagram = new UmlActivityDiagram("");
            //UmlUseCaseDiagram case1 = new UmlUseCaseDiagram();
            UmlInitialState initial     = new UmlInitialState();
            UmlFinalState   final       = new UmlFinalState();
            UmlActionState  action      = new UmlActionState();
            UmlActionState  action1     = new UmlActionState();
            UmlTransition   transition  = new UmlTransition();
            UmlTransition   transition1 = new UmlTransition();
            UmlTransition   transition2 = new UmlTransition();

            initial.Name = "initial0";
            final.Name   = "final0";
            diagram.UmlObjects.Add(initial);
            transition.Source = initial;
            transition.Target = action;
            action.SetTaggedValue("jude.hyperlink", "teste");
            transition1.Source = action;
            transition1.Target = action1;
            transition1.SetTaggedValue("FTaction", "");
            transition1.SetTaggedValue("FTexpectedResult", "Use parameters in the shared step below.");
            transition2.Source = action1;
            transition2.Target = final;
            diagram.UmlObjects.Add(action);
            diagram.UmlObjects.Add(action1);
            diagram.UmlObjects.Add(transition);
            diagram.UmlObjects.Add(transition1);
            diagram.UmlObjects.Add(transition2);
            diagram.UmlObjects.Add(transition2);



            List <KeyValuePair <string, int> > expected = new List <KeyValuePair <string, int> >(); // TODO: Initialize to an appropriate value
            List <KeyValuePair <string, int> > actual   = ValidatorFactory.CreateValidator().Validate(model, "");


            Assert.AreEqual(expected.Count, actual.Count);

            IEnumerator <KeyValuePair <string, int> > e1 = expected.GetEnumerator();
            IEnumerator <KeyValuePair <string, int> > e2 = actual.GetEnumerator();

            while (e1.MoveNext() && e2.MoveNext())
            {
                Assert.AreEqual(e1.Current, e2.Current);
            }
        }
        public UmlModel FromXmi(XmlDocument doc, ref String name)
        {
            UmlModel model = new UmlModel("");
            //uml and astah namespaces
            XmlNamespaceManager nsManager = new XmlNamespaceManager(doc.NameTable);

            nsManager.AddNamespace("JUDE", "http://objectclub.esm.co.jp/Jude/namespace/");
            nsManager.AddNamespace("UML", "org.omg.xmi.namespace.UML");

            XmlNodeList mod = doc.SelectNodes("//UML:Model[@xmi.id]", nsManager);

            foreach (XmlNode node in mod)
            {
                name = node.Attributes["name"].Value;
                break;
            }
            //importing activity diagrams into model.
            XmlNodeList nodesWithActivityDiagrams = doc.SelectNodes("//UML:ActivityGraph[@xmi.id]", nsManager);

            #region Activity Diagram
            if (nodesWithActivityDiagrams.Count != 0)
            {
                foreach (XmlNode node in nodesWithActivityDiagrams)
                {
                    UmlActivityDiagram actDiagram = new UmlActivityDiagram(node.Attributes["name"].Value);
                    actDiagram.Id   = node.Attributes["xmi.id"].Value;
                    actDiagram.Name = node.Attributes["name"].Value;
                    model.AddDiagram(actDiagram);

                    #region Pseudostate
                    foreach (XmlNode pseudoNode in node.SelectNodes("//UML:ActivityGraph[@xmi.id='" + actDiagram.Id + "']//UML:Pseudostate[@xmi.id]", nsManager))
                    {
                        UmlElement element = null;

                        if (pseudoNode.Attributes["kind"].Value.Equals("initial"))
                        {
                            element = new UmlInitialState();
                        }
                        else if (pseudoNode.Attributes["kind"].Value.Equals("fork"))
                        {
                            element = new UmlFork();
                        }
                        else if (pseudoNode.Attributes["kind"].Value.Equals("junction"))
                        {
                            element = new UmlDecision();
                        }
                        else if (pseudoNode.Attributes["kind"].Value.Equals("join"))
                        {
                            element = new UmlJoin();
                        }

                        element.Name = pseudoNode.Attributes["name"].Value;
                        element.Id   = pseudoNode.Attributes["xmi.id"].Value;

                        #region Tagged Values
                        foreach (XmlNode taggedValuesNode in pseudoNode.SelectNodes("//UML:Pseudostate[@xmi.id='" + element.Id + "']//UML:ModelElement.taggedValue//UML:TaggedValue[@xmi.id]", nsManager))
                        {
                            //element.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value, HttpUtility.UrlDecode(taggedValuesNode.Attributes["value"].Value));
                            element.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value, taggedValuesNode.Attributes["value"].Value);
                        }
                        #endregion

                        actDiagram.UmlObjects.Add(element);
                    }
                    #endregion
                    #region ActionState
                    foreach (XmlNode stateNode in node.SelectNodes("//UML:ActivityGraph[@xmi.id='" + actDiagram.Id + "']//UML:ActionState[@xmi.id]", nsManager))
                    {
                        UmlElement state = new UmlActionState();
                        state.Id   = stateNode.Attributes["xmi.id"].Value;
                        state.Name = stateNode.Attributes["name"].Value;

                        #region Tagged Values
                        foreach (XmlNode taggedValuesNode in stateNode.SelectNodes("//UML:ActionState[@xmi.id='" + state.Id + "']//UML:ModelElement.taggedValue//UML:TaggedValue[@xmi.id]", nsManager))
                        {
                            #region Hyperlink
                            if (taggedValuesNode.Attributes["tag"].Value.Equals("jude.hyperlink"))
                            {
                                string nameToken    = "type%3Dmodel%2Cname%3D";
                                string commentToken = "%2Cpath%3D%2Ccomment%3D";
                                int    i1           = taggedValuesNode.Attributes["value"].Value.IndexOf(nameToken) + (nameToken.Length);
                                int    i2           = taggedValuesNode.Attributes["value"].Value.IndexOf(commentToken);
                                String aux_value    = taggedValuesNode.Attributes["value"].Value.Substring(i1, i2 - commentToken.Length + 1);
                                String aux_value2   = taggedValuesNode.Attributes["value"].Value.Substring(i2 + commentToken.Length);

                                state.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value, aux_value);

                                if (!String.IsNullOrEmpty(aux_value2))
                                {
                                    state.SetTaggedValue("cycles", aux_value2);
                                }

                                foreach (XmlNode jude in node.SelectNodes("//JUDE:Diagram[@xmi.id='" + aux_value + "']//UML:ActivityGraph", nsManager))
                                {
                                    string idActivityGraph = jude.Attributes["xmi.idref"].Value;
                                    foreach (XmlNode item in node.SelectNodes("//UML:ActivityGraph[xmi.id='" + idActivityGraph + "']", nsManager))
                                    {
                                        state.SetTaggedValue("jude.hyperlink", item.Attributes["name"].Value);
                                    }
                                }
                                foreach (XmlNode item in node.SelectNodes("//JUDE:ActivityDiagram[@xmi.id='" + aux_value + "']//UML:ActivityGraph", nsManager))
                                {
                                    string idActivityGraph = item.Attributes["xmi.idref"].Value;
                                    foreach (XmlNode item1 in node.SelectNodes("//UML:ActivityGraph[@xmi.id='" + idActivityGraph + "']", nsManager))
                                    {
                                        state.SetTaggedValue("jude.hyperlink", item1.Attributes["name"].Value);
                                    }
                                }
                            }
                            #endregion
                            else
                            {
                                string tag = taggedValuesNode.Attributes["tag"].Value;
                                string var = null;
                                try
                                {
                                    var = taggedValuesNode.Attributes["value"].Value;
                                }
                                catch (Exception)
                                {
                                    state.SetTaggedValue(tag, "");
                                }
                                if (var != null)
                                {
                                    state.SetTaggedValue(tag, var);
                                }
                            }
                        }
                        #endregion

                        actDiagram.UmlObjects.Add(state);
                    }
                    #endregion
                    #region FinalState
                    foreach (XmlNode finalStateNode in node.SelectNodes("//UML:ActivityGraph[@xmi.id='" + actDiagram.Id + "']//UML:FinalState[@xmi.id]", nsManager))
                    {
                        UmlElement finalState = new UmlFinalState();
                        finalState.Name = finalStateNode.Attributes["name"].Value;
                        finalState.Id   = finalStateNode.Attributes["xmi.id"].Value;

                        #region Tagged Values
                        foreach (XmlNode taggedValuesNode in finalStateNode.SelectNodes("//UML:FinalState[@xmi.id='" + finalState.Id + "']//UML:ModelElement.taggedValue//UML:TaggedValue[@xmi.id]", nsManager))
                        {
                            //finalState.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value, HttpUtility.UrlDecode(taggedValuesNode.Attributes["value"].Value));
                            finalState.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value, taggedValuesNode.Attributes["value"].Value);
                        }
                        #endregion

                        actDiagram.UmlObjects.Add(finalState);
                    }
                    #endregion
                    #region Transition
                    //UmlTransition
                    foreach (XmlNode transitionNode in node.SelectNodes("//UML:ActivityGraph[@xmi.id='" + actDiagram.Id + "']//UML:Transition[@xmi.id]", nsManager))
                    {
                        UmlTransition transition = new UmlTransition();

                        transition.Id   = transitionNode.Attributes["xmi.id"].Value;
                        transition.Name = transitionNode.Attributes["name"].Value;
                        // Tagged Values
                        foreach (XmlNode tagValuesNode in transitionNode.SelectNodes("//UML:ActivityGraph[@xmi.id='" + actDiagram.Id + "']//UML:Transition[@xmi.id='" + transition.Id + "']//UML:TaggedValue", nsManager))
                        {
                            try
                            {
                                //transition.SetTaggedValue(tagValuesNode.Attributes["tag"].Value, HttpUtility.UrlDecode(tagValuesNode.Attributes["value"].Value));
                                transition.SetTaggedValue(tagValuesNode.Attributes["tag"].Value.ToUpper(), tagValuesNode.Attributes["value"].Value);
                            }
                            catch
                            {
                                transition.SetTaggedValue(tagValuesNode.Attributes["tag"].Value.ToUpper(), "");
                            }
                        }
                        // Transition Source
                        foreach (XmlNode transitionSource in transitionNode.SelectNodes("//UML:ActivityGraph[@xmi.id='" + actDiagram.Id + "']//UML:Transition[@xmi.id='" + transition.Id + "']//UML:Transition.source//UML:StateVertex", nsManager))
                        {
                            UmlElement element = actDiagram.GetElementById(transitionSource.Attributes["xmi.idref"].Value);
                            transition.Source = element;
                        }
                        // Transition Target
                        foreach (XmlNode transitionTarget in transitionNode.SelectNodes("//UML:ActivityGraph[@xmi.id='" + actDiagram.Id + "']//UML:Transition[@xmi.id='" + transition.Id + "']//UML:Transition.target//UML:StateVertex", nsManager))
                        {
                            UmlElement element = actDiagram.GetElementById(transitionTarget.Attributes["xmi.idref"].Value);
                            transition.Target = element;
                        }
                        actDiagram.UmlObjects.Add(transition);
                    }
                    #endregion
                    #region Lanes
                    XmlNodeList partition   = node.SelectNodes("//UML:ActivityGraph[@xmi.id='" + actDiagram.Id + "']//UML:Partition[@xmi.id]", nsManager);
                    bool        isDimension = false;

                    if (partition.Count != 0)
                    {
                        foreach (XmlNode dimensionNode in partition)
                        {
                            if (isDimension == false)
                            {
                                isDimension = true;
                                UmlLane dimension = new UmlLane();
                                dimension.Id   = dimensionNode.Attributes["xmi.id"].Value;
                                dimension.Name = dimensionNode.Attributes["name"].Value;
                                foreach (XmlNode laneNode in dimensionNode.SelectNodes("//UML:ActivityGraph[@xmi.id='" + actDiagram.Id + "']//UML:Partition[@xmi.id='" + dimension.Id + "']//JUDE:ModelElement", nsManager))
                                {
                                    XmiImporter importer = new XmiImporter();
                                    UmlLane     lane     = importer.CreateLane(dimension.Id, node, laneNode.Attributes["xmi.idref"].Value, actDiagram, nsManager);
                                    actDiagram.UmlObjects.Add(lane);
                                    actDiagram.Lanes.Add(lane);
                                    dimension.ListLane.Add(lane);
                                }
                            }
                        }
                    }
                    #endregion
                }
            }
            #endregion

            //importing usecase diagrams into model.
            XmlNodeList nodesWithUseCaseDiagrams = doc.SelectNodes("//UML:UseCase[@xmi.id]", nsManager);
            XmlNodeList nodesWithActorDiagrams   = doc.SelectNodes("//UML:Actor[@xmi.id]", nsManager);

            #region UseCase Diagrams
            //   if (nodesWithUseCaseDiagrams.Count != 0 && nodesWithActorDiagrams.Count != 0)
            {
                XmlNodeList modelElements = doc.SelectNodes("//UML:Model[@xmi.id]", nsManager);

                foreach (XmlNode node in modelElements)
                {
                    UmlUseCaseDiagram useCaseDiagram = new UmlUseCaseDiagram();
                    useCaseDiagram.Id   = node.Attributes["xmi.id"].Value;
                    useCaseDiagram.Name = node.Attributes["name"].Value;
                    model.AddDiagram(useCaseDiagram);
                    #region Actor
                    foreach (XmlNode actorNode in node.SelectNodes("//UML:Actor[@xmi.id]", nsManager))
                    {
                        UmlActor actor = new UmlActor();
                        actor.Id   = actorNode.Attributes["xmi.id"].Value;
                        actor.Name = actorNode.Attributes["name"].Value;

                        #region Tagged Values
                        foreach (XmlNode taggedValuesNode in actorNode.SelectNodes("//UML:Actor[@xmi.id='" + actor.Id + "']//UML:ModelElement.taggedValue//UML:TaggedValue[@xmi.id]", nsManager))
                        {
                            #region Hyperlink
                            if (taggedValuesNode.Attributes["tag"].Value.Equals("jude.hyperlink"))
                            {
                                string aux_value = taggedValuesNode.Attributes["value"].Value.Substring(22);
                                aux_value = aux_value.Substring(0, aux_value.Length - 23);
                                actor.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value, aux_value);
                                foreach (XmlNode jude in node.SelectNodes("//JUDE:Diagram[@xmi.id='" + aux_value + "']//UML:ActivityGraph", nsManager))
                                {
                                    string idActivityGraph = jude.Attributes["xmi.idref"].Value;
                                    foreach (XmlNode item in node.SelectNodes("//UML:ActivityGraph[xmi.id='" + idActivityGraph + "']", nsManager))
                                    {
                                        actor.SetTaggedValue("jude.hyperlink", item.Attributes["name"].Value);
                                    }
                                }
                                foreach (XmlNode item in node.SelectNodes("//JUDE:ActivityDiagram[@xmi.id='" + aux_value + "']//UML:ActivityGraph", nsManager))
                                {
                                    string idActivityGraph = item.Attributes["xmi.idref"].Value;
                                    foreach (XmlNode item1 in node.SelectNodes("//UML:ActivityGraph[@xmi.id='" + idActivityGraph + "']", nsManager))
                                    {
                                        actor.SetTaggedValue("jude.hyperlink", item1.Attributes["name"].Value);
                                    }
                                }
                            }
                            #endregion
                            else
                            {
                                try
                                {
                                    //actor.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value, HttpUtility.UrlDecode(taggedValuesNode.Attributes["value"].Value));
                                    actor.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value.ToUpper(), taggedValuesNode.Attributes["value"].Value);
                                }
                                catch
                                {
                                    actor.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value.ToUpper(), "");
                                }
                            }
                        }
                        #endregion
                        useCaseDiagram.UmlObjects.Add(actor);
                    }
                    #endregion
                    #region UseCase
                    foreach (XmlNode useCaseNode in node.SelectNodes("//UML:UseCase[@xmi.id]", nsManager))
                    {
                        UmlUseCase useCase = new UmlUseCase();
                        useCase.Id   = useCaseNode.Attributes["xmi.id"].Value;
                        useCase.Name = useCaseNode.Attributes["name"].Value;

                        #region Tagged Values
                        foreach (XmlNode taggedValuesNode in node.SelectNodes("//UML:UseCase[@xmi.id='" + useCase.Id + "']//UML:ModelElement.taggedValue//UML:TaggedValue[@xmi.id]", nsManager))
                        {
                            #region Hyperlink
                            if (taggedValuesNode.Attributes["tag"].Value.Equals("jude.hyperlink"))
                            {
                                string aux_value = taggedValuesNode.Attributes["value"].Value.Substring(22);
                                aux_value = aux_value.Substring(0, aux_value.Length - 23);
                                foreach (XmlNode jude in node.SelectNodes("//JUDE:Diagram[@xmi.id='" + aux_value + "']//UML:ActivityGraph", nsManager))
                                {
                                    string idActivityGraph = jude.Attributes["xmi.idref"].Value;
                                    foreach (XmlNode item in node.SelectNodes("//UML:ActivityGraph[xmi.id='" + idActivityGraph + "']", nsManager))
                                    {
                                        useCase.SetTaggedValue("jude.hyperlink", item.Attributes["name"].Value);
                                    }
                                }

                                foreach (XmlNode item in node.SelectNodes("//JUDE:ActivityDiagram[@xmi.id='" + aux_value + "']//UML:ActivityGraph", nsManager))
                                {
                                    string idActivityGraph = item.Attributes["xmi.idref"].Value;
                                    foreach (XmlNode item1 in node.SelectNodes("//UML:ActivityGraph[@xmi.id='" + idActivityGraph + "']", nsManager))
                                    {
                                        useCase.SetTaggedValue("jude.hyperlink", item1.Attributes["name"].Value);
                                    }
                                }
                            }
                            #endregion
                            else
                            {
                                try
                                {
                                    //useCase.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value, HttpUtility.UrlDecode(taggedValuesNode.Attributes["value"].Value));
                                    useCase.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value.ToUpper(), taggedValuesNode.Attributes["value"].Value);
                                }
                                catch
                                {
                                    useCase.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value.ToUpper(), "");
                                }
                            }
                        }
                        #endregion
                        useCaseDiagram.UmlObjects.Add(useCase);
                    }
                    #endregion
                    #region Association
                    foreach (XmlNode associationNode in node.SelectNodes("//UML:Association[@xmi.id]", nsManager))
                    {
                        UmlAssociation association = new UmlAssociation();
                        association.Id   = associationNode.Attributes["xmi.id"].Value;
                        association.Name = associationNode.Attributes["name"].Value;

                        bool putEnd1 = false;

                        foreach (XmlNode associationEndNode in associationNode.SelectNodes("//UML:Association[@xmi.id='" + association.Id + "']//UML:AssociationEnd//UML:AssociationEnd.participant//UML:Classifier[@xmi.idref]", nsManager))
                        {
                            foreach (UmlElement element in useCaseDiagram.UmlObjects.OfType <UmlElement>())
                            {
                                if (!putEnd1)
                                {
                                    if (element.Id.Equals(associationEndNode.Attributes["xmi.idref"].Value))
                                    {
                                        association.End1 = element;
                                        putEnd1          = true;
                                    }
                                }
                                else
                                {
                                    if (element.Id.Equals(associationEndNode.Attributes["xmi.idref"].Value))
                                    {
                                        association.End2 = element;
                                    }
                                }
                            }
                        }

                        #region Tagged Values
                        foreach (XmlNode taggedValuesNode in node.SelectNodes("//UML:Association[@xmi.id='" + association.Id + "']//UML:ModelElement.taggedValue//UML:TaggedValue[@xmi.id]", nsManager))
                        {
                            try
                            {
                                //association.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value, HttpUtility.UrlDecode(taggedValuesNode.Attributes["value"].Value));
                                association.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value, taggedValuesNode.Attributes["value"].Value);
                            }
                            catch
                            {
                                association.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value, "");
                            }
                        }
                        #endregion
                        useCaseDiagram.UmlObjects.Add(association);
                    }

                    #endregion
                    #region Include
                    foreach (XmlNode includeNode in node.SelectNodes("//UML:Include[@xmi.id]", nsManager))
                    {
                        UmlAssociation association = new UmlAssociation();
                        association.Id   = includeNode.Attributes["xmi.id"].Value;
                        association.Name = includeNode.Attributes["name"].Value;
                        association.Stereotypes.Add("Include");

                        XmlNode begin = includeNode.SelectSingleNode("//UML:Include[@xmi.id='" + association.Id + "']//UML:Include.base//UML:UseCase[@xmi.idref]", nsManager);
                        XmlNode end   = includeNode.SelectSingleNode("//UML:Include[@xmi.id='" + association.Id + "']//UML:Include.addition//UML:UseCase[@xmi.idref]", nsManager);

                        foreach (UmlElement element in useCaseDiagram.UmlObjects.OfType <UmlElement>())
                        {
                            if (element.Id.Equals(begin.Attributes["xmi.idref"].Value))
                            {
                                association.End1 = element;
                            }
                            else if (element.Id.Equals(end.Attributes["xmi.idref"].Value))
                            {
                                association.End2 = element;
                            }
                        }
                        useCaseDiagram.UmlObjects.Add(association);
                    }
                    #endregion
                    #region Extend
                    foreach (XmlNode extendNode in node.SelectNodes("//UML:Extend[@xmi.id]", nsManager))
                    {
                        UmlAssociation association = new UmlAssociation();
                        association.Id   = extendNode.Attributes["xmi.id"].Value;
                        association.Name = extendNode.Attributes["name"].Value;
                        association.Stereotypes.Add("Extend");

                        XmlNode end   = extendNode.SelectSingleNode("//UML:Extend[@xmi.id='" + association.Id + "']//UML:Extend.base//UML:UseCase[@xmi.idref]", nsManager);
                        XmlNode begin = extendNode.SelectSingleNode("//UML:Extend[@xmi.id='" + association.Id + "']//UML:Extend.extension//UML:UseCase[@xmi.idref]", nsManager);

                        foreach (UmlElement element in useCaseDiagram.UmlObjects.OfType <UmlElement>())
                        {
                            if (element.Id.Equals(begin.Attributes["xmi.idref"].Value))
                            {
                                association.End1 = element;
                            }
                            else if (element.Id.Equals(end.Attributes["xmi.idref"].Value))
                            {
                                association.End2 = element;
                            }
                        }
                        useCaseDiagram.UmlObjects.Add(association);
                    }
                    #endregion
                }
            }
            #endregion
            return(model);
        }