001/* 002 * (C) Copyright 2006-2008 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * bstefanescu 018 */ 019package org.nuxeo.ecm.webengine.forms.validation.test; 020 021import java.util.Arrays; 022 023import org.nuxeo.ecm.webengine.forms.SimpleFormDataProvider; 024import org.nuxeo.ecm.webengine.forms.validation.ValidationException; 025 026/** 027 * @author <a href="mailto:[email protected]">Bogdan Stefanescu</a> 028 */ 029public class Test { 030 031 public static void main(String[] args) throws Exception { 032 try { 033 SimpleFormDataProvider data = new SimpleFormDataProvider(); 034 data.putString("title", "my title"); 035 data.putString("name", ""); 036 data.putString("age", "40"); 037 data.putString("number", "10"); 038 data.putList("emails", "[email protected]", "[email protected]"); 039 // data.putString("id", "theid"); 040 data.putString("password", "xxx"); 041 data.putString("verifyPassword", "xx"); 042 data.putString("other", "some value"); 043 MyForm form = data.validate(MyForm.class); 044 System.out.println(form.getTitle()); 045 System.out.println(form.getName()); 046 System.out.println(form.getAge()); 047 System.out.println(form.getNumber()); 048 System.out.println(Arrays.asList(form.getEmails())); 049 System.out.println(form.unknownKeys()); 050 } catch (ValidationException e) { 051 if (e.hasFieldErrors()) { 052 System.err.println("Errors:\n" + e.getMessage()); 053 } 054 } 055 } 056 057}