Class CruTs2pt1SupplierTest
@TestInstance(PER_CLASS)
@TestMethodOrder(org.junit.jupiter.api.MethodOrderer.OrderAnnotation.class)
@DisplayName("Unit tests for CruTs2pt1Supplier, minus GUI")
public class CruTs2pt1SupplierTest
extends Object
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 Summary
Fields Modifier and Type Field Description private DerbyConsumerdataConsumerData consumer to use.private CruTs2pt1SupplierdataSupplierData supplier to use.private StringdefaultDatabaseDirectoryDirectory database is in - gained from properties.private StringdefaultDatasetDefault database name - gained from properties.private StringdefaultDatasetOriginalDefault source file without characters removed - gained from properties.private StringdefaultFileDirectoryDirectory files are in - gained from properties.private StringdefaultSourceDefault source file - gained from properties.private StringdefaultSource1stLineDefault source file - gained from properties.private intdefaultSourceCountRecord count in default source.private StringdefaultSourceLastLineDefault source file - gained from properties.private StringdefaultTableDefault table name - gained from properties.private StringdefaultTableOriginalDefault table name without characters removed - gained from properties.private StringpropertiesDirectoryDirectory for properties files.private StringstoreDatabase location - constructed from default variables. -
Constructor Summary
Constructors Constructor Description CruTs2pt1SupplierTest() -
Method Summary
Modifier and Type Method Description private voidconnectAndProcess(String filename)Connects to a file and processes it.voiddisconnect()Releases file.voidextraDataValueTest()Test for file with an extra long line or extra data value.voidinitialisationlTest()This is largely checked in the full runthrough, but here we check the estimate.voidinvalidDateTest()Test for header with invalid date, e.g.(package private) voidloadData()Runs the application to build data files.voidlongDataValuesTest()Test for file with a correct five significant figures running into each other.voidmissingDataTest()Test for file with missing data.voidmissingDataValueTest()Test for file with a missing data value.voidmissingHeaderTest()Test for data with missing header.
-
Field Details
-
propertiesDirectory
Directory for properties files. -
defaultDatabaseDirectory
Directory database is in - gained from properties. -
defaultFileDirectory
Directory files are in - gained from properties. -
defaultDataset
Default database name - gained from properties. -
defaultTable
Default table name - gained from properties. -
defaultTableOriginal
Default table name without characters removed - gained from properties. -
defaultSource
Default source file - gained from properties. -
defaultDatasetOriginal
Default source file without characters removed - gained from properties. -
defaultSource1stLine
Default source file - gained from properties. -
defaultSourceLastLine
Default source file - gained from properties. -
store
Database location - constructed from default variables. -
defaultSourceCount
private int defaultSourceCountRecord count in default source. -
dataSupplier
Data supplier to use. -
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
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.
-