bmatthews68 / inmemdb-maven-plugin

A Maven 3 plug-in that can be used to launch an in-memory database for use in integration tests. Apache Derby and HSQLDB are both supported.
http://inmemdb-maven-plugin.btmatthews.com
Apache License 2.0
15 stars 7 forks source link

Does it work with Datasource from outside #23

Open hboumedane opened 9 years ago

hboumedane commented 9 years ago

Hello,

I have used your plugin to populate a hsql database but I experiencing some problems, I'm using openjpa with annotation class. I have two datasources and when i run IT my tests uses the persistence file that use the Test datasource. when running IT I got an exception :

Unable to retrieve EntityManager
Tcharl commented 9 years ago

What do you use as Itests framework? Pax-Exam, WildFly? It's really not an inmemdb issue, this plugin just starts a db in the pre-integration test phase (if you configured it). But inmemdb isn't responsible of any EntityManager startup/handling.

If you want to see an IT, take a look at https://github.com/OsgiliathEnterprise/net.osgiliath.parent that uses inmemdb, Pax-Exam and failsafe to setup a fully fledged integration server (but wildfly/failsafe/inMemdb is also feasible, or even tomcat/spring/failsafe/inMemDb, there are number of sample googling for them).

Regards,

hboumedane commented 9 years ago

I'm using an OSGI Framework with it's IT test framework. but i was wondering if inMemDb uses my datasource configured with my OSGI Framework.

bmatthews68 commented 9 years ago

Can you share your pom.xml?

Kind regards, Brian

http://btmatthews.com http://ie.linkedin.com/in/bmatthews68 https://plus.google.com/+BrianMatthews68 http://twitter.com/bmatthews68 https://www.facebook.com/bmatthews68 http://blog.btmatthews.com/

On 7 April 2015 at 21:16, hboumedane notifications@github.com wrote:

I'm using an OSGI Framework with it's IT test framework. but i was wondering if inMemDb uses my datasource configured with my OSGI Framework.

— Reply to this email directly or view it on GitHub https://github.com/bmatthews68/inmemdb-maven-plugin/issues/23#issuecomment-90718094 .

hboumedane commented 9 years ago

thanks for the reply , will do that tomorrow , because i don't have it right now (it's in the office)

hboumedane commented 9 years ago

Here my pom.xml file

