Skip to content

Commit

Permalink
Merge pull request #3444 from mapfish/ClusteredMapPrinterServletTest
Browse files Browse the repository at this point in the history
Tests context with h2 datasource
  • Loading branch information
sebr72 authored Oct 16, 2024
2 parents 4a98ee4 + c4c182a commit ecd4a0e
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 28 deletions.
1 change: 1 addition & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ dependencies {
compileOnly 'com.github.spotbugs:spotbugs-annotations:4.7.3'

testImplementation group: 'de.saly', name: 'javamail-mock2-fullmock', version: '0.5-beta4'
testImplementation group: 'com.h2database', name: 'h2', version: '2.3.232'
}

static def gitRevision() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import java.net.URI;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Lob;
import org.mapfish.print.servlet.job.impl.PrintJobResultImpl;

/** Extension of Print Job Result that holds data as BLOB. */
@Entity
public class PrintJobResultExtImpl extends PrintJobResultImpl {

@Column private byte[] data;
@Column @Lob private byte[] data;

/** Default Constructor. */
public PrintJobResultExtImpl() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package org.mapfish.print.servlet;

import org.junit.Ignore;
import org.springframework.test.context.ContextConfiguration;

@ContextConfiguration(locations = {ClusteredMapPrinterServletTest.CLUSTERED_CONTEXT})
@Ignore // db must be set up to run this test
public class ClusteredMapPrinterServletTest extends MapPrinterServletTest {

public static final String CLUSTERED_CONTEXT =
"classpath:org/mapfish/print/servlet/mapfish-spring-application-context-clustered.xml";
"classpath:org/mapfish/print/servlet/mapfish-spring-application-context-clustered-test.xml";
}
38 changes: 38 additions & 0 deletions core/src/test/resources/mapfish-spring-hibernate.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx" default-lazy-init="true"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

<bean id="mfSessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="mfDataSource"/>
<property name="annotatedClasses">
<list>
<value>org.mapfish.print.servlet.job.impl.PrintJobEntryImpl</value>
<value>org.mapfish.print.servlet.job.impl.PrintJobStatusImpl</value>
<value>org.mapfish.print.servlet.job.impl.PrintJobResultImpl</value>
<value>org.mapfish.print.servlet.job.impl.hibernate.PrintJobStatusExtImpl</value>
<value>org.mapfish.print.servlet.job.impl.hibernate.PrintJobResultExtImpl</value>
<value>org.mapfish.print.servlet.job.HibernateAccountingEntry</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.hbm2ddl.auto=update
hibernate.dialect=org.hibernate.dialect.H2Dialect
hibernate.default_schema=${db.schema}
<!-- hibernate.show_sql=true -->
</value>
</property>
</bean>

<bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="mfSessionFactory"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>

<bean id="printJobDao" class="org.mapfish.print.servlet.job.impl.hibernate.PrintJobDao"/>

</beans>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>

<beans default-lazy-init="true" xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

<!-- At this point, there can be two flavours of this conf. the one with postgres datasource and the one with h2 datasource. Both import this file so to shared beans to be instantiated. -->

<bean id="jobQueue" class="org.mapfish.print.servlet.job.impl.hibernate.HibernateJobQueue" />

<bean class="org.springframework.beans.factory.config.PropertyOverrideConfigurer" >
<property name="ignoreResourceNotFound" value="true"/>
<property name="properties">
<props>
<prop key="jobManager.clustered">true</prop>
<prop key="jobManager.oldFileCleanUp">false</prop>
</props>
</property>
</bean>

<bean id="printJobPrototype" class="org.mapfish.print.servlet.job.impl.hibernate.HibernatePrintJob" scope="prototype"/>
<bean id="fileReportLoader" class="org.mapfish.print.servlet.job.impl.hibernate.HibernateReportLoader"/>

</beans>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>

<beans default-lazy-init="true" xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

<bean id="mfDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.h2.Driver" />
<property name="url" value="jdbc:h2:mem:dbtest;DB_CLOSE_DELAY=-1" />
<property name="username" value="jobs" />
<property name="password" value="jobs" />
</bean>

<import resource="classpath:org/mapfish/print/servlet/abstract-mapfish-spring-application-context-clustered.xml"/>
</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,14 @@

<beans default-lazy-init="true" xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<!--
This file is intentionally left empty. Other plugins/configurations can add a file with the same name and the beans
in that file will override the beans defined in the other default spring configuration files
-->

<!-- Uncomment this to use hibernate instead of the registry to store the job queue.
configure the data source as well -->
<bean id="jobQueue" class="org.mapfish.print.servlet.job.impl.hibernate.HibernateJobQueue" />
<bean id="mfDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="jdbc:postgresql://localhost/jobs" />
<property name="username" value="jobs" />
<property name="password" value="jobs" />
</bean>

<!-- Uncomment this to force the job manager the support clustering, by not taking submitted jobs automatically as its own.
This mode requires the hibernate job queue, the registry job queue is unsupported.
oldFileCleanUp should be turned off if hibernate is used for print job results (see below) -->
<bean class="org.springframework.beans.factory.config.PropertyOverrideConfigurer" >
<property name="ignoreResourceNotFound" value="true"/>
<property name="properties">
<props>
<prop key="jobManager.clustered">true</prop>
<prop key="jobManager.oldFileCleanUp">false</prop>
</props>
</property>
</bean>

<!-- Uncomment this to use hibernate to read and write print job results -->
<bean id="printJobPrototype" class="org.mapfish.print.servlet.job.impl.hibernate.HibernatePrintJob" scope="prototype"/>
<bean id="fileReportLoader" class="org.mapfish.print.servlet.job.impl.hibernate.HibernateReportLoader"/>

<import resource="classpath:org/mapfish/print/servlet/abstract-mapfish-spring-application-context-clustered.xml"/>
</beans>

0 comments on commit ecd4a0e

Please sign in to comment.