Ejemplo n.º 1
0
        public async Task TestPatternWithNonExistingFolder()
        {
            var corpus      = TestHelper.GetLocalCorpus(testsSubpath, "TestPatternWithNonExistingFolder");
            var content     = TestHelper.GetInputFileContent(testsSubpath, "TestPatternWithNonExistingFolder", "entities.manifest.cdm.json");
            var cdmManifest = ManifestPersistence.FromObject(new ResolveContext(corpus, null), "entities", "local", "/", JsonConvert.DeserializeObject <ManifestContent>(content));
            int errorLogged = 0;

            corpus.SetEventCallback(new EventCallback
            {
                Invoke = (CdmStatusLevel statusLevel, string message) =>
                {
                    if (message.Contains("Failed to fetch all files in the folder location 'local:/testLocation' described by a partition pattern. Exception:"))
                    {
                        errorLogged++;
                    }
                }
            }, CdmStatusLevel.Warning);

            await cdmManifest.FileStatusCheckAsync();

            Assert.AreEqual(1, errorLogged);
            Assert.AreEqual(cdmManifest.Entities[0].DataPartitions.Count, 0);
            // make sure the last check time is still being set
            Assert.IsNotNull(cdmManifest.Entities[0].DataPartitionPatterns[0].LastFileStatusCheckTime);
        }
Ejemplo n.º 2
0
        public async Task TestLoadingCdmFolderResultAndModelJsonToData()
        {
            var cdmCorpus = TestHelper.GetLocalCorpus(testsSubpath, nameof(TestLoadingCdmFolderResultAndModelJsonToData));

            var watch       = Stopwatch.StartNew();
            var cdmManifest = await cdmCorpus.FetchObjectAsync <CdmManifestDefinition>($"result.model{PersistenceLayer.ManifestExtension}", cdmCorpus.Storage.FetchRootFolder("local"));

            watch.Stop();
            Assert.Performance(1000, watch.ElapsedMilliseconds, "Loading from data");

            watch.Restart();
            var obtainedModelJson = await ManifestPersistence.ToData(cdmManifest, null, null);

            watch.Stop();
            Assert.Performance(1000, watch.ElapsedMilliseconds, "Parsing to data");

            // remove empty description from entities as they interfere with test.
            obtainedModelJson.Entities.ForEach(RemoveDescriptionFromEntityIfEmpty);
            obtainedModelJson.Description = null;

            Assert.IsNull(cdmManifest.Imports.Item(Constants.FoundationsCorpusPath, checkMoniker: false));
            Assert.AreEqual(1, obtainedModelJson.Imports.Count);
            Assert.AreEqual(Constants.FoundationsCorpusPath, obtainedModelJson.Imports[0].CorpusPath);

            this.HandleOutput(nameof(TestLoadingCdmFolderResultAndModelJsonToData), PersistenceLayer.ModelJsonExtension, obtainedModelJson);
        }
Ejemplo n.º 3
0
        public async Task TestImportsRelativePath()
        {
            // the corpus path in the imports are relative to the document where it was defined.
            // when saving in model.json the documents are flattened to the manifest level
            // so it is necessary to recalculate the path to be relative to the manifest.
            var corpus = this.GetLocalCorpus("notImportantLocation");
            var folder = corpus.Storage.FetchRootFolder("local");

            var manifest          = new CdmManifestDefinition(corpus.Ctx, "manifest");
            var entityDeclaration = manifest.Entities.Add("EntityName", "EntityName/EntityName.cdm.json/EntityName");

            folder.Documents.Add(manifest);

            var entityFolder = folder.ChildFolders.Add("EntityName");

            var document = new CdmDocumentDefinition(corpus.Ctx, "EntityName.cdm.json");

            document.Imports.Add("subfolder/EntityName.cdm.json");
            document.Definitions.Add("EntityName");
            entityFolder.Documents.Add(document);

            var subFolder = entityFolder.ChildFolders.Add("subfolder");

            subFolder.Documents.Add("EntityName.cdm.json");

            var data = await ManifestPersistence.ToData(manifest, null, null);

            Assert.AreEqual(1, data.Entities.Count);
            var imports = data.Entities[0]["cdm:imports"].ToObject <List <Import> >();

            Assert.AreEqual(1, imports.Count);
            Assert.AreEqual("EntityName/subfolder/EntityName.cdm.json", imports[0].CorpusPath);
        }
