diff --git a/xapi-model/src/main/java/dev/learning/xapi/jackson/LocaleSerializer.java b/xapi-model/src/main/java/dev/learning/xapi/jackson/LocaleSerializer.java new file mode 100644 index 00000000..95bd4e31 --- /dev/null +++ b/xapi-model/src/main/java/dev/learning/xapi/jackson/LocaleSerializer.java @@ -0,0 +1,58 @@ +/* + * Copyright 2016-2023 Berry Cloud Ltd. All rights reserved. + */ + +package dev.learning.xapi.jackson; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; +import java.io.IOException; +import java.util.Locale; +import java.util.Map; + +/** + * Specific Locale serializer using {@link Locale#toLanguageTag()} instead of + * {@link Locale#toString()}. + * + * @author István Rátkai (Selindek) + */ +public class LocaleSerializer extends StdSerializer { + + private static final long serialVersionUID = 7182941951585541965L; + + public LocaleSerializer() { + super(Locale.class); + } + + @Override + public void serialize(Locale value, JsonGenerator gen, SerializerProvider provider) + throws IOException { + gen.writeString(value.toLanguageTag()); + } + + /** + *

+ * Locale Key Serializer. + *

+ * For serializing Locale keys in {@link Map}s + * + * @author István Rátkai (Selindek) + */ + public static class LocaleKeySerializer extends StdSerializer { + + private static final long serialVersionUID = 7182941951585541965L; + + public LocaleKeySerializer() { + super(Locale.class); + } + + @Override + public void serialize(Locale value, JsonGenerator gen, SerializerProvider provider) + throws IOException { + gen.writeFieldName(value.toLanguageTag()); + } + + } + +} diff --git a/xapi-model/src/main/java/dev/learning/xapi/model/Context.java b/xapi-model/src/main/java/dev/learning/xapi/model/Context.java index 8b4fd44d..7f0a6aab 100644 --- a/xapi-model/src/main/java/dev/learning/xapi/model/Context.java +++ b/xapi-model/src/main/java/dev/learning/xapi/model/Context.java @@ -6,6 +6,8 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import dev.learning.xapi.jackson.LocaleSerializer; import dev.learning.xapi.model.validation.constraints.HasScheme; import dev.learning.xapi.model.validation.constraints.NotUndetermined; import dev.learning.xapi.model.validation.constraints.ValidActor; @@ -73,6 +75,7 @@ public class Context { * The language in which the experience being recorded in this Statement (mainly) occurred in. */ @NotUndetermined + @JsonSerialize(using = LocaleSerializer.class) private Locale language; /** diff --git a/xapi-model/src/main/java/dev/learning/xapi/model/LanguageMap.java b/xapi-model/src/main/java/dev/learning/xapi/model/LanguageMap.java index 9566f5ed..7dbc0929 100644 --- a/xapi-model/src/main/java/dev/learning/xapi/model/LanguageMap.java +++ b/xapi-model/src/main/java/dev/learning/xapi/model/LanguageMap.java @@ -4,6 +4,8 @@ package dev.learning.xapi.model; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import dev.learning.xapi.jackson.LocaleSerializer; import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; @@ -20,6 +22,7 @@ * @see Language * Maps */ +@JsonSerialize(keyUsing = LocaleSerializer.LocaleKeySerializer.class) public class LanguageMap extends LinkedHashMap { private static final long serialVersionUID = 7375610804995032187L; diff --git a/xapi-model/src/test/java/dev/learning/xapi/model/ActivityDefinitionTests.java b/xapi-model/src/test/java/dev/learning/xapi/model/ActivityDefinitionTests.java index e8f848a1..c34d292a 100644 --- a/xapi-model/src/test/java/dev/learning/xapi/model/ActivityDefinitionTests.java +++ b/xapi-model/src/test/java/dev/learning/xapi/model/ActivityDefinitionTests.java @@ -114,7 +114,7 @@ void whenDeserializingActivityDefinitionThenNameIsExpected() throws Exception { final ActivityDefinition result = objectMapper.readValue(file, ActivityDefinition.class); // Then Name Is Expected - assertThat(result.getName().get(Locale.ENGLISH), + assertThat(result.getName().get(Locale.US), is("Does the xAPI include the concept of statements?")); } @@ -129,7 +129,7 @@ void whenDeserializingActivityDefinitionThenDescriptionIsExpected() throws Excep final ActivityDefinition result = objectMapper.readValue(file, ActivityDefinition.class); // Then Description Is Expected - assertThat(result.getDescription().get(Locale.ENGLISH), is("pong[.]1:[,]dg[.]:10[,]lunch[.]")); + assertThat(result.getDescription().get(Locale.US), is("pong[.]1:[,]dg[.]:10[,]lunch[.]")); } @@ -188,7 +188,7 @@ void whenDeserializingActivityDefinitionWithChoicesThenChoicesDescriptionIsExpec final ActivityDefinition result = objectMapper.readValue(file, ActivityDefinition.class); // Then Choices Description Is Expected - assertThat(result.getChoices().get(0).getDescription().get(Locale.ENGLISH), + assertThat(result.getChoices().get(0).getDescription().get(Locale.US), is("Does the xAPI include the concept of statements?")); } @@ -218,7 +218,7 @@ void whenDeserializingActivityDefinitionWithScaledThenScaleDescriptionIsExpected final ActivityDefinition result = objectMapper.readValue(file, ActivityDefinition.class); // Then Scale Description Is Expected - assertThat(result.getScale().get(0).getDescription().get(Locale.ENGLISH), + assertThat(result.getScale().get(0).getDescription().get(Locale.US), is("Does the xAPI include the concept of statements?")); } @@ -248,7 +248,7 @@ void whenDeserializingActivityDefinitionWithSourceThenSourceDescriptionIsExpecte final ActivityDefinition result = objectMapper.readValue(file, ActivityDefinition.class); // Then Source Description Is Expected - assertThat(result.getSource().get(0).getDescription().get(Locale.ENGLISH), + assertThat(result.getSource().get(0).getDescription().get(Locale.US), is("Does the xAPI include the concept of statements?")); } @@ -278,7 +278,7 @@ void whenDeserializingActivityDefinitionWithTargetThenTargetDescriptionIsExpecte final ActivityDefinition result = objectMapper.readValue(file, ActivityDefinition.class); // Then Target Description Is Expected - assertThat(result.getTarget().get(0).getDescription().get(Locale.ENGLISH), + assertThat(result.getTarget().get(0).getDescription().get(Locale.US), is("Does the xAPI include the concept of statements?")); } @@ -308,7 +308,7 @@ void whenDeserializingActivityDefinitionWithStepsThenStepsDescriptionIsExpected( final ActivityDefinition result = objectMapper.readValue(file, ActivityDefinition.class); // Then Steps Description Is Expected - assertThat(result.getSteps().get(0).getDescription().get(Locale.ENGLISH), + assertThat(result.getSteps().get(0).getDescription().get(Locale.US), is("Does the xAPI include the concept of statements?")); } @@ -319,9 +319,9 @@ void whenSerializingActivityDefinitionOfInteractionTypeTrueFalseThenResultIsEqua final ActivityDefinition activityDefinition = ActivityDefinition.builder() - .addName(Locale.ENGLISH, "True false question") + .addName(Locale.US, "True false question") - .addDescription(Locale.ENGLISH, "Does the xAPI include the concept of statements?") + .addDescription(Locale.US, "Does the xAPI include the concept of statements?") .interactionType(InteractionType.TRUE_FALSE) @@ -347,21 +347,21 @@ void whenSerializingActivityDefinitionOfInteractionTypeChoiceThenResultIsEqualTo final ActivityDefinition activityDefinition = ActivityDefinition.builder() - .addName(Locale.ENGLISH, "Choice") + .addName(Locale.US, "Choice") - .addDescription(Locale.ENGLISH, "Which of these prototypes are available at the beta site?") + .addDescription(Locale.US, "Which of these prototypes are available at the beta site?") .interactionType(InteractionType.CHOICE) .correctResponsesPattern(Collections.singletonList("golf[,]tetris")) - .addChoice(c -> c.id("golf").addDescription(Locale.ENGLISH, "Golf Example")) + .addChoice(c -> c.id("golf").addDescription(Locale.US, "Golf Example")) - .addChoice(c -> c.id("facebook").addDescription(Locale.ENGLISH, "Facebook App")) + .addChoice(c -> c.id("facebook").addDescription(Locale.US, "Facebook App")) - .addChoice(c -> c.id("tetris").addDescription(Locale.ENGLISH, "Tetris Example")) + .addChoice(c -> c.id("tetris").addDescription(Locale.US, "Tetris Example")) - .addChoice(c -> c.id("scrabble").addDescription(Locale.ENGLISH, "Scrabble Example")) + .addChoice(c -> c.id("scrabble").addDescription(Locale.US, "Scrabble Example")) .type(URI.create("http://adlnet.gov/expapi/activities/cmi.interaction")) @@ -389,7 +389,7 @@ void whenCallingToStringThenResultIsExpected() throws Exception { // Then Result Is Expected assertThat(result, is( - "ActivityDefinition(name={en=Does the xAPI include the concept of statements?}, description={en=pong[.]1:[,]dg[.]:10[,]lunch[.]}, type=http://adlnet.gov/expapi/activities/cmi.interaction, moreInfo=http://example.com/more, interactionType=TRUE_FALSE, correctResponsesPattern=[{case_matters=false}{lang=en}To store and provide access to learning experiences.], choices=[InteractionComponent(id=1, description={en=Does the xAPI include the concept of statements?})], scale=[InteractionComponent(id=1, description={en=Does the xAPI include the concept of statements?})], source=[InteractionComponent(id=1, description={en=Does the xAPI include the concept of statements?})], target=[InteractionComponent(id=1, description={en=Does the xAPI include the concept of statements?})], steps=[InteractionComponent(id=1, description={en=Does the xAPI include the concept of statements?})], extensions={http://url=www.example.com})")); + "ActivityDefinition(name={en_US=Does the xAPI include the concept of statements?}, description={en_US=pong[.]1:[,]dg[.]:10[,]lunch[.]}, type=http://adlnet.gov/expapi/activities/cmi.interaction, moreInfo=http://example.com/more, interactionType=TRUE_FALSE, correctResponsesPattern=[{case_matters=false}{lang=en}To store and provide access to learning experiences.], choices=[InteractionComponent(id=1, description={en_US=Does the xAPI include the concept of statements?})], scale=[InteractionComponent(id=1, description={en_US=Does the xAPI include the concept of statements?})], source=[InteractionComponent(id=1, description={en_US=Does the xAPI include the concept of statements?})], target=[InteractionComponent(id=1, description={en_US=Does the xAPI include the concept of statements?})], steps=[InteractionComponent(id=1, description={en_US=Does the xAPI include the concept of statements?})], extensions={http://url=www.example.com})")); } @Test @@ -398,11 +398,11 @@ void whenBuildingActivityDefinitionWithTwoNameValuesThenNameLanguageMapHasTwoEnt // When Building ActivityDefinition With Two Name Values final ActivityDefinition activityDefinition = ActivityDefinition.builder() - .addName(Locale.ENGLISH, "True false question") + .addName(Locale.US, "True false question") .addName(Locale.GERMAN, "Richtig / Falsch-Frage") - .addDescription(Locale.ENGLISH, "Does the xAPI include the concept of statements?") + .addDescription(Locale.US, "Does the xAPI include the concept of statements?") .interactionType(InteractionType.TRUE_FALSE) @@ -423,9 +423,9 @@ void whenBuildingActivityDefinitionWithTwoDescriptionValuesThenDescriptionLangua // When Building ActivityDefinition With Two Description Values final ActivityDefinition activityDefinition = ActivityDefinition.builder() - .addName(Locale.ENGLISH, "True false question") + .addName(Locale.US, "True false question") - .addDescription(Locale.ENGLISH, "Does the xAPI include the concept of statements?") + .addDescription(Locale.US, "Does the xAPI include the concept of statements?") .addDescription(Locale.GERMAN, "Enthält die xAPI das Konzept von Anweisungen?") diff --git a/xapi-model/src/test/java/dev/learning/xapi/model/ActivityTests.java b/xapi-model/src/test/java/dev/learning/xapi/model/ActivityTests.java index f30d4f41..933dfb1e 100644 --- a/xapi-model/src/test/java/dev/learning/xapi/model/ActivityTests.java +++ b/xapi-model/src/test/java/dev/learning/xapi/model/ActivityTests.java @@ -79,9 +79,9 @@ void whenSerializingActivityThenResultIsEqualToExpectedJson() throws IOException .definition(d -> d - .addName(Locale.ENGLISH, "simple statement") + .addName(Locale.US, "simple statement") - .addDescription(Locale.ENGLISH, + .addDescription(Locale.US, "A simple Experience API statement. Note that the LRS does not need to have any prior information about the Actor (learner), the verb, or the Activity/object.")) .build(); diff --git a/xapi-model/src/test/java/dev/learning/xapi/model/ContextTests.java b/xapi-model/src/test/java/dev/learning/xapi/model/ContextTests.java index 1e834553..c6902fe2 100644 --- a/xapi-model/src/test/java/dev/learning/xapi/model/ContextTests.java +++ b/xapi-model/src/test/java/dev/learning/xapi/model/ContextTests.java @@ -93,7 +93,7 @@ void whenDeserializingContextThenLanguageIsExpected() throws Exception { final Context result = objectMapper.readValue(file, Context.class); // Then Language Is Expected - assertThat(result.getLanguage(), is(Locale.ENGLISH)); + assertThat(result.getLanguage(), is(Locale.US)); } @@ -230,7 +230,7 @@ void whenSerializingContextThenResultIsEqualToExpectedJson() throws IOException .platform("platform") - .language(Locale.ENGLISH) + .language(Locale.US) .statementReference(s -> s.id(UUID.fromString("e9b6b9ed-ef48-4986-9b86-2ef697578bf7"))) @@ -268,7 +268,7 @@ void whenCallingToStringThenResultIsExpected() throws IOException { // Then Result Is Expected assertThat(result, is( - "Context(registration=1d527164-ed0d-4b1d-9f9b-39aab0e4a089, instructor=Agent(super=Actor(name=Andrew Downes, mbox=mailto:andrew@example.co.uk, mboxSha1sum=null, openid=null, account=null)), team=Group(super=Actor(name=Example Group, mbox=null, mboxSha1sum=null, openid=null, account=null), member=null), contextActivities=ContextActivities(parent=[Activity(id=https://example.com/activity/1, definition=null)], grouping=[Activity(id=https://example.com/activity/2, definition=null)], category=[Activity(id=https://example.com/activity/3, definition=null)], other=[Activity(id=https://example.com/activity/4, definition=null)]), revision=revision, platform=platform, language=en, statement=StatementReference(id=e9b6b9ed-ef48-4986-9b86-2ef697578bf7), extensions={http://url=www.example.com})")); + "Context(registration=1d527164-ed0d-4b1d-9f9b-39aab0e4a089, instructor=Agent(super=Actor(name=Andrew Downes, mbox=mailto:andrew@example.co.uk, mboxSha1sum=null, openid=null, account=null)), team=Group(super=Actor(name=Example Group, mbox=null, mboxSha1sum=null, openid=null, account=null), member=null), contextActivities=ContextActivities(parent=[Activity(id=https://example.com/activity/1, definition=null)], grouping=[Activity(id=https://example.com/activity/2, definition=null)], category=[Activity(id=https://example.com/activity/3, definition=null)], other=[Activity(id=https://example.com/activity/4, definition=null)]), revision=revision, platform=platform, language=en_US, statement=StatementReference(id=e9b6b9ed-ef48-4986-9b86-2ef697578bf7), extensions={http://url=www.example.com})")); } diff --git a/xapi-model/src/test/java/dev/learning/xapi/model/InteractionComponentTests.java b/xapi-model/src/test/java/dev/learning/xapi/model/InteractionComponentTests.java index 05f986f0..6daa5363 100644 --- a/xapi-model/src/test/java/dev/learning/xapi/model/InteractionComponentTests.java +++ b/xapi-model/src/test/java/dev/learning/xapi/model/InteractionComponentTests.java @@ -75,7 +75,7 @@ void whenDeserializingInteractionComponentThenDescriptionIsExpected() throws Exc final InteractionComponent result = objectMapper.readValue(file, InteractionComponent.class); // Then Description Is Expected - assertThat(result.getDescription().get(Locale.ENGLISH), is("value")); + assertThat(result.getDescription().get(Locale.US), is("value")); } @@ -86,7 +86,7 @@ void whenSerializingInteractionComponentThenResultIsEqualToExpectedJson() throws .id("1") - .addDescription(Locale.ENGLISH, "value") + .addDescription(Locale.US, "value") .build(); @@ -111,7 +111,7 @@ void whenCallingToStringThenResultIsExpected() throws IOException { final String result = interactionComponent.toString(); // Then Result Is Expected - assertThat(result, is("InteractionComponent(id=1, description={en=value})")); + assertThat(result, is("InteractionComponent(id=1, description={en_US=value})")); } @@ -120,7 +120,7 @@ void whenBuildingInteractionComponentWithTwoDescriptionValuesThenDisplayLanguage // When Building InteractionComponent With Two Description Values final InteractionComponent interactionComponent = InteractionComponent.builder().id("1") - .addDescription(Locale.ENGLISH, "value").addDescription(Locale.GERMAN, "Wert").build(); + .addDescription(Locale.US, "value").addDescription(Locale.GERMAN, "Wert").build(); // Then Description Language Map Has Two Entries assertThat(interactionComponent.getDescription(), aMapWithSize(2)); @@ -131,7 +131,7 @@ void whenBuildingInteractionComponentWithTwoDescriptionValuesThenDisplayLanguage void whenValidatingInteractionComponentWithAllRequiredPropertiesThenConstraintViolationsSizeIsZero() { final InteractionComponent interactionComponent = - InteractionComponent.builder().id("1").addDescription(Locale.ENGLISH, "value").build(); + InteractionComponent.builder().id("1").addDescription(Locale.US, "value").build(); // When Validating Interaction Component With All Required Properties final Set> constraintViolations = @@ -146,7 +146,7 @@ void whenValidatingInteractionComponentWithAllRequiredPropertiesThenConstraintVi void whenValidatingInteractionComponentWithoutIdThenConstraintViolationsSizeIsOne() { final InteractionComponent interactionComponent = - InteractionComponent.builder().addDescription(Locale.ENGLISH, "value").build(); + InteractionComponent.builder().addDescription(Locale.US, "value").build(); // When Validating Interaction Component Without Id final Set> constraintViolations = diff --git a/xapi-model/src/test/java/dev/learning/xapi/model/LanguageMapTests.java b/xapi-model/src/test/java/dev/learning/xapi/model/LanguageMapTests.java index 2373e136..6cb22782 100644 --- a/xapi-model/src/test/java/dev/learning/xapi/model/LanguageMapTests.java +++ b/xapi-model/src/test/java/dev/learning/xapi/model/LanguageMapTests.java @@ -68,7 +68,7 @@ void givenFrenchAndEnglishKeyWhenGettingUSValueThenValueIsEnglish() throws Excep // Given French And English Key languageMap.put(Locale.FRENCH, "Couleur"); - languageMap.put(Locale.ENGLISH, "Color"); + languageMap.put(Locale.US, "Color"); // When Getting US Value final String value = languageMap.get(LanguageRange.parse("en-US")); diff --git a/xapi-model/src/test/java/dev/learning/xapi/model/StatementTests.java b/xapi-model/src/test/java/dev/learning/xapi/model/StatementTests.java index 7a2c3a28..52bf14b8 100644 --- a/xapi-model/src/test/java/dev/learning/xapi/model/StatementTests.java +++ b/xapi-model/src/test/java/dev/learning/xapi/model/StatementTests.java @@ -240,9 +240,9 @@ void whenSerializingStatementThenResultIsEqualToExpectedJson() throws IOExceptio final Attachment attachment = Attachment.builder().usageType(URI.create("http://example.com")) .fileUrl(URI.create("http://example.com")) - .addDisplay(Locale.ENGLISH, "value") + .addDisplay(Locale.US, "value") - .addDescription(Locale.ENGLISH, "value") + .addDescription(Locale.US, "value") .length(123) @@ -282,7 +282,7 @@ void whenSerializingStatementThenResultIsEqualToExpectedJson() throws IOExceptio .platform("Example virtual meeting software") - .language(Locale.ENGLISH) + .language(Locale.US) .statementReference(s -> s.id(UUID.fromString("6690e6c9-3ef0-4ed3-8b37-7f3964730bee"))) @@ -296,10 +296,10 @@ void whenSerializingStatementThenResultIsEqualToExpectedJson() throws IOExceptio .activityObject(a -> a.id("http://www.example.com/meetings/occurances/34534") - .definition(d -> d.addName(Locale.UK, + .definition(d -> d.addName(Locale.US, "A simple Experience API statement. Note that the LRS does not need to have any prior information about the Actor (learner), the verb, or the Activity/object.") - .addDescription(Locale.UK, + .addDescription(Locale.US, "A simple Experience API statement. Note that the LRS does not need to have any prior information about the Actor (learner), the verb, or the Activity/object.") .type(URI.create("http://adlnet.gov/expapi/activities/meeting")) @@ -324,6 +324,100 @@ void whenSerializingStatementThenResultIsEqualToExpectedJson() throws IOExceptio } + @Test + void whenSerializingStatementWithEnLocaleThenResultIsEqualToExpectedJson() throws IOException { + + final LinkedHashMap extensions = new LinkedHashMap<>(); + extensions.put(URI.create("http://name"), "Kilby"); + + final Attachment attachment = Attachment.builder().usageType(URI.create("http://example.com")) + .fileUrl(URI.create("http://example.com")) + + .addDisplay(Locale.ENGLISH, "value") + + .addDescription(Locale.ENGLISH, "value") + + .length(123) + + .sha2("123") + + .contentType("file") + + .build(); + + final Account account = Account.builder() + + .homePage(URI.create("https://example.com")) + + .name("13936749") + + .build(); + + + final Statement statement = Statement.builder() + + .id(UUID.fromString("4b9175ba-367d-4b93-990b-34d4180039f1")) + + .actor(a -> a.name("A N Other")) + + .verb(v -> v.id(URI.create("http://example.com/xapi/verbs#sent-a-statement")) + .addDisplay(Locale.ENGLISH, "attended")) + + .result(r -> r.success(true).completion(true).response("Response").duration("P1D")) + + .context(c -> c + + .registration(UUID.fromString("ec531277-b57b-4c15-8d91-d292c5b2b8f7")) + + .agentInstructor(a -> a.name("A N Other").account(account)) + + .team(t -> t.name("Team").mbox("mailto:team@example.com")) + + .platform("Example virtual meeting software") + + .language(Locale.ENGLISH) + + .statementReference(s -> s.id(UUID.fromString("6690e6c9-3ef0-4ed3-8b37-7f3964730bee"))) + + ) + + .timestamp(Instant.parse("2013-05-18T05:32:34.804+00:00")) + + .stored(Instant.parse("2013-05-18T05:32:34.804+00:00")) + + .agentAuthority(a -> a.account(account)) + + .activityObject(a -> a.id("http://www.example.com/meetings/occurances/34534") + + .definition(d -> d.addName(Locale.ENGLISH, + "A simple Experience API statement. Note that the LRS does not need to have any prior information about the Actor (learner), the verb, or the Activity/object.") + + .addDescription(Locale.ENGLISH, + "A simple Experience API statement. Note that the LRS does not need to have any prior information about the Actor (learner), the verb, or the Activity/object.") + + .type(URI.create("http://adlnet.gov/expapi/activities/meeting")) + + .moreInfo(URI.create("http://virtualmeeting.example.com/345256")) + + .extensions(extensions))) + + .attachments(Collections.singletonList(attachment)) + + .version("1.0.0") + + .build(); + + // When Serializing Statement With En Locale + final JsonNode result = objectMapper.readTree(objectMapper.writeValueAsString(statement)); + + // Then Result Is Equal To Expected Json + assertThat(result, + is(objectMapper.readTree(objectMapper.writeValueAsString(objectMapper.readValue( + ResourceUtils.getFile("classpath:statement/statement_with_en_locale.json"), + Statement.class))))); + + } + @Test void givenStatementWithPassedVerbWhenCallingToBuilderAndSettingVerbToCompletedThenResultVerbIsCompleted() { diff --git a/xapi-model/src/test/java/dev/learning/xapi/model/SubStatementTests.java b/xapi-model/src/test/java/dev/learning/xapi/model/SubStatementTests.java index 4d5e903c..da8eb198 100644 --- a/xapi-model/src/test/java/dev/learning/xapi/model/SubStatementTests.java +++ b/xapi-model/src/test/java/dev/learning/xapi/model/SubStatementTests.java @@ -281,7 +281,7 @@ void whenSerializingSubStatementThenResultIsEqualToExpectedJson() throws IOExcep .platform("platform") - .language(Locale.forLanguageTag("en")) + .language(Locale.US) .instructor(agent) @@ -298,9 +298,9 @@ void whenSerializingSubStatementThenResultIsEqualToExpectedJson() throws IOExcep final Attachment attachment = Attachment.builder().usageType(URI.create("http://example.com")) .fileUrl(URI.create("http://example.com")) - .addDisplay(Locale.ENGLISH, "value") + .addDisplay(Locale.US, "value") - .addDescription(Locale.ENGLISH, "value") + .addDescription(Locale.US, "value") .length(123) @@ -316,7 +316,7 @@ void whenSerializingSubStatementThenResultIsEqualToExpectedJson() throws IOExcep .actor(agent) - .verb(v -> v.id(URI.create("http://example.com/confirmed")).addDisplay(Locale.ENGLISH, + .verb(v -> v.id(URI.create("http://example.com/confirmed")).addDisplay(Locale.US, "confirmed")) .object(statementRef) @@ -352,7 +352,7 @@ void whenCallingToStringThenResultIsExpected() throws IOException { // Then Result Is Expected assertThat(result, is( - "SubStatement(actor=Agent(super=Actor(name=null, mbox=mailto:agent@example.com, mboxSha1sum=null, openid=null, account=null)), verb=Verb(id=http://example.com/confirmed, display={en=confirmed}), object=StatementReference(id=9e13cefd-53d3-4eac-b5ed-2cf6693903bb), result=Result(score=Score(scaled=1.0, raw=1.0, min=0.0, max=5.0), success=true, completion=true, response=test, duration=P1D, extensions=null), context=Context(registration=6d969975-8d7e-4506-ac19-877c57f2921a, instructor=Agent(super=Actor(name=null, mbox=mailto:agent@example.com, mboxSha1sum=null, openid=null, account=null)), team=Group(super=Actor(name=Example Group, mbox=null, mboxSha1sum=null, openid=null, account=null), member=null), contextActivities=ContextActivities(parent=[Activity(id=http://www.example.co.uk/exampleactivity, definition=null)], grouping=[Activity(id=http://www.example.co.uk/exampleactivity, definition=null)], category=[Activity(id=http://www.example.co.uk/exampleactivity, definition=null)], other=[Activity(id=http://www.example.co.uk/exampleactivity, definition=null)]), revision=revision, platform=platform, language=en, statement=StatementReference(id=9e13cefd-53d3-4eac-b5ed-2cf6693903bb), extensions={http://url=www.example.com}), timestamp=2015-11-18T11:17:00Z, attachments=[Attachment(usageType=http://example.com, display={en=value}, description={en=value}, contentType=file, length=123, sha2=123, fileUrl=http://example.com)])")); + "SubStatement(actor=Agent(super=Actor(name=null, mbox=mailto:agent@example.com, mboxSha1sum=null, openid=null, account=null)), verb=Verb(id=http://example.com/confirmed, display={en_US=confirmed}), object=StatementReference(id=9e13cefd-53d3-4eac-b5ed-2cf6693903bb), result=Result(score=Score(scaled=1.0, raw=1.0, min=0.0, max=5.0), success=true, completion=true, response=test, duration=P1D, extensions=null), context=Context(registration=6d969975-8d7e-4506-ac19-877c57f2921a, instructor=Agent(super=Actor(name=null, mbox=mailto:agent@example.com, mboxSha1sum=null, openid=null, account=null)), team=Group(super=Actor(name=Example Group, mbox=null, mboxSha1sum=null, openid=null, account=null), member=null), contextActivities=ContextActivities(parent=[Activity(id=http://www.example.co.uk/exampleactivity, definition=null)], grouping=[Activity(id=http://www.example.co.uk/exampleactivity, definition=null)], category=[Activity(id=http://www.example.co.uk/exampleactivity, definition=null)], other=[Activity(id=http://www.example.co.uk/exampleactivity, definition=null)]), revision=revision, platform=platform, language=en_US, statement=StatementReference(id=9e13cefd-53d3-4eac-b5ed-2cf6693903bb), extensions={http://url=www.example.com}), timestamp=2015-11-18T11:17:00Z, attachments=[Attachment(usageType=http://example.com, display={en_US=value}, description={en_US=value}, contentType=file, length=123, sha2=123, fileUrl=http://example.com)])")); } diff --git a/xapi-model/src/test/java/dev/learning/xapi/model/VerbTests.java b/xapi-model/src/test/java/dev/learning/xapi/model/VerbTests.java index 6b660629..5017dcda 100644 --- a/xapi-model/src/test/java/dev/learning/xapi/model/VerbTests.java +++ b/xapi-model/src/test/java/dev/learning/xapi/model/VerbTests.java @@ -78,7 +78,7 @@ void whenSerializingVerbThenResultIsEqualToExpectedJson() throws IOException { .id(URI.create("http://adlnet.gov/expapi/verbs/answered")) - .addDisplay(Locale.ENGLISH, "answered") + .addDisplay(Locale.US, "answered") .build(); @@ -128,7 +128,7 @@ void whenCallingToStringThenResultIsExpected() throws IOException { // Then Result Is Expected assertThat(result, - is("Verb(id=http://adlnet.gov/expapi/verbs/answered, display={en=answered})")); + is("Verb(id=http://adlnet.gov/expapi/verbs/answered, display={en_US=answered})")); } @@ -187,7 +187,7 @@ void whenBuildingVerbWithTwoDisplayValuesThenDisplayLanguageMapHasTwoEntries() { .id("http://adlnet.gov/expapi/verbs/answered") - .addDisplay(Locale.ENGLISH, "answered") + .addDisplay(Locale.US, "answered") .addDisplay(Locale.GERMAN, "antwortete") @@ -217,7 +217,7 @@ void givenVerbWithoutDisplayPropertyWhenTestingEqualityWithVerbWithDisplayProper .id("http://adlnet.gov/expapi/verbs/answered") - .addDisplay(Locale.ENGLISH, "answered") + .addDisplay(Locale.US, "answered") .build()); @@ -243,7 +243,7 @@ void givenVerbWithGermanDisplayPropertyWhenTestingEqualityWithVerbWithEnglishDis .id("http://adlnet.gov/expapi/verbs/answered") - .addDisplay(Locale.ENGLISH, "answered") + .addDisplay(Locale.US, "answered") .build()); @@ -318,7 +318,7 @@ void givenVerbDoesNotHaveIdVoidedWhenCallingIsVoidedThenResultIsFalse() { void whenValidatingVerbWithAllRequiredPropertiesThenConstraintViolationsSizeIsZero() { final Verb verb = Verb.builder().id("http://adlnet.gov/expapi/verbs/answered") - .addDisplay(Locale.ENGLISH, "answered").build(); + .addDisplay(Locale.US, "answered").build(); // When Validating Interaction Component With All Required Properties final Set> constraintViolations = validator.validate(verb); @@ -331,7 +331,7 @@ void whenValidatingVerbWithAllRequiredPropertiesThenConstraintViolationsSizeIsZe @Test void whenValidatingVerbWithoutIdThenConstraintViolationsSizeIsOne() { - final Verb verb = Verb.builder().addDisplay(Locale.ENGLISH, "answered").build(); + final Verb verb = Verb.builder().addDisplay(Locale.US, "answered").build(); // When Validating Interaction Component Without Id final Set> constraintViolations = validator.validate(verb); diff --git a/xapi-model/src/test/resources/activity/activity.json b/xapi-model/src/test/resources/activity/activity.json index b4627ef1..138307a8 100644 --- a/xapi-model/src/test/resources/activity/activity.json +++ b/xapi-model/src/test/resources/activity/activity.json @@ -2,10 +2,10 @@ "id":"http://example.com/xapi/activity/simplestatement", "definition":{ "name":{ - "en":"simple statement" + "en-US":"simple statement" }, "description":{ - "en":"A simple Experience API statement. Note that the LRS does not need to have any prior information about the Actor (learner), the verb, or the Activity/object." + "en-US":"A simple Experience API statement. Note that the LRS does not need to have any prior information about the Actor (learner), the verb, or the Activity/object." } } } \ No newline at end of file diff --git a/xapi-model/src/test/resources/activity/activity_with_object_type.json b/xapi-model/src/test/resources/activity/activity_with_object_type.json index adfae696..b9825af2 100644 --- a/xapi-model/src/test/resources/activity/activity_with_object_type.json +++ b/xapi-model/src/test/resources/activity/activity_with_object_type.json @@ -3,10 +3,10 @@ "id":"http://example.com/xapi/activity/simplestatement", "definition":{ "name":{ - "en":"simple statement" + "en-US":"simple statement" }, "description":{ - "en":"A simple Experience API statement. Note that the LRS does not need to have any prior information about the Actor (learner), the verb, or the Activity/object." + "en-US":"A simple Experience API statement. Note that the LRS does not need to have any prior information about the Actor (learner), the verb, or the Activity/object." } } } \ No newline at end of file diff --git a/xapi-model/src/test/resources/activity_definition/activity_definition.json b/xapi-model/src/test/resources/activity_definition/activity_definition.json index b6cad8f5..31a19763 100644 --- a/xapi-model/src/test/resources/activity_definition/activity_definition.json +++ b/xapi-model/src/test/resources/activity_definition/activity_definition.json @@ -6,40 +6,40 @@ "http://url" : "www.example.com" }, "name" : { - "en" : "Does the xAPI include the concept of statements?" + "en-US" : "Does the xAPI include the concept of statements?" }, "description" : { - "en" : "pong[.]1:[,]dg[.]:10[,]lunch[.]" + "en-US" : "pong[.]1:[,]dg[.]:10[,]lunch[.]" }, "type" : "http://adlnet.gov/expapi/activities/cmi.interaction", "choices" : [ { "id" : "1", "description" : { - "en" : "Does the xAPI include the concept of statements?" + "en-US" : "Does the xAPI include the concept of statements?" } } ], "scale" : [ { "id" : "1", "description" : { - "en" : "Does the xAPI include the concept of statements?" + "en-US" : "Does the xAPI include the concept of statements?" } } ], "source" : [ { "id" : "1", "description" : { - "en" : "Does the xAPI include the concept of statements?" + "en-US" : "Does the xAPI include the concept of statements?" } } ], "target" : [ { "id" : "1", "description" : { - "en" : "Does the xAPI include the concept of statements?" + "en-US" : "Does the xAPI include the concept of statements?" } } ], "steps" : [ { "id" : "1", "description" : { - "en" : "Does the xAPI include the concept of statements?" + "en-US" : "Does the xAPI include the concept of statements?" } } ] } diff --git a/xapi-model/src/test/resources/activity_definition/activity_definition_without_type.json b/xapi-model/src/test/resources/activity_definition/activity_definition_without_type.json index 505fb28e..90c3470c 100644 --- a/xapi-model/src/test/resources/activity_definition/activity_definition_without_type.json +++ b/xapi-model/src/test/resources/activity_definition/activity_definition_without_type.json @@ -1,6 +1,6 @@ { "description": { - "en": "Does the xAPI include the concept of statements?" + "en-US": "Does the xAPI include the concept of statements?" }, "interactionType": "fill-in", "correctResponsesPattern": [ diff --git a/xapi-model/src/test/resources/activity_definition/choice.json b/xapi-model/src/test/resources/activity_definition/choice.json index 1d1bfbad..cf411f4a 100644 --- a/xapi-model/src/test/resources/activity_definition/choice.json +++ b/xapi-model/src/test/resources/activity_definition/choice.json @@ -1,9 +1,9 @@ { "name": { - "en": "Choice" + "en-US": "Choice" }, "description": { - "en": "Which of these prototypes are available at the beta site?" + "en-US": "Which of these prototypes are available at the beta site?" }, "type": "http://adlnet.gov/expapi/activities/cmi.interaction", "interactionType": "choice", @@ -14,25 +14,25 @@ { "id": "golf", "description": { - "en": "Golf Example" + "en-US": "Golf Example" } }, { "id": "facebook", "description": { - "en": "Facebook App" + "en-US": "Facebook App" } }, { "id": "tetris", "description": { - "en": "Tetris Example" + "en-US": "Tetris Example" } }, { "id": "scrabble", "description": { - "en": "Scrabble Example" + "en-US": "Scrabble Example" } } ] diff --git a/xapi-model/src/test/resources/activity_definition/true_false.json b/xapi-model/src/test/resources/activity_definition/true_false.json index 6523da45..b1a64e3a 100644 --- a/xapi-model/src/test/resources/activity_definition/true_false.json +++ b/xapi-model/src/test/resources/activity_definition/true_false.json @@ -1,9 +1,9 @@ { "name":{ - "en":"True false question" + "en-US":"True false question" }, "description":{ - "en":"Does the xAPI include the concept of statements?" + "en-US":"Does the xAPI include the concept of statements?" }, "type":"http://adlnet.gov/expapi/activities/cmi.interaction", "interactionType":"true-false", diff --git a/xapi-model/src/test/resources/context/context.json b/xapi-model/src/test/resources/context/context.json index 06d476a4..bb044dca 100644 --- a/xapi-model/src/test/resources/context/context.json +++ b/xapi-model/src/test/resources/context/context.json @@ -2,7 +2,7 @@ "registration": "1d527164-ed0d-4b1d-9f9b-39aab0e4a089", "revision": "revision", "platform": "platform", - "language": "en", + "language": "en-US", "instructor": { "objectType": "Agent", "name": "Andrew Downes", diff --git a/xapi-model/src/test/resources/context/context_with_empty_registration.json b/xapi-model/src/test/resources/context/context_with_empty_registration.json index 990ffb74..59e0f7af 100644 --- a/xapi-model/src/test/resources/context/context_with_empty_registration.json +++ b/xapi-model/src/test/resources/context/context_with_empty_registration.json @@ -2,7 +2,7 @@ "registration": "", "revision": "revision", "platform": "platform", - "language": "en", + "language": "en-US", "instructor": { "name": "Andrew Downes", "mbox": "mailto:andrew@example.co.uk" diff --git a/xapi-model/src/test/resources/context/context_without_registration.json b/xapi-model/src/test/resources/context/context_without_registration.json index cd324ee9..50f37e08 100644 --- a/xapi-model/src/test/resources/context/context_without_registration.json +++ b/xapi-model/src/test/resources/context/context_without_registration.json @@ -1,7 +1,7 @@ { "revision": "revision", "platform": "platform", - "language": "en", + "language": "en-US", "instructor": { "name": "Andrew Downes", "mbox": "mailto:andrew@example.co.uk" diff --git a/xapi-model/src/test/resources/interaction_component/interaction_component.json b/xapi-model/src/test/resources/interaction_component/interaction_component.json index b01f6834..546d196b 100644 --- a/xapi-model/src/test/resources/interaction_component/interaction_component.json +++ b/xapi-model/src/test/resources/interaction_component/interaction_component.json @@ -1,6 +1,6 @@ { "id": "1", "description": { - "en": "value" + "en-US": "value" } } diff --git a/xapi-model/src/test/resources/statement/statement.json b/xapi-model/src/test/resources/statement/statement.json index c0b6e5ee..32014dce 100644 --- a/xapi-model/src/test/resources/statement/statement.json +++ b/xapi-model/src/test/resources/statement/statement.json @@ -32,7 +32,7 @@ "objectType": "Group" }, "platform": "Example virtual meeting software", - "language": "en", + "language": "en-US", "statement": { "objectType": "StatementRef", "id": "6690e6c9-3ef0-4ed3-8b37-7f3964730bee" @@ -55,10 +55,10 @@ "http://name": "Kilby" }, "name": { - "en-GB": "A simple Experience API statement. Note that the LRS does not need to have any prior information about the Actor (learner), the verb, or the Activity/object." + "en-US": "A simple Experience API statement. Note that the LRS does not need to have any prior information about the Actor (learner), the verb, or the Activity/object." }, "description": { - "en-GB": "A simple Experience API statement. Note that the LRS does not need to have any prior information about the Actor (learner), the verb, or the Activity/object." + "en-US": "A simple Experience API statement. Note that the LRS does not need to have any prior information about the Actor (learner), the verb, or the Activity/object." }, "type": "http://adlnet.gov/expapi/activities/meeting", "moreInfo": "http://virtualmeeting.example.com/345256" @@ -69,10 +69,10 @@ { "usageType": "http://example.com", "display": { - "en": "value" + "en-US": "value" }, "description": { - "en": "value" + "en-US": "value" }, "contentType": "file", "length": 123, diff --git a/xapi-model/src/test/resources/statement/statement_with_en_locale.json b/xapi-model/src/test/resources/statement/statement_with_en_locale.json new file mode 100644 index 00000000..7ecf41b0 --- /dev/null +++ b/xapi-model/src/test/resources/statement/statement_with_en_locale.json @@ -0,0 +1,83 @@ +{ + "id": "4b9175ba-367d-4b93-990b-34d4180039f1", + "actor": { + "name": "A N Other", + "objectType": "Agent" + }, + "verb": { + "id": "http://example.com/xapi/verbs#sent-a-statement", + "display": { + "en": "attended" + } + }, + "result": { + "success": true, + "completion": true, + "response": "Response", + "duration": "P1D" + }, + "context": { + "registration": "ec531277-b57b-4c15-8d91-d292c5b2b8f7", + "instructor": { + "name": "A N Other", + "account": { + "homePage": "https://example.com", + "name": "13936749" + }, + "objectType": "Agent" + }, + "team": { + "name": "Team", + "mbox": "mailto:team@example.com", + "objectType": "Group" + }, + "platform": "Example virtual meeting software", + "language": "en", + "statement": { + "objectType": "StatementRef", + "id": "6690e6c9-3ef0-4ed3-8b37-7f3964730bee" + } + }, + "timestamp": "2013-05-18T05:32:34.804+00:00", + "stored": "2013-05-18T05:32:34.804+00:00", + "authority": { + "account": { + "homePage": "https://example.com", + "name": "13936749" + }, + "objectType": "Agent" + }, + "version": "1.0.0", + "object": { + "id": "http://www.example.com/meetings/occurances/34534", + "definition": { + "extensions": { + "http://name": "Kilby" + }, + "name": { + "en": "A simple Experience API statement. Note that the LRS does not need to have any prior information about the Actor (learner), the verb, or the Activity/object." + }, + "description": { + "en": "A simple Experience API statement. Note that the LRS does not need to have any prior information about the Actor (learner), the verb, or the Activity/object." + }, + "type": "http://adlnet.gov/expapi/activities/meeting", + "moreInfo": "http://virtualmeeting.example.com/345256" + }, + "objectType": "Activity" + }, + "attachments": [ + { + "usageType": "http://example.com", + "display": { + "en": "value" + }, + "description": { + "en": "value" + }, + "contentType": "file", + "length": 123, + "sha2": "123", + "fileUrl": "http://example.com" + } + ] +} diff --git a/xapi-model/src/test/resources/sub_statement/sub_statement.json b/xapi-model/src/test/resources/sub_statement/sub_statement.json index 58955494..a4db3e02 100644 --- a/xapi-model/src/test/resources/sub_statement/sub_statement.json +++ b/xapi-model/src/test/resources/sub_statement/sub_statement.json @@ -4,7 +4,7 @@ "verb" : { "id" : "http://example.com/confirmed", "display" : { - "en" : "confirmed" + "en-US" : "confirmed" } }, "actor" : { @@ -31,7 +31,7 @@ "registration" : "6d969975-8d7e-4506-ac19-877c57f2921a", "revision" : "revision", "platform" : "platform", - "language" : "en", + "language" : "en-US", "instructor" : { "objectType" : "Agent", "mbox" : "mailto:agent@example.com" @@ -69,10 +69,10 @@ "attachments" : [ { "usageType" : "http://example.com", "display" : { - "en" : "value" + "en-US" : "value" }, "description" : { - "en" : "value" + "en-US" : "value" }, "contentType" : "file", "length" : 123, diff --git a/xapi-model/src/test/resources/sub_statement/sub_statement_with_object_of_type_sub_statement.json b/xapi-model/src/test/resources/sub_statement/sub_statement_with_object_of_type_sub_statement.json index 4b6cd007..e5c65d94 100644 --- a/xapi-model/src/test/resources/sub_statement/sub_statement_with_object_of_type_sub_statement.json +++ b/xapi-model/src/test/resources/sub_statement/sub_statement_with_object_of_type_sub_statement.json @@ -19,7 +19,7 @@ "verb":{ "id":"http://example.com/confirmed", "display":{ - "en":"confirmed" + "en-US":"confirmed" } }, "object":{ diff --git a/xapi-model/src/test/resources/verb/verb.json b/xapi-model/src/test/resources/verb/verb.json index 78c1c7c7..5d9236b9 100644 --- a/xapi-model/src/test/resources/verb/verb.json +++ b/xapi-model/src/test/resources/verb/verb.json @@ -1,6 +1,6 @@ { "id": "http://adlnet.gov/expapi/verbs/answered", "display": { - "en": "answered" + "en-US": "answered" } }