aboutsummaryrefslogtreecommitdiffstats
path: root/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/billing/StatusHistoryTest.java
diff options
context:
space:
mode:
authorbjormel <bjormel@yahooinc.com>2023-10-26 13:59:28 +0000
committerbjormel <bjormel@yahooinc.com>2023-10-26 13:59:28 +0000
commit567be9a1f6353cec41c23bfd1fcd46b4b2a4d2d7 (patch)
tree4664a743e166a5e11aee7b9acd70ad8ee2617612 /controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/billing/StatusHistoryTest.java
parente9058b555d4dfea2f6c872d9a677e8678b569569 (diff)
parentbce3b8e926bf9da880172acbe1ba4b12d5e026d6 (diff)
Merge branch 'master' into bjormel/aws-main-controllerbjormel/aws-main-controller
Diffstat (limited to 'controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/billing/StatusHistoryTest.java')
-rw-r--r--controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/billing/StatusHistoryTest.java89
1 files changed, 89 insertions, 0 deletions
diff --git a/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/billing/StatusHistoryTest.java b/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/billing/StatusHistoryTest.java
new file mode 100644
index 00000000000..46a4c7e199c
--- /dev/null
+++ b/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/billing/StatusHistoryTest.java
@@ -0,0 +1,89 @@
+package com.yahoo.vespa.hosted.controller.api.integration.billing;
+
+import org.junit.jupiter.api.Test;
+
+import java.time.Clock;
+import java.time.ZonedDateTime;
+import java.util.Map;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+/**
+ * @author gjoranv
+ */
+public class StatusHistoryTest {
+
+ private final Clock clock = Clock.systemUTC();
+
+ @Test
+ void open_can_change_to_any_status() {
+ var history = StatusHistory.open(clock);
+ history.checkValidTransition(BillStatus.FROZEN);
+ history.checkValidTransition(BillStatus.CLOSED);
+ history.checkValidTransition(BillStatus.VOID);
+ }
+
+ @Test
+ void frozen_cannot_change_to_open() {
+ var history = new StatusHistory(historyWith(BillStatus.FROZEN));
+
+ history.checkValidTransition(BillStatus.CLOSED);
+ history.checkValidTransition(BillStatus.VOID);
+
+ assertThrows(IllegalArgumentException.class, () -> history.checkValidTransition(BillStatus.OPEN));
+ }
+
+ @Test
+ void closed_cannot_change() {
+ var history = new StatusHistory(historyWith(BillStatus.CLOSED));
+
+ assertThrows(IllegalArgumentException.class, () -> history.checkValidTransition(BillStatus.OPEN));
+ assertThrows(IllegalArgumentException.class, () -> history.checkValidTransition(BillStatus.FROZEN));
+ assertThrows(IllegalArgumentException.class, () -> history.checkValidTransition(BillStatus.VOID));
+ }
+
+ @Test
+ void void_cannot_change() {
+ var history = new StatusHistory(historyWith(BillStatus.VOID));
+
+ assertThrows(IllegalArgumentException.class, () -> history.checkValidTransition(BillStatus.OPEN));
+ assertThrows(IllegalArgumentException.class, () -> history.checkValidTransition(BillStatus.FROZEN));
+ assertThrows(IllegalArgumentException.class, () -> history.checkValidTransition(BillStatus.CLOSED));
+ }
+
+ @Test
+ void any_status_can_change_to_itself() {
+ var history = new StatusHistory(historyWith(BillStatus.OPEN));
+ history.checkValidTransition(BillStatus.OPEN);
+
+ history = new StatusHistory(historyWith(BillStatus.FROZEN));
+ history.checkValidTransition(BillStatus.FROZEN);
+
+ history = new StatusHistory(historyWith(BillStatus.CLOSED));
+ history.checkValidTransition(BillStatus.CLOSED);
+
+ history = new StatusHistory(historyWith(BillStatus.VOID));
+ history.checkValidTransition(BillStatus.VOID);
+ }
+
+ @Test
+ void it_validates_status_history_in_constructor() {
+ assertThrows(IllegalArgumentException.class, () -> new StatusHistory(historyWith(BillStatus.FROZEN, BillStatus.OPEN)));
+ assertThrows(IllegalArgumentException.class, () -> new StatusHistory(historyWith(BillStatus.CLOSED, BillStatus.OPEN)));
+ assertThrows(IllegalArgumentException.class, () -> new StatusHistory(historyWith(BillStatus.CLOSED, BillStatus.FROZEN)));
+ assertThrows(IllegalArgumentException.class, () -> new StatusHistory(historyWith(BillStatus.CLOSED, BillStatus.VOID)));
+ assertThrows(IllegalArgumentException.class, () -> new StatusHistory(historyWith(BillStatus.VOID, BillStatus.OPEN)));
+ assertThrows(IllegalArgumentException.class, () -> new StatusHistory(historyWith(BillStatus.VOID, BillStatus.FROZEN)));
+ assertThrows(IllegalArgumentException.class, () -> new StatusHistory(historyWith(BillStatus.VOID, BillStatus.CLOSED)));
+ }
+
+ private SortedMap<ZonedDateTime, BillStatus> historyWith(BillStatus... statuses) {
+ var history = new TreeMap<>(Map.of(ZonedDateTime.now(clock), BillStatus.OPEN));
+ for (var status : statuses) {
+ history.put(ZonedDateTime.now(clock), status);
+ }
+ return history;
+ }
+}