Ejemplo n.º 4
0
        public void TestToDataPartitionPatternWithIncrementalTrait()
        {
            var  corpus = TestHelper.GetLocalCorpus(testsSubpath, nameof(TestToDataPartitionPatternWithIncrementalTrait), noInputAndOutputFolder: true);
            bool errorMessageVerified = false;

            // not checking the CdmLogCode here as we want to check if this error message constructed correctly for the partition pattern (it shares the same CdmLogCode with partition)
            corpus.SetEventCallback(new EventCallback
            {
                Invoke = (CdmStatusLevel statusLevel, string message) =>
                {
                    if (message.Contains("Failed to persist object 'UpsertPartitionPattern'. " +
                                         "This object contains the trait 'is.partition.incremental', " +
                                         "so it should not be in the collection 'DataPartitionPatterns'. | ToData"))
                    {
                        errorMessageVerified = true;
                    }
                    else
                    {
                        Assert.Fail("Some unexpected failure - " + message);
                    }
                }
            }, CdmStatusLevel.Warning);

            var manifest = new CdmManifestDefinition(corpus.Ctx, "manifest");

            corpus.Storage.FetchRootFolder("local").Documents.Add(manifest);

            var entity = new CdmEntityDefinition(corpus.Ctx, "entityName", null);

            CdmCollectionHelperFunctions.CreateDocumentForEntity(corpus, entity);
            var localizedEntityDeclaration = manifest.Entities.Add(entity);

            var upsertIncrementalPartitionPattern = corpus.MakeObject <CdmDataPartitionPatternDefinition>(CdmObjectType.DataPartitionPatternDef, "UpsertPartitionPattern", false);

            upsertIncrementalPartitionPattern.RootLocation      = "/IncrementalData";
            upsertIncrementalPartitionPattern.SpecializedSchema = "csv";
            upsertIncrementalPartitionPattern.ExhibitsTraits.Add(Constants.IncrementalTraitName, new List <Tuple <string, dynamic> >()
            {
                new Tuple <string, dynamic>("type", CdmIncrementalPartitionType.Upsert.ToString())
            });

            var testingPartitionPattern = corpus.MakeObject <CdmDataPartitionPatternDefinition>(CdmObjectType.DataPartitionPatternDef, "TestingPartitionPattern", false);

            testingPartitionPattern.RootLocation      = "/testingData";
            testingPartitionPattern.SpecializedSchema = "csv";
            localizedEntityDeclaration.DataPartitionPatterns.Add(upsertIncrementalPartitionPattern);
            localizedEntityDeclaration.DataPartitionPatterns.Add(testingPartitionPattern);

            using (Logger.EnterScope(nameof(DataPartitionPatternTest), corpus.Ctx, nameof(TestToDataPartitionPatternWithIncrementalTrait)))
            {
                var manifestData = ManifestPersistence.ToData(manifest, null, null);

                Assert.AreEqual(1, manifestData.Entities.Count);
                var entityData = manifestData.Entities[0];
                Assert.AreEqual(1, entityData.Value <JArray>("dataPartitionPatterns").Count);
                var patternData = entityData.Value <JArray>("dataPartitionPatterns").First;
                Assert.AreEqual("TestingPartitionPattern", patternData.Value <JToken>("name"));
            }
            Assert.IsTrue(errorMessageVerified);
        }
Ejemplo n.º 5
0
        public void TestProgrammaticallyCreatePartitions()
        {
            var corpus = new CdmCorpusDefinition();

            corpus.Storage.Mount("local", new LocalAdapter());
            var manifest = corpus.MakeObject <CdmManifestDefinition>(CdmObjectType.ManifestDef, "manifest");
            var entity   = manifest.Entities.Add("entity");

            var relativePartition = corpus.MakeObject <CdmDataPartitionDefinition>(CdmObjectType.DataPartitionDef, "relative partition");

            relativePartition.Location = "relative/path";
            var absolutePartition = corpus.MakeObject <CdmDataPartitionDefinition>(CdmObjectType.DataPartitionDef, "absolute partition");

            absolutePartition.Location = "local:/absolute/path";

            entity.DataPartitions.Add(relativePartition);
            entity.DataPartitions.Add(absolutePartition);

            var manifestData = ManifestPersistence.ToData(manifest, new ResolveOptions(), new CopyOptions());

            Assert.AreEqual(manifestData.Entities.Count, 1);
            var entityData     = manifestData.Entities[0];
            var partitionsList = entityData.Value <JArray>("dataPartitions");

            Assert.AreEqual(partitionsList.Count, 2);
            var relativePartitionData = partitionsList.First;
            var absolutePartitionData = partitionsList.Last;

            Assert.AreEqual(relativePartitionData.Value <string>("location"), relativePartition.Location);
            Assert.AreEqual(absolutePartitionData.Value <string>("location"), absolutePartition.Location);
        }
Ejemplo n.º 6
0
        public async Task TestFromAndToData()
        {
            var expectedLogCodes = new HashSet <CdmLogCode> {
                CdmLogCode.ErrResolveReferenceFailure
            };
            CdmCorpusDefinition corpus = TestHelper.GetLocalCorpus(testsSubpath, nameof(TestFromAndToData), expectedCodes: expectedLogCodes);

            var folder   = corpus.Storage.FetchRootFolder("local");
            var manifest = await corpus.FetchObjectAsync <CdmManifestDefinition>($"default{PersistenceLayer.ManifestExtension}", folder);

            var actualData = ManifestPersistence.ToData(manifest, null, null);

            foreach (var entity in manifest.Entities)
            {
                await corpus.FetchObjectAsync <CdmEntityDefinition>(entity.EntityPath, manifest);
            }

            corpus.Storage.FetchRootFolder("output").Documents.Add(manifest);
            await manifest.SaveAsAsync($"default{PersistenceLayer.ManifestExtension}", saveReferenced : true);

            TestHelper.AssertCdmLogCodeEquality(corpus, CdmLogCode.ErrResolveReferenceFailure, true);

            var expected_data = TestHelper.GetExpectedOutputFileContent(testsSubpath, nameof(TestFromAndToData), $"default{PersistenceLayer.ManifestExtension}");

            TestHelper.AssertSameObjectWasSerialized(expected_data,
                                                     JsonConvert.SerializeObject(actualData, Formatting.Indented, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            }));
        }
