Пример #1
0
        public void ActionParamsByName()
        {
            string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<Peach>\n" +
                         "	<DataModel name=\"TheDataModel\">"+
                         "		<Number name=\"FindMe\" size=\"8\"/>"+
                         "	</DataModel>"+
                         "	<StateModel name=\"TheState\" initialState=\"State1\">"+
                         "		<State name=\"State1\">"+
                         "			<Action name='call' type=\"call\" method=\"foo\">"+
                         "				<Param>"+
                         "					<DataModel name=\"DM_Param1\" ref=\"TheDataModel\" />"+
                         "				</Param>"+
                         "				<Param>"+
                         "					<DataModel name=\"DM_Param2\" ref=\"TheDataModel\" />"+
                         "				</Param>"+
                         "				<Result>"+
                         "					<DataModel name=\"DM_Result\" ref=\"TheDataModel\" />"+
                         "				</Result>"+
                         "			</Action>"+
                         "		</State>"+
                         "	</StateModel>"+
                         "	<Test name=\"Default\">"+
                         "		<StateModel ref=\"TheState\"/>"+
                         "		<Publisher class=\"Console\" />"+
                         "	</Test>"+
                         "</Peach>";

            PitParser parser = new PitParser();

            Dom.Dom dom = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml)));

            var action = dom.tests["Default"].stateModel.states["State1"].actions[0] as Dom.Actions.Call;


            PeachXPathNavigator navi   = new PeachXPathNavigator(dom);
            XPathNodeIterator   iter   = navi.Select("//DM_Param1//FindMe");
            DataElement         findMe = action.parameters[0].dataModel[0];

            Assert.IsTrue(iter.MoveNext());
            Assert.AreEqual(findMe, ((PeachXPathNavigator)iter.Current).currentNode);
            Assert.IsFalse(iter.MoveNext());

            iter   = navi.Select("//DM_Param2//FindMe");
            findMe = action.parameters[1].dataModel[0];

            Assert.IsTrue(iter.MoveNext());
            Assert.AreEqual(findMe, ((PeachXPathNavigator)iter.Current).currentNode);
            Assert.IsFalse(iter.MoveNext());

            iter   = navi.Select("//DM_Result//FindMe");
            findMe = action.result.dataModel[0];

            Assert.IsTrue(iter.MoveNext());
            Assert.AreEqual(findMe, ((PeachXPathNavigator)iter.Current).currentNode);
            Assert.IsFalse(iter.MoveNext());
        }
Пример #2
0
        public void BasicTest()
        {
            string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<Peach>\n" +
                         "	<DataModel name=\"TheDataModel\">"+
                         "		<Number name=\"TheNumber\" size=\"8\">"+
                         "			<Relation type=\"count\" of=\"Array\" />"+
                         "		</Number>"+
                         "		<String name=\"Array\" value=\"1\" maxOccurs=\"100\"/>"+
                         "	</DataModel>"+
                         "	<StateModel name=\"TheState\" initialState=\"State1\">"+
                         "		<State name=\"State1\">"+
                         "			<Action type=\"output\">"+
                         "				<DataModel ref=\"TheDataModel\" />"+
                         "			</Action>"+
                         "		</State>"+
                         "	</StateModel>"+
                         "	<Test name=\"Default\">"+
                         "		<StateModel ref=\"TheState\"/>"+
                         "		<Publisher class=\"Console\" />"+
                         "	</Test>"+
                         "</Peach>";

            PitParser parser = new PitParser();

            Dom.Dom             dom  = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml)));
            PeachXPathNavigator navi = new PeachXPathNavigator(dom);
            XPathNodeIterator   iter = navi.Select("//TheNumber");

            Assert.IsTrue(iter.MoveNext());
            Assert.AreEqual(dom.tests["Default"].stateModel.states["State1"].actions[0].dataModel["TheNumber"],
                            ((PeachXPathNavigator)iter.Current).currentNode);
            Assert.IsFalse(iter.MoveNext());
        }
Пример #3
0
        public void PeachXPath2()
        {
            string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" +
                         "<Peach>" +
                         "   <DataModel name=\"TheDataModel1\">" +
                         "       <String name=\"String1\" value=\"1234567890\"/>" +
                         "   </DataModel>" +
                         "   <DataModel name=\"TheDataModel2\">" +
                         "       <String name=\"String2\" value=\"Hello World!\"/>" +
                         "   </DataModel>" +

                         "   <StateModel name=\"TheStateModel\" initialState=\"InitialState\">" +
                         "       <State name=\"InitialState\">" +
                         "           <Action name=\"Action1\" type=\"output\">" +
                         "               <DataModel ref=\"TheDataModel1\"/>" +
                         "           </Action>" +

                         "           <Action name=\"Action2\" type=\"slurp\" valueXpath=\"//String1\" setXpath=\"//String2\" />" +

                         "           <Action name=\"Action3\" type=\"output\">" +
                         "               <DataModel ref=\"TheDataModel2\"/>" +
                         "           </Action>" +

                         "           <Action name=\"Action4\" type=\"output\">" +
                         "               <DataModel ref=\"TheDataModel2\"/>" +
                         "           </Action>" +
                         "       </State>" +
                         "   </StateModel>" +

                         "   <Test name=\"Default\">" +
                         "       <StateModel ref=\"TheStateModel\"/>" +
                         "       <Publisher class=\"Null\"/>" +
                         "   </Test>" +
                         "</Peach>";

            PitParser parser = new PitParser();

            Dom.Dom dom = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml)));

            PeachXPathNavigator nav = new PeachXPathNavigator(dom);
            XPathNodeIterator   it  = nav.Select("//String1");

            // Should find one element
            bool ret1 = it.MoveNext();

            Assert.True(ret1);

            // The result should be a DataElement
            DataElement valueElement = ((PeachXPathNavigator)it.Current).currentNode as DataElement;

            Assert.NotNull(valueElement);

            // There sould on;ly be one result
            bool ret2 = it.MoveNext();

            Assert.False(ret2);
        }
