Beispiel #1
0
        private TestSession NewSession(WorkingDirectory workingDirectory, ArchiveType archiveType, Uuid uuid)
        {
            Archive archive = new Archive(archiveType, uuid, workingDirectory);

            workingDirectory.CopyAddmlFileToAdministrativeMetadata();

            ConvertNoarkihToAddmlIfNoark4(archive);

            var testSession = new TestSession(archive);

            if (archiveType == ArchiveType.Noark5)
            {
                return(testSession);
            }

            ArkadeFile addmlFile = archive.AddmlFile;

            try
            {
                AddmlInfo addml = AddmlUtil.ReadFromFile(addmlFile.FullName);

                var addmlDefinitionParser = new AddmlDefinitionParser(addml, workingDirectory, _statusEventHandler);

                testSession.AddmlDefinition = addmlDefinitionParser.GetAddmlDefinition();
            }
            catch (Exception exception)
            {
                _log.Warning("Reading file " + addmlFile.Name + " failed: " + exception.Message);
            }

            return(testSession);
        }
        public AddmlDefinitionParserTest()
        {
            var       workingDirectory = new WorkingDirectory(new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + "\\..\\..\\TestData\\noark3\\"));
            AddmlInfo addml            = AddmlUtil.ReadFromFile(workingDirectory.Root().WithFile("noark_3_arkivuttrekk_med_prosesser.xml").FullName);

            _parser = new AddmlDefinitionParser(addml, workingDirectory);
        }
Beispiel #3
0
        public AddmlDefinitionParserTest()
        {
            var workingDirectory =
                new WorkingDirectory(new DirectoryInfo(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "/TestData/noark3"));
            AddmlInfo addml = AddmlUtil.ReadFromFile(workingDirectory.Root().WithFile("noark_3_arkivuttrekk_med_prosesser.xml").FullName);

            _parser = new AddmlDefinitionParser(addml, workingDirectory, new StatusEventHandler());
        }
        private static AddmlDefinitionParser SetupParser(string archiveDirectory)
        {
            var workingDirectory =
                new WorkingDirectory(new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + archiveDirectory));
            AddmlInfo addml = AddmlUtil.ReadFromFile(workingDirectory.Root().WithFile("addml.xml").FullName);

            return(new AddmlDefinitionParser(addml, workingDirectory, new StatusEventHandler()));
        }