Ejemplo n.º 7
0
        public void TestLoadLocalEntitiyWithDataPartition()
        {
            var content     = TestHelper.GetInputFileContent(testsSubpath, "TestLoadLocalEntityWithDataPartition", "entities.manifest.cdm.json");
            var cdmManifest = ManifestPersistence.FromData(new ResolveContext(new CdmCorpusDefinition(), null), "entities", "testNamespace", "/", JsonConvert.DeserializeObject <ManifestContent>(content));

            Assert.AreEqual(cdmManifest.Entities.Count, 1);
            Assert.AreEqual(cdmManifest.Entities[0].ObjectType, CdmObjectType.LocalEntityDeclarationDef);
            var entity = cdmManifest.Entities[0];

            Assert.AreEqual(entity.DataPartitions.Count, 1);
            var partition = entity.DataPartitions[0];

            Assert.AreEqual(partition.Location, "test/location");
            Assert.AreEqual(TimeUtils.GetFormattedDateString(partition.LastFileModifiedTime), "2008-09-15T23:53:23.000Z");
            Assert.AreEqual(partition.ExhibitsTraits.Count, 1);
            Assert.AreEqual(partition.SpecializedSchema, "teststring");

            var testList = partition.Arguments["test"];

            Assert.AreEqual(testList.Count, 2);
            Assert.AreEqual(testList[0], "something");
            Assert.AreEqual(testList[1], "somethingelse");

            var keyList = partition.Arguments["KEY"];

            Assert.AreEqual(keyList.Count, 1);
            Assert.AreEqual(keyList[0], "VALUE");

            Assert.IsFalse(partition.Arguments.ContainsKey("wrong"));
        }
Ejemplo n.º 8
0
        public async Task TestLoadingAndSavingDateAndTimeDataTypes()
        {
            var cdmCorpus = TestHelper.GetLocalCorpus(testsSubpath, nameof(TestLoadingAndSavingDateAndTimeDataTypes));

            // Load the manifest and resolve it
            var manifest = await cdmCorpus.FetchObjectAsync <CdmManifestDefinition>("local:/default.manifest.cdm.json");

            var resolvedManifest = await manifest.CreateResolvedManifestAsync("resolved", null);

            // Convert loaded manifest to model.json
            var modelJson = await ManifestPersistence.ToData(resolvedManifest, null, null);

            // Verify that the attributes' data types were correctly persisted as "date" and "time"
            Assert.AreEqual("date", modelJson.Entities[0]["attributes"][0]["dataType"].ToString());
            Assert.AreEqual("time", modelJson.Entities[0]["attributes"][1]["dataType"].ToString());

            // Now check that these attributes' data types are still "date" and "time" when loading the model.json back to manifest
            // We first need to create a second adapter to the input folder to fool the OM into thinking it's different
            // This is because there's a bug that currently prevents us from saving and then loading a model.json under the same namespace
            cdmCorpus.Storage.Mount("local2", new LocalAdapter(TestHelper.GetInputFolderPath(testsSubpath, nameof(TestLoadingAndSavingDateAndTimeDataTypes))));

            var manifestFromModelJson = await cdmCorpus.FetchObjectAsync <CdmManifestDefinition>("local2:/model.json");

            var entity = await cdmCorpus.FetchObjectAsync <CdmEntityDefinition>(manifestFromModelJson.Entities[0].EntityPath, manifestFromModelJson);

            // Verify that the attributes' data types were correctly loaded as "date" and "time"
            Assert.AreEqual(CdmDataFormat.Date, (entity.Attributes[0] as CdmTypeAttributeDefinition).DataFormat);
            Assert.AreEqual(CdmDataFormat.Time, (entity.Attributes[1] as CdmTypeAttributeDefinition).DataFormat);
        }
Ejemplo n.º 9
0
        public void TestProgrammaticallyCreatePartitions()
        {
            var corpus   = TestHelper.GetLocalCorpus(testsSubpath, nameof(TestProgrammaticallyCreatePartitions), noInputAndOutputFolder: true);
            var manifest = corpus.MakeObject <CdmManifestDefinition>(CdmObjectType.ManifestDef, "manifest");
            var entity   = manifest.Entities.Add("entity");

            var relativePartition = corpus.MakeObject <CdmDataPartitionDefinition>(CdmObjectType.DataPartitionDef, "relative partition");

            relativePartition.Location = "relative/path";
            relativePartition.Arguments.Add("test1", new List <string>()
            {
                "argument1"
            });
            relativePartition.Arguments.Add("test2", new List <string>()
            {
                "argument2", "argument3"
            });

            var absolutePartition = corpus.MakeObject <CdmDataPartitionDefinition>(CdmObjectType.DataPartitionDef, "absolute partition");

            absolutePartition.Location = "local:/absolute/path";
            // add an empty arguments list to test empty list should not be displayed in ToData json.
            absolutePartition.Arguments.Add("test", new List <string>());

            entity.DataPartitions.Add(relativePartition);
            entity.DataPartitions.Add(absolutePartition);

            var manifestData = ManifestPersistence.ToData(manifest, new ResolveOptions(), new CopyOptions());

            Assert.AreEqual(1, manifestData.Entities.Count);
            var entityData     = manifestData.Entities[0];
            var partitionsList = entityData.Value <JArray>("dataPartitions");

            Assert.AreEqual(2, partitionsList.Count);
            var relativePartitionData = partitionsList.First;
            var absolutePartitionData = partitionsList.Last;

            Assert.AreEqual(relativePartition.Location, relativePartitionData.Value <string>("location"));

            var argumentsList = relativePartitionData.Value <JArray>("arguments");

            Assert.AreEqual(3, argumentsList.Count);
            Assert.AreEqual(2, argumentsList[0].Count());
            Assert.AreEqual("test1", argumentsList[0].Value <string>("name"));
            Assert.AreEqual("argument1", argumentsList[0].Value <string>("value"));
            Assert.AreEqual(2, argumentsList[1].Count());
            Assert.AreEqual("test2", argumentsList[1].Value <string>("name"));
            Assert.AreEqual("argument2", argumentsList[1].Value <string>("value"));
            Assert.AreEqual(2, argumentsList[2].Count());
            Assert.AreEqual("test2", argumentsList[2].Value <string>("name"));
            Assert.AreEqual("argument3", argumentsList[2].Value <string>("value"));

            Assert.AreEqual(absolutePartition.Location, absolutePartitionData.Value <string>("location"));
            // test if empty argument list is set to null
            Assert.IsNull(absolutePartitionData.Value <List <object> >("arguments"));
        }
