Example #1
0
        public void Run(CommandLineOptions options)
        {
            try
            {
                var arkade = new Core.Arkade();

                var fileInfo = new FileInfo(options.Archive);
                Log.Information($"Processing archive: {fileInfo.FullName}");

                if (!Enum.TryParse(options.ArchiveType, true, out ArchiveType archiveType))
                {
                    Log.Error("Unknown archive type");
                    throw new ArgumentException("unknown archive type");
                }

                TestSession testSession = CreateTestSession(options, arkade, archiveType);

                var archiveMetadata = JsonConvert.DeserializeObject <ArchiveMetadata>(File.ReadAllText(options.MetadataFile));

                testSession.ArchiveMetadata = archiveMetadata;

                arkade.CreatePackage(testSession, PackageType.SubmissionInformationPackage, options.OutputDirectory);

                arkade.SaveReport(testSession, PrepareTestReportFile(options, testSession));
            }
            finally
            {
                ArkadeProcessingArea.CleanUp();
            }
        }
        public void ProcessingAreaIsDestroyed()
        {
            ArkadeProcessingArea.Establish(_locationPath);
            ArkadeProcessingArea.RootDirectory.Exists.Should().BeTrue();

            ArkadeProcessingArea.Destroy();
            ArkadeProcessingArea.RootDirectory.Exists.Should().BeFalse();
        }
        public void ProcessingAreaIsEstablished()
        {
            ArkadeProcessingArea.Establish(_locationPath);

            ArkadeProcessingArea.Location.FullName.Should().Be(_locationPath);
            ArkadeProcessingArea.RootDirectory.FullName.Should().Be(_locationPath + "\\Arkade");
            ArkadeProcessingArea.WorkDirectory.FullName.Should().Be(_locationPath + "\\Arkade\\work");
            ArkadeProcessingArea.LogsDirectory.FullName.Should().Be(_locationPath + "\\Arkade\\logs");
        }
Example #4
0
        public static void Main(string[] args)
        {
            ArkadeProcessingArea.SetupTemporaryLogsDirectory();

            ConfigureLogging(); // Configured with temporary log directory

            Parser.Default.ParseArguments <CommandLineOptions>(args)
            .WithParsed(RunOptionsAndReturnExitCode)
            .WithNotParsed(HandleParseError);
        }
Example #5
0
        public void TestReportAndPackageIsCreatedRunningN5Archive()
        {
            // Establish/clear needed paths:

            string workingDirectoryPath  = AppDomain.CurrentDomain.BaseDirectory;
            string testDataDirectoryPath = Path.Combine(workingDirectoryPath, "TestData");
            string metadataFilePath      = Path.Combine(testDataDirectoryPath, "metadata.txt");
            string archiveDirectoryPath  = Path.Combine(testDataDirectoryPath, "N5-archive");
            string outputDirectoryPath   = Path.Combine(testDataDirectoryPath, "output");

            // Clear needed paths:

            File.Delete(metadataFilePath);

            if (Directory.Exists(outputDirectoryPath))
            {
                Directory.Delete(outputDirectoryPath, true);
            }
            Directory.CreateDirectory(outputDirectoryPath);

            // Run commands and store results:

            Program.Main(new[]
            {
                "-g", metadataFilePath,
                "-p", testDataDirectoryPath
            });

            bool metadataWasGenerated = File.Exists(metadataFilePath);

            Program.Main(new[]
            {
                "-a", archiveDirectoryPath,
                "-t", "noark5",
                "-m", metadataFilePath,
                "-p", testDataDirectoryPath,
                "-o", outputDirectoryPath
            });

            FileSystemInfo[] outputDirectoryItems = new DirectoryInfo(outputDirectoryPath).GetFileSystemInfos();
            bool             testReportWasCreated = outputDirectoryItems.Any(item => item.Name.StartsWith("Arkaderapport"));
            bool             packageWasCreated    = outputDirectoryItems.Any(item => item.Name.StartsWith("Arkadepakke"));

            // Clean up:

            File.Delete(metadataFilePath);
            Directory.Delete(outputDirectoryPath, true);
            ArkadeProcessingArea.Destroy();

            // Control results:

            metadataWasGenerated.Should().BeTrue();
            testReportWasCreated.Should().BeTrue();
            packageWasCreated.Should().BeTrue();
        }
