Skip to content

Commit

Permalink
GH-2262 - Polishing.
Browse files Browse the repository at this point in the history
  • Loading branch information
odrotbohm committed Dec 10, 2024
1 parent d7c8133 commit 5d5966c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public interface HalFormsOptions {
* @param values must not be {@literal null}.
* @return will never be {@literal null}.
*/
@SuppressWarnings("unchecked")
@SafeVarargs
public static <T> Inline inline(T... values) {

Assert.notNull(values, "Values must not be null!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,15 +573,31 @@ void rendersPromptedOptionsValues() throws Exception {
.isEqualTo("My Prompt");
}

@Test
// #2257
@Test // #1483
void rendersRemoteOptions() {

Link link = Link.of("/foo{?bar}").withType(MediaType.APPLICATION_JSON_VALUE);

Remote remote = HalFormsOptions.remote(link);

DocumentContext result = JsonPath.parse(getCuriedObjectMapper().writeObject(remote));

assertThat(result.read("$.link.href", String.class)).isEqualTo("/foo{?bar}");
assertThat(result.read("$.link.type", String.class)).isEqualTo(MediaType.APPLICATION_JSON_VALUE);
assertThat(result.read("$.link.templated", boolean.class)).isTrue();
}

@Test // #2257
void rendersFullInlineOptions() {
Inline inline = HalFormsOptions.inline(Map.of("my-prompt-field", "foo","my-value-field", "bar")).withPromptField("my-prompt-field")

var options = HalFormsOptions.inline(Map.of("my-prompt-field", "foo", "my-value-field", "bar"))
.withPromptField("my-prompt-field")
.withValueField("my-value-field")
.withMinItems(2L)
.withMaxItems(3L);

DocumentContext result = JsonPath.parse(getCuriedObjectMapper().writeObject(inline));
var result = JsonPath.parse(getCuriedObjectMapper().writeObject(options));

assertThat(result.read("$.inline[0].my-prompt-field", String.class)).isEqualTo("foo");
assertThat(result.read("$.inline[0].my-value-field", String.class)).isEqualTo("bar");
assertThat(result.read("$.promptField", String.class)).isEqualTo("my-prompt-field");
Expand All @@ -590,18 +606,19 @@ void rendersFullInlineOptions() {
assertThat(result.read("$.maxItems", Long.class)).isEqualTo(3L);
}

@Test
// #2257
@Test // #2257
void rendersFullRemoteOptions() {
Link link = Link.of("/foo{?bar}").withType(MediaType.APPLICATION_JSON_VALUE);

Remote remote = HalFormsOptions.remote(link)
var link = Link.of("/foo{?bar}").withType(MediaType.APPLICATION_JSON_VALUE);

var options = HalFormsOptions.remote(link)
.withPromptField("my-prompt-field")
.withValueField("my-value-field")
.withMinItems(2L)
.withMaxItems(3L);

DocumentContext result = JsonPath.parse(getCuriedObjectMapper().writeObject(remote));
var result = JsonPath.parse(getCuriedObjectMapper().writeObject(options));

assertThat(result.read("$.link.href", String.class)).isEqualTo("/foo{?bar}");
assertThat(result.read("$.link.type", String.class)).isEqualTo(MediaType.APPLICATION_JSON_VALUE);
assertThat(result.read("$.link.templated", boolean.class)).isTrue();
Expand All @@ -611,20 +628,6 @@ void rendersFullRemoteOptions() {
assertThat(result.read("$.maxItems", Long.class)).isEqualTo(3L);
}

@Test // #1483
void rendersRemoteOptions() {

Link link = Link.of("/foo{?bar}").withType(MediaType.APPLICATION_JSON_VALUE);

Remote remote = HalFormsOptions.remote(link);

DocumentContext result = JsonPath.parse(getCuriedObjectMapper().writeObject(remote));

assertThat(result.read("$.link.href", String.class)).isEqualTo("/foo{?bar}");
assertThat(result.read("$.link.type", String.class)).isEqualTo(MediaType.APPLICATION_JSON_VALUE);
assertThat(result.read("$.link.templated", boolean.class)).isTrue();
}

private void assertThatPathDoesNotExist(Object toMarshall, String path) throws Exception {

String json = getCuriedObjectMapper().writeObject(toMarshall);
Expand Down

0 comments on commit 5d5966c

Please sign in to comment.