Ejemplo n.º 10
0
        public async Task TestLoadLegacyEntityDeclaration()
        {
            var content     = TestHelper.GetInputFileContent(testsSubpath, "TestLoadLegacyEntityDeclaration", "entities.manifest.cdm.json");
            var cdmManifest = ManifestPersistence.FromData(new ResolveContext(new CdmCorpusDefinition(), null), "", "", "", JsonConvert.DeserializeObject <ManifestContent>(content));

            // Local entity declaration.
            Assert.AreEqual("testPath", cdmManifest.Entities[0].EntityPath);

            // Referenced entity declaration.
            Assert.AreEqual("Account.cdm.json/Account", cdmManifest.Entities[1].EntityPath);
        }
Ejemplo n.º 11
0
        public async Task TestReferenceModels()
        {
            var corpus = TestHelper.GetLocalCorpus(testsSubpath, nameof(TestReferenceModels));

            var manifest = await corpus.FetchObjectAsync <CdmManifestDefinition>(PersistenceLayer.ModelJsonExtension, corpus.Storage.FetchRootFolder("local"));

            // entity with same modelId but different location
            var referenceEntity1 = new CdmReferencedEntityDeclarationDefinition(corpus.Ctx, "ReferenceEntity1")
            {
                EntityPath = "remote:/contoso/entity1.model.json/Entity1"
            };
            var modelIdTrait1 = referenceEntity1.ExhibitsTraits.Add("is.propertyContent.multiTrait") as CdmTraitReference;

            modelIdTrait1.IsFromProperty = true;
            modelIdTrait1.Arguments.Add("modelId", "f19bbb97-c031-441a-8bd1-61b9181c0b83/1a7ef9c8-c7e8-45f8-9d8a-b80f8ffe4612");
            manifest.Entities.Add(referenceEntity1);

            // entity without modelId but same location
            var referenceEntity2 = new CdmReferencedEntityDeclarationDefinition(corpus.Ctx, "ReferenceEntity2")
            {
                EntityPath = "remote:/contoso/entity.model.json/Entity2"
            };

            manifest.Entities.Add(referenceEntity2);

            // entity with modelId and new location
            var referenceEntity3 = new CdmReferencedEntityDeclarationDefinition(corpus.Ctx, "ReferenceEntity3")
            {
                EntityPath = "remote:/contoso/entity3.model.json/Entity3"
            };
            var modelIdTrait3 = referenceEntity3.ExhibitsTraits.Add("is.propertyContent.multiTrait") as CdmTraitReference;

            modelIdTrait3.IsFromProperty = true;
            modelIdTrait3.Arguments.Add("modelId", "3b2e040a-c8c5-4508-bb42-09952eb04a50");
            manifest.Entities.Add(referenceEntity3);

            // entity with same modelId and same location
            var referenceEntity4 = new CdmReferencedEntityDeclarationDefinition(corpus.Ctx, "ReferenceEntity4")
            {
                EntityPath = "remote:/contoso/entity.model.json/Entity4"
            };
            var modelIdTrait4 = referenceEntity4.ExhibitsTraits.Add("is.propertyContent.multiTrait") as CdmTraitReference;

            modelIdTrait4.IsFromProperty = true;
            modelIdTrait4.Arguments.Add("modelId", "f19bbb97-c031-441a-8bd1-61b9181c0b83/1a7ef9c8-c7e8-45f8-9d8a-b80f8ffe4612");
            manifest.Entities.Add(referenceEntity4);


            var obtainedModelJson = await ManifestPersistence.ToData(manifest, null, null);

            this.HandleOutput(nameof(TestReferenceModels), PersistenceLayer.ModelJsonExtension, obtainedModelJson);
        }
Ejemplo n.º 12
0
        public void TestLoadFolderWithSubFolders()
        {
            var content = TestHelper.GetInputFileContent(testsSubpath, "TestLoadFolderWithSubFolders", "subManifest.manifest.cdm.json");

            var cdmManifest = ManifestPersistence.FromObject(new ResolveContext(new CdmCorpusDefinition(), null), "testEntity", "testNamespace", "/", JsonConvert.DeserializeObject <ManifestContent>(content));

            Assert.AreEqual(cdmManifest.SubManifests.Count, 1);
            var subManifest = cdmManifest.SubManifests[0];

            Assert.AreEqual(subManifest.GetName(), "sub folder declaration");
            Assert.AreEqual(subManifest.Explanation, "test sub explanation");
            Assert.AreEqual(subManifest.Definition, "test definition");
        }
        public void TestLoadReferencedEntity()
        {
            var content     = TestHelper.GetInputFileContent(testsSubpath, "TestLoadReferencedEntity", "entities.manifest.cdm.json");
            var cdmManifest = ManifestPersistence.FromObject(new ResolveContext(new CdmCorpusDefinition(), null), "testEntity", "testNamespace", "/", JsonConvert.DeserializeObject <ManifestContent>(content));

            Assert.AreEqual(cdmManifest.Entities.Count, 1);
            Assert.AreEqual(cdmManifest.Entities[0].ObjectType, CdmObjectType.ReferencedEntityDeclarationDef);
            var entity = cdmManifest.Entities[0];

            Assert.AreEqual(entity.EntityName, "testEntity");
            Assert.AreEqual(entity.Explanation, "test explanation");
            Assert.AreEqual(entity.EntityPath, "testNamespace:/testPath");
            Assert.AreEqual(entity.ExhibitsTraits.Count, 1);
        }
