Class ContentVerifier

Object
ContentVerifier

public class ContentVerifier extends Object
Verification operations that compare metadata or CRS properties against the expected values. The metadata or CRS to verify (typically read from a dataset) is specified by a call to one of the addMetadataToVerify(…) methods. The expected metadata values are specified by calls to addExpectedValues(…) methods. After the expected and actual values have been specified, they can be compared by a call to assertMetadataEquals().
Since:
3.1
  • Constructor Details

    • ContentVerifier

      public ContentVerifier()
      Creates a new dataset content verifier.
  • Method Details

    • clear

      public void clear()
      Resets this verifier to the same state than after construction. This method can be invoked for reusing the same verifier with different metadata objects.
    • addPropertyToIgnore

      public void addPropertyToIgnore(Class<?> type, String property)
      Adds a metadata property to ignore. The property is identified by a GeoAPI interface and the UML identifier of a property in that interface. Properties to ignore must be declared before to invoke addMetadataToVerify(…).
      Parameters:
      type - GeoAPI interface containing the property to ignore.
      property - UML identifier of a property in the given interface.
    • addMetadataToVerify

      public void addMetadataToVerify(Metadata actual)
      Stores all properties of the given metadata, for later comparison against expected values. If this method is invoked more than once, then the given metadata objects shall not provide values for the same properties (unless the values are equal, or unless clear() has been invoked).
      Parameters:
      actual - the metadata read from a dataset, or null if none.
      Throws:
      IllegalStateException - if the given metadata contains a property already found in a previous call to this method, and the values found in those two invocations are not equal.
    • addMetadataToVerify

      public void addMetadataToVerify(CoordinateReferenceSystem actual)
      Stores all properties of the given CRS, for later comparison against expected values. In this class, a Coordinate Reference System is considered as a kind of metadata. If this method is invoked more than once, then the given CRS objects shall not provide values for the same properties (unless the values are equal, or unless clear() has been invoked).
      Parameters:
      actual - the CRS read from a dataset, or null if none.
      Throws:
      IllegalStateException - if the given CRS contains a property already found in a previous call to this method, and the values found in those two invocations are not equal.
    • addExpectedValue

      public void addExpectedValue(String path, Object expectedValue)
      Adds the expected metadata value for the given path. The path is a string like the following examples ([0] is the index of an element in lists or collections):
      • "identificationInfo[0].citation.identifier[0].code"
      • "spatialRepresentationInfo[0].axisDimensionProperties[0].dimensionSize"
      The expectedValue argument is the expected values for the properties identified by the path.
      Parameters:
      path - path to the property to verify.
      expectedValue - the expected values of property identified by the path.
      Throws:
      IllegalArgumentException - if a different value is already declared for the given path.
    • addExpectedValues

      public void addExpectedValues(String path, Object expectedValue, Object... others)
      Adds the expected metadata values for the given paths. The path argument identifies a metadata element like the following examples ([0] is the index of an element in lists or collections):
      • "identificationInfo[0].citation.identifier[0].code"
      • "spatialRepresentationInfo[0].axisDimensionProperties[0].dimensionSize"
      The value argument is the expected value for the property identified by the path.
      Parameters:
      path - path of the property to compare.
      expectedValue - expected value for the property at the given path.
      others - other (path, expectedValue) pairs.
      Throws:
      ClassCastException - if an others element for a path is not a String instance.
      IllegalArgumentException - if a path is already associated to a different value.
    • addExpectedValues

      public void addExpectedValues(Map<String,?> expected)
      Adds the expected metadata values for the given paths. For each entry in the map, the key is a path to a metadata element like the following examples ([0] is the index of an element in lists or collections):
      • "identificationInfo[0].citation.identifier[0].code"
      • "spatialRepresentationInfo[0].axisDimensionProperties[0].dimensionSize"
      Values in the map are the expected values for the properties identified by the keys.
      Parameters:
      expected - the expected values of properties identified by the keys.
      Throws:
      IllegalArgumentException - if a path is already associated to a different value.
    • compareMetadata

      public boolean compareMetadata()
      Compares actual metadata properties against the expected values given in a map. The addMetadataToVerify(…) and addExpectedValues(…) methods must be invoked before this method. Comparison result can be viewed after this method call with toString().
      Returns:
      true if all properties match, with no missing property and no unexpected property.
    • assertMetadataEquals

      public void assertMetadataEquals()
      Asserts that actual metadata properties are equal to the expected values. The addMetadataToVerify(…) and addExpectedValues(…) methods must be invoked before this method. If there is any mismatched, missing or unexpected value, then the assertion fails with an error message listing all differences found.
    • toString

      public String toString()
      Returns a string representation of the comparison results. This method formats up to three blocks in a JSON-like format:
      • List of actual values that do no match the expected values.
      • List of expected values that are missing in the actual values.
      • List of actual values that were unexpected.
      Overrides:
      toString in class Object
      Returns:
      a string representation of the comparison results.