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
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<runSuite>**/UiFormSchemaGeneratorTest.class</runSuite>
</properties>
<dependencies>
<dependency>
Expand Down Expand Up @@ -77,6 +78,15 @@
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>${runSuite}</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
Expand Down
88 changes: 88 additions & 0 deletions src/test/java/io/asfjava/ui/core/schema/CheckBoxFormTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package io.asfjava.ui.core.schema;

import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasSize;

import java.io.Serializable;

import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import io.asfjava.ui.core.GeneratorFactoryInitializer;
import io.asfjava.ui.core.form.CheckBox;
import io.asfjava.ui.dto.UiForm;

public class CheckBoxFormTest {

static GeneratorFactoryInitializer generatorFactoryInitializer;

@BeforeClass
public static void setUpBeforeClass() {
generatorFactoryInitializer = new GeneratorFactoryInitializer();
generatorFactoryInitializer.contextInitialized(null);
}

@AfterClass
public static void tearDownAfterClass() {
generatorFactoryInitializer.contextDestroyed(null);
}

@Test
public void testGenerate_CheckBox() throws JsonProcessingException {
UiForm ui = UiFormSchemaGenerator.get().generate(CheckBoxForm.class);
String json = new ObjectMapper().writeValueAsString(ui);
Assert.assertThat(json, hasJsonPath("$.schema.properties.color.title", equalTo("Color")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='color')]", hasSize(1)));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='color')].multiple", hasItem(false)));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='color')].required", hasItem(true)));
Assert.assertThat(json,
hasJsonPath("$.form[?(@.key=='color')].titleMap[?(@.name=='Red')].value", hasItem("red")));
Assert.assertThat(json,
hasJsonPath("$.form[?(@.key=='color')].titleMap[?(@.name=='Blue')].value", hasItem("blue")));
Assert.assertThat(json,
hasJsonPath("$.form[?(@.key=='color')].titleMap[?(@.name=='Green')].value", hasItem("green")));
}

@Test
public void testGenerate_CheckBox_WithCustomValuesContainer() throws JsonProcessingException {
UiForm ui = UiFormSchemaGenerator.get().generate(CheckBoxForm2.class);
String json = new ObjectMapper().writeValueAsString(ui);
Assert.assertThat(json, hasJsonPath("$.schema.properties.color.title", equalTo("Color")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='color')]", hasSize(1)));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='color')].multiple", hasItem(true)));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='color')].required", hasItem(false)));
Assert.assertThat(json,
hasJsonPath("$.form[?(@.key=='color')].titleMap[?(@.name=='Red')].value", hasItem("red")));
Assert.assertThat(json,
hasJsonPath("$.form[?(@.key=='color')].titleMap[?(@.name=='Blue')].value", hasItem("blue")));
Assert.assertThat(json,
hasJsonPath("$.form[?(@.key=='color')].titleMap[?(@.name=='Green')].value", hasItem("green")));
}
}

class CheckBoxForm implements Serializable {

@CheckBox(title = "Color", values = { "red", "blue", "green" }, defaultvalue = "red", required = true)
private String color;

public String getColor() {
return color;
}
}

class CheckBoxForm2 implements Serializable {

@CheckBox(title = "Color", titleMap = MyCheckBoxValues.class, defaultvalue = "red", multiple = true)
private String color;

public String getColor() {
return color;
}
}
94 changes: 94 additions & 0 deletions src/test/java/io/asfjava/ui/core/schema/ComboBoxFormTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package io.asfjava.ui.core.schema;

import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasSize;

import java.io.Serializable;

import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import io.asfjava.ui.core.GeneratorFactoryInitializer;
import io.asfjava.ui.core.form.ComboBox;
import io.asfjava.ui.dto.UiForm;