Ejemplo n.º 14
0
        public async Task TestLoadingAndSavingCdmTraits()
        {
            var cdmCorpus = TestHelper.GetLocalCorpus(testsSubpath, nameof(TestLoadingAndSavingCdmTraits));
            var manifest  = await cdmCorpus.FetchObjectAsync <CdmManifestDefinition>("model.json");

            var entity = await cdmCorpus.FetchObjectAsync <CdmEntityDefinition>("someEntity.cdm.json/someEntity");

            Assert.NotNull(entity.ExhibitsTraits.Item("is.CDM.entityVersion"));

            var manifestData = await ManifestPersistence.ToData(manifest, new ResolveOptions(manifest.InDocument), new CopyOptions());

            var versionAnnotation = (manifestData.Entities[0]["annotations"][0]).ToObject <Annotation>();

            Assert.AreEqual("<version>", versionAnnotation.Value);
        }
Ejemplo n.º 15
0
        public void TestManifestWithBlankFields()
        {
            var content     = TestHelper.GetInputFileContent(testsSubpath, "testManifestWithBlankFields", "blank.manifest.cdm.json");
            var cdmManifest = ManifestPersistence.FromObject(new ResolveContext(new CdmCorpusDefinition(), null), "cdmTest", "someNamespace", "/", JsonConvert.DeserializeObject <ManifestContent>(content));

            Assert.IsNull(cdmManifest.Schema);
            Assert.IsNull(cdmManifest.DocumentVersion);
            Assert.AreEqual(TimeUtils.GetFormattedDateString((DateTimeOffset)cdmManifest.LastFileModifiedTime), "2008-09-15T23:53:23.000Z");
            Assert.AreEqual(cdmManifest.Explanation, "test cdm folder for cdm version 1.0+");
            Assert.AreEqual(cdmManifest.Imports.Count, 1);
            Assert.AreEqual(cdmManifest.Imports[0].CorpusPath, "/primitives.cdm.json");
            Assert.AreEqual(cdmManifest.Entities.Count, 0);
            Assert.AreEqual(cdmManifest.ExhibitsTraits.Count, 1);
            Assert.AreEqual(cdmManifest.SubManifests.Count, 0);
        }
Ejemplo n.º 16
0
        public void TestFolioWithEverything()
        {
            var content     = TestHelper.GetInputFileContent(testsSubpath, "TestFolioWithEverything", "complete.folio.cdm.json");
            var cdmManifest = ManifestPersistence.FromData(new ResolveContext(new CdmCorpusDefinition(), null), "docName", "someNamespace", "/", JsonConvert.DeserializeObject <ManifestContent>(content));

            Assert.AreEqual(1, cdmManifest.SubManifests.Count);
            Assert.AreEqual(2, cdmManifest.Entities.Count);
            Assert.AreEqual("cdmTest", cdmManifest.ManifestName);

            content     = TestHelper.GetInputFileContent(testsSubpath, "TestFolioWithEverything", "noname.folio.cdm.json");
            cdmManifest = ManifestPersistence.FromData(new ResolveContext(new CdmCorpusDefinition(), null), "docName.folio.cdm.json", "someNamespace", "/", JsonConvert.DeserializeObject <ManifestContent>(content));
            Assert.AreEqual(1, cdmManifest.SubManifests.Count);
            Assert.AreEqual(2, cdmManifest.Entities.Count);
            Assert.AreEqual("docName", cdmManifest.ManifestName);
        }
Ejemplo n.º 17
0
        public void TestLoadFolderWithNoEntityFolders()
        {
            var content     = TestHelper.GetInputFileContent(testsSubpath, "TestLoadFolderWithNoEntityFolders", "empty.manifest.cdm.json");
            var cdmManifest = ManifestPersistence.FromData(new ResolveContext(new CdmCorpusDefinition(), null), "cdmTest", "someNamespace", "/", JsonConvert.DeserializeObject <ManifestContent>(content));

            Assert.AreEqual(cdmManifest.Schema, "CdmManifestDefinition.cdm.json");
            Assert.AreEqual(cdmManifest.ManifestName, "cdmTest");
            Assert.AreEqual(cdmManifest.JsonSchemaSemanticVersion, "0.9.0");
            Assert.AreEqual(TimeUtils.GetFormattedDateString((DateTimeOffset)cdmManifest.LastFileModifiedTime), "2008-09-15T23:53:23.000Z");
            Assert.AreEqual(cdmManifest.Explanation, "test cdm folder for cdm version 0.9+");
            Assert.AreEqual(cdmManifest.Imports.Count, 1);
            Assert.AreEqual(cdmManifest.Imports[0].CorpusPath, "/primitives.cdm.json");
            Assert.AreEqual(cdmManifest.Entities.Count, 0);
            Assert.AreEqual(cdmManifest.ExhibitsTraits.Count, 1);
            Assert.AreEqual(cdmManifest.SubManifests.Count, 0);
        }
Ejemplo n.º 18
0
        public void TestLoadNoPartition()
        {
            var content     = TestHelper.GetInputFileContent(testsSubpath, "TestLoadNoPartition", "entities.manifest.cdm.json");
            var cdmManifest = ManifestPersistence.FromObject(new ResolveContext(new CdmCorpusDefinition(), null), "", "", "", JsonConvert.DeserializeObject <ManifestContent>(content));

            Assert.AreEqual(1, cdmManifest.Entities.Count);
            Assert.AreEqual(cdmManifest.Entities[0].ObjectType, CdmObjectType.LocalEntityDeclarationDef);
            var entity = cdmManifest.Entities[0];

            Assert.AreEqual("Account", entity.EntityName);
            Assert.AreEqual("Account explanation", entity.Explanation);
            Assert.AreEqual("Account.cdm.json/Account", entity.EntityPath);
            Assert.AreEqual(1, entity.ExhibitsTraits.Count);
            Assert.AreEqual(0, entity.DataPartitions.Count);
            Assert.AreEqual(0, entity.DataPartitionPatterns.Count);
        }
