Skip to content

Commit

Permalink
Merge pull request #18 from dvsa/newEnvs
Browse files Browse the repository at this point in the history
chore: uri constructor changes for Containers
  • Loading branch information
sr4850 authored Oct 23, 2024
2 parents 399c146 + 77096c0 commit 243ca85
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
9 changes: 6 additions & 3 deletions src/main/java/org/dvsa/testing/lib/url/api/URL.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
public class URL extends URLBase {

public static java.net.URL build(@NotNull String scheme, @NotNull EnvironmentType environment, @NotNull String path) {
// TODO: find out how prod url looks and incorporate findings
if (environment == EnvironmentType.LOCAL) {
setURL(String.format("%s://olcs-backend/api/%s",scheme, path));
setURL(String.format("%s://olcs-backend/api/%s", scheme, path));
} else {
setURL(String.format("%s://api.%s.olcs.dev-dvsacloud.uk/api/%s", scheme, environment, path));
String baseUrl = String.format("%s://api.%s.olcs.dev-dvsacloud.uk/api/%s", scheme, environment, path);
if (environment == EnvironmentType.PRODUCTION) {
baseUrl = baseUrl.replace(".dev-", ".");
}
setURL(baseUrl);
}
return getURL();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public enum EnvironmentType {
DEVELOP("dev"),
REGRESSION("reg"),
INTEGRATION("int"),
PREPRODUCTION("pre"),
PREPRODUCTION("prep"),
PRODUCTION("prod"),
LOCAL("local");

Expand All @@ -24,7 +24,6 @@ public enum EnvironmentType {

public static EnvironmentType getEnum(@NotNull String env) {
EnvironmentType envEnum;

switch (env.toLowerCase()) {
case "qa":
envEnum = EnvironmentType.QUALITY_ASSURANCE;
Expand All @@ -41,7 +40,7 @@ public static EnvironmentType getEnum(@NotNull String env) {
case "reg":
envEnum = EnvironmentType.REGRESSION;
break;
case "pre":
case "prep":
envEnum = EnvironmentType.PREPRODUCTION;
break;
case "prod":
Expand All @@ -57,14 +56,13 @@ public static EnvironmentType getEnum(@NotNull String env) {
envEnum = EnvironmentType.LOCAL;
break;
default:
throw new IllegalArgumentException(String.format("[ERROR] %s does not match up to any environment"));
throw new IllegalArgumentException(String.format("[ERROR] %s does not match up to any environment", env));
}
return envEnum;
}

public static String name(@NotNull ApplicationType appType, @NotNull EnvironmentType env) {
String name;

switch (env) {
case QUALITY_ASSURANCE:
name = "qa";
Expand All @@ -85,7 +83,7 @@ public static String name(@NotNull ApplicationType appType, @NotNull Environment
name = "prodsupp";
break;
case PREPRODUCTION:
name = "pre";
name = "prep";
break;
case DEMO:
name = "demo";
Expand All @@ -101,11 +99,12 @@ public static String name(@NotNull ApplicationType appType, @NotNull Environment
}
break;
default:
throw new IllegalArgumentException(String.format("unable to handle application type of %s and/or environment of type %s.", appType, env));
throw new IllegalArgumentException(String.format("unable to handle application type of %s and/or environment of type %s. ", appType, env));
}

return name;
}

@Override
public final String toString() {
return this.name;
Expand Down
20 changes: 18 additions & 2 deletions src/test/java/URLTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ public void createInternalIntegrationDomain() throws MalformedURLException {

@Test
public void createExternalPreProductionDomain() throws MalformedURLException {
java.net.URL actualDomain = new java.net.URL("https://ssweb.pre.olcs.dvsacloud.uk/");
java.net.URL actualDomain = new java.net.URL("https://ssweb.prep.olcs.dvsacloud.uk/");
java.net.URL expectedDomain = URL.build(ApplicationType.EXTERNAL, EnvironmentType.PREPRODUCTION);

assertEquals(expectedDomain, actualDomain);
}

@Test
public void createInternalPreProductionDomain() throws MalformedURLException {
java.net.URL actualDomain = new java.net.URL("https://iuweb.pre.olcs.dvsacloud.uk/");
java.net.URL actualDomain = new java.net.URL("https://iuweb.prep.olcs.dvsacloud.uk/");
java.net.URL expectedDomain = URL.build(ApplicationType.INTERNAL, EnvironmentType.PREPRODUCTION);

assertEquals(expectedDomain, actualDomain);
Expand Down Expand Up @@ -162,6 +162,22 @@ public void createInternalRegressionDomain() throws MalformedURLException {
assertEquals(expectedDomain, actualDomain);
}

@Test
public void createExternalDemoDomain() throws MalformedURLException {
java.net.URL actualDomain = new java.net.URL("https://ssweb.demo.olcs.dev-dvsacloud.uk/");
java.net.URL expectedDomain = URL.build(ApplicationType.EXTERNAL, EnvironmentType.DEMO);

assertEquals(expectedDomain, actualDomain);
}

@Test
public void createInternalDemoDomain() throws MalformedURLException {
java.net.URL actualDomain = new java.net.URL("https://iuweb.demo.olcs.dev-dvsacloud.uk/");
java.net.URL expectedDomain = URL.build(ApplicationType.INTERNAL, EnvironmentType.DEMO);

assertEquals(expectedDomain, actualDomain);
}

@Test
public void updatesTheURLPath() throws MalformedURLException {
URL.build(ApplicationType.EXTERNAL, EnvironmentType.PRODUCTION, "register");
Expand Down

0 comments on commit 243ca85

Please sign in to comment.