public class ComboBoxFormTest {

static GeneratorFactoryInitializer generatorFactoryInitializer;

@BeforeClass
public static void setUpBeforeClass() {
generatorFactoryInitializer = new GeneratorFactoryInitializer();
generatorFactoryInitializer.contextInitialized(null);
}

@AfterClass
public static void tearDownAfterClass() {
generatorFactoryInitializer.contextDestroyed(null);
}

@Test
public void testGenerate_ComboBox() throws JsonProcessingException {
UiForm ui = UiFormSchemaGenerator.get().generate(ComboBoxForm.class);

String json = new ObjectMapper().writeValueAsString(ui);
Assert.assertThat(json, hasJsonPath("$.schema.properties.currency.title", equalTo("Currency")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='currency')]", hasSize(1)));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='currency')].disabled", hasItem(false)));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='currency')].multiple", hasItem(false)));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='currency')].required", hasItem(true)));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='currency')].autofocus", hasItem(false)));
Assert.assertThat(json,
hasJsonPath("$.form[?(@.key=='currency')].titleMap[?(@.name=='Euro')].value", hasItem("euro")));
Assert.assertThat(json,
hasJsonPath("$.form[?(@.key=='currency')].titleMap[?(@.name=='Dollar')].value", hasItem("dollar")));

}

@Test
public void testGenerate_ComboBox_WithCustomValuesContainer() throws JsonProcessingException {
UiForm ui = UiFormSchemaGenerator.get().generate(ComboBoxForm2.class);

String json = new ObjectMapper().writeValueAsString(ui);
Assert.assertThat(json, hasJsonPath("$.schema.properties.gender.title", equalTo("Gender")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='gender')]", hasSize(1)));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='gender')].disabled", hasItem(false)));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='gender')].multiple", hasItem(false)));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='gender')].required", hasItem(false)));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='gender')].autofocus", hasItem(false)));
Assert.assertThat(json,
hasJsonPath("$.form[?(@.key=='gender')].titleMap[?(@.name=='Male')].value", hasItem("male")));
Assert.assertThat(json,
hasJsonPath("$.form[?(@.key=='gender')].titleMap[?(@.name=='Female')].value", hasItem("female")));

}

}

class ComboBoxForm implements Serializable {

@ComboBox(title = "Currency", values = { "euro", "dollar" }, required = true)
private String currency;

public String getCurrency() {
return currency;
}
}

class ComboBoxForm2 implements Serializable {

@ComboBox(title = "Gender", titleMap = GenderTitleMap.class)
private String gender;

public String getGender() {
return gender;
}
}

173 changes: 173 additions & 0 deletions src/test/java/io/asfjava/ui/core/schema/NumberFormTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
package io.asfjava.ui.core.schema;

import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasSize;

import java.io.Serializable;

import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import io.asfjava.ui.core.GeneratorFactoryInitializer;
import io.asfjava.ui.core.form.Number;
import io.asfjava.ui.dto.UiForm;

public class NumberFormTest {

static GeneratorFactoryInitializer generatorFactoryInitializer;

@BeforeClass
public static void setUpBeforeClass() {
generatorFactoryInitializer = new GeneratorFactoryInitializer();
generatorFactoryInitializer.contextInitialized(null);
}

@AfterClass
public static void tearDownAfterClass() {
generatorFactoryInitializer.contextDestroyed(null);
}

@Test
public void testGenerate_Number_For_Integer() throws JsonProcessingException {
UiForm ui = UiFormSchemaGenerator.get().generate(IntegerNumberForm.class);
String json = new ObjectMapper().writeValueAsString(ui);
Assert.assertThat(json, hasJsonPath("$.schema.properties.number.title", equalTo("Integer Number")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')]", hasSize(1)));
Assert.assertThat(json,
hasJsonPath("$.form[?(@.key=='number')].description", hasItem("This is an integer number")));
Assert.assertThat(json,
hasJsonPath("$.form[?(@.key=='number')].placeholder", hasItem("Integer Number PlaceHolder")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].validationMessage",
hasItem("this is a validation msg for an integer value")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].type", hasItem("number")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].notitle", hasItem(true)));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].readonly", hasItem(true)));

}