Beispiel #5
0
        private FlatFile GetDokDat()
        {
            var       workingDirectory = new WorkingDirectory(ArkadeProcessingArea.WorkDirectory, new DirectoryInfo(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\TestData\\noark3"));
            AddmlInfo addml            = AddmlUtil.ReadFromFile(workingDirectory.Content().WithFile("noark_3_arkivuttrekk_med_prosesser.xml").FullName);

            AddmlDefinition addmlDefinition = new AddmlDefinitionParser(addml, workingDirectory, new StatusEventHandler()).GetAddmlDefinition();
            FlatFile        flatFile        = addmlDefinition.GetFlatFiles().Single(file => file.Definition.FileName == "DOK.DAT");

            return(flatFile);
        }
Beispiel #6
0
        private FlatFile GetDokDat()
        {
            var       workingDirectory = new WorkingDirectory(ArkadeConstants.GetArkadeWorkDirectory(), new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + "\\..\\..\\TestData\\noark3\\"));
            AddmlInfo addml            = AddmlUtil.ReadFromFile(workingDirectory.Content().WithFile("noark_3_arkivuttrekk_med_prosesser.xml").FullName);

            AddmlDefinition addmlDefinition = new AddmlDefinitionParser(addml, workingDirectory, new StatusEventHandler()).GetAddmlDefinition();
            FlatFile        flatFile        = addmlDefinition.GetFlatFiles().Single(file => file.Definition.FileName == "DOK.DAT");

            return(flatFile);
        }
        public void ShouldTransformFromNoarkihToAddml()
        {
            string noark4Xml = TestUtil.ReadFromFileInTestDataDir("noark4\\NOARKIH.XML");

            string noark3Xml = NoarkihToAddmlTransformer.Transform(noark4Xml);

            addml addml = AddmlUtil.ReadFromString(noark3Xml);

            addml.Should().NotBeNull();

            addml.dataset[0].flatFiles.flatFile.Length.Should().Be(67);
            addml.dataset[0].flatFiles.flatFileDefinitions.Length.Should().Be(67);
        }
Beispiel #8
0
        private void ConvertNoarkihToAddmlIfNoark4(Archive archive)
        {
            if (archive.ArchiveType != ArchiveType.Noark4)
            {
                return;
            }

            FileInfo addmlFileInContentFolder = archive.WorkingDirectory.Content().WithFile(ArkadeConstants.AddmlXmlFileName);

            if (addmlFileInContentFolder.Exists)
            {
                _log.Information("{0} already exists. XSLT transformation of {1} skipped.",
                                 ArkadeConstants.AddmlXmlFileName, ArkadeConstants.NoarkihXmlFileName);
                return;
            }

            FileInfo noarkihFile = archive.WorkingDirectory.Content().WithFile(ArkadeConstants.NoarkihXmlFileName);

            if (!noarkihFile.Exists)
            {
                Log.Warning("Expected file not found: " + noarkihFile.FullName);

                return;
            }

            string noarkihString = File.ReadAllText(noarkihFile.FullName);

            try
            {
                // TODO: Use stream instead of strings
                string addmlString = NoarkihToAddmlTransformer.Transform(noarkihString);

                // Verify correct ADDML file
                AddmlUtil.ReadFromString(addmlString);

                FileInfo addmlFileToWrite = archive.WorkingDirectory.AdministrativeMetadata().WithFile(ArkadeConstants.AddmlXmlFileName);

                File.WriteAllText(addmlFileToWrite.FullName, addmlString);
                _log.Information("Successfully transformed {0} to {1}.", ArkadeConstants.NoarkihXmlFileName,
                                 ArkadeConstants.AddmlXmlFileName);
            }
            catch (Exception e)
            {
                string message = string.Format(Resources.Messages.Noark4ConvertNoarkihFileError,
                                               ArkadeConstants.NoarkihXmlFileName,
                                               ArkadeConstants.AddmlXmlFileName);

                throw new ArkadeException(message, e);
            }
        }
Beispiel #9
0
        private TestSession NewSession(WorkingDirectory workingDirectory, ArchiveType archiveType, Uuid uuid)
        {
            Archive archive = new Archive(archiveType, uuid, workingDirectory);

            workingDirectory.CopyAddmlFileToAdministrativeMetadata();

            ConvertNoarkihToAddmlIfNoark4(archive);

            var testSession = new TestSession(archive);

            if (archiveType != ArchiveType.Noark5)
            {
                AddmlInfo addml = AddmlUtil.ReadFromFile(archive.GetStructureDescriptionFileName());
                testSession.AddmlDefinition = new AddmlDefinitionParser(addml, workingDirectory).GetAddmlDefinition();
            }

            return(testSession);
        }
Beispiel #10
0
        private TestSession NewSession(WorkingDirectory workingDirectory, ArchiveType archiveType, Uuid uuid)
        {
            Archive archive = new Archive(archiveType, uuid, workingDirectory);

            workingDirectory.CopyAddmlFileToAdministrativeMetadata();

            ConvertNoarkihToAddmlIfNoark4(archive);

            var testSession = new TestSession(archive);

            if (archiveType != ArchiveType.Noark5)
            {
                FileInfo addmlFile = archive.GetStructureDescriptionFile();
                if (addmlFile.Exists) // file does not exist when user want to just do a simple packaging job
                {
                    AddmlInfo addml = AddmlUtil.ReadFromFile(addmlFile.FullName);
                    testSession.AddmlDefinition = new AddmlDefinitionParser(addml, workingDirectory, _statusEventHandler).GetAddmlDefinition();
                }
            }

            return(testSession);
        }
        public void ShouldReturnTestSuiteFromTests()
        {
            var             workingDirectory = new WorkingDirectory(ArkadeConstants.GetArkadeWorkDirectory(), new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + "\\..\\..\\TestData\\noark3\\"));
            AddmlInfo       addml            = AddmlUtil.ReadFromFile(workingDirectory.Root().WithFile("noark_3_arkivuttrekk_med_prosesser.xml").FullName);
            AddmlDefinition addmlDefinition  = new AddmlDefinitionParser(addml, workingDirectory).GetAddmlDefinition();

            var testSession = new TestSession(new Archive(ArchiveType.Noark3, Uuid.Random(), workingDirectory));

            testSession.AddmlDefinition = addmlDefinition;

            var       addmlDatasetTestEngine = new AddmlDatasetTestEngine(new FlatFileReaderFactory(), new AddmlProcessRunner(), new StatusEventHandler());
            TestSuite testSuite = addmlDatasetTestEngine.RunTestsOnArchive(testSession);


            testSuite.Should().NotBeNull();
            testSuite.TestRuns.Should().NotBeNullOrEmpty();

            List <TestRun> analyseFindMinMaxValues = testSuite.TestRuns
                                                     .Where(run => run.TestName == AnalyseFindMinMaxValues.Name)
                                                     .ToList();

            analyseFindMinMaxValues.Count.Should().Be(1);
        }
