diff options
Diffstat (limited to 'controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration')
9 files changed, 190 insertions, 7 deletions
diff --git a/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/ConsoleUrlsTest.java b/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/ConsoleUrlsTest.java new file mode 100644 index 00000000000..259a279671b --- /dev/null +++ b/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/ConsoleUrlsTest.java @@ -0,0 +1,44 @@ +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.hosted.controller.api.integration; + +import com.yahoo.config.provision.ApplicationId; +import com.yahoo.config.provision.ClusterSpec; +import com.yahoo.config.provision.Environment; +import com.yahoo.config.provision.zone.ZoneId; +import com.yahoo.vespa.hosted.controller.api.integration.deployment.JobType; +import com.yahoo.vespa.hosted.controller.api.integration.deployment.RunId; +import org.junit.jupiter.api.Test; + +import java.net.URI; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * @author freva + */ +class ConsoleUrlsTest { + + private final ConsoleUrls urls = new ConsoleUrls(URI.create("https://console.tld/")); + + @Test + void urls() { + ApplicationId app = ApplicationId.from("t1", "a1", "i1"); + ZoneId prod = ZoneId.from("prod", "us-north-1"); + ZoneId dev = ZoneId.from("dev", "eu-west-2"); + ZoneId test = ZoneId.from("test", "ap-east-3"); + ClusterSpec.Id cluster = ClusterSpec.Id.from("c1"); + + assertEquals("https://console.tld", urls.root()); + assertEquals("https://console.tld/tenant/t1", urls.tenantOverview(app.tenant())); + assertEquals("https://console.tld/tenant/t1/account/notifications", urls.tenantNotifications(app.tenant())); + assertEquals("https://console.tld/tenant/t1/account/billing", urls.tenantBilling(app.tenant())); + assertEquals("https://console.tld/tenant/t1/application/a1/prod/instance", urls.prodApplicationOverview(app.tenant(), app.application())); + assertEquals("https://console.tld/tenant/t1/application/a1/prod/instance/i1", urls.instanceOverview(app, Environment.test)); + assertEquals("https://console.tld/tenant/t1/application/a1/dev/instance/i1?i1.dev.eu-west-2=clusters%2Cc1", urls.clusterOverview(app, dev, cluster)); + assertEquals("https://console.tld/tenant/t1/application/a1/prod/instance/i1?i1.prod.us-north-1=clusters%2Cc1%3Dreindexing", urls.clusterReindexing(app, prod, cluster)); + assertEquals("https://console.tld/tenant/t1/application/a1/prod/instance/i1/job/production-us-north-1/run/1", urls.deploymentRun(new RunId(app, JobType.deploymentTo(prod), 1))); + assertEquals("https://console.tld/tenant/t1/application/a1/prod/instance/i1/job/system-test/run/1", urls.deploymentRun(new RunId(app, JobType.deploymentTo(test), 1))); + assertEquals("https://console.tld/tenant/t1/application/a1/dev/instance/i1/job/dev-eu-west-2/run/1", urls.deploymentRun(new RunId(app, JobType.deploymentTo(dev), 1))); + assertEquals("https://console.tld/verify?code=test123", urls.verifyEmail("test123")); + } +} diff --git a/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/billing/BillStatusTest.java b/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/billing/BillStatusTest.java new file mode 100644 index 00000000000..022474406b9 --- /dev/null +++ b/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/billing/BillStatusTest.java @@ -0,0 +1,19 @@ +package com.yahoo.vespa.hosted.controller.api.integration.billing; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * @author gjoranv + */ +public class BillStatusTest { + + @Test + void legacy_states_are_converted() { + assertEquals(BillStatus.OPEN, BillStatus.from("ISSUED")); + assertEquals(BillStatus.OPEN, BillStatus.from("EXPORTED")); + assertEquals(BillStatus.VOID, BillStatus.from("CANCELED")); + } + +} 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; + } +} diff --git a/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/certificates/EndpointCertificateTest.java b/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/certificates/EndpointCertificateTest.java new file mode 100644 index 00000000000..e165157dac2 --- /dev/null +++ b/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/certificates/EndpointCertificateTest.java @@ -0,0 +1,31 @@ +package com.yahoo.vespa.hosted.controller.api.integration.certificates; + +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * @author mpolden + */ +class EndpointCertificateTest { + + @Test + public void san_matches() { + List<String> sans = List.of("*.a.example.com", "b.example.com", "c.example.com"); + assertTrue(EndpointCertificate.sanMatches("b.example.com", sans)); + assertTrue(EndpointCertificate.sanMatches("c.example.com", sans)); + assertTrue(EndpointCertificate.sanMatches("foo.a.example.com", sans)); + assertFalse(EndpointCertificate.sanMatches("", List.of())); + assertFalse(EndpointCertificate.sanMatches("example.com", List.of())); + assertFalse(EndpointCertificate.sanMatches("example.com", sans)); + assertFalse(EndpointCertificate.sanMatches("d.example.com", sans)); + assertFalse(EndpointCertificate.sanMatches("a.example.com", sans)); + assertFalse(EndpointCertificate.sanMatches("aa.example.com", sans)); + assertFalse(EndpointCertificate.sanMatches("c.c.example.com", sans)); + assertFalse(EndpointCertificate.sanMatches("a.a.a.example.com", sans)); + } + +} diff --git a/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/deployment/JobTypeTest.java b/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/deployment/JobTypeTest.java index 1693f752b89..552b313e454 100644 --- a/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/deployment/JobTypeTest.java +++ b/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/deployment/JobTypeTest.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.controller.api.integration.deployment; import com.yahoo.config.provision.zone.ZoneId; @@ -48,4 +48,4 @@ public class JobTypeTest { assertTrue(JobType.test("snohetta").isProduction()); } -}
\ No newline at end of file +} diff --git a/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/dns/AliasTargetTest.java b/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/dns/AliasTargetTest.java index c859cc020ab..2ef254a7f2d 100644 --- a/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/dns/AliasTargetTest.java +++ b/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/dns/AliasTargetTest.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.controller.api.integration.dns; import com.yahoo.config.provision.HostName; diff --git a/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/dns/DirectTargetTest.java b/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/dns/DirectTargetTest.java index f262821a638..f6414113d4e 100644 --- a/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/dns/DirectTargetTest.java +++ b/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/dns/DirectTargetTest.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.controller.api.integration.dns; import com.yahoo.config.provision.zone.ZoneId; @@ -33,4 +33,4 @@ class DirectTargetTest { } } -}
\ No newline at end of file +} diff --git a/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/maven/MetadataTest.java b/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/maven/MetadataTest.java index a6f7a5ee069..e78e9fb64d9 100644 --- a/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/maven/MetadataTest.java +++ b/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/maven/MetadataTest.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.controller.api.integration.maven; import com.yahoo.collections.Iterables; diff --git a/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/user/RolesTest.java b/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/user/RolesTest.java index 59484fbb0ce..f8bd0243c02 100644 --- a/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/user/RolesTest.java +++ b/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/user/RolesTest.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.controller.api.integration.user; import com.yahoo.config.provision.ApplicationName; |