From e1495f609512a4d54e929b58e3ce10501eae5b31 Mon Sep 17 00:00:00 2001 From: t-ober <63147366+t-ober@users.noreply.github.com> Date: Tue, 15 Jun 2021 11:38:54 +0200 Subject: [PATCH 1/3] test for nulls and empty strings --- .../input/AssetInputEntityFactoryTest.groovy | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/test/groovy/edu/ie3/datamodel/io/factory/input/AssetInputEntityFactoryTest.groovy b/src/test/groovy/edu/ie3/datamodel/io/factory/input/AssetInputEntityFactoryTest.groovy index 191560ce0..94b29b916 100644 --- a/src/test/groovy/edu/ie3/datamodel/io/factory/input/AssetInputEntityFactoryTest.groovy +++ b/src/test/groovy/edu/ie3/datamodel/io/factory/input/AssetInputEntityFactoryTest.groovy @@ -53,6 +53,39 @@ class AssetInputEntityFactoryTest extends Specification implements FactoryTestHe } } + def "An AssetInputFactory should parse a valid operated AssetInput correctly (nulls and empty strings)"() { + given: "a system participant input type factory and model data" + def inputFactory = new TestAssetInputFactory() + Map parameter = [ + "uuid": "91ec3bcf-1777-4d38-af67-0bf7c9fa73c7", + "operatesfrom" : operatesfrom, + "operatesuntil": operatesuntil, + "id" : "TestID" + ] + def inputClass = TestAssetInput + def operatorInput = Mock(OperatorInput) + + when: + Optional input = inputFactory.get(new AssetInputEntityData(parameter, inputClass, operatorInput)) + + then: + input.present + input.get().getClass() == inputClass + ((TestAssetInput) input.get()).with { + assert uuid == UUID.fromString(parameter["uuid"]) + assert operationTime == OperationTime.notLimited() + assert operator == operatorInput + assert id == parameter["id"] + } + + where: + operatesfrom | operatesuntil + null | null + "" | null + null | "" + "" | "" + } + def "An AssetInputFactory should parse a valid operated AssetInput correctly (operation start time provided)"() { given: "a system participant input type factory and model data" def inputFactory = new TestAssetInputFactory() From 4c857f494952c19946bad388f48960edac31a25b Mon Sep 17 00:00:00 2001 From: t-ober <63147366+t-ober@users.noreply.github.com> Date: Tue, 15 Jun 2021 12:00:40 +0200 Subject: [PATCH 2/3] adjust test text --- .../io/factory/input/AssetInputEntityFactoryTest.groovy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/groovy/edu/ie3/datamodel/io/factory/input/AssetInputEntityFactoryTest.groovy b/src/test/groovy/edu/ie3/datamodel/io/factory/input/AssetInputEntityFactoryTest.groovy index 94b29b916..d072393f5 100644 --- a/src/test/groovy/edu/ie3/datamodel/io/factory/input/AssetInputEntityFactoryTest.groovy +++ b/src/test/groovy/edu/ie3/datamodel/io/factory/input/AssetInputEntityFactoryTest.groovy @@ -53,14 +53,14 @@ class AssetInputEntityFactoryTest extends Specification implements FactoryTestHe } } - def "An AssetInputFactory should parse a valid operated AssetInput correctly (nulls and empty strings)"() { + def "An AssetInputFactory should parse a valid operated AssetInput correctly (with nulls and empty strings)"() { given: "a system participant input type factory and model data" def inputFactory = new TestAssetInputFactory() Map parameter = [ "uuid": "91ec3bcf-1777-4d38-af67-0bf7c9fa73c7", "operatesfrom" : operatesfrom, "operatesuntil": operatesuntil, - "id" : "TestID" + "id" : "TestID"git ] def inputClass = TestAssetInput def operatorInput = Mock(OperatorInput) From 3772013b302de24c67f6cc6c5038dff10cf19625 Mon Sep 17 00:00:00 2001 From: t-ober <63147366+t-ober@users.noreply.github.com> Date: Tue, 15 Jun 2021 14:22:56 +0200 Subject: [PATCH 3/3] adjust docs --- docs/readthedocs/models/models.rst | 6 ++++++ .../io/factory/input/AssetInputEntityFactoryTest.groovy | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/readthedocs/models/models.rst b/docs/readthedocs/models/models.rst index f7fb1c80a..62d55420b 100644 --- a/docs/readthedocs/models/models.rst +++ b/docs/readthedocs/models/models.rst @@ -80,6 +80,12 @@ Equality Checks If you think you would benefit from such a method, please consider handing in an issue `here `_. +Conditional Parameters + Some of the models have conditional parameters. When reading model data from a data source, their respective factories for building these + models can handle nulls and empty Strings (as well as any combination of those) safely. E.g.: When given parameters for a line's + :code:`operationTime` where :code:`operationStartTime` and :code:`operationEndTime` are both :code:`null` or :code:`""`, the + factory will build an always-on line model. + ***** Input ***** diff --git a/src/test/groovy/edu/ie3/datamodel/io/factory/input/AssetInputEntityFactoryTest.groovy b/src/test/groovy/edu/ie3/datamodel/io/factory/input/AssetInputEntityFactoryTest.groovy index d072393f5..eae4638a3 100644 --- a/src/test/groovy/edu/ie3/datamodel/io/factory/input/AssetInputEntityFactoryTest.groovy +++ b/src/test/groovy/edu/ie3/datamodel/io/factory/input/AssetInputEntityFactoryTest.groovy @@ -60,7 +60,7 @@ class AssetInputEntityFactoryTest extends Specification implements FactoryTestHe "uuid": "91ec3bcf-1777-4d38-af67-0bf7c9fa73c7", "operatesfrom" : operatesfrom, "operatesuntil": operatesuntil, - "id" : "TestID"git + "id" : "TestID" ] def inputClass = TestAssetInput def operatorInput = Mock(OperatorInput)