Beispiel #12
0
        public void ShouldParseNoark4ConvertedArkivuttrekkXml()
        {
            // Code to convert NOARKIH.XML to addml.xml
            //string noarkihString = TestUtil.ReadFromFileInTestDataDir("noark4\\NOARKIH.XML");
            //string addmlString = NoarkihToAddmlTransformer.Transform(noarkihString);

            // File is converted from NOARKIH.XML format

            var testDataDirectory = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + "\\TestData\\noark4");
            var workingDirectory  = new WorkingDirectory(testDataDirectory, testDataDirectory);

            AddmlInfo addml = AddmlUtil.ReadFromFile(workingDirectory.Content().WithFile("addml.xml").FullName);

            AddmlDefinitionParser parser = new AddmlDefinitionParser(addml, workingDirectory, new StatusEventHandler());

            AddmlDefinition addmlDefinition = parser.GetAddmlDefinition();

            List <AddmlFlatFileDefinition> addmlFlatFileDefinitions = addmlDefinition.AddmlFlatFileDefinitions;

            addmlFlatFileDefinitions.Count.Should().Be(63);
            addmlFlatFileDefinitions[0].Name.Should().Be("ORDNPRINSTYPE");
            addmlFlatFileDefinitions[0].FileName.Should().Be("OPRITYP.XML");
            addmlFlatFileDefinitions[0].Encoding.Should().Be(Encodings.ISO_8859_1);
            addmlFlatFileDefinitions[0].RecordSeparator.Should().BeNull();
            addmlFlatFileDefinitions[0].AddmlRecordDefinitions.Count.Should().Be(1);
            AddmlRecordDefinition addmlRecordDefinition = addmlFlatFileDefinitions[0].AddmlRecordDefinitions[0];

            addmlRecordDefinition.Name.Should().Be("ORDNPRINSTYPE");
            List <AddmlFieldDefinition> addmlFieldDefinitions = addmlRecordDefinition.AddmlFieldDefinitions;

            addmlFieldDefinitions.Count.Should().Be(2);
            addmlFieldDefinitions[0].Name.Should().Be("OT.KODE");
            addmlFieldDefinitions[0].Type.Should().Be(StringDataType.Default);
            addmlFieldDefinitions[1].Name.Should().Be("OT.BETEGN");
            addmlFieldDefinitions[1].Type.Should().Be(StringDataType.Default);
            addmlRecordDefinition.PrimaryKey.Should().BeNull();
        }