@Test
public void testGenerate_Number_For_Long() throws JsonProcessingException {
UiForm ui = UiFormSchemaGenerator.get().generate(LongNumberForm.class);
String json = new ObjectMapper().writeValueAsString(ui);
Assert.assertThat(json, hasJsonPath("$.schema.properties.number.title", equalTo("Long Number")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')]", hasSize(1)));
Assert.assertThat(json,
hasJsonPath("$.form[?(@.key=='number')].description", hasItem("This is a long number")));
Assert.assertThat(json,
hasJsonPath("$.form[?(@.key=='number')].placeholder", hasItem("Long Number PlaceHolder")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].validationMessage",
hasItem("this is a validation msg for long value")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].type", hasItem("number")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].notitle", hasItem(true)));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].readonly", hasItem(true)));

}


@Test
public void testGenerate_Number_For_Double() throws JsonProcessingException {
UiForm ui = UiFormSchemaGenerator.get().generate(DoubleNumberForm.class);
String json = new ObjectMapper().writeValueAsString(ui);
Assert.assertThat(json, hasJsonPath("$.schema.properties.number.title", equalTo("Double Number")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')]", hasSize(1)));
Assert.assertThat(json,
hasJsonPath("$.form[?(@.key=='number')].description", hasItem("This is a double number")));
Assert.assertThat(json,
hasJsonPath("$.form[?(@.key=='number')].placeholder", hasItem("Double Number PlaceHolder")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].validationMessage",
hasItem("this is a validation msg for double value")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].type", hasItem("number")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].notitle", hasItem(true)));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].readonly", hasItem(true)));

}

@Test
public void testGenerate_Number_WithRightAddon() throws JsonProcessingException {
UiForm ui = UiFormSchemaGenerator.get().generate(NumberFormRight.class);
String json = new ObjectMapper().writeValueAsString(ui);
//Assert.assertThat(json, hasJsonPath("$.schema.properties.number.title",equalTo("Number")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')]",hasSize(1)));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].description",hasItem("This is a number")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].placeholder",hasItem("Number of children")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].validationMessage",hasItem("this is a validation msg")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].type",hasItem("number")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].notitle",hasItem(true)));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].readonly",hasItem(true)));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].fieldAddonRight",hasItem("@")));

}

@Test
public void testGenerate_Number_WithLeftAddon() throws JsonProcessingException {
UiForm ui = UiFormSchemaGenerator.get().generate(NumberFormLeft.class);
String json = new ObjectMapper().writeValueAsString(ui);
//Assert.assertThat(json, hasJsonPath("$.schema.properties.number.title",equalTo("Number")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')]",hasSize(1)));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].description",hasItem("This is a number")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].placeholder",hasItem("Number of children")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].validationMessage",hasItem("this is a validation msg")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].type",hasItem("number")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].notitle",hasItem(true)));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].readonly",hasItem(true)));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].fieldAddonLeft",hasItem("@")));

}

}

class IntegerNumberForm implements Serializable {

@Number(title = "Integer Number", placeHolder = "Integer Number PlaceHolder", description = "This is an integer number", noTitle = true, validationMessage = "this is a validation msg for an integer value", readOnly = true)
private Integer number;

public Integer getNumber() {
return number;
}
}

class NumberFormRight implements Serializable {

@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)
private Integer number;

public Integer getNumber() {
return number;
}
}

class LongNumberForm implements Serializable {

@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)
private Long number;

public Long getNumber() {
return number;
}
}

class NumberFormLeft implements Serializable {

@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)
private Integer number;

public Integer getNumber() {
return number;
}
}
class DoubleNumberForm implements Serializable {

@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)
private Double number;

public Double getNumber() {
return number;
}
}
Loading