diff --git a/.github/workflows/CI build.yml b/.github/workflows/CI build.yml index 348c1b28..43cb54b8 100644 --- a/.github/workflows/CI build.yml +++ b/.github/workflows/CI build.yml @@ -15,6 +15,17 @@ jobs: # Main build job used to name: Build runs-on: ubuntu-latest + services: + postgres: + image: postgis/postgis:16-3.4 + env: + POSTGRES_USER: orbisgis + POSTGRES_PASSWORD: orbisgis + POSTGRES_DB: orbisgis_db + ports: + - 5432:5432 + # needed because the postgres container does not provide a healthcheck + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 steps: # Checkout the source code of the project - name: Checkout @@ -27,16 +38,6 @@ jobs: distribution: 'temurin' java-version: '11' - # Setup postgis test DB - - uses: SPalominos/PostGIS-Installer-Action@v1.0.1 - with: - psql_version: '9.6' - pgis_version: '2.5' - docker_image: 'postgis/postgis' - db_password: 'orbisgis' - db_user: 'orbisgis' - db_name: 'orbisgis_db' - # Build the project using # - clean : clean up the workspace # - validate : perform different check like the dependency and plugin version update @@ -62,4 +63,4 @@ jobs: - if: steps.changes.outputs.changelog == 'false' && github.event_name != 'workflow_dispatch' && steps.changes.outputs.sources == 'true' run: | echo "Please update the Changelog.md file." - exit 1 + exit 1 \ No newline at end of file diff --git a/.github/workflows/CI release.yml b/.github/workflows/CI release.yml index 45b08716..646c0a6b 100644 --- a/.github/workflows/CI release.yml +++ b/.github/workflows/CI release.yml @@ -11,6 +11,17 @@ jobs: build: name: Release and next iteration runs-on: ubuntu-latest + services: + postgres: + image: postgis/postgis:16-3.4 + env: + POSTGRES_USER: orbisgis + POSTGRES_PASSWORD: orbisgis + POSTGRES_DB: orbisgis_db + ports: + - 5432:5432 + # needed because the postgres container does not provide a healthcheck + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 steps: # Checkout the source code of the project - name: Checkout @@ -37,16 +48,6 @@ jobs: gpg-private-key: ${{ secrets.GPG_SECRET_KEY }} gpg-passphrase: MAVEN_GPG_PASSPHRASE - # Setup postgis test DB - - uses: SPalominos/PostGIS-Installer-Action@v1.0.1 - with: - psql_version: '9.6' - pgis_version: '2.5' - docker_image: 'postgis/postgis' - db_password: 'orbisgis' - db_user: 'orbisgis' - db_name: 'orbisgis_db' - # Configure git user in order to sign release with OrbisGIS user. - name: Configure Git User run: | @@ -100,7 +101,6 @@ jobs: git commit -a -m "Empty changelog." git push origin master - # If the version change is a major or minor, create a branch from the previous tag for future revisions. - name: Branch fork run: | @@ -117,4 +117,4 @@ jobs: mvn versions:set -DnewVersion="${SPLIT0[0]}.${SPLIT0[1]}.$((${SPLIT0[2]}+1))-SNAPSHOT" git commit -a -m "Set next version." git push -u origin "$BRANCH" - fi + fi \ No newline at end of file diff --git a/.github/workflows/CI snapshot.yml b/.github/workflows/CI snapshot.yml index 7c6ab1f2..70a4f2dd 100644 --- a/.github/workflows/CI snapshot.yml +++ b/.github/workflows/CI snapshot.yml @@ -2,7 +2,7 @@ name: CI_snapshot on: push: - branches: [ '**' ] + branches: [ 'master' ] workflow_run: workflows: ["CI release"] branches: [ '**' ] @@ -14,6 +14,18 @@ jobs: build: name: Upload Snapshot runs-on: ubuntu-latest + services: + postgres: + image: postgis/postgis:16-3.4 + env: + # must specify password for PG Docker container image, see: https://registry.hub.docker.com/_/postgres?tab=description&page=1&name=10 + POSTGRES_USER: orbisgis + POSTGRES_PASSWORD: orbisgis + POSTGRES_DB: orbisgis_db + ports: + - 5432:5432 + # needed because the postgres container does not provide a healthcheck + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 steps: # Checkout the source code of the project - name: Checkout @@ -40,21 +52,10 @@ jobs: gpg-private-key: ${{ secrets.GPG_SECRET_KEY }} gpg-passphrase: MAVEN_GPG_PASSPHRASE - # Setup postgis test DB - - uses: SPalominos/PostGIS-Installer-Action@v1.0.1 - with: - psql_version: '9.6' - pgis_version: '2.5' - docker_image: 'postgis/postgis' - db_password: 'orbisgis' - db_user: 'orbisgis' - db_name: 'orbisgis_db' - - # Deploy the snapshot - name: Deploy run: mvn deploy -ntp --batch-mode env: MAVEN_USERNAME: ${{ secrets.MVN_CENTRAL_USERNAME }} MAVEN_PASSWORD: ${{ secrets.MVN_CENTRAL_PASSWORD }} - MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} + MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} \ No newline at end of file diff --git a/commons/pom.xml b/commons/pom.xml index 19eaa470..0702b18c 100644 --- a/commons/pom.xml +++ b/commons/pom.xml @@ -14,14 +14,6 @@ commons Library to manage OrbisData utilities - - - UTF-8 - YYYY-MM-dd - ${maven.build.timestamp} - ${project.parent.basedir} - - diff --git a/data/data-api/pom.xml b/data/data-api/pom.xml index d2629cae..0bc325bb 100644 --- a/data/data-api/pom.xml +++ b/data/data-api/pom.xml @@ -16,20 +16,11 @@ data-api DATA API define extension point of OrbisData - - - UTF-8 - YYYY-MM-dd - ${maven.build.timestamp} - ${project.parent.basedir} - - org.apache.groovy groovy - ${groovy-version} org.locationtech.jts @@ -59,43 +50,4 @@ h2gis-utilities - - - - - - org.apache.felix - maven-bundle-plugin - - - org.apache.maven.plugins - maven-surefire-plugin - - - org.codehaus.mojo - versions-maven-plugin - - - org.apache.maven.plugins - maven-enforcer-plugin - - - org.codehaus.gmavenplus - gmavenplus-plugin - - - org.apache.maven.plugins - maven-javadoc-plugin - - - org.sonatype.central - central-publishing-maven-plugin - 0.8.0 - true - - central - - - - \ No newline at end of file diff --git a/data/dataframe/pom.xml b/data/dataframe/pom.xml index 6785edad..3d2016f4 100644 --- a/data/dataframe/pom.xml +++ b/data/dataframe/pom.xml @@ -16,14 +16,6 @@ dataframe Library to manage dataframe - - - UTF-8 - YYYY-MM-dd - ${maven.build.timestamp} - ${project.parent.basedir} - - Erwan Bocher @@ -40,40 +32,31 @@ com.h2database h2 - ${h2-version} org.orbisgis commons - ${project.version} - compile org.orbisgis.data data-api - ${project.version} - compile org.orbisgis.data jdbc - ${project.version} test org.apache.groovy groovy - ${groovy-version} org.apache.groovy groovy-sql - ${groovy-version} org.apache.groovy groovy-templates - ${groovy-version} org.orbisgis @@ -106,7 +89,6 @@ org.orbisgis.data h2gis - ${project.version} test @@ -114,39 +96,10 @@ - - org.apache.felix - maven-bundle-plugin - - - org.apache.maven.plugins - maven-surefire-plugin - - - org.codehaus.mojo - versions-maven-plugin - - - org.apache.maven.plugins - maven-enforcer-plugin - org.codehaus.gmavenplus gmavenplus-plugin - - org.apache.maven.plugins - maven-javadoc-plugin - - - org.sonatype.central - central-publishing-maven-plugin - 0.8.0 - true - - central - - - + \ No newline at end of file diff --git a/data/h2gis/pom.xml b/data/h2gis/pom.xml index 4f694650..fbd43efe 100644 --- a/data/h2gis/pom.xml +++ b/data/h2gis/pom.xml @@ -16,14 +16,6 @@ h2gis Library to manage h2gis database - - - UTF-8 - YYYY-MM-dd - ${maven.build.timestamp} - ${project.parent.basedir} - - @@ -37,22 +29,18 @@ com.h2database h2 - ${h2-version} org.apache.groovy groovy - ${groovy-version} org.apache.groovy groovy-sql - ${groovy-version} org.apache.groovy groovy-templates - ${groovy-version} org.orbisgis @@ -93,12 +81,10 @@ commons-dbcp commons-dbcp - 1.4 org.orbisgis.data postgis - ${project.version} test @@ -106,39 +92,10 @@ - - org.apache.felix - maven-bundle-plugin - - - org.apache.maven.plugins - maven-surefire-plugin - - - org.codehaus.mojo - versions-maven-plugin - - - org.apache.maven.plugins - maven-enforcer-plugin - org.codehaus.gmavenplus gmavenplus-plugin - - org.apache.maven.plugins - maven-javadoc-plugin - - - org.sonatype.central - central-publishing-maven-plugin - 0.8.0 - true - - central - - \ No newline at end of file diff --git a/data/jdbc/pom.xml b/data/jdbc/pom.xml index 1b4d62f3..f0e027dc 100644 --- a/data/jdbc/pom.xml +++ b/data/jdbc/pom.xml @@ -16,14 +16,6 @@ jdbc Library to manage jdbc connection - - - UTF-8 - YYYY-MM-dd - ${maven.build.timestamp} - ${project.parent.basedir} - - @@ -37,22 +29,18 @@ com.h2database h2 - ${h2-version} org.apache.groovy groovy - ${groovy-version} org.apache.groovy groovy-sql - ${groovy-version} org.apache.groovy groovy-templates - ${groovy-version} org.orbisgis @@ -91,43 +79,4 @@ test - - - - - - org.apache.felix - maven-bundle-plugin - - - org.apache.maven.plugins - maven-surefire-plugin - - - org.codehaus.mojo - versions-maven-plugin - - - org.apache.maven.plugins - maven-enforcer-plugin - - - org.codehaus.gmavenplus - gmavenplus-plugin - - - org.apache.maven.plugins - maven-javadoc-plugin - - - org.sonatype.central - central-publishing-maven-plugin - 0.8.0 - true - - central - - - - - + \ No newline at end of file diff --git a/data/pom.xml b/data/pom.xml index dfb3276e..cfb4a47a 100644 --- a/data/pom.xml +++ b/data/pom.xml @@ -22,49 +22,4 @@ postgis - - - UTF-8 - YYYY-MM-dd - ${maven.build.timestamp} - ${project.parent.basedir} - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - - org.apache.maven.plugins - maven-surefire-plugin - - - org.codehaus.mojo - versions-maven-plugin - - - org.apache.maven.plugins - maven-enforcer-plugin - - - org.codehaus.gmavenplus - gmavenplus-plugin - - - org.apache.maven.plugins - maven-resources-plugin - - - org.jacoco - jacoco-maven-plugin - - - org.apache.maven.plugins - maven-javadoc-plugin - - - - + \ No newline at end of file diff --git a/data/postgis/pom.xml b/data/postgis/pom.xml index a427beaf..772bb250 100644 --- a/data/postgis/pom.xml +++ b/data/postgis/pom.xml @@ -16,14 +16,6 @@ postgis Library to manage postgis database - - - UTF-8 - YYYY-MM-dd - ${maven.build.timestamp} - ${project.parent.basedir} - - @@ -37,22 +29,18 @@ com.h2database h2 - ${h2-version} org.apache.groovy groovy - ${groovy-version} org.apache.groovy groovy-sql - ${groovy-version} org.apache.groovy groovy-templates - ${groovy-version} org.orbisgis @@ -81,46 +69,16 @@ commons-dbcp commons-dbcp - 1.4 - - org.apache.felix - maven-bundle-plugin - - - org.apache.maven.plugins - maven-surefire-plugin - - - org.codehaus.mojo - versions-maven-plugin - - - org.apache.maven.plugins - maven-enforcer-plugin - org.codehaus.gmavenplus gmavenplus-plugin - - org.apache.maven.plugins - maven-javadoc-plugin - - - org.sonatype.central - central-publishing-maven-plugin - 0.8.0 - true - - central - - \ No newline at end of file diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 9acb4ba7..9034ce1e 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,2 +1,3 @@ ## Changelog for v2.1.3 +- Clean the poms + remove usused module process \ No newline at end of file diff --git a/pom.xml b/pom.xml index b60810b6..4af9fb91 100644 --- a/pom.xml +++ b/pom.xml @@ -1,158 +1,214 @@ 4.0.0 + + org.orbisgis orbisdata 2.1.3-SNAPSHOT pom + + + OrbisData + Data managing for OrbisGIS application + commons data + + Lab-STICC - CNRS UMR 6285 + https://www.labsticc.fr + + + https://github.com/orbisgis/orbisdata + + + + The GNU General Public License, Version 3.0 + http://www.gnu.org/licenses/gpl-3.0.txt + repo + + + + + + Erwan Bocher + ebocher + https://github.com/ebocher + Lab-STICC - CNRS UMR 6285 + https://www.labsticc.fr + + + Sylvain Palominos + SPalominos + https://github.com/spalominos + Lab-STICC - CNRS UMR 6285 + https://www.labsticc.fr + + + + + scm:git:https://github.com/orbisgis/orbisdata.git + scm:git:https://github.com/orbisgis/orbisdata.git + git@github.com:orbisgis/orbisdata.git + HEAD + + + + Github + https://github.com/orbisgis/orbisdata/issues + + UTF-8 - YYYY-MM-dd - ${maven.build.timestamp} - 11 - 11 - 3.5.0 - 3.2.1 11 - ${project.basedir} - - - 5.9.2 - 2.2.6-SNAPSHOT - 1.20.0 - 4.0.29 - 4.7.7 - 2.4.240 - 1.7.2 - 2.21.0 - 1.28.0 - 2.0.17 - 2.5.3 - 1.4.18 - - - 3.0.0 - 3.0.2 - 0.8.12 - 3.2.1 - 3.6.0 - 5.1.2 - 3.3.2 - 3.11.0 - 3.1.1 - 3.4.1 - 3.1.0 - 3.1.1 - 3.3.0 - 3.6.2 - 3.4.5 - 3.0.1 - 3.3.1 - 4.0.0-M11 - 3.2.2 - 3.2.2 - 2.16.0 + + ${java-version} + - - 3.1.2 + + + + repo1.maven.org + Maven2 repository 1 + https://repo1.maven.org/maven2 + + + Central Portal Snapshots + central-portal-snapshots + https://central.sonatype.com/repository/maven-snapshots/ + + false + + + true + + + - + + + central + https://repo1.maven.org/maven2 + + true + + + + - org.slf4j - slf4j-api - ${slf4j-version} + org.orbisgis + commons + ${project.version} - org.locationtech.jts - jts-core - ${jts-version} + org.orbisgis.data + data-api + ${project.version} - org.apache.commons - commons-compress - ${commons-compress-version} + org.orbisgis.data + jdbc + ${project.version} - commons-io - commons-io - ${commons-io-version} + org.orbisgis.data + h2gis + ${project.version} + + + org.orbisgis.data + postgis + ${project.version} + + org.orbisgis h2gis - ${h2gis-version} + 2.2.6-SNAPSHOT org.orbisgis h2gis-utilities - ${h2gis-version} + 2.2.6-SNAPSHOT org.orbisgis h2gis-network - ${h2gis-version} + 2.2.6-SNAPSHOT org.orbisgis postgis-jts - ${h2gis-version} + 2.2.6-SNAPSHOT org.orbisgis cts - ${cts-version} + 1.7.2 - org.orbisgis - commons - ${project.version} - compile + com.h2database + h2 + 2.4.240 - org.orbisgis.data - data-api - ${project.version} - compile + org.locationtech.jts + jts-core + 1.20.0 + + - org.orbisgis.data - jdbc - ${project.version} - compile + org.apache.groovy + groovy + 4.0.29 - - org.orbisgis.data - h2gis - ${project.version} - compile + org.apache.groovy + groovy-sql + 4.0.29 - org.orbisgis.data - postgis - ${project.version} - compile + org.apache.groovy + groovy-templates + 4.0.29 + + + + + org.slf4j + slf4j-api + 2.0.17 + + + org.apache.commons + commons-compress + 1.28.0 + + + commons-io + commons-io + 2.21.0 + + + commons-dbcp + commons-dbcp + 1.4 com.github.haifengl smile-core - ${smile-version} + 2.5.3 com.github.haifeng @@ -163,66 +219,93 @@ com.github.haifengl smile-data - ${smile-version} - - - com.thoughtworks.xstream - xstream - ${xstream-version} + 2.5.3 + org.slf4j slf4j-simple - ${slf4j-version} + 2.0.17 test org.junit.jupiter junit-jupiter-api - ${junit-version} + 5.9.2 test org.junit.jupiter junit-jupiter-engine - ${junit-version} - test - - - org.junit.jupiter - junit-jupiter-params - ${junit-version} + 5.9.2 test + + + deploy + + + + + org.apache.maven.plugins + maven-gpg-plugin + + + + + + - - - - org.apache.maven.archetype - archetype-packaging - ${archetype-packaging-version} - - - + org.apache.maven.plugins maven-clean-plugin - ${maven-clean-version} + 3.4.0 + + + org.apache.maven.plugins + maven-resources-plugin + 3.3.1 - + + org.apache.maven.plugins + maven-compiler-plugin + 3.16.0 + + + org.apache.maven.plugins + maven-install-plugin + 3.2.0 + + + org.apache.maven.plugins + maven-deploy-plugin + 3.1.2 + + + org.apache.maven.plugins + maven-assembly-plugin + 3.6.0 + + + org.codehaus.mojo + exec-maven-plugin + 3.0.0 + + org.codehaus.gmavenplus gmavenplus-plugin - ${gmaven-version} + 3.0.2 - ${maven.compiler.target} + ${java-version} @@ -233,36 +316,46 @@ - + org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-version} + maven-gpg-plugin + 3.1.0 - ${maven.compiler.source} - ${maven.compiler.target} - true + + --pinentry-mode + loopback + + + + sign-artifacts + verify + + sign + + + - org.apache.maven.plugins maven-surefire-plugin - ${maven-surefire-version} + 3.2.2 false + org.apache.maven.plugins - maven-surefire-report-plugin - ${maven-surefire-report-plugin-version} + maven-jar-plugin + 3.3.0 org.apache.felix maven-bundle-plugin - ${maven-bundle-version} + 5.1.2 true @@ -270,23 +363,11 @@ - - - org.apache.maven.plugins - maven-deploy-plugin - ${maven-deploy-version} - - - - org.apache.maven.plugins - maven-install-plugin - ${maven-install-version} - org.apache.maven.plugins maven-enforcer-plugin - ${maven-enforcer-version} + 3.4.1 enforce-versions @@ -303,7 +384,7 @@ - ${maven-version} + 3.6.3 ${java-version} @@ -317,68 +398,18 @@ org.codehaus.mojo versions-maven-plugin - ${version-maven-version} + 2.16.0 https://raw.githubusercontent.com/orbisgis/orbisgis-parents/master/maven-version-rules.xml - - - org.apache.maven.plugins - maven-project-info-reports-plugin - ${maven-project-info-reports-version} - - - - org.jacoco - jacoco-maven-plugin - ${jacoco-maven-version} - - - initialize - - prepare-agent - - - - test - - report - - - - - - - org.codehaus.mojo - exec-maven-plugin - ${exec-maven-version} - - - - org.apache.maven.plugins - maven-assembly-plugin - ${maven-assembly-version} - - - - org.apache.maven.plugins - maven-jar-plugin - ${maven-jar-version} - - - - org.apache.maven.plugins - maven-archetype-plugin - ${maven-archetype-plugin-version} - org.apache.maven.plugins maven-javadoc-plugin - ${maven-javadoc-version} + 3.6.2 all,-missing true @@ -393,10 +424,11 @@ + org.apache.maven.plugins maven-source-plugin - ${maven-source-version} + 3.2.1 attach-sources @@ -411,45 +443,12 @@ org.apache.maven.plugins maven-release-plugin - ${maven-release-version} + 3.0.1 true v@{project.version} - - - org.apache.maven.plugins - maven-gpg-plugin - ${maven-gpg-plugin-version} - - - --pinentry-mode - loopback - - - - - sign-artifacts - verify - - sign - - - - - - - org.apache.maven.plugins - maven-resources-plugin - ${maven-resources-version} - - - - org.apache.maven.plugins - maven-site-plugin - ${maven-site-version} - @@ -458,11 +457,6 @@ maven-bundle-plugin - - org.apache.maven.plugins - maven-compiler-plugin - - org.apache.maven.plugins maven-surefire-plugin @@ -482,20 +476,17 @@ false - org.apache.maven.plugins maven-enforcer-plugin - org.apache.maven.plugins maven-javadoc-plugin - - org.jacoco - jacoco-maven-plugin + org.apache.maven.plugins + maven-source-plugin org.sonatype.central @@ -508,137 +499,4 @@ - - - - deploy - - - - org.apache.maven.plugins - maven-gpg-plugin - ${maven-gpg-plugin-version} - - - --pinentry-mode - loopback - - - - - sign-artifacts - verify - - sign - - - - - - - - - - - - - - org.codehaus.mojo - versions-maven-plugin - - - - dependency-updates-report - plugin-updates-report - property-updates-report - - - - - - org.jacoco - jacoco-maven-plugin - - - org.apache.maven.plugins - maven-javadoc-plugin - - public - - - - - - - OrbisData - Data managing for OrbisGIS application - https://github.com/orbisgis/orbisdata - - - The GNU General Public License, Version 3.0 - http://www.gnu.org/licenses/gpl-3.0.txt - repo - - - - Lab-STICC - CNRS UMR 6285 - https://www.labsticc.fr - - - - Erwan Bocher - ebocher - https://github.com/ebocher - Lab-STICC - CNRS UMR 6285 - Lab-STICC - CNRS UMR 6285 - - - Sylvain Palominos - SPalominos - https://github.com/spalominos - Lab-STICC - CNRS UMR 6285 - Lab-STICC - CNRS UMR 6285 - - - - - - Github - https://github.com/orbisgis/orbisdata/issues - - - scm:git:https://github.com/orbisgis/orbisdata.git - scm:git:https://github.com/orbisgis/orbisdata.git - git@github.com:orbisgis/orbisdata.git - HEAD - - - - - repo1.maven.org - Maven2 repository 1 - https://repo1.maven.org/maven2 - - - Central Portal Snapshots - central-portal-snapshots - https://central.sonatype.com/repository/maven-snapshots/ - - false - - - true - - - - - - - central - https://repo1.maven.org/maven2 - - true - - - diff --git a/process/pom.xml b/process/pom.xml deleted file mode 100644 index 4b63b93c..00000000 --- a/process/pom.xml +++ /dev/null @@ -1,90 +0,0 @@ - - - 4.0.0 - - - - org.orbisgis - orbisdata - 2.1.3-SNAPSHOT - - process - bundle - - - - UTF-8 - YYYY-MM-dd - ${maven.build.timestamp} - ${project.parent.basedir} - - - - - - org.orbisgis.data - data-api - ${project.version} - - - org.slf4j - slf4j-api - - - org.junit.jupiter - junit-jupiter-api - test - - - org.junit.jupiter - junit-jupiter-engine - test - - - org.locationtech.jts - jts-core - test - - - org.orbisgis.data - h2gis - ${project.version} - test - - - org.slf4j - slf4j-simple - test - - - - - - - - org.apache.felix - maven-bundle-plugin - - - org.apache.maven.plugins - maven-surefire-plugin - - - org.codehaus.mojo - versions-maven-plugin - - - org.apache.maven.plugins - maven-enforcer-plugin - - - org.codehaus.gmavenplus - gmavenplus-plugin - - - org.apache.maven.plugins - maven-javadoc-plugin - - - - \ No newline at end of file diff --git a/process/src/main/java/org/orbisgis/process/GroovyProcessFactory.java b/process/src/main/java/org/orbisgis/process/GroovyProcessFactory.java deleted file mode 100644 index bb38477a..00000000 --- a/process/src/main/java/org/orbisgis/process/GroovyProcessFactory.java +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process; - -import groovy.lang.*; -import org.codehaus.groovy.runtime.InvokerHelper; -import org.orbisgis.process.api.IProcess; -import org.orbisgis.process.api.IProcessBuilder; -import org.orbisgis.process.api.IProcessFactory; -import org.orbisgis.process.api.IProcessManager; - -import java.util.Optional; -import java.util.UUID; - -/** - * Implementation of the {@link IProcessFactory} class dedicated to Groovy. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS Lab-STICC 2019-2020) - */ -public abstract class GroovyProcessFactory extends Script implements IProcessFactory, GroovyObject, GroovyInterceptable { - private final ProcessFactory factory = new ProcessFactory(); - /** - * MetaClass use for groovy methods/properties binding - */ - protected MetaClass metaClass = InvokerHelper.getMetaClass(ProcessManager.class); - private IProcessManager processManager; - - @Override - public void registerProcess(IProcess process) { - factory.registerProcess(process); - } - - @Override - public boolean isLocked() { - return factory.isLocked(); - } - - @Override - public boolean isDefault() { - return factory.isDefault(); - } - - @Override - public Optional getProcess(String processId) { - return factory.getProcess(processId); - } - - @Override - public IProcessBuilder create() { - return factory.create(); - } - - @Override - public Optional create(@DelegatesTo(IProcessBuilder.class) Closure cl) { - if(cl == null) { - return Optional.empty(); - } - else { - IProcessBuilder builder = new ProcessBuilder(this, this); - Closure code = cl.rehydrate(builder, this, this); - code.setResolveStrategy(Closure.DELEGATE_FIRST); - return Optional.of(((IProcessBuilder) code.call()).getProcess()); - } - } - - @Override - public Object invokeMethod(String name, Object args) { - if(name != null) { - Object obj = getMetaClass().invokeMethod(this, name, args); - if(obj instanceof Optional){ - return ((Optional)obj).orElse(null); - } - else { - return obj; - } - } - else { - return null; - } - } - - @Override - public Object getProperty(String name) { - if(name == null) { - return null; - } - Optional p = getProcess(name); - if(p.isPresent()){ - return p.get().newInstance(); - } - else{ - Object o = getMetaClass().getProperty(this, name); - if(o instanceof Optional){ - return ((Optional) o).orElse(null); - } - return o; - } - } - - @Override - public Optional getProcessManager() { - return Optional.ofNullable(processManager); - } - - @Override - public void setProcessManager(IProcessManager processManager) { - this.processManager = processManager; - } - - /** - * Prefix the given String with '_' and an UUID. - * - * @param name String to prefix - * @return The prefixed String - */ - public static String prefix(String name) { - return UUID.randomUUID().toString().replaceAll("-", "_") + "_" + name; - } - - /** - * Prefix the given String with the given prefix. - * - * @param prefix Prefix - * @param name String to prefix - * @return The prefixed String - */ - public static String prefix(String prefix, String name) { - return prefix == null || prefix.isEmpty() ? name : prefix + "_" + name; - } - - /** - * Postfix the given String with '_' and an UUID.. - * - * @param name String to postfix - * @return The postfix String - */ - public static String postfix(String name) { - return name + "_" + UUID.randomUUID().toString().replaceAll("-", "_"); - } - - /** - * Postfix the given String with the given postfix. - * - * @param postfix Postfix - * @param name String to postfix - * @return The postfix String - */ - public static String postfix(String name, String postfix) { - return postfix == null || postfix.isEmpty() ? name : name + "_" + postfix; - } -} diff --git a/process/src/main/java/org/orbisgis/process/GroovyProcessManager.java b/process/src/main/java/org/orbisgis/process/GroovyProcessManager.java deleted file mode 100644 index 3a7a85de..00000000 --- a/process/src/main/java/org/orbisgis/process/GroovyProcessManager.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process; - -import groovy.lang.*; -import org.codehaus.groovy.runtime.InvokerHelper; -import org.orbisgis.process.api.IProcess; -import org.orbisgis.process.api.IProcessBuilder; -import org.orbisgis.process.api.IProcessFactory; -import org.orbisgis.process.api.IProcessManager; - -import java.util.List; -import java.util.Map; -import java.util.Optional; - -/** - * Implementation of the {@link IProcessManager} class dedicated to Groovy. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS Lab-STICC 2020) - */ -public abstract class GroovyProcessManager extends Script implements IProcessManager, GroovyObject, GroovyInterceptable { - - /** - * Internal ProcessManager. - */ - private final IProcessManager pm = new ProcessManager(); - /** - * MetaClass use for groovy methods/properties binding - */ - protected MetaClass metaClass = InvokerHelper.getMetaClass(GroovyProcessManager.class); - - @Override - public IProcessBuilder create() { - return pm.create(); - } - - @Override - public Optional create(Closure cl) { - return pm.create(cl); - } - - @Override - public List factoryIds() { - return pm.factoryIds(); - } - - @Override - public IProcessFactory factory(String identifier) { - return pm.factory(identifier); - } - - @Override - public IProcessFactory factory() { - return pm.factory(); - } - - @Override - public Optional process(String processId) { - return pm.process(processId); - } - - @Override - public Optional process(String processId, String factoryId) { - return pm.process(processId, factoryId); - } - - @Override - public boolean registerFactory(String id, IProcessFactory factory) { - boolean ret = pm.registerFactory(id, factory); - factory.setProcessManager(this); - return ret; - } - - @Override - public void register(Map map) { - pm.register(map); - map.values().forEach(factory -> factory.setProcessManager(this)); - } - - public void register(List> list) throws IllegalAccessException, InstantiationException { - if(list != null) { - for (Class clazz : list) { - GroovyProcessFactory gpf = clazz.newInstance(); - gpf.run(); - registerFactory(clazz.getSimpleName(), gpf); - gpf.setProcessManager(this); - } - } - } - - public static GroovyProcessManager load(Class clazz) throws IllegalAccessException, InstantiationException { - GroovyProcessManager gpm = clazz.newInstance(); - gpm.run(); - return gpm; - } - - public void setLogger(GroovyObject logger) { - factoryIds().stream() - .map(this::factory) - .filter(pf -> pf instanceof GroovyProcessFactory) - .map(pf -> (GroovyProcessFactory)pf); - } - - @Override - public Object invokeMethod(String name, Object args) { - if(name != null) { - Object obj = getMetaClass().invokeMethod(this, name, args); - if(obj instanceof Optional){ - return ((Optional)obj).orElse(null); - } - else { - return obj; - } - } - else { - return null; - } - } - - @Override - public Object getProperty(String name) { - if(name == null) { - return null; - } - if(factoryIds().contains(name)){ - return factory(name); - } - else{ - return getMetaClass().getProperty(this, name); - } - } - - @Override - public MetaClass getMetaClass() { - return metaClass; - } - - @Override - public void setMetaClass(MetaClass metaClass) { - this.metaClass = metaClass == null ? InvokerHelper.getMetaClass(this.getClass()) : metaClass; - } -} diff --git a/process/src/main/java/org/orbisgis/process/Linker.java b/process/src/main/java/org/orbisgis/process/Linker.java deleted file mode 100644 index 2effb445..00000000 --- a/process/src/main/java/org/orbisgis/process/Linker.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process; - -import org.orbisgis.process.api.ILinker; -import org.orbisgis.process.api.inoutput.IInOutPut; -import org.orbisgis.process.api.inoutput.IInput; -import org.orbisgis.process.api.inoutput.IOutput; -import org.orbisgis.process.inoutput.Input; -import org.orbisgis.process.inoutput.Output; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.*; - -/** - * This class manage the link between inputs, outputs and aliases. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS Lab-STICC 2019-2020) - */ -public class Linker implements ILinker { - - private static final Logger LOGGER = LoggerFactory.getLogger(Linker.class); - /** - * Array of inputs - */ - private final List inputList = new ArrayList<>(); - /** - * Array of outputs - */ - private final List outputList = new ArrayList<>(); - /** - * Map with the input as key and the output as value. - */ - private final Map inputOutputMap; - /** - * Map of the aliases as key and the list of input/output as value. - */ - private final Map> aliases; - private final LinkedList inputs = new LinkedList<>(); - private final LinkedList outputs = new LinkedList<>(); - - /** - * Main constructor. - * - * @param inOutPuts Inputs or outputs to link. - */ - protected Linker(IInOutPut... inOutPuts) { - inputOutputMap = new HashMap<>(); - aliases = new HashMap<>(); - if (inOutPuts == null || inOutPuts.length == 0) { - LOGGER.error("The input/output list should not be empty."); - return; - } - boolean allInputs = true; - boolean allOutputs = true; - for (IInOutPut inOutPut : inOutPuts) { - if (!inOutPut.getProcess().isPresent()) { - allOutputs = false; - allInputs = false; - } - else { - if (inOutPut.getProcess().get().getInputs().stream() - .noneMatch(input -> input.getName().equals(inOutPut.getName()))) { - allInputs = false; - } - if (inOutPut.getProcess().get().getOutputs().stream() - .noneMatch(output -> output.getName().equals(inOutPut.getName()))) { - allOutputs = false; - } - } - } - if (!allInputs && !allOutputs) { - LOGGER.error("Input and outputs should not be mixed."); - } else if (allInputs) { - inputList.addAll(Arrays.asList(inOutPuts)); - } else { - outputList.addAll(Arrays.asList(inOutPuts)); - } - } - - @Override - public void to(IInOutPut... inOutPuts) { - if (inOutPuts == null || inOutPuts.length == 0) { - LOGGER.error("The input/output list should not be empty."); - return; - } - if (Arrays.stream(inOutPuts).anyMatch(iInOutPut -> iInOutPut instanceof IInput) && - Arrays.stream(inOutPuts).anyMatch(iInOutPut -> iInOutPut instanceof IOutput)) { - LOGGER.error("Input and outputs should not be mixed."); - return; - } - if (!inputList.isEmpty()) { - if (Arrays.stream(inOutPuts).noneMatch(iInOutPut -> iInOutPut instanceof IOutput)) { - LOGGER.error("Inputs should be link to outputs."); - return; - } - outputList.addAll(Arrays.asList(inOutPuts)); - } else if (!outputList.isEmpty()) { - if (Arrays.stream(inOutPuts).noneMatch(iInOutPut -> iInOutPut instanceof IInput)) { - LOGGER.error("Outputs should be link to inputs."); - return; - } - inputList.addAll(Arrays.asList(inOutPuts)); - } - for (IInOutPut input : inputList) { - for (IInOutPut output : outputList) { - inputOutputMap.put(input, output); - } - } - } - - @Override - public void to(String alias) { - List inOutPuts = new ArrayList<>(); - inOutPuts.addAll(inputList); - inOutPuts.addAll(outputList); - for (IInOutPut inOutPut : inOutPuts) { - if (aliases.get(alias) != null) { - aliases.get(alias).add(inOutPut); - } else { - aliases.put(alias, new ArrayList<>(inOutPuts)); - } - } - if (!inputList.isEmpty() && - inputList.stream().map(IInOutPut::getName).map(Optional::get) - .noneMatch(name -> name.equals(alias))) { - inputs.add(new Input().name(alias)); - } - if (!outputList.isEmpty() && - outputList.stream().map(IInOutPut::getName).map(Optional::get) - .noneMatch(name -> name.equals(alias))) { - outputs.add(new Output().name(alias)); - } - } - - public Map> getAliases() { - return aliases; - } - - public Map getInputOutputMap() { - return inputOutputMap; - } - - public LinkedList getInputs() { - return inputs; - } - - public LinkedList getOutputs() { - return outputs; - } -} diff --git a/process/src/main/java/org/orbisgis/process/Process.java b/process/src/main/java/org/orbisgis/process/Process.java deleted file mode 100644 index 2acb00f9..00000000 --- a/process/src/main/java/org/orbisgis/process/Process.java +++ /dev/null @@ -1,456 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process; - -import groovy.lang.Closure; -import groovy.lang.GroovyInterceptable; -import groovy.lang.GroovyObject; -import groovy.lang.MetaClass; -import org.codehaus.groovy.runtime.InvokerHelper; -import org.orbisgis.process.api.IProcess; -import org.orbisgis.process.api.inoutput.IInOutPut; -import org.orbisgis.process.api.inoutput.IInput; -import org.orbisgis.process.api.inoutput.IOutput; -import org.orbisgis.process.inoutput.Input; -import org.orbisgis.process.inoutput.Output; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.*; -import java.util.stream.Collectors; - -/** - * Implementation of the {@link IProcess} interface dedicated to the local creation and execution of process (no link with - * WPS process for now). - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS Lab-STICC 2019-2020) - */ -public class Process implements IProcess, GroovyObject, GroovyInterceptable { - - private static final Logger LOGGER = LoggerFactory.getLogger(Process.class); - - /** - * Title of the process - */ - private String title; - /** - * Process version - */ - private String version; - /** - * Human readable description of the process - */ - private String description; - /** - * List of simple keyword (one word) of the process - */ - private String[] keywords; - /** - * List of inputs - */ - private LinkedList inputs; - /** - * List of outputs - */ - private LinkedList outputs; - /** - * Closure containing the code to execute on the process execution - */ - private Closure closure; - /** - * Map of the process Result - */ - private Map resultMap; - /** - * Unique identifier - */ - private String identifier; - /** - * MetaClass use for groovy methods/properties binding - */ - private MetaClass metaClass; - /** - * Map of the defaults values - */ - private Map defaultValues; - - /** - * Create a new Process with its title, description, keyword array, input map, output map, version - * and the closure containing the code to execute on the process execution. The Closure will receive all the input - * as parameter in the same order as the order of the input map. So the list of parameter of the closure, the - * array of input and the map of input given on the execution should have the same size and meaning. - * - * @param title Title of the process. - * @param description Human readable description of the process. - * @param keywords List of simple keyword (one word) of the process. - * @param inputs Map of inputs with the name as key and the input class as value. The names will be used to link - * the closure parameters with the execution input data map. - * @param outputs Map of outputs with the name as key and the output class as value. Those names will be used to - * generate the Map of the getResults Method. - * @param version Process version. - * @param closure Closure containing the code to execute on the process execution. - */ - Process(String title, String description, String[] keywords, LinkedHashMap inputs, - LinkedHashMap outputs, String version, Closure closure) { - this(null, title, description, keywords, inputs, outputs, version, closure); - } - - /** - * Create a new Process with its title, description, keyword array, input map, output map, version - * and the closure containing the code to execute on the process execution. The Closure will receive all the input - * as parameter in the same order as the order of the input map. So the list of parameter of the closure, the - * array of input and the map of input given on the execution should have the same size and meaning. - * - * @param id Identifier of the process. - * @param title Title of the process. - * @param description Human readable description of the process. - * @param keywords List of simple keyword (one word) of the process. - * @param inputs Map of inputs with the name as key and the input class as value. The names will be used to link - * the closure parameters with the execution input data map. - * @param outputs Map of outputs with the name as key and the output class as value. Those names will be used to - * generate the Map of the getResults Method. - * @param version Process version. - * @param closure Closure containing the code to execute on the process execution. - */ - Process(String id, String title, String description, String[] keywords, LinkedHashMap inputs, - LinkedHashMap outputs, String version, Closure closure) { - if (inputs != null && closure != null && closure.getMaximumNumberOfParameters() != inputs.size()) { - LOGGER.error("The number of the closure parameters and the number of process input names are different."); - return; - } - this.title = title; - this.version = version; - this.description = description; - this.keywords = keywords; - this.inputs = new LinkedList<>(); - this.defaultValues = new HashMap<>(); - if (inputs != null) { - for (Map.Entry entry : inputs.entrySet()) { - Input input; - if (entry.getValue() instanceof Class) { - input = new Input().type((Class) entry.getValue()); - } else if (entry.getValue() instanceof Input) { - input = (Input) entry.getValue(); - if (input.isOptional()) { - this.defaultValues.put(entry.getKey(), input.getDefaultValue().orElse(null)); - } - } else { - input = new Input() - .type(entry.getValue().getClass()) - .optional(entry.getValue()); - this.defaultValues.put(entry.getKey(), entry.getValue()); - } - input.process(this).name(entry.getKey()); - this.inputs.add(input); - } - } - this.outputs = new LinkedList<>(); - if (outputs != null) { - for (Map.Entry entry : outputs.entrySet()) { - Output output; - if (entry.getValue() instanceof Class) { - output = new Output().type((Class) entry.getValue()); - } else { - output = ((Output) entry.getValue()); - } - output.process(this).name(entry.getKey()); - this.outputs.add(output); - } - } - this.closure = closure; - this.resultMap = new HashMap<>(); - this.identifier = id == null ? UUID.randomUUID().toString() : id; - this.metaClass = InvokerHelper.getMetaClass(getClass()); - } - - @Override - public IProcess newInstance() { - Process process = new Process(title, description, keywords, null, null, - version, closure); - process.inputs = this.inputs.stream().map(IInput::copy).collect(Collectors.toCollection(LinkedList::new)); - process.inputs.forEach(in -> in.setProcess(process)); - process.outputs = this.outputs.stream().map(IOutput::copy).collect(Collectors.toCollection(LinkedList::new)); - process.outputs.forEach(out -> out.setProcess(process)); - process.defaultValues = this.defaultValues; - return process; - } - - @Override - public IProcess copy() { - Process process = new Process(title, description, keywords, null, null, - version, closure); - process.inputs = this.inputs.stream().map(IInput::copy).collect(Collectors.toCollection(LinkedList::new)); - process.inputs.forEach(in -> in.setProcess(process)); - process.outputs = this.outputs.stream().map(IOutput::copy).collect(Collectors.toCollection(LinkedList::new)); - process.outputs.forEach(out -> out.setProcess(process)); - process.defaultValues = this.defaultValues; - process.identifier = this.identifier; - return process; - } - - /** - * Return the curry closure taking into account the optional arguments. - * - * @param inputDataMap Map containing the data for the execution of the closure. This map may not contains several - * inputs. - * @param cl Closure to curry. - * @return The closure if the missing inputs are all optional, false otherwise. - */ - private Closure getClosureWithCurry(LinkedHashMap inputDataMap, Closure cl) { - int curryIndex = 0; - List names = inputs.stream().map(IInOutPut::getName).map(Optional::get).collect(Collectors.toCollection(LinkedList::new)); - for (String name : names) { - if (!inputDataMap.containsKey(name)) { - if (defaultValues.get(name) == null) { - LOGGER.error("The parameter " + name + " has no default value."); - return null; - } - cl = cl.ncurry(curryIndex, defaultValues.get(name)); - curryIndex--; - } - curryIndex++; - } - return cl; - } - - /** - * Returns the input data as an Object array. - * - * @param inputDataMap Map containing the data for the execution of the closure. - * @return The casted input data as an Object array. - */ - private Object[] getClosureArgs(LinkedHashMap inputDataMap) { - return inputs - .stream() - .map(IInOutPut::getName) - .filter(Optional::isPresent) - .map(Optional::get) - .filter(inputDataMap::containsKey) - .map(inputDataMap::get) - .toArray(); - } - - @Override - public boolean execute(LinkedHashMap inputDataMap) { - LinkedHashMap map = (inputDataMap == null ? new LinkedHashMap<>() : inputDataMap); - if (closure == null) { - LOGGER.error("The process should have a Closure defined."); - return false; - } - LOGGER.debug("Starting the execution of '" + this.getTitle() + "'."); - if ((inputs.size() < map.size() || inputs.size() - defaultValues.size() > map.size())) { - LOGGER.error("The number of the input data map and the number of process input are different, should" + - " be between " + (closure.getMaximumNumberOfParameters() - defaultValues.size()) + " and " + - closure.getMaximumNumberOfParameters() + "."); - return false; - } - Object result; - try { - if (inputs.size() != 0) { - Closure cl = getClosureWithCurry(map, closure); - if (cl == null) { - return false; - } - result = cl.call(getClosureArgs(map)); - } else { - result = closure.call(); - } - } catch (Exception e) { - LOGGER.error("Error while executing the process.", e); - return false; - } - if (outputs.size() == 0) { - resultMap = new HashMap<>(); - resultMap.put("result", result); - return true; - } - else if (outputs.size() == 1) { - if(result == null){ - return false; - } - if(result instanceof Map){ - resultMap.putAll(((Map) result)); - return true; - } - else { - resultMap = new HashMap<>(); - resultMap.put("result", result); - return true; - } - } else if (result == null) { - return false; - } else { - return checkResults(result); - } - } - - /** - * Check that the process result contains all the process outputs and store the results of the process execution. - * - * @param result Result of the process execution. - * @return True if the execution hes been successful, false otherwise. - */ - private boolean checkResults(Object result) { - Map map; - if (!(result instanceof Map)) { - return false; - } else { - map = (Map) result; - } - boolean isResultValid = outputs.stream() - .map(IInOutPut::getName) - .filter(Optional::isPresent) - .map(Optional::get) - .allMatch(map::containsKey); - LOGGER.debug("End of the execution of '" + this.getTitle() + "'."); - if (!isResultValid) { - LOGGER.debug("The output of the execution are not compatible with process output."); - return false; - } else { - resultMap.putAll(map); - return true; - } - } - - @Override - public Optional getTitle() { - return Optional.ofNullable(title); - } - - @Override - public Optional getVersion() { - return Optional.ofNullable(version); - } - - @Override - public Optional getDescription() { - return Optional.ofNullable(description); - } - - @Override - public Optional getKeywords() { - return Optional.ofNullable(keywords); - } - - @Override - public Map getResults() { - return resultMap; - } - - @Override - public String getIdentifier() { - return identifier; - } - - @Override - public List getInputs() { - return inputs; - } - - @Override - public List getOutputs() { - return outputs; - } - - //Groovy object methods - @Override - public Object invokeMethod(String name, Object args) { - if(name == null) { - return null; - } - Object obj = metaClass.invokeMethod(this, name, args); - if(obj instanceof Optional) { - return ((Optional)obj).orElse(null); - } - else { - return obj; - } - } - - @Override - public Object getProperty(String propertyName) { - if(propertyName == null){ - return null; - } - if (inputs.stream() - .map(IInOutPut::getName) - .filter(Optional::isPresent) - .map(Optional::get) - .anyMatch(propertyName::equals)) { - return new Input().process(this).name(propertyName); - } - if (outputs.stream() - .map(IInOutPut::getName) - .filter(Optional::isPresent) - .map(Optional::get) - .anyMatch(propertyName::equals)) { - return new Output().process(this).name(propertyName); - } - Object obj = metaClass.getProperty(this, propertyName); - if(obj instanceof Optional) { - return ((Optional)obj).orElse(null); - } - else { - return obj; - } - } - - @Override - public MetaClass getMetaClass() { - return metaClass; - } - - @Override - public void setMetaClass(MetaClass metaClass) { - this.metaClass = metaClass == null ? InvokerHelper.getMetaClass(this.getClass()) : metaClass; - } - - @Override - public boolean call(LinkedHashMap inputDataMap) { - return execute(inputDataMap); - } - - @Override - public boolean equals(Object obj){ - if(! (obj instanceof Process)){ - return false; - } - Process p = (Process)obj; - return Objects.equals(this.getIdentifier(), p.getIdentifier()); - } -} \ No newline at end of file diff --git a/process/src/main/java/org/orbisgis/process/ProcessBuilder.java b/process/src/main/java/org/orbisgis/process/ProcessBuilder.java deleted file mode 100644 index 47fe1d2e..00000000 --- a/process/src/main/java/org/orbisgis/process/ProcessBuilder.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process; - -import groovy.lang.Closure; -import org.orbisgis.commons.utilities.CheckUtils; -import org.orbisgis.process.api.IProcess; -import org.orbisgis.process.api.IProcessBuilder; -import org.orbisgis.process.api.IProcessFactory; - -import java.util.LinkedHashMap; - -/** - * Implementation of the interface {@link IProcessBuilder}. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS Lab-STICC 2019-2020) - */ -public class ProcessBuilder implements IProcessBuilder { - - /** - * {@link IProcessFactory} used to register the process. - */ - private final IProcessFactory factory; - /** - * Delegate for the closure - */ - private final Object delegate; - /** - * Identifier of the process. - */ - private String id; - /** - * Title of the process. - */ - private String title; - /** - * Human readable description of the process. - */ - private String description; - /** - * List of simple keyword (one word) of the process. - */ - private String[] keywords; - /** - * @link LinkedHashMap} of inputs with the name as key and the input Object as value. - */ - private LinkedHashMap inputs; - /** - * {@link LinkedHashMap} of outputs with the name as key and the output Object as value. - */ - private LinkedHashMap outputs; - /** - * Process version. - */ - private String version; - /** - * {@link Closure} containing the code to execute on the process execution. - */ - private Closure closure; - - /** - * Main constructor. - * - * @param factory {@link IProcessFactory} used to register the process. - * @param delegate Delegate for the closure. - */ - public ProcessBuilder(IProcessFactory factory, Object delegate) { - CheckUtils.checkNotNull(factory, "The ProcessFactory should not be null."); - CheckUtils.checkNotNull(delegate, "The Closure delegate object should not be null."); - this.factory = factory; - this.delegate = delegate; - } - - @Override - public IProcessBuilder id(String id) { - this.id = id; - return this; - } - - @Override - public IProcessBuilder title(String title) { - this.title = title; - return this; - } - - @Override - public IProcessBuilder description(String description) { - this.description = description; - return this; - } - - @Override - public IProcessBuilder keywords(String[] keywords) { - this.keywords = keywords; - return this; - } - - @Override - public IProcessBuilder inputs(LinkedHashMap inputs) { - this.inputs = inputs; - return this; - } - - @Override - public IProcessBuilder outputs(LinkedHashMap outputs) { - this.outputs = outputs; - return this; - } - - @Override - public IProcessBuilder version(String version) { - this.version = version; - return this; - } - - @Override - public IProcessBuilder run(Closure closure) { - this.closure = closure; - if (closure != null) { - this.closure.setDelegate(delegate); - this.closure.setResolveStrategy(Closure.DELEGATE_FIRST); - } - return this; - } - - @Override - public IProcess getProcess() { - IProcess process = new Process(id, title, description, keywords, inputs, outputs, version, closure); - factory.registerProcess(process); - return process; - } -} diff --git a/process/src/main/java/org/orbisgis/process/ProcessFactory.java b/process/src/main/java/org/orbisgis/process/ProcessFactory.java deleted file mode 100644 index 7489783b..00000000 --- a/process/src/main/java/org/orbisgis/process/ProcessFactory.java +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process; - -import groovy.lang.*; -import org.codehaus.groovy.runtime.InvokerHelper; -import org.orbisgis.process.api.IProcess; -import org.orbisgis.process.api.IProcessBuilder; -import org.orbisgis.process.api.IProcessFactory; -import org.orbisgis.process.api.IProcessManager; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -/** - * Implementation of the {@link IProcessFactory}. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS Lab-STICC 2019-2020) - */ -public class ProcessFactory implements IProcessFactory, GroovyObject, GroovyInterceptable { - - /** - * Indicated if the process creation is allowed. - */ - protected boolean isLock; - /** - * Indicates if the factory should be used as the default one. - */ - protected boolean isDefault; - /** - * List of the processes created with this factory. - */ - private final List processList; - private IProcessManager processManager; - /** - * {@link MetaClass} - */ - private MetaClass metaClass = InvokerHelper.getMetaClass(ProcessFactory.class); - - /** - * Default empty constructor. - */ - ProcessFactory() { - this(false, false); - } - - /** - * Constructor allowing to configure the factory. - * - * @param lock If true, not process creation allowed. - * @param dflt If true, it will be selected as the default factory. - */ - ProcessFactory(boolean lock, boolean dflt) { - isLock = lock; - isDefault = dflt; - processList = new ArrayList<>(); - } - - @Override - public void registerProcess(IProcess process) { - if (!isLock && process != null) { - List list = new ArrayList<>(); - for (IProcess p : processList) { - if (p.getIdentifier().equals(process.getIdentifier())) { - list.add(p); - } - } - processList.removeAll(list); - processList.add(process); - } - } - - @Override - public boolean isLocked() { - return isLock; - } - - @Override - public boolean isDefault() { - return isDefault; - } - - @Override - public Optional getProcess(String processId) { - return processList - .stream() - .filter(iProcess -> iProcess.getIdentifier().equals(processId)) - .findFirst() - .map(IProcess::newInstance); - } - - @Override - public IProcessBuilder create() { - return new ProcessBuilder(this, this); - } - - @Override - public Optional create(@DelegatesTo(IProcessBuilder.class) Closure cl) { - if(cl == null) { - return Optional.empty(); - } - else { - IProcessBuilder builder = new ProcessBuilder(this, this); - Closure code = cl.rehydrate(builder, this, this); - code.setResolveStrategy(Closure.DELEGATE_FIRST); - return Optional.of(((IProcessBuilder) code.call()).getProcess()); - } - } - - @Override - public Optional getProcessManager() { - return Optional.ofNullable(processManager); - } - - @Override - public void setProcessManager(IProcessManager processManager) { - this.processManager = processManager; - } - - @Override - public Object invokeMethod(String name, Object args) { - if(name != null) { - Object obj = this.metaClass.invokeMethod(this, name, args); - if(obj instanceof Optional){ - return ((Optional)obj).orElse(null); - } - else { - return obj; - } - } - else { - return null; - } - } - - @Override - public MetaClass getMetaClass() { - return metaClass; - } - - @Override - public void setMetaClass(MetaClass metaClass) { - this.metaClass = metaClass == null ? InvokerHelper.getMetaClass(this.getClass()) : metaClass; - } -} diff --git a/process/src/main/java/org/orbisgis/process/ProcessManager.java b/process/src/main/java/org/orbisgis/process/ProcessManager.java deleted file mode 100644 index 1634c0e8..00000000 --- a/process/src/main/java/org/orbisgis/process/ProcessManager.java +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process; - -import groovy.lang.*; -import org.codehaus.groovy.runtime.InvokerHelper; -import org.orbisgis.process.api.IProcess; -import org.orbisgis.process.api.IProcessBuilder; -import org.orbisgis.process.api.IProcessFactory; -import org.orbisgis.process.api.IProcessManager; - -import java.util.*; - -/** - * Implementation of IProcessManager as a singleton. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS Lab-STICC 2019-2020) - */ -public class ProcessManager implements IProcessManager, GroovyObject, GroovyInterceptable { - - /** - * Default factory name - */ - private static final String DEFAULT_FACTORY_NAME = "Default"; - /** - * Unique ProcessManager instance. - */ - private static ProcessManager instance = null; - - /** - * Map of the process factory and their identifier. - */ - private final Map processFactoryMap; - /** - * Default factory - */ - private final IProcessFactory defaultFactory; - /** - * MetaClass use for groovy methods/properties binding - */ - protected MetaClass metaClass = InvokerHelper.getMetaClass(ProcessManager.class); - - /** - * Private constructor in order to make it unique. - */ - protected ProcessManager() { - defaultFactory = new ProcessFactory(false, true); - defaultFactory.setProcessManager(this); - processFactoryMap = new HashMap<>(); - processFactoryMap.put(DEFAULT_FACTORY_NAME, defaultFactory); - } - - /** - * Return the unique instance of the ProcessManager. - * - * @return The unique instance of the ProcessManager. - */ - public static ProcessManager getProcessManager() { - if (instance == null) { - instance = new ProcessManager(); - } - return instance; - } - - @Override - public IProcessBuilder create() { - return new ProcessBuilder(defaultFactory, defaultFactory); - } - - @Override - public Optional create(@DelegatesTo(IProcessBuilder.class) Closure cl) { - if(cl == null) { - return Optional.empty(); - } - IProcessBuilder builder = new ProcessBuilder(defaultFactory, defaultFactory); - Closure code = cl.rehydrate(builder, this, this); - code.setResolveStrategy(Closure.DELEGATE_FIRST); - code.call(); - Process p = (Process)builder.getProcess(); - return Optional.of(p); - } - - @Override - public List factoryIds() { - return new ArrayList<>(processFactoryMap.keySet()); - } - - @Override - public IProcessFactory factory(String identifier) { - if(identifier == null) { - return factory(); - } - if (!processFactoryMap.containsKey(identifier)) { - IProcessFactory factory = new ProcessFactory(); - factory.setProcessManager(this); - processFactoryMap.put(identifier, factory); - } - return processFactoryMap.get(identifier); - } - - public static IProcessFactory createFactory(String identifier) { - return getProcessManager().factory( - identifier != null && !identifier.isEmpty() ? identifier : "factory_"+ UUID.randomUUID()); - } - - @Override - public IProcessFactory factory() { - return defaultFactory; - } - - public static IProcessFactory createFactory() { - return getProcessManager().factory(); - } - - @Override - public Optional process(String processId) { - return factory().getProcess(processId); - } - - @Override - public Optional process(String processId, String factoryId) { - return factory(factoryId).getProcess(processId); - } - - @Override - public boolean registerFactory(String id, IProcessFactory factory) { - if(factory == null || id == null || id.isEmpty() || processFactoryMap.containsKey(id)) { - return false; - } - processFactoryMap.put(id, factory); - factory.setProcessManager(this); - return true; - } - - @Override - public void register(Map map) { - if(map != null) { - map.forEach(this::registerFactory); - } - } - - @Override - public Object invokeMethod(String name, Object args) { - if(name != null) { - Object obj = getMetaClass().invokeMethod(this, name, args); - if(obj instanceof Optional){ - return ((Optional)obj).orElse(null); - } - else { - return obj; - } - } - else { - return null; - } - } - - @Override - public MetaClass getMetaClass() { - return metaClass; - } - - @Override - public void setMetaClass(MetaClass metaClass) { - this.metaClass = metaClass == null ? InvokerHelper.getMetaClass(this.getClass()) : metaClass; - } -} diff --git a/process/src/main/java/org/orbisgis/process/ProcessMapper.java b/process/src/main/java/org/orbisgis/process/ProcessMapper.java deleted file mode 100644 index 80eae891..00000000 --- a/process/src/main/java/org/orbisgis/process/ProcessMapper.java +++ /dev/null @@ -1,477 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process; - -import groovy.lang.GroovyInterceptable; -import groovy.lang.GroovyObject; -import groovy.lang.MetaClass; -import org.codehaus.groovy.runtime.InvokerHelper; -import org.orbisgis.process.api.ILinker; -import org.orbisgis.process.api.IProcess; -import org.orbisgis.process.api.IProcessMapper; -import org.orbisgis.process.api.check.ICheckDataBuilder; -import org.orbisgis.process.api.check.IProcessCheck; -import org.orbisgis.process.api.inoutput.IInOutPut; -import org.orbisgis.process.api.inoutput.IInput; -import org.orbisgis.process.api.inoutput.IOutput; -import org.orbisgis.process.check.CheckDataBuilder; -import org.orbisgis.process.check.ProcessCheck; -import org.orbisgis.process.inoutput.Input; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.*; -import java.util.stream.Collectors; - -/** - * Implementation of IProcessMapper. This class should not be used will using a IProcess executing and mapping - * processes is easier. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS Lab-STICC 2019-2020) - */ -public class ProcessMapper implements IProcessMapper, GroovyObject, GroovyInterceptable { - - private static final Logger LOGGER = LoggerFactory.getLogger(ProcessMapper.class); - - private LinkedList inputs; - private LinkedList outputs; - private List> executionTree; - private Map results; - /** - * List of all the processes used in this mapper. - */ - private List processList; - /** - * List of check to do before process execution - */ - private final List beforeList; - /** - * List of check to do after process execution - */ - private final List afterList; - /** - * List of linker used to rebuild the execution. - */ - private List linkerList; - /** - * Map with the input as key and the output as value. - */ - private final Map inputOutputMap; - /** - * Map of the aliases as key and the list of input/output as value. - */ - private final Map> aliases; - /** - * Title of the mapper. - */ - private final String title; - - /** - * Groovy {@link MetaClass}. - */ - protected MetaClass metaClass = InvokerHelper.getMetaClass(ProcessMapper.class); - - /** - * Main empty constructor. - */ - public ProcessMapper() { - this("mapper_" + UUID.randomUUID()); - } - - /** - * Main constructor. - */ - public ProcessMapper(String title) { - this.title = title; - beforeList = new ArrayList<>(); - afterList = new ArrayList<>(); - linkerList = new ArrayList<>(); - inputs = new LinkedList<>(); - outputs = new LinkedList<>(); - aliases = new HashMap<>(); - inputOutputMap = new HashMap<>(); - } - - /** - * Return the alias of the given input or output. - * - * @param name Name of the alias. - * @param process {@link IProcess} containing the input/output with the alias. - * @return The alias name if there is one, null otherwise. - */ - private String getAlias(String name, IProcess process) { - return aliases.entrySet() - .stream() - .filter(entry -> - entry.getValue().stream().map(IInOutPut::getName).map(Optional::get).anyMatch(n -> n.equals(name)) && - entry.getValue().stream().map(IInOutPut::getProcess).map(Optional::get).anyMatch(p -> p.equals(process))) - .findFirst() - .orElse(new AbstractMap.SimpleEntry<>(null, null)) - .getKey(); - } - - /** - * Fill the process list. - */ - private void fillProcessList() { - processList.addAll( - inputOutputMap.keySet().stream() - .map(IInOutPut::getProcess) - .filter(Optional::isPresent) - .map(Optional::get) - .collect(Collectors.toList())); - processList.addAll( - inputOutputMap.values().stream() - .map(IInOutPut::getProcess) - .filter(Optional::isPresent) - .map(Optional::get) - .collect(Collectors.toList())); - processList.addAll( - aliases.values().stream() - .flatMap(Collection::stream) - .map(IInOutPut::getProcess) - .map(Optional::get) - .collect(Collectors.toList())); - //Keep distinct processes - processList = processList.stream().distinct().collect(Collectors.toList()); - } - - private Collection collectInput(IInput input, IProcess process) { - Collection collection = new ArrayList<>(); - if (inputOutputMap.keySet().stream().noneMatch(in -> in.equals(input))) { - if (getAlias(input.getName().orElse(null), process) == null) { - inputs.add(input); - } - collection.add(new Input().process(process).name(input.getName().orElse(null))); - } - return collection; - } - - private void collectOutput(IOutput output, IProcess process) { - if (inputOutputMap.values().stream().noneMatch(out -> out.equals(output)) && - getAlias(output.getName().orElse(null), process) == null) { - outputs.add(output); - } - } - - /** - * Collect all the not linked inputs/outputs to set the {@link ProcessMapper} inputs/outputs. - * - * @return The list of available inputs. - */ - private List collectInputOutput() { - List availableIn = new ArrayList<>(); - for (IProcess process : processList) { - process.getInputs().forEach(input -> availableIn.addAll(collectInput(input, process))); - process.getOutputs().forEach(output -> collectOutput(output, process)); - } - return availableIn; - } - - private void buildExecutionTreeLevel(List iterableProcessList, List availableIn, - int i, List newIn) { - for (Iterator iterator = iterableProcessList.iterator(); iterator.hasNext(); ) { - IProcess process = iterator.next(); - boolean isAllInput = true; - for (IInput input : process.getInputs()) { - boolean isInputAvailable = false; - for (IInOutPut processInput : availableIn) { - if (processInput.equals(input)) { - isInputAvailable = true; - break; - } - } - if (!isInputAvailable) { - isAllInput = false; - break; - } - } - if (isAllInput) { - executionTree.get(i).add(process); - for (IOutput output : process.getOutputs()) { - for (Map.Entry entry : inputOutputMap.entrySet()) { - if (entry.getValue().equals(output)) { - newIn.add(entry.getKey()); - } - } - } - iterator.remove(); - } - } - } - - /** - * Link the inputs, the outputs and the aliases to prepare the execution. - */ - private boolean link() { - executionTree = new ArrayList<>(); - results = new HashMap<>(); - processList = new ArrayList<>(); - - linkerList.stream().map(Linker::getAliases).forEach(aliases::putAll); - linkerList.stream().map(Linker::getInputOutputMap).forEach(inputOutputMap::putAll); - linkerList.stream().map(Linker::getInputs).forEach(inputs::addAll); - linkerList.stream().map(Linker::getOutputs).forEach(outputs::addAll); - - fillProcessList(); - - List availableIn = collectInputOutput(); - - //Build the execution tree - List iterableProcessList = new ArrayList<>(processList); - int i = 0; - List newIn = new ArrayList<>(); - do { - availableIn.addAll(newIn); - newIn = new ArrayList<>(); - executionTree.add(new ArrayList<>()); - buildExecutionTreeLevel(iterableProcessList, availableIn, i, newIn); - i++; - } while (!iterableProcessList.isEmpty() && !executionTree.get(i - 1).isEmpty()); - - if (!iterableProcessList.isEmpty()) { - LOGGER.error("Unable to link the processes '" + - iterableProcessList.stream() - .map(IProcess::getTitle) - .filter(Optional::isPresent) - .map(Optional::get) - .collect(Collectors.joining(",")) + "'"); - return false; - } - return true; - } - - @Override - public List getInputs() { - return inputs; - } - - @Override - public List getOutputs() { - return outputs; - } - - @Override - public IProcessMapper newInstance() { - ProcessMapper mapper = new ProcessMapper(); - mapper.processList = new ArrayList<>(processList); - mapper.executionTree = new ArrayList<>(executionTree); - mapper.linkerList = new ArrayList<>(linkerList); - mapper.inputs = this.inputs.stream().map(IInput::copy).collect(Collectors.toCollection(LinkedList::new)); - mapper.outputs = this.outputs.stream().map(IOutput::copy).collect(Collectors.toCollection(LinkedList::new)); - return mapper; - } - - @Override - public IProcessMapper copy() { - ProcessMapper mapper = new ProcessMapper(); - mapper.processList = new ArrayList<>(processList); - mapper.executionTree = new ArrayList<>(executionTree); - mapper.linkerList = new ArrayList<>(linkerList); - mapper.inputs = this.inputs.stream().map(IInput::copy).collect(Collectors.toCollection(LinkedList::new)); - mapper.outputs = this.outputs.stream().map(IOutput::copy).collect(Collectors.toCollection(LinkedList::new)); - return mapper; - } - - /** - * Return a {@link LinkedHashMap} with the input data for the given {@link IProcess} execution. - * - * @param process {@link IProcess} which will executed. - * @param dataMap {@link Map} with the {@link ProcessMapper} input data. - * @return A {@link LinkedHashMap} with the input data for the given {@link IProcess}. - */ - private LinkedHashMap getInputDataMap(IProcess process, Map dataMap) { - LinkedHashMap processInData = new LinkedHashMap<>(); - for (IInput in : process.getInputs()) { - //Try to get the data directly from the out of a process - String alias = getAlias(in.getName().orElse(null), process); - final Object[] data = new Object[1]; - if (alias != null) { - data[0] = dataMap.get(alias); - } else { - data[0] = dataMap.get(in.getName().orElse(null)); - } - //Get the link between the input 'in' and a process output if exists - inputOutputMap.forEach((input, output) -> { - if (process.equals(input.getProcess().orElse(null)) && - input.getName().equals(in.getName())) { - //get the process with the output linked to 'in' - for (IProcess p : processList) { - if (p.equals(output.getProcess().orElse(null))) { - data[0] = p.getResults().get(output.getName().orElse(null)); - } - } - } - }); - //Do not add null value for optional input - if (in.isOptional() && data[0] == null) { - processInData.put(in.getName().orElse(null), in.getDefaultValue().orElse(null)); - } else { - processInData.put(in.getName().orElse(null), data[0]); - } - } - return processInData; - } - - @Override - public boolean execute(LinkedHashMap inputDataMap) { - if (!link()) { - return false; - } - Map dataMap = inputDataMap == null ? new HashMap<>() : new HashMap<>(inputDataMap); - //Iterate over the execution tree - for (List processes : executionTree) { - for (IProcess process : processes) { - LinkedHashMap processInData = getInputDataMap(process, dataMap); - //Do the before check - beforeList.stream() - .filter(check -> check.getProcess().isPresent()) - .filter(check -> check.getProcess().get().getIdentifier().equals(process.getIdentifier())) - .forEach(check -> check.run(processInData)); - //Execute the process - process.execute(processInData); - storeResults(process); - //Do the after check - afterList.stream() - .filter(check -> check.getProcess().isPresent()) - .filter(check -> check.getProcess().get().getIdentifier().equals(process.getIdentifier())) - .forEach(check -> check.run(processInData)); - } - } - return true; - } - - /** - * Store the result of the {@link IProcess} execution. - * - * @param process {@link IProcess} which results should be stored. - */ - private void storeResults(IProcess process) { - for (String key : process.getResults().keySet()) { - boolean isBetween = inputOutputMap.values().stream() - .anyMatch(value -> key.equals(value.getName().orElse(null)) && - process.equals(value.getProcess().orElse(null))); - String alias = getAlias(key, process); - if (alias != null) { - results.put(alias, process.getResults().get(key)); - } else { - if (!isBetween) { - results.put(key, process.getResults().get(key)); - } - } - } - } - - @Override - public Optional getTitle() { - return Optional.ofNullable(title); - } - - @Override - public Map getResults() { - return results; - } - - @Override - public ILinker link(IInOutPut... inOutPuts) { - Linker linker = new Linker(inOutPuts); - linkerList.add(linker); - return linker; - } - - @Override - public ICheckDataBuilder before(IProcess process) { - IProcessCheck processCheck = new ProcessCheck(process); - beforeList.add(processCheck); - return new CheckDataBuilder(processCheck); - } - - @Override - public ICheckDataBuilder after(IProcess process) { - IProcessCheck processCheck = new ProcessCheck(process); - afterList.add(processCheck); - return new CheckDataBuilder(processCheck); - } - - @Override - public boolean call(LinkedHashMap inputDataMap) { - return execute(inputDataMap); - } - - @Override - public Object getProperty(String propertyName){ - if(propertyName != null) { - Object obj = this.metaClass.getProperty(this, propertyName); - if(obj instanceof Optional){ - return ((Optional)obj).orElse(null); - } - else { - return obj; - } - } - else { - return null; - } - } - - @Override - public Object invokeMethod(String name, Object args) { - if(name != null) { - Object obj = this.metaClass.invokeMethod(this, name, args); - if(obj instanceof Optional){ - return ((Optional)obj).orElse(null); - } - else { - return obj; - } - } - else { - return null; - } - } - - @Override - public MetaClass getMetaClass() { - return metaClass; - } - - @Override - public void setMetaClass(MetaClass metaClass) { - this.metaClass = metaClass == null ? InvokerHelper.getMetaClass(this.getClass()) : metaClass; - } -} diff --git a/process/src/main/java/org/orbisgis/process/ProgressMonitor.java b/process/src/main/java/org/orbisgis/process/ProgressMonitor.java deleted file mode 100644 index 99af8b11..00000000 --- a/process/src/main/java/org/orbisgis/process/ProgressMonitor.java +++ /dev/null @@ -1,285 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process; - -import org.orbisgis.process.api.IProgressMonitor; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -/** - * Implementation of the {@link IProgressMonitor} interface. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS Lab-STICC 2020) - */ -public class ProgressMonitor implements IProgressMonitor { - - /** - * Actual step of the progression. - */ - private int step; - /** - * Maximum step count. - */ - private final int maximum; - /** - * True if the progression should be logged, false otherwise. - */ - private final boolean autoLog; - /** - * {@link Logger} used to log progression. - */ - private final Logger logger; - /** - * List of child. - */ - private final List children; - /** - * Name of the task. - */ - private final String name; - /** - * Reference to the parent {@link IProgressMonitor} - */ - private final IProgressMonitor parent; - /** - * Indicates if the progression has end. - */ - private boolean end; - - /** - * Returns a child {@link IProgressMonitor} with the given name as task name, the given maximum as maximum - * step count and logging the progression if autoLog to true. - * - * @param parent Parent {@link IProgressMonitor}. - * @param taskName Name of the task. - * @param maximum Maximum step number. - * @param autoLog Log the progression if true, otherwise do not log. - */ - public ProgressMonitor(IProgressMonitor parent, String taskName, int maximum, boolean autoLog){ - this.name = taskName == null ? "task_" + UUID.randomUUID() : taskName; - this.maximum = maximum; - this.step = 0; - this.children = new ArrayList<>(); - this.autoLog = autoLog; - this.logger = LoggerFactory.getLogger(ProgressMonitor.class); - this.parent = parent; - this.end = false; - } - - /** - * Creates a child {@link IProgressMonitor} with the given name as task name, the given maximum as maximum - * step count and logging the progression if autoLog to true. - * - * @param taskName Name of the task. - * @param maximum Maximum step number. - * @param autoLog Log the progression if true, otherwise do not log. - */ - public ProgressMonitor(String taskName, int maximum, boolean autoLog){ - this(null, taskName, maximum, autoLog); - } - - /** - * Creates a child {@link IProgressMonitor} with the given maximum as maximum step count and logging the - * progression if autoLog to true. - * - * @param maximum Maximum step number. - * @param autoLog Log the progression if true, otherwise do not log. - */ - public ProgressMonitor(int maximum, boolean autoLog){ - this(null, null, maximum, autoLog); - } - - /** - * Creates a child {@link IProgressMonitor} with the given name as task name, without maximum step count and - * logging the progression if autoLog to true. - * - * @param taskName Name of the task. - * @param autoLog Log the progression if true, otherwise do not log. - */ - public ProgressMonitor(String taskName, boolean autoLog){ - this(null, taskName, -1, autoLog); - } - - /** - * Creates a child {@link IProgressMonitor} with the given name as task name and the given maximum as maximum - * step count. - * - * @param taskName Name of the task. - * @param maximum Maximum step number. - */ - public ProgressMonitor(String taskName, int maximum){ - this(null, taskName, maximum, false); - } - - /** - * Creates a child {@link IProgressMonitor} with the given name as task name, without maximum step count. - * - * @param taskName Name of the task. - */ - public ProgressMonitor(String taskName){ - this(null, taskName, -1, false); - } - - /** - * Creates a child {@link IProgressMonitor} with the given maximum as maximum step count. - * - * @param maximum Maximum step number. - */ - public ProgressMonitor(int maximum){ - this(null, null, maximum, false); - } - - /** - * Creates a child {@link IProgressMonitor} without maximum step count, logging the progression if autoLog to true. - * - * @param autoLog Log the progression if true, otherwise do not log. - */ - public ProgressMonitor(boolean autoLog){ - this(null, null, -1, autoLog); - } - - /** - * Creates a child {@link IProgressMonitor} without maximum step count. - */ - public ProgressMonitor(){ - this(null, null, -1, false); - } - - @Override - public void incrementStep() { - if(step < maximum) { - this.step++; - } - if(maximum != -1 && step >= maximum){ - end = true; - } - if(autoLog) { - if(parent != null) { - parent.log(); - } - else { - log(); - } - } - } - - @Override - public double getProgress() { - if(end){ - return 100; - } - if(maximum == -1){ - return -1; - } - if(children.stream().map(IProgressMonitor::getProgress).anyMatch(d -> d==-1)){ - return -1; - } - return 100.0 / - (children.size() + maximum) * - (children.stream().map(IProgressMonitor::getProgress).reduce(0.0, Double::sum)/100 +step); - } - - @Override - public int getMaxStep() { - return maximum; - } - - @Override - public String getName() { - return name; - } - - @Override - public IProgressMonitor getSubProgress(String taskName) { - return getSubProgress(taskName, -1, autoLog); - } - - @Override - public IProgressMonitor getSubProgress(boolean autoLog) { - return getSubProgress(null, -1, autoLog); - } - - @Override - public IProgressMonitor getSubProgress(int maximum) { - return getSubProgress(null, maximum, autoLog); - } - - @Override - public IProgressMonitor getSubProgress(String taskName, int maximum) { - return getSubProgress(taskName, maximum, autoLog); - } - - @Override - public IProgressMonitor getSubProgress(String taskName, boolean autoLog) { - return getSubProgress(taskName, -1, autoLog); - } - - @Override - public IProgressMonitor getSubProgress(int maximum, boolean autoLog) { - return getSubProgress(null, maximum, autoLog); - } - - @Override - public IProgressMonitor getSubProgress(String taskName, int maximum, boolean autoLog) { - IProgressMonitor pm = new ProgressMonitor(this, taskName, maximum, autoLog); - children.add(pm); - return pm; - } - - @Override - public void log() { - if(parent == null) { - logger.info(name + " : " + String.format("%.2f", getProgress()) + "/100.00"); - } - else { - parent.log(); - } - } - - @Override - public void end() { - end = true; - if(autoLog){ - log(); - } - } -} diff --git a/process/src/main/java/org/orbisgis/process/api/ILinker.java b/process/src/main/java/org/orbisgis/process/api/ILinker.java deleted file mode 100644 index 7c5cefad..00000000 --- a/process/src/main/java/org/orbisgis/process/api/ILinker.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process.api; - -import org.orbisgis.process.api.inoutput.IInOutPut; - -/** - * This interface declare the methods used to link inputs, outputs and aliases. The first element to link is given - * through the constructor, the second through the methods {@link ILinker#to(String)} or - * {@link ILinker#to(IInOutPut[])}. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS 2019) - */ -public interface ILinker { - - /** - * Second element to link. - * - * @param inOutPuts Inputs or Outputs to link. - */ - void to(IInOutPut... inOutPuts); - - /** - * Alias to give to the inputs or outputs. - * - * @param alias Alias to use. - */ - void to(String alias); -} diff --git a/process/src/main/java/org/orbisgis/process/api/IProcess.java b/process/src/main/java/org/orbisgis/process/api/IProcess.java deleted file mode 100644 index 7da18dc6..00000000 --- a/process/src/main/java/org/orbisgis/process/api/IProcess.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process.api; - -import org.orbisgis.process.api.inoutput.IInput; -import org.orbisgis.process.api.inoutput.IOutput; - -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -/** - * Interface defining the main methods of a process. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS 2019) - */ -public interface IProcess { - - /** - * Return a new instance of the process. - * - * @return A process new instance. - */ - IProcess newInstance(); - - /** - * Execute the process with the given inputs. - * - * @param inputDataMap Map of the inputs with the name as key and the input value as value. - * @return True if the execution is successful, false otherwise. - */ - boolean execute(LinkedHashMap inputDataMap); - - /** - * Return the title of the process. - * - * @return The title of the process. - */ - Optional getTitle(); - - /** - * Return the process version. - * - * @return The process version. - */ - Optional getVersion(); - - /** - * Return the human readable description of the process. - * - * @return The description of the process. - */ - Optional getDescription(); - - /** - * Return the array of the process keywords. - * - * @return The array of the process keywords. - */ - Optional getKeywords(); - - /** - * Return the results of the process. - * - * @return A Map of the results with the output name as key and the output value as value. - */ - Map getResults(); - - /** - * Return the process identifier. - * - * @return The process identifier. - */ - String getIdentifier(); - - /** - * Return a {@link Map} with the input name as key and its {@link Class} as value. - * - * @return A {@link Map} with the input name as key and its {@link Class} as value. - */ - List getInputs(); - - /** - * Return a {@link Map} with the output name as key and its {@link Class} as value. - * - * @return A {@link Map} with the output name as key and its {@link Class} as value. - */ - List getOutputs(); - - /** - * Call the {@link IProcess#execute(LinkedHashMap)} method. - * - * @param inputDataMap Map of the inputs with the name as key and the input value as value. - * @return True if the execution is successful, false otherwise. - */ - boolean call(LinkedHashMap inputDataMap); - - /** - * Create an exact copy of this {@link IProcess}. - * - * @return Exact copy of this {@link IProcess} - */ - IProcess copy(); -} \ No newline at end of file diff --git a/process/src/main/java/org/orbisgis/process/api/IProcessBuilder.java b/process/src/main/java/org/orbisgis/process/api/IProcessBuilder.java deleted file mode 100644 index abe28db9..00000000 --- a/process/src/main/java/org/orbisgis/process/api/IProcessBuilder.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process.api; - -import groovy.lang.Closure; - -import java.util.LinkedHashMap; - -/** - * Interface declaring all the methods for the building of a {@link IProcess}. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS 2019) - */ -public interface IProcessBuilder { - - /** - * Set the identifier of the process. - * - * @param id Identifier of the process. - * @return A {@link IProcessBuilder} to continue the building. - */ - IProcessBuilder id(String id); - - /** - * Set the title of the process. - * - * @param title Title of the process. - * @return A {@link IProcessBuilder} to continue the building. - */ - IProcessBuilder title(String title); - - /** - * Set the description of the process. - * - * @param description Human readable description of the process. - * @return A {@link IProcessBuilder} to continue the building. - */ - IProcessBuilder description(String description); - - /** - * Set the keywords of the process. - * - * @param keywords List of simple keyword (one word) of the process. - * @return A {@link IProcessBuilder} to continue the building. - */ - IProcessBuilder keywords(String[] keywords); - - /** - * Set the inputs of the process. - * - * @param inputs {@link LinkedHashMap} of inputs with the name as key and the input Object as value. - * The names will be used to link the closure parameters with the execution - * input data map. - * @return A {@link IProcessBuilder} to continue the building. - */ - IProcessBuilder inputs(LinkedHashMap inputs); - - /** - * Set the outputs of the process. - * - * @param outputs {@link LinkedHashMap} of outputs with the name as key and the output Object as value. - * Those names will be used to generate the LinkedHashMap of the - * getResults Method. - * @return A {@link IProcessBuilder} to continue the building. - */ - IProcessBuilder outputs(LinkedHashMap outputs); - - /** - * Set the version of the process. - * - * @param version Process version. - * @return A {@link IProcessBuilder} to continue the building. - */ - IProcessBuilder version(String version); - - /** - * Set the closure of the process. - * - * @param closure {@link Closure} containing the code to execute on the process execution. - * @return A {@link IProcessBuilder} to continue the building. - */ - IProcessBuilder run(Closure closure); - - /** - * Build and return the process. - * - * @return The built {@link IProcess}. - */ - IProcess getProcess(); -} diff --git a/process/src/main/java/org/orbisgis/process/api/IProcessFactory.java b/process/src/main/java/org/orbisgis/process/api/IProcessFactory.java deleted file mode 100644 index 3e43bca1..00000000 --- a/process/src/main/java/org/orbisgis/process/api/IProcessFactory.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process.api; - -import groovy.lang.Closure; -import groovy.lang.DelegatesTo; - -import java.util.Optional; - -/** - * This interface defines the methods dedicated to the process creation and managing. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS Lab-STICC 2019-2020) - */ -public interface IProcessFactory { - - /** - * Register a {@link IProcess}. - * - * @param process {@link IProcess} to register. - */ - void registerProcess(IProcess process); - - /** - * Return true if the process creation is locked, false otherwise. - * - * @return True if the process creation is locked, false otherwise. - */ - boolean isLocked(); - - /** - * Return true if the factory if the default one, false otherwise. - * - * @return True if the factory if the default one, false otherwise. - */ - boolean isDefault(); - - /** - * Returns the process with the given identifier. - * - * @param processId Identifier of the process to get. - * @return The process with the given identifier. - */ - Optional getProcess(String processId); - - /** - * Return a {@link IProcessBuilder} to create a {@link IProcess}. Once the process created, it will be register - * in this {@link IProcessFactory}. - * - * @return A {@link IProcessBuilder} to create a {@link IProcess}. - */ - IProcessBuilder create(); - - /** - * Return a {@link IProcess} created from the given {@link Closure}. Once the process created, it will be register - * in this {@link IProcessFactory}. - * - * @param cl {@link Closure} delegated to {@link IProcessBuilder}. - * @return A {@link IProcess}. - */ - Optional create(@DelegatesTo(IProcessBuilder.class) Closure cl); - - /** - * Return the {@link IProcess} containing the factory. - * - * @return The {@link IProcess} containing the factory. - */ - Optional getProcessManager(); - - /** - * Set the {@link IProcessManager} containing the factory. - * - * @param processManager The {@link IProcessManager} containing the factory. - */ - void setProcessManager(IProcessManager processManager); -} diff --git a/process/src/main/java/org/orbisgis/process/api/IProcessManager.java b/process/src/main/java/org/orbisgis/process/api/IProcessManager.java deleted file mode 100644 index 70f073eb..00000000 --- a/process/src/main/java/org/orbisgis/process/api/IProcessManager.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process.api; - -import groovy.lang.Closure; -import groovy.lang.DelegatesTo; - -import java.util.List; -import java.util.Map; -import java.util.Optional; - -/** - * This interface defines the methods dedicated to the process and process factory managing. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS 2019) - */ -public interface IProcessManager { - - /** - * Return a {@link IProcessBuilder} to create a {@link IProcess}. Once the process created, it will be register - * in the default {@link IProcessFactory} if set. - * - * @return A {@link IProcessBuilder} to create a {@link IProcess}. - */ - IProcessBuilder create(); - - /** - * Return a {@link IProcess} created from the given {@link Closure}. Once the process created, it will be register - * in the default {@link IProcessFactory} if set. - * - * @param cl {@link Closure} delegated to {@link IProcessBuilder}. - * @return A {@link IProcess}. - */ - Optional create(@DelegatesTo(IProcessBuilder.class) Closure cl); - - /** - * Return the list of the factory identifiers. - * - * @return The list of the factory identifier. - */ - List factoryIds(); - - /** - * Returns the process factory with the given identifier. - * - * @param identifier Identifier of the factory. - * @return The process factory with the given identifier. - */ - IProcessFactory factory(String identifier); - - /** - * Returns the default process factory. - * - * @return The default process factory. - */ - IProcessFactory factory(); - - /** - * Returns the process with the given identifier from the default factory. - * - * @param processId Identifier of the process to get. - * @return The process with the given identifier from the default factory. - */ - Optional process(String processId); - - /** - * Returns the process with the given identifier from the factory with the given identifier. - * - * @param processId Identifier of the process to get. - * @param factoryId Identifier of the factory. - * @return The process with the given identifier from the factory with the given identifier. - */ - Optional process(String processId, String factoryId); - - /** - * Register the given factory with the given id. - * - * @param id Identifier of the factory to register. - * @param factory Factory to register. - */ - boolean registerFactory(String id, IProcessFactory factory); - - /** - * Register a map of factories with the id as key and the factory as value. - * - * @param map Map of the factories. - */ - void register(Map map); -} diff --git a/process/src/main/java/org/orbisgis/process/api/IProcessMapper.java b/process/src/main/java/org/orbisgis/process/api/IProcessMapper.java deleted file mode 100644 index 6729972f..00000000 --- a/process/src/main/java/org/orbisgis/process/api/IProcessMapper.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process.api; - -import org.orbisgis.process.api.check.ICheckDataBuilder; -import org.orbisgis.process.api.check.IProcessCheck; -import org.orbisgis.process.api.inoutput.IInOutPut; - -import java.util.Optional; -import java.util.UUID; - -/** - * This class should not be used will using a IProcess executing and mapping processes is easier. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS 2019) - */ -public interface IProcessMapper extends IProcess { - - @Override - IProcessMapper newInstance(); - - @Override - IProcessMapper copy(); - - /** - * Start to link the given inputs/outputs. - * - * @param inOutPuts Inputs or outputs to link. - * @return A {@link ILinker} object which will do the link. - */ - ILinker link(IInOutPut... inOutPuts); - - /** - * Add a {@link IProcessCheck} before the execution of the given {@link IProcess}. - * - * @param process {@link IProcess} before which the check should be done. - * @return A {@link ICheckDataBuilder} to continue the {@link IProcessCheck} build. - */ - ICheckDataBuilder before(IProcess process); - - - /** - * Add a {@link IProcessCheck} after the execution of the given {@link IProcess}. - * - * @param process {@link IProcess} after which the check should be done. - * @return A {@link ICheckDataBuilder} to continue the {@link IProcessCheck} build. - */ - ICheckDataBuilder after(IProcess process); - - @Override - default Optional getVersion() { - return Optional.empty(); - } - - @Override - default Optional getDescription() { - return Optional.empty(); - } - - @Override - default Optional getKeywords() { - return Optional.empty(); - } - - @Override - default String getIdentifier() { - return UUID.randomUUID().toString(); - } -} diff --git a/process/src/main/java/org/orbisgis/process/api/IProgressMonitor.java b/process/src/main/java/org/orbisgis/process/api/IProgressMonitor.java deleted file mode 100644 index 604b7176..00000000 --- a/process/src/main/java/org/orbisgis/process/api/IProgressMonitor.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process.api; - - -/** - * This interface declare the methods for a progress monitoring the running of a {@link IProcess} or a - * {@link IProcessMapper}. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (Lab-STICC UBS 2020) - */ -public interface IProgressMonitor { - - /** - * Increments the current step of the progression. - */ - void incrementStep(); - - /** - * Returns the progression or -1 if the {@link IProgressMonitor} has not maximum step count. - * - * @return The progression or -1. - */ - double getProgress(); - - /** - * Returns the maximum count of steps. - * - * @return The maximum count of steps. - */ - int getMaxStep(); - - /** - * Log the progression. - */ - void log(); - - /** - * Make the progression reach its end. - */ - void end(); - - /** - * Returns the {@link IProgressMonitor} name. - * - * @return The {@link IProgressMonitor} name. - */ - String getName(); - - /** - * Returns a child {@link IProgressMonitor} with the given name as task name, without maximum step count. - * - * @param taskName Name of the task. - * @return A child {@link IProgressMonitor}. - */ - IProgressMonitor getSubProgress(String taskName); - - /** - * Returns a child {@link IProgressMonitor} with the given maximum as maximum step count. - * - * @param maximum Maximum step number. - * @return A child {@link IProgressMonitor}. - */ - IProgressMonitor getSubProgress(int maximum); - - /** - * Returns a child {@link IProgressMonitor} without maximum step count, logging the progression if autoLog to true. - * - * @param autoLog Log the progression if true, otherwise do not log. - * @return A child {@link IProgressMonitor}. - */ - IProgressMonitor getSubProgress(boolean autoLog); - - /** - * Returns a child {@link IProgressMonitor} with the given name as task name and the given maximum as maximum - * step count. - * - * @param taskName Name of the task. - * @param maximum Maximum step number. - * @return A child {@link IProgressMonitor}. - */ - IProgressMonitor getSubProgress(String taskName, int maximum); - - /** - * Returns a child {@link IProgressMonitor} with the given name as task name, without maximum step count and - * logging the progression if autoLog to true. - * - * @param taskName Name of the task. - * @param autoLog Log the progression if true, otherwise do not log. - * @return A child {@link IProgressMonitor}. - */ - IProgressMonitor getSubProgress(String taskName, boolean autoLog); - - /** - * Returns a child {@link IProgressMonitor} with the given maximum as maximum step count and logging the - * progression if autoLog to true. - * - * @param maximum Maximum step number. - * @param autoLog Log the progression if true, otherwise do not log. - * @return A child {@link IProgressMonitor}. - */ - IProgressMonitor getSubProgress(int maximum, boolean autoLog); - - /** - * Returns a child {@link IProgressMonitor} with the given name as task name, the given maximum as maximum - * step count and logging the progression if autoLog to true. - * - * @param taskName Name of the task. - * @param maximum Maximum step number. - * @param autoLog Log the progression if true, otherwise do not log. - * @return A child {@link IProgressMonitor}. - */ - IProgressMonitor getSubProgress(String taskName, int maximum, boolean autoLog); -} diff --git a/process/src/main/java/org/orbisgis/process/api/check/ICheckClosureBuilder.java b/process/src/main/java/org/orbisgis/process/api/check/ICheckClosureBuilder.java deleted file mode 100644 index 2a97e935..00000000 --- a/process/src/main/java/org/orbisgis/process/api/check/ICheckClosureBuilder.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ - -package org.orbisgis.process.api.check; - -import groovy.lang.Closure; -import org.orbisgis.process.api.inoutput.IInOutPut; - -/** - * Interface for the definition of which closure is provided for the Process check execution. - * Instance is get from the {@link ICheckDataBuilder#with(IInOutPut...)}. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS Lab-STICC 2019-2020) - */ -public interface ICheckClosureBuilder { - - /** - * Sets the {@link Closure} to execute to perform the check. - * If the {@link Closure} is null, just check equality of data. - * - * @param cl {@link Closure} to execute to perform the check. - * @return A {@link ICheckClosureBuilder} to continue the check building. - */ - ICheckOptionBuilder check(Closure cl); -} diff --git a/process/src/main/java/org/orbisgis/process/api/check/ICheckDataBuilder.java b/process/src/main/java/org/orbisgis/process/api/check/ICheckDataBuilder.java deleted file mode 100644 index 1ac6040b..00000000 --- a/process/src/main/java/org/orbisgis/process/api/check/ICheckDataBuilder.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process.api.check; - -import org.orbisgis.process.api.IProcess; -import org.orbisgis.process.api.IProcessMapper; -import org.orbisgis.process.api.inoutput.IInOutPut; - -/** - * Interface for the definition of which data are provided for the Process check execution. - * Instance is get from the {@link IProcessMapper#after(IProcess)} and {@link IProcessMapper#before(IProcess)}. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS Lab-STICC 2019-2020) - */ -public interface ICheckDataBuilder { - - /** - * Sets the inputs or outputs to use for the check. - * - * @param data Input or output list to use to do the check. - * @return A {@link ICheckClosureBuilder} to continue the check building. - */ - ICheckClosureBuilder with(IInOutPut... data); -} diff --git a/process/src/main/java/org/orbisgis/process/api/check/ICheckOptionBuilder.java b/process/src/main/java/org/orbisgis/process/api/check/ICheckOptionBuilder.java deleted file mode 100644 index 9541e7ec..00000000 --- a/process/src/main/java/org/orbisgis/process/api/check/ICheckOptionBuilder.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process.api.check; - -import groovy.lang.Closure; - -/** - * Interface for the definition of the getProcess check execution options. - * Instance is get from the {@link ICheckClosureBuilder#check(Closure)}. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS Lab-STICC 2019-2020) - */ -public interface ICheckOptionBuilder { - - /** - * Make the check log the given message and stop the program on fail . - * - * @param message Message to log. - * @return A {@link ICheckOptionBuilder} to continue the check building. - */ - ICheckOptionBuilder stopOnFail(String message); - - /** - * Make the check stop the program on fail . - * - * @return A {@link ICheckOptionBuilder} to continue the check building. - */ - ICheckOptionBuilder stopOnFail(); - - /** - * Make the check log the given message and stop the program on success . - * - * @param message Message to log. - * @return A {@link ICheckOptionBuilder} to continue the check building. - */ - ICheckOptionBuilder stopOnSuccess(String message); - - /** - * Make the check stop the program on success . - * - * @return A {@link ICheckOptionBuilder} to continue the check building. - */ - ICheckOptionBuilder stopOnSuccess(); - - /** - * Make the check log the given message and continue the program on fail . - * - * @param message Message to log. - * @return A {@link ICheckOptionBuilder} to continue the check building. - */ - ICheckOptionBuilder continueOnFail(String message); - - /** - * Make the check continue the program on fail . - * - * @return A {@link ICheckOptionBuilder} to continue the check building. - */ - ICheckOptionBuilder continueOnFail(); - - /** - * Make the check log the given message and continue the program on success . - * - * @param message Message to log. - * @return A {@link ICheckOptionBuilder} to continue the check building. - */ - ICheckOptionBuilder continueOnSuccess(String message); - - /** - * Make the check continue the program on success . - * - * @return A {@link ICheckOptionBuilder} to continue the check building. - */ - ICheckOptionBuilder continueOnSuccess(); -} diff --git a/process/src/main/java/org/orbisgis/process/api/check/IProcessCheck.java b/process/src/main/java/org/orbisgis/process/api/check/IProcessCheck.java deleted file mode 100644 index f604033b..00000000 --- a/process/src/main/java/org/orbisgis/process/api/check/IProcessCheck.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process.api.check; - -import groovy.lang.Closure; -import org.orbisgis.process.api.IProcess; -import org.orbisgis.process.api.inoutput.IInOutPut; - -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.Optional; - -/** - * Interface for the definition of getProcess check. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS Lab-STICC 2019-2020) - */ -public interface IProcessCheck { - - /** - * Enumeration of the action to do after a process check. - */ - enum Action{CONTINUE, STOP} - - /** - * Run the check with output data given with {@link #setInOutPuts(IInOutPut...)} and the input data from the given - * {@link LinkedHashMap}. On fail, return false and apply the action set with {@link #onFail(Action, String)}. - * On success, return true and apply the action set with {@link #onSuccess(Action, String)}. - * - * I not process have been provided, the default values of the mapper input are checked. The given map represents - * the inputs to check as key and there default value as value. - * - * @param processInData {@link LinkedHashMap} containing the input data for the {@link IProcess} execution. - * @return True if the process should continue, false otherwise - */ - boolean run(LinkedHashMap processInData); - - /** - * Set the action to do on check fail. If action is null, use {@link Action#STOP} by default. - * - * @param action Action to do on fail. - * @param message Message to log. - */ - void onFail(Action action, String message); - - /** - * Set the message on check fail. By default use {@link Action#STOP}. - * - * @param message Message to log. - */ - void onFail(String message); - - /** - * Set the action to do on check success. If action is null, use {@link Action#STOP} by default. - * - * @param action Action to do on success. - * @param message Message to log. - */ - void onSuccess(Action action, String message); - - /** - * Set the message on check success. By default use {@link Action#CONTINUE}. - * - * @param message Message to log. - */ - void onSuccess(String message); - - /** - * Sets the input and output to use inside the check. - * - * @param inputOrOutput Input or output list to use for the check. - */ - void setInOutPuts(IInOutPut... inputOrOutput); - - /** - * Returns the input and output to use inside the check. - * - * @return The input or output list to use for the check. - */ - LinkedList getInOutPuts(); - - /** - * Set the {@link Closure} to call to execute the check. - * - * @param cl {@link Closure} to call to execute the check. - */ - void setClosure(Closure cl); - - /** - * Returns the {@link Closure} to call to execute the check. - * - * @return The {@link Closure} to call to execute the check. - */ - Optional> getClosure(); - - /** - * Method executed on check fail. If process should stop, returns true, false otherwise. - * - * @return False if the process should stop, true otherwise. - * @throws IllegalStateException Exception thrown when check should stop. - */ - boolean fail() throws IllegalStateException; - - /** - * Method executed on check success. If process should stop, returns true, false otherwise. - * - * @return False if the process should stop, true otherwise. - * @throws IllegalStateException Exception thrown when check should stop. - */ - boolean success() throws IllegalStateException; - - /** - * Return the {@link IProcess} concerned by the check. - * - * @return The {@link IProcess} concerned by the check. - */ - Optional getProcess(); -} diff --git a/process/src/main/java/org/orbisgis/process/api/inoutput/IInOutPut.java b/process/src/main/java/org/orbisgis/process/api/inoutput/IInOutPut.java deleted file mode 100644 index 4692a486..00000000 --- a/process/src/main/java/org/orbisgis/process/api/inoutput/IInOutPut.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process.api.inoutput; - -import org.orbisgis.process.api.IProcess; - -import java.util.Optional; - -/** - * This interface defines the methods dedicated the wrapping of input/output. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS Lab-STICC 2019-2020) - */ -public interface IInOutPut { - - /** - * Return the input/output name. - * - * @return The input/output name. - */ - Optional getName(); - - /** - * Sets the name of the input/output. - * - * @param name Name of the input/output. - */ - void setName(String name); - - /** - * Sets the name of the input/output. - * - * @param name Name of the input/output. - * @return Itself. - */ - IInOutPut name(String name); - - /** - * Return the {@link IProcess} of the input/output. - * - * @return The {@link IProcess} of the input/output. - */ - Optional getProcess(); - - /** - * Sets the {@link IProcess} of the input/output. - * - * @param process The {@link IProcess} of the input/output. - */ - void setProcess(IProcess process); - - /** - * Sets the {@link IProcess} of the input/output. - * - * @param process The {@link IProcess} of the input/output. - * @return Itself. - */ - IInOutPut process(IProcess process); - - /** - * Return the type of the input/output. - * - * @return The type of the input/output. - */ - Optional> getType(); - - /** - * Sets the type of the input/output. - * - * @param type The type of the input/output. - */ - void setType(Class type); - - /** - * Sets the type of the input/output. - * - * @param type The type of the input/output. - * @return Itself. - */ - IInOutPut type(Class type); - - /** - * Return the title or the input/output. - * - * @return The title of the input/output. - */ - Optional getTitle(); - - /** - * Sets the title of the input/output. - * - * @param title The title of the input/output. - */ - void setTitle(String title); - - /** - * Sets the title of the input/output. - * - * @param title The title of the input/output. - * @return Itself. - */ - IInOutPut title(String title); - - /** - * Return the description of the input/output. - * - * @return The description of the input/output. - */ - Optional getDescription(); - - /** - * Sets the description of the input/output. - * - * @param description The description of the input/output. - */ - void setDescription(String description); - - /** - * Sets the description of the input/output. - * - * @param description The description of the input/output. - * @return Itself. - */ - IInOutPut description(String description); - - /** - * Return the keywords of the input/output. - * - * @return The keywords of the input/output. - */ - Optional getKeywords(); - - /** - * Sets the keywords of the input/output. - * - * @param keywords The keywords of the input/output. - */ - void setKeywords(String[] keywords); - - /** - * Sets the keywords of the input/output. - * - * @param keywords The keywords of the input/output. - * @return Itself. - */ - IInOutPut keywords(String[] keywords); - - /** - * Returns a copy the the current object. - * - * @return A copy of the current object. - */ - IInOutPut copy(); -} diff --git a/process/src/main/java/org/orbisgis/process/api/inoutput/IInput.java b/process/src/main/java/org/orbisgis/process/api/inoutput/IInput.java deleted file mode 100644 index 37b889b0..00000000 --- a/process/src/main/java/org/orbisgis/process/api/inoutput/IInput.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process.api.inoutput; - - -import java.util.Optional; - -/** - * This interface defines the methods dedicated the wrapping of input. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS Lab-STICC 2019-2020) - */ -public interface IInput extends IInOutPut { - - /** - * Make the {@link IInput} optional. - * - * @param dfltValue Default value to use if no value is provided. - * @return The {@link IInput} to continue its configuration. - */ - IInOutPut optional(Object dfltValue); - - /** - * Return true if the input is optional, false otherwise. - * - * @return True if the input is optional, false otherwise. - */ - boolean isOptional(); - - /** - * Make the {@link IInput} mandatory. - * - * @return The {@link IInput} to continue its configuration. - */ - IInOutPut mandatory(); - - /** - * Return true if the input is mandatory, false otherwise. - * - * @return True if the input is mandatory, false otherwise. - */ - boolean isMandatory(); - - /** - * Return the default value of the input. If mandatory, return null. - * - * @return The default value of the input. - */ - Optional getDefaultValue(); - - /** - * Returns a copy the the current object. - * - * @return A copy of the current object. - */ - IInput copy(); -} diff --git a/process/src/main/java/org/orbisgis/process/api/inoutput/IOutput.java b/process/src/main/java/org/orbisgis/process/api/inoutput/IOutput.java deleted file mode 100644 index f9072796..00000000 --- a/process/src/main/java/org/orbisgis/process/api/inoutput/IOutput.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process.api.inoutput; - - -/** - * This interface defines the methods dedicated the wrapping of output. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS Lab-STICC 2019-2020) - */ -public interface IOutput extends IInOutPut { - - /** - * Returns a copy the the current object. - * - * @return A copy of the current object. - */ - IOutput copy(); -} diff --git a/process/src/main/java/org/orbisgis/process/check/CheckClosureBuilder.java b/process/src/main/java/org/orbisgis/process/check/CheckClosureBuilder.java deleted file mode 100644 index 12ae6fa3..00000000 --- a/process/src/main/java/org/orbisgis/process/check/CheckClosureBuilder.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process.check; - -import groovy.lang.Closure; -import org.orbisgis.process.api.check.ICheckClosureBuilder; -import org.orbisgis.process.api.check.ICheckOptionBuilder; -import org.orbisgis.process.api.check.IProcessCheck; - -/** - * Implementation of the {@link ICheckClosureBuilder} interface. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS 2019-2020) - */ -public class CheckClosureBuilder implements ICheckClosureBuilder { - - /** - * {@link IProcessCheck} being built - */ - private final IProcessCheck processCheck; - - /** - * Default constructor. - * - * @param processCheck {@link IProcessCheck} to build. - */ - protected CheckClosureBuilder(IProcessCheck processCheck) { - this.processCheck = processCheck; - } - - @Override - public ICheckOptionBuilder check(Closure cl) { - processCheck.setClosure(cl); - return new CheckOptionBuilder(processCheck); - } -} diff --git a/process/src/main/java/org/orbisgis/process/check/CheckDataBuilder.java b/process/src/main/java/org/orbisgis/process/check/CheckDataBuilder.java deleted file mode 100644 index fd5c7d6f..00000000 --- a/process/src/main/java/org/orbisgis/process/check/CheckDataBuilder.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process.check; - -import org.orbisgis.process.api.check.ICheckClosureBuilder; -import org.orbisgis.process.api.check.ICheckDataBuilder; -import org.orbisgis.process.api.check.IProcessCheck; -import org.orbisgis.process.api.inoutput.IInOutPut; - -import java.util.Arrays; -import java.util.Objects; - -/** - * Implementation of the {@link ICheckDataBuilder} interface. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS 2019-2020) - */ -public class CheckDataBuilder implements ICheckDataBuilder { - - /** - * {@link IProcessCheck} being built - */ - private final IProcessCheck processCheck; - - /** - * Default constructor. - * - * @param processCheck {@link IProcessCheck} to build. - */ - public CheckDataBuilder(IProcessCheck processCheck) { - this.processCheck = processCheck; - } - - @Override - public ICheckClosureBuilder with(IInOutPut... data) { - if(data != null && (data.length == 0 || Arrays.stream(data).allMatch(Objects::isNull))) { - processCheck.setInOutPuts((IInOutPut[]) null); - } - else { - processCheck.setInOutPuts(data); - } - return new CheckClosureBuilder(processCheck); - } -} diff --git a/process/src/main/java/org/orbisgis/process/check/CheckOptionBuilder.java b/process/src/main/java/org/orbisgis/process/check/CheckOptionBuilder.java deleted file mode 100644 index 791430c7..00000000 --- a/process/src/main/java/org/orbisgis/process/check/CheckOptionBuilder.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process.check; - -import org.orbisgis.process.api.check.ICheckOptionBuilder; -import org.orbisgis.process.api.check.IProcessCheck; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Implementation of the {@link ICheckOptionBuilder} interface. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS 2019-2020) - */ -public class CheckOptionBuilder implements ICheckOptionBuilder { - - /** - * Class logger. - */ - private static final Logger LOGGER = LoggerFactory.getLogger(CheckOptionBuilder.class); - - /** - * {@link IProcessCheck} being built - */ - private final IProcessCheck processCheck; - - /** - * Default constructor. - * - * @param processCheck {@link IProcessCheck} to build. - */ - protected CheckOptionBuilder(IProcessCheck processCheck) { - this.processCheck = processCheck; - } - - @Override - public ICheckOptionBuilder stopOnFail(String message) { - if(message == null) { - LOGGER.warn("No message provided for the ProcessCheck stopOnFail."); - } - processCheck.onFail(IProcessCheck.Action.STOP, message); - return this; - } - - @Override - public ICheckOptionBuilder stopOnFail() { - processCheck.onFail(IProcessCheck.Action.STOP, null); - return this; - } - - @Override - public ICheckOptionBuilder stopOnSuccess(String message) { - if(message == null) { - LOGGER.warn("No message provided for the ProcessCheck stopOnSuccess."); - } - processCheck.onSuccess(IProcessCheck.Action.STOP, message); - return this; - } - - @Override - public ICheckOptionBuilder stopOnSuccess() { - processCheck.onSuccess(IProcessCheck.Action.STOP, null); - return this; - } - - @Override - public ICheckOptionBuilder continueOnFail(String message) { - if(message == null) { - LOGGER.warn("No message provided for the ProcessCheck continueOnFail."); - } - processCheck.onFail(IProcessCheck.Action.CONTINUE, message); - return this; - } - - @Override - public ICheckOptionBuilder continueOnFail() { - processCheck.onFail(IProcessCheck.Action.CONTINUE, null); - return this; - } - - @Override - public ICheckOptionBuilder continueOnSuccess(String message) { - if(message == null) { - LOGGER.warn("No message provided for the ProcessCheck continueOnSuccess."); - } - processCheck.onSuccess(IProcessCheck.Action.CONTINUE, message); - return this; - } - - @Override - public ICheckOptionBuilder continueOnSuccess() { - processCheck.onSuccess(IProcessCheck.Action.CONTINUE, null); - return this; - } -} diff --git a/process/src/main/java/org/orbisgis/process/check/ProcessCheck.java b/process/src/main/java/org/orbisgis/process/check/ProcessCheck.java deleted file mode 100644 index 862bc93c..00000000 --- a/process/src/main/java/org/orbisgis/process/check/ProcessCheck.java +++ /dev/null @@ -1,351 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process.check; - -import groovy.lang.Closure; -import groovy.lang.GroovyInterceptable; -import groovy.lang.GroovyObject; -import groovy.lang.MetaClass; -import org.codehaus.groovy.runtime.InvokerHelper; -import org.orbisgis.process.api.IProcess; -import org.orbisgis.process.api.check.IProcessCheck; -import org.orbisgis.process.api.inoutput.IInOutPut; -import org.orbisgis.process.api.inoutput.IInput; -import org.orbisgis.process.api.inoutput.IOutput; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.*; -import java.util.stream.Collectors; - -import static org.orbisgis.process.api.check.IProcessCheck.Action.CONTINUE; -import static org.orbisgis.process.api.check.IProcessCheck.Action.STOP; - -/** - * Implementation of the {@link IProcessCheck} interface. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS 2019-2020) - */ -public class ProcessCheck implements IProcessCheck, GroovyObject, GroovyInterceptable { - - /** - * Logger - */ - private static final Logger LOGGER = LoggerFactory.getLogger(ProcessCheck.class); - - /** - * {@link IProcess} concerned by the check. - */ - private final IProcess process; - /** - * Inputs/outputs to use for the check. - */ - private final LinkedList inOutPuts = new LinkedList<>(); - /** - * {@link Closure} to perform for the check. - */ - private Closure cl; - /** - * Action to do on fail. - */ - private Action failAction = STOP; - /** - * Message to log on fail. - */ - private String failMessage = "Check failed"; - /** - * Action to do on success. - */ - private Action successAction = CONTINUE; - /** - * Message to log on success. - */ - private String successMessage = "Check successful"; - /** - * MetaClass use for groovy methods/properties binding - */ - private MetaClass metaClass = InvokerHelper.getMetaClass(getClass()); - - /** - * Default constructor. It the given {@link IProcess} is null, execute the check before any process execution. - * - * @param process {@link IProcess} concerned by the check. - */ - public ProcessCheck(IProcess process) { - this.process = process; - } - - /** - * Return true if the Inputs are equals to given data, false otherwise. - * - * @param data {@link LinkedHashMap} containing the input data for the {@link IProcess} execution. - * @return True if the process should continue, false otherwise. - */ - private boolean runNoClosure(LinkedHashMap data) { - //First gather only the inputs as outputs can't be checked before any execution. - List inputs = inOutPuts.stream() - .filter(inOutPut -> inOutPut instanceof IInput) - .map(input -> (IInput)input) - .collect(Collectors.toList()); - //Then check that the default values are the same as the data in the given map - return inputs.stream().allMatch(in -> in.getName().isPresent() && - in.getDefaultValue().isPresent() && - data.containsKey(in.getName().get()) && - data.get(in.getName().get()).equals(in.getDefaultValue().get())); - } - - /** - * Execute the given closure with the given data. - * - * @param data {@link LinkedHashMap} containing the input data for the {@link IProcess} execution. - * @param cl {@link Closure} to execute for the check. - * @return The {@link Closure} result or false if it can't be executed. - */ - private Object runWithClosure(LinkedHashMap data, Closure cl) { - LinkedList dataList = new LinkedList<>(); - //Gather all the data (process output or input data) - for (IInOutPut inOutPut : inOutPuts) { - if (inOutPut.getProcess().isPresent() && - inOutPut.getProcess().get().getOutputs().stream() - .anyMatch(output -> output.getName().equals(inOutPut.getName()))) { - dataList.add(inOutPut.getProcess().get().getResults().get(inOutPut.getName().get())); - } else if (data != null && inOutPut.getName().isPresent()) { - dataList.add(data.get(inOutPut.getName().get())); - } - } - //Execute the Closure with the gathered data. - try { - return cl.call(dataList.toArray()); - } catch (Exception e) { - String message = ""; - if(data == null || cl.getMaximumNumberOfParameters() > data.size()) { - message = "\nIt can be an invalid number of data or closure input."; - } - LOGGER.error("Unable to run the process check with the given data." + message, e); - } - return false; - } - - @Override - public boolean run(LinkedHashMap data) { - if (cl == null && (inOutPuts.isEmpty() || data == null || data.isEmpty())) { - LOGGER.warn("No closure set and no In/Outputs or data to check, no check to do."); - return false; - } - - Object result; - if(cl == null){ - result = runNoClosure(data); - } - else { - result = runWithClosure(data, cl); - } - if (!(result instanceof Boolean)) { - LOGGER.error("The result of the check closure should be a boolean."); - result = false; - } - if ((Boolean) result) { - return success(); - } else { - return fail(); - } - } - - @Override - public void onFail(Action action, String message) { - failAction = action == null ? STOP : action; - failMessage = message; - } - - @Override - public void onFail(String message) { - failAction = STOP; - failMessage = message; - } - - @Override - public void onSuccess(Action action, String message) { - successAction = action == null ? STOP : action; - successMessage = message; - } - - @Override - public void onSuccess(String message) { - successAction = CONTINUE; - successMessage = message; - } - - @Override - public void setInOutPuts(IInOutPut... data) { - if(data != null) { - this.inOutPuts.clear(); - Collections.addAll(this.inOutPuts, data); - } - } - - @Override - public LinkedList getInOutPuts() { - return inOutPuts; - } - - @Override - public void setClosure(Closure cl) { - this.cl = cl; - } - - @Override - public Optional> getClosure() { - return Optional.ofNullable(cl); - } - - @Override - public boolean fail() throws IllegalStateException { - if(failMessage != null) { - LOGGER.error(failMessage); - } - switch (failAction) { - case CONTINUE: - return false; - case STOP: - default: - return true; - } - } - - @Override - public boolean success() throws IllegalStateException { - if(successMessage != null) { - LOGGER.info(successMessage); - } - switch (successAction) { - case CONTINUE: - default: - return false; - case STOP: - return true; - } - } - - @Override - public Optional getProcess() { - return Optional.ofNullable(process); - } - - @Override - public void setProperty(String propertyName, Object newValue) { - if(propertyName != null) { - this.metaClass.setProperty(this, propertyName, newValue); - } - } - - @Override - public Object getProperty(String propertyName){ - Object obj = this.metaClass.getProperty(this, propertyName); - if(obj instanceof Optional){ - return ((Optional)obj).orElse(null); - } - else { - return obj; - } - } - - @Override - public Object invokeMethod(String name, Object args) { - if(name != null) { - Object obj = this.metaClass.invokeMethod(this, name, args); - if(obj instanceof Optional){ - return ((Optional)obj).orElse(null); - } - else { - return obj; - } - } - else { - return null; - } - } - - @Override - public MetaClass getMetaClass() { - return metaClass; - } - - @Override - public void setMetaClass(MetaClass metaClass) { - this.metaClass = metaClass == null ? InvokerHelper.getMetaClass(this.getClass()) : metaClass; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("ProcessCheck : \n"); - if(!getClosure().isPresent() && getInOutPuts().isEmpty()){ - return "No check can be run as there is no closure nor in/outputs set."; - } - if(getProcess().isPresent()) { - //If there is a process, get the name. If the name is null, use the process id. - String processName = getProcess().get().getTitle().isPresent() ? - getProcess().get().getTitle().get() : - getProcess().get().getIdentifier(); - builder.append("On process :") - .append(processName) - .append("\n"); - } - if(!getInOutPuts().isEmpty()) { - builder.append("Check that inputs :\n"); - inOutPuts.stream() - .filter(inOutPut -> inOutPut instanceof IInput) - .filter(inOutPut -> inOutPut.getName().isPresent()) - .forEach(inOutPut -> builder.append("\t").append(inOutPut.getName().get()).append("\n")); - - if (getProcess().isPresent()) { - builder.append("and output :\n"); - inOutPuts.stream() - .filter(inOutPut -> inOutPut instanceof IOutput) - .forEach(inOutPut -> builder.append("\t").append(inOutPut.getName().get()).append("\n")); - } - } - if (getClosure().isPresent()) { - builder.append("Verifies a closure"); - } - else { - builder.append("are equals to provided data."); - } - return builder.toString(); - } -} diff --git a/process/src/main/java/org/orbisgis/process/inoutput/InOutPut.java b/process/src/main/java/org/orbisgis/process/inoutput/InOutPut.java deleted file mode 100644 index 1cb2d101..00000000 --- a/process/src/main/java/org/orbisgis/process/inoutput/InOutPut.java +++ /dev/null @@ -1,234 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process.inoutput; - -import groovy.lang.GroovyInterceptable; -import groovy.lang.GroovyObject; -import groovy.lang.MetaClass; -import org.codehaus.groovy.runtime.InvokerHelper; -import org.orbisgis.process.api.IProcess; -import org.orbisgis.process.api.inoutput.IInOutPut; - -import java.util.Optional; - -/** - * Implementation of the {@link IInOutPut} interface. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS Lab-STICC 2019-2020) - */ -public abstract class InOutPut implements IInOutPut, GroovyObject, GroovyInterceptable { - - /** - * Groovy {@link MetaClass}. - */ - protected MetaClass metaClass = InvokerHelper.getMetaClass(InOutPut.class); - /** - * {@link IProcess} of the input/output. - */ - private IProcess process; - /** - * Name of the input/output. - */ - private String name; - /** - * Type of the input/output. - */ - private Class type; - /** - * Title of the input/output. - */ - private String title; - /** - * Description of the input/output. - */ - private String description; - /** - * Keywords of the input/output. - */ - private String[] keywords; - - public Optional getName() { - return Optional.ofNullable(name); - } - - @Override - public void setName(String name) { - this.name = name; - } - - @Override - public IInOutPut name(String name) { - this.name = name; - return this; - } - - public Optional getProcess() { - return Optional.ofNullable(process); - } - - @Override - public void setProcess(IProcess process) { - this.process = process; - } - - @Override - public IInOutPut process(IProcess process) { - this.process = process; - return this; - } - - @Override - public Optional getTitle() { - return Optional.ofNullable(title); - } - - @Override - public void setTitle(String title) { - this.title = title; - } - - @Override - public IInOutPut title(String title) { - this.title = title; - return this; - } - - @Override - public Optional getDescription() { - return Optional.ofNullable(description); - } - - @Override - public void setDescription(String description) { - this.description = description; - } - - @Override - public IInOutPut description(String description) { - this.description = description; - return this; - } - - @Override - public Optional getKeywords() { - return Optional.ofNullable(keywords); - } - - @Override - public void setKeywords(String[] keywords) { - this.keywords = keywords; - } - - @Override - public IInOutPut keywords(String[] keywords) { - this.keywords = keywords; - return this; - } - - @Override - public Optional> getType() { - return Optional.ofNullable(type); - } - - @Override - public void setType(Class type) { - this.type = type; - } - - @Override - public IInOutPut type(Class type) { - this.type = type; - return this; - } - - @Override - public String toString() { - String pId = process != null ? ":" + process.getIdentifier() : ""; - String str = name != null ? name : ""; - return str + pId; - } - - @Override - public void setProperty(String propertyName, Object newValue) { - if(propertyName != null) { - this.metaClass.setProperty(this, propertyName, newValue); - } - } - - @Override - public Object getProperty(String propertyName){ - if(propertyName != null) { - Object obj = this.metaClass.getProperty(this, propertyName); - if(obj instanceof Optional){ - return ((Optional)obj).orElse(null); - } - else { - return obj; - } - } - else { - return null; - } - } - - @Override - public Object invokeMethod(String name, Object args) { - if(name != null) { - Object obj = this.metaClass.invokeMethod(this, name, args); - if(obj instanceof Optional){ - return ((Optional)obj).orElse(null); - } - else { - return obj; - } - } - else { - return null; - } - } - - @Override - public MetaClass getMetaClass() { - return metaClass; - } - - @Override - public void setMetaClass(MetaClass metaClass) { - this.metaClass = metaClass == null ? InvokerHelper.getMetaClass(this.getClass()) : metaClass; - } -} diff --git a/process/src/main/java/org/orbisgis/process/inoutput/Input.java b/process/src/main/java/org/orbisgis/process/inoutput/Input.java deleted file mode 100644 index 6c3ca766..00000000 --- a/process/src/main/java/org/orbisgis/process/inoutput/Input.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process.inoutput; - -import groovy.lang.MetaClass; -import org.codehaus.groovy.runtime.InvokerHelper; -import org.orbisgis.process.api.IProcess; -import org.orbisgis.process.api.inoutput.IInput; - -import java.util.Objects; -import java.util.Optional; - -/** - * Implementation of the {@link IInput} interface. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS Lab-STICC 2019-2020) - */ -public class Input extends InOutPut implements IInput { - - private Object dfltValue; - - /** - * Default constructor. - */ - public Input() { - this.metaClass = InvokerHelper.getMetaClass(Input.class); - } - - @Override - public Input optional(Object dfltValue) { - this.dfltValue = dfltValue; - return this; - } - - @Override - public boolean isOptional() { - return dfltValue != null; - } - - @Override - public Optional getDefaultValue() { - return Optional.ofNullable(dfltValue); - } - - @Override - public Input mandatory() { - dfltValue = null; - return this; - } - - @Override - public boolean isMandatory() { - return dfltValue == null; - } - - @Override - public Input title(String title) { - super.setTitle(title); - return this; - } - - @Override - public Input description(String description) { - super.setDescription(description); - return this; - } - - @Override - public Input keywords(String[] keywords) { - super.setKeywords(keywords); - return this; - } - - @Override - public Input type(Class type) { - super.setType(type); - return this; - } - - @Override - public Input name(String name) { - super.setName(name); - return this; - } - - @Override - public Input process(IProcess process) { - super.setProcess(process); - return this; - } - - @Override - public void setMetaClass(MetaClass metaClass) { - this.metaClass = metaClass == null ? InvokerHelper.getMetaClass(this.getClass()) : metaClass; - } - - @Override - public boolean equals(Object obj){ - if(! (obj instanceof Input)){ - return false; - } - Input in = (Input)obj; - return Objects.equals(this.getProcess(), in.getProcess()) && - Objects.equals(this.getName(), in.getName()); - } - - @Override - public Input copy() { - Input copy = new Input(); - copy.dfltValue = this.dfltValue; - copy.setProcess(this.getProcess().orElse(null)); - copy.setName(this.getName().orElse(null)); - copy.setType(this.getType().orElse(null)); - copy.setTitle(this.getTitle().orElse(null)); - copy.setDescription(this.getDescription().orElse(null)); - copy.setKeywords(this.getKeywords().orElse(null)); - return copy; - } -} diff --git a/process/src/main/java/org/orbisgis/process/inoutput/Output.java b/process/src/main/java/org/orbisgis/process/inoutput/Output.java deleted file mode 100644 index c2015053..00000000 --- a/process/src/main/java/org/orbisgis/process/inoutput/Output.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process.inoutput; - -import groovy.lang.MetaClass; -import org.codehaus.groovy.runtime.InvokerHelper; -import org.orbisgis.process.api.IProcess; -import org.orbisgis.process.api.inoutput.IOutput; - -import java.util.Objects; - -/** - * Implementation of the {@link IOutput} interface. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS Lab-STICC 2019-2020) - */ -public class Output extends InOutPut implements IOutput { - - /** - * Default constructor. - */ - public Output() { - this.metaClass = InvokerHelper.getMetaClass(Output.class); - } - - @Override - public Output title(String title) { - super.setTitle(title); - return this; - } - - @Override - public Output description(String description) { - super.setDescription(description); - return this; - } - - @Override - public Output keywords(String[] keywords) { - super.setKeywords(keywords); - return this; - } - - @Override - public Output type(Class type) { - super.setType(type); - return this; - } - - @Override - public Output name(String name) { - super.setName(name); - return this; - } - - @Override - public Output process(IProcess process) { - super.setProcess(process); - return this; - } - - @Override - public void setMetaClass(MetaClass metaClass) { - this.metaClass = metaClass == null ? InvokerHelper.getMetaClass(this.getClass()) : metaClass; - } - - @Override - public boolean equals(Object obj){ - if(! (obj instanceof Output)){ - return false; - } - Output out = (Output)obj; - return Objects.equals(this.getProcess(), out.getProcess()) && - Objects.equals(this.getName(), out.getName()); - } - - @Override - public Output copy() { - Output copy = new Output(); - copy.setProcess(this.getProcess().orElse(null)); - copy.setName(this.getName().orElse(null)); - copy.setType(this.getType().orElse(null)); - copy.setTitle(this.getTitle().orElse(null)); - copy.setDescription(this.getDescription().orElse(null)); - copy.setKeywords(this.getKeywords().orElse(null)); - return copy; - } -} diff --git a/process/src/test/groovy/org/orbisgis/process/IProcessMapperTest.java b/process/src/test/groovy/org/orbisgis/process/IProcessMapperTest.java deleted file mode 100644 index d07db77c..00000000 --- a/process/src/test/groovy/org/orbisgis/process/IProcessMapperTest.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process; - -import org.junit.jupiter.api.Test; -import org.orbisgis.process.api.ILinker; -import org.orbisgis.process.api.IProcess; -import org.orbisgis.process.api.IProcessMapper; -import org.orbisgis.process.api.check.ICheckDataBuilder; -import org.orbisgis.process.api.inoutput.IInOutPut; -import org.orbisgis.process.api.inoutput.IInput; -import org.orbisgis.process.api.inoutput.IOutput; - -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - -/** - * Test class dedicated to {@link IProcessMapper} interface. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS 2019) - */ -public class IProcessMapperTest { - - /** - * Test the {@link IProcessMapper#getVersion()} method. - */ - @Test - public void testGetVersion() { - assertFalse(new DummyProcessMapper().getVersion().isPresent()); - } - - /** - * Test the {@link IProcessMapper#getDescription()} method. - */ - @Test - public void testGetDescription() { - assertFalse(new DummyProcessMapper().getDescription().isPresent()); - } - - /** - * Test the {@link IProcessMapper#getKeywords()} method. - */ - @Test - public void testGetKeyword() { - assertFalse(new DummyProcessMapper().getKeywords().isPresent()); - } - - /** - * Test the {@link IProcessMapper#getIdentifier()} method. - */ - @Test - public void testGetIdentifier() { - Pattern pattern = Pattern.compile("[\\da-f]{8}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{12}"); - Matcher matcher = pattern.matcher(new DummyProcessMapper().getIdentifier()); - assertTrue(matcher.find()); - } - - /** - * Simple implementtion of the {@link IProcessMapper} interface. - */ - private static class DummyProcessMapper implements IProcessMapper { - - - @Override - public ILinker link(IInOutPut... inOutPuts) { - return null; - } - - - @Override - public ICheckDataBuilder before(IProcess process) { - return null; - } - - - @Override - public ICheckDataBuilder after(IProcess process) { - return null; - } - - - @Override - public IProcessMapper newInstance() { - return null; - } - - @Override - public boolean execute(LinkedHashMap inputDataMap) { - return false; - } - - - @Override - public Optional getTitle() { - return Optional.empty(); - } - - - @Override - public Map getResults() { - return null; - } - - - @Override - public List getInputs() { - return null; - } - - - @Override - public List getOutputs() { - return null; - } - - @Override - public boolean call(LinkedHashMap inputDataMap) { - return false; - } - - - @Override - public IProcessMapper copy() { - return null; - } - } -} diff --git a/process/src/test/groovy/org/orbisgis/process/TestGroovyProcessFactory.groovy b/process/src/test/groovy/org/orbisgis/process/TestGroovyProcessFactory.groovy deleted file mode 100644 index e353f085..00000000 --- a/process/src/test/groovy/org/orbisgis/process/TestGroovyProcessFactory.groovy +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process - -import org.junit.jupiter.api.Test -import org.orbisgis.process.api.IProcess - -/** - * Test class dedicated to {@link GroovyProcessFactory} class. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS Lab-STICC 2019- 2020) - */ -class TestGroovyProcessFactory { - - /** - * Test the {@link ProcessFactory#ProcessFactory(boolean, boolean)}, {@link ProcessFactory#ProcessFactory()}, - * {@link ProcessFactory#isDefault()} and {@link ProcessFactory#isLocked()} methods. - */ - @Test - void testAttributes() { - def pf = new DummyFactory() - assert !pf.default - assert !pf.locked - } - - /** - * Test the {@link ProcessFactory#registerProcess(IProcess)} and {@link ProcessFactory#getProcess(String)} methods. - */ - @Test - void testRegister() { - def process = new Process(null, null, null, null, null, null, null) - - def pf = new DummyFactory() - pf.registerProcess(process) - assert pf.getProcess(process.identifier) - } - - /** - * Test the {@link GroovyProcessFactory#create()} and {@link GroovyProcessFactory#create(Closure)} methods. - */ - @Test - void testCreate() { - def pf1 = new DummyFactory() - assert pf1.create() - - def process = pf1.create { - title "simple process" - description "description" - keywords "key1", "key2" - inputs inputA: String, inputB: String - outputs outputA: String - version "version" - run { inputA, inputB -> [outputA: inputA + inputB] } - } - - assert "simple process" == process.title - assert "description", process.description - assert "version", process.version - assert ["key1", "key2"] == process.keywords - assert 2, process.inputs.size - assert 1, process.outputs.size - } - - private static class DummyFactory extends GroovyProcessFactory { - @Override - - Object run() { - return null - } - - @Override - Object invokeMethod(String name, Object args) { - super.invokeMethod(name, args) - } - } -} diff --git a/process/src/test/groovy/org/orbisgis/process/TestLinker.groovy b/process/src/test/groovy/org/orbisgis/process/TestLinker.groovy deleted file mode 100644 index d76e9b23..00000000 --- a/process/src/test/groovy/org/orbisgis/process/TestLinker.groovy +++ /dev/null @@ -1,227 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process - -import org.junit.jupiter.api.Test -import org.orbisgis.process.api.inoutput.IInOutPut -import org.orbisgis.process.inoutput.Input -import org.orbisgis.process.inoutput.Output - -/** - * Test class dedicated to {@link Linker} class. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS Lab-STICC 2020) - */ -class TestLinker { - - /** - * Test the {@link Linker#Linker(IInOutPut...)} method. - */ - @Test - void linkerTest() { - def linker = [new Linker((IInOutPut[]) null)] - assert !linker[0].aliases - assert !linker[0].inputOutputMap - assert !linker[0].inputs - assert !linker[0].outputs - - linker[0] = new Linker() - assert !linker[0].aliases - assert !linker[0].inputOutputMap - assert !linker[0].inputs - assert !linker[0].outputs - - def in1 = new Input() - def in2 = new Input().name("in") - def out1 = new Output() - def out2 = new Output().name("out") - - def inputs = ["in": in2] - def outputs = ["out": out2] - new Process(null, null, null, inputs, outputs, null, null) - - linker[0] = new Linker(in1) - assert !linker[0].aliases - assert !linker[0].inputOutputMap - assert !linker[0].inputs - assert !linker[0].outputs - - linker[0] = new Linker(out1) - assert !linker[0].aliases - assert !linker[0].inputOutputMap - assert !linker[0].inputs - assert !linker[0].outputs - - linker[0] = new Linker(in2, out2) - assert !linker[0].aliases - assert !linker[0].inputOutputMap - assert !linker[0].inputs - assert !linker[0].outputs - - linker[0] = new Linker(in2) - assert !linker[0].aliases - assert !linker[0].inputOutputMap - assert !linker[0].inputs - assert !linker[0].outputs - - linker[0] = new Linker(out2) - assert !linker[0].aliases - assert !linker[0].inputOutputMap - assert !linker[0].inputs - assert !linker[0].outputs - } - - /** - * Test the {@link Linker#to(String)} method. - */ - @Test - void toAliasTest() { - def in1 = new Input().name("in1") - def in2 = new Input().name("in2") - def out1 = new Output().name("out1") - def out2 = new Output().name("out2") - - def inputs = ["in1": in1, "in2": in2] - def outputs = ["out1": out1, "out2": out2] - new Process(null, null, null, inputs, outputs, null, null) - - def linker = [new Linker(in1, in2)] - linker[0].to("toto") - assert 1 == linker[0].aliases.size() - assert linker[0].aliases.containsKey("toto") - assert !linker[0].inputOutputMap - assert 1 == linker[0].inputs.size() - assert !linker[0].outputs - - linker[0] = new Linker(in1, in2) - linker[0].to("in1") - assert 1 == linker[0].aliases.size() - assert linker[0].aliases.containsKey("in1") - assert !linker[0].inputOutputMap - assert !linker[0].inputs - assert !linker[0].outputs - - linker[0] = new Linker(out1) - linker[0].to("toto") - assert 1 == linker[0].aliases.size() - assert linker[0].aliases.containsKey("toto") - assert !linker[0].inputOutputMap - assert !linker[0].inputs - assert 1 == linker[0].outputs.size() - - linker[0] = new Linker(out1) - linker[0].to("out1") - assert 1 == linker[0].aliases.size() - assert linker[0].aliases.containsKey("out1") - assert !linker[0].inputOutputMap - assert !linker[0].inputs - assert !linker[0].outputs - } - - /** - * Test the {@link Linker#to(IInOutPut...)} method. - */ - @Test - void toIInOutPutTest() { - - def in1 = new Input().name("in1") - def in2 = new Input().name("in2") - def out1 = new Output().name("out1") - def out2 = new Output().name("out2") - - def linker = [new Linker(in1, in2)] - linker[0].to((IInOutPut[]) null) - assert !linker[0].aliases - assert !linker[0].inputOutputMap - assert !linker[0].inputs - assert !linker[0].outputs - - linker[0] = new Linker() - linker[0].to() - assert !linker[0].aliases - assert !linker[0].inputOutputMap - assert !linker[0].inputs - assert !linker[0].outputs - - def inputs = ["in1": in1, "in2": in2] - def outputs = ["out1": out1, "out2": out2] - new Process(null, null, null, inputs, outputs, null, null) - - linker[0] = new Linker(in1, in2) - linker[0].to(out1, out2) - assert !linker[0].aliases - assert 2 == linker[0].inputOutputMap.size() - assert !linker[0].inputs - assert !linker[0].outputs - - linker[0] = new Linker(out1, out2) - linker[0].to(in1, in2) - assert !linker[0].aliases - assert 2 == linker[0].inputOutputMap.size() - assert !linker[0].inputs - assert !linker[0].outputs - - linker[0] = new Linker(out1, out2) - linker[0].to(in1, out2) - assert !linker[0].aliases - assert !linker[0].inputOutputMap - assert !linker[0].inputs - assert !linker[0].outputs - - linker[0] = new Linker(in1) - linker[0].to(in2) - assert !linker[0].aliases - assert !linker[0].inputOutputMap - assert !linker[0].inputs - assert !linker[0].outputs - - linker[0] = new Linker(out1) - linker[0].to(out2) - assert !linker[0].aliases - assert !linker[0].inputOutputMap - assert !linker[0].inputs - assert !linker[0].outputs - - linker[0] = new Linker() - linker[0].to(out2) - assert !linker[0].aliases - assert !linker[0].inputOutputMap - assert !linker[0].inputs - assert !linker[0].outputs - } -} diff --git a/process/src/test/groovy/org/orbisgis/process/TestProcess.groovy b/process/src/test/groovy/org/orbisgis/process/TestProcess.groovy deleted file mode 100644 index ea404792..00000000 --- a/process/src/test/groovy/org/orbisgis/process/TestProcess.groovy +++ /dev/null @@ -1,503 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process - - -import org.locationtech.jts.geom.Geometry -import org.locationtech.jts.io.WKTReader -import org.orbisgis.data.api.dataset.ITable -import org.orbisgis.process.api.IProcessManager -import org.orbisgis.process.inoutput.Input -import org.orbisgis.process.inoutput.Output - -import static org.junit.jupiter.api.Assertions.* - -class TestProcess { - - private static final IProcessManager processManager = ProcessManager.processManager - - void testProcessCreation() { - - assertFalse processManager.create({}).execute() - assertTrue processManager.create({ run { 1 + 1 } }).execute() - - String[] arr = ["key1", "key2"] - - def process = processManager.create() - .title("simple process") - .description("description") - .keywords("key1", "key2") - .inputs([inputA: String, inputB: String]) - .outputs([outputA: String]) - .version("version") - .run({ inputA, inputB -> [outputA: inputA + inputB] }) - .process - process([inputA: "tata", inputB: "toto"]) - assertEquals "tatatoto", process.results.outputA - assertEquals "simple process", process.title - assertEquals "description", process.description - assertArrayEquals arr, process.keywords - assertEquals 2, process.inputs.size() - assertEquals 1, process.outputs.size() - assertEquals "version", process.version - - process = processManager.create({ - title "simple process" - description "description" - keywords "key1", "key2" - inputs inputA: String, inputB: String - outputs outputA: String - version "version" - run { inputA, inputB -> [outputA: inputA + inputB] } - }) - process([inputA: "tata", inputB: "toto"]) - assertEquals "tatatoto", process.results.outputA - assertEquals "simple process", process.title - assertEquals "description", process.description - assertArrayEquals arr, process.keywords - assertEquals 2, process.inputs.size() - assertEquals 1, process.outputs.size() - assertEquals "version", process.version - - process = processManager.create({ - title "simple process" - description "description" - keywords "key1", "key2" - inputs inputA: String, inputB: String - outputs outputA: String - version "version" - run { inputA, inputB -> [outputA: inputA + inputB] } - }) - - process([inputA: "tata", inputB: "toto"]) - assertEquals "tatatoto", process.results.outputA - assertEquals "simple process", process.title - assertEquals "description", process.description - assertArrayEquals arr, process.keywords - assertEquals 2, process.inputs.size() - assertEquals 1, process.outputs.size() - assertEquals "version", process.version - } - - void testNullResult() { - def process = processManager.create() - .title("simple process") - .run({ return }) - .process - assertTrue process() - assertTrue process.getResults().keySet().contains("result") - } - - void testSimpleProcess() { - def process = processManager.create() - .title("simple process") - .inputs([inputA: String, inputB: String]) - .outputs([outputA: String]) - .run({ inputA, inputB -> [outputA: inputA + inputB] }) - .process - process([inputA: "tata", inputB: "toto"]) - assertEquals "tatatoto", process.getResults().outputA - } - - void testSimpleProcess2() { - def p = processManager.create({ - title "OrbisGIS" - inputs inputA: String - outputs outputA: String - run { inputA -> [outputA: inputA.replace("OrbisGIS", "Bretagne")] } - }) - - p([inputA: 'OrbisGIS is nice']) - assertTrue(p.results.outputA.equals("Bretagne is nice")) - } - - void testSimpleProcess3() { - def h2GIS = H2GIS.open([databaseName: './target/loadH2GIS']) - h2GIS(""" - DROP TABLE IF EXISTS h2gis, super; - CREATE TABLE h2gis (id int, the_geom geometry(point)); - INSERT INTO h2gis VALUES (1, 'POINT(10 10)'::GEOMETRY), (2, 'POINT(1 1)'::GEOMETRY); - """) - - def p = processManager.create({ - title "With database" - inputs inputA: ITable - outputs outputA: String - run { inputA -> [outputA: inputA.getColumnNames] } - }) - - - p([inputA: h2GIS.getSpatialTable("h2gis")]) - assertTrue(p.results.outputA.equals(["ID", "THE_GEOM"])) - } - - void testSimpleProcess4() { - - def p = processManager.create({ - title "Create a buffer around a geometry" - inputs inputA: Geometry, distance: double - outputs outputA: Geometry - run { inputA, distance -> [outputA: inputA.buffer(distance)] } - }) - - p([inputA: new WKTReader().read("POINT(1 1)"), distance: 10]) - assertTrue new WKTReader().read("POLYGON ((11 1, 10.807852804032304 " + - "-0.9509032201612824, 10.238795325112868 -2.826834323650898, 9.314696123025453 -4.555702330196022, " + - "8.071067811865476 -6.071067811865475, 6.555702330196023 -7.314696123025453, 4.826834323650898 " + - "-8.238795325112868, 2.9509032201612833 -8.807852804032304, 1.0000000000000007 -9, -0.9509032201612819 " + - "-8.807852804032304, -2.826834323650897 -8.238795325112868, -4.55570233019602 -7.314696123025454, " + - "-6.071067811865475 -6.0710678118654755, -7.314696123025453 -4.555702330196022, -8.238795325112868 " + - "-2.8268343236508944, -8.807852804032306 -0.9509032201612773, -9 1.0000000000000075, -8.807852804032303 " + - "2.950903220161292, -8.238795325112862 4.826834323650909, -7.3146961230254455 6.555702330196034, " + - "-6.071067811865463 8.071067811865486, -4.555702330196008 9.314696123025463, -2.826834323650879 " + - "10.238795325112875, -0.9509032201612606 10.807852804032308, 1.0000000000000249 11, 2.950903220161309 " + - "10.807852804032299, 4.826834323650925 10.238795325112857, 6.555702330196048 9.314696123025435, " + - "8.071067811865499 8.07106781186545, 9.314696123025472 6.555702330195993, 10.238795325112882 " + - "4.826834323650862, 10.807852804032311 2.9509032201612437, 11 1))").equalsExact((Geometry) p.results.outputA, 1e-6) - } - - void testSimpleProcess5() { - - def p = processManager.create({ - title "Array" - inputs inputA: String[] - outputs outputA: String - run { inputA -> [outputA: inputA[1]] } - }) - - - p([inputA: ["A", "B", "C"]]) - assertEquals "B", p.getResults().outputA - } - - void testProcessWithDefaultValue1() { - - def p = processManager.create({ - title "simple process" - inputs inputA: String, inputB: "toto" - outputs outputA: String - run { inputA, inputB -> [outputA: inputA + inputB] } - }) - - assertTrue p([inputA: "tata"]) - assertEquals "tatatoto", p.getResults().outputA - } - - void testProcessWithDefaultValue2() { - def process = processManager.factory("test").create({ - title "simple process" - inputs inputA: "tata", inputB: String - outputs outputA: String - run { inputA, inputB -> [outputA: inputA + inputB] } - }) - assertTrue process([inputB: "toti"]) - assertEquals "tatatoti", process.getResults().outputA - } - - void testProcessWithDefaultValue3() { - def process = processManager.factory("test").create({ - title "simple process" - inputs inputA: String, inputB: "tyty", inputC: 5.23d, inputD: Double - outputs outputA: String - run { inputA, inputB, inputC, inputD -> [outputA: inputA + inputB + inputC + inputD] } - }) - assertTrue process([inputA: "tata", inputB: "toto", inputC: 1.0d, inputD: 2.1d]) - assertEquals "tatatoto1.02.1", process.getResults().outputA - assertTrue process([inputA: "tata", inputC: 1.0d, inputD: 2.1d]) - assertEquals "tatatyty1.02.1", process.getResults().outputA - assertTrue process([inputA: "tata", inputB: "toto", inputD: 2.1d]) - assertEquals "tatatoto5.232.1", process.getResults().outputA - assertTrue process([inputA: "tata", inputD: 2.1d]) - assertEquals "tatatyty5.232.1", process.getResults().outputA - assertFalse process([inputD: 2.1d]) - assertFalse process([inputA: "tata", inputB: "toto"]) - } - - /** - * --> ----- ---- - * | pA | -> | pB |--> - * --> ----- ---- - */ - void testMapping() { - def pA = processManager.factory("map1").create({ - title "pA" - inputs inA1: String, inA2: String - outputs outA1: String - run { inA1, inA2 -> [outA1: inA1 + inA2] } - }) - def pB = processManager.factory("map1").create({ - title "pB" - inputs inB1: String - outputs outB1: String - run { inB1 -> [outB1: inB1 + inB1] } - }) - - def mapper = new ProcessMapper() - mapper.link(pA.outA1).to(pB.inB1) - assertTrue mapper([inA1: "t", inA2: "a"]) - assertEquals "tata", mapper.getResults().outB1 - } - - /** - * --> ---- - * | pB | -----> ---- --> - * |--> ---- | pC | - * | |--> ---- --> - * |------------| - * | - * --> ---- | - * | pA | ---| - * ---- - */ - void testMapping2() { - def pA = processManager.factory("map2").create({ - title "pA" - inputs inA1: String - outputs outA1: String - run { inA1 -> [outA1: inA1.toUpperCase()] } - }) - def pB = processManager.factory("map2").create({ - title "pB" - inputs inB1: String, inB2: String - outputs outB1: String - run { inB1, inB2 -> [outB1: inB2 + inB1] } - }) - def pC = processManager.factory("map2").create({ - title "pC" - inputs inC1: String, inC2: String - outputs outC1: String, outC2: String - run { inC1, inC2 -> [outC1: inC1 + inC2, outC2: inC2 + inC1] } - }) - - def mapper = new ProcessMapper() - mapper.link(pA.outA1).to(pB.inB1) - mapper.link(pB.outB1).to(pC.inC2) - mapper.link(pA.outA1).to(pC.inC1) - - assertTrue mapper([inA1: "a", inB2: "b"]) - assertEquals "AbA", mapper.getResults().outC1 - assertEquals "bAA", mapper.getResults().outC2 - } - - /** - * --> ---- - * | pC | - * --> ---- --> ---- --> ---- --> - * | pA | | | pD | - * --> ----  |> ---- --> ---- --> - * | pB | - * --> ---- - */ - void testMapping3() { - def pA = processManager.factory("map3").create({ - title "process" - inputs in1: String - outputs out1: String - run { in1 -> [out1: in1.toUpperCase()] } - }) - def pB = processManager.factory("map3").create({ - title "pB" - inputs in1: String, in2: String - outputs out1: String - run { in1, in2 -> [out1: in2 + in1] } - }) - def pC = processManager.factory("map3").getProcess(pB.getIdentifier()) - def pD = processManager.factory("map3").create({ - title "pD" - inputs in1: String, in2: String - outputs out1: String, out2: String - run { in1, in2 -> [out1: in1.toLowerCase(), out2: in2 + in1] } - }) - - def mapper = new ProcessMapper() - mapper.link(pA.in1).to("a") - mapper.link(pB.in2).to("b") - mapper.link(pC.in2).to("c") - mapper.link(pA.out1).to(pB.in1) - mapper.link(pA.out1).to(pC.in1) - mapper.link(pB.out1).to(pD.in1) - mapper.link(pC.out1).to(pD.in2) - - assertTrue mapper([a: "a", b: "b", c: "c"]) - assertEquals "ba", mapper.getResults().out1 - assertEquals "cAbA", mapper.getResults().out2 - } - - /** - * --> ----- |--> ---- |--> ---- - * | pA |-| | pA |-| | pA |--> - * --> ----- |--> ---- |--> ---- - */ - void testMapping4() { - def pA1 = processManager.factory("map4").create({ - title "pA" - inputs inA1: String, inA2: String - outputs outA1: String - run { inA1, inA2 -> [outA1: inA1 + inA2] } - }) - def pA2 = processManager.factory("map4").getProcess(pA1.getIdentifier()) - def pA3 = processManager.factory("map4").getProcess(pA1.getIdentifier()) - - def mapper = new ProcessMapper() - mapper.link(pA1.outA1).to(pA2.inA1) - mapper.link(pA1.outA1).to(pA2.inA2) - mapper.link(pA2.outA1).to(pA3.inA1) - mapper.link(pA2.outA1).to(pA3.inA2) - assertTrue mapper([inA1: "t", inA2: "a"]) - assertEquals "tatatata", mapper.getResults().outA1 - } - - /** - * --> ----- |--> ---- - * | pA |-| | pB |---> - * --> ----- |--> ---- - * - * --> ----- |--> ---- - * | pA |-| | pB |---> - * --> ----- |--> ---- - */ - void testMapping5() { - def pA1 = processManager.factory("map5").create({ - title "pA" - inputs inA1: String, inA2: String - outputs outA1: String - run { inA1, inA2 -> [outA1: inA1 + inA2] } - }) - def pA2 = processManager.factory("map5").getProcess(pA1.getIdentifier()) - def pB1 = processManager.factory("map5").create({ - title "pB" - inputs inB1: String, inB2: String - outputs outB1: String - run { inB1, inB2 -> [outB1: inB1 + " or " + inB2] } - }) - def pB2 = processManager.factory("map5").getProcess(pB1.getIdentifier()) - - def mapper = new ProcessMapper() - - mapper.link(pA1.outA1).to(pB1.inB1) - mapper.link(pA1.outA1).to(pB1.inB2) - mapper.link(pA2.outA1).to(pB2.inB1, pB2.inB2) - - mapper.link(pA1.outA1).to("interPA1OutA1") - mapper.link(pA2.outA1).to("interPA2OutA1") - - mapper.link(pA1.inA1, pA2.inA1).to("commonInput") - mapper.link(pA1.inA2).to("inputD") - mapper.link(pA2.inA2).to("inputK") - - mapper.link(pB1.outB1).to("outD") - mapper.link(pB2.outB1).to("outK") - - assertTrue mapper([inputD: "D", inputK: "K", commonInput: "common"]) - assertFalse mapper.getResults().containsKey("outB1") - assertEquals "commonD or commonD", mapper.getResults().outD - assertEquals "commonK or commonK", mapper.getResults().outK - assertEquals "commonK", mapper.getResults().interPA2OutA1 - assertEquals "commonD", mapper.getResults().interPA1OutA1 - } - - /** - * X-> ----- ---- - * | pA | -> | pB |--> - * --> ----- ---- - * - * with test after and before pB and pA - */ - void testMapping6() { - def pA = processManager.factory("map1").create({ - title "pA" - inputs inA1: new Input().type(String).optional("t"), inA2: String - outputs outA1: new Output().type(String) - run { inA1, inA2 -> [outA1: inA1 + inA2] } - }) - def pB = processManager.factory("map1").create({ - title "pB" - inputs inB1: String - outputs outB1: String - run { inB1 -> [outB1: inB1 + inB1] } - }) - - def mapper = new ProcessMapper() - mapper.link(pA.outA1).to(pB.inB1) - - mapper.before(pA).with(pA.inA1).check({ inA1 -> inA1 == "t" }).stopOnFail("Fail") - mapper.after(pA).with(pA.outA1).check({ outA1 -> outA1 == "ta" }).stopOnFail("Fail") - - mapper.before(pB).with(pB.inB1, pA.outA1).check({ inB1, outA1 -> inB1 == "ta" && outA1 == inB1 }).stopOnFail("Fail") - mapper.after(pB).with(pB.outB1).check({ outB1 -> outB1 == "tata" }).stopOnFail("Fail") - - assertTrue mapper([inA2: "a"]) - assertEquals "tata", mapper.getResults().outB1 - } - - void testOnlyOneOptionalInput() { - String[] arr = ["key1", "key2"] - def process = processManager.create() - .title("simple process") - .description("description") - .keywords("key1", "key2") - .inputs([inputA: ["key1", "key2"], inputB: String]) - .outputs([outputA: String]) - .version("version") - .run({ inputA, inputB -> [outputA: inputA] }) - .process - assertTrue process.execute([inputB: String]) - assertFalse process.results.isEmpty() - assertTrue process.results.containsKey("outputA") - assertEquals arr.join(""), process.results.outputA.join("") - } - - void testBadTypeInput() { - String[] arr = ["key1", "key2"] - def process = processManager.create() - .title("simple process") - .description("description") - .keywords("key1", "key2") - .inputs([inputA: String[], inputB: "toto"]) - .outputs([outputA: String]) - .version("version") - .run({ inputA, inputB -> [outputA: inputA] }) - .process - assertFalse process.execute([inputB: 56D]) - assertTrue process.results.isEmpty() - //assertFalse process.execute([inputA: arr]) - //assertTrue process.results.isEmpty() - assertTrue process.execute([inputA: ["key1", "key2"]]) - assertFalse process.results.isEmpty() - } -} - diff --git a/process/src/test/groovy/org/orbisgis/process/TestProcessBuilder.groovy b/process/src/test/groovy/org/orbisgis/process/TestProcessBuilder.groovy deleted file mode 100644 index 2cc4324e..00000000 --- a/process/src/test/groovy/org/orbisgis/process/TestProcessBuilder.groovy +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process - -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.function.Executable -import org.orbisgis.process.api.IProcessFactory - -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow -import static org.junit.jupiter.api.Assertions.assertThrows - -/** - * Test class dedicated to {@link ProcessBuilder} class. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS Lab-STICC 2019-2020) - */ -class TestProcessBuilder { - - private static final Object delegate = "" - private static final IProcessFactory factory = new ProcessFactory() - - /** - * Test the {@link ProcessBuilder#ProcessBuilder(IProcessFactory, Object)} method. - */ - @Test - void constructorTest() { - assertDoesNotThrow((Executable){new ProcessBuilder(factory, delegate)}) - assertThrows(IllegalArgumentException) {new ProcessBuilder(null, delegate)} - assertThrows(IllegalArgumentException) {new ProcessBuilder(null, null)} - assertThrows(IllegalArgumentException) {new ProcessBuilder(factory, null)} - } - - /** - * Test the {@link ProcessBuilder#title(String)} method. - */ - @Test - void titleTest() { - def processBuilder = new ProcessBuilder(factory, delegate) - assert processBuilder == processBuilder.title("title") - - processBuilder = new ProcessBuilder(factory, delegate) - assert processBuilder == processBuilder.title(null) - } - - /** - * Test the {@link ProcessBuilder#description(String)} method. - */ - @Test - void descriptionTest() { - def processBuilder = new ProcessBuilder(factory, delegate) - assert processBuilder == processBuilder.description("description") - - processBuilder = new ProcessBuilder(factory, delegate) - assert processBuilder == processBuilder.description(null) - } - - /** - * Test the {@link ProcessBuilder#keywords(String[])} method. - */ - @Test - void keywordsTest() { - def processBuilder = new ProcessBuilder(factory, delegate) - assert processBuilder == processBuilder.keywords("key1", "key2") - - processBuilder = new ProcessBuilder(factory, delegate) - assert processBuilder == processBuilder.keywords(null) - } - - /** - * Test the {@link ProcessBuilder#inputs(LinkedHashMap)} method. - */ - @Test - void inputsTest() { - def inputs = [in1: String, in2: String, in3: String] - - def processBuilder = new ProcessBuilder(factory, delegate) - assert processBuilder == processBuilder.inputs(inputs) - - processBuilder = new ProcessBuilder(factory, delegate) - assert processBuilder == processBuilder.inputs(null) - } - - /** - * Test the {@link ProcessBuilder#outputs(LinkedHashMap)} method. - */ - @Test - void outputsTest() { - def outputs = [out1: String, out2: String] - - def processBuilder = new ProcessBuilder(factory, delegate) - assert processBuilder == processBuilder.outputs(outputs) - - processBuilder = new ProcessBuilder(factory, delegate) - assert processBuilder == processBuilder.outputs(null) - } - - /** - * Test the {@link ProcessBuilder#version(String)} method. - */ - @Test - void versionTest() { - def processBuilder = new ProcessBuilder(factory, delegate) - assert processBuilder == processBuilder.version("version") - processBuilder = new ProcessBuilder(factory, delegate) - assert processBuilder == processBuilder.version(null) - } - - /** - * Test the {@link ProcessBuilder#run(Closure)} method. - */ - @Test - void runTest() { - def processBuilder = new ProcessBuilder(factory, delegate) - assert processBuilder == processBuilder.run(null) - - def cl = {in1, in2, in3 -> return [out1:in1+in2+in3]} - processBuilder = new ProcessBuilder(factory, delegate) - assert processBuilder == processBuilder.run(cl) - } - - /** - * Teste the whole building chain. - */ - @Test - void testProcessBuilder() { - def inputs = [in1: String, in2: String, in3: String] - def outputs = [out1: String, out2: String] - def cl = {in1, in2, in3 -> return [out1:in1+in2+in3]} - - def builder = {factory, delegate -> new ProcessBuilder(factory, delegate)} - - def process = builder factory, delegate title "title" description "description" version "version" keywords "key1", "key2" inputs inputs outputs outputs run cl process - - assert "title" == process.title - assert "description" == process.description - assert "version" == process.version - assert ["key1", "key2"] == process.keywords - assert 3 == process.inputs.size() - assert 2 == process.outputs.size() - - process = new ProcessBuilder(factory, delegate) - .title(null) - .description(null) - .keywords(null) - .inputs(null) - .outputs(null) - .run(null) - .version(null) - .process - - assert !process.title - assert !process.description - assert !process.version - assert !process.keywords - assert !process.inputs - assert !process.outputs - } -} diff --git a/process/src/test/groovy/org/orbisgis/process/TestProcessFactory.groovy b/process/src/test/groovy/org/orbisgis/process/TestProcessFactory.groovy deleted file mode 100644 index e67f1f62..00000000 --- a/process/src/test/groovy/org/orbisgis/process/TestProcessFactory.groovy +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process - -import org.junit.jupiter.api.Test -import org.orbisgis.process.api.IProcess - -/** - * Test class dedicated to {@link ProcessFactory} class. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS Lab-STICC 2019- 2020) - */ -class TestProcessFactory { - - /** - * Test the {@link ProcessFactory#ProcessFactory(boolean, boolean)}, {@link ProcessFactory#ProcessFactory()}, - * {@link ProcessFactory#isDefault()} and {@link ProcessFactory#isLocked()} methods. - */ - @Test - void testAttributes() { - def pf = new ProcessFactory() - assert !pf.default - assert !pf.locked - - pf = new ProcessFactory(true, true) - assert pf.default - assert pf.locked - - pf = new ProcessFactory(false, true) - assert pf.default - assert !pf.locked - - pf = new ProcessFactory(true, false) - assert !pf.default - assert pf.locked - } - - /** - * Test the {@link ProcessFactory#registerProcess(IProcess)} and {@link ProcessFactory#getProcess(String)} methods. - */ - @Test - void testRegister() { - def process = new Process(null, null, null, null, null, null, null) - - def pf = new ProcessFactory(false, false) - pf.registerProcess(process) - assert pf.getProcess(process.identifier) - pf = new ProcessFactory(false, false) - pf.registerProcess(null) - assert !pf.getProcess(process.identifier) - - pf = new ProcessFactory(true, true) - pf.registerProcess(process) - assert !pf.getProcess(process.identifier) - pf = new ProcessFactory(true, true) - pf.registerProcess(null) - assert !pf.getProcess(process.identifier) - } - - /** - * Test the {@link ProcessFactory#create()} and {@link ProcessFactory#create(Closure)} methods. - */ - @Test - void testCreate() { - def pf1 = new ProcessFactory() - assert pf1.create() - - assert !pf1.create(null) - - def process = pf1.create { - title "simple process" - description "description" - keywords "key1", "key2" - inputs inputA: String, inputB: String - outputs outputA: String - version "version" - run { inputA, inputB -> [outputA: inputA + inputB] } - } - assert process - assert "simple process", process.title - assert "description", process.description - assert "version", process.version - assert ["key1", "key2"] == process.keywords - assert 2 == process.inputs.size() - assert 1 == process.outputs.size() - } -} diff --git a/process/src/test/groovy/org/orbisgis/process/TestProcessManager.groovy b/process/src/test/groovy/org/orbisgis/process/TestProcessManager.groovy deleted file mode 100644 index d80bc702..00000000 --- a/process/src/test/groovy/org/orbisgis/process/TestProcessManager.groovy +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process - -import org.junit.jupiter.api.Test - -/** - * Test class dedicated to {@link ProcessFactory} class. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS Lab-STICC 2019-2020) - */ -class TestProcessManager { - - /** - * Test the {@link ProcessManager#getProcessManager()} method - */ - @Test - void getProcessManagerTest() { - assert ProcessManager.getProcessManager() - } - - /** - * Test the {@link ProcessManager#create()} and {@link ProcessManager#create(Closure)} methods. - */ - @Test - void testCreate() { - def pm = ProcessManager.getProcessManager() - assert pm.create() - assert pm.create().getProcess() - - def process = pm.create { - title "simple process" - description "description" - keywords "key1", "key2" - inputs inputA: String, inputB: String - outputs outputA: String - version "version" - run { inputA, inputB -> [outputA: inputA + inputB] } - } - assert process - assert "simple process" == process.title - assert "description", process.description - assert "version", process.version - assert ["key1", "key2"] == process.keywords - assert 2, process.inputs.size() - assert 1 == process.outputs.size() - - process = pm.create(null) - assert !process - } - - /** - * Test the {@link ProcessManager#factoryIds()}, - * {@link ProcessManager#factory(String)}, {@link ProcessManager#factory()}, - * {@link ProcessManager#createFactory(String)}, {@link ProcessManager#createFactory()} methods. - */ - @Test - void testFactories() { - def pm = ProcessManager.getProcessManager() - assert ProcessManager.createFactory() - assert ProcessManager.createFactory("Mayor_DeFacto_Ry") - assert ProcessManager.createFactory(null) - assert ProcessManager.createFactory("") - - assert pm.factory() - assert pm.factory() == pm.factory(null) - assert pm.factory() == pm.factory("Default") - assert pm.factory("Mayor_DeFacto_Ry") - assert pm.factory("Factorio") - - assert pm.factoryIds().contains("Default") - assert pm.factoryIds().contains("Mayor_DeFacto_Ry") - assert pm.factoryIds().contains("Factorio") - } - - /** - * Test the {@link ProcessManager#process(String)} and {@link ProcessManager#process(String, String)} methods. - */ - @Test - void testProcess() { - def pm = ProcessManager.getProcessManager() - assert ProcessManager.createFactory("Mayor_DeFacto_Ry") - - def p1 = pm.factory().create { - title "simple process" - description "description" - keywords "key1", "key2" - inputs inputA: String, inputB: String - outputs outputA: String - version "version" - run { inputA, inputB -> [outputA: inputA + inputB] } - } - assert p1 - def id1 = p1.identifier - - def p2 = pm.factory("Mayor_DeFacto_Ry").create { - title "simple process" - description "description" - keywords "key1", "key2" - inputs inputA: String, inputB: String - outputs outputA: String - version "version" - run { inputA, inputB -> [outputA: inputA + inputB] } - } - assert p2 - def id2 = p2.identifier - - assert pm.process(id1) - assert !pm.process(id2) - - assert !pm.process(id1, "Mayor_DeFacto_Ry") - assert pm.process(id2, "Mayor_DeFacto_Ry") - - assert !pm.process(null) - assert !pm.process(null, "Mayor_DeFacto_Ry") - assert !pm.process(id2, null) - assert !pm.process(null, null) - } -} diff --git a/process/src/test/groovy/org/orbisgis/process/TestProcessMapper.groovy b/process/src/test/groovy/org/orbisgis/process/TestProcessMapper.groovy deleted file mode 100644 index d03ee836..00000000 --- a/process/src/test/groovy/org/orbisgis/process/TestProcessMapper.groovy +++ /dev/null @@ -1,307 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process - -import org.junit.jupiter.api.BeforeAll -import org.junit.jupiter.api.Test -import org.orbisgis.process.api.IProcess -import org.orbisgis.process.api.IProcessManager -import org.orbisgis.process.api.IProcessMapper -import org.orbisgis.process.api.inoutput.IInOutPut - -/** - * Test class dedicated to {@link ProcessMapper} class. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS 2019) - */ -class TestProcessMapper { - - private static final IProcessManager processManager = ProcessManager.getProcessManager() - - private static Process pA1 - private static Process pA2 - private static Process pB1 - private static Process pB2 - private static Process pC - - @BeforeAll - static void init() { - def pAInputMap = [inA1: String, inA2: String] - def pAOutputMap = [outA1: String] - pA1 = processManager.factory("map5").create().title("pA").inputs(pAInputMap).outputs(pAOutputMap) - .run({ in1, in2 -> ["outA1": "$in1$in2"] }).process - - pA2 = pA1.newInstance() - - def pBInputMap = [inB1: String, inB2: String] - def pBOutputMap = [outB1: String] - pB1 = processManager.factory("map5").create().title("pB").inputs(pBInputMap).outputs(pBOutputMap) - .run({ in1, in2 -> [outB1: "$in2 or $in1"] }).process - - pB2 = pB1.newInstance() - - - def pCInputMap = [inC1: "D", inC2: String] - def pCOutputMap = [outC1: String, outC2: String] - - pC = processManager.factory("map2").create().title("pC").inputs(pCInputMap).outputs(pCOutputMap) - .run{in1, in2 -> [outC1: "$in1$in2", outC2:"$in2$in1"]}.process - } - - /** - * --> ---- - * | pB | -----> ---- --> - * |--> ---- | pC | - * | |--> ---- --> - * |------------| - * | - * --> ---- | - * | pA | ---| - * ---- - */ - @Test - void mapping1Test() { - def pAInputMap = [inA1: String] - def pAOutputMap = [outA1: String] - def pA = processManager.factory("map2").create().title("pA").inputs(pAInputMap) - .outputs(pAOutputMap).run{in1 -> [outA1: "${in1.toUpperCase()}"]}.process - - def mapper = new ProcessMapper() - mapper.link(pA.outA1).to(pB1.inB1) - mapper.link(pB1.outB1).to(pC.inC2) - mapper.link(pA.outA1).to(pC.inC1) - - mapper.after(pA).with().check{1+1 == 2} - mapper.before(pA).with().check{1+1 == 2} - - def dataMap = [inA1: "a",inB2: "b"] - assert mapper(dataMap) - assert 2 == mapper.results.size() - assert "Ab or A" == mapper.results.get("outC1") - assert "b or AA" == mapper.results.get("outC2") - } - - - /** - * --> ----- |-----> ---- - * | pA |-| | pB |---> - * --> ----- |-\ /-> ---- - * X - * --> ----- |-/ \-> ---- - * | pA |-| | pB |---> - * --> ----- |-----> ---- - */ - @Test - void mapping2Test() { - - def mapper = new ProcessMapper() - - mapper.link(pA2.outA1).to(pB1.inB1) - mapper.link(pB2.inB2).to(pA2.outA1) - mapper.link(pA1.outA1).to(pB2.inB1, pB1.inB2) - - mapper.link(pA1.outA1).to("interPA1OutA1") - mapper.link(pA2.outA1).to("interPA2OutA1") - - mapper.link(pA1.inA1, pA2.inA1).to("commonInput") - mapper.link(pA1.inA2).to("inputD") - mapper.link(pA2.inA2).to("inputK") - - mapper.link(pB1.outB1).to("outD") - mapper.link(pB2.outB1).to("outK") - - def dataMap = [inputD: "D", inputK: "K", commonInput: "common"] - assert mapper(dataMap) - - assert 3 == mapper.inputs.size() - - assert 4 == mapper.outputs.size() - - assert !mapper.results.containsKey("outB1") - assert "commonD or commonK" == mapper.results.get("outD") - assert "commonK or commonD" == mapper.results.get("outK") - assert "commonK" == mapper.results.get("interPA2OutA1") - assert "commonD" == mapper.results.get("interPA1OutA1") - } - - - /** - * --> ----- - * | pA |--> - * --> ----- - *

- * --> ----- - * | pA |--> - * --> ----- - */ - @Test - void mapping4Test() { - - def mapper = new ProcessMapper() - - mapper.link(pA1.inA1, pA2.inA1).to("commonInput") - mapper.link(pA1.inA2).to("inputD") - mapper.link(pA2.inA2).to("inputK") - - def dataMap = [inputD: "D", inputK: "K", commonInput: "common"] - assert mapper(dataMap) - } - - - /** - * - */ - @Test - void mapping3Test() { - def mapper = new ProcessMapper() - - mapper.link(pC.outC1).to("out") - - def dataMap = [inC1: null, inC2: "K"] - assert mapper(dataMap) - - assert 2 == mapper.inputs.size() - - assert 2 == mapper.outputs.size() - - assert 2 == mapper.results.size() - assert !mapper.results.containsKey("outC1") - assert "DK" == mapper.results.get("out") - assert "KD" == mapper.results.get("outC2") - } - - /** - * Test a mapper which processes can't be linked. - */ - @Test - void noLinkeableTest() { - - def mapper = new ProcessMapper() - - mapper.link(pC.outC1).to(pC.inC1) - - def dataMap = [inC1: "D", inC2: "K"] - assert !mapper(dataMap) - } - - /** - * Test the methods {@link ProcessMapper#link(IInOutPut...)}, - * {@link org.orbisgis.process.api.ILinker#to(String)} and - * {@link org.orbisgis.process.api.ILinker#to(IInOutPut...)} methods in case of bad linking. - */ - @Test - void badMappingTest() { - IProcessMapper mapper = new ProcessMapper() - mapper.link(pA1.outA1).to(pB2.outB1) - assert !mapper.inputs - assert !mapper.outputs - - mapper = new ProcessMapper() - mapper.link(pA1.inA1).to(pB2.inB1) - assert !mapper.inputs - assert !mapper.outputs - - mapper = new ProcessMapper() - mapper.link(pA1.outA1, pB2.inB1) - assert !mapper.inputs - assert !mapper.outputs - - mapper = new ProcessMapper() - mapper.link(pA1.inA1).to(pA1.outA1, pB2.inB1) - assert !mapper.inputs - assert !mapper.outputs - - mapper = new ProcessMapper() - mapper.link(pA1.inA1).to() - assert !mapper.inputs - assert !mapper.outputs - - mapper = new ProcessMapper() - mapper.link() - assert !mapper.inputs - assert !mapper.outputs - } - - /** - * Test the methods {@link ProcessMapper#getTitle()}, {@link ProcessMapper#getDescription()}, - * {@link ProcessMapper#getKeywords()}, {@link ProcessMapper#getVersion()} methods. - */ - @Test - void getAttributesTest() { - def mapper = new ProcessMapper() - assert mapper.title - assert !mapper.description - assert !mapper.keywords - assert !mapper.version - - mapper = new ProcessMapper("title") - assert "title" == mapper.title - assert !mapper.description - assert !mapper.keywords - assert !mapper.version - } - - /** - * Test the methods {@link ProcessMapper#after(IProcess)}, {@link ProcessMapper#before(IProcess)} methods. - */ - @Test - void getCheckerTest() { - def mapper = new ProcessMapper() - assert mapper.after(null) - assert mapper.before(null) - } - - /** - * Test the methods {@link ProcessMapper#newInstance()} method. - */ - @Test - void newInstanceTest() { - def mapper = new ProcessMapper() - mapper.link(pA1.inA1).to("in") - mapper.link(pA1.outA1).to("out") - mapper(null) - def mapper2 = mapper.newInstance() - assert mapper.getTitle() != mapper2.getTitle() - assert mapper.getDescription() == mapper2.getDescription() - assert mapper.getKeywords() == mapper2.getKeywords() - assert mapper.inputs == mapper2.inputs - assert mapper.outputs == mapper2.outputs - assert mapper.getVersion() == mapper2.getVersion() - assert mapper.getIdentifier() != mapper2.getIdentifier() - } -} \ No newline at end of file diff --git a/process/src/test/groovy/org/orbisgis/process/TestProgressMonitor.groovy b/process/src/test/groovy/org/orbisgis/process/TestProgressMonitor.groovy deleted file mode 100644 index 03691844..00000000 --- a/process/src/test/groovy/org/orbisgis/process/TestProgressMonitor.groovy +++ /dev/null @@ -1,274 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process - -import org.junit.jupiter.api.Test - -import static java.lang.Math.round - -/** - * Test class dedicated to {@link ProgressMonitor} class. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (Lab-STICC UBS 2020) - */ -class TestProgressMonitor { - - @Test - void progressTest() { - def pm1 = new ProgressMonitor("main", 7, true) - def pm2 = new ProgressMonitor("main", 7) - def pm3 = new ProgressMonitor(7, true) - def pm4 = new ProgressMonitor(7) - def pm5 = new ProgressMonitor("main", true) - def pm6 = new ProgressMonitor(true) - def pm7 = new ProgressMonitor("main") - def pm8 = new ProgressMonitor() - - assert 7 == pm1.maxStep - assert 7 == pm2.maxStep - assert 7 == pm3.maxStep - assert 7 == pm4.maxStep - assert -1 == pm5.maxStep - assert -1 == pm6.maxStep - assert -1 == pm7.maxStep - assert -1 == pm8.maxStep - - assert "main", pm1.name - assert "main", pm2.name - assert pm3.name - assert pm4.name - assert "main", pm5.name - assert pm6.name - assert "main", pm7.name - assert pm8.name - } - - @Test - void progressWithMaxTest(){ - def list = [ - new ProgressMonitor("main", 7, true), - new ProgressMonitor("main", 7), - new ProgressMonitor(7, true), - new ProgressMonitor(7) - ] - - list.each { pm -> - def p = 0 - def p1 = 0 - def p2 = 0 - def p3 = 0 - def p4 = 0 - def p5 = 0 - def p6 = 0 - def p7 = 0 - assert 7 == pm.maxStep - assert 0.0 == pm.progress - - pm.incrementStep() - p++ - assert round(100.0 / 7.0 * 1.0) == round(pm.progress) - - def subPm1 = pm.getSubProgress("sub1", 4, false) - assert subPm1 - - pm.incrementStep() - p++ - pm.incrementStep() - p++ - assert round(100.0 / 8.0 * 3.0) == round(pm.progress) - - def subPm2 = pm.getSubProgress("sub2", 3) - assert subPm2 - def subPm3 = pm.getSubProgress("sub3", false) - assert subPm3 - def subPm4 = pm.getSubProgress(4, false) - assert subPm4 - def subPm5 = pm.getSubProgress("sub2") - assert subPm5 - def subPm6 = pm.getSubProgress(false) - assert subPm6 - def subPm7 = pm.getSubProgress(5) - assert subPm7 - - subPm1.incrementStep() - p1++ - assert round(getProg(p, p1, p2, p3, p4, p5, p6, p7)) == round(pm.progress) - - subPm1.incrementStep() - p1++ - subPm1.incrementStep() - p1++ - assert round(getProg(p, p1, p2, p3, p4, p5, p6, p7)) == round(pm.progress) - - subPm2.incrementStep() - p2++ - subPm2.incrementStep() - p2++ - assert round(getProg(p, p1, p2, p3, p4, p5, p6, p7)) == round(pm.progress) - - subPm3.incrementStep() - subPm3.incrementStep() - subPm3.incrementStep() - assert round(getProg(p, p1, p2, p3, p4, p5, p6, p7)) == round(pm.progress) - - subPm3.end() - p3 = 1 - assert round(getProg(p, p1, p2, p3, p4, p5, p6, p7)) == round(pm.progress) - - subPm5.end() - p5 = 1 - subPm6.end() - p6 = 1 - assert round(getProg(p, p1, p2, p3, p4, p5, p6, p7)) == round(pm.progress) - - subPm7.end() - p7 = 5 - assert round(getProg(p, p1, p2, p3, p4, p5, p6, p7)) == round(pm.progress) - - subPm1.incrementStep() - p1++ - subPm2.incrementStep() - p2++ - assert round(getProg(p, p1, p2, p3, p4, p5, p6, p7)) == round(pm.progress) - - pm.incrementStep() - p++ - pm.incrementStep() - p++ - assert round(getProg(p, p1, p2, p3, p4, p5, p6, p7)) == round(pm.progress) - - subPm4.end() - p4 = 4 - assert round(getProg(p, p1, p2, p3, p4, p5, p6, p7)) == round(pm.progress) - - pm.incrementStep() - pm.incrementStep() - assert 100.0 == round(pm.progress) - - pm.incrementStep() - pm.incrementStep() - pm.incrementStep() - assert 100.0 == round(pm.progress) - } - } - - @Test - void progressWithoutMaxTest(){ - def list = [ - new ProgressMonitor("main", true), - new ProgressMonitor(true), - new ProgressMonitor("main"), - new ProgressMonitor() - ] - - list.each { pm -> - assert -1 == pm.maxStep - assert -1 == pm.progress - - pm.incrementStep() - assert -1 == pm.progress - - def subPm1 = pm.getSubProgress("sub1", 4, false) - assert subPm1 - - pm.incrementStep() - pm.incrementStep() - assert -1, pm.progress - - def subPm2 = pm.getSubProgress("sub2", 3) - assert subPm2 - def subPm3 = pm.getSubProgress("sub3", false) - assert subPm3 - def subPm4 = pm.getSubProgress(4, false) - assert subPm4 - def subPm5 = pm.getSubProgress("sub2") - assert subPm5 - def subPm6 = pm.getSubProgress(false) - assert subPm6 - def subPm7 = pm.getSubProgress(5) - assert subPm7 - - subPm1.incrementStep() - assert -1 == pm.progress - - subPm1.incrementStep() - subPm1.incrementStep() - assert -1 == pm.progress - - subPm2.incrementStep() - subPm2.incrementStep() - assert -1 == pm.progress - - subPm3.incrementStep() - subPm3.incrementStep() - subPm3.incrementStep() - assert -1 == pm.progress - - subPm3.end() - assert -1 == pm.progress - - subPm5.end() - subPm6.end() - assert -1 == pm.progress - - subPm7.end() - assert -1 == pm.progress - - subPm1.incrementStep() - subPm2.incrementStep() - assert -1 == pm.progress - - pm.incrementStep() - pm.incrementStep() - assert -1 == pm.progress - - subPm4.end() - assert -1 == pm.progress - - pm.end() - assert 100.0, round(pm.progress) - } - } - - private static double getProg(float p, float p1, float p2, float p3, float p4, float p5, float p6, float p7){ - if(p3 == 0 || p5 == 0 || p6 == 0){ - return -1 - } - return (100.0/(7+7)*(p+p1/4+p2/3+p3+p4/4+p5+p6+p7/5)) - } -} \ No newline at end of file diff --git a/process/src/test/groovy/org/orbisgis/process/check/TestCheckClosureBuilder.groovy b/process/src/test/groovy/org/orbisgis/process/check/TestCheckClosureBuilder.groovy deleted file mode 100644 index c28d4a4c..00000000 --- a/process/src/test/groovy/org/orbisgis/process/check/TestCheckClosureBuilder.groovy +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process.check - - -import org.junit.jupiter.api.Test -import org.orbisgis.process.check.CheckClosureBuilder - -/** - * Test class dedicated to {@link org.orbisgis.process.check.CheckClosureBuilder} class. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS 2020) - */ -class TestCheckClosureBuilder { - - /** - * Test the {@link org.orbisgis.process.check.CheckClosureBuilder#check(Closure)} method. - */ - @Test - void checkTest() { - def dummy = new DummyProcessCheck() - def builder = new CheckClosureBuilder(dummy) - def cl = { } - assert builder.check(cl) - assert cl == dummy.closure.get() - - dummy = new DummyProcessCheck() - builder = new CheckClosureBuilder(dummy) - assert builder.check() - assert !dummy.closure.present - } -} diff --git a/process/src/test/groovy/org/orbisgis/process/check/TestCheckDataBuilder.groovy b/process/src/test/groovy/org/orbisgis/process/check/TestCheckDataBuilder.groovy deleted file mode 100644 index 062d5bd8..00000000 --- a/process/src/test/groovy/org/orbisgis/process/check/TestCheckDataBuilder.groovy +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process.check - -import org.junit.jupiter.api.Test -import org.orbisgis.process.api.inoutput.IInOutPut -import org.orbisgis.process.check.CheckDataBuilder -import org.orbisgis.process.inoutput.Input -import org.orbisgis.process.inoutput.Output - -/** - * Test class dedicated to {@link org.orbisgis.process.check.CheckClosureBuilder} class. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS 2020) - */ -class TestCheckDataBuilder { - - /** - * Test the {@link org.orbisgis.process.check.CheckDataBuilder#with(IInOutPut...)} method. - */ - @Test - void withTest() { - def (in1, in2) = [new Input(), new Input()] - def (out1, out2) = [new Output(), new Output()] - - def dummy = new DummyProcessCheck() - def builder = new CheckDataBuilder(dummy) - assert builder.with(in1, in2, out1, out2) - assert [in1, in2, out1, out2] == dummy.inputOrOutput - - dummy = new DummyProcessCheck() - builder = new CheckDataBuilder(dummy) - assert builder.with(out2) - assert [out2] == dummy.inputOrOutput - - dummy = new DummyProcessCheck() - builder = new CheckDataBuilder(dummy) - assert builder.with() - assert !dummy.inputOrOutput - - dummy = new DummyProcessCheck() - builder = new CheckDataBuilder(dummy) - assert builder.with() - assert !dummy.inputOrOutput - - dummy = new DummyProcessCheck() - builder = new CheckDataBuilder(dummy) - assert builder.with() - assert !dummy.inputOrOutput - } -} diff --git a/process/src/test/groovy/org/orbisgis/process/check/TestCheckOptionBuilder.groovy b/process/src/test/groovy/org/orbisgis/process/check/TestCheckOptionBuilder.groovy deleted file mode 100644 index 2daffd46..00000000 --- a/process/src/test/groovy/org/orbisgis/process/check/TestCheckOptionBuilder.groovy +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process.check - -import org.junit.jupiter.api.Test -import org.orbisgis.process.check.CheckOptionBuilder - -import static org.orbisgis.process.api.check.IProcessCheck.Action.CONTINUE -import static org.orbisgis.process.api.check.IProcessCheck.Action.STOP - -/** - * Test class dedicated to {@link org.orbisgis.process.check.CheckOptionBuilder} class. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS 2019-2020) - */ -class TestCheckOptionBuilder { - - /** - * Test the {@link org.orbisgis.process.check.CheckOptionBuilder#stopOnFail()}, {@link org.orbisgis.process.check.CheckOptionBuilder#stopOnFail(String)}, - * {@link org.orbisgis.process.check.CheckOptionBuilder#continueOnFail()}, {@link org.orbisgis.process.check.CheckOptionBuilder#continueOnFail(String)}methods. - */ - @Test - void onFailTest() { - def failMessage = "Fail Message" - def successMessage = "Success Message" - - def dummy = new DummyProcessCheck() - def builder = new CheckOptionBuilder(dummy) - assert builder.stopOnFail() - assert STOP == dummy.failAction - assert !dummy.failMessage - - dummy = new DummyProcessCheck() - builder = new CheckOptionBuilder(dummy) - assert builder.stopOnFail(failMessage) - assert STOP == dummy.failAction - assert failMessage == dummy.failMessage - - dummy = new DummyProcessCheck() - builder = new CheckOptionBuilder(dummy) - assert builder.stopOnFail() - assert STOP == dummy.failAction - assert !dummy.failMessage - - dummy = new DummyProcessCheck() - builder = new CheckOptionBuilder(dummy) - assert builder.stopOnFail() - assert STOP == dummy.failAction - assert !dummy.failMessage - - dummy = new DummyProcessCheck() - builder = new CheckOptionBuilder(dummy) - assert builder.stopOnFail() - assert STOP == dummy.failAction - assert !dummy.failMessage - - dummy = new DummyProcessCheck() - builder = new CheckOptionBuilder(dummy) - assert builder.continueOnFail(successMessage) - assert CONTINUE == dummy.failAction - assert successMessage == dummy.failMessage - - dummy = new DummyProcessCheck() - builder = new CheckOptionBuilder(dummy) - assert builder.continueOnFail() - assert CONTINUE == dummy.failAction - assert !dummy.failMessage - - dummy = new DummyProcessCheck() - builder = new CheckOptionBuilder(dummy) - assert builder.continueOnFail() - assert CONTINUE == dummy.failAction - assert !dummy.failMessage - - dummy = new DummyProcessCheck() - builder = new CheckOptionBuilder(dummy) - assert builder.continueOnFail() - assert CONTINUE == dummy.failAction - assert !dummy.failMessage - } - - /** - * Test the {@link CheckOptionBuilder#stopOnSuccess()}, {@link CheckOptionBuilder#stopOnSuccess(String)}, - * {@link CheckOptionBuilder#continueOnSuccess()}, {@link CheckOptionBuilder#continueOnSuccess(String)}methods. - */ - @Test - void onSuccessTest() { - def failMessage = "Fail Message" - def successMessage = "Success Message" - - def dummy = new DummyProcessCheck() - def builder = new CheckOptionBuilder(dummy) - assert builder.stopOnSuccess() - assert STOP == dummy.successAction - assert !dummy.successMessage - - dummy = new DummyProcessCheck() - builder = new CheckOptionBuilder(dummy) - assert builder.stopOnSuccess(failMessage) - assert STOP == dummy.successAction - assert failMessage, dummy.successMessage - - dummy = new DummyProcessCheck() - builder = new CheckOptionBuilder(dummy) - assert builder.stopOnSuccess() - assert STOP == dummy.successAction - assert !dummy.successMessage - - dummy = new DummyProcessCheck() - builder = new CheckOptionBuilder(dummy) - assert builder.stopOnSuccess() - assert STOP == dummy.successAction - assert !dummy.successMessage - - dummy = new DummyProcessCheck() - builder = new CheckOptionBuilder(dummy) - assert builder.stopOnSuccess() - assert STOP == dummy.successAction - assert !dummy.successMessage - - dummy = new DummyProcessCheck() - builder = new CheckOptionBuilder(dummy) - assert builder.continueOnSuccess(successMessage) - assert CONTINUE == dummy.successAction - assert successMessage == dummy.successMessage - - dummy = new DummyProcessCheck() - builder = new CheckOptionBuilder(dummy) - assert builder.continueOnSuccess() - assert CONTINUE == dummy.successAction - assert !dummy.successMessage - - dummy = new DummyProcessCheck() - builder = new CheckOptionBuilder(dummy) - assert builder.continueOnSuccess() - assert CONTINUE == dummy.successAction - assert !dummy.successMessage - - dummy = new DummyProcessCheck() - builder = new CheckOptionBuilder(dummy) - assert builder.continueOnSuccess() - assert CONTINUE == dummy.successAction - assert !dummy.successMessage - } -} diff --git a/process/src/test/groovy/org/orbisgis/process/check/TestProcessCheck.groovy b/process/src/test/groovy/org/orbisgis/process/check/TestProcessCheck.groovy deleted file mode 100644 index a5a8c9ac..00000000 --- a/process/src/test/groovy/org/orbisgis/process/check/TestProcessCheck.groovy +++ /dev/null @@ -1,320 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process.check - -import org.codehaus.groovy.runtime.InvokerHelper -import org.junit.jupiter.api.BeforeAll -import org.junit.jupiter.api.Test -import org.orbisgis.process.api.IProcess -import org.orbisgis.process.api.check.IProcessCheck -import org.orbisgis.process.api.inoutput.IInOutPut -import org.orbisgis.process.ProcessManager -import org.orbisgis.process.inoutput.Input -import org.orbisgis.process.inoutput.Output - -import static org.orbisgis.process.api.check.IProcessCheck.Action.CONTINUE -import static org.orbisgis.process.api.check.IProcessCheck.Action.STOP - -/** - * Test class dedicated to {@link org.orbisgis.process.check.ProcessCheck} class. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS 2020) - */ -class TestProcessCheck { - - private static IProcess PROCESS - - private static IProcess NULL_PROCESS - - @BeforeAll - static void beforeAll() { - PROCESS = ProcessManager.createFactory() - .create { - outputs "out1": String - inputs "in1": String, "in2": String, "in3": String - run {in1, in2, in3 -> return [out1:in1+in2+in3]} } - NULL_PROCESS = null - } - - @Test - void getProcessTest() { - assert new ProcessCheck(PROCESS).process - assert !new ProcessCheck(NULL_PROCESS).process - } - - /** - * Test the {@link ProcessCheck#fail()}, {@link ProcessCheck#success()}, - * {@link ProcessCheck#onFail(String)}, {@link ProcessCheck#onFail(IProcessCheck.Action, String)}, - * {@link ProcessCheck#onSuccess(String)}, {@link ProcessCheck#onSuccess(IProcessCheck.Action, String)} methods. - */ - @Test - void failSuccessTest() { - def message = "message" - def check = new ProcessCheck(PROCESS) - - assert check.fail() - assert !check.success() - - check.onFail(null, message) - assert check.fail() - check.onFail(null, null) - assert check.fail() - check.onFail(STOP, message) - assert check.fail() - check.onFail(STOP, null) - assert check.fail() - check.onFail(CONTINUE, message) - assert !check.fail() - check.onFail(CONTINUE, null) - assert !check.fail() - check.onFail(message) - assert check.fail() - check.onFail(null) - assert check.fail() - - check.onSuccess(null, message) - assert check.success() - check.onSuccess(null, null) - assert check.success() - check.onSuccess(STOP, message) - assert check.success() - check.onSuccess(STOP, null) - assert check.success() - check.onSuccess(CONTINUE, message) - assert !check.success() - check.onSuccess(CONTINUE, null) - assert !check.success() - check.onSuccess(message) - assert !check.success() - check.onSuccess(null) - assert !check.success() - } - - /** - * Test the {@link ProcessCheck#run(LinkedHashMap)}, {@link ProcessCheck#setClosure(Closure)}, - * {@link ProcessCheck#setInOutPuts(IInOutPut...)} methods. - */ - @Test - void runTest() { - def map = [in1: "a", in2: "b"] - def cl = {in1, in2, in3 -> return in1+in2+in3 == 'abc'} - - def emptyInOutPuts = [] - def inOutPuts = [ - new Input().process(PROCESS).name("in1").optional("a"), - new Input().process(PROCESS).name("in2"), - new Input().process(PROCESS).name("in3").optional("c")] - - def processCheck = new ProcessCheck(PROCESS) - - //Ensure the check is not run - processCheck.onFail(STOP, null) - processCheck.onSuccess(STOP, null) - - processCheck.closure = null - processCheck.inOutPuts = null - assert !processCheck.run() - assert !processCheck.run([:]) - assert !processCheck.run(map) - - processCheck.closure = null - processCheck.inOutPuts = emptyInOutPuts - assert !processCheck.run() - assert !processCheck.run([:]) - assert !processCheck.run(map) - - processCheck.closure = null - processCheck.inOutPuts = inOutPuts - assert !processCheck.run() - assert !processCheck.run([:]) - assert processCheck.run(map) - - processCheck.closure = cl - processCheck.inOutPuts = null - assert processCheck.run() - assert processCheck.run([:]) - assert processCheck.run(map) - - processCheck.closure = cl - processCheck.inOutPuts = emptyInOutPuts - assert processCheck.run() - assert processCheck.run([:]) - assert processCheck.run(map) - - processCheck.closure = cl - processCheck.inOutPuts = inOutPuts - assert processCheck.run() - assert processCheck.run([:]) - assert processCheck.run(map) - - - //Test that check without closure fail when required - def inOutPutsOpt = [ - new Input().process(PROCESS).name("in1").optional("a"), - new Input().process(PROCESS).name("in2").optional("b"), - new Input().process(PROCESS).name("in3").optional("c"), - new Output().process(PROCESS).name("out1")] - def noNameInOutPuts = [ - new Input().process(PROCESS).name("in1").optional("a"), - new Input().process(PROCESS).optional("b"), - new Input().process(PROCESS).optional("c"), - new Output().process(PROCESS).name("out1")] - - def mapMissingInputs = [in1: "a"] - def mapInvalidInputs = [in1: "a", in2: "a", in3: "a"] - def mapInputs = [in1: "a", in2: "b", in3: "c"] - - processCheck.onFail(STOP, null) - processCheck.onSuccess(CONTINUE, null) - - processCheck.closure = null - processCheck.inOutPuts = noNameInOutPuts - assert processCheck.run(map) - - processCheck.closure = null - processCheck.inOutPuts = inOutPuts - assert processCheck.run(mapInputs) - - processCheck.closure = null - processCheck.inOutPuts = inOutPutsOpt - assert processCheck.run(mapMissingInputs) - - processCheck.closure = null - processCheck.inOutPuts = inOutPutsOpt - assert processCheck.run(mapInvalidInputs) - - - //Test that check with closure fail when required - def inOutPutsNullProcess = [ - new Input().process(PROCESS).name("in1").optional("a"), - new Input().name("in2").optional("b"), - new Input().process(PROCESS).name("in3").optional("c"), - new Output().process(PROCESS).name("out1")] - - processCheck.closure = cl - processCheck.inOutPuts = inOutPutsNullProcess - assert processCheck.run(mapInputs) - - processCheck.closure = cl - processCheck.inOutPuts = noNameInOutPuts - assert processCheck.run(mapInputs) - - processCheck.closure = cl - processCheck.inOutPuts = noNameInOutPuts - assert processCheck.run(null) - - processCheck.closure = cl - processCheck.inOutPuts = inOutPuts - assert processCheck.run(mapInvalidInputs) - - processCheck.closure = {in1, in2, in3 -> return in1+in2+in3} - processCheck.inOutPuts = inOutPuts - assert processCheck.run(mapInputs) - - processCheck.closure = {in1, in2, in3 -> return false} - processCheck.inOutPuts = inOutPuts - assert processCheck.run(mapInputs) - - processCheck.closure = null - processCheck.inOutPuts = [ - new Input().process(PROCESS).name("in1").optional("a"), - new Input().process(PROCESS).name("in2").optional("b"), - new Input().process(PROCESS).name("in3").optional("c")] - assert !processCheck.run(mapInputs) - - processCheck.closure = cl - processCheck.inOutPuts = [ - new Input().process(PROCESS).name("in1"), - new Input().process(PROCESS).name("in2"), - new Input().process(PROCESS).name("in3")] - assert !processCheck.run(mapInputs) - - assert PROCESS.execute(mapInputs) - processCheck.closure = {out1 -> return out1 == 'abc'} - processCheck.inOutPuts = [new Output().process(PROCESS).name("out1")] - assert !processCheck.run(mapInputs) - } - - /** - * Test the {@link ProcessCheck#setProperty(String, Object)}, {@link ProcessCheck#getProperty(String)} methods. - */ - @Test - void propertyTest() { - def processCheck = new ProcessCheck(PROCESS) - - processCheck.inOutPuts == null - def obj = processCheck.inOutPuts - assert obj !instanceof Optional - assert obj instanceof LinkedList - assert obj.isEmpty() - - processCheck.inOutPuts = [new Input()] - obj = processCheck.inOutPuts - assert obj !instanceof Optional - assert obj instanceof LinkedList - assert 1 == obj.size() - - obj = processCheck.inOutPuts - assert obj - - processCheck.metaClass = InvokerHelper.getMetaClass(getClass()) - obj = processCheck.metaClass - assert obj - - processCheck.metaClass = null - processCheck.inOutPuts = null - obj = processCheck.inOutPuts - assert obj - } - - /** - * Test the {@link ProcessCheck#invokeMethod(String, Object)} methods. - */ - @Test - void invokeMethodTest() { - def processCheck = new ProcessCheck(PROCESS) - - assert !processCheck.invokeMethod(null, "value") - assert !processCheck.invokeMethod(null, null) - assert !processCheck.invokeMethod("setClosure", null) - assert !processCheck.invokeMethod("getClosure", null) - - assert !processCheck.invokeMethod("setClosure", {in1, in2, in3 -> return in1+in2+in3 == 'abc'}) - assert processCheck.invokeMethod("getClosure", null) - } -} diff --git a/process/src/test/groovy/org/orbisgis/process/inoutput/TestInOutPut.groovy b/process/src/test/groovy/org/orbisgis/process/inoutput/TestInOutPut.groovy deleted file mode 100644 index 7bb5a225..00000000 --- a/process/src/test/groovy/org/orbisgis/process/inoutput/TestInOutPut.groovy +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process.inoutput - -import org.junit.jupiter.api.Test -import org.orbisgis.process.api.IProcess - -import static org.orbisgis.process.ProcessManager.createFactory as factory - -/** - * Test class dedicated to {@link InOutPut} class. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS Lab-STICC 2020) - */ -class TestInOutPut { - - /** - * Test the {@link InOutPut#setName(String)} and {@link InOutPut#getName()} method. - */ - @Test - void nameTest() { - def dummyInOutPut = new DummyInOutPut() - assert !dummyInOutPut.name - assert dummyInOutPut.name("name") instanceof InOutPut - assert dummyInOutPut.name - assert "name" == dummyInOutPut.name - dummyInOutPut.name = null - assert !dummyInOutPut.name - } - - /** - * Test the {@link InOutPut#setProcess(IProcess)} and {@link InOutPut#getProcess()} method. - */ - @Test - void processTest() { - def process = factory().create().process - def dummyInOutPut = new DummyInOutPut() - assert !dummyInOutPut.process - assert dummyInOutPut.process(process) instanceof InOutPut - assert dummyInOutPut.process - assert process == dummyInOutPut.process - dummyInOutPut.process = null - assert !dummyInOutPut.process - } - - /** - * Test the {@link InOutPut#setTitle(String)} and {@link InOutPut#getTitle()} method. - */ - @Test - void titleTest() { - def dummyInOutPut = new DummyInOutPut() - assert !dummyInOutPut.title - assert dummyInOutPut.title("title") instanceof InOutPut - assert dummyInOutPut.title - assert "title" == dummyInOutPut.title - dummyInOutPut.title = null - assert !dummyInOutPut.title - } - - /** - * Test the {@link InOutPut#setDescription(String)} and {@link InOutPut#getDescription()} method. - */ - @Test - void descriptionTest() { - def dummyInOutPut = new DummyInOutPut() - assert !dummyInOutPut.description - assert dummyInOutPut.description("descr") instanceof InOutPut - assert dummyInOutPut.description - assert "descr", dummyInOutPut.description - dummyInOutPut.description = null - assert !dummyInOutPut.description - } - - /** - * Test the {@link InOutPut#setKeywords(String[])} and {@link InOutPut#getKeywords()} method. - */ - @Test - void keywordsTest() { - def dummyInOutPut = new DummyInOutPut() - assert !dummyInOutPut.keywords - assert dummyInOutPut.keywords(new String[]{"key1", "key2"}) instanceof InOutPut - assert dummyInOutPut.keywords - assert new String[]{"key1", "key2"} == dummyInOutPut.keywords - dummyInOutPut.keywords = null - assert !dummyInOutPut.keywords - } - - /** - * Test the {@link InOutPut#setType(Class)} and {@link InOutPut#getType()} method. - */ - @Test - void typeTest() { - def dummyInOutPut = new DummyInOutPut() - assert !dummyInOutPut.type - assert dummyInOutPut.type(Integer.class) instanceof InOutPut - assert dummyInOutPut.type - assert Integer.class, dummyInOutPut.type - dummyInOutPut.type = null - assert !dummyInOutPut.type - } - - /** - * Test the {@link InOutPut#toString()} method. - */ - @Test - void toStringTest() { - def process = factory().create().getProcess() - def dummyInOutPut = new DummyInOutPut() - assert !dummyInOutPut.toString() - - dummyInOutPut.name "name" - assert "name", dummyInOutPut.toString() - - dummyInOutPut.process = process - assert "name:" + process.getIdentifier() == dummyInOutPut.toString() - - dummyInOutPut.name = null - assert ":" + process.getIdentifier() == dummyInOutPut.toString() - } -} diff --git a/process/src/test/groovy/org/orbisgis/process/inoutput/TestInput.groovy b/process/src/test/groovy/org/orbisgis/process/inoutput/TestInput.groovy deleted file mode 100644 index 470bdc4c..00000000 --- a/process/src/test/groovy/org/orbisgis/process/inoutput/TestInput.groovy +++ /dev/null @@ -1,243 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process.inoutput - -import org.junit.jupiter.api.Test -import org.orbisgis.process.api.IProcess - -import static org.orbisgis.process.ProcessManager.createFactory - -/** - * Test class dedicated to {@link Input} class. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS Lab-STICC 2020) - */ -class TestInput { - - /** - * Test the {@link Input#setName(String)} and {@link Input#getName()} method. - */ - @Test - void nameTest() { - def input = new Input() - assert !input.name - assert input.name("name") - assert input.name - assert "name" == input.name - input.name = null - assert !input.name - } - - /** - * Test the {@link Input#setProcess(IProcess)} and {@link Input#getProcess()} method. - */ - @Test - void processTest() { - def process = createFactory().create().getProcess() - def input = new Input() - assert !input.process - assert input.process(process) - assert input.process - assert process == input.process - input.process = null - assert !input.process - } - - /** - * Test the {@link Input#setTitle(String)} and {@link Input#getTitle()} method. - */ - @Test - void titleTest() { - def input = new Input() - assert !input.title - assert input.title("title") - assert input.title - assert "title", input.title - input.title = null - assert !input.title - } - - /** - * Test the {@link Input#setDescription(String)} and {@link Input#getDescription()} method. - */ - @Test - void descriptionTest() { - def input = new Input() - assert !input.description - assert input.description("descr") - assert input.description - assert "descr" == input.description - input.description = null - assert !input.description - } - - /** - * Test the {@link Input#setKeywords(String[])} and {@link Input#getKeywords()} method. - */ - @Test - void keywordsTest() { - def input = new Input() - assert !input.keywords - assert input.keywords(new String[]{"key1", "key2"}) - assert input.keywords - assert new String[]{"key1", "key2"} == input.keywords - input.keywords = null - assert !input.keywords - } - - /** - * Test the {@link Input#setType(Class)} and {@link Input#getType()} method. - */ - @Test - void typeTest() { - def input = new Input() - assert !input.type - assert input.type(Integer) - assert input.type - assert Integer, input.type - input.type = null - assert !input.type - } - - /** - * Test the {@link Input#toString()} method. - */ - @Test - void toStringTest() { - def process = createFactory().create().process - def input = new Input() - assert !input.toString() - - input.name = "name" - assert "name", input.toString() - - input.process = process - assert "name:" + process.identifier == input.toString() - - input.name = null - assert ":" + process.identifier == input.toString() - } - - /** - * Test the {@link Input#optional(Object)}, {@link Input#isOptional()}, {@link Input#getDefaultValue()} methods. - */ - @Test - void optionalTest() { - def input = new Input() - assert !input.defaultValue - assert !input.optional - assert input.mandatory - assert input.optional("toto") - assert input.defaultValue - assert "toto" == input.defaultValue - assert input.optional - assert !input.mandatory - } - - /** - * Test the {@link Input#mandatory()} and {@link Input#isMandatory()} methods. - */ - @Test - void mandatoryTest() { - def input = new Input() - assert !input.defaultValue - assert !input.optional - assert input.mandatory - assert input.mandatory() - assert !input.defaultValue - assert !input.optional - assert input.mandatory - } - - /** - * Test the {@link Input#equals(Object)} method. - */ - @Test - void equalsTest() { - def p1 = createFactory().create().process - def p2 = createFactory().create().process - def in1 = new Input().name("toto").process(p1) - def in2 = new Input().name("toto").process(p1) - def in3 = new Input().name("toto").process(p2) - def in4 = new Input().name("toto") - def in5 = new Input().name("tata").process(p1) - def in6 = new Input() - - assert in1 == in2 - - assert in1 != in3 - assert in1 != in4 - assert in1 != in5 - assert in1 != in6 - assert in1 != "in3" - assert in1 != null - } - - /** - * Test the {@link Input#copy()} method. - */ - @Test - void copyTest() { - def p1 = createFactory().create().process - def p2 = createFactory().create().process - def in1 = new Input().name("toto").process(p1) - def in2 = new Input().name("toto").process(p1) - def in3 = new Input().name("toto").process(p2) - def in4 = new Input().name("toto") - def in5 = new Input().name("tata").process(p1) - def in6 = new Input() - - assert in1 == in1.copy() - assert in1 !== in1.copy() - - assert in2 == in2.copy() - assert in2 !== in2.copy() - - assert in3 == in3.copy() - assert in3 !== in3.copy() - - assert in4 == in4.copy() - assert in4 !== in4.copy() - - assert in5 == in5.copy() - assert in5 !== in5.copy() - - assert in6 == in6.copy() - assert in6 !== in6.copy() - } -} diff --git a/process/src/test/groovy/org/orbisgis/process/inoutput/TestOutput.groovy b/process/src/test/groovy/org/orbisgis/process/inoutput/TestOutput.groovy deleted file mode 100644 index 2025bc20..00000000 --- a/process/src/test/groovy/org/orbisgis/process/inoutput/TestOutput.groovy +++ /dev/null @@ -1,212 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process.inoutput - -import org.junit.jupiter.api.Test -import org.orbisgis.process.api.IProcess - -import static org.orbisgis.process.ProcessManager.createFactory - -/** - * Test class dedicated to {@link Output} class. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS Lab-STICC 2020) - */ -class TestOutput { - - /** - * Test the {@link Output#setName(String)} and {@link Output#getName()} method. - */ - @Test - void nameTest() { - def output = new Output() - assert !output.name - assert output.name("name") - assert output.name - assert "name" == output.name - output.name = null - assert !output.name - } - - /** - * Test the {@link Output#setProcess(IProcess)} and {@link Output#getProcess()} method. - */ - @Test - void processTest() { - def process = createFactory().create().getProcess() - def output = new Output() - assert !output.process - assert output.process(process) - assert output.process - assert process == output.process - output.process = null - assert !output.process - } - - /** - * Test the {@link Output#setTitle(String)} and {@link Output#getTitle()} method. - */ - @Test - void titleTest() { - def output = new Output() - assert !output.title - assert output.title("title") - assert output.title - assert "title" == output.title - output.title = null - assert !output.title - } - - /** - * Test the {@link Output#setDescription(String)} and {@link Output#getDescription()} method. - */ - @Test - void descriptionTest() { - def output = new Output() - assert !output.description - assert output.description("descr") - assert output.description - assert "descr" == output.description - output.description = null - assert !output.description - } - - /** - * Test the {@link Output#setKeywords(String[])} and {@link Output#getKeywords()} method. - */ - @Test - void keywordsTest() { - def output = new Output() - assert !output.keywords - assert output.keywords(new String[]{"key1", "key2"}) - assert output.keywords - assert new String[]{"key1", "key2"} == output.keywords - output.keywords = null - assert !output.keywords - } - - /** - * Test the {@link Output#setType(Class)} and {@link Output#getType()} method. - */ - @Test - void typeTest() { - def output = new Output() - assert !output.type - assert output.type(Integer) - assert output.type - assert Integer == output.type - output.type = null - assert !output.type - } - - /** - * Test the {@link Output#toString()} method. - */ - @Test - void toStringTest() { - def process = createFactory().create().getProcess() - def output = new Output() - assert !output.toString() - - output.name = "name" - assert "name" == output.toString() - - output.process = process - assert "name:" + process.getIdentifier() == output.toString() - - output.name = null - assert ":" + process.getIdentifier() == output.toString() - } - - /** - * Test the {@link Output#equals(Object)} method. - */ - @Test - void equalsTest() { - def p1 = createFactory().create().process - def p2 = createFactory().create().process - def out1 = new Output().name("toto").process(p1) - def out2 = new Output().name("toto").process(p1) - def out3 = new Output().name("toto").process(p2) - def out4 = new Output().name("toto") - def out5 = new Output().name("tata").process(p1) - def out6 = new Output() - - assert out1 == out2 - - assert out1 != out3 - assert out1 != out4 - assert out1 != out5 - assert out1 != out6 - assert out1 != "out3" - assert out1 != null - } - - /** - * Test the {@link Output#copy()} method. - */ - @Test - void copyTest() { - def p1 = createFactory().create().process - def p2 = createFactory().create().process - def out1 = new Output().name("toto").process(p1) - def out2 = new Output().name("toto").process(p1) - def out3 = new Output().name("toto").process(p2) - def out4 = new Output().name("toto") - def out5 = new Output().name("tata").process(p1) - def out6 = new Output() - - assert out1 == out1.copy() - assert out1 !== out1.copy() - - assert out2 == out2.copy() - assert out2 !== out2.copy() - - assert out3 == out3.copy() - assert out3 !== out3.copy() - - assert out4 == out4.copy() - assert out4 !== out4.copy() - - assert out5 == out5.copy() - assert out5 !== out5.copy() - - assert out6 == out6.copy() - assert out6 !== out6.copy() - } -} diff --git a/process/src/test/java/org/orbisgis/process/GroovyProcessFactoryTest.java b/process/src/test/java/org/orbisgis/process/GroovyProcessFactoryTest.java deleted file mode 100644 index 6a0b6852..00000000 --- a/process/src/test/java/org/orbisgis/process/GroovyProcessFactoryTest.java +++ /dev/null @@ -1,523 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process; - -import groovy.lang.Closure; -import groovy.lang.GroovyObject; -import groovy.lang.GroovyShell; -import groovy.lang.MetaClass; -import org.codehaus.groovy.runtime.InvokerHelper; -import org.codehaus.groovy.runtime.metaclass.MissingPropertyExceptionNoStack; -import org.junit.jupiter.api.Test; -import org.orbisgis.process.api.IProcess; -import org.orbisgis.process.api.IProcessManager; -import org.slf4j.Logger; -import org.slf4j.Marker; - -import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.*; - -/** - * Test class dedicated to {@link GroovyProcessFactory} class. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS Lab-STICC 2019- 2020) - */ -public class GroovyProcessFactoryTest { - - /** - * Test the {@link GroovyProcessFactory#isDefault()} and {@link GroovyProcessFactory#isLocked()} methods. - */ - @Test - void testAttributes() { - GroovyProcessFactory pf = new DummyFactory(); - assertFalse(pf.isDefault()); - assertFalse(pf.isLocked()); - } - - /** - * Test the {@link GroovyProcessFactory#registerProcess(IProcess)} and {@link GroovyProcessFactory#getProcess(String)} methods. - */ - @Test - void testRegister() { - IProcess process = new Process(null, null, null, null, null, null, null); - - DummyFactory pf = new DummyFactory(); - pf.registerProcess(process); - assertTrue(pf.getProcess(process.getIdentifier()).isPresent()); - } - - /** - * Test the {@link GroovyProcessFactory#create()} and {@link GroovyProcessFactory#create(Closure)} methods. - */ - @Test - void testCreate() { - GroovyProcessFactory pf1 = new DummyFactory(); - assertNotNull(pf1.create()); - Optional opt = pf1.create(null); - assertFalse(opt.isPresent()); - - String string = "({\n" + - " title \"simple process\"\n" + - " description \"description\"\n" + - " keywords \"key1\", \"key2\"\n" + - " inputs inputA: String, inputB: String\n" + - " outputs outputA: String\n" + - " version \"version\"\n" + - " run { inputA, inputB -> [outputA: inputA + inputB] }\n" + - " })"; - Closure cl = (Closure) new GroovyShell().evaluate(string); - opt = pf1.create(cl); - assertTrue(opt.isPresent()); - - IProcess process = opt.get(); - assertTrue(process.getTitle().isPresent()); - assertEquals("simple process", process.getTitle().get()); - assertTrue(process.getDescription().isPresent()); - assertEquals("description", process.getDescription().get()); - assertTrue(process.getVersion().isPresent()); - assertEquals("version", process.getVersion().get()); - assertTrue(process.getKeywords().isPresent()); - assertArrayEquals(new String[]{"key1", "key2"}, process.getKeywords().get()); - assertEquals(2, process.getInputs().size()); - assertEquals(1, process.getOutputs().size()); - } - - /** - * Test the {@link GroovyProcessFactory#invokeMethod(String, Object)} method. - */ - @Test - void invokeMethodTest() { - DummyFactory factory = new DummyFactory(); - assertNull(factory.invokeMethod(null, null)); - assertEquals(false, factory.invokeMethod("isLocked", null)); - assertNull(factory.invokeMethod("getProcess", null)); - factory.setMetaClass(null); - assertNull(factory.invokeMethod(null, null)); - assertEquals(false, factory.invokeMethod("isLocked", null)); - assertNull(factory.invokeMethod("getProcess", null)); - assertNull(factory.invokeMethod("create", new Object[]{null})); - } - - /** - * Test the {@link GroovyProcessFactory#getProcessManager()} and {@link GroovyProcessFactory#setProcessManager(IProcessManager)} method. - */ - @Test - void getProcessManagerTest() { - DummyFactory factory = new DummyFactory(); - assertFalse(factory.getProcessManager().isPresent()); - ProcessManager pm = new ProcessManager(); - factory.setProcessManager(pm); - assertTrue(factory.getProcessManager().isPresent()); - assertEquals(pm, factory.getProcessManager().get()); - factory.setProcessManager(null); - assertFalse(factory.getProcessManager().isPresent()); - } - - /** - * Test the {@link GroovyProcessFactory#prefix(String)}, {@link GroovyProcessFactory#prefix(String, String)}, - * {@link GroovyProcessFactory#postfix(String)}, {@link GroovyProcessFactory#postfix(String, String)} methods. - */ - @Test - void prePostFixTest() { - assertEquals("tata_toto", GroovyProcessFactory.prefix("tata", "toto")); - assertEquals("tata_null", GroovyProcessFactory.prefix("tata", null)); - assertEquals("toto", GroovyProcessFactory.prefix(null, "toto")); - assertEquals("toto", GroovyProcessFactory.prefix("", "toto")); - assertEquals("tata_toto", GroovyProcessFactory.postfix("tata", "toto")); - assertEquals("null_toto", GroovyProcessFactory.postfix(null, "toto")); - assertEquals("tata", GroovyProcessFactory.postfix("tata", null)); - assertEquals("tata", GroovyProcessFactory.postfix("tata", "")); - assertTrue(GroovyProcessFactory.prefix("toto").endsWith("toto")); - assertTrue(GroovyProcessFactory.postfix("toto").startsWith("toto")); - } - - /** - * Test the {@link GroovyProcessFactory#getProperty(String)} method. - */ - @Test - void getPropertyTest() { - DummyFactory factory = new DummyFactory(); - factory.registerProcess(new Process("toto", null, null, null, null, null, null, null)); - assertNotNull(factory.getProperty("toto")); - assertNull(factory.getProperty(null)); - assertNull(factory.getProperty("processManager")); - assertNotNull(factory.getProperty("metaClass")); - assertThrows(MissingPropertyExceptionNoStack.class, () -> factory.getProperty("pm")); - } - - private static class DummyFactory extends GroovyProcessFactory { - @Override - - public Object run() { - return null; - } - } - - private static class DummyLogger implements Logger, GroovyObject { - - private MetaClass metaClass = InvokerHelper.getMetaClass(this.getClass()); - - public String infoS; - public Throwable infoE; - public String debugS; - public Throwable debugE; - public String warnS; - public Throwable warnE; - public String errorS; - public Throwable errorE; - - @Override - public String getName() { - return null; - } - - @Override - public boolean isTraceEnabled() { - return false; - } - - @Override - public void trace(String s) { - - } - - @Override - public void trace(String s, Object o) { - - } - - @Override - public void trace(String s, Object o, Object o1) { - - } - - @Override - public void trace(String s, Object... objects) { - - } - - @Override - public void trace(String s, Throwable throwable) { - - } - - @Override - public boolean isTraceEnabled(Marker marker) { - return false; - } - - @Override - public void trace(Marker marker, String s) { - - } - - @Override - public void trace(Marker marker, String s, Object o) { - - } - - @Override - public void trace(Marker marker, String s, Object o, Object o1) { - - } - - @Override - public void trace(Marker marker, String s, Object... objects) { - - } - - @Override - public void trace(Marker marker, String s, Throwable throwable) { - - } - - @Override - public boolean isDebugEnabled() { - return false; - } - - @Override - public void debug(String s) { - debugS = s; - } - - @Override - public void debug(String s, Object o) { - } - - @Override - public void debug(String s, Object o, Object o1) { - - } - - @Override - public void debug(String s, Object... objects) { - - } - - @Override - public void debug(String s, Throwable throwable) { - debugS = s; - debugE = throwable; - } - - @Override - public boolean isDebugEnabled(Marker marker) { - return false; - } - - @Override - public void debug(Marker marker, String s) { - - } - - @Override - public void debug(Marker marker, String s, Object o) { - - } - - @Override - public void debug(Marker marker, String s, Object o, Object o1) { - - } - - @Override - public void debug(Marker marker, String s, Object... objects) { - - } - - @Override - public void debug(Marker marker, String s, Throwable throwable) { - - } - - @Override - public boolean isInfoEnabled() { - return false; - } - - @Override - public void info(String s) { - infoS = s; - } - - @Override - public void info(String s, Object o) { - - } - - @Override - public void info(String s, Object o, Object o1) { - - } - - @Override - public void info(String s, Object... objects) { - - } - - @Override - public void info(String s, Throwable throwable) { - infoS = s; - infoE = throwable; - } - - @Override - public boolean isInfoEnabled(Marker marker) { - return false; - } - - @Override - public void info(Marker marker, String s) { - - } - - @Override - public void info(Marker marker, String s, Object o) { - - } - - @Override - public void info(Marker marker, String s, Object o, Object o1) { - - } - - @Override - public void info(Marker marker, String s, Object... objects) { - - } - - @Override - public void info(Marker marker, String s, Throwable throwable) { - - } - - @Override - public boolean isWarnEnabled() { - return false; - } - - @Override - public void warn(String s) { - warnS = s; - } - - @Override - public void warn(String s, Object o) { - - } - - @Override - public void warn(String s, Object... objects) { - - } - - @Override - public void warn(String s, Object o, Object o1) { - - } - - @Override - public void warn(String s, Throwable throwable) { - warnS = s; - warnE = throwable; - } - - @Override - public boolean isWarnEnabled(Marker marker) { - return false; - } - - @Override - public void warn(Marker marker, String s) { - - } - - @Override - public void warn(Marker marker, String s, Object o) { - - } - - @Override - public void warn(Marker marker, String s, Object o, Object o1) { - - } - - @Override - public void warn(Marker marker, String s, Object... objects) { - - } - - @Override - public void warn(Marker marker, String s, Throwable throwable) { - - } - - @Override - public boolean isErrorEnabled() { - return false; - } - - @Override - public void error(String s) { - errorS = s; - } - - @Override - public void error(String s, Object o) { - - } - - @Override - public void error(String s, Object o, Object o1) { - - } - - @Override - public void error(String s, Object... objects) { - - } - - @Override - public void error(String s, Throwable throwable) { - errorS = s; - errorE = throwable; - } - - @Override - public boolean isErrorEnabled(Marker marker) { - return false; - } - - @Override - public void error(Marker marker, String s) { - - } - - @Override - public void error(Marker marker, String s, Object o) { - - } - - @Override - public void error(Marker marker, String s, Object o, Object o1) { - - } - - @Override - public void error(Marker marker, String s, Object... objects) { - - } - - @Override - public void error(Marker marker, String s, Throwable throwable) { - - } - - @Override - public MetaClass getMetaClass() { - return metaClass; - } - - @Override - public void setMetaClass(MetaClass metaClass) { - this.metaClass = metaClass != null ? metaClass : InvokerHelper.getMetaClass(this.getClass()); - } - } -} diff --git a/process/src/test/java/org/orbisgis/process/GroovyProcessManagerTest.java b/process/src/test/java/org/orbisgis/process/GroovyProcessManagerTest.java deleted file mode 100644 index 9d953065..00000000 --- a/process/src/test/java/org/orbisgis/process/GroovyProcessManagerTest.java +++ /dev/null @@ -1,264 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process; - -import groovy.lang.Closure; -import groovy.lang.GroovyShell; -import groovy.lang.MetaClass; -import org.codehaus.groovy.runtime.InvokerHelper; -import org.codehaus.groovy.runtime.metaclass.MissingPropertyExceptionNoStack; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.orbisgis.process.api.IProcess; -import org.orbisgis.process.api.IProcessFactory; - -import java.util.*; - -import static org.junit.jupiter.api.Assertions.*; - -/** - * Test class dedicated to {@link ProcessFactory} class. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS Lab-STICC 2019-2020) - */ -public class GroovyProcessManagerTest { - - public static Closure cl; - - @BeforeAll - public static void beforeAll() { - String string = "({\n" + - " title \"simple process\"\n" + - " description \"description\"\n" + - " keywords \"key1\", \"key2\"\n" + - " inputs inputA: String, inputB: String\n" + - " outputs outputA: String\n" + - " version \"version\"\n" + - " run { inputA, inputB -> [outputA: inputA + inputB] }\n" + - " })"; - cl = (Closure) new GroovyShell().evaluate(string); - } - - /** - * Test the {@link GroovyProcessManager#create()} and {@link GroovyProcessManager#create(Closure)} methods. - */ - @Test - void testCreate() { - GroovyProcessManager pm = new DummyGPM(); - assertNotNull(pm.create()); - assertNotNull(pm.create().getProcess()); - - Optional opt = pm.create(cl); - assertTrue(opt.isPresent()); - IProcess process = opt.get(); - - assertNotNull(process); - assertTrue(process.getTitle().isPresent()); - assertEquals("simple process", process.getTitle().get()); - assertTrue(process.getDescription().isPresent()); - assertEquals("description", process.getDescription().get()); - assertTrue(process.getVersion().isPresent()); - assertEquals("version", process.getVersion().get()); - assertTrue(process.getKeywords().isPresent()); - assertArrayEquals(new String[]{"key1", "key2"}, process.getKeywords().get()); - assertEquals(2, process.getInputs().size()); - assertEquals(1, process.getOutputs().size()); - - opt = pm.create(null); - assertFalse(opt.isPresent()); - } - - /** - * Test the {@link GroovyProcessManager#factoryIds()}, - * {@link GroovyProcessManager#factory(String)}, {@link GroovyProcessManager#factory()}, - */ - @Test - void testFactories() { - GroovyProcessManager pm = new DummyGPM(); - - assertNotNull(pm.factory()); - assertEquals(pm.factory(), pm.factory(null)); - assertEquals(pm.factory(), pm.factory("Default")); - assertNotNull(pm.factory("Mayor_DeFacto_Ry")); - assertNotNull(pm.factory("Factorio")); - - assertTrue(pm.factoryIds().contains("Default")); - assertTrue(pm.factoryIds().contains("Mayor_DeFacto_Ry")); - assertTrue(pm.factoryIds().contains("Factorio")); - } - - /** - * Test the {@link GroovyProcessManager#process(String)} and {@link GroovyProcessManager#process(String, String)} methods. - */ - @Test - void testProcess() { - GroovyProcessManager pm = new DummyGPM(); - assertNotNull(ProcessManager.createFactory("Mayor_DeFacto_Ry")); - - Optional opt1 = pm.factory().create(cl); - assertTrue(opt1.isPresent()); - String id1 = opt1.get().getIdentifier(); - - Optional opt2 = pm.factory("Mayor_DeFacto_Ry").create(cl); - assertTrue(opt2.isPresent()); - String id2 = opt2.get().getIdentifier(); - - assertTrue(pm.process(id1).isPresent()); - assertFalse(pm.process(id2).isPresent()); - - assertFalse(pm.process(id1, "Mayor_DeFacto_Ry").isPresent()); - assertTrue(pm.process(id2, "Mayor_DeFacto_Ry").isPresent()); - - assertFalse(pm.process(null).isPresent()); - assertFalse(pm.process(null, "Mayor_DeFacto_Ry").isPresent()); - assertFalse(pm.process(id2, null).isPresent()); - assertFalse(pm.process(null, null).isPresent()); - } - - /** - * Test the {@link GroovyProcessManager#setMetaClass(MetaClass)} and {@link GroovyProcessManager#getMetaClass()} methods. - */ - @Test - void metaClassTest() { - GroovyProcessManager pm = new DummyGPM(); - assertEquals(InvokerHelper.getMetaClass(GroovyProcessManager.class), pm.getMetaClass()); - pm.setMetaClass(null); - assertNotNull(pm.getMetaClass()); - pm.setMetaClass(InvokerHelper.getMetaClass(this.getClass())); - assertEquals(InvokerHelper.getMetaClass(this.getClass()), pm.getMetaClass()); - pm.setMetaClass(InvokerHelper.getMetaClass(GroovyProcessManager.class)); - } - - /** - * Test the {@link GroovyProcessManager#invokeMethod(String, Object)} method. - */ - @Test - void invokeMethodTest() { - GroovyProcessManager pm = new DummyGPM(); - assertNotNull(pm.invokeMethod("create", cl)); - assertInstanceOf(IProcess.class, pm.invokeMethod("create", cl)); - assertNull(pm.invokeMethod("process", "null")); - assertNotNull(pm.invokeMethod("factory", null)); - assertNull(pm.invokeMethod(null, null)); - } - - /** - * Test the {@link GroovyProcessManager#register(Map)}, {@link GroovyProcessManager#registerFactory(String, IProcessFactory)} - * and {@link GroovyProcessManager#register(List)} methods. - */ - @Test - void registerTest() { - GroovyProcessManager pm = new DummyGPM(); - assertEquals(1, pm.factoryIds().size()); - - assertTrue(pm.registerFactory("toto1", new ProcessFactory())); - assertEquals(2, pm.factoryIds().size()); - assertTrue(pm.factoryIds().contains("toto1")); - - Map map = new HashMap<>(); - map.put("toto1", new ProcessFactory()); - map.put("toto2", new ProcessFactory()); - map.put("toto3", new ProcessFactory()); - pm.register(map); - assertEquals(4, pm.factoryIds().size()); - assertTrue(pm.factoryIds().contains("toto1")); - assertTrue(pm.factoryIds().contains("toto2")); - assertTrue(pm.factoryIds().contains("toto3")); - - List> list = new ArrayList<>(); - list.add(DummyGPF.class); - list.add(DummyGPF.class); - try { - pm.register(list); - } catch (IllegalAccessException | InstantiationException e) { - fail(e); - } - assertEquals(5, pm.factoryIds().size()); - assertTrue(pm.factoryIds().contains("DummyGPF")); - - try { - pm.register((List>)null); - } catch (IllegalAccessException | InstantiationException e) { - fail(e); - } - assertEquals(5, pm.factoryIds().size()); - assertTrue(pm.factoryIds().contains("DummyGPF")); - } - - /** - * Test the {@link GroovyProcessFactory#getProperty(String)} method. - */ - @Test - void propertyTest() { - GroovyProcessManager pm = new DummyGPM(); - assertNull(pm.getProperty(null)); - assertInstanceOf(ProcessManager.class, pm.getProperty("pm")); - - pm.registerFactory("toto1", new ProcessFactory()); - assertInstanceOf(ProcessFactory.class, pm.getProperty("toto1")); - - assertThrows(MissingPropertyExceptionNoStack.class, () -> pm.getProperty("not a property")); - } - - /** - * Test the {@link GroovyProcessManager#load(Class)} method. - */ - @Test - public void loadTest() { - try { - assertNotNull(GroovyProcessManager.load(DummyGPM.class)); - } catch (IllegalAccessException | InstantiationException e) { - fail(e); - } - } - - public static class DummyGPM extends GroovyProcessManager { - - @Override - public Object run() { - return null; - } - } - public static class DummyGPF extends GroovyProcessFactory { - - @Override - public Object run() { - return this; - } - } -} diff --git a/process/src/test/java/org/orbisgis/process/LinkerTest.java b/process/src/test/java/org/orbisgis/process/LinkerTest.java deleted file mode 100644 index 55001c1c..00000000 --- a/process/src/test/java/org/orbisgis/process/LinkerTest.java +++ /dev/null @@ -1,248 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process; - -import org.junit.jupiter.api.Test; -import org.orbisgis.process.api.inoutput.IInOutPut; -import org.orbisgis.process.api.inoutput.IInput; -import org.orbisgis.process.api.inoutput.IOutput; -import org.orbisgis.process.inoutput.Input; -import org.orbisgis.process.inoutput.Output; - -import java.util.LinkedHashMap; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -/** - * Test class dedicated to {@link Linker} class. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS Lab-STICC 2020) - */ -public class LinkerTest { - - /** - * Test the {@link Linker#Linker(IInOutPut...)} method. - */ - @Test - void linkerTest() { - Linker[] linker = new Linker[1]; - linker[0] = new Linker((IInOutPut[]) null); - assertTrue(linker[0].getAliases().isEmpty()); - assertTrue(linker[0].getInputOutputMap().isEmpty()); - assertTrue(linker[0].getInputs().isEmpty()); - assertTrue(linker[0].getOutputs().isEmpty()); - - linker[0] = new Linker(); - assertTrue(linker[0].getAliases().isEmpty()); - assertTrue(linker[0].getInputOutputMap().isEmpty()); - assertTrue(linker[0].getInputs().isEmpty()); - assertTrue(linker[0].getOutputs().isEmpty()); - - IInput in1 = new Input(); - IInput in2 = new Input().name("in"); - IOutput out1 = new Output(); - IOutput out2 = new Output().name("out"); - - LinkedHashMap inputs = new LinkedHashMap<>(); - inputs.put("in", in2); - LinkedHashMap outputs = new LinkedHashMap<>(); - outputs.put("out", out2); - new Process(null, null, null, inputs, outputs, null, null); - - linker[0] = new Linker(in1); - assertTrue(linker[0].getAliases().isEmpty()); - assertTrue(linker[0].getInputOutputMap().isEmpty()); - assertTrue(linker[0].getInputs().isEmpty()); - assertTrue(linker[0].getOutputs().isEmpty()); - - linker[0] = new Linker(out1); - assertTrue(linker[0].getAliases().isEmpty()); - assertTrue(linker[0].getInputOutputMap().isEmpty()); - assertTrue(linker[0].getInputs().isEmpty()); - assertTrue(linker[0].getOutputs().isEmpty()); - - linker[0] = new Linker(in2, out2); - assertTrue(linker[0].getAliases().isEmpty()); - assertTrue(linker[0].getInputOutputMap().isEmpty()); - assertTrue(linker[0].getInputs().isEmpty()); - assertTrue(linker[0].getOutputs().isEmpty()); - - linker[0] = new Linker(in2); - assertTrue(linker[0].getAliases().isEmpty()); - assertTrue(linker[0].getInputOutputMap().isEmpty()); - assertTrue(linker[0].getInputs().isEmpty()); - assertTrue(linker[0].getOutputs().isEmpty()); - - linker[0] = new Linker(out2); - assertTrue(linker[0].getAliases().isEmpty()); - assertTrue(linker[0].getInputOutputMap().isEmpty()); - assertTrue(linker[0].getInputs().isEmpty()); - assertTrue(linker[0].getOutputs().isEmpty()); - } - - /** - * Test the {@link Linker#to(String)} method. - */ - @Test - void toAliasTest() { - Linker[] linker = new Linker[1]; - - IInput in1 = new Input().name("in1"); - IInput in2 = new Input().name("in2"); - IOutput out1 = new Output().name("out1"); - IOutput out2 = new Output().name("out2"); - - LinkedHashMap inputs = new LinkedHashMap<>(); - inputs.put("in1", in1); - inputs.put("in2", in2); - LinkedHashMap outputs = new LinkedHashMap<>(); - outputs.put("out1", out1); - outputs.put("out2", out2); - new Process(null, null, null, inputs, outputs, null, null); - - linker[0] = new Linker(in1, in2); - linker[0].to("toto"); - assertEquals(1, linker[0].getAliases().size()); - assertTrue(linker[0].getAliases().containsKey("toto")); - assertTrue(linker[0].getInputOutputMap().isEmpty()); - assertEquals(1, linker[0].getInputs().size()); - assertTrue(linker[0].getOutputs().isEmpty()); - - linker[0] = new Linker(in1, in2); - linker[0].to("in1"); - assertEquals(1, linker[0].getAliases().size()); - assertTrue(linker[0].getAliases().containsKey("in1")); - assertTrue(linker[0].getInputOutputMap().isEmpty()); - assertTrue(linker[0].getInputs().isEmpty()); - assertTrue(linker[0].getOutputs().isEmpty()); - - linker[0] = new Linker(out1); - linker[0].to("toto"); - assertEquals(1, linker[0].getAliases().size()); - assertTrue(linker[0].getAliases().containsKey("toto")); - assertTrue(linker[0].getInputOutputMap().isEmpty()); - assertTrue(linker[0].getInputs().isEmpty()); - assertEquals(1, linker[0].getOutputs().size()); - - linker[0] = new Linker(out1); - linker[0].to("out1"); - assertEquals(1, linker[0].getAliases().size()); - assertTrue(linker[0].getAliases().containsKey("out1")); - assertTrue(linker[0].getInputOutputMap().isEmpty()); - assertTrue(linker[0].getInputs().isEmpty()); - assertTrue(linker[0].getOutputs().isEmpty()); - } - - /** - * Test the {@link Linker#to(IInOutPut...)} method. - */ - @Test - void toIInOutPutTest() { - Linker[] linker = new Linker[1]; - - IInput in1 = new Input().name("in1"); - IInput in2 = new Input().name("in2"); - IOutput out1 = new Output().name("out1"); - IOutput out2 = new Output().name("out2"); - - linker[0] = new Linker(in1, in2); - linker[0].to((IInOutPut[]) null); - assertTrue(linker[0].getAliases().isEmpty()); - assertTrue(linker[0].getInputOutputMap().isEmpty()); - assertTrue(linker[0].getInputs().isEmpty()); - assertTrue(linker[0].getOutputs().isEmpty()); - - linker[0] = new Linker(); - linker[0].to(); - assertTrue(linker[0].getAliases().isEmpty()); - assertTrue(linker[0].getInputOutputMap().isEmpty()); - assertTrue(linker[0].getInputs().isEmpty()); - assertTrue(linker[0].getOutputs().isEmpty()); - - LinkedHashMap inputs = new LinkedHashMap<>(); - inputs.put("in1", in1); - inputs.put("in2", in2); - LinkedHashMap outputs = new LinkedHashMap<>(); - outputs.put("out1", out1); - outputs.put("out2", out2); - new Process(null, null, null, inputs, outputs, null, null); - - linker[0] = new Linker(in1, in2); - linker[0].to(out1, out2); - assertTrue(linker[0].getAliases().isEmpty()); - assertEquals(2, linker[0].getInputOutputMap().size()); - assertTrue(linker[0].getInputs().isEmpty()); - assertTrue(linker[0].getOutputs().isEmpty()); - - linker[0] = new Linker(out1, out2); - linker[0].to(in1, in2); - assertTrue(linker[0].getAliases().isEmpty()); - assertEquals(2, linker[0].getInputOutputMap().size()); - assertTrue(linker[0].getInputs().isEmpty()); - assertTrue(linker[0].getOutputs().isEmpty()); - - linker[0] = new Linker(out1, out2); - linker[0].to(in1, out2); - assertTrue(linker[0].getAliases().isEmpty()); - assertTrue(linker[0].getInputOutputMap().isEmpty()); - assertTrue(linker[0].getInputs().isEmpty()); - assertTrue(linker[0].getOutputs().isEmpty()); - - linker[0] = new Linker(in1); - linker[0].to(in2); - assertTrue(linker[0].getAliases().isEmpty()); - assertTrue(linker[0].getInputOutputMap().isEmpty()); - assertTrue(linker[0].getInputs().isEmpty()); - assertTrue(linker[0].getOutputs().isEmpty()); - - linker[0] = new Linker(out1); - linker[0].to(out2); - assertTrue(linker[0].getAliases().isEmpty()); - assertTrue(linker[0].getInputOutputMap().isEmpty()); - assertTrue(linker[0].getInputs().isEmpty()); - assertTrue(linker[0].getOutputs().isEmpty()); - - linker[0] = new Linker(); - linker[0].to(out2); - assertTrue(linker[0].getAliases().isEmpty()); - assertTrue(linker[0].getInputOutputMap().isEmpty()); - assertTrue(linker[0].getInputs().isEmpty()); - assertTrue(linker[0].getOutputs().isEmpty()); - } -} diff --git a/process/src/test/java/org/orbisgis/process/ProcessBuilderTest.java b/process/src/test/java/org/orbisgis/process/ProcessBuilderTest.java deleted file mode 100644 index 6693bfad..00000000 --- a/process/src/test/java/org/orbisgis/process/ProcessBuilderTest.java +++ /dev/null @@ -1,258 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process; - -import groovy.lang.Closure; -import groovy.lang.GroovyCodeSource; -import groovy.lang.GroovyShell; -import org.junit.jupiter.api.Test; -import org.orbisgis.process.api.IProcess; -import org.orbisgis.process.api.IProcessFactory; - -import java.util.LinkedHashMap; - -import static org.junit.jupiter.api.Assertions.*; - -/** - * Test class dedicated to {@link ProcessBuilder} class. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS Lab-STICC 2019-2020) - */ -public class ProcessBuilderTest { - - private static final Object delegate = ""; - private static final IProcessFactory factory = new ProcessFactory(); - - /** - * Test the {@link ProcessBuilder#ProcessBuilder(IProcessFactory, Object)} method. - */ - @Test - void constructorTest() { - assertDoesNotThrow(() -> new ProcessBuilder(factory, delegate)); - assertThrows(IllegalArgumentException.class, () -> new ProcessBuilder(null, delegate)); - assertThrows(IllegalArgumentException.class, () -> new ProcessBuilder(null, null)); - assertThrows(IllegalArgumentException.class, () -> new ProcessBuilder(factory, null)); - } - - /** - * Test the {@link ProcessBuilder#title(String)} method. - */ - @Test - void titleTest() { - ProcessBuilder processBuilder = new ProcessBuilder(factory, delegate); - assertEquals(processBuilder, processBuilder.title("title")); - - processBuilder = new ProcessBuilder(factory, delegate); - assertEquals(processBuilder, processBuilder.title(null)); - } - - /** - * Test the {@link ProcessBuilder#id(String)} method. - */ - @Test - void idTest() { - ProcessBuilder processBuilder = new ProcessBuilder(factory, delegate); - assertEquals(processBuilder, processBuilder.id("id")); - - processBuilder = new ProcessBuilder(factory, delegate); - assertEquals(processBuilder, processBuilder.title(null)); - } - - /** - * Test the {@link ProcessBuilder#description(String)} method. - */ - @Test - void descriptionTest() { - ProcessBuilder processBuilder = new ProcessBuilder(factory, delegate); - assertEquals(processBuilder, processBuilder.description("description")); - - processBuilder = new ProcessBuilder(factory, delegate); - assertEquals(processBuilder, processBuilder.description(null)); - } - - /** - * Test the {@link ProcessBuilder#keywords(String[])} method. - */ - @Test - void keywordsTest() { - ProcessBuilder processBuilder = new ProcessBuilder(factory, delegate); - assertEquals(processBuilder, processBuilder.keywords(new String[]{"key1", "key2"})); - - processBuilder = new ProcessBuilder(factory, delegate); - assertEquals(processBuilder, processBuilder.keywords(null)); - } - - /** - * Test the {@link ProcessBuilder#inputs(LinkedHashMap)} method. - */ - @Test - void inputsTest() { - LinkedHashMap inputs = new LinkedHashMap<>(); - inputs.put("in1", String.class); - inputs.put("in2", String.class); - inputs.put("in3", String.class); - - ProcessBuilder processBuilder = new ProcessBuilder(factory, delegate); - assertEquals(processBuilder, processBuilder.inputs(inputs)); - - processBuilder = new ProcessBuilder(factory, delegate); - assertEquals(processBuilder, processBuilder.inputs(null)); - } - - /** - * Test the {@link ProcessBuilder#outputs(LinkedHashMap)} method. - */ - @Test - void outputsTest() { - LinkedHashMap outputs = new LinkedHashMap<>(); - outputs.put("out1", String.class); - outputs.put("out2", String.class); - - ProcessBuilder processBuilder = new ProcessBuilder(factory, delegate); - assertEquals(processBuilder, processBuilder.outputs(outputs)); - - processBuilder = new ProcessBuilder(factory, delegate); - assertEquals(processBuilder, processBuilder.outputs(null)); - } - - /** - * Test the {@link ProcessBuilder#version(String)} method. - */ - @Test - void versionTest() { - ProcessBuilder processBuilder = new ProcessBuilder(factory, delegate); - assertEquals(processBuilder, processBuilder.version("version")); - processBuilder = new ProcessBuilder(factory, delegate); - assertEquals(processBuilder, processBuilder.version(null)); - } - - /** - * Test the {@link ProcessBuilder#run(Closure)} method. - */ - @Test - void runTest() { - ProcessBuilder processBuilder = new ProcessBuilder(factory, delegate); - assertEquals(processBuilder, processBuilder.run(null)); - - String str = "{in1, in2, in3 -> return [out1:in1+in2+in3]}"; - Closure cl = (Closure) new GroovyShell().evaluate(new GroovyCodeSource(str, "script", "")); - processBuilder = new ProcessBuilder(factory, delegate); - assertEquals(processBuilder, processBuilder.run(cl)); - } - - /** - * Teste the whole building chain. - */ - @Test - void testProcessBuilder() { - LinkedHashMap inputs = new LinkedHashMap<>(); - inputs.put("in1", String.class); - inputs.put("in2", String.class); - inputs.put("in3", String.class); - - LinkedHashMap outputs = new LinkedHashMap<>(); - outputs.put("out1", String.class); - outputs.put("out2", String.class); - - String str = "{in1, in2, in3 -> return [out1:in1+in2+in3]}"; - Closure cl = (Closure) new GroovyShell().evaluate(new GroovyCodeSource(str, "script", "")); - - IProcess process = new ProcessBuilder(factory, delegate) - .title("title") - .id("id") - .description("description") - .keywords(new String[]{"key1", "key2"}) - .inputs(inputs) - .outputs(outputs) - .run(cl) - .version("version") - .getProcess(); - - assertTrue(process.getTitle().isPresent()); - assertEquals("title", process.getTitle().get()); - assertEquals("id", process.getIdentifier()); - assertTrue(process.getDescription().isPresent()); - assertEquals("description", process.getDescription().get()); - assertTrue(process.getVersion().isPresent()); - assertEquals("version", process.getVersion().get()); - assertTrue(process.getKeywords().isPresent()); - assertArrayEquals(new String[]{"key1", "key2"}, process.getKeywords().get()); - assertEquals(3, process.getInputs().size()); - assertEquals(2, process.getOutputs().size()); - - process = new ProcessBuilder(factory, delegate) - .title("title") - .description("description") - .keywords(new String[]{"key1", "key2"}) - .inputs(inputs) - .outputs(outputs) - .run(cl) - .version("version") - .getProcess(); - - assertTrue(process.getTitle().isPresent()); - assertEquals("title", process.getTitle().get()); - assertNotNull(process.getIdentifier()); - assertTrue(process.getDescription().isPresent()); - assertEquals("description", process.getDescription().get()); - assertTrue(process.getVersion().isPresent()); - assertEquals("version", process.getVersion().get()); - assertTrue(process.getKeywords().isPresent()); - assertArrayEquals(new String[]{"key1", "key2"}, process.getKeywords().get()); - assertEquals(3, process.getInputs().size()); - assertEquals(2, process.getOutputs().size()); - - process = new ProcessBuilder(factory, delegate) - .title(null) - .id(null) - .description(null) - .keywords(null) - .inputs(null) - .outputs(null) - .run(null) - .version(null) - .getProcess(); - - assertFalse(process.getTitle().isPresent()); - assertFalse(process.getDescription().isPresent()); - assertFalse(process.getVersion().isPresent()); - assertFalse(process.getKeywords().isPresent()); - assertTrue(process.getInputs().isEmpty()); - assertTrue(process.getOutputs().isEmpty()); - } -} diff --git a/process/src/test/java/org/orbisgis/process/ProcessFactoryTest.java b/process/src/test/java/org/orbisgis/process/ProcessFactoryTest.java deleted file mode 100644 index c30c8fc1..00000000 --- a/process/src/test/java/org/orbisgis/process/ProcessFactoryTest.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process; - -import groovy.lang.Closure; -import groovy.lang.GroovyShell; -import groovy.lang.MetaClass; -import org.codehaus.groovy.runtime.InvokerHelper; -import org.junit.jupiter.api.Test; -import org.orbisgis.process.api.IProcess; - -import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.*; - -/** - * Test class dedicated to {@link ProcessFactory} class. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS Lab-STICC 2019- 2020) - */ -public class ProcessFactoryTest { - - /** - * Test the {@link ProcessFactory#ProcessFactory(boolean, boolean)}, {@link ProcessFactory#ProcessFactory()}, - * {@link ProcessFactory#isDefault()} and {@link ProcessFactory#isLocked()} methods. - */ - @Test - void testAttributes() { - ProcessFactory pf = new ProcessFactory(); - assertFalse(pf.isDefault()); - assertFalse(pf.isLocked()); - - pf = new ProcessFactory(true, true); - assertTrue(pf.isDefault()); - assertTrue(pf.isLocked()); - - pf = new ProcessFactory(false, true); - assertTrue(pf.isDefault()); - assertFalse(pf.isLocked()); - - pf = new ProcessFactory(true, false); - assertFalse(pf.isDefault()); - assertTrue(pf.isLocked()); - } - - /** - * Test the {@link ProcessFactory#registerProcess(IProcess)} and {@link ProcessFactory#getProcess(String)} methods. - */ - @Test - void testRegister() { - IProcess process = new Process(null, null, null, null, null, null, null); - IProcess newInst = process.newInstance(); - IProcess copy = process.copy(); - - ProcessFactory pf = new ProcessFactory(false, false); - pf.registerProcess(process); - assertTrue(pf.getProcess(process.getIdentifier()).isPresent()); - - pf.registerProcess(newInst); - assertTrue(pf.getProcess(newInst.getIdentifier()).isPresent()); - assertTrue(pf.getProcess(process.getIdentifier()).isPresent()); - - pf.registerProcess(copy); - assertTrue(pf.getProcess(newInst.getIdentifier()).isPresent()); - assertTrue(pf.getProcess(copy.getIdentifier()).isPresent()); - assertTrue(pf.getProcess(process.getIdentifier()).isPresent()); - - pf = new ProcessFactory(false, false); - pf.registerProcess(null); - assertFalse(pf.getProcess(process.getIdentifier()).isPresent()); - - pf = new ProcessFactory(true, true); - pf.registerProcess(process); - assertFalse(pf.getProcess(process.getIdentifier()).isPresent()); - pf = new ProcessFactory(true, true); - pf.registerProcess(null); - assertFalse(pf.getProcess(process.getIdentifier()).isPresent()); - } - - /** - * Test the {@link ProcessFactory#create()} and {@link ProcessFactory#create(Closure)} methods. - */ - @Test - void testCreate() { - ProcessFactory pf1 = new ProcessFactory(); - assertNotNull(pf1.create()); - - assertFalse(pf1.create(null).isPresent()); - - String string = "({\n" + - " title \"simple process\"\n" + - " description \"description\"\n" + - " keywords \"key1\", \"key2\"\n" + - " inputs inputA: String, inputB: String\n" + - " outputs outputA: String\n" + - " version \"version\"\n" + - " run { inputA, inputB -> [outputA: inputA + inputB] }\n" + - " })"; - Closure cl = (Closure) new GroovyShell().evaluate(string); - Optional opt = pf1.create(cl); - assertTrue(opt.isPresent()); - - IProcess process = opt.get(); - assertNotNull(process); - assertTrue(process.getTitle().isPresent()); - assertEquals("simple process", process.getTitle().get()); - assertTrue(process.getDescription().isPresent()); - assertEquals("description", process.getDescription().get()); - assertTrue(process.getVersion().isPresent()); - assertEquals("version", process.getVersion().get()); - assertTrue(process.getKeywords().isPresent()); - assertArrayEquals(new String[]{"key1", "key2"}, process.getKeywords().get()); - assertEquals(2, process.getInputs().size()); - assertEquals(1, process.getOutputs().size()); - } - - /** - * Test the {@link ProcessFactory#setMetaClass(MetaClass)} and {@link ProcessFactory#getMetaClass()} methods. - */ - @Test - void metaClassTest(){ - ProcessFactory factory = new ProcessFactory(); - assertEquals(InvokerHelper.getMetaClass(ProcessFactory.class), factory.getMetaClass()); - factory.setMetaClass(null); - assertEquals(InvokerHelper.getMetaClass(factory.getClass()).getClass(), - factory.getMetaClass().getClass()); - factory.setMetaClass(InvokerHelper.getMetaClass(this.getClass())); - assertEquals(InvokerHelper.getMetaClass(this.getClass()), factory.getMetaClass()); - } - - /** - * Test the {@link ProcessFactory#invokeMethod(String, Object)} method. - */ - @Test - void invokeMethodTest() { - ProcessFactory factory = new ProcessFactory(false, true); - assertNull(factory.invokeMethod(null, null)); - assertEquals(false, factory.invokeMethod("isLocked", null)); - assertNull(factory.invokeMethod("getProcess", null)); - factory.setMetaClass(null); - assertNull(factory.invokeMethod(null, null)); - assertEquals(false, factory.invokeMethod("isLocked", null)); - assertNull(factory.invokeMethod("getProcess", null)); - } - - /** - * Test the {@link ProcessFactory#getProcessManager()} and {@link ProcessFactory#setProcessManager(org.orbisgis.process.api.IProcessManager)} method. - */ - @Test - void getProcessManagerTest() { - ProcessFactory factory = new ProcessFactory(false, true); - assertFalse(factory.getProcessManager().isPresent()); - ProcessManager pm = new ProcessManager(); - factory.setProcessManager(pm); - assertTrue(factory.getProcessManager().isPresent()); - assertEquals(pm, factory.getProcessManager().get()); - factory.setProcessManager(null); - assertFalse(factory.getProcessManager().isPresent()); - } -} diff --git a/process/src/test/java/org/orbisgis/process/ProcessManagerTest.java b/process/src/test/java/org/orbisgis/process/ProcessManagerTest.java deleted file mode 100644 index bc7eb1c7..00000000 --- a/process/src/test/java/org/orbisgis/process/ProcessManagerTest.java +++ /dev/null @@ -1,224 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process; - -import groovy.lang.Closure; -import groovy.lang.GroovyShell; -import groovy.lang.MetaClass; -import org.codehaus.groovy.runtime.InvokerHelper; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.orbisgis.process.api.IProcess; -import org.orbisgis.process.api.IProcessFactory; - -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.*; - -/** - * Test class dedicated to {@link ProcessFactory} class. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS Lab-STICC 2019-2020) - */ -public class ProcessManagerTest { - - public static Closure cl; - - @BeforeAll - public static void beforeAll() { - String string = "({\n" + - " title \"simple process\"\n" + - " description \"description\"\n" + - " keywords \"key1\", \"key2\"\n" + - " inputs inputA: String, inputB: String\n" + - " outputs outputA: String\n" + - " version \"version\"\n" + - " run { inputA, inputB -> [outputA: inputA + inputB] }\n" + - " })"; - cl = (Closure) new GroovyShell().evaluate(string); - } - - /** - * Test the {@link ProcessManager#getProcessManager()} method - */ - @Test - void getProcessManagerTest() { - assertNotNull(ProcessManager.getProcessManager()); - } - - /** - * Test the {@link ProcessManager#create()} and {@link ProcessManager#create(Closure)} methods. - */ - @Test - void testCreate() { - ProcessManager pm = ProcessManager.getProcessManager(); - assertNotNull(pm.create()); - assertNotNull(pm.create().getProcess()); - - Optional opt = pm.create(cl); - assertTrue(opt.isPresent()); - IProcess process = opt.get(); - - assertNotNull(process); - assertTrue(process.getTitle().isPresent()); - assertEquals("simple process", process.getTitle().get()); - assertTrue(process.getDescription().isPresent()); - assertEquals("description", process.getDescription().get()); - assertTrue(process.getVersion().isPresent()); - assertEquals("version", process.getVersion().get()); - assertTrue(process.getKeywords().isPresent()); - assertArrayEquals(new String[]{"key1", "key2"}, process.getKeywords().get()); - assertEquals(2, process.getInputs().size()); - assertEquals(1, process.getOutputs().size()); - - opt = pm.create(null); - assertFalse(opt.isPresent()); - } - - /** - * Test the {@link ProcessManager#factoryIds()}, - * {@link ProcessManager#factory(String)}, {@link ProcessManager#factory()}, - * {@link ProcessManager#createFactory(String)}, {@link ProcessManager#createFactory()} methods. - */ - @Test - void testFactories() { - ProcessManager pm = ProcessManager.getProcessManager(); - assertNotNull(ProcessManager.createFactory()); - assertNotNull(ProcessManager.createFactory("Mayor_DeFacto_Ry")); - assertNotNull(ProcessManager.createFactory(null)); - assertNotNull(ProcessManager.createFactory("")); - - assertNotNull(pm.factory()); - assertEquals(pm.factory(), pm.factory(null)); - assertEquals(pm.factory(), pm.factory("Default")); - assertNotNull(pm.factory("Mayor_DeFacto_Ry")); - assertNotNull(pm.factory("Factorio")); - - assertTrue(pm.factoryIds().contains("Default")); - assertTrue(pm.factoryIds().contains("Mayor_DeFacto_Ry")); - assertTrue(pm.factoryIds().contains("Factorio")); - } - - /** - * Test the {@link ProcessManager#process(String)} and {@link ProcessManager#process(String, String)} methods. - */ - @Test - void testProcess() { - ProcessManager pm = ProcessManager.getProcessManager(); - assertNotNull(ProcessManager.createFactory("Mayor_DeFacto_Ry")); - - Optional opt1 = pm.factory().create(cl); - assertTrue(opt1.isPresent()); - String id1 = opt1.get().getIdentifier(); - - Optional opt2 = pm.factory("Mayor_DeFacto_Ry").create(cl); - assertTrue(opt2.isPresent()); - String id2 = opt2.get().getIdentifier(); - - assertTrue(pm.process(id1).isPresent()); - assertFalse(pm.process(id2).isPresent()); - - assertFalse(pm.process(id1, "Mayor_DeFacto_Ry").isPresent()); - assertTrue(pm.process(id2, "Mayor_DeFacto_Ry").isPresent()); - - assertFalse(pm.process(null).isPresent()); - assertFalse(pm.process(null, "Mayor_DeFacto_Ry").isPresent()); - assertFalse(pm.process(id2, null).isPresent()); - assertFalse(pm.process(null, null).isPresent()); - } - - /** - * Test the {@link ProcessManager#setMetaClass(MetaClass)} and {@link ProcessManager#getMetaClass()} methods. - */ - @Test - void metaClassTest() { - ProcessManager pm = ProcessManager.getProcessManager(); - assertEquals(InvokerHelper.getMetaClass(ProcessManager.class), pm.getMetaClass()); - pm.setMetaClass(null); - assertNotNull(pm.getMetaClass()); - pm.setMetaClass(InvokerHelper.getMetaClass(this.getClass())); - assertEquals(InvokerHelper.getMetaClass(this.getClass()), pm.getMetaClass()); - pm.setMetaClass(InvokerHelper.getMetaClass(ProcessManager.class)); - } - - /** - * Test the {@link ProcessManager#invokeMethod(String, Object)} method. - */ - @Test - void invokeMethodTest() { - ProcessManager pm = ProcessManager.getProcessManager(); - assertNotNull(pm.invokeMethod("create", cl)); - assertInstanceOf(IProcess.class, pm.invokeMethod("create", cl)); - assertNull(pm.invokeMethod("process", "null")); - assertNotNull(pm.invokeMethod("factory", null)); - assertNull(pm.invokeMethod(null, null)); - } - - /** - * Test the {@link ProcessManager#register(Map)}, { - * @link GroovyProcessManager#registerFactory(String, IProcessFactory) methods. - */ - @Test - void registerTest() { - ProcessManager pm = new ProcessManager(); - assertEquals(1, pm.factoryIds().size()); - - assertTrue(pm.registerFactory("toto1", new ProcessFactory())); - assertEquals(2, pm.factoryIds().size()); - assertTrue(pm.factoryIds().contains("toto1")); - - Map map = new HashMap<>(); - map.put("toto1", new ProcessFactory()); - map.put("toto2", new ProcessFactory()); - map.put("toto3", new ProcessFactory()); - pm.register(map); - assertEquals(4, pm.factoryIds().size()); - assertTrue(pm.factoryIds().contains("toto1")); - assertTrue(pm.factoryIds().contains("toto2")); - assertTrue(pm.factoryIds().contains("toto3")); - - assertFalse(pm.registerFactory(null, new ProcessFactory())); - assertFalse(pm.registerFactory("toto1", new ProcessFactory())); - assertFalse(pm.registerFactory("", new ProcessFactory())); - assertFalse(pm.registerFactory("id", null)); - - assertDoesNotThrow(() -> pm.register(null)); - } -} diff --git a/process/src/test/java/org/orbisgis/process/ProcessMapperTest.java b/process/src/test/java/org/orbisgis/process/ProcessMapperTest.java deleted file mode 100644 index 466933ba..00000000 --- a/process/src/test/java/org/orbisgis/process/ProcessMapperTest.java +++ /dev/null @@ -1,464 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process; - -import groovy.lang.Closure; -import groovy.lang.GroovyShell; -import org.codehaus.groovy.runtime.InvokerHelper; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.orbisgis.process.api.IProcess; -import org.orbisgis.process.api.IProcessManager; -import org.orbisgis.process.api.IProcessMapper; -import org.orbisgis.process.api.inoutput.IInOutPut; -import org.orbisgis.process.inoutput.InOutPut; - -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.*; - -/** - * Test class dedicated to {@link ProcessMapper} class. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS 2019) - */ -public class ProcessMapperTest { - - private static final IProcessManager processManager = ProcessManager.getProcessManager(); - - private static Process pA1; - private static Process pA2; - private static Process pB1; - private static Process pB2; - private static Process pC; - - @BeforeAll - public static void init() { - LinkedHashMap pAInputMap = new LinkedHashMap<>(); - pAInputMap.put("inA1", String.class); - pAInputMap.put("inA2", String.class); - LinkedHashMap pAOutputMap = new LinkedHashMap<>(); - pAOutputMap.put("outA1", String.class); - pA1 = (Process) processManager.factory("map5").create().title("pA").inputs(pAInputMap).outputs(pAOutputMap) - .run(new Closure(null) { - public int getMaximumNumberOfParameters() { - return 2; - } - - @Override - public Object call(Object... arguments) { - Map map = new HashMap<>(); - map.put("outA1", arguments[0].toString() + arguments[1].toString()); - return map; - } - }).getProcess(); - - pA2 = (Process) pA1.newInstance(); - - - LinkedHashMap pBInputMap = new LinkedHashMap<>(); - pBInputMap.put("inB1", String.class); - pBInputMap.put("inB2", String.class); - LinkedHashMap pBOutputMap = new LinkedHashMap<>(); - pBOutputMap.put("outB1", String.class); - pB1 = (Process) processManager.factory("map5").create().title("pB").inputs(pBInputMap).outputs(pBOutputMap) - .run(new Closure(null) { - public int getMaximumNumberOfParameters() { - return 2; - } - - @Override - public Object call(Object... arguments) { - Map map = new HashMap<>(); - map.put("outB1", arguments[1].toString() + " or " + arguments[0].toString()); - return map; - } - }).getProcess(); - - pB2 = (Process) pB1.newInstance(); - - - LinkedHashMap pCInputMap = new LinkedHashMap<>(); - pCInputMap.put("inC1", "D"); - pCInputMap.put("inC2", String.class); - LinkedHashMap pCOutputMap = new LinkedHashMap<>(); - pCOutputMap.put("outC1", String.class); - pCOutputMap.put("outC2", String.class); - - pC = (Process) processManager.factory("map2").create().title("pC").inputs(pCInputMap).outputs(pCOutputMap) - .run(new Closure(null) { - public int getMaximumNumberOfParameters() { - return 2; - } - - @Override - public Object call(Object... arguments) { - Map map = new HashMap<>(); - map.put("outC1", arguments[0].toString() + arguments[1].toString()); - map.put("outC2", arguments[1].toString() + arguments[0].toString()); - return map; - } - }).getProcess(); - } - - /** - * {@code - * --> ---- - * | pB | -----> ---- --> - * |--> ---- | pC | - * | |--> ---- --> - * |------------| - * | - * --> ---- | - * | pA | ---| - * ---- - * } - */ - @Test - public void mapping1Test() { - LinkedHashMap pAInputMap = new LinkedHashMap<>(); - pAInputMap.put("inA1", String.class); - LinkedHashMap pAOutputMap = new LinkedHashMap<>(); - pAOutputMap.put("outA1", String.class); - Process pA = (Process) processManager.factory("map2").create().title("pA").inputs(pAInputMap) - .outputs(pAOutputMap).run(new Closure(this) { - public int getMaximumNumberOfParameters() { - return 1; - } - - @Override - public Object call(Object... arguments) { - Map map = new HashMap<>(); - map.put("outA1", arguments[0].toString().toUpperCase()); - return map; - } - }).getProcess(); - - IProcessMapper mapper = new ProcessMapper(); - mapper.link((IInOutPut) pA.getProperty("outA1")).to((IInOutPut) pB1.getProperty("inB1")); - mapper.link((IInOutPut) pB1.getProperty("outB1")).to((IInOutPut) pC.getProperty("inC2")); - mapper.link((IInOutPut) pA.getProperty("outA1")).to((IInOutPut) pC.getProperty("inC1")); - - Closure cl = (Closure) new GroovyShell().evaluate("({1+1 == 2})"); - - mapper.after(pA).with().check(cl); - mapper.before(pA).with().check(cl); - - LinkedHashMap dataMap = new LinkedHashMap<>(); - dataMap.put("inA1", "a"); - dataMap.put("inB2", "b"); - assertTrue(mapper.execute(dataMap)); - assertEquals(2, mapper.getResults().size()); - assertEquals("Ab or A", mapper.getResults().get("outC1")); - assertEquals("b or AA", mapper.getResults().get("outC2")); - } - - - /** - * {@code - * --> ----- |-----> ---- - * | pA |-| | pB |---> - * --> ----- |-\ /-> ---- - * X - * --> ----- |-/ \-> ---- - * | pA |-| | pB |---> - * --> ----- |-----> ---- - * } - */ - @Test - public void mapping2Test() { - - IProcessMapper mapper = new ProcessMapper(); - - mapper.link((IInOutPut) pA2.getProperty("outA1")).to((IInOutPut) pB1.getProperty("inB1")); - mapper.link((IInOutPut) pB2.getProperty("inB2")).to((IInOutPut) pA2.getProperty("outA1")); - mapper.link((IInOutPut) pA1.getProperty("outA1")).to((IInOutPut) pB2.getProperty("inB1"), (IInOutPut) pB1.getProperty("inB2")); - - mapper.link((IInOutPut) pA1.getProperty("outA1")).to("interPA1OutA1"); - mapper.link((IInOutPut) pA2.getProperty("outA1")).to("interPA2OutA1"); - - mapper.link((IInOutPut) pA1.getProperty("inA1"), (IInOutPut) pA2.getProperty("inA1")).to("commonInput"); - mapper.link((IInOutPut) pA1.getProperty("inA2")).to("inputD"); - mapper.link((IInOutPut) pA2.getProperty("inA2")).to("inputK"); - - mapper.link((IInOutPut) pB1.getProperty("outB1")).to("outD"); - mapper.link((IInOutPut) pB2.getProperty("outB1")).to("outK"); - - LinkedHashMap dataMap = new LinkedHashMap<>(); - dataMap.put("inputD", "D"); - dataMap.put("inputK", "K"); - dataMap.put("commonInput", "common"); - assertTrue(mapper.call(dataMap)); - - assertEquals(3, mapper.getInputs().size()); - assertTrue(mapper.getInputs().stream().map(IInOutPut::getName).filter(Optional::isPresent).map(Optional::get).anyMatch(input -> input.equals("inputD"))); - assertTrue(mapper.getInputs().stream().map(IInOutPut::getName).filter(Optional::isPresent).map(Optional::get).anyMatch(input -> input.equals("inputK"))); - assertTrue(mapper.getInputs().stream().map(IInOutPut::getName).filter(Optional::isPresent).map(Optional::get).anyMatch(input -> input.equals("commonInput"))); - - assertEquals(4, mapper.getOutputs().size()); - assertTrue(mapper.getOutputs().stream().map(IInOutPut::getName).filter(Optional::isPresent).map(Optional::get).anyMatch(output -> output.equals("interPA2OutA1"))); - assertTrue(mapper.getOutputs().stream().map(IInOutPut::getName).filter(Optional::isPresent).map(Optional::get).anyMatch(output -> output.equals("interPA1OutA1"))); - assertTrue(mapper.getOutputs().stream().map(IInOutPut::getName).filter(Optional::isPresent).map(Optional::get).anyMatch(output -> output.equals("outD"))); - assertTrue(mapper.getOutputs().stream().map(IInOutPut::getName).filter(Optional::isPresent).map(Optional::get).anyMatch(output -> output.equals("outK"))); - - assertFalse(mapper.getResults().containsKey("outB1")); - assertEquals("commonD or commonK", mapper.getResults().get("outD")); - assertEquals("commonK or commonD", mapper.getResults().get("outK")); - assertEquals("commonK", mapper.getResults().get("interPA2OutA1")); - assertEquals("commonD", mapper.getResults().get("interPA1OutA1")); - } - - - /** - * {@code - * --> ----- - * | pA |--> - * --> ----- - *

- * --> ----- - * | pA |--> - * --> ----- - * } - */ - @Test - public void mapping4Test() { - - IProcessMapper mapper = new ProcessMapper(); - - mapper.link((IInOutPut) pA1.getProperty("inA1"), (IInOutPut) pA2.getProperty("inA1")).to("commonInput"); - mapper.link((IInOutPut) pA1.getProperty("inA2")).to("inputD"); - mapper.link((IInOutPut) pA2.getProperty("inA2")).to("inputK"); - - LinkedHashMap dataMap = new LinkedHashMap<>(); - dataMap.put("inputD", "D"); - dataMap.put("inputK", "K"); - dataMap.put("commonInput", "common"); - assertTrue(mapper.call(dataMap)); - } - - - /** - * - */ - @Test - public void mapping3Test() { - IProcessMapper mapper = new ProcessMapper(); - - mapper.link((IInOutPut) pC.getProperty("outC1")).to("out"); - - LinkedHashMap dataMap = new LinkedHashMap<>(); - dataMap.put("inC1", null); - dataMap.put("inC2", "K"); - assertTrue(mapper.call(dataMap)); - - assertEquals(2, mapper.getInputs().size()); - assertTrue(mapper.getInputs().stream().map(IInOutPut::getName).filter(Optional::isPresent).map(Optional::get).anyMatch(input -> input.equals("inC1"))); - assertTrue(mapper.getInputs().stream().map(IInOutPut::getName).filter(Optional::isPresent).map(Optional::get).anyMatch(input -> input.equals("inC2"))); - - assertEquals(2, mapper.getOutputs().size()); - assertTrue(mapper.getOutputs().stream().map(IInOutPut::getName).filter(Optional::isPresent).map(Optional::get).anyMatch(output -> output.equals("out"))); - assertTrue(mapper.getOutputs().stream().map(IInOutPut::getName).filter(Optional::isPresent).map(Optional::get).anyMatch(output -> output.equals("outC2"))); - - assertEquals(2, mapper.getResults().size()); - assertFalse(mapper.getResults().containsKey("outC1")); - assertEquals("DK", mapper.getResults().get("out")); - assertEquals("KD", mapper.getResults().get("outC2")); - } - - /** - * Test a mapper which processes can't be linked. - */ - @Test - public void noLinkeableTest() { - - IProcessMapper mapper = new ProcessMapper(); - - mapper.link((IInOutPut) pC.getProperty("outC1")).to((IInOutPut) pC.getProperty("inC1")); - - LinkedHashMap dataMap = new LinkedHashMap<>(); - dataMap.put("inC1", "D"); - dataMap.put("inC2", "K"); - assertFalse(mapper.call(dataMap)); - } - - /** - * Test the methods {@link ProcessMapper#link(IInOutPut...)}, - * {@link org.orbisgis.process.api.ILinker#to(String)} and - * {@link org.orbisgis.process.api.ILinker#to(IInOutPut...)} methods in case of bad linking. - */ - @Test - public void badMappingTest() { - IProcessMapper mapper = new ProcessMapper(); - mapper.link((IInOutPut) pA1.getProperty("outA1")).to((IInOutPut) pB2.getProperty("outB1")); - assertTrue(mapper.getInputs().isEmpty()); - assertTrue(mapper.getOutputs().isEmpty()); - - mapper = new ProcessMapper(); - mapper.link((IInOutPut) pA1.getProperty("inA1")).to((IInOutPut) pB2.getProperty("inB1")); - assertTrue(mapper.getInputs().isEmpty()); - assertTrue(mapper.getOutputs().isEmpty()); - - mapper = new ProcessMapper(); - mapper.link((IInOutPut) pA1.getProperty("outA1"), (IInOutPut) pB2.getProperty("inB1")); - assertTrue(mapper.getInputs().isEmpty()); - assertTrue(mapper.getOutputs().isEmpty()); - - mapper = new ProcessMapper(); - mapper.link((IInOutPut) pA1.getProperty("inA1")).to((IInOutPut) pA1.getProperty("outA1"), (IInOutPut) pB2.getProperty("inB1")); - assertTrue(mapper.getInputs().isEmpty()); - assertTrue(mapper.getOutputs().isEmpty()); - - mapper = new ProcessMapper(); - mapper.link((IInOutPut) pA1.getProperty("inA1")).to(); - assertTrue(mapper.getInputs().isEmpty()); - assertTrue(mapper.getOutputs().isEmpty()); - - mapper = new ProcessMapper(); - mapper.link().to(); - assertTrue(mapper.getInputs().isEmpty()); - assertTrue(mapper.getOutputs().isEmpty()); - } - - /** - * Test the methods {@link ProcessMapper#getTitle()}, {@link ProcessMapper#getDescription()}, - * {@link ProcessMapper#getKeywords()}, {@link ProcessMapper#getVersion()} methods. - */ - @Test - public void getAttributesTest() { - IProcessMapper mapper = new ProcessMapper(); - assertTrue(mapper.getTitle().isPresent()); - assertFalse(mapper.getDescription().isPresent()); - assertFalse(mapper.getKeywords().isPresent()); - assertFalse(mapper.getVersion().isPresent()); - - mapper = new ProcessMapper("title"); - assertEquals("title", mapper.getTitle().get()); - assertFalse(mapper.getDescription().isPresent()); - assertFalse(mapper.getKeywords().isPresent()); - assertFalse(mapper.getVersion().isPresent()); - } - - /** - * Test the methods {@link ProcessMapper#after(IProcess)}, {@link ProcessMapper#before(IProcess)} methods. - */ - @Test - public void getCheckerTest() { - IProcessMapper mapper = new ProcessMapper(); - assertNotNull(mapper.after(null)); - assertNotNull(mapper.before(null)); - } - - /** - * Test the methods {@link ProcessMapper#newInstance()} method. - */ - @Test - void newInstanceTest() { - IProcessMapper mapper = new ProcessMapper(); - mapper.link((InOutPut) pA1.getProperty("inA1")).to("in"); - mapper.link((InOutPut) pA1.getProperty("outA1")).to("out"); - mapper.execute(null); - IProcessMapper mapper2 = mapper.newInstance(); - assertNotEquals(mapper.getTitle(), mapper2.getTitle()); - assertEquals(mapper.getDescription(), mapper2.getDescription()); - assertEquals(mapper.getKeywords(), mapper2.getKeywords()); - assertEquals(mapper.getInputs(), mapper2.getInputs()); - assertEquals(mapper.getOutputs(), mapper2.getOutputs()); - assertEquals(mapper.getVersion(), mapper2.getVersion()); - assertNotEquals(mapper.getIdentifier(), mapper2.getIdentifier()); - } - - /** - * Test the methods {@link ProcessMapper#copy()} method. - */ - @Test - void copyTest() { - IProcessMapper mapper = new ProcessMapper(); - mapper.link((InOutPut) pA1.getProperty("inA1")).to("in"); - mapper.link((InOutPut) pA1.getProperty("outA1")).to("out"); - mapper.execute(null); - IProcessMapper mapper2 = mapper.copy(); - assertNotEquals(mapper.getTitle(), mapper2.getTitle()); - assertEquals(mapper.getDescription(), mapper2.getDescription()); - assertEquals(mapper.getKeywords(), mapper2.getKeywords()); - assertEquals(mapper.getInputs(), mapper2.getInputs()); - assertEquals(mapper.getOutputs(), mapper2.getOutputs()); - assertEquals(mapper.getVersion(), mapper2.getVersion()); - assertNotEquals(mapper.getIdentifier(), mapper2.getIdentifier()); - } - - /** - * Test the {@link Process#invokeMethod(String, Object)} method. - */ - @Test - void invokeMethodTest() { - ProcessMapper mapper = new ProcessMapper("title"); - assertEquals("title", mapper.invokeMethod("getTitle", null)); - - assertNull(mapper.invokeMethod(null, null)); - assertNotNull(mapper.invokeMethod("getIdentifier", null)); - } - - /** - * Test the {@link Process#getProperty(String)} method. - */ - @Test - void getPropertyTest() { - ProcessMapper mapper = new ProcessMapper("title"); - assertEquals("title", mapper.getProperty("title")); - - assertNull(mapper.getProperty(null)); - assertNotNull(mapper.getProperty("identifier")); - } - - /** - * Test the {@link Process#getMetaClass()} method. - */ - @Test - void metaClassTest() { - ProcessMapper mapper = new ProcessMapper(); - assertEquals(InvokerHelper.getMetaClass(ProcessMapper.class), mapper.getMetaClass()); - mapper.setMetaClass(InvokerHelper.getMetaClass(ProcessMapperTest.class)); - assertEquals(InvokerHelper.getMetaClass(ProcessMapperTest.class), mapper.getMetaClass()); - mapper.setMetaClass(null); - assertEquals(InvokerHelper.getMetaClass(ProcessMapper.class), mapper.getMetaClass()); - mapper.setMetaClass(InvokerHelper.getMetaClass(ProcessMapper.class)); - } -} \ No newline at end of file diff --git a/process/src/test/java/org/orbisgis/process/ProcessTest.java b/process/src/test/java/org/orbisgis/process/ProcessTest.java deleted file mode 100644 index 3636da2f..00000000 --- a/process/src/test/java/org/orbisgis/process/ProcessTest.java +++ /dev/null @@ -1,447 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process; - -import groovy.lang.Closure; -import groovy.lang.GroovyCodeSource; -import groovy.lang.GroovyShell; -import org.codehaus.groovy.runtime.InvokerHelper; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.orbisgis.process.api.IProcess; -import org.orbisgis.process.api.inoutput.IInOutPut; -import org.orbisgis.process.api.inoutput.IInput; -import org.orbisgis.process.api.inoutput.IOutput; -import org.orbisgis.process.inoutput.Input; -import org.orbisgis.process.inoutput.Output; - -import java.util.Arrays; -import java.util.LinkedHashMap; - -import static org.junit.jupiter.api.Assertions.*; - -/** - * Test class dedicated to {@link Process} class. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS 2019) - */ -public class ProcessTest { - - private static Process miniProcess; - private static Process fullProcess; - - @BeforeAll - static void beforeAll() { - - Closure cl1 = new Closure(null) { - - @Override - public Object call() { - return null; - } - }; - - miniProcess = new Process(null, null, null, null, null, null, cl1); - - String str = "{in1, in2, in3, in4 -> Object o1 = \"$in1$in2$in3$in4\"\n" + - " Object o2 = 4\n" + - " return [out1:o1, out2:o2, out3:\"toto\"]}"; - Closure cl2 = (Closure) new GroovyShell().evaluate(new GroovyCodeSource(str, "script", "")); - - Input in3 = new Input().title("in title").description("in description") - .keywords(new String[]{"key1", "key2"}).type(String[].class).mandatory(); - Input in4 = new Input().type(Double.class).optional(3.56D); - - LinkedHashMap inputs = new LinkedHashMap<>(); - inputs.put("in1", 5698); - inputs.put("in2", String.class); - inputs.put("in3", in3); - inputs.put("in4", in4); - - Output out1 = new Output().title("out title").description("out description") - .keywords(new String[]{"key1", "key2"}).type(String[].class); - Output out2 = new Output().type(int.class); - - LinkedHashMap outputs = new LinkedHashMap<>(); - outputs.put("out1", out1); - outputs.put("out2", out2); - outputs.put("out3", String.class); - - fullProcess = new Process("title", "description", new String[]{"test", "process"}, inputs, outputs, "1.0.0", cl2); - } - - @Test - void nullResultTest() { - Closure cl = new Closure(null) { - - @Override - public Object call() { - return null; - } - }; - - LinkedHashMap outputs = new LinkedHashMap<>(); - outputs.put("out1", new Output().type(int.class)); - - assertFalse(new Process("title", "description", new String[]{"test", "process"}, new LinkedHashMap<>(), - outputs, "1.0.0", cl).execute(new LinkedHashMap<>())); - } - - @Test - void processPropertiesTest() { - assertFalse(miniProcess.getTitle().isPresent()); - assertFalse(miniProcess.getDescription().isPresent()); - assertFalse(miniProcess.getKeywords().isPresent()); - assertTrue(miniProcess.getInputs().isEmpty()); - assertTrue(miniProcess.getOutputs().isEmpty()); - assertFalse(miniProcess.getVersion().isPresent()); - assertTrue(miniProcess.execute(null)); - - assertTrue(fullProcess.getTitle().isPresent()); - assertEquals("title", fullProcess.getTitle().get()); - assertTrue(fullProcess.getDescription().isPresent()); - assertEquals("description", fullProcess.getDescription().get()); - assertTrue(fullProcess.getKeywords().isPresent()); - assertEquals(2, fullProcess.getKeywords().get().length); - assertEquals("test", fullProcess.getKeywords().get()[0]); - assertEquals("process", fullProcess.getKeywords().get()[1]); - - assertNotNull(fullProcess.getInputs()); - assertEquals(4, fullProcess.getInputs().size()); - - assertTrue(fullProcess.getInputs().get(0).getDefaultValue().isPresent()); - assertEquals(5698, fullProcess.getInputs().get(0).getDefaultValue().get()); - assertTrue(fullProcess.getInputs().get(0).getName().isPresent()); - assertEquals("in1", fullProcess.getInputs().get(0).getName().get()); - assertTrue(fullProcess.getInputs().get(0).getType().isPresent()); - assertEquals(Integer.class, fullProcess.getInputs().get(0).getType().get()); - assertTrue(fullProcess.getInputs().get(0).getProcess().isPresent()); - assertEquals(fullProcess.getIdentifier(), fullProcess.getInputs().get(0).getProcess().get().getIdentifier()); - - assertFalse(fullProcess.getInputs().get(1).getDefaultValue().isPresent()); - assertTrue(fullProcess.getInputs().get(1).getName().isPresent()); - assertEquals("in2", fullProcess.getInputs().get(1).getName().get()); - assertTrue(fullProcess.getInputs().get(1).getType().isPresent()); - assertEquals(String.class, fullProcess.getInputs().get(1).getType().get()); - assertTrue(fullProcess.getInputs().get(1).getProcess().isPresent()); - assertEquals(fullProcess.getIdentifier(), fullProcess.getInputs().get(1).getProcess().get().getIdentifier()); - - assertFalse(fullProcess.getInputs().get(2).getDefaultValue().isPresent()); - assertTrue(fullProcess.getInputs().get(2).getName().isPresent()); - assertEquals("in3", fullProcess.getInputs().get(2).getName().get()); - assertTrue(fullProcess.getInputs().get(2).getType().isPresent()); - assertEquals(String[].class, fullProcess.getInputs().get(2).getType().get()); - assertTrue(fullProcess.getInputs().get(2).getProcess().isPresent()); - assertEquals(fullProcess.getIdentifier(), fullProcess.getInputs().get(2).getProcess().get().getIdentifier()); - - assertTrue(fullProcess.getInputs().get(3).getDefaultValue().isPresent()); - assertEquals(3.56D, fullProcess.getInputs().get(3).getDefaultValue().get()); - assertTrue(fullProcess.getInputs().get(3).getName().isPresent()); - assertEquals("in4", fullProcess.getInputs().get(3).getName().get()); - assertTrue(fullProcess.getInputs().get(3).getType().isPresent()); - assertEquals(Double.class, fullProcess.getInputs().get(3).getType().get()); - assertTrue(fullProcess.getInputs().get(3).getProcess().isPresent()); - assertEquals(fullProcess.getIdentifier(), fullProcess.getInputs().get(3).getProcess().get().getIdentifier()); - - assertNotNull(fullProcess.getOutputs()); - assertEquals(3, fullProcess.getOutputs().size()); - - assertTrue(fullProcess.getOutputs().get(0).getName().isPresent()); - assertEquals("out1", fullProcess.getOutputs().get(0).getName().get()); - assertTrue(fullProcess.getOutputs().get(0).getType().isPresent()); - assertEquals(String[].class, fullProcess.getOutputs().get(0).getType().get()); - assertTrue(fullProcess.getOutputs().get(0).getProcess().isPresent()); - assertEquals(fullProcess.getIdentifier(), fullProcess.getOutputs().get(0).getProcess().get().getIdentifier()); - - assertTrue(fullProcess.getOutputs().get(1).getName().isPresent()); - assertEquals("out2", fullProcess.getOutputs().get(1).getName().get()); - assertTrue(fullProcess.getOutputs().get(1).getType().isPresent()); - assertEquals(int.class, fullProcess.getOutputs().get(1).getType().get()); - assertTrue(fullProcess.getOutputs().get(1).getProcess().isPresent()); - assertEquals(fullProcess.getIdentifier(), fullProcess.getOutputs().get(1).getProcess().get().getIdentifier()); - - assertTrue(fullProcess.getOutputs().get(2).getName().isPresent()); - assertEquals("out3", fullProcess.getOutputs().get(2).getName().get()); - assertTrue(fullProcess.getOutputs().get(2).getType().isPresent()); - assertEquals(String.class, fullProcess.getOutputs().get(2).getType().get()); - assertTrue(fullProcess.getOutputs().get(2).getProcess().isPresent()); - assertEquals(fullProcess.getIdentifier(), fullProcess.getOutputs().get(2).getProcess().get().getIdentifier()); - - assertTrue(fullProcess.getVersion().isPresent()); - assertEquals("1.0.0", fullProcess.getVersion().get()); - - LinkedHashMap data = new LinkedHashMap<>(); - data.put("in2", "toto"); - data.put("in3", new String[]{"t", "a", "t", "a"}); - assertTrue(fullProcess.execute(data)); - assertEquals(3, fullProcess.getResults().size()); - assertEquals("5698toto[t, a, t, a]3.56", fullProcess.getResults().get("out1").toString()); - assertEquals(4, fullProcess.getResults().get("out2")); - assertEquals("toto", fullProcess.getResults().get("out3")); - } - - @Test - void badProcessTest() { - //Test wrong constructor - assertFalse(new Process(null, null, null, new LinkedHashMap<>(), null, null, new Closure(null) { - @Override - public int getMaximumNumberOfParameters() { - return 2; - } - }).execute(new LinkedHashMap<>())); - - assertFalse(new Process(null, null, null, new LinkedHashMap<>(), null, null, null).execute(null)); - - //Test execution with exception - LinkedHashMap inputs = new LinkedHashMap<>(); - inputs.put("in", String.class); - LinkedHashMap outputs = new LinkedHashMap<>(); - outputs.put("out", String.class); - Process p = new Process(null, null, null, inputs, outputs, null, new Closure(null) { - @Override - public int getMaximumNumberOfParameters() { - return 1; - } - - @Override - public Object call(Object... args) { - Arrays.asList(args).forEach(System.out::println); - return null; - } - }); - LinkedHashMap data = new LinkedHashMap<>(); - data.put("in", null); - assertFalse(p.execute(data)); - - //Test null input value - inputs = new LinkedHashMap<>(); - inputs.put("in", String.class); - outputs = new LinkedHashMap<>(); - outputs.put("out", String.class); - p = new Process(null, null, null, inputs, outputs, null, new Closure(null) { - @Override - public int getMaximumNumberOfParameters() { - return 1; - } - - @Override - public Object call(Object... args) { - return null; - } - }); - data = new LinkedHashMap<>(); - data.put("in", null); - assertFalse(p.execute(data)); - - //Test no mandatory input - data = new LinkedHashMap<>(); - data.put("in3", "toto"); - data.put("in", "toto"); - data.put(null, "toto"); - assertFalse(fullProcess.execute(data)); - - //Test too much inputs - data = new LinkedHashMap<>(); - data.put("in", "toto"); - data.put("in2", "toto"); - data.put("in3", "toto"); - data.put("in4", "toto"); - data.put("in5", "toto"); - data.put(null, "toto"); - assertFalse(fullProcess.call(data)); - - //Test empty inputs - assertFalse(fullProcess.execute(new LinkedHashMap<>())); - } - - @Test - void returnClosureTest() { - String str = "{ o -> return 'toto' }"; - Closure cl = (Closure) new GroovyShell().evaluate(new GroovyCodeSource(str, "script", "")); - LinkedHashMap inputs = new LinkedHashMap<>(); - inputs.put("o", String.class); - LinkedHashMap outputs = new LinkedHashMap<>(); - outputs.put("o", String.class); - - IProcess process = new Process(null, null, null, inputs, null, null, cl); - assertTrue(process.execute(inputs)); - assertTrue(process.getResults().containsKey("result")); - assertEquals("toto", process.getResults().get("result")); - - process = new Process(null, null, null, inputs, outputs, null, cl); - assertTrue(process.execute(inputs)); - assertTrue(process.getResults().containsKey("result")); - assertEquals("toto", process.getResults().get("result")); - - str = "{ -> return [o1 : 'toto'] }"; - cl = (Closure) new GroovyShell().evaluate(new GroovyCodeSource(str, "script", "")); - process = new Process(null, null, null, null, outputs, null, cl); - assertTrue(process.execute(null)); - assertTrue(process.getResults().containsKey("o1")); - assertEquals("toto", process.getResults().get("o1")); - - outputs = new LinkedHashMap<>(); - outputs.put("o1", String.class); - outputs.put("o2", String.class); - str = "{ o1 -> return null }"; - cl = (Closure) new GroovyShell().evaluate(new GroovyCodeSource(str, "script", "")); - process = new Process(null, null, null, inputs, outputs, null, cl); - assertFalse(process.execute(inputs)); - - outputs = new LinkedHashMap<>(); - outputs.put("o1", String.class); - outputs.put("o2", String.class); - str = "{ o1 -> return 'yoyo' }"; - cl = (Closure) new GroovyShell().evaluate(new GroovyCodeSource(str, "script", "")); - process = new Process(null, null, null, inputs, outputs, null, cl); - assertFalse(process.execute(inputs)); - - outputs = new LinkedHashMap<>(); - outputs.put("o1", String.class); - outputs.put("o2", String.class); - str = "{ o1 -> return [o1 : 'otot', o3 : 'toto'] }"; - cl = (Closure) new GroovyShell().evaluate(new GroovyCodeSource(str, "script", "")); - process = new Process(null, null, null, inputs, outputs, null, cl); - assertFalse(process.execute(inputs)); - } - - /** - * Test the {@link Process#newInstance()} method. - */ - @Test - void newInstanceTest() { - IProcess p = fullProcess.newInstance(); - assertEquals(fullProcess.getTitle(), p.getTitle()); - assertEquals(fullProcess.getDescription(), p.getDescription()); - assertEquals(fullProcess.getKeywords(), p.getKeywords()); - assertTrue(fullProcess.getInputs().stream().map(IInOutPut::getName) - .allMatch(in -> p.getInputs().stream().map(IInOutPut::getName).anyMatch(in::equals))); - assertTrue(fullProcess.getOutputs().stream().map(IInOutPut::getName) - .allMatch(in -> p.getOutputs().stream().map(IInOutPut::getName).anyMatch(in::equals))); - assertEquals(fullProcess.getVersion(), p.getVersion()); - assertNotEquals(fullProcess.getIdentifier(), p.getIdentifier()); - } - - /** - * Test the {@link Process#copy()} method. - */ - @Test - void copyTest() { - IProcess p = fullProcess.copy(); - assertEquals(fullProcess.getTitle(), p.getTitle()); - assertEquals(fullProcess.getDescription(), p.getDescription()); - assertEquals(fullProcess.getKeywords(), p.getKeywords()); - assertTrue(fullProcess.getInputs().stream().map(IInOutPut::getName) - .allMatch(in -> p.getInputs().stream().map(IInOutPut::getName).anyMatch(in::equals))); - assertTrue(fullProcess.getOutputs().stream().map(IInOutPut::getName) - .allMatch(in -> p.getOutputs().stream().map(IInOutPut::getName).anyMatch(in::equals))); - assertEquals(fullProcess.getVersion(), p.getVersion()); - assertEquals(fullProcess.getIdentifier(), p.getIdentifier()); - } - - /** - * Test the {@link Process#invokeMethod(String, Object)} method. - */ - @Test - void invokeMethodTest() { - assertEquals("title", fullProcess.invokeMethod("getTitle", null)); - assertEquals("1.0.0", fullProcess.invokeMethod("getVersion", null)); - - assertNull(fullProcess.invokeMethod(null, null)); - assertNotNull(fullProcess.invokeMethod("getIdentifier", null)); - } - - /** - * Test the {@link Process#getProperty(String)} method. - */ - @Test - void getPropertyTest() { - assertInstanceOf(IInput.class, fullProcess.getProperty("in1")); - assertInstanceOf(IInput.class, fullProcess.getProperty("in2")); - assertInstanceOf(IInput.class, fullProcess.getProperty("in3")); - assertInstanceOf(IInput.class, fullProcess.getProperty("in4")); - assertInstanceOf(IOutput.class, fullProcess.getProperty("out1")); - assertInstanceOf(IOutput.class, fullProcess.getProperty("out2")); - assertInstanceOf(IOutput.class, fullProcess.getProperty("out3")); - assertEquals("title", fullProcess.getProperty("title")); - - assertNull(fullProcess.getProperty(null)); - assertNotNull(fullProcess.getProperty("identifier")); - } - - /** - * Test the {@link Process#getProperty(String)} and {@link Process#setProperty(String, Object)} methods. - */ - @Test - void setPropertyTest() { - assertEquals("title", fullProcess.getProperty("title")); - fullProcess.setProperty("title", "toto"); - assertEquals("toto", fullProcess.getProperty("title")); - fullProcess.setProperty("title", "title"); - assertEquals("title", fullProcess.getProperty("title")); - } - - /** - * Test the {@link Process#getMetaClass()} method. - */ - @Test - void metaClassTest() { - assertEquals(InvokerHelper.getMetaClass(Process.class), fullProcess.getMetaClass()); - fullProcess.setMetaClass(InvokerHelper.getMetaClass(ProcessTest.class)); - assertEquals(InvokerHelper.getMetaClass(ProcessTest.class), fullProcess.getMetaClass()); - fullProcess.setMetaClass(null); - assertEquals(InvokerHelper.getMetaClass(Process.class), fullProcess.getMetaClass()); - fullProcess.setMetaClass(InvokerHelper.getMetaClass(Process.class)); - } - - /** - * Test the {@link Process#equals(Object)} method. - */ - @Test - void equalsTest() { - assertNotEquals(fullProcess, "miniProcess"); - assertNotEquals(fullProcess, miniProcess); - assertNotEquals(fullProcess, fullProcess.newInstance()); - assertNotEquals(fullProcess, null); - assertNotEquals(miniProcess, miniProcess.newInstance()); - assertNotEquals(miniProcess, null); - - assertEquals(fullProcess, fullProcess); - assertEquals(miniProcess, miniProcess); - } -} diff --git a/process/src/test/java/org/orbisgis/process/ProgressMonitorTest.java b/process/src/test/java/org/orbisgis/process/ProgressMonitorTest.java deleted file mode 100644 index 3c023468..00000000 --- a/process/src/test/java/org/orbisgis/process/ProgressMonitorTest.java +++ /dev/null @@ -1,278 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process; - -import org.junit.jupiter.api.Test; -import org.orbisgis.process.api.IProgressMonitor; - -import java.util.ArrayList; -import java.util.List; - -import static java.lang.Math.round; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -/** - * Test class dedicated to {@link ProgressMonitor} class. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (Lab-STICC UBS 2020) - */ -class ProgressMonitorTest { - - @Test - public void progressTest() { - IProgressMonitor pm1 = new ProgressMonitor("main", 7, true); - IProgressMonitor pm2 = new ProgressMonitor("main", 7); - IProgressMonitor pm3 = new ProgressMonitor(7, true); - IProgressMonitor pm4 = new ProgressMonitor(7); - IProgressMonitor pm5 = new ProgressMonitor("main", true); - IProgressMonitor pm6 = new ProgressMonitor(true); - IProgressMonitor pm7 = new ProgressMonitor("main"); - IProgressMonitor pm8 = new ProgressMonitor(); - - assertEquals(7, pm1.getMaxStep()); - assertEquals(7, pm2.getMaxStep()); - assertEquals(7, pm3.getMaxStep()); - assertEquals(7, pm4.getMaxStep()); - assertEquals(-1, pm5.getMaxStep()); - assertEquals(-1, pm6.getMaxStep()); - assertEquals(-1, pm7.getMaxStep()); - assertEquals(-1, pm8.getMaxStep()); - - assertEquals("main", pm1.getName()); - assertEquals("main", pm2.getName()); - assertNotNull(pm3.getName()); - assertNotNull(pm4.getName()); - assertEquals("main", pm5.getName()); - assertNotNull(pm6.getName()); - assertEquals("main", pm7.getName()); - assertNotNull(pm8.getName()); - } - - @Test - public void progressWithMaxTest(){ - List list = new ArrayList<>(); - list.add(new ProgressMonitor("main", 7, true)); - list.add(new ProgressMonitor("main", 7)); - list.add(new ProgressMonitor(7, true)); - list.add(new ProgressMonitor(7)); - - for(IProgressMonitor pm : list) { - float p = 0; - float p1 = 0; - float p2 = 0; - float p3 = 0; - float p4 = 0; - float p5 = 0; - float p6 = 0; - float p7 = 0; - assertEquals(7, pm.getMaxStep()); - assertEquals(0.0, pm.getProgress()); - - pm.incrementStep(); - p++; - assertEquals(round(100.0 / 7.0), round(pm.getProgress())); - - IProgressMonitor subPm1 = pm.getSubProgress("sub1", 4, false); - assertNotNull(subPm1); - - pm.incrementStep(); - p++; - pm.incrementStep(); - p++; - assertEquals(round(100.0 / 8.0 * 3.0), round(pm.getProgress())); - - IProgressMonitor subPm2 = pm.getSubProgress("sub2", 3); - assertNotNull(subPm2); - IProgressMonitor subPm3 = pm.getSubProgress("sub3", false); - assertNotNull(subPm3); - IProgressMonitor subPm4 = pm.getSubProgress(4, false); - assertNotNull(subPm4); - IProgressMonitor subPm5 = pm.getSubProgress("sub2"); - assertNotNull(subPm5); - IProgressMonitor subPm6 = pm.getSubProgress(false); - assertNotNull(subPm6); - IProgressMonitor subPm7 = pm.getSubProgress(5); - assertNotNull(subPm7); - - subPm1.incrementStep(); - p1++; - assertEquals(round(getProg(p, p1, p2, p3, p4, p5, p6, p7)), round(pm.getProgress())); - - subPm1.incrementStep(); - p1++; - subPm1.incrementStep(); - p1++; - assertEquals(round(getProg(p, p1, p2, p3, p4, p5, p6, p7)), round(pm.getProgress())); - - subPm2.incrementStep(); - p2++; - subPm2.incrementStep(); - p2++; - assertEquals(round(getProg(p, p1, p2, p3, p4, p5, p6, p7)), round(pm.getProgress())); - - subPm3.incrementStep(); - subPm3.incrementStep(); - subPm3.incrementStep(); - assertEquals(round(getProg(p, p1, p2, p3, p4, p5, p6, p7)), round(pm.getProgress())); - - subPm3.end(); - p3 = 1; - assertEquals(round(getProg(p, p1, p2, p3, p4, p5, p6, p7)), round(pm.getProgress())); - - subPm5.end(); - p5 = 1; - subPm6.end(); - p6 = 1; - assertEquals(round(getProg(p, p1, p2, p3, p4, p5, p6, p7)), round(pm.getProgress())); - - subPm7.end(); - p7 = 5; - assertEquals(round(getProg(p, p1, p2, p3, p4, p5, p6, p7)), round(pm.getProgress())); - - subPm1.incrementStep(); - p1++; - subPm2.incrementStep(); - p2++; - assertEquals(round(getProg(p, p1, p2, p3, p4, p5, p6, p7)), round(pm.getProgress())); - - pm.incrementStep(); - p++; - pm.incrementStep(); - p++; - assertEquals(round(getProg(p, p1, p2, p3, p4, p5, p6, p7)), round(pm.getProgress())); - - subPm4.end(); - p4 = 4; - assertEquals(round(getProg(p, p1, p2, p3, p4, p5, p6, p7)), round(pm.getProgress())); - - pm.incrementStep(); - pm.incrementStep(); - assertEquals(100.0, round(pm.getProgress())); - - pm.incrementStep(); - pm.incrementStep(); - pm.incrementStep(); - assertEquals(100.0, round(pm.getProgress())); - } - } - - @Test - public void progressWithoutMaxTest(){ - List list = new ArrayList<>(); - list.add(new ProgressMonitor("main", true)); - list.add(new ProgressMonitor(true)); - list.add(new ProgressMonitor("main")); - list.add(new ProgressMonitor()); - - for(IProgressMonitor pm : list) { - assertEquals(-1, pm.getMaxStep()); - assertEquals(-1, pm.getProgress()); - - pm.incrementStep(); - assertEquals(-1, pm.getProgress()); - - IProgressMonitor subPm1 = pm.getSubProgress("sub1", 4, false); - assertNotNull(subPm1); - - pm.incrementStep(); - pm.incrementStep(); - assertEquals(-1, pm.getProgress()); - - IProgressMonitor subPm2 = pm.getSubProgress("sub2", 3); - assertNotNull(subPm2); - IProgressMonitor subPm3 = pm.getSubProgress("sub3", false); - assertNotNull(subPm3); - IProgressMonitor subPm4 = pm.getSubProgress(4, false); - assertNotNull(subPm4); - IProgressMonitor subPm5 = pm.getSubProgress("sub2"); - assertNotNull(subPm5); - IProgressMonitor subPm6 = pm.getSubProgress(false); - assertNotNull(subPm6); - IProgressMonitor subPm7 = pm.getSubProgress(5); - assertNotNull(subPm7); - - subPm1.incrementStep(); - assertEquals(-1, pm.getProgress()); - - subPm1.incrementStep(); - subPm1.incrementStep(); - assertEquals(-1, pm.getProgress()); - - subPm2.incrementStep(); - subPm2.incrementStep(); - assertEquals(-1, pm.getProgress()); - - subPm3.incrementStep(); - subPm3.incrementStep(); - subPm3.incrementStep(); - assertEquals(-1, pm.getProgress()); - - subPm3.end(); - assertEquals(-1, pm.getProgress()); - - subPm5.end(); - subPm6.end(); - assertEquals(-1, pm.getProgress()); - - subPm7.end(); - assertEquals(-1, pm.getProgress()); - - subPm1.incrementStep(); - subPm2.incrementStep(); - assertEquals(-1, pm.getProgress()); - - pm.incrementStep(); - pm.incrementStep(); - assertEquals(-1, pm.getProgress()); - - subPm4.end(); - assertEquals(-1, pm.getProgress()); - - pm.end(); - assertEquals(100.0, round(pm.getProgress())); - } - } - - private double getProg(float p, float p1, float p2, float p3, float p4, float p5, float p6, float p7){ - if(p3 == 0 || p5 == 0 || p6 == 0){ - return -1; - } - return (100.0/(7+7)*(p+p1/4+p2/3+p3+p4/4+p5+p6+p7/5)); - } -} \ No newline at end of file diff --git a/process/src/test/java/org/orbisgis/process/check/CheckClosureBuilderTest.java b/process/src/test/java/org/orbisgis/process/check/CheckClosureBuilderTest.java deleted file mode 100644 index 4fbe1136..00000000 --- a/process/src/test/java/org/orbisgis/process/check/CheckClosureBuilderTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process.check; - -import groovy.lang.Closure; -import org.junit.jupiter.api.Test; -import org.orbisgis.process.check.CheckClosureBuilder; - -import static org.junit.jupiter.api.Assertions.*; - -/** - * Test class dedicated to {@link CheckClosureBuilder} class. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS 2020) - */ -public class CheckClosureBuilderTest { - - /** - * Test the {@link CheckClosureBuilder#check(Closure)} method. - */ - @Test - public void checkTest() { - DummyProcessCheck dummy = new DummyProcessCheck(null); - CheckClosureBuilder builder = new CheckClosureBuilder(dummy); - Closure cl = new Closure(this) {}; - assertNotNull(builder.check(cl)); - assertEquals(cl, dummy.closure); - - dummy = new DummyProcessCheck(null); - builder = new CheckClosureBuilder(dummy); - assertNotNull(builder.check(null)); - assertNull(dummy.closure); - } -} diff --git a/process/src/test/java/org/orbisgis/process/check/CheckDataBuilderTest.java b/process/src/test/java/org/orbisgis/process/check/CheckDataBuilderTest.java deleted file mode 100644 index d2e5d425..00000000 --- a/process/src/test/java/org/orbisgis/process/check/CheckDataBuilderTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process.check; - -import org.junit.jupiter.api.Test; -import org.orbisgis.process.api.inoutput.IInOutPut; -import org.orbisgis.process.check.CheckClosureBuilder; -import org.orbisgis.process.check.CheckDataBuilder; -import org.orbisgis.process.inoutput.InOutPut; -import org.orbisgis.process.inoutput.Input; -import org.orbisgis.process.inoutput.Output; - -import static org.junit.jupiter.api.Assertions.*; - -/** - * Test class dedicated to {@link CheckClosureBuilder} class. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS 2020) - */ -public class CheckDataBuilderTest { - - /** - * Test the {@link CheckDataBuilder#with(IInOutPut...)} method. - */ - @Test - public void withTest() { - Input in1 = new Input(); - Input in2 = new Input(); - Output out1 = new Output(); - Output out2 = new Output(); - - DummyProcessCheck dummy = new DummyProcessCheck(null); - CheckDataBuilder builder = new CheckDataBuilder(dummy); - assertNotNull(builder.with(in1, in2, out1, out2)); - assertArrayEquals(new InOutPut[]{in1, in2, out1, out2}, dummy.inputOrOutput); - - dummy = new DummyProcessCheck(null); - builder = new CheckDataBuilder(dummy); - assertNotNull(builder.with(out2)); - assertArrayEquals(new InOutPut[]{out2}, dummy.inputOrOutput); - - dummy = new DummyProcessCheck(null); - builder = new CheckDataBuilder(dummy); - assertNotNull(builder.with((IInOutPut[]) null)); - assertNull(dummy.inputOrOutput); - - dummy = new DummyProcessCheck(null); - builder = new CheckDataBuilder(dummy); - assertNotNull(builder.with((IInOutPut) null)); - assertNull(dummy.inputOrOutput); - - dummy = new DummyProcessCheck(null); - builder = new CheckDataBuilder(dummy); - assertNotNull(builder.with()); - assertNull(dummy.inputOrOutput); - } -} diff --git a/process/src/test/java/org/orbisgis/process/check/CheckOptionBuilderTest.java b/process/src/test/java/org/orbisgis/process/check/CheckOptionBuilderTest.java deleted file mode 100644 index bd8ca284..00000000 --- a/process/src/test/java/org/orbisgis/process/check/CheckOptionBuilderTest.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process.check; - -import org.junit.jupiter.api.Test; -import org.orbisgis.process.api.check.IProcessCheck; -import org.orbisgis.process.check.CheckOptionBuilder; - -import static org.junit.jupiter.api.Assertions.*; - -/** - * Test class dedicated to {@link CheckOptionBuilder} class. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS 2019-2020) - */ -public class CheckOptionBuilderTest { - - /** - * Test the {@link CheckOptionBuilder#stopOnFail()}, {@link CheckOptionBuilder#stopOnFail(String)}, - * {@link CheckOptionBuilder#continueOnFail()}, {@link CheckOptionBuilder#continueOnFail(String)}methods. - */ - @Test - public void onFailTest() { - String failMessage = "Fail Message"; - String successMessage = "Success Message"; - - DummyProcessCheck dummy = new DummyProcessCheck(null); - CheckOptionBuilder builder = new CheckOptionBuilder(dummy); - assertNotNull(builder.stopOnFail()); - assertEquals(IProcessCheck.Action.STOP, dummy.failAction); - assertNull(dummy.failMessage); - - dummy = new DummyProcessCheck(null); - builder = new CheckOptionBuilder(dummy); - assertNotNull(builder.stopOnFail(failMessage)); - assertEquals(IProcessCheck.Action.STOP, dummy.failAction); - assertEquals(failMessage, dummy.failMessage); - - dummy = new DummyProcessCheck(null); - builder = new CheckOptionBuilder(dummy); - assertNotNull(builder.stopOnFail()); - assertEquals(IProcessCheck.Action.STOP, dummy.failAction); - assertNull(dummy.failMessage); - - dummy = new DummyProcessCheck(null); - builder = new CheckOptionBuilder(dummy); - assertNotNull(builder.stopOnFail(null)); - assertEquals(IProcessCheck.Action.STOP, dummy.failAction); - assertNull(dummy.failMessage); - - dummy = new DummyProcessCheck(null); - builder = new CheckOptionBuilder(dummy); - assertNotNull(builder.stopOnFail()); - assertEquals(IProcessCheck.Action.STOP, dummy.failAction); - assertNull(dummy.failMessage); - - dummy = new DummyProcessCheck(null); - builder = new CheckOptionBuilder(dummy); - assertNotNull(builder.continueOnFail(successMessage)); - assertEquals(IProcessCheck.Action.CONTINUE, dummy.failAction); - assertEquals(successMessage, dummy.failMessage); - - dummy = new DummyProcessCheck(null); - builder = new CheckOptionBuilder(dummy); - assertNotNull(builder.continueOnFail()); - assertEquals(IProcessCheck.Action.CONTINUE, dummy.failAction); - assertNull(dummy.failMessage); - - dummy = new DummyProcessCheck(null); - builder = new CheckOptionBuilder(dummy); - assertNotNull(builder.continueOnFail(null)); - assertEquals(IProcessCheck.Action.CONTINUE, dummy.failAction); - assertNull(dummy.failMessage); - - dummy = new DummyProcessCheck(null); - builder = new CheckOptionBuilder(dummy); - assertNotNull(builder.continueOnFail()); - assertEquals(IProcessCheck.Action.CONTINUE, dummy.failAction); - assertNull(dummy.failMessage); - } - - /** - * Test the {@link CheckOptionBuilder#stopOnSuccess()}, {@link CheckOptionBuilder#stopOnSuccess(String)}, - * {@link CheckOptionBuilder#continueOnSuccess()}, {@link CheckOptionBuilder#continueOnSuccess(String)}methods. - */ - @Test - public void onSuccessTest() { - String failMessage = "Fail Message"; - String successMessage = "Success Message"; - - DummyProcessCheck dummy = new DummyProcessCheck(null); - CheckOptionBuilder builder = new CheckOptionBuilder(dummy); - assertNotNull(builder.stopOnSuccess()); - assertEquals(IProcessCheck.Action.STOP, dummy.successAction); - assertNull(dummy.successMessage); - - dummy = new DummyProcessCheck(null); - builder = new CheckOptionBuilder(dummy); - assertNotNull(builder.stopOnSuccess(failMessage)); - assertEquals(IProcessCheck.Action.STOP, dummy.successAction); - assertEquals(failMessage, dummy.successMessage); - - dummy = new DummyProcessCheck(null); - builder = new CheckOptionBuilder(dummy); - assertNotNull(builder.stopOnSuccess()); - assertEquals(IProcessCheck.Action.STOP, dummy.successAction); - assertNull(dummy.successMessage); - - dummy = new DummyProcessCheck(null); - builder = new CheckOptionBuilder(dummy); - assertNotNull(builder.stopOnSuccess(null)); - assertEquals(IProcessCheck.Action.STOP, dummy.successAction); - assertNull(dummy.successMessage); - - dummy = new DummyProcessCheck(null); - builder = new CheckOptionBuilder(dummy); - assertNotNull(builder.stopOnSuccess()); - assertEquals(IProcessCheck.Action.STOP, dummy.successAction); - assertNull(dummy.successMessage); - - dummy = new DummyProcessCheck(null); - builder = new CheckOptionBuilder(dummy); - assertNotNull(builder.continueOnSuccess(successMessage)); - assertEquals(IProcessCheck.Action.CONTINUE, dummy.successAction); - assertEquals(successMessage, dummy.successMessage); - - dummy = new DummyProcessCheck(null); - builder = new CheckOptionBuilder(dummy); - assertNotNull(builder.continueOnSuccess()); - assertEquals(IProcessCheck.Action.CONTINUE, dummy.successAction); - assertNull(dummy.successMessage); - - dummy = new DummyProcessCheck(null); - builder = new CheckOptionBuilder(dummy); - assertNotNull(builder.continueOnSuccess(null)); - assertEquals(IProcessCheck.Action.CONTINUE, dummy.successAction); - assertNull(dummy.successMessage); - - dummy = new DummyProcessCheck(null); - builder = new CheckOptionBuilder(dummy); - assertNotNull(builder.continueOnSuccess()); - assertEquals(IProcessCheck.Action.CONTINUE, dummy.successAction); - assertNull(dummy.successMessage); - } -} diff --git a/process/src/test/java/org/orbisgis/process/check/DummyProcessCheck.java b/process/src/test/java/org/orbisgis/process/check/DummyProcessCheck.java deleted file mode 100644 index 30916885..00000000 --- a/process/src/test/java/org/orbisgis/process/check/DummyProcessCheck.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process.check; - -import groovy.lang.Closure; -import org.orbisgis.process.api.IProcess; -import org.orbisgis.process.api.check.IProcessCheck; -import org.orbisgis.process.api.inoutput.IInOutPut; - -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.Optional; - -/** - * {@link IProcessCheck} implementation for test purpose. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS 2020) - */ -public class DummyProcessCheck implements IProcessCheck { - - public LinkedHashMap processInData; - public Action failAction; - public String failMessage; - public Action successAction; - public String successMessage; - public IInOutPut[] inputOrOutput; - public Closure closure; - public IProcess process; - - public DummyProcessCheck(IProcess process) { - this.process = process; - } - - @Override - public boolean run(LinkedHashMap processInData) { - this.processInData = processInData; - return false; - } - - @Override - public void onFail(Action action, String message) { - this.failAction = action; - this.failMessage = message; - } - - @Override - public void onFail(String message) { - this.failMessage = message; - } - - @Override - public void onSuccess(Action action, String message) { - this.successAction = action; - this.successMessage = message; - } - - @Override - public void onSuccess(String message) { - this.successMessage = message; - } - - @Override - public void setInOutPuts(IInOutPut... inputOrOutput) { - this.inputOrOutput = inputOrOutput; - } - - @Override - public LinkedList getInOutPuts() { - return new LinkedList<>(); - } - - @Override - public void setClosure(Closure cl) { - this.closure = cl; - } - - @Override - public Optional> getClosure() { - return Optional.ofNullable(closure); - } - - @Override - public boolean fail() { - return false; - } - - @Override - public boolean success() { - return false; - } - - @Override - public Optional getProcess() { - return Optional.ofNullable(process); - } -} diff --git a/process/src/test/java/org/orbisgis/process/check/ProcessCheckTest.java b/process/src/test/java/org/orbisgis/process/check/ProcessCheckTest.java deleted file mode 100644 index b2c2ebfd..00000000 --- a/process/src/test/java/org/orbisgis/process/check/ProcessCheckTest.java +++ /dev/null @@ -1,527 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process.check; - -import groovy.lang.Closure; -import groovy.lang.GroovyCodeSource; -import groovy.lang.GroovyShell; -import org.codehaus.groovy.runtime.InvokerHelper; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.orbisgis.process.api.IProcess; -import org.orbisgis.process.api.check.IProcessCheck; -import org.orbisgis.process.api.inoutput.IInOutPut; -import org.orbisgis.process.ProcessManager; -import org.orbisgis.process.check.ProcessCheck; -import org.orbisgis.process.inoutput.Input; -import org.orbisgis.process.inoutput.Output; - -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.*; -import static org.orbisgis.process.api.check.IProcessCheck.Action.CONTINUE; -import static org.orbisgis.process.api.check.IProcessCheck.Action.STOP; - -/** - * Test class dedicated to {@link ProcessCheck} class. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS 2020) - */ -public class ProcessCheckTest { - - private static IProcess PROCESS; - - private static IProcess NULL_PROCESS; - - @BeforeAll - public static void beforeAll() { - LinkedHashMap outputs = new LinkedHashMap<>(); - outputs.put("out1", new Output()); - - LinkedHashMap inputs = new LinkedHashMap<>(); - inputs.put("in1", new Input()); - inputs.put("in2", new Input()); - inputs.put("in3", new Input()); - - String str = "{in1, in2, in3 -> return [out1:in1+in2+in3]}"; - Closure cl = (Closure) new GroovyShell().evaluate(new GroovyCodeSource(str, "script", "")); - - PROCESS = ProcessManager.createFactory() - .create() - .outputs(outputs) - .inputs(inputs) - .run(cl) - .getProcess(); - NULL_PROCESS = null; - } - - /** - * Test the {@link ProcessCheck#getProcess()} method. - */ - @Test - public void getProcessTest() { - assertTrue(new ProcessCheck(PROCESS).getProcess().isPresent()); - assertFalse(new ProcessCheck(NULL_PROCESS).getProcess().isPresent()); - } - - /** - * Test the {@link ProcessCheck#fail()}, {@link ProcessCheck#success()}, - * {@link ProcessCheck#onFail(String)}, {@link ProcessCheck#onFail(IProcessCheck.Action, String)}, - * {@link ProcessCheck#onSuccess(String)}, {@link ProcessCheck#onSuccess(IProcessCheck.Action, String)} methods. - */ - @Test - public void failSuccessTest() { - String message = "message"; - ProcessCheck check = new ProcessCheck(PROCESS); - - assertTrue(check::fail); - assertFalse(check::success); - - check.onFail(null, message); - assertTrue(check::fail); - check.onFail(null, null); - assertTrue(check::fail); - check.onFail(STOP, message); - assertTrue(check::fail); - check.onFail(STOP, null); - assertTrue(check::fail); - check.onFail(CONTINUE, message); - assertFalse(check::fail); - check.onFail(CONTINUE, null); - assertFalse(check::fail); - check.onFail(message); - assertTrue(check::fail); - check.onFail(null); - assertTrue(check::fail); - - check.onSuccess(null, message); - assertTrue(check::success); - check.onSuccess(null, null); - assertTrue(check::success); - check.onSuccess(STOP, message); - assertTrue(check::success); - check.onSuccess(STOP, null); - assertTrue(check::success); - check.onSuccess(CONTINUE, message); - assertFalse(check::success); - check.onSuccess(CONTINUE, null); - assertFalse(check::success); - check.onSuccess(message); - assertFalse(check::success); - check.onSuccess(null); - assertFalse(check::success); - } - - /** - * Test the {@link ProcessCheck#run(LinkedHashMap)}, {@link ProcessCheck#setClosure(Closure)}, - * {@link ProcessCheck#setInOutPuts(IInOutPut...)} methods. - */ - @Test - public void runTest() { - LinkedHashMap map = new LinkedHashMap<>(); - map.put("in1", "a"); - map.put("in2", "b"); - - String str = "{in1, in2, in3 -> return in1+in2+in3 == 'abc'}"; - Closure cl = (Closure) new GroovyShell().evaluate(new GroovyCodeSource(str, "script", "")); - - IInOutPut[] emptyInOutPuts = new IInOutPut[]{}; - IInOutPut[] inOutPuts = new IInOutPut[]{ - new Input().process(PROCESS).name("in1").optional("a"), - new Input().process(PROCESS).name("in2"), - new Input().process(PROCESS).name("in3").optional("c")}; - - ProcessCheck processCheck = new ProcessCheck(PROCESS); - - //Ensure the check is not run - processCheck.onFail(STOP, null); - processCheck.onSuccess(STOP, null); - - processCheck.setClosure(null); - assertFalse(processCheck.getClosure().isPresent()); - processCheck.setInOutPuts((IInOutPut[]) null); - assertTrue(processCheck.getInOutPuts().isEmpty()); - assertFalse(processCheck.run(null)); - assertFalse(processCheck.run(new LinkedHashMap<>())); - assertFalse(processCheck.run(map)); - - processCheck.setClosure(null); - processCheck.setInOutPuts(emptyInOutPuts); - assertFalse(processCheck.run(null)); - assertFalse(processCheck.run(new LinkedHashMap<>())); - assertFalse(processCheck.run(map)); - - processCheck.setClosure(null); - processCheck.setInOutPuts(inOutPuts); - assertFalse(processCheck.run(null)); - assertFalse(processCheck.run(new LinkedHashMap<>())); - assertTrue(processCheck.run(map)); - - processCheck.setClosure(cl); - processCheck.setInOutPuts((IInOutPut[]) null); - assertTrue(processCheck.run(null)); - assertTrue(processCheck.run(new LinkedHashMap<>())); - assertTrue(processCheck.run(map)); - - processCheck.setClosure(cl); - processCheck.setInOutPuts(emptyInOutPuts); - assertTrue(processCheck.run(null)); - assertTrue(processCheck.run(new LinkedHashMap<>())); - assertTrue(processCheck.run(map)); - - processCheck.setClosure(cl); - assertTrue(processCheck.getClosure().isPresent()); - assertEquals(cl, processCheck.getClosure().get()); - processCheck.setInOutPuts(inOutPuts); - assertEquals(3, processCheck.getInOutPuts().size()); - assertTrue(processCheck.run(null)); - assertTrue(processCheck.run(new LinkedHashMap<>())); - assertTrue(processCheck.run(map)); - - - //Test that check without closure fail when required - IInOutPut[] inOutPutsOpt = new IInOutPut[]{ - new Input().process(PROCESS).name("in1").optional("a"), - new Input().process(PROCESS).name("in2").optional("b"), - new Input().process(PROCESS).name("in3").optional("c"), - new Output().process(PROCESS).name("out1")}; - IInOutPut[] noNameInOutPuts = new IInOutPut[]{ - new Input().process(PROCESS).name("in1").optional("a"), - new Input().process(PROCESS).optional("b"), - new Input().process(PROCESS).optional("c"), - new Output().process(PROCESS).name("out1")}; - - LinkedHashMap mapMissingInputs = new LinkedHashMap<>(); - mapMissingInputs.put("in1", "a"); - - LinkedHashMap mapInvalidInputs = new LinkedHashMap<>(); - mapInvalidInputs.put("in1", "a"); - mapInvalidInputs.put("in2", "a"); - mapInvalidInputs.put("in3", "a"); - - LinkedHashMap mapInputs = new LinkedHashMap<>(); - mapInputs.put("in1", "a"); - mapInputs.put("in2", "b"); - mapInputs.put("in3", "c"); - - processCheck.onFail(STOP, null); - processCheck.onSuccess(CONTINUE, null); - - processCheck.setClosure(null); - processCheck.setInOutPuts(noNameInOutPuts); - assertTrue(processCheck.run(map)); - - processCheck.setClosure(null); - processCheck.setInOutPuts(inOutPuts); - assertTrue(processCheck.run(mapInputs)); - - processCheck.setClosure(null); - processCheck.setInOutPuts(inOutPutsOpt); - assertTrue(processCheck.run(mapMissingInputs)); - - processCheck.setClosure(null); - processCheck.setInOutPuts(inOutPutsOpt); - assertTrue(processCheck.run(mapInvalidInputs)); - - - //Test that check with closure fail when required - IInOutPut[] inOutPutsNullProcess = new IInOutPut[]{ - new Input().process(PROCESS).name("in1").optional("a"), - new Input().name("in2").optional("b"), - new Input().process(PROCESS).name("in3").optional("c"), - new Output().process(PROCESS).name("out1")}; - - processCheck.setClosure(cl); - processCheck.setInOutPuts(inOutPutsNullProcess); - assertTrue(processCheck.run(mapInputs)); - - processCheck.setClosure(cl); - processCheck.setInOutPuts(noNameInOutPuts); - assertTrue(processCheck.run(mapInputs)); - - processCheck.setClosure(cl); - processCheck.setInOutPuts(noNameInOutPuts); - assertTrue(processCheck.run(null)); - - processCheck.setClosure(cl); - processCheck.setInOutPuts(inOutPuts); - assertTrue(processCheck.run(mapInvalidInputs)); - - String str2 = "{in1, in2, in3 -> return in1+in2+in3}"; - Closure badCl = (Closure) new GroovyShell().evaluate(new GroovyCodeSource(str2, "script", "")); - - processCheck.setClosure(badCl); - processCheck.setInOutPuts(inOutPuts); - assertTrue(processCheck.run(mapInputs)); - - String str3 = "{in1, in2, in3 -> return false}"; - Closure falseCl = (Closure) new GroovyShell().evaluate(new GroovyCodeSource(str3, "script", "")); - - processCheck.setClosure(falseCl); - processCheck.setInOutPuts(inOutPuts); - assertTrue(processCheck.run(mapInputs)); - - processCheck.setClosure(null); - processCheck.setInOutPuts( - new Input().process(PROCESS).name("in1").optional("a"), - new Input().process(PROCESS).name("in2").optional("b"), - new Input().process(PROCESS).name("in3").optional("c")); - assertFalse(processCheck.run(mapInputs)); - - processCheck.setClosure(cl); - processCheck.setInOutPuts( - new Input().process(PROCESS).name("in1"), - new Input().process(PROCESS).name("in2"), - new Input().process(PROCESS).name("in3")); - assertFalse(processCheck.run(mapInputs)); - - String str4 = "{out1 -> return out1== 'abc'}"; - Closure outCl = (Closure) new GroovyShell().evaluate(new GroovyCodeSource(str4, "script", "")); - - assertTrue(PROCESS.execute(mapInputs)); - processCheck.setClosure(outCl); - processCheck.setInOutPuts(new Output().process(PROCESS).name("out1")); - assertFalse(processCheck.run(mapInputs)); - } - - /** - * Test the {@link ProcessCheck#setProperty(String, Object)}, {@link ProcessCheck#getProperty(String)} methods. - */ - @Test - public void propertyTest() { - ProcessCheck processCheck = new ProcessCheck(PROCESS); - - assertDoesNotThrow(() -> processCheck.setProperty(null, "value")); - - processCheck.setProperty("inOutPuts", null); - Object obj = processCheck.getProperty("inOutPuts"); - assertFalse(obj instanceof Optional); - assertInstanceOf(LinkedList.class, obj); - assertTrue(((LinkedList) obj).isEmpty()); - - processCheck.setProperty("inOutPuts", new IInOutPut[]{new Input()}); - obj = processCheck.getProperty("inOutPuts"); - assertFalse(obj instanceof Optional); - assertInstanceOf(LinkedList.class, obj); - assertEquals(1, ((LinkedList)obj).size()); - - processCheck.setMetaClass(null); - processCheck.setProperty("inOutPuts", null); - obj = processCheck.getProperty("inOutPuts"); - assertInstanceOf(LinkedList.class, obj); - - processCheck.setMetaClass(InvokerHelper.getMetaClass(processCheck.getClass())); - obj = processCheck.getProperty("inOutPuts"); - assertNotNull(obj); - - processCheck.setProperty("metaClass", InvokerHelper.getMetaClass(getClass())); - obj = processCheck.getProperty("metaClass"); - assertNotNull(obj); - } - - /** - * Test the {@link ProcessCheck#invokeMethod(String, Object)} methods. - */ - @Test - public void invokeMethodTest() { - ProcessCheck processCheck = new ProcessCheck(PROCESS); - - assertNull(processCheck.invokeMethod(null, "value")); - assertNull(processCheck.invokeMethod(null, null)); - assertNull(processCheck.invokeMethod("setClosure", null)); - assertNull(processCheck.invokeMethod("getClosure", null)); - - String str = "{in1, in2, in3 -> return in1+in2+in3 == 'abc'}"; - Closure cl = (Closure) new GroovyShell().evaluate(new GroovyCodeSource(str, "script", "")); - - assertNull(processCheck.invokeMethod("setClosure", cl)); - assertNotNull(processCheck.invokeMethod("getClosure", null)); - - processCheck.setMetaClass(null); - assertNotNull(processCheck.getMetaClass()); - assertNull(processCheck.invokeMethod(null, "value")); - assertNull(processCheck.invokeMethod(null, null)); - assertNull(processCheck.invokeMethod("setClosure", null)); - assertNull(processCheck.invokeMethod("getClosure", null)); - assertNull(processCheck.invokeMethod("setClosure", cl)); - assertEquals(cl, processCheck.invokeMethod("getClosure", null)); - } - - /** - * Test the {@link ProcessCheck#toString()} method. - */ - @Test - public void toStringTest() { - String str = "{in1, in2, in3 -> return in1+in2+in3 == 'abc'}"; - Closure cl = (Closure) new GroovyShell().evaluate(new GroovyCodeSource(str, "script", "")); - - IInOutPut[] inOutPuts = new IInOutPut[]{ - new Input().process(PROCESS).name("in1").optional("a"), - new Input().process(PROCESS).name("in2"), - new Input().process(PROCESS).name("in3").optional("c"), - new Output().process(PROCESS).name("out1")}; - - ProcessCheck processCheck = new ProcessCheck(null); - processCheck.setClosure(null); - processCheck.setInOutPuts((IInOutPut[]) null); - assertEquals("No check can be run as there is no closure nor in/outputs set.", processCheck.toString()); - - processCheck = new ProcessCheck(null); - processCheck.setClosure(null); - processCheck.setInOutPuts(inOutPuts); - assertEquals("ProcessCheck : \n" + - "Check that inputs :\n" + - "\tin1\n" + - "\tin2\n" + - "\tin3\n" + - "are equals to provided data.", processCheck.toString()); - - processCheck = new ProcessCheck(null); - processCheck.setClosure(cl); - processCheck.setInOutPuts((IInOutPut[]) null); - assertEquals("ProcessCheck : \n" + - "Verifies a closure" - , processCheck.toString()); - - processCheck = new ProcessCheck(null); - processCheck.setClosure(cl); - processCheck.setInOutPuts(inOutPuts); - assertEquals("ProcessCheck : \n" + - "Check that inputs :\n" + - "\tin1\n" + - "\tin2\n" + - "\tin3\n" + - "Verifies a closure", processCheck.toString()); - - processCheck = new ProcessCheck(PROCESS); - assertTrue(processCheck.getProcess().isPresent()); - processCheck.setClosure(null); - processCheck.setInOutPuts((IInOutPut[]) null); - assertEquals("No check can be run as there is no closure nor in/outputs set.", processCheck.toString()); - - processCheck = new ProcessCheck(PROCESS); - processCheck.setClosure(null); - processCheck.setInOutPuts(inOutPuts); - assertEquals("ProcessCheck : \n" + - "On process :" + processCheck.getProcess().get().getIdentifier() + "\n" + - "Check that inputs :\n" + - "\tin1\n" + - "\tin2\n" + - "\tin3\n" + - "and output :\n" + - "\tout1\n" + - "are equals to provided data.", processCheck.toString()); - - processCheck = new ProcessCheck(PROCESS); - processCheck.setClosure(cl); - processCheck.setInOutPuts((IInOutPut[]) null); - assertEquals("ProcessCheck : \n" + - "On process :" + processCheck.getProcess().get().getIdentifier() + "\n" + - "Verifies a closure", processCheck.toString()); - - processCheck = new ProcessCheck(PROCESS); - processCheck.setClosure(cl); - processCheck.setInOutPuts(inOutPuts); - assertEquals("ProcessCheck : \n" + - "On process :" + processCheck.getProcess().get().getIdentifier() + "\n" + - "Check that inputs :\n" + - "\tin1\n" + - "\tin2\n" + - "\tin3\n" + - "and output :\n" + - "\tout1\n" + - "Verifies a closure", processCheck.toString()); - - - LinkedHashMap outputs = new LinkedHashMap<>(); - outputs.put("out1", new Output()); - - LinkedHashMap inputs = new LinkedHashMap<>(); - inputs.put("in1", new Input()); - inputs.put("in2", new Input()); - inputs.put("in3", new Input()); - IProcess namedProcess = ProcessManager.createFactory() - .create() - .title("namedProcess") - .outputs(outputs) - .inputs(inputs) - .run(cl) - .getProcess(); - - processCheck = new ProcessCheck(namedProcess); - assertTrue(processCheck.getProcess().isPresent()); - processCheck.setClosure(null); - processCheck.setInOutPuts((IInOutPut[]) null); - assertEquals("No check can be run as there is no closure nor in/outputs set.", processCheck.toString()); - - processCheck = new ProcessCheck(namedProcess); - processCheck.setClosure(null); - processCheck.setInOutPuts(inOutPuts); - assertEquals("ProcessCheck : \n" + - "On process :namedProcess\n" + - "Check that inputs :\n" + - "\tin1\n" + - "\tin2\n" + - "\tin3\n" + - "and output :\n" + - "\tout1\n" + - "are equals to provided data.", processCheck.toString()); - - processCheck = new ProcessCheck(namedProcess); - processCheck.setClosure(cl); - processCheck.setInOutPuts((IInOutPut[]) null); - assertEquals("ProcessCheck : \n" + - "On process :namedProcess\n" + - "Verifies a closure", processCheck.toString()); - - processCheck = new ProcessCheck(namedProcess); - processCheck.setClosure(cl); - processCheck.setInOutPuts(inOutPuts); - assertEquals("ProcessCheck : \n" + - "On process :namedProcess\n" + - "Check that inputs :\n" + - "\tin1\n" + - "\tin2\n" + - "\tin3\n" + - "and output :\n" + - "\tout1\n" + - "Verifies a closure", processCheck.toString()); - } -} diff --git a/process/src/test/java/org/orbisgis/process/inoutput/DummyInOutPut.java b/process/src/test/java/org/orbisgis/process/inoutput/DummyInOutPut.java deleted file mode 100644 index 8c1db6f6..00000000 --- a/process/src/test/java/org/orbisgis/process/inoutput/DummyInOutPut.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process.inoutput; - -import org.codehaus.groovy.runtime.InvokerHelper; -import org.orbisgis.process.api.inoutput.IInOutPut; - -/** - * Extension of the {@link InOutPut} class. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS Lab-STICC 2019-2020) - */ -public class DummyInOutPut extends InOutPut { - - private String notOptional; - - public DummyInOutPut() { - setMetaClass(InvokerHelper.getMetaClass(DummyInOutPut.class)); - } - - void setNotOptional(String s) { - notOptional = s; - } - - String getNotOptional() { - return notOptional; - } - - @Override - public IInOutPut copy() { - return null; - } -} diff --git a/process/src/test/java/org/orbisgis/process/inoutput/InOutPutTest.java b/process/src/test/java/org/orbisgis/process/inoutput/InOutPutTest.java deleted file mode 100644 index 152b5faf..00000000 --- a/process/src/test/java/org/orbisgis/process/inoutput/InOutPutTest.java +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process.inoutput; - -import groovy.lang.MetaClass; -import org.codehaus.groovy.runtime.InvokerHelper; -import org.junit.jupiter.api.Test; -import org.orbisgis.process.api.IProcess; -import org.orbisgis.process.ProcessManager; - -import static org.junit.jupiter.api.Assertions.*; - -/** - * Test class dedicated to {@link InOutPut} class. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS Lab-STICC 2020) - */ -public class InOutPutTest { - - /** - * Test the {@link InOutPut#setName(String)} and {@link InOutPut#getName()} method. - */ - @Test - void nameTest() { - DummyInOutPut dummyInOutPut = new DummyInOutPut(); - assertFalse(dummyInOutPut.getName().isPresent()); - assertInstanceOf(InOutPut.class, dummyInOutPut.name("name")); - assertTrue(dummyInOutPut.getName().isPresent()); - assertEquals("name", dummyInOutPut.getName().get()); - dummyInOutPut.setName(null); - assertFalse(dummyInOutPut.getName().isPresent()); - } - - /** - * Test the {@link InOutPut#setProcess(IProcess)} and {@link InOutPut#getProcess()} method. - */ - @Test - void processTest() { - IProcess process = ProcessManager.createFactory().create().getProcess(); - DummyInOutPut dummyInOutPut = new DummyInOutPut(); - assertFalse(dummyInOutPut.getProcess().isPresent()); - assertInstanceOf(InOutPut.class, dummyInOutPut.process(process)); - assertTrue(dummyInOutPut.getProcess().isPresent()); - assertEquals(process, dummyInOutPut.getProcess().get()); - dummyInOutPut.setProcess(null); - assertFalse(dummyInOutPut.getProcess().isPresent()); - } - - /** - * Test the {@link InOutPut#setTitle(String)} and {@link InOutPut#getTitle()} method. - */ - @Test - void titleTest() { - DummyInOutPut dummyInOutPut = new DummyInOutPut(); - assertFalse(dummyInOutPut.getTitle().isPresent()); - assertInstanceOf(InOutPut.class, dummyInOutPut.title("title")); - assertTrue(dummyInOutPut.getTitle().isPresent()); - assertEquals("title", dummyInOutPut.getTitle().get()); - dummyInOutPut.setTitle(null); - assertFalse(dummyInOutPut.getTitle().isPresent()); - } - - /** - * Test the {@link InOutPut#setDescription(String)} and {@link InOutPut#getDescription()} method. - */ - @Test - void descriptionTest() { - DummyInOutPut dummyInOutPut = new DummyInOutPut(); - assertFalse(dummyInOutPut.getDescription().isPresent()); - assertInstanceOf(InOutPut.class, dummyInOutPut.description("descr")); - assertTrue(dummyInOutPut.getDescription().isPresent()); - assertEquals("descr", dummyInOutPut.getDescription().get()); - dummyInOutPut.setDescription(null); - assertFalse(dummyInOutPut.getDescription().isPresent()); - } - - /** - * Test the {@link InOutPut#setKeywords(String[])} and {@link InOutPut#getKeywords()} method. - */ - @Test - void keywordsTest() { - DummyInOutPut dummyInOutPut = new DummyInOutPut(); - assertFalse(dummyInOutPut.getKeywords().isPresent()); - assertInstanceOf(InOutPut.class, dummyInOutPut.keywords(new String[]{"key1", "key2"})); - assertTrue(dummyInOutPut.getKeywords().isPresent()); - assertArrayEquals(new String[]{"key1", "key2"}, dummyInOutPut.getKeywords().get()); - dummyInOutPut.setKeywords(null); - assertFalse(dummyInOutPut.getKeywords().isPresent()); - } - - /** - * Test the {@link InOutPut#setType(Class)} and {@link InOutPut#getType()} method. - */ - @Test - void typeTest() { - DummyInOutPut dummyInOutPut = new DummyInOutPut(); - assertFalse(dummyInOutPut.getType().isPresent()); - assertInstanceOf(InOutPut.class, dummyInOutPut.type(Integer.class)); - assertTrue(dummyInOutPut.getType().isPresent()); - assertEquals(Integer.class, dummyInOutPut.getType().get()); - dummyInOutPut.setType(null); - assertFalse(dummyInOutPut.getType().isPresent()); - } - - /** - * Test the {@link InOutPut#toString()} method. - */ - @Test - void toStringTest() { - IProcess process = ProcessManager.createFactory().create().getProcess(); - DummyInOutPut dummyInOutPut = new DummyInOutPut(); - assertTrue(dummyInOutPut.toString().isEmpty()); - - dummyInOutPut.setName("name"); - assertEquals("name", dummyInOutPut.toString()); - - dummyInOutPut.setProcess(process); - assertEquals("name:" + process.getIdentifier(), dummyInOutPut.toString()); - - dummyInOutPut.setName(null); - assertEquals(":" + process.getIdentifier(), dummyInOutPut.toString()); - } - - /** - * Test the {@link InOutPut#setMetaClass(MetaClass)} and {@link InOutPut#getMetaClass()} methods. - */ - @Test - void metaClassTest() { - DummyInOutPut dummyInOutPut = new DummyInOutPut(); - assertEquals(InvokerHelper.getMetaClass(DummyInOutPut.class), dummyInOutPut.getMetaClass()); - dummyInOutPut.setMetaClass(null); - assertNotNull(dummyInOutPut.getMetaClass()); - dummyInOutPut.setMetaClass(InvokerHelper.getMetaClass(this.getClass())); - assertEquals(InvokerHelper.getMetaClass(this.getClass()), dummyInOutPut.getMetaClass()); - } - - /** - * Test the {@link InOutPut#setMetaClass(MetaClass)} and {@link InOutPut#getMetaClass()} methods. - */ - @Test - void propertyTest() { - DummyInOutPut dummyInOutPut = new DummyInOutPut(); - dummyInOutPut.setProperty(null, null); - dummyInOutPut.setName("toto"); - - assertNull(dummyInOutPut.getProperty(null)); - assertTrue(dummyInOutPut.getName().isPresent()); - assertEquals("toto", dummyInOutPut.getName().get()); - - dummyInOutPut.setProperty("name", null); - assertFalse(dummyInOutPut.getName().isPresent()); - - dummyInOutPut.setProperty("name", "tata"); - assertTrue(dummyInOutPut.getName().isPresent()); - assertEquals("tata", dummyInOutPut.getName().get()); - assertEquals("tata", dummyInOutPut.getProperty("name")); - - dummyInOutPut.setMetaClass(null); - dummyInOutPut.setProperty("name", "tata"); - assertNull(dummyInOutPut.getProperty(null)); - } - - /** - * Test the {@link InOutPut#invokeMethod(String, Object)} method. - */ - @Test - void invokeMethodTest() { - DummyInOutPut dummyInOutPut = new DummyInOutPut(); - dummyInOutPut.setName("name"); - - assertNull(dummyInOutPut.invokeMethod(null, null)); - assertEquals("name", dummyInOutPut.invokeMethod("getName", null)); - dummyInOutPut.setNotOptional("toto"); - assertEquals("toto", dummyInOutPut.invokeMethod("getNotOptional", null)); - } -} diff --git a/process/src/test/java/org/orbisgis/process/inoutput/InputTest.java b/process/src/test/java/org/orbisgis/process/inoutput/InputTest.java deleted file mode 100644 index 38d0152a..00000000 --- a/process/src/test/java/org/orbisgis/process/inoutput/InputTest.java +++ /dev/null @@ -1,259 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process.inoutput; - -import groovy.lang.MetaClass; -import org.codehaus.groovy.runtime.InvokerHelper; -import org.junit.jupiter.api.Test; -import org.orbisgis.process.api.IProcess; -import org.orbisgis.process.ProcessManager; - -import static org.junit.jupiter.api.Assertions.*; - -/** - * Test class dedicated to {@link Input} class. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS Lab-STICC 2020) - */ -public class InputTest { - - /** - * Test the {@link Input#setName(String)} and {@link Input#getName()} method. - */ - @Test - void nameTest() { - Input input = new Input(); - assertFalse(input.getName().isPresent()); - assertNotNull(input.name("name")); - assertTrue(input.getName().isPresent()); - assertEquals("name", input.getName().get()); - input.setName(null); - assertFalse(input.getName().isPresent()); - } - - /** - * Test the {@link Input#setProcess(IProcess)} and {@link Input#getProcess()} method. - */ - @Test - void processTest() { - IProcess process = ProcessManager.createFactory().create().getProcess(); - Input input = new Input(); - assertFalse(input.getProcess().isPresent()); - assertNotNull(input.process(process)); - assertTrue(input.getProcess().isPresent()); - assertEquals(process, input.getProcess().get()); - input.setProcess(null); - assertFalse(input.getProcess().isPresent()); - } - - /** - * Test the {@link Input#setTitle(String)} and {@link Input#getTitle()} method. - */ - @Test - void titleTest() { - Input input = new Input(); - assertFalse(input.getTitle().isPresent()); - assertNotNull(input.title("title")); - assertTrue(input.getTitle().isPresent()); - assertEquals("title", input.getTitle().get()); - input.setTitle(null); - assertFalse(input.getTitle().isPresent()); - } - - /** - * Test the {@link Input#setDescription(String)} and {@link Input#getDescription()} method. - */ - @Test - void descriptionTest() { - Input input = new Input(); - assertFalse(input.getDescription().isPresent()); - assertNotNull(input.description("descr")); - assertTrue(input.getDescription().isPresent()); - assertEquals("descr", input.getDescription().get()); - input.setDescription(null); - assertFalse(input.getDescription().isPresent()); - } - - /** - * Test the {@link Input#setKeywords(String[])} and {@link Input#getKeywords()} method. - */ - @Test - void keywordsTest() { - Input input = new Input(); - assertFalse(input.getKeywords().isPresent()); - assertNotNull(input.keywords(new String[]{"key1", "key2"})); - assertTrue(input.getKeywords().isPresent()); - assertArrayEquals(new String[]{"key1", "key2"}, input.getKeywords().get()); - input.setKeywords(null); - assertFalse(input.getKeywords().isPresent()); - } - - /** - * Test the {@link Input#setType(Class)} and {@link Input#getType()} method. - */ - @Test - void typeTest() { - Input input = new Input(); - assertFalse(input.getType().isPresent()); - assertNotNull(input.type(Integer.class)); - assertTrue(input.getType().isPresent()); - assertEquals(Integer.class, input.getType().get()); - input.setType(null); - assertFalse(input.getType().isPresent()); - } - - /** - * Test the {@link Input#toString()} method. - */ - @Test - void toStringTest() { - IProcess process = ProcessManager.createFactory().create().getProcess(); - Input input = new Input(); - assertTrue(input.toString().isEmpty()); - - input.setName("name"); - assertEquals("name", input.toString()); - - input.setProcess(process); - assertEquals("name:" + process.getIdentifier(), input.toString()); - - input.setName(null); - assertEquals(":" + process.getIdentifier(), input.toString()); - } - - /** - * Test the {@link Input#optional(Object)}, {@link Input#isOptional()}, {@link Input#getDefaultValue()} methods. - */ - @Test - void optionalTest() { - Input input = new Input(); - assertFalse(input.getDefaultValue().isPresent()); - assertFalse(input.isOptional()); - assertTrue(input.isMandatory()); - assertNotNull(input.optional("toto")); - assertTrue(input.getDefaultValue().isPresent()); - assertEquals("toto", input.getDefaultValue().get()); - assertTrue(input.isOptional()); - assertFalse(input.isMandatory()); - } - - /** - * Test the {@link Input#mandatory()} and {@link Input#isMandatory()} methods. - */ - @Test - void mandatoryTest() { - Input input = new Input(); - assertFalse(input.getDefaultValue().isPresent()); - assertFalse(input.isOptional()); - assertTrue(input.isMandatory()); - assertNotNull(input.mandatory()); - assertFalse(input.getDefaultValue().isPresent()); - assertFalse(input.isOptional()); - assertTrue(input.isMandatory()); - } - - /** - * Test the {@link InOutPut#setMetaClass(MetaClass)} and {@link InOutPut#getMetaClass()} methods. - */ - @Test - void metaClassTest(){ - Input input = new Input(); - assertEquals(InvokerHelper.getMetaClass(Input.class), input.getMetaClass()); - input.setMetaClass(null); - assertNotNull(input.getMetaClass()); - input.setMetaClass(InvokerHelper.getMetaClass(this.getClass())); - assertEquals(InvokerHelper.getMetaClass(this.getClass()), input.getMetaClass()); - } - - /** - * Test the {@link Input#equals(Object)} method. - */ - @Test - void equalsTest() { - IProcess p1 = ProcessManager.createFactory().create().getProcess(); - IProcess p2 = ProcessManager.createFactory().create().getProcess(); - Input in1 = new Input().name("toto").process(p1); - Input in2 = new Input().name("toto").process(p1); - Input in3 = new Input().name("toto").process(p2); - Input in4 = new Input().name("toto"); - Input in5 = new Input().name("tata").process(p1); - Input in6 = new Input(); - - assertEquals(in1, in2); - - assertNotEquals(in1, in3); - assertNotEquals(in1, in4); - assertNotEquals(in1, in5); - assertNotEquals(in1, in6); - assertNotEquals(in1, "in3"); - assertNotEquals(in1, null); - } - - /** - * Test the {@link Input#copy()} method. - */ - @Test - void copyTest() { - IProcess p1 = ProcessManager.createFactory().create().getProcess(); - IProcess p2 = ProcessManager.createFactory().create().getProcess(); - Input in1 = new Input().name("toto").process(p1); - Input in2 = new Input().name("toto").process(p1); - Input in3 = new Input().name("toto").process(p2); - Input in4 = new Input().name("toto"); - Input in5 = new Input().name("tata").process(p1); - Input in6 = new Input(); - - assertEquals(in1, in1.copy()); - assertNotSame(in1, in1.copy()); - - assertEquals(in2, in2.copy()); - assertNotSame(in2, in2.copy()); - - assertEquals(in3, in3.copy()); - assertNotSame(in3, in3.copy()); - - assertEquals(in4, in4.copy()); - assertNotSame(in4, in4.copy()); - - assertEquals(in5, in5.copy()); - assertNotSame(in5, in5.copy()); - - assertEquals(in6, in6.copy()); - assertNotSame(in6, in6.copy()); - } -} diff --git a/process/src/test/java/org/orbisgis/process/inoutput/OutputTest.java b/process/src/test/java/org/orbisgis/process/inoutput/OutputTest.java deleted file mode 100644 index 44f66067..00000000 --- a/process/src/test/java/org/orbisgis/process/inoutput/OutputTest.java +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Bundle Process is part of the OrbisGIS platform - * - * OrbisGIS is a java GIS application dedicated to research in GIScience. - * OrbisGIS is developed by the GIS group of the DECIDE team of the - * Lab-STICC CNRS laboratory, see . - * - * The GIS group of the DECIDE team is located at : - * - * Laboratoire Lab-STICC – CNRS UMR 6285 - * Equipe DECIDE - * UNIVERSITÉ DE BRETAGNE-SUD - * Institut Universitaire de Technologie de Vannes - * 8, Rue Montaigne - BP 561 56017 Vannes Cedex - * - * Process is distributed under LGPL 3 license. - * - * Copyright (C) 2018 CNRS (Lab-STICC UMR CNRS 6285) - * - * - * Process is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * Process is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * Process. If not, see . - * - * For more information, please consult: - * or contact directly: - * info_at_ orbisgis.org - */ -package org.orbisgis.process.inoutput; - -import groovy.lang.MetaClass; -import org.codehaus.groovy.runtime.InvokerHelper; -import org.junit.jupiter.api.Test; -import org.orbisgis.process.api.IProcess; -import org.orbisgis.process.ProcessManager; - -import static org.junit.jupiter.api.Assertions.*; - -/** - * Test class dedicated to {@link Output} class. - * - * @author Erwan Bocher (CNRS) - * @author Sylvain PALOMINOS (UBS Lab-STICC 2020) - */ -public class OutputTest { - - /** - * Test the {@link Output#setName(String)} and {@link Output#getName()} method. - */ - @Test - void nameTest() { - Output output = new Output(); - assertFalse(output.getName().isPresent()); - assertNotNull(output.name("name")); - assertTrue(output.getName().isPresent()); - assertEquals("name", output.getName().get()); - output.setName(null); - assertFalse(output.getName().isPresent()); - } - - /** - * Test the {@link Output#setProcess(IProcess)} and {@link Output#getProcess()} method. - */ - @Test - void processTest() { - IProcess process = ProcessManager.createFactory().create().getProcess(); - Output output = new Output(); - assertFalse(output.getProcess().isPresent()); - assertNotNull(output.process(process)); - assertTrue(output.getProcess().isPresent()); - assertEquals(process, output.getProcess().get()); - output.setProcess(null); - assertFalse(output.getProcess().isPresent()); - } - - /** - * Test the {@link Output#setTitle(String)} and {@link Output#getTitle()} method. - */ - @Test - void titleTest() { - Output output = new Output(); - assertFalse(output.getTitle().isPresent()); - assertNotNull(output.title("title")); - assertTrue(output.getTitle().isPresent()); - assertEquals("title", output.getTitle().get()); - output.setTitle(null); - assertFalse(output.getTitle().isPresent()); - } - - /** - * Test the {@link Output#setDescription(String)} and {@link Output#getDescription()} method. - */ - @Test - void descriptionTest() { - Output output = new Output(); - assertFalse(output.getDescription().isPresent()); - assertNotNull(output.description("descr")); - assertTrue(output.getDescription().isPresent()); - assertEquals("descr", output.getDescription().get()); - output.setDescription(null); - assertFalse(output.getDescription().isPresent()); - } - - /** - * Test the {@link Output#setKeywords(String[])} and {@link Output#getKeywords()} method. - */ - @Test - void keywordsTest() { - Output output = new Output(); - assertFalse(output.getKeywords().isPresent()); - assertNotNull(output.keywords(new String[]{"key1", "key2"})); - assertTrue(output.getKeywords().isPresent()); - assertArrayEquals(new String[]{"key1", "key2"}, output.getKeywords().get()); - output.setKeywords(null); - assertFalse(output.getKeywords().isPresent()); - } - - /** - * Test the {@link Output#setType(Class)} and {@link Output#getType()} method. - */ - @Test - void typeTest() { - Output output = new Output(); - assertFalse(output.getType().isPresent()); - assertNotNull(output.type(Integer.class)); - assertTrue(output.getType().isPresent()); - assertEquals(Integer.class, output.getType().get()); - output.setType(null); - assertFalse(output.getType().isPresent()); - } - - /** - * Test the {@link Output#toString()} method. - */ - @Test - void toStringTest() { - IProcess process = ProcessManager.createFactory().create().getProcess(); - Output output = new Output(); - assertTrue(output.toString().isEmpty()); - - output.setName("name"); - assertEquals("name", output.toString()); - - output.setProcess(process); - assertEquals("name:" + process.getIdentifier(), output.toString()); - - output.setName(null); - assertEquals(":" + process.getIdentifier(), output.toString()); - } - - /** - * Test the {@link InOutPut#setMetaClass(MetaClass)} and {@link InOutPut#getMetaClass()} methods. - */ - @Test - void metaClassTest(){ - Output output = new Output(); - assertEquals(InvokerHelper.getMetaClass(Output.class), output.getMetaClass()); - output.setMetaClass(null); - assertNotNull(output.getMetaClass()); - output.setMetaClass(InvokerHelper.getMetaClass(this.getClass())); - assertEquals(InvokerHelper.getMetaClass(this.getClass()), output.getMetaClass()); - } - - /** - * Test the {@link Output#equals(Object)} method. - */ - @Test - void equalsTest() { - IProcess p1 = ProcessManager.createFactory().create().getProcess(); - IProcess p2 = ProcessManager.createFactory().create().getProcess(); - Output out1 = new Output().name("toto").process(p1); - Output out2 = new Output().name("toto").process(p1); - Output out3 = new Output().name("toto").process(p2); - Output out4 = new Output().name("toto"); - Output out5 = new Output().name("tata").process(p1); - Output out6 = new Output(); - - assertEquals(out1, out2); - - assertNotEquals(out1, out3); - assertNotEquals(out1, out4); - assertNotEquals(out1, out5); - assertNotEquals(out1, out6); - assertNotEquals(out1, "out3"); - assertNotEquals(out1, null); - } - - /** - * Test the {@link Output#copy()} method. - */ - @Test - void copyTest() { - IProcess p1 = ProcessManager.createFactory().create().getProcess(); - IProcess p2 = ProcessManager.createFactory().create().getProcess(); - Output out1 = new Output().name("toto").process(p1); - Output out2 = new Output().name("toto").process(p1); - Output out3 = new Output().name("toto").process(p2); - Output out4 = new Output().name("toto"); - Output out5 = new Output().name("tata").process(p1); - Output out6 = new Output(); - - assertEquals(out1, out1.copy()); - assertNotSame(out1, out1.copy()); - - assertEquals(out2, out2.copy()); - assertNotSame(out2, out2.copy()); - - assertEquals(out3, out3.copy()); - assertNotSame(out3, out3.copy()); - - assertEquals(out4, out4.copy()); - assertNotSame(out4, out4.copy()); - - assertEquals(out5, out5.copy()); - assertNotSame(out5, out5.copy()); - - assertEquals(out6, out6.copy()); - assertNotSame(out6, out6.copy()); - } -}