Ejemplo n.º 19
0
        public void TestDataPartitionArgumentsAreSerializedAppropriately()
        {
            var readFile    = TestHelper.GetInputFileContent(testsSubpath, nameof(TestDataPartitionArgumentsAreSerializedAppropriately), "entities.manifest.cdm.json");
            var cdmManifest = ManifestPersistence.FromObject(
                new ResolveContext(new CdmCorpusDefinition(), null), "entities", "testNamespace", "/", JsonConvert.DeserializeObject <ManifestContent>(readFile));
            var obtainedCdmFolder = ManifestPersistence.ToData(cdmManifest, null, null);

            if (doesWriteTestDebuggingFiles)
            {
                TestHelper.WriteActualOutputFileContent(testsSubpath, nameof(TestDataPartitionArgumentsAreSerializedAppropriately),
                                                        "savedManifest.manifest.cdm.json", ModelJsonTestsBase.Serialize(obtainedCdmFolder));
            }
            var expectedOutput = TestHelper.GetExpectedOutputFileContent(testsSubpath, nameof(TestDataPartitionArgumentsAreSerializedAppropriately), "savedManifest.manifest.cdm.json");

            TestHelper.AssertSameObjectWasSerialized(expectedOutput, ModelJsonTestsBase.Serialize(obtainedCdmFolder));
        }
Ejemplo n.º 20
0
        public async Task TestLoadingCdmFolderAndModelJsonToData()
        {
            var cdmCorpus = TestHelper.GetLocalCorpus(testsSubpath, nameof(TestLoadingCdmFolderAndModelJsonToData));

            var watch       = Stopwatch.StartNew();
            var cdmManifest = await cdmCorpus.FetchObjectAsync <CdmManifestDefinition>($"default{PersistenceLayer.ManifestExtension}", cdmCorpus.Storage.FetchRootFolder("local"));

            watch.Stop();
            Assert.Performance(1000, watch.ElapsedMilliseconds, "Loading from data");

            watch.Restart();
            var obtainedModelJson = await ManifestPersistence.ToData(cdmManifest, null, null);

            watch.Stop();
            Assert.Performance(9800, watch.ElapsedMilliseconds, "Parsing to data");

            this.HandleOutput(nameof(TestLoadingCdmFolderAndModelJsonToData), "model.json", obtainedModelJson, isLanguageSpecific: true);
        }
Ejemplo n.º 21
0
        public async Task TestModelJsonFromAndToData()
        {
            var cdmCorpus = TestHelper.GetLocalCorpus(testsSubpath, nameof(TestModelJsonFromAndToData));

            var watch       = Stopwatch.StartNew();
            var cdmManifest = await cdmCorpus.FetchObjectAsync <CdmManifestDefinition>(PersistenceLayer.ModelJsonExtension, cdmCorpus.Storage.FetchRootFolder("local"));

            watch.Stop();
            Assert.Performance(1000, watch.ElapsedMilliseconds, "Loading from data");

            watch.Restart();
            var obtainedModelJson = await ManifestPersistence.ToData(cdmManifest, null, null);

            watch.Stop();
            Assert.Performance(1000, watch.ElapsedMilliseconds, "Parsing to data");

            this.HandleOutput(nameof(TestModelJsonFromAndToData), PersistenceLayer.ModelJsonExtension, obtainedModelJson);
        }
Ejemplo n.º 22
0
        public async Task TestLoadingCdmFolderAndSavingModelJson()
        {
            var cdmCorpus = TestHelper.GetLocalCorpus(testsSubpath, "TestLoadingCdmFolderAndSavingModelJson");

            var watch       = Stopwatch.StartNew();
            var cdmManifest = await cdmCorpus.FetchObjectAsync <CdmManifestDefinition>("default.manifest.cdm.json", cdmCorpus.Storage.FetchRootFolder("local"));

            watch.Stop();
            Assert.Performance(1000, watch.ElapsedMilliseconds, "Loading from data");

            watch.Restart();
            var obtainedModelJson = await ManifestPersistence.ToData(cdmManifest, null, null);

            watch.Stop();
            Assert.Performance(5000, watch.ElapsedMilliseconds, "Parsing to data");

            this.HandleOutput("TestLoadingCdmFolderAndSavingModelJson", "model.json", obtainedModelJson);
        }
