Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/test/java/com/cosium/hal_model2/HalFormsBodyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,13 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import tools.jackson.core.type.TypeReference;
import tools.jackson.databind.json.JsonMapper;
import tools.jackson.jr.ob.JSON;

/**
* @author Réda Housni Alaoui
*/
class HalFormsBodyTest {

private static final JsonMapper JSON_MAPPER =
JsonMapper.builder().addModule(new HalModelJacksonModule()).build();

@Test
@DisplayName("Parse atomic value")
void test1() {
Expand All @@ -45,7 +41,8 @@ void test1() {
.end()
.finish();

HalFormsBody<User> halFormsBody = JSON_MAPPER.readValue(json, new TypeReference<>() {});
HalFormsBody<User> halFormsBody =
TestJsonMapper.INSTANCE.readValue(json, new TypeReference<>() {});
assertThat(halFormsBody.representation().username()).isEqualTo("jdoe");
assertThat(halFormsBody.linkByName()).containsOnlyKeys("self");
assertThat(halFormsBody.requireLink("self").href().expand())
Expand Down Expand Up @@ -94,7 +91,7 @@ void test2() {
.finish();

HalFormsBody<EmbeddedContainer<ContentList<String>>> halFormsBody =
JSON_MAPPER.readValue(json, new TypeReference<>() {});
TestJsonMapper.INSTANCE.readValue(json, new TypeReference<>() {});
assertThat(halFormsBody.representation().requireEmbedded().content())
.containsExactly("element1", "element2");
assertThat(halFormsBody.linkByName()).containsOnlyKeys("self");
Expand Down
12 changes: 4 additions & 8 deletions src/test/java/com/cosium/hal_model2/OptionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@
import java.util.Map;
import org.junit.jupiter.api.Test;
import tools.jackson.core.type.TypeReference;
import tools.jackson.databind.json.JsonMapper;
import tools.jackson.jr.ob.JSON;

/**
* @author Réda Housni Alaoui
*/
class OptionsTest {

private static final JsonMapper JSON_MAPPER =
JsonMapper.builder().addModule(new HalModelJacksonModule()).build();

@Test
void inlineOfStringArray() {

Expand Down Expand Up @@ -52,7 +48,7 @@ void inlineOfStringArray() {
.finish();

Options options =
JSON_MAPPER
TestJsonMapper.INSTANCE
.<HalFormsBody<Void>>readValue(json, new TypeReference<>() {})
.requireTemplate("default")
.propertyByName()
Expand Down Expand Up @@ -121,7 +117,7 @@ void referenceProperties() {
.finish();

Options options =
JSON_MAPPER
TestJsonMapper.INSTANCE
.<HalFormsBody<Void>>readValue(json, new TypeReference<>() {})
.requireTemplate("default")
.propertyByName()
Expand Down Expand Up @@ -194,7 +190,7 @@ void multipleReturnValues() {
.finish();

Options options =
JSON_MAPPER
TestJsonMapper.INSTANCE
.<HalFormsBody<Void>>readValue(json, new TypeReference<>() {})
.requireTemplate("default")
.propertyByName()
Expand Down Expand Up @@ -255,7 +251,7 @@ void externalArrayOfValues() {
.finish();

Options options =
JSON_MAPPER
TestJsonMapper.INSTANCE
.<HalFormsBody<Void>>readValue(json, new TypeReference<>() {})
.requireTemplate("default")
.propertyByName()
Expand Down
52 changes: 32 additions & 20 deletions src/test/java/com/cosium/hal_model2/TemplateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import tools.jackson.core.type.TypeReference;
import tools.jackson.databind.json.JsonMapper;
import tools.jackson.jr.ob.JSON;

/**
* @author Réda Housni Alaoui
*/
class TemplateTest {

private static final JsonMapper JSON_MAPPER =
JsonMapper.builder().addModule(new HalModelJacksonModule()).build();

@Test
@DisplayName("Parse template title")
void test1() {
Expand All @@ -37,7 +33,8 @@ void test1() {
.end()
.finish();

HalFormsBody<Void> formsBody = JSON_MAPPER.readValue(json, new TypeReference<>() {});
HalFormsBody<Void> formsBody =
TestJsonMapper.INSTANCE.readValue(json, new TypeReference<>() {});

assertThat(formsBody.linkByName()).containsOnlyKeys("self");
assertThat(formsBody.requireLink("self").href().expand())
Expand Down Expand Up @@ -75,7 +72,8 @@ void test2() {
.end()
.finish();

HalFormsBody<Void> formsBody = JSON_MAPPER.readValue(json, new TypeReference<>() {});
HalFormsBody<Void> formsBody =
TestJsonMapper.INSTANCE.readValue(json, new TypeReference<>() {});

assertThat(formsBody.linkByName()).containsOnlyKeys("self");
assertThat(formsBody.requireLink("self").href().expand())
Expand Down Expand Up @@ -116,7 +114,8 @@ void test3() {
.end()
.finish();

HalFormsBody<Void> formsBody = JSON_MAPPER.readValue(json, new TypeReference<>() {});
HalFormsBody<Void> formsBody =
TestJsonMapper.INSTANCE.readValue(json, new TypeReference<>() {});

assertThat(formsBody.linkByName()).containsOnlyKeys("self");
assertThat(formsBody.requireLink("self").href().expand())
Expand Down Expand Up @@ -157,7 +156,8 @@ void test4() {
.end()
.finish();

HalFormsBody<Void> formsBody = JSON_MAPPER.readValue(json, new TypeReference<>() {});
HalFormsBody<Void> formsBody =
TestJsonMapper.INSTANCE.readValue(json, new TypeReference<>() {});

assertThat(formsBody.linkByName()).containsOnlyKeys("self");
assertThat(formsBody.requireLink("self").href().expand())
Expand Down Expand Up @@ -198,7 +198,8 @@ void test5() {
.end()
.finish();

HalFormsBody<Void> formsBody = JSON_MAPPER.readValue(json, new TypeReference<>() {});
HalFormsBody<Void> formsBody =
TestJsonMapper.INSTANCE.readValue(json, new TypeReference<>() {});

assertThat(formsBody.linkByName()).containsOnlyKeys("self");
assertThat(formsBody.requireLink("self").href().expand())
Expand Down Expand Up @@ -239,7 +240,8 @@ void test6() {
.end()
.finish();

HalFormsBody<Void> formsBody = JSON_MAPPER.readValue(json, new TypeReference<>() {});
HalFormsBody<Void> formsBody =
TestJsonMapper.INSTANCE.readValue(json, new TypeReference<>() {});

assertThat(formsBody.linkByName()).containsOnlyKeys("self");
assertThat(formsBody.requireLink("self").href().expand())
Expand Down Expand Up @@ -280,7 +282,8 @@ void test7() {
.end()
.finish();

HalFormsBody<Void> formsBody = JSON_MAPPER.readValue(json, new TypeReference<>() {});
HalFormsBody<Void> formsBody =
TestJsonMapper.INSTANCE.readValue(json, new TypeReference<>() {});

assertThat(formsBody.linkByName()).containsOnlyKeys("self");
assertThat(formsBody.requireLink("self").href().expand())
Expand Down Expand Up @@ -321,7 +324,8 @@ void test8() {
.end()
.finish();

HalFormsBody<Void> formsBody = JSON_MAPPER.readValue(json, new TypeReference<>() {});
HalFormsBody<Void> formsBody =
TestJsonMapper.INSTANCE.readValue(json, new TypeReference<>() {});

assertThat(formsBody.linkByName()).containsOnlyKeys("self");
assertThat(formsBody.requireLink("self").href().expand())
Expand Down Expand Up @@ -362,7 +366,8 @@ void test10() {
.end()
.finish();

HalFormsBody<Void> formsBody = JSON_MAPPER.readValue(json, new TypeReference<>() {});
HalFormsBody<Void> formsBody =
TestJsonMapper.INSTANCE.readValue(json, new TypeReference<>() {});

assertThat(formsBody.linkByName()).containsOnlyKeys("self");
assertThat(formsBody.requireLink("self").href().expand())
Expand Down Expand Up @@ -403,7 +408,8 @@ void test11() {
.end()
.finish();

HalFormsBody<Void> formsBody = JSON_MAPPER.readValue(json, new TypeReference<>() {});
HalFormsBody<Void> formsBody =
TestJsonMapper.INSTANCE.readValue(json, new TypeReference<>() {});

assertThat(formsBody.linkByName()).containsOnlyKeys("self");
assertThat(formsBody.requireLink("self").href().expand())
Expand Down Expand Up @@ -444,7 +450,8 @@ void test12() {
.end()
.finish();

HalFormsBody<Void> formsBody = JSON_MAPPER.readValue(json, new TypeReference<>() {});
HalFormsBody<Void> formsBody =
TestJsonMapper.INSTANCE.readValue(json, new TypeReference<>() {});

assertThat(formsBody.linkByName()).containsOnlyKeys("self");
assertThat(formsBody.requireLink("self").href().expand())
Expand Down Expand Up @@ -485,7 +492,8 @@ void test13() {
.end()
.finish();

HalFormsBody<Void> formsBody = JSON_MAPPER.readValue(json, new TypeReference<>() {});
HalFormsBody<Void> formsBody =
TestJsonMapper.INSTANCE.readValue(json, new TypeReference<>() {});

assertThat(formsBody.linkByName()).containsOnlyKeys("self");
assertThat(formsBody.requireLink("self").href().expand())
Expand Down Expand Up @@ -526,7 +534,8 @@ void test14() {
.end()
.finish();

HalFormsBody<Void> formsBody = JSON_MAPPER.readValue(json, new TypeReference<>() {});
HalFormsBody<Void> formsBody =
TestJsonMapper.INSTANCE.readValue(json, new TypeReference<>() {});

assertThat(formsBody.linkByName()).containsOnlyKeys("self");
assertThat(formsBody.requireLink("self").href().expand())
Expand Down Expand Up @@ -567,7 +576,8 @@ void test15() {
.end()
.finish();

HalFormsBody<Void> formsBody = JSON_MAPPER.readValue(json, new TypeReference<>() {});
HalFormsBody<Void> formsBody =
TestJsonMapper.INSTANCE.readValue(json, new TypeReference<>() {});

assertThat(formsBody.linkByName()).containsOnlyKeys("self");
assertThat(formsBody.requireLink("self").href().expand())
Expand Down Expand Up @@ -602,7 +612,8 @@ void test16() {
.end()
.finish();

HalFormsBody<Void> formsBody = JSON_MAPPER.readValue(json, new TypeReference<>() {});
HalFormsBody<Void> formsBody =
TestJsonMapper.INSTANCE.readValue(json, new TypeReference<>() {});

assertThat(formsBody.linkByName()).containsOnlyKeys("self");
assertThat(formsBody.requireLink("self").href().expand())
Expand Down Expand Up @@ -634,7 +645,8 @@ void test17() {
.end()
.finish();

HalFormsBody<Void> formsBody = JSON_MAPPER.readValue(json, new TypeReference<>() {});
HalFormsBody<Void> formsBody =
TestJsonMapper.INSTANCE.readValue(json, new TypeReference<>() {});

assertThat(formsBody.linkByName()).containsOnlyKeys("self");
assertThat(formsBody.requireLink("self").href().expand())
Expand Down
23 changes: 23 additions & 0 deletions src/test/java/com/cosium/hal_model2/TestJsonMapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.cosium.hal_model2;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import tools.jackson.databind.json.JsonMapper;

/**
* @author Réda Housni Alaoui
*/
class TestJsonMapper {

public static final JsonMapper INSTANCE =
JsonMapper.builder()
.addModule(new HalModelJacksonModule())
.changeDefaultVisibility(
visibilityChecker ->
visibilityChecker
.withCreatorVisibility(JsonAutoDetect.Visibility.NONE)
.withFieldVisibility(JsonAutoDetect.Visibility.NONE)
.withGetterVisibility(JsonAutoDetect.Visibility.NONE)
.withIsGetterVisibility(JsonAutoDetect.Visibility.NONE)
.withSetterVisibility(JsonAutoDetect.Visibility.NONE))
.build();
}
Loading