diff --git a/integrasjon/rest-klient/src/main/java/no/nav/vedtak/felles/integrasjon/rest/FpApplication.java b/integrasjon/rest-klient/src/main/java/no/nav/vedtak/felles/integrasjon/rest/FpApplication.java index 03c0b9a26..cbf831d3f 100644 --- a/integrasjon/rest-klient/src/main/java/no/nav/vedtak/felles/integrasjon/rest/FpApplication.java +++ b/integrasjon/rest-klient/src/main/java/no/nav/vedtak/felles/integrasjon/rest/FpApplication.java @@ -55,31 +55,32 @@ public boolean specified() { public static String contextPathFor(FpApplication application) { - return contextPathFor(application, ENV.getCluster()); + return contextPathFor(application, ENV); } public static String scopesFor(FpApplication application) { - return scopesFor(application, ENV.getCluster()); + return scopesFor(application, ENV); } - static String contextPathFor(FpApplication application, Cluster clusten) { + static String contextPathFor(FpApplication application, Environment currentEnvironment) { if (application == null || NONFP.equals(application)) { throw new IllegalArgumentException("Utviklerfeil: angitt app er ikke i fp-familien"); } var appname = application.name().toLowerCase(); + var cluster = currentEnvironment.getCluster(); - if (clusten.isLocal()) { - return Optional.ofNullable(ENV.getProperty(application.name().toLowerCase() + ".override.url")) + if (cluster.isLocal()) { + return Optional.ofNullable(currentEnvironment.getProperty(application.name().toLowerCase() + ".override.url")) .orElseGet(() -> String.format("http://localhost:%s/%s", LOCAL_PORTS.get(application), appname)); } - var clusterForApplication = getClusterTilFPApplikasjonenSomSkalKalles(application, clusten); - if (clusten.isCoLocated(clusterForApplication)) { + var clusterForApplication = getClusterTilFPApplikasjonenSomSkalKalles(application, currentEnvironment); + if (cluster.isCoLocated(clusterForApplication)) { return String.format("http://%s/%s", appname, appname); } else { var prefix = "https://" + appname; - if (clusten.isFss()) { // Kaller fra FSS til GCP - return prefix + ".intern" + (clusten.isProd() ? "" : ".dev") + ".nav.no/" + appname; + if (currentEnvironment.isFss()) { // Kaller fra FSS til GCP + return prefix + ".intern" + (cluster.isProd() ? "" : ".dev") + ".nav.no/" + appname; } else { // Kaller fra GCP til FSS if (FPSAK.equals(application)) { prefix += "-api"; @@ -89,18 +90,18 @@ static String contextPathFor(FpApplication application, Cluster clusten) { } } - static String scopesFor(FpApplication application, Cluster cluster) { - if (cluster.isLocal()) { + static String scopesFor(FpApplication application, Environment currentEnvironment) { + if (currentEnvironment.isLocal()) { return "api://" + Cluster.VTP.clusterName() + "." + FORELDREPENGER.getName() + "." + Cluster.VTP.clusterName() + "/.default"; } - return "api://" + getClusterTilFPApplikasjonenSomSkalKalles(application, cluster).clusterName() + "." + FORELDREPENGER.getName() + "." + application.name().toLowerCase() + "/.default"; + return "api://" + getClusterTilFPApplikasjonenSomSkalKalles(application, currentEnvironment).clusterName() + "." + FORELDREPENGER.getName() + "." + application.name().toLowerCase() + "/.default"; } - private static Cluster getClusterTilFPApplikasjonenSomSkalKalles(FpApplication application, Cluster cluster) { - if (cluster.isProd()) { + private static Cluster getClusterTilFPApplikasjonenSomSkalKalles(FpApplication application, Environment currentEnvironment) { + if (currentEnvironment.isProd()) { return GCP_APPS.contains(application) ? Cluster.PROD_GCP : Cluster.PROD_FSS; } - if (cluster.isDev()) { + if (currentEnvironment.isDev()) { return GCP_APPS.contains(application) ? Cluster.DEV_GCP : Cluster.DEV_FSS; } throw new IllegalArgumentException("Utviklerfeil: Skal ikke kunne nå her med cluster annet enn de som er definert over"); diff --git a/integrasjon/rest-klient/src/test/java/no/nav/vedtak/felles/integrasjon/rest/FpApplicationTest.java b/integrasjon/rest-klient/src/test/java/no/nav/vedtak/felles/integrasjon/rest/FpApplicationTest.java index 458739bf1..bb1510c4c 100644 --- a/integrasjon/rest-klient/src/test/java/no/nav/vedtak/felles/integrasjon/rest/FpApplicationTest.java +++ b/integrasjon/rest-klient/src/test/java/no/nav/vedtak/felles/integrasjon/rest/FpApplicationTest.java @@ -1,56 +1,76 @@ package no.nav.vedtak.felles.integrasjon.rest; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.when; import org.junit.jupiter.api.Test; +import org.mockito.Mockito; import no.nav.foreldrepenger.konfig.Cluster; +import no.nav.foreldrepenger.konfig.Environment; class FpApplicationTest { + private Environment environment = Mockito.mock(Environment.class); + @Test void test_at_service_discovery_brukes_mellom_FPAppp_i_samme_cluster() { - var contextPath = FpApplication.contextPathFor(FpApplication.FPSAK, Cluster.DEV_FSS); + when(environment.getCluster()).thenReturn(Cluster.DEV_FSS); + when(environment.isDev()).thenReturn(true); + var contextPath = FpApplication.contextPathFor(FpApplication.FPSAK, environment); assertThat(contextPath).isEqualTo("http://fpsak/fpsak"); } @Test void test_at_fss_til_gcp_bruker_full_ingress() { - var contextPath = FpApplication.contextPathFor(FpApplication.FPOVERSIKT, Cluster.DEV_FSS); + when(environment.getCluster()).thenReturn(Cluster.DEV_FSS); + when(environment.isFss()).thenReturn(true); + when(environment.isDev()).thenReturn(true); + var contextPath = FpApplication.contextPathFor(FpApplication.FPOVERSIKT, environment); assertThat(contextPath).isEqualTo("https://fpoversikt.intern.dev.nav.no/fpoversikt"); } @Test void test_at_gcp_til_annen_app_enn_fpsak_i_fss_bruker_ingress_av_type_pub() { - var contextPath = FpApplication.contextPathFor(FpApplication.FPTILBAKE, Cluster.DEV_GCP); + when(environment.getCluster()).thenReturn(Cluster.DEV_GCP); + when(environment.isDev()).thenReturn(true); + var contextPath = FpApplication.contextPathFor(FpApplication.FPTILBAKE, environment); assertThat(contextPath).isEqualTo("https://fptilbake.dev-fss-pub.nais.io/fptilbake"); } @Test void test_at_gcp_til_fpsak_i_fss_bruker_ingress_av_type_pub() { - var contextPath = FpApplication.contextPathFor(FpApplication.FPSAK, Cluster.DEV_GCP); - assertThat(contextPath).isEqualTo("https://fpsak-api.dev-fss-pub.nais.io/fpsak"); + when(environment.getCluster()).thenReturn(Cluster.PROD_GCP); + when(environment.isProd()).thenReturn(true); + var contextPath = FpApplication.contextPathFor(FpApplication.FPSAK, environment); + assertThat(contextPath).isEqualTo("https://fpsak-api.prod-fss-pub.nais.io/fpsak"); } @Test void test_at_vi_bruker_default_lokalhost_ved_lokal_kjøring_uten_override_url_satt() { - var contextPath = FpApplication.contextPathFor(FpApplication.FPABAKUS, Cluster.VTP); + when(environment.getCluster()).thenReturn(Cluster.VTP); + when(environment.isDev()).thenReturn(true); + when(environment.getProperty("fpabakus.override.url")).thenReturn(null); + var contextPath = FpApplication.contextPathFor(FpApplication.FPABAKUS, environment); assertThat(contextPath).isEqualTo("http://localhost:8015/fpabakus"); } @Test void bruk_override_url_hvis_oppgitt_og_cluster_er_vtp() { var overrideUrl = "http://override.url/"; - System.setProperty("fpabakus.override.url", overrideUrl); - var contextPath = FpApplication.contextPathFor(FpApplication.FPABAKUS, Cluster.VTP); + when(environment.getCluster()).thenReturn(Cluster.VTP); + when(environment.getProperty("fpabakus.override.url")).thenReturn(overrideUrl); + var contextPath = FpApplication.contextPathFor(FpApplication.FPABAKUS, environment); assertThat(contextPath).isEqualTo(overrideUrl); } @Test void ikke_bruk_override_url_hvis_oppgitt_og_cluster_dev_eller_prod() { var overrideUrl = "http://override.url/"; - System.setProperty("fpabakus.override.url", overrideUrl); - var contextPath = FpApplication.contextPathFor(FpApplication.FPABAKUS, Cluster.DEV_FSS); + when(environment.getCluster()).thenReturn(Cluster.DEV_FSS); + when(environment.isDev()).thenReturn(true); + when(environment.getProperty("fpabakus.override.url")).thenReturn(overrideUrl); + var contextPath = FpApplication.contextPathFor(FpApplication.FPABAKUS, environment); assertThat(contextPath).isEqualTo("http://fpabakus/fpabakus"); } } diff --git a/pom.xml b/pom.xml index d4c32998c..ccfc22077 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ no.nav.foreldrepenger.felles fp-bom - 1.1.0-SNAPSHOT + 0.5.0 felles-root