Example #6
0
        public void ShouldReadSmallVersionOfJegerregisteret98()
        {
            ArkadeProcessingArea.Establish(Path.Combine(Environment.CurrentDirectory, "TestData"));

            ArchiveFile archive = ArchiveFile.Read("..\\..\\TestData\\tar\\jegerregisteret98-small\\20b5f34c-4411-47c3-a0f9-0a8bca631603.tar", ArchiveType.Fagsystem);

            Arkade.Core.Base.Arkade arkade     = new Arkade.Core.Base.Arkade();
            TestSession             testSesson = arkade.RunTests(archive);

            testSesson.Should().NotBeNull();
            TestSuite testSuite = testSesson.TestSuite;

            testSuite.Should().NotBeNull();
        }
        public void ProcessingAreaIsCleanedUp()
        {
            ArkadeProcessingArea.Establish(_locationPath);

            // CREATE SOME WORK-FILES:

            // Create a file in the work-directory:
            new FileInfo(Path.Combine(ArkadeProcessingArea.WorkDirectory.FullName, "someFile.txt")).Create().Close();
            // Create a folder in the work-directory:
            DirectoryInfo workDirectorySubDirectory = ArkadeProcessingArea.WorkDirectory.CreateSubdirectory("someFolder");

            // Create a file in the sub-directory of the work-directory:
            new FileInfo(Path.Combine(workDirectorySubDirectory.FullName, "someOtherFile.txt")).Create().Close();
            // Confirm that the test-files have been created:
            ArkadeProcessingArea.WorkDirectory.GetFiles("*", SearchOption.AllDirectories).Length.Should().Be(2);

            // CREATE SOME LOG-FILES:

            string nowDate = DateTime.Now.ToString("yyyyMMdd");
            string oldDate = DateTime.Now.AddDays(-7).ToString("yyyyMMdd"); // Date one week ago

            string fileNameNewLog      = $"arkade-{nowDate}.log";
            string fileNameOldLog      = $"arkade-{oldDate}.log";
            string fileNameNewErrorLog = $"arkade-error-{nowDate}235959.log";
            string fileNameOldErrorLog = $"arkade-error-{oldDate}235959.log";

            // Create a new log file in the logs-directory:
            new FileInfo(Path.Combine(ArkadeProcessingArea.LogsDirectory.FullName, fileNameNewLog)).Create().Close();
            // Create an old log file in the logs-directory:
            new FileInfo(Path.Combine(ArkadeProcessingArea.LogsDirectory.FullName, fileNameOldLog)).Create().Close();
            // Create a new error log file in the logs-directory:
            new FileInfo(Path.Combine(ArkadeProcessingArea.LogsDirectory.FullName, fileNameNewErrorLog)).Create().Close();
            // Create an old error log file in the logs-directory:
            new FileInfo(Path.Combine(ArkadeProcessingArea.LogsDirectory.FullName, fileNameOldErrorLog)).Create().Close();
            // Confirm that the test-files have been created:
            ArkadeProcessingArea.LogsDirectory.GetFiles().Length.Should().Be(4);

            // RUN CLEANUP AND INSPECT:

            ArkadeProcessingArea.CleanUp();

            // Work-directory are removed:
            ArkadeProcessingArea.WorkDirectory.Exists.Should().BeFalse();
            // Old logs are removed, new logs are kept:
            ArkadeProcessingArea.LogsDirectory.GetFiles().Should().Contain(log => log.Name.Equals(fileNameNewLog));
            ArkadeProcessingArea.LogsDirectory.GetFiles().Should().NotContain(log => log.Name.Equals(fileNameOldLog));
            // Old error logs are removed, new error logs are kept:
            ArkadeProcessingArea.LogsDirectory.GetFiles().Should().Contain(log => log.Name.Equals(fileNameNewErrorLog));
            ArkadeProcessingArea.LogsDirectory.GetFiles().Should().NotContain(log => log.Name.Equals(fileNameOldErrorLog));
        }
        public void ProcessingAreaIsEstablishedWithMissingLocation()
        {
            try
            {
                ArkadeProcessingArea.Establish("");
            }
            catch (Exception exception)
            {
                exception.GetType().Should().Be(typeof(ArgumentException));
                exception.Message.Should().Be("Unable to establish processing area in: " + "");
            }

            ProcessingAreaIsSetupWithTemporaryLogsDirectoryOnly().Should().BeTrue();
        }
Example #9
0
        public void Run(CommandLineOptions options)
        {
            try
            {
                var arkade = new Core.Base.Arkade();

                var fileInfo = new FileInfo(options.Archive);
                Log.Information($"Processing archive: {fileInfo.FullName}");

                if (!Enum.TryParse(options.ArchiveType, true, out ArchiveType archiveType))
                {
                    Log.Error("Unknown archive type");
                    throw new ArgumentException("unknown archive type");
                }

                if (archiveType == ArchiveType.Noark4)
                {
                    Log.Error("Archive type Noark 4 is currently not supported");
                    throw new ArgumentException("unsupported archive type");
                }

                TestSession testSession = CreateTestSession(options, arkade, archiveType);

                if (!TestingIsSkipped(options))
                {
                    arkade.RunTests(testSession);
                    SaveTestReport(arkade, testSession, options);
                }

                if (!PackingIsSkipped(options))
                {
                    ArchiveMetadata archiveMetadata = MetadataLoader.Load(options.MetadataFile);

                    archiveMetadata.PackageType = options.InformationPackageType != null &&
                                                  options.InformationPackageType.Equals("AIP")
                        ? PackageType.ArchivalInformationPackage
                        : PackageType.SubmissionInformationPackage;

                    testSession.ArchiveMetadata    = archiveMetadata;
                    testSession.ArchiveMetadata.Id = $"UUID:{testSession.Archive.Uuid}";

                    arkade.CreatePackage(testSession, options.OutputDirectory);
                }
            }
            finally
            {
                ArkadeProcessingArea.CleanUp();
            }
        }
