2
0
Fork 0
imxmi/vasc-frontend-swing/src/test/java/com/idcanet/vasc/TestTable.java

152 lines
5.7 KiB
Java
Raw Normal View History

/*
* Copyright 2004-2006 IDCA. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
* the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
* and the following disclaimer in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.vasc;
2009-04-13 19:19:48 +02:00
import java.io.File;
import java.io.FileOutputStream;
2008-09-15 00:00:09 +02:00
import java.lang.reflect.Method;
import java.util.Locale;
2009-08-11 20:31:29 +02:00
import com.idcanet.vasc.core.VascBackend;
2009-12-31 13:51:53 +01:00
import com.idcanet.vasc.core.VascBackendControllerLocal;
2008-09-13 17:04:49 +02:00
import com.idcanet.vasc.core.VascController;
2008-09-08 02:07:46 +02:00
import com.idcanet.vasc.core.VascEntry;
import com.idcanet.vasc.core.VascEntryField;
2009-08-11 20:31:29 +02:00
import com.idcanet.vasc.core.VascException;
import com.idcanet.vasc.core.VascFrontendData;
2009-08-11 20:31:29 +02:00
import com.idcanet.vasc.impl.DefaultVascBackedEntryFinalizer;
2009-12-31 13:51:53 +01:00
import com.idcanet.vasc.impl.DefaultVascFactory;
2008-09-15 00:00:09 +02:00
import com.idcanet.vasc.impl.DefaultVascFrontendData;
import com.idcanet.vasc.impl.DefaultVascFrontendHelper;
2009-08-11 20:31:29 +02:00
import com.idcanet.vasc.impl.VascBackendProxyPaged;
import com.idcanet.vasc.impl.VascBackendProxySearch;
import com.idcanet.vasc.impl.VascBackendProxySort;
import com.idcanet.vasc.impl.actions.AddRowAction;
import com.idcanet.vasc.impl.actions.CSVExportGlobalAction;
import com.idcanet.vasc.impl.actions.DeleteRowAction;
import com.idcanet.vasc.impl.actions.EditRowAction;
import com.idcanet.vasc.impl.actions.RefreshDataGlobalAction;
import com.idcanet.vasc.impl.actions.XMLExportGlobalAction;
import com.idcanet.vasc.impl.x4o.VascParser;
/**
*
* @author Willem Cazander
* @version 1.0 Aug 2, 2007
*/
public class TestTable {
2008-09-15 00:00:09 +02:00
static VascController getDefaultVascController() throws Exception {
2009-12-31 13:51:53 +01:00
VascController c = DefaultVascFactory.getDefaultVascController(2288L,"idca.nl","user","admin");
2008-09-21 13:30:50 +02:00
// for test
TestModelVascDataSource backend = new TestModelVascDataSource();
backend.setId("testBackend1");
2009-12-31 13:51:53 +01:00
((VascBackendControllerLocal)c.getVascBackendController()).addVascBackend(backend);
2008-09-13 17:04:49 +02:00
return c;
}
static public void fill(VascEntry entry,VascController vascController) {
2009-04-13 19:19:48 +02:00
VascFrontendData frontendData = DefaultVascFactory.getDefaultVascFrontendData("i18n.vasc", Locale.getDefault());
frontendData.setVascController(vascController);
entry.setVascFrontendData(frontendData);
VascBackend backend = DefaultVascFactory.getProxyVascBackend(entry);
frontendData.getVascEntryState().setVascBackend(backend);
frontendData.getVascEntryState().setVascEntry(entry);
2009-04-13 19:19:48 +02:00
2008-09-08 02:07:46 +02:00
entry.addRowAction(new AddRowAction());
entry.addRowAction(new EditRowAction());
entry.addRowAction(new DeleteRowAction());
2008-09-08 02:07:46 +02:00
entry.addGlobalAction(new XMLExportGlobalAction());
entry.addGlobalAction(new CSVExportGlobalAction());
entry.addGlobalAction(new RefreshDataGlobalAction());
2009-08-11 20:31:29 +02:00
// hackje om deze manuale actions van i18n keys te voorzien;
// this is temp untill x4o templaing
DefaultVascBackedEntryFinalizer f = new DefaultVascBackedEntryFinalizer();
try {
f.finalizeVascEntry(entry, vascController);
2009-08-11 20:31:29 +02:00
} catch (VascException e) {
e.printStackTrace();
}
}
static public VascEntry getVascTable() throws Exception {
VascController c = getDefaultVascController();
VascParser parser = new VascParser(c);
2009-04-13 19:19:48 +02:00
File f = File.createTempFile("test-vasc", ".xml");
parser.setDebugOutputStream(new FileOutputStream(f));
2008-12-07 19:26:44 +01:00
parser.parseResource("vasc/tables.xml");
2009-12-31 13:51:53 +01:00
VascEntry entry = parser.getVascController().getVascEntryController().getVascEntryById("test1");
fill(entry,c);
2009-04-13 19:19:48 +02:00
2008-09-08 02:07:46 +02:00
return entry;
}
2008-09-15 00:00:09 +02:00
static void printEntry(VascEntry e) throws Exception {
System.out.println("");
System.out.println("=== Printing entry ===");
System.out.println("");
for (Method m:e.getClass().getMethods()) {
if (m.getName().startsWith("get")==false) { //a bit dirty
continue;
}
if (m.getParameterTypes().length>0) {
continue;
}
2009-04-13 19:19:48 +02:00
System.out.println("prop: "+m.getName()+" -> "+m.invoke(e));
2008-09-15 00:00:09 +02:00
}
System.out.println("");
System.out.println("=== Fields ===");
for (VascEntryField vef:e.getVascEntryFields()) {
System.out.println("=== Field: "+vef.getId());
for (Method m:vef.getClass().getMethods()) {
if (m.getName().startsWith("get")==false) { //a bit dirty
continue;
}
if (m.getParameterTypes().length>0) {
continue;
}
2009-04-13 19:19:48 +02:00
System.out.println("prop: "+m.getName()+" -> "+m.invoke(vef));
2008-09-15 00:00:09 +02:00
}
}
}
}