Ejemplo n.º 23
0
        public async Task TestRefEntityWithSlashPath()
        {
            var slashCorpus    = TestHelper.GetLocalCorpus(testsSubpath, "TestRefEntityWithSlashPath");
            var slashLocalPath = ((LocalAdapter)slashCorpus.Storage.NamespaceAdapters["local"]).Root;
            var slashAdapter   = new LocalAdapterWithSlashPath(slashLocalPath, "/");

            slashCorpus.Storage.Mount("slash", slashAdapter);
            slashCorpus.Storage.DefaultNamespace = "slash";

            // load model.json files with paths generated using both '/' and '\'
            var slashManifest = await slashCorpus.FetchObjectAsync <CdmManifestDefinition>("slash:/model.json");

            // manually add the reference model location, path will vary on each machine
            var refModelTrait = slashManifest.ExhibitsTraits.Item("is.modelConversion.referenceModelMap") as CdmTraitReference;
            var entityPath    = slashManifest.Entities[0].EntityPath;

            refModelTrait.Arguments[0].Value[0].location = slashAdapter.CreateAdapterPath(entityPath.Substring(0, entityPath.LastIndexOf("/")));

            var slashModel = await ManifestPersistence.ToData(slashManifest, new ResolveOptions(), new CopyOptions());

            Assert.IsNotNull(slashModel);
            Assert.AreEqual(1, slashModel.Entities.Count);

            var backSlashCorpus    = TestHelper.GetLocalCorpus(testsSubpath, "TestRefEntityWithSlashPath");
            var backSlashLocalPath = ((LocalAdapter)backSlashCorpus.Storage.NamespaceAdapters["local"]).Root;
            var backSlashAdapter   = new LocalAdapterWithSlashPath(backSlashLocalPath, "\\");

            backSlashCorpus.Storage.Mount("backslash", backSlashAdapter);
            backSlashCorpus.Storage.DefaultNamespace = "backslash";

            var backSlashManifest = await backSlashCorpus.FetchObjectAsync <CdmManifestDefinition>("backslash:/model.json");

            // manually add the reference model location, path will vary on each machine
            var backSlashRefModelTrait = backSlashManifest.ExhibitsTraits.Item("is.modelConversion.referenceModelMap") as CdmTraitReference;
            var backSlashEntityPath    = backSlashManifest.Entities[0].EntityPath;

            backSlashRefModelTrait.Arguments[0].Value[0].location = backSlashAdapter.CreateAdapterPath(backSlashEntityPath.Substring(0, backSlashEntityPath.LastIndexOf("/")))
                                                                    .Replace("/", "\\\\");

            var backSlashModel = await ManifestPersistence.ToData(backSlashManifest, new ResolveOptions(), new CopyOptions());

            Assert.IsNotNull(backSlashModel);
            Assert.AreEqual(1, backSlashModel.Entities.Count);
        }
Ejemplo n.º 24
0
        public void TestManifestForCopyData()
        {
            var             content        = TestHelper.GetInputFileContent(testsSubpath, "TestManifestForCopyData", "complete.manifest.cdm.json");
            var             cdmManifest    = ManifestPersistence.FromData(new ResolveContext(new CdmCorpusDefinition(), null), "docName", "someNamespace", "/", JsonConvert.DeserializeObject <ManifestContent>(content));
            ManifestContent manifestObject = CdmObjectBase.CopyData(cdmManifest, null, null);

            Assert.AreEqual(manifestObject.Schema, "CdmManifestDefinition.cdm.json");
            Assert.AreEqual(manifestObject.JsonSchemaSemanticVersion, "0.9.0");
            Assert.AreEqual(manifestObject.ManifestName, "cdmTest");
            Assert.AreEqual(manifestObject.Explanation, "test cdm folder for cdm version 0.9+");
            Assert.AreEqual(manifestObject.Imports.Count, 1);
            Assert.AreEqual(manifestObject.Imports[0].CorpusPath, "/primitives.cdm.json");
            Assert.AreEqual(manifestObject.ExhibitsTraits.Count, 1);
            Assert.AreEqual(manifestObject.Entities.Count, 2);
            Assert.AreEqual(manifestObject.Entities[0]["entityName"], "testEntity");
            Assert.AreEqual(manifestObject.SubManifests.Count, 1);
            Assert.AreEqual(manifestObject.SubManifests[0].Definition, "test definition");
            Assert.AreEqual(manifestObject.LastFileModifiedTime, null);
        }
Ejemplo n.º 25
0
        public async Task TestModelJsonExtensibility()
        {
            var cdmCorpus   = TestHelper.GetLocalCorpus(testsSubpath, "TestModelJsonExtensibility");
            var cdmManifest = await cdmCorpus.FetchObjectAsync <CdmManifestDefinition>("model.json", cdmCorpus.Storage.FetchRootFolder("local"));

            var obtainedModel = await ManifestPersistence.ToData(cdmManifest, null, null);

            // The imports were generated during processing and are not present in the original file.
            obtainedModel.Imports = null;

            if (doesWriteTestDebuggingFiles)
            {
                TestHelper.WriteActualOutputFileContent(testsSubpath, "TestModelJsonExtensibility", "SerializerTesting-model.json", Serialize(obtainedModel));
            }
            var obtainedModelJson = Serialize(obtainedModel);

            var originalModelJson = TestHelper.GetExpectedOutputFileContent(testsSubpath, "TestModelJsonExtensibility", "SerializerTesting-model.json");

            TestHelper.AssertSameObjectWasSerialized(originalModelJson, obtainedModelJson);
        }
Ejemplo n.º 26
0
        public void TestLoadNoPartitionAbsoluteNamespaceSet()
        {
            var             content         = TestHelper.GetInputFileContent(testsSubpath, "TestLoadNoPartitionAbsoluteNamespaceSet", "entities.manifest.cdm.json");
            ManifestContent manifestContent = JsonConvert.DeserializeObject <ManifestContent>(content);
            var             cdmManifest     = ManifestPersistence.FromObject(new ResolveContext(new CdmCorpusDefinition(), null), "testEntity", "testNamespace", "/", manifestContent);

            Assert.AreEqual(cdmManifest.Entities.Count, 1);
            Assert.AreEqual(cdmManifest.Entities[0].ObjectType, CdmObjectType.LocalEntityDeclarationDef);
            var entity = cdmManifest.Entities[0];

            Assert.AreEqual("Account", entity.EntityName);
            Assert.AreEqual("Account explanation", entity.Explanation);
            Assert.AreEqual("testNamespace:/Account.cdm.json/Account", entity.EntityPath);
            Assert.AreEqual(1, entity.ExhibitsTraits.Count);
            Assert.AreEqual(0, entity.DataPartitions.Count);
            Assert.AreEqual(0, entity.DataPartitionPatterns.Count);

            var manifestToData = ManifestPersistence.ToData(cdmManifest, null, null);

            Assert.AreEqual("testNamespace:/Account.cdm.json/Account", manifestToData.Entities[0].Value <string>("entityPath"));
        }
