Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,32 @@ jobs:
if-no-files-found: ignore
if: always()

- run: make acceptance-tests-up
- run: make acceptance-tests-run
- run: make acceptance-tests-down
- name: Start the acceptance tests composition
run: make acceptance-tests-up
- name: Run the acceptance tests
run: make acceptance-tests-run
timeout-minutes: 6 # Add a timeout to catch performance regressions
- run: c2cciutils-docker-logs || true
if: always()
- name: Stop the acceptance tests composition
run: make acceptance-tests-down
Comment thread
sbrunner marked this conversation as resolved.

- name: Start the acceptance tests composition (cluster)
run: make acceptance-tests-up
env:
DOCKER_COMPOSE_ARGS: --file=docker-compose-cluster.yaml
- name: Run the acceptance tests (cluster)
run: make acceptance-tests-run
timeout-minutes: 6 # Add a timeout to catch performance regressions
env:
DOCKER_COMPOSE_ARGS: --file=docker-compose-cluster.yaml
MAPFISH_PRINT_TESTS_CLUSTER_MODE: 'true'
- run: c2cciutils-docker-logs || true
if: always()
- name: Stop the acceptance tests composition (cluster)
run: make acceptance-tests-down
env:
DOCKER_COMPOSE_ARGS: --file=docker-compose-cluster.yaml
Comment thread
sbrunner marked this conversation as resolved.

- uses: actions/upload-artifact@v6
with:
Expand Down
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
GIT_HEAD_ARG = --build-arg=GIT_HEAD=$(shell git rev-parse HEAD)
export DOCKER_BUILDKIT = 1

# Set it to `--file=docker-compose-cluster.yaml` to run the acceptance tests in cluster mode
DOCKER_COMPOSE_ARGS ?=

.PHONY: clean
clean:
rm -rf .env examples/geoserver-data/logs/
Expand Down Expand Up @@ -50,11 +53,11 @@ tests: build-builder
acceptance-tests-up: build .env
# Required to avoid root ownership of reports folder
mkdir -p examples/build/reports/ || true
docker compose up --detach
docker compose $(DOCKER_COMPOSE_ARGS) up --detach

.PHONY: acceptance-tests-run
acceptance-tests-run: .env
docker compose exec -T tests gradle \
docker compose $(DOCKER_COMPOSE_ARGS) exec -T tests gradle \
--exclude-task=:core:spotbugsMain --exclude-task=:core:checkstyleMain \
--exclude-task=:core:spotbugsTest --exclude-task=:core:checkstyleTest --exclude-task=:core:testCLI \
:examples:integrationTest
Expand All @@ -63,7 +66,7 @@ acceptance-tests-run: .env

.PHONY: acceptance-tests-down
acceptance-tests-down: .env
docker compose down || true
docker compose $(DOCKER_COMPOSE_ARGS) down || true

.PHONY: dist
dist: build-builder
Expand Down
2 changes: 2 additions & 0 deletions core/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ CMD ["/usr/local/tomcat/bin/docker-start-print"]
FROM runner AS tester

COPY extraConfigFor/acceptanceTests/mapfish-spring-application-context-override.xml /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/
COPY extraConfigFor/acceptanceTests/mapfish-spring-application-context-override-db.xml /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/
RUN chmod go+rw /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/mapfish-spring-application-context-override*.xml

FROM runner AS watcher

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:security="http://www.springframework.org/schema/security"
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/security http://www.springframework.org/schema/security/spring-security.xsd">

<!-- 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="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="org.postgresql.Driver"/>
<property name="jdbcUrl" value="jdbc:postgresql://${db.host}:${db.port:5432}/${db.name}"/>
<property name="user" value="${db.username}"/>
<property name="password" value="${db.password}"/>
<property name="minPoolSize" value="1"/>
<property name="numHelperThreads" value="1"/>
<property name="maxIdleTime" value="30"/>
</bean>

<!-- 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>

<!-- 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"/>
<bean id="accounting" class="org.mapfish.print.servlet.job.HibernateAccounting" lazy-init="false"/>

<bean name="bcryptEncoder"
class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder"/>

