From a32027cdf44eafb8c278cb09e6f1c418474c6827 Mon Sep 17 00:00:00 2001
From: stigus <stian.gustavsson@nav.no>
Date: Thu, 11 Jan 2024 13:26:54 +0100
Subject: [PATCH] Udistub refaktor for spring 3.2 #deploy-udi-stub

---
 apps/udi-stub/build.gradle                    |  16 ++-
 .../java/no/nav/udistub/config/DevConfig.java |   2 +-
 .../nav/udistub/service/KodeverkService.java  |   2 +-
 .../no/nav/udistub/service/PersonService.java |   4 +-
 .../wsdl/schema/Common_Headers_v2.xsd         | 100 +++++++++---------
 .../ArbeidsadgangPersonConverterTest.java     |   8 +-
 ...dsPaSammeVilkarIkkeVisumConverterTest.java |   7 +-
 .../udistub/converter/itest/UdiStubITest.java |   2 +-
 8 files changed, 76 insertions(+), 65 deletions(-)

diff --git a/apps/udi-stub/build.gradle b/apps/udi-stub/build.gradle
index f22b8655ff3..4a372d58b91 100644
--- a/apps/udi-stub/build.gradle
+++ b/apps/udi-stub/build.gradle
@@ -1,9 +1,10 @@
 plugins {
     id "org.sonarqube" version "4.0.0.2929"
     id 'java'
-    id "uk.co.boothen.gradle.wsimport" version "0.18"
+    id "uk.co.boothen.gradle.wsimport" version "0.21"
     id 'org.springframework.boot' version "3.2.1"
     id 'io.spring.dependency-management' version "1.1.4"
+    id("org.openrewrite.rewrite") version("6.6.4")
     id "jacoco"
 }
 
@@ -18,6 +19,10 @@ jacocoTestReport {
     }
 }
 
