<packaging>pom</packaging>
<modules>
<module>dep</module>
+ <module>runtime</module>
</modules>
</project>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" output="target/classes" path="src/main/java"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.argeo.support.junit</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
--- /dev/null
+#Tue Oct 13 10:02:09 CEST 2009
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.source=1.5
--- /dev/null
+#Tue Oct 13 10:01:59 CEST 2009
+activeProfiles=
+eclipse.preferences.version=1
+fullBuildGoals=process-test-resources
+includeModules=false
+resolveWorkspaceProjects=true
+resourceFilterGoals=process-resources resources\:testResources
+skipCompilerPlugin=true
+version=1
--- /dev/null
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.argeo.commons.basic</groupId>
+ <artifactId>runtime</artifactId>
+ <version>0.1.1-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <artifactId>org.argeo.support.junit</artifactId>
+ <name>Commons Support JUnit</name>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-source-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>${version.maven-bundle-plugin}</version>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.argeo.support.junit.*
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.junit</groupId>
+ <artifactId>com.springsource.junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>org.springframework.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>org.springframework.context</artifactId>
+ </dependency>
+
+ <!-- Logging -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>com.springsource.slf4j.org.apache.commons.logging</artifactId>
+ </dependency>
+ </dependencies>
+</project>
--- /dev/null
+package org.argeo.support.junit;
+
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.factory.BeanFactoryUtils;
+import org.springframework.beans.factory.ListableBeanFactory;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+
+/** Helper for tests using a Spring application context. */
+public abstract class AbstractSpringTestCase extends TestCase {
+ protected final Log log = LogFactory.getLog(getClass());
+ private ConfigurableApplicationContext context;
+
+ /**
+ * Gets (and create if necessary) the application context to use. Default
+ * implementation uses a class path xml application context and calls
+ * {@link #getApplicationContextLocation()}.
+ */
+ protected ConfigurableApplicationContext getContext() {
+ if (context == null) {
+ context = new ClassPathXmlApplicationContext(
+ getApplicationContextLocation());
+ if (getIsStartContext())
+ context.start();
+ }
+ return context;
+ }
+
+ /** Whether the context should be started after being created. */
+ protected Boolean getIsStartContext() {
+ return false;
+ }
+
+ /** Returns a bean from the underlying context */
+ @SuppressWarnings(value = { "unchecked" })
+ protected <T> T getBean(String beanId) {
+ return (T) getContext().getBean(beanId);
+ }
+
+ protected <T> T getBean(Class<? extends T> clss) {
+ T bean = loadSingleFromContext(getContext(), clss);
+ if (bean == null) {
+ throw new RuntimeException("Cannot retrieve a unique bean of type "
+ + clss);
+ } else {
+ return bean;
+ }
+ }
+
+ /**
+ * Th location of the application to load. The default implementation
+ * returns <i>applicationContext.xml</i> found in the same package as the
+ * test.
+ */
+ protected String getApplicationContextLocation() {
+ return inPackage("applicationContext.xml");
+ }
+
+ /**
+ * Prefixes the package of the class after converting the '.' to '/' in
+ * order to have a resource path.
+ */
+ protected String inPackage(String suffix) {
+ String prefix = getClass().getPackage().getName().replace('.', '/');
+ return prefix + '/' + suffix;
+ }
+
+ @SuppressWarnings(value = { "unchecked" })
+ protected <T> T loadSingleFromContext(ListableBeanFactory context,
+ Class<T> clss) {
+ Map<String, T> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(
+ context, clss, false, false);
+ if (beans.size() == 1) {
+ return beans.values().iterator().next();
+ } else if (beans.size() > 1) {
+ if (log.isDebugEnabled()) {
+ log
+ .debug(("Found more that on bean for type " + clss
+ + ": " + beans.keySet()));
+ }
+ return null;
+ } else {
+ return null;
+ }
+ }
+
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.argeo.commons</groupId>
+ <version>0.1.1-SNAPSHOT</version>
+ <artifactId>basic</artifactId>
+ <relativePath>..</relativePath>
+ </parent>
+ <groupId>org.argeo.commons.basic</groupId>
+ <artifactId>runtime</artifactId>
+ <name>Commons Basic Runtime</name>
+ <packaging>pom</packaging>
+ <modules>
+ <module>org.argeo.support.junit</module>
+ </modules>
+</project>
\ No newline at end of file
private List<Resource> workbooks = new ArrayList<Resource>();
public void afterPropertiesSet() throws Exception {
+ init();
+ }
+
+ public void init() {
+ // used to resolve inner references
+ Map<String, List<Object>> tempRefs = new HashMap<String, List<Object>>();
+
+ List<Reference> references = new ArrayList<Reference>();
+
for (Resource res : workbooks) {
InputStream in = null;
try {
in = res.getInputStream();
- load(in);
+ load(in, references, tempRefs);
+ } catch (Exception e) {
+ throw new ArgeoServerException("Cannot load stream", e);
} finally {
IOUtils.closeQuietly(in);
}
}
+ // Inject references
+ for (Reference ref : references) {
+ injectReference(ref, tempRefs);
+ }
+ if (log.isDebugEnabled())
+ log.debug(references.size() + " references linked");
}
- public void load(InputStream in) {
+ public void load(InputStream in, List<Reference> references,
+ Map<String, List<Object>> tempRefs) {
try {
- // used to resolve inner references
- Map<String, List<Object>> tempRefs = new HashMap<String, List<Object>>();
-
- List<Reference> references = new ArrayList<Reference>();
-
Workbook workbook = Workbook.getWorkbook(in);
-
for (Sheet sheet : workbook.getSheets()) {
loadSheet(sheet, references, tempRefs);
}
-
- for (Reference ref : references) {
- injectReference(ref, tempRefs);
- }
- if (log.isDebugEnabled())
- log.debug(references.size() + " references linked");
-
} catch (Exception e) {
throw new ArgeoServerException("Cannot load workbook", e);
}
if (cell instanceof FormulaCell) {
String formula = ((FormulaCell) cell).getFormula();
int index = formula.indexOf('!');
+ if (index < 0)
+ throw new ArgeoServerException("Cannot interpret formula "
+ + formula);
+ ;
String targetSheet = formula.substring(0, index);
// assume no double letters!!
String targetRowStr = formula.substring(index + 2);
package org.argeo.server.jxl.dao;
-import java.io.InputStream;
import java.util.List;
import junit.framework.TestCase;
+import org.springframework.core.io.ClassPathResource;
+
public class JxlDaoSupportTest extends TestCase {
public void testBasic() throws Exception {
JxlDaoSupport jsd = new JxlDaoSupport();
jsd.getExternalRefs().put("test", new OtherObject());
- InputStream in = null;
- try {
- in = getClass().getResourceAsStream("/dao/simple.xls");
- jsd.load(in);
-
- SimpleObject soAaa = jsd.getByKey(SimpleObject.class, "aaa");
- assertNotNull(soAaa);
- assertEquals("aaa", soAaa.getString());
- assertEquals(1, soAaa.getInteger().intValue());
- assertNotNull(soAaa.getOtherObject());
- assertEquals("USD", soAaa.getOtherObject().getKey());
- assertEquals("US Dollar", soAaa.getOtherObject().getValue());
-
- SimpleObject soBbb = jsd.getByKey(SimpleObject.class, "bbb");
- assertNotNull(soBbb.getOtherObject());
- assertEquals("bbb", ((SimpleObject) soBbb.getOtherObject()
- .getValue()).getString());
-
- List<SimpleObject> simpleObjects = jsd.list(SimpleObject.class,
- null);
- assertEquals(2, simpleObjects.size());
- } finally {
- if (in != null)
- in.close();
- }
+ jsd.getWorkbooks().add(new ClassPathResource("/dao/simple.xls"));
+ jsd.init();
+
+ SimpleObject soAaa = jsd.getByKey(SimpleObject.class, "aaa");
+ assertNotNull(soAaa);
+ assertEquals("aaa", soAaa.getString());
+ assertEquals(1, soAaa.getInteger().intValue());
+ assertNotNull(soAaa.getOtherObject());
+ assertEquals("USD", soAaa.getOtherObject().getKey());
+ assertEquals("US Dollar", soAaa.getOtherObject().getValue());
+
+ SimpleObject soBbb = jsd.getByKey(SimpleObject.class, "bbb");
+ assertNotNull(soBbb.getOtherObject());
+ assertEquals("bbb", ((SimpleObject) soBbb.getOtherObject().getValue())
+ .getString());
+ List<SimpleObject> simpleObjects = jsd.list(SimpleObject.class, null);
+ assertEquals(2, simpleObjects.size());
}
}