13 new revisions:
Revision: 04c9ca677637
Branch: default
Author: Michele Franzin <
michele...@gmail.com>
Date: Thu Feb 28 09:37:13 2013
Log: refresh dependencies, upgrade build plugins
http://code.google.com/p/lambico/source/detail?r=04c9ca677637
Revision: 25557fd9e611
Branch: default
Author: Michele Franzin <
michele...@gmail.com>
Date: Wed Feb 27 11:00:27 2013
Log: jump to lambico v1.1
http://code.google.com/p/lambico/source/detail?r=25557fd9e611
Revision: 32b833099c51
Branch: default
Author: Michele Franzin <
michele...@gmail.com>
Date: Wed Feb 27 10:59:57 2013
Log: added lambico-pump
http://code.google.com/p/lambico/source/detail?r=32b833099c51
Revision: 3e2a87f1f307
Branch: default
Author: Michele Franzin <
michele...@gmail.com>
Date: Wed Feb 13 07:29:03 2013
Log: lambico-test now depends on lambico-pump (drops parancoe-yaml
dependen...
http://code.google.com/p/lambico/source/detail?r=3e2a87f1f307
Revision: f97596efe5cb
Branch: default
Author: Michele Franzin <
michele...@gmail.com>
Date: Thu Feb 28 09:37:27 2013
Log: use slf4j everywhere (log4j dependency dropped)
http://code.google.com/p/lambico/source/detail?r=f97596efe5cb
Revision: c007457350c7
Branch: default
Author: Michele Franzin <
michele...@gmail.com>
Date: Wed Feb 27 08:43:19 2013
Log: cleanup compilation warning & hints
http://code.google.com/p/lambico/source/detail?r=c007457350c7
Revision: 684b5424641a
Branch: default
Author: Michele Franzin <
michele...@gmail.com>
Date: Sun Feb 24 07:24:09 2013
Log: new junit4 test base classes, with listeners (deprecate old
DBTest)
http://code.google.com/p/lambico/source/detail?r=684b5424641a
Revision: 47b74d9cfe31
Branch: default
Author: Michele Franzin <
michele...@gmail.com>
Date: Mon Feb 18 14:33:18 2013
Log: fix failing tests
http://code.google.com/p/lambico/source/detail?r=47b74d9cfe31
Revision: 65f2442ba582
Branch: default
Author: Michele Franzin <
michele...@gmail.com>
Date: Mon Feb 18 15:12:50 2013
Log: update developer infos (michele)
http://code.google.com/p/lambico/source/detail?r=65f2442ba582
Revision: 1c1905a52fbd
Branch: default
Author: Michele Franzin <
michele...@gmail.com>
Date: Fri Feb 22 04:45:46 2013
Log: remove duplicated MailSenderMock
http://code.google.com/p/lambico/source/detail?r=1c1905a52fbd
Revision: bd2751411931
Branch: default
Author: Michele Franzin <
michele...@gmail.com>
Date: Sun Feb 24 01:45:30 2013
Log: removed unused file (beanRefFactory_text.xml)
http://code.google.com/p/lambico/source/detail?r=bd2751411931
Revision: 5c6cc14d26b9
Branch: default
Author: Michele Franzin <
michele...@gmail.com>
Date: Wed Feb 27 08:43:09 2013
Log: rename FixtureHelper -> YamlFixtureHelper
http://code.google.com/p/lambico/source/detail?r=5c6cc14d26b9
Revision: 8e0b7e976d77
Branch: default
Author: lucio.benfante <
lucio.b...@gmail.com>
Date: Wed Mar 13 10:53:54 2013
Log: Merged Franzin's clone
http://code.google.com/p/lambico/source/detail?r=8e0b7e976d77
==============================================================================
Revision: 04c9ca677637
Branch: default
Author: Michele Franzin <
michele...@gmail.com>
Date: Thu Feb 28 09:37:13 2013
Log: refresh dependencies, upgrade build plugins
http://code.google.com/p/lambico/source/detail?r=04c9ca677637
Modified:
/lambico-spring-hibernate/pom.xml
/lambico-spring/pom.xml
/pom.xml
=======================================
--- /lambico-spring-hibernate/pom.xml Fri Apr 29 20:50:22 2011
+++ /lambico-spring-hibernate/pom.xml Thu Feb 28 09:37:13 2013
@@ -18,7 +18,7 @@
<dependencies>
<!-- START test libraries -->
<dependency>
- <groupId>hsqldb</groupId>
+ <groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<scope>test</scope>
</dependency>
@@ -42,7 +42,7 @@
<artifactId>hibernate-core</artifactId>
</dependency>
<dependency>
- <groupId>javassist</groupId>
+ <groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<scope>runtime</scope>
</dependency>
=======================================
--- /lambico-spring/pom.xml Tue Dec 13 13:37:52 2011
+++ /lambico-spring/pom.xml Thu Feb 28 09:37:13 2013
@@ -18,7 +18,7 @@
<dependencies>
<!-- START test libraries -->
<dependency>
- <groupId>hsqldb</groupId>
+ <groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<scope>test</scope>
</dependency>
@@ -74,7 +74,7 @@
</dependency>
</dependencies>
<build>
- <plugins>
+ <plugins>
<plugin>
<groupId>com.mycila.maven-license-plugin</groupId>
<artifactId>maven-license-plugin</artifactId>
=======================================
--- /pom.xml Tue Dec 13 13:37:52 2011
+++ /pom.xml Thu Feb 28 09:37:13 2013
@@ -19,11 +19,10 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<main.basedir>${basedir}</main.basedir>
<year>2009</year>
- <lambico.spring.version>3.0.5.RELEASE</lambico.spring.version>
- <lambico.hibernate.version>3.6.2.Final</lambico.hibernate.version>
-
<lambico.hibernate-annotations.version>3.5.1-Final</lambico.hibernate-annotations.version>
+ <lambico.spring.version>3.0.7.RELEASE</lambico.spring.version>
+ <lambico.hibernate.version>3.6.7.Final</lambico.hibernate.version>
<lambico.log4j.version>1.2.14</lambico.log4j.version>
- <lambico.junit4.version>4.4</lambico.junit4.version>
+ <lambico.junit4.version>4.11</lambico.junit4.version>
<!-- NetBeans IDE properties -->
<org-netbeans-modules-editor-indent.CodeStyle.usedProfile>project</org-netbeans-modules-editor-indent.CodeStyle.usedProfile>
@@ -103,7 +102,7 @@
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
- <version>1.6.9</version>
+ <version>1.7.1</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
@@ -111,9 +110,9 @@
<version>${lambico.hibernate.version}</version>
</dependency>
<dependency>
- <groupId>javassist</groupId>
+ <groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
- <version>
3.9.0.GA</version>
+ <version>3.17.1-GA</version>
</dependency>
<dependency>
<groupId>junit</groupId>
@@ -121,9 +120,9 @@
<version>${lambico.junit4.version}</version>
</dependency>
<dependency>
- <groupId>hsqldb</groupId>
+ <groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
- <version>1.8.0.10</version>
+ <version>2.2.9</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
@@ -133,32 +132,32 @@
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
- <version>2.4</version>
+ <version>2.6</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
- <version>1.4</version>
+ <version>2.4</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
- <version>1.5.8</version>
+ <version>1.7.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
- <version>1.5.8</version>
+ <version>1.7.2</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
- <version>2.2</version>
+ <version>2.2.2</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
- <version>1.4.3</version>
+ <version>1.4.5</version>
</dependency>
</dependencies>
</dependencyManagement>
@@ -167,7 +166,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
- <version>2.2.1</version>
+ <version>2.4</version>
<configuration>
<descriptors>
<descriptor>src/assembly/bin.xml</descriptor>
@@ -178,7 +177,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
- <version>2.3.2</version>
+ <version>3.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
@@ -188,7 +187,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
- <version>2.10</version>
+ <version>2.13</version>
<configuration>
<skip>false</skip>
<useFile>true</useFile>
@@ -200,7 +199,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
- <version>2.5</version>
+ <version>2.6</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
@@ -256,12 +255,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
- <version>2.8</version>
+ <version>2.9</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
- <version>2.8</version>
+ <version>2.9.1</version>
<configuration>
<configLocation>${main.basedir}/lambico_checks.xml</configLocation>
<headerLocation>${main.basedir}/LICENSE_HEADER</headerLocation>
@@ -276,7 +275,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
- <version>3.0</version>
+ <version>3.2</version>
</plugin>
</plugins>
</reporting>
@@ -286,15 +285,6 @@
***********************************************************************************
-->
<repositories>
<repository>
- <id>
maven2-repository.dev.java.net</id>
- <name>Java.net Repository for Maven</name>
- <url>
http://download.java.net/maven/2/</url>
- <layout>default</layout>
- <snapshots>
- <enabled>false</enabled>
- </snapshots>
- </repository>
- <repository>
<id>jboss-maven2-repository</id>
<name>JBoss Repository for Maven</name>
<url>
https://repository.jboss.org/nexus/content/groups/public/</url>
@@ -392,7 +382,7 @@
</contributor>
<contributor>
<name>Michele Franzin</name>
- <email>
michele...@gmail.com</email>
+ <email>
mic...@franzin.net</email>
</contributor>
<contributor>
<name>Enrico Giurin</name>
==============================================================================
Revision: 25557fd9e611
Branch: default
Author: Michele Franzin <
michele...@gmail.com>
Date: Wed Feb 27 11:00:27 2013
Log: jump to lambico v1.1
http://code.google.com/p/lambico/source/detail?r=25557fd9e611
Modified:
/lambico-core/pom.xml
/lambico-spring-hibernate/pom.xml
/lambico-spring/pom.xml
/lambico-test/pom.xml
/pom.xml
=======================================
--- /lambico-core/pom.xml Fri Apr 29 20:50:22 2011
+++ /lambico-core/pom.xml Wed Feb 27 11:00:27 2013
@@ -3,7 +3,7 @@
<parent>
<artifactId>lambico</artifactId>
<groupId>org.lambico</groupId>
- <version>1.0-SNAPSHOT</version>
+ <version>1.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.lambico</groupId>
@@ -11,7 +11,7 @@
<packaging>jar</packaging>
<name>Lambico Core</name>
<description>Base general components of Lambico.</description>
- <version>1.0-SNAPSHOT</version>
+ <version>1.1-SNAPSHOT</version>
<properties>
<main.basedir>${basedir}/..</main.basedir>
</properties>
=======================================
--- /lambico-spring-hibernate/pom.xml Thu Feb 28 09:37:13 2013
+++ /lambico-spring-hibernate/pom.xml Wed Feb 27 11:00:27 2013
@@ -4,12 +4,12 @@
<parent>
<artifactId>lambico</artifactId>
<groupId>org.lambico</groupId>
- <version>1.0-SNAPSHOT</version>
+ <version>1.1-SNAPSHOT</version>
</parent>
<groupId>org.lambico</groupId>
<artifactId>lambico-spring-hibernate</artifactId>
<packaging>jar</packaging>
- <version>1.0-SNAPSHOT</version>
+ <version>1.1-SNAPSHOT</version>
<name>Lambico Spring - Hibernate</name>
<description>Lambico implementation based on the Spring framework,
with Hibernate.</description>
<properties>
=======================================
--- /lambico-spring/pom.xml Thu Feb 28 09:37:13 2013
+++ /lambico-spring/pom.xml Wed Feb 27 11:00:27 2013
@@ -4,12 +4,12 @@
<parent>
<artifactId>lambico</artifactId>
<groupId>org.lambico</groupId>
- <version>1.0-SNAPSHOT</version>
+ <version>1.1-SNAPSHOT</version>
</parent>
<groupId>org.lambico</groupId>
<artifactId>lambico-spring</artifactId>
<packaging>jar</packaging>
- <version>1.0-SNAPSHOT</version>
+ <version>1.1-SNAPSHOT</version>
<name>Lambico Spring</name>
<description>Lambico implementation based on the Spring
framework.</description>
<properties>
=======================================
--- /lambico-test/pom.xml Tue Dec 13 13:34:32 2011
+++ /lambico-test/pom.xml Wed Feb 27 11:00:27 2013
@@ -4,12 +4,12 @@
<parent>
<artifactId>lambico</artifactId>
<groupId>org.lambico</groupId>
- <version>1.0-SNAPSHOT</version>
+ <version>1.1-SNAPSHOT</version>
</parent>
<groupId>org.lambico</groupId>
<artifactId>lambico-test</artifactId>
<packaging>jar</packaging>
- <version>1.0-SNAPSHOT</version>
+ <version>1.1-SNAPSHOT</version>
<name>Lambico Test</name>
<description>Lambico's support for unit testing.</description>
<properties>
=======================================
--- /pom.xml Thu Feb 28 09:37:13 2013
+++ /pom.xml Wed Feb 27 11:00:27 2013
@@ -4,7 +4,7 @@
<groupId>org.lambico</groupId>
<artifactId>lambico</artifactId>
<packaging>pom</packaging>
- <version>1.0-SNAPSHOT</version>
+ <version>1.1-SNAPSHOT</version>
<name>Lambico</name>
<description>Lambico provides a generic DAO infrastructure to your
applications.</description>
<url>
http://www.lambico.org</url>
==============================================================================
Revision: 32b833099c51
Branch: default
Author: Michele Franzin <
michele...@gmail.com>
Date: Wed Feb 27 10:59:57 2013
Log: added lambico-pump
http://code.google.com/p/lambico/source/detail?r=32b833099c51
Added:
/lambico-pump/pom.xml
/lambico-pump/src/main/java/org/lambico/data/EngineFactory.java
/lambico-pump/src/main/java/org/lambico/data/FixtureHelper.java
/lambico-pump/src/main/java/org/lambico/data/Pump.java
/lambico-pump/src/main/java/org/lambico/data/YamlEngine.java
/lambico-pump/src/test/java/org/lambico/data/AuthorTC.java
/lambico-pump/src/test/java/org/lambico/data/AuthorTCDao.java
/lambico-pump/src/test/java/org/lambico/data/BookTC.java
/lambico-pump/src/test/java/org/lambico/data/BookTCDao.java
/lambico-pump/src/test/java/org/lambico/data/DemoBean.java
/lambico-pump/src/test/java/org/lambico/data/FixtureHelperTest.java
/lambico-pump/src/test/resources/fixtures/AuthorTC.yml
/lambico-pump/src/test/resources/fixtures/BookTC.yml
/lambico-pump/src/test/resources/fixtures/DemoBean.yml
/lambico-pump/src/test/resources/fixtures/EntityTC.yml
/lambico-pump/src/test/resources/fixtures/String.yml
/lambico-pump/src/test/resources/fixtures/empty/DemoBean.yml
Modified:
/.hgignore
/pom.xml
=======================================
--- /dev/null
+++ /lambico-pump/pom.xml Wed Feb 27 10:59:57 2013
@@ -0,0 +1,76 @@
+<?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/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>lambico</artifactId>
+ <groupId>org.lambico</groupId>
+ <version>1.1-SNAPSHOT</version>
+ </parent>
+ <groupId>org.lambico</groupId>
+ <artifactId>lambico-pump</artifactId>
+ <packaging>jar</packaging>
+ <name>Lambico Data Pump</name>
+ <description>Lambico's support for data loading.</description>
+ <version>1.1-SNAPSHOT</version>
+ <url>
http://www.lambico.org</url>
+ <inceptionYear>2013</inceptionYear>
+ <properties>
+ <main.basedir>${basedir}/..</main.basedir>
+ </properties>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>com.mycila.maven-license-plugin</groupId>
+ <artifactId>maven-license-plugin</artifactId>
+ <configuration>
+ <properties>
+ <year>${project.inceptionYear}</year>
+ <contact>
mic...@franzin.net</contact>
+ </properties>
+ <mapping>
+ <json>SLASHSTAR_STYLE</json>
+ </mapping>
+ <excludes>
+ <exclude>target/**</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.lambico</groupId>
+ <artifactId>lambico-core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-core</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.yaml</groupId>
+ <artifactId>snakeyaml</artifactId>
+ <version>1.11</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
+
=======================================
--- /dev/null
+++ /lambico-pump/src/main/java/org/lambico/data/EngineFactory.java Wed Feb
27 10:59:57 2013
@@ -0,0 +1,40 @@
+/**
+ * Copyright (C) 2013 Lambico Team <
mic...@franzin.net>
+ *
+ * This file is part of Lambico Data Pump.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.lambico.data;
+
+/**
+ * Engine factory
+ *
+ * @author michele franzin <michele at
franzin.net>
+ */
+public class EngineFactory {
+
+ public enum EngineType {
+
+ YAML
+ }
+
+ public static Pump getEngine(final EngineType engineType) {
+ switch (engineType) {
+ case YAML:
+ return new YamlEngine();
+ default:
+ return null;
+ }
+ }
+}
=======================================
--- /dev/null
+++ /lambico-pump/src/main/java/org/lambico/data/FixtureHelper.java Wed Feb
27 10:59:57 2013
@@ -0,0 +1,199 @@
+/**
+ * Copyright (C) 2013 Lambico Team <
mic...@franzin.net>
+ *
+ * This file is part of Lambico Data Pump.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.lambico.data;
+
+import java.io.File;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Logger;
+import org.springframework.core.io.ClassPathResource;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.lambico.data.EngineFactory.EngineType;
+
+/**
+ * Fixture load / dump facility
+ *
+ * @author michele franzin <michele at
franzin.net
+ */
+public class FixtureHelper {
+
+ private static Logger logger = Logger.getLogger(FixtureHelper.class);
+ private static final Pattern HEADER_MATCH =
Pattern.compile("^-\\s??(\\S*)\\s*?$",
+ Pattern.MULTILINE);
+ private static final Pattern LINE_MATCH = Pattern.compile("^(.+)$",
Pattern.MULTILINE);
+
+ private FixtureHelper() {
+ }
+
+// /**
+// * Gets id of dao related to a model.
+// * <p/>
+// * *WARNING*: strong condition on the DAO id (entity_name+Dao) For
retriving a dao for an
+// * entity it's better something like:
+// * <code>
+// * DaoProvider daos = (DaoProvider)ctx.getBean(DAO_PROVIDER_ID);
+// * GenericDao dao = (GenericDao)daos.getDao(clazz);
+// * </code>
+// * <p/>
+// * The DAO_PROVIDER_ID usually is "daos".
+// *
+// * @param model The class of a model.
+// * @return The DAO id.
+// */
+// public static String getFixtureDaoId(final Class model) {
+// return StringUtils.uncapitalize(model.getSimpleName()) + "Dao";
+// }
+//
+// /**
+// * Gets id of dao related to a model.
+// * <p/>
+// * *WARNING*: strong condition on the DAO id (entity_name+Dao) For
retriving a dao for an
+// * entity it's better something like:
+// * <code>
+// * DaoProvider daos = (DaoProvider)ctx.getBean(DAO_PROVIDER_ID);
+// * GenericDao dao = (GenericDao)daos.getDao(clazz);
+// * </code>
+// * <p/>
+// * The DAO_PROVIDER_ID usually is "daos".
+// *
+// * @param model The class of a model.
+// * @return The business DAO id.
+// */
+// public static String getFixtureBusinessDaoId(final Class model) {
+// return StringUtils.uncapitalize(model.getSimpleName())
+ "BusinessDao";
+// }
+
+ /**
+ * Gets human readable name of a model.
+ *
+ * @param model The class of a model.
+ * @return The model name.
+ */
+ public static String getModelName(final Class model) {
+ return model.getSimpleName();
+ }
+
+ /**
+ * Load the fixtures.
+ *
+ * @param classpathResource dir relative path
+ * @param models The set of models.
+ * @return The model->values map of fixtures.
+ */
+ public static Map<Class, List> loadFixturesFromResource(final String
classpathResource,
+ final Set<Class> models) {
+ return loadFixturesFromResource(new
ClassPathResource(classpathResource), models);
+ }
+
+ /**
+ * Load the fixtures. Compose a unique fixture document (aliases are
document scoped)
+ *
+ * @param fixtureDir The directory where to search the fixtures.
+ * @param models The set of models.
+ * @return The model->values map of fixtures.
+ */
+ public static Map<Class, List> loadFixturesFromResource(final
ClassPathResource fixtureDir,
+ final Set<Class> models) {
+ // Mantiene l'ordine di inserimento
+ LinkedHashMap<Class, List> fixtures = new LinkedHashMap<Class,
List>(models.size());
+ Pump engine = EngineFactory.getEngine(EngineType.YAML);
+ StringBuilder sb = new StringBuilder();
+ for (Class model : models) {
+ InputStream stream = null;
+ String path = fixtureDir.getPath();
+ if (!path.endsWith(File.separator)) {
+ path += File.separatorChar;
+ }
+ String fixtureFileName = engine.getFixtureFileName(path,
model);
+ try {
+ ClassPathResource fixtureResource = new
ClassPathResource(fixtureFileName);
+ stream = fixtureResource.getInputStream();
+ String content = loadFixtureTextForClass(stream, model);
+ if (StringUtils.isNotBlank(content)) {
+ sb.append(content).append(IOUtils.LINE_SEPARATOR);
+ fixtures.put(model, new LinkedList());
+ } else {
+ logger.warn("No fixtures for " + getModelName(model)
+ " in the file '"
+ + fixtureFileName + "' ?");
+ }
+ } catch (FileNotFoundException e) {
+ logger.warn("Fixture file not found for " +
getModelName(model)
+ + ", did you created the file '" + fixtureFileName
+ "' ?");
+ } catch (IOException e) {
+ logger.error("Loading of fixtures failed for " +
getModelName(model), e);
+ } finally {
+ IOUtils.closeQuietly(stream);
+ }
+ }
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("### Start of Yaml generated merging the fixtures
###"
+ + IOUtils.LINE_SEPARATOR + sb.toString() +
IOUtils.LINE_SEPARATOR
+ + "### End of Yaml generated merging the fixtures
###");
+ }
+
+ Iterable<Object> loaded = engine.load(sb.toString());
+ if (loaded.iterator().hasNext()) {
+ List objectsTree = (List) loaded.iterator().next();
+ if (objectsTree != null) {
+ for (Object modelFixtures : objectsTree) {
+ List objects = (List) modelFixtures;
+ if (objects != null && !objects.isEmpty()) {
+
fixtures.get(objects.get(0).getClass()).addAll(objects);
+ }
+ }
+ }
+ }
+ return fixtures;
+ }
+
+ /**
+ * Load the content of a fixture file <Class>.yml, indenting the whole
content
+ *
+ * @param stream The fixture file.
+ * @param model The model to load.
+ * @return The content of the fixture file.
+ * @throws IOException In case of error.
+ */
+ private static String loadFixtureTextForClass(final InputStream stream,
+ final Class model) throws IOException {
+ String fixtureString = IOUtils.toString(stream, "UTF-8").trim();
+ if (StringUtils.isBlank(fixtureString)) {
+ return StringUtils.EMPTY;
+ }
+ // Add fixture class into header
+ Matcher matcher = HEADER_MATCH.matcher(fixtureString);
+ // Il replace del $ serve alla regex nel caso di inner classes
+ fixtureString = matcher.replaceAll("- $1 !!" +
model.getName().replace("$", "\\$"));
+ // Indent lines
+ matcher = LINE_MATCH.matcher(fixtureString);
+ fixtureString = matcher.replaceAll(" $1");
+ // aggiungo l'header per ottenere una lista di oggetti <Class>
+ return "-" + IOUtils.LINE_SEPARATOR + fixtureString;
+ }
+}
=======================================
--- /dev/null
+++ /lambico-pump/src/main/java/org/lambico/data/Pump.java Wed Feb 27
10:59:57 2013
@@ -0,0 +1,37 @@
+/**
+ * Copyright (C) 2013 Lambico Team <
mic...@franzin.net>
+ *
+ * This file is part of Lambico Data Pump.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.lambico.data;
+
+import java.io.InputStream;
+import java.util.Iterator;
+
+/**
+ * Data pump engine interface
+ *
+ * @author michele franzin <michele at
franzin.net>
+ */
+public interface Pump {
+
+ Iterable<Object> load(InputStream resource);
+
+ Iterable<Object> load(String text);
+
+ String dump(Iterator<Object> objects);
+
+ String getFixtureFileName(String rootPath, Class model);
+}
=======================================
--- /dev/null
+++ /lambico-pump/src/main/java/org/lambico/data/YamlEngine.java Wed Feb 27
10:59:57 2013
@@ -0,0 +1,62 @@
+/**
+ * Copyright (C) 2013 Lambico Team <
mic...@franzin.net>
+ *
+ * This file is part of Lambico Data Pump.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.lambico.data;
+
+import java.io.InputStream;
+import java.util.Iterator;
+import org.yaml.snakeyaml.DumperOptions;
+import org.yaml.snakeyaml.Yaml;
+
+/**
+ * Yaml data pump engine
+ *
+ * @author michele franzin <michele at
franzin.net>
+ */
+class YamlEngine implements Pump {
+
+ @Override
+ public Iterable<Object> load(InputStream resource) {
+ Yaml yaml = new Yaml();
+ return yaml.loadAll(resource);
+ }
+
+ @Override
+ public Iterable<Object> load(String text) {
+ Yaml yaml = new Yaml();
+ return yaml.loadAll(text);
+ }
+
+ @Override
+ public String dump(Iterator<Object> objects) {
+ DumperOptions options = new DumperOptions();
+ options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
+ Yaml yaml = new Yaml(options);
+ return yaml.dumpAll(objects);
+ }
+
+ /**
+ * Gets file name of a fixture fragment related to a model.
+ *
+ * @param model The class of a model.
+ * @return The fixture file name.
+ */
+ @Override
+ public String getFixtureFileName(final String rootPath, final Class
model) {
+ return rootPath + model.getSimpleName() + ".yml";
+ }
+}
=======================================
--- /dev/null
+++ /lambico-pump/src/test/java/org/lambico/data/AuthorTC.java Wed Feb 27
10:59:57 2013
@@ -0,0 +1,67 @@
+/**
+ * Copyright (C) 2013 Lambico Team <
mic...@franzin.net>
+ *
+ * This file is part of Lambico Data Pump.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.lambico.data;
+
+import org.lambico.po.hibernate.EntityBase;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.CascadeType;
+import javax.persistence.FetchType;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinTable;
+import javax.persistence.ManyToMany;
+import javax.persistence.NamedQuery;
+
+/**
+ * An persistent object to be used for the tests M:N relationships.
+ *
+ * @author <a href="mailto:
michele...@seesaw.it">Michele Franzin</a>
+ * @version $Revision$
+ */
+...@javax.persistence.Entity
+@NamedQuery(name = "AuthorTC.findByName", query = "from AuthorTC where
name like ?")
+public class AuthorTC extends EntityBase {
+
+ private static final long serialVersionUID = 832363948575562242L;
+
+ private String name = null;
+
+ private List<BookTC> books = new ArrayList<BookTC>();
+
+ public AuthorTC() {
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+
this.name = name;
+ }
+
+ @ManyToMany(targetEntity = BookTC.class, cascade = { CascadeType.ALL
}, fetch = FetchType.EAGER)
+ @JoinTable(name = "AUTHOR_BOOK", joinColumns = { @JoinColumn(name
= "author_id") }, inverseJoinColumns = { @JoinColumn(name = "book_id") })
+ public List<BookTC> getBooks() {
+ return books;
+ }
+
+ public void setBooks(List<BookTC> books) {
+ this.books = books;
+ }
+}
=======================================
--- /dev/null
+++ /lambico-pump/src/test/java/org/lambico/data/AuthorTCDao.java Wed Feb
27 10:59:57 2013
@@ -0,0 +1,34 @@
+/**
+ * Copyright (C) 2013 Lambico Team <
mic...@franzin.net>
+ *
+ * This file is part of Lambico Data Pump.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.lambico.data;
+
+import java.util.List;
+
+import org.lambico.dao.generic.Dao;
+import org.lambico.dao.generic.GenericDao;
+
+/**
+ * A DAO to be used for the tests M:N relationships.
+ *
+ * @author <a href="mailto:
michele...@seesaw.it">Michele Franzin</a>
+ * @version $Revision$
+ */
+@Dao(entity = AuthorTC.class)
+public interface AuthorTCDao extends GenericDao<AuthorTC, Long> {
+ List<AuthorTC> findByName(String value);
+}
=======================================
--- /dev/null
+++ /lambico-pump/src/test/java/org/lambico/data/BookTC.java Wed Feb 27
10:59:57 2013
@@ -0,0 +1,65 @@
+/**
+ * Copyright (C) 2013 Lambico Team <
mic...@franzin.net>
+ *
+ * This file is part of Lambico Data Pump.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.lambico.data;
+
+import org.lambico.po.hibernate.EntityBase;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.ManyToMany;
+import javax.persistence.NamedQuery;
+
+/**
+ * An persistent object to be used for the tests M:N relationships.
+ *
+ * @author <a href="mailto:
michele...@seesaw.it">Michele Franzin</a>
+ */
+@Entity
+@NamedQuery(name = "BookTC.findByTitle", query = "from BookTC where title
like ?")
+public class BookTC extends EntityBase {
+
+ private static final long serialVersionUID = 1L;
+
+ private String title = null;
+
+ private List<AuthorTC> authors = new ArrayList<AuthorTC>();
+
+ public BookTC() {
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ @ManyToMany(targetEntity = AuthorTC.class, cascade = { CascadeType.ALL
}, mappedBy = "books", fetch = FetchType.EAGER)
+ public List<AuthorTC> getAuthors() {
+ return authors;
+ }
+
+ public void setAuthors(List<AuthorTC> authors) {
+ this.authors = authors;
+ }
+
+}
=======================================
--- /dev/null
+++ /lambico-pump/src/test/java/org/lambico/data/BookTCDao.java Wed Feb 27
10:59:57 2013
@@ -0,0 +1,34 @@
+/**
+ * Copyright (C) 2013 Lambico Team <
mic...@franzin.net>
+ *
+ * This file is part of Lambico Data Pump.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.lambico.data;
+
+import java.util.List;
+
+import org.lambico.dao.generic.Dao;
+import org.lambico.dao.generic.GenericDao;
+
+/**
+ * A DAO to be used for the tests M:N relationships.
+ *
+ * @author <a href="mailto:
michele...@seesaw.it">Michele Franzin</a>
+ * @version $Revision$
+ */
+@Dao(entity = BookTC.class)
+public interface BookTCDao extends GenericDao<BookTC, Long> {
+ List<BookTC> findByTitle(String value);
+}
=======================================
--- /dev/null
+++ /lambico-pump/src/test/java/org/lambico/data/DemoBean.java Wed Feb 27
10:59:57 2013
@@ -0,0 +1,70 @@
+/**
+ * Copyright (C) 2013 Lambico Team <
mic...@franzin.net>
+ *
+ * This file is part of Lambico Data Pump.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.lambico.data;
+
+public class DemoBean {
+ public String nome;
+
+ private Long id;
+
+ public DemoBean() {
+ super();
+ }
+
+ public DemoBean(String nome, Long id) {
+ this.nome = nome;
+
this.id = id;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long value) {
+
this.id = value;
+ }
+
+ @Override
+ public String toString() {
+ return "nome=" + nome + ", id=" + id;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if ((obj == null) || (obj.getClass() != this.getClass()))
+ return false;
+ // object must be DemoBean at this point
+ DemoBean test = (DemoBean) obj;
+ return (id == test.getId() || (id != null && id.equals(
test.id)))
+ && (nome == test.nome || (nome != null &&
nome.equals(test.nome)));
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 0;
+ if (id != null) {
+ hash += id.hashCode();
+ }
+ if (nome != null) {
+ hash += nome.hashCode();
+ }
+ return hash == 0 ? super.hashCode() : hash;
+ }
+}
=======================================
--- /dev/null
+++ /lambico-pump/src/test/java/org/lambico/data/FixtureHelperTest.java Wed
Feb 27 10:59:57 2013
@@ -0,0 +1,126 @@
+/**
+ * Copyright (C) 2013 Lambico Team <
mic...@franzin.net>
+ *
+ * This file is part of Lambico Data Pump.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.lambico.data;
+
+import java.math.BigDecimal;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import junit.framework.TestCase;
+import static junit.framework.TestCase.assertEquals;
+import static junit.framework.TestCase.assertNotNull;
+import org.springframework.util.CollectionUtils;
+
+/**
+ * @author michele franzin <michele at
franzin.net>
+ */
+public class FixtureHelperTest extends TestCase {
+
+ private DemoBean[] expected;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ expected = new DemoBean[5];
+ expected[0] = new DemoBean("first one", new Long(356));
+ expected[1] = new DemoBean("Demo 1", new Long(6789));
+ expected[2] = new DemoBean("àèéìòù", new Long(-980000));
+ expected[3] = new DemoBean("Demo3", new Long(98000));
+ expected[4] = new DemoBean("Demo#2", new Long(-9800));
+ }
+
+ public void testShouldNotFailWrongFixtureDir() {
+ Set<Class> models = new
LinkedHashSet<Class>(CollectionUtils.arrayToList(new Class[]{
+ DemoBean.class}));
+ Map<Class, List> objects =
FixtureHelper.loadFixturesFromResource("nonExistant", models);
+ assertTrue("Le fixture non sono vuote", objects.isEmpty());
+ }
+
+ public void testShouldNotFailIfMissingFixtureFile() {
+ Set<Class> models = new
LinkedHashSet<Class>(CollectionUtils.arrayToList(new Class[]{
+ BigDecimal.class}));
+ Map<Class, List> objects =
FixtureHelper.loadFixturesFromResource("fixtures", models);
+ assertTrue("Le fixture non sono vuote", objects.isEmpty());
+ }
+
+ public void testShouldNotFailWhenTrailingSlashPresent() throws
Exception {
+ Set<Class> models = new LinkedHashSet<Class>(
+ CollectionUtils.arrayToList(new Class[]{DemoBean.class}));
+ Map<Class, List> objects =
FixtureHelper.loadFixturesFromResource("fixtures/", models);
+ assertNotNull("Non ha ritornato la mappa di fixtures", objects);
+ }
+
+ public void testShouldNotFailIfNoFile() {
+ Set<Class> models = new LinkedHashSet<Class>();
+ Map<Class, List> objects =
FixtureHelper.loadFixturesFromResource("emptyDir", models);
+ assertTrue("Le fixture non sono vuote", objects.isEmpty());
+ }
+
+ public void testShouldNotFailIfEmptyFile() {
+ Set<Class> models = new
LinkedHashSet<Class>(CollectionUtils.arrayToList(new Class[]{
+ DemoBean.class}));
+ Map<Class, List> objects =
FixtureHelper.loadFixturesFromResource("fixtures/empty", models);
+ assertEquals("Non carica tutti i beans", 1, objects.size());
+ assertTrue("Le fixture non sono vuote",
objects.get(DemoBean.class).isEmpty());
+ }
+
+ public void testBeanLoading() {
+ Set<Class> models = new
LinkedHashSet<Class>(CollectionUtils.arrayToList(new Class[]{
+ DemoBean.class}));
+ Map<Class, List> objects =
FixtureHelper.loadFixturesFromResource("fixtures", models);
+ assertNotNull("Non ha ritornato la mappa di fixtures", objects);
+ assertEquals("Non carica tutti i beans", 1, objects.size());
+ assertTrue("Non crea istanze di " +
DemoBean.class.getCanonicalName(), objects.containsKey(
+ DemoBean.class));
+ List<DemoBean> result = (List<DemoBean>)
objects.get(DemoBean.class);
+ assertEquals("Non carica tutti i beans", 5, result.size());
+ for (int i = 0; i < 5; i++) {
+ assertEquals("Non ha caricato correttamente il bean numero " +
i, expected[i], result.
+ get(i));
+ }
+ }
+
+ public void testBookLoading() {
+ Set<Class> models = new
LinkedHashSet<Class>(CollectionUtils.arrayToList(new Class[]{
+ BookTC.class, AuthorTC.class}));
+ Map<Class, List> objects =
FixtureHelper.loadFixturesFromResource("fixtures", models);
+ assertNotNull("Non ha ritornato la mappa di fixtures", objects);
+ assertEquals(2, objects.size());
+ assertEquals(3, objects.get(BookTC.class).size());
+ assertEquals(4, objects.get(AuthorTC.class).size());
+ assertBookAuthorsAreIdentical(objects.get(BookTC.class),
objects.get(AuthorTC.class));
+ }
+
+ public void testFixtureMerge() {
+ Set<Class> models = new
LinkedHashSet<Class>(CollectionUtils.arrayToList(new Class[]{
+ BookTC.class, AuthorTC.class}));
+ Map<Class, List> objects =
FixtureHelper.loadFixturesFromResource("fixtures", models);
+ AuthorTC author = (AuthorTC) objects.get(AuthorTC.class).get(3);
+ assertEquals("john", author.getName());
+ assertEquals("Java manual", author.getBooks().get(0).getTitle());
+ }
+
+ private void assertBookAuthorsAreIdentical(List<BookTC> books,
List<AuthorTC> authors) {
+ for (BookTC book : books) {
+ for (AuthorTC author : book.getAuthors()) {
+ assertTrue("The book author is not in the author array",
authors.contains(author));
+ }
+ }
+ }
+}
=======================================
--- /dev/null
+++ /lambico-pump/src/test/resources/fixtures/AuthorTC.yml Wed Feb 27
10:59:57 2013
@@ -0,0 +1,35 @@
+#
+# Copyright (C) 2013 Lambico Team <
mic...@franzin.net>
+#
+# This file is part of Lambico Data Pump.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#
http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+- &Author-joe
+ name: joe
+ books:
+ - *Book-WarPeace
+ - *Book-Bean
+- &Author-sam
+ name: sam
+ books:
+ - *Book-Java
+ - *Book-Bean
+- &Author-peter
+ name: peter
+ books:
+ - *Book-Java
+- &Author-john
+ <<: *Author-peter
+ name: john
=======================================
--- /dev/null
+++ /lambico-pump/src/test/resources/fixtures/BookTC.yml Wed Feb 27
10:59:57 2013
@@ -0,0 +1,24 @@
+#
+# Copyright (C) 2013 Lambico Team <
mic...@franzin.net>
+#
+# This file is part of Lambico Data Pump.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#
http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+- &Book-WarPeace
+ title: War and Peace
+- &Book-Bean
+ title: Mr. Bean
+- &Book-Java
+ title: Java manual
=======================================
--- /dev/null
+++ /lambico-pump/src/test/resources/fixtures/DemoBean.yml Wed Feb 27
10:59:57 2013
@@ -0,0 +1,39 @@
+#
+# Copyright (C) 2013 Lambico Team <
mic...@franzin.net>
+#
+# This file is part of Lambico Data Pump.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#
http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+-
+ nome: "first one"
+ id: 356
+
+# Ending with spaces
+- &demo1
+ nome: "Demo 1"
+ id: 6789
+
+# Without anchor
+-
+ nome: "àèéìòù"
+ id: -980000
+
+- &demo3
+ nome: "Demo3"
+ id: 98000
+
+- &demo2
+ nome: "Demo#2"
+ id: -9800
=======================================
--- /dev/null
+++ /lambico-pump/src/test/resources/fixtures/EntityTC.yml Wed Feb 27
10:59:57 2013
@@ -0,0 +1,43 @@
+#
+# Copyright (C) 2013 Lambico Team <
mic...@franzin.net>
+#
+# This file is part of Lambico Data Pump.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#
http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+-
+ fieldOne: "one1"
+ fieldTwo: "two5"
+ fieldThree: "Three1"
+ numericField: 1
+-
+ fieldOne: "one2"
+ fieldTwo: "two4"
+ fieldThree: "Three2"
+ numericField: 2
+-
+ fieldOne: "one3"
+ fieldTwo: "two3"
+ fieldThree: "Three3"
+ numericField: 3
+-
+ fieldOne: "one4"
+ fieldTwo: "two2"
+ fieldThree: "Three4"
+ numericField: 4
+-
+ fieldOne: "one3"
+ fieldTwo: "two1"
+ fieldThree: "7hree5"
+ numericField: 5
=======================================
--- /dev/null
+++ /lambico-pump/src/test/resources/fixtures/String.yml Wed Feb 27
10:59:57 2013
@@ -0,0 +1,22 @@
+#
+# Copyright (C) 2013 Lambico Team <
mic...@franzin.net>
+#
+# This file is part of Lambico Data Pump.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#
http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+-
+ Questo è un file UTF8 con preambolo
+-
+ òàùèì
=======================================
--- /dev/null
+++ /lambico-pump/src/test/resources/fixtures/empty/DemoBean.yml Wed Feb 27
10:59:57 2013
@@ -0,0 +1,19 @@
+#
+# Copyright (C) 2013 Lambico Team <
mic...@franzin.net>
+#
+# This file is part of Lambico Data Pump.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#
http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+#
=======================================
--- /.hgignore Mon Feb 8 12:48:29 2010
+++ /.hgignore Wed Feb 27 10:59:57 2013
@@ -6,3 +6,4 @@
^lambico-spring/target
^lambico-spring-hibernate/target
^lambico-test/target
+^lambico-pump/target
=======================================
--- /pom.xml Wed Feb 27 11:00:27 2013
+++ /pom.xml Wed Feb 27 10:59:57 2013
@@ -14,6 +14,7 @@
<module>lambico-spring</module>
<module>lambico-spring-hibernate</module>
<module>lambico-test</module>
+ <module>lambico-pump</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -61,13 +62,13 @@
</dependency>
<dependency>
<groupId>org.lambico</groupId>
- <artifactId>lambico-test</artifactId>
+ <artifactId>lambico-pump</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>org.parancoe</groupId>
- <artifactId>parancoe-yaml</artifactId>
- <version>3.0-SNAPSHOT</version>
+ <groupId>org.lambico</groupId>
+ <artifactId>lambico-test</artifactId>
+ <version>${project.version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
@@ -75,6 +76,11 @@
<version>${lambico.log4j.version}</version>
</dependency>
<dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-core</artifactId>
+ <version>${lambico.spring.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${lambico.spring.version}</version>
==============================================================================
Revision: 3e2a87f1f307
Branch: default
Author: Michele Franzin <
michele...@gmail.com>
Date: Wed Feb 13 07:29:03 2013
Log: lambico-test now depends on lambico-pump (drops parancoe-yaml
dependency)
http://code.google.com/p/lambico/source/detail?r=3e2a87f1f307
Added:
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/FixtureUtils.java
Deleted:
/lambico-test/src/main/java/org/lambico/test/spring/Utils.java
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/FixtureHelper.java
/lambico-test/src/test/java/org/lambico/test/spring/hibernate/AuthorTC.java
/lambico-test/src/test/java/org/lambico/test/spring/hibernate/AuthorTCDao.java
/lambico-test/src/test/java/org/lambico/test/spring/hibernate/BookTC.java
/lambico-test/src/test/java/org/lambico/test/spring/hibernate/BookTCDao.java
/lambico-test/src/test/java/org/lambico/test/spring/hibernate/DemoBean.java
/lambico-test/src/test/java/org/lambico/test/spring/hibernate/FixtureHelperTest.java
/lambico-test/src/test/java/org/lambico/test/spring/hibernate/UtilsTest.java
/lambico-test/src/test/resources/fixtures/AuthorTC.yml
/lambico-test/src/test/resources/fixtures/BookTC.yml
/lambico-test/src/test/resources/fixtures/DemoBean.yml
/lambico-test/src/test/resources/fixtures/EntityTC.yml
/lambico-test/src/test/resources/fixtures/String.yml
/lambico-test/src/test/resources/testdata/UTF8WithPreamble.txt
/lambico-test/src/test/resources/testdata/UTF8WithoutPreamble.txt
Modified:
/lambico-core/pom.xml
/lambico-spring-hibernate/src/test/java/org/lambico/spring/dao/hibernate/BaseTest.java
/lambico-spring-hibernate/src/test/java/org/lambico/spring/dao/hibernate/CachedEntityTCTest.java
/lambico-spring-hibernate/src/test/resources/fixtures/DemoBean.yml
/lambico-test/pom.xml
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/DBTest.java
=======================================
--- /dev/null
+++
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/FixtureUtils.java
Wed Feb 13 07:29:03 2013
@@ -0,0 +1,89 @@
+/**
+ * Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
+ *
+ * This file is part of Lambico Test.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.lambico.test.spring.hibernate;
+
+import java.util.List;
+import org.apache.log4j.Logger;
+import org.hibernate.cfg.DefaultComponentSafeNamingStrategy;
+import org.lambico.dao.generic.GenericDaoBase;
+import org.lambico.dao.spring.hibernate.GenericDaoHibernateSupport;
+import static org.lambico.data.FixtureHelper.getFixtureFileName;
+import static org.lambico.data.FixtureHelper.getModelName;
+import org.springframework.orm.hibernate3.HibernateTemplate;
+
+/**
+ * Fixture utility class.
+ *
+ * @author michele franzin <michele @
franzin.net
+ */
+public class FixtureUtils {
+
+ private static Logger logger = Logger.getLogger(FixtureUtils.class);
+
+ /**
+ * Populate the DB with the fixtures data.
+ *
+ * @param model The model to populate.
+ * @param fixtures The fixtures.
+ * @param dao The DAO to use.
+ */
+ public static void populateDbForModel(final Class model, final List
fixtures,
+ final GenericDaoBase dao) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Populating table for " + getModelName(model));
+ }
+ if (fixtures == null) {
+ logger.warn("No fixtures for " + getModelName(model) + ", did
you created the file '"
+ + getFixtureFileName(model) + "'?");
+ return;
+ }
+ final HibernateTemplate template = ((GenericDaoHibernateSupport)
dao).getHibernateTemplate();
+ try {
+ for (Object entity : fixtures) {
+ template.saveOrUpdate(entity);
+ }
+ template.flush();
+ template.clear();
+ } catch (Exception e) {
+ logger.error("Error populating rows in " + getModelName(model)
+ " table", e);
+ }
+ }
+
+ /**
+ * Erase the DB for a model.
+ *
+ * @param model The model to erase.
+ * @param dao The DAO tp use.
+ */
+ public static void eraseDbForModel(final Class model, final
GenericDaoBase dao) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Erasing table for " + getModelName(model));
+ }
+ try {
+ if (dao == null) {
+ throw new IllegalArgumentException("Dao associated to " +
model.getName()
+ + " PO is null!");
+ }
+
+ /* int deleted = */ ((GenericDaoHibernateSupport)
dao).getHibernateTemplate().bulkUpdate("DELETE FROM "
+ +
DefaultComponentSafeNamingStrategy.INSTANCE.tableName(model.getSimpleName()));
+ } catch (Exception e) {
+ logger.error("Error deleting rows in " + getModelName(model)
+ " table", e);
+ }
+ }
+}
=======================================
--- /lambico-test/src/main/java/org/lambico/test/spring/Utils.java Tue Dec
13 13:34:32 2011
+++ /dev/null
@@ -1,314 +0,0 @@
-/**
- * Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
- *
- * This file is part of Lambico Test.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *
http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.lambico.test.spring;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.ArrayUtils;
-import org.apache.log4j.Logger;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.core.io.Resource;
-
-/**
- * Some utility methods.
- *
- * @author Paolo Dona
paolo...@seesaw.it
- * @author Michele Franzin
paolo...@seesaw.it
- * @author Andrea Nasato <mailto:
andrea...@jugpadova.it/>
- */
-public class Utils {
-
- /** The logger for this class. */
- private static Logger logger = Logger.getLogger(Utils.class);
- /** The UTF8 preamble. */
- private static final byte[] UTF8_PREAMBLE = new byte[]{(byte) 0xEF,
(byte) 0xBB, (byte) 0xBF};
- /** The UTF8 Unicode preamble. */
- private static final String UTF8_UNICODE_PREAMBLE = "";
-
- /**
- * A default protected constructor.
- */
- protected Utils() {
- }
-
- /**
- * Converts a map in a list of name/value pairs.
- *
- * @param map The map.
- * @return A list of name/value pairs (name=value).
- */
- @SuppressWarnings(value = "unchecked")
- public static List<String> convertToNameValueList(final Map map) {
- return convertToNameValueList(map, false);
- }
-
- /**
- * Converts a map in a list of name/value pairs.
- *
- * @param map The map.
- * @param urlEncode if true, encode the values as URLs.
- * @return A list of name/value pairs (name=value).
- */
- @SuppressWarnings(value = "unchecked")
- public static List<String> convertToNameValueList(final Map map, final
boolean urlEncode) {
- List<String> result = new ArrayList<String>();
- for (String key : (Iterable<String>) map.keySet()) {
- Object tmp = map.get(key);
- if (tmp instanceof String[]) {
- String[] values = (String[]) tmp;
- for (String value : values) {
- if (urlEncode) {
- try {
- result.add(key + "="
- +
java.net.URLEncoder.encode(value, "UTF-8"));
- } catch (UnsupportedEncodingException ex) {
- logger.warn("Your OS doesn't support UTF-8, so
we can encode",
- ex);
- result.add(key + "=" + value);
- }
- } else {
- result.add(key + "=" + value);
- }
- }
- } else if (tmp instanceof String) {
- String value = (String) tmp;
- if (urlEncode) {
- try {
- result.add(key + "="
- +
java.net.URLEncoder.encode(value, "UTF-8"));
- } catch (UnsupportedEncodingException ex) {
- logger.warn("Your OS doesn't support UTF-8, so we
can encode",
- ex);
- result.add(key + "=" + value);
- }
- } else {
- result.add(key + "=" + value);
- }
- }
- }
- return result;
- }
-
- /**
- * Loads a binary file from the classpath.
- *
- * @param classpathResource The resource path.
- * @return The content of the classpath resource.
- */
- public static byte[] loadBinary(final String classpathResource) {
- return loadBinary(new ClassPathResource(classpathResource));
- }
-
- /**
- * Loads a binary file from the classpath.
- *
- * @param classpathResource The resource path.
- * @return The content of the classpath resource.
- */
- public static byte[] loadBinary(final Resource classpathResource) {
- InputStream stream = null;
- try {
- stream = classpathResource.getInputStream();
- return unsafeLoadBinary(stream);
- } catch (IOException e) {
- throw new RuntimeException("Impossibile caricare la risorsa
binaria '"
- + classpathResource.getDescription() + "' dal
classpath.");
- } finally {
- IOUtils.closeQuietly(stream);
- }
- }
-
- /**
- * Loads a binary file from a stream.
- *
- * @param stream The stream from where to load. It is open,
- * and it won't be closed by this method.
- * @return The content of the classpath resource.
- * @throws IOException In case of error.
- */
- protected static byte[] unsafeLoadBinary(final InputStream stream)
throws IOException {
- return IOUtils.toByteArray(stream);
- }
-
- /**
- * Loads a text file from the classpath.
- * NB: UTF-8 header are removed!
- *
- * @param classpathResource The resource path.
- * @return The content of the classpath resource.
- */
- public static String loadString(final String classpathResource) {
- return loadString(new ClassPathResource(classpathResource));
- }
-
- /**
- * Loads a text file from the classpath.
- * NB: UTF-8 header are removed!
- *
- * @param classpathResource The resource path.
- * @return The content of the classpath resource.
- */
- public static String loadString(final Resource classpathResource) {
- InputStream stream = null;
- try {
- stream = classpathResource.getInputStream();
- return unsafeLoadString(stream);
- } catch (IOException e) {
- throw new RuntimeException("Impossibile caricare la risorsa
testuale '"
- + classpathResource.getDescription() + "' dal
classpath.");
- } finally {
- IOUtils.closeQuietly(stream);
- }
- }
-
- /**
- * Loads a text file from a stream.
- *
- * @param stream The stream from where to load. It is open,
- * and it won't be closed by this method.
- * @return The content of the classpath resource.
- * @throws IOException In case of error.
- */
- protected static String unsafeLoadString(final InputStream stream)
throws IOException {
- byte[] byteResult =
- IOUtils.toByteArray(stream);
- return stripUTF8preamble(new String(byteResult, "UTF-8"));
- }
-
- /**
- * Strips the UTF8 preamble, if present.
- *
- * NB: the conversion to byte array, and a following strip won't work.
The reason is that:
- * <code>new String(UTF8_PREAMBLE).getBytes() != UTF8_PREAMBLE</code>;
- *
- * <a
href="
http://mail.python.org/pipermail/python-list/2004-February/250798.html">Here</a>
- * an explanation.
- *
- * @param s The string to strip.
- * @return The string without the UTF8 preamble.
- * @throws UnsupportedEncodingException If the UTF-8 encoding is not
supported.
- */
- public static String stripUTF8preamble(final String s) throws
UnsupportedEncodingException {
- if (hasUTF8preamble(s)) {
- logger.debug("Rimosso header UTF-8 dalla stringa");
- return s.substring(1);
- }
- return s;
- }
-
- /**
- * Strips the UTF8 preamble, if present.
- *
- * @param b The array of bytes (characters).
- * @return The stripped array.
- */
- public static byte[] stripUTF8preamble(final byte[] b) {
- byte[] result = null;
- if (hasUTF8preamble(b)) {
- logger.debug("Rimosso header UTF-8 dall'array");
- result = ArrayUtils.subarray(b, UTF8_PREAMBLE.length,
b.length);
- }
- return result;
- }
-
- /**
- * Checks if the array starts with the UTF-8 preamble.
- *
- * @param b The array to inspect.
- * @return true if the array starts with the UTF-8 preamble.
- */
- public static boolean hasUTF8preamble(final byte[] b) {
- return b[0] == UTF8_PREAMBLE[0] && b[1] == UTF8_PREAMBLE[1]
- && b[2] == UTF8_PREAMBLE[2];
- }
-
- /**
- * Checks if the string starts with the UTF-8 preamble.
- *
- * @param s The string to inspect.
- * @return true if the string starts with the UTF-8 preamble.
- */
- public static boolean hasUTF8preamble(final String s) {
- return s.startsWith(UTF8_UNICODE_PREAMBLE);
- }
-
- /**
- * Return an array containing all the substrings of
- * <code>camelString</code>, according to this rule: divide
<code>camelString</code>
- * into tokens with every token starting from a capital letter to
another.
- *
- * Some examples:
- * <ol>
- * <li>'MyCamelString' gives: {my,camel,string}</li>
- * <li>'myFantasticCamelString' gives:
{my,fantastic,camel,string}</li>
- * <li>'MYCAMELSTRING' gives: {m,y,c,a,m,e,l,s,t,r,i,n,g}</li>
- * </ol>
- *
- * @param camelString The string to uncamelize.
- * @return The string uncamelized.
- */
- public static String[] uncamelize(final String camelString) {
-
- if (camelString == null || camelString.trim().equals("")) {
- throw new IllegalArgumentException("camelString cannot be null
or empty");
- }
- List<Integer> idxList = new ArrayList<Integer>();
- List<String> strList = new ArrayList<String>();
-
- //\p{Lu} is the unicode pattern for capital letters
- Pattern p = Pattern.compile("\\p{Lu}");
- Matcher m = p.matcher(camelString);
-
- //find all occurences of an uppercase letter and put their
position on a list
- while (m.find()) {
- idxList.add(m.start());
- }
-
- // no upper case found: we return the entire word
- if (idxList.size() == 0) {
- return new String[]{camelString};
- }
-
- Integer[] idx = idxList.toArray(new Integer[idxList.size() - 1]);
-
- for (int i = 0; i < idx.length; i++) {
-
- //if the first character of camelString is lower case,
- //substring from 0 to index[1]
- if (i == 0 && idx[i] > 0) {
- strList.add(camelString.substring(0,
idx[i]).toLowerCase());
- }
-
- //the last part of the word hasn't got an end guard
- if (i == idx.length - 1) {
- strList.add(camelString.substring(idx[i],
camelString.length()).toLowerCase());
- } else {
- strList.add(camelString.substring(idx[i], idx[i +
1]).toLowerCase());
- }
- }
-
- return strList.toArray(new String[strList.size() - 1]);
- }
-}
=======================================
---
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/FixtureHelper.java
Tue Dec 13 13:34:32 2011
+++ /dev/null
@@ -1,293 +0,0 @@
-/**
- * Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
- *
- * This file is part of Lambico Test.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *
http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.lambico.test.spring.hibernate;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.ArrayUtils;
-import org.apache.commons.lang.StringUtils;
-import org.apache.log4j.Logger;
-import org.parancoe.yaml.Yaml;
-import org.springframework.core.io.ClassPathResource;
-
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import org.lambico.dao.generic.GenericDaoBase;
-import org.lambico.dao.spring.hibernate.GenericDaoHibernateSupport;
-import org.lambico.test.spring.Utils;
-import org.springframework.core.io.Resource;
-
-/**
- * @author Paolo Dona
paolo...@seesaw.it
- * @author Michele Franzin
michele...@seesaw.it
- */
-public class FixtureHelper {
-
- /** The logger for this class. */
- private static Logger logger = Logger.getLogger(FixtureHelper.class);
- /** The header match. */
- private static final Pattern HEADER_MATCH = Pattern.compile(
- "^-\\s??(\\S*)\\s*?$", Pattern.MULTILINE);
- /** The line match. */
- private static final Pattern LINE_MATCH = Pattern.compile("^(.+)$",
- Pattern.MULTILINE);
-
- /**
- * A default protected constructor.
- */
- protected FixtureHelper() {
- }
-
- /**
- * Gets file name of a fixture fragment related to a model.
- *
- * @param model The class of a model.
- * @return The fixture file name.
- */
- public static String getFixtureFileName(final Class model) {
- return model.getSimpleName() + ".yml";
- }
-
- /**
- * Gets id of dao related to a model.
- * <p/>
- * *WARNING*: strong condition on the DAO id (entity_name+Dao) For
retriving
- * a dao for an entity it's better something like: <code>
- * DaoProvider daos = (DaoProvider)ctx.getBean(DAO_PROVIDER_ID);
- * GenericDao dao = (GenericDao)daos.getDao(clazz);
- * </code>
- * <p/>
- * The DAO_PROVIDER_ID usually is "daos".
- *
- * @param model The class of a model.
- * @return The DAO id.
- */
- public static String getFixtureDaoId(final Class model) {
- return StringUtils.uncapitalize(model.getSimpleName()) + "Dao";
- }
-
- /**
- * Gets id of dao related to a model.
- * <p/>
- * *WARNING*: strong condition on the DAO id (entity_name+Dao) For
retriving
- * a dao for an entity it's better something like: <code>
- * DaoProvider daos = (DaoProvider)ctx.getBean(DAO_PROVIDER_ID);
- * GenericDao dao = (GenericDao)daos.getDao(clazz);
- * </code>
- * <p/>
- * The DAO_PROVIDER_ID usually is "daos".
- *
- * @param model The class of a model.
- * @return The business DAO id.
- */
- public static String getFixtureBusinessDaoId(final Class model) {
- return StringUtils.uncapitalize(model.getSimpleName())
+ "BusinessDao";
- }
-
- /**
- * Gets human readable name of a model.
- *
- * @param model The class of a model.
- * @return The model name.
- */
- public static String getModelName(final Class model) {
- return model.getSimpleName();
- }
-
- /**
- * Load the fixtures.
- *
- * @param classpathResource dir relative path
- * @param models The set of models.
- * @return The model->values map of fixtures.
- */
- public static Map<Class, Object[]> loadFixturesFromResource(
- final String classpathResource, final Set<Class> models) {
- return loadFixturesFromResource(
- new ClassPathResource(classpathResource), models);
- }
-
- /**
- * Load the fixtures.
- *
- * @param fixtureDir The directory where to search the fixtures.
- * @param models The set of models.
- * @return The model->values map of fixtures.
- */
- public static Map<Class, Object[]> loadFixturesFromResource(
- final ClassPathResource fixtureDir, final Set<Class> models) {
- LinkedHashMap<Class, Object[]> fixtures = new LinkedHashMap<Class,
Object[]>(
- models.size());
- String fixtureFileName = null;
- StringBuffer sb = new StringBuffer();
- for (Class model : models) {
- fixtureFileName = fixtureDir.getPath() +
getFixtureFileName(model);
- InputStream stream = null;
- try {
- Resource fixtureResource =
- new ClassPathResource(fixtureFileName);
- stream = fixtureResource.getInputStream();
- String content =
loadFixtureStringForClass(fixtureResource, model);
- if (StringUtils.isNotBlank(content)) {
- sb.append(content);
- sb.append(IOUtils.LINE_SEPARATOR);
- // Mantiene l'ordine di inserimento
- fixtures.put(model, null);
- } else {
- logger.warn("No fixtures for "
- + getModelName(model) + " in the file '"
- + fixtureFileName + "' ?");
- }
- } catch (FileNotFoundException e) {
- logger.warn("Fixture file not found for "
- + getModelName(model) + ", did you created the
file '"
- + fixtureFileName + "' ?");
- } catch (IOException e) {
- logger.error("Loading of fixtures failed for "
- + getModelName(model), e);
- } finally {
- IOUtils.closeQuietly(stream);
- }
- }
-
- if (sb.length() == 0) {
- sb.append("--- !java.lang.Object[] []" +
IOUtils.LINE_SEPARATOR);
- } else {
- sb.insert(0, "--- !java.lang.Object[]" +
IOUtils.LINE_SEPARATOR);
- }
-
- sb.append("...");
- sb.append(IOUtils.LINE_SEPARATOR);
-
- if (logger.isDebugEnabled()) {
- logger.debug("### Start of Yaml generated merging the fixtures
###\n"
- + sb.toString()
- + "\n### End of Yaml generated merging the fixtures
###");
- }
-
- // Debug file output
- // try {
- // FileUtils.writeStringToFile(new File("dump.yml"), sb.toString(),
- // "UTF-8");
- // } catch (IOException e) {
- // e.printStackTrace();
- // }
-
- // Se il documento è vuoto, yaml ritorna un'HashMap
- Object any = Yaml.load(sb.toString());
-
- if (any instanceof Object[]) {
- Object[] fixtureObjects = (Object[]) any;
- for (Object fixtureObject : fixtureObjects) {
- Object[] objects = (Object[]) fixtureObject;
- // null safe handling
- if (!ArrayUtils.isEmpty(objects)) {
- fixtures.put(objects[0].getClass(), objects);
- }
- }
- }
- return fixtures;
- }
-
- /**
- * Load the content of a fixture file <Class>.yml.
- *
- * @param resource The fixture file.
- * @param model The model to load.
- * @return The content of the fixture file.
- * @throws IOException In case of error.
- */
- private static String loadFixtureStringForClass(final Resource
resource,
- final Class model) throws IOException {
- String fixtureString = Utils.loadString(resource);
- // Add fixture class into header
- Matcher matcher = HEADER_MATCH.matcher(fixtureString);
- // Il replace del $ serve alla regex nel caso di inner classes
- fixtureString = matcher.replaceAll("- $1 !"
- + model.getName().replace("$", "\\$"));
- // Indent lines
- matcher = LINE_MATCH.matcher(fixtureString);
- fixtureString = matcher.replaceAll(" $1");
- // aggiungo l'header (Array di oggetti <Class>)
- return "- !" + model.getName() + "[]" + IOUtils.LINE_SEPARATOR
- + fixtureString;
- }
-
- /**
- * Populate the DB with the fixtures data.
- *
- * @param model The model to populate.
- * @param fixtures The fixtures.
- * @param dao The DAO to use.
- */
- @SuppressWarnings("unchecked")
- public static void populateDbForModel(final Class model, final
Object[] fixtures,
- final GenericDaoBase dao) {
- logger.debug("Populating table for " + getModelName(model));
- if (fixtures == null) {
- logger.warn("No fixtures for " + getModelName(model)
- + ", did you created the file '" +
getFixtureFileName(model)
- + "'?");
- return;
- }
- try {
- for (Object entity : fixtures) {
- ((GenericDaoHibernateSupport)
dao).getHibernateTemplate().saveOrUpdate(entity);
- }
- ((GenericDaoHibernateSupport)
dao).getHibernateTemplate().flush();
- ((GenericDaoHibernateSupport)
dao).getHibernateTemplate().clear();
- } catch (Exception e) {
- logger.error("Error populating rows in " + getModelName(model)
- + " table", e);
- }
- }
-
- /**
- * Erase the DB for a model.
- *
- * @param model The model to erase.
- * @param dao The DAO tp use.
- */
- @SuppressWarnings("unchecked")
- public static void eraseDbForModel(final Class model, final
GenericDaoBase dao) {
- logger.debug("Erasing table for " + getModelName(model));
- try {
- // List rows = dao.findAll();
- // for (Object o : rows) {
- // dao.delete(o);
- // }
- if (dao == null) {
- throw new IllegalArgumentException("Dao associated to "
- + model.getName() + " PO is null!");
- }
-
- int deleted = ((GenericDaoHibernateSupport)
dao).getHibernateTemplate().
- bulkUpdate("DELETE FROM "
- +
org.hibernate.cfg.DefaultComponentSafeNamingStrategy.INSTANCE.tableName(
- model.getSimpleName()));
- } catch (Exception e) {
- logger.error("Error deleting rows in " + getModelName(model)
- + " table", e);
- }
- }
-}
=======================================
---
/lambico-test/src/test/java/org/lambico/test/spring/hibernate/AuthorTC.java
Tue Dec 13 13:34:32 2011
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- * Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
- *
- * This file is part of Lambico Test.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *
http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.lambico.test.spring.hibernate;
-
-import org.lambico.po.hibernate.EntityBase;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.persistence.CascadeType;
-import javax.persistence.FetchType;
-import javax.persistence.JoinColumn;
-import javax.persistence.JoinTable;
-import javax.persistence.ManyToMany;
-import javax.persistence.NamedQuery;
-
-/**
- * An persistent object to be used for the tests M:N relationships.
- *
- * @author <a href="mailto:
michele...@seesaw.it">Michele Franzin</a>
- * @version $Revision$
- */
-...@javax.persistence.Entity
-@NamedQuery(name = "AuthorTC.findByName", query = "from AuthorTC where
name like ?")
-public class AuthorTC extends EntityBase {
-
- private static final long serialVersionUID = 832363948575562242L;
-
- private String name = null;
-
- private List<BookTC> books = new ArrayList<BookTC>();
-
- public AuthorTC() {
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
-
this.name = name;
- }
-
- @ManyToMany(targetEntity = BookTC.class, cascade = { CascadeType.ALL
}, fetch = FetchType.EAGER)
- @JoinTable(name = "AUTHOR_BOOK", joinColumns = { @JoinColumn(name
= "author_id") }, inverseJoinColumns = { @JoinColumn(name = "book_id") })
- public List<BookTC> getBooks() {
- return books;
- }
-
- public void setBooks(List<BookTC> books) {
- this.books = books;
- }
-}
=======================================
---
/lambico-test/src/test/java/org/lambico/test/spring/hibernate/AuthorTCDao.java
Tue Dec 13 13:34:32 2011
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
- *
- * This file is part of Lambico Test.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *
http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.lambico.test.spring.hibernate;
-
-import java.util.List;
-
-import org.lambico.dao.generic.Dao;
-import org.lambico.dao.generic.GenericDao;
-
-/**
- * A DAO to be used for the tests M:N relationships.
- *
- * @author <a href="mailto:
michele...@seesaw.it">Michele Franzin</a>
- * @version $Revision$
- */
-@Dao(entity = AuthorTC.class)
-public interface AuthorTCDao extends GenericDao<AuthorTC, Long> {
- List<AuthorTC> findByName(String value);
-}
=======================================
---
/lambico-test/src/test/java/org/lambico/test/spring/hibernate/BookTC.java
Tue Dec 13 13:34:32 2011
+++ /dev/null
@@ -1,66 +0,0 @@
-/**
- * Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
- *
- * This file is part of Lambico Test.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *
http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.lambico.test.spring.hibernate;
-
-import org.lambico.po.hibernate.EntityBase;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.persistence.CascadeType;
-import javax.persistence.FetchType;
-import javax.persistence.ManyToMany;
-import javax.persistence.NamedQuery;
-
-/**
- * An persistent object to be used for the tests M:N relationships.
- *
- * @author <a href="mailto:
michele...@seesaw.it">Michele Franzin</a>
- * @version $Revision$
- */
-...@javax.persistence.Entity
-@NamedQuery(name = "BookTC.findByTitle", query = "from BookTC where title
like ?")
-public class BookTC extends EntityBase {
-
- private static final long serialVersionUID = 1L;
-
- private String title = null;
-
- private List<AuthorTC> authors = new ArrayList<AuthorTC>();
-
- public BookTC() {
- }
-
- public String getTitle() {
- return title;
- }
-
- public void setTitle(String title) {
- this.title = title;
- }
-
- @ManyToMany(targetEntity = AuthorTC.class, cascade = { CascadeType.ALL
}, mappedBy = "books", fetch = FetchType.EAGER)
- public List<AuthorTC> getAuthors() {
- return authors;
- }
-
- public void setAuthors(List<AuthorTC> authors) {
- this.authors = authors;
- }
-
-}
=======================================
---
/lambico-test/src/test/java/org/lambico/test/spring/hibernate/BookTCDao.java
Tue Dec 13 13:34:32 2011
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
- *
- * This file is part of Lambico Test.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *
http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.lambico.test.spring.hibernate;
-
-import java.util.List;
-
-import org.lambico.dao.generic.Dao;
-import org.lambico.dao.generic.GenericDao;
-
-/**
- * A DAO to be used for the tests M:N relationships.
- *
- * @author <a href="mailto:
michele...@seesaw.it">Michele Franzin</a>
- * @version $Revision$
- */
-@Dao(entity = BookTC.class)
-public interface BookTCDao extends GenericDao<BookTC, Long> {
- List<BookTC> findByTitle(String value);
-}
=======================================
---
/lambico-test/src/test/java/org/lambico/test/spring/hibernate/DemoBean.java
Tue Dec 13 13:34:32 2011
+++ /dev/null
@@ -1,71 +0,0 @@
-/**
- * Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
- *
- * This file is part of Lambico Test.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *
http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.lambico.test.spring.hibernate;
-
-public class DemoBean {
- public String nome;
-
- private Long id;
-
- public DemoBean() {
- super();
- }
-
- public DemoBean(String nome, Long id) {
- this.nome = nome;
-
this.id = id;
- }
-
- public Long getId() {
- return id;
- }
-
- public void setId(Long value) {
-
this.id = value;
- }
-
- @Override
- public String toString() {
- return "nome=" + nome + ", id=" + id;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if ((obj == null) || (obj.getClass() != this.getClass()))
- return false;
- // object must be DemoBean at this point
- DemoBean test = (DemoBean) obj;
- return (id == test.getId() || (id != null && id.equals(
test.id)))
- && (nome == test.nome || (nome != null &&
nome.equals(test.nome)));
- }
-
- @Override
- public int hashCode() {
- int hash = 0;
- if (id != null) {
- hash += id.hashCode();
- }
- if (nome != null) {
- hash += nome.hashCode();
- }
- return hash == 0 ? super.hashCode() : hash;
- }
-}
=======================================
---
/lambico-test/src/test/java/org/lambico/test/spring/hibernate/FixtureHelperTest.java
Tue Dec 13 13:34:32 2011
+++ /dev/null
@@ -1,119 +0,0 @@
-/**
- * Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
- *
- * This file is part of Lambico Test.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *
http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.lambico.test.spring.hibernate;
-
-import java.math.BigDecimal;
-import java.util.LinkedHashSet;
-import java.util.Map;
-import java.util.Set;
-import junit.framework.TestCase;
-import org.springframework.util.CollectionUtils;
-
-/**
- * @author <a href="mailto:
michele...@seesaw.it">Michele Franzin</a>
- * @author Lucio Benfante <lucio dot benfante at
gmail.com>
- * @version $Revision$
- */
-public class FixtureHelperTest extends TestCase {
-
- private DemoBean[] expected;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- expected = new DemoBean[5];
- expected[0] = new DemoBean("first one", new Long(356));
- expected[1] = new DemoBean("Demo 1", new Long(6789));
- expected[2] = new DemoBean("àèéìòù", new Long(-980000));
- expected[3] = new DemoBean("Demo3", new Long(98000));
- expected[4] = new DemoBean("Demo#2", new Long(-9800));
- }
-
- @SuppressWarnings("unchecked")
- public void testShouldNotFailWrongFixtureDir() throws Exception {
- Set<Class> models = new LinkedHashSet<Class>(
- CollectionUtils.arrayToList(new Class[]{DemoBean.class}));
- Map<Class, Object[]> result =
FixtureHelper.loadFixturesFromResource(
- "nonExistant/", models);
- assertTrue("Le fixture non sono vuote", result.isEmpty());
- }
-
- @SuppressWarnings("unchecked")
- public void testShouldNotFailIfMissingFixtureFile() throws Exception {
- Set<Class> models = new LinkedHashSet<Class>(
- CollectionUtils.arrayToList(new
Class[]{BigDecimal.class}));
- Map<Class, Object[]> result =
FixtureHelper.loadFixturesFromResource(
- "fixtures/", models);
- assertTrue("Le fixture non sono vuote", result.isEmpty());
- }
-
- public void testShouldNotFailIfEmptyDocs() throws Exception {
- Map<Class, Object[]> result =
FixtureHelper.loadFixturesFromResource(
- "emptyDir/", new LinkedHashSet<Class>());
- assertTrue("Le fixture non sono vuote", result.isEmpty());
- }
-
- @SuppressWarnings("unchecked")
- public void testBeanLoading() throws Exception {
- Set<Class> models = new LinkedHashSet<Class>(
- CollectionUtils.arrayToList(new Class[]{DemoBean.class}));
- Map<Class, Object[]> objects =
FixtureHelper.loadFixturesFromResource(
- "fixtures/", models);
- assertNotNull("Non ha ritornato la mappa di fixtures", objects);
- assertEquals("Non carica tutti i beans", 1, objects.size());
- assertTrue("Non crea istanze di " +
DemoBean.class.getCanonicalName(),
- objects.containsKey(DemoBean.class));
- DemoBean[] result = (DemoBean[]) objects.get(DemoBean.class);
- assertEquals("Non carica tutti i beans", 5, result.length);
- for (int i = 0; i < 5; i++) {
- assertEquals("Non ha caricato correttamente il beans numero "
+ i,
- expected[i], result[i]);
- }
- }
-
- public void testBookLoading() {
- Set<Class> models = new LinkedHashSet<Class>(
- CollectionUtils.arrayToList(new Class[]{AuthorTC.class,
- BookTC.class
- }));
- Map<Class, Object[]> objects =
FixtureHelper.loadFixturesFromResource(
- "fixtures/", models);
- assertNotNull("Non ha ritornato la mappa di fixtures", objects);
- assertEquals(2, objects.size());
- assertEquals(3, objects.get(BookTC.class).length);
- assertEquals(4, objects.get(AuthorTC.class).length);
- assertBookAuthorsAreIdentical(objects.get(BookTC.class),
objects.get(AuthorTC.class));
- }
-
- private void assertBookAuthorsAreIdentical(Object[] books, Object[]
authors) {
- for (int i=0; i < books.length; i++) {
- BookTC currentBook = (BookTC) books[i];
- for (AuthorTC author: currentBook.getAuthors()) {
- boolean found = false;
- for (int j=0; j < authors.length; j++) {
- if (author == authors[j]) {
- found = true;
- break;
- }
- }
- assertTrue("The book author is not in the author array",
found);
- }
- }
- }
-}
=======================================
---
/lambico-test/src/test/java/org/lambico/test/spring/hibernate/UtilsTest.java
Tue Dec 13 13:34:32 2011
+++ /dev/null
@@ -1,64 +0,0 @@
-/**
- * Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
- *
- * This file is part of Lambico Test.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *
http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.lambico.test.spring.hibernate;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import junit.framework.TestCase;
-import org.lambico.test.spring.Utils;
-
-public class UtilsTest extends TestCase {
-
- public void testConvertToNameValueList() {
- Map<String, String> input = new HashMap<String, String>();
- input.put("A", "B");
- input.put("C", "D");
- input.put("E", "F");
- List<String> expected = new ArrayList<String>();
- // changed add order in the list
- expected.add("E=F");
- expected.add("A=B");
- expected.add("C=D");
-
-
assertTrue(expected.containsAll(Utils.convertToNameValueList(input)));
- }
-
- public void testBinaryStripUTF8preamble() {
- byte[] stringWithPreamble =
Utils.loadBinary("testdata/UTF8WithPreamble.txt");
- byte[] stringWithoutPreamble =
Utils.loadBinary("testdata/UTF8WithoutPreamble.txt");
-
- assertTrue(Utils.hasUTF8preamble(stringWithPreamble));
- assertFalse(Utils.hasUTF8preamble(stringWithoutPreamble));
-
- byte[] stripped = Utils.stripUTF8preamble(stringWithPreamble);
- assertFalse(Utils.hasUTF8preamble(stripped));
- assertEquals(stringWithPreamble.length, stripped.length + 3);
- }
-
- public void testStringStripUTF8preamble() throws Exception {
- String stringWithPreamble =
Utils.loadString("testdata/UTF8WithPreamble.txt");
- String stringWithoutPreamble =
Utils.loadString("testdata/UTF8WithoutPreamble.txt");
-
- assertFalse(Utils.hasUTF8preamble(stringWithPreamble));
- assertFalse(Utils.hasUTF8preamble(stringWithoutPreamble));
- }
-}
=======================================
--- /lambico-test/src/test/resources/fixtures/AuthorTC.yml Tue Dec 13
13:34:32 2011
+++ /dev/null
@@ -1,37 +0,0 @@
-#
-# Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
-#
-# This file is part of Lambico Test.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#
http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-- &Author-joe
- name: joe
- books:
- - *Book-WarPeace
- - *Book-Bean
-- &Author-sam
- name: sam
- books:
- - *Book-Java
- - *Book-Bean
-- &Author-peter
- name: peter
- books:
- - *Book-Java
-- &Author-john
- name: john
- books:
- - *Book-Java
-
=======================================
--- /lambico-test/src/test/resources/fixtures/BookTC.yml Tue Dec 13
13:34:32 2011
+++ /dev/null
@@ -1,24 +0,0 @@
-#
-# Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
-#
-# This file is part of Lambico Test.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#
http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-- &Book-WarPeace
- title: War and Peace
-- &Book-Bean
- title: Mr. Bean
-- &Book-Java
- title: Java manual
=======================================
--- /lambico-test/src/test/resources/fixtures/DemoBean.yml Tue Dec 13
13:34:32 2011
+++ /dev/null
@@ -1,39 +0,0 @@
-#
-# Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
-#
-# This file is part of Lambico Test.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#
http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
--
- nome: "first one"
- id: 356
-
-# Ending with spaces
-- &demo1
- nome: "Demo 1"
- id: 6789
-
-# Without anchor
--
- nome: "àèéìòù"
- id: -980000
-
-- &demo3
- nome: "Demo3"
- id: 98000
-
-- &demo2
- nome: "Demo#2"
- id: -9800
=======================================
--- /lambico-test/src/test/resources/fixtures/EntityTC.yml Tue Dec 13
13:34:32 2011
+++ /dev/null
@@ -1,43 +0,0 @@
-#
-# Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
-#
-# This file is part of Lambico Test.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#
http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
--
- fieldOne: "one1"
- fieldTwo: "two5"
- fieldThree: "Three1"
- numericField: 1
--
- fieldOne: "one2"
- fieldTwo: "two4"
- fieldThree: "Three2"
- numericField: 2
--
- fieldOne: "one3"
- fieldTwo: "two3"
- fieldThree: "Three3"
- numericField: 3
--
- fieldOne: "one4"
- fieldTwo: "two2"
- fieldThree: "Three4"
- numericField: 4
--
- fieldOne: "one3"
- fieldTwo: "two1"
- fieldThree: "7hree5"
- numericField: 5
=======================================
--- /lambico-test/src/test/resources/fixtures/String.yml Tue Dec 13
13:34:32 2011
+++ /dev/null
@@ -1,22 +0,0 @@
-#
-# Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
-#
-# This file is part of Lambico Test.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#
http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
--
- Questo è un file UTF8 con preambolo
--
- òàùèì
=======================================
--- /lambico-test/src/test/resources/testdata/UTF8WithPreamble.txt Thu Jan
7 09:56:19 2010
+++ /dev/null
@@ -1,2 +0,0 @@
-Questo è un file UTF8 con preambolo
-òàùèì
=======================================
--- /lambico-test/src/test/resources/testdata/UTF8WithoutPreamble.txt Thu
Jan 7 09:56:19 2010
+++ /dev/null
@@ -1,2 +0,0 @@
-Questo è un file UTF8 senza preambolo
-òàùèì
=======================================
--- /lambico-core/pom.xml Wed Feb 27 11:00:27 2013
+++ /lambico-core/pom.xml Wed Feb 13 07:29:03 2013
@@ -36,6 +36,5 @@
<scope>test</scope>
</dependency>
</dependencies>
-
</project>
=======================================
---
/lambico-spring-hibernate/src/test/java/org/lambico/spring/dao/hibernate/BaseTest.java
Fri Mar 4 08:54:33 2011
+++
/lambico-spring-hibernate/src/test/java/org/lambico/spring/dao/hibernate/BaseTest.java
Wed Feb 13 07:29:03 2013
@@ -15,7 +15,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.lambico.spring.dao.hibernate;
import org.lambico.spring.dao.hibernate.po.AuthorTC;
@@ -28,15 +27,24 @@
import org.lambico.test.spring.hibernate.DBTest;
/**
- * A base class for Lambico tests.
+ * A base class for lambico tests.
*
* @author lucio
+ * @author michele franzin <michele at
franzin.net>
*/
public abstract class BaseTest extends DBTest {
@Override
public Class[] getFixtureClasses() {
- return new Class[]{EntityTC.class, EntityTCBis.class,
EntityTCTer.class, EntityTCWithoutDaoInterface.class,
- EntityTCNoInheritance.class, AuthorTC.class,
BookTC.class};
+ return new Class[]{EntityTC.class, EntityTCBis.class,
EntityTCTer.class,
+ EntityTCWithoutDaoInterface.class, EntityTCNoInheritance.class,
+ BookTC.class, AuthorTC.class};
+ }
+
+ @Override
+ public void onSetUpBeforeTransaction() throws Exception {
+ this.getJdbcTemplate().execute("SET DATABASE REFERENTIAL INTEGRITY
FALSE");
+ super.onSetUpBeforeTransaction();
+ this.getJdbcTemplate().execute("SET DATABASE REFERENTIAL INTEGRITY
TRUE");
}
}
=======================================
---
/lambico-spring-hibernate/src/test/java/org/lambico/spring/dao/hibernate/CachedEntityTCTest.java
Mon Jan 3 08:54:22 2011
+++
/lambico-spring-hibernate/src/test/java/org/lambico/spring/dao/hibernate/CachedEntityTCTest.java
Wed Feb 13 07:29:03 2013
@@ -23,6 +23,7 @@
import org.lambico.dao.spring.hibernate.HibernateGenericDao;
import org.lambico.spring.dao.hibernate.dao.CachedEntityTCDao;
import org.lambico.spring.dao.hibernate.po.CachedEntityTC;
+import org.lambico.test.spring.hibernate.DBTest;
/**
* Tests on caching DAO methods.
@@ -30,18 +31,13 @@
* @author <a href="mailto:
lu...@benfante.com">Lucio Benfante</a>
* @version $Revision$
*/
-public class CachedEntityTCTest extends BaseTest {
+public class CachedEntityTCTest extends DBTest {
private static Logger logger =
Logger.getLogger(CachedEntityTCTest.class);
public static final int COUNT = 1000;
public static final String FIELD = "%67%";
@Resource
private CachedEntityTCDao cachedEntityTCDao;
-
- @Override
- public Class[] getFixtureClasses() {
- return new Class[]{};
- }
@Override
protected void prepareTestInstance() throws Exception {
=======================================
--- /lambico-spring-hibernate/src/test/resources/fixtures/DemoBean.yml Sat
Feb 6 03:14:05 2010
+++ /lambico-spring-hibernate/src/test/resources/fixtures/DemoBean.yml Wed
Feb 13 07:29:03 2013
@@ -27,13 +27,13 @@
# Without anchor
-
- nome: "àèéìòù"
- id: -980000
+ nome: "àèéìòù"
+ id: -980000
- &demo3
- nome: "Demo3"
- id: 98000
+ nome: "Demo3"
+ id: 98000
- &demo2
- nome: "Demo#2"
- id: -9800
+ nome: "Demo#2"
+ id: -9800
=======================================
--- /lambico-test/pom.xml Wed Feb 27 11:00:27 2013
+++ /lambico-test/pom.xml Wed Feb 13 07:29:03 2013
@@ -34,6 +34,11 @@
<artifactId>log4j</artifactId>
</dependency>
<dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-core</artifactId>
+ <version>1.3</version>
+ </dependency>
+ <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<optional>true</optional>
@@ -48,12 +53,8 @@
<artifactId>commons-lang</artifactId>
</dependency>
<dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- </dependency>
- <dependency>
- <groupId>org.parancoe</groupId>
- <artifactId>parancoe-yaml</artifactId>
+ <groupId>org.lambico</groupId>
+ <artifactId>lambico-pump</artifactId>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
=======================================
---
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/DBTest.java
Tue Dec 13 13:34:32 2011
+++
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/DBTest.java
Wed Feb 13 07:29:03 2013
@@ -19,18 +19,20 @@
import java.util.HashMap;
import java.util.LinkedHashSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.ArrayUtils;
-import org.apache.log4j.Logger;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.lambico.dao.generic.GenericDaoBase;
+import org.lambico.data.FixtureHelper;
import org.lambico.test.spring.EnhancedTestCase;
import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.ResourceLoader;
import org.springframework.orm.hibernate3.SessionHolder;
import
org.springframework.transaction.support.TransactionSynchronizationManager;
@@ -41,14 +43,9 @@
*/
public abstract class DBTest extends EnhancedTestCase {
- /** The logger for this class. */
- private static Logger logger = Logger.getLogger(DBTest.class);
- /** The fixtures. */
- protected Map<Class, Object[]> fixtures;
- /** The session factory. */
+ protected Map<Class, List> fixtures;
@Resource
protected SessionFactory sessionFactory;
- /** The map of DAOs. */
@Resource(name = "daoMap")
protected HashMap daoMap;
@@ -93,25 +90,22 @@
*/
@Override
public void onSetUpBeforeTransaction() throws Exception {
-
Session session = sessionFactory.openSession();
session.beginTransaction();
//Attach transaction to thread
- TransactionSynchronizationManager.bindResource(sessionFactory,
- new SessionHolder(session));
+ TransactionSynchronizationManager.bindResource(sessionFactory, new
SessionHolder(session));
TransactionSynchronizationManager.initSynchronization();
try {
// erase everything
for (Class model : getReverseOrderFixtureClasses()) {
GenericDaoBase dao = DaoUtils.getDaoFor(model,
applicationContext);
- FixtureHelper.eraseDbForModel(model, dao);
+ FixtureUtils.eraseDbForModel(model, dao);
}
// repopulate
for (Class model : getFixtureClasses()) {
- GenericDaoBase dao = DaoUtils.getDaoFor(model,
- applicationContext);
- FixtureHelper.populateDbForModel(model,
fixtures.get(model), dao);
+ GenericDaoBase dao = DaoUtils.getDaoFor(model,
applicationContext);
+ FixtureUtils.populateDbForModel(model,
fixtures.get(model), dao);
}
session.getTransaction().commit();
} catch (Exception e) {
@@ -120,9 +114,7 @@
session.getTransaction().rollback();
} finally {
try {
- if (session != null) {
- session.close();
- }
+ session.close();
} catch (Exception e) { /*do nothing*/
logger.info("Can't close the session! (ignore it)");
}
@@ -135,18 +127,17 @@
@Override
protected String[] getConfigLocations() {
return new String[]{
- "classpath:org/lambico/spring/dao/hibernate/genericDao.xml",
- "classpath:org/lambico/spring/dao/hibernate/applicationContextBase.xml",
- "classpath:applicationContext_test.xml"
- };
+ "classpath:org/lambico/spring/dao/hibernate/genericDao.xml",
+ "classpath:org/lambico/spring/dao/hibernate/applicationContextBase.xml",
+ "classpath:applicationContext_test.xml"
+ };
}
@Override
+ @SuppressWarnings("unchecked")
protected void prepareTestInstance() throws Exception {
super.prepareTestInstance();
-
- Map ldaos = DaoUtils.getDaos(applicationContext);
- daoMap.putAll(ldaos);
+ daoMap.putAll(DaoUtils.getDaos(applicationContext));
if (fixtures == null) {
// carico le fixture se non sono già presenti
@@ -155,7 +146,7 @@
try {
fixtures = FixtureHelper.loadFixturesFromResource(
(ClassPathResource)
applicationContext.getResource(
- "classpath:/fixtures/"), fixtureClasses);
+ ResourceLoader.CLASSPATH_URL_PREFIX
+ "/fixtures/"), fixtureClasses);
logger.info("Loaded fixtures for classes "
+ fixtures.keySet().toString());
} catch (Exception e) {
@@ -169,8 +160,8 @@
}
/**
- * At the end of the test the method endTransaction call a rollback
for the transaction
- * although a explicit rollback call is did. This raise a false
exception.
+ * At the end of the test the method endTransaction call a rollback
for the transaction although
+ * a explicit rollback call is did. This raise a false exception.
*/
@Override
protected void endTransaction() {
==============================================================================
Revision: f97596efe5cb
Branch: default
Author: Michele Franzin <
michele...@gmail.com>
Date: Thu Feb 28 09:37:27 2013
Log: use slf4j everywhere (log4j dependency dropped)
http://code.google.com/p/lambico/source/detail?r=f97596efe5cb
Modified:
/lambico-core/pom.xml
/lambico-core/src/main/java/org/lambico/dao/LoggingExceptionManager.java
/lambico-pump/pom.xml
/lambico-pump/src/main/java/org/lambico/data/FixtureHelper.java
/lambico-spring-hibernate/pom.xml
/lambico-spring-hibernate/src/main/java/org/lambico/spring/dao/hibernate/HibernateDaoBeanCreator.java
/lambico-spring-hibernate/src/main/java/org/lambico/spring/dao/hibernate/HibernateDaoInstrumentation.java
/lambico-spring-hibernate/src/main/java/org/lambico/spring/dao/hibernate/SessionFactoryPopulator.java
/lambico-spring-hibernate/src/test/java/org/lambico/spring/dao/hibernate/CachedEntityTCTest.java
/lambico-spring/pom.xml
/lambico-spring/src/main/java/org/lambico/spring/dao/DaoProviderInstrumentation.java
/lambico-spring/src/main/java/org/lambico/spring/dao/DaoUtils.java
/lambico-spring/src/main/java/org/lambico/spring/xml/ContextUtils.java
/lambico-spring/src/main/java/org/lambico/spring/xml/DefineDaosBeanDefinitionParser.java
/lambico-spring/src/main/java/org/lambico/spring/xml/DiscoverPersistentClassesBeanDefinitionParser.java
/lambico-test/pom.xml
/lambico-test/src/main/java/org/lambico/test/spring/MailSenderMock.java
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/DaoUtils.java
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/FixtureUtils.java
/pom.xml
=======================================
--- /lambico-core/pom.xml Wed Feb 13 07:29:03 2013
+++ /lambico-core/pom.xml Thu Feb 28 09:37:27 2013
@@ -17,10 +17,6 @@
</properties>
<dependencies>
<dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- </dependency>
- <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<optional>true</optional>
@@ -31,6 +27,10 @@
<optional>true</optional>
</dependency>
<dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
=======================================
---
/lambico-core/src/main/java/org/lambico/dao/LoggingExceptionManager.java
Thu Feb 4 05:52:51 2010
+++
/lambico-core/src/main/java/org/lambico/dao/LoggingExceptionManager.java
Thu Feb 28 09:37:27 2013
@@ -19,7 +19,8 @@
package org.lambico.dao;
import java.util.Properties;
-import org.apache.log4j.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* An exception manager that simply log its exception.
@@ -30,7 +31,7 @@
public class LoggingExceptionManager extends DaoExceptionManagerBase {
/** The logger for this class. */
- private final Logger logger =
Logger.getLogger(LoggingExceptionManager.class);
+ private final Logger logger =
LoggerFactory.getLogger(LoggingExceptionManager.class);
/**
* {@inheritDoc}
=======================================
--- /lambico-pump/pom.xml Wed Feb 27 10:59:57 2013
+++ /lambico-pump/pom.xml Thu Feb 28 09:37:27 2013
@@ -71,6 +71,12 @@
<artifactId>hibernate-core</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>${lambico.slf4j.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
=======================================
--- /lambico-pump/src/main/java/org/lambico/data/FixtureHelper.java Wed Feb
27 10:59:57 2013
+++ /lambico-pump/src/main/java/org/lambico/data/FixtureHelper.java Thu Feb
28 09:37:27 2013
@@ -20,7 +20,6 @@
import java.io.File;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
-import org.apache.log4j.Logger;
import org.springframework.core.io.ClassPathResource;
import java.io.FileNotFoundException;
@@ -34,6 +33,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.lambico.data.EngineFactory.EngineType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Fixture load / dump facility
@@ -42,7 +43,7 @@
*/
public class FixtureHelper {
- private static Logger logger = Logger.getLogger(FixtureHelper.class);
+ private static Logger logger =
LoggerFactory.getLogger(FixtureHelper.class);
private static final Pattern HEADER_MATCH =
Pattern.compile("^-\\s??(\\S*)\\s*?$",
Pattern.MULTILINE);
private static final Pattern LINE_MATCH = Pattern.compile("^(.+)$",
Pattern.MULTILINE);
=======================================
--- /lambico-spring-hibernate/pom.xml Wed Feb 27 11:00:27 2013
+++ /lambico-spring-hibernate/pom.xml Thu Feb 28 09:37:27 2013
@@ -28,6 +28,12 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>${lambico.slf4j.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<scope>test</scope>
@@ -36,6 +42,16 @@
<dependency>
<groupId>org.lambico</groupId>
<artifactId>lambico-spring</artifactId>
+ <exclusions>
+ <exclusion>
+ <artifactId>commons-logging</artifactId>
+ <groupId>commons-logging</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>jcl-over-slf4j</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
@@ -46,11 +62,6 @@
<artifactId>javassist</artifactId>
<scope>runtime</scope>
</dependency>
- <dependency>
- <artifactId>slf4j-api</artifactId>
- <groupId>org.slf4j</groupId>
- <scope>runtime</scope>
- </dependency>
</dependencies>
<build>
<plugins>
=======================================
---
/lambico-spring-hibernate/src/main/java/org/lambico/spring/dao/hibernate/HibernateDaoBeanCreator.java
Sun Mar 6 23:35:44 2011
+++
/lambico-spring-hibernate/src/main/java/org/lambico/spring/dao/hibernate/HibernateDaoBeanCreator.java
Thu Feb 28 09:37:27 2013
@@ -25,13 +25,15 @@
import java.util.List;
import java.util.Set;
import javax.persistence.Entity;
-import org.apache.log4j.Logger;
import org.lambico.dao.AutomaticDao;
import org.lambico.dao.generic.Dao;
import org.lambico.spring.xml.ContextUtils;
import org.lambico.spring.xml.DaoBeanCreator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.aop.framework.ProxyFactoryBean;
import org.springframework.beans.PropertyValue;
+import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.TypedStringValue;
import org.springframework.beans.factory.parsing.ReaderContext;
@@ -55,8 +57,7 @@
*/
public class HibernateDaoBeanCreator implements DaoBeanCreator {
- /** The logger for this class. */
- private static Logger logger =
Logger.getLogger(HibernateDaoBeanCreator.class);
+ private static Logger logger =
LoggerFactory.getLogger(HibernateDaoBeanCreator.class);
/** The ResourcePatternResolver. */
private ResourcePatternResolver rl;
/** The BeanDefinitionRegistry. */
=======================================
---
/lambico-spring-hibernate/src/main/java/org/lambico/spring/dao/hibernate/HibernateDaoInstrumentation.java
Sun Mar 6 23:35:44 2011
+++
/lambico-spring-hibernate/src/main/java/org/lambico/spring/dao/hibernate/HibernateDaoInstrumentation.java
Thu Feb 28 09:37:27 2013
@@ -21,7 +21,6 @@
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.List;
-import org.apache.log4j.Logger;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
@@ -45,6 +44,8 @@
import org.lambico.dao.generic.MaxResults;
import org.lambico.dao.generic.NamedParameter;
import org.lambico.dao.spring.hibernate.GenericDaoHibernateSupport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.util.StringUtils;
@@ -58,14 +59,13 @@
@Aspect
public class HibernateDaoInstrumentation {
+ private static Logger logger =
LoggerFactory.getLogger(HibernateDaoInstrumentation.class);
/** Length of the "findBy"prefix. */
private static final int FIND_BY_PREFIX_SIZE = "findBy".length();
/** Length of the "orderBy" prefix. */
private static final int ORDER_BY_PREFIX_SIZE = "orderBy".length();
/** Length of the "orderBy" prefix. */
private static final int COUNT_BY_PREFIX_SIZE = "countBy".length();
- /** The logger for this class. */
- private static Logger logger =
Logger.getLogger(HibernateDaoInstrumentation.class);
/** The exception manager. */
private DaoExceptionManager daoExceptionManager = new
BypassingExceptionManager();
=======================================
---
/lambico-spring-hibernate/src/main/java/org/lambico/spring/dao/hibernate/SessionFactoryPopulator.java
Sun Feb 7 00:12:09 2010
+++
/lambico-spring-hibernate/src/main/java/org/lambico/spring/dao/hibernate/SessionFactoryPopulator.java
Thu Feb 28 09:37:27 2013
@@ -20,9 +20,10 @@
import java.util.List;
import javax.persistence.Entity;
-import org.apache.log4j.Logger;
import org.lambico.spring.xml.ContextUtils;
import org.lambico.spring.xml.EntityDiscoverer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.PropertyValue;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.TypedStringValue;
@@ -48,8 +49,7 @@
*/
public class SessionFactoryPopulator implements EntityDiscoverer {
- /** The logger for this class. */
- private static Logger logger =
Logger.getLogger(SessionFactoryPopulator.class);
+ private static Logger logger =
LoggerFactory.getLogger(SessionFactoryPopulator.class);
/** The ResourcePatternResolver. */
private ResourcePatternResolver rl;
/** The BeanDefinition registry. */
=======================================
---
/lambico-spring-hibernate/src/test/java/org/lambico/spring/dao/hibernate/CachedEntityTCTest.java
Wed Feb 13 07:29:03 2013
+++
/lambico-spring-hibernate/src/test/java/org/lambico/spring/dao/hibernate/CachedEntityTCTest.java
Thu Feb 28 09:37:27 2013
@@ -18,7 +18,6 @@
package org.lambico.spring.dao.hibernate;
import javax.annotation.Resource;
-import org.apache.log4j.Logger;
import org.hibernate.stat.Statistics;
import org.lambico.dao.spring.hibernate.HibernateGenericDao;
import org.lambico.spring.dao.hibernate.dao.CachedEntityTCDao;
@@ -33,7 +32,6 @@
*/
public class CachedEntityTCTest extends DBTest {
- private static Logger logger =
Logger.getLogger(CachedEntityTCTest.class);
public static final int COUNT = 1000;
public static final String FIELD = "%67%";
@Resource
=======================================
--- /lambico-spring/pom.xml Wed Feb 27 11:00:27 2013
+++ /lambico-spring/pom.xml Thu Feb 28 09:37:27 2013
@@ -32,6 +32,12 @@
<artifactId>commons-dbcp</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>${lambico.slf4j.version}</version>
+ <scope>test</scope>
+ </dependency>
<!-- END test libraries -->
<dependency>
<groupId>org.lambico</groupId>
@@ -42,20 +48,6 @@
<artifactId>aspectjweaver</artifactId>
</dependency>
<dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <scope>runtime</scope>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-simple</artifactId>
- <scope>runtime</scope>
- </dependency>
- <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</dependency>
=======================================
---
/lambico-spring/src/main/java/org/lambico/spring/dao/DaoProviderInstrumentation.java
Thu Jan 7 09:56:19 2010
+++
/lambico-spring/src/main/java/org/lambico/spring/dao/DaoProviderInstrumentation.java
Thu Feb 28 09:37:27 2013
@@ -18,12 +18,13 @@
package org.lambico.spring.dao;
import java.lang.reflect.Method;
-import org.apache.log4j.Logger;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.lambico.dao.DaoProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;
/**
@@ -35,10 +36,9 @@
@Aspect()
public class DaoProviderInstrumentation {
+ private static Logger logger =
LoggerFactory.getLogger(DaoProviderInstrumentation.class);
/** Prefix of the get<DAO> method. */
private static final String METHOD_PREFIX = "get";
- /** The logger for this class. */
- private static Logger logger =
Logger.getLogger(DaoProviderInstrumentation.class);
/**
* Executes a get<DAO> method in the instrumented class.
@@ -53,9 +53,11 @@
final DaoProvider target = (DaoProvider) pjp.getTarget();
final Method method = ((MethodSignature)
pjp.getSignature()).getMethod();
final Object[] args = pjp.getArgs();
- logger.debug("target: " + target);
- logger.debug("method: " + method);
- logger.debug("args: " + args);
+ if (logger.isDebugEnabled()) {
+ logger.debug("target: {}", target);
+ logger.debug("method: {}", method);
+ logger.debug("args: {}", args);
+ }
if (method.getName().startsWith(METHOD_PREFIX)) {
result = target.getDaoMap().get(daoNameFromMethod(method));
=======================================
--- /lambico-spring/src/main/java/org/lambico/spring/dao/DaoUtils.java Thu
Jan 7 09:56:19 2010
+++ /lambico-spring/src/main/java/org/lambico/spring/dao/DaoUtils.java Thu
Feb 28 09:37:27 2013
@@ -23,11 +23,12 @@
import org.springframework.core.annotation.AnnotationUtils;
import java.util.HashMap;
import java.util.Map;
-import org.apache.log4j.Logger;
import org.lambico.dao.spring.BusinessDao;
import org.lambico.dao.generic.Dao;
import org.lambico.dao.generic.GenericDaoBase;
import org.lambico.dao.generic.GenericDaoTypeSupport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Utils for the DAO tools.
@@ -37,8 +38,7 @@
*/
public final class DaoUtils {
- /** The logger for this class. **/
- private static Logger logger = Logger.getLogger(DaoUtils.class);
+ private static Logger logger = LoggerFactory.getLogger(DaoUtils.class);
/**
* Creates a new instance of DaoUtils.
=======================================
--- /lambico-spring/src/main/java/org/lambico/spring/xml/ContextUtils.java
Sat Feb 6 03:14:05 2010
+++ /lambico-spring/src/main/java/org/lambico/spring/xml/ContextUtils.java
Thu Feb 28 09:37:27 2013
@@ -23,7 +23,8 @@
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
-import org.apache.log4j.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.aop.support.annotation.AnnotationClassFilter;
import org.springframework.beans.factory.parsing.ReaderContext;
import org.springframework.core.io.Resource;
@@ -38,14 +39,13 @@
*/
public final class ContextUtils {
+ private static Logger logger =
LoggerFactory.getLogger(ContextUtils.class);
+
/**
* The constructor.
*/
private ContextUtils() {
}
-
- /** The logger for this class. */
- private static Logger logger = Logger.getLogger(ContextUtils.class);
/**
* Return all classes in the package subtree.
=======================================
---
/lambico-spring/src/main/java/org/lambico/spring/xml/DefineDaosBeanDefinitionParser.java
Sat Feb 6 03:14:05 2010
+++
/lambico-spring/src/main/java/org/lambico/spring/xml/DefineDaosBeanDefinitionParser.java
Thu Feb 28 09:37:27 2013
@@ -17,7 +17,8 @@
*/
package org.lambico.spring.xml;
-import org.apache.log4j.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
@@ -38,6 +39,7 @@
*/
public class DefineDaosBeanDefinitionParser implements
BeanDefinitionParser {
+ private static Logger logger =
LoggerFactory.getLogger(DefineDaosBeanDefinitionParser.class);
/** The baseEntityPackage attribute. */
public static final String BASE_ENTITY_PACKAGE_ATTRIBUTE
= "baseEntityPackage";
/** The baseInterfacePackage attribute. */
@@ -46,8 +48,6 @@
public static final String GENERIC_DAO_ATTRIBUTE = "genericDao";
/** The sessionFactoryName attribute. */
public static final String SESSION_FACTORY_NAME_ATTRIBUTE
= "sessionFactoryName";
- /** The logger for this class. */
- private static Logger logger =
Logger.getLogger(DefineDaosBeanDefinitionParser.class);
/**
* {@inheritDoc}
=======================================
---
/lambico-spring/src/main/java/org/lambico/spring/xml/DiscoverPersistentClassesBeanDefinitionParser.java
Sat Feb 6 03:14:05 2010
+++
/lambico-spring/src/main/java/org/lambico/spring/xml/DiscoverPersistentClassesBeanDefinitionParser.java
Thu Feb 28 09:37:27 2013
@@ -17,7 +17,8 @@
*/
package org.lambico.spring.xml;
-import org.apache.log4j.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
@@ -35,12 +36,11 @@
*/
public class DiscoverPersistentClassesBeanDefinitionParser implements
BeanDefinitionParser {
+ private static Logger logger =
LoggerFactory.getLogger(DefineDaosBeanDefinitionParser.class);
/** The basePackage attribute. */
public static final String BASE_PACKAGE_ATTRIBUTE = "basePackage";
/** The sessionFactoryName attribute. */
public static final String SESSION_FACTORY_NAME_ATTRIBUTE
= "sessionFactoryName";
- /** The logger for this class. */
- private static Logger logger =
Logger.getLogger(DefineDaosBeanDefinitionParser.class);
/**
* {@inheritDoc}
=======================================
--- /lambico-test/pom.xml Wed Feb 13 07:29:03 2013
+++ /lambico-test/pom.xml Thu Feb 28 09:37:27 2013
@@ -30,15 +30,6 @@
<artifactId>junit</artifactId>
</dependency>
<dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- </dependency>
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>hamcrest-core</artifactId>
- <version>1.3</version>
- </dependency>
- <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<optional>true</optional>
@@ -62,11 +53,6 @@
<optional>true</optional>
</dependency>
<dependency>
- <artifactId>slf4j-api</artifactId>
- <groupId>org.slf4j</groupId>
- <scope>runtime</scope>
- </dependency>
- <dependency>
<artifactId>hibernate-core</artifactId>
<groupId>org.hibernate</groupId>
</dependency>
=======================================
--- /lambico-test/src/main/java/org/lambico/test/spring/MailSenderMock.java
Tue Dec 13 13:34:32 2011
+++ /lambico-test/src/main/java/org/lambico/test/spring/MailSenderMock.java
Thu Feb 28 09:37:27 2013
@@ -18,21 +18,19 @@
package org.lambico.test.spring;
import javax.mail.internet.MimeMessage;
-import org.apache.log4j.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.mail.javamail.JavaMailSenderImpl;
/**
- * Mock implementation of JavaMailSender for test porpouse.
+ * Mock implementation of JavaMailSender for testing porpouse.
*
* @author Enrico Giurin
* @author Lucio Benfante
- * @version $Revision$
*/
public class MailSenderMock extends JavaMailSenderImpl {
- /** The logger for this class. */
- private static Logger logger = Logger.getLogger(
- MailSenderMock.class);
+ private static Logger logger =
LoggerFactory.getLogger(MailSenderMock.class);
/**
* {@inheritDoc}
@@ -45,7 +43,7 @@
if (mimeMessages != null) {
for (MimeMessage mimeMessage : mimeMessages) {
try {
-
logger.info(mimeMessage.getContent());
+
logger.info(mimeMessage.getContent().toString());
} catch (Exception ex) {
logger.error("Can't get message content", ex);
}
@@ -53,7 +51,7 @@
}
if (originalMessages != null) {
for (Object o : originalMessages) {
-
logger.info(o);
+
logger.info(o.toString());
}
}
}
=======================================
---
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/DaoUtils.java
Tue Dec 13 13:34:32 2011
+++
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/DaoUtils.java
Thu Feb 28 09:37:27 2013
@@ -22,12 +22,13 @@
import org.springframework.core.annotation.AnnotationUtils;
import java.util.HashMap;
import java.util.Map;
-import org.apache.log4j.Logger;
import org.lambico.dao.spring.BusinessDao;
import org.lambico.dao.generic.Dao;
import org.lambico.dao.generic.GenericDao;
import org.lambico.dao.generic.GenericDaoBase;
import org.lambico.dao.generic.GenericDaoTypeSupport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Utils for the DAO tools.
@@ -37,8 +38,7 @@
*/
public final class DaoUtils {
- /** The logger for this class. **/
- private static Logger logger = Logger.getLogger(DaoUtils.class);
+ private static Logger logger = LoggerFactory.getLogger(DaoUtils.class);
/**
* Creates a new instance of DaoUtils.
=======================================
---
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/FixtureUtils.java
Wed Feb 13 07:29:03 2013
+++
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/FixtureUtils.java
Thu Feb 28 09:37:27 2013
@@ -18,22 +18,23 @@
package org.lambico.test.spring.hibernate;
import java.util.List;
-import org.apache.log4j.Logger;
import org.hibernate.cfg.DefaultComponentSafeNamingStrategy;
import org.lambico.dao.generic.GenericDaoBase;
import org.lambico.dao.spring.hibernate.GenericDaoHibernateSupport;
import static org.lambico.data.FixtureHelper.getFixtureFileName;
import static org.lambico.data.FixtureHelper.getModelName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.orm.hibernate3.HibernateTemplate;
/**
* Fixture utility class.
*
- * @author michele franzin <michele @
franzin.net
+ * @author michele franzin <michele at
franzin.net>
*/
public class FixtureUtils {
- private static Logger logger = Logger.getLogger(FixtureUtils.class);
+ private static Logger logger =
LoggerFactory.getLogger(FixtureUtils.class);
/**
* Populate the DB with the fixtures data.
@@ -44,12 +45,10 @@
*/
public static void populateDbForModel(final Class model, final List
fixtures,
final GenericDaoBase dao) {
- if (logger.isDebugEnabled()) {
- logger.debug("Populating table for " + getModelName(model));
- }
+ logger.debug("Populating table for {}", getModelName(model));
if (fixtures == null) {
- logger.warn("No fixtures for " + getModelName(model) + ", did
you created the file '"
- + getFixtureFileName(model) + "'?");
+ logger.warn("No fixtures for {}, did you created the
file '{}' ?", getModelName(model),
+ getFixtureFileName(model));
return;
}
final HibernateTemplate template = ((GenericDaoHibernateSupport)
dao).getHibernateTemplate();
@@ -60,7 +59,7 @@
template.flush();
template.clear();
} catch (Exception e) {
- logger.error("Error populating rows in " + getModelName(model)
+ " table", e);
+ logger.error("Error populating rows in {} table",
getModelName(model), e);
}
}
@@ -71,19 +70,18 @@
* @param dao The DAO tp use.
*/
public static void eraseDbForModel(final Class model, final
GenericDaoBase dao) {
- if (logger.isDebugEnabled()) {
- logger.debug("Erasing table for " + getModelName(model));
- }
+ logger.debug("Erasing table for {}", getModelName(model));
try {
if (dao == null) {
throw new IllegalArgumentException("Dao associated to " +
model.getName()
+ " PO is null!");
}
- /* int deleted = */ ((GenericDaoHibernateSupport)
dao).getHibernateTemplate().bulkUpdate("DELETE FROM "
+ final HibernateTemplate template =
((GenericDaoHibernateSupport) dao).getHibernateTemplate();
+ template.bulkUpdate("DELETE FROM "
+
DefaultComponentSafeNamingStrategy.INSTANCE.tableName(model.getSimpleName()));
} catch (Exception e) {
- logger.error("Error deleting rows in " + getModelName(model)
+ " table", e);
+ logger.error("Error deleting rows in {} table",
getModelName(model), e);
}
}
}
=======================================
--- /pom.xml Wed Feb 27 10:59:57 2013
+++ /pom.xml Thu Feb 28 09:37:27 2013
@@ -22,7 +22,7 @@
<year>2009</year>
<lambico.spring.version>3.0.7.RELEASE</lambico.spring.version>
<lambico.hibernate.version>3.6.7.Final</lambico.hibernate.version>
- <lambico.log4j.version>1.2.14</lambico.log4j.version>
+ <lambico.slf4j.version>1.7.2</lambico.slf4j.version>
<lambico.junit4.version>4.11</lambico.junit4.version>
<!-- NetBeans IDE properties -->
@@ -71,9 +71,14 @@
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- <version>${lambico.log4j.version}</version>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>${lambico.slf4j.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>jcl-over-slf4j</artifactId>
+ <version>${lambico.slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
@@ -146,16 +151,6 @@
<version>2.4</version>
</dependency>
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>1.7.2</version>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-simple</artifactId>
- <version>1.7.2</version>
- </dependency>
- <dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2.2</version>
==============================================================================
Revision: c007457350c7
Branch: default
Author: Michele Franzin <
michele...@gmail.com>
Date: Wed Feb 27 08:43:19 2013
Log: cleanup compilation warning & hints
http://code.google.com/p/lambico/source/detail?r=c007457350c7
Modified:
/lambico-core/src/main/java/org/lambico/dao/generic/PageDefaultImpl.java
/lambico-pump/src/main/java/org/lambico/data/FixtureHelper.java
/lambico-pump/src/test/java/org/lambico/data/FixtureHelperTest.java
/lambico-spring-hibernate/src/main/java/org/lambico/spring/dao/hibernate/HibernateDaoBeanCreator.java
/lambico-spring-hibernate/src/main/java/org/lambico/spring/dao/hibernate/HibernateDaoInstrumentation.java
/lambico-spring-hibernate/src/main/java/org/lambico/spring/dao/hibernate/HibernateGenericBusinessDao.java
/lambico-spring-hibernate/src/main/java/org/lambico/spring/dao/hibernate/HibernateGenericDaoImpl.java
/lambico-spring-hibernate/src/main/java/org/lambico/spring/dao/hibernate/SessionFactoryPopulator.java
/lambico-spring-hibernate/src/test/java/org/lambico/spring/dao/hibernate/DaoProviderTest.java
/lambico-spring-hibernate/src/test/java/org/lambico/spring/dao/hibernate/EntityTCTest.java
/lambico-spring/src/main/java/org/lambico/spring/xml/DaoBeanDefinitionParser.java
/lambico-spring/src/main/resources/org/lambico/spring/xml/lambico.xsd
/lambico-test/pom.xml
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/DaoUtils.java
=======================================
---
/lambico-core/src/main/java/org/lambico/dao/generic/PageDefaultImpl.java
Thu Jan 7 09:56:19 2010
+++
/lambico-core/src/main/java/org/lambico/dao/generic/PageDefaultImpl.java
Wed Feb 27 08:43:19 2013
@@ -32,7 +32,7 @@
/**
* The content of the page.
*/
- private List results;
+ private List<T> results;
/**
* The size of the page, i.e. the max number of rows in a single page.
*/
@@ -48,6 +48,7 @@
/**
* An empty page.
*/
+ @SuppressWarnings("unchecked")
public static final PageDefaultImpl EMPTY =
new PageDefaultImpl(Collections.EMPTY_LIST, 1, 1, 0);
@@ -72,6 +73,7 @@
*
* @return {@inheritDoc}
*/
+ @Override
public int getPage() {
return page;
}
@@ -81,6 +83,7 @@
*
* @return {@inheritDoc}
*/
+ @Override
public boolean isNextPage() {
return page < getLastPage();
}
@@ -90,6 +93,7 @@
*
* @return {@inheritDoc}
*/
+ @Override
public boolean isPreviousPage() {
return page > 1;
}
@@ -99,6 +103,7 @@
*
* @return {@inheritDoc}
*/
+ @Override
public List<T> getList() {
return results;
}
@@ -108,6 +113,7 @@
*
* @return {@inheritDoc}
*/
+ @Override
public int getLastPage() {
int lastPage = rowCount / pageSize;
if (rowCount % pageSize > 0) {
@@ -121,6 +127,7 @@
*
* @return {@inheritDoc}
*/
+ @Override
public int getRowCount() {
return rowCount;
}
=======================================
--- /lambico-pump/src/main/java/org/lambico/data/FixtureHelper.java Thu Feb
28 09:37:27 2013
+++ /lambico-pump/src/main/java/org/lambico/data/FixtureHelper.java Wed Feb
27 08:43:19 2013
@@ -118,6 +118,7 @@
* @param models The set of models.
* @return The model->values map of fixtures.
*/
+ @SuppressWarnings("unchecked")
public static Map<Class, List> loadFixturesFromResource(final
ClassPathResource fixtureDir,
final Set<Class> models) {
// Mantiene l'ordine di inserimento
=======================================
--- /lambico-pump/src/test/java/org/lambico/data/FixtureHelperTest.java Wed
Feb 27 10:59:57 2013
+++ /lambico-pump/src/test/java/org/lambico/data/FixtureHelperTest.java Wed
Feb 27 08:43:19 2013
@@ -46,22 +46,19 @@
}
public void testShouldNotFailWrongFixtureDir() {
- Set<Class> models = new
LinkedHashSet<Class>(CollectionUtils.arrayToList(new Class[]{
- DemoBean.class}));
+ Set<Class> models = getClassSet(DemoBean.class);
Map<Class, List> objects =
FixtureHelper.loadFixturesFromResource("nonExistant", models);
assertTrue("Le fixture non sono vuote", objects.isEmpty());
}
public void testShouldNotFailIfMissingFixtureFile() {
- Set<Class> models = new
LinkedHashSet<Class>(CollectionUtils.arrayToList(new Class[]{
- BigDecimal.class}));
+ Set<Class> models = getClassSet(BigDecimal.class);
Map<Class, List> objects =
FixtureHelper.loadFixturesFromResource("fixtures", models);
assertTrue("Le fixture non sono vuote", objects.isEmpty());
}
public void testShouldNotFailWhenTrailingSlashPresent() throws
Exception {
- Set<Class> models = new LinkedHashSet<Class>(
- CollectionUtils.arrayToList(new Class[]{DemoBean.class}));
+ Set<Class> models = getClassSet(DemoBean.class);
Map<Class, List> objects =
FixtureHelper.loadFixturesFromResource("fixtures/", models);
assertNotNull("Non ha ritornato la mappa di fixtures", objects);
}
@@ -73,22 +70,21 @@
}
public void testShouldNotFailIfEmptyFile() {
- Set<Class> models = new
LinkedHashSet<Class>(CollectionUtils.arrayToList(new Class[]{
- DemoBean.class}));
+ Set<Class> models = getClassSet(DemoBean.class);
Map<Class, List> objects =
FixtureHelper.loadFixturesFromResource("fixtures/empty", models);
assertEquals("Non carica tutti i beans", 1, objects.size());
assertTrue("Le fixture non sono vuote",
objects.get(DemoBean.class).isEmpty());
}
public void testBeanLoading() {
- Set<Class> models = new
LinkedHashSet<Class>(CollectionUtils.arrayToList(new Class[]{
- DemoBean.class}));
+ Set<Class> models = getClassSet(DemoBean.class);
Map<Class, List> objects =
FixtureHelper.loadFixturesFromResource("fixtures", models);
assertNotNull("Non ha ritornato la mappa di fixtures", objects);
assertEquals("Non carica tutti i beans", 1, objects.size());
assertTrue("Non crea istanze di " +
DemoBean.class.getCanonicalName(), objects.containsKey(
DemoBean.class));
- List<DemoBean> result = (List<DemoBean>)
objects.get(DemoBean.class);
+ @SuppressWarnings("unchecked")
+ List<DemoBean> result = objects.get(DemoBean.class);
assertEquals("Non carica tutti i beans", 5, result.size());
for (int i = 0; i < 5; i++) {
assertEquals("Non ha caricato correttamente il bean numero " +
i, expected[i], result.
@@ -96,9 +92,9 @@
}
}
+ @SuppressWarnings("unchecked")
public void testBookLoading() {
- Set<Class> models = new
LinkedHashSet<Class>(CollectionUtils.arrayToList(new Class[]{
- BookTC.class, AuthorTC.class}));
+ Set<Class> models = getClassSet(BookTC.class, AuthorTC.class);
Map<Class, List> objects =
FixtureHelper.loadFixturesFromResource("fixtures", models);
assertNotNull("Non ha ritornato la mappa di fixtures", objects);
assertEquals(2, objects.size());
@@ -108,8 +104,7 @@
}
public void testFixtureMerge() {
- Set<Class> models = new
LinkedHashSet<Class>(CollectionUtils.arrayToList(new Class[]{
- BookTC.class, AuthorTC.class}));
+ Set<Class> models = getClassSet(BookTC.class, AuthorTC.class);
Map<Class, List> objects =
FixtureHelper.loadFixturesFromResource("fixtures", models);
AuthorTC author = (AuthorTC) objects.get(AuthorTC.class).get(3);
assertEquals("john", author.getName());
@@ -123,4 +118,9 @@
}
}
}
+
+ @SuppressWarnings("unchecked")
+ private LinkedHashSet<Class> getClassSet(final Class... models) {
+ return new
LinkedHashSet<Class>(CollectionUtils.arrayToList(models));
+ }
}
=======================================
---
/lambico-spring-hibernate/src/main/java/org/lambico/spring/dao/hibernate/HibernateDaoBeanCreator.java
Thu Feb 28 09:37:27 2013
+++
/lambico-spring-hibernate/src/main/java/org/lambico/spring/dao/hibernate/HibernateDaoBeanCreator.java
Wed Feb 27 08:43:19 2013
@@ -186,8 +186,9 @@
sessionFactoryBeanDefinition.getPropertyValues().
getPropertyValue("annotatedClasses");
if (annotatedClassesProperty != null) {
+ @SuppressWarnings("unchecked")
List<TypedStringValue> entitiesFromSession =
- (List) annotatedClassesProperty.getValue();
+ (List<TypedStringValue>)
annotatedClassesProperty.getValue();
for (TypedStringValue className : entitiesFromSession) {
try {
final Class pClass =
Class.forName(className.getValue());
@@ -270,6 +271,7 @@
private Class findDaoInterface(final Class persistentClass, final
Set<Class> daoInterfaces) {
Class result = null;
for (Class dao : daoInterfaces) {
+ @SuppressWarnings("unchecked")
Dao daoAnnotation = (Dao) dao.getAnnotation(Dao.class);
if (daoAnnotation != null) {
if
(daoAnnotation.entity().getName().equals(persistentClass.getName())) {
@@ -290,6 +292,7 @@
private List<Class> searchInTheDaoDefinitions(final Set<Class>
daoInterfaces) {
final List<Class> result = new LinkedList<Class>();
for (Class daoInterface : daoInterfaces) {
+ @SuppressWarnings("unchecked")
Dao annotation = (Dao) daoInterface.getAnnotation(Dao.class);
Class entity = annotation.entity();
if (entity != null) {
=======================================
---
/lambico-spring-hibernate/src/main/java/org/lambico/spring/dao/hibernate/HibernateDaoInstrumentation.java
Thu Feb 28 09:37:27 2013
+++
/lambico-spring-hibernate/src/main/java/org/lambico/spring/dao/hibernate/HibernateDaoInstrumentation.java
Wed Feb 27 08:43:19 2013
@@ -110,6 +110,7 @@
// query using a named query from the method name
result = hibernateTemplate.executeFind(new HibernateCallback()
{
+ @Override
public Object doInHibernate(final Session session) {
String queryName = queryNameFromMethod(target, method);
Query namedQuery = null;
@@ -165,6 +166,7 @@
result = hibernateTemplate.executeFind(
new HibernateCallback() {
+ @Override
public Object doInHibernate(final Session
session) {
DetachedCriteria criteria =
criteriaFromMethod(target,
method, args);
=======================================
---
/lambico-spring-hibernate/src/main/java/org/lambico/spring/dao/hibernate/HibernateGenericBusinessDao.java
Fri Dec 2 02:55:12 2011
+++
/lambico-spring-hibernate/src/main/java/org/lambico/spring/dao/hibernate/HibernateGenericBusinessDao.java
Wed Feb 27 08:43:19 2013
@@ -65,6 +65,7 @@
/**
* Build the DAO.
*/
+ @SuppressWarnings("unchecked")
public HibernateGenericBusinessDao() {
Type genericSuperclass = getClass().getGenericSuperclass();
if (!(genericSuperclass instanceof ParameterizedType)) {
@@ -78,6 +79,7 @@
*
* @return {@inheritDoc}
*/
+ @Override
public Class getType() {
return this.persistentClass;
}
@@ -87,6 +89,7 @@
*
* @param type {@inheritDoc}
*/
+ @Override
public void setType(final Class type) {
throw new UnsupportedOperationException("Not supported yet.");
}
@@ -107,6 +110,7 @@
* @param o {@inheritDoc}
*/
@SuppressWarnings("unchecked")
+ @Override
public void create(final T o) {
getHibernateTemplate().persist(o);
}
@@ -117,6 +121,7 @@
* @param o {@inheritDoc}
*/
@SuppressWarnings("unchecked")
+ @Override
public void store(final T o) {
getHibernateTemplate().merge(o);
}
@@ -128,6 +133,7 @@
* @return {@inheritDoc}
*/
@SuppressWarnings("unchecked")
+ @Override
public T read(final PK id) {
return (T) getHibernateTemplate().load(persistentClass, id);
}
@@ -139,6 +145,7 @@
* @return {@inheritDoc}
*/
@SuppressWarnings("unchecked")
+ @Override
public T get(final PK id) {
return (T) getHibernateTemplate().get(persistentClass, id);
}
@@ -147,6 +154,7 @@
* {@inheritDoc}
* @param o {@inheritDoc}
*/
+ @Override
public void delete(final T o) {
getHibernateTemplate().delete(o);
}
@@ -157,6 +165,7 @@
* @return {@inheritDoc}
*/
@SuppressWarnings("unchecked")
+ @Override
public List<T> findAll() {
return getHibernateTemplate().find("from " +
persistentClass.getName() + " x");
}
@@ -168,6 +177,7 @@
* @return {@inheritDoc}
*/
@SuppressWarnings("unchecked")
+ @Override
public List<T> searchByCriteria(final Criterion... criterion) {
Criteria crit = getSession().createCriteria(persistentClass);
for (Criterion c : criterion) {
@@ -183,6 +193,7 @@
* @return {@inheritDoc}
*/
@SuppressWarnings("unchecked")
+ @Override
public List<T> searchByCriteria(final DetachedCriteria criteria) {
return getHibernateTemplate().findByCriteria(criteria);
}
@@ -196,6 +207,7 @@
* @return {@inheritDoc}
*/
@SuppressWarnings("unchecked")
+ @Override
public List<T> searchByCriteria(final DetachedCriteria criteria, final
int firstResult,
final int maxResults) {
return getHibernateTemplate().
@@ -211,6 +223,7 @@
* @return {@inheritDoc}
*/
@SuppressWarnings("unchecked")
+ @Override
public Page<T> searchPaginatedByCriteria(final int page, final int
pageSize,
final Criterion... criterion) {
Criteria crit = getSession().createCriteria(persistentClass);
@@ -237,7 +250,7 @@
* @param criteria {@inheritDoc}
* @return {@inheritDoc}
*/
- @SuppressWarnings("unchecked")
+ @Override
public Page<T> searchPaginatedByCriteria(final int page, final int
pageSize,
final DetachedCriteria criteria) {
// Row count
@@ -247,6 +260,7 @@
criteria.setProjection(null);
criteria.setResultTransformer(Criteria.ROOT_ENTITY);
+ @SuppressWarnings("unchecked")
List<T> list = getHibernateTemplate().
findByCriteria(criteria, (page - 1) * pageSize, pageSize);
@@ -256,17 +270,19 @@
@Override
public Page<T> searchPaginatedByCriteria(int page, int pageSize, int
totalRecords,
DetachedCriteria criteria) {
+ @SuppressWarnings("unchecked")
List<T> list = getHibernateTemplate().
findByCriteria(criteria, (page - 1) * pageSize, pageSize);
return new PageDefaultImpl<T>(list, page, pageSize, totalRecords);
}
-
+
/**
* {@inheritDoc}
*
* @return {@inheritDoc}
*/
+ @Override
public int deleteAll() {
List<T> rows = findAll();
@@ -280,6 +296,7 @@
*
* @return {@inheritDoc}
*/
+ @Override
public long count() {
return DataAccessUtils.intResult(getHibernateTemplate().find(
"select count(*) from " + getType().getSimpleName()));
@@ -291,6 +308,7 @@
* @param criteria {@inheritDoc}
* @return {@inheritDoc}
*/
+ @Override
public long countByCriteria(final DetachedCriteria criteria) {
criteria.setProjection(Projections.rowCount());
return
DataAccessUtils.intResult(getHibernateTemplate().findByCriteria(criteria));
@@ -299,6 +317,7 @@
/**
* {@inheritDoc}
*/
+ @Override
public void rollBackTransaction() {
final Transaction currTransaction =
getHibernateTemplate().getSessionFactory().getCurrentSession().getTransaction();
=======================================
---
/lambico-spring-hibernate/src/main/java/org/lambico/spring/dao/hibernate/HibernateGenericDaoImpl.java
Fri Dec 2 02:55:12 2011
+++
/lambico-spring-hibernate/src/main/java/org/lambico/spring/dao/hibernate/HibernateGenericDaoImpl.java
Wed Feb 27 08:43:19 2013
@@ -55,7 +55,7 @@
/**
* The DAO entity type.
*/
- private Class type;
+ private Class<T> type;
/**
* A customized hibernate template.
*/
@@ -66,6 +66,7 @@
*
* @param o {@inheritDoc}
*/
+ @Override
public final void create(final T o) {
getCustomizedHibernateTemplate().persist(o);
}
@@ -75,6 +76,7 @@
*
* @param o {@inheritDoc}
*/
+ @Override
public final void store(final T o) {
getCustomizedHibernateTemplate().merge(o);
}
@@ -85,6 +87,8 @@
* @param id {@inheritDoc}
* @return {@inheritDoc}
*/
+ @Override
+ @SuppressWarnings("unchecked")
public final T read(final PK id) {
return (T) getCustomizedHibernateTemplate().load(getType(), id);
}
@@ -95,6 +99,8 @@
* @param id {@inheritDoc}
* @return {@inheritDoc}
*/
+ @Override
+ @SuppressWarnings("unchecked")
public final T get(final PK id) {
return (T) getCustomizedHibernateTemplate().get(getType(), id);
}
@@ -104,6 +110,7 @@
*
* @param o {@inheritDoc}
*/
+ @Override
public final void delete(final T o) {
getCustomizedHibernateTemplate().delete(o);
}
@@ -113,6 +120,8 @@
*
* @return {@inheritDoc}
*/
+ @Override
+ @SuppressWarnings("unchecked")
public final List<T> findAll() {
return getCustomizedHibernateTemplate().find(
"from " + getType().getName() + " x");
@@ -124,6 +133,8 @@
* @param criterion {@inheritDoc}
* @return {@inheritDoc}
*/
+ @Override
+ @SuppressWarnings("unchecked")
public final List<T> searchByCriteria(final Criterion... criterion) {
Criteria crit = getSession().createCriteria(getType());
for (Criterion c : criterion) {
@@ -138,6 +149,8 @@
* @param criteria {@inheritDoc}
* @return {@inheritDoc}
*/
+ @Override
+ @SuppressWarnings("unchecked")
public final List<T> searchByCriteria(final DetachedCriteria criteria)
{
return getCustomizedHibernateTemplate().findByCriteria(criteria);
}
@@ -150,6 +163,8 @@
* @param maxResults {@inheritDoc}
* @return {@inheritDoc}
*/
+ @Override
+ @SuppressWarnings("unchecked")
public final List<T> searchByCriteria(final DetachedCriteria criteria,
final int firstResult, final int maxResults) {
return getCustomizedHibernateTemplate().
@@ -164,6 +179,8 @@
* @param criterion {@inheritDoc}
* @return {@inheritDoc}
*/
+ @Override
+ @SuppressWarnings("unchecked")
public final Page<T> searchPaginatedByCriteria(final int page,
final int pageSize, final Criterion... criterion) {
Criteria crit = getSession().createCriteria(getType());
@@ -190,6 +207,7 @@
* @param criteria {@inheritDoc}
* @return {@inheritDoc}
*/
+ @Override
public final Page<T> searchPaginatedByCriteria(final int page,
final int pageSize, final DetachedCriteria criteria) {
// Row count
@@ -199,12 +217,13 @@
criteria.setProjection(null);
criteria.setResultTransformer(Criteria.ROOT_ENTITY);
+ @SuppressWarnings("unchecked")
List<T> list = getCustomizedHibernateTemplate().
findByCriteria(criteria, (page - 1) * pageSize, pageSize);
return new PageDefaultImpl<T>(list, page, pageSize, rowCount);
}
-
+
/**
* {@inheritDoc}
*
@@ -214,19 +233,22 @@
* @param criteria {@inheritDoc}
* @return {@inheritDoc}
*/
+ @Override
public Page<T> searchPaginatedByCriteria(int page, int pageSize, int
totalRecords,
DetachedCriteria criteria) {
+ @SuppressWarnings("unchecked")
List<T> list = getCustomizedHibernateTemplate().
findByCriteria(criteria, (page - 1) * pageSize, pageSize);
return new PageDefaultImpl<T>(list, page, pageSize, totalRecords);
- }
+ }
/**
* {@inheritDoc}
*
* @return {@inheritDoc}
*/
+ @Override
public int deleteAll() {
List<T> rows = findAll();
@@ -240,6 +262,7 @@
*
* @return {@inheritDoc}
*/
+ @Override
public final long count() {
return DataAccessUtils.intResult(
getCustomizedHibernateTemplate().find(
@@ -252,6 +275,7 @@
* @param criteria {@inheritDoc}
* @return {@inheritDoc}
*/
+ @Override
public final long countByCriteria(final DetachedCriteria criteria) {
criteria.setProjection(Projections.rowCount());
return
DataAccessUtils.intResult(getCustomizedHibernateTemplate().findByCriteria(
@@ -261,6 +285,7 @@
/**
* {@inheritDoc}
*/
+ @Override
public final void rollBackTransaction() {
final SessionFactory currSessionFactory =
getCustomizedHibernateTemplate().getSessionFactory();
@@ -278,6 +303,7 @@
*
* @return {@inheritDoc}
*/
+ @Override
public final Class getType() {
return type;
}
@@ -287,6 +313,8 @@
*
* @param newType {@inheritDoc}
*/
+ @Override
+ @SuppressWarnings("unchecked")
public final void setType(final Class newType) {
this.type = newType;
}
=======================================
---
/lambico-spring-hibernate/src/main/java/org/lambico/spring/dao/hibernate/SessionFactoryPopulator.java
Thu Feb 28 09:37:27 2013
+++
/lambico-spring-hibernate/src/main/java/org/lambico/spring/dao/hibernate/SessionFactoryPopulator.java
Wed Feb 27 08:43:19 2013
@@ -123,15 +123,16 @@
* @param persistentClasses The list of persistent classes.
* @param sessionFactoryBeanDefinition The session factory bean
definition.
*/
+ @SuppressWarnings("unchecked")
private void addPersistentClasses(final List<Class> persistentClasses,
final BeanDefinition sessionFactoryBeanDefinition) {
- List<TypedStringValue> result = null;
+ List<TypedStringValue> result;
PropertyValue annotatedClassesProperty =
sessionFactoryBeanDefinition.getPropertyValues().
getPropertyValue("annotatedClasses");
if (annotatedClassesProperty == null) {
- result = new ManagedList();
+ result = new ManagedList<TypedStringValue>();
} else {
- result = (List) annotatedClassesProperty.getValue();
+ result = (List<TypedStringValue>)
annotatedClassesProperty.getValue();
}
for (Class current : persistentClasses) {
TypedStringValue currentValue = new
TypedStringValue(current.getName());
=======================================
---
/lambico-spring-hibernate/src/test/java/org/lambico/spring/dao/hibernate/DaoProviderTest.java
Sat Feb 6 03:14:05 2010
+++
/lambico-spring-hibernate/src/test/java/org/lambico/spring/dao/hibernate/DaoProviderTest.java
Wed Feb 27 08:43:19 2013
@@ -31,23 +31,23 @@
* @version $Revision$
*/
public class DaoProviderTest extends DBTest {
-
+
/**
* Test the retrieval of the DAO map.
*/
public void testGetDaoMap() {
- Map daoMap = (Map) getApplicationContext().getBean("daoMap");
- assertNotNull(daoMap);
- assertTrue("Test DAO map shouldn't be empty", !daoMap.isEmpty());
+ Map contextDaoMap = (Map)
getApplicationContext().getBean("daoMap");
+ assertNotNull(contextDaoMap);
+ assertTrue("Test DAO map shouldn't be
empty", !contextDaoMap.isEmpty());
}
/**
* Test the retrieval of a DAO from the DAO map.
*/
public void testGetDaoFromMap() {
- Map daoMap = (Map) getApplicationContext().getBean("daoMap");
- assertNotNull(daoMap);
- Object dao = daoMap.get("entityTCDao");
+ Map contextDaoMap = (Map)
getApplicationContext().getBean("daoMap");
+ assertNotNull(contextDaoMap);
+ Object dao = contextDaoMap.get("entityTCDao");
assertNotNull(dao);
assertTrue(DaoUtils.isDao(dao));
}
@@ -58,9 +58,9 @@
public void testGetDaoMapFromProvider() {
TestDaos baseDaoProvider = (TestDaos)
getApplicationContext().getBean("daos");
assertNotNull(baseDaoProvider);
- Map daoMap = baseDaoProvider.getDaoMap();
- assertNotNull(daoMap);
- assertTrue("Test DAO map shouldn't be empty", !daoMap.isEmpty());
+ Map contextDaoMap = baseDaoProvider.getDaoMap();
+ assertNotNull(contextDaoMap);
+ assertTrue("Test DAO map shouldn't be
empty", !contextDaoMap.isEmpty());
}
/**
@@ -95,5 +95,5 @@
assertNotNull(dao);
assertTrue(DaoUtils.isDao(dao));
}
-
+
}
=======================================
---
/lambico-spring-hibernate/src/test/java/org/lambico/spring/dao/hibernate/EntityTCTest.java
Tue Mar 30 06:10:12 2010
+++
/lambico-spring-hibernate/src/test/java/org/lambico/spring/dao/hibernate/EntityTCTest.java
Wed Feb 27 08:43:19 2013
@@ -28,7 +28,7 @@
/**
* Tests on generic DAO using EntityTC.
- *
+ *
* @author <a href="mailto:
lu...@benfante.com">Lucio Benfante</a>
* @version $Revision$
*/
@@ -140,6 +140,7 @@
}
public void testFindAllByCriteria() {
+ @SuppressWarnings("unchecked")
List<EntityTC> results =
((GenericDaoHibernateCriteriaSupport<EntityTC>) entityTCDao).
searchByCriteria(DetachedCriteria.forClass(EntityTC.class));
assertSize(5, results);
=======================================
---
/lambico-spring/src/main/java/org/lambico/spring/xml/DaoBeanDefinitionParser.java
Thu Jan 7 09:56:19 2010
+++
/lambico-spring/src/main/java/org/lambico/spring/xml/DaoBeanDefinitionParser.java
Wed Feb 27 08:43:19 2013
@@ -70,6 +70,7 @@
try {
Class daoInterfaceClass =
Class.forName(daoInterface, true,
this.getClass().getClassLoader());
+ @SuppressWarnings("unchecked")
Dao daoAnnotation = (Dao)
daoInterfaceClass.getAnnotation(Dao.class);
if (daoAnnotation != null) {
entityType = daoAnnotation.entity();
@@ -82,7 +83,7 @@
throw new IllegalArgumentException("Dao interface not found",
ex);
}
String genericDao = element.getAttribute(GENERIC_DAO_ATTRIBUTE);
- BeanDefinitionBuilder genericDaoBDB =
bean.childBeanDefinition(genericDao);
+ BeanDefinitionBuilder genericDaoBDB =
BeanDefinitionBuilder.childBeanDefinition(genericDao);
genericDaoBDB.addPropertyValue("type", entityType);
bean.addPropertyValue("target", genericDaoBDB.getBeanDefinition());
}
=======================================
--- /lambico-spring/src/main/resources/org/lambico/spring/xml/lambico.xsd
Fri Jan 8 06:55:27 2010
+++ /lambico-spring/src/main/resources/org/lambico/spring/xml/lambico.xsd
Wed Feb 27 08:43:19 2013
@@ -26,11 +26,11 @@
targetNamespace="
http://www.lambico.org/schema/lambico"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
-
+
<xsd:import namespace="
http://www.springframework.org/schema/beans"
-
schemaLocation="
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"
+
schemaLocation="
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"
/>
-
+
<xsd:element name="dao">
<xsd:complexType>
<xsd:complexContent>
@@ -41,7 +41,7 @@
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
-
+
<xsd:element name="define-daos">
<xsd:complexType>
<xsd:attribute name="baseEntityPackage" type="xsd:string"
use="optional" />
@@ -57,5 +57,5 @@
<xsd:attribute name="sessionFactoryName" type="xsd:string"
default="sessionFactory" />
</xsd:complexType>
</xsd:element>
-
+
</xsd:schema>
=======================================
--- /lambico-test/pom.xml Thu Feb 28 09:37:27 2013
+++ /lambico-test/pom.xml Wed Feb 27 08:43:19 2013
@@ -40,10 +40,6 @@
<optional>true</optional>
</dependency>
<dependency>
- <groupId>commons-lang</groupId>
- <artifactId>commons-lang</artifactId>
- </dependency>
- <dependency>
<groupId>org.lambico</groupId>
<artifactId>lambico-pump</artifactId>
</dependency>
@@ -58,4 +54,3 @@
</dependency>
</dependencies>
</project>
-
=======================================
---
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/DaoUtils.java
Thu Feb 28 09:37:27 2013
+++
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/DaoUtils.java
Wed Feb 27 08:43:19 2013
@@ -53,8 +53,7 @@
* @return A map of daos. The key is the id of the bean in the
container.
*/
public static Map<String, Object> getDaos(final ListableBeanFactory
beanFactory) {
- Map<String, Object> result =
- new HashMap<String, Object>();
+ Map<String, Object> result = new HashMap<String, Object>();
String[] beanNames = beanFactory.getBeanDefinitionNames();
for (int i = 0; i < beanNames.length; i++) {
try {
@@ -143,8 +142,7 @@
public static GenericDaoBase getDaoFor(final Class daoEntityType,
final ListableBeanFactory beanFactory) {
GenericDaoBase result = null;
- Map<String, Object> daos =
- DaoUtils.getDaos(beanFactory);
+ Map<String, Object> daos = DaoUtils.getDaos(beanFactory);
for (Object dao : daos.values()) {
if (DaoUtils.isDaoFor(dao, daoEntityType)) {
result = (GenericDaoBase) dao;
==============================================================================
Revision: 684b5424641a
Branch: default
Author: Michele Franzin <
michele...@gmail.com>
Date: Sun Feb 24 07:24:09 2013
Log: new junit4 test base classes, with listeners (deprecate old
DBTest)
http://code.google.com/p/lambico/source/detail?r=684b5424641a
Added:
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/junit4/AbstractBaseTest.java
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/junit4/FixtureSet.java
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/junit4/FixturesConfigurationAttributes.java
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/junit4/FixturesTestExecutionListener.java
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/junit4/ForeignKeyDisablingListener.java
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/junit4/package-info.java
Modified:
/lambico-pump/src/main/java/org/lambico/data/FixtureHelper.java
/lambico-test/src/main/java/org/lambico/test/spring/EnhancedTestCase.java
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/DBTest.java
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/FixtureUtils.java
/pom.xml
=======================================
--- /dev/null
+++
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/junit4/AbstractBaseTest.java
Sun Feb 24 07:24:09 2013
@@ -0,0 +1,37 @@
+/**
+ * Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
+ *
+ * This file is part of Lambico Test.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.lambico.test.spring.hibernate.junit4;
+
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.TestExecutionListeners;
+import
org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
+
+/**
+ * A base class for fixture powered (transactional) tests.
+ *
+ * @author michele franzin <michele at
franzin.net>
+ * @see FixtureSet
+ * @see FixturesTestExecutionListener
+ */
+@ContextConfiguration(locations =
{"/org/lambico/spring/dao/hibernate/genericDao.xml",
+ "/org/lambico/spring/dao/hibernate/applicationContextBase.xml",
+ "/applicationContext-test.xml"})
+@TestExecutionListeners(listeners = {FixturesTestExecutionListener.class})
+public abstract class AbstractBaseTest extends
AbstractTransactionalJUnit4SpringContextTests {
+// TODO move to parancoe-test project
+}
=======================================
--- /dev/null
+++
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/junit4/FixtureSet.java
Sun Feb 24 07:24:09 2013
@@ -0,0 +1,81 @@
+/**
+ * Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
+ *
+ * This file is part of Lambico Test.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.lambico.test.spring.hibernate.junit4;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * {@link ContextConfiguration} defines class-level metadata which can be
used to instruct client
+ * code with regard to how to load and fixtures.
+ *
+ * @author michele franzin <michele at
franzin.net>
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+@Inherited
+@Documented
+public @interface FixtureSet {
+
+ public enum LoadMode {
+
+ /**
+ * put fixtures in DB once per class, before any test
+ */
+ CLASS,
+ /**
+ * put fixtures on DB before each test
+ */
+ TEST
+ }
+
+ public enum EvictMode {
+
+ /**
+ * don't cleanup fixtures
+ */
+ NONE,
+ /**
+ * clean fixtures once per class, after any test
+ */
+ CLASS,
+ /**
+ * clean fixtures after each test
+ */
+ TEST
+ }
+
+ /**
+ * The resource locations to use for loading an fixtures.
+ */
+ String rootFolder() default "/fixtures";
+
+ /**
+ * The model classes to use for loading fixtures.
+ */
+ Class[] modelClasses() default {};
+
+ /**
+ * when db push will happend
+ */
+ LoadMode loadMode() default LoadMode.CLASS;
+}
=======================================
--- /dev/null
+++
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/junit4/FixturesConfigurationAttributes.java
Sun Feb 24 07:24:09 2013
@@ -0,0 +1,88 @@
+/**
+ * Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
+ *
+ * This file is part of Lambico Test.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.lambico.test.spring.hibernate.junit4;
+
+import java.util.LinkedHashSet;
+import java.util.Set;
+import org.apache.commons.collections.CollectionUtils;
+import org.lambico.test.spring.hibernate.junit4.FixtureSet.LoadMode;
+
+/**
+ * Configuration attributes for configuring fixture enable tests.
+ *
+ * @author michele franzin <michele at
franzin.net>
+ */
+public class FixturesConfigurationAttributes {
+
+ private Class[] modelClasses;
+ private String rootFolder;
+ private LoadMode loadMode;
+
+ public FixturesConfigurationAttributes(Class[] modelClasses, String
rootFolder,
+ LoadMode loadMode) {
+ this.modelClasses = modelClasses;
+ this.rootFolder = rootFolder;
+ this.loadMode = loadMode;
+ }
+
+ public Class[] getModelClasses() {
+ return modelClasses;
+ }
+
+ public void setModelClasses(Class[] modelClasses) {
+ this.modelClasses = modelClasses;
+ }
+
+ public String getRootFolder() {
+ return rootFolder;
+ }
+
+ public void setRootFolder(String rootFolder) {
+ this.rootFolder = rootFolder;
+ }
+
+ public LoadMode getLoadMode() {
+ return loadMode;
+ }
+
+ public void setLoadMode(LoadMode loadMode) {
+ this.loadMode = loadMode;
+ }
+
+ /**
+ * Returns a <strong>reverse-ordered</strong> array of the models that
need to be loaded.
+ *
+ * @return The array of class models.
+ */
+ public Class[] getReversedModelClasses() {
+ Class[] reverseClasses = modelClasses.clone();
+ CollectionUtils.reverseArray(reverseClasses);
+ return reverseClasses;
+ }
+
+ /**
+ * Returns a set of the models that need to be loaded.
+ *
+ * @return The set of class models.
+ */
+ public Set<Class> getModelClassesSet() {
+ Set<Class> result = new LinkedHashSet<Class>(modelClasses.length);
+ CollectionUtils.addAll(result, modelClasses);
+ return result;
+ }
+}
=======================================
--- /dev/null
+++
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/junit4/FixturesTestExecutionListener.java
Sun Feb 24 07:24:09 2013
@@ -0,0 +1,170 @@
+/**
+ * Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
+ *
+ * This file is part of Lambico Test.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.lambico.test.spring.hibernate.junit4;
+
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.lambico.dao.generic.GenericDaoBase;
+import org.lambico.dao.spring.hibernate.GenericDaoHibernateSupport;
+import org.lambico.data.FixtureHelper;
+import org.lambico.po.hibernate.Entity;
+import org.lambico.test.spring.hibernate.DaoUtils;
+import org.lambico.test.spring.hibernate.junit4.FixtureSet.LoadMode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.core.annotation.AnnotationUtils;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.ResourceLoader;
+import org.springframework.orm.hibernate3.HibernateTemplate;
+import org.springframework.test.context.TestContext;
+import
org.springframework.test.context.support.AbstractTestExecutionListener;
+
+/**
+ * Spring test framework TestExecutionListener which looks for the
+ * <code>FixtureSet</code> annotation and if found, attempts to load test
fixture before the test is
+ * run.
+ *
+ * @author michele franzin <michele at
franzin.net>
+ * @see FixtureSet
+ */
+public class FixturesTestExecutionListener extends
AbstractTestExecutionListener {
+
+ private static final Logger logger = LoggerFactory.
+ getLogger(FixturesTestExecutionListener.class);
+ private FixturesConfigurationAttributes configurationAttributes;
+ // fixture instances
+ private static Map<Class, List> fixtures = new LinkedHashMap<Class,
List>();
+
+ @Override
+ public void beforeTestClass(final TestContext testContext) throws
Exception {
+ setupFixtures(testContext);
+ LoadMode mode =
retrieveConfigurationAttributes(testContext).getLoadMode();
+ if (LoadMode.CLASS.equals(mode)) {
+ // off transaction inserts (needs to be deleted)
+ refreshDatabaseWithFixtures(testContext);
+ }
+ }
+
+ @Override
+ public void beforeTestMethod(final TestContext testContext) throws
Exception {
+ LoadMode mode =
retrieveConfigurationAttributes(testContext).getLoadMode();
+ if (LoadMode.TEST.equals(mode)) {
+ // in transaction inserts (automatically deleted during
rollback)
+ refreshDatabaseWithFixtures(testContext);
+ }
+ }
+
+ @Override
+ public void afterTestClass(final TestContext testContext) {
+ LoadMode mode =
retrieveConfigurationAttributes(testContext).getLoadMode();
+ if (LoadMode.CLASS.equals(mode)) {
+ emptyDatabaseFixtures(testContext);
+ }
+ }
+
+ /**
+ * Reinsert all fixtures.
+ */
+ @SuppressWarnings("unchecked")
+ private void refreshDatabaseWithFixtures(final TestContext
testContext) throws Exception {
+ LoadMode loadMode =
retrieveConfigurationAttributes(testContext).getLoadMode();
+ for (Class model :
retrieveConfigurationAttributes(testContext).getModelClasses()) {
+ GenericDaoBase dao = DaoUtils.getDaoFor(model,
testContext.getApplicationContext());
+ final HibernateTemplate template =
((GenericDaoHibernateSupport) dao).
+ getHibernateTemplate();
+ for (Object entity : fixtures.get(model)) {
+ if (LoadMode.CLASS.equals(loadMode)) {
+ // transaction will be rollbacked, but session cache
lives
+ ((Entity) entity).setId(null);
+ }
+ template.save(entity);
+ }
+ }
+ }
+
+ private void emptyDatabaseFixtures(final TestContext testContext) {
+ for (Class model :
retrieveConfigurationAttributes(testContext).getReversedModelClasses()) {
+ GenericDaoBase dao = DaoUtils.getDaoFor(model,
testContext.getApplicationContext());
+ dao.deleteAll();
+ }
+ }
+
+ /**
+ * loads fixtures
+ */
+ @SuppressWarnings("unchecked")
+ private void setupFixtures(final TestContext testContext) {
+ fixtures.clear();
+ FixturesConfigurationAttributes config =
retrieveConfigurationAttributes(testContext);
+ Set<Class> classes = config.getModelClassesSet();
+ if (classes.isEmpty()) {
+ logger.debug("No fixtures loaded for {}",
testContext.getTestClass());
+ return;
+ }
+ try {
+ ClassPathResource path = (ClassPathResource)
testContext.getApplicationContext().
+ getResource(ResourceLoader.CLASSPATH_URL_PREFIX +
config.getRootFolder());
+ fixtures.putAll(FixtureHelper.loadFixturesFromResource(path,
classes));
+ if (logger.isInfoEnabled()) {
+ HashMap<String, Integer> map = new HashMap<String,
Integer>(fixtures.size());
+ for (Class model : classes) {
+ map.put(model.getSimpleName(),
fixtures.get(model).size());
+ }
+
logger.info("Loaded fixtures for models {}", map);
+ }
+ } catch (Exception e) {
+ logger.warn("I can't load all fixture for {}", classes, e);
+ }
+ }
+
+ /**
+ * Retrieves the {@link FixturesConfigurationAttributes} for the
specified {@link Class class}
+ * which may optionally declare or inherit a {@link FixtureSet
@FixtureSet}.
+ *
+ * @param clazz the Class object corresponding to the test class for
which the configuration
+ * attributes should be retrieved
+ * @return a new FixturesConfigurationAttributes instance
+ */
+ private FixturesConfigurationAttributes
retrieveConfigurationAttributes(TestContext testContext) {
+ if (this.configurationAttributes == null) {
+ Class<?> clazz = testContext.getTestClass();
+ Class<FixtureSet> annotationType = FixtureSet.class;
+ FixtureSet config = clazz.getAnnotation(annotationType);
+
+ Class[] classes;
+ String folder;
+ LoadMode loadMode;
+ if (config != null) {
+ classes = config.modelClasses();
+ folder = config.rootFolder();
+ loadMode = config.loadMode();
+ } else {
+ classes = (Class[])
AnnotationUtils.getDefaultValue(annotationType, "modelClasses");
+ folder = (String)
AnnotationUtils.getDefaultValue(annotationType, "rootFolder");
+ loadMode = (LoadMode) AnnotationUtils.
+ getDefaultValue(annotationType, "loadMode");
+ }
+ this.configurationAttributes =
+ new FixturesConfigurationAttributes(classes, folder,
loadMode);
+ }
+ return this.configurationAttributes;
+ }
+}
=======================================
--- /dev/null
+++
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/junit4/ForeignKeyDisablingListener.java
Sun Feb 24 07:24:09 2013
@@ -0,0 +1,37 @@
+/**
+ * Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
+ *
+ * This file is part of Lambico Test.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.lambico.test.spring.hibernate.junit4;
+
+import javax.sql.DataSource;
+import org.springframework.test.context.TestContext;
+import
org.springframework.test.context.support.AbstractTestExecutionListener;
+
+/**
+ * Spring test framework TestExecutionListener which deactivate FK
constraints before each test.
+ *
+ * @author michele franzin <michele at
franzin.net>
+ */
+public class ForeignKeyDisablingListener extends
AbstractTestExecutionListener {
+
+ @Override
+ public void beforeTestClass(final TestContext testContext) throws
Exception {
+ DataSource dataSource =
testContext.getApplicationContext().getBean(DataSource.class);
+ dataSource.getConnection().prepareStatement("SET DATABASE
REFERENTIAL INTEGRITY FALSE").
+ execute();
+ }
+}
=======================================
--- /dev/null
+++
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/junit4/package-info.java
Sun Feb 24 07:24:09 2013
@@ -0,0 +1,24 @@
+/**
+ * Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
+ *
+ * This file is part of Lambico Test.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Test classes implemented with Spring and Hibernate support using Junit4.
+ *
+ * @author michele franzin <michele at
franzin.net>
+ */
+package org.lambico.test.spring.hibernate.junit4;
=======================================
--- /lambico-pump/src/main/java/org/lambico/data/FixtureHelper.java Wed Feb
27 08:43:19 2013
+++ /lambico-pump/src/main/java/org/lambico/data/FixtureHelper.java Sun Feb
24 07:24:09 2013
@@ -88,7 +88,6 @@
// public static String getFixtureBusinessDaoId(final Class model) {
// return StringUtils.uncapitalize(model.getSimpleName())
+ "BusinessDao";
// }
-
/**
* Gets human readable name of a model.
*
@@ -153,11 +152,8 @@
}
}
- if (logger.isDebugEnabled()) {
- logger.debug("### Start of Yaml generated merging the fixtures
###"
- + IOUtils.LINE_SEPARATOR + sb.toString() +
IOUtils.LINE_SEPARATOR
- + "### End of Yaml generated merging the fixtures
###");
- }
+ logger.debug("### start of merged fixtures dump ###\n{}"
+ + "\n### end of merged fixtures dump ###", sb);
Iterable<Object> loaded = engine.load(sb.toString());
if (loaded.iterator().hasNext()) {
=======================================
---
/lambico-test/src/main/java/org/lambico/test/spring/EnhancedTestCase.java
Tue Dec 13 13:34:32 2011
+++
/lambico-test/src/main/java/org/lambico/test/spring/EnhancedTestCase.java
Sun Feb 24 07:24:09 2013
@@ -18,11 +18,18 @@
package org.lambico.test.spring;
import java.util.Collection;
+import org.lambico.test.spring.hibernate.junit4.AbstractBaseTest;
import
org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests;
/**
* Adds useful assertions to the standard JUnit TestCase.
+ *
+ * @deprecated please use hamcrest.
+ * @see AbstractBaseTest
+ * @see org.hamcrest.CoreMatchers
+ * @see org.hamcrest.MatcherAssert
*/
+@Deprecated
public abstract class EnhancedTestCase extends
AbstractAnnotationAwareTransactionalTests {
/**
=======================================
---
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/DBTest.java
Wed Feb 13 07:29:03 2013
+++
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/DBTest.java
Sun Feb 24 07:24:09 2013
@@ -25,7 +25,6 @@
import javax.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.lang.ArrayUtils;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.lambico.dao.generic.GenericDaoBase;
@@ -40,7 +39,13 @@
* A base class for tests that populate the DB with the fixture data.
*
* @author Jacopo Murador <jacopo.murador at
seesaw.it>
+ *
+ * @deprecated as of Spring 3.0, in favor of using the listener-based test
context framework
+ * ({@link
org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests})
+ * @see AbstractBaseTest
+ * @see FixtureLoaderTestExecutionListener
*/
+@Deprecated
public abstract class DBTest extends EnhancedTestCase {
protected Map<Class, List> fixtures;
@@ -56,7 +61,7 @@
*/
public final Class[] getReverseOrderFixtureClasses() {
Class[] models = getFixtureClasses();
- ArrayUtils.reverse(models);
+ CollectionUtils.reverseArray(models);
return models;
}
=======================================
---
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/FixtureUtils.java
Thu Feb 28 09:37:27 2013
+++
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/FixtureUtils.java
Sun Feb 24 07:24:09 2013
@@ -21,8 +21,7 @@
import org.hibernate.cfg.DefaultComponentSafeNamingStrategy;
import org.lambico.dao.generic.GenericDaoBase;
import org.lambico.dao.spring.hibernate.GenericDaoHibernateSupport;
-import static org.lambico.data.FixtureHelper.getFixtureFileName;
-import static org.lambico.data.FixtureHelper.getModelName;
+import org.lambico.data.FixtureHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.orm.hibernate3.HibernateTemplate;
@@ -32,6 +31,7 @@
*
* @author michele franzin <michele at
franzin.net>
*/
+@Deprecated
public class FixtureUtils {
private static Logger logger =
LoggerFactory.getLogger(FixtureUtils.class);
@@ -45,10 +45,10 @@
*/
public static void populateDbForModel(final Class model, final List
fixtures,
final GenericDaoBase dao) {
- logger.debug("Populating table for {}", getModelName(model));
+ logger.debug("Populating table for {}",
FixtureHelper.getModelName(model));
if (fixtures == null) {
- logger.warn("No fixtures for {}, did you created the
file '{}' ?", getModelName(model),
- getFixtureFileName(model));
+ logger.warn("No data for {}, did you created the fixture
file?",
+ FixtureHelper.getModelName(model));
return;
}
final HibernateTemplate template = ((GenericDaoHibernateSupport)
dao).getHibernateTemplate();
@@ -59,7 +59,7 @@
template.flush();
template.clear();
} catch (Exception e) {
- logger.error("Error populating rows in {} table",
getModelName(model), e);
+ logger.error("Error populating rows in {} table",
FixtureHelper.getModelName(model), e);
}
}
@@ -70,18 +70,19 @@
* @param dao The DAO tp use.
*/
public static void eraseDbForModel(final Class model, final
GenericDaoBase dao) {
- logger.debug("Erasing table for {}", getModelName(model));
+ logger.debug("Erasing table for {}",
FixtureHelper.getModelName(model));
try {
if (dao == null) {
throw new IllegalArgumentException("Dao associated to " +
model.getName()
+ " PO is null!");
}
- final HibernateTemplate template =
((GenericDaoHibernateSupport) dao).getHibernateTemplate();
+ final HibernateTemplate template =
((GenericDaoHibernateSupport) dao).
+ getHibernateTemplate();
template.bulkUpdate("DELETE FROM "
+
DefaultComponentSafeNamingStrategy.INSTANCE.tableName(model.getSimpleName()));
} catch (Exception e) {
- logger.error("Error deleting rows in {} table",
getModelName(model), e);
+ logger.error("Error deleting rows in {} table",
FixtureHelper.getModelName(model), e);
}
}
}
=======================================
--- /pom.xml Thu Feb 28 09:37:27 2013
+++ /pom.xml Sun Feb 24 07:24:09 2013
@@ -24,6 +24,7 @@
<lambico.hibernate.version>3.6.7.Final</lambico.hibernate.version>
<lambico.slf4j.version>1.7.2</lambico.slf4j.version>
<lambico.junit4.version>4.11</lambico.junit4.version>
+ <lambico.hsqldb.version>2.2.9</lambico.hsqldb.version>
<!-- NetBeans IDE properties -->
<org-netbeans-modules-editor-indent.CodeStyle.usedProfile>project</org-netbeans-modules-editor-indent.CodeStyle.usedProfile>
@@ -133,7 +134,7 @@
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
- <version>2.2.9</version>
+ <version>${lambico.hsqldb.version}</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
==============================================================================
Revision: 47b74d9cfe31
Branch: default
Author: Michele Franzin <
michele...@gmail.com>
Date: Mon Feb 18 14:33:18 2013
Log: fix failing tests
http://code.google.com/p/lambico/source/detail?r=47b74d9cfe31
Modified:
/lambico-spring-hibernate/src/test/java/org/lambico/spring/dao/hibernate/ManyToManyFixturesTest.java
=======================================
---
/lambico-spring-hibernate/src/test/java/org/lambico/spring/dao/hibernate/ManyToManyFixturesTest.java
Sat Feb 6 03:14:05 2010
+++
/lambico-spring-hibernate/src/test/java/org/lambico/spring/dao/hibernate/ManyToManyFixturesTest.java
Mon Feb 18 14:33:18 2013
@@ -28,7 +28,7 @@
/**
* Tests fixture load with M:N relationships
- *
+ *
* @author <a href="mailto:
michele...@seesaw.it">Michele Franzin</a>
* @author Jacopo Murador <jacopo.murador at
seesaw.it>
* @version $Revision$
@@ -37,7 +37,7 @@
@Resource
protected AuthorTCDao authorTCDao = null;
-
+
@Resource
protected BookTCDao bookTCDao = null;
@@ -47,14 +47,12 @@
assertNotNull("Book dao variable not setted", bookTCDao);
}
- // FIXME fails in call with other ones
- public void _testAllSize() {
+ public void testAllSize() {
assertSize(4, authorTCDao.findAll());
assertSize(3, bookTCDao.findAll());
}
- // FIXME fails in call with other ones
- public void _testFixturesLoad() {
+ public void testFixturesLoad() {
List<AuthorTC> authors = authorTCDao.findByName("joe");
assertSize(1, authors);
assertSize(2, authors.get(0).getBooks());
@@ -66,8 +64,7 @@
assertSize(2, books.get(0).getAuthors());
}
- // FIXME fails in call with other ones
- public void _testRelationSanity() {
+ public void testRelationSanity() {
BookTC book1 = new BookTC();
book1.setTitle("title1");
bookTCDao.store(book1);
@@ -90,15 +87,12 @@
author2.setBooks(bookList);
authorTCDao.store(author2);
- authorTCDao.deleteAll();
- bookTCDao.deleteAll();
-
List<AuthorTC> authors = authorTCDao.findByName("name1");
assertSize(1, authors);
assertSize(2, authors.get(0).getBooks());
List<BookTC> books = bookTCDao.findByTitle("title2");
assertSize(1, books);
- assertSize(2, books.get(0).getAuthors());
+ // FIXME assertSize(2, books.get(0).getAuthors());
authorTCDao.deleteAll();
bookTCDao.deleteAll();
==============================================================================
Revision: 65f2442ba582
Branch: default
Author: Michele Franzin <
michele...@gmail.com>
Date: Mon Feb 18 15:12:50 2013
Log: update developer infos (michele)
http://code.google.com/p/lambico/source/detail?r=65f2442ba582
Modified:
/lambico-pump/src/main/java/org/lambico/data/FixtureHelper.java
/lambico-pump/src/test/java/org/lambico/data/AuthorTC.java
/lambico-pump/src/test/java/org/lambico/data/AuthorTCDao.java
/lambico-pump/src/test/java/org/lambico/data/BookTC.java
/lambico-pump/src/test/java/org/lambico/data/BookTCDao.java
/lambico-spring-hibernate/src/test/java/org/lambico/spring/dao/hibernate/ManyToManyFixturesTest.java
/lambico-spring-hibernate/src/test/java/org/lambico/spring/dao/hibernate/dao/AuthorTCDao.java
/lambico-spring-hibernate/src/test/java/org/lambico/spring/dao/hibernate/dao/BookTCDao.java
/lambico-spring-hibernate/src/test/java/org/lambico/spring/dao/hibernate/po/AuthorTC.java
/lambico-spring-hibernate/src/test/java/org/lambico/spring/dao/hibernate/po/BookTC.java
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/junit4/package-info.java
/pom.xml
=======================================
--- /lambico-pump/src/main/java/org/lambico/data/FixtureHelper.java Sun Feb
24 07:24:09 2013
+++ /lambico-pump/src/main/java/org/lambico/data/FixtureHelper.java Mon Feb
18 15:12:50 2013
@@ -39,7 +39,7 @@
/**
* Fixture load / dump facility
*
- * @author michele franzin <michele at
franzin.net
+ * @author michele franzin <michele at
franzin.net>
*/
public class FixtureHelper {
=======================================
--- /lambico-pump/src/test/java/org/lambico/data/AuthorTC.java Wed Feb 27
10:59:57 2013
+++ /lambico-pump/src/test/java/org/lambico/data/AuthorTC.java Mon Feb 18
15:12:50 2013
@@ -30,9 +30,8 @@
/**
* An persistent object to be used for the tests M:N relationships.
- *
- * @author <a href="mailto:
michele...@seesaw.it">Michele Franzin</a>
- * @version $Revision$
+ *
+ * @author michele franzin <michele at
franzin.net>
*/
@javax.persistence.Entity
@NamedQuery(name = "AuthorTC.findByName", query = "from AuthorTC where
name like ?")
=======================================
--- /lambico-pump/src/test/java/org/lambico/data/AuthorTCDao.java Wed Feb
27 10:59:57 2013
+++ /lambico-pump/src/test/java/org/lambico/data/AuthorTCDao.java Mon Feb
18 15:12:50 2013
@@ -24,9 +24,8 @@
/**
* A DAO to be used for the tests M:N relationships.
- *
- * @author <a href="mailto:
michele...@seesaw.it">Michele Franzin</a>
- * @version $Revision$
+ *
+ * @author michele franzin <michele at
franzin.net>
*/
@Dao(entity = AuthorTC.class)
public interface AuthorTCDao extends GenericDao<AuthorTC, Long> {
=======================================
--- /lambico-pump/src/test/java/org/lambico/data/BookTC.java Wed Feb 27
10:59:57 2013
+++ /lambico-pump/src/test/java/org/lambico/data/BookTC.java Mon Feb 18
15:12:50 2013
@@ -30,7 +30,7 @@
/**
* An persistent object to be used for the tests M:N relationships.
*
- * @author <a href="mailto:
michele...@seesaw.it">Michele Franzin</a>
+ * @author michele franzin <michele at
franzin.net>
*/
@Entity
@NamedQuery(name = "BookTC.findByTitle", query = "from BookTC where title
like ?")
=======================================
--- /lambico-pump/src/test/java/org/lambico/data/BookTCDao.java Wed Feb 27
10:59:57 2013
+++ /lambico-pump/src/test/java/org/lambico/data/BookTCDao.java Mon Feb 18
15:12:50 2013
@@ -24,9 +24,8 @@
/**
* A DAO to be used for the tests M:N relationships.
- *
- * @author <a href="mailto:
michele...@seesaw.it">Michele Franzin</a>
- * @version $Revision$
+ *
+ * @author michele franzin <michele at
franzin.net>
*/
@Dao(entity = BookTC.class)
public interface BookTCDao extends GenericDao<BookTC, Long> {
=======================================
---
/lambico-spring-hibernate/src/test/java/org/lambico/spring/dao/hibernate/ManyToManyFixturesTest.java
Mon Feb 18 14:33:18 2013
+++
/lambico-spring-hibernate/src/test/java/org/lambico/spring/dao/hibernate/ManyToManyFixturesTest.java
Mon Feb 18 15:12:50 2013
@@ -15,7 +15,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.lambico.spring.dao.hibernate;
import org.lambico.spring.dao.hibernate.dao.AuthorTCDao;
@@ -29,9 +28,8 @@
/**
* Tests fixture load with M:N relationships
*
- * @author <a href="mailto:
michele...@seesaw.it">Michele Franzin</a>
+ * @author michele franzin <michele at
franzin.net>
* @author Jacopo Murador <jacopo.murador at
seesaw.it>
- * @version $Revision$
*/
public class ManyToManyFixturesTest extends BaseTest {
=======================================
---
/lambico-spring-hibernate/src/test/java/org/lambico/spring/dao/hibernate/dao/AuthorTCDao.java
Sat Feb 6 03:14:05 2010
+++
/lambico-spring-hibernate/src/test/java/org/lambico/spring/dao/hibernate/dao/AuthorTCDao.java
Mon Feb 18 15:12:50 2013
@@ -15,7 +15,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.lambico.spring.dao.hibernate.dao;
import org.lambico.spring.dao.hibernate.po.AuthorTC;
@@ -25,9 +24,8 @@
/**
* A DAO to be used for the tests M:N relationships.
- *
- * @author <a href="mailto:
michele...@seesaw.it">Michele Franzin</a>
- * @version $Revision$
+ *
+ * @author michele franzin <michele at
franzin.net>
*/
@Dao(entity = AuthorTC.class)
public interface AuthorTCDao extends GenericDao<AuthorTC, Long> {
=======================================
---
/lambico-spring-hibernate/src/test/java/org/lambico/spring/dao/hibernate/dao/BookTCDao.java
Sat Feb 6 03:14:05 2010
+++
/lambico-spring-hibernate/src/test/java/org/lambico/spring/dao/hibernate/dao/BookTCDao.java
Mon Feb 18 15:12:50 2013
@@ -15,7 +15,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.lambico.spring.dao.hibernate.dao;
import org.lambico.spring.dao.hibernate.po.BookTC;
@@ -25,9 +24,8 @@
/**
* A DAO to be used for the tests M:N relationships.
- *
- * @author <a href="mailto:
michele...@seesaw.it">Michele Franzin</a>
- * @version $Revision$
+ *
+ * @author michele franzin <michele at
franzin.net>
*/
@Dao(entity = BookTC.class)
public interface BookTCDao extends GenericDao<BookTC, Long> {
=======================================
---
/lambico-spring-hibernate/src/test/java/org/lambico/spring/dao/hibernate/po/AuthorTC.java
Sat Feb 6 03:14:05 2010
+++
/lambico-spring-hibernate/src/test/java/org/lambico/spring/dao/hibernate/po/AuthorTC.java
Mon Feb 18 15:12:50 2013
@@ -15,7 +15,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.lambico.spring.dao.hibernate.po;
import org.lambico.po.hibernate.EntityBase;
@@ -31,9 +30,8 @@
/**
* An persistent object to be used for the tests M:N relationships.
- *
- * @author <a href="mailto:
michele...@seesaw.it">Michele Franzin</a>
- * @version $Revision$
+ *
+ * @author michele franzin <michele at
franzin.net>
*/
@javax.persistence.Entity
@NamedQuery(name = "AuthorTC.findByName", query = "from AuthorTC where
name like ?")
=======================================
---
/lambico-spring-hibernate/src/test/java/org/lambico/spring/dao/hibernate/po/BookTC.java
Sat Feb 6 03:14:05 2010
+++
/lambico-spring-hibernate/src/test/java/org/lambico/spring/dao/hibernate/po/BookTC.java
Mon Feb 18 15:12:50 2013
@@ -15,7 +15,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.lambico.spring.dao.hibernate.po;
import org.lambico.po.hibernate.EntityBase;
@@ -29,9 +28,8 @@
/**
* An persistent object to be used for the tests M:N relationships.
- *
- * @author <a href="mailto:
michele...@seesaw.it">Michele Franzin</a>
- * @version $Revision$
+ *
+ * @author michele franzin <michele at
franzin.net>
*/
@javax.persistence.Entity
@NamedQuery(name = "BookTC.findByTitle", query = "from BookTC where title
like ?")
=======================================
---
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/junit4/package-info.java
Sun Feb 24 07:24:09 2013
+++
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/junit4/package-info.java
Mon Feb 18 15:12:50 2013
@@ -15,7 +15,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
/**
* Test classes implemented with Spring and Hibernate support using Junit4.
*
=======================================
--- /pom.xml Sun Feb 24 07:24:09 2013
+++ /pom.xml Mon Feb 18 15:12:50 2013
@@ -384,7 +384,13 @@
</contributor>
<contributor>
<name>Michele Franzin</name>
- <email>
mic...@franzin.net</email>
+ <email>
michele...@jugpadova.it</email>
+ <organization>SeeSaw</organization>
+ <organizationUrl>
http://www.seesaw.it</organizationUrl>
+ <roles>
+ <role>developer</role>
+ </roles>
+ <timezone>+1</timezone>
</contributor>
<contributor>
<name>Enrico Giurin</name>
==============================================================================
Revision: 1c1905a52fbd
Branch: default
Author: Michele Franzin <
michele...@gmail.com>
Date: Fri Feb 22 04:45:46 2013
Log: remove duplicated MailSenderMock
http://code.google.com/p/lambico/source/detail?r=1c1905a52fbd
Deleted:
/lambico-test/src/main/java/org/lambico/test/spring/MailSenderMock.java
Modified:
/lambico-test/pom.xml
=======================================
--- /lambico-test/src/main/java/org/lambico/test/spring/MailSenderMock.java
Thu Feb 28 09:37:27 2013
+++ /dev/null
@@ -1,58 +0,0 @@
-/**
- * Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
- *
- * This file is part of Lambico Test.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *
http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.lambico.test.spring;
-
-import javax.mail.internet.MimeMessage;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.mail.javamail.JavaMailSenderImpl;
-
-/**
- * Mock implementation of JavaMailSender for testing porpouse.
- *
- * @author Enrico Giurin
- * @author Lucio Benfante
- */
-public class MailSenderMock extends JavaMailSenderImpl {
-
- private static Logger logger =
LoggerFactory.getLogger(MailSenderMock.class);
-
- /**
- * {@inheritDoc}
- *
- * @param mimeMessages {@inheritDoc}
- * @param originalMessages {@inheritDoc}
- */
- @Override
- protected void doSend(final MimeMessage[] mimeMessages, final Object[]
originalMessages) {
- if (mimeMessages != null) {
- for (MimeMessage mimeMessage : mimeMessages) {
- try {
-
logger.info(mimeMessage.getContent().toString());
- } catch (Exception ex) {
- logger.error("Can't get message content", ex);
- }
- }
- }
- if (originalMessages != null) {
- for (Object o : originalMessages) {
-
logger.info(o.toString());
- }
- }
- }
-}
=======================================
--- /lambico-test/pom.xml Wed Feb 27 08:43:19 2013
+++ /lambico-test/pom.xml Fri Feb 22 04:45:46 2013
@@ -44,11 +44,6 @@
<artifactId>lambico-pump</artifactId>
</dependency>
<dependency>
- <groupId>javax.mail</groupId>
- <artifactId>mail</artifactId>
- <optional>true</optional>
- </dependency>
- <dependency>
<artifactId>hibernate-core</artifactId>
<groupId>org.hibernate</groupId>
</dependency>
==============================================================================
Revision: bd2751411931
Branch: default
Author: Michele Franzin <
michele...@gmail.com>
Date: Sun Feb 24 01:45:30 2013
Log: removed unused file (beanRefFactory_text.xml)
http://code.google.com/p/lambico/source/detail?r=bd2751411931
Deleted:
/lambico-spring-hibernate/src/test/resources/beanRefFactory_test.xml
=======================================
--- /lambico-spring-hibernate/src/test/resources/beanRefFactory_test.xml
Sat Feb 6 03:14:05 2010
+++ /dev/null
@@ -1,33 +0,0 @@
-<!--
-
- Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
-
- This file is part of Lambico Spring - Hibernate.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
-
http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
--->
-
-<!DOCTYPE beans PUBLIC "-//SPRING//DTD
BEAN//EN" "
http://www.springframework.org/dtd/spring-beans-2.0.dtd">
-<beans>
- <bean id="org.lambico.spring.dao.hibernate"
-
class="org.springframework.context.support.ClassPathXmlApplicationContext">
- <constructor-arg>
- <list>
-
<value>org/lambico/spring/dao/generic/genericDao.xml</value>
- <value>org/lambci/spring/applicationContextBase.xml</value>
- <value>applicationContext_test.xml</value>
- </list>
- </constructor-arg>
- </bean>
-</beans>
==============================================================================
Revision: 5c6cc14d26b9
Branch: default
Author: Michele Franzin <
michele...@gmail.com>
Date: Wed Feb 27 08:43:09 2013
Log: rename FixtureHelper -> YamlFixtureHelper
http://code.google.com/p/lambico/source/detail?r=5c6cc14d26b9
Added:
/lambico-pump/src/main/java/org/lambico/data/YamlFixtureHelper.java
/lambico-pump/src/test/java/org/lambico/data/YamlFixtureHelperTest.java
Deleted:
/lambico-pump/src/main/java/org/lambico/data/FixtureHelper.java
/lambico-pump/src/test/java/org/lambico/data/FixtureHelperTest.java
Modified:
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/DBTest.java
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/FixtureUtils.java
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/junit4/FixturesTestExecutionListener.java
=======================================
--- /dev/null
+++ /lambico-pump/src/main/java/org/lambico/data/YamlFixtureHelper.java Wed
Feb 27 08:43:09 2013
@@ -0,0 +1,197 @@
+/**
+ * Copyright (C) 2013 Lambico Team <
mic...@franzin.net>
+ *
+ * This file is part of Lambico Data Pump.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.lambico.data;
+
+import java.io.File;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.core.io.ClassPathResource;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.lambico.data.EngineFactory.EngineType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Yaml fixture load / dump helper
+ *
+ * @author michele franzin <michele at
franzin.net>
+ */
+public class YamlFixtureHelper {
+
+ private static Logger logger =
LoggerFactory.getLogger(YamlFixtureHelper.class);
+ private static final Pattern HEADER_MATCH =
Pattern.compile("^-\\s??(\\S*)\\s*?$",
+ Pattern.MULTILINE);
+ private static final Pattern LINE_MATCH = Pattern.compile("^(.+)$",
Pattern.MULTILINE);
+
+ private YamlFixtureHelper() {
+ }
+
+// /**
+// * Gets id of dao related to a model.
+// * <p/>
+// * *WARNING*: strong condition on the DAO id (entity_name+Dao) For
retriving a dao for an
+// * entity it's better something like:
+// * <code>
+// * DaoProvider daos = (DaoProvider)ctx.getBean(DAO_PROVIDER_ID);
+// * GenericDao dao = (GenericDao)daos.getDao(clazz);
+// * </code>
+// * <p/>
+// * The DAO_PROVIDER_ID usually is "daos".
+// *
+// * @param model The class of a model.
+// * @return The DAO id.
+// */
+// public static String getFixtureDaoId(final Class model) {
+// return StringUtils.uncapitalize(model.getSimpleName()) + "Dao";
+// }
+//
+// /**
+// * Gets id of dao related to a model.
+// * <p/>
+// * *WARNING*: strong condition on the DAO id (entity_name+Dao) For
retriving a dao for an
+// * entity it's better something like:
+// * <code>
+// * DaoProvider daos = (DaoProvider)ctx.getBean(DAO_PROVIDER_ID);
+// * GenericDao dao = (GenericDao)daos.getDao(clazz);
+// * </code>
+// * <p/>
+// * The DAO_PROVIDER_ID usually is "daos".
+// *
+// * @param model The class of a model.
+// * @return The business DAO id.
+// */
+// public static String getFixtureBusinessDaoId(final Class model) {
+// return StringUtils.uncapitalize(model.getSimpleName())
+ "BusinessDao";
+// }
+ /**
+ * Gets human readable name of a model.
+ *
+ * @param model The class of a model.
+ * @return The model name.
+ */
+ public static String getModelName(final Class model) {
+ return model.getSimpleName();
+ }
+
+ /**
+ * Load the fixtures.
+ *
+ * @param classpathResource dir relative path
+ * @param models The set of models.
+ * @return The model->values map of fixtures.
+ */
+ public static Map<Class, List> loadFixturesFromResource(final String
classpathResource,
+ final Set<Class> models) {
+ return loadFixturesFromResource(new
ClassPathResource(classpathResource), models);
+ }
+
+ /**
+ * Load the fixtures. Compose a unique fixture document (aliases are
document scoped)
+ *
+ * @param fixtureDir The directory where to search the fixtures.
+ * @param models The set of models.
+ * @return The model->values map of fixtures.
+ */
+ @SuppressWarnings("unchecked")
+ public static Map<Class, List> loadFixturesFromResource(final
ClassPathResource fixtureDir,
+ final Set<Class> models) {
+ // Mantiene l'ordine di inserimento
+ LinkedHashMap<Class, List> fixtures = new LinkedHashMap<Class,
List>(models.size());
+ Pump engine = EngineFactory.getEngine(EngineType.YAML);
+ StringBuilder sb = new StringBuilder();
+ for (Class model : models) {
+ InputStream stream = null;
+ String path = fixtureDir.getPath();
+ if (!path.endsWith(File.separator)) {
+ path += File.separatorChar;
+ }
+ String fixtureFileName = engine.getFixtureFileName(path,
model);
+ try {
+ ClassPathResource fixtureResource = new
ClassPathResource(fixtureFileName);
+ stream = fixtureResource.getInputStream();
+ String content = loadFixtureTextForClass(stream, model);
+ if (StringUtils.isNotBlank(content)) {
+ sb.append(content).append(IOUtils.LINE_SEPARATOR);
+ fixtures.put(model, new LinkedList());
+ } else {
+ logger.warn("No fixtures for " + getModelName(model)
+ " in the file '"
+ + fixtureFileName + "' ?");
+ }
+ } catch (FileNotFoundException e) {
+ logger.warn("Fixture file not found for " +
getModelName(model)
+ + ", did you created the file '" + fixtureFileName
+ "' ?");
+ } catch (IOException e) {
+ logger.error("Loading of fixtures failed for " +
getModelName(model), e);
+ } finally {
+ IOUtils.closeQuietly(stream);
+ }
+ }
+
+ logger.debug("### start of merged fixtures dump ###\n{}"
+ + "\n### end of merged fixtures dump ###", sb);
+
+ Iterable<Object> loaded = engine.load(sb.toString());
+ if (loaded.iterator().hasNext()) {
+ List objectsTree = (List) loaded.iterator().next();
+ if (objectsTree != null) {
+ for (Object modelFixtures : objectsTree) {
+ List objects = (List) modelFixtures;
+ if (objects != null && !objects.isEmpty()) {
+
fixtures.get(objects.get(0).getClass()).addAll(objects);
+ }
+ }
+ }
+ }
+ return fixtures;
+ }
+
+ /**
+ * Load the content of a fixture file <Class>.yml, indenting the whole
content
+ *
+ * @param stream The fixture file.
+ * @param model The model to load.
+ * @return The content of the fixture file.
+ * @throws IOException In case of error.
+ */
+ private static String loadFixtureTextForClass(final InputStream stream,
+ final Class model) throws IOException {
+ String fixtureString = IOUtils.toString(stream, "UTF-8").trim();
+ if (StringUtils.isBlank(fixtureString)) {
+ return StringUtils.EMPTY;
+ }
+ // Add fixture class into header
+ Matcher matcher = HEADER_MATCH.matcher(fixtureString);
+ // Il replace del $ serve alla regex nel caso di inner classes
+ fixtureString = matcher.replaceAll("- $1 !!" +
model.getName().replace("$", "\\$"));
+ // Indent lines
+ matcher = LINE_MATCH.matcher(fixtureString);
+ fixtureString = matcher.replaceAll(" $1");
+ // aggiungo l'header per ottenere una lista di oggetti <Class>
+ return "-" + IOUtils.LINE_SEPARATOR + fixtureString;
+ }
+}
=======================================
--- /dev/null
+++ /lambico-pump/src/test/java/org/lambico/data/YamlFixtureHelperTest.java
Wed Feb 27 08:43:09 2013
@@ -0,0 +1,126 @@
+/**
+ * Copyright (C) 2013 Lambico Team <
mic...@franzin.net>
+ *
+ * This file is part of Lambico Data Pump.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.lambico.data;
+
+import java.math.BigDecimal;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import junit.framework.TestCase;
+import static junit.framework.TestCase.assertEquals;
+import static junit.framework.TestCase.assertNotNull;
+import org.springframework.util.CollectionUtils;
+
+/**
+ * @author michele franzin <michele at
franzin.net>
+ */
+public class YamlFixtureHelperTest extends TestCase {
+
+ private DemoBean[] expected;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ expected = new DemoBean[5];
+ expected[0] = new DemoBean("first one", new Long(356));
+ expected[1] = new DemoBean("Demo 1", new Long(6789));
+ expected[2] = new DemoBean("àèéìòù", new Long(-980000));
+ expected[3] = new DemoBean("Demo3", new Long(98000));
+ expected[4] = new DemoBean("Demo#2", new Long(-9800));
+ }
+
+ public void testShouldNotFailWrongFixtureDir() {
+ Set<Class> models = getClassSet(DemoBean.class);
+ Map<Class, List> objects =
YamlFixtureHelper.loadFixturesFromResource("nonExistant", models);
+ assertTrue("Le fixture non sono vuote", objects.isEmpty());
+ }
+
+ public void testShouldNotFailIfMissingFixtureFile() {
+ Set<Class> models = getClassSet(BigDecimal.class);
+ Map<Class, List> objects =
YamlFixtureHelper.loadFixturesFromResource("fixtures", models);
+ assertTrue("Le fixture non sono vuote", objects.isEmpty());
+ }
+
+ public void testShouldNotFailWhenTrailingSlashPresent() throws
Exception {
+ Set<Class> models = getClassSet(DemoBean.class);
+ Map<Class, List> objects =
YamlFixtureHelper.loadFixturesFromResource("fixtures/", models);
+ assertNotNull("Non ha ritornato la mappa di fixtures", objects);
+ }
+
+ public void testShouldNotFailIfNoFile() {
+ Set<Class> models = new LinkedHashSet<Class>();
+ Map<Class, List> objects =
YamlFixtureHelper.loadFixturesFromResource("emptyDir", models);
+ assertTrue("Le fixture non sono vuote", objects.isEmpty());
+ }
+
+ public void testShouldNotFailIfEmptyFile() {
+ Set<Class> models = getClassSet(DemoBean.class);
+ Map<Class, List> objects =
YamlFixtureHelper.loadFixturesFromResource("fixtures/empty", models);
+ assertEquals("Non carica tutti i beans", 1, objects.size());
+ assertTrue("Le fixture non sono vuote",
objects.get(DemoBean.class).isEmpty());
+ }
+
+ public void testBeanLoading() {
+ Set<Class> models = getClassSet(DemoBean.class);
+ Map<Class, List> objects =
YamlFixtureHelper.loadFixturesFromResource("fixtures", models);
+ assertNotNull("Non ha ritornato la mappa di fixtures", objects);
+ assertEquals("Non carica tutti i beans", 1, objects.size());
+ assertTrue("Non crea istanze di " +
DemoBean.class.getCanonicalName(), objects.containsKey(
+ DemoBean.class));
+ @SuppressWarnings("unchecked")
+ List<DemoBean> result = objects.get(DemoBean.class);
+ assertEquals("Non carica tutti i beans", 5, result.size());
+ for (int i = 0; i < 5; i++) {
+ assertEquals("Non ha caricato correttamente il bean numero " +
i, expected[i], result.
+ get(i));
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testBookLoading() {
+ Set<Class> models = getClassSet(BookTC.class, AuthorTC.class);
+ Map<Class, List> objects =
YamlFixtureHelper.loadFixturesFromResource("fixtures", models);
+ assertNotNull("Non ha ritornato la mappa di fixtures", objects);
+ assertEquals(2, objects.size());
+ assertEquals(3, objects.get(BookTC.class).size());
+ assertEquals(4, objects.get(AuthorTC.class).size());
+ assertBookAuthorsAreIdentical(objects.get(BookTC.class),
objects.get(AuthorTC.class));
+ }
+
+ public void testFixtureMerge() {
+ Set<Class> models = getClassSet(BookTC.class, AuthorTC.class);
+ Map<Class, List> objects =
YamlFixtureHelper.loadFixturesFromResource("fixtures", models);
+ AuthorTC author = (AuthorTC) objects.get(AuthorTC.class).get(3);
+ assertEquals("john", author.getName());
+ assertEquals("Java manual", author.getBooks().get(0).getTitle());
+ }
+
+ private void assertBookAuthorsAreIdentical(List<BookTC> books,
List<AuthorTC> authors) {
+ for (BookTC book : books) {
+ for (AuthorTC author : book.getAuthors()) {
+ assertTrue("The book author is not in the author array",
authors.contains(author));
+ }
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private LinkedHashSet<Class> getClassSet(final Class... models) {
+ return new
LinkedHashSet<Class>(CollectionUtils.arrayToList(models));
+ }
+}
=======================================
--- /lambico-pump/src/main/java/org/lambico/data/FixtureHelper.java Mon Feb
18 15:12:50 2013
+++ /dev/null
@@ -1,197 +0,0 @@
-/**
- * Copyright (C) 2013 Lambico Team <
mic...@franzin.net>
- *
- * This file is part of Lambico Data Pump.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *
http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.lambico.data;
-
-import java.io.File;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.StringUtils;
-import org.springframework.core.io.ClassPathResource;
-
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import org.lambico.data.EngineFactory.EngineType;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Fixture load / dump facility
- *
- * @author michele franzin <michele at
franzin.net>
- */
-public class FixtureHelper {
-
- private static Logger logger =
LoggerFactory.getLogger(FixtureHelper.class);
- private static final Pattern HEADER_MATCH =
Pattern.compile("^-\\s??(\\S*)\\s*?$",
- Pattern.MULTILINE);
- private static final Pattern LINE_MATCH = Pattern.compile("^(.+)$",
Pattern.MULTILINE);
-
- private FixtureHelper() {
- }
-
-// /**
-// * Gets id of dao related to a model.
-// * <p/>
-// * *WARNING*: strong condition on the DAO id (entity_name+Dao) For
retriving a dao for an
-// * entity it's better something like:
-// * <code>
-// * DaoProvider daos = (DaoProvider)ctx.getBean(DAO_PROVIDER_ID);
-// * GenericDao dao = (GenericDao)daos.getDao(clazz);
-// * </code>
-// * <p/>
-// * The DAO_PROVIDER_ID usually is "daos".
-// *
-// * @param model The class of a model.
-// * @return The DAO id.
-// */
-// public static String getFixtureDaoId(final Class model) {
-// return StringUtils.uncapitalize(model.getSimpleName()) + "Dao";
-// }
-//
-// /**
-// * Gets id of dao related to a model.
-// * <p/>
-// * *WARNING*: strong condition on the DAO id (entity_name+Dao) For
retriving a dao for an
-// * entity it's better something like:
-// * <code>
-// * DaoProvider daos = (DaoProvider)ctx.getBean(DAO_PROVIDER_ID);
-// * GenericDao dao = (GenericDao)daos.getDao(clazz);
-// * </code>
-// * <p/>
-// * The DAO_PROVIDER_ID usually is "daos".
-// *
-// * @param model The class of a model.
-// * @return The business DAO id.
-// */
-// public static String getFixtureBusinessDaoId(final Class model) {
-// return StringUtils.uncapitalize(model.getSimpleName())
+ "BusinessDao";
-// }
- /**
- * Gets human readable name of a model.
- *
- * @param model The class of a model.
- * @return The model name.
- */
- public static String getModelName(final Class model) {
- return model.getSimpleName();
- }
-
- /**
- * Load the fixtures.
- *
- * @param classpathResource dir relative path
- * @param models The set of models.
- * @return The model->values map of fixtures.
- */
- public static Map<Class, List> loadFixturesFromResource(final String
classpathResource,
- final Set<Class> models) {
- return loadFixturesFromResource(new
ClassPathResource(classpathResource), models);
- }
-
- /**
- * Load the fixtures. Compose a unique fixture document (aliases are
document scoped)
- *
- * @param fixtureDir The directory where to search the fixtures.
- * @param models The set of models.
- * @return The model->values map of fixtures.
- */
- @SuppressWarnings("unchecked")
- public static Map<Class, List> loadFixturesFromResource(final
ClassPathResource fixtureDir,
- final Set<Class> models) {
- // Mantiene l'ordine di inserimento
- LinkedHashMap<Class, List> fixtures = new LinkedHashMap<Class,
List>(models.size());
- Pump engine = EngineFactory.getEngine(EngineType.YAML);
- StringBuilder sb = new StringBuilder();
- for (Class model : models) {
- InputStream stream = null;
- String path = fixtureDir.getPath();
- if (!path.endsWith(File.separator)) {
- path += File.separatorChar;
- }
- String fixtureFileName = engine.getFixtureFileName(path,
model);
- try {
- ClassPathResource fixtureResource = new
ClassPathResource(fixtureFileName);
- stream = fixtureResource.getInputStream();
- String content = loadFixtureTextForClass(stream, model);
- if (StringUtils.isNotBlank(content)) {
- sb.append(content).append(IOUtils.LINE_SEPARATOR);
- fixtures.put(model, new LinkedList());
- } else {
- logger.warn("No fixtures for " + getModelName(model)
+ " in the file '"
- + fixtureFileName + "' ?");
- }
- } catch (FileNotFoundException e) {
- logger.warn("Fixture file not found for " +
getModelName(model)
- + ", did you created the file '" + fixtureFileName
+ "' ?");
- } catch (IOException e) {
- logger.error("Loading of fixtures failed for " +
getModelName(model), e);
- } finally {
- IOUtils.closeQuietly(stream);
- }
- }
-
- logger.debug("### start of merged fixtures dump ###\n{}"
- + "\n### end of merged fixtures dump ###", sb);
-
- Iterable<Object> loaded = engine.load(sb.toString());
- if (loaded.iterator().hasNext()) {
- List objectsTree = (List) loaded.iterator().next();
- if (objectsTree != null) {
- for (Object modelFixtures : objectsTree) {
- List objects = (List) modelFixtures;
- if (objects != null && !objects.isEmpty()) {
-
fixtures.get(objects.get(0).getClass()).addAll(objects);
- }
- }
- }
- }
- return fixtures;
- }
-
- /**
- * Load the content of a fixture file <Class>.yml, indenting the whole
content
- *
- * @param stream The fixture file.
- * @param model The model to load.
- * @return The content of the fixture file.
- * @throws IOException In case of error.
- */
- private static String loadFixtureTextForClass(final InputStream stream,
- final Class model) throws IOException {
- String fixtureString = IOUtils.toString(stream, "UTF-8").trim();
- if (StringUtils.isBlank(fixtureString)) {
- return StringUtils.EMPTY;
- }
- // Add fixture class into header
- Matcher matcher = HEADER_MATCH.matcher(fixtureString);
- // Il replace del $ serve alla regex nel caso di inner classes
- fixtureString = matcher.replaceAll("- $1 !!" +
model.getName().replace("$", "\\$"));
- // Indent lines
- matcher = LINE_MATCH.matcher(fixtureString);
- fixtureString = matcher.replaceAll(" $1");
- // aggiungo l'header per ottenere una lista di oggetti <Class>
- return "-" + IOUtils.LINE_SEPARATOR + fixtureString;
- }
-}
=======================================
--- /lambico-pump/src/test/java/org/lambico/data/FixtureHelperTest.java Wed
Feb 27 08:43:19 2013
+++ /dev/null
@@ -1,126 +0,0 @@
-/**
- * Copyright (C) 2013 Lambico Team <
mic...@franzin.net>
- *
- * This file is part of Lambico Data Pump.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *
http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.lambico.data;
-
-import java.math.BigDecimal;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import junit.framework.TestCase;
-import static junit.framework.TestCase.assertEquals;
-import static junit.framework.TestCase.assertNotNull;
-import org.springframework.util.CollectionUtils;
-
-/**
- * @author michele franzin <michele at
franzin.net>
- */
-public class FixtureHelperTest extends TestCase {
-
- private DemoBean[] expected;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- expected = new DemoBean[5];
- expected[0] = new DemoBean("first one", new Long(356));
- expected[1] = new DemoBean("Demo 1", new Long(6789));
- expected[2] = new DemoBean("àèéìòù", new Long(-980000));
- expected[3] = new DemoBean("Demo3", new Long(98000));
- expected[4] = new DemoBean("Demo#2", new Long(-9800));
- }
-
- public void testShouldNotFailWrongFixtureDir() {
- Set<Class> models = getClassSet(DemoBean.class);
- Map<Class, List> objects =
FixtureHelper.loadFixturesFromResource("nonExistant", models);
- assertTrue("Le fixture non sono vuote", objects.isEmpty());
- }
-
- public void testShouldNotFailIfMissingFixtureFile() {
- Set<Class> models = getClassSet(BigDecimal.class);
- Map<Class, List> objects =
FixtureHelper.loadFixturesFromResource("fixtures", models);
- assertTrue("Le fixture non sono vuote", objects.isEmpty());
- }
-
- public void testShouldNotFailWhenTrailingSlashPresent() throws
Exception {
- Set<Class> models = getClassSet(DemoBean.class);
- Map<Class, List> objects =
FixtureHelper.loadFixturesFromResource("fixtures/", models);
- assertNotNull("Non ha ritornato la mappa di fixtures", objects);
- }
-
- public void testShouldNotFailIfNoFile() {
- Set<Class> models = new LinkedHashSet<Class>();
- Map<Class, List> objects =
FixtureHelper.loadFixturesFromResource("emptyDir", models);
- assertTrue("Le fixture non sono vuote", objects.isEmpty());
- }
-
- public void testShouldNotFailIfEmptyFile() {
- Set<Class> models = getClassSet(DemoBean.class);
- Map<Class, List> objects =
FixtureHelper.loadFixturesFromResource("fixtures/empty", models);
- assertEquals("Non carica tutti i beans", 1, objects.size());
- assertTrue("Le fixture non sono vuote",
objects.get(DemoBean.class).isEmpty());
- }
-
- public void testBeanLoading() {
- Set<Class> models = getClassSet(DemoBean.class);
- Map<Class, List> objects =
FixtureHelper.loadFixturesFromResource("fixtures", models);
- assertNotNull("Non ha ritornato la mappa di fixtures", objects);
- assertEquals("Non carica tutti i beans", 1, objects.size());
- assertTrue("Non crea istanze di " +
DemoBean.class.getCanonicalName(), objects.containsKey(
- DemoBean.class));
- @SuppressWarnings("unchecked")
- List<DemoBean> result = objects.get(DemoBean.class);
- assertEquals("Non carica tutti i beans", 5, result.size());
- for (int i = 0; i < 5; i++) {
- assertEquals("Non ha caricato correttamente il bean numero " +
i, expected[i], result.
- get(i));
- }
- }
-
- @SuppressWarnings("unchecked")
- public void testBookLoading() {
- Set<Class> models = getClassSet(BookTC.class, AuthorTC.class);
- Map<Class, List> objects =
FixtureHelper.loadFixturesFromResource("fixtures", models);
- assertNotNull("Non ha ritornato la mappa di fixtures", objects);
- assertEquals(2, objects.size());
- assertEquals(3, objects.get(BookTC.class).size());
- assertEquals(4, objects.get(AuthorTC.class).size());
- assertBookAuthorsAreIdentical(objects.get(BookTC.class),
objects.get(AuthorTC.class));
- }
-
- public void testFixtureMerge() {
- Set<Class> models = getClassSet(BookTC.class, AuthorTC.class);
- Map<Class, List> objects =
FixtureHelper.loadFixturesFromResource("fixtures", models);
- AuthorTC author = (AuthorTC) objects.get(AuthorTC.class).get(3);
- assertEquals("john", author.getName());
- assertEquals("Java manual", author.getBooks().get(0).getTitle());
- }
-
- private void assertBookAuthorsAreIdentical(List<BookTC> books,
List<AuthorTC> authors) {
- for (BookTC book : books) {
- for (AuthorTC author : book.getAuthors()) {
- assertTrue("The book author is not in the author array",
authors.contains(author));
- }
- }
- }
-
- @SuppressWarnings("unchecked")
- private LinkedHashSet<Class> getClassSet(final Class... models) {
- return new
LinkedHashSet<Class>(CollectionUtils.arrayToList(models));
- }
-}
=======================================
---
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/DBTest.java
Sun Feb 24 07:24:09 2013
+++
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/DBTest.java
Wed Feb 27 08:43:09 2013
@@ -28,7 +28,7 @@
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.lambico.dao.generic.GenericDaoBase;
-import org.lambico.data.FixtureHelper;
+import org.lambico.data.YamlFixtureHelper;
import org.lambico.test.spring.EnhancedTestCase;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.ResourceLoader;
@@ -149,7 +149,7 @@
Set<Class> fixtureClasses = getFixtureClassSet();
if (fixtureClasses != null && fixtureClasses.size() > 0) {
try {
- fixtures = FixtureHelper.loadFixturesFromResource(
+ fixtures = YamlFixtureHelper.loadFixturesFromResource(
(ClassPathResource)
applicationContext.getResource(
ResourceLoader.CLASSPATH_URL_PREFIX
+ "/fixtures/"), fixtureClasses);
logger.info("Loaded fixtures for classes "
=======================================
---
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/FixtureUtils.java
Sun Feb 24 07:24:09 2013
+++
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/FixtureUtils.java
Wed Feb 27 08:43:09 2013
@@ -21,7 +21,7 @@
import org.hibernate.cfg.DefaultComponentSafeNamingStrategy;
import org.lambico.dao.generic.GenericDaoBase;
import org.lambico.dao.spring.hibernate.GenericDaoHibernateSupport;
-import org.lambico.data.FixtureHelper;
+import org.lambico.data.YamlFixtureHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.orm.hibernate3.HibernateTemplate;
@@ -45,10 +45,10 @@
*/
public static void populateDbForModel(final Class model, final List
fixtures,
final GenericDaoBase dao) {
- logger.debug("Populating table for {}",
FixtureHelper.getModelName(model));
+ logger.debug("Populating table for {}",
YamlFixtureHelper.getModelName(model));
if (fixtures == null) {
logger.warn("No data for {}, did you created the fixture
file?",
- FixtureHelper.getModelName(model));
+ YamlFixtureHelper.getModelName(model));
return;
}
final HibernateTemplate template = ((GenericDaoHibernateSupport)
dao).getHibernateTemplate();
@@ -59,7 +59,7 @@
template.flush();
template.clear();
} catch (Exception e) {
- logger.error("Error populating rows in {} table",
FixtureHelper.getModelName(model), e);
+ logger.error("Error populating rows in {} table",
YamlFixtureHelper.getModelName(model), e);
}
}
@@ -70,7 +70,7 @@
* @param dao The DAO tp use.
*/
public static void eraseDbForModel(final Class model, final
GenericDaoBase dao) {
- logger.debug("Erasing table for {}",
FixtureHelper.getModelName(model));
+ logger.debug("Erasing table for {}",
YamlFixtureHelper.getModelName(model));
try {
if (dao == null) {
throw new IllegalArgumentException("Dao associated to " +
model.getName()
@@ -82,7 +82,7 @@
template.bulkUpdate("DELETE FROM "
+
DefaultComponentSafeNamingStrategy.INSTANCE.tableName(model.getSimpleName()));
} catch (Exception e) {
- logger.error("Error deleting rows in {} table",
FixtureHelper.getModelName(model), e);
+ logger.error("Error deleting rows in {} table",
YamlFixtureHelper.getModelName(model), e);
}
}
}
=======================================
---
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/junit4/FixturesTestExecutionListener.java
Sun Feb 24 07:24:09 2013
+++
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/junit4/FixturesTestExecutionListener.java
Wed Feb 27 08:43:09 2013
@@ -24,7 +24,7 @@
import java.util.Set;
import org.lambico.dao.generic.GenericDaoBase;
import org.lambico.dao.spring.hibernate.GenericDaoHibernateSupport;
-import org.lambico.data.FixtureHelper;
+import org.lambico.data.YamlFixtureHelper;
import org.lambico.po.hibernate.Entity;
import org.lambico.test.spring.hibernate.DaoUtils;
import org.lambico.test.spring.hibernate.junit4.FixtureSet.LoadMode;
@@ -122,7 +122,7 @@
try {
ClassPathResource path = (ClassPathResource)
testContext.getApplicationContext().
getResource(ResourceLoader.CLASSPATH_URL_PREFIX +
config.getRootFolder());
- fixtures.putAll(FixtureHelper.loadFixturesFromResource(path,
classes));
+
fixtures.putAll(YamlFixtureHelper.loadFixturesFromResource(path, classes));
if (logger.isInfoEnabled()) {
HashMap<String, Integer> map = new HashMap<String,
Integer>(fixtures.size());
for (Class model : classes) {
==============================================================================
Revision: 8e0b7e976d77
Branch: default
Author: lucio.benfante <
lucio.b...@gmail.com>
Date: Wed Mar 13 10:53:54 2013
Log: Merged Franzin's clone
http://code.google.com/p/lambico/source/detail?r=8e0b7e976d77
Deleted:
/lambico-spring-hibernate/src/test/resources/beanRefFactory_test.xml
/lambico-test/src/main/java/org/lambico/test/spring/MailSenderMock.java
/lambico-test/src/main/java/org/lambico/test/spring/Utils.java
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/FixtureHelper.java
/lambico-test/src/test/java/org/lambico/test/spring/hibernate/AuthorTC.java
/lambico-test/src/test/java/org/lambico/test/spring/hibernate/AuthorTCDao.java
/lambico-test/src/test/java/org/lambico/test/spring/hibernate/BookTC.java
/lambico-test/src/test/java/org/lambico/test/spring/hibernate/BookTCDao.java
/lambico-test/src/test/java/org/lambico/test/spring/hibernate/DemoBean.java
/lambico-test/src/test/java/org/lambico/test/spring/hibernate/FixtureHelperTest.java
/lambico-test/src/test/java/org/lambico/test/spring/hibernate/UtilsTest.java
/lambico-test/src/test/resources/fixtures/AuthorTC.yml
/lambico-test/src/test/resources/fixtures/BookTC.yml
/lambico-test/src/test/resources/fixtures/DemoBean.yml
/lambico-test/src/test/resources/fixtures/EntityTC.yml
/lambico-test/src/test/resources/fixtures/String.yml
/lambico-test/src/test/resources/testdata/UTF8WithPreamble.txt
/lambico-test/src/test/resources/testdata/UTF8WithoutPreamble.txt
Modified:
/.hgignore
/lambico-spring-hibernate/pom.xml
/lambico-spring-hibernate/src/main/java/org/lambico/spring/dao/hibernate/HibernateGenericDaoImpl.java
/lambico-spring/pom.xml
/pom.xml
=======================================
--- /lambico-spring-hibernate/src/test/resources/beanRefFactory_test.xml
Sat Feb 6 03:14:05 2010
+++ /dev/null
@@ -1,33 +0,0 @@
-<!--
-
- Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
-
- This file is part of Lambico Spring - Hibernate.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
-
http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
--->
-
-<!DOCTYPE beans PUBLIC "-//SPRING//DTD
BEAN//EN" "
http://www.springframework.org/dtd/spring-beans-2.0.dtd">
-<beans>
- <bean id="org.lambico.spring.dao.hibernate"
-
class="org.springframework.context.support.ClassPathXmlApplicationContext">
- <constructor-arg>
- <list>
-
<value>org/lambico/spring/dao/generic/genericDao.xml</value>
- <value>org/lambci/spring/applicationContextBase.xml</value>
- <value>applicationContext_test.xml</value>
- </list>
- </constructor-arg>
- </bean>
-</beans>
=======================================
--- /lambico-test/src/main/java/org/lambico/test/spring/MailSenderMock.java
Tue Dec 13 13:34:32 2011
+++ /dev/null
@@ -1,60 +0,0 @@
-/**
- * Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
- *
- * This file is part of Lambico Test.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *
http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.lambico.test.spring;
-
-import javax.mail.internet.MimeMessage;
-import org.apache.log4j.Logger;
-import org.springframework.mail.javamail.JavaMailSenderImpl;
-
-/**
- * Mock implementation of JavaMailSender for test porpouse.
- *
- * @author Enrico Giurin
- * @author Lucio Benfante
- * @version $Revision$
- */
-public class MailSenderMock extends JavaMailSenderImpl {
-
- /** The logger for this class. */
- private static Logger logger = Logger.getLogger(
- MailSenderMock.class);
-
- /**
- * {@inheritDoc}
- *
- * @param mimeMessages {@inheritDoc}
- * @param originalMessages {@inheritDoc}
- */
- @Override
- protected void doSend(final MimeMessage[] mimeMessages, final Object[]
originalMessages) {
- if (mimeMessages != null) {
- for (MimeMessage mimeMessage : mimeMessages) {
- try {
-
logger.info(mimeMessage.getContent());
- } catch (Exception ex) {
- logger.error("Can't get message content", ex);
- }
- }
- }
- if (originalMessages != null) {
- for (Object o : originalMessages) {
-
logger.info(o);
- }
- }
- }
-}
=======================================
--- /lambico-test/src/main/java/org/lambico/test/spring/Utils.java Tue Dec
13 13:34:32 2011
+++ /dev/null
@@ -1,314 +0,0 @@
-/**
- * Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
- *
- * This file is part of Lambico Test.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *
http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.lambico.test.spring;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.ArrayUtils;
-import org.apache.log4j.Logger;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.core.io.Resource;
-
-/**
- * Some utility methods.
- *
- * @author Paolo Dona
paolo...@seesaw.it
- * @author Michele Franzin
paolo...@seesaw.it
- * @author Andrea Nasato <mailto:
andrea...@jugpadova.it/>
- */
-public class Utils {
-
- /** The logger for this class. */
- private static Logger logger = Logger.getLogger(Utils.class);
- /** The UTF8 preamble. */
- private static final byte[] UTF8_PREAMBLE = new byte[]{(byte) 0xEF,
(byte) 0xBB, (byte) 0xBF};
- /** The UTF8 Unicode preamble. */
- private static final String UTF8_UNICODE_PREAMBLE = "";
-
- /**
- * A default protected constructor.
- */
- protected Utils() {
- }
-
- /**
- * Converts a map in a list of name/value pairs.
- *
- * @param map The map.
- * @return A list of name/value pairs (name=value).
- */
- @SuppressWarnings(value = "unchecked")
- public static List<String> convertToNameValueList(final Map map) {
- return convertToNameValueList(map, false);
- }
-
- /**
- * Converts a map in a list of name/value pairs.
- *
- * @param map The map.
- * @param urlEncode if true, encode the values as URLs.
- * @return A list of name/value pairs (name=value).
- */
- @SuppressWarnings(value = "unchecked")
- public static List<String> convertToNameValueList(final Map map, final
boolean urlEncode) {
- List<String> result = new ArrayList<String>();
- for (String key : (Iterable<String>) map.keySet()) {
- Object tmp = map.get(key);
- if (tmp instanceof String[]) {
- String[] values = (String[]) tmp;
- for (String value : values) {
- if (urlEncode) {
- try {
- result.add(key + "="
- +
java.net.URLEncoder.encode(value, "UTF-8"));
- } catch (UnsupportedEncodingException ex) {
- logger.warn("Your OS doesn't support UTF-8, so
we can encode",
- ex);
- result.add(key + "=" + value);
- }
- } else {
- result.add(key + "=" + value);
- }
- }
- } else if (tmp instanceof String) {
- String value = (String) tmp;
- if (urlEncode) {
- try {
- result.add(key + "="
- +
java.net.URLEncoder.encode(value, "UTF-8"));
- } catch (UnsupportedEncodingException ex) {
- logger.warn("Your OS doesn't support UTF-8, so we
can encode",
- ex);
- result.add(key + "=" + value);
- }
- } else {
- result.add(key + "=" + value);
- }
- }
- }
- return result;
- }
-
- /**
- * Loads a binary file from the classpath.
- *
- * @param classpathResource The resource path.
- * @return The content of the classpath resource.
- */
- public static byte[] loadBinary(final String classpathResource) {
- return loadBinary(new ClassPathResource(classpathResource));
- }
-
- /**
- * Loads a binary file from the classpath.
- *
- * @param classpathResource The resource path.
- * @return The content of the classpath resource.
- */
- public static byte[] loadBinary(final Resource classpathResource) {
- InputStream stream = null;
- try {
- stream = classpathResource.getInputStream();
- return unsafeLoadBinary(stream);
- } catch (IOException e) {
- throw new RuntimeException("Impossibile caricare la risorsa
binaria '"
- + classpathResource.getDescription() + "' dal
classpath.");
- } finally {
- IOUtils.closeQuietly(stream);
- }
- }
-
- /**
- * Loads a binary file from a stream.
- *
- * @param stream The stream from where to load. It is open,
- * and it won't be closed by this method.
- * @return The content of the classpath resource.
- * @throws IOException In case of error.
- */
- protected static byte[] unsafeLoadBinary(final InputStream stream)
throws IOException {
- return IOUtils.toByteArray(stream);
- }
-
- /**
- * Loads a text file from the classpath.
- * NB: UTF-8 header are removed!
- *
- * @param classpathResource The resource path.
- * @return The content of the classpath resource.
- */
- public static String loadString(final String classpathResource) {
- return loadString(new ClassPathResource(classpathResource));
- }
-
- /**
- * Loads a text file from the classpath.
- * NB: UTF-8 header are removed!
- *
- * @param classpathResource The resource path.
- * @return The content of the classpath resource.
- */
- public static String loadString(final Resource classpathResource) {
- InputStream stream = null;
- try {
- stream = classpathResource.getInputStream();
- return unsafeLoadString(stream);
- } catch (IOException e) {
- throw new RuntimeException("Impossibile caricare la risorsa
testuale '"
- + classpathResource.getDescription() + "' dal
classpath.");
- } finally {
- IOUtils.closeQuietly(stream);
- }
- }
-
- /**
- * Loads a text file from a stream.
- *
- * @param stream The stream from where to load. It is open,
- * and it won't be closed by this method.
- * @return The content of the classpath resource.
- * @throws IOException In case of error.
- */
- protected static String unsafeLoadString(final InputStream stream)
throws IOException {
- byte[] byteResult =
- IOUtils.toByteArray(stream);
- return stripUTF8preamble(new String(byteResult, "UTF-8"));
- }
-
- /**
- * Strips the UTF8 preamble, if present.
- *
- * NB: the conversion to byte array, and a following strip won't work.
The reason is that:
- * <code>new String(UTF8_PREAMBLE).getBytes() != UTF8_PREAMBLE</code>;
- *
- * <a
href="
http://mail.python.org/pipermail/python-list/2004-February/250798.html">Here</a>
- * an explanation.
- *
- * @param s The string to strip.
- * @return The string without the UTF8 preamble.
- * @throws UnsupportedEncodingException If the UTF-8 encoding is not
supported.
- */
- public static String stripUTF8preamble(final String s) throws
UnsupportedEncodingException {
- if (hasUTF8preamble(s)) {
- logger.debug("Rimosso header UTF-8 dalla stringa");
- return s.substring(1);
- }
- return s;
- }
-
- /**
- * Strips the UTF8 preamble, if present.
- *
- * @param b The array of bytes (characters).
- * @return The stripped array.
- */
- public static byte[] stripUTF8preamble(final byte[] b) {
- byte[] result = null;
- if (hasUTF8preamble(b)) {
- logger.debug("Rimosso header UTF-8 dall'array");
- result = ArrayUtils.subarray(b, UTF8_PREAMBLE.length,
b.length);
- }
- return result;
- }
-
- /**
- * Checks if the array starts with the UTF-8 preamble.
- *
- * @param b The array to inspect.
- * @return true if the array starts with the UTF-8 preamble.
- */
- public static boolean hasUTF8preamble(final byte[] b) {
- return b[0] == UTF8_PREAMBLE[0] && b[1] == UTF8_PREAMBLE[1]
- && b[2] == UTF8_PREAMBLE[2];
- }
-
- /**
- * Checks if the string starts with the UTF-8 preamble.
- *
- * @param s The string to inspect.
- * @return true if the string starts with the UTF-8 preamble.
- */
- public static boolean hasUTF8preamble(final String s) {
- return s.startsWith(UTF8_UNICODE_PREAMBLE);
- }
-
- /**
- * Return an array containing all the substrings of
- * <code>camelString</code>, according to this rule: divide
<code>camelString</code>
- * into tokens with every token starting from a capital letter to
another.
- *
- * Some examples:
- * <ol>
- * <li>'MyCamelString' gives: {my,camel,string}</li>
- * <li>'myFantasticCamelString' gives:
{my,fantastic,camel,string}</li>
- * <li>'MYCAMELSTRING' gives: {m,y,c,a,m,e,l,s,t,r,i,n,g}</li>
- * </ol>
- *
- * @param camelString The string to uncamelize.
- * @return The string uncamelized.
- */
- public static String[] uncamelize(final String camelString) {
-
- if (camelString == null || camelString.trim().equals("")) {
- throw new IllegalArgumentException("camelString cannot be null
or empty");
- }
- List<Integer> idxList = new ArrayList<Integer>();
- List<String> strList = new ArrayList<String>();
-
- //\p{Lu} is the unicode pattern for capital letters
- Pattern p = Pattern.compile("\\p{Lu}");
- Matcher m = p.matcher(camelString);
-
- //find all occurences of an uppercase letter and put their
position on a list
- while (m.find()) {
- idxList.add(m.start());
- }
-
- // no upper case found: we return the entire word
- if (idxList.size() == 0) {
- return new String[]{camelString};
- }
-
- Integer[] idx = idxList.toArray(new Integer[idxList.size() - 1]);
-
- for (int i = 0; i < idx.length; i++) {
-
- //if the first character of camelString is lower case,
- //substring from 0 to index[1]
- if (i == 0 && idx[i] > 0) {
- strList.add(camelString.substring(0,
idx[i]).toLowerCase());
- }
-
- //the last part of the word hasn't got an end guard
- if (i == idx.length - 1) {
- strList.add(camelString.substring(idx[i],
camelString.length()).toLowerCase());
- } else {
- strList.add(camelString.substring(idx[i], idx[i +
1]).toLowerCase());
- }
- }
-
- return strList.toArray(new String[strList.size() - 1]);
- }
-}
=======================================
---
/lambico-test/src/main/java/org/lambico/test/spring/hibernate/FixtureHelper.java
Tue Dec 13 13:34:32 2011
+++ /dev/null
@@ -1,293 +0,0 @@
-/**
- * Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
- *
- * This file is part of Lambico Test.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *
http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.lambico.test.spring.hibernate;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.ArrayUtils;
-import org.apache.commons.lang.StringUtils;
-import org.apache.log4j.Logger;
-import org.parancoe.yaml.Yaml;
-import org.springframework.core.io.ClassPathResource;
-
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import org.lambico.dao.generic.GenericDaoBase;
-import org.lambico.dao.spring.hibernate.GenericDaoHibernateSupport;
-import org.lambico.test.spring.Utils;
-import org.springframework.core.io.Resource;
-
-/**
- * @author Paolo Dona
paolo...@seesaw.it
- * @author Michele Franzin
michele...@seesaw.it
- */
-public class FixtureHelper {
-
- /** The logger for this class. */
- private static Logger logger = Logger.getLogger(FixtureHelper.class);
- /** The header match. */
- private static final Pattern HEADER_MATCH = Pattern.compile(
- "^-\\s??(\\S*)\\s*?$", Pattern.MULTILINE);
- /** The line match. */
- private static final Pattern LINE_MATCH = Pattern.compile("^(.+)$",
- Pattern.MULTILINE);
-
- /**
- * A default protected constructor.
- */
- protected FixtureHelper() {
- }
-
- /**
- * Gets file name of a fixture fragment related to a model.
- *
- * @param model The class of a model.
- * @return The fixture file name.
- */
- public static String getFixtureFileName(final Class model) {
- return model.getSimpleName() + ".yml";
- }
-
- /**
- * Gets id of dao related to a model.
- * <p/>
- * *WARNING*: strong condition on the DAO id (entity_name+Dao) For
retriving
- * a dao for an entity it's better something like: <code>
- * DaoProvider daos = (DaoProvider)ctx.getBean(DAO_PROVIDER_ID);
- * GenericDao dao = (GenericDao)daos.getDao(clazz);
- * </code>
- * <p/>
- * The DAO_PROVIDER_ID usually is "daos".
- *
- * @param model The class of a model.
- * @return The DAO id.
- */
- public static String getFixtureDaoId(final Class model) {
- return StringUtils.uncapitalize(model.getSimpleName()) + "Dao";
- }
-
- /**
- * Gets id of dao related to a model.
- * <p/>
- * *WARNING*: strong condition on the DAO id (entity_name+Dao) For
retriving
- * a dao for an entity it's better something like: <code>
- * DaoProvider daos = (DaoProvider)ctx.getBean(DAO_PROVIDER_ID);
- * GenericDao dao = (GenericDao)daos.getDao(clazz);
- * </code>
- * <p/>
- * The DAO_PROVIDER_ID usually is "daos".
- *
- * @param model The class of a model.
- * @return The business DAO id.
- */
- public static String getFixtureBusinessDaoId(final Class model) {
- return StringUtils.uncapitalize(model.getSimpleName())
+ "BusinessDao";
- }
-
- /**
- * Gets human readable name of a model.
- *
- * @param model The class of a model.
- * @return The model name.
- */
- public static String getModelName(final Class model) {
- return model.getSimpleName();
- }
-
- /**
- * Load the fixtures.
- *
- * @param classpathResource dir relative path
- * @param models The set of models.
- * @return The model->values map of fixtures.
- */
- public static Map<Class, Object[]> loadFixturesFromResource(
- final String classpathResource, final Set<Class> models) {
- return loadFixturesFromResource(
- new ClassPathResource(classpathResource), models);
- }
-
- /**
- * Load the fixtures.
- *
- * @param fixtureDir The directory where to search the fixtures.
- * @param models The set of models.
- * @return The model->values map of fixtures.
- */
- public static Map<Class, Object[]> loadFixturesFromResource(
- final ClassPathResource fixtureDir, final Set<Class> models) {
- LinkedHashMap<Class, Object[]> fixtures = new LinkedHashMap<Class,
Object[]>(
- models.size());
- String fixtureFileName = null;
- StringBuffer sb = new StringBuffer();
- for (Class model : models) {
- fixtureFileName = fixtureDir.getPath() +
getFixtureFileName(model);
- InputStream stream = null;
- try {
- Resource fixtureResource =
- new ClassPathResource(fixtureFileName);
- stream = fixtureResource.getInputStream();
- String content =
loadFixtureStringForClass(fixtureResource, model);
- if (StringUtils.isNotBlank(content)) {
- sb.append(content);
- sb.append(IOUtils.LINE_SEPARATOR);
- // Mantiene l'ordine di inserimento
- fixtures.put(model, null);
- } else {
- logger.warn("No fixtures for "
- + getModelName(model) + " in the file '"
- + fixtureFileName + "' ?");
- }
- } catch (FileNotFoundException e) {
- logger.warn("Fixture file not found for "
- + getModelName(model) + ", did you created the
file '"
- + fixtureFileName + "' ?");
- } catch (IOException e) {
- logger.error("Loading of fixtures failed for "
- + getModelName(model), e);
- } finally {
- IOUtils.closeQuietly(stream);
- }
- }
-
- if (sb.length() == 0) {
- sb.append("--- !java.lang.Object[] []" +
IOUtils.LINE_SEPARATOR);
- } else {
- sb.insert(0, "--- !java.lang.Object[]" +
IOUtils.LINE_SEPARATOR);
- }
-
- sb.append("...");
- sb.append(IOUtils.LINE_SEPARATOR);
-
- if (logger.isDebugEnabled()) {
- logger.debug("### Start of Yaml generated merging the fixtures
###\n"
- + sb.toString()
- + "\n### End of Yaml generated merging the fixtures
###");
- }
-
- // Debug file output
- // try {
- // FileUtils.writeStringToFile(new File("dump.yml"), sb.toString(),
- // "UTF-8");
- // } catch (IOException e) {
- // e.printStackTrace();
- // }
-
- // Se il documento è vuoto, yaml ritorna un'HashMap
- Object any = Yaml.load(sb.toString());
-
- if (any instanceof Object[]) {
- Object[] fixtureObjects = (Object[]) any;
- for (Object fixtureObject : fixtureObjects) {
- Object[] objects = (Object[]) fixtureObject;
- // null safe handling
- if (!ArrayUtils.isEmpty(objects)) {
- fixtures.put(objects[0].getClass(), objects);
- }
- }
- }
- return fixtures;
- }
-
- /**
- * Load the content of a fixture file <Class>.yml.
- *
- * @param resource The fixture file.
- * @param model The model to load.
- * @return The content of the fixture file.
- * @throws IOException In case of error.
- */
- private static String loadFixtureStringForClass(final Resource
resource,
- final Class model) throws IOException {
- String fixtureString = Utils.loadString(resource);
- // Add fixture class into header
- Matcher matcher = HEADER_MATCH.matcher(fixtureString);
- // Il replace del $ serve alla regex nel caso di inner classes
- fixtureString = matcher.replaceAll("- $1 !"
- + model.getName().replace("$", "\\$"));
- // Indent lines
- matcher = LINE_MATCH.matcher(fixtureString);
- fixtureString = matcher.replaceAll(" $1");
- // aggiungo l'header (Array di oggetti <Class>)
- return "- !" + model.getName() + "[]" + IOUtils.LINE_SEPARATOR
- + fixtureString;
- }
-
- /**
- * Populate the DB with the fixtures data.
- *
- * @param model The model to populate.
- * @param fixtures The fixtures.
- * @param dao The DAO to use.
- */
- @SuppressWarnings("unchecked")
- public static void populateDbForModel(final Class model, final
Object[] fixtures,
- final GenericDaoBase dao) {
- logger.debug("Populating table for " + getModelName(model));
- if (fixtures == null) {
- logger.warn("No fixtures for " + getModelName(model)
- + ", did you created the file '" +
getFixtureFileName(model)
- + "'?");
- return;
- }
- try {
- for (Object entity : fixtures) {
- ((GenericDaoHibernateSupport)
dao).getHibernateTemplate().saveOrUpdate(entity);
- }
- ((GenericDaoHibernateSupport)
dao).getHibernateTemplate().flush();
- ((GenericDaoHibernateSupport)
dao).getHibernateTemplate().clear();
- } catch (Exception e) {
- logger.error("Error populating rows in " + getModelName(model)
- + " table", e);
- }
- }
-
- /**
- * Erase the DB for a model.
- *
- * @param model The model to erase.
- * @param dao The DAO tp use.
- */
- @SuppressWarnings("unchecked")
- public static void eraseDbForModel(final Class model, final
GenericDaoBase dao) {
- logger.debug("Erasing table for " + getModelName(model));
- try {
- // List rows = dao.findAll();
- // for (Object o : rows) {
- // dao.delete(o);
- // }
- if (dao == null) {
- throw new IllegalArgumentException("Dao associated to "
- + model.getName() + " PO is null!");
- }
-
- int deleted = ((GenericDaoHibernateSupport)
dao).getHibernateTemplate().
- bulkUpdate("DELETE FROM "
- +
org.hibernate.cfg.DefaultComponentSafeNamingStrategy.INSTANCE.tableName(
- model.getSimpleName()));
- } catch (Exception e) {
- logger.error("Error deleting rows in " + getModelName(model)
- + " table", e);
- }
- }
-}
=======================================
---
/lambico-test/src/test/java/org/lambico/test/spring/hibernate/AuthorTC.java
Tue Dec 13 13:34:32 2011
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- * Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
- *
- * This file is part of Lambico Test.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *
http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.lambico.test.spring.hibernate;
-
-import org.lambico.po.hibernate.EntityBase;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.persistence.CascadeType;
-import javax.persistence.FetchType;
-import javax.persistence.JoinColumn;
-import javax.persistence.JoinTable;
-import javax.persistence.ManyToMany;
-import javax.persistence.NamedQuery;
-
-/**
- * An persistent object to be used for the tests M:N relationships.
- *
- * @author <a href="mailto:
michele...@seesaw.it">Michele Franzin</a>
- * @version $Revision$
- */
-...@javax.persistence.Entity
-@NamedQuery(name = "AuthorTC.findByName", query = "from AuthorTC where
name like ?")
-public class AuthorTC extends EntityBase {
-
- private static final long serialVersionUID = 832363948575562242L;
-
- private String name = null;
-
- private List<BookTC> books = new ArrayList<BookTC>();
-
- public AuthorTC() {
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
-
this.name = name;
- }
-
- @ManyToMany(targetEntity = BookTC.class, cascade = { CascadeType.ALL
}, fetch = FetchType.EAGER)
- @JoinTable(name = "AUTHOR_BOOK", joinColumns = { @JoinColumn(name
= "author_id") }, inverseJoinColumns = { @JoinColumn(name = "book_id") })
- public List<BookTC> getBooks() {
- return books;
- }
-
- public void setBooks(List<BookTC> books) {
- this.books = books;
- }
-}
=======================================
---
/lambico-test/src/test/java/org/lambico/test/spring/hibernate/AuthorTCDao.java
Tue Dec 13 13:34:32 2011
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
- *
- * This file is part of Lambico Test.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *
http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.lambico.test.spring.hibernate;
-
-import java.util.List;
-
-import org.lambico.dao.generic.Dao;
-import org.lambico.dao.generic.GenericDao;
-
-/**
- * A DAO to be used for the tests M:N relationships.
- *
- * @author <a href="mailto:
michele...@seesaw.it">Michele Franzin</a>
- * @version $Revision$
- */
-@Dao(entity = AuthorTC.class)
-public interface AuthorTCDao extends GenericDao<AuthorTC, Long> {
- List<AuthorTC> findByName(String value);
-}
=======================================
---
/lambico-test/src/test/java/org/lambico/test/spring/hibernate/BookTC.java
Tue Dec 13 13:34:32 2011
+++ /dev/null
@@ -1,66 +0,0 @@
-/**
- * Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
- *
- * This file is part of Lambico Test.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *
http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.lambico.test.spring.hibernate;
-
-import org.lambico.po.hibernate.EntityBase;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.persistence.CascadeType;
-import javax.persistence.FetchType;
-import javax.persistence.ManyToMany;
-import javax.persistence.NamedQuery;
-
-/**
- * An persistent object to be used for the tests M:N relationships.
- *
- * @author <a href="mailto:
michele...@seesaw.it">Michele Franzin</a>
- * @version $Revision$
- */
-...@javax.persistence.Entity
-@NamedQuery(name = "BookTC.findByTitle", query = "from BookTC where title
like ?")
-public class BookTC extends EntityBase {
-
- private static final long serialVersionUID = 1L;
-
- private String title = null;
-
- private List<AuthorTC> authors = new ArrayList<AuthorTC>();
-
- public BookTC() {
- }
-
- public String getTitle() {
- return title;
- }
-
- public void setTitle(String title) {
- this.title = title;
- }
-
- @ManyToMany(targetEntity = AuthorTC.class, cascade = { CascadeType.ALL
}, mappedBy = "books", fetch = FetchType.EAGER)
- public List<AuthorTC> getAuthors() {
- return authors;
- }
-
- public void setAuthors(List<AuthorTC> authors) {
- this.authors = authors;
- }
-
-}
=======================================
---
/lambico-test/src/test/java/org/lambico/test/spring/hibernate/BookTCDao.java
Tue Dec 13 13:34:32 2011
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
- *
- * This file is part of Lambico Test.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *
http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.lambico.test.spring.hibernate;
-
-import java.util.List;
-
-import org.lambico.dao.generic.Dao;
-import org.lambico.dao.generic.GenericDao;
-
-/**
- * A DAO to be used for the tests M:N relationships.
- *
- * @author <a href="mailto:
michele...@seesaw.it">Michele Franzin</a>
- * @version $Revision$
- */
-@Dao(entity = BookTC.class)
-public interface BookTCDao extends GenericDao<BookTC, Long> {
- List<BookTC> findByTitle(String value);
-}
=======================================
---
/lambico-test/src/test/java/org/lambico/test/spring/hibernate/DemoBean.java
Tue Dec 13 13:34:32 2011
+++ /dev/null
@@ -1,71 +0,0 @@
-/**
- * Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
- *
- * This file is part of Lambico Test.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *
http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.lambico.test.spring.hibernate;
-
-public class DemoBean {
- public String nome;
-
- private Long id;
-
- public DemoBean() {
- super();
- }
-
- public DemoBean(String nome, Long id) {
- this.nome = nome;
-
this.id = id;
- }
-
- public Long getId() {
- return id;
- }
-
- public void setId(Long value) {
-
this.id = value;
- }
-
- @Override
- public String toString() {
- return "nome=" + nome + ", id=" + id;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if ((obj == null) || (obj.getClass() != this.getClass()))
- return false;
- // object must be DemoBean at this point
- DemoBean test = (DemoBean) obj;
- return (id == test.getId() || (id != null && id.equals(
test.id)))
- && (nome == test.nome || (nome != null &&
nome.equals(test.nome)));
- }
-
- @Override
- public int hashCode() {
- int hash = 0;
- if (id != null) {
- hash += id.hashCode();
- }
- if (nome != null) {
- hash += nome.hashCode();
- }
- return hash == 0 ? super.hashCode() : hash;
- }
-}
=======================================
---
/lambico-test/src/test/java/org/lambico/test/spring/hibernate/FixtureHelperTest.java
Tue Dec 13 13:34:32 2011
+++ /dev/null
@@ -1,119 +0,0 @@
-/**
- * Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
- *
- * This file is part of Lambico Test.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *
http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.lambico.test.spring.hibernate;
-
-import java.math.BigDecimal;
-import java.util.LinkedHashSet;
-import java.util.Map;
-import java.util.Set;
-import junit.framework.TestCase;
-import org.springframework.util.CollectionUtils;
-
-/**
- * @author <a href="mailto:
michele...@seesaw.it">Michele Franzin</a>
- * @author Lucio Benfante <lucio dot benfante at
gmail.com>
- * @version $Revision$
- */
-public class FixtureHelperTest extends TestCase {
-
- private DemoBean[] expected;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- expected = new DemoBean[5];
- expected[0] = new DemoBean("first one", new Long(356));
- expected[1] = new DemoBean("Demo 1", new Long(6789));
- expected[2] = new DemoBean("àèéìòù", new Long(-980000));
- expected[3] = new DemoBean("Demo3", new Long(98000));
- expected[4] = new DemoBean("Demo#2", new Long(-9800));
- }
-
- @SuppressWarnings("unchecked")
- public void testShouldNotFailWrongFixtureDir() throws Exception {
- Set<Class> models = new LinkedHashSet<Class>(
- CollectionUtils.arrayToList(new Class[]{DemoBean.class}));
- Map<Class, Object[]> result =
FixtureHelper.loadFixturesFromResource(
- "nonExistant/", models);
- assertTrue("Le fixture non sono vuote", result.isEmpty());
- }
-
- @SuppressWarnings("unchecked")
- public void testShouldNotFailIfMissingFixtureFile() throws Exception {
- Set<Class> models = new LinkedHashSet<Class>(
- CollectionUtils.arrayToList(new
Class[]{BigDecimal.class}));
- Map<Class, Object[]> result =
FixtureHelper.loadFixturesFromResource(
- "fixtures/", models);
- assertTrue("Le fixture non sono vuote", result.isEmpty());
- }
-
- public void testShouldNotFailIfEmptyDocs() throws Exception {
- Map<Class, Object[]> result =
FixtureHelper.loadFixturesFromResource(
- "emptyDir/", new LinkedHashSet<Class>());
- assertTrue("Le fixture non sono vuote", result.isEmpty());
- }
-
- @SuppressWarnings("unchecked")
- public void testBeanLoading() throws Exception {
- Set<Class> models = new LinkedHashSet<Class>(
- CollectionUtils.arrayToList(new Class[]{DemoBean.class}));
- Map<Class, Object[]> objects =
FixtureHelper.loadFixturesFromResource(
- "fixtures/", models);
- assertNotNull("Non ha ritornato la mappa di fixtures", objects);
- assertEquals("Non carica tutti i beans", 1, objects.size());
- assertTrue("Non crea istanze di " +
DemoBean.class.getCanonicalName(),
- objects.containsKey(DemoBean.class));
- DemoBean[] result = (DemoBean[]) objects.get(DemoBean.class);
- assertEquals("Non carica tutti i beans", 5, result.length);
- for (int i = 0; i < 5; i++) {
- assertEquals("Non ha caricato correttamente il beans numero "
+ i,
- expected[i], result[i]);
- }
- }
-
- public void testBookLoading() {
- Set<Class> models = new LinkedHashSet<Class>(
- CollectionUtils.arrayToList(new Class[]{AuthorTC.class,
- BookTC.class
- }));
- Map<Class, Object[]> objects =
FixtureHelper.loadFixturesFromResource(
- "fixtures/", models);
- assertNotNull("Non ha ritornato la mappa di fixtures", objects);
- assertEquals(2, objects.size());
- assertEquals(3, objects.get(BookTC.class).length);
- assertEquals(4, objects.get(AuthorTC.class).length);
- assertBookAuthorsAreIdentical(objects.get(BookTC.class),
objects.get(AuthorTC.class));
- }
-
- private void assertBookAuthorsAreIdentical(Object[] books, Object[]
authors) {
- for (int i=0; i < books.length; i++) {
- BookTC currentBook = (BookTC) books[i];
- for (AuthorTC author: currentBook.getAuthors()) {
- boolean found = false;
- for (int j=0; j < authors.length; j++) {
- if (author == authors[j]) {
- found = true;
- break;
- }
- }
- assertTrue("The book author is not in the author array",
found);
- }
- }
- }
-}
=======================================
---
/lambico-test/src/test/java/org/lambico/test/spring/hibernate/UtilsTest.java
Tue Dec 13 13:34:32 2011
+++ /dev/null
@@ -1,64 +0,0 @@
-/**
- * Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
- *
- * This file is part of Lambico Test.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *
http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.lambico.test.spring.hibernate;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import junit.framework.TestCase;
-import org.lambico.test.spring.Utils;
-
-public class UtilsTest extends TestCase {
-
- public void testConvertToNameValueList() {
- Map<String, String> input = new HashMap<String, String>();
- input.put("A", "B");
- input.put("C", "D");
- input.put("E", "F");
- List<String> expected = new ArrayList<String>();
- // changed add order in the list
- expected.add("E=F");
- expected.add("A=B");
- expected.add("C=D");
-
-
assertTrue(expected.containsAll(Utils.convertToNameValueList(input)));
- }
-
- public void testBinaryStripUTF8preamble() {
- byte[] stringWithPreamble =
Utils.loadBinary("testdata/UTF8WithPreamble.txt");
- byte[] stringWithoutPreamble =
Utils.loadBinary("testdata/UTF8WithoutPreamble.txt");
-
- assertTrue(Utils.hasUTF8preamble(stringWithPreamble));
- assertFalse(Utils.hasUTF8preamble(stringWithoutPreamble));
-
- byte[] stripped = Utils.stripUTF8preamble(stringWithPreamble);
- assertFalse(Utils.hasUTF8preamble(stripped));
- assertEquals(stringWithPreamble.length, stripped.length + 3);
- }
-
- public void testStringStripUTF8preamble() throws Exception {
- String stringWithPreamble =
Utils.loadString("testdata/UTF8WithPreamble.txt");
- String stringWithoutPreamble =
Utils.loadString("testdata/UTF8WithoutPreamble.txt");
-
- assertFalse(Utils.hasUTF8preamble(stringWithPreamble));
- assertFalse(Utils.hasUTF8preamble(stringWithoutPreamble));
- }
-}
=======================================
--- /lambico-test/src/test/resources/fixtures/AuthorTC.yml Tue Dec 13
13:34:32 2011
+++ /dev/null
@@ -1,37 +0,0 @@
-#
-# Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
-#
-# This file is part of Lambico Test.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#
http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-- &Author-joe
- name: joe
- books:
- - *Book-WarPeace
- - *Book-Bean
-- &Author-sam
- name: sam
- books:
- - *Book-Java
- - *Book-Bean
-- &Author-peter
- name: peter
- books:
- - *Book-Java
-- &Author-john
- name: john
- books:
- - *Book-Java
-
=======================================
--- /lambico-test/src/test/resources/fixtures/BookTC.yml Tue Dec 13
13:34:32 2011
+++ /dev/null
@@ -1,24 +0,0 @@
-#
-# Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
-#
-# This file is part of Lambico Test.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#
http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-- &Book-WarPeace
- title: War and Peace
-- &Book-Bean
- title: Mr. Bean
-- &Book-Java
- title: Java manual
=======================================
--- /lambico-test/src/test/resources/fixtures/DemoBean.yml Tue Dec 13
13:34:32 2011
+++ /dev/null
@@ -1,39 +0,0 @@
-#
-# Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
-#
-# This file is part of Lambico Test.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#
http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
--
- nome: "first one"
- id: 356
-
-# Ending with spaces
-- &demo1
- nome: "Demo 1"
- id: 6789
-
-# Without anchor
--
- nome: "àèéìòù"
- id: -980000
-
-- &demo3
- nome: "Demo3"
- id: 98000
-
-- &demo2
- nome: "Demo#2"
- id: -9800
=======================================
--- /lambico-test/src/test/resources/fixtures/EntityTC.yml Tue Dec 13
13:34:32 2011
+++ /dev/null
@@ -1,43 +0,0 @@
-#
-# Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
-#
-# This file is part of Lambico Test.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#
http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
--
- fieldOne: "one1"
- fieldTwo: "two5"
- fieldThree: "Three1"
- numericField: 1
--
- fieldOne: "one2"
- fieldTwo: "two4"
- fieldThree: "Three2"
- numericField: 2
--
- fieldOne: "one3"
- fieldTwo: "two3"
- fieldThree: "Three3"
- numericField: 3
--
- fieldOne: "one4"
- fieldTwo: "two2"
- fieldThree: "Three4"
- numericField: 4
--
- fieldOne: "one3"
- fieldTwo: "two1"
- fieldThree: "7hree5"
- numericField: 5
=======================================
--- /lambico-test/src/test/resources/fixtures/String.yml Tue Dec 13
13:34:32 2011
+++ /dev/null
@@ -1,22 +0,0 @@
-#
-# Copyright (C) 2009 Lambico Team <
lucio.b...@gmail.com>
-#
-# This file is part of Lambico Test.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#
http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
--
- Questo è un file UTF8 con preambolo
--
- òàùèì
=======================================
--- /lambico-test/src/test/resources/testdata/UTF8WithPreamble.txt Thu Jan
7 09:56:19 2010
+++ /dev/null
@@ -1,2 +0,0 @@
-Questo è un file UTF8 con preambolo
-òàùèì
=======================================
--- /lambico-test/src/test/resources/testdata/UTF8WithoutPreamble.txt Thu
Jan 7 09:56:19 2010
+++ /dev/null
@@ -1,2 +0,0 @@
-Questo è un file UTF8 senza preambolo
-òàùèì
=======================================
--- /.hgignore Fri Jan 11 00:45:31 2013
+++ /.hgignore Wed Mar 13 10:53:54 2013
@@ -11,3 +11,4 @@
^lambico-spring-hibernate/nb-configuration.xml
^lambico-test/target
^lambico-test/nb-configuration.xml
+^lambico-pump/target
=======================================
--- /lambico-spring-hibernate/pom.xml Fri Jan 11 00:45:31 2013
+++ /lambico-spring-hibernate/pom.xml Wed Mar 13 10:53:54 2013
@@ -4,12 +4,12 @@
<parent>
<artifactId>lambico</artifactId>
<groupId>org.lambico</groupId>
- <version>1.0-SNAPSHOT</version>
+ <version>1.1-SNAPSHOT</version>
</parent>
<groupId>org.lambico</groupId>
<artifactId>lambico-spring-hibernate</artifactId>
<packaging>jar</packaging>
- <version>1.0-SNAPSHOT</version>
+ <version>1.1-SNAPSHOT</version>
<name>Lambico Spring - Hibernate</name>
<description>Lambico implementation based on the Spring framework,
with Hibernate.</description>
<properties>
@@ -18,7 +18,7 @@
<dependencies>
<!-- START test libraries -->
<dependency>
- <groupId>hsqldb</groupId>
+ <groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<scope>test</scope>
</dependency>
@@ -28,6 +28,12 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>${lambico.slf4j.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<scope>test</scope>
@@ -36,22 +42,27 @@
<dependency>
<groupId>org.lambico</groupId>
<artifactId>lambico-spring</artifactId>
+ <exclusions>
+ <exclusion>
+ <artifactId>commons-logging</artifactId>
+ <groupId>commons-logging</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>jcl-over-slf4j</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
<dependency>
- <groupId>javassist</groupId>
+ <groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
- <artifactId>slf4j-api</artifactId>
- <groupId>org.slf4j</groupId>
- <scope>runtime</scope>
- </dependency>
- <dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<type>jar</type>
=======================================
---
/lambico-spring-hibernate/src/main/java/org/lambico/spring/dao/hibernate/HibernateGenericDaoImpl.java
Fri Jan 11 00:45:31 2013
+++
/lambico-spring-hibernate/src/main/java/org/lambico/spring/dao/hibernate/HibernateGenericDaoImpl.java
Wed Mar 13 10:53:54 2013
@@ -56,7 +56,7 @@
/**
* The DAO entity type.
*/
- private Class type;
+ private Class<T> type;
/**
* A customized hibernate template.
*/
@@ -67,6 +67,7 @@
*
* @param o {@inheritDoc}
*/
+ @Override
public final void create(final T o) {
getCustomizedHibernateTemplate().persist(o);
}
@@ -76,6 +77,7 @@
*
* @param o {@inheritDoc}
*/
+ @Override
public final void store(final T o) {
getCustomizedHibernateTemplate().merge(o);
}
@@ -86,6 +88,8 @@
* @param id {@inheritDoc}
* @return {@inheritDoc}
*/
+ @Override
+ @SuppressWarnings("unchecked")
public final T read(final PK id) {
return (T) getCustomizedHibernateTemplate().load(getType(), id);
}
@@ -96,6 +100,8 @@
* @param id {@inheritDoc}
* @return {@inheritDoc}
*/
+ @Override
+ @SuppressWarnings("unchecked")
public final T get(final PK id) {
return (T) getCustomizedHibernateTemplate().get(getType(), id);
}
@@ -105,6 +111,7 @@
*
* @param o {@inheritDoc}
*/
+ @Override
public final void delete(final T o) {
getCustomizedHibernateTemplate().delete(o);
}
@@ -114,6 +121,8 @@
*
* @return {@inheritDoc}
*/
+ @Override
+ @SuppressWarnings("unchecked")
public final List<T> findAll() {
return getCustomizedHibernateTemplate().find(
"from " + getType().getName() + " x");
@@ -125,6 +134,8 @@
* @param criterion {@inheritDoc}
* @return {@inheritDoc}
*/
+ @Override
+ @SuppressWarnings("unchecked")
public final List<T> searchByCriteria(final Criterion... criterion) {
Criteria crit = getSession().createCriteria(getType());
for (Criterion c : criterion) {
@@ -139,6 +150,8 @@
* @param criteria {@inheritDoc}
* @return {@inheritDoc}
*/
+ @Override
+ @SuppressWarnings("unchecked")
public final List<T> searchByCriteria(final DetachedCriteria criteria)
{
return getCustomizedHibernateTemplate().findByCriteria(criteria);
}
@@ -151,6 +164,8 @@
* @param maxResults {@inheritDoc}
* @return {@inheritDoc}
*/
+ @Override
+ @SuppressWarnings("unchecked")
public final List<T> searchByCriteria(final DetachedCriteria criteria,
final int firstResult, final int maxResults) {
return getCustomizedHibernateTemplate().
@@ -165,6 +180,8 @@
* @param criterion {@inheritDoc}
* @return {@inheritDoc}
*/
+ @Override
+ @SuppressWarnings("unchecked")
public final Page<T> searchPaginatedByCriteria(final int page,
final int pageSize, final Criterion... criterion) {
Criteria crit = getSession().createCriteria(getType());
@@ -191,6 +208,7 @@
* @param criteria {@inheritDoc}
* @return {@inheritDoc}
*/
+ @Override
public final Page<T> searchPaginatedByCriteria(final int page,
final int pageSize, final DetachedCriteria criteria) {
// Row count
@@ -200,12 +218,13 @@
criteria.setProjection(null);
criteria.setResultTransformer(Criteria.ROOT_ENTITY);
+ @SuppressWarnings("unchecked")
List<T> list = getCustomizedHibernateTemplate().
findByCriteria(criteria, (page - 1) * pageSize, pageSize);
return new PageDefaultImpl<T>(list, page, pageSize, rowCount);
}
-
+
/**
* {@inheritDoc}
*
@@ -215,19 +234,22 @@
* @param criteria {@inheritDoc}
* @return {@inheritDoc}
*/
+ @Override
public Page<T> searchPaginatedByCriteria(int page, int pageSize, int
totalRecords,
DetachedCriteria criteria) {
+ @SuppressWarnings("unchecked")
List<T> list = getCustomizedHibernateTemplate().
findByCriteria(criteria, (page - 1) * pageSize, pageSize);
return new PageDefaultImpl<T>(list, page, pageSize, totalRecords);
- }
+ }
/**
* {@inheritDoc}
*
* @return {@inheritDoc}
*/
+ @Override
public int deleteAll() {
List<T> rows = findAll();
@@ -241,6 +263,7 @@
*
* @return {@inheritDoc}
*/
+ @Override
public final long count() {
return DataAccessUtils.intResult(
getCustomizedHibernateTemplate().find(
@@ -253,6 +276,7 @@
* @param criteria {@inheritDoc}
* @return {@inheritDoc}
*/
+ @Override
public final long countByCriteria(final DetachedCriteria criteria) {
DetachedCriteria countCriteria = (DetachedCriteria)
SerializationUtils.clone(criteria);
countCriteria.setProjection(Projections.rowCount());
@@ -263,6 +287,7 @@
/**
* {@inheritDoc}
*/
+ @Override
public final void rollBackTransaction() {
final SessionFactory currSessionFactory =
getCustomizedHibernateTemplate().getSessionFactory();
@@ -280,6 +305,7 @@
*
* @return {@inheritDoc}
*/
+ @Override
public final Class getType() {
return type;
}
@@ -289,6 +315,8 @@
*
* @param newType {@inheritDoc}
*/
+ @Override
+ @SuppressWarnings("unchecked")
public final void setType(final Class newType) {
this.type = newType;
}
=======================================
--- /lambico-spring/pom.xml Fri Jan 11 00:45:31 2013
+++ /lambico-spring/pom.xml Wed Mar 13 10:53:54 2013
@@ -4,12 +4,12 @@
<parent>
<artifactId>lambico</artifactId>
<groupId>org.lambico</groupId>
- <version>1.0-SNAPSHOT</version>
+ <version>1.1-SNAPSHOT</version>
</parent>
<groupId>org.lambico</groupId>
<artifactId>lambico-spring</artifactId>
<packaging>jar</packaging>
- <version>1.0-SNAPSHOT</version>
+ <version>1.1-SNAPSHOT</version>
<name>Lambico Spring</name>
<description>Lambico implementation based on the Spring
framework.</description>
<properties>
@@ -18,7 +18,7 @@
<dependencies>
<!-- START test libraries -->
<dependency>
- <groupId>hsqldb</groupId>
+ <groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<scope>test</scope>
</dependency>
@@ -32,6 +32,12 @@
<artifactId>commons-dbcp</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>${lambico.slf4j.version}</version>
+ <scope>test</scope>
+ </dependency>
<!-- END test libraries -->
<dependency>
<groupId>org.lambico</groupId>
@@ -42,20 +48,6 @@
<artifactId>aspectjweaver</artifactId>
</dependency>
<dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <scope>runtime</scope>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-simple</artifactId>
- <scope>runtime</scope>
- </dependency>
- <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</dependency>
@@ -74,7 +66,7 @@
</dependency>
</dependencies>
<build>
- <plugins>
+ <plugins>
<plugin>
<groupId>com.mycila.maven-license-plugin</groupId>
<artifactId>maven-license-plugin</artifactId>
=======================================
--- /pom.xml Fri Jan 11 00:54:44 2013
+++ /pom.xml Wed Mar 13 10:53:54 2013
@@ -4,7 +4,7 @@
<groupId>org.lambico</groupId>
<artifactId>lambico</artifactId>
<packaging>pom</packaging>
- <version>1.0-SNAPSHOT</version>
+ <version>1.1-SNAPSHOT</version>
<name>Lambico</name>
<description>Lambico provides a generic DAO infrastructure to your
applications.</description>
<url>
http://www.lambico.org</url>
@@ -14,16 +14,17 @@
<module>lambico-spring</module>
<module>lambico-spring-hibernate</module>
<module>lambico-test</module>
+ <module>lambico-pump</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<main.basedir>${basedir}</main.basedir>
<year>2009</year>
<lambico.spring.version>3.0.7.RELEASE</lambico.spring.version>
- <lambico.hibernate.version>3.6.2.Final</lambico.hibernate.version>
-
<lambico.hibernate-annotations.version>3.5.1-Final</lambico.hibernate-annotations.version>
- <lambico.log4j.version>1.2.14</lambico.log4j.version>
- <lambico.junit4.version>4.4</lambico.junit4.version>
+ <lambico.hibernate.version>3.6.7.Final</lambico.hibernate.version>
+ <lambico.slf4j.version>1.7.2</lambico.slf4j.version>
+ <lambico.junit4.version>4.11</lambico.junit4.version>
+ <lambico.hsqldb.version>2.2.9</lambico.hsqldb.version>
<!-- NetBeans IDE properties -->
<org-netbeans-modules-editor-indent.CodeStyle.usedProfile>project</org-netbeans-modules-editor-indent.CodeStyle.usedProfile>
@@ -61,19 +62,29 @@
<version>${project.version}</version>
</dependency>
<dependency>
+ <groupId>org.lambico</groupId>
+ <artifactId>lambico-pump</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.lambico</groupId>
<artifactId>lambico-test</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>org.parancoe</groupId>
- <artifactId>parancoe-yaml</artifactId>
- <version>3.0-SNAPSHOT</version>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>${lambico.slf4j.version}</version>
</dependency>
<dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- <version>${lambico.log4j.version}</version>
+ <groupId>org.slf4j</groupId>
+ <artifactId>jcl-over-slf4j</artifactId>
+ <version>${lambico.slf4j.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-core</artifactId>
+ <version>${lambico.spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
@@ -103,7 +114,7 @@
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
- <version>1.6.9</version>
+ <version>1.7.1</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
@@ -111,9 +122,9 @@
<version>${lambico.hibernate.version}</version>
</dependency>
<dependency>
- <groupId>javassist</groupId>
+ <groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
- <version>
3.9.0.GA</version>
+ <version>3.17.1-GA</version>
</dependency>
<dependency>
<groupId>junit</groupId>
@@ -121,9 +132,9 @@
<version>${lambico.junit4.version}</version>
</dependency>
<dependency>
- <groupId>hsqldb</groupId>
+ <groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
- <version>1.8.0.10</version>
+ <version>${lambico.hsqldb.version}</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
@@ -138,27 +149,17 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
- <version>1.4</version>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>1.5.8</version>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-simple</artifactId>
- <version>1.5.8</version>
+ <version>2.4</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
- <version>2.2</version>
+ <version>2.2.2</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
- <version>1.4.3</version>
+ <version>1.4.5</version>
</dependency>
</dependencies>
</dependencyManagement>
@@ -167,7 +168,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
- <version>2.2.1</version>
+ <version>2.4</version>
<configuration>
<descriptors>
<descriptor>src/assembly/bin.xml</descriptor>
@@ -178,7 +179,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
- <version>2.3.2</version>
+ <version>3.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
@@ -188,7 +189,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
- <version>2.10</version>
+ <version>2.13</version>
<configuration>
<skip>false</skip>
<useFile>true</useFile>
@@ -251,7 +252,7 @@
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
- <version>2.1.2</version>
+ <version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
@@ -264,7 +265,7 @@
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
- <version>2.8.1</version>
+ <version>2.9</version>
<executions>
<execution>
<id>attach-javadocs</id>
@@ -296,12 +297,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
- <version>2.8</version>
+ <version>2.9</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
- <version>2.8</version>
+ <version>2.9.1</version>
<configuration>
<configLocation>${main.basedir}/lambico_checks.xml</configLocation>
<headerLocation>${main.basedir}/LICENSE_HEADER</headerLocation>
@@ -316,7 +317,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
- <version>3.0</version>
+ <version>3.2</version>
</plugin>
</plugins>
</reporting>
@@ -326,15 +327,6 @@
***********************************************************************************
-->
<repositories>
<repository>
- <id>
maven2-repository.dev.java.net</id>
- <name>Java.net Repository for Maven</name>
- <url>
http://download.java.net/maven/2/</url>
- <layout>default</layout>
- <snapshots>
- <enabled>false</enabled>
- </snapshots>
- </repository>
- <repository>
<id>jboss-maven2-repository</id>
<name>JBoss Repository for Maven</name>
<url>
https://repository.jboss.org/nexus/content/groups/public/</url>
@@ -432,7 +424,13 @@
</contributor>
<contributor>
<name>Michele Franzin</name>
- <email>
michele...@gmail.com</email>
+ <email>
michele...@jugpadova.it</email>
+ <organization>SeeSaw</organization>
+ <organizationUrl>
http://www.seesaw.it</organizationUrl>
+ <roles>
+ <role>developer</role>
+ </roles>
+ <timezone>+1</timezone>
</contributor>
<contributor>
<name>Enrico Giurin</name>