Exemplo n.º 1
0
        public virtual void TestEntities()
        {
            TimelineEntities entities = new TimelineEntities();

            for (int j = 0; j < 2; ++j)
            {
                TimelineEntity entity = new TimelineEntity();
                entity.SetEntityId("entity id " + j);
                entity.SetEntityType("entity type " + j);
                entity.SetStartTime(Runtime.CurrentTimeMillis());
                for (int i = 0; i < 2; ++i)
                {
                    TimelineEvent @event = new TimelineEvent();
                    @event.SetTimestamp(Runtime.CurrentTimeMillis());
                    @event.SetEventType("event type " + i);
                    @event.AddEventInfo("key1", "val1");
                    @event.AddEventInfo("key2", "val2");
                    entity.AddEvent(@event);
                }
                entity.AddRelatedEntity("test ref type 1", "test ref id 1");
                entity.AddRelatedEntity("test ref type 2", "test ref id 2");
                entity.AddPrimaryFilter("pkey1", "pval1");
                entity.AddPrimaryFilter("pkey2", "pval2");
                entity.AddOtherInfo("okey1", "oval1");
                entity.AddOtherInfo("okey2", "oval2");
                entity.SetDomainId("domain id " + j);
                entities.AddEntity(entity);
            }
            Log.Info("Entities in JSON:");
            Log.Info(TimelineUtils.DumpTimelineRecordtoJSON(entities, true));
            NUnit.Framework.Assert.AreEqual(2, entities.GetEntities().Count);
            TimelineEntity entity1 = entities.GetEntities()[0];

            NUnit.Framework.Assert.AreEqual("entity id 0", entity1.GetEntityId());
            NUnit.Framework.Assert.AreEqual("entity type 0", entity1.GetEntityType());
            NUnit.Framework.Assert.AreEqual(2, entity1.GetRelatedEntities().Count);
            NUnit.Framework.Assert.AreEqual(2, entity1.GetEvents().Count);
            NUnit.Framework.Assert.AreEqual(2, entity1.GetPrimaryFilters().Count);
            NUnit.Framework.Assert.AreEqual(2, entity1.GetOtherInfo().Count);
            NUnit.Framework.Assert.AreEqual("domain id 0", entity1.GetDomainId());
            TimelineEntity entity2 = entities.GetEntities()[1];

            NUnit.Framework.Assert.AreEqual("entity id 1", entity2.GetEntityId());
            NUnit.Framework.Assert.AreEqual("entity type 1", entity2.GetEntityType());
            NUnit.Framework.Assert.AreEqual(2, entity2.GetRelatedEntities().Count);
            NUnit.Framework.Assert.AreEqual(2, entity2.GetEvents().Count);
            NUnit.Framework.Assert.AreEqual(2, entity2.GetPrimaryFilters().Count);
            NUnit.Framework.Assert.AreEqual(2, entity2.GetOtherInfo().Count);
            NUnit.Framework.Assert.AreEqual("domain id 1", entity2.GetDomainId());
        }
Exemplo n.º 2
0
        public virtual void TestMapInterfaceOrTimelineRecords()
        {
            TimelineEntity entity = new TimelineEntity();
            IList <IDictionary <string, ICollection <object> > > primaryFiltersList = new AList <IDictionary
                                                                                                 <string, ICollection <object> > >();

            primaryFiltersList.AddItem(Sharpen.Collections.SingletonMap("pkey", Sharpen.Collections
                                                                        .Singleton((object)"pval")));
            IDictionary <string, ICollection <object> > primaryFilters = new SortedDictionary <string
                                                                                               , ICollection <object> >();

            primaryFilters["pkey1"] = Sharpen.Collections.Singleton((object)"pval1");
            primaryFilters["pkey2"] = Sharpen.Collections.Singleton((object)"pval2");
            primaryFiltersList.AddItem(primaryFilters);
            entity.SetPrimaryFilters(null);
            foreach (IDictionary <string, ICollection <object> > primaryFiltersToSet in primaryFiltersList)
            {
                entity.SetPrimaryFilters(primaryFiltersToSet);
                AssertPrimaryFilters(entity);
                IDictionary <string, ICollection <object> > primaryFiltersToAdd = new WeakHashMap <string
                                                                                                   , ICollection <object> >();
                primaryFiltersToAdd["pkey3"] = Sharpen.Collections.Singleton((object)"pval3");
                entity.AddPrimaryFilters(primaryFiltersToAdd);
                AssertPrimaryFilters(entity);
            }
            IList <IDictionary <string, ICollection <string> > > relatedEntitiesList = new AList <IDictionary
                                                                                                  <string, ICollection <string> > >();

            relatedEntitiesList.AddItem(Sharpen.Collections.SingletonMap("rkey", Sharpen.Collections
                                                                         .Singleton("rval")));
            IDictionary <string, ICollection <string> > relatedEntities = new SortedDictionary <string
                                                                                                , ICollection <string> >();

            relatedEntities["rkey1"] = Sharpen.Collections.Singleton("rval1");
            relatedEntities["rkey2"] = Sharpen.Collections.Singleton("rval2");
            relatedEntitiesList.AddItem(relatedEntities);
            entity.SetRelatedEntities(null);
            foreach (IDictionary <string, ICollection <string> > relatedEntitiesToSet in relatedEntitiesList)
            {
                entity.SetRelatedEntities(relatedEntitiesToSet);
                AssertRelatedEntities(entity);
                IDictionary <string, ICollection <string> > relatedEntitiesToAdd = new WeakHashMap <string
                                                                                                    , ICollection <string> >();
                relatedEntitiesToAdd["rkey3"] = Sharpen.Collections.Singleton("rval3");
                entity.AddRelatedEntities(relatedEntitiesToAdd);
                AssertRelatedEntities(entity);
            }
            IList <IDictionary <string, object> > otherInfoList = new AList <IDictionary <string,
                                                                                          object> >();

            otherInfoList.AddItem(Sharpen.Collections.SingletonMap("okey", (object)"oval"));
            IDictionary <string, object> otherInfo = new SortedDictionary <string, object>();

            otherInfo["okey1"] = "oval1";
            otherInfo["okey2"] = "oval2";
            otherInfoList.AddItem(otherInfo);
            entity.SetOtherInfo(null);
            foreach (IDictionary <string, object> otherInfoToSet in otherInfoList)
            {
                entity.SetOtherInfo(otherInfoToSet);
                AssertOtherInfo(entity);
                IDictionary <string, object> otherInfoToAdd = new WeakHashMap <string, object>();
                otherInfoToAdd["okey3"] = "oval3";
                entity.AddOtherInfo(otherInfoToAdd);
                AssertOtherInfo(entity);
            }
            TimelineEvent @event = new TimelineEvent();
            IList <IDictionary <string, object> > eventInfoList = new AList <IDictionary <string,
                                                                                          object> >();

            eventInfoList.AddItem(Sharpen.Collections.SingletonMap("ekey", (object)"eval"));
            IDictionary <string, object> eventInfo = new SortedDictionary <string, object>();

            eventInfo["ekey1"] = "eval1";
            eventInfo["ekey2"] = "eval2";
            eventInfoList.AddItem(eventInfo);
            @event.SetEventInfo(null);
            foreach (IDictionary <string, object> eventInfoToSet in eventInfoList)
            {
                @event.SetEventInfo(eventInfoToSet);
                AssertEventInfo(@event);
                IDictionary <string, object> eventInfoToAdd = new WeakHashMap <string, object>();
                eventInfoToAdd["ekey3"] = "eval3";
                @event.AddEventInfo(eventInfoToAdd);
                AssertEventInfo(@event);
            }
        }