-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TFP-3391 la til roundtrip test i kontrakter (#205)
- Loading branch information
Showing
3 changed files
with
115 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...abonnent/src/test/java/no/nav/foreldrepenger/kontrakter/abonnent/FødselsHendelseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package no.nav.foreldrepenger.kontrakter.abonnent; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.time.LocalDate; | ||
import java.util.Collections; | ||
|
||
import javax.validation.Validation; | ||
|
||
import org.junit.Test; | ||
|
||
import com.fasterxml.jackson.databind.ObjectReader; | ||
import com.fasterxml.jackson.databind.ObjectWriter; | ||
|
||
import no.nav.foreldrepenger.kontrakter.abonnent.tps.FødselHendelseDto; | ||
|
||
public class FødselsHendelseTest { | ||
|
||
private static final ObjectWriter WRITER = TestJsonMapper.getMapper().writerWithDefaultPrettyPrinter(); | ||
private static final ObjectReader READER = TestJsonMapper.getMapper().reader(); | ||
|
||
private static final String AKTØR_ID = "10000000001"; | ||
private static final LocalDate NÅ = LocalDate.now(); | ||
|
||
@Test | ||
public void test_fødselshendelse() throws Exception { | ||
var fødselsHendelse = new FødselHendelseDto(); | ||
fødselsHendelse.setId("id_1"); | ||
fødselsHendelse.setAktørIdForeldre(Collections.singletonList(AKTØR_ID)); | ||
fødselsHendelse.setFødselsdato(NÅ); | ||
|
||
|
||
String json = WRITER.writeValueAsString(fødselsHendelse); | ||
System.out.println(json); | ||
|
||
FødselHendelseDto roundTripped = READER.forType(FødselHendelseDto.class).readValue(json); | ||
|
||
assertThat(roundTripped).isNotNull(); | ||
assertThat(roundTripped.getId()).isEqualTo("id_1"); | ||
assertThat(roundTripped.getAktørIdForeldre().get(0)).isEqualTo(AKTØR_ID); | ||
assertThat(roundTripped.getFødselsdato()).isEqualTo(NÅ); | ||
assertThat(roundTripped.getHendelsetype()).isEqualTo("FØDSEL"); | ||
validateResult(roundTripped); | ||
} | ||
|
||
private void validateResult(Object roundTripped) { | ||
assertThat(roundTripped).isNotNull(); | ||
try (var factory = Validation.buildDefaultValidatorFactory()) { | ||
var validator = factory.getValidator(); | ||
var violations = validator.validate(roundTripped); | ||
assertThat(violations).isEmpty(); | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...rakt-abonnent/src/test/java/no/nav/foreldrepenger/kontrakter/abonnent/TestJsonMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package no.nav.foreldrepenger.kontrakter.abonnent; | ||
|
||
import com.fasterxml.jackson.annotation.JsonAutoDetect; | ||
import com.fasterxml.jackson.annotation.PropertyAccessor; | ||
import com.fasterxml.jackson.databind.DeserializationFeature; | ||
import com.fasterxml.jackson.databind.InjectableValues; | ||
import com.fasterxml.jackson.databind.InjectableValues.Std; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.SerializationFeature; | ||
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; | ||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | ||
|
||
public class TestJsonMapper { | ||
|
||
private static final ObjectMapper OM; | ||
|
||
static { | ||
ObjectMapper objectMapper = new ObjectMapper(); | ||
objectMapper.registerModule(new Jdk8Module()); | ||
objectMapper.registerModule(new JavaTimeModule()); | ||
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); | ||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); | ||
objectMapper.setVisibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.NONE); | ||
objectMapper.setVisibility(PropertyAccessor.SETTER, JsonAutoDetect.Visibility.NONE); | ||
objectMapper.setVisibility(PropertyAccessor.IS_GETTER, JsonAutoDetect.Visibility.NONE); | ||
objectMapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY); | ||
objectMapper.setVisibility(PropertyAccessor.CREATOR, JsonAutoDetect.Visibility.ANY); | ||
|
||
Std std = new InjectableValues.Std(); | ||
objectMapper.setInjectableValues(std); | ||
OM = objectMapper; | ||
} | ||
|
||
public static ObjectMapper getMapper() { | ||
return OM; | ||
} | ||
|
||
} |