Skip to content

Commit

Permalink
Do extensive unit(/integration) testing on documents directory handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jtellnes committed Feb 8, 2018
1 parent 4d6bb3d commit cecfee2
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 20 deletions.
11 changes: 8 additions & 3 deletions src/Arkivverket.Arkade.Test/Arkivverket.Arkade.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
<Compile Include="Core\ArchiveBuilder.cs" />
<Compile Include="Core\ArkadeProcessingAreaTest.cs" />
<Compile Include="Core\ArkadeTestMock.cs" />
<Compile Include="Core\DocumentsDirectoryTest.cs" />
<Compile Include="Core\EncodingsTest.cs" />
<Compile Include="Core\InformationPackageCreatorTest.cs" />
<Compile Include="Core\TestRunBuilder.cs" />
Expand Down Expand Up @@ -344,7 +345,10 @@
<None Include="TestData\Noark5\DocumentfilesControl\CountMismatch\content\dokumenter\5000000.pdf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="TestData\Noark5\DocumentfilesControl\FilesToBeReferenced\content\dokumenter\underkatalog\5000002.pdf">
<None Include="TestData\Noark5\DocumentfilesControl\FilesToBeReferenced\content\DOKUMENT\underkatalog\d.PDF">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="TestData\Noark5\DocumentfilesControl\FilesToBeReferenced\content\DOKUMENT\underkatalog\C.pdf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="TestData\Noark5\DocumentfilesControl\FilesWithDocumentedChecksums\content\dokumenter\5000000.pdf">
Expand All @@ -353,10 +357,10 @@
<None Include="TestData\Noark5\DocumentfilesControl\FilesWithDocumentedChecksums\content\dokumenter\5000001.pdf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="TestData\Noark5\DocumentfilesControl\FilesToBeReferenced\content\dokumenter\5000000.pdf">
<None Include="TestData\Noark5\DocumentfilesControl\FilesToBeReferenced\content\DOKUMENT\a.pdf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="TestData\Noark5\DocumentfilesControl\FilesToBeReferenced\content\dokumenter\5000001.pdf">
<None Include="TestData\Noark5\DocumentfilesControl\FilesToBeReferenced\content\DOKUMENT\B.PDF">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="TestData\Noark5\DocumentfilesControl\MissingDocumentation\content\dokumenter\5000000.pdf">
Expand Down Expand Up @@ -581,6 +585,7 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="TestData\DocumentDirectoryTest\content\" />
<Folder Include="TestData\package-creation\descriptive_metadata\" />
<Folder Include="TestData\tar\Noark3-eksempel-1\" />
</ItemGroup>
Expand Down
108 changes: 108 additions & 0 deletions src/Arkivverket.Arkade.Test/Core/DocumentsDirectoryTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
using System;
using System.IO;
using Arkivverket.Arkade.Core;
using FluentAssertions;
using Xunit;

