Skip to content

Commit a2b83bd

Browse files
authored
:green_heart; Merge pull request #47 from ahdbk/master
💚 Update Test Unit
2 parents 305571f + 42dae0f commit a2b83bd

File tree

1 file changed

+107
-1
lines changed

1 file changed

+107
-1
lines changed

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

Lines changed: 107 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ public void testGenerate_Number_For_Long() throws JsonProcessingException {
126126
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].readonly", hasItem(true)));
127127

128128
}
129-
129+
130+
130131
@Test
131132
public void testGenerate_Number_For_Double() throws JsonProcessingException {
132133
UiForm ui = UiFormSchemaGenerator.get().generate(DoubleNumberForm.class);
@@ -144,6 +145,38 @@ public void testGenerate_Number_For_Double() throws JsonProcessingException {
144145
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].readonly", hasItem(true)));
145146

146147
}
148+
149+
@Test
150+
public void testGenerate_Number_WithRightAddon() throws JsonProcessingException {
151+
UiForm ui = UiFormSchemaGenerator.get().generate(NumberFormRight.class);
152+
String json = new ObjectMapper().writeValueAsString(ui);
153+
//Assert.assertThat(json, hasJsonPath("$.schema.properties.number.title",equalTo("Number")));
154+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')]",hasSize(1)));
155+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].description",hasItem("This is a number")));
156+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].placeholder",hasItem("Number of children")));
157+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].validationMessage",hasItem("this is a validation msg")));
158+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].type",hasItem("number")));
159+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].notitle",hasItem(true)));
160+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].readonly",hasItem(true)));
161+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].fieldAddonRight",hasItem("@")));
162+
163+
}
164+
165+
@Test
166+
public void testGenerate_Number_WithLeftAddon() throws JsonProcessingException {
167+
UiForm ui = UiFormSchemaGenerator.get().generate(NumberFormLeft.class);
168+
String json = new ObjectMapper().writeValueAsString(ui);
169+
//Assert.assertThat(json, hasJsonPath("$.schema.properties.number.title",equalTo("Number")));
170+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')]",hasSize(1)));
171+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].description",hasItem("This is a number")));
172+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].placeholder",hasItem("Number of children")));
173+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].validationMessage",hasItem("this is a validation msg")));
174+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].type",hasItem("number")));
175+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].notitle",hasItem(true)));
176+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].readonly",hasItem(true)));
177+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].fieldAddonLeft",hasItem("@")));
178+
179+
}
147180

148181
@Test
149182
public void testGenerate_Password() throws JsonProcessingException {
@@ -161,6 +194,40 @@ public void testGenerate_Password() throws JsonProcessingException {
161194
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='password')].notitle", hasItem(true)));
162195
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='password')].readonly", hasItem(true)));
163196
}
197+
198+
@Test
199+
public void testGenerate_Password_WithFieldAddonLeft() throws JsonProcessingException {
200+
UiForm ui = UiFormSchemaGenerator.get().generate(PasswordForm3.class);
201+
202+
String json = new ObjectMapper().writeValueAsString(ui);
203+
Assert.assertThat(json, hasJsonPath("$.schema.properties.password.title",equalTo("Password")));
204+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='password')]",hasSize(1)));
205+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='password')].description",hasItem("This is password")));
206+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='password')].placeholder",hasItem("Please set you password")));
207+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='password')].validationMessage",hasItem("this is a validation msg")));
208+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='password')].type",hasItem("password")));
209+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='password')].notitle",hasItem(true)));
210+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='password')].readonly",hasItem(true)));
211+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='password')].fieldAddonLeft",hasItem("@")));
212+
213+
}
214+
215+
@Test
216+
public void testGenerate_Password_WithFieldAddonRight() throws JsonProcessingException {
217+
UiForm ui = UiFormSchemaGenerator.get().generate(PasswordForm2.class);
218+
219+
String json = new ObjectMapper().writeValueAsString(ui);
220+
Assert.assertThat(json, hasJsonPath("$.schema.properties.password.title",equalTo("Password")));
221+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='password')]",hasSize(1)));
222+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='password')].description",hasItem("This is password")));
223+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='password')].placeholder",hasItem("Please set you password")));
224+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='password')].validationMessage",hasItem("this is a validation msg")));
225+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='password')].type",hasItem("password")));
226+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='password')].notitle",hasItem(true)));
227+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='password')].readonly",hasItem(true)));
228+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='password')].fieldAddonRight",hasItem("@")));
229+
230+
}
164231

165232
@Test
166233
public void testGenerate_TextArea() throws JsonProcessingException {
@@ -310,6 +377,16 @@ public Integer getNumber() {
310377
}
311378
}
312379

380+
class NumberFormRight implements Serializable {
381+
382+
@Number(title = "Number of children", placeHolder = "Number of children", fieldAddonRight = "@", description = "This is a number", noTitle = true, validationMessage = "this is a validation msg", readOnly = true)
383+
private Integer number;
384+
385+
public Integer getNumber() {
386+
return number;
387+
}
388+
}
389+
313390
class LongNumberForm implements Serializable {
314391

315392
@Number(title = "Long Number", placeHolder = "Long Number PlaceHolder", description = "This is a long number", noTitle = true, validationMessage = "this is a validation msg for long value", readOnly = true)
@@ -320,6 +397,15 @@ public Long getNumber() {
320397
}
321398
}
322399

400+
class NumberFormLeft implements Serializable {
401+
402+
@Number(title = "Number of children", placeHolder = "Number of children", fieldAddonLeft = "@", description = "This is a number", noTitle = true, validationMessage = "this is a validation msg", readOnly = true)
403+
private Integer number;
404+
405+
public Integer getNumber() {
406+
return number;
407+
}
408+
}
323409
class DoubleNumberForm implements Serializable {
324410

325411
@Number(title = "Double Number", placeHolder = "Double Number PlaceHolder", description = "This is a double number", noTitle = true, validationMessage = "this is a validation msg for double value", readOnly = true)
@@ -340,6 +426,26 @@ public String getPassword() {
340426
}
341427
}
342428

429+
class PasswordForm2 implements Serializable {
430+
431+
@Password(title = "Password", placeHolder = "Please set you password", fieldAddonRight = "@", description = "This is password", noTitle = true, validationMessage = "this is a validation msg", readOnly = true)
432+
private String password;
433+
434+
public String getPassword() {
435+
return password;
436+
}
437+
}
438+
439+
class PasswordForm3 implements Serializable {
440+
441+
@Password(title = "Password", placeHolder = "Please set you password", fieldAddonLeft = "@", description = "This is password", noTitle = true, validationMessage = "this is a validation msg", readOnly = true)
442+
private String password;
443+
444+
public String getPassword() {
445+
return password;
446+
}
447+
}
448+
343449
class TextAreaForm implements Serializable {
344450

345451
@TextArea(title = "Address", placeHolder = "Fill your address please", description = "This is textarea", noTitle = true, validationMessage = "this is a validation msg", readOnly = true)

0 commit comments

Comments
 (0)