Skip to content

Commit

Permalink
Sett locale i jsonSchema
Browse files Browse the repository at this point in the history
  • Loading branch information
johatr committed Jul 15, 2024
1 parent a4f53cc commit 0be797d
Showing 1 changed file with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.networknt.schema.JsonSchema;
import com.networknt.schema.JsonSchemaFactory;
import com.networknt.schema.SpecVersion;
import com.networknt.schema.ValidationMessage;
import com.networknt.schema.*;
import lombok.SneakyThrows;
import no.nav.veilarbaktivitet.person.Person;
import org.junit.jupiter.api.Test;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Locale;
import java.util.Set;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -37,7 +35,7 @@ void schema_should_be_in_sync_with_classes() {
InputStream aktitivitetskortYml = JsonSchemaValidatorTest.class.getResourceAsStream("/schemas/akaas/Aktivitetskort.V1.aktivitetskort.schema.yml");
String aktiviteskortSchemaJsonString = convertYamlToJson(aktitivitetskortYml);

JsonSchema jsonSchema = factory.getSchema(new ByteArrayInputStream(aktiviteskortSchemaJsonString.getBytes()));
JsonSchema jsonSchema = factory.getSchema(new ByteArrayInputStream(aktiviteskortSchemaJsonString.getBytes())).withConfig(SchemaValidatorsConfig.builder().locale(Locale.ENGLISH).build());

var valid = AktivitetskortProducerUtil.validExampleAktivitetskortRecord(Person.fnr("1234567890"));
var validValidationMessages = jsonSchema.validate(valid);
Expand All @@ -47,7 +45,7 @@ void schema_should_be_in_sync_with_classes() {
var invalid = AktivitetskortProducerUtil.invalidExampleRecord(Person.fnr("1234567890"));
var invalidValidationMessages = jsonSchema.validate(invalid);
assertEquals(1, invalidValidationMessages.size(), errorMessage(invalidValidationMessages));
assertEquals("$: required property 'aktivitetskortType' not found", errorMessage(invalidValidationMessages));
assertEquals(": required property 'aktivitetskortType' not found", errorMessage(invalidValidationMessages));
}

@Test
Expand Down

0 comments on commit 0be797d

Please sign in to comment.