summaryrefslogtreecommitdiffstats
path: root/controller-api/src
diff options
context:
space:
mode:
authorgjoranv <gjoranv@gmail.com>2023-10-31 12:53:06 +0100
committergjoranv <gjoranv@gmail.com>2023-10-31 16:17:30 +0100
commit36b435a302357e198baeed816df79bdef0055292 (patch)
tree6c7c59cfadcdc5940733e905c67bc10cb37da979 /controller-api/src
parent7c150cdc0bab88d5913de557fd24c31cd3bf18b4 (diff)
Rename CLOSED -> SUCCESSFUL and introduce BillStatus.isFinal()
Diffstat (limited to 'controller-api/src')
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/BillStatus.java15
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/StatusHistory.java2
-rw-r--r--controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/billing/StatusHistoryTest.java20
3 files changed, 22 insertions, 15 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/BillStatus.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/BillStatus.java
index 4f35b47219a..00aa43cce5d 100644
--- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/BillStatus.java
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/BillStatus.java
@@ -4,10 +4,10 @@ package com.yahoo.vespa.hosted.controller.api.integration.billing;
* @author gjoranv
*/
public enum BillStatus {
- OPEN, // All bills start in this state. The bill can be modified and exported/synced to external systems.
- FROZEN, // Syncing to external systems is switched off. No changes can be made.
- CLOSED, // End state for a valid bill.
- VOID; // End state, indicating that the bill is not valid.
+ OPEN, // All bills start in this state. The bill can be modified and exported/synced to external systems.
+ FROZEN, // Syncing to external systems is switched off. No changes can be made.
+ SUCCESSFUL, // Final state for a valid bill.
+ VOID; // Final state, indicating that the bill is not valid.
// Legacy states, used by historical bills
private static final String LEGACY_ISSUED = "ISSUED";
@@ -24,6 +24,13 @@ public enum BillStatus {
return value;
}
+ /**
+ * Returns true if the bill is in a final state.
+ */
+ public boolean isFinal() {
+ return this == SUCCESSFUL || this == VOID;
+ }
+
public static BillStatus from(String status) {
if (LEGACY_ISSUED.equals(status) || LEGACY_EXPORTED.equals(status)) return OPEN;
if (LEGACY_CANCELED.equals(status)) return VOID;
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/StatusHistory.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/StatusHistory.java
index f0c7f806c8c..788995555a8 100644
--- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/StatusHistory.java
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/StatusHistory.java
@@ -53,7 +53,7 @@ public class StatusHistory {
return switch(current) {
case OPEN -> true;
case FROZEN -> newStatus != BillStatus.OPEN; // This could be subject to change.
- case CLOSED -> newStatus == BillStatus.CLOSED;
+ case SUCCESSFUL -> newStatus == BillStatus.SUCCESSFUL;
case VOID -> newStatus == BillStatus.VOID;
};
}
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
index 46a4c7e199c..8318a0449ea 100644
--- 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
@@ -21,7 +21,7 @@ public class StatusHistoryTest {
void open_can_change_to_any_status() {
var history = StatusHistory.open(clock);
history.checkValidTransition(BillStatus.FROZEN);
- history.checkValidTransition(BillStatus.CLOSED);
+ history.checkValidTransition(BillStatus.SUCCESSFUL);
history.checkValidTransition(BillStatus.VOID);
}
@@ -29,7 +29,7 @@ public class StatusHistoryTest {
void frozen_cannot_change_to_open() {
var history = new StatusHistory(historyWith(BillStatus.FROZEN));
- history.checkValidTransition(BillStatus.CLOSED);
+ history.checkValidTransition(BillStatus.SUCCESSFUL);
history.checkValidTransition(BillStatus.VOID);
assertThrows(IllegalArgumentException.class, () -> history.checkValidTransition(BillStatus.OPEN));
@@ -37,7 +37,7 @@ public class StatusHistoryTest {
@Test
void closed_cannot_change() {
- var history = new StatusHistory(historyWith(BillStatus.CLOSED));
+ var history = new StatusHistory(historyWith(BillStatus.SUCCESSFUL));
assertThrows(IllegalArgumentException.class, () -> history.checkValidTransition(BillStatus.OPEN));
assertThrows(IllegalArgumentException.class, () -> history.checkValidTransition(BillStatus.FROZEN));
@@ -50,7 +50,7 @@ public class StatusHistoryTest {
assertThrows(IllegalArgumentException.class, () -> history.checkValidTransition(BillStatus.OPEN));
assertThrows(IllegalArgumentException.class, () -> history.checkValidTransition(BillStatus.FROZEN));
- assertThrows(IllegalArgumentException.class, () -> history.checkValidTransition(BillStatus.CLOSED));
+ assertThrows(IllegalArgumentException.class, () -> history.checkValidTransition(BillStatus.SUCCESSFUL));
}
@Test
@@ -61,8 +61,8 @@ public class StatusHistoryTest {
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.SUCCESSFUL));
+ history.checkValidTransition(BillStatus.SUCCESSFUL);
history = new StatusHistory(historyWith(BillStatus.VOID));
history.checkValidTransition(BillStatus.VOID);
@@ -71,12 +71,12 @@ public class StatusHistoryTest {
@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.SUCCESSFUL, BillStatus.OPEN)));
+ assertThrows(IllegalArgumentException.class, () -> new StatusHistory(historyWith(BillStatus.SUCCESSFUL, BillStatus.FROZEN)));
+ assertThrows(IllegalArgumentException.class, () -> new StatusHistory(historyWith(BillStatus.SUCCESSFUL, 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)));
+ assertThrows(IllegalArgumentException.class, () -> new StatusHistory(historyWith(BillStatus.VOID, BillStatus.SUCCESSFUL)));
}
private SortedMap<ZonedDateTime, BillStatus> historyWith(BillStatus... statuses) {