mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-29 15:21:53 +00:00
Compare commits
65 Commits
17.58
...
fix/admin-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
53ecbaa74f | ||
|
|
bc5aabbf37 | ||
|
|
501d9204a9 | ||
|
|
924005e94e | ||
|
|
3a34c42d2f | ||
|
|
332af85227 | ||
|
|
556c13eba0 | ||
|
|
3caf6bf9f3 | ||
|
|
b5fcc5370a | ||
|
|
29007871e8 | ||
|
|
12df503cc2 | ||
|
|
e3a9e9c034 | ||
|
|
d116cf397b | ||
|
|
271c123a00 | ||
|
|
5bae1ca9b6 | ||
|
|
f84c82c6a2 | ||
|
|
c639eec1df | ||
|
|
d2e561dc95 | ||
|
|
54347fbbee | ||
|
|
ab0d482179 | ||
|
|
5fed5292d9 | ||
|
|
1e8944a310 | ||
|
|
b97b6751cc | ||
|
|
af97aca661 | ||
|
|
368acf4724 | ||
|
|
2341f0290e | ||
|
|
2e4f5d5726 | ||
|
|
be118c25ba | ||
|
|
601b743388 | ||
|
|
3c3c3b2666 | ||
|
|
b671e17f03 | ||
|
|
a08b134ec2 | ||
|
|
9795349f9b | ||
|
|
f120ba3a87 | ||
|
|
2285dc1ecb | ||
|
|
cbded8f967 | ||
|
|
5e3ee41fce | ||
|
|
6c9163ce65 | ||
|
|
8a79d3bed1 | ||
|
|
f1c588f1da | ||
|
|
f38902ede9 | ||
|
|
5f1cf5ef60 | ||
|
|
2a41c1f14a | ||
|
|
4f0cbd7206 | ||
|
|
0823d5319c | ||
|
|
001e7a4bff | ||
|
|
aba89218e6 | ||
|
|
e533af4ecb | ||
|
|
4a7046211b | ||
|
|
48e902c556 | ||
|
|
e178428624 | ||
|
|
7b4f7c9174 | ||
|
|
d84424ee5b | ||
|
|
a4ad5f9211 | ||
|
|
9fbdc61d3c | ||
|
|
7db6d372da | ||
|
|
c334f14cd2 | ||
|
|
d584b3c1a3 | ||
|
|
b06a74c5cb | ||
|
|
5b723e9176 | ||
|
|
bf69340e4b | ||
|
|
b6aeac0c4e | ||
|
|
c1da01ba6e | ||
|
|
ecb0d9a329 | ||
|
|
c3189adf9f |
7
.github/dependabot.yml
vendored
7
.github/dependabot.yml
vendored
@@ -159,9 +159,8 @@ updates:
|
||||
registries:
|
||||
- maven-repository-artifacts-alfresco-com-nexus-content-groups-int
|
||||
- package-ecosystem: "docker"
|
||||
directory: "packaging/docker-alfresco/"
|
||||
schedule:
|
||||
directory: "packaging/docker-alfresco/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
time: "22:00"
|
||||
timezone: "Europe/London"
|
||||
open-pull-requests-limit: 99
|
||||
timezone: Africa/Abidjan
|
||||
|
||||
682
.travis.yml
682
.travis.yml
@@ -1,7 +1,7 @@
|
||||
---
|
||||
dist: focal
|
||||
language: java
|
||||
jdk: openjdk11
|
||||
jdk: openjdk17
|
||||
|
||||
services:
|
||||
- docker
|
||||
@@ -51,346 +51,346 @@ jobs:
|
||||
install: skip
|
||||
script: travis_retry travis_wait 80 bash scripts/travis/prepare.sh
|
||||
|
||||
- name: "Source Clear Scan (SCA)"
|
||||
stage: test
|
||||
if: branch = master OR branch =~ /release\/.*/
|
||||
# Run Veracode
|
||||
install: skip
|
||||
script: travis_wait 30 bash scripts/travis/source_clear.sh
|
||||
|
||||
- name: "Core, Data-Model, Repository - AllUnitTestsSuite - Build and test"
|
||||
if: commit_message !~ /\[skip repo\]/
|
||||
install: skip
|
||||
script:
|
||||
- travis_retry mvn -B test -pl core,data-model -am -DfailIfNoTests=false
|
||||
- travis_retry mvn -B test -pl "repository,mmt" -am "-Dtest=AllUnitTestsSuite,AllMmtUnitTestSuite" -DfailIfNoTests=false
|
||||
|
||||
- name: "Repository - AppContext01TestSuite"
|
||||
if: commit_message !~ /\[skip repo\]/
|
||||
install: skip
|
||||
before_script:
|
||||
- docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:14.4 postgres -c 'max_connections=300'
|
||||
- docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
- docker run -d -p 8090:8090 -e JAVA_OPTS=" -Xms256m -Xmx256m" alfresco/alfresco-transform-core-aio:${TRANSFORMERS_TAG}
|
||||
script: travis_wait 20 mvn -B test -pl repository -am -Dtest=AppContext01TestSuite -DfailIfNoTests=false -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
|
||||
|
||||
- name: "Repository - AppContext02TestSuite"
|
||||
if: commit_message !~ /\[skip repo\]/
|
||||
install: skip
|
||||
before_script:
|
||||
- docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:14.4 postgres -c 'max_connections=300'
|
||||
- docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
script: travis_wait 20 mvn -B test -pl repository -am -Dtest=AppContext02TestSuite -DfailIfNoTests=false -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
|
||||
|
||||
- name: "Repository - AppContext03TestSuite"
|
||||
if: commit_message !~ /\[skip repo\]/
|
||||
install: skip
|
||||
before_script:
|
||||
- docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:14.4 postgres -c 'max_connections=300'
|
||||
- docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
- docker run -d -p 8090:8090 -e JAVA_OPTS=" -Xms256m -Xmx256m" alfresco/alfresco-transform-core-aio:${TRANSFORMERS_TAG}
|
||||
script: travis_wait 20 mvn -B test -pl repository -am -Dtest=AppContext03TestSuite -DfailIfNoTests=false -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
|
||||
|
||||
- name: "Repository - AppContext04TestSuite"
|
||||
if: commit_message !~ /\[skip repo\]/
|
||||
install: skip
|
||||
before_script:
|
||||
- docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:14.4 postgres -c 'max_connections=300'
|
||||
- docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
- docker run -d -p 8090:8090 -e JAVA_OPTS=" -Xms256m -Xmx256m" alfresco/alfresco-transform-core-aio:${TRANSFORMERS_TAG}
|
||||
script: travis_wait 20 mvn -B test -pl repository -am -Dtest=AppContext04TestSuite -DfailIfNoTests=false -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
|
||||
|
||||
- name: "Repository - AppContext05TestSuite"
|
||||
if: commit_message !~ /\[skip repo\]/
|
||||
install: skip
|
||||
before_script:
|
||||
- docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:14.4 postgres -c 'max_connections=300'
|
||||
- docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
- mkdir -p "${HOME}/tmp"
|
||||
- cp repository/src/test/resources/realms/alfresco-realm.json "${HOME}/tmp"
|
||||
- export HOST_IP=$(hostname -I | cut -f1 -d' ')
|
||||
- docker run -d -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin -e DB_VENDOR=h2 -p 8999:8080 -e KEYCLOAK_IMPORT=/tmp/alfresco-realm.json -v $HOME/tmp/alfresco-realm.json:/tmp/alfresco-realm.json alfresco/alfresco-identity-service:1.2
|
||||
script: travis_wait 20 mvn -B test -pl repository -am -Dtest=AppContext05TestSuite -DfailIfNoTests=false -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco "-Didentity-service.auth-server-url=http://${HOST_IP}:8999/auth"
|
||||
|
||||
- name: "Repository - AppContext06TestSuite"
|
||||
if: commit_message !~ /\[skip repo\]/
|
||||
install: skip
|
||||
before_script:
|
||||
- docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:14.4 postgres -c 'max_connections=300'
|
||||
- docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
- docker run -d -p 8090:8090 -e JAVA_OPTS=" -Xms256m -Xmx256m" alfresco/alfresco-transform-core-aio:${TRANSFORMERS_TAG}
|
||||
script: travis_wait 20 mvn -B test -pl repository -am -Dtest=AppContext06TestSuite -DfailIfNoTests=false -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
|
||||
|
||||
- name: "Repository - AppContextExtraTestSuite"
|
||||
if: commit_message !~ /\[skip repo\]/
|
||||
install: skip
|
||||
before_script:
|
||||
- docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:14.4 postgres -c 'max_connections=300'
|
||||
- docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
- docker run -d -p 8090:8090 -e JAVA_OPTS=" -Xms256m -Xmx256m" alfresco/alfresco-transform-core-aio:${TRANSFORMERS_TAG}
|
||||
script: travis_wait 20 mvn -B test -pl repository -am -Dtest=AppContextExtraTestSuite -DfailIfNoTests=false -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
|
||||
|
||||
- name: "Repository - MiscContextTestSuite"
|
||||
if: commit_message !~ /\[skip repo\]/
|
||||
install: skip
|
||||
before_script:
|
||||
- docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:14.4 postgres -c 'max_connections=300'
|
||||
- docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
- docker run -d -p 8090:8090 -e JAVA_OPTS=" -Xms256m -Xmx256m" alfresco/alfresco-transform-core-aio:${TRANSFORMERS_TAG}
|
||||
script: travis_wait 20 mvn -B test -pl repository -am -Dtest=MiscContextTestSuite -DfailIfNoTests=false -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
|
||||
|
||||
- name: "Repository - SearchTestSuite"
|
||||
if: commit_message !~ /\[skip repo\]/
|
||||
install: skip
|
||||
before_script:
|
||||
- docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:14.4 postgres -c 'max_connections=300'
|
||||
- docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
script: travis_wait 20 mvn -B test -pl repository -am -Dtest=SearchTestSuite -DfailIfNoTests=false -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco -Dindex.subsystem.name=solr6
|
||||
|
||||
- name: "Repository - MariaDB 10.2.18 tests"
|
||||
if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip db\]/ AND type != pull_request) OR commit_message =~ /\[db\]/
|
||||
install: skip
|
||||
before_script:
|
||||
- docker run -d -p 3307:3306 --name mariadb -e MYSQL_ROOT_PASSWORD=alfresco -e MYSQL_USER=alfresco -e MYSQL_DATABASE=alfresco -e MYSQL_PASSWORD=alfresco mariadb:10.2.18 --transaction-isolation=READ-COMMITTED --max-connections=300 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
|
||||
- docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
script: travis_wait 20 mvn -B test -pl repository -am -Dtest=AllDBTestsTestSuite -DfailIfNoTests=false -Ddb.name=alfresco -Ddb.url=jdbc:mariadb://localhost:3307/alfresco?useUnicode=yes\&characterEncoding=UTF-8 -Ddb.username=alfresco -Ddb.password=alfresco -Ddb.driver=org.mariadb.jdbc.Driver
|
||||
|
||||
- name: "Repository - MariaDB 10.4 tests"
|
||||
if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip db\]/ AND type != pull_request) OR commit_message =~ /\[db\]/
|
||||
install: skip
|
||||
before_script:
|
||||
- docker run -d -p 3307:3306 --name mariadb -e MYSQL_ROOT_PASSWORD=alfresco -e MYSQL_USER=alfresco -e MYSQL_DATABASE=alfresco -e MYSQL_PASSWORD=alfresco mariadb:10.4 --transaction-isolation=READ-COMMITTED --max-connections=300 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
|
||||
- docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
script: travis_wait 20 mvn -B test -pl repository -am -Dtest=AllDBTestsTestSuite -DfailIfNoTests=false -Ddb.name=alfresco -Ddb.url=jdbc:mariadb://localhost:3307/alfresco?useUnicode=yes\&characterEncoding=UTF-8 -Ddb.username=alfresco -Ddb.password=alfresco -Ddb.driver=org.mariadb.jdbc.Driver
|
||||
|
||||
- name: "Repository - MariaDB 10.5 tests"
|
||||
if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip db\]/ AND type != pull_request) OR commit_message =~ /\[db\]/
|
||||
install: skip
|
||||
before_script:
|
||||
- docker run -d -p 3307:3306 --name mariadb -e MYSQL_ROOT_PASSWORD=alfresco -e MYSQL_USER=alfresco -e MYSQL_DATABASE=alfresco -e MYSQL_PASSWORD=alfresco mariadb:10.5 --transaction-isolation=READ-COMMITTED --max-connections=300 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
|
||||
- docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
script: travis_wait 20 mvn -B test -pl repository -am -Dtest=AllDBTestsTestSuite -DfailIfNoTests=false -Ddb.name=alfresco -Ddb.url=jdbc:mariadb://localhost:3307/alfresco?useUnicode=yes\&characterEncoding=UTF-8 -Ddb.username=alfresco -Ddb.password=alfresco -Ddb.driver=org.mariadb.jdbc.Driver
|
||||
|
||||
- name: "Repository - MariaDB 10.6 tests"
|
||||
# We run tests on the latest version of MariaDB on pull requests plus the normal master and release branches - ignored on feature branches
|
||||
if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip db\]/ ) OR commit_message =~ /\[db\]/ OR commit_message =~ /\[latest db\]/
|
||||
install: skip
|
||||
before_script:
|
||||
- docker run -d -p 3307:3306 --name mariadb -e MYSQL_ROOT_PASSWORD=alfresco -e MYSQL_USER=alfresco -e MYSQL_DATABASE=alfresco -e MYSQL_PASSWORD=alfresco mariadb:10.6 --transaction-isolation=READ-COMMITTED --max-connections=300 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
|
||||
- docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
script: travis_wait 20 mvn -B test -pl repository -am -Dtest=AllDBTestsTestSuite -DfailIfNoTests=false -Ddb.name=alfresco -Ddb.url=jdbc:mariadb://localhost:3307/alfresco?useUnicode=yes\&characterEncoding=UTF-8 -Ddb.username=alfresco -Ddb.password=alfresco -Ddb.driver=org.mariadb.jdbc.Driver
|
||||
|
||||
- name: "Repository - MySQL 8 tests"
|
||||
# We run tests on the latest version of MySQL on pull requests plus the normal master and release branches - ignored on feature branches
|
||||
if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip db\]/ ) OR commit_message =~ /\[db\]/ OR commit_message =~ /\[latest db\]/
|
||||
install: skip
|
||||
before_script:
|
||||
- docker run -d -p 3307:3306 -e MYSQL_ROOT_PASSWORD=alfresco -e MYSQL_USER=alfresco -e MYSQL_DATABASE=alfresco -e MYSQL_PASSWORD=alfresco mysql:8 --transaction-isolation='READ-COMMITTED'
|
||||
- docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
script: travis_wait 20 mvn -B test -pl repository -am -Dtest=AllDBTestsTestSuite -DfailIfNoTests=false -Ddb.driver=com.mysql.jdbc.Driver -Ddb.name=alfresco -Ddb.url=jdbc:mysql://localhost:3307/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
|
||||
|
||||
- name: "Repository - PostgreSQL 13.7 tests"
|
||||
if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip db\]/ AND type != pull_request) OR commit_message =~ /\[db\]/
|
||||
install: skip
|
||||
before_script:
|
||||
- docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:13.7 postgres -c 'max_connections=300'
|
||||
- docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
script: travis_wait 20 mvn -B test -pl repository -am -Dtest=AllDBTestsTestSuite -DfailIfNoTests=false -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
|
||||
|
||||
- name: "Repository - PostgreSQL 14.4 tests"
|
||||
# We only run DB tests on the latest version of PostgreSQL on feature branches
|
||||
if: commit_message !~ /\[skip db\]/ OR commit_message =~ /\[db\]/ OR commit_message =~ /\[latest db\]/
|
||||
install: skip
|
||||
before_script:
|
||||
- docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:14.4 postgres -c 'max_connections=300'
|
||||
- docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
script: travis_wait 20 mvn -B test -pl repository -am -Dtest=AllDBTestsTestSuite -DfailIfNoTests=false -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
|
||||
|
||||
- name: "Repository - Messaging tests"
|
||||
if: commit_message !~ /\[skip repo\]/
|
||||
install: skip
|
||||
before_script:
|
||||
- docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
script: travis_wait 20 mvn -B test -pl repository -am -Dtest=CamelRoutesTest,CamelComponentsTest -DfailIfNoTests=false
|
||||
|
||||
- name: "Remote-api - AppContext01TestSuite"
|
||||
if: commit_message !~ /\[skip repo\]/
|
||||
install: travis_retry travis_wait 40 env REQUIRES_INSTALLED_ARTIFACTS=true bash scripts/travis/build.sh
|
||||
before_script:
|
||||
- docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:14.4 postgres -c 'max_connections=300'
|
||||
- docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
script: travis_wait 20 mvn -B test -pl remote-api -Dtest=AppContext01TestSuite -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
|
||||
|
||||
- name: "Remote-api - AppContext02TestSuite"
|
||||
if: commit_message !~ /\[skip repo\]/
|
||||
install: travis_retry travis_wait 40 env REQUIRES_INSTALLED_ARTIFACTS=true bash scripts/travis/build.sh
|
||||
before_script:
|
||||
- docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:14.4 postgres -c 'max_connections=300'
|
||||
- docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
- docker run -d -p 8090:8090 -e JAVA_OPTS=" -Xms256m -Xmx256m" alfresco/alfresco-transform-core-aio:${TRANSFORMERS_TAG}
|
||||
script: travis_wait 20 mvn -B test -pl remote-api -Dtest=AppContext02TestSuite -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
|
||||
|
||||
- name: "Remote-api - AppContext03TestSuite"
|
||||
if: commit_message !~ /\[skip repo\]/
|
||||
install: travis_retry travis_wait 40 env REQUIRES_INSTALLED_ARTIFACTS=true bash scripts/travis/build.sh
|
||||
before_script:
|
||||
- docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:14.4 postgres -c 'max_connections=300'
|
||||
- docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
- docker run -d -p 8090:8090 -e JAVA_OPTS=" -Xms256m -Xmx256m" alfresco/alfresco-transform-core-aio:${TRANSFORMERS_TAG}
|
||||
script: travis_wait 20 mvn -B test -pl remote-api -Dtest=AppContext03TestSuite -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
|
||||
|
||||
- name: "Remote-api - AppContext04TestSuite"
|
||||
if: commit_message !~ /\[skip repo\]/
|
||||
install: travis_retry travis_wait 40 env REQUIRES_INSTALLED_ARTIFACTS=true bash scripts/travis/build.sh
|
||||
before_script:
|
||||
- docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:14.4 postgres -c 'max_connections=300'
|
||||
- docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
- docker run -d -p 8090:8090 -e JAVA_OPTS=" -Xms256m -Xmx256m" alfresco/alfresco-transform-core-aio:${TRANSFORMERS_TAG}
|
||||
script: travis_wait 20 mvn -B test -pl remote-api -Dtest=AppContext04TestSuite -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
|
||||
|
||||
- name: "Remote-api - AppContextExtraTestSuite"
|
||||
if: commit_message !~ /\[skip repo\]/
|
||||
install: travis_retry travis_wait 40 env REQUIRES_INSTALLED_ARTIFACTS=true bash scripts/travis/build.sh
|
||||
before_script:
|
||||
- docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:14.4 postgres -c 'max_connections=300'
|
||||
- docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
script: travis_wait 20 mvn -B test -pl remote-api -Dtest=AppContextExtraTestSuite -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
|
||||
|
||||
- name: "REST API TAS tests part1"
|
||||
# TAS tests are generally skipped on feature branches as they will be repeated on the enterprise repo or community packaging builds
|
||||
if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip tas\]/) OR commit_message =~ /\[tas\]/
|
||||
install: travis_retry travis_wait 40 env REQUIRES_LOCAL_IMAGES=true bash scripts/travis/build.sh
|
||||
before_script:
|
||||
- ${TAS_SCRIPTS}/start-compose.sh ${TAS_ENVIRONMENT}/docker-compose-minimal+transforms.yml
|
||||
- ${TAS_SCRIPTS}/wait-for-alfresco-start.sh "http://localhost:8082/alfresco"
|
||||
script: travis_wait 60 mvn -B verify -f packaging/tests/tas-restapi/pom.xml -Pall-tas-tests,run-restapi-part1 -Denvironment=default -DrunBugs=false
|
||||
|
||||
- name: "REST API TAS tests part2"
|
||||
if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip tas\]/) OR commit_message =~ /\[tas\]/
|
||||
install: travis_retry travis_wait 40 env REQUIRES_LOCAL_IMAGES=true bash scripts/travis/build.sh
|
||||
before_script:
|
||||
- ${TAS_SCRIPTS}/start-compose.sh ${TAS_ENVIRONMENT}/docker-compose-minimal+transforms.yml
|
||||
- ${TAS_SCRIPTS}/wait-for-alfresco-start.sh "http://localhost:8082/alfresco"
|
||||
script: travis_wait 60 mvn -B verify -f packaging/tests/tas-restapi/pom.xml -Pall-tas-tests,run-restapi-part2 -Denvironment=default -DrunBugs=false
|
||||
|
||||
- name: "REST API TAS tests part3"
|
||||
if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip tas\]/) OR commit_message =~ /\[tas\]/
|
||||
install: travis_retry travis_wait 40 env REQUIRES_LOCAL_IMAGES=true bash scripts/travis/build.sh
|
||||
before_script:
|
||||
- ${TAS_SCRIPTS}/start-compose.sh ${TAS_ENVIRONMENT}/docker-compose-minimal+transforms.yml
|
||||
- ${TAS_SCRIPTS}/wait-for-alfresco-start.sh "http://localhost:8082/alfresco"
|
||||
script: travis_wait 60 mvn -B verify -f packaging/tests/tas-restapi/pom.xml -Pall-tas-tests,run-restapi-part3 -Denvironment=default -DrunBugs=false
|
||||
|
||||
- name: "CMIS TAS tests - BROWSER binding"
|
||||
if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip tas\]/) OR commit_message =~ /\[tas\]/
|
||||
install: travis_retry travis_wait 40 env REQUIRES_LOCAL_IMAGES=true bash scripts/travis/build.sh
|
||||
before_script:
|
||||
- ${TAS_SCRIPTS}/start-compose.sh ${TAS_ENVIRONMENT}/docker-compose-minimal+transforms.yml
|
||||
- ${TAS_SCRIPTS}/wait-for-alfresco-start.sh "http://localhost:8082/alfresco"
|
||||
script: travis_wait 40 mvn -B verify -f packaging/tests/tas-cmis/pom.xml -Pall-tas-tests,run-cmis-browser -Denvironment=default -DrunBugs=false
|
||||
|
||||
- name: "CMIS TAS tests - ATOM binding"
|
||||
if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip tas\]/) OR commit_message =~ /\[tas\]/
|
||||
install: travis_retry travis_wait 40 env REQUIRES_LOCAL_IMAGES=true bash scripts/travis/build.sh
|
||||
before_script:
|
||||
- ${TAS_SCRIPTS}/start-compose.sh ${TAS_ENVIRONMENT}/docker-compose-minimal+transforms.yml
|
||||
- ${TAS_SCRIPTS}/wait-for-alfresco-start.sh "http://localhost:8082/alfresco"
|
||||
script: travis_wait 40 mvn -B verify -f packaging/tests/tas-cmis/pom.xml -Pall-tas-tests,run-cmis-atom -Denvironment=default -DrunBugs=false
|
||||
|
||||
- name: "CMIS TAS tests - WEBSERVICES binding"
|
||||
if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip tas\]/) OR commit_message =~ /\[tas\]/
|
||||
install: travis_retry travis_wait 40 env REQUIRES_LOCAL_IMAGES=true bash scripts/travis/build.sh
|
||||
before_script:
|
||||
- ${TAS_SCRIPTS}/start-compose.sh ${TAS_ENVIRONMENT}/docker-compose-minimal+transforms.yml
|
||||
- ${TAS_SCRIPTS}/wait-for-alfresco-start.sh "http://localhost:8082/alfresco"
|
||||
script: travis_wait 40 mvn -B verify -f packaging/tests/tas-cmis/pom.xml -Pall-tas-tests,run-cmis-webservices -Denvironment=default -DrunBugs=false
|
||||
|
||||
- name: "Email TAS tests"
|
||||
if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip tas\]/) OR commit_message =~ /\[tas\]/
|
||||
install: travis_retry travis_wait 40 env REQUIRES_LOCAL_IMAGES=true bash scripts/travis/build.sh
|
||||
before_script:
|
||||
- ${TAS_SCRIPTS}/start-compose.sh ${TAS_ENVIRONMENT}/docker-compose-minimal.yml
|
||||
- ${TAS_SCRIPTS}/wait-for-alfresco-start.sh "http://localhost:8082/alfresco"
|
||||
script: travis_wait 30 mvn -B verify -f packaging/tests/tas-email/pom.xml -Pall-tas-tests -Denvironment=default -DrunBugs=false
|
||||
|
||||
- name: "WebDAV TAS tests"
|
||||
if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip tas\]/) OR commit_message =~ /\[tas\]/
|
||||
install: travis_retry travis_wait 40 env REQUIRES_LOCAL_IMAGES=true bash scripts/travis/build.sh
|
||||
before_script:
|
||||
- ${TAS_SCRIPTS}/start-compose.sh ${TAS_ENVIRONMENT}/docker-compose-minimal.yml
|
||||
- ${TAS_SCRIPTS}/wait-for-alfresco-start.sh "http://localhost:8082/alfresco"
|
||||
script: travis_wait 30 mvn -B verify -f packaging/tests/tas-webdav/pom.xml -Pall-tas-tests -Denvironment=default -DrunBugs=false
|
||||
|
||||
- name: "Integration TAS tests"
|
||||
if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip tas\]/) OR commit_message =~ /\[tas\]/
|
||||
install: travis_retry travis_wait 40 env REQUIRES_LOCAL_IMAGES=true bash scripts/travis/build.sh
|
||||
before_script:
|
||||
- ${TAS_SCRIPTS}/start-compose.sh ${TAS_ENVIRONMENT}/docker-compose-minimal.yml
|
||||
- ${TAS_SCRIPTS}/wait-for-alfresco-start.sh "http://localhost:8082/alfresco"
|
||||
script: travis_wait 30 mvn -B verify -f packaging/tests/tas-integration/pom.xml -Pall-tas-tests -Denvironment=default -DrunBugs=false
|
||||
|
||||
- name: "Share Services - ShareServicesTestSuite"
|
||||
if: commit_message !~ /\[skip repo\]/
|
||||
install: skip
|
||||
before_script:
|
||||
- docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:14.4 postgres -c 'max_connections=300'
|
||||
script: travis_wait 20 mvn -B test -pl :alfresco-share-services -am -Dtest=ShareServicesTestSuite -DfailIfNoTests=false -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
|
||||
|
||||
- name: "AGS Unit & Integration Tests 01 (PostgreSQL)"
|
||||
if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip ags\]/) OR commit_message =~ /\[ags\]/
|
||||
install: travis_retry travis_wait 40 env REQUIRES_INSTALLED_ARTIFACTS=true bash scripts/travis/build.sh
|
||||
script: travis_retry travis_wait 80 mvn -B verify -Dmaven.javadoc.skip=true -Dmaven.source.skip=true -Pags -Pstart-postgres -PagsAllTestSuitePt1 -f amps/ags/pom.xml ${LOG_WARN}
|
||||
|
||||
- name: "AGS Integration Tests 02 (PostgreSQL)"
|
||||
if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip ags\]/) OR commit_message =~ /\[ags\]/
|
||||
install: travis_retry travis_wait 40 env REQUIRES_INSTALLED_ARTIFACTS=true bash scripts/travis/build.sh
|
||||
script: travis_retry travis_wait 80 mvn -B verify -Dmaven.javadoc.skip=true -Dmaven.source.skip=true -Pags -Pstart-postgres -PagsAllTestSuitePt2 -f amps/ags/pom.xml ${LOG_WARN}
|
||||
|
||||
- name: "AGS Integration Tests 03 (PostgreSQL)"
|
||||
if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip ags\]/) OR commit_message =~ /\[ags\]/
|
||||
install: travis_retry travis_wait 40 env REQUIRES_INSTALLED_ARTIFACTS=true bash scripts/travis/build.sh
|
||||
script: travis_retry travis_wait 80 mvn -B verify -Dmaven.javadoc.skip=true -Dmaven.source.skip=true -Pags -Pstart-postgres -PagsAllTestSuitePt3 -f amps/ags/pom.xml ${LOG_WARN}
|
||||
|
||||
- name: "AGS Unit & Integration Tests 04 (PostgreSQL)"
|
||||
if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip ags\]/) OR commit_message =~ /\[ags\]/
|
||||
install: travis_retry travis_wait 40 env REQUIRES_INSTALLED_ARTIFACTS=true bash scripts/travis/build.sh
|
||||
script: travis_retry travis_wait 80 mvn -B verify -Dmaven.javadoc.skip=true -Dmaven.source.skip=true -Pags -Pstart-postgres -PagsAllTestSuitePt4 -f amps/ags/pom.xml ${LOG_WARN}
|
||||
|
||||
- name: "AGS Unit & Integration Tests 01 (MySQL) "
|
||||
if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip ags\]/) OR commit_message =~ /\[ags on MySQL\]/
|
||||
install: travis_retry travis_wait 40 env REQUIRES_INSTALLED_ARTIFACTS=true bash scripts/travis/build.sh
|
||||
script: travis_retry travis_wait 80 mvn -B verify -Dmaven.javadoc.skip=true -Dmaven.source.skip=true -Pags -Pstart-mysql -PagsAllTestSuitePt1 -f amps/ags/pom.xml ${LOG_WARN}
|
||||
|
||||
- name: "AGS Integration Tests 02 (MySQL) "
|
||||
if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip ags\]/) OR commit_message =~ /\[ags on MySQL\]/
|
||||
install: travis_retry travis_wait 40 env REQUIRES_INSTALLED_ARTIFACTS=true bash scripts/travis/build.sh
|
||||
script: travis_retry travis_wait 80 mvn -B verify -Dmaven.javadoc.skip=true -Dmaven.source.skip=true -Pags -Pstart-mysql -PagsAllTestSuitePt2 -f amps/ags/pom.xml ${LOG_WARN}
|
||||
|
||||
- name: "AGS Integration Tests 03 (MySQL) "
|
||||
if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip ags\]/) OR commit_message =~ /\[ags\]/
|
||||
install: travis_retry travis_wait 40 env REQUIRES_INSTALLED_ARTIFACTS=true bash scripts/travis/build.sh
|
||||
script: travis_retry travis_wait 80 mvn -B verify -Dmaven.javadoc.skip=true -Dmaven.source.skip=true -Pags -Pstart-mysql -PagsAllTestSuitePt3 -f amps/ags/pom.xml ${LOG_WARN}
|
||||
|
||||
- name: "AGS Unit & Integration Tests 04 (MySQL) "
|
||||
if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip ags\]/) OR commit_message =~ /\[ags on MySQL\]/
|
||||
install: travis_retry travis_wait 40 env REQUIRES_INSTALLED_ARTIFACTS=true bash scripts/travis/build.sh
|
||||
script: travis_retry travis_wait 80 mvn -B verify -Dmaven.javadoc.skip=true -Dmaven.source.skip=true -Pags -Pstart-mysql -PagsAllTestSuitePt4 -f amps/ags/pom.xml ${LOG_WARN}
|
||||
|
||||
- name: "AGS Community Rest API Tests"
|
||||
if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip ags\]/) OR commit_message =~ /\[ags\]/
|
||||
install: travis_retry travis_wait 40 env REQUIRES_LOCAL_IMAGES=true bash scripts/travis/build.sh
|
||||
addons:
|
||||
artifacts:
|
||||
paths:
|
||||
- ./amps/ags/rm-automation/rm-automation-community-rest-api/target/reports/rm-automation-community-rest-api.log
|
||||
- alfresco.log
|
||||
- solr.log
|
||||
target_paths: community/${TRAVIS_BUILD_NUMBER}/${TRAVIS_JOB_NAME}
|
||||
before_script:
|
||||
- ${TAS_SCRIPTS}/start-compose.sh ./amps/ags/rm-community/rm-community-repo/docker-compose.yml
|
||||
- ${TAS_SCRIPTS}/wait-for-alfresco-start.sh "http://localhost:8080/alfresco"
|
||||
script: travis_wait 40 mvn -B test -pl :alfresco-governance-services-automation-community-rest-api -am -DfailIfNoTests=false -Dskip.automationtests=false -Pags
|
||||
after_script: bash amps/ags/travis/scripts/getLogs.sh
|
||||
# - name: "Source Clear Scan (SCA)"
|
||||
# stage: test
|
||||
# if: branch = master OR branch =~ /release\/.*/
|
||||
# # Run Veracode
|
||||
# install: skip
|
||||
# script: travis_wait 30 bash scripts/travis/source_clear.sh
|
||||
#
|
||||
# - name: "Core, Data-Model, Repository - AllUnitTestsSuite - Build and test"
|
||||
# if: commit_message !~ /\[skip repo\]/
|
||||
# install: skip
|
||||
# script:
|
||||
# - travis_retry mvn -B test -pl core,data-model -am -DfailIfNoTests=false
|
||||
# - travis_retry mvn -B test -pl "repository,mmt" -am "-Dtest=AllUnitTestsSuite,AllMmtUnitTestSuite" -DfailIfNoTests=false
|
||||
#
|
||||
# - name: "Repository - AppContext01TestSuite"
|
||||
# if: commit_message !~ /\[skip repo\]/
|
||||
# install: skip
|
||||
# before_script:
|
||||
# - docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:14.4 postgres -c 'max_connections=300'
|
||||
# - docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
# - docker run -d -p 8090:8090 -e JAVA_OPTS=" -Xms256m -Xmx256m" alfresco/alfresco-transform-core-aio:${TRANSFORMERS_TAG}
|
||||
# script: travis_wait 20 mvn -B test -pl repository -am -Dtest=AppContext01TestSuite -DfailIfNoTests=false -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
|
||||
#
|
||||
# - name: "Repository - AppContext02TestSuite"
|
||||
# if: commit_message !~ /\[skip repo\]/
|
||||
# install: skip
|
||||
# before_script:
|
||||
# - docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:14.4 postgres -c 'max_connections=300'
|
||||
# - docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
# script: travis_wait 20 mvn -B test -pl repository -am -Dtest=AppContext02TestSuite -DfailIfNoTests=false -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
|
||||
#
|
||||
# - name: "Repository - AppContext03TestSuite"
|
||||
# if: commit_message !~ /\[skip repo\]/
|
||||
# install: skip
|
||||
# before_script:
|
||||
# - docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:14.4 postgres -c 'max_connections=300'
|
||||
# - docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
# - docker run -d -p 8090:8090 -e JAVA_OPTS=" -Xms256m -Xmx256m" alfresco/alfresco-transform-core-aio:${TRANSFORMERS_TAG}
|
||||
# script: travis_wait 20 mvn -B test -pl repository -am -Dtest=AppContext03TestSuite -DfailIfNoTests=false -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
|
||||
#
|
||||
# - name: "Repository - AppContext04TestSuite"
|
||||
# if: commit_message !~ /\[skip repo\]/
|
||||
# install: skip
|
||||
# before_script:
|
||||
# - docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:14.4 postgres -c 'max_connections=300'
|
||||
# - docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
# - docker run -d -p 8090:8090 -e JAVA_OPTS=" -Xms256m -Xmx256m" alfresco/alfresco-transform-core-aio:${TRANSFORMERS_TAG}
|
||||
# script: travis_wait 20 mvn -B test -pl repository -am -Dtest=AppContext04TestSuite -DfailIfNoTests=false -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
|
||||
#
|
||||
# - name: "Repository - AppContext05TestSuite"
|
||||
# if: commit_message !~ /\[skip repo\]/
|
||||
# install: skip
|
||||
# before_script:
|
||||
# - docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:14.4 postgres -c 'max_connections=300'
|
||||
# - docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
# - mkdir -p "${HOME}/tmp"
|
||||
# - cp repository/src/test/resources/realms/alfresco-realm.json "${HOME}/tmp"
|
||||
# - export HOST_IP=$(hostname -I | cut -f1 -d' ')
|
||||
# - docker run -d -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin -e DB_VENDOR=h2 -p 8999:8080 -e KEYCLOAK_IMPORT=/tmp/alfresco-realm.json -v $HOME/tmp/alfresco-realm.json:/tmp/alfresco-realm.json alfresco/alfresco-identity-service:1.2
|
||||
# script: travis_wait 20 mvn -B test -pl repository -am -Dtest=AppContext05TestSuite -DfailIfNoTests=false -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco "-Didentity-service.auth-server-url=http://${HOST_IP}:8999/auth"
|
||||
#
|
||||
# - name: "Repository - AppContext06TestSuite"
|
||||
# if: commit_message !~ /\[skip repo\]/
|
||||
# install: skip
|
||||
# before_script:
|
||||
# - docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:14.4 postgres -c 'max_connections=300'
|
||||
# - docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
# - docker run -d -p 8090:8090 -e JAVA_OPTS=" -Xms256m -Xmx256m" alfresco/alfresco-transform-core-aio:${TRANSFORMERS_TAG}
|
||||
# script: travis_wait 20 mvn -B test -pl repository -am -Dtest=AppContext06TestSuite -DfailIfNoTests=false -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
|
||||
#
|
||||
# - name: "Repository - AppContextExtraTestSuite"
|
||||
# if: commit_message !~ /\[skip repo\]/
|
||||
# install: skip
|
||||
# before_script:
|
||||
# - docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:14.4 postgres -c 'max_connections=300'
|
||||
# - docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
# - docker run -d -p 8090:8090 -e JAVA_OPTS=" -Xms256m -Xmx256m" alfresco/alfresco-transform-core-aio:${TRANSFORMERS_TAG}
|
||||
# script: travis_wait 20 mvn -B test -pl repository -am -Dtest=AppContextExtraTestSuite -DfailIfNoTests=false -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
|
||||
#
|
||||
# - name: "Repository - MiscContextTestSuite"
|
||||
# if: commit_message !~ /\[skip repo\]/
|
||||
# install: skip
|
||||
# before_script:
|
||||
# - docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:14.4 postgres -c 'max_connections=300'
|
||||
# - docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
# - docker run -d -p 8090:8090 -e JAVA_OPTS=" -Xms256m -Xmx256m" alfresco/alfresco-transform-core-aio:${TRANSFORMERS_TAG}
|
||||
# script: travis_wait 20 mvn -B test -pl repository -am -Dtest=MiscContextTestSuite -DfailIfNoTests=false -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
|
||||
#
|
||||
# - name: "Repository - SearchTestSuite"
|
||||
# if: commit_message !~ /\[skip repo\]/
|
||||
# install: skip
|
||||
# before_script:
|
||||
# - docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:14.4 postgres -c 'max_connections=300'
|
||||
# - docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
# script: travis_wait 20 mvn -B test -pl repository -am -Dtest=SearchTestSuite -DfailIfNoTests=false -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco -Dindex.subsystem.name=solr6
|
||||
#
|
||||
# - name: "Repository - MariaDB 10.2.18 tests"
|
||||
# if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip db\]/ AND type != pull_request) OR commit_message =~ /\[db\]/
|
||||
# install: skip
|
||||
# before_script:
|
||||
# - docker run -d -p 3307:3306 --name mariadb -e MYSQL_ROOT_PASSWORD=alfresco -e MYSQL_USER=alfresco -e MYSQL_DATABASE=alfresco -e MYSQL_PASSWORD=alfresco mariadb:10.2.18 --transaction-isolation=READ-COMMITTED --max-connections=300 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
|
||||
# - docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
# script: travis_wait 20 mvn -B test -pl repository -am -Dtest=AllDBTestsTestSuite -DfailIfNoTests=false -Ddb.name=alfresco -Ddb.url=jdbc:mariadb://localhost:3307/alfresco?useUnicode=yes\&characterEncoding=UTF-8 -Ddb.username=alfresco -Ddb.password=alfresco -Ddb.driver=org.mariadb.jdbc.Driver
|
||||
#
|
||||
# - name: "Repository - MariaDB 10.4 tests"
|
||||
# if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip db\]/ AND type != pull_request) OR commit_message =~ /\[db\]/
|
||||
# install: skip
|
||||
# before_script:
|
||||
# - docker run -d -p 3307:3306 --name mariadb -e MYSQL_ROOT_PASSWORD=alfresco -e MYSQL_USER=alfresco -e MYSQL_DATABASE=alfresco -e MYSQL_PASSWORD=alfresco mariadb:10.4 --transaction-isolation=READ-COMMITTED --max-connections=300 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
|
||||
# - docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
# script: travis_wait 20 mvn -B test -pl repository -am -Dtest=AllDBTestsTestSuite -DfailIfNoTests=false -Ddb.name=alfresco -Ddb.url=jdbc:mariadb://localhost:3307/alfresco?useUnicode=yes\&characterEncoding=UTF-8 -Ddb.username=alfresco -Ddb.password=alfresco -Ddb.driver=org.mariadb.jdbc.Driver
|
||||
#
|
||||
# - name: "Repository - MariaDB 10.5 tests"
|
||||
# if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip db\]/ AND type != pull_request) OR commit_message =~ /\[db\]/
|
||||
# install: skip
|
||||
# before_script:
|
||||
# - docker run -d -p 3307:3306 --name mariadb -e MYSQL_ROOT_PASSWORD=alfresco -e MYSQL_USER=alfresco -e MYSQL_DATABASE=alfresco -e MYSQL_PASSWORD=alfresco mariadb:10.5 --transaction-isolation=READ-COMMITTED --max-connections=300 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
|
||||
# - docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
# script: travis_wait 20 mvn -B test -pl repository -am -Dtest=AllDBTestsTestSuite -DfailIfNoTests=false -Ddb.name=alfresco -Ddb.url=jdbc:mariadb://localhost:3307/alfresco?useUnicode=yes\&characterEncoding=UTF-8 -Ddb.username=alfresco -Ddb.password=alfresco -Ddb.driver=org.mariadb.jdbc.Driver
|
||||
#
|
||||
# - name: "Repository - MariaDB 10.6 tests"
|
||||
# # We run tests on the latest version of MariaDB on pull requests plus the normal master and release branches - ignored on feature branches
|
||||
# if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip db\]/ ) OR commit_message =~ /\[db\]/ OR commit_message =~ /\[latest db\]/
|
||||
# install: skip
|
||||
# before_script:
|
||||
# - docker run -d -p 3307:3306 --name mariadb -e MYSQL_ROOT_PASSWORD=alfresco -e MYSQL_USER=alfresco -e MYSQL_DATABASE=alfresco -e MYSQL_PASSWORD=alfresco mariadb:10.6 --transaction-isolation=READ-COMMITTED --max-connections=300 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
|
||||
# - docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
# script: travis_wait 20 mvn -B test -pl repository -am -Dtest=AllDBTestsTestSuite -DfailIfNoTests=false -Ddb.name=alfresco -Ddb.url=jdbc:mariadb://localhost:3307/alfresco?useUnicode=yes\&characterEncoding=UTF-8 -Ddb.username=alfresco -Ddb.password=alfresco -Ddb.driver=org.mariadb.jdbc.Driver
|
||||
#
|
||||
# - name: "Repository - MySQL 8 tests"
|
||||
# # We run tests on the latest version of MySQL on pull requests plus the normal master and release branches - ignored on feature branches
|
||||
# if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip db\]/ ) OR commit_message =~ /\[db\]/ OR commit_message =~ /\[latest db\]/
|
||||
# install: skip
|
||||
# before_script:
|
||||
# - docker run -d -p 3307:3306 -e MYSQL_ROOT_PASSWORD=alfresco -e MYSQL_USER=alfresco -e MYSQL_DATABASE=alfresco -e MYSQL_PASSWORD=alfresco mysql:8 --transaction-isolation='READ-COMMITTED'
|
||||
# - docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
# script: travis_wait 20 mvn -B test -pl repository -am -Dtest=AllDBTestsTestSuite -DfailIfNoTests=false -Ddb.driver=com.mysql.jdbc.Driver -Ddb.name=alfresco -Ddb.url=jdbc:mysql://localhost:3307/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
|
||||
#
|
||||
# - name: "Repository - PostgreSQL 13.7 tests"
|
||||
# if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip db\]/ AND type != pull_request) OR commit_message =~ /\[db\]/
|
||||
# install: skip
|
||||
# before_script:
|
||||
# - docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:13.7 postgres -c 'max_connections=300'
|
||||
# - docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
# script: travis_wait 20 mvn -B test -pl repository -am -Dtest=AllDBTestsTestSuite -DfailIfNoTests=false -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
|
||||
#
|
||||
# - name: "Repository - PostgreSQL 14.4 tests"
|
||||
# # We only run DB tests on the latest version of PostgreSQL on feature branches
|
||||
# if: commit_message !~ /\[skip db\]/ OR commit_message =~ /\[db\]/ OR commit_message =~ /\[latest db\]/
|
||||
# install: skip
|
||||
# before_script:
|
||||
# - docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:14.4 postgres -c 'max_connections=300'
|
||||
# - docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
# script: travis_wait 20 mvn -B test -pl repository -am -Dtest=AllDBTestsTestSuite -DfailIfNoTests=false -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
|
||||
#
|
||||
# - name: "Repository - Messaging tests"
|
||||
# if: commit_message !~ /\[skip repo\]/
|
||||
# install: skip
|
||||
# before_script:
|
||||
# - docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
# script: travis_wait 20 mvn -B test -pl repository -am -Dtest=CamelRoutesTest,CamelComponentsTest -DfailIfNoTests=false
|
||||
#
|
||||
# - name: "Remote-api - AppContext01TestSuite"
|
||||
# if: commit_message !~ /\[skip repo\]/
|
||||
# install: travis_retry travis_wait 40 env REQUIRES_INSTALLED_ARTIFACTS=true bash scripts/travis/build.sh
|
||||
# before_script:
|
||||
# - docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:14.4 postgres -c 'max_connections=300'
|
||||
# - docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
# script: travis_wait 20 mvn -B test -pl remote-api -Dtest=AppContext01TestSuite -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
|
||||
#
|
||||
# - name: "Remote-api - AppContext02TestSuite"
|
||||
# if: commit_message !~ /\[skip repo\]/
|
||||
# install: travis_retry travis_wait 40 env REQUIRES_INSTALLED_ARTIFACTS=true bash scripts/travis/build.sh
|
||||
# before_script:
|
||||
# - docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:14.4 postgres -c 'max_connections=300'
|
||||
# - docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
# - docker run -d -p 8090:8090 -e JAVA_OPTS=" -Xms256m -Xmx256m" alfresco/alfresco-transform-core-aio:${TRANSFORMERS_TAG}
|
||||
# script: travis_wait 20 mvn -B test -pl remote-api -Dtest=AppContext02TestSuite -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
|
||||
#
|
||||
# - name: "Remote-api - AppContext03TestSuite"
|
||||
# if: commit_message !~ /\[skip repo\]/
|
||||
# install: travis_retry travis_wait 40 env REQUIRES_INSTALLED_ARTIFACTS=true bash scripts/travis/build.sh
|
||||
# before_script:
|
||||
# - docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:14.4 postgres -c 'max_connections=300'
|
||||
# - docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
# - docker run -d -p 8090:8090 -e JAVA_OPTS=" -Xms256m -Xmx256m" alfresco/alfresco-transform-core-aio:${TRANSFORMERS_TAG}
|
||||
# script: travis_wait 20 mvn -B test -pl remote-api -Dtest=AppContext03TestSuite -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
|
||||
#
|
||||
# - name: "Remote-api - AppContext04TestSuite"
|
||||
# if: commit_message !~ /\[skip repo\]/
|
||||
# install: travis_retry travis_wait 40 env REQUIRES_INSTALLED_ARTIFACTS=true bash scripts/travis/build.sh
|
||||
# before_script:
|
||||
# - docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:14.4 postgres -c 'max_connections=300'
|
||||
# - docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
# - docker run -d -p 8090:8090 -e JAVA_OPTS=" -Xms256m -Xmx256m" alfresco/alfresco-transform-core-aio:${TRANSFORMERS_TAG}
|
||||
# script: travis_wait 20 mvn -B test -pl remote-api -Dtest=AppContext04TestSuite -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
|
||||
#
|
||||
# - name: "Remote-api - AppContextExtraTestSuite"
|
||||
# if: commit_message !~ /\[skip repo\]/
|
||||
# install: travis_retry travis_wait 40 env REQUIRES_INSTALLED_ARTIFACTS=true bash scripts/travis/build.sh
|
||||
# before_script:
|
||||
# - docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:14.4 postgres -c 'max_connections=300'
|
||||
# - docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.17.1-jre11-rockylinux8
|
||||
# script: travis_wait 20 mvn -B test -pl remote-api -Dtest=AppContextExtraTestSuite -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
|
||||
#
|
||||
# - name: "REST API TAS tests part1"
|
||||
# # TAS tests are generally skipped on feature branches as they will be repeated on the enterprise repo or community packaging builds
|
||||
# if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip tas\]/) OR commit_message =~ /\[tas\]/
|
||||
# install: travis_retry travis_wait 40 env REQUIRES_LOCAL_IMAGES=true bash scripts/travis/build.sh
|
||||
# before_script:
|
||||
# - ${TAS_SCRIPTS}/start-compose.sh ${TAS_ENVIRONMENT}/docker-compose-minimal+transforms.yml
|
||||
# - ${TAS_SCRIPTS}/wait-for-alfresco-start.sh "http://localhost:8082/alfresco"
|
||||
# script: travis_wait 60 mvn -B verify -f packaging/tests/tas-restapi/pom.xml -Pall-tas-tests,run-restapi-part1 -Denvironment=default -DrunBugs=false
|
||||
#
|
||||
# - name: "REST API TAS tests part2"
|
||||
# if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip tas\]/) OR commit_message =~ /\[tas\]/
|
||||
# install: travis_retry travis_wait 40 env REQUIRES_LOCAL_IMAGES=true bash scripts/travis/build.sh
|
||||
# before_script:
|
||||
# - ${TAS_SCRIPTS}/start-compose.sh ${TAS_ENVIRONMENT}/docker-compose-minimal+transforms.yml
|
||||
# - ${TAS_SCRIPTS}/wait-for-alfresco-start.sh "http://localhost:8082/alfresco"
|
||||
# script: travis_wait 60 mvn -B verify -f packaging/tests/tas-restapi/pom.xml -Pall-tas-tests,run-restapi-part2 -Denvironment=default -DrunBugs=false
|
||||
#
|
||||
# - name: "REST API TAS tests part3"
|
||||
# if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip tas\]/) OR commit_message =~ /\[tas\]/
|
||||
# install: travis_retry travis_wait 40 env REQUIRES_LOCAL_IMAGES=true bash scripts/travis/build.sh
|
||||
# before_script:
|
||||
# - ${TAS_SCRIPTS}/start-compose.sh ${TAS_ENVIRONMENT}/docker-compose-minimal+transforms.yml
|
||||
# - ${TAS_SCRIPTS}/wait-for-alfresco-start.sh "http://localhost:8082/alfresco"
|
||||
# script: travis_wait 60 mvn -B verify -f packaging/tests/tas-restapi/pom.xml -Pall-tas-tests,run-restapi-part3 -Denvironment=default -DrunBugs=false
|
||||
#
|
||||
# - name: "CMIS TAS tests - BROWSER binding"
|
||||
# if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip tas\]/) OR commit_message =~ /\[tas\]/
|
||||
# install: travis_retry travis_wait 40 env REQUIRES_LOCAL_IMAGES=true bash scripts/travis/build.sh
|
||||
# before_script:
|
||||
# - ${TAS_SCRIPTS}/start-compose.sh ${TAS_ENVIRONMENT}/docker-compose-minimal+transforms.yml
|
||||
# - ${TAS_SCRIPTS}/wait-for-alfresco-start.sh "http://localhost:8082/alfresco"
|
||||
# script: travis_wait 40 mvn -B verify -f packaging/tests/tas-cmis/pom.xml -Pall-tas-tests,run-cmis-browser -Denvironment=default -DrunBugs=false
|
||||
#
|
||||
# - name: "CMIS TAS tests - ATOM binding"
|
||||
# if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip tas\]/) OR commit_message =~ /\[tas\]/
|
||||
# install: travis_retry travis_wait 40 env REQUIRES_LOCAL_IMAGES=true bash scripts/travis/build.sh
|
||||
# before_script:
|
||||
# - ${TAS_SCRIPTS}/start-compose.sh ${TAS_ENVIRONMENT}/docker-compose-minimal+transforms.yml
|
||||
# - ${TAS_SCRIPTS}/wait-for-alfresco-start.sh "http://localhost:8082/alfresco"
|
||||
# script: travis_wait 40 mvn -B verify -f packaging/tests/tas-cmis/pom.xml -Pall-tas-tests,run-cmis-atom -Denvironment=default -DrunBugs=false
|
||||
#
|
||||
# - name: "CMIS TAS tests - WEBSERVICES binding"
|
||||
# if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip tas\]/) OR commit_message =~ /\[tas\]/
|
||||
# install: travis_retry travis_wait 40 env REQUIRES_LOCAL_IMAGES=true bash scripts/travis/build.sh
|
||||
# before_script:
|
||||
# - ${TAS_SCRIPTS}/start-compose.sh ${TAS_ENVIRONMENT}/docker-compose-minimal+transforms.yml
|
||||
# - ${TAS_SCRIPTS}/wait-for-alfresco-start.sh "http://localhost:8082/alfresco"
|
||||
# script: travis_wait 40 mvn -B verify -f packaging/tests/tas-cmis/pom.xml -Pall-tas-tests,run-cmis-webservices -Denvironment=default -DrunBugs=false
|
||||
#
|
||||
# - name: "Email TAS tests"
|
||||
# if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip tas\]/) OR commit_message =~ /\[tas\]/
|
||||
# install: travis_retry travis_wait 40 env REQUIRES_LOCAL_IMAGES=true bash scripts/travis/build.sh
|
||||
# before_script:
|
||||
# - ${TAS_SCRIPTS}/start-compose.sh ${TAS_ENVIRONMENT}/docker-compose-minimal.yml
|
||||
# - ${TAS_SCRIPTS}/wait-for-alfresco-start.sh "http://localhost:8082/alfresco"
|
||||
# script: travis_wait 30 mvn -B verify -f packaging/tests/tas-email/pom.xml -Pall-tas-tests -Denvironment=default -DrunBugs=false
|
||||
#
|
||||
# - name: "WebDAV TAS tests"
|
||||
# if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip tas\]/) OR commit_message =~ /\[tas\]/
|
||||
# install: travis_retry travis_wait 40 env REQUIRES_LOCAL_IMAGES=true bash scripts/travis/build.sh
|
||||
# before_script:
|
||||
# - ${TAS_SCRIPTS}/start-compose.sh ${TAS_ENVIRONMENT}/docker-compose-minimal.yml
|
||||
# - ${TAS_SCRIPTS}/wait-for-alfresco-start.sh "http://localhost:8082/alfresco"
|
||||
# script: travis_wait 30 mvn -B verify -f packaging/tests/tas-webdav/pom.xml -Pall-tas-tests -Denvironment=default -DrunBugs=false
|
||||
#
|
||||
# - name: "Integration TAS tests"
|
||||
# if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip tas\]/) OR commit_message =~ /\[tas\]/
|
||||
# install: travis_retry travis_wait 40 env REQUIRES_LOCAL_IMAGES=true bash scripts/travis/build.sh
|
||||
# before_script:
|
||||
# - ${TAS_SCRIPTS}/start-compose.sh ${TAS_ENVIRONMENT}/docker-compose-minimal.yml
|
||||
# - ${TAS_SCRIPTS}/wait-for-alfresco-start.sh "http://localhost:8082/alfresco"
|
||||
# script: travis_wait 30 mvn -B verify -f packaging/tests/tas-integration/pom.xml -Pall-tas-tests -Denvironment=default -DrunBugs=false
|
||||
#
|
||||
# - name: "Share Services - ShareServicesTestSuite"
|
||||
# if: commit_message !~ /\[skip repo\]/
|
||||
# install: skip
|
||||
# before_script:
|
||||
# - docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:14.4 postgres -c 'max_connections=300'
|
||||
# script: travis_wait 20 mvn -B test -pl :alfresco-share-services -am -Dtest=ShareServicesTestSuite -DfailIfNoTests=false -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
|
||||
#
|
||||
# - name: "AGS Unit & Integration Tests 01 (PostgreSQL)"
|
||||
# if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip ags\]/) OR commit_message =~ /\[ags\]/
|
||||
# install: travis_retry travis_wait 40 env REQUIRES_INSTALLED_ARTIFACTS=true bash scripts/travis/build.sh
|
||||
# script: travis_retry travis_wait 80 mvn -B verify -Dmaven.javadoc.skip=true -Dmaven.source.skip=true -Pags -Pstart-postgres -PagsAllTestSuitePt1 -f amps/ags/pom.xml ${LOG_WARN}
|
||||
#
|
||||
# - name: "AGS Integration Tests 02 (PostgreSQL)"
|
||||
# if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip ags\]/) OR commit_message =~ /\[ags\]/
|
||||
# install: travis_retry travis_wait 40 env REQUIRES_INSTALLED_ARTIFACTS=true bash scripts/travis/build.sh
|
||||
# script: travis_retry travis_wait 80 mvn -B verify -Dmaven.javadoc.skip=true -Dmaven.source.skip=true -Pags -Pstart-postgres -PagsAllTestSuitePt2 -f amps/ags/pom.xml ${LOG_WARN}
|
||||
#
|
||||
# - name: "AGS Integration Tests 03 (PostgreSQL)"
|
||||
# if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip ags\]/) OR commit_message =~ /\[ags\]/
|
||||
# install: travis_retry travis_wait 40 env REQUIRES_INSTALLED_ARTIFACTS=true bash scripts/travis/build.sh
|
||||
# script: travis_retry travis_wait 80 mvn -B verify -Dmaven.javadoc.skip=true -Dmaven.source.skip=true -Pags -Pstart-postgres -PagsAllTestSuitePt3 -f amps/ags/pom.xml ${LOG_WARN}
|
||||
#
|
||||
# - name: "AGS Unit & Integration Tests 04 (PostgreSQL)"
|
||||
# if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip ags\]/) OR commit_message =~ /\[ags\]/
|
||||
# install: travis_retry travis_wait 40 env REQUIRES_INSTALLED_ARTIFACTS=true bash scripts/travis/build.sh
|
||||
# script: travis_retry travis_wait 80 mvn -B verify -Dmaven.javadoc.skip=true -Dmaven.source.skip=true -Pags -Pstart-postgres -PagsAllTestSuitePt4 -f amps/ags/pom.xml ${LOG_WARN}
|
||||
#
|
||||
# - name: "AGS Unit & Integration Tests 01 (MySQL) "
|
||||
# if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip ags\]/) OR commit_message =~ /\[ags on MySQL\]/
|
||||
# install: travis_retry travis_wait 40 env REQUIRES_INSTALLED_ARTIFACTS=true bash scripts/travis/build.sh
|
||||
# script: travis_retry travis_wait 80 mvn -B verify -Dmaven.javadoc.skip=true -Dmaven.source.skip=true -Pags -Pstart-mysql -PagsAllTestSuitePt1 -f amps/ags/pom.xml ${LOG_WARN}
|
||||
#
|
||||
# - name: "AGS Integration Tests 02 (MySQL) "
|
||||
# if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip ags\]/) OR commit_message =~ /\[ags on MySQL\]/
|
||||
# install: travis_retry travis_wait 40 env REQUIRES_INSTALLED_ARTIFACTS=true bash scripts/travis/build.sh
|
||||
# script: travis_retry travis_wait 80 mvn -B verify -Dmaven.javadoc.skip=true -Dmaven.source.skip=true -Pags -Pstart-mysql -PagsAllTestSuitePt2 -f amps/ags/pom.xml ${LOG_WARN}
|
||||
#
|
||||
# - name: "AGS Integration Tests 03 (MySQL) "
|
||||
# if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip ags\]/) OR commit_message =~ /\[ags\]/
|
||||
# install: travis_retry travis_wait 40 env REQUIRES_INSTALLED_ARTIFACTS=true bash scripts/travis/build.sh
|
||||
# script: travis_retry travis_wait 80 mvn -B verify -Dmaven.javadoc.skip=true -Dmaven.source.skip=true -Pags -Pstart-mysql -PagsAllTestSuitePt3 -f amps/ags/pom.xml ${LOG_WARN}
|
||||
#
|
||||
# - name: "AGS Unit & Integration Tests 04 (MySQL) "
|
||||
# if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip ags\]/) OR commit_message =~ /\[ags on MySQL\]/
|
||||
# install: travis_retry travis_wait 40 env REQUIRES_INSTALLED_ARTIFACTS=true bash scripts/travis/build.sh
|
||||
# script: travis_retry travis_wait 80 mvn -B verify -Dmaven.javadoc.skip=true -Dmaven.source.skip=true -Pags -Pstart-mysql -PagsAllTestSuitePt4 -f amps/ags/pom.xml ${LOG_WARN}
|
||||
#
|
||||
# - name: "AGS Community Rest API Tests"
|
||||
# if: (branch =~ /(release\/.*$|master)/ AND commit_message !~ /\[skip ags\]/) OR commit_message =~ /\[ags\]/
|
||||
# install: travis_retry travis_wait 40 env REQUIRES_LOCAL_IMAGES=true bash scripts/travis/build.sh
|
||||
# addons:
|
||||
# artifacts:
|
||||
# paths:
|
||||
# - ./amps/ags/rm-automation/rm-automation-community-rest-api/target/reports/rm-automation-community-rest-api.log
|
||||
# - alfresco.log
|
||||
# - solr.log
|
||||
# target_paths: community/${TRAVIS_BUILD_NUMBER}/${TRAVIS_JOB_NAME}
|
||||
# before_script:
|
||||
# - ${TAS_SCRIPTS}/start-compose.sh ./amps/ags/rm-community/rm-community-repo/docker-compose.yml
|
||||
# - ${TAS_SCRIPTS}/wait-for-alfresco-start.sh "http://localhost:8080/alfresco"
|
||||
# script: travis_wait 40 mvn -B test -pl :alfresco-governance-services-automation-community-rest-api -am -DfailIfNoTests=false -Dskip.automationtests=false -Pags
|
||||
# after_script: bash amps/ags/travis/scripts/getLogs.sh
|
||||
|
||||
- name: "Push to Nexus"
|
||||
stage: release
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo-amps</artifactId>
|
||||
<version>17.58</version>
|
||||
<version>17.75-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
@@ -30,16 +30,20 @@
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<!-- Keeping illegal-access=permit for Java 11 compatibility, even though it has no effect on JDK 17 -->
|
||||
<argLine>
|
||||
--illegal-access=permit
|
||||
--add-opens=java.base/java.lang=ALL-UNNAMED
|
||||
</argLine>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<!-- Keeping illegal-access=permit for Java 11 compatibility, even though it has no effect on JDK 17 -->
|
||||
<configuration>
|
||||
<argLine>
|
||||
--illegal-access=permit
|
||||
--add-opens=java.base/java.lang=ALL-UNNAMED
|
||||
</argLine>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-governance-services-community-parent</artifactId>
|
||||
<version>17.58</version>
|
||||
<version>17.75-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-governance-services-automation-community-repo</artifactId>
|
||||
<version>17.58</version>
|
||||
<version>17.75-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-governance-services-community-parent</artifactId>
|
||||
<version>17.58</version>
|
||||
<version>17.75-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-governance-services-community-repo-parent</artifactId>
|
||||
<version>17.58</version>
|
||||
<version>17.75-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-governance-services-community-repo-parent</artifactId>
|
||||
<version>17.58</version>
|
||||
<version>17.75-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo</artifactId>
|
||||
<version>17.58</version>
|
||||
<version>17.75-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo-amps</artifactId>
|
||||
<version>17.58</version>
|
||||
<version>17.75-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
|
||||
@@ -40,6 +40,7 @@ import org.json.JSONObject;
|
||||
import org.junit.Assert;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
@@ -194,13 +195,13 @@ public class SlingshotContentGetTest extends BaseWebScriptTest
|
||||
|
||||
NodeRef rootFolder = createNode(companyHome, "rootFolder", ContentModel.TYPE_FOLDER);
|
||||
|
||||
NodeRef doc1 = createNodeWithTextContent(rootFolder, "doc1", ContentModel.TYPE_CONTENT, "doc1 file content");
|
||||
NodeRef doc1 = createNodeWithTextContent(rootFolder, "doc1", ContentModel.TYPE_CONTENT, "doc1 file content", MimetypeMap.MIMETYPE_TEXT_PLAIN);
|
||||
|
||||
NodeRef folderX = createNode(rootFolder, "X", ContentModel.TYPE_FOLDER);
|
||||
NodeRef folderY = createNode(folderX, "Y", ContentModel.TYPE_FOLDER);
|
||||
NodeRef folderZ = createNode(folderY, "Z", ContentModel.TYPE_FOLDER);
|
||||
|
||||
NodeRef doc2 = createNodeWithTextContent(folderZ, "doc2", ContentModel.TYPE_CONTENT, "doc2 file content");
|
||||
NodeRef doc2 = createNodeWithTextContent(folderZ, "doc2", ContentModel.TYPE_CONTENT, "doc2 file content", MimetypeMap.MIMETYPE_TEXT_PLAIN);
|
||||
|
||||
// uri with relative path at the end
|
||||
String uri = URL_CONTENT_DOWNLOAD + doc1.getId() + "/X/Y/Z/doc2";
|
||||
@@ -212,7 +213,50 @@ public class SlingshotContentGetTest extends BaseWebScriptTest
|
||||
nodeService.deleteNode(rootFolder);
|
||||
}
|
||||
|
||||
public NodeRef createNodeWithTextContent(NodeRef parentNode, String nodeCmName, QName nodeType, String content)
|
||||
public void testForcedAttachment() throws Exception
|
||||
{
|
||||
Repository repositoryHelper = (Repository) getServer().getApplicationContext().getBean("repositoryHelper");
|
||||
NodeRef companyHome = repositoryHelper.getCompanyHome();
|
||||
|
||||
NodeRef rootFolder = createNode(companyHome, "rootFolder", ContentModel.TYPE_FOLDER);
|
||||
NodeRef testhtml = createNodeWithTextContent(rootFolder, "testhtml", ContentModel.TYPE_CONTENT, "testhtml content", MimetypeMap.MIMETYPE_HTML);
|
||||
NodeRef testpdf = createNodeWithTextContent(rootFolder, "testpdf", ContentModel.TYPE_CONTENT, "testpdf content", MimetypeMap.MIMETYPE_PDF);
|
||||
|
||||
String uri = URL_CONTENT_DOWNLOAD + testhtml.getId() + "?a=false";
|
||||
GetRequest req = new GetRequest(uri);
|
||||
Response res = sendRequest(req, 200);
|
||||
assertEquals("attachment", res.getHeader("Content-Disposition"));
|
||||
assertEquals(MimetypeMap.MIMETYPE_HTML + ";charset=UTF-8", res.getContentType());
|
||||
|
||||
uri = URL_CONTENT_DOWNLOAD + testhtml.getId();
|
||||
res = sendRequest(new GetRequest(uri), 200);
|
||||
assertEquals("attachment", res.getHeader("Content-Disposition"));
|
||||
assertEquals(MimetypeMap.MIMETYPE_HTML + ";charset=UTF-8", res.getContentType());
|
||||
|
||||
uri = URL_CONTENT_DOWNLOAD + testhtml.getId() + "?a=true";
|
||||
res = sendRequest(new GetRequest(uri), 200);
|
||||
assertEquals("attachment", res.getHeader("Content-Disposition"));
|
||||
assertEquals(MimetypeMap.MIMETYPE_HTML + ";charset=UTF-8", res.getContentType());
|
||||
|
||||
uri = URL_CONTENT_DOWNLOAD + testpdf.getId() + "?a=false";
|
||||
res = sendRequest(new GetRequest(uri), 200);
|
||||
assertNull(res.getHeader("Content-Disposition"));
|
||||
assertEquals(MimetypeMap.MIMETYPE_PDF + ";charset=UTF-8", res.getContentType());
|
||||
|
||||
uri = URL_CONTENT_DOWNLOAD + testpdf.getId();
|
||||
res = sendRequest(new GetRequest(uri), 200);
|
||||
assertNull(res.getHeader("Content-Disposition"));
|
||||
assertEquals(MimetypeMap.MIMETYPE_PDF + ";charset=UTF-8", res.getContentType());
|
||||
|
||||
uri = URL_CONTENT_DOWNLOAD + testpdf.getId() + "?a=true";
|
||||
res = sendRequest(new GetRequest(uri), 200);
|
||||
assertEquals("attachment", res.getHeader("Content-Disposition"));
|
||||
assertEquals(MimetypeMap.MIMETYPE_PDF + ";charset=UTF-8", res.getContentType());
|
||||
|
||||
nodeService.deleteNode(rootFolder);
|
||||
}
|
||||
|
||||
public NodeRef createNodeWithTextContent(NodeRef parentNode, String nodeCmName, QName nodeType, String content, String mimetype)
|
||||
{
|
||||
NodeRef nodeRef = createNode(parentNode, nodeCmName, nodeType);
|
||||
|
||||
@@ -220,7 +264,7 @@ public class SlingshotContentGetTest extends BaseWebScriptTest
|
||||
if (content != null)
|
||||
{
|
||||
ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
|
||||
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
|
||||
writer.setMimetype(mimetype);
|
||||
writer.setEncoding("UTF-8");
|
||||
writer.putContent(content);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo</artifactId>
|
||||
<version>17.58</version>
|
||||
<version>17.75-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo</artifactId>
|
||||
<version>17.58</version>
|
||||
<version>17.75-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo</artifactId>
|
||||
<version>17.58</version>
|
||||
<version>17.75-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -9,6 +9,6 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo-packaging</artifactId>
|
||||
<version>17.58</version>
|
||||
<version>17.75-SNAPSHOT</version>
|
||||
</parent>
|
||||
</project>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Fetch image based on Tomcat 9.0, Java 11 and Centos 7
|
||||
# Fetch image based on Tomcat 9.0, Java 17 and Rocky Linux 8
|
||||
# More infos about this image: https://github.com/Alfresco/alfresco-docker-base-tomcat
|
||||
FROM alfresco/alfresco-base-tomcat:tomcat9-jre11-rockylinux8-202205140719
|
||||
FROM alfresco/alfresco-base-tomcat:tomcat9-jre17-rockylinux8-202205140719
|
||||
|
||||
# Set default docker_context.
|
||||
ARG resource_path=target
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo-packaging</artifactId>
|
||||
<version>17.58</version>
|
||||
<version>17.75-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo</artifactId>
|
||||
<version>17.58</version>
|
||||
<version>17.75-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo-packaging</artifactId>
|
||||
<version>17.58</version>
|
||||
<version>17.75-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo-tests</artifactId>
|
||||
<version>17.58</version>
|
||||
<version>17.75-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<developers>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo-tests</artifactId>
|
||||
<version>17.58</version>
|
||||
<version>17.75-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<developers>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo-tests</artifactId>
|
||||
<version>17.58</version>
|
||||
<version>17.75-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<developers>
|
||||
@@ -106,8 +106,10 @@
|
||||
<suiteXmlFiles>
|
||||
<suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
|
||||
</suiteXmlFiles>
|
||||
<!-- Keeping illegal-access=warn for Java 11 compatibility, even though it has no effect on JDK 17 -->
|
||||
<argLine>
|
||||
--illegal-access=warn
|
||||
--add-opens=java.base/java.lang=ALL-UNNAMED
|
||||
</argLine>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo-tests</artifactId>
|
||||
<version>17.58</version>
|
||||
<version>17.75-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<developers>
|
||||
@@ -78,8 +78,10 @@
|
||||
<suiteXmlFiles>
|
||||
<suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
|
||||
</suiteXmlFiles>
|
||||
<!-- Keeping illegal-access=warn for Java 11 compatibility, even though it has no effect on JDK 17 -->
|
||||
<argLine>
|
||||
--illegal-access=warn
|
||||
--add-opens=java.base/java.lang=ALL-UNNAMED
|
||||
</argLine>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
@@ -27,7 +27,9 @@ package org.alfresco.rest.rules;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import static org.alfresco.utility.constants.UserRole.SiteCollaborator;
|
||||
import static org.alfresco.rest.rules.RulesTestsUtils.createActionModel;
|
||||
import static org.alfresco.rest.rules.RulesTestsUtils.createRuleModel;
|
||||
import static org.alfresco.utility.constants.UserRole.*;
|
||||
import static org.alfresco.utility.model.FileModel.getRandomFileModel;
|
||||
import static org.alfresco.utility.model.FileType.TEXT_PLAIN;
|
||||
import static org.alfresco.utility.report.log.Step.STEP;
|
||||
@@ -43,6 +45,7 @@ import java.util.stream.IntStream;
|
||||
import org.alfresco.rest.RestTest;
|
||||
import org.alfresco.rest.model.RestRuleModel;
|
||||
import org.alfresco.rest.model.RestRuleModelsCollection;
|
||||
import org.alfresco.utility.constants.UserRole;
|
||||
import org.alfresco.utility.model.FileModel;
|
||||
import org.alfresco.utility.model.FolderModel;
|
||||
import org.alfresco.utility.model.SiteModel;
|
||||
@@ -73,14 +76,12 @@ public class CreateRulesTests extends RestTest
|
||||
@Test (groups = { TestGroup.REST_API, TestGroup.RULES, TestGroup.SANITY })
|
||||
public void createRule()
|
||||
{
|
||||
RestRuleModel ruleModel = new RestRuleModel();
|
||||
ruleModel.setName("ruleName");
|
||||
RestRuleModel ruleModel = createRuleModel("ruleName");
|
||||
|
||||
RestRuleModel rule = restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet()
|
||||
.createSingleRule(ruleModel);
|
||||
|
||||
restClient.assertStatusCodeIs(CREATED);
|
||||
|
||||
rule.assertThat().field("id").isNotNull()
|
||||
.assertThat().field("name").is("ruleName");
|
||||
}
|
||||
@@ -133,8 +134,7 @@ public class CreateRulesTests extends RestTest
|
||||
@Test (groups = { TestGroup.REST_API, TestGroup.RULES })
|
||||
public void duplicateRuleNameIsAcceptable()
|
||||
{
|
||||
RestRuleModel ruleModel = new RestRuleModel();
|
||||
ruleModel.setName("duplicateRuleName");
|
||||
RestRuleModel ruleModel = createRuleModel("duplicateRuleName");
|
||||
|
||||
STEP("Create two identical rules");
|
||||
RestRuleModel ruleA = restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet().createSingleRule(ruleModel);
|
||||
@@ -163,26 +163,42 @@ public class CreateRulesTests extends RestTest
|
||||
restClient.assertLastError().containsSummary("Insufficient permissions to manage rules");
|
||||
}
|
||||
|
||||
/** Check that a user without write permission for the folder cannot create a rule in it. */
|
||||
public void requireWritePermissionToCreateRule()
|
||||
/** Check that a Collaborator cannot create a rule in a private folder. */
|
||||
public void siteCollaboratorCannotCreateRule()
|
||||
{
|
||||
STEP("Create a user and use them to create a private site containing a folder");
|
||||
UserModel privateUser = dataUser.createRandomTestUser();
|
||||
SiteModel privateSite = dataSite.usingUser(privateUser).createPrivateRandomSite();
|
||||
FolderModel privateFolder = dataContent.usingUser(privateUser).usingSite(privateSite).createFolder();
|
||||
|
||||
STEP("Create a collaborator and check they cannot create a rule in the private folder");
|
||||
UserModel collaborator = dataUser.createRandomTestUser();
|
||||
dataUser.addUserToSite(collaborator, privateSite, SiteCollaborator);
|
||||
RestRuleModel ruleModel = new RestRuleModel();
|
||||
ruleModel.setName("ruleName");
|
||||
|
||||
restClient.authenticateUser(collaborator).withCoreAPI().usingNode(privateFolder).usingDefaultRuleSet().createSingleRule(ruleModel);
|
||||
testRolePermissionsWith(SiteCollaborator);
|
||||
|
||||
restClient.assertStatusCodeIs(FORBIDDEN);
|
||||
restClient.assertLastError().containsSummary("Insufficient permissions to manage rules");
|
||||
}
|
||||
|
||||
/** Check that a Contributor cannot create a rule in a private folder. */
|
||||
public void siteContributorCannotCreateRule()
|
||||
{
|
||||
testRolePermissionsWith(SiteContributor);
|
||||
|
||||
restClient.assertStatusCodeIs(FORBIDDEN);
|
||||
restClient.assertLastError().containsSummary("Insufficient permissions to manage rules");
|
||||
}
|
||||
|
||||
/** Check that a Consumer cannot create a rule in a private folder. */
|
||||
public void siteConsumerCannotCreateRule()
|
||||
{
|
||||
testRolePermissionsWith(SiteConsumer);
|
||||
|
||||
restClient.assertStatusCodeIs(FORBIDDEN);
|
||||
restClient.assertLastError().containsSummary("Insufficient permissions to manage rules");
|
||||
}
|
||||
|
||||
/** Check that a siteManager can create a rule in a private folder. */
|
||||
public void siteManagerCanCreateRule()
|
||||
{
|
||||
testRolePermissionsWith(SiteManager)
|
||||
.assertThat().field("id").isNotNull()
|
||||
.assertThat().field("name").is("testRule");
|
||||
restClient.assertStatusCodeIs(CREATED);
|
||||
}
|
||||
|
||||
/** Check we can't create a rule under a document node. */
|
||||
@Test (groups = { TestGroup.REST_API, TestGroup.RULES })
|
||||
public void tryToCreateRuleUnderDocument()
|
||||
@@ -205,12 +221,7 @@ public class CreateRulesTests extends RestTest
|
||||
{
|
||||
STEP("Create a list of rules in one POST request");
|
||||
List<String> ruleNames = List.of("ruleA", "ruleB", "ruleC");
|
||||
List<RestRuleModel> ruleModels = ruleNames.stream().map(ruleName ->
|
||||
{
|
||||
RestRuleModel ruleModel = new RestRuleModel();
|
||||
ruleModel.setName(ruleName);
|
||||
return ruleModel;
|
||||
}).collect(toList());
|
||||
List<RestRuleModel> ruleModels = ruleNames.stream().map(RulesTestsUtils::createRuleModel).collect(toList());
|
||||
|
||||
RestRuleModelsCollection rules = restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet()
|
||||
.createListOfRules(ruleModels);
|
||||
@@ -229,12 +240,10 @@ public class CreateRulesTests extends RestTest
|
||||
public void createRulesWithOneError()
|
||||
{
|
||||
STEP("Try to create a three rules but the middle one has an error.");
|
||||
RestRuleModel ruleA = new RestRuleModel();
|
||||
ruleA.setName("ruleA");
|
||||
RestRuleModel ruleA = createRuleModel("ruleA");
|
||||
RestRuleModel ruleB = new RestRuleModel();
|
||||
// Don't set a name for Rule B.
|
||||
RestRuleModel ruleC = new RestRuleModel();
|
||||
ruleC.setName("ruleC");
|
||||
RestRuleModel ruleC = createRuleModel("ruleC");
|
||||
List<RestRuleModel> ruleModels = List.of(ruleA, ruleB, ruleC);
|
||||
|
||||
restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet().createListOfRules(ruleModels);
|
||||
@@ -242,4 +251,18 @@ public class CreateRulesTests extends RestTest
|
||||
restClient.assertStatusCodeIs(BAD_REQUEST);
|
||||
restClient.assertLastError().containsSummary("Rule name is a mandatory parameter");
|
||||
}
|
||||
|
||||
public RestRuleModel testRolePermissionsWith(UserRole userRole)
|
||||
{
|
||||
STEP("Create a user and use them to create a private site containing a folder");
|
||||
SiteModel privateSite = dataSite.usingUser(user).createPrivateRandomSite();
|
||||
FolderModel privateFolder = dataContent.usingUser(user).usingSite(privateSite).createFolder();
|
||||
|
||||
STEP(String.format("Add a user with '%s' role in the private site's folder", userRole.toString()));
|
||||
UserModel userWithRole = dataUser.createRandomTestUser();
|
||||
dataUser.addUserToSite(userWithRole, privateSite, userRole);
|
||||
RestRuleModel ruleModel = createRuleModel("testRule", List.of(createActionModel()));
|
||||
|
||||
return restClient.authenticateUser(userWithRole).withCoreAPI().usingNode(privateFolder).usingDefaultRuleSet().createSingleRule(ruleModel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,254 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.rules;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import static org.alfresco.rest.rules.RulesTestsUtils.createRuleModel;
|
||||
import static org.alfresco.utility.constants.UserRole.SiteCollaborator;
|
||||
import static org.alfresco.utility.constants.UserRole.SiteContributor;
|
||||
import static org.alfresco.utility.constants.UserRole.SiteManager;
|
||||
import static org.alfresco.utility.report.log.Step.STEP;
|
||||
import static org.springframework.http.HttpStatus.FORBIDDEN;
|
||||
import static org.springframework.http.HttpStatus.NOT_FOUND;
|
||||
import static org.springframework.http.HttpStatus.NO_CONTENT;
|
||||
import static org.springframework.http.HttpStatus.OK;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.alfresco.rest.RestTest;
|
||||
import org.alfresco.rest.model.RestRuleModel;
|
||||
import org.alfresco.rest.model.RestRuleModelsCollection;
|
||||
import org.alfresco.utility.model.FolderModel;
|
||||
import org.alfresco.utility.model.SiteModel;
|
||||
import org.alfresco.utility.model.TestGroup;
|
||||
import org.alfresco.utility.model.UserModel;
|
||||
import org.junit.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Tests for DELETE /nodes/{nodeId}/rule-sets/{ruleSetId}/rules/{ruleId}.
|
||||
*/
|
||||
@Test(groups = {TestGroup.RULES})
|
||||
public class DeleteRulesTests extends RestTest
|
||||
{
|
||||
private static final String FAKE_NODE_REF = "fake-node-id";
|
||||
|
||||
private UserModel user;
|
||||
private SiteModel site;
|
||||
|
||||
@BeforeClass(alwaysRun = true)
|
||||
public void dataPreparation()
|
||||
{
|
||||
STEP("Create a Contributor user and a public site");
|
||||
user = dataUser.createRandomTestUser();
|
||||
user.setUserRole(SiteContributor);
|
||||
site = dataSite.usingUser(user).createPublicRandomSite();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete previously created rule by its id (as Contributor).
|
||||
*/
|
||||
@Test(groups = {TestGroup.REST_API, TestGroup.RULES, TestGroup.SANITY})
|
||||
public void deleteSingleRuleAndGet204()
|
||||
{
|
||||
STEP("Create a few rules in the folder");
|
||||
final FolderModel ruleFolder = dataContent.usingUser(user).usingSite(site).createFolder();
|
||||
final List<RestRuleModel> createdRules = Stream.of("ruleA", "ruleB", "ruleC")
|
||||
.map(ruleName -> {
|
||||
RestRuleModel ruleModel = createRuleModel(ruleName);
|
||||
return restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet()
|
||||
.createSingleRule(ruleModel);
|
||||
})
|
||||
.collect(toList());
|
||||
|
||||
STEP("Attempt delete one rule");
|
||||
final RestRuleModel ruleA = createdRules.get(0);
|
||||
restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet().deleteRule(ruleA.getId());
|
||||
restClient.assertStatusCodeIs(NO_CONTENT);
|
||||
|
||||
STEP("Get and check the rules from the folder after deleting one of them");
|
||||
final RestRuleModelsCollection rulesAfterDeletion =
|
||||
restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet().getListOfRules();
|
||||
restClient.assertStatusCodeIs(OK);
|
||||
rulesAfterDeletion.assertThat().entriesListCountIs(createdRules.size() - 1);
|
||||
Assert.assertTrue(rulesAfterDeletion.getEntries()
|
||||
.stream()
|
||||
.noneMatch(r -> r.onModel().getId().equals(ruleA.getId()))
|
||||
);
|
||||
final Set<String> ruleIdsThatShouldBeLeft = createdRules.stream()
|
||||
.filter(r -> !r.getName().equals("ruleA"))
|
||||
.map(RestRuleModel::getId)
|
||||
.collect(Collectors.toSet());
|
||||
final Set<String> ruleIdsAfterDeletion = rulesAfterDeletion.getEntries().stream()
|
||||
.map(r -> r.onModel().getId())
|
||||
.collect(Collectors.toSet());
|
||||
Assert.assertEquals(ruleIdsThatShouldBeLeft, ruleIdsAfterDeletion);
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to delete a rule in a non-existing folder and get 404.
|
||||
*/
|
||||
@Test(groups = {TestGroup.REST_API, TestGroup.RULES})
|
||||
public void deleteRuleInNonExistingFolderAndGet404()
|
||||
{
|
||||
final FolderModel ruleFolder = dataContent.usingUser(user).usingSite(site).createFolder();
|
||||
final RestRuleModel testRule = createRule(ruleFolder);
|
||||
|
||||
STEP("Create a non-existing folder model");
|
||||
final FolderModel nonExistingFolder = new FolderModel();
|
||||
nonExistingFolder.setNodeRef(FAKE_NODE_REF);
|
||||
|
||||
STEP("Attempt delete the rule in non-existing folder");
|
||||
restClient.authenticateUser(user).withCoreAPI().usingNode(nonExistingFolder).usingDefaultRuleSet().deleteRule(testRule.getId());
|
||||
|
||||
restClient.assertLastError().statusCodeIs(NOT_FOUND);
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to delete a rule in a non-existing rule set and get 404.
|
||||
*/
|
||||
@Test(groups = {TestGroup.REST_API, TestGroup.RULES})
|
||||
public void deleteRuleInNonExistingRuleSetAndGet404()
|
||||
{
|
||||
final FolderModel ruleFolder = dataContent.usingUser(user).usingSite(site).createFolder();
|
||||
final RestRuleModel testRule = createRule(ruleFolder);
|
||||
|
||||
STEP("Attempt delete the rule in non-existing rule set");
|
||||
restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingRuleSet(FAKE_NODE_REF).deleteRule(testRule.getId());
|
||||
|
||||
restClient.assertLastError().statusCodeIs(NOT_FOUND);
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to delete a non-existing rule and get 404.
|
||||
*/
|
||||
@Test(groups = {TestGroup.REST_API, TestGroup.RULES, TestGroup.SANITY})
|
||||
public void deleteNonExistingRuleAndGet404()
|
||||
{
|
||||
final FolderModel ruleFolder = dataContent.usingUser(user).usingSite(site).createFolder();
|
||||
STEP("Attempt delete non-existing rule");
|
||||
restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet().deleteRule(FAKE_NODE_REF);
|
||||
|
||||
restClient.assertLastError().statusCodeIs(NOT_FOUND);
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to delete an existing rule passing a wrong but existing folder and get 404.
|
||||
*/
|
||||
@Test(groups = {TestGroup.REST_API, TestGroup.RULES, TestGroup.SANITY})
|
||||
public void deleteExistingRuleFromWrongFolderAndGet404()
|
||||
{
|
||||
final FolderModel ruleFolder = dataContent.usingUser(user).usingSite(site).createFolder();
|
||||
final RestRuleModel testRule = createRule(ruleFolder);
|
||||
|
||||
STEP("Create a second folder in the site");
|
||||
final FolderModel anotherFolder = dataContent.usingUser(user).usingSite(site).createFolder();
|
||||
|
||||
STEP("Attempt delete an existing rule from a wrong but existing (second) folder");
|
||||
restClient.authenticateUser(user).withCoreAPI().usingNode(anotherFolder).usingDefaultRuleSet().deleteRule(testRule.getId());
|
||||
|
||||
restClient.assertLastError().statusCodeIs(NOT_FOUND);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that a user without write permission on folder cannot delete a rule inside it.
|
||||
*/
|
||||
public void deleteSinglePrivateRuleWithoutPermissionAndGet403()
|
||||
{
|
||||
STEP("Create a user and use them to create a private site containing a folder with a rule");
|
||||
final UserModel privateUser = dataUser.createRandomTestUser();
|
||||
final SiteModel privateSite = dataSite.usingUser(privateUser).createPrivateRandomSite();
|
||||
final FolderModel privateFolder = dataContent.usingUser(privateUser).usingSite(privateSite).createFolder();
|
||||
final RestRuleModel ruleModel = createRuleModel("Private site rule");
|
||||
final RestRuleModel createdRule =
|
||||
restClient.authenticateUser(privateUser).withCoreAPI().usingNode(privateFolder).usingDefaultRuleSet()
|
||||
.createSingleRule(ruleModel);
|
||||
|
||||
STEP("Try to delete the rule with another user");
|
||||
restClient.authenticateUser(user).withCoreAPI().usingNode(privateFolder).usingDefaultRuleSet().deleteRule(createdRule.getId());
|
||||
|
||||
restClient.assertLastError().statusCodeIs(FORBIDDEN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that a user with SiteCollaborator permissions on folder can delete a rule inside it.
|
||||
*/
|
||||
public void deleteSinglePublicRuleAsCollaboratorAndGet403()
|
||||
{
|
||||
STEP("Create a user and use them to create a private site containing a folder with a rule");
|
||||
final FolderModel ruleFolder = dataContent.usingUser(user).usingSite(site).createFolder();
|
||||
final RestRuleModel testRule = createRule(ruleFolder);
|
||||
|
||||
STEP("Create a manager in the private site");
|
||||
final UserModel siteCollaborator = dataUser.createRandomTestUser();
|
||||
siteCollaborator.setUserRole(SiteCollaborator);
|
||||
restClient.authenticateUser(user).withCoreAPI().usingSite(site).addPerson(siteCollaborator);
|
||||
|
||||
STEP("Check the manager can delete the rule");
|
||||
restClient.authenticateUser(siteCollaborator).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet()
|
||||
.deleteRule(testRule.getId());
|
||||
|
||||
restClient.assertLastError().statusCodeIs(FORBIDDEN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that a user with SiteManager permissions on folder can delete a rule inside it.
|
||||
*/
|
||||
public void deleteSinglePrivateRuleAsSiteManagerAndGet204()
|
||||
{
|
||||
STEP("Create a user and use them to create a private site containing a folder with a rule");
|
||||
final UserModel privateUser = dataUser.createRandomTestUser();
|
||||
final SiteModel privateSite = dataSite.usingUser(privateUser).createPrivateRandomSite();
|
||||
final FolderModel privateFolder = dataContent.usingUser(privateUser).usingSite(privateSite).createFolder();
|
||||
final RestRuleModel ruleModel = createRuleModel("Private site rule");
|
||||
final RestRuleModel createdRule =
|
||||
restClient.authenticateUser(privateUser).withCoreAPI().usingNode(privateFolder).usingDefaultRuleSet()
|
||||
.createSingleRule(ruleModel);
|
||||
|
||||
STEP("Create a manager in the private site");
|
||||
final UserModel siteManager = dataUser.createRandomTestUser();
|
||||
siteManager.setUserRole(SiteManager);
|
||||
restClient.authenticateUser(privateUser).withCoreAPI().usingSite(privateSite).addPerson(siteManager);
|
||||
|
||||
STEP("Check the manager can delete the rule");
|
||||
restClient.authenticateUser(siteManager).withCoreAPI().usingNode(privateFolder).usingDefaultRuleSet()
|
||||
.deleteRule(createdRule.getId());
|
||||
|
||||
restClient.assertStatusCodeIs(NO_CONTENT);
|
||||
}
|
||||
|
||||
private RestRuleModel createRule(FolderModel ruleFolder)
|
||||
{
|
||||
STEP("Create a rule in the folder");
|
||||
final RestRuleModel ruleModel = createRuleModel("Test rule");
|
||||
return restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet().createSingleRule(ruleModel);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.rules;
|
||||
|
||||
import static org.alfresco.rest.rules.RulesTestsUtils.createRuleModel;
|
||||
import static org.alfresco.utility.report.log.Step.STEP;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.http.HttpStatus.NOT_FOUND;
|
||||
import static org.springframework.http.HttpStatus.OK;
|
||||
|
||||
import org.alfresco.rest.RestTest;
|
||||
import org.alfresco.rest.model.RestRuleModel;
|
||||
import org.alfresco.rest.model.RestRuleModelsCollection;
|
||||
import org.alfresco.rest.model.RestRuleSetModel;
|
||||
import org.alfresco.rest.model.RestRuleSetModelsCollection;
|
||||
import org.alfresco.utility.model.FolderModel;
|
||||
import org.alfresco.utility.model.SiteModel;
|
||||
import org.alfresco.utility.model.TestGroup;
|
||||
import org.alfresco.utility.model.UserModel;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Tests for GET /nodes/{nodeId}/rule-sets and /nodes/{nodeId}/rule-sets/{ruleSetId}.
|
||||
*/
|
||||
@Test (groups = { TestGroup.RULES })
|
||||
public class GetRuleSetsTests extends RestTest
|
||||
{
|
||||
private UserModel user;
|
||||
private SiteModel site;
|
||||
private FolderModel ruleFolder;
|
||||
private RestRuleModel rule;
|
||||
|
||||
@BeforeClass (alwaysRun = true)
|
||||
public void dataPreparation()
|
||||
{
|
||||
STEP("Create a user, site and folder.");
|
||||
user = dataUser.createRandomTestUser();
|
||||
site = dataSite.usingUser(user).createPublicRandomSite();
|
||||
ruleFolder = dataContent.usingUser(user).usingSite(site).createFolder();
|
||||
|
||||
STEP("Create a rule in the folder.");
|
||||
RestRuleModel ruleModel = createRuleModel("ruleName");
|
||||
rule = restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet()
|
||||
.createSingleRule(ruleModel);
|
||||
}
|
||||
|
||||
/** Check we can get an empty list of rule sets. */
|
||||
@Test (groups = { TestGroup.REST_API, TestGroup.RULES })
|
||||
public void getEmptyRuleSetsList()
|
||||
{
|
||||
STEP("Create a folder in existing site");
|
||||
FolderModel folder = dataContent.usingUser(user).usingSite(site).createFolder();
|
||||
|
||||
STEP("Get the rule sets for the folder");
|
||||
RestRuleSetModelsCollection ruleSets = restClient.authenticateUser(user).withCoreAPI()
|
||||
.usingNode(folder).getListOfRuleSets();
|
||||
|
||||
restClient.assertStatusCodeIs(OK);
|
||||
assertTrue("Expected no rule sets to be present.", ruleSets.isEmpty());
|
||||
}
|
||||
|
||||
/** Check we can get a list of rule sets. */
|
||||
@Test (groups = { TestGroup.REST_API, TestGroup.RULES, TestGroup.SANITY })
|
||||
public void getRuleSetsList()
|
||||
{
|
||||
STEP("Get the rule sets for the folder");
|
||||
RestRuleSetModelsCollection ruleSets = restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder)
|
||||
.getListOfRuleSets();
|
||||
|
||||
restClient.assertStatusCodeIs(OK);
|
||||
ruleSets.assertThat().entriesListCountIs(1);
|
||||
ruleSets.getEntries().get(0).onModel()
|
||||
.assertThat().field("id").isNotNull();
|
||||
}
|
||||
|
||||
/** Check we get a 404 if trying to load rule sets for a folder that doesn't exist. */
|
||||
@Test (groups = { TestGroup.REST_API, TestGroup.RULES })
|
||||
public void getRuleSetsForNonExistentFolder()
|
||||
{
|
||||
STEP("Try to load rule sets for a non-existent folder.");
|
||||
FolderModel nonExistentFolder = FolderModel.getRandomFolderModel();
|
||||
nonExistentFolder.setNodeRef("fake-id");
|
||||
restClient.authenticateUser(user).withCoreAPI().usingNode(nonExistentFolder).getListOfRuleSets();
|
||||
restClient.assertStatusCodeIs(NOT_FOUND);
|
||||
}
|
||||
|
||||
/** Check we can get a rule set by its id. */
|
||||
@Test (groups = { TestGroup.REST_API, TestGroup.RULES, TestGroup.SANITY })
|
||||
public void getRuleSetById()
|
||||
{
|
||||
STEP("Get the rule sets for the folder and find the rule set id");
|
||||
RestRuleSetModelsCollection ruleSets = restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder)
|
||||
.getListOfRuleSets();
|
||||
ruleSets.assertThat().entriesListCountIs(1);
|
||||
String ruleSetId = ruleSets.getEntries().get(0).onModel().getId();
|
||||
|
||||
STEP("Get the rule set using its rule set id");
|
||||
RestRuleSetModel ruleSet = restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder)
|
||||
.getRuleSet(ruleSetId);
|
||||
|
||||
restClient.assertStatusCodeIs(OK);
|
||||
ruleSet.assertThat().field("id").is(ruleSetId);
|
||||
}
|
||||
|
||||
/** Check we can get a rule set using the "-default-" synonym. */
|
||||
@Test (groups = { TestGroup.REST_API, TestGroup.RULES })
|
||||
public void getDefaultRuleSetById()
|
||||
{
|
||||
STEP("Get the default rule set for the folder");
|
||||
RestRuleSetModel ruleSet = restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder)
|
||||
.getDefaultRuleSet();
|
||||
|
||||
restClient.assertStatusCodeIs(OK);
|
||||
ruleSet.assertThat().field("id").isNotNull();
|
||||
}
|
||||
|
||||
/** Check we get a 404 if trying to load the default rule set for a folder that doesn't exist. */
|
||||
@Test (groups = { TestGroup.REST_API, TestGroup.RULES })
|
||||
public void getDefaultRuleSetForNonExistentFolder()
|
||||
{
|
||||
STEP("Try to load a rule set for a non-existent folder.");
|
||||
FolderModel nonExistentFolder = FolderModel.getRandomFolderModel();
|
||||
nonExistentFolder.setNodeRef("fake-id");
|
||||
restClient.authenticateUser(user).withCoreAPI().usingNode(nonExistentFolder).getDefaultRuleSet();
|
||||
restClient.assertStatusCodeIs(NOT_FOUND);
|
||||
}
|
||||
|
||||
/** Check we get 404 for a non-existing rule set id. */
|
||||
@Test (groups = { TestGroup.REST_API, TestGroup.RULES, TestGroup.SANITY })
|
||||
public void getRuleSetByNonExistingId()
|
||||
{
|
||||
STEP("Get the rule set using fake rule set id");
|
||||
String ruleSetId = "fake-rule-set-id";
|
||||
restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).getRuleSet(ruleSetId);
|
||||
restClient.assertStatusCodeIs(NOT_FOUND);
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ package org.alfresco.rest.rules;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import static org.alfresco.rest.rules.RulesTestsUtils.createRuleModel;
|
||||
import static org.alfresco.utility.constants.UserRole.SiteCollaborator;
|
||||
import static org.alfresco.utility.report.log.Step.STEP;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -70,8 +71,7 @@ public class GetRulesTests extends RestTest
|
||||
|
||||
STEP("Create rules in the folder");
|
||||
createdRules = Stream.of("ruleA", "ruleB").map(ruleName -> {
|
||||
RestRuleModel ruleModel = new RestRuleModel();
|
||||
ruleModel.setName(ruleName);
|
||||
RestRuleModel ruleModel = createRuleModel(ruleName);
|
||||
return restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet().createSingleRule(ruleModel);
|
||||
}).collect(toList());
|
||||
createdRuleA = createdRules.get(0);
|
||||
@@ -87,7 +87,7 @@ public class GetRulesTests extends RestTest
|
||||
STEP("Get the rules that apply to the folder");
|
||||
RestRuleModelsCollection rules = restClient.authenticateUser(user).withCoreAPI().usingNode(folder).usingDefaultRuleSet().getListOfRules();
|
||||
|
||||
restClient.assertStatusCodeIs(OK);
|
||||
restClient.assertStatusCodeIs(NOT_FOUND);
|
||||
assertTrue("Expected no rules to be present.", rules.isEmpty());
|
||||
}
|
||||
|
||||
@@ -163,6 +163,17 @@ public class GetRulesTests extends RestTest
|
||||
restClient.assertStatusCodeIs(NOT_FOUND);
|
||||
}
|
||||
|
||||
/** Check we get a 404 if trying to load an existing rule providing a wrong but existing folder */
|
||||
@Test (groups = { TestGroup.REST_API, TestGroup.RULES })
|
||||
public void getSingleRuleFromWrongFolder()
|
||||
{
|
||||
STEP("Create a folder in existing site");
|
||||
FolderModel folder = dataContent.usingUser(user).usingSite(site).createFolder();
|
||||
STEP("Try to load a rule for a wrong but existing folder.");
|
||||
restClient.authenticateUser(user).withCoreAPI().usingNode(folder).usingDefaultRuleSet().getSingleRule(createdRuleA.getId());
|
||||
restClient.assertStatusCodeIs(NOT_FOUND);
|
||||
}
|
||||
|
||||
/** Check that a user without read permission cannot view the folder rules. */
|
||||
public void requireReadPermissionToGetRule()
|
||||
{
|
||||
@@ -189,8 +200,7 @@ public class GetRulesTests extends RestTest
|
||||
UserModel privateUser = dataUser.createRandomTestUser();
|
||||
SiteModel privateSite = dataSite.usingUser(privateUser).createPrivateRandomSite();
|
||||
FolderModel privateFolder = dataContent.usingUser(privateUser).usingSite(privateSite).createFolder();
|
||||
RestRuleModel ruleModel = new RestRuleModel();
|
||||
ruleModel.setName("Private site rule");
|
||||
RestRuleModel ruleModel = createRuleModel("Private site rule");
|
||||
restClient.authenticateUser(privateUser).withCoreAPI().usingNode(privateFolder).usingDefaultRuleSet().createSingleRule(ruleModel);
|
||||
|
||||
STEP("Create a collaborator in the private site");
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.rules;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.rest.model.RestActionBodyExecTemplateModel;
|
||||
import org.alfresco.rest.model.RestRuleModel;
|
||||
|
||||
public class RulesTestsUtils
|
||||
{
|
||||
|
||||
public static RestRuleModel createRuleModel(String name) {
|
||||
return createRuleModel(name, List.of(createActionModel()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a rule model.
|
||||
*
|
||||
* @param name The name for the rule.
|
||||
* @param restActionModels Rule's actions.
|
||||
* @return The created rule model.
|
||||
*/
|
||||
public static RestRuleModel createRuleModel(String name, List<RestActionBodyExecTemplateModel> restActionModels)
|
||||
{
|
||||
RestRuleModel ruleModel = new RestRuleModel();
|
||||
ruleModel.setName(name);
|
||||
ruleModel.setActions(restActionModels);
|
||||
return ruleModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a rule's action model.
|
||||
*
|
||||
* @return The created action model.
|
||||
*/
|
||||
public static RestActionBodyExecTemplateModel createActionModel()
|
||||
{
|
||||
RestActionBodyExecTemplateModel restActionModel = new RestActionBodyExecTemplateModel();
|
||||
restActionModel.setActionDefinitionId("add-features");
|
||||
restActionModel.setParams(Map.of("aspect-name", "{http://www.alfresco.org/model/audio/1.0}audio", "actionContext", "rule"));
|
||||
return restActionModel;
|
||||
}
|
||||
}
|
||||
@@ -25,19 +25,20 @@
|
||||
*/
|
||||
package org.alfresco.rest.rules;
|
||||
|
||||
import static org.alfresco.rest.rules.RulesTestsUtils.createActionModel;
|
||||
import static org.alfresco.rest.rules.RulesTestsUtils.createRuleModel;
|
||||
import static org.alfresco.utility.constants.UserRole.SiteCollaborator;
|
||||
import static org.alfresco.utility.report.log.Step.STEP;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.springframework.http.HttpStatus.BAD_REQUEST;
|
||||
import static org.springframework.http.HttpStatus.CREATED;
|
||||
import static org.springframework.http.HttpStatus.FORBIDDEN;
|
||||
import static org.springframework.http.HttpStatus.NOT_FOUND;
|
||||
import static org.springframework.http.HttpStatus.OK;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.rest.RestTest;
|
||||
import org.alfresco.rest.model.RestActionBodyExecTemplateModel;
|
||||
import org.alfresco.rest.model.RestRuleModel;
|
||||
import org.alfresco.rest.model.RestRuleSetModel;
|
||||
import org.alfresco.utility.constants.UserRole;
|
||||
import org.alfresco.utility.model.FolderModel;
|
||||
import org.alfresco.utility.model.SiteModel;
|
||||
import org.alfresco.utility.model.TestGroup;
|
||||
@@ -67,11 +68,10 @@ public class UpdateRulesTests extends RestTest
|
||||
@Test (groups = { TestGroup.REST_API, TestGroup.RULES, TestGroup.SANITY })
|
||||
public void updateRule()
|
||||
{
|
||||
RestRuleModel rule = createRule("Rule name");
|
||||
RestRuleModel rule = createAndSaveRule("Rule name");
|
||||
|
||||
STEP("Try to update the rule.");
|
||||
RestRuleModel updatedRuleModel = new RestRuleModel();
|
||||
updatedRuleModel.setName("Updated rule name");
|
||||
RestRuleModel updatedRuleModel = createRuleModel("Updated rule name");
|
||||
RestRuleModel updatedRule = restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet()
|
||||
.updateRule(rule.getId(), updatedRuleModel);
|
||||
|
||||
@@ -84,7 +84,7 @@ public class UpdateRulesTests extends RestTest
|
||||
@Test (groups = { TestGroup.REST_API, TestGroup.RULES })
|
||||
public void updateRuleForNonExistentFolder()
|
||||
{
|
||||
RestRuleModel rule = createRule("Rule name");
|
||||
RestRuleModel rule = createAndSaveRule("Rule name");
|
||||
|
||||
STEP("Try to update a rule in a non-existent folder.");
|
||||
FolderModel nonExistentFolder = FolderModel.getRandomFolderModel();
|
||||
@@ -103,7 +103,7 @@ public class UpdateRulesTests extends RestTest
|
||||
@Test (groups = { TestGroup.REST_API, TestGroup.RULES })
|
||||
public void updateRuleForNonExistentRuleSet()
|
||||
{
|
||||
RestRuleModel rule = createRule("Rule name");
|
||||
RestRuleModel rule = createAndSaveRule("Rule name");
|
||||
|
||||
STEP("Try to update a rule in a non-existent rule set.");
|
||||
RestRuleModel updatedRuleModel = new RestRuleModel();
|
||||
@@ -153,7 +153,7 @@ public class UpdateRulesTests extends RestTest
|
||||
@Test (groups = { TestGroup.REST_API, TestGroup.RULES })
|
||||
public void updateRuleToHaveEmptyName()
|
||||
{
|
||||
RestRuleModel rule = createRule("Rule name");
|
||||
RestRuleModel rule = createAndSaveRule("Rule name");
|
||||
|
||||
STEP("Try to update the rule to have no name.");
|
||||
RestRuleModel updatedRuleModel = new RestRuleModel();
|
||||
@@ -168,30 +168,34 @@ public class UpdateRulesTests extends RestTest
|
||||
@Test (groups = { TestGroup.REST_API, TestGroup.RULES })
|
||||
public void tryToUpdateRuleId()
|
||||
{
|
||||
RestRuleModel rule = createRule("Rule name");
|
||||
RestRuleModel rule = createAndSaveRule("Rule name");
|
||||
|
||||
STEP("Try to update the rule id and check it isn't changed.");
|
||||
RestRuleModel updatedRuleModel = new RestRuleModel();
|
||||
RestRuleModel updatedRuleModel = createRuleModel("Rule name");
|
||||
updatedRuleModel.setId("new-rule-id");
|
||||
updatedRuleModel.setName("Rule name");
|
||||
RestRuleModel updatedRule = restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet()
|
||||
.updateRule(rule.getId(), updatedRuleModel);
|
||||
|
||||
updatedRule.assertThat().field("id").is(rule.getId());
|
||||
}
|
||||
|
||||
private RestRuleModel createAndSaveRule(String name)
|
||||
{
|
||||
return createAndSaveRule(name, List.of(createActionModel()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a rule.
|
||||
* Create a rule for folder and store it.
|
||||
*
|
||||
* @param name The name for the rule.
|
||||
* @param restActionModels Rule's actions.
|
||||
* @return The created rule.
|
||||
*/
|
||||
private RestRuleModel createRule(String name)
|
||||
private RestRuleModel createAndSaveRule(String name, List<RestActionBodyExecTemplateModel> restActionModels)
|
||||
{
|
||||
STEP("Create a rule called " + name);
|
||||
RestRuleModel ruleModel = new RestRuleModel();
|
||||
ruleModel.setName(name);
|
||||
STEP("Create a rule called " + name + ", containing actions: " + restActionModels);
|
||||
RestRuleModel ruleModel = createRuleModel(name, restActionModels);
|
||||
return restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet()
|
||||
.createSingleRule(ruleModel);
|
||||
.createSingleRule(ruleModel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo-tests</artifactId>
|
||||
<version>17.58</version>
|
||||
<version>17.75-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<developers>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo-packaging</artifactId>
|
||||
<version>17.58</version>
|
||||
<version>17.75-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
|
||||
35
pom.xml
35
pom.xml
@@ -2,7 +2,7 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>alfresco-community-repo</artifactId>
|
||||
<version>17.58</version>
|
||||
<version>17.75-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>Alfresco Community Repo Parent</name>
|
||||
|
||||
@@ -53,10 +53,10 @@
|
||||
<dependency.activiti.version>5.23.0</dependency.activiti.version>
|
||||
<dependency.alfresco-transform-service.version>1.5.3</dependency.alfresco-transform-service.version>
|
||||
<dependency.alfresco-transform-core.version>2.6.0</dependency.alfresco-transform-core.version>
|
||||
<dependency.alfresco-greenmail.version>6.2</dependency.alfresco-greenmail.version>
|
||||
<dependency.acs-event-model.version>0.0.15</dependency.acs-event-model.version>
|
||||
<dependency.alfresco-greenmail.version>6.4</dependency.alfresco-greenmail.version>
|
||||
<dependency.acs-event-model.version>0.0.16</dependency.acs-event-model.version>
|
||||
|
||||
<dependency.spring.version>5.3.21</dependency.spring.version>
|
||||
<dependency.spring.version>5.3.22</dependency.spring.version>
|
||||
<dependency.antlr.version>3.5.2</dependency.antlr.version>
|
||||
<dependency.jackson.version>2.13.3</dependency.jackson.version>
|
||||
<dependency.jackson-databind.version>2.13.3</dependency.jackson-databind.version>
|
||||
@@ -76,7 +76,7 @@
|
||||
<dependency.xercesImpl.version>2.12.2</dependency.xercesImpl.version>
|
||||
<dependency.slf4j.version>1.7.35</dependency.slf4j.version>
|
||||
<dependency.gytheio.version>0.16</dependency.gytheio.version>
|
||||
<dependency.groovy.version>3.0.11</dependency.groovy.version>
|
||||
<dependency.groovy.version>3.0.12</dependency.groovy.version>
|
||||
<dependency.tika.version>2.4.1</dependency.tika.version>
|
||||
<dependency.spring-security.version>5.7.2</dependency.spring-security.version>
|
||||
<dependency.truezip.version>7.7.10</dependency.truezip.version>
|
||||
@@ -114,13 +114,13 @@
|
||||
<alfresco.maven-plugin.version>2.2.0</alfresco.maven-plugin.version>
|
||||
<license-maven-plugin.version>2.0.1.alfresco-2</license-maven-plugin.version>
|
||||
|
||||
<dependency.postgresql.version>42.4.0</dependency.postgresql.version>
|
||||
<dependency.mysql.version>8.0.29</dependency.mysql.version>
|
||||
<dependency.postgresql.version>42.4.1</dependency.postgresql.version>
|
||||
<dependency.mysql.version>8.0.30</dependency.mysql.version>
|
||||
<dependency.mysql-image.version>8</dependency.mysql-image.version>
|
||||
<dependency.mariadb.version>2.7.4</dependency.mariadb.version>
|
||||
<dependency.tas-utility.version>3.0.49</dependency.tas-utility.version>
|
||||
<dependency.rest-assured.version>3.3.0</dependency.rest-assured.version>
|
||||
<dependency.tas-restapi.version>1.97</dependency.tas-restapi.version>
|
||||
<dependency.tas-restapi.version>1.101</dependency.tas-restapi.version>
|
||||
<dependency.tas-cmis.version>1.31</dependency.tas-cmis.version>
|
||||
<dependency.tas-email.version>1.8</dependency.tas-email.version>
|
||||
<dependency.tas-webdav.version>1.6</dependency.tas-webdav.version>
|
||||
@@ -148,7 +148,7 @@
|
||||
<connection>scm:git:https://github.com/Alfresco/alfresco-community-repo.git</connection>
|
||||
<developerConnection>scm:git:https://github.com/Alfresco/alfresco-community-repo.git</developerConnection>
|
||||
<url>https://github.com/Alfresco/alfresco-community-repo</url>
|
||||
<tag>17.58</tag>
|
||||
<tag>HEAD</tag>
|
||||
</scm>
|
||||
|
||||
<distributionManagement>
|
||||
@@ -877,6 +877,17 @@
|
||||
<version>1.18.24</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.activiti</groupId>
|
||||
<artifactId>activiti-spring</artifactId>
|
||||
<version>${dependency.activiti.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>commons-dbcp</groupId>
|
||||
<artifactId>commons-dbcp</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
@@ -894,7 +905,7 @@
|
||||
<plugin>
|
||||
<groupId>io.fabric8</groupId>
|
||||
<artifactId>docker-maven-plugin</artifactId>
|
||||
<version>0.40.1</version>
|
||||
<version>0.40.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
@@ -920,7 +931,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<version>3.3.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
@@ -929,7 +940,7 @@
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>3.4.1</version>
|
||||
<version>3.4.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.alfresco.maven.plugin</groupId>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo</artifactId>
|
||||
<version>17.58</version>
|
||||
<version>17.75-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
@@ -130,7 +130,7 @@
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-server</artifactId>
|
||||
<version>8.2.0.v20160908</version>
|
||||
<version>10.0.11</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
@@ -142,19 +142,19 @@
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-security</artifactId>
|
||||
<version>8.2.0.v20160908</version>
|
||||
<version>10.0.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-webapp</artifactId>
|
||||
<version>8.2.0.v20160908</version>
|
||||
<version>10.0.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.alfresco.cmis.client</groupId>
|
||||
<artifactId>alfresco-opencmis-extension</artifactId>
|
||||
<version>2.0</version>
|
||||
<version>2.1</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<!-- Duplicates classes from jakarta.transaction:jakarta.transaction-api -->
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts;
|
||||
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.MimetypeService;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
|
||||
public class MimeTypeUtil
|
||||
{
|
||||
|
||||
/**
|
||||
* Get the file mimetype from the file ContentReader, and if its null then set the mimetype to binary by default
|
||||
* and try to get the correct one from file extension
|
||||
*
|
||||
*
|
||||
* @param reader reader of the file in the request
|
||||
* @param req request relating to the file
|
||||
* @param mimetypeService MimetypeService
|
||||
*
|
||||
* @return mimetype of the file as a string
|
||||
*/
|
||||
public static String determineMimetype(ContentReader reader, WebScriptRequest req, MimetypeService mimetypeService)
|
||||
{
|
||||
String mimetype = reader.getMimetype();
|
||||
if (mimetype == null || mimetype.length() == 0)
|
||||
{
|
||||
String extensionPath = req.getExtensionPath();
|
||||
mimetype = MimetypeMap.MIMETYPE_BINARY;
|
||||
int extIndex = extensionPath.lastIndexOf('.');
|
||||
if (extIndex != -1)
|
||||
{
|
||||
String ext = extensionPath.substring(extIndex + 1);
|
||||
mimetype = mimetypeService.getMimetype(ext);
|
||||
}
|
||||
}
|
||||
return mimetype;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
@@ -26,14 +26,18 @@
|
||||
package org.alfresco.repo.web.scripts.content;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.web.scripts.MimeTypeUtil;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
@@ -65,6 +69,19 @@ public class ContentGet extends StreamContent implements ServletContextAware
|
||||
private NamespaceService namespaceService;
|
||||
private ContentService contentService;
|
||||
|
||||
private List<String> nonAttachContentTypes = Collections.emptyList();
|
||||
|
||||
/**
|
||||
* @param nonAttachContentTypes List<String>
|
||||
*/
|
||||
public void setNonAttachContentTypes(List<String> nonAttachContentTypes)
|
||||
{
|
||||
if (nonAttachContentTypes != null && !nonAttachContentTypes.isEmpty())
|
||||
{
|
||||
this.nonAttachContentTypes = nonAttachContentTypes;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param servletContext ServletContext
|
||||
*/
|
||||
@@ -121,9 +138,7 @@ public class ContentGet extends StreamContent implements ServletContextAware
|
||||
{
|
||||
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find " + reference.toString());
|
||||
}
|
||||
|
||||
// determine attachment
|
||||
boolean attach = Boolean.valueOf(req.getParameter("a"));
|
||||
|
||||
|
||||
// render content
|
||||
QName propertyQName = ContentModel.PROP_CONTENT;
|
||||
@@ -140,6 +155,19 @@ public class ContentGet extends StreamContent implements ServletContextAware
|
||||
propertyQName = QName.createQName(propertyName, namespaceService);
|
||||
}
|
||||
}
|
||||
// determine attachment and force download for specific mimetypes - see PRODSEC-5862
|
||||
boolean attach = Boolean.valueOf(req.getParameter("a"));
|
||||
ContentReader reader = contentService.getReader(nodeRef, propertyQName);
|
||||
String mimetype = MimeTypeUtil.determineMimetype(reader, req, mimetypeService);
|
||||
|
||||
if (!attach)
|
||||
{
|
||||
if (nonAttachContentTypes == null || !nonAttachContentTypes.contains(mimetype))
|
||||
{
|
||||
attach = true;
|
||||
logger.warn("Ignored a=false for " + nodeRef.getId() + " since " + mimetype + " is not in the whitelist for non-attach content types");
|
||||
}
|
||||
}
|
||||
|
||||
// Stream the content
|
||||
streamContentLocal(req, res, nodeRef, attach, propertyQName, null);
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.content;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -33,7 +33,7 @@ import java.util.Map;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.web.scripts.MimeTypeUtil;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
@@ -79,18 +79,7 @@ public class ContentInfo extends StreamContent
|
||||
delegate.setAttachment(req, res, attach, attachFileName);
|
||||
|
||||
// establish mimetype
|
||||
String mimetype = reader.getMimetype();
|
||||
String extensionPath = req.getExtensionPath();
|
||||
if (mimetype == null || mimetype.length() == 0)
|
||||
{
|
||||
mimetype = MimetypeMap.MIMETYPE_BINARY;
|
||||
int extIndex = extensionPath.lastIndexOf('.');
|
||||
if (extIndex != -1)
|
||||
{
|
||||
String ext = extensionPath.substring(extIndex + 1);
|
||||
mimetype = mimetypeService.getMimetype(ext);
|
||||
}
|
||||
}
|
||||
String mimetype = MimeTypeUtil.determineMimetype(reader, req, mimetypeService);
|
||||
|
||||
// set mimetype for the content and the character encoding + length for the stream
|
||||
res.setContentType(mimetype);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
@@ -43,6 +43,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.content.filestore.FileContentReader;
|
||||
import org.alfresco.repo.web.scripts.MimeTypeUtil;
|
||||
import org.alfresco.sync.repo.events.EventPublisher;
|
||||
import org.alfresco.repo.web.util.HttpRangeProcessor;
|
||||
import org.alfresco.rest.framework.resource.content.CacheDirective;
|
||||
@@ -361,18 +362,7 @@ public class ContentStreamer implements ResourceLoaderAware
|
||||
setAttachment(req, res, attach, attachFileName);
|
||||
|
||||
// establish mimetype
|
||||
String mimetype = reader.getMimetype();
|
||||
String extensionPath = req.getExtensionPath();
|
||||
if (mimetype == null || mimetype.length() == 0)
|
||||
{
|
||||
mimetype = MimetypeMap.MIMETYPE_BINARY;
|
||||
int extIndex = extensionPath.lastIndexOf('.');
|
||||
if (extIndex != -1)
|
||||
{
|
||||
String ext = extensionPath.substring(extIndex + 1);
|
||||
mimetype = mimetypeService.getMimetype(ext);
|
||||
}
|
||||
}
|
||||
String mimetype = MimeTypeUtil.determineMimetype(reader, req, mimetypeService);
|
||||
|
||||
res.setHeader(HEADER_ACCEPT_RANGES, "bytes");
|
||||
try
|
||||
|
||||
61
remote-api/src/main/java/org/alfresco/rest/api/RuleSets.java
Normal file
61
remote-api/src/main/java/org/alfresco/rest/api/RuleSets.java
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.api;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.rest.api.model.rules.Rule;
|
||||
import org.alfresco.rest.api.model.rules.RuleSet;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Paging;
|
||||
import org.alfresco.service.Experimental;
|
||||
|
||||
/**
|
||||
* Rule sets API.
|
||||
*/
|
||||
@Experimental
|
||||
public interface RuleSets
|
||||
{
|
||||
/**
|
||||
* Get rule sets for a folder.
|
||||
*
|
||||
* @param folderNodeId Folder node ID
|
||||
* @param paging {@link Paging} information
|
||||
* @param includes List of fields to include in the rule set
|
||||
* @return {@link CollectionWithPagingInfo} containing a list page of rule sets
|
||||
*/
|
||||
CollectionWithPagingInfo<RuleSet> getRuleSets(String folderNodeId, List<String> includes, Paging paging);
|
||||
|
||||
/**
|
||||
* Get the rule set with the given ID and check associations with the folder node.
|
||||
*
|
||||
* @param folderNodeId Folder node ID
|
||||
* @param ruleSetId Rule set ID
|
||||
* @param includes List of fields to include in the rule set
|
||||
* @return {@link RuleSet} definition
|
||||
*/
|
||||
RuleSet getRuleSetById(String folderNodeId, String ruleSetId, List<String> includes);
|
||||
}
|
||||
@@ -23,122 +23,33 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api.impl;
|
||||
package org.alfresco.rest.api.impl.rules;
|
||||
|
||||
import static org.alfresco.service.cmr.security.AccessStatus.ALLOWED;
|
||||
import static org.alfresco.service.cmr.security.PermissionService.CHANGE_PERMISSIONS;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.rule.RuleModel;
|
||||
import org.alfresco.rest.api.Nodes;
|
||||
import org.alfresco.rest.api.Rules;
|
||||
import org.alfresco.rest.api.model.rules.Rule;
|
||||
import org.alfresco.rest.api.model.rules.RuleSet;
|
||||
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
|
||||
import org.alfresco.rest.framework.core.exceptions.PermissionDeniedException;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.ListPage;
|
||||
import org.alfresco.rest.framework.resource.parameters.Paging;
|
||||
import org.alfresco.service.Experimental;
|
||||
import org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.rule.RuleService;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@Experimental
|
||||
public class RulesImpl implements Rules
|
||||
/** Responsible for validating nodes when working with rules. */
|
||||
public class NodeValidator
|
||||
{
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(RulesImpl.class);
|
||||
private static final String RULE_SET_EXPECTED_TYPE_NAME = "rule set";
|
||||
|
||||
private Nodes nodes;
|
||||
|
||||
private PermissionService permissionService;
|
||||
|
||||
private RuleService ruleService;
|
||||
|
||||
@Override
|
||||
public CollectionWithPagingInfo<Rule> getRules(final String folderNodeId, final String ruleSetId, final Paging paging)
|
||||
{
|
||||
final NodeRef folderNodeRef = validateFolderNode(folderNodeId, false);
|
||||
final NodeRef ruleSetNodeRef = validateRuleSetNode(ruleSetId, folderNodeRef);
|
||||
|
||||
final boolean isShared = isRuleSetNotNullAndShared(ruleSetNodeRef);
|
||||
final List<Rule> rules = ruleService.getRules(folderNodeRef).stream()
|
||||
.map(ruleModel -> Rule.from(ruleModel, isShared))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return ListPage.of(rules, paging);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rule getRuleById(final String folderNodeId, final String ruleSetId, final String ruleId)
|
||||
{
|
||||
final NodeRef folderNodeRef = validateFolderNode(folderNodeId, false);
|
||||
final NodeRef ruleSetNodeRef = validateRuleSetNode(ruleSetId, folderNodeRef);
|
||||
final NodeRef ruleNodeRef = validateRuleNode(ruleId, ruleSetNodeRef);
|
||||
|
||||
return Rule.from(ruleService.getRule(ruleNodeRef), isRuleSetNotNullAndShared(ruleSetNodeRef));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Rule> createRules(final String folderNodeId, final String ruleSetId, final List<Rule> rules)
|
||||
{
|
||||
final NodeRef folderNodeRef = validateFolderNode(folderNodeId, true);
|
||||
// Don't validate the ruleset node if -default- is passed since we may need to create it.
|
||||
final NodeRef ruleSetNodeRef = (RuleSet.isNotDefaultId(ruleSetId)) ? validateRuleSetNode(ruleSetId, folderNodeRef) : null;
|
||||
|
||||
return rules.stream()
|
||||
.map(rule -> rule.toServiceModel(nodes))
|
||||
.map(rule -> ruleService.saveRule(folderNodeRef, rule))
|
||||
.map(rule -> Rule.from(rule, isRuleSetNotNullAndShared(ruleSetNodeRef, folderNodeRef)))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rule updateRuleById(String folderNodeId, String ruleSetId, String ruleId, Rule rule)
|
||||
{
|
||||
LOGGER.debug("Updating rule in folder {}, rule set {}, rule {} to {}", folderNodeId, ruleSetId, ruleId, rule);
|
||||
|
||||
NodeRef folderNodeRef = validateFolderNode(folderNodeId, true);
|
||||
NodeRef ruleSetNodeRef = validateRuleSetNode(ruleSetId, folderNodeRef);
|
||||
validateRuleNode(ruleId, ruleSetNodeRef);
|
||||
|
||||
boolean shared = isRuleSetNotNullAndShared(ruleSetNodeRef, folderNodeRef);
|
||||
return Rule.from(ruleService.saveRule(folderNodeRef, rule.toServiceModel(nodes)), shared);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteRuleById(String folderNodeId, String ruleSetId, String ruleId)
|
||||
{
|
||||
final NodeRef folderNodeRef = validateFolderNode(folderNodeId, true);
|
||||
final NodeRef ruleSetNodeRef = validateRuleSetNode(ruleSetId, folderNodeRef);
|
||||
final NodeRef ruleNodeRef = validateRuleNode(ruleId, ruleSetNodeRef);
|
||||
final org.alfresco.service.cmr.rule.Rule rule = ruleService.getRule(ruleNodeRef);
|
||||
ruleService.removeRule(folderNodeRef, rule);
|
||||
}
|
||||
|
||||
public void setNodes(Nodes nodes)
|
||||
{
|
||||
this.nodes = nodes;
|
||||
}
|
||||
|
||||
public void setPermissionService(PermissionService permissionService)
|
||||
{
|
||||
this.permissionService = permissionService;
|
||||
}
|
||||
|
||||
public void setRuleService(RuleService ruleService)
|
||||
{
|
||||
this.ruleService = ruleService;
|
||||
}
|
||||
private PermissionService permissionService;
|
||||
|
||||
/**
|
||||
* Validates if folder node exists and the user has permission to use it.
|
||||
@@ -149,7 +60,7 @@ public class RulesImpl implements Rules
|
||||
* @throws InvalidArgumentException if node is not of an expected type
|
||||
* @throws PermissionDeniedException if the user doesn't have the appropriate permission for the folder.
|
||||
*/
|
||||
private NodeRef validateFolderNode(final String folderNodeId, boolean requireChangePermission)
|
||||
public NodeRef validateFolderNode(final String folderNodeId, boolean requireChangePermission)
|
||||
{
|
||||
final NodeRef nodeRef = nodes.validateOrLookupNode(folderNodeId, null);
|
||||
if (requireChangePermission)
|
||||
@@ -179,21 +90,29 @@ public class RulesImpl implements Rules
|
||||
* @return rule set node reference
|
||||
* @throws InvalidArgumentException in case of not matching associated folder node
|
||||
*/
|
||||
private NodeRef validateRuleSetNode(final String ruleSetId, final NodeRef associatedFolderNodeRef)
|
||||
public NodeRef validateRuleSetNode(final String ruleSetId, final NodeRef associatedFolderNodeRef)
|
||||
{
|
||||
if (RuleSet.isDefaultId(ruleSetId))
|
||||
{
|
||||
return ruleService.getRuleSetNode(associatedFolderNodeRef);
|
||||
final NodeRef ruleSetNodeRef = ruleService.getRuleSetNode(associatedFolderNodeRef);
|
||||
if (ruleSetNodeRef == null)
|
||||
{
|
||||
//folder doesn't have a -default- rule set
|
||||
throw new RelationshipResourceNotFoundException(associatedFolderNodeRef.getId(), ruleSetId);
|
||||
}
|
||||
return ruleSetNodeRef;
|
||||
}
|
||||
|
||||
final NodeRef ruleSetNodeRef = validateNode(ruleSetId, ContentModel.TYPE_SYSTEM_FOLDER, RULE_SET_EXPECTED_TYPE_NAME);
|
||||
if (!ruleService.isRuleSetAssociatedWithFolder(ruleSetNodeRef, associatedFolderNodeRef)) {
|
||||
if (!ruleService.isRuleSetAssociatedWithFolder(ruleSetNodeRef, associatedFolderNodeRef))
|
||||
{
|
||||
throw new InvalidArgumentException("Rule set is not associated with folder node!");
|
||||
}
|
||||
|
||||
return ruleSetNodeRef;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Validates if rule node exists and associated rule set node matches.
|
||||
*
|
||||
@@ -202,7 +121,7 @@ public class RulesImpl implements Rules
|
||||
* @return rule node reference
|
||||
* @throws InvalidArgumentException in case of not matching associated rule set node
|
||||
*/
|
||||
private NodeRef validateRuleNode(final String ruleId, final NodeRef associatedRuleSetNodeRef)
|
||||
public NodeRef validateRuleNode(final String ruleId, final NodeRef associatedRuleSetNodeRef)
|
||||
{
|
||||
final NodeRef ruleNodeRef = validateNode(ruleId, RuleModel.TYPE_RULE, null);
|
||||
if (associatedRuleSetNodeRef != null && !ruleService.isRuleAssociatedWithRuleSet(ruleNodeRef, associatedRuleSetNodeRef))
|
||||
@@ -224,13 +143,14 @@ public class RulesImpl implements Rules
|
||||
private void verifyNodeType(final NodeRef nodeRef, final QName expectedType, final String expectedTypeName)
|
||||
{
|
||||
final Set<QName> expectedTypes = Set.of(expectedType);
|
||||
if (!nodes.nodeMatches(nodeRef, expectedTypes, null)) {
|
||||
final String expectedTypeLocalName = (expectedTypeName != null)? expectedTypeName : expectedType.getLocalName();
|
||||
if (!nodes.nodeMatches(nodeRef, expectedTypes, null))
|
||||
{
|
||||
final String expectedTypeLocalName = (expectedTypeName != null) ? expectedTypeName : expectedType.getLocalName();
|
||||
throw new InvalidArgumentException(String.format("NodeId of a %s is expected!", expectedTypeLocalName));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isRuleSetNotNullAndShared(final NodeRef ruleSetNodeRef, final NodeRef folderNodeRef)
|
||||
public boolean isRuleSetNotNullAndShared(final NodeRef ruleSetNodeRef, final NodeRef folderNodeRef)
|
||||
{
|
||||
if (ruleSetNodeRef == null && folderNodeRef != null)
|
||||
{
|
||||
@@ -243,8 +163,23 @@ public class RulesImpl implements Rules
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isRuleSetNotNullAndShared(final NodeRef ruleSetNodeRef)
|
||||
public boolean isRuleSetNotNullAndShared(final NodeRef ruleSetNodeRef)
|
||||
{
|
||||
return ruleSetNodeRef != null && ruleService.isRuleSetShared(ruleSetNodeRef);
|
||||
}
|
||||
|
||||
public void setPermissionService(PermissionService permissionService)
|
||||
{
|
||||
this.permissionService = permissionService;
|
||||
}
|
||||
|
||||
public void setRuleService(RuleService ruleService)
|
||||
{
|
||||
this.ruleService = ruleService;
|
||||
}
|
||||
|
||||
public void setNodes(Nodes nodes)
|
||||
{
|
||||
this.nodes = nodes;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api.impl.rules;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.alfresco.rest.api.RuleSets;
|
||||
import org.alfresco.rest.api.model.rules.RuleSet;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.ListPage;
|
||||
import org.alfresco.rest.framework.resource.parameters.Paging;
|
||||
import org.alfresco.service.Experimental;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.rule.RuleService;
|
||||
|
||||
@Experimental
|
||||
public class RuleSetsImpl implements RuleSets
|
||||
{
|
||||
private RuleService ruleService;
|
||||
private NodeValidator validator;
|
||||
|
||||
@Override
|
||||
public CollectionWithPagingInfo<RuleSet> getRuleSets(String folderNodeId, List<String> includes, Paging paging)
|
||||
{
|
||||
NodeRef folderNode = validator.validateFolderNode(folderNodeId, false);
|
||||
|
||||
NodeRef ruleSetNode = ruleService.getRuleSetNode(folderNode);
|
||||
List<RuleSet> ruleSets = Optional.ofNullable(ruleSetNode)
|
||||
.map(NodeRef::getId)
|
||||
.map(RuleSet::of).stream().collect(toList());
|
||||
|
||||
return ListPage.of(ruleSets, paging);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RuleSet getRuleSetById(String folderNodeId, String ruleSetId, List<String> includes)
|
||||
{
|
||||
NodeRef folderNode = validator.validateFolderNode(folderNodeId, false);
|
||||
NodeRef ruleSetNode = validator.validateRuleSetNode(ruleSetId, folderNode);
|
||||
|
||||
return RuleSet.of(ruleSetNode.getId());
|
||||
}
|
||||
|
||||
public void setValidator(NodeValidator validator)
|
||||
{
|
||||
this.validator = validator;
|
||||
}
|
||||
|
||||
public void setRuleService(RuleService ruleService)
|
||||
{
|
||||
this.ruleService = ruleService;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api.impl.rules;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.alfresco.rest.api.Nodes;
|
||||
import org.alfresco.rest.api.Rules;
|
||||
import org.alfresco.rest.api.model.rules.Rule;
|
||||
import org.alfresco.rest.api.model.rules.RuleSet;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.ListPage;
|
||||
import org.alfresco.rest.framework.resource.parameters.Paging;
|
||||
import org.alfresco.service.Experimental;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.rule.RuleService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@Experimental
|
||||
public class RulesImpl implements Rules
|
||||
{
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(RulesImpl.class);
|
||||
|
||||
private Nodes nodes;
|
||||
private RuleService ruleService;
|
||||
private NodeValidator validator;
|
||||
|
||||
@Override
|
||||
public CollectionWithPagingInfo<Rule> getRules(final String folderNodeId, final String ruleSetId, final Paging paging)
|
||||
{
|
||||
final NodeRef folderNodeRef = validator.validateFolderNode(folderNodeId, false);
|
||||
final NodeRef ruleSetNodeRef = validator.validateRuleSetNode(ruleSetId, folderNodeRef);
|
||||
|
||||
final boolean isShared = validator.isRuleSetNotNullAndShared(ruleSetNodeRef);
|
||||
final List<Rule> rules = ruleService.getRules(folderNodeRef).stream()
|
||||
.map(ruleModel -> Rule.from(ruleModel, isShared))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return ListPage.of(rules, paging);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rule getRuleById(final String folderNodeId, final String ruleSetId, final String ruleId)
|
||||
{
|
||||
final NodeRef folderNodeRef = validator.validateFolderNode(folderNodeId, false);
|
||||
final NodeRef ruleSetNodeRef = validator.validateRuleSetNode(ruleSetId, folderNodeRef);
|
||||
final NodeRef ruleNodeRef = validator.validateRuleNode(ruleId, ruleSetNodeRef);
|
||||
|
||||
return Rule.from(ruleService.getRule(ruleNodeRef), validator.isRuleSetNotNullAndShared(ruleSetNodeRef));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Rule> createRules(final String folderNodeId, final String ruleSetId, final List<Rule> rules)
|
||||
{
|
||||
final NodeRef folderNodeRef = validator.validateFolderNode(folderNodeId, true);
|
||||
// Don't validate the ruleset node if -default- is passed since we may need to create it.
|
||||
final NodeRef ruleSetNodeRef = (RuleSet.isNotDefaultId(ruleSetId)) ? validator.validateRuleSetNode(ruleSetId, folderNodeRef) : null;
|
||||
|
||||
return rules.stream()
|
||||
.map(rule -> rule.toServiceModel(nodes))
|
||||
.map(rule -> ruleService.saveRule(folderNodeRef, rule))
|
||||
.map(rule -> Rule.from(rule, validator.isRuleSetNotNullAndShared(ruleSetNodeRef, folderNodeRef)))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rule updateRuleById(String folderNodeId, String ruleSetId, String ruleId, Rule rule)
|
||||
{
|
||||
LOGGER.debug("Updating rule in folder {}, rule set {}, rule {} to {}", folderNodeId, ruleSetId, ruleId, rule);
|
||||
|
||||
NodeRef folderNodeRef = validator.validateFolderNode(folderNodeId, true);
|
||||
NodeRef ruleSetNodeRef = validator.validateRuleSetNode(ruleSetId, folderNodeRef);
|
||||
validator.validateRuleNode(ruleId, ruleSetNodeRef);
|
||||
|
||||
boolean shared = validator.isRuleSetNotNullAndShared(ruleSetNodeRef, folderNodeRef);
|
||||
return Rule.from(ruleService.saveRule(folderNodeRef, rule.toServiceModel(nodes)), shared);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteRuleById(String folderNodeId, String ruleSetId, String ruleId)
|
||||
{
|
||||
final NodeRef folderNodeRef = validator.validateFolderNode(folderNodeId, true);
|
||||
final NodeRef ruleSetNodeRef = validator.validateRuleSetNode(ruleSetId, folderNodeRef);
|
||||
final NodeRef ruleNodeRef = validator.validateRuleNode(ruleId, ruleSetNodeRef);
|
||||
final org.alfresco.service.cmr.rule.Rule rule = ruleService.getRule(ruleNodeRef);
|
||||
ruleService.removeRule(folderNodeRef, rule);
|
||||
}
|
||||
|
||||
public void setNodes(Nodes nodes)
|
||||
{
|
||||
this.nodes = nodes;
|
||||
}
|
||||
|
||||
public void setRuleService(RuleService ruleService)
|
||||
{
|
||||
this.ruleService = ruleService;
|
||||
}
|
||||
|
||||
public void setValidator(NodeValidator validator)
|
||||
{
|
||||
this.validator = validator;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api.model.rules;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.alfresco.repo.action.ActionImpl;
|
||||
import org.alfresco.repo.action.CompositeActionImpl;
|
||||
import org.alfresco.repo.action.executer.SetPropertyValueActionExecuter;
|
||||
import org.alfresco.service.Experimental;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.util.GUID;
|
||||
|
||||
@Experimental
|
||||
public class Action
|
||||
{
|
||||
private String actionDefinitionId;
|
||||
private Map<String, Serializable> params;
|
||||
|
||||
/**
|
||||
* Converts service POJO action to REST model action.
|
||||
*
|
||||
* @param actionModel - {@link org.alfresco.service.cmr.action.Action} service POJO
|
||||
* @return {@link Action} REST model
|
||||
*/
|
||||
public static Action from(final org.alfresco.service.cmr.action.Action actionModel)
|
||||
{
|
||||
if (actionModel == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
final Action.Builder builder = builder().actionDefinitionId(actionModel.getActionDefinitionName());
|
||||
if (actionModel.getParameterValues() != null)
|
||||
{
|
||||
builder.params(new HashMap<>(actionModel.getParameterValues()));
|
||||
}
|
||||
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the REST model object to the equivalent service POJO.
|
||||
*
|
||||
* @param nodeRef The node reference.
|
||||
* @return The action service POJO.
|
||||
*/
|
||||
public org.alfresco.service.cmr.action.Action toServiceModel(final NodeRef nodeRef)
|
||||
{
|
||||
return new ActionImpl(nodeRef, GUID.generate(), SetPropertyValueActionExecuter.NAME, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the REST model objects to composite action service POJO.
|
||||
*
|
||||
* @param actions List of actions.
|
||||
* @return The composite action service POJO.
|
||||
*/
|
||||
public static org.alfresco.service.cmr.action.Action toCompositeAction(final List<Action> actions) {
|
||||
if (actions == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
final org.alfresco.service.cmr.action.CompositeAction compositeAction = new CompositeActionImpl(null, GUID.generate());
|
||||
actions.forEach(action -> compositeAction.addAction(action.toServiceModel(null)));
|
||||
return compositeAction;
|
||||
}
|
||||
|
||||
public String getActionDefinitionId()
|
||||
{
|
||||
return actionDefinitionId;
|
||||
}
|
||||
|
||||
public void setActionDefinitionId(String actionDefinitionId)
|
||||
{
|
||||
this.actionDefinitionId = actionDefinitionId;
|
||||
}
|
||||
|
||||
public Map<String, Serializable> getParams()
|
||||
{
|
||||
return params;
|
||||
}
|
||||
|
||||
public void setParams(Map<String, Serializable> params)
|
||||
{
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "Action{" + "actionDefinitionId='" + actionDefinitionId + '\'' + ", params=" + params + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
Action action = (Action) o;
|
||||
return Objects.equals(actionDefinitionId, action.actionDefinitionId) && Objects.equals(params, action.params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hash(actionDefinitionId, params);
|
||||
}
|
||||
|
||||
public static Builder builder()
|
||||
{
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder
|
||||
{
|
||||
private String actionDefinitionId;
|
||||
private Map<String, Serializable> params;
|
||||
|
||||
public Builder actionDefinitionId(String actionDefinitionId)
|
||||
{
|
||||
this.actionDefinitionId = actionDefinitionId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder params(Map<String, Serializable> params)
|
||||
{
|
||||
this.params = params;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Action create() {
|
||||
final Action action = new Action();
|
||||
action.setActionDefinitionId(actionDefinitionId);
|
||||
action.setParams(params);
|
||||
return action;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,230 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api.model.rules;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.alfresco.service.Experimental;
|
||||
import org.alfresco.service.cmr.action.ActionCondition;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
|
||||
@Experimental
|
||||
public class CompositeCondition
|
||||
{
|
||||
private boolean inverted;
|
||||
private ConditionOperator booleanMode = ConditionOperator.AND;
|
||||
private List<CompositeCondition> compositeConditions;
|
||||
private List<SimpleCondition> simpleConditions;
|
||||
|
||||
/**
|
||||
* Converts Action conditions (service POJO) list to composite condition (REST model).
|
||||
*
|
||||
* @param actionConditions - list of {@link ActionCondition} service POJOs
|
||||
* @return {@link CompositeCondition} REST model
|
||||
*/
|
||||
public static CompositeCondition from(final List<ActionCondition> actionConditions)
|
||||
{
|
||||
if (actionConditions == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
final CompositeCondition conditions = new CompositeCondition();
|
||||
conditions.compositeConditions = new ArrayList<>();
|
||||
// group action conditions by inversion flag
|
||||
actionConditions.stream().filter(Objects::nonNull).collect(Collectors.groupingBy(ActionCondition::getInvertCondition))
|
||||
// map action condition sub lists
|
||||
.forEach((inverted, actionConditionsPart) -> Optional.ofNullable(CompositeCondition.ofActionConditions(actionConditionsPart, inverted, ConditionOperator.AND))
|
||||
// if composite condition present add to final list
|
||||
.ifPresent(compositeCondition -> conditions.compositeConditions.add(compositeCondition)));
|
||||
|
||||
if (conditions.compositeConditions.isEmpty()) {
|
||||
conditions.compositeConditions = null;
|
||||
}
|
||||
|
||||
return conditions;
|
||||
}
|
||||
|
||||
private static CompositeCondition ofActionConditions(final List<ActionCondition> actionConditions, final boolean inverted, final ConditionOperator conditionOperator)
|
||||
{
|
||||
if (actionConditions == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return ofSimpleConditions(SimpleCondition.listOf(actionConditions), inverted, conditionOperator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a composite condition instance of simple conditions.
|
||||
*
|
||||
* @param simpleConditions - list of {@link SimpleCondition}
|
||||
* @param inverted - determines if condition should be inverted
|
||||
* @param conditionOperator - determines the operation, see {@link ConditionOperator}
|
||||
* @return {@link CompositeCondition}
|
||||
*/
|
||||
public static CompositeCondition ofSimpleConditions(final List<SimpleCondition> simpleConditions, final boolean inverted, final ConditionOperator conditionOperator)
|
||||
{
|
||||
return of(simpleConditions, null, inverted, conditionOperator);
|
||||
}
|
||||
|
||||
private static CompositeCondition of(final List<SimpleCondition> simpleConditions, final List<CompositeCondition> compositeConditions,
|
||||
final boolean inverted, final ConditionOperator conditionOperator)
|
||||
{
|
||||
if (CollectionUtils.isEmpty(simpleConditions) && CollectionUtils.isEmpty(compositeConditions))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return builder()
|
||||
.inverted(inverted)
|
||||
.booleanMode(conditionOperator)
|
||||
.simpleConditions(simpleConditions)
|
||||
.compositeConditions(compositeConditions)
|
||||
.create();
|
||||
}
|
||||
|
||||
public boolean isInverted()
|
||||
{
|
||||
return inverted;
|
||||
}
|
||||
|
||||
public void setInverted(boolean inverted)
|
||||
{
|
||||
this.inverted = inverted;
|
||||
}
|
||||
|
||||
public String getBooleanMode()
|
||||
{
|
||||
if (booleanMode == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return booleanMode.name().toLowerCase();
|
||||
}
|
||||
|
||||
public void setBooleanMode(ConditionOperator booleanMode)
|
||||
{
|
||||
this.booleanMode = booleanMode;
|
||||
}
|
||||
|
||||
public List<CompositeCondition> getCompositeConditions()
|
||||
{
|
||||
return compositeConditions;
|
||||
}
|
||||
|
||||
public void setCompositeConditions(List<CompositeCondition> compositeConditions)
|
||||
{
|
||||
this.compositeConditions = compositeConditions;
|
||||
}
|
||||
|
||||
public List<SimpleCondition> getSimpleConditions()
|
||||
{
|
||||
return simpleConditions;
|
||||
}
|
||||
|
||||
public void setSimpleConditions(List<SimpleCondition> simpleConditions)
|
||||
{
|
||||
this.simpleConditions = simpleConditions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "CompositeCondition{" + "inverted=" + inverted + ", booleanMode=" + booleanMode + ", compositeConditions=" + compositeConditions + ", simpleConditions="
|
||||
+ simpleConditions + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
CompositeCondition that = (CompositeCondition) o;
|
||||
return inverted == that.inverted && booleanMode == that.booleanMode && Objects.equals(compositeConditions, that.compositeConditions) && Objects.equals(
|
||||
simpleConditions, that.simpleConditions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hash(inverted, booleanMode, compositeConditions, simpleConditions);
|
||||
}
|
||||
|
||||
public static Builder builder()
|
||||
{
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder
|
||||
{
|
||||
private boolean inverted;
|
||||
private ConditionOperator booleanMode = ConditionOperator.AND;
|
||||
private List<CompositeCondition> compositeConditions;
|
||||
private List<SimpleCondition> simpleConditions;
|
||||
|
||||
public Builder inverted(boolean inverted)
|
||||
{
|
||||
this.inverted = inverted;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder booleanMode(ConditionOperator booleanMode)
|
||||
{
|
||||
this.booleanMode = booleanMode;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder compositeConditions(List<CompositeCondition> compositeConditions)
|
||||
{
|
||||
this.compositeConditions = compositeConditions;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder simpleConditions(List<SimpleCondition> simpleConditions)
|
||||
{
|
||||
this.simpleConditions = simpleConditions;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CompositeCondition create()
|
||||
{
|
||||
final CompositeCondition condition = new CompositeCondition();
|
||||
condition.setInverted(inverted);
|
||||
condition.setBooleanMode(booleanMode);
|
||||
condition.setCompositeConditions(compositeConditions);
|
||||
condition.setSimpleConditions(simpleConditions);
|
||||
return condition;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api.model.rules;
|
||||
|
||||
import org.alfresco.service.Experimental;
|
||||
|
||||
@Experimental
|
||||
public enum ConditionOperator
|
||||
{
|
||||
AND, OR
|
||||
}
|
||||
@@ -26,22 +26,16 @@
|
||||
|
||||
package org.alfresco.rest.api.model.rules;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.action.ActionImpl;
|
||||
import org.alfresco.repo.action.executer.ScriptActionExecuter;
|
||||
import org.alfresco.repo.action.executer.SetPropertyValueActionExecuter;
|
||||
import org.alfresco.rest.api.Nodes;
|
||||
import org.alfresco.rest.framework.resource.UniqueId;
|
||||
import org.alfresco.service.Experimental;
|
||||
import org.alfresco.service.cmr.action.CompositeAction;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.util.GUID;
|
||||
|
||||
@Experimental
|
||||
public class Rule
|
||||
@@ -55,6 +49,8 @@ public class Rule
|
||||
private boolean shared;
|
||||
private String errorScript;
|
||||
private List<RuleTrigger> triggers;
|
||||
private CompositeCondition conditions;
|
||||
private List<Action> actions;
|
||||
|
||||
/**
|
||||
* Converts service POJO rule to REST model rule.
|
||||
@@ -84,9 +80,17 @@ public class Rule
|
||||
{
|
||||
builder.triggers(ruleModel.getRuleTypes().stream().map(RuleTrigger::of).collect(Collectors.toList()));
|
||||
}
|
||||
if (ruleModel.getAction() != null && ruleModel.getAction().getCompensatingAction() != null && ruleModel.getAction().getCompensatingAction().getParameterValue(ScriptActionExecuter.PARAM_SCRIPTREF) != null)
|
||||
if (ruleModel.getAction() != null)
|
||||
{
|
||||
builder.errorScript(ruleModel.getAction().getCompensatingAction().getParameterValue(ScriptActionExecuter.PARAM_SCRIPTREF).toString());
|
||||
builder.conditions(CompositeCondition.from(ruleModel.getAction().getActionConditions()));
|
||||
if (ruleModel.getAction().getCompensatingAction() != null && ruleModel.getAction().getCompensatingAction().getParameterValue(ScriptActionExecuter.PARAM_SCRIPTREF) != null)
|
||||
{
|
||||
builder.errorScript(ruleModel.getAction().getCompensatingAction().getParameterValue(ScriptActionExecuter.PARAM_SCRIPTREF).toString());
|
||||
}
|
||||
if (ruleModel.getAction() instanceof CompositeAction && ((CompositeAction) ruleModel.getAction()).getActions() != null)
|
||||
{
|
||||
builder.actions(((CompositeAction) ruleModel.getAction()).getActions().stream().map(Action::from).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
|
||||
return builder.create();
|
||||
@@ -100,20 +104,12 @@ public class Rule
|
||||
*/
|
||||
public org.alfresco.service.cmr.rule.Rule toServiceModel(Nodes nodes)
|
||||
{
|
||||
org.alfresco.service.cmr.rule.Rule ruleModel = new org.alfresco.service.cmr.rule.Rule();
|
||||
if (id != null)
|
||||
{
|
||||
NodeRef nodeRef = nodes.validateOrLookupNode(id, null);
|
||||
ruleModel.setNodeRef(nodeRef);
|
||||
}
|
||||
final org.alfresco.service.cmr.rule.Rule ruleModel = new org.alfresco.service.cmr.rule.Rule();
|
||||
final NodeRef nodeRef = (id != null) ? nodes.validateOrLookupNode(id, null) : null;
|
||||
ruleModel.setNodeRef(nodeRef);
|
||||
ruleModel.setTitle(name);
|
||||
|
||||
// TODO: Once we have actions working properly then this needs to be replaced.
|
||||
Map<String, Serializable> parameters = Map.of(
|
||||
SetPropertyValueActionExecuter.PARAM_PROPERTY, ContentModel.PROP_TITLE,
|
||||
SetPropertyValueActionExecuter.PARAM_VALUE, "UPDATED:" + GUID.generate());
|
||||
org.alfresco.service.cmr.action.Action action = new ActionImpl(null, GUID.generate(), SetPropertyValueActionExecuter.NAME, parameters);
|
||||
ruleModel.setAction(action);
|
||||
ruleModel.setAction(Action.toCompositeAction(actions));
|
||||
|
||||
return ruleModel;
|
||||
}
|
||||
@@ -199,9 +195,13 @@ public class Rule
|
||||
this.shared = shared;
|
||||
}
|
||||
|
||||
public List<RuleTrigger> getTriggers()
|
||||
public List<String> getTriggers()
|
||||
{
|
||||
return triggers;
|
||||
if (triggers == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return triggers.stream().map(RuleTrigger::getValue).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public void setTriggers(List<RuleTrigger> triggers)
|
||||
@@ -209,16 +209,32 @@ public class Rule
|
||||
this.triggers = triggers;
|
||||
}
|
||||
|
||||
public List<Void> getActions()
|
||||
public CompositeCondition getConditions()
|
||||
{
|
||||
return Collections.emptyList();
|
||||
return conditions;
|
||||
}
|
||||
|
||||
public void setConditions(CompositeCondition conditions)
|
||||
{
|
||||
this.conditions = conditions;
|
||||
}
|
||||
|
||||
public List<Action> getActions()
|
||||
{
|
||||
return actions;
|
||||
}
|
||||
|
||||
public void setActions(List<Action> actions)
|
||||
{
|
||||
this.actions = actions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "Rule{" + "id='" + id + '\'' + ", name='" + name + '\'' + ", description='" + description + '\'' + ", enabled=" + enabled + ", cascade=" + cascade
|
||||
+ ", asynchronous=" + asynchronous + ", shared=" + shared + ", errorScript='" + errorScript + '\'' + ", triggers=" + triggers + '}';
|
||||
+ ", asynchronous=" + asynchronous + ", shared=" + shared + ", errorScript='" + errorScript + '\'' + ", triggers=" + triggers + ", conditions=" + conditions
|
||||
+ ", actions=" + actions + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -230,13 +246,14 @@ public class Rule
|
||||
return false;
|
||||
Rule rule = (Rule) o;
|
||||
return enabled == rule.enabled && cascade == rule.cascade && asynchronous == rule.asynchronous && shared == rule.shared && Objects.equals(id, rule.id) && Objects.equals(
|
||||
name, rule.name) && Objects.equals(description, rule.description) && Objects.equals(errorScript, rule.errorScript) && Objects.equals(triggers, rule.triggers);
|
||||
name, rule.name) && Objects.equals(description, rule.description) && Objects.equals(errorScript, rule.errorScript) && Objects.equals(triggers, rule.triggers)
|
||||
&& Objects.equals(conditions, rule.conditions) && Objects.equals(actions, rule.actions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hash(id, name, description, enabled, cascade, asynchronous, shared, errorScript, triggers);
|
||||
return Objects.hash(id, name, description, enabled, cascade, asynchronous, shared, errorScript, triggers, conditions, actions);
|
||||
}
|
||||
|
||||
public static Builder builder()
|
||||
@@ -256,6 +273,8 @@ public class Rule
|
||||
private boolean shared;
|
||||
private String errorScript;
|
||||
private List<RuleTrigger> triggers;
|
||||
private CompositeCondition conditions;
|
||||
private List<Action> actions;
|
||||
|
||||
public Builder id(String id)
|
||||
{
|
||||
@@ -311,6 +330,18 @@ public class Rule
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder conditions(CompositeCondition conditions)
|
||||
{
|
||||
this.conditions = conditions;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder actions(List<Action> actions)
|
||||
{
|
||||
this.actions = actions;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Rule create()
|
||||
{
|
||||
Rule rule = new Rule();
|
||||
@@ -323,6 +354,8 @@ public class Rule
|
||||
rule.setShared(shared);
|
||||
rule.setErrorScript(errorScript);
|
||||
rule.setTriggers(triggers);
|
||||
rule.setConditions(conditions);
|
||||
rule.setActions(actions);
|
||||
return rule;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,14 +44,6 @@ public class RuleSet
|
||||
.create();
|
||||
}
|
||||
|
||||
public boolean isNotDefaultId() {
|
||||
return isNotDefaultId(this.id);
|
||||
}
|
||||
|
||||
public boolean isDefaultId() {
|
||||
return isDefaultId(this.id);
|
||||
}
|
||||
|
||||
public static boolean isNotDefaultId(final String id) {
|
||||
return !isDefaultId(id);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,277 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api.model.rules;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.alfresco.repo.action.evaluator.CompareMimeTypeEvaluator;
|
||||
import org.alfresco.repo.action.evaluator.ComparePropertyValueEvaluator;
|
||||
import org.alfresco.repo.action.evaluator.HasAspectEvaluator;
|
||||
import org.alfresco.repo.action.evaluator.HasChildEvaluator;
|
||||
import org.alfresco.repo.action.evaluator.HasTagEvaluator;
|
||||
import org.alfresco.repo.action.evaluator.HasVersionHistoryEvaluator;
|
||||
import org.alfresco.repo.action.evaluator.InCategoryEvaluator;
|
||||
import org.alfresco.repo.action.evaluator.IsSubTypeEvaluator;
|
||||
import org.alfresco.repo.action.evaluator.NoConditionEvaluator;
|
||||
import org.alfresco.service.Experimental;
|
||||
import org.alfresco.service.cmr.action.ActionCondition;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
|
||||
@Experimental
|
||||
public class SimpleCondition
|
||||
{
|
||||
private static final String COMPARATOR_EQUALS = "equals";
|
||||
|
||||
private String field;
|
||||
private String comparator;
|
||||
private String parameter;
|
||||
|
||||
/**
|
||||
* Converts list of service POJO action conditions to list of REST model simple conditions.
|
||||
*
|
||||
* @param actionConditions - list of {@link ActionCondition} service POJOs
|
||||
* @return list of {@link SimpleCondition} REST models
|
||||
*/
|
||||
public static List<SimpleCondition> listOf(final List<ActionCondition> actionConditions)
|
||||
{
|
||||
if (CollectionUtils.isEmpty(actionConditions))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return actionConditions.stream()
|
||||
.map(SimpleCondition::from)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates simple condition REST model instance from service POJO action condition.
|
||||
*
|
||||
* @param actionCondition - {@link ActionCondition} service POJO
|
||||
* @return {@link SimpleCondition} REST model
|
||||
*/
|
||||
public static SimpleCondition from(final ActionCondition actionCondition)
|
||||
{
|
||||
if (actionCondition == null || actionCondition.getActionConditionDefinitionName() == null || actionCondition.getParameterValues() == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
switch (actionCondition.getActionConditionDefinitionName())
|
||||
{
|
||||
case ComparePropertyValueEvaluator.NAME:
|
||||
return createComparePropertyValueCondition(actionCondition);
|
||||
case CompareMimeTypeEvaluator.NAME:
|
||||
return createCompareMimeTypeCondition(actionCondition);
|
||||
case HasAspectEvaluator.NAME:
|
||||
return createHasAspectCondition(actionCondition);
|
||||
case HasChildEvaluator.NAME:
|
||||
return createHasChildCondition(actionCondition);
|
||||
case HasTagEvaluator.NAME:
|
||||
return createHasTagCondition(actionCondition);
|
||||
case HasVersionHistoryEvaluator.NAME:
|
||||
return createHasVersionHistoryCondition(actionCondition);
|
||||
case InCategoryEvaluator.NAME:
|
||||
return createInCategoryCondition(actionCondition);
|
||||
case IsSubTypeEvaluator.NAME:
|
||||
return createIsSubtypeCondition(actionCondition);
|
||||
case NoConditionEvaluator.NAME:
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String getField()
|
||||
{
|
||||
return field;
|
||||
}
|
||||
|
||||
public void setField(String field)
|
||||
{
|
||||
this.field = field;
|
||||
}
|
||||
|
||||
public String getComparator()
|
||||
{
|
||||
return comparator;
|
||||
}
|
||||
|
||||
public void setComparator(String comparator)
|
||||
{
|
||||
this.comparator = comparator;
|
||||
}
|
||||
|
||||
public String getParameter()
|
||||
{
|
||||
return parameter;
|
||||
}
|
||||
|
||||
public void setParameter(String parameter)
|
||||
{
|
||||
this.parameter = parameter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "SimpleCondition{" + "field='" + field + '\'' + ", comparator='" + comparator + '\'' + ", parameter='" + parameter + '\'' + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
SimpleCondition that = (SimpleCondition) o;
|
||||
return Objects.equals(field, that.field) && Objects.equals(comparator, that.comparator) && Objects.equals(parameter, that.parameter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hash(field, comparator, parameter);
|
||||
}
|
||||
|
||||
private static SimpleCondition createComparePropertyValueCondition(final ActionCondition actionCondition) {
|
||||
final SimpleCondition.Builder builder = builder();
|
||||
if (actionCondition.getParameterValues().get(ComparePropertyValueEvaluator.PARAM_CONTENT_PROPERTY) != null)
|
||||
{
|
||||
builder.field(actionCondition.getParameterValues().get(ComparePropertyValueEvaluator.PARAM_CONTENT_PROPERTY).toString().toLowerCase());
|
||||
} else {
|
||||
builder.field(actionCondition.getParameterValues().get(ComparePropertyValueEvaluator.PARAM_PROPERTY).toString().toLowerCase());
|
||||
}
|
||||
return builder
|
||||
.comparator(actionCondition.getParameterValues().get(ComparePropertyValueEvaluator.PARAM_OPERATION).toString().toLowerCase())
|
||||
.parameter(actionCondition.getParameterValues().get(ComparePropertyValueEvaluator.PARAM_VALUE).toString())
|
||||
.create();
|
||||
}
|
||||
|
||||
private static SimpleCondition createCompareMimeTypeCondition(final ActionCondition actionCondition) {
|
||||
return builder()
|
||||
.field(actionCondition.getParameterValues().get(ComparePropertyValueEvaluator.PARAM_PROPERTY).toString().toLowerCase())
|
||||
.comparator(COMPARATOR_EQUALS)
|
||||
.parameter(actionCondition.getParameterValues().get(ComparePropertyValueEvaluator.PARAM_VALUE).toString())
|
||||
.create();
|
||||
}
|
||||
|
||||
private static SimpleCondition createHasAspectCondition(final ActionCondition actionCondition) {
|
||||
return builder()
|
||||
.field(HasAspectEvaluator.PARAM_ASPECT)
|
||||
.comparator(COMPARATOR_EQUALS)
|
||||
.parameter(actionCondition.getParameterValues().get(HasAspectEvaluator.PARAM_ASPECT).toString())
|
||||
.create();
|
||||
}
|
||||
|
||||
private static SimpleCondition createHasChildCondition(final ActionCondition actionCondition) {
|
||||
final SimpleCondition.Builder builder = builder();
|
||||
if (actionCondition.getParameterValues().get(HasChildEvaluator.PARAM_ASSOC_TYPE) != null)
|
||||
{
|
||||
builder.field(actionCondition.getParameterValues().get(HasChildEvaluator.PARAM_ASSOC_TYPE).toString().toLowerCase());
|
||||
} else {
|
||||
builder.field(actionCondition.getParameterValues().get(HasChildEvaluator.PARAM_ASSOC_NAME).toString().toLowerCase());
|
||||
}
|
||||
return builder
|
||||
.comparator(COMPARATOR_EQUALS)
|
||||
.parameter(actionCondition.getParameterValues().get(ComparePropertyValueEvaluator.PARAM_VALUE).toString())
|
||||
.create();
|
||||
}
|
||||
|
||||
private static SimpleCondition createHasTagCondition(final ActionCondition actionCondition) {
|
||||
return builder()
|
||||
.field(HasTagEvaluator.PARAM_TAG)
|
||||
.comparator(COMPARATOR_EQUALS)
|
||||
.parameter(actionCondition.getParameterValues().get(HasTagEvaluator.PARAM_TAG).toString())
|
||||
.create();
|
||||
}
|
||||
|
||||
private static SimpleCondition createHasVersionHistoryCondition(final ActionCondition actionCondition) {
|
||||
return builder()
|
||||
.field(actionCondition.getParameterValues().get(ComparePropertyValueEvaluator.PARAM_PROPERTY).toString().toLowerCase())
|
||||
.comparator(actionCondition.getParameterValues().get(ComparePropertyValueEvaluator.PARAM_OPERATION).toString().toLowerCase())
|
||||
.parameter(actionCondition.getParameterValues().get(ComparePropertyValueEvaluator.PARAM_VALUE).toString())
|
||||
.create();
|
||||
}
|
||||
|
||||
private static SimpleCondition createInCategoryCondition(final ActionCondition actionCondition) {
|
||||
return builder()
|
||||
.field(actionCondition.getParameterValues().get(InCategoryEvaluator.PARAM_CATEGORY_ASPECT).toString().toLowerCase())
|
||||
.comparator(COMPARATOR_EQUALS)
|
||||
.parameter(actionCondition.getParameterValues().get(InCategoryEvaluator.PARAM_CATEGORY_VALUE).toString())
|
||||
.create();
|
||||
}
|
||||
|
||||
private static SimpleCondition createIsSubtypeCondition(final ActionCondition actionCondition) {
|
||||
return builder()
|
||||
.field(IsSubTypeEvaluator.PARAM_TYPE)
|
||||
.comparator(COMPARATOR_EQUALS)
|
||||
.parameter(actionCondition.getParameterValues().get(IsSubTypeEvaluator.PARAM_TYPE).toString())
|
||||
.create();
|
||||
}
|
||||
|
||||
public static Builder builder()
|
||||
{
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder
|
||||
{
|
||||
private String field;
|
||||
private String comparator;
|
||||
private String parameter;
|
||||
|
||||
public Builder field(String field)
|
||||
{
|
||||
this.field = field;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder comparator(String comparator)
|
||||
{
|
||||
this.comparator = comparator;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder parameter(String parameter)
|
||||
{
|
||||
this.parameter = parameter;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SimpleCondition create() {
|
||||
final SimpleCondition condition = new SimpleCondition();
|
||||
condition.setField(field);
|
||||
condition.setComparator(comparator);
|
||||
condition.setParameter(parameter);
|
||||
return condition;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,15 +26,84 @@
|
||||
|
||||
package org.alfresco.rest.api.nodes;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.rest.api.RuleSets;
|
||||
import org.alfresco.rest.api.model.rules.RuleSet;
|
||||
import org.alfresco.rest.framework.WebApiDescription;
|
||||
import org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException;
|
||||
import org.alfresco.rest.framework.resource.RelationshipResource;
|
||||
import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Paging;
|
||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||
import org.alfresco.service.Experimental;
|
||||
import org.alfresco.util.PropertyCheck;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
/**
|
||||
* Folder node rule sets.
|
||||
*
|
||||
*/
|
||||
@Experimental
|
||||
@RelationshipResource(name = "rule-sets", entityResource = NodesEntityResource.class, title = "Folder node rule sets")
|
||||
public class NodeRuleSetsRelation
|
||||
public class NodeRuleSetsRelation implements RelationshipResourceAction.Read<RuleSet>,
|
||||
RelationshipResourceAction.ReadById<RuleSet>,
|
||||
InitializingBean
|
||||
{
|
||||
private RuleSets ruleSets;
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception
|
||||
{
|
||||
PropertyCheck.mandatory(this, "ruleSets", ruleSets);
|
||||
}
|
||||
|
||||
/**
|
||||
* List rule sets for given folder.
|
||||
* <p>
|
||||
* - GET /nodes/{folderNodeId}/rule-sets
|
||||
*
|
||||
* @param folderNodeId The id of the folder node.
|
||||
* @param parameters Contains paging information and information about which fields to include
|
||||
* @return {@link CollectionWithPagingInfo} containing a page of rule sets
|
||||
*/
|
||||
@WebApiDescription (
|
||||
title = "Get rule sets for a folder",
|
||||
description = "Returns a paged list of rule sets for given node",
|
||||
successStatus = HttpServletResponse.SC_OK
|
||||
)
|
||||
@Override
|
||||
public CollectionWithPagingInfo<RuleSet> readAll(String folderNodeId, Parameters parameters)
|
||||
{
|
||||
return ruleSets.getRuleSets(folderNodeId, parameters.getInclude(), parameters.getPaging());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get single folder rule for given node's, rule set's and rule's IDs.
|
||||
* <p>
|
||||
* - GET /nodes/{folderNodeId}/rule-sets/{ruleSetId}
|
||||
*
|
||||
* @param folderNodeId - entity resource context for this relationship
|
||||
* @param ruleSetId - rule set node ID (associated with folder node)
|
||||
* @param parameters Contains information about which fields to include
|
||||
* @return {@link RuleSet} definition
|
||||
* @throws RelationshipResourceNotFoundException in case resource was not found
|
||||
*/
|
||||
@WebApiDescription (
|
||||
title = "Get rule set",
|
||||
description = "Returns a single rule set for the given node",
|
||||
successStatus = HttpServletResponse.SC_OK
|
||||
)
|
||||
@Override
|
||||
public RuleSet readById(String folderNodeId, String ruleSetId, Parameters parameters) throws RelationshipResourceNotFoundException
|
||||
{
|
||||
return ruleSets.getRuleSetById(folderNodeId, ruleSetId, parameters.getInclude());
|
||||
}
|
||||
|
||||
public void setRuleSets(RuleSets ruleSets)
|
||||
{
|
||||
this.ruleSets = ruleSets;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,8 +121,8 @@ public class ResourceLookupDictionary implements ResourceLocator
|
||||
return resource;
|
||||
}
|
||||
}
|
||||
logger.warn("Unable to locate resource resource for :"+entityResource+" "+relationResource==null?"":relationResource+" "+property==null?"":property);
|
||||
throw new NotFoundException("Unable to locate resource resource for :"+entityResource+" "+(relationResource==null?"":relationResource+" "+property==null?"":property));
|
||||
logger.warn("Unable to locate resource for: "+entityResource+" "+relationResource==null ? "" : relationResource+" "+property==null ? "" : property);
|
||||
throw new NotFoundException("Unable to locate resource for: "+entityResource+" "+(relationResource==null ? "" : relationResource+" "+property==null ? "" : property));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -160,8 +160,8 @@ public class ResourceLookupDictionary implements ResourceLocator
|
||||
return resource;
|
||||
}
|
||||
}
|
||||
logger.warn("Unable to locate resource resource for :"+entityResource+" "+relationResource==null?"":relationResource);
|
||||
throw new NotFoundException("Unable to locate resource resource for :"+entityResource+" "+(relationResource==null?"":relationResource));
|
||||
logger.warn("Unable to locate resource for: "+entityResource+" "+relationResource==null ? "" : relationResource);
|
||||
throw new NotFoundException("Unable to locate resource for: "+entityResource+" "+relationResource==null ? "" : relationResource);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -850,9 +850,38 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="rules" class="org.alfresco.rest.api.impl.RulesImpl">
|
||||
<bean id="nodeValidator" class="org.alfresco.rest.api.impl.rules.NodeValidator">
|
||||
<property name="nodes" ref="Nodes" />
|
||||
<property name="permissionService" ref="PermissionService"/>
|
||||
<property name="permissionService" ref="PermissionService" />
|
||||
<property name="ruleService" ref="RuleService" />
|
||||
</bean>
|
||||
|
||||
<bean class="org.alfresco.rest.api.nodes.NodeRulesRelation">
|
||||
<property name="rules" ref="Rules" />
|
||||
</bean>
|
||||
|
||||
<bean id="ruleSets" class="org.alfresco.rest.api.impl.rules.RuleSetsImpl">
|
||||
<property name="validator" ref="nodeValidator" />
|
||||
<property name="ruleService" ref="RuleService" />
|
||||
</bean>
|
||||
|
||||
<bean id="RuleSets" class="org.springframework.aop.framework.ProxyFactoryBean">
|
||||
<property name="proxyInterfaces" value="org.alfresco.rest.api.RuleSets" />
|
||||
<property name="target" ref="ruleSets" />
|
||||
<property name="interceptorNames">
|
||||
<list>
|
||||
<idref bean="legacyExceptionInterceptor" />
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean class="org.alfresco.rest.api.nodes.NodeRuleSetsRelation">
|
||||
<property name="ruleSets" ref="RuleSets" />
|
||||
</bean>
|
||||
|
||||
<bean id="rules" class="org.alfresco.rest.api.impl.rules.RulesImpl">
|
||||
<property name="nodes" ref="Nodes" />
|
||||
<property name="validator" ref="nodeValidator"/>
|
||||
<property name="ruleService" ref="RuleService" />
|
||||
</bean>
|
||||
|
||||
@@ -866,10 +895,6 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean class="org.alfresco.rest.api.nodes.NodeRulesRelation">
|
||||
<property name="rules" ref="Rules" />
|
||||
</bean>
|
||||
|
||||
<bean id="publicapi.mimeTypePropertyLookup" class="org.alfresco.rest.api.lookups.MimeTypePropertyLookup">
|
||||
<property name="serviceRegistry" ref="ServiceRegistry"/>
|
||||
<property name="supported">
|
||||
|
||||
@@ -249,6 +249,7 @@
|
||||
<property name="delegate" ref="webscript.content.streamer" />
|
||||
<property name="contentService" ref="contentService" />
|
||||
<property name="repository" ref="repositoryHelper" />
|
||||
<property name="nonAttachContentTypes" value="#{T(java.util.Arrays).asList('${content.nonAttach.mimetypes}')}" />
|
||||
</bean>
|
||||
|
||||
<!-- Content Info -->
|
||||
|
||||
@@ -66,13 +66,17 @@ public class ContentGetTest extends BaseWebScriptTest
|
||||
{
|
||||
super.setUp();
|
||||
|
||||
this.authenticationService = (MutableAuthenticationService) getServer().getApplicationContext()
|
||||
.getBean("AuthenticationService");
|
||||
this.authenticationService = (MutableAuthenticationService)getServer().getApplicationContext().getBean("AuthenticationService");
|
||||
this.personService = (PersonService) getServer().getApplicationContext().getBean("PersonService");
|
||||
this.nodeService = (NodeService) getServer().getApplicationContext().getBean("NodeService");
|
||||
this.contentService = (ContentService) getServer().getApplicationContext().getBean("ContentService");
|
||||
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
|
||||
createUser(USER_ONE);
|
||||
|
||||
Repository repositoryHelper = (Repository) getServer().getApplicationContext().getBean("repositoryHelper");
|
||||
NodeRef companyHome = repositoryHelper.getCompanyHome();
|
||||
|
||||
rootFolder = createNode(companyHome, "rootFolder", ContentModel.TYPE_FOLDER);
|
||||
}
|
||||
|
||||
private void createUser(String userName)
|
||||
@@ -117,18 +121,13 @@ public class ContentGetTest extends BaseWebScriptTest
|
||||
*/
|
||||
public void testRelativePath() throws Exception
|
||||
{
|
||||
Repository repositoryHelper = (Repository) getServer().getApplicationContext().getBean("repositoryHelper");
|
||||
NodeRef companyHome = repositoryHelper.getCompanyHome();
|
||||
|
||||
rootFolder = createNode(companyHome, "rootFolder", ContentModel.TYPE_FOLDER);
|
||||
|
||||
NodeRef doc1 = createNodeWithTextContent(rootFolder, "doc1", ContentModel.TYPE_CONTENT, "doc1 file content");
|
||||
NodeRef doc1 = createNodeWithTextContent(rootFolder, "doc1", ContentModel.TYPE_CONTENT, "doc1 file content", MimetypeMap.MIMETYPE_TEXT_PLAIN);
|
||||
|
||||
NodeRef folderX = createNode(rootFolder, "X", ContentModel.TYPE_FOLDER);
|
||||
NodeRef folderY = createNode(folderX, "Y", ContentModel.TYPE_FOLDER);
|
||||
NodeRef folderZ = createNode(folderY, "Z", ContentModel.TYPE_FOLDER);
|
||||
|
||||
NodeRef doc2 = createNodeWithTextContent(folderZ, "doc2", ContentModel.TYPE_CONTENT, "doc2 file content");
|
||||
NodeRef doc2 = createNodeWithTextContent(folderZ, "doc2", ContentModel.TYPE_CONTENT, "doc2 file content", MimetypeMap.MIMETYPE_TEXT_PLAIN);
|
||||
|
||||
// uri with relative path at the end
|
||||
String uri = URL_CONTENT_DOWNLOAD + doc1.getId() + "/X/Y/Z/doc2";
|
||||
@@ -138,7 +137,46 @@ public class ContentGetTest extends BaseWebScriptTest
|
||||
Assert.assertEquals("doc2 file content", resp.getContentAsString());
|
||||
}
|
||||
|
||||
public NodeRef createNodeWithTextContent(NodeRef parentNode, String nodeCmName, QName nodeType, String content)
|
||||
|
||||
|
||||
public void testForcedAttachment() throws Exception
|
||||
{
|
||||
NodeRef testhtml = createNodeWithTextContent(rootFolder, "testhtml", ContentModel.TYPE_CONTENT, "testhtml content", MimetypeMap.MIMETYPE_HTML);
|
||||
NodeRef testpdf = createNodeWithTextContent(rootFolder, "testpdf", ContentModel.TYPE_CONTENT, "testpdf content", MimetypeMap.MIMETYPE_PDF);
|
||||
|
||||
String uri = URL_CONTENT_DOWNLOAD + testhtml.getId() + "?a=false";
|
||||
GetRequest req = new GetRequest(uri);
|
||||
Response res = sendRequest(req, 200);
|
||||
assertEquals("attachment", res.getHeader("Content-Disposition"));
|
||||
assertEquals(MimetypeMap.MIMETYPE_HTML + ";charset=UTF-8", res.getContentType());
|
||||
|
||||
uri = URL_CONTENT_DOWNLOAD + testhtml.getId();
|
||||
res = sendRequest(new GetRequest(uri), 200);
|
||||
assertEquals("attachment", res.getHeader("Content-Disposition"));
|
||||
assertEquals(MimetypeMap.MIMETYPE_HTML + ";charset=UTF-8", res.getContentType());
|
||||
|
||||
uri = URL_CONTENT_DOWNLOAD + testhtml.getId() + "?a=true";
|
||||
res = sendRequest(new GetRequest(uri), 200);
|
||||
assertEquals("attachment", res.getHeader("Content-Disposition"));
|
||||
assertEquals(MimetypeMap.MIMETYPE_HTML + ";charset=UTF-8", res.getContentType());
|
||||
|
||||
uri = URL_CONTENT_DOWNLOAD + testpdf.getId() + "?a=false";
|
||||
res = sendRequest(new GetRequest(uri), 200);
|
||||
assertNull(res.getHeader("Content-Disposition"));
|
||||
assertEquals(MimetypeMap.MIMETYPE_PDF + ";charset=UTF-8", res.getContentType());
|
||||
|
||||
uri = URL_CONTENT_DOWNLOAD + testpdf.getId();
|
||||
res = sendRequest(new GetRequest(uri), 200);
|
||||
assertNull(res.getHeader("Content-Disposition"));
|
||||
assertEquals(MimetypeMap.MIMETYPE_PDF + ";charset=UTF-8", res.getContentType());
|
||||
|
||||
uri = URL_CONTENT_DOWNLOAD + testpdf.getId() + "?a=true";
|
||||
res = sendRequest(new GetRequest(uri), 200);
|
||||
assertEquals("attachment", res.getHeader("Content-Disposition"));
|
||||
assertEquals(MimetypeMap.MIMETYPE_PDF + ";charset=UTF-8", res.getContentType());
|
||||
}
|
||||
|
||||
public NodeRef createNodeWithTextContent(NodeRef parentNode, String nodeCmName, QName nodeType, String content, String mimetype)
|
||||
{
|
||||
NodeRef nodeRef = createNode(parentNode, nodeCmName, nodeType);
|
||||
|
||||
@@ -146,7 +184,7 @@ public class ContentGetTest extends BaseWebScriptTest
|
||||
if (content != null)
|
||||
{
|
||||
ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
|
||||
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
|
||||
writer.setMimetype(mimetype);
|
||||
writer.setEncoding("UTF-8");
|
||||
writer.putContent(content);
|
||||
}
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.web.util;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
@@ -32,6 +32,7 @@ import java.io.InputStreamReader;
|
||||
import java.net.InetAddress;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
@@ -44,7 +45,8 @@ import org.alfresco.util.TempFileProvider;
|
||||
import org.alfresco.util.WebApplicationContextLoader;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.eclipse.jetty.security.HashLoginService;
|
||||
import org.eclipse.jetty.http.UriCompliance;
|
||||
import org.eclipse.jetty.server.HttpConnectionFactory;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
@@ -145,6 +147,8 @@ public abstract class AbstractJettyComponent implements JettyComponent
|
||||
|
||||
configureWebAppContext(webAppContext);
|
||||
|
||||
ignoreAmbiguousLinks(server);
|
||||
|
||||
server.start();
|
||||
|
||||
if(logger.isDebugEnabled())
|
||||
@@ -203,15 +207,27 @@ public abstract class AbstractJettyComponent implements JettyComponent
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// with a login-config in web.xml, jetty seems to require this in order to start successfully
|
||||
webAppContext.getSecurityHandler().setLoginService(new HashLoginService());
|
||||
|
||||
// arbitrary temporary file location
|
||||
File tmp = new File(TempFileProvider.getSystemTempDir(), String.valueOf(System.currentTimeMillis()));
|
||||
webAppContext.setResourceBase(tmp.getAbsolutePath());
|
||||
}
|
||||
|
||||
/**
|
||||
* In newer jetty versions there is a stricter check for links e.g. "//" is not allowed, which clashes
|
||||
* with some of our tests, because even a NodeRef triggers it - "workspace://..."
|
||||
* Since Jetty is only used in tests it's alright to block this behaviour.
|
||||
*
|
||||
* @param server
|
||||
*/
|
||||
private void ignoreAmbiguousLinks(Server server) {
|
||||
Arrays.stream(server.getConnectors())
|
||||
.flatMap(c -> c.getConnectionFactories().stream())
|
||||
.filter(cf -> cf instanceof HttpConnectionFactory)
|
||||
.map(cf -> (HttpConnectionFactory) cf)
|
||||
.forEach(hcf -> hcf.getHttpConfiguration().setUriCompliance(UriCompliance.RFC3986));
|
||||
}
|
||||
|
||||
public void shutdown()
|
||||
{
|
||||
try
|
||||
|
||||
@@ -26,8 +26,12 @@
|
||||
|
||||
package org.alfresco.rest.api;
|
||||
|
||||
import org.alfresco.rest.api.impl.RulesImplTest;
|
||||
import org.alfresco.rest.api.impl.rules.NodeValidatorTest;
|
||||
import org.alfresco.rest.api.model.rules.ActionTest;
|
||||
import org.alfresco.rest.api.model.rules.CompositeConditionTest;
|
||||
import org.alfresco.rest.api.impl.rules.RulesImplTest;
|
||||
import org.alfresco.rest.api.model.rules.RuleTest;
|
||||
import org.alfresco.rest.api.model.rules.SimpleConditionTest;
|
||||
import org.alfresco.rest.api.nodes.NodeRulesRelationTest;
|
||||
import org.alfresco.service.Experimental;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -38,7 +42,11 @@ import org.junit.runners.Suite;
|
||||
@Suite.SuiteClasses({
|
||||
NodeRulesRelationTest.class,
|
||||
RulesImplTest.class,
|
||||
RuleTest.class
|
||||
NodeValidatorTest.class,
|
||||
RuleTest.class,
|
||||
ActionTest.class,
|
||||
SimpleConditionTest.class,
|
||||
CompositeConditionTest.class
|
||||
})
|
||||
public class RulesUnitTests
|
||||
{
|
||||
|
||||
@@ -1,648 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api.impl;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
|
||||
import static org.alfresco.rest.api.model.rules.RuleSet.DEFAULT_ID;
|
||||
import static org.alfresco.service.cmr.security.AccessStatus.ALLOWED;
|
||||
import static org.alfresco.service.cmr.security.AccessStatus.DENIED;
|
||||
import static org.alfresco.service.cmr.security.PermissionService.CHANGE_PERMISSIONS;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.isNull;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.BDDMockito.then;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.alfresco.repo.action.ActionImpl;
|
||||
import org.alfresco.rest.api.Nodes;
|
||||
import org.alfresco.rest.api.model.rules.Rule;
|
||||
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
|
||||
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
|
||||
import org.alfresco.rest.framework.core.exceptions.PermissionDeniedException;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Paging;
|
||||
import org.alfresco.service.Experimental;
|
||||
import org.alfresco.service.cmr.action.Action;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.rule.RuleService;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
@Experimental
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class RulesImplTest extends TestCase
|
||||
{
|
||||
private static final String FOLDER_NODE_ID = "dummy-folder-node-id";
|
||||
private static final String RULE_SET_ID = "dummy-rule-set-id";
|
||||
private static final String RULE_ID = "dummy-rule-id";
|
||||
private static final NodeRef folderNodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, FOLDER_NODE_ID);
|
||||
private static final NodeRef ruleSetNodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, RULE_SET_ID);
|
||||
private static final NodeRef ruleNodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, RULE_ID);
|
||||
private static final Paging paging = Paging.DEFAULT;
|
||||
private static final Action action = new ActionImpl(folderNodeRef, "actionId", "actionDefinitionName");
|
||||
private static final String RULE_NAME = "Rule name";
|
||||
|
||||
@Mock
|
||||
private Nodes nodesMock;
|
||||
|
||||
@Mock
|
||||
private PermissionService permissionServiceMock;
|
||||
|
||||
@Mock
|
||||
private RuleService ruleServiceMock;
|
||||
|
||||
@InjectMocks
|
||||
private RulesImpl rules;
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
MockitoAnnotations.openMocks(this);
|
||||
|
||||
given(nodesMock.validateOrLookupNode(eq(FOLDER_NODE_ID), any())).willReturn(folderNodeRef);
|
||||
given(nodesMock.validateNode(RULE_SET_ID)).willReturn(ruleSetNodeRef);
|
||||
given(nodesMock.validateNode(RULE_ID)).willReturn(ruleNodeRef);
|
||||
given(nodesMock.nodeMatches(any(), any(), any())).willReturn(true);
|
||||
given(permissionServiceMock.hasReadPermission(any())).willReturn(ALLOWED);
|
||||
given(permissionServiceMock.hasPermission(any(), any())).willReturn(ALLOWED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRules()
|
||||
{
|
||||
given(ruleServiceMock.isRuleSetAssociatedWithFolder(any(), any())).willReturn(true);
|
||||
given(ruleServiceMock.getRules(any())).willReturn(List.of(createRule(RULE_ID)));
|
||||
|
||||
// when
|
||||
final CollectionWithPagingInfo<Rule> rulesPage = rules.getRules(FOLDER_NODE_ID, RULE_SET_ID, paging);
|
||||
|
||||
then(nodesMock).should().validateOrLookupNode(FOLDER_NODE_ID, null);
|
||||
then(nodesMock).should().validateNode(RULE_SET_ID);
|
||||
then(nodesMock).should().nodeMatches(eq(folderNodeRef), any(), isNull());
|
||||
then(nodesMock).should().nodeMatches(eq(ruleSetNodeRef), any(), isNull());
|
||||
then(nodesMock).shouldHaveNoMoreInteractions();
|
||||
then(permissionServiceMock).should().hasReadPermission(folderNodeRef);
|
||||
then(permissionServiceMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).should().isRuleSetAssociatedWithFolder(ruleSetNodeRef, folderNodeRef);
|
||||
then(ruleServiceMock).should().isRuleSetShared(ruleSetNodeRef);
|
||||
then(ruleServiceMock).should().getRules(folderNodeRef);
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
assertThat(rulesPage)
|
||||
.isNotNull()
|
||||
.extracting(CollectionWithPagingInfo::getCollection)
|
||||
.isNotNull()
|
||||
.extracting(Collection::size)
|
||||
.isEqualTo(1);
|
||||
assertThat(rulesPage.getCollection().stream().findFirst().orElse(null))
|
||||
.isNotNull()
|
||||
.extracting(Rule::getId)
|
||||
.isEqualTo(RULE_ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRulesForDefaultRuleSet()
|
||||
{
|
||||
given(ruleServiceMock.getRuleSetNode(any())).willReturn(ruleSetNodeRef);
|
||||
given(ruleServiceMock.getRules(any())).willReturn(List.of(createRule(RULE_ID)));
|
||||
|
||||
// when
|
||||
final CollectionWithPagingInfo<Rule> rulesPage = rules.getRules(FOLDER_NODE_ID, DEFAULT_ID, paging);
|
||||
|
||||
then(nodesMock).should().validateOrLookupNode(FOLDER_NODE_ID, null);
|
||||
then(nodesMock).should().nodeMatches(eq(folderNodeRef), any(), isNull());
|
||||
then(nodesMock).shouldHaveNoMoreInteractions();
|
||||
then(permissionServiceMock).should().hasReadPermission(folderNodeRef);
|
||||
then(permissionServiceMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).should().getRuleSetNode(folderNodeRef);
|
||||
then(ruleServiceMock).should().isRuleSetShared(ruleSetNodeRef);
|
||||
then(ruleServiceMock).should().getRules(folderNodeRef);
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
assertThat(rulesPage)
|
||||
.isNotNull()
|
||||
.extracting(CollectionWithPagingInfo::getCollection)
|
||||
.isNotNull()
|
||||
.extracting(Collection::size)
|
||||
.isEqualTo(1);
|
||||
assertThat(rulesPage.getCollection().stream().findFirst().orElse(null))
|
||||
.isNotNull()
|
||||
.extracting(Rule::getId)
|
||||
.isEqualTo(RULE_ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRulesForNotExistingFolderNode()
|
||||
{
|
||||
given(nodesMock.nodeMatches(eq(folderNodeRef), any(), any())).willReturn(false);
|
||||
|
||||
// when
|
||||
assertThatExceptionOfType(InvalidArgumentException.class).isThrownBy(
|
||||
() -> rules.getRules(FOLDER_NODE_ID, RULE_SET_ID, paging));
|
||||
|
||||
then(ruleServiceMock).shouldHaveNoInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRulesForNotExistingRuleSetNode()
|
||||
{
|
||||
given(nodesMock.nodeMatches(eq(folderNodeRef), any(), any())).willReturn(true);
|
||||
given(nodesMock.nodeMatches(eq(ruleSetNodeRef), any(), any())).willReturn(false);
|
||||
|
||||
// when
|
||||
assertThatExceptionOfType(InvalidArgumentException.class).isThrownBy(
|
||||
() -> rules.getRules(FOLDER_NODE_ID, RULE_SET_ID, paging));
|
||||
|
||||
then(ruleServiceMock).shouldHaveNoInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRulesForNotAssociatedRuleSetToFolder()
|
||||
{
|
||||
given(ruleServiceMock.isRuleSetAssociatedWithFolder(any(), any())).willReturn(false);
|
||||
|
||||
// when
|
||||
assertThatExceptionOfType(InvalidArgumentException.class).isThrownBy(
|
||||
() -> rules.getRules(FOLDER_NODE_ID, RULE_SET_ID, paging));
|
||||
|
||||
then(ruleServiceMock).should().isRuleSetAssociatedWithFolder(ruleSetNodeRef, folderNodeRef);
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRulesWithoutReadPermission()
|
||||
{
|
||||
given(permissionServiceMock.hasReadPermission(any())).willReturn(DENIED);
|
||||
|
||||
// when
|
||||
assertThatExceptionOfType(PermissionDeniedException.class).isThrownBy(
|
||||
() -> rules.getRules(FOLDER_NODE_ID, RULE_SET_ID, paging));
|
||||
|
||||
then(ruleServiceMock).shouldHaveNoInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRuleById()
|
||||
{
|
||||
given(ruleServiceMock.isRuleSetAssociatedWithFolder(any(), any())).willReturn(true);
|
||||
given(ruleServiceMock.isRuleAssociatedWithRuleSet(any(), any())).willReturn(true);
|
||||
given(ruleServiceMock.getRule(any())).willReturn(createRule(RULE_ID));
|
||||
|
||||
// when
|
||||
final Rule rule = rules.getRuleById(FOLDER_NODE_ID, RULE_SET_ID, RULE_ID);
|
||||
|
||||
then(nodesMock).should().validateOrLookupNode(FOLDER_NODE_ID, null);
|
||||
then(nodesMock).should().validateNode(RULE_SET_ID);
|
||||
then(nodesMock).should().validateNode(RULE_ID);
|
||||
then(nodesMock).should().nodeMatches(eq(folderNodeRef), any(), isNull());
|
||||
then(nodesMock).should().nodeMatches(eq(ruleSetNodeRef), any(), isNull());
|
||||
then(nodesMock).should().nodeMatches(eq(ruleNodeRef), any(), isNull());
|
||||
then(nodesMock).shouldHaveNoMoreInteractions();
|
||||
then(permissionServiceMock).should().hasReadPermission(folderNodeRef);
|
||||
then(permissionServiceMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).should().isRuleSetAssociatedWithFolder(ruleSetNodeRef, folderNodeRef);
|
||||
then(ruleServiceMock).should().isRuleAssociatedWithRuleSet(ruleNodeRef, ruleSetNodeRef);
|
||||
then(ruleServiceMock).should().isRuleSetShared(ruleSetNodeRef);
|
||||
then(ruleServiceMock).should().getRule(ruleNodeRef);
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
assertThat(rule)
|
||||
.isNotNull()
|
||||
.extracting(Rule::getId)
|
||||
.isEqualTo(RULE_ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRuleByIdForDefaultRuleSet()
|
||||
{
|
||||
final String defaultRuleSetId = "-default-";
|
||||
given(ruleServiceMock.getRuleSetNode(any())).willReturn(ruleSetNodeRef);
|
||||
given(ruleServiceMock.isRuleAssociatedWithRuleSet(any(), any())).willReturn(true);
|
||||
given(ruleServiceMock.getRule(any())).willReturn(createRule(RULE_ID));
|
||||
|
||||
// when
|
||||
final Rule rule = rules.getRuleById(FOLDER_NODE_ID, defaultRuleSetId, RULE_ID);
|
||||
|
||||
then(nodesMock).should().validateOrLookupNode(FOLDER_NODE_ID, null);
|
||||
then(nodesMock).should().validateNode(RULE_ID);
|
||||
then(nodesMock).should().nodeMatches(eq(folderNodeRef), any(), isNull());
|
||||
then(nodesMock).should().nodeMatches(eq(ruleNodeRef), any(), isNull());
|
||||
then(nodesMock).shouldHaveNoMoreInteractions();
|
||||
then(permissionServiceMock).should().hasReadPermission(folderNodeRef);
|
||||
then(permissionServiceMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).should().getRuleSetNode(folderNodeRef);
|
||||
then(ruleServiceMock).should().isRuleAssociatedWithRuleSet(ruleNodeRef, ruleSetNodeRef);
|
||||
then(ruleServiceMock).should().isRuleSetShared(ruleSetNodeRef);
|
||||
then(ruleServiceMock).should().getRule(ruleNodeRef);
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
assertThat(rule)
|
||||
.isNotNull()
|
||||
.extracting(Rule::getId)
|
||||
.isEqualTo(RULE_ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRuleByIdForNotAssociatedRuleToRuleSet()
|
||||
{
|
||||
given(ruleServiceMock.isRuleSetAssociatedWithFolder(any(), any())).willReturn(true);
|
||||
given(ruleServiceMock.isRuleAssociatedWithRuleSet(any(), any())).willReturn(false);
|
||||
|
||||
// when
|
||||
assertThatExceptionOfType(InvalidArgumentException.class).isThrownBy(
|
||||
() -> rules.getRuleById(FOLDER_NODE_ID, RULE_SET_ID, RULE_ID));
|
||||
|
||||
then(ruleServiceMock).should().isRuleSetAssociatedWithFolder(ruleSetNodeRef, folderNodeRef);
|
||||
then(ruleServiceMock).should().isRuleAssociatedWithRuleSet(ruleNodeRef, ruleSetNodeRef);
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
}
|
||||
|
||||
/** Create a single rule. */
|
||||
@Test
|
||||
public void testSaveRules()
|
||||
{
|
||||
Rule ruleBody = mock(Rule.class);
|
||||
List<Rule> ruleList = List.of(ruleBody);
|
||||
given(ruleServiceMock.isRuleSetAssociatedWithFolder(any(), any())).willReturn(true);
|
||||
org.alfresco.service.cmr.rule.Rule serviceRuleBody = mock(org.alfresco.service.cmr.rule.Rule.class);
|
||||
given(ruleBody.toServiceModel(nodesMock)).willReturn(serviceRuleBody);
|
||||
org.alfresco.service.cmr.rule.Rule serviceRule = mock(org.alfresco.service.cmr.rule.Rule.class);
|
||||
given(ruleServiceMock.saveRule(folderNodeRef, serviceRuleBody)).willReturn(serviceRule);
|
||||
given(serviceRule.getNodeRef()).willReturn(ruleNodeRef);
|
||||
given(serviceRule.getAction()).willReturn(action);
|
||||
|
||||
// when
|
||||
List<Rule> actual = rules.createRules(folderNodeRef.getId(), ruleSetNodeRef.getId(), ruleList);
|
||||
|
||||
then(ruleServiceMock).should().isRuleSetAssociatedWithFolder(ruleSetNodeRef, folderNodeRef);
|
||||
then(ruleServiceMock).should().isRuleSetShared(ruleSetNodeRef);
|
||||
then(ruleServiceMock).should().saveRule(folderNodeRef, ruleBody.toServiceModel(nodesMock));
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
List<Rule> expected = List.of(Rule.from(serviceRule, false));
|
||||
assertThat(actual).isEqualTo(expected);
|
||||
}
|
||||
|
||||
/** Check that when passing the default rule set then we don't perform any validation around the rule set node. */
|
||||
@Test
|
||||
public void testSaveRules_defaultRuleSet()
|
||||
{
|
||||
Rule ruleBody = mock(Rule.class);
|
||||
List<Rule> ruleList = List.of(ruleBody);
|
||||
org.alfresco.service.cmr.rule.Rule serviceRuleBody = mock(org.alfresco.service.cmr.rule.Rule.class);
|
||||
given(ruleBody.toServiceModel(nodesMock)).willReturn(serviceRuleBody);
|
||||
given(ruleServiceMock.getRuleSetNode(any())).willReturn(ruleSetNodeRef);
|
||||
org.alfresco.service.cmr.rule.Rule serviceRule = mock(org.alfresco.service.cmr.rule.Rule.class);
|
||||
given(ruleServiceMock.saveRule(folderNodeRef, serviceRuleBody)).willReturn(serviceRule);
|
||||
given(serviceRule.getNodeRef()).willReturn(ruleNodeRef);
|
||||
given(serviceRule.getAction()).willReturn(action);
|
||||
|
||||
// when
|
||||
List<Rule> actual = rules.createRules(folderNodeRef.getId(), DEFAULT_ID, ruleList);
|
||||
|
||||
then(ruleServiceMock).should().getRuleSetNode(folderNodeRef);
|
||||
then(ruleServiceMock).should().isRuleSetShared(ruleSetNodeRef);
|
||||
then(ruleServiceMock).should().saveRule(folderNodeRef, ruleBody.toServiceModel(nodesMock));
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
List<Rule> expected = List.of(Rule.from(serviceRule, false));
|
||||
assertThat(actual).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveRules_ruleSetNotAssociatedWithFolder()
|
||||
{
|
||||
Rule rule = Rule.builder().name(RULE_NAME).create();
|
||||
List<Rule> ruleList = List.of(rule);
|
||||
given(ruleServiceMock.isRuleSetAssociatedWithFolder(ruleSetNodeRef, folderNodeRef)).willReturn(false);
|
||||
|
||||
// when
|
||||
assertThatExceptionOfType(InvalidArgumentException.class).isThrownBy(
|
||||
() -> rules.createRules(folderNodeRef.getId(), ruleSetNodeRef.getId(), ruleList));
|
||||
|
||||
then(ruleServiceMock).should().isRuleSetAssociatedWithFolder(ruleSetNodeRef, folderNodeRef);
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveRules_emptyRuleList()
|
||||
{
|
||||
given(ruleServiceMock.isRuleSetAssociatedWithFolder(any(), any())).willReturn(true);
|
||||
List<Rule> ruleList = emptyList();
|
||||
|
||||
// when
|
||||
List<Rule> actual = this.rules.createRules(folderNodeRef.getId(), ruleSetNodeRef.getId(), ruleList);
|
||||
|
||||
then(ruleServiceMock).should().isRuleSetAssociatedWithFolder(ruleSetNodeRef, folderNodeRef);
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
assertThat(actual).isEqualTo(emptyList());
|
||||
}
|
||||
|
||||
/** Create three rules in a single call and check they are all passed to the RuleService. */
|
||||
@Test
|
||||
public void testSaveRules_createMultipleRules()
|
||||
{
|
||||
given(ruleServiceMock.isRuleSetAssociatedWithFolder(any(), any())).willReturn(true);
|
||||
List<Rule> ruleBodyList = new ArrayList<>();
|
||||
List<Rule> expected = new ArrayList<>();
|
||||
for (String ruleId : List.of("A", "B", "C"))
|
||||
{
|
||||
Rule ruleBody = mock(Rule.class);
|
||||
ruleBodyList.add(ruleBody);
|
||||
org.alfresco.service.cmr.rule.Rule serviceRuleBody = mock(org.alfresco.service.cmr.rule.Rule.class);
|
||||
given(ruleBody.toServiceModel(nodesMock)).willReturn(serviceRuleBody);
|
||||
org.alfresco.service.cmr.rule.Rule serviceRule = mock(org.alfresco.service.cmr.rule.Rule.class);
|
||||
given(ruleServiceMock.saveRule(folderNodeRef, serviceRuleBody)).willReturn(serviceRule);
|
||||
NodeRef ruleNodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, ruleId);
|
||||
given(serviceRule.getNodeRef()).willReturn(ruleNodeRef);
|
||||
given(serviceRule.getAction()).willReturn(action);
|
||||
expected.add(Rule.from(serviceRule, false));
|
||||
}
|
||||
|
||||
// when
|
||||
List<Rule> actual = rules.createRules(folderNodeRef.getId(), ruleSetNodeRef.getId(), ruleBodyList);
|
||||
|
||||
then(ruleServiceMock).should().isRuleSetAssociatedWithFolder(ruleSetNodeRef, folderNodeRef);
|
||||
for (Rule ruleBody : ruleBodyList)
|
||||
{
|
||||
then(ruleServiceMock).should().saveRule(folderNodeRef, ruleBody.toServiceModel(nodesMock));
|
||||
}
|
||||
then(ruleServiceMock).should(times(ruleBodyList.size())).isRuleSetShared(ruleSetNodeRef);
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
assertThat(actual).isEqualTo(expected);
|
||||
}
|
||||
|
||||
/** Try to create a rule without CHANGE permission and check an exception is thrown. */
|
||||
@Test
|
||||
public void testSaveRules_noChangePermission()
|
||||
{
|
||||
given(permissionServiceMock.hasPermission(folderNodeRef, CHANGE_PERMISSIONS)).willReturn(DENIED);
|
||||
|
||||
Rule ruleBody = mock(Rule.class);
|
||||
List<Rule> ruleList = List.of(ruleBody);
|
||||
|
||||
// when
|
||||
assertThatExceptionOfType(PermissionDeniedException.class).isThrownBy(() ->
|
||||
rules.createRules(folderNodeRef.getId(), ruleSetNodeRef.getId(), ruleList));
|
||||
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
}
|
||||
|
||||
/** Check that we can update a rule. */
|
||||
@Test
|
||||
public void testUpdateRules()
|
||||
{
|
||||
Rule ruleBody = mock(Rule.class);
|
||||
given(ruleServiceMock.isRuleSetAssociatedWithFolder(any(), any())).willReturn(true);
|
||||
given(ruleServiceMock.isRuleAssociatedWithRuleSet(ruleNodeRef, ruleSetNodeRef)).willReturn(true);
|
||||
given(ruleServiceMock.isRuleSetShared(ruleSetNodeRef)).willReturn(true);
|
||||
org.alfresco.service.cmr.rule.Rule serviceRuleBody = mock(org.alfresco.service.cmr.rule.Rule.class);
|
||||
given(ruleBody.toServiceModel(nodesMock)).willReturn(serviceRuleBody);
|
||||
org.alfresco.service.cmr.rule.Rule serviceRule = mock(org.alfresco.service.cmr.rule.Rule.class);
|
||||
given(ruleServiceMock.saveRule(folderNodeRef, serviceRuleBody)).willReturn(serviceRule);
|
||||
given(serviceRule.getNodeRef()).willReturn(ruleNodeRef);
|
||||
given(serviceRule.getAction()).willReturn(action);
|
||||
|
||||
// when
|
||||
Rule updatedRule = rules.updateRuleById(folderNodeRef.getId(), ruleSetNodeRef.getId(), RULE_ID, ruleBody);
|
||||
|
||||
then(ruleServiceMock).should().isRuleSetAssociatedWithFolder(ruleSetNodeRef, folderNodeRef);
|
||||
then(ruleServiceMock).should().isRuleAssociatedWithRuleSet(ruleNodeRef, ruleSetNodeRef);
|
||||
then(ruleServiceMock).should().isRuleSetShared(ruleSetNodeRef);
|
||||
then(ruleServiceMock).should().saveRule(folderNodeRef, serviceRuleBody);
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
|
||||
Rule expected = Rule.builder().id(RULE_ID)
|
||||
.enabled(true)
|
||||
.shared(true)
|
||||
.triggers(emptyList()).create();
|
||||
assertThat(updatedRule).isEqualTo(expected);
|
||||
}
|
||||
|
||||
/** Check that we get an error if the rule set is not a child of the folder. */
|
||||
@Test
|
||||
public void testUpdateRules_ruleSetNotInFolder()
|
||||
{
|
||||
Rule ruleBody = mock(Rule.class);
|
||||
given(ruleServiceMock.isRuleSetAssociatedWithFolder(ruleSetNodeRef, folderNodeRef)).willReturn(false);
|
||||
|
||||
// when
|
||||
assertThatExceptionOfType(InvalidArgumentException.class).isThrownBy(() ->
|
||||
rules.updateRuleById(folderNodeRef.getId(), ruleSetNodeRef.getId(), RULE_ID, ruleBody));
|
||||
|
||||
then(ruleServiceMock).should().isRuleSetAssociatedWithFolder(ruleSetNodeRef, folderNodeRef);
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
}
|
||||
|
||||
/** Check that we get an error if the rule is not a child of the rule set. */
|
||||
@Test
|
||||
public void testUpdateRules_ruleNotInRuleSet()
|
||||
{
|
||||
Rule ruleBody = mock(Rule.class);
|
||||
given(ruleServiceMock.isRuleSetAssociatedWithFolder(any(), any())).willReturn(true);
|
||||
given(ruleServiceMock.isRuleAssociatedWithRuleSet(ruleNodeRef, ruleSetNodeRef)).willReturn(false);
|
||||
|
||||
// when
|
||||
assertThatExceptionOfType(InvalidArgumentException.class).isThrownBy(() ->
|
||||
rules.updateRuleById(folderNodeRef.getId(), ruleSetNodeRef.getId(), RULE_ID, ruleBody));
|
||||
|
||||
then(ruleServiceMock).should().isRuleSetAssociatedWithFolder(ruleSetNodeRef, folderNodeRef);
|
||||
then(ruleServiceMock).should().isRuleAssociatedWithRuleSet(ruleNodeRef, ruleSetNodeRef);
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
}
|
||||
|
||||
/** Try to update a rule without CHANGE permission and check an exception is thrown. */
|
||||
@Test
|
||||
public void testUpdateRules_noChangePermission()
|
||||
{
|
||||
given(permissionServiceMock.hasPermission(folderNodeRef, CHANGE_PERMISSIONS)).willReturn(DENIED);
|
||||
|
||||
Rule ruleBody = mock(Rule.class);
|
||||
|
||||
// when
|
||||
assertThatExceptionOfType(PermissionDeniedException.class).isThrownBy(() ->
|
||||
rules.updateRuleById(folderNodeRef.getId(), ruleSetNodeRef.getId(), RULE_ID, ruleBody));
|
||||
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteRuleById() {
|
||||
given(ruleServiceMock.isRuleAssociatedWithRuleSet(any(), any())).willReturn(true);
|
||||
given(ruleServiceMock.isRuleSetAssociatedWithFolder(any(), any())).willReturn(true);
|
||||
org.alfresco.service.cmr.rule.Rule rule = createRule(RULE_ID);
|
||||
given(ruleServiceMock.getRule(any())).willReturn(rule);
|
||||
|
||||
//when
|
||||
rules.deleteRuleById(FOLDER_NODE_ID, RULE_SET_ID, RULE_ID);
|
||||
|
||||
then(nodesMock).should().validateOrLookupNode(FOLDER_NODE_ID, null);
|
||||
then(nodesMock).should().validateNode(RULE_SET_ID);
|
||||
then(nodesMock).should().validateNode(RULE_ID);
|
||||
then(nodesMock).should().nodeMatches(eq(folderNodeRef), any(), isNull());
|
||||
then(nodesMock).should().nodeMatches(eq(ruleSetNodeRef), any(), isNull());
|
||||
then(nodesMock).should().nodeMatches(eq(ruleNodeRef), any(), isNull());
|
||||
then(nodesMock).shouldHaveNoMoreInteractions();
|
||||
then(permissionServiceMock).should().hasPermission(folderNodeRef, CHANGE_PERMISSIONS);
|
||||
then(permissionServiceMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).should().isRuleSetAssociatedWithFolder(ruleSetNodeRef, folderNodeRef);
|
||||
then(ruleServiceMock).should().isRuleAssociatedWithRuleSet(ruleNodeRef, ruleSetNodeRef);
|
||||
then(ruleServiceMock).should().getRule(ruleNodeRef);
|
||||
then(ruleServiceMock).should().removeRule(folderNodeRef, rule);
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteRuleById_NonExistingRuleId() {
|
||||
given(nodesMock.validateNode(RULE_ID)).willThrow(new EntityNotFoundException(RULE_ID));
|
||||
given(ruleServiceMock.isRuleSetAssociatedWithFolder(any(), any())).willReturn(true);
|
||||
|
||||
//when
|
||||
assertThatExceptionOfType(EntityNotFoundException.class).isThrownBy(
|
||||
() -> rules.deleteRuleById(FOLDER_NODE_ID, RULE_SET_ID, RULE_ID));
|
||||
|
||||
then(nodesMock).should().validateOrLookupNode(FOLDER_NODE_ID, null);
|
||||
then(nodesMock).should().validateNode(RULE_SET_ID);
|
||||
then(nodesMock).should().validateNode(RULE_ID);
|
||||
then(nodesMock).should().nodeMatches(eq(folderNodeRef), any(), isNull());
|
||||
then(nodesMock).should().nodeMatches(eq(ruleSetNodeRef), any(), isNull());
|
||||
then(nodesMock).shouldHaveNoMoreInteractions();
|
||||
then(permissionServiceMock).should().hasPermission(folderNodeRef, CHANGE_PERMISSIONS);
|
||||
then(permissionServiceMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).should().isRuleSetAssociatedWithFolder(ruleSetNodeRef, folderNodeRef);
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteRuleById_RuleIdNotInRuleSet() {
|
||||
given(ruleServiceMock.isRuleSetAssociatedWithFolder(any(), any())).willReturn(true);
|
||||
given(ruleServiceMock.isRuleAssociatedWithRuleSet(any(), any())).willReturn(false);
|
||||
|
||||
//when
|
||||
assertThatExceptionOfType(InvalidArgumentException.class).isThrownBy(
|
||||
() -> rules.deleteRuleById(FOLDER_NODE_ID, RULE_SET_ID, RULE_ID));
|
||||
|
||||
then(nodesMock).should().validateOrLookupNode(FOLDER_NODE_ID, null);
|
||||
then(nodesMock).should().validateNode(RULE_SET_ID);
|
||||
then(nodesMock).should().validateNode(RULE_ID);
|
||||
then(nodesMock).should().nodeMatches(eq(folderNodeRef), any(), isNull());
|
||||
then(nodesMock).should().nodeMatches(eq(ruleSetNodeRef), any(), isNull());
|
||||
then(nodesMock).should().nodeMatches(eq(ruleNodeRef), any(), isNull());
|
||||
then(nodesMock).shouldHaveNoMoreInteractions();
|
||||
then(permissionServiceMock).should().hasPermission(folderNodeRef, CHANGE_PERMISSIONS);
|
||||
then(permissionServiceMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).should().isRuleSetAssociatedWithFolder(ruleSetNodeRef, folderNodeRef);
|
||||
then(ruleServiceMock).should().isRuleAssociatedWithRuleSet(ruleNodeRef, ruleSetNodeRef);
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteRuleById_NonExistingRuleSetId() {
|
||||
given(nodesMock.validateNode(RULE_SET_ID)).willThrow(new EntityNotFoundException(RULE_SET_ID));
|
||||
|
||||
//when
|
||||
assertThatExceptionOfType(EntityNotFoundException.class).isThrownBy(
|
||||
() -> rules.deleteRuleById(FOLDER_NODE_ID, RULE_SET_ID, RULE_ID));
|
||||
|
||||
then(nodesMock).should().validateOrLookupNode(FOLDER_NODE_ID, null);
|
||||
then(nodesMock).should().validateNode(RULE_SET_ID);
|
||||
then(nodesMock).should().nodeMatches(eq(folderNodeRef), any(), isNull());
|
||||
then(nodesMock).shouldHaveNoMoreInteractions();
|
||||
then(permissionServiceMock).should().hasPermission(folderNodeRef, CHANGE_PERMISSIONS);
|
||||
then(permissionServiceMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteRuleById_RuleSetNotInFolder() {
|
||||
given(ruleServiceMock.isRuleSetAssociatedWithFolder(any(), any())).willReturn(false);
|
||||
|
||||
//when
|
||||
assertThatExceptionOfType(InvalidArgumentException.class).isThrownBy(
|
||||
() -> rules.deleteRuleById(FOLDER_NODE_ID, RULE_SET_ID, RULE_ID));
|
||||
|
||||
then(nodesMock).should().validateOrLookupNode(FOLDER_NODE_ID, null);
|
||||
then(nodesMock).should().validateNode(RULE_SET_ID);
|
||||
then(nodesMock).should().nodeMatches(eq(folderNodeRef), any(), isNull());
|
||||
then(nodesMock).should().nodeMatches(eq(ruleSetNodeRef), any(), isNull());
|
||||
then(nodesMock).shouldHaveNoMoreInteractions();
|
||||
then(permissionServiceMock).should().hasPermission(folderNodeRef, CHANGE_PERMISSIONS);
|
||||
then(permissionServiceMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).should().isRuleSetAssociatedWithFolder(ruleSetNodeRef, folderNodeRef);
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteRuleById_NonExistingFolderId() {
|
||||
given(nodesMock.validateOrLookupNode(FOLDER_NODE_ID, null)).willThrow(new EntityNotFoundException(RULE_ID));
|
||||
|
||||
//when
|
||||
assertThatExceptionOfType(EntityNotFoundException.class).isThrownBy(
|
||||
() -> rules.deleteRuleById(FOLDER_NODE_ID, RULE_SET_ID, RULE_ID));
|
||||
|
||||
then(nodesMock).should().validateOrLookupNode(FOLDER_NODE_ID, null);
|
||||
then(nodesMock).shouldHaveNoMoreInteractions();
|
||||
then(permissionServiceMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
}
|
||||
|
||||
/** Try to delete a rule without CHANGE permission and check an exception is thrown. */
|
||||
@Test
|
||||
public void testDeleteRuleById_noChangePermission()
|
||||
{
|
||||
given(permissionServiceMock.hasPermission(folderNodeRef, CHANGE_PERMISSIONS)).willReturn(DENIED);
|
||||
|
||||
// when
|
||||
assertThatExceptionOfType(PermissionDeniedException.class).isThrownBy(() ->
|
||||
rules.deleteRuleById(folderNodeRef.getId(), ruleSetNodeRef.getId(), RULE_ID));
|
||||
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
}
|
||||
|
||||
|
||||
private static org.alfresco.service.cmr.rule.Rule createRule(final String id) {
|
||||
final NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, id);
|
||||
final org.alfresco.service.cmr.rule.Rule rule = new org.alfresco.service.cmr.rule.Rule();
|
||||
rule.setNodeRef(nodeRef);
|
||||
rule.setRuleType("ruleType");
|
||||
rule.setAction(action);
|
||||
|
||||
return rule;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,379 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api.impl.rules;
|
||||
|
||||
import static org.alfresco.model.ContentModel.TYPE_FOLDER;
|
||||
import static org.alfresco.model.ContentModel.TYPE_SYSTEM_FOLDER;
|
||||
import static org.alfresco.repo.rule.RuleModel.TYPE_RULE;
|
||||
import static org.alfresco.rest.api.model.rules.RuleSet.DEFAULT_ID;
|
||||
import static org.alfresco.service.cmr.security.AccessStatus.ALLOWED;
|
||||
import static org.alfresco.service.cmr.security.AccessStatus.DENIED;
|
||||
import static org.alfresco.service.cmr.security.PermissionService.CHANGE_PERMISSIONS;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.BDDMockito.then;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.rest.api.Nodes;
|
||||
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
|
||||
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
|
||||
import org.alfresco.rest.framework.core.exceptions.PermissionDeniedException;
|
||||
import org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.rule.RuleService;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
public class NodeValidatorTest
|
||||
{
|
||||
|
||||
private static final String FOLDER_NODE_ID = "dummy-folder-node-id";
|
||||
private static final String RULE_SET_ID = "dummy-rule-set-id";
|
||||
private static final String RULE_ID = "dummy-rule-id";
|
||||
private static final NodeRef folderNodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, FOLDER_NODE_ID);
|
||||
private static final NodeRef ruleSetNodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, RULE_SET_ID);
|
||||
private static final NodeRef ruleNodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, RULE_ID);
|
||||
|
||||
@Mock
|
||||
private Nodes nodesMock;
|
||||
|
||||
@Mock
|
||||
private PermissionService permissionServiceMock;
|
||||
|
||||
@Mock
|
||||
private RuleService ruleServiceMock;
|
||||
|
||||
@InjectMocks
|
||||
private NodeValidator nodeValidator;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
MockitoAnnotations.openMocks(this);
|
||||
given(nodesMock.validateOrLookupNode(eq(FOLDER_NODE_ID), any())).willReturn(folderNodeRef);
|
||||
given(nodesMock.validateNode(RULE_SET_ID)).willReturn(ruleSetNodeRef);
|
||||
given(nodesMock.validateNode(RULE_ID)).willReturn(ruleNodeRef);
|
||||
given(nodesMock.nodeMatches(any(), any(), any())).willReturn(true);
|
||||
given(permissionServiceMock.hasReadPermission(any())).willReturn(ALLOWED);
|
||||
given(permissionServiceMock.hasPermission(any(), any())).willReturn(ALLOWED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateFolderNode()
|
||||
{
|
||||
// when
|
||||
final NodeRef nodeRef = nodeValidator.validateFolderNode(FOLDER_NODE_ID, false);
|
||||
|
||||
then(nodesMock).should().validateOrLookupNode(FOLDER_NODE_ID, null);
|
||||
then(nodesMock).should().nodeMatches(folderNodeRef, Set.of(TYPE_FOLDER), null);
|
||||
then(nodesMock).shouldHaveNoMoreInteractions();
|
||||
then(permissionServiceMock).should().hasReadPermission(folderNodeRef);
|
||||
then(permissionServiceMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).shouldHaveNoInteractions();
|
||||
|
||||
assertThat(nodeRef).isNotNull().isEqualTo(folderNodeRef);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateFolderNode_notExistingFolder()
|
||||
{
|
||||
given(nodesMock.validateOrLookupNode(any(), any())).willThrow(new EntityNotFoundException(FOLDER_NODE_ID));
|
||||
|
||||
//when
|
||||
assertThatExceptionOfType(EntityNotFoundException.class).isThrownBy(
|
||||
() -> nodeValidator.validateFolderNode(FOLDER_NODE_ID, false));
|
||||
|
||||
then(nodesMock).should().validateOrLookupNode(FOLDER_NODE_ID, null);
|
||||
then(nodesMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).shouldHaveNoInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateFolderNode_notMatchingTypeFolder()
|
||||
{
|
||||
given(nodesMock.nodeMatches(any(), eq(Set.of(TYPE_FOLDER)), any())).willReturn(false);
|
||||
|
||||
// when
|
||||
assertThatExceptionOfType(InvalidArgumentException.class).isThrownBy(
|
||||
() -> nodeValidator.validateFolderNode(FOLDER_NODE_ID, false));
|
||||
|
||||
then(nodesMock).should().validateOrLookupNode(FOLDER_NODE_ID, null);
|
||||
then(nodesMock).should().nodeMatches(folderNodeRef, Set.of(TYPE_FOLDER), null);
|
||||
then(nodesMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).shouldHaveNoInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateFolderNode_noReadPermission()
|
||||
{
|
||||
given(permissionServiceMock.hasReadPermission(any())).willReturn(DENIED);
|
||||
|
||||
// when
|
||||
assertThatExceptionOfType(PermissionDeniedException.class).isThrownBy(
|
||||
() -> nodeValidator.validateFolderNode(FOLDER_NODE_ID, false));
|
||||
|
||||
then(permissionServiceMock).should().hasReadPermission(folderNodeRef);
|
||||
then(permissionServiceMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).shouldHaveNoInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateFolderNode_noChangePermission()
|
||||
{
|
||||
given(permissionServiceMock.hasPermission(any(), any())).willReturn(DENIED);
|
||||
|
||||
// when
|
||||
assertThatExceptionOfType(PermissionDeniedException.class).isThrownBy(() ->
|
||||
nodeValidator.validateFolderNode(folderNodeRef.getId(), true));
|
||||
|
||||
then(permissionServiceMock).should().hasPermission(folderNodeRef, CHANGE_PERMISSIONS);
|
||||
then(permissionServiceMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateRuleSetNode()
|
||||
{
|
||||
given(ruleServiceMock.isRuleSetAssociatedWithFolder(any(), any())).willReturn(true);
|
||||
|
||||
// when
|
||||
final NodeRef nodeRef = nodeValidator.validateRuleSetNode(RULE_SET_ID, folderNodeRef);
|
||||
|
||||
then(nodesMock).should().validateNode(RULE_SET_ID);
|
||||
then(nodesMock).should().nodeMatches(ruleSetNodeRef, Set.of(TYPE_SYSTEM_FOLDER), null);
|
||||
then(nodesMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).should().isRuleSetAssociatedWithFolder(ruleSetNodeRef, folderNodeRef);
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
then(permissionServiceMock).shouldHaveNoInteractions();
|
||||
|
||||
assertThat(nodeRef).isNotNull().isEqualTo(ruleSetNodeRef);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateRuleSetNode_defaultId()
|
||||
{
|
||||
given(ruleServiceMock.getRuleSetNode(any())).willReturn(ruleSetNodeRef);
|
||||
|
||||
// when
|
||||
final NodeRef nodeRef = nodeValidator.validateRuleSetNode(DEFAULT_ID, folderNodeRef);
|
||||
|
||||
then(ruleServiceMock).should().getRuleSetNode(folderNodeRef);
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
then(nodesMock).shouldHaveNoInteractions();
|
||||
then(permissionServiceMock).shouldHaveNoInteractions();
|
||||
|
||||
assertThat(nodeRef).isNotNull().isEqualTo(ruleSetNodeRef);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateRuleSetNode_notExistingRuleSet()
|
||||
{
|
||||
given(nodesMock.validateNode(RULE_SET_ID)).willThrow(new EntityNotFoundException(RULE_SET_ID));
|
||||
|
||||
//when
|
||||
assertThatExceptionOfType(EntityNotFoundException.class).isThrownBy(
|
||||
() -> nodeValidator.validateRuleSetNode(RULE_SET_ID, folderNodeRef));
|
||||
|
||||
then(nodesMock).should().validateNode(RULE_SET_ID);
|
||||
then(nodesMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).shouldHaveNoInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateRuleSetNode_notMatchingTypeSystemFolder()
|
||||
{
|
||||
given(nodesMock.nodeMatches(any(), eq(Set.of(TYPE_SYSTEM_FOLDER)), any())).willReturn(false);
|
||||
|
||||
// when
|
||||
assertThatExceptionOfType(InvalidArgumentException.class).isThrownBy(
|
||||
() -> nodeValidator.validateRuleSetNode(RULE_SET_ID, folderNodeRef));
|
||||
|
||||
then(nodesMock).should().validateNode(RULE_SET_ID);
|
||||
then(nodesMock).should().nodeMatches(ruleSetNodeRef, Set.of(TYPE_SYSTEM_FOLDER), null);
|
||||
then(nodesMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).shouldHaveNoInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateRuleSetNode_notExistingDefaultRuleSet()
|
||||
{
|
||||
given(ruleServiceMock.getRuleSetNode(folderNodeRef)).willReturn(null);
|
||||
|
||||
// when
|
||||
assertThatExceptionOfType(RelationshipResourceNotFoundException.class).isThrownBy(
|
||||
() -> nodeValidator.validateRuleSetNode(DEFAULT_ID, folderNodeRef));
|
||||
|
||||
then(ruleServiceMock).should().getRuleSetNode(folderNodeRef);
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
then(nodesMock).shouldHaveNoInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateRuleSetNode_notAssociatedRuleSetToFolder()
|
||||
{
|
||||
given(ruleServiceMock.isRuleSetAssociatedWithFolder(any(), any())).willReturn(false);
|
||||
|
||||
// when
|
||||
assertThatExceptionOfType(InvalidArgumentException.class).isThrownBy(
|
||||
() -> nodeValidator.validateRuleSetNode(RULE_SET_ID, folderNodeRef));
|
||||
|
||||
then(ruleServiceMock).should().isRuleSetAssociatedWithFolder(ruleSetNodeRef, folderNodeRef);
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateRuleNode()
|
||||
{
|
||||
given(ruleServiceMock.isRuleAssociatedWithRuleSet(any(), any())).willReturn(true);
|
||||
|
||||
// when
|
||||
final NodeRef nodeRef = nodeValidator.validateRuleNode(RULE_ID, ruleSetNodeRef);
|
||||
|
||||
then(nodesMock).should().validateNode(RULE_ID);
|
||||
then(nodesMock).should().nodeMatches(ruleNodeRef, Set.of(TYPE_RULE), null);
|
||||
then(nodesMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).should().isRuleAssociatedWithRuleSet(ruleNodeRef, ruleSetNodeRef);
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
then(permissionServiceMock).shouldHaveNoInteractions();
|
||||
|
||||
assertThat(nodeRef).isNotNull().isEqualTo(ruleNodeRef);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateRuleNode_nullRuleSet()
|
||||
{
|
||||
// when
|
||||
final NodeRef nodeRef = nodeValidator.validateRuleNode(RULE_ID, null);
|
||||
|
||||
then(nodesMock).should().validateNode(RULE_ID);
|
||||
then(nodesMock).should().nodeMatches(ruleNodeRef, Set.of(TYPE_RULE), null);
|
||||
then(nodesMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).shouldHaveNoInteractions();
|
||||
then(permissionServiceMock).shouldHaveNoInteractions();
|
||||
|
||||
assertThat(nodeRef).isNotNull().isEqualTo(ruleNodeRef);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateRuleNode_notExistingRule()
|
||||
{
|
||||
given(nodesMock.validateNode(RULE_ID)).willThrow(new EntityNotFoundException(RULE_ID));
|
||||
|
||||
//when
|
||||
assertThatExceptionOfType(EntityNotFoundException.class).isThrownBy(
|
||||
() -> nodeValidator.validateRuleNode(RULE_ID, ruleSetNodeRef));
|
||||
|
||||
then(nodesMock).should().validateNode(RULE_ID);
|
||||
then(nodesMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).shouldHaveNoInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateRuleNode_notMatchingTypeRule()
|
||||
{
|
||||
given(nodesMock.nodeMatches(any(), eq(Set.of(TYPE_RULE)), any())).willReturn(false);
|
||||
|
||||
// when
|
||||
assertThatExceptionOfType(InvalidArgumentException.class).isThrownBy(
|
||||
() -> nodeValidator.validateRuleNode(RULE_ID, ruleSetNodeRef));
|
||||
|
||||
then(nodesMock).should().validateNode(RULE_ID);
|
||||
then(nodesMock).should().nodeMatches(ruleNodeRef, Set.of(TYPE_RULE), null);
|
||||
then(nodesMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).shouldHaveNoInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateRuleNode_notAssociatedRuleToRuleSet()
|
||||
{
|
||||
given(ruleServiceMock.isRuleAssociatedWithRuleSet(any(), any())).willReturn(false);
|
||||
|
||||
// when
|
||||
assertThatExceptionOfType(InvalidArgumentException.class).isThrownBy(
|
||||
() -> nodeValidator.validateRuleNode(RULE_ID, ruleSetNodeRef));
|
||||
|
||||
then(ruleServiceMock).should().isRuleAssociatedWithRuleSet(ruleNodeRef, ruleSetNodeRef);
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsRuleSetNotNullAndShared()
|
||||
{
|
||||
given(ruleServiceMock.isRuleSetShared(any())).willReturn(true);
|
||||
|
||||
// when
|
||||
final boolean shared = nodeValidator.isRuleSetNotNullAndShared(ruleSetNodeRef);
|
||||
|
||||
then(ruleServiceMock).should().isRuleSetShared(ruleSetNodeRef);
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
|
||||
assertThat(shared).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsRuleSetNotNullAndShared_nullRuleSetNode()
|
||||
{
|
||||
// when
|
||||
final boolean shared = nodeValidator.isRuleSetNotNullAndShared(null);
|
||||
|
||||
then(ruleServiceMock).shouldHaveNoInteractions();
|
||||
|
||||
assertThat(shared).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsRuleSetNotNullAndShared_withoutRuleSetAndWithFolder()
|
||||
{
|
||||
given(ruleServiceMock.getRuleSetNode(any())).willReturn(ruleSetNodeRef);
|
||||
|
||||
// when
|
||||
nodeValidator.isRuleSetNotNullAndShared(null, folderNodeRef);
|
||||
|
||||
then(ruleServiceMock).should().getRuleSetNode(folderNodeRef);
|
||||
then(ruleServiceMock).should().isRuleSetShared(ruleSetNodeRef);
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsRuleSetNotNullAndShared_withRuleSetAndWithFolder()
|
||||
{
|
||||
// when
|
||||
nodeValidator.isRuleSetNotNullAndShared(ruleSetNodeRef, folderNodeRef);
|
||||
|
||||
then(ruleServiceMock).should().isRuleSetShared(ruleSetNodeRef);
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.api.impl.rules;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.BDDMockito.then;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.alfresco.rest.api.model.rules.RuleSet;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Paging;
|
||||
import org.alfresco.service.Experimental;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.rule.RuleService;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
/** Unit tests for {@link RuleSetsImpl}. */
|
||||
@Experimental
|
||||
@RunWith (MockitoJUnitRunner.class)
|
||||
public class RuleSetsImplTest extends TestCase
|
||||
{
|
||||
private static final String FOLDER_ID = "dummy-folder-id";
|
||||
private static final String RULE_SET_ID = "dummy-rule-set-id";
|
||||
private static final NodeRef FOLDER_NODE = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, FOLDER_ID);
|
||||
private static final NodeRef RULE_SET_NODE = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, RULE_SET_ID);
|
||||
private static final Paging PAGING = Paging.DEFAULT;
|
||||
|
||||
@InjectMocks
|
||||
private RuleSetsImpl ruleSets;
|
||||
@Mock
|
||||
private NodeValidator nodeValidatorMock;
|
||||
@Mock
|
||||
private RuleService ruleServiceMock;
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp()
|
||||
{
|
||||
MockitoAnnotations.openMocks(this);
|
||||
|
||||
given(nodeValidatorMock.validateFolderNode(eq(FOLDER_ID), anyBoolean())).willReturn(FOLDER_NODE);
|
||||
//given(nodeValidatorMock.validateFolderNode(eq(RULE_SET_ID), anyBoolean())).willReturn(RULE_SET_NODE);
|
||||
given(nodeValidatorMock.validateRuleSetNode(RULE_SET_ID, FOLDER_NODE)).willReturn(RULE_SET_NODE);
|
||||
|
||||
given(ruleServiceMock.getRuleSetNode(FOLDER_NODE)).willReturn(RULE_SET_NODE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRuleSets()
|
||||
{
|
||||
// Call the method under test.
|
||||
CollectionWithPagingInfo<RuleSet> actual = ruleSets.getRuleSets(FOLDER_ID, null, PAGING);
|
||||
|
||||
then(nodeValidatorMock).should().validateFolderNode(FOLDER_ID, false);
|
||||
then(nodeValidatorMock).shouldHaveNoMoreInteractions();
|
||||
|
||||
then(ruleServiceMock).should().getRuleSetNode(FOLDER_NODE);
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
|
||||
Collection<RuleSet> expected = List.of(RuleSet.of(RULE_SET_ID));
|
||||
assertEquals(expected, actual.getCollection());
|
||||
assertEquals(PAGING, actual.getPaging());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetZeroRuleSets()
|
||||
{
|
||||
// Simulate no rule sets for the folder.
|
||||
given(ruleServiceMock.getRuleSetNode(FOLDER_NODE)).willReturn(null);
|
||||
|
||||
// Call the method under test.
|
||||
CollectionWithPagingInfo<RuleSet> actual = ruleSets.getRuleSets(FOLDER_ID, null, PAGING);
|
||||
|
||||
then(nodeValidatorMock).should().validateFolderNode(FOLDER_ID, false);
|
||||
then(nodeValidatorMock).shouldHaveNoMoreInteractions();
|
||||
|
||||
then(ruleServiceMock).should().getRuleSetNode(FOLDER_NODE);
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
|
||||
assertEquals(emptyList(), actual.getCollection());
|
||||
assertEquals(PAGING, actual.getPaging());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRuleSetById()
|
||||
{
|
||||
// Call the method under test.
|
||||
RuleSet actual = ruleSets.getRuleSetById(FOLDER_ID, RULE_SET_ID, null);
|
||||
|
||||
then(nodeValidatorMock).should().validateFolderNode(FOLDER_ID, false);
|
||||
then(nodeValidatorMock).should().validateRuleSetNode(RULE_SET_ID, FOLDER_NODE);
|
||||
then(nodeValidatorMock).shouldHaveNoMoreInteractions();
|
||||
|
||||
assertEquals(RuleSet.of(RULE_SET_ID), actual);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,614 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api.impl.rules;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
|
||||
import static org.alfresco.rest.api.model.rules.RuleSet.DEFAULT_ID;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.BDDMockito.then;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.alfresco.repo.action.ActionImpl;
|
||||
import org.alfresco.rest.api.Nodes;
|
||||
import org.alfresco.rest.api.model.rules.CompositeCondition;
|
||||
import org.alfresco.rest.api.model.rules.Rule;
|
||||
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
|
||||
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
|
||||
import org.alfresco.rest.framework.core.exceptions.PermissionDeniedException;
|
||||
import org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Paging;
|
||||
import org.alfresco.service.Experimental;
|
||||
import org.alfresco.service.cmr.action.Action;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.rule.RuleService;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
@Experimental
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class RulesImplTest extends TestCase
|
||||
{
|
||||
private static final String FOLDER_NODE_ID = "dummy-folder-node-id";
|
||||
private static final String RULE_SET_ID = "dummy-rule-set-id";
|
||||
private static final String RULE_ID = "dummy-rule-id";
|
||||
private static final NodeRef folderNodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, FOLDER_NODE_ID);
|
||||
private static final NodeRef ruleSetNodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, RULE_SET_ID);
|
||||
private static final NodeRef ruleNodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, RULE_ID);
|
||||
private static final Paging paging = Paging.DEFAULT;
|
||||
private static final Action action = new ActionImpl(folderNodeRef, "actionId", "actionDefinitionName");
|
||||
|
||||
@Mock
|
||||
private Nodes nodesMock;
|
||||
|
||||
@Mock
|
||||
private NodeValidator nodeValidatorMock;
|
||||
|
||||
@Mock
|
||||
private RuleService ruleServiceMock;
|
||||
|
||||
@InjectMocks
|
||||
private RulesImpl rules;
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
MockitoAnnotations.openMocks(this);
|
||||
given(nodeValidatorMock.validateFolderNode(any(), anyBoolean())).willReturn(folderNodeRef);
|
||||
given(nodeValidatorMock.validateRuleSetNode(any(), any())).willReturn(ruleSetNodeRef);
|
||||
given(nodeValidatorMock.validateRuleNode(any(), any())).willReturn(ruleNodeRef);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRules()
|
||||
{
|
||||
given(ruleServiceMock.getRules(any())).willReturn(List.of(createRule(RULE_ID)));
|
||||
|
||||
// when
|
||||
final CollectionWithPagingInfo<Rule> rulesPage = rules.getRules(FOLDER_NODE_ID, RULE_SET_ID, paging);
|
||||
|
||||
then(nodeValidatorMock).should().validateFolderNode(FOLDER_NODE_ID, false);
|
||||
then(nodeValidatorMock).should().validateRuleSetNode(RULE_SET_ID, folderNodeRef);
|
||||
then(nodeValidatorMock).should().isRuleSetNotNullAndShared(ruleSetNodeRef);
|
||||
then(nodeValidatorMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).should().getRules(folderNodeRef);
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
assertThat(rulesPage)
|
||||
.isNotNull()
|
||||
.extracting(CollectionWithPagingInfo::getCollection)
|
||||
.isNotNull()
|
||||
.extracting(Collection::size)
|
||||
.isEqualTo(1);
|
||||
assertThat(rulesPage.getCollection().stream().findFirst().orElse(null))
|
||||
.isNotNull()
|
||||
.extracting(Rule::getId)
|
||||
.isEqualTo(RULE_ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRules_emptyResult()
|
||||
{
|
||||
given(ruleServiceMock.getRules(any())).willReturn(emptyList());
|
||||
|
||||
// when
|
||||
final CollectionWithPagingInfo<Rule> rulesPage = rules.getRules(FOLDER_NODE_ID, RULE_SET_ID, paging);
|
||||
|
||||
then(ruleServiceMock).should().getRules(folderNodeRef);
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
assertThat(rulesPage)
|
||||
.isNotNull()
|
||||
.extracting(CollectionWithPagingInfo::getCollection)
|
||||
.isNotNull()
|
||||
.extracting(Collection::isEmpty)
|
||||
.isEqualTo(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRules_invalidFolder()
|
||||
{
|
||||
for (Exception exception : folderValidationExceptions())
|
||||
{
|
||||
Mockito.reset(nodeValidatorMock);
|
||||
given(nodeValidatorMock.validateFolderNode(any(), anyBoolean())).willThrow(exception);
|
||||
|
||||
// when
|
||||
assertThatExceptionOfType(exception.getClass()).isThrownBy(
|
||||
() -> rules.getRules(FOLDER_NODE_ID, RULE_SET_ID, paging));
|
||||
|
||||
then(nodeValidatorMock).should().validateFolderNode(FOLDER_NODE_ID, false);
|
||||
then(nodeValidatorMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).shouldHaveNoInteractions();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRules_invalidRuleSet()
|
||||
{
|
||||
for (Exception exception : ruleSetValidationExceptions())
|
||||
{
|
||||
Mockito.reset(nodeValidatorMock);
|
||||
given(nodeValidatorMock.validateFolderNode(any(), anyBoolean())).willReturn(folderNodeRef);
|
||||
given(nodeValidatorMock.validateRuleSetNode(any(), any())).willThrow(exception);
|
||||
|
||||
// when
|
||||
assertThatExceptionOfType(exception.getClass()).isThrownBy(
|
||||
() -> rules.getRules(FOLDER_NODE_ID, RULE_SET_ID, paging));
|
||||
|
||||
then(nodeValidatorMock).should().validateFolderNode(FOLDER_NODE_ID, false);
|
||||
then(nodeValidatorMock).should().validateRuleSetNode(RULE_SET_ID, folderNodeRef);
|
||||
then(nodeValidatorMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).shouldHaveNoInteractions();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRuleById()
|
||||
{
|
||||
given(ruleServiceMock.getRule(any())).willReturn(createRule(RULE_ID));
|
||||
|
||||
// when
|
||||
final Rule rule = rules.getRuleById(FOLDER_NODE_ID, RULE_SET_ID, RULE_ID);
|
||||
|
||||
then(nodeValidatorMock).should().validateFolderNode(FOLDER_NODE_ID, false);
|
||||
then(nodeValidatorMock).should().validateRuleSetNode(RULE_SET_ID, folderNodeRef);
|
||||
then(nodeValidatorMock).should().validateRuleNode(RULE_ID, ruleSetNodeRef);
|
||||
then(nodeValidatorMock).should().isRuleSetNotNullAndShared(ruleSetNodeRef);
|
||||
then(nodeValidatorMock).shouldHaveNoMoreInteractions();
|
||||
then(nodesMock).shouldHaveNoInteractions();
|
||||
then(ruleServiceMock).should().getRule(ruleNodeRef);
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
assertThat(rule)
|
||||
.isNotNull()
|
||||
.extracting(Rule::getId)
|
||||
.isEqualTo(RULE_ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRuleById_invalidFolder()
|
||||
{
|
||||
for (Exception exception : folderValidationExceptions())
|
||||
{
|
||||
Mockito.reset(nodeValidatorMock);
|
||||
given(nodeValidatorMock.validateFolderNode(any(), anyBoolean())).willThrow(exception);
|
||||
|
||||
// when
|
||||
assertThatExceptionOfType(exception.getClass()).isThrownBy(
|
||||
() -> rules.getRuleById(FOLDER_NODE_ID, RULE_SET_ID, RULE_ID));
|
||||
|
||||
then(nodeValidatorMock).should().validateFolderNode(FOLDER_NODE_ID, false);
|
||||
then(nodeValidatorMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).shouldHaveNoInteractions();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRuleById_invalidRuleSet()
|
||||
{
|
||||
for (Exception exception : ruleSetValidationExceptions())
|
||||
{
|
||||
Mockito.reset(nodeValidatorMock);
|
||||
given(nodeValidatorMock.validateFolderNode(any(), anyBoolean())).willReturn(folderNodeRef);
|
||||
given(nodeValidatorMock.validateRuleSetNode(any(), any())).willThrow(exception);
|
||||
|
||||
// when
|
||||
assertThatExceptionOfType(exception.getClass()).isThrownBy(
|
||||
() -> rules.getRuleById(FOLDER_NODE_ID, RULE_SET_ID, RULE_ID));
|
||||
|
||||
then(nodeValidatorMock).should().validateFolderNode(FOLDER_NODE_ID, false);
|
||||
then(nodeValidatorMock).should().validateRuleSetNode(RULE_SET_ID, folderNodeRef);
|
||||
then(nodeValidatorMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).shouldHaveNoInteractions();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRuleById_invalidRule()
|
||||
{
|
||||
for (Exception exception : ruleValidationExceptions())
|
||||
{
|
||||
Mockito.reset(nodeValidatorMock);
|
||||
given(nodeValidatorMock.validateFolderNode(any(), anyBoolean())).willReturn(folderNodeRef);
|
||||
given(nodeValidatorMock.validateRuleSetNode(any(), any())).willReturn(ruleSetNodeRef);
|
||||
given(nodeValidatorMock.validateRuleNode(any(), any())).willThrow(exception);
|
||||
|
||||
// when
|
||||
assertThatExceptionOfType(exception.getClass()).isThrownBy(
|
||||
() -> rules.getRuleById(FOLDER_NODE_ID, RULE_SET_ID, RULE_ID));
|
||||
|
||||
then(nodeValidatorMock).should().validateFolderNode(FOLDER_NODE_ID, false);
|
||||
then(nodeValidatorMock).should().validateRuleSetNode(RULE_SET_ID, folderNodeRef);
|
||||
then(nodeValidatorMock).should().validateRuleNode(RULE_ID, ruleSetNodeRef);
|
||||
then(nodeValidatorMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).shouldHaveNoInteractions();
|
||||
}
|
||||
}
|
||||
|
||||
/** Create a single rule. */
|
||||
@Test
|
||||
public void testCreateRules()
|
||||
{
|
||||
Rule ruleBody = mock(Rule.class);
|
||||
List<Rule> ruleList = List.of(ruleBody);
|
||||
org.alfresco.service.cmr.rule.Rule serviceRuleBody = mock(org.alfresco.service.cmr.rule.Rule.class);
|
||||
given(ruleBody.toServiceModel(nodesMock)).willReturn(serviceRuleBody);
|
||||
org.alfresco.service.cmr.rule.Rule serviceRule = mock(org.alfresco.service.cmr.rule.Rule.class);
|
||||
given(ruleServiceMock.saveRule(folderNodeRef, serviceRuleBody)).willReturn(serviceRule);
|
||||
given(serviceRule.getNodeRef()).willReturn(ruleNodeRef);
|
||||
given(serviceRule.getAction()).willReturn(action);
|
||||
|
||||
// when
|
||||
List<Rule> actual = rules.createRules(folderNodeRef.getId(), ruleSetNodeRef.getId(), ruleList);
|
||||
|
||||
then(nodeValidatorMock).should().validateFolderNode(FOLDER_NODE_ID, true);
|
||||
then(nodeValidatorMock).should().validateRuleSetNode(RULE_SET_ID, folderNodeRef);
|
||||
then(nodeValidatorMock).should().isRuleSetNotNullAndShared(ruleSetNodeRef, folderNodeRef);
|
||||
then(nodeValidatorMock).shouldHaveNoMoreInteractions();
|
||||
then(nodeValidatorMock).should().isRuleSetNotNullAndShared(ruleSetNodeRef, folderNodeRef);
|
||||
then(ruleServiceMock).should().saveRule(folderNodeRef, ruleBody.toServiceModel(nodesMock));
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
List<Rule> expected = List.of(Rule.from(serviceRule, false));
|
||||
assertThat(actual).isEqualTo(expected);
|
||||
}
|
||||
|
||||
/** Check that when passing the default rule set then we don't perform any validation around the rule set node. */
|
||||
@Test
|
||||
public void testCreateRules_defaultRuleSet()
|
||||
{
|
||||
Rule ruleBody = mock(Rule.class);
|
||||
List<Rule> ruleList = List.of(ruleBody);
|
||||
org.alfresco.service.cmr.rule.Rule serviceRuleBody = mock(org.alfresco.service.cmr.rule.Rule.class);
|
||||
given(ruleBody.toServiceModel(nodesMock)).willReturn(serviceRuleBody);
|
||||
org.alfresco.service.cmr.rule.Rule serviceRule = mock(org.alfresco.service.cmr.rule.Rule.class);
|
||||
given(ruleServiceMock.saveRule(folderNodeRef, serviceRuleBody)).willReturn(serviceRule);
|
||||
given(serviceRule.getNodeRef()).willReturn(ruleNodeRef);
|
||||
given(serviceRule.getAction()).willReturn(action);
|
||||
|
||||
// when
|
||||
List<Rule> actual = rules.createRules(folderNodeRef.getId(), DEFAULT_ID, ruleList);
|
||||
|
||||
then(nodeValidatorMock).should().validateFolderNode(FOLDER_NODE_ID, true);
|
||||
then(nodeValidatorMock).should().isRuleSetNotNullAndShared(null, folderNodeRef);
|
||||
then(nodeValidatorMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).should().saveRule(folderNodeRef, ruleBody.toServiceModel(nodesMock));
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
List<Rule> expected = List.of(Rule.from(serviceRule, false));
|
||||
assertThat(actual).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateRules_emptyRuleList()
|
||||
{
|
||||
List<Rule> ruleList = emptyList();
|
||||
|
||||
// when
|
||||
List<Rule> actual = rules.createRules(folderNodeRef.getId(), ruleSetNodeRef.getId(), ruleList);
|
||||
|
||||
then(ruleServiceMock).shouldHaveNoInteractions();
|
||||
assertThat(actual).isEqualTo(emptyList());
|
||||
}
|
||||
|
||||
/** Create three rules in a single call and check they are all passed to the RuleService. */
|
||||
@Test
|
||||
public void testCreateRules_createMultipleRules()
|
||||
{
|
||||
List<Rule> ruleBodyList = new ArrayList<>();
|
||||
List<Rule> expected = new ArrayList<>();
|
||||
for (String ruleId : List.of("A", "B", "C"))
|
||||
{
|
||||
Rule ruleBody = mock(Rule.class);
|
||||
ruleBodyList.add(ruleBody);
|
||||
org.alfresco.service.cmr.rule.Rule serviceRuleBody = mock(org.alfresco.service.cmr.rule.Rule.class);
|
||||
given(ruleBody.toServiceModel(nodesMock)).willReturn(serviceRuleBody);
|
||||
org.alfresco.service.cmr.rule.Rule serviceRule = mock(org.alfresco.service.cmr.rule.Rule.class);
|
||||
given(ruleServiceMock.saveRule(folderNodeRef, serviceRuleBody)).willReturn(serviceRule);
|
||||
NodeRef ruleNodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, ruleId);
|
||||
given(serviceRule.getNodeRef()).willReturn(ruleNodeRef);
|
||||
given(serviceRule.getAction()).willReturn(action);
|
||||
expected.add(Rule.from(serviceRule, false));
|
||||
}
|
||||
|
||||
// when
|
||||
List<Rule> actual = rules.createRules(folderNodeRef.getId(), ruleSetNodeRef.getId(), ruleBodyList);
|
||||
|
||||
then(nodeValidatorMock).should().validateFolderNode(FOLDER_NODE_ID, true);
|
||||
then(nodeValidatorMock).should().validateRuleSetNode(RULE_SET_ID, folderNodeRef);
|
||||
then(nodeValidatorMock).should(times(ruleBodyList.size())).isRuleSetNotNullAndShared(ruleSetNodeRef, folderNodeRef);
|
||||
then(nodeValidatorMock).shouldHaveNoMoreInteractions();
|
||||
for (Rule ruleBody : ruleBodyList)
|
||||
{
|
||||
then(ruleServiceMock).should().saveRule(folderNodeRef, ruleBody.toServiceModel(nodesMock));
|
||||
}
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
assertThat(actual).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateRules_invalidFolder()
|
||||
{
|
||||
for (Exception exception : folderValidationExceptions())
|
||||
{
|
||||
Mockito.reset(nodeValidatorMock);
|
||||
given(nodeValidatorMock.validateFolderNode(any(), anyBoolean())).willThrow(exception);
|
||||
|
||||
// when
|
||||
assertThatExceptionOfType(exception.getClass()).isThrownBy(
|
||||
() -> rules.createRules(folderNodeRef.getId(), ruleSetNodeRef.getId(), emptyList()));
|
||||
|
||||
then(nodeValidatorMock).should().validateFolderNode(FOLDER_NODE_ID, true);
|
||||
then(nodeValidatorMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).shouldHaveNoInteractions();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateRules_invalidRuleSet()
|
||||
{
|
||||
for (Exception exception : ruleSetValidationExceptions())
|
||||
{
|
||||
Mockito.reset(nodeValidatorMock);
|
||||
given(nodeValidatorMock.validateFolderNode(any(), anyBoolean())).willReturn(folderNodeRef);
|
||||
given(nodeValidatorMock.validateRuleSetNode(any(), any())).willThrow(exception);
|
||||
|
||||
// when
|
||||
assertThatExceptionOfType(exception.getClass()).isThrownBy(
|
||||
() -> rules.createRules(folderNodeRef.getId(), ruleSetNodeRef.getId(), emptyList()));
|
||||
|
||||
then(nodeValidatorMock).should().validateFolderNode(FOLDER_NODE_ID, true);
|
||||
then(nodeValidatorMock).should().validateRuleSetNode(RULE_SET_ID, folderNodeRef);
|
||||
then(nodeValidatorMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).shouldHaveNoInteractions();
|
||||
}
|
||||
}
|
||||
|
||||
/** Check that we can update a rule. */
|
||||
@Test
|
||||
public void testUpdateRuleById()
|
||||
{
|
||||
Rule ruleBody = mock(Rule.class);
|
||||
given(nodeValidatorMock.isRuleSetNotNullAndShared(any(), any())).willReturn(true);
|
||||
org.alfresco.service.cmr.rule.Rule serviceRuleBody = mock(org.alfresco.service.cmr.rule.Rule.class);
|
||||
given(ruleBody.toServiceModel(nodesMock)).willReturn(serviceRuleBody);
|
||||
org.alfresco.service.cmr.rule.Rule serviceRule = mock(org.alfresco.service.cmr.rule.Rule.class);
|
||||
given(ruleServiceMock.saveRule(folderNodeRef, serviceRuleBody)).willReturn(serviceRule);
|
||||
given(serviceRule.getNodeRef()).willReturn(ruleNodeRef);
|
||||
given(serviceRule.getAction()).willReturn(action);
|
||||
|
||||
// when
|
||||
Rule updatedRule = rules.updateRuleById(folderNodeRef.getId(), ruleSetNodeRef.getId(), RULE_ID, ruleBody);
|
||||
|
||||
then(nodeValidatorMock).should().validateFolderNode(FOLDER_NODE_ID, true);
|
||||
then(nodeValidatorMock).should().validateRuleSetNode(RULE_SET_ID, folderNodeRef);
|
||||
then(nodeValidatorMock).should().validateRuleNode(RULE_ID, ruleSetNodeRef);
|
||||
then(nodeValidatorMock).should().isRuleSetNotNullAndShared(ruleSetNodeRef, folderNodeRef);
|
||||
then(nodeValidatorMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).should().saveRule(folderNodeRef, serviceRuleBody);
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
|
||||
|
||||
Rule expected = Rule.builder().id(RULE_ID)
|
||||
.enabled(true)
|
||||
.shared(true)
|
||||
.triggers(emptyList())
|
||||
.conditions(CompositeCondition.builder().inverted(false).create())
|
||||
.create();
|
||||
assertThat(updatedRule).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateRuleById_invalidFolder()
|
||||
{
|
||||
for (Exception exception : folderValidationExceptions())
|
||||
{
|
||||
Mockito.reset(nodeValidatorMock);
|
||||
given(nodeValidatorMock.validateFolderNode(any(), anyBoolean())).willThrow(exception);
|
||||
|
||||
// when
|
||||
assertThatExceptionOfType(exception.getClass()).isThrownBy(
|
||||
() -> rules.updateRuleById(folderNodeRef.getId(), ruleSetNodeRef.getId(), RULE_ID, mock(Rule.class)));
|
||||
|
||||
then(nodeValidatorMock).should().validateFolderNode(FOLDER_NODE_ID, true);
|
||||
then(nodeValidatorMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).shouldHaveNoInteractions();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateRuleById_invalidRuleSet()
|
||||
{
|
||||
for (Exception exception : ruleSetValidationExceptions())
|
||||
{
|
||||
Mockito.reset(nodeValidatorMock);
|
||||
given(nodeValidatorMock.validateFolderNode(any(), anyBoolean())).willReturn(folderNodeRef);
|
||||
given(nodeValidatorMock.validateRuleSetNode(any(), any())).willThrow(exception);
|
||||
|
||||
// when
|
||||
assertThatExceptionOfType(exception.getClass()).isThrownBy(
|
||||
() -> rules.updateRuleById(folderNodeRef.getId(), ruleSetNodeRef.getId(), RULE_ID, mock(Rule.class)));
|
||||
|
||||
then(nodeValidatorMock).should().validateFolderNode(FOLDER_NODE_ID, true);
|
||||
then(nodeValidatorMock).should().validateRuleSetNode(RULE_SET_ID, folderNodeRef);
|
||||
then(nodeValidatorMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).shouldHaveNoInteractions();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateRuleById_invalidRule()
|
||||
{
|
||||
for (Exception exception : ruleValidationExceptions())
|
||||
{
|
||||
Mockito.reset(nodeValidatorMock);
|
||||
given(nodeValidatorMock.validateFolderNode(any(), anyBoolean())).willReturn(folderNodeRef);
|
||||
given(nodeValidatorMock.validateRuleSetNode(any(), any())).willReturn(ruleSetNodeRef);
|
||||
given(nodeValidatorMock.validateRuleNode(any(), any())).willThrow(exception);
|
||||
|
||||
// when
|
||||
assertThatExceptionOfType(exception.getClass()).isThrownBy(
|
||||
() -> rules.updateRuleById(folderNodeRef.getId(), ruleSetNodeRef.getId(), RULE_ID, mock(Rule.class)));
|
||||
|
||||
then(nodeValidatorMock).should().validateFolderNode(FOLDER_NODE_ID, true);
|
||||
then(nodeValidatorMock).should().validateRuleSetNode(RULE_SET_ID, folderNodeRef);
|
||||
then(nodeValidatorMock).should().validateRuleNode(RULE_ID, ruleSetNodeRef);
|
||||
then(nodeValidatorMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).shouldHaveNoInteractions();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteRuleById() {
|
||||
org.alfresco.service.cmr.rule.Rule rule = createRule(RULE_ID);
|
||||
given(ruleServiceMock.getRule(any())).willReturn(rule);
|
||||
|
||||
//when
|
||||
rules.deleteRuleById(FOLDER_NODE_ID, RULE_SET_ID, RULE_ID);
|
||||
|
||||
then(nodeValidatorMock).should().validateFolderNode(FOLDER_NODE_ID, true);
|
||||
then(nodeValidatorMock).should().validateRuleSetNode(RULE_SET_ID, folderNodeRef);
|
||||
then(nodeValidatorMock).should().validateRuleNode(RULE_ID, ruleSetNodeRef);
|
||||
then(nodeValidatorMock).shouldHaveNoMoreInteractions();
|
||||
then(nodesMock).shouldHaveNoInteractions();
|
||||
then(ruleServiceMock).should().getRule(ruleNodeRef);
|
||||
then(ruleServiceMock).should().removeRule(folderNodeRef, rule);
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteRuleById_invalidFolder()
|
||||
{
|
||||
for (Exception exception : folderValidationExceptions())
|
||||
{
|
||||
Mockito.reset(nodeValidatorMock);
|
||||
given(nodeValidatorMock.validateFolderNode(any(), anyBoolean())).willThrow(exception);
|
||||
|
||||
// when
|
||||
assertThatExceptionOfType(exception.getClass()).isThrownBy(
|
||||
() -> rules.deleteRuleById(FOLDER_NODE_ID, RULE_SET_ID, RULE_ID));
|
||||
|
||||
then(nodeValidatorMock).should().validateFolderNode(FOLDER_NODE_ID, true);
|
||||
then(nodeValidatorMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).shouldHaveNoInteractions();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteRuleById_invalidRuleSet()
|
||||
{
|
||||
for (Exception exception : ruleSetValidationExceptions())
|
||||
{
|
||||
Mockito.reset(nodeValidatorMock);
|
||||
given(nodeValidatorMock.validateFolderNode(any(), anyBoolean())).willReturn(folderNodeRef);
|
||||
given(nodeValidatorMock.validateRuleSetNode(any(), any())).willThrow(exception);
|
||||
|
||||
// when
|
||||
assertThatExceptionOfType(exception.getClass()).isThrownBy(
|
||||
() -> rules.deleteRuleById(FOLDER_NODE_ID, RULE_SET_ID, RULE_ID));
|
||||
|
||||
then(nodeValidatorMock).should().validateFolderNode(FOLDER_NODE_ID, true);
|
||||
then(nodeValidatorMock).should().validateRuleSetNode(RULE_SET_ID, folderNodeRef);
|
||||
then(nodeValidatorMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).shouldHaveNoInteractions();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteRuleById_invalidRule()
|
||||
{
|
||||
for (Exception exception : ruleValidationExceptions())
|
||||
{
|
||||
Mockito.reset(nodeValidatorMock);
|
||||
given(nodeValidatorMock.validateFolderNode(any(), anyBoolean())).willReturn(folderNodeRef);
|
||||
given(nodeValidatorMock.validateRuleSetNode(any(), any())).willReturn(ruleSetNodeRef);
|
||||
given(nodeValidatorMock.validateRuleNode(any(), any())).willThrow(exception);
|
||||
|
||||
// when
|
||||
assertThatExceptionOfType(exception.getClass()).isThrownBy(
|
||||
() -> rules.deleteRuleById(FOLDER_NODE_ID, RULE_SET_ID, RULE_ID));
|
||||
|
||||
then(nodeValidatorMock).should().validateFolderNode(FOLDER_NODE_ID, true);
|
||||
then(nodeValidatorMock).should().validateRuleSetNode(RULE_SET_ID, folderNodeRef);
|
||||
then(nodeValidatorMock).should().validateRuleNode(RULE_ID, ruleSetNodeRef);
|
||||
then(nodeValidatorMock).shouldHaveNoMoreInteractions();
|
||||
then(ruleServiceMock).shouldHaveNoInteractions();
|
||||
}
|
||||
}
|
||||
|
||||
private static org.alfresco.service.cmr.rule.Rule createRule(final String id) {
|
||||
final NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, id);
|
||||
final org.alfresco.service.cmr.rule.Rule rule = new org.alfresco.service.cmr.rule.Rule();
|
||||
rule.setNodeRef(nodeRef);
|
||||
rule.setRuleType("ruleType");
|
||||
rule.setAction(action);
|
||||
|
||||
return rule;
|
||||
}
|
||||
|
||||
private static List<Exception> folderValidationExceptions()
|
||||
{
|
||||
return List.of(
|
||||
new EntityNotFoundException(FOLDER_NODE_ID),
|
||||
new InvalidArgumentException(),
|
||||
new PermissionDeniedException()
|
||||
);
|
||||
}
|
||||
|
||||
private static List<Exception> ruleSetValidationExceptions()
|
||||
{
|
||||
return List.of(
|
||||
new EntityNotFoundException(RULE_SET_ID),
|
||||
new InvalidArgumentException(),
|
||||
new RelationshipResourceNotFoundException(RULE_SET_ID, "fake-relationship-id")
|
||||
);
|
||||
}
|
||||
|
||||
private static List<Exception> ruleValidationExceptions()
|
||||
{
|
||||
return List.of(
|
||||
new EntityNotFoundException(RULE_ID),
|
||||
new InvalidArgumentException(),
|
||||
new RelationshipResourceNotFoundException(RULE_ID, "fake-relationship-id")
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api.model.rules;
|
||||
|
||||
import static org.alfresco.repo.action.executer.SetPropertyValueActionExecuter.PARAM_PROPERTY;
|
||||
import static org.alfresco.repo.action.executer.SetPropertyValueActionExecuter.PARAM_VALUE;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.action.ActionImpl;
|
||||
import org.alfresco.service.Experimental;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.junit.Test;
|
||||
|
||||
@Experimental
|
||||
public class ActionTest
|
||||
{
|
||||
|
||||
private static final String ACTION_DEFINITION_NAME = "actionDefName";
|
||||
private static final Map<String, Serializable> parameters = new HashMap<>();
|
||||
|
||||
static
|
||||
{
|
||||
parameters.put(PARAM_PROPERTY, "propertyName");
|
||||
parameters.put(PARAM_VALUE, "propertyValue");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFrom()
|
||||
{
|
||||
final NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, "ruleId");
|
||||
final org.alfresco.service.cmr.action.Action actionModel = new ActionImpl(nodeRef, "actionId", ACTION_DEFINITION_NAME, parameters);
|
||||
final Action expectedAction = Action.builder().actionDefinitionId(ACTION_DEFINITION_NAME).params(parameters).create();
|
||||
|
||||
final Action actualAction = Action.from(actionModel);
|
||||
|
||||
assertThat(actualAction).isNotNull().usingRecursiveComparison().isEqualTo(expectedAction);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFromActionModelWithNullValues()
|
||||
{
|
||||
final org.alfresco.service.cmr.action.Action actionModel = new ActionImpl(null, null, null);
|
||||
final Action expectedAction = Action.builder().params(Collections.emptyMap()).create();
|
||||
|
||||
final Action actualAction = Action.from(actionModel);
|
||||
|
||||
assertThat(actualAction).isNotNull().usingRecursiveComparison().isEqualTo(expectedAction);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api.model.rules;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.action.ActionConditionImpl;
|
||||
import org.alfresco.repo.action.evaluator.ComparePropertyValueEvaluator;
|
||||
import org.alfresco.service.Experimental;
|
||||
import org.alfresco.service.cmr.action.ActionCondition;
|
||||
import org.junit.Test;
|
||||
|
||||
@Experimental
|
||||
public class CompositeConditionTest
|
||||
{
|
||||
|
||||
@Test
|
||||
public void testFrom()
|
||||
{
|
||||
final List<ActionCondition> actionConditions = List.of(
|
||||
createActionCondition("value1"),
|
||||
createActionCondition("value2", true),
|
||||
createActionCondition("value3")
|
||||
);
|
||||
final CompositeCondition expectedCompositeCondition = createCompositeCondition(List.of(
|
||||
createCompositeCondition(false, List.of(
|
||||
createSimpleCondition("value1"),
|
||||
createSimpleCondition("value3")
|
||||
)),
|
||||
createCompositeCondition(true, List.of(
|
||||
createSimpleCondition("value2")
|
||||
))
|
||||
));
|
||||
|
||||
// when
|
||||
final CompositeCondition actualCompositeCondition = CompositeCondition.from(actionConditions);
|
||||
|
||||
assertThat(actualCompositeCondition).isNotNull().usingRecursiveComparison().isEqualTo(expectedCompositeCondition);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFromEmptyList()
|
||||
{
|
||||
final List<ActionCondition> actionConditions = Collections.emptyList();
|
||||
final CompositeCondition expectedCompositeCondition = CompositeCondition.builder().create();
|
||||
|
||||
// when
|
||||
final CompositeCondition actualCompositeCondition = CompositeCondition.from(actionConditions);
|
||||
|
||||
assertThat(actualCompositeCondition).isNotNull().usingRecursiveComparison().isEqualTo(expectedCompositeCondition);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFromNullValue()
|
||||
{
|
||||
// when
|
||||
final CompositeCondition actualCompositeCondition = CompositeCondition.from(null);
|
||||
|
||||
assertThat(actualCompositeCondition).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFromListContainingNull()
|
||||
{
|
||||
final List<ActionCondition> actionConditions = new ArrayList<>();
|
||||
actionConditions.add(null);
|
||||
final CompositeCondition expectedCompositeCondition = CompositeCondition.builder().create();
|
||||
|
||||
// when
|
||||
final CompositeCondition actualCompositeCondition = CompositeCondition.from(actionConditions);
|
||||
|
||||
assertThat(actualCompositeCondition).isNotNull().usingRecursiveComparison().isEqualTo(expectedCompositeCondition);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOfSimpleConditions()
|
||||
{
|
||||
final List<SimpleCondition> simpleConditions = List.of(SimpleCondition.builder().field("field").comparator("comparator").parameter("param").create());
|
||||
final boolean inverted = true;
|
||||
final ConditionOperator conditionOperator = ConditionOperator.OR;
|
||||
final CompositeCondition expectedCondition = createCompositeCondition(inverted, conditionOperator, null, simpleConditions);
|
||||
|
||||
// when
|
||||
final CompositeCondition actualCompositeCondition = CompositeCondition.ofSimpleConditions(simpleConditions, inverted, conditionOperator);
|
||||
|
||||
assertThat(actualCompositeCondition).isNotNull().usingRecursiveComparison().isEqualTo(expectedCondition);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOfEmptySimpleConditions()
|
||||
{
|
||||
// when
|
||||
final CompositeCondition actualCompositeCondition = CompositeCondition.ofSimpleConditions(Collections.emptyList(), false, ConditionOperator.AND);
|
||||
|
||||
assertThat(actualCompositeCondition).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOfNullSimpleConditions()
|
||||
{
|
||||
// when
|
||||
final CompositeCondition actualCompositeCondition = CompositeCondition.ofSimpleConditions(null, false, ConditionOperator.AND);
|
||||
|
||||
assertThat(actualCompositeCondition).isNull();
|
||||
}
|
||||
|
||||
private static ActionCondition createActionCondition(final String value)
|
||||
{
|
||||
return createActionCondition(value, false);
|
||||
}
|
||||
|
||||
private static ActionCondition createActionCondition(final String value, final boolean inverted)
|
||||
{
|
||||
final ActionCondition actionCondition = new ActionConditionImpl("fake-id", ComparePropertyValueEvaluator.NAME);
|
||||
actionCondition.setInvertCondition(inverted);
|
||||
final Map<String, Serializable> parameterValues = new HashMap<>();
|
||||
parameterValues.put(ComparePropertyValueEvaluator.PARAM_CONTENT_PROPERTY, "content-property");
|
||||
parameterValues.put(ComparePropertyValueEvaluator.PARAM_OPERATION, "operation");
|
||||
parameterValues.put(ComparePropertyValueEvaluator.PARAM_VALUE, value);
|
||||
actionCondition.setParameterValues(parameterValues);
|
||||
return actionCondition;
|
||||
}
|
||||
|
||||
private static SimpleCondition createSimpleCondition(final String value) {
|
||||
return SimpleCondition.builder()
|
||||
.field("content-property")
|
||||
.comparator("operation")
|
||||
.parameter(value)
|
||||
.create();
|
||||
}
|
||||
|
||||
private static CompositeCondition createCompositeCondition(final List<CompositeCondition> compositeConditions) {
|
||||
return createCompositeCondition(false, ConditionOperator.AND, compositeConditions, null);
|
||||
}
|
||||
|
||||
private static CompositeCondition createCompositeCondition(final boolean inverted, final List<SimpleCondition> simpleConditions) {
|
||||
return createCompositeCondition(inverted, ConditionOperator.AND, null, simpleConditions);
|
||||
}
|
||||
|
||||
private static CompositeCondition createCompositeCondition(final boolean inverted, final ConditionOperator conditionOperator,
|
||||
final List<CompositeCondition> compositeConditions, final List<SimpleCondition> simpleConditions) {
|
||||
return CompositeCondition.builder()
|
||||
.inverted(inverted)
|
||||
.booleanMode(conditionOperator)
|
||||
.compositeConditions(compositeConditions)
|
||||
.simpleConditions(simpleConditions)
|
||||
.create();
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@ package org.alfresco.rest.api.model.rules;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.repo.action.ActionConditionImpl;
|
||||
@@ -39,7 +40,6 @@ import org.alfresco.service.cmr.action.ActionCondition;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.rule.RuleType;
|
||||
import org.assertj.core.api.Condition;
|
||||
import org.junit.Test;
|
||||
|
||||
@Experimental
|
||||
@@ -50,7 +50,7 @@ public class RuleTest
|
||||
private static final String RULE_DESCRIPTION = "rule description";
|
||||
private static final boolean RULE_ENABLED = true;
|
||||
private static final boolean RULE_CASCADE = true;
|
||||
private static final boolean RULE_ASYNC = false;
|
||||
private static final boolean RULE_ASYNC = true;
|
||||
private static final boolean RULE_SHARED = true;
|
||||
private static final String ERROR_SCRIPT = "error-script-ref";
|
||||
|
||||
@@ -111,6 +111,7 @@ public class RuleTest
|
||||
.shared(RULE_SHARED)
|
||||
.triggers(List.of(RuleTrigger.INBOUND, RuleTrigger.UPDATE))
|
||||
.errorScript(ERROR_SCRIPT)
|
||||
.conditions(CompositeCondition.from(Collections.emptyList()))
|
||||
.create();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api.model.rules;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.alfresco.repo.action.ActionConditionImpl;
|
||||
import org.alfresco.repo.action.evaluator.CompareMimeTypeEvaluator;
|
||||
import org.alfresco.repo.action.evaluator.ComparePropertyValueEvaluator;
|
||||
import org.alfresco.repo.action.evaluator.HasAspectEvaluator;
|
||||
import org.alfresco.repo.action.evaluator.HasChildEvaluator;
|
||||
import org.alfresco.repo.action.evaluator.HasTagEvaluator;
|
||||
import org.alfresco.repo.action.evaluator.HasVersionHistoryEvaluator;
|
||||
import org.alfresco.repo.action.evaluator.InCategoryEvaluator;
|
||||
import org.alfresco.repo.action.evaluator.IsSubTypeEvaluator;
|
||||
import org.alfresco.repo.action.evaluator.NoConditionEvaluator;
|
||||
import org.alfresco.service.Experimental;
|
||||
import org.alfresco.service.cmr.action.ActionCondition;
|
||||
import org.junit.Test;
|
||||
|
||||
@Experimental
|
||||
public class SimpleConditionTest
|
||||
{
|
||||
|
||||
private static List<TestData> getTestData() {
|
||||
return List.of(
|
||||
TestData.of(ComparePropertyValueEvaluator.NAME),
|
||||
TestData.of(CompareMimeTypeEvaluator.NAME),
|
||||
TestData.of(HasAspectEvaluator.NAME),
|
||||
TestData.of(HasChildEvaluator.NAME),
|
||||
TestData.of(HasTagEvaluator.NAME),
|
||||
TestData.of(HasVersionHistoryEvaluator.NAME),
|
||||
TestData.of(InCategoryEvaluator.NAME),
|
||||
TestData.of(IsSubTypeEvaluator.NAME),
|
||||
TestData.of(NoConditionEvaluator.NAME, true),
|
||||
TestData.of("fake-definition-name", true),
|
||||
TestData.of("", true),
|
||||
TestData.of(null, true)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFrom()
|
||||
{
|
||||
for (TestData testData : getTestData())
|
||||
{
|
||||
final ActionCondition actionCondition = createActionCondition(testData.actionDefinitionName);
|
||||
|
||||
// when
|
||||
final SimpleCondition actualSimpleCondition = SimpleCondition.from(actionCondition);
|
||||
|
||||
assertThat(Objects.isNull(actualSimpleCondition)).isEqualTo(testData.isNullResult);
|
||||
if (!testData.isNullResult)
|
||||
{
|
||||
assertThat(actualSimpleCondition.getField()).isNotEmpty();
|
||||
assertThat(actualSimpleCondition.getComparator()).isNotEmpty();
|
||||
assertThat(actualSimpleCondition.getParameter()).isNotEmpty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFromNullValue()
|
||||
{
|
||||
// when
|
||||
final SimpleCondition actualSimpleCondition = SimpleCondition.from(null);
|
||||
|
||||
assertThat(actualSimpleCondition).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFromActionConditionWithoutDefinitionName()
|
||||
{
|
||||
final ActionCondition actionCondition = new ActionConditionImpl("fake-id", null, createParameterValues());
|
||||
|
||||
// when
|
||||
final SimpleCondition actualSimpleCondition = SimpleCondition.from(actionCondition);
|
||||
|
||||
assertThat(actualSimpleCondition).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFromActionConditionWithoutParameterValues()
|
||||
{
|
||||
final ActionCondition actionCondition = new ActionConditionImpl("fake-id", "fake-def-name", null);
|
||||
|
||||
// when
|
||||
final SimpleCondition actualSimpleCondition = SimpleCondition.from(actionCondition);
|
||||
|
||||
assertThat(actualSimpleCondition).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListOf()
|
||||
{
|
||||
final List<ActionCondition> actionConditions = List.of(
|
||||
createActionCondition(ComparePropertyValueEvaluator.NAME),
|
||||
createActionCondition(CompareMimeTypeEvaluator.NAME)
|
||||
);
|
||||
final List<SimpleCondition> expectedSimpleConditions = List.of(
|
||||
SimpleCondition.builder().field("content-property").comparator("operation").parameter("value").create(),
|
||||
SimpleCondition.builder().field("property").comparator("equals").parameter("value").create()
|
||||
);
|
||||
|
||||
// when
|
||||
final List<SimpleCondition> actualSimpleConditions = SimpleCondition.listOf(actionConditions);
|
||||
|
||||
assertThat(actualSimpleConditions)
|
||||
.isNotNull()
|
||||
.containsExactlyElementsOf(expectedSimpleConditions);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListOfEmptyActionConditions()
|
||||
{
|
||||
final List<SimpleCondition> actualSimpleConditions = SimpleCondition.listOf(Collections.emptyList());
|
||||
|
||||
assertThat(actualSimpleConditions).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListOfNullActionConditions()
|
||||
{
|
||||
final List<SimpleCondition> actualSimpleConditions = SimpleCondition.listOf(null);
|
||||
|
||||
assertThat(actualSimpleConditions).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListOfActionConditionsContainingNull()
|
||||
{
|
||||
final List<ActionCondition> actionConditions = new ArrayList<>();
|
||||
actionConditions.add(null);
|
||||
|
||||
final List<SimpleCondition> actualSimpleConditions = SimpleCondition.listOf(actionConditions);
|
||||
|
||||
assertThat(actualSimpleConditions).isNotNull().isEmpty();
|
||||
}
|
||||
|
||||
private static ActionCondition createActionCondition(final String actionDefinitionName)
|
||||
{
|
||||
return new ActionConditionImpl("fake-id", actionDefinitionName, createParameterValues());
|
||||
}
|
||||
|
||||
private static Map<String, Serializable> createParameterValues() {
|
||||
final Map<String, Serializable> parameterValues = new HashMap<>();
|
||||
parameterValues.put(ComparePropertyValueEvaluator.PARAM_CONTENT_PROPERTY, "content-property");
|
||||
parameterValues.put(HasChildEvaluator.PARAM_ASSOC_TYPE, "assoc-type");
|
||||
parameterValues.put(ComparePropertyValueEvaluator.PARAM_PROPERTY, "property");
|
||||
parameterValues.put(ComparePropertyValueEvaluator.PARAM_OPERATION, "operation");
|
||||
parameterValues.put(ComparePropertyValueEvaluator.PARAM_VALUE, "value");
|
||||
parameterValues.put(HasAspectEvaluator.PARAM_ASPECT, "aspect");
|
||||
parameterValues.put(HasChildEvaluator.PARAM_ASSOC_NAME, "assoc-name");
|
||||
parameterValues.put(HasTagEvaluator.PARAM_TAG, "tag");
|
||||
parameterValues.put(InCategoryEvaluator.PARAM_CATEGORY_ASPECT, "category-aspect");
|
||||
parameterValues.put(InCategoryEvaluator.PARAM_CATEGORY_VALUE, "category-value");
|
||||
parameterValues.put(IsSubTypeEvaluator.PARAM_TYPE, "type");
|
||||
|
||||
return parameterValues;
|
||||
}
|
||||
|
||||
private static class TestData
|
||||
{
|
||||
String actionDefinitionName;
|
||||
boolean isNullResult;
|
||||
|
||||
public TestData(String actionDefinitionName, boolean isNullResult)
|
||||
{
|
||||
this.actionDefinitionName = actionDefinitionName;
|
||||
this.isNullResult = isNullResult;
|
||||
}
|
||||
|
||||
public static TestData of(String actionDefinitionName) {
|
||||
return new TestData(actionDefinitionName, false);
|
||||
}
|
||||
|
||||
public static TestData of(String actionDefinitionName, boolean isNullResult) {
|
||||
return new TestData(actionDefinitionName, isNullResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +1,30 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.api.tests;
|
||||
|
||||
import org.apache.chemistry.opencmis.server.impl.atompub.CmisAtomPubServlet;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
|
||||
/**
|
||||
* Manages an embedded jetty server, hooking it up to the repository spring context and providing
|
||||
* authenticated, tenant-based access through the tenant servlet.
|
||||
@@ -42,15 +38,4 @@ public class EnterpriseJettyComponent extends PublicApiJettyComponent
|
||||
{
|
||||
super(port, contextPath, configLocations, classLocations);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureWebAppContext(WebAppContext webAppContext)
|
||||
{
|
||||
super.configureWebAppContext(webAppContext);
|
||||
|
||||
// the tenant servlet with alfresco managed authentication
|
||||
ServletHolder servletHolder = new ServletHolder(CmisAtomPubServlet.class);
|
||||
servletHolder.setInitParameter("callContextHandler", "org.apache.chemistry.opencmis.server.shared.BasicAuthCallContextHandler");
|
||||
webAppContext.addServlet(servletHolder, "/cmisatom/*");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ public class ModulePackagesApiTest extends AbstractBaseApiTest
|
||||
assertNotNull(response);
|
||||
assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatusCode());
|
||||
assertEquals("no-cache", response.getHeaders().get("Cache-Control"));
|
||||
assertEquals("application/json;charset=UTF-8", response.getHeaders().get("Content-Type"));
|
||||
assertEquals("application/json;charset=utf-8", response.getHeaders().get("Content-Type"));
|
||||
|
||||
PublicApiClient.ExpectedErrorResponse errorResponse = RestApiUtil.parseErrorResponse(response.getJsonResponse());
|
||||
assertNotNull(errorResponse);
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.api.tests;
|
||||
|
||||
import org.alfresco.repo.web.util.AbstractJettyComponent;
|
||||
@@ -48,63 +48,16 @@ public class PublicApiJettyComponent extends AbstractJettyComponent
|
||||
@Override
|
||||
protected void configureWebAppContext(WebAppContext webAppContext)
|
||||
{
|
||||
// ServletContext servletContext = webAppContext.getServletContext();
|
||||
|
||||
// the tenant servlet with alfresco managed authentication
|
||||
ServletHolder servletHolder = new ServletHolder(PublicApiWebScriptServlet.class);
|
||||
servletHolder.setInitParameter("authenticator", "publicapi.authenticator");
|
||||
webAppContext.addServlet(servletHolder, "/" + publicApiServletName + "/*");
|
||||
|
||||
// DependencyInjectedFilter apiFilter = (DependencyInjectedFilter)getApplicationContext().getBean("publicAPICMISFilter");
|
||||
// BeanProxyFilter filter = new BeanProxyFilter(servletContext, apiFilter);
|
||||
// FilterHolder filterHolder = new FilterHolder(filter);
|
||||
// webAppContext.addFilter(filterHolder, "/" + publicApiServletName + "/*", null);
|
||||
|
||||
|
||||
// the tenant servlet with alfresco managed authentication
|
||||
servletHolder = new ServletHolder(CmisAtomPubServlet.class);
|
||||
servletHolder.setInitParameter("callContextHandler", "org.apache.chemistry.opencmis.server.shared.BasicAuthCallContextHandler");
|
||||
webAppContext.addServlet(servletHolder, "/cmisatom/*");
|
||||
webAppContext.addServlet(servletHolder, "/cmisatom/*");
|
||||
}
|
||||
|
||||
// private static class BeanProxyFilter implements Filter
|
||||
// {
|
||||
// private DependencyInjectedFilter filter;
|
||||
// private ServletContext context;
|
||||
//
|
||||
// private BeanProxyFilter(ServletContext context, DependencyInjectedFilter filter)
|
||||
// {
|
||||
// this.context = context;
|
||||
// this.filter = filter;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Initialize the filter.
|
||||
// *
|
||||
// * @param args
|
||||
// * FilterConfig
|
||||
// * @throws ServletException
|
||||
// * the servlet exception
|
||||
// * @exception ServletException
|
||||
// */
|
||||
// public void init(FilterConfig args) throws ServletException
|
||||
// {
|
||||
// }
|
||||
//
|
||||
// /* (non-Javadoc)
|
||||
// * @see javax.servlet.Filter#destroy()
|
||||
// */
|
||||
// public void destroy()
|
||||
// {
|
||||
// this.filter = null;
|
||||
// }
|
||||
//
|
||||
// /* (non-Javadoc)
|
||||
// * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
|
||||
// */
|
||||
// public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
|
||||
// ServletException
|
||||
// {
|
||||
// this.filter.doFilter(this.context, request, response, chain);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -303,7 +303,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
|
||||
assertArrayEquals(file1_originalBytes, response.getResponseAsBytes());
|
||||
Map<String, String> responseHeaders = response.getHeaders();
|
||||
assertNotNull(responseHeaders);
|
||||
assertEquals(file1_MimeType+";charset=UTF-8", responseHeaders.get("Content-Type"));
|
||||
assertEquals(file1_MimeType+";charset=utf-8", responseHeaders.get("Content-Type"));
|
||||
assertNotNull(responseHeaders.get("Expires"));
|
||||
assertEquals("attachment; filename=\"" + fileName1 + "\"; filename*=UTF-8''" + fileName1 + "", responseHeaders.get("Content-Disposition"));
|
||||
String lastModifiedHeader = responseHeaders.get(LAST_MODIFIED_HEADER);
|
||||
@@ -319,7 +319,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
|
||||
assertArrayEquals(file1_originalBytes, response.getResponseAsBytes());
|
||||
responseHeaders = response.getHeaders();
|
||||
assertNotNull(responseHeaders);
|
||||
assertEquals(file1_MimeType+";charset=UTF-8", responseHeaders.get("Content-Type"));
|
||||
assertEquals(file1_MimeType+";charset=utf-8", responseHeaders.get("Content-Type"));
|
||||
assertNotNull(responseHeaders.get(LAST_MODIFIED_HEADER));
|
||||
assertNotNull(responseHeaders.get("Expires"));
|
||||
assertNull(responseHeaders.get("Content-Disposition"));
|
||||
@@ -330,7 +330,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
|
||||
assertArrayEquals(content2Text.getBytes(), response.getResponseAsBytes());
|
||||
responseHeaders = response.getHeaders();
|
||||
assertNotNull(responseHeaders);
|
||||
assertEquals(file2_MimeType+";charset=ISO-8859-1", responseHeaders.get("Content-Type"));
|
||||
assertEquals(file2_MimeType+";charset=iso-8859-1", responseHeaders.get("Content-Type"));
|
||||
assertNotNull(responseHeaders.get("Expires"));
|
||||
assertNotNull(responseHeaders.get(LAST_MODIFIED_HEADER));
|
||||
assertEquals("attachment; filename=\"" + fileName2 + "\"; filename*=UTF-8''" + fileName2 + "", responseHeaders.get("Content-Disposition"));
|
||||
@@ -392,7 +392,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
|
||||
assertTrue(response.getResponseAsBytes().length > 0);
|
||||
responseHeaders = response.getHeaders();
|
||||
assertNotNull(responseHeaders);
|
||||
assertEquals(MimetypeMap.MIMETYPE_IMAGE_PNG+";charset=UTF-8", responseHeaders.get("Content-Type"));
|
||||
assertEquals(MimetypeMap.MIMETYPE_IMAGE_PNG+";charset=utf-8", responseHeaders.get("Content-Type"));
|
||||
assertNotNull(responseHeaders.get(LAST_MODIFIED_HEADER));
|
||||
assertNotNull(responseHeaders.get("Expires"));
|
||||
String docName = "doclib";
|
||||
@@ -405,7 +405,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
|
||||
assertTrue(response.getResponseAsBytes().length > 0);
|
||||
responseHeaders = response.getHeaders();
|
||||
assertNotNull(responseHeaders);
|
||||
assertEquals(MimetypeMap.MIMETYPE_IMAGE_PNG+";charset=UTF-8", responseHeaders.get("Content-Type"));
|
||||
assertEquals(MimetypeMap.MIMETYPE_IMAGE_PNG+";charset=utf-8", responseHeaders.get("Content-Type"));
|
||||
assertNotNull(responseHeaders.get("Expires"));
|
||||
assertNull(responseHeaders.get("Content-Disposition"));
|
||||
lastModifiedHeader = responseHeaders.get(LAST_MODIFIED_HEADER);
|
||||
@@ -816,7 +816,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
|
||||
assertArrayEquals(file1_originalBytes, response.getResponseAsBytes());
|
||||
Map<String, String> responseHeaders = response.getHeaders();
|
||||
assertNotNull(responseHeaders);
|
||||
assertEquals(file1_MimeType + ";charset=UTF-8", responseHeaders.get("Content-Type"));
|
||||
assertEquals(file1_MimeType + ";charset=utf-8", responseHeaders.get("Content-Type"));
|
||||
assertNotNull(responseHeaders.get("Expires"));
|
||||
assertEquals("attachment; filename=\"" + fileName1 + "\"; filename*=UTF-8''" + fileName1 + "", responseHeaders.get("Content-Disposition"));
|
||||
String lastModifiedHeader = responseHeaders.get(LAST_MODIFIED_HEADER);
|
||||
@@ -832,7 +832,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
|
||||
assertArrayEquals(file1_originalBytes, response.getResponseAsBytes());
|
||||
responseHeaders = response.getHeaders();
|
||||
assertNotNull(responseHeaders);
|
||||
assertEquals(file1_MimeType + ";charset=UTF-8", responseHeaders.get("Content-Type"));
|
||||
assertEquals(file1_MimeType + ";charset=utf-8", responseHeaders.get("Content-Type"));
|
||||
assertNotNull(responseHeaders.get(LAST_MODIFIED_HEADER));
|
||||
assertNotNull(responseHeaders.get("Expires"));
|
||||
assertNull(responseHeaders.get("Content-Disposition"));
|
||||
@@ -888,7 +888,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
|
||||
assertTrue(response.getResponseAsBytes().length > 0);
|
||||
responseHeaders = response.getHeaders();
|
||||
assertNotNull(responseHeaders);
|
||||
assertEquals(MimetypeMap.MIMETYPE_IMAGE_PNG + ";charset=UTF-8", responseHeaders.get("Content-Type"));
|
||||
assertEquals(MimetypeMap.MIMETYPE_IMAGE_PNG + ";charset=utf-8", responseHeaders.get("Content-Type"));
|
||||
assertNotNull(responseHeaders.get(LAST_MODIFIED_HEADER));
|
||||
assertNotNull(responseHeaders.get("Expires"));
|
||||
String docName = "doclib";
|
||||
@@ -901,7 +901,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
|
||||
assertTrue(response.getResponseAsBytes().length > 0);
|
||||
responseHeaders = response.getHeaders();
|
||||
assertNotNull(responseHeaders);
|
||||
assertEquals(MimetypeMap.MIMETYPE_IMAGE_PNG + ";charset=UTF-8", responseHeaders.get("Content-Type"));
|
||||
assertEquals(MimetypeMap.MIMETYPE_IMAGE_PNG + ";charset=utf-8", responseHeaders.get("Content-Type"));
|
||||
assertNotNull(responseHeaders.get("Expires"));
|
||||
assertNull(responseHeaders.get("Content-Disposition"));
|
||||
lastModifiedHeader = responseHeaders.get(LAST_MODIFIED_HEADER);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo</artifactId>
|
||||
<version>17.58</version>
|
||||
<version>17.75-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -862,10 +862,7 @@ public class RuleServiceImpl
|
||||
{
|
||||
// Get the action definition from the rule
|
||||
Action action = rule.getAction();
|
||||
if (action == null)
|
||||
{
|
||||
throw new RuleServiceException("An action must be specified when defining a rule.");
|
||||
}
|
||||
ParameterCheck.mandatory("Rule action", action);
|
||||
|
||||
// Get the current action node reference
|
||||
NodeRef actionNodeRef = null;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,7 +2,7 @@
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
@@ -25,44 +25,39 @@
|
||||
*/
|
||||
package org.alfresco.repo.content.transform;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import static org.alfresco.repo.content.transform.LocalTransformServiceRegistry.LOCAL_TRANSFORMER;
|
||||
import static org.alfresco.repo.content.transform.LocalTransformServiceRegistry.URL;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.Properties;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class LocalTransformServiceRegistryTest
|
||||
{
|
||||
@Spy
|
||||
private Properties properties = new Properties();
|
||||
|
||||
private Properties properties;
|
||||
@InjectMocks
|
||||
LocalTransformServiceRegistry registry = new LocalTransformServiceRegistry();
|
||||
|
||||
@Rule
|
||||
public MockitoRule initRule = MockitoJUnit.rule();
|
||||
private LocalTransformServiceRegistry registry;
|
||||
|
||||
@Test
|
||||
public void testGetTEngineUrlsSortedByName() throws IOException
|
||||
public void testGetTEngineUrlsSortedByName()
|
||||
{
|
||||
properties.put(LOCAL_TRANSFORMER+"aa"+URL, "aa");
|
||||
properties.put(LOCAL_TRANSFORMER+"engine1"+URL, "http_xxxx1");
|
||||
properties.put(LOCAL_TRANSFORMER+"engine3"+URL, "http3");
|
||||
properties.put(LOCAL_TRANSFORMER+"engine2"+URL, "http_xx2");
|
||||
properties.put(LOCAL_TRANSFORMER+"bb"+URL, "bb");
|
||||
properties.put(LOCAL_TRANSFORMER+"b"+URL, "b");
|
||||
properties.put(LOCAL_TRANSFORMER + "aa" + URL, "aa");
|
||||
properties.put(LOCAL_TRANSFORMER + "engine1" + URL, "http_xxxx1");
|
||||
properties.put(LOCAL_TRANSFORMER + "engine3" + URL, "http3");
|
||||
properties.put(LOCAL_TRANSFORMER + "engine2" + URL, "http_xx2");
|
||||
properties.put(LOCAL_TRANSFORMER + "bb" + URL, "bb");
|
||||
properties.put(LOCAL_TRANSFORMER + "b" + URL, "b");
|
||||
|
||||
StringJoiner orderEngineConfigRead = new StringJoiner(",");
|
||||
registry.getTEngineUrlsSortedByName().forEach(name -> orderEngineConfigRead.add(name));
|
||||
registry.getTEngineUrlsSortedByName().forEach(orderEngineConfigRead::add);
|
||||
assertEquals("aa,b,bb,http_xxxx1,http_xx2,http3", orderEngineConfigRead.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -455,7 +455,7 @@ public class ImapMessageTest extends TestCase
|
||||
};
|
||||
// UID SEARCH SINCE
|
||||
Response[] ret = (Response[]) folder.doCommand(uid_search_since);
|
||||
assertEquals("java.net.SocketException: Connection reset", ret[0].getException().toString());
|
||||
assertEquals("java.io.IOException: Connection dropped by server?", ret[0].getException().toString());
|
||||
}
|
||||
catch (MessagingException e)
|
||||
{
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.model.ml.tools;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -45,7 +45,7 @@ import org.junit.experimental.categories.Category;
|
||||
public class ContentFilterLanguagesMapTest extends AbstractMultilingualTestCases
|
||||
{
|
||||
|
||||
public void testGetFilterLanguages() throws Exception
|
||||
public void testGetFilterLanguages()
|
||||
{
|
||||
// get the list of content filter languages
|
||||
List<String> lggs = contentFilterLanguagesService.getFilterLanguages();
|
||||
@@ -57,7 +57,7 @@ public class ContentFilterLanguagesMapTest extends AbstractMultilingualTestCases
|
||||
try
|
||||
{
|
||||
lggs.add("NEW LOCALE");
|
||||
assertTrue("Add a value to the content filter language list is not permit, this list would be read only", false);
|
||||
fail("Add a value to the content filter language list is not permit, this list would be read only");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -67,7 +67,7 @@ public class ContentFilterLanguagesMapTest extends AbstractMultilingualTestCases
|
||||
try
|
||||
{
|
||||
lggs.remove(0);
|
||||
assertTrue("Remove a value to the content filter language list is not permit, this list would be read only", false);
|
||||
fail("Remove a value to the content filter language list is not permit, this list would be read only");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -76,7 +76,7 @@ public class ContentFilterLanguagesMapTest extends AbstractMultilingualTestCases
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testGetMissingLanguages() throws Exception
|
||||
public void testGetMissingLanguages()
|
||||
{
|
||||
List<String> lggs = contentFilterLanguagesService.getFilterLanguages();
|
||||
|
||||
@@ -97,7 +97,7 @@ public class ContentFilterLanguagesMapTest extends AbstractMultilingualTestCases
|
||||
assertEquals("Language list returned with the empty parameter corrupted", missingLggsEmpty.size(), lggs.size());
|
||||
|
||||
// get missing languages with a two locale list
|
||||
List<String> param = new ArrayList<String>();
|
||||
List<String> param = new ArrayList<>();
|
||||
param.add(0, lggs.get(0));
|
||||
param.add(1, lggs.get(1));
|
||||
List<String> missingLggsOk = contentFilterLanguagesService.getMissingLanguages(param);
|
||||
@@ -123,29 +123,29 @@ public class ContentFilterLanguagesMapTest extends AbstractMultilingualTestCases
|
||||
assertFalse("Language found : " + param.get(2), missingLggsWrong.contains(param.get(2)));
|
||||
}
|
||||
|
||||
public void testISOCodeConvertions() throws Exception
|
||||
public void testISOCodeConversions()
|
||||
{
|
||||
// New ISO code list
|
||||
String[] newCode = {"he", "id", "yi"};
|
||||
String[] oldCode = {"iw", "in", "ji"};
|
||||
|
||||
Locale loc0 = new Locale(newCode[0]);
|
||||
Locale loc1 = new Locale(newCode[1]);
|
||||
Locale loc2 = new Locale(newCode[2]);
|
||||
Locale loc0 = new Locale(oldCode[0]);
|
||||
Locale loc1 = new Locale(oldCode[1]);
|
||||
Locale loc2 = new Locale(oldCode[2]);
|
||||
|
||||
// Ensure that java.util.Locale has converted the new ISO code into new iso code
|
||||
assertEquals("java.util.Locale Convertion not correct for " + newCode[0], oldCode[0], loc0.getLanguage());
|
||||
assertEquals("java.util.Locale Convertion not correct for " + newCode[1], oldCode[1], loc1.getLanguage());
|
||||
assertEquals("java.util.Locale Convertion not correct for " + newCode[2], oldCode[2], loc2.getLanguage());
|
||||
// Ensure that java.util.Locale has converted the old ISO code into new ISO code
|
||||
// This conversion can be avoided by setting the java.locale.useOldISOCodes=true system property
|
||||
assertEquals("java.util.Locale Conversion not correct for " + oldCode[0], newCode[0], loc0.getLanguage());
|
||||
assertEquals("java.util.Locale Conversion not correct for " + oldCode[1], newCode[1], loc1.getLanguage());
|
||||
assertEquals("java.util.Locale Conversion not correct for " + oldCode[2], newCode[2], loc2.getLanguage());
|
||||
|
||||
// Ensure that the convertion is correcte
|
||||
assertEquals("Convertion of new ISO codes not correct for " + newCode[0], oldCode[0], contentFilterLanguagesService.convertToOldISOCode(newCode[0]));
|
||||
assertEquals("Convertion of new ISO codes not correct for " + newCode[1], oldCode[1], contentFilterLanguagesService.convertToOldISOCode(newCode[1]));
|
||||
assertEquals("Convertion of new ISO codes not correct for " + newCode[2], oldCode[2], contentFilterLanguagesService.convertToOldISOCode(newCode[2]));
|
||||
// Ensure that the conversion is correct
|
||||
assertEquals("Conversion of new ISO codes not correct for " + newCode[0], oldCode[0], contentFilterLanguagesService.convertToOldISOCode(newCode[0]));
|
||||
assertEquals("Conversion of new ISO codes not correct for " + newCode[1], oldCode[1], contentFilterLanguagesService.convertToOldISOCode(newCode[1]));
|
||||
assertEquals("Conversion of new ISO codes not correct for " + newCode[2], oldCode[2], contentFilterLanguagesService.convertToOldISOCode(newCode[2]));
|
||||
|
||||
|
||||
assertEquals("Convertion of old ISO codes not correct for " + oldCode[0], newCode[0], contentFilterLanguagesService.convertToNewISOCode(oldCode[0]));
|
||||
assertEquals("Convertion of old ISO codes not correct for " + oldCode[1], newCode[1], contentFilterLanguagesService.convertToNewISOCode(oldCode[1]));
|
||||
assertEquals("Convertion of old ISO codes not correct for " + oldCode[2], newCode[2], contentFilterLanguagesService.convertToNewISOCode(oldCode[2]));
|
||||
assertEquals("Conversion of old ISO codes not correct for " + oldCode[0], newCode[0], contentFilterLanguagesService.convertToNewISOCode(oldCode[0]));
|
||||
assertEquals("Conversion of old ISO codes not correct for " + oldCode[1], newCode[1], contentFilterLanguagesService.convertToNewISOCode(oldCode[1]));
|
||||
assertEquals("Conversion of old ISO codes not correct for " + oldCode[2], newCode[2], contentFilterLanguagesService.convertToNewISOCode(oldCode[2]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,10 +31,12 @@ import static org.alfresco.repo.rule.RuleModel.ASSOC_RULE_FOLDER;
|
||||
import static org.alfresco.repo.rule.RuleModel.TYPE_RULE;
|
||||
import static org.alfresco.service.cmr.security.AccessStatus.ALLOWED;
|
||||
import static org.alfresco.service.cmr.security.AccessStatus.DENIED;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.BDDMockito.then;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -44,6 +46,7 @@ import static org.mockito.Mockito.when;
|
||||
import static org.mockito.MockitoAnnotations.openMocks;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.repo.action.RuntimeActionService;
|
||||
@@ -136,7 +139,7 @@ public class RuleServiceImplUnitTest
|
||||
when(mockRule.getAction()).thenReturn(null);
|
||||
|
||||
// Call the method under test.
|
||||
assertThatExceptionOfType(RuleServiceException.class).isThrownBy(() -> ruleService.saveRule(FOLDER_NODE, mockRule));
|
||||
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> ruleService.saveRule(FOLDER_NODE, mockRule));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -187,4 +190,170 @@ public class RuleServiceImplUnitTest
|
||||
|
||||
assertThatExceptionOfType(RuleServiceException.class).isThrownBy(() -> ruleService.saveRule(FOLDER_NODE, mockRule));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRuleSetNode()
|
||||
{
|
||||
given(runtimeNodeService.getChildAssocs(any(), any(), any())).willReturn(List.of(createAssociation(FOLDER_NODE, RULE_SET_NODE)));
|
||||
|
||||
// when
|
||||
final NodeRef actualNode = ruleService.getRuleSetNode(FOLDER_NODE);
|
||||
|
||||
then(runtimeNodeService).should().getChildAssocs(FOLDER_NODE, ASSOC_RULE_FOLDER, ASSOC_RULE_FOLDER);
|
||||
then(runtimeNodeService).shouldHaveNoMoreInteractions();
|
||||
then(nodeService).shouldHaveNoInteractions();
|
||||
assertThat(actualNode).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRuleSetNode_emptyAssociation()
|
||||
{
|
||||
given(runtimeNodeService.getChildAssocs(any(), any(), any())).willReturn(Collections.emptyList());
|
||||
|
||||
// when
|
||||
final NodeRef actualNode = ruleService.getRuleSetNode(FOLDER_NODE);
|
||||
|
||||
then(runtimeNodeService).should().getChildAssocs(FOLDER_NODE, ASSOC_RULE_FOLDER, ASSOC_RULE_FOLDER);
|
||||
then(runtimeNodeService).shouldHaveNoMoreInteractions();
|
||||
then(nodeService).shouldHaveNoInteractions();
|
||||
assertThat(actualNode).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRuleSetNode_notPrimaryAssociation()
|
||||
{
|
||||
given(runtimeNodeService.getChildAssocs(any(), any(), any())).willReturn(List.of(createAssociation(FOLDER_NODE, RULE_SET_NODE, false)));
|
||||
|
||||
// when
|
||||
final NodeRef actualNode = ruleService.getRuleSetNode(FOLDER_NODE);
|
||||
|
||||
then(runtimeNodeService).should().getChildAssocs(FOLDER_NODE, ASSOC_RULE_FOLDER, ASSOC_RULE_FOLDER);
|
||||
then(runtimeNodeService).shouldHaveNoMoreInteractions();
|
||||
then(nodeService).shouldHaveNoInteractions();
|
||||
assertThat(actualNode).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsRuleSetAssociatedWithFolder()
|
||||
{
|
||||
given(runtimeNodeService.getParentAssocs(any(), any(), any())).willReturn(List.of(createAssociation(FOLDER_NODE, RULE_SET_NODE)));
|
||||
|
||||
// when
|
||||
boolean associated = ruleService.isRuleSetAssociatedWithFolder(RULE_SET_NODE, FOLDER_NODE);
|
||||
|
||||
then(runtimeNodeService).should().getParentAssocs(RULE_SET_NODE, ASSOC_RULE_FOLDER, ASSOC_RULE_FOLDER);
|
||||
then(runtimeNodeService).shouldHaveNoMoreInteractions();
|
||||
then(nodeService).shouldHaveNoInteractions();
|
||||
assertThat(associated).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsRuleSetAssociatedWithFolder_emptyAssociation()
|
||||
{
|
||||
given(runtimeNodeService.getParentAssocs(any(), any(), any())).willReturn(Collections.emptyList());
|
||||
|
||||
// when
|
||||
boolean associated = ruleService.isRuleSetAssociatedWithFolder(RULE_SET_NODE, FOLDER_NODE);
|
||||
|
||||
then(runtimeNodeService).should().getParentAssocs(RULE_SET_NODE, ASSOC_RULE_FOLDER, ASSOC_RULE_FOLDER);
|
||||
then(runtimeNodeService).shouldHaveNoMoreInteractions();
|
||||
then(nodeService).shouldHaveNoInteractions();
|
||||
assertThat(associated).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsRuleSetAssociatedWithFolder_improperAssociation()
|
||||
{
|
||||
final NodeRef fakeFolderNode = new NodeRef("folder://node/fake");
|
||||
given(runtimeNodeService.getParentAssocs(any(), any(), any())).willReturn(List.of(createAssociation(fakeFolderNode, RULE_SET_NODE)));
|
||||
|
||||
// when
|
||||
boolean associated = ruleService.isRuleSetAssociatedWithFolder(RULE_SET_NODE, FOLDER_NODE);
|
||||
|
||||
then(runtimeNodeService).should().getParentAssocs(RULE_SET_NODE, ASSOC_RULE_FOLDER, ASSOC_RULE_FOLDER);
|
||||
then(runtimeNodeService).shouldHaveNoMoreInteractions();
|
||||
then(nodeService).shouldHaveNoInteractions();
|
||||
assertThat(associated).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsRuleAssociatedWithRuleSet()
|
||||
{
|
||||
given(runtimeNodeService.getParentAssocs(any())).willReturn(List.of(createAssociation(RULE_SET_NODE, RULE_NODE)));
|
||||
|
||||
// when
|
||||
boolean associated = ruleService.isRuleAssociatedWithRuleSet(RULE_NODE, RULE_SET_NODE);
|
||||
|
||||
then(runtimeNodeService).should().getParentAssocs(RULE_NODE);
|
||||
then(runtimeNodeService).shouldHaveNoMoreInteractions();
|
||||
then(nodeService).shouldHaveNoInteractions();
|
||||
assertThat(associated).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsRuleAssociatedWithRuleSet_emptyAssociation()
|
||||
{
|
||||
given(runtimeNodeService.getParentAssocs(any())).willReturn(Collections.emptyList());
|
||||
|
||||
// when
|
||||
boolean associated = ruleService.isRuleAssociatedWithRuleSet(RULE_NODE, RULE_SET_NODE);
|
||||
|
||||
then(runtimeNodeService).should().getParentAssocs(RULE_NODE);
|
||||
then(runtimeNodeService).shouldHaveNoMoreInteractions();
|
||||
then(nodeService).shouldHaveNoInteractions();
|
||||
assertThat(associated).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsRuleAssociatedWithRuleSet_improperAssociation()
|
||||
{
|
||||
final NodeRef fakeRuleSetNode = new NodeRef("rule://set/node/fake");
|
||||
given(runtimeNodeService.getParentAssocs(any())).willReturn(List.of(createAssociation(fakeRuleSetNode, RULE_NODE)));
|
||||
|
||||
// when
|
||||
boolean associated = ruleService.isRuleAssociatedWithRuleSet(RULE_NODE, RULE_SET_NODE);
|
||||
|
||||
then(runtimeNodeService).should().getParentAssocs(RULE_NODE);
|
||||
then(runtimeNodeService).shouldHaveNoMoreInteractions();
|
||||
then(nodeService).shouldHaveNoInteractions();
|
||||
assertThat(associated).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsRuleSetShared()
|
||||
{
|
||||
given(runtimeNodeService.getParentAssocs(any())).willReturn(List.of(createAssociation(FOLDER_NODE, RULE_SET_NODE, false)));
|
||||
|
||||
// when
|
||||
boolean shared = ruleService.isRuleSetShared(RULE_SET_NODE);
|
||||
|
||||
then(runtimeNodeService).should().getParentAssocs(RULE_SET_NODE);
|
||||
then(runtimeNodeService).shouldHaveNoMoreInteractions();
|
||||
then(nodeService).shouldHaveNoInteractions();
|
||||
assertThat(shared).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsRuleSetShared_notShared()
|
||||
{
|
||||
given(runtimeNodeService.getParentAssocs(any())).willReturn(List.of(createAssociation(FOLDER_NODE, RULE_SET_NODE)));
|
||||
|
||||
// when
|
||||
boolean shared = ruleService.isRuleSetShared(RULE_SET_NODE);
|
||||
|
||||
then(runtimeNodeService).should().getParentAssocs(RULE_SET_NODE);
|
||||
then(runtimeNodeService).shouldHaveNoMoreInteractions();
|
||||
then(nodeService).shouldHaveNoInteractions();
|
||||
assertThat(shared).isFalse();
|
||||
}
|
||||
|
||||
private static ChildAssociationRef createAssociation(final NodeRef parentRef, final NodeRef childRef)
|
||||
{
|
||||
return createAssociation(parentRef, childRef, true);
|
||||
}
|
||||
|
||||
private static ChildAssociationRef createAssociation(final NodeRef parentRef, final NodeRef childRef, final boolean isPrimary)
|
||||
{
|
||||
return new ChildAssociationRef(null, parentRef, null, childRef, isPrimary, 1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user