namespace Arkivverket.Arkade.Test.Core
{
public class DocumentsDirectoryTest
{
private static DirectoryInfo _physicalWorkingDirectory;

public DocumentsDirectoryTest()
{
_physicalWorkingDirectory = new DirectoryInfo(
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestData", "DocumentDirectoryTest")
);

if (!_physicalWorkingDirectory.Exists)
_physicalWorkingDirectory.Create();
}

[Fact]
[Trait("Category", "Integration")]
public void ArhiveDetectsDocumentsDirectoriesWithSupportedNames()
{
// Plural, lowercase documents directory name:
DirectoryInfo documentsDirectoryA = SetupArchiveWithPhysicalDocumentsDirectory("dokumenter");
documentsDirectoryA.Name.Should().Be("dokumenter");
documentsDirectoryA.Exists.Should().BeTrue();

// Plural, uppercase documents directory name:
DirectoryInfo documentsDirectoryB = SetupArchiveWithPhysicalDocumentsDirectory("DOKUMENTER");
documentsDirectoryB.Name.Should().Be("DOKUMENTER");
documentsDirectoryB.Exists.Should().BeTrue();

// Singular, lowercase documents directory name:
DirectoryInfo documentsDirectoryC = SetupArchiveWithPhysicalDocumentsDirectory("dokument");
documentsDirectoryC.Name.Should().Be("dokument");
documentsDirectoryC.Exists.Should().BeTrue();

// Singular, uppercase documents directory name:
DirectoryInfo documentsDirectoryD = SetupArchiveWithPhysicalDocumentsDirectory("DOKUMENT");
documentsDirectoryD.Name.Should().Be("DOKUMENT");
documentsDirectoryD.Exists.Should().BeTrue();
}

[Fact]
[Trait("Category", "Integration")]
public void DocumentsDirectoriesWithUnsupportedNamesResultsInFallback()
{
// Mixed case documents directory name:
DirectoryInfo documentsDirectoryA = SetupArchiveWithPhysicalDocumentsDirectory("Dokumenter");
documentsDirectoryA.Name.Should().Be("dokumenter");

// English documents directory name:
DirectoryInfo documentsDirectoryB = SetupArchiveWithPhysicalDocumentsDirectory("documenter");
documentsDirectoryB.Name.Should().Be("dokumenter");
}

[Fact]
[Trait("Category", "Integration")]
public void MissingDocumentsDirectoryResultsInFallback()
{
// Missing documents directory:
DirectoryInfo documentsDirectoryA = SetupArchiveWithPhysicalDocumentsDirectory(string.Empty);
documentsDirectoryA.Name.Should().Be("dokumenter");
documentsDirectoryA.Exists.Should().BeFalse();
}

private static DirectoryInfo SetupArchiveWithPhysicalDocumentsDirectory(string documentsDirectoryName)
{
// Remove any existing document directories:
RemovePhysicalContentsDirectory();

// Make new archive to reset any existing documentsdirectory reference:
Archive archive = SetupArchive();

// Create an actual documentsdirectory for the archive to look for:
CreatePhysicalDocumentsDirectory(documentsDirectoryName);

// Return what the archive has defined as its documentsdirectory:
return archive.GetDocumentsDirectory();
}
private static void RemovePhysicalContentsDirectory()
{
var contentDirectory = new DirectoryInfo(Path.Combine(_physicalWorkingDirectory.FullName, "content"));

if (contentDirectory.Exists)
contentDirectory.Delete(true);
}

private static Archive SetupArchive()
{
return new ArchiveBuilder()
.WithArchiveType(ArchiveType.Noark5)
.WithWorkingDirectoryRoot(_physicalWorkingDirectory.FullName)
.Build();
}

private static void CreatePhysicalDocumentsDirectory(string documentsDirectoryName)
{
Directory.CreateDirectory(
Path.Combine(_physicalWorkingDirectory.FullName, "content", documentsDirectoryName)
);
}
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,44 @@ public class DocumentfilesReferenceControlTest
[Fact]
public void AllFilesAreReferenced()
{
/*
The documents directory does not use the default/fallback name (dokumenter).
One of the references use backslashes in the path.
2 of the referenced files are located in a documents directory subdirectory.
The referenced files have all combinations of lowercase/uppercase in their filename + extension.
*/

XmlElementHelper xmlElementHelper =
new XmlElementHelper().Add("arkiv",
new XmlElementHelper().Add("arkivdel",
new XmlElementHelper().Add("klassifikasjonssystem",
new XmlElementHelper().Add("klasse",
new XmlElementHelper().Add("mappe",
new XmlElementHelper()
.Add("registrering", new[] {"xsi:type", "journalpost"},
.Add("registrering", new[] { "xsi:type", "journalpost" },
new XmlElementHelper().Add("dokumentbeskrivelse",
new XmlElementHelper().Add("dokumentobjekt",
new XmlElementHelper().Add("referanseDokumentfil",
"dokumenter/5000000.pdf"))))
.Add("registrering", new[] {"xsi:type", "journalpost"},
new XmlElementHelper().Add(
"referanseDokumentfil", "DOKUMENT/a.pdf"
))))
.Add("registrering", new[] { "xsi:type", "journalpost" },
new XmlElementHelper().Add("dokumentbeskrivelse",
new XmlElementHelper().Add("dokumentobjekt",
new XmlElementHelper().Add("referanseDokumentfil",
// Backslashed file reference supported:
"dokumenter\\5000001.pdf"))))
new XmlElementHelper().Add(
"referanseDokumentfil", "DOKUMENT\\B.PDF"
))))
.Add("registrering", new[] { "xsi:type", "journalpost" },
new XmlElementHelper().Add("dokumentbeskrivelse",
new XmlElementHelper().Add("dokumentobjekt",
new XmlElementHelper().Add("referanseDokumentfil",
// Subdirectory file reference:
"dokumenter/underkatalog/5000002.pdf")))))))));

new XmlElementHelper().Add(
"referanseDokumentfil", "DOKUMENT/underkatalog/C.pdf"
))))
.Add("registrering", new[] { "xsi:type", "journalpost" },
new XmlElementHelper().Add("dokumentbeskrivelse",
new XmlElementHelper().Add("dokumentobjekt",
new XmlElementHelper().Add(
"referanseDokumentfil", "DOKUMENT/underkatalog/d.PDF"
)))))))));

TestRun testRun = CreateTestRun(xmlElementHelper);

Expand All @@ -52,22 +65,30 @@ public void SomeFilesAreNotReferenced()
new XmlElementHelper().Add("klasse",
new XmlElementHelper().Add("mappe",
new XmlElementHelper()
.Add("registrering", new[] {"xsi:type", "journalpost"},
.Add("registrering", new[] { "xsi:type", "journalpost" },
new XmlElementHelper().Add("dokumentbeskrivelse",
new XmlElementHelper().Add("dokumentobjekt",
new XmlElementHelper().Add(
"referanseDokumentfil", "DOKUMENT/a.pdf"
))))
.Add("registrering", new[] { "xsi:type", "journalpost" },
new XmlElementHelper().Add("dokumentbeskrivelse",
new XmlElementHelper().Add("dokumentobjekt",
new XmlElementHelper().Add("referanseDokumentfil",
"dokumenter/5000000.pdf"))))
new XmlElementHelper().Add(
"referanseDokumentfil", "DOKUMENT\\B.PDF"
))))
.Add("registrering", new[] { "xsi:type", "journalpost" },
new XmlElementHelper().Add("dokumentbeskrivelse",
new XmlElementHelper().Add("dokumentobjekt",
new XmlElementHelper().Add("referanseDokumentfil",
"dokumenter/underkatalog/5000002.pdf")))))))));
new XmlElementHelper().Add(
"referanseDokumentfil", "DOKUMENT/underkatalog/C.pdf"
)))))))));


TestRun testRun = CreateTestRun(xmlElementHelper);

testRun.Results.Should().Contain(r => r.Message.Equals(
"Ikke-referert fil funnet: dokumenter/5000001.pdf")
"Ikke-referert fil funnet: DOKUMENT/underkatalog/d.PDF")
);

testRun.Results.Count.Should().Be(1);
Expand Down

0 comments on commit cecfee2

Please sign in to comment.