+rewrite {
+    activeRecipe("org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_2")
+}
+
 sonarqube {
     properties {
         property "sonar.coverage.jacoco.xmlReportPaths", "${project.layout.buildDirectory}/reports/jacoco/test/jacocoTestReport.xml"
@@ -51,6 +56,7 @@ configurations {
 }
 
 bootJar {
+    duplicatesStrategy(DuplicatesStrategy.INCLUDE)
     archiveFileName = "app.jar"
 }
 
@@ -74,8 +80,11 @@ repositories {
 }
 dependencies {
 
+    rewrite("org.openrewrite.recipe:rewrite-spring:5.2.0")
+
     implementation platform('org.testcontainers:testcontainers-bom:1.19.1')
 
+    implementation "com.sun.xml.ws:jaxws-rt:4.0.2"
     implementation 'no.nav.testnav.libs:servlet-core'
     implementation 'no.nav.testnav.libs:servlet-security'
     implementation 'no.nav.testnav.libs:database'
@@ -105,12 +114,13 @@ dependencies {
     implementation 'org.hibernate.validator:hibernate-validator'
 
     testImplementation 'com.h2database:h2'
+    testImplementation "org.junit.jupiter:junit-jupiter:5.10.1"
     testImplementation 'org.testcontainers:junit-jupiter'
     testImplementation 'org.testcontainers:postgresql'
     testImplementation 'org.springframework.boot:spring-boot-starter-test'
-    testImplementation 'org.springframework.cloud:spring-cloud-contract-wiremock'
-    testImplementation 'junit:junit:4.13.2' //TODO upgrade to JUnit5
+    testImplementation 'org.springframework.cloud:spring-cloud-contract-wiremock' //TODO upgrade to JUnit5
 
+    testImplementation "org.mockito:mockito-junit-jupiter:4.11.0"
     implementation 'org.projectlombok:lombok'
     annotationProcessor 'org.projectlombok:lombok'
     testAnnotationProcessor 'org.projectlombok:lombok'
diff --git a/apps/udi-stub/src/main/java/no/nav/udistub/config/DevConfig.java b/apps/udi-stub/src/main/java/no/nav/udistub/config/DevConfig.java
index 3cd1c00c271..8668160175a 100644
--- a/apps/udi-stub/src/main/java/no/nav/udistub/config/DevConfig.java
+++ b/apps/udi-stub/src/main/java/no/nav/udistub/config/DevConfig.java
@@ -30,7 +30,7 @@ public ClientAuthentication clientAuthentication() {
         }
         var token = System.getProperty(VAULT_PROPERTY);
         if (isBlank(token)) {
-            throw new IllegalArgumentException(String.format("Påkrevet property '%s' er ikke satt.", VAULT_PROPERTY));
+            throw new IllegalArgumentException("Påkrevet property '%s' er ikke satt.".formatted(VAULT_PROPERTY));
         }
         return new TokenAuthentication(System.getProperty(VAULT_PROPERTY));
     }
diff --git a/apps/udi-stub/src/main/java/no/nav/udistub/service/KodeverkService.java b/apps/udi-stub/src/main/java/no/nav/udistub/service/KodeverkService.java
index 0d1ba54a8de..7b4060542a7 100644
--- a/apps/udi-stub/src/main/java/no/nav/udistub/service/KodeverkService.java
+++ b/apps/udi-stub/src/main/java/no/nav/udistub/service/KodeverkService.java
@@ -30,7 +30,7 @@ public List<Kodeverk> finnAlleMedType(String type) {
     public Kodeverk finnMedKode(String kode) {
         return kodeverkRepository.findByKode(kode).orElseThrow(() ->
                 new HttpClientErrorException(HttpStatus.NOT_FOUND,
-                        String.format("Kunne ikke finne kode: %s i kodeverket", kode))
+                        "Kunne ikke finne kode: %s i kodeverket".formatted(kode))
         );
     }
 
diff --git a/apps/udi-stub/src/main/java/no/nav/udistub/service/PersonService.java b/apps/udi-stub/src/main/java/no/nav/udistub/service/PersonService.java
index b58dfc9eb62..f9e00975643 100644
--- a/apps/udi-stub/src/main/java/no/nav/udistub/service/PersonService.java
+++ b/apps/udi-stub/src/main/java/no/nav/udistub/service/PersonService.java
@@ -45,14 +45,14 @@ public UdiPerson finnPerson(String ident) {
 
         return personRepository.findByIdent(ident)
                 .map(person -> mapperFacade.map(person, UdiPerson.class))
-                .orElseThrow(() -> new NotFoundException(String.format(IKKE_FUNNET, ident)));
+                .orElseThrow(() -> new NotFoundException(IKKE_FUNNET.formatted(ident)));
     }
 
     @Transactional
     public void deletePerson(String ident) {
 
         var slettePerson = personRepository.findByIdent(ident)
-                .orElseThrow(() -> new NotFoundException(String.format(IKKE_FUNNET, ident)));
+                .orElseThrow(() -> new NotFoundException(IKKE_FUNNET.formatted(ident)));
         personRepository.deleteById(slettePerson.getId());
     }
 }
diff --git a/apps/udi-stub/src/main/resources/wsdl/schema/Common_Headers_v2.xsd b/apps/udi-stub/src/main/resources/wsdl/schema/Common_Headers_v2.xsd
index 36a3145f8b5..1e5d9306ab4 100755
--- a/apps/udi-stub/src/main/resources/wsdl/schema/Common_Headers_v2.xsd
+++ b/apps/udi-stub/src/main/resources/wsdl/schema/Common_Headers_v2.xsd
@@ -1,58 +1,60 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!-- edited with XMLSpy v2011 rel. 3 sp1 (x64) (http://www.altova.com) by Utlendingsdirektoratet (Utlendingsdirektoratet) -->
-<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://udi.no/Common/Headers/v2" targetNamespace="http://udi.no/Common/Headers/v2" elementFormDefault="qualified">
-  <xs:element name="RequestHeader" type="RequestHeaderType" nillable="true" />
-  <xs:complexType name="RequestHeaderType">
-    <xs:annotation>
-      <xs:documentation>Headeren som blir brukt av alle tjenester</xs:documentation>
-    </xs:annotation>
-    <xs:sequence>
-      <xs:element name="UoW" type="UoWType" minOccurs="0" />
-      <xs:element name="Opphav" type="OpphavType" minOccurs="0" />
-    </xs:sequence>
-  </xs:complexType>
-  <xs:complexType name="UoWType">
-    <xs:annotation>
-      <xs:documentation>Unit of Work. Benyttes i headers</xs:documentation>
-    </xs:annotation>
-    <xs:sequence>
-      <xs:element name="Id" type="xs:string" minOccurs="0">
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://udi.no/Common/Headers/v2"
+           targetNamespace="http://udi.no/Common/Headers/v2" elementFormDefault="qualified">
+    <xs:element name="RequestHeader" type="RequestHeaderType" nillable="true"/>
+    <xs:complexType name="RequestHeaderType">
         <xs:annotation>
-          <xs:documentation>Id til den logiske transaksjonen.</xs:documentation>
+            <xs:documentation>Headeren som blir brukt av alle tjenester</xs:documentation>
         </xs:annotation>
-      </xs:element>
-      <xs:element name="MeldingsId" type="xs:string" minOccurs="0">
+        <xs:sequence>
+            <xs:element name="UoW" type="UoWType" minOccurs="0"/>
+            <xs:element name="Opphav" type="OpphavType" minOccurs="0"/>
+        </xs:sequence>
+    </xs:complexType>
+    <xs:complexType name="UoWType">
         <xs:annotation>
-          <xs:documentation>Id til meldingen.</xs:documentation>
+            <xs:documentation>Unit of Work. Benyttes i headers</xs:documentation>
         </xs:annotation>
-      </xs:element>
-    </xs:sequence>
-  </xs:complexType>
-  <xs:complexType name="OpphavType">
-    <xs:annotation>
-      <xs:documentation>Informasjon om kallets opphav. Benyttes i headers</xs:documentation>
-    </xs:annotation>
-    <xs:sequence>
-      <xs:element name="Brukernavn" type="xs:string" minOccurs="0">
+        <xs:sequence>
+            <xs:element name="Id" type="xs:string" minOccurs="0">
+                <xs:annotation>
+                    <xs:documentation>Id til den logiske transaksjonen.</xs:documentation>
+                </xs:annotation>
+            </xs:element>
+            <xs:element name="MeldingsId" type="xs:string" minOccurs="0">
+                <xs:annotation>
+                    <xs:documentation>Id til meldingen.</xs:documentation>
+                </xs:annotation>
+            </xs:element>
+        </xs:sequence>
+    </xs:complexType>
+    <xs:complexType name="OpphavType">
         <xs:annotation>
-          <xs:documentation>Active Directory brukernavn på formatet domain\user</xs:documentation>
+            <xs:documentation>Informasjon om kallets opphav. Benyttes i headers</xs:documentation>
         </xs:annotation>
-      </xs:element>
-      <xs:element name="Systemtjenestenavn" type="xs:string" minOccurs="0">
-        <xs:annotation>
-          <xs:documentation>Navn på systemtjenesten som utførte det opprinnelige kallet</xs:documentation>
-        </xs:annotation>
-      </xs:element>
-      <xs:element name="Nettadresse" type="xs:string" minOccurs="0">
-        <xs:annotation>
-          <xs:documentation>IP eller DNS -navn  til maskinen som utførte det opprinnelige kallet</xs:documentation>
-        </xs:annotation>
-      </xs:element>
-      <xs:element name="Tidspunkt" type="xs:dateTime" minOccurs="0">
-        <xs:annotation>
-          <xs:documentation>Tidspunktet for det opprinnelige kallet</xs:documentation>
-        </xs:annotation>
-      </xs:element>
-    </xs:sequence>
-  </xs:complexType>
+        <xs:sequence>
+            <xs:element name="Brukernavn" type="xs:string" minOccurs="0">
+                <xs:annotation>
+                    <xs:documentation>Active Directory brukernavn på formatet domain user</xs:documentation>
+                </xs:annotation>
+            </xs:element>
+            <xs:element name="Systemtjenestenavn" type="xs:string" minOccurs="0">
+                <xs:annotation>
+                    <xs:documentation>Navn på systemtjenesten som utførte det opprinnelige kallet</xs:documentation>
+                </xs:annotation>
+            </xs:element>
+            <xs:element name="Nettadresse" type="xs:string" minOccurs="0">
+                <xs:annotation>
+                    <xs:documentation>IP eller DNS -navn til maskinen som utførte det opprinnelige kallet
+                    </xs:documentation>
+                </xs:annotation>
+            </xs:element>
+            <xs:element name="Tidspunkt" type="xs:dateTime" minOccurs="0">
+                <xs:annotation>
+                    <xs:documentation>Tidspunktet for det opprinnelige kallet</xs:documentation>
+                </xs:annotation>
+            </xs:element>
+        </xs:sequence>
+    </xs:complexType>
 </xs:schema>
\ No newline at end of file
diff --git a/apps/udi-stub/src/test/java/no/nav/udistub/converter/ArbeidsadgangPersonConverterTest.java b/apps/udi-stub/src/test/java/no/nav/udistub/converter/ArbeidsadgangPersonConverterTest.java
index 921fa3c9636..3ba545f12ae 100644
--- a/apps/udi-stub/src/test/java/no/nav/udistub/converter/ArbeidsadgangPersonConverterTest.java
+++ b/apps/udi-stub/src/test/java/no/nav/udistub/converter/ArbeidsadgangPersonConverterTest.java
@@ -1,7 +1,6 @@
 package no.nav.udistub.converter;
 
 import no.nav.udistub.converter.ws.ArbeidsadgangWsConverter;
-import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.InjectMocks;
@@ -10,6 +9,7 @@
 import static no.nav.udistub.converter.DefaultTestData.TEST_ARBEIDOMGANGKATEGORI;
 import static no.nav.udistub.converter.DefaultTestData.TEST_ARBEIDSADGANG;
 import static no.nav.udistub.converter.DefaultTestData.TEST_ARBEIDSADGANG_TYPE;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertNull;
 
@@ -23,9 +23,9 @@ class ArbeidsadgangPersonConverterTest extends ConverterTestBase {
     void convertFromPersonToArbeidsadgangIfPresent() {
         no.udi.mt_1067_nav_data.v1.Arbeidsadgang result = arbeidsadgangConverter.convert(defaultTestPerson.getArbeidsadgang());
         assertNotNull(result);
-        Assertions.assertEquals(TEST_ARBEIDSADGANG, result.getHarArbeidsadgang());
-        Assertions.assertEquals(TEST_ARBEIDOMGANGKATEGORI, result.getArbeidsOmfang());
-        Assertions.assertEquals(TEST_ARBEIDSADGANG_TYPE, result.getTypeArbeidsadgang());
+        assertEquals(TEST_ARBEIDSADGANG, result.getHarArbeidsadgang());
+        assertEquals(TEST_ARBEIDOMGANGKATEGORI, result.getArbeidsOmfang());
+        assertEquals(TEST_ARBEIDSADGANG_TYPE, result.getTypeArbeidsadgang());
     }
 
     @Test
diff --git a/apps/udi-stub/src/test/java/no/nav/udistub/converter/IkkeOppholdstillatelseIkkeOppholdsPaSammeVilkarIkkeVisumConverterTest.java b/apps/udi-stub/src/test/java/no/nav/udistub/converter/IkkeOppholdstillatelseIkkeOppholdsPaSammeVilkarIkkeVisumConverterTest.java
index bb42fb13e75..89502df793f 100644
--- a/apps/udi-stub/src/test/java/no/nav/udistub/converter/IkkeOppholdstillatelseIkkeOppholdsPaSammeVilkarIkkeVisumConverterTest.java
+++ b/apps/udi-stub/src/test/java/no/nav/udistub/converter/IkkeOppholdstillatelseIkkeOppholdsPaSammeVilkarIkkeVisumConverterTest.java
@@ -6,7 +6,6 @@
 import no.udi.mt_1067_nav_data.v1.EOSellerEFTAGrunnlagskategoriOppholdstillatelse;
 import no.udi.mt_1067_nav_data.v1.IkkeOppholdstillatelseIkkeOppholdsPaSammeVilkarIkkeVisum;
 import no.udi.mt_1067_nav_data.v1.OppholdsgrunnlagKategori;
-import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.InjectMocks;
@@ -28,10 +27,10 @@ void convertFromPersonToIkkeOppholdstillatelseIkkeOppholdsPaSammeVilkarIkkeVisum
                 defaultTestPerson.getOppholdStatus().getIkkeOppholdstilatelseIkkeVilkaarIkkeVisum());
 
         assertNotNull(result);
-        Assertions.assertEquals(DefaultTestData.TEST_ovrigIkkeOppholdsKategori, result.getOvrigIkkeOpphold().getArsak());
+        assertEquals(DefaultTestData.TEST_ovrigIkkeOppholdsKategori, result.getOvrigIkkeOpphold().getArsak());
 
-        Assertions.assertEquals(DefaultTestData.TEST_INNREISEFORBUD, result.getUtvistMedInnreiseForbud().getInnreiseForbud());
-        Assertions.assertEquals(DefaultTestData.TEST_VARIGHET_UDI, result.getUtvistMedInnreiseForbud().getVarighet());
+        assertEquals(DefaultTestData.TEST_INNREISEFORBUD, result.getUtvistMedInnreiseForbud().getInnreiseForbud());
+        assertEquals(DefaultTestData.TEST_VARIGHET_UDI, result.getUtvistMedInnreiseForbud().getVarighet());
 
         AvslagEllerBortfallAvPOBOSellerTilbakekallEllerFormeltVedtak avslagEllerBortfall = result.getAvslagEllerBortfallAvPOBOSellerTilbakekallEllerFormeltVedtak();
         assertEquals(EOSellerEFTAGrunnlagskategoriOppholdsrett.FAMILIE, avslagEllerBortfall.getAvslagPaSoknadOmOppholdsrettRealitetsBehandlet().getAvslagsGrunnlagEOS());
diff --git a/apps/udi-stub/src/test/java/no/nav/udistub/converter/itest/UdiStubITest.java b/apps/udi-stub/src/test/java/no/nav/udistub/converter/itest/UdiStubITest.java
index 7f93be643d8..54170daf2a5 100644
--- a/apps/udi-stub/src/test/java/no/nav/udistub/converter/itest/UdiStubITest.java
+++ b/apps/udi-stub/src/test/java/no/nav/udistub/converter/itest/UdiStubITest.java
@@ -67,7 +67,7 @@ class UdiStubITest {
     private Flyway flyway;
 
     @BeforeEach
-    public void setUp() throws IOException {
+    void setUp() throws IOException {
 
 
         flyway.migrate();