Example #10
0
        protected override void OnExit(ExitEventArgs e)
        {
            _log.Information("Arkade " + ArkadeVersion.Current + " stopping");

            if (!ArkadeProcessingAreaLocationSetting.IsApplied())
            {
                ArkadeProcessingArea.Destroy();
            }

            else if (ArkadeInstance.IsOnlyInstance)
            {
                ArkadeProcessingArea.CleanUp();
            }

            base.OnExit(e);
        }
Example #11
0
        public App()
        {
            try
            {
                ArkadeProcessingArea.Establish(Settings.Default.ArkadeProcessingAreaLocation);
            }
            catch (Exception e)
            {
                Trace.WriteLine("Exception while establishing arkade processing area: " + e.Message);
            }

            LogConfiguration.ConfigureSeriLog();
            _log = Log.ForContext <App>();
            // For some reason this will not work for exceptions thrown from inside the Views.
            AppDomain.CurrentDomain.UnhandledException += MyHandler;
        }
        public void ProcessingAreaIsEstablishedWithInvalidLocation()
        {
            string nonExistingLocation = Path.Combine(Environment.CurrentDirectory, "TestData", "NonExistingDirectory");

            try
            {
                ArkadeProcessingArea.Establish(nonExistingLocation);
            }
            catch (Exception exception)
            {
                exception.GetType().Should().Be(typeof(ArgumentException));
                exception.Message.Should().Be("Unable to establish processing area in: " + nonExistingLocation);

                exception.InnerException?.GetType().Should().Be(typeof(IOException));
                exception.InnerException?.Message.Should().Be("Non existing path: " + nonExistingLocation);
            }

            ProcessingAreaIsSetupWithTemporaryLogsDirectoryOnly().Should().BeTrue();
        }
Example #13
0
        public void Test1()
        {
            ArkadeProcessingArea.Establish(Path.Combine(Environment.CurrentDirectory, "TestData"));

            ArchiveFile archive1 =
                ArchiveFile.Read(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "/TestData/tar/Noark3-eksempel-1/c3db9d4e-720c-4f75-bfb6-de90231dc44c.tar", ArchiveType.Noark3);

            Arkade.Core.Arkade arkade     = new Arkade.Core.Arkade();
            TestSession        testSesson = arkade.RunTests(archive1);

            testSesson.Should().NotBeNull();
            TestSuite testSuite = testSesson.TestSuite;

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

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

            analyseFindMinMaxValues.Count.Should().Be(1);
        }
Example #14
0
        private static void RunOptionsAndReturnExitCode(CommandLineOptions options)
        {
            ArkadeProcessingArea.Establish(options.ProcessingArea); // Removes temporary log directory

            ConfigureLogging();                                     // Re-configured with log directory within processing area

            if (ValidArgumentsForMetadataCreation(options))
            {
                new MetadataExampleGenerator().Generate(options.GenerateMetadataExample);
            }
            else
            {
                if (ValidArgumentsForTesting(options))
                {
                    new CommandLineRunner().Run(options);
                }
                else
                {
                    Console.WriteLine(options.GetUsage());
                }
            }
        }
Example #15
0
        public void Test1()
        {
            ArkadeProcessingArea.Establish(Path.Combine(Environment.CurrentDirectory, "TestData"));

            ArchiveFile archive1 =
                ArchiveFile.Read(AppDomain.CurrentDomain.BaseDirectory + "\\TestData\\tar\\Noark3-eksempel-1\\c3db9d4e-720c-4f75-bfb6-de90231dc44c.tar", ArchiveType.Noark3);

            Arkade.Core.Base.Arkade arkade     = new Arkade.Core.Base.Arkade();
            TestSession             testSesson = arkade.RunTests(archive1);

            testSesson.Should().NotBeNull();
            TestSuite testSuite = testSesson.TestSuite;

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

            var            analyseFindMinMaxValuesTestId = new TestId(TestId.TestKind.Addml, 9);
            List <TestRun> analyseFindMinMaxValues       = testSuite.TestRuns
                                                           .Where(run => run.TestId.Equals(analyseFindMinMaxValuesTestId))
                                                           .ToList();

            analyseFindMinMaxValues.Count.Should().Be(1);
        }