Skip to content

Commit 7e9834b

Browse files
committed
Update Unit Test
1 parent c3d70d1 commit 7e9834b

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

src/test/java/io/asfjava/ui/core/schema/UiFormSchemaGeneratorTest.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,38 @@ public void testGenerate_textField() throws JsonProcessingException {
4646
//Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='firstName')].type",hasItem("textField")));
4747

4848
}
49+
50+
@Test
51+
public void testGenerate_textField_WithFieldAddonRight() throws JsonProcessingException {
52+
UiForm ui = UiFormSchemaGenerator.get().generate(TextFieldForm2.class);
53+
String json = new ObjectMapper().writeValueAsString(ui);
54+
55+
56+
Assert.assertThat(json, hasJsonPath("$.schema.properties.firstName.title",equalTo("First Name")));
57+
Assert.assertThat(json, hasJsonPath("$.schema.properties.firstName.pattern",equalTo("[a-z]")));
58+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='firstName')]",hasSize(1)));
59+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='firstName')].description",hasItem("This is a description for your first name field")));
60+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='firstName')].placeholder",hasItem("Your first name")));
61+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='firstName')].validationMessage",hasItem("this is a validation msg")));
62+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='firstName')].fieldAddonRight",hasItem("@")));
63+
64+
}
65+
66+
@Test
67+
public void testGenerate_textField_WithFieldAddonLeft() throws JsonProcessingException {
68+
UiForm ui = UiFormSchemaGenerator.get().generate(TextFieldForm3.class);
69+
String json = new ObjectMapper().writeValueAsString(ui);
70+
71+
72+
Assert.assertThat(json, hasJsonPath("$.schema.properties.firstName.title",equalTo("First Name")));
73+
Assert.assertThat(json, hasJsonPath("$.schema.properties.firstName.pattern",equalTo("[a-z]")));
74+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='firstName')]",hasSize(1)));
75+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='firstName')].description",hasItem("This is a description for your first name field")));
76+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='firstName')].placeholder",hasItem("Your first name")));
77+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='firstName')].validationMessage",hasItem("this is a validation msg")));
78+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='firstName')].fieldAddonLeft",hasItem("@")));
79+
80+
}
4981

5082
@Test
5183
public void testGenerate_Number() throws JsonProcessingException {
@@ -163,6 +195,8 @@ public void testGenerate_ComboBox_WithCustomValuesContainer() throws JsonProcess
163195
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='gender')].titleMap[?(@.name=='Female')].value",hasItem("female")));
164196

165197
}
198+
199+
166200

167201
}
168202

@@ -177,6 +211,28 @@ public String getFirstName() {
177211

178212
}
179213

214+
class TextFieldForm2 implements Serializable {
215+
216+
@TextField(title = "First Name", placeHolder = "Your first name", fieldAddonRight = "@", pattern = "[a-z]", noTitle = true, validationMessage = "this is a validation msg", description = "This is a description for your first name field")
217+
private String firstName;
218+
219+
public String getFirstName() {
220+
return firstName;
221+
}
222+
223+
}
224+
225+
class TextFieldForm3 implements Serializable {
226+
227+
@TextField(title = "First Name", placeHolder = "Your first name", fieldAddonLeft = "@", pattern = "[a-z]", noTitle = true, validationMessage = "this is a validation msg", description = "This is a description for your first name field")
228+
private String firstName;
229+
230+
public String getFirstName() {
231+
return firstName;
232+
}
233+
234+
}
235+
180236
class NumberForm implements Serializable {
181237

182238
@Number(title = "Number of children", placeHolder = "Number of children", description = "This is a number", noTitle = true, validationMessage = "this is a validation msg", readOnly = true)

0 commit comments

Comments
 (0)