From b1bcc22d718a18b361b8175a7fafee9813ef33be Mon Sep 17 00:00:00 2001 From: Simon Weiser <5929283+simonweiser@users.noreply.github.com> Date: Fri, 11 Jan 2019 17:46:08 +0100 Subject: [PATCH 1/2] Add transactionId to validation method of StartTransactionConfirmation --- .../core/StartTransactionConfirmation.java | 1 + .../StartTransactionConfirmationTest.java | 30 +++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/StartTransactionConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/StartTransactionConfirmation.java index 516e36a0a..5847ccd17 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/StartTransactionConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/StartTransactionConfirmation.java @@ -49,6 +49,7 @@ public boolean validate() { boolean valid = true; if (valid &= idTagInfo != null) valid &= idTagInfo.validate(); + valid &= transactionId != null; return valid; } diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/StartTransactionConfirmationTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/StartTransactionConfirmationTest.java index a0eb96b86..4a91ded5b 100644 --- a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/StartTransactionConfirmationTest.java +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/StartTransactionConfirmationTest.java @@ -77,7 +77,33 @@ public void validate_returnFalse() { } @Test - public void validate_idTagInfoAndTransactionIdIsSet_idTagInfoIsValidated() throws Exception { + public void validate_idTagInfoIsNotSetAndTransactionIdIsSet_returnFalse() { + // Given + confirmation.setTransactionId(42); + + // When + boolean isValid = confirmation.validate(); + + // Then + assertThat(isValid, is(false)); + } + + @Test + public void validate_idTagInfoIsSetAndTransactionIdIsNotSet_returnFalse() { + // Given + IdTagInfo idTagInfo = mock(IdTagInfo.class); + when(idTagInfo.validate()).thenReturn(true); + confirmation.setIdTagInfo(idTagInfo); + + // When + boolean isValid = confirmation.validate(); + + // Then + assertThat(isValid, is(false)); + } + + @Test + public void validate_idTagInfoAndTransactionIdIsSet_idTagInfoIsValidated() { // Given confirmation.setTransactionId(42); IdTagInfo idTagInfo = mock(IdTagInfo.class); @@ -91,7 +117,7 @@ public void validate_idTagInfoAndTransactionIdIsSet_idTagInfoIsValidated() throw } @Test - public void validate_idTagInfoAndTransactionIdIsSet_returnTrue() throws Exception { + public void validate_idTagInfoAndTransactionIdIsSet_returnTrue() { // Given confirmation.setTransactionId(42); IdTagInfo idTagInfo = mock(IdTagInfo.class); From 588d6aa460300d7ea3097e303bf4f53e8c8a395b Mon Sep 17 00:00:00 2001 From: Simon Weiser <5929283+simonweiser@users.noreply.github.com> Date: Tue, 12 Feb 2019 18:01:29 +0100 Subject: [PATCH 2/2] Set transactionId when creating new StartTransactionConfirmation for integration tests --- .../src/main/java/eu/chargetime/ocpp/test/DummyHandlers.java | 1 + 1 file changed, 1 insertion(+) diff --git a/ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/DummyHandlers.java b/ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/DummyHandlers.java index e7bb13286..3e781474c 100644 --- a/ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/DummyHandlers.java +++ b/ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/DummyHandlers.java @@ -111,6 +111,7 @@ public StartTransactionConfirmation handleStartTransactionRequest(UUID sessionIn StartTransactionConfirmation confirmation = new StartTransactionConfirmation(); confirmation.setIdTagInfo(tagInfo); + confirmation.setTransactionId(42); return failurePoint(confirmation); }