Beispiel #13
0
        public void ShouldParseJegerreg98ArkivuttrekkXml()
        {
            var       externalContentDirectory = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + "\\..\\..\\TestData\\jegerreg-98-dos\\");
            var       workingDirectory         = new WorkingDirectory(ArkadeConstants.GetArkadeWorkDirectory(), externalContentDirectory);
            AddmlInfo addml = AddmlUtil.ReadFromFile(workingDirectory.Content().WithFile("arkivuttrekk.xml").FullName);

            AddmlDefinition addmlDefinition = new AddmlDefinitionParser(addml, workingDirectory).GetAddmlDefinition();

            List <AddmlFlatFileDefinition> addmlFlatFileDefinitions = addmlDefinition.AddmlFlatFileDefinitions;

            addmlFlatFileDefinitions.Count.Should().Be(10);
            {
                addmlFlatFileDefinitions[0].Name.Should().Be("ffd_3");
                addmlFlatFileDefinitions[0].FileName.Should().Be("jeger.dat");
                addmlFlatFileDefinitions[0].Encoding.Should().Be(Encodings.ISO_8859_1);
                addmlFlatFileDefinitions[0].RecordSeparator.Should().Be(Separator.CRLF);
                addmlFlatFileDefinitions[0].AddmlRecordDefinitions.Count.Should().Be(1);
                AddmlRecordDefinition       addmlRecordDefinition = addmlFlatFileDefinitions[0].AddmlRecordDefinitions[0];
                List <AddmlFieldDefinition> addmlFieldDefinitions = addmlRecordDefinition.AddmlFieldDefinitions;
                addmlFieldDefinitions.Count.Should().Be(36);
                addmlFieldDefinitions[0].Name.Should().Be("fodselsnummer");
                addmlRecordDefinition.PrimaryKey.Should()
                .Equal(new List <AddmlFieldDefinition>()
                {
                    addmlFieldDefinitions[0]
                });
            }
            {
                addmlFlatFileDefinitions[1].Name.Should().Be("ffd_4");
                addmlFlatFileDefinitions[1].FileName.Should().Be("ut_jeger.dat");
                addmlFlatFileDefinitions[1].Encoding.Should().Be(Encodings.ISO_8859_1);
                addmlFlatFileDefinitions[1].RecordSeparator.Should().Be(Separator.CRLF);
                addmlFlatFileDefinitions[1].AddmlRecordDefinitions.Count.Should().Be(1);
                AddmlRecordDefinition       addmlRecordDefinition = addmlFlatFileDefinitions[1].AddmlRecordDefinitions[0];
                List <AddmlFieldDefinition> addmlFieldDefinitions = addmlRecordDefinition.AddmlFieldDefinitions;
                addmlFieldDefinitions.Count.Should().Be(37);
                addmlFieldDefinitions[0].Name.Should().Be("plassnummer");
                addmlFieldDefinitions[0].Type.Should().Be(IntegerDataType.Default);
                addmlFieldDefinitions[1].Name.Should().Be("landkort");
                addmlFieldDefinitions[8].Name.Should().Be("personnummer");
                addmlRecordDefinition.PrimaryKey.Should()
                .Equal(new List <AddmlFieldDefinition>()
                {
                    addmlFieldDefinitions[0],
                    addmlFieldDefinitions[1],
                    addmlFieldDefinitions[8]
                });
            }
            {
                addmlFlatFileDefinitions[2].Name.Should().Be("ffd_5");
                addmlFlatFileDefinitions[2].FileName.Should().Be("ikkejeg.dat");
                addmlFlatFileDefinitions[2].Encoding.Should().Be(Encodings.ISO_8859_1);
                addmlFlatFileDefinitions[2].RecordSeparator.Should().Be(Separator.CRLF);
                addmlFlatFileDefinitions[2].AddmlRecordDefinitions.Count.Should().Be(1);
                AddmlRecordDefinition       addmlRecordDefinition = addmlFlatFileDefinitions[2].AddmlRecordDefinitions[0];
                List <AddmlFieldDefinition> addmlFieldDefinitions = addmlRecordDefinition.AddmlFieldDefinitions;
                addmlFieldDefinitions.Count.Should().Be(44);
                addmlFieldDefinitions[0].Name.Should().Be("fodselsnummer");
                addmlFieldDefinitions[0].StartPosition.Should().Be(1);
                addmlFieldDefinitions[0].FixedLength.Should().Be(11);
                addmlFieldDefinitions[0].IsUnique.Should().BeTrue();
                addmlFieldDefinitions[0].IsNullable.Should().BeFalse();
                addmlFieldDefinitions[0].MaxLength.Should().NotHaveValue();
                addmlFieldDefinitions[0].MinLength.Should().NotHaveValue();
                addmlFieldDefinitions[0].Type.Should().Be(StringDataType.Default);
                addmlFieldDefinitions[0].ForeignKey.Should().Be(
                    addmlFlatFileDefinitions[0].AddmlRecordDefinitions[0].AddmlFieldDefinitions[0]
                    );

                addmlFieldDefinitions[1].Name.Should().Be("etternavn");
                addmlFieldDefinitions[1].StartPosition.Should().Be(12);
                addmlFieldDefinitions[1].FixedLength.Should().Be(25);
                addmlFieldDefinitions[1].IsUnique.Should().BeFalse();
                addmlFieldDefinitions[1].IsNullable.Should().BeTrue();
                addmlFieldDefinitions[1].MaxLength.Should().NotHaveValue();
                addmlFieldDefinitions[1].MinLength.Should().NotHaveValue();
                addmlFieldDefinitions[1].Type.Should().Be(StringDataType.Default);
                addmlFieldDefinitions[1].ForeignKey.Should().BeNull();

                addmlRecordDefinition.PrimaryKey.Should()
                .Equal(new List <AddmlFieldDefinition>()
                {
                    addmlFieldDefinitions[0]
                });


                TestDateDataType(addmlDefinition);
                TestBooleanDataType(addmlDefinition);
                TestFloatDataType(addmlDefinition);
            }
        }
