GH-2262 - Explicitly declare properties in HalFormsOptions.
This commit is contained in:
committed by
Oliver Drotbohm
parent
3071073b21
commit
d7c81336c6
@@ -32,6 +32,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
* Representation of HAL-FORMS {@code options} attribute.
|
||||
*
|
||||
* @author Oliver Drotbohm
|
||||
* @author Réda Housni Alaoui
|
||||
* @see https://rwcbook.github.io/hal-forms/#options-element
|
||||
* @since 1.3
|
||||
*/
|
||||
@@ -151,6 +152,7 @@ public interface HalFormsOptions {
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
@JsonProperty
|
||||
public String getPromptField() {
|
||||
return promptField;
|
||||
}
|
||||
@@ -161,6 +163,7 @@ public interface HalFormsOptions {
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
@JsonProperty
|
||||
public String getValueField() {
|
||||
return valueField;
|
||||
}
|
||||
@@ -171,6 +174,7 @@ public interface HalFormsOptions {
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
@JsonProperty
|
||||
public Long getMinItems() {
|
||||
return minItems;
|
||||
}
|
||||
@@ -181,6 +185,7 @@ public interface HalFormsOptions {
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
@JsonProperty
|
||||
public Long getMaxItems() {
|
||||
return maxItems;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -83,6 +84,7 @@ import com.jayway.jsonpath.PathNotFoundException;
|
||||
/**
|
||||
* @author Greg Turnquist
|
||||
* @author Oliver Drotbohm
|
||||
* @author Réda Housni Alaoui
|
||||
*/
|
||||
class Jackson2HalFormsIntegrationTest {
|
||||
|
||||
@@ -571,6 +573,44 @@ class Jackson2HalFormsIntegrationTest {
|
||||
.isEqualTo("My Prompt");
|
||||
}
|
||||
|
||||
@Test
|
||||
// #2257
|
||||
void rendersFullInlineOptions() {
|
||||
Inline inline = 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));
|
||||
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");
|
||||
assertThat(result.read("$.valueField", String.class)).isEqualTo("my-value-field");
|
||||
assertThat(result.read("$.minItems", Long.class)).isEqualTo(2L);
|
||||
assertThat(result.read("$.maxItems", Long.class)).isEqualTo(3L);
|
||||
}
|
||||
|
||||
@Test
|
||||
// #2257
|
||||
void rendersFullRemoteOptions() {
|
||||
Link link = Link.of("/foo{?bar}").withType(MediaType.APPLICATION_JSON_VALUE);
|
||||
|
||||
Remote remote = HalFormsOptions.remote(link)
|
||||
.withPromptField("my-prompt-field")
|
||||
.withValueField("my-value-field")
|
||||
.withMinItems(2L)
|
||||
.withMaxItems(3L);
|
||||
|
||||
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();
|
||||
assertThat(result.read("$.promptField", String.class)).isEqualTo("my-prompt-field");
|
||||
assertThat(result.read("$.valueField", String.class)).isEqualTo("my-value-field");
|
||||
assertThat(result.read("$.minItems", Long.class)).isEqualTo(2L);
|
||||
assertThat(result.read("$.maxItems", Long.class)).isEqualTo(3L);
|
||||
}
|
||||
|
||||
@Test // #1483
|
||||
void rendersRemoteOptions() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user