Ejemplo n.º 27
0
        public async Task TestSettingModelJsonEntityDescription()
        {
            var cdmCorpus   = new CdmCorpusDefinition();
            var cdmManifest = cdmCorpus.MakeObject <CdmManifestDefinition>(CdmObjectType.ManifestDef, "test");
            var document    = cdmCorpus.MakeObject <CdmDocumentDefinition>(CdmObjectType.DocumentDef, $"entity{PersistenceLayer.CdmExtension}");

            var folder = cdmCorpus.Storage.FetchRootFolder("local");

            folder.Documents.Add(document);

            var entity = document.Definitions.Add(CdmObjectType.EntityDef, "entity") as CdmEntityDefinition;

            entity.Description = "test description";

            cdmManifest.Entities.Add(entity);
            folder.Documents.Add(cdmManifest);

            var obtainedModelJson = await ManifestPersistence.ToData(cdmManifest, null, null);

            Assert.AreEqual("test description", obtainedModelJson.Entities[0]["description"].ToString());
        }
Ejemplo n.º 28
0
        public async Task TestLoadingCdmFolderResultAndSavingModelJson()
        {
            var cdmCorpus = TestHelper.GetLocalCorpus(testsSubpath, "TestLoadingCdmFolderResultAndSavingModelJson");

            var watch       = Stopwatch.StartNew();
            var cdmManifest = await cdmCorpus.FetchObjectAsync <CdmManifestDefinition>("result.model.manifest.cdm.json", cdmCorpus.Storage.FetchRootFolder("local"));

            watch.Stop();
            Assert.Performance(1000, watch.ElapsedMilliseconds, "Loading from data");

            watch.Restart();
            var obtainedModelJson = await ManifestPersistence.ToData(cdmManifest, null, null);

            watch.Stop();
            Assert.Performance(1000, watch.ElapsedMilliseconds, "Parsing to data");

            // remove empty description from entities as they interfere with test.
            obtainedModelJson.Entities.ForEach(RemoveDescriptionFromEntityIfEmpty);
            obtainedModelJson.Description = null;

            this.HandleOutput("TestLoadingCdmFolderResultAndSavingModelJson", "model.json", obtainedModelJson);
        }
        public void TestLoadLocalEntitiyWithDataPartitionPattern()
        {
            var content = TestHelper.GetInputFileContent(testsSubpath, "TestLoadLocalEntityWithDataPartitionPattern", "entities.manifest.cdm.json");

            var cdmManifest = ManifestPersistence.FromObject(new ResolveContext(new CdmCorpusDefinition(), null), "entities", "testNamespace", "/", JsonConvert.DeserializeObject <ManifestContent>(content));

            Assert.AreEqual(cdmManifest.Entities.Count, 1);
            Assert.AreEqual(cdmManifest.Entities[0].ObjectType, CdmObjectType.LocalEntityDeclarationDef);
            var entity = cdmManifest.Entities[0];

            Assert.AreEqual(entity.DataPartitionPatterns.Count, 1);
            var pattern = entity.DataPartitionPatterns[0];

            Assert.AreEqual(pattern.Name, "testPattern");
            Assert.AreEqual(pattern.Explanation, "test explanation");
            Assert.AreEqual(pattern.RootLocation, "test location");
            Assert.AreEqual(pattern.RegularExpression.ToString(), "\\s*");
            Assert.AreEqual(pattern.Parameters.Count, 2);
            Assert.AreEqual(pattern.Parameters[0], "testParam1");
            Assert.AreEqual(pattern.Parameters[1], "testParam2");
            Assert.AreEqual(pattern.SpecializedSchema, "test special schema");
            Assert.AreEqual(pattern.ExhibitsTraits.Count, 1);
        }
Ejemplo n.º 30
0
        public async Task TestLoadingAndSavingCsvPartitionTraits()
        {
            var cdmCorpus = TestHelper.GetLocalCorpus(testsSubpath, nameof(TestLoadingCsvPartitionTraitsFromFileFormatSettings));
            var manifest  = await cdmCorpus.FetchObjectAsync <CdmManifestDefinition>("model.json");

            // If the data partition trait is.partition.format.CSV being saved has arguments that are not supported by fileFormatSettings
            // the trait should also be persisted.
            var manifestData = await ManifestPersistence.ToData(manifest, new ResolveOptions(manifest.InDocument), new CopyOptions());

            var localEntity = manifestData.Entities[0].ToObject <LocalEntity>();

            Assert.AreEqual(1, localEntity.Partitions[0].Traits.Count);

            // Remove the argument that is not supported by fileFormatSettings and check if the trait is removed after that.
            var csvTrait = manifest.Entities[0].DataPartitions[0].ExhibitsTraits[0] as CdmTraitReference;

            csvTrait.Arguments.Remove(csvTrait.Arguments.Item("newline"));

            manifestData = await ManifestPersistence.ToData(manifest, new ResolveOptions(manifest.InDocument), new CopyOptions());

            localEntity = manifestData.Entities[0].ToObject <LocalEntity>();
            Assert.IsNull(localEntity.Partitions[0].Traits);
        }