Beispiel #14
0
        public void ShouldParseJegerreg98ArkivuttrekkXml()
        {
            var       externalContentDirectory = new DirectoryInfo(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\TestData\\jegerreg-98-dos");
            var       workingDirectory         = new WorkingDirectory(ArkadeProcessingArea.WorkDirectory, externalContentDirectory);
            AddmlInfo addml = AddmlUtil.ReadFromFile(workingDirectory.Content().WithFile("arkivuttrekk.xml").FullName);

            AddmlDefinition addmlDefinition = new AddmlDefinitionParser(addml, workingDirectory, new StatusEventHandler()).GetAddmlDefinition();

            List <AddmlFlatFileDefinition> addmlFlatFileDefinitions = addmlDefinition.AddmlFlatFileDefinitions;

            addmlFlatFileDefinitions.Count.Should().Be(10);
            {
                addmlFlatFileDefinitions[0].Name.Should().Be("ffd_3");
                addmlFlatFileDefinitions[0].FileName.Should().Be("jeger.dat");
                addmlFlatFileDefinitions[0].Encoding.Should().Be(Encodings.ISO_8859_1);
                addmlFlatFileDefinitions[0].RecordSeparator.Should().Be(Separator.CRLF);
                addmlFlatFileDefinitions[0].AddmlRecordDefinitions.Count.Should().Be(1);
                AddmlRecordDefinition       addmlRecordDefinition = addmlFlatFileDefinitions[0].AddmlRecordDefinitions[0];
                List <AddmlFieldDefinition> addmlFieldDefinitions = addmlRecordDefinition.AddmlFieldDefinitions;
                addmlFieldDefinitions.Count.Should().Be(36);
                addmlFieldDefinitions[0].Name.Should().Be("fodselsnummer");
                addmlRecordDefinition.PrimaryKey.Should()
                .Equal(new List <AddmlFieldDefinition>()
                {
                    addmlFieldDefinitions[0]
                });
            }
            {
                addmlFlatFileDefinitions[1].Name.Should().Be("ffd_4");
                addmlFlatFileDefinitions[1].FileName.Should().Be("ut_jeger.dat");
                addmlFlatFileDefinitions[1].Encoding.Should().Be(Encodings.ISO_8859_1);
                addmlFlatFileDefinitions[1].RecordSeparator.Should().Be(Separator.CRLF);
                addmlFlatFileDefinitions[1].AddmlRecordDefinitions.Count.Should().Be(1);
                AddmlRecordDefinition       addmlRecordDefinition = addmlFlatFileDefinitions[1].AddmlRecordDefinitions[0];
                List <AddmlFieldDefinition> addmlFieldDefinitions = addmlRecordDefinition.AddmlFieldDefinitions;
                addmlFieldDefinitions.Count.Should().Be(37);
                addmlFieldDefinitions[0].Name.Should().Be("plassnummer");
                addmlFieldDefinitions[0].Type.Should().Be(IntegerDataType.Default);
                addmlFieldDefinitions[1].Name.Should().Be("landkort");
                addmlFieldDefinitions[8].Name.Should().Be("personnummer");
                addmlRecordDefinition.PrimaryKey.Should()
                .Equal(new List <AddmlFieldDefinition>()
                {
                    addmlFieldDefinitions[0],
                    addmlFieldDefinitions[1],
                    addmlFieldDefinitions[8]
                });
            }
            {
                addmlFlatFileDefinitions[2].Name.Should().Be("ffd_5");
                addmlFlatFileDefinitions[2].FileName.Should().Be("ikkejeg.dat");
                addmlFlatFileDefinitions[2].Encoding.Should().Be(Encodings.ISO_8859_1);
                addmlFlatFileDefinitions[2].RecordSeparator.Should().Be(Separator.CRLF);
                addmlFlatFileDefinitions[2].AddmlRecordDefinitions.Count.Should().Be(1);
                AddmlRecordDefinition       addmlRecordDefinition = addmlFlatFileDefinitions[2].AddmlRecordDefinitions[0];
                List <AddmlFieldDefinition> addmlFieldDefinitions = addmlRecordDefinition.AddmlFieldDefinitions;
                addmlFieldDefinitions.Count.Should().Be(44);
                addmlFieldDefinitions[0].Name.Should().Be("fodselsnummer");
                addmlFieldDefinitions[0].StartPosition.Should().Be(1);
                addmlFieldDefinitions[0].FixedLength.Should().Be(11);
                addmlFieldDefinitions[0].IsUnique.Should().BeTrue();
                addmlFieldDefinitions[0].IsNullable.Should().BeFalse();
                addmlFieldDefinitions[0].MaxLength.Should().NotHaveValue();
                addmlFieldDefinitions[0].MinLength.Should().NotHaveValue();
                addmlFieldDefinitions[0].Type.Should().Be(StringDataType.Default);

                /*              addmlFieldDefinitions[0].ForeignKeys.First().Should().Be(
                 *                addmlFlatFileDefinitions[0].AddmlRecordDefinitions[0].AddmlFieldDefinitions[0]
                 *            );*/

                addmlFieldDefinitions[1].Name.Should().Be("etternavn");
                addmlFieldDefinitions[1].StartPosition.Should().Be(12);
                addmlFieldDefinitions[1].FixedLength.Should().Be(25);
                addmlFieldDefinitions[1].IsUnique.Should().BeFalse();
                addmlFieldDefinitions[1].IsNullable.Should().BeTrue();
                addmlFieldDefinitions[1].MaxLength.Should().NotHaveValue();
                addmlFieldDefinitions[1].MinLength.Should().NotHaveValue();
                addmlFieldDefinitions[1].Type.Should().Be(StringDataType.Default);
//                addmlFieldDefinitions[1].ForeignKeys.Should().BeEmpty();

                addmlRecordDefinition.PrimaryKey.Should()
                .Equal(new List <AddmlFieldDefinition>()
                {
                    addmlFieldDefinitions[0]
                });


                TestDateDataType(addmlDefinition);
                TestBooleanDataType(addmlDefinition);
                TestFloatDataType(addmlDefinition);
            }
        }