Class CruTs2pt1SupplierTest

java.lang.Object
io.github.ajevans.dbcode.filesuppliers.CruTs2pt1SupplierTest

@TestInstance(PER_CLASS)
@TestMethodOrder(org.junit.jupiter.api.MethodOrderer.OrderAnnotation.class)
@DisplayName("Unit tests for CruTs2pt1Supplier, minus GUI")
public class CruTs2pt1SupplierTest
extends Object
Unit tests for CruTs2pt1Supplier, minus GUI.

Tests were built for edge conditions for a few specific methods, but the most significant tests run through a full file load.

Reads defaults and first and last lines from application.properties to allow for simple replacement of data for fundamental tests.

JUnit 5.

Note: because of the nature of the exception testing these tests only work with the English language localisation.

Author:
Andy Evans
Version: 1.0 01 Mar 2021
  • Field Details

    • propertiesDirectory

      private String propertiesDirectory
      Directory for properties files.
    • defaultDatabaseDirectory

      private String defaultDatabaseDirectory
      Directory database is in - gained from properties.
    • defaultFileDirectory

      private String defaultFileDirectory
      Directory files are in - gained from properties.
    • defaultDataset

      private String defaultDataset
      Default database name - gained from properties.
    • defaultTable

      private String defaultTable
      Default table name - gained from properties.
    • defaultTableOriginal

      private String defaultTableOriginal
      Default table name without characters removed - gained from properties.
    • defaultSource

      private String defaultSource
      Default source file - gained from properties.
    • defaultDatasetOriginal

      private String defaultDatasetOriginal
      Default source file without characters removed - gained from properties.
    • defaultSource1stLine

      private String defaultSource1stLine
      Default source file - gained from properties.
    • defaultSourceLastLine

      private String defaultSourceLastLine
      Default source file - gained from properties.
    • store

      private String store
      Database location - constructed from default variables.
    • defaultSourceCount

      private int defaultSourceCount
      Record count in default source.
    • dataSupplier

      private CruTs2pt1Supplier dataSupplier
      Data supplier to use.
    • dataConsumer

      private DerbyConsumer dataConsumer
      Data consumer to use.
  • Constructor Details

    • CruTs2pt1SupplierTest

      public CruTs2pt1SupplierTest()
  • Method Details

    • loadData

      @BeforeAll @DisplayName("Load data") void loadData()
      Runs the application to build data files. Uses default locations from the app's META-INF/application.properties file.
    • connectAndProcess

      private void connectAndProcess​(String filename) throws Exception
      Connects to a file and processes it.

      Uses classLoader.getResource() so file must be in test "resources" directory.

      Parameters:
      filename - The filename to connect to.
      Throws:
      Exception - A wide variety of exceptions - see exception tests.
    • disconnect

      @AfterAll @DisplayName("Releases file") public void disconnect()
      Releases file.
    • initialisationlTest

      @Order(1) @Test @DisplayName("(initialisation) -> record count estimation") public void initialisationlTest()
      This is largely checked in the full runthrough, but here we check the estimate.
    • missingHeaderTest

      @Order(2) @Test @DisplayName("(initialisation) missing header -> exception") public void missingHeaderTest()
      Test for data with missing header.

      Unfortunately, as the end point of a wide variety of exceptions, the data linker throws generic Exceptions for the GUI to pick up and display. However, the internal messages vary, so we can test those.

    • missingDataTest

      @Order(3) @Test @DisplayName("(initialisation) missing data -> exception") public void missingDataTest()
      Test for file with missing data.

      Unfortunately, as the end point of a wide variety of exceptions, the data linker throws generic Exceptions for the GUI to pick up and display. However, the internal messages vary, so we can test those.

    • missingDataValueTest

      @Order(4) @Test @DisplayName("(initialisation) missing data value -> exception") public void missingDataValueTest()
      Test for file with a missing data value.

      Unfortunately, as the end point of a wide variety of exceptions, the data linker throws generic Exceptions for the GUI to pick up and display. However, the internal messages vary, so we can test those.

    • extraDataValueTest

      @Order(5) @Test @DisplayName("(initialisation) extra // long data -> exception") public void extraDataValueTest()
      Test for file with an extra long line or extra data value.

      Unfortunately, as the end point of a wide variety of exceptions, the data linker throws generic Exceptions for the GUI to pick up and display. However, the internal messages vary, so we can test those.

    • invalidDateTest

      @Order(6) @Test @DisplayName("(initialisation) invalid date -> exception") public void invalidDateTest()
      Test for header with invalid date, e.g. 32/13/2004.

      Unfortunately, as the end point of a wide variety of exceptions, the data linker throws generic Exceptions for the GUI to pick up and display. However, the internal messages vary, so we can test those.

    • longDataValuesTest

      @Order(7) @Test @DisplayName("(initialisation) long but ok data -> no exception") public void longDataValuesTest()
      Test for file with a correct five significant figures running into each other.

      This should not throw an exception as data is width (not space) delimited.