From 84d7ed8e6556526292183524e5e8eb62ac850345 Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Sat, 12 Dec 2020 15:33:00 +0100 Subject: [PATCH] Added method to getting app states --- .../com/plannaplan/entities/AppConfig.java | 24 +++ .../java/com/plannaplan/types/AppState.java | 5 + .../plannaplan/entities/AppConfigTest.java | 141 ++++++++++++++++++ .../cas/CustomUAMCasValidatorTest.java | 12 +- 4 files changed, 178 insertions(+), 4 deletions(-) create mode 100755 buisnesslogic/src/main/java/com/plannaplan/types/AppState.java create mode 100755 buisnesslogic/src/test/java/com/plannaplan/entities/AppConfigTest.java diff --git a/buisnesslogic/src/main/java/com/plannaplan/entities/AppConfig.java b/buisnesslogic/src/main/java/com/plannaplan/entities/AppConfig.java index 49a035f..6487691 100755 --- a/buisnesslogic/src/main/java/com/plannaplan/entities/AppConfig.java +++ b/buisnesslogic/src/main/java/com/plannaplan/entities/AppConfig.java @@ -9,6 +9,7 @@ import javax.persistence.GenerationType; import javax.persistence.Id; import com.plannaplan.models.TourData; +import com.plannaplan.types.AppState; /** * entity that keeps app configurations @@ -91,4 +92,27 @@ public class AppConfig { return configDate; } + /** + * current state getter + * + * @return AppState of app at the moment of calling method + */ + public AppState getCurrentState() { + final Date now = new Date(System.currentTimeMillis()); + if (this.secondTourEnd.before(now)) { + return AppState.NO_TOUR; + } + if (this.secondTourStart.before(now)) { + return AppState.SECOND_TOUR; + } + if (this.firstTourEnd.before(now)) { + return AppState.NO_TOUR; + } + if (this.firstTourStart.before(now)) { + return AppState.FIRST_TOUR; + } + + return AppState.NO_TOUR; + } + } diff --git a/buisnesslogic/src/main/java/com/plannaplan/types/AppState.java b/buisnesslogic/src/main/java/com/plannaplan/types/AppState.java new file mode 100755 index 0000000..3feacef --- /dev/null +++ b/buisnesslogic/src/main/java/com/plannaplan/types/AppState.java @@ -0,0 +1,5 @@ +package com.plannaplan.types; + +public enum AppState { + FIRST_TOUR, SECOND_TOUR, NO_TOUR +} diff --git a/buisnesslogic/src/test/java/com/plannaplan/entities/AppConfigTest.java b/buisnesslogic/src/test/java/com/plannaplan/entities/AppConfigTest.java new file mode 100755 index 0000000..a280c22 --- /dev/null +++ b/buisnesslogic/src/test/java/com/plannaplan/entities/AppConfigTest.java @@ -0,0 +1,141 @@ +package com.plannaplan.entities; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.sql.Date; + +import com.plannaplan.models.TourData; +import com.plannaplan.types.AppState; + +import org.junit.Test; + +public class AppConfigTest { + + private static long ONE_DAY = 86400000; + + @Test + public void shouldReturnNoTourDueToTooEarly() { + final Date firtstTourStart = new Date(System.currentTimeMillis() + ONE_DAY); + final Date firtstTourEnd = new Date(System.currentTimeMillis() + 2 * ONE_DAY); + final Date secondTourStart = new Date(System.currentTimeMillis() + 3 * ONE_DAY); + final Date secondTourEnd = new Date(System.currentTimeMillis() + 4 * ONE_DAY); + + final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd), + new TourData(secondTourStart, secondTourEnd)); + assertTrue(config.getCurrentState() == AppState.NO_TOUR); + } + + @Test + public void shouldReturnFirstTourDueToStart() throws InterruptedException { + final Date firtstTourStart = new Date(System.currentTimeMillis()); + final Date firtstTourEnd = new Date(System.currentTimeMillis() + 2 * ONE_DAY); + final Date secondTourStart = new Date(System.currentTimeMillis() + 3 * ONE_DAY); + final Date secondTourEnd = new Date(System.currentTimeMillis() + 4 * ONE_DAY); + + final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd), + new TourData(secondTourStart, secondTourEnd)); + Thread.sleep(1000); + assertTrue(config.getCurrentState() == AppState.FIRST_TOUR); + } + + @Test + public void shouldReturnFirstTourDueToInBetween() { + final Date firtstTourStart = new Date(System.currentTimeMillis() - ONE_DAY); + final Date firtstTourEnd = new Date(System.currentTimeMillis() + 2 * ONE_DAY); + final Date secondTourStart = new Date(System.currentTimeMillis() + 3 * ONE_DAY); + final Date secondTourEnd = new Date(System.currentTimeMillis() + 4 * ONE_DAY); + + final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd), + new TourData(secondTourStart, secondTourEnd)); + assertTrue(config.getCurrentState() == AppState.FIRST_TOUR); + } + + @Test + public void shouldReturnNoTourInLastDay() throws InterruptedException { + final Date firtstTourStart = new Date(System.currentTimeMillis() - ONE_DAY); + final Date firtstTourEnd = new Date(System.currentTimeMillis()); + final Date secondTourStart = new Date(System.currentTimeMillis() + 3 * ONE_DAY); + final Date secondTourEnd = new Date(System.currentTimeMillis() + 4 * ONE_DAY); + + final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd), + new TourData(secondTourStart, secondTourEnd)); + Thread.sleep(1000); + assertTrue(config.getCurrentState() == AppState.NO_TOUR); + } + + @Test + public void shouldReturnNoTourInBetween() { + final Date firtstTourStart = new Date(System.currentTimeMillis() - 2 * ONE_DAY); + final Date firtstTourEnd = new Date(System.currentTimeMillis() - ONE_DAY); + final Date secondTourStart = new Date(System.currentTimeMillis() + 3 * ONE_DAY); + final Date secondTourEnd = new Date(System.currentTimeMillis() + 4 * ONE_DAY); + + final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd), + new TourData(secondTourStart, secondTourEnd)); + assertTrue(config.getCurrentState() == AppState.NO_TOUR); + } + + @Test + public void shouldReturnSecondTourInStart() throws InterruptedException { + final Date firtstTourStart = new Date(System.currentTimeMillis() - 2 * ONE_DAY); + final Date firtstTourEnd = new Date(System.currentTimeMillis() - ONE_DAY); + final Date secondTourStart = new Date(System.currentTimeMillis()); + final Date secondTourEnd = new Date(System.currentTimeMillis() + 4 * ONE_DAY); + + final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd), + new TourData(secondTourStart, secondTourEnd)); + Thread.sleep(1000); + assertTrue(config.getCurrentState() == AppState.SECOND_TOUR); + } + + @Test + public void shouldReturnSecondTourInBetween() { + final Date firtstTourStart = new Date(System.currentTimeMillis() - 3 * ONE_DAY); + final Date firtstTourEnd = new Date(System.currentTimeMillis() - 2 * ONE_DAY); + final Date secondTourStart = new Date(System.currentTimeMillis() - ONE_DAY); + final Date secondTourEnd = new Date(System.currentTimeMillis() + 4 * ONE_DAY); + + final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd), + new TourData(secondTourStart, secondTourEnd)); + assertTrue(config.getCurrentState() == AppState.SECOND_TOUR); + } + + @Test + public void shouldReturnNoTourDueToEndSecond() throws InterruptedException { + final Date firtstTourStart = new Date(System.currentTimeMillis() - 3 * ONE_DAY); + final Date firtstTourEnd = new Date(System.currentTimeMillis() - 2 * ONE_DAY); + final Date secondTourStart = new Date(System.currentTimeMillis() - ONE_DAY); + final Date secondTourEnd = new Date(System.currentTimeMillis()); + + final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd), + new TourData(secondTourStart, secondTourEnd)); + Thread.sleep(1000); + assertTrue(config.getCurrentState() == AppState.NO_TOUR); + } + + @Test + public void shouldReturnNoTourAfterSecondEnd() { + final Date firtstTourStart = new Date(System.currentTimeMillis() - 4 * ONE_DAY); + final Date firtstTourEnd = new Date(System.currentTimeMillis() - 3 * ONE_DAY); + final Date secondTourStart = new Date(System.currentTimeMillis() - 2 * ONE_DAY); + final Date secondTourEnd = new Date(System.currentTimeMillis() - ONE_DAY); + + final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd), + new TourData(secondTourStart, secondTourEnd)); + assertTrue(config.getCurrentState() == AppState.NO_TOUR); + } + + @Test + public void shouldReturnSecondTourWhereThereIsABrake() throws InterruptedException { + final Date firtstTourStart = new Date(System.currentTimeMillis() - 4 * ONE_DAY); + final Date firtstTourEnd = new Date(System.currentTimeMillis()); + final Date secondTourStart = new Date(System.currentTimeMillis()); + final Date secondTourEnd = new Date(System.currentTimeMillis() + ONE_DAY); + + final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd), + new TourData(secondTourStart, secondTourEnd)); + Thread.sleep(1000); + assertTrue(config.getCurrentState() == AppState.SECOND_TOUR); + } + +} diff --git a/restservice/src/test/java/com/plannaplan/security/cas/CustomUAMCasValidatorTest.java b/restservice/src/test/java/com/plannaplan/security/cas/CustomUAMCasValidatorTest.java index cab037e..a4de2b7 100755 --- a/restservice/src/test/java/com/plannaplan/security/cas/CustomUAMCasValidatorTest.java +++ b/restservice/src/test/java/com/plannaplan/security/cas/CustomUAMCasValidatorTest.java @@ -1,5 +1,6 @@ package com.plannaplan.security.cas; +import org.junit.Ignore; import org.junit.Test; import org.springframework.beans.factory.annotation.Value; @@ -9,12 +10,15 @@ public class CustomUAMCasValidatorTest { private String serviceUrl; @Test + @Ignore public void shouldValidateWithDomain() { - - CustomUAMCasValidator validator = new CustomUAMCasValidator(serviceUrl, "ST-54649-5x4h09vzUpEIyAGmf1sz-cas.amu.edu.pl"); - - validator.validate(); + // you need to privide fresh ticket to make this test pass that's why it is + // marked as ignored + CustomUAMCasValidator validator = new CustomUAMCasValidator(serviceUrl, + "ST-54649-5x4h09vzUpEIyAGmf1sz-cas.amu.edu.pl"); + + validator.validate(); } }