// Path: src/main/java/io/asfjava/ui/core/GeneratorFactoryInitializer.java
// @WebListener
// public class GeneratorFactoryInitializer implements ServletContextListener {
// 
// 	@Override
// 	public final void contextInitialized(final ServletContextEvent sce) {
// 		SFJavaUi.initialize();
// 	}
// 
// 	@Override
// 	public final void contextDestroyed(final ServletContextEvent sce) {
// 		// to implement it
// 	}
// }
// 
// Path: src/main/java/io/asfjava/ui/dto/UiForm.java
// public class UiForm implements Serializable {
// 
// 	private transient JsonSchema schema;
// 	private transient ArrayNode form;
// 
// 	public UiForm(JsonSchema schema, ArrayNode form) {
// 		setSchema(schema);
// 		setForm(form);
// 	}
// 
// 	public JsonSchema getSchema() {
// 		return schema;
// 	}
// 
// 	public void setSchema(JsonSchema schema) {
// 		this.schema = schema;
// 	}
// 
// 	public ArrayNode getForm() {
// 		return form;
// 	}
// 
// 	public void setForm(ArrayNode form) {
// 		this.form = form;
// 	}
// 
// 	private static final long serialVersionUID = -2534915468830780L;
// }


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.TextField;
import io.asfjava.ui.dto.UiForm;
package io.asfjava.ui.core.schema;






public class TextFieldFormTest {
	
	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_textField() throws JsonProcessingException {
		UiForm ui = UiFormSchemaGenerator.get().generate(TextFieldForm.class);
		String json = new ObjectMapper().writeValueAsString(ui);

		Assert.assertThat(json, hasJsonPath("$.schema.properties.firstName.title", equalTo("First Name")));
		Assert.assertThat(json, hasJsonPath("$.schema.properties.firstName.pattern", equalTo("[a-z]")));
		Assert.assertThat(json, hasJsonPath("$.schema.properties.firstName.minLength", equalTo(6)));
		Assert.assertThat(json, hasJsonPath("$.schema.properties.firstName.maxLength", equalTo(10)));
		Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='firstName')]", hasSize(1)));
		Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='firstName')].description",
				hasItem("This is a description for your first name field")));
		Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='firstName')].placeholder", hasItem("Your first name")));
		Assert.assertThat(json,
				hasJsonPath("$.form[?(@.key=='firstName')].validationMessage", hasItem("this is a validation msg")));
		// Assert.assertThat(json,
		// hasJsonPath("$.form[?(@.key=='firstName')].type",hasItem("textField")));

	}

	@Test
	public void testGenerate_textField_WithFieldAddonRight() throws JsonProcessingException {
// Path: src/main/java/io/asfjava/ui/core/GeneratorFactoryInitializer.java
// @WebListener
// public class GeneratorFactoryInitializer implements ServletContextListener {
// 
// 	@Override
// 	public final void contextInitialized(final ServletContextEvent sce) {
// 		SFJavaUi.initialize();
// 	}
// 
// 	@Override
// 	public final void contextDestroyed(final ServletContextEvent sce) {
// 		// to implement it
// 	}
// }
// 
// Path: src/main/java/io/asfjava/ui/dto/UiForm.java
// public class UiForm implements Serializable {
// 
// 	private transient JsonSchema schema;
// 	private transient ArrayNode form;
// 
// 	public UiForm(JsonSchema schema, ArrayNode form) {
// 		setSchema(schema);
// 		setForm(form);
// 	}
// 
// 	public JsonSchema getSchema() {
// 		return schema;
// 	}
// 
// 	public void setSchema(JsonSchema schema) {
// 		this.schema = schema;
// 	}
// 
// 	public ArrayNode getForm() {
// 		return form;
// 	}
// 
// 	public void setForm(ArrayNode form) {
// 		this.form = form;
// 	}
// 
// 	private static final long serialVersionUID = -2534915468830780L;
// }


// Path: src/test/java/io/asfjava/ui/core/schema/TextFieldFormTest.java
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.TextField;
import io.asfjava.ui.dto.UiForm;

package io.asfjava.ui.core.schema;






public class TextFieldFormTest {
	
	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_textField() throws JsonProcessingException {
		UiForm ui = UiFormSchemaGenerator.get().generate(TextFieldForm.class);
		String json = new ObjectMapper().writeValueAsString(ui);

		Assert.assertThat(json, hasJsonPath("$.schema.properties.firstName.title", equalTo("First Name")));
		Assert.assertThat(json, hasJsonPath("$.schema.properties.firstName.pattern", equalTo("[a-z]")));
		Assert.assertThat(json, hasJsonPath("$.schema.properties.firstName.minLength", equalTo(6)));
		Assert.assertThat(json, hasJsonPath("$.schema.properties.firstName.maxLength", equalTo(10)));
		Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='firstName')]", hasSize(1)));
		Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='firstName')].description",
				hasItem("This is a description for your first name field")));
		Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='firstName')].placeholder", hasItem("Your first name")));
		Assert.assertThat(json,
				hasJsonPath("$.form[?(@.key=='firstName')].validationMessage", hasItem("this is a validation msg")));
		// Assert.assertThat(json,
		// hasJsonPath("$.form[?(@.key=='firstName')].type",hasItem("textField")));

	}

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