Пример #4
0
        protected void handleSlurp(RunContext context)
        {
            PeachXmlNamespaceResolver resolver = new PeachXmlNamespaceResolver();
            PeachXPathNavigator       navi     = new PeachXPathNavigator(context.dom);
            var iter = navi.Select(valueXpath, resolver);

            if (!iter.MoveNext())
            {
                throw new SoftException("Error, slurp valueXpath returned no values. [" + valueXpath + "]");
            }

            DataElement valueElement = ((PeachXPathNavigator)iter.Current).currentNode as DataElement;

            if (valueElement == null)
            {
                throw new SoftException("Error, slurp valueXpath did not return a Data Element. [" + valueXpath + "]");
            }

            if (iter.MoveNext())
            {
                throw new SoftException("Error, slurp valueXpath returned multiple values. [" + valueXpath + "]");
            }

            iter = navi.Select(setXpath, resolver);

            if (!iter.MoveNext())
            {
                throw new SoftException("Error, slurp setXpath returned no values. [" + setXpath + "]");
            }

            do
            {
                var setElement = ((PeachXPathNavigator)iter.Current).currentNode as DataElement;
                if (setElement == null)
                {
                    throw new PeachException("Error, slurp setXpath did not return a Data Element. [" + valueXpath + "]");
                }

                logger.Debug("Slurp, setting " + setElement.fullName + " from " + valueElement.fullName);
                setElement.DefaultValue = valueElement.DefaultValue;
            }while (iter.MoveNext());
        }
Пример #5
0
        public void PeachXPath()
        {
            string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" +
                         "<Peach>" +
                         "	<DataModel name=\"TheDataModel\">"+
                         "		<Number name=\"TheNumber\" size=\"8\"/>"+
                         "	</DataModel>"+

                         "   <StateModel name=\"TheStateModel\" initialState=\"InitialState\">" +
                         "       <State name=\"InitialState\">" +
                         "           <Action name=\"Action1\" type=\"output\">" +
                         "               <DataModel ref=\"TheDataModel\"/>" +
                         "           </Action>" +
                         "       </State>" +
                         "   </StateModel>" +

                         "   <Test name=\"Default\">" +
                         "       <StateModel ref=\"TheStateModel\"/>" +
                         "       <Publisher class=\"Null\"/>" +
                         "   </Test>" +
                         "</Peach>";

            PitParser parser = new PitParser();

            Dom.Dom dom = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml)));

            PeachXPathNavigator nav = new PeachXPathNavigator(dom);
            XPathNodeIterator   it  = nav.Select("//TheNumber");

            List <string> res = new List <string>();

            while (it.MoveNext())
            {
                var val = it.Current.Name;
                res.Add(val);
            }

            Assert.AreEqual(1, res.Count);
            Assert.AreEqual("TheNumber", res[0]);
        }
Пример #6
0
        public void SlurpArray()
        {
            string xml = @"
<Peach>
	<DataModel name='TheDataModel'>
		<String name='str' value='Hello'/>
		<Block name='blk' minOccurs='1'>
			<String name='val'/>
		</Block>
	</DataModel>

	<StateModel name='TheState' initialState='State1'>
		<State name='State1'>
			<Action type='output'>
				<DataModel ref='TheDataModel'/>
			</Action>
		</State>
	</StateModel>

	<Test name='Default'>
		<StateModel ref='TheState'/>
		<Publisher class='Console'/>
	</Test>
</Peach>
";

            PitParser parser = new PitParser();

            Dom.Dom dom = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml)));

            Dom.Array array = dom.tests[0].stateModel.states["State1"].actions[0].dataModel[1] as Dom.Array;
            array.ExpandTo(50);

            PeachXPathNavigator navi = new PeachXPathNavigator(dom);
            var iter = navi.Select("//str");

            if (!iter.MoveNext())
            {
                Assert.Fail();
            }

            DataElement valueElement = ((PeachXPathNavigator)iter.Current).currentNode as DataElement;

            if (valueElement == null)
            {
                Assert.Fail();
            }

            if (iter.MoveNext())
            {
                Assert.Fail();
            }

            iter = navi.Select("//val");

            if (!iter.MoveNext())
            {
                Assert.Fail();
            }

            int count = 0;

            do
            {
                var setElement = ((PeachXPathNavigator)iter.Current).currentNode as DataElement;
                if (setElement == null)
                {
                    Assert.Fail();
                }

                setElement.DefaultValue = valueElement.DefaultValue;
                ++count;
            }while (iter.MoveNext());

            // When Array.ExpandTo() is used, it duplicates the element and adds that
            // same element over and over, so there are really only 2 unique elements in the array...
            Assert.AreEqual(2, count);
            Assert.AreEqual(50, array.Count);

            int hash = 0;

            for (int i = 0; i < array.Count; ++i)
            {
                if (i <= 1)
                {
                    hash = array[i].GetHashCode();
                }

                Assert.AreEqual(hash, array[i].GetHashCode());
                var b = array[i] as Block;
                Assert.NotNull(b);
                Assert.AreEqual("Hello", (string)b[0].DefaultValue);
            }
        }