The following C# unit test generates 2 versions of the same Jetfire workflow class. This is important in a persistent system since objects may remain active for a long period time (weeks, months or even years). During this time it may be necessary or desirable to add more features without impacting existing objects.

# region Copyright
//===================================================================================
// DVDLibTest.cs
// This file is part of Jetfire.  http://Jetfire.ca
// 
// Jetfire is open software: you can redistribute it and/or modify it under the 
// terms of the GNU General Public License as published by the Free Software 
// Foundation, version 3 of the License.
// 
// Jetfire is distributed in the hope that it will be useful, but WITHOUT ANY 
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
// FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License along with 
// Jetfire.  If not, see <http://www.gnu.org/licenses/>.
// REMOVAL OF THIS NOTICE IS VIOLATION OF THE COPYRIGHT.
//====================================================================================
# endregion
using System;
using System.Text;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TrackerRealm.Jetfire.Base;
using TrackerRealm.Jetfire;
using TrackerRealm.Jetfire.TransportCommon;
using TrackerRealm.Jetfire.NexusFileStorage;
using TrackerRealm.Jetfire.Nexus;
using TrackerRealm.Jetfire.MemoryTransport;

namespace JetfireCoreExampleTests
{
    /// <summary>
    /// 
    /// </summary>
    [TestClass]
    public class VersionTest
    {
        [TestMethod]
        public void TestMethodVersionTest()
        {
            #region simple Storage test
            // This is Jetfire code that defines a DVD with a single property: Title 
            string workflowString = 
            "namespace MySpace "+
            "{"+
            "   workflow DVD "+
            "   {"+
            "       string msg = \"noTitle\";"+
            "       public string Title"+
            "       {"+
            "           get{return msg;}" +
            "           set{msg = value;}" +
            "       }"+
            "   }"+
            "} ";
            TjFileStorage fileStorage = new TjFileStorage("c:/JetfireDashboard.Storage");
            fileStorage.Clear();
            TjServerNexus serverNexus = new TjServerNexus(fileStorage);
            TjLoginConnection loginConnection = new TjLoginConnection(
                    new TjLoginObjectUser(""),
                    new TjLoginObjectSubscription(""),
                    new TjLoginObjectRole[0],
                    null);
            TjMemoryTransport transport = new TjMemoryTransport(loginConnection, serverNexus);
            TjNexus nexus = transport.ClientNexus;
            TjParser parser = nexus.ParseServer(workflowString, null);

            TjWorkflowClass flowClass = parser.ToClasses()[0] as TjWorkflowClass;

            TjWorkflow flow = flowClass.NewWorkflow();
            TjPropertyClass titleClass;
            bool isFound = flowClass.TryFindClass("Title", out titleClass);
            Assert.IsTrue(isFound);
            TjProperty title = (TjProperty)titleClass.GetMemberObject(flow);

            TjString titleStr = (TjString)title.GetValueClient();
            Assert.AreEqual("noTitle", titleStr.GetValue() );

            titleStr.SetValue("Hello World");
            title.SetValueServer(titleStr);
            Assert.AreEqual("Hello World", titleStr.GetValue() );
            #endregion
            // Jetfire code example 2 is the same class: DVD with another property added - Genre 
            string workflowString2 =
            "namespace MySpace " +
            "{" +
            "   workflow DVD " +
            "   {" +
            "       string msg = \"noTitle\";" +
            "       string genre = \"Action\";"+
            "       public string Title" +
            "       {" +
            "           get{return msg;}" +
            "           set{msg = value;}" +
            "       }" +
            "       public string Genre" +
            "       {" +
            "           get{return genre;}" +
            "           set{msg = genre;}" +
            "       }" +
            "   }" +
            "} ";
            // Add this code to the nexus. 
            // Because this is the same class: DVD, the nexus adds the class as a separate version
            // There are now TWO DVD classes in the library.
            TjParser parser2 = nexus.ParseServer(workflowString2, parser.ParseUnit);

            TjWorkflowClass flowClass2 = parser2.ToClasses()[0] as TjWorkflowClass;

            TjWorkflow flow2 = flowClass2.NewWorkflow();

            TjPropertyClass titleClass2;
            bool isFound2 = flowClass2.TryFindClass("Title", out titleClass2);
            Assert.IsTrue(isFound2);
            TjProperty title2 = (TjProperty)titleClass2.GetMemberObject(flow2);

            TjString titleStr2 = (TjString)title2.GetValueClient();
            Assert.AreEqual("noTitle", titleStr2.GetValue());

            titleStr2.SetValue("Wild Wild West");
            title2.SetValueServer(titleStr);
            Assert.AreEqual("Wild Wild West", titleStr.GetValue());
            nexus.SaveToServer();
            transport.Dispose();
        }
    }
}


Note: To find an existing 'parse unit' use the 'codecollection' found in the client nexus. The instance property 'TjNexus.CodeCollection' can be used to navigate to the 'codecollection'. Search the source code for 'TjCodeCollection' for more information.

Last edited Feb 3, 2011 at 11:58 AM by JohnHansen, version 5

Comments

No comments yet.