<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>
        <groupId>***********</groupId>
        <artifactId>common</artifactId>
        <version>1.5-SNAPSHOT</version>
    </parent>

    <artifactId>************</artifactId>
    <packaging>wisdom</packaging>

    <inceptionYear>2015</inceptionYear>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <projectBaseUri>${project.baseUri}</projectBaseUri>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.ow2.chameleon.mail</groupId>
            <artifactId>mail-service</artifactId>
        </dependency>

        <dependency>
            <groupId>org.wisdom-framework</groupId>
            <artifactId>wisdom-api</artifactId>
        </dependency>

        <dependency>
            <groupId>org.apache.felix</groupId>
            <artifactId>org.apache.felix.ipojo.annotations</artifactId>
        </dependency>

        <dependency>
            <groupId>org.apache.felix</groupId>
            <artifactId>org.apache.felix.ipojo</artifactId>
        </dependency>

        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.core</artifactId>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </dependency>
        <!-- Test dependencies -->
        <dependency>
            <groupId>org.wisdom-framework</groupId>
            <artifactId>wisdom-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.fluentlenium</groupId>
            <artifactId>fluentlenium-assertj</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <!-- slf4j binding used for tests -->
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-jcl</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- Additional applications -->
        <dependency>
            <groupId>org.wisdom-framework</groupId>
            <artifactId>wisdom-monitor</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-collections</groupId>
            <artifactId>commons-collections</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
        </dependency>
        <!-- jdbc dependencies + datasource jdbc plugin-->
        <dependency>
            <groupId>org.wisdom-framework</groupId>
            <artifactId>wisdom-jdbc-datasources</artifactId>
        </dependency>

        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>bootstrap</artifactId>
        </dependency>

        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>jquery</artifactId>
        </dependency>

        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>jquery-ui</artifactId>
            <version>1.11.1</version>
        </dependency>

        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>jquery-file-upload</artifactId>
            <version>9.8.0</version>
        </dependency>

        <dependency>
            <groupId>org.imgscalr</groupId>
            <artifactId>imgscalr-lib</artifactId>
            <version>4.2</version>
            <scope>compile</scope>
        </dependency>

        <!-- libraries used to execute http request and parse responses -->
        <dependency>
            <groupId>org.jsoup</groupId>
            <artifactId>jsoup</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient-osgi</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpasyncclient-osgi</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpmime</artifactId>
        </dependency>
        <!-- librairies used to send e-mails. -->
        <dependency>
            <groupId>org.wisdom-framework</groupId>
            <artifactId>wisdom-mailer</artifactId>
        </dependency>

        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
        </dependency>

        <!-- OpenJPA provider and dependencies -->
        <dependency>
            <groupId>org.apache.openjpa</groupId>
            <artifactId>openjpa</artifactId>
            <version>2.3.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.geronimo.specs</groupId>
            <artifactId>geronimo-servlet_2.5_spec</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <!--Because ot the split packager from rt.jar, JTA is declared as a library -->
            <groupId>org.apache.geronimo.specs</groupId>
            <artifactId>geronimo-jta_1.1_spec</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.servicemix.bundles</groupId>
            <artifactId>org.apache.servicemix.bundles.serp</artifactId>
            <version>1.14.1_1</version>
        </dependency>
        <!-- JPA support and data source -->
        <dependency>
            <groupId>org.wisdom-framework</groupId>
            <artifactId>wisdom-jpa-manager</artifactId>
            <version>0.5</version>
        </dependency>

        <dependency>
            <groupId>org.wisdom-framework</groupId>
            <artifactId>postgresql</artifactId>
            <version>9.1-901.jdbc4_1</version>
        </dependency>

        <dependency>
            <groupId>org.wisdom-framework</groupId>
            <artifactId>hsqldb</artifactId>
            <version>2.3.2_2</version>
        </dependency>

        <dependency>
            <groupId>org.wisdom-framework</groupId>
            <artifactId>h2</artifactId>
            <version>1.4.184_1</version>
        </dependency>

        <!-- added to prevent error-->
        <dependency>
            <groupId>org.ow2.chameleon</groupId>
            <artifactId>chameleon-core</artifactId>
            <version>1.10.6</version>
            <scope>provided</scope>
        </dependency>

    </dependencies>

    <build>

        <testResources>
            <testResource>
                <directory>src/test/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>**/*.xml</include>
                </includes>
                <excludes>
                    <exclude>**/fit/**</exclude>
                    <exclude>**/reports/**</exclude>
                </excludes>
            </testResource>
        </testResources>

        <plugins>
            <plugin>
                <groupId>org.wisdom-framework</groupId>
                <artifactId>wisdom-maven-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <!-- Defines the set of 'libraries' -->
                    <libraries>
                        <includes>
                            <include>:imgscalr-lib</include>
                            <include>:geronimo-jta_1.1_spec</include>
                        </includes>

                        <resolveTransitive>true</resolveTransitive>
                        <excludeFromApplication>true</excludeFromApplication>

                    </libraries>
                    <nonFilteredExtensions>
                        <extension>jks</extension>
                    </nonFilteredExtensions>
                    <skipGoogleClosure>true</skipGoogleClosure>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.wisdom-framework</groupId>
                <artifactId>wisdom-openjpa-enhancer-plugin</artifactId>
                <version>0.5</version>
                <configuration>
                    <includes>**/models/*.class</includes>
                    <addDefaultConstructor>true</addDefaultConstructor>
                    <enforcePropertyRestrictions>true</enforcePropertyRestrictions>
                </configuration>
                <executions>
                    <execution>
                        <id>enhancer</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>enhance-entities</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.openjpa</groupId>
                        <artifactId>openjpa</artifactId>
                        <version>2.3.0</version>
                    </dependency>
                </dependencies>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.17</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                        <configuration>
                            <properties>
                                <property>
                                    <name>listener</name>
                                    <value>org.wisdom.test.WisdomRunListener</value>
                                </property>
                            </properties>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>com.btmatthews.maven.plugins.inmemdb</groupId>
                <artifactId>inmemdb-maven-plugin</artifactId>
                <version>1.4.2</version>
                <configuration>
                    <monitorKey>inmemdb</monitorKey>
                    <monitorPort>11527</monitorPort>
                </configuration>
                <executions>
                    <execution>
                        <id>run</id>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <phase>pre-integration-test</phase>
                        <configuration>
                            <daemon>true</daemon>
                            <type>h2</type>
                            <database>h2-mem-it</database>
                            <username>SA</username>
                            <password></password>
                            <sources>
                                <script>
                                    <sourceFile>src/test/resources/test-data-h2.sql</sourceFile>
                                </script>
                            </sources>
                        </configuration>
                    </execution>
                    <execution>
                        <id>stop</id>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                        <phase>post-integration-test</phase>
                    </execution>
                </executions>
            </plugin>

        </plugins>

    </build>

</project>
Tcharl commented 9 years ago

It depends on how you configured your persistence.xml.

Within Osgi, you can use pax-jdbc, aries-jndi and aries-jpa to expose/reference a datasource (the one started with inmemdb). You should really take a look at Osgiliath fwk, we merely have the same stack, and its integration tested and also uses imemdb (but not for provisioning tests).

Regards,