Skip to content

Commit

Permalink
Add a common tests to veify content of different type of records
Browse files Browse the repository at this point in the history
  • Loading branch information
mhshams committed Jan 6, 2022
1 parent cbffc9f commit bdb7fac
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 130 deletions.
11 changes: 9 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@
</distributionManagement>

<properties>
<junit.version>4.13.2</junit.version>
<jackson.version>2.13.1</jackson.version>
<maven.compiler.verison>3.8.1</maven.compiler.verison>
<maven.source.verison>3.2.0</maven.source.verison>
<maven.javadoc.verison>3.3.1</maven.javadoc.verison>
<maven.gpg.verison>3.0.1</maven.gpg.verison>
<moditect.version>1.0.0.RC2</moditect.version>
<junit.version>4.13.2</junit.version>
<assertj.version>3.19.0</assertj.version>
<jackson.version>2.13.1</jackson.version>
</properties>

<dependencies>
Expand All @@ -66,6 +67,12 @@
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
133 changes: 133 additions & 0 deletions src/test/java/org/jnbis/records/CommonRecordsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package org.jnbis.records;

import org.jnbis.FileUtils;
import org.jnbis.api.Jnbis;
import org.jnbis.api.model.Nist;
import org.jnbis.api.model.record.SignatureImage;
import org.jnbis.api.model.record.TransactionInformation;
import org.jnbis.api.model.record.UserDefinedTestingImage;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.io.File;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;

/**
* @author TeeSofteis
*/

@RunWith(Parameterized.class)
public class CommonRecordsTest {

@Parameterized.Parameters(name = "{index}: {0}")
public static Collection<File> data() {
File[] files = new File(FileUtils.absolute("ansi/references"))
.listFiles((f, name) -> name.endsWith(".an2"));

assert files != null;
return Arrays.asList(files);
}

private final File file;

public CommonRecordsTest(File file) {
this.file = file;
}

@Test
public void verify() {
Nist decoded = Jnbis.nist().decode(file);

verifyUserDefinedFields(decoded);
verifyTransactionInfo(decoded);

verifySignatureImageIfPresent(decoded.getSignatures());
verifyUserDefinedTestingImageIfPresent(decoded.getUserDefinedTestingImages());

verifyOtherCollections(decoded);
}

private void verifyUserDefinedFields(Nist decoded) {
assertThat(decoded.getUserDefinedTexts()).hasSize(1);
Map<Integer, String> fields = decoded.getUserDefinedTexts().get(0).getUserDefinedFields();

assertThat(fields.get(0)).isNull();
assertThat(fields.get(1)).isIn("55", "57");
assertThat(fields.get(2)).isEqualTo("00");
assertThat(fields.get(3)).isIn(
"two chinese characters: 華裔",
"domain defined text place holder");

}

private void verifyTransactionInfo(Nist decoded) {
TransactionInformation info = decoded.getTransactionInfo();

assertThat(info).isNotNull();
assertThat(info.getLogicalRecordLength()).isBetween("158", "273");
assertThat(info.getTypeOfTransaction()).isIn("AMN", "FAUF", "CAR", "ABC");
assertThat(info.getDestinationAgencyId()).isIn("DAI000000", "Wallace");
assertThat(info.getOriginatingAgencyId()).isIn("MDNISTIMG", "Gormit");
}

private void verifyOtherCollections(Nist decoded) {
assertThat(decoded.getLowResGrayscaleFingerprints().size()).isIn(0, 1, 14);
assertThat(decoded.getHiResGrayscaleFingerprints().size()).isIn(0, 1, 2, 4, 14);
assertThat(decoded.getLowResBinaryFingerprints().size()).isIn(0, 1);
assertThat(decoded.getHiResBinaryFingerprints().size()).isIn(0, 1);
assertThat(decoded.getUserDefinedImages().size()).isIn(0, 1);
assertThat(decoded.getSignatures().size()).isIn(0, 1);
assertThat(decoded.getMinutiaeData().size()).isIn(0, 1, 2);
assertThat(decoded.getFacialAndSmtImages().size()).isIn(0, 1, 2, 6);
assertThat(decoded.getVariableResLatentImages().size()).isIn(0, 1, 5);
assertThat(decoded.getVariableResFingerprints().size()).isIn(0, 1, 2, 3, 5, 14);
assertThat(decoded.getVariableResPalmprints().size()).isIn(0, 2);
assertThat(decoded.getUserDefinedTestingImages().size()).isIn(0, 1);
assertThat(decoded.getIrisImages().size()).isIn(0, 1);
}

private void verifySignatureImageIfPresent(List<SignatureImage> images) {
if (images.isEmpty()) return;

SignatureImage image = images.get(0);
assertThat(image.getLogicalRecordLength()).isIn("48474", "455", "36012");
assertThat(image.getImageDesignationCharacter()).isEqualTo("1");
assertThat(image.getImageScanningResolution()).isEqualTo("1");
assertThat(image.getSignatureType()).isEqualTo("0");
assertThat(image.getSignatureRepresentationType()).isIn("0", "1");
}

private void verifyUserDefinedTestingImageIfPresent(List<UserDefinedTestingImage> images) {
if (images.isEmpty()) return;

UserDefinedTestingImage image = images.get(0);

assertThat(image.getLogicalRecordLength()).isEqualTo("4733");
assertThat(image.getImageDesignationCharacter()).isEqualTo("01");
assertThat(image.getScaleUnits()).isEqualTo("1");
assertThat(image.getHorizontalPixelScale()).isEqualTo("1");
assertThat(image.getVerticalPixelScale()).isEqualTo("1");
assertThat(image.getBitsPerPixel()).isEqualTo("24");

Map<Integer, String> userDefinedFields = image.getUserDefinedFields();
assertThat(userDefinedFields).hasSize(4);

// Tag 16.003
assertThat(userDefinedFields.get(3)).isEqualTo("Wallace\u001FGromit\u001FMcGraw");

// Tag 16.004
assertThat(userDefinedFields.get(4)).isEqualTo("Shaun\u001EPreston\u001EPiella Backleicht");

// Tag 16.005
assertThat(userDefinedFields.get(5)).isEqualTo("single value");

// Tag 16.013
assertThat(userDefinedFields.get(13)).isEqualTo("A1\u001FB1\u001FC1\u001EA2\u001FB2\u001FC2\u001EA3\u001FB3\u001FC3");
}
}
52 changes: 0 additions & 52 deletions src/test/java/org/jnbis/records/SignatureImageTest.java

This file was deleted.

76 changes: 0 additions & 76 deletions src/test/java/org/jnbis/records/UserDefinedTestingImageTest.java

This file was deleted.

0 comments on commit bdb7fac

Please sign in to comment.