<security:authentication-manager alias="authenticationManager">
<security:authentication-provider>
<security:password-encoder ref="bcryptEncoder"/>
<security:user-service>
<!-- password is jimi -->
<security:user name="jimi"
password="$2a$10$OeKmMfVmL2IbF/3skK8l2.Gl3EqvvGhb.Pxr/K0dN7.ttPRHsOzVW"
authorities="ROLE_USER, ROLE_ADMIN"/>
<!-- password is bob -->
<security:user name="bob"
password="$2a$10$D5gwUewQQSpjfZPTcj9rpuTTfmxAqNEyJ19pzC7Z9.fHSCl3jtDj."
authorities="ROLE_USER"/>
</security:user-service>
</security:authentication-provider>
</security:authentication-manager>
</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ public AccessAssertion setRequiredRoles(final Collection<String> assertionRequir
public void assertAccess(final String resourceDescription, final Object protectedResource) {
final SecurityContext context = SecurityContextHolder.getContext();

if (context == null || context.getAuthentication() == null) {
if (context == null) {
throw new AuthenticationCredentialsNotFoundException("Unable to get the security context");
}
if (context.getAuthentication() == null) {
throw new AuthenticationCredentialsNotFoundException(
resourceDescription + " requires an authenticated user");
} else if (this.requiredRoles.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<bean id="jobQueue" class="org.mapfish.print.servlet.job.impl.hibernate.HibernateJobQueue"/>
<bean id="mfDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="org.postgresql.Driver"/>
<property name="jdbcUrl" value="jdbc:postgresql://${db.host}:${db.port}/${db.name}"/>
<property name="jdbcUrl" value="jdbc:postgresql://${db.host}:${db.port:5432}/${db.name}"/>
<property name="user" value="${db.username}"/>
<property name="password" value="${db.password}"/>
<property name="minPoolSize" value="1"/>
Expand Down
40 changes: 40 additions & 0 deletions docker-compose-cluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
services:
db:
image: postgres:15.15
environment:
POSTGRES_DB: print
POSTGRES_USER: print
POSTGRES_PASSWORD: print

geoserver:
image: camptocamp/geoserver:16
volumes:
- ./examples/geoserver-data/:/mnt/geoserver_datadir
- ./core/src/test/resources/map-data/:/mnt/geoserver_datadir/www/map-data

print:
image: mapfish_print_tester
user: ${USER_ID}
volumes:
- ./examples/src/test/resources/examples:/usr/local/tomcat/webapps/ROOT/print-apps:ro
ports:
- 8080:8080
environment:
PRINT_YAML_MAX_ALIASES: '200'
LOG_LEVEL: DEBUG
JASPER_LOG_LEVEL: DEBUG
CATALINA_OPTS: '-Ddb.host=db -Ddb.username=print -Ddb.password=print -Ddb.name=print'
JAVA_OPTS: '-Dmapfish.image.plugins=true'

tests:
image: mapfish_print_builder
user: ${USER_ID}
command: tail --follow /dev/null
volumes:
- ./examples/src:/src/examples/src:ro
- ./examples/src/test/resources/examples:/src/examples/src/test/resources/examples
- ./examples/build/reports:/src/examples/build/reports
- ./examples/build/resources:/src/examples/build/resources
environment:
PRINT_YAML_MAX_ALIASES: '200'
GRADLE_USER_HOME: /home/gradle/.gradle
15 changes: 15 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,18 @@ We can optionally have a mask image that will be used to mask the tested image.
This mask image will be loaded from the `src/test/resources/examples/<tested_application>/expected_output/mask-requestData<postfix>.png` file.
This image should be grayscale with only full black and full white pixel values.
If we create the mask image with Gimp, we can't create indexed image with tow colors because in the Java code we get the values 1 instead of 0 for the black pixel.

## Acceptance tests run by CI

To run the acceptance tests, in the CI run:

- `make acceptance-tests-up` to start the test server.
- `make acceptance-tests-run` to run the tests.
- `make acceptance-tests-down` to stop the test server.

The CI does also the tests in cluster mode with a single instance but with a PostgreSQL database used to store the state.
To do so, in the CI use the `DOCKER_COMPOSE_ARGS` environment variable to specify the docker-compose file to use:

- `DOCKER_COMPOSE_ARGS=--file=docker-compose-cluster.yaml make acceptance-tests-up`
- `DOCKER_COMPOSE_ARGS=--file=docker-compose-cluster.yaml make acceptance-tests-run`
- `DOCKER_COMPOSE_ARGS=--file=docker-compose-cluster.yaml make acceptance-tests-down`
2 changes: 2 additions & 0 deletions examples/src/test/java/org/mapfish/print/PrintApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.json.JSONObject;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mapfish.print.servlet.MapPrinterServlet;
import org.springframework.http.HttpMethod;
Expand Down Expand Up @@ -486,6 +487,7 @@ private void assertRequiresAuth(String path) throws IOException, URISyntaxExcept
}

@Test
@EnabledIfEnvironmentVariable(named = "MAPFISH_PRINT_TESTS_CLUSTER_MODE", matches = "true")
public void testSecuredTemplate_CreateMap() throws Exception {
ClientHttpRequest request =
getPrintRequest(
Expand Down
Loading