diff --git a/.travis.yml b/.travis.yml index cae37e3e37..8063f1d9df 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,10 +14,6 @@ cache: env: global: - VERSION_EDITION=Community - - DOCKER_IMAGE_TAG=latest - - DOCKER_IMAGE_REGISTRY=quay.io - - DOCKER_COMPOSE_VERSION=1.23.2 - - ALFRESCO_IMAGE_NAME=alfresco/alfresco-content-repository-community branches: only: @@ -29,13 +25,49 @@ matrix: # only on master and if it is not a PR if: fork = false AND branch = master AND type != pull_request install: - - travis_retry travis_wait 30 mvn -q install -Dbuild-number=${TRAVIS_BUILD_NUMBER} "-Dbuild-key=${TRAVIS_COMMIT}" "-Dbuild-name=${TRAVIS_BUILD_WEB_URL}" "-Dscm-path=${TRAVIS_REPO_SLUG}" "-Dversion.edition=${VERSION_EDITION}" -f war/pom.xml + - travis_retry travis_wait 30 mvn -q install "-Dversion.edition=${VERSION_EDITION}" -f war/pom.xml script: # Download the latest version of WhiteSource Unified Agent - curl -LJO https://github.com/whitesource/unified-agent-distribution/raw/master/standAlone/wss-unified-agent.jar # Run WhiteSource Unified Agent - java -jar wss-unified-agent.jar -apiKey ${WHITESOURCE_API_KEY} -c .wss-unified-agent.config -d ./war - - name: "Build packaging" - install: skip + - name: "REST API TAS tests" + jdk: openjdk11 + install: + - travis_retry travis_wait 40 mvn install -q "-Dversion.edition=${VERSION_EDITION}" -Dmaven.javadoc.skip=true -PcommunityDocker + - ./tests/scripts/start-compose.sh ./tests/environment/docker-compose-minimal+transforms.yml + - ./tests/scripts/wait-for-alfresco-start.sh "http://localhost:8082/alfresco" script: - - travis_retry travis_wait 40 mvn install -q -Dbuild-number=${TRAVIS_BUILD_NUMBER} -Dbuild-key=${TRAVIS_COMMIT} -Dbuild-name="${TRAVIS_BUILD_WEB_URL}" -Dscm-path=${TRAVIS_REPO_SLUG} "-Dversion.edition=${VERSION_EDITION}" "-Dimage.tag=${DOCKER_IMAGE_TAG}" -Dimage.registry=${DOCKER_IMAGE_REGISTRY} -Dimage.name=${ALFRESCO_IMAGE_NAME} -Dmaven.javadoc.skip=true -PcommunityDocker + - travis_wait 60 mvn install -q -f tests/tas-restapi/pom.xml -Pall-tas-tests -Denvironment=default -DrunBugs=false + - name: "CMIS TAS tests" + jdk: openjdk11 + install: + - travis_retry travis_wait 40 mvn install -q "-Dversion.edition=${VERSION_EDITION}" -Dmaven.javadoc.skip=true -PcommunityDocker + - ./tests/scripts/start-compose.sh ./tests/environment/docker-compose-minimal+transforms.yml + - ./tests/scripts/wait-for-alfresco-start.sh "http://localhost:8082/alfresco" + script: + - travis_wait 40 mvn install -q -f tests/tas-cmis/pom.xml -Pall-tas-tests -Denvironment=default -DrunBugs=false + - name: "Email TAS tests" + jdk: openjdk11 + install: + - travis_retry travis_wait 40 mvn install -q "-Dversion.edition=${VERSION_EDITION}" -Dmaven.javadoc.skip=true -PcommunityDocker + - ./tests/scripts/start-compose.sh ./tests/environment/docker-compose-minimal.yml + - ./tests/scripts/wait-for-alfresco-start.sh "http://localhost:8082/alfresco" + script: + - travis_wait 30 mvn install -q -f tests/tas-email/pom.xml -Pall-tas-tests -Denvironment=default -DrunBugs=false + - name: "WebDAV TAS tests" + jdk: openjdk11 + install: + - travis_retry travis_wait 40 mvn install -q "-Dversion.edition=${VERSION_EDITION}" -Dmaven.javadoc.skip=true -PcommunityDocker + - ./tests/scripts/start-compose.sh ./tests/environment/docker-compose-minimal.yml + - ./tests/scripts/wait-for-alfresco-start.sh "http://localhost:8082/alfresco" + script: + - travis_wait 30 mvn install -q -f tests/tas-webdav/pom.xml -Pall-tas-tests -Denvironment=default -DrunBugs=false + - name: "Integration TAS tests" + jdk: openjdk11 + install: + - travis_retry travis_wait 40 mvn install -q "-Dversion.edition=${VERSION_EDITION}" -Dmaven.javadoc.skip=true -PcommunityDocker + - ./tests/scripts/start-compose.sh ./tests/environment/docker-compose-minimal.yml + - ./tests/scripts/wait-for-alfresco-start.sh "http://localhost:8082/alfresco" + script: + - travis_wait 30 mvn install -q -f tests/tas-integration/pom.xml -Pall-tas-tests -Denvironment=default -DrunBugs=false diff --git a/docker-alfresco/test/docker-compose.yml b/docker-alfresco/test/docker-compose.yml index baaa309091..af6dc3e519 100644 --- a/docker-alfresco/test/docker-compose.yml +++ b/docker-alfresco/test/docker-compose.yml @@ -54,8 +54,8 @@ services: - 8082:8080 - 8000:8000 - 143:1143 - - "21:1221" - - "30000-30099:30000-30099" + - 21:1221 + - 30000-30099:30000-30099 alfresco-pdf-renderer: image: alfresco/alfresco-pdf-renderer:${TRANSFORMERS_TAG} @@ -106,8 +106,6 @@ services: - POSTGRES_PASSWORD=alfresco - POSTGRES_USER=alfresco - POSTGRES_DB=alfresco - ports: - - 5432:5432 solr6: image: alfresco/alfresco-search-services:${SOLR6_TAG} diff --git a/pom.xml b/pom.xml index c727b4cb1d..d737ad6215 100644 --- a/pom.xml +++ b/pom.xml @@ -37,6 +37,12 @@ docker-alfresco + + all-tas-tests + + tests + + @@ -101,6 +107,15 @@ 42.2.6 + 3.0.14 + 3.3.0 + 1.0.4 + 1.15 + 1.5 + 1.1 + 1.0 + 1.0 + 2.2 diff --git a/tests/environment/.env b/tests/environment/.env new file mode 100644 index 0000000000..ef18cd66ba --- /dev/null +++ b/tests/environment/.env @@ -0,0 +1,4 @@ +TRANSFORMERS_TAG=2.1.0 +SOLR6_TAG=1.4.0 +POSTGRES_TAG=11.4 +ACTIVEMQ_TAG=5.15.8 diff --git a/tests/environment/docker-compose-minimal+transforms.yml b/tests/environment/docker-compose-minimal+transforms.yml new file mode 100644 index 0000000000..2de93ab468 --- /dev/null +++ b/tests/environment/docker-compose-minimal+transforms.yml @@ -0,0 +1,143 @@ +version: "3" + +# The acs-community-deployment project contains the product version of docker-compose. +# +# This version is for testing and development use. For testing and debug we need to have a more open version. +# For remote debug we need the CATALINA_OPTS and to expose port 8000. + +services: + alfresco: + image: alfresco/alfresco-content-repository-community:latest + environment: + CATALINA_OPTS : "-agentlib:jdwp=transport=dt_socket,address=*:8000,server=y,suspend=n" + JAVA_OPTS : + " + -Ddb.driver=org.postgresql.Driver + -Ddb.username=alfresco + -Ddb.password=alfresco + -Ddb.url=jdbc:postgresql://postgres:5432/alfresco + -Dsolr.host=solr6 + -Dsolr.port=8983 + -Dsolr.secureComms=none + -Dsolr.base.url=/solr + -Dindex.subsystem.name=solr6 + -Dalfresco.restApi.basicAuthScheme=true + -Dimap.server.enabled=true + -Dftp.enabled=true + -Dftp.dataPortFrom=30000 + -Dftp.dataPortTo=30099 + -Dshare.host=localhost + -Daos.baseUrlOverwrite=http://localhost:8082/alfresco/aos + -Dmessaging.broker.url=\"failover:(tcp://activemq:61616)?timeout=3000&jms.useCompression=true\" + + -Dlocal.transform.service.enabled=true + -DlocalTransform.pdfrenderer.url=http://alfresco-pdf-renderer:8090/ + -DlocalTransform.imagemagick.url=http://imagemagick:8090/ + -DlocalTransform.libreoffice.url=http://libreoffice:8090/ + -DlocalTransform.tika.url=http://tika:8090/ + -DlocalTransform.misc.url=http://transform-misc:8090/ + + -Dlegacy.transform.service.enabled=true + -Dalfresco-pdf-renderer.url=http://alfresco-pdf-renderer:8090/ + -Djodconverter.url=http://libreoffice:8090/ + -Dimg.url=http://imagemagick:8090/ + -Dtika.url=http://tika:8090/ + -Dtransform.misc.url=http://transform-misc:8090/ + + -Dimap.server.port=1143 + -Dftp.port=1221 + -Dcors.enabled=true + -Dcors.allowed.origins=http://localhost:4200 + " + ports: + - 8082:8080 + - 8000:8000 + - 143:1143 + - 21:1221 + - 30000-30099:30000-30099 + + postgres: + image: library/postgres:${POSTGRES_TAG} + environment: + - POSTGRES_PASSWORD=alfresco + - POSTGRES_USER=alfresco + - POSTGRES_DB=alfresco + + solr6: + image: alfresco/alfresco-search-services:${SOLR6_TAG} + environment: + #Solr needs to know how to register itself with Alfresco + - SOLR_ALFRESCO_HOST=alfresco + - SOLR_ALFRESCO_PORT=8080 + #Alfresco needs to know how to call solr + - SOLR_SOLR_HOST=solr6 + - SOLR_SOLR_PORT=8983 + #Create the default alfresco and archive cores + - SOLR_CREATE_ALFRESCO_DEFAULTS=alfresco,archive + #HTTP by default + - ALFRESCO_SECURE_COMMS=none + ports: + - 8083:8983 #Browser port + + activemq: + image: alfresco/alfresco-activemq:${ACTIVEMQ_TAG} + ports: + - 8161:8161 # Web Console + - 5672:5672 # AMQP + - 61616:61616 # OpenWire + - 61613:61613 # STOMP + + alfresco-pdf-renderer: + image: alfresco/alfresco-pdf-renderer:${TRANSFORMERS_TAG} + environment: + JAVA_OPTS: " -Xms256m -Xmx256m" + ACTIVEMQ_URL: "nio://activemq:61616" + ACTIVEMQ_USER: "admin" + ACTIVEMQ_PASSWORD: "admin" + FILE_STORE_URL: "http://shared-file-store:8099/alfresco/api/-default-/private/sfs/versions/1/file" + ports: + - 8090:8090 + + imagemagick: + image: alfresco/alfresco-imagemagick:${TRANSFORMERS_TAG} + environment: + JAVA_OPTS: " -Xms256m -Xmx256m" + ACTIVEMQ_URL: "nio://activemq:61616" + ACTIVEMQ_USER: "admin" + ACTIVEMQ_PASSWORD: "admin" + FILE_STORE_URL: "http://shared-file-store:8099/alfresco/api/-default-/private/sfs/versions/1/file" + ports: + - 8091:8090 + + libreoffice: + image: alfresco/alfresco-libreoffice:${TRANSFORMERS_TAG} + environment: + JAVA_OPTS: " -Xms256m -Xmx256m" + ACTIVEMQ_URL: "nio://activemq:61616" + ACTIVEMQ_USER: "admin" + ACTIVEMQ_PASSWORD: "admin" + FILE_STORE_URL: "http://shared-file-store:8099/alfresco/api/-default-/private/sfs/versions/1/file" + ports: + - 8092:8090 + + tika: + image: alfresco/alfresco-tika:${TRANSFORMERS_TAG} + environment: + JAVA_OPTS: " -Xms256m -Xmx256m" + ACTIVEMQ_URL: "nio://activemq:61616" + FILE_STORE_URL: "http://shared-file-store:8099/alfresco/api/-default-/private/sfs/versions/1/file" + ACTIVEMQ_USER: "admin" + ACTIVEMQ_PASSWORD: "admin" + ports: + - 8093:8090 + + transform-misc: + image: alfresco/alfresco-transform-misc:${TRANSFORMERS_TAG} + environment: + JAVA_OPTS: " -Xms256m -Xmx256m" + ACTIVEMQ_URL: "nio://activemq:61616" + ACTIVEMQ_USER: "admin" + ACTIVEMQ_PASSWORD: "admin" + FILE_STORE_URL: "http://shared-file-store:8099/alfresco/api/-default-/private/sfs/versions/1/file" + ports: + - 8094:8090 diff --git a/tests/environment/docker-compose-minimal.yml b/tests/environment/docker-compose-minimal.yml new file mode 100644 index 0000000000..453db3ae8b --- /dev/null +++ b/tests/environment/docker-compose-minimal.yml @@ -0,0 +1,77 @@ +version: "3" + +# The acs-community-deployment project contains the product version of docker-compose. +# +# This version is for testing and development use. For testing and debug we need to have a more open version. +# For remote debug we need the CATALINA_OPTS and to expose port 8000. + +services: + alfresco: + image: alfresco/alfresco-content-repository-community:latest + environment: + CATALINA_OPTS : "-agentlib:jdwp=transport=dt_socket,address=*:8000,server=y,suspend=n" + JAVA_OPTS : + " + -Ddb.driver=org.postgresql.Driver + -Ddb.username=alfresco + -Ddb.password=alfresco + -Ddb.url=jdbc:postgresql://postgres:5432/alfresco + -Dsolr.host=solr6 + -Dsolr.port=8983 + -Dsolr.secureComms=none + -Dsolr.base.url=/solr + -Dindex.subsystem.name=solr6 + -Dalfresco.restApi.basicAuthScheme=true + -Dimap.server.enabled=true + -Dftp.enabled=true + -Dftp.dataPortFrom=30000 + -Dftp.dataPortTo=30099 + -Dshare.host=localhost + -Daos.baseUrlOverwrite=http://localhost:8082/alfresco/aos + -Dmessaging.broker.url=\"failover:(tcp://activemq:61616)?timeout=3000&jms.useCompression=true\" + + -Dlocal.transform.service.enabled=false + -Dlegacy.transform.service.enabled=false + + -Dimap.server.port=1143 + -Dftp.port=1221 + -Dcors.enabled=true + -Dcors.allowed.origins=http://localhost:4200 + " + ports: + - 8082:8080 + - 8000:8000 + - 143:1143 + - 21:1221 + - 30000-30099:30000-30099 + + postgres: + image: library/postgres:${POSTGRES_TAG} + environment: + - POSTGRES_PASSWORD=alfresco + - POSTGRES_USER=alfresco + - POSTGRES_DB=alfresco + + solr6: + image: alfresco/alfresco-search-services:${SOLR6_TAG} + environment: + #Solr needs to know how to register itself with Alfresco + - SOLR_ALFRESCO_HOST=alfresco + - SOLR_ALFRESCO_PORT=8080 + #Alfresco needs to know how to call solr + - SOLR_SOLR_HOST=solr6 + - SOLR_SOLR_PORT=8983 + #Create the default alfresco and archive cores + - SOLR_CREATE_ALFRESCO_DEFAULTS=alfresco,archive + #HTTP by default + - ALFRESCO_SECURE_COMMS=none + ports: + - 8083:8983 #Browser port + + activemq: + image: alfresco/alfresco-activemq:${ACTIVEMQ_TAG} + ports: + - 8161:8161 # Web Console + - 5672:5672 # AMQP + - 61616:61616 # OpenWire + - 61613:61613 # STOMP \ No newline at end of file diff --git a/tests/pom.xml b/tests/pom.xml new file mode 100644 index 0000000000..80692a107b --- /dev/null +++ b/tests/pom.xml @@ -0,0 +1,86 @@ + + 4.0.0 + content-repository-community-tas-tests-parent + 6.3.0-SNAPSHOT + pom + + + org.alfresco + acs-community-packaging + 6.3.0-SNAPSHOT + ../pom.xml + + + + tas-restapi + tas-cmis + tas-email + tas-webdav + tas-integration + + + + + + org.alfresco.tas + utility + ${dependency.tas-utility.version} + test + + + io.rest-assured + rest-assured + ${dependency.rest-assured.version} + test + + + org.glassfish + javax.json + ${dependency.javax.json.version} + test + + + org.alfresco.tas + restapi + ${dependency.tas-restapi.version} + test + + + org.alfresco.tas + cmis + ${dependency.tas-cmis.version} + test + + + org.alfresco.tas + email + ${dependency.tas-email.version} + test + + + org.alfresco.tas + webdav + ${dependency.tas-webdav.version} + test + + + org.alfresco.tas + ftp + ${dependency.tas-ftp.version} + test + + + org.alfresco.test + dataprep + ${dependency.tas-dataprep.version} + test + + + org.springframework + spring-test + ${dependency.spring.version} + test + + + + \ No newline at end of file diff --git a/tests/scripts/start-compose.sh b/tests/scripts/start-compose.sh new file mode 100755 index 0000000000..ace065bb0c --- /dev/null +++ b/tests/scripts/start-compose.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +export DOCKER_COMPOSE_PATH=$1 + +if [ -z "$DOCKER_COMPOSE_PATH" ] +then + echo "Please provide path to docker-compose.yml: \"${0##*/} /path/to/docker-compose.yml\"" + exit 1 +fi + +echo "Starting ACS stack in ${DOCKER_COMPOSE_PATH}" + +# .env files are picked up from project directory correctly on docker-compose 1.23.0+ +docker-compose --file "${DOCKER_COMPOSE_PATH}" --project-directory $(dirname "${DOCKER_COMPOSE_PATH}") up -d + +if [ $? -eq 0 ] +then + echo "Docker Compose started ok" +else + echo "Docker Compose failed to start" >&2 + exit 1 +fi \ No newline at end of file diff --git a/tests/scripts/stop-compose.sh b/tests/scripts/stop-compose.sh new file mode 100755 index 0000000000..6fe5738624 --- /dev/null +++ b/tests/scripts/stop-compose.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +export DOCKER_COMPOSE_PATH=$1 + +if [ -z "$DOCKER_COMPOSE_PATH" ] +then + echo "Please provide path to docker-compose.yml: \"${0##*/} /path/to/docker-compose.yml\"" + exit 1 +fi + +echo "Killing ACS stack in ${DOCKER_COMPOSE_PATH}" + +cd ${DOCKER_COMPOSE_PATH} + +docker-compose ps +# logs for debug +docker-compose logs --no-color -t alfresco +docker-compose kill +docker-compose rm -fv \ No newline at end of file diff --git a/tests/scripts/wait-for-alfresco-start.sh b/tests/scripts/wait-for-alfresco-start.sh new file mode 100755 index 0000000000..df48191306 --- /dev/null +++ b/tests/scripts/wait-for-alfresco-start.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +export ALFRESCO_URL=$1 + +if [ -z "$ALFRESCO_URL" ] +then + echo "Please provide the Alfresco URL to check, for example: \"${0##*/} http://localhost:8080/alfresco\"" + exit 1 +fi + +WAIT_INTERVAL=1 +COUNTER=0 +TIMEOUT=300 +t0=$(date +%s) + +echo "Waiting for alfresco to start" +until $(curl --output /dev/null --silent --head --fail ${ALFRESCO_URL}) || [ "$COUNTER" -eq "$TIMEOUT" ]; do + printf '.' + sleep $WAIT_INTERVAL + COUNTER=$(($COUNTER+$WAIT_INTERVAL)) +done + +if (("$COUNTER" < "$TIMEOUT")) ; then + t1=$(date +%s) + delta=$((($t1 - $t0)/60)) + echo "Alfresco Started in $delta minutes" +else + echo "Waited $COUNTER seconds" + echo "Alfresco Could not start in time." + exit 1 +fi \ No newline at end of file diff --git a/tests/tas-cmis/pom.xml b/tests/tas-cmis/pom.xml new file mode 100644 index 0000000000..6b5f6175a6 --- /dev/null +++ b/tests/tas-cmis/pom.xml @@ -0,0 +1,66 @@ + + + 4.0.0 + org.alfresco.tas + content-repository-community-cmis-test + content-repository-community-cmis-test + 6.3.0-SNAPSHOT + jar + + + org.alfresco + content-repository-community-tas-tests-parent + 6.3.0-SNAPSHOT + ../pom.xml + + + + + Paul Brodner + + Test Automation Architect + + + + + + ${project.basedir}/src/test/resources/cmis-suite.xml + + + + + org.alfresco.tas + cmis + test + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + ${suiteXmlFile} + + + --illegal-access=warn + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + test-jar + + + + + + + diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/AclTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/AclTests.java new file mode 100644 index 0000000000..ed372303ca --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/AclTests.java @@ -0,0 +1,645 @@ +package org.alfresco.cmis; + +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +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.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.data.PermissionMapping; +import org.apache.chemistry.opencmis.commons.enums.AclPropagation; +import org.apache.chemistry.opencmis.commons.enums.VersioningState; +import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.apache.chemistry.opencmis.commons.impl.jaxb.EnumBasicPermissions; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class AclTests extends CmisTest +{ + UserModel testUser, inviteUser, unauthorizedUser; + SiteModel testSite, privateSite; + FileModel testFile; + FolderModel testFolder; + private DataUser.ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + testUser = dataUser.createRandomTestUser(); + inviteUser = dataUser.createRandomTestUser(); + unauthorizedUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(testUser).createPublicRandomSite(); + privateSite = dataSite.usingUser(testUser).createPrivateRandomSite(); + usersWithRoles = dataUser.usingUser(testUser) + .addUsersWithRolesToSite(testSite, UserRole.SiteContributor, UserRole.SiteCollaborator, UserRole.SiteConsumer); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Site manager can get the acls for valid document") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS }) + public void siteManagerShouldGetDocumentAcls() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo() + .and().assertThat().hasAcls(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Site manager can get the acls for valid folder") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void siteManagerShouldGetFolderAcls() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(testFolder).and().assertThat().existsInRepo() + .and().assertThat().hasAcls(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Add Acl for valid document with AclPropagation set to REPOSITORYDETERMINED") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanAddAclWithRepositoryDeterminedPropagation() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo(); + cmisApi.usingResource(testFile).addAcl(inviteUser, UserRole.SiteContributor, AclPropagation.REPOSITORYDETERMINED) + .then().assertThat().permissionIsSetForUser(inviteUser, UserRole.SiteContributor); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Add Acl for valid folder with AclPropagation set to PROPAGATE") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanAddAclWithPropagate() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(testFolder).and().assertThat().existsInRepo(); + cmisApi.usingResource(testFolder).addAcl(inviteUser, UserRole.SiteConsumer, AclPropagation.PROPAGATE) + .then().assertThat().permissionIsSetForUser(inviteUser, UserRole.SiteConsumer); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Add Acl for valid folder with AclPropagation set to OBJECTONLY") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanAddAclWithObjectOnlyPropagation() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(testFolder).and().assertThat().existsInRepo(); + cmisApi.usingResource(testFolder).addAcl(inviteUser, UserRole.SiteCollaborator, AclPropagation.OBJECTONLY) + .then().assertThat().permissionIsSetForUser(inviteUser, UserRole.SiteCollaborator); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Apply Acl for valid folder with AclPropagation set to OBJECTONLY") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanApplyAclWithObjectOnlyPropagation() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(testFolder).and().assertThat().existsInRepo(); + cmisApi.usingResource(testFolder).addAcl(inviteUser, UserRole.SiteCollaborator, AclPropagation.OBJECTONLY) + .then().applyAcl(inviteUser, UserRole.SiteConsumer, UserRole.SiteCollaborator, AclPropagation.OBJECTONLY) + .and().assertThat().permissionIsSetForUser(inviteUser, UserRole.SiteConsumer) + .and().assertThat().permissionIsNotSetForUser(inviteUser, UserRole.SiteCollaborator); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify appply acl with invalid role that will be removed") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisConstraintException.class) + public void applyAclWithInvalidAddedRole() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo() + .then().addAcl(inviteUser, UserRole.SiteCollaborator, AclPropagation.OBJECTONLY) + .then().applyAcl(inviteUser, UserRole.SiteConsumer, UserRole.SiteManager, AclPropagation.OBJECTONLY); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Apply Acl for valid folder with AclPropagation set to PROPAGATE") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void siteManagerCanApplyAclWithPropagate() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.PDF); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile) + .and().addAcl(inviteUser, UserRole.SiteConsumer, AclPropagation.PROPAGATE) + .when().applyAcl(inviteUser, UserRole.SiteManager, UserRole.SiteConsumer, AclPropagation.PROPAGATE) + .assertThat().permissionIsSetForUser(inviteUser, UserRole.SiteManager) + .and().assertThat().permissionIsNotSetForUser(inviteUser, UserRole.SiteConsumer); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Apply Acl for valid folder with AclPropagation set to REPOSITORYDETERMINED") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanApplyAclWithRepositoryDeterminedPropagation() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.PDF); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile) + .and().addAcl(inviteUser, UserRole.SiteConsumer, AclPropagation.OBJECTONLY) + .when().applyAcl(inviteUser, UserRole.SiteManager, UserRole.SiteConsumer, AclPropagation.REPOSITORYDETERMINED) + .assertThat().permissionIsSetForUser(inviteUser, UserRole.SiteManager) + .and().assertThat().permissionIsNotSetForUser(inviteUser, UserRole.SiteConsumer); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Remove Acl for valid folder with AclPropagation set to REPOSITORYDETERMINED") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanRemoveAclWithRepositoryDeterminedPropagation() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.PDF); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile) + .and().addAcl(inviteUser, UserRole.SiteConsumer, AclPropagation.OBJECTONLY) + .when().removeAcl(inviteUser, UserRole.SiteConsumer, AclPropagation.REPOSITORYDETERMINED) + .and().assertThat().permissionIsNotSetForUser(inviteUser, UserRole.SiteConsumer); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Remove Acl for valid folder with AclPropagation set to REPOSITORYDETERMINED") + @Test(groups = {TestGroup.SANITY, TestGroup.CMIS}) + public void siteManagerCanRemoveAclWithPropagate() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.PDF); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile) + .and().addAcl(inviteUser, UserRole.SiteManager, AclPropagation.OBJECTONLY) + .when().removeAcl(inviteUser, UserRole.SiteManager, AclPropagation.PROPAGATE) + .and().assertThat().permissionIsNotSetForUser(inviteUser, UserRole.SiteManager); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Remove Acl for valid folder with AclPropagation set to REPOSITORYDETERMINED") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanRemoveAclWithObjectOnlyPropagation() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.PDF); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile) + .and().addAcl(inviteUser, UserRole.SiteContributor, AclPropagation.OBJECTONLY) + .when().removeAcl(inviteUser, UserRole.SiteContributor, AclPropagation.OBJECTONLY) + .and().assertThat().permissionIsNotSetForUser(inviteUser, UserRole.SiteContributor); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Remove Acl for valid folder with AclPropagation set to REPOSITORYDETERMINED") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisConstraintException.class) + public void siteManagerCannotRemoveInvalidAcl() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.PDF); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile) + .and().addAcl(inviteUser, UserRole.SiteContributor, AclPropagation.OBJECTONLY) + .when().removeAcl(inviteUser, UserRole.SiteManager, AclPropagation.OBJECTONLY); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Site manager can add acl with null AclPropagation") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanAddAclWithNullPropagation() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.PDF, "content"); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile) + .and().addAcl(inviteUser, UserRole.SiteContributor, null) + .then().assertThat().permissionIsSetForUser(inviteUser, UserRole.SiteContributor); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Site manager cannot get acl for pwc document") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisRuntimeException.class) + public void siteManagerCannotGetAclForPwcDocument() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.PDF, "content"); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile, VersioningState.CHECKEDOUT) + .usingPWCDocument().addAcl(inviteUser, UserRole.SiteContributor, AclPropagation.PROPAGATE) + .then().assertThat().permissionIsSetForUser(inviteUser, UserRole.SiteContributor); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Site manager cannot get acl for invalid object") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisObjectNotFoundException.class) + public void siteManagerCannotGetAclForInvalidObject() throws Exception + { + FolderModel folder = FolderModel.getRandomFolderModel(); + folder.setCmisLocation("/" + folder.getName() + "/"); + cmisApi.authenticateUser(testUser) + .usingResource(folder) + .assertThat().permissionIsSetForUser(inviteUser, UserRole.SiteContributor); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Apply Acl for valid document with null AclPropagation") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanApplyAclWithNullPropagation() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.PDF); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile) + .and().addAcl(inviteUser, UserRole.SiteConsumer, AclPropagation.OBJECTONLY) + .when().applyAcl(inviteUser, UserRole.SiteManager, UserRole.SiteConsumer, null) + .assertThat().permissionIsSetForUser(inviteUser, UserRole.SiteManager) + .and().assertThat().permissionIsNotSetForUser(inviteUser, UserRole.SiteConsumer); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Apply Acl for checked out document") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisRuntimeException.class) + public void siteManagerCannotGetAclForAppliedAclForPWC() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSEXCEL); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile) + .and().addAcl(inviteUser, UserRole.SiteConsumer, AclPropagation.OBJECTONLY) + .then().checkOut().assertThat().documentIsCheckedOut() + .usingPWCDocument().applyAcl(inviteUser, UserRole.SiteManager, UserRole.SiteConsumer) + .assertThat().permissionIsSetForUser(inviteUser, UserRole.SiteManager); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Remove Acl from valid folder with null AclPropagation") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanRemoveAclWithNullPropagation() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.PDF); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile) + .and().addAcl(inviteUser, UserRole.SiteContributor, AclPropagation.OBJECTONLY) + .when().removeAcl(inviteUser, UserRole.SiteContributor) + .and().assertThat().permissionIsNotSetForUser(inviteUser, UserRole.SiteContributor); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Unauthorized user cannot remove acl") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void removeAclByUnauthorizedUser() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSEXCEL); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile) + .and().addAcl(inviteUser, UserRole.SiteConsumer, AclPropagation.OBJECTONLY) + .assertThat().permissionIsSetForUser(inviteUser, UserRole.SiteConsumer) + .when().authenticateUser(unauthorizedUser) + .removeAcl(inviteUser, UserRole.SiteConsumer); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Unauthorized user cannot add acl") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void addAclByUnauthorizedUser() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSEXCEL); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile) + .then().authenticateUser(unauthorizedUser) + .and().addAcl(inviteUser, UserRole.SiteConsumer, AclPropagation.OBJECTONLY); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Unauthorized user cannot apply acl") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void applyAclByUnauthorizedUser() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSEXCEL); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile) + .and().addAcl(inviteUser, UserRole.SiteConsumer) + .when().authenticateUser(unauthorizedUser) + .and().applyAcl(inviteUser, UserRole.SiteManager, UserRole.SiteConsumer); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Add Acl for checked out document") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanAddAclForCheckedOutDocument() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile, VersioningState.CHECKEDOUT).and().assertThat().existsInRepo() + .and().assertThat().documentIsCheckedOut() + .then().usingResource(testFile) + .addAcl(inviteUser, UserRole.SiteContributor) + .and().assertThat().permissionIsSetForUser(inviteUser, UserRole.SiteContributor); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Add Acl by user with collaborator role for document created by himself") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void collaboratorCanAddAclForDocumentCreatedByHimself() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo() + .addAcl(inviteUser, UserRole.SiteContributor) + .and().assertThat().permissionIsSetForUser(inviteUser, UserRole.SiteContributor); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Add Acl by user with collaborator role for document created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void collaboratorCannotAddAclForDocumentCreatedByManager() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .addAcl(inviteUser, UserRole.SiteContributor); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Get Acl by user with collaborator role for document created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void collaboratorCanGetAclForDocumentCreatedByManager() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo() + .addAcl(inviteUser, UserRole.SiteContributor) + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .usingResource(testFile).refreshResource() + .and().assertThat().permissionIsSetForUser(inviteUser, UserRole.SiteContributor); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Apply Acl by user with collaborator role for document created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void collaboratorCannotApplyAclForDocumentCreatedByManager() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo() + .addAcl(inviteUser, UserRole.SiteContributor) + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .applyAcl(inviteUser, UserRole.SiteCollaborator, UserRole.SiteContributor); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Apply Acl by user with collaborator role for document created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void collaboratorCannotRemoveAclForDocumentCreatedByManager() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo() + .addAcl(inviteUser, UserRole.SiteContributor) + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .removeAcl(inviteUser, UserRole.SiteContributor); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Add Acl by user with contributor role for document created by himself") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void contributorCanAddAclForDocumentCreatedByHimself() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo() + .addAcl(inviteUser, UserRole.SiteContributor) + .and().assertThat().permissionIsSetForUser(inviteUser, UserRole.SiteContributor); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Add Acl by user with contributor role for document created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void contributorCannotAddAclForDocumentCreatedByManager() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .addAcl(inviteUser, UserRole.SiteCollaborator); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Get Acl by user with collaborator role for document created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void contributorCanGetAclForDocumentCreatedByManager() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo() + .addAcl(inviteUser, UserRole.SiteContributor) + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .usingResource(testFile).refreshResource() + .and().assertThat().permissionIsSetForUser(inviteUser, UserRole.SiteContributor); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Apply Acl by user with contributor role for document created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void contributorCannotApplyAclForDocumentCreatedByManager() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo() + .addAcl(inviteUser, UserRole.SiteContributor) + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .applyAcl(inviteUser, UserRole.SiteCollaborator, UserRole.SiteContributor); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Apply Acl by user with contributor role for document created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void contributorCannotRemoveAclForDocumentCreatedByManager() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo() + .addAcl(inviteUser, UserRole.SiteContributor) + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .removeAcl(inviteUser, UserRole.SiteContributor); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Add Acl by user with consumer role for document created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void consumerCannotAddAclForDocumentCreatedByManager() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .addAcl(inviteUser, UserRole.SiteCollaborator); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Get Acl by user with consumer role for document created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void consumerCanGetAclForDocumentCreatedByManager() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo() + .addAcl(inviteUser, UserRole.SiteContributor) + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .usingResource(testFile).refreshResource() + .and().assertThat().permissionIsSetForUser(inviteUser, UserRole.SiteContributor); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Apply Acl by user with consumer role for document created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void consumerCannotApplyAclForDocumentCreatedByManager() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo() + .addAcl(inviteUser, UserRole.SiteContributor) + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .applyAcl(inviteUser, UserRole.SiteCollaborator, UserRole.SiteContributor); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Apply Acl by user with consumer role for document created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void consumerCannotRemoveAclForDocumentCreatedByManager() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo() + .addAcl(inviteUser, UserRole.SiteContributor) + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .removeAcl(inviteUser, UserRole.SiteContributor); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Add Acl by non invited user in private site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void nonInvitedUserCannotAddAclInPrivateSite() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(privateSite) + .createFile(testFile).and().assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .addAcl(inviteUser, UserRole.SiteCollaborator); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Get Acl by non invited user in private site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void nonInvitedUserCannotGetAclInPrivateSite() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(privateSite) + .createFile(testFile).and().assertThat().existsInRepo() + .addAcl(inviteUser, UserRole.SiteContributor) + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .usingResource(testFile).refreshResource() + .and().assertThat().permissionIsSetForUser(inviteUser, UserRole.SiteContributor); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Apply Acl by non invited user in private site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void nonInvitedUserCannotApplyAclInPrivateSite() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(privateSite) + .createFile(testFile).and().assertThat().existsInRepo() + .addAcl(inviteUser, UserRole.SiteContributor) + .applyAcl(inviteUser, UserRole.SiteCollaborator, UserRole.SiteContributor) + .and().assertThat().permissionIsSetForUser(inviteUser, UserRole.SiteCollaborator) + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .applyAcl(inviteUser, UserRole.SiteContributor, UserRole.SiteCollaborator); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Remove Acl by non invited user in private site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void nonInvitedUserCannotRemoveAclFromPrivateSite() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(privateSite) + .createFile(testFile).and().assertThat().existsInRepo() + .addAcl(inviteUser, UserRole.SiteContributor) + .and().assertThat().permissionIsSetForUser(inviteUser, UserRole.SiteContributor) + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .removeAcl(inviteUser, UserRole.SiteContributor); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Add Acl for valid document with PermissionMapping") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanAddAclWithPermissionMapping() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo() + .then().addAcl(inviteUser, PermissionMapping.CAN_UPDATE_PROPERTIES_OBJECT) + .assertThat().permissionIsSetForUser(inviteUser, EnumBasicPermissions.CMIS_WRITE.value()) + .then().addAcl(inviteUser, PermissionMapping.CAN_DELETE_OBJECT) + .and().assertThat().permissionIsSetForUser(inviteUser, EnumBasicPermissions.CMIS_ALL.value()); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Apply Acl for valid document with PermissionMapping") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanApplyAclWithPermissionMapping() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo() + .then().addAcl(inviteUser, PermissionMapping.CAN_DELETE_OBJECT) + .and().assertThat().permissionIsSetForUser(inviteUser, EnumBasicPermissions.CMIS_ALL.value()) + .then().applyAcl(inviteUser, PermissionMapping.CAN_UPDATE_PROPERTIES_OBJECT, PermissionMapping.CAN_DELETE_OBJECT) + .and().assertThat().permissionIsSetForUser(inviteUser, EnumBasicPermissions.CMIS_WRITE.value()) + .and().assertThat().permissionIsNotSetForUser(inviteUser, EnumBasicPermissions.CMIS_ALL.value()); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Remove Acl for valid document with PermissionMapping") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanRemoveAclWithPermissionMapping() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo() + .then().addAcl(inviteUser, PermissionMapping.CAN_UPDATE_PROPERTIES_OBJECT) + .assertThat().permissionIsSetForUser(inviteUser, EnumBasicPermissions.CMIS_WRITE.value()) + .then().addAcl(inviteUser, PermissionMapping.CAN_DELETE_OBJECT) + .and().assertThat().permissionIsSetForUser(inviteUser, EnumBasicPermissions.CMIS_ALL.value()) + .then().removeAcl(inviteUser, PermissionMapping.CAN_DELETE_OBJECT) + .and().assertThat().permissionIsNotSetForUser(inviteUser, EnumBasicPermissions.CMIS_ALL.value()); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Remove invalid Acl(that was not set) for valid document with PermissionMapping") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisConstraintException.class, + expectedExceptionsMessageRegExp="No matching ACE found to remove!*") + public void siteManagerCannotRemoveInvalidAclWithPermissionMapping() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo() + .then().addAcl(inviteUser, PermissionMapping.CAN_UPDATE_PROPERTIES_OBJECT) + .assertThat().permissionIsSetForUser(inviteUser, EnumBasicPermissions.CMIS_WRITE.value()) + .then().removeAcl(inviteUser, PermissionMapping.CAN_CHECKIN_DOCUMENT); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Apply invalid Acl(that was not set) for valid document with PermissionMapping") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisConstraintException.class, + expectedExceptionsMessageRegExp="No matching ACE found to remove!*") + public void siteManagerCannotApplyInvalidAclWithPermissionMapping() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo() + .then().addAcl(inviteUser, PermissionMapping.CAN_DELETE_OBJECT) + .and().assertThat().permissionIsSetForUser(inviteUser, EnumBasicPermissions.CMIS_ALL.value()) + .then().applyAcl(inviteUser, PermissionMapping.CAN_UPDATE_PROPERTIES_OBJECT, PermissionMapping.CAN_CREATE_FOLDER_FOLDER); + } +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/AddObjectToFolderTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/AddObjectToFolderTests.java new file mode 100644 index 0000000000..558e46ee58 --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/AddObjectToFolderTests.java @@ -0,0 +1,222 @@ +package org.alfresco.cmis; + +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +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.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 9/28/2016. + */ +public class AddObjectToFolderTests extends CmisTest +{ + UserModel testUser; + SiteModel testSite; + FolderModel destinationFolder; + FileModel sourceFile; + private DataUser.ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + testUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(testUser).createPublicRandomSite(); + destinationFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(testUser).usingSite(testSite).createFolder(destinationFolder) + .assertThat().existsInRepo(); + usersWithRoles = dataUser.usingUser(testUser) + .addUsersWithRolesToSite(testSite, UserRole.SiteContributor, UserRole.SiteCollaborator, UserRole.SiteConsumer); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.SANITY, + description = "Verify site manager is able to add document object to folder with CMIS") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void siteManagerShouldAddFileToFolder() throws Exception + { + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(sourceFile).assertThat().existsInRepo() + .then().addDocumentToFolder(destinationFolder, true) + .and().assertThat().existsInRepo() + .and().assertThat().objectIdIs(sourceFile.getNodeRef()); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is not able to add folder object to folder with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisInvalidArgumentException.class, + expectedExceptionsMessageRegExp="Object is not a document!*") + public void siteManagerShouldNotAddFolderToFolder() throws Exception + { + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + FolderModel folderToAdd = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(folderToAdd).assertThat().existsInRepo() + .then().addDocumentToFolder(folderToAdd, true); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is not able to add file a document object in more than one folder in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisObjectNotFoundException.class) + public void siteManagerShouldNotAddInvalidFileToFolder() throws Exception + { + FileModel randomFile = FileModel.getRandomFileModel(FileType.HTML); + randomFile.setCmisLocation("/" + randomFile.getName() + "/"); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .usingResource(randomFile) + .addDocumentToFolder(destinationFolder, true); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is not able to add folder object to folder with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisObjectNotFoundException.class) + public void siteManagerShouldNotAddInvalidFolderToFolder() throws Exception + { + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + FolderModel randomFolder = FolderModel.getRandomFolderModel(); + randomFolder.setCmisLocation("/" + randomFolder.getName() + "/"); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(sourceFile).assertThat().existsInRepo() + .then().addDocumentToFolder(randomFolder, true); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is able to add PWC document to folder with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerShouldAddPWCFileToFolder() throws Exception + { + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(sourceFile).assertThat().existsInRepo() + .then().checkOut().and().assertThat().documentIsCheckedOut() + .usingPWCDocument().addDocumentToFolder(destinationFolder, true) + .and().assertThat().existsInRepo() + .and().assertThat().documentIsCheckedOut(); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is able to add document object to folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanAddDocumentWithVersionsToFolderWithTrueAllVersions() throws Exception + { + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(sourceFile).assertThat().existsInRepo() + .then().update("first content").update("second content") + .and().assertThat().documentHasVersion(1.2) + .then().addDocumentToFolder(destinationFolder, true) + .and().assertThat().existsInRepo() + .and().assertThat().documentHasVersion(1.2); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is not able to add document object to folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisInvalidArgumentException.class, + expectedExceptionsMessageRegExp="Only allVersions=true supported!*") + public void siteManagerCannotAddDocumentToFolderWithFalseAllVersions() throws Exception + { + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(sourceFile).assertThat().existsInRepo() + .then().update("update content") + .and().assertThat().documentHasVersion(1.1) + .then().addDocumentToFolder(destinationFolder, false); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site collaborator is able to add document object to folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void collaboratorCanAddFileToFolderCreatedByHimself() throws Exception + { + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .usingSite(testSite) + .createFile(sourceFile).assertThat().existsInRepo() + .then().addDocumentToFolder(destinationFolder, true) + .and().assertThat().existsInRepo() + .and().assertThat().objectIdIs(sourceFile.getNodeRef()); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site collaborator is able to add document object created by manager to folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void collaboratorCanAddFileToFolderCreatedByManager() throws Exception + { + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser) + .usingSite(testSite) + .createFile(sourceFile).assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .then().addDocumentToFolder(destinationFolder, true) + .and().assertThat().existsInRepo(); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site contributor is able to add document object to folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void contributorCanAddFileToFolderCreatedByHimself() throws Exception + { + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .usingSite(testSite) + .createFile(sourceFile).assertThat().existsInRepo() + .then().addDocumentToFolder(destinationFolder, true) + .and().assertThat().existsInRepo() + .and().assertThat().objectIdIs(sourceFile.getNodeRef()); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site contributor is able to add document object created by manager to folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void contributorCanAddFileToFolderCreatedByManager() throws Exception + { + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser) + .usingSite(testSite) + .createFile(sourceFile).assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .then().addDocumentToFolder(destinationFolder, true) + .and().assertThat().existsInRepo(); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site consumer is able to add document object created by manager to folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void consumerCanAddFileToFolderCreatedByManager() throws Exception + { + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser) + .usingSite(testSite) + .createFile(sourceFile).assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .then().addDocumentToFolder(destinationFolder, true); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify non invited user is not able to delete parent folder with multiple children in private site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void nonInvitedUserCannotDeleteFolderTreeInPrivateSite() throws Exception + { + SiteModel privateSite = dataSite.usingUser(testUser).createPrivateRandomSite(); + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + destinationFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(testUser) + .usingSite(privateSite) + .createFolder(destinationFolder).assertThat().existsInRepo() + .createFile(sourceFile).assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .then().addDocumentToFolder(destinationFolder, true); + } +} + diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/AllowableActionTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/AllowableActionTests.java new file mode 100644 index 0000000000..3047a32441 --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/AllowableActionTests.java @@ -0,0 +1,217 @@ +package org.alfresco.cmis; + +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +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.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.enums.Action; +import org.apache.chemistry.opencmis.commons.enums.VersioningState; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class AllowableActionTests extends CmisTest +{ + UserModel testUser; + SiteModel testSite; + FileModel testFile, managerFile; + FolderModel testFolder, managerFolder; + private DataUser.ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + managerFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, documentContent); + managerFolder = FolderModel.getRandomFolderModel(); + testUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(testUser).createPublicRandomSite(); + usersWithRoles = dataUser.usingUser(testUser) + .addUsersWithRolesToSite(testSite, UserRole.SiteContributor, UserRole.SiteCollaborator, UserRole.SiteConsumer); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(managerFile).assertThat().existsInRepo() + .createFolder(managerFolder).assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify valid document has allowable action CAN_CHECK_OUT") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void verifyValidDocumentHasAllowableActionCanCheckOut() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingResource(managerFile) + .assertThat().hasAllowableActions(Action.CAN_CHECK_OUT) + .then().assertThat().isAllowableActionInList(Action.CAN_APPLY_ACL, Action.CAN_DELETE_CONTENT_STREAM, Action.CAN_GET_ALL_VERSIONS); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify valid folder has allowable action CAN_GET_CHILDREN, CAN_CREATE_FOLDER") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void verifyValidFolderHasAllowableAction() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(testUser).usingResource(managerFolder) + .assertThat().hasAllowableActions(Action.CAN_GET_CHILDREN, Action.CAN_CREATE_FOLDER); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify pwc document has allowable action CAN_CHECK_IN, CAN_CANCEL_CHECK_OUT and CAN_MOVE_OBJECT") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void verifyPWCDocumentHasAllowable() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile, VersioningState.CHECKEDOUT) + .assertThat().existsInRepo().and().assertThat().documentIsCheckedOut() + .usingPWCDocument() + .assertThat().hasAllowableActions(Action.CAN_CHECK_IN, Action.CAN_MOVE_OBJECT, Action.CAN_CANCEL_CHECK_OUT) + .and().assertThat().isAllowableActionInList(Action.CAN_CHECK_IN, Action.CAN_GET_CONTENT_STREAM, Action.CAN_CANCEL_CHECK_OUT); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify valid folder does not have allowable action CAN_CHECK_IN, CAN_CHECK_OUT, CAN_CANCEL_CHECK_OUT") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void verifyFolderDoesNotHaveCanCheckInAction() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(testUser).usingResource(managerFolder) + .assertThat().doesNotHaveAllowableActions(Action.CAN_CHECK_IN, Action.CAN_CHECK_OUT, Action.CAN_CANCEL_CHECK_OUT); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify delete document has allowable actions") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisObjectNotFoundException.class) + public void verifyDeletedDocumentHasAllowableActions() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).assertThat().existsInRepo() + .then().delete() + .and().assertThat().hasAllowableActions(Action.CAN_CHECK_IN, Action.CAN_MOVE_OBJECT, Action.CAN_CANCEL_CHECK_OUT); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify delete document has allowable actions") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisObjectNotFoundException.class) + public void verifyDeletedDocumentGetAllowableActions() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).assertThat().existsInRepo() + .then().delete() + .and().assertThat().isAllowableActionInList(Action.CAN_CHECK_IN, Action.CAN_MOVE_OBJECT, Action.CAN_CANCEL_CHECK_OUT); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify checked out document does not have allowable action CAN_CHECK_IN, CAN_CANCEL_CHECK_OUT") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void verifyCheckedOutDocumentHasAllowable() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile, VersioningState.CHECKEDOUT) + .assertThat().existsInRepo().and().assertThat().documentIsCheckedOut() + .usingResource(testFile) + .assertThat().hasAllowableActions(Action.CAN_GET_ALL_VERSIONS, Action.CAN_GET_CONTENT_STREAM, Action.CAN_GET_ACL, Action.CAN_GET_PROPERTIES) + .and().assertThat().doesNotHaveAllowableActions(Action.CAN_CHECK_IN, Action.CAN_CANCEL_CHECK_OUT); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify contributor can get allowable and not allowable actions for content created by mananger") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void contributorGetAllowableActionForContentCreatedByManager() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .usingResource(managerFile) + .assertThat().hasAllowableActions(Action.CAN_GET_PROPERTIES, Action.CAN_GET_ACL, Action.CAN_GET_CONTENT_STREAM) + .assertThat().doesNotHaveAllowableActions(Action.CAN_DELETE_OBJECT, Action.CAN_CHECK_OUT, Action.CAN_CHECK_IN, Action.CAN_MOVE_OBJECT) + .assertThat().isAllowableActionInList(Action.CAN_GET_PROPERTIES, Action.CAN_GET_ACL, Action.CAN_GET_CONTENT_STREAM) + .usingResource(managerFolder) + .assertThat().hasAllowableActions(Action.CAN_GET_FOLDER_PARENT, Action.CAN_GET_FOLDER_TREE, Action.CAN_CREATE_FOLDER) + .assertThat().doesNotHaveAllowableActions(Action.CAN_DELETE_OBJECT, Action.CAN_DELETE_TREE, Action.CAN_MOVE_OBJECT) + .assertThat().isAllowableActionInList(Action.CAN_GET_FOLDER_PARENT, Action.CAN_GET_FOLDER_TREE, Action.CAN_CREATE_FOLDER); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify collaborator can get allowable and not allowable actions for content created by mananger") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void collaboratorGetAllowableActionForContentCreatedByManager() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .usingResource(managerFile) + .assertThat().hasAllowableActions(Action.CAN_UPDATE_PROPERTIES, Action.CAN_GET_ACL, Action.CAN_CHECK_OUT, Action.CAN_ADD_OBJECT_TO_FOLDER) + .assertThat().doesNotHaveAllowableActions(Action.CAN_DELETE_OBJECT, Action.CAN_MOVE_OBJECT) + .assertThat().isAllowableActionInList(Action.CAN_GET_PROPERTIES, Action.CAN_GET_ACL, Action.CAN_GET_CONTENT_STREAM, + Action.CAN_UPDATE_PROPERTIES, Action.CAN_CHECK_OUT, Action.CAN_ADD_OBJECT_TO_FOLDER) + .usingResource(managerFolder) + .assertThat().hasAllowableActions(Action.CAN_GET_FOLDER_PARENT, Action.CAN_GET_FOLDER_TREE, Action.CAN_CREATE_FOLDER, Action.CAN_UPDATE_PROPERTIES) + .assertThat().doesNotHaveAllowableActions(Action.CAN_DELETE_OBJECT, Action.CAN_DELETE_TREE, Action.CAN_MOVE_OBJECT) + .assertThat().isAllowableActionInList(Action.CAN_GET_FOLDER_PARENT, Action.CAN_GET_FOLDER_TREE, Action.CAN_CREATE_FOLDER,Action.CAN_UPDATE_PROPERTIES); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify consumer can get allowable and not allowable actions for content created by mananger") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void consumerGetAllowableActionForContentCreatedByManager() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .usingResource(managerFile) + .assertThat().hasAllowableActions(Action.CAN_GET_PROPERTIES, Action.CAN_GET_ACL, Action.CAN_GET_ALL_VERSIONS, Action.CAN_ADD_OBJECT_TO_FOLDER) + .assertThat().doesNotHaveAllowableActions(Action.CAN_DELETE_OBJECT, Action.CAN_MOVE_OBJECT, Action.CAN_CHECK_OUT) + .assertThat().isAllowableActionInList(Action.CAN_GET_PROPERTIES, Action.CAN_GET_ACL, Action.CAN_GET_ALL_VERSIONS, Action.CAN_ADD_OBJECT_TO_FOLDER) + .usingResource(managerFolder) + .assertThat().hasAllowableActions(Action.CAN_GET_FOLDER_PARENT, Action.CAN_GET_FOLDER_TREE, Action.CAN_GET_DESCENDANTS) + .assertThat().doesNotHaveAllowableActions(Action.CAN_DELETE_OBJECT, Action.CAN_DELETE_TREE, Action.CAN_MOVE_OBJECT) + .assertThat().isAllowableActionInList(Action.CAN_GET_FOLDER_PARENT, Action.CAN_GET_FOLDER_TREE, Action.CAN_GET_DESCENDANTS); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify consumer can get allowable and not allowable actions for content created by mananger") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void nonInvitedUserCanGetAllowableActionForContentCreatedByManager() throws Exception + { + UserModel nonInvitedUser = dataUser.createRandomTestUser(); + cmisApi.authenticateUser(nonInvitedUser) + .usingResource(managerFile) + .assertThat().hasAllowableActions(Action.CAN_GET_PROPERTIES, Action.CAN_GET_ACL, Action.CAN_GET_ALL_VERSIONS, Action.CAN_ADD_OBJECT_TO_FOLDER) + .assertThat().doesNotHaveAllowableActions(Action.CAN_DELETE_OBJECT, Action.CAN_MOVE_OBJECT, Action.CAN_CHECK_OUT) + .assertThat().isAllowableActionInList(Action.CAN_GET_PROPERTIES, Action.CAN_GET_ACL, Action.CAN_GET_ALL_VERSIONS, Action.CAN_ADD_OBJECT_TO_FOLDER) + .usingResource(managerFolder) + .assertThat().hasAllowableActions(Action.CAN_GET_FOLDER_PARENT, Action.CAN_GET_FOLDER_TREE, Action.CAN_GET_DESCENDANTS) + .assertThat().doesNotHaveAllowableActions(Action.CAN_DELETE_OBJECT, Action.CAN_DELETE_TREE, Action.CAN_MOVE_OBJECT) + .assertThat().isAllowableActionInList(Action.CAN_GET_FOLDER_PARENT, Action.CAN_GET_FOLDER_TREE, Action.CAN_GET_DESCENDANTS); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify non invited user is not able to get allowable actions from private site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void nonInvitedUserOnPrivateSiteCannotGetAllowableActions() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + SiteModel privateSite = dataSite.usingUser(testUser).createPrivateRandomSite(); + cmisApi.authenticateUser(testUser).usingSite(privateSite).createFile(testFile).assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .usingResource(testFile) + .assertThat().hasAllowableActions(Action.CAN_GET_PROPERTIES); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify non invited user is not able to get allowable actions from private site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void nonInvitedUserOnModeratedSiteCannotGetAllowableActions() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + SiteModel moderatedSite = dataSite.usingUser(testUser).createModeratedRandomSite(); + cmisApi.authenticateUser(testUser).usingSite(moderatedSite).createFile(testFile).assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .usingResource(testFile) + .assertThat().hasAllowableActions(Action.CAN_GET_PROPERTIES); + } +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/AppendContentStreamTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/AppendContentStreamTests.java new file mode 100644 index 0000000000..1cc3f5b753 --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/AppendContentStreamTests.java @@ -0,0 +1,240 @@ +package org.alfresco.cmis; + +import org.alfresco.cmis.exception.InvalidCmisObjectException; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.*; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 9/26/2016. + */ +public class AppendContentStreamTests extends CmisTest +{ + UserModel siteManager; + SiteModel publicSite, privateSite; + FileModel testFile; + String initialContent = "initial content "; + String textToAppend = "text to append"; + private DataUser.ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + siteManager = dataUser.createRandomTestUser(); + publicSite = dataSite.usingUser(siteManager).createPublicRandomSite(); + privateSite = dataSite.usingUser(siteManager).createPrivateRandomSite(); + usersWithRoles = dataUser.addUsersWithRolesToSite(publicSite, UserRole.SiteManager, UserRole.SiteContributor, UserRole.SiteCollaborator, UserRole.SiteConsumer); + } + + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify site manager is able to append content to a not empty file in DocumentLibrary with CMIS") + public void siteManagerShouldAppendContentToNotEmptyFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD, initialContent); + cmisApi.authenticateUser(siteManager).usingSite(publicSite).createFile(testFile).assertThat().existsInRepo() + .and().assertThat().contentIs(initialContent) + .then().update(textToAppend) + .assertThat().contentIs(initialContent + textToAppend); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisObjectNotFoundException.class) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify user is not able to append content to a non existent Document in DocumentLibrary with CMIS") + public void userShouldNotAppendContentToNonexistentFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD, initialContent); + cmisApi.authenticateUser(siteManager).usingSite(publicSite).createFile(testFile) + .assertThat().existsInRepo() + .and().assertThat().contentIs(initialContent) + .then().delete() + .and().assertThat().doesNotExistInRepo() + .then().update(textToAppend); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is able to append content to an empty file with version with CMIS") + public void siteManagerCanAppendContentToEmptyFileWithVersion() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD, initialContent); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(testFile).assertThat().existsInRepo() + .and().assertThat().contentIs(initialContent) + .then().setContent("") + .assertThat().contentIs("") + .refreshResource() + .then().update(textToAppend) + .and().assertThat().contentIs(textToAppend); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is able to append content to an empty file with no version in DocumentLibrary with CMIS") + public void siteManagerCanAppendContentToEmptyFileWithNoVersion() throws Exception + { + FileModel emptyFile = FileModel.getRandomFileModel(FileType.HTML); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(emptyFile).assertThat().existsInRepo() + .and().assertThat().contentIs("") + .then().update(textToAppend) + .and().assertThat().contentIs(textToAppend); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is able to append content with last chunk parameter set to FALSE with CMIS") + public void siteManagerCanAppendContentWithLastChunkSetToFalse() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD, initialContent); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(testFile).assertThat().existsInRepo() + .and().assertThat().contentIs(initialContent) + .then().update(textToAppend, false) + .and().assertThat().contentIs(initialContent + textToAppend); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify admin is able to append content to a file created by other user in DocumentLibrary with CMIS") + public void adminShouldAppendContentToFileCreatedByOtherUser() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD, initialContent); + cmisApi.authenticateUser(siteManager).usingSite(publicSite).createFile(testFile).assertThat().existsInRepo() + .and().assertThat().contentIs(initialContent) + .then().authenticateUser(dataUser.getAdminUser()).update(textToAppend) + .assertThat().contentIs(initialContent + textToAppend); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is able to append content to a file created by other user in DocumentLibrary with CMIS") + public void siteManagerShouldAppendContentToFileCreatedByOtherUser() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD, initialContent); + cmisApi.authenticateUser(siteManager).usingSite(publicSite).createFile(testFile).assertThat().existsInRepo() + .and().assertThat().contentIs(initialContent) + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).update(textToAppend) + .assertThat().contentIs(initialContent + textToAppend); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site contributor is able to append content to a file created by self in DocumentLibrary with CMIS") + public void contributorShouldAppendContentToFileCreatedBySelf() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD, initialContent); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .usingSite(publicSite).createFile(testFile).assertThat().existsInRepo() + .and().assertThat().contentIs(initialContent) + .then().update(textToAppend) + .assertThat().contentIs(initialContent + textToAppend); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site contributor is not able to append content to a file created by other user in DocumentLibrary with CMIS") + public void contributorCannotAppendContentToFileCreatedByOtherUser() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD, initialContent); + cmisApi.authenticateUser(siteManager) + .usingSite(publicSite).createFile(testFile).assertThat().existsInRepo() + .and().assertThat().contentIs(initialContent) + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).update(textToAppend); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site collaborator is able to append content to a file created by other user in DocumentLibrary with CMIS") + public void collaboratorShouldAppendContentToFileCreatedByOtherUser() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD, initialContent); + cmisApi.authenticateUser(siteManager).usingSite(publicSite).createFile(testFile).assertThat().existsInRepo() + .and().assertThat().contentIs(initialContent) + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).update(textToAppend) + .assertThat().contentIs(initialContent + textToAppend); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site collaborator is able to append content to a file created by self in DocumentLibrary with CMIS") + public void collaboratorShouldAppendContentToFileCreatedBySelf() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD, initialContent); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .usingSite(publicSite).createFile(testFile).assertThat().existsInRepo() + .and().assertThat().contentIs(initialContent) + .then().update(textToAppend) + .assertThat().contentIs(initialContent + textToAppend); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site consumer is not able to append content to a file with CMIS") + public void consumerCannotAppendContentToFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD, initialContent); + cmisApi.authenticateUser(siteManager) + .usingSite(publicSite).createFile(testFile).assertThat().existsInRepo() + .and().assertThat().contentIs(initialContent) + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).update(textToAppend); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = CmisUpdateConflictException.class, expectedExceptionsMessageRegExp = "^.*Cannot perform operation since the node.*is locked.$") + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is not able to append content to a checked out file with CMIS") + public void managerCannotAppendContentToCheckedOutFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD, initialContent); + cmisApi.authenticateUser(siteManager) + .usingSite(publicSite).createFile(testFile).assertThat().existsInRepo() + .then().checkOut().assertThat().documentIsCheckedOut() + .when().update(textToAppend); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is able to append content to a PWC file with CMIS") + public void managerCanAppendContentToPWCFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD, initialContent); + cmisApi.authenticateUser(siteManager) + .usingSite(publicSite).createFile(testFile).assertThat().existsInRepo() + .then().checkOut().assertThat().documentIsCheckedOut() + .usingPWCDocument().update(textToAppend) + .assertThat().contentIs(initialContent + textToAppend); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify unauthorized user is not able to append content to a file created in a private site with CMIS") + public void unauthorizedUserCannotAppendContentToFileFromPrivateSite() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD, initialContent); + cmisApi.authenticateUser(siteManager) + .usingSite(privateSite).createFile(testFile).assertThat().existsInRepo() + .and().assertThat().contentIs(initialContent) + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .usingResource(testFile).update(textToAppend); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify user is not able to append content to an invalid file with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions = InvalidCmisObjectException.class, expectedExceptionsMessageRegExp = "^Content at.*is not a file$") + public void userCannotAppendContentOfInvalidFile() throws Exception + { + FolderModel testFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFolder(testFolder).assertThat().existsInRepo() + .update(textToAppend); + } + +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/CancelCheckOutTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/CancelCheckOutTests.java new file mode 100644 index 0000000000..55f1971607 --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/CancelCheckOutTests.java @@ -0,0 +1,154 @@ +package org.alfresco.cmis; + +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.enums.VersioningState; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class CancelCheckOutTests extends CmisTest +{ + UserModel siteManager; + SiteModel testSite; + FileModel testFile; + private String fileContent = "content"; + private DataUser.ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + siteManager = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(siteManager).createPublicRandomSite(); + usersWithRoles = dataUser.addUsersWithRolesToSite(testSite, UserRole.SiteContributor, UserRole.SiteCollaborator); + } + + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify cancel check out on a pwc") + public void cancelCheckOutOnPWC() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, fileContent); + cmisApi.authenticateUser(siteManager).usingSite(testSite) + .createFile(testFile) + .and().assertThat().existsInRepo() + .then().checkOut().and().assertThat().documentIsCheckedOut() + .and().assertThat().isPrivateWorkingCopy() + .then().cancelCheckOut() + .and().assertThat().isNotPrivateWorkingCopy() + .and().assertThat().existsInRepo() + .and().assertThat().documentIsNotCheckedOut(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify cancel check out on a document that isn't checked out") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = CmisRuntimeException.class) + public void cancelCheckOutOnADocumentThatIsntCheckedOut() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, fileContent); + cmisApi.authenticateUser(siteManager).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo() + .and().assertThat().isNotPrivateWorkingCopy() + .then().cancelCheckOut(); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisObjectNotFoundException.class) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify cancel check out on deleted document") + public void cancelCheckOutOnDeletedDocument() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, fileContent); + cmisApi.authenticateUser(siteManager).usingSite(testSite) + .createFile(testFile) + .and().assertThat().existsInRepo() + .then().delete().and().assertThat().doesNotExistInRepo() + .then().cancelCheckOut(); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisRuntimeException.class) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify cancel check out on a pwc twice") + public void cancelCheckOutTwice() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, fileContent); + cmisApi.authenticateUser(siteManager).usingSite(testSite) + .createFile(testFile) + .and().assertThat().existsInRepo() + .and().checkOut() + .and().assertThat().documentIsCheckedOut().assertThat().isPrivateWorkingCopy() + .and().cancelCheckOut() + .cancelCheckOut(); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify that cancel check out on document created with Versioning State CHECKED OUT deletes the document") + public void cancelCheckOutOnDocWithVersioningStateCheckedOut() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, fileContent); + cmisApi.authenticateUser(siteManager).usingSite(testSite) + .createFile(testFile, VersioningState.CHECKEDOUT) + .and().assertThat().existsInRepo().assertThat().documentIsCheckedOut() + .then().usingPWCDocument() + .cancelCheckOut() + .and().assertThat().doesNotExistInRepo() + .usingResource(testFile).assertThat().doesNotExistInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify that collaborator user can cancel check out on document created by self") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void collaboratorCanCancelCheckInDocumentCreatedBySelf() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, fileContent); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingSite(testSite) + .createFile(testFile) + .and().assertThat().existsInRepo() + .and().checkOut() + .and().assertThat().documentIsCheckedOut() + .and().cancelCheckOut() + .and().assertThat().documentIsNotCheckedOut() + .then().assertThat().documentHasVersion(1.0); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify that collaborator user can cancel check out on document created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void collaboratorCanCancelCheckInDocumentCreatedByManager() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, fileContent); + cmisApi.authenticateUser(siteManager).usingSite(testSite) + .createFile(testFile) + .and().assertThat().existsInRepo() + .authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .and().checkOut() + .and().assertThat().documentIsCheckedOut() + .and().cancelCheckOut() + .and().assertThat().documentIsNotCheckedOut() + .then().assertThat().documentHasVersion(1.0); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify that contributor user can cancel check out on document created by self") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void contributorCanCancelCheckInDocumentCreatedBySelf() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, fileContent); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingSite(testSite) + .createFile(testFile) + .and().assertThat().existsInRepo() + .and().checkOut() + .and().assertThat().documentIsCheckedOut() + .and().cancelCheckOut() + .and().assertThat().documentIsNotCheckedOut() + .then().assertThat().documentHasVersion(1.0); + } +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/CheckInTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/CheckInTests.java new file mode 100644 index 0000000000..4caa9fddef --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/CheckInTests.java @@ -0,0 +1,329 @@ +package org.alfresco.cmis; + +import java.util.HashMap; +import java.util.Map; + +import org.alfresco.utility.Utility; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.PropertyIds; +import org.apache.chemistry.opencmis.commons.enums.VersioningState; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisVersioningException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class CheckInTests extends CmisTest +{ + UserModel unauthorizedUser; + UserModel siteManager; + SiteModel testSite; + FileModel testFile; + private String fileContent = "content"; + private DataUser.ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + unauthorizedUser = dataUser.createRandomTestUser(); + siteManager = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(siteManager).createPublicRandomSite(); + usersWithRoles = dataUser.addUsersWithRolesToSite(testSite, UserRole.SiteContributor, UserRole.SiteCollaborator); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify check in document with minor version and no content") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void checkInDocumentWithMinorVersionAndNoContent() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, fileContent); + cmisApi.authenticateUser(siteManager).usingSite(testSite) + .createFile(testFile) + .and().assertThat().existsInRepo() + .and().checkOut() + .and().assertThat().documentIsCheckedOut() + .and().prepareDocumentForCheckIn() + .withMinorVersion() + .checkIn().refreshResource() + .and().assertThat().documentIsNotCheckedOut() + .then().assertThat().documentHasVersion(1.1); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify check in document with minor version and with content") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void checkInDocumentWithMinorVersionAndWithContent() throws Exception + { + String newContent = "new minor content"; + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, fileContent); + cmisApi.authenticateUser(siteManager).usingSite(testSite).createFile(testFile) + .and().assertThat().existsInRepo() + .and().checkOut() + .and().assertThat().documentIsCheckedOut() + .assertThat().isPrivateWorkingCopy() + .and().prepareDocumentForCheckIn() + .withMinorVersion() + .withContent(newContent) + .checkIn() + .and().assertThat().documentIsNotCheckedOut() + .then().assertThat().documentHasVersion(1.1) + .and().assertThat().contentIs(newContent); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify check in document with major version and no content") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void checkInDocumentWithMajorVersionAndNoContent() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, fileContent); + cmisApi.authenticateUser(siteManager).usingSite(testSite).createFile(testFile) + .and().assertThat().existsInRepo() + .and().checkOut() + .and().assertThat().documentIsCheckedOut() + .and().prepareDocumentForCheckIn() + .withMajorVersion() + .checkIn().refreshResource() + .and().assertThat().documentIsNotCheckedOut() + .then().assertThat().documentHasVersion(2.0); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify check in document with major version and with content") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void checkInDocumentWithMajorVersionAndWithContent() throws Exception + { + String newContent = "new major content"; + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, fileContent); + cmisApi.authenticateUser(siteManager).usingSite(testSite).createFile(testFile) + .and().assertThat().existsInRepo() + .and().checkOut() + .and().assertThat().documentIsCheckedOut() + .and().prepareDocumentForCheckIn() + .withMajorVersion() + .withContent(newContent) + .checkIn().refreshResource() + .and().assertThat().documentIsNotCheckedOut() + .then().assertThat().documentHasVersion(2.0); + Utility.waitToLoopTime(5); + cmisApi.assertThat().contentIs(newContent); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify check in document that wasn't checked out") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = CmisVersioningException.class) + public void checkInDocumentThatWasntCheckedOut() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, fileContent); + cmisApi.authenticateUser(siteManager).usingSite(testSite).createFile(testFile) + .and().assertThat().existsInRepo() + .and().assertThat().documentIsNotCheckedOut() + .then().prepareDocumentForCheckIn() + .checkIn(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify check in comment for document with major version") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void getCheckInCommentForDocMajorVersion() throws Exception + { + String newContent = "new major content"; + String comment = "major version comment"; + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, fileContent); + cmisApi.authenticateUser(siteManager).usingSite(testSite).createFile(testFile) + .and().assertThat().existsInRepo() + .and().checkOut() + .and().assertThat().documentIsCheckedOut() + .and().prepareDocumentForCheckIn() + .withMajorVersion() + .withContent(newContent) + .withComment(comment) + .checkIn().refreshResource() + .and().assertThat().documentIsNotCheckedOut() + .then().assertThat().documentHasVersion(2.0) + .and().assertThat().contentIs(newContent) + .assertThat().hasCheckInCommentLastVersion(comment); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify check in comments for multiple versions") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void getCheckInCommentForDocWithMultipleVersions() throws Exception + { + String minorComment = "minor version comment"; + String majorComment = "major version comment"; + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, fileContent); + cmisApi.authenticateUser(siteManager).usingSite(testSite).createFile(testFile) + .and().assertThat().existsInRepo() + .and().checkOut() + .then().prepareDocumentForCheckIn() + .withMinorVersion() + .withContent("minor content") + .withComment(minorComment) + .checkIn().refreshResource() + .and().assertThat().documentIsNotCheckedOut() + .and().assertThat().hasCheckInCommentForVersion(1.1, minorComment) + .then().checkOut().prepareDocumentForCheckIn() + .withMajorVersion() + .withContent("major content") + .withComment(majorComment) + .checkIn().refreshResource() + .and().assertThat().documentIsNotCheckedOut() + .and().assertThat().hasCheckInCommentForVersion(2.0, majorComment); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify check in document with minor version and no content") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisVersioningException.class) + public void checkInDocumentTwice() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, fileContent); + cmisApi.authenticateUser(siteManager).usingSite(testSite) + .createFile(testFile) + .and().assertThat().existsInRepo() + .and().checkOut() + .and().assertThat().documentIsCheckedOut() + .and().prepareDocumentForCheckIn() + .withMinorVersion() + .checkIn() + .prepareDocumentForCheckIn() + .checkIn(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify check in document created with VersioningState checkedout") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void checkInDocumentCreatedWithVersioningStateCheckedOut() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, fileContent); + cmisApi.authenticateUser(siteManager).usingSite(testSite) + .createFile(testFile, VersioningState.CHECKEDOUT) + .and().assertThat().existsInRepo().assertThat().documentIsCheckedOut() + .then().prepareDocumentForCheckIn() + .withMinorVersion() + .withContent("minor content") + .checkIn().refreshResource() + .and().assertThat().documentIsNotCheckedOut() + .then().assertThat().documentHasVersion(1.1); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify check in for deleted document") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisObjectNotFoundException.class) + public void checkInDeletedDocument() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, fileContent); + cmisApi.authenticateUser(siteManager).usingSite(testSite) + .createFile(testFile) + .and().assertThat().existsInRepo() + .then().delete().assertThat().doesNotExistInRepo() + .then().prepareDocumentForCheckIn() + .withMinorVersion() + .withContent("minor content") + .checkIn(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify check in document created with VersioningState checkedout") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void checkInDocumentWithProperties() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, fileContent); + + Map properties = new HashMap(); + properties.put(PropertyIds.NAME, testFile.getName() + "-edit"); + properties.put("cm:title", testFile.getName() + "-title"); + properties.put("cm:description", "description after checkout"); + + cmisApi.authenticateUser(siteManager).usingSite(testSite) + .createFile(testFile, VersioningState.CHECKEDOUT) + .and().assertThat().existsInRepo().assertThat().documentIsCheckedOut() + .then().prepareDocumentForCheckIn() + .withMinorVersion() + .withContent("minor content") + .checkIn(properties).refreshResource() + .and().assertThat().documentIsNotCheckedOut() + .then().assertThat().documentHasVersion(1.1) + .and().assertThat().contentPropertyHasValue("cmis:description", "description after checkout") + .assertThat().contentPropertyHasValue("cmis:name", testFile.getName() + "-edit") + .assertThat().contentPropertyHasValue("cm:title", testFile.getName() + "-title"); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify check in document created with VersioningState checkedout") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=IllegalArgumentException.class) + public void checkInDocumentWithInvalidProperties() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, fileContent); + Map properties = new HashMap(); + properties.put("cmis:fakeProp","fake-value"); + cmisApi.authenticateUser(siteManager).usingSite(testSite) + .createFile(testFile, VersioningState.CHECKEDOUT) + .and().assertThat().existsInRepo().assertThat().documentIsCheckedOut() + .then().prepareDocumentForCheckIn() + .withMinorVersion() + .withContent("minor content") + .checkIn(properties).refreshResource(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify that contributor user can check in document created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void contributorCanCheckInDocumentCreatedBySelf() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, fileContent); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingSite(testSite) + .createFile(testFile) + .and().assertThat().existsInRepo() + .and().checkOut() + .and().assertThat().documentIsCheckedOut() + .and().prepareDocumentForCheckIn() + .withMinorVersion() + .checkIn().refreshResource() + .and().assertThat().documentIsNotCheckedOut() + .then().assertThat().documentHasVersion(1.1); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify that collaborator user can check in document created by self") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void collaboratorCanCheckInDocumentCreatedBySelf() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, fileContent); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingSite(testSite) + .createFile(testFile) + .and().assertThat().existsInRepo() + .and().checkOut() + .and().assertThat().documentIsCheckedOut() + .and().prepareDocumentForCheckIn() + .withMinorVersion() + .checkIn().refreshResource() + .and().assertThat().documentIsNotCheckedOut() + .then().assertThat().documentHasVersion(1.1); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify that collaborator user can check in document created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void collaboratorCanCheckInDocumentCreatedByManager() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, fileContent); + cmisApi.authenticateUser(siteManager).usingSite(testSite) + .createFile(testFile) + .and().assertThat().existsInRepo() + .authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .and().checkOut() + .and().assertThat().documentIsCheckedOut() + .and().prepareDocumentForCheckIn() + .withMinorVersion() + .checkIn().refreshResource() + .and().assertThat().documentIsNotCheckedOut() + .then().assertThat().documentHasVersion(1.1); + } +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/CheckOutTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/CheckOutTests.java new file mode 100644 index 0000000000..95affaa4ca --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/CheckOutTests.java @@ -0,0 +1,148 @@ +package org.alfresco.cmis; + +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.exceptions.*; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class CheckOutTests extends CmisTest +{ + UserModel unauthorizedUser; + UserModel siteManager; + SiteModel testSite; + FileModel testFile; + private String fileContent = "content"; + private DataUser.ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + unauthorizedUser = dataUser.createRandomTestUser(); + siteManager = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(siteManager).createPublicRandomSite(); + usersWithRoles = dataUser.addUsersWithRolesToSite(testSite, UserRole.SiteContributor, UserRole.SiteConsumer); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify check out valid document") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void verifyCheckOutValidDocument() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, fileContent); + cmisApi.authenticateUser(siteManager).usingSite(testSite).createFile(testFile) + .and().assertThat().existsInRepo() + .and().checkOut() + .then().assertThat().documentIsCheckedOut() + .and().assertThat().isPrivateWorkingCopy(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify check out inexistent document") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = CmisObjectNotFoundException.class) + public void verifyCheckOutInexistentDocument() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, fileContent); + cmisApi.authenticateUser(siteManager).usingSite(testSite).createFile(testFile) + .and().delete().assertThat().doesNotExistInRepo() + .then().checkOut(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify if PWC is created for document that is not checked out") + @Test(groups = {TestGroup.REGRESSION, TestGroup.CMIS}) + public void verifyPWCForDocThatIsNotCheckedOut() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, fileContent); + cmisApi.authenticateUser(siteManager).usingSite(testSite).createFile(testFile).assertThat().isNotPrivateWorkingCopy(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify error when a document is checked out twice") + @Test(groups = {TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisVersioningException.class, expectedExceptionsMessageRegExp = "^Check out failed.*This node is already checked out.$") + public void checkOutDocumentTwice() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, fileContent); + cmisApi.authenticateUser(siteManager).usingSite(testSite) + .createFile(testFile).assertThat().existsInRepo() + .then().checkOut().assertThat().documentIsCheckedOut() + .then().checkOut(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify private working copy does NOT exists for a document that was deleted") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void verifyPWCDoesNotExistsForDeletedDocument() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, fileContent); + cmisApi.authenticateUser(siteManager).usingSite(testSite).createFile(testFile) + .and().checkOut() + .then().assertThat().documentIsCheckedOut() + .usingPWCDocument() + .delete() + .and().assertThat().doesNotExistInRepo() + .then().usingResource(testFile) + .assertThat().isNotPrivateWorkingCopy().and().assertThat().documentIsNotCheckedOut(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify that contributor user can NOT check out document created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = { CmisUnauthorizedException.class, CmisPermissionDeniedException.class }) + public void contributorCannotCheckOutDocumentCreatedByManager() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, fileContent); + cmisApi.authenticateUser(siteManager).usingSite(testSite) + .createFile(testFile) + .and().assertThat().existsInRepo() + .authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .and().checkOut(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify that consumer user can NOT check out document") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = { CmisUnauthorizedException.class, CmisPermissionDeniedException.class }) + public void consumerCannotCheckOutDocument() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, fileContent); + cmisApi.authenticateUser(siteManager).usingSite(testSite) + .createFile(testFile) + .and().assertThat().existsInRepo() + .authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .and().checkOut(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify that unauthorized user can NOT check out document from private site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = { CmisUnauthorizedException.class, CmisPermissionDeniedException.class }) + public void unauthorizedUserCannotCheckOutDocumentFromPrivateSite() throws Exception + { + SiteModel privateSite = dataSite.usingUser(siteManager).createPrivateRandomSite(); + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, fileContent); + cmisApi.authenticateUser(siteManager).usingSite(privateSite) + .createFile(testFile) + .and().assertThat().existsInRepo() + .authenticateUser(unauthorizedUser) + .and().checkOut(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify that unauthorized user can NOT check out document from moderated site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = { CmisUnauthorizedException.class, CmisPermissionDeniedException.class }) + public void unauthorizedUserCannotCheckOutDocumentModeratedSite() throws Exception + { + SiteModel moderatedSite = dataSite.usingUser(siteManager).createModeratedRandomSite(); + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, fileContent); + cmisApi.authenticateUser(siteManager).usingSite(moderatedSite) + .createFile(testFile) + .and().assertThat().existsInRepo() + .authenticateUser(unauthorizedUser) + .and().checkOut(); + } +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/CmisTest.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/CmisTest.java new file mode 100644 index 0000000000..cf83810ce9 --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/CmisTest.java @@ -0,0 +1,67 @@ +package org.alfresco.cmis; + +import java.lang.reflect.Method; + +import org.alfresco.utility.LogFactory; +import org.alfresco.utility.data.DataContent; +import org.alfresco.utility.data.DataSite; +import org.alfresco.utility.data.DataUserAIS; +import org.alfresco.utility.network.ServerHealth; +import org.slf4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.BeforeSuite; + +@ContextConfiguration("classpath:alfresco-cmis-context.xml") +@Component +@Scope(value = "prototype") +public abstract class CmisTest extends AbstractTestNGSpringContextTests +{ + private static Logger LOG = LogFactory.getLogger(); + + @Autowired + protected CmisWrapper cmisApi; + + @Autowired + protected DataUserAIS dataUser; + + @Autowired + protected DataSite dataSite; + + @Autowired + protected DataContent dataContent; + + @Autowired + ServerHealth serverHealth; + + public String documentContent = "CMIS document content"; + + @BeforeSuite(alwaysRun = true) + public void checkServerHealth() throws Exception + { + super.springTestContextPrepareTestInstance(); + serverHealth.assertServerIsOnline(); + } + + @BeforeMethod(alwaysRun = true) + public void showStartTestInfo(Method method) + { + LOG.info(String.format("*** STARTING Test: [%s] ***", method.getName())); + } + + @AfterMethod(alwaysRun = true) + public void showEndTestInfo(Method method) + { + LOG.info(String.format("*** ENDING Test: [%s] ***", method.getName())); + } + + public Integer getSolrWaitTimeInSeconds() + { + return cmisApi.cmisProperties.envProperty().getSolrWaitTimeInSeconds(); + } +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/CopyTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/CopyTests.java new file mode 100644 index 0000000000..668c52c039 --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/CopyTests.java @@ -0,0 +1,318 @@ +package org.alfresco.cmis; + +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +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.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 9/28/2016. + */ +public class CopyTests extends CmisTest +{ + UserModel inexistentUser; + UserModel unauthorizedUser; + UserModel testUser; + UserModel contributorUser; + UserModel collaboratorUser; + UserModel consumerUser; + SiteModel testSite; + FileModel sourceFile; + FolderModel targetFolder, sourceFolder; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + unauthorizedUser = dataUser.createRandomTestUser(); + testUser = dataUser.createRandomTestUser(); + contributorUser = dataUser.createRandomTestUser(); + collaboratorUser = dataUser.createRandomTestUser(); + consumerUser = dataUser.createRandomTestUser(); + inexistentUser = new UserModel("inexistent", "inexistent"); + testSite = dataSite.usingUser(testUser).createPublicRandomSite(); + + dataUser.addUserToSite(consumerUser, testSite, UserRole.SiteConsumer); + dataUser.addUserToSite(collaboratorUser, testSite, UserRole.SiteCollaborator); + dataUser.addUserToSite(contributorUser, testSite, UserRole.SiteContributor); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.SANITY, + description = "Verify site manager is able to copy file to an existent location in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void siteManagerCopyFile() throws Exception + { + targetFolder = FolderModel.getRandomFolderModel(); + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "content"); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(targetFolder).and().assertThat().existsInRepo() + .createFile(sourceFile).and().assertThat().existsInRepo() + .then().copyTo(targetFolder) + .and().assertThat().existsInRepo().usingResource(sourceFile).assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.SANITY, + description = "Verify site manager is able to copy folder to an existent location in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void siteManagerCopyFolder() throws Exception + { + targetFolder = FolderModel.getRandomFolderModel(); + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "content"); + sourceFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(targetFolder).assertThat().existsInRepo() + .createFolder(sourceFolder).assertThat().existsInRepo() + .then().copyTo(targetFolder) + .and().assertThat().existsInRepo().usingResource(sourceFolder).assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is not able to copy file to a nonexistent location in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = CmisObjectNotFoundException.class) + public void siteManagerCopyFileToNonexistentTarget() throws Exception + { + targetFolder = FolderModel.getRandomFolderModel(); + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "content"); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(sourceFile).assertThat().existsInRepo() + .createFolder(targetFolder).and().delete() + .then().copyTo(targetFolder); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is not able to copy a nonexistent file in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = CmisObjectNotFoundException.class) + public void siteManagerCopyNonexistentSourceFile() throws Exception + { + targetFolder = FolderModel.getRandomFolderModel(); + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "content"); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(targetFolder).assertThat().existsInRepo() + .createFile(sourceFile).delete() + .then().copyTo(targetFolder); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify non existing user is not able to copy file with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = CmisUnauthorizedException.class) + public void nonExistentUserIsNotAbleToCopyFile() throws Exception + { + targetFolder = FolderModel.getRandomFolderModel(); + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "content"); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(targetFolder).and().assertThat().existsInRepo() + .createFile(sourceFile).and().assertThat().existsInRepo(); + cmisApi.authenticateUser(inexistentUser) + .then().copyTo(targetFolder); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify non existing user is not able to copy folder with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = CmisUnauthorizedException.class) + public void nonExistentUserIsNotAbleToCopyFolder() throws Exception + { + targetFolder = FolderModel.getRandomFolderModel(); + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "content"); + sourceFolder = FolderModel.getRandomFolderModel(); + + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(targetFolder).assertThat().existsInRepo() + .createFolder(sourceFolder).assertThat().existsInRepo(); + cmisApi.authenticateUser(inexistentUser) + .then().copyTo(targetFolder); + } + +// @Bug(id="ACE-5606") + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify that checked out document can be copied with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void checkedOutDocumentCanBeCopied() throws Exception + { + targetFolder = FolderModel.getRandomFolderModel(); + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "content"); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(targetFolder).and().assertThat().existsInRepo() + .createFile(sourceFile).and().assertThat().existsInRepo() + .then().checkOut() + .and().copyTo(targetFolder).refreshResource() + .then().assertThat().existsInRepo() + .then().usingResource(sourceFile).assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify that whole folder structure can be copied with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void folderStructureCanBeCopied() throws Exception + { + targetFolder = FolderModel.getRandomFolderModel(); + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "content"); + FolderModel randomFolder = FolderModel.getRandomFolderModel(); + sourceFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(targetFolder).and().assertThat().existsInRepo() + .createFolder(sourceFolder).and().assertThat().existsInRepo() + .usingResource(sourceFolder).createFolder(randomFolder) + .then().createFile(sourceFile).and().assertThat().existsInRepo() + .then().usingResource(sourceFolder) + .copyTo(targetFolder) + .and().assertThat().existsInRepo() + .assertThat().hasFiles(sourceFile); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify that version history of a copied document is not kept with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void versionHistoryIsNotKeptWhenCopyingFile() throws Exception + { + targetFolder = FolderModel.getRandomFolderModel(); + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "content"); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(targetFolder).and().assertThat().existsInRepo() + .createFile(sourceFile).and().assertThat().existsInRepo() + .then().checkOut().refreshResource() + .prepareDocumentForCheckIn() + .withContent("First update").checkIn().refreshResource() + .and().assertThat().documentHasVersion(1.1) + .then().checkOut() + .prepareDocumentForCheckIn() + .withContent("Second update") + .withMajorVersion() + .checkIn().refreshResource() + .and().assertThat().documentHasVersion(2.0) + .then().copyTo(targetFolder) + .and().assertThat().existsInRepo() + .then().assertThat().documentHasVersion(1.0) + .and().assertThat().contentIs("Second update"); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify copy PWC document object") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void managerCopyPWCDocumentObject() throws Exception + { + sourceFile = dataContent.usingUser(testUser).usingSite(testSite).createContent(FileModel.getRandomFileModel(FileType.TEXT_PLAIN)); + targetFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + FileModel pwcFile = cmisApi.authenticateUser(testUser).usingResource(sourceFile).checkOut().withCMISUtil().getPWCFileModel(); + cmisApi.usingResource(pwcFile).copyTo(targetFolder) + .usingResource(targetFolder).assertThat().hasChildren(pwcFile); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify contributor can copy Document") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void contributorCanCopyDocument() throws Exception + { + sourceFile = dataContent.usingUser(testUser).usingSite(testSite).createContent(FileModel.getRandomFileModel(FileType.TEXT_PLAIN)); + targetFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + cmisApi.authenticateUser(contributorUser).usingResource(sourceFile).copyTo(targetFolder) + .usingResource(targetFolder).assertThat().hasChildren(sourceFile); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify contributor can copy Folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void contributorCanCopyFolder() throws Exception + { + sourceFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + targetFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + cmisApi.authenticateUser(contributorUser).usingResource(sourceFolder).copyTo(targetFolder) + .usingResource(targetFolder).assertThat().hasChildren(sourceFolder); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify collaborator can copy Document") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void collaboratorCanCopyDocument() throws Exception + { + sourceFile = dataContent.usingUser(testUser).usingSite(testSite).createContent(FileModel.getRandomFileModel(FileType.TEXT_PLAIN)); + targetFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + cmisApi.authenticateUser(collaboratorUser).usingResource(sourceFile).copyTo(targetFolder) + .usingResource(targetFolder).assertThat().hasChildren(sourceFile); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify collaborator can copy Folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void collaboratorCanCopyFolder() throws Exception + { + sourceFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + targetFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + cmisApi.authenticateUser(collaboratorUser).usingResource(sourceFolder).copyTo(targetFolder) + .usingResource(targetFolder).assertThat().hasChildren(sourceFolder); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify consumer cannot copy Document") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions = {CmisUnauthorizedException.class, CmisPermissionDeniedException.class}) + public void consumerCannotCopyDocument() throws Exception + { + sourceFile = dataContent.usingUser(testUser).usingSite(testSite).createContent(FileModel.getRandomFileModel(FileType.TEXT_PLAIN)); + targetFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + cmisApi.authenticateUser(consumerUser).usingResource(sourceFile).copyTo(targetFolder) + .usingResource(targetFolder).assertThat().hasChildren(sourceFile); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify consumer cannot copy Folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions = {CmisUnauthorizedException.class, CmisPermissionDeniedException.class}) + public void consumerCannotCopyFolder() throws Exception + { + sourceFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + targetFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + cmisApi.authenticateUser(consumerUser).usingResource(sourceFolder).copyTo(targetFolder) + .usingResource(targetFolder).assertThat().hasChildren(sourceFolder); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify unauthorized user cannot copy Document from private site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisUnauthorizedException.class, CmisPermissionDeniedException.class}) + public void unauthorizedUserCannotCopyDocumentFromPrivateSite() throws Exception + { + SiteModel privateSite = dataSite.usingUser(testUser).createPrivateRandomSite(); + sourceFile = dataContent.usingUser(testUser).usingSite(privateSite).createContent(FileModel.getRandomFileModel(FileType.TEXT_PLAIN)); + targetFolder = dataContent.usingUser(testUser).usingSite(privateSite).createFolder(); + cmisApi.authenticateUser(unauthorizedUser).usingResource(sourceFile).copyTo(targetFolder); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify unauthorized user cannot copy Folder from private site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisUnauthorizedException.class, CmisPermissionDeniedException.class}) + public void unauthorizedUserCannotCopyFolderFromPrivateSite() throws Exception + { + SiteModel privateSite = dataSite.usingUser(testUser).createPrivateRandomSite(); + sourceFolder = dataContent.usingUser(testUser).usingSite(privateSite).createFolder(); + targetFolder = dataContent.usingUser(testUser).usingSite(privateSite).createFolder(); + cmisApi.authenticateUser(unauthorizedUser).usingResource(sourceFolder).copyTo(targetFolder); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify unauthorized user cannot copy Document from moderated site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisUnauthorizedException.class, CmisPermissionDeniedException.class}) + public void unauthorizedUserCannotCopyDocumentFromModeratedSite() throws Exception + { + SiteModel moderatedSite = dataSite.usingUser(testUser).createModeratedRandomSite(); + sourceFile = dataContent.usingUser(testUser).usingSite(moderatedSite).createContent(FileModel.getRandomFileModel(FileType.TEXT_PLAIN)); + targetFolder = dataContent.usingUser(testUser).usingSite(moderatedSite).createFolder(); + cmisApi.authenticateUser(unauthorizedUser).usingResource(sourceFile).copyTo(targetFolder); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify unauthorized user cannot copy Folder from moderated site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisUnauthorizedException.class, CmisPermissionDeniedException.class}) + public void unauthorizedUserCannotCopyFolderFromModeratedSite() throws Exception + { + SiteModel moderatedSite = dataSite.usingUser(testUser).createModeratedRandomSite(); + sourceFolder = dataContent.usingUser(testUser).usingSite(moderatedSite).createFolder(); + targetFolder = dataContent.usingUser(testUser).usingSite(moderatedSite).createFolder(); + cmisApi.authenticateUser(unauthorizedUser).usingResource(sourceFolder).copyTo(targetFolder); + } +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/CreateDocumentFromSourceTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/CreateDocumentFromSourceTests.java new file mode 100644 index 0000000000..b04eb10425 --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/CreateDocumentFromSourceTests.java @@ -0,0 +1,307 @@ +package org.alfresco.cmis; + +import org.alfresco.cmis.exception.InvalidCmisObjectException; +import org.alfresco.utility.Utility; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +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.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.enums.VersioningState; +import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisContentAlreadyExistsException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 9/26/2016. + */ +public class CreateDocumentFromSourceTests extends CmisTest +{ + SiteModel publicSite, privateSite; + UserModel siteManager; + FileModel sourceFile, newFile; + String sourceContent = "source content"; + private DataUser.ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + siteManager = dataUser.createRandomTestUser(); + publicSite = dataSite.usingUser(siteManager).createPublicRandomSite(); + privateSite = dataSite.usingUser(siteManager).createPrivateRandomSite(); + usersWithRoles = dataUser.addUsersWithRolesToSite(publicSite, UserRole.SiteManager, UserRole.SiteContributor, + UserRole.SiteCollaborator, UserRole.SiteConsumer); + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, sourceContent); + cmisApi.authenticateUser(siteManager).usingSite(publicSite).createFile(sourceFile).and().assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.SANITY, + description = "Verify site manager is able to create file from source in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS }) + public void siteManagerShouldCreateDocumentFromSource() throws Exception + { + newFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(siteManager).usingSite(publicSite).createFileFromSource(newFile, sourceFile).and() + .refreshResource().then().assertThat().existsInRepo().and().assertThat().contentIs(sourceContent); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify inexistent user isn't able to create file from source in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions = CmisUnauthorizedException.class) + public void inexistentUserShouldNotCreateDocumentFromSource() throws Exception + { + newFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + UserModel inexistentUser = new UserModel("inexistent", "inexistent"); + cmisApi.authenticateUser(inexistentUser).usingSite(publicSite).createFileFromSource(newFile, sourceFile); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.SANITY, + description = "Verify unauthorized user isn't able to create file from source in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS }, expectedExceptions = { CmisPermissionDeniedException.class, + CmisUnauthorizedException.class }) + public void unauthorizedUserShouldNotCreateDocumentFromSource() throws Exception + { + UserModel unauthorizedUser = dataUser.createRandomTestUser(); + newFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(unauthorizedUser).usingSite(publicSite).createFileFromSource(newFile, sourceFile); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify that manager user is not able to create document from source twice in the same location with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions = CmisContentAlreadyExistsException.class) + public void siteManagerCannotCreateDocumentFromSourceTwice() throws Exception + { + newFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(siteManager).usingSite(publicSite).createFileFromSource(newFile, sourceFile).and().assertThat() + .existsInRepo().then().usingSite(publicSite).createFileFromSource(newFile, sourceFile); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify that admin user is not able to create document from source with invalid source with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions = CmisObjectNotFoundException.class) + public void adminCannotCreateDocFromInvalidSource() throws Exception + { + newFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + FileModel sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(dataUser.getAdminUser()).usingSite(publicSite).createFile(sourceFile).and().assertThat() + .existsInRepo().then().delete().when().usingResource(sourceFile).createFileFromSource(newFile, sourceFile); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify that manager user is not able to create document from source with invalid characters with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions = CmisConstraintException.class) + public void siteManagerCannotCreateDocFromSourceWithInvalidChars() throws Exception + { + newFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + FileModel invalidCharDoc = new FileModel("/.:?|\\`\\.txt", FileType.TEXT_PLAIN); + cmisApi.authenticateUser(siteManager).usingSite(publicSite).createFileFromSource(invalidCharDoc, sourceFile); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify that admin user is not able to create document from source at invalid location with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions = CmisObjectNotFoundException.class) + public void adminCannotCreateDocumentAtInvalidPath() throws Exception + { + newFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + FolderModel invalidLocation = new FolderModel("/Shared/invalidFolder"); + cmisApi.authenticateUser(dataUser.getAdminUser()).usingResource(invalidLocation).createFileFromSource(newFile, + sourceFile); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is not able to create file from folder source CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions = InvalidCmisObjectException.class) + public void siteManagerShouldNotCreateDocFromFolderSource() throws Exception + { + newFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + FolderModel folderSource = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(siteManager).usingSite(publicSite).createFolder(folderSource).then() + .createFileFromSource(newFile, folderSource); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify that manager user is not able to create document from source with invalid base type id with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions = CmisContentAlreadyExistsException.class) + public void siteManagerCannotCreateDocFromSourceWithInvalidBaseTypeId() throws Exception + { + newFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(siteManager).usingSite(publicSite).createFileFromSource(newFile, sourceFile).and().assertThat() + .existsInRepo().then().usingSite(publicSite).createFileFromSource(newFile, sourceFile, "cmis:fakeType"); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify that manager user is not able to create an unnamed document from source with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteManagerCannotCreateUnnamedDocFromSource() throws Exception + { + newFile = new FileModel(""); + cmisApi.authenticateUser(siteManager).usingSite(publicSite).createFileFromSource(newFile, sourceFile).then() + .usingSite(publicSite).assertThat().doesNotHaveFile(newFile); + Utility.sleep(500, 10000, () -> + { + cmisApi.usingSite(publicSite).assertThat().doesNotHaveFile(newFile); + }); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is able to create file from source added by another user with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void anotherSiteManagerShouldCreateDocumentFromSource() throws Exception + { + newFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).usingSite(publicSite) + .createFileFromSource(newFile, sourceFile); + Utility.sleep(500, 10000, () -> + { + cmisApi.refreshResource().then().assertThat().existsInRepo().and().assertThat().contentIs(sourceContent); + }); + + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site contributor is able to create file from source added by another user with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void contributorShouldCreateDocumentFromSource() throws Exception + { + newFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingSite(publicSite) + .createFileFromSource(newFile, sourceFile); + Utility.sleep(500, 10000, () -> + { + cmisApi.refreshResource().then().assertThat().existsInRepo().and().assertThat().contentIs(sourceContent); + }); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site collaborator is able to create file from source added by another user with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void collaboratorShouldCreateDocumentFromSource() throws Exception + { + newFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingSite(publicSite) + .createFileFromSource(newFile, sourceFile); + Utility.sleep(500, 10000, () -> + { + cmisApi.refreshResource().then().assertThat().existsInRepo().and() + .assertThat().contentIs(sourceContent); + }); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site consumer is not able to create file from source with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions = { CmisPermissionDeniedException.class, + CmisUnauthorizedException.class }) + public void consumerShouldNotCreateDocumentFromSource() throws Exception + { + newFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).usingSite(publicSite) + .createFileFromSource(newFile, sourceFile); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is able to create file from source with versioning state set to Minor with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void managerCreatesDocumentFromSourceWithVersionMinor() throws Exception + { + newFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFileFromSource(newFile, sourceFile, VersioningState.MINOR); + Utility.sleep(500, 10000, () -> + { + cmisApi.refreshResource().then().assertThat().existsInRepo().and() + .assertThat().contentIs(sourceContent).and() + .assertThat().documentHasVersion(0.1).and() + .assertThat().isNotLatestMajorVersion(); + }); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is able to create file from source with versioning state set to None with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void managerShouldCreateDocumentFromSourceWithVersionNone() throws Exception + { + newFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFileFromSource(newFile, sourceFile, VersioningState.NONE); + Utility.sleep(1000, 35000, () -> + { + cmisApi.refreshResource().then().assertThat().existsInRepo().and() + .assertThat().contentIs(sourceContent).and() + .assertThat().documentHasVersion(1.0); + }); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is able to create file from source with versioning state set to CHECKEDOUT with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void managerCreatesDocumentFromSourceWithVersionCHECKEDOUT() throws Exception + { + newFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFileFromSource(newFile, sourceFile, VersioningState.CHECKEDOUT); + Utility.sleep(1000, 35000, () -> + { + cmisApi.refreshResource().then().assertThat().existsInRepo().and() + .assertThat().contentIs(sourceContent).and() + .assertThat().documentIsCheckedOut(); + }); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify that admin user is not able to create document from null source with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions = NullPointerException.class) + public void adminCannotCreateDocFromNullSource() throws Exception + { + newFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + FileModel sourceFile = null; + cmisApi.authenticateUser(dataUser.getAdminUser()).usingSite(publicSite).createFileFromSource(newFile, sourceFile); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify that manager is able to create document from a source that is checked out with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void managerShouldCreateDocFromSourceThatIsCheckedOut() throws Exception + { + newFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + FileModel sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, sourceContent); + cmisApi.authenticateUser(siteManager).usingSite(publicSite).createFile(sourceFile).and().assertThat().existsInRepo() + .then().checkOut().and().assertThat().documentIsCheckedOut().when().usingSite(publicSite) + .createFileFromSource(newFile, sourceFile).then().assertThat().existsInRepo().and().assertThat() + .contentIs(sourceContent).and().assertThat().documentIsNotCheckedOut(); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify that manager is able to create document from a source from his private site with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void managerShouldCreateDocFromSourceFromHisPrivateSite() throws Exception + { + newFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + FileModel sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, sourceContent); + cmisApi.authenticateUser(siteManager).usingSite(privateSite).createFile(sourceFile).and().assertThat().existsInRepo() + .when().usingSite(publicSite).createFileFromSource(newFile, sourceFile).then().assertThat().existsInRepo().and() + .assertThat().contentIs(sourceContent); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify that an user is not able to create document from a source from a private site with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions = { CmisPermissionDeniedException.class, + CmisUnauthorizedException.class }) + public void userShouldNotCreateDocFromSourceFromPrivateSite() throws Exception + { + newFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + FileModel sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, sourceContent); + cmisApi.authenticateUser(siteManager).usingSite(privateSite).createFile(sourceFile).and().assertThat().existsInRepo(); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).usingSite(publicSite) + .createFileFromSource(newFile, sourceFile); + } + +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/CreateDocumentTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/CreateDocumentTests.java new file mode 100644 index 0000000000..c212824ec2 --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/CreateDocumentTests.java @@ -0,0 +1,313 @@ +package org.alfresco.cmis; + +import java.util.HashMap; +import java.util.Map; + +import org.alfresco.cmis.exception.InvalidCmisObjectException; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.data.RandomData; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +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.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.enums.BaseTypeId; +import org.apache.chemistry.opencmis.commons.enums.VersioningState; +import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisContentAlreadyExistsException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 9/26/2016. + */ +public class CreateDocumentTests extends CmisTest +{ + SiteModel testSite; + UserModel testUser; + UserModel inexistentUser; + FileModel testFile, adminFile; + private DataUser.ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + testUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(testUser).createPublicRandomSite(); + inexistentUser = new UserModel("inexistent", "inexistent"); + usersWithRoles = dataUser.usingUser(testUser) + .addUsersWithRolesToSite(testSite, UserRole.SiteContributor, UserRole.SiteCollaborator, UserRole.SiteConsumer); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify site manager is able to create files in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void siteManagerShouldCreateDocument() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify inexistent user isn't able to create files in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisUnauthorizedException.class) + public void inexistentUserShouldNotCreateDocument() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD); + cmisApi.authenticateUser(inexistentUser).usingSite(testSite).createFile(testFile); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify unauthorized user isn't able to create files in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void unauthorizedUserShouldNotCreateDocument() throws Exception + { + UserModel unauthorizedUser = dataUser.createRandomTestUser(); + testFile = FileModel.getRandomFileModel(FileType.MSWORD); + cmisApi.authenticateUser(unauthorizedUser) + .usingSite(testSite).createFile(testFile); + } + + @TestRail(section = {"cmis-api"}, executionType=ExecutionType.REGRESSION, + description = "Verify admin user is able to create files in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void adminShouldCreateDocument() throws Exception + { + adminFile = FileModel.getRandomFileModel(FileType.PDF); + cmisApi.authenticateUser(dataUser.getAdminUser()).usingSite(testSite) + .createFile(adminFile).and().assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType=ExecutionType.REGRESSION, + description = "Verify that manager user is not able to create document twice in the same location with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisContentAlreadyExistsException.class) + public void siteManagerCannotCreateDocumentTwice() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo() + .then().createFile(testFile); + } + + @TestRail(section = {"cmis-api"}, executionType=ExecutionType.REGRESSION, + description = "Verify that manager user is not able to create document ending with '.'") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisConstraintException.class) + public void siteManagerCannotCreateDocumentEndingWithPoint() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD, documentContent); + testFile.setName(testFile.getName() + "."); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile); + } + + @TestRail(section = {"cmis-api"}, executionType=ExecutionType.REGRESSION, + description = "Verify that admin user is not able to create document in invalid location with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisObjectNotFoundException.class) + public void adminCannotCreateDocumentAtInvalidPath() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD); + FolderModel invalidLocation = new FolderModel("/Shared/invalidFolder"); + cmisApi.authenticateUser(dataUser.getAdminUser()).usingResource(invalidLocation).createFile(testFile); + } + + @TestRail(section = {"cmis-api"}, executionType=ExecutionType.REGRESSION, + description = "Verify that admin user is not able to create document with invalid characters in name with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisConstraintException.class) + public void adminCannotCreateDocumentWithInvalidCharacters() throws Exception + { + FileModel invalidCharDoc = new FileModel("/.:?|\\`\\.txt", FileType.TEXT_PLAIN); + cmisApi.authenticateUser(dataUser.getAdminUser()) + .usingResource(FolderModel.getSharedFolderModel()) + .createFile(invalidCharDoc); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is not able to create document with invalid base type id with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisObjectNotFoundException.class) + public void siteManagerCannotCreateDocWithInvalidObjectTypeId() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile, "cmis:fakeType", VersioningState.MAJOR); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is not able to create document with cmis:folder base type id with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisConstraintException.class) + public void siteManagerCannotCreateDocWithFolderTypeId() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile, BaseTypeId.CMIS_FOLDER.value(), VersioningState.MAJOR); + } + + @TestRail(section = {"cmis-api"}, executionType=ExecutionType.REGRESSION, + description = "Verify that manager user is able to create document with valid symbols in name") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanCreateDocumentWithValidSymbols() throws Exception + { + FileModel validSymbolsDoc = new FileModel("!@#$%^&", FileType.TEXT_PLAIN, "content"); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(validSymbolsDoc).and().assertThat().existsInRepo(); + Assert.assertNotNull(cmisApi.withCMISUtil().getCmisObject(validSymbolsDoc.getCmisLocation())); + } + + @TestRail(section = {"cmis-api"}, executionType=ExecutionType.REGRESSION, + description = "Verify that manager is not able to create document with empty name") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisInvalidArgumentException.class) + public void siteManagerCannotCreateDocumentWithEmptyName() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(new FileModel("", FileType.TEXT_PLAIN)); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is able to create file with Major versioning state") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerShouldCreateDocumentWithMajorVersioningState() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile, VersioningState.MAJOR).and().assertThat().existsInRepo() + .and().assertThat().documentHasVersion(1.0) + .assertThat().isLatestMajorVersion(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is able to create file with Minor versioning state") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerShouldCreateDocumentWithMinorVersioningState() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.HTML); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile, VersioningState.MINOR).and().assertThat().existsInRepo() + .and().assertThat().documentHasVersion(0.1) + .assertThat().isNotLatestMajorVersion(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is able to create file with CHECKEDOUT versioning state") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerShouldCreateDocumentWithCheckedOutVersioningState() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile, VersioningState.CHECKEDOUT).and().assertThat().existsInRepo() + .and().assertThat().documentIsCheckedOut() + .assertThat().isPrivateWorkingCopy(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site contributor is able to create file") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void contributorShouldCreateDocument() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site collaborator is able to create file") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void collaboratorShouldCreateDocument() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site consumer is not able to create file") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void consumerShouldNotCreateDocument() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .usingSite(testSite) + .createFile(testFile); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify non invited user is not able to create file") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void nonInvitedUserShouldNotCreateDocumentInSite() throws Exception + { + UserModel outsider = dataUser.createRandomTestUser(); + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(outsider) + .usingSite(testSite) + .createFile(testFile); + } + + @Bug(id="REPO-4301") + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify disabled user is not able to create file in Shared folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void disabledUserShouldNotCreateDocument() throws Exception + { + UserModel disabled = dataUser.createRandomTestUser(); + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(disabled); + dataUser.usingAdmin().disableUser(disabled); + cmisApi.usingShared() + .createFile(testFile); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify non invited user is not able to create file in private site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void nonInvitedUserShouldNotCreateDocumentInPrivateSite() throws Exception + { + SiteModel privateSite = dataSite.usingUser(testUser).createPrivateRandomSite(); + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .usingSite(privateSite) + .createFile(testFile); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is not able to create document with no properties") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=IllegalArgumentException.class, + expectedExceptionsMessageRegExp="Properties must not be empty!*") + public void siteManagerCannotCreateDocumentWithNoProperties() throws Exception + { + Map properties = new HashMap(); + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile, properties, VersioningState.MAJOR); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is able to create file with a name containing multi byte characters.") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void managerIsAbleToCreateFileWithMultiByteName() throws Exception + { + testFile = new FileModel(RandomData.getRandomAlphanumeric() + "\ufeff\u6768\u6728\u91d1"); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType=ExecutionType.REGRESSION, + description = "Verify that manager user is not able to create document at document location") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=InvalidCmisObjectException.class) + public void siteManagerCannotCreateDocumentInDocumentLocation() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo() + .then().usingResource(testFile) + .createFile(testFile); + } + +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/CreateFolderTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/CreateFolderTests.java new file mode 100644 index 0000000000..8674321502 --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/CreateFolderTests.java @@ -0,0 +1,232 @@ +package org.alfresco.cmis; + +import java.util.HashMap; +import java.util.Map; + +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.data.RandomData; +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.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.PropertyIds; +import org.apache.chemistry.opencmis.commons.enums.BaseTypeId; +import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisContentAlreadyExistsException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 9/26/2016 + */ +public class CreateFolderTests extends CmisTest +{ + UserModel testUser; + SiteModel testSite; + FolderModel testFolder; + private DataUser.ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + testUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(testUser).createPublicRandomSite(); + usersWithRoles = dataUser.usingUser(testUser) + .addUsersWithRolesToSite(testSite, UserRole.SiteContributor, UserRole.SiteCollaborator, UserRole.SiteConsumer); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify admin user is able to create folder in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void adminShouldCreateFolder() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(dataUser.getAdminUser()).usingSite(testSite) + .createFolder(testFolder).and().assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify site manager is able to create folder in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void siteManagerShouldCreateFolder() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(testFolder).and().assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify inexistent user can't create folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisUnauthorizedException.class) + public void inexistentUserShouldNotCreateFolder() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(new UserModel("random user", "random password")).usingSite(testSite).createFolder(testFolder); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify a folder with same name can't be created in the same location") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisContentAlreadyExistsException.class, + expectedExceptionsMessageRegExp="An object with this name already exists.*") + public void shouldNotCreateFolderWithSameName() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(testUser).usingSite(testSite).createFolder(testFolder).and().assertThat().existsInRepo(); + cmisApi.authenticateUser(testUser).usingSite(testSite).createFolder(testFolder); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify a folder can't be created at invalid path") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisObjectNotFoundException.class, + expectedExceptionsMessageRegExp="Object not found.*") + public void shouldNotCreateFolderAtInvalidPath() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(testUser).usingSite(new SiteModel("inexitentSite")).createFolder(testFolder); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is not able to create folder with invalid base type id with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisObjectNotFoundException.class) + public void siteManagerCannotCreateFolderWithInvalidObjectTypeId() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(testFolder, "cmis:fakeType"); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is not able to create folder with cmis:document base type id with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisConstraintException.class) + public void siteManagerCannotCreateFolderWithDocumentTypeId() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(testFolder, BaseTypeId.CMIS_DOCUMENT.value()); + } + + @TestRail(section = {"cmis-api"}, executionType=ExecutionType.REGRESSION, + description = "Verify that admin user is not able to create folder with invalid characters in name") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisConstraintException.class) + public void adminCannotCreateFolderWithInvalidCharacters() throws Exception + { + testFolder = new FolderModel("/.:?|\\`\\.txt"); + cmisApi.authenticateUser(dataUser.getAdminUser()) + .usingResource(FolderModel.getSharedFolderModel()) + .createFolder(testFolder); + } + + @TestRail(section = {"cmis-api"}, executionType=ExecutionType.REGRESSION, + description = "Verify that admin user is not able to create folder with empty name") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisInvalidArgumentException.class, + expectedExceptionsMessageRegExp="Property cmis:name must be set!*") + public void adminCannotCreateFolderWithEmptyName() throws Exception + { + cmisApi.authenticateUser(dataUser.getAdminUser()) + .usingResource(FolderModel.getSharedFolderModel()) + .createFolder(new FolderModel("")); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is not able to create folder with empty properties") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=IllegalArgumentException.class, + expectedExceptionsMessageRegExp="Properties must not be empty!*") + public void siteManagerCannotCreateFolderWithNoParamenters() throws Exception + { + Map properties = new HashMap(); + testFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(testUser) + .usingSite(testSite) + .createFolder(testFolder, properties); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is not able to create folder with properties specific for documents") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=IllegalArgumentException.class, + expectedExceptionsMessageRegExp="Property 'cmis:isLatestMajorVersion' is not valid for this type or one of the secondary types!*") + public void siteManagerCannotCreateFolderWithDocumentParamenters() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + Map properties = new HashMap(); + properties.put(PropertyIds.OBJECT_TYPE_ID, BaseTypeId.CMIS_FOLDER.value()); + properties.put(PropertyIds.NAME, testFolder.getName()); + properties.put(PropertyIds.IS_LATEST_MAJOR_VERSION, "true"); + cmisApi.authenticateUser(testUser) + .usingSite(testSite) + .createFolder(testFolder, properties); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify contributor is able to create folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void contributorCanCreateFolder() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingSite(testSite) + .createFolder(testFolder).and().assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify collaborator is able to create folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void collaboratorCanCreateFolder() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingSite(testSite) + .createFolder(testFolder).and().assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify consumer is not able to create folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void consumerCannotCreateFolder() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).usingSite(testSite) + .createFolder(testFolder); + } + + @Bug(id="REPO-4301") + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify disabled user is not able to create folder in Shared location") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void disabledUserShouldNotCreateFolder() throws Exception + { + UserModel disabled = dataUser.createRandomTestUser(); + testFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(disabled); + dataUser.usingAdmin().disableUser(disabled); + cmisApi.usingShared() + .createFolder(testFolder); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify non invited user is not able to create folder in private site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void nonInvitedUserShouldNotCreateDocumentInPrivateSite() throws Exception + { + SiteModel privateSite = dataSite.usingUser(testUser).createPrivateRandomSite(); + testFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .usingSite(privateSite) + .createFolder(testFolder); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is able to create folder with a name containing multi byte characters.") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void managerIsAbleToCreateFolderWithMultiByteName() throws Exception + { + testFolder = new FolderModel(RandomData.getRandomAlphanumeric() + "\ufeff\u6768\u6728\u91d1"); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(testFolder).and().assertThat().existsInRepo(); + } +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/DataListsTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/DataListsTests.java new file mode 100644 index 0000000000..fec6d4b7fc --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/DataListsTests.java @@ -0,0 +1,590 @@ +package org.alfresco.cmis; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.data.RandomData; +import org.alfresco.utility.model.DataListItemModel; +import org.alfresco.utility.model.DataListModel; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.PropertyIds; +import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisContentAlreadyExistsException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class DataListsTests extends CmisTest +{ + UserModel manager; + SiteModel testSite; + DataListModel dataListModel; + private DataUser.ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + manager = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(manager).createPublicRandomSite(); + usersWithRoles = dataUser.usingUser(manager) + .addUsersWithRolesToSite(testSite, UserRole.SiteContributor, UserRole.SiteCollaborator, UserRole.SiteConsumer); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify admin user is able to create data list type contact") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS, TestGroup.REQUIRE_SHARE}) + public void adminCanCreateContactDataList() throws Exception + { + dataListModel = DataListModel.getRandomDataListModel("dl:contact"); + cmisApi.authenticateUser(dataUser.getAdminUser()).usingShared() + .createDataList(dataListModel).and().assertThat().existsInRepo() + .assertThat().objectTypeIdIs("F:dl:dataList"); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify manager user is able to create data list type contact") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS, TestGroup.REQUIRE_SHARE}) + public void managerCanCreateContactDataList() throws Exception + { + dataListModel = DataListModel.getRandomDataListModel("dl:contact"); + cmisApi.authenticateUser(manager).usingSite(testSite) + .createDataList(dataListModel).and().assertThat().existsInRepo() + .assertThat().objectTypeIdIs("F:dl:dataList") + .and().assertThat().objectHasProperty("dl:dataListItemType", "dl:contact"); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify collaborator user is able to create data list type contact") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS, TestGroup.REQUIRE_SHARE}) + public void collaboratorCanCreatedIssueDataList() throws Exception + { + dataListModel = DataListModel.getRandomDataListModel("dl:issue"); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingSite(testSite) + .createDataList(dataListModel).and().assertThat().existsInRepo() + .assertThat().objectTypeIdIs("F:dl:dataList") + .and().assertThat().objectHasProperty("dl:dataListItemType", "dl:issue"); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify contributor user is able to create data list type contact") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS, TestGroup.REQUIRE_SHARE}) + public void contributorCanCreateEventAgendaDataList() throws Exception + { + dataListModel = DataListModel.getRandomDataListModel("dl:eventAgenda"); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingSite(testSite) + .createDataList(dataListModel).and().assertThat().existsInRepo() + .assertThat().objectTypeIdIs("F:dl:dataList") + .assertThat().objectHasProperty("dl:dataListItemType", "dl:eventAgenda"); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify consumer user is able to create data list type contact") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS, TestGroup.REQUIRE_SHARE}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void consumerCannotCreateEventAgendaDataList() throws Exception + { + dataListModel = DataListModel.getRandomDataListModel("dl:eventAgenda"); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).usingSite(testSite) + .createDataList(dataListModel).and().assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify manager user is able to create data list type contact") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS, TestGroup.REQUIRE_SHARE}) + public void managerCanCreateContactDataListItem() throws Exception + { + Map itemProperties = new HashMap(); + itemProperties.put(PropertyIds.OBJECT_TYPE_ID, "D:dl:contact"); + itemProperties.put(PropertyIds.NAME, RandomData.getRandomAlphanumeric()); + itemProperties.put("dl:contactFirstName", "John"); + itemProperties.put("dl:contactLastName", "Snow"); + itemProperties.put("dl:contactEmail", "john.snow@stark.com"); + itemProperties.put("dl:contactCompany", "GOT"); + itemProperties.put("dl:contactJobTitle", "king"); + itemProperties.put("dl:contactPhoneOffice", "1234"); + itemProperties.put("dl:contactPhoneMobile", "5678"); + itemProperties.put("dl:contactNotes", "you know nothing john snow"); + + DataListItemModel contactItem = new DataListItemModel(itemProperties); + dataListModel = DataListModel.getRandomDataListModel("dl:contact"); + cmisApi.authenticateUser(manager).usingSite(testSite) + .then().createDataList(dataListModel).and().assertThat().existsInRepo() + .and().assertThat().objectHasProperty("dl:dataListItemType", "dl:contact") + .then().usingResource(dataListModel) + .createDataListItem(contactItem).assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify manager user is able to create data list type contact") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS, TestGroup.REQUIRE_SHARE}) + public void managerCanCreateIssueListItem() throws Exception + { + UserModel assignUser = dataUser.createRandomTestUser(); + FileModel attachDoc1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + FileModel attachDoc2 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + + Map itemProperties = new HashMap(); + itemProperties.put(PropertyIds.OBJECT_TYPE_ID, "D:dl:issue"); + itemProperties.put(PropertyIds.NAME, RandomData.getRandomAlphanumeric()); + itemProperties.put("dl:issueID", RandomData.getRandomAlphanumeric()); + itemProperties.put("dl:issueStatus", "Not Started"); + itemProperties.put("dl:issuePriority", "Low"); + itemProperties.put("dl:issueDueDate", new Date()); + itemProperties.put("dl:issueComments", "comment"); + + DataListItemModel issueItem = new DataListItemModel(itemProperties); + + dataListModel = DataListModel.getRandomDataListModel("dl:issue"); + cmisApi.authenticateUser(manager).usingSite(testSite).createFile(attachDoc1).createFile(attachDoc2) + .then().createDataList(dataListModel).and().assertThat().existsInRepo() + .and().assertThat().objectHasProperty("dl:dataListItemType", "dl:issue") + .then().usingResource(dataListModel) + .createDataListItem(issueItem).assertThat().existsInRepo() + .then().attachDocument(attachDoc1) + .attachDocument(attachDoc2) + .assertThat().objectHasRelationshipWith(attachDoc1) + .assertThat().objectHasRelationshipWith(attachDoc2) + .then().assignToUser(assignUser, "R:dl:issueAssignedTo") + .assertThat().userIsAssigned(assignUser); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify manager user is able to create data list type contact") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS, TestGroup.REQUIRE_SHARE}, expectedExceptions=CmisObjectNotFoundException.class, + expectedExceptionsMessageRegExp="Type 'D:dl:invalidItem' is unknown!*") + public void managerCannotCreateInvalidDataListItem() throws Exception + { + Map itemProperties = new HashMap(); + itemProperties.put(PropertyIds.OBJECT_TYPE_ID, "D:dl:invalidItem"); + itemProperties.put(PropertyIds.NAME, RandomData.getRandomAlphanumeric()); + + DataListItemModel contactItem = new DataListItemModel(itemProperties); + dataListModel = DataListModel.getRandomDataListModel("dl:contact"); + cmisApi.authenticateUser(manager).usingSite(testSite) + .then().createDataList(dataListModel).and().assertThat().existsInRepo() + .and().assertThat().objectHasProperty("dl:dataListItemType", "dl:contact") + .then().usingResource(dataListModel) + .createDataListItem(contactItem).assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify collaborator user is able to add issue item type for data list created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS, TestGroup.REQUIRE_SHARE}) + public void collaboratorCanAddIssueItem() throws Exception + { + UserModel assignUser = dataUser.createRandomTestUser(); + FileModel attachDoc1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + FileModel attachDoc2 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + + Map itemProperties = new HashMap(); + itemProperties.put(PropertyIds.OBJECT_TYPE_ID, "D:dl:issue"); + itemProperties.put(PropertyIds.NAME, RandomData.getRandomAlphanumeric()); + itemProperties.put("dl:issueID", RandomData.getRandomAlphanumeric()); + itemProperties.put("dl:issueDueDate", new Date()); + itemProperties.put("dl:issueComments", "comment"); + DataListItemModel issueItem = new DataListItemModel(itemProperties); + dataListModel = DataListModel.getRandomDataListModel("dl:issue"); + + cmisApi.authenticateUser(manager).usingSite(testSite).createFile(attachDoc1).createFile(attachDoc2) + .then().createDataList(dataListModel).and().assertThat().existsInRepo() + .and().assertThat().objectHasProperty("dl:dataListItemType", "dl:issue") + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .then().usingResource(dataListModel) + .createDataListItem(issueItem).assertThat().existsInRepo() + .then().attachDocument(attachDoc1) + .attachDocument(attachDoc2) + .assertThat().objectHasRelationshipWith(attachDoc1) + .assertThat().objectHasRelationshipWith(attachDoc2) + .then().assignToUser(assignUser, "R:dl:issueAssignedTo") + .assertThat().userIsAssigned(assignUser); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify contributor user is able to add issue item type for data list created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS, TestGroup.REQUIRE_SHARE}) + public void contributorCanAddIssueItem() throws Exception + { + UserModel assignUser = dataUser.createRandomTestUser(); + FileModel attachDoc1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + FileModel attachDoc2 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + + Map itemProperties = new HashMap(); + itemProperties.put(PropertyIds.OBJECT_TYPE_ID, "D:dl:issue"); + itemProperties.put(PropertyIds.NAME, RandomData.getRandomAlphanumeric()); + itemProperties.put("dl:issueID", RandomData.getRandomAlphanumeric()); + itemProperties.put("dl:issueStatus", "Not Started"); + itemProperties.put("dl:issuePriority", "Low"); + DataListItemModel issueItem = new DataListItemModel(itemProperties); + dataListModel = DataListModel.getRandomDataListModel("dl:issue"); + + cmisApi.authenticateUser(manager).usingSite(testSite).createFile(attachDoc1).createFile(attachDoc2) + .then().createDataList(dataListModel).and().assertThat().existsInRepo() + .and().assertThat().objectHasProperty("dl:dataListItemType", "dl:issue") + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .then().usingResource(dataListModel) + .createDataListItem(issueItem).assertThat().existsInRepo() + .then().attachDocument(attachDoc1) + .attachDocument(attachDoc2) + .assertThat().objectHasRelationshipWith(attachDoc1) + .assertThat().objectHasRelationshipWith(attachDoc2) + .then().assignToUser(assignUser, "R:dl:issueAssignedTo") + .assertThat().userIsAssigned(assignUser); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify consumer user is able to add issue item type for data list created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS, TestGroup.REQUIRE_SHARE}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void consumerCannotAddIssueItem() throws Exception + { + Map itemProperties = new HashMap(); + itemProperties.put(PropertyIds.OBJECT_TYPE_ID, "D:dl:issue"); + itemProperties.put(PropertyIds.NAME, RandomData.getRandomAlphanumeric()); + DataListItemModel issueItem = new DataListItemModel(itemProperties); + dataListModel = DataListModel.getRandomDataListModel("dl:issue"); + + cmisApi.authenticateUser(manager).usingSite(testSite) + .then().createDataList(dataListModel).and().assertThat().existsInRepo() + .and().assertThat().objectHasProperty("dl:dataListItemType", "dl:issue") + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .then().usingResource(dataListModel) + .createDataListItem(issueItem).assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify non invited user is able to add issue item type for data list created by manager in private site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS, TestGroup.REQUIRE_SHARE}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void nonInvitedUserCannotAddIssueItemInPrivateSite() throws Exception + { + SiteModel privateSite = dataSite.usingUser(manager).createPrivateRandomSite(); + + Map itemProperties = new HashMap(); + itemProperties.put(PropertyIds.OBJECT_TYPE_ID, "D:dl:issue"); + itemProperties.put(PropertyIds.NAME, RandomData.getRandomAlphanumeric()); + DataListItemModel issueItem = new DataListItemModel(itemProperties); + dataListModel = DataListModel.getRandomDataListModel("dl:issue"); + + cmisApi.authenticateUser(manager).usingSite(privateSite) + .then().createDataList(dataListModel).and().assertThat().existsInRepo() + .and().assertThat().objectHasProperty("dl:dataListItemType", "dl:issue") + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .usingResource(dataListModel) + .createDataListItem(issueItem).assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify manager user is not able to create data list item with invalid status") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS, TestGroup.REQUIRE_SHARE}, expectedExceptions=CmisConstraintException.class) + public void managerCannotCreateTaskItemWithInvalidStatusValue() throws Exception + { + Map itemProperties = new HashMap(); + itemProperties.put(PropertyIds.OBJECT_TYPE_ID, "D:dl:simpletask"); + itemProperties.put(PropertyIds.NAME, RandomData.getRandomAlphanumeric()); + itemProperties.put("dl:simpletaskStatus", "invalid-status"); + + DataListItemModel issueItem = new DataListItemModel(itemProperties); + + dataListModel = DataListModel.getRandomDataListModel("dl:simpletask"); + cmisApi.authenticateUser(manager).usingSite(testSite) + .then().createDataList(dataListModel).and().assertThat().existsInRepo() + .then().usingResource(dataListModel) + .createDataListItem(issueItem).assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify manager user is not able to create data list item with invalid status") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS, TestGroup.REQUIRE_SHARE}, expectedExceptions=IllegalArgumentException.class, + expectedExceptionsMessageRegExp="Property 'dl:fakePriority' is not valid for this type or one of the secondary types!*") + public void managerCannotCreateTaskItemWithInvalidParameter() throws Exception + { + Map itemProperties = new HashMap(); + itemProperties.put(PropertyIds.OBJECT_TYPE_ID, "D:dl:simpletask"); + itemProperties.put(PropertyIds.NAME, RandomData.getRandomAlphanumeric()); + itemProperties.put("dl:fakePriority", "High"); + + DataListItemModel issueItem = new DataListItemModel(itemProperties); + + dataListModel = DataListModel.getRandomDataListModel("dl:simpletask"); + cmisApi.authenticateUser(manager).usingSite(testSite) + .then().createDataList(dataListModel).and().assertThat().existsInRepo() + .then().usingResource(dataListModel) + .createDataListItem(issueItem).assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify manager user is not able to assign issue item to deleted user") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS, TestGroup.REQUIRE_SHARE}, expectedExceptions=CmisInvalidArgumentException.class, + expectedExceptionsMessageRegExp="Property cmis:targetId must be set!*") + public void managerCannotAssignIssueItemToDeletedUser() throws Exception + { + UserModel assignUser = dataUser.createRandomTestUser(); + + Map itemProperties = new HashMap(); + itemProperties.put(PropertyIds.OBJECT_TYPE_ID, "D:dl:issue"); + itemProperties.put(PropertyIds.NAME, RandomData.getRandomAlphanumeric()); + itemProperties.put("dl:issueID", RandomData.getRandomAlphanumeric()); + itemProperties.put("dl:issueDueDate", new Date()); + itemProperties.put("dl:issueComments", "comment"); + DataListItemModel issueItem = new DataListItemModel(itemProperties); + dataListModel = DataListModel.getRandomDataListModel("dl:issue"); + + cmisApi.authenticateUser(manager).usingSite(testSite) + .then().createDataList(dataListModel).and().assertThat().existsInRepo() + .and().assertThat().objectHasProperty("dl:dataListItemType", "dl:issue") + .then().usingResource(dataListModel) + .createDataListItem(issueItem).assertThat().existsInRepo(); + dataUser.usingAdmin().deleteUser(assignUser); + cmisApi.assignToUser(assignUser, "R:dl:issueAssignedTo").assertThat().userIsAssigned(assignUser); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify manager user is not able to assign issue item twice to same user") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS, TestGroup.REQUIRE_SHARE}, expectedExceptions=CmisRuntimeException.class) + public void managerCannotAssignIssueItemTwice() throws Exception + { + UserModel assignUser = dataUser.createRandomTestUser(); + + Map itemProperties = new HashMap(); + itemProperties.put(PropertyIds.OBJECT_TYPE_ID, "D:dl:issue"); + itemProperties.put(PropertyIds.NAME, RandomData.getRandomAlphanumeric()); + itemProperties.put("dl:issueID", RandomData.getRandomAlphanumeric()); + itemProperties.put("dl:issueDueDate", new Date()); + itemProperties.put("dl:issueComments", "comment"); + DataListItemModel issueItem = new DataListItemModel(itemProperties); + dataListModel = DataListModel.getRandomDataListModel("dl:issue"); + + cmisApi.authenticateUser(manager).usingSite(testSite) + .then().createDataList(dataListModel).and().assertThat().existsInRepo() + .and().assertThat().objectHasProperty("dl:dataListItemType", "dl:issue") + .then().usingResource(dataListModel) + .createDataListItem(issueItem).assertThat().existsInRepo(); + cmisApi.assignToUser(assignUser, "R:dl:issueAssignedTo").assertThat().userIsAssigned(assignUser) + .then().assignToUser(assignUser, "R:dl:issueAssignedTo"); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify manager user is able to assign issue item for 2 users") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS, TestGroup.REQUIRE_SHARE}) + public void managerCanAssignIssueItemForTwoUsers() throws Exception + { + UserModel assignUser = dataUser.createRandomTestUser(); + UserModel anotherUser = dataUser.createRandomTestUser(); + + Map itemProperties = new HashMap(); + itemProperties.put(PropertyIds.OBJECT_TYPE_ID, "D:dl:issue"); + itemProperties.put(PropertyIds.NAME, RandomData.getRandomAlphanumeric()); + itemProperties.put("dl:issueID", RandomData.getRandomAlphanumeric()); + itemProperties.put("dl:issueDueDate", new Date()); + itemProperties.put("dl:issueComments", "comment"); + DataListItemModel issueItem = new DataListItemModel(itemProperties); + dataListModel = DataListModel.getRandomDataListModel("dl:issue"); + + cmisApi.authenticateUser(manager).usingSite(testSite) + .then().createDataList(dataListModel).and().assertThat().existsInRepo() + .and().assertThat().objectHasProperty("dl:dataListItemType", "dl:issue") + .then().usingResource(dataListModel) + .createDataListItem(issueItem).assertThat().existsInRepo(); + cmisApi.assignToUser(assignUser, "R:dl:issueAssignedTo").assertThat().userIsAssigned(assignUser) + .then().assignToUser(anotherUser, "R:dl:issueAssignedTo"); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify manager user is able to delete contact data list with no items") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS, TestGroup.REQUIRE_SHARE}) + public void managerCanDeleteContactDataList() throws Exception + { + dataListModel = DataListModel.getRandomDataListModel("dl:contact"); + cmisApi.authenticateUser(manager).usingSite(testSite) + .createDataList(dataListModel).and().assertThat().existsInRepo() + .and().assertThat().objectHasProperty("dl:dataListItemType", "dl:contact") + .then().delete().assertThat().doesNotExistInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify manager user is not able to create contact data list items with same name twice") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS, TestGroup.REQUIRE_SHARE}, expectedExceptions=CmisContentAlreadyExistsException.class) + public void managerCannotCreateContactDataListWithSameNameTwice() throws Exception + { + Map itemProperties = new HashMap(); + itemProperties.put(PropertyIds.OBJECT_TYPE_ID, "D:dl:contact"); + itemProperties.put(PropertyIds.NAME, RandomData.getRandomAlphanumeric()); + itemProperties.put("dl:contactFirstName", "John"); + DataListItemModel contactItem = new DataListItemModel(itemProperties); + + dataListModel = DataListModel.getRandomDataListModel("dl:contact"); + cmisApi.authenticateUser(manager).usingSite(testSite) + .then().createDataList(dataListModel).and().assertThat().existsInRepo() + .and().assertThat().objectHasProperty("dl:dataListItemType", "dl:contact") + .then().usingResource(dataListModel) + .createDataListItem(contactItem).assertThat().existsInRepo() + .then().usingResource(dataListModel) + .then().createDataListItem(contactItem); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify manager user is not able to create contact data list items at item location") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS, TestGroup.REQUIRE_SHARE}, expectedExceptions=CmisInvalidArgumentException.class, + expectedExceptionsMessageRegExp="Parent folder is not a folder!*") + public void managerCannotCreateContactDataListItemInsideItem() throws Exception + { + Map itemProperties = new HashMap(); + itemProperties.put(PropertyIds.OBJECT_TYPE_ID, "D:dl:contact"); + itemProperties.put(PropertyIds.NAME, RandomData.getRandomAlphanumeric()); + itemProperties.put("dl:contactFirstName", "John"); + DataListItemModel contactItem = new DataListItemModel(itemProperties); + + dataListModel = DataListModel.getRandomDataListModel("dl:contact"); + cmisApi.authenticateUser(manager).usingSite(testSite) + .then().createDataList(dataListModel).and().assertThat().existsInRepo() + .and().assertThat().objectHasProperty("dl:dataListItemType", "dl:contact") + .then().usingResource(dataListModel) + .createDataListItem(contactItem).assertThat().existsInRepo() + .then().usingResource(contactItem) + .createDataListItem(contactItem); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify manager user is not able to simple delete contact data list with items") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS, TestGroup.REQUIRE_SHARE}, expectedExceptions=CmisConstraintException.class, + expectedExceptionsMessageRegExp="Could not delete folder with at least one child!*") + public void managerCannotSimpleDeleteContactDataListWithItems() throws Exception + { + Map itemProperties = new HashMap(); + itemProperties.put(PropertyIds.OBJECT_TYPE_ID, "D:dl:contact"); + itemProperties.put(PropertyIds.NAME, RandomData.getRandomAlphanumeric()); + itemProperties.put("dl:contactFirstName", "John"); + DataListItemModel contactItem = new DataListItemModel(itemProperties); + + dataListModel = DataListModel.getRandomDataListModel("dl:contact"); + cmisApi.authenticateUser(manager).usingSite(testSite) + .then().createDataList(dataListModel).and().assertThat().existsInRepo() + .then().usingResource(dataListModel) + .createDataListItem(contactItem).assertThat().existsInRepo() + .then().usingResource(dataListModel).delete(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify manager user is able to delete(delete tree) contact data list with items in it") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS, TestGroup.REQUIRE_SHARE}) + public void managerCanDeleteTreeContactDataListWithItems() throws Exception + { + Map itemProperties = new HashMap(); + itemProperties.put(PropertyIds.OBJECT_TYPE_ID, "D:dl:contact"); + itemProperties.put(PropertyIds.NAME, RandomData.getRandomAlphanumeric()); + itemProperties.put("dl:contactFirstName", "John"); + DataListItemModel contactItem = new DataListItemModel(itemProperties); + + dataListModel = DataListModel.getRandomDataListModel("dl:contact"); + cmisApi.authenticateUser(manager).usingSite(testSite) + .then().createDataList(dataListModel).and().assertThat().existsInRepo() + .then().usingResource(dataListModel) + .createDataListItem(contactItem).assertThat().existsInRepo() + .then().usingResource(dataListModel) + .deleteFolderTree().assertThat().doesNotExistInRepo() + .and().usingResource(contactItem).assertThat().doesNotExistInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify collaborator user is not able to delete(delete tree) contact data list with items in it created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS, TestGroup.REQUIRE_SHARE}) + public void collaboratorCannotDeleteTreeContactDataListWithItems() throws Exception + { + Map itemProperties = new HashMap(); + itemProperties.put(PropertyIds.OBJECT_TYPE_ID, "D:dl:contact"); + itemProperties.put(PropertyIds.NAME, RandomData.getRandomAlphanumeric()); + itemProperties.put("dl:contactFirstName", "John"); + DataListItemModel contactItem = new DataListItemModel(itemProperties); + + dataListModel = DataListModel.getRandomDataListModel("dl:contact"); + cmisApi.authenticateUser(manager).usingSite(testSite) + .then().createDataList(dataListModel).and().assertThat().existsInRepo() + .then().usingResource(dataListModel) + .createDataListItem(contactItem).assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .usingResource(dataListModel) + .deleteFolderTree().assertThat() + .hasFailedDeletedObject(dataListModel.getNodeRef()) + .and().assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify contributor user is not able to delete(delete tree) contact data list with items in it created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS, TestGroup.REQUIRE_SHARE}) + public void contributorCannotDeleteTreeContactDataListWithItems() throws Exception + { + Map itemProperties = new HashMap(); + itemProperties.put(PropertyIds.OBJECT_TYPE_ID, "D:dl:contact"); + itemProperties.put(PropertyIds.NAME, RandomData.getRandomAlphanumeric()); + itemProperties.put("dl:contactFirstName", "John"); + DataListItemModel contactItem = new DataListItemModel(itemProperties); + + dataListModel = DataListModel.getRandomDataListModel("dl:contact"); + cmisApi.authenticateUser(manager).usingSite(testSite) + .then().createDataList(dataListModel).and().assertThat().existsInRepo() + .then().usingResource(dataListModel) + .createDataListItem(contactItem).assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .usingResource(dataListModel) + .deleteFolderTree().assertThat() + .hasFailedDeletedObject(dataListModel.getNodeRef()) + .and().assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify consumer user is not able to delete(delete tree) contact data list with items in it created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS, TestGroup.REQUIRE_SHARE}) + public void consumerCannotDeleteTreeContactDataListWithItems() throws Exception + { + Map itemProperties = new HashMap(); + itemProperties.put(PropertyIds.OBJECT_TYPE_ID, "D:dl:contact"); + itemProperties.put(PropertyIds.NAME, RandomData.getRandomAlphanumeric()); + itemProperties.put("dl:contactFirstName", "John"); + DataListItemModel contactItem = new DataListItemModel(itemProperties); + + dataListModel = DataListModel.getRandomDataListModel("dl:contact"); + cmisApi.authenticateUser(manager).usingSite(testSite) + .then().createDataList(dataListModel).and().assertThat().existsInRepo() + .then().usingResource(dataListModel) + .createDataListItem(contactItem).assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .usingResource(dataListModel) + .deleteFolderTree().assertThat() + .hasFailedDeletedObject(dataListModel.getNodeRef()) + .and().assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify non invited user is not able to delete(delete tree) contact data list with items in it created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS, TestGroup.REQUIRE_SHARE}) + public void nonInvitedUserCannotDeleteTreeContactDataListWithItems() throws Exception + { + UserModel nonInvited = dataUser.createRandomTestUser(); + Map itemProperties = new HashMap(); + itemProperties.put(PropertyIds.OBJECT_TYPE_ID, "D:dl:contact"); + itemProperties.put(PropertyIds.NAME, RandomData.getRandomAlphanumeric()); + itemProperties.put("dl:contactFirstName", "John"); + DataListItemModel contactItem = new DataListItemModel(itemProperties); + + dataListModel = DataListModel.getRandomDataListModel("dl:contact"); + cmisApi.authenticateUser(manager).usingSite(testSite) + .then().createDataList(dataListModel).and().assertThat().existsInRepo() + .then().usingResource(dataListModel) + .createDataListItem(contactItem).assertThat().existsInRepo() + .then().authenticateUser(nonInvited) + .usingResource(dataListModel) + .deleteFolderTree().assertThat() + .hasFailedDeletedObject(dataListModel.getNodeRef()) + .and().assertThat().existsInRepo(); + } +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/DeleteAllVersionsTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/DeleteAllVersionsTests.java new file mode 100644 index 0000000000..8beaee73bb --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/DeleteAllVersionsTests.java @@ -0,0 +1,325 @@ +package org.alfresco.cmis; + +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.RandomData; +import org.alfresco.utility.model.*; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 9/26/2016. + */ +public class DeleteAllVersionsTests extends CmisTest +{ + UserModel testUser; + UserModel consumerUser; + UserModel collaboratorUser; + UserModel contributorUser; + UserModel unauthorizedUser; + SiteModel testSite; + FileModel testFile; + FolderModel testFolder; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + testUser = dataUser.createRandomTestUser(); + consumerUser = dataUser.createRandomTestUser(); + collaboratorUser = dataUser.createRandomTestUser(); + contributorUser = dataUser.createRandomTestUser(); + unauthorizedUser = dataUser.createRandomTestUser(); + + testSite = dataSite.usingUser(testUser).createPublicRandomSite(); + + dataUser.addUserToSite(consumerUser, testSite, UserRole.SiteConsumer); + dataUser.addUserToSite(collaboratorUser, testSite, UserRole.SiteCollaborator); + dataUser.addUserToSite(contributorUser, testSite, UserRole.SiteContributor); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify site manager is able to delete all document versions in DocumentLibrary with CMIS") + @Test(groups = {TestGroup.SANITY, TestGroup.CMIS }) + public void siteManagerDeletesAllDocumentVersions() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).and().update(testFile.getName()) + .then().deleteAllVersions(true).and().assertThat().doesNotExistInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify site manager is able to delete only latest document version in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void siteManagerDeletesLatestDocumentVersion() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).and().update(testFile.getName()) + .then().deleteAllVersions(false).and().assertThat().documentHasVersion(1.0); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is NOT able to delete all versions of inexistent file with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = CmisObjectNotFoundException.class) + public void siteManagerCannotDeleteAllVersionsOfInexistentFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD); + testFile.setCmisLocation("/fake-folder/inexistentFile.txt"); + cmisApi.authenticateUser(testUser).usingSite(testSite).usingResource(testFile).deleteAllVersions(true); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is able to delete PWC file version of a file with multiple versions with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanDeletePWCFileWithDeleteAllVersionsTrue() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD); + cmisApi.authenticateUser(testUser).usingSite(testSite).createFile(testFile) + .usingResource(testFile).update("content 1") + .assertThat().documentHasVersion(1.1) + .usingResource(testFile).update("content 2") + .assertThat().documentHasVersion(1.2) + .usingResource(testFile).checkOut() + .assertThat().documentIsCheckedOut() + .usingPWCDocument().deleteAllVersions(true) + .assertThat().doesNotExistInRepo() + .usingResource(testFile).assertThat().existsInRepo().and().assertThat().documentHasVersion(1.2); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is able to delete PWC file version of a file with multiple versions set to false with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanDeletePWCFileWithDeleteAllVersionsFalse() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD); + cmisApi.authenticateUser(testUser).usingSite(testSite).createFile(testFile) + .then().update("content 1") + .assertThat().documentHasVersion(1.1) + .then().update("content 2") + .assertThat().documentHasVersion(1.2) + .then().checkOut().refreshResource() + .assertThat().documentIsCheckedOut() + .usingPWCDocument().deleteAllVersions(false) + .assertThat().doesNotExistInRepo() + .usingResource(testFile).assertThat().existsInRepo().and().assertThat().documentHasVersion(1.2); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is NOT able to delete file original multiple version which is checked out with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = CmisConstraintException.class, expectedExceptionsMessageRegExp = "^Could not delete/cancel checkout on the original checked out document$") + public void siteManagerCannotDeleteOriginalFileMultipleVersionWhenCheckedout() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD); + cmisApi.authenticateUser(testUser).usingSite(testSite).createFile(testFile) + .then().update("content 1") + .assertThat().documentHasVersion(1.1) + .then().update("content 2") + .assertThat().documentHasVersion(1.2) + .refreshResource().then().checkOut() + .assertThat().documentIsCheckedOut(); + cmisApi.usingResource(testFile).deleteAllVersions(true); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify unauthorized user is NOT able to delete a checked out document") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisUnauthorizedException.class, CmisPermissionDeniedException.class}) + public void unauthorizedUserCannotDeletePWCDocument() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).then().update("content 1") + .and().checkOut().assertThat().documentIsCheckedOut() + .when().authenticateUser(unauthorizedUser) + .usingResource(testFile).usingPWCDocument().deleteAllVersions(true); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager can delete object Document") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanDeleteDocument() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite).createFile(testFile).usingResource(testFile).update("content 1") + .usingResource(testFile).deleteAllVersions(true) + .assertThat().doesNotExistInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager can delete object Folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanDeleteFolder() throws Exception + { + testFolder = new FolderModel(RandomData.getRandomName("Folder")); + cmisApi.authenticateUser(testUser).usingSite(testSite).createFolder(testFolder).usingResource(testFolder) + .deleteAllVersions(true) + .assertThat().doesNotExistInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify contributor can delete object Document created by self") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void contributorCanDeleteDocumentCreatedBySelf() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(contributorUser).usingSite(testSite).createFile(testFile).usingResource(testFile).update("content 1") + .deleteAllVersions(true) + .assertThat().doesNotExistInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify contributor cannot delete object Document created by site manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisUnauthorizedException.class, CmisPermissionDeniedException.class}) + public void contributorCannotDeleteDocumentCreatedByManager() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).then().update("content 1") + .when().authenticateUser(contributorUser).usingResource(testFile).deleteAllVersions(true); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify contributor can delete object Folder created by self") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void contributorCanDeleteFolderCreatedBySelf() throws Exception + { + testFolder = new FolderModel(RandomData.getRandomName("Folder")); + cmisApi.authenticateUser(contributorUser).usingSite(testSite).createFolder(testFolder).usingResource(testFolder) + .deleteAllVersions(true) + .assertThat().doesNotExistInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify contributor cannot delete object Folder created by site manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisUnauthorizedException.class, CmisPermissionDeniedException.class}) + public void contributorCannotDeleteFolderCreatedByManager() throws Exception + { + testFolder = new FolderModel(RandomData.getRandomName("Folder")); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(testFolder).assertThat().existsInRepo() + .when().authenticateUser(contributorUser) + .usingResource(testFolder).deleteAllVersions(true); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify collaborator can delete object Document created by self") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void collaboratorCanDeleteDocumentCreatedBySelf() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(collaboratorUser).usingSite(testSite).createFile(testFile).usingResource(testFile).update("content 1") + .deleteAllVersions(true) + .assertThat().doesNotExistInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify collaborator cannot delete object Document created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisUnauthorizedException.class, CmisPermissionDeniedException.class}) + public void collaboratorCannotDeleteDocumentCreatedByManager() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).then().update("content 1") + .when().authenticateUser(collaboratorUser) + .usingResource(testFile).deleteAllVersions(true); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify collaborator can delete object Folder created by self") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void collaboratorCanDeleteFolderCreatedBySelf() throws Exception + { + testFolder = new FolderModel(RandomData.getRandomName("Folder")); + cmisApi.authenticateUser(collaboratorUser).usingSite(testSite).createFolder(testFolder).usingResource(testFolder) + .deleteAllVersions(true) + .assertThat().doesNotExistInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify collaborator cannot delete object Folder created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisUnauthorizedException.class, CmisPermissionDeniedException.class}) + public void collaboratorCannotDeleteFolderCreatedByManager() throws Exception + { + testFolder = new FolderModel(RandomData.getRandomName("Folder")); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(testFolder).assertThat().existsInRepo() + .then().authenticateUser(collaboratorUser) + .usingResource(testFolder).deleteAllVersions(true); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify consumer cannot delete object Document") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisUnauthorizedException.class, CmisPermissionDeniedException.class}) + public void consumerCannotDeleteDocumentCreated() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).update("content 1") + .when().authenticateUser(consumerUser) + .usingResource(testFile).deleteAllVersions(true); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify consumer cannot delete object Folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisUnauthorizedException.class, CmisPermissionDeniedException.class}) + public void consumerCannotDeleteFolderCreated() throws Exception + { + testFolder = new FolderModel(RandomData.getRandomName("Folder")); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(testFolder).assertThat().existsInRepo() + .then().authenticateUser(consumerUser) + .usingResource(testFolder).deleteAllVersions(true); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify unauthorized user cannot delete Document from private site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisUnauthorizedException.class, CmisPermissionDeniedException.class}) + public void unauthorizedUserCannotDeleteDocumentFromPrivateSite() throws Exception + { + SiteModel privateSite = dataSite.usingUser(testUser).createPrivateRandomSite(); + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(privateSite) + .createFile(testFile).then().update("content 1") + .when().authenticateUser(unauthorizedUser) + .usingResource(testFile).deleteAllVersions(true); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify unauthorized user cannot delete Folder from private site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisUnauthorizedException.class, CmisPermissionDeniedException.class}) + public void unauthorizedUserCannotDeleteFolderFromPrivateSite() throws Exception + { + SiteModel privateSite = dataSite.usingUser(testUser).createPrivateRandomSite(); + testFolder = new FolderModel(RandomData.getRandomName("Folder")); + cmisApi.authenticateUser(testUser).usingSite(privateSite).createFolder(testFolder); + cmisApi.authenticateUser(unauthorizedUser).usingResource(testFolder).deleteAllVersions(true); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify unauthorized user cannot delete Document from moderated site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisUnauthorizedException.class, CmisPermissionDeniedException.class}) + public void unauthorizedUserCannotDeleteDocumentFromModeratedSite() throws Exception + { + SiteModel moderatedSite = dataSite.usingUser(testUser).createModeratedRandomSite(); + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(moderatedSite).createFile(testFile).usingResource(testFile).update("content 1"); + cmisApi.authenticateUser(unauthorizedUser).usingResource(testFile).deleteAllVersions(true); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify unauthorized user cannot delete Folder from moderated site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisUnauthorizedException.class, CmisPermissionDeniedException.class}) + public void unauthorizedUserCannotDeleteFolderFromModeratedSite() throws Exception + { + SiteModel moderatedSite = dataSite.usingUser(testUser).createModeratedRandomSite(); + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + testFolder = new FolderModel(RandomData.getRandomName("Folder")); + cmisApi.authenticateUser(testUser).usingSite(moderatedSite).createFolder(testFolder); + cmisApi.authenticateUser(unauthorizedUser).usingResource(testFolder).deleteAllVersions(true); + } +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/DeleteContentStreamTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/DeleteContentStreamTests.java new file mode 100644 index 0000000000..04ea6091dc --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/DeleteContentStreamTests.java @@ -0,0 +1,236 @@ +package org.alfresco.cmis; + +import org.alfresco.cmis.exception.InvalidCmisObjectException; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.*; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 9/27/2016. + */ +public class DeleteContentStreamTests extends CmisTest +{ + UserModel siteManager; + SiteModel publicSite, privateSite; + FileModel testFile; + String content = "file content"; + private DataUser.ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + siteManager = dataUser.createRandomTestUser(); + publicSite = dataSite.usingUser(siteManager).createPublicRandomSite(); + privateSite = dataSite.usingUser(siteManager).createPrivateRandomSite(); + usersWithRoles = dataUser.addUsersWithRolesToSite(publicSite, UserRole.SiteManager, UserRole.SiteContributor, UserRole.SiteCollaborator, UserRole.SiteConsumer); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify site manager is able to delete content of a not empty document in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void siteManagerDeletesDocumentContent() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(testFile) + .deleteContent().and().assertThat().contentIs(""); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify user is not able to delete content of a nonexistent document in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisObjectNotFoundException.class) + public void userCantDeleteContentFromNonexistentFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + testFile.setCmisLocation("/fake-folder/test.txt"); + cmisApi.authenticateUser(siteManager) + .usingResource(testFile).deleteContent(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is able to delete content of a empty document in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanDeleteContentOfEmptyDocument() throws Exception + { + FileModel emptyDoc = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(siteManager) + .usingSite(publicSite).createFile(emptyDoc).and().assertThat().existsInRepo() + .and().assertThat().contentIs("") + .then().deleteContent().and().assertThat().contentIs(""); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify nonexistent user is not able to delete content of a document with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisUnauthorizedException.class) + public void nonexistentUserCannotDeleteDocumentContent() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(testFile) + .then().authenticateUser(UserModel.getRandomUserModel()) + .usingResource(testFile).deleteContent(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is able to delete content of a not empty document with refresh set to TRUE with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanDeleteDocContentWithRefreshTrue() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.HTML, content); + cmisApi.authenticateUser(siteManager) + .usingSite(publicSite).createFile(testFile) + .deleteContent(true).and().assertThat().contentIs(""); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is able to delete content of a not empty document with refresh set to FALSE with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanDeleteDocContentWithRefreshFalse() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.HTML, content); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(testFile) + .deleteContent(true).and().assertThat().contentIs(""); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify admin is able to delete content of a not empty document created by other user in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void adminDeletesContentOfFileCreatedByOtherUser() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(testFile).assertThat().existsInRepo() + .then().authenticateUser(dataUser.getAdminUser()) + .deleteContent().and().assertThat().contentIs(""); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is able to delete content of a not empty document created by other user in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerDeletesContentOfFileCreatedByOtherUser() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(testFile).assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .deleteContent().and().assertThat().contentIs(""); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site collaborator is able to delete content of a not empty document created by other user in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void collaboratorDeletesContentOfFileCreatedByOtherUser() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(testFile).assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .deleteContent().and().assertThat().contentIs(""); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site collaborator is able to delete content of a not empty document created by self in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void collaboratorDeletesContentOfFileCreatedBySelf() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingSite(publicSite) + .createFile(testFile).assertThat().existsInRepo() + .then().deleteContent() + .and().assertThat().contentIs(""); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site contributor is not able to delete content of a not empty document created by other user in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void contributorCannotDeleteContentOfFileCreatedByOtherUser() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(testFile).assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .deleteContent(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site contributor is able to delete content of a not empty document created by self in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void contributorDeletesContentOfFileCreatedBySelf() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingSite(publicSite) + .createFile(testFile).assertThat().existsInRepo() + .then().deleteContent() + .and().assertThat().contentIs(""); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site consumer is not able to delete content of a not empty document in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void consumerCannotDeleteContentOfFileCreatedByOtherUser() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(testFile).assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .deleteContent(); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = CmisUpdateConflictException.class, expectedExceptionsMessageRegExp = "^.*Cannot perform operation since the node.*is locked.$") + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is not able to delete content of a checked out file with CMIS") + public void managerCannotDeleteContentOfCheckedOutFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD, content); + cmisApi.authenticateUser(siteManager) + .usingSite(publicSite).createFile(testFile).assertThat().existsInRepo() + .then().checkOut().assertThat().documentIsCheckedOut() + .when().deleteContent(); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is able to delete content of a PWC file with CMIS") + public void managerDeletesContentOfPWCFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD, content); + cmisApi.authenticateUser(siteManager) + .usingSite(publicSite).createFile(testFile).assertThat().existsInRepo() + .then().checkOut().assertThat().documentIsCheckedOut() + .usingPWCDocument().deleteContent() + .assertThat().contentIs(""); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify unauthorized user is not able to delete content of a file created in a private site with CMIS") + public void unauthorizedUserCannotDeleteContentOfFileFromPrivateSite() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD, content); + cmisApi.authenticateUser(siteManager) + .usingSite(privateSite).createFile(testFile).assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .usingResource(testFile).deleteContent(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify user is not able to delete content of invalid file with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions = InvalidCmisObjectException.class, expectedExceptionsMessageRegExp = "^Content at.*is not a file$") + public void userShouldNotDeleteContentOfInvalidFile() throws Exception + { + FolderModel testFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFolder(testFolder).assertThat().existsInRepo() + .deleteContent(); + } + +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/DeleteTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/DeleteTests.java new file mode 100644 index 0000000000..a9a63e7eef --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/DeleteTests.java @@ -0,0 +1,321 @@ +package org.alfresco.cmis; + +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.*; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 9/26/2016. + */ +public class DeleteTests extends CmisTest +{ + UserModel siteManager; + SiteModel publicSite, privateSite; + FolderModel testFolder; + FileModel testFile; + private DataUser.ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + siteManager = dataUser.createRandomTestUser(); + publicSite = dataSite.usingUser(siteManager).createPublicRandomSite(); + privateSite = dataSite.usingUser(siteManager).createPrivateRandomSite(); + usersWithRoles = dataUser.addUsersWithRolesToSite(publicSite, UserRole.SiteManager, UserRole.SiteContributor, UserRole.SiteCollaborator, UserRole.SiteConsumer); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify site manager is able to delete files in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void siteManagerShouldDeleteDocument() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD); + cmisApi.authenticateUser(siteManager).usingSite(publicSite).createFile(testFile).and().assertThat().existsInRepo() + .then().delete() + .and().assertThat().doesNotExistInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify site manager is able to delete empty folders in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void siteManagerShouldDeleteEmptyFolder() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(siteManager).usingSite(publicSite).createFolder(testFolder).and().assertThat().existsInRepo() + .then().delete() + .and().assertThat().doesNotExistInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is NOT able to delete folders with chidren with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = CmisConstraintException.class, expectedExceptionsMessageRegExp = "^Could not delete folder with at least one child!$") + public void siteManagerCannotDeleteFolderWithChildren() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.MSWORD); + + cmisApi.authenticateUser(siteManager).usingSite(publicSite).createFolder(testFolder) + .usingResource(testFolder).createFile(testFile) + .usingResource(testFolder).delete(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is able to delete file with multiple versions with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanDeleteFileWithVersions() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.MSWORD); + + cmisApi.authenticateUser(siteManager).usingSite(publicSite).createFolder(testFolder) + .usingResource(testFolder).createFile(testFile) + .then().update("content 1").assertThat().documentHasVersion(1.1) + .then().update("content 2").assertThat().documentHasVersion(1.2) + .then().usingResource(testFile).delete() + .assertThat().doesNotExistInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is NOT able to delete file which is checked out with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = CmisConstraintException.class, expectedExceptionsMessageRegExp = "^Could not delete/cancel checkout on the original checked out document$") + public void siteManagerCannotDeleteCheckedOutFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD); + + cmisApi.authenticateUser(siteManager).usingSite(publicSite).createFile(testFile).usingResource(testFile).checkOut() + .assertThat().documentIsCheckedOut() + .then().delete(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is able to delete PWC file version with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanDeletePWCFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD); + + cmisApi.authenticateUser(siteManager).usingSite(publicSite).createFile(testFile).then().checkOut() + .assertThat().documentIsCheckedOut() + .usingPWCDocument().delete() + .assertThat().doesNotExistInRepo() + .usingResource(testFile).assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is NOT able to delete nonexistent file with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = CmisObjectNotFoundException.class) + public void siteManagerCannotDeleteNonexistentFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD); + testFile.setCmisLocation("/" + testFile.getName() + "/"); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .usingResource(testFile).delete(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is NOT able to delete nonexistent folder with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = CmisObjectNotFoundException.class) + public void siteManagerCannotDeleteNonexistentFolder() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + testFolder.setCmisLocation("/" + testFolder.getName() + "/"); + cmisApi.authenticateUser(siteManager) + .usingResource(testFolder).delete(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is able to delete files created by another users in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerShouldDeleteDocumentCreatedByAnotherUser() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD); + + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(testFile).and().assertThat().existsInRepo(); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .usingResource(testFile).delete() + .and().assertThat().doesNotExistInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site contributor is able to delete content created by self in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void contributorShouldDeleteContentCreatedBySelf() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD); + testFolder = FolderModel.getRandomFolderModel(); + + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .usingSite(publicSite) + .createFile(testFile).and().assertThat().existsInRepo() + .createFolder(testFolder).and().assertThat().existsInRepo() + .then().usingResource(testFile).delete() + .and().assertThat().doesNotExistInRepo() + .then().usingResource(testFolder).delete() + .and().assertThat().doesNotExistInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site contributor is not able to delete file created by other user in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisUnauthorizedException.class, CmisPermissionDeniedException.class}) + public void contributorShouldNotDeleteFileCreatedByOtherUser() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD); + cmisApi.authenticateUser(siteManager) + .usingSite(publicSite) + .createFile(testFile).and().assertThat().existsInRepo() + .when().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .usingResource(testFile).delete(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site contributor is not able to delete folder created by other user in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisUnauthorizedException.class, CmisPermissionDeniedException.class}) + public void contributorShouldNotDeleteFolderCreatedByOtherUser() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(siteManager) + .usingSite(publicSite) + .createFolder(testFolder).and().assertThat().existsInRepo() + .when().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .usingResource(testFolder).delete(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site collaborator is able to delete content created by self in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void collaboratorShouldDeleteContentCreatedBySelf() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD); + testFolder = FolderModel.getRandomFolderModel(); + + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .usingSite(publicSite) + .createFile(testFile).and().assertThat().existsInRepo() + .createFolder(testFolder).and().assertThat().existsInRepo() + .then().usingResource(testFile).delete() + .and().assertThat().doesNotExistInRepo() + .then().usingResource(testFolder).delete() + .and().assertThat().doesNotExistInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site collaborator is not able to delete file created by other user in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisUnauthorizedException.class, CmisPermissionDeniedException.class}) + public void collaboratorShouldNotDeleteFileCreatedByOtherUser() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD); + + cmisApi.authenticateUser(siteManager) + .usingSite(publicSite) + .createFile(testFile).and().assertThat().existsInRepo() + .when().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .usingResource(testFile).delete(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site collaborator is not able to delete folder created by other user in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisUnauthorizedException.class, CmisPermissionDeniedException.class}) + public void collaboratorShouldNotDeleteFolderCreatedByOtherUser() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + + cmisApi.authenticateUser(siteManager) + .usingSite(publicSite) + .createFolder(testFolder).and().assertThat().existsInRepo() + .when().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .usingResource(testFolder).delete(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site consumer is not able to delete file created by other user in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisUnauthorizedException.class, CmisPermissionDeniedException.class}) + public void consumerShouldNotDeleteFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD); + + cmisApi.authenticateUser(siteManager) + .usingSite(publicSite) + .createFile(testFile).and().assertThat().existsInRepo() + .when().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .usingResource(testFile).delete(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site consumer is not able to delete folder created by other user in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisUnauthorizedException.class, CmisPermissionDeniedException.class}) + public void consumerShouldNotDeleteFolder() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + + cmisApi.authenticateUser(siteManager) + .usingSite(publicSite) + .createFolder(testFolder).and().assertThat().existsInRepo() + .when().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .usingResource(testFolder).delete(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify admin is able to delete files created by another users in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void adminShouldDeleteDocumentCreatedByAnotherUser() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD); + + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(testFile).and().assertThat().existsInRepo(); + cmisApi.authenticateUser(dataUser.getAdminUser()) + .usingResource(testFile).delete() + .and().assertThat().doesNotExistInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify unauthorized user is not able to delete file created inside a private site with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisUnauthorizedException.class, CmisPermissionDeniedException.class}) + public void unauthorizedUserShouldNotDeleteFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD); + + cmisApi.authenticateUser(siteManager) + .usingSite(privateSite) + .createFile(testFile).and().assertThat().existsInRepo() + .when().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .usingResource(testFile).delete(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify unauthorized user is not able to delete folder created inside a private site with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisUnauthorizedException.class, CmisPermissionDeniedException.class}) + public void unauthorizedUserShouldNotDeleteFolder() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + + cmisApi.authenticateUser(siteManager) + .usingSite(privateSite) + .createFolder(testFolder).and().assertThat().existsInRepo() + .when().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .usingResource(testFolder).delete(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify unauthorized user is not able to delete content created inside a private site with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisUnauthorizedException.class, CmisPermissionDeniedException.class}) + public void unauthorizedUserCannotDeleteCheckedOutFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD); + + cmisApi.authenticateUser(siteManager).usingSite(privateSite) + .createFile(testFile).then().checkOut() + .and().assertThat().documentIsCheckedOut() + .when().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .usingResource(testFile).delete(); + } +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/DeleteTreeTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/DeleteTreeTests.java new file mode 100644 index 0000000000..f1c0b0dd08 --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/DeleteTreeTests.java @@ -0,0 +1,385 @@ +package org.alfresco.cmis; + +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +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.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.enums.UnfileObject; +import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 9/27/2016. + */ +public class DeleteTreeTests extends CmisTest +{ + UserModel testUser; + SiteModel testSite; + FileModel testFile; + FolderModel parentTestFolder, childTestFolder; + private String content = "content"; + private DataUser.ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + testUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(testUser).createPublicRandomSite(); + usersWithRoles = dataUser.usingUser(testUser) + .addUsersWithRolesToSite(testSite, UserRole.SiteContributor, UserRole.SiteCollaborator, UserRole.SiteConsumer); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify site manager is able to delete parent folder with multiple children in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void siteManagerDeletesFolderTree() throws Exception + { + parentTestFolder = FolderModel.getRandomFolderModel(); + childTestFolder = FolderModel.getRandomFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.MSWORD, content); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(parentTestFolder).and().assertThat().existsInRepo() + .usingResource(parentTestFolder) + .createFolder(childTestFolder).and().assertThat().existsInRepo() + .createFile(testFile).and().assertThat().existsInRepo() + .when().usingResource(parentTestFolder).refreshResource() + .deleteFolderTree() + .and().assertThat().doesNotExistInRepo() + .then().usingResource(childTestFolder).assertThat().doesNotExistInRepo() + .usingResource(testFile).assertThat().doesNotExistInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify exception is thrown when deleting inexistent folder tree in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisObjectNotFoundException.class) + public void siteManagerDeletesInexistentFolderTree() throws Exception + { + parentTestFolder = FolderModel.getRandomFolderModel(); + childTestFolder = FolderModel.getRandomFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.MSWORD, content); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(parentTestFolder).and().assertThat().existsInRepo() + .usingResource(parentTestFolder) + .createFolder(childTestFolder).and().assertThat().existsInRepo() + .createFile(testFile).and().assertThat().existsInRepo() + .when().usingResource(parentTestFolder).deleteFolderTree().assertThat().doesNotExistInRepo() + .deleteFolderTree(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify inexistent user is NOT able to delete parent folder with multiple children in DocumentLibrary") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisUnauthorizedException.class) + public void inexistentUserCannotDeleteFolderTree() throws Exception + { + parentTestFolder = FolderModel.getRandomFolderModel(); + childTestFolder = FolderModel.getRandomFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.MSWORD, content); + UserModel inexistentUser = UserModel.getRandomUserModel(); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(parentTestFolder).and().assertThat().existsInRepo() + .usingResource(parentTestFolder) + .createFolder(childTestFolder).and().assertThat().existsInRepo() + .createFile(testFile).and().assertThat().existsInRepo() + .then().authenticateUser(inexistentUser) + .usingResource(parentTestFolder).deleteFolderTree(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is able to delete parent folder with allVersions parameter set to true") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerDeletesFolderTreeWithAllVersionsParamTrue() throws Exception + { + parentTestFolder = FolderModel.getRandomFolderModel(); + childTestFolder = FolderModel.getRandomFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.MSWORD, content); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(parentTestFolder).and().assertThat().existsInRepo() + .usingResource(parentTestFolder) + .createFolder(childTestFolder).and().assertThat().existsInRepo() + .createFile(testFile).and().assertThat().existsInRepo() + .when().usingResource(parentTestFolder).deleteFolderTree(true, UnfileObject.DELETE, true) + .and().assertThat().doesNotExistInRepo() + .then().usingResource(childTestFolder).assertThat().doesNotExistInRepo() + .usingResource(testFile).assertThat().doesNotExistInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Only allVersions=true is supported for delete parent folder tree, allVersions=true is not supported") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisInvalidArgumentException.class}) + public void deleteFolderTreeWithAllVersionsParamFalseNotSupported() throws Exception + { + parentTestFolder = FolderModel.getRandomFolderModel(); + childTestFolder = FolderModel.getRandomFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.MSWORD, content); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(parentTestFolder).and().assertThat().existsInRepo() + .usingResource(parentTestFolder) + .createFolder(childTestFolder).and().assertThat().existsInRepo() + .createFile(testFile).and().assertThat().existsInRepo() + .when().usingResource(parentTestFolder).deleteFolderTree(false, UnfileObject.DELETE, true) + .and().assertThat().doesNotExistInRepo() + .then().usingResource(childTestFolder).assertThat().doesNotExistInRepo() + .usingResource(testFile).assertThat().doesNotExistInRepo(); + } + +// @Bug(id="REPO-1108") + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is NOT able to delete parent folder with unfile parameter set to DELETESINGLEFILED, using checked out document") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteManagerDeletesFolderTreeWithDeleteSingleFieldWithCheckoutDoc() throws Exception + { + parentTestFolder = FolderModel.getRandomFolderModel(); + childTestFolder = FolderModel.getRandomFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.MSWORD, content); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(parentTestFolder) + .usingResource(parentTestFolder) + .createFolder(childTestFolder) + .createFile(testFile).and().assertThat().existsInRepo() + .and().checkOut() + .when().usingResource(parentTestFolder).deleteFolderTree(true, UnfileObject.DELETESINGLEFILED, true) + .and().assertThat().doesNotExistInRepo() + .then().usingResource(childTestFolder).assertThat().doesNotExistInRepo() + .usingResource(testFile).assertThat().doesNotExistInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is NOT able to delete parent folder with unfile parameter set to DELETESINGLEFILED, using add object to folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerDeletesFolderTreeWithDeleteSingleFieldWithAddDocToFolder1() throws Exception + { + parentTestFolder = FolderModel.getRandomFolderModel(); + childTestFolder = FolderModel.getRandomFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.MSWORD, content); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(parentTestFolder) + .createFolder(childTestFolder) + .usingResource(parentTestFolder) + .createFile(testFile).and().assertThat().existsInRepo() + .usingResource(testFile).addDocumentToFolder(childTestFolder, true) + .then().usingResource(childTestFolder).deleteFolderTree(true, UnfileObject.DELETESINGLEFILED, true) + .and().assertThat().doesNotExistInRepo() + .then().usingResource(parentTestFolder).assertThat().existsInRepo() + .usingResource(testFile).assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is able to delete parent folder with unfile parameter set to DELETESINGLEFILED, using add object to folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerDeletesFolderTreeWithDeleteSingleFieldWithAddDocToFolder2() throws Exception + { + parentTestFolder = FolderModel.getRandomFolderModel(); + childTestFolder = FolderModel.getRandomFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.MSWORD, content); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(parentTestFolder) + .createFolder(childTestFolder) + .usingResource(parentTestFolder) + .createFile(testFile).and().assertThat().existsInRepo() + .usingResource(testFile).addDocumentToFolder(childTestFolder, true) + .then().usingResource(childTestFolder).deleteFolderTree(true, UnfileObject.DELETE, true) + .and().assertThat().doesNotExistInRepo() + .then().usingResource(parentTestFolder).assertThat().existsInRepo() + .usingResource(testFile).assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Unfile-ing is not supported for delete parent folder tree") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisInvalidArgumentException.class}, + expectedExceptionsMessageRegExp="Unfiling not supported!*") + public void deleteFolderTreeWithUnfileNotSupported() throws Exception + { + parentTestFolder = FolderModel.getRandomFolderModel(); + childTestFolder = FolderModel.getRandomFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.MSWORD, content); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(parentTestFolder).and().assertThat().existsInRepo() + .usingResource(parentTestFolder) + .createFolder(childTestFolder).and().assertThat().existsInRepo() + .createFile(testFile).and().assertThat().existsInRepo() + .when().usingResource(parentTestFolder).deleteFolderTree(true, UnfileObject.UNFILE, true) + .and().assertThat().doesNotExistInRepo() + .then().usingResource(childTestFolder).assertThat().doesNotExistInRepo() + .usingResource(testFile).assertThat().doesNotExistInRepo(); + } + +// @Bug(id="REPO-1108") + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is able to delete parent folder with continueOnFailure parameter set to false") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerDeletesFolderTreeWithContinueOnFailureParamFalse() throws Exception + { + parentTestFolder = FolderModel.getRandomFolderModel(); + childTestFolder = FolderModel.getRandomFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.MSWORD, content); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(parentTestFolder) + .usingResource(parentTestFolder) + .createFolder(childTestFolder) + .createFile(testFile).and().assertThat().existsInRepo() + .when().usingResource(parentTestFolder).deleteFolderTree(true, UnfileObject.DELETE, false) + .and().assertThat().doesNotExistInRepo() + .then().usingResource(childTestFolder).assertThat().doesNotExistInRepo() + .usingResource(testFile).assertThat().doesNotExistInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site contributor is able to delete parent folder with multiple children created by himself") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void contributorDeletesOwnFolderTree() throws Exception + { + parentTestFolder = FolderModel.getRandomFolderModel(); + childTestFolder = FolderModel.getRandomFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.MSWORD, content); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .usingSite(testSite) + .createFolder(parentTestFolder).and().assertThat().existsInRepo() + .usingResource(parentTestFolder) + .createFolder(childTestFolder).and().assertThat().existsInRepo() + .createFile(testFile).and().assertThat().existsInRepo() + .when().usingResource(parentTestFolder).refreshResource() + .deleteFolderTree() + .and().assertThat().doesNotExistInRepo() + .then().usingResource(childTestFolder).assertThat().doesNotExistInRepo() + .usingResource(testFile).assertThat().doesNotExistInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site contributor is not able to delete parent folder with multiple children created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void contributorCannotDeleteFolderTreeCreatedByManager() throws Exception + { + parentTestFolder = FolderModel.getRandomFolderModel(); + childTestFolder = FolderModel.getRandomFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.MSWORD, content); + cmisApi.authenticateUser(testUser) + .usingSite(testSite) + .createFolder(parentTestFolder).and().assertThat().existsInRepo() + .usingResource(parentTestFolder) + .createFolder(childTestFolder).and().assertThat().existsInRepo() + .createFile(testFile).and().assertThat().existsInRepo() + .authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .when().usingResource(parentTestFolder).refreshResource() + .deleteFolderTree().and().assertThat().hasFailedDeletedObject(parentTestFolder.getNodeRef()) + .and().assertThat().existsInRepo() + .then().usingResource(childTestFolder).assertThat().existsInRepo() + .usingResource(testFile).assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site collaborator is not able to delete parent folder with multiple children created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void collaboratorCannotDeleteFolderTreeCreatedByManager() throws Exception + { + parentTestFolder = FolderModel.getRandomFolderModel(); + childTestFolder = FolderModel.getRandomFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.MSWORD, content); + cmisApi.authenticateUser(testUser) + .usingSite(testSite) + .createFolder(parentTestFolder).and().assertThat().existsInRepo() + .usingResource(parentTestFolder) + .createFolder(childTestFolder).and().assertThat().existsInRepo() + .createFile(testFile).and().assertThat().existsInRepo() + .authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .when().usingResource(parentTestFolder).refreshResource() + .deleteFolderTree().and().assertThat().hasFailedDeletedObject(parentTestFolder.getNodeRef()) + .and().assertThat().existsInRepo() + .then().usingResource(childTestFolder).assertThat().existsInRepo() + .usingResource(testFile).assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site collaborator is able to delete parent folder with multiple children created by himself") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void collaboratorDeletesOwnFolderTree() throws Exception + { + parentTestFolder = FolderModel.getRandomFolderModel(); + childTestFolder = FolderModel.getRandomFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.MSWORD, content); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .usingSite(testSite) + .createFolder(parentTestFolder).and().assertThat().existsInRepo() + .usingResource(parentTestFolder) + .createFolder(childTestFolder).and().assertThat().existsInRepo() + .createFile(testFile).and().assertThat().existsInRepo() + .when().usingResource(parentTestFolder).refreshResource() + .deleteFolderTree() + .and().assertThat().doesNotExistInRepo() + .then().usingResource(childTestFolder).assertThat().doesNotExistInRepo() + .usingResource(testFile).assertThat().doesNotExistInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site consumer is not able to delete parent folder with multiple children created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void consumerCannotDeleteFolderTreeCreatedByManager() throws Exception + { + parentTestFolder = FolderModel.getRandomFolderModel(); + childTestFolder = FolderModel.getRandomFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.MSWORD, content); + cmisApi.authenticateUser(testUser) + .usingSite(testSite) + .createFolder(parentTestFolder).and().assertThat().existsInRepo() + .usingResource(parentTestFolder) + .createFolder(childTestFolder).and().assertThat().existsInRepo() + .createFile(testFile).and().assertThat().existsInRepo() + .authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .when().usingResource(parentTestFolder).refreshResource() + .deleteFolderTree().and().assertThat().hasFailedDeletedObject(parentTestFolder.getNodeRef()) + .and().assertThat().existsInRepo() + .then().usingResource(childTestFolder).assertThat().existsInRepo() + .usingResource(testFile).assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify non invited user is not able to delete parent folder with multiple children in private site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void nonInvitedUserCannotDeleteFolderTreeInPrivateSite() throws Exception + { + SiteModel privateSite = dataSite.usingUser(testUser).createPrivateRandomSite(); + parentTestFolder = FolderModel.getRandomFolderModel(); + childTestFolder = FolderModel.getRandomFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.MSWORD, content); + cmisApi.authenticateUser(testUser) + .usingSite(privateSite) + .createFolder(parentTestFolder).and().assertThat().existsInRepo() + .usingResource(parentTestFolder) + .createFolder(childTestFolder).and().assertThat().existsInRepo() + .createFile(testFile).and().assertThat().existsInRepo() + .authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .when().usingResource(parentTestFolder) + .deleteFolderTree(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify that only the parent folder is displayed in trash can after deleting it") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void checkTrashCanAfterDeletingParentFolder() throws Exception + { + parentTestFolder = FolderModel.getRandomFolderModel(); + childTestFolder = FolderModel.getRandomFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.MSWORD, content); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(parentTestFolder).and().assertThat().existsInRepo() + .usingResource(parentTestFolder) + .createFolder(childTestFolder).and().assertThat().existsInRepo() + .createFile(testFile).and().assertThat().existsInRepo() + .when().usingResource(parentTestFolder).refreshResource() + .deleteFolderTree() + .and().assertThat().doesNotExistInRepo() + .then().usingResource(childTestFolder).assertThat().doesNotExistInRepo() + .usingResource(testFile).assertThat().doesNotExistInRepo(); + dataUser.assertTrashCanHasContent(parentTestFolder); + dataUser.assertTrashCanDoesNotHaveContent(childTestFolder, testFile); + } +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetAllVersionsTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetAllVersionsTests.java new file mode 100644 index 0000000000..f9a948b29b --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetAllVersionsTests.java @@ -0,0 +1,186 @@ +package org.alfresco.cmis; + +import org.alfresco.cmis.exception.InvalidCmisObjectException; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.*; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.client.api.OperationContext; +import org.apache.chemistry.opencmis.commons.PropertyIds; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class GetAllVersionsTests extends CmisTest +{ + UserModel siteManager; + SiteModel publicSite; + FileModel testFile, managerFile; + private DataUser.ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + managerFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, documentContent); + siteManager = dataUser.createRandomTestUser(); + publicSite = dataSite.usingUser(siteManager).createPublicRandomSite(); + usersWithRoles = dataUser.usingUser(siteManager) + .addUsersWithRolesToSite(publicSite, UserRole.SiteContributor, UserRole.SiteCollaborator, UserRole.SiteConsumer); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(managerFile).assertThat().existsInRepo() + .and().checkOut().assertThat().documentIsCheckedOut() + .then().prepareDocumentForCheckIn().checkIn() + .and().checkOut().assertThat().documentIsCheckedOut() + .then().prepareDocumentForCheckIn() + .withMajorVersion().checkIn(); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.SANITY, + description = "Verify site manager can get all versions for a valid document") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void siteManagerShouldGetAllVersionsForAValidDocument() throws Exception + { + cmisApi.authenticateUser(siteManager).usingResource(managerFile) + .usingVersion().getAllDocumentVersions().assertHasVersions(1.0, 1.1, 2.0); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager can not get all versions for a document that was deleted") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = CmisObjectNotFoundException.class) + public void siteManagerShouldNotGetAllVersionsForADeletedDocument() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(testFile).assertThat().existsInRepo() + .and().update("content 1").update("content 2") + .assertThat().documentHasVersion(1.2).usingVersion().getAllDocumentVersions().assertHasVersions(1.0, 1.1, 1.2) + .and().delete() + .then().usingVersion().getAllDocumentVersions(); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager can get all versions for a document using OperationContext: OrderBy") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerShouldGetAllVersionsWithOperationContextForADocument() throws Exception + { + OperationContext context = cmisApi.authenticateUser(siteManager).getSession().createOperationContext(); + context.setOrderBy(PropertyIds.OBJECT_ID + " DESC"); + + cmisApi.authenticateUser(siteManager).usingResource(managerFile) + .usingVersion().getAllDocumentVersionsBy(context).assertHasVersionsInOrder(2.0, 1.1, 1.0); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager cannot get all versions for a folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=InvalidCmisObjectException.class) + public void siteManagerCannotGetAllVersionsForFolder() throws Exception + { + FolderModel folder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFolder(folder).assertThat().existsInRepo() + .usingVersion().getAllDocumentVersions(); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager can get all versions for a valid checked out document") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerShouldGetAllVersionsForCheckedOutDocument() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(testFile).assertThat().existsInRepo() + .and().checkOut().assertThat().documentIsCheckedOut() + .then().prepareDocumentForCheckIn().checkIn() + .and().checkOut().assertThat().documentIsCheckedOut() + .then().usingResource(testFile) + .usingVersion().getAllDocumentVersions().assertHasVersions("pwc", 1.1, 1.0); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager can get all versions for a valid pwc document") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerShouldGetAllVersionsForPWCDocument() throws Exception + { + OperationContext context = cmisApi.getSession().createOperationContext(); + context.setOrderBy(PropertyIds.OBJECT_ID + " DESC"); + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(testFile).assertThat().existsInRepo() + .and().checkOut().assertThat().documentIsCheckedOut() + .then().prepareDocumentForCheckIn().checkIn() + .and().checkOut().assertThat().documentIsCheckedOut() + .then().usingResource(testFile).usingPWCDocument() + .usingVersion().getAllDocumentVersions().assertHasVersions(1.1, 1.0, "pwc") + .usingVersion().getAllDocumentVersionsBy(context).assertHasVersionsInOrder("pwc", 1.1, 1.0); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site collaborator can get all versions for a document created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void collaboratorCanGetAllVersionsForDocumentCreatedByManager() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .usingResource(managerFile) + .usingVersion().getAllDocumentVersions().assertHasVersions(1.0, 1.1, 2.0); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site collaborator can get all versions for a document created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void contributorCanGetAllVersionsForDocumentCreatedByManager() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .usingResource(managerFile) + .usingVersion().getAllDocumentVersions().assertHasVersions(1.0, 1.1, 2.0); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site consumer can get all versions for a document created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void consumerCanGetAllVersionsForDocumentCreatedByManager() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .usingResource(managerFile) + .usingVersion().getAllDocumentVersions().assertHasVersions(1.0, 1.1, 2.0); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify non invited user can get all versions for a document in public site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void nonInvitedUserCannotGetAllVersionsForDocumentFromPublicSite() throws Exception + { + UserModel nonInvitedUser = dataUser.createRandomTestUser(); + cmisApi.authenticateUser(nonInvitedUser) + .usingResource(managerFile) + .usingVersion().getAllDocumentVersions().assertHasVersions(1.0, 1.1, 2.0); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify non invited user cannot get all versions for a document in private site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void nonInvitedUserCannotGetAllVersionsForDocumentFromPrivateSite() throws Exception + { + SiteModel privateSite = dataSite.usingUser(siteManager).createPrivateRandomSite(); + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, documentContent); + cmisApi.authenticateUser(siteManager).usingSite(privateSite).createFile(testFile) + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .usingResource(testFile) + .usingVersion().getAllDocumentVersions().assertHasVersions(1.0); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify non invited user cannot get all versions for a document in moderated site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void nonInvitedUserCannotGetAllVersionsForDocumentFromModeratedSite() throws Exception + { + SiteModel moderated = dataSite.usingUser(siteManager).createPrivateRandomSite(); + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, documentContent); + cmisApi.authenticateUser(siteManager).usingSite(moderated).createFile(testFile) + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .usingResource(testFile) + .usingVersion().getAllDocumentVersions().assertHasVersions(1.0); + } +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetCheckedOutDocumentsTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetCheckedOutDocumentsTests.java new file mode 100644 index 0000000000..0d49f2f5c0 --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetCheckedOutDocumentsTests.java @@ -0,0 +1,200 @@ +package org.alfresco.cmis; + +import org.alfresco.utility.Utility; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.*; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.client.api.OperationContext; +import org.apache.chemistry.opencmis.commons.PropertyIds; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class GetCheckedOutDocumentsTests extends CmisTest +{ + UserModel testUser; + SiteModel testSite; + FileModel testFile; + FolderModel testFolder; + private DataUser.ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + testFolder = FolderModel.getRandomFolderModel(); + testUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(testUser).createPublicRandomSite(); + usersWithRoles = dataUser.usingUser(testUser) + .addUsersWithRolesToSite(testSite, UserRole.SiteContributor, UserRole.SiteCollaborator, UserRole.SiteConsumer); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(testFolder) + .usingResource(testFolder).createFile(testFile).assertThat().existsInRepo() + .and().checkOut().assertThat().documentIsCheckedOut(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify site manager is able to get checked out documents from a valid folder") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void siteManagerShouldGetCheckedOutDocumentsFromAValidFolder() throws Exception + { + cmisApi.authenticateUser(testUser) + .usingResource(testFolder) + .assertThat().folderHasCheckedOutDocument(testFile); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify site manager is able to get checked out documents from session") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void siteManagerShouldGetCheckedOutDocumentsFromSession() throws Exception + { + cmisApi.authenticateUser(testUser).assertThat().sessionHasCheckedOutDocument(testFile); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager CANNOT get checked out documents from inexistent folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisObjectNotFoundException.class}) + public void siteManagerCannotGetCheckedOutDocumentsFromInexistentFolder() throws Exception + { + FolderModel testFolder = FolderModel.getRandomFolderModel(); + testFolder.setCmisLocation(Utility.buildPath("/", testFolder.getCmisLocation())); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .and().usingResource(testFolder) + .assertThat().folderHasCheckedOutDocument(testFile); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify that user is not able to get checked out documents from session created by admin in root") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void userShouldNotGetCheckedOutDocumentFromSessionCreatedByAdminInRoot() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(dataUser.getAdminUser()).usingRoot() + .createFile(testFile).assertThat().existsInRepo() + .and().checkOut() + .then().authenticateUser(testUser) + .and().assertThat().sessioDoesNotHaveCheckedOutDocument(testFile); + } + + @Bug(id="MNT-17357") + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site collaborator is able to get checked out documents created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void collaboratorShouldGetCheckedOutDocumentsFromFolderCreatedByManager() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .usingResource(testFolder) + .assertThat().folderHasCheckedOutDocument(testFile); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site collaborator is able to get checked out documents created by himslef") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void collaboratorShouldGetCheckedOutDocumentsCreatedByHimself() throws Exception + { + FileModel collaboratorFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .usingResource(testFolder) + .createFile(collaboratorFile).checkOut() + .usingResource(testFolder) + .assertThat().folderHasCheckedOutDocument(collaboratorFile) + .assertThat().sessionHasCheckedOutDocument(collaboratorFile); + } + + @Bug(id="MNT-17357") + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site contributor is able to get checked out documents created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void contributorShouldGetCheckedOutDocumentsFromFolderCreatedByManager() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .usingResource(testFolder) + .assertThat().folderHasCheckedOutDocument(testFile); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site collaborator is able to get checked out documents created by himslef") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void contributorShouldGetCheckedOutDocumentsCreatedByHimself() throws Exception + { + FileModel contributorFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .usingResource(testFolder) + .createFile(contributorFile).checkOut() + .usingResource(testFolder) + .assertThat().folderHasCheckedOutDocument(contributorFile) + .assertThat().sessionHasCheckedOutDocument(contributorFile); + } + + @Bug(id="MNT-17357") + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site collaborator is able to get checked out documents created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void consumerShouldGetCheckedOutDocumentsFromFolderCreatedByManager() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .usingResource(testFolder) + .assertThat().folderHasCheckedOutDocument(testFile); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify non invited user is not able to get checked out documents") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void nonInvitedUserShouldNotGetCheckedOutDocuments() throws Exception + { + FileModel doc = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + FolderModel folder = FolderModel.getRandomFolderModel(); + SiteModel privateSite = dataSite.usingUser(testUser).createPrivateRandomSite(); + cmisApi.authenticateUser(testUser).usingSite(privateSite) + .createFolder(folder).usingResource(folder) + .createFile(doc).checkOut() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .usingResource(folder) + .assertThat().folderHasCheckedOutDocument(doc); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager user is able to get checked out documents from folder with operation context") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanGetCheckedOutDocumentsFromFolderWithOperationContext() throws Exception + { + OperationContext context = cmisApi.authenticateUser(testUser).getSession().createOperationContext(); + context.setOrderBy(PropertyIds.NAME + " DESC"); + FileModel doc1 = new FileModel("a-file.txt", FileType.TEXT_PLAIN, documentContent); + FileModel doc2 = new FileModel("b-file.txt", FileType.TEXT_PLAIN, documentContent); + FileModel doc3 = new FileModel("c-file.txt", FileType.TEXT_PLAIN, documentContent); + FolderModel folder = FolderModel.getRandomFolderModel(); + SiteModel privateSite = dataSite.usingUser(testUser).createPrivateRandomSite(); + cmisApi.authenticateUser(testUser).usingSite(privateSite) + .createFolder(folder).usingResource(folder) + .createFile(doc1).checkOut() + .createFile(doc2).checkOut() + .createFile(doc3) + .usingResource(folder) + .assertThat().folderHasCheckedOutDocument(context, doc2, doc1); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify user is able to get checked out documents from session with operation context") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanGetCheckedOutDocumentsFromSessionWithOperationContext() throws Exception + { + UserModel user = dataUser.createRandomTestUser(); + OperationContext context = cmisApi.authenticateUser(user).getSession().createOperationContext(); + context.setOrderBy(PropertyIds.NAME + " DESC"); + FileModel doc1 = new FileModel("a-file.txt", FileType.TEXT_PLAIN, documentContent); + FileModel doc2 = new FileModel("b-file.txt", FileType.TEXT_PLAIN, documentContent); + FileModel doc3 = new FileModel("c-file.txt", FileType.TEXT_PLAIN, documentContent); + SiteModel publicSite = dataSite.usingUser(user).createPublicRandomSite(); + cmisApi.authenticateUser(user).usingSite(publicSite) + .createFile(doc1).checkOut() + .createFile(doc2).checkOut() + .createFile(doc3) + .then().assertThat().sessionHasCheckedOutDocument(context, doc2, doc1); + } +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetChildrenTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetChildrenTests.java new file mode 100644 index 0000000000..9716ae6440 --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetChildrenTests.java @@ -0,0 +1,203 @@ +package org.alfresco.cmis; + +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +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.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +public class GetChildrenTests extends CmisTest +{ + UserModel testUser; + SiteModel testSite; + FileModel testFile; + FileModel secondFile; + FolderModel testFolder; + FolderModel subFolder; + DataUser.ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + testUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(testUser).createPublicRandomSite(); + usersWithRoles = dataUser.addUsersWithRolesToSite(testSite, UserRole.SiteCollaborator, UserRole.SiteContributor, UserRole.SiteConsumer); + } + + @BeforeMethod(alwaysRun = true) + public void generateRandomContent() + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + secondFile = FileModel.getRandomFileModel(FileType.MSEXCEL); + testFolder = FolderModel.getRandomFolderModel(); + subFolder = FolderModel.getRandomFolderModel(); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.SANITY, description = "Get children from valid folder") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void getChildrenFromValidFolder() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(testFolder).assertThat().existsInRepo() + .and().usingResource(testFolder) + .createFile(testFile) + .createFile(secondFile) + .createFolder(subFolder) + .then().usingResource(testFolder).assertThat().hasChildren(testFile, secondFile, subFolder) + .assertThat().hasFiles(testFile, secondFile) + .assertThat().hasFolders(subFolder); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Fails to get children from folder that was previously deleted") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS} , expectedExceptions = CmisObjectNotFoundException.class) + public void getChildrenFromDeletedFolder() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(testFolder) + .and().usingResource(testFolder) + .createFile(testFile) + .createFile(secondFile) + .createFolder(subFolder) + .then().usingResource(testFolder) + .assertThat().hasChildren(testFile, secondFile, subFolder) + .and().usingResource(testFolder).refreshResource().and().deleteFolderTree() + .then().usingResource(testFolder).assertThat().hasChildren(testFile, secondFile, subFolder); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site collaborator can get children for a folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteCollaboratorCanGetChildrenFromValidFolderCreatedBySelf() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingSite(testSite) + .createFolder(testFolder).assertThat().existsInRepo() + .and().usingResource(testFolder) + .createFile(testFile) + .createFile(secondFile) + .createFolder(subFolder) + .then().usingResource(testFolder).assertThat().hasChildren(testFile, secondFile, subFolder) + .assertThat().hasFiles(testFile, secondFile) + .assertThat().hasFolders(subFolder); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site collaborator can get children for a folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteCollaboratorCanGetChildrenFromValidFolderCreatedByManager() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(testFolder).assertThat().existsInRepo() + .and().usingResource(testFolder) + .createFile(testFile) + .createFile(secondFile) + .createFolder(subFolder); + + + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .usingResource(testFolder).assertThat().hasChildren(testFile, secondFile, subFolder) + .assertThat().hasFiles(testFile, secondFile) + .assertThat().hasFolders(subFolder); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site contributor can get children for a folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteContributorCanGetChildrenFromValidFolderCreatedBySelf() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingSite(testSite) + .createFolder(testFolder).assertThat().existsInRepo() + .and().usingResource(testFolder) + .createFile(testFile) + .createFile(secondFile) + .createFolder(subFolder) + .then().usingResource(testFolder).assertThat().hasChildren(testFile, secondFile, subFolder) + .assertThat().hasFiles(testFile, secondFile) + .assertThat().hasFolders(subFolder); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site contributor can get children for a folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteContributorCanGetChildrenFromValidFolderCreatedByManager() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(testFolder).assertThat().existsInRepo() + .and().usingResource(testFolder) + .createFile(testFile) + .createFile(secondFile) + .createFolder(subFolder); + + + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .usingResource(testFolder).assertThat().hasChildren(testFile, secondFile, subFolder) + .assertThat().hasFiles(testFile, secondFile) + .assertThat().hasFolders(subFolder); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site consumer can get children for a folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteConsumerCanGetChildrenFromValidFolder() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(testFolder).assertThat().existsInRepo() + .and().usingResource(testFolder) + .createFile(testFile) + .createFile(secondFile) + .createFolder(subFolder); + + + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .usingResource(testFolder).assertThat().hasChildren(testFile, secondFile, subFolder) + .assertThat().hasFiles(testFile, secondFile) + .assertThat().hasFolders(subFolder); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify non site member cannot get children for a folder from a private site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions={ CmisPermissionDeniedException.class, CmisUnauthorizedException.class }) + public void nonSiteMemberCannotGetChildrenFromValidFolderFromAPrivateSite() throws Exception + { + SiteModel privateSite = dataSite.usingAdmin().createPrivateRandomSite(); + + cmisApi.authenticateUser(testUser).usingSite(privateSite) + .createFolder(testFolder).assertThat().existsInRepo() + .and().usingResource(testFolder) + .createFile(testFile) + .createFile(secondFile) + .createFolder(subFolder); + + cmisApi.authenticateUser(testUser) + .usingResource(testFolder).assertThat().hasChildren(testFile, secondFile, subFolder); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify non site member cannot get children for a folder from a moderated site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions={ CmisPermissionDeniedException.class, CmisUnauthorizedException.class }) + public void nonSiteMemberCannotGetChildrenFromValidFolderFromAModeratedSite() throws Exception + { + SiteModel moderatedSite = dataSite.usingAdmin().createModeratedRandomSite(); + + cmisApi.authenticateUser(testUser).usingSite(moderatedSite) + .createFolder(testFolder).assertThat().existsInRepo() + .and().usingResource(testFolder) + .createFile(testFile) + .createFile(secondFile) + .createFolder(subFolder); + + cmisApi.authenticateUser(testUser) + .usingResource(testFolder).assertThat().hasChildren(testFile, secondFile, subFolder); + } +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetContentStreamTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetContentStreamTests.java new file mode 100644 index 0000000000..5de39f2026 --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetContentStreamTests.java @@ -0,0 +1,200 @@ +package org.alfresco.cmis; + +import org.alfresco.cmis.exception.InvalidCmisObjectException; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.*; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 9/27/2016. + */ +public class GetContentStreamTests extends CmisTest +{ + SiteModel publicSite, privateSite; + UserModel siteManager; + FileModel testFile; + String content = "file content"; + private DataUser.ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + siteManager = dataUser.createRandomTestUser(); + publicSite = dataSite.usingUser(siteManager).createPublicRandomSite(); + privateSite = dataSite.usingUser(siteManager).createPrivateRandomSite(); + usersWithRoles = dataUser.addUsersWithRolesToSite(publicSite, UserRole.SiteManager, UserRole.SiteContributor, UserRole.SiteCollaborator, UserRole.SiteConsumer); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify site manager is able to get a document content in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void siteManagerShouldGetDocumentContent() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + cmisApi.authenticateUser(siteManager) + .usingSite(publicSite).createFile(testFile) + .then().assertThat().existsInRepo() + .and().assertThat().contentIs(content); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify site manager is able to get empty document content in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerShouldGetEmptyDocumentContent() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD); + cmisApi.authenticateUser(siteManager) + .usingSite(publicSite).createFile(testFile) + .then().assertThat().existsInRepo().and().assertThat().contentIs(""); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is able to get content from checked out document with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerShouldGetContentFromCheckedOutDoc() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + cmisApi.authenticateUser(siteManager) + .usingSite(publicSite).createFile(testFile) + .and().assertThat().existsInRepo() + .then().checkOut() + .and().assertThat().contentIs(content); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify admin is able to get document content with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void adminShouldGetContentOfFileCreatedByOtherUser() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(testFile).assertThat().existsInRepo() + .then().authenticateUser(dataUser.getAdminUser()) + .usingResource(testFile).assertThat().contentIs(content); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is able to get content of file created by other user in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerShouldGetContentOfFileCreatedByOtherUser() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(testFile).assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .usingResource(testFile).assertThat().contentIs(content); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site collaborator is able to get content of file created by other user in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void collaboratorShouldGetContentOfFileCreatedByOtherUser() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(testFile).assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .usingResource(testFile).assertThat().contentIs(content); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site collaborator is able to get content of file created by self in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void collaboratorShouldGetContentOfFileCreatedBySelf() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingSite(publicSite) + .createFile(testFile).assertThat().existsInRepo() + .and().assertThat().contentIs(content); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site contributor is able to get content of file created by other user in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void contributorShouldGetContentOfFileCreatedByOtherUser() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(testFile).assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .usingResource(testFile).assertThat().contentIs(content); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site contributor is able to get content of file created by self in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void contributorShouldGetContentOfFileCreatedBySelf() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingSite(publicSite) + .createFile(testFile).assertThat().existsInRepo() + .and().assertThat().contentIs(content); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site consumer is able to get content of file created by other user in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void consumerShouldGetContentOfFileCreatedByOtherUser() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(testFile).assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .usingResource(testFile).assertThat().contentIs(content); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is able to get content from checked out document with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerShouldGetContentOfPWCDoc() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + cmisApi.authenticateUser(siteManager) + .usingSite(publicSite).createFile(testFile) + .and().assertThat().existsInRepo() + .then().checkOut().assertThat().documentIsCheckedOut() + .usingPWCDocument().assertThat().contentIs(content); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify unauthorized is not able to get content of file created in a private site with CMIS") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS }, expectedExceptions = { CmisPermissionDeniedException.class, CmisUnauthorizedException.class }) + public void unauthorizedUserShouldNotGetFileContent() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + cmisApi.authenticateUser(siteManager).usingSite(privateSite) + .createFile(testFile).assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .usingResource(testFile).assertThat().contentIs(content); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify user is not able to get content of non existent file with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions = CmisObjectNotFoundException.class) + public void userShouldNotGetContentOfNonexistentFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + testFile.setCmisLocation("/" + testFile.getName() + "/"); + cmisApi.authenticateUser(siteManager) + .usingResource(testFile).assertThat().contentIs(content); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify user is not able to get content of invalid file with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions = InvalidCmisObjectException.class, expectedExceptionsMessageRegExp = "^Content at.*is not a file$") + public void userShouldNotGetContentOfInvalidFile() throws Exception + { + FolderModel testFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFolder(testFolder).assertThat().existsInRepo() + .and().assertThat().contentIs(content); + } + +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetDescendantsTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetDescendantsTests.java new file mode 100644 index 0000000000..043e3b20c4 --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetDescendantsTests.java @@ -0,0 +1,194 @@ +package org.alfresco.cmis; + +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.*; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +public class GetDescendantsTests extends CmisTest +{ + UserModel testUser; + SiteModel testSite; + FileModel testFile; + FileModel fileModel; + FolderModel testFolder; + FolderModel folderModel; + DataUser.ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + testUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(testUser).createPublicRandomSite(); + usersWithRoles = dataUser.addUsersWithRolesToSite(testSite, UserRole.SiteCollaborator, UserRole.SiteContributor, UserRole.SiteConsumer); + } + + @BeforeMethod(alwaysRun = true) + public void generateRandomContent() + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + fileModel = FileModel.getRandomFileModel(FileType.MSPOWERPOINT); + testFolder = FolderModel.getRandomFolderModel(); + folderModel = FolderModel.getRandomFolderModel(); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.SANITY, + description = "Verify site manager can get descendants for valid parent folder with at least 3 children and depth set to >=1") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void getDescendantsForValidParentFolderWithAtLeast3ChildrenAndDepthGreaterThan1() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite).createFolder(testFolder) + .and().assertThat().existsInRepo() + .and().usingResource(testFolder).createFile(testFile) + .and().createFile(fileModel) + .and().createFolder(folderModel) + .then().usingResource(testFolder).assertThat().hasDescendants(1, folderModel, fileModel, testFile); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.SANITY, + description = "Verify site manager can get descendants for valid parent folder with at least 3 children and depth set to -1") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void getDescendantsForValidParentFolderWithAtLeast3ChildrenAndDepthSetToMinus1() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite).createFolder(testFolder) + .and().assertThat().existsInRepo() + .and().usingResource(testFolder).createFile(testFile) + .then().createFile(fileModel) + .and().createFolder(folderModel) + .then().usingResource(testFolder).assertThat().hasDescendants(-1, folderModel, fileModel, testFile); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager CANNOT get descendants for valid parent folder with at least 2 children and depth set to 0") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisInvalidArgumentException.class}) + public void getDescendantsForValidParentFolderWithAtLeast2ChildrenAndDepthSetTo0() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite).createFolder(testFolder) + .and().usingResource(testFolder).createFile(testFile) + .and().createFolder(folderModel) + .then().usingResource(testFolder).assertThat().hasDescendants(0, folderModel, testFile); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager CANNOT get descendants for valid parent folder with at least 2 children and depth set to -2") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisInvalidArgumentException.class}) + public void getDescendantsForValidParentFolderWithAtLeast2ChildrenAndDepthSetToMinus2() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite).createFolder(testFolder) + .and().usingResource(testFolder).createFile(testFile) + .and().createFolder(folderModel) + .then().usingResource(testFolder).assertThat().hasDescendants(-2, folderModel, testFile); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager CANNOT get descendants for parent folder with at least 2 children that was previously deleted") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisObjectNotFoundException.class}) + public void getDescendantsForDeletedParentFolderWithAtLeast2Children() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite).createFolder(testFolder) + .and().usingResource(testFolder).createFile(testFile) + .and().createFolder(folderModel) + .and().usingResource(testFolder).deleteFolderTree() + .then().usingResource(testFolder) + .assertThat().hasDescendants(1, folderModel, testFile); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site collaborator can get descendants for parent folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteCollaboratorCanGetDescendantsForValidFolderCreatedBySelf() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingSite(testSite) + .createFolder(testFolder) + .usingResource(testFolder).createFile(testFile) + .usingResource(testFolder).assertThat().hasDescendants(-1, testFile); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site collaborator can get descendants for parent folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteCollaboratorCanGetDescendantsForValidFolderCreatedByManager() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(testFolder) + .usingResource(testFolder).createFile(testFile); + + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingResource(testFolder) + .assertThat().hasDescendants(-1, testFile); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site contributor can get descendants for parent folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteContributorCanGetDescendantsForValidFolderCreatedBySelf() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingSite(testSite) + .createFolder(testFolder) + .usingResource(testFolder).createFile(testFile) + .usingResource(testFolder).assertThat().hasDescendants(-1, testFile); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site contributor can get descendants for parent folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteContributorCanGetDescendantsForValidFolderCreatedByManager() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(testFolder) + .usingResource(testFolder).createFile(testFile); + + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingResource(testFolder) + .assertThat().hasDescendants(-1, testFile); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site consumer can get descendants for parent folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteConsumerCanGetDescendantsForValidFolder() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(testFolder) + .usingResource(testFolder).createFile(testFile); + + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).usingResource(testFolder) + .assertThat().hasDescendants(-1, testFile); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify that non site member cannot get descendants for a folder from a private site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions={ CmisPermissionDeniedException.class, CmisUnauthorizedException.class }) + public void nonSiteMemberCannotGetDescendantsAFolderFromAPrivateSite() throws Exception + { + SiteModel privateSite = dataSite.usingAdmin().createPrivateRandomSite(); + + cmisApi.authenticateUser(dataUser.getAdminUser()).usingSite(privateSite) + .createFolder(testFolder) + .usingResource(testFolder).createFile(testFile); + + cmisApi.authenticateUser(testUser).usingResource(testFolder) + .assertThat().hasDescendants(-1, testFile); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify that non site member cannot get descendants for a folder from a moderated site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions={ CmisPermissionDeniedException.class, CmisUnauthorizedException.class }) + public void nonSiteMemberCannotGetDescendantsAFolderFromAModeratedSite() throws Exception + { + SiteModel moderatedSite = dataSite.usingAdmin().createModeratedRandomSite(); + + cmisApi.authenticateUser(dataUser.getAdminUser()).usingSite(moderatedSite) + .createFolder(testFolder) + .usingResource(testFolder).createFile(testFile); + + cmisApi.authenticateUser(testUser).usingResource(testFolder) + .assertThat().hasDescendants(-1, testFile); + } +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetExtensionTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetExtensionTests.java new file mode 100644 index 0000000000..83ac7bd406 --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetExtensionTests.java @@ -0,0 +1,153 @@ +package org.alfresco.cmis; + +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +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.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class GetExtensionTests extends CmisTest +{ + UserModel testUser, nonInvitedUser; + SiteModel testSite; + FileModel testFile, managerFile; + FolderModel managerFolder; + private DataUser.ListUserWithRoles usersWithRoles; + private String titledAspect = "P:cm:titled"; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + managerFile = FileModel.getRandomFileModel(FileType.XML, documentContent); + managerFolder = FolderModel.getRandomFolderModel(); + testUser = dataUser.createRandomTestUser(); + nonInvitedUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(testUser).createPublicRandomSite(); + usersWithRoles = dataUser.usingUser(testUser) + .addUsersWithRolesToSite(testSite, UserRole.SiteContributor, UserRole.SiteCollaborator, UserRole.SiteConsumer); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(managerFile) + .createFolder(managerFolder); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Site manager can get extensions from a valid folder") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void siteManagerCanGetExtensionsForValidFolder() throws Exception + { + cmisApi.authenticateUser(testUser).usingResource(managerFolder) + .assertThat().hasAspectExtension(titledAspect); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Site manager can get extensions from a valid file") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void siteManagerCanGetExtensionsForValidFile() throws Exception + { + cmisApi.authenticateUser(testUser).usingResource(managerFile) + .assertThat().hasAspectExtension(titledAspect); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Site manager cannot get extensions from an invalid document - that was deleted") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisObjectNotFoundException.class}) + public void siteManagerCannotGetExtensionsForInvalidDocument() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD); + cmisApi.authenticateUser(testUser).usingSite(testSite).createFile(testFile) + .then().assertThat().hasAspectExtension(titledAspect) + .and().delete() + .then().assertThat().hasAspectExtension(titledAspect); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Site manager can get extensions from checkedout document") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanGetExtensionsForCheckedOutDocument() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD, documentContent); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).checkOut() + .then().assertThat().hasAspectExtension(titledAspect) + .then().usingPWCDocument() + .assertThat().hasAspectExtension(titledAspect); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Site collaborator can get extensions") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void collaboratorCanGetExtensions() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingResource(managerFolder) + .assertThat().hasAspectExtension(titledAspect) + .then().usingResource(managerFile) + .assertThat().hasAspectExtension(titledAspect); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Site contributor can get extensions") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void contributorCanGetExtensions() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingResource(managerFolder) + .assertThat().hasAspectExtension(titledAspect) + .then().usingResource(managerFile) + .assertThat().hasAspectExtension(titledAspect); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Site consumer can get extensions") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void consumerCanGetExtensions() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingResource(managerFolder) + .assertThat().hasAspectExtension(titledAspect) + .then().usingResource(managerFile) + .assertThat().hasAspectExtension(titledAspect); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Non invited user can get extensions in public site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void nonInvitedUserCanGetExtensionsInPublicSite() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingResource(managerFolder) + .assertThat().hasAspectExtension(titledAspect) + .then().usingResource(managerFile) + .assertThat().hasAspectExtension(titledAspect); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Non invited user cannot get extensions in private site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void nonInvitedUserCannotGetExtensionsInPrivateSite() throws Exception + { + SiteModel privateSite = dataSite.usingUser(testUser).createPrivateRandomSite(); + FileModel privateDoc = FileModel.getRandomFileModel(FileType.HTML, documentContent); + cmisApi.authenticateUser(testUser).usingSite(privateSite) + .createFile(privateDoc) + .then().authenticateUser(nonInvitedUser).assertThat().hasAspectExtension(titledAspect); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Non invited user cannot get extensions in moderated site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void nonInvitedUserCannotGetExtensionsInModeratedSite() throws Exception + { + SiteModel moderatedSite = dataSite.usingUser(testUser).createPrivateRandomSite(); + FileModel moderatedDoc = FileModel.getRandomFileModel(FileType.HTML, documentContent); + cmisApi.authenticateUser(testUser).usingSite(moderatedSite) + .createFile(moderatedDoc) + .then().authenticateUser(nonInvitedUser).assertThat().hasAspectExtension(titledAspect); + } +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetFolderParentTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetFolderParentTests.java new file mode 100644 index 0000000000..946b8c7e21 --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetFolderParentTests.java @@ -0,0 +1,151 @@ +package org.alfresco.cmis; + +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.*; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +public class GetFolderParentTests extends CmisTest +{ + UserModel testUser; + SiteModel testSite; + FolderModel testFolder; + FolderModel parentFolder; + DataUser.ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + testUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(testUser).createPublicRandomSite(); + usersWithRoles = dataUser.addUsersWithRolesToSite(testSite, UserRole.SiteCollaborator, UserRole.SiteContributor, UserRole.SiteConsumer); + } + + @BeforeMethod(alwaysRun = true) + public void generateRandomContent() + { + parentFolder = FolderModel.getRandomFolderModel(); + testFolder = FolderModel.getRandomFolderModel(); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.SANITY, description = "Verify folder parent") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void verifyFolderParent() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite).createFolder(testFolder) + .and().assertThat().existsInRepo() + .and().usingResource(testFolder).createFolder(FolderModel.getRandomFolderModel()) + .then().assertThat().folderHasParent(testFolder); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, description = "Verify folder parent that was previously deleted") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisObjectNotFoundException.class}) + public void verifyFolderParentThatWasDeleted() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite).createFolder(parentFolder) + .and().assertThat().existsInRepo() + .and().usingResource(parentFolder).createFolder(testFolder) + .then().assertThat().folderHasParent(parentFolder) + .and().usingResource(parentFolder).deleteFolderTree() + .then().usingResource(testFolder).assertThat().folderHasParent(parentFolder); + } + + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site contributor can get folder parent") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteContributorVerifyFolderParentCreatedBySelf() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingSite(testSite).createFolder(testFolder) + .and().assertThat().existsInRepo() + .and().usingResource(testFolder).createFolder(FolderModel.getRandomFolderModel()) + .then().assertThat().folderHasParent(testFolder); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site contributor can get folder parent") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteContributorVerifyFolderParentCreatedByManager() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite).createFolder(parentFolder) + .and().assertThat().existsInRepo() + .and().usingResource(parentFolder).createFolder(testFolder); + + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingResource(testFolder) + .assertThat().folderHasParent(parentFolder); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site collaborator can get folder parent") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteCollaboratorVerifyFolderParentCreatedBySelf() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingSite(testSite).createFolder(testFolder) + .and().assertThat().existsInRepo() + .and().usingResource(testFolder).createFolder(FolderModel.getRandomFolderModel()) + .then().assertThat().folderHasParent(testFolder); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site collaborator can get folder parent") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteCollaboratorVerifyFolderParentCreatedByManager() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite).createFolder(parentFolder) + .and().assertThat().existsInRepo() + .and().usingResource(parentFolder).createFolder(testFolder); + + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingResource(testFolder) + .assertThat().folderHasParent(parentFolder); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site consumer can get folder parent") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteConsumerVerifyFolderParent() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite).createFolder(parentFolder) + .and().assertThat().existsInRepo() + .and().usingResource(parentFolder).createFolder(testFolder); + + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).usingResource(testFolder) + .assertThat().folderHasParent(parentFolder); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify non site member for a private site is not able to get folder parent") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions={ CmisPermissionDeniedException.class, CmisUnauthorizedException.class }) + public void nonSiteMemberGetFolderParentFromPrivateSite() throws Exception + { + SiteModel privateSite = dataSite.usingAdmin().createPrivateRandomSite(); + + cmisApi.authenticateUser(dataUser.getAdminUser()).usingSite(privateSite).createFolder(parentFolder) + .and().assertThat().existsInRepo() + .and().usingResource(parentFolder).createFolder(testFolder); + + cmisApi.authenticateUser(testUser).usingResource(testFolder) + .assertThat().folderHasParent(parentFolder); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify non site member for a moderated site is not able to get folder parent") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions={ CmisPermissionDeniedException.class, CmisUnauthorizedException.class }) + public void nonSiteMemberGetFolderParentFromModeratedSite() throws Exception + { + SiteModel moderatedSite = dataSite.usingAdmin().createModeratedRandomSite(); + + cmisApi.authenticateUser(dataUser.getAdminUser()).usingSite(moderatedSite).createFolder(parentFolder) + .and().assertThat().existsInRepo() + .and().usingResource(parentFolder).createFolder(testFolder); + + cmisApi.authenticateUser(testUser).usingResource(testFolder) + .assertThat().folderHasParent(parentFolder); + } +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetFolderTreeTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetFolderTreeTests.java new file mode 100644 index 0000000000..93f389b707 --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetFolderTreeTests.java @@ -0,0 +1,211 @@ +package org.alfresco.cmis; + +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.*; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +public class GetFolderTreeTests extends CmisTest +{ + UserModel testUser; + SiteModel testSite; + FolderModel testFolder; + FolderModel folderModel1; + FolderModel folderModel11; + FolderModel folderModel12; + FolderModel folderModel2; + DataUser.ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + testUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(testUser).createPublicRandomSite(); + usersWithRoles = dataUser.addUsersWithRolesToSite(testSite, UserRole.SiteCollaborator, UserRole.SiteContributor, UserRole.SiteConsumer); + } + + @BeforeMethod(alwaysRun = true) + public void generateRandomContent() + { + testFolder = FolderModel.getRandomFolderModel(); + folderModel1 = FolderModel.getRandomFolderModel(); + folderModel11 = FolderModel.getRandomFolderModel(); + folderModel12 = FolderModel.getRandomFolderModel(); + folderModel2 = FolderModel.getRandomFolderModel(); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.SANITY, + description = "Verify site manager can get folder tree for valid parent folder with at least 2 children" + + " folders and depth set to 1") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void getFolderTreeForValidParentFolderWithAtLeast2ChildrenFoldersAndDepthGreaterThan1() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite).createFolder(testFolder) + .and().assertThat().existsInRepo() + .and().usingResource(testFolder) + .and().createFolder(folderModel1) + .and().createFolder(folderModel2) + .then().usingResource(testFolder).assertThat().hasFolderTree(1, folderModel1, folderModel2); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.SANITY, + description = "Verify site manager can get folder tree for valid parent folder with at least 2 children" + + " folders and depth set to -1") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void getFolderTreeForValidParentFolderWithAtLeast2ChildrenFoldersAndDepthSetToMinus1() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite).createFolder(testFolder) + .and().assertThat().existsInRepo() + .and().usingResource(testFolder) + .and().createFolder(folderModel1) + .and().usingResource(folderModel1).createFolder(folderModel2) + .then().usingResource(testFolder).assertThat().hasFolderTree(-1, folderModel1, folderModel2); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager can NOT get folder tree for valid parent folder with at least 2 children" + + " folders and depth set to 0") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisInvalidArgumentException.class}) + public void getFolderTreeForValidParentFolderWithAtLeast2ChildrenFoldersAndDepthSetTo0() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite).createFolder(testFolder) + .and().assertThat().existsInRepo() + .and().usingResource(testFolder) + .and().createFolder(folderModel11) + .and().createFolder(folderModel12) + .and().usingResource(folderModel11).createFolder(folderModel2) + .then().usingResource(testFolder) + .assertThat().hasFolderTree(0, folderModel11); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager can NOT get folder tree for valid parent folder with at least 2 children" + + " folders and depth set to -2") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisInvalidArgumentException.class}) + public void getFolderTreeForValidParentFolderWithAtLeast2ChildrenFoldersAndDepthSetToMinus2() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite).createFolder(testFolder) + .and().assertThat().existsInRepo() + .and().usingResource(testFolder) + .and().createFolder(folderModel11) + .and().createFolder(folderModel12) + .and().usingResource(folderModel11).createFolder(folderModel2) + .then().usingResource(testFolder) + .assertThat().hasFolderTree(-2, folderModel11); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager can NOT get folder tree for parent folder with children" + + " that was previously deleted") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisObjectNotFoundException.class}) + public void getFolderTreeForDeletedParentFolderWithChildren() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite).createFolder(testFolder) + .and().assertThat().existsInRepo() + .and().usingResource(testFolder) + .and().createFolder(folderModel11) + .and().createFolder(folderModel12) + .and().usingResource(folderModel11).createFolder(folderModel2) + .and().usingResource(testFolder).deleteFolderTree() + .then().usingResource(testFolder) + .assertThat().hasFolderTree(1, folderModel11); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site collaborator can get folder tree for valid parent folder with at least 2 children folders") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteCollaboratorCanGetFolderTreeForValidParentFolder() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingSite(testSite) + .createFolder(testFolder) + .usingResource(testFolder).createFolder(folderModel1).and().createFolder(folderModel2) + .usingResource(testFolder).assertThat().hasFolderTree(-1, folderModel1, folderModel2); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site collaborator can get folder tree for valid parent folder with at least 2 children folders") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteCollaboratorCanGetFolderTreeForValidParentFolderCreatedByManager() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite).createFolder(testFolder) + .usingResource(testFolder).createFolder(folderModel1).and().createFolder(folderModel2); + + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .usingResource(testFolder).assertThat().hasFolderTree(-1, folderModel1, folderModel2); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site contributor can get folder tree for valid parent folder with at least 2 children folders") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteContributorCanGetFolderTreeForValidParentFolder() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingSite(testSite) + .createFolder(testFolder) + .usingResource(testFolder).createFolder(folderModel1).and().createFolder(folderModel2) + .usingResource(testFolder).assertThat().hasFolderTree(-1, folderModel1, folderModel2); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site contributor can get folder tree for valid parent folder with at least 2 children folders") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteContributorCanGetFolderTreeForValidParentFolderCreatedByManager() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(testFolder) + .usingResource(testFolder).createFolder(folderModel1).and().createFolder(folderModel2); + + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .usingResource(testFolder).assertThat().hasFolderTree(-1, folderModel1, folderModel2); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site consumer can get folder tree for valid parent folder with at least 2 children folders") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteConsumerCanGetFolderTreeForValidParentFolder() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(testFolder) + .usingResource(testFolder).createFolder(folderModel1).and().createFolder(folderModel2); + + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .usingResource(testFolder).assertThat().hasFolderTree(-1, folderModel1, folderModel2); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify non site member of a private site cannot get folder tree for valid parent folder with at least 2 children folders") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions={ CmisPermissionDeniedException.class, CmisUnauthorizedException.class }) + public void nonSiteMemberCannotGetFolderTreeForAFolderFromAPrivateSite() throws Exception + { + SiteModel privateSite = dataSite.usingAdmin().createPrivateRandomSite(); + + cmisApi.authenticateUser(dataUser.getAdminUser()).usingSite(privateSite) + .createFolder(testFolder) + .usingResource(testFolder).createFolder(folderModel1).and().createFolder(folderModel2); + + cmisApi.authenticateUser(testUser).usingResource(testFolder) + .assertThat().hasFolderTree(-1, folderModel1, folderModel2); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify non site member of a moderated site cannot get folder tree for valid parent folder with at least 2 children folders") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions={ CmisPermissionDeniedException.class, CmisUnauthorizedException.class }) + public void nonSiteMemberCannotGetFolderTreeForAFolderFromAModeratedSite() throws Exception + { + SiteModel moderatedSite = dataSite.usingAdmin().createModeratedRandomSite(); + + cmisApi.authenticateUser(dataUser.getAdminUser()).usingSite(moderatedSite) + .createFolder(testFolder) + .usingResource(testFolder).createFolder(folderModel1).and().createFolder(folderModel2); + + cmisApi.authenticateUser(testUser).usingResource(testFolder) + .assertThat().hasFolderTree(-1, folderModel1, folderModel2); + } +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetObjectOfLatestVersionTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetObjectOfLatestVersionTests.java new file mode 100644 index 0000000000..a230df2d39 --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetObjectOfLatestVersionTests.java @@ -0,0 +1,202 @@ +package org.alfresco.cmis; + +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.enums.VersioningState; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class GetObjectOfLatestVersionTests extends CmisTest +{ + UserModel testUser, nonInvitedUser; + SiteModel testSite; + FileModel testFile, managerFile; + private DataUser.ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + managerFile = FileModel.getRandomFileModel(FileType.HTML, documentContent); + testUser = dataUser.createRandomTestUser(); + nonInvitedUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(testUser).createPublicRandomSite(); + usersWithRoles = dataUser.usingUser(testUser) + .addUsersWithRolesToSite(testSite, UserRole.SiteContributor, UserRole.SiteCollaborator, UserRole.SiteConsumer); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(managerFile).assertThat().existsInRepo() + .then().checkOut() + .and().prepareDocumentForCheckIn().withMajorVersion().checkIn() + .then().checkOut() + .and().prepareDocumentForCheckIn().withMinorVersion().checkIn(); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.SANITY, + description = "Verify site manager is able to get last major version for document checked in with minor version") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void siteManagerShouldGetLastMajorVersionForDocumentCheckedInWithMajorVersion() throws Exception + { + cmisApi.authenticateUser(testUser).usingResource(managerFile) + .usingVersion().assertLatestMajorVersionIs(2.0); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.SANITY, + description = "Verify site manager is able to get last minor version for document checked in with major version") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void siteManagerShouldGetLastMinorVersionForDocumentCheckedInWithMajorVersion() throws Exception + { + cmisApi.authenticateUser(testUser).usingResource(managerFile) + .usingVersion().assertLatestMinorVersionIs(2.1); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is NOT able to get last major version for document that was already deleted") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisObjectNotFoundException.class}) + public void siteManagerCannotGetLastMajorVersionForInexistentDocument() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite).createFile(testFile) + .and().assertThat().existsInRepo() + .and().checkOut() + .and().prepareDocumentForCheckIn().withMajorVersion().checkIn() + .then().usingVersion().assertLatestMajorVersionIs(2.0) + .and().delete() + .then().usingVersion().assertLatestMajorVersionIs(2.0); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is able to get last major version for document that was checked out") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanGetLastMajorVersionForCheckedOutDocument() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite).createFile(testFile) + .and().assertThat().existsInRepo() + .and().checkOut() + .and().prepareDocumentForCheckIn().withMajorVersion().checkIn() + .usingVersion().assertLatestMajorVersionIs(2.0) + .checkOut() + .then().usingVersion().assertLatestMajorVersionIs(2.0); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is able to get last minor version for document created with minor VersioningState") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanGetLastMinorVersionForDocumentWithMinorVersioningState() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile, VersioningState.MINOR).and().assertThat().existsInRepo() + .then().usingVersion().assertLatestMinorVersionIs(0.1); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is not able to get last major version for document created with minor VersioningState") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisObjectNotFoundException.class, + expectedExceptionsMessageRegExp="There is no major version!*") + public void siteManagerCannotGetLastMajorVersionForDocumentWithMinorVersioningState() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile, VersioningState.MINOR).and().assertThat().existsInRepo() + .then().usingVersion().assertLatestMajorVersionIs(0.1); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is able to get last minor version for document created with checked out VersioningState") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanGetLastVersionForDocumentWithCheckedOutVersioningState() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile, VersioningState.CHECKEDOUT).and().assertThat().existsInRepo() + .then().usingVersion().assertLatestMinorVersionIs(1.0) + .usingVersion().assertLatestMajorVersionIs(1.0) + .then().usingPWCDocument() + .usingVersion().assertLatestMajorVersionIs(1.0) + .usingVersion().assertLatestMinorVersionIs(1.0); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site collaborator is able to get last versions for document created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void collaboratorCanGetLastVersionsForDocumentCreatedByManager() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .usingResource(managerFile) + .usingVersion().assertLatestMinorVersionIs(2.1) + .usingVersion().assertLatestMajorVersionIs(2.0); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site contributor is able to get last versions for document created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void contributorCanGetLastVersionsForDocumentCreatedByManager() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .usingResource(managerFile) + .usingVersion().assertLatestMinorVersionIs(2.1) + .usingVersion().assertLatestMajorVersionIs(2.0); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site consumer is able to get last versions for document created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void consumerCanGetLastVersionsForDocumentCreatedByManager() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .usingResource(managerFile) + .usingVersion().assertLatestMinorVersionIs(2.1) + .usingVersion().assertLatestMajorVersionIs(2.0); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify non invited user is able to get last versions for document created in public site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void nonInvitedUserCanGetLastVersionsForDocumentInPublicSite() throws Exception + { + cmisApi.authenticateUser(nonInvitedUser) + .usingResource(managerFile) + .usingVersion().assertLatestMinorVersionIs(2.1) + .usingVersion().assertLatestMajorVersionIs(2.0); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify non invited user is not able to get last versions for document from private site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void nonInvitedUserCannotGetLastVersionsForDocumentCreatedByManagerInPrivateSite() throws Exception + { + SiteModel privateSite = dataSite.createPrivateRandomSite(); + FileModel privateDoc = FileModel.getRandomFileModel(FileType.XML, documentContent); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .usingSite(privateSite) + .createFile(privateDoc) + .then().checkOut() + .and().prepareDocumentForCheckIn().withMajorVersion().checkIn() + .authenticateUser(nonInvitedUser).usingVersion().assertLatestMinorVersionIs(2.0); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify non invited user is not able to get last versions for document from moderated site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void nonInvitedUserCannotGetLastVersionsForDocumentCreatedByManagerInModeratedSite() throws Exception + { + SiteModel moderatedSite = dataSite.createModeratedRandomSite(); + FileModel moderatedDoc = FileModel.getRandomFileModel(FileType.XML, documentContent); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .usingSite(moderatedSite) + .createFile(moderatedDoc) + .then().checkOut() + .and().prepareDocumentForCheckIn().withMajorVersion().checkIn() + .authenticateUser(nonInvitedUser).usingVersion().assertLatestMinorVersionIs(2.0); + } +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetObjectTypeTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetObjectTypeTests.java new file mode 100644 index 0000000000..bf5d3a2057 --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetObjectTypeTests.java @@ -0,0 +1,191 @@ +package org.alfresco.cmis; + +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.*; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.enums.BaseTypeId; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class GetObjectTypeTests extends CmisTest +{ + UserModel siteManager; + SiteModel testSite; + FolderModel testFolder; + FileModel testFile; + DataUser.ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + siteManager = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(siteManager).createPublicRandomSite(); + usersWithRoles = dataUser.addUsersWithRolesToSite(testSite, UserRole.SiteCollaborator, UserRole.SiteContributor, UserRole.SiteConsumer); + + testFolder = FolderModel.getRandomFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.MSWORD); + + cmisApi.authenticateUser(siteManager).usingSite(testSite) + .createFolder(testFolder).and().assertThat().existsInRepo() + .createFile(testFile).and().assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.SANITY, + description = "Verify CMIS folder type") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void verifyCmisFolderType() throws Exception + { + cmisApi.authenticateUser(siteManager).usingSite(testSite) + .usingResource(testFolder) + .assertThat().baseTypeIdIs(BaseTypeId.CMIS_FOLDER.value()); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.SANITY, + description = "Verify CMIS document type") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void verifyCmisDocumentType() throws Exception + { + cmisApi.authenticateUser(siteManager).usingSite(testSite) + .usingResource(testFile) + .assertThat().baseTypeIdIs(BaseTypeId.CMIS_DOCUMENT.value()); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify CMIS folder type of folder that was deleted") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisObjectNotFoundException.class}) + public void verifyCmisFolderTypeOfDeletedFolder() throws Exception + { + FolderModel folderModel = FolderModel.getRandomFolderModel(); + + cmisApi.authenticateUser(siteManager).usingSite(testSite).createFolder(folderModel) + .usingResource(folderModel).delete() + .assertThat().baseTypeIdIs(BaseTypeId.CMIS_FOLDER.value()); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify CMIS document type of file that was deleted") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisObjectNotFoundException.class}) + public void verifyCmisDocumentTypeOfDeletedDocument() throws Exception + { + FileModel fileModel = FileModel.getRandomFileModel(FileType.MSWORD); + + cmisApi.authenticateUser(siteManager).usingSite(testSite).createFile(fileModel) + .usingResource(fileModel).delete() + .assertThat().baseTypeIdIs(BaseTypeId.CMIS_DOCUMENT.value()); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Site contributor verifies CMIS document type") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteContributorVerifiesCmisDocumentType() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingResource(testFile) + .assertThat().baseTypeIdIs(BaseTypeId.CMIS_DOCUMENT.value()); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Site contributor verifies CMIS folder type") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteContributorVerifiesCmisFolderType() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingResource(testFolder) + .assertThat().baseTypeIdIs(BaseTypeId.CMIS_FOLDER.value()); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Site collaborator verifies CMIS document type") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteCollaboratorVerifiesCmisDocumentType() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingResource(testFile) + .assertThat().baseTypeIdIs(BaseTypeId.CMIS_DOCUMENT.value()); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Site collaborator verifies CMIS folder type") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteCollaboratorVerifiesCmisFolderType() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingResource(testFolder) + .assertThat().baseTypeIdIs(BaseTypeId.CMIS_FOLDER.value()); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Site consumer verifies CMIS document type") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteConsumerVerifiesCmisDocumentType() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).usingResource(testFile) + .assertThat().baseTypeIdIs(BaseTypeId.CMIS_DOCUMENT.value()); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Site consumer verifies CMIS folder type") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteConsumerVerifiesCmisFolderType() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).usingResource(testFolder) + .assertThat().baseTypeIdIs(BaseTypeId.CMIS_FOLDER.value()); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Non site member is not able to verify CMIS document type for a document from a private site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void nonSiteMemberCannotVerifyCmisObjectTypeForADocumentFromPrivateSite() throws Exception + { + SiteModel privateSite = dataSite.usingAdmin().createPrivateRandomSite(); + FileModel privateSiteFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + + cmisApi.authenticateUser(dataUser.getAdminUser()).usingSite(privateSite).createFile(privateSiteFile); + + cmisApi.authenticateUser(siteManager).usingResource(privateSiteFile) + .assertThat().baseTypeIdIs(BaseTypeId.CMIS_DOCUMENT.value()); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Non site member is not able to verify CMIS document type for a folder from a private site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void nonSiteMemberCannotVerifyCmisFolderTypeForAFolderFromPrivateSite() throws Exception + { + SiteModel privateSite = dataSite.usingAdmin().createPrivateRandomSite(); + FolderModel privateSiteFolder = FolderModel.getRandomFolderModel(); + + cmisApi.authenticateUser(dataUser.getAdminUser()).usingSite(privateSite).createFolder(privateSiteFolder); + + cmisApi.authenticateUser(siteManager).usingResource(privateSiteFolder) + .assertThat().baseTypeIdIs(BaseTypeId.CMIS_FOLDER.value()); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Non site member is not able to verify CMIS document type for a document from a moderated site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void nonSiteMemberCannotVerifyCmisObjectTypeForADocumentFromModeratedSite() throws Exception + { + SiteModel moderatedSite = dataSite.usingAdmin().createModeratedRandomSite(); + FileModel moderatedSiteFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + + cmisApi.authenticateUser(dataUser.getAdminUser()).usingSite(moderatedSite).createFile(moderatedSiteFile); + + cmisApi.authenticateUser(siteManager).usingResource(moderatedSiteFile) + .assertThat().baseTypeIdIs(BaseTypeId.CMIS_DOCUMENT.value()); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Non site member is not able to verify CMIS document type for a folder from a moderated site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void nonSiteMemberCannotVerifyCmisObjectTypeForAFolderFromModeratedSite() throws Exception + { + SiteModel moderatedSite = dataSite.usingAdmin().createModeratedRandomSite(); + FolderModel moderatedSiteFolder = FolderModel.getRandomFolderModel(); + + cmisApi.authenticateUser(dataUser.getAdminUser()).usingSite(moderatedSite).createFolder(moderatedSiteFolder); + + cmisApi.authenticateUser(siteManager).usingResource(moderatedSiteFolder) + .assertThat().baseTypeIdIs(BaseTypeId.CMIS_FOLDER.value()); + } +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetParentsTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetParentsTests.java new file mode 100644 index 0000000000..49b67b613a --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetParentsTests.java @@ -0,0 +1,263 @@ +package org.alfresco.cmis; + +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +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.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 10/5/2016. + */ +public class GetParentsTests extends CmisTest +{ + UserModel testUser; + SiteModel testSite; + FolderModel testFolder, parentFolder; + FileModel testFile; + DataUser.ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + testUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(testUser).createPublicRandomSite(); + usersWithRoles = dataUser.addUsersWithRolesToSite(testSite, UserRole.SiteCollaborator, UserRole.SiteContributor, UserRole.SiteConsumer); + } + + @BeforeMethod(alwaysRun = true) + public void generateRandomContent() + { + parentFolder = FolderModel.getRandomFolderModel(); + testFolder = FolderModel.getRandomFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.MSWORD); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify site manager is able to get file parents with CMIS") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void siteManagerGetsFileParents() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(testFolder).and().assertThat().existsInRepo() + .createFolder(parentFolder).and().assertThat().existsInRepo() + .usingResource(parentFolder).createFile(testFile).and().assertThat().existsInRepo() + .addDocumentToFolder(testFolder, true).and().assertThat().existsInRepo() + .then().assertThat().hasParents(testFolder.getName(), parentFolder.getName()); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify site manager is able to get folder parents with CMIS") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void siteManagerGetsFolderParents() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(parentFolder).and().assertThat().existsInRepo() + .usingResource(parentFolder).createFolder(testFolder).and().assertThat().existsInRepo() + .then().assertThat().hasParents(parentFolder.getName()); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is NOT able to get parents for an inexistent folder with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisObjectNotFoundException.class}) + public void siteManagerCannotGetInexistentFolderParents() throws Exception + { + FolderModel inexistentFolder = FolderModel.getRandomFolderModel(); + inexistentFolder.setCmisLocation("/" + inexistentFolder.getName() + "/"); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(parentFolder).and().assertThat().existsInRepo() + .and().usingResource(inexistentFolder).assertThat().hasParents(parentFolder.getName()); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site contributor is able to get folder parents with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteContributorGetsFolderParentsCreatedBySelf() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingSite(testSite) + .createFolder(parentFolder).and().assertThat().existsInRepo() + .usingResource(parentFolder).createFolder(testFolder).and().assertThat().existsInRepo() + .then().assertThat().hasParents(parentFolder.getName()); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site contributor is able to get file parents with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteContributorGetsFileParentsCreatedBySelf() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingSite(testSite) + .createFolder(parentFolder).and().assertThat().existsInRepo() + .usingResource(parentFolder).createFile(testFile).and().assertThat().existsInRepo() + .assertThat().hasParents(parentFolder.getName()); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site contributor is able to get folder parents with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteContributorGetsFolderParentsCreatedByManager() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(parentFolder).and().assertThat().existsInRepo() + .usingResource(parentFolder).createFolder(testFolder).and().assertThat().existsInRepo(); + + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingResource(testFolder) + .assertThat().hasParents(parentFolder.getName()); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site contributor is able to get file parents with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteContributorGetsFileParentsCreatedByManager() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(parentFolder).and().assertThat().existsInRepo() + .usingResource(parentFolder).createFolder(testFolder).and().assertThat().existsInRepo() + .usingResource(testFolder).createFile(testFile).and().assertThat().existsInRepo(); + + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingResource(testFile) + .assertThat().hasParents(testFolder.getName()); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site collaborator is able to get folder parents with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteCollaboratorGetsFolderParentsCreatedBySelf() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingSite(testSite) + .createFolder(parentFolder).and().assertThat().existsInRepo() + .usingResource(parentFolder).createFolder(testFolder).and().assertThat().existsInRepo() + .then().assertThat().hasParents(parentFolder.getName()); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site collaborator is able to get file parents with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteCollaboratorGetsFileParentsCreatedBySelf() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingSite(testSite) + .createFolder(parentFolder).and().assertThat().existsInRepo() + .usingResource(parentFolder).createFile(testFile).and().assertThat().existsInRepo() + .assertThat().hasParents(parentFolder.getName()); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site collaborator is able to get folder parents with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteCollaboratorGetsFolderParentsCreatedByManager() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(parentFolder).and().assertThat().existsInRepo() + .usingResource(parentFolder).createFolder(testFolder).and().assertThat().existsInRepo(); + + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingResource(testFolder) + .assertThat().hasParents(parentFolder.getName()); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site collaborator is able to get file parents with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteCollaboratorGetsFileParentsCreatedByManager() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(parentFolder).and().assertThat().existsInRepo() + .usingResource(parentFolder).createFolder(testFolder).and().assertThat().existsInRepo() + .usingResource(testFolder).createFile(testFile).and().assertThat().existsInRepo(); + + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingResource(testFile) + .assertThat().hasParents(testFolder.getName()); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site consumer is able to get folder parents with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteConsumerGetsFolderParents() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(parentFolder).and().assertThat().existsInRepo() + .usingResource(parentFolder).createFolder(testFolder).and().assertThat().existsInRepo(); + + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).usingResource(testFolder) + .assertThat().hasParents(parentFolder.getName()); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site consumer is able to get file parents with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteConsumerGetsFileParents() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(parentFolder).and().assertThat().existsInRepo() + .usingResource(parentFolder).createFolder(testFolder).and().assertThat().existsInRepo() + .usingResource(testFolder).createFile(testFile).and().assertThat().existsInRepo(); + + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).usingResource(testFile) + .assertThat().hasParents(testFolder.getName()); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify non site member for a private site is not able to get folder parents with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void nonSiteMemberGetsFolderParentsFromPrivateSite() throws Exception + { + SiteModel privateSite = dataSite.usingAdmin().createPrivateRandomSite(); + cmisApi.authenticateUser(dataUser.getAdminUser()).usingSite(privateSite) + .createFolder(parentFolder).and().assertThat().existsInRepo() + .usingResource(parentFolder).createFolder(testFolder).and().assertThat().existsInRepo(); + + cmisApi.authenticateUser(testUser).usingResource(testFolder) + .assertThat().hasParents(parentFolder.getName()); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify non site member for a private site is not able to get file parents with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void nonSiteMemberGetsFileParentsFromPrivateSite() throws Exception + { + SiteModel privateSite = dataSite.usingAdmin().createPrivateRandomSite(); + cmisApi.authenticateUser(dataUser.getAdminUser()).usingSite(privateSite) + .createFolder(parentFolder).and().assertThat().existsInRepo() + .usingResource(parentFolder).createFile(testFile).and().assertThat().existsInRepo(); + + cmisApi.authenticateUser(testUser).usingResource(testFile) + .assertThat().hasParents(parentFolder.getName()); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify non site member for a moderated site is not able to get folder parents with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void nonSiteMemberGetsFolderParentsFromModeratedSite() throws Exception + { + SiteModel moderatedSite = dataSite.usingAdmin().createModeratedRandomSite(); + cmisApi.authenticateUser(dataUser.getAdminUser()).usingSite(moderatedSite) + .createFolder(parentFolder).and().assertThat().existsInRepo() + .usingResource(parentFolder).createFolder(testFolder).and().assertThat().existsInRepo(); + + cmisApi.authenticateUser(testUser).usingResource(testFolder) + .assertThat().hasParents(parentFolder.getName()); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify non site member for a moderated site is not able to get file parents with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void nonSiteMemberGetsFileParentsFromModeratedSite() throws Exception + { + SiteModel moderatedSite = dataSite.usingAdmin().createModeratedRandomSite(); + cmisApi.authenticateUser(dataUser.getAdminUser()).usingSite(moderatedSite) + .createFolder(parentFolder).and().assertThat().existsInRepo() + .usingResource(parentFolder).createFile(testFile).and().assertThat().existsInRepo(); + + cmisApi.authenticateUser(testUser).usingResource(testFile) + .assertThat().hasParents(parentFolder.getName()); + } +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetPropertiesTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetPropertiesTests.java new file mode 100644 index 0000000000..6503983bf2 --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetPropertiesTests.java @@ -0,0 +1,266 @@ +package org.alfresco.cmis; + +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.*; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +public class GetPropertiesTests extends CmisTest +{ + UserModel testUser; + SiteModel testSite; + FileModel testFile; + FolderModel testFolder; + DataUser.ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + testUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(testUser).createPublicRandomSite(); + usersWithRoles = dataUser.addUsersWithRolesToSite(testSite, UserRole.SiteManager, UserRole.SiteCollaborator, + UserRole.SiteContributor, UserRole.SiteConsumer); + } + + @BeforeMethod(alwaysRun = true) + public void generateRandomContent() + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + testFolder = FolderModel.getRandomFolderModel(); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.SANITY, + description = "Verify secondaryObjectTypeIds property for valid document") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void verifySecondaryObjectTypeIdsPropertyForValidDocument() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite).createFile(testFile) + .and().assertThat().existsInRepo() + .then().assertThat().objectHasProperty("cmis:secondaryObjectTypeIds", "Secondary Object Type Ids", + "secondaryObjectTypeIds", "cmis:secondaryObjectTypeIds", "P:cm:titled", "P:sys:localized"); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.SANITY, + description = "Verify secondaryObjectTypeIds property for valid folder") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void verifySecondaryObjectTypeIdsPropertyForValidFolder() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite).createFolder(testFolder) + .and().assertThat().existsInRepo() + .then().assertThat().objectHasProperty("cmis:secondaryObjectTypeIds", "Secondary Object Type Ids", + "secondaryObjectTypeIds", "cmis:secondaryObjectTypeIds", "P:cm:titled", "P:sys:localized"); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify secondaryObjectTypeIds property for inexistent folder (that was previously deleted)") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisObjectNotFoundException.class}) + public void verifySecondaryObjectTypeIdsPropertyForInexistentFolder() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite).createFolder(testFolder) + .then().assertThat().objectHasProperty("cmis:secondaryObjectTypeIds", "Secondary Object Type Ids", + "secondaryObjectTypeIds", "cmis:secondaryObjectTypeIds", "P:cm:titled", "P:sys:localized") + .and().usingResource(testFolder).deleteFolderTree() + .then().assertThat().objectHasProperty("cmis:secondaryObjectTypeIds", "Secondary Object Type Ids", + "secondaryObjectTypeIds", "cmis:secondaryObjectTypeIds", "P:cm:titled", "P:sys:localized"); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify secondaryObjectTypeIds property for valid folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void managerVerifiesSecondaryObjectTypeIdsPropertyForValidFolder() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite).createFolder(testFolder); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).usingSite(testSite).usingResource(testFolder) + .then().assertThat().objectHasProperty("cmis:secondaryObjectTypeIds", "Secondary Object Type Ids", + "secondaryObjectTypeIds", "cmis:secondaryObjectTypeIds", "P:cm:titled", "P:sys:localized"); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify secondaryObjectTypeIds property as site collaborator for valid document") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void collaboratorVerifiesSecondaryObjectTypeIdsPropertyForValidDocumentCreatedBySelf() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingSite(testSite).createFile(testFile) + .and().assertThat().existsInRepo() + .then().assertThat().objectHasProperty("cmis:secondaryObjectTypeIds", "Secondary Object Type Ids", + "secondaryObjectTypeIds", "cmis:secondaryObjectTypeIds", "P:cm:titled", "P:sys:localized"); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify secondaryObjectTypeIds property as site collaborator for valid folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void collaboratorVerifiesSecondaryObjectTypeIdsPropertyForValidFolderCreatedBySelf() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingSite(testSite).createFolder(testFolder) + .and().assertThat().existsInRepo() + .then().assertThat().objectHasProperty("cmis:secondaryObjectTypeIds", "Secondary Object Type Ids", + "secondaryObjectTypeIds", "cmis:secondaryObjectTypeIds", "P:cm:titled", "P:sys:localized"); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify secondaryObjectTypeIds property as site collaborator for valid document") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void collaboratorVerifiesSecondaryObjectTypeIdsPropertyForValidDocumentCreatedByManager() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite).createFile(testFile) + .and().assertThat().existsInRepo(); + + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingResource(testFile) + .assertThat().objectHasProperty("cmis:secondaryObjectTypeIds", "Secondary Object Type Ids", + "secondaryObjectTypeIds", "cmis:secondaryObjectTypeIds", "P:cm:titled", "P:sys:localized"); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify secondaryObjectTypeIds property as site collaborator for valid folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void collaboratorVerifiesSecondaryObjectTypeIdsPropertyForValidFolderCreatedByManager() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite).createFolder(testFolder) + .and().assertThat().existsInRepo(); + + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingResource(testFolder) + .assertThat().objectHasProperty("cmis:secondaryObjectTypeIds", "Secondary Object Type Ids", + "secondaryObjectTypeIds", "cmis:secondaryObjectTypeIds", "P:cm:titled", "P:sys:localized"); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify secondaryObjectTypeIds property as site contributor for valid document") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void contributorVerifiesSecondaryObjectTypeIdsPropertyForValidDocumentCreatedBySelf() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingSite(testSite).createFile(testFile) + .and().assertThat().existsInRepo() + .then().assertThat().objectHasProperty("cmis:secondaryObjectTypeIds", "Secondary Object Type Ids", + "secondaryObjectTypeIds", "cmis:secondaryObjectTypeIds", "P:cm:titled", "P:sys:localized"); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify secondaryObjectTypeIds property as site contributor for valid folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void contributorVerifiesSecondaryObjectTypeIdsPropertyForValidFolderCreatedBySelf() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingSite(testSite).createFolder(testFolder) + .and().assertThat().existsInRepo() + .then().assertThat().objectHasProperty("cmis:secondaryObjectTypeIds", "Secondary Object Type Ids", + "secondaryObjectTypeIds", "cmis:secondaryObjectTypeIds", "P:cm:titled", "P:sys:localized"); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify secondaryObjectTypeIds property as site contributor for valid document") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void contributorVerifiesSecondaryObjectTypeIdsPropertyForValidDocumentCreatedByManager() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite).createFile(testFile) + .and().assertThat().existsInRepo(); + + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingResource(testFile) + .assertThat().objectHasProperty("cmis:secondaryObjectTypeIds", "Secondary Object Type Ids", + "secondaryObjectTypeIds", "cmis:secondaryObjectTypeIds", "P:cm:titled", "P:sys:localized"); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify secondaryObjectTypeIds property as site contributor for valid folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void contributorVerifiesSecondaryObjectTypeIdsPropertyForValidFolderCreatedByManager() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite).createFolder(testFolder) + .and().assertThat().existsInRepo(); + + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingResource(testFolder) + .assertThat().objectHasProperty("cmis:secondaryObjectTypeIds", "Secondary Object Type Ids", + "secondaryObjectTypeIds", "cmis:secondaryObjectTypeIds", "P:cm:titled", "P:sys:localized"); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify secondaryObjectTypeIds property as site consumer for valid document") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void consumerVerifiesSecondaryObjectTypeIdsPropertyForValidDocument() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite).createFile(testFile) + .and().assertThat().existsInRepo(); + + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).usingResource(testFile) + .assertThat().objectHasProperty("cmis:secondaryObjectTypeIds", "Secondary Object Type Ids", + "secondaryObjectTypeIds", "cmis:secondaryObjectTypeIds", "P:cm:titled", "P:sys:localized"); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify secondaryObjectTypeIds property as site consumer for valid folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void consumerVerifiesSecondaryObjectTypeIdsPropertyForValidFolder() throws Exception + { + cmisApi.authenticateUser(testUser).usingSite(testSite).createFolder(testFolder) + .and().assertThat().existsInRepo(); + + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).usingResource(testFolder) + .assertThat().objectHasProperty("cmis:secondaryObjectTypeIds", "Secondary Object Type Ids", + "secondaryObjectTypeIds", "cmis:secondaryObjectTypeIds", "P:cm:titled", "P:sys:localized"); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify that non site member cannot get secondaryObjectTypeIds property for a valid document from a private site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void nonSiteMemberCannotGetSecondaryObjectTypeIdsForAValidDocumentFromAPrivateSite() throws Exception + { + SiteModel privateSite = dataSite.usingAdmin().createPrivateRandomSite(); + + cmisApi.authenticateUser(dataUser.getAdminUser()).usingSite(privateSite).createFile(testFile) + .and().assertThat().existsInRepo(); + + cmisApi.authenticateUser(testUser).usingResource(testFile).assertThat() + .objectHasProperty("cmis:secondaryObjectTypeIds", "Secondary Object Type Ids", + "secondaryObjectTypeIds", "cmis:secondaryObjectTypeIds", "P:cm:titled", "P:sys:localized"); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify that non site member cannot get secondaryObjectTypeIds property for a valid folder from a private site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void nonSiteMemberCannotGetSecondaryObjectTypeIdsForAValidFolderFromAPrivateSite() throws Exception + { + SiteModel privateSite = dataSite.usingAdmin().createPrivateRandomSite(); + + cmisApi.authenticateUser(dataUser.getAdminUser()).usingSite(privateSite).createFolder(testFolder) + .and().assertThat().existsInRepo(); + + cmisApi.authenticateUser(testUser).usingResource(testFolder).assertThat() + .objectHasProperty("cmis:secondaryObjectTypeIds", "Secondary Object Type Ids", + "secondaryObjectTypeIds", "cmis:secondaryObjectTypeIds", "P:cm:titled", "P:sys:localized"); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify that non site member cannot get secondaryObjectTypeIds property for a valid document from a moderated site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void nonSiteMemberCannotGetSecondaryObjectTypeIdsForAValidDocumentFromAModeratedSite() throws Exception + { + SiteModel moderatedSite = dataSite.usingAdmin().createModeratedRandomSite(); + + cmisApi.authenticateUser(dataUser.getAdminUser()).usingSite(moderatedSite).createFile(testFile) + .and().assertThat().existsInRepo(); + + cmisApi.authenticateUser(testUser).usingResource(testFile).assertThat() + .objectHasProperty("cmis:secondaryObjectTypeIds", "Secondary Object Type Ids", + "secondaryObjectTypeIds", "cmis:secondaryObjectTypeIds", "P:cm:titled", "P:sys:localized"); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify that non site member cannot get secondaryObjectTypeIds property for a valid folder from a moderated site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void nonSiteMemberCannotGetSecondaryObjectTypeIdsForAValidFolderFromAModeratedSite() throws Exception + { + SiteModel moderatedSite = dataSite.usingAdmin().createModeratedRandomSite(); + + cmisApi.authenticateUser(dataUser.getAdminUser()).usingSite(moderatedSite).createFolder(testFolder) + .and().assertThat().existsInRepo(); + + cmisApi.authenticateUser(testUser).usingResource(testFolder).assertThat() + .objectHasProperty("cmis:secondaryObjectTypeIds", "Secondary Object Type Ids", + "secondaryObjectTypeIds", "cmis:secondaryObjectTypeIds", "P:cm:titled", "P:sys:localized"); + } +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetTypeChildrenTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetTypeChildrenTests.java new file mode 100644 index 0000000000..9a7fe34fca --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetTypeChildrenTests.java @@ -0,0 +1,123 @@ +package org.alfresco.cmis; + + +import org.alfresco.utility.exception.DataPreparationException; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.enums.BaseTypeId; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 10/6/2016. + */ +public class GetTypeChildrenTests extends CmisTest +{ + @BeforeClass(alwaysRun = true) + public void setup() throws Exception + { + cmisApi.authenticateUser(dataUser.getAdminUser()); + } + + /** + * Get type children for a valid type id and includePropertyDefinitions set to false + * (verify that Map> is empty) + */ + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.SANITY, + description = "Verify admin can get type children for BaseTypeId.CMIS_DOCUMENT and includePropertyDefinitions = false") + @Test(groups = { TestGroup.CMIS, TestGroup.SANITY }) + public void getTypeChildrenWithoutPropertyDefinitions() + { + cmisApi.authenticateUser(dataUser.getAdminUser()) + .usingObjectType(BaseTypeId.CMIS_DOCUMENT.value()) + .withoutPropertyDefinitions() + .hasChildren("D:srft:facetField").propertyDefinitionIsEmpty(); + } + + /** + * Get type children for a valid type id and includePropertyDefinitions set to true + * (verify that Map> is not empty) + */ + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.SANITY, + description = "Verify admin can get type children for valid type id and includePropertyDefinitions = true") + @Test(groups = { TestGroup.CMIS, TestGroup.SANITY }) + public void getTypeChildrenWithPropertyDefinitions() + { + cmisApi.authenticateUser(dataUser.getAdminUser()).usingObjectType(BaseTypeId.CMIS_FOLDER.value()) + .withPropertyDefinitions() + .hasChildren("F:pub:DeliveryChannel").propertyDefinitionIsNotEmpty(); + cmisApi.usingObjectType(BaseTypeId.CMIS_FOLDER.value()).withPropertyDefinitions() + .doesNotHaveChildren("D:srft:facetField"); + } + + /** + * Get invalid type children for a valid type id and includePropertyDefinitions set to true + * (verify that Map> is not empty) + */ + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify admin can get invalid type children for valid type id") + @Test(groups = { TestGroup.CMIS, TestGroup.REGRESSION }) + public void getInvalidTypeChildrenForATypeId() + { + cmisApi.authenticateUser(dataUser.getAdminUser()).usingObjectType(BaseTypeId.CMIS_FOLDER.value()) + .withPropertyDefinitions() + .doesNotHaveChildren("F:pub:invalidDeliveryChannelv"); + } + + /** + * Get valid type children for a invalid type id and includePropertyDefinitions set to true + * (verify that Map> is not empty) + */ + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify admin can get valid type children for invalid type id") + @Test(groups = { TestGroup.CMIS, TestGroup.REGRESSION }, expectedExceptions = {CmisObjectNotFoundException.class}, + expectedExceptionsMessageRegExp="Type 'cmis:invalidfolder' is unknown!*") + public void getValidTypeChildrenForInvalidTypeId() + { + cmisApi.authenticateUser(dataUser.getAdminUser()).usingObjectType("cmis:invalidfolder") + .withPropertyDefinitions() + .hasChildren("F:pub:DeliveryChannel").propertyDefinitionIsNotEmpty();; + } + + /** + * Deleted user is not authorized to get type children for a valid type id + * (verify that Map> is not empty) + * @throws DataPreparationException + */ + @Bug(id="REPO-4301") + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify deleted user is not authorized to get type children for valid type id") + @Test(groups = { TestGroup.CMIS, TestGroup.REGRESSION }, expectedExceptions = {CmisUnauthorizedException.class}) + public void getTypeChildrenWithWithDeletedUser() throws DataPreparationException + { + UserModel deletedUser = dataUser.createRandomTestUser(); + cmisApi.authenticateUser(deletedUser) + .usingObjectType(BaseTypeId.CMIS_FOLDER.value()) + .withPropertyDefinitions() + .hasChildren("F:pub:DeliveryChannel").propertyDefinitionIsNotEmpty(); + dataUser.deleteUser(deletedUser); + cmisApi.disconnect() + .usingObjectType(BaseTypeId.CMIS_FOLDER.value()).withPropertyDefinitions().doesNotHaveChildren("D:srft:facetField"); + } + + @Bug(id="REPO-4301") + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify disabled user is not authorized to get type children for valid type id") + @Test(groups = { TestGroup.CMIS, TestGroup.REGRESSION }, expectedExceptions = {CmisUnauthorizedException.class}) + public void getTypeChildrenWithWithDisabledUser() throws DataPreparationException + { + UserModel disabledUser = dataUser.createRandomTestUser(); + cmisApi.authenticateUser(disabledUser) + .usingObjectType(BaseTypeId.CMIS_FOLDER.value()) + .withPropertyDefinitions() + .hasChildren("F:pub:DeliveryChannel").propertyDefinitionIsNotEmpty(); + dataUser.usingAdmin().disableUser(disabledUser); + cmisApi.disconnect() + .usingObjectType(BaseTypeId.CMIS_FOLDER.value()).withPropertyDefinitions().doesNotHaveChildren("D:srft:facetField"); + } +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetTypeDefinitionTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetTypeDefinitionTests.java new file mode 100644 index 0000000000..ed6097558f --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetTypeDefinitionTests.java @@ -0,0 +1,248 @@ +package org.alfresco.cmis; + +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.*; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.enums.BaseTypeId; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class GetTypeDefinitionTests extends CmisTest +{ + UserModel testUser; + SiteModel publicSite, privateSite, moderatedSite; + FileModel testFile; + FolderModel testFolder; + + DataUser.ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + testUser = dataUser.createRandomTestUser(); + publicSite = dataSite.usingUser(testUser).createPublicRandomSite(); + privateSite = dataSite.usingUser(testUser).createPrivateRandomSite(); + moderatedSite = dataSite.usingUser(testUser).createModeratedRandomSite(); + cmisApi.authenticateUser(testUser); + + usersWithRoles = dataUser.addUsersWithRolesToSite(publicSite, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteContributor, + UserRole.SiteConsumer); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.SANITY, + description = "Verify site manager can get Type Definition for a valid folder") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS }) + public void siteManagerShouldGetTypeDefinitionForValidFolder() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(testUser).usingSite(publicSite).createFolder(testFolder) + .and().assertThat().existsInRepo() + .then().assertThat() + .typeDefinitionIs(testFolder); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.SANITY, + description = "Verify site manager can get Type Definition for a valid document") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS }) + public void siteManagerShouldGetTypeDefinitionForValidDocument() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(publicSite).createFile(testFile) + .and().assertThat().existsInRepo() + .then().assertThat() + .typeDefinitionIs(testFile); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager cannot get Type Definition for a deleted document") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions = { CmisObjectNotFoundException.class }) + public void siteManagerShouldGetTypeDefinitionForDeletedDocument() throws Exception + { + FileModel deletedFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + + cmisApi.authenticateUser(testUser).usingSite(publicSite).createFile(deletedFile) + .and().usingResource(deletedFile).delete() + .then().assertThat() + .typeDefinitionIs(deletedFile); + } + + @Bug(id="REPO-4301") + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify user that was deleted cannot get Type Definition for a valid folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions = { CmisUnauthorizedException.class }) + public void deletedUserCannotGetTypeDefinitionForValidFolder() throws Exception + { + UserModel deletedUser = dataUser.createRandomTestUser(); + + dataUser.usingUser(testUser).addUserToSite(deletedUser, publicSite, UserRole.SiteManager); + testFolder = FolderModel.getRandomFolderModel(); + + cmisApi.authenticateUser(testUser).usingSite(publicSite).createFolder(testFolder); + cmisApi.authenticateUser(deletedUser).usingSite(publicSite).usingResource(testFolder) + .then().assertThat() + .typeDefinitionIs(testFolder); + + dataUser.deleteUser(deletedUser); + cmisApi.disconnect().assertThat().baseTypeIdIs(BaseTypeId.CMIS_FOLDER.value()); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify user that was deleted can NOT get Type Definition for a valid folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteManagerGetTypeDefinitionForValidFolder() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).usingSite(publicSite).createFolder(testFolder) + .usingResource(testFolder).and().assertThat().existsInRepo() + .then().assertThat().typeDefinitionIs(testFolder); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site Contributor is able to get Type Definition for a valid folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteContributorGetTypeDefinitionForValidFolder() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(testUser).usingSite(publicSite).createFolder(testFolder).and().assertThat().existsInRepo(); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .usingResource(testFolder).assertThat().typeDefinitionIs(testFolder); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site Collaborator is able to get Type Definition for a valid folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteCollaboratorGetTypeDefinitionForValidFolder() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingSite(publicSite).createFolder(testFolder) + .usingResource(testFolder).and().assertThat().existsInRepo() + .then().assertThat().typeDefinitionIs(testFolder); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site Consumer is NOT able to get Type Definition for a valid folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions = { CmisPermissionDeniedException.class, CmisUnauthorizedException.class }) + public void siteConsumerCantGetTypeDefinitionForValidFolder() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).usingSite(publicSite).createFolder(testFolder) + .usingResource(testFolder).and().assertThat().existsInRepo() + .then().assertThat().typeDefinitionIs(testFolder); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site Manager is able to get Type Definition for a valid file") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteManagerGetTypeDefinitionForValidFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.PDF); + + cmisApi.authenticateUser(testUser).usingSite(publicSite).createFile(testFile).and().assertThat().existsInRepo(); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .usingResource(testFile).assertThat().typeDefinitionIs(testFile); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site Contributor is able to get Type Definition for a valid file") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteContributorGetTypeDefinitionForValidFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.HTML); + + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingSite(publicSite).createFile(testFile) + .usingResource(testFile).and().assertThat().existsInRepo() + .then().assertThat().typeDefinitionIs(testFile); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site Collaborator is able to get Type Definition for a valid file") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteCollaboratorGetTypeDefinitionForValidFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.XML); + + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingSite(publicSite).createFile(testFile) + .usingResource(testFile).and().assertThat().existsInRepo() + .then().assertThat().typeDefinitionIs(testFile); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site Consumer is NOT able to get Type Definition for a valid file") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions = { CmisPermissionDeniedException.class, CmisUnauthorizedException.class }) + public void siteConsumerCantGetTypeDefinitionForValidFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.UNDEFINED); + + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).usingSite(publicSite).createFile(testFile) + .usingResource(testFile) + .and().assertThat().existsInRepo() + .then().assertThat().typeDefinitionIs(testFile); + } + + @Bug(id="REPO-4301") + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify user outside private site cannot get Type Definition for a valid file") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions = { CmisPermissionDeniedException.class }) + public void outsideUserPrivateSiteCantGetTypeDefinitionForValidFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.XML); + + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingSite(privateSite).createFile(testFile) + .usingResource(testFile).and().assertThat().existsInRepo() + .then().assertThat().typeDefinitionIs(testFile); + } + + @Bug(id="REPO-4301") + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify user outside moderated site cannot get Type Definition for a valid file") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions = { CmisPermissionDeniedException.class}) + public void outsideUserModeratedSiteGetTypeDefinitionForValidFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.XML); + + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).usingSite(moderatedSite).createFile(testFile) + .usingResource(testFile) + .and().assertThat().existsInRepo() + .then().assertThat().typeDefinitionIs(testFile); + } + + @Bug(id="REPO-4301") + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify user outside private site cannot get Type Definition for a valid folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions = { CmisPermissionDeniedException.class }) + public void outsideUserPrivateSiteCantGetTypeDefinitionForValidFolder() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.XML); + + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingSite(privateSite).createFolder(testFolder) + .usingResource(testFolder).createFile(testFile) + .usingResource(testFolder).and().assertThat().existsInRepo() + .then().assertThat().typeDefinitionIs(testFolder); + } + + @Bug(id="REPO-4301") + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify user outside moderated site cannot get Type Definition for a valid folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions = { CmisPermissionDeniedException.class}) + public void outsideUserModeratedSiteGetTypeDefinitionForValidFolder() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.XML); + + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).usingSite(moderatedSite).createFolder(testFolder) + .usingResource(testFolder).createFile(testFile) + .usingResource(testFolder) + .and().assertThat().existsInRepo() + .then().assertThat().typeDefinitionIs(testFolder); + } +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetTypeDescendantsTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetTypeDescendantsTests.java new file mode 100644 index 0000000000..cf897a8546 --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/GetTypeDescendantsTests.java @@ -0,0 +1,139 @@ +package org.alfresco.cmis; + +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.enums.BaseTypeId; +import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class GetTypeDescendantsTests extends CmisTest +{ + @BeforeClass(alwaysRun = true) + public void setup() throws Exception + { + cmisApi.authenticateUser(dataUser.getAdminUser()); + } + + /** + * Get type descendants for a valid type id and includePropertyDefinitions set to true + * and depth set to -1 (verify that Map> is not empty) + */ + @Test(groups = { TestGroup.CMIS , TestGroup.REGRESSION }) + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify admin can get type descendantes for valid type id and includePropertyDefinitions = true and depth = -1") + public void adminShouldGetTypeDescendantsValidInputCase1() + { + cmisApi.usingObjectType(BaseTypeId.CMIS_DOCUMENT.value()) + .withPropertyDefinitions().hasDescendantType(-1, "D:cm:dictionaryModel", "D:trx:transferLock"); + } + + /** + * Get type descendants for a valid type id and includePropertyDefinitions set to true + * and depth set to 1 (verify that Map> is not empty) + */ + @Test(groups = { TestGroup.CMIS , TestGroup.REGRESSION }) + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify admin can get type descendantes for valid type id and includePropertyDefinitions = true and depth = 1") + public void adminShouldGetTypeDescendantsValidInputCase2() + { + cmisApi.usingObjectType(BaseTypeId.CMIS_DOCUMENT.value()) + .withPropertyDefinitions().hasDescendantType(1, "D:cm:dictionaryModel", "D:trx:transferLock"); + } + + /** + * Get type descendants for a valid type id and includePropertyDefinitions set to false + * and depth set to 1 (verify that Map> is not empty) + */ + @Test(groups = { TestGroup.CMIS , TestGroup.REGRESSION }) + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify admin can get type descendants for valid type id and includePropertyDefinitions = false and depth = 1") + public void adminShouldGetTypeDescendantsValidInputCase3() + { + cmisApi.usingObjectType(BaseTypeId.CMIS_DOCUMENT.value()) + .withoutPropertyDefinitions().hasDescendantType(1, "D:cm:dictionaryModel", "D:trx:transferLock"); + } + + /** + * Get type descendantes for a valid type id and includePropertyDefinitions set to false + * and depth set to -1 (verify that Map> is not empty) + */ + @Test(groups = { TestGroup.CMIS , TestGroup.REGRESSION }) + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify admin can get type descendantes for valid type id and includePropertyDefinitions = false and depth = -1") + public void adminShouldGetTypeDescendantsValidInputCase4() + { + cmisApi.usingObjectType(BaseTypeId.CMIS_DOCUMENT.value()) + .withoutPropertyDefinitions().hasDescendantType(-1, "D:cm:dictionaryModel", "D:trx:transferLock"); + } + + /** + * Get type descendantes for an invalid type id and includePropertyDefinitions set to false + * and depth set to -1 (verify that Map> is not empty) + */ + @Test(groups = { TestGroup.CMIS , TestGroup.REGRESSION }, expectedExceptions = {CmisObjectNotFoundException.class}, + expectedExceptionsMessageRegExp="Type 'cmis:documentfake' is unknown!*") + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify admin cannot get type descendantes for invalid type id and includePropertyDefinitions = false and depth = -1") + public void adminCannotGetTypeDescendantsForInvalidType() + { + cmisApi.usingObjectType(BaseTypeId.CMIS_DOCUMENT.value() +"fake") + .withoutPropertyDefinitions().hasDescendantType(-1, "D:cm:dictionaryModel", "D:trx:transferLock"); + } + + /** + * Get type descendantes for a valid type id and includePropertyDefinitions set to false + * and incorrect depth set to -2 (verify that Map> is not empty) + */ + @Test(groups = { TestGroup.CMIS , TestGroup.REGRESSION }, expectedExceptions = {CmisInvalidArgumentException.class}) + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify admin can get type descendantes for valid type id and includePropertyDefinitions = false and incorrect depth = -2") + public void adminShouldGetTypeDescendantsValidTypeWithIncorrectDepth() + { + cmisApi.usingObjectType(BaseTypeId.CMIS_DOCUMENT.value()) + .withoutPropertyDefinitions().hasDescendantType(-2, "D:cm:dictionaryModel", "D:trx:transferLock"); + } + + @Test(groups = { TestGroup.CMIS , TestGroup.SANITY }) + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.SANITY, + description = "Verify random user can get type descendantes for valid type id and includePropertyDefinitions = false and depth = 1") + public void userGetTypeDescendants() throws Exception + { + UserModel user = dataUser.createRandomTestUser(); + cmisApi.authenticateUser(user).usingObjectType(BaseTypeId.CMIS_DOCUMENT.value()) + .withoutPropertyDefinitions().hasDescendantType(1, "D:cm:dictionaryModel", "D:trx:transferLock"); + } + + @Bug(id="REPO-4301") + @Test(groups = { TestGroup.CMIS , TestGroup.REGRESSION }, expectedExceptions=CmisUnauthorizedException.class) + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify deleted user cannot get type descendantes for valid type id and includePropertyDefinitions = false and depth = 1") + public void deletedUserCannotGetTypeDescendants() throws Exception + { + UserModel deletedUser = dataUser.createRandomTestUser(); + cmisApi.authenticateUser(deletedUser).usingObjectType(BaseTypeId.CMIS_DOCUMENT.value()) + .withoutPropertyDefinitions().hasDescendantType(1, "D:cm:dictionaryModel", "D:trx:transferLock"); + dataUser.usingAdmin().deleteUser(deletedUser); + cmisApi.disconnect().usingObjectType(BaseTypeId.CMIS_DOCUMENT.value()) + .withoutPropertyDefinitions().hasDescendantType(1, "D:cm:dictionaryModel", "D:trx:transferLock"); + } + + @Bug(id="REPO-4301") + @Test(groups = { TestGroup.CMIS , TestGroup.REGRESSION }, expectedExceptions=CmisUnauthorizedException.class) + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify disabled user cannot get type descendantes for valid type id and includePropertyDefinitions = false and depth = 1") + public void disabledUserCannotGetTypeDescendants() throws Exception + { + UserModel disabledUser = dataUser.createRandomTestUser(); + cmisApi.authenticateUser(disabledUser).usingObjectType(BaseTypeId.CMIS_DOCUMENT.value()) + .withoutPropertyDefinitions().hasDescendantType(1, "D:cm:dictionaryModel", "D:trx:transferLock"); + dataUser.usingAdmin().disableUser(disabledUser); + cmisApi.disconnect().usingObjectType(BaseTypeId.CMIS_DOCUMENT.value()) + .withoutPropertyDefinitions().hasDescendantType(1, "D:cm:dictionaryModel", "D:trx:transferLock"); + } +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/IsLatestMajorVersionTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/IsLatestMajorVersionTests.java new file mode 100644 index 0000000000..d5fdb7b46a --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/IsLatestMajorVersionTests.java @@ -0,0 +1,188 @@ +package org.alfresco.cmis; + +import org.alfresco.cmis.exception.InvalidCmisObjectException; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +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.alfresco.utility.report.Bug; +import org.alfresco.utility.report.Bug.Status; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.enums.VersioningState; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class IsLatestMajorVersionTests extends CmisTest +{ + UserModel managerUser, nonInviteUser; + SiteModel testSite; + FileModel minorVersionDoc, majorVersionDoc; + private DataUser.ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + minorVersionDoc = FileModel.getRandomFileModel(FileType.XML, documentContent); + majorVersionDoc = FileModel.getRandomFileModel(FileType.XML, documentContent); + managerUser = dataUser.createRandomTestUser(); + nonInviteUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(managerUser).createPublicRandomSite(); + usersWithRoles = dataUser.usingUser(managerUser) + .addUsersWithRolesToSite(testSite, UserRole.SiteContributor, UserRole.SiteCollaborator, UserRole.SiteConsumer); + cmisApi.authenticateUser(managerUser).usingSite(testSite) + .createFile(minorVersionDoc, VersioningState.MINOR) + .createFile(majorVersionDoc, VersioningState.MAJOR); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify is latest major version for document created with VersioningState set to major") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void verifyIsLatestMajorVersionForMajorState() throws Exception + { + cmisApi.authenticateUser(managerUser).usingResource(majorVersionDoc) + .and().assertThat().isLatestMajorVersion(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify latest major version for folder") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}, expectedExceptions=InvalidCmisObjectException.class) + public void verifyIsLatestMajorVersionOnFolders() throws Exception + { + FolderModel folderModel = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(managerUser).usingSite(testSite) + .createFolder(folderModel) + .and().assertThat().isLatestMajorVersion(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify is latest major version for document created with VersioningState set to minor") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void verifyIsLatestMajorVersionForMinorState() throws Exception + { + cmisApi.authenticateUser(managerUser).usingResource(minorVersionDoc) + .and().assertThat().isNotLatestMajorVersion(); + } + + @Bug(id = "MNT-17961", status = Status.FIXED) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify that major version doesn't change for document created with VersioningState set to none") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void verifyMajorVersionNotChangedForNoneState() throws Exception + { + FileModel testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile, VersioningState.NONE).and().assertThat().existsInRepo() + .and().assertThat().isLatestMajorVersion() + .and().checkOut().and().assertThat().documentIsCheckedOut() + .and().prepareDocumentForCheckIn() + .withMinorVersion() + .checkIn().refreshResource() + .and().assertThat().documentIsNotCheckedOut() + .then().assertThat().documentHasVersion(1.0); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify is latest major version for document created with VersioningState set to checkedout") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void verifyIsLatestMajorVersionForCheckedOutState() throws Exception + { + FileModel testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile, VersioningState.CHECKEDOUT) + .usingPWCDocument() + .assertThat().existsInRepo() + .and().assertThat().isNotLatestMajorVersion() + .and().assertThat().documentIsCheckedOut(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify latest major version fails for document that was deleted") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisObjectNotFoundException.class) + public void verifyIsLatestMajorVersionFailsOnDeletedDocument() throws Exception + { + FileModel testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile) + .and().assertThat().isLatestMajorVersion() + .and().delete() + .then().assertThat().isLatestMajorVersion(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify collaborator can verify is latest major version for document created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void collaboratorCanVerifyIsLatestMajorVersion() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingResource(majorVersionDoc) + .usingResource(majorVersionDoc) + .and().assertThat().isLatestMajorVersion() + .then().usingResource(minorVersionDoc).assertThat().isNotLatestMajorVersion(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify contributor can verify is latest major version for document created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void contributorCanVerifyIsLatestMajorVersion() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingResource(majorVersionDoc) + .usingResource(majorVersionDoc) + .and().assertThat().isLatestMajorVersion() + .then().usingResource(minorVersionDoc).assertThat().isNotLatestMajorVersion(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify consumer can verify is latest major version for document created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void consumerCanVerifyIsLatestMajorVersion() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).usingResource(majorVersionDoc) + .usingResource(majorVersionDoc) + .and().assertThat().isLatestMajorVersion() + .then().usingResource(minorVersionDoc).assertThat().isNotLatestMajorVersion(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify non invited user can verify is latest major version for document in public site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void nonInvitedUserCanVerifyIsLatestMajorVersionInPublicSite() throws Exception + { + cmisApi.authenticateUser(nonInviteUser).usingResource(majorVersionDoc) + .usingResource(majorVersionDoc) + .and().assertThat().isLatestMajorVersion() + .then().usingResource(minorVersionDoc).assertThat().isNotLatestMajorVersion(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify non invited user can verify is latest major version for document in private site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void nonInvitedUserCannotVerifyIsLatestMajorVersionInPrivateSite() throws Exception + { + SiteModel privateSite = dataSite.usingUser(managerUser).createPrivateRandomSite(); + FileModel privateDoc = FileModel.getRandomFileModel(FileType.HTML, documentContent); + cmisApi.authenticateUser(managerUser) + .usingSite(privateSite).createFile(privateDoc) + .then().authenticateUser(nonInviteUser).usingResource(privateDoc) + .and().assertThat().isLatestMajorVersion(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify non invited user can verify is latest major version for document in moderated site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void nonInvitedUserCannotVerifyIsLatestMajorVersionInModeratedSite() throws Exception + { + SiteModel moderatedSite = dataSite.usingUser(managerUser).createPrivateRandomSite(); + FileModel moderatedDoc = FileModel.getRandomFileModel(FileType.HTML, documentContent); + cmisApi.authenticateUser(managerUser) + .usingSite(moderatedSite).createFile(moderatedDoc) + .then().authenticateUser(nonInviteUser).usingResource(moderatedDoc) + .and().assertThat().isLatestMajorVersion(); + } +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/IsPrivateWorkingCopyTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/IsPrivateWorkingCopyTests.java new file mode 100644 index 0000000000..e7ea845023 --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/IsPrivateWorkingCopyTests.java @@ -0,0 +1,153 @@ +package org.alfresco.cmis; + +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.enums.VersioningState; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class IsPrivateWorkingCopyTests extends CmisTest +{ + SiteModel testSite; + UserModel managerUser, nonInvitedUser; + FileModel checkedOutDoc, simpleDoc; + private DataUser.ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + checkedOutDoc = FileModel.getRandomFileModel(FileType.XML, documentContent); + simpleDoc = FileModel.getRandomFileModel(FileType.HTML, documentContent); + managerUser = dataUser.createRandomTestUser(); + nonInvitedUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(managerUser).createPublicRandomSite(); + usersWithRoles = dataUser.usingUser(managerUser) + .addUsersWithRolesToSite(testSite, UserRole.SiteContributor, UserRole.SiteCollaborator, UserRole.SiteConsumer); + cmisApi.authenticateUser(managerUser).usingSite(testSite) + .createFile(checkedOutDoc).and().checkOut() + .createFile(simpleDoc); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify site manager is able to verify if checked out document is private working copy") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void siteManagerCanVerifyIsPrivateWorkingCopy() throws Exception + { + cmisApi.authenticateUser(managerUser).usingResource(checkedOutDoc) + .assertThat().isPrivateWorkingCopy() + .then().usingResource(simpleDoc).assertThat().isNotPrivateWorkingCopy(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify site manager is able to verify if pwc document is private working copy") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void siteManagerCanVerifyIsPrivateWorkingCopyOnPwc() throws Exception + { + cmisApi.authenticateUser(managerUser).usingResource(checkedOutDoc) + .usingPWCDocument() + .assertThat().isPrivateWorkingCopy(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is not able to verify if deleted document is private working copy") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisObjectNotFoundException.class) + public void siteManagerCannotVerifyIsPrivateWorkingCopyOnDeletedDoc() throws Exception + { + FileModel deletedDoc = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, documentContent); + cmisApi.authenticateUser(managerUser).usingSite(testSite) + .createFile(deletedDoc) + .then().delete().and().assertThat().doesNotExistInRepo() + .assertThat().isPrivateWorkingCopy(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site collaborator is able to verify if checked out document is private working copy") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void collaboratorCanVerifyIsPrivateWorkingCopy() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .usingResource(checkedOutDoc) + .assertThat().isPrivateWorkingCopy() + .then().usingResource(simpleDoc).assertThat().isNotPrivateWorkingCopy(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site contributor is able to verify if checked out document is private working copy") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void contributorCanVerifyIsPrivateWorkingCopy() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .usingResource(checkedOutDoc) + .assertThat().isPrivateWorkingCopy() + .then().usingResource(simpleDoc).assertThat().isNotPrivateWorkingCopy(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site consumer is able to verify if checked out document is private working copy") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void consumerCanVerifyIsPrivateWorkingCopy() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .usingResource(checkedOutDoc) + .assertThat().isPrivateWorkingCopy() + .then().usingResource(simpleDoc).assertThat().isNotPrivateWorkingCopy(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify non invited user is able to verify if checked out document is private working copy in public site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void nonInvitedUserCanVerifyIsPrivateWorkingCopyInPublicSite() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .usingResource(checkedOutDoc) + .assertThat().isPrivateWorkingCopy() + .then().usingResource(simpleDoc).assertThat().isNotPrivateWorkingCopy(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify non invited user is not able to verify if checked out document is private working copy in private site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void nonInvitedUserCannotVerifyIsPrivateWorkingCopyInPrivateSite() throws Exception + { + SiteModel privateSite = dataSite.usingUser(managerUser).createPrivateRandomSite(); + FileModel privateFile = FileModel.getRandomFileModel(FileType.HTML); + cmisApi.authenticateUser(managerUser).usingSite(privateSite) + .createFile(privateFile) + .then().authenticateUser(nonInvitedUser) + .assertThat().isPrivateWorkingCopy(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify non invited user is not able to verify if checked out document is private working copy in moderated site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void nonInvitedUserCannotVerifyIsPrivateWorkingCopyInModeratedSite() throws Exception + { + SiteModel moderatedSite = dataSite.usingUser(managerUser).createPrivateRandomSite(); + FileModel moderatedFile = FileModel.getRandomFileModel(FileType.HTML); + cmisApi.authenticateUser(managerUser).usingSite(moderatedSite) + .createFile(moderatedFile) + .then().authenticateUser(nonInvitedUser) + .assertThat().isPrivateWorkingCopy(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is able to verify if document created with CHECKEDOUT versioning state is private working copy") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void verifyIsPrivateWorkingCopyForDocumentWithCheckedOutVersioningState() throws Exception + { + FileModel checkedDoc = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, documentContent); + cmisApi.authenticateUser(managerUser).usingSite(testSite) + .createFile(checkedDoc, VersioningState.CHECKEDOUT).refreshResource() + .assertThat().isPrivateWorkingCopy(); + } +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/MoveTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/MoveTests.java new file mode 100644 index 0000000000..b6f9fccc19 --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/MoveTests.java @@ -0,0 +1,357 @@ +package org.alfresco.cmis; + +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +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.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.enums.VersioningState; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 9/28/2016. + */ +public class MoveTests extends CmisTest +{ + UserModel unauthorizedUser; + UserModel siteManager; + UserModel contributorUser; + UserModel collaboratorUser; + UserModel consumerUser; + SiteModel publicSite; + FileModel sourceFile; + FolderModel targetFolder, sourceFolder; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + unauthorizedUser = dataUser.createRandomTestUser(); + siteManager = dataUser.createRandomTestUser(); + contributorUser = dataUser.createRandomTestUser(); + collaboratorUser = dataUser.createRandomTestUser(); + consumerUser = dataUser.createRandomTestUser(); + publicSite = dataSite.usingUser(siteManager).createPublicRandomSite(); + + dataUser.addUserToSite(consumerUser, publicSite, UserRole.SiteConsumer); + dataUser.addUserToSite(collaboratorUser, publicSite, UserRole.SiteCollaborator); + dataUser.addUserToSite(contributorUser, publicSite, UserRole.SiteContributor); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify site manager is able to move a file to an existent location in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void siteManagerMovesFile() throws Exception + { + targetFolder = FolderModel.getRandomFolderModel(); + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "content"); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFolder(targetFolder).and().assertThat().existsInRepo() + .createFile(sourceFile).and().assertThat().existsInRepo() + .then().moveTo(targetFolder).and().assertThat().existsInRepo() + .usingResource(sourceFile).assertThat().doesNotExistInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is not able to move file to a nonexistent location in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisObjectNotFoundException.class) + public void siteManagerMovesFileToNonExistentTarget() throws Exception + { + targetFolder = FolderModel.getRandomFolderModel(); + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "content"); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(sourceFile).and().assertThat().existsInRepo() + .createFolder(targetFolder).and().delete() + .then().moveTo(targetFolder); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is not able to move a nonexistent file in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisObjectNotFoundException.class) + public void siteManagerMovesNonExistentSourceFile() throws Exception + { + targetFolder = FolderModel.getRandomFolderModel(); + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "content"); + cmisApi.usingSite(publicSite) + .createFolder(targetFolder).and().assertThat().existsInRepo() + .createFile(sourceFile).and().delete() + .then().moveTo(targetFolder); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is able to move file that has multiple versions with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerShouldMoveFileWithMultipleVersions() throws Exception + { + targetFolder = FolderModel.getRandomFolderModel(); + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "content"); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFolder(targetFolder).and().assertThat().existsInRepo() + .createFile(sourceFile).and().assertThat().existsInRepo() + .then().update("first content") + .assertThat().documentHasVersion(1.1) + .update("second content") + .assertThat().documentHasVersion(1.2) + .then().moveTo(targetFolder).and().assertThat().existsInRepo() + .and().usingVersion().assertHasVersions(1.0, 1.1, 1.2) + .usingResource(sourceFile).assertThat().doesNotExistInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is able to move folder structure to an existent location in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerMovesFolderStructure() throws Exception + { + targetFolder = FolderModel.getRandomFolderModel(); + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "content"); + FolderModel sourceParentFolder = FolderModel.getRandomFolderModel(); + FolderModel subFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFolder(targetFolder).and().assertThat().existsInRepo() + .createFolder(sourceParentFolder).and().assertThat().existsInRepo() + .then().usingResource(sourceParentFolder) + .createFile(sourceFile).and().assertThat().existsInRepo() + .createFolder(subFolder).and().assertThat().existsInRepo() + .when().usingResource(sourceParentFolder) + .moveTo(targetFolder).and().assertThat().existsInRepo() + .and().assertThat().hasChildren(sourceFile, subFolder); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify inexistent is not able to move file with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisUnauthorizedException.class) + public void inexistentUserCannotMoveFile() throws Exception + { + targetFolder = FolderModel.getRandomFolderModel(); + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "content"); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFolder(targetFolder).and().assertThat().existsInRepo() + .createFile(sourceFile).and().assertThat().existsInRepo() + .then().authenticateUser(UserModel.getRandomUserModel()) + .moveTo(targetFolder).and().assertThat().existsInRepo() + .usingResource(sourceFile).assertThat().doesNotExistInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is able to move checked out file with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions=CmisUpdateConflictException.class) + public void siteManagerShouldNotMoveCheckedOutFile() throws Exception + { + targetFolder = FolderModel.getRandomFolderModel(); + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "content"); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFolder(targetFolder).and().assertThat().existsInRepo() + .createFile(sourceFile).and().assertThat().existsInRepo() + .and().checkOut().assertThat().documentIsCheckedOut() + .then().usingResource(sourceFile) + .moveTo(targetFolder).and().assertThat().existsInRepo() + .and().assertThat().documentIsCheckedOut(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is able to move folder with checked out document") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void siteManagerShouldMoveFolderWithCheckedOutFile() throws Exception + { + targetFolder = FolderModel.getRandomFolderModel(); + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "content"); + sourceFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFolder(targetFolder).and().assertThat().existsInRepo() + .createFolder(sourceFolder).and().assertThat().existsInRepo() + .then().usingResource(sourceFolder) + .createFile(sourceFile, VersioningState.CHECKEDOUT) + .and().assertThat().existsInRepo() + .assertThat().documentIsCheckedOut() + .then().usingResource(sourceFolder) + .moveTo(targetFolder).and().assertThat().existsInRepo() + .and().assertThat().hasFiles(sourceFile); + FileModel checkedOutDoc = cmisApi.getFiles().get(0); + cmisApi.usingResource(checkedOutDoc).assertThat().documentIsCheckedOut(); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify unauthorized user is no able to move a file") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void unauthorizedUserCannotMovesFile() throws Exception + { + targetFolder = FolderModel.getRandomFolderModel(); + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "content"); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFolder(targetFolder).and().assertThat().existsInRepo() + .createFile(sourceFile).and().assertThat().existsInRepo() + .then().authenticateUser(unauthorizedUser) + .then().moveTo(targetFolder); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Manager verify PWC document object cannot be moved") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions = CmisUpdateConflictException.class) + public void managerCannotMovePWCDocumentObject() throws Exception + { + sourceFile = dataContent.usingUser(siteManager).usingSite(publicSite).createContent(FileModel.getRandomFileModel(FileType.TEXT_PLAIN)); + targetFolder = dataContent.usingUser(siteManager).usingSite(publicSite).createFolder(); + FileModel pwcFile = cmisApi.authenticateUser(siteManager).usingResource(sourceFile).checkOut().withCMISUtil().getPWCFileModel(); + cmisApi.usingResource(pwcFile).moveTo(targetFolder); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify contributor can move Document created by self") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void contributorCanMoveDocumentCreatedBySelf() throws Exception + { + sourceFile = dataContent.usingUser(contributorUser).usingSite(publicSite).createContent(FileModel.getRandomFileModel(FileType.TEXT_PLAIN)); + targetFolder = dataContent.usingUser(contributorUser).usingSite(publicSite).createFolder(); + cmisApi.authenticateUser(contributorUser).usingResource(sourceFile).moveTo(targetFolder) + .usingResource(targetFolder).assertThat().hasChildren(sourceFile) + .usingSite(publicSite).assertThat().doesNotHaveFile(sourceFile); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify contributor cannot move Document created by Manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions = {CmisUnauthorizedException.class, CmisPermissionDeniedException.class}) + public void contributorCannotMoveDocumentCreatedByManager() throws Exception + { + sourceFile = dataContent.usingUser(siteManager).usingSite(publicSite).createContent(FileModel.getRandomFileModel(FileType.TEXT_PLAIN)); + targetFolder = dataContent.usingUser(siteManager).usingSite(publicSite).createFolder(); + cmisApi.authenticateUser(contributorUser).usingResource(sourceFile).moveTo(targetFolder); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify contributor can move Folder created by self") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void contributorCanMoveFolderCreatedBySelf() throws Exception + { + sourceFolder = dataContent.usingUser(contributorUser).usingSite(publicSite).createFolder(); + targetFolder = dataContent.usingUser(contributorUser).usingSite(publicSite).createFolder(); + cmisApi.authenticateUser(contributorUser).usingResource(sourceFolder).moveTo(targetFolder) + .usingResource(targetFolder).assertThat().hasChildren(sourceFolder) + .usingSite(publicSite).assertThat().doesNotHaveFolder(sourceFolder); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify contributor cannot move Folder created by Manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions = {CmisUnauthorizedException.class, CmisPermissionDeniedException.class}) + public void contributorCannotMoveFolderCreatedByManager() throws Exception + { + sourceFolder = dataContent.usingUser(siteManager).usingSite(publicSite).createFolder(); + targetFolder = dataContent.usingUser(siteManager).usingSite(publicSite).createFolder(); + cmisApi.authenticateUser(contributorUser).usingResource(sourceFolder).moveTo(targetFolder); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify collaborator can move Document created by self") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void collaboratorCanMoveDocumentCreatedBySelf() throws Exception + { + sourceFile = dataContent.usingUser(collaboratorUser).usingSite(publicSite).createContent(FileModel.getRandomFileModel(FileType.TEXT_PLAIN)); + targetFolder = dataContent.usingUser(collaboratorUser).usingSite(publicSite).createFolder(); + cmisApi.authenticateUser(collaboratorUser).usingResource(sourceFile).moveTo(targetFolder) + .usingResource(targetFolder).assertThat().hasChildren(sourceFile) + .usingSite(publicSite).assertThat().doesNotHaveFile(sourceFile); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify collaborator cannot move Document created by Manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions = {CmisUnauthorizedException.class, CmisPermissionDeniedException.class}) + public void collaboratorCannotMoveDocumentCreatedByManager() throws Exception + { + sourceFile = dataContent.usingUser(siteManager).usingSite(publicSite).createContent(FileModel.getRandomFileModel(FileType.TEXT_PLAIN)); + targetFolder = dataContent.usingUser(siteManager).usingSite(publicSite).createFolder(); + cmisApi.authenticateUser(collaboratorUser).usingResource(sourceFile).moveTo(targetFolder); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify collaborator can move Folder created by self") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void collaboratorCanMoveFolderCreatedBySelf() throws Exception + { + sourceFolder = dataContent.usingUser(collaboratorUser).usingSite(publicSite).createFolder(); + targetFolder = dataContent.usingUser(collaboratorUser).usingSite(publicSite).createFolder(); + cmisApi.authenticateUser(collaboratorUser).usingResource(sourceFolder).moveTo(targetFolder) + .usingResource(targetFolder).assertThat().hasChildren(sourceFolder) + .usingSite(publicSite).assertThat().doesNotHaveFolder(sourceFolder); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify collaborator cannot move Folder created by Manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions = {CmisUnauthorizedException.class, CmisPermissionDeniedException.class}) + public void collaboratorCannotMoveFolderCreatedByManager() throws Exception + { + sourceFolder = dataContent.usingUser(siteManager).usingSite(publicSite).createFolder(); + targetFolder = dataContent.usingUser(siteManager).usingSite(publicSite).createFolder(); + cmisApi.authenticateUser(collaboratorUser).usingResource(sourceFolder).moveTo(targetFolder); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify consumer cannot move Document") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions = {CmisUnauthorizedException.class, CmisPermissionDeniedException.class}) + public void consumerCannotMoveDocument() throws Exception + { + sourceFile = dataContent.usingUser(siteManager).usingSite(publicSite).createContent(FileModel.getRandomFileModel(FileType.TEXT_PLAIN)); + targetFolder = dataContent.usingUser(siteManager).usingSite(publicSite).createFolder(); + cmisApi.authenticateUser(consumerUser).usingResource(sourceFile).moveTo(targetFolder); + } + + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify consumer cannot move Folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions = {CmisUnauthorizedException.class, CmisPermissionDeniedException.class}) + public void consumerCannotMoveFolder() throws Exception + { + sourceFolder = dataContent.usingUser(siteManager).usingSite(publicSite).createFolder(); + targetFolder = dataContent.usingUser(siteManager).usingSite(publicSite).createFolder(); + cmisApi.authenticateUser(consumerUser).usingResource(sourceFolder).moveTo(targetFolder); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify unauthorized user cannot move Document from private site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisUnauthorizedException.class, CmisPermissionDeniedException.class}) + public void unauthorizedUserCannotMoveDocumentFromPrivateSite() throws Exception + { + SiteModel privateSite = dataSite.usingUser(siteManager).createPrivateRandomSite(); + sourceFile = dataContent.usingUser(siteManager).usingSite(privateSite).createContent(FileModel.getRandomFileModel(FileType.TEXT_PLAIN)); + targetFolder = dataContent.usingUser(siteManager).usingSite(privateSite).createFolder(); + cmisApi.authenticateUser(unauthorizedUser).usingResource(sourceFile).moveTo(targetFolder); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify unauthorized user cannot move Folder from private site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisUnauthorizedException.class, CmisPermissionDeniedException.class}) + public void unauthorizedUserCannotMoveFolderFromPrivateSite() throws Exception + { + SiteModel privateSite = dataSite.usingUser(siteManager).createPrivateRandomSite(); + sourceFolder = dataContent.usingUser(siteManager).usingSite(privateSite).createFolder(); + targetFolder = dataContent.usingUser(siteManager).usingSite(privateSite).createFolder(); + cmisApi.authenticateUser(unauthorizedUser).usingResource(sourceFolder).moveTo(targetFolder); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify unauthorized user cannot move Document from moderated site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisUnauthorizedException.class, CmisPermissionDeniedException.class}) + public void unauthorizedUserCannotMoveDocumentFromModeratedSite() throws Exception + { + SiteModel moderatedSite = dataSite.usingUser(siteManager).createModeratedRandomSite(); + sourceFile = dataContent.usingUser(siteManager).usingSite(moderatedSite).createContent(FileModel.getRandomFileModel(FileType.TEXT_PLAIN)); + targetFolder = dataContent.usingUser(siteManager).usingSite(moderatedSite).createFolder(); + cmisApi.authenticateUser(unauthorizedUser).usingResource(sourceFile).moveTo(targetFolder); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify unauthorized user cannot move Folder from moderated site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisUnauthorizedException.class, CmisPermissionDeniedException.class}) + public void unauthorizedUserCannotMoveFolderFromModeratedSite() throws Exception + { + SiteModel moderatedSite = dataSite.usingUser(siteManager).createModeratedRandomSite(); + sourceFolder = dataContent.usingUser(siteManager).usingSite(moderatedSite).createFolder(); + targetFolder = dataContent.usingUser(siteManager).usingSite(moderatedSite).createFolder(); + cmisApi.authenticateUser(unauthorizedUser).usingResource(sourceFolder).moveTo(targetFolder); + } +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/RelationshipTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/RelationshipTests.java new file mode 100644 index 0000000000..d5662fafeb --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/RelationshipTests.java @@ -0,0 +1,267 @@ +package org.alfresco.cmis; + +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +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.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 9/29/2016. + */ +public class RelationshipTests extends CmisTest +{ + UserModel siteManager; + SiteModel publicSite, privateSite; + FileModel sourceFile, targetFile; + private DataUser.ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + siteManager = dataUser.createRandomTestUser(); + publicSite = dataSite.usingUser(siteManager).createPublicRandomSite(); + privateSite = dataSite.usingUser(siteManager).createPrivateRandomSite(); + usersWithRoles = dataUser.addUsersWithRolesToSite(publicSite, UserRole.SiteManager, UserRole.SiteContributor, UserRole.SiteCollaborator, UserRole.SiteConsumer); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify site manager is able to create relationship between a source object and a target object in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void siteManagerCreatesRelationshipBetween2Files() throws Exception + { + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + targetFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(targetFile).and().assertThat().existsInRepo() + .createFile(sourceFile).and().assertThat().existsInRepo() + .then().createRelationshipWith(targetFile) + .and().assertThat().objectHasRelationshipWith(targetFile); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is not able to create relationship between a invalid sources with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisObjectNotFoundException.class) + public void siteManagerCannotCreateRelWithInvalidSources() throws Exception + { + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + targetFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(targetFile).and().delete().assertThat().doesNotExistInRepo() + .createFile(sourceFile).and().delete().assertThat().doesNotExistInRepo() + .then().createRelationshipWith(targetFile); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is not able to create relationship with checkout source document with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanCreateRelWithCheckedOutSourceDocument() throws Exception + { + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + targetFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(targetFile).and().assertThat().existsInRepo() + .createFile(sourceFile).and().assertThat().existsInRepo() + .then().checkOut().and().assertThat().documentIsCheckedOut() + .then().createRelationshipWith(targetFile) + .and().assertThat().objectHasRelationshipWith(targetFile); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify that inexistent user is not able to create relationship between documents with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisUnauthorizedException.class) + public void inexistentUserCannotCreateRelationship() throws Exception + { + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + targetFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(targetFile).and().assertThat().existsInRepo() + .createFile(sourceFile).and().assertThat().existsInRepo() + .then().authenticateUser(UserModel.getRandomUserModel()) + .createRelationshipWith(targetFile) + .and().assertThat().objectHasRelationshipWith(targetFile); + } + + @Bug(id="REPO-4301") + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify that user that was deleted is not able to create relationship between documents with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisUnauthorizedException.class) + public void deletedUserCannotCreateRelationship() throws Exception + { + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + targetFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + UserModel toBeDeleted = dataUser.createRandomTestUser(); + FolderModel shared = FolderModel.getSharedFolderModel(); + cmisApi.authenticateUser(toBeDeleted) + .usingResource(shared) + .createFile(targetFile).and().assertThat().existsInRepo() + .createFile(sourceFile).and().assertThat().existsInRepo(); + dataUser.deleteUser(toBeDeleted); + cmisApi.createRelationshipWith(targetFile); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify that site manager is able to create relationship between documents with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanCreateRelationshipInPrivateSite() throws Exception + { + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + targetFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(dataUser.getAdminUser()) + .usingSite(privateSite) + .createFile(targetFile).and().assertThat().existsInRepo() + .createFile(sourceFile).and().assertThat().existsInRepo() + .then().authenticateUser(siteManager) + .createRelationshipWith(targetFile) + .and().assertThat().objectHasRelationshipWith(targetFile); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is not able to create relationship between a invalid sources with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisObjectNotFoundException.class) + public void siteManagerCannotGetRelWithInvalidObject() throws Exception + { + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + targetFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + FileModel invalidFile = FileModel.getRandomFileModel(FileType.HTML); + invalidFile.setCmisLocation("/" + invalidFile.getName() + "/"); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(targetFile) + .createFile(sourceFile) + .then().createRelationshipWith(targetFile) + .and().assertThat().objectHasRelationshipWith(targetFile) + .assertThat().objectHasRelationshipWith(invalidFile); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify admin is able to create relationship between a source folder and a target file with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void adminCreatesRelBetweenSourceFolderAndTargetFile() throws Exception + { + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + targetFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + FolderModel sourceFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(dataUser.getAdminUser()).usingSite(publicSite) + .createFile(targetFile).assertThat().existsInRepo() + .createFolder(sourceFolder).assertThat().existsInRepo() + .then().createRelationshipWith(targetFile) + .and().assertThat().objectHasRelationshipWith(targetFile); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify contributor is not able to create relationship between a source object and a target object in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS},expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void contributorCannotCreateRelationship() throws Exception + { + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + targetFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(targetFile).and().assertThat().existsInRepo() + .createFile(sourceFile).and().assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .usingResource(sourceFile).createRelationshipWith(targetFile) + .and().assertThat().objectHasRelationshipWith(targetFile); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify collaborator is able to create relationship between a source object and a target object in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void collaboratorCanCreateRelationship() throws Exception + { + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + targetFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(targetFile).and().assertThat().existsInRepo() + .createFile(sourceFile).and().assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .usingResource(sourceFile).createRelationshipWith(targetFile) + .and().assertThat().objectHasRelationshipWith(targetFile); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify consumer is not able to create relationship between a source object and a target object in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS},expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void consumerCannotCreateRelationship() throws Exception + { + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + targetFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(targetFile).and().assertThat().existsInRepo() + .createFile(sourceFile).and().assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .usingResource(sourceFile).createRelationshipWith(targetFile) + .and().assertThat().objectHasRelationshipWith(targetFile); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify unauthorized user is not able to create relationship between a source object and a target object from a private site with CMIS") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void unauthorizedUserCannotCreateRelationship() throws Exception + { + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + targetFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(siteManager).usingSite(privateSite) + .createFile(targetFile).and().assertThat().existsInRepo() + .createFile(sourceFile).and().assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .usingResource(sourceFile).createRelationshipWith(targetFile); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify unauthorized user is not able to get relationship between a source object and a target object from a private site with CMIS") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void unauthorizedUserCannotGetRelationship() throws Exception + { + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + targetFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(siteManager).usingSite(privateSite) + .createFile(targetFile).and().assertThat().existsInRepo() + .createFile(sourceFile).and().assertThat().existsInRepo() + .usingResource(sourceFile).createRelationshipWith(targetFile) + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .and().assertThat().objectHasRelationshipWith(targetFile); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is not able to create relationship for PWC source document with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisInvalidArgumentException.class, + expectedExceptionsMessageRegExp = "^Source is not the latest version of a document, a folder or an item object!$") + public void siteManagerCannotCreateRelationshipPWCSourceFile() throws Exception + { + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + targetFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(targetFile).and().assertThat().existsInRepo() + .createFile(sourceFile).and().assertThat().existsInRepo().then().checkOut() + .assertThat().documentIsCheckedOut() + .usingPWCDocument().createRelationshipWith(targetFile); + } + + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is able to create relationship with checkout target document with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanCreateRelWithCheckedOutTargetDocument() throws Exception + { + sourceFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + targetFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(targetFile).and().assertThat().existsInRepo() + .then().checkOut().and().assertThat().documentIsCheckedOut() + .createFile(sourceFile).and().assertThat().existsInRepo() + .then().createRelationshipWith(targetFile) + .and().assertThat().objectHasRelationshipWith(targetFile); + } +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/RemoveObjectFromFolderTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/RemoveObjectFromFolderTests.java new file mode 100644 index 0000000000..9d164edca6 --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/RemoveObjectFromFolderTests.java @@ -0,0 +1,243 @@ +package org.alfresco.cmis; + +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +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.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 10/3/2016. + */ +public class RemoveObjectFromFolderTests extends CmisTest +{ + UserModel unauthorizedUser; + UserModel siteManager; + UserModel contributorUser; + UserModel collaboratorUser; + UserModel consumerUser; + SiteModel publicSite; + FolderModel parentFolder, testFolder; + FileModel testFile; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + unauthorizedUser = dataUser.createRandomTestUser(); + siteManager = dataUser.createRandomTestUser(); + contributorUser = dataUser.createRandomTestUser(); + collaboratorUser = dataUser.createRandomTestUser(); + consumerUser = dataUser.createRandomTestUser(); + publicSite = dataSite.usingUser(siteManager).createPublicRandomSite(); + dataUser.addUserToSite(consumerUser, publicSite, UserRole.SiteConsumer); + dataUser.addUserToSite(collaboratorUser, publicSite, UserRole.SiteCollaborator); + dataUser.addUserToSite(contributorUser, publicSite, UserRole.SiteContributor); + parentFolder = FolderModel.getRandomFolderModel(); + testFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFolder(testFolder).assertThat().existsInRepo() + .createFolder(parentFolder).assertThat().existsInRepo(); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.SANITY, + description = "Verify site manager is able to remove a document from folder in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void siteManagerShouldRemoveFileToFolder() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(siteManager).usingResource(parentFolder) + .createFile(testFile).assertThat().existsInRepo() + .and().addDocumentToFolder(testFolder, true).then().assertThat().existsInRepo() + .when().removeDocumentFromFolder(testFolder).assertThat().doesNotExistInRepo() + .usingResource(testFile).assertThat().existsInRepo(); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is able to leave a document without parent folder with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisInvalidArgumentException.class, expectedExceptionsMessageRegExp = "^Object is not a document!$") + public void siteManagerShouldNotRemoveFolderFromFolder() throws Exception + { + FolderModel subFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(siteManager).usingResource(parentFolder) + .createFolder(subFolder).assertThat().existsInRepo() + .when().removeDocumentFromFolder(testFolder).assertThat().doesNotExistInRepo(); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is not able to remove a document without parent folder with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisObjectNotFoundException.class) + public void siteManagerShouldNotRemoveInvalidFileFromFolder() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + testFile.setCmisLocation("/" + testFile.getName() + "/"); + cmisApi.authenticateUser(siteManager).usingResource(testFile) + .when().removeDocumentFromFolder(testFolder).assertThat().doesNotExistInRepo() + .usingResource(testFile).assertThat().existsInRepo(); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is not able to remove valid document from invalid folder with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisObjectNotFoundException.class) + public void siteManagerShouldNotRemoveFileToInvalidFolder() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + FolderModel invalidFolder = FolderModel.getRandomFolderModel(); + invalidFolder.setCmisLocation("/" + invalidFolder.getName() + "/"); + cmisApi.authenticateUser(siteManager).usingResource(parentFolder) + .createFile(testFile).assertThat().existsInRepo() + .and().addDocumentToFolder(testFolder, true).then().assertThat().existsInRepo() + .when().removeDocumentFromFolder(invalidFolder) + .assertThat().doesNotExistInRepo() + .usingResource(testFile).assertThat().existsInRepo(); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is able to remove a checked out document from folder in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerShouldRemovePWCFileToFolder() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(siteManager).usingResource(parentFolder) + .createFile(testFile).assertThat().existsInRepo() + .then().checkOut().and().assertThat().documentIsCheckedOut() + .usingPWCDocument().addDocumentToFolder(testFolder, true) + .then().assertThat().existsInRepo() + .and().assertThat().documentIsCheckedOut() + .when().removeDocumentFromFolder(testFolder).assertThat().doesNotExistInRepo() + .usingResource(testFile).assertThat().existsInRepo() + .and().assertThat().documentIsCheckedOut(); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.SANITY, + description = "Verify unauthorized user is not able to remove a document from folder") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void unauthorizedUserShouldNotRemoveFileToFolder() throws Exception + { + UserModel unauthorizedUser = dataUser.createRandomTestUser(); + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(siteManager) + .usingResource(parentFolder) + .createFile(testFile).assertThat().existsInRepo() + .then().authenticateUser(unauthorizedUser) + .removeDocumentFromFolder(testFolder); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify contributor can remove document from folder created by self") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void contributorCanRemoveDocumentFromFolderCreatedBySelf() throws Exception + { + parentFolder = dataContent.usingUser(contributorUser).usingSite(publicSite).createFolder(); + testFolder = dataContent.usingUser(contributorUser).usingSite(publicSite).createFolder(); + testFile = dataContent.usingUser(contributorUser).usingResource(parentFolder) + .createContent(FileModel.getRandomFileModel(FileType.TEXT_PLAIN)); + + cmisApi.authenticateUser(contributorUser).usingResource(testFile) + .addDocumentToFolder(testFolder, true).then().assertThat().existsInRepo() + .removeDocumentFromFolder(testFolder).assertThat().doesNotExistInRepo() + .usingResource(testFile).assertThat().existsInRepo(); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify contributor can remove document from folder created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void contributorCannotRemoveDocumentFromFolderCreatedByManager() throws Exception + { + parentFolder = dataContent.usingUser(siteManager).usingSite(publicSite).createFolder(); + testFolder = dataContent.usingUser(siteManager).usingSite(publicSite).createFolder(); + testFile = dataContent.usingUser(siteManager).usingResource(parentFolder) + .createContent(FileModel.getRandomFileModel(FileType.TEXT_PLAIN)); + cmisApi.authenticateUser(siteManager).usingResource(testFile) + .addDocumentToFolder(testFolder, true); + + cmisApi.authenticateUser(contributorUser).usingResource(testFile).removeDocumentFromFolder(testFolder); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify collaborator can remove document from folder created by self") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }) + public void collaboratorCanRemoveDocumentFromFolderCreatedBySelf() throws Exception + { + parentFolder = dataContent.usingUser(collaboratorUser).usingSite(publicSite).createFolder(); + testFolder = dataContent.usingUser(collaboratorUser).usingSite(publicSite).createFolder(); + testFile = dataContent.usingUser(collaboratorUser).usingResource(parentFolder) + .createContent(FileModel.getRandomFileModel(FileType.TEXT_PLAIN)); + + cmisApi.authenticateUser(collaboratorUser).usingResource(testFile) + .addDocumentToFolder(testFolder, true).then().assertThat().existsInRepo() + .removeDocumentFromFolder(testFolder).assertThat().doesNotExistInRepo() + .usingResource(testFile).assertThat().existsInRepo(); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify collaborator can remove document from folder created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void collaboratorCannotRemoveDocumentFromFolderCreatedByManager() throws Exception + { + parentFolder = dataContent.usingUser(siteManager).usingSite(publicSite).createFolder(); + testFolder = dataContent.usingUser(siteManager).usingSite(publicSite).createFolder(); + testFile = dataContent.usingUser(siteManager).usingResource(parentFolder) + .createContent(FileModel.getRandomFileModel(FileType.TEXT_PLAIN)); + cmisApi.authenticateUser(siteManager).usingResource(testFile) + .addDocumentToFolder(testFolder, true); + + cmisApi.authenticateUser(collaboratorUser).usingResource(testFile).removeDocumentFromFolder(testFolder); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify consumer cannot remove document from folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void consumerCannotRemoveDocumentFromFolder() throws Exception + { + parentFolder = dataContent.usingUser(siteManager).usingSite(publicSite).createFolder(); + testFolder = dataContent.usingUser(siteManager).usingSite(publicSite).createFolder(); + testFile = dataContent.usingUser(siteManager).usingResource(parentFolder) + .createContent(FileModel.getRandomFileModel(FileType.TEXT_PLAIN)); + cmisApi.authenticateUser(siteManager).usingResource(testFile) + .addDocumentToFolder(testFolder, true).then().assertThat().existsInRepo(); + + cmisApi.authenticateUser(consumerUser).usingResource(testFile).removeDocumentFromFolder(testFolder); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify remove document from folder by user that is outside a private site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void unauthorizedUserCannotRemoveDocumentFromPrivateSite() throws Exception + { + SiteModel privateSite = dataSite.usingUser(siteManager).createPrivateRandomSite(); + parentFolder = dataContent.usingUser(siteManager).usingSite(privateSite).createFolder(); + testFolder = dataContent.usingUser(siteManager).usingSite(privateSite).createFolder(); + testFile = dataContent.usingUser(siteManager).usingResource(parentFolder) + .createContent(FileModel.getRandomFileModel(FileType.TEXT_PLAIN)); + cmisApi.authenticateUser(siteManager).usingResource(testFile) + .addDocumentToFolder(testFolder, true).then().assertThat().existsInRepo(); + + cmisApi.authenticateUser(unauthorizedUser).usingResource(testFile).removeDocumentFromFolder(testFolder); + } + + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify remove document from folder by user that is outside a moderated site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS }, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void unauthorizedUserCannotRemoveDocumentFromModeratedSite() throws Exception + { + SiteModel moderatedSite = dataSite.usingUser(siteManager).createModeratedRandomSite(); + parentFolder = dataContent.usingUser(siteManager).usingSite(moderatedSite).createFolder(); + testFolder = dataContent.usingUser(siteManager).usingSite(moderatedSite).createFolder(); + testFile = dataContent.usingUser(siteManager).usingResource(parentFolder) + .createContent(FileModel.getRandomFileModel(FileType.TEXT_PLAIN)); + cmisApi.authenticateUser(siteManager).usingResource(testFile) + .addDocumentToFolder(testFolder, true).then().assertThat().existsInRepo(); + + cmisApi.authenticateUser(unauthorizedUser).usingResource(testFile).removeDocumentFromFolder(testFolder); + } +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/RenameTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/RenameTests.java new file mode 100644 index 0000000000..a7206e8388 --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/RenameTests.java @@ -0,0 +1,351 @@ +package org.alfresco.cmis; + +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +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.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisContentAlreadyExistsException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class RenameTests extends CmisTest +{ + SiteModel testSite; + UserModel managerUser, inexistentUser, nonInvitedUser; + FileModel testFile; + FolderModel testFolder; + private DataUser.ListUserWithRoles usersWithRoles; + private String prefix = "-edit"; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + managerUser = dataUser.createRandomTestUser(); + nonInvitedUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(managerUser).createPublicRandomSite(); + inexistentUser = new UserModel("inexistent", "inexistent"); + usersWithRoles = dataUser.usingUser(managerUser) + .addUsersWithRolesToSite(testSite, UserRole.SiteContributor, UserRole.SiteCollaborator, UserRole.SiteConsumer); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.SANITY, + description = "Verify site manager is able to rename document and folder created by himself") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void siteManagerCanRenameContent() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, documentContent); + testFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).assertThat().existsInRepo() + .createFolder(testFolder).assertThat().existsInRepo() + .then().usingResource(testFile) + .rename(testFile.getName() + prefix).assertThat().existsInRepo() + .when().usingResource(testFile).assertThat().doesNotExistInRepo() + .then().usingResource(testFolder) + .rename(testFolder.getName() + prefix).assertThat().existsInRepo() + .when().usingResource(testFolder).assertThat().doesNotExistInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify admin user is able to rename document and folder created by himself") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void adminCanRenameContentFromPublicSite() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, documentContent); + testFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).assertThat().existsInRepo() + .createFolder(testFolder).assertThat().existsInRepo() + .then().authenticateUser(dataUser.getAdminUser()) + .usingResource(testFile) + .rename(testFile.getName() + prefix).assertThat().existsInRepo() + .when().usingResource(testFile).assertThat().doesNotExistInRepo() + .usingResource(testFolder) + .rename(testFolder.getName() + prefix).assertThat().existsInRepo() + .when().usingResource(testFolder).assertThat().doesNotExistInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is not able to rename inexistent document") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisObjectNotFoundException.class) + public void siteManagerCannotRenameInexistentDocument() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, documentContent); + testFile.setCmisLocation("/fake-folder/test.txt"); + cmisApi.authenticateUser(managerUser).usingSite(testSite) + .then().usingResource(testFile) + .rename(testFile.getName() + prefix).assertThat().existsInRepo() + .when().usingResource(testFile).assertThat().doesNotExistInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is not able to rename inexistent folder") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisObjectNotFoundException.class) + public void siteManagerCannotRenameInexistentFolder() throws Exception + { + FolderModel folder = FolderModel.getRandomFolderModel(); + folder.setCmisLocation("/" + folder.getName() + "/"); + cmisApi.authenticateUser(managerUser).usingSite(testSite) + .then().usingResource(folder) + .rename(prefix).assertThat().existsInRepo() + .when().usingResource(testFile).assertThat().doesNotExistInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is not able to rename document with invalid symbols") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisConstraintException.class) + public void siteManagerCannotRenameDocumentInvalidSymbols() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, documentContent); + cmisApi.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).assertThat().existsInRepo() + .then().usingResource(testFile) + .rename("/.:?|\\`\\.txt").assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is not able to rename folder with invalid symbols") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisConstraintException.class) + public void siteManagerCannotRenameFolderInvalidSymbols() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(managerUser).usingSite(testSite) + .createFolder(testFolder).assertThat().existsInRepo() + .then().usingResource(testFolder) + .rename("/.:?|\\`\\.txt").assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is not able to rename document with empty string") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=IllegalArgumentException.class, + expectedExceptionsMessageRegExp="New name must not be empty!*") + public void siteManagerCannotRenameDocumentEmptyName() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, documentContent); + cmisApi.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).assertThat().existsInRepo() + .then().usingResource(testFile) + .rename("").assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is not able to rename folder with empty name") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=IllegalArgumentException.class, + expectedExceptionsMessageRegExp="New name must not be empty!*") + public void siteManagerCannotRenameFolderEmptyName() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(managerUser).usingSite(testSite) + .createFolder(testFolder).assertThat().existsInRepo() + .then().usingResource(testFolder) + .rename("").assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is not able to rename checked out document") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisUpdateConflictException.class) + public void siteManagerCannotRenameCheckedOutDocument() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, documentContent); + cmisApi.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).assertThat().existsInRepo() + .then().checkOut().assertThat().documentIsCheckedOut() + .then().usingResource(testFile) + .rename(testFile.getName() + prefix).assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is able to rename pwc document") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanRenamePwcDocument() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, documentContent); + FileModel renamedPwc = new FileModel("pwc" + prefix + " (Working Copy)"); + cmisApi.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).assertThat().existsInRepo() + .then().checkOut().assertThat().documentIsCheckedOut() + .then().usingResource(testFile) + .usingPWCDocument().assertThat().existsInRepo() + .rename("pwc" + prefix); + renamedPwc.setCmisLocation(testFile.getCmisLocation().replace(testFile.getName(), renamedPwc.getName())); + cmisApi.usingResource(renamedPwc).assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is able to rename document with same name") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanRenameDocumentWithSameName() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, documentContent); + cmisApi.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).assertThat().existsInRepo() + .then().usingResource(testFile) + .rename(testFile.getName()).assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is able to rename document with multiple versions") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanRenameDocumentWithMultipleVersions() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, documentContent); + cmisApi.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).assertThat().existsInRepo() + .then().update("first content").assertThat().documentHasVersion(1.1) + .then().update("second content").assertThat().documentHasVersion(1.2) + .rename(testFile.getName() + prefix).assertThat().existsInRepo() + .and().assertThat().documentHasVersion(1.2); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify site collaborator is able to rename document created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteCollaboratorCanRenameDocumentCreatedByManager() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, documentContent); + cmisApi.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .rename(testFile.getName() + prefix).assertThat().existsInRepo() + .when().usingResource(testFile).assertThat().doesNotExistInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify site collaborator is able to rename folder created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteCollaboratorCanRenameFolderCreatedByManager() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(managerUser).usingSite(testSite) + .createFolder(testFolder).assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .rename(testFolder.getName() + prefix).assertThat().existsInRepo() + .when().usingResource(testFolder).assertThat().doesNotExistInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is able to rename folder created by collaborator") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanRenameFolderCreatedByCollaborator() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingSite(testSite) + .createFolder(testFolder).assertThat().existsInRepo() + .then().authenticateUser(managerUser) + .rename(testFolder.getName() + prefix).assertThat().existsInRepo() + .when().usingResource(testFolder).assertThat().doesNotExistInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify site collaborator is able to rename document created by himself") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteCollaboratorCanRenameDocumentCreatedByHimself() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, documentContent); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingSite(testSite) + .createFile(testFile).assertThat().existsInRepo() + .rename(testFile.getName() + prefix).assertThat().existsInRepo() + .when().usingResource(testFile).assertThat().doesNotExistInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify site contributor is not able to rename document created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void siteContributorCannotRenameDocumentCreatedByManager() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, documentContent); + cmisApi.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .rename(testFile.getName() + prefix).assertThat().existsInRepo() + .when().usingResource(testFile).assertThat().doesNotExistInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify site contributor is able to rename document created by himself") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteContributorCanRenameDocumentCreatedByHimself() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, documentContent); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingSite(testSite) + .createFile(testFile).assertThat().existsInRepo() + .rename(testFile.getName() + prefix).assertThat().existsInRepo() + .when().usingResource(testFile).assertThat().doesNotExistInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify site consumer is not able to rename document created by manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void siteConsumerCannotRenameDocumentCreatedByManager() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, documentContent); + cmisApi.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .rename(testFile.getName() + prefix).assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify non invited user is not able to rename document in public site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void siteConsumerCannotRenameDocumentInPublicSite() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, documentContent); + cmisApi.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .rename(testFile.getName() + prefix).assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify non invited user is not able to rename document in private site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void nonInvitedUserCannotRenameDocumentInPrivateSite() throws Exception + { + SiteModel privateSite = dataSite.usingUser(managerUser).createPrivateRandomSite(); + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, documentContent); + cmisApi.authenticateUser(managerUser).usingSite(privateSite) + .createFile(testFile).assertThat().existsInRepo() + .then().authenticateUser(nonInvitedUser) + .rename(testFile.getName() + prefix).assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify non invited user is not able to rename document in moderated site") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void nonInvitedUserCannotRenameDocumentInModeratedSite() throws Exception + { + SiteModel moderatedSite = dataSite.usingUser(managerUser).createModeratedRandomSite(); + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, documentContent); + cmisApi.authenticateUser(managerUser).usingSite(moderatedSite) + .createFile(testFile).assertThat().existsInRepo() + .then().authenticateUser(nonInvitedUser) + .rename(testFile.getName() + prefix).assertThat().existsInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is not able to rename document with same name as another file in same location") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisContentAlreadyExistsException.class, + expectedExceptionsMessageRegExp="An object with this name already exists.*") + public void siteManagerCannotRenameDocumentWithSameNameFromOtherFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, documentContent); + FileModel secondFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, documentContent); + cmisApi.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).assertThat().existsInRepo() + .createFile(secondFile) + .then().usingResource(testFile) + .rename(secondFile.getName()).assertThat().existsInRepo(); + } +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/RenditionTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/RenditionTests.java new file mode 100644 index 0000000000..5f4a03f9d8 --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/RenditionTests.java @@ -0,0 +1,168 @@ +package org.alfresco.cmis; + +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.enums.VersioningState; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +@Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS, TestGroup.RENDITIONS}) +public class RenditionTests extends CmisTest +{ + SiteModel testSite; + UserModel testUser, inexistentUser, nonInvitedUser; + FileModel testFile; + private DataUser.ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, documentContent); + testUser = dataUser.createRandomTestUser(); + nonInvitedUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(testUser).createPublicRandomSite(); + inexistentUser = new UserModel("inexistent", "inexistent"); + usersWithRoles = dataUser.usingUser(testUser) + .addUsersWithRolesToSite(testSite, UserRole.SiteContributor, UserRole.SiteCollaborator, UserRole.SiteConsumer); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).assertThat().existsInRepo(); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify admin can get renditions for valid Document object") + public void adminShouldGetRenditionsForDocument() throws Exception + { + FileModel txtModel = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, documentContent); + cmisApi.authenticateUser(dataUser.getAdminUser()).usingShared().createFile(txtModel) + .then().usingResource(txtModel).assertThat().renditionIsAvailable() + .assertThat().thumbnailRenditionIsAvailable(); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisObjectNotFoundException.class}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify admin can get renditions for invalid Document object") + public void adminCannotGetRenditionsForInvalidDocument() throws Exception + { + FileModel invalidFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, documentContent); + invalidFile.setCmisLocation("/" + invalidFile.getName() + "/"); + cmisApi.authenticateUser(dataUser.getAdminUser()).usingShared() + .then().usingResource(invalidFile).assertThat().renditionIsAvailable() + .assertThat().thumbnailRenditionIsAvailable(); + } + + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify site manager can get renditions for valid Document") + public void managerGetRenditionsForDocument() throws Exception + { + cmisApi.authenticateUser(testUser) + .usingResource(testFile).assertThat().renditionIsAvailable() + .assertThat().thumbnailRenditionIsAvailable(); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site collaborator can get renditions for valid Document") + public void collaboratorGetRenditionsForDocument() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .usingResource(testFile).assertThat().renditionIsAvailable() + .assertThat().thumbnailRenditionIsAvailable(); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site contributor can get renditions for valid Document") + public void contributorGetRenditionsForDocument() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .usingResource(testFile).assertThat().renditionIsAvailable() + .assertThat().thumbnailRenditionIsAvailable(); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site consumer can get renditions for valid Document") + public void consumerGetRenditionsForDocument() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .usingResource(testFile).assertThat().renditionIsAvailable() + .assertThat().thumbnailRenditionIsAvailable(); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager can get renditions for checked out document") + public void managerGetRenditionsForCheckedOutDocument() throws Exception + { + FileModel checkedDoc = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, documentContent); + cmisApi.authenticateUser(testUser) + .usingSite(testSite).createFile(checkedDoc, VersioningState.CHECKEDOUT).assertThat().documentIsCheckedOut() + .usingResource(checkedDoc) + .assertThat().renditionIsAvailable() + .assertThat().thumbnailRenditionIsAvailable(); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify non invited user can get renditions in public site") + public void nonInvitedUserGetRenditionsInPublicSite() throws Exception + { + cmisApi.authenticateUser(nonInvitedUser) + .usingResource(testFile) + .assertThat().renditionIsAvailable() + .assertThat().thumbnailRenditionIsAvailable(); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify non invited user cannot get renditions in private site") + public void nonInvitedUserCannotGetRenditionsInPrivateSite() throws Exception + { + SiteModel privateSite = dataSite.usingUser(testUser).createPrivateRandomSite(); + FileModel privateDoc = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, documentContent); + cmisApi.authenticateUser(testUser).usingSite(privateSite) + .createFile(privateDoc).assertThat().existsInRepo() + .authenticateUser(nonInvitedUser) + .usingResource(privateDoc) + .assertThat().renditionIsAvailable() + .assertThat().thumbnailRenditionIsAvailable(); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify non invited user cannot get renditions in moderated site") + public void nonInvitedUserCannotGetRenditionsInModeratedSite() throws Exception + { + SiteModel moderatedSite = dataSite.usingUser(testUser).createPrivateRandomSite(); + FileModel moderatedDoc = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, documentContent); + cmisApi.authenticateUser(testUser).usingSite(moderatedSite) + .createFile(moderatedDoc).assertThat().existsInRepo() + .authenticateUser(nonInvitedUser) + .usingResource(moderatedDoc) + .assertThat().renditionIsAvailable() + .assertThat().thumbnailRenditionIsAvailable(); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisUnauthorizedException.class) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify inexistent user cannot get renditions") + public void inexistentUserCannotGetRenditions() throws Exception + { + cmisApi.authenticateUser(inexistentUser) + .usingResource(testFile) + .assertThat().renditionIsAvailable() + .assertThat().thumbnailRenditionIsAvailable(); + } +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/RepositoryInfoTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/RepositoryInfoTests.java new file mode 100644 index 0000000000..8a24cb496f --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/RepositoryInfoTests.java @@ -0,0 +1,118 @@ +package org.alfresco.cmis; + +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.data.AclCapabilities; +import org.apache.chemistry.opencmis.commons.data.RepositoryCapabilities; +import org.apache.chemistry.opencmis.commons.data.RepositoryInfo; +import org.apache.chemistry.opencmis.commons.enums.BindingType; +import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class RepositoryInfoTests extends CmisTest +{ + UserModel testUser; + UserModel unauthorizedUser; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + testUser = dataUser.createRandomTestUser(); + unauthorizedUser = dataUser.createRandomTestUser(); + } + + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.SANITY, description = "Verify that valid user can get repositories") + public void validUserCanGetRepositories() throws Exception + { + Assert.assertNotNull(cmisApi.authenticateUser(testUser).getSession()); + } + + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}, expectedExceptions = CmisUnauthorizedException.class) + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.SANITY, description = "Verify that valid user with invalid password cannot get repositories") + public void unauthorizedUserCannotGetRepositories() throws Exception + { + unauthorizedUser.setPassword("invalidPass"); + cmisApi.authenticateUser(unauthorizedUser); + } + + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.SANITY, description = "Verify that valid user can get the repository informations") + public void validUserCanGetRepositoryInfo() throws Exception + { + RepositoryInfo repoInfo = cmisApi.authenticateUser(testUser).getRepositoryInfo(); + Assert.assertNotNull(repoInfo.getRootFolderId()); + Assert.assertNotNull(repoInfo.getProductVersion()); + Assert.assertNotNull(repoInfo.getRootFolderId()); + Assert.assertNotNull(repoInfo.getId()); + Assert.assertEquals(repoInfo.getProductName(), String.format("Alfresco %s", serverHealth.getAlfrescoEdition())); + Assert.assertEquals(repoInfo.getVendorName(), "Alfresco"); + RepositoryCapabilities capabilities = repoInfo.getCapabilities(); + Assert.assertNotNull(capabilities); + Assert.assertEquals(capabilities.getContentStreamUpdatesCapability().value(), "anytime", "Verify repository capability: capabilityContentStreamUpdatability"); + Assert.assertEquals(capabilities.getRenditionsCapability().value(), "read", "Verify repository capability: capabilityRenditions"); + Assert.assertTrue(capabilities.isGetDescendantsSupported(), "Verify repository capability: capabilityGetDescendants"); + Assert.assertTrue(capabilities.isGetFolderTreeSupported(), "Verify repository capability: capabilityGetFolderTree"); + Assert.assertTrue(capabilities.isMultifilingSupported(), "Verify repository capability: capabilityMultifiling"); + Assert.assertFalse(capabilities.isUnfilingSupported(), "Verify repository capability: capabilityUnfiling"); + Assert.assertFalse(capabilities.isVersionSpecificFilingSupported(), "Verify repository capability: capabilityVersionSpecificFiling"); + Assert.assertFalse(capabilities.isPwcSearchableSupported(), "Verify repository capability: capabilityPWCSearchable"); + Assert.assertTrue(capabilities.isPwcUpdatableSupported(), "Verify repository capability: capabilityPWCUpdatable"); + Assert.assertFalse(capabilities.isAllVersionsSearchableSupported(), "Verify repository capability: capabilityAllVersionsSearchable"); + Assert.assertEquals(capabilities.getQueryCapability().value(), "bothcombined", "Verify repository capability: capabilityQuery"); + Assert.assertEquals(capabilities.getJoinCapability().value(), "none", "Verify repository capability: capabilityJoin"); + Assert.assertEquals(capabilities.getAclCapability().value(), "manage", "Verify repository capability: capabilityACL"); + } + + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.SANITY, description = "Verify that valid user can get Acl Capabilities") + public void validUserCanGetAclCapabilities() throws Exception + { + AclCapabilities aclCapabilities = cmisApi.authenticateUser(testUser).getAclCapabilities(); + Assert.assertNotNull(aclCapabilities); + Assert.assertFalse(aclCapabilities.getPermissions().isEmpty(), "Verify acl capabilities: getPermissions"); + Assert.assertEquals(aclCapabilities.getSupportedPermissions().value(), "both", "Verify acl capabilities: getSupportedPermissions"); + Assert.assertEquals(aclCapabilities.getAclPropagation().value(), "propagate", "Verify acl capabilities: getAclPropagation"); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = CmisUnauthorizedException.class) + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, description = "Verify that invalid user cannot get repositories") + public void invalidUserCannotGetRepositories() throws Exception + { + UserModel invalidUser = UserModel.getRandomUserModel(); + cmisApi.authenticateUser(invalidUser).getRepositoryInfo(); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {NoSuchMethodError.class}, expectedExceptionsMessageRegExp = "^org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException.*") + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, description = "Verify that invalid user cannot get repositories") + public void userCannotGetRepositoriesUsingWrongBrowserUrl() throws Exception + { + String wrongUrlPath = "//alfresco//api//-default-//public//cmis//versions//1.1"; + cmisApi.authUserUsingBrowserUrlAndBindingType(testUser, wrongUrlPath, BindingType.BROWSER.value()).getRepositoryInfo(); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {IllegalArgumentException.class, CmisRuntimeException.class}, expectedExceptionsMessageRegExp = "Invalid binding type!") + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, description = "Verify that invalid user cannot get repositories") + public void userCannotGetRepositoriesUsingWrongBindingType() throws Exception + { + String wrongBindingType = BindingType.BROWSER.value() + "w"; + cmisApi.authUserUsingBrowserUrlAndBindingType(testUser, cmisApi.cmisProperties.envProperty().getFullServerUrl() + cmisApi.cmisProperties.getBasePath(), wrongBindingType).getRepositoryInfo(); + } + + @Bug(id="REPO-4301") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = CmisUnauthorizedException.class) + @TestRail(section = { "cmis-api" }, executionType = ExecutionType.REGRESSION, description = "Verify that disabled user cannot get repositories") + public void disabledUserCannotGetRepositories() throws Exception + { + UserModel disabledUser = dataUser.createRandomTestUser(); + Assert.assertNotNull(cmisApi.authenticateUser(disabledUser).getRepositoryInfo()); + dataUser.usingAdmin().disableUser(disabledUser); + cmisApi.authenticateUser(disabledUser).getRepositoryInfo(); + } +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/SecondaryTypesTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/SecondaryTypesTests.java new file mode 100644 index 0000000000..121bd2dab4 --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/SecondaryTypesTests.java @@ -0,0 +1,287 @@ +package org.alfresco.cmis; + +import java.util.Date; + +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +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.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.apache.commons.lang.time.DateUtils; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class SecondaryTypesTests extends CmisTest +{ + SiteModel testSite; + UserModel testUser, nonInvitedUser; + private DataUser.ListUserWithRoles usersWithRoles; + FileModel managerFile; + FolderModel managerFolder; + String titledAspect = "P:cm:titled"; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + managerFile = FileModel.getRandomFileModel(FileType.MSWORD2007, documentContent); + managerFolder = FolderModel.getRandomFolderModel(); + testUser = dataUser.createRandomTestUser(); + nonInvitedUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(testUser).createPublicRandomSite(); + usersWithRoles = dataUser.usingUser(testUser) + .addUsersWithRolesToSite(testSite, UserRole.SiteContributor, UserRole.SiteCollaborator, UserRole.SiteConsumer); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(managerFile) + .createFolder(managerFolder); + } + + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify site manager is able to get secondary types for Document") + public void userCanGetSecondaryTypesForDocument() throws Exception + { + cmisApi.authenticateUser(testUser).usingResource(managerFile) + .assertThat().secondaryTypeIsAvailable(titledAspect); + } + + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify site manager is able to get secondary types for Folder") + public void userCanGetSecondaryTypesForFolder() throws Exception + { + cmisApi.authenticateUser(testUser).usingResource(managerFolder) + .assertThat().secondaryTypeIsAvailable(titledAspect); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = {CmisObjectNotFoundException.class}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is NOT able to get secondary types for Folder") + public void userCannotGetSecondaryTypesForInvalidObject() throws Exception + { + FolderModel folder = FolderModel.getRandomFolderModel(); + folder.setCmisLocation("/" + folder.getName() + "/"); + cmisApi.authenticateUser(testUser) + .usingResource(folder) + .assertThat().secondaryTypeIsAvailable(titledAspect); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is NOT able to get invalid secondary type for Folder") + public void invalidSecondaryTypeIsNotAvailableForFolder() throws Exception + { + FolderModel folder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(folder).and().assertThat().existsInRepo() + .and().assertThat().secondaryTypeIsNotAvailable(titledAspect + "-fake"); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site collaborator is able to get secondary types") + public void collaboratorCanGetSecondaryTypesForContent() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .usingResource(managerFolder) + .assertThat().secondaryTypeIsAvailable(titledAspect) + .then().usingResource(managerFile) + .assertThat().secondaryTypeIsAvailable(titledAspect); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site contributor is able to get secondary types") + public void contributorCanGetSecondaryTypesForContent() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .usingResource(managerFolder) + .assertThat().secondaryTypeIsAvailable(titledAspect) + .then().usingResource(managerFile) + .assertThat().secondaryTypeIsAvailable(titledAspect); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site consumer is able to get secondary types") + public void consumerCanGetSecondaryTypesForContent() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .usingResource(managerFolder) + .assertThat().secondaryTypeIsAvailable(titledAspect) + .then().usingResource(managerFile) + .assertThat().secondaryTypeIsAvailable(titledAspect); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify non invited user is able to get secondary types in public site") + public void nonInvitedUserCanGetSecondaryTypesForContentInPublicSite() throws Exception + { + cmisApi.authenticateUser(nonInvitedUser) + .usingResource(managerFolder) + .assertThat().secondaryTypeIsAvailable(titledAspect) + .then().usingResource(managerFile) + .assertThat().secondaryTypeIsAvailable(titledAspect); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify non invited user is not able to get secondary types in private site") + public void nonInvitedUserCannotGetSecondaryTypesForContentInPrivateSite() throws Exception + { + SiteModel privateSite = dataSite.usingUser(testUser).createPrivateRandomSite(); + FileModel privateDoc = FileModel.getRandomFileModel(FileType.MSPOWERPOINT2007); + cmisApi.authenticateUser(testUser).usingSite(privateSite) + .createFile(privateDoc) + .authenticateUser(nonInvitedUser) + .assertThat().secondaryTypeIsAvailable(titledAspect); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify non invited user is not able to get secondary types in moderated site") + public void nonInvitedUserCannotGetSecondaryTypesInModeratedSite() throws Exception + { + SiteModel privateSite = dataSite.usingUser(testUser).createModeratedRandomSite(); + FileModel privateDoc = FileModel.getRandomFileModel(FileType.MSPOWERPOINT2007); + cmisApi.authenticateUser(testUser).usingSite(privateSite) + .createFile(privateDoc) + .authenticateUser(nonInvitedUser) + .assertThat().secondaryTypeIsAvailable(titledAspect); + } + + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify site manager is able to add secondary types for Document") + public void managerCanAddSecondaryTypesForDocument() throws Exception + { + cmisApi.authenticateUser(testUser).usingResource(managerFile) + .addSecondaryTypes("P:cm:dublincore") + .assertThat().secondaryTypeIsAvailable("P:cm:dublincore") + .assertThat().secondaryTypeIsAvailable(titledAspect) + .then().updateProperty("cm:subject", "TAS Subject") + .updateProperty("cm:rights", "TAS Rights") + .updateProperty("cm:publisher", "TAS Team") + .then().assertThat().objectHasProperty("cm:subject", "TAS Subject") + .assertThat().objectHasProperty("cm:rights", "TAS Rights") + .assertThat().objectHasProperty("cm:publisher", "TAS Team"); + } + + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.SANITY, + description = "Verify site manager is able to add secondary types for folder") + public void managerCanAddSecondaryTypesForFolder() throws Exception + { + cmisApi.authenticateUser(testUser).usingResource(managerFolder) + .addSecondaryTypes("P:cm:geographic") + .assertThat().secondaryTypeIsAvailable("P:cm:geographic") + .assertThat().secondaryTypeIsAvailable(titledAspect) + .then().updateProperty("cm:longitude", 455.21) + .updateProperty("cm:latitude", 101.32) + .then().assertThat().objectHasProperty("cm:longitude", 455.21) + .assertThat().objectHasProperty("cm:latitude", 101.32); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisObjectNotFoundException.class, + expectedExceptionsMessageRegExp="Type 'P:cm:fakeAspect' is unknown!*") + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is not able to add fake secondary type") + public void managerCannotAddInexistentSecondaryType() throws Exception + { + cmisApi.authenticateUser(testUser).usingResource(managerFolder) + .addSecondaryTypes("P:cm:fakeAspect"); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is able to add twice same secondary type") + public void managerCanAddTwiceSameSecondaryType() throws Exception + { + cmisApi.authenticateUser(testUser).usingResource(managerFile) + .addSecondaryTypes("P:cm:dublincore") + .assertThat().secondaryTypeIsAvailable("P:cm:dublincore") + .then().addSecondaryTypes("P:cm:dublincore") + .assertThat().secondaryTypeIsAvailable("P:cm:dublincore"); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site collaborator is able to add secondary types for document created by manager") + public void collaboratorCanAddAspectForDocument() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingResource(managerFile) + .addSecondaryTypes("P:audio:audio") + .assertThat().secondaryTypeIsAvailable("P:audio:audio") + .assertThat().secondaryTypeIsAvailable(titledAspect) + .then().updateProperty("audio:channelType", "TAS") + .updateProperty("audio:trackNumber", 9) + .updateProperty("audio:sampleType", "TAS Sample") + .then().assertThat().objectHasProperty("audio:channelType", "TAS") + .assertThat().objectHasProperty("audio:trackNumber", 9) + .assertThat().objectHasProperty("audio:sampleType", "TAS Sample"); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site contributor is able to add secondary types for document created by manager") + public void contributorCanAddAspectForDocument() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingResource(managerFile) + .addSecondaryTypes("P:dp:restrictable") + .assertThat().secondaryTypeIsAvailable("P:dp:restrictable") + .assertThat().secondaryTypeIsAvailable(titledAspect) + .then().updateProperty("dp:offlineExpiresAfter", 2) + .and().assertThat().objectHasProperty("dp:offlineExpiresAfter", 2); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site contributor is able to add secondary types for document created by manager") + public void consumerCanAddAspectForDocument() throws Exception + { + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).usingResource(managerFile) + .addSecondaryTypes("P:dp:restrictable") + .assertThat().secondaryTypeIsAvailable("P:dp:restrictable") + .assertThat().secondaryTypeIsAvailable(titledAspect) + .then().updateProperty("dp:offlineExpiresAfter", 2) + .and().assertThat().objectHasProperty("dp:offlineExpiresAfter", 2); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is able to add twice same secondary type") + public void managerCanAddDateProperty() throws Exception + { + Date today = new Date(); + Date tomorow = new Date(); + tomorow = DateUtils.addDays(tomorow, 1); + cmisApi.authenticateUser(testUser).usingResource(managerFile) + .addSecondaryTypes("P:cm:effectivity") + .assertThat().secondaryTypeIsAvailable("P:cm:effectivity") + .then().updateProperty("cm:to", today) + .updateProperty("cm:from", tomorow) + .and().assertThat().objectHasProperty("cm:to", today) + .assertThat().objectHasProperty("cm:from", tomorow); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=IllegalArgumentException.class, + expectedExceptionsMessageRegExp="Property 'cm:fake-prop' is not valid for this type or one of the secondary types!*") + @TestRail(section = {"cmis-api"}, executionType= ExecutionType.REGRESSION, + description = "Verify site manager is not able to update aspect with fake property") + public void managerCannotUpdateFakePropertyFromAspect() throws Exception + { + cmisApi.authenticateUser(testUser).usingResource(managerFile) + .addSecondaryTypes("P:cm:dublincore") + .assertThat().secondaryTypeIsAvailable("P:cm:dublincore") + .assertThat().secondaryTypeIsAvailable(titledAspect) + .then().updateProperty("cm:fake-prop", "fake-prop"); + } +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/SetContentTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/SetContentTests.java new file mode 100644 index 0000000000..7ceada39ae --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/SetContentTests.java @@ -0,0 +1,246 @@ +package org.alfresco.cmis; + +import org.alfresco.cmis.exception.InvalidCmisObjectException; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.*; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.exceptions.CmisContentAlreadyExistsException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 9/28/2016. + */ +public class SetContentTests extends CmisTest +{ + UserModel siteManager; + SiteModel publicSite; + FileModel testFile; + FolderModel testFolder; + private String someContent = "some content"; + private String secondContent = "second content"; + private DataUser.ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + siteManager = dataUser.createRandomTestUser(); + publicSite = dataSite.usingUser(siteManager).createPublicRandomSite(); + usersWithRoles = dataUser.addUsersWithRolesToSite(publicSite, UserRole.SiteManager, UserRole.SiteContributor, UserRole.SiteCollaborator, UserRole.SiteConsumer); + } + + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.SANITY, + description = "Verify site manager is able to set content to a valid document in DocumentLibrary with CMIS") + public void siteManagerSetFileContentForFileCreatedBySelf() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "first content"); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(testFile).assertThat().existsInRepo() + .then().update("content") + .then().setContent(someContent).and().refreshResource() + .then().assertThat().contentIs(someContent) + .and().assertThat().contentLengthIs(12); + } + + @Test(expectedExceptions = InvalidCmisObjectException.class, groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify if exception is thrown when user tries to set content to an invalid document in DocumentLibrary with CMIS") + public void siteManagerSetFolderContent() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(siteManager) + .usingSite(publicSite) + .createFolder(testFolder).setContent(someContent); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisUnauthorizedException.class) + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify that inexistent user is not able to set content to a document with CMIS") + public void inexistentUserCannotSetFileContent() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(testFile).assertThat().existsInRepo() + .and().assertThat().contentLengthIs(0) + .then().authenticateUser(UserModel.getRandomUserModel()) + .setContent(someContent); + } + + @Bug(id="ACE-5614") + @Test(groups = { TestGroup.REGRESSION , TestGroup.CMIS}) + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is able to set content to a document with no content with overwrite parameter set to false with CMIS") + public void siteManagerCanSetContentWithFalseOverwriteToDocWithNoContent() throws Exception + { + FileModel newFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(newFile).assertThat().existsInRepo() + .and().assertThat().contentLengthIs(0) + .then().setContent(someContent, false).and() + .and().assertThat().contentIs(someContent); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisContentAlreadyExistsException.class) + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is not able to set content to a document with content with overwrite parameter set to false with CMIS") + public void siteManagerCanSetContentWithFalseOverwriteToDocWithContent() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, someContent); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(testFile).assertThat().existsInRepo() + .and().assertThat().contentIs(someContent) + .then().setContent(secondContent, false); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify unauthorized user is not able to set content to a document") + public void unauthorizedUserCannotSetContent() throws Exception + { + UserModel unauthorizedUser = dataUser.createRandomTestUser(); + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, someContent); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(testFile).assertThat().existsInRepo() + .then().authenticateUser(unauthorizedUser) + .setContent(secondContent); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify admin is able to set file content with CMIS") + public void adminCanSetFileContent() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "first content"); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingSite(publicSite) + .createFile(testFile).assertThat().existsInRepo() + .then().authenticateUser(dataUser.getAdminUser()) + .and().setContent(someContent).and().refreshResource() + .then().assertThat().contentIs(someContent) + .and().assertThat().contentLengthIs(12); + } + + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.SANITY, + description = "Verify site manager is able to set file content for a file created by other user with CMIS") + public void managerCanSetFileContentForFileCreatedByOtherUser() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "first content"); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingSite(publicSite) + .createFile(testFile).assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .and().setContent(someContent).and().refreshResource() + .then().assertThat().contentIs(someContent) + .and().assertThat().contentLengthIs(12); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site contributor is not able to set content to a document created by other user with CMIS") + public void contributorCannotSetFileContentForFileCreatedByOtherUser() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "first content"); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(testFile).assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .then().setContent(someContent); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site contributor is able to set content to a document created by self with CMIS") + public void contributorCanSetFileContentForFileCreatedBySelf() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "first content"); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingSite(publicSite) + .createFile(testFile).assertThat().existsInRepo() + .then().setContent(someContent).and().refreshResource() + .then().assertThat().contentIs(someContent) + .and().assertThat().contentLengthIs(12); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site collaborator is able to set content to a document created by other user with CMIS") + public void collaboratorCanSetFileContentForFileCreatedByOtherUser() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "first content"); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(testFile).assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .then().usingResource(testFile) + .setContent(someContent).and().refreshResource() + .and().assertThat().contentIs(someContent) + .assertThat().contentLengthIs(12); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site collaborator is able to set content to a document created by self with CMIS") + public void collaboratorCanSetFileContentForFileCreatedBySelf() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "first content"); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingSite(publicSite) + .createFile(testFile).assertThat().existsInRepo() + .then().setContent(someContent).and().refreshResource() + .then().assertThat().contentIs(someContent) + .and().assertThat().contentLengthIs(12); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site consumer is not able to set file content with CMIS") + public void consumerCannotSetFileContent() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "first content"); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(testFile).assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .then().setContent(someContent); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions = CmisUpdateConflictException.class, expectedExceptionsMessageRegExp = "^.*Cannot perform operation since the node.*is locked.$") + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is able to set content to a checked out document with CMIS") + public void siteManagerCannotSetContentToCheckedOutFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "first content"); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(testFile).assertThat().existsInRepo() + .then().checkOut().and().assertThat().documentIsCheckedOut() + .setContent(someContent); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is able to set content to PWC document version with CMIS") + public void siteManagerSetContentToPWCFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "first content"); + cmisApi.authenticateUser(siteManager).usingSite(publicSite) + .createFile(testFile).assertThat().existsInRepo() + .then().checkOut().and().assertThat().documentIsCheckedOut() + .usingPWCDocument().setContent(someContent).and().refreshResource() + .then().assertThat().contentIs(someContent) + .and().assertThat().contentLengthIs(12); + } + + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + @TestRail(section = {"cmis-api" }, executionType = ExecutionType.REGRESSION, + description = "Verify unauthorized user is not able to set content to a document from a private site") + public void unauthorizedUserCannotSetContentToPrivateSiteDoc() throws Exception + { + SiteModel privateSite = dataSite.usingUser(siteManager).createPrivateRandomSite(); + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, someContent); + cmisApi.authenticateUser(siteManager).usingSite(privateSite) + .createFile(testFile).assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .usingResource(testFile).setContent(secondContent); + } +} diff --git a/tests/tas-cmis/src/test/java/org/alfresco/cmis/UpdatePropertiesTests.java b/tests/tas-cmis/src/test/java/org/alfresco/cmis/UpdatePropertiesTests.java new file mode 100644 index 0000000000..da87ca47f6 --- /dev/null +++ b/tests/tas-cmis/src/test/java/org/alfresco/cmis/UpdatePropertiesTests.java @@ -0,0 +1,357 @@ +package org.alfresco.cmis; + +import java.util.HashMap; +import java.util.Map; + +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.data.RandomData; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +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.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.PropertyIds; +import org.apache.chemistry.opencmis.commons.enums.VersioningState; +import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 9/30/2016. + */ +public class UpdatePropertiesTests extends CmisTest +{ + UserModel testUser; + SiteModel testSite; + FileModel testFile; + FolderModel testFolder; + String propertyNameValue; + private DataUser.ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + testUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(testUser).createPublicRandomSite(); + dataContent.deployContentModel("shared-resources/model/tas-model.xml"); + usersWithRoles = dataUser.usingUser(testUser) + .addUsersWithRolesToSite(testSite, UserRole.SiteContributor, UserRole.SiteCollaborator, UserRole.SiteConsumer); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.SANITY, + description = "Verify site manager is able to update properties to a valid document in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void siteManagerUpdatesFileProperties() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + propertyNameValue = RandomData.getRandomAlphanumeric(); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).assertThat().existsInRepo() + .then().updateProperty("cmis:name", propertyNameValue) + .and().assertThat().contentPropertyHasValue("cmis:name", propertyNameValue) + .then().updateProperty("cmis:description", "some description") + .and().assertThat().contentPropertyHasValue("cmis:description", "some description"); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.SANITY, + description = "Verify site manager is able to update properties to a valid folder in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.SANITY, TestGroup.CMIS}) + public void siteManagerUpdatesFolderProperties() throws Exception + { + propertyNameValue = RandomData.getRandomAlphanumeric(); + testFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(testUser).usingSite(testSite).createFolder(testFolder).assertThat().existsInRepo() + .then().updateProperty("cmis:name", propertyNameValue) + .and().assertThat().contentPropertyHasValue("cmis:name", propertyNameValue) + .then().updateProperty("cmis:description", "some description") + .and().assertThat().contentPropertyHasValue("cmis:description", "some description"); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify if exception is thrown when user tries to update properties to a non existent document in DocumentLibrary with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisObjectNotFoundException.class) + public void siteManagerUpdatesNoneExistentFileProperties() throws Exception + { + propertyNameValue = RandomData.getRandomAlphanumeric(); + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite).createFile(testFile).assertThat().existsInRepo() + .then().delete().and().assertThat().doesNotExistInRepo() + .then().updateProperty("cmis:name", propertyNameValue); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is not able to update properties with invalid property with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=IllegalArgumentException.class) + public void siteManagerCannotUpdateFileWithInvalidProperty() throws Exception + { + propertyNameValue = RandomData.getRandomAlphanumeric(); + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).assertThat().existsInRepo() + .then().updateProperty("cmis:fakeProp", propertyNameValue); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify that deleted user is not able to update properties with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisUnauthorizedException.class) + public void deletedUserCannotUpdateFileProperties() throws Exception + { + propertyNameValue = RandomData.getRandomAlphanumeric(); + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + UserModel toBeDeleted = dataUser.createRandomTestUser(); + FolderModel shared = FolderModel.getSharedFolderModel(); + cmisApi.authenticateUser(toBeDeleted) + .usingResource(shared) + .createFile(testFile).and().assertThat().existsInRepo(); + dataUser.deleteUser(toBeDeleted); + cmisApi.updateProperty("cmis:name", propertyNameValue); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is not able to update name property while document is checked out with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCannotUpdatePWCDocumentName() throws Exception + { + propertyNameValue = RandomData.getRandomAlphanumeric(); + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).assertThat().existsInRepo() + .then().checkOut() + .and().assertThat().documentIsCheckedOut() + .usingPWCDocument().updateProperty("cmis:name", testFile.getName() + "-edit") + .cancelCheckOut() + .then().usingResource(testFile) + .assertThat().contentPropertyHasValue("cmis:name", testFile.getName()); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is able to update the title and description while document is checked out with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanUpdateCheckOutDocTitleAndDescription() throws Exception + { + propertyNameValue = RandomData.getRandomAlphanumeric(); + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).assertThat().existsInRepo() + .then().checkOut().and().assertThat().documentIsCheckedOut() + .then().usingPWCDocument() + .updateProperty("cmis:description", propertyNameValue) + .updateProperty("cm:title", propertyNameValue) + .and().assertThat().contentPropertyHasValue("cmis:description", propertyNameValue) + .assertThat().contentPropertyHasValue("cm:title", propertyNameValue); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is able to update the title and description for document with version is checked out with CMIS") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanUpdateDocumentWithVersion() throws Exception + { + propertyNameValue = RandomData.getRandomAlphanumeric(); + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite).createFile(testFile).assertThat().existsInRepo() + .then().update("first content").update("second content") + .updateProperty("cmis:description", propertyNameValue) + .updateProperty("cm:title", propertyNameValue) + .and().assertThat().contentPropertyHasValue("cmis:description", propertyNameValue) + .assertThat().contentPropertyHasValue("cm:title", propertyNameValue); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is not able to update document name with invalid symbols") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisConstraintException.class) + public void siteManagerCannotUpdateDocNameInvalidSymbols() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + propertyNameValue = "/.:?|\\`\\"; + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).assertThat().existsInRepo() + .then().updateProperty("cmis:name", propertyNameValue); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is not able to update folder name with invalid symbols") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisConstraintException.class) + public void siteManagerCannotUpdateFolderNameInvalidSymbols() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + propertyNameValue = "/.:?|\\`\\"; + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(testFolder).assertThat().existsInRepo() + .then().updateProperty("cmis:name", propertyNameValue); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is not able to update document name with empty value") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisRuntimeException.class, + expectedExceptionsMessageRegExp="Local name cannot be null or empty.") + public void siteManagerCannotUpdateDocNameEmptyValue() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).assertThat().existsInRepo() + .then().updateProperty("cmis:name", ""); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is not able to update folder name with empty value") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisRuntimeException.class, + expectedExceptionsMessageRegExp="Local name cannot be null or empty.") + public void siteManagerCannotUpdateFolderNameEmptyValue() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFolder(testFolder).assertThat().existsInRepo() + .then().updateProperty("cmis:name", ""); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is able to update Integer and Long types with max values") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanUpdateIntAndLongTypesWithMaxValue() throws Exception + { + FileModel customFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "custom content"); + Map properties = new HashMap(); + properties.put(PropertyIds.OBJECT_TYPE_ID, "D:tas:document"); + properties.put(PropertyIds.NAME, customFile.getName()); + + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(customFile, properties, VersioningState.MAJOR).assertThat().existsInRepo() + .then().updateProperty("tas:IntPropertyC", Integer.MAX_VALUE) + .and().assertThat().contentPropertyHasValue("tas:IntPropertyC", String.valueOf(Integer.MAX_VALUE)) + .then().updateProperty("tas:LongPropertyC", Long.MAX_VALUE) + .and().assertThat().contentPropertyHasValue("tas:LongPropertyC", String.valueOf(Long.MAX_VALUE)); + cmisApi.usingResource(customFile).delete().assertThat().doesNotExistInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is able to update Integer and Long types with min values") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void siteManagerCanUpdateIntAndLongTypesWithMinValue() throws Exception + { + FileModel customFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "custom content"); + Map properties = new HashMap(); + properties.put(PropertyIds.OBJECT_TYPE_ID, "D:tas:document"); + properties.put(PropertyIds.NAME, customFile.getName()); + + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(customFile, properties, VersioningState.MAJOR).assertThat().existsInRepo() + .then().updateProperty("tas:IntPropertyC", Integer.MIN_VALUE) + .and().assertThat().contentPropertyHasValue("tas:IntPropertyC", String.valueOf(Integer.MIN_VALUE)) + .then().updateProperty("tas:LongPropertyC", Long.MIN_VALUE) + .and().assertThat().contentPropertyHasValue("tas:LongPropertyC", String.valueOf(Long.MIN_VALUE)); + cmisApi.usingResource(customFile).delete().assertThat().doesNotExistInRepo(); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify site collaborator is able to update properties to a valid document created by himself") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void collaboratorCanUpdateHisOwnFileProperties() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + propertyNameValue = RandomData.getRandomAlphanumeric(); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingSite(testSite) + .createFile(testFile).assertThat().existsInRepo() + .then().updateProperty("cmis:name", propertyNameValue) + .and().assertThat().contentPropertyHasValue("cmis:name", propertyNameValue) + .then().updateProperty("cmis:description", "some description") + .and().assertThat().contentPropertyHasValue("cmis:description", "some description"); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify site collaborator is able to update properties to a valid document created by site manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void collaboratorCanUpdateFilePropertiesCreatedByManager() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + propertyNameValue = RandomData.getRandomAlphanumeric(); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .and().updateProperty("cmis:name", propertyNameValue) + .and().assertThat().contentPropertyHasValue("cmis:name", propertyNameValue) + .then().updateProperty("cmis:description", "some description") + .and().assertThat().contentPropertyHasValue("cmis:description", "some description"); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify site contributor is able to update properties to a valid document created by himself") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void contributorCanUpdateHisOwnFileProperties() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + propertyNameValue = RandomData.getRandomAlphanumeric(); + cmisApi.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingSite(testSite) + .createFile(testFile).assertThat().existsInRepo() + .then().updateProperty("cmis:name", propertyNameValue) + .and().assertThat().contentPropertyHasValue("cmis:name", propertyNameValue) + .then().updateProperty("cmis:description", "some description") + .and().assertThat().contentPropertyHasValue("cmis:description", "some description"); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify site collaborator is able to update properties to a valid document created by site manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}) + public void contributorCanUpdateFilePropertiesCreatedByManager() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + propertyNameValue = RandomData.getRandomAlphanumeric(); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .and().updateProperty("cmis:name", propertyNameValue) + .and().assertThat().contentPropertyHasValue("cmis:name", propertyNameValue) + .then().updateProperty("cmis:description", "some description") + .and().assertThat().contentPropertyHasValue("cmis:description", "some description"); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify site consumer is not able to update properties to a valid document created by site manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void consumerCannotUpdateFilePropertiesCreatedByManager() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + propertyNameValue = RandomData.getRandomAlphanumeric(); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .and().updateProperty("cmis:name", propertyNameValue); + } + + @Bug(id="REPO-4301") + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify disabled user is not able to update properties") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions=CmisUnauthorizedException.class) + public void disabledUserCannotUpdateFileProperties() throws Exception + { + UserModel disabledUser = dataUser.createRandomTestUser(); + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + propertyNameValue = RandomData.getRandomAlphanumeric(); + cmisApi.authenticateUser(disabledUser).usingShared() + .createFile(testFile).assertThat().existsInRepo(); + dataUser.usingAdmin().disableUser(disabledUser); + cmisApi.usingResource(testFile).updateProperty("cmis:name", propertyNameValue); + } + + @TestRail(section = {"cmis-api"}, executionType = ExecutionType.REGRESSION, + description = "Verify non invited user is not able to update properties to a document created by site manager") + @Test(groups = { TestGroup.REGRESSION, TestGroup.CMIS}, expectedExceptions={CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + public void nonInvitedUserCannotUpdateFilePropertiesCreatedByManager() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + UserModel nonInvitedUser = dataUser.createRandomTestUser(); + propertyNameValue = RandomData.getRandomAlphanumeric(); + cmisApi.authenticateUser(testUser).usingSite(testSite) + .createFile(testFile).assertThat().existsInRepo() + .then().authenticateUser(nonInvitedUser) + .and().updateProperty("cmis:name", propertyNameValue); + } +} diff --git a/tests/tas-cmis/src/test/resources/alfresco-cmis-context.xml b/tests/tas-cmis/src/test/resources/alfresco-cmis-context.xml new file mode 100644 index 0000000000..ecf3d2db4b --- /dev/null +++ b/tests/tas-cmis/src/test/resources/alfresco-cmis-context.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + diff --git a/tests/tas-cmis/src/test/resources/cmis-suite.xml b/tests/tas-cmis/src/test/resources/cmis-suite.xml new file mode 100644 index 0000000000..46728ee4e4 --- /dev/null +++ b/tests/tas-cmis/src/test/resources/cmis-suite.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/tas-cmis/src/test/resources/default.properties b/tests/tas-cmis/src/test/resources/default.properties new file mode 100644 index 0000000000..9ca9119ba5 --- /dev/null +++ b/tests/tas-cmis/src/test/resources/default.properties @@ -0,0 +1,76 @@ +# dataprep related +alfresco.scheme=http +alfresco.server=localhost +alfresco.port=8082 + +# credentials +admin.user=admin +admin.password=admin + +solrWaitTimeInSeconds=30 + +# in containers we cannot access directly JMX, so we will use http://jolokia.org agent +# disabling this we will use direct JMX calls to server +jmx.useJolokiaAgent=false + +# Server Health section +# in ServerHealth#isServerReachable() - could also be shown. +# enable this option to view if on server there are tenants or not +serverHealth.showTenants=true + +# set CMIS binding to 'browser' or 'atom' +cmis.binding=browser +cmis.basePath=/alfresco/api/-default-/public/cmis/versions/1.1/${cmis.binding} + +# TEST MANAGEMENT SECTION - Test Rail +# +# (currently supporting Test Rail v5.2.1.3472 integration) +# +# Example of configuration: +# ------------------------------------------------------ +# if testManagement.enabled=true we enabled TestRailExecutorListener (if used in your suite xml file) +# testManagement.updateTestExecutionResultsOnly=true (this will just update the results of a test: no step will be updated - good for performance) +# testManagement.endPoint=https://alfresco.testrail.com/ +# testManagement.username= +# testManagement.apiKey= +# testManagement.project= +# testManagement.includeOnlyTestCasesExecuted=true #if you want to include in your run ONLY the test cases that you run, then set this value to false +# testManagement.rateLimitInSeconds=1 #is the default rate limit after what minimum time, should we upload the next request. http://docs.gurock.com/testrail-api2/introduction #Rate Limit +# testManagement.suiteId=23 (the id of the Master suite) +# ------------------------------------------------------ +testManagement.enabled=false +testManagement.endPoint= +testManagement.username= +testManagement.apiKey= +testManagement.project=7 +testManagement.includeOnlyTestCasesExecuted=true +testManagement.rateLimitInSeconds=1 +testManagement.testRun=MyTestRunInTestRail +testManagement.suiteId=12 + +# The location of the reports path +reports.path=./target/reports + +# +# Database Section +# You should provide here the database URL, that can be a differed server as alfresco. +# https://docs.oracle.com/javase/tutorial/jdbc/basics/connecting.html +# +# Current supported db.url: +# +# MySQL: +# db.url = jdbc:mysql://${alfresco.server}:3306/alfresco +# +# PostgreSQL: +# db.url = jdbc:postgresql://:3306/alfresco +# +# Oracle: +# db.url = jdbc:oracle://:3306/alfresco +# +# MariaDB: +# db.url = jdbc:mariadb://:3306/alfresco +# +db.url = jdbc:mysql://${alfresco.server}:3306/alfresco +db.username = alfresco +db.password = alfresco diff --git a/tests/tas-cmis/src/test/resources/log4j.properties b/tests/tas-cmis/src/test/resources/log4j.properties new file mode 100644 index 0000000000..00e9b5a114 --- /dev/null +++ b/tests/tas-cmis/src/test/resources/log4j.properties @@ -0,0 +1,26 @@ +# Root logger option +log4j.rootLogger=INFO, file, stdout + +# Direct log messages to a log file +log4j.appender.file=org.apache.log4j.RollingFileAppender +log4j.appender.file.File=./target/reports/alfresco-tas.log +log4j.appender.file.MaxBackupIndex=10 +log4j.appender.file.layout=org.apache.log4j.PatternLayout +log4j.appender.file.layout.ConversionPattern=[%t] %d{HH:mm:ss} %-5p %c{1}:%L - %m%n + +# Direct log messages to stdout +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=[%t] %d{HH:mm:ss} %-5p %c{1}:%L - %m%n + +# TestRail particular log file +# Direct log messages to a log file +log4j.appender.testrailLog=org.apache.log4j.RollingFileAppender +log4j.appender.testrailLog.File=./target/reports/alfresco-testrail.log +log4j.appender.testrailLog.MaxBackupIndex=10 +log4j.appender.testrailLog.layout=org.apache.log4j.PatternLayout +log4j.appender.testrailLog.layout.ConversionPattern=%d{HH:mm:ss} %-5p %c{1}:%L - %m%n + +log4j.category.testrail=INFO, testrailLog +log4j.additivity.testrail=false \ No newline at end of file diff --git a/tests/tas-cmis/src/test/resources/shared-resources/model/tas-model.xml b/tests/tas-cmis/src/test/resources/shared-resources/model/tas-model.xml new file mode 100644 index 0000000000..892027f9c1 --- /dev/null +++ b/tests/tas-cmis/src/test/resources/shared-resources/model/tas-model.xml @@ -0,0 +1,151 @@ + + + + + Alfresco TAS custom model + Bogdan + 1.0 + + + + + + + + + + + + + CMIS TAS Content + cm:content + + + Text + d:text + + + Datetime + d:datetime + + + Integer + d:int + + + Long + d:long + + + Multiply String + d:text + true + true + + + + + + + false + false + + + cm:content + false + false + + + + + + + CMIS TAS Folder + cm:folder + + + Text + d:text + + + Datetime + d:datetime + + + Integer + d:int + + + Multiply String + d:text + true + true + + + + + + + false + false + + + cm:folder + false + false + + + + + + + + + TAS Content Aspect + + + Aspect Text + d:text + + + Aspect Datetime + d:datetime + + + Aspect Integer + d:int + + + Aspect Multiply String + d:text + true + true + + + + + + TAS Folder Aspect + + + Aspect Text + d:text + + + Aspect Datetime + d:datetime + + + Aspect Integer + d:int + + + Aspect Multiply String + d:text + true + true + + + + + \ No newline at end of file diff --git a/tests/tas-cmis/src/test/resources/shared-resources/testdata/cmis-checkIn.txt b/tests/tas-cmis/src/test/resources/shared-resources/testdata/cmis-checkIn.txt new file mode 100644 index 0000000000..863a223b69 --- /dev/null +++ b/tests/tas-cmis/src/test/resources/shared-resources/testdata/cmis-checkIn.txt @@ -0,0 +1 @@ +Sp23xfcYhUBYpsXuPFzn8nVQ \ No newline at end of file diff --git a/tests/tas-cmis/src/test/resources/shared-resources/testdata/cmis-resource b/tests/tas-cmis/src/test/resources/shared-resources/testdata/cmis-resource new file mode 100644 index 0000000000..e01d809153 --- /dev/null +++ b/tests/tas-cmis/src/test/resources/shared-resources/testdata/cmis-resource @@ -0,0 +1 @@ +tas \ No newline at end of file diff --git a/tests/tas-email/pom.xml b/tests/tas-email/pom.xml new file mode 100644 index 0000000000..b8734067ae --- /dev/null +++ b/tests/tas-email/pom.xml @@ -0,0 +1,66 @@ + + + 4.0.0 + org.alfresco.tas + content-repository-community-email-test + content-repository-community-email-test + 6.3.0-SNAPSHOT + jar + + + org.alfresco + content-repository-community-tas-tests-parent + 6.3.0-SNAPSHOT + ../pom.xml + + + + + Paul Brodner + + Test Automation Architect + + + + + + ${project.basedir}/src/test/resources/email-suite.xml + + + + + org.alfresco.tas + email + test + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + ${suiteXmlFile} + + + --illegal-access=warn + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + test-jar + + + + + + + diff --git a/tests/tas-email/src/test/java/org/alfresco/email/EmailTest.java b/tests/tas-email/src/test/java/org/alfresco/email/EmailTest.java new file mode 100644 index 0000000000..2a1a1b4a58 --- /dev/null +++ b/tests/tas-email/src/test/java/org/alfresco/email/EmailTest.java @@ -0,0 +1,100 @@ +package org.alfresco.email; + +import java.lang.reflect.Method; + +import org.alfresco.email.dsl.ServerConfiguration; +import org.alfresco.utility.LogFactory; +import org.alfresco.utility.data.*; +import org.alfresco.utility.model.*; +import org.alfresco.utility.network.ServerHealth; +import org.alfresco.utility.network.TenantConsole; +import org.slf4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; +import org.testng.annotations.*; + +@ContextConfiguration("classpath:alfresco-email-context.xml") +public abstract class EmailTest extends AbstractTestNGSpringContextTests +{ + private static Logger LOG = LogFactory.getLogger(); + + @Autowired + ServerHealth serverHealth; + + @Autowired + protected ImapWrapper imapProtocol; + + @Autowired + protected SmtpWrapper smtpProtocol; + + @Autowired + public DataUser dataUser; + + @Autowired + public DataGroup dataGroup; + + @Autowired + public DataSite dataSite; + + @Autowired + public DataContent dataContent; + + @Autowired + public DataLink dataLink; + + @Autowired + public DataCalendarEvent dataCalendarEvent; + + @Autowired + public DataWiki dataWiki; + + @Autowired + public TenantConsole tenantConsole; + + protected UserModel adminUser; + protected UserModel testUser; + protected SiteModel adminSite; + protected SiteModel testSite; + protected FolderModel testFolder; + protected FileModel testFile; + protected ContentModel contentModel; + + @BeforeSuite(alwaysRun = true) + public void checkServerHealth() throws Exception + { + super.springTestContextPrepareTestInstance(); + serverHealth.assertServerIsOnline(); + + UserModel anonymousUser = new UserModel("anonymous", DataUser.PASSWORD); + if (!dataUser.isUserInRepo(anonymousUser.getUsername())) + { + dataUser.createUser(anonymousUser); + dataGroup.usingUser(anonymousUser).addUserToGroup(GroupModel.getEmailContributorsGroup()); + } + + String jmxUseJolokiaAgent = System.getProperty("jmx.useJolokiaAgent"); + if ("true".equals(jmxUseJolokiaAgent)) + { + imapProtocol.assertThat().protocolIsEnabled(); + smtpProtocol.assertThat().protocolIsEnabled(); + ServerConfiguration.save(smtpProtocol.withJMX(), smtpProtocol.emailProperties); + } + else + { + LOG.warn("*** Jolokia is not used! To use jolokia, please add next system property when running the tests: jmx.useJolokiaAgent=true ***"); + } + } + + @BeforeMethod(alwaysRun=true) + public void showStartTestInfo(Method method) + { + LOG.info(String.format("*** STARTING Test: [%s] ***",method.getName())); + } + + @AfterMethod(alwaysRun=true) + public void showEndTestInfo(Method method) + { + LOG.info(String.format("*** ENDING Test: [%s] ***", method.getName())); + } +} diff --git a/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapCheckFolderTests.java b/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapCheckFolderTests.java new file mode 100644 index 0000000000..d99b21dad7 --- /dev/null +++ b/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapCheckFolderTests.java @@ -0,0 +1,189 @@ +package org.alfresco.email.imap; + +import org.alfresco.email.EmailTest; +import org.alfresco.utility.constants.UserRole; +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.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import javax.mail.FolderNotFoundException; +import javax.mail.MessagingException; + +public class ImapCheckFolderTests extends EmailTest +{ + UserModel managerUser; + SiteModel managerTestSite; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + managerUser = dataUser.createRandomTestUser(); + managerTestSite = dataSite.usingUser(managerUser).createIMAPSite(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.SANITY, + description = "Returns the current working directory with admin user") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.SANITY }) + public void adminShouldGetCurrentWorkingDirectory() throws Exception + { + testUser = dataUser.getAdminUser(); + testSite = dataSite.usingUser(testUser).createIMAPSite(); + testFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + imapProtocol.authenticateUser(testUser).usingSite(testSite).usingResource(testFolder).assertThat().existsInRepo() + .then().assertThat().currentDirectoryIs(testFolder); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.SANITY, + description = "Verify in IMAP client current directory/list of directories for site manager") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.SANITY }) + public void siteManagerShouldGetCurrentWorkingDirectory() throws Exception + { + testFolder = dataContent.usingUser(managerUser).usingSite(managerTestSite).createFolder(); + imapProtocol.authenticateUser(managerUser).usingSite(managerTestSite).usingResource(testFolder).assertThat().existsInRepo() + .then().assertThat().currentDirectoryIs(testFolder); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.SANITY, + description = "Returns the directories list of the root for site manager") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.SANITY }) + public void siteManagerShouldGetDirectoriesListOfRoot() throws Exception + { + testUser = dataUser.createRandomTestUser(); + FolderModel alfrescoImap = FolderModel.getRandomFolderModel(); + alfrescoImap.setName("Alfresco IMAP"); + FolderModel inbox = FolderModel.getRandomFolderModel(); + inbox.setName("INBOX"); + imapProtocol.authenticateUser(testUser).usingRoot() + .then().assertThat().contains(alfrescoImap, inbox); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.SANITY, + description = "User finds all its folders for IMAP Sites in Alfresco IMAP > Sites folder") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.SANITY }) + public void userShouldFindAllIMAPSitesFoldersInAlfrescoIMAPFolder() throws Exception + { + testUser = dataUser.createRandomTestUser(); + SiteModel imapSite1 = dataSite.usingUser(testUser).createIMAPSite(); + SiteModel imapSite2 = dataSite.usingUser(testUser).createIMAPSite(); + + imapProtocol.authenticateUser(testUser).usingSites().assertThat().existsInImap() + .then().assertThat().contains(imapSite1, imapSite2); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify in IMAP client current directory/list of directories for COLLABORATOR user - folder created by other user") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }) + public void collaboratorShouldGetCurrentWorkingDirectory() throws Exception + { + UserModel collaborator = dataUser.createRandomTestUser(); + dataUser.usingUser(managerUser).addUserToSite(collaborator, managerTestSite, UserRole.SiteCollaborator); + + testFolder = dataContent.usingUser(managerUser).usingSite(managerTestSite).createFolder(); + imapProtocol.authenticateUser(collaborator).usingSite(managerTestSite).usingResource(testFolder).assertThat().existsInRepo() + .then().assertThat().currentDirectoryIs(testFolder); + + dataSite.usingUser(collaborator).usingSite(managerTestSite).setIMAPFavorite(); + + FolderModel testFolder1 = dataContent.usingUser(managerUser).usingSite(managerTestSite) + .usingResource(testFolder).createFolder(); + FolderModel testFolder2 = dataContent.usingUser(managerUser).usingSite(managerTestSite) + .usingResource(testFolder).createFolder(); + + imapProtocol.authenticateUser(collaborator).usingSite(managerTestSite) + .usingResource(testFolder) + .then().assertThat().contains(testFolder1,testFolder2); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify in IMAP client current directory/list of directories for CONTRIBUTOR user - folder created by other user") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }) + public void contributorShouldGetCurrentWorkingDirectory() throws Exception + { + UserModel contributor = dataUser.createRandomTestUser(); + dataUser.usingUser(managerUser).addUserToSite(contributor, managerTestSite, UserRole.SiteContributor); + + testFolder = dataContent.usingUser(managerUser).usingSite(managerTestSite).createFolder(); + imapProtocol.authenticateUser(contributor).usingSite(managerTestSite).usingResource(testFolder).assertThat().existsInRepo() + .then().assertThat().currentDirectoryIs(testFolder); + + dataSite.usingUser(contributor).usingSite(managerTestSite).setIMAPFavorite(); + + FolderModel testFolder1 = dataContent.usingUser(managerUser).usingSite(managerTestSite) + .usingResource(testFolder).createFolder(); + FolderModel testFolder2 = dataContent.usingUser(managerUser).usingSite(managerTestSite) + .usingResource(testFolder).createFolder(); + + imapProtocol.authenticateUser(contributor).usingSite(managerTestSite) + .usingResource(testFolder) + .then().assertThat().contains(testFolder1,testFolder2); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify in IMAP client current directory/list of directories for CONSUMER user - folder created by other user") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.FULL }) + public void consumerShouldGetCurrentWorkingDirectory() throws Exception + { + UserModel consumer = dataUser.createRandomTestUser(); + dataUser.usingUser(managerUser).addUserToSite(consumer, managerTestSite, UserRole.SiteConsumer); + + testFolder = dataContent.usingUser(managerUser).usingSite(managerTestSite).createFolder(); + imapProtocol.authenticateUser(consumer).usingSite(managerTestSite).usingResource(testFolder).assertThat().existsInRepo() + .then().assertThat().currentDirectoryIs(testFolder); + + dataSite.usingUser(consumer).usingSite(managerTestSite).setIMAPFavorite(); + + FolderModel testFolder1 = dataContent.usingUser(managerUser).usingSite(managerTestSite) + .usingResource(testFolder).createFolder(); + FolderModel testFolder2 = dataContent.usingUser(managerUser).usingSite(managerTestSite) + .usingResource(testFolder).createFolder(); + + imapProtocol.authenticateUser(consumer).usingSite(managerTestSite) + .usingResource(testFolder) + .then().assertThat().contains(testFolder1,testFolder2); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify unauthorized is not able to access document library section ( PUBLIC imap SITE)") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.FULL }, expectedExceptions = FolderNotFoundException.class) + public void unAuthorizedUserCannotAccessPublicImapSiteDocumentLibrary() throws Exception + { + testUser = dataUser.createRandomTestUser(); + UserModel unauthorizedUser = dataUser.createRandomTestUser(); + SiteModel publicImapSite = dataSite.usingUser(testUser).createPublicRandomSite(); + dataSite.usingUser(unauthorizedUser).usingSite(publicImapSite).setIMAPFavorite(); + + imapProtocol.authenticateUser(unauthorizedUser).usingSite(publicImapSite).assertThat().doesNotContain(testFolder); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify unauthorized is not able to access document library section ( Moderated imap SITE)") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.FULL }, expectedExceptions = FolderNotFoundException.class) + public void unAuthorizedUserCannotAccessModeratedImapSiteDocumentLibrary() throws Exception + { + testUser = dataUser.createRandomTestUser(); + UserModel unauthorizedUser = dataUser.createRandomTestUser(); + SiteModel moderatedImapSite = dataSite.usingUser(testUser).createModeratedRandomSite(); + dataSite.usingUser(unauthorizedUser).usingSite(moderatedImapSite).setIMAPFavorite(); + + imapProtocol.authenticateUser(unauthorizedUser).usingSite(moderatedImapSite).assertThat().doesNotContain(testFolder); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify unauthorized is not able to access document library section ( Private imap SITE)") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.FULL }, expectedExceptions = MessagingException.class, + expectedExceptionsMessageRegExp = ".*Access Denied.*You do not have the appropriate permissions to perform this operation.*") + public void unAuthorizedUserCannotAccessPrivateImapSiteDocumentLibrary() throws Exception + { + testUser = dataUser.createRandomTestUser(); + UserModel unauthorizedUser = dataUser.createRandomTestUser(); + SiteModel privateImapSite = dataSite.usingUser(testUser).createPrivateRandomSite(); + dataSite.usingUser(unauthorizedUser).usingSite(privateImapSite).setIMAPFavorite(); + + imapProtocol.authenticateUser(unauthorizedUser).usingSite(privateImapSite).assertThat().doesNotContain(testFolder); + } +} diff --git a/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapConnectionTests.java b/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapConnectionTests.java new file mode 100644 index 0000000000..db73d0a9fc --- /dev/null +++ b/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapConnectionTests.java @@ -0,0 +1,79 @@ +package org.alfresco.email.imap; + +import org.alfresco.email.EmailTest; +import org.alfresco.utility.exception.TestConfigurationException; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Tests for Connection to Imap + * + * @author Cristina Axinte + * + */ +public class ImapConnectionTests extends EmailTest +{ + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + testUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(testUser).createIMAPSite(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.SANITY, + description = "Verify user can connect successfully to IMAP") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.SANITY }) + public void correctUserConnectsToIMAPSuccessfully() throws Exception + { + imapProtocol.authenticateUser(testUser).then().assertThat().userIsConnected(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.SANITY, + description = "Verify user fails to connect to IMAP on different port") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.SANITY }, expectedExceptions = TestConfigurationException.class) + public void userFailsConnectToIMAPOnDifferentPort() throws Exception + { + imapProtocol.authenticateUser(testUser, 43).then().assertThat().userIsNotConnected(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.SANITY, + description = "Verify user can disconnect successfully from IMAP Server") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.SANITY }) + public void userDisconnectsFromImapServerSuccessfully() throws Exception + { + imapProtocol.authenticateUser(testUser) + .disconnect().then().assertThat().userIsNotConnected(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify user fails to connect to IMAP on different host") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }, expectedExceptions = TestConfigurationException.class) + public void userFailsConnectToIMAPOnDifferentHost() throws Exception + { + imapProtocol.authenticateUser(testUser, "172.29.101.1256").then().assertThat().userIsNotConnected(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify existing user with wrong password fails to connect to IMAP") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }, expectedExceptions = TestConfigurationException.class, + expectedExceptionsMessageRegExp =".*You missed some configuration settings in your tests: User failed to connect to IMAP server LOGIN failed. Invalid login/password$" ) + public void userFailsConnectToIMAPWithWrongPassword() throws Exception + { + testUser = dataUser.createRandomTestUser(); + testUser.setPassword("invalid"); + imapProtocol.authenticateUser(testUser); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify a non existing user fails to connect to IMAP.") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.FULL }, expectedExceptions = TestConfigurationException.class, + expectedExceptionsMessageRegExp =".*You missed some configuration settings in your tests: User failed to connect to IMAP server LOGIN failed. Invalid login/password") + public void nonExistentUserFailsConnectToIMAP() throws Exception + { + imapProtocol.authenticateUser(new UserModel("nonExistingUser", "pass")); + } +} diff --git a/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapCopyFolderTests.java b/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapCopyFolderTests.java new file mode 100644 index 0000000000..d6929edab0 --- /dev/null +++ b/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapCopyFolderTests.java @@ -0,0 +1,124 @@ +package org.alfresco.email.imap; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.email.EmailTest; +import org.alfresco.utility.Utility; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.model.*; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import javax.mail.FolderNotFoundException; +import javax.mail.MessagingException; + +public class ImapCopyFolderTests extends EmailTest +{ + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + testUser = dataUser.createRandomTestUser(); + adminSite = dataSite.usingAdmin().createIMAPSite(); + testSite = dataSite.usingUser(testUser).createIMAPSite(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.SANITY, + description = "Verify copy non-empty folder to a different location by admin user") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.SANITY }) + public void adminShouldCopyNonEmptyFolder() throws Exception + { + testFolder = dataContent.usingAdmin().usingSite(adminSite).createFolder(); + FolderModel copyFolder = dataContent.usingAdmin().usingSite(adminSite).createFolder(); + FolderModel copiedFolder = testFolder; + copiedFolder.setProtocolLocation(Utility.buildPath(copyFolder.getProtocolLocation(), testFolder.getName())); + dataContent.usingResource(testFolder).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + imapProtocol.authenticateUser(adminUser).usingSite(adminSite).usingResource(testFolder) + .copyTo(copyFolder).then().usingResource(copiedFolder).assertThat().countMessagesIs(1); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.SANITY, + description = "Verify copy folder with Manager") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.SANITY }) + public void siteManagerShouldCopyFolder() throws Exception + { + testFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + FolderModel copyFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + FolderModel copiedFolder = testFolder; + copiedFolder.setCmisLocation(Utility.buildPath(copyFolder.getCmisLocation(), testFolder.getName())); + copiedFolder.setProtocolLocation(Utility.buildPath(copyFolder.getProtocolLocation(), testFolder.getName())); + imapProtocol.authenticateUser(testUser).usingSite(testSite).usingResource(testFolder) + .copyTo(copyFolder).then().usingResource(copiedFolder).assertThat().existsInRepo().assertThat().existsInImap(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify copy folder that has been deleted with Manager") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }, expectedExceptions = FolderNotFoundException.class) + public void siteManagerShouldNotCopyFolderThatHasBeenDeleted() throws Exception + { + testFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + FolderModel folderModel = dataContent.usingUser(testUser).usingSite(testSite).usingResource(testFolder).createFolder(); + imapProtocol.authenticateUser(testUser).usingSite(testSite).usingResource(folderModel).delete() + .and().assertThat().doesNotExistInRepo().assertThat().doesNotContain(folderModel) + .then().copyTo(testFolder); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify copy folder with Contributor user") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }) + public void contributorShouldCopyFolder() throws Exception + { + UserModel contributorUser = dataUser.createRandomTestUser(); + dataUser.addUserToSite(contributorUser, testSite, UserRole.SiteContributor); + testFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + FolderModel copyFolder = dataContent.usingUser(contributorUser).usingSite(testSite).createFolder(); + FolderModel copiedFolder = testFolder; + copiedFolder.setProtocolLocation(Utility.buildPath(copyFolder.getProtocolLocation(), testFolder.getName())); + dataContent.usingResource(testFolder).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + imapProtocol.authenticateUser(contributorUser).usingSite(testSite).usingResource(testFolder) + .copyTo(copyFolder).then().usingResource(copiedFolder).assertThat().countMessagesIs(1); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify copy folder with Collaborator user") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }) + public void collaboratorShouldCopyFolder() throws Exception + { + UserModel collaboratorUser = dataUser.createRandomTestUser(); + dataUser.addUserToSite(collaboratorUser, testSite, UserRole.SiteCollaborator); + testFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + FolderModel copyFolder = dataContent.usingUser(collaboratorUser).usingSite(testSite).createFolder(); + FolderModel copiedFolder = testFolder; + copiedFolder.setProtocolLocation(Utility.buildPath(copyFolder.getProtocolLocation(), testFolder.getName())); + dataContent.usingResource(testFolder).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + imapProtocol.authenticateUser(collaboratorUser).usingSite(testSite).usingResource(testFolder) + .copyTo(copyFolder).then().usingResource(copiedFolder).assertThat().countMessagesIs(1); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify that copy folder with Consumer user is not possible") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }, expectedExceptions = FolderNotFoundException.class) + public void consumerShouldNotCopyFolder() throws Exception + { + UserModel consumerUser = dataUser.createRandomTestUser(); + dataUser.addUserToSite(consumerUser, testSite, UserRole.SiteConsumer); + testFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + FolderModel copyFolder = new FolderModel("copyFolder"); + imapProtocol.authenticateUser(consumerUser).usingSite(testSite).createFolder(copyFolder).usingResource(testFolder) + .copyTo(copyFolder); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify copy folder to a location for which the user does not have permission") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }, expectedExceptions = MessagingException.class) + public void userCopyFolderToALocationThatHeDoesNotHaveAccess() throws Exception + { + SiteModel siteModel = dataSite.usingAdmin().createPrivateRandomSite(); + testFolder = dataContent.usingAdmin().usingSite(testSite).createFolder(); + FolderModel copyFolder = dataContent.usingAdmin().usingSite(siteModel).createFolder(); + dataContent.usingResource(testFolder).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + imapProtocol.authenticateUser(testUser).usingResource(testFolder) + .copyTo(copyFolder); + } +} diff --git a/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapCopyMessagesTests.java b/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapCopyMessagesTests.java new file mode 100644 index 0000000000..5e0d5bb701 --- /dev/null +++ b/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapCopyMessagesTests.java @@ -0,0 +1,111 @@ +package org.alfresco.email.imap; + +import javax.mail.MessagingException; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.email.EmailTest; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.testng.SkipException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class ImapCopyMessagesTests extends EmailTest +{ + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + testUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(testUser).createIMAPSite(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.SANITY, + description = "Verify site manager can copy non-empty file via IMAP client to a different location") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.SANITY }) + public void siteManagerShouldCopyNonEmptyFile() throws Exception + { + testFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + FileModel fileModel = dataContent.usingSite(testSite).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + imapProtocol.authenticateUser(testUser).usingSite(testSite).usingResource(fileModel).assertThat().existsInRepo() + .and().assertThat().existsInImap() + .then().copyMessageTo(testFolder).assertThat().containsMessages(fileModel); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.SANITY, + description = "Verify site manager can copy non-empty files via IMAP client to a different location") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.SANITY }) + public void siteManagerShouldCopyNonEmptyFiles() throws Exception + { + testFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + FileModel fileModel1 = dataContent.usingSite(testSite).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + FileModel fileModel2 = dataContent.usingSite(testSite).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + imapProtocol.authenticateUser(testUser).usingSite(testSite).usingResource(fileModel1).assertThat().existsInRepo() + .and().assertThat().existsInImap() + .then().usingSite(testSite).copyMessagesTo(testFolder).assertThat().containsMessages(fileModel1, fileModel2); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager can copy empty file via IMAP client to a different location") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }) + public void siteManagerShouldCopyEmptyFile() throws Exception + { + testFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + FileModel fileModel = new FileModel("EmptyFile.txt", FileType.TEXT_PLAIN, ""); + fileModel = dataContent.usingUser(testUser).usingSite(testSite).createContent(fileModel); + imapProtocol.authenticateUser(testUser).usingSite(testSite).usingResource(fileModel).assertThat().existsInRepo() + .and().assertThat().existsInImap() + .then().copyMessageTo(testFolder).assertThat().containsMessages(fileModel); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify user can copy file via IMAP client to a location where the message already exists") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }) + public void userShouldCopyFileWhereAlreadyExists() throws Exception + { + testFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + FileModel fileModel = new FileModel("CopyFile.txt", FileType.TEXT_PLAIN, "content of copied file"); + dataContent.usingSite(testSite).usingResource(testFolder).createContent(fileModel); + FileModel fileToBeCopied = dataContent.usingSite(testSite).createContent(fileModel); + + imapProtocol.authenticateUser(testUser).usingSite(testSite).usingResource(fileToBeCopied).assertThat().existsInRepo() + .and().assertThat().existsInImap() + .then().copyMessageTo(testFolder).assertThat().containsMessages(fileToBeCopied); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify user cannot copy a file via IMAP client if it was already deleted from repository") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }, expectedExceptions = MessagingException.class, + expectedExceptionsMessageRegExp ="There are no messages to be copied") + public void userCannotCopyDeletedFile() throws Exception + { + testFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + FileModel fileModel = dataContent.usingSite(testSite).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + imapProtocol.authenticateUser(testUser).usingSite(testSite).usingResource(fileModel).assertThat().existsInImap(); + dataContent.usingResource(fileModel).deleteContent(); + imapProtocol.copyMessageTo(testFolder); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify user cannot copy file via IMAP client to a location where you don't have permissions") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }, expectedExceptions = MessagingException.class, + expectedExceptionsMessageRegExp = ".*A4 NO APPEND failed. Can't append message - Permission denied.*") + public void userCannotCopyFileWhereNoPermissions() throws Exception + { + testFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + + UserModel user = dataUser.createRandomTestUser(); + SiteModel site = dataSite.usingUser(user).createIMAPSite(); + FileModel file = dataContent.usingUser(user).usingSite(site).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + dataSite.usingUser(user).usingSite(testSite).setIMAPFavorite(); + + imapProtocol.authenticateUser(user).usingSite(site).usingResource(file).assertThat().existsInRepo() + .and().assertThat().existsInImap() + .then().copyMessageTo(testFolder); + } +} diff --git a/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapCreateFolderTests.java b/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapCreateFolderTests.java new file mode 100644 index 0000000000..e32bc38829 --- /dev/null +++ b/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapCreateFolderTests.java @@ -0,0 +1,217 @@ +package org.alfresco.email.imap; + +import org.alfresco.email.EmailTest; +import org.alfresco.utility.constants.UserRole; +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.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import javax.mail.FolderNotFoundException; + +/** + * Tests for Create Folder action using IMAP client + * + * @author Cristina Axinte + * + */ +public class ImapCreateFolderTests extends EmailTest +{ + private UserModel adminUser; + private SiteModel imapSite; + + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + testUser = dataUser.createRandomTestUser(); + imapSite = dataSite.usingUser(testUser).createIMAPSite(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.SANITY, + description = "Verify admin can create a folder in Afresco IMAP root folder") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.SANITY }) + public void adminCanCreateFolderInAlfrescoImapRoot() throws Exception + { + FolderModel folderToCreate = FolderModel.getRandomFolderModel(); + + imapProtocol.authenticateUser(adminUser).usingAlfrescoImap().createFolder(folderToCreate) + .assertThat().existsInImap() + .assertThat().existsInRepo(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.SANITY, + description = "Verify user can create a folder in Afresco IMAP root folder, but it is not displayed in Alfresco Repository") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.SANITY }) + public void userCanCreateFolderInAlfrescoImapRootButNotDisplayedInRepo() throws Exception + { + FolderModel folderToCreate = FolderModel.getRandomFolderModel(); + + imapProtocol.authenticateUser(testUser).usingAlfrescoImap().createFolder(folderToCreate) + .assertThat().existsInImap() + .assertThat().doesNotExistInRepo(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.SANITY, + description = "Verify admin can create a folder in Sites folder and it will be displayed in Alfresco Repository/Sites") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.SANITY }) + public void adminCanCreateFolderInSitesFolder() throws Exception + { + FolderModel folderToCreate = FolderModel.getRandomFolderModel(); + + imapProtocol.authenticateUser(adminUser) + .usingSites().createFolder(folderToCreate) + .assertThat().existsInImap() + .assertThat().existsInRepo(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.SANITY, + description = "Verify manager can create a folder in IMAP Site > documentLibrary") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.SANITY }) + public void managerCanCreateFolderInIMAPSite() throws Exception + { + UserModel managerUser = dataUser.createRandomTestUser(); + dataUser.usingUser(testUser).addUserToSite(managerUser, imapSite, UserRole.SiteManager); + FolderModel folderToCreate = FolderModel.getRandomFolderModel(); + + imapProtocol.authenticateUser(managerUser) + .usingSite(imapSite).createFolder(folderToCreate) + .assertThat().existsInImap() + .assertThat().existsInRepo(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify manager can create a folder with spaces in name in IMAP Site > documentLibrary") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }) + public void managerCanCreateFolderWithSpacesInIMAPSite() throws Exception + { + UserModel managerUser = dataUser.createRandomTestUser(); + imapSite = dataSite.usingUser(managerUser).createIMAPSite(); + FolderModel folderToCreate = new FolderModel("Folder with spaces in name"); + + imapProtocol.authenticateUser(managerUser) + .usingSite(imapSite).createFolder(folderToCreate) + .assertThat().existsInImap() + .assertThat().existsInRepo(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify collaborator can create a folder in IMAP Site > documentLibrary") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }) + public void collaboratorCanCreateFolderInImapSite() throws Exception + { + UserModel collaboratorUser = dataUser.createRandomTestUser(); + dataUser.usingUser(testUser).addUserToSite(collaboratorUser, imapSite, UserRole.SiteCollaborator); + FolderModel folderToCreate = FolderModel.getRandomFolderModel(); + + imapProtocol.authenticateUser(collaboratorUser) + .usingSite(imapSite).createFolder(folderToCreate) + .assertThat().existsInImap() + .assertThat().existsInRepo(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify contributor can create a folder in IMAP Site > documentLibrary") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }) + public void contributorCanCreateFolderInImapSite() throws Exception + { + UserModel contributorUser = dataUser.createRandomTestUser(); + dataUser.usingUser(testUser).addUserToSite(contributorUser, imapSite, UserRole.SiteCollaborator); + FolderModel folderToCreate = FolderModel.getRandomFolderModel(); + + imapProtocol.authenticateUser(contributorUser) + .usingSite(imapSite).createFolder(folderToCreate) + .assertThat().existsInImap() + .assertThat().existsInRepo(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify consumer cannot create a folder in IMAP Site > documentLibrary") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.FULL }) + public void consumerCannotCreateFolderInImapSite() throws Exception + { + UserModel consumerUser = dataUser.createRandomTestUser(); + dataUser.usingUser(testUser).addUserToSite(consumerUser, imapSite, UserRole.SiteConsumer); + dataSite.usingUser(consumerUser).usingSite(imapSite).setIMAPFavorite(); + FolderModel folderToCreate = FolderModel.getRandomFolderModel(); + + imapProtocol.authenticateUser(consumerUser).usingSite(imapSite).createFolder(folderToCreate) + .and() + .assertThat().doesNotExistInRepo() + .then().usingSite(imapSite) + .assertThat().doesNotContain(folderToCreate); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify user can create folder successfully with name that contains special characters") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.FULL }) + public void userCanCreateFolderWithSpecialCharacters() throws Exception + { + testSite = dataSite.usingUser(testUser).createIMAPSite(); + FolderModel folderToCreate = new FolderModel("(a)[b]!#%^"); + + imapProtocol.authenticateUser(testUser).usingSite(testSite).createFolder(folderToCreate) + .then() + .assertThat().existsInImap() + .assertThat().existsInRepo(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify user can create folder successfully with name that contains symbols") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.FULL }) + public void userCanCreateFolderWithSymbols() throws Exception + { + testSite = dataSite.usingUser(testUser).createIMAPSite(); + FolderModel folderToCreate = new FolderModel("a£¥€$♊♎ ♏ ♐ ♑ ♒ ♓"); + + imapProtocol.authenticateUser(testUser).usingSite(testSite).createFolder(folderToCreate) + .then() + .assertThat().existsInImap() + .assertThat().existsInRepo(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify user cannot create folder with name omegaΩ_<>./?") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.FULL }) + public void userCannotCreateFolderWithNameThatContainsRestrictedCharacters() throws Exception + { + testSite = dataSite.usingUser(testUser).createIMAPSite(); + FolderModel folderToCreate = new FolderModel("omegaΩ_<>./?"); + + imapProtocol.authenticateUser(testUser).usingSite(testSite).createFolder(folderToCreate) + .and() + .assertThat().doesNotExistInRepo() + .then().usingSite(testSite) + .assertThat().doesNotContain(folderToCreate); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify create folder using an user and check folder can be view by another user with access to the same location/site") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.FULL }) + public void verifyUserCanViewTheFolderCreatedByAnotherUser() throws Exception + { + testSite = dataSite.usingUser(testUser).createIMAPSite(); + UserModel collaboratorUser = dataUser.createRandomTestUser(); + dataUser.addUserToSite(collaboratorUser, testSite, UserRole.SiteCollaborator); + FolderModel folderToCreate = FolderModel.getRandomFolderModel(); + + imapProtocol.authenticateUser(collaboratorUser).usingSite(testSite).createFolder(folderToCreate).disconnect(); + imapProtocol.authenticateUser(testUser).usingSite(testSite).usingResource(folderToCreate) + .assertThat().existsInImap() + .assertThat().existsInRepo(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify error is returned for unauthenticated user on creating folder") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.FULL }, expectedExceptions = IllegalStateException.class, + expectedExceptionsMessageRegExp = "Not connected") + public void verifyErrorIsReturnedForUnauthenticatedUserTryingToCreateFolder() throws Exception + { + imapProtocol.authenticateUser(testUser).usingSite(imapSite).disconnect().then().createFolder(FolderModel.getRandomFolderModel()); + } +} diff --git a/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapDeleteFolderTests.java b/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapDeleteFolderTests.java new file mode 100644 index 0000000000..9f37177931 --- /dev/null +++ b/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapDeleteFolderTests.java @@ -0,0 +1,259 @@ +package org.alfresco.email.imap; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.email.EmailTest; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.model.*; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import javax.mail.FolderNotFoundException; + +public class ImapDeleteFolderTests extends EmailTest +{ + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + testUser = dataUser.createRandomTestUser(); + adminSite = dataSite.usingAdmin().createIMAPSite(); + testSite = dataSite.usingUser(testUser).createIMAPSite(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.SANITY, + description = "Verify admin can delete folder") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.SANITY }) + public void adminShouldDeleteFolder() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + imapProtocol.authenticateUser(adminUser).usingSite(adminSite).createFolder(testFolder) + .assertThat().existsInRepo() + .assertThat().existsInImap() + .delete() + .assertThat().doesNotExistInRepo() + .usingSite(adminSite).assertThat().doesNotContain(testFolder); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.SANITY, + description = "Verify site Manager can delete a folder with a message(file)") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.SANITY }) + public void siteManagerShouldDeleteNonEmptyFolder() throws Exception + { + UserModel user = dataUser.createRandomTestUser(); + SiteModel site = dataSite.usingUser(user).createIMAPSite(); + FolderModel folder = FolderModel.getRandomFolderModel(); + imapProtocol.authenticateUser(user).usingSite(site).createFolder(folder) + .assertThat().existsInImap() + .assertThat().existsInRepo(); + dataContent.usingUser(user).usingSite(site).usingResource(folder).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + imapProtocol.usingSite(site).usingResource(folder).assertThat().countMessagesIs(1) + .delete() + .assertThat().doesNotExistInRepo() + .usingSite(site).assertThat().doesNotContain(folder); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify that site manager can delete a empty folder") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }) + public void siteManagerShouldDeleteFolder() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + imapProtocol.authenticateUser(testUser).usingSite(testSite).createFolder(testFolder) + .assertThat().existsInRepo() + .assertThat().existsInImap() + .delete() + .assertThat().doesNotExistInRepo() + .usingSite(testSite).assertThat().doesNotContain(testFolder); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify that site manager can delete a folder that contains collaborator user messages") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }, enabled = false)//disable since it's failing intermitent + public void siteManagerShouldDeleteFolderWithCollaboratorMessages() throws Exception + { + UserModel collaboratorUser = dataUser.createRandomTestUser(); + dataUser.usingUser(testUser).addUserToSite(collaboratorUser, testSite, UserRole.SiteCollaborator); + testFolder = FolderModel.getRandomFolderModel(); + imapProtocol.authenticateUser(testUser).usingSite(testSite).createFolder(testFolder) + .assertThat().existsInImap() + .assertThat().existsInRepo(); + testFile = dataContent.usingUser(collaboratorUser).usingResource(testFolder).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + imapProtocol.usingSite(testSite).usingResource(testFolder) + .assertThat().countMessagesIs(1) + .delete() + .assertThat().doesNotExistInRepo() + .usingSite(testSite).assertThat().doesNotContain(testFolder); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify that site manager can delete a folder that contains contributor user messages") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }, enabled = false)//disable since it's failing intermitent + public void siteManagerShouldDeleteFolderWithContributorMessages() throws Exception + { + UserModel contributorUser = dataUser.createRandomTestUser(); + dataUser.usingUser(testUser).addUserToSite(contributorUser, testSite, UserRole.SiteContributor); + testFolder = FolderModel.getRandomFolderModel(); + imapProtocol.authenticateUser(testUser).usingSite(testSite).createFolder(testFolder) + .assertThat().existsInImap() + .assertThat().existsInRepo(); + dataContent.usingUser(contributorUser).usingSite(testSite).usingResource(testFolder).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + imapProtocol.usingSite(testSite).usingResource(testFolder).assertThat().countMessagesIs(1) + .delete() + .assertThat().doesNotExistInRepo() + .usingSite(testSite).assertThat().doesNotContain(testFolder); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify that an unauthorized user can not delete folder") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }, expectedExceptions = FolderNotFoundException.class) + public void unauthorizedUserShouldNotDeleteFolder() throws Exception + { + UserModel unauthorizedUser = dataUser.createRandomTestUser(); + testFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + imapProtocol.authenticateUser(unauthorizedUser).usingResource(testFolder).delete(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify that site manager can delete a folder that contains consumer user messages") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.FULL }) + public void siteManagerShouldDeleteFolderWithConsumerMessages() throws Exception + { + UserModel consumerUser = dataUser.createRandomTestUser(); + dataUser.usingUser(testUser).addUserToSite(consumerUser, testSite, UserRole.SiteContributor); + testFolder = FolderModel.getRandomFolderModel(); + imapProtocol.authenticateUser(testUser).usingSite(testSite).createFolder(testFolder) + .assertThat().existsInImap() + .assertThat().existsInRepo(); + dataContent.usingUser(consumerUser).usingSite(testSite).usingResource(testFolder).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + dataUser.usingUser(testUser).removeUserFromSite(consumerUser, testSite); + dataUser.usingUser(testUser).addUserToSite(consumerUser, testSite, UserRole.SiteConsumer); + imapProtocol.authenticateUser(testUser).usingSite(testSite).usingResource(testFolder).assertThat().countMessagesIs(1) + .delete() + .assertThat().doesNotExistInRepo() + .usingSite(testSite).assertThat().doesNotContain(testFolder); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify user cannot delete folder that no longer exists") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.FULL }, expectedExceptions = FolderNotFoundException.class) + public void userCannotDeleteFolderThatNoLongerExists() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + imapProtocol.authenticateUser(testUser).usingSite(testSite).createFolder(testFolder) + .assertThat().existsInImap() + .assertThat().existsInRepo() + .delete() + .assertThat().doesNotExistInRepo() + .usingSite(testSite).assertThat().doesNotContain(testFolder) + .usingResource(testFolder) + .delete(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify deleting folder that contains messages by COLLABORATOR user") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.FULL }) + public void collaboratorTriesToDeleteFolderContainingMessagesByCollaborator() throws Exception + { + UserModel collaboratorUser1 = dataUser.createRandomTestUser(); + UserModel collaboratorUser2 = dataUser.createRandomTestUser(); + dataUser.usingUser(testUser).addUserToSite(collaboratorUser1, testSite, UserRole.SiteCollaborator); + dataUser.usingUser(testUser).addUserToSite(collaboratorUser2, testSite, UserRole.SiteCollaborator); + testFolder = FolderModel.getRandomFolderModel(); + + dataSite.usingUser(collaboratorUser1).usingSite(testSite).setIMAPFavorite(); + imapProtocol.authenticateUser(collaboratorUser1).usingSite(testSite).createFolder(testFolder) + .assertThat().existsInImap() + .assertThat().existsInRepo() + .disconnect(); + testFile = dataContent.usingUser(collaboratorUser1).usingSite(testSite).usingResource(testFolder).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + dataSite.usingUser(collaboratorUser2).usingSite(testSite).setIMAPFavorite(); + imapProtocol.authenticateUser(collaboratorUser2).usingSite(testSite).usingResource(testFolder) + .delete() + .assertThat().existsInRepo() + .usingSite(testSite).assertThat().contains(testFolder); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify deleting folder that contains messages by CONTRIBUTOR user") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.FULL }) + public void contributorTriesToDeleteFolderContainingMessagesByContributor() throws Exception + { + UserModel contributorUser1 = dataUser.createRandomTestUser(); + UserModel contributorUser2 = dataUser.createRandomTestUser(); + dataUser.usingUser(testUser).addUserToSite(contributorUser1, testSite, UserRole.SiteContributor); + dataUser.usingUser(testUser).addUserToSite(contributorUser2, testSite, UserRole.SiteContributor); + testFolder = FolderModel.getRandomFolderModel(); + + dataSite.usingUser(contributorUser1).usingSite(testSite).setIMAPFavorite(); + imapProtocol.authenticateUser(contributorUser1).usingSite(testSite).createFolder(testFolder) + .assertThat().existsInImap() + .assertThat().existsInRepo() + .disconnect(); + testFile = dataContent.usingUser(contributorUser1).usingSite(testSite).usingResource(testFolder).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + dataSite.usingUser(contributorUser2).usingSite(testSite).setIMAPFavorite(); + imapProtocol.authenticateUser(contributorUser2).usingSite(testSite).usingResource(testFolder) + .delete() + .assertThat().existsInRepo() + .usingSite(testSite).assertThat().contains(testFolder); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify deleting folder that contains messages by CONSUMER user") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.FULL }) + public void consumerTriesToDeleteFolderContainingMessagesByConsumer() throws Exception + { + UserModel consumerUser1 = dataUser.createRandomTestUser(); + UserModel consumerUser2 = dataUser.createRandomTestUser(); + dataUser.usingUser(testUser).addUserToSite(consumerUser1, testSite, UserRole.SiteCollaborator); + dataUser.usingUser(testUser).addUserToSite(consumerUser2, testSite, UserRole.SiteConsumer); + testFolder = FolderModel.getRandomFolderModel(); + + dataSite.usingUser(consumerUser1).usingSite(testSite).setIMAPFavorite(); + imapProtocol.authenticateUser(consumerUser1).usingSite(testSite).createFolder(testFolder) + .assertThat().existsInImap() + .assertThat().existsInRepo() + .disconnect(); + testFile = dataContent.usingUser(consumerUser1).usingSite(testSite).usingResource(testFolder).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + dataUser.usingUser(testUser).removeUserFromSite(consumerUser1, testSite); + dataUser.usingUser(testUser).addUserToSite(consumerUser1, testSite, UserRole.SiteConsumer); + dataSite.usingUser(consumerUser2).usingSite(testSite).setIMAPFavorite(); + imapProtocol.authenticateUser(consumerUser2).usingSite(testSite).usingResource(testFolder) + .delete() + .assertThat().existsInRepo() + .usingSite(testSite).assertThat().contains(testFolder); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify delete folder from a location where you don't have permission") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.FULL }, expectedExceptions = FolderNotFoundException.class) + public void userTriesToDeleteFolderFromALocationToWhichHeDoesNotHavePermissionToDelete() throws Exception + { + UserModel userModel = dataUser.createRandomTestUser(); + SiteModel privateSite = dataSite.usingAdmin().createIMAPSite(); + testFolder = FolderModel.getRandomFolderModel(); + + imapProtocol.authenticateUser(dataUser.getAdminUser()).usingSite(privateSite).createFolder(testFolder) + .assertThat().existsInImap() + .assertThat().existsInRepo() + .disconnect(); + + dataSite.usingUser(userModel).usingSite(privateSite).setIMAPFavorite(); + imapProtocol.authenticateUser(userModel).usingSite(testSite).usingResource(testFolder).delete(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify admin cannot delete a open folder") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.FULL }, expectedExceptions = IllegalStateException.class, + expectedExceptionsMessageRegExp = "This operation is not allowed on an open folder") + public void adminTriesToDeleteOpenFolder() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + imapProtocol.authenticateUser(adminUser).usingSite(adminSite).createFolder(testFolder) + .assertThat().existsInRepo() + .assertThat().existsInImap() + .attemptToDeleteOpenFolder(); + } +} diff --git a/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapDeleteMessagesTests.java b/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapDeleteMessagesTests.java new file mode 100644 index 0000000000..fe8c70f873 --- /dev/null +++ b/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapDeleteMessagesTests.java @@ -0,0 +1,95 @@ +package org.alfresco.email.imap; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.email.EmailTest; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.model.*; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import javax.mail.MessagingException; + +public class ImapDeleteMessagesTests extends EmailTest +{ + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + testUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(testUser).createIMAPSite(); + adminSite = dataSite.usingAdmin().createIMAPSite(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.SANITY, + description = "Verify message can be deleted from IMAP client by admin") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.SANITY }) + public void adminShouldDeleteMessage() throws Exception + { + testFile = dataContent.usingAdmin().usingSite(adminSite).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + imapProtocol.authenticateUser(dataUser.getAdminUser()).usingSite(adminSite).assertThat().containsMessages(testFile) + .and().usingResource(testFile).assertThat().existsInRepo().deleteMessage() + .and().assertThat().doesNotContainMessages(testFile) + .then().usingResource(testFile).assertThat().doesNotExistInRepo(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.SANITY, + description = "Verify deleting message via IMAP client by user with MANAGER role") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.SANITY }) + public void siteManagerShouldDeleteMessage() throws Exception + { + testFile = dataContent.usingUser(testUser).usingSite(testSite).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + imapProtocol.authenticateUser(testUser).usingResource(testFile).assertThat().existsInRepo() + .and().usingSite(testSite).assertThat().containsMessages(testFile).deleteMessage(testFile.getName()) + .and().assertThat().doesNotContainMessages(testFile); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify message has been deleted via REPOSITORU by user with MANAGER role") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }) + public void siteManagerVerifyMessageHasBeenDeletedFromRepository() throws Exception + { + testFile = dataContent.usingUser(testUser).usingSite(testSite).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + dataContent.usingUser(testUser).usingResource(testFile).deleteContent(); + imapProtocol.authenticateUser(testUser).usingResource(testFile).assertThat().doesNotExistInRepo() + .and().usingSite(testSite).assertThat().doesNotContainMessages(testFile); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify deleting message via IMAP client by user with CONTRIBUTOR role") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }) + public void siteContributorShouldDeleteMessage() throws Exception + { + UserModel contributorUser = dataUser.createRandomTestUser(); + dataUser.usingUser(testUser).addUserToSite(contributorUser, testSite, UserRole.SiteContributor); + testFile = dataContent.usingUser(contributorUser).usingSite(testSite).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + imapProtocol.authenticateUser(contributorUser).usingResource(testFile).deleteMessage() + .usingResource(testFile).assertThat().doesNotExistInRepo() + .and().usingSite(testSite).assertThat().doesNotContainMessages(testFile); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify deleting message via IMAP client by user with COLLABORATOR role") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }) + public void siteCollaboratorShouldDeleteMessage() throws Exception + { + UserModel collaboratorUser = dataUser.createRandomTestUser(); + dataUser.usingUser(testUser).addUserToSite(collaboratorUser, testSite, UserRole.SiteCollaborator); + testFile = dataContent.usingUser(collaboratorUser).usingSite(testSite).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + imapProtocol.authenticateUser(collaboratorUser).usingResource(testFile).deleteMessage() + .usingResource(testFile).assertThat().doesNotExistInRepo() + .and().usingSite(testSite).assertThat().doesNotContainMessages(testFile); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify deleting message via IMAP client by user with CONSUMER role is not permitted") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }, expectedExceptions = MessagingException.class, + expectedExceptionsMessageRegExp = ".*No permission to set DELETED flag") + public void siteConsumerShouldNotDeleteMessage() throws Exception + { + UserModel consumerUser = dataUser.createRandomTestUser(); + dataUser.usingUser(testUser).addUserToSite(consumerUser, testSite, UserRole.SiteConsumer); + testFile = dataContent.usingUser(testUser).usingSite(testSite).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + imapProtocol.authenticateUser(consumerUser).usingResource(testFile).deleteMessage(); + } +} diff --git a/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapMessageFlagsTests.java b/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapMessageFlagsTests.java new file mode 100644 index 0000000000..1cb777664d --- /dev/null +++ b/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapMessageFlagsTests.java @@ -0,0 +1,58 @@ +package org.alfresco.email.imap; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.email.EmailTest; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.testng.annotations.Test; + +import javax.mail.Flags; + +public class ImapMessageFlagsTests extends EmailTest +{ + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.SANITY, + description = "Verify site manager can set flags action to a content(message) through IMAP Client") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.SANITY }) + public void siteManagerShouldSetFlagsToAContent() throws Exception + { + testUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(testUser).createIMAPSite(); + FileModel fileModel = dataContent.usingUser(testUser).usingSite(testSite).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + imapProtocol.authenticateUser(testUser).usingResource(fileModel).assertThat().existsInRepo() + .and().assertThat().existsInImap() + .and().withMessage().setAnsweredFlag().setSeenFlag().updateFlags() + .then().assertThat().messageContainsFlags(Flags.Flag.ANSWERED, Flags.Flag.SEEN); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager can set flags to a content(message) through IMAP Client") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }) + public void siteManagerShouldSetFlagsToContent() throws Exception + { + testUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(testUser).createIMAPSite(); + FileModel fileModel = dataContent.usingUser(testUser).usingSite(testSite).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + imapProtocol.authenticateUser(testUser).usingResource(fileModel).assertThat().existsInRepo() + .and().assertThat().existsInImap() + .and().withMessage().setFlags(Flags.Flag.ANSWERED, Flags.Flag.SEEN).updateFlags() + .then().assertThat().messageContainsFlags(Flags.Flag.ANSWERED, Flags.Flag.SEEN); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager can remove flags from a content(message) through IMAP Client") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }) + public void siteManagerShouldRemoveFlagsFromContent() throws Exception + { + testUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(testUser).createIMAPSite(); + FileModel fileModel = dataContent.usingUser(testUser).usingSite(testSite).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + imapProtocol.authenticateUser(testUser).usingResource(fileModel).assertThat().existsInRepo() + .and().assertThat().existsInImap() + .and().withMessage().setFlags(Flags.Flag.ANSWERED, Flags.Flag.SEEN).updateFlags() + .and().assertThat().messageContainsFlags(Flags.Flag.ANSWERED, Flags.Flag.SEEN) + .and().withMessage().removeFlags(Flags.Flag.ANSWERED, Flags.Flag.SEEN).updateFlags() + .then().assertThat().messageDoesNotContainFlags(Flags.Flag.ANSWERED, Flags.Flag.SEEN); + } +} diff --git a/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapMoveFolderTests.java b/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapMoveFolderTests.java new file mode 100644 index 0000000000..0d41f149f0 --- /dev/null +++ b/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapMoveFolderTests.java @@ -0,0 +1,146 @@ +package org.alfresco.email.imap; + +import javax.mail.FolderNotFoundException; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.email.EmailTest; +import org.alfresco.utility.constants.UserRole; +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.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class ImapMoveFolderTests extends EmailTest +{ + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + testUser = dataUser.createRandomTestUser(); + adminSite = dataSite.usingAdmin().createIMAPSite(); + testSite = dataSite.usingUser(testUser).createIMAPSite(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.SANITY, + description = "Verify move non-empty folder to a different location by admin user") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.SANITY }) + public void adminShouldMoveNonEmptyFolder() throws Exception + { + testFolder = dataContent.usingAdmin().usingSite(adminSite).createFolder(); + FolderModel moveToFolder = dataContent.usingAdmin().usingSite(adminSite).createFolder(); + dataContent.usingAdmin().usingResource(testFolder).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + imapProtocol.authenticateUser(adminUser).usingSite(adminSite).usingResource(testFolder).moveTo(moveToFolder) + .and().usingResource(testFolder).assertThat().doesNotExistInRepo() + .then().usingResource(moveToFolder).assertThat().contains(testFolder); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.SANITY, + description = "Verify move folder with Manager") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.SANITY }) + public void siteManagerShouldMoveFolder() throws Exception + { + testFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + FolderModel moveToFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + imapProtocol.authenticateUser(testUser).usingSite(testSite).usingResource(testFolder).moveTo(moveToFolder) + .and().usingResource(testFolder).assertThat().doesNotExistInRepo() + .then().usingResource(moveToFolder).assertThat().contains(testFolder); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify move folder at location where the folder already exists is successful") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }) + public void userShouldMoveFolderWhereAlreadyExists() throws Exception + { + testFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + FolderModel moveToFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + dataContent.usingUser(testUser).usingSite(testSite) + .usingResource(moveToFolder) + .createFolder(testFolder); + imapProtocol.authenticateUser(testUser).usingSite(testSite).usingResource(testFolder).moveTo(moveToFolder) + .and().usingResource(testFolder).assertThat().doesNotExistInRepo() + .then().usingResource(moveToFolder).assertThat().existsInRepo(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify move folder with Contributor will create the new folder, but is NOT able to delete the current one") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }) + public void siteContributorCannotMoveFolder() throws Exception + { + UserModel siteContributor = dataUser.createRandomTestUser(); + dataUser.usingUser(testUser).addUserToSite(siteContributor, testSite, UserRole.SiteContributor); + dataSite.usingUser(siteContributor).usingSite(testSite).setIMAPFavorite(); + testFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + FolderModel moveToFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + + imapProtocol.authenticateUser(siteContributor).usingSite(testSite).usingResource(testFolder).moveTo(moveToFolder) + .usingResource(moveToFolder).assertThat().contains(testFolder) + .and().usingResource(testFolder).assertThat().existsInRepo(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify move folder with Collaborator will create the new folder, but is NOT able to delete the current one") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }) + public void siteCollaboratorCannotMoveFolder() throws Exception + { + UserModel siteCollaborator = dataUser.createRandomTestUser(); + dataUser.usingUser(testUser).addUserToSite(siteCollaborator, testSite, UserRole.SiteContributor); + dataSite.usingUser(siteCollaborator).usingSite(testSite).setIMAPFavorite(); + testFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + FolderModel moveToFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + + imapProtocol.authenticateUser(siteCollaborator).usingSite(testSite).usingResource(testFolder).moveTo(moveToFolder) + .usingResource(moveToFolder).assertThat().contains(testFolder) + .and().usingResource(testFolder).assertThat().existsInRepo(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify move folder with Consumer will create the new folder, but is NOT able to delete the current one") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }) + public void siteConsumerCannotMoveFolder() throws Exception + { + UserModel siteConsumer = dataUser.createRandomTestUser(); + dataUser.usingUser(testUser).addUserToSite(siteConsumer, testSite, UserRole.SiteContributor); + dataSite.usingUser(siteConsumer).usingSite(testSite).setIMAPFavorite(); + testFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + FolderModel moveToFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + + imapProtocol.authenticateUser(siteConsumer).usingSite(testSite).usingResource(testFolder).moveTo(moveToFolder) + .usingResource(moveToFolder).assertThat().contains(testFolder) + .and().usingResource(testFolder).assertThat().existsInRepo(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify move folder fails using user that doesn't have permission to the IMAP site") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }, expectedExceptions = FolderNotFoundException.class) + public void unauthorizedUserCannotMoveFolder() throws Exception + { + testFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + FolderModel moveToFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + + UserModel unauthorizedUser = dataUser.createRandomTestUser(); + dataSite.usingUser(unauthorizedUser).usingSite(testSite).setIMAPFavorite(); + + imapProtocol.authenticateUser(unauthorizedUser).usingSite(testSite).usingResource(testFolder).moveTo(moveToFolder) + .usingResource(moveToFolder).assertThat().doesNotContain(testFolder) + .and().usingResource(testFolder).assertThat().existsInRepo(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify move folder with Manager") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.FULL }, expectedExceptions = FolderNotFoundException.class) + public void siteManagerShouldNotMoveDeletedFolder() throws Exception + { + testFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + FolderModel moveToFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + imapProtocol.authenticateUser(testUser).usingSite(testSite).usingResource(testFolder) + .assertThat().existsInImap() + .assertThat().existsInRepo() + .delete() + .moveTo(moveToFolder); + } +} diff --git a/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapMoveMessagesTests.java b/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapMoveMessagesTests.java new file mode 100644 index 0000000000..31ee6b0931 --- /dev/null +++ b/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapMoveMessagesTests.java @@ -0,0 +1,27 @@ +package org.alfresco.email.imap; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.email.EmailTest; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.testng.annotations.Test; + +public class ImapMoveMessagesTests extends EmailTest +{ + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.SANITY, + description = "Verify site manager can move message via IMAP client to a different location") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.SANITY }) + public void siteManagerShouldMoveNonEmptyFile() throws Exception + { + testUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(testUser).createIMAPSite(); + testFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + FileModel fileModel = dataContent.usingSite(testSite).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + imapProtocol.authenticateUser(testUser).usingSite(testSite).usingResource(fileModel).assertThat().existsInRepo() + .and().assertThat().existsInImap() + .then().moveMessageTo(testFolder).assertThat().containsMessages(fileModel) + .and().usingSite(testSite).assertThat().doesNotContainMessages(fileModel); + } +} diff --git a/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapReadMessagesTests.java b/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapReadMessagesTests.java new file mode 100644 index 0000000000..9419f16216 --- /dev/null +++ b/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapReadMessagesTests.java @@ -0,0 +1,180 @@ +package org.alfresco.email.imap; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.email.EmailTest; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.RandomData; +import org.alfresco.utility.model.*; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import javax.mail.Flags; +import javax.mail.MessagingException; +import java.io.IOException; + +public class ImapReadMessagesTests extends EmailTest +{ + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + testUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(testUser).createIMAPSite(); + adminUser = dataUser.getAdminUser(); + adminSite = dataSite.usingAdmin().createIMAPSite(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.SANITY, + description = "Verify folders created in repository in other folder via IMAP client by admin user") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.SANITY }) + public void adminShouldGetFoldersCreatedInRepositoryViaImap() throws Exception + { + testFolder = dataContent.usingAdmin().usingSite(testSite).createFolder(); + FolderModel testFolder1 = FolderModel.getRandomFolderModel(); + FolderModel testFolder2 = FolderModel.getRandomFolderModel(); + imapProtocol.authenticateUser(adminUser).usingSite(adminSite).usingResource(testFolder).createFolder(testFolder1) + .and().assertThat().existsInRepo() + .and().assertThat().existsInImap() + .then().usingResource(testFolder).createFolder(testFolder2).assertThat().existsInRepo() + .and().assertThat().existsInImap(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.SANITY, + description = "Verify file and its content are displayed via IMAP client when the file is created by site manager") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.SANITY }) + public void siteManagerShouldGetFileAndItsContentsViaImap() throws Exception + { + FileModel fileModel = dataContent.usingUser(testUser).usingSite(testSite).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + imapProtocol.authenticateUser(testUser).usingSite(testSite).assertThat().containsMessages(fileModel) + .and().usingResource(fileModel).assertThat().existsInRepo() + .then().assertThat().fileContentIsDisplayed(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.SANITY, + description = "Verify that file content in IMAP client contains creator, title, description, created date, " + + "modifier, modified date, size, three links to content folder, to content url, to download url") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.SANITY }) + public void siteManagerShouldVerifyFileContent() throws Exception + { + FileModel fileModel = dataContent.usingUser(testUser).usingSite(testSite).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + imapProtocol.authenticateUser(testUser).usingSite(testSite).assertThat().containsMessages(fileModel) + .and().usingResource(fileModel).assertThat().existsInRepo() + .then().assertThat().messageContentMatchesFileModelData(fileModel); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify that the admin user can mark a message as read") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }) + public void adminCanMarkMessageAsRead() throws Exception + { + testFile = dataContent.usingUser(adminUser).usingSite(adminSite).createContent(FileModel.getRandomFileModel(FileType.TEXT_PLAIN)); + imapProtocol.authenticateUser(adminUser).usingResource(testFile).withMessage().setSeenFlag().updateFlags() + .then().assertThat().messageContainsFlags(Flags.Flag.SEEN); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify that site manager can see wiki pages via IMAP") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }) + public void siteManagerCanViewWikiPages() throws Exception + { + dataWiki.usingUser(testUser).usingSite(testSite).createRandomWiki(); + imapProtocol.authenticateUser(testUser).usingSiteWikiContainer(testSite).assertThat().countMessagesIs(1); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify that collaborator can see files created by self") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }) + public void collaboratorCanViewFileCreatedBySelf() throws Exception + { + UserModel collaboratorUser = dataUser.createRandomTestUser(); + dataUser.addUserToSite(collaboratorUser, testSite, UserRole.SiteCollaborator); + testFile = dataContent.usingUser(collaboratorUser).usingSite(testSite).createContent(FileModel.getRandomFileModel(FileType.TEXT_PLAIN)); + imapProtocol.authenticateUser(collaboratorUser).usingSite(testSite).assertThat().containsMessages(testFile); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify that contributor can see files created by self") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }) + public void contributorCanViewFileCreatedBySelf() throws Exception + { + UserModel contributorUser = dataUser.createRandomTestUser(); + dataUser.addUserToSite(contributorUser, testSite, UserRole.SiteContributor); + testFile = dataContent.usingUser(contributorUser).usingSite(testSite).createContent(FileModel.getRandomFileModel(FileType.TEXT_PLAIN)); + imapProtocol.authenticateUser(contributorUser).usingSite(testSite).assertThat().containsMessages(testFile); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify file created with spaces in the name is displayed in IMAP client") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }) + public void fileWithSpacesInNameIsDisplayedInImap() throws Exception + { + testFile = dataContent.usingUser(testUser).usingSite(testSite).createContent(new FileModel("name with spaces.txt", FileType.TEXT_PLAIN)); + imapProtocol.authenticateUser(testUser).usingSite(testSite).assertThat().containsMessages(testFile); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify that a file created with name which contains special characters is visible in IMAP") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.FULL }) + public void userCanViewFileWithSpecialCharactersInNameViaIMAP() throws Exception + { + testFile = dataContent.usingUser(testUser).usingSite(testSite).createContent(new FileModel("(a)[b]!#%^.txt", FileType.TEXT_PLAIN)); + imapProtocol.authenticateUser(testUser) + .usingSite(testSite).assertThat().containsMessages(testFile) + .usingResource(testFile).assertThat().existsInRepo(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify that a file created with name which contains symbols is visible in IMAP") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.FULL }) + public void userCanViewFileWithSymbolsInNameViaIMAP() throws Exception + { + testFile = dataContent.usingUser(testUser).usingSite(testSite).createContent(new FileModel("a£¥€$♊♎♏♐♑♒♓Ω.txt", FileType.TEXT_PLAIN)); + imapProtocol.authenticateUser(testUser) + .usingSite(testSite).assertThat().containsMessages(testFile) + .usingResource(testFile).assertThat().existsInRepo(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify that site manager can see links via IMAP") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.FULL }) + public void siteManagerCanViewLinks() throws Exception + { + dataLink.usingUser(testUser).usingSite(testSite).createRandomLink(); + imapProtocol.authenticateUser(testUser).usingSiteLinksContainer(testSite).assertThat().countMessagesIs(1); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify that site manager can see calendar events via IMAP") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.FULL }) + public void siteManagerCanViewCalendarEvents() throws Exception + { + dataCalendarEvent.usingUser(testUser).usingSite(testSite).createRandomCalendarEvent(); + imapProtocol.authenticateUser(testUser).usingSiteCalendarContainer(testSite).assertThat().countMessagesIs(1); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify that site manager cannot read file via IMAP if it is already deleted from repository") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.FULL }, expectedExceptions = MessagingException.class, + expectedExceptionsMessageRegExp = "No message with subject .* has been found") + public void siteManagerCannotReadFileInImapIfItWasDeletedFromRepository() throws Exception + { + testFile = dataContent.usingUser(testUser).usingSite(testSite) + .createContent(new FileModel(RandomData.getRandomName("File"), FileType.TEXT_PLAIN)); + dataContent.usingUser(testUser).usingSite(testSite).usingResource(testFile).deleteContent(); + imapProtocol.authenticateUser(testUser).usingSite(testSite).usingResource(testFile).assertThat().fileContentIsDisplayed(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify that site manager cannot read file via IMAP client if it is locked by an user in repository") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.FULL }, expectedExceptions = IOException.class, + expectedExceptionsMessageRegExp = "No content") + public void siteManagerCannotReadFileInImapIfItsLocked() throws Exception + { + String content = RandomData.getRandomAlphanumeric(); + testFile = dataContent.usingUser(testUser).usingSite(testSite) + .createContent(new FileModel(RandomData.getRandomName("File"), FileType.TEXT_PLAIN, content)); + dataContent.usingUser(testUser).usingSite(testSite).usingResource(testFile).checkOutDocument(); + imapProtocol.authenticateUser(testUser).usingSite(testSite).usingResource(testFile).assertThat().fileContentIsDisplayed(); + } +} diff --git a/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapRenameFolderTests.java b/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapRenameFolderTests.java new file mode 100644 index 0000000000..c7f3471c08 --- /dev/null +++ b/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapRenameFolderTests.java @@ -0,0 +1,361 @@ +package org.alfresco.email.imap; + +import javax.mail.FolderNotFoundException; + +import org.alfresco.email.EmailTest; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.RandomData; +import org.alfresco.utility.exception.TestConfigurationException; +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.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.commons.lang3.RandomStringUtils; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class ImapRenameFolderTests extends EmailTest +{ + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + testUser = dataUser.createRandomTestUser(); + adminSite = dataSite.usingAdmin().createIMAPSite(); + testSite = dataSite.usingUser(testUser).createIMAPSite(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.SANITY, + description = "Verify rename folder by admin user") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.SANITY }) + public void adminShouldRenameFolder() throws Exception + { + testFolder = dataContent.usingAdmin().usingSite(adminSite).createFolder(); + String newFolderName = RandomData.getRandomName("Folder"); + imapProtocol.authenticateUser(adminUser).usingSite(adminSite).usingResource(testFolder).rename(newFolderName) + .usingSite(adminSite) + .assertThat().contains(new FolderModel(newFolderName)) + .assertThat().doesNotContain(testFolder); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.SANITY, + description = "Verify renaming folder by user with MANAGER role") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.SANITY }) + public void siteManagerShouldRenameFolder() throws Exception + { + testFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + String newFolderName = RandomData.getRandomName("Folder"); + imapProtocol.authenticateUser(testUser).usingSite(testSite).usingResource(testFolder).rename(newFolderName) + .usingSite(testSite) + .assertThat().contains(new FolderModel(newFolderName)) + .assertThat().doesNotContain(testFolder); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify user with MANAGER role is not able to rename an nonexistent folder") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }, expectedExceptions = FolderNotFoundException.class) + public void siteManagerShouldNotRenameNonExistentFolder() throws Exception + { + String newFolderName = RandomData.getRandomName("Folder"); + + imapProtocol.authenticateUser(testUser).usingSite(testSite).usingResource(FolderModel.getRandomFolderModel()) + .rename(newFolderName) + .assertThat().contains(testFolder) + .and().assertThat().doesNotContain(new FolderModel(newFolderName)); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify user with MANAGER role is able to rename a folder with long name") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }) + public void siteManagerShouldRenameFolderWithLongName() throws Exception + { + testFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + String longName = RandomStringUtils.randomAlphabetic(200); + + imapProtocol.authenticateUser(testUser).usingSite(testSite).usingResource(testFolder) + .rename(longName) + .usingSite(testSite) + .assertThat().contains(new FolderModel(longName)) + .assertThat().doesNotContain(testFolder); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify unauthorized user is not able to rename a folder") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.FULL }, expectedExceptions = FolderNotFoundException.class) + public void unauthorizedUserShouldNotRenameFolder() throws Exception + { + UserModel unauthorizedUser = dataUser.createRandomTestUser(); + testFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + + dataSite.usingUser(unauthorizedUser).usingSite(testSite).setIMAPFavorite(); + + String newFolderName = RandomData.getRandomName("Folder"); + imapProtocol.authenticateUser(unauthorizedUser).usingResource(testFolder) + .rename(newFolderName) + .then().assertThat().doesNotExistInRepo() + .assertThat().contains(testFolder) + .and().assertThat().doesNotContain(new FolderModel(newFolderName)); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify inexistent user is not able to rename a folder") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }, expectedExceptions = TestConfigurationException.class, + expectedExceptionsMessageRegExp = ".*You missed some configuration settings in your tests: User failed to connect to IMAP server LOGIN failed. Invalid login/password$") + public void nonexistentUserShouldNotRenameFolder() throws Exception + { + testFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + String newFolderName = RandomData.getRandomName("Folder"); + + imapProtocol.authenticateUser(UserModel.getRandomUserModel()).usingResource(testFolder) + .rename(newFolderName) + .then().assertThat().doesNotExistInRepo() + .and().assertThat().contains(testFolder) + .and().assertThat().doesNotContain(new FolderModel(newFolderName)); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify disconnected user is not able to rename a folder") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }, expectedExceptions = IllegalStateException.class, + expectedExceptionsMessageRegExp= "Not connected") + public void disconnectedUserShouldNotRenameFolder() throws Exception + { + testFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + String newFolderName = RandomData.getRandomName("Folder"); + + imapProtocol.authenticateUser(testUser).usingResource(testFolder).assertThat().existsInImap().then() + .disconnect().usingResource(testFolder) + .rename(newFolderName) + .then().assertThat().doesNotExistInRepo() + .and().assertThat().contains(testFolder) + .and().assertThat().doesNotContain(new FolderModel(newFolderName)); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify renaming folder by user with COLLABORATOR role - folder created by self") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }) + public void collaboratorShouldRenameFolderCreatedBySelf() throws Exception + { + UserModel collaboratorUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(testUser).addUserToSite(collaboratorUser, testSite, UserRole.SiteCollaborator); + + dataSite.usingUser(collaboratorUser).usingSite(testSite).setIMAPFavorite(); + + testFolder = dataContent.usingUser(collaboratorUser).usingSite(testSite).createFolder(); + String newFolderName = RandomData.getRandomName("Folder"); + imapProtocol.authenticateUser(collaboratorUser).usingSite(testSite).usingResource(testFolder) + .rename(newFolderName) + .usingSite(testSite) + .assertThat().contains(new FolderModel(newFolderName)) + .assertThat().doesNotContain(testFolder); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify user with COLLABORATOR role is not able to rename a folder created by other user") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }) + public void collaboratorShouldNotRenameFolderCreatedByOtherUser() throws Exception + { + UserModel collaboratorUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(testUser).addUserToSite(collaboratorUser, testSite, UserRole.SiteCollaborator); + + dataSite.usingUser(collaboratorUser).usingSite(testSite).setIMAPFavorite(); + + testFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + String newFolderName = RandomData.getRandomName("Folder"); + imapProtocol.authenticateUser(collaboratorUser).usingResource(testFolder).rename(newFolderName) + .usingSite(testSite) + .assertThat().contains(testFolder) + .assertThat().doesNotContain(new FolderModel(newFolderName)); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify user with CONTRIBUTOR role is able to rename a folder created by self") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }) + public void contributorShouldRenameFolderCreatedBySelf() throws Exception + { + UserModel contributorUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(testUser).addUserToSite(contributorUser, testSite, UserRole.SiteContributor); + + dataSite.usingUser(contributorUser).usingSite(testSite).setIMAPFavorite(); + + testFolder = dataContent.usingUser(contributorUser).usingSite(testSite).createFolder(); + String newFolderName = RandomData.getRandomName("Folder"); + imapProtocol.authenticateUser(contributorUser).usingSite(testSite).usingResource(testFolder) + .rename(newFolderName) + .usingSite(testSite) + .assertThat().contains(new FolderModel(newFolderName)) + .assertThat().doesNotContain(testFolder); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify user with CONTRIBUTOR role is NOT able to rename a folder created by other user") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }) + public void contributorShouldNotRenameFolderCreatedByOtherUser() throws Exception + { + UserModel contributorUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(testUser).addUserToSite(contributorUser, testSite, UserRole.SiteContributor); + + dataSite.usingUser(contributorUser).usingSite(testSite).setIMAPFavorite(); + + FolderModel testFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + String newFolderName = RandomData.getRandomName("Folder"); + imapProtocol.authenticateUser(contributorUser).usingSite(testSite).usingResource(testFolder) + .rename(newFolderName).usingSite(testSite).then().assertThat().contains(testFolder) + .and().assertThat().doesNotContain(new FolderModel(newFolderName)); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify user with CONSUMER role is not able to rename a folder created by other user") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.FULL }) + public void consumerShouldNotRenameFolderCreatedByOtherUser() throws Exception + { + UserModel consumer = dataUser.createRandomTestUser(); + dataUser.usingUser(testUser).addUserToSite(consumer, testSite, UserRole.SiteConsumer); + + dataSite.usingUser(consumer).usingSite(testSite).setIMAPFavorite(); + + FolderModel testFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + String newFolderName = RandomData.getRandomName("Folder"); + imapProtocol.authenticateUser(consumer).usingSite(testSite).usingResource(testFolder) + .rename(newFolderName).usingSite(testSite).then() + .assertThat().contains(testFolder) + .and().assertThat().doesNotContain(new FolderModel(newFolderName)); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify renaming folder fails when it was deleted by another user") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.FULL }, expectedExceptions = FolderNotFoundException.class) + public void userCannotRenameFolderDeletedByAnotherUser() throws Exception + { + UserModel contributorUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(testUser).addUserToSite(contributorUser, testSite, UserRole.SiteContributor); + FolderModel testFolder = FolderModel.getRandomFolderModel(); + + dataSite.usingUser(contributorUser).usingSite(testSite).setIMAPFavorite(); + imapProtocol.authenticateUser(contributorUser).usingSite(testSite).createFolder(testFolder) + .assertThat().existsInRepo() + .assertThat().existsInImap() + .delete().disconnect(); + + imapProtocol.authenticateUser(testUser).usingSite(testSite).usingResource(testFolder).rename("deletedFolderRename"); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify user can rename folder to a name that contains white spaces") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.FULL }) + public void userCanRenameFolderToAFolderThatContainsWhiteSpaces() throws Exception + { + FolderModel testFolder = FolderModel.getRandomFolderModel(); + + imapProtocol.authenticateUser(testUser).usingSite(testSite).createFolder(testFolder) + .and() + .assertThat().existsInRepo() + .assertThat().existsInImap() + .rename("folder with name that contains spaces") + .then().usingSite(testSite) + .assertThat().contains(new FolderModel("folder with name that contains spaces")) + .assertThat().doesNotContain(testFolder); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify user can rename folder successfully with name that contains special characters") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.FULL }) + public void userCanRenameFolderWithSpecialCharacters() throws Exception + { + FolderModel testFolder = FolderModel.getRandomFolderModel(); + + imapProtocol.authenticateUser(testUser).usingSite(testSite).createFolder(testFolder) + .and() + .assertThat().existsInRepo() + .assertThat().existsInImap() + .rename("(a)[b]!#%^") + .then().usingSite(testSite) + .assertThat().contains(new FolderModel("(a)[b]!#%^")) + .assertThat().doesNotContain(testFolder); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify user can rename folder successfully with name that contains symbols") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.FULL }) + public void userCanRenameFolderWithSymbols() throws Exception + { + FolderModel testFolder = FolderModel.getRandomFolderModel(); + + imapProtocol.authenticateUser(testUser).usingSite(testSite).createFolder(testFolder) + .and() + .assertThat().existsInRepo() + .assertThat().existsInImap() + .rename("a£¥€$♊♎ ♏ ♐ ♑ ♒ ♓") + .then().usingSite(testSite) + .assertThat().contains(new FolderModel("a£¥€$♊♎ ♏ ♐ ♑ ♒ ♓")) + .assertThat().doesNotContain(testFolder); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify user cannot create folder with name omegaΩ_<>./?") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.FULL }) + public void userCannotRenameFolderWithNameThatContainsRestrictedCharacters() throws Exception + { + FolderModel testFolder = FolderModel.getRandomFolderModel(); + + imapProtocol.authenticateUser(testUser).usingSite(testSite).createFolder(testFolder) + .and() + .assertThat().existsInRepo() + .assertThat().existsInImap() + .rename("omegaΩ_<>./?") + .then().usingSite(testSite) + .assertThat().contains(testFolder) + .assertThat().doesNotContain(new FolderModel("omegaΩ_<>./?")); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify renaming folder fails when it was renamed by another user") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.FULL }, expectedExceptions = FolderNotFoundException.class) + public void userCannotRenameFolderRenamedByAnotherUser() throws Exception + { + UserModel contributorUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(testUser).addUserToSite(contributorUser, testSite, UserRole.SiteContributor); + FolderModel testFolder = FolderModel.getRandomFolderModel(); + + dataSite.usingUser(contributorUser).usingSite(testSite).setIMAPFavorite(); + imapProtocol.authenticateUser(contributorUser).usingSite(testSite).createFolder(testFolder) + .assertThat().existsInRepo() + .assertThat().existsInImap() + .rename("folderRenamedByUser").disconnect(); + + imapProtocol.authenticateUser(testUser).usingSite(testSite).usingResource(testFolder).rename("deletedFolderRename"); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify a site folder cannot be renamed via IMAP client") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.FULL }) + public void verifyASiteFolderCannotBeRenamedViaImap() throws Exception + { + SiteModel siteModel = dataSite.usingUser(testUser).createIMAPSite(); + + imapProtocol.authenticateUser(testUser).usingSiteRoot(siteModel).rename("new site name") + .and() + .assertThat().doesNotExistInRepo() + .then().usingSites() + .assertThat().doesNotContain(new FolderModel("new site name")); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify renaming folder by changing the case") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.FULL }) + public void verifyFolderCanBeRenamedByChangingTheCase() throws Exception + { + FolderModel testFolder = FolderModel.getRandomFolderModel(); + + imapProtocol.authenticateUser(testUser).usingSite(testSite).createFolder(testFolder) + .and() + .assertThat().existsInRepo() + .assertThat().existsInImap() + .rename(testFolder.getName().toUpperCase()) + .then().usingSite(testSite) + .assertThat().contains(new FolderModel(testFolder.getName().toUpperCase())) + .assertThat().doesNotContain(testFolder); + } +} diff --git a/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapRenameMessagesTests.java b/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapRenameMessagesTests.java new file mode 100644 index 0000000000..55e3384f1f --- /dev/null +++ b/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapRenameMessagesTests.java @@ -0,0 +1,34 @@ +package org.alfresco.email.imap; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.email.EmailTest; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class ImapRenameMessagesTests extends EmailTest +{ + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + testUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(testUser).createIMAPSite(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.SANITY, + description = "Verify the renamed file from repository is still preset in IMAP client with the old name for site manager") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.SANITY }) + public void siteManagerShouldVerifyFileContentForRenamedFileViaImap() throws Exception + { + testFile = dataContent.usingUser(testUser).usingSite(testSite).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + FileModel renamedFile = testFile; + renamedFile.setName(FileModel.getRandomFileModel(FileType.TEXT_PLAIN).getName()); + imapProtocol.authenticateUser(testUser).usingSite(testSite).usingResource(testFile).assertThat().existsInRepo() + .and().assertThat().existsInImap() + .then().renameMessageTo(renamedFile).assertThat().messageContentMatchesFileModelData(testFile); + } +} diff --git a/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapSearchMessagesTests.java b/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapSearchMessagesTests.java new file mode 100644 index 0000000000..dd74390949 --- /dev/null +++ b/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapSearchMessagesTests.java @@ -0,0 +1,118 @@ +package org.alfresco.email.imap; + +import org.alfresco.email.EmailTest; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.testng.annotations.Test; + +/** + * Tests for Search for Messages in IMAP client + * + * @author Cristina Axinte + * + */ +public class ImapSearchMessagesTests extends EmailTest +{ + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.SANITY, + description = "Verify that no results are returned when searching for a message name term with no match") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.SANITY }) + public void noResultsReturnedWhenSearchingForNotExistingMessage() throws Exception + { + testUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(testUser).createIMAPSite(); + testFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + String fileName1="File-new1"; + FileModel fileModel1 = dataContent.usingUser(testUser).usingSite(testSite).usingResource(testFolder) + .createContent(new FileModel(fileName1, fileName1, fileName1 + "description", FileType.TEXT_PLAIN, fileName1 + "content")); + String fileName2="File2"; + FileModel fileModel2 = dataContent.usingUser(testUser).usingSite(testSite).usingResource(testFolder) + .createContent(new FileModel(fileName2, fileName2, fileName2 + "description", FileType.TEXT_PLAIN, fileName2 + "content")); + + imapProtocol.authenticateUser(testUser).usingSite(testSite).usingResource(testFolder) + .searchSubjectFor("new").assertThat().resultsContainMessage(fileModel1) + .assertThat().resultsDoNotContainMessage(fileModel2); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.SANITY, + description = "Verify that searched message is returned when searching for full message name") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.SANITY }) + public void searchedMessageIsReturnedWhenSearchingForFullMessageName() throws Exception + { + testUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(testUser).createIMAPSite(); + testFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + String fileName1="File-new1"; + FileModel fileModel1 = dataContent.usingUser(testUser).usingSite(testSite).usingResource(testFolder) + .createContent(new FileModel(fileName1, fileName1, fileName1 + "description", FileType.TEXT_PLAIN, fileName1 + "content")); + String fileName2="File2"; + FileModel fileModel2 = dataContent.usingUser(testUser).usingSite(testSite).usingResource(testFolder) + .createContent(new FileModel(fileName2, fileName2, fileName2 + "description", FileType.TEXT_PLAIN, fileName2 + "content")); + + imapProtocol.authenticateUser(testUser).usingSite(testSite).usingResource(testFolder) + .searchSubjectFor("File2").assertThat().resultsContainMessage(fileModel2) + .assertThat().resultsDoNotContainMessage(fileModel1); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify that search results are returned for search term containing white spaces") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }) + public void siteManagerVerifySearchResultsForWhiteSpaces() throws Exception + { + testUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(testUser).createIMAPSite(); + String fileName1="File new"; + FileModel fileModel1 = dataContent.usingUser(testUser).usingSite(testSite) + .createContent(new FileModel(fileName1, fileName1, fileName1 + "description", FileType.TEXT_PLAIN, fileName1 + "content")); + String fileName2="File new1"; + FileModel fileModel2 = dataContent.usingSite(testSite) + .createContent(new FileModel(fileName2, fileName2, fileName2 + "description", FileType.TEXT_PLAIN, fileName2 + "content")); + + imapProtocol.authenticateUser(testUser).usingSite(testSite).searchSubjectFor("File new") + .assertThat().resultsContainMessage(fileModel1, fileModel2); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify that search results are returned for search term containing wildcards") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }) + public void siteManagerVerifySearchResultsForWildcards() throws Exception + { + testUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(testUser).createIMAPSite(); + String fileName1="File new 1"; + FileModel fileModel1 = dataContent.usingUser(testUser).usingSite(testSite) + .createContent(new FileModel(fileName1, fileName1, fileName1 + "description", FileType.TEXT_PLAIN, fileName1 + "content")); + String fileName2="File presentation 2"; + FileModel fileModel2 = dataContent.usingSite(testSite) + .createContent(new FileModel(fileName2, fileName2, fileName2 + "description", FileType.TEXT_PLAIN, fileName2 + "content")); + + imapProtocol.authenticateUser(testUser).usingSite(testSite).searchSubjectWithWildcardsFor("File.*1.*") + .assertThat().resultsContainMessage(fileModel1) + .assertThat().resultsDoNotContainMessage(fileModel2); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify that search results are returned for search term containing special characters") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }) + public void siteManagerVerifySearchResultsForSpecialCharacters() throws Exception + { + testUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(testUser).createIMAPSite(); + String fileName1="File@#$%^&()-_=+-[]{};'"; + FileModel fileModel1 = dataContent.usingUser(testUser).usingSite(testSite) + .createContent(new FileModel(fileName1, fileName1, fileName1 + "description", FileType.TEXT_PLAIN, fileName1 + "content")); + String fileName2="File"; + FileModel fileModel2 = dataContent.usingSite(testSite) + .createContent(new FileModel(fileName2, fileName2, fileName2 + "description", FileType.TEXT_PLAIN, fileName2 + "content")); + + imapProtocol.authenticateUser(testUser).usingSite(testSite) + .searchSubjectFor("=").assertThat().resultsContainMessage(fileModel1).assertThat().resultsDoNotContainMessage(fileModel2) + .searchSubjectFor("@").assertThat().resultsContainMessage(fileModel1).assertThat().resultsDoNotContainMessage(fileModel2) + .searchSubjectFor("#").assertThat().resultsContainMessage(fileModel1).assertThat().resultsDoNotContainMessage(fileModel2) + .searchSubjectFor("$").assertThat().resultsContainMessage(fileModel1).assertThat().resultsDoNotContainMessage(fileModel2) + .searchSubjectFor("@#").assertThat().resultsContainMessage(fileModel1).assertThat().resultsDoNotContainMessage(fileModel2) + .searchSubjectFor("[]").assertThat().resultsContainMessage(fileModel1).assertThat().resultsDoNotContainMessage(fileModel2); + } +} diff --git a/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapSitesTests.java b/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapSitesTests.java new file mode 100644 index 0000000000..6522185eab --- /dev/null +++ b/tests/tas-email/src/test/java/org/alfresco/email/imap/ImapSitesTests.java @@ -0,0 +1,81 @@ +package org.alfresco.email.imap; + +import org.alfresco.email.EmailTest; +import org.alfresco.utility.model.FolderModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import javax.mail.FolderNotFoundException; +import javax.mail.MessagingException; + +public class ImapSitesTests extends EmailTest +{ + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + testUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(testUser).createIMAPSite(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify that site manager can unsubscribe from a folder") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }) + public void siteManagerCanUnSubscribeFromAFolder() throws Exception + { + testFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + imapProtocol.authenticateUser(testUser).usingSite(testSite).assertThat().isSubscribed() + .usingResource(testFolder).assertThat().isSubscribed() + .unsubscribe().assertThat().isNotSubscribed() + .usingSite(testSite).assertThat().isSubscribed(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify that site manager is subscribed to folders created by self") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }) + public void siteManagerIsSubscribedToFoldersCreatedBySelf() throws Exception + { + testFolder = new FolderModel("newFolder"); + imapProtocol.authenticateUser(testUser).usingSite(testSite).assertThat().isSubscribed() + .createFolder(testFolder).assertThat().existsInRepo().assertThat().existsInImap() + .assertThat().isSubscribed(); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify that operations on a private site are not permitted") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }, expectedExceptions = MessagingException.class, + expectedExceptionsMessageRegExp = ".* Access Denied.*You do not have the appropriate permissions to perform this operation.*") + public void verifyOperationsOnPrivateSiteAreNotPermitted() throws Exception + { + adminUser = dataUser.getAdminUser(); + adminSite = dataSite.usingAdmin().createPrivateRandomSite(); + testFolder = dataContent.usingAdmin().usingSite(adminSite).createFolder(); + dataSite.usingUser(testUser).usingSite(testSite).setIMAPFavorite(); + imapProtocol.authenticateUser(testUser).usingSite(adminSite).assertThat().contains(testFolder); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify that operations on a moderated site are not permitted") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.CORE }, expectedExceptions = FolderNotFoundException.class) + public void verifyOperationsOnModeratedSiteAreNotPermitted() throws Exception + { + adminUser = dataUser.getAdminUser(); + adminSite = dataSite.usingAdmin().createModeratedRandomSite(); + testFolder = dataContent.usingAdmin().usingSite(adminSite).createFolder(); + dataSite.usingUser(testUser).usingSite(testSite).setIMAPFavorite(); + imapProtocol.authenticateUser(testUser).usingSite(adminSite).assertThat().contains(testFolder); + } + + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.IMAP }, executionType = ExecutionType.REGRESSION, + description = "Verify site cannot be accessed in IMAP client if it is no longer an IMAP site or marked as IMAP favorite") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.IMAP, TestGroup.FULL }, expectedExceptions = FolderNotFoundException.class) + public void userCannotAccessSiteThatIsNoLongerAnImapSiteOrMarkedAsImapFavorite() throws Exception + { + testFolder = dataContent.usingUser(testUser).usingSite(testSite).createFolder(); + imapProtocol.authenticateUser(testUser).usingSite(testSite).assertThat().contains(testFolder); + dataSite.usingUser(testUser).usingSite(testSite).unsetIMAPFavorite(); + imapProtocol.authenticateUser(testUser).usingSite(testSite).assertThat().contains(testFolder); + } +} diff --git a/tests/tas-email/src/test/resources/alfresco-email-context.xml b/tests/tas-email/src/test/resources/alfresco-email-context.xml new file mode 100644 index 0000000000..d6a5817e9c --- /dev/null +++ b/tests/tas-email/src/test/resources/alfresco-email-context.xml @@ -0,0 +1,14 @@ + + + + + + + + + \ No newline at end of file diff --git a/tests/tas-email/src/test/resources/default.properties b/tests/tas-email/src/test/resources/default.properties new file mode 100644 index 0000000000..6dd13d4b3d --- /dev/null +++ b/tests/tas-email/src/test/resources/default.properties @@ -0,0 +1,97 @@ +# dataprep related +alfresco.scheme=http +alfresco.server=localhost +alfresco.port=8082 + +# credentials +admin.user=admin +admin.password=admin + +# in containers we cannot access directly JMX, so we will use http://jolokia.org agent +# disabling this we will use direct JMX calls to server +jmx.useJolokiaAgent=false + +# Server Health section +# in ServerHealth#isServerReachable() - could also be shown. +# enable this option to view if on server there are tenants or not +serverHealth.showTenants=true + +# IMAP Service settings from admin console +imap.server=${alfresco.server} +imap.port=143 +imaps.port=993 + +# Inbound Email settings from admin console +smtp.server=${alfresco.server} +smtp.port=25 +smtp.authentication.enabled=true +smtp.tsl.enabled=false + +# Outbound Email settings from admin console +mail.encoding=UTF-8 +mail.from.default=alfresco.cloud@gmail.com +mail.from.enabled=true +mail.host=smtp.gmail.com +mail.password=eiWei6vieiWei6vieiWei6vieiWei6vi +mail.port=465 +mail.protocol=smtps +mail.smtp.auth=true +mail.smtp.debug=false +mail.smtp.starttls.enable=true +mail.smtp.timeout=30000 +mail.smtps.auth=true +mail.smtps.starttls.enable=true +mail.username=alfresco.cloud@gmail.com + +# TEST MANAGEMENT SECTION - Test Rail +# +# (currently supporting Test Rail v5.2.1.3472 integration) +# +# Example of configuration: +# ------------------------------------------------------ +# if testManagement.enabled=true we enabled TestRailExecutorListener (if used in your suite xml file) +# testManagement.updateTestExecutionResultsOnly=true (this will just update the results of a test: no step will be updated - good for performance) +# testManagement.endPoint=https://alfresco.testrail.com/ +# testManagement.username= +# testManagement.apiKey= +# testManagement.project= +# testManagement.includeOnlyTestCasesExecuted=true #if you want to include in your run ONLY the test cases that you run, then set this value to false +# testManagement.rateLimitInSeconds=1 #is the default rate limit after what minimum time, should we upload the next request. http://docs.gurock.com/testrail-api2/introduction #Rate Limit +# testManagement.suiteId=23 (the id of the Master suite) +# ------------------------------------------------------ +testManagement.enabled=false +testManagement.endPoint= +testManagement.username= +testManagement.apiKey= +testManagement.project=7 +testManagement.includeOnlyTestCasesExecuted=true +testManagement.rateLimitInSeconds=1 +testManagement.testRun=MyTestRunInTestRail +testManagement.suiteId=12 + +# The location of the reports path +reports.path=./target/reports + +# +# Database Section +# You should provide here the database URL, that can be a differed server as alfresco. +# https://docs.oracle.com/javase/tutorial/jdbc/basics/connecting.html +# +# Current supported db.url: +# +# MySQL: +# db.url = jdbc:mysql://${alfresco.server}:3306/alfresco +# +# PostgreSQL: +# db.url = jdbc:postgresql://:3306/alfresco +# +# Oracle: +# db.url = jdbc:oracle://:3306/alfresco +# +# MariaDB: +# db.url = jdbc:mariadb://:3306/alfresco +# +db.url = jdbc:mysql://${alfresco.server}:3306/alfresco +db.username = alfresco +db.password = alfresco diff --git a/tests/tas-email/src/test/resources/email-suite.xml b/tests/tas-email/src/test/resources/email-suite.xml new file mode 100644 index 0000000000..ecb87f6d2d --- /dev/null +++ b/tests/tas-email/src/test/resources/email-suite.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/tests/tas-email/src/test/resources/log4j.properties b/tests/tas-email/src/test/resources/log4j.properties new file mode 100644 index 0000000000..00e9b5a114 --- /dev/null +++ b/tests/tas-email/src/test/resources/log4j.properties @@ -0,0 +1,26 @@ +# Root logger option +log4j.rootLogger=INFO, file, stdout + +# Direct log messages to a log file +log4j.appender.file=org.apache.log4j.RollingFileAppender +log4j.appender.file.File=./target/reports/alfresco-tas.log +log4j.appender.file.MaxBackupIndex=10 +log4j.appender.file.layout=org.apache.log4j.PatternLayout +log4j.appender.file.layout.ConversionPattern=[%t] %d{HH:mm:ss} %-5p %c{1}:%L - %m%n + +# Direct log messages to stdout +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=[%t] %d{HH:mm:ss} %-5p %c{1}:%L - %m%n + +# TestRail particular log file +# Direct log messages to a log file +log4j.appender.testrailLog=org.apache.log4j.RollingFileAppender +log4j.appender.testrailLog.File=./target/reports/alfresco-testrail.log +log4j.appender.testrailLog.MaxBackupIndex=10 +log4j.appender.testrailLog.layout=org.apache.log4j.PatternLayout +log4j.appender.testrailLog.layout.ConversionPattern=%d{HH:mm:ss} %-5p %c{1}:%L - %m%n + +log4j.category.testrail=INFO, testrailLog +log4j.additivity.testrail=false \ No newline at end of file diff --git a/tests/tas-email/src/test/resources/shared-resources/email-runner-suite.xml b/tests/tas-email/src/test/resources/shared-resources/email-runner-suite.xml new file mode 100644 index 0000000000..0ff426e2c8 --- /dev/null +++ b/tests/tas-email/src/test/resources/shared-resources/email-runner-suite.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/tests/tas-email/src/test/resources/shared-resources/email-sanity-suite.xml b/tests/tas-email/src/test/resources/shared-resources/email-sanity-suite.xml new file mode 100644 index 0000000000..d8831e3131 --- /dev/null +++ b/tests/tas-email/src/test/resources/shared-resources/email-sanity-suite.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/tas-email/src/test/resources/shared-resources/email-suites.xml b/tests/tas-email/src/test/resources/shared-resources/email-suites.xml new file mode 100644 index 0000000000..0afc400acc --- /dev/null +++ b/tests/tas-email/src/test/resources/shared-resources/email-suites.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/tas-email/src/test/resources/shared-resources/tas-email-sanity-suite.xml b/tests/tas-email/src/test/resources/shared-resources/tas-email-sanity-suite.xml new file mode 100644 index 0000000000..e900cfb97d --- /dev/null +++ b/tests/tas-email/src/test/resources/shared-resources/tas-email-sanity-suite.xml @@ -0,0 +1,143 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/tas-email/src/test/resources/shared-resources/testCount.xml b/tests/tas-email/src/test/resources/shared-resources/testCount.xml new file mode 100644 index 0000000000..2e0aaaac54 --- /dev/null +++ b/tests/tas-email/src/test/resources/shared-resources/testCount.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/tas-email/src/test/resources/shared-resources/testdata/imap-input-data.xml b/tests/tas-email/src/test/resources/shared-resources/testdata/imap-input-data.xml new file mode 100644 index 0000000000..53bf3f4955 --- /dev/null +++ b/tests/tas-email/src/test/resources/shared-resources/testdata/imap-input-data.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + /Sites/site1/documentLibrary + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/tas-email/src/test/resources/shared-resources/testdata/imap-resource b/tests/tas-email/src/test/resources/shared-resources/testdata/imap-resource new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/tas-integration/pom.xml b/tests/tas-integration/pom.xml new file mode 100644 index 0000000000..0fdb7773b2 --- /dev/null +++ b/tests/tas-integration/pom.xml @@ -0,0 +1,134 @@ + + + 4.0.0 + org.alfresco.tas + content-repository-community-integration-test + content-repository-community-integration-test + 6.3.0-SNAPSHOT + jar + + + org.alfresco + content-repository-community-tas-tests-parent + 6.3.0-SNAPSHOT + ../pom.xml + + + + + Paul Brodner + + Test Automation Architect + + + + + + ${project.basedir}/src/test/resources/integration-suite.xml + 2.5.5 + 1.5.1 + + + + + org.alfresco.tas + utility + test + + + + io.rest-assured + rest-assured + test + + + + javax.mail + javax.mail-api + ${dependency.javax.mail.version} + test + + + + com.sun.mail + javax.mail + ${dependency.javax.mail.version} + + + + org.codehaus.groovy + groovy + ${dependency.groovy.version} + + + + + org.alfresco.tas + ftp + test + + + + + org.alfresco.tas + restapi + test + + + + + org.alfresco.tas + cmis + test + + + + + org.alfresco.tas + email + test + + + + + org.alfresco.tas + webdav + test + + + + com.jayway.jsonpath + json-path + 2.3.0 + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + ${suiteXmlFile} + + + --illegal-access=warn + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + test-jar + + + + + + + diff --git a/tests/tas-integration/src/test/java/org/alfresco/tas/integration/IntegrationCoreTests.java b/tests/tas-integration/src/test/java/org/alfresco/tas/integration/IntegrationCoreTests.java new file mode 100644 index 0000000000..7f211292c1 --- /dev/null +++ b/tests/tas-integration/src/test/java/org/alfresco/tas/integration/IntegrationCoreTests.java @@ -0,0 +1,1494 @@ +package org.alfresco.tas.integration; + +import static org.alfresco.utility.report.log.Step.STEP; + +import javax.mail.FolderNotFoundException; + +import org.alfresco.rest.model.RestCommentModel; +import org.alfresco.rest.model.RestDeploymentModel; +import org.alfresco.rest.model.RestDeploymentModelsCollection; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestPersonFavoritesModel; +import org.alfresco.rest.model.RestPersonFavoritesModelsCollection; +import org.alfresco.rest.model.RestRatingModel; +import org.alfresco.utility.Utility; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.RandomData; +import org.alfresco.utility.model.*; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.apache.commons.lang3.RandomStringUtils; +import org.springframework.http.HttpStatus; +import org.testng.annotations.Test; + +import junit.framework.Assert; + +/** + * Created by Claudia Agache on 12/13/2016. + */ +public class IntegrationCoreTests extends IntegrationTest +{ + UserModel testUser1, testUser2; + SiteModel testSitePublic, testSiteModerated, testSitePrivate, secondPublicSite; + FolderModel testFolder1, testFolder2, parentFolder1; + private String renamePrefix = "edited-"; + FileModel testFile1, testFile2, childDoc1, childDoc2, childDoc3, childDoc4, childDoc5; + RestRatingModel returnedRatingModel; + RestPersonFavoritesModel restPersonFavoritesModel; + private String newContent = "new TAS content"; + + /** + * Scenario 22 + * 1. Using CMIS create 2 test users: u1 and u2 + * 2. U1 creates a public test site and U2 a public test site using CMIS + * 3. U1 creates a folder with a file in his public site's document library using WebDav + * 4. U1 tries to move his folder to U2 public site using IMAP + * 5. Verify folder with file is not moved. U1 is not authorized to access the public site + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.CORE }, expectedExceptions = FolderNotFoundException.class) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, + description = "Verify user is not able to move a folder with a file to a public site if he is not a member of that site.") + public void moveFolderWithFileToPublicSiteByUninvitedUser() throws Exception + { + STEP("1. Using CMIS create 2 test users: u1 and u2"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + + STEP("2. U1 creates a public test site and U2 a public test site using CMIS"); + testSitePublic = dataSite.usingUser(testUser1).createPublicRandomSite(); + secondPublicSite = dataSite.usingUser(testUser2).createIMAPSite(); + + STEP("3. U1 creates a folder with a file in public site's document library using WebDav"); + testFolder1 = FolderModel.getRandomFolderModel(); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file1 content"); + webDavProtocol.authenticateUser(testUser1).usingSite(testSitePublic) + .createFolder(testFolder1).assertThat().existsInWebdav() + .usingResource(testFolder1).createFile(testFile1).assertThat().existsInRepo(); + + STEP("4. U1 tries to move his folder to U2 public site using IMAP. 5. Verify folder with file is not moved. U1 is not authorized to access the U2 public site"); + FolderModel destination = new FolderModel(Utility.buildPath("Sites", secondPublicSite.getId(), "documentLibrary")); + destination.setProtocolLocation(imapProtocol.authenticateUser(testUser2).usingSite(secondPublicSite).getLastResourceWithoutPrefix()); + imapProtocol.authenticateUser(testUser1) + .usingResource(testFolder1).moveTo(destination) + .assertThat().doesNotExistInRepo(); + } + + /** + * Scenario 23 + * 1. Using CMIS create 1 test user: u1 + * 2. U1 creates a public test site + * 3. U1 creates a folder (parentFolder) inside public site's document library using WebDav + * 4. Inside parentFolder create 4 files using CMIS, WebDAV, FTP + * 5. Inside parentFolder create 1 subfolder using IMAP + * 6. Delete parentFolder using CMIS + * 7. Verify folder is deleted along with all its children + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.CORE }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, + description = "Verify user is able to delete parent folder along with all its children using CMIS.") + public void deleteFolderWithChildrenUsingCMIS() throws Exception + { + STEP("1. Using CMIS create 1 test user: u1"); + testUser1 = dataUser.createRandomTestUser(); + + STEP("2. U1 creates a public test site using CMIS"); + testSitePublic = dataSite.usingUser(testUser1).createIMAPSite(); + + STEP("3. U1 creates a folder (parentFolder) inside public site's document library using WebDav"); + FolderModel parentFolder = FolderModel.getRandomFolderModel(); + webDavProtocol.authenticateUser(testUser1) + .usingSite(testSitePublic).createFolder(parentFolder) + .assertThat().existsInWebdav() + .and().assertThat().existsInRepo(); + + STEP("4. Inside parentFolder create 4 files using CMIS, WebDAV, FTP"); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + FileModel testFile2 = FileModel.getRandomFileModel(FileType.MSWORD); + FileModel testFile3 = FileModel.getRandomFileModel(FileType.HTML); + FileModel testFile4 = FileModel.getRandomFileModel(FileType.EXE); + cmisAPI.authenticateUser(testUser1).usingResource(parentFolder) + .createFile(testFile1).assertThat().existsInRepo(); + webDavProtocol.usingResource(parentFolder).createFile(testFile2) + .assertThat().existsInWebdav().and() + .assertThat().existsInRepo(); + cmisAPI.authenticateUser(testUser1).usingResource(parentFolder).createFile(testFile3) + .assertThat().existsInRepo(); + ftpProtocol.authenticateUser(testUser1).usingResource(parentFolder).createFile(testFile4) + .assertThat().existsInFtp().and() + .assertThat().existsInRepo(); + + STEP("5. Inside parentFolder create 1 subfolder using IMAP"); + testFolder1 = FolderModel.getRandomFolderModel(); + imapProtocol.authenticateUser(testUser1) + .usingResource(parentFolder).createFolder(testFolder1) + .assertThat().existsInImap().and() + .assertThat().existsInRepo(); + + STEP("6. Delete parentFolder using CMIS 7. Verify folder is deleted along with all its children"); + cmisAPI.usingResource(parentFolder).deleteFolderTree().and().assertThat().doesNotExistInRepo() + .usingResource(testFolder1).assertThat().doesNotExistInRepo() + .usingResource(testFile1).assertThat().doesNotExistInRepo() + .usingResource(testFile2).assertThat().doesNotExistInRepo() + .usingResource(testFile3).assertThat().doesNotExistInRepo() + .usingResource(testFile4).assertThat().doesNotExistInRepo(); + } + + /** + * Scenario 24 + * 1. Using CMIS create 1 test user: u1 + * 2. U1 creates a public test site + * 3. U1 creates a folder (parentFolder) inside public site's document library using IMAP + * 4. Inside parentFolder create 4 files using CMIS, WebDAV, FTP + * 5. Inside parentFolder create 1 subfolder using WebDAV + * 6. Delete parentFolder using WebDAV + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.CORE }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, + description = "Verify user is able to delete parent folder along with all its children using WebDAV.") + public void deleteFolderWithChildrenUsingWebDAV() throws Exception + { + STEP("1. Using CMIS create 1 test user: u1"); + testUser1 = dataUser.createRandomTestUser(); + + STEP("2. U1 creates a public test site using CMIS"); + testSitePublic = dataSite.usingUser(testUser1).createIMAPSite(); + + STEP("3. U1 creates a folder (parentFolder) inside public site's document library using IMAP"); + FolderModel parentFolder = FolderModel.getRandomFolderModel(); + imapProtocol.authenticateUser(testUser1) + .usingSite(testSitePublic).createFolder(parentFolder) + .assertThat().existsInImap().and() + .assertThat().existsInRepo(); + + STEP("4. Inside parentFolder create 4 files using CMIS, WebDAV, FTP"); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + FileModel testFile2 = FileModel.getRandomFileModel(FileType.MSWORD); + FileModel testFile3 = FileModel.getRandomFileModel(FileType.HTML); + FileModel testFile4 = FileModel.getRandomFileModel(FileType.EXE); + cmisAPI.authenticateUser(testUser1).usingResource(parentFolder) + .createFile(testFile1).assertThat().existsInRepo(); + webDavProtocol.authenticateUser(testUser1).usingResource(parentFolder).createFile(testFile2) + .assertThat().existsInWebdav().and() + .assertThat().existsInRepo(); + ftpProtocol.authenticateUser(testUser1).usingResource(parentFolder).createFile(testFile4) + .assertThat().existsInFtp().and() + .assertThat().existsInRepo(); + + STEP("5. Inside parentFolder create 1 subfolder using WebDAV"); + testFolder1 = FolderModel.getRandomFolderModel(); + webDavProtocol.usingResource(parentFolder).createFolder(testFolder1) + .assertThat().existsInWebdav() + .and().assertThat().existsInRepo(); + + STEP("6. Delete parentFolder using WebDAV 7. Verify folder is deleted along with all its children"); + webDavProtocol.usingResource(parentFolder).delete().and().assertThat().doesNotExistInRepo() + .usingResource(testFolder1).assertThat().doesNotExistInRepo() + .usingResource(testFile1).assertThat().doesNotExistInRepo() + .usingResource(testFile2).assertThat().doesNotExistInRepo() + .usingResource(testFile3).assertThat().doesNotExistInRepo() + .usingResource(testFile4).assertThat().doesNotExistInRepo(); + } + + /** + * Scenario 25 + * 1. Using CMIS create 2 test users: u1 and u2 + * 2. U1 creates a public test site and adds u2 as manager to his site using CMIS + * 3. U1 creates a folder (parentFolder) inside public site's document library using CMIS + * 4. U1 creates a subfolder1 and a file1 inside parentFolder using FTP + * 5. U1 creates a subfolder2 and a file2 inside subfolder1 using CMIS + * 6. U2 creates a subfolder3 and a file3 using WebDAV + * 7. U2 deletes parentFolder using FTP + * 8. Verify folder is deleted along with all its children + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.CORE}) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, + description = "Verify user is able to delete parent folder along with all its children using FTP.") + public void deleteFolderWithChildrenUsingFTP() throws Exception + { + STEP("1. Using CMIS create 2 test users: u1 and u2"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + + STEP("2. U1 creates a public test site using CMIS and adds u2 as manager to his site using REST"); + testSitePublic = dataSite.usingUser(testUser1).createPublicRandomSite(); + dataUser.usingUser(testUser1).addUserToSite(testUser2, testSitePublic, UserRole.SiteManager); + testUser2.setUserRole(UserRole.SiteManager); + + STEP("3. U1 creates a folder (parentFolder) inside public site's document library using CMIS"); + FolderModel parentFolder = FolderModel.getRandomFolderModel(); + cmisAPI.authenticateUser(testUser1) + .usingSite(testSitePublic).createFolder(parentFolder) + .assertThat().existsInRepo(); + + STEP("4. U1 creates a subfolder1 and a file1 inside parentFolder using FTP"); + FolderModel subFolder1 = FolderModel.getRandomFolderModel(); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + + ftpProtocol.authenticateUser(testUser1) + .usingResource(parentFolder).createFolder(subFolder1) + .assertThat().existsInRepo() + .assertThat().existsInFtp() + .usingResource(parentFolder).createFile(testFile1) + .assertThat().existsInRepo() + .assertThat().existsInFtp(); + + STEP("5. U1 creates a subfolder2 and a file2 inside subfolder1 using CMIS"); + FolderModel subFolder2 = FolderModel.getRandomFolderModel(); + FileModel testFile2 = FileModel.getRandomFileModel(FileType.MSWORD); + + cmisAPI.authenticateUser(testUser1).usingResource(subFolder1) + .createFolder(subFolder2) + .assertThat().existsInRepo() + .createFile(testFile2) + .assertThat().existsInRepo(); + + STEP("6. U2 creates a subfolder3 and a file3 using WebDAV"); + FolderModel subFolder3 = FolderModel.getRandomFolderModel(); + FileModel testFile3 = FileModel.getRandomFileModel(FileType.HTML); + + webDavProtocol.authenticateUser(testUser2).usingResource(subFolder2) + .createFolder(subFolder3) + .assertThat().existsInWebdav() + .assertThat().existsInRepo() + .createFile(testFile3) + .assertThat().existsInWebdav() + .assertThat().existsInRepo(); + + STEP("7. U2 deletes parentFolder using FTP"); + ftpProtocol.authenticateUser(testUser2) + .usingResource(parentFolder).assertThat().existsInFtp() + .then().delete() + .assertThat().doesNotExistInRepo().and() + .assertThat().doesNotExistInFtp() + .usingResource(subFolder1) + .assertThat().doesNotExistInRepo().and() + .assertThat().doesNotExistInFtp() + .usingResource(subFolder2) + .assertThat().doesNotExistInRepo().and() + .assertThat().doesNotExistInFtp() + .usingResource(subFolder3) + .assertThat().doesNotExistInRepo().and() + .assertThat().doesNotExistInFtp() + .usingResource(testFile1) + .assertThat().doesNotExistInRepo().and() + .assertThat().doesNotExistInFtp() + .usingResource(testFile2) + .assertThat().doesNotExistInRepo().and() + .assertThat().doesNotExistInFtp() + .usingResource(testFile3) + .assertThat().doesNotExistInRepo().and() + .assertThat().doesNotExistInFtp(); + } + + /** + * Scenario 28 + * 1. Using CMIS create one test user: U1 + * 2. Using CMIS U1 creates a public test site + * 3. Using CMIS, WebDAV and FTP U1 creates multiple files and folders in parent folder + * 4. Using CMIS, U1 checks out a document from parent folder + * 5. Using CMIS, U1 deletes parent folder (deleteTree) + * 6. Using WebDAV, U1 verifies that parent folder and all children are NOT present in Repo and WebDAV + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.CORE}) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, description = "Verify deletion of a parentFolder with checkedout file using CMIS.") + public void deleteParentFolderWithCheckoutFileInUsingCMIS() throws Exception + { + STEP("1. Using CMIS create one test user: U1"); + testUser1 = dataUser.createRandomTestUser(); + + STEP("2. Using CMIS U1 creates a public test site"); + testSitePublic = dataSite.usingUser(testUser1).createPublicRandomSite(); + + STEP("3. Using CMIS, WebDAV and FTP U1 creates multiple files and folders in parent folder"); + FileModel cmisTestFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file 1 content"); + FileModel webdavTestFile = FileModel.getRandomFileModel(FileType.HTML, "file 2 content"); + FileModel ftpTestFile = FileModel.getRandomFileModel(FileType.MSWORD, "file 4 content"); + + testFolder1 = FolderModel.getRandomFolderModel(); + cmisAPI.authenticateUser(testUser1).usingSite(testSitePublic).createFolder(testFolder1).assertThat().existsInRepo(); + cmisAPI.authenticateUser(testUser1).usingResource(testFolder1).createFile(cmisTestFile) + .assertThat().existsInRepo(); + webDavProtocol.authenticateUser(testUser1).usingResource(testFolder1).createFile(webdavTestFile) + .assertThat().existsInWebdav().assertThat().existsInRepo(); + ftpProtocol.authenticateUser(testUser1).usingResource(testFolder1).createFile(ftpTestFile) + .assertThat().existsInFtp().assertThat().existsInRepo(); + + FolderModel cmisTestFolder = FolderModel.getRandomFolderModel(); + FolderModel webdavTestFolder = FolderModel.getRandomFolderModel(); + FolderModel ftpTestFolder = FolderModel.getRandomFolderModel(); + + cmisAPI.usingResource(testFolder1).createFolder(cmisTestFolder) + .assertThat().existsInRepo(); + webDavProtocol.usingResource(testFolder1).createFolder(webdavTestFolder) + .assertThat().existsInWebdav().assertThat().existsInRepo(); + ftpProtocol.usingResource(testFolder1).createFolder(ftpTestFolder) + .assertThat().existsInFtp().assertThat().existsInRepo(); + + cmisAPI.usingResource(testFolder1).assertThat() + .hasChildren(cmisTestFile, webdavTestFile, ftpTestFile, cmisTestFolder, webdavTestFolder, ftpTestFolder); + + STEP("Step 4: Using CMIS, U1 checks out a document from parent folder"); + cmisAPI.usingResource(webdavTestFile).checkOut().assertThat().documentIsCheckedOut(); + + STEP("Step 5: Using CMIS, U1 deletes parent folder (deleteTree)"); + + cmisAPI.usingResource(testFolder1).deleteFolderTree() + .assertThat().doesNotExistInRepo(); + STEP("Step 6. Using WebDAV, U1 verifies that parent folder and all children are not present"); + webDavProtocol.usingResource(testFolder1).assertThat().doesNotExistInRepo().assertThat().doesNotExistInWebdav() + .and().usingResource(cmisTestFile).assertThat().doesNotExistInRepo().assertThat().doesNotExistInWebdav() + .and().usingResource(webdavTestFile).assertThat().doesNotExistInRepo().assertThat().doesNotExistInWebdav() + .and().usingResource(ftpTestFile).assertThat().doesNotExistInRepo().assertThat().doesNotExistInWebdav() + .and().usingResource(cmisTestFolder).assertThat().doesNotExistInRepo().assertThat().doesNotExistInWebdav() + .and().usingResource(webdavTestFolder).assertThat().doesNotExistInRepo().assertThat().doesNotExistInWebdav() + .and().usingResource(ftpTestFolder).assertThat().doesNotExistInRepo().assertThat().doesNotExistInWebdav(); + } + + /** + * Scenario 29 + * 1. Using CMIS create one test user: U1 + * 2. Using CMIS U1 creates a public test site + * 3. Using FTP U1 creates a parent folder in public site's document library + * 4. Using CMIS, WebDAV and FTP U1 creates multiple files and folders in parent folder + * 5. Using CMIS, U1 checks out a document from parent folder + * 6. Using WebDAV, U1 deletes parent folder (deleteFolder) + * 7. Using FTP, U1 verifies that parent folder and all children are NOT present in Repo and FTP + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.CORE}) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, description = "Verify deletion of a parentFolder with checkedout file using WebDAV.") + public void deleteParentFolderWithCheckoutFileInUsingWebDAV() throws Exception + { + STEP("1. Using CMIS create one test user: U1"); + testUser1 = dataUser.createRandomTestUser(); + + STEP("2. Using CMIS U1 creates a public test site"); + testSitePublic = dataSite.usingUser(testUser1).createPublicRandomSite(); + + STEP("3. Using FTP U1 creates a parent folder"); + testFolder1 = FolderModel.getRandomFolderModel(); + ftpProtocol.authenticateUser(testUser1).usingSite(testSitePublic).createFolder(testFolder1).assertThat().existsInRepo(); + + STEP("4. Using CMIS, WebDAV and FTP U1 creates multiple files and folders in parent folder"); + FileModel cmisTestFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file 1 content"); + FileModel webdavTestFile = FileModel.getRandomFileModel(FileType.HTML, "file 2 content"); + FileModel ftpTestFile = FileModel.getRandomFileModel(FileType.MSWORD, "file 4 content"); + + cmisAPI.authenticateUser(testUser1).usingResource(testFolder1).createFile(cmisTestFile) + .assertThat().existsInRepo(); + webDavProtocol.authenticateUser(testUser1).usingResource(testFolder1).createFile(webdavTestFile) + .assertThat().existsInWebdav().assertThat().existsInRepo(); + ftpProtocol.usingResource(testFolder1).createFile(ftpTestFile) + .assertThat().existsInFtp().assertThat().existsInRepo(); + + FolderModel cmisTestFolder = FolderModel.getRandomFolderModel(); + FolderModel webdavTestFolder = FolderModel.getRandomFolderModel(); + + cmisAPI.usingResource(testFolder1).createFolder(cmisTestFolder) + .assertThat().existsInRepo(); + webDavProtocol.usingResource(testFolder1).createFolder(webdavTestFolder).assertThat().existsInWebdav() + .and().assertThat().existsInRepo(); + + cmisAPI.usingResource(testFolder1).assertThat().hasChildren(cmisTestFile, webdavTestFile, ftpTestFile, cmisTestFolder, webdavTestFolder); + + STEP("Step 5: Using CMIS, U1 checks out a document from parent folder"); + cmisAPI.usingResource(cmisTestFile).checkOut().assertThat().documentIsCheckedOut(); + + STEP("Step 6: Using WebDAV, U1 deletes parent folder (deleteFolder)"); + webDavProtocol.usingResource(testFolder1).assertThat().existsInRepo().and().assertThat().existsInWebdav() + .and().assertThat().hasFiles(cmisTestFile, webdavTestFile, ftpTestFile) + .and().assertThat().hasFolders(cmisTestFolder, webdavTestFolder) + .then().usingResource(testFolder1).delete() + .assertThat().doesNotExistInWebdav().assertThat().doesNotExistInRepo(); + + STEP("Step 7. Using FTP, U1 verifies that parent folder and all children are not present"); + ftpProtocol.usingResource(testFolder1).assertThat().doesNotExistInRepo().assertThat().doesNotExistInFtp() + .and().usingResource(cmisTestFile).assertThat().doesNotExistInRepo().assertThat().doesNotExistInFtp() + .and().usingResource(webdavTestFile).assertThat().doesNotExistInRepo().assertThat().doesNotExistInFtp() + .and().usingResource(ftpTestFile).assertThat().doesNotExistInRepo().assertThat().doesNotExistInFtp() + .and().usingResource(cmisTestFolder).assertThat().doesNotExistInRepo().assertThat().doesNotExistInFtp() + .and().usingResource(webdavTestFolder).assertThat().doesNotExistInRepo().assertThat().doesNotExistInFtp(); + } + + /** + * Scenario 30 + * 1. Using CMIS create one test user: U1 + * 2. Using CMIS U1 creates a public test site + * 3. Using WebDAV U1 creates a parent folder in public site's document library + * 4. Using CMIS, WebDAV and FTP U1 creates multiple files and folders in parent folder + * 5. Using CMIS, U1 checks out a document from parent folder + * 6. Using FTP, U1 deletes parent folder (deleteDirectory) + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.CORE}) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT}, executionType = ExecutionType.REGRESSION, description = "Verify deletion of a parentFolder with checkedout file using FTP.") + public void deleteParentFolderWithCheckoutFileInUsingFTP() throws Exception + { + STEP("1. Using CMIS create one test user: U1"); + testUser1 = dataUser.createRandomTestUser(); + + STEP("2. Using CMIS U1 creates a public test site"); + testSitePublic = dataSite.usingUser(testUser1).createPublicRandomSite(); + + STEP("3. Using WebDAV U1 creates a parent folder"); + testFolder1 = FolderModel.getRandomFolderModel(); + webDavProtocol.authenticateUser(testUser1).usingSite(testSitePublic).createFolder(testFolder1).assertThat().existsInRepo().assertThat() + .existsInWebdav(); + + STEP("4. Using CMIS, WebDAV and FTP U1 creates multiple files and folders in parent folder"); + FileModel cmisTestFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file 1 content"); + FileModel webdavTestFile = FileModel.getRandomFileModel(FileType.HTML, "file 2 content"); + + cmisAPI.authenticateUser(testUser1).usingResource(testFolder1).createFile(cmisTestFile) + .assertThat().existsInRepo(); + webDavProtocol.authenticateUser(testUser1).usingResource(testFolder1).createFile(webdavTestFile) + .assertThat().existsInWebdav().assertThat().existsInRepo(); + + FolderModel cmisTestFolder = FolderModel.getRandomFolderModel(); + FolderModel webdavTestFolder = FolderModel.getRandomFolderModel(); + FolderModel ftpTestFolder = FolderModel.getRandomFolderModel(); + + cmisAPI.usingResource(testFolder1).createFolder(cmisTestFolder) + .assertThat().existsInRepo(); + webDavProtocol.usingResource(testFolder1).createFolder(webdavTestFolder) + .assertThat().existsInWebdav().assertThat().existsInRepo(); + ftpProtocol.authenticateUser(testUser1).usingResource(testFolder1).createFolder(ftpTestFolder) + .assertThat().existsInFtp().assertThat().existsInRepo(); + + cmisAPI.usingResource(testFolder1).assertThat() + .hasChildren(cmisTestFile, webdavTestFile, cmisTestFolder, webdavTestFolder, ftpTestFolder); + + STEP("Step 5: Using CMIS, U1 checks out a document from parent folder"); + cmisAPI.usingResource(webdavTestFile).checkOut().assertThat().documentIsCheckedOut(); + + STEP("Step 6: Using FTP, U1 deletes parent folder (deleteDirectory)"); + ftpProtocol.usingResource(testFolder1).delete() + .and().assertThat().doesNotExistInFtp().and().assertThat().doesNotExistInRepo(); + } + + /** + * Scenario 32 - Document updates + * + * 1. Using CMIS create 2 test users: U1 and U2 + * 2. Using CMIS and RestAPI U1 creates a public test site and U2 user is added with collaborator role + * 3. Using WebDAV U1 creates a folder in his public site's document library + * 4. Using WebDAV U1 creates a document inside the above folder + * 5. Using RestAPI U2 adds the document to favorites + * 6. Using CMIS U1 adds content to document + * 7. Using WebDAV U2 validates document's content + * 8. Using WebDAV U2 updates content from document + * 9. Using CMIS U2 validates document's content + * 10. Using WebDAV U1 deletes the file + * 11. Using RestAPI U1 deletes the folder + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.CORE }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, + description = "Verify user with collaborator role can update document content in a public site.") + public void usersCanUpdateDocumentContentInsideAPublicSite() throws Exception + { + String originalContent = "originalContent"; + String updatedContent = "updatedContent"; + testFolder1 = FolderModel.getRandomFolderModel(); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + + STEP("1. Using CMIS create 2 test users: U1 and U2"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + + STEP("2. Using CMIS and RestAPI U1 creates a public test site and U2 user is added with collaborator role"); + testSitePublic = dataSite.usingUser(testUser1).createPublicRandomSite(); + testUser2.setUserRole(UserRole.SiteCollaborator); + restAPI.authenticateUser(testUser1).withCoreAPI().usingSite(testSitePublic).addPerson(testUser2); + + STEP("3. Using WebDAV U1 creates a folder in his public site's document library"); + webDavProtocol.authenticateUser(testUser1).usingSite(testSitePublic).createFolder(testFolder1) + .and().assertThat().existsInRepo(); + + STEP("4. Using WebDAV U1 creates a document inside the above folder"); + webDavProtocol.authenticateUser(testUser1).usingResource(testFolder1).createFile(testFile1) + .and().assertThat().existsInWebdav() + .and().assertThat().existsInRepo(); + + STEP("5. Using RestAPI U2 adds the document to favorites"); + restAPI.authenticateUser(testUser2).withCoreAPI().usingAuthUser().addFolderToFavorites(testFolder1); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + STEP("6. Using CMIS U1 adds content to document"); + cmisAPI.authenticateUser(testUser1).usingResource(testFile1) + .and().assertThat().existsInRepo() + .and().update(originalContent); + + STEP("7. Using WebDAV U2 validates document's content"); + webDavProtocol.authenticateUser(testUser2).usingResource(testFile1).assertThat().contentIs(originalContent); + + STEP("8. Using WebDAV U2 updates content from document"); + webDavProtocol.usingUser(testUser2).usingResource(testFile1) + .assertThat().existsInRepo() + .and().update(updatedContent); + + STEP("9. Using CMIS U2 validates document's content"); + cmisAPI.authenticateUser(testUser2).usingResource(testFile1).assertThat().contentIs(updatedContent); + + STEP("10. Using WebDAV U1 deletes the file"); + webDavProtocol.authenticateUser(testUser1).usingResource(testFile1).delete() + .and().assertThat().doesNotExistInRepo(); + + STEP("11. Using WebDAV U1 deletes the folder"); + webDavProtocol.authenticateUser(testUser1).usingResource(testFolder1).delete() + .and().assertThat().doesNotExistInRepo(); + } + + /** + * Scenario 33 - Document likes + * + * 1. Using CMIS create 2 test users: U1 and U2 + * 2. Using RestAPI U1 creates a public test site and U2 user is added with contributor role + * 3. Using WebDAV U1 creates a folder in his public site's document library + * 4. Using WebDAV U1 creates a document1 inside the above folder + * 5. Using WebDAV U2 creates a document2 inside folder + * 6. Using RestAPI U2 likes document1 + * 7. Using RestAPI U1 likes document2 + * 8. Using RestAPI U1 dislikes document2 + * 9. Using RestAPI U2 add to favorites document1 + * 10. Using CMIS U1 delete document1 + * 11. Using CMIS U2 delete the folder + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.CORE }, expectedExceptions = {CmisPermissionDeniedException.class, CmisUnauthorizedException.class} ) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, + description = "Verify user with contributor role can like/favorite a document in a public site.") + public void usersCanLikeADocumentInPublicSite() throws Exception + { + STEP("1. Using CMIS create 2 test users: U1 and U2"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + + STEP("2. Using RestAPI U1 creates a public test site and U2 user is added with contributor role"); + testSitePublic = dataSite.usingUser(testUser1).createPublicRandomSite(); + testUser2.setUserRole(UserRole.SiteContributor); + restAPI.authenticateUser(testUser1).withCoreAPI().usingSite(testSitePublic).addPerson(testUser2); + + STEP("3. Using WebDAV U1 creates a folder in his public site's document library"); + testFolder1 = FolderModel.getRandomFolderModel(); + webDavProtocol.authenticateUser(testUser1).usingSite(testSitePublic) + .createFolder(testFolder1).assertThat().existsInWebdav() + .and().assertThat().existsInRepo(); + + STEP("4. Using WebDAV U1 creates a document1 inside the above folder"); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + webDavProtocol.usingResource(testFolder1).createFile(testFile1) + .assertThat().existsInRepo() + .and().assertThat().existsInWebdav(); + + STEP("5. Using WebDAV U2 creates a document2 inside folder"); + testFile2 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + webDavProtocol.authenticateUser(testUser2) + .usingResource(testFolder1).createFile(testFile2).assertThat().existsInRepo() + .and().assertThat().existsInWebdav(); + + STEP("6. Using RestAPI U2 likes document1"); + RestRatingModel returnedRatingModel = restAPI.authenticateUser(testUser2).withCoreAPI().usingResource(testFile1).likeDocument(); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + returnedRatingModel.assertThat().field("myRating").is("true") + .and().field("id").is("likes").and().field("aggregate").isNotEmpty(); + + STEP("7. Using RestAPI U1 likes document2"); + returnedRatingModel = restAPI.authenticateUser(testUser1).withCoreAPI().usingResource(testFile2).likeDocument(); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + returnedRatingModel.assertThat().field("myRating").is("true") + .and().field("id").is("likes").and().field("aggregate").isNotEmpty(); + + STEP("8. Using RestAPI U1 dislikes document2"); + restAPI.authenticateUser(testUser1).withCoreAPI().usingResource(testFile2).deleteLikeRating(); + restAPI.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + STEP("9. Using RestAPI U2 add to favorites document1"); + RestPersonFavoritesModel restPersonFavoritesModel = restAPI.authenticateUser(testUser2).withCoreAPI().usingAuthUser().addFileToFavorites(testFile1); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + restPersonFavoritesModel.assertThat().field("targetGuid").is(testFile1.getNodeRefWithoutVersion()); + + STEP("10. Using CMIS U1 delete document1"); + cmisAPI.authenticateUser(testUser1).usingResource(testFile1).delete() + .and().assertThat().doesNotExistInRepo(); + + restAPI.withCoreAPI().usingResource(testFile1).getLikeRating(); + restAPI.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, testFile1.getNodeRef())); + + RestPersonFavoritesModelsCollection userFavorites = restAPI.withCoreAPI().usingAuthUser().getFavorites(); + restAPI.assertStatusCodeIs(HttpStatus.OK); + userFavorites.assertThat().entriesListIsEmpty().and().paginationField("totalItems").is("0"); + + STEP("11. Using CMIS U2 delete the folder. With Contributor role, U2 does not have permission to delete files/folders created by others."); + cmisAPI.authenticateUser(testUser2).usingResource(testFolder1).assertThat().doesNotHaveFile(testFile1) + .and().assertThat().hasFiles(testFile2) + .and().usingResource(testFile2).delete() + .and().usingResource(testFolder1).delete(); + } + + /** + * Scenario 34 - Document ratings + * + * 1. Using CMIS create 2 test users: U1 and U2 + * 2. Using RestAPI U1 creates a public test site and U2 user is added with collaborator role + * 3. Using CMIS U1 creates a new folder in site + * 4. Using WebDAV U2 creates file1 in public site document library + * 5. Using WebDAV U1 creates a file2 in public site document library + * 6. Using RestAPI U2 rates with 5 stars file2 + * 7. Using RestAPI U1 rates with 1 star file1 + * 8. Using RestAPI U2 likes file1 + * 9. Using RestAPI U2 removes the rating of 5 stars for file2 + * 10. Using WebDAV U1 delete file1. Using RestAPI get ratings of file1. + * 11. Using WebDAV U1 delete the folder + */ + + @Test(groups = { TestGroup.INTEGRATION, TestGroup.CORE }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, + description = "Verify user with collaborator role can rate a document in a public site.") + public void usersCanRateADocumentInPublicSite() throws Exception + { + RestRatingModel returnedRatingModel; + + STEP("1. Using CMIS create 2 test users: U1 and U2"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + + STEP("2. Using RestAPI U1 creates a public test site and U2 user is added with collaborator role"); + testSitePublic = dataSite.usingUser(testUser1).createPublicRandomSite(); + testUser2.setUserRole(UserRole.SiteCollaborator); + restAPI.authenticateUser(testUser1).withCoreAPI().usingSite(testSitePublic).addPerson(testUser2); + + STEP("3. Using CMIS U1 creates a new folder in site"); + testFolder1 = FolderModel.getRandomFolderModel(); + cmisAPI.authenticateUser(testUser1).usingSite(testSitePublic) + .createFolder(testFolder1).assertThat().existsInRepo(); + + STEP("4. Using WebDAV U2 creates file1 in public site document library"); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + webDavProtocol.authenticateUser(testUser2).usingResource(testFolder1) + .createFile(testFile1).assertThat().existsInRepo() + .and().assertThat().existsInWebdav(); + + STEP("5. Using WebDAV U1 creates a file2 in public site document library"); + testFile2 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + webDavProtocol.authenticateUser(testUser1).usingSite(testSitePublic) + .usingResource(testFolder1).createFile(testFile2).assertThat().existsInRepo(); + + STEP("6. Using RestAPI U2 rates with 5 stars file2"); + returnedRatingModel = restAPI.authenticateUser(testUser2).withCoreAPI().usingResource(testFile2) + .rateStarsToDocument(5); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty(); + + STEP("7. Using RestAPI U1 rates with 1 star file1"); + returnedRatingModel = restAPI.authenticateUser(testUser1).withCoreAPI().usingResource(testFile1) + .rateStarsToDocument(1); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + returnedRatingModel.assertThat().field("myRating").is("1").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty(); + + STEP("8. Using RestAPI U2 likes file1"); + returnedRatingModel = restAPI.authenticateUser(testUser2).withCoreAPI().usingResource(testFile1) + .likeDocument(); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + returnedRatingModel.assertThat().field("myRating").is("true").and().field("id").is("likes").and().field("aggregate").isNotEmpty(); + + STEP("9. Using RestAPI U2 removes the rating of 5 stars for file2"); + restAPI.authenticateUser(testUser2).withCoreAPI().usingResource(testFile2).deleteFiveStarRating(); + restAPI.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + returnedRatingModel = restAPI.withCoreAPI().usingResource(testFile2).getFiveStarRating(); + restAPI.assertStatusCodeIs(HttpStatus.OK); + returnedRatingModel.getAggregate().assertThat().field("numberOfRatings").is("0"); + + STEP("10. Using WebDAV U1 delete file1. Using RestAPI get ratings of file1."); + webDavProtocol.authenticateUser(testUser1).usingResource(testFile1).delete() + .and().assertThat().doesNotExistInRepo() + .and().assertThat().doesNotExistInWebdav(); + + restAPI.withCoreAPI().usingResource(testFile1).getLikeRating(); + restAPI.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, testFile1.getNodeRef())); + + restAPI.withCoreAPI().usingResource(testFile1).getFiveStarRating(); + restAPI.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, testFile1.getNodeRef())); + + STEP("11. Using WebDAV U1 delete the folder"); + webDavProtocol.authenticateUser(testUser1).usingResource(testFolder1).assertThat().hasFiles(testFile2) + .and().usingResource(testFolder1).delete() + .and().assertThat().doesNotExistInRepo(); + } + + /** + * Scenario 35 + * 1. Using CMIS create 2 test user: U1 and U2 + * 2. Using CMIS U1 creates a public test site + * 3. Using FTP U1 creates a folder in public site's document library: folder1 + * 4. Using WebDAV U1 creates inside folder1 a new folder: folder2 + * 5. Using WebDAV U1 creates inside folder2 a new folder: folder3 + * 6. Using CMIS U1 creates inside folder1 a new file: file1 + * 7. Using WebDAV U1 creates inside folder2 a new file: file2 + * 8. Using FTP U1 creates inside folder3 a new file: file3 + * 9. Using WebDAV U1 deletes file1 + * 10. Using IMAP U1 deletes file2 + * 11. Using WebDAV U1 updates content of file3 + * 12. Using RestAPI U1 adds a comment to file3 + * 13. Using RestAPI U1 likes file3 and user U2 rates file3 + * 14. Using CMIS U1 deletes file3 + */ + + @Test(groups = { TestGroup.INTEGRATION, TestGroup.CORE }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, + description = "File handling - perform actions: create, delete, add comment, like and rate, update file content ") + public void fileHandlingCreateUpdateContentDeleteLikeAndRate() throws Exception + { + STEP("1. Using CMIS create 1 test user: U1 and U2"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + + STEP("2. U1 creates a public test site using CMIS"); + testSitePublic = dataSite.usingUser(testUser1).createIMAPSite(); + + STEP("3. Using FTP U1 creates folder: folder1"); + FolderModel folder1 = FolderModel.getRandomFolderModel(); + ftpProtocol.authenticateUser(testUser1).usingSite(testSitePublic).createFolder(folder1) + .assertThat().existsInRepo(); + + STEP("4. Using WebDAV U1 creates folder2 inside folder1"); + FolderModel folder2 = FolderModel.getRandomFolderModel(); + webDavProtocol.authenticateUser(testUser1).usingResource(folder1).createFolder(folder2); + + STEP("5. Using webDAV U1 creates folder3 inside folder2"); + FolderModel folder3 = FolderModel.getRandomFolderModel(); + webDavProtocol.authenticateUser(testUser1).usingResource(folder2).createFolder(folder3); + + STEP("6. Using CMIS U1 creates file1 inside folder1"); + FileModel file1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file 1 content"); + cmisAPI.authenticateUser(testUser1).usingResource(folder1).createFile(file1) + .assertThat().existsInRepo(); + + STEP("7. Using webDAV U1 creates file2 inside folder2"); + FileModel file2 = FileModel.getRandomFileModel(FileType.HTML, "file 2 content"); + webDavProtocol.authenticateUser(testUser1).usingResource(folder2).createFile(file2) + .assertThat().existsInWebdav().assertThat().existsInRepo(); + + STEP("8. Using FTP U1 creates file3 inside folder3"); + FileModel file3 = FileModel.getRandomFileModel(FileType.MSWORD, "file 3 content"); + ftpProtocol.authenticateUser(testUser1).usingResource(folder3).createFile(file3) + .assertThat().existsInRepo(); + + STEP("9. Using webDAV U1 deletes file1"); + webDavProtocol.authenticateUser(testUser1).usingResource(file1).delete() + .assertThat().doesNotExistInRepo().and().assertThat().doesNotExistInWebdav(); + + STEP("10. Using IMAP U1 deletes file2"); + imapProtocol.authenticateUser(testUser1).usingResource(file2).deleteMessage() + .and().usingResource(file2).assertThat().doesNotExistInRepo(); + + STEP("11. Using WebDAV U1 update content of file3"); + webDavProtocol.authenticateUser(testUser1) + .usingResource(file3).assertThat().existsInRepo() + .update(newContent).assertThat().contentIs(newContent); + + STEP("12. Using RestAPI U1 adds a comment to file3"); + String comment = RandomData.getRandomName("comment1"); + file3.setNodeRef(dataContent.usingUser(testUser1).usingSite(testSitePublic) + .usingResource(folder3).usingResource(file3).getNodeRef()); + RestCommentModel commentModel = restAPI.authenticateUser(testUser1).withCoreAPI() + .usingResource(file3).addComment(comment); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + commentModel.assertThat().field("content").isNotEmpty() + .and().field("content").is(comment); + + STEP("13. Using RestAPI U1 likes file3 and user U2 rates file3"); + returnedRatingModel = restAPI.authenticateUser(testUser1).withCoreAPI().usingResource(file3).likeDocument(); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + returnedRatingModel.assertThat().field("myRating").is("true").and().field("id").is("likes").and().field("aggregate").isNotEmpty(); + + returnedRatingModel = restAPI.authenticateUser(testUser2).withCoreAPI() + .usingResource(file3).rateStarsToDocument(5); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty(); + + STEP("14. Using CMIS U1 deletes file3"); + cmisAPI.authenticateUser(testUser1).usingResource(file3).delete() + .assertThat().doesNotExistInRepo(); + } + + /** + * Scenario 37 + * 1. Using CMIS creates 2 users: U1 and U + * 2. U1 creates a public test site using CMIS + * 3. Using CMIS U1 creates folder: folder1 + * 4. Using WebDAV U1 creates folder2 and folder3 inside folder1 + * 5. Using FTP U1 creates file1 inside folder1 + * 6. Using CMIS U1 copies file1 to folder2 + * 7. Using WebDAV U1 update content of file1 from folder2 + * 8. Using FTP U1 tries to move file1 from folder2 to folder1 + * 9. Using WebDAV U1 updates content of file1 from folder1 + * 10. Using RestAPI U1 adds file1 to favorites + * 11. Using RestAPI U1 likes file1 and U2 user rates file1 + * 12. Using CMIS U1 moves file1 from folder1 to folder3 + * 13. Using CMIS/RestAPI U1 checks that content, favorites and ratings are kept + */ + + @Test(groups = { TestGroup.INTEGRATION, TestGroup.CORE }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, + description = "File handling - perform actions: copy, move, add/update content, favorites, like and rate") + public void fileHandlingCopyMoveAddUpdateContentFavoritesLikeAndRate() throws Exception + { + STEP("1. Using CMIS creates 2 users: U1 and U2"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + + STEP("2. U1 creates a public test site using CMIS"); + testSitePublic = dataSite.usingUser(testUser1).createPublicRandomSite(); + + STEP("3. Using CMIS U1 creates folder: folder1"); + FolderModel folder1 = FolderModel.getRandomFolderModel(); + cmisAPI.authenticateUser(testUser1).usingSite(testSitePublic).createFolder(folder1) + .assertThat().existsInRepo(); + + STEP("4. Using WebDAV U1 creates folder2 and folder3 inside folder1"); + FolderModel folder2 = FolderModel.getRandomFolderModel(); + FolderModel folder3 = FolderModel.getRandomFolderModel(); + webDavProtocol.authenticateUser(testUser1) + .usingResource(folder1).createFolder(folder2).and().assertThat().existsInWebdav() + .usingResource(folder1).createFolder(folder3).and().assertThat().existsInWebdav(); + + STEP("5. Using FTP U1 creates file1 inside folder1"); + FileModel file1 = FileModel.getRandomFileModel(FileType.MSWORD2007, "tasTesting"); + ftpProtocol.authenticateUser(testUser1).usingResource(folder1).createFile(file1) + .assertThat().existsInRepo(); + + STEP("6. Using CMIS U1 copies file1 to folder2"); + FileModel copiedFile = new FileModel(file1); + cmisAPI.authenticateUser(testUser1).usingResource(file1).copyTo(folder2); + copiedFile.setCmisLocation(cmisAPI.getLastResource()); + cmisAPI.usingResource(folder2).assertThat().hasFiles(file1); + + STEP("7. Using WebDAV U1 update content of file1 from folder2"); + webDavProtocol.usingResource(copiedFile).assertThat().existsInRepo() + .update(newContent).assertThat().contentIs(newContent); + + STEP("8. Using FTP U1 tries to move file1 from folder2 to folder1"); + ftpProtocol.authenticateUser(testUser1) + .usingResource(copiedFile).moveTo(folder1).assertThat().existsInRepo(); + Assert.assertTrue(ftpProtocol.usingResource(folder1).getFiles().size() == 1); + + STEP("9. Using WebDAV U1 updates content of file1 from folder1"); + webDavProtocol.usingResource(file1).update("content folder1") + .assertThat().contentIs("content folder1"); + + STEP("10. Using RestAPI U1 adds file1 to favorites"); + file1.setNodeRef(dataContent.usingUser(testUser1).usingSite(testSitePublic) + .usingResource(folder1).usingResource(file1).getNodeRef()); + + restPersonFavoritesModel = restAPI.authenticateUser(testUser1).withCoreAPI() + .usingAuthUser().addFileToFavorites(file1); + restAPI.assertStatusCodeIs(org.springframework.http.HttpStatus.CREATED); + restPersonFavoritesModel.assertThat().field("targetGuid").is(file1.getNodeRefWithoutVersion()); + + STEP("11. Using RestAPI U1 likes file1 and U2 user rates file1"); + returnedRatingModel = restAPI.authenticateUser(testUser1).withCoreAPI() + .usingResource(file1).likeDocument(); + restAPI.assertStatusCodeIs(org.springframework.http.HttpStatus.CREATED); + returnedRatingModel.assertThat().field("myRating").is("true").and().field("id").is("likes") + .and().field("aggregate").isNotEmpty(); + + returnedRatingModel = restAPI.authenticateUser(testUser2).withCoreAPI() + .usingResource(file1).rateStarsToDocument(5); + restAPI.assertStatusCodeIs(org.springframework.http.HttpStatus.CREATED); + returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar") + .and().field("aggregate").isNotEmpty(); + + STEP("12. Using CMIS U1 moves file1 from folder1 to folder3"); + cmisAPI.usingSite(testSitePublic).usingResource(file1).moveTo(folder3) + .and().assertThat().existsInRepo(); + + STEP("13. Using CMIS/RestAPI U1 checks that content, favorites and ratings are kept"); + returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar") + .and().field("aggregate").isNotEmpty(); + restPersonFavoritesModel.assertThat().field("targetGuid").is(file1.getNodeRefWithoutVersion()); + } + + /** + * Scenario 38 + * 1. Using CMIS create one test user: U1 + * 2. Using CMIS U1 creates a new document in Share + * 3. Using WebDAV U1 creates a new document in User Home + * 4. Using WebDAV U1 updates both documents + * 5. Verify if only first document's version is increased using CMIS + * 6. Verify if content is updated using WebDav + * 7. Verify if the size of the document is increased + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.CORE }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, description = "Verify document versioning after appending content using WebDAV.") + public void checkDocumentVersionAfterAppendingContent() throws Exception + { + STEP("1. Using CMIS create one test user: U1"); + testUser1 = dataUser.createRandomTestUser(); + + STEP("2. Using CMIS U1 creates a new document in Share"); + FileModel cmisTestFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file 1 content"); + cmisAPI.authenticateUser(testUser1) + .usingShared().createFile(cmisTestFile) + .assertThat().existsInRepo(); + + STEP("3. Using WebDAV U1 creates a new document in User Home"); + FileModel webDAVTestFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file 2 content"); + webDavProtocol.authenticateUser(testUser1) + .usingUserHome().createFile(webDAVTestFile) + .assertThat().existsInWebdav().and() + .assertThat().existsInRepo(); + + STEP("4. Using WebDAV U1 updates both documents"); + webDavProtocol.usingResource(cmisTestFile).update("cmis file content") + .usingResource(webDAVTestFile).update("WebDAV file content"); + + STEP("5. Verify if only first document's version is increased using CMIS"); + cmisAPI.usingResource(cmisTestFile).assertThat().documentHasVersion(1.1) + .usingResource(webDAVTestFile).assertThat().documentHasVersion(1.0); + + STEP("6. Verify if content is updated using WebDav"); + webDavProtocol.authenticateUser(testUser1) + .usingResource(cmisTestFile).assertThat().contentIs("cmis file content") + .usingResource(webDAVTestFile).assertThat().contentIs("WebDAV file content"); + + STEP("7. Verify if the size of the document is increased"); + cmisAPI.usingResource(cmisTestFile).assertThat().contentLengthIs(17) + .usingResource(webDAVTestFile).assertThat().contentLengthIs(19); + } + + /** + * Scenario 40 + * 1. Using CMIS create test user: U1 + * 2. U1 creates a private test site using CMIS + * 3. Using WebDAV U1 creates a folder + * 4. Using WebDAV U1 creates a file inside the folder + * 5. Using CMIS, check out the document + * 6. Using CMIS verify if PWC is created + * 7. Using CMIS check in document with content + * 8. Using CMIS verify that version does not increase + * 9. Using CMIS verify new content is added to document + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.CORE }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, + description = "Verify increased version and new content of a file that was check out then check in.") + public void verifyIncreasedVersionAndNewContentOfCheckInDocument() throws Exception + { + STEP("Step 1. Using CMIS create test user: U1"); + testUser1 = dataUser.createRandomTestUser(); + + STEP("Step 2. U1 creates a private test site using CMIS"); + testSitePublic = dataSite.usingUser(testUser1).createPrivateRandomSite(); + + STEP("Step 3. Using WebDAV U1 creates a folder"); + FolderModel folder = FolderModel.getRandomFolderModel(); + webDavProtocol.authenticateUser(testUser1).usingSite(testSitePublic).createFolder(folder); + + STEP("Step 4. Using WebDAV U1 creates a file inside the folder"); + FileModel file = FileModel.getRandomFileModel(FileType.XML, "file content"); + webDavProtocol.authenticateUser(testUser1).usingResource(folder).createFile(file) + .assertThat().existsInWebdav().assertThat().existsInRepo(); + + STEP("Step 5: Using CMIS, check out the document and verify document version"); + cmisAPI.authenticateUser(testUser1).usingResource(file).checkOut() + .assertThat().documentIsCheckedOut(); + + STEP("Step 6: Using CMIS verify if PWC is created"); + FileModel filePWC = cmisAPI.usingResource(file).withCMISUtil().getPWCFileModel(); + cmisAPI.usingResource(filePWC).assertThat().existsInRepo(); + + STEP("Step 7: Using CMIS check in document with content"); + String newContent = "new major content"; + cmisAPI.usingResource(folder).assertThat().folderHasCheckedOutDocument(file); + cmisAPI.usingResource(file).prepareDocumentForCheckIn() + .withMajorVersion() + .withContent(newContent) + .checkIn().refreshResource() + .and().assertThat().documentIsNotCheckedOut(); + + STEP("Step 8: Using CMIS verify that version does not increase"); + cmisAPI.usingResource(file).assertThat().documentHasVersion(1.0); + + STEP("Step 9: Using CMIS verify new content is added to document"); + cmisAPI.usingResource(file).assertThat().contentIs(newContent); + } + + /** + * Scenario 41 + * 1. Using CMIS create test user: U1 + * 2. U1 creates a private test site using CMIS + * 3. Using WebDAV U1 creates a folder + * 4. Using WebDAV U1 creates a file inside the folder + * 5. Using CMIS, check out the document + * 6. Using CMIS verify if PWC is created + * 7. Using CMIS, cancel check out + * 8. Using CMIS, verify original document has version 1.0 + * 9. Using CMIS, verify original document has same content + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.CORE }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, + description = "Verify that version and the content of a file are not changed if the checkout is canceled.") + public void verifyVersionAndContentOfACanceledCheckoutDocument() throws Exception + { + STEP("Step 1. Using CMIS create test user: U1"); + testUser1 = dataUser.createRandomTestUser(); + + STEP("Step 2. U1 creates a private test site using CMIS"); + testSitePublic = dataSite.usingUser(testUser1).createPrivateRandomSite(); + + STEP("Step 3. Using WebDAV U1 creates a folder"); + FolderModel folder = FolderModel.getRandomFolderModel(); + webDavProtocol.authenticateUser(testUser1).usingSite(testSitePublic).createFolder(folder); + + STEP("Step 4. Using WebDAV U1 creates a file inside the folder"); + FileModel file = FileModel.getRandomFileModel(FileType.XML, "file content"); + webDavProtocol.authenticateUser(testUser1).usingResource(folder).createFile(file) + .assertThat().existsInWebdav().assertThat().existsInRepo(); + + STEP("Step 5: Using CMIS, check out the document"); + cmisAPI.authenticateUser(testUser1).usingResource(file).checkOut(); + + STEP("Step 6: Using CMIS verify if PWC is created"); + FileModel filePWC = cmisAPI.usingResource(file).withCMISUtil().getPWCFileModel(); + cmisAPI.usingResource(filePWC).assertThat().existsInRepo(); + + STEP("Step 7: Using CMIS, cancel check out"); + cmisAPI.usingResource(file).cancelCheckOut().then() + .assertThat().documentIsNotCheckedOut(); + + STEP("Step 8: Using CMIS, verify original document has version 1.0"); + cmisAPI.usingResource(file).assertThat().isNotPrivateWorkingCopy() + .then().assertThat().documentHasVersion(1.0); + + STEP("Step 9: Using CMIS, verify original document has same content"); + cmisAPI.usingResource(file).assertThat().contentIs("file content"); + } + + /** + * Scenario 42 + * 1. Using CMIS create one test user: U1 + * 2. Using CMIS U1 creates a file: file + * 3. Using WebDAV U1 renames file and verify if the new document exists + * 4. Using FTP verify old document does not exists + */ + + @Test(groups = { TestGroup.INTEGRATION, TestGroup.CORE }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, + description = "Edit document name and verify document with new name") + public void renameDocument() throws Exception + { + STEP("1. Using CMIS create test user: U1"); + testUser1 = dataUser.createRandomTestUser(); + + STEP("2. Using CMIS U1 creates file"); + FileModel file = FileModel.getRandomFileModel(FileType.PDF, "file content"); + cmisAPI.authenticateUser(testUser1).usingUserHome().createFile(file) + .assertThat().existsInRepo(); + + STEP("3. Using WebDAV U1 renames file and verify if the new document exists"); + FileModel oldFile = new FileModel(file); + webDavProtocol.authenticateUser(testUser1).usingResource(file).rename(renamePrefix + file.getName()) + .and().assertThat().existsInRepo().and().assertThat().existsInWebdav(); + + STEP("4. Using FTP verify old document does not exists"); + ftpProtocol.authenticateUser(testUser1).usingResource(oldFile) + .assertThat().doesNotExistInRepo() + .and().assertThat().doesNotExistInFtp(); + } + + /** + * Scenario 43 + * 1. Using CMIS create test user: U1 + * 2. Using WebDAV U1 creates a file using shared + * 3. Using webDAV append content to document + * 4. Using CMIS, verify original document has version 1.0 + * 5. Using CMIS delete document + * 6. Using WebDAV, verify document is deleted + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.CORE }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, + description = "Delete document after append content and verify document version.") + public void deleteDocumentAfterAppendContent() throws Exception + { + STEP("Step 1. Using CMIS create test user: U1"); + testUser1 = dataUser.createRandomTestUser(); + + STEP("Step 2. Using WebDAV U1 creates a file using shared"); + FileModel file = FileModel.getRandomFileModel(FileType.XML, "file content"); + webDavProtocol.authenticateUser(testUser1).usingUserHome().createFile(file) + .assertThat().existsInRepo(); + + STEP("Step 3. Using webDAV append content to document"); + String newContentToAppend = " - append this text to the file"; + webDavProtocol.authenticateUser(testUser1).usingResource(file).assertThat().contentIs("file content") + .then().update(file.getContent() + newContentToAppend) + .assertThat().contentIs(file.getContent() + newContentToAppend); + + STEP("Step 4: Using CMIS, verify original document has version 1.0"); + cmisAPI.authenticateUser(testUser1).usingResource(file).assertThat().isNotPrivateWorkingCopy() + .then().assertThat().documentHasVersion(1.0); + + STEP("Step 4: Using CMIS, delete document"); + cmisAPI.usingResource(file).assertThat().existsInRepo().delete(); + + STEP("Step 5: Using WebDAV, verify document is deleted"); + webDavProtocol.authenticateUser(testUser1).usingResource(file).assertThat().doesNotExistInWebdav() + .and().assertThat().doesNotExistInRepo(); + } + + /** + * Scenario 44 + * 1. Using CMIS create one test user: U1 + * 2. Using CMIS U1 creates a public test site + * 3. Using WebDAV U1 creates a new file in User Home + * 4. Using WebDAV U1 creates another file in public site document library. + * 5. Using CMIS U1 creates a relationship between documents + * 6. Verify if relationship is created + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.CORE }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, description = "Verify if relationship is created between 2 items using CMIS.") + public void checkRelationshipBetween2Files() throws Exception + { + STEP("1. Using CMIS create one test user: U1"); + testUser1 = dataUser.createRandomTestUser(); + + STEP("2. Using CMIS U1 creates a public test site"); + testSitePublic = dataSite.usingUser(testUser1).createPublicRandomSite(); + + STEP("3. Using WebDAV U1 creates a new file in User Home"); + FileModel sourceFile= FileModel.getRandomFileModel(FileType.PDF, "file content"); + webDavProtocol.authenticateUser(testUser1).usingUserHome() + .createFile(sourceFile).assertThat().existsInRepo(); + + STEP("4. Using WebDAV U1 creates another file in public site document library."); + FileModel targetFile= FileModel.getRandomFileModel(FileType.PDF, "file content"); + webDavProtocol.authenticateUser(testUser1).usingSite(testSitePublic) + .createFile(targetFile).assertThat().existsInRepo(); + + STEP("5. Using CMIS U1 creates a relationship between documents. 6. Verify if relationship is created"); + cmisAPI.authenticateUser(testUser1).usingResource(sourceFile).createRelationshipWith(targetFile) + .assertThat().objectHasRelationshipWith(targetFile); + } + + /** + * Scenario 46 + * 1. Using CMIS create one test user: U1 + * 2. Using CMIS U1 creates an imap test site + * 3. Using CMIS U1 creates cmisFolder in Shared + * 4. Using IMAP U1 creates parentFolder in private site document library. + * 5. Using FTP U1 creates a subfolder in parentFolder + * 6. Using WebDAV U1 creates a webdavFolder in User Home + * 7. Using WebDAV U1 creates a document in parentFolder + * 8. Using CMIS U1 adds document to cmisFolder, subfolder, webdavFolder + * 9. Using WebDAV verify document is present in all folders + * 10. Using CMIS U1 removes document from subFolder + * 11. Using WebDAV verify document is not present in subFolder + * 12. Using FTP U1 deletes original document from parentFolder + * 13. Using CMIS verify document does not exist + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.CORE }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, description = "Verify parents list for an object using CMIS.") + public void addAndRemoveDocumentFromFolders() throws Exception + { + STEP("1. Using CMIS create one test user: U1"); + testUser1 = dataUser.createRandomTestUser(); + + STEP("2. Using CMIS U1 creates an imap test site"); + testSitePublic = dataSite.usingUser(testUser1).createIMAPSite(); + + STEP("3. Using CMIS U1 creates cmisFolder in Shared"); + FolderModel cmisFolder = FolderModel.getRandomFolderModel(); + cmisAPI.authenticateUser(testUser1) + .usingShared().createFolder(cmisFolder) + .assertThat().existsInRepo(); + + STEP("4. Using IMAP U1 creates parentFolder in private site document library."); + FolderModel parentFolder = FolderModel.getRandomFolderModel(); + imapProtocol.authenticateUser(testUser1) + .usingSite(testSitePublic).createFolder(parentFolder) + .assertThat().existsInRepo(); + + STEP("5. Using FTP U1 creates a subfolder in parentFolder"); + FolderModel subFolder = FolderModel.getRandomFolderModel(); + ftpProtocol.authenticateUser(testUser1) + .usingResource(parentFolder).createFolder(subFolder) + .assertThat().existsInRepo(); + + STEP("6. Using WebDAV U1 creates a webdavFolder in User Home"); + FolderModel webdavFolder = FolderModel.getRandomFolderModel(); + webDavProtocol.authenticateUser(testUser1) + .usingUserHome().createFolder(webdavFolder) + .assertThat().existsInRepo(); + + STEP("7. Using WebDAV U1 creates a document in parentFolder"); + testFile1= FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file content"); + webDavProtocol.authenticateUser(testUser1) + .usingResource(parentFolder).createFile(testFile1) + .assertThat().existsInRepo(); + + STEP("8. Using CMIS U1 adds document to cmisFolder, subfolder, webdavFolder"); + cmisAPI.usingResource(testFile1) + .addDocumentToFolder(cmisFolder, true).assertThat().hasParents(parentFolder.getName(), cmisFolder.getName()) + .addDocumentToFolder(subFolder, true).assertThat().hasParents(parentFolder.getName(), cmisFolder.getName(), subFolder.getName()) + .addDocumentToFolder(webdavFolder, true).assertThat().hasParents(parentFolder.getName(), cmisFolder.getName(), subFolder.getName(), webdavFolder.getName()); + + STEP("9. Using WebDAV verify document is present in all folders"); + FileModel fileAddedInCMISFolder = new FileModel(testFile1.getName(), testFile1.getTitle(), testFile1.getDescription(), testFile1.getFileType(), testFile1.getContent()); + fileAddedInCMISFolder.setCmisLocation(Utility.buildPath(cmisFolder.getCmisLocation(), testFile1.getName())); + + FileModel fileAddedInSubFolder = new FileModel(testFile1.getName(), testFile1.getTitle(), testFile1.getDescription(), testFile1.getFileType(), testFile1.getContent()); + fileAddedInSubFolder.setCmisLocation(Utility.buildPath(subFolder.getCmisLocation(), testFile1.getName())); + + FileModel fileAddedInWebDAVFolder = new FileModel(testFile1.getName(), testFile1.getTitle(), testFile1.getDescription(), testFile1.getFileType(), testFile1.getContent()); + fileAddedInWebDAVFolder.setCmisLocation(Utility.buildPath(webdavFolder.getCmisLocation(), testFile1.getName())); + + webDavProtocol.usingResource(fileAddedInCMISFolder).assertThat().existsInWebdav() + .usingResource(fileAddedInSubFolder).assertThat().existsInWebdav() + .usingResource(fileAddedInWebDAVFolder).assertThat().existsInWebdav(); + + STEP("10. Using CMIS U1 removes document from subFolder"); + cmisAPI.usingResource(testFile1).removeDocumentFromFolder(subFolder) + .assertThat().hasParents(parentFolder.getName(), cmisFolder.getName(), webdavFolder.getName()); + + STEP("11. Using WebDAV verify document is not present in subFolder"); + webDavProtocol.usingResource(testFile1).assertThat().existsInWebdav() + .usingResource(fileAddedInCMISFolder).assertThat().existsInWebdav() + .usingResource(fileAddedInSubFolder).assertThat().doesNotExistInWebdav() + .usingResource(fileAddedInWebDAVFolder).assertThat().existsInWebdav(); + + STEP("12. Using FTP U1 deletes original document from parentFolder"); + ftpProtocol.usingResource(testFile1).delete().assertThat().doesNotExistInFtp(); + + STEP("13. Using CMIS verify document does not exist"); + cmisAPI.usingResource(fileAddedInCMISFolder).assertThat().doesNotExistInRepo() + .usingResource(fileAddedInWebDAVFolder).assertThat().doesNotExistInRepo(); + } + + /** + * Scenario 47 - Delete many documents + * + * 1. Using CMIS create test user: U1 + * 2. Using CMIS U1 creates a public test site + * 3. Using CMIS and WebDAV U1 creates parentFolder1, doc1 and doc2 in document library + * 4. Using WebDAV and FTP U1 creates inside parentFolder1: childDoc1 to childDoc5 + * 5. Using IMAP bulk delete doc1 and doc2 + * 6. Using CMIS verify that doc1 and doc2 are deleted + * 7. Using IMAP delete childDoc1 to childDoc4 + * 8. Using WebDAV and FTP verify if docs are deleted from their folders + */ + + @Test(groups = { TestGroup.INTEGRATION, TestGroup.CORE }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT}, executionType = ExecutionType.REGRESSION, + description = "Verify users can delete many documents in a public site using different protocols.") + public void usersCanDeleteManyDocuments() throws Exception + { + FolderModel parentFolder1 = FolderModel.getRandomFolderModel(); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + testFile2 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + FileModel childDoc1, childDoc2, childDoc3, childDoc4, childDoc5; + childDoc1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + childDoc2 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + childDoc3 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + childDoc4 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + childDoc5 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + + STEP("1. Using CMIS create test user: U1"); + testUser1 = dataUser.createRandomTestUser(); + + STEP("2. Using CMIS U1 creates a public test site"); + testSitePublic = dataSite.usingUser(testUser1).createPublicRandomSite(); + + STEP("3. Using CMIS and WebDAV U1 creates parentFolder1, doc1 and doc2 in document library"); + cmisAPI.authenticateUser(testUser1).usingSite(testSitePublic).createFolder(parentFolder1) + .and().assertThat().existsInRepo(); + + webDavProtocol.authenticateUser(testUser1).usingSite(testSitePublic).createFile(testFile1) + .and().createFile(testFile2); + + STEP("4. Using WebDAV and FTP U1 creates inside parentFolder1: childDoc1 to childDoc5"); + webDavProtocol.authenticateUser(testUser1).usingResource(parentFolder1) + .createFile(childDoc1).and().createFile(childDoc2); + + ftpProtocol.authenticateUser(testUser1).usingResource(parentFolder1) + .createFile(childDoc3).and().createFile(childDoc4).and().createFile(childDoc5); + + STEP("5. Using IMAP bulk delete doc1 and doc2"); + imapProtocol.authenticateUser(testUser1).usingSite(testSitePublic).deleteMessage(testFile1.getName(), testFile2.getName()).assertThat().doesNotContainMessages(testFile1, testFile2); + Utility.waitToLoopTime(10); + + STEP("6. Using CMIS verify that doc1 and doc2 are deleted"); + cmisAPI.authenticateUser(testUser1) + .usingResource(testFile1).assertThat().doesNotExistInRepo() + .and().usingResource(testFile2).assertThat().doesNotExistInRepo(); + + STEP("7. Using IMAP delete childDoc1 to childDoc4"); + imapProtocol.authenticateUser(testUser1).usingResource(parentFolder1).deleteMessage(childDoc1.getName(), childDoc2.getName(), childDoc3.getName(), childDoc4.getName()) + .assertThat().doesNotContainMessages(childDoc1, childDoc2, childDoc3, childDoc4); + Utility.waitToLoopTime(10); + + STEP("8. Using WebDAV and FTP verify if docs are deleted from their folders"); + webDavProtocol.authenticateUser(testUser1).usingResource(parentFolder1).assertThat().hasFiles(childDoc5) + .and().usingResource(childDoc1).assertThat().doesNotExistInRepo() + .and().usingResource(childDoc2).assertThat().doesNotExistInRepo(); + + ftpProtocol.authenticateUser(testUser1).usingResource(childDoc3) + .assertThat().doesNotExistInRepo() + .and().usingResource(childDoc4).assertThat().doesNotExistInRepo(); + } + + /** + * Scenario 48 - Move folder in another folder + * + * 1. Using CMIS create user u1 and public site + * 2. Using WebDAV U1 creates folder1 and folder2 + * 3. Using WebDAV U1 creates doc1 in folder1 + * 4. Using FTP U1 moves folder1 in folder2 + * 5. Using WebDAV verify that folder1 is not in the original location and is present in folder2 + * 6. Using CMIS verify if doc1 is still present in folder1 + */ + + @Test(groups = { TestGroup.INTEGRATION, TestGroup.CORE }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, description = "Verify user is able to move a non empty folder to another folder from the same site.") + public void moveFolderInAnotherFolder() throws Exception + { + testFolder1 = FolderModel.getRandomFolderModel(); + testFolder2 = FolderModel.getRandomFolderModel(); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + + STEP("1. Using CMIS create user u1 and public site"); + testUser1 = dataUser.createRandomTestUser(); + testSitePublic = dataSite.usingUser(testUser1).createPublicRandomSite(); + + STEP("2. Using WebDAV U1 creates folder1 and folder2"); + webDavProtocol.authenticateUser(testUser1).usingSite(testSitePublic) + .createFolder(testFolder1) + .and().assertThat().existsInRepo().and().assertThat().existsInWebdav() + .then().createFolder(testFolder2) + .and().assertThat().existsInRepo().and().assertThat().existsInWebdav(); + + STEP("3. Using WebDAV U1 creates doc1 in folder1"); + webDavProtocol.authenticateUser(testUser1).usingResource(testFolder1).createFile(testFile1) + .and().assertThat().existsInRepo().and().assertThat().existsInWebdav() + .and().usingResource(testFolder1).assertThat().hasFiles(testFile1); + + STEP("4. Using FTP U1 moves folder1 in folder2"); + ftpProtocol.authenticateUser(testUser1) + .usingResource(testFolder1).moveTo(testFolder2) + .assertThat().existsInRepo() + .then().usingResource(testFolder1).assertThat().doesNotExistInRepo(); + + STEP("5. Using WebDAV verify that folder1 is not in the original location and is present in folder2"); + webDavProtocol.authenticateUser(testUser1).usingResource(testFolder1).assertThat().doesNotExistInRepo() + .and().usingResource(testFolder2).assertThat().hasFolders(testFolder1); + + STEP("6. Using CMIS verify if doc1 is still present in folder1"); + FolderModel newTestFolder1 = new FolderModel(testFolder1.getName(), testFolder1.getTitle(), testFolder1.getDescription()); + newTestFolder1.setCmisLocation(Utility.buildPath(testFolder2.getCmisLocation(), testFolder1.getName())); + + FileModel newTestFile1 = new FileModel(testFile1.getName(), testFile1.getTitle(), testFile1.getDescription(), testFile1.getFileType(), testFile1.getContent()); + newTestFile1.setCmisLocation(Utility.buildPath(newTestFolder1.getCmisLocation(), testFile1.getName())); + + cmisAPI.authenticateUser(testUser1).usingResource(newTestFolder1) + .assertThat().existsInRepo() + .assertThat().hasFiles(newTestFile1); + } + + /** + * Scenario 49 - Copy folder in another folder + * + * 1. Using CMIS create user u1 and public site + * 2. Using CMIS U1 creates folder1 and folder2 + * 3. Using WebDAV U1 creates doc1 in folder1 + * 4. Using WebDAV U1 copies folder1 in folder2 + * 5. Using FTP verify that folder1 is in the original location and contains doc1 + * 6. Using WebDAV verify that folder1 is in folder2 and contains doc1 + */ + + @Test(groups = { TestGroup.INTEGRATION, TestGroup.CORE }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, description = "Verify user is able to copy non empty folder to another folder in the same site.") + public void copyFolderInAnotherFolder() throws Exception + { + testFolder1 = FolderModel.getRandomFolderModel(); + testFolder2 = FolderModel.getRandomFolderModel(); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + + STEP("1. Using CMIS create user u1 and public site"); + testUser1 = dataUser.createUser(RandomStringUtils.randomAlphanumeric(20)); + testSitePublic = dataSite.usingUser(testUser1).createPublicRandomSite(); + + STEP("2. Using CMIS U1 creates folder1 and folder2"); + cmisAPI.authenticateUser(testUser1).usingSite(testSitePublic) + .createFolder(testFolder1).and().assertThat().existsInRepo().and() + .createFolder(testFolder2).and().assertThat().existsInRepo(); + + STEP("3. Using WebDAV U1 creates doc1 in folder1"); + webDavProtocol.authenticateUser(testUser1).usingResource(testFolder1) + .createFile(testFile1).and().assertThat().existsInRepo() + .and().assertThat().existsInWebdav(); + + STEP("4. Using WebDAV U1 copies folder1 in folder2"); + testFolder2.setProtocolLocation(webDavProtocol.getPrefixSpace() + testFolder2.getCmisLocation()); + webDavProtocol.authenticateUser(testUser1).usingResource(testFolder1).copyTo(testFolder2) + .assertThat().existsInRepo() + .then().usingResource(testFolder1).assertThat().existsInRepo(); + + STEP("5. Using FTP verify that folder1 is in the original location and contains doc1"); + ftpProtocol.authenticateUser(testUser1).usingResource(testFolder1) + .assertThat().existsInRepo() + .and().assertThat().existsInFtp() + .and().assertThat().hasFiles(testFile1); + + STEP("6. Using WebDAV verify that folder1 is in folder2 and contains doc1"); + FolderModel newTestFolder1 = new FolderModel(testFolder1.getName(), testFolder1.getTitle(), testFolder1.getDescription()); + newTestFolder1.setCmisLocation(Utility.buildPath(testFolder2.getCmisLocation(), testFolder1.getName())); + + FileModel newTestFile1 = new FileModel(testFile1.getName(), testFile1.getTitle(), testFile1.getDescription(), testFile1.getFileType(), testFile1.getContent()); + newTestFile1.setCmisLocation(Utility.buildPath(newTestFolder1.getCmisLocation(), testFile1.getName())); + + webDavProtocol.authenticateUser(testUser1).usingResource(testFolder2) + .assertThat().hasFolders(newTestFolder1) + .and().usingResource(newTestFolder1) + .assertThat().existsInRepo().and().assertThat().existsInWebdav() + .and().assertThat().hasFiles(newTestFile1); + } + + /** + * Scenario 50 - Rename site + * + * 1. Using CMIS create one test user: U1 + * 2. Using CMIS U1 creates a moderated site + * 3. Using WebDAV U1 creates a folder in the moderated site document library + * 4. Using CMIS U1 tries to rename site + * 5. Verify that a site cannot be renamed + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.CORE }, expectedExceptions = CmisRuntimeException.class, expectedExceptionsMessageRegExp = "^.*Sites can not be renamed.$") + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, description = "Verify sites cannot be renamed using CMIS.") + public void renameSite() throws Exception + { + STEP("1. Using CMIS create one test user: U1"); + testUser1 = dataUser.createRandomTestUser(); + + STEP("2. Using CMIS U1 creates a moderated site"); + testSiteModerated = dataSite.usingUser(testUser1).createModeratedRandomSite(); + + STEP("3. Using WebDAV U1 creates a folder in the moderated site document library"); + testFolder1 = FolderModel.getRandomFolderModel(); + webDavProtocol.authenticateUser(testUser1) + .usingSite(testSiteModerated).createFolder(testFolder1) + .assertThat().existsInWebdav() + .assertThat().existsInRepo(); + + STEP("4. Using CMIS U1 tries to rename site 5. Verify that a site cannot be renamed"); + FolderModel siteFolder = new FolderModel(String.format("/Sites/%s", testSiteModerated.getId())); + cmisAPI.authenticateUser(testUser1).usingResource(siteFolder).rename("renamedSite"); + } +} diff --git a/tests/tas-integration/src/test/java/org/alfresco/tas/integration/IntegrationFullTests.java b/tests/tas-integration/src/test/java/org/alfresco/tas/integration/IntegrationFullTests.java new file mode 100644 index 0000000000..529c5ef412 --- /dev/null +++ b/tests/tas-integration/src/test/java/org/alfresco/tas/integration/IntegrationFullTests.java @@ -0,0 +1,1800 @@ +package org.alfresco.tas.integration; + +import static org.alfresco.utility.report.log.Step.STEP; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.equalTo; + +import io.restassured.RestAssured; +import java.io.File; + +import javax.json.JsonObject; +import javax.mail.Flags; +import javax.mail.MessagingException; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.dataprep.SiteService.Visibility; +import org.alfresco.rest.core.JsonBodyGenerator; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.core.RestResponse; +import org.alfresco.rest.model.RestCommentModel; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestItemModelsCollection; +import org.alfresco.rest.model.RestNetworkModelsCollection; +import org.alfresco.rest.model.RestPreferenceModel; +import org.alfresco.rest.model.RestPreferenceModelsCollection; +import org.alfresco.rest.model.RestProcessDefinitionModelsCollection; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.rest.model.RestProcessVariableCollection; +import org.alfresco.rest.model.RestProcessVariableModel; +import org.alfresco.rest.model.RestTaskModel; +import org.alfresco.rest.model.RestTaskModelsCollection; +import org.alfresco.utility.Utility; +import org.alfresco.utility.constants.PreferenceName; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.RandomData; +import org.alfresco.utility.model.*; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.report.Bug.Status; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException; +import org.apache.commons.net.ftp.FTPReply; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.testng.Assert; +import org.testng.SkipException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 2/7/2017. + */ +public class IntegrationFullTests extends IntegrationTest +{ + private UserModel admin, testUser1, testUser2, userToAssign; + private SiteModel publicSite, moderatedSite, privateSite; + private FileModel testFile1, testFile2; + private FolderModel parentFolder; + private RestTaskModelsCollection processTasks; + private RestProcessModel processModel; + private RestItemModelsCollection taskItems; + private TaskModel taskModel; + private RestTaskModel restTaskModel; + + @BeforeClass(alwaysRun = true) + public void setup() throws Exception + { + admin = dataUser.getAdminUser(); + } + + /** + * Scenario + * 1. Using CMIS create test user testUser + * 2. Using CMIS create public IMAP site testSite + * 3. Using CMIS create file testFile in testSite document library + * 4. Using IMAP delete testFile + * 5. Using CMIS try to rename testFile + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }, expectedExceptions = CmisObjectNotFoundException.class) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, + description = "Verify the file cannot be renamed in repository if it is deleted from IMAP client") + public void verifyFileCannotBeRenamedInRepoIfItWasAlreadyDeletedViaIMAP() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser(); + SiteModel testSite = dataSite.usingUser(testUser).createIMAPSite(); + FileModel testFile = dataContent.usingUser(testUser).usingSite(testSite).createContent(FileModel.getRandomFileModel(FileType.TEXT_PLAIN)); + imapProtocol.authenticateUser(testUser).usingSite(testSite).usingResource(testFile).deleteMessage(); + cmisAPI.authenticateUser(testUser).usingSite(testSite).usingResource(testFile).rename("new file name"); + } + + /** + * Scenario 51 + * 1. Using CMIS create a test user: u1 + * 2. U1 creates a private site using CMIS + * 3. U1 creates a folder in site's document library using WebDAV + * 4. U1 uploads a document with size > x MB in folder1 using FTP + * 5. Verify file is present in folder1 using WebDAV + * 6. Verify size of the document from folder1 is exact as the size of the uploaded document CMIS + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, + description = "Verify a 1MB file is uploaded in a private site") + public void userShouldUploadFileInPrivateSite() throws Exception + { + STEP("1. Using CMIS create a test user: u1"); + testUser1 = dataUser.createRandomTestUser(); + + STEP("2. U1 creates a private site using CMIS"); + privateSite = dataSite.usingUser(testUser1).createPrivateRandomSite(); + + STEP("3. U1 creates a folder in site's document library using WebDav"); + parentFolder = FolderModel.getRandomFolderModel(); + webDavProtocol.authenticateUser(testUser1) + .usingSite(privateSite).createFolder(parentFolder) + .assertThat().existsInWebdav(); + + STEP("4. U1 uploads a document with size > x MB in folder1 using FTP"); + File fileForUpload = Utility.getTestResourceFile("shared-resources/testdata/flower.jpg"); + ftpProtocol.authenticateUser(testUser1) + .usingResource(parentFolder).uploadFile(fileForUpload) + .assertThat().existsInRepo() + .and().assertThat().existsInFtp(); + testFile1 = new FileModel(fileForUpload.getName()); + testFile1.setCmisLocation(ftpProtocol.getLastResourceWithoutPrefix()); + + STEP("5. Verify file is present in folder1 using WebDAV"); + webDavProtocol.authenticateUser(testUser1).usingResource(parentFolder).assertThat().hasFiles(testFile1); + + STEP("6. Verify size of the document from folder1 is exact as the size of the uploaded document CMIS"); + cmisAPI.authenticateUser(testUser1) + .usingResource(testFile1).assertThat().contentLengthIs(fileForUpload.length()); + } + + /** + * Scenario 52 + * 1. Using CMIS create 2 test users: u1 and u2 + * 2. U1 creates a private site using CMIS + * 3. U1 creates 2 documents in his site using WebDAV + * 4. U1 creates a new task with the documents created above and assigns the task to U2 using REST + * 5. Verify that U2 doesn't have access to te documents attached to the task using FTP + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.WORKFLOW }, executionType = ExecutionType.REGRESSION, + description = "Verify user is not able to access files from a private site, even if they are attached to a task assigned to him.") + public void assigneeCantAccessFilesFromPrivateSiteIfHeIsNotAMember() throws Exception + { + STEP("1. Using CMIS create 2 test users: u1 and u2"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + + STEP("2. U1 creates a private site using CMIS"); + privateSite = dataSite.usingUser(testUser1).createPrivateRandomSite(); + + STEP("3. U1 creates 2 documents in his site using WebDav"); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file1 content"); + testFile2 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file2 content"); + webDavProtocol.authenticateUser(testUser1).usingSite(privateSite) + .createFile(testFile1) + .assertThat().existsInWebdav() + .assertThat().existsInRepo() + .createFile(testFile2) + .assertThat().existsInWebdav() + .assertThat().existsInRepo(); + + STEP("4. U1 creates a new task with the documents created above and assigns the task to U2 using REST"); + processModel = restAPI.authenticateUser(testUser1).withWorkflowAPI() + .addProcess("activitiAdhoc", testUser2, false, CMISUtil.Priority.Normal); + restAPI.withWorkflowAPI().usingProcess(processModel).addProcessItem(testFile1); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + restAPI.withWorkflowAPI().usingProcess(processModel).addProcessItem(testFile2); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + STEP("5. Verify that U2 doesn't have access to te documents attached to the task using FTP"); + ftpProtocol.authenticateUser(testUser2) + .usingResource(testFile1).assertThat().hasReplyCode(FTPReply.FILE_UNAVAILABLE).and().assertThat().doesNotExistInFtp() + .usingResource(testFile2).assertThat().hasReplyCode(FTPReply.FILE_UNAVAILABLE).and().assertThat().doesNotExistInFtp(); + } + + /** + * Scenario 53 + * 1. Using CMIS create 2 test users: u1 and u2 + * 2. U1 creates a moderated site using CMIS + * 3. U1 creates 2 documents in his site using WebDAV + * 4. U1 creates a new task with the documents created above and assigns the task to U2 using REST + * 5. Verify that U2 doesn't have access to te documents attached to the task using WebDav + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }, expectedExceptionsMessageRegExp = "^Access is denied.$") + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.WORKFLOW }, executionType = ExecutionType.REGRESSION, + description = "Verify user is not able to access files from a moderated site, even if they are attached to a task assigned to him.") + public void assigneeCantAccessFilesFromModeratedSiteIfHeIsNotAMember() throws Exception + { + STEP("1. Using CMIS create 2 test users: u1 and u2"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + + STEP("2. U1 creates a moderated site using CMIS"); + moderatedSite = dataSite.usingUser(testUser1).createModeratedRandomSite(); + + STEP("3. U1 creates 2 documents in his site using WebDAV"); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file1 content"); + testFile2 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file2 content"); + webDavProtocol.authenticateUser(testUser1).usingSite(moderatedSite) + .createFile(testFile1) + .assertThat().existsInWebdav() + .assertThat().existsInRepo() + .createFile(testFile2) + .assertThat().existsInWebdav() + .assertThat().existsInRepo(); + + STEP("4. U1 creates a new task with the documents created above and assigns the task to U2 using REST"); + processModel = restAPI.authenticateUser(testUser1).withWorkflowAPI() + .addProcess("activitiAdhoc", testUser2, false, CMISUtil.Priority.Normal); + restAPI.withWorkflowAPI().usingProcess(processModel).addProcessItem(testFile1); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + restAPI.withWorkflowAPI().usingProcess(processModel).addProcessItem(testFile2); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + STEP("5. Verify that U2 doesn't have access to te documents attached to the task using WebDav"); + webDavProtocol.authenticateUser(testUser2) + .usingResource(testFile1).assertThat().doesNotExistInWebdav() + .usingResource(testFile2).assertThat().doesNotExistInWebdav(); + } + + /** + * Scenario 54 + * 1. Using CMIS create 2 test users: u1 and u2 + * 2. U1 creates a public site using CMIS + * 3. U1 creates 2 documents in his site using CMIS + * 4. U1 creates a new task with the documents created above and assigns the task to U2 using REST + * 5. Verify that U2 have access to te documents attached to the task using WebDAV + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.WORKFLOW }, executionType = ExecutionType.REGRESSION, + description = "Verify user is able to access files from a public site, even if they are attached to a task assigned to him.") + public void assigneeCanAccessFilesFromPublicSiteIfHeIsNotAMember() throws Exception + { + STEP("1. Using CMIS create 2 test users: u1 and u2"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + + STEP("2. U1 creates a public site using CMIS"); + publicSite = dataSite.usingUser(testUser1).createPublicRandomSite(); + + STEP("3. U1 creates 2 documents in his site using CMIS"); + testFile1 = FileModel.getRandomFileModel(FileType.MSWORD, "file1 content"); + testFile2 = FileModel.getRandomFileModel(FileType.MSWORD, "file2 content"); + cmisAPI.authenticateUser(testUser1).usingSite(publicSite) + .createFile(testFile1) + .assertThat().existsInRepo() + .usingSite(publicSite).createFile(testFile2) + .assertThat().existsInRepo(); + + STEP("4. U1 creates a new task with the documents created above and assigns the task to U2 using REST"); + processModel = restAPI.authenticateUser(testUser1).withWorkflowAPI() + .addProcess("activitiAdhoc", testUser2, false, CMISUtil.Priority.Normal); + testFile1.setNodeRef(dataContent.usingResource(testFile1).getNodeRef()); + restAPI.withWorkflowAPI().usingProcess(processModel).addProcessItem(testFile1); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + testFile2.setNodeRef(dataContent.usingResource(testFile2).getNodeRef()); + restAPI.withWorkflowAPI().usingProcess(processModel).addProcessItem(testFile2); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + STEP("5. Verify that U2 have access to te documents attached to the task using WebDAV"); + webDavProtocol.authenticateUser(testUser2) + .usingSite(publicSite).assertThat().hasFiles(testFile1, testFile2); + } + + /** + * Scenario 55 + * 1. Using CMIS create 2 test users: u1 and u2 + * 2. U1 creates 2 documents in User Home with CMIS + * 3. U1 creates a new task with the documents created above and assigns the task to U2 using REST + * 4. Verify that U2 doesn't have access to te documents attached to the task using CMIS + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }, expectedExceptions = {CmisPermissionDeniedException.class, CmisUnauthorizedException.class}) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.WORKFLOW }, executionType = ExecutionType.REGRESSION, + description = "Verify user is not able to access files from another user User Home repo, even if they are attached to a task assigned to him.") + public void assigneeCantAccessFilesFromAnotherUserHome() throws Exception + { + STEP("1. Using CMIS create 2 test users: u1 and u2"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + + STEP("2. U1 creates 2 documents in User Home with CMIS"); + testFile1 = FileModel.getRandomFileModel(FileType.MSWORD, "file1 content"); + testFile2 = FileModel.getRandomFileModel(FileType.MSWORD, "file2 content"); + + cmisAPI.authenticateUser(testUser1).usingUserHome() + .createFile(testFile1) + .assertThat().existsInRepo() + .createFile(testFile2) + .assertThat().existsInRepo(); + + STEP("3. U1 creates a new task with the documents created above and assigns the task to U2 using REST"); + processModel = restAPI.authenticateUser(testUser1).withWorkflowAPI() + .addProcess("activitiAdhoc", testUser2, false, CMISUtil.Priority.Normal); + restAPI.withWorkflowAPI().usingProcess(processModel).addProcessItem(testFile1); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + restAPI.withWorkflowAPI().usingProcess(processModel).addProcessItem(testFile2); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + STEP("4. Verify that U2 doesn't have access to te documents attached to the task using CMIS"); + cmisAPI.authenticateUser(testUser2) + .usingResource(testFile1).assertThat().doesNotExistInRepo(); + } + + /** + * Scenario 56 + * 1. Using CMIS create 2 test users: u1 and u2 + * 2. U1 creates document1 in a public site using CMIS + * 3. U2 is added to that public site with manager role using REST + * 4. U2 opens the document and renames it to document2 using WebDAV + * 5. Verify that U1 can't delete anymore document1 using FTP + * 6. U1 deletes document2 using WebDAV + * 7. Verify U2 can't update document2 using WebDAV + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, + description = "Check that user can't delete/update a file that is renamed/deleted by another user.") + public void deleteFileAfterItIsRenamedByAnotherUser() throws Exception + { + STEP("1. Using CMIS create 2 test users: u1 and u2"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + + STEP("2. U1 creates document1 in a public site using CMIS"); + publicSite = dataSite.usingUser(testUser1).createPublicRandomSite(); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file1 content"); + cmisAPI.authenticateUser(testUser1).usingSite(publicSite) + .createFile(testFile1).assertThat().existsInRepo(); + + STEP("3. U2 is added to that public site with manager role using REST"); + testUser2.setUserRole(UserRole.SiteManager); + restAPI.authenticateUser(testUser1).withCoreAPI() + .usingSite(publicSite).addPerson(testUser2); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + STEP("4. U2 opens the document and renames it to document2 using WebDAV"); + FileModel oldFile = new FileModel(testFile1); + webDavProtocol.authenticateUser(testUser2) + .usingResource(testFile1).rename("new" + testFile1.getName()) + .assertThat().existsInRepo(); + + STEP("5. Verify that U1 can't delete anymore document1 using FTP"); + ftpProtocol.authenticateUser(testUser1) + .usingResource(oldFile).delete() + .assertThat().hasReplyCode(550); + + STEP("6. U1 deletes document2 using WebDAV"); + webDavProtocol.authenticateUser(testUser1) + .usingResource(testFile1).delete() + .assertThat().doesNotExistInWebdav() + .assertThat().doesNotExistInRepo(); + + STEP("7. Verify U2 can't update document2 using WebDAV"); + webDavProtocol.authenticateUser(testUser2) + .usingResource(testFile1).update("file2 content") + .assertThat().hasStatus(404); + } + + /** + * Scenario 57 + * 1. Using CMIS create 2 test users: u1 and u2 + * 2. U1 creates document1 in a public site using FTP + * 3. U2 is added to that public site with manager role using REST + * 4. U1 adds comment to document1 using REST + * 5. U2 gets document1 comments using REST + * 6. U1 renames document1 using CMIS + * 7. U2 deletes comment using REST + * 8. Verify U1 cannot get comment using REST + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, + description = "Check that user can't get a comment that is deleted by another user.") + public void getCommentAfterItIsDeleted() throws Exception + { + STEP("1. Using CMIS create 2 test users: u1 and u2"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + + STEP("2. U1 creates document1 in a public site using FTP"); + publicSite = dataSite.usingUser(testUser1).createPublicRandomSite(); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file1 content"); + ftpProtocol.authenticateUser(testUser1).usingSite(publicSite).createFile(testFile1).assertThat().existsInRepo(); + + STEP("3. U2 is added to that public site with manager role using REST"); + testUser2.setUserRole(UserRole.SiteManager); + restAPI.authenticateUser(testUser1).withCoreAPI() + .usingSite(publicSite).addPerson(testUser2); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + STEP("4. U1 adds comment to document1 using REST"); + RestCommentModel user1Comment = restAPI.authenticateUser(testUser1).withCoreAPI().usingResource(testFile1).addComment("user1 comment"); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + STEP("5. U2 gets document1 comments using REST"); + restAPI.authenticateUser(testUser2).withCoreAPI().usingResource(testFile1).getNodeComments() + .assertThat().entriesListContains("content", "user1 comment"); + + STEP("6. U1 renames document1 using CMIS"); + cmisAPI.authenticateUser(testUser1).usingResource(testFile1).rename("new" + testFile1.getName()) + .assertThat().existsInRepo() + .assertThat().contentPropertyHasValue("cmis:name", "new" + testFile1.getName()) + .usingResource(testFile1).assertThat().doesNotExistInRepo(); + + STEP("7. U2 deletes comment using REST"); + restAPI.withCoreAPI().usingResource(testFile1).deleteComment(user1Comment); + restAPI.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + STEP("8. Verify U1 cannot get comment using REST"); + restAPI.authenticateUser(testUser1).withCoreAPI().usingResource(testFile1).getNodeComments() + .assertThat().entriesListIsEmpty(); + } + + /** + * Scenario 59 + * 1. Using CMIS create one test user: u1 + * 2. U1 creates a public site using CMIS + * 3. Admin creates a folder with a document (doc1.txt) in the public site using WebDAV + * 4. Admin renames document1 (doc1-edited.txt) using WebDAV + * 5. U1 tries to move doc1.txt to another location using IMAP + * 6. Verify that document is not moved (catch Exceptions) + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }, expectedExceptions = MessagingException.class) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, + description = "Verify user is not able to move a renamed file using its initial name.") + public void moveRenamedFileUsingInitialFilename() throws Exception + { + STEP("1. Using CMIS create one test user: u1"); + testUser1 = dataUser.createRandomTestUser(); + + STEP("2. U1 creates a public site using CMIS"); + publicSite = dataSite.usingUser(testUser1).createIMAPSite(); + + STEP("3. Admin creates a folder with a document (doc1.txt) in the public site using WebDav"); + parentFolder = FolderModel.getRandomFolderModel(); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file 1 content"); + + webDavProtocol.authenticateUser(admin) + .usingSite(publicSite).createFolder(parentFolder) + .assertThat().existsInWebdav() + .usingResource(parentFolder).createFile(testFile1) + .assertThat().existsInWebdav(); + + STEP("4. Admin renames document1 (doc1-edited.txt) using WebDAV"); + FileModel oldFile = new FileModel(testFile1); + webDavProtocol.authenticateUser(admin) + .usingResource(testFile1).rename("new" + testFile1.getName()) + .assertThat().existsInRepo(); + + STEP("5. U1 tries to move doc1.txt to another location using IMAP"); + FolderModel destination = new FolderModel(Utility.buildPath("Sites", publicSite.getId(), "documentLibrary")); + destination.setProtocolLocation(imapProtocol.authenticateUser(testUser1).usingSite(publicSite).getLastResourceWithoutPrefix()); + imapProtocol.usingResource(oldFile).moveMessageTo(destination); + } + + /** + * Scenario 61 + * 1. Using CMIS create an user and a site. + * 2. Using FTP create two folders. + * 3. Using CMIS create documents in folder1: a-childDoc1, childDoc11, child21. + * 4. Using CMIS create documents in folder2: childDoc112, childDoc2, achild2. + * 5. Using IMAP client flag content 'childDoc112'. + * 6. Using IMAP find documents after search term 'child'. + * 7. Using IMAP find documents after search term '.*child2.*'. + * 8. Using IMAP find documents after search term 'childa'. No results should be displayed. + * 9. Using IMAP find documents after search term 'child*2'. + * 10. Using IMAP verify that 'childDoc112' is flagged. + * + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL}) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, + description = "Find files and flag files.") + public void findFilesAndFlagFiles() throws Exception + { + STEP("1. Using CMIS create an user and a site."); + UserModel testUser = dataUser.createRandomTestUser(); + SiteModel testSitePublic = dataSite.usingUser(testUser).createIMAPSite(); + + STEP("2. Using FTP create two folders."); + FolderModel folder1 = FolderModel.getRandomFolderModel(); + FolderModel folder2 = FolderModel.getRandomFolderModel(); + + ftpProtocol.authenticateUser(testUser).usingSite(testSitePublic).createFolder(folder1).and().createFolder(folder2); + + STEP("3. Using CMIS create documents in folder1: a-childDoc1, childDoc11, child21."); + + FileModel file11 = dataContent.usingUser(testUser).usingSite(testSitePublic).usingResource(folder1) + .createContent(new FileModel("a-childDoc1", FileType.TEXT_PLAIN, "content")); + FileModel file12 = dataContent.usingUser(testUser).usingSite(testSitePublic).usingResource(folder1) + .createContent(new FileModel("childDoc11", FileType.TEXT_PLAIN, "content")); + FileModel file13 = dataContent.usingUser(testUser).usingSite(testSitePublic).usingResource(folder1) + .createContent(new FileModel("child21", FileType.TEXT_PLAIN, "content")); + + STEP("4. Using CMIS create documents in folder2: childDoc112, childDoc2, achild2."); + + FileModel file21 = dataContent.usingUser(testUser).usingSite(testSitePublic).usingResource(folder2) + .createContent(new FileModel("childDoc112", FileType.TEXT_PLAIN, "content")); + FileModel file22 = dataContent.usingUser(testUser).usingSite(testSitePublic).usingResource(folder2) + .createContent(new FileModel("childDoc2", FileType.TEXT_PLAIN, "content")); + FileModel file23 = dataContent.usingUser(testUser).usingSite(testSitePublic).usingResource(folder2) + .createContent(new FileModel("achild2", FileType.TEXT_PLAIN, "content")); + + STEP("5. Using IMAP client flag content 'childDoc112'."); + imapProtocol.authenticateUser(testUser).usingResource(file21).withMessage().setFlags(Flags.Flag.ANSWERED, Flags.Flag.SEEN).updateFlags(); + + STEP("6. Using IMAP find documents after search term 'child'."); + imapProtocol.usingResource(folder1).searchSubjectFor("child") + .assertThat().resultsContainMessage(file11,file12,file13) + .usingResource(folder2).searchSubjectFor("child") + .assertThat().resultsContainMessage(file21,file22,file23); + + STEP("7. Using IMAP find documents after search term '.*child2.*'."); + imapProtocol.usingResource(folder2).searchSubjectWithWildcardsFor(".*child2.*") + .assertThat().resultsContainMessage(file23) + .assertThat().resultsDoNotContainMessage(file21,file22); + + STEP("8. Using IMAP find documents after search term 'childa'. No results should be displayed."); + imapProtocol.usingResource(folder1).searchSubjectFor("childa") + .assertThat().resultsDoNotContainMessage(file11,file12,file13) + .usingResource(folder2).searchSubjectFor("childa") + .assertThat().resultsDoNotContainMessage(file21,file22,file23); + + STEP("9. Using IMAP find documents after search term 'child*2'."); + imapProtocol.usingResource(folder1).searchSubjectWithWildcardsFor("child.*2.*") + .assertThat().resultsContainMessage(file13) + .assertThat().resultsDoNotContainMessage(file11,file12) + .usingResource(folder2).searchSubjectWithWildcardsFor("child.*2.*") + .assertThat().resultsContainMessage(file21,file22) + .assertThat().resultsDoNotContainMessage(file23); + + STEP("10. Using IMAP verify that 'childDoc112' is flagged."); + imapProtocol.usingResource(file21) + .assertThat().messageContainsFlags(Flags.Flag.ANSWERED, Flags.Flag.SEEN); + } + + /** + * Scenario 62 + * 1. Using CMIS create two test users: u1 and userToAssign + * 2. U1 creates a public site using CMIS: publicSite + * 3. U1 creates a document in public site using WebDAV: documentTest + * 4. U1 creates a new task with the documents created above and assigns the task to userToAssign using REST + * 5. Verify that userToAssign receives the task using REST + * 6. U1 adds items to task using REST + * 7. U1 removes items from task using REST + * 8. userToAssign gets the list of the updated items using REST + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.WORKFLOW }, executionType = ExecutionType.REGRESSION, + description = "Verify assigner user is able to add and remove items from task.") + public void assignerIsAbleToAddAndRemoveItemsFromTask() throws Exception + { + STEP("1. Using CMIS create two test users: u1 and userToAssign"); + testUser1 = dataUser.createRandomTestUser(); + UserModel userToAssign = dataUser.createRandomTestUser(); + + STEP("2. U1 creates a public site using CMIS: publicSite"); + publicSite = dataSite.usingUser(testUser1).createPublicRandomSite(); + + STEP("3. U1 creates a document in public site using WebDAV: documentTest"); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file1 content"); + webDavProtocol.authenticateUser(testUser1).usingSite(publicSite) + .createFile(testFile1) + .assertThat().webDavWrapper() + .assertThat().existsInRepo(); + + STEP("4. U1 creates a new task with the documents created above and assigns the task to userToAssign using REST"); + processModel = restAPI.authenticateUser(testUser1).withWorkflowAPI() + .addProcess("activitiAdhoc", userToAssign, false, CMISUtil.Priority.Normal); + processTasks = restAPI.authenticateUser(userToAssign).withWorkflowAPI() + .usingProcess(processModel) + .getProcessTasks(); + restAPI.withWorkflowAPI().usingTask(processTasks.getTaskModelByAssignee(userToAssign)) + .addTaskItem(testFile1); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + STEP("5. Verify that userToAssign receives the task using REST"); + processTasks = restAPI.authenticateUser(userToAssign).withWorkflowAPI().usingProcess(processModel) + .getProcessTasks(); + processTasks.assertThat().entriesListContains("assignee", userToAssign.getUsername()) + .and().entriesListContains("state", "claimed") + .and().paginationField("count").is("1"); + + STEP("6. U1 adds items to task using REST"); + testFile2 = dataContent.usingSite(publicSite).createContent(CMISUtil.DocumentType.HTML); + FileModel testFile3 = dataContent.usingSite(publicSite).createContent(CMISUtil.DocumentType.PDF); + taskItems = restAPI.authenticateUser(testUser1).withWorkflowAPI() + .usingTask(processTasks.getTaskModelByAssignee(userToAssign)) + .addTaskItems(testFile2, testFile3); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + STEP("7. U1 removes items from task using REST"); + restAPI.authenticateUser(testUser1).withWorkflowAPI().usingTask(processTasks.getTaskModelByAssignee(userToAssign)) + .deleteTaskItem(taskItems.getEntries().get(0).onModel()); + restAPI.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + STEP("8. userToAssign gets the list of the updated items using REST"); + restAPI.authenticateUser(userToAssign).withWorkflowAPI().usingTask(processTasks.getTaskModelByAssignee(userToAssign)) + .getTaskItems() + .assertThat().entriesListContains("name", testFile1.getName()) + .assertThat().entriesListContains("name", testFile3.getName()) + .and().paginationField("count").is("2"); + } + + /** + * Scenario 63 + * 1. Using CMIS create two test users: u1 and userToAssign + * 2. U1 creates a public site using CMIS: publicSite + * 3. U1 creates a document in public site using webDAV: documentTest + * 4. U1 creates a new task with the documents created above and assigns the task to userToAssign using REST + * 5. Verify that userToAssign receives the task using REST + * 6. userToAssign adds items to task using REST + * 7. userToAssign removes items from task using REST + * 8. u1 gets the list of the updated items using REST + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.WORKFLOW }, executionType = ExecutionType.REGRESSION, + description = "Verify assignee user is to add and remove items from task.") + public void assigneeIsAbleToAddAndRemoveItemsFromTask() throws Exception + { + STEP("1. Using CMIS create two test users: u1 and userToAssign"); + testUser1 = dataUser.createRandomTestUser(); + UserModel userToAssign = dataUser.createRandomTestUser(); + + STEP("2. U1 creates a public site using CMIS: publicSite"); + publicSite = dataSite.usingUser(testUser1).createPublicRandomSite(); + + STEP("3. U1 creates a document in public site using webDAV: documentTest"); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file1 content"); + webDavProtocol.authenticateUser(testUser1).usingSite(publicSite) + .createFile(testFile1) + .assertThat().existsInWebdav() + .assertThat().existsInRepo(); + + STEP("4. U1 creates a new task with the documents created above and assigns the task to userToAssign using REST"); + processModel = restAPI.authenticateUser(testUser1).withWorkflowAPI() + .addProcess("activitiAdhoc", userToAssign, false, CMISUtil.Priority.Normal); + processTasks = restAPI.authenticateUser(userToAssign).withWorkflowAPI() + .usingProcess(processModel) + .getProcessTasks(); + restAPI.withWorkflowAPI().usingTask(processTasks.getTaskModelByAssignee(userToAssign)) + .addTaskItem(testFile1); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + STEP("5. Verify that userToAssign receives the task using REST"); + processTasks = restAPI.authenticateUser(userToAssign).withWorkflowAPI().usingProcess(processModel) + .getProcessTasks(); + processTasks.assertThat().entriesListContains("assignee", userToAssign.getUsername()) + .and().entriesListContains("state", "claimed") + .and().paginationField("count").is("1"); + + STEP("6. userToAssign adds items to task using REST"); + testFile2 = dataContent.usingSite(publicSite).createContent(CMISUtil.DocumentType.HTML); + FileModel testFile3 = dataContent.usingSite(publicSite).createContent(CMISUtil.DocumentType.PDF); + + taskItems = restAPI.withWorkflowAPI().usingTask(processTasks.getTaskModelByAssignee(userToAssign)) + .addTaskItems(testFile2, testFile3); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + STEP("7. userToAssign removes items from task using REST"); + restAPI.withWorkflowAPI().usingTask(processTasks.getTaskModelByAssignee(userToAssign)) + .deleteTaskItem(taskItems.getEntries().get(1).onModel()); + restAPI.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + STEP("8. U1 gets the list of the updated items using REST"); + restAPI.authenticateUser(testUser1).withWorkflowAPI().usingTask(processTasks.getTaskModelByAssignee(userToAssign)) + .getTaskItems() + .assertThat().entriesListContains("name", testFile2.getName()) + .assertThat().entriesListContains("name", testFile1.getName()) + .and().paginationField("count").is("2"); + } + + /** + * Scenario 66 + * 1. Using CMIS create two test users: u1 and userToAssign + * 2. U1 creates a public site using CMIS: publicSite + * 3. U1 creates a document in public site using webDavProtocol: documentTest + * 4. U1 creates a new task with the documents created above and assigns the task to userToAssign using REST + * 5. Verify that userToAssign receives the task using REST + * 6. Status is changed by userToAssign using REST + * 7. U1 gets the modified values from the task using REST + * 8. userToAssign marks the task as 'Resolved' using REST + * 9. U1 receives the task using REST + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.WORKFLOW }, executionType = ExecutionType.REGRESSION, + description = "Verify assignee user is able to update task.") + public void assigneeIsAbleToUpdateTask() throws Exception + { + STEP("1. Using CMIS create two test users: u1 and userToAssign"); + testUser1 = dataUser.createRandomTestUser(); + userToAssign = dataUser.createRandomTestUser(); + + STEP("2. U1 creates a public site using CMIS: publicSite"); + publicSite = dataSite.usingUser(testUser1).createPublicRandomSite(); + + STEP("3. U1 creates a document in public site using webDavProtocol: documentTest"); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file1 content"); + webDavProtocol.authenticateUser(testUser1).usingSite(publicSite).createFile(testFile1).assertThat().existsInRepo(); + + STEP("4. U1 creates a new task with the documents created above and assigns the task to userToAssign using REST"); + processModel = restAPI.authenticateUser(testUser1).withWorkflowAPI() + .addProcess("activitiAdhoc", userToAssign, false, CMISUtil.Priority.Normal); + restAPI.withWorkflowAPI().usingProcess(processModel).addProcessItem(testFile1); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + STEP("5. Verify that userToAssign receives the task using REST"); + taskModel = restAPI.authenticateUser(userToAssign).withWorkflowAPI().usingProcess(processModel).getProcessTasks() + .getTaskModelByAssignee(userToAssign) + .assertThat().field("assignee").is(userToAssign.getUsername()); + + STEP("6. Status is changed by userToAssign using REST"); + restTaskModel = restAPI.authenticateUser(userToAssign).withParams("select=state").withWorkflowAPI().usingTask(taskModel) + .updateTask("claimed"); + restAPI.assertStatusCodeIs(HttpStatus.OK); + + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("claimed"); + + STEP("7. U1 gets the modified values from the task using REST"); + restAPI.authenticateUser(testUser1).withWorkflowAPI().usingTask(restTaskModel).getTask() + .assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("claimed"); + + STEP("8. userToAssign marks the task as 'Resolved' using REST"); + restTaskModel = restAPI.authenticateUser(userToAssign).withParams("select=state").withWorkflowAPI().usingTask(taskModel) + .updateTask("completed"); + restAPI.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("completed") + .and().field("assignee").is(userToAssign.getUsername()); + + STEP("9. U1 receives the task using REST"); + restAPI.authenticateUser(testUser1).withWorkflowAPI().usingTask(restTaskModel).getTask() + .assertThat().field("state").is("completed"); + } + + /** + * Scenario 67 + * 1. Using CMIS create two test users: U1 and userToAssign + * 2. U1 creates a public site using CMIS: publicSite + * 3. U1 creates a document in public site using webDavProtocol: documentTest + * 4. U1 creates a new task with the documents created above and assigns the task to userToAssign using REST + * 5. Verify that userToAssign receives the task using REST + * 6. Status is changed by U1 using REST + * 7. userToAssign gets the modified values from the task using REST + * 8. userToAssign marks the task as 'Resolved' using REST + * 9. U1 receives the task using REST + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.WORKFLOW }, executionType = ExecutionType.REGRESSION, + description = "Verify assigner user is able to update task.") + public void assignerIsAbleToUpdateTask() throws Exception + { + STEP("1. Using CMIS create two test users: u1 and userToAssign"); + testUser1 = dataUser.createRandomTestUser(); + userToAssign = dataUser.createRandomTestUser(); + + STEP("2. U1 creates a public site using CMIS: publicSite"); + publicSite = dataSite.usingUser(testUser1).createPublicRandomSite(); + + STEP("3. U1 creates a document in public site using webDavProtocol: documentTest"); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file1 content"); + webDavProtocol.authenticateUser(testUser1).usingSite(publicSite).createFile(testFile1).assertThat().existsInRepo(); + + STEP("4. U1 creates a new task with the documents created above and assigns the task to userToAssign using REST"); + processModel = restAPI.authenticateUser(testUser1).withWorkflowAPI() + .addProcess("activitiAdhoc", userToAssign, false, CMISUtil.Priority.Normal); + restAPI.withWorkflowAPI().usingProcess(processModel).addProcessItem(testFile1); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + STEP("5. Verify that userToAssign receives the task using REST"); + taskModel = restAPI.authenticateUser(userToAssign).withWorkflowAPI().usingProcess(processModel).getProcessTasks().getEntryByIndex(0) + .assertThat().field("assignee").is(userToAssign.getUsername()); + + STEP("6. Status is changed by U1 using REST"); + JsonObject inputJson = JsonBodyGenerator.defineJSON().add("state", "delegated").add("assignee", userToAssign.getUsername()).build(); + restTaskModel = restAPI.authenticateUser(testUser1).withParams("select=state,assignee").withWorkflowAPI().usingTask(taskModel) + .updateTask(inputJson); + restAPI.assertStatusCodeIs(HttpStatus.OK); + + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("delegated") + .and().field("owner").is(testUser1.getUsername()) + .and().field("assignee").is(userToAssign.getUsername()); + + STEP("7. userToAssign gets the modified values from the task using REST"); + restAPI.authenticateUser(userToAssign).withWorkflowAPI().usingProcess(processModel).getProcessTasks().getTaskModelByAssignee(userToAssign) + .assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("delegated"); + + STEP("8. userToAssign marks the task as 'Resolved' using REST"); + restTaskModel = restAPI.withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("resolved"); + restAPI.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("resolved"); + + STEP("9. U1 receives the task using REST"); + restAPI.authenticateUser(testUser1).withWorkflowAPI().usingProcess(processModel).getProcessTasks().getEntryByIndex(0) + .assertThat().field("state").is("resolved") + .assertThat().field("id").is(taskModel.getId()) + .assertThat().field("assignee").is(testUser1.getUsername()); + } + + /** + * Scenario 68 + * 1. Using CMIS create two test users: u1 and userToAssign + * 2. U1 creates a public site using CMIS: publicSite + * 3. U1 creates a document in public site using webDavProtocol: documentTest + * 4. U1 creates a new task with the documents created above and assigns the task to userToAssign using REST + * 5. Verify that userToAssign receives the task using REST + * 6. U1 cancels workflow using REST + * 7. Verify task is no longer present for userToAssign + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.WORKFLOW }, executionType = ExecutionType.REGRESSION, + description = "Verify assigner user is able to cancel an workflow.") + public void assignerIsAbleToCancelWorkflow() throws Exception + { + STEP("1. Using CMIS create two test users: u1 and userToAssign"); + testUser1 = dataUser.createRandomTestUser(); + userToAssign = dataUser.createRandomTestUser(); + + STEP("2. U1 creates a public site using CMIS: publicSite"); + publicSite = dataSite.usingUser(testUser1).createPublicRandomSite(); + + STEP("3. U1 creates a document in public site using webDavProtocol: documentTest"); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file1 content"); + webDavProtocol.authenticateUser(testUser1).usingSite(publicSite).createFile(testFile1).assertThat().existsInRepo(); + + STEP("4. U1 creates a new task with the documents created above and assigns the task to userToAssign using REST"); + processModel = restAPI.authenticateUser(testUser1).withWorkflowAPI().addProcess("activitiAdhoc", userToAssign, false, CMISUtil.Priority.Normal); + restAPI.withWorkflowAPI().usingProcess(processModel).addProcessItem(testFile1); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + restAPI.withWorkflowAPI().getProcesses() +// due changing to java 11 the id changed +// .assertThat().entriesListContains("processDefinitionId", WorkflowService.WorkflowType.NewTask.getId()) + .assertThat().entriesListContains("startActivityId", "start") + .and().paginationField("count").is("1"); + + STEP("5. Verify that userToAssign receives the task using REST"); + restAPI.authenticateUser(userToAssign).withWorkflowAPI().usingProcess(processModel).getProcessTasks() + .getTaskModelByAssignee(userToAssign) + .assertThat().field("assignee").is(userToAssign.getUsername()); + + STEP("6. U1 cancels workflow using REST"); + Assert.assertTrue(dataWorkflow.usingUser(testUser1).cancelProcess(processModel), "User is able to cancel the workflow"); + + restAPI.withWorkflowAPI().getProcesses().assertThat() + .entriesListDoesNotContain("id", processModel.getId()) + .and().paginationField("count").is("0"); + + STEP("7. Verify task is no longer present for userToAssign: MyTasks"); + restAPI.authenticateUser(userToAssign).withWorkflowAPI().getProcesses().assertThat() + .entriesListDoesNotContain("id", processModel.getId()); + } + + /** + * Scenario 69 + * 1. Using CMIS create two test users: u1 and userToAssign + * 2. U1 creates a public site using CMIS: publicSite + * 3. U1 creates a document in public site using webDavProtocol: documentTest + * 4. U1 creates a new task with the documents created above and assigns the task to userToAssign using REST + * 5. Verify that userToAssign receives the task using REST + * 6. userToAssign is not able to cancel workflow using REST + * 7. Verify U1 still has the workflow + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.WORKFLOW }, executionType = ExecutionType.REGRESSION, + description = "Verify assignee user is able to cancel an workflow.") + public void assigneeIsNotAbleToCancelWorkflow() throws Exception + { + STEP("1. Using CMIS create two test users: u1 and userToAssign"); + testUser1 = dataUser.createRandomTestUser(); + userToAssign = dataUser.createRandomTestUser(); + + STEP("2. U1 creates a public site using CMIS: publicSite"); + publicSite = dataSite.usingUser(testUser1).createPublicRandomSite(); + + STEP("3. U1 creates a document in public site using webDavProtocol: documentTest"); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file1 content"); + webDavProtocol.authenticateUser(testUser1).usingSite(publicSite).createFile(testFile1).assertThat().existsInRepo(); + + STEP("4. U1 creates a new task with the documents created above and assigns the task to userToAssign using REST"); + processModel = restAPI.authenticateUser(testUser1).withWorkflowAPI().addProcess("activitiAdhoc", userToAssign, false, CMISUtil.Priority.Normal); + restAPI.withWorkflowAPI().usingProcess(processModel).addProcessItem(testFile1); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + restAPI.withWorkflowAPI().getProcesses() + .assertThat().entriesListContains("startActivityId", "start") + .and().paginationField("count").is("1"); + + STEP("5. Verify that userToAssign receives the task using REST"); + restAPI.authenticateUser(userToAssign).withWorkflowAPI().usingProcess(processModel).getProcessTasks() + .getTaskModelByAssignee(userToAssign) + .assertThat().field("assignee").is(userToAssign.getUsername()); + + STEP("6. userToAssign is not able to cancel workflow using REST"); + Assert.assertFalse(dataWorkflow.usingUser(userToAssign).cancelProcess(processModel), "User is unable to cancel workflow."); + + restAPI.withWorkflowAPI().getProcesses().assertThat() + .entriesListContains("id", processModel.getId()) + .and().paginationField("count").is("1"); + + STEP("7. Verify U1 still has the workflow"); + restAPI.authenticateUser(userToAssign).withWorkflowAPI().getProcesses().assertThat() + .entriesListContains("id", processModel.getId()) + .and().paginationField("count").is("1"); + } + + /** + * Scenario 70 + * 1. Using CMIS create two test users: u1 and userToAssign + * 2. U1 creates a public site using CMIS: publicSite + * 3. U1 creates a document in public site using webDavProtocol: documentTest + * 4. U1 creates a new task with the documents created above and assigns the task to userToAssign using REST + * 5. Verify that userToAssign receives the task using REST + * 6. U1 renames the document using webDAV + * 7. Verify renamed document with users: U1 and userToAssign using RestAPI + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.WORKFLOW }, executionType = ExecutionType.REGRESSION, + description = "Verify assigner user is able to rename items from a task.") + public void assignerIsAbleToRenameItemsFromTask() throws Exception + { + STEP("1. Using CMIS create two test users: u1 and userToAssign"); + testUser1 = dataUser.createRandomTestUser(); + userToAssign = dataUser.createRandomTestUser(); + + STEP("2. U1 creates a public site using CMIS: publicSite"); + publicSite = dataSite.usingUser(testUser1).createPublicRandomSite(); + + STEP("3. U1 creates a document in public site using webDavProtocol: documentTest"); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file1 content"); + webDavProtocol.authenticateUser(testUser1).usingSite(publicSite).createFile(testFile1).assertThat().existsInRepo(); + + STEP("4. U1 creates a new task with the documents created above and assigns the task to userToAssign using REST"); + processModel = restAPI.authenticateUser(testUser1).withWorkflowAPI() + .addProcess("activitiAdhoc", userToAssign, false, CMISUtil.Priority.Normal); + restAPI.withWorkflowAPI().usingProcess(processModel).addProcessItem(testFile1); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + STEP("5. Verify that userToAssign receives the task using REST"); + taskModel = restAPI.authenticateUser(userToAssign).withWorkflowAPI().usingProcess(processModel).getProcessTasks() + .getTaskModelByAssignee(userToAssign) + .assertThat().field("assignee").is(userToAssign.getUsername()); + + STEP("6. U1 renames the document using webDAV"); + FileModel originalFileModel = new FileModel(testFile1); + webDavProtocol.authenticateUser(testUser1).usingSite(publicSite) + .usingResource(testFile1).and().assertThat().existsInRepo() + .when().rename(testFile1.getName() + "-edit").assertThat().existsInRepo() + .and().assertThat().hasStatus(org.apache.commons.httpclient.HttpStatus.SC_CREATED) + .then().usingSite(publicSite).usingResource(originalFileModel).assertThat().doesNotExistInRepo(); + + STEP("7. Verify renamed document with users: U1 and userToAssign using RestAPI"); + processTasks = restAPI.authenticateUser(testUser1).withWorkflowAPI().usingProcess(processModel) + .getProcessTasks(); + restAPI.withWorkflowAPI().usingTask(processTasks.getTaskModelByAssignee(userToAssign)) + .getTaskItems() + .assertThat().entriesListContains("name", testFile1.getName()+ "-edit") + .assertThat().entriesListDoesNotContain("name", originalFileModel.getName()) + .and().paginationField("count").is("1"); + + processTasks = restAPI.authenticateUser(userToAssign).withWorkflowAPI().usingProcess(processModel) + .getProcessTasks(); + restAPI.authenticateUser(userToAssign).withWorkflowAPI().usingTask(processTasks.getTaskModelByAssignee(userToAssign)) + .getTaskItems() + .assertThat().entriesListContains("name", testFile1.getName()+ "-edit") + .assertThat().entriesListDoesNotContain("name", originalFileModel.getName()) + .and().paginationField("count").is("1"); + } + + /** + * Scenario 71 + * 1. Using CMIS create two test users: u1 and userToAssign + * 2. U1 creates a public site using CMIS: publicSite + * 3. U1 creates a document in public site using webDavProtocol: documentTest + * 4. U1 creates a new task with the documents created above and assigns the task to userToAssign using REST + * 5. Verify that userToAssign receives the task using REST + * 6. U1 deletes the document using webDAV + * 7. Verify no documents are present with users: U1 and userToAssign using RestAPI + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.WORKFLOW }, executionType = ExecutionType.REGRESSION, + description = "Verify assigner user is able to delete items from a task.") + public void assignerIsAbleToDeleteItemsFromTask() throws Exception + { + STEP("1. Using CMIS create two test users: u1 and userToAssign"); + testUser1 = dataUser.createRandomTestUser(); + userToAssign = dataUser.createRandomTestUser(); + + STEP("2. U1 creates a public site using CMIS: publicSite"); + publicSite = dataSite.usingUser(testUser1).createPublicRandomSite(); + + STEP("3. U1 creates a document in public site using webDavProtocol: documentTest"); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file1 content"); + webDavProtocol.authenticateUser(testUser1).usingSite(publicSite).createFile(testFile1).assertThat().existsInRepo(); + + STEP("4. U1 creates a new task with the documents created above and assigns the task to userToAssign using REST"); + processModel = restAPI.authenticateUser(testUser1).withWorkflowAPI() + .addProcess("activitiAdhoc", userToAssign, false, CMISUtil.Priority.Normal); + restAPI.withWorkflowAPI().usingProcess(processModel).addProcessItem(testFile1); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + STEP("5. Verify that userToAssign receives the task using REST"); + taskModel = restAPI.authenticateUser(userToAssign).withWorkflowAPI().usingProcess(processModel).getProcessTasks() + .getTaskModelByAssignee(userToAssign) + .assertThat().field("assignee").is(userToAssign.getUsername()); + + STEP("6. U1 deletes the document using webDAV"); + webDavProtocol.authenticateUser(testUser1).usingSite(publicSite) + .usingResource(testFile1).delete() + .assertThat().hasStatus(org.apache.commons.httpclient.HttpStatus.SC_OK) + .and().assertThat().doesNotExistInRepo() + .and().assertThat().doesNotExistInWebdav() + .and().assertThat().hasStatus(org.apache.commons.httpclient.HttpStatus.SC_NOT_FOUND); + + STEP("7. Verify no documents are present with users: U1 and userToAssign using RestAPI"); + processTasks = restAPI.authenticateUser(testUser1).withWorkflowAPI().usingProcess(processModel) + .getProcessTasks(); + restAPI.withWorkflowAPI().usingTask(processTasks.getTaskModelByAssignee(userToAssign)).getTaskItems().assertThat() + .entriesListDoesNotContain("name", testFile1.getName()).and() + .paginationField("count").is("0"); + + processTasks = restAPI.authenticateUser(userToAssign).withWorkflowAPI().usingProcess(processModel).getProcessTasks(); + restAPI.authenticateUser(userToAssign).withWorkflowAPI().usingTask(processTasks.getTaskModelByAssignee(userToAssign)).getTaskItems().assertThat() + .entriesListDoesNotContain("name", testFile1.getName()).and() + .paginationField("count").is("0"); + } + + + /** + * Scenario 72 + * 1. Using CMIS create 1 test user: u1 + * 2. U1 creates folder1 in a public site using IMAP + * 3. U1 creates file with special symbols in its name using FTP inside the public site + * 4. U1 adds some special characters in document content using CMIS + * 5. U1 renames document to a different name using special chars using FTP + * 6. U1 copy document to the folder created above using IMAP + * 7. U1 deletes document from initial location using CMIS + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, + description = "Verify user is able to create, rename, update content, delete a file with special symbols in its name.") + public void userIsAbleToDoCRUDActionsOnFileWithSpecialName() throws Exception + { + STEP("1. Using CMIS create 1 test user: u1"); + testUser1 = dataUser.createRandomTestUser(); + + STEP("2. U1 creates folder1 in a public site using IMAP"); + publicSite = dataSite.usingUser(testUser1).createIMAPSite(); + parentFolder = FolderModel.getRandomFolderModel(); + + imapProtocol.authenticateUser(testUser1) + .usingSite(publicSite).createFolder(parentFolder) + .assertThat().existsInImap().and() + .assertThat().existsInRepo(); + + STEP("3. U1 creates file with special symbols in its name using FTP inside the public site"); + String fileName = RandomData.getRandomAlphanumeric(); + testFile1 = new FileModel(fileName + "\ufeff\u6768\u6728\u91d1.doc"); + ftpProtocol.authenticateUser(testUser1) + .then().usingSite(publicSite) + .createFile(testFile1).and().assertThat().existsInRepo() + .and().assertThat().existsInFtp(); + + STEP("4. U1 adds some special characters in document content using CMIS"); + cmisAPI.authenticateUser(testUser1).usingResource(testFile1).update("!@#$%^&()-_+={}[].,") + .assertThat().contentIs("!@#$%^&()-_+={}[].,"); + + STEP("5. U1 renames document to a different name using special chars using FTP"); + ftpProtocol.usingResource(testFile1).rename(fileName + "!@#$%^&()-_+={}[].,") + .assertThat().existsInRepo(); + + testFile2 = new FileModel(testFile1); + STEP("6. U1 copy document to the folder created above using IMAP"); + imapProtocol.authenticateUser(testUser1).usingSite(publicSite) + .usingResource(testFile1) + .assertThat().existsInRepo() + .assertThat().existsInImap() + .copyMessageTo(parentFolder) + .assertThat().containsMessages(testFile1); + + STEP("7. U1 deletes document from initial location using CMIS"); + cmisAPI.usingResource(testFile2).delete().assertThat().doesNotExistInRepo() + .usingResource(parentFolder).assertThat().hasFiles(testFile1); + } + + /** + * Scenario 75 + * 1. Using CMIS create 3 test users: u1, u2 and u3 + * 2. U1 creates document1 in a public site using WebDAV + * 3. U1 adds U3 to his site as Site manager using REST + * 4. Check that U2 is not able to update document using FTP. + * 5. Check that U3 is able to update document using WebDAV. + * 6. U1 changes site visibility to moderated using REST + * 7. Check that U2 is not able to update document using FTP. + * 8. Check that U3 is able to update document WebDAV. + * 9. U1 changes site visibility to private using REST + * 10. Check that U2 is not able to update document using FTP. + * 11. Check that U3 is able to update document WebDAV. + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, + description = "Verify users ability to update files when site visibility is changed.") + public void updateFileByRegularUserAndSiteMemberWhenSiteVisibilityIsChanged() throws Exception + { + STEP("1. Using CMIS create 3 test users: u1, u2 and u3"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + UserModel testUser3 = dataUser.createRandomTestUser(); + + STEP("2. U1 creates document1 in a public site using WebDAV"); + publicSite = dataSite.usingUser(testUser1).createPublicRandomSite(); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file1 content"); + webDavProtocol.authenticateUser(testUser1) + .usingSite(publicSite).createFile(testFile1) + .assertThat().existsInRepo(); + + STEP("3. U1 adds U3 to his site as Site manager using REST"); + testUser3.setUserRole(UserRole.SiteManager); + restAPI.authenticateUser(testUser1).withCoreAPI() + .usingSite(publicSite).addPerson(testUser3); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + STEP("4. Check that U2 is able to update document using FTP."); + ftpProtocol.authenticateUser(testUser2).usingResource(testFile1).update("u2 update when site visibility is public") + .assertThat().contentIs("file1 content"); + + STEP("5. Check that U3 is able to update document using WebDav."); + webDavProtocol.authenticateUser(testUser3).usingResource(testFile1).update("u3 update when site visibility is public") + .assertThat().contentIs("u3 update when site visibility is public"); + + STEP("6. U1 changes site visibility to moderated using REST"); + dataSite.usingUser(testUser1).updateSiteVisibility(publicSite, Visibility.MODERATED); + + STEP("7. Check that U2 is not able to update document using FTP."); + ftpProtocol.authenticateUser(testUser2).usingResource(testFile1).update("u2 update when site visibility is moderated") + .assertThat().hasReplyCode(FTPReply.ACTION_ABORTED); + + STEP("8. Check that U3 is able to update document WebDAV."); + webDavProtocol.authenticateUser(testUser3).usingResource(testFile1).update("u3 update when site visibility is moderated") + .assertThat().contentIs("u3 update when site visibility is moderated"); + + STEP("9. U1 changes site visibility to private using REST"); + dataSite.usingUser(testUser1).updateSiteVisibility(publicSite, Visibility.PRIVATE); + + STEP("10. Check that U2 is not able to update document using FTP."); + ftpProtocol.authenticateUser(testUser2).usingResource(testFile1).update("u2 update when site visibility is private") + .assertThat().hasReplyCode(FTPReply.ACTION_ABORTED); + + STEP("11. Check that U3 is able to update document WebDAV."); + webDavProtocol.authenticateUser(testUser3).usingResource(testFile1).update("u3 update when site visibility is private") + .assertThat().contentIs("u3 update when site visibility is private"); + } + + /** + * Scenario 89 + * 1. Using CMIS create 2 test users: u1 and u2 + * 2. U1 creates document1 in a public site using FTP + * 3. U1 creates a New Task with the document created above and assigns it to U2 using REST + * 4. U2 updates the task as resolved using REST + * 5. U1 deletes the task process using REST. Assert that process is deleted successfully among with its tasks. + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.WORKFLOW }, executionType = ExecutionType.REGRESSION, + description = "Verify initiator is able to delete a process after its task is updated by assignee as resolved.") + public void deleteWorkflowByInitiator() throws Exception + { + STEP("1. Using CMIS create 2 test users: u1 and u2"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + + STEP("2. U1 creates document1 in a public site using FTP"); + publicSite = dataSite.usingUser(testUser1).createPublicRandomSite(); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file1 content"); + ftpProtocol.authenticateUser(testUser1).usingSite(publicSite).createFile(testFile1).assertThat().existsInRepo(); + + STEP("3. U1 creates a New Task with the document created above and assigns it to U2 using REST"); + processModel = restAPI.authenticateUser(testUser1).withWorkflowAPI() + .addProcess("activitiAdhoc", testUser2, false, CMISUtil.Priority.Normal); + restAPI.withWorkflowAPI().usingProcess(processModel).addProcessItem(testFile1); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + STEP("4. U2 updates the task as Done using REST"); + processTasks = restAPI.authenticateUser(testUser2).withWorkflowAPI().usingProcess(processModel).getProcessTasks(); + restAPI.assertStatusCodeIs(HttpStatus.OK); + + RestTaskModel processTask = processTasks.getTaskModelByAssignee(testUser2); + + restAPI.withParams("select=state").withWorkflowAPI().usingTask(processTask).updateTask("resolved"); + restAPI.assertStatusCodeIs(HttpStatus.OK); + + STEP("5. U1 deletes the task process using REST. Assert that process is deleted successfully among with its tasks."); + restAPI.authenticateUser(testUser1).withWorkflowAPI().usingProcess(processModel).deleteProcess(); + restAPI.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restAPI.withWorkflowAPI().getProcesses().assertThat().entriesListDoesNotContain("id", processModel.getId()); + restAPI.withWorkflowAPI().getTasks().assertThat().entriesListDoesNotContain("id", processTask.getId()); + } + + /** + * Scenario 90 + * 1. Using CMIS create 2 test users: u1 and u2 + * 2. U1 creates document1 in a public site using WebDAV + * 3. U1 creates a New Task with the document created above and assigns it to U2 using REST + * 4. U2 updates the task as resolved using REST + * 5. U1 updates the task as completed using REST + * 6. U2 deletes the task process using REST. Assert that process is not deleted. + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.WORKFLOW }, executionType = ExecutionType.REGRESSION, + description = "Verify assignee is not able to delete a process after its task is completed.") + public void deleteWorkflowByAssignee() throws Exception + { + STEP("1. Using CMIS create 2 test users: u1 and u2"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + + STEP("2. U1 creates document1 in a public site using WebDAV"); + publicSite = dataSite.usingUser(testUser1).createPublicRandomSite(); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file1 content"); + webDavProtocol.authenticateUser(testUser1).usingSite(publicSite).createFile(testFile1).assertThat().existsInRepo(); + + STEP("3. U1 creates a New Task with the document created above and assigns it to U2 using REST"); + processModel = restAPI.authenticateUser(testUser1).withWorkflowAPI() + .addProcess("activitiAdhoc", testUser2, false, CMISUtil.Priority.Normal); + restAPI.withWorkflowAPI().usingProcess(processModel).addProcessItem(testFile1); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + STEP("4. U2 updates the task as resolved using REST"); + processTasks = restAPI.authenticateUser(testUser2).withWorkflowAPI().usingProcess(processModel).getProcessTasks(); + restAPI.assertStatusCodeIs(HttpStatus.OK); + + RestTaskModel processTask = processTasks.getTaskModelByAssignee(testUser2); + + restAPI.withParams("select=state").withWorkflowAPI().usingTask(processTask).updateTask("resolved"); + restAPI.assertStatusCodeIs(HttpStatus.OK); + + STEP("5. U1 updates the task as completed using REST"); + restAPI.authenticateUser(testUser1).withParams("select=state").withWorkflowAPI().usingTask(processTask).updateTask("completed"); + restAPI.assertStatusCodeIs(HttpStatus.OK); + + STEP("6. U2 deletes the task process using REST. Assert that process is not deleted. "); + restAPI.authenticateUser(testUser2).withWorkflowAPI().usingProcess(processModel).deleteProcess(); + restAPI.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError().containsSummary(String.format(RestErrorModel.ACCESS_INFORMATION_NOT_ALLOWED, processModel.getId())); + } + + /** + * Scenario 91 + * 1. Using CMIS create 2 test users: u1 and u2 + * 2. U1 creates document1 in a public site using CMIS + * 3. U1 creates a New Task with the document created above and assigns it to U2 using REST + * 4. U1 deletes the task process using REST. Assert that process is deleted. + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.WORKFLOW }, executionType = ExecutionType.REGRESSION, + description = "Verify initiator is able to delete a process even if its task is not completed.") + public void deleteWorkflowWithoutCompletingIt() throws Exception + { + STEP("1. Using CMIS create 2 test users: u1 and u2"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + + STEP("2. U1 creates document1 in a public site using CMIS"); + publicSite = dataSite.usingUser(testUser1).createPublicRandomSite(); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file1 content"); + cmisAPI.authenticateUser(testUser1).usingSite(publicSite).createFile(testFile1).assertThat().existsInRepo(); + + STEP("3. U1 creates a New Task with the document created above and assigns it to U2 using REST"); + processModel = restAPI.authenticateUser(testUser1).withWorkflowAPI() + .addProcess("activitiAdhoc", testUser2, false, CMISUtil.Priority.Normal); + restAPI.withWorkflowAPI().usingProcess(processModel).addProcessItem(testFile1); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + STEP("4. U1 deletes the task process using REST. Assert that process is deleted."); + restAPI.withWorkflowAPI().usingProcess(processModel).deleteProcess(); + restAPI.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restAPI.withWorkflowAPI().getProcesses().assertThat().entriesListDoesNotContain("id", processModel.getId()); + } + + /** + * Scenario 94 + * 1. Using CMIS create one test user: u1 + * 2. Using FTP create file in unauthorized folder (Data Dictionary) + * 3. Verify that document is not created + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT}, executionType = ExecutionType.REGRESSION, + description = "Verify that document is not created in unauthorized folder (Data Dictonary)") + public void createUserMakeUnathorizedAction() throws Exception + { + STEP("1. Using CMIS creates one test user: u1"); + testUser1 = dataUser.createRandomTestUser(); + + STEP("2. Using FTP create file in unauthorized folder (Data Dictionary). 3. Verify that document is not created"); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file1 content"); + + ftpProtocol.authenticateUser(testUser1) + .changeWorkingDirectory(ftpProtocol.getDataDictionaryPath()) + .assertThat().currentFolderIs(ftpProtocol.getDataDictionaryPath()) + .createFile(testFile1).assertThat().doesNotExistInFtp(); + } + + /** + * Scenario 95 + * 1. Using CMIS create 2 test users: u1 and u2 + * 2. U1 creates 2 documents in User Homes using CMIS + * 3. U1 verifies the list of available process definitions using REST + * 4. U1 creates a workflow of type "activitiAdhoc" with the documents created above and assign it to u2 using REST + * 5. U1 adds a new process variable using REST + * 6. U2 gets the process variables using REST + * 7. U2 closes the task using REST + * 8. Verify that user2 doesn't have access to the documents attached to the task using FTP + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.WORKFLOW}, executionType = ExecutionType.REGRESSION, + description = "Verify assignee user is able to get a process variable added by another user.") + public void createWorkflowProcessWithNewProcessVariable() throws Exception + { + STEP("1. Using CMIS create 2 test users: u1 and u2"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + + STEP("2. U1 creates 2 documents in User Homes using CMIS"); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file1 content"); + testFile2 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file2 content"); + cmisAPI.authenticateUser(testUser1).usingUserHome() + .createFile(testFile1).assertThat().existsInRepo() + .createFile(testFile2).assertThat().existsInRepo(); + + STEP("3. U1 verifies the list of available process definitions using REST"); + RestProcessDefinitionModelsCollection procDefinitions = restAPI.authenticateUser(testUser1).withWorkflowAPI().getAllProcessDefinitions(); + restAPI.assertStatusCodeIs(HttpStatus.OK); + procDefinitions.assertThat().entriesListContains("key", "activitiAdhoc"); + + STEP("4. U1 creates a workflow of type 'activitiAdhoc' with the documents created above and assign it to u2 using REST"); + processModel = restAPI.authenticateUser(testUser1).withWorkflowAPI() + .addProcess("activitiAdhoc", testUser2, false, CMISUtil.Priority.Normal); + restAPI.withWorkflowAPI().usingProcess(processModel).addProcessItem(testFile1); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + restAPI.withWorkflowAPI().usingProcess(processModel).addProcessItem(testFile2); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + STEP("5. U1 adds a new process variable using REST"); + RestProcessVariableModel variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + + RestProcessVariableModel processVariable = restAPI.withWorkflowAPI().usingProcess(processModel).addProcessVariable(variableModel); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + processVariable.assertThat().field("name").is(variableModel.getName()) + .and().field("type").is(variableModel.getType()) + .and().field("value").is(variableModel.getValue()); + + STEP("6. U2 gets the process variables using REST"); + RestProcessVariableCollection processVariables = restAPI.authenticateUser(testUser2).withWorkflowAPI().usingProcess(processModel).getProcessVariables(); + processVariables.getProcessVariableByName(processVariable.getName()) + .assertThat().field("type").is(processVariable.getType()) + .assertThat().field("value").is(processVariable.getValue()); + + processVariables.getProcessVariableByName("bpm_assignee") + .assertThat().field("type").is("cm:person") + .assertThat().field("value").is(testUser2.getUsername()); + + processVariables.getProcessVariableByName("bpm_priority") + .assertThat().field("type").is("d:int") + .assertThat().field("value").is(CMISUtil.Priority.Normal.getLevel()); + + processVariables.getProcessVariableByName("bpm_sendEMailNotifications") + .assertThat().field("type").is("d:boolean") + .assertThat().field("value").is(false); + + processVariables.getProcessVariableByName("initiator") + .assertThat().field("type").is("d:noderef") + .assertThat().field("value").is(testUser1.getUsername()); + + processVariables.getProcessVariableByName("bpm_percentComplete") + .assertThat().field("type").is("d:int") + .assertThat().field("value").is(0); + + STEP("7. U2 closes the task using REST"); + RestTaskModel processTask = restAPI.withWorkflowAPI().usingProcess(processModel).getProcessTasks().getTaskModelByAssignee(testUser2); + restAPI.withParams("select=state").withWorkflowAPI().usingTask(processTask).updateTask("completed"); + restAPI.assertStatusCodeIs(HttpStatus.OK); + + STEP("8. Verify that user2 doesn't have access to the documents attached to the task using FTP"); + ftpProtocol.authenticateUser(testUser2) + .usingResource(testFile1).assertThat().hasReplyCode(FTPReply.FILE_UNAVAILABLE).and().assertThat().doesNotExistInFtp() + .usingResource(testFile2).assertThat().hasReplyCode(FTPReply.FILE_UNAVAILABLE).and().assertThat().doesNotExistInFtp(); + } + + /** + * Scenario 96 + * 1. Using CMIS create 2 test users: u1 and u2. + * 2. U1 creates 2 documents in User Homes using CMIS + * 3. U1 verifies the list of available process definitions using REST + * 4. U1 creates a workflow of type 'activitiReview' with the documents created above and assign it to u2 using REST + * 5. U1 adds a new process variable using REST + * 6. U2 gets the process variables using REST + * 7. U2 closes the task using REST + * 8. U1 deletes the new added process variable + * 9. U1 starts new 'activitiReview' process. Verify the process doesn't have the process variable added above. + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.WORKFLOW}, executionType = ExecutionType.REGRESSION, + description = "Verify process variable is process specific, not process definition.") + public void createWorkflowProcessAndDeleteProcessVariable() throws Exception + { + STEP("1. Using CMIS create 2 test users: u1 and u2."); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + + STEP("2. U1 creates 2 documents in User Homes using CMIS"); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file1 content"); + testFile2 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file2 content"); + cmisAPI.authenticateUser(testUser1).usingUserHome() + .createFile(testFile1).assertThat().existsInRepo() + .createFile(testFile2).assertThat().existsInRepo(); + + STEP("3. U1 verifies the list of available process definitions using REST"); + RestProcessDefinitionModelsCollection procDefinitions = restAPI.authenticateUser(testUser1).withWorkflowAPI().getAllProcessDefinitions(); + restAPI.assertStatusCodeIs(HttpStatus.OK); + procDefinitions.assertThat().entriesListContains("key", "activitiReview"); + + + STEP("4. U1 creates a workflow of type 'activitiParallelGroupReview' with the documents created above and assign it to u2 using REST"); + processModel = restAPI.authenticateUser(testUser1).withWorkflowAPI() + .addProcess("activitiReview", testUser2, false, CMISUtil.Priority.Normal); + restAPI.withWorkflowAPI().usingProcess(processModel).addProcessItem(testFile1); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + restAPI.withWorkflowAPI().usingProcess(processModel).addProcessItem(testFile2); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + STEP("5. U1 adds a new process variable using REST"); + RestProcessVariableModel variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + + RestProcessVariableModel processVariable = restAPI.withWorkflowAPI().usingProcess(processModel).addProcessVariable(variableModel); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + processVariable.assertThat().field("name").is(variableModel.getName()) + .and().field("type").is(variableModel.getType()) + .and().field("value").is(variableModel.getValue()); + + STEP("6. U2 gets the process variables using REST"); + RestProcessVariableCollection processVariables = restAPI.authenticateUser(testUser2).withWorkflowAPI().usingProcess(processModel).getProcessVariables(); + processVariables.getProcessVariableByName(processVariable.getName()) + .assertThat().field("type").is(processVariable.getType()) + .assertThat().field("value").is(processVariable.getValue()); + + processVariables.getProcessVariableByName("bpm_assignee") + .assertThat().field("type").is("cm:person") + .assertThat().field("value").is(testUser2.getUsername()); + + processVariables.getProcessVariableByName("bpm_priority") + .assertThat().field("type").is("d:int") + .assertThat().field("value").is(CMISUtil.Priority.Normal.getLevel()); + + processVariables.getProcessVariableByName("bpm_sendEMailNotifications") + .assertThat().field("type").is("d:boolean") + .assertThat().field("value").is(false); + + processVariables.getProcessVariableByName("initiator") + .assertThat().field("type").is("d:noderef") + .assertThat().field("value").is(testUser1.getUsername()); + + processVariables.getProcessVariableByName("wf_reviewOutcome") + .assertThat().field("type").is("d:text") + .assertThat().field("value").is("Reject"); + + STEP("7. U2 closes the task using REST"); + RestTaskModel processTask = restAPI.withWorkflowAPI().usingProcess(processModel).getProcessTasks().getTaskModelByAssignee(testUser2); + restAPI.withParams("select=state").withWorkflowAPI().usingTask(processTask).updateTask("completed"); + restAPI.assertStatusCodeIs(HttpStatus.OK); + + STEP("8. U1 deletes the new added process variable"); + restAPI.authenticateUser(testUser1).withWorkflowAPI().usingProcess(processModel).deleteProcessVariable(processVariable); + restAPI.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + STEP("9. U1 starts new 'activitiReview' process. Verify the process doesn't have the process variable added above."); + processModel = restAPI.withWorkflowAPI().addProcess("activitiReview", testUser2, false, CMISUtil.Priority.Normal); + restAPI.withWorkflowAPI().usingProcess(processModel).getProcessVariables().assertThat() + .entriesListDoesNotContain("name", processVariable.getName()); + } + + /** + * Scenario 97 + * 1. Using CMIS create 2 public sites: s1, s2. + * 2. Using CMIS create test users: u1 and u2. + * 3. Using RestAPI add u1 to s1 and s2, u2 to s2. + * 4. Using RestAPI add all sites to favorites for every user. + * 5. Using RestAPI get preferences and check that favorited sites are listed. + * 6. Using RestAPI, u1 removes site1 from favorites, u2 removes site2 from favorites. + * 7. Using RestAPI get preferences and check that favorited sites are listed. Removed sites are not listed. + * 8. Using FTP U1 creates file1 in s1 document library and adds it to favorites using RestAPI. Same for u2 and s2 + * 9. Using RestAPI U1 and U2 get preferences. Files added to favorites are listed. + * 10. Using WebDAV rename file1 and file2. + * 11. Using RestAPI U1 and U2 get preferences. Files renamed are listed. + * 12. Using FTP delete files. + * 13. Using CMIS delete site1. + * 14. Using RestAPI get preferences. Files and sites deleted are not listed anymore as favorites. + */ + + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL}) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, + description = "Verify user can get preferences of sites and documents which were updated or deleted") + @Bug(id = "ACE-5769") + public void getUserPreferencesForSitesAndFiles() throws Exception + { + RestPreferenceModelsCollection restPreferenceModelsCollection; + + STEP("1. Using CMIS create 2 public sites: s1, s2."); + SiteModel testSitePublic1 = dataSite.usingUser(testUser1).createPublicRandomSite(); + SiteModel testSitePublic2 = dataSite.usingUser(testUser1).createPublicRandomSite(); + + STEP("2. Using CMIS create test users: u1 and u2."); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + + STEP("3. Using RestAPI add u1 to s1 and s2, u2 to s2."); + dataUser.addUserToSite(testUser1, testSitePublic1, UserRole.SiteManager); + dataUser.addUserToSite(testUser1, testSitePublic2, UserRole.SiteCollaborator); + dataUser.addUserToSite(testUser2, testSitePublic2, UserRole.SiteManager); + + STEP("4. Using RestAPI add all sites to favorites for every user."); + restAPI.authenticateUser(testUser1).withCoreAPI().usingAuthUser().addSiteToFavorites(testSitePublic1); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + restAPI.withCoreAPI().usingAuthUser().addSiteToFavorites(testSitePublic2); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + restAPI.authenticateUser(testUser2).withCoreAPI().usingAuthUser().addSiteToFavorites(testSitePublic1); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + restAPI.withCoreAPI().usingAuthUser().addSiteToFavorites(testSitePublic2); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + STEP("5. Using RestAPI get preferences and check that favorited sites are listed."); + restPreferenceModelsCollection = restAPI.authenticateUser(testUser1).withCoreAPI().usingAuthUser().getPersonPreferences(); + restPreferenceModelsCollection.assertThat().paginationField("count").is("4"); + restPreferenceModelsCollection.assertThat().entriesListIsNotEmpty() + .and().entriesListContains("id", String.format(PreferenceName.EXT_SITES_FAVORITES_PREFIX.toString(), testSitePublic1.getId())) + .and().entriesListContains("id", String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), testSitePublic1.getId())) + .and().entriesListContains("id", String.format(PreferenceName.EXT_SITES_FAVORITES_PREFIX.toString(), testSitePublic2.getId())) + .and().entriesListContains("id", String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), testSitePublic2.getId())) + .and().entriesListContains("value", "true"); + + restPreferenceModelsCollection = restAPI.authenticateUser(testUser2).withCoreAPI().usingAuthUser().getPersonPreferences(); + restPreferenceModelsCollection.assertThat().paginationField("count").is("4"); + restPreferenceModelsCollection.assertThat().entriesListIsNotEmpty() + .and().entriesListContains("id", String.format(PreferenceName.EXT_SITES_FAVORITES_PREFIX.toString(), testSitePublic1.getId())) + .and().entriesListContains("id", String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), testSitePublic1.getId())) + .and().entriesListContains("id", String.format(PreferenceName.EXT_SITES_FAVORITES_PREFIX.toString(), testSitePublic2.getId())) + .and().entriesListContains("id", String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), testSitePublic2.getId())) + .and().entriesListContains("value", "true"); + + STEP("6. Using RestAPI, u1 removes site1 from favorites, u2 removes site2 from favorites."); + restAPI.authenticateUser(testUser1).withCoreAPI().usingAuthUser().removeFavoriteSite(testSitePublic1); + restAPI.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + restAPI.authenticateUser(testUser2).withCoreAPI().usingAuthUser().removeFavoriteSite(testSitePublic2); + restAPI.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + STEP("7. Using RestAPI get preferences and check that favorited sites are listed. Removed sites are not listed."); + restPreferenceModelsCollection = restAPI.authenticateUser(testUser1).withCoreAPI().usingAuthUser().getPersonPreferences(); + restPreferenceModelsCollection.assertThat().paginationField("count").is("3"); + restPreferenceModelsCollection.assertThat().entriesListIsNotEmpty() + .and().entriesListContains("id", String.format(PreferenceName.EXT_SITES_FAVORITES_PREFIX.toString(), testSitePublic2.getId())) + .and().entriesListContains("id", String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), testSitePublic2.getId())) + .and().entriesListContains("value", "true"); + + restPreferenceModelsCollection = restAPI.authenticateUser(testUser2).withCoreAPI().usingAuthUser().getPersonPreferences(); + restPreferenceModelsCollection.assertThat().paginationField("count").is("3"); + restPreferenceModelsCollection.assertThat().entriesListIsNotEmpty() + .and().entriesListContains("id", String.format(PreferenceName.EXT_SITES_FAVORITES_PREFIX.toString(), testSitePublic1.getId())) + .and().entriesListContains("id", String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), testSitePublic1.getId())) + .and().entriesListContains("value", "true"); + + STEP("8. Using FTP U1 creates file1 in s1 document library and adds it to favorites using RestAPI. Same for u2 and s2"); + FileModel file1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + FileModel file2 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + + ftpProtocol.authenticateUser(testUser1).usingSite(testSitePublic1).createFile(file1); + restAPI.authenticateUser(testUser1).withCoreAPI().usingAuthUser().addFileToFavorites(file1); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + ftpProtocol.authenticateUser(testUser2).usingSite(testSitePublic2).createFile(file2); + restAPI.authenticateUser(testUser2).withCoreAPI().usingAuthUser().addFileToFavorites(file2); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + STEP("9. Using RestAPI U1 and U2 get preferences. Files added to favorites are listed."); + restPreferenceModelsCollection = restAPI.authenticateUser(testUser1).withCoreAPI().usingAuthUser().getPersonPreferences(); + restPreferenceModelsCollection.assertThat().paginationField("count").is("5"); + restPreferenceModelsCollection.assertThat().entriesListIsNotEmpty() + .and().entriesListContains("id", String.format(PreferenceName.EXT_SITES_FAVORITES_PREFIX.toString(), testSitePublic2.getId())) + .and().entriesListContains("id", String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), testSitePublic2.getId())) + .and().entriesListContains("id", "org.alfresco.ext.documents.favourites.workspace://SpacesStore/" + file1.getNodeRef() +".createdAt") + .and().entriesListContains("value", "workspace://SpacesStore/" + file1.getNodeRef()) + .and().entriesListContains("value", "true"); + + restPreferenceModelsCollection = restAPI.authenticateUser(testUser2).withCoreAPI().usingAuthUser().getPersonPreferences(); + restPreferenceModelsCollection.assertThat().paginationField("count").is("5"); + restPreferenceModelsCollection.assertThat().entriesListIsNotEmpty() + .and().entriesListContains("id", String.format(PreferenceName.EXT_SITES_FAVORITES_PREFIX.toString(), testSitePublic1.getId())) + .and().entriesListContains("id", String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), testSitePublic1.getId())) + .and().entriesListContains("id", "org.alfresco.ext.documents.favourites.workspace://SpacesStore/" + file2.getNodeRef() +".createdAt") + .and().entriesListContains("value", "workspace://SpacesStore/" + file2.getNodeRef()) + .and().entriesListContains("value", "true"); + + STEP("10. Using WebDAV rename file1 and file2."); + webDavProtocol.authenticateUser(testUser1).usingResource(file1).rename(file1.getName()+ "-updated-file1"); + webDavProtocol.authenticateUser(testUser2).usingResource(file2).rename(file2.getName()+ "-updated-file2"); + + STEP("11. Using RestAPI U1 and U2 get preferences. Files renamed are listed."); + restPreferenceModelsCollection = restAPI.authenticateUser(testUser1).withCoreAPI().usingAuthUser().getPersonPreferences(); + restPreferenceModelsCollection.assertThat().paginationField("count").is("5"); + restPreferenceModelsCollection.assertThat().entriesListIsNotEmpty() + .and().entriesListContains("id", String.format(PreferenceName.EXT_SITES_FAVORITES_PREFIX.toString(), testSitePublic2.getId())) + .and().entriesListContains("id", String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), testSitePublic2.getId())) + .and().entriesListContains("id", "org.alfresco.ext.documents.favourites.workspace://SpacesStore/" + file1.getNodeRef() +".createdAt") + .and().entriesListContains("value", "workspace://SpacesStore/" + file1.getNodeRef()) + .and().entriesListContains("value", "true"); + + restPreferenceModelsCollection = restAPI.authenticateUser(testUser2).withCoreAPI().usingAuthUser().getPersonPreferences(); + restPreferenceModelsCollection.assertThat().paginationField("count").is("5"); + restPreferenceModelsCollection.assertThat().entriesListIsNotEmpty() + .and().entriesListContains("id", String.format(PreferenceName.EXT_SITES_FAVORITES_PREFIX.toString(), testSitePublic1.getId())) + .and().entriesListContains("id", String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), testSitePublic1.getId())) + .and().entriesListContains("id", "org.alfresco.ext.documents.favourites.workspace://SpacesStore/" + file2.getNodeRef() +".createdAt") + .and().entriesListContains("value", "workspace://SpacesStore/" + file2.getNodeRef()) + .and().entriesListContains("value", "true"); + + STEP("12. Using FTP delete files."); + ftpProtocol.authenticateUser(testUser1).usingResource(file1).delete(); + ftpProtocol.authenticateUser(testUser2).usingResource(file2).delete(); + + STEP("13. Using CMIS delete site1."); + dataSite.usingUser(admin).deleteSite(testSitePublic1); + + STEP("14. Using RestAPI get preferences. Files and sites deleted are not listed anymore as favorites."); + restPreferenceModelsCollection = restAPI.authenticateUser(testUser1).withCoreAPI().usingAuthUser().getPersonPreferences(); + restPreferenceModelsCollection.assertThat().paginationField("count").is("2"); + restPreferenceModelsCollection.assertThat().entriesListIsNotEmpty() + .and().entriesListContains("id", String.format(PreferenceName.EXT_SITES_FAVORITES_PREFIX.toString(), testSitePublic2.getId())) + .and().entriesListContains("id", String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), testSitePublic2.getId())) + .and().entriesListDoesNotContain("id", "org.alfresco.ext.documents.favourites.workspace://SpacesStore/" + file1.getNodeRef() +".createdAt") + .and().entriesListDoesNotContain("value", "workspace://SpacesStore/" + file1.getNodeRef()) + .and().entriesListContains("value", "true"); + + restPreferenceModelsCollection = restAPI.authenticateUser(testUser2).withCoreAPI().usingAuthUser().getPersonPreferences(); + restPreferenceModelsCollection.assertThat().paginationField("count").is("2"); + restPreferenceModelsCollection.assertThat().entriesListIsNotEmpty() + .and().entriesListDoesNotContain("id", String.format(PreferenceName.EXT_SITES_FAVORITES_PREFIX.toString(), testSitePublic1.getId())) + .and().entriesListDoesNotContain("id", String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), testSitePublic1.getId())) + .and().entriesListDoesNotContain("id", "org.alfresco.ext.documents.favourites.workspace://SpacesStore/" + file2.getNodeRef() +".createdAt") + .and().entriesListDoesNotContain("value", "workspace://SpacesStore/" + file2.getNodeRef()) + .and().entriesListContains("value", "true"); + } + + /** + * Scenario 101 + * 1. Using CMIS create test users: u1 and u2 + * 2. U1 creates public test site U1 creates a public test site using CMIS + * 3. U1 adds U2 as site member with manager role using RestAPI + * 4. U2 adds site to favorites using RestAPI + * 5. U2 gets preference 'org.alfresco.ext.sites.favourites.testsite.createdAt' using RestAPI + * 6. U2 remove site from favorites using RestAPI + * 7. U2 gets preference 'org.alfresco.ext.sites.favourites.testsite.createdAt' using RestAPI + * 8. U2 creates file1 in test site's document library using FTP + * 9. U2 gets preference 'org.alfresco.ext.documents.favourites.workspace://SpacesStore/.createdAt' using RestAPI + * 10. U2 removes file1 from favorites using RestAPI + * 11. U2 gets preference 'org.alfresco.share.documents.favourite' using RestAPI + * 12. U2 renames file1 to file-updated with WebDAV + * 13. U2 gets preference 'org.alfresco.ext.documents.favourites.workspace://SpacesStore/.createdAt' using RestAPI + * 14. U2 deletes file-updated with CMIS + * 15. U2 gets preference 'org.alfresco.ext.documents.favourites.workspace://SpacesStore/.createdAt' using RestAPI + * 16. U2 adds site to favorites with RestAPI and U1 deletes site1 with CMIS + * 17. U2 gets preference 'org.alfresco.ext.sites.favourites.site1.createdAt' using RestAPI + */ + @Bug(id = "ACE-5769") + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL}) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, + description = "Verify user can get preference of sites and documents which were updated or deleted") + public void getPreferenceForSiteAndFiles() throws Exception + { + STEP("1. Using CMIS create 2 test users: u1 and u2"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + + STEP("2. U1 creates public test site U1 creates a public test site using CMIS"); + SiteModel testSitePublic = dataSite.usingUser(testUser1).createPublicRandomSite(); + + STEP("3. U1 adds U2 as site member with manager role using RestAPI"); + dataUser.usingUser(testUser1).addUserToSite(testUser2, testSitePublic, UserRole.SiteManager); + testUser2.setUserRole(UserRole.SiteManager); + + STEP("4. U2 adds site to favorites using RestAPI"); + restAPI.authenticateUser(testUser2).withCoreAPI().usingAuthUser().addSiteToFavorites(testSitePublic); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + STEP("5. U2 gets preference 'org.alfresco.ext.sites.favourites.testsite.createdAt' using RestAPI"); + restAPI.authenticateUser(testUser2).withCoreAPI().usingAuthUser().getPersonPreferenceInformation(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), testSitePublic.getId())); + restAPI.assertStatusCodeIs(HttpStatus.OK); + + STEP("6. U2 remove site from favorites using RestAPI"); + restAPI.authenticateUser(testUser2).withCoreAPI().usingAuthUser().removeFavoriteSite(testSitePublic); + restAPI.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + STEP("7. U2 gets preference 'org.alfresco.ext.sites.favourites.testsite.createdAt' using RestAPI"); + restAPI.authenticateUser(testUser2).withCoreAPI().usingAuthUser().getPersonPreferenceInformation(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), testSitePublic.getId())); + restAPI.assertStatusCodeIs(HttpStatus.NOT_FOUND); + + STEP("8. U2 creates file1 in test site's document library using FTP and adds it to favorites using RestAPI"); + FileModel file1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + ftpProtocol.authenticateUser(testUser2).usingSite(testSitePublic).createFile(file1); + restAPI.authenticateUser(testUser2).withCoreAPI().usingAuthUser().addFileToFavorites(file1); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + STEP("9. U2 gets preference 'org.alfresco.ext.documents.favourites.workspace://SpacesStore/.createdAt' using RestAPI"); + RestPreferenceModel preference = restAPI.authenticateUser(testUser2).withCoreAPI().usingAuthUser().getPersonPreferenceInformation(PreferenceName.DOCUMENTS_FAVORITES_PREFIX.toString()); + restAPI.assertStatusCodeIs(HttpStatus.OK); + preference.assertThat().field("value").is("workspace://SpacesStore/" + file1.getNodeRefWithoutVersion()); + + STEP("10. U2 removes file1 from favorites using RestAPI"); + restAPI.authenticateUser(testUser2).withCoreAPI().usingAuthUser().deleteFileFromFavorites(file1); + restAPI.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + STEP("11. U2 gets preference 'org.alfresco.share.documents.favourite' using RestAPI"); + preference = restAPI.authenticateUser(testUser2).withCoreAPI().usingAuthUser().getPersonPreferenceInformation(PreferenceName.DOCUMENTS_FAVORITES_PREFIX.toString()); + restAPI.assertStatusCodeIs(HttpStatus.OK); + preference.assertThat().field("value").isNull(); + + STEP("12. U2 adds file1 to favorites using RestAPI and renames file1 to file-updated with WebDAV"); + restAPI.authenticateUser(testUser2).withCoreAPI().usingAuthUser().addFileToFavorites(file1); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + webDavProtocol.authenticateUser(testUser2).usingResource(file1).rename(file1.getName()+ "-updated"); + + STEP("13. U2 gets preference 'org.alfresco.ext.documents.favourites.workspace://SpacesStore/.createdAt' using RestAPI"); + preference = restAPI.authenticateUser(testUser2).withCoreAPI().usingAuthUser().getPersonPreferenceInformation(PreferenceName.DOCUMENTS_FAVORITES_PREFIX.toString()); + restAPI.assertStatusCodeIs(HttpStatus.OK); + preference.assertThat().field("value").is("workspace://SpacesStore/" + file1.getNodeRefWithoutVersion()); + + STEP("14. U2 adds file1 to favorites using RestAPI and deletes file-updated with CMIS"); + restAPI.authenticateUser(testUser2).withCoreAPI().usingAuthUser().addFileToFavorites(file1); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + cmisAPI.authenticateUser(testUser2).usingResource(file1).delete(); + + STEP("15. U2 gets preference 'org.alfresco.ext.documents.favourites.workspace://SpacesStore/.createdAt' using RestAPI"); + preference = restAPI.authenticateUser(testUser2).withCoreAPI().usingAuthUser().getPersonPreferenceInformation(PreferenceName.DOCUMENTS_FAVORITES_PREFIX.toString()); + restAPI.assertStatusCodeIs(HttpStatus.OK); + preference.assertThat().field("value").isNull(); + + STEP("16. U2 adds site to favorites with RestAPI and U1 deletes site1 with CMIS"); + restAPI.authenticateUser(testUser2).withCoreAPI().usingAuthUser().addSiteToFavorites(testSitePublic); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + dataSite.usingUser(testUser1).deleteSite(testSitePublic); + + STEP("17. U2 gets preference 'org.alfresco.ext.sites.favourites.site1.createdAt' using RestAPI"); + preference = restAPI.authenticateUser(testUser2).withCoreAPI().usingAuthUser().getPersonPreferenceInformation(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), testSitePublic.getId())); + restAPI.assertStatusCodeIs(HttpStatus.NOT_FOUND); + restAPI.assertStatusCodeIs(HttpStatus.OK); + preference.assertThat().field("value").isNull(); + } + + @Bug(id = "REPO-2419", status = Status.FIXED) + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.FULL }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.REGRESSION, description = "Verify that the version of a new file uploaded through WebDAV is 1.0 with the real content size.") + public void uploadedFileThroughWebdavHasFirstVersion() throws Exception + { + UserModel managerUser = dataUser.createRandomTestUser(); + SiteModel testSite = dataSite.usingUser(managerUser).createPublicRandomSite(); + + STEP("0. Verify versionable aspect is set for all contents using webscript"); + String fileCreationWebScript = "alfresco/s/api/classes/cm_content"; + + RestAssured.basePath = ""; + restAPI.configureRequestSpec().setBasePath(RestAssured.basePath); + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, fileCreationWebScript); + RestResponse response = restAPI.authenticateUser(admin).process(request); + Assert.assertEquals(response.getResponse().getStatusCode(), HttpStatus.OK.value()); + try + { + response.assertThat().body(containsString("cm:versionable")); + response.assertThat().body("defaultAspects.'cm:versionable'.title", equalTo("Versionable")); + } + catch(AssertionError ae) + { + throw new SkipException("Skipping this test because the versionable aspect is not applied. Please add " + + "the versionable aspect to all content in contentModel.xml and run the test again."); + } + + STEP("1. Upload a local file on a new folder using WebDAV protocol"); + FolderModel folder = dataContent.usingUser(managerUser).usingSite(testSite).createFolder(); + File fileToUpload = Utility.getTestResourceFile("shared-resources/testdata/nonemptyupload.txt"); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite).usingResource(folder).uploadFile(fileToUpload); + FileModel file = new FileModel(fileToUpload.getName()); + + STEP("2. Verify version is exactly 1.0 and the size is the same as the local file"); + dataContent.usingResource(file).assertContentVersionIs("1.0"); + dataContent.usingResource(file).assertContentSizeIs(19); + } +} diff --git a/tests/tas-integration/src/test/java/org/alfresco/tas/integration/IntegrationFullTests1.java b/tests/tas-integration/src/test/java/org/alfresco/tas/integration/IntegrationFullTests1.java new file mode 100644 index 0000000000..c606dc17cf --- /dev/null +++ b/tests/tas-integration/src/test/java/org/alfresco/tas/integration/IntegrationFullTests1.java @@ -0,0 +1,477 @@ +package org.alfresco.tas.integration; + +import static org.alfresco.utility.report.log.Step.STEP; + +import io.restassured.RestAssured; +import java.util.HashMap; +import java.util.Map; + +import org.alfresco.dataprep.SiteService.Visibility; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.core.RestResponse; +import org.alfresco.rest.model.RestSiteContainerModel; +import org.alfresco.rest.model.RestSiteContainerModelsCollection; +import org.alfresco.rest.model.RestSiteEntry; +import org.alfresco.rest.model.RestSiteMemberModelsCollection; +import org.alfresco.rest.model.RestSiteMembershipRequestModel; +import org.alfresco.rest.model.RestTagModel; +import org.alfresco.rest.model.RestTaskModel; +import org.alfresco.utility.Utility; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.RandomData; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +import org.alfresco.utility.model.FolderModel; +import org.alfresco.utility.model.GroupModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.testng.Assert; +import org.testng.annotations.Test; + +public class IntegrationFullTests1 extends IntegrationTest +{ + UserModel testUser1, testUser2, testUser3; + SiteModel testSitePublic, testSiteModerated; + + /** + * Scenario 87 + * 1. Using RestApi Admin user creates a new group1 + * 2. Using CMIS create test users: U1, U2 and U3 + * 3. Using RestApi add users U2 and U3 to group1 + * 4. U1 creates public test site1 using CMIS + * 5. U1 creates file1 using CMIS, WebDav, FTP + * 6. U1 apply Acl permission in the new documents for testGroup with role Site Consumer using CMIS + * 7. Get permissions for U2 using CMIS + * 8. U2 edits files created with CMIS, WebDav, FTP using WebDav + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, + description = "Verify document permissions are added for a group of users") + public void addDocumentPermissionsForGroupOfUsers() throws Exception + { + STEP("1. Using RestApi Admin user creates a new group1"); + GroupModel group1 = dataGroup.createRandomGroup(); + + STEP("2. Using CMIS create test users: U1, U2 and U3"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + testUser3 = dataUser.createRandomTestUser(); + + STEP("3. Using RestApi add users U2 and U3 to group1"); + dataGroup.usingUser(testUser2).addUserToGroup(group1); + dataGroup.usingUser(testUser3).addUserToGroup(group1); + + STEP("4. U1 creates public test site1 using CMIS"); + testSitePublic = dataSite.usingUser(testUser1).createPublicRandomSite(); + + STEP("5. U1 creates file1 using CMIS, WebDav, FTP"); + FileModel cmisFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisAPI.authenticateUser(testUser1).usingSite(testSitePublic).createFile(cmisFile); + FileModel webDavFile = FileModel.getRandomFileModel(FileType.HTML); + webDavProtocol.authenticateUser(testUser1).usingSite(testSitePublic).createFile(webDavFile); + FileModel ftpFile = FileModel.getRandomFileModel(FileType.XML); + ftpProtocol.authenticateUser(testUser1).usingSite(testSitePublic).createFile(ftpFile); + + STEP("6. U1 apply Acl permission in the new documents for testGroup with role Site Consumer using CMIS"); + cmisAPI.usingResource(cmisFile).addAcl(group1, UserRole.SiteConsumer); + cmisAPI.usingResource(webDavFile).addAcl(group1, UserRole.SiteConsumer); + cmisAPI.usingResource(ftpFile).addAcl(group1, UserRole.SiteConsumer); + + STEP("7. Get permissions for U2 using CMIS"); + cmisAPI.usingResource(cmisFile).assertThat().permissionIsSetForGrup(group1, UserRole.SiteConsumer); + cmisAPI.usingResource(webDavFile).assertThat().permissionIsSetForGrup(group1, UserRole.SiteConsumer); + cmisAPI.usingResource(ftpFile).assertThat().permissionIsSetForGrup(group1, UserRole.SiteConsumer); + + STEP("8. U2 edits files created with CMIS, WebDav, FTP using WebDav"); + String newContent = "new content"; + webDavProtocol.authenticateUser(testUser2) + .usingResource(cmisFile).update(newContent) + .assertThat().hasStatus(org.apache.commons.httpclient.HttpStatus.SC_FORBIDDEN) + .usingResource(webDavFile).update(newContent) + .assertThat().hasStatus(org.apache.commons.httpclient.HttpStatus.SC_FORBIDDEN) + .usingResource(ftpFile).update(newContent) + .assertThat().hasStatus(org.apache.commons.httpclient.HttpStatus.SC_FORBIDDEN); + } + + /** + * Scenario 88 + * 1. Using RestApi Admin user creates a new group1 + * 2. Using CMIS create test users: U1, U2 and U3 + * 3. Using RestApi add users U2 and U3 to group1 + * 4. U1 creates public test site1 using CMIS + * 5. U1 creates folder1 using CMIS, WebDav, FTP + * 6. U1 apply Acl permission in the new folders for testGroup with role Site Consumer using CMIS + * 7. Get permissions for U2 using CMIS + * 8. U2 edits folders created with CMIS, WebDav, FTP using WebDav + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, + description = "Verify folder permissions are added for a group of users") + public void addFolderPermissionsForGroupOfUsers() throws Exception + { + STEP("1. Using RestApi Admin user creates a new group1"); + GroupModel group1 = dataGroup.createRandomGroup(); + + STEP("2. Using CMIS create test users: U1, U2 and U3"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + testUser3 = dataUser.createRandomTestUser(); + + STEP("3. Using RestApi add users U2 and U3 to group1"); + dataGroup.usingUser(testUser2).addUserToGroup(group1); + dataGroup.usingUser(testUser3).addUserToGroup(group1); + + STEP("4. U1 creates public test site1 using CMIS"); + testSitePublic = dataSite.usingUser(testUser1).createPublicRandomSite(); + + STEP("5. U1 creates folders using CMIS, WebDav, FTP"); + FolderModel cmisFolder = FolderModel.getRandomFolderModel(); + cmisAPI.authenticateUser(testUser1).usingSite(testSitePublic).createFolder(cmisFolder); + FolderModel webDavFolder = FolderModel.getRandomFolderModel(); + webDavProtocol.authenticateUser(testUser1).usingSite(testSitePublic).createFolder(webDavFolder); + FolderModel ftpFolder = FolderModel.getRandomFolderModel(); + ftpProtocol.authenticateUser(testUser1).usingSite(testSitePublic).createFolder(ftpFolder); + + STEP("6. U1 apply Acl permission in the new folders for testGroup with role Site Consumer using CMIS"); + cmisAPI.usingResource(cmisFolder).addAcl(group1, UserRole.SiteConsumer); + cmisAPI.usingResource(webDavFolder).addAcl(group1, UserRole.SiteConsumer); + cmisAPI.usingResource(ftpFolder).addAcl(group1, UserRole.SiteConsumer); + + STEP("7. Get permissions for U2 using CMIS"); + cmisAPI.usingResource(cmisFolder).assertThat().permissionIsSetForGrup(group1, UserRole.SiteConsumer); + cmisAPI.usingResource(webDavFolder).assertThat().permissionIsSetForGrup(group1, UserRole.SiteConsumer); + cmisAPI.usingResource(ftpFolder).assertThat().permissionIsSetForGrup(group1, UserRole.SiteConsumer); + + STEP("8. U2 edits folders created with CMIS, WebDav, FTP using WebDav"); + String newName = "newName"; + webDavProtocol.authenticateUser(testUser2) + .usingResource(cmisFolder).rename(newName) + .assertThat().hasStatus(org.apache.commons.httpclient.HttpStatus.SC_FORBIDDEN) + .usingResource(webDavFolder).rename(newName) + .assertThat().hasStatus(org.apache.commons.httpclient.HttpStatus.SC_FORBIDDEN) + .usingResource(ftpFolder).rename(newName) + .assertThat().hasStatus(org.apache.commons.httpclient.HttpStatus.SC_FORBIDDEN); + } + + /** + * Scenario 102 + * 1. Using CMIS create test users: U1 and U2 + * 2. U1 creates moderated test site1 using CMIS + * 3. U2 creates site membership request to site1 with RestAPI + * 4. U2 gets site membership request, check new message using RestAPI + * 5. U2 updates site membership request with a new message using RestAPI + * 6. U2 gets site membership request, check new message using RestAPI + * 7. U1 changes site visibility to private site using RestAPI + * 8. U2 updates site membership request with a new message using RestAPI + * 9. U2 gets site membership request, check new message using RestAPI + * 10. U1 change site visibility to moderated site RestAPI + * 11. U2 gets site membership request, check new message using RestAPI + * 12. U2 updates site membership request with a new message using RestAPI + * 13. U2 get site membership request, check new message using RestAPI + * 14. U1 user1 changes site visibility to public using RestAPI + * 15. U2 updates site membership request with a new message with RestAPI + * 16. U2 gets site membership request, check new message using RestAPI + * 17. U1 changes site visibility to moderated site RestAPI"); + * 18. U2 gets site membership request, check new message using RestAPI"); + * 19. U2 updates new site membership request using RestAPI + * 20. U1 approves site membership using RestAPI + * 21. U2 gets site membership request - no request using RestAPI + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user can update or not site membership request when site visibility is updated") + public void updateSiteMembershipRequestWhenSiteVisibilityIsUpdated() throws Exception + { + STEP("1. Using CMIS create 2 test users: U1 and U2"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + + STEP("2. U1 creates moderated test site1 using CMIS"); + testSiteModerated = dataSite.usingUser(testUser1).createModeratedRandomSite(); + + STEP("3. U2 creates site membership request to site1 with RestAPI"); + restAPI.authenticateUser(testUser2).withCoreAPI().usingMe().addSiteMembershipRequest("Please add me 1", testSiteModerated, "Request1"); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + STEP("4. U2 gets site membership request, check new message using RestAPI"); + RestSiteMembershipRequestModel request = restAPI.withCoreAPI().usingMe().getSiteMembershipRequest(testSiteModerated); + restAPI.assertStatusCodeIs(HttpStatus.OK); + request.assertThat().field("message").is("Please add me 1"); + + STEP("5. U2 updates site membership request with a new message using RestAPI"); + request = restAPI.withCoreAPI().usingMe().updateSiteMembershipRequest(testSiteModerated, "Please add me 2"); + request.assertThat().field("message").is("Please add me 2"); + + STEP("6. U2 gets site membership request, check new message using RestAPI"); + request = restAPI.withCoreAPI().usingMe().getSiteMembershipRequest(testSiteModerated); + restAPI.assertStatusCodeIs(HttpStatus.OK); + request.assertThat().field("message").is("Please add me 2"); + + STEP("7. U1 changes site visibility to private site using RestAPI"); + dataSite.usingUser(testUser1).updateSiteVisibility(testSiteModerated, Visibility.PRIVATE); + + STEP("8. U2 updates site membership request with a new message using RestAPI"); + restAPI.withCoreAPI().usingMe().updateSiteMembershipRequest(testSiteModerated, "Please add me 2"); + restAPI.assertStatusCodeIs(HttpStatus.NOT_FOUND); + + STEP("9. U2 gets site membership request, check new message using RestAPI"); + restAPI.withCoreAPI().usingMe().getSiteMembershipRequest(testSiteModerated); + restAPI.assertStatusCodeIs(HttpStatus.NOT_FOUND); + + STEP("10. U1 change site visibility to moderated site RestAPI"); + dataSite.usingUser(testUser1).updateSiteVisibility(testSiteModerated, Visibility.MODERATED); + + STEP("11. U2 gets site membership request, check new message using RestAPI"); + request = restAPI.withCoreAPI().usingMe().getSiteMembershipRequest(testSiteModerated); + restAPI.assertStatusCodeIs(HttpStatus.OK); + request.assertThat().field("message").is("Please add me 2"); + + STEP("12. U2 updates site membership request with a new message using RestAPI"); + request = restAPI.withCoreAPI().usingMe().updateSiteMembershipRequest(testSiteModerated, "Please add me 3"); + request.assertThat().field("message").is("Please add me 3"); + + STEP("13. U2 get site membership request, check new message using RestAPI"); + request = restAPI.withCoreAPI().usingMe().getSiteMembershipRequest(testSiteModerated); + restAPI.assertStatusCodeIs(HttpStatus.OK); + request.assertThat().field("message").is("Please add me 3"); + + STEP("14. U1 user1 changes site visibility to public using RestAPI"); + dataSite.usingUser(testUser1).updateSiteVisibility(testSiteModerated, Visibility.PUBLIC); + + STEP("15. U2 updates site membership request with a new message with RestAPI"); + restAPI.withCoreAPI().usingMe().updateSiteMembershipRequest(testSiteModerated, "Please add me 4"); + restAPI.assertStatusCodeIs(HttpStatus.NOT_FOUND); + + STEP("16. U2 gets site membership request, check new message using RestAPI"); + restAPI.withCoreAPI().usingMe().getSiteMembershipRequest(testSiteModerated); + restAPI.assertStatusCodeIs(HttpStatus.NOT_FOUND); + + STEP("17. U1 changes site visibility to moderated site RestAPI"); + dataSite.usingUser(testUser1).updateSiteVisibility(testSiteModerated, Visibility.MODERATED); + + STEP("18. U2 gets site membership request, check new message using RestAPI"); + request = restAPI.withCoreAPI().usingMe().getSiteMembershipRequest(testSiteModerated); + restAPI.assertStatusCodeIs(HttpStatus.OK); + request.assertThat().field("message").is("Please add me 3"); + + STEP("19. U2 updates new site membership request using RestAPI"); + request = restAPI.withCoreAPI().usingMe().updateSiteMembershipRequest(testSiteModerated, "Please add me 5"); + restAPI.assertStatusCodeIs(HttpStatus.OK); + request.assertThat().field("message").is("Please add me 5"); + + STEP("20. U1 approves site membership using RestAPI"); + RestTaskModel taskModel = restAPI.withWorkflowAPI().getTasks().getTaskModelByDescription(testSiteModerated); + workflow.approveSiteMembershipRequest(testUser1.getUsername(), testUser1.getPassword(), taskModel.getId(), true, "Approve"); + + STEP("21. U2 gets site membership request - no request using RestAPI"); + restAPI.withCoreAPI().usingMe().getSiteMembershipRequest(testSiteModerated); + restAPI.assertStatusCodeIs(HttpStatus.NOT_FOUND); + RestSiteEntry site= restAPI.withCoreAPI().usingMe().getSiteMembership(testSiteModerated); + restAPI.assertStatusCodeIs(HttpStatus.OK); + site.assertThat().field("id").is(testSiteModerated.getId()) + .and().field("role").isNotEmpty(); + } + + /** + * Scenario 104 + * 1. Using CMIS create test user A1 + * 2. A1 creates public test site1 using CMIS + * 3. Using CMIS create test user U1 + * 4. A1 adds U1 to site1 as site manager using RestAPI + * 5. A1 get site members using RestAPI + * 6. Using CMIS create test user U2 + * 7. A1 adds U2 to site1 as site collaborator using RestAPI + * 8. A1 get site members using RestAPI + * 9. Using CMIS create test user U3 + * 10. A1 add U3 to site1 as site contributor using RestAPI + * 11. A1 get site members using RestAPI + * 12. Using CMIS create test user U4 + * 13. A1 add U4 to site1 as site consumer using RestAPI + * 14. A1 get site members using RestAPI + * 15. Using CMIS delete test user U1 + * 16. A1 get site members using RestAPI + * 17. Using CMIS delete test user U2 + * 18. A1 get site members using RestAPI + * 19. Using CMIS delete test user U3 + * 20. A1 get site members using RestAPI + * 21. Using CMIS delete test user U4 + * 22. A1 get site members using RestAPI + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify get site members when users are added to site or deleted") + public void getSiteMembersWhenUsersAreAddedOrDeleted() throws Exception + { + STEP("1. Using CMIS create test user A1"); + UserModel testUser = dataUser.createRandomTestUser(); + + STEP("2. A1 creates public test site1 using CMIS"); + testSitePublic = dataSite.usingUser(testUser).createPublicRandomSite(); + + STEP("3. Using CMIS create test user U1"); + UserModel user1 = dataUser.createRandomTestUser(); + + STEP("4. A1 adds U1 to site1 as site manager using RestAPI"); + user1.setUserRole(UserRole.SiteManager); + restAPI.authenticateUser(testUser).withCoreAPI().usingSite(testSitePublic).addPerson(user1); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + STEP("5. A1 get site members using RestAPI"); + RestSiteMemberModelsCollection members = restAPI.authenticateUser(testUser).withCoreAPI().usingSite(testSitePublic).getSiteMembers(); + restAPI.assertStatusCodeIs(HttpStatus.OK); + members.assertThat().paginationField("count").is("2"); + members.assertThat().entriesListContains("id", user1.getUsername()) + .and().entriesListContains("role", UserRole.SiteManager.toString()); + + STEP("6. Using CMIS create test user U2"); + UserModel user2 = dataUser.createRandomTestUser(); + + STEP("7. A1 adds U2 to site1 as site collaborator using RestAPI"); + user2.setUserRole(UserRole.SiteCollaborator); + restAPI.authenticateUser(testUser).withCoreAPI().usingSite(testSitePublic).addPerson(user2); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + STEP("8. A1 get site members using RestAPI"); + members = restAPI.authenticateUser(testUser).withCoreAPI().usingSite(testSitePublic).getSiteMembers(); + restAPI.assertStatusCodeIs(HttpStatus.OK); + members.assertThat().paginationField("count").is("3"); + members.assertThat().entriesListContains("id", user2.getUsername()) + .and().entriesListContains("role", UserRole.SiteCollaborator.toString()); + + STEP("9. Using CMIS create test user U3"); + UserModel user3 = dataUser.createRandomTestUser(); + + STEP("10. A1 add U3 to site1 as site contributor using RestAPI"); + user3.setUserRole(UserRole.SiteContributor); + restAPI.authenticateUser(testUser).withCoreAPI().usingSite(testSitePublic).addPerson(user3); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + STEP("11. A1 get site members using RestAPI"); + members = restAPI.authenticateUser(testUser).withCoreAPI().usingSite(testSitePublic).getSiteMembers(); + restAPI.assertStatusCodeIs(HttpStatus.OK); + members.assertThat().paginationField("count").is("4"); + members.assertThat().entriesListContains("id", user3.getUsername()) + .and().entriesListContains("role", UserRole.SiteContributor.toString()); + + STEP("12. Using CMIS create test user U4"); + UserModel user4 = dataUser.createRandomTestUser(); + + STEP("13. A1 add U4 to site1 as site consumer using RestAPI"); + user4.setUserRole(UserRole.SiteConsumer); + restAPI.authenticateUser(testUser).withCoreAPI().usingSite(testSitePublic).addPerson(user4); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + STEP("14. A1 get site members using RestAPI"); + members = restAPI.authenticateUser(testUser).withCoreAPI().usingSite(testSitePublic).getSiteMembers(); + restAPI.assertStatusCodeIs(HttpStatus.OK); + members.assertThat().paginationField("count").is("5"); + members.assertThat().entriesListContains("id", user4.getUsername()) + .and().entriesListContains("role", UserRole.SiteConsumer.toString()); + + STEP("15. Using CMIS delete test user U1"); + dataUser.deleteUser(user1); + + STEP("16. A1 get site members using RestAPI"); + members = restAPI.authenticateUser(testUser).withCoreAPI().usingSite(testSitePublic).getSiteMembers(); + restAPI.assertStatusCodeIs(HttpStatus.OK); + members.assertThat().paginationField("count").is("4"); + members.assertThat().entriesListDoesNotContain("id", user1.getUsername()); + + STEP("17. Using CMIS delete test user U2"); + dataUser.deleteUser(user2); + + STEP("18. A1 get site members using RestAPI"); + members = restAPI.authenticateUser(testUser).withCoreAPI().usingSite(testSitePublic).getSiteMembers(); + restAPI.assertStatusCodeIs(HttpStatus.OK); + members.assertThat().paginationField("count").is("3"); + members.assertThat().entriesListDoesNotContain("id", user2.getUsername()); + + STEP("19. Using CMIS delete test user U3"); + dataUser.deleteUser(user3); + + STEP("20. A1 get site members using RestAPI"); + members = restAPI.authenticateUser(testUser).withCoreAPI().usingSite(testSitePublic).getSiteMembers(); + restAPI.assertStatusCodeIs(HttpStatus.OK); + members.assertThat().paginationField("count").is("2"); + members.assertThat().entriesListDoesNotContain("id", user3.getUsername()); + + STEP("21. Using CMIS delete test user U4"); + dataUser.deleteUser(user4); + + STEP("22. A1 get site members using RestAPI"); + members = restAPI.authenticateUser(testUser).withCoreAPI().usingSite(testSitePublic).getSiteMembers(); + restAPI.assertStatusCodeIs(HttpStatus.OK); + members.assertThat().paginationField("count").is("1"); + members.assertThat().entriesListDoesNotContain("id", user4.getUsername()); + } + + /** + * Scenario 105 + * 1. Using CMIS create test user U1 + * 2. U1 creates public test site1 using CMIS + * 3. U1 creates file1 using Webdav + * 4. U1 updates file1 properties using CMIS + * 5. U1 gets file1 properties using CMIS + * 6. U1 renames file1 using Webdav + * 7. U1 updates file1 content using FTP + * 8. U1 adds tags to file1 using RestAPI + * 9. U1 updates file1 properties using CMIS + * 10. U1 gets file1 properties using CMIS + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, + description = "Verify file properties with file properties are updated") + public void checkFilePropertiesWhenFileIsUpdated() throws Exception + { + STEP("1. Using CMIS create test user U1"); + UserModel testUser = dataUser.createRandomTestUser(); + + STEP("2. U1 creates public test site1 using CMIS"); + testSitePublic = dataSite.usingUser(testUser).createPublicRandomSite(); + + STEP("3. U1 creates file1 using Webdav"); + FileModel file1 = FileModel.getRandomFileModel(FileType.MSWORD2007); + file1.setContent("content1"); + webDavProtocol.authenticateUser(testUser).usingSite(testSitePublic).createFile(file1); + + STEP("4. U1 updates file1 properties using CMIS"); + String newDescription = "New-" + file1.getDescription(); + String newTitle = "New title-" +file1.getTitle(); + cmisAPI.authenticateUser(testUser).usingSite(testSitePublic).usingResource(file1).updateProperty("cmis:description", newDescription) + .updateProperty("cm:title", newTitle); + + STEP("5. U1 gets file1 properties using CMIS"); + cmisAPI.authenticateUser(testUser).usingResource(file1).assertThat().contentPropertyHasValue("cmis:description", newDescription) + .assertThat().contentPropertyHasValue("cm:title", newTitle); + + STEP("6. U1 renames file1 using Webdav"); + String newName = "Edited-" + file1.getName(); + webDavProtocol.authenticateUser(testUser).usingSite(testSitePublic).usingResource(file1).rename(newName); + + STEP("7. U1 updates file1 content using FTP"); + String newContent = "New " + file1.getContent(); + ftpProtocol.authenticateUser(testUser).usingSite(testSitePublic).usingResource(file1).update(newContent) + .assertThat().contentIs(newContent); + + STEP("8. U1 adds tags to file1 using RestAPI"); + String newTag = RandomData.getRandomName("tag"); + RestTagModel tag = restAPI.authenticateUser(testUser).withCoreAPI().usingResource(file1).addTag(newTag); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + STEP("9. U1 updates file1 properties using CMIS"); + newTitle = "New title2-" + file1.getTitle(); + cmisAPI.authenticateUser(testUser).usingSite(testSitePublic).usingResource(file1).updateProperty("cm:title", newTitle); + + STEP("10. U1 gets file1 properties using CMIS"); + cmisAPI.authenticateUser(testUser).usingResource(file1).assertThat().contentPropertyHasValue("cmis:description", newDescription) + .assertThat().contentPropertyHasValue("cm:title", newTitle) + .assertThat().contentPropertyHasValue("cmis:name", newName) + .assertThat().contentPropertyHasValue("cm:taggable", tag.getId()) + .assertThat().contentIs(newContent); + } +} diff --git a/tests/tas-integration/src/test/java/org/alfresco/tas/integration/IntegrationFullTestsBulk2.java b/tests/tas-integration/src/test/java/org/alfresco/tas/integration/IntegrationFullTestsBulk2.java new file mode 100644 index 0000000000..74d12a0641 --- /dev/null +++ b/tests/tas-integration/src/test/java/org/alfresco/tas/integration/IntegrationFullTestsBulk2.java @@ -0,0 +1,490 @@ +package org.alfresco.tas.integration; + +import static org.alfresco.utility.report.log.Step.STEP; + +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestTagModel; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; +import org.alfresco.utility.exception.DataPreparationException; +import org.alfresco.utility.model.*; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +public class IntegrationFullTestsBulk2 extends IntegrationTest +{ + private UserModel testUser1; + private SiteModel testSitePublic; + private FolderModel testFolder1, testFolder2; + private FileModel wordFile, testFile; + private ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + testUser1 = dataUser.createRandomTestUser(); + + wordFile = FileModel.getRandomFileModel(FileType.MSWORD2007, "tasTesting"); + } + + @BeforeMethod(alwaysRun = true) + public void setup() throws DataPreparationException { + testSitePublic = dataSite.usingUser(testUser1).createPublicRandomSite(); + testFolder1 = FolderModel.getRandomFolderModel(); + testFolder2 = FolderModel.getRandomFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "testContent"); + } + + /** + * Scenario 73 + * 1. Create file1 using ftp + * 2. Open document for edit using CMIS + * 3. Try to edit document using Webdav while checked-out with CMIS + * 4. Copy document to testFolder2 with ftp + * 5. Update document from folder2, check its content is updated with Webdav + * 6. Update document with WebDAV - should fail since document is checked out + * + * @throws Exception + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, + description = "Edit checked out document using several protocols") + public void updateFileUsingDifferentProtocolsWhileDocumentIsCheckedOut() throws Exception + { + STEP("1. Create testFile1 using ftp"); + ftpProtocol.authenticateUser(testUser1).usingSite(testSitePublic).createFolder(testFolder1) + .usingResource(testFolder1).createFile(wordFile) + .assertThat().contentIs("tasTesting"); + + STEP("2. Open document for edit using CMIS"); + cmisAPI.authenticateUser(testUser1).usingResource(wordFile).checkOut(); + FileModel wordFilePWC = cmisAPI.usingResource(wordFile).withCMISUtil().getPWCFileModel(); + + STEP("3. Try to edit document using Webdav while checked-out with CMIS - content should be updated"); + webDavProtocol.authenticateUser(testUser1).usingResource(wordFilePWC).update("update") + .and().assertThat().contentIs("update"); + + STEP("4. Copy document to testFolder2 with ftp"); + FileModel copiedWordFile = new FileModel(wordFile); + ftpProtocol.usingSite(testSitePublic).createFolder(testFolder2) + .usingResource(wordFile).copyTo(testFolder2); + copiedWordFile.setCmisLocation(ftpProtocol.getLastResourceWithoutPrefix()); + ftpProtocol.usingResource(testFolder1).assertThat().hasFiles(wordFile) + .and().usingResource(testFolder2).assertThat().hasFiles(copiedWordFile); + + STEP("5. Update document from folder2, check its content is updated with Webdav"); + webDavProtocol.usingResource(copiedWordFile).update("Step5") + .and().assertThat().contentIs("Step5"); + + STEP("6. Update document with WebDAV"); + webDavProtocol.authenticateUser(testUser1).usingResource(wordFile).update("WebDAVUpdate"); + } + + /** + * Scenario 84 + * 1. Create folder1 with webdav + * 2. Upload new file, file1 with ftp + * 3. Set content for file1 with cmis + * 4. CheckOut file1 with cmis + * 5. Try to edit file while checked-out with ftp + * 6. Cancel checkout with cmis + * 7. Try again to edit file with ftp + * 8. Edit file content using webDav + * 9. Get content using cmis, validate it + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL } ) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, + description = "Update checked out document") + public void updateCheckedOutFile() throws Exception + { + STEP("1. Create folder1 with webdav"); + webDavProtocol.authenticateUser(testUser1).usingSite(testSitePublic).createFolder(testFolder1).and().assertThat().existsInRepo(); + + STEP("2. Upload new file, file1 with ftp"); + ftpProtocol.authenticateUser(testUser1).usingResource(testFolder1).createFile(testFile) + .and().assertThat().existsInRepo().and().assertThat().existsInFtp(); + + STEP("3. Set content for file1 with cmis"); + cmisAPI.authenticateUser(testUser1).usingResource(testFile).update("cmisUpdate") + .and().assertThat().contentIs("testContentcmisUpdate"); + + STEP("4. CheckOut file1 with cmis"); + cmisAPI.usingResource(testFile).checkOut(); + + STEP("5. Try to edit file while checked-out with ftp - content should not be updated since file is checked out"); + ftpProtocol.usingResource(testFile).update("ftpUpdate") + .and().assertThat().contentIs("testContentcmisUpdate"); + + STEP("6. Cancel checkout with cmis"); + cmisAPI.usingResource(testFile).cancelCheckOut(); + + STEP("7. Try again to edit file with ftp"); + ftpProtocol.usingResource(testFile).update("ftpUpdate") + .and().assertThat().contentIs("ftpUpdate"); + + STEP("8. Edit file content using webDav"); + webDavProtocol.usingResource(testFile).update("webdavUpdate").and().assertThat().contentIs("webdavUpdate"); + + STEP("9. Get content using cmis, validate it"); + cmisAPI.usingResource(testFile).assertThat().contentIs("webdavUpdate"); + } + + /** + * 1. Create folder1 with cmis + * 2. Add new file with webdav + * 3. Open file with Manager, add some content, save with webdav + * 4. Open file with Consumer, add some content, save with ftp + * 5. Open file with Contributor, delete some content, save with webdav + * 6. Open file with Collaborator, add some content, save with WebDAV + * 7. Open file with Consumer, delete some content, save with webdav + * 8. Open file with Manager, add new content, save with cmis + * 9. Open file with Collaborator, delete content that Manager added with ftp + * 10. Open file with Manager, add new content with webdav + * 11. Delete all content with admin using FTP + * 12. Delete file with cmis + * 13. Check file is deleted with WebDAV + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, + description = "Update file with different user roles and protocols") + public void updateFileWithDifferentRolesUsingDifferentProtocols() throws Exception + { + usersWithRoles = dataUser.addUsersWithRolesToSite(testSitePublic, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, + UserRole.SiteContributor); + + STEP("1. Create folder1 with cmis"); + cmisAPI.authenticateUser(testUser1).usingSite(testSitePublic).createFolder(testFolder1).and().assertThat().existsInRepo(); + + STEP("2. Add new file with webdav"); + webDavProtocol.authenticateUser(testUser1).usingResource(testFolder1).createFile(testFile).and().assertThat().existsInRepo(); + + STEP("3. Open file with Manager, add some content, save with webdav"); + webDavProtocol.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).usingResource(testFile).update("webdavUpdate") + .and().assertThat().contentIs("webdavUpdate"); + + STEP("4. Open file with Consumer, add some content, save with ftp"); + ftpProtocol.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .usingResource(testFile).update("ftpUpdate").and().assertThat().contentIs("webdavUpdate"); + + STEP("5. Open file with Contributor, delete some content, save with webdav"); + webDavProtocol.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .usingResource(testFile).update("webdavUpdate").and().assertThat().contentIs("webdavUpdate"); + + STEP("6. Open file with Collaborator, add some content, save with WebDAV"); + webDavProtocol.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .usingResource(testFile).update("webdavUpdate2").and().assertThat().contentIs("webdavUpdate2"); + + STEP("7. Open file with Consumer, delete some content, save with webdav"); + webDavProtocol.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .usingResource(testFile).update("webdavUpdate3").and().assertThat().contentIs("webdavUpdate2"); + + STEP("8. Open file with Manager, add new content, save with cmis"); + cmisAPI.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .usingResource(testFile).update("cmisUpdate").and().assertThat().contentIs("webdavUpdate2cmisUpdate"); + + STEP("9. Open file with Collaborator, delete content that Manager added with ftp"); + ftpProtocol.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .usingResource(testFile).update("ftpUpdate").and().assertThat().contentIs("ftpUpdate"); + + STEP("10. Open file with Contributor, add new page with webdav"); + webDavProtocol.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .usingResource(testFile).update("webdavUpdate").and().assertThat().contentIs("webdavUpdate"); + + STEP("11. Delete all content with admin using FTP"); + ftpProtocol.authenticateUser(dataUser.getAdminUser()) + .usingResource(testFile).update("").and().assertThat().contentIs(""); + + STEP("12. Delete file with cmis"); + cmisAPI.usingResource(testFile).delete().and().assertThat().doesNotExistInRepo(); + + STEP("13. Check file is deleted with WebDAV"); + webDavProtocol.authenticateUser(testUser1).usingResource(testFile).assertThat().doesNotExistInWebdav(); + } + + /** + * 1. Add file1 to document library with ftp + * 2. Update file content with WebDAV + * 3. Add a minor change to a document with cmis + * 4. Add a change with webdav, check document version with cmis + * 5. Add a major change to a document with cmis + * 6. Delete document last version with cmis + * 7. Try to edit previous version with cmis + * 8. Update content with ftp, check version + * 9. Check document content with WebDAV + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, + description = "Check document versioning") + public void documentVersioningTest() throws Exception + { + STEP("1. Add file1 to document library with ftp"); + ftpProtocol.authenticateUser(testUser1).usingSite(testSitePublic).createFile(testFile).and().assertThat().existsInRepo(); + + STEP("2. Update file content with WebDAV"); + webDavProtocol.authenticateUser(testUser1).usingResource(testFile).update("WebDAVUpdate").and().assertThat().contentIs("WebDAVUpdate"); + + STEP("3. Add a minor change to a document with cmis"); + cmisAPI.authenticateUser(testUser1).usingResource(testFile).update("cmisUpdate") + .then().assertThat().documentHasVersion(1.1).and().assertThat().contentIs("WebDAVUpdatecmisUpdate"); + + STEP("4. Check document version with webdav"); + webDavProtocol.authenticateUser(testUser1).usingResource(testFile).update("webdavUpdate"); + cmisAPI.assertThat().documentHasVersion(1.2); + + STEP("5. Add a major change to a document with cmis"); + cmisAPI.authenticateUser(testUser1).usingResource(testFile).checkOut().prepareDocumentForCheckIn().withMajorVersion().checkIn() + .and().assertThat().documentHasVersion(2.0); + + STEP("6. Delete document last version with cmis"); + cmisAPI.usingResource(testFile).deleteAllVersions(false).and().assertThat().documentHasVersion(1.2); + + STEP("7. Try to edit previous version with cmis"); + cmisAPI.authenticateUser(testUser1).usingResource(testFile).update("cmisUpdate") + .then().assertThat().documentHasVersion(1.3).and().assertThat().contentIs("webdavUpdatecmisUpdate"); + + STEP("8. Update content with ftp, check version"); + ftpProtocol.usingResource(testFile).update("ftpUpdate"); + cmisAPI.assertThat().documentHasVersion(1.4); + + STEP("9. Check document content with WebDAV"); + webDavProtocol.authenticateUser(testUser1).usingResource(testFile).assertThat().contentIs("ftpUpdate"); + } + + /** + * Scenario 82 + * 1. Create user1, user2 + * 2. User1 creates site1 and invites user2 as manager + * 3. User1 adds document1 and tag1 to doc + * 4. User2 gets tags and verifies tag1 appears + * 5. User2 delete tag1 + * 6. User1 tries to update tag1 + * 7. User1 add new tag tag2 + * 8. User2 verifies tag2 appears and tag1 is not in the list + * 9. User2 deletes document1 + * 10. User1 tries to delete tag2 + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Check negative scenarios for tags") + public void tagsNegativeScenariosTest() throws Exception + { + STEP("1. Create user1, user2"); + UserModel user1 = dataUser.createRandomTestUser(); + UserModel user2 = dataUser.createRandomTestUser(); + user2.setUserRole(UserRole.SiteManager); + + STEP("2. User1 creates site1 and invites user2 as manager"); + SiteModel site = dataSite.usingUser(user1).createPublicRandomSite(); + restAPI.authenticateUser(user1).withCoreAPI().usingSite(site).addPerson(user2); + + STEP("3. User1 adds document1 and tag1 to doc"); + dataContent.usingUser(user1).usingSite(site).createContent(testFile); + RestTagModel tag = restAPI.withCoreAPI().usingResource(testFile).addTag("tag1"); + restAPI.withCoreAPI().usingResource(testFile).getNodeTags().assertThat().entriesListContains("tag", "tag1"); + + STEP("4. User2 gets tags and verifies tag1 appears"); + restAPI.authenticateUser(user2).withCoreAPI().usingResource(testFile).getNodeTags().assertThat().entriesListContains("tag", "tag1"); + + STEP("5. User2 delete tag1"); + restAPI.withCoreAPI().usingResource(testFile).deleteTag(tag); + restAPI.withCoreAPI().usingResource(testFile).getNodeTags().assertThat().entriesListDoesNotContain("tag", "tag1"); + + STEP("6. User1 tries to update tag1"); + restAPI.authenticateUser(user2).withCoreAPI().usingTag(tag).update("updatedTag"); + restAPI.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED) + .containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY); + + STEP("7. User1 add new tag tag2"); + tag = restAPI.authenticateUser(user1).withCoreAPI().usingResource(testFile).addTag("tag2"); + restAPI.withCoreAPI().usingResource(testFile).getNodeTags().assertThat().entriesListContains("tag", "tag2"); + + STEP("8. User2 verifies tag2 appears and tag1 is not in the list"); + restAPI.authenticateUser(user2).withCoreAPI().usingResource(testFile).getNodeTags() + .assertThat().entriesListDoesNotContain("tag", "tag1") + .assertThat().entriesListContains("tag", "tag2"); + + STEP("9. User2 deletes document1"); + dataContent.usingUser(user2).usingResource(testFile).deleteContent(); + + STEP("10. User1 tries to delete tag2"); + restAPI.authenticateUser(user1).withCoreAPI().usingResource(testFile).deleteTag(tag); + restAPI.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, testFile.getNodeRefWithoutVersion())) + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY); + } + + /** + * Scenario 83 + * 1. Create user1, user2 + * 2. User1 creates site1 and invites user2 as manager with rest api + * 3. User1 adds document1 with webdav + * 4. User2 reads the document1 with ftp + * 5. User1 update document1 with WebDAV + * 6. User2 update the document1 with WebDAV + * 7. User1 deletes the document1 with ftp + * 8. Verify user2 cannot update document1 with cmis + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }, expectedExceptions = CmisObjectNotFoundException.class, expectedExceptionsMessageRegExp = ".*Object not found:.*") + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, description = "Negative scenarios for update document") + public void fileUpdateNegativeScenariosTest() throws Exception + { + STEP("1. Create user1, user2"); + UserModel user1 = dataUser.createRandomTestUser(); + UserModel user2 = dataUser.createRandomTestUser(); + user2.setUserRole(UserRole.SiteManager); + + STEP("2. User1 creates site1 and invites user2 as manager with rest api"); + SiteModel site = dataSite.usingUser(user1).createPublicRandomSite(); + restAPI.authenticateUser(user1).withCoreAPI().usingSite(site).addPerson(user2); + + STEP("3. User1 adds document1 with webdav"); + webDavProtocol.authenticateUser(user1).usingSite(site).createFile(testFile).and().assertThat().existsInRepo(); + + STEP("4. User2 reads the document1 with ftp"); + ftpProtocol.authenticateUser(user2).usingResource(testFile).assertThat().contentIs("testContent"); + + STEP("5. User1 update document1 with WebDAV"); + webDavProtocol.authenticateUser(user1).usingResource(testFile).update("WebDAVUpdate1").assertThat().contentIs("WebDAVUpdate1"); + + STEP("6. User2 update the document1 with WebDAV"); + webDavProtocol.authenticateUser(user2).usingResource(testFile).update("WebDAVUpdate2").assertThat().contentIs("WebDAVUpdate2"); + + STEP("7. User1 deletes the document1 with ftp"); + ftpProtocol.authenticateUser(user1).usingResource(testFile).delete().assertThat().doesNotExistInFtp().assertThat().doesNotExistInRepo(); + + STEP("8. Verify user2 cannot update document1 with cmis"); + cmisAPI.authenticateUser(user2).usingResource(testFile).update("cmisUpdate"); + } + + /** + * Scenario 85 + * 1. Upload file with CMIS + * 2. Add some content with ftp + * 3. Add a minor change to document, 1.2 with cmis + * 4. Add a major change to document, 2.0 with cmis + * 5. Add a minor change to document, 2.1 with cmis + * 6. Delete version 2.0 with cmis with cmis + * 7. Get document version with cmis + * 8. Try to edit version 2.0 with cmis + * 9. Delete version 2.1 with cmis + * 10. Get document version with cmis + * 11. Try to edit version 2.0 with cmis + * 12. Check document content with ftp + * 13. Check document version with cmis + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, + description = "File versioning test scenarios") + public void fileVersioningScenariosTest() throws Exception + { + STEP("1. Upload file with CMIS"); + cmisAPI.authenticateUser(testUser1).usingSite(testSitePublic).createFile(testFile).and().assertThat().existsInRepo(); + + STEP("2. Add some content with ftp "); + ftpProtocol.authenticateUser(testUser1).usingResource(testFile).update("ftpUpdate").and().assertThat().contentIs("ftpUpdate"); + + STEP("3. Add a minor change to document, 1.1 with cmis"); + cmisAPI.usingResource(testFile).checkOut().prepareDocumentForCheckIn().withContent("cmisUpdate") + .withMinorVersion().checkIn().refreshResource().and().assertThat().documentHasVersion(1.2); + + STEP("4. Add a major change to document, 2.0 with cmis"); + cmisAPI.usingResource(testFile).checkOut().prepareDocumentForCheckIn().withContent("cmisUpdate") + .withMajorVersion().checkIn().and().assertThat().documentHasVersion(2.0); + + STEP("5. Add a minor change to document, 2.1 with cmis"); + cmisAPI.usingResource(testFile).checkOut().prepareDocumentForCheckIn().withContent("cmisUpdate") + .withMinorVersion().checkIn().and().assertThat().documentHasVersion(2.1); + + STEP("6. Delete version 2.0 with cmis with cmis"); + cmisAPI.usingResource(testFile).deleteAllVersions(false); + + STEP("7. Get document version with cmis"); + cmisAPI.usingResource(testFile).assertThat().documentHasVersion(2.0); + + STEP("8. Try to edit version 2.0 with cmis"); + cmisAPI.usingResource(testFile).update("cmisUpdate").and().assertThat().contentIs("cmisUpdatecmisUpdate") + .and().assertThat().documentHasVersion(2.1); + + STEP("9. Delete version 2.1 with cmis"); + cmisAPI.usingResource(testFile).deleteAllVersions(false); + + STEP("10. Get document version with cmis"); + cmisAPI.usingResource(testFile).assertThat().documentHasVersion(2.0); + + STEP("11. Try to edit version 2.0 with cmis"); + cmisAPI.usingResource(testFile).update("cmisUpdate").and().assertThat().contentIs("cmisUpdatecmisUpdate") + .and().assertThat().documentHasVersion(2.1); + + STEP("12. Update and check document content with ftp"); + ftpProtocol.authenticateUser(testUser1).usingResource(testFile).update("ftpUpdate").assertThat().contentIs("ftpUpdate"); + + STEP("13. Check document version with cmis"); + cmisAPI.usingResource(testFile).assertThat().documentHasVersion(2.2); + } + + /** + * 1. Upload file with cmis + * 2. Add some content with WebDAV + * 3. Add a minor change to document, 1.2 with cmis + * 4. Add a major change to document, 2.0 with cmis + * 5. Add a minor change to document, 2.1 with cmis + * 6. Delete version 2.1 with cmis + * 7. Try to edit the last version (which is now 2.0) with webdav + * 8. Check version with CMIS + * 9. Add new major change, version 3.0 with cmis + * 10. Delete previous version with cmis + * 11. Delete document with ftp + * 12. Check document version with cmis + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }, expectedExceptionsMessageRegExp = ".*Version Series not found.*", + expectedExceptions = CmisObjectNotFoundException.class) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, + description = "File versioning additional test scenarios") + public void fileVersioningNegativeScenariosTest() throws Exception + { + STEP("1. Upload file with cmis"); + cmisAPI.authenticateUser(testUser1).usingSite(testSitePublic).createFile(testFile).and().assertThat().existsInRepo(); + + STEP("2. Add some content with WebDAV"); + webDavProtocol.authenticateUser(testUser1).usingResource(testFile).update("WebDAVUpdate").and().assertThat().contentIs("WebDAVUpdate"); + + STEP("3. Add a minor change to document, 1.2 with cmis"); + cmisAPI.usingResource(testFile).checkOut().prepareDocumentForCheckIn().withContent("cmisUpdate") + .withMinorVersion().checkIn().refreshResource().and().assertThat().documentHasVersion(1.2); + + STEP("4. Add a major change to document, 2.0 with cmis"); + cmisAPI.usingResource(testFile).checkOut().prepareDocumentForCheckIn().withContent("cmisUpdate") + .withMajorVersion().checkIn().and().assertThat().documentHasVersion(2.0); + + STEP("5. Add a minor change to document, 2.1 with cmis"); + cmisAPI.usingResource(testFile).checkOut().prepareDocumentForCheckIn().withContent("cmisUpdate") + .withMinorVersion().checkIn().refreshResource().and().assertThat().documentHasVersion(2.1); + + STEP("6. Delete version 2.1 with cmis"); + cmisAPI.usingResource(testFile).deleteAllVersions(false).assertThat().documentHasVersion(2.0); + + STEP("7. Try to edit the last version (which is now 2.0) with webdav"); + webDavProtocol.authenticateUser(testUser1).usingResource(testFile).update("webdavUpdate"); + + STEP("8. Check version with CMIS"); + cmisAPI.usingResource(testFile).assertThat().documentHasVersion(2.1); + + STEP("9. Add new major change, version 3.0 with cmis"); + cmisAPI.usingResource(testFile).checkOut().prepareDocumentForCheckIn().withContent("cmisUpdate") + .withMajorVersion().checkIn().and().assertThat().documentHasVersion(3.0); + + STEP("10. Delete previous version with cmis"); + cmisAPI.usingResource(testFile).deleteAllVersions(false).assertThat().documentHasVersion(2.1); + + STEP("11. Delete document with ftp"); + ftpProtocol.authenticateUser(testUser1).usingResource(testFile).delete().assertThat().doesNotExistInRepo(); + + STEP("12. Check document version with cmis - should fail"); + cmisAPI.usingResource(testFile).assertThat().documentHasVersion(2.1); + } +} \ No newline at end of file diff --git a/tests/tas-integration/src/test/java/org/alfresco/tas/integration/IntegrationFullTestsBulk3.java b/tests/tas-integration/src/test/java/org/alfresco/tas/integration/IntegrationFullTestsBulk3.java new file mode 100644 index 0000000000..5a855da02d --- /dev/null +++ b/tests/tas-integration/src/test/java/org/alfresco/tas/integration/IntegrationFullTestsBulk3.java @@ -0,0 +1,433 @@ +package org.alfresco.tas.integration; + +import static org.alfresco.utility.report.log.Step.STEP; + +import org.alfresco.rest.model.RestCommentModelsCollection; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.utility.Utility; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +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.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class IntegrationFullTestsBulk3 extends IntegrationTest +{ + private UserModel testUser1, testUser2; + private SiteModel publicSite, moderatedSite, privateSite; + private RestCommentModelsCollection comments; + private FileModel testFile1, testFile2, wordFile ; + private ListUserWithRoles usersWithRoles; + private FolderModel testFolder1; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + testUser1 = dataUser.createRandomTestUser(); + testFolder1 = FolderModel.getRandomFolderModel(); + publicSite = dataSite.usingUser(testUser1).createPublicRandomSite(); + } + + /** + * Scenario 64 + * 1. Create folder1 with WEBDAV + * 2. Create wordFile inside folder1 with CMIS + * 3. Delete wordFile content with CMIS + * 4. Update content using Collaborator role with CMIS + * 5. Append content using Manager role with WebDAV + * 6. Delete content that Manager added using Collaborator role with CMIS + * 7. Rename wordFile with WebDAV + * 9. Delete wordFile with WEBDAV + * + * @throws Exception + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, + description = "File handling using several protocols") + public void fileHandlingWithCollaboratorRole() throws Exception + { + String contentCollaborator = "content added by Collaborator"; + publicSite = dataSite.usingUser(testUser1).createPublicRandomSite(); + usersWithRoles = dataUser.addUsersWithRolesToSite(publicSite, UserRole.SiteCollaborator); + wordFile = FileModel.getRandomFileModel(FileType.MSWORD2007, "tasTesting"); + + STEP("1. Create folder1 with webdav"); + webDavProtocol.authenticateUser(testUser1).usingSite(publicSite).createFolder(testFolder1).and().assertThat().existsInRepo(); + + STEP("2. Create testFile1 inside folder1 using CMIS"); + cmisAPI.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingSite(publicSite).usingResource(testFolder1).createFile(wordFile) + .assertThat().existsInRepo(); + + STEP("3. Delete wordFile content with WebDAV"); + cmisAPI.authenticateUser(testUser1).usingResource(wordFile).deleteContent(); + + STEP("4. Update content using Collaborator role with CMIS"); + cmisAPI.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .usingResource(wordFile).update(contentCollaborator) + .assertThat().contentIs(contentCollaborator); + + STEP("5. Append content using Manager role with WebDAV"); + webDavProtocol.authenticateUser(testUser1).usingResource(wordFile).update("content added by Manager").assertThat().contentIs("content added by Manager"); + + STEP("6. Delete content that Manager added using Collaborator role with CMIS"); + cmisAPI.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .usingResource(wordFile).deleteAllVersions(false) + .and().assertThat().documentHasVersion(1.2); + + STEP("7. Rename wordFile with FTP"); + ftpProtocol.authenticateUser(testUser1).usingResource(wordFile).rename("renamedFile.docx"); + + STEP("8. Delete file with WEBDAV"); + webDavProtocol.authenticateUser(testUser1).usingResource(wordFile).delete() + .assertThat().doesNotExistInRepo(); + } + + /** + * Scenario 65 + * 1. Create folder1 with WEBDAV + * 2. Create wordFile inside folder1 with CMIS + * 3. Delete wordFile content with CMIS + * 4. Update content using Contributor role with CMIS + * 5. Append content using Manager role with WebDAV + * 6. Delete content that Manager added using Collaborator role with CMIS + * 7. Rename wordFile with WEBDAV + * 8. Delete wordFile with FTP + * + * @throws Exception + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, + description = "File handling using several protocols") + public void fileHandlingWithContributorRole() throws Exception + { + String contentContributor = "content added by Contributor"; + publicSite = dataSite.usingUser(testUser1).createPublicRandomSite(); + usersWithRoles = dataUser.addUsersWithRolesToSite(publicSite, UserRole.SiteContributor); + wordFile = FileModel.getRandomFileModel(FileType.MSWORD2007, "tasTesting"); + + STEP("1. Create folder1 with webdav"); + webDavProtocol.authenticateUser(testUser1).usingSite(publicSite).createFolder(testFolder1).and().assertThat().existsInRepo(); + + STEP("2. Create testFile1 inside folder1 using CMIS"); + cmisAPI.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .usingResource(testFolder1).createFile(wordFile) + .assertThat().existsInRepo(); + + STEP("3. Delete wordFile content with CMIS"); + cmisAPI.authenticateUser(testUser1).usingResource(wordFile).deleteContent(); + + STEP("4. Update content using Contributor role with CMIS"); + cmisAPI.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .usingResource(wordFile).update(contentContributor) + .assertThat().contentIs(contentContributor); + + STEP("5. Append content using Manager role with WebDAV"); + webDavProtocol.authenticateUser(testUser1) + .usingResource(wordFile).update("content added by Manager") + .assertThat().contentIs("content added by Manager"); + + STEP("6. Delete content that Manager added using Contributor role with CMIS"); + cmisAPI.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .usingResource(wordFile).deleteAllVersions(false) + .and().assertThat().documentHasVersion(1.2); + + STEP("7. Rename wordFile with WebDAV"); + webDavProtocol.authenticateUser(testUser1).usingResource(wordFile).rename("renamedFile.docx"); + + STEP("8. Delete file with FTP"); + ftpProtocol.authenticateUser(testUser1).usingResource(wordFile).delete().assertThat().doesNotExistInRepo(); + } + + /** + * Scenario 76 + * 1. Using CMIS create two users: u1 and u2 + * 2. U1 creates a public site using CMIS + * 3. U1 creates testFile1 in public site's document library using FTP + * 4. U1 adds comment1 for testFile1 using REST API + * 5. U2 gets comment1 using REST API + * 6. U1 updates testFile1 using WEBDAV + * 7. U2 gets comment1 using REST API + * 8. U1 deletes testFile1 using WebDAV + * 9. U2 can not get comment1 using REST API + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, + description = "Verify comment is deleted .") + public void negativeScenarioWithComments() throws Exception + { + STEP("* 1. Using CMIS create two users: u1 and u2"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + + STEP("* 2. U1 creates a public site using CMIS"); + publicSite = dataSite.usingUser(testUser1).createPublicRandomSite(); + + STEP("* 3. U1 creates a file in public site's document library using FTP"); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file1 content"); + ftpProtocol.authenticateUser(testUser1).usingSite(publicSite).createFile(testFile1).then().assertThat().existsInRepo(); + + STEP("* 4. U1 adds comment1 for testFile1 using REST API"); + String newComment = "This is a new comment added by " + testUser1.getUsername(); + restAPI.authenticateUser(testUser1).withCoreAPI().usingResource(testFile1).addComment(newComment).assertThat().field("content").isNotEmpty().and().field("content").is(newComment); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + + STEP("* 5. U2 gets comment1 using REST API"); + comments = restAPI.authenticateUser(testUser2).withCoreAPI().usingResource(testFile1).getNodeComments(); + restAPI.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", newComment); + + STEP("* 6. U1 updates testFile1 using WEBDAV"); + String newContent = "This is new content added by " + testUser1.getUsername(); + webDavProtocol.authenticateUser(testUser1).usingResource(testFile1).update(newContent).and().assertThat().contentIs(newContent); + + STEP("* 7. U2 gets comment1 using REST API"); + comments = restAPI.authenticateUser(testUser2).withCoreAPI().usingResource(testFile1).getNodeComments(); + restAPI.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", newComment); + + STEP("* 8. U1 deletes testFile1 using WebDAV"); + webDavProtocol.authenticateUser(testUser1).usingResource(testFile1).delete().and().assertThat().doesNotExistInRepo(); + + STEP("* 9. U2 can not get comment1 using REST API"); + comments = restAPI.authenticateUser(testUser2).withCoreAPI().usingResource(testFile1).getNodeComments(); + restAPI.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, testFile1.getNodeRef())); + } + + /** + * Scenario 77 + * 1. Using CMIS create two users: u1 and u2 + * 2. U1 creates a public site using CMIS + * 3. U1 creates a file in public site's document library using FTP + * 4. U1 applyAcl(permission) for U2 with role Site Manager to the document using CMIS + * 5. U2 edits the document using FTP + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, + description = "Verify manager permission to a document in a public site - is able to edit document.") + public void addManagerPermissionToADocumentFromPublicSite() throws Exception + { + STEP("* 1. Using CMIS create two users: u1 and u2"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + + STEP("* 2. U1 creates a public site using CMIS"); + publicSite = dataSite.usingUser(testUser1).createPublicRandomSite(); + + STEP("* 3. U1 creates a file in public site's document library using FTP"); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file1 content"); + ftpProtocol.authenticateUser(testUser1).usingSite(publicSite).createFile(testFile1).then().assertThat().existsInRepo(); + + STEP("* 4. U1 applyAcl(permission) for U2 with role Site Manager to the document using CMIS"); + cmisAPI.authenticateUser(testUser1).usingResource(testFile1).addAcl(testUser2, UserRole.SiteManager).then().assertThat().permissionIsSetForUser(testUser2, UserRole.SiteManager); + + STEP("* 5. U2 edits the document using FTP"); + ftpProtocol.authenticateUser(testUser2).usingSite(publicSite).usingResource(testFile1).update("new Content").assertThat().contentIs("new Content"); + } + + /** + * Scenario 78 + * 1. Using CMIS create two users: u1 and u2 + * 2. U1 creates a public site using CMIS + * 3. U1 creates a file in public site's document library using FTP + * 4. U1 applyAcl(permission) for U2 with role Site Collaborator to the document using CMIS + * 5. U2 edits the document using FTP + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, + description = "Verify collaborator permission to a document in a public site - is able to edit document.") + public void addCollaboratorPermissionToADocumentFromPublicSite() throws Exception + { + STEP("* 1. Using CMIS create two users: u1 and u2"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + + STEP("* 2. U1 creates a public site using CMIS"); + publicSite = dataSite.usingUser(testUser1).createPublicRandomSite(); + + STEP("* 3. U1 creates a file in public site's document library using FTP"); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file1 content"); + ftpProtocol.authenticateUser(testUser1).usingSite(publicSite).createFile(testFile1).then().assertThat().existsInRepo(); + + STEP("* 4. U1 applyAcl(permission) for U2 with role Site Manager to the document using CMIS"); + cmisAPI.authenticateUser(testUser1).usingResource(testFile1).addAcl(testUser2, UserRole.SiteCollaborator).then().assertThat().permissionIsSetForUser(testUser2, UserRole.SiteCollaborator); + + STEP("* 5. U2 edits the document using FTP"); + ftpProtocol.authenticateUser(testUser2).usingSite(publicSite).usingResource(testFile1).update("new Content").assertThat().contentIs("new Content"); + } + + /** + * Scenario 79 + * 1. Using CMIS create two users: u1 and u2 + * 2. U1 creates a public site using CMIS + * 3. U1 creates a file in public site's document library using FTP + * 4. U1 applyAcl(permission) for U2 with role Site Contributor to the document using CMIS + * 5. U2 edits the document using FTP + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, + description = "Verify contributor permission to a document in a public site - is not able to edit document.") + public void addContributorPermissionToADocumentFromPublicSite() throws Exception + { + STEP("* 1. Using CMIS create two users: u1 and u2"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + + STEP("* 2. U1 creates a public site using CMIS"); + publicSite = dataSite.usingUser(testUser1).createPublicRandomSite(); + + STEP("* 3. U1 creates a file in public site's document library using FTP"); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file1 content"); + ftpProtocol.authenticateUser(testUser1).usingSite(publicSite).createFile(testFile1).then().assertThat().existsInRepo(); + + STEP("* 4. U1 applyAcl(permission) for U2 with role Site Manager to the document using CMIS"); + cmisAPI.authenticateUser(testUser1).usingResource(testFile1).addAcl(testUser2, UserRole.SiteContributor).then().assertThat().permissionIsSetForUser(testUser2, UserRole.SiteContributor); + + STEP("* 5. U2 edits the document using FTP"); + ftpProtocol.authenticateUser(testUser2).usingSite(publicSite).usingResource(testFile1).update("new Content"); + ftpProtocol.authenticateUser(testUser1).usingSite(publicSite).usingResource(testFile1).assertThat().contentIs("file1 content"); + } + + /** + * Scenario 80 + * 1. Using CMIS create two users: u1 and u2 + * 2. U1 creates a public site using CMIS + * 3. U1 creates a file in public site's document library using FTP + * 4. U1 applyAcl(permission) for U2 with role Site Consumer to the document using CMIS + * 5. U2 edits the document using FTP + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, + description = "Verify consumer permission to a document in a public site - is not able to edit document.") + public void addConsumerPermissionToADocumentFromPublicSite() throws Exception + { + STEP("* 1. Using CMIS create two users: u1 and u2"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + + STEP("* 2. U1 creates a public site using CMIS"); + publicSite = dataSite.usingUser(testUser1).createPublicRandomSite(); + + STEP("* 3. U1 creates a file in public site's document library using FTP"); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file1 content"); + ftpProtocol.authenticateUser(testUser1).usingSite(publicSite).createFile(testFile1).then().assertThat().existsInRepo(); + + STEP("* 4. U1 applyAcl(permission) for U2 with role Site Manager to the document using CMIS"); + cmisAPI.authenticateUser(testUser1).usingResource(testFile1).addAcl(testUser2, UserRole.SiteConsumer).then().assertThat().permissionIsSetForUser(testUser2, UserRole.SiteConsumer); + + STEP("* 5. U2 edits the document using FTP"); + ftpProtocol.authenticateUser(testUser2).usingSite(publicSite).usingResource(testFile1).update("new Content"); + ftpProtocol.authenticateUser(testUser1).usingSite(publicSite).usingResource(testFile1).assertThat().contentIs("file1 content"); + } + + /** + * Scenario 107 + * 1. Using CMIS create two users: u1 and u2 + * 2. U1 creates a moderated site using CMIS + * 3. U1 creates a file in moderated site's document library using FTP + * 4. U1 applyAcl(permission) for U2 with role Site Manager to the document using CMIS + * 5. U2 edits the document using FTP + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, + description = "Verify manager permission to a document in a moderated site - is not able to edit document.") + public void addManagerPermissionToADocumentFromModeratedSite() throws Exception + { + STEP("* 1. Using CMIS create two users: u1 and u2"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + + STEP("* 2. U1 creates a moderated site using CMIS"); + moderatedSite = dataSite.usingUser(testUser1).createModeratedRandomSite(); + + STEP("* 3. U1 creates a file in moderated site's document library using FTP"); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file1 content"); + ftpProtocol.authenticateUser(testUser1).usingSite(moderatedSite).createFile(testFile1).then().assertThat().existsInRepo(); + + STEP("* 4. U1 applyAcl(permission) for U2 with role Site Manager to the document using CMIS"); + cmisAPI.authenticateUser(testUser1).usingResource(testFile1).addAcl(testUser2, UserRole.SiteManager).then().assertThat().permissionIsSetForUser(testUser2, UserRole.SiteManager); + + STEP("* 5. U2 edits the document using FTP"); + ftpProtocol.authenticateUser(testUser2).usingSite(moderatedSite).usingResource(testFile1).update("new Content"); + ftpProtocol.authenticateUser(testUser1).usingSite(moderatedSite).usingResource(testFile1).assertThat().contentIs("file1 content"); + } + + /** + * Scenario 108 + * 1. Using CMIS create two users: u1 and u2 + * 2. U1 creates a private site using CMIS + * 3. U1 creates a file in private site's document library using FTP + * 4. U1 applyAcl(permission) for U2 with role Site Manager to the document using CMIS + * 5. U2 edits the document using FTP + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.REGRESSION, + description = "Verify manager permission to a document in a private site - is not able to edit document.") + public void addManagerPermissionToADocumentFromPrivateSite() throws Exception + { + STEP("* 1. Using CMIS create two users: u1 and u2"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + + STEP("* 2. U1 creates a private site using CMIS"); + privateSite = dataSite.usingUser(testUser1).createPrivateRandomSite(); + + STEP("* 3. U1 creates a file in private site's document library using FTP"); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file1 content"); + ftpProtocol.authenticateUser(testUser1).usingSite(privateSite).createFile(testFile1).then().assertThat().existsInRepo(); + + STEP("* 4. U1 applyAcl(permission) for U2 with role Site Manager to the document using CMIS"); + cmisAPI.authenticateUser(testUser1).usingResource(testFile1).addAcl(testUser2, UserRole.SiteManager).then().assertThat().permissionIsSetForUser(testUser2, UserRole.SiteManager); + + STEP("* 5. U2 edits the document using FTP"); + ftpProtocol.authenticateUser(testUser2).usingSite(privateSite).usingResource(testFile1).update("new Content"); + ftpProtocol.authenticateUser(testUser1).usingSite(privateSite).usingResource(testFile1).assertThat().contentIs("file1 content"); + } + + /** + * Scenario 60 + * 1. Using CMIS creates one test user: u1 + * 2. U1 creates testFile1 in public site using FTP + * 3. U1 creates testFile2 in public site using FTP + * 4. U1 updates testFile2 using FTP + * 5. Compare created date with modified date + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT}, executionType = ExecutionType.REGRESSION, description = "Compare Modified Date") + public void manageModificationTimeOfFile() throws Exception + { + STEP("1. Using CMIS creates one test user: u1"); + testUser1 = dataUser.createRandomTestUser(); + + STEP("2. U1 creates testFile1 in a public site using FTP"); + publicSite = dataSite.usingUser(testUser1).createPublicRandomSite(); + testFile1 = new FileModel("testFile1", FileType.TEXT_PLAIN); + ftpProtocol.authenticateUser(testUser1).usingSite(publicSite).createFile(testFile1).assertThat().existsInRepo(); + String modifiedDate1 = ftpProtocol.getModificationTime(); + + STEP("3. U1 creates testFile2 in a public site using FTP"); + publicSite = dataSite.usingUser(testUser1).createPublicRandomSite(); + testFile2 = new FileModel("testFile1", FileType.TEXT_PLAIN); + Utility.waitToLoopTime(2); + ftpProtocol.usingSite(publicSite).createFile(testFile2).assertThat().existsInRepo(); + String modifiedDate2 = ftpProtocol.getModificationTime(); + Utility.waitToLoopTime(2, "Waiting for update"); + + STEP("4. U1 updates testFile2 in a public site using FTP"); + ftpProtocol.update("test update").assertThat().contentIs("test update"); + String updatedDate2 = ftpProtocol.getModificationTime(); + + STEP("5. Compare created date with modified date"); + Assert.assertNotEquals(modifiedDate1, modifiedDate2, "Updated and modified dates are equal"); + Assert.assertNotEquals(modifiedDate2, updatedDate2, "Modified and updated dates are equal"); + } + +} \ No newline at end of file diff --git a/tests/tas-integration/src/test/java/org/alfresco/tas/integration/IntegrationSanityTests.java b/tests/tas-integration/src/test/java/org/alfresco/tas/integration/IntegrationSanityTests.java new file mode 100644 index 0000000000..c80db30096 --- /dev/null +++ b/tests/tas-integration/src/test/java/org/alfresco/tas/integration/IntegrationSanityTests.java @@ -0,0 +1,1108 @@ +package org.alfresco.tas.integration; + +import static org.alfresco.utility.report.log.Step.STEP; + +import java.util.ArrayList; +import java.util.List; + +import javax.mail.MessagingException; + +import org.alfresco.rest.model.RestCommentModel; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestTagModel; +import org.alfresco.utility.Utility; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.RandomData; +import org.alfresco.utility.model.*; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 10/25/2016. + */ +public class IntegrationSanityTests extends IntegrationTest +{ + UserModel testUser1, testUser2, testUser3; + SiteModel testSitePublic, testSiteModerated, testSitePrivate, secondTestSitePublic; + FolderModel testFolder1, testFolder2, testFolder3; + FileModel testFile1, testFile2, testFile3, testFile4; + RestCommentModel comment; + + /** + * Scenario 1 + * 1. Using CMIS create two test users: u1, u2 + * 2. U1 creates a test site using CMIS + * 3. Using REST API add u2 as member with Collaborator role + * 4. U2 creates one folder F1 using WEBDAV + * 5. U2 creates one file in F1 using WebDAV + * 6. U2 adds a comment to file using REST API + * 7. U1 gets comments using REST API + * 8. U1 updates the file content using WEBDAV. Assert with CMIS that content is updated + * 9. U1 updates comment using REST API + * 10. U2 gets comments using REST API + * 11. U2 deletes comment using REST API + * 12. U1 deletes file using FTP. Assert with CMIS that file doesn't exist in repository + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.SANITY }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT, TestGroup.COMMENTS }, executionType = ExecutionType.SANITY, + description = "Verify two new users are able to manage comments on the same file.") + public void usersAreAbleToManageComments() throws Exception + { + STEP("* 1. Using CMIS create two test users: u1, u2"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + + STEP("* 2. U1 creates a test site using CMIS"); + testSitePublic = dataSite.usingUser(testUser1).createPublicRandomSite(); + + STEP("* 3. Using REST API add u2 as member with Collaborator role"); + testUser2.setUserRole(UserRole.SiteCollaborator); + restAPI.authenticateUser(testUser1).withCoreAPI().usingSite(testSitePublic).addPerson(testUser2); + + STEP("* 4. U2 creates one folder F1 using WEBDAV"); + testFolder1 = FolderModel.getRandomFolderModel(); + webDavProtocol.authenticateUser(testUser2).usingSite(testSitePublic).createFolder(testFolder1).and().assertThat().existsInWebdav(); + + STEP("* 5. U2 creates one file in F1 using WebDAV"); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + webDavProtocol.authenticateUser(testUser2).usingResource(testFolder1).createFile(testFile1).and().assertThat().existsInWebdav(); + + STEP("* 6. U2 adds a comment to file using REST API"); + comment = restAPI.authenticateUser(testUser2).withCoreAPI().usingResource(testFile1).addComment("U2 comment"); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + comment.assertThat().field("content").is("U2 comment"); + + STEP("* 7. U1 gets comments using REST API"); + restAPI.authenticateUser(testUser1).withCoreAPI() + .usingResource(testFile1).getNodeComments() + .assertThat().entriesListContains("content", "U2 comment"); + + STEP("* 8. U1 updates the file content using WEBDAV. Assert with CMIS that content is updated"); + webDavProtocol.authenticateUser(testUser1).usingResource(testFile1).update("file content"); + cmisAPI.authenticateUser(testUser1).usingResource(testFile1).assertThat().contentIs("file content"); + + STEP("* 9. U1 updates comment using REST API"); + comment = restAPI.withCoreAPI().usingResource(testFile1).updateComment(comment, "U1 updated comment"); + restAPI.assertStatusCodeIs(HttpStatus.OK); + comment.assertThat().field("content").is("U1 updated comment"); + + STEP("* 10. U2 gets comments using REST API"); + restAPI.authenticateUser(testUser2).withCoreAPI() + .usingResource(testFile1).getNodeComments() + .assertThat().entriesListContains("content", "U1 updated comment"); + + STEP("* 11. U2 deletes comment using REST API"); + restAPI.withCoreAPI().usingResource(testFile1).deleteComment(comment); + restAPI.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + STEP("* 12. U1 deletes file using FTP. Assert with CMIS that file doesn't exist in repository"); + ftpProtocol.authenticateUser(testUser1).usingResource(testFile1).delete().assertThat().doesNotExistInRepo(); + } + + /** + * Scenario 2 + * 1. Using CMIS create two test users: u1, u2 + * 2. U1 creates a test site using CMIS + * 3. Using CMIS add u2 as site member with Contributor role + * 4. U1 creates one folder F1 using FTP + * 5. U1 creates one file in F1 using WEBDAV + * 6. U2 adds file to favorites using REST API + * 7. U2 gets favorites using REST API. Assert that only file is favorite. + * 8. U1 gets favorites using REST API. Assert that U1 has his site at favorites. + * 9. U1 adds file to favorites using REST API + * 10. U1 adds folder to favorites using REST API + * 11. U2 remove file from favorites using REST API + * 12. U2 adds site to favorites using REST API + * 13. U2 gets favorites using REST API. Assert that only site is favorite. + * 14. U1 gets favorites using REST API. Assert that site, file and folder are favorites. + * 15. U1 deletes file using WebDAV. Assert with WebDAV that file doesn't exist in repository + * 16. U1 gets favorites using REST API. Assert that only site and folder are favorites. + * 17. U2 gets favorites using REST API. Assert that only site is favorite. + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.SANITY }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.FAVORITES }, executionType = ExecutionType.SANITY, + description = "Verify two new users are able to manage favorites.") + public void usersAreAbleToManageFavorites() throws Exception + { + STEP("* 1. Using CMIS create two test users: u1, u2"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + + STEP("* 2. U1 creates a test site using CMIS"); + testSitePublic = dataSite.usingUser(testUser1).createPublicRandomSite(); + restAPI.authenticateUser(dataUser.getAdminUser()); + + STEP("* 3. Using CMIS add u2 as site member with Contributor role"); + dataUser.usingUser(testUser1).addUserToSite(testUser2, testSitePublic, UserRole.SiteContributor); + + STEP("* 4. U1 creates one folder F1 using FTP"); + testFolder1 = FolderModel.getRandomFolderModel(); + ftpProtocol.authenticateUser(testUser1).usingSite(testSitePublic).createFolder(testFolder1).and().assertThat().existsInRepo(); + + STEP("* 5. U1 creates one file in F1 using WEBDAV"); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + webDavProtocol.authenticateUser(testUser1).usingResource(testFolder1).createFile(testFile1).and().assertThat().existsInWebdav(); + + STEP("* 6. U2 adds file to favorites using REST API"); + restAPI.authenticateUser(testUser2).withCoreAPI() + .usingAuthUser().addFileToFavorites(testFile1) + .assertThat().field("targetGuid").is(testFile1.getNodeRef().replace(";1.0", "")); + + STEP("* 7. U2 gets favorites using REST API. Assert that only the file is favorite."); + restAPI.withCoreAPI().usingAuthUser().getFavorites() + .assertThat().entriesListContains("targetGuid", testFile1.getNodeRef().replace(";1.0", "")) + .and().paginationField("totalItems").is("1"); + + STEP("* 8. U1 gets favorites using REST API. Assert that U1 has his site at favorites."); + restAPI.authenticateUser(testUser1).withCoreAPI() + .usingAuthUser().getFavorites() + .assertThat().entriesListContains("targetGuid", testSitePublic.getGuid()) + .and().paginationField("totalItems").is("1"); + + STEP("* 9. U1 adds file to favorites using REST API"); + restAPI.withCoreAPI().usingAuthUser().addFileToFavorites(testFile1) + .assertThat().field("targetGuid").is(testFile1.getNodeRef().replace(";1.0", "")); + + STEP("* 10. U1 adds folder to favorites using REST API"); + restAPI.withCoreAPI().usingAuthUser().addFolderToFavorites(testFolder1) + .assertThat().field("targetGuid").is(testFolder1.getNodeRef()); + + STEP("* 11. U2 remove file from favorites using REST API"); + restAPI.authenticateUser(testUser2).withCoreAPI() + .usingAuthUser().deleteFileFromFavorites(testFile1); + + STEP("* 12. U2 adds site to favorites using REST API"); + restAPI.withCoreAPI().usingAuthUser().addSiteToFavorites(testSitePublic) + .assertThat().field("targetGuid").is(testSitePublic.getGuid()); + + STEP("* 13. U2 gets favorites using REST API. Assert that only site is favorite."); + restAPI.withCoreAPI().usingAuthUser().getFavorites() + .assertThat().entriesListDoesNotContain("targetGuid", testFile1.getNodeRef().replace(";1.0", "")).and() + .entriesListContains("targetGuid", testSitePublic.getGuid()).and().paginationField("totalItems").is("1"); + + STEP("* 14. U1 gets favorites using REST API. Assert that site, file and folder are favorites."); + restAPI.authenticateUser(testUser1).withCoreAPI().usingAuthUser().getFavorites() + .assertThat().entriesListContains("targetGuid", testSitePublic.getGuid()) + .assertThat().entriesListContains("targetGuid", testFile1.getNodeRef().replace(";1.0", "")) + .and().entriesListContains("targetGuid", testFolder1.getNodeRef()) + .and().paginationField("totalItems").is("3"); + + STEP("* 15. U1 deletes file using WebDAV. Assert with WebDAV that file doesn't exist in repository"); + webDavProtocol.authenticateUser(testUser1).usingResource(testFile1).delete().and().assertThat().doesNotExistInWebdav(); + + STEP("* 16. U1 gets favorites using REST API. Assert that only site and folder are favorites."); + restAPI.withCoreAPI().usingAuthUser().getFavorites() + .assertThat().entriesListContains("targetGuid", testSitePublic.getGuid()) + .assertThat().entriesListContains("targetGuid", testFolder1.getNodeRef()) + .and().paginationField("totalItems").is("2"); + + STEP("* 17. U2 gets favorites using REST API. Assert that only site is favorite."); + restAPI.authenticateUser(testUser2).withCoreAPI().usingAuthUser().getFavorites() + .assertThat().entriesListContains("targetGuid", testSitePublic.getGuid()) + .and().paginationField("totalItems").is("1"); + } + + /** + * Scenario 3 + * 1. Using CMIS create two test users: u1, u2 + * 2. U1 creates a test site using CMIS + * 3. Using CMIS add u2 as site member with Manager role + * 4. U1 creates 3 folders: F1 using FTP, F2 using WebDAV as a subfolder of F1, F3 using WEBDAV as a subfolder of F2 + * 5. U1 creates one file in each folder using FTP and WEBDAV + * 6. U1 renames F2 using IMAP + * 7. U1 updates file1 using WebDAV + * 8. U1 deletes file2 using FTP + * 9. U1 deletes non empty folder3 using WEBDAV + * 10. Assert with CMIS that U2 is able to see all the above changes + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.SANITY }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.SANITY, + description = "Verify user is able to manage files and folders.") + public void userIsAbleToManageFilesAndFolders() throws Exception + { + STEP("* 1. Using CMIS create two test users: u1, u2"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + + STEP("* 2. U1 creates a test site using CMIS"); + testSitePublic = dataSite.usingUser(testUser1).createIMAPSite(); + + STEP("* 3. Using CMIS add u2 as site member with Manager role"); + dataUser.usingUser(testUser1).addUserToSite(testUser2, testSitePublic, UserRole.SiteManager); + + STEP("* 4. U1 creates 3 folders: F1 using FTP, F2 using WebDAV as a subfolder of F1, F3 using WEBDAV as a subfolder of F2. " + + "* 5. U1 creates one file in each folder using FTP and WEBDAV"); + testFolder1 = FolderModel.getRandomFolderModel(); + testFolder2 = FolderModel.getRandomFolderModel(); + testFolder3 = FolderModel.getRandomFolderModel(); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + testFile2 = FileModel.getRandomFileModel(FileType.HTML); + testFile3 = FileModel.getRandomFileModel(FileType.MSWORD, "some content"); + + ftpProtocol.authenticateUser(testUser1).usingSite(testSitePublic).createFolder(testFolder1).and().assertThat().existsInFtp(); + webDavProtocol.authenticateUser(testUser1).usingResource(testFolder1).createFolder(testFolder2).assertThat().existsInWebdav() + .and().createFile(testFile1).assertThat().existsInWebdav(); + webDavProtocol.authenticateUser(testUser1).usingResource(testFolder2).createFolder(testFolder3).assertThat().existsInWebdav() + .and().createFile(testFile2).assertThat().existsInWebdav(); + ftpProtocol.authenticateUser(testUser1).usingResource(testFolder3).createFile(testFile3).then().assertThat().existsInFtp(); + + STEP(" * 6. U1 renames F2 using IMAP"); + imapProtocol.authenticateUser(testUser1).usingResource(testFolder2).rename("F2 rename") + .then().usingResource(testFolder1) + .assertThat().contains(new FolderModel("F2 rename")) + .and().assertThat().doesNotContain(testFolder2); + + STEP(" * 7. U1 updates file1 using WebDAV"); + webDavProtocol.authenticateUser(testUser1).usingResource(testFile1).update("testFile1 content.").then().assertThat().contentIs("testFile1 content."); + + STEP("* 8. U1 deletes file2 using FTP"); + ftpProtocol.authenticateUser(testUser1).usingResource(testFile2).delete().then().assertThat().doesNotExistInRepo(); + + STEP(" * 9. U1 deletes non empty folder3 using WEBDAV"); + webDavProtocol.authenticateUser(testUser1).usingResource(testFolder3).delete().then().assertThat().doesNotExistInWebdav(); + + STEP("* 10. Assert with CMIS that U2 is able to see all the above changes"); + cmisAPI.authenticateUser(testUser2) + .usingResource(testFolder1).assertThat().hasChildren(testFile1) + .usingResource(testFile1).assertThat().contentIs("testFile1 content.") + .usingResource(testFile2).assertThat().doesNotExistInRepo() + .usingResource(testFolder3).assertThat().doesNotExistInRepo() + .usingResource(testFile3).assertThat().doesNotExistInRepo(); + + FolderModel renamedFolder = cmisAPI.usingResource(testFolder1).getFolders().get(0); + Assert.assertEquals(renamedFolder.getName(), "F2 rename", "User2 is able to see the renamed folder"); + } + + /** + * Scenario 4 + * 1. Using CMIS create two test users: u1, u2 + * 2. U1 creates a test site using CMIS + * 3. Using REST API add u2 as site member with Collaborator role + * 4. U2 creates file1 with using CMIS + * 5. U1 creates file2 from source using CMIS + * 6. U1 uploads file3 using FTP + * 7. U1 creates file4 using CMIS + * 8. U1 marks file1 and 3 as favorite using REST API + * 9. U2 marks file 1, 2, 4 as favorite using REST API + * 10. U2 marks site as favorite using REST API + * 11. U1 removes file1 from favorites using REST API + * 12. U2 checks file favorites using REST API. Assert that U2 gets only his favorite files. + * 13. U2 removes file1 from favorites using REST API + * 14. U2 checks file favorites using REST API. Assert that U2 gets only his favorite files. + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.SANITY }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT, TestGroup.FAVORITES }, executionType = ExecutionType.SANITY, + description = "Verify two new users are able to manage favorite files.") + public void usersAreAbleToManageFavoriteFiles() throws Exception + { + STEP("* 1. Using CMIS create two test users: u1, u2"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + + STEP("* 2. U1 creates a test site using CMIS"); + testSitePublic = dataSite.usingUser(testUser1).createPublicRandomSite(); + restAPI.authenticateUser(dataUser.getAdminUser()); + testSitePublic.setGuid(restAPI.withCoreAPI().usingSite(testSitePublic).getSite().getGuid()); + + STEP("* 3. Using REST API add u2 as site member with Collaborator role"); + testUser2.setUserRole(UserRole.SiteCollaborator); + restAPI.authenticateUser(testUser1).withCoreAPI().usingSite(testSitePublic).addPerson(testUser2); + + STEP(" * 4. U2 creates file1 with using CMIS"); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file1 content"); + cmisAPI.authenticateUser(testUser2).usingSite(testSitePublic).createFile(testFile1).then().assertThat().existsInRepo(); + + STEP("* 5. U1 creates file2 from source using CMIS"); + testFile2 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + cmisAPI.authenticateUser(testUser1).usingSite(testSitePublic).createFileFromSource(testFile2, testFile1).and().refreshResource().then() + .assertThat().existsInRepo(); + + STEP(" * 6. U1 uploads file3 using FTP"); + testFile3 = FileModel.getFileModelBasedOnTestDataFile("testUploadFile.txt"); + ftpProtocol.authenticateUser(testUser1).usingSite(testSitePublic).createFile(testFile3).then().assertThat().existsInRepo(); + + STEP("* 7. U1 creates file4 using CMIS"); + testFile4 = FileModel.getRandomFileModel(FileType.MSWORD, "file4 content"); + cmisAPI.authenticateUser(testUser1).usingSite(testSitePublic).createFile(testFile4).then().assertThat().existsInRepo(); + + STEP("* 8. U1 marks file1 and 3 as favorite using REST API"); + restAPI.authenticateUser(testUser1).withCoreAPI() + .usingAuthUser().addFileToFavorites(testFile1) + .assertThat().field("targetGuid").is(testFile1.getNodeRef().replace(";1.0", "")); + restAPI.withCoreAPI().usingAuthUser().addFileToFavorites(testFile3) + .assertThat().field("targetGuid").is(testFile3.getNodeRef().replace(";1.0", "")); + + STEP("* 9. U2 marks file 1, 2, 4 as favorite using REST API"); + restAPI.authenticateUser(testUser2).withCoreAPI() + .usingAuthUser().addFileToFavorites(testFile1) + .assertThat().field("targetGuid").is(testFile1.getNodeRef().replace(";1.0", "")); + restAPI.withCoreAPI().usingAuthUser().addFileToFavorites(testFile2) + .assertThat().field("targetGuid").is(testFile2.getNodeRef().replace(";1.0", "")); + restAPI.withCoreAPI().usingAuthUser().addFileToFavorites(testFile4) + .assertThat().field("targetGuid").is(testFile4.getNodeRef().replace(";1.0", "")); + + STEP("* 10. U2 marks site as favorite using REST API"); + restAPI.withCoreAPI().usingAuthUser().addSiteToFavorites(testSitePublic) + .assertThat().field("targetGuid").is(testSitePublic.getGuid()); + + STEP("* 11. U1 removes file1 from favorites using REST API"); + restAPI.authenticateUser(testUser1).withCoreAPI().usingAuthUser().deleteFileFromFavorites(testFile1); + + STEP("* 12. U2 checks file favorites using REST API. Assert that U2 gets only his favorite files."); + restAPI.authenticateUser(testUser2).withCoreAPI().usingAuthUser() + .where().targetFileExist().getFavorites().assertThat() + .entriesListContains("targetGuid", testFile1.getNodeRef().replace(";1.0", "")).and() + .entriesListContains("targetGuid", testFile2.getNodeRef().replace(";1.0", "")).and() + .entriesListContains("targetGuid", testFile4.getNodeRef().replace(";1.0", "")).and() + .paginationField("totalItems").is("3"); + + STEP("* 13. U2 removes file1 from favorites using REST API"); + restAPI.withCoreAPI().usingAuthUser().deleteFileFromFavorites(testFile1); + + STEP("* 14. U2 checks file favorites using REST API. Assert that U2 gets only his favorite files."); + restAPI.withCoreAPI().usingAuthUser() + .where().targetFileExist().getFavorites().assertThat() + .entriesListContains("targetGuid", testFile2.getNodeRef().replace(";1.0", "")).and() + .entriesListContains("targetGuid", testFile4.getNodeRef().replace(";1.0", "")).and() + .paginationField("totalItems").is("2"); + } + + /** + * Scenario 5 + * 1. Using CMIS create a test user: u1 + * 2. U1 creates a test site using CMIS + * 3. U1 creates 2 files in site's document library using FTP + * 4. U1 creates folder1 in site's document library using WebDAV + * 5. U1 creates another 2 files in folder1 using WEBDAV + * 6. U1 adds tag1, tag2 on file1, tag2 on file2 using REST API + * 7. U1 adds tag1 on folder1, tag3 on file3 using REST API + * 8. U1 gets tags and verify all tags are listed + * 9. U1 gets file1 tags and verify only tag1 and tag2 are listed + * 10. U1 deletes tag2 from file1 + * 11. U1 deletes file3 using WebDAV + * 12. U1 gets tags and verify all tags are listed + * 13. U1 gets file1 tags and verify tag2 was removed. + * 14. U1 gets folder1 tags and verify only tag1 is listed. + * 15. U1 deletes non empty folder1 using CMIS + * 16. U1 gets tags and verify all tags are listed + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.SANITY }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT, TestGroup.TAGS }, executionType = ExecutionType.SANITY, + description = "Verify site manager is able to manage tags.") + public void siteManagerIsAbleToManageTags() throws Exception + { + STEP("* 1. Using CMIS create a test user: u1"); + testUser1 = dataUser.createRandomTestUser(); + + STEP("* 2. U1 creates a test site using CMIS"); + testSitePublic = dataSite.usingUser(testUser1).createPublicRandomSite(); + + STEP("* 3. U1 creates 2 files in site's document library using FTP"); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file1 content"); + testFile2 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file2 content"); + ftpProtocol.authenticateUser(testUser1).usingSite(testSitePublic) + .createFile(testFile1).then().assertThat().existsInRepo() + .createFile(testFile2).then().assertThat().existsInRepo(); + + STEP("* 4. U1 creates folder1 in site's document library using WebDAV"); + testFolder1 = FolderModel.getRandomFolderModel(); + webDavProtocol.authenticateUser(testUser1).usingSite(testSitePublic).createFolder(testFolder1).then().assertThat().existsInRepo(); + + STEP("* 5. U1 creates another 2 files in folder1 using WEBDAV"); + testFile3 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file3 content"); + testFile4 = FileModel.getRandomFileModel(FileType.MSWORD, "file4 content"); + webDavProtocol.authenticateUser(testUser1).usingResource(testFolder1) + .createFile(testFile3).then().assertThat().existsInRepo() + .createFile(testFile4).then().assertThat().existsInRepo(); + + STEP("* 6. U1 adds tag1, tag2 on file1, tag2 on file2 using REST API"); + restAPI.authenticateUser(testUser1).withCoreAPI() + .usingResource(testFile1).addTags("integration_tag1", "integration_tag2") + .assertThat().entriesListContains("tag", "integration_tag1") + .and().entriesListContains("tag", "integration_tag2"); + RestTagModel tag2 = restAPI.withCoreAPI() + .usingResource(testFile2).addTag("integration_tag2") + .assertThat().field("tag").is("integration_tag2"); + + STEP("* 7. U1 adds tag1 on folder1, tag3 on file3 using REST API"); + restAPI.withCoreAPI() + .usingResource(testFolder1).addTag("integration_tag1") + .assertThat().field("tag").is("integration_tag1"); + + restAPI.withCoreAPI() + .usingResource(testFile3).addTag("integration_tag3") + .assertThat().field("tag").is("integration_tag3"); + + STEP("* 8. U1 gets tags and verify all tags are listed"); + Utility.waitToLoopTime(30); + restAPI.withParams("maxItems=10000").withCoreAPI().getTags() + .assertThat().entriesListContains("tag", "integration_tag1") + .and().entriesListContains("tag", "integration_tag2") + .and().entriesListContains("tag", "integration_tag3"); + + STEP("* 9. U1 gets file1 tags and verify only tag1 and tag2 are listed"); + restAPI.withCoreAPI() + .usingResource(testFile1).getNodeTags() + .assertThat().entriesListContains("tag", "integration_tag1") + .and().entriesListContains("tag", "integration_tag2") + .and().paginationField("totalItems").is("2"); + + STEP("* 10. U1 deletes tag2 from file1"); + restAPI.withCoreAPI().usingResource(testFile1).deleteTag(tag2); + restAPI.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + STEP("* 11. U1 deletes file3 using WebDAV"); + webDavProtocol.authenticateUser(testUser1).usingResource(testFile3).delete().then().assertThat().doesNotExistInWebdav(); + + STEP("* 12. U1 gets tags and verify all tags are listed"); + restAPI.withParams("maxItems=10000").withCoreAPI().getTags() + .assertThat().entriesListContains("tag", "integration_tag1") + .and().entriesListContains("tag", "integration_tag2") + .and().entriesListContains("tag", "integration_tag3"); + + STEP(" * 13. U1 gets file1 tags and verify tag2 was removed."); + restAPI.withCoreAPI().usingResource(testFile1).getNodeTags() + .assertThat().entriesListContains("tag", "integration_tag1") + .and().entriesListDoesNotContain("tag", "integration_tag2") + .and().paginationField("totalItems").is("1"); + + STEP("* 14. U1 gets folder1 tags and verify only tag1 is listed."); + restAPI.withCoreAPI().usingResource(testFolder1).getNodeTags() + .assertThat().entriesListContains("tag", "integration_tag1") + .and().paginationField("totalItems").is("1"); + + STEP("* 15. U1 deletes non empty folder1 using CMIS"); + cmisAPI.authenticateUser(testUser1).usingResource(testFolder1).deleteFolderTree().assertThat().doesNotExistInRepo(); + + STEP("* 16. U1 gets tags and verify all tags are listed"); + restAPI.withParams("maxItems=10000").withCoreAPI().getTags() + .assertThat().entriesListContains("tag", "integration_tag1") + .and().entriesListContains("tag", "integration_tag2") + .and().entriesListContains("tag", "integration_tag3"); + } + + /** + * Scenario 6 + * 1. Using CMIS create 3 test user: u1, u2, u3 + * 2. Using CMIS U1 creates a public test site, a moderated test site and a private test site + * 3. Using REST API, U2 request to join the public site + * 4. Using REST API, U3 request to join the public site + * 5. Using REST API, check that u2 and u3 are added to public site with Consumer role + * 6. Using REST API, U2 request to join the moderated site + * 7. Using REST API, U3 request to join the moderated site + * 8. Using REST API, check that u2 and u3 requests to join the moderated site are added to site membership request list + * 9. Using REST API, U1 cancels the request for U3 + * 10. Using REST API, check that u2 can't make requests to join the private site + * 11. Using REST API, check that only u2 request remains in site membership request list + * 12. Using REST API, U1 change U2 role to Collaborator in public site + * 13. Using REST API, get site membership information for each user + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.SANITY }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.SITES }, executionType = ExecutionType.SANITY, + description = "Verify site manager is able to manage site membership.") + public void siteManagerIsAbleToManageSiteMembership() throws Exception + { + STEP("* 1. Using CMIS create 3 test user: u1, u2, u3"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + testUser3 = dataUser.createRandomTestUser(); + + STEP(" * 2. Using CMIS U1 creates a public test site, a moderated test site and a private test site"); + testSitePublic = dataSite.usingUser(testUser1).createPublicRandomSite(); + testSiteModerated = dataSite.usingUser(testUser1).createModeratedRandomSite(); + testSitePrivate = dataSite.usingUser(testUser1).createPrivateRandomSite(); + + STEP("* 3. Using REST API, U2 request to join the public site"); + restAPI.authenticateUser(testUser2).withCoreAPI() + .usingAuthUser().addSiteMembershipRequest(testSitePublic); + + STEP("* 4. Using REST API, U3 request to join the public site"); + restAPI.authenticateUser(testUser3).withCoreAPI() + .usingAuthUser().addSiteMembershipRequest(testSitePublic); + + STEP(" * 5. Using REST API, check that u2 and u3 are added to public site with Consumer role"); + restAPI.withCoreAPI() + .usingSite(testSitePublic).getSiteMembers() + .assertThat().entriesListContains("id", testUser2.getUsername()) + .and().entriesListContains("id", testUser3.getUsername()); + restAPI.withCoreAPI() + .usingSite(testSitePublic).getSiteMember(testUser2) + .assertThat().field("role").is("SiteConsumer"); + + restAPI.withCoreAPI() + .usingSite(testSitePublic).getSiteMember(testUser3) + .assertThat().field("role").is("SiteConsumer"); + + STEP("* 6. Using REST API, U3 request to join the moderated site"); + restAPI.withCoreAPI() + .usingAuthUser().addSiteMembershipRequest(testSiteModerated); + + STEP("* 7. Using REST API, U2 request to join the moderated site"); + restAPI.authenticateUser(testUser2).withCoreAPI() + .usingAuthUser().addSiteMembershipRequest(testSiteModerated); + + STEP("* 8. Using REST API, check that u2 and u3 requests to join the moderated site are added to site membership request list"); + restAPI.authenticateUser(testUser1).withCoreAPI() + .usingSite(testSiteModerated).getSiteMembers() + .assertThat().entriesListDoesNotContain("id", testUser2.getUsername()) + .and().entriesListDoesNotContain("id", testUser3.getUsername()); + + restAPI.withCoreAPI() + .usingUser(testUser2).getSiteMembershipRequest(testSiteModerated) + .assertThat().field("id").is(testSiteModerated.getId()); + + restAPI.withCoreAPI() + .usingUser(testUser3).getSiteMembershipRequest(testSiteModerated) + .assertThat().field("id").is(testSiteModerated.getId()); + + STEP("* 9. Using REST API, U1 cancels the request for U3"); + restAPI.withCoreAPI().usingUser(testUser3).deleteSiteMembershipRequest(testSiteModerated); + + STEP("* 10. Using REST API, check that u2 can't make requests to join the private site."); + restAPI.authenticateUser(testUser2).withCoreAPI() + .usingAuthUser().addSiteMembershipRequest(testSitePrivate); + restAPI.assertStatusCodeIs(HttpStatus.NOT_FOUND); + + STEP("* 11. Using REST API, check that only u2 request remains in site membership request list"); + restAPI.withCoreAPI() + .usingAuthUser().getSiteMembershipRequests() + .assertThat().entriesListContains("id", testSiteModerated.getId()) + .and().paginationField("totalItems").is("1"); + + restAPI.authenticateUser(testUser3).withCoreAPI() + .usingAuthUser().getSiteMembershipRequests() + .assertThat().entriesListIsEmpty(); + + STEP("* 12. Using REST API, U1 change U2 role to Collaborator in public site"); + testUser2.setUserRole(UserRole.SiteCollaborator); + restAPI.authenticateUser(testUser1).withCoreAPI() + .usingSite(testSitePublic).updateSiteMember(testUser2) + .assertThat().field("role").is(testUser2.getUserRole()); + + STEP("* 13. Using REST API, get site membership information for each user"); + restAPI.withCoreAPI() + .usingAuthUser().getSitesMembershipInformation() + .assertThat().paginationField("count").is("3"); + restAPI.withCoreAPI() + .usingUser(testUser2).getSitesMembershipInformation() + .assertThat().entriesListContains("id", testSitePublic.getId()).and() + .entriesListContains("role", "SiteCollaborator").and().paginationField("count").is("1"); + restAPI.withCoreAPI() + .usingUser(testUser3).getSitesMembershipInformation() + .assertThat().entriesListContains("id", testSitePublic.getId()).and() + .entriesListContains("role", "SiteConsumer").and().paginationField("count").is("1"); + } + + /** + * Scenario 7 + * 1. Using CMIS create 1 test user: u1 + * 2. Using CMIS U1 creates a public site, a moderated test site and a private test site + * 3. Using WEBDAV, U1 adds file1 to site1 + * 4. Using REST API, check the u1 favorites sites list + * 5. Using REST API, U1 removes site1 from favorites + * 6. Using REST API, check the u1 favorites sites list + * 7. Using CMIS, U1 deletes site2 + * 8. Using REST API, check the u1 favorites sites list + * 9. Using REST API, U1 marks site1 as favorite + * 10. Using REST API, check the u1 favorites sites list + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.SANITY }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.SITES, TestGroup.FAVORITES }, executionType = ExecutionType.SANITY, + description = "Verify users are able to manage favorite sites.") + public void userIsAbleToManageFavoriteSites() throws Exception + { + STEP("* 1. Using CMIS create a test user: u1"); + testUser1 = dataUser.createRandomTestUser(); + + STEP("* 2. Using CMIS U1 creates a public site, a moderated test site and a private test site"); + testSitePublic = dataSite.usingUser(testUser1).createPublicRandomSite(); + testSiteModerated = dataSite.usingUser(testUser1).createModeratedRandomSite(); + testSitePrivate = dataSite.usingUser(testUser1).createPrivateRandomSite(); + + STEP("* 3. Using WEBDAV, U1 adds file1 to site1"); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file1 content"); + webDavProtocol.authenticateUser(testUser1).usingSite(testSitePublic).createFile(testFile1).assertThat().existsInRepo(); + + STEP("* 4. Using REST API, check the u1 favorites sites list"); + restAPI.authenticateUser(testUser1) + .withCoreAPI().usingAuthUser().where().targetSiteExist().getFavorites().assertThat() + .entriesListContains("targetGuid", testSitePublic.getGuid()).and() + .entriesListContains("targetGuid", testSiteModerated.getGuid()).and() + .entriesListContains("targetGuid", testSitePrivate.getGuid()).and() + .paginationField("totalItems").is("3"); + + STEP("* 5. Using REST API, U1 removes site1 from favorites"); + restAPI.withCoreAPI().usingAuthUser().deleteSiteFromFavorites(testSitePublic); + + STEP("* 6. Using REST API, check the u1 favorites sites list"); + restAPI.withCoreAPI().usingAuthUser() + .where().targetSiteExist().getFavorites().assertThat() + .entriesListContains("targetGuid", testSiteModerated.getGuid()).and() + .entriesListContains("targetGuid", testSitePrivate.getGuid()).and() + .paginationField("totalItems").is("2"); + + STEP("* 7. Using CMIS, U1 deletes site2"); + dataSite.usingUser(testUser1).deleteSite(testSiteModerated); + + STEP("* 8. Using REST API, check the u1 favorites sites list"); + restAPI.withCoreAPI().usingAuthUser() + .where().targetSiteExist().getFavorites().assertThat() + .entriesListContains("targetGuid", testSitePrivate.getGuid()).and() + .paginationField("totalItems").is("1"); + + STEP("* 9. Using REST API, U1 marks site1 as favorite"); + restAPI.withCoreAPI().usingAuthUser().addSiteToFavorites(testSitePublic) + .assertThat().field("targetGuid").is(testSitePublic.getGuid()); + + STEP("* 10. Using REST API, check the u1 favorites sites list"); + restAPI.withCoreAPI().usingAuthUser().where().targetSiteExist().getFavorites().assertThat() + .entriesListContains("targetGuid", testSitePublic.getGuid()).and() + .entriesListContains("targetGuid", testSitePrivate.getGuid()).and() + .paginationField("totalItems").is("2"); + } + + /** + * Scenario 10 + * 1. Using CMIS create 3 test user: u1, u2, u3 + * 2. Using CMIS U1 creates a a moderated test site + * 3. Using REST API, U2 request to join the moderated site + * 4. Using REST API, U3 request to join the moderated site + * 5. Using REST API, check that u2 and u3 requests to join the moderated site are added to site membership request list + * 6. Using REST API, U1 cancels the request for U3 + * 7. Using REST API, check that only u2 request remains in site membership request list + * 8. Using REST API, U1 cancels the request for U2 + * 9. Using REST API, verify that there is no request to join left in the site membership request list. + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.SANITY }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.SITES }, executionType = ExecutionType.SANITY, + description = "Verify site manager is able to cancel requests to join moderated site.") + public void siteManagerIsAbleToCancelSiteMembership() throws Exception + { + STEP("* 1. Using CMIS create 3 test user: u1, u2, u3"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + testUser3 = dataUser.createRandomTestUser(); + + STEP("* 2. Using CMIS U1 creates a a moderated test site"); + testSiteModerated = dataSite.usingUser(testUser1).createModeratedRandomSite(); + + STEP("* 3. Using REST API, U2 request to join the moderated site"); + restAPI.authenticateUser(testUser2).withCoreAPI() + .usingAuthUser().addSiteMembershipRequest(testSiteModerated); + + STEP("* 4. Using REST API, U3 request to join the moderated site"); + restAPI.authenticateUser(testUser3).withCoreAPI() + .usingAuthUser().addSiteMembershipRequest(testSiteModerated); + + STEP("* 5. Using REST API, check that u2 and u3 requests to join the moderated site are added to site membership request list"); + restAPI.authenticateUser(testUser1).withCoreAPI() + .usingUser(testUser2).getSiteMembershipRequest(testSiteModerated) + .assertThat().field("id").is(testSiteModerated.getId()); + restAPI.withCoreAPI() + .usingUser(testUser3).getSiteMembershipRequest(testSiteModerated) + .assertThat().field("id").is(testSiteModerated.getId()); + + STEP("* 6. Using REST API, U1 cancels the request for U3"); + restAPI.withCoreAPI() + .usingUser(testUser3).deleteSiteMembershipRequest(testSiteModerated); + + STEP("* 7. Using REST API, check that u3 request isn't in site membership request list"); + restAPI.withCoreAPI() + .usingUser(testUser3).getSiteMembershipRequest(testSiteModerated); + restAPI.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "The relationship resource")) + .containsSummary(testUser3.getUsername()); + + STEP("* 8. Using REST API, U1 cancels the request for U2"); + restAPI.withCoreAPI() + .usingUser(testUser2).deleteSiteMembershipRequest(testSiteModerated); + + STEP("* 9. Using REST API, check that u2 request isn't in site membership request list."); + restAPI.withCoreAPI() + .usingUser(testUser2).getSiteMembershipRequest(testSiteModerated); + restAPI.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "The relationship resource")) + .containsSummary(testUser2.getUsername()); + } + + /** + * Scenario 11 + * 1. Using CMIS create 2 test user: u1, u2 + * 2. Using CMIS U1 creates 3 test sites + * 3. Using CMIS U1 adds U2 to site1 with "Consumer" role + * 4. Using CMIS U1 adds U2 to site2 with "Collaborator" role + * 5. Using REST API, admin adds U2 to site3 with "Manager" role + * 6. Using REST API, verify that site1, site2, site3 are present in the list of sites for U2 + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.SANITY }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.SITES }, executionType = ExecutionType.SANITY, + description = "Verify user is able to get site membership informations.") + public void userIsAbleToGetSiteMembershipInfo() throws Exception + { + STEP("* 1. Using CMIS create 2 test user: u1, u2"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + + STEP("* 2. Using CMIS U1 creates 3 test sites"); + testSitePublic = dataSite.usingUser(testUser1).createPublicRandomSite(); + testSiteModerated = dataSite.usingUser(testUser1).createModeratedRandomSite(); + testSitePrivate = dataSite.usingUser(testUser1).createPrivateRandomSite(); + + STEP("* 3. Using CMIS U1 adds U2 to site1 with \"Consumer\" role"); + dataUser.usingUser(testUser1).addUserToSite(testUser2, testSitePublic, UserRole.SiteConsumer); + + STEP("* 4. Using CMIS U1 adds U2 to site2 with \"Collaborator\" role"); + dataUser.usingUser(testUser1).addUserToSite(testUser2, testSiteModerated, UserRole.SiteCollaborator); + + STEP("* 5. Using REST API, admin adds U2 to site3 with \"Manager\" role"); + testUser2.setUserRole(UserRole.SiteManager); + restAPI.authenticateUser(dataUser.getAdminUser()).withCoreAPI() + .usingSite(testSitePrivate).addPerson(testUser2); + + STEP("* 6. Using REST API, verify that site1, site2, site3 are present in the list of sites for U2"); + restAPI.withCoreAPI() + .usingUser(testUser2).getSitesMembershipInformation() + .assertThat().entriesListContains("id", testSitePublic.getId()) + .and().entriesListContains("id", testSiteModerated.getId()) + .and().entriesListContains("id", testSitePrivate.getId()) + .and().paginationField("count").is("3"); + + restAPI.withCoreAPI() + .usingSite(testSitePublic).getSiteMember(testUser2) + .assertThat().field("role").is("SiteConsumer"); + restAPI.withCoreAPI() + .usingSite(testSiteModerated).getSiteMember(testUser2) + .assertThat().field("role").is("SiteCollaborator"); + restAPI.withCoreAPI() + .usingSite(testSitePrivate).getSiteMember(testUser2) + .assertThat().field("role").is("SiteManager"); + } + + /** + * Scenario 12 + * 1. Using CMIS create a test user: u1 + * 2. U1 creates a test site using CMIS + * 3. U1 creates a file in site's document library using WebDAV + * 4. U1 creates another site using CMIS + * 5. U1 creates a folder in site's document library using FTP + * 6. U1 copy file to folder using WEBDAV + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.SANITY }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.SANITY, + description = "Verify user is able to copy file to a folder from another site.") + public void userIsAbleToCopyFileToAFolderFromAnotherSite() throws Exception + { + STEP("* 1. Using CMIS create a test user: u1"); + testUser1 = dataUser.createRandomTestUser(); + + STEP("* 2. U1 creates a test site using CMIS"); + testSitePublic = dataSite.usingUser(testUser1).createPublicRandomSite(); + + STEP("* 3. U1 creates a file in site's document library using WebDAV"); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file1 content"); + webDavProtocol.authenticateUser(testUser1).usingSite(testSitePublic).createFile(testFile1).then().assertThat().existsInRepo(); + + STEP("* 4. U1 creates another site using CMIS"); + secondTestSitePublic = dataSite.usingUser(testUser1).createPublicRandomSite(); + + STEP("* 5. U1 creates a folder in second site's document library using FTP"); + testFolder1 = FolderModel.getRandomFolderModel(); + ftpProtocol.authenticateUser(testUser1).usingSite(secondTestSitePublic).createFolder(testFolder1).then().assertThat().existsInRepo(); + + STEP("* 6. U1 copy file to folder using WEBDAV"); + webDavProtocol.authenticateUser(testUser1).usingResource(testFile1).copyTo(testFolder1).assertThat().existsInRepo(); + } + + /** + * Scenario 13 + * 1. Using CMIS create a test user: u1 + * 2. U1 creates a test site using CMIS + * 3. U1 creates a file in site's document library using FTP + * 4. U1 creates another site using CMIS + * 5. U1 creates a folder in site's document library using WebDAV + * 6. U1 moves file to folder using FTP + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.SANITY }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.SANITY, + description = "Verify user is able to move file to a folder from another site.") + public void userIsAbleToMoveFileToAFolderFromAnotherSite() throws Exception + { + STEP("* 1. Using CMIS create a test user: u1"); + testUser1 = dataUser.createRandomTestUser(); + + STEP("* 2. U1 creates a test site using CMIS"); + testSitePublic = dataSite.usingUser(testUser1).createPublicRandomSite(); + + STEP("* 3. U1 creates a file in site's document library using FTP"); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file1 content"); + ftpProtocol.authenticateUser(testUser1).usingSite(testSitePublic).createFile(testFile1).then().assertThat().existsInRepo(); + + STEP("* 4. U1 creates another site using CMIS"); + secondTestSitePublic = dataSite.usingUser(testUser1).createPublicRandomSite(); + + STEP("* 5. U1 creates a folder in second site's document library using WebDAV"); + testFolder1 = FolderModel.getRandomFolderModel(); + webDavProtocol.authenticateUser(testUser1).usingSite(secondTestSitePublic).createFolder(testFolder1).then().assertThat().existsInRepo(); + + STEP("* 6. U1 moves file to folder using FTP"); + ftpProtocol.authenticateUser(testUser1).usingResource(testFile1).moveTo(testFolder1).assertThat().existsInRepo(); + } + + /** + * Scenario 14 + * 1. Using CMIS create a test user: u1 + * 2. U1 creates a public test site, a moderated test site and a private test site using CMIS + * 3. U1 gets each site with REST API: public, moderated and private sites are listed + * 4. U1 deletes moderated site using CMIS + * 5. U1 gets each site with REST API: public and private sites are listed + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.SANITY }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.SITES }, executionType = ExecutionType.SANITY, + description = "Verify user is able to get created sites with different visibility.") + public void userIsAbleToGetSitesWithDifferentVisibility() throws Exception + { + STEP("* 1. Using CMIS create a test user: u1"); + testUser1 = dataUser.createRandomTestUser(); + + STEP("* 2. U1 creates a public test site, a moderated test site and a private test site using CMIS "); + testSitePublic = dataSite.usingUser(testUser1).createPublicRandomSite(); + testSiteModerated = dataSite.usingUser(testUser1).createModeratedRandomSite(); + testSitePrivate = dataSite.usingUser(testUser1).createPrivateRandomSite(); + + STEP("* 3. U1 gets each site with REST API: public, moderated and private sites are listed"); + restAPI.authenticateUser(testUser1); + + List createdSites = new ArrayList(); + createdSites.add(testSitePublic); + createdSites.add(testSiteModerated); + createdSites.add(testSitePrivate); + + for(SiteModel site : createdSites) + { + restAPI.withCoreAPI() + .usingSite(site).getSite() + .assertThat().field("id").is(site.getId()) + .and().field("title").is(site.getTitle()); + restAPI.assertStatusCodeIs(HttpStatus.OK); + } + + STEP("* 4. U1 deletes moderated site using CMIS"); + dataSite.usingUser(testUser1).deleteSite(testSiteModerated); + + STEP("* 5. U1 gets each site with REST API: public and private sites are listed"); + restAPI.withParams("maxItems=10000").withCoreAPI().getSites() + .assertThat().entriesListContains("id", testSitePublic.getId()) + .assertThat().entriesListContains("id", testSitePrivate.getId()) + .assertThat().entriesListDoesNotContain("id", testSiteModerated.getId()); + } + + /** + * Scenario 15 + * 1. Using CMIS create two users: u1 and u2 + * 2. U1 creates a public site using CMIS + * 3. U1 creates a file in public site's document library using FTP + * 4. U2 creates a private site using CMIS + * 5. U2 creates a folder in public site's document library using WebDAV + * 6. U1 copies the file in private site's document library using WEBDAV + * 7. Using WEBDAV, verify that file was not copied + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.SANITY }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.SANITY, + description = "Verify uninvited user is not able to copy document to a private site.") + public void userIsNotAbleToCopyAFileToAPrivateSite() throws Exception + { + STEP("* 1. Using CMIS create two users: u1 and u2"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + + STEP("* 2. U1 creates a public site using CMIS"); + testSitePublic = dataSite.usingUser(testUser1).createPublicRandomSite(); + + STEP("* 3. U1 creates a file in public site's document library using FTP"); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file1 content"); + ftpProtocol.authenticateUser(testUser1).usingSite(testSitePublic).createFile(testFile1).then().assertThat().existsInRepo(); + + STEP("* 4. U2 creates a private site using CMIS"); + testSitePrivate = dataSite.usingUser(testUser2).createPrivateRandomSite(); + + STEP("* 5. U2 creates a folder in public site's document library using WebDAV"); + testFolder1 = FolderModel.getRandomFolderModel(); + webDavProtocol.authenticateUser(testUser2).usingSite(testSitePrivate).createFolder(testFolder1).then().assertThat().existsInRepo(); + + STEP("* 6. U1 copies the file in private site's document library using WEBDAV" + + "* 7. Using WEBDAV, verify that file was not copied"); + webDavProtocol.authenticateUser(testUser1).usingResource(testFile1).copyTo(testFolder1).assertThat().doesNotExistInRepo(); + } + + /** + * Scenario 16 + * 1. Using CMIS create two users: u1 and u2 + * 2. U1 creates a public site using CMIS + * 3. U1 adds U2 to site with "Consumer" role using CMIS + * 4. Using REST API, verify membership information for u2 on public site + * 5. Using REST API, U1 change U2 role to Collaborator in public site + * 6. Using REST API, verify membership information for u2 on public site + * 7. Using REST API, U1 remove U2 from public site + * 8. Using REST API, verify that u2 isn't member of u1 public site + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.SANITY }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.SITES }, executionType = ExecutionType.SANITY, + description = "Verify user is able to get user membership information.") + public void userIsAbleToGetASiteMember() throws Exception + { + STEP("* 1: Using CMIS create two users: u1 and u2"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + + STEP("* 2: U1 creates a public site using CMIS"); + testSitePublic = dataSite.usingUser(testUser1).createPublicRandomSite(); + + STEP("* 3. U1 adds U2 to site with \"Consumer\" role using CMIS"); + dataUser.usingUser(testUser1).addUserToSite(testUser2, testSitePublic, UserRole.SiteConsumer); + + STEP("* 4. Using REST API, verify membership information for u2 on public site"); + restAPI.authenticateUser(testUser1).withCoreAPI() + .usingSite(testSitePublic).getSiteMember(testUser2) + .assertThat().field("role").is("SiteConsumer"); + + STEP("* 5. Using REST API, U1 change U2 role to Collaborator in public site"); + testUser2.setUserRole(UserRole.SiteCollaborator); + restAPI.withCoreAPI() + .usingSite(testSitePublic).updateSiteMember(testUser2) + .assertThat().field("role").is(testUser2.getUserRole()); + + STEP("* 6. Using REST API, verify membership information for u2 on public site"); + restAPI.withCoreAPI() + .usingSite(testSitePublic).getSiteMember(testUser2) + .assertThat().field("role").is("SiteCollaborator"); + + STEP("* 7. Using REST API, U1 remove U2 from public site"); + restAPI.withCoreAPI() + .usingSite(testSitePublic).deleteSiteMember(testUser2); + restAPI.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + STEP("* 8. Using REST API, verify that u2 isn't member of u1 public site"); + restAPI.withCoreAPI() + .usingSite(testSitePublic).getSiteMember(testUser2); + restAPI.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format("The relationship resource was not found for the entity with id: %s and a relationship id of %s", testUser2.getUsername(), testSitePublic.getId())); + } + + /** + * Scenario 17 + * 1. Using CMIS create 3 test user: u1, u2, u3 + * 2. Using CMIS U1 creates a public site + * 3. Using CMIS U1 adds U2 to site with "Contributor" role + * 4. Using CMIS U1 adds U3 to site with "Collaborator" role + * 5. Using REST API, verify the information related to site's containers and members + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.SANITY }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.SITES }, executionType = ExecutionType.SANITY, + description = "Verify user is able to get site membership informations.") + public void userIsAbleToGetSite() throws Exception + { + STEP("* 1. Using CMIS create 3 test user: u1, u2, u3"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + testUser3 = dataUser.createRandomTestUser(); + + STEP("* 2. Using CMIS U1 creates a public site"); + testSitePublic = dataSite.usingUser(testUser1).createPublicRandomSite(); + + STEP("* 3. Using CMIS U1 adds U2 to site with \"Contributor\" role"); + dataUser.usingUser(testUser1).addUserToSite(testUser2, testSitePublic, UserRole.SiteContributor); + + STEP("* 4. Using CMIS U1 adds U3 to site with \"Collaborator\" role"); + dataUser.usingUser(testUser1).addUserToSite(testUser3, testSitePublic, UserRole.SiteCollaborator); + + STEP("* 5. Using REST API, verify the information related to site's containers and members"); + restAPI.authenticateUser(testUser1).withCoreAPI() + .usingSite(testSitePublic).getSite() + .assertThat().field("visibility").is("PUBLIC") + .and().field("id").is(testSitePublic.getId()); + restAPI.withCoreAPI() + .usingSite(testSitePublic).getSiteMembers() + .assertThat().paginationField("count").is("3"); + restAPI.withCoreAPI() + .usingSite(testSitePublic).getSiteContainers() + .assertThat().entriesListContains("folderId", "documentLibrary") + .and().paginationField("totalItems").is("1"); + } + + /** + * Scenario 18 + * 1. Using CMIS create 2 test users: u1 and u2 + * 2. U1 creates a public test site and U2 a moderated test site using CMIS + * 3. U1 creates a folder with a file in public site's document library using WEBDAV + * 4. U2 creates a folder in moderated site's document library using FTP + * 5. U1 tries to copy the folder to moderated site using WebDAV + * 6. Verify folder is not copied. U1 is not authorized to access the moderated site + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.SANITY }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.SANITY, + description = "Verify user is not able to copy folder to a moderated site if it is not a member of that site.") + public void copyFolderToModeratedSiteByUninvitedUser() throws Exception + { + STEP("* 1. Using CMIS create two users: u1 and u2"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + + STEP("* 2. U1 creates a public test site and U2 a moderated test site using CMIS"); + testSitePublic = dataSite.usingUser(testUser1).createPublicRandomSite(); + testSiteModerated = dataSite.usingUser(testUser2).createModeratedRandomSite(); + + STEP("* 3. U1 creates a folder with a file in public site's document library using WEBDAV"); + testFolder1 = FolderModel.getRandomFolderModel(); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file1 content"); + webDavProtocol.authenticateUser(testUser1).usingSite(testSitePublic).createFolder(testFolder1).assertThat().existsInWebdav() + .then().usingResource(testFolder1).createFile(testFile1).then().assertThat().existsInRepo(); + + STEP("* 4. U2 creates a folder in moderated site's document library using FTP"); + testFolder2 = FolderModel.getRandomFolderModel(); + ftpProtocol.authenticateUser(testUser2).usingSite(testSiteModerated).createFolder(testFolder2).assertThat().existsInRepo(); + + STEP("* 5. U1 tries to copy the folder to moderated site using WebDAV" + + "* 6. Verify folder is not copied. U1 is not authorized to access the moderated site"); + testFolder2.setProtocolLocation(webDavProtocol.getPrefixSpace() + testFolder2.getCmisLocation()); + webDavProtocol.authenticateUser(testUser1).usingResource(testFolder1).copyTo(testFolder2).assertThat().doesNotExistInRepo() + .and().assertThat().doesNotExistInWebdav(); + } + + /** + * Scenario 20 + * 1. Using CMIS create 2 test users: u1 and u2 + * 2. U1 creates a public test site and U2 a private test site using CMIS + * 3. U1 creates a file in public site's document library using WEBDAV + * 4. U2 creates a folder in private site's document library using WebDAV + * 5. U1 tries to move his file to folder from U2 private site using IMAP + * 6. Verify file is not moved. U1 is not authorized to access the private site + */ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.SANITY }, expectedExceptions = MessagingException.class) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.CONTENT }, executionType = ExecutionType.SANITY, + description = "Verify user is not able to move file to a private site if he is not a member of that site.") + public void moveFileToPrivateSiteByUninvitedUser() throws Exception + { + STEP("1. Using CMIS create 2 test users: u1 and u2"); + testUser1 = dataUser.createRandomTestUser(); + testUser2 = dataUser.createRandomTestUser(); + + STEP("2. U1 creates a public test site and U2 a private test site using CMIS"); + testSitePublic = dataSite.usingUser(testUser1).createPublicRandomSite(); + testSitePrivate = dataSite.usingUser(testUser2).createPrivateRandomSite(); + + STEP("3. U1 creates a file in public site's document library using WEBDAV"); + testFile1 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "file1 content"); + webDavProtocol.authenticateUser(testUser1).usingSite(testSitePublic).createFile(testFile1).assertThat().existsInRepo(); + + STEP("4. U2 creates a folder in private site's document library using WebDAV"); + testFolder1 = FolderModel.getRandomFolderModel(); + webDavProtocol.authenticateUser(testUser2).usingSite(testSitePrivate).createFolder(testFolder1).assertThat().existsInRepo(); + + STEP("5. U1 tries to move his file to folder from U2 private site using IMAP. 6. Verify file is not moved. U1 is not authorized to access the private site "); + testFolder1.setProtocolLocation(testFolder1.getCmisLocation()); + imapProtocol.authenticateUser(testUser1).usingResource(testFile1).moveMessageTo(testFolder1).assertThat().doesNotContainMessages(testFile1); + } +} diff --git a/tests/tas-integration/src/test/java/org/alfresco/tas/integration/IntegrationTest.java b/tests/tas-integration/src/test/java/org/alfresco/tas/integration/IntegrationTest.java new file mode 100644 index 0000000000..4765948b5a --- /dev/null +++ b/tests/tas-integration/src/test/java/org/alfresco/tas/integration/IntegrationTest.java @@ -0,0 +1,106 @@ +package org.alfresco.tas.integration; + +import java.lang.reflect.Method; + +import org.alfresco.cmis.CmisProperties; +import org.alfresco.cmis.CmisWrapper; +import org.alfresco.dataprep.WorkflowService; +import org.alfresco.email.EmailProperties; +import org.alfresco.email.ImapWrapper; +import org.alfresco.email.SmtpWrapper; +import org.alfresco.ftp.FTPWrapper; +import org.alfresco.rest.core.RestProperties; +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.utility.LogFactory; +import org.alfresco.utility.data.DataContent; +import org.alfresco.utility.data.DataGroup; +import org.alfresco.utility.data.DataSite; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.data.DataWorkflow; +import org.alfresco.utility.extension.ExtentionPointTestUtility; +import org.alfresco.utility.network.ServerHealth; +import org.alfresco.webdav.WebDavWrapper; +import org.slf4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.BeforeSuite; + +@ContextConfiguration("classpath:alfresco-integration-context.xml") +public abstract class IntegrationTest extends AbstractTestNGSpringContextTests +{ + private static Logger LOG = LogFactory.getLogger(); + + @Autowired + protected DataUser dataUser; + + @Autowired + protected DataSite dataSite; + + @Autowired + protected DataContent dataContent; + + @Autowired + protected DataGroup dataGroup; + + @Autowired + protected DataWorkflow dataWorkflow; + + @Autowired + protected WorkflowService workflow; + + @Autowired + protected FTPWrapper ftpProtocol; + + @Autowired + protected WebDavWrapper webDavProtocol; + + @Autowired + protected CmisWrapper cmisAPI; + + @Autowired + protected CmisProperties cmisProperties; + + @Autowired + protected ImapWrapper imapProtocol; + + @Autowired + protected RestWrapper restAPI; + + @Autowired + protected ServerHealth serverHealth; + + @Autowired + protected RestProperties restProperties; + + @Autowired + protected ExtentionPointTestUtility extentionPointTestUtility; + + @Autowired + protected SmtpWrapper smtpProtocol; + + @Autowired + EmailProperties emailProperties; + + @BeforeSuite(alwaysRun = true) + public void checkServerHealth() throws Exception + { + super.springTestContextPrepareTestInstance(); + serverHealth.assertServerIsOnline(); + } + + @BeforeMethod(alwaysRun=true) + public void showStartTestInfo(Method method) + { + LOG.info(String.format("*** STARTING Test: [%s] ***",method.getName())); + } + + @AfterMethod(alwaysRun=true) + public void showEndTestInfo(Method method) + { + LOG.info(String.format("*** ENDING Test: [%s] ***", method.getName())); + } + +} diff --git a/tests/tas-integration/src/test/java/org/alfresco/tas/integration/IntegrationWithAosTests.java b/tests/tas-integration/src/test/java/org/alfresco/tas/integration/IntegrationWithAosTests.java new file mode 100644 index 0000000000..c91e948b28 --- /dev/null +++ b/tests/tas-integration/src/test/java/org/alfresco/tas/integration/IntegrationWithAosTests.java @@ -0,0 +1,88 @@ +package org.alfresco.tas.integration; + +import static org.alfresco.utility.report.log.Step.STEP; + +import io.restassured.RestAssured; +import io.restassured.http.ContentType; +import java.util.HashMap; +import java.util.Map; + +import javax.json.JsonObject; + +import org.alfresco.rest.core.JsonBodyGenerator; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.model.RestHtmlResponse; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.report.Bug.Status; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.commons.codec.binary.Base64; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.testng.annotations.Test; + +/** + * @author Catalin Gornea + */ +public class IntegrationWithAosTests extends IntegrationTest +{ + @Bug(id = "REPO-2096", status = Status.FIXED) + @Test(groups = { TestGroup.INTEGRATION, TestGroup.AOS, TestGroup.FULL, TestGroup.SSO }) + @TestRail(section = { TestGroup.INTEGRATION, + TestGroup.AOS }, executionType = ExecutionType.REGRESSION, description = "Security check for AOS Protocol with External Authentification - MNT-17474") + public void aosCSRFVulnerabilityInSSOEnvironment() throws Exception + { + STEP("1. Post call using RestAPI for specific AOS Security issue"); + UserModel adminUser = dataUser.getAdminUser(); + Map headers = new HashMap(); + String authCookie = String.format("%s:%s", adminUser.getUsername(), adminUser.getPassword()); + String authCookieEncoded = new String(Base64.encodeBase64(authCookie.getBytes())); + headers.put("Authorization", String.format("Basic %s", authCookieEncoded)); + + restAPI.configureRequestSpec().addHeaders(headers); + JsonObject postBody = JsonBodyGenerator.defineJSON().add("method", "create url-directories:6.0.2.8164") + .add("urldirs", "[[url=ExploitedMNT17474;meta_info=[]]]").build(); + restAPI.authenticateUser(adminUser).usingContentType(ContentType.URLENC).withAosAPI(); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody.toString(), "_vti_bin/_vti_aut/author.dll"); + restAPI.process(request); + restAPI.assertStatusCodeIs(HttpStatus.BAD_REQUEST); + } + + @Bug(id = "REPO-2172", status = Status.FIXED) + @Test(groups = { TestGroup.INTEGRATION, TestGroup.AOS, TestGroup.FULL, TestGroup.SSO }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.AOS }, + executionType = ExecutionType.REGRESSION, description = "Non domain user can login to aos through Kerberos successfully.") + public void nonDomainKerberosUserCanLoginSuccessfulInAos() throws Exception { + + STEP("1. Perform a GET request of aos using a non-domain kerberos user"); + String webDavUrl = "alfresco/aos"; + + RestAssured.basePath = ""; + restAPI.configureRequestSpec().setBasePath(RestAssured.basePath); + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, webDavUrl); + RestHtmlResponse response = restAPI.authenticateUser(dataUser.getAdminUser()).processHtmlResponse(request); + restAPI.assertStatusCodeIs(HttpStatus.OK); + response.assertPathInHtmlBodyEquals("html.body.table.tr[1].td[0].text()", "Shared"); + response.assertPathInHtmlBodyEquals("html.body.table.tr[2].td[0].text()", "Imap Attachments"); + } + + @Bug(id = "REPO-2172", status = Status.FIXED) + @Test(groups = { TestGroup.INTEGRATION, TestGroup.WEBDAV, TestGroup.FULL, TestGroup.SSO }) + @TestRail(section = { TestGroup.INTEGRATION, TestGroup.WEBDAV }, + executionType = ExecutionType.REGRESSION, description = "Non domain user can login to webdav through Kerberos successfully.") + public void nonDomainKerberosUserCanLoginSuccessfulInWebDav() throws Exception { + + STEP("1. Perform a GET request of webdav using a non-domain kerberos user"); + String webDavUrl = "alfresco/webdav"; + + RestAssured.basePath = ""; + restAPI.configureRequestSpec().setBasePath(RestAssured.basePath); + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, webDavUrl); + RestHtmlResponse response = restAPI.authenticateUser(dataUser.getAdminUser()).processHtmlResponse(request); + restAPI.assertStatusCodeIs(HttpStatus.OK); + response.assertPathInHtmlBodyEquals("html.body.table.tr.td[0].text()", "Directory listing for /"); + response.assertPathInHtmlBodyEquals("html.body.table.tr.td.find{it.@class=='textData'}[0].text()", "Shared"); + } +} diff --git a/tests/tas-integration/src/test/java/org/alfresco/tas/integration/IntegrationWithCmisTests.java b/tests/tas-integration/src/test/java/org/alfresco/tas/integration/IntegrationWithCmisTests.java new file mode 100644 index 0000000000..b3a5be9a8f --- /dev/null +++ b/tests/tas-integration/src/test/java/org/alfresco/tas/integration/IntegrationWithCmisTests.java @@ -0,0 +1,189 @@ +package org.alfresco.tas.integration; + +import static org.alfresco.utility.report.log.Step.STEP; + +import io.restassured.RestAssured; +import java.util.HashMap; + +import org.alfresco.rest.core.JsonBodyGenerator; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.core.RestResponse; +import org.alfresco.rest.model.RestNodeModel; +import org.alfresco.rest.model.RestRenditionInfoModel; +import org.alfresco.utility.Utility; +import org.alfresco.utility.exception.DataPreparationException; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +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.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + + +public class IntegrationWithCmisTests extends IntegrationTest +{ + private UserModel user; + private SiteModel site; + + @BeforeClass(alwaysRun = true) + public void createUserAndSite() throws DataPreparationException + { + user = dataUser.createRandomTestUser(); + site = dataSite.usingUser(user).createPublicRandomSite(); + } + +// @Test(groups = { TestGroup.INTEGRATION, TestGroup.CMIS, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, + TestGroup.CMIS }, executionType = ExecutionType.REGRESSION, description = "Verify getChildren action for a large number of files from CMIS returns only unique values with few retries") + public void verifyGetChildrenReturnsUniqueValues() throws Exception + { + STEP("1. Create user, site, folder."); + FolderModel folder = FolderModel.getRandomFolderModel(); + folder = dataContent.usingUser(user).usingSite(site).createFolder(folder); + + STEP("2. Create 5000 files in folder using webscript"); + int totalFiles = 5000; + String fileCreationWebScript = "alfresco/s/api/model/filefolder/load"; + HashMap input = new HashMap(); + input.put("folderPath", folder.getCmisLocation()); + input.put("fileCount", String.valueOf(totalFiles)); + String postBody = JsonBodyGenerator.keyValueJson(input); + + RestAssured.basePath = ""; + restAPI.configureRequestSpec().setBasePath(RestAssured.basePath); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody, fileCreationWebScript); + RestResponse response = restAPI.authenticateUser(user).process(request); + Assert.assertEquals(response.getResponse().getStatusCode(), HttpStatus.OK.value()); + + STEP("3. Verify getChildren from CMIS returns unique values"); + cmisAPI.authenticateUser(user).usingSite(site).usingResource(folder); + for (int i = 1; i <= 20; i++) + { + System.out.println(String.format("Try no: %d", i)); + cmisAPI.usingResource(folder).assertThat().hasUniqueChildren(totalFiles); + } + } + + @Test(groups = { TestGroup.INTEGRATION, TestGroup.CMIS, TestGroup.CORE }) + @TestRail(section = { TestGroup.INTEGRATION, + TestGroup.CMIS }, executionType = ExecutionType.REGRESSION, description = "Verify content and thumbnail of TIF files are retrieved by CMIS ") + @Bug(id = "REPO-2042", description = "Should fail only on MAC OS System and Linux") + public void verifyContentAndThumbnailForTifFile() throws Exception + { + STEP("1. Create user, site and a folder "); + FolderModel folder = FolderModel.getRandomFolderModel(); + folder = dataContent.usingUser(user).usingSite(site).createFolder(folder); + + STEP("2. Upload existing TIF file using RESTAPI"); + restAPI.authenticateUser(user).configureRequestSpec().addMultiPart("filedata", Utility.getResourceTestDataFile("my-file.tif")); + + RestNodeModel fileNode = restAPI.authenticateUser(user).withCoreAPI().usingNode(folder).createNode(); + restAPI.assertStatusCodeIs(HttpStatus.CREATED); + FileModel file = new FileModel("my-file.tif"); + file.setCmisLocation(folder.getCmisLocation() + "/my-file.tif"); + file.setNodeRef(fileNode.getId()); + + STEP("3. Create thumbnail and content of TIF files using file"); + restAPI.withCoreAPI().usingNode(file).createNodeRendition("pdf"); + restAPI.assertStatusCodeIs(HttpStatus.ACCEPTED); + restAPI.withCoreAPI().usingNode(file).createNodeRendition("doclib"); + restAPI.assertStatusCodeIs(HttpStatus.ACCEPTED); + + STEP("4. Verify thumbnail and content of TIF files are created using RESTAPI"); + cmisAPI.authenticateUser(user).usingSite(site).usingResource(folder).usingResource(file).assertThat().contentContains("Adobe Photoshop CC 2015"); + RestRenditionInfoModel renditionInfo = restAPI.withCoreAPI().usingNode(file).getNodeRendition("pdf"); + restAPI.assertStatusCodeIs(HttpStatus.OK); + renditionInfo.assertThat().field("status").is("CREATED"); + renditionInfo = restAPI.withCoreAPI().usingNode(file).getNodeRendition("doclib"); + restAPI.assertStatusCodeIs(HttpStatus.OK); + renditionInfo.assertThat().field("status").is("CREATED"); + } + + @Test(groups = { TestGroup.INTEGRATION, TestGroup.CMIS, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, + TestGroup.CMIS }, executionType = ExecutionType.REGRESSION, description = "Verify getChildren action for a large number of files from CMIS returns only unique values with few retries") + public void verifyContentDispositionForContentThatAreWhiteListed() throws Exception + { + + STEP("1. Create a .pdf and a .html file in the Shared folder in CMIS"); + FolderModel sharedFolder = FolderModel.getSharedFolderModel(); + FileModel pdfFile = FileModel.getRandomFileModel(FileType.PDF); + FileModel htmlFile = FileModel.getRandomFileModel(FileType.HTML); + + STEP("2. Upload the .pdf file and verify the reponse header adding the download=inline/attachement parameters (accepted both)."); + cmisAPI.authenticateUser(user).usingResource(sharedFolder).createFile(pdfFile); + + RestResponse response = restAPI.authenticateUser(user).withCMISApi().getRootObjectByLocation(pdfFile); + restAPI.assertStatusCodeIs(HttpStatus.OK); + response.assertThat().header("Content-Disposition", String.format("inline; filename=%s", pdfFile.getName())); + + response = restAPI.authenticateUser(user).withCMISApi().usingParams("download=inline").getRootObjectByLocation(pdfFile); + restAPI.assertStatusCodeIs(HttpStatus.OK); + response.assertThat().header("Content-Disposition", String.format("inline; filename=%s", pdfFile.getName())); + + response = restAPI.authenticateUser(user).withCMISApi().usingParams("download=attachment").getRootObjectByLocation(pdfFile); + restAPI.assertStatusCodeIs(HttpStatus.OK); + response.assertThat().header("Content-Disposition", String.format("attachment; filename=%s", pdfFile.getName())); + + STEP("3. Upload the .html file and verify the reponse header adding the download=inline/attachement parameters (accepted only attachment) ."); + cmisAPI.usingResource(sharedFolder).createFile(htmlFile); + + response = restAPI.authenticateUser(user).withCMISApi().getRootObjectByLocation(htmlFile); + restAPI.assertStatusCodeIs(HttpStatus.OK); + response.assertThat().header("Content-Disposition", String.format("attachment; filename=%s", htmlFile.getName())); + + response = restAPI.authenticateUser(user).withCMISApi().usingParams("download=attachment").getRootObjectByLocation(htmlFile); + restAPI.assertStatusCodeIs(HttpStatus.OK); + response.assertThat().header("Content-Disposition", String.format("attachment; filename=%s", htmlFile.getName())); + + response = restAPI.authenticateUser(user).withCMISApi().usingParams("download=inline").getRootObjectByLocation(htmlFile); + restAPI.assertStatusCodeIs(HttpStatus.OK); + response.assertThat().header("Content-Disposition", String.format("attachment; filename=%s", htmlFile.getName())); + } + + @Test(groups = { TestGroup.INTEGRATION, TestGroup.CMIS, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, + TestGroup.CMIS }, executionType = ExecutionType.SANITY, description = "Verify that alfresco returns the correct encoding for files created via CMIS.") + public void verifyFileEncodingUsingCMIS() throws Exception + { + STEP("1. Create a folder, two text file with specific encoding content and define the expected encoding."); + FileModel utf8File = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, " ∮ E⋅da = Q"); + FileModel iso8859File = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, + "aegif Mind Share Leader Generating New Paradigms by aegif corporation

Test html

"); + String utf8Type = "text/plain;charset=UTF-8"; + String iso8859Type = "text/plain;charset=ISO-8859-1"; + + STEP("2. Upload the files via CMIS."); + cmisAPI.authenticateUser(user).usingSite(site).createFile(utf8File); + cmisAPI.createFile(iso8859File); + + String fileCreationWebScript = "alfresco/service/api/node/content/workspace/SpacesStore/"; + RestAssured.basePath = ""; + + STEP("3. Retrieve the nodes via webscripts and verify that the content type is the expected one (GET alfresco/service/api/node/content/workspace/SpacesStore/)."); + restAPI.configureRequestSpec().setBasePath(RestAssured.basePath); + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, fileCreationWebScript + utf8File.getNodeRefWithoutVersion()); + RestResponse response = restAPI.authenticateUser(user).process(request); + Assert.assertEquals(response.getResponse().getStatusCode(), HttpStatus.OK.value()); + Assert.assertEquals(response.getResponse().getContentType(), utf8Type); + + request = RestRequest.simpleRequest(HttpMethod.GET, fileCreationWebScript + iso8859File.getNodeRefWithoutVersion()); + response = restAPI.process(request); + Assert.assertEquals(response.getResponse().getStatusCode(), HttpStatus.OK.value()); + Assert.assertEquals(response.getResponse().getContentType(), iso8859Type); + + // Commented the use of v1 RestAPI GET (nodes/{nodeId}), because it works on alfresco 5.2.N or above. + // STEP("3. Retrieve the nodes and verify that the content type is the expected one (GET nodes/{nodeId})."); + // restAPI.authenticateUser(user).withCoreAPI().usingNode(utf8File).getNodeContent().assertThat().contentType(utf8Type); + // restAPI.authenticateUser(user).withCoreAPI().usingNode(iso8859File).getNodeContent().assertThat().contentType(iso8859Type); + + } +} diff --git a/tests/tas-integration/src/test/java/org/alfresco/tas/integration/IntegrationWithWebScriptsTests.java b/tests/tas-integration/src/test/java/org/alfresco/tas/integration/IntegrationWithWebScriptsTests.java new file mode 100644 index 0000000000..9680d39fa0 --- /dev/null +++ b/tests/tas-integration/src/test/java/org/alfresco/tas/integration/IntegrationWithWebScriptsTests.java @@ -0,0 +1,82 @@ +package org.alfresco.tas.integration; + +import static org.alfresco.utility.report.log.Step.STEP; + +import io.restassured.RestAssured; +import io.restassured.http.Cookie; +import io.restassured.response.Response; +import java.net.URLDecoder; +import java.util.HashMap; + +import java.util.List; +import org.alfresco.rest.core.JsonBodyGenerator; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.model.RestPersonModel; +import org.alfresco.utility.Utility; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.commons.codec.binary.Base64; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.testng.Assert; +import org.testng.annotations.Test; + +public class IntegrationWithWebScriptsTests extends IntegrationTest +{ + @Test(groups = { TestGroup.INTEGRATION, TestGroup.REST_API, TestGroup.FULL }) + @TestRail(section = { TestGroup.INTEGRATION, + TestGroup.REST_API }, executionType = ExecutionType.REGRESSION, description = "Verify when importing multiple users via CSV, if the password is not set in the CSV file, user will be disable") + public void verifyCSVUserImportDisableUserAndGivesRandomPasswordIfItIsMissing() throws Exception + { + STEP("1.Upload the CSV File that contains the users."); + restAPI.authenticateUser(dataUser.getAdminUser()).configureRequestSpec().addMultiPart("filedata", + Utility.getResourceTestDataFile("userCSV.csv")); + String fileCreationWebScript = "alfresco/s/api/people/upload"; + RestAssured.basePath = ""; + restAPI.configureRequestSpec().setBasePath(RestAssured.basePath); + RestRequest request = RestRequest.simpleRequest(HttpMethod.POST, fileCreationWebScript); + restAPI.authenticateUser(dataUser.getAdminUser()).process(request); + restAPI.assertStatusCodeIs(HttpStatus.OK); + + STEP("2.Verify that user1np is disabled and user2 is enabled"); + UserModel disabledUserPerson = new UserModel("MNT-171990-user-with-no-password", "user1"); + UserModel enabledUserPerson = new UserModel("MNT-171990-user-with-password", "user2"); + RestPersonModel personModel = restAPI.authenticateUser(dataUser.getAdminUser()).withCoreAPI() + .usingUser(new UserModel(disabledUserPerson.getUsername(), disabledUserPerson.getPassword())).getPerson(); + restAPI.assertStatusCodeIs(HttpStatus.OK); + personModel.assertThat().field("enabled").is("false"); + personModel = restAPI.authenticateUser(dataUser.getAdminUser()).withCoreAPI() + .usingUser(new UserModel(enabledUserPerson.getUsername(), enabledUserPerson.getPassword())).getPerson(); + restAPI.assertStatusCodeIs(HttpStatus.OK); + personModel.assertThat().field("enabled").is("true"); + + STEP("3.Activate the disabled user."); + HashMap input = new HashMap(); + input.put("enabled", "true"); + String putBody = JsonBodyGenerator.keyValueJson(input); + restAPI.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingUser(disabledUserPerson).updatePerson(putBody); + restAPI.assertStatusCodeIs(HttpStatus.OK); + + STEP("4.Verify that the disabled user has a randomly generated password not the same as firstname(DOCS-2755)"); + restAPI.authenticateUser(disabledUserPerson).withCoreAPI() + .usingUser(new UserModel(enabledUserPerson.getUsername(), enabledUserPerson.getPassword())).getPerson(); + restAPI.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + + STEP("5.Change the user password and try an Rest API call."); + input = new HashMap(); + input.put("password", "newPassword1"); + putBody = JsonBodyGenerator.keyValueJson(input); + restAPI.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingUser(disabledUserPerson).updatePerson(putBody); + restAPI.assertStatusCodeIs(HttpStatus.OK); + disabledUserPerson = new UserModel(disabledUserPerson.getUsername(), "newPassword1"); + restAPI.authenticateUser(disabledUserPerson).withCoreAPI() + .usingUser(new UserModel(enabledUserPerson.getUsername(), enabledUserPerson.getPassword())).getPerson(); + restAPI.assertStatusCodeIs(HttpStatus.OK); + + dataUser.usingAdmin().deleteUser(disabledUserPerson); + dataUser.usingAdmin().deleteUser(enabledUserPerson); + } +} diff --git a/tests/tas-integration/src/test/resources/alfresco-integration-context.xml b/tests/tas-integration/src/test/resources/alfresco-integration-context.xml new file mode 100644 index 0000000000..4641a01443 --- /dev/null +++ b/tests/tas-integration/src/test/resources/alfresco-integration-context.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + diff --git a/tests/tas-integration/src/test/resources/default.properties b/tests/tas-integration/src/test/resources/default.properties new file mode 100644 index 0000000000..7da5acaf77 --- /dev/null +++ b/tests/tas-integration/src/test/resources/default.properties @@ -0,0 +1,148 @@ +# dataprep related +alfresco.scheme=http +alfresco.server=localhost +alfresco.port=8082 + +# credentials +admin.user=admin +admin.password=admin +admin.name=Administrator + +# in containers we cannot access directly JMX, so we will use http://jolokia.org agent +# disabling this we will use direct JMX calls to server +jmx.useJolokiaAgent=false + +# Server Health section +# in ServerHealth#isServerReachable() - could also be shown. +# enable this option to view if on server there are tenants or not +serverHealth.showTenants=false + +# IMAP Service settings from admin console +imap.server=${alfresco.server} +imap.port=143 +imaps.port=993 + +# Inbound Email settings from admin console +smtp.server=${alfresco.server} +smtp.port=25 +smtp.authentication.enabled=true +smtp.tsl.enabled=false + +# Outbound Email settings from admin console +mail.encoding=UTF-8 +mail.from.default=admin@alfness.com +mail.from.enabled=true +mail.host=172.29.100.164 +mail.password=admin +mail.port=25 +mail.protocol=smtp +mail.smtp.auth=true +mail.smtp.debug=false +mail.smtp.starttls.enable=true +mail.smtp.timeout=30000 +mail.smtps.auth=true +mail.smtps.starttls.enable=true +mail.username=admin@alfness.com + +# FTP related +ftp.port=21 +ftp.timeout=20000 +# use passive or active depending where the tests are run +# (docker env or not) +ftp.passiveMode=true + +# CMIS related +# set cmis binding to 'browser' or 'atom' +cmis.binding=browser +cmis.basePath=/alfresco/api/-default-/public/cmis/versions/1.1/${cmis.binding} + +# WEBDAV related +webdav.port=${alfresco.port} + +# AOS related +aos.path=/alfresco/aos +aos.windowsNetwork=\\\${alfresco.server}:${alfresco.port}${aos.path} +aos.linuxNetwork=${alfresco.scheme}://${alfresco.server}:${alfresco.port}${aos.path} + +# TEST MANAGEMENT SECTION - Test Rail +# +# (currently supporting Test Rail v5.2.1.3472 integration) +# +# Example of configuration: +# ------------------------------------------------------ +# if testManagement.enabled=true we enabled TestRailExecutorListener (if used in your suite xml file) +# testManagement.updateTestExecutionResultsOnly=true (this will just update the results of a test: no step will be updated - good for performance) +# testManagement.endPoint=https://alfresco.testrail.com/ +# testManagement.username= +# testManagement.apiKey= +# testManagement.project= +# testManagement.includeOnlyTestCasesExecuted=true #if you want to include in your run ONLY the test cases that you run, then set this value to false +# testManagement.rateLimitInSeconds=1 #is the default rate limit after what minimum time, should we upload the next request. http://docs.gurock.com/testrail-api2/introduction #Rate Limit +# testManagement.suiteId=23 (the id of the Master suite) +# ------------------------------------------------------ +testManagement.enabled=false +testManagement.endPoint= +testManagement.username= +testManagement.apiKey= +testManagement.project=7 +testManagement.includeOnlyTestCasesExecuted=true +testManagement.rateLimitInSeconds=1 +testManagement.testRun=MyTestRunInTestRail +testManagement.suiteId=12 + +# The location of the reports path +reports.path=./target/reports + +# +# Database Section +# You should provide here the database URL, that can be a differed server as alfresco. +# https://docs.oracle.com/javase/tutorial/jdbc/basics/connecting.html +# +# Current supported db.url: +# +# MySQL: +# db.url = jdbc:mysql://${alfresco.server}:3306/alfresco +# +# PostgreSQL: +# db.url = jdbc:postgresql://:3306/alfresco +# +# Oracle: +# db.url = jdbc:oracle://:3306/alfresco +# +# MariaDB: +# db.url = jdbc:mariadb://:3306/alfresco +# +db.url = jdbc:mysql://${alfresco.server}:3306/alfresco +db.username = alfresco +db.password = alfresco + +# ------------------------------------------------------ +#WEB specific +# ------------------------------------------------------ +# set browser type: Firefox, Chrome +browser.name=Firefox +browser.version=41.0 +# browser.chrome.driver=/Users/p3700454/projects/drivers/chromedriver +env.platform=WINDOWS + +# default implicit wait for web elements to be rendered +browser.implicitWait=3 +browser.explicitWait=30 + +share.port=${alfresco.port} +share.url=${alfresco.scheme}://${alfresco.server}:${share.port}/share +share2.url=${server2.url}:${server2.port}/share +server2.port=9090 +server2.url=http://172.29.100.215 + +# location of all screenshots taken on failed test +screenshots.dir=screenshots + +# grid based settings +grid.enabled=false +grid.url=http://127.0.0.1:4444/wd/hub + +# handle internationalization +locale.language=en +locale.country=US diff --git a/tests/tas-integration/src/test/resources/integration-suite.xml b/tests/tas-integration/src/test/resources/integration-suite.xml new file mode 100644 index 0000000000..d37f64fc5d --- /dev/null +++ b/tests/tas-integration/src/test/resources/integration-suite.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/tas-integration/src/test/resources/log4j.properties b/tests/tas-integration/src/test/resources/log4j.properties new file mode 100644 index 0000000000..00e9b5a114 --- /dev/null +++ b/tests/tas-integration/src/test/resources/log4j.properties @@ -0,0 +1,26 @@ +# Root logger option +log4j.rootLogger=INFO, file, stdout + +# Direct log messages to a log file +log4j.appender.file=org.apache.log4j.RollingFileAppender +log4j.appender.file.File=./target/reports/alfresco-tas.log +log4j.appender.file.MaxBackupIndex=10 +log4j.appender.file.layout=org.apache.log4j.PatternLayout +log4j.appender.file.layout.ConversionPattern=[%t] %d{HH:mm:ss} %-5p %c{1}:%L - %m%n + +# Direct log messages to stdout +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=[%t] %d{HH:mm:ss} %-5p %c{1}:%L - %m%n + +# TestRail particular log file +# Direct log messages to a log file +log4j.appender.testrailLog=org.apache.log4j.RollingFileAppender +log4j.appender.testrailLog.File=./target/reports/alfresco-testrail.log +log4j.appender.testrailLog.MaxBackupIndex=10 +log4j.appender.testrailLog.layout=org.apache.log4j.PatternLayout +log4j.appender.testrailLog.layout.ConversionPattern=%d{HH:mm:ss} %-5p %c{1}:%L - %m%n + +log4j.category.testrail=INFO, testrailLog +log4j.additivity.testrail=false \ No newline at end of file diff --git a/tests/tas-integration/src/test/resources/shared-resources/testdata/.keepme b/tests/tas-integration/src/test/resources/shared-resources/testdata/.keepme new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/tas-integration/src/test/resources/shared-resources/testdata/extentionPointTestSuiteTemplate.xsd b/tests/tas-integration/src/test/resources/shared-resources/testdata/extentionPointTestSuiteTemplate.xsd new file mode 100644 index 0000000000..26ec6f0a32 --- /dev/null +++ b/tests/tas-integration/src/test/resources/shared-resources/testdata/extentionPointTestSuiteTemplate.xsd @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/tas-integration/src/test/resources/shared-resources/testdata/flower.jpg b/tests/tas-integration/src/test/resources/shared-resources/testdata/flower.jpg new file mode 100644 index 0000000000..1aa016ba10 Binary files /dev/null and b/tests/tas-integration/src/test/resources/shared-resources/testdata/flower.jpg differ diff --git a/tests/tas-integration/src/test/resources/shared-resources/testdata/my-file.tif b/tests/tas-integration/src/test/resources/shared-resources/testdata/my-file.tif new file mode 100644 index 0000000000..612bfa9c0b Binary files /dev/null and b/tests/tas-integration/src/test/resources/shared-resources/testdata/my-file.tif differ diff --git a/tests/tas-integration/src/test/resources/shared-resources/testdata/nonemptyupload.txt b/tests/tas-integration/src/test/resources/shared-resources/testdata/nonemptyupload.txt new file mode 100644 index 0000000000..44f73e0fc5 --- /dev/null +++ b/tests/tas-integration/src/test/resources/shared-resources/testdata/nonemptyupload.txt @@ -0,0 +1 @@ +text file to upload \ No newline at end of file diff --git a/tests/tas-integration/src/test/resources/shared-resources/testdata/test.docx b/tests/tas-integration/src/test/resources/shared-resources/testdata/test.docx new file mode 100644 index 0000000000..e5d64a4091 Binary files /dev/null and b/tests/tas-integration/src/test/resources/shared-resources/testdata/test.docx differ diff --git a/tests/tas-integration/src/test/resources/shared-resources/testdata/test.html b/tests/tas-integration/src/test/resources/shared-resources/testdata/test.html new file mode 100644 index 0000000000..9daeafb986 --- /dev/null +++ b/tests/tas-integration/src/test/resources/shared-resources/testdata/test.html @@ -0,0 +1 @@ +test diff --git a/tests/tas-integration/src/test/resources/shared-resources/testdata/test.msg b/tests/tas-integration/src/test/resources/shared-resources/testdata/test.msg new file mode 100644 index 0000000000..b981bb9aee Binary files /dev/null and b/tests/tas-integration/src/test/resources/shared-resources/testdata/test.msg differ diff --git a/tests/tas-integration/src/test/resources/shared-resources/testdata/test.rtf b/tests/tas-integration/src/test/resources/shared-resources/testdata/test.rtf new file mode 100644 index 0000000000..dd99bca460 --- /dev/null +++ b/tests/tas-integration/src/test/resources/shared-resources/testdata/test.rtf @@ -0,0 +1,196 @@ +{\rtf1\adeflang1025\ansi\ansicpg1252\uc1\adeff0\deff0\stshfdbch31505\stshfloch31506\stshfhich31506\stshfbi0\deflang1033\deflangfe1033\themelang1033\themelangfe0\themelangcs0{\fonttbl{\f0\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f0\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;} +{\f39\fbidi \fswiss\fcharset0\fprq2{\*\panose 020f0502020204030204}Calibri;}{\flomajor\f31500\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;} +{\fdbmajor\f31501\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\fhimajor\f31502\fbidi \fswiss\fcharset0\fprq2{\*\panose 020f0302020204030204}Calibri Light;} +{\fbimajor\f31503\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\flominor\f31504\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;} +{\fdbminor\f31505\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\fhiminor\f31506\fbidi \fswiss\fcharset0\fprq2{\*\panose 020f0502020204030204}Calibri;} +{\fbiminor\f31507\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f40\fbidi \froman\fcharset238\fprq2 Times New Roman CE;}{\f41\fbidi \froman\fcharset204\fprq2 Times New Roman Cyr;} +{\f43\fbidi \froman\fcharset161\fprq2 Times New Roman Greek;}{\f44\fbidi \froman\fcharset162\fprq2 Times New Roman Tur;}{\f45\fbidi \froman\fcharset177\fprq2 Times New Roman (Hebrew);}{\f46\fbidi \froman\fcharset178\fprq2 Times New Roman (Arabic);} +{\f47\fbidi \froman\fcharset186\fprq2 Times New Roman Baltic;}{\f48\fbidi \froman\fcharset163\fprq2 Times New Roman (Vietnamese);}{\f40\fbidi \froman\fcharset238\fprq2 Times New Roman CE;}{\f41\fbidi \froman\fcharset204\fprq2 Times New Roman Cyr;} +{\f43\fbidi \froman\fcharset161\fprq2 Times New Roman Greek;}{\f44\fbidi \froman\fcharset162\fprq2 Times New Roman Tur;}{\f45\fbidi \froman\fcharset177\fprq2 Times New Roman (Hebrew);}{\f46\fbidi \froman\fcharset178\fprq2 Times New Roman (Arabic);} +{\f47\fbidi \froman\fcharset186\fprq2 Times New Roman Baltic;}{\f48\fbidi \froman\fcharset163\fprq2 Times New Roman (Vietnamese);}{\f430\fbidi \fswiss\fcharset238\fprq2 Calibri CE;}{\f431\fbidi \fswiss\fcharset204\fprq2 Calibri Cyr;} +{\f433\fbidi \fswiss\fcharset161\fprq2 Calibri Greek;}{\f434\fbidi \fswiss\fcharset162\fprq2 Calibri Tur;}{\f437\fbidi \fswiss\fcharset186\fprq2 Calibri Baltic;}{\f438\fbidi \fswiss\fcharset163\fprq2 Calibri (Vietnamese);} +{\flomajor\f31508\fbidi \froman\fcharset238\fprq2 Times New Roman CE;}{\flomajor\f31509\fbidi \froman\fcharset204\fprq2 Times New Roman Cyr;}{\flomajor\f31511\fbidi \froman\fcharset161\fprq2 Times New Roman Greek;} +{\flomajor\f31512\fbidi \froman\fcharset162\fprq2 Times New Roman Tur;}{\flomajor\f31513\fbidi \froman\fcharset177\fprq2 Times New Roman (Hebrew);}{\flomajor\f31514\fbidi \froman\fcharset178\fprq2 Times New Roman (Arabic);} +{\flomajor\f31515\fbidi \froman\fcharset186\fprq2 Times New Roman Baltic;}{\flomajor\f31516\fbidi \froman\fcharset163\fprq2 Times New Roman (Vietnamese);}{\fdbmajor\f31518\fbidi \froman\fcharset238\fprq2 Times New Roman CE;} +{\fdbmajor\f31519\fbidi \froman\fcharset204\fprq2 Times New Roman Cyr;}{\fdbmajor\f31521\fbidi \froman\fcharset161\fprq2 Times New Roman Greek;}{\fdbmajor\f31522\fbidi \froman\fcharset162\fprq2 Times New Roman Tur;} +{\fdbmajor\f31523\fbidi \froman\fcharset177\fprq2 Times New Roman (Hebrew);}{\fdbmajor\f31524\fbidi \froman\fcharset178\fprq2 Times New Roman (Arabic);}{\fdbmajor\f31525\fbidi \froman\fcharset186\fprq2 Times New Roman Baltic;} +{\fdbmajor\f31526\fbidi \froman\fcharset163\fprq2 Times New Roman (Vietnamese);}{\fhimajor\f31528\fbidi \fswiss\fcharset238\fprq2 Calibri Light CE;}{\fhimajor\f31529\fbidi \fswiss\fcharset204\fprq2 Calibri Light Cyr;} +{\fhimajor\f31531\fbidi \fswiss\fcharset161\fprq2 Calibri Light Greek;}{\fhimajor\f31532\fbidi \fswiss\fcharset162\fprq2 Calibri Light Tur;}{\fhimajor\f31535\fbidi \fswiss\fcharset186\fprq2 Calibri Light Baltic;} +{\fhimajor\f31536\fbidi \fswiss\fcharset163\fprq2 Calibri Light (Vietnamese);}{\fbimajor\f31538\fbidi \froman\fcharset238\fprq2 Times New Roman CE;}{\fbimajor\f31539\fbidi \froman\fcharset204\fprq2 Times New Roman Cyr;} +{\fbimajor\f31541\fbidi \froman\fcharset161\fprq2 Times New Roman Greek;}{\fbimajor\f31542\fbidi \froman\fcharset162\fprq2 Times New Roman Tur;}{\fbimajor\f31543\fbidi \froman\fcharset177\fprq2 Times New Roman (Hebrew);} +{\fbimajor\f31544\fbidi \froman\fcharset178\fprq2 Times New Roman (Arabic);}{\fbimajor\f31545\fbidi \froman\fcharset186\fprq2 Times New Roman Baltic;}{\fbimajor\f31546\fbidi \froman\fcharset163\fprq2 Times New Roman (Vietnamese);} +{\flominor\f31548\fbidi \froman\fcharset238\fprq2 Times New Roman CE;}{\flominor\f31549\fbidi \froman\fcharset204\fprq2 Times New Roman Cyr;}{\flominor\f31551\fbidi \froman\fcharset161\fprq2 Times New Roman Greek;} +{\flominor\f31552\fbidi \froman\fcharset162\fprq2 Times New Roman Tur;}{\flominor\f31553\fbidi \froman\fcharset177\fprq2 Times New Roman (Hebrew);}{\flominor\f31554\fbidi \froman\fcharset178\fprq2 Times New Roman (Arabic);} +{\flominor\f31555\fbidi \froman\fcharset186\fprq2 Times New Roman Baltic;}{\flominor\f31556\fbidi \froman\fcharset163\fprq2 Times New Roman (Vietnamese);}{\fdbminor\f31558\fbidi \froman\fcharset238\fprq2 Times New Roman CE;} +{\fdbminor\f31559\fbidi \froman\fcharset204\fprq2 Times New Roman Cyr;}{\fdbminor\f31561\fbidi \froman\fcharset161\fprq2 Times New Roman Greek;}{\fdbminor\f31562\fbidi \froman\fcharset162\fprq2 Times New Roman Tur;} +{\fdbminor\f31563\fbidi \froman\fcharset177\fprq2 Times New Roman (Hebrew);}{\fdbminor\f31564\fbidi \froman\fcharset178\fprq2 Times New Roman (Arabic);}{\fdbminor\f31565\fbidi \froman\fcharset186\fprq2 Times New Roman Baltic;} +{\fdbminor\f31566\fbidi \froman\fcharset163\fprq2 Times New Roman (Vietnamese);}{\fhiminor\f31568\fbidi \fswiss\fcharset238\fprq2 Calibri CE;}{\fhiminor\f31569\fbidi \fswiss\fcharset204\fprq2 Calibri Cyr;} +{\fhiminor\f31571\fbidi \fswiss\fcharset161\fprq2 Calibri Greek;}{\fhiminor\f31572\fbidi \fswiss\fcharset162\fprq2 Calibri Tur;}{\fhiminor\f31575\fbidi \fswiss\fcharset186\fprq2 Calibri Baltic;} +{\fhiminor\f31576\fbidi \fswiss\fcharset163\fprq2 Calibri (Vietnamese);}{\fbiminor\f31578\fbidi \froman\fcharset238\fprq2 Times New Roman CE;}{\fbiminor\f31579\fbidi \froman\fcharset204\fprq2 Times New Roman Cyr;} +{\fbiminor\f31581\fbidi \froman\fcharset161\fprq2 Times New Roman Greek;}{\fbiminor\f31582\fbidi \froman\fcharset162\fprq2 Times New Roman Tur;}{\fbiminor\f31583\fbidi \froman\fcharset177\fprq2 Times New Roman (Hebrew);} +{\fbiminor\f31584\fbidi \froman\fcharset178\fprq2 Times New Roman (Arabic);}{\fbiminor\f31585\fbidi \froman\fcharset186\fprq2 Times New Roman Baltic;}{\fbiminor\f31586\fbidi \froman\fcharset163\fprq2 Times New Roman (Vietnamese);}} +{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0; +\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;\red192\green192\blue192;}{\*\defchp \fs22\loch\af31506\hich\af31506\dbch\af31505 }{\*\defpap \ql \li0\ri0\sa160\sl259\slmult1 +\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 }\noqfpromote {\stylesheet{\ql \li0\ri0\sa160\sl259\slmult1\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \rtlch\fcs1 \af0\afs22\alang1025 \ltrch\fcs0 +\fs22\lang1033\langfe1033\loch\f31506\hich\af31506\dbch\af31505\cgrid\langnp1033\langfenp1033 \snext0 \sqformat \spriority0 Normal;}{\*\cs10 \additive \ssemihidden \sunhideused \spriority1 Default Paragraph Font;}{\* +\ts11\tsrowd\trftsWidthB3\trpaddl108\trpaddr108\trpaddfl3\trpaddft3\trpaddfb3\trpaddfr3\trcbpat1\trcfpat1\tblind0\tblindtype3\tsvertalt\tsbrdrt\tsbrdrl\tsbrdrb\tsbrdrr\tsbrdrdgl\tsbrdrdgr\tsbrdrh\tsbrdrv \ql \li0\ri0\sa160\sl259\slmult1 +\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \rtlch\fcs1 \af0\afs22\alang1025 \ltrch\fcs0 \fs22\lang1033\langfe1033\loch\f31506\hich\af31506\dbch\af31505\cgrid\langnp1033\langfenp1033 \snext11 \ssemihidden \sunhideused +Normal Table;}}{\*\rsidtbl \rsid5330132\rsid6713591\rsid12614322\rsid14699881}{\mmathPr\mmathFont34\mbrkBin0\mbrkBinSub0\msmallFrac0\mdispDef1\mlMargin0\mrMargin0\mdefJc1\mwrapIndent1440\mintLim0\mnaryLim1}{\info{\operator Alecsandru Pruna} +{\creatim\yr2017\mo2\dy9\hr9\min19}{\revtim\yr2017\mo2\dy9\hr9\min20}{\version4}{\edmins0}{\nofpages1}{\nofwords0}{\nofchars5}{\nofcharsws5}{\vern19}}{\*\xmlnstbl {\xmlns1 http://schemas.microsoft.com/office/word/2003/wordml}} +\paperw12240\paperh15840\margl1440\margr1440\margt1440\margb1440\gutter0\ltrsect +\widowctrl\ftnbj\aenddoc\trackmoves0\trackformatting1\donotembedsysfont0\relyonvml0\donotembedlingdata1\grfdocevents0\validatexml0\showplaceholdtext0\ignoremixedcontent0\saveinvalidxml0\showxmlerrors0\horzdoc\dghspace120\dgvspace120\dghorigin1701 +\dgvorigin1984\dghshow0\dgvshow3\jcompress\viewkind1\viewscale100\rsidroot14699881 \fet0{\*\wgrffmtfilter 2450}\ilfomacatclnup0\ltrpar \sectd \ltrsect\linex0\sectdefaultcl\sftnbj {\*\pnseclvl1\pnucrm\pnstart1\pnindent720\pnhang {\pntxta .}}{\*\pnseclvl2 +\pnucltr\pnstart1\pnindent720\pnhang {\pntxta .}}{\*\pnseclvl3\pndec\pnstart1\pnindent720\pnhang {\pntxta .}}{\*\pnseclvl4\pnlcltr\pnstart1\pnindent720\pnhang {\pntxta )}}{\*\pnseclvl5\pndec\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl6 +\pnlcltr\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl7\pnlcrm\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl8\pnlcltr\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl9\pnlcrm\pnstart1\pnindent720\pnhang +{\pntxtb (}{\pntxta )}}\pard\plain \ltrpar\ql \li0\ri0\sa160\sl259\slmult1\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \rtlch\fcs1 \af0\afs22\alang1025 \ltrch\fcs0 +\fs22\lang1033\langfe1033\loch\af31506\hich\af31506\dbch\af31505\cgrid\langnp1033\langfenp1033 {\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid5330132 \hich\af31506\dbch\af31505\loch\f31506 t}{\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid14699881 +\hich\af31506\dbch\af31505\loch\f31506 est}{\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid12614322 +\par }{\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid6713591 +\par }{\*\themedata 504b030414000600080000002100e9de0fbfff0000001c020000130000005b436f6e74656e745f54797065735d2e786d6cac91cb4ec3301045f748fc83e52d4a +9cb2400825e982c78ec7a27cc0c8992416c9d8b2a755fbf74cd25442a820166c2cd933f79e3be372bd1f07b5c3989ca74aaff2422b24eb1b475da5df374fd9ad +5689811a183c61a50f98f4babebc2837878049899a52a57be670674cb23d8e90721f90a4d2fa3802cb35762680fd800ecd7551dc18eb899138e3c943d7e503b6 +b01d583deee5f99824e290b4ba3f364eac4a430883b3c092d4eca8f946c916422ecab927f52ea42b89a1cd59c254f919b0e85e6535d135a8de20f20b8c12c3b0 +0c895fcf6720192de6bf3b9e89ecdbd6596cbcdd8eb28e7c365ecc4ec1ff1460f53fe813d3cc7f5b7f020000ffff0300504b030414000600080000002100a5d6 +a7e7c0000000360100000b0000005f72656c732f2e72656c73848fcf6ac3300c87ef85bd83d17d51d2c31825762fa590432fa37d00e1287f68221bdb1bebdb4f +c7060abb0884a4eff7a93dfeae8bf9e194e720169aaa06c3e2433fcb68e1763dbf7f82c985a4a725085b787086a37bdbb55fbc50d1a33ccd311ba548b6309512 +0f88d94fbc52ae4264d1c910d24a45db3462247fa791715fd71f989e19e0364cd3f51652d73760ae8fa8c9ffb3c330cc9e4fc17faf2ce545046e37944c69e462 +a1a82fe353bd90a865aad41ed0b5b8f9d6fd010000ffff0300504b0304140006000800000021006b799616830000008a0000001c0000007468656d652f746865 +6d652f7468656d654d616e616765722e786d6c0ccc4d0ac3201040e17da17790d93763bb284562b2cbaebbf600439c1a41c7a0d29fdbd7e5e38337cedf14d59b +4b0d592c9c070d8a65cd2e88b7f07c2ca71ba8da481cc52c6ce1c715e6e97818c9b48d13df49c873517d23d59085adb5dd20d6b52bd521ef2cdd5eb9246a3d8b +4757e8d3f729e245eb2b260a0238fd010000ffff0300504b030414000600080000002100ec7f4c3895070000c9200000160000007468656d652f7468656d652f +7468656d65312e786d6cec59cd8b1bc915bf07f23f347d97f5d5ad8fc1f2a24fcfda33b6b164873dd648a5eef2547789aad28cc56208de532e81c026e49085bd +ed21842cecc22eb9e48f31d8249b3f22afaa5bdd5552c99e191c3061463074977eefd5afde7bf5de53d5ddcf5e26d4bbc05c1096f6fcfa9d9aefe174ce16248d +7afeb3d9a4d2f13d2151ba4094a5b8e76fb0f03fbbf7eb5fdd454732c609f6403e1547a8e7c752ae8eaa5531876124eeb0154ee1bb25e30992f0caa3ea82a34b +d09bd06aa3566b55134452df4b51026a1f2f97648ebd9952e9dfdb2a1f53784da5500373caa74a35b6243476715e5708b11143cabd0b447b3eccb3609733fc52 +fa1e4542c2173dbfa6fffceabdbb5574940b517940d6909be8bf5c2e17589c37f49c3c3a2b260d823068f50bfd1a40e53e6edc1eb7c6ad429f06a0f91c569a71 +31758683ee6014e65803943d3a748fdaa366ddc21bfa9b7b9cfba1fa58780dcaf4077bf8c9640856b4f01a94e1c33d7c10b41bc3c0c26b50866fede1dbb5fe28 +685b780d8a2949cff7d0b5b0d51c6e575b40968c1e3be1dd3098b41bb9f21205d15044979a62c9527928d612f482f1090014902249524f6e567889e610c54344 +c91927de09896208bc154a9980e15aa336a935e1bffa04fa495b041d6164482b5ec044ec0d293e9e9873b2923dff0168f50dc8db9f7f7ef3fac737af7f7af3d5 +576f5eff3d9f5babb2e48e511a9972bf7cf787ff7cf35befdf3f7cfbcbd77fcca6dec50b13ffee6fbf7bf78f7fbe4f3dacb834c5db3f7dffeec7efdffef9f7ff +faebd70eed7d8ece4cf88c2458788ff0a5f79425b040077f7cc6af27318b113125fa6924508ad42c0efd63195be8471b44910337c0b61d9f7348352ee0fdf50b +8bf034e66b491c1a1fc689053c658c0e18775ae1a19acb30f36c9d46eec9f9dac43d45e8c235f710a59697c7eb15e458e252398cb145f30945a944114eb1f4d4 +77ec1c63c7eabe20c4b2eb29997326d8527a5f106f8088d324337266455329744c12f0cbc64510fc6dd9e6f4b93760d4b5ea11beb091b0371075909f616a99f1 +3e5a4b94b854ce50424d839f2019bb484e377c6ee2c64282a7234c99375e60215c328f39acd770fa4348336eb79fd24d6223b924e72e9d278831133962e7c318 +252b17764ad2d8c47e2ece214491f7844917fc94d93b44bd831f507ad0ddcf09b6dcfde16cf00c32ac49a90c10f5cd9a3b7c791f332b7ea71bba44d8956afa3c +b1526c9f1367740cd69115da271853748916187bcf3e773018b09565f392f48318b2ca317605d60364c7aa7a4fb1805e493537fb79f284082b64a7386207f89c +6e7612cf06a509e287343f02af9b361f43a94b5c01f098cecf4de023023d20c48bd3288f05e83082fba0d62731b20a987a17ee78dd70cb7f57d963b02f5f5834 +aeb02f41065f5b0612bb29f35edbcc10b52628036686a0cb70a55b10b1dc5f8aa8e2aac5d64eb9a5bd694b37407764353d09493fd801edf43ee1ffaef7810ee3 +ed5fbe71ec838fd3efb8155bc9ea9a9dcea16472bcd3df1cc2ed763543c617e4d36f6a46689d3ec15047f633d66d4f73dbd3f8fff73dcda1fd7cdbc91cea376e +3b191f3a8cdb4e263f5cf9389d4cd9bc405fa30e3cb2831e7dec931c3cf559124aa77243f189d0073f027ecf2c2630a8e4f489272e4e0157313caa32071358b8 +88232de371267f43643c8dd10a4e87eabe5212895c7524bc15137068a4879dba159eae9353b6c80e3beb7575b09955568164395e0b8b7138a89219bad52e0ff0 +0af59a6da40f5ab70494ec75481893d9249a0e12ededa032923ed605a33948e8957d14165d078b8e52bf75d51e0ba05678057e707bf033bde787018880109cc7 +4173be507eca5cbdf5ae76e6c7f4f421635a11000df636024a4f7715d783cb53abcb42ed0a9eb64818e16693d096d10d9e88e167701e9d6af42a34aeebeb6ee9 +528b9e32859e0f42aba4d1eebc8fc54d7d0d72bbb981a666a6a0a977d9f35bcd1042668e563d7f0987c6f098ac207684facd856804372f73c9b30d7f93ccb2e2 +428e90883383eba49365838448cc3d4a929eaf965fb881a63a87686ef50624844f965c17d2caa7460e9c6e3b192f97782e4db71b23cad2d92b64f82c5738bfd5 +e237072b49b606774fe3c5a57746d7fc2982100bdb7565c00511707750cfacb92070195624b232fe760a539e76cddb281d43d938a2ab18e515c54ce6195ca7f2 +828e7e2b6c60bce56b06831a26c90be159a40aac6954ab9a165523e370b0ea7e584859ce489a65cdb4b28aaa9aee2c66cdb02d033bb6bc599137586d4d0c39cd +acf059eade4db9dd6daedbe9138a2a01062fece7a8ba57280806b572328b9a62bc9f8655cece47eddab15de007a85da5481859bfb555bb63b7a24638a783c11b +557e90db8d5a185a6efb4a6d697d6b6e5e6cb3b317903c46d0e5aea914da9570b2cb11344453dd93646903b6c84b996f0d78f2d69cf4fc2f6b613f1836c261a5 +d609c795a019d42a9db0dfacf4c3b0591f87f5da68d078058545c6493dcc6eec2770814137f9bdbd1edfbbbb4fb6773477e62ca9327d375fd5c4f5dd7dbd71f8 +eede239074be6c3526dd6677d0aa749bfd4925180d3a95eeb035a88c5ac3f668321a869deee495ef5d6870d06f0e83d6b85369d587c34ad0aa29fa9d6ea51d34 +1afda0ddef8c83feabbc8d819567e923b7059857f3baf75f000000ffff0300504b0304140006000800000021000dd1909fb60000001b01000027000000746865 +6d652f7468656d652f5f72656c732f7468656d654d616e616765722e786d6c2e72656c73848f4d0ac2301484f78277086f6fd3ba109126dd88d0add40384e435 +0d363f2451eced0dae2c082e8761be9969bb979dc9136332de3168aa1a083ae995719ac16db8ec8e4052164e89d93b64b060828e6f37ed1567914b284d262452 +282e3198720e274a939cd08a54f980ae38a38f56e422a3a641c8bbd048f7757da0f19b017cc524bd62107bd5001996509affb3fd381a89672f1f165dfe514173 +d9850528a2c6cce0239baa4c04ca5bbabac4df000000ffff0300504b01022d0014000600080000002100e9de0fbfff0000001c02000013000000000000000000 +00000000000000005b436f6e74656e745f54797065735d2e786d6c504b01022d0014000600080000002100a5d6a7e7c0000000360100000b0000000000000000 +0000000000300100005f72656c732f2e72656c73504b01022d00140006000800000021006b799616830000008a0000001c000000000000000000000000001902 +00007468656d652f7468656d652f7468656d654d616e616765722e786d6c504b01022d0014000600080000002100ec7f4c3895070000c9200000160000000000 +0000000000000000d60200007468656d652f7468656d652f7468656d65312e786d6c504b01022d00140006000800000021000dd1909fb60000001b0100002700 +0000000000000000000000009f0a00007468656d652f7468656d652f5f72656c732f7468656d654d616e616765722e786d6c2e72656c73504b050600000000050005005d0100009a0b00000000} +{\*\colorschememapping 3c3f786d6c2076657273696f6e3d22312e302220656e636f64696e673d225554462d3822207374616e64616c6f6e653d22796573223f3e0d0a3c613a636c724d +617020786d6c6e733a613d22687474703a2f2f736368656d61732e6f70656e786d6c666f726d6174732e6f72672f64726177696e676d6c2f323030362f6d6169 +6e22206267313d226c743122207478313d22646b3122206267323d226c743222207478323d22646b322220616363656e74313d22616363656e74312220616363 +656e74323d22616363656e74322220616363656e74333d22616363656e74332220616363656e74343d22616363656e74342220616363656e74353d22616363656e74352220616363656e74363d22616363656e74362220686c696e6b3d22686c696e6b2220666f6c486c696e6b3d22666f6c486c696e6b222f3e} +{\*\latentstyles\lsdstimax374\lsdlockeddef0\lsdsemihiddendef0\lsdunhideuseddef0\lsdqformatdef0\lsdprioritydef99{\lsdlockedexcept \lsdqformat1 \lsdpriority0 \lsdlocked0 Normal;\lsdqformat1 \lsdpriority9 \lsdlocked0 heading 1; +\lsdsemihidden1 \lsdunhideused1 \lsdqformat1 \lsdpriority9 \lsdlocked0 heading 2;\lsdsemihidden1 \lsdunhideused1 \lsdqformat1 \lsdpriority9 \lsdlocked0 heading 3;\lsdsemihidden1 \lsdunhideused1 \lsdqformat1 \lsdpriority9 \lsdlocked0 heading 4; +\lsdsemihidden1 \lsdunhideused1 \lsdqformat1 \lsdpriority9 \lsdlocked0 heading 5;\lsdsemihidden1 \lsdunhideused1 \lsdqformat1 \lsdpriority9 \lsdlocked0 heading 6;\lsdsemihidden1 \lsdunhideused1 \lsdqformat1 \lsdpriority9 \lsdlocked0 heading 7; +\lsdsemihidden1 \lsdunhideused1 \lsdqformat1 \lsdpriority9 \lsdlocked0 heading 8;\lsdsemihidden1 \lsdunhideused1 \lsdqformat1 \lsdpriority9 \lsdlocked0 heading 9;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 index 1; +\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 index 2;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 index 3;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 index 4;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 index 5; +\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 index 6;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 index 7;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 index 8;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 index 9; +\lsdsemihidden1 \lsdunhideused1 \lsdpriority39 \lsdlocked0 toc 1;\lsdsemihidden1 \lsdunhideused1 \lsdpriority39 \lsdlocked0 toc 2;\lsdsemihidden1 \lsdunhideused1 \lsdpriority39 \lsdlocked0 toc 3; +\lsdsemihidden1 \lsdunhideused1 \lsdpriority39 \lsdlocked0 toc 4;\lsdsemihidden1 \lsdunhideused1 \lsdpriority39 \lsdlocked0 toc 5;\lsdsemihidden1 \lsdunhideused1 \lsdpriority39 \lsdlocked0 toc 6; +\lsdsemihidden1 \lsdunhideused1 \lsdpriority39 \lsdlocked0 toc 7;\lsdsemihidden1 \lsdunhideused1 \lsdpriority39 \lsdlocked0 toc 8;\lsdsemihidden1 \lsdunhideused1 \lsdpriority39 \lsdlocked0 toc 9;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 Normal Indent; +\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 footnote text;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 annotation text;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 header;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 footer; +\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 index heading;\lsdsemihidden1 \lsdunhideused1 \lsdqformat1 \lsdpriority35 \lsdlocked0 caption;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 table of figures; +\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 envelope address;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 envelope return;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 footnote reference;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 annotation reference; +\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 line number;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 page number;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 endnote reference;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 endnote text; +\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 table of authorities;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 macro;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 toa heading;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 List; +\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 List Bullet;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 List Number;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 List 2;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 List 3; +\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 List 4;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 List 5;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 List Bullet 2;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 List Bullet 3; +\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 List Bullet 4;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 List Bullet 5;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 List Number 2;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 List Number 3; +\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 List Number 4;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 List Number 5;\lsdqformat1 \lsdpriority10 \lsdlocked0 Title;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 Closing; +\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 Signature;\lsdsemihidden1 \lsdunhideused1 \lsdpriority1 \lsdlocked0 Default Paragraph Font;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 Body Text;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 Body Text Indent; +\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 List Continue;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 List Continue 2;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 List Continue 3;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 List Continue 4; +\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 List Continue 5;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 Message Header;\lsdqformat1 \lsdpriority11 \lsdlocked0 Subtitle;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 Salutation; +\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 Date;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 Body Text First Indent;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 Body Text First Indent 2;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 Note Heading; +\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 Body Text 2;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 Body Text 3;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 Body Text Indent 2;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 Body Text Indent 3; +\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 Block Text;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 Hyperlink;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 FollowedHyperlink;\lsdqformat1 \lsdpriority22 \lsdlocked0 Strong; +\lsdqformat1 \lsdpriority20 \lsdlocked0 Emphasis;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 Document Map;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 Plain Text;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 E-mail Signature; +\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 HTML Top of Form;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 HTML Bottom of Form;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 Normal (Web);\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 HTML Acronym; +\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 HTML Address;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 HTML Cite;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 HTML Code;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 HTML Definition; +\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 HTML Keyboard;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 HTML Preformatted;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 HTML Sample;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 HTML Typewriter; +\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 HTML Variable;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 annotation subject;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 No List;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 Outline List 1; +\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 Outline List 2;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 Outline List 3;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 Balloon Text;\lsdpriority39 \lsdlocked0 Table Grid; +\lsdsemihidden1 \lsdlocked0 Placeholder Text;\lsdqformat1 \lsdpriority1 \lsdlocked0 No Spacing;\lsdpriority60 \lsdlocked0 Light Shading;\lsdpriority61 \lsdlocked0 Light List;\lsdpriority62 \lsdlocked0 Light Grid; +\lsdpriority63 \lsdlocked0 Medium Shading 1;\lsdpriority64 \lsdlocked0 Medium Shading 2;\lsdpriority65 \lsdlocked0 Medium List 1;\lsdpriority66 \lsdlocked0 Medium List 2;\lsdpriority67 \lsdlocked0 Medium Grid 1;\lsdpriority68 \lsdlocked0 Medium Grid 2; +\lsdpriority69 \lsdlocked0 Medium Grid 3;\lsdpriority70 \lsdlocked0 Dark List;\lsdpriority71 \lsdlocked0 Colorful Shading;\lsdpriority72 \lsdlocked0 Colorful List;\lsdpriority73 \lsdlocked0 Colorful Grid;\lsdpriority60 \lsdlocked0 Light Shading Accent 1; +\lsdpriority61 \lsdlocked0 Light List Accent 1;\lsdpriority62 \lsdlocked0 Light Grid Accent 1;\lsdpriority63 \lsdlocked0 Medium Shading 1 Accent 1;\lsdpriority64 \lsdlocked0 Medium Shading 2 Accent 1;\lsdpriority65 \lsdlocked0 Medium List 1 Accent 1; +\lsdsemihidden1 \lsdlocked0 Revision;\lsdqformat1 \lsdpriority34 \lsdlocked0 List Paragraph;\lsdqformat1 \lsdpriority29 \lsdlocked0 Quote;\lsdqformat1 \lsdpriority30 \lsdlocked0 Intense Quote;\lsdpriority66 \lsdlocked0 Medium List 2 Accent 1; +\lsdpriority67 \lsdlocked0 Medium Grid 1 Accent 1;\lsdpriority68 \lsdlocked0 Medium Grid 2 Accent 1;\lsdpriority69 \lsdlocked0 Medium Grid 3 Accent 1;\lsdpriority70 \lsdlocked0 Dark List Accent 1;\lsdpriority71 \lsdlocked0 Colorful Shading Accent 1; +\lsdpriority72 \lsdlocked0 Colorful List Accent 1;\lsdpriority73 \lsdlocked0 Colorful Grid Accent 1;\lsdpriority60 \lsdlocked0 Light Shading Accent 2;\lsdpriority61 \lsdlocked0 Light List Accent 2;\lsdpriority62 \lsdlocked0 Light Grid Accent 2; +\lsdpriority63 \lsdlocked0 Medium Shading 1 Accent 2;\lsdpriority64 \lsdlocked0 Medium Shading 2 Accent 2;\lsdpriority65 \lsdlocked0 Medium List 1 Accent 2;\lsdpriority66 \lsdlocked0 Medium List 2 Accent 2; +\lsdpriority67 \lsdlocked0 Medium Grid 1 Accent 2;\lsdpriority68 \lsdlocked0 Medium Grid 2 Accent 2;\lsdpriority69 \lsdlocked0 Medium Grid 3 Accent 2;\lsdpriority70 \lsdlocked0 Dark List Accent 2;\lsdpriority71 \lsdlocked0 Colorful Shading Accent 2; +\lsdpriority72 \lsdlocked0 Colorful List Accent 2;\lsdpriority73 \lsdlocked0 Colorful Grid Accent 2;\lsdpriority60 \lsdlocked0 Light Shading Accent 3;\lsdpriority61 \lsdlocked0 Light List Accent 3;\lsdpriority62 \lsdlocked0 Light Grid Accent 3; +\lsdpriority63 \lsdlocked0 Medium Shading 1 Accent 3;\lsdpriority64 \lsdlocked0 Medium Shading 2 Accent 3;\lsdpriority65 \lsdlocked0 Medium List 1 Accent 3;\lsdpriority66 \lsdlocked0 Medium List 2 Accent 3; +\lsdpriority67 \lsdlocked0 Medium Grid 1 Accent 3;\lsdpriority68 \lsdlocked0 Medium Grid 2 Accent 3;\lsdpriority69 \lsdlocked0 Medium Grid 3 Accent 3;\lsdpriority70 \lsdlocked0 Dark List Accent 3;\lsdpriority71 \lsdlocked0 Colorful Shading Accent 3; +\lsdpriority72 \lsdlocked0 Colorful List Accent 3;\lsdpriority73 \lsdlocked0 Colorful Grid Accent 3;\lsdpriority60 \lsdlocked0 Light Shading Accent 4;\lsdpriority61 \lsdlocked0 Light List Accent 4;\lsdpriority62 \lsdlocked0 Light Grid Accent 4; +\lsdpriority63 \lsdlocked0 Medium Shading 1 Accent 4;\lsdpriority64 \lsdlocked0 Medium Shading 2 Accent 4;\lsdpriority65 \lsdlocked0 Medium List 1 Accent 4;\lsdpriority66 \lsdlocked0 Medium List 2 Accent 4; +\lsdpriority67 \lsdlocked0 Medium Grid 1 Accent 4;\lsdpriority68 \lsdlocked0 Medium Grid 2 Accent 4;\lsdpriority69 \lsdlocked0 Medium Grid 3 Accent 4;\lsdpriority70 \lsdlocked0 Dark List Accent 4;\lsdpriority71 \lsdlocked0 Colorful Shading Accent 4; +\lsdpriority72 \lsdlocked0 Colorful List Accent 4;\lsdpriority73 \lsdlocked0 Colorful Grid Accent 4;\lsdpriority60 \lsdlocked0 Light Shading Accent 5;\lsdpriority61 \lsdlocked0 Light List Accent 5;\lsdpriority62 \lsdlocked0 Light Grid Accent 5; +\lsdpriority63 \lsdlocked0 Medium Shading 1 Accent 5;\lsdpriority64 \lsdlocked0 Medium Shading 2 Accent 5;\lsdpriority65 \lsdlocked0 Medium List 1 Accent 5;\lsdpriority66 \lsdlocked0 Medium List 2 Accent 5; +\lsdpriority67 \lsdlocked0 Medium Grid 1 Accent 5;\lsdpriority68 \lsdlocked0 Medium Grid 2 Accent 5;\lsdpriority69 \lsdlocked0 Medium Grid 3 Accent 5;\lsdpriority70 \lsdlocked0 Dark List Accent 5;\lsdpriority71 \lsdlocked0 Colorful Shading Accent 5; +\lsdpriority72 \lsdlocked0 Colorful List Accent 5;\lsdpriority73 \lsdlocked0 Colorful Grid Accent 5;\lsdpriority60 \lsdlocked0 Light Shading Accent 6;\lsdpriority61 \lsdlocked0 Light List Accent 6;\lsdpriority62 \lsdlocked0 Light Grid Accent 6; +\lsdpriority63 \lsdlocked0 Medium Shading 1 Accent 6;\lsdpriority64 \lsdlocked0 Medium Shading 2 Accent 6;\lsdpriority65 \lsdlocked0 Medium List 1 Accent 6;\lsdpriority66 \lsdlocked0 Medium List 2 Accent 6; +\lsdpriority67 \lsdlocked0 Medium Grid 1 Accent 6;\lsdpriority68 \lsdlocked0 Medium Grid 2 Accent 6;\lsdpriority69 \lsdlocked0 Medium Grid 3 Accent 6;\lsdpriority70 \lsdlocked0 Dark List Accent 6;\lsdpriority71 \lsdlocked0 Colorful Shading Accent 6; +\lsdpriority72 \lsdlocked0 Colorful List Accent 6;\lsdpriority73 \lsdlocked0 Colorful Grid Accent 6;\lsdqformat1 \lsdpriority19 \lsdlocked0 Subtle Emphasis;\lsdqformat1 \lsdpriority21 \lsdlocked0 Intense Emphasis; +\lsdqformat1 \lsdpriority31 \lsdlocked0 Subtle Reference;\lsdqformat1 \lsdpriority32 \lsdlocked0 Intense Reference;\lsdqformat1 \lsdpriority33 \lsdlocked0 Book Title;\lsdsemihidden1 \lsdunhideused1 \lsdpriority37 \lsdlocked0 Bibliography; +\lsdsemihidden1 \lsdunhideused1 \lsdqformat1 \lsdpriority39 \lsdlocked0 TOC Heading;\lsdpriority41 \lsdlocked0 Plain Table 1;\lsdpriority42 \lsdlocked0 Plain Table 2;\lsdpriority43 \lsdlocked0 Plain Table 3;\lsdpriority44 \lsdlocked0 Plain Table 4; +\lsdpriority45 \lsdlocked0 Plain Table 5;\lsdpriority40 \lsdlocked0 Grid Table Light;\lsdpriority46 \lsdlocked0 Grid Table 1 Light;\lsdpriority47 \lsdlocked0 Grid Table 2;\lsdpriority48 \lsdlocked0 Grid Table 3;\lsdpriority49 \lsdlocked0 Grid Table 4; +\lsdpriority50 \lsdlocked0 Grid Table 5 Dark;\lsdpriority51 \lsdlocked0 Grid Table 6 Colorful;\lsdpriority52 \lsdlocked0 Grid Table 7 Colorful;\lsdpriority46 \lsdlocked0 Grid Table 1 Light Accent 1;\lsdpriority47 \lsdlocked0 Grid Table 2 Accent 1; +\lsdpriority48 \lsdlocked0 Grid Table 3 Accent 1;\lsdpriority49 \lsdlocked0 Grid Table 4 Accent 1;\lsdpriority50 \lsdlocked0 Grid Table 5 Dark Accent 1;\lsdpriority51 \lsdlocked0 Grid Table 6 Colorful Accent 1; +\lsdpriority52 \lsdlocked0 Grid Table 7 Colorful Accent 1;\lsdpriority46 \lsdlocked0 Grid Table 1 Light Accent 2;\lsdpriority47 \lsdlocked0 Grid Table 2 Accent 2;\lsdpriority48 \lsdlocked0 Grid Table 3 Accent 2; +\lsdpriority49 \lsdlocked0 Grid Table 4 Accent 2;\lsdpriority50 \lsdlocked0 Grid Table 5 Dark Accent 2;\lsdpriority51 \lsdlocked0 Grid Table 6 Colorful Accent 2;\lsdpriority52 \lsdlocked0 Grid Table 7 Colorful Accent 2; +\lsdpriority46 \lsdlocked0 Grid Table 1 Light Accent 3;\lsdpriority47 \lsdlocked0 Grid Table 2 Accent 3;\lsdpriority48 \lsdlocked0 Grid Table 3 Accent 3;\lsdpriority49 \lsdlocked0 Grid Table 4 Accent 3; +\lsdpriority50 \lsdlocked0 Grid Table 5 Dark Accent 3;\lsdpriority51 \lsdlocked0 Grid Table 6 Colorful Accent 3;\lsdpriority52 \lsdlocked0 Grid Table 7 Colorful Accent 3;\lsdpriority46 \lsdlocked0 Grid Table 1 Light Accent 4; +\lsdpriority47 \lsdlocked0 Grid Table 2 Accent 4;\lsdpriority48 \lsdlocked0 Grid Table 3 Accent 4;\lsdpriority49 \lsdlocked0 Grid Table 4 Accent 4;\lsdpriority50 \lsdlocked0 Grid Table 5 Dark Accent 4; +\lsdpriority51 \lsdlocked0 Grid Table 6 Colorful Accent 4;\lsdpriority52 \lsdlocked0 Grid Table 7 Colorful Accent 4;\lsdpriority46 \lsdlocked0 Grid Table 1 Light Accent 5;\lsdpriority47 \lsdlocked0 Grid Table 2 Accent 5; +\lsdpriority48 \lsdlocked0 Grid Table 3 Accent 5;\lsdpriority49 \lsdlocked0 Grid Table 4 Accent 5;\lsdpriority50 \lsdlocked0 Grid Table 5 Dark Accent 5;\lsdpriority51 \lsdlocked0 Grid Table 6 Colorful Accent 5; +\lsdpriority52 \lsdlocked0 Grid Table 7 Colorful Accent 5;\lsdpriority46 \lsdlocked0 Grid Table 1 Light Accent 6;\lsdpriority47 \lsdlocked0 Grid Table 2 Accent 6;\lsdpriority48 \lsdlocked0 Grid Table 3 Accent 6; +\lsdpriority49 \lsdlocked0 Grid Table 4 Accent 6;\lsdpriority50 \lsdlocked0 Grid Table 5 Dark Accent 6;\lsdpriority51 \lsdlocked0 Grid Table 6 Colorful Accent 6;\lsdpriority52 \lsdlocked0 Grid Table 7 Colorful Accent 6; +\lsdpriority46 \lsdlocked0 List Table 1 Light;\lsdpriority47 \lsdlocked0 List Table 2;\lsdpriority48 \lsdlocked0 List Table 3;\lsdpriority49 \lsdlocked0 List Table 4;\lsdpriority50 \lsdlocked0 List Table 5 Dark; +\lsdpriority51 \lsdlocked0 List Table 6 Colorful;\lsdpriority52 \lsdlocked0 List Table 7 Colorful;\lsdpriority46 \lsdlocked0 List Table 1 Light Accent 1;\lsdpriority47 \lsdlocked0 List Table 2 Accent 1;\lsdpriority48 \lsdlocked0 List Table 3 Accent 1; +\lsdpriority49 \lsdlocked0 List Table 4 Accent 1;\lsdpriority50 \lsdlocked0 List Table 5 Dark Accent 1;\lsdpriority51 \lsdlocked0 List Table 6 Colorful Accent 1;\lsdpriority52 \lsdlocked0 List Table 7 Colorful Accent 1; +\lsdpriority46 \lsdlocked0 List Table 1 Light Accent 2;\lsdpriority47 \lsdlocked0 List Table 2 Accent 2;\lsdpriority48 \lsdlocked0 List Table 3 Accent 2;\lsdpriority49 \lsdlocked0 List Table 4 Accent 2; +\lsdpriority50 \lsdlocked0 List Table 5 Dark Accent 2;\lsdpriority51 \lsdlocked0 List Table 6 Colorful Accent 2;\lsdpriority52 \lsdlocked0 List Table 7 Colorful Accent 2;\lsdpriority46 \lsdlocked0 List Table 1 Light Accent 3; +\lsdpriority47 \lsdlocked0 List Table 2 Accent 3;\lsdpriority48 \lsdlocked0 List Table 3 Accent 3;\lsdpriority49 \lsdlocked0 List Table 4 Accent 3;\lsdpriority50 \lsdlocked0 List Table 5 Dark Accent 3; +\lsdpriority51 \lsdlocked0 List Table 6 Colorful Accent 3;\lsdpriority52 \lsdlocked0 List Table 7 Colorful Accent 3;\lsdpriority46 \lsdlocked0 List Table 1 Light Accent 4;\lsdpriority47 \lsdlocked0 List Table 2 Accent 4; +\lsdpriority48 \lsdlocked0 List Table 3 Accent 4;\lsdpriority49 \lsdlocked0 List Table 4 Accent 4;\lsdpriority50 \lsdlocked0 List Table 5 Dark Accent 4;\lsdpriority51 \lsdlocked0 List Table 6 Colorful Accent 4; +\lsdpriority52 \lsdlocked0 List Table 7 Colorful Accent 4;\lsdpriority46 \lsdlocked0 List Table 1 Light Accent 5;\lsdpriority47 \lsdlocked0 List Table 2 Accent 5;\lsdpriority48 \lsdlocked0 List Table 3 Accent 5; +\lsdpriority49 \lsdlocked0 List Table 4 Accent 5;\lsdpriority50 \lsdlocked0 List Table 5 Dark Accent 5;\lsdpriority51 \lsdlocked0 List Table 6 Colorful Accent 5;\lsdpriority52 \lsdlocked0 List Table 7 Colorful Accent 5; +\lsdpriority46 \lsdlocked0 List Table 1 Light Accent 6;\lsdpriority47 \lsdlocked0 List Table 2 Accent 6;\lsdpriority48 \lsdlocked0 List Table 3 Accent 6;\lsdpriority49 \lsdlocked0 List Table 4 Accent 6; +\lsdpriority50 \lsdlocked0 List Table 5 Dark Accent 6;\lsdpriority51 \lsdlocked0 List Table 6 Colorful Accent 6;\lsdpriority52 \lsdlocked0 List Table 7 Colorful Accent 6;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 Mention; +\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 Smart Hyperlink;\lsdsemihidden1 \lsdunhideused1 \lsdlocked0 Hashtag;}}{\*\datastore 0105000002000000180000004d73786d6c322e534158584d4c5265616465722e362e3000000000000000000000060000 +d0cf11e0a1b11ae1000000000000000000000000000000003e000300feff090006000000000000000000000001000000010000000000000000100000feffffff00000000feffffff0000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +fffffffffffffffffdfffffffeffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +ffffffffffffffffffffffffffffffff52006f006f007400200045006e00740072007900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016000500ffffffffffffffffffffffff0c6ad98892f1d411a65f0040963251e50000000000000000000000005063 +a2efa482d201feffffff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffff00000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000 +000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffff000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000105000000000000}} \ No newline at end of file diff --git a/tests/tas-integration/src/test/resources/shared-resources/testdata/testUploadFile.txt b/tests/tas-integration/src/test/resources/shared-resources/testdata/testUploadFile.txt new file mode 100644 index 0000000000..de93bb26e9 --- /dev/null +++ b/tests/tas-integration/src/test/resources/shared-resources/testdata/testUploadFile.txt @@ -0,0 +1 @@ +test upload file. \ No newline at end of file diff --git a/tests/tas-integration/src/test/resources/shared-resources/testdata/testUserShoudDeleteFiles.txt b/tests/tas-integration/src/test/resources/shared-resources/testdata/testUserShoudDeleteFiles.txt new file mode 100644 index 0000000000..30d74d2584 --- /dev/null +++ b/tests/tas-integration/src/test/resources/shared-resources/testdata/testUserShoudDeleteFiles.txt @@ -0,0 +1 @@ +test \ No newline at end of file diff --git a/tests/tas-integration/src/test/resources/shared-resources/testdata/userCSV.csv b/tests/tas-integration/src/test/resources/shared-resources/testdata/userCSV.csv new file mode 100644 index 0000000000..3ceafc6cef --- /dev/null +++ b/tests/tas-integration/src/test/resources/shared-resources/testdata/userCSV.csv @@ -0,0 +1,2 @@ +MNT-171990-user-with-no-password,user1,user1,user1171990@alfresco.com,, +MNT-171990-user-with-password,user2,user2,user2171990@alfresco.com,,user2 diff --git a/tests/tas-restapi/pom.xml b/tests/tas-restapi/pom.xml new file mode 100644 index 0000000000..afa94b2c2a --- /dev/null +++ b/tests/tas-restapi/pom.xml @@ -0,0 +1,81 @@ + + + 4.0.0 + org.alfresco.tas + content-repository-community-restapi-test + content-repository-community-restapi-test + 6.3.0-SNAPSHOT + jar + + + org.alfresco + content-repository-community-tas-tests-parent + 6.3.0-SNAPSHOT + ../pom.xml + + + + + Paul Brodner + + Test Automation Architect + + + + + + ${project.basedir}/src/test/resources/restapi-suite.xml + + + + + org.alfresco.tas + restapi + test + + + io.rest-assured + rest-assured + test + + + org.glassfish + javax.json + test + + + org.springframework + spring-test + test + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + ${suiteXmlFile} + + + --illegal-access=warn + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + test-jar + + + + + + + diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/FunctionalCasesTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/FunctionalCasesTests.java new file mode 100644 index 0000000000..7676dac8b6 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/FunctionalCasesTests.java @@ -0,0 +1,701 @@ +package org.alfresco.rest; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.dataprep.SiteService.Visibility; +import org.alfresco.rest.model.RestActivityModelsCollection; +import org.alfresco.rest.model.RestCommentModel; +import org.alfresco.rest.model.RestCommentModelsCollection; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestFavoriteSiteModel; +import org.alfresco.rest.model.RestPersonFavoritesModelsCollection; +import org.alfresco.rest.model.RestRatingModel; +import org.alfresco.rest.model.RestSiteMemberModel; +import org.alfresco.rest.model.RestSiteMembershipRequestModelsCollection; +import org.alfresco.rest.model.RestTagModel; +import org.alfresco.rest.model.RestTaskModel; +import org.alfresco.utility.constants.ActivityType; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class FunctionalCasesTests extends RestTest +{ + private UserModel adminUser, manager; + private SiteModel publicSite, moderatedSite, privateSite; + private RestSiteMemberModel updatedMember; + private RestSiteMembershipRequestModelsCollection returnedCollection; + private RestFavoriteSiteModel restFavoriteSiteModel; + private RestActivityModelsCollection activities; + private FileModel file; + private RestActivityModelsCollection restActivityModelsCollection; + + private FileModel fileInSite; + private RestCommentModel commentModel; + + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + manager = dataUser.createRandomTestUser(); + publicSite = dataSite.usingUser(adminUser).createPublicRandomSite(); + dataUser.addUserToSite(manager, publicSite, UserRole.SiteManager); + moderatedSite = dataSite.usingUser(adminUser).createModeratedRandomSite(); + privateSite = dataSite.usingUser(adminUser).createPrivateRandomSite(); + } + + /** + * Scenario: + * 1. Add a site member as Manager + * 2. Update it's role to Collaborator + * 3. Update it's role to Contributor + * 4. Update it's role to Consumer + */ + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that manager is able to update manager with different roles and gets status code CREATED (201)") + public void managerIsAbleToUpdateManagerWithDifferentRoles() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteManager); + restClient.authenticateUser(adminUser).withCoreAPI().usingSite(publicSite).addPerson(testUser) + .assertThat().field("id").is(testUser.getUsername()) + .and().field("role").is(testUser.getUserRole()); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + testUser.setUserRole(UserRole.SiteCollaborator); + updatedMember = restClient.withCoreAPI() + .usingSite(publicSite).updateSiteMember(testUser); + restClient.assertStatusCodeIs(HttpStatus.OK); + updatedMember.assertThat().field("id").is(testUser.getUsername()).and().field("role").is(testUser.getUserRole()); + + testUser.setUserRole(UserRole.SiteContributor); + updatedMember = restClient.withCoreAPI() + .usingSite(publicSite).updateSiteMember(testUser); + restClient.assertStatusCodeIs(HttpStatus.OK); + updatedMember.assertThat().field("id").is(testUser.getUsername()).and().field("role").is(testUser.getUserRole()); + + testUser.setUserRole(UserRole.SiteConsumer); + updatedMember = restClient.withCoreAPI() + .usingSite(publicSite).updateSiteMember(testUser); + restClient.assertStatusCodeIs(HttpStatus.OK); + updatedMember.assertThat().field("id").is(testUser.getUsername()).and().field("role").is(testUser.getUserRole()); + } + + /** + * Scenario: + * 1. Add a site member as Consumer + * 2. Update it's role to Contributor + * 3. Update it's role to Collaborator + * 4. Update it's role to Manager + */ + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that manager is able to update consumer with different roles and gets status code CREATED (201)") + public void managerIsAbleToUpdateConsumerWithDifferentRoles() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteConsumer); + restClient.authenticateUser(adminUser).withCoreAPI().usingSite(publicSite).addPerson(testUser) + .assertThat().field("id").is(testUser.getUsername()) + .and().field("role").is(testUser.getUserRole()); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + testUser.setUserRole(UserRole.SiteContributor); + updatedMember = restClient.withCoreAPI() + .usingSite(publicSite).updateSiteMember(testUser); + restClient.assertStatusCodeIs(HttpStatus.OK); + updatedMember.assertThat().field("id").is(testUser.getUsername()).and().field("role").is(testUser.getUserRole()); + + testUser.setUserRole(UserRole.SiteCollaborator); + updatedMember = restClient.withCoreAPI() + .usingSite(publicSite).updateSiteMember(testUser); + restClient.assertStatusCodeIs(HttpStatus.OK); + updatedMember.assertThat().field("id").is(testUser.getUsername()).and().field("role").is(testUser.getUserRole()); + + testUser.setUserRole(UserRole.SiteManager); + updatedMember = restClient.withCoreAPI() + .usingSite(publicSite).updateSiteMember(testUser); + restClient.assertStatusCodeIs(HttpStatus.OK); + updatedMember.assertThat().field("id").is(testUser.getUsername()).and().field("role").is(testUser.getUserRole()); + } + + /** + * Scenario: + * 1. Create site membership request + * 2. Approve site membership request + * 3. Add site to Favorites + * 4. Delete site from Favorites + */ + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, + executionType = ExecutionType.REGRESSION, description = "Approve request, add site to favorites, then delete it from favorites") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void approveRequestAddAndDeleteSiteFromFavorites() throws Exception + { + UserModel newMember = dataUser.createRandomTestUser(); + + restClient.authenticateUser(newMember).withCoreAPI().usingMe().addSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + RestTaskModel taskModel = restClient.authenticateUser(newMember).withWorkflowAPI().getTasks().getTaskModelByDescription(moderatedSite); + workflow.approveSiteMembershipRequest(adminUser.getUsername(), adminUser.getPassword(), taskModel.getId(), true, "Approve"); + returnedCollection = restClient.authenticateUser(newMember).withCoreAPI().usingMe().getSiteMembershipRequests(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedCollection.assertThat().entriesListDoesNotContain("id", moderatedSite.getId()); + + restFavoriteSiteModel = restClient.authenticateUser(newMember).withCoreAPI().usingUser(newMember).addFavoriteSite(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restFavoriteSiteModel.assertThat().field("id").is(moderatedSite.getId()); + + restClient.authenticateUser(newMember).withCoreAPI().usingAuthUser().removeFavoriteSite(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + } + + /** + * Scenario: + * 1. Create site membership request + * 2. Reject site membership request + * 3. Add moderated site to Favorites + * 4. Create site membership request again + * 5. Approve site membership request + * 6. Delete member from site + */ + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, + executionType = ExecutionType.REGRESSION, description = "Reject request, add moderated site to favorites, create request again and approve it") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void rejectRequestAddModeratedSiteToFavorites() throws Exception + { + UserModel newMember = dataUser.createRandomTestUser(); + + restClient.authenticateUser(newMember).withCoreAPI().usingMe().addSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + RestTaskModel taskModel = restClient.authenticateUser(newMember).withWorkflowAPI().getTasks().getTaskModelByDescription(moderatedSite); + workflow.approveSiteMembershipRequest(adminUser.getUsername(), adminUser.getPassword(), taskModel.getId(), false, "Rejected"); + returnedCollection = restClient.authenticateUser(newMember).withCoreAPI().usingMe().getSiteMembershipRequests(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedCollection.assertThat().entriesListDoesNotContain("id", moderatedSite.getId()); + + restFavoriteSiteModel = restClient.authenticateUser(newMember).withCoreAPI().usingUser(newMember).addFavoriteSite(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restFavoriteSiteModel.assertThat().field("id").is(moderatedSite.getId()); + + restClient.authenticateUser(newMember).withCoreAPI().usingMe().addSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + taskModel = restClient.authenticateUser(newMember).withWorkflowAPI().getTasks().getTaskModelByDescription(moderatedSite); + workflow.approveSiteMembershipRequest(adminUser.getUsername(), adminUser.getPassword(), taskModel.getId(), true, "Accept"); + + restClient.authenticateUser(adminUser).withCoreAPI().usingUser(newMember).deleteSiteMember(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + restClient.withCoreAPI().usingSite(moderatedSite).getSiteMembers().assertThat().entriesListDoesNotContain("id", newMember.getUsername()); + } + + /** + * Scenario: + * 1. Add file + * 2. Check file is included in person activities list + */ + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Add a file and check that activity is included in person activities") + public void addFileThenGetPersonActivities() throws Exception + { + file = dataContent.usingUser(manager).usingSite(publicSite).createContent(DocumentType.TEXT_PLAIN); + activities = restClient.authenticateUser(manager).withCoreAPI().usingAuthUser().getPersonActivitiesUntilEntriesCountIs(2); + activities.assertThat().entriesListIsNotEmpty() + .and().entriesListContains("siteId", publicSite.getId()) + .and().entriesListContains("activityType", "org.alfresco.documentlibrary.file-added") + .and().entriesListContains("activitySummary.objectId", file.getNodeRefWithoutVersion()); + } + + /** + * Scenario: + * 1. Add a comment to a file + * 2. Check that comment is included in person activities list + */ + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Add a comment to a file and check that activity is included in person activities") + public void addCommentThenGetPersonActivities() throws Exception + { + file = dataContent.usingUser(manager).usingSite(publicSite).createContent(DocumentType.TEXT_PLAIN); + restClient.authenticateUser(manager).withCoreAPI().usingResource(file).addComment("new comment"); + activities = restClient.authenticateUser(manager).withCoreAPI().usingAuthUser().getPersonActivitiesUntilEntriesCountIs(3); + activities.assertThat().entriesListIsNotEmpty() + .and().entriesListContains("siteId", publicSite.getId()) + .and().entriesListContains("activityType", "org.alfresco.comments.comment-created") + .and().entriesListContains("activitySummary.objectId", file.getNodeRefWithoutVersion()); + } + + /** + * Scenario: + * 1. Add file then delete it + * 2. Check action is included in person activities list + */ + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Add a file, delete it and check that activity is included in person activities") + public void addFileDeleteItThenGetPersonActivities() throws Exception + { + file = dataContent.usingUser(manager).usingSite(publicSite).createContent(DocumentType.TEXT_PLAIN); + dataContent.usingUser(manager).usingResource(file).deleteContent(); + activities = restClient.authenticateUser(manager).withCoreAPI().usingAuthUser().getPersonActivitiesUntilEntriesCountIs(2); + activities.assertThat().entriesListIsNotEmpty() + .and().entriesListContains("siteId", publicSite.getId()) + .and().entriesListContains("activityType", "org.alfresco.documentlibrary.file-deleted") + .and().entriesListContains("activitySummary.objectId", file.getNodeRefWithoutVersion()); + } + + /** + * 1. Post one comment + * 2. Get comment details + * 3. Update comment + * 4. Get again comment details + * 5. Delete comment + */ + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, + executionType = ExecutionType.REGRESSION, + description = "Add comment to a file, then get comment details. Update it and check that get comment returns updated details. Delete comment then check that file has no comments.") + public void addUpdateDeleteCommentThenGetCommentDetails() throws Exception + { + file = dataContent.usingUser(manager).usingSite(publicSite).createContent(DocumentType.TEXT_PLAIN); + RestCommentModel newComment = restClient.authenticateUser(manager).withCoreAPI().usingResource(file).addComment("new comment"); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + RestCommentModelsCollection fileComments = restClient.withCoreAPI().usingResource(file).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + fileComments.assertThat().entriesListContains("content", newComment.getContent()); + + RestCommentModel updatedComment = restClient.withCoreAPI().usingResource(file).updateComment(newComment, "updated comment"); + restClient.assertStatusCodeIs(HttpStatus.OK); + + fileComments = restClient.withCoreAPI().usingResource(file).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + fileComments.assertThat().entriesListContains("content", updatedComment.getContent()).assertThat().entriesListDoesNotContain("content", newComment.getContent()); + + restClient.withCoreAPI().usingResource(file).deleteComment(updatedComment); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + fileComments = restClient.withCoreAPI().usingResource(file).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + fileComments.assertThat().entriesListIsEmpty(); + } + + /** + * 1. Post one comment + * 2. Delete comment + * 3. Post the same comment again + */ + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, + executionType = ExecutionType.REGRESSION, + description = "Add a comment to a file, delete it, then added the same comment again.") + public void checkThatADeletedCommentCanBePostedAgain() throws Exception + { + file = dataContent.usingUser(manager).usingSite(publicSite).createContent(DocumentType.TEXT_PLAIN); + RestCommentModel newComment = restClient.authenticateUser(manager).withCoreAPI().usingResource(file).addComment("new comment"); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + RestCommentModelsCollection fileComments = restClient.withCoreAPI().usingResource(file).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + fileComments.assertThat().entriesListContains("content", newComment.getContent()); + + restClient.withCoreAPI().usingResource(file).deleteComment(newComment); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + fileComments = restClient.withCoreAPI().usingResource(file).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + fileComments.assertThat().entriesListIsEmpty(); + + restClient.authenticateUser(manager).withCoreAPI().usingResource(file).addComment("new comment"); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + fileComments = restClient.withCoreAPI().usingResource(file).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + fileComments.assertThat().entriesListContains("content", newComment.getContent()); + } + + /** + * Scenario: + * 1. join an user to a site + * 2. Check action is included in person activities list + * + * @throws Exception + */ + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Create an user, join the user to a site and check that activity is included in person activities") + public void joinUserToSiteThenGetPersonActivities() throws Exception + { + UserModel userJoinSite = dataUser.createRandomTestUser(); + + restClient.authenticateUser(userJoinSite).withCoreAPI().usingMe().addSiteMembershipRequest(publicSite); + activities = restClient.withCoreAPI().usingAuthUser().getPersonActivitiesUntilEntriesCountIs(2); + activities.assertThat().entriesListIsNotEmpty().and() + .entriesListContains("siteId", publicSite.getId()).and() + .entriesListContains("activityType", "org.alfresco.site.user-joined").and() + .entriesListContains("activitySummary.memberPersonId", userJoinSite.getUsername()); + } + + /** + * Scenario: + * 1. Add user to private site + * 2. Remove user from private site + * 3. User creates membership request to the same private site + */ + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, + executionType = ExecutionType.REGRESSION, description = "Verify membership request by user after it was removed from site gets status code 404") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void userCanNotCreateMembershipRequestIfItWasRemovedFromPrivateSite() throws Exception + { + UserModel newMember = dataUser.createRandomTestUser(); + newMember.setUserRole(UserRole.SiteCollaborator); + + restClient.authenticateUser(adminUser).withCoreAPI().usingSite(privateSite).addPerson(newMember) + .assertThat().field("id").is(newMember.getUsername()); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.authenticateUser(adminUser).withCoreAPI().usingUser(newMember).deleteSiteMember(privateSite); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + restClient.authenticateUser(newMember).withCoreAPI().usingMe().addSiteMembershipRequest(privateSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, newMember.getUsername(), privateSite.getTitle())); + } + + /** + * Scenario: + * 1. User creates membership request to moderated site + * 2. Accept membership request + * 3. Remove user from moderated site + * 4. Add user on moderated site + */ + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, + executionType = ExecutionType.REGRESSION, description = "Verify user can be added back after if was removed from site") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void userCanBeAddedAfterItWasRemovedFromSite() throws Exception + { + UserModel newMember = dataUser.createRandomTestUser(); + newMember.setUserRole(UserRole.SiteCollaborator); + + restClient.authenticateUser(newMember).withCoreAPI().usingMe().addSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + RestTaskModel taskModel = restClient.authenticateUser(newMember).withWorkflowAPI().getTasks().getTaskModelByDescription(moderatedSite); + workflow.approveSiteMembershipRequest(adminUser.getUsername(), adminUser.getPassword(), taskModel.getId(), true, "Accept"); + + restClient.authenticateUser(adminUser).withCoreAPI().usingUser(newMember).deleteSiteMember(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withCoreAPI().usingSite(moderatedSite).getSiteMembers().assertThat().entriesListDoesNotContain("id", newMember.getUsername()); + + restClient.authenticateUser(adminUser).withCoreAPI().usingSite(moderatedSite).addPerson(newMember) + .assertThat().field("id").is(newMember.getUsername()); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.withCoreAPI().usingSite(moderatedSite).getSiteMembers().assertThat().entriesListContains("id", newMember.getUsername()); + } + + /** + * Scenario: + * 1. Create document in site + * 2. Add comment + * 3. Delete document + * 4. Get comments and check if the above comment was deleted + */ + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, + executionType = ExecutionType.REGRESSION, description = "Check that a comment of a document was also removed after deleting the document") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void checkTheCommentOfADocumentThatWasDeletedDoesNotExist() throws Exception + { + file = dataContent.usingSite(publicSite).usingUser(adminUser).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + String newContent = "This is a new comment added by " + adminUser.getUsername(); + + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(file).addComment(newContent) + .assertThat().field("content").isNotEmpty() + .and().field("content").is(newContent); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + dataContent.usingUser(adminUser).usingResource(file).deleteContent(); + + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(file).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary((String.format(RestErrorModel.ENTITY_WAS_NOT_FOUND, file.getNodeRefWithoutVersion()))); + } + + /** + * Scenario: + * 1. Add user to private site + * 2. Add comment to a document of private site + * 3. Remove user from site + * 4. Get comments and check if the above comment was deleted + */ + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, + executionType = ExecutionType.REGRESSION, description = "Check that a comment of a document from a private site is not deleted after user is removed") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void checkThatCommentIsNotDeletedWhenPrivateSiteMemberIsRemoved() throws Exception + { + UserModel newUser = dataUser.createRandomTestUser(); + newUser.setUserRole(UserRole.SiteManager); + restClient.authenticateUser(adminUser).withCoreAPI().usingSite(privateSite).addPerson(newUser); + + file = dataContent.usingSite(privateSite).usingUser(adminUser).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + String newContent = "This is a new comment added by " + newUser.getUsername(); + + restClient.authenticateUser(newUser).withCoreAPI().usingResource(file).addComment(newContent) + .assertThat().field("content").isNotEmpty() + .and().field("content").is(newContent); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.authenticateUser(adminUser).withCoreAPI().usingSite(privateSite).deleteSiteMember(newUser); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withCoreAPI().usingSite(privateSite).getSiteMembers().assertThat().entriesListDoesNotContain("id", newUser.getUsername()); + + RestCommentModelsCollection comments = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(file).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", newContent) + .and().entriesListContains("createdBy.id", newUser.getUsername()); + } + + /** + * Scenario: + * 1. Add one file to favorites then add a comment to this file + */ + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, + executionType = ExecutionType.REGRESSION, + description = "Add one file to favorites then add a comment to this file") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void commentAFavoriteFile() throws Exception + { + file = dataContent.usingSite(publicSite).usingUser(adminUser).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + restClient.authenticateUser(manager).withCoreAPI().usingMe().addFileToFavorites(file); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.withCoreAPI().usingAuthUser().getFavorites() + .assertThat().entriesListContains("targetGuid", file.getNodeRefWithoutVersion()); + + RestCommentModel comment = restClient.withCoreAPI().usingResource(file).addComment("new comment"); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + comment.assertThat().field("content").is("new comment"); + } + + /** + * Scenario: + * 1. Remove one file from favorites then add a comment to this file + */ + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, + executionType = ExecutionType.REGRESSION, + description = "Remove one file from favorites then add a comment to this file") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void commentFileRemovedFromFavorites() throws Exception + { + file = dataContent.usingSite(publicSite).usingUser(adminUser).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + restClient.authenticateUser(manager).withCoreAPI().usingMe().addFileToFavorites(file); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.withCoreAPI().usingMe().deleteFileFromFavorites(file); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + restClient.withCoreAPI().usingAuthUser().getFavorites() + .assertThat().entriesListDoesNotContain("targetGuid", file.getNodeRefWithoutVersion()); + + RestCommentModel comment = restClient.withCoreAPI().usingResource(file).addComment("new comment"); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + comment.assertThat().field("content").is("new comment"); + } + + /** + * Scenario: + * 1. Add public site to favorites + * 2. Change site visibility to moderated + * 3. Check favorites + * 4. Change site visibility to private + * 5. Check favorites + */ + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, + executionType = ExecutionType.REGRESSION, + description = "Check favorite sites after a favorite site visibility is changed") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void changeFavoriteSiteVisibilityThenCheckFavorites() throws Exception + { + SiteModel favoriteSite = dataSite.usingUser(manager).createPublicRandomSite(); + UserModel regularUser = dataUser.createRandomTestUser(); + + restClient.authenticateUser(regularUser).withCoreAPI().usingAuthUser().addSiteToFavorites(favoriteSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + RestPersonFavoritesModelsCollection userFavoriteSites = restClient.withCoreAPI().usingAuthUser().where().targetSiteExist().getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + userFavoriteSites.assertThat().entriesListContains("targetGuid", favoriteSite.getGuid()) + .assertThat().entriesListContains("target.site.visibility", favoriteSite.getVisibility().name()) + .assertThat().entriesListContains("target.site.id", favoriteSite.getId()); + + dataSite.usingUser(manager).updateSiteVisibility(favoriteSite, Visibility.MODERATED); + + userFavoriteSites = restClient.authenticateUser(regularUser).withCoreAPI().usingAuthUser().where().targetSiteExist().getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + userFavoriteSites.assertThat().entriesListContains("targetGuid", favoriteSite.getGuid()) + .assertThat().entriesListContains("target.site.visibility", "MODERATED") + .assertThat().entriesListContains("target.site.id", favoriteSite.getId()); + + dataSite.usingUser(manager).updateSiteVisibility(favoriteSite, Visibility.PRIVATE); + + userFavoriteSites = restClient.authenticateUser(regularUser).withCoreAPI().usingAuthUser().where().targetSiteExist().getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + userFavoriteSites.assertThat().entriesListIsEmpty(); + + dataSite.usingUser(manager).updateSiteVisibility(favoriteSite, Visibility.PUBLIC); + + userFavoriteSites = restClient.authenticateUser(regularUser).withCoreAPI().usingAuthUser().where().targetSiteExist().getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + userFavoriteSites.assertThat().entriesListContains("targetGuid", favoriteSite.getGuid()) + .assertThat().entriesListContains("target.site.visibility", favoriteSite.getVisibility().name()) + .assertThat().entriesListContains("target.site.id", favoriteSite.getId()); + } + + /** + * Scenario: + * 1. Regular user adds moderated site membership request + * 2. Site manager approves the request + * 3. Site manager updates the new member role to Manager + * 4. New member adds comment to a file on site + * 5. New member likes and rate one file + * 6. New member adds tags to a file + * 7. New member adds site to favorite + * 8. New member adds, then deletes a site member + */ + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, + executionType = ExecutionType.REGRESSION, + description = "Check that a user who joins a moderated site as manager is able to comment, rate, tag an existing file from the site, add site to favorites, add and remove site members.") + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + public void checkNewManagerActions() throws Exception + { + UserModel newMember = dataUser.createRandomTestUser(); + file = dataContent.usingSite(moderatedSite).usingUser(adminUser).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(newMember).withCoreAPI().usingMe().addSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + RestTaskModel taskModel = restClient.withWorkflowAPI().getTasks().getTaskModelByDescription(moderatedSite); + workflow.approveSiteMembershipRequest(adminUser.getUsername(), adminUser.getPassword(), taskModel.getId(), true, "Approve"); + returnedCollection = restClient.withCoreAPI().usingMe().getSiteMembershipRequests(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedCollection.assertThat().entriesListDoesNotContain("id", moderatedSite.getId()); + + newMember.setUserRole(UserRole.SiteManager); + restClient.authenticateUser(adminUser).withCoreAPI().usingSite(moderatedSite).updateSiteMember(newMember) + .assertThat().field("id").is(newMember.getUsername()) + .and().field("role").is(newMember.getUserRole()); + restClient.assertStatusCodeIs(HttpStatus.OK); + + RestCommentModel comment = restClient.authenticateUser(newMember).withCoreAPI().usingResource(file).addComment("new comment"); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + comment.assertThat().field("content").is("new comment"); + + RestRatingModel returnedRatingModel = restClient.withCoreAPI().usingResource(file).likeDocument(); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + returnedRatingModel.assertThat().field("myRating").is("true") + .and().field("id").is("likes") + .and().field("aggregate").isNotEmpty(); + + returnedRatingModel = restClient.withCoreAPI().usingResource(file).rateStarsToDocument(5); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + returnedRatingModel.assertThat().field("myRating").is("5") + .and().field("id").is("fiveStar") + .and().field("aggregate").isNotEmpty(); + + RestTagModel tag = restClient.withCoreAPI().usingResource(file).addTag("filetag"); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + tag.assertThat().field("tag").is("filetag") + .and().field("id").isNotEmpty(); + + restFavoriteSiteModel = restClient.withCoreAPI().usingAuthUser().addFavoriteSite(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restFavoriteSiteModel.assertThat().field("id").is(moderatedSite.getId()); + + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteManager); + restClient.withCoreAPI().usingSite(moderatedSite).addPerson(testUser) + .assertThat().field("id").is(testUser.getUsername()) + .and().field("role").is(testUser.getUserRole()); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.withCoreAPI().usingSite(moderatedSite).deleteSiteMember(testUser); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + restClient.withCoreAPI().usingSite(moderatedSite).getSiteMembers() + .assertThat().entriesListDoesNotContain("id", testUser.getUsername()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + /** + * Scenario: + * 1. Add user to site + * 2. Create folder + * 3. Create document + * 4. Add comment to the document + * 5. Like document + * 6. Update Comment + * 7. Update user role + * 8. Delete like rating + * 9. Delete site member + * 10. Delete comment + * 11. Get Activities + * + * @throws Exception + */ + @Bug(id="REPO-1830") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.ACTIVITIES }, executionType = ExecutionType.REGRESSION, description = "Verify user gets its activities with Rest API and response is successful") + public void userGetsItsPeopleActivities() throws Exception + { + UserModel newUser = dataUser.createRandomTestUser(); + SiteModel userSiteModel = dataSite.usingUser(adminUser).createPublicRandomSite(); + + dataUser.addUserToSite(newUser, userSiteModel, UserRole.SiteCollaborator); + dataContent.usingUser(newUser).usingSite(userSiteModel).createFolder(); + + fileInSite = dataContent.usingUser(newUser).usingSite(userSiteModel).createContent(DocumentType.TEXT_PLAIN); + String newContent = "This is a new comment added by " + newUser.getUsername(); + commentModel = restClient.authenticateUser(newUser).withCoreAPI().usingResource(fileInSite).addComment(newContent); + restClient.authenticateUser(newUser).withCoreAPI().usingResource(fileInSite).likeDocument(); + + restClient.withCoreAPI().usingResource(fileInSite).updateComment(commentModel, "new Content"); + newUser.setUserRole(UserRole.SiteManager); + restClient.authenticateUser(adminUser).withCoreAPI().usingSite(userSiteModel).updateSiteMember(newUser); + + restClient.authenticateUser(newUser).withCoreAPI().usingResource(fileInSite).deleteLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withCoreAPI().usingResource(fileInSite).deleteComment(commentModel); + restClient.authenticateUser(adminUser).withCoreAPI().usingSite(userSiteModel).deleteSiteMember(newUser); + + restActivityModelsCollection = restClient.authenticateUser(newUser).withCoreAPI().usingMe().getPersonActivitiesUntilEntriesCountIs(10); + restClient.assertStatusCodeIs(HttpStatus.OK); + restActivityModelsCollection.assertThat().paginationField("count").is("10"); + + restActivityModelsCollection = restClient.authenticateUser(newUser).withCoreAPI().usingMe().getPersonActivities(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restActivityModelsCollection.assertThat().paginationField("count").is("10"); + + restActivityModelsCollection.assertThat().entriesListContains("activityType", ActivityType.USER_JOINED.toString()).assertThat() + .entriesListContains("activityType", ActivityType.FILE_ADDED.toString()).assertThat() + .entriesListContains("activityType", ActivityType.FOLDER_ADDED.toString()).assertThat() + .entriesListContains("activityType", ActivityType.COMMENT_CREATED.toString()).assertThat() + .entriesListContains("activityType", ActivityType.FILE_LIKED.toString()).assertThat() + .entriesListContains("activityType", ActivityType.COMMENT_UPDATED.toString()).assertThat() + .entriesListContains("activityType", ActivityType.USER_ROLE_CHANGED.toString()).assertThat() + .entriesListContains("activityType", ActivityType.COMMENT_DELETED.toString()).assertThat() + .entriesListContains("activityType", ActivityType.USER_LEFT.toString()); + } + +} \ No newline at end of file diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/RestTest.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/RestTest.java new file mode 100644 index 0000000000..f4104eda88 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/RestTest.java @@ -0,0 +1,85 @@ +package org.alfresco.rest; + +import java.lang.reflect.Method; + +import org.alfresco.dataprep.WorkflowService; +import org.alfresco.rest.core.RestProperties; +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.utility.LogFactory; +import org.alfresco.utility.TasProperties; +import org.alfresco.utility.data.DataContent; +import org.alfresco.utility.data.DataGroup; +import org.alfresco.utility.data.DataLink; +import org.alfresco.utility.data.DataSite; +import org.alfresco.utility.data.DataUserAIS; +import org.alfresco.utility.data.DataWorkflow; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.network.ServerHealth; +import org.slf4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.BeforeSuite; + +@ContextConfiguration("classpath:alfresco-restapi-context.xml") +public abstract class RestTest extends AbstractTestNGSpringContextTests +{ + private static Logger LOG = LogFactory.getLogger(); + + @Autowired + protected RestProperties restProperties; + + @Autowired + protected TasProperties properties; + + @Autowired + protected ServerHealth serverHealth; + + @Autowired + protected RestWrapper restClient; + + @Autowired + protected DataUserAIS dataUser; + + @Autowired + protected DataSite dataSite; + + @Autowired + protected DataContent dataContent; + + @Autowired + protected DataGroup dataGroup; + + @Autowired + protected DataWorkflow dataWorkflow; + + @Autowired + protected DataLink dataLink; + + @Autowired + protected WorkflowService workflow; + + protected SiteModel testSite; + + @BeforeSuite(alwaysRun = true) + public void checkServerHealth() throws Exception + { + super.springTestContextPrepareTestInstance(); + serverHealth.assertServerIsOnline(); + testSite = dataSite.createPublicRandomSite(); + } + + @BeforeMethod(alwaysRun=true) + public void showStartTestInfo(Method method) + { + LOG.info(String.format("*** STARTING Test: [%s] ***",method.getName())); + } + + @AfterMethod(alwaysRun=true) + public void showEndTestInfo(Method method) + { + LOG.info(String.format("*** ENDING Test: [%s] ***", method.getName())); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/actions/ActionsTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/actions/ActionsTests.java new file mode 100644 index 0000000000..df822111de --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/actions/ActionsTests.java @@ -0,0 +1,151 @@ +package org.alfresco.rest.actions; + +import static org.testng.Assert.assertFalse; + +import com.google.common.collect.ImmutableMap; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestActionDefinitionModel; +import org.alfresco.rest.model.RestActionDefinitionModelsCollection; +import org.alfresco.rest.model.RestNodeModel; +import org.alfresco.utility.Utility; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.json.JSONObject; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class ActionsTests extends RestTest +{ + private UserModel adminUser; + private FileModel document; + private SiteModel publicSite; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + publicSite = dataSite.createPublicRandomSite(); + document = dataContent.usingSite(publicSite).usingUser(adminUser).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.ACTIONS }, executionType = ExecutionType.SANITY, + description = "Verify actions") + @Test(groups = { TestGroup.REST_API, TestGroup.ACTIONS, TestGroup.SANITY}) + public void testActionDefinitions() throws Exception + { + restClient.authenticateUser(dataContent.getAdminUser()); + + RestActionDefinitionModelsCollection restActionDefinitions = restClient. + withCoreAPI(). + usingActions(). + listActionDefinitions(); + + restClient.assertStatusCodeIs(HttpStatus.OK); + assertFalse(restActionDefinitions.isEmpty()); + restActionDefinitions.assertThat(). + entriesListContains("name", "copy"). + and().entriesListContains("name", "move"). + and().entriesListContains("name", "check-out"). + and().entriesListContains("name", "check-in"); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.ACTIONS }, executionType = ExecutionType.REGRESSION, + description = "Verify actions error conditions") + @Test(groups = { TestGroup.REST_API, TestGroup.ACTIONS, TestGroup.REGRESSION}) + public void testActionDefinitionsNegative() throws Exception{ + // Badly formed request -> 400 + { + restClient.authenticateUser(dataContent.getAdminUser()). + // invalid skipCount + withParams("skipCount=-1"). + withCoreAPI(). + usingActions(). + listActionDefinitions(); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST); + + } + + // Unauthorized -> 401 + { + + UserModel userUnauthorized = new UserModel("invalid-user", "invalid-pasword"); + restClient.authenticateUser(userUnauthorized).withCoreAPI().usingActions().listActionDefinitions(); + + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.ACTIONS }, executionType = ExecutionType.SANITY, + description = "Sanity test for POST /action-executions") + @Test(groups = { TestGroup.REST_API, TestGroup.ACTIONS, TestGroup.SANITY}) + public void executeAction() throws Exception + { + JSONObject response = restClient.authenticateUser(adminUser).withCoreAPI().usingActions().executeAction + ("add-features", document, ImmutableMap.of("aspect-name", "cm:versionable")); + restClient.assertStatusCodeIs(HttpStatus.ACCEPTED); + + assertFalse(response.getString("id").isEmpty()); + + /* + * Get all node properties and check that action was executed and + * cm:versionable aspect was added + */ + Utility.sleep(500, 20000, () -> { + RestNodeModel fileModel = restClient.authenticateUser(adminUser).withCoreAPI().usingNode(document).getNode(); + + restClient.assertStatusCodeIs(HttpStatus.OK); + fileModel.assertThat().field("aspectNames").contains("cm:versionable"); + }); + } + + @TestRail (section = { TestGroup.REST_API, TestGroup.ACTIONS }, executionType = ExecutionType.SANITY, + description = "Sanity test for POST /action-executions") + @Test (groups = { TestGroup.REST_API, TestGroup.ACTIONS, TestGroup.SANITY }) + public void executeActionWithoutParam() throws Exception + { + JSONObject response = restClient.authenticateUser(adminUser).withCoreAPI().usingActions().executeAction + ("check-out", document); + restClient.assertStatusCodeIs(HttpStatus.ACCEPTED); + + assertFalse(response.getString("id").isEmpty()); + + /* + * Get all node properties and check that action was executed and + * cm:checkedOut aspect was added + */ + Utility.sleep(500, 20000, () -> { + RestNodeModel fileModel = restClient.authenticateUser(adminUser).withCoreAPI().usingNode(document) + .getNode(); + + restClient.assertStatusCodeIs(HttpStatus.OK); + fileModel.assertThat().field("aspectNames").contains("cm:checkedOut"); + }); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.ACTIONS }, executionType = ExecutionType.SANITY, + description = "Sanity test for ACTIONS endpoint GET action-definitions/{actionDefinitionId}") + @Test(groups = { TestGroup.REST_API, TestGroup.ACTIONS, TestGroup.SANITY}) + public void testGetActionDefinitionById() throws Exception + { + restClient.authenticateUser(dataContent.getAdminUser()); + + RestActionDefinitionModel restActionDefinition = restClient. + withCoreAPI(). + usingActions(). + getActionDefinitionById("add-features"); + + restClient.assertStatusCodeIs(HttpStatus.OK); + assertFalse(restActionDefinition.getId().isEmpty()); + restActionDefinition.getId().equals("add-features"); + restActionDefinition.getDescription().equals("This will add an aspect to the matched item."); + restActionDefinition.getTitle().equals("Add aspect"); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/aos/AosApiTest.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/aos/AosApiTest.java new file mode 100644 index 0000000000..6223db2f7d --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/aos/AosApiTest.java @@ -0,0 +1,24 @@ +package org.alfresco.rest.aos; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.RestRequest; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.testng.annotations.Test; + +public class AosApiTest extends RestTest +{ + /* + * @author: Catalin Gornea + * + * simple test for demo purposes on how to use Aos with Rest + */ + @Test(enabled=false) + public void assertResponsIsSuccesufulWhenGetRootDirectory() throws Exception + { + restClient.authenticateUser(dataUser.getAdminUser()).withAosAPI(); + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, ""); + restClient.process(request); + restClient.assertStatusCodeIs(HttpStatus.OK); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/auth/AuthTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/auth/AuthTests.java new file mode 100644 index 0000000000..70826fe4c2 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/auth/AuthTests.java @@ -0,0 +1,87 @@ +package org.alfresco.rest.auth; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.exception.JsonToModelConversionException; +import org.alfresco.rest.model.RestTicketBodyModel; +import org.alfresco.rest.model.RestTicketModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.commons.codec.binary.Base64; +import org.springframework.http.HttpStatus; +import org.testng.Assert; +import org.testng.annotations.Test; + +public class AuthTests extends RestTest +{ + + private RestWrapper addRestRequestAuthorization(RestTicketModel ticketModel) + { + restClient.configureRequestSpec().addHeader("Authorization", "Basic " + encodeB64(ticketModel.getId())); + return restClient; + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.AUTH }, executionType = ExecutionType.SANITY, description = "Verify HttpMethod.POST tickets") + @Test(groups = { TestGroup.REST_API, TestGroup.SANITY, TestGroup.AUTH }) + public void adminShouldGetTicketBody() throws JsonToModelConversionException, Exception + { + RestTicketBodyModel ticketBody = new RestTicketBodyModel(); + ticketBody.setUserId("admin"); + ticketBody.setPassword("admin"); + + RestTicketModel ticketReturned = restClient.authenticateUser(dataContent.getAdminUser()).withAuthAPI().createTicket(ticketBody); + + restClient.assertStatusCodeIs(HttpStatus.CREATED); + ticketReturned.assertThat().field("id").contains("TICKET_"); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.AUTH }, executionType = ExecutionType.SANITY, description = "Verify HttpMethod.GET tickets/-me-") + @Test(groups = { TestGroup.REST_API, TestGroup.SANITY, TestGroup.AUTH }) + public void randomUserGetTicket() throws Exception + { + UserModel userModel = dataUser.createRandomTestUser(); + RestTicketBodyModel ticketBody = new RestTicketBodyModel(); + ticketBody.setUserId(userModel.getUsername()); + ticketBody.setPassword(userModel.getPassword()); + + RestTicketModel ticketCreated = restClient.authenticateUser(userModel).withAuthAPI().createTicket(ticketBody); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + addRestRequestAuthorization(ticketCreated); + RestTicketModel ticketReturned = restClient.withAuthAPI().getTicket(); + Assert.assertEquals(ticketCreated.getId(), ticketReturned.getId()); + + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.AUTH }, executionType = ExecutionType.SANITY, description = "Verify HttpMethod.REMOVE tickets/-me-") + @Test(groups = { TestGroup.REST_API, TestGroup.SANITY, TestGroup.AUTH }) + public void randomUserRemoveTicket() throws Exception + { + UserModel userModel = dataUser.createRandomTestUser(); + RestTicketBodyModel ticketBody = new RestTicketBodyModel(); + ticketBody.setUserId(userModel.getUsername()); + ticketBody.setPassword(userModel.getPassword()); + + RestTicketModel ticketCreated = restClient.authenticateUser(userModel).withAuthAPI().createTicket(ticketBody); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + addRestRequestAuthorization(ticketCreated); + restClient.withAuthAPI().removeTicket(); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + restClient.withAuthAPI().getTicket(); + restClient.assertLastError().containsErrorKey("Ticket base authentication required."); + + } + + private String encodeB64(String str) + { + return Base64.encodeBase64String(str.getBytes()); + } + +} \ No newline at end of file diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/cmis/CmisBrowserTest.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/cmis/CmisBrowserTest.java new file mode 100644 index 0000000000..1e9afbab76 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/cmis/CmisBrowserTest.java @@ -0,0 +1,25 @@ +package org.alfresco.rest.cmis; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.RestResponse; +import org.alfresco.utility.model.FileModel; +import org.testng.annotations.Test; + +public class CmisBrowserTest extends RestTest +{ + /* + * @author: Paul Brodner + * simple test for demo purposes on how to use CMIS browser binding with Rest + */ + @Test(enabled=false) + public void assertContentDispositionHeaderOnCmisFile() throws Exception + { + FileModel document = dataContent.usingUser(dataUser.getAdminUser()) + .usingSite(testSite).createContent(DocumentType.HTML); + + RestResponse response = restClient.authenticateUser(dataUser.getAdminUser()).withCMISApi().getRootObjectByID(document); + response.assertThat().header("Content-Disposition", String.format("attachment; filename=%s", document.getName())); + } + +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/comments/AddCommentTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/comments/AddCommentTests.java new file mode 100644 index 0000000000..2ae874babc --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/comments/AddCommentTests.java @@ -0,0 +1,258 @@ +package org.alfresco.rest.comments; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestCommentModel; +import org.alfresco.rest.model.RestCommentModelsCollection; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestTagModel; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.RandomData; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +import org.alfresco.utility.model.LinkModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.commons.lang3.RandomStringUtils; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class AddCommentTests extends RestTest +{ + private UserModel adminUserModel; + private FileModel document; + private SiteModel siteModel; + private ListUserWithRoles usersWithRoles; + private String comment; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUserModel = dataUser.getAdminUser(); + restClient.authenticateUser(adminUserModel); + siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); + document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, + UserRole.SiteContributor); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.SANITY, description = "Verify admin user adds comments with Rest API and status code is 201") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.SANITY }) + public void adminIsAbleToAddComment() throws Exception + { + restClient.authenticateUser(adminUserModel); + String newContent = "This is a new comment added by " + adminUserModel.getUsername(); + restClient.withCoreAPI().usingResource(document).addComment(newContent) + .assertThat().field("content").isNotEmpty() + .and().field("content").is(newContent); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.onResponse().assertThat().body("entry.edited", org.hamcrest.Matchers.is(false)); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.SANITY, + description = "Verify that comment can be retrieved after it is added") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.SANITY }) + public void addCommentThenRetrieveComment() throws Exception + { + comment = RandomData.getRandomName("comment1"); + restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingResource(document).addComment(comment); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + RestCommentModelsCollection comments = restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingResource(document).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + + comments.assertThat().entriesListContains("content", comment); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.SANITY, description = "Verify unauthenticated user gets status code 401 on post comments call") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.SANITY }) +// @Bug(id = "MNT-16904", description = "It fails only on environment with tenants") + public void unauthenticatedUserIsNotAbleToAddComment() throws Exception + { + restClient.authenticateUser(new UserModel("random user", "random password")); + restClient.withCoreAPI().usingResource(document).addComment("This is a new comment"); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Manager user adds comments with Rest API and status code is 201") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void managerIsAbleToAddComment() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + String contentSiteManger = "This is a new comment added by user with role: " + UserRole.SiteManager; + RestCommentModel createdComment = restClient.withCoreAPI().usingResource(document).addComment(contentSiteManger); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + createdComment.assertThat().field("content").isNotEmpty() + .and().field("content").is(contentSiteManger); + + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Contributor user adds comments with Rest API and status code is 201") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + @Bug(id="ACE-4614") + public void contributorIsAbleToAddComment() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); + String contentSiteContributor = "This is a new comment added by user with role" + UserRole.SiteContributor; + RestCommentModel createdComment = restClient.withCoreAPI().usingResource(document).addComment(contentSiteContributor); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + createdComment.assertThat().field("content").isNotEmpty() + .and().field("content").is(contentSiteContributor); + + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Collaborator user adds comments with Rest API and status code is 201") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void collaboratorIsAbleToAddComment() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); + String contentSiteCollaborator = "This is a new comment added by user with role: " + UserRole.SiteCollaborator; + restClient.withCoreAPI().usingResource(document).addComment(contentSiteCollaborator) + .assertThat().field("content").isNotEmpty() + .and().field("content").is(contentSiteCollaborator); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Consumer user can't add comments with Rest API and status code is 403") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void consumerIsNotAbleToAddComment() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)); + String contentSiteConsumer = "This is a new comment added by user with role: " + UserRole.SiteConsumer; + restClient.withCoreAPI().usingResource(document).addComment(contentSiteConsumer); + restClient + .assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, + description = "Verify that invalid request returns status code 404 for nodeId that does not exist") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void addCommentUsingInvalidNodeId() throws Exception + { + comment = RandomData.getRandomName("comment1"); + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + file.setNodeRef(RandomStringUtils.randomAlphanumeric(20)); + + restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingResource(file).addComment(comment); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, file.getNodeRef())); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, + description = "Verify that request using nodeId that is neither document or folder returns 405") + @Bug(id = "MNT-16904") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void addCommentUsingResourceThatIsNotFileOrFolder() throws Exception + { + comment = RandomData.getRandomName("comment1"); + LinkModel link = dataLink.usingAdmin().usingSite(siteModel).createRandomLink(); + FileModel fileWithNodeRefFromLink = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + fileWithNodeRefFromLink = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + fileWithNodeRefFromLink.setNodeRef(link.getNodeRef()); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingResource(fileWithNodeRefFromLink).addComment(comment); + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, + description = "Verify that adding comment using empty content returns 400 status code") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void addCommentUsingEmptyContent() throws Exception + { + restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingResource(document).addComment(""); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(String.format(RestErrorModel.NULL_ARGUMENT, "comment")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, + description = "Verify adding comment with the same content as one existing comment") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void addCommentTwice() throws Exception + { + comment = RandomData.getRandomName("comment1"); + restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingResource(document).addComment(comment); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingResource(document).addComment(comment); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.withCoreAPI().usingResource(document).getNodeComments() + .assertThat().entriesListContains("content", comment); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, + description = "Verify comment cannot be added if user is not member of private site") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void addCommentWithNonMemberOfPrivateSite() throws Exception + { + comment = RandomData.getRandomName("comment1"); + UserModel member = dataUser.createRandomTestUser(); + SiteModel privateSite = dataSite.usingUser(adminUserModel).createPrivateRandomSite(); + FileModel file = dataContent.usingSite(privateSite).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(member) + .withCoreAPI().usingResource(file).addComment(comment); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, + description = "Verify comment cannot be added if empty network ID is provided") +// @Bug(id = "MNT-16904", description = "It fails only on environment with tenants") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void addCommentUsingEmptyNetworkId() throws Exception + { + comment = RandomData.getRandomName("comment1"); + UserModel member = dataUser.createRandomTestUser(); + member.setDomain(""); + + restClient.authenticateUser(member) + .withCoreAPI().usingResource(document).addComment(comment); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, + description = "Verify that comment cannot be added to another comment") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void addCommentToAComment() throws Exception + { + comment = RandomData.getRandomName("comment1"); + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + RestCommentModel commentEntry = restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingResource(file).addComment(comment); + file.setNodeRef(commentEntry.getId()); + + restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingResource(file).addComment(comment); + + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED).assertLastError().containsSummary(RestErrorModel.CANNOT_COMMENT); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, + description = "Verify that comment cannot be added to a tag") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void addCommentToATag() throws Exception + { + comment = RandomData.getRandomName("comment1"); + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + RestTagModel tag = restClient.withCoreAPI().usingResource(document).addTag("randomTag"); + + file.setNodeRef(tag.getId()); + + restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingResource(file).addComment(comment); + + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED).assertLastError().containsSummary(RestErrorModel.CANNOT_COMMENT); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/comments/AddCommentsTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/comments/AddCommentsTests.java new file mode 100644 index 0000000000..d2e81252c2 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/comments/AddCommentsTests.java @@ -0,0 +1,377 @@ +package org.alfresco.rest.comments; + +import java.util.List; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.JsonBodyGenerator; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.exception.JsonToModelConversionException; +import org.alfresco.rest.model.RestCommentModel; +import org.alfresco.rest.model.RestCommentModelsCollection; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestTagModel; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.data.RandomData; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +import org.alfresco.utility.model.LinkModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.commons.lang3.RandomStringUtils; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 10/10/2016. + */ +public class AddCommentsTests extends RestTest +{ + private UserModel adminUserModel, networkUserModel; + private FileModel document; + private SiteModel siteModel; + private DataUser.ListUserWithRoles usersWithRoles; + private RestCommentModelsCollection comments; + private String comment1, comment2; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUserModel = dataUser.getAdminUser(); + networkUserModel = dataUser.createRandomTestUser(); + restClient.authenticateUser(adminUserModel); + siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); + + document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor); + } + + @BeforeMethod(alwaysRun = true) + public void generateRandomComments() + { + comment1 = RandomData.getRandomName("comment1"); + comment2 = RandomData.getRandomName("comment2"); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.COMMENTS }, executionType = ExecutionType.SANITY, description = "Verify admin user adds multiple comments with Rest API and status code is 201") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.SANITY }) + public void adminIsAbleToAddComments() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingResource(document).addComments(comment1, comment2) + .assertThat().entriesListIsNotEmpty() + .and().entriesListContains("content", comment1) + .and().entriesListContains("content", comment2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.COMMENTS }, executionType = ExecutionType.SANITY, description = "Verify unauthenticated user gets status code 401 on post multiple comments call") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.SANITY }) + public void unauthenticatedUserIsNotAbleToAddComments() throws JsonToModelConversionException, Exception + { + restClient.noAuthentication() + .withCoreAPI().usingResource(document).addComments(comment1, comment2); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Manager user adds multiple comments with Rest API and status code is 201") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void managerIsAbleToAddComments() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingResource(document).addComments(comment1, comment2) + .assertThat().entriesListIsNotEmpty() + .and().entriesListContains("content", comment1) + .and().entriesListContains("content", comment2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Contributor user adds multiple comments with Rest API and status code is 201") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void contributorIsAbleToAddComments() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .withCoreAPI().usingResource(document).addComments(comment1, comment2) + .assertThat().entriesListIsNotEmpty() + .and().entriesListContains("content", comment1) + .and().entriesListContains("content", comment2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Collaborator user adds multiple comments with Rest API and status code is 201") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void collaboratorIsAbleToAddComments() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .withCoreAPI().usingResource(document).addComments(comment1, comment2) + .assertThat().paginationExist().and().entriesListIsNotEmpty() + .and().entriesListContains("content", comment1) + .and().entriesListContains("content", comment2); + + restClient.assertStatusCodeIs(HttpStatus.CREATED); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Consumer user adds multiple comments with Rest API and status code is 201") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void consumerIsAbleToAddComments() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .withCoreAPI().usingResource(document).addComments(comment1, comment2); + + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify User can not add comments to a not joined private site. Status code returned is 403") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void userCanNotAddCommentsToANotJoinedPrivateSite() throws Exception + { + SiteModel sitePrivateNotJoined = dataSite.createPrivateRandomSite(); + FileModel file = dataContent.usingSite(sitePrivateNotJoined).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingResource(file).addComments(comment1, comment2); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify User can't add comments to a node with ID that does not exist and status code is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void userCanNotAddCommentsOnNonexistentFile() throws Exception + { + FileModel nonexistentFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + + nonexistentFile.setNodeRef("ABC"); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(nonexistentFile).addComments(comment1,comment2); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, nonexistentFile.getNodeRef())); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify User can't add comments to a node that exists but is not a document or a folder and status code is 405") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + @Bug(id = "MNT-16904") + public void userCanNotAddCommentsOnLink() throws Exception + { + LinkModel link = dataLink.usingAdmin().usingSite(siteModel).createRandomLink(); + FileModel fileWithNodeRefFromLink = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + fileWithNodeRefFromLink.setNodeRef(link.getNodeRef()); + + restClient.authenticateUser(adminUserModel).withCoreAPI() + .usingResource(fileWithNodeRefFromLink).addComments(comment1,comment2); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(RestErrorModel.UNABLE_TO_LOCATE); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify User can add comments with the same content as one existing comment") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void userCanAddCommentWithTheSameContentAsExistingOne() throws Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + String sameComment = comment1; + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingResource(file).addComments(comment1, sameComment) + .assertThat().paginationExist().and().entriesListIsNotEmpty() + .and().entriesListContains("content", comment1) + .and().entriesListContains("content", sameComment); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + comments = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI() + .usingResource(file).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListIsNotEmpty(); + List commentsList = comments.getEntries(); + commentsList.get(0).onModel().assertThat().field("content").is(comment1); + commentsList.get(1).onModel().assertThat().field("content").is(sameComment); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify add comments from node with invalid network id returns status code 401") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void addCommentsWithInvalidNetworkId() throws Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + + networkUserModel.setDomain("invalidNetwork"); + restClient.authenticateUser(networkUserModel).withCoreAPI().usingResource(file).addComments(comment1,comment2); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify add comments from node with empty network id returns status code 401") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void addCommentsWithEmptyNetworkId() throws Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + + networkUserModel.setDomain(""); + restClient.authenticateUser(networkUserModel).withCoreAPI().usingResource(file).addComments(comment1,comment2); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, + description = "Verify that comments cannot be added to another comment") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void addCommentsToAComment() throws JsonToModelConversionException, Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + RestCommentModel commentEntry = restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingResource(file).addComment(comment1); + file.setNodeRef(commentEntry.getId()); + + restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingResource(file).addComments(comment1, comment2); + + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED).assertLastError().containsSummary(RestErrorModel.CANNOT_COMMENT); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, + description = "Verify that comments cannot be added to a tag") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void addCommentsToATag() throws JsonToModelConversionException, Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + RestTagModel tag = restClient.withCoreAPI().usingResource(file).addTag("randomTag"); + + file.setNodeRef(tag.getId()); + + restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingResource(file).addComments(comment1, comment2); + + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED).assertLastError().containsSummary(RestErrorModel.CANNOT_COMMENT); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Using Manager user verify that you can provide a large string for one comment") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void addLongCommentsWithManagerAndCheckThatCommentIsReturned() throws Exception + { + document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + String longString = RandomStringUtils.randomAlphanumeric(10000); + String longString1 = RandomStringUtils.randomAlphanumeric(90000); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingResource(document).addComments(longString, longString1); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", longString); + comments.assertThat().entriesListContains("content", longString1); + comments.assertThat().paginationField("totalItems").is("2"); + comments.assertThat().paginationField("count").is("2"); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Using Manager user verify that you can provide a short string for one comment") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void addShortCommentsWithManagerAndCheckThatCommentIsReturned() throws Exception + { + document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + String shortString = RandomStringUtils.randomAlphanumeric(2); + String shortString1 = RandomStringUtils.randomAlphanumeric(1); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingResource(document).addComments(shortString, shortString1); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", shortString); + comments.assertThat().entriesListContains("content", shortString1); + comments.assertThat().paginationField("totalItems").is("2"); + comments.assertThat().paginationField("count").is("2"); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Using Collaborator user verify that you can provide a string with special characters for one comment") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void addCommentsWithSpecialCharsWithCollaboratorCheckCommentIsReturned() throws Exception + { + document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + String specialCharsString = "!@#$%^&*()'\".,<>-_+=|\\"; + String shortString = RandomStringUtils.randomAlphanumeric(2); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .withCoreAPI().usingResource(document).addComments(specialCharsString, shortString); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", specialCharsString); + comments.assertThat().entriesListContains("content", shortString); + comments.assertThat().paginationField("totalItems").is("2"); + comments.assertThat().paginationField("count").is("2"); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Using Manager user verify that you can not provide an empty string for one comment") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void addEmptyStringCommentsWithManagerCheckCommentIsReturned() throws Exception + { + document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + String emptyString = ""; + String spaceString = " "; + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingResource(document).addComments(emptyString, spaceString); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(RestErrorModel.NON_NULL_COMMENT); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Using Collaborator user verify that you can provide several comments in one request") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void addSeveralCommentsWithCollaboratorCheckCommentsAreReturned() throws Exception + { + document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + String charString = RandomStringUtils.randomAlphanumeric(10); + String charString1 = RandomStringUtils.randomAlphanumeric(10); + String charString2 = RandomStringUtils.randomAlphanumeric(10); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .withCoreAPI().usingResource(document).addComments(comment1, comment2, charString, charString1, charString2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", comment1); + comments.assertThat().paginationField("totalItems").is("5"); + comments.assertThat().paginationField("count").is("5"); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Provide invalid request body parameter and check default error model schema") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void invalidRequestBodyParameterCheckErrorModelSchema() throws Exception + { + document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(adminUserModel).withCoreAPI(); + String postBody = JsonBodyGenerator.keyValueJson("content2", comment1); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody, "nodes/{nodeId}/comments", document.getNodeRef()); + restClient.processModel(RestCommentModel.class, request); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST); + restClient.assertLastError().containsErrorKey(String.format(RestErrorModel.UNRECOGNIZED_FIELD, "content2")); + restClient.assertLastError().containsSummary(String.format(RestErrorModel.UNRECOGNIZED_FIELD, "content2")); + restClient.assertLastError().descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + restClient.assertLastError().stackTraceIs(RestErrorModel.STACKTRACE); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/comments/DeleteCommentTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/comments/DeleteCommentTests.java new file mode 100644 index 0000000000..efd769dbed --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/comments/DeleteCommentTests.java @@ -0,0 +1,299 @@ +package org.alfresco.rest.comments; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestCommentModel; +import org.alfresco.rest.model.RestCommentModelsCollection; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.utility.Utility; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import java.io.File; + +public class DeleteCommentTests extends RestTest +{ + private UserModel adminUserModel, networkUserModel; + + private FileModel document; + private SiteModel siteModel; + private RestCommentModelsCollection comments; + private RestCommentModel commentModel; + private ListUserWithRoles usersWithRoles; + private String commentText = "This is a new comment"; + + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + adminUserModel = dataUser.getAdminUser(); + networkUserModel = dataUser.createRandomTestUser(); + restClient.authenticateUser(adminUserModel); + siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); + document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel,UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.COMMENTS }, executionType = ExecutionType.SANITY, description = "Verify Admin user deletes comments with Rest API and status code is 204") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.SANITY }) + public void adminIsAbleToDeleteComments() throws Exception + { + restClient.authenticateUser(adminUserModel); + commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment"); + restClient.withCoreAPI().usingResource(document).deleteComment(commentModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.COMMENTS }, executionType = ExecutionType.SANITY, description = "Verify User gets status code 401 if authentication call fails") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.SANITY }) +// @Bug(id="MNT-16904", description = "It fails only on environment with tenants") + public void userIsNotAbleToDeleteCommentIfAuthenticationFails() throws Exception + { + restClient.authenticateUser(adminUserModel); + commentModel = restClient.withCoreAPI().usingResource(document).addComment("New comment addded by admin"); + UserModel nonexistentModel = new UserModel("nonexistentUser", "nonexistentPassword"); + restClient.authenticateUser(nonexistentModel); + restClient.withCoreAPI().usingResource(document).deleteComment(commentModel); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Manager user deletes own comments and status code is 204") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void managerIsAbleToDeleteComments() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + commentModel = restClient.withCoreAPI().usingResource(document).addComment("New comment added by Manager"); + restClient.withCoreAPI().usingResource(document).deleteComment(commentModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Collaborator user deletes own comments and status code is 204") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void collaboratorIsAbleToDeleteComments() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); + commentModel = restClient.withCoreAPI().usingResource(document).addComment("New comment added by Collaborator"); + restClient.withCoreAPI().usingResource(document).deleteComment(commentModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Contributor user deletes own comments and status code is 204") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void contributorIsAbleToDeleteComments() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); + commentModel = restClient.withCoreAPI().usingResource(document).addComment("New comment added by Contributor"); + restClient.withCoreAPI().usingResource(document).deleteComment(commentModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Consumer user can't delete comments created by admin user and status code is 403") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void consumerIsNotAbleToDeleteComments() throws Exception + { + restClient.authenticateUser(adminUserModel); + commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment"); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)); + restClient.withCoreAPI().usingResource(document).deleteComment(commentModel); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Admin user can't delete comments with inexistent ID and status code is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void userIsNotAbleToDeleteInexistentComment() throws Exception + { + restClient.authenticateUser(adminUserModel); + commentModel = new RestCommentModel(); + commentModel.setId("inexistent"); + restClient.withCoreAPI().usingResource(document).deleteComment(commentModel); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Admin user can't delete comments with inexistend NodeId and status code is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void userIsNotAbleToDeleteCommentWithInexistentNodeId() throws Exception + { + restClient.authenticateUser(adminUserModel); + commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment"); + FileModel inexistentDocument = new FileModel(); + inexistentDocument.setNodeRef("inexistent"); + restClient.withCoreAPI().usingResource(inexistentDocument).deleteComment(commentModel); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Admin user can't delete deleted comments and status code is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void userIsNotAbleToDeleteDeletedComment() throws Exception + { + restClient.authenticateUser(adminUserModel); + commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment"); + restClient.withCoreAPI().usingResource(document).deleteComment(commentModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withCoreAPI().usingResource(document).deleteComment(commentModel); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.COMMENTS }, + executionType = ExecutionType.REGRESSION, description = "Verify Manager user deletes comment created by admin" + + " and status code is 204. Check with getComments for validation") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void managerIsAbleToDeleteCommentCreatedByOthers() throws Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + + commentModel = restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingResource(file).addComment(commentText); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingResource(file).deleteComment(commentModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListDoesNotContain("content", commentText); + comments.getPagination().assertThat().field("totalItems").is("0").and().field("count").is("0"); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.COMMENTS }, + executionType = ExecutionType.REGRESSION, description = "Verify Collaborator user can delete comment created by self" + + " and status code is 204. Check with getComments for validation") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void collaboratorIsAbleToDeleteCommentCreatedBySelf() throws Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + + commentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .withCoreAPI().usingResource(file).addComment(commentText); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.withCoreAPI().usingResource(file).deleteComment(commentModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListDoesNotContain("content", commentText); + comments.getPagination().assertThat().field("totalItems").is("0").and().field("count").is("0"); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.COMMENTS }, + executionType = ExecutionType.REGRESSION, description = "Verify Contributor user deletes comment created by self" + + " and status code is 204. Check with getComments for validation") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + @Bug(id = "ACE-4614") + public void contributorIsAbleToDeleteCommentCreatedBySelf() throws Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + + commentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .withCoreAPI().usingResource(file).addComment(commentText); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.withCoreAPI().usingResource(file).deleteComment(commentModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListDoesNotContain("content", commentText); + comments.getPagination().assertThat().field("totalItems").is("0").and().field("count").is("0"); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.COMMENTS }, + executionType = ExecutionType.REGRESSION, description = "Verify Consumer user cannot delete comment created by admin" + + " and status code is 403. Check with getComments for validation and check default error model schema.") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void consumerIsNotAbleToDeleteCommentCreatedByOthersDefaultErrorModelSchema() throws Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + + commentModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).addComment(commentText); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .withCoreAPI().usingResource(file).deleteComment(commentModel); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED) + .statusCodeIs(HttpStatus.FORBIDDEN) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE) + .containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY); + + comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", commentText); + comments.getPagination().assertThat().field("totalItems").is("1").and().field("count").is("1"); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.COMMENTS }, + executionType = ExecutionType.REGRESSION, description = "Verify Manager can delete comment with version number") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void usingManagerDeleteCommentWithVersionNumber() throws Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + File updatedContent = Utility.getResourceTestDataFile("sampleContent.txt"); + + restClient.withCoreAPI().usingNode(file).usingParams("majorVersion=true&name=newfile.txt").updateNodeContent(updatedContent); + restClient.assertStatusCodeIs(HttpStatus.OK); + + commentModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).addComment(commentText); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingResource(file).deleteComment(commentModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.COMMENTS }, + executionType = ExecutionType.REGRESSION, description = "Verify Manager user cannot delete comment with invalid node " + + "and status code is 404. Check with getComments for validation") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void usingManagerDeleteCommentWithInvalidNode() throws Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + + commentModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).addComment(commentText); + file.setNodeRef("invalid"); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingResource(file).deleteComment(commentModel); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(file.getNodeRef() + " was not found"); + + comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(file.getNodeRef() + " was not found"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS}, executionType = ExecutionType.REGRESSION, + description = "Verify deleteComment from node with invalid network id returns status code 401") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void deleteCommentWithInvalidNetworkId() throws Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + + commentModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).addComment(commentText); + networkUserModel.setDomain("invalidNetwork"); + restClient.authenticateUser(networkUserModel).withCoreAPI().usingResource(file).deleteComment(commentModel); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.COMMENTS }, + executionType = ExecutionType.REGRESSION, description = "Verify deleteComment from node with empty network id returns status code 401") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void deleteCommentWithEmptyNetworkId() throws Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + + commentModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).addComment(commentText); + networkUserModel.setDomain(""); + restClient.authenticateUser(networkUserModel).withCoreAPI().usingResource(file).deleteComment(commentModel); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/comments/GetCommentsTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/comments/GetCommentsTests.java new file mode 100644 index 0000000000..5872f83a7f --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/comments/GetCommentsTests.java @@ -0,0 +1,421 @@ +package org.alfresco.rest.comments; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestCommentModelsCollection; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +import org.alfresco.utility.model.LinkModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class GetCommentsTests extends RestTest +{ + private FileModel file, document, document1; + private SiteModel siteModel, privateSiteModel; + private UserModel adminUserModel, userModel, networkUserModel; + private ListUserWithRoles usersWithRoles; + private String comment = "This is a new comment"; + private String comment2 = "This is a 2nd comment"; + private String comment3 = "This is a 3rd comment"; + private RestCommentModelsCollection comments; + + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + adminUserModel = dataUser.getAdminUser(); + networkUserModel = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); + privateSiteModel = dataSite.usingUser(adminUserModel).createPrivateRandomSite(); + document = dataContent.usingSite(privateSiteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + document1 = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + restClient.authenticateUser(adminUserModel).withCoreAPI() + .usingResource(document1).addComment(comment); + restClient.withCoreAPI().usingResource(document).addComment(comment); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.withCoreAPI().usingResource(document).addComment(comment2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.withCoreAPI().usingResource(document).addComment(comment3); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.SANITY, + description= "Verify Admin user gets comments with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.SANITY }) + public void adminIsAbleToRetrieveComments() throws Exception + { + comments = restClient.authenticateUser(adminUserModel).withCoreAPI() + .usingResource(document1).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", comment); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.SANITY, + description= "Verify Manager user gets status code 401 if authentication call fails") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.SANITY }) +// @Bug(id="MNT-16904", description = "It fails only on environment with tenants") + public void managerIsNotAbleToRetrieveCommentIfAuthenticationFails() throws Exception + { + UserModel nonexistentModel = new UserModel("nonexistentUser", "nonexistentPassword"); + restClient.authenticateUser(nonexistentModel).withCoreAPI() + .usingResource(document1).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify Manager user gets comments created by admin user with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void managerIsAbleToRetrieveComments() throws Exception + { + comments = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI() + .usingResource(document1).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", comment); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify Contributor user gets comments created by admin user with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void contributorIsAbleToRetrieveComments() throws Exception + { + comments = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).withCoreAPI() + .usingResource(document1).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", comment); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify Collaborator user gets comments created by admin user with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void collaboratorIsAbleToRetrieveComments() throws Exception + { + comments = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI() + .usingResource(document1).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", comment); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify Consumer user gets comments created by admin user with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void consumerIsAbleToRetrieveComments() throws Exception + { + comments = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI() + .usingResource(document1).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", comment); + } + + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify Manager user gets comments created by another user and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void managerIsAbleToRetrieveCommentsCreatedByAnotherUser() throws Exception + { + userModel = usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator); + String contentManager = "This is a new comment added by " + userModel.getUsername(); + restClient.authenticateUser(userModel).withCoreAPI() + .usingResource(document1).addComment(contentManager); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + comments = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI() + .usingResource(document1).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", contentManager) + .and().entriesListContains("content", comment); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify admin user gets comments created by another user and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void adminIsAbleToRetrieveCommentsCreatedByAnotherUser() throws Exception + { + userModel = usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator); + String contentCollaborator = "This is a new comment added by " + userModel.getUsername(); + restClient.authenticateUser(userModel).withCoreAPI() + .usingResource(document1).addComment(contentCollaborator); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + comments = restClient.authenticateUser(adminUserModel).withCoreAPI() + .usingResource(document1).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", contentCollaborator) + .and().entriesListContains("content", comment); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify request returns status 403 if the user does not have permission read comments on the node") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void uninvitedUserCanNotGetCommentsFromPrivateSite() throws Exception + { + restClient.authenticateUser(userModel).withCoreAPI() + .usingResource(document).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify user gets comments without the first 2 and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void skipFirst2Comments() throws Exception + { + comments = restClient.authenticateUser(adminUserModel).withParams("skipCount=2") + .withCoreAPI().usingResource(document).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", comment) + .and().paginationField("count").is("1"); + comments.assertThat().paginationField("skipCount").is("2"); + comments.assertThat().paginationField("totalItems").is("3"); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify invalid request returns status code 400 for invalid maxItems or skipCount") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void checkStatusCodeForInvalidMaxItems() throws Exception + { + restClient.authenticateUser(adminUserModel).withParams("maxItems=0") + .withCoreAPI().usingResource(document).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary("Only positive values supported for maxItems"); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify User can't get comments for node with ID that does not exist and status code is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void userCanNotGetCommentsOnNonExistentFile() throws Exception + { + FileModel nonexistentFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + nonexistentFile.setNodeRef("ABC"); + restClient.authenticateUser(adminUserModel).withCoreAPI() + .usingResource(nonexistentFile).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, nonexistentFile.getNodeRef())); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify User can't get comments for node that exists but is not a document or a folder and status code is 400") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void userCanNotGetCommentsOnLink() throws Exception + { + LinkModel link = dataLink.usingAdmin().usingSite(siteModel).createRandomLink(); + FileModel fileWithNodeRefFromLink = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + fileWithNodeRefFromLink.setNodeRef(link.getNodeRef().replace("workspace://SpacesStore/", "workspace%3A%2F%2FSpacesStore%2F")); + restClient.authenticateUser(adminUserModel).withCoreAPI() + .usingResource(fileWithNodeRefFromLink).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, fileWithNodeRefFromLink.getNodeRef())) + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify get comments from node with invalid network id returns status code 401") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void getCommentsWithInvalidNetwork() throws Exception + { + networkUserModel.setDomain("invalidNetwork"); + restClient.authenticateUser(networkUserModel).withCoreAPI().usingResource(document).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify get comments from node with empty network id returns status code 401") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void getCommentsWithEmptyNetwork() throws Exception + { + networkUserModel.setDomain(""); + restClient.authenticateUser(networkUserModel).withCoreAPI().usingResource(document).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify that if manager adds one comment, it will be returned in getComments response") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void addCommentWithManagerAndCheckThatCommentIsReturned() throws Exception + { + file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(file).addComment(comment); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", comment) + .getPagination().assertThat().field("totalItems").is("1") + .assertThat().field("count").is("1"); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify that if collaborator adds one comment, it will be returned in getComments response") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void addCommentWithCollaboratorAndCheckThatCommentIsReturned() throws Exception + { + file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .withCoreAPI().usingResource(file).addComment(comment); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", comment) + .getPagination().assertThat().field("totalItems").is("1") + .assertThat().field("count").is("1"); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify that if contributor adds one comment, it will be returned in getComments response") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + @Bug(id = "ACE-4614") + public void addCommentWithContributorAndCheckThatCommentIsReturned() throws Exception + { + file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .withCoreAPI().usingResource(file).addComment(comment); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", comment) + .getPagination().assertThat().field("totalItems").is("1") + .assertThat().field("count").is("1"); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify that consumer cannot add a comment and no comments will be returned in getComments response") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void addCommentWithConsumerAndCheckThatCommentIsNotReturned() throws Exception + { + file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .withCoreAPI().usingResource(file).addComment(comment); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + + comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().paginationField("totalItems").is("0"); + comments.assertThat().paginationField("count").is("0"); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Add one comment with Manager and check that returned person is the right one") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void addCommentWithManagerCheckReturnedPersonIsTheRightOne() throws Exception + { + file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + UserModel user1 = dataUser.createRandomTestUser(); + dataUser.addUserToSite(user1, siteModel, UserRole.SiteManager); + + restClient.authenticateUser(user1).withCoreAPI().usingResource(file).addComment(comment); + comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); + comments.getOneRandomEntry().onModel().getCreatedBy().assertThat().field("firstName").is(user1.getUsername() + " FirstName") + .assertThat().field("lastName").is("LN-" + user1.getUsername()); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Add one comment with Collaborator and check that returned company details are correct") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void addCommentWithCollaboratorCheckReturnedCompanyDetails() throws Exception + { + file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingResource(file).addComment(comment); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); + comments.getOneRandomEntry().onModel().getCreatedBy().getCompany() + .assertThat().field("organization").isNull() + .assertThat().field("address1").isNull() + .assertThat().field("address2").isNull() + .assertThat().field("address3").isNull() + .assertThat().field("postcode").isNull() + .assertThat().field("telephone").isNull() + .assertThat().field("fax").isNull() + .assertThat().field("email").isNull(); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Add 2 comments with Manager and Collaborator users and verify valid request using skipCount. Check that param is applied") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void addTwoCommentsWithManagerCollaboratorVerifySkipCountParamIsApplied() throws Exception + { + file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(file).addComment(comment); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingResource(file).addComment(comment2); + + comments = restClient.authenticateUser(adminUserModel).withParams("skipCount=1") + .withCoreAPI().usingResource(file).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", comment) + .and().paginationField("count").is("1"); + comments.assertThat().paginationField("skipCount").is("1"); + comments.assertThat().paginationField("totalItems").is("2"); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Add 2 comments with Admin and Collaborator users and verify valid request using maxItems. Check that param is applied") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void addTwoCommentsWithAdminCollaboratorVerifyMaxItemsParamIsApplied() throws Exception + { + file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).addComment(comment); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingResource(file).addComment(comment2); + + comments = restClient.authenticateUser(adminUserModel).withParams("maxItems=1") + .withCoreAPI().usingResource(file).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", comment2) + .and().paginationField("count").is("1"); + comments.assertThat().paginationField("totalItems").is("2"); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Add 2 comments with Manager and Admin users and verify valid request using properties. Check that param is applied") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void addTwoCommentsWithAdminManagerVerifyPropertiesParamIsApplied() throws Exception + { + file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).addComment(comment); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(file).addComment(comment2); + + comments = restClient.authenticateUser(adminUserModel).withParams("properties=createdBy,modifiedBy") + .withCoreAPI().usingResource(file).getNodeComments(); + comments.assertThat().entriesListIsNotEmpty() + .and().paginationField("count").is("2"); + comments.assertThat().paginationField("totalItems").is("2"); + + comments.getEntries().get(0).onModel().getCreatedBy() + .assertThat().field("firstName").is(usersWithRoles.getOneUserWithRole(UserRole.SiteManager).getUsername() + " FirstName") + .assertThat().field("lastName").is("LN-" + usersWithRoles.getOneUserWithRole(UserRole.SiteManager).getUsername()); + + comments.getEntries().get(1).onModel().getCreatedBy() + .assertThat().field("firstName").is("Administrator") + .assertThat().field("id").is("admin"); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Check default error model schema") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void addTwoCommentsWithManagerCheckDefaultErrorModelSchema() throws Exception + { + file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingResource(file).addComments(comment, comment2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).usingParams("maxItems=0").getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS); + restClient.assertLastError().containsErrorKey(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS); + restClient.assertLastError().containsSummary(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS); + restClient.assertLastError().descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + restClient.assertLastError().stackTraceIs(RestErrorModel.STACKTRACE); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/comments/UpdateCommentTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/comments/UpdateCommentTests.java new file mode 100644 index 0000000000..f914edd4a4 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/comments/UpdateCommentTests.java @@ -0,0 +1,460 @@ +package org.alfresco.rest.comments; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestCommentModel; +import org.alfresco.rest.model.RestCommentModelsCollection; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +import org.alfresco.utility.model.FolderModel; +import org.alfresco.utility.model.LinkModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.commons.lang3.RandomStringUtils; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class UpdateCommentTests extends RestTest +{ + private UserModel adminUserModel, networkUserModel; + private FileModel document; + private SiteModel siteModel; + private RestCommentModel commentModel, returnedCommentModel; + private RestCommentModelsCollection comments;; + private ListUserWithRoles usersWithRoles; + private String firstComment = "This is a new comment"; + private String updatedComment = "This is the updated comment"; + + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + adminUserModel = dataUser.getAdminUser(); + restClient.authenticateUser(adminUserModel); + networkUserModel = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); + + document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel,UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.SANITY, description = "Verify Admin user updates comments and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.SANITY }) + public void adminIsAbleToUpdateHisComment() throws Exception + { + restClient.authenticateUser(adminUserModel); + commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment added by admin"); + String updatedContent = "This is the updated comment with admin user"; + restClient.withCoreAPI().usingResource(document).updateComment(commentModel, updatedContent) + .assertThat().field("content").isNotEmpty() + .and().field("content").is(updatedContent); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.SANITY, description = "Verify unauthenticated user gets status code 401 on update comment call") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.SANITY }) +// @Bug(id = "MNT-16904", description = "fails only on environment with tenants") + public void unauthenticatedUserIsNotAbleToUpdateComment() throws Exception + { + restClient.authenticateUser(adminUserModel); + commentModel = restClient.withCoreAPI().usingResource(document).addComment("To be updated by unauthenticated user."); + UserModel incorrectUserModel = new UserModel("userName", "password"); + restClient.authenticateUser(incorrectUserModel) + .withCoreAPI().usingResource(document).updateComment(commentModel, "try to update"); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.SANITY, description = "Verify entry content in response") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.SANITY }) + public void checkEntryContentInResponse() throws Exception + { + restClient.authenticateUser(adminUserModel); + commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment added by admin"); + commentModel = restClient.withCoreAPI().usingResource(document).updateComment(commentModel, "This is the updated comment with admin user"); + restClient.assertStatusCodeIs(HttpStatus.OK); + commentModel.assertThat().field("content").is("This is the updated comment with admin user"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Manager user updates comments created by admin user and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void managerIsAbleToUpdateHisComment() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment added by manager"); + restClient.withCoreAPI().usingResource(document).updateComment(commentModel, "This is the updated comment with Manager user") + .and().field("content").is("This is the updated comment with Manager user") + .and().field("canEdit").is(true) + .and().field("canDelete").is(true); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Contributor user can update his own comment and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void contributorIsAbleToUpdateHisComment() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); + commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment added by contributor"); + String updatedContent = "This is the updated comment with Contributor user"; + restClient.withCoreAPI().usingResource(document).updateComment(commentModel, updatedContent); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Consumer user can not update comments created by admin user and status code is 403") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void consumerIsNotAbleToUpdateComment() throws Exception + { + restClient.authenticateUser(adminUserModel); + commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment added by admin"); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)); + restClient.withCoreAPI().usingResource(document).updateComment(commentModel, "This is the updated comment with Consumer user"); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Collaborator user can update his own comment and status code is 200") +// @Bug(id="REPO-1011") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void collaboratorIsAbleToUpdateHisComment() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); + commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment added by collaborator"); + restClient.withCoreAPI().usingResource(document).updateComment(commentModel, "This is the updated comment with Collaborator user"); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Collaborator user can not update comments of another user and status code is 200") +// @Bug(id="MNT-2502",description="seems it's one old issue: also logged as MNT-2502, MNT-2346") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void collaboratorIsNotAbleToUpdateCommentOfAnotherUser() throws Exception + { + restClient.authenticateUser(adminUserModel); + commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment added by admin"); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .withCoreAPI().usingResource(document).updateComment(commentModel, "This is the updated comment with Collaborator user"); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify update comment with inexistent nodeId returns status code 404") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void canNotUpdateCommentIfNodeIdIsNotSet() throws Exception + { + restClient.authenticateUser(adminUserModel); + + FolderModel content = FolderModel.getRandomFolderModel(); + content.setNodeRef("node ref that does not exist"); + commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment"); + restClient.withCoreAPI().usingResource(content).updateComment(commentModel, "This is the updated comment."); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary("node ref that does not exist was not found"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify if commentId is not set the status code is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void canNotUpdateCommentIfCommentIdIsNotSet() throws Exception + { + restClient.authenticateUser(adminUserModel); + + RestCommentModel comment = new RestCommentModel(); + String id = "comment id that does not exist"; + comment.setId(id); + restClient.withCoreAPI().usingResource(document).updateComment(comment, "This is the updated comment."); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, id)); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify can not update comment if NodeId is neither document or folder and returns status code 405") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void canNotUpdateCommentIfNodeIdIsNeitherDocumentOrFolder() throws Exception + { + FileModel content = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + content = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(adminUserModel); + commentModel = restClient.withCoreAPI().usingResource(content).addComment("This is a new comment"); + + LinkModel link = dataLink.usingAdmin().usingSite(siteModel).createRandomLink(); + content.setNodeRef(link.getNodeRef().replace("workspace://SpacesStore/", "workspace%3A%2F%2FSpacesStore%2F")); + + restClient.withCoreAPI().usingResource(content).updateComment(commentModel, "This is the updated comment."); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, content.getNodeRef())) + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Admin user is not able to update with empty comment body and status code is 400") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void adminIsNotAbleToUpdateWithEmptyCommentBody() throws Exception + { + restClient.authenticateUser(adminUserModel); + commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment added by admin"); + restClient.withCoreAPI().usingResource(document).updateComment(commentModel, ""); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary("An invalid argument was received"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify updated comment by Manager is listed when calling getComments and status code is 200") +// @Bug(id="REPO-1011") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void updatedCommentByManagerIsListed() throws Exception + { + commentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .withCoreAPI().usingResource(document).addComment("This is a new comment added by collaborator"); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI() + .usingResource(document).updateComment(commentModel, "This is the updated comment with Manager user"); + comments = restClient.withCoreAPI().usingResource(document).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", "This is the updated comment with Manager user"); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify Manager user can update a comment with a large string") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void managerIsAbleToUpdateACommentWithALargeString() throws Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + String longString = RandomStringUtils.randomAlphanumeric(10000); + + commentModel = restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingResource(file).addComment(firstComment); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + returnedCommentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingResource(file).updateComment(commentModel, longString); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedCommentModel.assertThat().field("content").is(longString); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify Manager user can update a comment with a short string") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void managerIsAbleToUpdateACommentWithAShortString() throws Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + String shortString = RandomStringUtils.randomAlphanumeric(2); + + commentModel = restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingResource(file).addComment(firstComment); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + returnedCommentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingResource(file).updateComment(commentModel, shortString); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedCommentModel.assertThat().field("content").is(shortString); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify Collaborator user can update a comment with special characters") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void collaboratorIsAbleToUpdateACommentThatContainsSpecialChars() throws Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + String specialChars = "!@#$%^&*()'\".,<>-_+=|\\"; + + commentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .withCoreAPI().usingResource(file).addComment(firstComment); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + returnedCommentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .withCoreAPI().usingResource(file).updateComment(commentModel, specialChars); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedCommentModel.assertThat().field("content").is(specialChars); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Check that you cannot update comment with Consumer then call getComments and check new comment is not listed") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void cannotUpdateCommentWithConsumerCallGetComments() throws Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + + commentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .withCoreAPI().usingResource(file).addComment(firstComment); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI().usingResource(file).updateComment(commentModel, updatedComment); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + + comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", firstComment) + .and().entriesListDoesNotContain("content", updatedComment) + .and().paginationField("totalItems").is("1"); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Update comment with Contributor then call getComments and check new comment is listed") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + @Bug(id = "ACE-4614") + public void updateCommentWithContributorCallGetComments() throws Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + + commentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .withCoreAPI().usingResource(file).addComment(firstComment); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).withCoreAPI().usingResource(file).updateComment(commentModel, updatedComment); + restClient.assertStatusCodeIs(HttpStatus.OK); + + comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", updatedComment) + .and().entriesListDoesNotContain("content", firstComment) + .and().paginationField("totalItems").is("1"); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Update comment with Collaborator then call getComments and check new comment is listed") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void updateCommentWithCollaboratorCallGetComments() throws Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + + commentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .withCoreAPI().usingResource(file).addComment(firstComment); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingResource(file).updateComment(commentModel, updatedComment); + restClient.assertStatusCodeIs(HttpStatus.OK); + + comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", updatedComment) + .and().entriesListDoesNotContain("content", firstComment) + .and().paginationField("totalItems").is("1"); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Update comment with Manager then check modified by information in response") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void updateCommentWithManagerCheckModifiedBy() throws Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + UserModel manager = usersWithRoles.getOneUserWithRole(UserRole.SiteManager); + + commentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .withCoreAPI().usingResource(file).addComment(firstComment); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + returnedCommentModel = restClient.authenticateUser(manager).withCoreAPI().usingResource(file).updateComment(commentModel, updatedComment); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedCommentModel.assertThat().field("modifiedBy.id").is(manager.getUsername()) + .and().field("content").is(updatedComment); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Delete comment with Admin then try to update it") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void deleteCommentThenTryToUpdateIt() throws Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + + commentModel = restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingResource(file).addComment(firstComment); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.withCoreAPI().usingResource(file).deleteComment(commentModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + restClient.withCoreAPI().usingResource(file).updateComment(commentModel, updatedComment); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify Manager user can update a comment with multi byte content") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void managerIsAbleToUpdateACommentWithMultiByteContent() throws Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + String multiByte = "\ufeff\u6768\u6728\u91d1"; + + commentModel = restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingResource(file).addComment(firstComment); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + returnedCommentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingResource(file).updateComment(commentModel, multiByte); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedCommentModel.assertThat().field("content").is(multiByte); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify Admin user can update a comment with properties parameter") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void adminIsAbleToUpdateACommentWithPropertiesParameter() throws Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + + commentModel = restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingResource(file).addComment(firstComment); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + UserModel manager = usersWithRoles.getOneUserWithRole(UserRole.SiteManager); + + returnedCommentModel = restClient.authenticateUser(manager) + .withParams("properties=createdBy,modifiedBy,canEdit,canDelete").withCoreAPI().usingResource(file).updateComment(commentModel, updatedComment); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedCommentModel.assertThat().field("createdBy.id").is(adminUserModel.getUsername()) + .assertThat().field("modifiedBy.id").is(manager.getUsername()) + .assertThat().fieldsCount().is(4); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, + description = "Update comment with invalid node") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void updateCommentUsingInvalidNodeId() throws Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + + commentModel = restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingResource(file).addComment(firstComment); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + file.setNodeRef(RandomStringUtils.randomAlphanumeric(20)); + restClient.withCoreAPI().usingResource(file).updateComment(commentModel, updatedComment); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, file.getNodeRef())); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify update comment from node with invalid network id returns status code 401") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void updateCommentWithInvalidNetworkId() throws Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + + commentModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).addComment(firstComment); + networkUserModel.setDomain("invalidNetwork"); + restClient.authenticateUser(networkUserModel).withCoreAPI().usingResource(file).updateComment(commentModel, updatedComment); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify User can not update comment to a not joined private site. Status code returned is 403") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.REGRESSION }) + public void userCanNotUpdateCommentToANotJoinedPrivateSiteDefaultErrorModelSchema() throws Exception + { + UserModel newUser = dataUser.createRandomTestUser(); + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + + commentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingResource(file).addComment(firstComment); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.authenticateUser(newUser).withCoreAPI().usingResource(file).updateComment(commentModel, updatedComment); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE) + .containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/cors/CORSTest.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/cors/CORSTest.java new file mode 100644 index 0000000000..790e75aab3 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/cors/CORSTest.java @@ -0,0 +1,89 @@ +package org.alfresco.rest.cors; + +import io.restassured.RestAssured; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.testng.annotations.Test; + +public class CORSTest extends RestTest +{ + + @Test(groups = { TestGroup.REST_API, TestGroup.SANITY, TestGroup.CORE}) + public void assertCORSisEnabledAndWorking() + { + // Origin url which should be different from the repository url + String validOriginUrl = "http://localhost:4200"; + String invalidOriginUrl1 = "http://localhost:4201"; + String invalidOriginUrl2 = "http://example.com"; + RestAssured.basePath = "alfresco/api/-default-/public/authentication/versions/1"; + restClient.configureRequestSpec().setBasePath(RestAssured.basePath); + + RestRequest request = RestRequest.simpleRequest(HttpMethod.OPTIONS, "tickets"); + + // Don't specify header Access-Control-Request-Method + restClient.configureRequestSpec().addHeader("Origin", validOriginUrl); + restClient.process(request); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + + // request not allowed method + restClient.configureRequestSpec().addHeader("Access-Control-Request-Method", "PATCH"); + restClient.configureRequestSpec().addHeader("Origin", validOriginUrl); + restClient.process(request); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN); + + // request invalid method + restClient.configureRequestSpec().addHeader("Access-Control-Request-Method", "invalid"); + restClient.configureRequestSpec().addHeader("Origin", validOriginUrl); + restClient.process(request); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN); + + // use invalidOriginUrl1 as origin + restClient.configureRequestSpec().addHeader("Access-Control-Request-Method", "POST"); + restClient.configureRequestSpec().addHeader("Origin", invalidOriginUrl1); + restClient.process(request); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN); + + // use invalidOriginUrl2 as origin + restClient.configureRequestSpec().addHeader("Origin", invalidOriginUrl2); + restClient.process(request); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN); + + // use validOriginUrl + restClient.configureRequestSpec().addHeader("Access-Control-Request-Method", "POST"); + restClient.configureRequestSpec().addHeader("Origin", validOriginUrl); + restClient.process(request); + + restClient.assertStatusCodeIs(HttpStatus.OK); + restClient.assertHeaderValueContains("Access-Control-Allow-Origin", validOriginUrl); + restClient.assertHeaderValueContains("Access-Control-Allow-Credentials", "true"); + restClient.assertHeaderValueContains("Access-Control-Max-Age", "10"); + restClient.assertHeaderValueContains("Access-Control-Allow-Methods", "POST"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SANITY, TestGroup.CORE}) + public void assertCORSisEnabledAndWorkingForDiscovery() + { + // Origin url which should be different from the repository url + String validOriginUrl = "http://localhost:4200"; + RestAssured.basePath = "alfresco/api"; + restClient.configureRequestSpec().setBasePath(RestAssured.basePath); + + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "discovery"); + + // use validOriginUrl + restClient.configureRequestSpec().addHeader("Access-Control-Request-Method", "GET"); + restClient.configureRequestSpec().addHeader("Origin", validOriginUrl); + + UserModel userModel = dataUser.createRandomTestUser(); + restClient.authenticateUser(userModel).process(request); + + restClient.assertStatusCodeIs(HttpStatus.OK); + restClient.assertHeaderValueContains("Access-Control-Allow-Origin", validOriginUrl); + restClient.assertHeaderValueContains("Access-Control-Allow-Credentials", "true"); + restClient.assertHeaderValueContains("Access-Control-Expose-Headers", "Access-Control-Allow-Origin,Access-Control-Allow-Credentials"); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/downloads/DownloadsTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/downloads/DownloadsTests.java new file mode 100644 index 0000000000..9021cd2d50 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/downloads/DownloadsTests.java @@ -0,0 +1,106 @@ +package org.alfresco.rest.downloads; + +import javax.json.JsonObject; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.JsonBodyGenerator; +import org.alfresco.rest.model.RestDownloadsModel; +import org.alfresco.utility.Utility; +import org.alfresco.utility.model.FileModel; +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.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class DownloadsTests extends RestTest +{ + private UserModel adminModel; + private FileModel document, document1; + private FolderModel folder; + private SiteModel siteModel; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminModel = dataUser.getAdminUser(); + siteModel = dataSite.usingUser(adminModel).createPrivateRandomSite(); + folder = dataContent.usingUser(adminModel).usingSite(siteModel).createFolder(); + document = dataContent.usingSite(siteModel).usingUser(adminModel).createContent(DocumentType.TEXT_PLAIN); + + // Create document1 based on existing resource + FileModel newFile = FileModel.getFileModelBasedOnTestDataFile("larger.pdf"); + newFile.setName("larger.pdf"); + document1 = dataContent.usingUser(adminModel).usingResource(folder).createContent(newFile); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.DOWNLOADS, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.DOWNLOADS }, executionType = ExecutionType.SANITY, + description = "Sanity tests for GET /downloads/{downloadId} and POST /downloads") + public void createDownloadNodeAndGetInfo() throws Exception + { + // POST /downloads + JsonObject postBody = JsonBodyGenerator.defineJSON() + .add("nodeIds", JsonBodyGenerator.defineJSONArray().add(document.getNodeRefWithoutVersion())) + .build(); + RestDownloadsModel downloadModel = restClient.authenticateUser(adminModel).withCoreAPI().usingDownloads().createDownload(postBody.toString()); + restClient.assertStatusCodeIs(HttpStatus.ACCEPTED); + downloadModel.assertThat().fieldsCount().is(6).and() + .field("id").isNotEmpty(); + + // GET /downloads/{downloadId} + Utility.sleep(500, 15000, () -> { + RestDownloadsModel downloadModel1 = restClient.authenticateUser(adminModel).withCoreAPI().usingDownloads(downloadModel).getDownload(); + restClient.assertStatusCodeIs(HttpStatus.OK); + + downloadModel1.assertThat().fieldsCount().is(6).and() + .field("id").is(downloadModel.getId()).and() + .field("filesAdded").isGreaterThan(0).and() + .field("bytesAdded").isGreaterThan(0).and() + .field("totalBytes").isGreaterThan(0).and() + .field("totalFiles").isGreaterThan(0).and() + .field("status").is("DONE"); + }); + + // Check that download node has content + restClient.authenticateUser(adminModel).withCoreAPI().usingNode().getNodeContent(downloadModel.getId()); + + restClient.assertStatusCodeIs(HttpStatus.OK); + restClient.assertHeaderValueContains("Content-Type","application/octet-stream;charset=UTF-8"); + restClient.assertHeaderValueContains("Content-disposition",".zip"); + Assert.assertTrue(restClient.onResponse().getResponse().body().asInputStream().available() > 0); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.DOWNLOADS, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.DOWNLOADS }, executionType = ExecutionType.SANITY, + description = "Sanity tests for DELETE /downloads/{downloadId}") + public void cancelDownloadNode() throws Exception + { + // POST /downloads + String postBody = JsonBodyGenerator.defineJSON() + .add("nodeIds", JsonBodyGenerator.defineJSONArray().add(document1.getNodeRefWithoutVersion())) + .build().toString(); + RestDownloadsModel downloadModel = restClient.authenticateUser(adminModel).withCoreAPI().usingDownloads().createDownload(postBody); + + /* + * DELETE /downloads/{downloadId} + * Download canceling is async and it works only if download status is not "DONE" + * To have this case, a large pdf file was used that takes a longer time to download + */ + restClient.authenticateUser(adminModel).withCoreAPI().usingDownloads(downloadModel).cancelDownload(); + restClient.assertStatusCodeIs(HttpStatus.ACCEPTED); + + // GET /downloads/{downloadId} to check that the download is canceled + Utility.sleep(500, 10000, () -> { + RestDownloadsModel downloadModel1 = restClient.authenticateUser(adminModel).withCoreAPI().usingDownloads(downloadModel).getDownload(); + restClient.assertStatusCodeIs(HttpStatus.OK); + downloadModel1.assertThat().field("status").is("CANCELLED"); + }); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/favorites/AddFavoriteSiteTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/favorites/AddFavoriteSiteTests.java new file mode 100644 index 0000000000..18fd34eaf4 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/favorites/AddFavoriteSiteTests.java @@ -0,0 +1,486 @@ +package org.alfresco.rest.favorites; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.model.RestCommentModel; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestFavoriteSiteModel; +import org.alfresco.rest.model.RestPersonFavoritesModel; +import org.alfresco.rest.model.RestPersonFavoritesModelsCollection; +import org.alfresco.rest.model.RestTagModel; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FolderModel; +import org.alfresco.utility.model.LinkModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class AddFavoriteSiteTests extends RestTest +{ + private UserModel userModel, adminUser; + private SiteModel publicSite, privateSite, moderatedSite; + private FileModel document; + private FolderModel folder; + private RestFavoriteSiteModel restFavoriteSiteModel; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + userModel = dataUser.createRandomTestUser(); + + publicSite = dataSite.usingUser(userModel).createPublicRandomSite(); + privateSite = dataSite.usingUser(userModel).createPrivateRandomSite(); + moderatedSite = dataSite.usingUser(userModel).createModeratedRandomSite(); + + document = dataContent.usingSite(publicSite).usingUser(adminUser).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + folder = dataContent.usingSite(publicSite).usingUser(adminUser).createFolder(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, description = "Verify manager user add a favorite site with Rest API and response is successful (201)") + public void managerUserAddFavoriteSiteWithSuccess() throws Exception + { + UserModel managerUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(managerUser, publicSite, UserRole.SiteManager); + + restFavoriteSiteModel = restClient.authenticateUser(managerUser).withCoreAPI().usingUser(managerUser).addFavoriteSite(publicSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restFavoriteSiteModel.assertThat().field("id").is(publicSite.getId()); + + restClient.withCoreAPI().usingUser(managerUser).addFavoriteSite(publicSite); + restClient.assertStatusCodeIs(HttpStatus.CONFLICT); + restClient.assertLastError().containsSummary(String.format("%s is already a favourite site", publicSite.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, description = "Verify a manager user is NOT Authorized to add a favorite site with Rest API when authentication fails (401)") +// @Bug(id="MNT-16904", description = "It fails only on environment with tenants") + public void managerUserNotAuthorizedFailsToAddFavoriteSite() throws Exception + { + UserModel managerUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(managerUser, publicSite, UserRole.SiteManager); + managerUser.setPassword("newpassword"); + + restClient.authenticateUser(managerUser).withCoreAPI().usingAuthUser().addFavoriteSite(publicSite); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION}) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify collaborator user add a favorite site with Rest API and response is successful (201)") + public void collaboratorUserAddFavoriteSiteWithSuccess() throws Exception + { + UserModel collaboratorUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(collaboratorUser, publicSite, UserRole.SiteCollaborator); + + restFavoriteSiteModel = restClient.authenticateUser(collaboratorUser).withCoreAPI().usingAuthUser().addFavoriteSite(publicSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restFavoriteSiteModel.assertThat().field("id").is(publicSite.getId()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION}) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify contributor user add a favorite site with Rest API and response is successful (201)") + public void contributorUserAddFavoriteSiteWithSuccess() throws Exception + { + UserModel contributorUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(contributorUser, publicSite, UserRole.SiteContributor); + + restFavoriteSiteModel = restClient.authenticateUser(contributorUser).withCoreAPI().usingAuthUser().addFavoriteSite(publicSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restFavoriteSiteModel.assertThat().field("id").is(publicSite.getId()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION}) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify consumer user add a favorite site with Rest API and response is successful (201)") + public void consumerUserAddFavoriteSiteWithSuccess() throws Exception + { + UserModel consumerUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(consumerUser, publicSite, UserRole.SiteConsumer); + + restFavoriteSiteModel = restClient.authenticateUser(consumerUser).withCoreAPI().usingAuthUser().addFavoriteSite(publicSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restFavoriteSiteModel.assertThat().field("id").is(publicSite.getId()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION}) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify admin user add a favorite site with Rest API and response is successful (201)") + public void adminUserAddFavoriteSiteWithSuccess() throws Exception + { + restFavoriteSiteModel = restClient.authenticateUser(adminUser).withCoreAPI().usingAuthUser().addFavoriteSite(publicSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restFavoriteSiteModel.assertThat().field("id").is(publicSite.getId()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION}) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify manager user is not able to add a favorite site when the site is already favorite - status code (409)") + public void managerUserAddFavoriteSiteAlreadyAFavoriteSite() throws Exception + { + publicSite = dataSite.usingUser(userModel).createPublicRandomSite(); + UserModel managerUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(managerUser, publicSite, UserRole.SiteManager); + + restClient.authenticateUser(managerUser).withCoreAPI().usingAuthUser().addFavoriteSite(publicSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.withCoreAPI().usingUser(managerUser).addFavoriteSite(publicSite); + restClient.assertStatusCodeIs(HttpStatus.CONFLICT); + restClient.assertLastError() + .containsSummary(String.format("%s is already a favourite site", publicSite.getId())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE) + .containsErrorKey(String.format("Site %s is already a favourite site", publicSite.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION}) + @TestRail(section = { TestGroup.REST_API,TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify user doesn't have permission to delete favorites of admin user with Rest API and status code is 403") + public void userIsNotAbleToAddFavoriteSiteOfAnotherUser() throws Exception + { + publicSite = dataSite.usingUser(userModel).createPublicRandomSite(); + UserModel contributorUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(contributorUser, publicSite, UserRole.SiteContributor); + UserModel consumerUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(consumerUser, publicSite, UserRole.SiteConsumer); + + restClient.authenticateUser(consumerUser).withCoreAPI() + .usingUser(contributorUser).addFavoriteSite(publicSite); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError() + .containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION}) + @TestRail(section = { TestGroup.REST_API,TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify manager user is able to add as favorite a private site.") + public void managerAddsPrivateSiteAsFavorite() throws Exception + { + UserModel managerUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(managerUser, privateSite, UserRole.SiteManager); + + restClient.authenticateUser(managerUser).withCoreAPI().usingUser(managerUser).addFavoriteSite(privateSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + RestPersonFavoritesModelsCollection favorites = restClient.withCoreAPI().usingAuthUser().getFavorites(); + favorites.assertThat().entriesListContains("targetGuid", privateSite.getGuidWithoutVersion()) + .and().paginationField("totalItems").is("1"); + favorites.getOneRandomEntry().onModel().getTarget().getSite() + .assertThat() + .field("description").is(privateSite.getDescription()) + .and().field("id").is(privateSite.getId()) + .and().field("visibility").is(privateSite.getVisibility().toString()) + .and().field("title").is(privateSite.getTitle()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION}) + @TestRail(section = { TestGroup.REST_API,TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify manager user is able to add as favorite a moderated site.") + public void managerAddsModeratedSiteAsFavorite() throws Exception + { + UserModel managerUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(managerUser, moderatedSite, UserRole.SiteManager); + + restClient.authenticateUser(managerUser).withCoreAPI().usingUser(managerUser).addFavoriteSite(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + RestPersonFavoritesModelsCollection favorites = restClient.withCoreAPI().usingAuthUser().getFavorites(); + favorites.assertThat().entriesListContains("targetGuid", moderatedSite.getGuidWithoutVersion()) + .and().paginationField("totalItems").is("1"); + favorites.getOneRandomEntry().onModel().getTarget().getSite() + .assertThat() + .field("description").is(moderatedSite.getDescription()) + .and().field("id").is(moderatedSite.getId()) + .and().field("visibility").is(moderatedSite.getVisibility().toString()) + .and().field("title").is(moderatedSite.getTitle()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION}) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify user removes a site from favorites using '-me-' in place of personId with Rest API and response is successful (201)") + public void addFavoriteSiteWithSuccessUsingMeAsPersonId() throws Exception + { + restClient.authenticateUser(adminUser).withCoreAPI().usingMe().addFavoriteSite(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION}) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify manager user removes a site from its favorites and adds it again and response is successful (204)") + public void managerUserRemovesFavoriteSiteAndAddItAgain() throws Exception + { + UserModel managerUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(managerUser, publicSite, UserRole.SiteManager); + dataSite.usingUser(managerUser).usingSite(publicSite).addSiteToFavorites(); + + restClient.authenticateUser(managerUser).withCoreAPI().usingAuthUser().removeFavoriteSite(publicSite); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + restClient.withCoreAPI().usingUser(managerUser).addSiteToFavorites(publicSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + } + + @Bug(id="ACE-2413") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION}) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify empty user is not able to add a site from favorites and response is (400)") + public void emptyUserIsNotAbleToRemoveFavoriteSite() throws Exception + { + UserModel emptyUser = new UserModel("", "password"); + restClient.authenticateUser(adminUser).withCoreAPI().usingUser(emptyUser).addFavoriteSite(publicSite); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "emptyUser")); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION}) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify inexistent user is not able to add a site from favorites and response is (404)") + public void inexistentUserIsNotAbleToRemoveFavoriteSite() throws Exception + { + UserModel inexistentUser = new UserModel("inexistentUser", "password"); + restClient.authenticateUser(adminUser).withCoreAPI().usingUser(inexistentUser).addFavoriteSite(publicSite); + + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "inexistentUser")) + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Bug(id="REPO-1827") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION}) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify user is not able to add a favorite site when the 'id' is empty - status code (400)") + public void userAddFavoriteSiteWithEmptySiteId() throws Exception + { + publicSite.setId(""); + restClient.authenticateUser(userModel).withCoreAPI().usingAuthUser().addFavoriteSite(publicSite); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST); + restClient.assertLastError() + .containsSummary("siteId is null") + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE) + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION}) + @TestRail(section = { TestGroup.REST_API,TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify admin user doesn't have permission to add a favorite site of another user with Rest API and status code is 403") + public void adminIsNotAbleToAddFavoriteSiteOfAnotherUser() throws Exception + { + UserModel collaboratorUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(collaboratorUser, publicSite, UserRole.SiteCollaborator); + restClient.authenticateUser(collaboratorUser) + .withCoreAPI().usingUser(adminUser).addFavoriteSite(publicSite); + + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError() + .containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @Bug(id="MNT-17338") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION}) + @TestRail(section = { TestGroup.REST_API,TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify admin user doesn't have permission to add a favorite site of another user with Rest API and status code is 403") + public void userIsNotAbleToAddFavoriteSiteOfAdmin() throws Exception + { + UserModel consumerUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(consumerUser, publicSite, UserRole.SiteConsumer); + restClient.authenticateUser(adminUser) + .withCoreAPI().usingUser(consumerUser).addFavoriteSite(publicSite); + + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError() + .containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION}) + @TestRail(section = { TestGroup.REST_API,TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify add favorite site using empty body - status code is 400") + public void addFavoriteSiteWithEmptyBody() throws Exception + { + restClient.authenticateUser(adminUser).withCoreAPI(); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, "{\"ids\": \"local\"}" , + "people/{personId}/favorite-sites", adminUser.getUsername()); + restClient.processModel(RestPersonFavoritesModel.class, request); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsSummary(String.format(RestErrorModel.NO_CONTENT, "Unrecognized field " + "\"ids\"")); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION}) + @TestRail(section = { TestGroup.REST_API,TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify add favorite site using empty body - status code is 400") + public void addFavoriteSiteWithEmptyRequiredFieldsBody() throws Exception + { + restClient.authenticateUser(adminUser).withCoreAPI(); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, "{\"\": \"\"}", + "people/{personId}/favorite-sites", adminUser.getUsername()); + restClient.processModel(RestPersonFavoritesModel.class, request); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsSummary(String.format(RestErrorModel.NO_CONTENT, "Unrecognized field " + "\"\"")); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION}) + @TestRail(section = { TestGroup.REST_API,TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify non member user is not able to add a private favorite site - status code is 404") + public void userAddFavoriteSiteUserNotMemberOfPrivateSite() throws Exception + { + UserModel user = dataUser.usingAdmin().createRandomTestUser(); + restClient.authenticateUser(user).withCoreAPI() + .usingAuthUser().addFavoriteSite(privateSite); + + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, privateSite.getId())) + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION}) + @TestRail(section = { TestGroup.REST_API,TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify non member user is able to add a moderated favorite site") + public void userAddFavoriteSiteUserNotMemberOfModeratedSite() throws Exception + { + UserModel user = dataUser.usingAdmin().createRandomTestUser(); + restClient.authenticateUser(user).withCoreAPI().usingAuthUser() + .addFavoriteSite(moderatedSite); + + RestPersonFavoritesModelsCollection favorites = restClient.withCoreAPI().usingAuthUser().getFavorites(); + favorites.assertThat().entriesListContains("targetGuid", moderatedSite.getGuidWithoutVersion()) + .and().paginationField("totalItems").is("1"); + favorites.getOneRandomEntry().onModel().getTarget().getSite() + .assertThat() + .field("description").is(moderatedSite.getDescription()) + .and().field("id").is(moderatedSite.getId()) + .and().field("visibility").is(moderatedSite.getVisibility().toString()) + .and().field("title").is(moderatedSite.getTitle()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION}) + @TestRail(section = { TestGroup.REST_API,TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify non member user is able to add a public favorite site") + public void userAddFavoriteSiteUserNotMemberOfPublicSite() throws Exception + { + UserModel user = dataUser.usingAdmin().createRandomTestUser(); + restFavoriteSiteModel = restClient.authenticateUser(user).withCoreAPI().usingAuthUser().addFavoriteSite(publicSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restFavoriteSiteModel.assertThat().field("id").is(publicSite.getId()); + + RestPersonFavoritesModelsCollection favorites = restClient.withCoreAPI().usingAuthUser().getFavorites(); + favorites.assertThat().entriesListContains("targetGuid", publicSite.getGuidWithoutVersion()) + .and().paginationField("totalItems").is("1"); + favorites.getOneRandomEntry().onModel().getTarget().getSite() + .assertThat() + .field("description").is(publicSite.getDescription()) + .and().field("id").is(publicSite.getId()) + .and().field("visibility").is(publicSite.getVisibility().toString()) + .and().field("title").is(publicSite.getTitle()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION}) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Check that if id does not exist, status code is 404") + public void addFavoriteSiteUsingInvalidId() throws Exception + { + SiteModel site = dataSite.usingUser(adminUser).createPublicRandomSite(); + String id = publicSite.getId(); + site.setId("invalidID"); + + restClient.authenticateUser(adminUser).withCoreAPI().usingAuthUser().addFavoriteSite(site); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "invalidID")); + + publicSite.setId(id); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION}) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Check that if user provides site in id but id is of a file status code is 404") + public void addSiteToFavoritesUsingFileId() throws Exception + { + String id = publicSite.getId(); + publicSite.setId(document.getNodeRefWithoutVersion()); + + restClient.authenticateUser(adminUser).withCoreAPI().usingAuthUser().addFavoriteSite(publicSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, document.getNodeRefWithoutVersion())); + + publicSite.setId(id); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION}) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Check that if user provides site in id but id is of a folder status code is 404") + public void addSiteToFavoritesUsingFolderId() throws Exception + { + String id = publicSite.getId(); + publicSite.setId(folder.getNodeRefWithoutVersion()); + + restClient.authenticateUser(adminUser).withCoreAPI().usingAuthUser().addFavoriteSite(publicSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, folder.getNodeRefWithoutVersion())); + + publicSite.setId(id); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION}) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Check that if user provides site in id but id is of a comment status code is 404") + public void addSiteToFavoriteUsingCommentId() throws Exception + { + publicSite = dataSite.usingUser(userModel).createPublicRandomSite(); + String id = publicSite.getId(); + FileModel file = dataContent.usingSite(publicSite).usingUser(adminUser).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + RestCommentModel comment = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(file).addComment("This is a comment"); + file.setNodeRef(comment.getId()); + publicSite.setId(comment.getId()); + + restClient.authenticateUser(adminUser).withCoreAPI().usingAuthUser().addFavoriteSite(publicSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND); + publicSite.setId(id); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION}) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Check that if user provides site in id but id is of a tag status code is 404") + public void addSiteFavoriteUsingTagId() throws Exception + { + FileModel file = dataContent.usingSite(publicSite).usingUser(adminUser).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + RestTagModel returnedModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(file).addTag("random_tag"); + file.setNodeRef(returnedModel.getId()); + publicSite.setId(returnedModel.getId()); + + restClient.authenticateUser(adminUser).withCoreAPI().usingAuthUser().addFavoriteSite(publicSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, returnedModel.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION}) + @TestRail(section = { TestGroup.REST_API,TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Check that if id does not describe a site, file, or folder status code is 400") + public void addFavoriteUsingInvalidGuid() throws Exception + { + LinkModel link = dataLink.usingAdmin().usingSite(publicSite).createRandomLink(); + SiteModel site = dataSite.usingUser(adminUser).createPublicRandomSite(); + site.setId(link.getNodeRef()); + + restClient.authenticateUser(adminUser).withCoreAPI().usingAuthUser().addFavoriteSite(site); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, site.getId().split("/")[3])); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/favorites/AddFavoritesTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/favorites/AddFavoritesTests.java new file mode 100644 index 0000000000..4dd5e3e73a --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/favorites/AddFavoritesTests.java @@ -0,0 +1,448 @@ +package org.alfresco.rest.favorites; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.exception.JsonToModelConversionException; +import org.alfresco.rest.model.*; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; +import org.alfresco.utility.model.*; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class AddFavoritesTests extends RestTest +{ + private UserModel adminUserModel; + private SiteModel siteModel; + private ListUserWithRoles usersWithRoles; + private RestPersonFavoritesModel restPersonFavoritesModel; + private FileModel document, document1; + private FolderModel folder, folder1; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUserModel = dataUser.getAdminUser(); + siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); + usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, + UserRole.SiteContributor); + + document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + folder = dataContent.usingSite(siteModel).usingUser(adminUserModel).createFolder(); + document1 = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + folder1 = dataContent.usingSite(siteModel).usingUser(adminUserModel).createFolder(); + } + + // @Bug(id="MNT-16904", description = "It fails only on environment with tenants") + @TestRail(section = { TestGroup.REST_API,TestGroup.FAVORITES }, executionType = ExecutionType.SANITY, + description = "Verify Manager user gets status code 401 if authentication call fails") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.SANITY }) + public void managerIsNotAbleToAddToFavoritesIfAuthenticationFails() throws Exception + { + UserModel siteManager = usersWithRoles.getOneUserWithRole(UserRole.SiteManager); + siteManager.setPassword("wrongPassword"); + restClient.authenticateUser(siteManager).withCoreAPI().usingAuthUser().addSiteToFavorites(siteModel); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify Collaborator user add site to favorites with Rest API and status code is 201") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void collaboratorIsAbleToAddToFavorites() throws Exception + { + restPersonFavoritesModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .withCoreAPI().usingAuthUser().addSiteToFavorites(siteModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restPersonFavoritesModel.and().field("targetGuid").is(siteModel.getGuid()); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify Contributor user add site to favorites with Rest API and status code is 201") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void contributorIsAbleToAddToFavorites() throws JsonToModelConversionException, Exception + { + restPersonFavoritesModel= restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .withCoreAPI().usingAuthUser().addSiteToFavorites(siteModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restPersonFavoritesModel.and().field("targetGuid").is(siteModel.getGuid()); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify Consumer user add site to favorites with Rest API and status code is 201") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void consumerIsAbleToAddToFavorites() throws Exception + { + restPersonFavoritesModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .withCoreAPI().usingAuthUser().addSiteToFavorites(siteModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restPersonFavoritesModel.and().field("targetGuid").is(siteModel.getGuid()); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify Admin user add site to favorites with Rest API and status code is 201") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void adminIsAbleToAddToFavorites() throws Exception + { + restPersonFavoritesModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingAuthUser().addSiteToFavorites(siteModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restPersonFavoritesModel.assertThat().field("targetGuid").is(siteModel.getGuid()); + } + + @Bug(id = "MNT-17157") + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Check that if a favorite already exists with the specified id status code is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void addFavoriteTwice() throws Exception + { + SiteModel site = dataSite.usingUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).createPublicRandomSite(); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingAuthUser().addSiteToFavorites(site); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.withCoreAPI().usingAuthUser().addSiteToFavorites(site); + restClient.assertStatusCodeIs(HttpStatus.CONFLICT); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.SANITY, + description = "Add to favorites a file for a Manager, check it was added") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.SANITY }) + public void managerIsAbleToAddFileToFavorites() throws Exception + { + restPersonFavoritesModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingAuthUser().addFileToFavorites(document); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restPersonFavoritesModel.assertThat().field("targetGuid").is(document.getNodeRefWithoutVersion()); + + RestFileModel restFileModel = restPersonFavoritesModel.getTarget().getFile(); + restFileModel.assertThat().field("mimeType").is("text/plain").and() + .field("isFile").is("true").and() + .field("isFolder").is("false").and() + .field("createdBy").is(adminUserModel.getUsername()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.SANITY, + description = "Add to favorites a folder for a Manager, check it was added") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.SANITY }) + public void managerIsAbleToAddFolderToFavorites() throws Exception + { + restPersonFavoritesModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingAuthUser().addFolderToFavorites(folder); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restPersonFavoritesModel.assertThat().field("targetGuid").is(folder.getNodeRefWithoutVersion()); + + RestFolderModel restFolderModel = restPersonFavoritesModel.getTarget().getFolder(); + restFolderModel.assertThat().field("isFile").is("false").and() + .field("isFolder").is("true").and() + .field("createdBy").is(adminUserModel.getUsername()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.SANITY, + description = "Add to favorites a site for a Manager, check it was added") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.SANITY }) + public void managerIsAbleToAddSiteToFavorites() throws Exception + { + restPersonFavoritesModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingAuthUser().addSiteToFavorites(siteModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restPersonFavoritesModel.assertThat().field("targetGuid").is(siteModel.getGuid()); + + RestSiteModel restSiteModel = restPersonFavoritesModel.getTarget().getSite(); + restSiteModel.assertThat().field("visibility").is(siteModel.getVisibility()).and() + .field("guid").is(siteModel.getGuid()).and() + .field("description").is(siteModel.getDescription()).and() + .field("id").is(siteModel.getId()).and() + .field("title").is(siteModel.getTitle()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify add favorite specifying -me- string in place of for request") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void userIsAbleToAddFavoriteWhenUsingMeAsUsername() throws Exception + { + UserModel user = dataUser.createRandomTestUser(); + restPersonFavoritesModel = restClient.authenticateUser(user) + .withCoreAPI().usingMe().addSiteToFavorites(siteModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restPersonFavoritesModel.assertThat().field("targetGuid").is(siteModel.getGuid()); + + restClient.authenticateUser(user).withCoreAPI().usingAuthUser().getFavoriteSites().assertThat().entriesListContains("guid", siteModel.getGuid()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Add to favorites a file for a Collaborator, check it was added") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void collaboratorIsAbleToAddFileToFavorites() throws Exception + { + restPersonFavoritesModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .withCoreAPI().usingAuthUser().addFileToFavorites(document); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restPersonFavoritesModel.assertThat().field("targetGuid").is(document.getNodeRefWithoutVersion()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Add to favorites a file for a Contributor, check it was added") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void contributorIsAbleToAddFileToFavorites() throws Exception + { + restPersonFavoritesModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .withCoreAPI().usingAuthUser().addFileToFavorites(document); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restPersonFavoritesModel.assertThat().field("targetGuid").is(document.getNodeRefWithoutVersion()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Add to favorites a file for a Consumer, check it was added") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void consumerIsAbleToAddFileToFavorites() throws Exception + { + restPersonFavoritesModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .withCoreAPI().usingAuthUser().addFileToFavorites(document); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restPersonFavoritesModel.assertThat().field("targetGuid").is(document.getNodeRefWithoutVersion()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Add to favorites a folder for a Collaborator, check it was added") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void collaboratorIsAbleToAddFolderToFavorites() throws Exception + { + restPersonFavoritesModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .withCoreAPI().usingUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).addFolderToFavorites(folder); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restPersonFavoritesModel.assertThat().field("targetGuid").is(folder.getNodeRefWithoutVersion()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Add to favorites a folder for a Contributor, check it was added") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void contributorIsAbleToAddFolderToFavorites() throws Exception + { + restPersonFavoritesModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .withCoreAPI().usingAuthUser().addFolderToFavorites(folder); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restPersonFavoritesModel.assertThat().field("targetGuid").is(folder.getNodeRefWithoutVersion()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Add to favorites a folder for a Consumer, check it was added") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void consumerIsAbleToAddFolderToFavorites() throws Exception + { + restPersonFavoritesModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .withCoreAPI().usingUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).addFolderToFavorites(folder); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restPersonFavoritesModel.assertThat().field("targetGuid").is(folder.getNodeRefWithoutVersion()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Add to favorites a site for a Collaborator, check it was added") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void collaboratorIsAbleToAddSiteToFavorites() throws Exception + { + restPersonFavoritesModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .withCoreAPI().usingAuthUser().addSiteToFavorites(siteModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restPersonFavoritesModel.assertThat().field("targetGuid").is(siteModel.getGuid()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Add to favorites a site for a Contributor, check it was added") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void contributorIsAbleToAddSiteToFavorites() throws Exception + { + restPersonFavoritesModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .withCoreAPI().usingAuthUser().addSiteToFavorites(siteModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restPersonFavoritesModel.assertThat().field("targetGuid").is(siteModel.getGuid()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Add to favorites a site for a Consumer, check it was added") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void consumerIsAbleToAddSiteToFavorites() throws Exception + { + restPersonFavoritesModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .withCoreAPI().usingAuthUser().addSiteToFavorites(siteModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restPersonFavoritesModel.assertThat().field("targetGuid").is(siteModel.getGuid()); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Check that if target guid does not describe a site, file, or folder status code is 400") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void addFavoriteUsingInvalidGuid() throws Exception + { + LinkModel link = dataLink.usingAdmin().usingSite(siteModel).createRandomLink(); + SiteModel site = dataSite.usingUser(adminUserModel).createPublicRandomSite(); + site.setGuid(link.getNodeRef()); + + restClient.authenticateUser(adminUserModel).withCoreAPI().usingAuthUser().addSiteToFavorites(site); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, site.getGuid().split("/")[3])); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Check that if personId does not exist, status code is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void addFavoriteUsingInexistentUser() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(new UserModel("random_user", "random_password")).addSiteToFavorites(siteModel); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "random_user")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Check that if target guid does not exist, status code is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void addFavoriteUsingInexistentGuid() throws Exception + { + SiteModel site = dataSite.usingUser(adminUserModel).createPublicRandomSite(); + site.setGuid("random_guid"); + + restClient.authenticateUser(adminUserModel).withCoreAPI().usingAuthUser().addSiteToFavorites(site); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "random_guid")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Check that if user provides file in target but guid is of a folder status code is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void addFileToFavoritesUsingFolderGuid() throws Exception + { + String nodeRef = document.getNodeRef(); + document.setNodeRef(folder.getNodeRef()); + + restClient.authenticateUser(adminUserModel).withCoreAPI().usingAuthUser().addFileToFavorites(document); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, + adminUserModel.getUsername(), folder.getNodeRefWithoutVersion())); + + document.setNodeRef(nodeRef); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify add favorite, perform getFavorites call, check value is updated") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void verifyGetFavoritesAfterFavoritingSite() throws Exception + { + UserModel user = dataUser.createRandomTestUser(); + restPersonFavoritesModel = restClient.authenticateUser(user) + .withCoreAPI().usingAuthUser().addSiteToFavorites(siteModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.authenticateUser(user).withCoreAPI().usingAuthUser().getFavoriteSites() + .assertThat().entriesListContains("guid", siteModel.getGuid()); + } + + // @Bug(id = "MNT-17158", description="Not a bug, If we need to stop comments from being favorited then an improvement/enhancement request should be raised against the platform.") + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify add file favorite with comment id returns status code 201") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void addFileFavoriteUsingCommentId() throws Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + RestCommentModel comment = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).addComment("This is a comment"); + file.setNodeRef(comment.getId()); + + restPersonFavoritesModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingAuthUser().addFileToFavorites(file); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restPersonFavoritesModel.assertThat().field("targetGuid").is(file.getNodeRef()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify add file favorite with tag id returns status code 404") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void addFileFavoriteUsingTagId() throws Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + RestTagModel returnedModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).addTag("random_tag"); + file.setNodeRef(returnedModel.getId()); + + restClient.authenticateUser(adminUserModel).withCoreAPI().usingAuthUser().addFileToFavorites(file); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, + adminUserModel.getUsername(), returnedModel.getId())); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Check that if user provides site in target but id is of a file status code is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void addSiteToFavoritesUsingFileId() throws Exception + { + String guid = siteModel.getGuid(); + siteModel.setGuid(document.getNodeRefWithoutVersion()); + + restClient.authenticateUser(adminUserModel).withCoreAPI().usingAuthUser().addSiteToFavorites(siteModel); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, document.getNodeRefWithoutVersion())); + + siteModel.setGuid(guid); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Check that if user provides folder in target but guid is of a file status code is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void addFolderToFavoritesUsingFileGuid() throws Exception + { + String nodeRef = folder1.getNodeRef(); + folder1.setNodeRef(document1.getNodeRef()); + + restClient.authenticateUser(adminUserModel).withCoreAPI().usingAuthUser().addFolderToFavorites(folder1); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(document1.getNodeRef()); + + folder1.setNodeRef(nodeRef); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Check that if user provides file in target but guid is of a site status code is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void addSiteToFavoritesUsingFolderId() throws Exception + { + SiteModel newSiteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); + newSiteModel.setGuid(folder.getNodeRef()); + + restClient.authenticateUser(adminUserModel).withCoreAPI().usingAuthUser().addSiteToFavorites(newSiteModel); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, folder.getNodeRef())); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Check that if user provides folder in target but guid is of a site status code is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void addFolderToFavoritesUsingSiteId() throws Exception + { + FolderModel newFolder = dataContent.usingSite(siteModel).usingUser(adminUserModel).createFolder(); + newFolder.setNodeRef(siteModel.getGuid()); + + restClient.authenticateUser(adminUserModel).withCoreAPI().usingAuthUser().addFolderToFavorites(newFolder); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, + adminUserModel.getUsername(), siteModel.getGuid())); + } + + @Bug(id = "REPO-1061") + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Check that if user does not have permission to favorite a site status code is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void verifyFavoriteASiteIfTheUserDoesNotHavePermission() throws Exception + { + SiteModel privateSite = dataSite.usingUser(adminUserModel).createPrivateRandomSite(); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingAuthUser().addSiteToFavorites(privateSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, privateSite.getGuid())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .containsErrorKey(RestErrorModel.NOT_FOUND_ERRORKEY) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Bug(id = "REPO-4000") + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify the response of favorite a sie with empty body at request") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void verifyFavoriteASiteWithEmptyBody() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI(); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, "", "people/{personId}/favorites", adminUserModel.getUsername()); + restClient.processModel(RestPersonFavoritesModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(String.format(RestErrorModel.NO_CONTENT, "No content to map due to end-of-input")); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/favorites/DeleteFavoriteSiteTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/favorites/DeleteFavoriteSiteTests.java new file mode 100644 index 0000000000..c00306567b --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/favorites/DeleteFavoriteSiteTests.java @@ -0,0 +1,359 @@ +package org.alfresco.rest.favorites; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * @author Cristina Axinte + */ + +public class DeleteFavoriteSiteTests extends RestTest +{ + private UserModel userModel, adminUserModel; + private SiteModel siteModel1, siteModel2; + private DataUser.ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + userModel = dataUser.createRandomTestUser(); + siteModel1 = dataSite.usingUser(userModel).createPublicRandomSite(); + siteModel2 = dataSite.usingUser(userModel).createPublicRandomSite(); + adminUserModel = dataUser.getAdminUser(); + + usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel1, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, + UserRole.SiteContributor); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, + description = "Verify manager user removes a site from its favorite sites list with Rest API and response is successful (204)") + public void managerUserRemovesFavoriteSiteWithSuccess() throws Exception + { + UserModel managerUser = usersWithRoles.getOneUserWithRole(UserRole.SiteManager); + dataSite.usingUser(managerUser).usingSite(siteModel1).addSiteToFavorites(); + dataSite.usingUser(managerUser).usingSite(siteModel2).addSiteToFavorites(); + + restClient.authenticateUser(managerUser).withCoreAPI().usingAuthUser().removeFavoriteSite(siteModel1); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + restClient.withCoreAPI().usingAuthUser().getFavorites() + .assertThat() + .entriesListDoesNotContain("targetGuid", siteModel1.getGuid()) + .and().entriesListDoesNotContain("id", siteModel1.getId()) + .and().entriesListDoesNotContain("description", siteModel1.getDescription()) + .and().entriesListDoesNotContain("visibility", siteModel1.getVisibility().toString()) + .and().entriesListDoesNotContain("title", siteModel1.getTitle()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, + description = "Verify manager user is NOT Authorized to remove a site from its favorite sites list with Rest API when authentication fails (401)") + public void managerUserNotAuthorizedFailsToRemoveFavoriteSite() throws Exception + { + UserModel managerUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(managerUser, siteModel1, UserRole.SiteManager); + dataSite.usingUser(managerUser).usingSite(siteModel1).addSiteToFavorites(); + dataSite.usingUser(managerUser).usingSite(siteModel2).addSiteToFavorites(); + managerUser.setPassword("newpassword"); + + restClient.authenticateUser(managerUser).withCoreAPI().usingAuthUser().removeFavoriteSite(siteModel1); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify collaborator user removes a site from its favorite sites list with Rest API and response is successful (204)") + public void collaboratorUserRemovesFavoriteSiteWithSuccess() throws Exception + { + UserModel collaboratorUser = usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator); + dataSite.usingUser(collaboratorUser).usingSite(siteModel1).addSiteToFavorites(); + dataSite.usingUser(collaboratorUser).usingSite(siteModel2).addSiteToFavorites(); + + restClient.authenticateUser(collaboratorUser).withCoreAPI().usingAuthUser().removeFavoriteSite(siteModel1); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + restClient.withCoreAPI().usingAuthUser().getFavorites() + .assertThat() + .entriesListDoesNotContain("targetGuid", siteModel1.getGuid()) + .and().entriesListDoesNotContain("id", siteModel1.getId()) + .and().entriesListDoesNotContain("description", siteModel1.getDescription()) + .and().entriesListDoesNotContain("visibility", siteModel1.getVisibility().toString()) + .and().entriesListDoesNotContain("title", siteModel1.getTitle()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify contributor user removes a site from its favorite sites list with Rest API and response is successful (204)") + public void contributorUserRemovesFavoriteSiteWithSuccess() throws Exception + { + UserModel contributorUser = usersWithRoles.getOneUserWithRole(UserRole.SiteContributor); + dataSite.usingUser(contributorUser).usingSite(siteModel1).addSiteToFavorites(); + dataSite.usingUser(contributorUser).usingSite(siteModel2).addSiteToFavorites(); + + restClient.authenticateUser(contributorUser).withCoreAPI().usingAuthUser().removeFavoriteSite(siteModel1); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + restClient.withCoreAPI().usingAuthUser().getFavorites() + .assertThat() + .entriesListDoesNotContain("targetGuid", siteModel1.getGuid()) + .and().entriesListDoesNotContain("id", siteModel1.getId()) + .and().entriesListDoesNotContain("description", siteModel1.getDescription()) + .and().entriesListDoesNotContain("visibility", siteModel1.getVisibility().toString()) + .and().entriesListDoesNotContain("title", siteModel1.getTitle()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify consumer user removes a site from its favorite sites list with Rest API and response is successful (204)") + public void consumerUserRemovesFavoriteSiteWithSuccess() throws Exception + { + UserModel consumerUser = usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer); + dataSite.usingUser(consumerUser).usingSite(siteModel1).addSiteToFavorites(); + dataSite.usingUser(consumerUser).usingSite(siteModel2).addSiteToFavorites(); + + restClient.authenticateUser(consumerUser).withCoreAPI().usingAuthUser().removeFavoriteSite(siteModel1); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + restClient.withCoreAPI().usingAuthUser().getFavorites() + .assertThat() + .entriesListDoesNotContain("targetGuid", siteModel1.getGuid()) + .and().entriesListDoesNotContain("id", siteModel1.getId()) + .and().entriesListDoesNotContain("description", siteModel1.getDescription()) + .and().entriesListDoesNotContain("visibility", siteModel1.getVisibility().toString()) + .and().entriesListDoesNotContain("title", siteModel1.getTitle()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify admin user removes a site from any user's favorite sites list with Rest API and response is successful (204)") + public void adminUserRemovesAnyFavoriteSiteWithSuccess() throws Exception + { + UserModel anyUser = dataUser.usingAdmin().createRandomTestUser(); + dataSite.usingUser(anyUser).usingSite(siteModel1).addSiteToFavorites(); + dataSite.usingUser(anyUser).usingSite(siteModel2).addSiteToFavorites(); + + restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingUser(anyUser).removeFavoriteSite(siteModel1); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE , TestGroup.REGRESSION}) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify a user removes a site from another user's favorite sites list with Rest API and response is permission denied (403)") + public void userCannotRemoveAnotherUserFavoriteSite() throws Exception + { + UserModel userAuth = dataUser.usingAdmin().createRandomTestUser(); + UserModel anotherUser = dataUser.usingAdmin().createRandomTestUser(); + dataSite.usingUser(anotherUser).usingSite(siteModel1).addSiteToFavorites(); + dataSite.usingUser(anotherUser).usingSite(siteModel2).addSiteToFavorites(); + + restClient.authenticateUser(userAuth).withCoreAPI().usingUser(anotherUser).removeFavoriteSite(siteModel1); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError() + .containsSummary(RestErrorModel.PERMISSION_WAS_DENIED) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE) + .containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify uninvited user can delete favorite public site and response is 204") + public void uninvitedUserCanDeleteFavoritePublicSite() throws Exception + { + SiteModel publicSiteModel = dataSite.usingAdmin().createPublicRandomSite(); + restClient.authenticateUser(userModel).withCoreAPI().usingUser(userModel).addFavoriteSite(publicSiteModel); + + restClient.withCoreAPI().usingAuthUser() + .removeFavoriteSite(publicSiteModel); + + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withCoreAPI().usingAuthUser().getFavoriteSites() + .assertThat().entriesListDoesNotContain("id", publicSiteModel.getId()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify uninvited user can delete favorite moderated site and response is 204") + public void uninvitedUserCanDeleteFavoriteModeratedSite() throws Exception + { + SiteModel moderatedSiteModel = dataSite.usingAdmin().createModeratedRandomSite(); + restClient.authenticateUser(userModel).withCoreAPI().usingUser(userModel).addFavoriteSite(moderatedSiteModel); + + restClient.withCoreAPI().usingAuthUser() + .removeFavoriteSite(moderatedSiteModel); + + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withCoreAPI().usingAuthUser().getFavoriteSites() + .assertThat().entriesListDoesNotContain("id", moderatedSiteModel.getId()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify user can delete favorite private site and response is 204") + public void userCanDeleteFavoritePrivateSite() throws Exception + { + SiteModel privateSiteModel = dataSite.usingUser(userModel).createPrivateRandomSite(); + restClient.authenticateUser(userModel).withCoreAPI().usingUser(userModel).addFavoriteSite(privateSiteModel); + + restClient.withCoreAPI().usingAuthUser() + .removeFavoriteSite(privateSiteModel); + + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withCoreAPI().usingAuthUser().getFavoriteSites() + .assertThat().entriesListDoesNotContain("id", privateSiteModel.getId()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify manager user removes a site from its favorites and adds it again and response is successful (204)") + public void managerUserRemovesFavoriteSiteAndAddItAgain() throws Exception + { + UserModel managerUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(managerUser, siteModel1, UserRole.SiteManager); + dataSite.usingUser(managerUser).usingSite(siteModel1).addSiteToFavorites(); + + restClient.authenticateUser(managerUser).withCoreAPI().usingAuthUser() + .removeFavoriteSite(siteModel1); + + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withCoreAPI().usingUser(managerUser).addFavoriteSite(siteModel1); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify user removes a site from favorites using '-me-' in place of personId with Rest API and response is successful (204)") + public void removeFavoriteSiteWithSuccessUsingMeAsPersonId() throws Exception + { + restClient.authenticateUser(adminUserModel); + dataSite.usingUser(adminUserModel).usingSite(siteModel1).addSiteToFavorites(); + + restClient.withCoreAPI().usingMe().removeFavoriteSite(siteModel1); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) +// @Bug(id = "REPO-1642", description = "reproduced on 5.2.1 only, it works on 5.2.0") + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify inexistent user is not able to remove a site from favorites and response is 404") + public void inexistentUserIsNotAbleToRemoveFavoriteSite() throws Exception + { + UserModel inexistentUser = new UserModel("inexistenUser", "password"); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(inexistentUser) + .removeFavoriteSite(siteModel1); + + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "inexistenUser")); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify user is not able to remove from favorites a site with inexistent id and response is 404") + public void userIsNotAbleToRemoveFavoriteSiteWithInexistentId() throws Exception + { + SiteModel inexistentSite = new SiteModel("inexistentSite"); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(adminUserModel) + .removeFavoriteSite(inexistentSite); + + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, + adminUserModel.getUsername(), inexistentSite.getTitle())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE) + .containsErrorKey(RestErrorModel.RELATIONSHIP_NOT_FOUND_ERRORKEY); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "User is not able to remove a favorite site of admin user") + public void userIsNotAbleToDeleteFavoritesOfAdmin() throws Exception + { + UserModel contributor = usersWithRoles.getOneUserWithRole(UserRole.SiteContributor); + dataSite.usingUser(adminUserModel).usingSite(siteModel1).addSiteToFavorites(); + + restClient.authenticateUser(contributor) + .withCoreAPI().usingUser(adminUserModel).removeFavoriteSite(siteModel1); + + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError() + .containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Users removed twice from favorites same site.") + public void managerUserRemovesDeletedFavoriteSite() throws Exception + { + UserModel managerUser = usersWithRoles.getOneUserWithRole(UserRole.SiteManager); + dataSite.usingUser(managerUser).usingSite(siteModel1).addSiteToFavorites(); + + restClient.authenticateUser(managerUser).withCoreAPI().usingAuthUser().removeFavoriteSite(siteModel1); + restClient.authenticateUser(managerUser).withCoreAPI().usingAuthUser().removeFavoriteSite(siteModel1); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsSummary(String.format(RestErrorModel.NOT_FAVOURITE_SITE, siteModel1.getTitle())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Users removes from favorite a site that is already deleted.") + public void consumerUserRemovesDeletedFavoriteSite() throws Exception + { + SiteModel siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); + UserModel consumerUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(consumerUser, siteModel, UserRole.SiteConsumer); + dataSite.usingUser(consumerUser).usingSite(siteModel).addSiteToFavorites(); + + dataSite.usingAdmin().deleteSite(siteModel); + restClient.authenticateUser(consumerUser).withCoreAPI().usingAuthUser().removeFavoriteSite(siteModel); + + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, + consumerUser.getUsername(), siteModel.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Delete favorite site that is NOT favorite.") + public void adminUserRemovesDeletedFavoriteSiteThatIsNotFavorite() throws Exception + { + SiteModel siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingAuthUser().removeFavoriteSite(siteModel); + + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsSummary(String.format(RestErrorModel.NOT_FAVOURITE_SITE, siteModel.getTitle())); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify user doesn't have permission to delete favorites of another user with Rest API and status code is 403") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void siteMemberIsNotAbleToDeleteFavoritesOfAnotherSiteMember() throws Exception + { + UserModel siteCollaborator = usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator); + dataSite.usingUser(siteCollaborator).usingSite(siteModel1).addSiteToFavorites(); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .withCoreAPI() + .usingUser(siteCollaborator) + .removeFavoriteSite(siteModel1); + + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError() + .containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/favorites/DeleteFavoriteTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/favorites/DeleteFavoriteTests.java new file mode 100644 index 0000000000..0fe571cf24 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/favorites/DeleteFavoriteTests.java @@ -0,0 +1,406 @@ +package org.alfresco.rest.favorites; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; +import org.alfresco.utility.model.FileModel; +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.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class DeleteFavoriteTests extends RestTest +{ + private UserModel adminUserModel; + private SiteModel siteModel; + private ListUserWithRoles usersWithRoles; + private FileModel fileModel; + private FolderModel folderModel; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUserModel = dataUser.getAdminUser(); + + siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); + siteModel.setGuid(restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(siteModel).getSite().getGuid()); + + fileModel = dataContent.usingUser(adminUserModel).usingSite(siteModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + folderModel = dataContent.usingSite(siteModel).usingUser(adminUserModel).createFolder(); + + usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, + UserRole.SiteContributor); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.SANITY, + description = "Verify Manager user deletes site from favorites with Rest API and status code is 204") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.SANITY }) + public void managerIsAbleToDeleteFavorites() throws Exception + { + UserModel siteManager = usersWithRoles.getOneUserWithRole(UserRole.SiteManager); + restClient.authenticateUser(siteManager).withCoreAPI().usingAuthUser().addSiteToFavorites(siteModel); + + restClient.withCoreAPI().usingAuthUser().deleteSiteFromFavorites(siteModel).assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withCoreAPI().usingAuthUser().getFavorites() + .assertThat() + .entriesListDoesNotContain("targetGuid", siteModel.getGuid()) + .and().entriesListDoesNotContain("id", siteModel.getId()) + .and().entriesListDoesNotContain("description", siteModel.getDescription()) + .and().entriesListDoesNotContain("visibility", siteModel.getVisibility().toString()) + .and().entriesListDoesNotContain("title", siteModel.getTitle()); + } + + // @Bug(id = "MNT-16904", description = "It fails only on environment with tenants") + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.SANITY, + description = "Verify user gets status code 401 if authentication call fails") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.SANITY }) + public void userIsNotAbleToDeleteFavoritesIfAuthenticationFails() throws Exception + { + UserModel siteManager = usersWithRoles.getOneUserWithRole(UserRole.SiteManager); + siteManager.setPassword("wrongPassword"); + restClient.authenticateUser(siteManager).withCoreAPI().usingAuthUser() + .deleteSiteFromFavorites(siteModel).assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify Collaborator user deletes site from favorites with Rest API and status code is 204") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void collaboratorIsAbleToDeleteFavorites() throws Exception + { + UserModel siteCollaborator = usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator); + restClient.authenticateUser(siteCollaborator).withCoreAPI().usingAuthUser().addSiteToFavorites(siteModel); + + restClient.withCoreAPI().usingAuthUser().deleteSiteFromFavorites(siteModel).assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withCoreAPI().usingAuthUser().getFavorites() + .assertThat() + .entriesListDoesNotContain("targetGuid", siteModel.getGuid()) + .and().entriesListDoesNotContain("id", siteModel.getId()) + .and().entriesListDoesNotContain("description", siteModel.getDescription()) + .and().entriesListDoesNotContain("visibility", siteModel.getVisibility().toString()) + .and().entriesListDoesNotContain("title", siteModel.getTitle()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify Contributor user deletes site from favorites with Rest API and status code is 204") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void contributorIsAbleToDeleteFavorites() throws Exception + { + UserModel siteContributor = usersWithRoles.getOneUserWithRole(UserRole.SiteContributor); + restClient.authenticateUser(siteContributor).withCoreAPI().usingAuthUser().addSiteToFavorites(siteModel); + + restClient.withCoreAPI().usingAuthUser().deleteSiteFromFavorites(siteModel).assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withCoreAPI().usingAuthUser().getFavorites() + .assertThat() + .entriesListDoesNotContain("targetGuid", siteModel.getGuid()) + .and().entriesListDoesNotContain("id", siteModel.getId()) + .and().entriesListDoesNotContain("description", siteModel.getDescription()) + .and().entriesListDoesNotContain("visibility", siteModel.getVisibility().toString()) + .and().entriesListDoesNotContain("title", siteModel.getTitle()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify Consumer user delets site from favorites with Rest API and status code is 204") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void consumerIsAbleToDeleteFavorites() throws Exception + { + UserModel siteConsumer = usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer); + restClient.authenticateUser(siteConsumer).withCoreAPI().usingAuthUser().addSiteToFavorites(siteModel); + + restClient.withCoreAPI().usingAuthUser().deleteSiteFromFavorites(siteModel).assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withCoreAPI().usingAuthUser().getFavorites() + .assertThat() + .entriesListDoesNotContain("targetGuid", siteModel.getGuid()) + .and().entriesListDoesNotContain("id", siteModel.getId()) + .and().entriesListDoesNotContain("description", siteModel.getDescription()) + .and().entriesListDoesNotContain("visibility", siteModel.getVisibility().toString()) + .and().entriesListDoesNotContain("title", siteModel.getTitle()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify Admin user deletes site from favorites with Rest API and status code is 204") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void adminIsAbleToDeleteFavorites() throws Exception + { + restClient.withCoreAPI().usingUser(adminUserModel).addSiteToFavorites(siteModel); + + restClient.withCoreAPI().usingAuthUser().deleteSiteFromFavorites(siteModel).assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withCoreAPI().usingAuthUser().getFavorites().assertThat().entriesListDoesNotContain("targetGuid", siteModel.getGuid()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify admin deletes files from favorites with Rest API and status code is (204)") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void adminIsAbleToDeleteFavoriteFile() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingAuthUser().addFileToFavorites(fileModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.withCoreAPI().usingAuthUser().deleteFileFromFavorites(fileModel).assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withCoreAPI().usingAuthUser().getFavorites() + .assertThat() + .entriesListDoesNotContain("targetGuid", fileModel.getNodeRefWithoutVersion()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify admin deletes folder from favorites with Rest API and status code is (204)") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void adminIsAbleToDeleteFavoriteFolder() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingAuthUser().addFolderToFavorites(folderModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.withCoreAPI().usingAuthUser().deleteFolderFromFavorites(folderModel) + .assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withCoreAPI().usingAuthUser().getFavorites() + .assertThat() + .entriesListDoesNotContain("targetGuid", fileModel.getNodeRefWithoutVersion()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user removes a site from favorites using '-me-' in place of personId with Rest API and response is successful (204)") + public void deleteFavoriteSiteWithSuccessUsingMeAsPersonId() throws Exception + { + siteModel.setGuid(restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(siteModel).getSite().getGuid()); + restClient.withCoreAPI().usingUser(adminUserModel).addSiteToFavorites(siteModel); + + restClient.withCoreAPI().usingMe().deleteSiteFromFavorites(siteModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + } + + @Bug(id="ACE-5588") + @TestRail(section = { TestGroup.REST_API,TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user doesn't have permission to delete favorites of admin user with Rest API and status code is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void userIsNotAbleToDeleteFavoritesOfAdminUser() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingAuthUser().addSiteToFavorites(siteModel); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .withCoreAPI().usingAuthUser().deleteSiteFromFavorites(siteModel) + .assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @Bug(id="ACE-5588") + @TestRail(section = { TestGroup.REST_API,TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify admin user doesn't have permission to delete favorites of another user with Rest API and status code is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void adminIsNotAbleToDeleteFavoritesOfASiteMember() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .withCoreAPI().usingAuthUser().addSiteToFavorites(siteModel); + + restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingAuthUser().deleteSiteFromFavorites(siteModel) + .assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError() + .containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @Bug(id="ACE-5588") + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user doesn't have permission to delete favorites of another user with Rest API and status code is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void consumerIsNotAbleToDeleteFavoritesOfAnotherUser() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI() + .usingAuthUser().addSiteToFavorites(siteModel); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI() + .usingAuthUser().deleteSiteFromFavorites(siteModel) + .assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @Bug(id="ACE-5588") + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify consumer user doesn't have permission to delete favorites of another user with Rest API and status code is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void collaboratorIsNotAbleToDeleteFavoriteOfAnotherUser() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI() + .usingAuthUser().addSiteToFavorites(siteModel); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI() + .usingAuthUser().deleteSiteFromFavorites(siteModel) + .assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError() + .containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @Bug(id="ACE-5588") + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify contributor user doesn't have permission to delete favorites of another user with Rest API and status code is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void contributorIsNotAbleToDeleteFavoriteOfAnotherUser() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI() + .usingAuthUser().addSiteToFavorites(siteModel); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).withCoreAPI() + .usingAuthUser().deleteSiteFromFavorites(siteModel) + .assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError() + .containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @Bug(id="ACE-5588") + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify contributor user doesn't have permission to delete favorites of another user with Rest API and status code is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void adminIsNotAbleToDeleteFavoriteOfAnotherUser() throws Exception + { + UserModel user = dataUser.createRandomTestUser(); + restClient.authenticateUser(user).withCoreAPI().usingAuthUser().addSiteToFavorites(siteModel); + + restClient.authenticateUser(adminUserModel).withCoreAPI() + .usingAuthUser().deleteSiteFromFavorites(siteModel) + .assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError() + .containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that status code is 404 if PersonID is incorrect - favorite file.") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION}) + public void deleteFavoriteIfPersonIdNotExists() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(adminUserModel).addSiteToFavorites(siteModel); + restClient.withCoreAPI().usingAuthUser().addFileToFavorites(fileModel); + + restClient.withCoreAPI().usingUser(new UserModel("inexistent", "inexistent")) + .deleteFileFromFavorites(fileModel).assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "inexistent")); + } + + @Bug(id="ACE-2413") + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that status code is 404 if PersonID is empty - favorite file.") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION}) + public void deleteFavoriteIfPersonIdIsEmpty() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(adminUserModel).addSiteToFavorites(siteModel); + restClient.withCoreAPI().usingAuthUser().addFileToFavorites(fileModel); + + restClient.withCoreAPI().usingUser(new UserModel ("", "")) + .deleteFileFromFavorites(fileModel).assertStatusCodeIs(HttpStatus.BAD_REQUEST); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that status code is 404 if FavoriteID is incorrect - favorite file.") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION}) + public void deleteFavoriteFileIfFavoriteIdIsIncorrect() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingAuthUser().addFileToFavorites(fileModel); + + fileModel.setNodeRef("wrongFavoriteId"); + restClient.withCoreAPI().usingAuthUser() + .deleteFileFromFavorites(fileModel).assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "wrongFavoriteId")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that status code is 404 if FavoriteID is incorrect - favorite file.") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION}) + public void deleteFavoriteFileIfFavoriteIdNotExists() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingAuthUser().addFileToFavorites(fileModel); + FileModel inexistentDocument = new FileModel(); + inexistentDocument.setNodeRef("inexistent"); + + restClient.withCoreAPI().usingAuthUser() + .deleteFileFromFavorites(inexistentDocument).assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "inexistent")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that status code is 404 if FavoriteID is incorrect - favorite site.") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION}) + public void deleteFavoriteSiteIfFavoriteIdNotExists() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(adminUserModel).addSiteToFavorites(siteModel); + siteModel.setGuid("wrongFavoriteId"); + + restClient.withCoreAPI().usingAuthUser() + .deleteSiteFromFavorites(siteModel).assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "wrongFavoriteId")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that status code is 404 if FavoriteID is incorrect - favorite folder.") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION}) + public void deleteFavoriteFolderIfFavoriteIdNotExists() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(adminUserModel).addSiteToFavorites(siteModel); + restClient.withCoreAPI().usingAuthUser().addFolderToFavorites(folderModel); + + folderModel.setNodeRef("wrongFavoriteId"); + restClient.withCoreAPI().usingAuthUser() + .deleteFolderFromFavorites(folderModel).assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "wrongFavoriteId")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify admin is not able to deletes files from favorites that were already deleted with Rest API and status code is (404)") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void adminIsNotAbleToDeleteADeletedFavoriteFile() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingAuthUser().addFileToFavorites(fileModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.withCoreAPI().usingAuthUser().deleteFileFromFavorites(fileModel).assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withCoreAPI().usingAuthUser().getFavorites() + .assertThat() + .entriesListDoesNotContain("targetGuid", fileModel.getNodeRefWithoutVersion()); + + restClient.withCoreAPI().usingAuthUser().deleteFileFromFavorites(fileModel) + .assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, + adminUserModel.getUsername(), fileModel.getNodeRef())); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user can't delete favorites using an invalid network ID.") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void userIsNotAbleToDeleteFavoriteSiteWithInvalidNetworkID() throws Exception + { + UserModel networkUserModel = dataUser.createRandomTestUser(); + restClient.authenticateUser(networkUserModel).withCoreAPI().usingAuthUser().addSiteToFavorites(siteModel); + networkUserModel.setDomain("invalidNetwork"); + + restClient.withCoreAPI() + .usingAuthUser().deleteSiteFromFavorites(siteModel) + .assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify contributor user doesn't have permission to delete favorites of another user with Rest API and status code is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void adminDeletesFavoriteForNotFavouriteFile() throws Exception + { + fileModel = dataContent.usingSite(siteModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(adminUserModel).withCoreAPI().usingAuthUser() + .deleteFileFromFavorites(fileModel) + .assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, + adminUserModel.getUsername(), fileModel.getNodeRef())) + .containsErrorKey(RestErrorModel.RELATIONSHIP_NOT_FOUND_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/favorites/FavoritesIncludePathTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/favorites/FavoritesIncludePathTests.java new file mode 100644 index 0000000000..dcbba231f7 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/favorites/FavoritesIncludePathTests.java @@ -0,0 +1,143 @@ +package org.alfresco.rest.favorites; + +import static org.alfresco.utility.report.log.Step.STEP; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.utility.model.FileModel; +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.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Class includes Sanity tests for the favorites api. Detailed tests would be covered in the alfresco-remote-api test project + * + * @author meenal bhave + */ +public class FavoritesIncludePathTests extends RestTest +{ + private UserModel adminUser; + private UserModel testUser1; + + private SiteModel siteModel1; + + private FolderModel folder1; + + private FileModel file1; + + private FolderModel subFolder1; + private FileModel fileInSubFolder; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + restClient.authenticateUser(adminUser); + + // Create Standard User + testUser1 = dataUser.usingUser(adminUser).createRandomTestUser(); + + // Create Site + siteModel1 = dataSite.usingUser(testUser1).createPublicRandomSite(); + + folder1 = dataContent.usingUser(adminUser).usingSite(siteModel1).createFolder(); + subFolder1 = dataContent.usingUser(adminUser).usingResource(folder1).createFolder(); + file1 = dataContent.usingUser(adminUser).usingResource(folder1).createContent(DocumentType.TEXT_PLAIN); + fileInSubFolder = dataContent.usingUser(adminUser).usingResource(subFolder1).createContent(DocumentType.TEXT_PLAIN); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, description = "Verify that get favorite site request does not include Path") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION}) + public void testGetFavoriteIncludePathForSite() throws Exception + { + restClient.authenticateUser(testUser1).withCoreAPI().usingAuthUser().includePath().getFavorite(siteModel1.getGuid()); + restClient.assertStatusCodeIs(HttpStatus.OK); + restClient.onResponse().assertThat().body("entry.target.site.id", org.hamcrest.Matchers.equalTo(siteModel1.getId()));//(org.hamcrest.Matchers.nullValue())); + restClient.onResponse().assertThat().body("entry.target.site.path", org.hamcrest.Matchers.is(org.hamcrest.Matchers.nullValue())); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, description = "Verify that get favorite file or folder request includes path when requested") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION}) + public void testGetFavouriteIncludePathForFileFolder() throws Exception + { + STEP("1. Favourite Folder and File"); + restClient.authenticateUser(testUser1).withCoreAPI().usingAuthUser().addFolderToFavorites(folder1); + restClient.authenticateUser(testUser1).withCoreAPI().usingAuthUser().addFileToFavorites(file1); + + STEP("2. Check Path for Folder: Displayed when requested"); + restClient.authenticateUser(testUser1).withCoreAPI().usingAuthUser().includePath().getFavorite(folder1.getNodeRefWithoutVersion()); + restClient.assertStatusCodeIs(HttpStatus.OK); + restClient.onResponse().assertThat().body("entry.target.folder.id", org.hamcrest.Matchers.equalTo(folder1.getNodeRefWithoutVersion())); + restClient.onResponse().assertThat().body("entry.target.folder.path", org.hamcrest.Matchers.notNullValue()); + + STEP("3. Check Path for file: Displayed when requested"); + restClient.authenticateUser(testUser1).withCoreAPI().usingAuthUser().includePath().getFavorite(file1.getNodeRefWithoutVersion()); + restClient.assertStatusCodeIs(HttpStatus.OK); + restClient.onResponse().assertThat().body("entry.target.file.id", org.hamcrest.Matchers.equalTo(file1.getNodeRefWithoutVersion())); + restClient.onResponse().assertThat().body("entry.target.file.path", org.hamcrest.Matchers.notNullValue()); + + STEP("4. Check Path for Folder: Not Displayed when not requested"); + restClient.authenticateUser(testUser1).withCoreAPI().usingAuthUser().getFavorite(folder1.getNodeRefWithoutVersion()); + restClient.assertStatusCodeIs(HttpStatus.OK); + restClient.onResponse().assertThat().body("entry.target.folder.id", org.hamcrest.Matchers.equalTo(folder1.getNodeRefWithoutVersion())); + restClient.onResponse().assertThat().body("entry.target.folder.path", org.hamcrest.Matchers.nullValue()); + + STEP("5. Check Path for file: Not Displayed when not requested"); + restClient.authenticateUser(testUser1).withCoreAPI().usingAuthUser().getFavorite(file1.getNodeRefWithoutVersion()); + restClient.assertStatusCodeIs(HttpStatus.OK); + restClient.onResponse().assertThat().body("entry.target.file.id", org.hamcrest.Matchers.equalTo(file1.getNodeRefWithoutVersion())); + restClient.onResponse().assertThat().body("entry.target.file.path", org.hamcrest.Matchers.nullValue()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, description = "Verify path in get favorites") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION}) + public void testGetFavouritesIncludePath() throws Exception + { + STEP("1. Favourite Folder and File"); + restClient.authenticateUser(testUser1).withCoreAPI().usingAuthUser().addFolderToFavorites(folder1); + restClient.authenticateUser(testUser1).withCoreAPI().usingAuthUser().addFileToFavorites(file1); + + STEP("2. Check Path: Displayed when appropriate"); + restClient.authenticateUser(testUser1).withCoreAPI().usingAuthUser().includePath().getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + // Folder + restClient.onResponse().assertThat().body("list.entries.entry.target.folder.id", org.hamcrest.Matchers.contains(folder1.getNodeRefWithoutVersion())); + restClient.onResponse().assertThat().body("list.entries.entry.target.folder.path", org.hamcrest.Matchers.notNullValue()); + // File + restClient.onResponse().assertThat().body("list.entries.entry.target.file.id", org.hamcrest.Matchers.contains(file1.getNodeRefWithoutVersion())); + restClient.onResponse().assertThat().body("list.entries.entry.target.file.path", org.hamcrest.Matchers.notNullValue()); + // Site + restClient.onResponse().assertThat().body("list.entries.entry.target.site.id", org.hamcrest.Matchers.contains(siteModel1.getId())); + restClient.onResponse().assertThat().body("list.entries.entry.target.site.path", org.hamcrest.Matchers.contains(org.hamcrest.Matchers.nullValue())); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, description = "Verify path in post favorites") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION}) + public void testPostFavouritesIncludePath() throws Exception + { + STEP("1. Favourite Site"); + restClient.authenticateUser(testUser1).withCoreAPI().usingAuthUser().deleteSiteFromFavorites(siteModel1); + restClient.authenticateUser(testUser1).withCoreAPI().usingAuthUser().usingParams("include=path").addFavoriteSite(siteModel1); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.onResponse().assertThat().body("entry.id", org.hamcrest.Matchers.equalTo(siteModel1.getId())); + restClient.onResponse().assertThat().body("entry.path", org.hamcrest.Matchers.nullValue()); + + STEP("2. Favourite Folder"); + restClient.authenticateUser(testUser1).withCoreAPI().usingAuthUser().usingParams("include=path").addFolderToFavorites(subFolder1); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.onResponse().assertThat().body("entry.target.folder.id", org.hamcrest.Matchers.equalTo(subFolder1.getNodeRefWithoutVersion())); + restClient.onResponse().assertThat().body("entry.target.folder.path", org.hamcrest.Matchers.notNullValue()); + + STEP("3. Favourite File"); + restClient.authenticateUser(testUser1).withCoreAPI().usingAuthUser().includePath().addFileToFavorites(fileInSubFolder); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.onResponse().assertThat().body("entry.target.file.id", org.hamcrest.Matchers.equalTo(fileInSubFolder.getNodeRefWithoutVersion())); + restClient.onResponse().assertThat().body("entry.target.file.path", org.hamcrest.Matchers.notNullValue()); + } +} \ No newline at end of file diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/favorites/GetFavoriteSiteTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/favorites/GetFavoriteSiteTests.java new file mode 100644 index 0000000000..72e702ec88 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/favorites/GetFavoriteSiteTests.java @@ -0,0 +1,289 @@ +package org.alfresco.rest.favorites; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.dataprep.SiteService; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestSiteModel; +import org.alfresco.rest.model.RestSiteModelsCollection; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.FileModel; +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.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Tests for Get Favorite Sites (/people/{personId}/preferences) RestAPI call + * + * @author Cristina Axinte + */ + +public class GetFavoriteSiteTests extends RestTest +{ + private UserModel userModel; + private SiteModel siteModel1; + private SiteModel siteModel2; + private RestSiteModel restSiteModel; + private DataUser.ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + userModel = dataUser.createRandomTestUser(); + siteModel1 = dataSite.usingUser(userModel).createPublicRandomSite(); + siteModel2 = dataSite.usingUser(userModel).createPublicRandomSite(); + + usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel1, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, + UserRole.SiteContributor); + + dataSite.usingUser(userModel).usingSite(siteModel1).addSiteToFavorites(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, description = "Verify manager user gets its specific favorite site with Rest API and response is successful (200)") + public void managerUserGetsFavoriteSiteWithSuccess() throws Exception + { + UserModel managerUser = usersWithRoles.getOneUserWithRole(UserRole.SiteManager); + + dataSite.usingUser(managerUser).usingSite(siteModel1).addSiteToFavorites(); + dataSite.usingUser(managerUser).usingSite(siteModel2).addSiteToFavorites(); + + restSiteModel = restClient.authenticateUser(managerUser).withCoreAPI().usingAuthUser().getFavoriteSite(siteModel1); + restClient.assertStatusCodeIs(HttpStatus.OK); + restSiteModel.assertThat().field("id").is(siteModel1.getId()).and().field("title").isNotNull(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify collaborator user gets its specific favorite site with Rest API and response is successful (200)") + public void collaboratorUserGetsFavoriteSiteWithSuccess() throws Exception + { + UserModel collaboratorUser = usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator); + + dataSite.usingUser(collaboratorUser).usingSite(siteModel1).addSiteToFavorites(); + dataSite.usingUser(collaboratorUser).usingSite(siteModel2).addSiteToFavorites(); + + restSiteModel = restClient.authenticateUser(collaboratorUser).withCoreAPI().usingAuthUser().getFavoriteSite(siteModel1); + restClient.assertStatusCodeIs(HttpStatus.OK); + restSiteModel.assertThat().field("id").is(siteModel1.getId()).and().field("title").isNotNull(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify contributor user gets its specific favorite site with Rest API and response is successful (200)") + public void contributorUserGetsFavoriteSiteWithSuccess() throws Exception + { + UserModel contributorUser = usersWithRoles.getOneUserWithRole(UserRole.SiteContributor); + + dataSite.usingUser(contributorUser).usingSite(siteModel1).addSiteToFavorites(); + dataSite.usingUser(contributorUser).usingSite(siteModel2).addSiteToFavorites(); + + restSiteModel = restClient.authenticateUser(contributorUser).withCoreAPI().usingAuthUser().getFavoriteSite(siteModel1); + restClient.assertStatusCodeIs(HttpStatus.OK); + restSiteModel.assertThat().field("id").is(siteModel1.getId()).and().field("title").isNotNull(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify consumer user gets its specific favorite site with Rest API and response is successful (200)") + public void consumerUserGetsFavoriteSiteWithSuccess() throws Exception + { + UserModel consumerUser = usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer); + + dataSite.usingUser(consumerUser).usingSite(siteModel1).addSiteToFavorites(); + dataSite.usingUser(consumerUser).usingSite(siteModel2).addSiteToFavorites(); + + restSiteModel = restClient.authenticateUser(consumerUser).withCoreAPI().usingAuthUser().getFavoriteSite(siteModel1); + restClient.assertStatusCodeIs(HttpStatus.OK); + restSiteModel.assertThat().field("id").is(siteModel1.getId()).and().field("title").isNotNull(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify admin user gets specific favorite site of any user with Rest API and response is successful (200)") + public void adminUserGetsAnyFavoriteSiteWithSuccess() throws Exception + { + UserModel adminUser = dataUser.getAdminUser(); + UserModel anyUser = dataUser.usingAdmin().createRandomTestUser(); + dataSite.usingUser(anyUser).usingSite(siteModel1).addSiteToFavorites(); + dataSite.usingUser(anyUser).usingSite(siteModel2).addSiteToFavorites(); + + restSiteModel = restClient.authenticateUser(adminUser).withCoreAPI().usingUser(anyUser).getFavoriteSite(siteModel1); + restClient.assertStatusCodeIs(HttpStatus.OK); + restSiteModel.assertThat().field("id").is(siteModel1.getId()).and().field("title").isNotNull(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify manager user fails to get specific favorite site of another user with Rest API and response is successful (403)") + public void managerUserFailsToGetFavoriteSiteOfAnotherUser() throws Exception + { + UserModel managerUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(managerUser, siteModel1, UserRole.SiteManager); + dataSite.usingUser(managerUser).usingSite(siteModel1).addSiteToFavorites(); + dataSite.usingUser(managerUser).usingSite(siteModel2).addSiteToFavorites(); + + restClient.authenticateUser(managerUser).withCoreAPI().usingUser(userModel).getFavoriteSite(siteModel1); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, description = "Verify manager user is NOT Authorized gets its specific favorite site with Rest API when authentication fails (401)") +// @Bug(id="MNT-16904", description = "It fails only on environment with tenants") + public void managerUserNotAuthorizedFailsToGetFavoriteSite() throws Exception + { + UserModel managerUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(managerUser, siteModel1, UserRole.SiteManager); + dataSite.usingUser(managerUser).usingSite(siteModel1).addSiteToFavorites(); + dataSite.usingUser(managerUser).usingSite(siteModel2).addSiteToFavorites(); + managerUser.setPassword("newpassword"); + + restClient.authenticateUser(managerUser).withCoreAPI().usingAuthUser().getFavoriteSite(siteModel1); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify invalid request returns status 404 when personId does not exist") + public void getFavoriteSiteWithNonExistentPersonId() throws Exception + { + UserModel someUser = new UserModel("someUser", DataUser.PASSWORD); + + restClient.authenticateUser(userModel).withCoreAPI().usingUser(someUser).getFavoriteSite(siteModel1); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "someUser")); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify invalid request returns status 404 when siteId does not exist") + public void getFavoriteSiteWithNonExistentSiteId() throws Exception + { + SiteModel nonExistentSite = new SiteModel("nonExistentSite"); + + restClient.authenticateUser(userModel).withCoreAPI().usingAuthUser().getFavoriteSite(nonExistentSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, userModel.getUsername(), nonExistentSite.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify User fails to get specific favorite site of admin with Rest API and response is 403") + public void userFailsToGetFavoriteSiteOfAdmin() throws Exception + { + restClient.authenticateUser(userModel).withCoreAPI().usingUser(dataUser.getAdminUser()).getFavoriteSite(siteModel1); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify request with empty site id") + public void getFavoriteSiteWithEmptySiteId() throws Exception + { + restClient.authenticateUser(userModel).withCoreAPI(); + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "people/{personId}/favorite-sites/{siteId}?{parameters}", + userModel.getUsername(), "", restClient.getParameters()); + RestSiteModelsCollection sites = restClient.processModels(RestSiteModelsCollection.class, request); + restClient.assertStatusCodeIs(HttpStatus.OK); + sites.assertThat().entriesListIsNotEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify invalid request returns status 401 when user is empty") + public void getFavoriteSiteWithEmptyPersonId() throws Exception + { + UserModel emptyUser = new UserModel("", "password"); + restClient.authenticateUser(emptyUser).withCoreAPI().usingAuthUser().getFavoriteSite(siteModel1); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify invalid request returns status 404 when another user get favorite site of an user") + public void getFavoriteSiteWithAnotherUser() throws Exception + { + UserModel user = dataUser.createRandomTestUser(); + restClient.authenticateUser(user).withCoreAPI().usingAuthUser().getFavoriteSite(siteModel1); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, user.getUsername(), siteModel1.getId())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE) + .containsErrorKey(RestErrorModel.RELATIONSHIP_NOT_FOUND_ERRORKEY); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify request returns status 200 when using -me-") + public void getFavoriteSiteUsingMe() throws Exception + { + restSiteModel = restClient.authenticateUser(userModel).withCoreAPI().usingMe().getFavoriteSite(siteModel1); + restClient.assertStatusCodeIs(HttpStatus.OK); + restSiteModel.assertThat().field("id").is(siteModel1.getId()) + .and().field("title").is(siteModel1.getTitle()) + .and().field("role").is(UserRole.SiteManager.toString()) + .and().field("visibility").is(SiteService.Visibility.PUBLIC.toString()) + .and().field("guid").isNotEmpty() + .and().field("description").is(siteModel1.getDescription()) + .and().field("preset").is("site-dashboard"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify invalid request returns status 404 when providing folder name instead of site id") + public void getFavoriteSiteUsingFolder() throws Exception + { + FolderModel folder = dataContent.usingUser(userModel).usingSite(siteModel1).createFolder(); + SiteModel siteFolder = new SiteModel(folder.getName()); + restSiteModel = restClient.authenticateUser(userModel).withCoreAPI().usingMe().getFavoriteSite(siteFolder); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, userModel.getUsername(), folder.getName())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify invalid request returns status 404 when providing file name instead of site id") + public void getFavoriteSiteUsingFile() throws Exception + { + FileModel file = dataContent.usingUser(userModel).usingSite(siteModel1).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + SiteModel siteFolder = new SiteModel(file.getName()); + restSiteModel = restClient.authenticateUser(userModel).withCoreAPI().usingMe().getFavoriteSite(siteFolder); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, userModel.getUsername(), file.getName())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify request returns status 200 when using valid parameters") + public void getFavoriteSiteUsingParameters() throws Exception + { + restSiteModel = restClient.withParams("maxItems=100").authenticateUser(userModel).withCoreAPI().usingMe().getFavoriteSite(siteModel1); + restClient.assertStatusCodeIs(HttpStatus.OK); + restSiteModel.assertThat().field("id").is(siteModel1.getId()) + .and().field("title").is(siteModel1.getTitle()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify request returns status 400 when using maxItems=0") + public void getFavoriteSiteUsingInvalidMaxItems() throws Exception + { + restSiteModel = restClient.withParams("maxItems=0").authenticateUser(userModel).withCoreAPI().usingMe().getFavoriteSite(siteModel1); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify request returns status 401 when using invalid network") + public void getFavoriteSiteUsingInvalidNetwork() throws Exception + { + UserModel invalidUserNetwork = dataUser.createRandomTestUser(); + SiteModel site = dataSite.usingUser(invalidUserNetwork).createPublicRandomSite(); + dataSite.usingUser(invalidUserNetwork).usingSite(site).addSiteToFavorites(); + invalidUserNetwork.setDomain("invalidNetwork"); + restSiteModel = restClient.authenticateUser(invalidUserNetwork).withCoreAPI().usingMe().getFavoriteSite(site); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/favorites/GetFavoriteSitesTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/favorites/GetFavoriteSitesTests.java new file mode 100644 index 0000000000..de58e43f05 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/favorites/GetFavoriteSitesTests.java @@ -0,0 +1,324 @@ +package org.alfresco.rest.favorites; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestSiteModel; +import org.alfresco.rest.model.RestSiteModelsCollection; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.data.RandomData; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class GetFavoriteSitesTests extends RestTest +{ + private UserModel userModel, testUser1; + private SiteModel siteModel, testSite1, testSite2, testSite3; + private RestSiteModelsCollection restSiteModelsCollection; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + userModel = dataUser.createRandomTestUser(); + testUser1 = dataUser.createRandomTestUser(); + + siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); + testSite1 = new SiteModel("A-" + RandomData.getRandomAlphanumeric()); + testSite2 = new SiteModel("B-" + RandomData.getRandomAlphanumeric()); + testSite3 = new SiteModel("C-" + RandomData.getRandomAlphanumeric()); + + dataSite.usingUser(userModel).usingSite(siteModel).addSiteToFavorites(); + + dataSite.usingUser(testUser1).createSite(testSite1); + dataSite.usingUser(testUser1).createSite(testSite2); + dataSite.usingUser(testUser1).createSite(testSite3); + + dataSite.usingUser(testUser1).usingSite(testSite3).addSiteToFavorites(); + dataSite.usingUser(testUser1).usingSite(testSite2).addSiteToFavorites(); + dataSite.usingUser(testUser1).usingSite(testSite1).addSiteToFavorites(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify manager user fails to get an user favorite sites with Rest API (403)") + public void managerUserFailsToGetAnUserFavoriteSites() throws Exception + { + UserModel managerUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(managerUser, siteModel, UserRole.SiteManager); + UserModel anotherUser = dataUser.usingAdmin().createRandomTestUser(); + dataSite.usingUser(anotherUser).usingSite(siteModel).addSiteToFavorites(); + + restClient.authenticateUser(managerUser).withCoreAPI().usingUser(anotherUser).getFavoriteSites(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify collaborator user fails to get an user favorite sites with Rest API (403)") + public void collaboratorUserFailsToGetAnUserFavoriteSites() throws Exception + { + UserModel collaboratorUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(collaboratorUser, siteModel, UserRole.SiteCollaborator); + UserModel contributorUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(contributorUser, siteModel, UserRole.SiteContributor); + dataSite.usingUser(contributorUser).usingSite(siteModel).addSiteToFavorites(); + + restClient.authenticateUser(collaboratorUser).withCoreAPI().usingUser(contributorUser).getFavoriteSites(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify contributor user fails to get an user favorite sites with Rest API (403)") + public void contributorUserFailsToGetAnUserFavoriteSites() throws Exception + { + UserModel contributorUser = dataUser.usingAdmin().createRandomTestUser(); + UserModel contributorUser2 = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(contributorUser, siteModel, UserRole.SiteContributor); + dataUser.usingUser(userModel).addUserToSite(contributorUser2, siteModel, UserRole.SiteContributor); + dataSite.usingUser(contributorUser2).usingSite(siteModel).addSiteToFavorites(); + + restClient.authenticateUser(contributorUser).withCoreAPI().usingUser(contributorUser2).getFavoriteSites(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify consumer user fails to get an user favorite sites with Rest API (403)") + public void consumerUserFailsToGetAnUserFavoriteSites() throws Exception + { + UserModel consumerUser = dataUser.usingAdmin().createRandomTestUser(); + UserModel collaboratorUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(consumerUser, siteModel, UserRole.SiteConsumer); + dataUser.usingUser(collaboratorUser).addUserToSite(collaboratorUser, siteModel, UserRole.SiteCollaborator); + dataSite.usingUser(collaboratorUser).usingSite(siteModel).addSiteToFavorites(); + + restClient.authenticateUser(consumerUser).withCoreAPI().usingUser(collaboratorUser).getFavoriteSites(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, description = "Verify any user gets its own user favorite sites with Rest API and response is successful (200)") + public void anyUserGetsHisFavoriteSites() throws Exception + { + UserModel anyUser = dataUser.usingAdmin().createRandomTestUser(); + dataSite.usingUser(anyUser).usingSite(siteModel).addSiteToFavorites(); + + restSiteModelsCollection = restClient.authenticateUser(anyUser).withCoreAPI().usingAuthUser().getFavoriteSites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restSiteModelsCollection.assertThat().entriesListIsNotEmpty().and().entriesListContains("id", siteModel.getId()).and().paginationExist(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, description = "Verify any user is NOT Authorized to get its favorite sites with Rest API when authentication fails (401)") +// @Bug(id = "MNT-16904", description = "It fails only on environment with tenants") + public void unauthenticatedUserIsNotAuthorizedToGetFavoriteSites() throws Exception + { + UserModel anyUser = dataUser.usingAdmin().createRandomTestUser(); + dataSite.usingUser(anyUser).usingSite(siteModel).addSiteToFavorites(); + anyUser.setPassword("newpassword"); + + restClient.authenticateUser(anyUser).withCoreAPI().usingAuthUser().getFavoriteSites(); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify that getFavoriteSites request status code is 404 for a personId that does not exist") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void getFavoriteSitesReturns404ForAPersonIdThatDoesNotExist() throws Exception + { + UserModel invalidUser = new UserModel(RandomData.getRandomName("User"), DataUser.PASSWORD); + + restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingUser(invalidUser).getFavoriteSites(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, invalidUser.getUsername())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify that getFavoriteSites request status code is 403 if the user doesn't have access to the person favorite sites") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void userCannotGetFavoriteSitesForAnotherUser() throws Exception + { + restClient.authenticateUser(userModel).withCoreAPI().usingUser(testUser1).getFavoriteSites(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError() + .containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY) + .containsSummary(RestErrorModel.PERMISSION_WAS_DENIED) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify that admin has access to regular user site favorites") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void adminCanGetFavoriteSitesForARegularUser() throws Exception + { + restSiteModelsCollection = restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingUser(userModel).getFavoriteSites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restSiteModelsCollection.assertThat().entriesListIsNotEmpty() + .assertThat().entriesListContains("id", siteModel.getId()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify that regular user can not see admin user site favorites") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void regularUserCannotGetFavoriteSitesForAdminUser() throws Exception + { + restClient.authenticateUser(testUser1).withCoreAPI().usingUser(dataUser.getAdminUser()).getFavoriteSites(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError() + .containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY) + .containsSummary(RestErrorModel.PERMISSION_WAS_DENIED) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify that favorite site can be removed") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void verifyThatFavoriteSiteCanBeRemoved() throws Exception + { + UserModel randomTestUser = dataUser.createRandomTestUser(); + dataSite.usingUser(randomTestUser).usingSite(siteModel).addSiteToFavorites(); + + restSiteModelsCollection = restClient.authenticateUser(randomTestUser).withCoreAPI().usingAuthUser().getFavoriteSites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restSiteModelsCollection.assertThat().entriesListIsNotEmpty() + .assertThat().entriesListContains("id", siteModel.getId()); + + dataSite.usingUser(randomTestUser).usingSite(siteModel).removeSiteFromFavorites(); + restSiteModelsCollection = restClient.withCoreAPI().usingAuthUser().getFavoriteSites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restSiteModelsCollection.assertThat().entriesListIsEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify that if maxItems param is invalid status code returned is BAD_REQUEST (400)") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void getFavoriteSitesMaxItemsInvalidValueTest() throws Exception + { + restClient.authenticateUser(userModel).withParams("maxItems=-1").withCoreAPI().usingAuthUser().getFavoriteSites(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS); + + restClient.authenticateUser(userModel).withParams("maxItems=abc").withCoreAPI().usingAuthUser().getFavoriteSites(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(String.format(RestErrorModel.INVALID_MAXITEMS, "abc")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify that if skipCount param is invalid status code returned is BAD_REQUEST (400)") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void getFavoriteSitesSkipCountInvalidValueTest() throws Exception + { + restClient.authenticateUser(userModel).withParams("skipCount=-1").withCoreAPI().usingAuthUser().getFavoriteSites(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(RestErrorModel.NEGATIVE_VALUES_SKIPCOUNT); + + restClient.authenticateUser(userModel).withParams("skipCount=abc").withCoreAPI().usingAuthUser().getFavoriteSites(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(String.format(RestErrorModel.INVALID_SKIPCOUNT, "abc")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify that getFavoriteSites request response status using -me- string in place of personId is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void userGetsFavoriteSiteWithSuccessUsingMEForRequest() throws Exception + { + restSiteModelsCollection = restClient.authenticateUser(testUser1).withCoreAPI().usingMe().getFavoriteSites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restSiteModelsCollection.assertThat().entriesListIsNotEmpty() + .and().entriesListContains("id", testSite1.getId()) + .and().paginationExist(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify that getFavoriteSites request response status for a user that has no favorite sites is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void getFavoriteSiteRequestForUserWithNoFavoriteSitesIsSuccessful() throws Exception + { + UserModel randomTestUser = dataUser.createRandomTestUser(); + + restSiteModelsCollection = restClient.authenticateUser(randomTestUser).withCoreAPI().usingMe().getFavoriteSites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restSiteModelsCollection.assertThat().entriesListIsEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify that getFavoriteSites request response status for a user with several favorite sites is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void getFavoriteSiteRequestForUserWithSeveralFavoriteSitesIsSuccessful() throws Exception + { + restSiteModelsCollection = restClient.authenticateUser(testUser1).withCoreAPI().usingAuthUser().getFavoriteSites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restSiteModelsCollection.assertThat().entriesListIsNotEmpty() + .and().entriesListContains("id", testSite1.getId()) + .and().entriesListContains("id", testSite2.getId()) + .and().entriesListContains("id", testSite3.getId()) + .and().paginationExist(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify that getFavoriteSites request can only be called with a positive maxItems param") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void userCanNotGetFavoriteSitesWith0MaxItems() throws Exception + { + restClient.authenticateUser(testUser1).withParams("maxItems=0").withCoreAPI().usingAuthUser().getFavoriteSites(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsErrorKey(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS) + .containsSummary(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify that getFavoriteSites request response status code for a high skipCount param is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void userCanGetFavoriteSitesWithHighSkipCount() throws Exception + { + restSiteModelsCollection = restClient.authenticateUser(testUser1).withParams("skipCount=999999999").withCoreAPI().usingAuthUser().getFavoriteSites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restSiteModelsCollection.assertThat().entriesListIsEmpty() + .assertThat().paginationField("skipCount").is("999999999"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify that user can retrieve the last 2 favorite sites") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void userCanRetrieveLast2FavoriteSites() throws Exception + { + restSiteModelsCollection = restClient.authenticateUser(testUser1).withParams("skipCount=1&maxCount=2"). + withCoreAPI().usingAuthUser().getFavoriteSites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restSiteModelsCollection.assertThat().entriesListIsNotEmpty() + .assertThat().entriesListCountIs(2) + .assertThat().entriesListContains("id", testSite2.getId()) + .assertThat().entriesListContains("id", testSite3.getId()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify that getFavoriteSites request applies valid properties param") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void getFavoriteSitesRequestWithValidPropertiesParam() throws Exception + { + RestSiteModel restSiteModel = restClient.authenticateUser(testUser1).withParams("properties=title") + .withCoreAPI().usingAuthUser().getFavoriteSites().getOneRandomEntry().onModel(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restSiteModel.assertThat().fieldsCount().is(1) + .assertThat().field("title").isNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify that getFavoriteSites request applies invalid properties param") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void getFavoriteSitesRequestWithInvalidPropertiesParam() throws Exception + { + restClient.authenticateUser(testUser1).withParams("properties=tas").withCoreAPI().usingAuthUser() + .getFavoriteSites().getOneRandomEntry().onModel().assertThat().fieldsCount().is(0); + restClient.assertStatusCodeIs(HttpStatus.OK); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/favorites/GetFavoriteTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/favorites/GetFavoriteTests.java new file mode 100644 index 0000000000..d2d9c96b89 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/favorites/GetFavoriteTests.java @@ -0,0 +1,479 @@ +package org.alfresco.rest.favorites; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.dataprep.SiteService; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestPersonFavoritesModel; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; +import org.alfresco.utility.model.FileModel; +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.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class GetFavoriteTests extends RestTest +{ + private UserModel adminUserModel; + private SiteModel siteModel; + private FolderModel folderModel; + private FileModel fileModel; + private ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUserModel = dataUser.getAdminUser(); + siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); + + folderModel = dataContent.usingUser(adminUserModel).usingSite(siteModel).createFolder(); + fileModel = dataContent.usingUser(adminUserModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, + UserRole.SiteContributor); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.SANITY, + description = "Verify Manager user gets favorite site with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.SANITY }) + public void managerIsAbleToRetrieveFavoriteSite() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + restClient.withCoreAPI().usingAuthUser().addSiteToFavorites(siteModel); + + RestPersonFavoritesModel favSite = restClient.withCoreAPI().usingAuthUser().getFavorite(siteModel.getGuid()); + restClient.assertStatusCodeIs(HttpStatus.OK); + favSite.assertThat().field("targetGuid").is(siteModel.getGuid()); + + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.SANITY, + description = "Verify Manager user gets favorite folder with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.SANITY }) + public void managerIsAbleToRetrieveFavoriteFolder() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + restClient.withCoreAPI().usingAuthUser().addFolderToFavorites(folderModel); + + RestPersonFavoritesModel favoriteFolder = restClient.withCoreAPI().usingAuthUser().getFavorite(folderModel.getNodeRef()); + restClient.assertStatusCodeIs(HttpStatus.OK); + favoriteFolder.assertThat().field("targetGuid").is(folderModel.getNodeRef()); + + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.SANITY, + description = "Verify Manager user gets favorite file with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.SANITY }) + public void managerIsAbleToRetrieveFavoriteFile() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + restClient.withCoreAPI().usingAuthUser().addFileToFavorites(fileModel); + + RestPersonFavoritesModel favoriteFile = restClient.withCoreAPI().usingAuthUser().getFavorite(fileModel.getNodeRefWithoutVersion()); + restClient.assertStatusCodeIs(HttpStatus.OK); + favoriteFile.assertThat().field("targetGuid").is(fileModel.getNodeRefWithoutVersion()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.SANITY, + description = "Verify user gets status code 401 if authentication call fails") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.SANITY }) +// @Bug(id = "MNT-16904", description = "fails only on environment with tenants") + public void userIsNotAbleToRetrieveFavoriteSiteIfAuthenticationFails() throws Exception + { + UserModel siteManager = usersWithRoles.getOneUserWithRole(UserRole.SiteManager); + siteManager.setPassword("wrongPassword"); + restClient.authenticateUser(siteManager).withCoreAPI() + .usingUser(siteManager).getFavorite(siteModel.getGuid()); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify Admin user gets favorite site with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void adminIsAbleToRetrieveFavoritesSite() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(adminUserModel).addSiteToFavorites(siteModel); + + RestPersonFavoritesModel favoriteSite = restClient.withCoreAPI().usingUser(adminUserModel).getFavorite(siteModel.getGuid()); + restClient.assertStatusCodeIs(HttpStatus.OK); + favoriteSite.assertThat().field("targetGuid").is(siteModel.getGuid()); + favoriteSite.getTarget().getSite() + .assertThat().field("guid").is(siteModel.getGuid()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify Admin user gets favorite folder with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void adminIsAbleToRetrieveFavoritesFolder() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(adminUserModel).addFolderToFavorites(folderModel); + + RestPersonFavoritesModel favoriteFolder = restClient.withCoreAPI().usingUser(adminUserModel).getFavorite(folderModel.getNodeRef()); + restClient.assertStatusCodeIs(HttpStatus.OK); + favoriteFolder.assertThat().field("targetGuid").is(folderModel.getNodeRef()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify Admin user gets favorite file with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void adminIsAbleToRetrieveFavoritesFile() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(adminUserModel).addFileToFavorites(fileModel); + + RestPersonFavoritesModel favoriteFile = restClient.withCoreAPI().usingUser(adminUserModel).getFavorite(fileModel.getNodeRefWithoutVersion()); + restClient.assertStatusCodeIs(HttpStatus.OK); + favoriteFile.assertThat().field("targetGuid").is(fileModel.getNodeRefWithoutVersion()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify Collaborator user gets favorite site with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void collaboratorIsAbleToRetrieveFavoriteSite() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .withCoreAPI().usingAuthUser().addSiteToFavorites(siteModel); + + RestPersonFavoritesModel favSite = restClient.withCoreAPI().usingAuthUser().getFavorite(siteModel.getGuid()); + restClient.assertStatusCodeIs(HttpStatus.OK); + favSite.assertThat().field("targetGuid").is(siteModel.getGuid()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify collaborator user gets favorite folder with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void collaboratorIsAbleToRetrieveFavoriteFolder() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); + restClient.withCoreAPI().usingAuthUser().addFolderToFavorites(folderModel); + + RestPersonFavoritesModel favoriteFolder = restClient.withCoreAPI().usingAuthUser().getFavorite(folderModel.getNodeRef()); + restClient.assertStatusCodeIs(HttpStatus.OK); + favoriteFolder.assertThat().field("targetGuid").is(folderModel.getNodeRef()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify collaborator user gets favorite file with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void collaboratorIsAbleToRetrieveFavoriteFile() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); + restClient.withCoreAPI().usingAuthUser().addFileToFavorites(fileModel); + + RestPersonFavoritesModel favoriteFile = restClient.withCoreAPI().usingAuthUser().getFavorite(fileModel.getNodeRefWithoutVersion()); + restClient.assertStatusCodeIs(HttpStatus.OK); + favoriteFile.assertThat().field("targetGuid").is(fileModel.getNodeRefWithoutVersion()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify Contributor user gets favorite site with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void contributorIsAbleToRetrieveFavoriteSite() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); + restClient.withCoreAPI().usingAuthUser().addSiteToFavorites(siteModel); + + RestPersonFavoritesModel favSite = restClient.withCoreAPI().usingAuthUser().getFavorite(siteModel.getGuid()); + restClient.assertStatusCodeIs(HttpStatus.OK); + favSite.assertThat().field("targetGuid").is(siteModel.getGuid()); ; + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify contributor user gets favorite folder with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void contributorIsAbleToRetrieveFavoriteFolder() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); + restClient.withCoreAPI().usingAuthUser().addFolderToFavorites(folderModel); + + RestPersonFavoritesModel favoriteFolder = restClient.withCoreAPI().usingAuthUser().getFavorite(folderModel.getNodeRef()); + restClient.assertStatusCodeIs(HttpStatus.OK); + favoriteFolder.assertThat().field("targetGuid").is(folderModel.getNodeRef()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify contributor user gets favorite file with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void contributorIsAbleToRetrieveFavoriteFile() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); + restClient.withCoreAPI().usingAuthUser().addFileToFavorites(fileModel); + + RestPersonFavoritesModel favoriteFile = restClient.withCoreAPI().usingAuthUser().getFavorite(fileModel.getNodeRefWithoutVersion()); + restClient.assertStatusCodeIs(HttpStatus.OK); + favoriteFile.assertThat().field("targetGuid").is(fileModel.getNodeRefWithoutVersion()); + } + + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify Consumer user gets favorite site with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void consumerIsAbleToRetrieveFavorites() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)); + restClient.withCoreAPI().usingAuthUser().addSiteToFavorites(siteModel); + + RestPersonFavoritesModel favSite = restClient.withCoreAPI().usingAuthUser().getFavorite(siteModel.getGuid()); + restClient.assertStatusCodeIs(HttpStatus.OK); + favSite.assertThat().field("targetGuid").is(siteModel.getGuid()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify consumer user gets favorite folder with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void consumerIsAbleToRetrieveFavoriteFolder() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)); + restClient.withCoreAPI().usingAuthUser().addFolderToFavorites(folderModel); + + RestPersonFavoritesModel favoriteFolder = restClient.withCoreAPI().usingAuthUser().getFavorite(folderModel.getNodeRef()); + restClient.assertStatusCodeIs(HttpStatus.OK); + favoriteFolder.assertThat().field("targetGuid").is(folderModel.getNodeRef()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify consumer user gets favorite file with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void consumerIsAbleToRetrieveFavoriteFile() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)); + restClient.withCoreAPI().usingAuthUser().addFileToFavorites(fileModel); + + RestPersonFavoritesModel favoriteFile = restClient.withCoreAPI().usingAuthUser().getFavorite(fileModel.getNodeRefWithoutVersion()); + restClient.assertStatusCodeIs(HttpStatus.OK); + favoriteFile.assertThat().field("targetGuid").is(fileModel.getNodeRefWithoutVersion()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user doesn't get favorite site of another user with Rest API and status code is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void userIsNotAbleToRetrieveFavoriteSiteOfAnotherSiteMember() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)); + restClient.withCoreAPI().usingUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .getFavorite(siteModel.getGuid()); + + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator).getUsername())); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user doesn't get favorite site of admin user with Rest API and status code is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void userIsNotAbleToRetrieveFavoritesOfAdminUser() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .withCoreAPI().usingUser(adminUserModel).getFavorite(siteModel.getGuid()); + + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, adminUserModel.getUsername())); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify admin user doesn't get favorite site of another user with Rest API and status code is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void adminIsNotAbleToRetrieveFavoritesOfAnotherUser() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI() + .usingUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).getFavorite(siteModel.getGuid()); + + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator).getUsername())); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, + executionType = ExecutionType.REGRESSION, description = "Verify get favorite user doesn't have any favorite site, file or folder") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void getFavoriteSiteForUserWithoutAnyFavorites() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + restClient.withCoreAPI().usingAuthUser().getFavorite(siteModel.getGuid()); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, usersWithRoles.getOneUserWithRole(UserRole.SiteManager).getUsername(), siteModel.getGuid())) + .statusCodeIs(HttpStatus.NOT_FOUND) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE) + .containsErrorKey(RestErrorModel.RELATIONSHIP_NOT_FOUND_ERRORKEY); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, description = "Verify get favorite site for -me-") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void getFavoriteSiteUsingMe() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingAuthUser().addSiteToFavorites(siteModel); + + RestPersonFavoritesModel favoriteSite = restClient.withCoreAPI().usingMe().getFavorite(siteModel.getGuid()); + restClient.assertStatusCodeIs(HttpStatus.OK); + favoriteSite.assertThat().field("targetGuid").is(siteModel.getGuid()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, description = "Verify get favorite site for -me-") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void getFavoriteFileUsingMe() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingAuthUser().addFileToFavorites(fileModel); + + RestPersonFavoritesModel favoriteFile = restClient.withCoreAPI().usingMe().getFavorite(fileModel.getNodeRefWithoutVersion()); + restClient.assertStatusCodeIs(HttpStatus.OK); + favoriteFile.assertThat().field("targetGuid").is(fileModel.getNodeRefWithoutVersion()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, + executionType = ExecutionType.REGRESSION, description = "Verify get favorite site when person id does't exist") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void getFavoriteSiteWhenPersonIdNotExist() throws Exception { + + restClient.withCoreAPI().usingUser(adminUserModel).addSiteToFavorites(siteModel); + UserModel someUser = new UserModel("invalidUser", DataUser.PASSWORD); + + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(someUser).getFavorite(siteModel.getGuid()); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, someUser.getUsername())) + .statusCodeIs(HttpStatus.NOT_FOUND) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE) + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY); + } + + @Bug(id = "ACE-2413") + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, + executionType = ExecutionType.REGRESSION, description = "Verify get favorite site when person id is empty") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void getFavoriteSiteWithEmptyUserId() throws Exception { + + restClient.withCoreAPI().usingUser(adminUserModel).addSiteToFavorites(siteModel); + UserModel someUser = new UserModel("", DataUser.PASSWORD); + + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(someUser).getFavorite(siteModel.getGuid()); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, someUser.getUsername())) + .statusCodeIs(HttpStatus.BAD_REQUEST); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, + executionType = ExecutionType.REGRESSION, description = "Verify get favorite site when favorite id does't exist") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void getFavoriteSiteWhenFavoriteIdNotExist() throws Exception { + + restClient.withCoreAPI().usingUser(adminUserModel).addSiteToFavorites(siteModel); + + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(adminUserModel).getFavorite("invalidId"); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "invalidId")) + .statusCodeIs(HttpStatus.NOT_FOUND) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE) + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify Admin user gets favorite site with properties filter") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void verifyRequestForGetFavoriteSiteWithProperties() throws Exception + { + UserModel collaborator = usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator); + restClient.authenticateUser(collaborator); + restClient.withCoreAPI().usingUser(collaborator).addSiteToFavorites(siteModel); + + RestPersonFavoritesModel favoriteSite = restClient.authenticateUser(collaborator).withParams("properties=targetGuid") + .withCoreAPI().usingAuthUser().getFavorite(siteModel.getGuid()); + restClient.assertStatusCodeIs(HttpStatus.OK); + favoriteSite.assertThat().field("targetGuid").is(siteModel.getGuid()); + favoriteSite.assertThat().fieldsCount().is(1); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify Admin user gets favorite site with inccorect properties filter") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void verifyRequestForGetFavoriteSiteWithInvalidProperties() throws Exception + { + UserModel collaborator = usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator); + restClient.authenticateUser(collaborator); + restClient.withCoreAPI().usingUser(collaborator).addFileToFavorites(fileModel); + + RestPersonFavoritesModel favoriteFile = restClient.authenticateUser(collaborator).withParams("properties=tas") + .withCoreAPI().usingAuthUser().getFavorite(fileModel.getNodeRefWithoutVersion()); + restClient.assertStatusCodeIs(HttpStatus.OK); + favoriteFile.assertThat().fieldsCount().is(0); + } + + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify all values from get favorite rest api for a file") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void verifyRequestFieldsForGetFavoriteFile() throws Exception + { + UserModel contributor = usersWithRoles.getOneUserWithRole(UserRole.SiteContributor); + restClient.authenticateUser(contributor); + restClient.withCoreAPI().usingUser(contributor).addFileToFavorites(fileModel); + + RestPersonFavoritesModel favoriteFile = restClient.authenticateUser(contributor) + .withCoreAPI().usingAuthUser().getFavorite(fileModel.getNodeRefWithoutVersion()); + restClient.assertStatusCodeIs(HttpStatus.OK); + + favoriteFile.assertThat().field("targetGuid").is(fileModel.getNodeRefWithoutVersion()) + .and().field("target.file.isFile").is("true") + .and().field("target.file.mimeType").is("text/plain") + .and().field("target.file.isFolder").is("false") + .and().field("target.file.createdBy").is(adminUserModel.getUsername()) + .and().field("target.file.versionLabel").is("1.0") + .and().field("target.file.name").is(fileModel.getName()) + .and().field("target.file.parentId").is(folderModel.getNodeRef()) + .and().field("target.file.guid").is(fileModel.getNodeRefWithoutVersion()) + .and().field("target.file.modifiedBy").is(adminUserModel.getUsername()) + .and().field("target.file.id").is(fileModel.getNodeRefWithoutVersion()); + } + + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify all values from get favorite rest api for a site") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void verifyRequestFieldsForGetFavoriteSite() throws Exception + { + UserModel contributor = usersWithRoles.getOneUserWithRole(UserRole.SiteContributor); + restClient.authenticateUser(contributor); + restClient.withCoreAPI().usingUser(contributor).addFavoriteSite(siteModel); + + RestPersonFavoritesModel favoriteSite = restClient.authenticateUser(contributor) + .withCoreAPI().usingAuthUser().getFavorite(siteModel.getGuid()); + restClient.assertStatusCodeIs(HttpStatus.OK); + + favoriteSite.assertThat().field("targetGuid").is(siteModel.getGuid()) + .and().field("target.site.role").is(UserRole.SiteContributor.toString()) + .and().field("target.site.visibility").is(SiteService.Visibility.PUBLIC.toString()) + .and().field("target.site.guid").is(siteModel.getGuid()) + .and().field("target.site.description").is(siteModel.getDescription()) + .and().field("target.site.id").is(siteModel.getId()) + .and().field("target.site.preset").is("site-dashboard") + .and().field("target.site.title").is(siteModel.getTitle()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify all values from get favorite rest api for a folder") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void verifyRequestFieldsForGetFavoriteFolder() throws Exception + { + UserModel contributor = usersWithRoles.getOneUserWithRole(UserRole.SiteContributor); + restClient.authenticateUser(contributor); + restClient.withCoreAPI().usingUser(contributor).addFolderToFavorites(folderModel); + + RestPersonFavoritesModel favoriteFolder = restClient.authenticateUser(contributor) + .withCoreAPI().usingAuthUser().getFavorite(folderModel.getNodeRef()); + restClient.assertStatusCodeIs(HttpStatus.OK); + + favoriteFolder.assertThat().field("targetGuid").is(folderModel.getNodeRef()) + .and().field("target.folder.isFile").is("false") + .and().field("target.folder.isFolder").is("true") + .and().field("target.folder.createdBy").is(adminUserModel.getUsername()) + .and().field("target.folder.name").is(folderModel.getName()) + .and().field("target.folder.guid").is(folderModel.getNodeRef()) + .and().field("target.folder.modifiedBy").is(adminUserModel.getUsername()) + .and().field("target.folder.id").is(folderModel.getNodeRef()); + } +} \ No newline at end of file diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/favorites/GetFavoritesTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/favorites/GetFavoritesTests.java new file mode 100644 index 0000000000..84d35a9dce --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/favorites/GetFavoritesTests.java @@ -0,0 +1,554 @@ +package org.alfresco.rest.favorites; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestPersonFavoritesModel; +import org.alfresco.rest.model.RestPersonFavoritesModelsCollection; +import org.alfresco.rest.model.RestSiteModel; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; +import org.alfresco.utility.model.FileModel; +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.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class GetFavoritesTests extends RestTest +{ + private UserModel adminUserModel, userModel; + private SiteModel firstSiteModel; + private SiteModel secondSiteModel; + private SiteModel thirdSiteModel; + private FileModel firstFileModel; + private FileModel secondFileModel; + private FolderModel firstFolderModel; + private FolderModel secondFolderModel; + private ListUserWithRoles firstSiteUsers, secondSiteUsers; + private RestPersonFavoritesModelsCollection userFavorites; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUserModel = dataUser.getAdminUser(); + userModel = dataUser.createRandomTestUser(); + + firstSiteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); + secondSiteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); + thirdSiteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); + firstFolderModel = dataContent.usingUser(adminUserModel).usingSite(firstSiteModel).createFolder(); + secondFolderModel = dataContent.usingUser(adminUserModel).usingSite(firstSiteModel).createFolder(); + firstFileModel = dataContent.usingUser(adminUserModel).usingResource(firstFolderModel).createContent(DocumentType.TEXT_PLAIN); + secondFileModel = dataContent.usingUser(adminUserModel).usingResource(firstFolderModel).createContent(DocumentType.TEXT_PLAIN); + + firstSiteUsers = dataUser.addUsersWithRolesToSite(firstSiteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, + UserRole.SiteContributor); + secondSiteUsers = dataUser.addUsersWithRolesToSite(secondSiteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, + UserRole.SiteContributor); + + restClient.authenticateUser(userModel); + restClient.withCoreAPI().usingUser(userModel).addSiteToFavorites(firstSiteModel); + restClient.withCoreAPI().usingUser(userModel).addSiteToFavorites(secondSiteModel); + restClient.withCoreAPI().usingUser(userModel).addSiteToFavorites(thirdSiteModel); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.SANITY, + description = "Verify Manager user gets favorites with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.SANITY }) + public void managerIsAbleToRetrieveFavorites() throws Exception + { + restClient.authenticateUser(firstSiteUsers.getOneUserWithRole(UserRole.SiteManager)); + restClient.withCoreAPI().usingAuthUser().addSiteToFavorites(firstSiteModel); + restClient.withCoreAPI().usingAuthUser().addSiteToFavorites(secondSiteModel); + + userFavorites = restClient.withCoreAPI().usingAuthUser().getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + userFavorites.assertThat().entriesListContains("targetGuid", firstSiteModel.getGuid()) + .assertThat().entriesListContains("targetGuid", secondSiteModel.getGuid()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.SANITY, + description = "Verify user gets status code 401 if authentication call fails") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.SANITY }) +// @Bug(id = "MNT-16904", description = "It fails only on environment with tenants") + public void userIsNotAbleToRetrieveFavoritesIfAuthenticationFails() throws Exception + { + UserModel siteManager = firstSiteUsers.getOneUserWithRole(UserRole.SiteManager); + siteManager.setPassword("wrongPassword"); + restClient.authenticateUser(siteManager).withCoreAPI().usingAuthUser().getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify Admin user gets favorites sites with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void adminIsAbleToRetrieveFavoritesSites() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(adminUserModel).addSiteToFavorites(firstSiteModel); + restClient.withCoreAPI().usingUser(adminUserModel).addSiteToFavorites(secondSiteModel); + + userFavorites = restClient.withCoreAPI() + .usingAuthUser().where().targetSiteExist().getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + userFavorites.assertThat().entriesListContains("targetGuid", firstSiteModel.getGuid()) + .and().entriesListContains("targetGuid", secondSiteModel.getGuid()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify Admin user gets favorites folders with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void adminIsAbleToRetrieveFavoritesFolders() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(adminUserModel).addFolderToFavorites(firstFolderModel); + restClient.withCoreAPI().usingUser(adminUserModel).addFolderToFavorites(secondFolderModel); + + userFavorites = restClient.withCoreAPI() + .usingAuthUser().where().targetFolderExist().getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + userFavorites.assertThat().entriesListContains("targetGuid", firstFolderModel.getNodeRef()) + .and().entriesListContains("targetGuid", secondFolderModel.getNodeRef()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify Admin user gets favorites files with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void adminIsAbleToRetrieveFavoritesFiles() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(adminUserModel).addFileToFavorites(firstFileModel); + restClient.withCoreAPI().usingUser(adminUserModel).addFileToFavorites(secondFileModel); + + userFavorites = restClient.withCoreAPI() + .usingAuthUser().where().targetFileExist().getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + userFavorites.assertThat().entriesListContains("targetGuid", firstFileModel.getNodeRefWithoutVersion()) + .and().entriesListContains("targetGuid", secondFileModel.getNodeRefWithoutVersion()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify Collaborator user gets favorites with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void collaboratorIsAbleToRetrieveFavorites() throws Exception + { + restClient.authenticateUser(firstSiteUsers.getOneUserWithRole(UserRole.SiteCollaborator)) + .withCoreAPI().usingAuthUser().addSiteToFavorites(firstSiteModel); + restClient.withCoreAPI().usingAuthUser().addSiteToFavorites(secondSiteModel); + + userFavorites = restClient.withCoreAPI().usingAuthUser().getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + userFavorites.assertThat().entriesListContains("targetGuid", firstSiteModel.getGuid()) + .and().entriesListContains("targetGuid", secondSiteModel.getGuid()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify Contributor user gets favorites with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void contributorIsAbleToRetrieveFavorites() throws Exception + { + restClient.authenticateUser(firstSiteUsers.getOneUserWithRole(UserRole.SiteContributor)) + .withCoreAPI().usingAuthUser().addSiteToFavorites(firstSiteModel); + restClient.withCoreAPI().usingAuthUser().addSiteToFavorites(secondSiteModel); + + userFavorites = restClient.withCoreAPI().usingAuthUser().getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + userFavorites.assertThat().entriesListContains("targetGuid", firstSiteModel.getGuid()).and() + .entriesListContains("targetGuid", secondSiteModel.getGuid()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify Consumer user gets favorites with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void consumerIsAbleToRetrieveFavorites() throws Exception + { + restClient.authenticateUser(firstSiteUsers.getOneUserWithRole(UserRole.SiteConsumer)) + .withCoreAPI().usingAuthUser().addSiteToFavorites(firstSiteModel); + restClient.withCoreAPI().usingAuthUser().addSiteToFavorites(secondSiteModel); + + userFavorites = restClient.withCoreAPI().usingAuthUser().getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + userFavorites.assertThat().entriesListContains("targetGuid", firstSiteModel.getGuid()) + .assertThat().entriesListContains("targetGuid", secondSiteModel.getGuid()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user doesn't have permission to get favorites of another user with Rest API and status code is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void userIsNotAbleToRetrieveFavoritesOfAnotherUser() throws Exception + { + restClient.authenticateUser(firstSiteUsers.getOneUserWithRole(UserRole.SiteConsumer)) + .withCoreAPI().usingUser(firstSiteUsers.getOneUserWithRole(UserRole.SiteCollaborator)).getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, firstSiteUsers.getOneUserWithRole(UserRole.SiteCollaborator).getUsername())); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user doesn't have permission to get favorites of admin user with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void userIsNotAbleToRetrieveFavoritesOfAdminUser() throws Exception + { + restClient.authenticateUser(firstSiteUsers.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI() + .usingUser(adminUserModel).getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, adminUserModel.getUsername())); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify admin user doesn't have permission to get favorites of another user with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void adminIsNotAbleToRetrieveFavoritesOfAnotherUser() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(firstSiteUsers.getOneUserWithRole(UserRole.SiteCollaborator)) + .getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, firstSiteUsers.getOneUserWithRole(UserRole.SiteCollaborator).getUsername())); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify User gets only favorites sites with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void userIsAbleToRetrieveOnlyFavoritesSites() throws Exception + { + restClient.authenticateUser(secondSiteUsers.getOneUserWithRole(UserRole.SiteManager)); + restClient.withCoreAPI().usingAuthUser().addSiteToFavorites(firstSiteModel); + restClient.withCoreAPI().usingAuthUser().addFileToFavorites(firstFileModel); + restClient.withCoreAPI().usingAuthUser().addFolderToFavorites(firstFolderModel); + + userFavorites = restClient.withCoreAPI().usingAuthUser().where().targetSiteExist().getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + userFavorites.assertThat().entriesListContains("targetGuid", firstSiteModel.getGuid()) + .and().entriesListDoesNotContain("targetGuid", secondSiteModel.getGuid()) + .and().entriesListDoesNotContain("targetGuid", firstFileModel.getNodeRefWithoutVersion()) + .and().entriesListDoesNotContain("targetGuid", firstFolderModel.getNodeRef()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify User gets only favorites files with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void userIsAbleToRetrieveOnlyFavoritesFiles() throws Exception + { + restClient.authenticateUser(firstSiteUsers.getOneUserWithRole(UserRole.SiteCollaborator)); + restClient.withCoreAPI().usingAuthUser().addSiteToFavorites(firstSiteModel); + restClient.withCoreAPI().usingAuthUser().addFileToFavorites(firstFileModel); + restClient.withCoreAPI().usingAuthUser().addFolderToFavorites(firstFolderModel); + + userFavorites = restClient.withCoreAPI().usingAuthUser().where().targetFileExist().getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + userFavorites.assertThat().entriesListContains("targetGuid", firstFileModel.getNodeRefWithoutVersion()) + .and().entriesListDoesNotContain("targetGuid", secondFileModel.getNodeRefWithoutVersion()) + .and().entriesListDoesNotContain("targetGuid", firstSiteModel.getGuid()) + .and().entriesListDoesNotContain("targetGuid", firstFolderModel.getNodeRef()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify User gets only favorites folders with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void userIsAbleToRetrieveOnlyFavoritesFolders() throws Exception + { + restClient.authenticateUser(firstSiteUsers.getOneUserWithRole(UserRole.SiteCollaborator)); + restClient.withCoreAPI().usingAuthUser().addSiteToFavorites(firstSiteModel); + restClient.withCoreAPI().usingAuthUser().addFileToFavorites(firstFileModel); + restClient.withCoreAPI().usingAuthUser().addFolderToFavorites(firstFolderModel); + + userFavorites = restClient.withCoreAPI().usingAuthUser().where().targetFolderExist().getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + userFavorites.assertThat().entriesListContains("targetGuid", firstFolderModel.getNodeRef()) + .and().entriesListDoesNotContain("targetGuid", secondFolderModel.getNodeRef()) + .and().entriesListDoesNotContain("targetGuid", firstSiteModel.getGuid()) + .and().entriesListDoesNotContain("targetGuid", firstFileModel.getNodeRefWithoutVersion()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify User gets only favorites files or folders with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void userIsAbleToRetrieveFavoritesFilesOrFolders() throws Exception + { + restClient.authenticateUser(firstSiteUsers.getOneUserWithRole(UserRole.SiteConsumer)); + restClient.withCoreAPI().usingAuthUser().addSiteToFavorites(firstSiteModel); + restClient.withCoreAPI().usingAuthUser().addFileToFavorites(firstFileModel); + restClient.withCoreAPI().usingAuthUser().addFolderToFavorites(firstFolderModel); + + userFavorites = restClient.withCoreAPI().usingAuthUser() + .where().targetFolderExist().or().targetFileExist() + .getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + userFavorites.assertThat().entriesListContains("targetGuid", firstFolderModel.getNodeRef()) + .and().entriesListContains("targetGuid", firstFileModel.getNodeRefWithoutVersion()) + .and().entriesListDoesNotContain("targetGuid", secondFolderModel.getNodeRef()) + .and().entriesListDoesNotContain("targetGuid", secondFileModel.getNodeRefWithoutVersion()) + .and().entriesListDoesNotContain("targetGuid", firstSiteModel.getGuid()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify User gets only favorites files or sites with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void userIsAbleToRetrieveFavoritesFilesOrSites() throws Exception + { + restClient.authenticateUser(secondSiteUsers.getOneUserWithRole(UserRole.SiteManager)); + restClient.withCoreAPI().usingAuthUser().addSiteToFavorites(firstSiteModel); + restClient.withCoreAPI().usingAuthUser().addFileToFavorites(firstFileModel); + restClient.withCoreAPI().usingAuthUser().addFolderToFavorites(firstFolderModel); + + userFavorites = restClient.withCoreAPI().usingAuthUser() + .where().targetSiteExist().or().targetFileExist() + .getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + userFavorites.assertThat().entriesListContains("targetGuid", firstSiteModel.getGuid()) + .and().entriesListContains("targetGuid", firstFileModel.getNodeRefWithoutVersion()) + .and().entriesListDoesNotContain("targetGuid", secondSiteModel.getGuid()) + .and().entriesListDoesNotContain("targetGuid", secondFileModel.getNodeRefWithoutVersion()) + .and().entriesListDoesNotContain("targetGuid", firstFolderModel.getNodeRef()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify User gets only favorites folders or sites with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void userIsAbleToRetrieveFavoritesFoldersOrSites() throws Exception + { + restClient.authenticateUser(secondSiteUsers.getOneUserWithRole(UserRole.SiteManager)); + restClient.withCoreAPI().usingAuthUser().addSiteToFavorites(firstSiteModel); + restClient.withCoreAPI().usingAuthUser().addFileToFavorites(firstFileModel); + restClient.withCoreAPI().usingAuthUser().addFolderToFavorites(firstFolderModel); + + userFavorites = restClient.withCoreAPI().usingAuthUser() + .where().targetSiteExist().or().targetFolderExist() + .getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + userFavorites.assertThat().entriesListContains("targetGuid", firstSiteModel.getGuid()) + .and().entriesListContains("targetGuid", firstFolderModel.getNodeRef()) + .and().entriesListDoesNotContain("targetGuid", secondSiteModel.getGuid()) + .and().entriesListDoesNotContain("targetGuid", secondFolderModel.getNodeRef()) + .and().entriesListDoesNotContain("targetGuid", firstFileModel.getNodeRefWithoutVersion()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify User gets all favorites with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void userIsAbleToRetrieveAllFavorites() throws Exception + { + restClient.authenticateUser(secondSiteUsers.getOneUserWithRole(UserRole.SiteCollaborator)); + restClient.withCoreAPI().usingAuthUser().addSiteToFavorites(firstSiteModel); + restClient.withCoreAPI().usingAuthUser().addFileToFavorites(firstFileModel); + restClient.withCoreAPI().usingAuthUser().addFolderToFavorites(firstFolderModel); + + userFavorites = restClient.withCoreAPI().usingAuthUser() + .where().targetSiteExist().or().targetFolderExist().or().targetFileExist() + .getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + userFavorites.assertThat().entriesListContains("targetGuid", firstSiteModel.getGuid()) + .and().entriesListContains("targetGuid", firstFolderModel.getNodeRef()) + .and().entriesListContains("targetGuid", firstFileModel.getNodeRefWithoutVersion()) + .and().entriesListDoesNotContain("targetGuid", secondSiteModel.getGuid()) + .and().entriesListDoesNotContain("targetGuid", secondFolderModel.getNodeRef()) + .and().entriesListDoesNotContain("targetGuid", secondFileModel.getNodeRefWithoutVersion()); + + userFavorites = restClient.withCoreAPI().usingAuthUser().getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + userFavorites.assertThat().entriesListContains("targetGuid", firstSiteModel.getGuid()) + .and().entriesListContains("targetGuid", firstFolderModel.getNodeRef()) + .and().entriesListContains("targetGuid", firstFileModel.getNodeRefWithoutVersion()) + .and().entriesListDoesNotContain("targetGuid", secondSiteModel.getGuid()) + .and().entriesListDoesNotContain("targetGuid", secondFolderModel.getNodeRef()) + .and().entriesListDoesNotContain("targetGuid", secondFileModel.getNodeRefWithoutVersion()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify request for a user with no favorites returns status 200") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void userHasNoFavorites() throws Exception + { + restClient.authenticateUser(secondSiteUsers.getOneUserWithRole(UserRole.SiteContributor)); + + userFavorites = restClient.withCoreAPI().usingAuthUser().getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + userFavorites.assertThat().entriesListIsEmpty().and().paginationField("totalItems").is("0"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify request using invalid where parameter returns status 400") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void getFavoritesUsingInvalidWhereParameter() throws Exception + { + restClient.authenticateUser(firstSiteUsers.getOneUserWithRole(UserRole.SiteConsumer)); + restClient.withCoreAPI().usingAuthUser().addSiteToFavorites(firstSiteModel); + restClient.withCoreAPI().usingAuthUser().addFileToFavorites(firstFileModel); + restClient.withCoreAPI().usingAuthUser().addFolderToFavorites(firstFolderModel); + + userFavorites = restClient.withCoreAPI().usingAuthUser() + .where().or().getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.INVALID_ARGUMENT, "WHERE query")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify User gets correct favorites after deleting a favorite") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void checkFavoriteFolderIsRemoved() throws Exception + { + restClient.authenticateUser(firstSiteUsers.getOneUserWithRole(UserRole.SiteManager)); + restClient.withCoreAPI().usingAuthUser().addSiteToFavorites(firstSiteModel); + restClient.withCoreAPI().usingAuthUser().addFileToFavorites(firstFileModel); + restClient.withCoreAPI().usingAuthUser().addFolderToFavorites(firstFolderModel); + + restClient.withCoreAPI().usingAuthUser().deleteFolderFromFavorites(firstFolderModel); + + userFavorites = restClient.withCoreAPI().usingAuthUser().getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + userFavorites.assertThat().entriesListDoesNotContain("targetGuid", firstFolderModel.getNodeRef()) + .and().paginationField("totalItems").is("2"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify get favorites specifying -me- string in place of for request") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void userIsAbleToGetFavoritesWhenUsingMeAsUsername() throws Exception + { + userFavorites = restClient.authenticateUser(userModel).withCoreAPI().usingMe().getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + userFavorites.assertThat().entriesListContains("targetGuid", firstSiteModel.getGuid()).and().entriesListContains("targetGuid", secondSiteModel.getGuid()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify get favorites using empty for where parameter for request") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void userIsAbleToGetFavoritesWhenUsingEmptyWhereParameter() throws Exception + { + userFavorites = restClient.authenticateUser(adminUserModel).withCoreAPI().usingAuthUser().where().getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.INVALID_ARGUMENT, "WHERE query")); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that for invalid maxItems parameter status code returned is 400.") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void checkInvalidMaxItemsStatusCode() throws Exception + { + restClient.authenticateUser(adminUserModel).withParams("maxItems=AB").withCoreAPI().usingUser(adminUserModel).getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary("Invalid paging parameter"); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that for invalid skipCount parameter status code returned is 400.") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void checkInvalidSkipCountStatusCode() throws Exception + { + restClient.authenticateUser(adminUserModel).withParams("skipCount=AB").withCoreAPI().usingUser(adminUserModel).getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary("Invalid paging parameter"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify get favorites when using invalid network id for non-tenant user") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void getFavoritesWhenNetworkIdIsInvalid() throws Exception + { + UserModel networkUserModel = dataUser.createRandomTestUser(); + networkUserModel.setDomain("invalidNetwork"); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(networkUserModel).where().targetSiteExist().getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, networkUserModel.getUsername())); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify get favorites using AND instead of OR in where parameter for request") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void userIsNotAbleToGetFavoritesWhenUsingANDInWhereParameter() throws Exception + { + userFavorites = restClient.withCoreAPI().usingAuthUser().where().targetFolderExist().invalidWhereParameter("AND").targetFileExist().getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.INVALID_ARGUMENT, "WHERE query")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify get favorites using wrong name instead of EXISTS in where parameter for request") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void userIsNotAbleToGetFavoritesWhenUsingWrongWhereParameter() throws Exception + { + userFavorites = restClient.withCoreAPI().usingAuthUser().where().invalidWhereParameter("EXIST((target/site))").targetFileExist().getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.INVALID_ARGUMENT, "WHERE query")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify get favorites except the first one for request") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void userIsAbleToGetFavoritesExceptTheFirstOne() throws Exception + { + userFavorites = restClient.authenticateUser(userModel).withParams("skipCount=1").withCoreAPI().usingUser(userModel).getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + + userFavorites.assertThat().entriesListContains("targetGuid", firstSiteModel.getGuid()) + .and().entriesListContains("targetGuid", secondSiteModel.getGuid()) + .and().entriesListDoesNotContain("targetGuid", thirdSiteModel.getGuid()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify get first two favorites sites") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void userIsAbleToGetFirstTwoFavorites() throws Exception + { + userFavorites = restClient.authenticateUser(userModel).withParams("maxItems=2").withCoreAPI().usingUser(userModel).getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + + userFavorites.assertThat().entriesListContains("targetGuid", thirdSiteModel.getGuid()) + .and().entriesListContains("targetGuid", secondSiteModel.getGuid()) + .and().entriesListDoesNotContain("targetGuid", firstSiteModel.getGuid()) + .getPagination().assertThat().field("maxItems").is("2") + .and().field("hasMoreItems").is("true") + .and().field("count").is("2"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify get favorites sites when using empty values for skipCount and maxItems") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void userIsAbleToGetFavoritesWhenSkipCountAndMaxItemsAreEmpty() throws Exception + { + restClient.authenticateUser(userModel).withParams("skipCount= ").withCoreAPI().usingUser(userModel).getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(String.format(RestErrorModel.INVALID_SKIPCOUNT, " ")); + + restClient.authenticateUser(userModel).withParams("maxItems= ").withCoreAPI().usingUser(userModel).getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(String.format(RestErrorModel.INVALID_MAXITEMS, " ")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify the get favorites request for a high value for skipCount parameter") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void userIsAbleToGetFavoritesWithHighSkipCount() throws Exception + { + userFavorites = restClient.authenticateUser(userModel).withParams("skipCount=999999999").withCoreAPI().usingUser(userModel).getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + + userFavorites.assertThat().entriesListIsEmpty().assertThat().paginationField("skipCount").is("999999999"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify the get favorites request with properties parameter applied") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void userIsAbleToGetFavoritesWithPropertiesParamApplied() throws Exception + { + userFavorites = restClient.authenticateUser(userModel).withParams("properties=targetGuid").withCoreAPI().usingUser(userModel).getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + + RestPersonFavoritesModel restPersonFavoritesModel = userFavorites.getEntries().get(0).onModel(); + restPersonFavoritesModel.assertThat().field("targetGuid").is(thirdSiteModel.getGuid()).and().field("createdAt").isNull(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, description = "Verify entry details for get favorites response with Rest API") + public void checkResponseSchemaForGetFavorites() throws Exception + { + userFavorites = restClient.authenticateUser(userModel).withCoreAPI().usingAuthUser().getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + + RestPersonFavoritesModel restPersonFavoritesModel = userFavorites.getEntries().get(0).onModel(); + restPersonFavoritesModel.assertThat().field("targetGuid").is(thirdSiteModel.getGuid()); + + RestSiteModel restSiteModel = restPersonFavoritesModel.getTarget().getSite(); + restSiteModel.assertThat().field("visibility").is(thirdSiteModel.getVisibility()).and() + .field("guid").is(thirdSiteModel.getGuid()).and() + .field("description").is(thirdSiteModel.getDescription()).and() + .field("id").is(thirdSiteModel.getId()).and() + .field("title").is(thirdSiteModel.getTitle()); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java new file mode 100644 index 0000000000..5eb3fa562e --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java @@ -0,0 +1,158 @@ +package org.alfresco.rest.groups; + +import java.util.UUID; + +import javax.json.Json; +import javax.json.JsonObject; + +import org.alfresco.rest.RestTest; +import org.alfresco.utility.RetryOperation; +import org.alfresco.utility.Utility; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +@Test(groups = {TestGroup.REQUIRE_SOLR}) +public class GroupsTests extends RestTest +{ + private UserModel adminUser, userModel; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + userModel = dataUser.createRandomTestUser(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.GROUPS, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.NODES }, executionType = ExecutionType.SANITY, + description = "Verify creation, listing, updating and deletion of groups.") + public void createListUpdateAndDeleteGroup() throws Exception + { + String groupName = "ZtestGroup" + UUID.randomUUID().toString(); + JsonObject groupBody = Json.createObjectBuilder().add("id", groupName).add("displayName", groupName).build(); + String groupBodyCreate = groupBody.toString(); + + //GroupCreation: + //-ve + restClient.authenticateUser(userModel).withCoreAPI().usingGroups().createGroup(groupBodyCreate); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN); + //+ve + restClient.authenticateUser(adminUser).withCoreAPI().usingParams("include=zones").usingGroups().createGroup(groupBodyCreate) + .assertThat().field("zones").contains("APP.DEFAULT") + .and().field("isRoot").is(true) + .and().field("displayName").is(groupName); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + //ListGroups: + restClient.withCoreAPI().usingParams("orderBy=displayName DESC&maxItems=10").usingGroups().listGroups() + .assertThat().entriesListContains("id", "GROUP_"+groupName) + .and().entriesListDoesNotContain("zones") + .and().paginationField("maxItems").is("10"); + restClient.assertStatusCodeIs(HttpStatus.OK); + + groupBody = Json.createObjectBuilder().add("displayName", "Z"+groupName).build(); + String groupBodyUpdate = groupBody.toString(); + //UpdateGroup: + restClient.withCoreAPI().usingGroups().updateGroupDetails("GROUP_"+groupName, groupBodyUpdate) + .assertThat().field("displayName").is("Z"+groupName) + .and().field("id").is("GROUP_"+groupName) + .and().field("zones").isNull(); + restClient.assertStatusCodeIs(HttpStatus.OK); + + //GetGroupDetails: + restClient.withCoreAPI().usingParams("include=zones").usingGroups().getGroupDetail("GROUP_"+groupName) + .assertThat().field("id").is("GROUP_"+groupName) + .and().field("zones").contains("APP.DEFAULT") + .and().field("isRoot").is(true); + restClient.assertStatusCodeIs(HttpStatus.OK); + + //DeleteGroup: + //-ve + restClient.authenticateUser(userModel).withCoreAPI().usingGroups().deleteGroup("GROUP_"+groupName); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN); + //+ve + restClient.authenticateUser(adminUser).withCoreAPI().usingGroups().deleteGroup("GROUP_"+groupName); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.GROUPS, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.NODES }, executionType = ExecutionType.SANITY, + description = "Verify creation, listing(only for person) and deletion of group memberships. ") + public void createListDeleteGroupMembership() throws Exception + { + String groupName = "ZtestGroup" + UUID.randomUUID().toString(); + JsonObject groupBody = Json.createObjectBuilder().add("id", groupName).add("displayName", groupName).build(); + String groupBodyCreate = groupBody.toString(); + + //GroupCreation: + restClient.authenticateUser(adminUser).withCoreAPI().usingParams("include=zones").usingGroups().createGroup(groupBodyCreate); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + JsonObject groupMembershipBody = Json.createObjectBuilder().add("id", userModel.getUsername()).add("memberType", "PERSON").build(); + String groupMembershipBodyCreate = groupMembershipBody.toString(); + //MembershipCreation: + //-ve + restClient.authenticateUser(userModel).withCoreAPI().usingGroups().createGroupMembership("GROUP_"+groupName, groupMembershipBodyCreate); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN); + //+ve + restClient.authenticateUser(adminUser).withCoreAPI().usingGroups().createGroupMembership("GROUP_"+groupName, groupMembershipBodyCreate); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + //ListPersonMembership + restClient.authenticateUser(userModel).withCoreAPI().usingUser(userModel).listGroupMemberships() + .assertThat().entriesListContains("id", "GROUP_"+groupName); + restClient.assertStatusCodeIs(HttpStatus.OK); + + //DeleteGroupMembership + //-ve + restClient.withCoreAPI().usingGroups().deleteGroupMembership("GROUP_"+groupName, userModel.getUsername()); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN); + //+ve + restClient.authenticateUser(adminUser).withCoreAPI().usingGroups().deleteGroupMembership("GROUP_"+groupName, userModel.getUsername()); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + //ListAgainPersonMembership + restClient.withCoreAPI().usingUser(userModel).listGroupMemberships() + .assertThat().entriesListDoesNotContain("id", "GROUP_"+groupName); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.GROUPS, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.NODES }, executionType = ExecutionType.SANITY, + description = "Verify listing of group memberships.") + public void listGroupMembership() throws Exception + { + String groupName = "testGroup" + UUID.randomUUID().toString(); + JsonObject groupBody = Json.createObjectBuilder().add("id", groupName).add("displayName", groupName).build(); + String groupBodyCreate = groupBody.toString(); + + //GroupCreation: + restClient.authenticateUser(adminUser).withCoreAPI().usingParams("include=zones").usingGroups().createGroup(groupBodyCreate); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + JsonObject groupMembershipBody = Json.createObjectBuilder().add("id", userModel.getUsername()).add("memberType", "PERSON").build(); + String groupMembershipBodyCreate = groupMembershipBody.toString(); + + //MembershipCreation + restClient.withCoreAPI().usingGroups().createGroupMembership("GROUP_"+groupName, groupMembershipBodyCreate) + .assertThat().field("displayName").is(userModel.getUsername()) + .and().field("id").is(userModel.getUsername()) + .and().field("memberType").is("PERSON"); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + //ListGroupMembership + RetryOperation op = new RetryOperation(){ + public void execute() throws Exception{ + restClient.withCoreAPI().usingGroups().listGroupMemberships("GROUP_"+groupName) + .assertThat().entriesListContains("id", userModel.getUsername()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + }; + Utility.sleep(1000, 35000, op);// Allow indexing to complete. + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodesActionDefinitionTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodesActionDefinitionTests.java new file mode 100644 index 0000000000..596ebf72cf --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodesActionDefinitionTests.java @@ -0,0 +1,87 @@ +package org.alfresco.rest.nodes; + + +import static org.testng.Assert.assertFalse; + +import org.alfresco.rest.RestTest; + +import org.alfresco.rest.model.RestActionDefinitionModelsCollection; +import org.alfresco.rest.model.builder.NodesBuilder; +import org.alfresco.rest.model.builder.NodesBuilder.NodeDetail; +import org.alfresco.utility.model.ContentModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.Test; + +public class NodesActionDefinitionTests extends RestTest +{ + + + @TestRail(section = { TestGroup.REST_API,TestGroup.NODES }, executionType = ExecutionType.SANITY, + description = "Verify actions") + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.SANITY}) + public void testActionDefinition() throws Exception + { + restClient.authenticateUser(dataContent.getAdminUser()); + + /* + * Create the following file structure for preconditions : + * - sourceFolder + * - file + */ + NodesBuilder nodesBuilder = restClient.withCoreAPI().usingNode(ContentModel.my()).defineNodes(); + NodeDetail sourceFolder = nodesBuilder.folder("sourceFolder"); + NodeDetail file = sourceFolder.file("file"); + ContentModel fileActionDefinitions = new ContentModel(); + fileActionDefinitions.setNodeRef(file.getId()); + + RestActionDefinitionModelsCollection restActionDefinitions = restClient.withCoreAPI().usingNode(fileActionDefinitions).getActionDefinitions(); + restClient.assertStatusCodeIs(HttpStatus.OK); + assertFalse(restActionDefinitions.isEmpty()); + restActionDefinitions.assertThat().entriesListContains("name", "copy"); + restActionDefinitions.assertThat().entriesListContains("name", "move"); + restActionDefinitions.assertThat().entriesListContains("name", "check-out"); + restActionDefinitions.assertThat().entriesListContains("name", "check-in"); + + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.NODES }, executionType = ExecutionType.REGRESSION, + description = "Verify actions negative request") + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.REGRESSION}) + public void testActionDefinitionNegative() throws Exception{ + + NodesBuilder nodesBuilder = restClient.withCoreAPI().usingNode(ContentModel.my()).defineNodes(); + NodeDetail sourceFolder = nodesBuilder.folder("sourceFolder"); + ContentModel validNode = new ContentModel(); + validNode.setNodeRef(sourceFolder.getId()); + + // Non-existent node ID + { + ContentModel fakeNode = new ContentModel(); + fakeNode.setNodeRef("750a2867-ecfa-478c-8343-fa0e39d27be3"); + restClient.authenticateUser(dataContent.getAdminUser()).withCoreAPI().usingNode(fakeNode).getActionDefinitions(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND); + } + + // Badly formed request -> 400 + { + restClient.authenticateUser(dataContent.getAdminUser()).withParams("skipCount=-1").withCoreAPI().usingNode(validNode) + .getActionDefinitions(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST); + + } + + // Unauthorized -> 401 + { + + UserModel userUnauthorized = new UserModel("invalid-user", "invalid-pasword"); + restClient.authenticateUser(userUnauthorized).withCoreAPI().usingNode(validNode).getActionDefinitions(); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + + } + } + +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodesContentAndVersioningTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodesContentAndVersioningTests.java new file mode 100644 index 0000000000..9e2d0702bc --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodesContentAndVersioningTests.java @@ -0,0 +1,319 @@ +package org.alfresco.rest.nodes; + +import static org.alfresco.utility.report.log.Step.STEP; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNotSame; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertSame; +import static org.testng.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; +import java.io.RandomAccessFile; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.JsonBodyGenerator; +import org.alfresco.rest.core.RestResponse; +import org.alfresco.rest.model.RestNodeModel; +import org.alfresco.rest.model.RestVersionModel; +import org.alfresco.rest.model.RestVersionModelsCollection; +import org.alfresco.rest.model.body.RestNodeLockBodyModel; +import org.alfresco.utility.Utility; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +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.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.json.JSONObject; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * + * @author mpopa + * + */ +public class NodesContentAndVersioningTests extends RestTest +{ + private UserModel user1, user2; + private SiteModel site1, site2; + private FileModel file1, file2; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + user1 = dataUser.createRandomTestUser(); + user2 = dataUser.createRandomTestUser(); + site1 = dataSite.usingUser(user1).createPublicRandomSite(); + site2 = dataSite.usingUser(user2).createPublicRandomSite(); + file1 = dataContent.usingUser(user1).usingSite(site1).createContent(DocumentType.TEXT_PLAIN); + file2 = dataContent.usingUser(user2).usingSite(site2).createContent(DocumentType.TEXT_PLAIN); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.NODES }, executionType = ExecutionType.SANITY, description = "Verify file name in Content-Disposition header") + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.SANITY }) + public void checkFileNameWithRegularCharsInHeader() throws Exception + { + restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("attachment=false").getNodeContent(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restClient.assertHeaderValueContains("Content-Disposition", String.format("filename=\"%s\"", file1.getName())); + } + + + + + @Bug(id = "MNT-17545", description = "HTTP Header Injection in ContentStreamer", status = Bug.Status.FIXED) + @TestRail(section = { TestGroup.REST_API, + TestGroup.NODES }, executionType = ExecutionType.REGRESSION, description = "Verify file name with special chars is escaped in Content-Disposition header") + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.REGRESSION }) + public void checkFileNameWithSpecialCharsInHeader() throws Exception + { + char c1 = 127; + char c2 = 31; + char c3 = 256; + FileModel file = dataContent.usingUser(user2).usingSite(site2).createContent(new FileModel("\ntest" + c1 + c2 + c3, FileType.TEXT_PLAIN)); + restClient.authenticateUser(user2).withCoreAPI().usingNode(file).usingParams("attachment=false").getNodeContent(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restClient.assertHeaderValueContains("Content-Disposition", "filename=\" test \""); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, + TestGroup.NODES }, executionType = ExecutionType.SANITY, description = "Verify that alfresco returns the correct encoding for files created via REST.") + public void verifyFileEncodingUsingRestAPI() throws Exception + { + STEP("1. Create a folder, two text file templates and define the expected encoding."); + FileModel utf8File = new FileModel("utf8File", FileType.TEXT_PLAIN); + FileModel iso8859File = new FileModel("iso8859File", FileType.TEXT_PLAIN); + FolderModel folder = dataContent.usingUser(user1).usingSite(site1).createFolder(FolderModel.getRandomFolderModel()); + String utf8Type = "text/plain;charset=UTF-8"; + String iso8859Type = "text/plain;charset=ISO-8859-1"; + + STEP("2. Using multipart data upload (POST nodes/{nodeId}/children) the UTF-8 encoded file."); + restClient.authenticateUser(user1).configureRequestSpec().addMultiPart("filedata", Utility.getResourceTestDataFile("UTF-8File.txt")); + RestNodeModel fileNode = restClient.withCoreAPI().usingNode(folder).createNode(); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + utf8File.setNodeRef(fileNode.getId()); + + STEP("3. Using multipart data upload (POST nodes/{nodeId}/children) the ISO-8859-1 file."); + restClient.configureRequestSpec().addMultiPart("filedata", Utility.getResourceTestDataFile("iso8859File.txt")); + fileNode = restClient.withCoreAPI().usingNode(folder).createNode(); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + iso8859File.setNodeRef(fileNode.getId()); + + STEP("4. Retrieve the nodes and verify that the content type is the expected one (GET nodes/{nodeId})."); + restClient.withCoreAPI().usingNode(utf8File).getNodeContent().assertThat().contentType(utf8Type); + restClient.withCoreAPI().usingNode(iso8859File).getNodeContent().assertThat().contentType(iso8859Type); + } + + + // This test takes around 30 minutes to complete so it will be ignored by default + @Test(enabled=false, groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.NODES }, + executionType = ExecutionType.REGRESSION, description = "Verify that the node content is streamed directly to the client and not buffered in memory.") + public void verifyUploadDownloadLargeFileUsingRestAPI() throws Exception + { + Integer largeFileSizeBytes = Integer.MAX_VALUE; + String largeFileName = "largeFile.tmp"; + String tempFolderPath = getSystemTempDir().getAbsolutePath(); + + STEP("1. Create a folder and a large file"); + FolderModel folder = dataContent.usingUser(user1).usingSite(site1).createFolder(FolderModel.getRandomFolderModel()); + createRandomFileInDirectory(tempFolderPath, largeFileName, largeFileSizeBytes); + + STEP("2. Using multipart data upload for the large file (POST nodes/{nodeId}/children)."); + File largeFile = new File(tempFolderPath, largeFileName); + FileModel largeFileModel = new FileModel(largeFileName, FileType.UNDEFINED); + restClient.authenticateUser(user1).configureRequestSpec().addMultiPart("filedata", largeFile); + RestNodeModel fileNode = restClient.withCoreAPI().usingNode(folder).createNode(); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + largeFileModel.setNodeRef(fileNode.getId()); + + STEP("3. Retrieve the content of the node without running out of memory (GET nodes/{nodeId}/content)."); + RestResponse nodeContent = restClient.withCoreAPI().usingNode(largeFileModel).getNodeContent(); + restClient.assertStatusCodeIs(HttpStatus.OK); + assertEquals(Integer.valueOf(nodeContent.getResponse().getHeader("Content-Length")), largeFileSizeBytes); + + largeFile.delete(); + } + + public static File getSystemTempDir() throws Exception + { + String systemTempDirPath = System.getProperty("java.io.tmpdir"); + if (systemTempDirPath == null) + { + throw new Exception("System property not available: " + "java.io.tmpdir"); + } + File systemTempDir = new File(systemTempDirPath); + return systemTempDir; + } + + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.NODES }, executionType = ExecutionType.SANITY, description = "Verify updating a node content.") + public void testUpdateNodeContent() throws Exception + { + STEP("1. Retrieve the node in order to get data to compare after update GET /nodes/{nodeId}?include=path."); + RestNodeModel initialNode = restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include=path").getNode(); + restClient.assertStatusCodeIs(HttpStatus.OK); + + STEP("2. Update the node content (different from the initial one) PUT /nodes/{nodeId}/content?majorVersion=true&name=newfile.txt."); + File updatedConentFile = Utility.getResourceTestDataFile("sampleContent.txt"); + RestNodeModel updatedBodyNode = restClient.withCoreAPI().usingNode(file1).usingParams("majorVersion=true&name=newfile.txt").updateNodeContent(updatedConentFile); + restClient.assertStatusCodeIs(HttpStatus.OK); + + STEP("3. Compare contentSize, modifiedAt, name and version, they should be different."); + assertNotSame(initialNode.getContent().getSizeInBytes(), updatedBodyNode.getContent().getSizeInBytes()); + assertNotSame(initialNode.getModifiedAt(), updatedBodyNode.getModifiedAt()); + assertNotSame(initialNode.getName(), updatedBodyNode.getName()); + + String initialNodeVersion = new JSONObject(initialNode.toJson()).getJSONObject("properties").getString("cm:versionLabel"); + String updatedBodyNodeVersion = new JSONObject(updatedBodyNode.toJson()).getJSONObject("properties").getString("cm:versionLabel"); + assertTrue(updatedBodyNodeVersion.charAt(0) > initialNodeVersion.charAt(0)); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.NODES }, executionType = ExecutionType.SANITY, description = "Test copy a node.") + public void testCopyNode() throws Exception + { + STEP("1. Create a lock and lock the node POST /nodes/{nodeId}/lock?include=path,isLocked."); + RestNodeLockBodyModel lockBodyModel = new RestNodeLockBodyModel(); + lockBodyModel.setLifetime("EPHEMERAL"); + lockBodyModel.setTimeToExpire(20); + lockBodyModel.setType("FULL"); + RestNodeModel initialNode = restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include=path,isLocked").lockNode(lockBodyModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + + STEP("2. With another user(that has access to the file), copy the node to another path POST /nodes/{nodeId}/copy?include=path,isLocked."); + String postBody = JsonBodyGenerator.keyValueJson("targetParentId", site2.getGuid()); + RestNodeModel copiedNode = restClient.authenticateUser(user2).withCoreAPI().usingNode(file1).usingParams("include=path,isLocked").copyNode(postBody); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + STEP("3. ParentId, createdAt, path and lock are different, but the nodes have the same contentSize."); + assertNotSame(copiedNode.getParentId(), initialNode.getParentId()); + assertNotSame(copiedNode.getCreatedAt(), initialNode.getCreatedAt()); + assertNotSame(copiedNode.getPath(), initialNode.getPath()); + assertTrue(initialNode.getIsLocked()); + assertSame(copiedNode.getContent().getSizeInBytes(), initialNode.getContent().getSizeInBytes()); + assertFalse(copiedNode.getIsLocked()); + + STEP("4. Unlock the node (this node may be used in the next tests)."); + initialNode = restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include=isLocked").unlockNode(); + restClient.assertStatusCodeIs(HttpStatus.OK); + assertFalse(initialNode.getIsLocked()); + } + + @Bug(id = "REPO-4050") + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, + TestGroup.NODES }, executionType = ExecutionType.SANITY, description = "Test retrieving node versions, a specific version and version content.") + public void testGetVersionContent() throws Exception + { + file2 = dataContent.usingUser(user2).usingSite(site2).createContent(DocumentType.TEXT_PLAIN); + File sampleFile = Utility.getResourceTestDataFile("sampleContent.txt"); + + STEP("1. Update the node content in order to increase version(one minor and one major) PUT /nodes/{nodeId}/content."); + // minor version update + restClient.authenticateUser(user2).withCoreAPI().usingNode(file2).updateNodeContent(sampleFile); + restClient.assertStatusCodeIs(HttpStatus.OK); + // major version update + restClient.authenticateUser(user2).withCoreAPI().usingParams("majorVersion=true").usingNode(file2).updateNodeContent(sampleFile); + restClient.assertStatusCodeIs(HttpStatus.OK); + + STEP("2. List node version history GET /nodes/{nodeId}/versions. And verify that first (in the list) version is 2.0 and last is 1.0."); + RestVersionModelsCollection versionListing = restClient.withCoreAPI().usingNode(file2).listVersionHistory(); + restClient.assertStatusCodeIs(HttpStatus.OK); + // additional check that the properties are not displayed by default. + assertEquals(versionListing.getEntries().get(versionListing.getPagination().getCount() - 1).onModel().getId(), "1.0"); + assertEquals(versionListing.getEntries().get(0).onModel().getId(), "2.0"); + assertNull(versionListing.getEntries().get(0).onModel().getProperties()); + + STEP("3. List node version using skipCount(1),maxItems(1) and include(properties) GET /nodes/{nodeId}/versions?include=properties&skipCount=1&maxItems=1"); + versionListing = restClient.withCoreAPI().usingParams("include=properties&skipCount=1&maxItems=1").usingNode(file2).listVersionHistory(); + restClient.assertStatusCodeIs(HttpStatus.OK); + // we expect only version 1.1 to be retrieved with the value for properties. + RestVersionModel version = versionListing.getEntries().get(0).onModel(); + assertNotNull(version.getProperties()); + assertEquals(version.getId(), "1.1"); + assertEquals(versionListing.getPagination().getMaxItems(), 1); + assertEquals(versionListing.getPagination().getSkipCount(), 1); + assertEquals(versionListing.getPagination().getCount(), 1); + + STEP("4. Get version information for version 1.1 GET /nodes/{nodeId}/versions/{versionId} ."); + RestVersionModel version11 = restClient.withCoreAPI().usingNode(file2).getVersionInformation("1.1"); + restClient.assertStatusCodeIs(HttpStatus.OK); + // aspectNames and properties are displayed by default. We compare + // id,contentSize and name with the values from v1.1, taken from listing all + // versions. + assertNotNull(version11.getAspectNames()); + assertNotNull(version11.getProperties()); + assertEquals(version.getId(), version11.getId()); + assertEquals(version.getContent().getSizeInBytes(), version11.getContent().getSizeInBytes()); + assertEquals(version.getName(), version11.getName()); + + STEP("5. Retrieve version 2.0 content GET /nodes/{nodeId}/versions/{versionId}/content"); + // verify the content is the same as the uploaded file and check in headers for + // Content-Disposition to validate the download as attachment and fileName. + // wait for content to be picked up on AWS QS stacks + Utility.sleep(1000, 60000, () -> { + RestResponse versionContent = restClient.withCoreAPI().usingNode(file2).getVersionContent("2.0"); + restClient.assertStatusCodeIs(HttpStatus.OK); + + assertEquals("Sample text.\n", versionContent.getResponse().body().asString()); + restClient.assertHeaderValueContains("Content-Disposition", "attachment"); + restClient.assertHeaderValueContains("Content-Disposition", String.format("filename=\"%s\"", file2.getName())); + }); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.NODES }, executionType = ExecutionType.SANITY, description = "Test revert and delete a node version.") + public void testRevertDeleteVersion() throws Exception + { + STEP("1. Revert to version 1.0 POST /nodes/{nodeId}/versions/{versionId}/revert"); + RestVersionModel version = restClient.authenticateUser(user2).withCoreAPI().usingNode(file2).revertVersion("1.0", new String("{}")); + restClient.assertStatusCodeIs(HttpStatus.OK); + String nodeVersionType = new JSONObject(version.toJson()).getJSONObject("properties").getString("cm:versionType"); + assertEquals(nodeVersionType, "MINOR"); + String nodeVersion = version.getId(); + + STEP("2. Revert to last minor version /nodes/{nodeId}/versions/{versionId}/revert"); + version = restClient.withCoreAPI().usingNode(file2).revertVersion(nodeVersion, new String("{\"majorVersion\": true}")); + restClient.assertStatusCodeIs(HttpStatus.OK); + nodeVersionType = new JSONObject(version.toJson()).getJSONObject("properties").getString("cm:versionType"); + assertEquals(nodeVersionType, "MAJOR"); + assertTrue(nodeVersion.charAt(0) + 1 == version.getId().charAt(0)); + + STEP("3. Delete last MINOR version DELETE /nodes/{nodeId}/versions/{versionId}"); + restClient.withCoreAPI().usingNode(file2).deleteNodeVersion(nodeVersion); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withCoreAPI().usingNode(file2).getVersionInformation(nodeVersion); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.NODES }, executionType = ExecutionType.SANITY, description = "Verify file name in Content Range header") + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.SANITY }) + public void checkFileNameContentRangeHeader() throws Exception + { + restClient.configureRequestSpec().addHeader("content-range", "bytes=1-10"); + restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).getNodeContent(); + restClient.assertStatusCodeIs(HttpStatus.PARTIAL_CONTENT); + restClient.assertHeaderValueContains("content-range", "bytes 1-10"); + restClient.assertHeaderValueContains("content-length", String.valueOf(10)); + } + + + private void createRandomFileInDirectory(String path, String fileName, int size) throws IOException { + String fullPath = new File(path, fileName).getPath(); + + RandomAccessFile file = new RandomAccessFile(fullPath,"rw"); + file.setLength(size); + file.close(); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodesLockTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodesLockTests.java new file mode 100644 index 0000000000..ce19991f6b --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodesLockTests.java @@ -0,0 +1,761 @@ +package org.alfresco.rest.nodes; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestNodeModel; +import org.alfresco.rest.model.body.RestNodeLockBodyModel; +import org.alfresco.rest.search.RestRequestFilterQueryModel; +import org.alfresco.rest.search.RestRequestQueryModel; +import org.alfresco.rest.search.SearchRequest; +import org.alfresco.rest.search.SearchResponse; +import org.alfresco.utility.Utility; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.model.FileModel; +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.alfresco.utility.report.Bug; +import org.alfresco.utility.report.Bug.Status; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import static org.alfresco.utility.report.log.Step.STEP; + +public class NodesLockTests extends RestTest +{ + private UserModel user1, user2, adminUser; + private SiteModel publicSite; + private FileModel file1; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + publicSite = dataSite.usingUser(adminUser).createPublicRandomSite(); + user1 = dataUser.createRandomTestUser(); + user2 = dataUser.createRandomTestUser(); + dataUser.addUserToSite(user1, publicSite, UserRole.SiteCollaborator); + user1.setUserRole(UserRole.SiteCollaborator); + dataUser.addUserToSite(user2, publicSite, UserRole.SiteCollaborator); + user2.setUserRole(UserRole.SiteCollaborator); + + } + + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.NODES }, executionType = ExecutionType.REGRESSION, + description = "Verify Collaborator can not lock PERSISTENT after EPHEMERAL lock made by different user") + public void lockEphemeralAndRelockPersistentDifferentUser() throws Exception + { + STEP("1. Administrator adds a file in the site."); + file1 = dataContent.usingUser(adminUser).usingSite(publicSite).createContent(DocumentType.TEXT_PLAIN); + + STEP("2. Verify with admin that the file is not locked."); + RestNodeModel file1Model1 = restClient.authenticateUser(adminUser).withCoreAPI().usingNode(file1).usingParams("include=isLocked").getNode(); + file1Model1.assertThat().field("isLocked").is(false); + + STEP("3. Lock the file using mode EPHEMERAL for 20 seconds with user1 (POST nodes/{nodeId}/lock)."); + RestNodeLockBodyModel lockBodyModel = new RestNodeLockBodyModel(); + lockBodyModel.setLifetime("EPHEMERAL"); + lockBodyModel.setTimeToExpire(20); + lockBodyModel.setType("FULL"); + restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include=isLocked").lockNode(lockBodyModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + + STEP("4. Verify with user1 that the file is locked."); + RestNodeModel file1Model2 = restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include=isLocked").getNode(); + file1Model2.assertThat().field("isLocked").is(true) + .assertThat().field("properties").contains("lockLifetime=EPHEMERAL") + .assertThat().field("properties").contains("lockType=READ_ONLY_LOCK"); + + STEP("5. Cannot lock the file using mode PERSISTENT with user2 while the file is still locked"); + RestNodeLockBodyModel lockBodyModel2 = new RestNodeLockBodyModel(); + lockBodyModel2.setLifetime("PERSISTENT"); + lockBodyModel2.setTimeToExpire(20); + lockBodyModel2.setType("ALLOW_OWNER_CHANGES"); + restClient.authenticateUser(user2).withCoreAPI().usingNode(file1).usingParams("include=isLocked").lockNode(lockBodyModel2); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY).assertLastError() + .containsErrorKey(RestErrorModel.API_DEFAULT_ERRORKEY) + .containsSummary(String.format(RestErrorModel.LOCKED_NODE_SUMMARY, file1.getNodeRefWithoutVersion())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.NODES }, executionType = ExecutionType.REGRESSION, + description = "Verify Collaborator can not lock EPHEMERAL after EPHEMERAL lock made by different user") + public void lockEphemeralAndRelockEphemeralDifferentUser() throws Exception + { + STEP("1. Adds a file in the site by administrator."); + file1 = dataContent.usingUser(adminUser).usingSite(publicSite).createContent(DocumentType.TEXT_PLAIN); + + STEP("2. Verify with admin that the file is not locked."); + RestNodeModel file1Model1 = restClient.authenticateUser(adminUser).withCoreAPI().usingNode(file1).usingParams("include=isLocked").getNode(); + file1Model1.assertThat().field("isLocked").is(false); + + STEP("3. Lock the file using mode EPHEMERAL with user1 (POST nodes/{nodeId}/lock)."); + RestNodeLockBodyModel lockBodyModel = new RestNodeLockBodyModel(); + lockBodyModel.setLifetime("EPHEMERAL"); + lockBodyModel.setTimeToExpire(20); + lockBodyModel.setType("FULL"); + restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include?isLocked").lockNode(lockBodyModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + + STEP("4. Verify with user1 that the file is locked."); + RestNodeModel file1Model2 = restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include=isLocked").getNode(); + file1Model2.assertThat().field("isLocked").is(true) + .assertThat().field("properties").contains("lockLifetime=EPHEMERAL") + .assertThat().field("properties").contains("lockType=READ_ONLY_LOCK"); + + STEP("5. Cannot lock the file using mode EPHEMERAL with user2 while the file is still locked"); + RestNodeLockBodyModel lockBodyModel2 = new RestNodeLockBodyModel(); + lockBodyModel2.setLifetime("EPHEMERAL"); + lockBodyModel2.setTimeToExpire(20); + lockBodyModel2.setType("FULL"); + restClient.authenticateUser(user2).withCoreAPI().usingNode(file1).usingParams("include=isLocked").lockNode(lockBodyModel2); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY).assertLastError() + .containsErrorKey(RestErrorModel.API_DEFAULT_ERRORKEY) + .containsSummary(String.format(RestErrorModel.LOCKED_NODE_SUMMARY, file1.getNodeRefWithoutVersion())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.NODES }, executionType = ExecutionType.REGRESSION, + description = "Verify Collaborator can lock EPHEMERAL after EPHEMERAL lock made by same user") + public void lockEphemeralAndRelockEphemeralSameUser() throws Exception + { + STEP("1. Adds a file in the site by administrator."); + file1 = dataContent.usingUser(adminUser).usingSite(publicSite).createContent(DocumentType.TEXT_PLAIN); + + STEP("2. Verify with admin that the file is not locked."); + RestNodeModel file1Model1 = restClient.authenticateUser(adminUser).withCoreAPI().usingNode(file1).usingParams("include=isLocked").getNode(); + file1Model1.assertThat().field("isLocked").is(false); + + STEP("3. Lock the file using mode EPHEMERAL with user1 (POST nodes/{nodeId}/lock)."); + RestNodeLockBodyModel lockBodyModel = new RestNodeLockBodyModel(); + lockBodyModel.setLifetime("EPHEMERAL"); + lockBodyModel.setTimeToExpire(20); + lockBodyModel.setType("FULL"); + restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include?isLocked").lockNode(lockBodyModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + + STEP("4. Verify with user1 that the file is locked."); + RestNodeModel file1Model2 = restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include=isLocked").getNode(); + file1Model2.assertThat().field("isLocked").is(true) + .assertThat().field("properties").contains("lockLifetime=EPHEMERAL") + .assertThat().field("properties").contains("lockType=READ_ONLY_LOCK"); + + STEP("5. Lock the file using mode EPHEMERAL with user1 while the file is still locked"); + RestNodeLockBodyModel lockBodyModel2 = new RestNodeLockBodyModel(); + lockBodyModel2.setLifetime("EPHEMERAL"); + lockBodyModel2.setTimeToExpire(20); + lockBodyModel2.setType("FULL"); + RestNodeModel file1Model3 = restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include=isLocked").lockNode(lockBodyModel2); + restClient.assertStatusCodeIs(HttpStatus.OK); + file1Model3.assertThat().field("isLocked").is(true) + .assertThat().field("properties").contains("lockLifetime=EPHEMERAL") + .assertThat().field("properties").contains("lockType=READ_ONLY_LOCK"); + } + + @Bug(id = "MNT-17612", status = Status.FIXED, description = "AccessDeniedException in AOS Edit Offline Upload New Version") + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.NODES }, executionType = ExecutionType.REGRESSION, + description = "Verify Collaborator can lock PERSISTENT after EPHEMERAL lock made by same user") + public void lockEphemeralAndRelockPersistentSameUser() throws Exception + { + STEP("1. Adds a file in the site by administrator."); + file1 = dataContent.usingUser(adminUser).usingSite(publicSite).createContent(DocumentType.TEXT_PLAIN); + + STEP("2. Verify with admin that the file is not locked."); + RestNodeModel file1Model1 = restClient.authenticateUser(adminUser).withCoreAPI().usingNode(file1).usingParams("include=isLocked").getNode(); + file1Model1.assertThat().field("isLocked").is(false); + + STEP("3. Lock the file using mode EPHEMERAL with user1 (POST nodes/{nodeId}/lock)."); + RestNodeLockBodyModel lockBodyModel = new RestNodeLockBodyModel(); + lockBodyModel.setLifetime("EPHEMERAL"); + lockBodyModel.setTimeToExpire(2); + lockBodyModel.setType("FULL"); + restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include?isLocked").lockNode(lockBodyModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + + STEP("4. Verify with user1 that the file is locked."); + RestNodeModel file1Model2 = restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include=isLocked").getNode(); + file1Model2.assertThat().field("isLocked").is(true) + .assertThat().field("properties").contains("lockLifetime=EPHEMERAL") + .assertThat().field("properties").contains("lockType=READ_ONLY_LOCK"); + + STEP("5. Lock the file using mode PERSISTENT with user1 while the file is still locked"); + RestNodeLockBodyModel lockBodyModel2 = new RestNodeLockBodyModel(); + lockBodyModel2.setLifetime("PERSISTENT"); + lockBodyModel2.setTimeToExpire(20); + lockBodyModel2.setType("ALLOW_OWNER_CHANGES"); + RestNodeModel file1Model3 = restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include=isLocked").lockNode(lockBodyModel2); + restClient.assertStatusCodeIs(HttpStatus.OK); + file1Model3.assertThat().field("isLocked").is(true) + .assertThat().field("properties").contains("lockLifetime=EPHEMERAL") + .assertThat().field("properties").contains("lockType=READ_ONLY_LOCK"); + + STEP("6. Verify that the file is locked PERSISTENT only after EPHEMERAL lock has expired"); + try{Thread.sleep(2500);}finally{} + RestNodeModel file1Model4 = restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include=isLocked").getNode(); + file1Model4.assertThat().field("isLocked").is(true) + .assertThat().field("properties").contains("lockLifetime=PERSISTENT") + .assertThat().field("properties").contains("lockType=WRITE_LOCK"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.NODES }, executionType = ExecutionType.REGRESSION, + description = "Verify Collaborator can not lock EPHEMERAL after PERSISTENT lock made by different user") + public void lockPersistentAndRelockEphemeralDifferentUser() throws Exception + { + STEP("1. Adds a file in the site by administrator."); + file1 = dataContent.usingUser(adminUser).usingSite(publicSite).createContent(DocumentType.TEXT_PLAIN); + + STEP("2. Verify with admin that the file is not locked."); + RestNodeModel file1Model1 = restClient.authenticateUser(adminUser).withCoreAPI().usingNode(file1).usingParams("include=isLocked").getNode(); + file1Model1.assertThat().field("isLocked").is(false); + + STEP("3. Lock the file using mode PERSISTENT with user1 (POST nodes/{nodeId}/lock)."); + RestNodeLockBodyModel lockBodyModel = new RestNodeLockBodyModel(); + lockBodyModel.setLifetime("PERSISTENT"); + lockBodyModel.setTimeToExpire(20); + lockBodyModel.setType("ALLOW_OWNER_CHANGES"); + restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include?isLocked").lockNode(lockBodyModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + + STEP("4. Verify with user1 that the file is locked."); + RestNodeModel file1Model2 = restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include=isLocked").getNode(); + file1Model2.assertThat().field("isLocked").is(true) + .assertThat().field("properties").contains("lockLifetime=PERSISTENT") + .assertThat().field("properties").contains("lockType=WRITE_LOCK"); + + STEP("5. Cannot lock the file using mode EPHEMERAL with user2 while the file is still locked"); + RestNodeLockBodyModel lockBodyModel2 = new RestNodeLockBodyModel(); + lockBodyModel2.setLifetime("EPHEMERAL"); + lockBodyModel2.setTimeToExpire(20); + lockBodyModel2.setType("FULL"); + restClient.authenticateUser(user2).withCoreAPI().usingNode(file1).usingParams("include=isLocked").lockNode(lockBodyModel2); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY).assertLastError() + .containsErrorKey(RestErrorModel.API_DEFAULT_ERRORKEY) + .containsSummary(String.format(RestErrorModel.LOCKED_NODE_SUMMARY, file1.getNodeRefWithoutVersion())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.NODES }, executionType = ExecutionType.REGRESSION, + description = "Verify Collaborator can not lock PERSISTENT after PERSISTENT lock made by different user") + public void lockPersistentAndRelockPersistentDifferentUser() throws Exception + { + STEP("1. Adds a file in the site by administrator."); + file1 = dataContent.usingUser(adminUser).usingSite(publicSite).createContent(DocumentType.TEXT_PLAIN); + + STEP("2. Verify with admin that the file is not locked."); + RestNodeModel file1Model1 = restClient.authenticateUser(adminUser).withCoreAPI().usingNode(file1).usingParams("include=isLocked").getNode(); + file1Model1.assertThat().field("isLocked").is(false); + + STEP("3. Lock the file using mode PERSISTENT with user1 (POST nodes/{nodeId}/lock)."); + RestNodeLockBodyModel lockBodyModel = new RestNodeLockBodyModel(); + lockBodyModel.setLifetime("PERSISTENT"); + lockBodyModel.setTimeToExpire(20); + lockBodyModel.setType("ALLOW_OWNER_CHANGES"); + restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include?isLocked").lockNode(lockBodyModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + + STEP("4. Verify with user1 that the file is locked."); + RestNodeModel file1Model2 = restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include=isLocked").getNode(); + file1Model2.assertThat().field("isLocked").is(true) + .assertThat().field("properties").contains("lockLifetime=PERSISTENT") + .assertThat().field("properties").contains("lockType=WRITE_LOCK"); + + STEP("5. Cannot lock the file using mode PERSISTENT with user2 while the file is still locked"); + RestNodeLockBodyModel lockBodyModel2 = new RestNodeLockBodyModel(); + lockBodyModel2.setLifetime("PERSISTENT"); + lockBodyModel2.setTimeToExpire(20); + lockBodyModel2.setType("ALLOW_OWNER_CHANGES"); + restClient.authenticateUser(user2).withCoreAPI().usingNode(file1).usingParams("include=isLocked").lockNode(lockBodyModel2); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY).assertLastError() + .containsErrorKey(RestErrorModel.API_DEFAULT_ERRORKEY) + .containsSummary(String.format(RestErrorModel.LOCKED_NODE_SUMMARY, file1.getNodeRefWithoutVersion())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.NODES }, executionType = ExecutionType.REGRESSION, + description = "Verify Collaborator can lock EPHEMERAL after PERSISTENT lock made by different user is expired") + public void lockPersistentAndRelockEphemeralAfterExpiredLockDifferentUser() throws Exception + { + STEP("1. Adds a file in the site by administrator."); + file1 = dataContent.usingUser(adminUser).usingSite(publicSite).createContent(DocumentType.TEXT_PLAIN); + + STEP("2. Verify with admin that the file is not locked."); + RestNodeModel file1Model1 = restClient.authenticateUser(adminUser).withCoreAPI().usingNode(file1).usingParams("include=isLocked").getNode(); + file1Model1.assertThat().field("isLocked").is(false); + + STEP("3. Lock the file using mode PERSISTENT with user1 (POST nodes/{nodeId}/lock)."); + RestNodeLockBodyModel lockBodyModel = new RestNodeLockBodyModel(); + lockBodyModel.setLifetime("PERSISTENT"); + lockBodyModel.setTimeToExpire(1); + lockBodyModel.setType("ALLOW_OWNER_CHANGES"); + restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include?isLocked").lockNode(lockBodyModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + + STEP("4. Verify with admin that the file is locked."); + RestNodeModel file1Model2 = restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include=isLocked").getNode(); + file1Model2.assertThat().field("isLocked").is(true) + .assertThat().field("properties").contains("lockLifetime=PERSISTENT") + .assertThat().field("properties").contains("lockType=WRITE_LOCK"); + + STEP("5. Lock the file using mode EPHEMERAL with user2 while the first lock has expired"); + RestNodeLockBodyModel lockBodyModel2 = new RestNodeLockBodyModel(); + lockBodyModel2.setLifetime("EPHEMERAL"); + lockBodyModel2.setTimeToExpire(20); + lockBodyModel2.setType("FULL"); + try{Thread.sleep(1500);}finally{} + RestNodeModel file1Model3 = restClient.authenticateUser(user2).withCoreAPI().usingNode(file1).usingParams("include=isLocked").lockNode(lockBodyModel2); + restClient.assertStatusCodeIs(HttpStatus.OK); + file1Model3.assertThat().field("isLocked").is(true) + .assertThat().field("properties").contains("lockLifetime=EPHEMERAL") + .assertThat().field("properties").contains("lockType=READ_ONLY_LOCK"); + } + + @Bug(id = "MNT-17612", status = Status.FIXED, description = "AccessDeniedException in AOS Edit Offline Upload New Version") + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.NODES }, executionType = ExecutionType.REGRESSION, + description = "Verify Collaborator can lock PERSISTENT after EPHEMERAL lock made by another user is expired") + public void lockEphemeralAndRelockPersistentAfterExpiredLockDifferentUser() throws Exception + { + STEP("1. Adds a file in the site by administrator."); + file1 = dataContent.usingUser(adminUser).usingSite(publicSite).createContent(DocumentType.TEXT_PLAIN); + + STEP("2. Verify with admin that the file is not locked."); + RestNodeModel file1Model1 = restClient.authenticateUser(adminUser).withCoreAPI().usingNode(file1).usingParams("include=isLocked").getNode(); + file1Model1.assertThat().field("isLocked").is(false); + + STEP("3. Lock the file using mode EPHEMERAL with user1 (POST nodes/{nodeId}/lock)."); + RestNodeLockBodyModel lockBodyModel = new RestNodeLockBodyModel(); + lockBodyModel.setLifetime("EPHEMERAL"); + lockBodyModel.setTimeToExpire(1); + lockBodyModel.setType("FULL"); + restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include?isLocked").lockNode(lockBodyModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + + STEP("4. Verify with user1 that the file is locked."); + RestNodeModel file1Model2 = restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include=isLocked").getNode(); + file1Model2.assertThat().field("isLocked").is(true) + .assertThat().field("properties").contains("lockLifetime=EPHEMERAL") + .assertThat().field("properties").contains("lockType=READ_ONLY_LOCK"); + + STEP("5. Lock the file using mode PERSISTENT with user2 after the first lock has expired"); + RestNodeLockBodyModel lockBodyModel2 = new RestNodeLockBodyModel(); + lockBodyModel2.setLifetime("PERSISTENT"); + lockBodyModel2.setTimeToExpire(20); + lockBodyModel2.setType("ALLOW_OWNER_CHANGES"); + try{Thread.sleep(1500);}finally{} + RestNodeModel file1Model3 = restClient.authenticateUser(user2).withCoreAPI().usingNode(file1).usingParams("include=isLocked").lockNode(lockBodyModel2); + restClient.assertStatusCodeIs(HttpStatus.OK); + file1Model3.assertThat().field("isLocked").is(true) + .assertThat().field("properties").contains("lockLifetime=PERSISTENT") + .assertThat().field("properties").contains("lockType=WRITE_LOCK"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.NODES }, executionType = ExecutionType.REGRESSION, + description = "Verify Collaborator can lock EPHEMERAL after EPHEMERAL lock made by another user is expired") + public void lockEphemeralAndRelockEphemeralAfterExpiredLockDifferentUser() throws Exception + { + STEP("1. Adds a file in the site by administrator."); + file1 = dataContent.usingUser(adminUser).usingSite(publicSite).createContent(DocumentType.TEXT_PLAIN); + + STEP("2. Verify with admin that the file is not locked."); + RestNodeModel file1Model1 = restClient.authenticateUser(adminUser).withCoreAPI().usingNode(file1).usingParams("include=isLocked").getNode(); + file1Model1.assertThat().field("isLocked").is(false); + + STEP("3. Lock the file using mode EPHEMERAL with user1 (POST nodes/{nodeId}/lock)."); + RestNodeLockBodyModel lockBodyModel = new RestNodeLockBodyModel(); + lockBodyModel.setLifetime("EPHEMERAL"); + lockBodyModel.setTimeToExpire(1); + lockBodyModel.setType("FULL"); + restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include?isLocked").lockNode(lockBodyModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + + STEP("4. Verify with user1 that the file is locked."); + RestNodeModel file1Model2 = restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include=isLocked").getNode(); + file1Model2.assertThat().field("isLocked").is(true) + .assertThat().field("properties").contains("lockLifetime=EPHEMERAL") + .assertThat().field("properties").contains("lockType=READ_ONLY_LOCK"); + + STEP("5. Lock the file using mode EPHEMERAL with user2 while the first lock has expired"); + RestNodeLockBodyModel lockBodyModel2 = new RestNodeLockBodyModel(); + lockBodyModel2.setLifetime("EPHEMERAL"); + lockBodyModel2.setTimeToExpire(20); + lockBodyModel2.setType("FULL"); + try{Thread.sleep(1500);}finally{} + RestNodeModel file1Model3 = restClient.authenticateUser(user2).withCoreAPI().usingNode(file1).usingParams("include=isLocked").lockNode(lockBodyModel2); + restClient.assertStatusCodeIs(HttpStatus.OK); + file1Model3.assertThat().field("isLocked").is(true) + .assertThat().field("properties").contains("lockLifetime=EPHEMERAL") + .assertThat().field("properties").contains("lockType=READ_ONLY_LOCK"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.NODES }, executionType = ExecutionType.REGRESSION, + description = "Verify Collaborator can lock PERSISTENT after PERSISTENT lock made by different user is expired") + public void lockPersistentAndRelockPersistentAfterExpiredLockDifferentUser() throws Exception + { + STEP("1. Adds a file in the site by administrator."); + file1 = dataContent.usingUser(adminUser).usingSite(publicSite).createContent(DocumentType.TEXT_PLAIN); + + STEP("2. Verify with admin that the file is not locked."); + RestNodeModel file1Model1 = restClient.authenticateUser(adminUser).withCoreAPI().usingNode(file1).usingParams("include=isLocked").getNode(); + file1Model1.assertThat().field("isLocked").is(false); + + STEP("3. Lock the file using mode PERSISTENT with user1 (POST nodes/{nodeId}/lock)."); + RestNodeLockBodyModel lockBodyModel = new RestNodeLockBodyModel(); + lockBodyModel.setLifetime("PERSISTENT"); + lockBodyModel.setTimeToExpire(1); + lockBodyModel.setType("ALLOW_OWNER_CHANGES"); + restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include?isLocked").lockNode(lockBodyModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + + STEP("4. Verify with admin that the file is locked."); + RestNodeModel file1Model2 = restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include=isLocked").getNode(); + file1Model2.assertThat().field("isLocked").is(true) + .assertThat().field("properties").contains("lockLifetime=PERSISTENT") + .assertThat().field("properties").contains("lockType=WRITE_LOCK"); + + STEP("5. Lock the file using mode PERSISTENT with user2 after the first lock has expired"); + RestNodeLockBodyModel lockBodyModel2 = new RestNodeLockBodyModel(); + lockBodyModel2.setLifetime("PERSISTENT"); + lockBodyModel2.setTimeToExpire(20); + lockBodyModel2.setType("ALLOW_OWNER_CHANGES"); + try{Thread.sleep(1500);}finally{} + RestNodeModel file1Model3 = restClient.authenticateUser(user2).withCoreAPI().usingNode(file1).usingParams("include=isLocked").lockNode(lockBodyModel2); + restClient.assertStatusCodeIs(HttpStatus.OK); + file1Model3.assertThat().field("isLocked").is(true) + .assertThat().field("properties").contains("lockLifetime=PERSISTENT") + .assertThat().field("properties").contains("lockType=WRITE_LOCK"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.NODES }, executionType = ExecutionType.REGRESSION, + description = "Verify Collaborator can lock EPHEMERAL after EPHEMERAL lock made by same user is expired") + public void lockEphemeralAndRelockEphemeralAfterExpiredLockSameUser() throws Exception + { + STEP("1. Adds a file in the site by administrator."); + file1 = dataContent.usingUser(adminUser).usingSite(publicSite).createContent(DocumentType.TEXT_PLAIN); + + STEP("2. Verify with admin that the file is not locked."); + RestNodeModel file1Model1 = restClient.authenticateUser(adminUser).withCoreAPI().usingNode(file1).usingParams("include=isLocked").getNode(); + file1Model1.assertThat().field("isLocked").is(false); + + STEP("3. Lock the file using mode EPHEMERAL with user1 (POST nodes/{nodeId}/lock)."); + RestNodeLockBodyModel lockBodyModel = new RestNodeLockBodyModel(); + lockBodyModel.setLifetime("EPHEMERAL"); + lockBodyModel.setTimeToExpire(1); + lockBodyModel.setType("FULL"); + restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include?isLocked").lockNode(lockBodyModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + + STEP("4. Verify with user1 that the file is locked."); + RestNodeModel file1Model2 = restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include=isLocked").getNode(); + file1Model2.assertThat().field("isLocked").is(true) + .assertThat().field("properties").contains("lockLifetime=EPHEMERAL") + .assertThat().field("properties").contains("lockType=READ_ONLY_LOCK"); + + STEP("5. Lock the file using mode EPHEMERAL with user1 after the first lock has expired"); + RestNodeLockBodyModel lockBodyModel2 = new RestNodeLockBodyModel(); + lockBodyModel2.setLifetime("EPHEMERAL"); + lockBodyModel2.setTimeToExpire(20); + lockBodyModel2.setType("FULL"); + try{Thread.sleep(1500);}finally{} + RestNodeModel file1Model3 = restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include=isLocked").lockNode(lockBodyModel2); + restClient.assertStatusCodeIs(HttpStatus.OK); + file1Model3.assertThat().field("isLocked").is(true) + .assertThat().field("properties").contains("lockLifetime=EPHEMERAL") + .assertThat().field("properties").contains("lockType=READ_ONLY_LOCK"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.NODES }, executionType = ExecutionType.REGRESSION, + description = "Verify Collaborator can lock PERSISTENT after PERSISTENT lock made by same user is expired") + public void lockPersistentAndRelockPersistentAfterExpiredLockSameUser() throws Exception + { + STEP("1. Adds a file in the site by administrator."); + file1 = dataContent.usingUser(adminUser).usingSite(publicSite).createContent(DocumentType.TEXT_PLAIN); + + STEP("2. Verify with admin that the file is not locked."); + RestNodeModel file1Model1 = restClient.authenticateUser(adminUser).withCoreAPI().usingNode(file1).usingParams("include=isLocked").getNode(); + file1Model1.assertThat().field("isLocked").is(false); + + STEP("3. Lock the file using mode PERSISTENT with user1 (POST nodes/{nodeId}/lock)."); + RestNodeLockBodyModel lockBodyModel = new RestNodeLockBodyModel(); + lockBodyModel.setLifetime("PERSISTENT"); + lockBodyModel.setTimeToExpire(1); + lockBodyModel.setType("ALLOW_OWNER_CHANGES"); + restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include?isLocked").lockNode(lockBodyModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + + STEP("4. Verify with user1 that the file is locked."); + RestNodeModel file1Model2 = restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include=isLocked").getNode(); + file1Model2.assertThat().field("isLocked").is(true); + file1Model2.assertThat().field("properties").contains("lockLifetime=PERSISTENT"); + + STEP("5. Lock the file using mode PERSISTENT with user1 while the first lock has expired"); + RestNodeLockBodyModel lockBodyModel2 = new RestNodeLockBodyModel(); + lockBodyModel2.setLifetime("PERSISTENT"); + lockBodyModel2.setTimeToExpire(20); + lockBodyModel2.setType("ALLOW_OWNER_CHANGES"); + try{Thread.sleep(1500);}finally{} + RestNodeModel file1Model3 = restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include=isLocked").lockNode(lockBodyModel2); + restClient.assertStatusCodeIs(HttpStatus.OK); + file1Model3.assertThat().field("isLocked").is(true) + .assertThat().field("properties").contains("lockLifetime=PERSISTENT") + .assertThat().field("properties").contains("lockType=WRITE_LOCK"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.NODES }, executionType = ExecutionType.REGRESSION, + description = "Verify Collaborator can lock EPHEMERAL after PERSISTENT lock made by same user is expired") + public void lockPersistentAndRelockEphemeralAfterExpiredLockSameUser() throws Exception + { + STEP("1. Adds a file in the site by administrator."); + file1 = dataContent.usingUser(adminUser).usingSite(publicSite).createContent(DocumentType.TEXT_PLAIN); + + STEP("2. Verify with admin that the file is not locked."); + RestNodeModel file1Model1 = restClient.authenticateUser(adminUser).withCoreAPI().usingNode(file1).usingParams("include=isLocked").getNode(); + file1Model1.assertThat().field("isLocked").is(false); + + STEP("3. Lock the file using mode PERSISTENT with user1 (POST nodes/{nodeId}/lock)."); + RestNodeLockBodyModel lockBodyModel = new RestNodeLockBodyModel(); + lockBodyModel.setLifetime("PERSISTENT"); + lockBodyModel.setTimeToExpire(1); + lockBodyModel.setType("ALLOW_OWNER_CHANGES"); + restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include?isLocked").lockNode(lockBodyModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + + STEP("4. Verify with admin that the file is locked."); + RestNodeModel file1Model2 = restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include=isLocked").getNode(); + file1Model2.assertThat().field("isLocked").is(true) + .assertThat().field("properties").contains("lockLifetime=PERSISTENT") + .assertThat().field("properties").contains("lockType=WRITE_LOCK"); + + STEP("5. Lock the file using mode EPHEMERAL with user1 while the first lock has expired"); + RestNodeLockBodyModel lockBodyModel2 = new RestNodeLockBodyModel(); + lockBodyModel2.setLifetime("EPHEMERAL"); + lockBodyModel2.setTimeToExpire(20); + lockBodyModel2.setType("FULL"); + try{Thread.sleep(1500);}finally{} + RestNodeModel file1Model3 = restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include=isLocked").lockNode(lockBodyModel2); + restClient.assertStatusCodeIs(HttpStatus.OK); + file1Model3.assertThat().field("isLocked").is(true) + .assertThat().field("properties").contains("lockLifetime=EPHEMERAL") + .assertThat().field("properties").contains("lockType=READ_ONLY_LOCK"); + } + + @Bug(id = "MNT-17612", status = Status.FIXED, description = "AccessDeniedException in AOS Edit Offline Upload New Version") + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.NODES }, executionType = ExecutionType.REGRESSION, + description = "Verify Collaborator can lock PERSISTENT after EPHEMERAL lock made by same user is expired") + public void lockEphemeralAndRelockPersistentAfterExpiredLockSameUser() throws Exception + { + STEP("1. Adds a file in the site by administrator."); + file1 = dataContent.usingUser(adminUser).usingSite(publicSite).createContent(DocumentType.TEXT_PLAIN); + + STEP("2. Verify with admin that the file is not locked."); + RestNodeModel file1Model1 = restClient.authenticateUser(adminUser).withCoreAPI().usingNode(file1) + .usingParams("include=isLocked").getNode(); + file1Model1.assertThat().field("isLocked").is(false); + + STEP("3. Lock the file using mode EPHEMERAL with user1 (POST nodes/{nodeId}/lock)."); + RestNodeLockBodyModel lockBodyModel = new RestNodeLockBodyModel(); + lockBodyModel.setLifetime("EPHEMERAL"); + lockBodyModel.setTimeToExpire(1); + lockBodyModel.setType("FULL"); + restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include?isLocked").lockNode(lockBodyModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + + STEP("4. Verify with useer1 that the file is locked."); + RestNodeModel file1Model2 = restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include=isLocked").getNode(); + file1Model2.assertThat().field("isLocked").is(true) + .assertThat().field("properties").contains("lockLifetime=EPHEMERAL") + .assertThat().field("properties").contains("lockType=READ_ONLY_LOCK"); + + STEP("5. Lock the file using mode PERSISTENT with user1 while the first lock has expired"); + RestNodeLockBodyModel lockBodyModel2 = new RestNodeLockBodyModel(); + lockBodyModel2.setLifetime("PERSISTENT"); + lockBodyModel2.setTimeToExpire(20); + lockBodyModel2.setType("ALLOW_OWNER_CHANGES"); + try{Thread.sleep(1500);}finally{} + RestNodeModel file1Model3 = restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include=isLocked").lockNode(lockBodyModel2); + restClient.assertStatusCodeIs(HttpStatus.OK); + file1Model3.assertThat().field("isLocked").is(true) + .assertThat().field("properties").contains("lockLifetime=PERSISTENT") + .assertThat().field("properties").contains("lockType=WRITE_LOCK"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.NODES }, executionType = ExecutionType.REGRESSION, + description = "Verify Collaborator can lock PERSISTENT after PERSISTENT lock made by same user") + public void lockPersistentAndRelockPersistentSameUser() throws Exception + { + STEP("1. Adds a file in the site by administrator."); + file1 = dataContent.usingUser(adminUser).usingSite(publicSite).createContent(DocumentType.TEXT_PLAIN); + + STEP("2. Verify with admin that the file is not locked."); + RestNodeModel file1Model1 = restClient.authenticateUser(adminUser).withCoreAPI().usingNode(file1).usingParams("include=isLocked").getNode(); + file1Model1.assertThat().field("isLocked").is(false); + + STEP("3. Lock the file using mode PERSISTENT with user1 (POST nodes/{nodeId}/lock)."); + RestNodeLockBodyModel lockBodyModel = new RestNodeLockBodyModel(); + lockBodyModel.setLifetime("PERSISTENT"); + lockBodyModel.setTimeToExpire(20); + lockBodyModel.setType("ALLOW_OWNER_CHANGES"); + restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include?isLocked").lockNode(lockBodyModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + + STEP("4. Verify with user1 that the file is locked."); + RestNodeModel file1Model2 = restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include=isLocked").getNode(); + file1Model2.assertThat().field("isLocked").is(true) + .assertThat().field("properties").contains("lockLifetime=PERSISTENT") + .assertThat().field("properties").contains("lockType=WRITE_LOCK"); + + STEP("5. Lock the file using mode PERSISTENT with user1 while the file is still locked"); + RestNodeLockBodyModel lockBodyModel2 = new RestNodeLockBodyModel(); + lockBodyModel2.setLifetime("PERSISTENT"); + lockBodyModel2.setTimeToExpire(20); + lockBodyModel2.setType("ALLOW_OWNER_CHANGES"); + RestNodeModel file1Model3 = restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include=isLocked").lockNode(lockBodyModel2); + restClient.assertStatusCodeIs(HttpStatus.OK); + file1Model3.assertThat().field("isLocked").is(true); + file1Model3.assertThat().field("properties").contains("lockLifetime=PERSISTENT") + .assertThat().field("properties").contains("lockType=WRITE_LOCK"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.NODES }, executionType = ExecutionType.REGRESSION, + description = "Verify Collaborator can lock EPHERMERAL after PERSISTENT lock made by same user") + public void lockPersistentAndRelockEphemeralSameUser() throws Exception + { + STEP("1. Adds a file in the site by administrator."); + file1 = dataContent.usingUser(adminUser).usingSite(publicSite).createContent(DocumentType.TEXT_PLAIN); + + STEP("2. Verify with admin that the file is not locked."); + RestNodeModel file1Model1 = restClient.authenticateUser(adminUser).withCoreAPI().usingNode(file1).usingParams("include=isLocked").getNode(); + file1Model1.assertThat().field("isLocked").is(false); + + STEP("3. Lock the file using mode PERSISTENT with user1 (POST nodes/{nodeId}/lock)."); + RestNodeLockBodyModel lockBodyModel = new RestNodeLockBodyModel(); + lockBodyModel.setLifetime("PERSISTENT"); + lockBodyModel.setTimeToExpire(1); + lockBodyModel.setType("ALLOW_OWNER_CHANGES"); + restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include?isLocked").lockNode(lockBodyModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + + STEP("4. Verify with user1 that the file is locked."); + RestNodeModel file1Model2 = restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include=isLocked").getNode(); + file1Model2.assertThat().field("isLocked").is(true) + .assertThat().field("properties").contains("lockLifetime=PERSISTENT") + .assertThat().field("properties").contains("lockType=WRITE_LOCK"); + + STEP("5. Lock the file using mode EPHERMERAL with user1 while the file is still locked"); + RestNodeLockBodyModel lockBodyModel2 = new RestNodeLockBodyModel(); + lockBodyModel2.setLifetime("EPHEMERAL"); + lockBodyModel2.setTimeToExpire(20); + lockBodyModel2.setType("FULL"); + RestNodeModel file1Model3 = restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include=isLocked").lockNode(lockBodyModel2); + restClient.assertStatusCodeIs(HttpStatus.OK); + file1Model3.assertThat().field("isLocked").is(true); + file1Model3.assertThat().field("properties").contains("lockLifetime=EPHEMERAL") + .assertThat().field("properties").contains("lockType=READ_ONLY_LOCK"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.REGRESSION, TestGroup.REQUIRE_SOLR }) + @TestRail(section = { TestGroup.REST_API, TestGroup.NODES }, executionType = ExecutionType.REGRESSION, + description = "Verify that child nodes can be locked differently and unlocked") + public void testLockUnlockParentChild() throws Exception + { + STEP("1. Create user, site, parent node and children nodes."); + SiteModel siteLock = dataSite.usingUser(adminUser).createPublicRandomSite(); + FolderModel parentNode = dataContent.usingUser(adminUser).usingSite(siteLock).createFolder(); + FileModel childNode1 = dataContent.usingUser(adminUser).usingSite(siteLock).usingResource(parentNode).createContent(DocumentType.TEXT_PLAIN); + FileModel childNode2 = dataContent.usingUser(adminUser).usingSite(siteLock).usingResource(parentNode).createContent(DocumentType.TEXT_PLAIN); + + STEP("2. Verify with admin that the file is not locked."); + RestNodeModel restNodeResponse = restClient.authenticateUser(adminUser).withCoreAPI().usingNode(parentNode).usingParams("include=isLocked").getNode(); + restNodeResponse.assertThat().field("isLocked").is(false); + + restNodeResponse = restClient.withCoreAPI().usingNode(childNode1).usingParams("include=isLocked").getNode(); + restNodeResponse.assertThat().field("isLocked").is(false); + + restNodeResponse = restClient.withCoreAPI().usingNode(childNode2).usingParams("include=isLocked").getNode(); + restNodeResponse.assertThat().field("isLocked").is(false); + + STEP("3. Lock childNode1 using mode PERSISTENT with adminUser (POST nodes/{nodeId}/lock)."); + RestNodeLockBodyModel lockBodyModel = new RestNodeLockBodyModel(); + lockBodyModel.setLifetime("PERSISTENT"); + lockBodyModel.setTimeToExpire(0); + lockBodyModel.setType("ALLOW_OWNER_CHANGES"); + restNodeResponse = restClient.withCoreAPI().usingNode(childNode1).usingParams("include=isLocked").lockNode(lockBodyModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + restNodeResponse.assertThat().field("aspectNames").contains("cm:lockable") + .assertThat().field("isLocked").is(true) + .assertThat().field("properties").contains("lockLifetime=PERSISTENT") + .assertThat().field("properties").contains("lockType=WRITE_LOCK"); + + STEP("4. Lock childNode2 using mode PERSISTENT with adminUser (POST nodes/{nodeId}/lock)."); + lockBodyModel = new RestNodeLockBodyModel(); + lockBodyModel.setLifetime("PERSISTENT"); + lockBodyModel.setTimeToExpire(0); + lockBodyModel.setType("FULL"); + restNodeResponse = restClient.withCoreAPI().usingNode(childNode2).usingParams("include=isLocked").lockNode(lockBodyModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + restNodeResponse.assertThat().field("aspectNames").contains("cm:lockable") + .assertThat().field("isLocked").is(true) + .assertThat().field("properties").contains("lockLifetime=PERSISTENT") + .assertThat().field("properties").contains("lockType=READ_ONLY_LOCK"); + + STEP("5. Verify that childNode1 and childNode 2 are locked."); + SearchRequest query = new SearchRequest(); + RestRequestQueryModel queryReq = new RestRequestQueryModel(); + RestRequestFilterQueryModel queryFilters = new RestRequestFilterQueryModel(); + queryFilters.setQuery("cm:lockOwner:\'admin\'"); + queryReq.setQuery("ASPECT:\'cm:lockable\'"); + query.setQuery(queryReq); + query.setFilterQueries(queryFilters); + query.setIncludeRequest(false); + + // Allow indexing to complete. + Utility.sleep(1000, 60000, () -> + { + SearchResponse response = query(query); + restClient.assertStatusCodeIs(HttpStatus.OK); + response.assertThat().entriesListContains("id",childNode1.getNodeRefWithoutVersion()); + response.assertThat().entriesListContains("id",childNode2.getNodeRefWithoutVersion()); + }); + + STEP("6. Unlock the nodes."); + restNodeResponse = restClient.withCoreAPI().usingNode(childNode1).usingParams("include=isLocked").unlockNode(); + restNodeResponse.assertThat().field("isLocked").is(false); + + restNodeResponse = restClient.withCoreAPI().usingNode(childNode2).usingParams("include=isLocked").unlockNode(); + restNodeResponse.assertThat().field("isLocked").is(false); + + STEP("7. Verify that childNode1 and childNode2 are not found in the query results."); + // Allow indexing to complete. + Utility.sleep(1000, 60000, () -> + { + SearchResponse response = query(query); + restClient.assertStatusCodeIs(HttpStatus.OK); + response.assertThat().entriesListDoesNotContain("id",childNode1.getNodeRefWithoutVersion()); + response.assertThat().entriesListDoesNotContain("id",childNode2.getNodeRefWithoutVersion()); + }); + } + + protected SearchResponse query(SearchRequest query) throws Exception + { + return restClient.authenticateUser(dataUser.getAdminUser()).withSearchAPI().search(query); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodesParentChildrenTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodesParentChildrenTests.java new file mode 100644 index 0000000000..417eb99d19 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodesParentChildrenTests.java @@ -0,0 +1,205 @@ +package org.alfresco.rest.nodes; + +import static org.alfresco.utility.report.log.Step.STEP; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestNodeBodyModel; +import org.alfresco.rest.model.RestNodeChildAssocModelCollection; +import org.alfresco.rest.model.RestNodeChildAssociationModel; +import org.alfresco.rest.model.RestNodeModel; +import org.alfresco.rest.model.RestNodeModelsCollection; +import org.alfresco.rest.model.RestNodeAssociationModelCollection; +import org.alfresco.rest.model.builder.NodesBuilder; +import org.alfresco.utility.Utility; +import org.alfresco.utility.model.ContentModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.Test; + +/** + * Handles tests related to + * api-explorer/#!/nodes/children + * api-explorer/#!/nodes/secondary-children + * api-explorer/#!/nodes/parents + */ +public class NodesParentChildrenTests extends RestTest +{ + @TestRail(section = { TestGroup.REST_API,TestGroup.NODES }, executionType = ExecutionType.SANITY, + description = "Verify new folder node is created as children on -my- posting as JSON content type") + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.SANITY}) + public void createNewFolderNodeViaJason() throws Exception + { + restClient.authenticateUser(dataContent.getAdminUser()); + + RestNodeBodyModel node = new RestNodeBodyModel(); + node.setName("My Folder"); + node.setNodeType("cm:folder"); + + RestNodeModel newNode = restClient.withParams("autoRename=true").withCoreAPI().usingNode(ContentModel.my()).createNode(node); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + newNode.assertThat().field("aspectNames").contains("cm:auditable") + .assertThat().field("isFolder").is(true) + .assertThat().field("isFile").is(false) + .assertThat().field("name").contains(node.getName()); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.NODES }, executionType = ExecutionType.REGRESSION, + description = "Verify new folder node is created as children on -my- posting as MultiPart content type") + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.REGRESSION}) + public void createNewFolderNodeWithMultiPartForms() throws Exception + { + //configuring multipart form + restClient.authenticateUser(dataContent.getAdminUser()) + .configureRequestSpec() + .addMultiPart("filedata", Utility.getResourceTestDataFile("restapi-resource")) + .addFormParam("renditions", "doclib") + .addFormParam("autoRename", true); + + RestNodeModel newNode = restClient.withCoreAPI().usingNode(ContentModel.my()).createNode(); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + newNode.assertThat().field("aspectNames").contains("cm:auditable") + .assertThat().field("isFolder").is(false) + .assertThat().field("isFile").is(true) + .assertThat().field("name").contains("restapi-resource"); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.NODES }, executionType = ExecutionType.SANITY, + description = "Verify list children when listing with relativePath and pagination") + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.SANITY}) + public void checkRelativePathAndPaginationOnCreateChildrenNode() throws Exception + { + /* + * Given we have a folder hierarchy folder1/folder2/folder3 and folder3 containing 3 files file1, file2, and file3 + */ + NodesBuilder nodesBuilder = restClient.authenticateUser(dataUser.getAdminUser()) + .withCoreAPI().usingNode(ContentModel.my()) + .defineNodes(); + nodesBuilder + .folder("F1") + .folder("F2") + .folder("F3") + .file("f1") + .file("f2") + .file("f3"); + + RestNodeModelsCollection returnedFiles = restClient.withParams("maxItems=2", + "skipCount=1", + String.format("relativePath=%s/%s", nodesBuilder.getNode("F2").getName(), nodesBuilder.getNode("F3").getName())) + .withCoreAPI().usingNode(nodesBuilder.getNode("F1").toContentModel()).listChildren(); + restClient.assertStatusCodeIs(HttpStatus.OK); + + /* + * Then I receive file2 and file3 + */ + returnedFiles.assertThat().entriesListCountIs(2); + returnedFiles.getEntries().get(0).onModel().assertThat().field("id").is(nodesBuilder.getNode("f2").getId()); + returnedFiles.getEntries().get(1).onModel().assertThat().field("id").is(nodesBuilder.getNode("f3").getId()); + } + + /** + * Sanity check for the following api endpoints + * POST /nodes/{nodeId}/secondary-children + * GET /nodes/{nodeId}/secondary-children + * DELETE /nodes/{nodeId}/secondary-children/{childId} + */ + @TestRail(section = { TestGroup.REST_API, + TestGroup.NODES }, executionType = ExecutionType.SANITY, description = "Check /secondary-children (create, list, delete) api calls") + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.SANITY }) + public void checkSecondaryChildrenApi() throws Exception + { + STEP("1. Create a folder hierarchy folder1/folder2, with folder2 containing 3 files: f1, f2, and f3"); + NodesBuilder nodesBuilder = restClient.authenticateUser(dataUser.getAdminUser()) + .withCoreAPI().usingNode(ContentModel.my()) + .defineNodes(); + nodesBuilder + .folder("F1") + .folder("F2") + .file("f1") + .file("f2") + .file("f3"); + + STEP("2. Create secondary child associations model objects"); + RestNodeChildAssociationModel childAssoc1 = new RestNodeChildAssociationModel(nodesBuilder.getNode("f1").getId(), "cm:contains"); + RestNodeChildAssociationModel childAssoc2 = new RestNodeChildAssociationModel(nodesBuilder.getNode("f2").getId(), "cm:contains"); + RestNodeChildAssociationModel childAssoc3 = new RestNodeChildAssociationModel(nodesBuilder.getNode("f3").getId(), "cm:preferenceImage"); + String secondaryChildrenBody = "[" + childAssoc1.toJson() + "," + childAssoc2.toJson() + "," + childAssoc3.toJson() + "]"; + + STEP("3. Create secondary child associations using POST /nodes/{nodeId}/secondary-children"); + RestNodeChildAssocModelCollection secondaryChildAssoc = restClient.withCoreAPI().usingNode(nodesBuilder.getNode("F1").toContentModel()) + .createSecondaryChildren(secondaryChildrenBody); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + secondaryChildAssoc.getEntryByIndex(0).assertThat().field("childId").is(childAssoc1.getChildId()); + secondaryChildAssoc.getEntryByIndex(1).assertThat().field("childId").is(childAssoc2.getChildId()); + secondaryChildAssoc.getEntryByIndex(2).assertThat().field("childId").is(childAssoc3.getChildId()); + + STEP("4. Check using GET /nodes/{nodeId}/secondary-children that the secondary 'cm:contains' child associations were created"); + RestNodeAssociationModelCollection secondaryChildren = restClient.withParams("where=(assocType='cm:contains')").withCoreAPI() + .usingNode(nodesBuilder.getNode("F1").toContentModel()).getSecondaryChildren(); + restClient.assertStatusCodeIs(HttpStatus.OK); + secondaryChildren.assertThat().entriesListCountIs(2); + + STEP("5. Check using DELETE /nodes/{nodeId}/secondary-children/{childId} that a secondary child can be deleted"); + restClient.withCoreAPI().usingNode(nodesBuilder.getNode("F1").toContentModel()).deleteSecondaryChild(secondaryChildren.getEntryByIndex(0)); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + STEP("6. Check using GET /nodes/{nodeId}/secondary-children that a secondary child association was deleted"); + secondaryChildren = restClient.withCoreAPI().usingNode(nodesBuilder.getNode("F1").toContentModel()) + .getSecondaryChildren(); + restClient.assertStatusCodeIs(HttpStatus.OK); + secondaryChildren.assertThat().entriesListCountIs(2); + secondaryChildren.getEntryByIndex(0).assertThat() + .field("id").is(secondaryChildAssoc.getEntryByIndex(1).getChildId()).and() + .field("parentId").is(nodesBuilder.getNode("F2").getId()) + .getAssociation().assertThat() + .field("isPrimary").is(false).and() + .field("assocType").is("cm:contains"); + secondaryChildren.getEntryByIndex(1).assertThat() + .field("id").is(secondaryChildAssoc.getEntryByIndex(2).getChildId()) + .getAssociation().assertThat() + .field("assocType").is("cm:preferenceImage"); + } + + /** + * Sanity check for the following api endpoint + * GET /nodes/{nodeId}/parents + */ + @TestRail(section = { TestGroup.REST_API, + TestGroup.NODES }, executionType = ExecutionType.SANITY, description = "Check that GET /parents retrieves primary and secondary parents for a node") + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.SANITY }) + public void checkGetNodeParents() throws Exception + { + STEP("1. Create a folder hierarchy folder1/folder2, with folder2 containing file f1"); + NodesBuilder nodesBuilder = restClient.authenticateUser(dataUser.getAdminUser()) + .withCoreAPI().usingNode(ContentModel.my()) + .defineNodes(); + nodesBuilder + .folder("F1") + .folder("F2") + .file("f1"); + + STEP("2. Create secondary child associations using POST /nodes/{nodeId}/secondary-children"); + RestNodeChildAssociationModel childAssoc = new RestNodeChildAssociationModel(nodesBuilder.getNode("f1").getId(), "cm:contains"); + restClient.withCoreAPI().usingNode(nodesBuilder.getNode("F1").toContentModel()).createSecondaryChildren(childAssoc.toJson()); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + STEP("3. Get all parents for file 'f1' - both primary and secondary"); + RestNodeAssociationModelCollection parents = restClient.withCoreAPI().usingNode(nodesBuilder.getNode("f1").toContentModel()).getParents(); + restClient.assertStatusCodeIs(HttpStatus.OK); + parents.assertThat().entriesListCountIs(2); + + STEP("4. Check using GET /nodes/{nodeId}/parents that the parent (not primary) for f1 is found"); + parents = restClient.withParams("where=(isPrimary=false)").withCoreAPI().usingNode(nodesBuilder.getNode("f1").toContentModel()).getParents(); + restClient.assertStatusCodeIs(HttpStatus.OK); + parents.assertThat().entriesListCountIs(1); + parents.getEntryByIndex(0).assertThat() + .field("isFolder").is("true").and() + .field("isFile").is(false).and() + .field("name").is(nodesBuilder.getNode("F1").getName()) + .getAssociation().assertThat() + .field("isPrimary").is(false).and() + .field("assocType").is("cm:contains"); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodesTargetSourcesTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodesTargetSourcesTests.java new file mode 100644 index 0000000000..83863ad59e --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodesTargetSourcesTests.java @@ -0,0 +1,120 @@ +package org.alfresco.rest.nodes; + +import static org.alfresco.utility.report.log.Step.STEP; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestNodeAssocTargetModel; +import org.alfresco.rest.model.RestNodeAssociationModelCollection; +import org.alfresco.rest.model.builder.NodesBuilder; +import org.alfresco.utility.model.ContentModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class NodesTargetSourcesTests extends RestTest +{ + + private UserModel adminUserModel; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUserModel = dataUser.getAdminUser(); + } + + /** + * Sanity check for the following api endpoints + * POST /nodes/{nodeId}/targets + * GET /nodes/{nodeId}/targets + * DELETE /nodes/{nodeId}/targets/{targetId} + */ + + @TestRail(section = { TestGroup.REST_API, + TestGroup.NODES }, executionType = ExecutionType.SANITY, description = "Check /targets (create, list, delete) api calls") + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.SANITY }) + public void checkTargetsNodeApi() throws Exception + { + STEP("1.Create folder1 which contains 3 files: f1, f2, and f3"); + NodesBuilder nodesBuilder = restClient.authenticateUser(adminUserModel).withCoreAPI().usingNode(ContentModel.my()).defineNodes(); + nodesBuilder.folder("F1").file("f1").file("f2").file("f3"); + + STEP("2. Create target associations model objects"); + RestNodeAssocTargetModel assocDocTarget1 = new RestNodeAssocTargetModel(nodesBuilder.getNode("f2").toContentModel().getNodeRef(), "cm:references"); + RestNodeAssocTargetModel assocDocTarget2 = new RestNodeAssocTargetModel(nodesBuilder.getNode("f3").toContentModel().getNodeRef(), "cm:references"); + + STEP("3. Create target associations using POST /nodes/{nodeId}/targets"); + restClient.withCoreAPI().usingResource(nodesBuilder.getNode("f1").toContentModel()).createTargetForNode(assocDocTarget1); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.withCoreAPI().usingResource(nodesBuilder.getNode("f1").toContentModel()).createTargetForNode(assocDocTarget2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + STEP("4. Check using GET /nodes/{nodeId}/targets targets associations were created"); + RestNodeAssociationModelCollection targetsRes = restClient.withParams("where=(assocType='cm:references')").withCoreAPI().usingResource(nodesBuilder.getNode("f1").toContentModel()).getNodeTargets(); + restClient.assertStatusCodeIs(HttpStatus.OK); + targetsRes.assertThat().entriesListCountIs(2); + targetsRes.getEntryByIndex(0).assertThat().field("association.assocType").is("cm:references").and().field("name") + .is(nodesBuilder.getNode("f2").getName()); + targetsRes.getEntryByIndex(1).assertThat().field("association.assocType").is("cm:references").and().field("name") + .is(nodesBuilder.getNode("f3").getName()); + + STEP("5. Check using DELETE /nodes/{nodeId}/targets/{targetId} that a target can be deleted"); + restClient.authenticateUser(adminUserModel); + restClient.withCoreAPI().usingResource(nodesBuilder.getNode("f1").toContentModel()).deleteTarget(assocDocTarget1); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + STEP("6. Check using GET /nodes/{nodeId}/targets that target association was deleted"); + targetsRes = restClient.withParams("where=(assocType='cm:references')").withCoreAPI() + .usingResource(nodesBuilder.getNode("f1").toContentModel()).getNodeTargets(); + restClient.assertStatusCodeIs(HttpStatus.OK); + targetsRes.assertThat().entriesListCountIs(1); + targetsRes.getEntryByIndex(0).assertThat().field("association.assocType").is("cm:references"); + } + + /** + * Sanity check for the following api endpoint + * GET /nodes/{nodeId}/sources + */ + @TestRail(section = { TestGroup.REST_API, + TestGroup.NODES }, executionType = ExecutionType.SANITY, description = "Check that source objects are retrieved using GET /nodes/{nodeId}/sources") + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.SANITY }) + public void checkGetNodeSources() throws Exception + { + STEP("1.Create a folder hierarchy folder1 containing 4 files: f1, f2, and f3"); + NodesBuilder nodesBuilder = restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingNode(ContentModel.my()).defineNodes(); + nodesBuilder.folder("F1").file("f1").file("f2").file("f3"); + + STEP("2. Create target associations model objects"); + RestNodeAssocTargetModel assocDocTarget1 = new RestNodeAssocTargetModel(nodesBuilder.getNode("f3").toContentModel().getNodeRef(), "cm:references"); + RestNodeAssocTargetModel assocDocTarget2 = new RestNodeAssocTargetModel(nodesBuilder.getNode("f3").toContentModel().getNodeRef(), "cm:preferenceImage"); + + STEP("3. Create target associations using POST /nodes/{nodeId}/targets"); + restClient.authenticateUser(adminUserModel); + restClient.withCoreAPI().usingResource(nodesBuilder.getNode("f1").toContentModel()).createTargetForNode(assocDocTarget1); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.withCoreAPI().usingResource(nodesBuilder.getNode("f2").toContentModel()).createTargetForNode(assocDocTarget2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + STEP("4. Check using GET /nodes/{nodeId}/sources that all source associations are displayed"); + RestNodeAssociationModelCollection sources = restClient.withCoreAPI().usingResource(nodesBuilder.getNode("f3").toContentModel()).getNodeSources(); + restClient.assertStatusCodeIs(HttpStatus.OK); + sources.assertThat().entriesListCountIs(2); + + STEP("5. Check using GET /nodes/{nodeId}/sources with params that sources and fields can be filtered in the response"); + sources = restClient.withParams("where=(assocType='cm:references')", "fields=isFile,name,association,id,nodeType,parentId").withCoreAPI().usingResource(nodesBuilder.getNode("f3").toContentModel()).getNodeSources(); + restClient.assertStatusCodeIs(HttpStatus.OK); + sources.assertThat().entriesListCountIs(1); + + sources.getEntryByIndex(0).assertThat() + .field("isFile").is(true).and() + .field("name").is(nodesBuilder.getNode("f1").getName()).and() + .field("id").is(nodesBuilder.getNode("f1").getId()).and() + .field("id").is(nodesBuilder.getNode("f1").getId()).and() + .field("nodeType").is("cm:content") + .getAssociation().assertThat() + .field("assocType").is("cm:references"); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodesTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodesTests.java new file mode 100644 index 0000000000..b122296c60 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodesTests.java @@ -0,0 +1,56 @@ +package org.alfresco.rest.nodes; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestNodeBodyMoveCopyModel; +import org.alfresco.rest.model.RestNodeModel; +import org.alfresco.rest.model.builder.NodesBuilder; +import org.alfresco.rest.model.builder.NodesBuilder.NodeDetail; +import org.alfresco.utility.model.ContentModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.Test; + +/** + * Handles tests related to api-explorer/#!/nodes + */ +public class NodesTests extends RestTest +{ + @TestRail(section = { TestGroup.REST_API,TestGroup.NODES }, executionType = ExecutionType.SANITY, + description = "Verify files can be moved from one folder to another") + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.SANITY}) + public void testMoveFile() throws Exception + { + restClient.authenticateUser(dataContent.getAdminUser()); + + /* + * Create the following file structure for preconditions : + * - sourceFolder + * - file + * - destinationFolder + */ + NodesBuilder nodesBuilder = restClient.withCoreAPI().usingNode(ContentModel.my()).defineNodes(); + NodeDetail sourceFolder = nodesBuilder.folder("sourceFolder"); + NodeDetail file = sourceFolder.file("file"); + NodeDetail destinationFolder = nodesBuilder.folder("destinationFolder"); + + // Move file from sourceFolder to destinationFolder + RestNodeBodyMoveCopyModel moveDestinationInfo = new RestNodeBodyMoveCopyModel(); + moveDestinationInfo.setTargetParentId(destinationFolder.getId()); + + ContentModel fileToMove = new ContentModel(); + fileToMove.setNodeRef(file.getId()); + + RestNodeModel response = restClient.withParams("autoRename=true").withCoreAPI().usingNode(fileToMove).move(moveDestinationInfo); + restClient.assertStatusCodeIs(HttpStatus.OK); + + /* + * Check file's parent has changed to destinationFolder + * - sourceFolder + * - destinationFolder + * - file + */ + response.assertThat().field("parentId").is(destinationFolder.getId()); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodesUnlockTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodesUnlockTests.java new file mode 100644 index 0000000000..ca10a5c59b --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/nodes/NodesUnlockTests.java @@ -0,0 +1,112 @@ +package org.alfresco.rest.nodes; + +import static org.alfresco.utility.report.log.Step.STEP; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestNodeModel; +import org.alfresco.rest.model.body.RestNodeLockBodyModel; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class NodesUnlockTests extends RestTest +{ + private UserModel user1, user2, adminUser; + private SiteModel publicSite; + private FileModel file1; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + publicSite = dataSite.usingUser(adminUser).createPublicRandomSite(); + user1 = dataUser.createRandomTestUser(); + user2 = dataUser.createRandomTestUser(); + dataUser.addUserToSite(user1, publicSite, UserRole.SiteCollaborator); + user1.setUserRole(UserRole.SiteCollaborator); + dataUser.addUserToSite(user2, publicSite, UserRole.SiteCollaborator); + user2.setUserRole(UserRole.SiteCollaborator); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.SANITY }) + @TestRail(section={TestGroup.REST_API, TestGroup.NODES}, executionType= ExecutionType.SANITY, + description= "Verify Collaborator canot unlock EPHEMERAL lock made by different user, but can unlock EPHEMERAL lock made by same user") + public void lockEphemeralAndUnlock() throws Exception + { + STEP("1. Add user(s) as collaborators to the site created by administrator and add a file in this site."); + file1 = dataContent.usingUser(adminUser).usingSite(publicSite).createContent(DocumentType.TEXT_PLAIN); + + STEP("2. Verify with user1 that the file is not locked."); + RestNodeModel file1Model1 = restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include=isLocked").getNode(); + file1Model1.assertThat().field("isLocked").is(false); + + STEP("3. Lock the file using mode EPHEMERAL with user1 (POST nodes/{nodeId}/lock)."); + RestNodeLockBodyModel lockBodyModel = new RestNodeLockBodyModel(); + lockBodyModel.setLifetime("EPHEMERAL"); + lockBodyModel.setTimeToExpire(20); + restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include?isLocked").lockNode(lockBodyModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + + STEP("4. Verify with user1 that the file is locked."); + RestNodeModel file1Model2 = restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include=isLocked").getNode(); + file1Model2.assertThat().field("isLocked").is(true); + + STEP("5. Cannot unlock the file with user2 while the file is still locked"); + restClient.authenticateUser(user2).withCoreAPI().usingNode(file1).usingParams("include=isLocked").unlockNode(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError() + .containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY) + .containsSummary(RestErrorModel.PERMISSION_WAS_DENIED) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + + STEP("6. Unlock the file with user1 while the file is still locked"); + RestNodeModel file1Model3 = restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include=isLocked").unlockNode(); + file1Model3.assertThat().field("isLocked").is(false); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.SANITY }) + @TestRail(section={TestGroup.REST_API, TestGroup.NODES}, executionType= ExecutionType.SANITY, + description= "Verify Collaborator canot unlock PERSISTENT lock made by different user, but can unlock PERSISTENT lock made by same user") + public void lockPersistentAndUnlock() throws Exception{ + + STEP("1. Add user(s) as collaborators to the site created by administrator and add a file in this site."); + file1 = dataContent.usingUser(adminUser).usingSite(publicSite).createContent(DocumentType.TEXT_PLAIN); + + STEP("2. Verify with admin that the file is not locked."); + RestNodeModel file1Model1 = restClient.authenticateUser(adminUser).withCoreAPI().usingNode(file1).usingParams("include=isLocked").getNode(); + file1Model1.assertThat().field("isLocked").is(false); + + STEP("3. Lock the file using mode PERSISTENT with user1 (POST nodes/{nodeId}/lock)."); + RestNodeLockBodyModel lockBodyModel = new RestNodeLockBodyModel(); + lockBodyModel.setLifetime("PERSISTENT"); + lockBodyModel.setTimeToExpire(20); + restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include?isLocked").lockNode(lockBodyModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + + STEP("4. Verify with user1 that the file is locked."); + RestNodeModel file1Model2 = restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include=isLocked").getNode(); + file1Model2.assertThat().field("isLocked").is(true); + + STEP("5. Cannot unlock the file with user2 while the file is still locked"); + restClient.authenticateUser(user2).withCoreAPI().usingNode(file1).usingParams("include=isLocked").unlockNode(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError() + .containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY) + .containsSummary(RestErrorModel.PERMISSION_WAS_DENIED) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + + STEP("6. Unlock the file with user1 while the file is still locked"); + RestNodeModel file1Model3 = restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include=isLocked").unlockNode(); + file1Model3.assertThat().field("isLocked").is(false); + } + +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/people/AvatarPeopleSanityTest.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/AvatarPeopleSanityTest.java new file mode 100644 index 0000000000..a1e0849ab9 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/AvatarPeopleSanityTest.java @@ -0,0 +1,66 @@ +package org.alfresco.rest.people; + +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import java.io.File; + +import org.alfresco.rest.RestTest; +import org.alfresco.utility.Utility; +import org.alfresco.utility.exception.DataPreparationException; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import io.restassured.response.ValidatableResponse; + +public class AvatarPeopleSanityTest extends RestTest +{ + + private UserModel userModel; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws DataPreparationException + { + userModel = dataUser.createRandomTestUser(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY, TestGroup.RENDITIONS }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, description = "Update Avatar for People") + public void updateGetAvatarForPeople() throws Exception + { + File avatarFile = Utility.getResourceTestDataFile("avatar.jpg"); + restClient.authenticateUser(userModel); + ValidatableResponse response = restClient.withCoreAPI().usingAuthUser() + .uploadAvatarContent(restProperties.envProperty().getFullServerUrl(), avatarFile).statusCode(200); + // Renditions are async + Utility.sleep(500, 60000, () -> + { + restClient.authenticateUser(userModel).withCoreAPI().usingAuthUser().downloadAvatarContent(); + restClient.assertStatusCodeIs(HttpStatus.OK); + }); + assertNotNull(response.extract().body().asByteArray()); + assertTrue(response.extract().body().asByteArray().length > 0, "Avatar Image not uploaded"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY, TestGroup.RENDITIONS }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, description = "Remove Avatar for People") + public void removeGetAvatarForPeople() throws Exception + { + File avatarFile = Utility.getResourceTestDataFile("avatar.jpg"); + restClient.authenticateUser(userModel); + restClient.withCoreAPI().usingAuthUser().uploadAvatarContent(restProperties.envProperty().getFullServerUrl(), avatarFile).statusCode(200); + + restClient.authenticateUser(userModel); + restClient.withCoreAPI().usingAuthUser().resetAvatarImageRequest(); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + restClient.authenticateUser(userModel).withCoreAPI().usingAuthUser().downloadAvatarContent(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND); + } + +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/people/DeleteSiteMemberCoreTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/DeleteSiteMemberCoreTests.java new file mode 100644 index 0000000000..bc7d5dfed6 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/DeleteSiteMemberCoreTests.java @@ -0,0 +1,229 @@ +package org.alfresco.rest.people; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class DeleteSiteMemberCoreTests extends RestTest +{ + private UserModel userModel; + private UserModel managerModel; + private SiteModel publicSiteModel; + private SiteModel moderatedSiteModel; + private SiteModel privateSiteModel; + private UserModel adminUserModel; + private UserModel secondUserModel; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + secondUserModel = dataUser.createRandomTestUser(); + secondUserModel.setUserRole(UserRole.SiteCollaborator); + userModel = dataUser.createRandomTestUser(); + userModel.setUserRole(UserRole.SiteCollaborator); + managerModel = dataUser.createRandomTestUser(); + managerModel.setUserRole(UserRole.SiteManager); + adminUserModel = dataUser.getAdminUser(); + publicSiteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); + moderatedSiteModel = dataSite.usingUser(adminUserModel).createModeratedRandomSite(); + privateSiteModel = dataSite.usingUser(adminUserModel).createPrivateRandomSite(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify user removes a site member using '-me-' in place of personId and response is successful (204)") + public void removeSiteMemberWithSuccessUsingMeAsPersonId() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(publicSiteModel).addPerson(userModel); + + restClient.authenticateUser(userModel).withCoreAPI().usingMe().deleteSiteMember(publicSiteModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify user can't remove a site membership of an inexistent uer and response is 404") + public void userIsNotAbleToRemoveInexistentSiteMember() throws Exception + { + UserModel inexistentUser = new UserModel("inexistenUser", "password"); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(inexistentUser).deleteSiteMember(publicSiteModel); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, inexistentUser.getUsername())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify user is not able to remove a member of an inexistent site and response is 404") + public void userIsNotAbleToRemoveMembershipOfInexistentSite() throws Exception + { + SiteModel inexistentSite = new SiteModel("inexistentSite"); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(userModel).deleteSiteMember(inexistentSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, userModel.getUsername(), inexistentSite.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify user is not able to remove a member of an empty site id and response is 404") + public void userIsNotAbleToRemoveMembershipOfEmptySiteId() throws Exception + { + SiteModel inexistentSite = new SiteModel(""); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(userModel).deleteSiteMember(inexistentSite); + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED).assertLastError().containsSummary(RestErrorModel.DELETE_EMPTY_ARGUMENT); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify user is not able to remove a regular member a moderated site and response is 422") + public void regularUserIsNotAbleToRemoveRegularUserSiteMembershipFromModeratedSite() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(publicSiteModel).addPerson(secondUserModel); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(moderatedSiteModel).addPerson(userModel); + restClient.authenticateUser(secondUserModel).withCoreAPI().usingUser(userModel).deleteSiteMember(moderatedSiteModel); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY).assertLastError() + .containsSummary(String.format(RestErrorModel.NOT_SUFFICIENT_PERMISSIONS, moderatedSiteModel.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify user is not able to remove a regular member of a private site and response is 422") + public void regularUserIsNotAbleToRemoveRegularUserSiteMembershipFromPrivateSite() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(privateSiteModel).addPerson(userModel); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(privateSiteModel).addPerson(secondUserModel); + restClient.authenticateUser(secondUserModel).withCoreAPI().usingUser(userModel).deleteSiteMember(privateSiteModel); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY).assertLastError() + .containsSummary(String.format(RestErrorModel.NOT_SUFFICIENT_PERMISSIONS, privateSiteModel.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify admin is able to remove a regular member of a moderated site and response is 204") + public void adminIsAbleToRemoveRegularUserSiteMembershipFromModeratedSite() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(moderatedSiteModel).addPerson(userModel); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(userModel).deleteSiteMember(moderatedSiteModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify admin is able to remove a regular member of a private site and response is 204") + public void adminIsAbleToRemoveRegularUserSiteMembershipFromPrivateSite() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(privateSiteModel).addPerson(userModel); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(userModel).deleteSiteMember(privateSiteModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify user is not able to remove admin membership from public site and response is 422") + public void regularUserIsNotAbleToRemoveAdminSiteMembershipFromPublicSite() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(publicSiteModel).addPerson(managerModel); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(privateSiteModel).addPerson(userModel); + restClient.authenticateUser(userModel).withCoreAPI().usingUser(adminUserModel).deleteSiteMember(publicSiteModel); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY).assertLastError() + .containsSummary(String.format(RestErrorModel.NOT_SUFFICIENT_PERMISSIONS, publicSiteModel.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify user is not able to remove admin membership from moderated site and response is 422") + public void regularUserIsNotAbleToRemoveAdminSiteMembershipFromModeratedSite() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(moderatedSiteModel).addPerson(managerModel); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(privateSiteModel).addPerson(userModel); + restClient.authenticateUser(userModel).withCoreAPI().usingUser(adminUserModel).deleteSiteMember(moderatedSiteModel); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY).assertLastError() + .containsSummary(String.format(RestErrorModel.NOT_SUFFICIENT_PERMISSIONS, moderatedSiteModel.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify user is not able to remove admin membership from private site and response is 422") + public void regularUserIsNotAbleToRemoveAdminSiteMembershipFromPrivateSite() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(privateSiteModel).addPerson(managerModel); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(privateSiteModel).addPerson(userModel); + restClient.authenticateUser(userModel).withCoreAPI().usingUser(adminUserModel).deleteSiteMember(privateSiteModel); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY).assertLastError() + .containsSummary(String.format(RestErrorModel.NOT_SUFFICIENT_PERMISSIONS, privateSiteModel.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify admin is able to remove the membership of a manager from a public site and response is 204") + public void adminIsAbleToRemoveManagerSiteMembershipOfPublicSite() throws Exception + { + UserModel secondManager = dataUser.createRandomTestUser(); + secondManager.setUserRole(UserRole.SiteManager); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(publicSiteModel).addPerson(secondManager); + restClient.withCoreAPI().usingSite(publicSiteModel).addPerson(managerModel); + restClient.withCoreAPI().usingUser(managerModel).deleteSiteMember(publicSiteModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify admin is able to remove the membership of a manager from a moderated site and response is 204") + public void adminIsAbleToRemoveManagerSiteMembershipOfModeratedSite() throws Exception + { + UserModel secondManager = dataUser.createRandomTestUser(); + secondManager.setUserRole(UserRole.SiteManager); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(moderatedSiteModel).addPerson(secondManager); + restClient.withCoreAPI().usingSite(moderatedSiteModel).addPerson(managerModel); + restClient.withCoreAPI().usingUser(managerModel).deleteSiteMember(moderatedSiteModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify admin is able to remove the membership of a manager from a private site and response is 204") + public void adminIsAbleToRemoveManagerSiteMembershipOfPrivateSite() throws Exception + { + UserModel secondManager = dataUser.createRandomTestUser(); + secondManager.setUserRole(UserRole.SiteManager); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(privateSiteModel).addPerson(secondManager); + restClient.withCoreAPI().usingSite(privateSiteModel).addPerson(managerModel); + restClient.withCoreAPI().usingUser(managerModel).deleteSiteMember(privateSiteModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify collaborator is not able to remove the membership of a manager from a public site and response is 204") + public void userIsNotAbleToRemoveManagerSiteMembershipOfPublicSite() throws Exception + { + UserModel secondManager = dataUser.createRandomTestUser(); + secondManager.setUserRole(UserRole.SiteManager); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(publicSiteModel).addPerson(secondManager); + restClient.withCoreAPI().usingSite(publicSiteModel).addPerson(userModel); + restClient.withCoreAPI().usingSite(publicSiteModel).addPerson(managerModel); + restClient.authenticateUser(userModel).withCoreAPI().usingUser(managerModel).deleteSiteMember(publicSiteModel); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY).assertLastError() + .containsSummary(String.format(RestErrorModel.NOT_SUFFICIENT_PERMISSIONS, publicSiteModel.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify collaborator is not able to remove the membership of a manager from a moderated site and response is 204") + public void userIsNotAbleToRemoveManagerSiteMembershipOfModeratedSite() throws Exception + { + UserModel secondManager = dataUser.createRandomTestUser(); + secondManager.setUserRole(UserRole.SiteManager); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(moderatedSiteModel).addPerson(secondManager); + restClient.withCoreAPI().usingSite(publicSiteModel).addPerson(userModel); + restClient.withCoreAPI().usingSite(moderatedSiteModel).addPerson(managerModel); + restClient.authenticateUser(userModel).withCoreAPI().usingUser(managerModel).deleteSiteMember(moderatedSiteModel); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY).assertLastError() + .containsSummary(String.format(RestErrorModel.NOT_SUFFICIENT_PERMISSIONS, moderatedSiteModel.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify collaborator is not able to remove the membership of a manager from a private site and response is 204") + public void userIsNotAbleToRemoveManagerSiteMembershipOfPrivateSite() throws Exception + { + UserModel secondManager = dataUser.createRandomTestUser(); + secondManager.setUserRole(UserRole.SiteManager); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(privateSiteModel).addPerson(secondManager); + restClient.withCoreAPI().usingSite(privateSiteModel).addPerson(userModel); + restClient.withCoreAPI().usingSite(privateSiteModel).addPerson(managerModel); + restClient.authenticateUser(userModel).withCoreAPI().usingUser(managerModel).deleteSiteMember(privateSiteModel); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY).assertLastError() + .containsSummary(String.format(RestErrorModel.NOT_SUFFICIENT_PERMISSIONS, privateSiteModel.getId())); + } +} \ No newline at end of file diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/people/DeleteSiteMemberFullTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/DeleteSiteMemberFullTests.java new file mode 100644 index 0000000000..d8b5e73286 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/DeleteSiteMemberFullTests.java @@ -0,0 +1,207 @@ +package org.alfresco.rest.people; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class DeleteSiteMemberFullTests extends RestTest +{ + private SiteModel publicSiteModel; + private SiteModel moderatedSiteModel; + private SiteModel privateSiteModel; + private UserModel adminUserModel; + private ListUserWithRoles usersWithRolesPublicSite; + private ListUserWithRoles usersWithRolesModeratedSite; + private ListUserWithRoles usersWithRolesPrivateSite; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUserModel = dataUser.getAdminUser(); + adminUserModel.setUserRole(UserRole.SiteManager); + publicSiteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); + moderatedSiteModel = dataSite.usingUser(adminUserModel).createModeratedRandomSite(); + privateSiteModel = dataSite.usingUser(adminUserModel).createPrivateRandomSite(); + + usersWithRolesPublicSite = dataUser.addUsersWithRolesToSite(publicSiteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, + UserRole.SiteContributor); + usersWithRolesModeratedSite = dataUser.addUsersWithRolesToSite(moderatedSiteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, + UserRole.SiteContributor); + usersWithRolesPrivateSite = dataUser.addUsersWithRolesToSite(privateSiteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, + UserRole.SiteContributor); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify admin is able to remove collaborator member of a public site") + public void adminIsAbleToRemoveCollaboratorSiteMembershipFromPublicSite() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(usersWithRolesPublicSite.getOneUserWithRole(UserRole.SiteCollaborator)).deleteSiteMember(publicSiteModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(publicSiteModel).addPerson(usersWithRolesPublicSite.getOneUserWithRole(UserRole.SiteCollaborator)); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify admin is able to remove contributor member of a public site") + public void adminIsAbleToRemoveContributorSiteMembershipFromPublicSite() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(usersWithRolesPublicSite.getOneUserWithRole(UserRole.SiteContributor)).deleteSiteMember(publicSiteModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(publicSiteModel).addPerson(usersWithRolesPublicSite.getOneUserWithRole(UserRole.SiteContributor)); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify user is not able to remove contributor member of a public site and response is 422") + public void userIsNotAbleToRemoveContributorSiteMembershipFromPublicSite() throws Exception + { + restClient.authenticateUser(usersWithRolesPublicSite.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingUser(usersWithRolesPublicSite.getOneUserWithRole(UserRole.SiteContributor)).deleteSiteMember(publicSiteModel); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY).assertLastError() + .containsSummary(String.format(RestErrorModel.NOT_SUFFICIENT_PERMISSIONS, publicSiteModel.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify user is not able to remove consumer member of a public site and response is 422") + public void userIsNotAbleToRemoveConsumerSiteMembershipFromPublicSite() throws Exception + { + restClient.authenticateUser(usersWithRolesPublicSite.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingUser(usersWithRolesPublicSite.getOneUserWithRole(UserRole.SiteConsumer)).deleteSiteMember(publicSiteModel); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY).assertLastError() + .containsSummary(String.format(RestErrorModel.NOT_SUFFICIENT_PERMISSIONS, publicSiteModel.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify admin is able to remove collaborator member of a moderated site") + public void adminIsAbleToRemoveCollaboratorSiteMembershipFromModeratedSite() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(usersWithRolesModeratedSite.getOneUserWithRole(UserRole.SiteCollaborator)).deleteSiteMember(moderatedSiteModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(moderatedSiteModel).addPerson(usersWithRolesModeratedSite.getOneUserWithRole(UserRole.SiteCollaborator)); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify admin is able to remove contributor member of a moderated site") + public void adminIsAbleToRemoveContributorSiteMembershipFromModeratedSite() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(usersWithRolesModeratedSite.getOneUserWithRole(UserRole.SiteContributor)).deleteSiteMember(moderatedSiteModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(moderatedSiteModel).addPerson(usersWithRolesModeratedSite.getOneUserWithRole(UserRole.SiteContributor)); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify user is not able to remove contributor member of a moderated site and response is 422") + public void userIsNotAbleToRemoveContributorSiteMembershipFromModeratedSite() throws Exception + { + restClient.authenticateUser(usersWithRolesModeratedSite.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingUser(usersWithRolesModeratedSite.getOneUserWithRole(UserRole.SiteContributor)).deleteSiteMember(moderatedSiteModel); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY).assertLastError() + .containsSummary(String.format(RestErrorModel.NOT_SUFFICIENT_PERMISSIONS, moderatedSiteModel.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify user is not able to remove consumer member of a moderated site and response is 422") + public void userIsNotAbleToRemoveConsumerSiteMembershipFromModeratedSite() throws Exception + { + restClient.authenticateUser(usersWithRolesModeratedSite.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingUser(usersWithRolesModeratedSite.getOneUserWithRole(UserRole.SiteConsumer)).deleteSiteMember(moderatedSiteModel); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY).assertLastError() + .containsSummary(String.format(RestErrorModel.NOT_SUFFICIENT_PERMISSIONS, moderatedSiteModel.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify admin is able to remove collaborator member of a private site") + public void adminIsAbleToRemoveCollaboratorSiteMembershipFromPrivateSite() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(usersWithRolesPrivateSite.getOneUserWithRole(UserRole.SiteCollaborator)).deleteSiteMember(privateSiteModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(privateSiteModel).addPerson(usersWithRolesPrivateSite.getOneUserWithRole(UserRole.SiteCollaborator)); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify admin is able to remove contributor member of a private site") + public void adminIsAbleToRemoveContributorSiteMembershipFromPrivateSite() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(usersWithRolesPrivateSite.getOneUserWithRole(UserRole.SiteContributor)).deleteSiteMember(privateSiteModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(privateSiteModel).addPerson(usersWithRolesPrivateSite.getOneUserWithRole(UserRole.SiteContributor)); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify user is not able to remove contributor member of a private site and response is 422") + public void userIsNotAbleToRemoveContributorSiteMembershipFromPrivateSite() throws Exception + { + restClient.authenticateUser(usersWithRolesPrivateSite.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingUser(usersWithRolesPrivateSite.getOneUserWithRole(UserRole.SiteContributor)).deleteSiteMember(privateSiteModel); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY).assertLastError() + .containsSummary(String.format(RestErrorModel.NOT_SUFFICIENT_PERMISSIONS, privateSiteModel.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify user is not able to remove consumer member of a private site and response is 422") + public void userIsNotAbleToRemoveConsumerSiteMembershipFromPrivateSite() throws Exception + { + restClient.authenticateUser(usersWithRolesPrivateSite.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingUser(usersWithRolesPrivateSite.getOneUserWithRole(UserRole.SiteConsumer)).deleteSiteMember(privateSiteModel); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY).assertLastError() + .containsSummary(String.format(RestErrorModel.NOT_SUFFICIENT_PERMISSIONS, privateSiteModel.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify admin is not able to remove same user twice and response is 400") + @Bug(id="ACE-5447") + public void adminIsNotAbleToRemoveSameUserTwice() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(usersWithRolesPublicSite.getOneUserWithRole(UserRole.SiteCollaborator)).deleteSiteMember(publicSiteModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(usersWithRolesPublicSite.getOneUserWithRole(UserRole.SiteCollaborator)).deleteSiteMember(publicSiteModel); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(RestErrorModel.ENTITY_NOT_FOUND); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(publicSiteModel).addPerson(usersWithRolesPublicSite.getOneUserWithRole(UserRole.SiteCollaborator)); + restClient.withCoreAPI().usingSite(publicSiteModel).getSiteMembers().assertThat().entriesListContains("id", usersWithRolesPublicSite.getOneUserWithRole(UserRole.SiteCollaborator).getUsername()) + .when().getSiteMember(usersWithRolesPublicSite.getOneUserWithRole(UserRole.SiteCollaborator).getUsername()) + .assertSiteMemberHasRole(UserRole.SiteCollaborator); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify single manager is not able to delete himself and response is 400") + public void lastManagerIsNotAbleToDeleteHimself() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(usersWithRolesPublicSite.getOneUserWithRole(UserRole.SiteManager)).deleteSiteMember(publicSiteModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withCoreAPI().usingUser(adminUserModel).deleteSiteMember(publicSiteModel); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.DELETE_LAST_MANAGER, publicSiteModel.getTitle())) + .containsErrorKey(String.format(RestErrorModel.DELETE_LAST_MANAGER, publicSiteModel.getTitle())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER).stackTraceIs(RestErrorModel.STACKTRACE); + + restClient.withCoreAPI().usingSite(publicSiteModel).addPerson(usersWithRolesPublicSite.getOneUserWithRole(UserRole.SiteManager)); + restClient.withCoreAPI().usingSite(publicSiteModel).getSiteMembers() + .assertThat().entriesListContains("id", usersWithRolesPublicSite.getOneUserWithRole(UserRole.SiteManager).getUsername()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify site creator can be deleted") + public void siteCreatorCanBeDeleted() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(adminUserModel).deleteSiteMember(publicSiteModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.authenticateUser(usersWithRolesPublicSite.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingSite(publicSiteModel).addPerson(adminUserModel); + restClient.withCoreAPI().usingSite(publicSiteModel).getSiteMembers().assertThat().entriesListContains("id", adminUserModel.getUsername()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify admin is not able to remove from site a user that created a member request that was not accepted yet") + @Bug(id="ACE-5447") + public void adminIsNotAbleToRemoveFromSiteANonExistingMember() throws Exception + { + UserModel newMember = dataUser.createRandomTestUser(); + restClient.authenticateUser(newMember).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSiteModel); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(newMember).deleteSiteMember(moderatedSiteModel); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(RestErrorModel.ENTITY_NOT_FOUND); + } + +} \ No newline at end of file diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/people/DeleteSiteMemberSanityTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/DeleteSiteMemberSanityTests.java new file mode 100644 index 0000000000..0ffff6c728 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/DeleteSiteMemberSanityTests.java @@ -0,0 +1,109 @@ +package org.alfresco.rest.people; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.exception.JsonToModelConversionException; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; +import org.alfresco.utility.exception.DataPreparationException; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class DeleteSiteMemberSanityTests extends RestTest +{ + private SiteModel siteModel; + private UserModel adminUser; + private ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws DataPreparationException + { + adminUser = dataUser.getAdminUser(); + siteModel = dataSite.usingUser(adminUser).createPublicRandomSite(); + + usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, + UserRole.SiteContributor); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, description = "Verify site manager is able to delete another member of the site") + public void siteManagerCanDeleteSiteMember() throws JsonToModelConversionException, DataPreparationException, Exception + { + UserModel newUser = dataUser.createRandomTestUser("testUser"); + newUser.setUserRole(UserRole.SiteCollaborator); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingSite(siteModel).addPerson(newUser); + + restClient.withCoreAPI().usingUser(newUser).deleteSiteMember(siteModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, description = "Verify admin user is able to delete another member of the site") + public void adminIsAbleToDeleteSiteMember() throws JsonToModelConversionException, DataPreparationException, Exception + { + UserModel newUser = dataUser.createRandomTestUser("testUser"); + newUser.setUserRole(UserRole.SiteCollaborator); + restClient.authenticateUser(adminUser).withCoreAPI().usingSite(siteModel).addPerson(newUser); + + restClient.withCoreAPI().usingUser(newUser).deleteSiteMember(siteModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, description = "Verify site collaborator does not have permission to delete another member of the site") + public void siteCollaboratorIsNotAbleToDeleteSiteMember() throws JsonToModelConversionException, DataPreparationException, Exception + { + UserModel newUser = dataUser.createRandomTestUser("testUser"); + newUser.setUserRole(UserRole.SiteCollaborator); + restClient.authenticateUser(adminUser).withCoreAPI().usingSite(siteModel).addPerson(newUser); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); + + restClient.withCoreAPI().usingUser(newUser).deleteSiteMember(siteModel); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY).assertLastError() + .containsSummary(String.format(RestErrorModel.NOT_SUFFICIENT_PERMISSIONS, siteModel.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify site contributor does not have permission to delete another member of the site") + public void siteContributorIsNotAbleToDeleteSiteMember() throws JsonToModelConversionException, DataPreparationException, Exception + { + UserModel newUser = dataUser.createRandomTestUser("testUser"); + newUser.setUserRole(UserRole.SiteCollaborator); + restClient.authenticateUser(adminUser).withCoreAPI().usingSite(siteModel).addPerson(newUser); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); + + restClient.withCoreAPI().usingUser(newUser).deleteSiteMember(siteModel); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY).assertLastError() + .containsSummary(String.format(RestErrorModel.NOT_SUFFICIENT_PERMISSIONS, siteModel.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify site consumer does not have permission to delete another member of the site") + public void siteConsumerIsNotAbleToDeleteSiteMember() throws JsonToModelConversionException, DataPreparationException, Exception + { + UserModel newUser = dataUser.createRandomTestUser("testUser"); + newUser.setUserRole(UserRole.SiteCollaborator); + restClient.authenticateUser(adminUser).withCoreAPI().usingSite(siteModel).addPerson(newUser); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)); + + restClient.withCoreAPI().usingUser(newUser).deleteSiteMember(siteModel); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY).assertLastError() + .containsSummary(String.format(RestErrorModel.NOT_SUFFICIENT_PERMISSIONS, siteModel.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify unauthenticated user is not able to delete another member of the site") + public void unauthenticatedUserIsNotAbleToDeleteSiteMember() throws JsonToModelConversionException, DataPreparationException, Exception + { + restClient.authenticateUser(new UserModel("random user", "random password")); + + restClient.withCoreAPI().usingUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).deleteSiteMember(siteModel); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } +} \ No newline at end of file diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/people/GetPeopleCoreTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/GetPeopleCoreTests.java new file mode 100644 index 0000000000..759689127a --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/GetPeopleCoreTests.java @@ -0,0 +1,56 @@ +package org.alfresco.rest.people; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * + * @author Cristina Axinte + * + */ +public class GetPeopleCoreTests extends RestTest +{ + UserModel userModel; + SiteModel siteModel; + UserModel searchedUser; + UserModel adminUser, managerUser; + UserModel inexistentUser; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + userModel = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); + searchedUser = dataUser.createRandomTestUser(); + managerUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(managerUser, siteModel, UserRole.SiteManager); + inexistentUser = new UserModel("inexistentUser", "password"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify inexistent user cannot get a person with Rest API and response is 401") + public void inexistentUserIsUnauthorizedToGetPerson() throws Exception + { + restClient.authenticateUser(inexistentUser).withCoreAPI().usingUser(searchedUser).getPerson(); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify user cannot get a person that doesn't exists with Rest API and response is 404") + public void userCannotGetInexistentPerson() throws Exception + { + restClient.authenticateUser(managerUser).withCoreAPI().usingUser(inexistentUser).getPerson(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND); + restClient.assertLastError().containsSummary(String.format(inexistentUser.getUsername(), RestErrorModel.ENTITY_NOT_FOUND)); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/people/GetPeopleFullTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/GetPeopleFullTests.java new file mode 100644 index 0000000000..a447bd1d58 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/GetPeopleFullTests.java @@ -0,0 +1,88 @@ +package org.alfresco.rest.people; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.model.RestPersonModel; +import org.alfresco.rest.model.RestPersonModelsCollection; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class GetPeopleFullTests extends RestTest +{ + UserModel userModel; + SiteModel siteModel; + UserModel searchedUser, managerUser; + UserModel adminUser; + private RestPersonModel personModel; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + userModel = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); + searchedUser = dataUser.createRandomTestUser(); + managerUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(managerUser, siteModel, UserRole.SiteManager); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify entry details for get person response with Rest API") + public void checkResponseSchemaForGetPerson() throws Exception + { + RestPersonModel newUser = RestPersonModel.getRandomPersonModel("aspectNames", "avatarId", "statusUpdatedAt","displayName"); + newUser = restClient.authenticateUser(adminUser).withCoreAPI().usingAuthUser().createPerson(newUser); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + personModel = restClient.authenticateUser(userModel).withCoreAPI().usingUser(new UserModel(newUser.getId(), newUser.getPassword())).getPerson(); + restClient.assertStatusCodeIs(HttpStatus.OK); + + personModel.assertThat().field("id").is(newUser.getId()) + .and().field("firstName").is(newUser.getFirstName()) + .and().field("lastName").is(newUser.getLastName()) + .and().field("description").is(newUser.getDescription()) + .and().field("email").is(newUser.getEmail()) + .and().field("skypeId").is(newUser.getSkypeId()) + .and().field("googleId").is(newUser.getGoogleId()) + .and().field("instantMessageId").is(newUser.getInstantMessageId()) + .and().field("jobTitle").is(newUser.getJobTitle()) + .and().field("location").is(newUser.getLocation()) + .and().field("mobile").is(newUser.getMobile()) + .and().field("telephone").is(newUser.getTelephone()) + .and().field("userStatus").is(newUser.getUserStatus()) + .and().field("enabled").is(newUser.getEnabled()) + .and().field("emailNotificationsEnabled").is(newUser.getEmailNotificationsEnabled()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify user gets a person with empty personId with Rest API and response is successful") + public void userGetPersonWithEmptyPersonId() throws Exception + { + restClient.authenticateUser(managerUser).withCoreAPI(); + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "people/{personId}?{parameters}", "", restClient.getParameters()); + RestPersonModelsCollection persons = restClient.processModels(RestPersonModelsCollection.class, request); + restClient.assertStatusCodeIs(HttpStatus.OK); + persons.assertThat().entriesListIsNotEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify user gets admin user with Rest API and response is successful") + public void managerUserGetAdminPerson() throws Exception + { + personModel = restClient.authenticateUser(managerUser).withCoreAPI().usingUser(adminUser).getPerson(); + restClient.assertStatusCodeIs(HttpStatus.OK); + personModel.assertThat().field("id").is(adminUser.getUsername()) + .and().field("firstName").is("Administrator") + .and().field("email").is("admin@alfresco.com") + .and().field("emailNotificationsEnabled").is("true") + .and().field("enabled").is("true"); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/people/GetPeopleSanityTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/GetPeopleSanityTests.java new file mode 100644 index 0000000000..2678895a52 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/GetPeopleSanityTests.java @@ -0,0 +1,110 @@ +package org.alfresco.rest.people; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestPersonModel; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class GetPeopleSanityTests extends RestTest +{ + UserModel userModel; + SiteModel siteModel; + UserModel searchedUser; + UserModel adminUser; + private RestPersonModel personModel; + private String domain = "@tas-automation.org"; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + userModel = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); + searchedUser = dataUser.createRandomTestUser(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, description = "Verify manager user gets a person with Rest API and response is successful") + public void managerUserChecksIfPersonIsPresent() throws Exception + { + UserModel managerUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(managerUser, siteModel, UserRole.SiteManager); + + personModel = restClient.authenticateUser(managerUser).withCoreAPI().usingUser(searchedUser).getPerson(); + restClient.assertStatusCodeIs(HttpStatus.OK); + personModel.assertThat().field("id").is(searchedUser.getUsername()).assertThat().field("firstName").is(searchedUser.getUsername() + " FirstName").and() + .field("email").is(searchedUser.getUsername() + domain).and().field("emailNotificationsEnabled").is("true"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, description = "Verify collaborator user gets a person with Rest API and response is successful") + public void collaboratorUserChecksIfPersonIsPresent() throws Exception + { + UserModel collaboratorUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(collaboratorUser, siteModel, UserRole.SiteCollaborator); + + personModel = restClient.authenticateUser(collaboratorUser).withCoreAPI().usingUser(searchedUser).getPerson(); + restClient.assertStatusCodeIs(HttpStatus.OK); + personModel.assertThat().field("id").is(searchedUser.getUsername()).assertThat().field("firstName").is(searchedUser.getUsername() + " FirstName").and() + .field("email").is(searchedUser.getUsername() + domain).and().field("emailNotificationsEnabled").is("true"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.COMMENTS, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, description = "Verify contributor user gets a person with Rest API and response is successful") + public void contributorUserChecksIfPersonIsPresent() throws Exception + { + UserModel contributorUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(contributorUser, siteModel, UserRole.SiteContributor); + + personModel = restClient.authenticateUser(contributorUser).withCoreAPI().usingUser(searchedUser).getPerson(); + restClient.assertStatusCodeIs(HttpStatus.OK); + personModel.assertThat().field("id").is(searchedUser.getUsername()).assertThat().field("firstName").is(searchedUser.getUsername() + " FirstName").and() + .field("email").is(searchedUser.getUsername() + domain).and().field("emailNotificationsEnabled").is("true"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, description = "Verify consumer user gets a person with Rest API and response is successful") + public void consumerUserChecksIfPersonIsPresent() throws Exception + { + UserModel consumerUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(consumerUser, siteModel, UserRole.SiteConsumer); + + personModel = restClient.authenticateUser(consumerUser).withCoreAPI().usingUser(searchedUser).getPerson(); + restClient.assertStatusCodeIs(HttpStatus.OK); + personModel.assertThat().field("id").is(searchedUser.getUsername()).assertThat().field("firstName").is(searchedUser.getUsername() + " FirstName").and() + .field("email").is(searchedUser.getUsername() + domain).and().field("emailNotificationsEnabled").is("true"); + ; + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, description = "Verify admin user gets a person with Rest API and response is successful") + public void adminUserChecksIfPersonIsPresent() throws Exception + { + personModel = restClient.authenticateUser(adminUser).withCoreAPI().usingUser(searchedUser).getPerson(); + restClient.assertStatusCodeIs(HttpStatus.OK); + personModel.assertThat().field("id").is(searchedUser.getUsername()).assertThat().field("firstName").is(searchedUser.getUsername() + " FirstName").and() + .field("email").is(searchedUser.getUsername() + domain).and().field("emailNotificationsEnabled").is("true"); + ; + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, description = "Verify manager user gets a non existing person with Rest API and person is not found") + public void managerUserChecksIfNonExistingPersonIsPresent() throws Exception + { + UserModel managerUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(managerUser, siteModel, UserRole.SiteManager); + UserModel searchedNonUser = new UserModel("nonexistinguser", DataUser.PASSWORD); + + restClient.authenticateUser(managerUser).withCoreAPI().usingUser(searchedNonUser).getPerson(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "")); + } +} \ No newline at end of file diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/people/GetSiteMembershipCoreTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/GetSiteMembershipCoreTests.java new file mode 100644 index 0000000000..a1ed9384e6 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/GetSiteMembershipCoreTests.java @@ -0,0 +1,114 @@ +package org.alfresco.rest.people; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestSiteEntry; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 11/28/2016. + */ + +public class GetSiteMembershipCoreTests extends RestTest +{ + UserModel regularUser, publicSiteManager, privateSiteManager, moderatedSiteManager, adminUser; + SiteModel publicSite, privateSite, moderatedSite; + private DataUser.ListUserWithRoles publicSiteUsers; + private RestSiteEntry restSiteEntry; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + regularUser = dataUser.createRandomTestUser(); + privateSiteManager = dataUser.createRandomTestUser(); + moderatedSiteManager = dataUser.createRandomTestUser(); + publicSite = dataSite.usingAdmin().createPublicRandomSite(); + privateSite = dataSite.usingAdmin().createPrivateRandomSite(); + moderatedSite = dataSite.usingAdmin().createModeratedRandomSite(); + + publicSiteUsers = dataUser.addUsersWithRolesToSite(publicSite, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, + UserRole.SiteContributor); + publicSiteManager = publicSiteUsers.getOneUserWithRole(UserRole.SiteManager); + dataUser.usingAdmin().addUserToSite(privateSiteManager, privateSite, UserRole.SiteManager); + dataUser.usingAdmin().addUserToSite(moderatedSiteManager, moderatedSite, UserRole.SiteManager); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) +// @Bug(id = "REPO-1642", description = "reproduced on 5.2.1 only, it works on 5.2.0") + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify get site membership for a site returns status 404 when personId does not exist.") + public void getSiteMembershipUsingNonExistentPersonId() throws Exception + { + UserModel someUser = new UserModel("someUser", DataUser.PASSWORD); + + restClient.authenticateUser(regularUser).withCoreAPI().usingUser(someUser).getSiteMembership(publicSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "someUser")); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify get site membership for a site returns status 404 when siteId does not exist.") + public void getSiteMembershipUsingNonExistentSiteId() throws Exception + { + SiteModel someSite = new SiteModel("someSite"); + + restClient.authenticateUser(regularUser).withCoreAPI().usingAuthUser().getSiteMembership(someSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, regularUser.getUsername(), "someSite")); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify get site membership for a site returns status 404 when personId is not a site member.") + public void getSiteMembershipForPersonThatIsNotSiteMember() throws Exception + { + restClient.authenticateUser(publicSiteManager).withCoreAPI().usingUser(regularUser).getSiteMembership(publicSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, regularUser.getUsername(), publicSite.getTitle())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify regular user is not able to retrieve site membership information of a private site member.") + public void regularUserIsNotAbleToRetrieveSiteMembershipForPrivateSiteManager() throws Exception + { + restClient.authenticateUser(regularUser).withCoreAPI().usingUser(privateSiteManager).getSiteMembership(privateSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, privateSiteManager.getUsername(), privateSite.getTitle())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify regular user is able to retrieve site membership information of a moderated site member.") + public void regularUserGetsSiteMembershipForModeratedSiteMember() throws Exception + { + restSiteEntry = restClient.authenticateUser(regularUser).withCoreAPI().usingUser(moderatedSiteManager).getSiteMembership(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.OK); + restSiteEntry.assertThat().field("role").is(UserRole.SiteManager).and().field("id").is(moderatedSite.getId()).and().field("site").isNotEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify if Admin user is able to retrieve site membership information of him.") + public void adminGetsSiteMembershipForHim() throws Exception + { + restSiteEntry = restClient.authenticateUser(adminUser).withCoreAPI().usingUser(adminUser).getSiteMembership(privateSite); + restClient.assertStatusCodeIs(HttpStatus.OK); + restSiteEntry.assertThat().field("role").is(UserRole.SiteManager).and().field("id").is(privateSite.getId()).and().field("site").isNotEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify if Admin user is able to retrieve site membership information of him.") + public void getSiteMembershipAfterRemovingASiteMember() throws Exception + { + UserModel publicSiteConsumer = publicSiteUsers.getOneUserWithRole(UserRole.SiteConsumer); + restClient.authenticateUser(publicSiteManager).withCoreAPI().usingSite(publicSite).deleteSiteMember(publicSiteConsumer); + restClient.authenticateUser(publicSiteManager).withCoreAPI().usingUser(publicSiteConsumer).getSiteMembership(publicSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, publicSiteConsumer.getUsername(), publicSite.getTitle())); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/people/GetSiteMembershipFullTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/GetSiteMembershipFullTests.java new file mode 100644 index 0000000000..7ad0ae6f94 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/GetSiteMembershipFullTests.java @@ -0,0 +1,138 @@ +package org.alfresco.rest.people; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestSiteEntry; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class GetSiteMembershipFullTests extends RestTest +{ + UserModel regularUser, adminUser; + SiteModel publicSite, moderatedSite; + private DataUser.ListUserWithRoles publicSiteUsers; + private RestSiteEntry restSiteEntry; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + regularUser = dataUser.createRandomTestUser(); + publicSite = dataSite.usingAdmin().createPublicRandomSite(); + moderatedSite = dataSite.usingAdmin().createModeratedRandomSite(); + + publicSiteUsers = dataUser.addUsersWithRolesToSite(publicSite, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, + UserRole.SiteContributor); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify that properties parameter is applied.") + public void checkThatPropertiesParameterIsApplied() throws Exception + { + restSiteEntry = restClient.authenticateUser(regularUser).withCoreAPI().usingParams("properties=site,role,id") + .usingUser(publicSiteUsers.getOneUserWithRole(UserRole.SiteManager)).getSiteMembership(publicSite); + restClient.assertStatusCodeIs(HttpStatus.OK); + restSiteEntry.assertThat().field("role").is(UserRole.SiteManager) + .and().field("id").is(publicSite.getId()) + .and().field("site").isNotEmpty() + .and().field("guid").isNull(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify that regular user " + + "is able to retrieve site membership information of admin.") + public void regularUserGetsSiteMembershipForAdmin() throws Exception + { + restSiteEntry = restClient.authenticateUser(regularUser).withCoreAPI().usingUser(adminUser).getSiteMembership(publicSite); + restClient.assertStatusCodeIs(HttpStatus.OK); + restSiteEntry.assertThat().field("role").is(UserRole.SiteManager) + .and().field("id").is(publicSite.getId()) + .and().field("site.id").is(publicSite.getId()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify that regular user " + + "is able to retrieve site membership details for a Collaborator role.") + public void getSiteMembershipDetailsForACollaboratorRole() throws Exception + { + restSiteEntry = restClient.authenticateUser(regularUser).withCoreAPI() + .usingUser(publicSiteUsers.getOneUserWithRole(UserRole.SiteCollaborator)).getSiteMembership(publicSite); + restClient.assertStatusCodeIs(HttpStatus.OK); + restSiteEntry.assertThat().field("role").is(UserRole.SiteCollaborator) + .and().field("guid").is(publicSite.getGuid()) + .and().field("id").is(publicSite.getId()) + .and().field("site.visibility").is(publicSite.getVisibility().toString()) + .and().field("site.guid").is(publicSite.getGuid()) + .and().field("site.description").is(publicSite.getDescription()) + .and().field("site.id").is(publicSite.getId()) + .and().field("site.preset").is("site-dashboard") + .and().field("site.title").is(publicSite.getTitle()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify that regular user " + + "is able to retrieve site membership details for a Contributor role.") + public void getSiteMembershipDetailsForAContributorRole() throws Exception + { + restSiteEntry = restClient.authenticateUser(regularUser).withCoreAPI() + .usingUser(publicSiteUsers.getOneUserWithRole(UserRole.SiteContributor)).getSiteMembership(publicSite); + restClient.assertStatusCodeIs(HttpStatus.OK); + restSiteEntry.assertThat().field("role").is(UserRole.SiteContributor) + .and().field("id").is(publicSite.getId()) + .and().field("site").isNotEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify that regular user " + + "is able to retrieve site membership details for a Consumer role.") + public void getSiteMembershipDetailsForAConsumerRole() throws Exception + { + restSiteEntry = restClient.authenticateUser(regularUser).withCoreAPI() + .usingUser(publicSiteUsers.getOneUserWithRole(UserRole.SiteConsumer)).getSiteMembership(publicSite); + restClient.assertStatusCodeIs(HttpStatus.OK); + restSiteEntry.assertThat().field("role").is(UserRole.SiteConsumer) + .and().field("id").is(publicSite.getId()) + .and().field("site").isNotEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "As regular user make a request to join a moderated site." + + " The request is pending. Check membership details.") + public void pendingRequestToASiteCheckMembershipDetails() throws Exception + { + restClient.authenticateUser(regularUser).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restSiteEntry = restClient.authenticateUser(adminUser).withCoreAPI() + .usingUser(regularUser).getSiteMembership(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, regularUser.getUsername(), moderatedSite.getTitle())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "As Collaborator user leave site and perform get call." + + "Check default error model schema.") + public void leaveSiteAndPerformGetCallCheckDefaultErrorModelSchema() throws Exception + { + UserModel leaveSiteUser = dataUser.createRandomTestUser(); + dataUser.addUserToSite(leaveSiteUser, publicSite, UserRole.SiteCollaborator); + restClient.authenticateUser(leaveSiteUser).withCoreAPI().usingAuthUser().deleteSiteMember(publicSite); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + restSiteEntry = restClient.authenticateUser(adminUser).withCoreAPI() + .usingUser(leaveSiteUser).getSiteMembership(publicSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsErrorKey(RestErrorModel.RELATIONSHIP_NOT_FOUND_ERRORKEY) + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, leaveSiteUser.getUsername(), publicSite.getTitle())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/people/GetSiteMembershipSanityTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/GetSiteMembershipSanityTests.java new file mode 100644 index 0000000000..2ee570239b --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/GetSiteMembershipSanityTests.java @@ -0,0 +1,89 @@ +package org.alfresco.rest.people; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.exception.JsonToModelConversionException; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; +import org.alfresco.utility.exception.DataPreparationException; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class GetSiteMembershipSanityTests extends RestTest +{ + private SiteModel siteModel; + private UserModel adminUser; + private ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws DataPreparationException + { + adminUser = dataUser.getAdminUser(); + siteModel = dataSite.usingUser(adminUser).createPublicRandomSite(); + + usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, + UserRole.SiteContributor); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, description = "Verify site manager is able to retrieve site membership information of another user") + public void siteManagerCanRetrieveSiteMembershipInformation() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingUser(adminUser).getSiteMembership(siteModel) + .assertThat().field("role").is(UserRole.SiteManager).and().field("id").is(siteModel.getId()).and().field("site").isNotEmpty(); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, description = "Verify site collaborator is able to retrieve site membership information of another user") + public void siteCollaboratorCanRetrieveSiteMembershipInformation() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingUser(adminUser) + .getSiteMembership(siteModel).onSite().assertThat().field("role").is(UserRole.SiteCollaborator).and().field("id").is(siteModel.getId()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, description = "Verify site contributor is able to retrieve site membership information of another user") + public void siteContributorCanRetrieveSiteMembershipInformation() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).withCoreAPI().usingUser(adminUser) + .getSiteMembership(siteModel).assertThat().field("role").is(UserRole.SiteManager).and().field("id").is(siteModel.getId()).and().field("site") + .isNotEmpty(); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, description = "Verify site consumer is able to retrieve site membership information of another user") + public void siteConsumerCanRetrieveSiteMembershipInformation() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI().usingUser(adminUser).getSiteMembership(siteModel) + .assertThat().field("role").is(UserRole.SiteManager).and().field("id").is(siteModel.getId()).and().field("site").isNotEmpty(); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, description = "Verify admin user is able to retrieve site membership information of another user") + public void adminCanRetrieveSiteMembershipInformation() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(adminUser).withCoreAPI().usingUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).getSiteMembership(siteModel) + .assertThat().field("role").is(UserRole.SiteManager).and().field("id").is(siteModel.getId()).and().field("site").isNotEmpty(); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, description = "Verify unauthenticated user is not able to retrieve site membership information of another user") +// @Bug(id="MNT-16904", description = "It fails only on environment with tenants") + public void unauthenticatedUserCannotRetrieveSiteMembershipInformation() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(new UserModel("random user", "random password")).withCoreAPI() + .usingUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).getSiteMembership(siteModel); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } +} \ No newline at end of file diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/people/GetSitesMembershipInformationCoreTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/GetSitesMembershipInformationCoreTests.java new file mode 100644 index 0000000000..16a91b9697 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/GetSitesMembershipInformationCoreTests.java @@ -0,0 +1,136 @@ +package org.alfresco.rest.people; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.exception.DataPreparationException; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class GetSitesMembershipInformationCoreTests extends RestTest +{ + private SiteModel publicSiteModel; + private SiteModel moderatedSiteModel; + private SiteModel privateSiteModel; + private UserModel userModel; + UserModel leaveSiteUserModel; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws DataPreparationException + { + userModel = dataUser.createRandomTestUser(); + leaveSiteUserModel = dataUser.createRandomTestUser(); + publicSiteModel = dataSite.usingUser(userModel).createPublicRandomSite(); + moderatedSiteModel = dataSite.usingUser(userModel).createModeratedRandomSite(); + privateSiteModel = dataSite.usingUser(userModel).createPrivateRandomSite(); + dataUser.addUserToSite(leaveSiteUserModel, publicSiteModel, UserRole.SiteCollaborator); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify site manager is not able to retrieve site membership information for a personId that does not exist") + public void siteManagerCantRetrieveSiteMembershipInformationForAPersonIdThatDoesNotExist() throws Exception + { + restClient.authenticateUser(userModel).withCoreAPI().usingUser(new UserModel("invalidPersonId", "password")).getSitesMembershipInformation() + .assertThat().entriesListIsEmpty(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND); + restClient.assertLastError().containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "invalidPersonId")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify if get site membership information request returns status code 400 when invalid maxItems parameter is used") + public void getSiteMembershipInformationRequestReturns400ForInvalidMaxItemsParameter() throws Exception + { + restClient.authenticateUser(userModel).withParams("maxItems=0").withCoreAPI().usingAuthUser().getSitesMembershipInformation().assertThat() + .entriesListIsEmpty(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST); + restClient.assertLastError().containsSummary(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS); + + restClient.withParams("maxItems=-1").withCoreAPI().usingAuthUser().getSitesMembershipInformation().assertThat().entriesListIsEmpty(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST); + restClient.assertLastError().containsSummary(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS); + + restClient.withParams("maxItems=test").withCoreAPI().usingAuthUser().getSitesMembershipInformation().assertThat().entriesListIsEmpty(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST); + restClient.assertLastError().containsSummary(String.format(RestErrorModel.INVALID_MAXITEMS, "test")); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify if get site membership information request returns status code 200 for valid maxItems parameter") + public void getSiteMembershipInformationRequestReturns200ForValidMaxItemsParameter() throws Exception + { + restClient.authenticateUser(userModel).withParams("maxItems=5").withCoreAPI().usingAuthUser().getSitesMembershipInformation().assertThat() + .entriesListIsNotEmpty().getPagination().assertThat().field("maxItems").is("5"); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify if get site membership information request returns status code 400 when invalid skipCount parameter is used") + public void getSiteMembershipInformationRequestReturns400ForInvalidSkipCountParameter() throws Exception + { + restClient.authenticateUser(userModel).withParams("skipCount=-1").withCoreAPI().usingAuthUser().getSitesMembershipInformation().assertThat() + .entriesListIsEmpty(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST); + restClient.assertLastError().containsSummary(RestErrorModel.NEGATIVE_VALUES_SKIPCOUNT); + + restClient.withParams("skipCount=test").withCoreAPI().usingAuthUser().getSitesMembershipInformation().assertThat().entriesListIsEmpty(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST); + restClient.assertLastError().containsErrorKey(String.format(RestErrorModel.INVALID_SKIPCOUNT, "test")) + .containsSummary(String.format(RestErrorModel.INVALID_SKIPCOUNT, "test")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify if get site membership information request returns status code 200 for valid skipCount parameter") + public void getSiteMembershipInformationRequestReturns200ForValidSkipCountParameter() throws Exception + { + restClient.authenticateUser(userModel).withParams("skipCount=1").withCoreAPI().usingAuthUser().getSitesMembershipInformation().assertThat() + .entriesListIsNotEmpty().getPagination().assertThat().field("skipCount").is("1"); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify site manager is able to retrieve public sites") + public void siteManagerCheckThatPublicSitesAreRetrieved() throws Exception + { + restClient.authenticateUser(userModel).withCoreAPI().usingAuthUser().getSitesMembershipInformation().assertThat() + .entriesListContains("id", publicSiteModel.getId()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify site manager is able to retrieve moderated sites") + public void siteManagerCheckThatModeratedSitesAreRetrieved() throws Exception + { + restClient.authenticateUser(userModel).withCoreAPI().usingAuthUser().getSitesMembershipInformation().assertThat() + .entriesListContains("id", moderatedSiteModel.getId()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify site manager is able to retrieve private sites") + public void siteManagerCheckThatPrivateSitesAreRetrieved() throws Exception + { + restClient.authenticateUser(userModel).withCoreAPI().usingAuthUser().getSitesMembershipInformation().assertThat() + .entriesListContains("id", privateSiteModel.getId()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify site member is able to leave site") + public void siteMemberIsAbleToLeaveSite() throws Exception + { + restClient.authenticateUser(leaveSiteUserModel).withCoreAPI().usingAuthUser().deleteSiteMember(publicSiteModel); + restClient.authenticateUser(leaveSiteUserModel).withCoreAPI().usingAuthUser().getSitesMembershipInformation().assertThat().entriesListIsEmpty(); + restClient.assertStatusCodeIs(HttpStatus.OK); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/people/GetSitesMembershipInformationFullTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/GetSitesMembershipInformationFullTests.java new file mode 100644 index 0000000000..856f8bf289 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/GetSitesMembershipInformationFullTests.java @@ -0,0 +1,205 @@ +package org.alfresco.rest.people; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestSiteMembershipModelsCollection; +import org.alfresco.rest.model.RestTaskModel; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.exception.DataPreparationException; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * + * @author Cristina Axinte + * + */ +public class GetSitesMembershipInformationFullTests extends RestTest +{ + private SiteModel publicSiteModel; + private SiteModel moderatedSiteModel; + private SiteModel privateSiteModel; + private SiteModel anotherUserSite; + private UserModel userModel, adminUser, anotherUserModel; + private RestSiteMembershipModelsCollection sitesMembershipInformation; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws DataPreparationException + { + adminUser = dataUser.getAdminUser(); + anotherUserSite = dataSite.usingUser(adminUser).createPublicRandomSite(); + userModel = dataUser.createRandomTestUser(); + anotherUserModel = dataUser.createRandomTestUser(); + publicSiteModel = dataSite.usingUser(adminUser).createPublicRandomSite(); + dataUser.addUserToSite(userModel, publicSiteModel, UserRole.SiteCollaborator); + moderatedSiteModel = dataSite.usingUser(adminUser).createModeratedRandomSite(); + dataUser.addUserToSite(userModel, moderatedSiteModel, UserRole.SiteConsumer); + privateSiteModel = dataSite.usingUser(userModel).createPrivateRandomSite(); + dataUser.addUserToSite(anotherUserModel, anotherUserSite, UserRole.SiteCollaborator); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify if get site membership information request returns status code 200 for valid properties parameter") + public void getSiteMembershipInformationUsingPropertiesParameter() throws Exception + { + sitesMembershipInformation = restClient.authenticateUser(userModel).withParams("properties=id").withCoreAPI().usingAuthUser().getSitesMembershipInformation(); + restClient.assertStatusCodeIs(HttpStatus.OK); + sitesMembershipInformation.assertThat().entriesListIsNotEmpty().getPagination().assertThat().field("count").is("3"); + sitesMembershipInformation.assertThat().entriesListContains("id", publicSiteModel.getId()) + .and().entriesListContains("id", moderatedSiteModel.getId()) + .and().entriesListContains("id", privateSiteModel.getId()) + .and().entriesListDoesNotContain("site") + .and().entriesListDoesNotContain("role") + .and().entriesListDoesNotContain("guid"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify if get site membership information request returns status code 200 for order ASC by parameter") + public void getSiteMembershipInformationUsingOrderAscByParameter() throws Exception + { + sitesMembershipInformation = restClient.authenticateUser(userModel).withParams("orderBy=id ASC").withCoreAPI().usingAuthUser().getSitesMembershipInformation(); + restClient.assertStatusCodeIs(HttpStatus.OK); + sitesMembershipInformation.assertThat().entriesListIsNotEmpty().getPagination().assertThat().field("count").is("3"); + sitesMembershipInformation.assertThat().entriesListIsSortedAscBy("id"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify if get site membership information request returns status code 200 for order DESC by parameter") + public void getSiteMembershipInformationUsingOrderDescByParameter() throws Exception + { + sitesMembershipInformation = restClient.authenticateUser(userModel).withParams("orderBy=id Desc").withCoreAPI().usingAuthUser().getSitesMembershipInformation(); + restClient.assertStatusCodeIs(HttpStatus.OK); + sitesMembershipInformation.assertThat().entriesListIsNotEmpty().getPagination().assertThat().field("count").is("3"); + sitesMembershipInformation.assertThat().entriesListIsSortedDescBy("id"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify if get site membership information request returns status code 200 for order by role parameter") + public void getSiteMembershipInformationUsingOrderByRoleParameter() throws Exception + { + sitesMembershipInformation = restClient.authenticateUser(userModel).withParams("orderBy=role").withCoreAPI().usingAuthUser().getSitesMembershipInformation(); + restClient.assertStatusCodeIs(HttpStatus.OK); + sitesMembershipInformation.assertThat().entriesListIsNotEmpty().getPagination().assertThat().field("count").is("3"); + sitesMembershipInformation.assertThat().entriesListIsSortedAscBy("role"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify if user gets site membership information of another user successfully") + public void userCanGetSiteMembershipInformationOfAnotherUser() throws Exception + { + sitesMembershipInformation = restClient.authenticateUser(userModel).withCoreAPI().usingUser(anotherUserModel).getSitesMembershipInformation(); + restClient.assertStatusCodeIs(HttpStatus.OK); + sitesMembershipInformation.assertThat().entriesListIsNotEmpty().getPagination().assertThat().field("count").is("1"); + sitesMembershipInformation.getEntries().get(0).onModel() + .assertThat().field("site.visibility").is(anotherUserSite.getVisibility().toString()) + .and().field("site.guid").is(anotherUserSite.getGuid()) + .and().field("site.description").is(anotherUserSite.getDescription()) + .and().field("site.id").is(anotherUserSite.getId()) + .and().field("site.preset").is("site-dashboard") + .and().field("site.title").is(anotherUserSite.getTitle()) + .and().field("id").is(anotherUserSite.getId()) + .and().field("guid").is(anotherUserSite.getGuid()) + .and().field("role").is(UserRole.SiteCollaborator.toString()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify if get site membership information request returns status code 200 for relations parameter") + public void getSiteMembershipInformationUsingRelationsParameter() throws Exception + { + sitesMembershipInformation = restClient.authenticateUser(userModel).withParams("relations=site-membership-requests").withCoreAPI().usingAuthUser().getSitesMembershipInformation(); + restClient.assertStatusCodeIs(HttpStatus.OK); + sitesMembershipInformation.assertThat().entriesListIsNotEmpty().getPagination().assertThat().field("count").is("3"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify get site membership information request when a site membership request is rejected") + public void getSiteMembershipInformationWhenASiteRequestIsRejected() throws Exception + { + UserModel userWithRequests = dataUser.createRandomTestUser(); + + restClient.authenticateUser(userWithRequests).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSiteModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + sitesMembershipInformation = restClient.authenticateUser(adminUser).withCoreAPI().usingUser(userWithRequests).getSitesMembershipInformation(); + restClient.assertStatusCodeIs(HttpStatus.OK); + sitesMembershipInformation.assertThat().entriesListIsEmpty() + .and().paginationField("count").is("0"); + + RestTaskModel taskModel = restClient.authenticateUser(userWithRequests).withWorkflowAPI().getTasks().getTaskModelByDescription(moderatedSiteModel); + workflow.approveSiteMembershipRequest(adminUser.getUsername(), adminUser.getPassword(), taskModel.getId(), false, "Rejected"); + + sitesMembershipInformation = restClient.authenticateUser(adminUser).withCoreAPI().usingUser(userWithRequests).getSitesMembershipInformation(); + restClient.assertStatusCodeIs(HttpStatus.OK); + sitesMembershipInformation.assertThat().entriesListIsEmpty() + .and().paginationField("count").is("0"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify get site membership information request when a site membership request is approved") + public void getSiteMembershipInformationWhenASiteRequestIsAppropved() throws Exception + { + UserModel userWithRequests = dataUser.createRandomTestUser(); + + restClient.authenticateUser(userWithRequests).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSiteModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + sitesMembershipInformation = restClient.authenticateUser(adminUser).withCoreAPI().usingUser(userWithRequests).getSitesMembershipInformation(); + restClient.assertStatusCodeIs(HttpStatus.OK); + sitesMembershipInformation.assertThat().entriesListIsEmpty() + .and().paginationField("count").is("0"); + + RestTaskModel taskModel = restClient.authenticateUser(userWithRequests).withWorkflowAPI().getTasks().getTaskModelByDescription(moderatedSiteModel); + workflow.approveSiteMembershipRequest(adminUser.getUsername(), adminUser.getPassword(), taskModel.getId(), true, "Approve"); + + sitesMembershipInformation = restClient.authenticateUser(adminUser).withCoreAPI().usingUser(userWithRequests).getSitesMembershipInformation(); + restClient.assertStatusCodeIs(HttpStatus.OK); + sitesMembershipInformation.assertThat().entriesListIsNotEmpty() + .and().entriesListContains("role", UserRole.SiteConsumer.toString()) + .and().entriesListContains("guid", moderatedSiteModel.getGuid()) + .and().entriesListContains("id", moderatedSiteModel.getId()) + .and().paginationField("count").is("1"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify if get site membership information request returns status code 200 for valid maxItems parameter") + public void getSiteMembershipInformationUsingMaxItemsParameter() throws Exception + { + sitesMembershipInformation = restClient.authenticateUser(userModel).withParams("maxItems=2").withCoreAPI().usingAuthUser().getSitesMembershipInformation(); + restClient.assertStatusCodeIs(HttpStatus.OK); + sitesMembershipInformation.assertThat().entriesListCountIs(2) + .getPagination().assertThat().field("count").is("2") + .and().field("hasMoreItems").is("true") + .and().field("totalItems").is("3") + .and().field("skipCount").is("0") + .and().field("maxItems").is("2"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify if get site membership information request returns status code 200 for valid skipCount parameter") + public void getSiteMembershipInformationUsingSkipCountParameter() throws Exception + { + sitesMembershipInformation = restClient.authenticateUser(userModel).withParams("skipCount=2").withCoreAPI().usingAuthUser().getSitesMembershipInformation(); + restClient.assertStatusCodeIs(HttpStatus.OK); + sitesMembershipInformation.assertThat().entriesListCountIs(1) + .getPagination().assertThat().field("count").is("1") + .and().field("hasMoreItems").is("false") + .and().field("totalItems").is("3") + .and().field("skipCount").is("2") + .and().field("maxItems").is("100"); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/people/GetSitesMembershipInformationSanityTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/GetSitesMembershipInformationSanityTests.java new file mode 100644 index 0000000000..3f18d43a61 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/GetSitesMembershipInformationSanityTests.java @@ -0,0 +1,88 @@ +package org.alfresco.rest.people; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.exception.JsonToModelConversionException; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; +import org.alfresco.utility.exception.DataPreparationException; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class GetSitesMembershipInformationSanityTests extends RestTest +{ + private SiteModel siteModel; + private UserModel adminUser; + private ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws DataPreparationException + { + adminUser = dataUser.getAdminUser(); + siteModel = dataSite.usingUser(adminUser).createPublicRandomSite(); + usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, + UserRole.SiteContributor); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, description = "Verify site manager is able to retrieve sites membership information of another user") + public void siteManagerIsAbleToRetrieveSitesMembershipInformation() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingUser(adminUser).getSitesMembershipInformation() + .assertThat().entriesListIsNotEmpty().and().paginationExist().and().paginationField("count").isNot("0"); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, description = "Verify site collaborator is able to retrieve sites membership information of another user") + public void siteCollaboratorIsAbleToRetrieveSitesMembershipInformation() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingUser(adminUser) + .getSitesMembershipInformation().assertThat().entriesListIsNotEmpty().and().paginationExist().and().paginationField("count").isNot("0"); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, description = "Verify site contributor is able to retrieve sites membership information of another user") + public void siteContributorIsAbleToRetrieveSitesMembershipInformation() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).withCoreAPI().usingUser(adminUser) + .getSitesMembershipInformation().assertThat().entriesListIsNotEmpty().and().paginationExist().and().paginationField("count").isNot("0"); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, description = "Verify site consumer is able to retrieve sites membership information of another user") + public void siteConsumerIsAbleToRetrieveSitesMembershipInformation() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI().usingUser(adminUser) + .getSitesMembershipInformation().assertThat().entriesListIsNotEmpty().and().paginationExist().and().paginationField("count").isNot("0"); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, description = "Verify admin is able to retrieve sites membership information of another user") + public void siteAdminIsAbleToRetrieveSitesMembershipInformation() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(adminUser).withCoreAPI().usingUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).getSitesMembershipInformation() + .assertThat().entriesListIsNotEmpty().and().paginationExist().and().paginationField("count").isNot("0"); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, description = "Verify that unauthenticated user is not able to retrieve sites membership information") +// @Bug(id="MNT-16904", description = "It fails only on environment with tenants") + public void unauthenticatedUserCannotRetrieveSitesMembershipInformation() throws JsonToModelConversionException, Exception + { + UserModel inexistentUser = new UserModel("inexistent user", "wrong password"); + restClient.authenticateUser(inexistentUser).withCoreAPI().usingUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .getSitesMembershipInformation(); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } +} \ No newline at end of file diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/people/activities/GetPeopleActivitiesCoreTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/activities/GetPeopleActivitiesCoreTests.java new file mode 100644 index 0000000000..ef5b2b8998 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/activities/GetPeopleActivitiesCoreTests.java @@ -0,0 +1,128 @@ +package org.alfresco.rest.people.activities; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestActivityModelsCollection; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.model.FileModel; +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.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * + * @author Cristina Axinte + * + */ +public class GetPeopleActivitiesCoreTests extends RestTest +{ + UserModel userModel, adminUser, managerUser; + SiteModel siteModel1, siteModel2; + FileModel fileInSite1, fileInSite2; + FolderModel folderInSite2; + private RestActivityModelsCollection restActivityModelsCollection; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + userModel = dataUser.createRandomTestUser(); + siteModel1 = dataSite.usingUser(userModel).createPublicRandomSite(); + fileInSite1 = dataContent.usingUser(userModel).usingSite(siteModel1).createContent(DocumentType.TEXT_PLAIN); + + siteModel2 = dataSite.usingUser(userModel).createPublicRandomSite(); + folderInSite2 = dataContent.usingUser(userModel).usingSite(siteModel2).createFolder(); + fileInSite2 = dataContent.usingAdmin().usingSite(siteModel2).createContent(DocumentType.TEXT_PLAIN); + + managerUser = dataUser.createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(managerUser, siteModel2, UserRole.SiteManager); + + // only once the activity list is checked with retry in order not to wait the entire list in each test + // after repo-4250 a file is created first and then update it with content, so there are more entries than previously + restActivityModelsCollection = restClient.authenticateUser(userModel).withCoreAPI().usingMe().getPersonActivitiesUntilEntriesCountIs(6); + restClient.assertStatusCodeIs(HttpStatus.OK); + restActivityModelsCollection.assertThat().paginationField("count").is("6"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.ACTIVITIES }, executionType = ExecutionType.REGRESSION, description = "Verify user cannot get activities for inexistent user with Rest API and response is 404") + public void userCannotGetPeopleActivitiesForInexistentPersonId() throws Exception + { + UserModel inexistentUserName = new UserModel("inexistent", "password"); + + restActivityModelsCollection = restClient.authenticateUser(userModel).withCoreAPI().usingUser(inexistentUserName).getPersonActivities(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, inexistentUserName.getUsername())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.ACTIVITIES }, executionType = ExecutionType.REGRESSION, description = "Verify user gets its activities for inexistent siteId with Rest API and response is 404") + public void userGetItsPeopleActivitiesForInexistentSite() throws Exception + { + restActivityModelsCollection = restClient.authenticateUser(userModel).withCoreAPI().usingUser(userModel).usingParams(String.format("siteId=inexistent")).getPersonActivities(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "inexistent")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.ACTIVITIES }, executionType = ExecutionType.REGRESSION, description = "Verify user gets activities with invald skipCount parameter with Rest API and response is 400") + public void userGetPeopleActivitiesUsingInvalidSkipCountParameter() throws Exception + { + restActivityModelsCollection = restClient.authenticateUser(userModel).withCoreAPI().usingMe().usingParams("skipCount=-1").getPersonActivities(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsErrorKey(RestErrorModel.NEGATIVE_VALUES_SKIPCOUNT) + .containsSummary(RestErrorModel.NEGATIVE_VALUES_SKIPCOUNT) + .stackTraceIs(RestErrorModel.STACKTRACE) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.ACTIVITIES }, executionType = ExecutionType.REGRESSION, description = "Verify user gets activities with invalid maxItems parameter with Rest API and response is 400") + public void userGetPeopleActivitiesUsingInvalidMaxItemsParameter() throws Exception + { + restActivityModelsCollection = restClient.authenticateUser(userModel).withCoreAPI().usingMe().usingParams("maxItems=0").getPersonActivities(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsErrorKey(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS) + .containsSummary(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS) + .stackTraceIs(RestErrorModel.STACKTRACE) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API,TestGroup.PEOPLE, TestGroup.ACTIVITIES }, executionType = ExecutionType.REGRESSION, description = "Verify user gets activities using invalid value for parameter 'who'with Rest API and response is 400") + public void userGetsPeopleActivitiesUsingInvalidValueForWhoParameter() throws Exception + { + restActivityModelsCollection = restClient.authenticateUser(userModel).withCoreAPI().usingUser(userModel).usingParams("who=mee").getPersonActivities(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsErrorKey(RestErrorModel.INVALID_PARAMETER_WHO) + .containsSummary(RestErrorModel.INVALID_PARAMETER_WHO) + .stackTraceIs(RestErrorModel.STACKTRACE) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API,TestGroup.PEOPLE, TestGroup.ACTIVITIES }, executionType = ExecutionType.REGRESSION, description = "Verify user gets activities successfully using parameter 'who' with 'others' value with Rest API") + public void userGetsPeopleActivitiesUsingOthersForWhoParameter() throws Exception + { + restActivityModelsCollection = restClient.authenticateUser(userModel).withCoreAPI().usingUser(userModel).usingParams("who=others").getPersonActivities(); + restClient.assertStatusCodeIs(HttpStatus.OK); + // after repo-4250 a file is created first and then update it with content when using dataprep, so there are more entries than previously + restActivityModelsCollection.assertThat().paginationField("count").is("3"); + restActivityModelsCollection.assertThat().entriesListDoesNotContain("postPersonId", userModel.getUsername().toLowerCase()) + .and().entriesListContains("postPersonId", adminUser.getUsername().toLowerCase()) + .and().entriesListContains("postPersonId", managerUser.getUsername().toLowerCase()); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/people/activities/GetPeopleActivitiesFullTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/activities/GetPeopleActivitiesFullTests.java new file mode 100644 index 0000000000..d15bec3a6d --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/activities/GetPeopleActivitiesFullTests.java @@ -0,0 +1,190 @@ +package org.alfresco.rest.people.activities; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestActivityModel; +import org.alfresco.rest.model.RestActivityModelsCollection; +import org.alfresco.rest.model.RestActivitySummaryModel; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.model.FileModel; +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.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * + * @author Cristina Axinte + * + */ +public class GetPeopleActivitiesFullTests extends RestTest +{ + UserModel userModel, adminUser, managerUser; + SiteModel siteModel1, siteModel2; + FileModel fileInSite1, fileInSite2; + FolderModel folderInSite2; + private RestActivityModelsCollection restActivityModelsCollection; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + userModel = dataUser.createRandomTestUser(); + siteModel1 = dataSite.usingUser(userModel).createPublicRandomSite(); + fileInSite1 = dataContent.usingUser(userModel).usingSite(siteModel1).createContent(DocumentType.TEXT_PLAIN); + + siteModel2 = dataSite.usingUser(userModel).createPublicRandomSite(); + folderInSite2 = dataContent.usingUser(userModel).usingSite(siteModel2).createFolder(); + fileInSite2 = dataContent.usingAdmin().usingSite(siteModel2).createContent(DocumentType.TEXT_PLAIN); + + managerUser = dataUser.createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(managerUser, siteModel2, UserRole.SiteManager); + + // only once the activity list is checked with retry in order not to wait the entire list in each test + // after repo-4250 a file is created first and then update it with content, so there are more entries than previously + restActivityModelsCollection = restClient.authenticateUser(userModel).withCoreAPI().usingMe().getPersonActivitiesUntilEntriesCountIs(6); + restClient.assertStatusCodeIs(HttpStatus.OK); + restActivityModelsCollection.assertThat().paginationField("count").is("6"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.ACTIVITIES }, executionType = ExecutionType.REGRESSION, description = "Verify activity summary from user gets activities response with Rest API") + public void userGetPeopleActivitiesWithActivitySummaryCheck() throws Exception + { + restActivityModelsCollection = restClient.authenticateUser(userModel).withCoreAPI().usingMe().usingParams(String.format("siteId=%s", siteModel1.getId())).getPersonActivities(); + restClient.assertStatusCodeIs(HttpStatus.OK); + // after repo-4250 a file is created first and then update it with content, so there are more entries than previously + restActivityModelsCollection.assertThat().paginationField("count").is("2"); + RestActivitySummaryModel summary = restActivityModelsCollection.getEntries().get(0).onModel().getActivitySummary(); + summary.assertThat().field("firstName").is(userModel.getUsername() + " FirstName") + .and().field("lastName").is("LN-" + userModel.getUsername()) + .and().field("title").is(fileInSite1.getName()) + .and().field("objectId").is(fileInSite1.getNodeRefWithoutVersion()); + } + + @Bug(id = "REPO-1911") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API,TestGroup.PEOPLE,TestGroup.ACTIVITIES }, executionType = ExecutionType.REGRESSION, description = "Verify user cannot get activities for empty user with Rest API and response is 400") + public void userCannotGetPeopleActivitiesForEmptyPersonId() throws Exception + { + UserModel emptyUserName = new UserModel("", "password"); + + restActivityModelsCollection = restClient.authenticateUser(userModel).withCoreAPI().usingUser(emptyUserName).getPersonActivities(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .containsSummary(RestErrorModel.LOCAL_NAME_CONSISTANCE) + .stackTraceIs(RestErrorModel.STACKTRACE) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API,TestGroup.PEOPLE,TestGroup.ACTIVITIES }, executionType = ExecutionType.REGRESSION, description = "Verify user gets its activities for siteId specified in siteId parameter using me with Rest API and response is successful") + public void userGetItsPeopleActivitiesForASpecificSite() throws Exception + { + restActivityModelsCollection = restClient.authenticateUser(userModel).withCoreAPI().usingUser(userModel).usingParams(String.format("siteId=%s", siteModel1.getId())).getPersonActivities(); + restClient.assertStatusCodeIs(HttpStatus.OK); + // after repo-4250 a file is created first and then update it with content, so there are more entries than previously + restActivityModelsCollection.assertThat().paginationField("count").is("2"); + restActivityModelsCollection.assertThat().entriesListContains("siteId", siteModel1.getId()) + .and().entriesListDoesNotContain("siteId", siteModel2.getId()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES }, executionType = ExecutionType.REGRESSION, description = "Verify user gets activities for user with no activities with Rest API and response is successful") + public void userGetPeopleActivitiesForUserWithNoActivities() throws Exception + { + UserModel userNoActivities = dataUser.createRandomTestUser(); + dataSite.usingUser(userNoActivities).createPublicRandomSite(); + + restActivityModelsCollection = restClient.authenticateUser(adminUser).withCoreAPI().usingUser(userNoActivities).getPersonActivities(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restActivityModelsCollection.assertThat().paginationField("count").is("0"); + restActivityModelsCollection.assertThat().entriesListIsEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES }, executionType = ExecutionType.REGRESSION, description = "Verify user cannot get activities for siteId that user doesn't have access to with Rest API and response is not found") + public void userGetPeopleActivitiesForASiteWithNoAccess() throws Exception + { + SiteModel siteNoAccess = dataSite.usingUser(managerUser).createPrivateRandomSite(); + + restActivityModelsCollection = restClient.authenticateUser(userModel).withCoreAPI().usingUser(userModel).usingParams(String.format("siteId=%s", siteNoAccess.getId())).getPersonActivities(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND); + restClient.assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, siteNoAccess.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES }, executionType = ExecutionType.REGRESSION, description = "Verify user cannot get activities for another user with Rest API and response is permission denied") + public void userGetPeopleActivitiesForAnotherUser() throws Exception + { + restActivityModelsCollection = restClient.authenticateUser(userModel).withCoreAPI().usingUser(managerUser).getPersonActivities(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN); + restClient.assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.ACTIVITIES }, executionType = ExecutionType.REGRESSION, description = "Verify user gets activities with properties parameter applied with Rest API and response is successful") + public void userGetPeopleActivitiesUsingPropertiesParameter() throws Exception + { + // after repo-4250 a file is created first and then update it with content, so there are more entries than previously + restActivityModelsCollection = restClient.authenticateUser(userModel).withCoreAPI().usingMe().usingParams("properties=postPersonId").getPersonActivities(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restActivityModelsCollection.assertThat().paginationField("count").is("6"); + restActivityModelsCollection.assertThat().entriesListContains("postPersonId", userModel.getUsername().toLowerCase()) + .and().entriesListContains("postPersonId", adminUser.getUsername().toLowerCase()) + .and().entriesListContains("postPersonId", managerUser.getUsername().toLowerCase()) + .and().entriesListDoesNotContain("postedAt") + .and().entriesListDoesNotContain("feedPersonId") + .and().entriesListDoesNotContain("siteId") + .and().entriesListDoesNotContain("activitySummary") + .and().entriesListDoesNotContain("id") + .and().entriesListDoesNotContain("activityType"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES }, executionType = ExecutionType.REGRESSION, description = "Verify user gets activities with skipCount parameter applied with Rest API and response is successful") + public void userGetPeopleActivitiesUsingSkipCountParameter() throws Exception + { + restActivityModelsCollection = restClient.authenticateUser(userModel).withCoreAPI().usingMe().getPersonActivities(); + restClient.assertStatusCodeIs(HttpStatus.OK); + // after repo-4250 a file is created first and then update it with content, so there are more entries than previously + restActivityModelsCollection.assertThat().paginationField("count").is("6"); + RestActivityModel expectedRestActivity3 = restActivityModelsCollection.getEntries().get(2).onModel(); + RestActivityModel expectedRestActivity4 = restActivityModelsCollection.getEntries().get(3).onModel(); + + restActivityModelsCollection = restClient.authenticateUser(userModel).withCoreAPI().usingMe().usingParams("skipCount=2").getPersonActivities(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restActivityModelsCollection.assertThat().paginationField("count").is("4"); + restActivityModelsCollection.getEntries().get(0).onModel().assertThat().field("postPersonId").is(expectedRestActivity3.getPostPersonId()) + .and().field("activityType").is(expectedRestActivity3.getActivityType()); + restActivityModelsCollection.getEntries().get(1).onModel().assertThat().field("postPersonId").is(expectedRestActivity4.getPostPersonId()) + .and().field("activityType").is(expectedRestActivity4.getActivityType()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES }, executionType = ExecutionType.REGRESSION, description = "Verify user gets activities with maxItems parameter applied with Rest API and response is successful") + public void userGetPeopleActivitiesUsingMaxItemsParameter() throws Exception + { + // after repo-4250 a file is created first and then update it with content, so there are more entries than previously + restActivityModelsCollection = restClient.authenticateUser(userModel).withCoreAPI().usingMe().getPersonActivities(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restActivityModelsCollection.assertThat().paginationField("count").is("6"); + RestActivityModel expectedRestActivity1 = restActivityModelsCollection.getEntries().get(0).onModel(); + RestActivityModel expectedRestActivity2 = restActivityModelsCollection.getEntries().get(1).onModel(); + + restActivityModelsCollection = restClient.authenticateUser(userModel).withCoreAPI().usingMe().usingParams("maxItems=2").getPersonActivities(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restActivityModelsCollection.assertThat().paginationField("count").is("2"); + restActivityModelsCollection.getEntries().get(0).onModel().assertThat().field("postPersonId").is(expectedRestActivity1.getPostPersonId()) + .and().field("activityType").is(expectedRestActivity1.getActivityType()); + restActivityModelsCollection.getEntries().get(1).onModel().assertThat().field("postPersonId").is(expectedRestActivity2.getPostPersonId()) + .and().field("activityType").is(expectedRestActivity2.getActivityType()); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/people/activities/GetPeopleActivitiesSanityTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/activities/GetPeopleActivitiesSanityTests.java new file mode 100644 index 0000000000..8183430764 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/activities/GetPeopleActivitiesSanityTests.java @@ -0,0 +1,108 @@ +package org.alfresco.rest.people.activities; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestActivityModelsCollection; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * @author Cristina Axinte + * Tests for getActivities (/people/{personId}/activities) RestAPI call + */ + +public class GetPeopleActivitiesSanityTests extends RestTest +{ + UserModel userModel, unauthenticatedUser; + SiteModel siteModel; + private DataUser.ListUserWithRoles usersWithRoles; + private RestActivityModelsCollection restActivityModelsCollection; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + userModel = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); + dataContent.usingUser(userModel).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, + UserRole.SiteContributor); + unauthenticatedUser = dataUser.usingAdmin().createRandomTestUser(); + unauthenticatedUser.setPassword("newpassword"); + + // only once the activity list is checked with retry in order not to wait the entire list in each test + restActivityModelsCollection = restClient.authenticateUser(userModel).withCoreAPI().usingAuthUser().getPersonActivitiesUntilEntriesCountIs(5); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API,TestGroup.PEOPLE, TestGroup.ACTIVITIES }, executionType = ExecutionType.SANITY, description = "Verify manager user gets its activities with Rest API and response is successful") + public void managerUserShouldGetPeopleActivitiesList() throws Exception + { + UserModel managerUser = usersWithRoles.getOneUserWithRole(UserRole.SiteManager); + dataContent.usingUser(managerUser).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + + restActivityModelsCollection = restClient.authenticateUser(managerUser).withCoreAPI().usingAuthUser().getPersonActivities(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restActivityModelsCollection.assertThat().entriesListIsNotEmpty().and().entriesListContains("siteId", siteModel.getId()).and().paginationExist(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API,TestGroup.PEOPLE, TestGroup.ACTIVITIES }, executionType = ExecutionType.SANITY, description = "Verify collaborator user gets its activities with Rest API and response is successful") + public void collaboratorUserShouldGetPeopleActivitiesList() throws Exception + { + UserModel collaboratorUser = usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator); + dataContent.usingUser(collaboratorUser).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + + restActivityModelsCollection = restClient.authenticateUser(collaboratorUser).withCoreAPI().usingAuthUser().getPersonActivities(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restActivityModelsCollection.assertThat().entriesListIsNotEmpty().and().entriesListContains("siteId", siteModel.getId()).and().paginationExist(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.ACTIVITIES }, executionType = ExecutionType.SANITY, description = "Verify contributor user gets its activities with Rest API and response is successful") + public void contributorUserShouldGetPeopleActivitiesList() throws Exception + { + UserModel contributorUser = usersWithRoles.getOneUserWithRole(UserRole.SiteContributor); + dataContent.usingUser(contributorUser).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + + restActivityModelsCollection = restClient.authenticateUser(contributorUser).withCoreAPI().usingAuthUser().getPersonActivities(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restActivityModelsCollection.assertThat().entriesListIsNotEmpty().and().entriesListContains("siteId", siteModel.getId()).and().paginationExist(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.ACTIVITIES }, executionType = ExecutionType.SANITY, description = "Verify consumer user gets its activities with Rest API and response is successful") + public void consumerUserShouldGetPeopleActivitiesList() throws Exception + { + UserModel consumerUser = usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer); + + restActivityModelsCollection = restClient.authenticateUser(consumerUser).withCoreAPI().usingAuthUser().getPersonActivities(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restActivityModelsCollection.assertThat().entriesListIsNotEmpty().and().entriesListContains("siteId", siteModel.getId()).and().paginationExist(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.ACTIVITIES }, executionType = ExecutionType.SANITY, description = "Verify admin user gets another user activities with Rest API and response is successful") + public void adminUserShouldGetPeopleActivitiesList() throws Exception + { + restActivityModelsCollection = restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingUser(userModel).getPersonActivities(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restActivityModelsCollection.assertThat().entriesListIsNotEmpty().and().entriesListContains("siteId", siteModel.getId()).and().paginationExist(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.ACTIVITIES }, executionType = ExecutionType.SANITY, description = "Verify unauthenticated user is NOT Authorized to gets another user activities with Rest API") + public void unauthenticatedUserShouldNotGetPeopleActivitiesList() throws Exception + { + restClient.authenticateUser(unauthenticatedUser).withCoreAPI().usingUser(userModel).getPersonActivities(); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/people/preferences/GetPeoplePreferenceCoreTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/preferences/GetPeoplePreferenceCoreTests.java new file mode 100644 index 0000000000..4e02b7025f --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/preferences/GetPeoplePreferenceCoreTests.java @@ -0,0 +1,78 @@ +package org.alfresco.rest.people.preferences; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.utility.constants.PreferenceName; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class GetPeoplePreferenceCoreTests extends RestTest +{ + UserModel userModel; + SiteModel siteModel; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + userModel = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); + dataSite.usingUser(userModel).usingSite(siteModel).addSiteToFavorites(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, description = "Verify user is Forbidden to get a specific preference for another user with Rest API and response is 403") + public void userDoesNotHaveAccessToFavoriteSitesOfAnotherUser() throws Exception + { + UserModel secondUser = dataUser.createRandomTestUser(); + restClient.authenticateUser(secondUser).withCoreAPI().usingUser(userModel) + .getPersonPreferenceInformation(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN); + restClient.assertLastError().containsSummary("Permission was denied"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, description = "Verify manager fails to get a specific preference for an invalid user with Rest API and response is 404") + public void statusNotFoundIsReturnedForAPersonIDThatDoesNotExist() throws Exception + { + restClient.authenticateUser(userModel).withCoreAPI().usingUser(new UserModel("invalidPersonID", "password")) + .getPersonPreferenceInformation(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "invalidPersonID")) + .statusCodeIs(HttpStatus.NOT_FOUND) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE) + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, description = "Verify manager fails to get a specific preference for an invalid preference with Rest API and response is 404") + public void statusNotFoundIsReturnedForAPreferenceNameThatDoesNotExist() throws Exception + { + restClient.authenticateUser(userModel).withCoreAPI().usingAuthUser().getPersonPreferenceInformation("invalidPreferenceName"); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND); + restClient.assertLastError().containsSummary( + String.format("The relationship resource was not found for the" + " entity with id: %s and a relationship id of invalidPreferenceName", + userModel.getUsername())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, description = "Verify manager fails to get a specific preference for removed preference with Rest API and response is 404") + public void statusNotFoundIsReturnedForAPreferenceNameThatHasBeenRemoved() throws Exception + { + SiteModel preferenceSite = dataSite.usingUser(userModel).createPublicRandomSite(); + dataSite.usingUser(userModel).usingSite(preferenceSite).addSiteToFavorites(); + dataSite.usingUser(userModel).usingSite(preferenceSite).removeSiteFromFavorites(); + restClient.authenticateUser(userModel).withCoreAPI().usingAuthUser() + .getPersonPreferenceInformation(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), preferenceSite.getId())); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND); + restClient.assertLastError().containsSummary( + String.format("The relationship resource was not found for the" + " entity with id: %s and a relationship id of %s", userModel.getUsername(), + String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), preferenceSite.getId()))); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/people/preferences/GetPeoplePreferenceFullTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/preferences/GetPeoplePreferenceFullTests.java new file mode 100644 index 0000000000..f0d7172220 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/preferences/GetPeoplePreferenceFullTests.java @@ -0,0 +1,189 @@ +package org.alfresco.rest.people.preferences; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestPreferenceModel; +import org.alfresco.utility.Utility; +import org.alfresco.utility.constants.PreferenceName; +import org.alfresco.utility.model.*; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.nio.file.Paths; + +public class GetPeoplePreferenceFullTests extends RestTest +{ + private UserModel userModel; + private SiteModel siteModel; + private RestPreferenceModel restPreferenceModel; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + userModel = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); + dataSite.usingUser(userModel).usingSite(siteModel).addSiteToFavorites(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, + description = "Check that properties parameter is applied") + public void propertiesParameterIsAppliedWhenRetrievingPreference() throws Exception + { + restPreferenceModel = restClient.authenticateUser(userModel).withParams("properties=id").withCoreAPI().usingUser(userModel) + .getPersonPreferenceInformation(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())); + restClient.assertStatusCodeIs(HttpStatus.OK); + restPreferenceModel.assertThat().field("id").is(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())) + .and().field("value").isNull(); + + restPreferenceModel = restClient.authenticateUser(userModel).withParams("properties=id,value").withCoreAPI().usingUser(userModel) + .getPersonPreferenceInformation(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())); + restClient.assertStatusCodeIs(HttpStatus.OK); + restPreferenceModel.assertThat().field("id").is(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())) + .and().field("value").is("true"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, + description = "Validate ID element in get site preference response") + public void validateIdElementInGetSitePreferenceResponse() throws Exception + { + restPreferenceModel = restClient.authenticateUser(userModel).withCoreAPI().usingAuthUser() + .getPersonPreferenceInformation(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())); + restPreferenceModel.assertThat().field("id").is(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())) + .and().field("value").is("true"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API,TestGroup.PEOPLE, TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, + description = "Validate ID element in get folder preference response") + public void validateIdElementInGetFolderPreferenceResponse() throws Exception + { + FolderModel folderFavorite = new FolderModel("favoriteFolder"); + folderFavorite = dataContent.usingSite(siteModel).createFolder(folderFavorite); + dataContent.getContentActions().setFolderAsFavorite(userModel.getUsername(), userModel.getPassword(), siteModel.getId(), folderFavorite.getName()); + + restPreferenceModel = restClient.authenticateUser(userModel).withCoreAPI().usingAuthUser() + .getPersonPreferenceInformation(PreferenceName.FOLDERS_FAVORITES_PREFIX.toString()); + restPreferenceModel.assertThat().field("id").is(PreferenceName.FOLDERS_FAVORITES_PREFIX) + .and().field("value").is(Utility.removeLastSlash(Utility.buildPath("workspace://SpacesStore", folderFavorite.getNodeRef()))); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API,TestGroup.PEOPLE, TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, + description = "Validate ID element in get file preference response") + public void validateIdElementInGetFilePreferenceResponse() throws Exception + { + FileModel fileFavorite = new FileModel("favoriteFile", FileType.TEXT_PLAIN); + fileFavorite = dataContent.usingUser(userModel).usingSite(siteModel).createContent(fileFavorite); + dataContent.getContentActions().setFileAsFavorite(userModel.getUsername(), userModel.getPassword(), siteModel.getId(), fileFavorite.getName()); + + restPreferenceModel = restClient.authenticateUser(userModel).withCoreAPI().usingAuthUser() + .getPersonPreferenceInformation(PreferenceName.DOCUMENTS_FAVORITES_PREFIX.toString()); + restPreferenceModel.assertThat().field("id").is(PreferenceName.DOCUMENTS_FAVORITES_PREFIX) + .and().field("value").is(Utility.removeLastSlash(Utility.buildPath("workspace://SpacesStore", fileFavorite.getNodeRefWithoutVersion()))); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, + description = "Get preference of an user that has no preferences") + public void getPreferenceForUserWithoutPreferences() throws Exception + { + UserModel newUser = dataUser.createRandomTestUser(); + + restPreferenceModel = restClient.authenticateUser(newUser).withCoreAPI().usingAuthUser() + .getPersonPreferenceInformation(PreferenceName.DOCUMENTS_FAVORITES_PREFIX.toString()); + restClient.assertLastError().containsSummary( + String.format("The relationship resource was not found for the" + " entity with id: %s and a relationship id of %s", newUser.getUsername(), + PreferenceName.DOCUMENTS_FAVORITES_PREFIX.toString())); + + restPreferenceModel = restClient.authenticateUser(newUser).withCoreAPI().usingAuthUser() + .getPersonPreferenceInformation(PreferenceName.FOLDERS_FAVORITES_PREFIX.toString()); + restClient.assertLastError().containsSummary( + String.format("The relationship resource was not found for the" + " entity with id: %s and a relationship id of %s", newUser.getUsername(), + PreferenceName.FOLDERS_FAVORITES_PREFIX.toString())); + + restPreferenceModel = restClient.authenticateUser(newUser).withCoreAPI().usingAuthUser() + .getPersonPreferenceInformation(PreferenceName.SITES_FAVORITES_PREFIX.toString()); + restClient.assertLastError().containsSummary( + String.format("The relationship resource was not found for the" + " entity with id: %s and a relationship id of %s", newUser.getUsername(), + PreferenceName.SITES_FAVORITES_PREFIX.toString())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, + description = "Change one preference for an user then perform get call") + @Bug(id = "REPO-1922") + public void changePreferenceThenPerformGetPreferenceCall() throws Exception + { + UserModel newUser = dataUser.createRandomTestUser(); + SiteModel site = dataSite.usingUser(newUser).createPublicRandomSite(); + + dataSite.usingUser(newUser).usingSite(site).addSiteToFavorites(); + + FileModel fileFavorite = new FileModel("favoriteFile", FileType.TEXT_PLAIN); + fileFavorite = dataContent.usingSite(site).createContent(fileFavorite); + dataContent.getContentActions().setFileAsFavorite(newUser.getUsername(), newUser.getPassword(), site.getId(), String.format("%s.%s", fileFavorite.getName(), fileFavorite.getFileType().extension)); + + FolderModel folderFavorite = new FolderModel("favoriteFolder"); + folderFavorite = dataContent.usingSite(site).createFolder(folderFavorite); + dataContent.getContentActions().setFolderAsFavorite(newUser.getUsername(), newUser.getPassword(), site.getId(), folderFavorite.getName()); + + dataSite.usingUser(newUser).usingSite(site).removeSiteFromFavorites(); + dataContent.getContentActions().removeFavorite(newUser.getUsername(), newUser.getPassword(), site.getId(), folderFavorite.getName()); + dataContent.getContentActions().removeFavorite(newUser.getUsername(), newUser.getPassword(), site.getId(), Paths.get(fileFavorite.getCmisLocation()).getFileName().toString()); + + restPreferenceModel = restClient.authenticateUser(newUser).withCoreAPI().usingAuthUser() + .getPersonPreferenceInformation(PreferenceName.FOLDERS_FAVORITES_PREFIX.toString()); + restClient.assertLastError().containsSummary( + String.format("The relationship resource was not found for the" + " entity with id: %s and a relationship id of %s", newUser.getUsername(), + PreferenceName.FOLDERS_FAVORITES_PREFIX.toString())); + + restPreferenceModel = restClient.authenticateUser(newUser).withCoreAPI().usingAuthUser() + .getPersonPreferenceInformation(PreferenceName.SITES_FAVORITES_PREFIX.toString()); + restClient.assertLastError().containsSummary( + String.format("The relationship resource was not found for the" + " entity with id: %s and a relationship id of %s", newUser.getUsername(), + PreferenceName.SITES_FAVORITES_PREFIX.toString())); + + restPreferenceModel = restClient.authenticateUser(newUser).withCoreAPI().usingAuthUser() + .getPersonPreferenceInformation(PreferenceName.DOCUMENTS_FAVORITES_PREFIX.toString()); + restClient.assertLastError().containsSummary( + String.format("The relationship resource was not found for the" + " entity with id: %s and a relationship id of %s", newUser.getUsername(), + PreferenceName.DOCUMENTS_FAVORITES_PREFIX.toString())); + + restPreferenceModel = restClient.authenticateUser(newUser).withCoreAPI().usingAuthUser() + .getPersonPreferenceInformation(PreferenceName.FOLDERS_FAVORITES_PREFIX.toString()); + restClient.assertLastError().containsSummary( + String.format("The relationship resource was not found for the" + " entity with id: %s and a relationship id of %s", newUser.getUsername(), + PreferenceName.FOLDERS_FAVORITES_PREFIX.toString())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, + description = "Verify admin is able to get preference of another user") + public void adminIsAbleToGetOtherUserPreference() throws Exception + { + restPreferenceModel = restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingUser(userModel) + .getPersonPreferenceInformation(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())); + restClient.assertStatusCodeIs(HttpStatus.OK); + restPreferenceModel.assertThat().field("id").is(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())).and().field("value").is("true"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, + description = "Verify regular user is not able to get preference of admin user") + public void regularUserIsNotAbleToGetAdminPreference() throws Exception + { + SiteModel newSite = dataSite.usingUser(dataUser.getAdminUser()).createPublicRandomSite(); + dataSite.usingUser(dataUser.getAdminUser()).usingSite(newSite).addSiteToFavorites(); + + restClient.authenticateUser(userModel).withCoreAPI().usingUser(dataUser.getAdminUser()) + .getPersonPreferenceInformation(PreferenceName.SITES_FAVORITES_PREFIX + newSite.getId()); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN); + restClient.assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } +} \ No newline at end of file diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/people/preferences/GetPeoplePreferenceSanityTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/preferences/GetPeoplePreferenceSanityTests.java new file mode 100644 index 0000000000..ccfd5f1cee --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/preferences/GetPeoplePreferenceSanityTests.java @@ -0,0 +1,119 @@ +package org.alfresco.rest.people.preferences; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestPreferenceModel; +import org.alfresco.utility.constants.PreferenceName; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Tests for Get a Peference (/people/{personId}/preferences/{preferenceName}) RestAPI call + * + * @author Cristina Axinte + */ + +public class GetPeoplePreferenceSanityTests extends RestTest +{ + UserModel userModel; + SiteModel siteModel; + private RestPreferenceModel restPreferenceModel; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + userModel = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.PREFERENCES }, executionType = ExecutionType.SANITY, description = "Verify manager user gets a specific preference with Rest API and response is successful (200)") + public void managerUserGetsAPreferenceWithSuccess() throws Exception + { + UserModel managerUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(managerUser, siteModel, UserRole.SiteManager); + dataSite.usingUser(managerUser).usingSite(siteModel).addSiteToFavorites(); + + restPreferenceModel = restClient.authenticateUser(managerUser).withCoreAPI().usingAuthUser() + .getPersonPreferenceInformation(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())); + restClient.assertStatusCodeIs(HttpStatus.OK); + restPreferenceModel.assertThat().field("id").is(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())).and().field("value").is("true"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.PREFERENCES }, executionType = ExecutionType.SANITY, description = "Verify collaborator user gets a specific preference with Rest API and response is successful (200)") + public void collaboratorUserGetsAPreferenceWithSuccess() throws Exception + { + UserModel collaboratorUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(collaboratorUser, siteModel, UserRole.SiteCollaborator); + dataSite.usingUser(collaboratorUser).usingSite(siteModel).addSiteToFavorites(); + + restPreferenceModel = restClient.authenticateUser(collaboratorUser).withCoreAPI().usingAuthUser() + .getPersonPreferenceInformation(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())); + restClient.assertStatusCodeIs(HttpStatus.OK); + restPreferenceModel.assertThat().field("id").is(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())).and().field("value").is("true"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.PREFERENCES }, executionType = ExecutionType.SANITY, description = "Verify contributor user gets a specific preference with Rest API and response is successful (200)") + public void contributorUserGetsAPreferenceWithSuccess() throws Exception + { + UserModel contributorUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(contributorUser, siteModel, UserRole.SiteContributor); + dataSite.usingUser(contributorUser).usingSite(siteModel).addSiteToFavorites(); + + restPreferenceModel = restClient.authenticateUser(contributorUser).withCoreAPI().usingAuthUser() + .getPersonPreferenceInformation(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())); + restClient.assertStatusCodeIs(HttpStatus.OK); + restPreferenceModel.assertThat().field("id").is(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())).and().field("value").is("true"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API,TestGroup.PEOPLE, TestGroup.PREFERENCES }, executionType = ExecutionType.SANITY, description = "Verify consumer user gets a specific preference with Rest API and response is successful (200)") + public void consumerUserGetsAPreferenceWithSuccess() throws Exception + { + UserModel consumerUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(consumerUser, siteModel, UserRole.SiteConsumer); + dataSite.usingUser(consumerUser).usingSite(siteModel).addSiteToFavorites(); + + restPreferenceModel = restClient.authenticateUser(consumerUser).withCoreAPI().usingAuthUser() + .getPersonPreferenceInformation(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(),siteModel.getId())); + restClient.assertStatusCodeIs(HttpStatus.OK); + restPreferenceModel.assertThat().field("id").is(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(),siteModel.getId())).and().field("value").is("true"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.PREFERENCES }, executionType = ExecutionType.SANITY, description = "Verify admin user gets a specific preference with Rest API and response is successful (200)") + public void adminUserGetsAPreferenceWithSuccess() throws Exception + { + UserModel adminUser = dataUser.getAdminUser(); + dataSite.usingUser(adminUser).usingSite(siteModel).addSiteToFavorites(); + + restPreferenceModel = restClient.authenticateUser(adminUser).withCoreAPI().usingAuthUser() + .getPersonPreferenceInformation(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())); + restClient.assertStatusCodeIs(HttpStatus.OK); + restPreferenceModel.assertThat().field("id").is(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())).and().field("value").is("true"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.PREFERENCES }, executionType = ExecutionType.SANITY, description = "Verify manager user is NOT Authorized to get a specific preference with Rest API when authentication fails (401)") +// @Bug(id = "MNT-16904", description = "fails only on environment with tenants") + public void managerUserNotAuthorizedFailsToGetsAPreference() throws Exception + { + UserModel managerUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(managerUser, siteModel, UserRole.SiteManager); + dataSite.usingUser(managerUser).usingSite(siteModel).addSiteToFavorites(); + managerUser.setPassword("newpassword"); + + restClient.authenticateUser(managerUser).withCoreAPI().usingAuthUser() + .getPersonPreferenceInformation(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/people/preferences/GetPeoplePreferencesCoreTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/preferences/GetPeoplePreferencesCoreTests.java new file mode 100644 index 0000000000..f4b42e8c7f --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/preferences/GetPeoplePreferencesCoreTests.java @@ -0,0 +1,123 @@ +package org.alfresco.rest.people.preferences; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestPreferenceModelsCollection; +import org.alfresco.utility.constants.PreferenceName; +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.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * + * @author Cristina Axinte + * + */ +public class GetPeoplePreferencesCoreTests extends RestTest +{ + UserModel userModel, user1, user2, adminUser; + SiteModel siteModel; + FolderModel folderModel; + private RestPreferenceModelsCollection restPreferenceModelsCollection; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + userModel = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); + folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + + user1 = dataUser.createRandomTestUser(); + dataSite.usingUser(user1).usingSite(siteModel).addSiteToFavorites(); + dataContent.usingUser(user1).usingSite(siteModel).addFolderToFavorites(folderModel); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API,TestGroup.PEOPLE, TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, description = "Verify user gets its preferences with invalid maxItems parameter with Rest API and response is 400") + public void userGetsPeoplePreferencesUsingInvalidMaxItemsParameter() throws Exception + { + restPreferenceModelsCollection = restClient.authenticateUser(user1).withCoreAPI().usingMe().usingParams("maxItems=0").getPersonPreferences(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsErrorKey(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS) + .containsSummary(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS) + .stackTraceIs(RestErrorModel.STACKTRACE) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, description = "Verify user gets its preferences with skipCount parameter applied with Rest API and response is successful") + public void userGetsPeoplePreferencesUsingInvalidSkipCountParameter() throws Exception + { + restPreferenceModelsCollection = restClient.authenticateUser(user1).withCoreAPI().usingMe().usingParams("skipCount=-1").getPersonPreferences(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsErrorKey(RestErrorModel.NEGATIVE_VALUES_SKIPCOUNT) + .containsSummary(RestErrorModel.NEGATIVE_VALUES_SKIPCOUNT) + .stackTraceIs(RestErrorModel.STACKTRACE) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API,TestGroup.PEOPLE, TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, description = "Verify user which doesn't have access to another user preferences fails to get its preferences with Rest API and response is permission denied") + public void userWithNoAccessToOtherUserPreferencesIsForbiddenToGetItsPreferences() throws Exception + { + UserModel noAccessUser = dataUser.createRandomTestUser(); + dataSite.usingUser(noAccessUser).usingSite(siteModel).addSiteToFavorites(); + + restPreferenceModelsCollection = restClient.authenticateUser(user1).withCoreAPI().usingUser(noAccessUser).getPersonPreferences(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN); + restClient.assertLastError().containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY) + .containsSummary(RestErrorModel.PERMISSION_WAS_DENIED) + .stackTraceIs(RestErrorModel.STACKTRACE) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API,TestGroup.PEOPLE, TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, description = "Verify user fails to get preferences for inexistent personId with Rest API and response is 404") + public void userCannotGetPeoplePreferencesForInexistentPersonId() throws Exception + { + UserModel inexistentUserName = new UserModel("inexistent", "password"); + + restPreferenceModelsCollection = restClient.authenticateUser(user1).withCoreAPI().usingUser(inexistentUserName).getPersonPreferences(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND); + restClient.assertLastError().containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, inexistentUserName.getUsername())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, description = "Verify user get preferences for a user with no preferences with Rest API and response is empty") + public void userGetsPeoplePreferencesForUserWithNoPreferences() throws Exception + { + UserModel userNoActivities = dataUser.createRandomTestUser(); + + restPreferenceModelsCollection = restClient.authenticateUser(adminUser).withCoreAPI().usingUser(userNoActivities).getPersonPreferences(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restPreferenceModelsCollection.assertThat().paginationField("count").is("0"); + restPreferenceModelsCollection.assertThat().entriesListIsEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API,TestGroup.PEOPLE, TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, description = "Verify user fails to get preferences for a removed preference with Rest API and response is 404") + public void userFailsToGetPeoplePreferencesIfPreferenceWasRemoved() throws Exception + { + SiteModel preferenceSite = dataSite.usingUser(user1).createPublicRandomSite(); + dataSite.usingUser(user1).usingSite(preferenceSite).addSiteToFavorites(); + restPreferenceModelsCollection = restClient.authenticateUser(user1).withCoreAPI().usingAuthUser().getPersonPreferences(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restPreferenceModelsCollection.assertThat().paginationField("count").is("6"); + + dataSite.usingUser(user1).usingSite(preferenceSite).removeSiteFromFavorites(); + restPreferenceModelsCollection = restClient.authenticateUser(user1).withCoreAPI().usingAuthUser().getPersonPreferences(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restPreferenceModelsCollection.assertThat().paginationField("count").is("5"); + restPreferenceModelsCollection.assertThat().entriesListDoesNotContain("id", String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), preferenceSite.getId())); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/people/preferences/GetPeoplePreferencesFullTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/preferences/GetPeoplePreferencesFullTests.java new file mode 100644 index 0000000000..28de256d3a --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/preferences/GetPeoplePreferencesFullTests.java @@ -0,0 +1,114 @@ +package org.alfresco.rest.people.preferences; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestPreferenceModelsCollection; +import org.alfresco.utility.constants.PreferenceName; +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.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * + * @author Cristina Axinte + * + */ +public class GetPeoplePreferencesFullTests extends RestTest +{ + UserModel userModel, user1, user2, adminUser; + SiteModel siteModel; + FolderModel folderModel; + private RestPreferenceModelsCollection restPreferenceModelsCollection; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + userModel = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); + folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + + user1 = dataUser.createRandomTestUser(); + dataSite.usingUser(user1).usingSite(siteModel).addSiteToFavorites(); + dataContent.usingUser(user1).usingSite(siteModel).addFolderToFavorites(folderModel); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, description = "Verify user gets its preferences with skipCount parameter applied with Rest API and response is successful") + public void userGetsItsPeoplePreferencesUsingSkipCountParameter() throws Exception + { + restPreferenceModelsCollection = restClient.authenticateUser(user1).withCoreAPI().usingMe().usingParams("skipCount=2").getPersonPreferences(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restPreferenceModelsCollection.assertThat().paginationField("count").is("2"); + restPreferenceModelsCollection.assertThat().paginationField("skipCount").is("2"); + restPreferenceModelsCollection.assertThat().entriesListIsNotEmpty() + .and().entriesListDoesNotContain("id", String.format(PreferenceName.EXT_FOLDERS_FAVORITES_PREFIX.toString(), "workspace://SpacesStore/" + folderModel.getNodeRef())) + .and().entriesListDoesNotContain("id", String.format(PreferenceName.EXT_SITES_FAVORITES_PREFIX.toString(), siteModel.getId())) + .and().entriesListContains("id", PreferenceName.FOLDERS_FAVORITES_PREFIX.toString()) + .and().entriesListContains("value", "workspace://SpacesStore/" + folderModel.getNodeRef()) + .and().entriesListContains("id", String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())) + .and().entriesListContains("value", "true"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API,TestGroup.PEOPLE, TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, description = "Verify user gets its preferences with maxItems parameter applied with Rest API and response is successful") + public void userGetsItsPeoplePreferencesUsingMaxItemsParameter() throws Exception + { + restPreferenceModelsCollection = restClient.authenticateUser(user1).withCoreAPI().usingMe().usingParams("maxItems=1").getPersonPreferences(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restPreferenceModelsCollection.assertThat().paginationField("count").is("1"); + restPreferenceModelsCollection.assertThat().paginationField("maxItems").is("1"); + restPreferenceModelsCollection.assertThat().entriesListIsNotEmpty() + .and().entriesListContains("id", String.format(PreferenceName.EXT_FOLDERS_FAVORITES_PREFIX.toString(), "workspace://SpacesStore/" + folderModel.getNodeRef())) + .and().entriesListDoesNotContain("id", String.format(PreferenceName.EXT_SITES_FAVORITES_PREFIX.toString(), siteModel.getId())) + .and().entriesListDoesNotContain("id", PreferenceName.FOLDERS_FAVORITES_PREFIX.toString()) + .and().entriesListDoesNotContain("value", "workspace://SpacesStore/" + folderModel.getNodeRef()) + .and().entriesListDoesNotContain("id", String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())) + .and().entriesListDoesNotContain("value", "true"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API,TestGroup.PEOPLE,TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, description = "Verify user gets admin preferences with Rest API and response is permission denied") + public void userIsForbiddenToGetAdminPreferences() throws Exception + { + restPreferenceModelsCollection = restClient.authenticateUser(user1).withCoreAPI().usingUser(adminUser).getPersonPreferences(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN); + restClient.assertLastError().containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY) + .containsSummary(RestErrorModel.PERMISSION_WAS_DENIED) + .stackTraceIs(RestErrorModel.STACKTRACE) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, description = "Verify user gets its preferences with skipCount parameter higher then no of entries with Rest API and response is empty") + public void userGetsItsPeoplePreferencesUsingHighSkipCount() throws Exception + { + restPreferenceModelsCollection = restClient.authenticateUser(user1).withCoreAPI().usingMe().usingParams("skipCount=100").getPersonPreferences(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restPreferenceModelsCollection.assertThat().paginationField("count").is("0"); + restPreferenceModelsCollection.assertThat().paginationField("skipCount").is("100"); + restPreferenceModelsCollection.assertThat().entriesListIsEmpty(); + } + + @Bug(id = "REPO-1911") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, description = "Verify user cannot get preferences for empty user with Rest API and response is 400") + public void userGetsItsPeoplePreferencesForEmptyPersonId() throws Exception + { + UserModel emptyUserName = new UserModel("", "password"); + + restPreferenceModelsCollection = restClient.authenticateUser(user1).withCoreAPI().usingUser(emptyUserName).getPersonPreferences(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .containsSummary(RestErrorModel.LOCAL_NAME_CONSISTANCE) + .stackTraceIs(RestErrorModel.STACKTRACE) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/people/preferences/GetPeoplePreferencesSanityTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/preferences/GetPeoplePreferencesSanityTests.java new file mode 100644 index 0000000000..9da2a3925c --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/people/preferences/GetPeoplePreferencesSanityTests.java @@ -0,0 +1,120 @@ +package org.alfresco.rest.people.preferences; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestPreferenceModelsCollection; +import org.alfresco.utility.constants.PreferenceName; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Tests for Get Peferences (/people/{personId}/preferences) RestAPI call + * + * @author Cristina Axinte + */ + +public class GetPeoplePreferencesSanityTests extends RestTest +{ + UserModel userModel; + SiteModel siteModel; + private RestPreferenceModelsCollection restPreferenceModelsCollection; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + userModel = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.PREFERENCES }, executionType = ExecutionType.SANITY, description = "Verify manager user gets its preferences with Rest API and response is successful (200)") + public void managerUserGetsPeoplePreferencesWithSuccess() throws Exception + { + UserModel managerUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(managerUser, siteModel, UserRole.SiteManager); + dataSite.usingUser(managerUser).usingSite(siteModel).addSiteToFavorites(); + + restPreferenceModelsCollection = restClient.authenticateUser(managerUser).withCoreAPI().usingAuthUser().getPersonPreferences(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restPreferenceModelsCollection.assertThat().entriesListIsNotEmpty().assertThat().paginationExist().and() + .entriesListContains("id", String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API,TestGroup.PEOPLE, TestGroup.PREFERENCES }, executionType = ExecutionType.SANITY, description = "Verify collaborator user gets its preferences with Rest API and response is successful (200)") + public void collaboratorUserGetsPeoplePreferencesWithSuccess() throws Exception + { + UserModel collaboratorUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(collaboratorUser, siteModel, UserRole.SiteCollaborator); + dataSite.usingUser(collaboratorUser).usingSite(siteModel).addSiteToFavorites(); + + restPreferenceModelsCollection = restClient.authenticateUser(collaboratorUser).withCoreAPI().usingAuthUser().getPersonPreferences(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restPreferenceModelsCollection.assertThat().entriesListIsNotEmpty().assertThat().paginationExist().and() + .entriesListContains("id", String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.PREFERENCES }, executionType = ExecutionType.SANITY, description = "Verify contributor user gets its preferences with Rest API and response is successful (200)") + public void contributorUserGetsPeoplePreferencesWithSuccess() throws Exception + { + UserModel contributorUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(contributorUser, siteModel, UserRole.SiteContributor); + dataSite.usingUser(contributorUser).usingSite(siteModel).addSiteToFavorites(); + + restPreferenceModelsCollection = restClient.authenticateUser(contributorUser).withCoreAPI().usingAuthUser().getPersonPreferences(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restPreferenceModelsCollection.assertThat().entriesListIsNotEmpty().assertThat().paginationExist().and() + .entriesListContains("id", String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API,TestGroup.PEOPLE, TestGroup.PREFERENCES }, executionType = ExecutionType.SANITY, description = "Verify consumer user gets its preferences with Rest API and response is successful (200)") + public void consumerUserGetsPeoplePreferencesWithSuccess() throws Exception + { + UserModel consumerUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(consumerUser, siteModel, UserRole.SiteConsumer); + dataSite.usingUser(consumerUser).usingSite(siteModel).addSiteToFavorites(); + + restPreferenceModelsCollection = restClient.authenticateUser(consumerUser).withCoreAPI().usingAuthUser().getPersonPreferences(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restPreferenceModelsCollection.assertThat().entriesListIsNotEmpty().assertThat().paginationExist().and() + .entriesListContains("id", String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.PREFERENCES }, executionType = ExecutionType.SANITY, description = "Verify admin user gets another user preferences with Rest API and response is successful (200)") + public void adminUserGetsPeoplePreferencesWithSuccess() throws Exception + { + UserModel managerUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(managerUser, siteModel, UserRole.SiteManager); + dataSite.usingUser(managerUser).usingSite(siteModel).addSiteToFavorites(); + UserModel adminUser = dataUser.getAdminUser(); + + restPreferenceModelsCollection = restClient.authenticateUser(adminUser).withCoreAPI().usingUser(managerUser).getPersonPreferences(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restPreferenceModelsCollection.assertThat().entriesListIsNotEmpty().assertThat().paginationExist().and() + .entriesListContains("id", String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.PREFERENCES }, executionType = ExecutionType.SANITY, description = "Verify manager user is NOT Authorized to gets its preferences with Rest API when authentication fails(401)") +// @Bug(id = "MNT-16904", description = "It fails only on environment with tenants") + public void managerUserGetsPeoplePreferencesIsNotAuthorized() throws Exception + { + UserModel managerUser = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(managerUser, siteModel, UserRole.SiteManager); + dataSite.usingUser(managerUser).usingSite(siteModel).addSiteToFavorites(); + managerUser.setPassword("newpassword"); + + restClient.authenticateUser(managerUser).withCoreAPI().usingAuthUser().getPersonPreferences(); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/queries/QueriesTest.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/queries/QueriesTest.java new file mode 100644 index 0000000000..09be1b82ca --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/queries/QueriesTest.java @@ -0,0 +1,180 @@ +package org.alfresco.rest.queries; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestNodeModelsCollection; +import org.alfresco.rest.model.RestPersonModelsCollection; +import org.alfresco.rest.model.RestSiteModel; +import org.alfresco.rest.model.RestSiteModelsCollection; +import org.alfresco.utility.RetryOperation; +import org.alfresco.utility.Utility; +import org.alfresco.utility.model.ContentModel; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +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.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.Test; + + +/** + * Handle requests on Queries + * + */ +public class QueriesTest extends RestTest +{ + @TestRail(section = { TestGroup.REST_API, + TestGroup.QUERIES }, executionType = ExecutionType.SANITY, description = "Check basic functionality of GET queries/sites") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE }) + public void getQueriesSites() throws Exception + { + restClient.authenticateUser(dataContent.getAdminUser()).withCoreAPI().usingQueries().findSites(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST); + restClient.assertLastError().containsErrorKey("Query 'term' not specified") + // and assert on summary too if you want + .containsSummary("Query 'term' not specified"); + + restClient.withCoreAPI().usingQueries().usingParams("term=b").findSites(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST); + restClient.assertLastError().containsErrorKey("Query 'term' is too short"); + + SiteModel site = RestSiteModel.getRandomSiteModel(); + RestSiteModel createdSite = restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingSite(site).createSite(); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + RetryOperation op = new RetryOperation() + { + public void execute() throws Exception + { + RestSiteModelsCollection restSiteModels = restClient.withCoreAPI().usingQueries().usingParams("term=" + createdSite.getTitle()) + .findSites(); + + assertEquals(restSiteModels.getEntries().size(), 1); + + } + }; + + Utility.sleep(300, 100000, op);// Allow indexing to complete. + + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.QUERIES }, executionType = ExecutionType.SANITY, description = "Check basic functionality of GET queries/people") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE }) + public void getQueriesPeople() throws Exception + { + restClient.authenticateUser(dataContent.getAdminUser()).withCoreAPI().usingQueries().findPeople(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST); + restClient.assertLastError().containsErrorKey("Query 'term' not specified") + // and assert on summary too if you want + .containsSummary("Query 'term' not specified"); + + restClient.withCoreAPI().usingQueries().usingParams("term=b").findPeople(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST); + restClient.assertLastError().containsErrorKey("Query 'term' is too short"); + + UserModel userModel = dataUser.createRandomTestUser(); + RetryOperation op = new RetryOperation() + { + public void execute() throws Exception + { + RestPersonModelsCollection restPersonModels = restClient.withCoreAPI().usingQueries().usingParams("term=" + userModel.getUsername()) + .findPeople(); + + assertEquals(restPersonModels.getEntries().size(), 1); + + } + }; + + Utility.sleep(300, 100000, op);// Allow indexing to complete. + + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.QUERIES }, + executionType = ExecutionType.REGRESSION, description = "Check basic functionality of GET queries/nodes") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void getOnQueriesNodesRoute() throws Exception + { + restClient.authenticateUser(dataContent.getAdminUser()) + .withCoreAPI() + .usingQueries().findNodes(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST); + + restClient.assertLastError() + .containsErrorKey("Query 'term' not specified") + //and assert on summary too if you want + .containsSummary("Query 'term' not specified"); + + restClient.withCoreAPI() + .usingQueries() + .usingParams("term=ab") + .findNodes(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST); + + restClient.assertLastError() + .containsErrorKey("Query 'term' is too short"); + + /* + * now making the correct call with a valid term value + */ + restClient.withCoreAPI().usingQueries().usingParams("term=name").findNodes(); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Bug(id="REPO-4784") + @TestRail(section = { TestGroup.REST_API, + TestGroup.QUERIES }, executionType = ExecutionType.REGRESSION, description = "Verify GET queries on queries/nodes return success status code") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE }) + public void testSearchTermWhiteSpace() throws Exception + { + + UserModel userModel = dataUser.createRandomTestUser(); + SiteModel siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); + /* + * Create the following file structure for preconditions : + * |- folder + * |--find123.txt + * |-- find123 find.txt + */ + restClient.authenticateUser(userModel).withCoreAPI().usingNode(ContentModel.my()).defineNodes(); + FolderModel folder = new FolderModel("folder" + Math.random()); + + // I use "find123" and "find123 find", the search using second term must + // return less result + // The space must not break the query + String childTerm = "find" + Math.random(); + String childTermWS = childTerm + " " + "find"; + + dataContent.usingUser(userModel).usingSite(siteModel).createFolder(folder); + FileModel file1 = new FileModel(childTerm + ".txt", FileType.TEXT_PLAIN, childTerm); + FileModel file2 = new FileModel(childTermWS + ".txt", FileType.TEXT_PLAIN, childTermWS); + ContentModel cm = new ContentModel(); + cm.setCmisLocation(folder.getCmisLocation()); + cm.setName(folder.getName()); + dataContent.usingUser(userModel).usingSite(siteModel).usingResource(cm).createContent(file1); + dataContent.usingUser(userModel).usingSite(siteModel).usingResource(cm).createContent(file2); + + RetryOperation op = new RetryOperation(){ + public void execute() throws Exception{ + RestNodeModelsCollection nodesChildTerm = restClient.withCoreAPI().usingQueries().usingParams("term=" + childTerm).findNodes(); + // check if the search returns all nodes which contain that query term + assertEquals(2, nodesChildTerm.getEntries().size()); + RestNodeModelsCollection nodesChildTermWS = restClient.withCoreAPI().usingQueries().usingParams("term=" + childTermWS).findNodes(); + // check if search works for words with space and the space don't break + // the query + assertEquals(1, nodesChildTermWS.getEntries().size()); + assertTrue(nodesChildTerm.getEntries().size() >= nodesChildTermWS.getEntries().size()); + } + + }; + Utility.sleep(300, 100000, op);// Allow indexing to complete. + + } +} \ No newline at end of file diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/ratings/AddRatingTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/ratings/AddRatingTests.java new file mode 100644 index 0000000000..c64edc579d --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/ratings/AddRatingTests.java @@ -0,0 +1,816 @@ +package org.alfresco.rest.ratings; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestCommentModel; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestRatingModel; +import org.alfresco.rest.model.RestTagModel; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; +import org.alfresco.utility.exception.DataPreparationException; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FolderModel; +import org.alfresco.utility.model.LinkModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.commons.lang3.RandomStringUtils; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + + +public class AddRatingTests extends RestTest +{ + private UserModel userModel; + private SiteModel siteModel; + private UserModel adminUser; + private ListUserWithRoles usersWithRoles; + private RestRatingModel returnedRatingModel; // placeholder for returned model + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws DataPreparationException + { + userModel = dataUser.createRandomTestUser(); + adminUser = dataUser.getAdminUser(); + siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); + + usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, + UserRole.SiteContributor); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.SANITY, description = "Verify user with Manager role is able to post like rating to a document") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY }) + public void managerIsAbleToLikeDocument() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(document) + .likeDocument(); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + returnedRatingModel.assertThat().field("myRating").is("true").and().field("id").is("likes").and().field("aggregate").isNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Verify user with Collaborator role is able to post like rating to a document") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void collaboratorIsAbleToLikeDocument() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingResource(document) + .likeDocument(); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + returnedRatingModel.assertThat().field("myRating").is("true").and().field("id").is("likes").and().field("aggregate").isNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Verify user with Contributor role is able to post like rating to a document") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void contributorIsAbleToLikeDocument() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).withCoreAPI().usingResource(document) + .likeDocument(); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + returnedRatingModel.assertThat().field("myRating").is("true").and().field("id").is("likes").and().field("aggregate").isNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Verify user with Consumer role is able to post like rating to a document") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void consumerIsAbleToLikeDocument() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI().usingResource(document) + .likeDocument(); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + returnedRatingModel.assertThat().field("myRating").is("true").and().field("id").is("likes").and().field("aggregate").isNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Verify admin user is able to post like rating to a document") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void adminIsAbleToLikeDocument() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + returnedRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).likeDocument(); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + returnedRatingModel.assertThat().field("myRating").is("true").and().field("id").is("likes").and().field("aggregate").isNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.SANITY, description = "Verify unauthenticated user is not able to post like rating to a document") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY }) +// @Bug(id="MNT-16904", description = "It fails only on environment with tenants") + public void unauthenticatedUserIsNotAbleToLikeDocument() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(new UserModel("random user", "random password")).withCoreAPI().usingResource(document).likeDocument(); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.SANITY, description = "Verify user with Manager role is able to post stars rating to a document") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY }) + public void managerIsAbleToAddStarsToDocument() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(document) + .rateStarsToDocument(5); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Verify user with Collaborator role is able to post stars rating to a document") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void collaboratorIsAbleToAddStarsToDocument() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingResource(document) + .rateStarsToDocument(5); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty(); + + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Verify user with Contributor role is able to post stars rating to a document") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void contributorIsAbleToAddStarsToDocument() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).withCoreAPI().usingResource(document) + .rateStarsToDocument(5); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Verify user with Consumer role is able to post stars rating to a document") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void consumerIsAbleToAddStarsToDocument() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI().usingResource(document) + .rateStarsToDocument(5); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.REGRESSION }, + executionType = ExecutionType.SANITY, description = "Verify admin user is able to post stars rating to a document") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void adminIsAbleToAddStarsToDocument() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + returnedRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).rateStarsToDocument(3); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + returnedRatingModel.assertThat().field("myRating").is("3").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.SANITY, description = "Verify unauthenticated user is not able to post stars rating to a document") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY }) +// @Bug(id="MNT-16904", description = "fails only on environment with tenants") + public void unauthenticatedUserIsNotAbleToRateStarsToDocument() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(new UserModel("random user", "random password")).withCoreAPI().usingResource(document).rateStarsToDocument(5); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Verify that if unknown rating scheme is provided status code is 400") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void unknownRatingSchemeReturnsBadRequest() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"id\":\"invalidRate\"}"); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsSummary(String.format(RestErrorModel.INVALID_RATING, "invalidRate")) + .containsErrorKey(String.format(RestErrorModel.INVALID_RATING, "invalidRate")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Verify that if nodeId does not exist status code 404 is returned") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void invalidNodeIdReturnsNotFound() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + document.setNodeRef(RandomStringUtils.randomAlphanumeric(10)); + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).likeDocument(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, document.getNodeRef())) + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Verify that if nodeId provided cannot be rated 405 status code is returned") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void likeResourceThatCannotBeRated() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + LinkModel link = dataLink.usingAdmin().usingSite(siteModel).createRandomLink(); + document.setNodeRef(link.getNodeRef().replace("workspace://SpacesStore/", "workspace%3A%2F%2FSpacesStore%2F")); + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).likeDocument(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, document.getNodeRef())) + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.SANITY, description = "Verify that manager is able to like a folder") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY }) + public void managerIsAbleToLikeAFolder() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + + returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(folderModel) + .likeDocument(); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + returnedRatingModel.assertThat().field("myRating").is("true").and().field("id").is("likes").and().field("aggregate").isNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.SANITY, description = "Verify that manager is able to like a site") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY }) + public void managerIsAbleToLikeASite() throws Exception + { + FolderModel folderModel = new FolderModel(); + folderModel.setNodeRef(siteModel.getGuid()); + + returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(folderModel) + .likeDocument(); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + returnedRatingModel.assertThat().field("myRating").is("true").and().field("id").is("likes").and().field("aggregate").isNotEmpty(); + + restClient.withCoreAPI().usingResource(folderModel).getRatings() + .assertNodeIsLiked(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.SANITY, description = "Verify that manager is able to rate a folder") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY }) + public void managerIsAbleToRateAFolder() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(folderModel) + .rateStarsToDocument(5); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.SANITY }, + executionType = ExecutionType.REGRESSION, description = "Verify that manager is able to rate a site") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY }) + public void managerIsAbleToRateASite() throws Exception + { + FolderModel folderModel = new FolderModel(); + folderModel.setNodeRef(siteModel.getGuid()); + returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(folderModel) + .rateStarsToDocument(5); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty(); + + restClient.withCoreAPI().usingResource(folderModel).getRatings() + .assertNodeHasFiveStarRating(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Verify that adding like again has no effect on a file") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void fileCanBeLikedTwice() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).likeDocument(); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + returnedRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).likeDocument(); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + returnedRatingModel.assertThat().field("myRating").is("true").and().field("id").is("likes").and().field("aggregate").isNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Verify that adding rate again has no effect on a file") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void fileCanBeRatedTwice() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).rateStarsToDocument(5); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + returnedRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).rateStarsToDocument(5); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Verify that rate is not added if empty rating object is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void addRateUsingEmptyRatingObject() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating(""); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(String.format(RestErrorModel.NO_CONTENT, "No content to map due to end-of-input")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Verify that if empty rate id is provided status code is 400") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void addRateUsingEmptyValueForId() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"id\":\"\"}"); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + // The message is shortened for comparison as there is a Java object id in the message (random) + .containsSummary(String.format(RestErrorModel.NO_CONTENT, "N/A")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Verify that if empty rating is provided status code is 400") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void addRateUsingEmptyValueForMyRating() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"id\":\"likes\", \"myRating\":\"\"}"); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(String.format(RestErrorModel.NULL_LIKE_RATING)); + + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"id\":\"fiveStar\", \"myRating\":\"\"}"); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(String.format(RestErrorModel.NULL_FIVESTAR_RATING)); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Verify that user is not able to rate a comment") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void addRatingToAComment() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + RestCommentModel comment = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addComment("This is a comment"); + document.setNodeRef(comment.getId()); + + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).likeDocument(); + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED) + .assertLastError() + .containsSummary(String.format(RestErrorModel.CANNOT_RATE)) + .containsErrorKey(RestErrorModel.CANNOT_RATE) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).rateStarsToDocument(5); + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED).assertLastError().containsSummary(String.format(RestErrorModel.CANNOT_RATE)); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Verify that user is not able to rate a tag") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void addRatingToATag() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + RestTagModel tag = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addTag("randomTag"); + document.setNodeRef(tag.getId()); + + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).likeDocument(); + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED).assertLastError().containsSummary(String.format(RestErrorModel.CANNOT_RATE)); + + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).rateStarsToDocument(5); + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED).assertLastError().containsSummary(String.format(RestErrorModel.CANNOT_RATE)); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that Contributor is able to like a folder") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void contributorIsAbleToLikeAFolder() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + + returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).withCoreAPI() + .usingResource(folderModel) + .likeDocument(); + + restClient.assertStatusCodeIs(HttpStatus.CREATED); + returnedRatingModel.assertThat().field("myRating").is("true") + .and().field("id").is("likes") + .and().field("aggregate").isNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that Collaborator is able to like a folder") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void collaboratorIsAbleToLikeAFolder() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI() + .usingResource(folderModel) + .likeDocument(); + + restClient.assertStatusCodeIs(HttpStatus.CREATED); + returnedRatingModel.assertThat().field("myRating").is("true") + .and().field("id").is("likes") + .and().field("aggregate").isNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that Consumer is able to like a folder") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void consumerIsAbleToLikeAFolder() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI() + .usingResource(folderModel) + .likeDocument(); + + restClient.assertStatusCodeIs(HttpStatus.CREATED); + returnedRatingModel.assertThat().field("myRating").is("true") + .and().field("id").is("likes") + .and().field("aggregate").isNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that Contributor is able to rate a folder") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void contributorIsAbleToRateAFolder() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).withCoreAPI() + .usingResource(folderModel) + .rateStarsToDocument(5); + + restClient.assertStatusCodeIs(HttpStatus.CREATED); + returnedRatingModel.assertThat().field("myRating").is("5") + .and().field("id").is("fiveStar") + .and().field("aggregate").isNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that Collaborator is able to rate a folder") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void collaboratorIsAbleToRateAFolder() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI() + .usingResource(folderModel) + .rateStarsToDocument(5); + + restClient.assertStatusCodeIs(HttpStatus.CREATED); + returnedRatingModel.assertThat().field("myRating").is("5") + .and().field("id").is("fiveStar") + .and().field("aggregate").isNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that Consumer is able to rate a folder") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void consumerIsAbleToRateAFolder() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI() + .usingResource(folderModel) + .rateStarsToDocument(5); + + restClient.assertStatusCodeIs(HttpStatus.CREATED); + returnedRatingModel.assertThat().field("myRating").is("5") + .and().field("id").is("fiveStar") + .and().field("aggregate").isNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that adding like again has no effect on a folder") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void folderCanBeLikedTwice() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(folderModel).likeDocument(); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + returnedRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(folderModel).likeDocument(); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + returnedRatingModel.assertThat().field("myRating").is("true") + .and().field("id").is("likes") + .and().field("aggregate").isNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that adding rate again has no effect on a folder") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void folderCanBeRatedTwice() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(folderModel).rateStarsToDocument(5); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + returnedRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(folderModel).rateStarsToDocument(5); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + returnedRatingModel.assertThat().field("myRating").is("5") + .and().field("id").is("fiveStar") + .and().field("aggregate").isNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that if invalid rate id is provided status code is 400") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void addRateUsingInvalidValueForId() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"id\":\"like\"}"); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsSummary(String.format(RestErrorModel.INVALID_RATING, "like")) + .containsErrorKey(String.format(RestErrorModel.INVALID_RATING, "like")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that rate id is case sensitive is provided status code is 400") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void addRateUsingInvalidValueForIdCaseSensitive() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"id\":\"Likes\"}"); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsSummary(String.format(RestErrorModel.INVALID_RATING, "Likes")) + .containsErrorKey(String.format(RestErrorModel.INVALID_RATING, "Likes")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"id\":\"FiveStar\"}"); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsSummary(String.format(RestErrorModel.INVALID_RATING, "FiveStar")) + .containsErrorKey(String.format(RestErrorModel.INVALID_RATING, "FiveStar")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that if invalid rating is provided status code is 400") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void addRateUsingInvalidValueForMyRating() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"id\":\"likes\", \"myRating\":\"skiped\"}"); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsSummary(String.format(RestErrorModel.NULL_LIKE_RATING)); + + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"id\":\"fiveStar\", \"myRating\":\"string\"}"); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsSummary(String.format(RestErrorModel.NULL_FIVESTAR_RATING)); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Like file created by a different user") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void addLikeToAnotherUserFile() throws Exception + { + UserModel user = dataUser.usingAdmin().createRandomTestUser(); + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + returnedRatingModel = restClient.authenticateUser(user).withCoreAPI().usingResource(document).likeDocument(); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + returnedRatingModel.assertThat().field("myRating").is("true") + .and().field("id").is("likes") + .and().field("aggregate").isNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Rate a file created by a different user") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void addRatingToAnotherUserFile() throws Exception + { + UserModel user = dataUser.usingAdmin().createRandomTestUser(); + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + returnedRatingModel = restClient.authenticateUser(user).withCoreAPI().usingResource(document).rateStarsToDocument(5); + returnedRatingModel.assertThat().field("myRating").is("5") + .and().field("id").is("fiveStar") + .and().field("aggregate").isNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Add Rate Using Boolean Value For 'myRating'") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void addRateUsingBooleanValueForMyRating() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"id\":\"fiveStar\", \"myRating\":\"true\"}"); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsSummary(RestErrorModel.NULL_FIVESTAR_RATING) + .containsErrorKey(RestErrorModel.NULL_FIVESTAR_RATING) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Add Like Using Integer Value For 'myRating'") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void addLikeUsingIntegerValueForMyRating() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"id\":\"likes\", \"myRating\":\"2\"}"); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsSummary(RestErrorModel.NULL_LIKE_RATING) + .containsErrorKey(RestErrorModel.NULL_LIKE_RATING) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that user is not able to like his own comment") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void userCannotLikeHisOwnComment() throws Exception + { + UserModel user = usersWithRoles.getOneUserWithRole(UserRole.SiteManager); + FolderModel folderModel = dataContent.usingUser(user).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(user).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + RestCommentModel comment = restClient.authenticateUser(user).withCoreAPI().usingResource(document).addComment("This is a comment"); + document.setNodeRef(comment.getId()); + + returnedRatingModel = restClient.authenticateUser(user).withCoreAPI().usingResource(document).likeDocument(); + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED) + .assertLastError() + .containsSummary(String.format(RestErrorModel.CANNOT_RATE)) + .containsErrorKey(RestErrorModel.CANNOT_RATE) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER).stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that user is not able to rate his own comment") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void userCannotRateHisOwnComment() throws Exception + { + UserModel user = usersWithRoles.getOneUserWithRole(UserRole.SiteManager); + FolderModel folderModel = dataContent.usingUser(user).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(user).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + RestCommentModel comment = restClient.authenticateUser(user).withCoreAPI().usingResource(document).addComment("This is a comment"); + document.setNodeRef(comment.getId()); + + returnedRatingModel = restClient.authenticateUser(user).withCoreAPI().usingResource(document).rateStarsToDocument(5); + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED) + .assertLastError() + .containsSummary(String.format(RestErrorModel.CANNOT_RATE)) + .containsErrorKey(RestErrorModel.CANNOT_RATE) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that Collaborator is NOT able to add a negative rating to a file") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void collaboratorIsNotAbleToAddANegativeRatingToAFile() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI() + .usingResource(document) + .rateStarsToDocument(-5); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsSummary(RestErrorModel.RATING_OUT_OF_BOUNDS) + .containsErrorKey(RestErrorModel.RATING_OUT_OF_BOUNDS) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that Collaborator is NOT able to add a high rating to a file") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void collaboratorIsNotAbleToAddAHighRatingToAFile() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI() + .usingResource(document) + .rateStarsToDocument(10); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsSummary(RestErrorModel.RATING_OUT_OF_BOUNDS) + .containsErrorKey(RestErrorModel.RATING_OUT_OF_BOUNDS) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + // @Bug(id = "MNT-17375", description = "Won't Fix, the error message is not ideal and a little cryptic but it does provide the reason i.e. ratingSchemeId is null.") + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Do not provide field - 'id'") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void notProvideIdLikeFile() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"myRating\":\"true\"}"); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsSummary(String.format(RestErrorModel.INVALID_RATING, "null")) + .containsErrorKey(String.format(RestErrorModel.INVALID_RATING, "null")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Do not provide field - 'myRating'") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void notProvideMyRatingRateFile() throws Exception + { + FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"id\":\"likes\"}"); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsSummary(RestErrorModel.NULL_LIKE_RATING) + .containsErrorKey(RestErrorModel.NULL_LIKE_RATING) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } +} \ No newline at end of file diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/ratings/DeleteRatingTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/ratings/DeleteRatingTests.java new file mode 100644 index 0000000000..3219750c38 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/ratings/DeleteRatingTests.java @@ -0,0 +1,523 @@ +package org.alfresco.rest.ratings; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestRatingModel; +import org.alfresco.rest.model.RestRatingModelsCollection; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; +import org.alfresco.utility.exception.DataPreparationException; +import org.alfresco.utility.model.FileModel; +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.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class DeleteRatingTests extends RestTest +{ + private SiteModel siteModel; + private UserModel adminUser; + private ListUserWithRoles usersWithRoles; + private RestRatingModelsCollection returnedRatingModelCollection; + private RestRatingModel returnedRatingModel; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws DataPreparationException + { + adminUser = dataUser.getAdminUser(); + siteModel = dataSite.usingUser(adminUser).createPublicRandomSite(); + + usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, + UserRole.SiteContributor); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.SANITY, description = "Verify user with Manager role is able to remove its own rating of a document") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY }) + public void managerIsAbleToDeleteItsOwnRatings() throws Exception + { + FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + restClient.withCoreAPI().usingResource(document).likeDocument(); + restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5); + + restClient.withCoreAPI().usingResource(document).deleteLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + restClient.withCoreAPI().usingResource(document).deleteFiveStarRating(); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + returnedRatingModelCollection = restClient.withCoreAPI().usingResource(document).getRatings(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedRatingModelCollection.assertNodeIsNotLiked().assertNodeHasNoFiveStarRating().and().entriesListIsNotEmpty().and().paginationExist(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Verify user with Collaborator role is able to remove its own rating of a document") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void collaboratorIsAbleToDeleteItsOwnRatings() throws Exception + { + FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); + + restClient.withCoreAPI().usingResource(document).likeDocument(); + restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5); + + restClient.withCoreAPI().usingResource(document).deleteLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + restClient.withCoreAPI().usingResource(document).deleteFiveStarRating(); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + returnedRatingModelCollection = restClient.withCoreAPI().usingResource(document).getRatings(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedRatingModelCollection.assertNodeIsNotLiked().assertNodeHasNoFiveStarRating().and().entriesListIsNotEmpty().and().paginationExist(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Verify user with Contributor role is able to remove its own rating of a document") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void contributorIsAbleToDeleteItsOwnRatings() throws Exception + { + FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); + + restClient.withCoreAPI().usingResource(document).likeDocument(); + restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5); + + restClient.withCoreAPI().usingResource(document).deleteLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + restClient.withCoreAPI().usingResource(document).deleteFiveStarRating(); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + returnedRatingModelCollection = restClient.withCoreAPI().usingResource(document).getRatings(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedRatingModelCollection.assertNodeIsNotLiked().assertNodeHasNoFiveStarRating().and().entriesListIsNotEmpty().and().paginationExist(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Verify user with Consumer role is able to remove its own rating of a document") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void consumerIsAbleToDeleteItsOwnRatings() throws Exception + { + FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)); + + restClient.withCoreAPI().usingResource(document).likeDocument(); + restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5); + + restClient.withCoreAPI().usingResource(document).deleteLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + restClient.withCoreAPI().usingResource(document).deleteFiveStarRating(); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + returnedRatingModelCollection = restClient.withCoreAPI().usingResource(document).getRatings(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedRatingModelCollection.assertNodeIsNotLiked().assertNodeHasNoFiveStarRating().and().entriesListIsNotEmpty().and().paginationExist(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Verify admin user is able to remove its own rating of a document") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void adminIsAbleToDeleteItsOwnRatings() throws Exception + { + FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + document = dataContent.usingUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).usingResource(folderModel) + .createContent(DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(adminUser); + + restClient.withCoreAPI().usingResource(document).likeDocument(); + restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5); + + restClient.withCoreAPI().usingResource(document).deleteLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + restClient.withCoreAPI().usingResource(document).deleteFiveStarRating(); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + returnedRatingModelCollection = restClient.withCoreAPI().usingResource(document).getRatings(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedRatingModelCollection.assertNodeIsNotLiked().assertNodeHasNoFiveStarRating().and().entriesListIsNotEmpty().and().paginationExist(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.SANITY, description = "Verify unauthenticated user is not able to remove its own rating of a document") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY }) +// @Bug(id="MNT-16904", description = "It fails only on environment with tenants") + public void unauthenticatedUserIsNotAbleToDeleteRatings() throws Exception + { + FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + document = dataContent.usingUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).usingResource(folderModel) + .createContent(DocumentType.TEXT_PLAIN); + restClient.authenticateUser(adminUser); + + restClient.withCoreAPI().usingResource(document).likeDocument(); + restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5); + + restClient.authenticateUser(new UserModel("random user", "random password")); + + restClient.withCoreAPI().usingResource(document).deleteLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + + restClient.withCoreAPI().usingResource(document).deleteFiveStarRating(); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Verify one user is not able to remove rating added by another user") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + @Bug(id = "ACE-5459") + public void oneUserIsNotAbleToDeleteRatingsOfAnotherUser() throws Exception + { + FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + UserModel userA = dataUser.createRandomTestUser(); + UserModel userB = dataUser.createRandomTestUser(); + + restClient.authenticateUser(userA); + + restClient.withCoreAPI().usingResource(document).likeDocument(); + restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5); + + restClient.authenticateUser(userB); + + restClient.withCoreAPI().usingResource(document).deleteLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + + restClient.withCoreAPI().usingResource(document).deleteFiveStarRating(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + restClient.withCoreAPI().usingResource(document).getRatings() + .assertNodeIsLiked() + .assertNodeHasFiveStarRating(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Verify that if ratingId provided is unknown status code returned is 400") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void deleteInvalidRating() throws Exception + { + FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).deleteInvalidRating("random_rating"); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsSummary(String.format(RestErrorModel.INVALID_RATING, "random_rating")) + .containsErrorKey(String.format(RestErrorModel.INVALID_RATING, "random_rating")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Verify that if nodeId does not exist status code returned is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void deleteRatingUsingInvalidDocument() throws Exception + { + FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + document.setNodeRef("random_value"); + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).deleteLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "random_value")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Delete rating stars for a document that was not rated") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + @Bug(id = "MNT-17181") + public void deleteStarsForANotRatedDocument() throws Exception + { + FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).deleteFiveStarRating(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Delete like rating for a document that was not liked") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + @Bug(id = "MNT-17181") + public void deleteLikeForANotLikedDocument() throws Exception + { + FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).deleteLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Delete like for a file then add it again") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void likeDocumentAfterLikeRatingIsDeleted() throws Exception + { + FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).likeDocument(); + restClient.withCoreAPI().usingResource(document).deleteLikeRating(); + returnedRatingModel = restClient.withCoreAPI().usingResource(document).likeDocument(); + + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + returnedRatingModel.assertThat().field("myRating").is("true").and().field("id").is("likes").and().field("aggregate").isNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Delete stars for a file then add them again") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void addStarsToDocumentAfterRatingIsDeleted() throws Exception + { + FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingResource(document).rateStarsToDocument(5); + restClient.withCoreAPI().usingResource(document).deleteFiveStarRating(); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + returnedRatingModel = restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5); + + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Verify site manager is not able to remove rating added by another user") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + @Bug(id = "ACE-5459") + public void deleteDocumentRatingUsingManager() throws Exception + { + FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingResource(document).rateStarsToDocument(5); + restClient.withCoreAPI().usingResource(document).likeDocument(); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(document).deleteFiveStarRating(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + restClient.withCoreAPI().usingResource(document).deleteLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + + restClient.withCoreAPI().usingResource(document).getRatings() + .assertNodeIsLiked() + .assertNodeHasFiveStarRating(); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Verify site contributor is not able to remove rating added by another user") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + @Bug(id = "ACE-5459") + public void contributorIsNotAbleToDeleteRatingsOfAnotherUser() throws Exception + { + FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(document).rateStarsToDocument(5); + restClient.withCoreAPI().usingResource(document).likeDocument(); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).withCoreAPI().usingResource(document).deleteFiveStarRating(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + restClient.withCoreAPI().usingResource(document).deleteLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + + restClient.withCoreAPI().usingResource(document).getRatings() + .assertNodeIsLiked() + .assertNodeHasFiveStarRating(); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Verify site collaborator is not able to remove rating added by another user") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + @Bug(id = "ACE-5459") + public void collaboratorIsNotAbleToDeleteRatingsOfAnotherUser() throws Exception + { + FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(document).rateStarsToDocument(5); + restClient.withCoreAPI().usingResource(document).likeDocument(); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingResource(document).deleteFiveStarRating(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + restClient.withCoreAPI().usingResource(document).deleteLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + + restClient.withCoreAPI().usingResource(document).getRatings() + .assertNodeIsLiked() + .assertNodeHasFiveStarRating(); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Verify site consumer is not able to remove rating added by another user") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + @Bug(id = "ACE-5459") + public void consumerIsNotAbleToDeleteRatingsOfAnotherUser() throws Exception + { + FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(document).rateStarsToDocument(5); + restClient.withCoreAPI().usingResource(document).likeDocument(); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI().usingResource(document).deleteFiveStarRating(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + restClient.withCoreAPI().usingResource(document).deleteLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + + restClient.withCoreAPI().usingResource(document).getRatings() + .assertNodeIsLiked() + .assertNodeHasFiveStarRating(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Delete rating stars twice") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + @Bug(id = "MNT-17181") + public void deleteStarsTwice() throws Exception + { + FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingResource(document).rateStarsToDocument(5); + + restClient.withCoreAPI().usingResource(document).deleteFiveStarRating(); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + returnedRatingModelCollection = restClient.withCoreAPI().usingResource(document).getRatings(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedRatingModelCollection.assertNodeHasNoFiveStarRating(); + + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).deleteFiveStarRating(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Delete like rating twice") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + @Bug(id = "MNT-17181") + public void deleteLikeTwice() throws Exception + { + FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + restClient.withCoreAPI().usingResource(document).likeDocument(); + + restClient.withCoreAPI().usingResource(document).deleteLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + returnedRatingModelCollection = restClient.withCoreAPI().usingResource(document).getRatings(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedRatingModelCollection.assertNodeIsNotLiked(); + + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).deleteLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Delete like for a folder then add it again") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void likeFolderAfterLikeRatingIsDeleted() throws Exception + { + FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder(); + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(folderModel).likeDocument(); + restClient.withCoreAPI().usingResource(folderModel).deleteLikeRating(); + returnedRatingModel = restClient.withCoreAPI().usingResource(folderModel).likeDocument(); + + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + returnedRatingModel.assertThat().field("myRating").is("true").and().field("id").is("likes").and().field("aggregate").isNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Delete stars for a folder then add them again") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void addStarsToFolderAfterRatingIsDeleted() throws Exception + { + FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder(); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingResource(folderModel).rateStarsToDocument(5); + restClient.withCoreAPI().usingResource(folderModel).deleteFiveStarRating(); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + returnedRatingModel = restClient.withCoreAPI().usingResource(folderModel).rateStarsToDocument(5); + + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Delete like for a site then add it again") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void likeSiteAfterLikeRatingIsDeleted() throws Exception + { + FolderModel folderModel = new FolderModel(); + folderModel.setNodeRef(siteModel.getGuid()); + + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(folderModel).likeDocument(); + restClient.withCoreAPI().usingResource(folderModel).deleteLikeRating(); + returnedRatingModel = restClient.withCoreAPI().usingResource(folderModel).likeDocument(); + + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + returnedRatingModel.assertThat().field("myRating").is("true").and().field("id").is("likes").and().field("aggregate").isNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Delete stars for a site then add them again") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void addStarsToSiteAfterRatingIsDeleted() throws Exception + { + FolderModel folderModel = new FolderModel(); + folderModel.setNodeRef(siteModel.getGuid()); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingResource(folderModel).rateStarsToDocument(5); + restClient.withCoreAPI().usingResource(folderModel).deleteFiveStarRating(); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + returnedRatingModel = restClient.withCoreAPI().usingResource(folderModel).rateStarsToDocument(5); + + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Verify user with Manager role is able to remove one star rating of a document") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void removeOneStarRating() throws Exception + { + FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + restClient.withCoreAPI().usingResource(document).rateStarsToDocument(1); + + restClient.withCoreAPI().usingResource(document).deleteFiveStarRating(); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + returnedRatingModelCollection = restClient.withCoreAPI().usingResource(document).getRatings(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedRatingModelCollection.assertNodeIsNotLiked().assertNodeHasNoFiveStarRating().and().entriesListIsNotEmpty().and().paginationExist(); + } +} \ No newline at end of file diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/ratings/GetRatingTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/ratings/GetRatingTests.java new file mode 100644 index 0000000000..dbbf14f614 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/ratings/GetRatingTests.java @@ -0,0 +1,438 @@ +package org.alfresco.rest.ratings; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestRatingModel; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; +import org.alfresco.utility.exception.DataPreparationException; +import org.alfresco.utility.model.FileModel; +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.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.commons.lang3.RandomStringUtils; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +public class GetRatingTests extends RestTest +{ + private SiteModel siteModel; + private UserModel adminUser, userModel, managerUser; + private FileModel document; + private ListUserWithRoles usersWithRoles; + private RestRatingModel restRatingModel; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws DataPreparationException + { + adminUser = dataUser.getAdminUser(); + userModel = dataUser.createRandomTestUser(); + managerUser = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(adminUser).createPublicRandomSite(); + + usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, + UserRole.SiteContributor); + + dataUser.addUserToSite(managerUser, siteModel, UserRole.SiteManager); + } + + @BeforeMethod(alwaysRun = true) + public void setUp() throws Exception + { + document = dataContent.usingSite(siteModel).usingAdmin().createContent(DocumentType.TEXT_PLAIN); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.SANITY, description = "Verify user with Manager role is able to retrieve rating of a document") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY }) + public void managerIsAbleToRetrieveRating() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + + restClient.withCoreAPI().usingResource(document).likeDocument(); + restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5); + + restRatingModel = restClient.withCoreAPI().usingResource(document).getLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restRatingModel.assertThat().field("id").is("likes").and().field("myRating").is("true"); + + restRatingModel = restClient.withCoreAPI().usingResource(document).getFiveStarRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restRatingModel.assertThat().field("id").is("fiveStar").and().field("myRating").is("5"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Verify user with Collaborator role is able to retrieve rating of a document") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void collaboratorIsAbleToRetrieveRating() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); + + restClient.withCoreAPI().usingResource(document).likeDocument(); + restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5); + + restRatingModel = restClient.withCoreAPI().usingResource(document).getLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restRatingModel.assertThat().field("id").is("likes").and().field("myRating").is("true"); + + restRatingModel = restClient.withCoreAPI().usingResource(document).getFiveStarRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restRatingModel.assertThat().field("id").is("fiveStar").and().field("myRating").is("5"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Verify user with Contributor role is able to retrieve rating of a document") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void contributorIsAbleToRetrieveRating() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); + + restClient.withCoreAPI().usingResource(document).likeDocument(); + restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5); + + restRatingModel = restClient.withCoreAPI().usingResource(document).getLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restRatingModel.assertThat().field("id").is("likes").and().field("myRating").is("true"); + + restRatingModel = restClient.withCoreAPI().usingResource(document).getFiveStarRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restRatingModel.assertThat().field("id").is("fiveStar").and().field("myRating").is("5"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Verify user with Consumer role is able to retrieve rating of a document") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void consumerIsAbleToRetrieveRating() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)); + + restClient.withCoreAPI().usingResource(document).likeDocument(); + restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5); + + restRatingModel = restClient.withCoreAPI().usingResource(document).getLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restRatingModel.assertThat().field("id").is("likes").and().field("myRating").is("true"); + + restRatingModel = restClient.withCoreAPI().usingResource(document).getFiveStarRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restRatingModel.assertThat().field("id").is("fiveStar").and().field("myRating").is("5"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Verify admin user is able to retrieve rating of a document") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void adminIsAbleToRetrieveRating() throws Exception + { + FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder(); + FileModel document = dataContent.usingUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingResource(folderModel) + .createContent(DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(adminUser); + restClient.withCoreAPI().usingResource(document).likeDocument(); + restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5); + + restRatingModel = restClient.withCoreAPI().usingResource(document).getLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restRatingModel.assertThat().field("id").is("likes").and().field("myRating").is("true"); + + restRatingModel = restClient.withCoreAPI().usingResource(document).getFiveStarRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restRatingModel.assertThat().field("id").is("fiveStar").and().field("myRating").is("5"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.SANITY, description = "Verify unauthenticated user is not able to retrieve rating of a document") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY }) +// @Bug(id = "MNT-16904", description = "It fails only on environment with tenants") + public void unauthenticatedUserIsNotAbleToRetrieveRating() throws Exception + { + restClient.authenticateUser(adminUser); + restClient.withCoreAPI().usingResource(document).likeDocument(); + restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5); + + restClient.authenticateUser(new UserModel("random user", "random password")); + + restClient.withCoreAPI().usingResource(document).getLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + + restClient.withCoreAPI().usingResource(document).getFiveStarRating(); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Check that using invalid ratingId for get rating call returns status code 400.") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void checkInvalidRatingIdStatusCode() throws Exception + { + restClient.authenticateUser(adminUser).withCoreAPI(); + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "nodes/{nodeId}/ratings/{ratingId}", document.getNodeRef(), "invalid ratingId"); + restClient.processModel(RestRatingModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(String.format(RestErrorModel.INVALID_RATING, "invalid ratingId")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Check that using invalid node ID for get rating call returns status code 404.") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void getRatingUsingInvalidNodeId() throws Exception + { + document.setNodeRef(RandomStringUtils.randomAlphanumeric(20)); + restRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).getFiveStarRating(); + + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, document.getNodeRef())); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Get rating of a file that has only likes.") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void getRatingOfFileThatHasOnlyLikes() throws Exception + { + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).likeDocument(); + + restRatingModel = restClient.withCoreAPI().usingResource(document).getLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restRatingModel.assertThat().field("id").is("likes").and().field("myRating").is("true"); + restRatingModel.getAggregate().assertThat().field("numberOfRatings").is("1"); + + restRatingModel = restClient.withCoreAPI().usingResource(document).getFiveStarRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restRatingModel.getAggregate().assertThat().field("numberOfRatings").is("0"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Get rating of a file that has only stars.") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void getRatingOfFileThatHasOnlyStars() throws Exception + { + restClient.authenticateUser(userModel).withCoreAPI().usingResource(document).rateStarsToDocument(5); + + restRatingModel = restClient.withCoreAPI().usingResource(document).getFiveStarRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty(); + restRatingModel.getAggregate().assertThat().field("numberOfRatings").is("1"); + + restRatingModel = restClient.withCoreAPI().usingResource(document).getLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restRatingModel.getAggregate().assertThat().field("numberOfRatings").is("0"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Get rating of a file that has likes and stars.") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void getRatingOfFileThatHasLikesAndStars() throws Exception + { + restClient.authenticateUser(userModel).withCoreAPI().usingResource(document).likeDocument(); + restClient.authenticateUser(userModel).withCoreAPI().usingResource(document).rateStarsToDocument(5); + + restRatingModel = restClient.withCoreAPI().usingResource(document).getLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restRatingModel.assertThat().field("id").is("likes").and().field("myRating").is("true"); + restRatingModel.getAggregate().assertThat().field("numberOfRatings").is("1"); + + restRatingModel = restClient.withCoreAPI().usingResource(document).getFiveStarRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty(); + restRatingModel.getAggregate().assertThat().field("numberOfRatings").is("1"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Get rating of a folder that has only likes.") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void getRatingOfFolderThatHasOnlyLikes() throws Exception + { + FolderModel firstFolderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder(); + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(firstFolderModel).likeDocument(); + + restRatingModel = restClient.withCoreAPI().usingResource(firstFolderModel).getLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restRatingModel.assertThat().field("id").is("likes").and().field("myRating").is("true"); + restRatingModel.getAggregate().assertThat().field("numberOfRatings").is("1"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Get rating of a file that has no ratings.") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void getRatingOfFileThatHasNoRatings() throws Exception + { + restRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).getLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restRatingModel.getAggregate().assertThat().field("numberOfRatings").is("0"); + + restRatingModel = restClient.withCoreAPI().usingResource(document).getFiveStarRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restRatingModel.getAggregate().assertThat().field("numberOfRatings").is("0"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Check default error schema") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void checkDefaultErrorSchema() throws Exception + { + FileModel document = dataContent.usingSite(siteModel).usingAdmin().createContent(DocumentType.TEXT_PLAIN); + String randomNodeRef = RandomStringUtils.randomAlphanumeric(10); + document.setNodeRef(randomNodeRef); + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).getLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, randomNodeRef)) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Get rating of a folder that has only stars") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void getRatingOfFolderThatHasOnlyStars() throws Exception + { + FolderModel folder = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder(); + restClient.authenticateUser(managerUser).withCoreAPI().usingResource(folder).rateStarsToDocument(3); + restRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(folder).getFiveStarRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restRatingModel.assertThat().field("id").is("fiveStar") + .getAggregate().assertThat().field("numberOfRatings").is("1") + .assertThat().field("average").is("3.0"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Get rating of a folder that has both likes and stars") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void getRatingOfFolderThatHasLikedAndStars() throws Exception + { + FolderModel folder = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder(); + restClient.authenticateUser(managerUser).withCoreAPI().usingResource(folder).rateStarsToDocument(3); + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(folder).likeDocument(); + + restRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(folder).getFiveStarRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restRatingModel.assertThat().field("id").is("fiveStar") + .getAggregate().assertThat().field("numberOfRatings").is("1") + .assertThat().field("average").is("3.0"); + + restRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(folder).getLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restRatingModel.assertThat().field("id").is("likes") + .assertThat().field("myRating").is("true"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Get rating of a folder that has no ratings") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void getRatingOfFolderThatHasNoRatings() throws Exception + { + FolderModel folder = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder(); + + restRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(folder).getFiveStarRating(); + restRatingModel.getAggregate().assertThat().field("numberOfRatings").is("0"); + + restRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(folder).getLikeRating(); + restRatingModel.getAggregate().assertThat().field("numberOfRatings").is("0"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Get rating of a folder after rating was deleted") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void getDeletedRatingOfAFolder() throws Exception + { + FolderModel folder = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder(); + restClient.authenticateUser(managerUser).withCoreAPI().usingResource(folder).rateStarsToDocument(3); + restClient.authenticateUser(managerUser).withCoreAPI().usingResource(folder).deleteFiveStarRating(); + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(folder).likeDocument(); + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(folder).deleteLikeRating(); + + restRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(folder).getFiveStarRating(); + restRatingModel.assertThat().field("id").is("fiveStar").getAggregate().assertThat().field("numberOfRatings").is("0") + .assertThat().field("average").isNull(); + + restRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(folder).getLikeRating(); + restRatingModel.assertThat().field("id").is("likes").assertThat().field("myRating").isNull() + .getAggregate().assertThat().field("numberOfRatings").is("0"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Get rating of a file after rating was deleted") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void getDeletedRatingOfAFile() throws Exception + { + FileModel file = dataContent.usingUser(adminUser).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + restClient.authenticateUser(managerUser).withCoreAPI().usingResource(file).rateStarsToDocument(3); + restClient.authenticateUser(managerUser).withCoreAPI().usingResource(file).deleteFiveStarRating(); + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(file).likeDocument(); + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(file).deleteLikeRating(); + + restRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(file).getFiveStarRating(); + restRatingModel.assertThat().field("id").is("fiveStar").getAggregate().assertThat().field("numberOfRatings").is("0") + .assertThat().field("average").isNull(); + + restRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(file).getLikeRating(); + restRatingModel.assertThat().field("id").is("likes").assertThat().field("myRating").isNull() + .getAggregate().assertThat().field("numberOfRatings").is("0"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Get rating of another user as admin") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void getRatingOfAnotherUserAsAdmin() throws Exception + { + FileModel file = dataContent.usingUser(adminUser).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + restClient.authenticateUser(managerUser).withCoreAPI().usingResource(file).rateStarsToDocument(3); + restClient.authenticateUser(managerUser).withCoreAPI().usingResource(file).likeDocument(); + + restRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(file).getFiveStarRating(); + restRatingModel.assertThat().field("id").is("fiveStar").and().field("myRating").isNull() + .getAggregate().assertThat().field("numberOfRatings").is("1").assertThat().field("average").is("3.0"); + + restRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(file).getLikeRating(); + restRatingModel.assertThat().field("id").is("likes").assertThat().field("myRating").isNull() + .getAggregate().assertThat().field("numberOfRatings").is("1"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Get rating of admin with another user") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void getRatingOfAdminWithAnotherUser() throws Exception + { + FileModel file = dataContent.usingUser(managerUser).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(file).rateStarsToDocument(3); + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(file).likeDocument(); + + restRatingModel = restClient.authenticateUser(managerUser).withCoreAPI().usingResource(file).getFiveStarRating(); + restRatingModel.assertThat().field("id").is("fiveStar").and().field("myRating").isNull() + .getAggregate().assertThat().field("numberOfRatings").is("1").assertThat().field("average").is("3.0"); + + restRatingModel = restClient.authenticateUser(managerUser).withCoreAPI().usingResource(file).getLikeRating(); + restRatingModel.assertThat().field("id").is("likes").assertThat().field("myRating").isNull() + .getAggregate().assertThat().field("numberOfRatings").is("1"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Get five star rating") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void getFiveStarRating() throws Exception + { + FileModel file = dataContent.usingUser(managerUser).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(file).rateStarsToDocument(5); + + restRatingModel = restClient.authenticateUser(managerUser).withCoreAPI().usingResource(file).getFiveStarRating(); + restRatingModel.assertThat().field("id").is("fiveStar").and().field("myRating").isNull() + .getAggregate().assertThat().field("numberOfRatings").is("1").assertThat().field("average").is("5.0"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Get one star rating") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void getOneStarRating() throws Exception + { + FileModel file = dataContent.usingUser(managerUser).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(file).rateStarsToDocument(1); + + restRatingModel = restClient.authenticateUser(managerUser).withCoreAPI().usingResource(file).getFiveStarRating(); + restRatingModel.assertThat().field("id").is("fiveStar").and().field("myRating").isNull() + .getAggregate().assertThat().field("numberOfRatings").is("1").assertThat().field("average").is("1.0"); + } +} \ No newline at end of file diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/ratings/GetRatingsTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/ratings/GetRatingsTests.java new file mode 100644 index 0000000000..aa4f728e9b --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/ratings/GetRatingsTests.java @@ -0,0 +1,312 @@ +package org.alfresco.rest.ratings; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestRatingModelsCollection; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; +import org.alfresco.utility.exception.DataPreparationException; +import org.alfresco.utility.model.FileModel; +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.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.commons.lang3.RandomStringUtils; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class GetRatingsTests extends RestTest +{ + private SiteModel siteModel; + private UserModel adminUser, userModel; + private ListUserWithRoles usersWithRoles; + private RestRatingModelsCollection restRatingModelsCollection; + private FileModel document; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws DataPreparationException + { + adminUser = dataUser.getAdminUser(); + userModel = dataUser.createRandomTestUser(); + + siteModel = dataSite.usingUser(adminUser).createPublicRandomSite(); + + usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, + UserRole.SiteContributor); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.SANITY, description = "Manager is able to retrieve document ratings") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY }) + public void managerIsAbleToRetrieveDocumentRatings() throws Exception + { + FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder(); + document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + + restClient.withCoreAPI().usingResource(document).likeDocument(); + restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5); + + restRatingModelsCollection = restClient.withCoreAPI().usingResource(document).getRatings(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restRatingModelsCollection.assertNodeHasFiveStarRating().assertNodeIsLiked(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Collaborator is able to retrieve document ratings") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void collaboratorIsAbleToRetrieveDocumentRatings() throws Exception + { + FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder(); + document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); + + restClient.withCoreAPI().usingResource(document).likeDocument(); + restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5); + + restRatingModelsCollection = restClient.withCoreAPI().usingResource(document).getRatings(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restRatingModelsCollection.assertNodeHasFiveStarRating().assertNodeIsLiked(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Contributor is able to retrieve document ratings") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void contributorIsAbleToRetrieveDocumentRatings() throws Exception + { + FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder(); + document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); + + restClient.withCoreAPI().usingResource(document).likeDocument(); + restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5); + + restRatingModelsCollection = restClient.withCoreAPI().usingResource(document).getRatings(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restRatingModelsCollection.assertNodeHasFiveStarRating().assertNodeIsLiked(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Consumer is able to retrieve document ratings") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void consumerIsAbleToRetrieveDocumentRatings() throws Exception + { + FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder(); + document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)); + + restClient.withCoreAPI().usingResource(document).likeDocument(); + restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5); + + restRatingModelsCollection = restClient.withCoreAPI().usingResource(document).getRatings(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restRatingModelsCollection.assertNodeHasFiveStarRating().assertNodeIsLiked(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.REGRESSION, description = "Admin user is able to retrieve document ratings") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void adminIsAbleToRetrieveDocumentRatings() throws Exception + { + FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder(); + document = dataContent.usingUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingResource(folderModel) + .createContent(DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(adminUser); + restClient.withCoreAPI().usingResource(document).likeDocument(); + restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5); + + restRatingModelsCollection = restClient.withCoreAPI().usingResource(document).getRatings(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restRatingModelsCollection.assertNodeHasFiveStarRating().assertNodeIsLiked(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, + executionType = ExecutionType.SANITY, description = "Verify unauthenticated user is not able to retrieve document ratings") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY }) +// @Bug(id="MNT-16904", description = "It fails only on environment with tenants") + public void unauthenticatedUserIsNotAbleToRetrieveRatings() throws Exception + { + FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder(); + document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(adminUser); + restClient.withCoreAPI().usingResource(document).likeDocument(); + restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5); + + restClient.authenticateUser(new UserModel("random user", "random password")); + + restClient.withCoreAPI().usingResource(document).getRatings(); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Check that rating for invalid maxItems status code is 400") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void checkInvalidMaxItemsStatusCode() throws Exception + { + document = dataContent.usingSite(siteModel).usingAdmin().createContent(CMISUtil.DocumentType.TEXT_PLAIN); + restClient.authenticateUser(userModel).withCoreAPI().usingNode(document).rateStarsToDocument(5); + restClient.authenticateUser(userModel).withCoreAPI().usingNode(document).likeDocument(); + + restClient.authenticateUser(adminUser).withParams("maxItems=0").withCoreAPI().usingResource(document).getRatings(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary("Only positive values supported for maxItems"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Check that rating for invalid skipCount status code is 400") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void checkInvalidSkipCountStatusCode() throws Exception + { + document = dataContent.usingSite(siteModel).usingAdmin().createContent(CMISUtil.DocumentType.TEXT_PLAIN); + restClient.authenticateUser(userModel).withCoreAPI().usingNode(document).rateStarsToDocument(5); + restClient.authenticateUser(userModel).withCoreAPI().usingNode(document).likeDocument(); + + restClient.authenticateUser(adminUser).withParams("skipCount=AB").withCoreAPI().usingResource(document).getRatings(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary("Invalid paging parameter skipCount:AB"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "If nodeId does not exist status code is 404 when a document is liked") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void addLikeUsingInvalidNodeId() throws Exception + { + document = dataContent.usingSite(siteModel).usingAdmin().createContent(CMISUtil.DocumentType.TEXT_PLAIN); + restClient.authenticateUser(userModel).withCoreAPI().usingNode(document).rateStarsToDocument(5); + restClient.authenticateUser(userModel).withCoreAPI().usingNode(document).likeDocument(); + document.setNodeRef(RandomStringUtils.randomAlphanumeric(20)); + + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).getRatings(); + + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, document.getNodeRef())); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Check that rating value is TRUE for a like rating") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void checkRatingValueIsTrueForLikedDoc() throws Exception + { + document = dataContent.usingSite(siteModel).usingAdmin().createContent(CMISUtil.DocumentType.TEXT_PLAIN); + restClient.authenticateUser(userModel).withCoreAPI().usingNode(document).rateStarsToDocument(5); + restClient.authenticateUser(userModel).withCoreAPI().usingNode(document).likeDocument(); + + restRatingModelsCollection = restClient.authenticateUser(userModel).withCoreAPI().usingResource(document).getRatings(); + restClient.assertStatusCodeIs(HttpStatus.OK); + + restRatingModelsCollection.assertThat().entriesListContains("myRating", "true") + .assertThat().entriesListContains("id", "likes"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Check that rating value is an INTEGER value for stars rating") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void checkRatingValueIsIntegerForStarsRating() throws Exception + { + document = dataContent.usingSite(siteModel).usingAdmin().createContent(CMISUtil.DocumentType.TEXT_PLAIN); + restClient.authenticateUser(userModel).withCoreAPI().usingNode(document).rateStarsToDocument(5); + restClient.authenticateUser(userModel).withCoreAPI().usingNode(document).likeDocument(); + + restRatingModelsCollection = restClient.authenticateUser(userModel).withCoreAPI().usingResource(document).getRatings(); + restClient.assertStatusCodeIs(HttpStatus.OK); + + restRatingModelsCollection.assertThat().entriesListContains("myRating", "5") + .assertThat().entriesListContains("id", "fiveStar"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Check default error schema in case of failure") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void checkDefaultErrorSchema() throws Exception + { + FileModel document = dataContent.usingSite(siteModel).usingAdmin().createContent(CMISUtil.DocumentType.TEXT_PLAIN); + document.setNodeRef("abc"); + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).getRatings(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "abc")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Check maxItems and skipCount parameters") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void checkMaxItemsAndSkipCountParameters() throws Exception + { + document = dataContent.usingSite(siteModel).usingAdmin().createContent(CMISUtil.DocumentType.TEXT_PLAIN); + restClient.authenticateUser(userModel).withCoreAPI().usingNode(document).rateStarsToDocument(5); + restClient.authenticateUser(userModel).withCoreAPI().usingNode(document).likeDocument(); + + restRatingModelsCollection = restClient.authenticateUser(adminUser).withParams("maxItems=1", "skipCount=1").withCoreAPI().usingResource(document).getRatings(); + restRatingModelsCollection.assertThat().entriesListCountIs(1); + restRatingModelsCollection.getPagination().assertThat().field("maxItems").is("1") + .and().field("skipCount").is("1"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Check totalItems and hasMoreitems parameters") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void checkTotalItemsAndHasMoreItemsParameters() throws Exception + { + document = dataContent.usingSite(siteModel).usingAdmin().createContent(CMISUtil.DocumentType.TEXT_PLAIN); + restClient.authenticateUser(userModel).withCoreAPI().usingNode(document).rateStarsToDocument(5); + restClient.authenticateUser(userModel).withCoreAPI().usingNode(document).likeDocument(); + + restRatingModelsCollection = restClient.authenticateUser(adminUser).withParams("maxItems=1").withCoreAPI().usingResource(document).getRatings(); + restRatingModelsCollection.assertThat().entriesListCountIs(1); + restRatingModelsCollection.getPagination().assertThat().field("hasMoreItems").is("true") + .and().field("count").is("1").and().field("maxItems").is("1"); + } + + @Bug(id = "REPO-1831") + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Get ratings for a document to which authenticated user does not have access") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void userIsNotAbleToGetRatingsOfDocumentToWhichItHasNoAccess() throws Exception + { + SiteModel privateSite = dataSite.usingAdmin().createPrivateRandomSite(); + FileModel file = dataContent.usingSite(privateSite).usingAdmin().createContent(CMISUtil.DocumentType.TEXT_PLAIN); + restRatingModelsCollection = restClient.authenticateUser(userModel).withCoreAPI().usingResource(file).getRatings(); + restRatingModelsCollection.assertThat().entriesListIsEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Check high value for skipCount parameter") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void getRatingsUsingHighValueForSkipCount() throws Exception + { + document = dataContent.usingSite(siteModel).usingAdmin().createContent(CMISUtil.DocumentType.TEXT_PLAIN); + restClient.authenticateUser(userModel).withCoreAPI().usingNode(document).rateStarsToDocument(5); + restClient.authenticateUser(userModel).withCoreAPI().usingNode(document).likeDocument(); + + restRatingModelsCollection = restClient.authenticateUser(adminUser).withParams("skipCount=100").withCoreAPI().usingResource(document).getRatings(); + restRatingModelsCollection.getPagination().assertThat().field("skipCount").is("100"); + restRatingModelsCollection.assertThat().entriesListIsEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Get ratings using site id instead of node id") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION }) + public void getRatingsUsingSiteId() throws Exception + { + FileModel document = dataContent.usingSite(siteModel).usingAdmin().createContent(CMISUtil.DocumentType.TEXT_PLAIN); + document.setNodeRef(siteModel.getId()); + restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).getRatings(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, siteModel.getId())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } +} \ No newline at end of file diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/renditions/AvailableRenditionTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/renditions/AvailableRenditionTests.java new file mode 100644 index 0000000000..c3facea640 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/renditions/AvailableRenditionTests.java @@ -0,0 +1,134 @@ +package org.alfresco.rest.renditions; + +import org.alfresco.rest.model.RestNodeModel; +import org.alfresco.rest.model.RestRenditionInfoModel; +import org.alfresco.rest.model.RestRenditionInfoModelCollection; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +/** + * + * Sanity check for renditions through REST API.
+ * Tests upload files and then request renditions for those files.
+ * Renditions are requested based on supported renditions according to GET '/nodes/{nodeId}/renditions'.
+ */ +@Test(groups = {TestGroup.RENDITIONS}) +public class AvailableRenditionTests extends RenditionIntegrationTests +{ + /** List of parameters used as an input to supportedRenditionTest - fileName, nodeId, renditionId, expectedMimeType **/ + private List renditionsToTest; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + super.dataPreparation(); + + // Upload files and get available renditions for each file + List toTest = Arrays.asList("doc", "xls", "ppt", "docx", "xlsx", "pptx", "msg", "pdf", "png", "gif", "jpg"); + List renditionsForFiles = new LinkedList<>(); + for (String extensions : toTest) + { + String sourceFile = "quick/quick." + extensions; + renditionsForFiles.addAll(uploadFileAndGetAvailableRenditions(sourceFile)); + } + + renditionsToTest = Collections.unmodifiableList(renditionsForFiles); + } + + /** + * Upload a source file and get all supported renditions for it. + */ + private List uploadFileAndGetAvailableRenditions(String sourceFile) throws Exception + { + + // Create folder & upload file + RestNodeModel fileNode = uploadFile(sourceFile); + FileModel file = new FileModel(); + file.setNodeRef(fileNode.getId()); + + List renditionsForFile = new LinkedList<>(); + + // Get supported renditions + RestRenditionInfoModelCollection renditionsInfo = restClient.withCoreAPI().usingNode(file).getNodeRenditionsInfo(); + for (RestRenditionInfoModel m : renditionsInfo.getEntries()) + { + RestRenditionInfoModel renditionInfo = m.onModel(); + String renditionId = renditionInfo.getId(); + String targetMimeType = renditionInfo.getContent().getMimeType(); + + renditionsForFile.add(new Object[]{sourceFile, fileNode.getId(), renditionId, targetMimeType}); + + } + + return renditionsForFile; + } + + /** + * Check that a particular rendition can be created for the file and that it has the expected Mime type + */ + @Test(dataProvider = "RenditionTestDataProvider", groups = {TestGroup.REST_API, TestGroup.RENDITIONS, TestGroup.SANITY}) + @TestRail(section = { TestGroup.REST_API, TestGroup.RENDITIONS }, executionType = ExecutionType.SANITY, + description = "Verify renditions created for a selection of test files via POST nodes/{nodeId}/renditions") + public void supportedRenditionTest(String fileName, String nodeId, String renditionId, String expectedMimeType) throws Exception + { + checkRendition(fileName, nodeId, renditionId, expectedMimeType); + } + + @DataProvider(name = "RenditionTestDataProvider") + protected Iterator renditionTestDataProvider() throws Exception + { + return renditionsToTest.iterator(); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.RENDITIONS, TestGroup.SANITY}) + @TestRail(section = { TestGroup.REST_API, TestGroup.RENDITIONS }, executionType = ExecutionType.SANITY, + description = "Verify that there are some available renditions.") + public void renditionsAvailableTest() + { + Assert.assertFalse(renditionsToTest.isEmpty(), "No available renditions were reported for any of the test files."); + } + + @Test(dataProvider = "UnsupportedRenditionTestDataProvider",groups = {TestGroup.REST_API, TestGroup.RENDITIONS, TestGroup.SANITY}) + @TestRail(section = { TestGroup.REST_API, TestGroup.RENDITIONS }, executionType = ExecutionType.SANITY, + description = "Verify that requests for unsupported renditions return 400 ") + public void unsupportedRenditionTest(String sourceFile, String renditionId) throws Exception + { + RestNodeModel fileNode = uploadFile(sourceFile); + + // 2. Request rendition of the file using RESTAPI + FileModel file = new FileModel(sourceFile); + file.setNodeRef(fileNode.getId()); + restClient.withCoreAPI().usingNode(file).createNodeRendition(renditionId); + + Assert.assertEquals(Integer.valueOf(restClient.getStatusCode()).intValue(), HttpStatus.BAD_REQUEST.value(), + "Expected to see the rendition rejected. [" + sourceFile + ", " + renditionId + "] [source file, rendition ID] "); + } + + @DataProvider(name = "UnsupportedRenditionTestDataProvider") + protected Iterator unsupportedRenditionTestDataProvider() throws Exception + { + String renditionId = "pdf"; + + List toTest = new LinkedList<>(); + toTest.add(new Object[]{"quick/quick.png", renditionId}); + toTest.add(new Object[]{"quick/quick.gif", renditionId}); + toTest.add(new Object[]{"quick/quick.jpg", renditionId}); + toTest.add(new Object[]{"quick/quick.pdf", renditionId}); + + return toTest.iterator(); + } +} + diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/renditions/CreateRenditionTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/renditions/CreateRenditionTests.java new file mode 100644 index 0000000000..71451d90a5 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/renditions/CreateRenditionTests.java @@ -0,0 +1,101 @@ +package org.alfresco.rest.renditions; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.exception.JsonToModelConversionException; +import org.alfresco.rest.model.RestNodeModel; +import org.alfresco.utility.Utility; +import org.alfresco.utility.model.FileModel; +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.alfresco.utility.report.Bug; +import org.alfresco.utility.report.Bug.Status; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +/** + * Handles tests related to POST api-explorer/#!/renditions + * @author Cristina Axinte + * + */ +@Test(groups = {TestGroup.RENDITIONS}) +public class CreateRenditionTests extends RestTest +{ + private UserModel adminUser, user; + private SiteModel site; + private FileModel document; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + user = dataUser.createRandomTestUser(); + site = dataSite.usingUser(user).createPublicRandomSite(); + } + + @BeforeMethod(alwaysRun = true) + public void createDocument() throws Exception + { + document = dataContent.usingUser(user).usingSite(site).createContent(DocumentType.TEXT_PLAIN); + } + + @Bug(id = "REPO-2042", description = "Should fail only on MAC OS System and Linux", status = Status.FIXED ) + @TestRail(section = { TestGroup.REST_API, TestGroup.RENDITIONS }, executionType = ExecutionType.SANITY, + description = "Verify admin user creates rendition with Rest API and status code is 202") + @Test(groups = { TestGroup.REST_API, TestGroup.RENDITIONS, TestGroup.SANITY }) + public void adminCanCreateRenditionToExistingNode() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(adminUser).withCoreAPI().usingNode(document).createNodeRendition("pdf"); + restClient.assertStatusCodeIs(HttpStatus.ACCEPTED); + + restClient.withCoreAPI().usingNode(document).getNodeRenditionUntilIsCreated("pdf") + .assertThat().field("status").is("CREATED"); + } + + @Bug(id = "REPO-2042", description = "Should fail only on MAC OS System and Linux", status = Status.FIXED ) + @TestRail(section = { TestGroup.REST_API, TestGroup.RENDITIONS }, executionType = ExecutionType.REGRESSION, + description = "Verify user that created the document can also creates 'pdf' rendition for it with Rest API and status code is 202") + @Test(groups = { TestGroup.REST_API, TestGroup.RENDITIONS, TestGroup.REGRESSION }) + public void userThatCreatedFileCanCreatePdfRenditionForIt() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(user).withCoreAPI().usingNode(document).createNodeRendition("pdf"); + restClient.assertStatusCodeIs(HttpStatus.ACCEPTED); + + restClient.withCoreAPI().usingNode(document).getNodeRenditionUntilIsCreated("pdf") + .assertThat().field("status").is("CREATED"); + } + + @Bug(id = "REPO-2042", description = "Should fail only on MAC OS System and Linux", status = Status.FIXED ) + @TestRail(section = { TestGroup.REST_API, TestGroup.RENDITIONS }, executionType = ExecutionType.REGRESSION, + description = "Verify user that created the document can also creates 'doclib' rendition for it with Rest API and status code is 202") + @Test(groups = { TestGroup.REST_API, TestGroup.RENDITIONS, TestGroup.REGRESSION, TestGroup.NOT_SUPPORTED_BY_ATS }) + public void userThatCreatedFileCanCreateDoclibRenditionForIt() throws JsonToModelConversionException, Exception + { + FolderModel folder = dataContent.usingUser(user).usingSite(site).createFolder(); + restClient.authenticateUser(user) + .configureRequestSpec() + .addMultiPart("filedata", Utility.getResourceTestDataFile("my-file.tif")); + + RestNodeModel fileNode = restClient.authenticateUser(user).withCoreAPI().usingResource(folder).createNode(); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + document = new FileModel("my-file.tif"); + document.setCmisLocation(folder.getCmisLocation() + "/my-file.tif"); + document.setNodeRef(fileNode.getId()); + + restClient.authenticateUser(user).withCoreAPI().usingNode(document).createNodeRendition("doclib"); + restClient.assertStatusCodeIs(HttpStatus.ACCEPTED); + + // Renditions are async + Utility.sleep(500, 60000, () -> + { + restClient.withCoreAPI().usingNode(document).getNodeRenditionUntilIsCreated("doclib") + .assertThat().field("status").is("CREATED"); + }); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/renditions/GetRenditionTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/renditions/GetRenditionTests.java new file mode 100644 index 0000000000..297296151e --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/renditions/GetRenditionTests.java @@ -0,0 +1,157 @@ +package org.alfresco.rest.renditions; + +import static org.alfresco.utility.report.log.Step.STEP; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.RestResponse; +import org.alfresco.rest.model.RestNodeModel; +import org.alfresco.rest.model.RestRenditionInfoModel; +import org.alfresco.utility.Utility; +import org.alfresco.utility.model.FileModel; +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.alfresco.utility.report.Bug; +import org.alfresco.utility.report.Bug.Status; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Handles tests related to GET api-explorer/#!/renditions + * @author Cristina Axinte + * + */ +@Test(groups = {TestGroup.RENDITIONS}) +public class GetRenditionTests extends RestTest +{ + private UserModel user; + private SiteModel site; + private FileModel file1; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + user = dataUser.createRandomTestUser(); + site = dataSite.usingUser(user).createPublicRandomSite(); + file1 = dataContent.usingUser(user).usingSite(site).createContent(DocumentType.TEXT_PLAIN); + } + + @Bug(id = "REPO-2449", status = Status.FIXED) + @Test(groups = { TestGroup.REST_API, TestGroup.RENDITIONS, TestGroup.SANITY, TestGroup.NOT_SUPPORTED_BY_ATS }) + @TestRail(section = { TestGroup.REST_API, TestGroup.RENDITIONS }, executionType = ExecutionType.SANITY, + description = "Verify that ZIP document preview is rendered") + public void verifyPreviewOfZipFile() throws Exception + { + STEP("1. Create a folder in existing site"); + FolderModel folder = FolderModel.getRandomFolderModel(); + folder = dataContent.usingUser(user).usingSite(site).createFolder(folder); + + STEP("2. Upload a local ZIP file using RESTAPI"); + restClient.authenticateUser(user).configureRequestSpec().addMultiPart("filedata", Utility.getResourceTestDataFile("content-zip-test.zip")); + + RestNodeModel fileNode = restClient.authenticateUser(user).withCoreAPI().usingNode(folder).createNode(); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + FileModel file = new FileModel("content-zip-test.zip"); + file.setCmisLocation(folder.getCmisLocation() + "/content-zip-test.zip"); + file.setNodeRef(fileNode.getId()); + + STEP("3. Create preview of ZIP file using RESTAPI"); + restClient.withCoreAPI().usingNode(file).createNodeRendition("pdf"); + restClient.assertStatusCodeIs(HttpStatus.ACCEPTED); + + STEP("4. Verify preview of ZIP file is created using RESTAPI"); + RestRenditionInfoModel renditionInfo = restClient.withCoreAPI().usingNode(file).getNodeRenditionUntilIsCreated("pdf"); + restClient.assertStatusCodeIs(HttpStatus.OK); + renditionInfo.assertThat().field("status").is("CREATED"); + } + + @Bug(id = "REPO-2485", status = Status.FIXED) + @Test(groups = { TestGroup.REST_API, TestGroup.RENDITIONS, TestGroup.SANITY, TestGroup.NOT_SUPPORTED_BY_ATS }) + @TestRail(section = { TestGroup.REST_API, TestGroup.RENDITIONS }, executionType = ExecutionType.SANITY, + description = "Verify that ZIP document thumbnail is rendered") + public void verifyThumbnailOfZipFile() throws Exception + { + STEP("1. Create a folder in existing site"); + FolderModel folder = FolderModel.getRandomFolderModel(); + folder = dataContent.usingUser(user).usingSite(site).createFolder(folder); + + STEP("2. Upload a local ZIP file using RESTAPI"); + restClient.authenticateUser(user).configureRequestSpec().addMultiPart("filedata", Utility.getResourceTestDataFile("content-zip-test.zip")); + + RestNodeModel fileNode = restClient.authenticateUser(user).withCoreAPI().usingNode(folder).createNode(); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + FileModel file = new FileModel("content-zip-test.zip"); + file.setCmisLocation(folder.getCmisLocation() + "/content-zip-test.zip"); + file.setNodeRef(fileNode.getId()); + + STEP("3. Create thumbnail of ZIP file using RESTAPI"); + restClient.withCoreAPI().usingNode(file).createNodeRendition("doclib"); + restClient.assertStatusCodeIs(HttpStatus.ACCEPTED); + + STEP("4. Verify thumbnail of ZIP file is created and has content using RESTAPI"); + RestRenditionInfoModel renditionInfo = restClient.withCoreAPI().usingNode(file).getNodeRenditionUntilIsCreated("doclib"); + restClient.assertStatusCodeIs(HttpStatus.OK); + renditionInfo.assertThat().field("status").is("CREATED"); + renditionInfo.assertThat().field("content.sizeInBytes").isGreaterThan(120); + } + + /** + * Sanity test for the following endpoint: + * GET /nodes/{nodeId}/renditions/{renditionId}/content + * @throws Exception + */ + @Test(groups = { TestGroup.REST_API, TestGroup.RENDITIONS, TestGroup.SANITY, TestGroup.NOT_SUPPORTED_BY_ATS }) + @TestRail(section = { TestGroup.REST_API, TestGroup.RENDITIONS }, executionType = ExecutionType.SANITY, + description = "Verify that the rendition content can be downloaded using GET /nodes/{nodeId}/renditions/{renditionId}/content") + public void getRenditionContent() throws Exception + { + STEP("1. Create a folder in existing site"); + FolderModel folder = FolderModel.getRandomFolderModel(); + folder = dataContent.usingUser(user).usingSite(site).createFolder(folder); + + STEP("2. Upload a local txt file using RESTAPI"); + restClient.authenticateUser(user).configureRequestSpec().addMultiPart("filedata", Utility.getResourceTestDataFile("iso8859File.txt")); + + RestNodeModel fileNode = restClient.authenticateUser(user).withCoreAPI().usingNode(folder).createNode(); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + FileModel file = new FileModel("iso8859File.txt"); + file.setCmisLocation(folder.getCmisLocation() + "/iso8859File.txt"); + file.setNodeRef(fileNode.getId()); + + STEP("3. Create thumbnail of txt file using RESTAPI"); + restClient.withCoreAPI().usingNode(file).createNodeRendition("doclib"); + restClient.assertStatusCodeIs(HttpStatus.ACCEPTED); + + STEP("4. Verify thumbnail of txt file is created and has content using RESTAPI"); + RestResponse restResponse = restClient.withCoreAPI().usingNode(file).getNodeRenditionContentUntilIsCreated("doclib"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restClient.assertHeaderValueContains("Content-Type","image/png;charset=UTF-8"); + Assert.assertTrue(restResponse.getResponse().body().asInputStream().available() > 0); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.RENDITIONS, TestGroup.SANITY}) + @TestRail(section = {TestGroup.REST_API, TestGroup.RENDITIONS}, executionType = ExecutionType.SANITY, + description = "Verify the Range request header using GET /nodes/{nodeId}/renditions/{renditionId}/content") + public void getVerifyRangeRequestHeader() throws Exception + { + STEP("1. Create thumbnail on file"); + restClient.authenticateUser(user).withCoreAPI().usingNode(file1).createNodeRendition("pdf"); + restClient.assertStatusCodeIs(HttpStatus.ACCEPTED); + + STEP("2. Make GET rendition content using content-range header"); + Utility.sleep(1000, 30000, () -> { + restClient.configureRequestSpec().addHeader("content-range", "bytes=1-10"); + restClient.authenticateUser(user).withCoreAPI().usingNode(file1).getNodeRenditionContent("pdf"); + restClient.assertStatusCodeIs(HttpStatus.PARTIAL_CONTENT); + restClient.assertHeaderValueContains("content-range", "bytes 1-10"); + restClient.assertHeaderValueContains("content-length", String.valueOf(10)); + }); + } +} + diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/renditions/RenditionIntegrationTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/renditions/RenditionIntegrationTests.java new file mode 100644 index 0000000000..dc28448417 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/renditions/RenditionIntegrationTests.java @@ -0,0 +1,81 @@ +package org.alfresco.rest.renditions; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.RestResponse; +import org.alfresco.rest.model.RestNodeModel; +import org.alfresco.utility.Utility; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FolderModel; +import org.alfresco.utility.model.SiteModel; + +import org.alfresco.utility.model.UserModel; + +import org.springframework.http.HttpStatus; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; + +public abstract class RenditionIntegrationTests extends RestTest +{ + + protected UserModel user; + protected SiteModel site; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + user = dataUser.createRandomTestUser(); + site = dataSite.usingUser(user).createPublicRandomSite(); + } + + /** + * Check that a rendition can be created for the specified node id + * @param fileName + * @param nodeId + * @param renditionId + * @param expectedMimeType + * @throws Exception + */ + protected void checkRendition(String fileName, String nodeId, String renditionId, String expectedMimeType) throws Exception + { + FileModel file = new FileModel(); + file.setNodeRef(nodeId); + + // 1. Create a rendition of the file using RESTAPI + restClient.withCoreAPI().usingNode(file).createNodeRendition(renditionId); + Assert.assertEquals(Integer.valueOf(restClient.getStatusCode()).intValue(), HttpStatus.ACCEPTED.value(), + "Failed to submit a request for rendition. [" + fileName+ ", " + renditionId+"] [source file, rendition ID]. "); + + // 2. Verify that a rendition of the file is created and has content using RESTAPI + RestResponse restResponse = restClient.withCoreAPI().usingNode(file).getNodeRenditionContentUntilIsCreated(renditionId); + Assert.assertEquals(Integer.valueOf(restClient.getStatusCode()).intValue(), HttpStatus.OK.value(), + "Failed to produce rendition. [" + fileName+ ", " + renditionId+"] [source file, rendition ID] "); + + // 3. Check the returned content type + Assert.assertEquals(restClient.getResponseHeaders().getValue("Content-Type"), expectedMimeType+";charset=UTF-8", + "Rendition was created but it has the wrong Content-Type. [" + fileName+ ", " + renditionId + "] [source file, rendition ID]"); + + + Assert.assertTrue((restResponse.getResponse().body().asInputStream().available() > 0), + "Rendition was created but its content is empty. [" + fileName+ ", " + renditionId+"] [source file, rendition ID] "); + } + + /** + * Upload a file and return its node id + * @param sourceFile + * @return + * @throws Exception + */ + protected RestNodeModel uploadFile(String sourceFile) throws Exception + { + FolderModel folder = FolderModel.getRandomFolderModel(); + folder = dataContent.usingUser(user).usingSite(site).createFolder(folder); + restClient.authenticateUser(user).configureRequestSpec() + .addMultiPart("filedata", Utility.getResourceTestDataFile(sourceFile)); + RestNodeModel fileNode = restClient.authenticateUser(user).withCoreAPI().usingNode(folder).createNode(); + + Assert.assertEquals(Integer.valueOf(restClient.getStatusCode()).intValue(), HttpStatus.CREATED.value(), + "Failed to created a node for rendition tests using file " + sourceFile); + + return fileNode; + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/sharedLinks/GetSharedLinksFullTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/sharedLinks/GetSharedLinksFullTests.java new file mode 100644 index 0000000000..c2e3627a61 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/sharedLinks/GetSharedLinksFullTests.java @@ -0,0 +1,75 @@ +package org.alfresco.rest.sharedLinks; + +import javax.json.Json; +import javax.json.JsonObject; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestNodeModel; +import org.alfresco.rest.model.RestSharedLinksModelCollection; +import org.alfresco.utility.exception.DataPreparationException; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class GetSharedLinksFullTests extends RestTest +{ + private SiteModel privateSite; + private UserModel adminUser, userModel; + protected FileModel file; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws DataPreparationException + { + adminUser = dataUser.getAdminUser(); + userModel = dataUser.createRandomTestUser(); + privateSite = dataSite.usingUser(adminUser).createPrivateRandomSite(); + } + + @Bug(id="REPO-2365") + @TestRail(section = { TestGroup.REST_API, + TestGroup.SHAREDLINKS }, executionType = ExecutionType.REGRESSION, description = "Verify that a user with permission can get allowableOperations on sharedLinks") + @Test(groups = { TestGroup.REST_API, TestGroup.SHAREDLINKS, TestGroup.REGRESSION }) + public void getSharedLinksWithAllowableOperations() throws Exception + { + file = dataContent.usingUser(adminUser).usingSite(privateSite).createContent(DocumentType.TEXT_PLAIN); + + /* + * { "permissions": { "isInheritanceEnabled": true, "locallySet": { "authorityId": "userModel.getUsername()", + * "name": "SiteConsumer", "accessStatus":"ALLOWED" } } } + */ + JsonObject userPermission = Json.createObjectBuilder().add("permissions", + Json.createObjectBuilder().add("isInheritanceEnabled", true).add("locallySet", Json.createObjectBuilder() + .add("authorityId", userModel.getUsername()).add("name", "SiteConsumer").add("accessStatus", "ALLOWED"))) + .build(); + String putBody = userPermission.toString(); + restClient.authenticateUser(adminUser).withCoreAPI().usingNode(file).updateNode(putBody); + restClient.assertStatusCodeIs(HttpStatus.OK); + restClient.authenticateUser(adminUser).withCoreAPI().usingSharedLinks().createSharedLink(file); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + // verify that the permision exists + RestNodeModel permissionsRequest = restClient.authenticateUser(userModel).withCoreAPI().usingNode(file) + .usingParams("include=permissions").getNode(); + permissionsRequest.assertThat().field("permissions.locallySet.authorityId").is("[" + userModel.getUsername() + "]"); + + // because the sharedLink take time to be created, we may need to wait for solr to index it. + int numberOfTries = 0; + RestSharedLinksModelCollection operationsRequest; + do + { + Thread.sleep(1000); + numberOfTries++; + operationsRequest = restClient.authenticateUser(userModel).withCoreAPI().usingSharedLinks().usingParams("include=allowableOperations").getSharedLinks(); + restClient.assertStatusCodeIs(HttpStatus.OK); + } while (operationsRequest.getPagination().getCount() == 0 && numberOfTries < 15); + operationsRequest.getPagination().assertThat().field("count").is(1); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/sharedLinks/SharedLinksSanityTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/sharedLinks/SharedLinksSanityTests.java new file mode 100644 index 0000000000..31cf778eb4 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/sharedLinks/SharedLinksSanityTests.java @@ -0,0 +1,270 @@ +package org.alfresco.rest.sharedLinks; + +import javax.json.Json; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestRenditionInfoModel; +import org.alfresco.rest.model.RestRenditionInfoModelCollection; +import org.alfresco.rest.model.RestSharedLinksModel; +import org.alfresco.rest.model.RestSharedLinksModelCollection; +import org.alfresco.utility.Utility; +import org.alfresco.utility.model.FileModel; +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.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Class includes Sanity tests for the shared-links api. Detailed tests would be covered in the alfresco-remote-api test project + * + * @author meenal bhave + */ +public class SharedLinksSanityTests extends RestTest +{ + private UserModel adminUser; + private UserModel testUser1; + + private SiteModel siteModel1; + + private FolderModel folder1; + + private FileModel file1; + private FileModel file2; + private FileModel file3; + private FileModel file4; + private FileModel file5; + private FileModel file6; + private FileModel file7; + private FileModel file8; + + private RestSharedLinksModel sharedLink1; + private RestSharedLinksModel sharedLink2; + private RestSharedLinksModel sharedLink3; + private RestSharedLinksModel sharedLink4; + private RestSharedLinksModel sharedLink5; + private RestSharedLinksModel sharedLink6; + private RestSharedLinksModel sharedLink7; + private RestSharedLinksModel sharedLink8; + private RestRenditionInfoModel nodeRenditionInfo; + + private RestSharedLinksModelCollection sharedLinksCollection; + private RestRenditionInfoModelCollection nodeRenditionInfoCollection; + + private String expiryDate = "2027-03-23T23:00:00.000+0000"; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + + adminUser = dataUser.getAdminUser(); + restClient.authenticateUser(adminUser); + + // Create Standard User + testUser1 = dataUser.usingUser(adminUser).createRandomTestUser(); + + // Create Site + siteModel1 = dataSite.usingUser(testUser1).createPublicRandomSite(); + + folder1 = dataContent.usingUser(adminUser).usingSite(siteModel1).createFolder(); + + file1 = dataContent.usingUser(adminUser).usingResource(folder1).createContent(DocumentType.TEXT_PLAIN); + file2 = dataContent.usingUser(adminUser).usingResource(folder1).createContent(DocumentType.TEXT_PLAIN); + file3 = dataContent.usingUser(adminUser).usingResource(folder1).createContent(DocumentType.TEXT_PLAIN); + file4 = dataContent.usingUser(adminUser).usingResource(folder1).createContent(DocumentType.TEXT_PLAIN); + file5 = dataContent.usingUser(adminUser).usingResource(folder1).createContent(DocumentType.TEXT_PLAIN); + file7 = dataContent.usingUser(adminUser).usingResource(folder1).createContent(DocumentType.TEXT_PLAIN); + file8 = dataContent.usingUser(adminUser).usingResource(folder1).createContent(DocumentType.TEXT_PLAIN); + // Create file6 based on existing resource + FileModel newFile = FileModel.getFileModelBasedOnTestDataFile("sampleContent.txt"); + newFile.setName("sampleContent.txt"); + file6 = dataContent.usingUser(adminUser).usingResource(folder1).createContent(newFile); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.SHAREDLINKS }, executionType = ExecutionType.SANITY, description = "Verify create sharedLinks without Path") + @Test(groups = { TestGroup.REST_API, TestGroup.SHAREDLINKS, TestGroup.SANITY }) + public void testCreateAndGetSharedLinks() throws Exception + { + // Post without includePath + sharedLink1 = restClient.authenticateUser(testUser1).withCoreAPI().usingSharedLinks().createSharedLink(file1); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.onResponse().assertThat().body("entry.nodeId", org.hamcrest.Matchers.equalTo(file1.getNodeRefWithoutVersion())); + restClient.onResponse().assertThat().body("entry.name", org.hamcrest.Matchers.equalTo(file1.getName())); + restClient.onResponse().assertThat().body("entry.id", org.hamcrest.Matchers.equalTo(sharedLink1.getId())); + restClient.onResponse().assertThat().body("entry.path", org.hamcrest.Matchers.nullValue()); + + // Same Checks above using sharedLink methods: GET sharedLink: without includePath + Assert.assertEquals(sharedLink1.getNodeId(), file1.getNodeRefWithoutVersion()); + Assert.assertEquals(sharedLink1.getName(), file1.getName()); + Assert.assertNull(sharedLink1.getPath(), "Path is expected to be null for noauth api: Response shows: " + sharedLink1.toJson()); + + // Get without includePath + restClient.authenticateUser(testUser1).withCoreAPI().usingSharedLinks().getSharedLink(sharedLink1); + restClient.onResponse().assertThat().body("entry.nodeId", org.hamcrest.Matchers.equalTo(file1.getNodeRefWithoutVersion())); + restClient.onResponse().assertThat().body("entry.name", org.hamcrest.Matchers.equalTo(file1.getName())); + restClient.onResponse().assertThat().body("entry.id", org.hamcrest.Matchers.equalTo(sharedLink1.getId())); + restClient.onResponse().assertThat().body("entry.path", org.hamcrest.Matchers.nullValue()); + + /* + * Get all shared-links while allowing indexing to complete and check + * that the created shared-link is displayed + */ + Utility.sleep(1000, 30000, () -> + { + sharedLinksCollection = restClient.withCoreAPI().usingSharedLinks().getSharedLinks(); + restClient.assertStatusCodeIs(HttpStatus.OK); + sharedLinksCollection.assertThat().entriesListContains("id", sharedLink1.getId()).and() + .entriesListContains("nodeId", sharedLink1.getNodeId()); + }); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.SHAREDLINKS }, executionType = ExecutionType.REGRESSION, description = "Verify create sharedLinks with Path") + @Test(groups = { TestGroup.REST_API, TestGroup.SHAREDLINKS, TestGroup.REGRESSION }) + public void testCreateAndGetSharedLinksWithInclude() throws Exception + { + // Post with includePath + sharedLink2 = restClient.authenticateUser(testUser1).withCoreAPI().includePath().usingSharedLinks().createSharedLink(file2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.onResponse().assertThat().body("entry.nodeId", org.hamcrest.Matchers.equalTo(file2.getNodeRefWithoutVersion())); + restClient.onResponse().assertThat().body("entry.name", org.hamcrest.Matchers.equalTo(file2.getName())); + restClient.onResponse().assertThat().body("entry.id", org.hamcrest.Matchers.equalTo(sharedLink2.getId())); + restClient.onResponse().assertThat().body("entry.path", org.hamcrest.Matchers.notNullValue()); + + // Same Checks above using sharedLink methods: POST sharedLink: includePath + Assert.assertEquals(sharedLink2.getNodeId(), file2.getNodeRefWithoutVersion()); + Assert.assertEquals(sharedLink2.getName(), file2.getName()); + Assert.assertNotNull(sharedLink2.getPath(), "Path not expected to be null for noauth api: Response shows: " + sharedLink1.toJson()); + + // Get with includePath + restClient.authenticateUser(testUser1).withCoreAPI().usingSharedLinks().getSharedLink(sharedLink2); + restClient.onResponse().assertThat().body("entry.nodeId", org.hamcrest.Matchers.equalTo(file2.getNodeRefWithoutVersion())); + restClient.onResponse().assertThat().body("entry.name", org.hamcrest.Matchers.equalTo(file2.getName())); + restClient.onResponse().assertThat().body("entry.id", org.hamcrest.Matchers.equalTo(sharedLink2.getId())); + // Verify that path is null since includePath is not supported for this noAuth api + restClient.onResponse().assertThat().body("entry.path", org.hamcrest.Matchers.nullValue()); + + // Get: noAuth with includePath + sharedLink2 = restClient.withCoreAPI().usingSharedLinks().getSharedLink(sharedLink2); + restClient.onResponse().assertThat().body("entry.nodeId", org.hamcrest.Matchers.equalTo(file2.getNodeRefWithoutVersion())); + restClient.onResponse().assertThat().body("entry.name", org.hamcrest.Matchers.equalTo(file2.getName())); + restClient.onResponse().assertThat().body("entry.id", org.hamcrest.Matchers.equalTo(sharedLink2.getId())); + // Verify that path is null since includePath is not supported for this noAuth api + restClient.onResponse().assertThat().body("entry.path", org.hamcrest.Matchers.nullValue()); + + // Same Checks above using sharedLink methods: GET sharedLink: noAuth + Assert.assertEquals(sharedLink2.getNodeId(), file2.getNodeRefWithoutVersion()); + Assert.assertEquals(sharedLink2.getName(), file2.getName()); + Assert.assertNull(sharedLink2.getPath(), "Path is expected to be null for noauth api: Response shows: " + sharedLink2.toJson()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.SHAREDLINKS }, executionType = ExecutionType.SANITY, description = "Verify delete sharedLinks with and without Path") + @Test(groups = { TestGroup.REST_API, TestGroup.SHAREDLINKS, TestGroup.SANITY}) + public void testDeleteSharedLinks() throws Exception + { + sharedLink3 = restClient.authenticateUser(testUser1).withCoreAPI().usingSharedLinks().createSharedLink(file3); + restClient.authenticateUser(testUser1).withCoreAPI().usingSharedLinks().deleteSharedLink(sharedLink3); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + sharedLink4 = restClient.authenticateUser(testUser1).withCoreAPI().usingSharedLinks().createSharedLink(file4); + restClient.authenticateUser(testUser1).withCoreAPI().includePath().usingSharedLinks().deleteSharedLink(sharedLink4); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.SHAREDLINKS }, executionType = ExecutionType.SANITY, description = "Sanity tests for GET {sharedId}/content and POST {sharedId}/email endpoints") + @Test(groups = { TestGroup.REST_API, TestGroup.SHAREDLINKS, TestGroup.SANITY }) + public void testGetSharedLinkContentAndPostEmail() throws Exception + { + // Create shared-link + sharedLink6 = restClient.authenticateUser(testUser1).withCoreAPI().usingSharedLinks().createSharedLink(file6); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + // Make GET {sharedId}/content and check file content + restClient.withCoreAPI().usingSharedLinks().getSharedLinkContent(sharedLink6); + restClient.assertStatusCodeIs(HttpStatus.OK); + restClient.assertHeaderValueContains("Content-Disposition", file6.getName()); + restClient.onResponse().getResponse().body().asString().contains("Sample text."); + + // Make POST {sharedId}/email to send email with created shared-link + String postBody = Json.createObjectBuilder().add("client", "share") + .add("recipientEmails", "john.doe@acme.com") + .build().toString(); + restClient.withCoreAPI().usingSharedLinks().sendSharedLinkEmail(sharedLink6, postBody); + restClient.assertStatusCodeIs(HttpStatus.ACCEPTED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.SHAREDLINKS }, executionType = ExecutionType.REGRESSION, description = "Verify get sharedLink/content and get/renditions") + @Test(groups = { TestGroup.REST_API, TestGroup.SHAREDLINKS, TestGroup.REGRESSION, TestGroup.RENDITIONS }) + public void testCreateWithExpiryDateAndGetSharedLinkRendition() throws Exception + { + sharedLink5 = restClient.authenticateUser(testUser1).withCoreAPI().includePath().usingSharedLinks().createSharedLinkWithExpiryDate(file5, expiryDate); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + Assert.assertEquals(sharedLink5.getExpiresAt(), expiryDate); + Assert.assertNotNull(sharedLink5.getPath(), "Path not expected to be null: Response shows: " + sharedLink5.toJson()); + + restClient.authenticateUser(testUser1).withCoreAPI().usingSharedLinks().getSharedLinkRenditions(sharedLink5); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.SHAREDLINKS }, executionType = ExecutionType.SANITY, description = "Sanity tests for GET /renditions, GET /renditions/{renditionId} and GET /renditions/{renditionId}/content endpoints") + @Test(groups = { TestGroup.REST_API, TestGroup.SHAREDLINKS, TestGroup.SANITY, TestGroup.RENDITIONS }) + public void testGetSharedLinkRendition() throws Exception + { + sharedLink7 = restClient.authenticateUser(testUser1).withCoreAPI().usingSharedLinks().createSharedLink(file7); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.withCoreAPI().usingNode(file7).createNodeRenditionIfNotExists("doclib"); + restClient.withCoreAPI().usingNode(file7).createNodeRendition("pdf"); + restClient.assertStatusCodeIs(HttpStatus.ACCEPTED); + + // GET /renditions: wait until all renditions are created and GET all entries + Utility.sleep(1000, 50000, () -> + { + nodeRenditionInfoCollection = restClient.authenticateUser(testUser1).withCoreAPI().usingSharedLinks().getSharedLinkRenditions(sharedLink7); + restClient.assertStatusCodeIs(HttpStatus.OK); + + nodeRenditionInfoCollection.assertThat().entriesListCountIs(2); + nodeRenditionInfoCollection.getEntryByIndex(0).assertThat().field("id").is("doclib").and() + .field("status").is("CREATED"); + nodeRenditionInfoCollection.getEntryByIndex(1).assertThat().field("id").is("pdf").and() + .field("status").is("CREATED"); + }); + + // GET /renditions/{renditionId}: get specific rendition information for the file with shared link + nodeRenditionInfo = restClient.authenticateUser(testUser1).withCoreAPI().usingSharedLinks().getSharedLinkRendition(sharedLink7, "pdf"); + restClient.assertStatusCodeIs(HttpStatus.OK); + nodeRenditionInfo.assertThat().field("id").is("pdf").and() + .field("status").is("CREATED"); + + // GET /renditions/{renditionId}/content: get the rendition content for file with shared link + restClient.authenticateUser(testUser1).withCoreAPI().usingSharedLinks().getSharedLinkRenditionContent(sharedLink7, "pdf"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restClient.assertHeaderValueContains("Content-Type","application/pdf;charset=UTF-8"); + Assert.assertTrue(restClient.onResponse().getResponse().body().asInputStream().available() > 0); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.SHAREDLINKS }, executionType = ExecutionType.SANITY, description = "Sanity tests for Range reuest header on GET shared-links/{sharedId}/renditions/{renditionId}/content endpoints") + @Test(groups = { TestGroup.REST_API, TestGroup.SHAREDLINKS, TestGroup.SANITY, TestGroup.RENDITIONS }) + public void testGetVerifyRangeReguestOnSharedLinks() throws Exception + { + sharedLink8 = restClient.authenticateUser(testUser1).withCoreAPI().usingSharedLinks().createSharedLink(file8); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.withCoreAPI().usingNode(file8).createNodeRendition("pdf"); + restClient.assertStatusCodeIs(HttpStatus.ACCEPTED); + + // GET /renditions/{renditionId}/content: get the Range request header for file with shared links endpoints. + Utility.sleep(1000, 30000, () -> + { + restClient.configureRequestSpec().addHeader("content-range", "bytes=1-10"); + restClient.authenticateUser(testUser1).withCoreAPI().usingSharedLinks().getSharedLinkRenditionContent(sharedLink8, "pdf"); + restClient.assertStatusCodeIs(HttpStatus.PARTIAL_CONTENT); + restClient.assertHeaderValueContains("Content-Type","application/pdf;charset=UTF-8"); + restClient.assertHeaderValueContains("content-range", "bytes 1-10"); + }); + } +} \ No newline at end of file diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/GetSiteTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/GetSiteTests.java new file mode 100644 index 0000000000..4a89cd3013 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/GetSiteTests.java @@ -0,0 +1,361 @@ +package org.alfresco.rest.sites; + +import org.alfresco.dataprep.SiteService; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.core.RestResponse; +import org.alfresco.rest.model.*; +import org.alfresco.utility.constants.ContainerName; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; +import org.alfresco.utility.exception.DataPreparationException; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.util.List; + +import static org.hamcrest.CoreMatchers.equalTo; + +/** + * @author iulia.cojocea + */ + +public class GetSiteTests extends RestTest +{ + private UserModel adminUserModel; + private ListUserWithRoles usersWithRoles; + private UserModel userModel, privateSiteConsumer; + private SiteModel publicSite, privateSite, moderatedSite; + private RestSiteModel restSiteModel; + + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws DataPreparationException + { + adminUserModel = dataUser.getAdminUser(); + restClient.authenticateUser(adminUserModel); + publicSite = dataSite.usingUser(adminUserModel).createPublicRandomSite(); + usersWithRoles = dataUser.addUsersWithRolesToSite(publicSite, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor); + + userModel = dataUser.createRandomTestUser(); + privateSiteConsumer = dataUser.createRandomTestUser(); + + privateSite = dataSite.usingAdmin().createPrivateRandomSite(); + moderatedSite = dataSite.usingAdmin().createModeratedRandomSite(); + dataUser.addUserToSite(privateSiteConsumer, privateSite, UserRole.SiteConsumer); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.SANITY, + description = "Verify user with Manager role gets site information and gets status code OK (200)") + public void getSiteWithManagerRole() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingSite(publicSite) + .getSite() + .and().field("id").is(publicSite.getId()) + .and().field("title").is(publicSite.getTitle()); + + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with Collaborator role gets site information and gets status code OK (200)") + public void getSiteWithCollaboratorRole() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .withCoreAPI().usingSite(publicSite) + .getSite() + .and().field("id").is(publicSite.getId()) + .and().field("title").is(publicSite.getTitle()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with Contributor role gets site information and gets status code OK (200)") + public void getSiteWithContributorRole() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .withCoreAPI().usingSite(publicSite) + .getSite() + .and().field("id").is(publicSite.getId()) + .and().field("title").is(publicSite.getTitle()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with Consumer role gets site information and gets status code OK (200)") + public void getSiteWithConsumerRole() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .withCoreAPI().usingSite(publicSite) + .getSite() + .and().field("id").is(publicSite.getId()) + .and().field("title").is(publicSite.getTitle()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with admin role gets site information and gets status code OK (200)") + public void getSiteWithAdminRole() throws Exception + { + restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingSite(publicSite) + .getSite() + .and().field("id").is(publicSite.getId()) + .and().field("title").is(publicSite.getTitle()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.SANITY, + description = "Failed authentication get site call returns status code 401") +// @Bug(id="MNT-16904", description = "It fails only on environment with tenants") + public void unauthenticatedUserIsNotAuthorizedToRetrieveSite() throws Exception + { + UserModel unauthenticatedManager = dataUser.createRandomTestUser(); + unauthenticatedManager.setPassword("user wrong password"); + dataUser.addUserToSite(unauthenticatedManager, publicSite, UserRole.SiteManager); + restClient.authenticateUser(unauthenticatedManager).withParams("maxItems=10000") + .withCoreAPI() + .getSites(); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify invalid request returns status code 404 if siteId does not exist") + public void checkStatusCodeForNonExistentSiteId() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite("NonExistentSiteId").getSite(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "NonExistentSiteId")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify user gets all public and moderated sites if an empty siteId is provided") + public void checkStatusCodeForEmptySiteId() throws Exception + { + restClient.authenticateUser(userModel).withCoreAPI(); + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "sites/{siteId}", ""); + RestSiteModelsCollection sites = restClient.processModels(RestSiteModelsCollection.class, request); + restClient.assertStatusCodeIs(HttpStatus.OK); + sites.assertThat().entriesListIsNotEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if any user gets public site details and status code is 200") + public void getPublicSiteByNotASiteMember() throws Exception + { + restSiteModel = restClient.authenticateUser(userModel).withCoreAPI() + .usingSite(publicSite).getSite(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restSiteModel.assertThat().field("visibility").is(publicSite.getVisibility()) + .and().field("id").is(publicSite.getId()) + .and().field("description").is(publicSite.getDescription()) + .and().field("title").is(publicSite.getTitle()) + .and().field("guid").isNotEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if any user gets moderated site details and status code is 200") + public void getModeratedSiteByNotASiteMember() throws Exception + { + restSiteModel = restClient.authenticateUser(userModel).withCoreAPI() + .usingSite(moderatedSite).getSite(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restSiteModel.assertThat().field("visibility").is(moderatedSite.getVisibility()) + .and().field("id").is(moderatedSite.getId()) + .and().field("description").is(moderatedSite.getDescription()) + .and().field("title").is(moderatedSite.getTitle()) + .and().field("guid").isNotEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if member of a private site gets that site details and status code is 200") + public void getPrivateSiteBySiteMember() throws Exception + { + restSiteModel = restClient.authenticateUser(privateSiteConsumer).withCoreAPI() + .usingSite(privateSite).getSite(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restSiteModel.assertThat().field("visibility").is(privateSite.getVisibility()) + .and().field("id").is(privateSite.getId()) + .and().field("description").is(privateSite.getDescription()) + .and().field("title").is(privateSite.getTitle()) + .and().field("guid").isNotEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if user that is not member of a private site does not get that site details and status code is 200") + public void getPrivateSiteByNotASiteMember() throws Exception + { + restSiteModel = restClient.authenticateUser(userModel).withCoreAPI() + .usingSite(privateSite).getSite(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, privateSite.getTitle())) + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }, expectedExceptions = java.lang.AssertionError.class) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Check that properties parameter is applied (guid field is mandatory, thus assertion error is expected)") + public void checkThatPropertiesParameterIsApplied() throws Exception + { + restSiteModel = restClient.authenticateUser(adminUserModel).withParams("properties=id, visibility").withCoreAPI().usingSite(publicSite).getSite(); + restSiteModel.assertThat().field("id").is(publicSite.getId()).and().field("visibility").is(SiteService.Visibility.PUBLIC.toString()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION } ) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Check that properties parameter is applied") + public void checkThatPropertiesParameterIsAppliedPositiveTest() throws Exception + { + restSiteModel = restClient.authenticateUser(adminUserModel).withParams("properties=id,guid,title,visibility").withCoreAPI().usingSite(publicSite).getSite(); + restSiteModel.assertThat().field("id").is(publicSite.getId()).and().field("visibility").is(SiteService.Visibility.PUBLIC.toString()) + .and().field("description").isNull() + .and().field("role").isNull(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION } ) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Delete site then get site details") + public void deleteSiteThenGetSiteDetails() throws Exception + { + SiteModel newSite = dataSite.usingAdmin().createPublicRandomSite(); + dataSite.deleteSite(newSite); + restSiteModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(newSite).getSite(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, newSite.getId())) + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION } ) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Delete site then get site details") + public void updateSiteVisibilityToPrivateThenGetSite() throws Exception + { + SiteModel newSite = dataSite.usingAdmin().createPublicRandomSite(); + restSiteModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(newSite).getSite(); + restClient.assertStatusCodeIs(HttpStatus.OK); + dataSite.updateSiteVisibility(newSite, SiteService.Visibility.PRIVATE); + restSiteModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(newSite).getSite(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restSiteModel.assertThat().field("id").is(newSite.getId()) + .and().field("visibility").is(SiteService.Visibility.PRIVATE.toString()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION } ) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Check that relations parameter is applied for containers") + public void checkThatRelationsParameterIsAppliedForContainers() throws Exception + { + List jsonObjects = restClient.authenticateUser(adminUserModel) + .withParams("relations=containers").withCoreAPI().usingSite(publicSite).getSiteWithRelations(); + + RestSiteModel siteModel = (RestSiteModel) jsonObjects.get(0); + RestSiteContainerModelsCollection containers = (RestSiteContainerModelsCollection) jsonObjects.get(1); + + siteModel.assertThat().field("visibility").is(publicSite.getVisibility()) + .and().field("id").is(publicSite.getId()) + .and().field("description").is(publicSite.getDescription()) + .and().field("title").is(publicSite.getTitle()) + .and().field("preset").is("site-dashboard") + .and().field("guid").isNotEmpty(); + + containers.assertThat().entriesListCountIs(1) + .and().entriesListContains("folderId", ContainerName.documentLibrary.toString()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION } ) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Check that relations parameter is applied for members") + public void checkThatRelationsParameterIsAppliedForMembers() throws Exception + { + SiteModel publicRandomSite = dataSite.usingUser(adminUserModel).createPublicRandomSite(); + List jsonObjects = restClient.authenticateUser(adminUserModel) + .withParams("relations=members").withCoreAPI().usingSite(publicRandomSite).getSiteWithRelations(); + + RestSiteModel siteModel = (RestSiteModel) jsonObjects.get(0); + RestSiteMemberModelsCollection siteMembers = (RestSiteMemberModelsCollection) jsonObjects.get(1); + + siteModel.assertThat().field("visibility").is(publicRandomSite.getVisibility()) + .and().field("id").is(publicRandomSite.getId()) + .and().field("description").is(publicRandomSite.getDescription()) + .and().field("title").is(publicRandomSite.getTitle()) + .and().field("preset").is("site-dashboard") + .and().field("guid").isNotEmpty(); + + siteMembers.assertThat().entriesListCountIs(1) + .assertThat().entriesListContains("id", adminUserModel.getUsername()) + .assertThat().entriesListContains("role", UserRole.SiteManager.toString()); + siteMembers.getOneRandomEntry().onModel().assertThat().field("person.firstName").is("Administrator") + .and().field("person.id").is("admin"); + } + + @Test(groups="demo") + public void checkThatRelationsParameterIsAppliedForMembersCustom() + { + /*1 - select API endpoint*/ + restClient.withCoreAPI(); + + /*2 - define request */ + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "sites/{siteId}?{parameters}", publicSite.getId(), "relations=members"); + + /*3 - send request */ + RestResponse response = restClient.authenticateUser(adminUserModel).process(request); + + /*assertions */ + response.assertThat().body("entry.id", equalTo(publicSite.getId())); + response.assertThat().body("relations.members.list.entries.entry[0].role", equalTo("SiteManager")); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION } ) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Check that relations parameter is applied for containers and members") + public void checkThatRelationsParameterIsAppliedForContainersAndMembers() throws Exception + { + SiteModel publicRandomSite = dataSite.usingUser(adminUserModel).createPublicRandomSite(); + List jsonObjects = restClient.authenticateUser(adminUserModel) + .withParams("relations=containers,members").withCoreAPI().usingSite(publicRandomSite).getSiteWithRelations(); + + RestSiteModel siteModel = (RestSiteModel) jsonObjects.get(0); + RestSiteContainerModelsCollection containers = (RestSiteContainerModelsCollection) jsonObjects.get(1); + RestSiteMemberModelsCollection siteMembers = (RestSiteMemberModelsCollection) jsonObjects.get(2); + + siteModel.assertThat().field("visibility").is(publicRandomSite.getVisibility()) + .and().field("id").is(publicRandomSite.getId()) + .and().field("description").is(publicRandomSite.getDescription()) + .and().field("title").is(publicRandomSite.getTitle()) + .and().field("preset").is("site-dashboard") + .and().field("guid").isNotEmpty(); + + containers.assertThat().entriesListCountIs(1) + .and().entriesListContains("folderId", ContainerName.documentLibrary.toString()); + + siteMembers.assertThat().entriesListCountIs(1) + .assertThat().entriesListContains("id", adminUserModel.getUsername()) + .assertThat().entriesListContains("role", UserRole.SiteManager.toString()); + siteMembers.getOneRandomEntry().onModel().assertThat().field("person.firstName").is("Administrator") + .and().field("person.id").is("admin"); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/GetSitesTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/GetSitesTests.java new file mode 100644 index 0000000000..65acb9fd0a --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/GetSitesTests.java @@ -0,0 +1,483 @@ +package org.alfresco.rest.sites; + +import org.alfresco.dataprep.SiteService; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.*; +import org.alfresco.utility.constants.ContainerName; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; +import org.alfresco.utility.data.RandomData; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.util.List; + +/** + * @author iulia.cojocea + */ +public class GetSitesTests extends RestTest +{ + private UserModel adminUser; + private UserModel lastPrivateSiteManager; + private ListUserWithRoles usersWithRoles; + private SiteModel siteModel; + private UserModel regularUser, privateSiteManager, privateSiteConsumer; + private SiteModel firstPublicSite, firstPrivateSite, firstModeratedSite, deletedSite; + private SiteModel lastPublicSite, lastPrivateSite, lastModeratedSite; + private RestSiteModelsCollection sites; + private String name; + + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + regularUser = dataUser.createRandomTestUser(); + lastPrivateSiteManager = dataUser.createRandomTestUser(); + privateSiteManager = dataUser.createRandomTestUser(); + privateSiteConsumer = dataUser.createRandomTestUser(); + + siteModel = new SiteModel(RandomData.getRandomName("0-PublicSite")); + firstPublicSite = dataSite.usingAdmin().createSite(siteModel); + siteModel = new SiteModel(RandomData.getRandomName("0-PrivateSite"), SiteService.Visibility.PRIVATE); + firstPrivateSite = dataSite.usingAdmin().createSite(siteModel); + siteModel = new SiteModel(RandomData.getRandomName("0-ModeratedSite"), SiteService.Visibility.MODERATED); + firstModeratedSite = dataSite.usingAdmin().createSite(siteModel); + dataUser.addUserToSite(privateSiteManager, firstPrivateSite, UserRole.SiteManager); + dataUser.addUserToSite(privateSiteConsumer, firstPrivateSite, UserRole.SiteConsumer); + deletedSite = dataSite.usingAdmin().createPublicRandomSite(); + + name = RandomData.getRandomName("ZZZZZZZZZ-PublicSite"); + lastPublicSite = dataSite.usingAdmin().createSite(new SiteModel(SiteService.Visibility.PUBLIC, "guid", name, name, name)); + lastPrivateSite = dataSite.usingAdmin().createSite(new SiteModel(RandomData.getRandomName("ZZZZZZZZZ-PrivateSite"), SiteService.Visibility.PRIVATE)); + lastModeratedSite = dataSite.usingAdmin().createSite(new SiteModel(RandomData.getRandomName("ZZZZZZZZZ-ModeratedSite"), SiteService.Visibility.MODERATED)); + + adminUser = dataUser.getAdminUser(); + siteModel = dataSite.usingAdmin().createPublicRandomSite(); + usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel,UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor); + dataUser.addUserToSite(lastPrivateSiteManager, lastPrivateSite, UserRole.SiteManager); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.SANITY, + description = "Verify user with Manager role gets sites information and gets status code OK (200)") + public void managerIsAbleToRetrieveSites() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withParams("maxItems=10000") + .withCoreAPI().getSites() + .assertThat().entriesListIsNotEmpty() + .assertThat().entriesListContains("id", siteModel.getId()) + .and().paginationExist(); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with Collaborator role gets sites information and gets status code OK (200)") + public void collaboratorIsAbleToRetrieveSites() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withParams("maxItems=10000") + .withCoreAPI().getSites().assertThat().entriesListIsNotEmpty() + .assertThat().entriesListContains("id", siteModel.getId()) + .and().paginationExist(); + + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with Contributor role gets sites information and gets status code OK (200)") + public void contributorIsAbleToRetrieveSites() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).withParams("maxItems=10000") + .withCoreAPI().getSites() + .assertThat().entriesListIsNotEmpty() + .assertThat().entriesListContains("id", siteModel.getId()) + .and().paginationExist(); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with Consumer role gets sites information and gets status code OK (200)") + public void consumerIsAbleToRetrieveSites() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withParams("maxItems=10000") + .withCoreAPI().getSites() + .assertThat().entriesListIsNotEmpty() + .assertThat().entriesListContains("id", siteModel.getId()) + .and().paginationExist(); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with Admin user gets sites information and gets status code OK (200)") + public void adminUserIsAbleToRetrieveSites() throws Exception + { + restClient.authenticateUser(adminUser).withParams("maxItems=10000") + .withCoreAPI().getSites() + .assertThat().entriesListIsNotEmpty() + .assertThat().entriesListContains("id", siteModel.getId()) + .and().paginationExist(); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.SANITY, + description = "Failed authentication get sites call returns status code 401") +// @Bug(id="MNT-16904", description = "It fails only on environment with tenants") + public void unauthenticatedUserIsNotAuthorizedToRetrieveSites() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + UserModel userModel = dataUser.createRandomTestUser(); + userModel.setPassword("user wrong password"); + dataUser.addUserToSite(userModel, siteModel, UserRole.SiteManager); + restClient.authenticateUser(userModel).withParams("maxItems=1") + .withCoreAPI().getSites(); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if get sites request returns status code 400 when invalid maxItems parameter is used") + public void getSitesWithInvalidMaxItems() throws Exception + { + restClient.authenticateUser(regularUser).withParams("maxItems=0=09") + .withCoreAPI().getSites(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.INVALID_MAXITEMS, "0=09")); + + restClient.withParams("maxItems=A") + .withCoreAPI().getSites(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.INVALID_MAXITEMS, "A")); + + restClient.withParams("maxItems=0") + .withCoreAPI().getSites(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if get sites request returns status code 400 when invalid skipCount parameter is used") + public void getSitesWithInvalidSkipCount() throws Exception + { + restClient.authenticateUser(regularUser).withParams("skipCount=A") + .withCoreAPI().getSites(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.INVALID_SKIPCOUNT, "A")); + + restClient.authenticateUser(regularUser).withParams("skipCount=-1") + .withCoreAPI().getSites(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(RestErrorModel.NEGATIVE_VALUES_SKIPCOUNT); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if User gets sites ordered by title ascending and status code is 200") + public void getSitesOrderedByTitleASC() throws Exception + { + sites = restClient.authenticateUser(privateSiteManager).withParams("orderBy=title ASC") + .withCoreAPI().getSites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + sites.assertThat().entriesListIsNotEmpty(); + List sitesList = sites.getEntries(); + sitesList.get(0).onModel().assertThat().field("title").is(firstModeratedSite.getTitle()); + sitesList.get(1).onModel().assertThat().field("title").is(firstPrivateSite.getTitle()); + sitesList.get(2).onModel().assertThat().field("title").is(firstPublicSite.getTitle()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if a regular user gets all public and moderated sites and status code is 200") + public void regularUserGetsOnlyPublicAndModeratedSites() throws Exception + { + sites = restClient.authenticateUser(regularUser).withParams("maxItems=5000") + .withCoreAPI().getSites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + sites.assertThat().entriesListContains("title", firstPublicSite.getTitle()) + .and().entriesListContains("title", firstModeratedSite.getTitle()) + .and().entriesListDoesNotContain("title", firstPrivateSite.getTitle()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if a member of a private site gets the private site, all public sites and all moderated sites. Verify if status code is 200") + public void privateSiteMemberGetsSitesVisibleForHim() throws Exception + { + sites = restClient.authenticateUser(privateSiteConsumer).withParams("maxItems=5000") + .withCoreAPI().getSites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + sites.assertThat().entriesListContains("title", firstPublicSite.getTitle()) + .and().entriesListContains("title", firstModeratedSite.getTitle()) + .and().entriesListContains("title", firstPrivateSite.getTitle()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if a site is not retrieved anymore after deletion and status code is 200") + public void checkDeletedSiteIsNotRetrieved() throws Exception + { + sites = restClient.authenticateUser(regularUser).withParams("maxItems=5000").withCoreAPI().getSites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + sites.assertThat().entriesListContains("title", deletedSite.getTitle()); + + dataSite.usingAdmin().deleteSite(deletedSite); + + sites = restClient.withParams("maxItems=5000").withCoreAPI().getSites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + sites.assertThat().entriesListDoesNotContain("title", deletedSite.getTitle()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION}) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if User gets sites ordered by title descending and status code is 200") + public void getSitesOrderedByTitleDESC() throws Exception + { + int totalItems = restClient.authenticateUser(lastPrivateSiteManager).withCoreAPI().getSites().getPagination().getTotalItems(); + sites = restClient.authenticateUser(lastPrivateSiteManager).withParams(String.format("maxItems=%s&orderBy=title DESC", totalItems)) + .withCoreAPI().getSites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + sites.assertThat().entriesListIsNotEmpty(); + List sitesList = sites.getEntries(); + sitesList.get(0).onModel().assertThat().field("title").is(lastPublicSite.getTitle()); + sitesList.get(1).onModel().assertThat().field("title").is(lastPrivateSite.getTitle()); + sitesList.get(2).onModel().assertThat().field("title").is(lastModeratedSite.getTitle()); + sitesList.get(sitesList.size()-1).onModel().assertThat().field("title").is(firstModeratedSite.getTitle()); + } + + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION}) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if User gets sites ordered by id ascending and status code is 200") + public void getSitesOrderedByIdASC() throws Exception + { + int totalItems = restClient.authenticateUser(lastPrivateSiteManager).withCoreAPI().getSites().getPagination().getTotalItems(); + sites = restClient.authenticateUser(lastPrivateSiteManager).withParams(String.format("maxItems=%s&orderBy=id ASC", totalItems)) + .withCoreAPI().getSites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + sites.assertThat().entriesListIsNotEmpty(); + List sitesList = sites.getEntries(); + sitesList.get(sitesList.size()-1).onModel().assertThat().field("id").is(lastPublicSite.getId()); + sitesList.get(sitesList.size()-2).onModel().assertThat().field("id").is(lastPrivateSite.getId()); + sitesList.get(sitesList.size()-3).onModel().assertThat().field("id").is(lastModeratedSite.getId()); + sitesList.get(0).onModel().assertThat().field("id").is(firstModeratedSite.getId()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION}) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify pagination") + public void checkPagination() throws Exception + { + sites = restClient.authenticateUser(regularUser).withCoreAPI().getSites(); + sites.getPagination().assertThat() + .field("totalItems").isNotEmpty().and() + .field("maxItems").is("100").and() + .field("hasMoreItems").is((sites.getPagination().getTotalItems() > sites.getPagination().getMaxItems()) ? "true" : "false").and() + .field("skipCount").is("0").and() + .field("count").is((sites.getPagination().isHasMoreItems()) ? sites.getPagination().getMaxItems() : sites.getPagination().getTotalItems()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION}) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify user can get only first two sites and status code is 200") + public void getFirstTwoSites() throws Exception + { + sites = restClient.authenticateUser(regularUser).withParams(String.format("maxItems=%s&orderBy=title ASC", 2)) + .withCoreAPI().getSites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + sites.getPagination().assertThat().field("maxItems").is("2").and().field("count").is("2"); + sites.assertThat().entriesListCountIs(2).and().entriesListDoesNotContain(firstPublicSite.getId()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION}) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify user can get sites using high skipCount parameter and status code is 200") + public void getSitesUsingHighSkipCount() throws Exception + { + RestSiteModelsCollection allSites = restClient.authenticateUser(regularUser).withCoreAPI().getSites(); + sites = restClient.withParams("skipCount=100").withCoreAPI().getSites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + sites.assertThat().paginationField("skipCount").is("100"); + if(allSites.getPagination().getTotalItems() > 100) + sites.assertThat().entriesListIsNotEmpty(); + else + sites.assertThat().entriesListIsEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION}) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify user can not get sites using zero maxItems parameter and status code is 400") + public void userCanNotGetSitesUsingZeroMaxItems() throws Exception + { + sites = restClient.authenticateUser(regularUser).withParams("maxItems=0").withCoreAPI().getSites(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsErrorKey(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS) + .containsSummary(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION}) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify that getSites request applies valid properties param and status code is 200") + public void getSitesRequestWithValidPropertiesParam() throws Exception + { + sites = restClient.authenticateUser(regularUser).withParams("properties=id").withCoreAPI().getSites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + sites.assertThat().entriesListDoesNotContain("description") + .assertThat().entriesListDoesNotContain("title") + .assertThat().entriesListDoesNotContain("visibility") + .assertThat().entriesListDoesNotContain("guid") + .assertThat().entriesListContains("id"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION}) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify pagination when skipCount and MaxItems are used") + public void checkPaginationWithSkipCountAndMaxItems() throws Exception + { + sites = restClient.authenticateUser(regularUser).withParams("skipCount=10&maxItems=110").withCoreAPI().getSites(); + sites.getPagination().assertThat() + .field("totalItems").isNotEmpty().and() + .field("maxItems").is("110").and() + .field("hasMoreItems").is((sites.getPagination().getTotalItems() - sites.getPagination().getSkipCount() > sites.getPagination().getMaxItems())?"true":"false").and() + .field("skipCount").is("10").and() + .field("count").is((sites.getPagination().isHasMoreItems()) ? sites.getPagination().getMaxItems() + : sites.getPagination().getTotalItems() - sites.getPagination().getSkipCount()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION}) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if User gets sites ordered by id ascending and status code is 200") + public void getSitesOrderedByTitleASCAndVisibilityASC() throws Exception + { + SiteModel secondPublicSite = dataSite.usingAdmin().createSite( + new SiteModel(SiteService.Visibility.PUBLIC, "guid", name+"A", name+"A", name)); + SiteModel thirdPublicSite = dataSite.usingAdmin().createSite( + new SiteModel(SiteService.Visibility.PUBLIC, "guid", name+"B", name+"B", name)); + + int totalItems = restClient.authenticateUser(regularUser).withCoreAPI().getSites().getPagination().getTotalItems(); + sites = restClient.authenticateUser(regularUser).withParams(String.format("maxItems=%s&orderBy=title ASC&orderBy=description ASC", totalItems)) + .withCoreAPI().getSites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + sites.assertThat().entriesListIsNotEmpty(); + List sitesList = sites.getEntries(); + sitesList.get(sitesList.size()-1).onModel().assertThat().field("title").is(thirdPublicSite.getTitle()); + sitesList.get(sitesList.size()-2).onModel().assertThat().field("title").is(secondPublicSite.getTitle()); + + dataSite.usingAdmin().deleteSite(secondPublicSite); + dataSite.usingAdmin().deleteSite(thirdPublicSite); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION} ) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Check that relations parameter is applied for containers") + public void checkThatRelationsParameterIsAppliedForContainers() throws Exception + { + List> jsonObjects = restClient.authenticateUser(adminUser) + .withParams("relations=containers").withCoreAPI().usingSite(lastPublicSite).getSitesWithRelations(); + + List siteObjects = jsonObjects.get(0); + for (int i = 0; i < siteObjects.size(); i++) + { + RestSiteModel siteModel = (RestSiteModel) siteObjects.get(i); + siteModel.assertThat().field("visibility").isNotEmpty() + .and().field("id").isNotEmpty() + .and().field("title").isNotEmpty() + .and().field("preset").is("site-dashboard") + .and().field("guid").isNotEmpty(); + } + + List containerObjects = jsonObjects.get(1); + for (int i = 0; i < containerObjects.size(); i++) + { + RestSiteContainerModelsCollection containers = (RestSiteContainerModelsCollection) containerObjects.get(i); + containers.assertThat().entriesListIsNotEmpty().and().entriesListContains("folderId", ContainerName.documentLibrary.toString()); + } + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION} ) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Check that relations parameter is applied for members") + public void checkThatRelationsParameterIsAppliedForMembers() throws Exception + { + List> jsonObjects = restClient.authenticateUser(adminUser) + .withParams("relations=members").withCoreAPI().usingSite(lastPublicSite).getSitesWithRelations(); + + List siteObjects = jsonObjects.get(0); + for (int i = 0; i < siteObjects.size(); i++) + { + RestSiteModel siteModel = (RestSiteModel) siteObjects.get(i); + siteModel.assertThat().field("visibility").isNotEmpty() + .and().field("id").isNotEmpty() + .and().field("title").isNotEmpty() + .and().field("preset").is("site-dashboard") + .and().field("guid").isNotEmpty(); + } + + List memberObjects = jsonObjects.get(1); + for (int i = 0; i < memberObjects.size(); i++) + { + RestSiteMemberModelsCollection siteMembers = (RestSiteMemberModelsCollection) memberObjects.get(i); + siteMembers.assertThat().entriesListIsNotEmpty().assertThat().entriesListContains("id").assertThat().entriesListContains("role", UserRole.SiteManager.toString()); + siteMembers.getOneRandomEntry().onModel().assertThat().field("person.firstName").isNotEmpty().and().field("person.id").isNotEmpty(); + } + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION} ) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Check that relations parameter is applied for members and containers") + public void checkThatRelationsParameterIsAppliedForMembersAndContainers() throws Exception + { + List> jsonObjects = restClient.authenticateUser(adminUser) + .withParams("relations=containers,members").withCoreAPI().usingSite(lastPublicSite).getSitesWithRelations(); + + List siteObjects = jsonObjects.get(0); + for (int i = 0; i < siteObjects.size(); i++) + { + RestSiteModel siteModel = (RestSiteModel) siteObjects.get(i); + siteModel.assertThat().field("visibility").isNotEmpty() + .and().field("id").isNotEmpty() + .and().field("title").isNotEmpty() + .and().field("preset").is("site-dashboard") + .and().field("guid").isNotEmpty(); + } + + List containerObjects = jsonObjects.get(1); + for (int i = 0; i < containerObjects.size(); i++) + { + RestSiteContainerModelsCollection containers = (RestSiteContainerModelsCollection) containerObjects.get(i); + containers.assertThat().entriesListIsNotEmpty().and().entriesListContains("folderId", ContainerName.documentLibrary.toString()); + } + + List memberObjects = jsonObjects.get(2); + for (int i = 0; i < memberObjects.size(); i++) + { + RestSiteMemberModelsCollection siteMembers = (RestSiteMemberModelsCollection) memberObjects.get(i); + siteMembers.assertThat().entriesListIsNotEmpty().assertThat().entriesListContains("id").assertThat().entriesListContains("role", UserRole.SiteManager.toString()); + siteMembers.getOneRandomEntry().onModel().assertThat().field("person.firstName").isNotEmpty().and().field("person.id").isNotEmpty(); + } + } + + @AfterClass(alwaysRun=true) + public void cleanup() throws Exception + { + dataSite.usingAdmin().deleteSite(firstModeratedSite); + dataSite.usingAdmin().deleteSite(firstPrivateSite); + dataSite.usingAdmin().deleteSite(firstPublicSite); + + dataSite.usingAdmin().deleteSite(lastPublicSite); + dataSite.usingAdmin().deleteSite(lastPrivateSite); + dataSite.usingAdmin().deleteSite(lastModeratedSite); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/SitesTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/SitesTests.java new file mode 100644 index 0000000000..9b40f70821 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/SitesTests.java @@ -0,0 +1,36 @@ +package org.alfresco.rest.sites; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestSiteModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.Test; + +/** + * Handles tests related to api-explorer/#!/sites + * + * @author Ana Bozianu + */ +public class SitesTests extends RestTest +{ + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.SANITY, description = "Tests the creation of a site") + public void testCreateSite() throws Exception + { + SiteModel site = RestSiteModel.getRandomSiteModel(); + + RestSiteModel createdSite = restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingSite(site).createSite(); + + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + createdSite.assertThat().field("id").is(site.getId()) + .assertThat().field("title").is(site.getTitle()) + .assertThat().field("description").is(site.getDescription()) + .assertThat().field("visibility").is(site.getVisibility()); + } + +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/containers/GetSiteContainerTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/containers/GetSiteContainerTests.java new file mode 100644 index 0000000000..fee1aef75d --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/containers/GetSiteContainerTests.java @@ -0,0 +1,303 @@ +package org.alfresco.rest.sites.containers; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestSiteContainerModel; +import org.alfresco.utility.constants.ContainerName; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; +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.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.commons.lang3.RandomStringUtils; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * @author iulia.cojocea + */ +public class GetSiteContainerTests extends RestTest +{ + private UserModel adminUserModel; + private SiteModel publicSiteModel, moderatedSiteModel, privateSiteModel, adminPrivateSiteModel; + private ListUserWithRoles usersWithRoles; + private RestSiteContainerModel siteContainerModel; + private UserModel testUser; + + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + adminUserModel = dataUser.getAdminUser(); + testUser = dataUser.createRandomTestUser(); + + publicSiteModel = dataSite.usingAdmin().createPublicRandomSite(); + moderatedSiteModel = dataSite.usingUser(testUser).createModeratedRandomSite(); + privateSiteModel = dataSite.usingUser(testUser).createPrivateRandomSite(); + adminPrivateSiteModel = dataSite.usingAdmin().createPrivateRandomSite(); + + usersWithRoles = dataUser.addUsersWithRolesToSite(publicSiteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, + UserRole.SiteContributor); + + dataLink.usingAdmin().usingSite(publicSiteModel).createRandomLink(); + + dataLink.usingAdmin().usingSite(adminPrivateSiteModel).createRandomLink(); + + dataLink.usingUser(testUser).usingSite(privateSiteModel).createRandomLink(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.SANITY, + description = "Verify user with Manager role gets site container and gets status code OK (200)") + public void getSiteContainerWithManagerRole() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + siteContainerModel = restClient.withCoreAPI().usingSite(publicSiteModel).getSiteContainers().getOneRandomEntry(); + restClient.withCoreAPI().usingSite(publicSiteModel).getSiteContainer(siteContainerModel.onModel()) + .assertThat().field("id").is(siteContainerModel.onModel().getId()) + .and().field("folderId").is(siteContainerModel.onModel().getFolderId()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with Collaborator role gets site container and gets status code OK (200)") + public void getSiteContainerWithCollaboratorRole() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); + siteContainerModel = restClient.withCoreAPI().usingSite(publicSiteModel).getSiteContainers().getOneRandomEntry(); + restClient.withCoreAPI().usingSite(publicSiteModel).getSiteContainer(siteContainerModel.onModel()) + .and().field("id").is(siteContainerModel.onModel().getId()) + .and().field("folderId").is(siteContainerModel.onModel().getFolderId()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with Contributor role gets site container and gets status code OK (200)") + public void getSiteContainerWithContributorRole() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); + siteContainerModel = restClient.withCoreAPI().usingSite(publicSiteModel).getSiteContainers().getOneRandomEntry(); + restClient.withCoreAPI().usingSite(publicSiteModel).getSiteContainer(siteContainerModel.onModel()) + .assertThat().field("id").is(siteContainerModel.onModel().getId()) + .and().field("folderId").is(siteContainerModel.onModel().getFolderId()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with Consumer role gets site container and gets status code OK (200)") + public void getSiteContainerWithConsumerRole() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)); + siteContainerModel = restClient.withCoreAPI().usingSite(publicSiteModel).getSiteContainers().getOneRandomEntry(); + restClient.withCoreAPI().usingSite(publicSiteModel).getSiteContainer(siteContainerModel.onModel()) + .assertThat().field("id").is(siteContainerModel.onModel().getId()) + .and().field("folderId").is(siteContainerModel.onModel().getFolderId()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with admin user gets site container and gets status code OK (200)") + public void getSiteContainerWithAdminUser() throws Exception + { + restClient.authenticateUser(adminUserModel); + siteContainerModel = restClient.withCoreAPI().usingSite(publicSiteModel).getSiteContainers().getOneRandomEntry(); + restClient.withCoreAPI().usingSite(publicSiteModel).getSiteContainer(siteContainerModel.onModel()) + .assertThat().field("id").is(siteContainerModel.onModel().getId()) + .and().field("folderId").is(siteContainerModel.onModel().getFolderId()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.SANITY, + description = "Failed authentication get site container call returns status code 401") + public void unauthenticatedUserIsNotAuthorizedToRetrieveSiteContainer() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + siteContainerModel = restClient.withCoreAPI().usingSite(publicSiteModel).getSiteContainers().getOneRandomEntry(); + UserModel userModel = dataUser.createRandomTestUser(); + userModel.setPassword("user wrong password"); + dataUser.addUserToSite(userModel, publicSiteModel, UserRole.SiteManager); + restClient.authenticateUser(userModel) + .withCoreAPI().usingSite(publicSiteModel).getSiteContainer(siteContainerModel.onModel()); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if get container request returns status code 400 when site doesn't exist") + public void getContainerWithNonExistentSite() throws Exception + { + restClient.authenticateUser(testUser) + .withCoreAPI().usingSite("NonExistentSiteId").getSiteContainer(ContainerName.links.toString()); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, "NonExistentSiteId", ContainerName.links.toString())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if get container request returns status code 400 when container item doesn't exist") + public void getContainerWithNonExistentItem() throws Exception + { + restClient.authenticateUser(testUser) + .withCoreAPI().usingSite(publicSiteModel).getSiteContainer("NonExistentFolder"); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, publicSiteModel.getId(), "NonExistentFolder")); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify regular user can get container for public site and request returns status 200") + public void getContainerForPublicSite() throws Exception + { + restClient.authenticateUser(testUser) + .withCoreAPI().usingSite(publicSiteModel).getSiteContainer(ContainerName.links.toString()) + .assertThat().field("folderId").is(ContainerName.links.toString()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify manager is able to get container for his private site and request returns status 200") + public void getContainerForPrivateSite() throws Exception + { + restClient.authenticateUser(testUser) + .withCoreAPI().usingSite(privateSiteModel).getSiteContainer(ContainerName.links.toString()) + .assertThat().field("folderId").is(ContainerName.links.toString()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify get container request returns status 200 for moderated site") + public void getContainerForModeratedSite() throws Exception + { + restClient.authenticateUser(testUser) + .withCoreAPI().usingSite(moderatedSiteModel).getSiteContainer(ContainerName.documentLibrary.toString()) + .assertThat().field("folderId").is(ContainerName.documentLibrary.toString()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if get container request with properties parameter returns status code 200 and parameter is applied") + public void getContainerUsingPropertiesParameter() throws Exception + { + restClient.authenticateUser(testUser) + .withCoreAPI().usingSite(publicSiteModel).usingParams("properties=id").getSiteContainer(ContainerName.links.toString()) + .assertThat().fieldsCount().is(1) + .and().field("id").isNotEmpty() + .and().field("folderId").isNull(); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if get container request for a container that does not belong to site returns status code 404") + public void getContainerThatDoesNotBelongToSite() throws Exception + { + restClient.authenticateUser(testUser) + .withCoreAPI().usingSite(moderatedSiteModel).getSiteContainer(ContainerName.links.toString()); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsErrorKey(RestErrorModel.RELATIONSHIP_NOT_FOUND_ERRORKEY) + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, moderatedSiteModel.getId(), ContainerName.links.toString())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if get container request for empty siteId returns status code 404") + public void getContainerForEmptySiteId() throws Exception + { + restClient.authenticateUser(testUser) + .withCoreAPI().usingSite("").getSiteContainer(ContainerName.links.toString()); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsErrorKey(RestErrorModel.RELATIONSHIP_NOT_FOUND_ERRORKEY) + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, "", ContainerName.links.toString())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if get container request for empty container returns status code 200 and the list of containers") + public void getContainerForEmptyContainer() throws Exception + { + restClient.authenticateUser(testUser) + .withCoreAPI().usingSite(moderatedSiteModel).getSiteContainer(""); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if get container with name containing special chars returns status code 404") + public void getContainerWithNameContainingSpecialChars() throws Exception + { + String containerSpecialName = RandomStringUtils.randomAlphabetic(2) + "~!%40%23%24%25%5E%26*()_%2B%5B%5D%7B%7D%7C%5C%3B%27%3A%22%2C.%2F%3C%3E"; + + restClient.authenticateUser(testUser) + .withCoreAPI().usingSite(publicSiteModel).getSiteContainer(containerSpecialName); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsErrorKey(RestErrorModel.RELATIONSHIP_NOT_FOUND_ERRORKEY) + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, publicSiteModel.getId(), containerSpecialName)) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if admin can get container request for a private site created by another user and status code is 200") + public void adminCanGetContainerForPrivateSiteCreatedByUser() throws Exception + { + restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingSite(privateSiteModel).getSiteContainer(ContainerName.links.toString()) + .assertThat().field("folderId").is(ContainerName.links.toString()) + .and().field("id").isNotEmpty(); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if user cannot get container request for a private site created by admin and status code is 404") + public void userCannotGetContainerForPrivateSiteCreatedByAdmin() throws Exception + { + restClient.authenticateUser(testUser) + .withCoreAPI().usingSite(adminPrivateSiteModel).getSiteContainer(ContainerName.links.toString()); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsErrorKey(RestErrorModel.RELATIONSHIP_NOT_FOUND_ERRORKEY) + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, adminPrivateSiteModel.getId(), ContainerName.links.toString())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if get container request for a deleted container returns status code is 404") + public void getContainerThatWasDeleted() throws Exception + { + restClient.authenticateUser(testUser) + .withCoreAPI().usingSite(privateSiteModel).getSiteContainer(ContainerName.links.toString()) + .assertThat().field("folderId").is(ContainerName.links.toString()); + restClient.assertStatusCodeIs(HttpStatus.OK); + + //use dataprep for delete 'links' container + FolderModel folder= new FolderModel("links"); + folder.setCmisLocation(String.format("/Sites/%s/%s", privateSiteModel.getId(), ContainerName.links.toString())); + dataContent.deleteTree(folder); + + restClient.authenticateUser(testUser) + .withCoreAPI().usingSite(privateSiteModel).getSiteContainer(ContainerName.links.toString()); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsErrorKey(RestErrorModel.RELATIONSHIP_NOT_FOUND_ERRORKEY) + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, privateSiteModel.getId(), ContainerName.links.toString())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/containers/GetSiteContainersTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/containers/GetSiteContainersTests.java new file mode 100644 index 0000000000..0d731d40e4 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/containers/GetSiteContainersTests.java @@ -0,0 +1,380 @@ +package org.alfresco.rest.sites.containers; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestSiteContainerModelsCollection; +import org.alfresco.utility.constants.ContainerName; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * @author iulia.cojocea + */ +public class GetSiteContainersTests extends RestTest +{ + private UserModel adminUserModel; + private SiteModel publicSiteModel, publicSiteWithContainers; + private SiteModel moderatedSiteModel, privateSiteModel; + private ListUserWithRoles publicSiteUsers; + private ListUserWithRoles publicSiteWithContainersUsers; + private RestSiteContainerModelsCollection restSiteContainers; + private int totalItems; + + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + adminUserModel = dataUser.getAdminUser(); + publicSiteModel = dataSite.usingAdmin().createPublicRandomSite(); + publicSiteWithContainers = dataSite.usingAdmin().createPublicRandomSite(); + moderatedSiteModel = dataSite.usingAdmin().createModeratedRandomSite(); + privateSiteModel = dataSite.usingAdmin().createPrivateRandomSite(); + + publicSiteUsers = dataUser.addUsersWithRolesToSite(publicSiteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor); + + publicSiteWithContainersUsers = dataUser + .addUsersWithRolesToSite(publicSiteWithContainers, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, + UserRole.SiteContributor); + + dataLink.usingAdmin().usingSite(publicSiteWithContainers).createRandomLink(); + + dataLink.usingAdmin().usingSite(moderatedSiteModel).createRandomLink(); + + dataLink.usingAdmin().usingSite(privateSiteModel).createRandomLink(); + + restSiteContainers = restClient.authenticateUser(publicSiteWithContainersUsers.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingSite(publicSiteWithContainers).getSiteContainers(); + totalItems = restSiteContainers.getPagination().getTotalItems(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.SANITY, + description = "Verify user with Manager role gets site containers and gets status code OK (200)") + public void getSiteContainersWithManagerRole() throws Exception + { + restClient.authenticateUser(publicSiteUsers.getOneUserWithRole(UserRole.SiteManager)); + restClient.withCoreAPI().usingSite(publicSiteModel).getSiteContainers() + .assertThat().entriesListIsNotEmpty() + .assertThat().paginationExist() + .and().paginationField("count").isNot("0"); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with Collaborator role gets site containers and gets status code OK (200)") + public void getSiteContainersWithCollaboratorRole() throws Exception + { + restClient.authenticateUser(publicSiteUsers.getOneUserWithRole(UserRole.SiteCollaborator)); + restClient.withCoreAPI().usingSite(publicSiteModel).getSiteContainers() + .assertThat().entriesListIsNotEmpty() + .assertThat().paginationExist() + .and().paginationField("count").isNot("0"); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with Contributor role gets site containers and gets status code OK (200)") + public void getSiteContainersWithContributorRole() throws Exception + { + restClient.authenticateUser(publicSiteUsers.getOneUserWithRole(UserRole.SiteContributor)); + restClient.withCoreAPI().usingSite(publicSiteModel).getSiteContainers() + .assertThat().entriesListIsNotEmpty() + .assertThat().paginationExist() + .and().paginationField("count").isNot("0"); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with Consumer role gets site containers and gets status code OK (200)") + public void getSiteContainersWithConsumerRole() throws Exception + { + restClient.authenticateUser(publicSiteUsers.getOneUserWithRole(UserRole.SiteConsumer)); + restClient.withCoreAPI().usingSite(publicSiteModel).getSiteContainers() + .assertThat().entriesListIsNotEmpty() + .assertThat().paginationExist() + .and().paginationField("count").isNot("0"); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with Admin user gets site containers information and gets status code OK (200)") + public void getSiteContainersWithAdminUser() throws Exception + { + restClient.authenticateUser(adminUserModel); + restClient.withCoreAPI().usingSite(publicSiteModel).getSiteContainers() + .assertThat().entriesListIsNotEmpty() + .assertThat().paginationExist() + .and().paginationField("count").isNot("0"); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.SANITY, + description = "Failed authentication get site containers call returns status code 401 with Manager role") +// @Bug(id="MNT-16904", description = "It fails only on environment with tenants") + public void unauthenticatedUserIsNotAuthorizedToRetrieveSiteContainers() throws Exception + { + UserModel userModel = dataUser.createRandomTestUser(); + userModel.setPassword("user wrong password"); + dataUser.addUserToSite(userModel, publicSiteModel, UserRole.SiteManager); + restClient.authenticateUser(userModel) + .withCoreAPI().usingSite(publicSiteModel).getSiteContainers(); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if get site container request returns status code 200 with valid maxItems parameter") + public void getContainersWithValidMaxItems() throws Exception + { + restClient.authenticateUser(publicSiteWithContainersUsers.getOneUserWithRole(UserRole.SiteManager)) + .withParams("maxItems=5") + .withCoreAPI().usingSite(publicSiteWithContainers).getSiteContainers() + .assertThat().entriesListCountIs(2) + .and().entriesListContains("folderId" , ContainerName.documentLibrary.toString()) + .and().entriesListContains("folderId", ContainerName.links.toString()); + restClient.assertStatusCodeIs(HttpStatus.OK); + + restClient.withParams("maxItems=1") + .withCoreAPI().usingSite(publicSiteWithContainers).getSiteContainers() + .assertThat().entriesListCountIs(1); + + restClient.withParams("maxItems=3") + .withCoreAPI().usingSite(publicSiteModel).getSiteContainers() + .assertThat().entriesListCountIs(1) + .and().entriesListContains("folderId", ContainerName.documentLibrary.toString()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if get site container request returns status code 400 when invalid maxItems parameter is used") + public void getContainersWithMaxItemsZero () throws Exception + { + restClient.authenticateUser(publicSiteUsers.getOneUserWithRole(UserRole.SiteManager)) + .withParams("maxItems=0") + .withCoreAPI().usingSite(publicSiteModel).getSiteContainers(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary("Only positive values supported for maxItems"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if get site container request returns status code 400 when invalid maxItems parameter is used") + public void getContainersWithMaxItemsCharacter () throws Exception + { + restClient.authenticateUser(publicSiteUsers.getOneUserWithRole(UserRole.SiteCollaborator)) + .withParams("maxItems=test") + .withCoreAPI().usingSite(publicSiteModel).getSiteContainers(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.INVALID_MAXITEMS, "test")); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if get site container request returns status code 200 when maxItems parameter starts with multiple zero") + public void getContainersWithMaxItemsMultipleZero () throws Exception + { + restClient.authenticateUser(publicSiteWithContainersUsers.getOneUserWithRole(UserRole.SiteCollaborator)) + .withParams("maxItems=000007") + .withCoreAPI().usingSite(publicSiteWithContainers).getSiteContainers() + .assertThat().entriesListCountIs(2); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if get site containers request returns status code 200 when valid skipCount parameter is used") + public void getSiteContainersWithValidSkipCount() throws Exception + { + restClient.authenticateUser(publicSiteUsers.getOneUserWithRole(UserRole.SiteManager)).withParams("skipCount=1") + .withCoreAPI().usingSite(publicSiteModel).getSiteContainers() + .assertThat().entriesListCountIs(0); + restClient.assertStatusCodeIs(HttpStatus.OK); + + restClient.authenticateUser(publicSiteWithContainersUsers.getOneUserWithRole(UserRole.SiteCollaborator)).withParams("skipCount=1") + .withCoreAPI().usingSite(publicSiteWithContainers).getSiteContainers() + .assertThat().entriesListCountIs(1); + restClient.assertStatusCodeIs(HttpStatus.OK); + + restClient.authenticateUser(publicSiteWithContainersUsers.getOneUserWithRole(UserRole.SiteConsumer)).withParams("skipCount=2") + .withCoreAPI().usingSite(publicSiteWithContainers).getSiteContainers() + .assertThat().entriesListCountIs(0); + restClient.assertStatusCodeIs(HttpStatus.OK); + + restClient.authenticateUser(publicSiteWithContainersUsers.getOneUserWithRole(UserRole.SiteCollaborator)).withParams("skipCount=0") + .withCoreAPI().usingSite(publicSiteWithContainers).getSiteContainers() + .assertThat().entriesListCountIs(2); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if get site containers request returns status code 400 when invalid skipCount parameter is used") + public void getSiteContainersWithSkipCountCharacter() throws Exception + { + restClient.authenticateUser(publicSiteUsers.getOneUserWithRole(UserRole.SiteCollaborator)).withParams("skipCount=abc") + .withCoreAPI().usingSite(publicSiteModel).getSiteContainers(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.INVALID_SKIPCOUNT, "abc")); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if get site containers request returns status code 200 when skipCount parameter starts with multiple zero") + public void getSiteContainersWithSkipCountMultipleZero() throws Exception + { + restClient.authenticateUser(publicSiteUsers.getOneUserWithRole(UserRole.SiteCollaborator)).withParams("skipCount=00002") + .withCoreAPI().usingSite(publicSiteWithContainers).getSiteContainers() + .assertThat().entriesListCountIs(0); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if get site containers request returns status code 400 when site doesn't exist") + public void getSiteContainersWithNonExistentSite() throws Exception + { + restClient.authenticateUser(publicSiteUsers.getOneUserWithRole(UserRole.SiteCollaborator)) + .withCoreAPI().usingSite("NonExistentSiteId").getSiteContainers(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "NonExistentSiteId")); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify get site containers request returns status 200 for private site") + public void getSiteContainersForPrivateSite() throws Exception + { + restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingSite(privateSiteModel).getSiteContainers() + .assertThat().entriesListCountIs(2); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify get site containers request returns status 200 for moderated site") + public void getSiteContainersForModeratedSite() throws Exception + { + restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingSite(moderatedSiteModel).getSiteContainers() + .assertThat().entriesListCountIs(2); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify get site containers request returns status 200 for several containers") + public void getSiteContainersForSeveralItems() throws Exception + { + restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingSite(publicSiteWithContainers).getSiteContainers() + .assertThat().entriesListCountIs(2) + .and().entriesListContains("folderId" ,ContainerName.documentLibrary.toString()) + .and().entriesListContains("folderId", ContainerName.links.toString()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify get site containers request returns status 200 for one container") + public void getSiteContainersWithOneItem() throws Exception + { + restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingSite(publicSiteModel).getSiteContainers() + .assertThat().entriesListCountIs(1) + .and().entriesListContains("folderId" ,ContainerName.documentLibrary.toString()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if get site container request with properties parameter applied returns status code 200") + public void getSiteContainersUsingPropertiesParameter() throws Exception + { + restClient.authenticateUser(publicSiteWithContainersUsers.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingSite(publicSiteWithContainers).usingParams("properties=folderId").getSiteContainers() + .assertThat().entriesListCountIs(2) + .and().entriesListContains("folderId", ContainerName.documentLibrary.toString()) + .and().entriesListContains("folderId", ContainerName.links.toString()) + .and().entriesListDoesNotContain("id"); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if get site container request for a container that is not empty returns status code 200") + public void getSiteContainersThatIsNotEmpty() throws Exception + { + restClient.authenticateUser(publicSiteWithContainersUsers.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingSite(publicSiteWithContainers).getSiteContainers() + .assertThat().entriesListCountIs(2) + .and().entriesListContains("folderId", ContainerName.documentLibrary.toString()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if get site containers request returns status code 200 when first container is skipped") + public void getSiteContainersAndSkipFirst() throws Exception + { + restClient.authenticateUser(publicSiteWithContainersUsers.getOneUserWithRole(UserRole.SiteCollaborator)) + .withParams("skipCount=1").withCoreAPI().usingSite(publicSiteWithContainers).getSiteContainers() + .assertThat().entriesListCountIs(1) + .and().entriesListDoesNotContain("folderId", restSiteContainers.getEntries().get(0).onModel().getFolderId()) + .and().entriesListContains("folderId", restSiteContainers.getEntries().get(1).onModel().getFolderId()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if get site containers request and get last container returns status code 200") + public void getLastSiteContainer() throws Exception + { + restClient.authenticateUser(publicSiteWithContainersUsers.getOneUserWithRole(UserRole.SiteCollaborator)) + .withParams("skipCount=" + String.valueOf(totalItems-1)).withCoreAPI().usingSite(publicSiteWithContainers).getSiteContainers() + .assertThat().entriesListCountIs(1) + .and().entriesListDoesNotContain("folderId", restSiteContainers.getEntries().get(0).onModel().getFolderId()) + .and().entriesListContains("folderId", restSiteContainers.getEntries().get(1).onModel().getFolderId()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if get site containers request returns status code 200 when high skipCount parameter is used") + public void getSiteContainersWithHighSkipCount() throws Exception + { + restClient.authenticateUser(publicSiteWithContainersUsers.getOneUserWithRole(UserRole.SiteCollaborator)) + .withParams("skipCount=999999").withCoreAPI().usingSite(publicSiteWithContainers).getSiteContainers() + .assertThat().entriesListIsEmpty() + .and().entriesListCountIs(0) + .and().paginationField("skipCount").is("999999"); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if get site container request for an empty siteId returns status code 404") + public void getSiteContainersForEmptySiteId() throws Exception + { + restClient.authenticateUser(publicSiteWithContainersUsers.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingSite("").getSiteContainers(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "")) + .stackTraceIs(RestErrorModel.STACKTRACE) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/members/AddSiteMemberTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/members/AddSiteMemberTests.java new file mode 100644 index 0000000000..4c097c9916 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/members/AddSiteMemberTests.java @@ -0,0 +1,588 @@ +package org.alfresco.rest.sites.members; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.JsonBodyGenerator; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestSiteMemberModel; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class AddSiteMemberTests extends RestTest +{ + private UserModel adminUserModel; + private SiteModel publicSiteModel, moderatedSiteModel, privateSiteModel; + private ListUserWithRoles publicSiteUsersWithRoles, moderatedSiteUsersWithRoles, privateSiteUsersWithRoles; + private String addMemberJson, addMembersJson; + private RestSiteMemberModel memberModel; + + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + adminUserModel = dataUser.getAdminUser(); + publicSiteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); + moderatedSiteModel = dataSite.usingUser(adminUserModel).createModeratedRandomSite(); + privateSiteModel = dataSite.usingUser(adminUserModel).createPrivateRandomSite(); + publicSiteUsersWithRoles = dataUser.addUsersWithRolesToSite(publicSiteModel, + UserRole.SiteManager, + UserRole.SiteCollaborator, + UserRole.SiteConsumer, + UserRole.SiteContributor); + moderatedSiteUsersWithRoles = dataUser.addUsersWithRolesToSite(moderatedSiteModel, + UserRole.SiteManager, + UserRole.SiteCollaborator, + UserRole.SiteConsumer, + UserRole.SiteContributor); + privateSiteUsersWithRoles = dataUser.addUsersWithRolesToSite(privateSiteModel, + UserRole.SiteManager, + UserRole.SiteCollaborator, + UserRole.SiteConsumer, + UserRole.SiteContributor); + addMemberJson = "{\"role\":\"%s\",\"id\":\"%s\"}"; + addMembersJson = "{\"role\":\"%s\",\"id\":\"%s\"}, {\"role\":\"%s\",\"id\":\"%s\"}"; + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.SANITY }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.SANITY, + description = "Verify that manager is able to add site member and gets status code CREATED (201)") + public void managerIsAbleToAddSiteMember() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteCollaborator); + restClient.authenticateUser(publicSiteUsersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + restClient.withCoreAPI().usingSite(publicSiteModel).addPerson(testUser) + .assertThat().field("id").is(testUser.getUsername()) + .and().field("role").is(testUser.getUserRole()); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that site collaborator is not able to add site member and gets status code FORBIDDEN (403)") + public void collaboratorIsNotAbleToAddSiteMember() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteConsumer); + restClient.authenticateUser(publicSiteUsersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .withCoreAPI().usingSite(publicSiteModel).addPerson(testUser); + + restClient.assertLastError().containsSummary("Permission was denied"); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION}) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that site contributor is not able to add site member and gets status code FORBIDDEN (403)") + public void contributorIsNotAbleToAddSiteMember() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteConsumer); + restClient.authenticateUser(publicSiteUsersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .withCoreAPI().usingSite(publicSiteModel).addPerson(testUser); + restClient.assertLastError().containsSummary("Permission was denied"); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that site consumer is not able to add site member and gets status code FORBIDDEN (403)") + public void consumerIsNotAbleToAddSiteMember() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteConsumer); + restClient.authenticateUser(publicSiteUsersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .withCoreAPI().usingSite(publicSiteModel).addPerson(testUser); + restClient.assertLastError().containsSummary("Permission was denied"); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.SANITY }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.SANITY, + description = "Verify that admin user is able to add site member and gets status code CREATED (201)") + public void adminIsAbleToAddSiteMember() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteConsumer); + restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingSite(publicSiteModel).addPerson(testUser) + .and().field("id").is(testUser.getUsername()) + .and().field("role").is(testUser.getUserRole()); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.SANITY }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.SANITY, + description = "Verify that unauthenticated user is not able to add site member") +// @Bug(id="MNT-16904", description = "It fails only on environment with tenants") + public void unauthenticatedUserIsNotAuthorizedToAddSiteMmeber() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteConsumer); + + UserModel userModel = dataUser.createRandomTestUser(); + userModel.setPassword("user wrong password"); + dataUser.addUserToSite(userModel, publicSiteModel, UserRole.SiteManager); + + restClient.authenticateUser(userModel) + .withCoreAPI().usingSite(publicSiteModel).addPerson(testUser); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that manager can add another user as manager to a public site and gets status code CREATED (201)") + public void addManagerToPublicSite() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteManager); + memberModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(publicSiteModel).addPerson(testUser); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + memberModel.assertThat().field("id").is(testUser.getUsername()) + .and().field("role").is(testUser.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that manager can add another user as manager to a moderated site and gets status code CREATED (201)") + public void addManagerToModeratedSite() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteManager); + memberModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(moderatedSiteModel).addPerson(testUser); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + memberModel.assertThat().field("id").is(testUser.getUsername()) + .and().field("role").is(testUser.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that manager can add another user as manager to a private site and gets status code CREATED (201)") + public void addManagerToPrivateSite() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteManager); + memberModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(privateSiteModel).addPerson(testUser); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + memberModel.assertThat().field("id").is(testUser.getUsername()) + .and().field("role").is(testUser.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that consumer role is not able to add another user to a moderated site and gets status code 403") + public void addUserByConsumerToModeratedSite() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteConsumer); + restClient.authenticateUser(moderatedSiteUsersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI().usingSite(moderatedSiteModel).addPerson(testUser); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that consumer role is not able to add another user to a private site and gets status code 403") + public void addUserByConsumerToPrivateSite() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteConsumer); + restClient.authenticateUser(privateSiteUsersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI().usingSite(privateSiteModel).addPerson(testUser); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that collaborator role is not able to add another user to a moderated site and gets status code 403") + public void addUserByCollaboratorToModeratedSite() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteConsumer); + restClient.authenticateUser(moderatedSiteUsersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingSite(moderatedSiteModel).addPerson(testUser); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that collaborator role is not able to add another user to a private site and gets status code 403") + public void addUserByCollaboratorToPrivateSite() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteConsumer); + restClient.authenticateUser(privateSiteUsersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingSite(privateSiteModel).addPerson(testUser); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that contributor role is not able to add another user to a moderated site and gets status code 403") + public void addUserByContributorToModeratedSite() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteConsumer); + restClient.authenticateUser(moderatedSiteUsersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).withCoreAPI().usingSite(moderatedSiteModel).addPerson(testUser); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that contributor role is not able to add another user to a private site and gets status code 403") + public void addUserByContributorToPrivateSite() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteConsumer); + restClient.authenticateUser(privateSiteUsersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).withCoreAPI().usingSite(privateSiteModel).addPerson(testUser); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that a user without specified role can not be added to a site and gets status code 400") + public void canNotAddUserWithoutSpecifyingRoleToSite() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + restClient.authenticateUser(adminUserModel).withCoreAPI(); + String json = JsonBodyGenerator.keyValueJson("id", testUser.getUsername()); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, json, "sites/{siteId}/members?{parameters}", publicSiteModel.getId(), restClient.getParameters()); + restClient.processModel(RestSiteMemberModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(RestErrorModel.MUST_PROVIDE_ROLE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that a user with inexistent role can not be added to a site and gets status code 400") + public void canNotAddUserWithInexistentRoleToSite() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + restClient.authenticateUser(adminUserModel).withCoreAPI(); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, String.format("{\"role\":\"inexistentRole\",\"id\":\"%s\"}", testUser.getUsername()), "sites/{siteId}/members?{parameters}", publicSiteModel.getId(), restClient.getParameters()); + restClient.processModel(RestSiteMemberModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(String.format(RestErrorModel.UNKNOWN_ROLE, "inexistentRole")); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that user can not add himself as a manager to a public site and gets status code 403") + public void userAddHimselfAsManagerToPublicSite() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteManager); + restClient.authenticateUser(testUser).withCoreAPI().usingSite(publicSiteModel).addPerson(testUser); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that user can not add himself as a manager to a moderated site and gets status code 403") + public void userAddHimselfAsManagerToModeratedSite() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteManager); + restClient.authenticateUser(testUser).withCoreAPI().usingSite(moderatedSiteModel).addPerson(testUser); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that user can not add himself as a manager to a private site and gets status code 404") + public void userAddHimselfAsManagerToPrivateSite() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteManager); + restClient.authenticateUser(testUser).withCoreAPI().usingSite(privateSiteModel).addPerson(testUser); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, privateSiteModel.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that user can not be added to an inexistent site and gets status code 404") + public void userIsNotAbleToAddUserToAnInexistentSite() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteManager); + SiteModel inexistentSite = new SiteModel("inexistentSite"); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(inexistentSite).addPerson(testUser); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, inexistentSite.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that user can not be added to a site if an empty site id is provided and gets status code 404") + public void userIsNotAbleToAddAnotherUserUsingEmptySiteId() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteManager); + SiteModel inexistentSite = new SiteModel(""); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(inexistentSite).addPerson(testUser); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, inexistentSite.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that inexistent user can not be added to site and gets status code 404") + public void userIsNotAbleToAddInexistentUserToSite() throws Exception + { + UserModel testUser = new UserModel("inexistentUser", "password"); + testUser.setUserRole(UserRole.SiteManager); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(publicSiteModel).addPerson(testUser); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, testUser.getUsername())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that empty username can not be added to site and gets status code 400") + public void userIsNotAbleToAddEmptyUserIdToSite() throws Exception + { + UserModel testUser = new UserModel("", "password"); + testUser.setUserRole(UserRole.SiteManager); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(publicSiteModel).addPerson(testUser); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(String.format(RestErrorModel.NO_CONTENT, testUser.getUsername())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that user can not add another user that is already a memeber and gets status code 409") + public void userIsNotAbleToAddUserThatIsAlreadyAMember() throws Exception + { + UserModel collaborator = moderatedSiteUsersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(moderatedSiteModel).addPerson(collaborator); + restClient.assertStatusCodeIs(HttpStatus.CONFLICT).assertLastError().containsSummary(String.format(RestErrorModel.ALREADY_Site_MEMBER, collaborator.getUsername(), moderatedSiteModel.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that several users with different roles can be added once in a row to a site and gets status code 201") + public void addSeveralUsersWithDifferentRolesToASite() throws Exception + { + UserModel firstUser = dataUser.createRandomTestUser("testUser"); + firstUser.setUserRole(UserRole.SiteContributor); + UserModel secondUser = dataUser.createRandomTestUser("testUser"); + secondUser.setUserRole(UserRole.SiteCollaborator); + restClient.authenticateUser(adminUserModel).withCoreAPI(); + String json = String.format(addMembersJson, firstUser.getUserRole(), firstUser.getUsername(), secondUser.getUserRole(), secondUser.getUsername()); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, json, "sites/{siteId}/members?{parameters}", publicSiteModel.getId(), restClient.getParameters()); + restClient.processModel(RestSiteMemberModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that several users with same roles can be added once in a row to a site and gets status code 201") + public void addSeveralUsersWithSameRolesToASite() throws Exception + { + UserModel firstUser = dataUser.createRandomTestUser("testUser"); + firstUser.setUserRole(UserRole.SiteCollaborator); + UserModel secondUser = dataUser.createRandomTestUser("testUser"); + secondUser.setUserRole(UserRole.SiteCollaborator); + restClient.authenticateUser(adminUserModel).withCoreAPI(); + String json = String.format(addMembersJson, firstUser.getUserRole(), firstUser.getUsername(), secondUser.getUserRole(), secondUser.getUsername()); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, json, "sites/{siteId}/members?{parameters}", publicSiteModel.getId(), restClient.getParameters()); + restClient.processModel(RestSiteMemberModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that several users that are already added to the site can not be added once in a row and gets status code 400") + public void addSeveralUsersThatAreAlreadyAddedToASite() throws Exception + { + UserModel collaborator = moderatedSiteUsersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator); + UserModel consumer = moderatedSiteUsersWithRoles.getOneUserWithRole(UserRole.SiteConsumer); + restClient.authenticateUser(adminUserModel).withCoreAPI(); + String json = String.format(addMembersJson, collaborator.getUserRole(), collaborator.getUsername(), consumer.getUserRole(), consumer.getUsername()); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, json, "sites/{siteId}/members?{parameters}", moderatedSiteModel.getId(), restClient.getParameters()); + restClient.processModel(RestSiteMemberModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.CONFLICT).assertLastError().containsSummary(String.format(RestErrorModel.ALREADY_Site_MEMBER, collaborator.getUsername(), moderatedSiteModel.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Add new site member request by providing an empty body") + public void addSiteMemberUsingEmptyBody() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI(); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, "", "sites/{siteId}/members?{parameters}", + publicSiteModel.getId(), restClient.getParameters()); + restClient.processModel(RestSiteMemberModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(String.format(RestErrorModel.NO_CONTENT, "No content to map due to end-of-input")) + .containsErrorKey(String.format(RestErrorModel.NO_CONTENT, "No content to map due to end-of-input")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Check lower and upper case letters for role field") + public void checkLowerUpperCaseLettersForRole() throws Exception + { + UserModel user = dataUser.createRandomTestUser(); + + String json = String.format(addMemberJson, "SITEMANAGER", user.getUsername()); + restClient.authenticateUser(adminUserModel).withCoreAPI(); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, json, "sites/{siteId}/members?{parameters}", publicSiteModel.getId(), restClient.getParameters()); + restClient.processModel(RestSiteMemberModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(String.format(RestErrorModel.UNKNOWN_ROLE, "SITEMANAGER")) + .containsErrorKey(String.format(RestErrorModel.UNKNOWN_ROLE, "SITEMANAGER")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + + json = String.format(addMemberJson, "sitemanager", user.getUsername()); + restClient.authenticateUser(adminUserModel).withCoreAPI(); + request = RestRequest.requestWithBody(HttpMethod.POST, json, "sites/{siteId}/members?{parameters}", publicSiteModel.getId(), restClient.getParameters()); + restClient.processModel(RestSiteMemberModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(String.format(RestErrorModel.UNKNOWN_ROLE, "sitemanager")) + .containsErrorKey(String.format(RestErrorModel.UNKNOWN_ROLE, "sitemanager")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Check empty value for user role") + public void checkEmptyValueForRole() throws Exception + { + UserModel user = dataUser.createRandomTestUser(); + + String json = String.format(addMemberJson, "", user.getUsername()); + restClient.authenticateUser(adminUserModel).withCoreAPI(); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, json, "sites/{siteId}/members?{parameters}", publicSiteModel.getId(), restClient.getParameters()); + restClient.processModel(RestSiteMemberModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsErrorKey(String.format(RestErrorModel.NO_CONTENT, "N/A")) + .containsSummary(String.format(RestErrorModel.NO_CONTENT, "N/A")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that contributor role can be added to public site") + public void addContributorToPublicSite() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteContributor); + memberModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(publicSiteModel).addPerson(testUser); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + memberModel.assertThat().field("id").is(testUser.getUsername()) + .and().field("role").is(testUser.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that collaborator role can be added to moderated site") + public void addCollaboratorToModeratedSite() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteCollaborator); + memberModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(moderatedSiteModel).addPerson(testUser); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + memberModel.assertThat().field("id").is(testUser.getUsername()) + .and().field("role").is(testUser.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that contributor role can be added to moderated site") + public void addContributorToModeratedSite() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteContributor); + memberModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(moderatedSiteModel).addPerson(testUser); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + memberModel.assertThat().field("id").is(testUser.getUsername()) + .and().field("role").is(testUser.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that consumer role can be added to moderated site") + public void addConsumerToModeratedSite() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteConsumer); + memberModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(moderatedSiteModel).addPerson(testUser); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + memberModel.assertThat().field("id").is(testUser.getUsername()) + .and().field("role").is(testUser.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that collaborator role can be added to private site") + public void addCollaboratorToPrivateSite() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteCollaborator); + memberModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(privateSiteModel).addPerson(testUser); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + memberModel.assertThat().field("id").is(testUser.getUsername()) + .and().field("role").is(testUser.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that contributor role can be added to private site") + public void addContributorToPrivateSite() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteContributor); + memberModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(privateSiteModel).addPerson(testUser); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + memberModel.assertThat().field("id").is(testUser.getUsername()) + .and().field("role").is(testUser.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that consumer role can be added to private site") + public void addConsumerToPrivateSite() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteConsumer); + memberModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(privateSiteModel).addPerson(testUser); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + memberModel.assertThat().field("id").is(testUser.getUsername()) + .and().field("role").is(testUser.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that admin can be added to private site by site manager") + public void adminCanBeAddedToPrivateSiteBySiteManager() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser(); + SiteModel privateSite = dataSite.usingUser(testUser).createPrivateRandomSite(); + adminUserModel.setUserRole(UserRole.SiteContributor); + memberModel = restClient.authenticateUser(testUser).withCoreAPI().usingSite(privateSite).addPerson(adminUserModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + memberModel.assertThat().field("id").is(adminUserModel.getUsername()).and().field("role").is(adminUserModel.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that admin cannot be added to private site by site collaborator") + public void adminCannotBeAddedToPrivateSiteBySiteCollaborator() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser(); + SiteModel privateSite = dataSite.usingUser(testUser).createPrivateRandomSite(); + UserModel siteCollaborator = dataUser.createRandomTestUser(); + dataUser.addUserToSite(siteCollaborator, privateSite, UserRole.SiteCollaborator); + adminUserModel.setUserRole(UserRole.SiteContributor); + memberModel = restClient.authenticateUser(siteCollaborator).withCoreAPI().usingSite(privateSite).addPerson(adminUserModel); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/members/GetSiteMemberTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/members/GetSiteMemberTests.java new file mode 100644 index 0000000000..1b52694554 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/members/GetSiteMemberTests.java @@ -0,0 +1,395 @@ +package org.alfresco.rest.sites.members; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.exception.JsonToModelConversionException; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; +import org.alfresco.utility.exception.DataPreparationException; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * @author iulia.cojocea + */ +public class GetSiteMemberTests extends RestTest +{ + private UserModel adminUser; + private SiteModel publicSiteModel, moderatedSiteModel, privateSiteModel; + private ListUserWithRoles usersWithRoles; + private UserModel manager, consumer, collaborator, contributor; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws DataPreparationException + { + adminUser = dataUser.getAdminUser(); + publicSiteModel = dataSite.usingUser(adminUser).createPublicRandomSite(); + moderatedSiteModel = dataSite.usingUser(adminUser).createModeratedRandomSite(); + privateSiteModel = dataSite.usingUser(adminUser).createPrivateRandomSite(); + usersWithRoles = dataUser.addUsersWithRolesToSite(publicSiteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, + UserRole.SiteContributor); + + consumer = dataUser.createRandomTestUser(); + manager = usersWithRoles.getOneUserWithRole(UserRole.SiteManager); + collaborator = usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator); + contributor = usersWithRoles.getOneUserWithRole(UserRole.SiteContributor); + + dataUser.addUserToSite(consumer, publicSiteModel, UserRole.SiteConsumer); + dataUser.addUserToSite(consumer, moderatedSiteModel, UserRole.SiteConsumer); + dataUser.addUserToSite(manager, moderatedSiteModel, UserRole.SiteManager); + dataUser.addUserToSite(consumer, privateSiteModel, UserRole.SiteConsumer); + dataUser.addUserToSite(manager, privateSiteModel, UserRole.SiteManager); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.SANITY, + description = "Verify user with Manager role gets site member and status code is OK (200)") + public void getSiteMemberWithManagerRole() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + restClient.withCoreAPI().usingSite(publicSiteModel).getSiteMember(consumer) + .assertThat().field("id").is(consumer.getUsername()) + .and().field("role").is(consumer.getUserRole()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with Collaborator role gets site member and gets status code OK (200)") + public void getSiteMemberWithCollaboratorRole() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); + restClient.withCoreAPI().usingSite(publicSiteModel).getSiteMember(consumer) + .and().field("id").is(consumer.getUsername()) + .and().field("role").is(consumer.getUserRole()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with Contributor role gets site member and gets status code OK (200)") + public void getSiteMemberWithContributorRole() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); + restClient.withCoreAPI().usingSite(publicSiteModel).getSiteMember(consumer) + .and().field("id").is(consumer.getUsername()) + .and().field("role").is(consumer.getUserRole()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with Consumer role gets site member and gets status code OK (200)") + public void getSiteMemberWithConsumerRole() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)); + restClient.withCoreAPI().usingSite(publicSiteModel).getSiteMember(consumer) + .and().field("id").is(consumer.getUsername()) + .and().field("role").is(consumer.getUserRole()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with admin user gets site member and gets status code OK (200)") + public void getSiteMemberWithAdminUser() throws Exception + { + restClient.authenticateUser(adminUser); + restClient.withCoreAPI().usingSite(publicSiteModel).getSiteMember(consumer) + .and().field("id").is(consumer.getUsername()) + .and().field("role").is(consumer.getUserRole()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.SANITY, + description = "Failed authentication get site member call returns status code 401") +// @Bug(id="MNT-16904", description = "It fails only on environment with tenants") + public void unauthenticatedUserIsNotAuthorizedToRetrieveSiteMember() throws JsonToModelConversionException, Exception + { + UserModel inexistentUser = new UserModel("inexistent user", "inexistent password"); + restClient.authenticateUser(inexistentUser); + restClient.withCoreAPI().usingSite(publicSiteModel).getSiteMember(consumer); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with Manager role doesn't get a site member of inexistent site and status code is Not Found (404)") + public void getSiteMemberOfInexistentSite() throws Exception + { + SiteModel invalidSite = new SiteModel("invalidSite"); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + restClient.withCoreAPI().usingSite(invalidSite).getSiteMember(consumer); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, consumer.getUsername(), invalidSite.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with Manager role doesn't get non site member of inexistent site and status code is Not Found (404)") + public void getSiteMemberForNonSiteMember() throws Exception + { + UserModel nonMember = dataUser.createRandomTestUser(); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + restClient.withCoreAPI().usingSite(publicSiteModel).getSiteMember(nonMember); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, nonMember.getUsername(), publicSiteModel.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with Manager role doesn't get not existing site member and status code is Not Found (404)") + public void getSiteMemberForInexistentSiteMember() throws Exception + { + UserModel inexistentUser = new UserModel("inexistentUser", "password"); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + restClient.withCoreAPI().usingSite(publicSiteModel).getSiteMember(inexistentUser); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, inexistentUser.getUsername())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with Manager role can get site member using \"-me-\" in place of personId") + public void getSiteMemberUsingMeForPersonId() throws Exception + { + UserModel meUser = new UserModel("-me-", "password"); + + restClient.authenticateUser(manager); + restClient.withCoreAPI().usingSite(publicSiteModel).getSiteMember(meUser) + .assertThat().field("id").is(manager.getUsername()) + .and().field("role").is(manager.getUserRole()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with Manager role can get site member for empty siteId") + public void getSiteMemberForEmptySiteId() throws Exception + { + SiteModel emptySite = new SiteModel(""); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + restClient.withCoreAPI().usingSite(emptySite).getSiteMember(consumer); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, consumer.getUsername(), emptySite.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with Manager role gets site member with Manager role and status code is OK (200)") + public void getSiteManagerMemberWithManagerRole() throws Exception + { + UserModel anotherManager = dataUser.createRandomTestUser(); + dataUser.addUserToSite(anotherManager, publicSiteModel, UserRole.SiteManager); + + restClient.authenticateUser(manager); + restClient.withCoreAPI().usingSite(publicSiteModel).getSiteMember(anotherManager) + .assertThat().field("id").is(anotherManager.getUsername()) + .and().field("role").is(anotherManager.getUserRole()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with Collaborator role gets site member with Manager role and status code is OK (200)") + public void getSiteManagerMemberWithCollaboratorRole() throws Exception + { + restClient.authenticateUser(collaborator); + restClient.withCoreAPI().usingSite(publicSiteModel).getSiteMember(manager) + .assertThat().field("id").is(manager.getUsername()) + .and().field("role").is(manager.getUserRole()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with Consumer role gets site member with Manager role and status code is OK (200)") + public void getSiteManagerMemberWithConsumerRole() throws Exception + { + restClient.authenticateUser(consumer); + restClient.withCoreAPI().usingSite(publicSiteModel).getSiteMember(manager) + .assertThat().field("id").is(manager.getUsername()) + .and().field("role").is(manager.getUserRole()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with Contributor role gets site member with Manager role and status code is OK (200)") + public void getSiteManagerMemberWithContributorRole() throws Exception + { + restClient.authenticateUser(contributor); + restClient.withCoreAPI().usingSite(publicSiteModel).getSiteMember(manager) + .assertThat().field("id").is(manager.getUsername()) + .and().field("role").is(manager.getUserRole()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with Contributor role gets admin site member and status code is OK (200)") + public void getSiteAdminManagerMember() throws Exception + { + restClient.authenticateUser(contributor); + restClient.withCoreAPI().usingSite(publicSiteModel).getSiteMember(adminUser) + .assertThat().field("id").is(adminUser.getUsername()) + .and().field("role").is(UserRole.SiteManager); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with Collaborator role gets site member with Contributor role and status code is OK (200)") + public void getSiteContributorMemberWithCollaboratorRole() throws Exception + { + restClient.authenticateUser(collaborator).withCoreAPI().usingSite(publicSiteModel).getSiteMember(contributor) + .assertThat().field("id").is(contributor.getUsername()) + .and().field("role").is(contributor.getUserRole()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with Contributor role gets site member with Collaborator role and status code is OK (200)") + public void getSiteCollaboratorMemberWithContributorRole() throws Exception + { + restClient.authenticateUser(contributor).withCoreAPI().usingSite(publicSiteModel).getSiteMember(collaborator) + .assertThat().field("id").is(collaborator.getUsername()) + .and().field("role").is(collaborator.getUserRole()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with Collaborator role gets admin role and status code is OK (200)") + public void getAdminWithCollaboratorRole() throws Exception + { + restClient.authenticateUser(collaborator).withCoreAPI().usingSite(publicSiteModel).getSiteMember(adminUser) + .assertThat().field("id").is(adminUser.getUsername()) + .and().field("role").is(UserRole.SiteManager); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with Collaborator role gets site member with Consumer role and status code is OK (200)") + public void getSiteConsumerMemberWithCollaboratorRole() throws Exception + { + restClient.authenticateUser(collaborator).withCoreAPI().usingSite(publicSiteModel).getSiteMember(consumer) + .assertThat().field("id").is(consumer.getUsername()) + .and().field("role").is(consumer.getUserRole()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user gets site member of private site and status code is OK (200)") + public void getSiteMemberOfPrivateSite() throws Exception + { + restClient.authenticateUser(manager).withCoreAPI().usingSite(privateSiteModel).getSiteMember(consumer) + .assertThat().field("id").is(consumer.getUsername()) + .and().field("role").is(consumer.getUserRole()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify not joined user is not is not able to get site member of private site and status code is 404") + public void regularUserIsNotAbleToGetSiteMemberOfPrivateSite() throws Exception { + UserModel regularUser = dataUser.createRandomTestUser(); + + restClient.authenticateUser(regularUser).withCoreAPI().usingSite(privateSiteModel).getSiteMember(consumer); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, consumer.getUsername(), privateSiteModel.getTitle())); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify admin is not able to get from site a user that created a member request that was not accepted yet") + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + public void adminIsNotAbleToGetFromSiteANonExistingMember() throws Exception + { + UserModel newMember = dataUser.createRandomTestUser(); + restClient.authenticateUser(newMember).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSiteModel); + + restClient.authenticateUser(adminUser).withCoreAPI().usingSite(moderatedSiteModel).getSiteMember(newMember); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, newMember.getUsername(), moderatedSiteModel.getTitle())) + .containsErrorKey(RestErrorModel.RELATIONSHIP_NOT_FOUND_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user gets site creator and status code is OK (200)") + public void getSiteCreator() throws Exception + { + SiteModel newSiteModel = dataSite.usingUser(collaborator).createModeratedRandomSite(); + dataUser.addUserToSite(consumer, publicSiteModel, UserRole.SiteConsumer); + + restClient.authenticateUser(consumer).withCoreAPI().usingSite(newSiteModel).getSiteMember(collaborator) + .assertThat().field("id").is(collaborator.getUsername()) + .and().field("role").is(UserRole.SiteManager); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with Consumer role can get site member using \"-me-\" in place of personId") + public void getSiteMemberOfPrivateSiteUsingMeForPersonId() throws Exception + { + UserModel meUser = new UserModel("-me-", "password"); + + restClient.authenticateUser(consumer).withCoreAPI().usingSite(privateSiteModel).getSiteMember(meUser) + .assertThat().field("id").is(consumer.getUsername()) + .and().field("role").is(consumer.getUserRole()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user gets site member of moderated site and status code is OK (200)") + public void getSiteMemberOfModeratedSite() throws Exception + { + restClient.authenticateUser(manager).withCoreAPI().usingSite(moderatedSiteModel).getSiteMember(consumer) + .assertThat().field("id").is(consumer.getUsername()) + .and().field("role").is(consumer.getUserRole()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify not joined user gets site member of moderated site and status code is OK (200)") + public void regularUserIsAbleToGetSiteMemberOfModeratedSite() throws Exception + { + UserModel regularUser = dataUser.createRandomTestUser(); + + restClient.authenticateUser(regularUser).withCoreAPI().usingSite(moderatedSiteModel).getSiteMember(consumer); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if get site member request with properties parameter returns status code 200 and parameter is applied") + public void getSiteMemberUsingPropertiesParameter() throws Exception + { + restClient.authenticateUser(manager) + .withCoreAPI().usingSite(publicSiteModel).usingParams("properties=id").getSiteMember(consumer) + .assertThat().fieldsCount().is(1) + .and().field("id").isNotEmpty() + .and().field("role").isNull() + .and().field("person").isNull(); + restClient.assertStatusCodeIs(HttpStatus.OK); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/members/GetSiteMembersTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/members/GetSiteMembersTests.java new file mode 100644 index 0000000000..14353694f5 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/members/GetSiteMembersTests.java @@ -0,0 +1,354 @@ +package org.alfresco.rest.sites.members; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestSiteMemberModel; +import org.alfresco.rest.model.RestSiteMemberModelsCollection; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * @author iulia.cojocea + */ +public class GetSiteMembersTests extends RestTest +{ + private SiteModel publicSite, privateSite, moderatedSite, moderatedSite2, moderatedSite3; + private RestSiteMemberModelsCollection siteMembers; + private ListUserWithRoles usersWithRoles, moderatedSiteUsers; + private UserModel regularUser, privateSiteConsumer, siteCreator; + private RestSiteMemberModel firstSiteMember, secondSiteMember, thirdSiteMember, fourthSiteMember; + + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + siteCreator = dataUser.createRandomTestUser(); + regularUser = dataUser.createRandomTestUser(); + privateSiteConsumer = dataUser.createRandomTestUser(); + + publicSite = dataSite.usingUser(siteCreator).createPublicRandomSite(); + privateSite = dataSite.usingUser(siteCreator).createPrivateRandomSite(); + moderatedSite = dataSite.usingUser(siteCreator).createModeratedRandomSite(); + moderatedSite2 = dataSite.usingUser(siteCreator).createModeratedRandomSite(); + moderatedSite3 = dataSite.usingUser(siteCreator).createModeratedRandomSite(); + + dataUser.addUserToSite(privateSiteConsumer, privateSite, UserRole.SiteConsumer); + dataUser.addUserToSite(privateSiteConsumer, moderatedSite3, UserRole.SiteConsumer); + usersWithRoles = dataUser.addUsersWithRolesToSite(publicSite,UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor); + moderatedSiteUsers = dataUser.addUsersWithRolesToSite(moderatedSite, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor); + + siteMembers = restClient.authenticateUser(siteCreator).withCoreAPI() + .usingSite(moderatedSite).usingParams("properties=role,id").getSiteMembers(); + firstSiteMember = siteMembers.getEntries().get(0).onModel(); + secondSiteMember = siteMembers.getEntries().get(1).onModel(); + thirdSiteMember = siteMembers.getEntries().get(2).onModel(); + fourthSiteMember = siteMembers.getEntries().get(3).onModel(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.SANITY }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.SANITY, + description = "Verify user with Manager role gets site members and gets status code OK (200)") + public void getSiteMembersWithManagerRole() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingSite(publicSite).getSiteMembers().assertThat().entriesListIsNotEmpty() + .and().entriesListContains("id", usersWithRoles.getOneUserWithRole(UserRole.SiteManager).getUsername()) + .and().entriesListContains("role", usersWithRoles.getOneUserWithRole(UserRole.SiteManager).getUserRole().toString()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with Collaborator role gets site members and gets status code OK (200)") + public void getSiteMembersWithCollaboratorRole() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .withCoreAPI().usingSite(publicSite).getSiteMembers().assertThat().entriesListIsNotEmpty().assertThat() + .entriesListContains("id", usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator).getUsername()).and() + .entriesListContains("role", usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator).getUserRole().toString()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with Contributor role gets site members and gets status code OK (200)") + public void getSiteMembersWithContributorRole() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .withCoreAPI().usingSite(publicSite).getSiteMembers().assertThat().entriesListIsNotEmpty() + .and().entriesListContains("id", usersWithRoles.getOneUserWithRole(UserRole.SiteContributor).getUsername()) + .and().entriesListContains("role", usersWithRoles.getOneUserWithRole(UserRole.SiteContributor).getUserRole().toString()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with Consumer role gets site members and gets status code OK (200)") + public void getSiteMembersWithConsumerRole() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .withCoreAPI().usingSite(publicSite).getSiteMembers().assertThat().entriesListIsNotEmpty() + .and().entriesListContains("id", usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer).getUsername()) + .and().entriesListContains("role", usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer).getUserRole().toString()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify user with admin usere gets site members and gets status code OK (200)") + public void getSiteMembersWithAdminUser() throws Exception + { + restClient.authenticateUser(dataUser.getAdminUser()) + .withCoreAPI().usingSite(publicSite).getSiteMembers().assertThat().entriesListIsNotEmpty() + .and().entriesListContains("id", siteCreator.getUsername()) + .when().assertThat().entriesListContains("role", "SiteManager"); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.SANITY }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.SANITY, + description = "Failed authentication get site members call returns status code 401") +// @Bug(id="MNT-16904", description = "It fails only on environment with tenants") + public void unauthenticatedUserIsNotAuthorizedToRetrieveSiteMembers() throws Exception + { + UserModel userModel = dataUser.createRandomTestUser(); + userModel.setPassword("user wrong password"); + dataUser.addUserToSite(userModel, publicSite, UserRole.SiteManager); + restClient.authenticateUser(userModel) + .withCoreAPI().usingSite(publicSite).getSiteMembers(); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify get site members call returns status code 404 if siteId does not exist") + public void checkStatusCodeForNonExistentSiteId() throws Exception + { + restClient.authenticateUser(regularUser).withCoreAPI() + .usingSite("NonExistentSiteId").getSiteMembers(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "NonExistentSiteId")); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify get site members call returns status code 400 for invalid maxItems") + public void checkStatusCodeForInvalidMaxItems() throws Exception + { + restClient.authenticateUser(regularUser).withParams("maxItems=0") + .withCoreAPI().usingSite(publicSite).getSiteMembers(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS) + .containsErrorKey(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + + restClient.withParams("maxItems=A") + .withCoreAPI().usingSite(publicSite).getSiteMembers(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.INVALID_MAXITEMS, "A")); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify get site members call returns status code 400 for invalid skipCount ") + public void checkStatusCodeForInvalidSkipCount() throws Exception + { + restClient.authenticateUser(regularUser).withParams("skipCount=A") + .withCoreAPI().usingSite(publicSite).getSiteMembers(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.INVALID_SKIPCOUNT, "A")); + + restClient.withParams("skipCount=-1") + .withCoreAPI().usingSite(publicSite).getSiteMembers(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(RestErrorModel.NEGATIVE_VALUES_SKIPCOUNT); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if any user gets public site members and status code is 200") + public void getPublicSiteMembers() throws Exception + { + siteMembers = restClient.authenticateUser(regularUser).withCoreAPI() + .usingSite(publicSite).getSiteMembers(); + restClient.assertStatusCodeIs(HttpStatus.OK); + siteMembers.assertThat().entriesListContains("id", siteCreator.getUsername()) + .and().entriesListContains("id", usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer).getUsername()) + .and().entriesListContains("id", usersWithRoles.getOneUserWithRole(UserRole.SiteContributor).getUsername()) + .and().entriesListContains("id", usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator).getUsername()) + .and().entriesListContains("id", usersWithRoles.getOneUserWithRole(UserRole.SiteManager).getUsername()) + .and().paginationField("count").is("5"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if any user gets moderated site members and status code is 200") + public void getModeratedSiteMembers() throws Exception + { + siteMembers = restClient.authenticateUser(regularUser).withCoreAPI() + .usingSite(moderatedSite).getSiteMembers(); + restClient.assertStatusCodeIs(HttpStatus.OK); + siteMembers.assertThat().entriesListContains("id", siteCreator.getUsername()) + .and().entriesListContains("id", moderatedSiteUsers.getOneUserWithRole(UserRole.SiteCollaborator).getUsername()) + .and().entriesListContains("id", moderatedSiteUsers.getOneUserWithRole(UserRole.SiteContributor).getUsername()) + .and().entriesListContains("id", moderatedSiteUsers.getOneUserWithRole(UserRole.SiteConsumer).getUsername()) + .and().paginationField("count").is("4"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if user gets private site members if he is a member of that site and status code is 200") + public void getPrivateSiteMembersByASiteMember() throws Exception + { + siteMembers = restClient.authenticateUser(privateSiteConsumer).withCoreAPI() + .usingSite(privateSite).getSiteMembers(); + restClient.assertStatusCodeIs(HttpStatus.OK); + siteMembers.assertThat().entriesListContains("id", siteCreator.getUsername()) + .and().entriesListContains("id", privateSiteConsumer.getUsername()) + .and().paginationField("count").is("2"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if user doesn't get private site members if he is not a member of that site and status code is 404") + public void getPrivateSiteMembersByNotASiteMember() throws Exception + { + restClient.authenticateUser(regularUser).withCoreAPI() + .usingSite(privateSite).getSiteMembers(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, privateSite.getTitle())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if user gets moderated site members after the adding of a new member and status code is 200") + public void getSiteMembersAfterAddingNewMember() throws Exception + { + siteMembers = restClient.authenticateUser(regularUser).withCoreAPI() + .usingSite(moderatedSite2).getSiteMembers(); + restClient.assertStatusCodeIs(HttpStatus.OK); + siteMembers.assertThat().entriesListContains("id", siteCreator.getUsername()) + .and().paginationField("count").is("1"); + + restClient.authenticateUser(siteCreator).withCoreAPI().usingSite(moderatedSite2).addPerson(privateSiteConsumer); + + siteMembers = restClient.authenticateUser(regularUser).withCoreAPI() + .usingSite(moderatedSite2).getSiteMembers(); + restClient.assertStatusCodeIs(HttpStatus.OK); + siteMembers.assertThat().entriesListContains("id", siteCreator.getUsername()) + .and().entriesListContains("id", privateSiteConsumer.getUsername()) + .and().paginationField("count").is("2"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if any user gets moderated site members with properties parameter applied and status code is 200") + public void getModeratedSiteMembersUsingPropertiesParameter() throws Exception + { + siteMembers = restClient.authenticateUser(siteCreator).withCoreAPI() + .usingSite(moderatedSite).usingParams("properties=role,id").getSiteMembers(); + restClient.assertStatusCodeIs(HttpStatus.OK); + siteMembers.assertThat().entriesListCountIs(4) + .and().entriesListDoesNotContain("person") + .and().entriesListContains("role", UserRole.SiteManager.toString()) + .and().entriesListContains("id", siteCreator.getUsername()) + .and().entriesListContains("role", UserRole.SiteContributor.toString()) + .and().entriesListContains("id", moderatedSiteUsers.getOneUserWithRole(UserRole.SiteContributor).getUsername()) + .and().entriesListContains("role", UserRole.SiteCollaborator.toString()) + .and().entriesListContains("id", moderatedSiteUsers.getOneUserWithRole(UserRole.SiteCollaborator).getUsername()) + .and().entriesListContains("role", UserRole.SiteConsumer.toString()) + .and().entriesListContains("id", moderatedSiteUsers.getOneUserWithRole(UserRole.SiteConsumer).getUsername()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if any user gets moderated site members with skipCount parameter applied") + public void getModeratedSiteMembersUsingSkipCountParameter() throws Exception + { + siteMembers = restClient.authenticateUser(siteCreator).withCoreAPI() + .usingSite(moderatedSite).usingParams("skipCount=2").getSiteMembers(); + restClient.assertStatusCodeIs(HttpStatus.OK); + siteMembers.assertThat().paginationField("count").is("2"); + siteMembers.assertThat().paginationField("skipCount").is("2"); + siteMembers.assertThat().entriesListDoesNotContain("id", firstSiteMember.getId()) + .and().entriesListDoesNotContain("id", secondSiteMember.getId()) + .and().entriesListContains("role", thirdSiteMember.getRole().toString()) + .and().entriesListContains("id", thirdSiteMember.getId()) + .and().entriesListContains("role", fourthSiteMember.getRole().toString()) + .and().entriesListContains("id", fourthSiteMember.getId()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if any user gets moderated site members with high skipCount parameter applied") + public void getModeratedSiteMembersUsingHighSkipCountParameter() throws Exception + { + siteMembers = restClient.authenticateUser(siteCreator).withCoreAPI() + .usingSite(moderatedSite).usingParams("skipCount=100").getSiteMembers(); + restClient.assertStatusCodeIs(HttpStatus.OK); + siteMembers.assertThat().paginationField("count").is("0"); + siteMembers.assertThat().paginationField("skipCount").is("100"); + siteMembers.assertThat().entriesListIsEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if any user gets moderated site members with maxItems parameter applied and check all pagination fields") + public void getModeratedSiteMembersUsingMaxItemsParameter() throws Exception + { + siteMembers = restClient.authenticateUser(siteCreator).withCoreAPI() + .usingSite(moderatedSite).usingParams("maxItems=1").getSiteMembers(); + restClient.assertStatusCodeIs(HttpStatus.OK); + siteMembers.assertThat().paginationField("count").is("1"); + siteMembers.assertThat().paginationField("hasMoreItems").is("true"); + siteMembers.assertThat().paginationField("maxItems").is("1"); + siteMembers.assertThat().paginationField("totalItems").isNotPresent(); + siteMembers.assertThat().entriesListContains("id", firstSiteMember.getId()) + .and().entriesListContains("role", firstSiteMember.getRole().toString()) + .and().entriesListDoesNotContain("id", secondSiteMember.getId()) + .and().entriesListDoesNotContain("id", thirdSiteMember.getId()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if user gets moderated site members with member not joined yet and status code is 200") + public void getSiteMembersFromNotJoinedModeratedSite() throws Exception + { + UserModel userNotJoined = dataUser.createRandomTestUser(); + restClient.authenticateUser(userNotJoined).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + siteMembers = restClient.authenticateUser(siteCreator).withCoreAPI() + .usingSite(moderatedSite2).getSiteMembers(); + restClient.assertStatusCodeIs(HttpStatus.OK); + siteMembers.assertThat().entriesListContains("id", siteCreator.getUsername()) + .and().entriesListDoesNotContain("id", userNotJoined.getUsername()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if any user gets site members after the member was removed from site and status code is 200") + public void getSiteMembersAfterRemovingASiteMember() throws Exception + { + siteMembers = restClient.authenticateUser(siteCreator).withCoreAPI() + .usingSite(moderatedSite3).getSiteMembers(); + restClient.assertStatusCodeIs(HttpStatus.OK); + siteMembers.assertThat().entriesListCountIs(2); + + restClient.withCoreAPI().usingSite(moderatedSite3).deleteSiteMember(privateSiteConsumer); + + siteMembers = restClient.withCoreAPI().usingSite(moderatedSite3).getSiteMembers(); + restClient.assertStatusCodeIs(HttpStatus.OK); + siteMembers.assertThat().entriesListCountIs(1) + .and().entriesListContains("role", UserRole.SiteManager.toString()) + .and().entriesListContains("id", siteCreator.getUsername()); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/members/RemoveSiteMemberTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/members/RemoveSiteMemberTests.java new file mode 100644 index 0000000000..a68ce31c0b --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/members/RemoveSiteMemberTests.java @@ -0,0 +1,466 @@ +package org.alfresco.rest.sites.members; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; +import org.alfresco.utility.exception.DataPreparationException; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * @author iulia.cojocea + */ +public class RemoveSiteMemberTests extends RestTest +{ + private SiteModel publicSiteModel, moderatedSiteModel, privateSiteModel; + private UserModel adminUserModel, siteCreator; + private ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws DataPreparationException + { + adminUserModel = dataUser.getAdminUser(); + siteCreator = dataUser.createRandomTestUser(); + publicSiteModel = dataSite.usingUser(siteCreator).createPublicRandomSite(); + moderatedSiteModel = dataSite.usingUser(siteCreator).createModeratedRandomSite(); + privateSiteModel = dataSite.usingUser(siteCreator).createPrivateRandomSite(); + usersWithRoles = dataUser.addUsersWithRolesToSite(publicSiteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, + UserRole.SiteContributor); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, + TestGroup.SITES }, executionType = ExecutionType.SANITY, description = "Verify that site manager can delete site member and gets status code 204, 'No Content'") + public void siteManagerIsAbleToDeleteSiteMemberWithConsumerRole() throws Exception + { + UserModel testUserModel = dataUser.createRandomTestUser(); + dataUser.addUserToSite(testUserModel, publicSiteModel, UserRole.SiteConsumer); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + restClient.withCoreAPI().usingSite(publicSiteModel).deleteSiteMember(testUserModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withCoreAPI().usingSite(publicSiteModel).getSiteMembers() + .assertThat().entriesListDoesNotContain("id", testUserModel.getUsername()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, + TestGroup.SITES }, executionType = ExecutionType.REGRESSION, description = "Verify that site collaborator cannot delete site member and gets status code 403, 'Forbidden'") + public void siteCollaboratorIsNotAbleToDeleteSiteMemberWithConsumerRole() throws Exception + { + UserModel testUserModel = dataUser.createRandomTestUser(); + dataUser.addUserToSite(testUserModel, publicSiteModel, UserRole.SiteConsumer); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); + restClient.withCoreAPI().usingSite(publicSiteModel).deleteSiteMember(testUserModel); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY); + + restClient.withCoreAPI().usingSite(publicSiteModel).getSiteMembers() + .assertThat().entriesListContains("id", testUserModel.getUsername()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, + TestGroup.SITES }, executionType = ExecutionType.REGRESSION, description = "Verify that site contributor cannot delete site member and gets status code 403, 'Forbidden'") + public void siteContributorIsNotAbleToDeleteSiteMemberWithConsumerRole() throws Exception + { + UserModel testUserModel = dataUser.createRandomTestUser(); + dataUser.addUserToSite(testUserModel, publicSiteModel, UserRole.SiteConsumer); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); + restClient.withCoreAPI().usingSite(publicSiteModel).deleteSiteMember(testUserModel); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY); + + restClient.withCoreAPI().usingSite(publicSiteModel).getSiteMembers() + .assertThat().entriesListContains("id", testUserModel.getUsername()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, + TestGroup.SITES }, executionType = ExecutionType.REGRESSION, description = "Verify that site consumer cannot delete site member and gets status code 403, 'Forbidden'") + public void siteConsumerIsNotAbleToDeleteSiteMemberWithConsumerRole() throws Exception + { + UserModel testUserModel = dataUser.createRandomTestUser(); + dataUser.addUserToSite(testUserModel, publicSiteModel, UserRole.SiteConsumer); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI().usingSite(publicSiteModel) + .deleteSiteMember(testUserModel); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY); + + restClient.withCoreAPI().usingSite(publicSiteModel).getSiteMembers() + .assertThat().entriesListContains("id", testUserModel.getUsername()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, + TestGroup.SITES }, executionType = ExecutionType.SANITY, description = "Verify that unauthenticated user is not able to delete site member") +// @Bug(id = "MNT-16904", description = "It fails only on environment with tenants") + public void unauthenticatedUserIsNotAuthorizedToDeleteSiteMember() throws Exception + { + UserModel testUserModel = dataUser.createRandomTestUser(); + dataUser.addUserToSite(testUserModel, publicSiteModel, UserRole.SiteConsumer); + + UserModel inexistentUser = new UserModel("inexistent user", "inexistent password"); + restClient.authenticateUser(inexistentUser).withCoreAPI().usingSite(publicSiteModel).deleteSiteMember(testUserModel); + + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that manager can NOT delete site member for an inexistent user and gets status code 404, 'Not Found'") + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + public void managerIsNotAbleToDeleteInexistentSiteMember() throws Exception + { + UserModel inexistentUser = new UserModel("inexistentUser", "password"); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + restClient.withCoreAPI().usingSite(publicSiteModel).deleteSiteMember(inexistentUser); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, inexistentUser.getUsername())); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that manager can NOT delete site member for a non site member and gets status code 400, 'Bad Request'") + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + public void managerIsNotAbleToDeleteNotSiteMember() throws Exception + { + UserModel nonMember = dataUser.createRandomTestUser(); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + restClient.withCoreAPI().usingSite(publicSiteModel).deleteSiteMember(nonMember); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.INVALID_ARGUMENT, "argument")); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that manager can NOT delete site member for an invalid site and gets status code 404, 'Not Found'") + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + public void managerIsNotAbleToDeleteSiteMemberOfInvalidSite() throws Exception + { + SiteModel invalidSite = new SiteModel("invalidSite"); + UserModel testUserModel = dataUser.createRandomTestUser(); + dataUser.addUserToSite(testUserModel, publicSiteModel, UserRole.SiteConsumer); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + restClient.withCoreAPI().usingSite(invalidSite).deleteSiteMember(testUserModel); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, testUserModel.getUsername(), invalidSite.getId())); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that manager can delete a site member with manager role") + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + public void siteManagerIsAbleToDeleteSiteMemberWithManagerRole() throws Exception + { + UserModel anothermanager = dataUser.createRandomTestUser(); + dataUser.addUserToSite(anothermanager, publicSiteModel, UserRole.SiteManager); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingSite(publicSiteModel).deleteSiteMember(anothermanager); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + restClient.withCoreAPI().usingSite(publicSiteModel).getSiteMembers() + .assertThat().entriesListDoesNotContain("id", anothermanager.getUsername()); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that manager can delete site member using \"-me-\" in place of personId") + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + public void managerIsAbleToDeleteSiteMemberUsingMe() throws Exception + { + UserModel manager = dataUser.createRandomTestUser(); + dataUser.addUserToSite(manager, publicSiteModel, UserRole.SiteManager); + UserModel meUser = new UserModel("-me-", "password"); + + restClient.authenticateUser(manager); + restClient.withCoreAPI().usingSite(publicSiteModel).deleteSiteMember(meUser); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + restClient.withCoreAPI().usingSite(publicSiteModel).getSiteMembers() + .assertThat().entriesListDoesNotContain("id", manager.getUsername()); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that site collaborator cannot delete a site member with Manager role and gets status code 422") + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + public void siteCollaboratorIsNotAbleToDeleteSiteMemberWithManagerRole() throws Exception + { + UserModel managerForDelete = dataUser.createRandomTestUser(); + dataUser.addUserToSite(managerForDelete, publicSiteModel, UserRole.SiteManager); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); + restClient.withCoreAPI().usingSite(publicSiteModel).deleteSiteMember(managerForDelete); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY) + .assertLastError().containsSummary(String.format(RestErrorModel.NOT_SUFFICIENT_PERMISSIONS, publicSiteModel.getId())); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that site contributor cannot delete site member with Manager role and gets status code 422") + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + public void siteContributorIsNotAbleToDeleteSiteMemberWithManagerRole() throws Exception + { + UserModel managerForDelete = dataUser.createRandomTestUser(); + dataUser.addUserToSite(managerForDelete, publicSiteModel, UserRole.SiteManager); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); + restClient.withCoreAPI().usingSite(publicSiteModel).deleteSiteMember(managerForDelete); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY) + .assertLastError().containsSummary(String.format(RestErrorModel.NOT_SUFFICIENT_PERMISSIONS, publicSiteModel.getId())); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that site consumer cannot delete site member with Manager role and gets status code 422") + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + public void siteConsumerIsNotAbleToDeleteSiteMemberWithManagerRole() throws Exception + { + UserModel managerForDelete = dataUser.createRandomTestUser(); + dataUser.addUserToSite(managerForDelete, publicSiteModel, UserRole.SiteManager); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)); + restClient.withCoreAPI().usingSite(publicSiteModel).deleteSiteMember(managerForDelete); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY) + .assertLastError().containsSummary(String.format(RestErrorModel.NOT_SUFFICIENT_PERMISSIONS, publicSiteModel.getId())); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that site collaborator cannot delete a site member with Contributor role and gets status code 422") + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + public void siteCollaboratorIsNotAbleToDeleteSiteMemberWithContributorRole() throws Exception + { + UserModel contributorForDelete = dataUser.createRandomTestUser(); + dataUser.addUserToSite(contributorForDelete, publicSiteModel, UserRole.SiteContributor); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); + restClient.withCoreAPI().usingSite(publicSiteModel).deleteSiteMember(contributorForDelete); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY) + .assertLastError().containsSummary(String.format(RestErrorModel.NOT_SUFFICIENT_PERMISSIONS, publicSiteModel.getId())); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that site contributor cannot delete site member with Contributor role and gets status code 422") + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + public void siteContributorIsNotAbleToDeleteSiteMemberWithContributorRole() throws Exception + { + UserModel contributorForDelete = dataUser.createRandomTestUser(); + dataUser.addUserToSite(contributorForDelete, publicSiteModel, UserRole.SiteContributor); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); + restClient.withCoreAPI().usingSite(publicSiteModel).deleteSiteMember(contributorForDelete); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY) + .assertLastError().containsSummary(String.format(RestErrorModel.NOT_SUFFICIENT_PERMISSIONS, publicSiteModel.getId())); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that site consumer cannot delete site member with Contributor role and gets status code 422") + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + public void siteConsumerIsNotAbleToDeleteSiteMemberWithContributorRole() throws Exception + { + UserModel contributorForDelete = dataUser.createRandomTestUser(); + dataUser.addUserToSite(contributorForDelete, publicSiteModel, UserRole.SiteContributor); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)); + restClient.withCoreAPI().usingSite(publicSiteModel).deleteSiteMember(contributorForDelete); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY) + .assertLastError().containsSummary(String.format(RestErrorModel.NOT_SUFFICIENT_PERMISSIONS, publicSiteModel.getId())); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that manager can delete a site member with Contributor role") + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + public void siteManagerIsAbleToDeleteSiteMemberWithContributorRole() throws Exception + { + UserModel contributorForDelete = dataUser.createRandomTestUser(); + dataUser.addUserToSite(contributorForDelete, publicSiteModel, UserRole.SiteContributor); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingSite(publicSiteModel).deleteSiteMember(contributorForDelete); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + restClient.withCoreAPI().usingSite(publicSiteModel).getSiteMembers() + .assertThat().entriesListDoesNotContain("id", contributorForDelete.getUsername()); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that site collaborator cannot delete a site member with Collaborator role and gets status code 422") + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + public void siteCollaboratorIsNotAbleToDeleteSiteMemberWithCollaboratorRole() throws Exception + { + UserModel collaboratorForDelete = dataUser.createRandomTestUser(); + dataUser.addUserToSite(collaboratorForDelete, publicSiteModel, UserRole.SiteCollaborator); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); + restClient.withCoreAPI().usingSite(publicSiteModel).deleteSiteMember(collaboratorForDelete); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY) + .assertLastError().containsSummary(String.format(RestErrorModel.NOT_SUFFICIENT_PERMISSIONS, publicSiteModel.getId())); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that site contributor cannot delete site member with Collaborator role and gets status code 422") + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + public void siteContributorIsNotAbleToDeleteSiteMemberWithCollaboratorRole() throws Exception + { + UserModel collaboratorForDelete = dataUser.createRandomTestUser(); + dataUser.addUserToSite(collaboratorForDelete, publicSiteModel, UserRole.SiteCollaborator); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); + restClient.withCoreAPI().usingSite(publicSiteModel).deleteSiteMember(collaboratorForDelete); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY) + .assertLastError().containsSummary(String.format(RestErrorModel.NOT_SUFFICIENT_PERMISSIONS, publicSiteModel.getId())); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that site consumer cannot delete site member with Collaborator role and gets status code 422") + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + public void siteConsumerIsNotAbleToDeleteSiteMemberWithCollaboratorRole() throws Exception + { + UserModel collaboratorForDelete = dataUser.createRandomTestUser(); + dataUser.addUserToSite(collaboratorForDelete, publicSiteModel, UserRole.SiteCollaborator); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)); + restClient.withCoreAPI().usingSite(publicSiteModel).deleteSiteMember(collaboratorForDelete); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY) + .assertLastError().containsSummary(String.format(RestErrorModel.NOT_SUFFICIENT_PERMISSIONS, publicSiteModel.getId())); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that manager can delete a site member with Collaborator role") + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + public void siteManagerIsAbleToDeleteSiteMemberWithCollaboratorRole() throws Exception + { + UserModel collaboratorForDelete = dataUser.createRandomTestUser(); + dataUser.addUserToSite(collaboratorForDelete, publicSiteModel, UserRole.SiteCollaborator); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingSite(publicSiteModel).deleteSiteMember(collaboratorForDelete); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + restClient.withCoreAPI().usingSite(publicSiteModel).getSiteMembers() + .assertThat().entriesListDoesNotContain("id", collaboratorForDelete.getUsername()); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that admin can delete a site member with Contributor role and gets status code 204") + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + public void adminIsAbleToDeleteSiteMemberWithContributorRole() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(publicSiteModel) + .deleteSiteMember(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + dataUser.addUserToSite(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor), publicSiteModel, UserRole.SiteContributor); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that admin can delete site member with Manager role and gets status code 204") + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + public void aminIsAbleToDeleteSiteMemberWithManagerRole() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(publicSiteModel) + .deleteSiteMember(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + dataUser.addUserToSite(usersWithRoles.getOneUserWithRole(UserRole.SiteManager), publicSiteModel, UserRole.SiteManager); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that admin can delete site member with Consumer role and gets status code 204") + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + public void adminIsAbleToDeleteSiteMemberWithConsumerRole() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(publicSiteModel) + .deleteSiteMember(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + dataUser.addUserToSite(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer), publicSiteModel, UserRole.SiteConsumer); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that admin can delete a site member with Collaborator role and gets status code 204") + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + public void adminIsAbleToDeleteSiteMemberWithCollaboratorRole() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(publicSiteModel) + .deleteSiteMember(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + dataUser.addUserToSite(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator), publicSiteModel, UserRole.SiteCollaborator); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that admin can delete a site member of moderated site and gets status code 204") + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + public void adminIsAbleToDeleteModeratedSiteMember() throws Exception + { + UserModel newMember = dataUser.createRandomTestUser(); + newMember.setUserRole(UserRole.SiteManager); + dataUser.addUserToSite(newMember, moderatedSiteModel, UserRole.SiteManager); + + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(moderatedSiteModel).deleteSiteMember(newMember); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that admin can delete a site member of private site and gets status code 204") + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + public void adminIsAbleToDeletePrivateSiteMember() throws Exception + { + UserModel newMember = dataUser.createRandomTestUser(); + newMember.setUserRole(UserRole.SiteManager); + dataUser.addUserToSite(newMember, privateSiteModel, UserRole.SiteManager); + + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(privateSiteModel).deleteSiteMember(newMember); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that regular user can not delete admin and gets status code 422") + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + public void regularUserIsNotAbleToDeleteASiteMember() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingSite(publicSiteModel) + .deleteSiteMember(siteCreator); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY).assertLastError() + .containsSummary(String.format(RestErrorModel.NOT_SUFFICIENT_PERMISSIONS, publicSiteModel.getTitle())) + .containsErrorKey(RestErrorModel.API_DEFAULT_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that admin can not delete a site member twice and gets status code 404 for the second attempt") + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @Bug(id="ACE-5447") + public void adminIsNotAbleToRemoveSiteMemberTwice() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(publicSiteModel) + .deleteSiteMember(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(publicSiteModel) + .deleteSiteMember(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(RestErrorModel.ENTITY_NOT_FOUND); + dataUser.addUserToSite(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor), publicSiteModel, UserRole.SiteContributor); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify admin is not able to remove from site a user that created a member request that was not accepted yet") + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @Bug(id="ACE-5447") + public void adminIsNotAbleToRemoveFromSiteANonExistingMember() throws Exception + { + UserModel newMember = dataUser.createRandomTestUser(); + restClient.authenticateUser(newMember).withCoreAPI().usingAuthUser().addSiteMembershipRequest(publicSiteModel); + + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(moderatedSiteModel).deleteSiteMember(newMember); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(RestErrorModel.ENTITY_NOT_FOUND); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/members/UpdateSiteMemberTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/members/UpdateSiteMemberTests.java new file mode 100644 index 0000000000..cb2fb09e8e --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/members/UpdateSiteMemberTests.java @@ -0,0 +1,545 @@ +package org.alfresco.rest.sites.members; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.JsonBodyGenerator; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestSiteMemberModel; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class UpdateSiteMemberTests extends RestTest +{ + private UserModel adminUser, siteCreator, regularUser; + private SiteModel publicSite, moderatedSite, privateSite; + private ListUserWithRoles publicSiteUsers; + private UserModel userToBeUpdated; + private RestSiteMemberModel updatedMember; + + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + siteCreator = dataUser.createRandomTestUser(); + publicSite = dataSite.usingUser(siteCreator).createPublicRandomSite(); + moderatedSite = dataSite.usingUser(siteCreator).createModeratedRandomSite(); + privateSite = dataSite.usingUser(siteCreator).createPrivateRandomSite(); + publicSiteUsers = dataUser.addUsersWithRolesToSite(publicSite, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, + UserRole.SiteContributor); + + regularUser = dataUser.createRandomTestUser(); + regularUser.setUserRole(UserRole.SiteConsumer); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that collaborator is not able to update site member and gets status code FORBIDDEN (403)") + public void collaboratorIsNotAbleToUpdateSiteMember() throws Exception + { + userToBeUpdated = dataUser.createRandomTestUser(); + dataUser.addUserToSite(userToBeUpdated, publicSite, UserRole.SiteConsumer); + userToBeUpdated.setUserRole(UserRole.SiteCollaborator); + restClient.authenticateUser(publicSiteUsers.getOneUserWithRole(UserRole.SiteCollaborator)); + restClient.withCoreAPI().usingSite(publicSite).updateSiteMember(userToBeUpdated); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY); + restClient.assertLastError() + .containsSummary(String.format("The current user does not have permissions to modify the membership details of the site %s.", publicSite.getTitle())); + } + + @Bug(id = "REPO-1832") + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that collaborator is not able to update site member and gets status code FORBIDDEN (403)") + public void collaboratorIsNotAbleToUpdateSiteMemberWithTheSameRole() throws Exception + { + userToBeUpdated = dataUser.createRandomTestUser(); + dataUser.addUserToSite(userToBeUpdated, publicSite, UserRole.SiteConsumer); + userToBeUpdated.setUserRole(UserRole.SiteConsumer); + restClient.authenticateUser(publicSiteUsers.getOneUserWithRole(UserRole.SiteCollaborator)); + restClient.withCoreAPI().usingSite(publicSite).updateSiteMember(userToBeUpdated); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY); + restClient.assertLastError() + .containsSummary(String.format("The current user does not have permissions to modify the membership details of the site %s.", publicSite.getTitle())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that contributor is not able to update site member and gets status code FORBIDDEN (403)") + public void contributorIsNotAbleToUpdateSiteMember() throws Exception + { + userToBeUpdated = dataUser.createRandomTestUser(); + dataUser.addUserToSite(userToBeUpdated, publicSite, UserRole.SiteConsumer); + userToBeUpdated.setUserRole(UserRole.SiteCollaborator); + restClient.authenticateUser(publicSiteUsers.getOneUserWithRole(UserRole.SiteContributor)); + restClient.withCoreAPI().usingSite(publicSite).updateSiteMember(userToBeUpdated); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY); + restClient.assertLastError() + .containsSummary(String.format("The current user does not have permissions to modify the membership details of the site %s.", publicSite.getTitle())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that consumer is not able to update site member and gets status code FORBIDDEN (403)") + public void consumerIsNotAbleToUpdateSiteMember() throws Exception + { + userToBeUpdated = dataUser.createRandomTestUser(); + dataUser.addUserToSite(userToBeUpdated, publicSite, UserRole.SiteConsumer); + userToBeUpdated.setUserRole(UserRole.SiteCollaborator); + restClient.authenticateUser(publicSiteUsers.getOneUserWithRole(UserRole.SiteConsumer)); + restClient.withCoreAPI().usingSite(publicSite).updateSiteMember(userToBeUpdated); + restClient.assertLastError() + .containsSummary(String.format("The current user does not have permissions to modify the membership details of the site %s.", publicSite.getTitle())); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that admin is able to update site member and gets status code OK (200)") + public void adminIsAbleToUpdateSiteMember() throws Exception + { + userToBeUpdated = dataUser.createRandomTestUser(); + dataUser.addUserToSite(userToBeUpdated, publicSite, UserRole.SiteConsumer); + userToBeUpdated.setUserRole(UserRole.SiteCollaborator); + restClient.authenticateUser(adminUser); + restClient.withCoreAPI().usingSite(publicSite).updateSiteMember(userToBeUpdated) + .assertThat().field("id").is(userToBeUpdated.getUsername()) + .and().field("role").is(userToBeUpdated.getUserRole()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.SANITY }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.SANITY, + description = "Verify that unauthenticated user is not able to update site member") +// @Bug(id="MNT-16904", description = "It fails only on environment with tenants") + public void unauthenticatedUserIsNotAuthorizedToUpdateSiteMmeber() throws Exception + { + userToBeUpdated = dataUser.createRandomTestUser(); + dataUser.addUserToSite(userToBeUpdated, publicSite, UserRole.SiteConsumer); + userToBeUpdated.setUserRole(UserRole.SiteCollaborator); + UserModel inexistentUser = new UserModel("inexistent user", "inexistent password"); + restClient.authenticateUser(inexistentUser); + restClient.withCoreAPI().usingSite(publicSite).updateSiteMember(userToBeUpdated); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if update site member request returns status code 404 when nonexistent siteId is used") + public void updateSiteMemberOfNonexistentSite() throws Exception + { + SiteModel deletedSite = dataSite.usingUser(adminUser).createPublicRandomSite(); + dataUser.addUserToSite(regularUser, deletedSite, UserRole.SiteConsumer); + dataSite.deleteSite(deletedSite); + + restClient.authenticateUser(adminUser).withCoreAPI() + .usingSite(deletedSite).updateSiteMember(regularUser); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, deletedSite.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if update site member request returns status code 400 when personId is not member of the site") + public void updateNotASiteMember() throws Exception + { + restClient.authenticateUser(adminUser).withCoreAPI() + .usingSite(publicSite).updateSiteMember(regularUser); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary("User is not a member of the site"); + } + + // @Bug(id="REPO-1642", description = "reproduced on 5.2.1 only, it works on 5.2.0") + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if update site member request returns status code 404 when personId does not exist") + public void updateNonexistentSiteMember() throws Exception + { + UserModel nonexistentUser = new UserModel("nonexistentUser", DataUser.PASSWORD); + nonexistentUser.setUserRole(UserRole.SiteContributor); + restClient.authenticateUser(adminUser).withCoreAPI() + .usingSite(publicSite).updateSiteMember(nonexistentUser); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, nonexistentUser.getUsername())); + } + + @Bug(id="REPO-1941") + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if a manager is able to downgrade to contributor using -me- string in place of personId.") + public void updateSiteManagerToSiteContributorUsingMe() throws Exception + { + UserModel meManager = dataUser.createRandomTestUser(); + dataUser.addUserToSite(meManager, publicSite, UserRole.SiteManager); + UserModel meUser = new UserModel("-me-", "password"); + meUser.setUserRole(UserRole.SiteContributor); + updatedMember = restClient.authenticateUser(meManager).withCoreAPI() + .usingSite(publicSite).updateSiteMember(meUser); + restClient.assertStatusCodeIs(HttpStatus.OK); + updatedMember.assertThat().field("id").is(meManager.getUsername()) + .and().field("role").is(meUser.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if update site member request returns status code 404 when empty siteId is used") + public void updateSiteMemberUsingEmptySiteId() throws Exception + { + restClient.authenticateUser(adminUser).withCoreAPI() + .usingSite("").updateSiteMember(regularUser); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "")); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if update site member request returns status code 405 when empty personId is used") + public void updateSiteMemberUsingEmptyPersonId() throws Exception + { + UserModel emptyUser = new UserModel("", DataUser.PASSWORD); + emptyUser.setUserRole(UserRole.SiteCollaborator); + restClient.authenticateUser(adminUser).withCoreAPI() + .usingSite(publicSite).updateSiteMember(emptyUser); + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED) + .assertLastError().containsSummary(RestErrorModel.PUT_EMPTY_ARGUMENT); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if update site member request returns status code 400 when invalid role is used") + public void updateSiteMemberUsingInvalidRole() throws Exception + { + restClient.authenticateUser(siteCreator).withCoreAPI(); + UserModel siteConsumer = publicSiteUsers.getOneUserWithRole(UserRole.SiteConsumer); + String json = JsonBodyGenerator.keyValueJson("role","invalidRole"); + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, json, "sites/{siteId}/members/{personId}", publicSite.getId(), siteConsumer.getUsername()); + restClient.processModel(RestSiteMemberModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.UNKNOWN_ROLE, "invalidRole")); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if manager is able to update another site manager to site collaborator") + public void managerUpdateSiteManagerToSiteCollaborator() throws Exception + { + UserModel siteManager = dataUser.createRandomTestUser(); + dataUser.addUserToSite(siteManager, publicSite, UserRole.SiteManager); + siteManager.setUserRole(UserRole.SiteCollaborator); + updatedMember = restClient.authenticateUser(siteCreator).withCoreAPI() + .usingSite(publicSite).updateSiteMember(siteManager); + restClient.assertStatusCodeIs(HttpStatus.OK); + updatedMember.assertThat().field("id").is(siteManager.getUsername()) + .and().field("role").is(siteManager.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if manager is able to update site contributor to site manager") + public void managerUpdateSiteContributorToSiteManager() throws Exception + { + UserModel siteContributor = publicSiteUsers.getOneUserWithRole(UserRole.SiteContributor); + siteContributor.setUserRole(UserRole.SiteManager); + updatedMember = restClient.authenticateUser(siteCreator).withCoreAPI() + .usingSite(publicSite).updateSiteMember(siteContributor); + restClient.assertStatusCodeIs(HttpStatus.OK); + updatedMember.assertThat().field("id").is(siteContributor.getUsername()) + .and().field("role").is(siteContributor.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if manager is able to update site collaborator to site manager") + public void managerUpdateSiteCollaboratorToSiteManager() throws Exception + { + UserModel siteCollaborator = publicSiteUsers.getOneUserWithRole(UserRole.SiteCollaborator); + siteCollaborator.setUserRole(UserRole.SiteManager); + updatedMember = restClient.authenticateUser(siteCreator).withCoreAPI() + .usingSite(publicSite).updateSiteMember(siteCollaborator); + restClient.assertStatusCodeIs(HttpStatus.OK); + updatedMember.assertThat().field("id").is(siteCollaborator.getUsername()) + .and().field("role").is(siteCollaborator.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.SANITY }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.SANITY, + description= "Verify if manager is able to update site consumer to site manager") + public void managerUpdateSiteConsumerToSiteManager() throws Exception + { + UserModel siteConsumer = publicSiteUsers.getOneUserWithRole(UserRole.SiteConsumer); + siteConsumer.setUserRole(UserRole.SiteManager); + updatedMember = restClient.authenticateUser(siteCreator).withCoreAPI() + .usingSite(publicSite).updateSiteMember(siteConsumer); + restClient.assertStatusCodeIs(HttpStatus.OK); + updatedMember.assertThat().field("id").is(siteConsumer.getUsername()) + .and().field("role").is(siteConsumer.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if manager is able to downgrade himself to site consumer") + public void publicSiteManagerDowngradesRole() throws Exception + { + UserModel siteManager = publicSiteUsers.getOneUserWithRole(UserRole.SiteManager); + siteManager.setUserRole(UserRole.SiteConsumer); + updatedMember = restClient.authenticateUser(siteManager).withCoreAPI() + .usingSite(publicSite).updateSiteMember(siteManager); + restClient.assertStatusCodeIs(HttpStatus.OK); + updatedMember.assertThat().field("id").is(siteManager.getUsername()) + .and().field("role").is(siteManager.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if manager is able to update another site manager to site contributor") + public void managerUpdateSiteManagerToSiteContributor() throws Exception + { + UserModel siteManager = dataUser.createRandomTestUser(); + dataUser.addUserToSite(siteManager, publicSite, UserRole.SiteManager); + + siteManager.setUserRole(UserRole.SiteContributor); + updatedMember = restClient.authenticateUser(siteCreator).withCoreAPI() + .usingSite(publicSite).updateSiteMember(siteManager); + restClient.assertStatusCodeIs(HttpStatus.OK); + updatedMember.assertThat().field("id").is(siteManager.getUsername()).and().field("role").is(siteManager.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if manager is able to update another site manager to site consumer") + public void managerUpdateSiteManagerToSiteConsumer() throws Exception + { + UserModel siteManager = dataUser.createRandomTestUser(); + dataUser.addUserToSite(siteManager, publicSite, UserRole.SiteManager); + + siteManager.setUserRole(UserRole.SiteConsumer); + updatedMember = restClient.authenticateUser(siteCreator).withCoreAPI() + .usingSite(publicSite).updateSiteMember(siteManager); + restClient.assertStatusCodeIs(HttpStatus.OK); + updatedMember.assertThat().field("id").is(siteManager.getUsername()).and().field("role").is(siteManager.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if manager is able to update site contributor to site collaborator") + public void managerUpdateSiteContributorToSiteCollaborator() throws Exception + { + UserModel siteContributor = dataUser.createRandomTestUser(); + dataUser.addUserToSite(siteContributor, publicSite, UserRole.SiteContributor); + + siteContributor.setUserRole(UserRole.SiteCollaborator); + updatedMember = restClient.authenticateUser(siteCreator).withCoreAPI() + .usingSite(publicSite).updateSiteMember(siteContributor); + restClient.assertStatusCodeIs(HttpStatus.OK); + updatedMember.assertThat().field("id").is(siteContributor.getUsername()).and().field("role").is(siteContributor.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if manager is able to update site contributor to site consumer") + public void managerUpdateSiteContributorToSiteConsumer() throws Exception + { + UserModel siteContributor = dataUser.createRandomTestUser(); + dataUser.addUserToSite(siteContributor, publicSite, UserRole.SiteContributor); + + siteContributor.setUserRole(UserRole.SiteConsumer); + updatedMember = restClient.authenticateUser(siteCreator).withCoreAPI() + .usingSite(publicSite).updateSiteMember(siteContributor); + restClient.assertStatusCodeIs(HttpStatus.OK); + updatedMember.assertThat().field("id").is(siteContributor.getUsername()).and().field("role").is(siteContributor.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if manager is able to update site collaborator to site contributor") + public void managerUpdateSiteCollaboratorToSiteContributor() throws Exception + { + UserModel siteCollaborator = dataUser.createRandomTestUser(); + dataUser.addUserToSite(siteCollaborator, publicSite, UserRole.SiteCollaborator); + + siteCollaborator.setUserRole(UserRole.SiteContributor); + updatedMember = restClient.authenticateUser(siteCreator).withCoreAPI() + .usingSite(publicSite).updateSiteMember(siteCollaborator); + restClient.assertStatusCodeIs(HttpStatus.OK); + updatedMember.assertThat().field("id").is(siteCollaborator.getUsername()).and().field("role").is(siteCollaborator.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if manager is able to update site collaborator to site consumer") + public void managerUpdateSiteCollaboratorToSiteConsumer() throws Exception + { + UserModel siteCollaborator = dataUser.createRandomTestUser(); + dataUser.addUserToSite(siteCollaborator, publicSite, UserRole.SiteCollaborator); + + siteCollaborator.setUserRole(UserRole.SiteConsumer); + updatedMember = restClient.authenticateUser(siteCreator).withCoreAPI() + .usingSite(publicSite).updateSiteMember(siteCollaborator); + restClient.assertStatusCodeIs(HttpStatus.OK); + updatedMember.assertThat().field("id").is(siteCollaborator.getUsername()).and().field("role").is(siteCollaborator.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if manager is able to update site consumer to site collaborator") + public void managerUpdateSiteConsumerToSiteCollaborator() throws Exception + { + UserModel siteConsumer = dataUser.createRandomTestUser(); + dataUser.addUserToSite(siteConsumer, publicSite, UserRole.SiteConsumer); + + siteConsumer.setUserRole(UserRole.SiteCollaborator); + updatedMember = restClient.authenticateUser(siteCreator).withCoreAPI() + .usingSite(publicSite).updateSiteMember(siteConsumer); + restClient.assertStatusCodeIs(HttpStatus.OK); + updatedMember.assertThat().field("id").is(siteConsumer.getUsername()).and().field("role").is(siteConsumer.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if manager is able to update site consumer to site contributor") + public void managerUpdateSiteConsumerToSiteContributor() throws Exception + { + UserModel siteConsumer = dataUser.createRandomTestUser(); + dataUser.addUserToSite(siteConsumer, publicSite, UserRole.SiteConsumer); + + siteConsumer.setUserRole(UserRole.SiteContributor); + updatedMember = restClient.authenticateUser(siteCreator).withCoreAPI() + .usingSite(publicSite).updateSiteMember(siteConsumer); + restClient.assertStatusCodeIs(HttpStatus.OK); + updatedMember.assertThat().field("id").is(siteConsumer.getUsername()).and().field("role").is(siteConsumer.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if manager is able to update another site manager to site manager") + public void managerUpdateSiteManagerToSiteManager() throws Exception + { + UserModel siteManager = dataUser.createRandomTestUser(); + dataUser.addUserToSite(siteManager, publicSite, UserRole.SiteManager); + + siteManager.setUserRole(UserRole.SiteManager); + updatedMember = restClient.authenticateUser(siteCreator).withCoreAPI() + .usingSite(publicSite).updateSiteMember(siteManager); + restClient.assertStatusCodeIs(HttpStatus.OK); + updatedMember.assertThat().field("id").is(siteManager.getUsername()).and().field("role").is(siteManager.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if manager is able to update site collaborator to site collaborator") + public void managerUpdateSiteCollaboratorToSiteCollaborator() throws Exception + { + UserModel siteCollaborator = dataUser.createRandomTestUser(); + dataUser.addUserToSite(siteCollaborator, publicSite, UserRole.SiteCollaborator); + + siteCollaborator.setUserRole(UserRole.SiteCollaborator); + updatedMember = restClient.authenticateUser(siteCreator).withCoreAPI() + .usingSite(publicSite).updateSiteMember(siteCollaborator); + restClient.assertStatusCodeIs(HttpStatus.OK); + updatedMember.assertThat().field("id").is(siteCollaborator.getUsername()).and().field("role").is(siteCollaborator.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if manager is able to update site contributor to site contributor") + public void managerUpdateSiteContributorToSiteContributor() throws Exception + { + UserModel siteContributor = dataUser.createRandomTestUser(); + dataUser.addUserToSite(siteContributor, publicSite, UserRole.SiteContributor); + + siteContributor.setUserRole(UserRole.SiteContributor); + updatedMember = restClient.authenticateUser(siteCreator).withCoreAPI() + .usingSite(publicSite).updateSiteMember(siteContributor); + restClient.assertStatusCodeIs(HttpStatus.OK); + updatedMember.assertThat().field("id").is(siteContributor.getUsername()).and().field("role").is(siteContributor.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if manager is able to update site consumer to site consumer") + public void managerUpdateSiteConsumerToSiteConsumer() throws Exception + { + UserModel siteConsumer = dataUser.createRandomTestUser(); + dataUser.addUserToSite(siteConsumer, publicSite, UserRole.SiteConsumer); + + siteConsumer.setUserRole(UserRole.SiteConsumer); + updatedMember = restClient.authenticateUser(siteCreator).withCoreAPI() + .usingSite(publicSite).updateSiteMember(siteConsumer); + restClient.assertStatusCodeIs(HttpStatus.OK); + updatedMember.assertThat().field("id").is(siteConsumer.getUsername()).and().field("role").is(siteConsumer.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if manager of a private site is able to downgrade his role") + public void privateSiteManagerDowngradesRole() throws Exception + { + UserModel siteManager = dataUser.createRandomTestUser(); + dataUser.addUserToSite(siteManager, privateSite, UserRole.SiteManager); + + siteManager.setUserRole(UserRole.SiteConsumer); + updatedMember = restClient.authenticateUser(siteManager).withCoreAPI() + .usingSite(privateSite).updateSiteMember(siteManager); + restClient.assertStatusCodeIs(HttpStatus.OK); + updatedMember.assertThat().field("id").is(siteManager.getUsername()).and().field("role").is(siteManager.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if manager of a moderated site is able to downgrade his role") + public void moderatedSiteManagerDowngradesRole() throws Exception + { + UserModel siteManager = dataUser.createRandomTestUser(); + dataUser.addUserToSite(siteManager, moderatedSite, UserRole.SiteManager); + + siteManager.setUserRole(UserRole.SiteConsumer); + updatedMember = restClient.authenticateUser(siteManager).withCoreAPI() + .usingSite(moderatedSite).updateSiteMember(siteManager); + restClient.assertStatusCodeIs(HttpStatus.OK); + updatedMember.assertThat().field("id").is(siteManager.getUsername()).and().field("role").is(siteManager.getUserRole()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify the response of updating a site member with empty body at request") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION }) + public void managerCanNotUpdateSiteMemberWithEmptyBody() throws Exception + { + restClient.authenticateUser(siteCreator).withCoreAPI(); + UserModel siteCollaborator = dataUser.createRandomTestUser(); + dataUser.addUserToSite(siteCollaborator, publicSite, UserRole.SiteCollaborator); + siteCollaborator.setUserRole(UserRole.SiteConsumer); + + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, "", "sites/{siteId}/members/{personId}", publicSite.getId(), siteCollaborator.getUsername()); + restClient.processModel(RestSiteMemberModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(String.format(RestErrorModel.NO_CONTENT, "No content to map due to end-of-input")) + .containsErrorKey(String.format(RestErrorModel.NO_CONTENT, "No content to map due to end-of-input")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.REGRESSION }) + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.REGRESSION, + description= "Verify if manager is able to update a user that has created a site membership request, but it's not a member of the site yet") + public void managerCanNotUpdateUserWithSiteMembershipRequest() throws Exception + { + UserModel siteConsumer = dataUser.createRandomTestUser(); + siteConsumer.setUserRole(UserRole.SiteConsumer); + restClient.authenticateUser(siteConsumer).withCoreAPI().usingUser(siteConsumer).addSiteMembershipRequest(moderatedSite); + + updatedMember = restClient.authenticateUser(siteCreator).withCoreAPI() + .usingSite(moderatedSite).updateSiteMember(siteConsumer); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(RestErrorModel.NOT_A_MEMBER); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/membershipRequests/AddSiteMembershipRequestTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/membershipRequests/AddSiteMembershipRequestTests.java new file mode 100644 index 0000000000..90acbee893 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/membershipRequests/AddSiteMembershipRequestTests.java @@ -0,0 +1,409 @@ +package org.alfresco.rest.sites.membershipRequests; + +import org.alfresco.dataprep.SiteService; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestSiteEntry; +import org.alfresco.rest.model.RestSiteMembershipRequestModel; +import org.alfresco.rest.model.RestSiteMembershipRequestModelsCollection; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.exception.DataPreparationException; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class AddSiteMembershipRequestTests extends RestTest +{ + private SiteModel publicSite, anotherPublicSite, moderatedSite, privateSite; + private DataUser.ListUserWithRoles usersWithRoles; + private UserModel adminUser, siteManager, regularUser, newMember; + private RestSiteMembershipRequestModel siteMembershipRequest; + private RestSiteMembershipRequestModelsCollection siteMembershipRequests; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws DataPreparationException + { + adminUser = dataUser.getAdminUser(); + publicSite = dataSite.usingUser(adminUser).createPublicRandomSite(); + usersWithRoles = dataUser.addUsersWithRolesToSite(publicSite, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, + UserRole.SiteContributor); + + siteManager = dataUser.createRandomTestUser(); + anotherPublicSite = dataSite.usingUser(siteManager).createPublicRandomSite(); + + moderatedSite = dataSite.usingUser(adminUser).createModeratedRandomSite(); + privateSite = dataSite.usingUser(adminUser).createPrivateRandomSite(); + + newMember = dataUser.createRandomTestUser(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, + description = "Verify site manager is able to create new site membership request for himself and status code is 201") + public void managerCreatesNewSiteMembershipRequestForSelf() throws Exception + { + siteMembershipRequest = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingAuthUser().addSiteMembershipRequest(anotherPublicSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + siteMembershipRequest.assertThat().field("id").is(anotherPublicSite.getId()) + .assertThat().field("site").isNotEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify site contributor is able to create new site membership request for himself and status code is 201") + public void contributorCreatesNewSiteMembershipRequestForSelf() throws Exception + { + siteMembershipRequest = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).withCoreAPI().usingAuthUser().addSiteMembershipRequest(anotherPublicSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + siteMembershipRequest.assertThat().field("id").is(anotherPublicSite.getId()) + .assertThat().field("site").isNotEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify site collaborator is able to create new site membership request for himself and status code is 201") + public void collaboratorCreatesNewSiteMembershipRequestForSelf() throws Exception + { + siteMembershipRequest = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingAuthUser().addSiteMembershipRequest(anotherPublicSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + siteMembershipRequest.assertThat().field("id").is(anotherPublicSite.getId()) + .assertThat().field("site").isNotEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify site consumer is able to create new site membership request for himself and status code is 201") + public void consumerCreatesNewSiteMembershipRequestForSelf() throws Exception + { + siteMembershipRequest = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI().usingAuthUser().addSiteMembershipRequest(anotherPublicSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + siteMembershipRequest.assertThat().field("id").is(anotherPublicSite.getId()) + .assertThat().field("site").isNotEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify admin is able to create new site membership request for himself and status code is 201") + public void adminCreatesNewSiteMembershipRequestForSelf() throws Exception + { + siteMembershipRequest = restClient.authenticateUser(adminUser).withCoreAPI().usingAuthUser().addSiteMembershipRequest(anotherPublicSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + siteMembershipRequest.assertThat().field("id").is(anotherPublicSite.getId()) + .assertThat().field("site").isNotEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, + description = "Verify unauthenticated user is not able to create new site membership request") + public void unauthenticatedUserIsNotAbleToCreateSiteMembershipRequest() throws Exception + { + restClient.authenticateUser(new UserModel("random user", "random password")).withCoreAPI().usingAuthUser().addSiteMembershipRequest(publicSite); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify addSiteMembershipRequest Rest API status code is 400 for a user that has already been invited") + public void addSiteMembershipRequestStatusCodeIs400ReceivedForAUserThatIsAlreadyInvited() throws Exception + { + UserModel newMember = dataUser.createRandomTestUser(); + dataUser.addUserToSite(newMember, moderatedSite, UserRole.SiteContributor); + restClient.authenticateUser(newMember).withCoreAPI().usingMe().addSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST); + restClient.assertLastError().containsSummary(String.format(RestErrorModel.ALREADY_Site_MEMBER, newMember.getUsername(), moderatedSite.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify addSiteMembershipRequest Rest API status code is 404 for a user that does not exist") + public void addSiteMembershipRequestStatusCodeIs404ReceivedForAUserThatDoesNotExist() throws Exception + { + UserModel newMember = dataUser.createRandomTestUser(); + restClient.authenticateUser(newMember).withCoreAPI().usingUser(new UserModel("invalidUser", "password")).addSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND); + restClient.assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "invalidUser")); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify addSiteMembershipRequest Rest API status code is 404 for a site that does not exist") + public void addSiteMembershipRequestStatusCodeIs404ReceivedForASiteThatDoesNotExist() throws Exception + { + UserModel newMember = dataUser.createRandomTestUser(); + restClient.authenticateUser(newMember).withCoreAPI().usingMe().addSiteMembershipRequest(new SiteModel("invalidSiteID")); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND); + restClient.assertLastError().containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, newMember.getUsername(), "invalidSiteID")); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify addSiteMembershipRequest Rest API status code is 400 for empty request body") + public void addSiteMembershipRequestStatusCodeIs400ForEmptyRequestBody() throws Exception + { + UserModel newMember = dataUser.createRandomTestUser(); + restClient.authenticateUser(newMember).withCoreAPI().usingMe().addSiteMembershipRequest(""); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.NO_CONTENT, "No content to map due to end-of-input")); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify addSiteMembershipRequest Rest API status code is 201 for request with empty message") + public void addSiteMembershipRequestStatusCodeIs201ForRequestWithEmptyMessage() throws Exception + { + UserModel newMember = dataUser.createRandomTestUser(); + siteMembershipRequest = restClient.authenticateUser(newMember).withCoreAPI().usingMe().addSiteMembershipRequest("", moderatedSite, "New request"); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + siteMembershipRequest.assertThat().field("id").is(moderatedSite.getId()).assertThat().field("site").isNotEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify addSiteMembershipRequest Rest API status code is 201 for request with empty title") + public void addSiteMembershipRequestStatusCodeIs201ForRequestWithEmptyTitle() throws Exception + { + UserModel newMember = dataUser.createRandomTestUser(); + siteMembershipRequest = restClient.authenticateUser(newMember).withCoreAPI().usingMe().addSiteMembershipRequest("Please accept me", moderatedSite, ""); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + siteMembershipRequest.assertThat().field("id").is(moderatedSite.getId()).assertThat().field("site").isNotEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify site manager is not able to create new site membership request for other user") + public void managerIsNotAbleToCreateSiteMembershipRequestForOtherUser() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingUser(newMember) + .addSiteMembershipRequest(publicSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, newMember.getUsername())) + .statusCodeIs(HttpStatus.NOT_FOUND) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE) + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify site collaborator is not able to create new site membership request for other user") + public void collaboratorIsNotAbleToCreateSiteMembershipRequestForOtherUser() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingUser(newMember) + .addSiteMembershipRequest(publicSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, newMember.getUsername())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify site contributor is not able to create new site membership request for other user") + public void contributorIsNotAbleToCreateSiteMembershipRequestForOtherUser() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).withCoreAPI().usingUser(newMember) + .addSiteMembershipRequest(publicSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, newMember.getUsername())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify site consumer is not able to create new site membership request for other user") + public void consumerIsNotAbleToCreateSiteMembershipRequestForOtherUser() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI().usingUser(newMember) + .addSiteMembershipRequest(publicSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, newMember.getUsername())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify admin user is not able to create new site membership request for other user") + public void adminIsNotAbleToCreateSiteMembershipRequestForOtherUser() throws Exception + { + restClient.authenticateUser(adminUser).withCoreAPI().usingUser(newMember).addSiteMembershipRequest(publicSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, newMember.getUsername())); + + restClient.withCoreAPI().usingUser(newMember).addSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, newMember.getUsername())); + + restClient.withCoreAPI().usingUser(newMember).addSiteMembershipRequest(privateSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, newMember.getUsername())); + } + + @Bug(id="ACE-2413") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify addSiteMembershipRequest Rest API status code is 400 for an invalid user id") + public void addSiteMembershipRequestReturns400ForEmptyUserId() throws Exception + { + restClient.authenticateUser(adminUser).withCoreAPI() + .usingUser(new UserModel("", "password")).addSiteMembershipRequest(publicSite); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify regular user is able to create new public site membership request for himself. Check that user joins immediately as consumer.") + public void userIsAbleToRequestMembershipOfPublicSite() throws Exception + { + regularUser = dataUser.createRandomTestUser(); + siteMembershipRequest = restClient.authenticateUser(regularUser).withCoreAPI().usingAuthUser().addSiteMembershipRequest(publicSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + siteMembershipRequest.assertThat().field("id").is(publicSite.getId()) + .assertThat().field("site").isNotEmpty(); + RestSiteEntry siteEntry = restClient.withCoreAPI().usingAuthUser().getSiteMembership(publicSite); + restClient.assertStatusCodeIs(HttpStatus.OK); + siteEntry.assertThat().field("role").is(UserRole.SiteConsumer) + .and().field("id").is(publicSite.getId()); + siteMembershipRequests = restClient.withCoreAPI().usingAuthUser().getSiteMembershipRequests(); + restClient.assertStatusCodeIs(HttpStatus.OK); + siteMembershipRequests.assertThat().entriesListIsEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify regular user is able to create new moderated site membership request for himself. Check that the request is added to the site membership request list.") + public void userIsAbleToRequestMembershipOfModeratedSite() throws Exception + { + regularUser = dataUser.createRandomTestUser(); + siteMembershipRequest = restClient.authenticateUser(regularUser).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + siteMembershipRequest.assertThat().field("id").is(moderatedSite.getId()) + .assertThat().field("message").is("Please accept me") + .assertThat().field("site").isNotEmpty(); + siteMembershipRequest.getSite() + .assertThat().field("visibility").is(moderatedSite.getVisibility()) + .assertThat().field("guid").is(moderatedSite.getGuid()) + .assertThat().field("description").is(moderatedSite.getDescription()) + .assertThat().field("id").is(moderatedSite.getId()) + .assertThat().field("title").is(moderatedSite.getTitle()); + + siteMembershipRequests = restClient.withCoreAPI().usingAuthUser().getSiteMembershipRequests(); + restClient.assertStatusCodeIs(HttpStatus.OK); + siteMembershipRequests.assertThat().entriesListContains("id", moderatedSite.getId()) + .assertThat().entriesListCountIs(1); + + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify regular user is not able to request membership of a private site.") + public void userIsNotAbleToRequestMembershipOfPrivateSite() throws Exception + { + regularUser = dataUser.createRandomTestUser(); + restClient.authenticateUser(regularUser).withCoreAPI().usingAuthUser().addSiteMembershipRequest(privateSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, regularUser.getUsername(), privateSite.getId())); + siteMembershipRequests = restClient.withCoreAPI().usingAuthUser().getSiteMembershipRequests(); + restClient.assertStatusCodeIs(HttpStatus.OK); + siteMembershipRequests.assertThat().entriesListIsEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify regular user is not able to create new site membership request for other user") + public void regularUserIsNotAbleToCreateSiteMembershipRequestForOtherUser() throws Exception + { + regularUser = dataUser.createRandomTestUser(); + restClient.authenticateUser(regularUser).withCoreAPI().usingUser(newMember) + .addSiteMembershipRequest(publicSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, newMember.getUsername())); + + restClient.withCoreAPI().usingUser(newMember).addSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, newMember.getUsername())); + + restClient.withCoreAPI().usingUser(newMember).addSiteMembershipRequest(privateSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, newMember.getUsername())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify create public site membership request returns status code 400 when the request is made twice") + public void userRequestsTwiceMembershipOfPublicSite() throws Exception + { + regularUser = dataUser.createRandomTestUser(); + siteMembershipRequest = restClient.authenticateUser(regularUser).withCoreAPI().usingAuthUser().addSiteMembershipRequest(publicSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + siteMembershipRequest.assertThat().field("id").is(publicSite.getId()) + .assertThat().field("site").isNotEmpty(); + restClient.withCoreAPI().usingAuthUser().addSiteMembershipRequest(publicSite); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST); + restClient.assertLastError().containsSummary(String.format(RestErrorModel.ALREADY_Site_MEMBER, regularUser.getUsername(), publicSite.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify create moderated site membership request returns status code 400 when the request is made twice") + public void userRequestsTwiceMembershipOfModeratedSite() throws Exception + { + regularUser = dataUser.createRandomTestUser(); + siteMembershipRequest = restClient.authenticateUser(regularUser).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + siteMembershipRequest.assertThat().field("id").is(moderatedSite.getId()) + .assertThat().field("site").isNotEmpty(); + restClient.withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST); + restClient.assertLastError().containsSummary(String.format(RestErrorModel.ALREADY_INVITED, regularUser.getUsername(), moderatedSite.getId())); + + siteMembershipRequests = restClient.withCoreAPI().usingAuthUser().getSiteMembershipRequests(); + restClient.assertStatusCodeIs(HttpStatus.OK); + siteMembershipRequests.assertThat().entriesListContains("id", moderatedSite.getId()) + .assertThat().entriesListCountIs(1); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify create private site membership request returns status code 404 when request is made with the user who created the site") + public void siteCreatorRequestsMembershipOfHisPrivateSite() throws Exception + { + restClient.authenticateUser(adminUser).withCoreAPI().usingAuthUser().addSiteMembershipRequest(privateSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, adminUser.getUsername(), privateSite.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify create moderated site membership request returns status code 400 when request is made with the user who created the site") + public void siteCreatorRequestsMembershipOfHisModeratedSite() throws Exception + { + restClient.authenticateUser(adminUser).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.ALREADY_Site_MEMBER, adminUser.getUsername(), moderatedSite.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify admin is able to create new moderated site membership request for himself. Check that the request is added to the site membership request list.") + public void adminIsAbleToRequestMembershipOfModeratedSite() throws Exception + { + regularUser = dataUser.createRandomTestUser(); + SiteModel anotherModeratedSite = dataSite.usingUser(regularUser).createModeratedRandomSite(); + siteMembershipRequest = restClient.authenticateUser(adminUser).withCoreAPI().usingAuthUser().addSiteMembershipRequest(anotherModeratedSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + siteMembershipRequest.assertThat().field("id").is(anotherModeratedSite.getId()) + .assertThat().field("site").isNotEmpty(); + siteMembershipRequests = restClient.withCoreAPI().usingAuthUser().getSiteMembershipRequests(); + restClient.assertStatusCodeIs(HttpStatus.OK); + siteMembershipRequests.assertThat().entriesListContains("id", anotherModeratedSite.getId()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify site membership request is automatically rejected when a site is switched from moderated to private") + public void siteMembershipRequestIsRejectedWhenSiteIsSwitchedFromModeratedToPrivate() throws Exception + { + regularUser = dataUser.createRandomTestUser(); + SiteModel moderatedThenPrivateSite = dataSite.usingUser(adminUser).createModeratedRandomSite(); + siteMembershipRequest = restClient.authenticateUser(regularUser).withCoreAPI().usingMe().addSiteMembershipRequest(moderatedThenPrivateSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + siteMembershipRequest.assertThat().field("id").is(moderatedThenPrivateSite.getId()) + .assertThat().field("site").isNotEmpty(); + + dataSite.usingUser(adminUser).updateSiteVisibility(moderatedThenPrivateSite, SiteService.Visibility.PRIVATE); + + siteMembershipRequests = restClient.withCoreAPI().usingAuthUser().getSiteMembershipRequests(); + restClient.assertStatusCodeIs(HttpStatus.OK); + siteMembershipRequests.assertThat().entriesListIsEmpty(); + } +} \ No newline at end of file diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/membershipRequests/DeleteSiteMembershipRequestTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/membershipRequests/DeleteSiteMembershipRequestTests.java new file mode 100644 index 0000000000..46ac8f11f2 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/membershipRequests/DeleteSiteMembershipRequestTests.java @@ -0,0 +1,316 @@ +package org.alfresco.rest.sites.membershipRequests; + +import org.alfresco.dataprep.SiteService.Visibility; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestSiteMembershipRequestModelsCollection; +import org.alfresco.rest.model.RestTaskModel; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; +import org.alfresco.utility.data.RandomData; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * @author iulia.cojocea + */ + +public class DeleteSiteMembershipRequestTests extends RestTest +{ + UserModel siteCreator, adminUserModel, secondSiteCreator, siteMember; + SiteModel moderatedSite, secondModeratedSite, publicSite; + private ListUserWithRoles usersWithRoles; + RestSiteMembershipRequestModelsCollection siteMembershipRequests; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUserModel = dataUser.getAdminUser(); + siteCreator = dataUser.createRandomTestUser(); + secondSiteCreator = dataUser.createRandomTestUser(); + String siteId = RandomData.getRandomName("site"); + moderatedSite = dataSite.usingUser(siteCreator).createSite(new SiteModel(Visibility.MODERATED, siteId, siteId, siteId, siteId)); + usersWithRoles = dataUser.addUsersWithRolesToSite(moderatedSite, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, + UserRole.SiteContributor); + + dataUser.addUserToSite(adminUserModel, moderatedSite, UserRole.SiteManager); + secondModeratedSite = dataSite.usingUser(secondSiteCreator).createModeratedRandomSite(); + publicSite = dataSite.usingUser(siteCreator).createPublicRandomSite(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, description = "Verify one user is able to delete his one site memebership request") + public void userCanDeleteHisOwnSiteMembershipRequest() throws Exception + { + restClient.authenticateUser(secondSiteCreator).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.withCoreAPI().usingUser(secondSiteCreator).deleteSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, description = "Verify site manager is able to delete site membership request") + public void managerCanDeleteSiteMembershipRequest() throws Exception + { + siteMember = dataUser.createRandomTestUser(); + restClient.authenticateUser(siteMember).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingUser(siteMember) + .deleteSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + restClient.withCoreAPI().usingUser(siteMember).getSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsErrorKey(RestErrorModel.RELATIONSHIP_NOT_FOUND_ERRORKEY) + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, siteMember.getUsername(), moderatedSite.getTitle())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify admin user is able to delete site memebership request") + public void adminUserCanDeleteSiteMembershipRequest() throws Exception + { + siteMember = dataUser.createRandomTestUser(); + restClient.authenticateUser(siteMember).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(siteMember).deleteSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @Bug(id = "REPO-1946") + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify collaborator user is not able to delete site memebership request") + public void collaboratorCannotDeleteSiteMembershipRequest() throws Exception + { + siteMember = dataUser.createRandomTestUser(); + restClient.authenticateUser(siteMember).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingUser(siteMember) + .deleteSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @Bug(id = "REPO-1946") + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify contributor user is not able to delete site memebership request") + public void contributorCannotDeleteSiteMembershipRequest() throws Exception + { + siteMember = dataUser.createRandomTestUser(); + restClient.authenticateUser(siteMember).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).withCoreAPI().usingUser(siteMember) + .deleteSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @Bug(id = "REPO-1946") + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, description = "Verify consumer user is not able to delete site memebership request") + public void consumerCannotDeleteSiteMembershipRequest() throws Exception + { + siteMember = dataUser.createRandomTestUser(); + restClient.authenticateUser(siteMember).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI().usingUser(siteMember) + .deleteSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @Bug(id = "REPO-1946") + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify random user is not able to delete site memebership request") + public void randomUserCanNotDeleteSiteMembershipRequest() throws Exception + { + siteMember = dataUser.createRandomTestUser(); + restClient.authenticateUser(siteMember).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite); + + restClient.authenticateUser(dataUser.createRandomTestUser()).withCoreAPI().usingUser(siteMember).deleteSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.SANITY, description = "Failed authentication get site member call returns status code 401") +// @Bug(id = "MNT-16904") + public void unauthenticatedUserIsNotAuthorizedToDeleteSiteMmebershipRequest() throws Exception + { + restClient.authenticateUser(dataUser.createRandomTestUser()).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite); + UserModel inexistentUser = new UserModel("inexistent user", "inexistent password"); + restClient.authenticateUser(inexistentUser).withCoreAPI().usingAuthUser().deleteSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify user is able to remove his own site memebership request using '-me-' in place of personId and response is successful (204)") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void userCanDeleteHisOwnSiteMembershipRequestUsingMeAsPersonId() throws Exception + { + restClient.authenticateUser(secondSiteCreator).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite); + restClient.withCoreAPI().usingMe().deleteSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify user is not able to remove a site memebership request of an inexistent user and response is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void adminIsNotAbleToDeleteSiteMembershipRequestOfAnInexistentUser() throws Exception + { + UserModel inexistentUser = new UserModel("inexistenUser", "password"); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(inexistentUser).deleteSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, inexistentUser.getUsername())); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify user is not able to remove a site memebership request to an inexistent site and response is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void adminIsNotAbleToDeleteSiteMembershipRequestToAnInexistentSite() throws Exception + { + SiteModel inexistentSite = new SiteModel("inexistentSite"); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(adminUserModel).deleteSiteMembershipRequest(inexistentSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, adminUserModel.getUsername(), inexistentSite.getId())); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify user is not able to remove a site memebership request to an empty site id and response is 405") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void adminIsNotAbleToDeleteSiteMembershipRequestWithEmptySiteId() throws Exception + { + SiteModel inexistentSite = new SiteModel(""); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(adminUserModel).deleteSiteMembershipRequest(inexistentSite); + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED).assertLastError().containsSummary(RestErrorModel.DELETE_EMPTY_ARGUMENT); + } + + @Bug(id = "REPO-1946") + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify contributor user is not able to remove a site memebership request of admin to a moderated site and response is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void contributorIsNotAbleToDeleteSiteMembershipRequestOfAdminToAModeratedSite() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).withCoreAPI().usingUser(adminUserModel).deleteSiteMembershipRequest(secondModeratedSite); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify manager is able to remove a site memebership request of admin to a moderated site and response is 204") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void managerUserIsAbleToDeleteSiteMembershipRequestOfAdminToAModeratedSite() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingAuthUser().addSiteMembershipRequest(secondModeratedSite); + restClient.authenticateUser(secondSiteCreator).withCoreAPI().usingUser(adminUserModel).deleteSiteMembershipRequest(secondModeratedSite); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify manager is not able to remove a site memebership request if it was already approved and response is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void managerUserIsNotAbleToDeleteASiteMembershipRequestIfItWasAlreadyApproved() throws Exception + { + siteMember.setUserRole(UserRole.SiteCollaborator); + restClient.authenticateUser(siteMember).withCoreAPI().usingAuthUser().addSiteMembershipRequest(secondModeratedSite); + RestTaskModel taskModel = restClient.authenticateUser(siteMember).withWorkflowAPI().getTasks().getTaskModelByDescription(secondModeratedSite); + workflow.approveSiteMembershipRequest(secondSiteCreator.getUsername(), secondSiteCreator.getPassword(), taskModel.getId(), true, "Approve"); + + restClient.authenticateUser(secondSiteCreator).withCoreAPI().usingUser(siteMember).deleteSiteMembershipRequest(secondModeratedSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, siteMember.getUsername(), secondModeratedSite.getId())); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify manager is not able to remove an inexitent site memebership request and response is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void managerUserIsNotAbleToDeleteAnInexistentSiteMembershipRequest() throws Exception + { + restClient.authenticateUser(secondSiteCreator).withCoreAPI().usingUser(adminUserModel).deleteSiteMembershipRequest(secondModeratedSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, adminUserModel.getUsername(), secondModeratedSite.getId())); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify collaborator user is not able to remove a site memebership request of admin to a public site and response is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void collaboratorIsNotAbleToDeleteSiteMembershipRequestOfAdminToAPublicSite() throws Exception + { + UserModel userCollaborator = usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator); + restClient.authenticateUser(siteMember).withCoreAPI().usingSite(publicSite).addPerson(userCollaborator); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingAuthUser().addSiteMembershipRequest(publicSite); + + restClient.authenticateUser(userCollaborator).withCoreAPI().usingUser(adminUserModel).deleteSiteMembershipRequest(publicSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsErrorKey(RestErrorModel.RELATIONSHIP_NOT_FOUND_ERRORKEY) + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, adminUserModel.getUsername(), publicSite.getId())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Delete a rejected site membership request.") + public void deleteARejectedSiteMembershipRequest() throws Exception + { + UserModel userWithRejectedRequests = dataUser.createRandomTestUser(); + restClient.authenticateUser(userWithRejectedRequests).withCoreAPI().usingAuthUser().addSiteMembershipRequest(secondModeratedSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + RestTaskModel taskModel = restClient.authenticateUser(userWithRejectedRequests).withWorkflowAPI().getTasks() + .getTaskModelByDescription(secondModeratedSite); + workflow.approveSiteMembershipRequest(secondSiteCreator.getUsername(), secondSiteCreator.getPassword(), taskModel.getId(), false, "Rejected"); + + siteMembershipRequests = restClient.authenticateUser(userWithRejectedRequests).withCoreAPI().usingMe().getSiteMembershipRequests(); + restClient.assertStatusCodeIs(HttpStatus.OK); + siteMembershipRequests.assertThat().entriesListDoesNotContain("id", secondModeratedSite.getId()); + + restClient.authenticateUser(secondSiteCreator).withCoreAPI().usingUser(userWithRejectedRequests).deleteSiteMembershipRequest(secondModeratedSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsErrorKey(RestErrorModel.RELATIONSHIP_NOT_FOUND_ERRORKEY) + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, userWithRejectedRequests.getUsername(), secondModeratedSite.getId())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Bug(id="ACE-2413") + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify user is not able to remove a site memebership request- empty person id and response is 400") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void adminIsNotAbleToDeleteSiteMembershipRequestEmptyPersonID() throws Exception + { + UserModel emptyPersonId = new UserModel("", "password"); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(emptyPersonId).deleteSiteMembershipRequest(moderatedSite); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsErrorKey(RestErrorModel.API_DEFAULT_ERRORKEY) + .containsSummary(RestErrorModel.ENTITY_NOT_FOUND) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify manager removes/cancel twice same site memebership request and response is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void managerCancelsTwiceSiteMembershipRequestModeratedSite() throws Exception + { + siteMember = dataUser.createRandomTestUser(); + restClient.authenticateUser(siteMember).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite); + + restClient.authenticateUser(siteCreator).withCoreAPI().usingUser(siteMember).deleteSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withCoreAPI().usingUser(siteMember).deleteSiteMembershipRequest(moderatedSite); + + restClient.withCoreAPI().usingUser(siteMember).getSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsErrorKey(RestErrorModel.RELATIONSHIP_NOT_FOUND_ERRORKEY) + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, siteMember.getUsername(), moderatedSite.getTitle())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/membershipRequests/GetSiteMembershipRequestTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/membershipRequests/GetSiteMembershipRequestTests.java new file mode 100644 index 0000000000..57ef4c55cf --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/membershipRequests/GetSiteMembershipRequestTests.java @@ -0,0 +1,330 @@ +package org.alfresco.rest.sites.membershipRequests; + +import org.alfresco.dataprep.SiteService; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestSiteMembershipRequestModel; +import org.alfresco.rest.model.RestTaskModel; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class GetSiteMembershipRequestTests extends RestTest +{ + private SiteModel publicSite, moderatedSite; + private ListUserWithRoles usersWithRoles; + private UserModel adminUser, siteCreator, newMember; + private RestSiteMembershipRequestModel returnedModel; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + publicSite = dataSite.usingUser(adminUser).createPublicRandomSite(); + + siteCreator = dataUser.createRandomTestUser(); + moderatedSite = dataSite.usingUser(siteCreator).createModeratedRandomSite(); + + usersWithRoles = dataUser.addUsersWithRolesToSite(moderatedSite, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, + UserRole.SiteContributor); + + newMember = dataUser.createRandomTestUser(); + restClient.authenticateUser(newMember).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, description = "Verify site manager is able to retrieve site membership request") + public void siteManagerIsAbleToRetrieveSiteMembershipRequest() throws Exception + { + returnedModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingUser(newMember).getSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedModel.assertThat().field("id").is(moderatedSite.getId()) + .and().field("message").is("Please accept me") + .and().field("site.title").is(moderatedSite.getTitle()) + .and().field("site.visibility").is(SiteService.Visibility.MODERATED.toString()) + .and().field("site.guid").isNotEmpty() + .and().field("site.description").is(moderatedSite.getDescription()) + .and().field("site.preset").is("site-dashboard"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify site collaborator is able to retrieve site membership request") + public void siteCollaboratorIsNotAbleToRetrieveSiteMembershipRequest() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingUser(newMember).getSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify site contributor is able to retrieve site membership request") + public void siteContributorIsNotAbleToRetrieveSiteMembershipRequest() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).withCoreAPI().usingUser(newMember).getSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify site consumer is able to retrieve site membership request") + public void siteConsumerIsNotAbleToRetrieveSiteMembershipRequest() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI().usingUser(newMember).getSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify admin user is able to retrieve site membership request") + public void adminIsAbleToRetrieveSiteMembershipRequest() throws Exception + { + returnedModel = restClient.authenticateUser(adminUser).withCoreAPI().usingUser(newMember).getSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedModel.assertThat().field("id").is(moderatedSite.getId()) + .and().field("message").is("Please accept me") + .and().field("site.title").is(moderatedSite.getTitle()) + .and().field("site.visibility").is(SiteService.Visibility.MODERATED.toString()) + .and().field("site.guid").isNotEmpty() + .and().field("site.description").is(moderatedSite.getDescription()) + .and().field("site.preset").is("site-dashboard"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, + description = "Verify user fails to get all site membership requests of a specific person with Rest API when the authentication fails (401)") + public void unauthorizedUserFailsToGetSiteMembershipRequests() throws Exception + { + UserModel manager = dataUser.usingAdmin().createRandomTestUser(); + dataUser.usingUser(siteCreator).addUserToSite(manager, moderatedSite, UserRole.SiteManager); + manager.setPassword("newpassword"); + restClient.authenticateUser(manager).withCoreAPI().usingUser(newMember).getSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, + TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify a user gets all its own site membership requests using '-me-' with Rest API and response is successful (200)") + public void usingMeGetSiteMembershipRequestsWithSuccess() throws Exception + { + restClient.authenticateUser(newMember).withCoreAPI().usingMe().getSiteMembershipRequest(moderatedSite).assertThat().field("id").is(moderatedSite.getId()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, + TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify site manager can't get site membership requests for inexistent user and response is not found (404)") + public void siteManagerCantGetSiteMembershipRequestsInexistentUser() throws Exception + { + restClient.authenticateUser(newMember).withCoreAPI().usingUser(UserModel.getRandomUserModel()).getSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "")); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, + TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify user can get site membership requests on site with no requests and response is successful (200)") + public void userWithNoRequestsCantGetSiteMembershipRequests() throws Exception + { + UserModel noRequestUser = dataUser.createRandomTestUser(); + restClient.authenticateUser(noRequestUser).withCoreAPI().usingMe().getSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, noRequestUser.getUsername(), moderatedSite.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, + TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify site manager can't get site membership requests on public site and response is not found (404)") + public void siteManagerCantGetPublicSiteMembershipRequests() throws Exception + { + UserModel publicUser = dataUser.createRandomTestUser(); + restClient.authenticateUser(publicUser).withCoreAPI().usingAuthUser().addSiteMembershipRequest(publicSite); + restClient.authenticateUser(adminUser).withCoreAPI() + .usingUser(publicUser).getSiteMembershipRequest(publicSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, publicUser.getUsername(), publicSite.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, + TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify site manager can't get site membership requests on private site and response is not found (404)") + public void siteManagerCantGetPrivateSiteMembershipRequests() throws Exception + { + UserModel privateUser = dataUser.createRandomTestUser(); + SiteModel privateSite = dataSite.usingUser(siteCreator).createPrivateRandomSite(); + restClient.authenticateUser(privateUser).withCoreAPI().usingAuthUser().addSiteMembershipRequest(privateSite); + restClient.authenticateUser(siteCreator).withCoreAPI().usingUser(privateUser).getSiteMembershipRequest(privateSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, privateUser.getUsername(), privateSite.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, + TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify site manager can't get site membership requests for inexistent site and response is not found (404)") + public void siteManagerCantGetSiteMembershipRequestsForInexistentSite() throws Exception + { + SiteModel inexistentSite = SiteModel.getRandomSiteModel(); + restClient.authenticateUser(siteCreator).withCoreAPI().usingMe().getSiteMembershipRequest(inexistentSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, siteCreator.getUsername(), inexistentSite.getId())); + } + + @Bug(id = "ACE-2413") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify if person ID field is empty user can't get site membership requests on moderated site and response is not found (400)") + public void emptyPersonIdCantGetModeratedSiteMembershipRequests() throws Exception + { + UserModel emptyUser = new UserModel("", "password"); + restClient.authenticateUser(siteCreator).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite); + restClient.authenticateUser(siteCreator).withCoreAPI().usingUser(emptyUser).getSiteMembershipRequest(moderatedSite); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsErrorKey(RestErrorModel.API_DEFAULT_ERRORKEY) + .containsSummary(String.format("The entity with id: personId is null. was not found")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Approve site membership request then verify get site membership requests - response is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void approveRequestThenGetSiteMembershipRequest() throws Exception + { + UserModel userWithApprovedRequests = dataUser.createRandomTestUser(); + restClient.authenticateUser(userWithApprovedRequests).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + RestTaskModel taskModel = restClient.authenticateUser(userWithApprovedRequests).withWorkflowAPI().getTasks().getTaskModelByDescription(moderatedSite); + workflow.approveSiteMembershipRequest(siteCreator.getUsername(), siteCreator.getPassword(), taskModel.getId(), true, "Approve"); + + returnedModel = restClient.authenticateUser(userWithApprovedRequests).withCoreAPI().usingMe().getSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, userWithApprovedRequests.getUsername(), moderatedSite.getId())) + .containsErrorKey(RestErrorModel.RELATIONSHIP_NOT_FOUND_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Reject site membership request then verify get site membership requests - response is 404") + public void rejectRequestThenGetSiteMembershipRequest() throws Exception + { + UserModel userWithRejectedRequests = dataUser.createRandomTestUser(); + restClient.authenticateUser(userWithRejectedRequests).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + RestTaskModel taskModel = restClient.authenticateUser(userWithRejectedRequests).withWorkflowAPI().getTasks().getTaskModelByDescription(moderatedSite); + workflow.approveSiteMembershipRequest(siteCreator.getUsername(), siteCreator.getPassword(), taskModel.getId(), false, "Rejected"); + + returnedModel = restClient.authenticateUser(userWithRejectedRequests).withCoreAPI().usingMe().getSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, userWithRejectedRequests.getUsername(), moderatedSite.getId())) + .containsErrorKey(RestErrorModel.RELATIONSHIP_NOT_FOUND_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify entry details for get site favorite response with Rest API") + public void checkResponseSchemaForGetSiteMembershipRequest() throws Exception + { + dataUser.usingUser(siteCreator).addUserToSite(newMember, moderatedSite, UserRole.SiteContributor); + returnedModel = restClient.authenticateUser(newMember).withCoreAPI().usingAuthUser().getSiteMembershipRequest(moderatedSite); + + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedModel.assertThat().field("id").is(moderatedSite.getId()) + .and().field("message").is("Please accept me") + .and().field("site.title").is(moderatedSite.getTitle()) + .and().field("site.visibility").is(SiteService.Visibility.MODERATED.toString()) + .and().field("site.guid").isNotEmpty() + .and().field("site.description").is(moderatedSite.getDescription()) + .and().field("site.preset").is("site-dashboard") + .and().field("site.role").is("SiteContributor"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify that getFavoriteSites request applies valid properties param") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void getSiteMembershipRequestWithValidPropertiesParam() throws Exception + { + RestSiteMembershipRequestModel returnedModel = restClient.authenticateUser(newMember).withParams("properties=message").withCoreAPI().usingAuthUser() + .getSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedModel.assertThat().fieldsCount().is(1).assertThat().field("message").isNotEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify that getFavoriteSites request returns status 200 when using valid parameters") + public void getSiteMembershipRequestUsingParameters() throws Exception + { + RestSiteMembershipRequestModel returnedModel = restClient.withParams("message=Please accept me") + .authenticateUser(newMember).withCoreAPI().usingMe() + .getSiteMembershipRequest(moderatedSite); + + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedModel.assertThat().field("id").is(moderatedSite.getId()).and().field("site.title").is(moderatedSite.getTitle()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify user doesn't have permission to get site membership request of admin without membership request with Rest API and status code is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void userIsNotAbleToGetSiteMembershipRequestOfAdminWithoutRequest() throws Exception + { + returnedModel = restClient.authenticateUser(newMember).withCoreAPI().usingUser(adminUser).getSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsErrorKey(RestErrorModel.RELATIONSHIP_NOT_FOUND_ERRORKEY) + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, adminUser.getUsername(), moderatedSite.getId())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER).stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify user doesn't have permission to get site membership request of admin with requests with Rest API and status code is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void userIsNotAbleToGetSiteMembershipRequestOfAdminWithRequest() throws Exception + { + UserModel newMember = dataUser.createRandomTestUser(); + restClient.authenticateUser(adminUser).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite); + + returnedModel = restClient.authenticateUser(newMember).withCoreAPI().usingUser(adminUser).getSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsErrorKey(RestErrorModel.RELATIONSHIP_NOT_FOUND_ERRORKEY) + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, adminUser.getUsername(), moderatedSite.getId())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify admin user doesn't have permission to get site membership request of another user with Rest API and status code is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void userIsNotAbleToGetSiteMembershipRequestOfAnotherUser() throws Exception + { + UserModel userCollaborator = dataUser.createRandomTestUser(); + UserModel userConsumer = dataUser.createRandomTestUser(); + restClient.authenticateUser(userConsumer).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite); + dataUser.usingUser(siteCreator).addUserToSite(userConsumer, moderatedSite, UserRole.SiteConsumer); + restClient.authenticateUser(userCollaborator).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite); + dataUser.usingUser(siteCreator).addUserToSite(userCollaborator, moderatedSite, UserRole.SiteCollaborator); + + returnedModel = restClient.authenticateUser(userCollaborator).withCoreAPI().usingUser(userConsumer).getSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsErrorKey(RestErrorModel.RELATIONSHIP_NOT_FOUND_ERRORKEY) + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, userConsumer.getUsername(), moderatedSite.getId())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + +} \ No newline at end of file diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/membershipRequests/GetSiteMembershipRequestsTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/membershipRequests/GetSiteMembershipRequestsTests.java new file mode 100644 index 0000000000..ba1f16f55b --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/membershipRequests/GetSiteMembershipRequestsTests.java @@ -0,0 +1,420 @@ +package org.alfresco.rest.sites.membershipRequests; + +import static org.alfresco.utility.report.log.Step.STEP; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.*; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Tests for + * GET /people/{personId}/site-membership-requests + * GET /site-membership-requests + * POST /sites/{siteId}/site-membership-requests/{inviteeId}/approve + * POST /sites/{siteId}/site-membership-requests/{inviteeId}/reject + * + * @author Cristina Axinte + */ + +public class GetSiteMembershipRequestsTests extends RestTest +{ + UserModel siteManager, newMember, adminUser, regularUser, testUser, testUser1; + DataUser.ListUserWithRoles usersWithRoles; + SiteModel moderatedSite1, moderatedSite2; + RestSiteMembershipRequestModelsCollection siteMembershipRequests; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + siteManager = dataUser.createRandomTestUser(); + newMember = dataUser.createRandomTestUser(); + regularUser = dataUser.createRandomTestUser(); + + testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteConsumer); + testUser1 = dataUser.createRandomTestUser("testUser1"); + testUser1.setUserRole(UserRole.SiteConsumer); + + moderatedSite1 = dataSite.usingUser(siteManager).createModeratedRandomSite(); + moderatedSite2 = dataSite.usingUser(siteManager).createModeratedRandomSite(); + + restClient.authenticateUser(newMember).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite1); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.authenticateUser(adminUser).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite1); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + usersWithRoles = dataUser.addUsersWithRolesToSite(moderatedSite1, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, + UserRole.SiteContributor); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @Bug(id = "MNT-16557") + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, description = "Verify manager user gets all site membership requests of a specific person with Rest API and response is successful (200)") + public void managerUserGetsSiteMembershipRequestsWithSuccess() throws Exception + { + siteMembershipRequests = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI() + .usingUser(newMember).getSiteMembershipRequests(); + restClient.assertStatusCodeIs(HttpStatus.OK); + siteMembershipRequests.assertThat().entriesListIsNotEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @Bug(id = "MNT-16557") + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify collaborator user fails to get all site membership requests of another user with Rest API (403)") + public void collaboratorUserFailsToGetSiteMembershipRequestsOfAnotherUser() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI() + .usingUser(newMember).getSiteMembershipRequests(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @Bug(id = "MNT-16557") + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify contributor user fails to get all site membership requests of another user with Rest API (403)") + public void contributorUserFailsToGetSiteMembershipRequestsOfAnotherUser() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).withCoreAPI() + .usingUser(newMember).getSiteMembershipRequests(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @Bug(id = "MNT-16557") + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify consumer user fails to get all site membership requests of another user with Rest API (403)") + public void consumerUserFailsToGetSiteMembershipRequestsOfAnotherUser() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI().usingUser(newMember).getSiteMembershipRequests(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @Bug(id = "MNT-16557") + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify admin user gets all site membership requests of a specific person with Rest API and response is successful (200)") + public void adminGetsSiteMembershipRequestsOfanotherUserWithSuccess() throws Exception + { + siteMembershipRequests = restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI() + .usingUser(newMember).getSiteMembershipRequests(); + restClient.assertStatusCodeIs(HttpStatus.OK); + siteMembershipRequests.assertThat().entriesListIsNotEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) +// @Bug(id = "MNT-16904", description = "It fails only on environment with tenants") + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, description = "Verify manager user fails to get all site membership requests of a specific person with Rest API when the authentication fails (401)") + public void unauthorizedUserFailsToGetSiteMembershipRequests() throws Exception + { + restClient.authenticateUser(new UserModel("random user", "random password")).withCoreAPI() + .usingAuthUser().getSiteMembershipRequests(); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, description = "Verify a user gets all its own site membership requests with Rest API and response is successful (200)") + public void oneUserGetsItsOwnSiteMembershipRequestsWithSuccess() throws Exception + { + siteMembershipRequests = restClient.authenticateUser(newMember).withCoreAPI().usingUser(newMember).getSiteMembershipRequests(); + restClient.assertStatusCodeIs(HttpStatus.OK); + siteMembershipRequests.assertThat().entriesListContains("id", moderatedSite1.getId()) + .assertThat().entriesListContains("message", "Please accept me") + .assertThat().entriesListCountIs(2); + RestSiteModel firstSite = siteMembershipRequests.getEntries().get(0).onModel().getSite(); + if (firstSite.getId().equals(moderatedSite1.getId())) + { + firstSite.assertThat().field("visibility").is(moderatedSite1.getVisibility()) + .assertThat().field("guid").is(moderatedSite1.getGuid()) + .assertThat().field("description").is(moderatedSite1.getDescription()) + .assertThat().field("id").is(moderatedSite1.getId()) + .assertThat().field("title").is(moderatedSite1.getTitle()); + } + else + { + firstSite.assertThat().field("visibility").is(moderatedSite2.getVisibility()) + .assertThat().field("guid").is(moderatedSite2.getGuid()) + .assertThat().field("description").is(moderatedSite2.getDescription()) + .assertThat().field("id").is(moderatedSite2.getId()) + .assertThat().field("title").is(moderatedSite2.getTitle()); + } + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, + executionType = ExecutionType.REGRESSION, + description = "Verify that for invalid maxItems parameter status code returned is 400.") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void checkInvalidMaxItemsStatusCode() throws Exception + { + restClient.authenticateUser(adminUser).withParams("maxItems=AB") + .withCoreAPI().usingUser(newMember).getSiteMembershipRequests(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.INVALID_MAXITEMS, "AB")); + + restClient.authenticateUser(adminUser).withParams("maxItems=0") + .withCoreAPI().usingUser(newMember).getSiteMembershipRequests(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, + executionType = ExecutionType.REGRESSION, + description = "Verify that for invalid skipCount parameter status code returned is 400.") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void checkInvalidSkipCountStatusCode() throws Exception + { + restClient.authenticateUser(adminUser).withParams("skipCount=AB") + .withCoreAPI().usingUser(newMember).getSiteMembershipRequests(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.INVALID_SKIPCOUNT, "AB")); + + restClient.authenticateUser(adminUser).withParams("skipCount=-1") + .withCoreAPI().usingUser(newMember).getSiteMembershipRequests(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(RestErrorModel.NEGATIVE_VALUES_SKIPCOUNT); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, + executionType = ExecutionType.REGRESSION, + description = "Verify that if personId does not exist status code returned is 404.") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void ifPersonIdDoesNotExist() throws Exception + { + UserModel nonexistentUser = dataUser.createRandomTestUser(); + nonexistentUser.setUsername("nonexistent"); + + restClient.authenticateUser(adminUser).withCoreAPI().usingUser(nonexistentUser).getSiteMembershipRequests(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "nonexistent")) + .statusCodeIs(HttpStatus.NOT_FOUND) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE) + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, + executionType = ExecutionType.REGRESSION, + description = "Specify -me- string in place of for request.") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void replacePersonIdWithMeRequest() throws Exception + { + UserModel meUser = dataUser.createRandomTestUser(); + restClient.authenticateUser(meUser).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite1); + siteMembershipRequests = restClient.authenticateUser(meUser).withCoreAPI().usingMe().getSiteMembershipRequests(); + restClient.assertStatusCodeIs(HttpStatus.OK); + siteMembershipRequests.assertThat().entriesListContains("id", moderatedSite1.getId()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, + executionType = ExecutionType.REGRESSION, + description = "Verify that if empty personId is used status code returned is 404.") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void useEmptyPersonId() throws Exception + { + UserModel emptyNameMember = dataUser.createRandomTestUser(); + emptyNameMember.setUsername(" "); + + restClient.authenticateUser(adminUser).withCoreAPI().usingUser(emptyNameMember).getSiteMembershipRequests(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, emptyNameMember.getUsername())); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, + executionType = ExecutionType.REGRESSION, + description = "Get site membership requests to a public site.") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void getRequestsToPublicSite() throws Exception + { + SiteModel publicSite = dataSite.usingAdmin().createPublicRandomSite(); + restClient.authenticateUser(newMember).withCoreAPI().usingAuthUser().addSiteMembershipRequest(publicSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + siteMembershipRequests = restClient.withCoreAPI().usingAuthUser().getSiteMembershipRequests(); + restClient.assertStatusCodeIs(HttpStatus.OK); + siteMembershipRequests.assertThat().entriesListDoesNotContain("id", publicSite.getId()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, + executionType = ExecutionType.REGRESSION, + description = "Approve request then get requests.") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void approveRequestThenGetRequests() throws Exception + { + UserModel siteManager = dataUser.createRandomTestUser(); + + SiteModel moderatedSite = dataSite.usingUser(siteManager).createModeratedRandomSite(); + restClient.authenticateUser(newMember).withCoreAPI().usingMe().addSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + RestTaskModel taskModel = restClient.authenticateUser(newMember).withWorkflowAPI().getTasks().getTaskModelByDescription(moderatedSite); + workflow.approveSiteMembershipRequest(siteManager.getUsername(), siteManager.getPassword(), taskModel.getId(), true, "Approve"); + + siteMembershipRequests = restClient.authenticateUser(newMember).withCoreAPI().usingMe().getSiteMembershipRequests(); + restClient.assertStatusCodeIs(HttpStatus.OK); + siteMembershipRequests.assertThat().entriesListDoesNotContain("id", moderatedSite.getId()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, + executionType = ExecutionType.REGRESSION, + description = "Verify admin user gets all its own site membership requests with Rest API and response is successful (200)") + public void adminGetsItsOwnSiteMembershipRequestsWithSuccess() throws Exception + { + siteMembershipRequests = restClient.authenticateUser(adminUser).withCoreAPI().usingAuthUser().getSiteMembershipRequests(); + restClient.assertStatusCodeIs(HttpStatus.OK); + siteMembershipRequests.assertThat().entriesListContains("id", moderatedSite1.getId()) + .assertThat().entriesListContains("id", moderatedSite2.getId()); + } + + @Bug(id = "MNT-16557") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, + executionType = ExecutionType.REGRESSION, + description = "Verify regular user fails to get all site membership requests of another user with Rest API (403)") + public void regularUserFailsToGetSiteMembershipRequestsOfAnotherUser() throws Exception + { + restClient.authenticateUser(regularUser).withCoreAPI() + .usingUser(newMember).getSiteMembershipRequests(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @Bug(id = "MNT-16557") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, + executionType = ExecutionType.REGRESSION, + description = "Verify regular user fails to get all site membership requests of admin with Rest API (403)") + public void regularUserFailsToGetSiteMembershipRequestsOfAdmin() throws Exception + { + restClient.authenticateUser(regularUser).withCoreAPI() + .usingUser(adminUser).getSiteMembershipRequests(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, + executionType = ExecutionType.REGRESSION, + description = "Verify regular user is able to get his site membership requests with, but skip the first one") + public void getSiteMembershipRequestsButSkipTheFirstOne() throws Exception + { + siteMembershipRequests = restClient.authenticateUser(newMember).withParams("orderBy=id ASC").withCoreAPI() + .usingMe().getSiteMembershipRequests(); + restClient.assertStatusCodeIs(HttpStatus.OK); + siteMembershipRequests.assertThat().entriesListContains("id", moderatedSite1.getId()) + .assertThat().entriesListContains("id", moderatedSite2.getId()); + + RestSiteMembershipRequestModel firstSiteMembershipRequest = siteMembershipRequests.getEntries().get(0).onModel(); + RestSiteMembershipRequestModel secondSiteMembershipRequest = siteMembershipRequests.getEntries().get(1).onModel(); + + siteMembershipRequests = restClient.authenticateUser(newMember).withParams("orderBy=id ASC&skipCount=1").withCoreAPI() + .usingMe().getSiteMembershipRequests(); + restClient.assertStatusCodeIs(HttpStatus.OK); + siteMembershipRequests.assertThat().entriesListDoesNotContain("id", firstSiteMembershipRequest.getId()) + .assertThat().entriesListContains("id", secondSiteMembershipRequest.getId()) + .assertThat().entriesListContains("id", secondSiteMembershipRequest.getSite().getId()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, + executionType = ExecutionType.REGRESSION, + description = "Verify regular user is able to get his site membership requests with higher skipCount than number of requests") + public void getSiteMembershipRequestsWithHighSkipCount() throws Exception + { + siteMembershipRequests = restClient.authenticateUser(newMember).withParams("skipCount=3").withCoreAPI() + .usingMe().getSiteMembershipRequests(); + restClient.assertStatusCodeIs(HttpStatus.OK); + siteMembershipRequests.assertThat().entriesListIsEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, + executionType = ExecutionType.REGRESSION, + description = "Verify get site membership requests returns an empty list where there are no requests") + public void getSiteMembershipRequestsWhereThereAreNoRequests() throws Exception + { + siteMembershipRequests = restClient.authenticateUser(regularUser).withCoreAPI().usingMe().getSiteMembershipRequests(); + restClient.assertStatusCodeIs(HttpStatus.OK); + siteMembershipRequests.assertThat().entriesListIsEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, + executionType = ExecutionType.REGRESSION, + description = "Reject request then get site membership requests.") + public void rejectRequestThenGetSiteMembershipRequests() throws Exception + { + UserModel userWithRejectedRequests = dataUser.createRandomTestUser(); + + restClient.authenticateUser(userWithRejectedRequests).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite1); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + RestTaskModel taskModel = restClient.authenticateUser(userWithRejectedRequests).withWorkflowAPI().getTasks().getTaskModelByDescription(moderatedSite1); + workflow.approveSiteMembershipRequest(siteManager.getUsername(), siteManager.getPassword(), taskModel.getId(), false, "Rejected"); + + siteMembershipRequests = restClient.authenticateUser(userWithRejectedRequests).withCoreAPI().usingMe().getSiteMembershipRequests(); + restClient.assertStatusCodeIs(HttpStatus.OK); + siteMembershipRequests.assertThat().entriesListDoesNotContain("id", moderatedSite1.getId()) + .assertThat().entriesListContains("id", moderatedSite2.getId()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, + executionType = ExecutionType.REGRESSION, + description = "Check get site membership requests when properties parameter is used") + public void getSiteMembershipRequestsWithProperties() throws Exception + { + siteMembershipRequests = restClient.authenticateUser(newMember).withParams("properties=id") + .withCoreAPI().usingAuthUser().getSiteMembershipRequests(); + restClient.assertStatusCodeIs(HttpStatus.OK); + siteMembershipRequests.assertThat().entriesListContains("id", moderatedSite1.getId()) + .assertThat().entriesListContains("id", moderatedSite2.getId()); + RestSiteMembershipRequestModel siteMembershipRequest = siteMembershipRequests.getOneRandomEntry().onModel(); + siteMembershipRequest.assertThat().fieldsCount().is(1); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, + TestGroup.SITES }, executionType = ExecutionType.SANITY, description = "Sanity test for endpoints: GET /site-membership-requests, POST /sites/{siteId}/site-membership-requests/{inviteeId}/approve, POST /sites/{siteId}/site-membership-requests/{inviteeId}/reject") + public void approveRejectSiteMembership() throws Exception + { + STEP("1. Make membership requests for 2 users on moderatedSite."); + restClient.authenticateUser(testUser).withCoreAPI().usingMe().addSiteMembershipRequest(moderatedSite1); + restClient.authenticateUser(testUser1).withCoreAPI().usingMe().addSiteMembershipRequest(moderatedSite1); + + STEP("2. Get site memberships and filter using username and siteId "); + RestSitePersonMembershipRequestModelsCollection membership = restClient.authenticateUser(siteManager) + .withParams("where=(personId='" + testUser.getUsername() + "' AND siteId='" + moderatedSite1.getId() + "')").withCoreAPI() + .usingSite(moderatedSite1).getSiteMemberships(); + + restClient.assertStatusCodeIs(HttpStatus.OK); + membership.getEntryByIndex(0).getSite().assertThat().field("id").is(moderatedSite1.getId()); + membership.getEntryByIndex(0).getPersonModel().assertThat().field("id").is(testUser.getUsername()); + + STEP("3. Approve site membership for one of the users. Check that the user is now a member of the site"); + restClient.authenticateUser(siteManager).withCoreAPI().usingSite(moderatedSite1).approveSiteMembership(testUser); + restClient.assertStatusCodeIs(HttpStatus.OK); + restClient.withCoreAPI().usingSite(moderatedSite1).getSiteMember(testUser).assertThat().field("id").is(testUser.getUsername()).and().field("role") + .is(testUser.getUserRole()); + + STEP("4. Reject site membership for the second user. Check that the user is not a member of the site"); + restClient.authenticateUser(siteManager).withCoreAPI().usingSite(moderatedSite1).rejectSiteMembership(testUser1); + restClient.assertStatusCodeIs(HttpStatus.OK); + RestSiteMemberModelsCollection memberList = restClient.withCoreAPI().usingSite(moderatedSite1).getSiteMembers(); + memberList.assertThat().entriesListDoesNotContain("id", testUser1.getUsername()); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/membershipRequests/UpdateSiteMembershipRequestTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/membershipRequests/UpdateSiteMembershipRequestTests.java new file mode 100644 index 0000000000..209aca5653 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/sites/membershipRequests/UpdateSiteMembershipRequestTests.java @@ -0,0 +1,604 @@ +package org.alfresco.rest.sites.membershipRequests; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestSiteMembershipRequestModel; +import org.alfresco.rest.model.RestTaskModel; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; +import org.alfresco.utility.exception.DataPreparationException; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class UpdateSiteMembershipRequestTests extends RestTest +{ + private SiteModel moderatedSite; + private ListUserWithRoles usersWithRoles; + private UserModel adminUser, managerUser; + private String updatedMessage, moderatedSiteId; + private RestSiteMembershipRequestModel requestUpdateModel, requestGetModel; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws DataPreparationException + { + adminUser = dataUser.getAdminUser(); + managerUser = dataUser.createRandomTestUser(); + moderatedSite = dataSite.usingUser(managerUser).createModeratedRandomSite(); + + usersWithRoles = dataUser.addUsersWithRolesToSite(moderatedSite, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, + UserRole.SiteContributor); + updatedMessage = "Please review my request"; + moderatedSiteId = moderatedSite.getId(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, description = "Verify user is able to update its own site membership request") + public void userIsAbleToUpdateItsOwnSiteMembershipRequest() throws Exception + { + UserModel newMember = dataUser.createRandomTestUser(); + restClient.authenticateUser(newMember).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite); + requestUpdateModel = restClient.withCoreAPI().usingUser(newMember).updateSiteMembershipRequest(moderatedSite, updatedMessage); + restClient.assertStatusCodeIs(HttpStatus.OK); + + requestUpdateModel.assertThat().field("id").is(moderatedSite.getId()) + .assertThat().field("message").is(updatedMessage) + .assertThat().field("site").isNotEmpty() + .assertThat().field("modifiedAt").isNotEmpty() + .assertThat().field("createdAt").isNotEmpty(); + requestUpdateModel.getSite().assertThat().field("visibility").is(moderatedSite.getVisibility()) + .assertThat().field("guid").is(moderatedSite.getGuid()) + .assertThat().field("description").is(moderatedSite.getDescription()) + .assertThat().field("id").is(moderatedSite.getId()) + .assertThat().field("preset").is("site-dashboard") + .assertThat().field("title").is(moderatedSite.getTitle()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify site manager is not able to update membership request of another user") +// @Bug(id = "MNT-16919", description = "Not a bug, The presence of the personId in the URL does not mean it should be possible to act on any other users behalf.") + public void siteManagerIsNotAbleToUpdateSiteMembershipRequestOfAnotherUser() throws Exception + { + UserModel newMember = dataUser.createRandomTestUser(); + + restClient.authenticateUser(newMember).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingUser(newMember) + .updateSiteMembershipRequest(moderatedSite, updatedMessage); + + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, newMember.getUsername())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify site collaborator is not able to update membership request of another user") + // @Bug(id = "MNT-16919", description = "Not a bug, The presence of the personId in the URL does not mean it should be possible to act on any other users behalf.") + public void siteCollaboratorIsNotAbleToUpdateSiteMembershipRequestOfAnotherUser() throws Exception + { + UserModel newMember = dataUser.createRandomTestUser(); + + restClient.authenticateUser(newMember).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingUser(newMember) + .updateSiteMembershipRequest(moderatedSite, updatedMessage); + + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, newMember.getUsername())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify site contributor is not able to update membership request of another user") + // @Bug(id = "MNT-16919", description = "Not a bug, The presence of the personId in the URL does not mean it should be possible to act on any other users behalf.") + public void siteContributorIsNotAbleToUpdateSiteMembershipRequestOfAnotherUser() throws Exception + { + UserModel newMember = dataUser.createRandomTestUser(); + + restClient.authenticateUser(newMember).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).withCoreAPI().usingUser(newMember) + .updateSiteMembershipRequest(moderatedSite, updatedMessage); + + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, newMember.getUsername())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify site consumer is not able to update membership request of another user") + // @Bug(id = "MNT-16919", description = "Not a bug, The presence of the personId in the URL does not mean it should be possible to act on any other users behalf.") + public void siteConsumerIsNotAbleToUpdateSiteMembershipRequestOfAnotherUser() throws Exception + { + UserModel newMember = dataUser.createRandomTestUser(); + + restClient.authenticateUser(newMember).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI().usingUser(newMember) + .updateSiteMembershipRequest(moderatedSite, updatedMessage); + + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, newMember.getUsername())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify one user is not able to update membership request of another user") + // @Bug(id = "MNT-16919", description = "Not a bug, The presence of the personId in the URL does not mean it should be possible to act on any other users behalf.") + public void regularUserIsNotAbleToUpdateSiteMembershipRequestOfAnotherUser() throws Exception + { + UserModel newMember = dataUser.createRandomTestUser(); + UserModel otherMember = dataUser.createRandomTestUser(); + + restClient.authenticateUser(newMember).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite); + + restClient.authenticateUser(otherMember).withCoreAPI().usingUser(newMember).updateSiteMembershipRequest(moderatedSite, updatedMessage); + + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, newMember.getUsername())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify admin is not able to update membership request of another user") + // @Bug(id = "MNT-16919", description = "Not a bug, The presence of the personId in the URL does not mean it should be possible to act on any other users behalf.") + public void adminIsNotAbleToUpdateSiteMembershipRequestOfAnotherUser() throws Exception + { + UserModel newMember = dataUser.createRandomTestUser(); + + restClient.authenticateUser(newMember).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite); + + restClient.authenticateUser(adminUser).withCoreAPI().usingUser(newMember).updateSiteMembershipRequest(moderatedSite, updatedMessage); + + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, newMember.getUsername())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.SANITY, description = "Verify unauthorized user is not able to update user site membership request") + public void unauthorizedUserIsNotAbleToUpdateSiteMembershipRequest() throws Exception + { + UserModel newMember = dataUser.createRandomTestUser(); + restClient.authenticateUser(newMember).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite); + newMember.setPassword("fakePass"); + restClient.withCoreAPI().usingUser(newMember).updateSiteMembershipRequest(moderatedSite, updatedMessage); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify user is able to update its own site membership request using -me-") + public void usingMeUpdateSiteMembershipRequest() throws Exception + { + UserModel newMember = dataUser.createRandomTestUser(); + restClient.authenticateUser(newMember).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite); + requestUpdateModel = restClient.withCoreAPI().usingMe().updateSiteMembershipRequest(moderatedSite, updatedMessage); + restClient.assertStatusCodeIs(HttpStatus.OK); + requestUpdateModel.assertMembershipRequestMessageIs(updatedMessage).and().field("id").is(moderatedSite.getId()).and().field("modifiedAt").isNotEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify inexistent user is not able to update its own site membership request") + public void inexistentUserCannotUpdateSiteMembershipRequest() throws Exception + { + UserModel inexistentUser = UserModel.getRandomUserModel(); + restClient.authenticateUser(managerUser).withCoreAPI().usingUser(inexistentUser).updateSiteMembershipRequest(moderatedSite, updatedMessage); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, inexistentUser.getUsername())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify user is not able to update its own site membership request for inexistent site") + public void userCannotUpdateSiteMembershipRequestForInexistentSite() throws Exception + { + SiteModel randomSite = SiteModel.getRandomSiteModel(); + UserModel newMember = dataUser.createRandomTestUser(); + restClient.authenticateUser(newMember).withCoreAPI().usingMe().updateSiteMembershipRequest(randomSite, updatedMessage); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, newMember.getUsername(), randomSite.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify user is able not to update its own site membership request for public site") + public void userCannotUpdateSiteMembershipRequestForPublicSite() throws Exception + { + SiteModel publicSite = dataSite.usingUser(managerUser).createPublicRandomSite(); + UserModel newMember = dataUser.createRandomTestUser(); + restClient.authenticateUser(newMember).withCoreAPI().usingAuthUser().addSiteMembershipRequest(publicSite); + restClient.withCoreAPI().usingMe().updateSiteMembershipRequest(publicSite, updatedMessage); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, newMember.getUsername(), publicSite.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify user is not able to update its own site membership request for private site") + public void userCannotUpdateSiteMembershipRequestForPrivateSite() throws Exception + { + SiteModel privateSite = dataSite.usingUser(managerUser).createPrivateRandomSite(); + UserModel newMember = dataUser.createRandomTestUser(); + restClient.authenticateUser(newMember).withCoreAPI().usingAuthUser().addSiteMembershipRequest(privateSite); + restClient.withCoreAPI().usingMe().updateSiteMembershipRequest(privateSite, updatedMessage); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, newMember.getUsername(), privateSite.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify user is able to update its own site membership request with initial message") + public void userCanUpdateSiteMembershipRequestWithInitialMessage() throws Exception + { + UserModel newMember = dataUser.createRandomTestUser(); + restClient.authenticateUser(newMember).withCoreAPI().usingAuthUser().addSiteMembershipRequest(updatedMessage, moderatedSite, "Accept me"); + requestUpdateModel = restClient.withCoreAPI().usingMe().updateSiteMembershipRequest(moderatedSite, updatedMessage); + restClient.assertStatusCodeIs(HttpStatus.OK); + requestUpdateModel.assertMembershipRequestMessageIs(updatedMessage).and().field("id").is(moderatedSite.getId()).and().field("modifiedAt").isNotEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify user is able to update its own site membership request with different message") + public void userCanUpdateSiteMembershipRequestWithDifferentMessage() throws Exception + { + UserModel newMember = dataUser.createRandomTestUser(); + restClient.authenticateUser(newMember).withCoreAPI().usingAuthUser().addSiteMembershipRequest("", moderatedSite, "Accept me"); + requestUpdateModel = restClient.withCoreAPI().usingMe().updateSiteMembershipRequest(moderatedSite, updatedMessage); + restClient.assertStatusCodeIs(HttpStatus.OK); + requestUpdateModel.assertMembershipRequestMessageIs(updatedMessage).and().field("id").is(moderatedSite.getId()).and().field("modifiedAt").isNotEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, description = "Verify modifiedAt field for update siteMembership request call") + public void verifyModifiedAtForUpdateSiteMembershipRequest() throws Exception + { + UserModel newMember = dataUser.createRandomTestUser(); + restClient.authenticateUser(newMember).withCoreAPI().usingAuthUser().addSiteMembershipRequest(moderatedSite); + String firstModifiedAt = restClient.withCoreAPI().usingMe().updateSiteMembershipRequest(moderatedSite, "first message").getModifiedAt(); + String secondModifiedAt = restClient.withCoreAPI().usingMe().updateSiteMembershipRequest(moderatedSite, "second message").getModifiedAt(); + Assert.assertNotEquals(firstModifiedAt, secondModifiedAt); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify user is not able to update membership request of admin") + public void userIsNotAbleToUpdateSiteMembershipRequestOfAdmin() throws Exception + { + UserModel newMember = dataUser.createRandomTestUser(); + restClient.authenticateUser(adminUser).withCoreAPI().usingAuthUser() + .addSiteMembershipRequest(moderatedSite); + + restClient.authenticateUser(newMember).withCoreAPI().usingUser(adminUser) + .updateSiteMembershipRequest(moderatedSite, updatedMessage); + + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsSummary(String.format("The entity with id: " + RestErrorModel.ENTITY_NOT_FOUND, adminUser.getUsername())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager is able to update site membership request") + public void updateSiteMembershipRequestAfterUserIsAddedAsMember() throws Exception + { + UserModel newMember = dataUser.createRandomTestUser(); + restClient.authenticateUser(newMember).withCoreAPI().usingAuthUser() + .addSiteMembershipRequest(moderatedSite); + dataUser.usingUser(managerUser).addUserToSite(newMember, moderatedSite, UserRole.SiteManager); + requestUpdateModel = restClient.authenticateUser(newMember).withCoreAPI().usingAuthUser() + .updateSiteMembershipRequest(moderatedSite, updatedMessage); + + restClient.assertStatusCodeIs(HttpStatus.OK); + requestUpdateModel.assertThat().field("id").is(moderatedSite.getId()) + .assertThat().field("message").is(updatedMessage) + .assertThat().field("modifiedAt").isNotEmpty() + .assertThat().field("createdAt").isNotEmpty(); + requestUpdateModel.getSite().assertThat().field("role").is(UserRole.SiteManager) + .assertThat().field("visibility").is(moderatedSite.getVisibility()) + .assertThat().field("guid").is(moderatedSite.getGuid()) + .assertThat().field("description").is(moderatedSite.getDescription()) + .assertThat().field("id").is(moderatedSite.getId()) + .assertThat().field("preset").is("site-dashboard") + .assertThat().field("title").is(moderatedSite.getTitle()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify admin is able to update site membership request") + public void adminIsAbleToUpdateHisSiteMembershipRequest() throws Exception + { + UserModel regularUser = dataUser.createRandomTestUser(); + SiteModel anotherModeratedSite = dataSite.usingUser(regularUser).createModeratedRandomSite(); + requestUpdateModel = restClient.authenticateUser(adminUser).withCoreAPI().usingAuthUser() + .addSiteMembershipRequest(anotherModeratedSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + requestUpdateModel = restClient.withCoreAPI().usingAuthUser() + .updateSiteMembershipRequest(anotherModeratedSite, updatedMessage); + + restClient.assertStatusCodeIs(HttpStatus.OK); + requestUpdateModel.assertThat().field("id").is(anotherModeratedSite.getId()) + .assertThat().field("message").is("Please review my request") + .assertThat().field("modifiedAt").isNotEmpty() + .assertThat().field("createdAt").isNotEmpty(); + requestUpdateModel.getSite().assertThat().field("visibility").is(anotherModeratedSite.getVisibility()) + .assertThat().field("guid").is(anotherModeratedSite.getGuid()) + .assertThat().field("description").is(anotherModeratedSite.getDescription()) + .assertThat().field("id").is(anotherModeratedSite.getId()) + .assertThat().field("preset").is("site-dashboard") + .assertThat().field("title").is(anotherModeratedSite.getTitle()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify user update site membership request with no message then adds a new message") + public void userUpdateSiteMembershipRequestWithNoMessageThenAddsNewMessage() throws Exception + { + UserModel newMember = dataUser.createRandomTestUser(); + requestUpdateModel = restClient.authenticateUser(newMember).withCoreAPI().usingAuthUser() + .addSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + requestUpdateModel.assertThat().field("id").is(moderatedSite.getId()) + .assertThat().field("message").is("Please accept me"); + + requestUpdateModel = restClient.withCoreAPI().usingMe().updateSiteMembershipRequest(moderatedSite, ""); + restClient.assertStatusCodeIs(HttpStatus.OK); + requestUpdateModel.assertThat().field("id").is(moderatedSite.getId()) + .and().field("modifiedAt").isNotEmpty() + .assertThat().field("message").isNull(); + + requestUpdateModel = restClient.withCoreAPI().usingMe().updateSiteMembershipRequest(moderatedSite, updatedMessage); + requestUpdateModel.assertThat().field("id").is(moderatedSite.getId()) + .assertThat().field("message").is(updatedMessage) + .assertThat().field("modifiedAt").isNotEmpty() + .assertThat().field("createdAt").isNotEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify user updates site membership request and verifies 'ModifiedAt' field using GET") + public void userUpdateSiteMembershipRequestAndCheckModifiedAtWithGet() throws Exception + { + UserModel newMember = dataUser.createRandomTestUser(); + requestUpdateModel = restClient.authenticateUser(newMember).withCoreAPI().usingAuthUser() + .addSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + requestUpdateModel.assertThat().field("id").is(moderatedSite.getId()) + .assertThat().field("message").is("Please accept me"); + + requestUpdateModel = restClient.withCoreAPI().usingAuthUser().updateSiteMembershipRequest(moderatedSite, updatedMessage); + requestGetModel = restClient.withCoreAPI().usingAuthUser().getSiteMembershipRequest(moderatedSite); + + restClient.assertStatusCodeIs(HttpStatus.OK); + requestGetModel.assertThat().field("id").is(requestUpdateModel.getId()) + .and().field("modifiedAt").is(requestUpdateModel.getModifiedAt()) + .assertThat().field("message").is(requestUpdateModel.getMessage()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Update membership request - empty body") + public void emptyBodyUpdateSiteMembershipRequest() throws Exception + { + restClient.authenticateUser(adminUser).withCoreAPI(); + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, "{\"\": \"\",\"\": \"\", \"\": \"\"}", + "people/{personId}/site-membership-requests/{siteId}", adminUser.getUsername(), moderatedSite.getId()); + restClient.processModel(RestSiteMembershipRequestModel.class, request); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.NO_CONTENT, "Unrecognized field " + "\"\"")); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Update membership request - missing 'Title' field from Json") + public void missingTitleFieldBodyUpdateSiteMembershipRequest() throws Exception + { + SiteModel moderatedSite = dataSite.usingUser(managerUser).createModeratedRandomSite(); + UserModel newMember = dataUser.createRandomTestUser(); + restClient.authenticateUser(newMember).withCoreAPI().usingAuthUser() + .addSiteMembershipRequest(moderatedSite); + + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, + "{\"message\":\"Please review my request\",\"id\":\"" + moderatedSite.getId() + "\"}", + "people/{personId}/site-membership-requests/{siteId}", + newMember.getUsername(), moderatedSite.getId()); + requestUpdateModel = restClient.processModel(RestSiteMembershipRequestModel.class, request); + + restClient.assertStatusCodeIs(HttpStatus.OK); + requestUpdateModel.assertThat().field("id").is(moderatedSite.getId()) + .assertThat().field("message").is(updatedMessage) + .assertThat().field("site").isNotEmpty() + .assertThat().field("modifiedAt").isNotEmpty() + .assertThat().field("createdAt").isNotEmpty(); + requestUpdateModel.getSite().assertThat().field("visibility").is(moderatedSite.getVisibility()) + .assertThat().field("guid").is(moderatedSite.getGuid()) + .assertThat().field("description").is(moderatedSite.getDescription()) + .assertThat().field("id").is(moderatedSite.getId()) + .assertThat().field("preset").is("site-dashboard") + .assertThat().field("title").is(moderatedSite.getTitle()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Update site membership request - missing JSON body") + public void missingJsonFieldBodyUpdateSiteMembershipRequest() throws Exception + { + SiteModel moderatedSite = dataSite.usingUser(managerUser).createModeratedRandomSite(); + UserModel newMember = dataUser.createRandomTestUser(); + restClient.authenticateUser(newMember).withCoreAPI().usingAuthUser() + .addSiteMembershipRequest(moderatedSite); + + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, "", + "people/{personId}/site-membership-requests/{siteId}", newMember.getUsername(), + moderatedSite.getId()); + requestUpdateModel = restClient.processModel(RestSiteMembershipRequestModel.class, request); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsSummary(String.format(RestErrorModel.NO_CONTENT, "No content to map due to end-of-input")) + .containsErrorKey(String.format(RestErrorModel.NO_CONTENT, "No content to map due to end-of-input")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Update site membership request - empty JSON body") + public void emptyJsonFieldBodyUpdateSiteMembershipRequest() throws Exception + { + SiteModel moderatedSite = dataSite.usingUser(managerUser).createModeratedRandomSite(); + UserModel newMember = dataUser.createRandomTestUser(); + restClient.authenticateUser(newMember).withCoreAPI().usingAuthUser() + .addSiteMembershipRequest(moderatedSite); + + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, "{}", + "people/{personId}/site-membership-requests/{siteId}", newMember.getUsername(), + moderatedSite.getId()); + requestUpdateModel = restClient.processModel(RestSiteMembershipRequestModel.class, request); + + restClient.assertStatusCodeIs(HttpStatus.OK); + requestUpdateModel.assertThat().field("id").is(moderatedSite.getId()) + .assertThat().field("message").isNull() + .assertThat().field("site").isNotEmpty() + .assertThat().field("modifiedAt").isNotEmpty() + .assertThat().field("createdAt").isNotEmpty(); + requestUpdateModel.getSite().assertThat().field("visibility").is(moderatedSite.getVisibility()) + .assertThat().field("guid").is(moderatedSite.getGuid()) + .assertThat().field("description").is(moderatedSite.getDescription()) + .assertThat().field("id").is(moderatedSite.getId()) + .assertThat().field("preset").is("site-dashboard") + .assertThat().field("title").is(moderatedSite.getTitle()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Update site membership request - invalid SiteId") + public void invalidSiteIdUpdateSiteMembershipRequest() throws Exception + { + moderatedSite.setId("invalidSiteId"); + restClient.authenticateUser(managerUser).withCoreAPI().usingAuthUser() + .updateSiteMembershipRequest(moderatedSite, updatedMessage); + + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, managerUser.getUsername(), moderatedSite.getId())); + + moderatedSite.setId(moderatedSiteId); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Update site membership request - empty SiteId") + public void emptySiteIdUpdateSiteMembershipRequest() throws Exception + { + moderatedSite.setId(""); + restClient.authenticateUser(managerUser).withCoreAPI().usingAuthUser() + .updateSiteMembershipRequest(moderatedSite, updatedMessage); + + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED) + .assertLastError() + .containsSummary(RestErrorModel.PUT_EMPTY_ARGUMENT) + .containsErrorKey(RestErrorModel.PUT_EMPTY_ARGUMENT) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + + moderatedSite.setId(moderatedSiteId); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Verify inexistent user is not able to update site membership request") + public void emptyUserCannotUpdateSiteMembershipRequest() throws Exception + { + UserModel emptyUser = new UserModel("", "password"); + restClient.authenticateUser(emptyUser).withCoreAPI().usingAuthUser() + .updateSiteMembershipRequest(moderatedSite, updatedMessage); + + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Update site membership request - rejected Request") + public void rejectRequestThenUpdateSiteMembershipRequest() throws Exception + { + UserModel userWithRejectedRequests = dataUser.createRandomTestUser(); + restClient.authenticateUser(userWithRejectedRequests).withCoreAPI().usingAuthUser() + .addSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + RestTaskModel taskModel = restClient.authenticateUser(userWithRejectedRequests).withWorkflowAPI().getTasks() + .getTaskModelByDescription(moderatedSite); + workflow.approveSiteMembershipRequest(managerUser.getUsername(), managerUser.getPassword(), taskModel.getId(), false, "Rejected"); + + requestUpdateModel = restClient.authenticateUser(userWithRejectedRequests).withCoreAPI().usingMe() + .updateSiteMembershipRequest(moderatedSite, updatedMessage); + + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, userWithRejectedRequests.getUsername(), moderatedSite.getId())) + .containsErrorKey(RestErrorModel.RELATIONSHIP_NOT_FOUND_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE }, executionType = ExecutionType.REGRESSION, + description = "Update site membership request - approved Request") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + public void approveRequestThenUpdateSiteMembershipRequest() throws Exception + { + UserModel userWithApprovedRequests = dataUser.createRandomTestUser(); + restClient.authenticateUser(userWithApprovedRequests).withCoreAPI().usingAuthUser() + .addSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + RestTaskModel taskModel = restClient.authenticateUser(userWithApprovedRequests).withWorkflowAPI().getTasks().getTaskModelByDescription(moderatedSite); + workflow.approveSiteMembershipRequest(managerUser.getUsername(), managerUser.getPassword(), taskModel.getId(), true, "Approve"); + + requestUpdateModel = restClient.authenticateUser(userWithApprovedRequests).withCoreAPI().usingMe() + .updateSiteMembershipRequest(moderatedSite, updatedMessage); + + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, userWithApprovedRequests.getUsername(), moderatedSite.getId())) + .containsErrorKey(RestErrorModel.RELATIONSHIP_NOT_FOUND_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE}, executionType = ExecutionType.REGRESSION, + description = "Update site membership request using invalid network") + public void updateSiteMembershipRequestUsingInvalidNetwork() throws Exception + { + UserModel invalidUserNetwork = dataUser.createRandomTestUser(); + SiteModel site = dataSite.usingUser(invalidUserNetwork).createModeratedRandomSite(); + dataSite.usingUser(invalidUserNetwork).usingSite(site).addSiteToFavorites(); + invalidUserNetwork.setDomain("invalidNetwork"); + + requestUpdateModel = restClient.authenticateUser(invalidUserNetwork).withCoreAPI().usingMe() + .updateSiteMembershipRequest(site, updatedMessage); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE}, executionType = ExecutionType.REGRESSION, + description = "Verify user is not able to update a deleted site membership request") + public void userCantUpdateSiteMembershipRequestForDeletedRequest() throws Exception + { + SiteModel moderatedSite = dataSite.usingUser(managerUser).createModeratedRandomSite(); + UserModel newMember = dataUser.createRandomTestUser(); + restClient.authenticateUser(newMember).withCoreAPI().usingAuthUser() + .addSiteMembershipRequest(moderatedSite); + + restClient.authenticateUser(newMember).withCoreAPI().usingAuthUser() + .deleteSiteMembershipRequest(moderatedSite); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + requestUpdateModel = restClient.withCoreAPI().usingAuthUser() + .updateSiteMembershipRequest(moderatedSite, updatedMessage); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsSummary(String.format(RestErrorModel.RELATIONSHIP_NOT_FOUND, newMember.getUsername(), moderatedSite.getId())); + } +} \ No newline at end of file diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagTests.java new file mode 100644 index 0000000000..2faa4cb847 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagTests.java @@ -0,0 +1,138 @@ +package org.alfresco.rest.tags; + +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestTagModel; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +@Test(groups = {TestGroup.REQUIRE_SOLR}) +public class GetTagTests extends TagsDataPrep +{ + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + init(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify admin user gets tag using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void adminIsAbleToGetTag() throws Exception + { + RestTagModel returnedTag = restClient.authenticateUser(adminUserModel).withCoreAPI().getTag(documentTag); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedTag.assertThat().field("tag").is(documentTagValue.toLowerCase()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.SANITY, description = "Verify user with Manager role gets tag using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY }) + public void userWithManagerRoleIsAbleToGetTag() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + + RestTagModel returnedTag = restClient.withCoreAPI().getTag(documentTag); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedTag.assertThat().field("tag").is(documentTagValue.toLowerCase()) + .assertThat().field("id").is(documentTag.getId()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify user with Collaborator role gets tag using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void userWithCollaboratorRoleIsAbleToGetTag() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); + RestTagModel returnedTag = restClient.withCoreAPI().getTag(documentTag); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedTag.assertThat().field("tag").is(documentTagValue.toLowerCase()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify user with Contributor role gets tag using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void userWithContributorRoleIsAbleToGetTag() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); + RestTagModel returnedTag = restClient.withCoreAPI().getTag(documentTag); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedTag.assertThat().field("tag").is(documentTagValue.toLowerCase()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify user with Consumer role gets tag using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void userWithConsumerRoleIsAbleToGetTag() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)); + RestTagModel returnedTag = restClient.withCoreAPI().getTag(documentTag); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedTag.assertThat().field("tag").is(documentTagValue.toLowerCase()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.SANITY, description = "Verify Manager user gets status code 401 if authentication call fails") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY }) +// @Bug(id="MNT-16904", description = "It fails only on environment with tenants") + public void managerIsNotAbleToGetTagIfAuthenticationFails() throws Exception + { + UserModel managerUser = dataUser.usingAdmin().createRandomTestUser(); + String managerPassword = managerUser.getPassword(); + dataUser.addUserToSite(managerUser, siteModel, UserRole.SiteManager); + managerUser.setPassword("wrongPassword"); + restClient.authenticateUser(managerUser).withCoreAPI().getTag(documentTag); + managerUser.setPassword(managerPassword); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that if tag id is invalid status code returned is 400") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void invalidTagIdTest() throws Exception + { + String tagId = documentTag.getId(); + documentTag.setId("random_tag_value"); + restClient.authenticateUser(adminUserModel).withCoreAPI().getTag(documentTag); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "random_tag_value")); + documentTag.setId(tagId); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, + executionType = ExecutionType.REGRESSION, description = "Check that properties filter is applied when getting tag using Manager user.") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void checkPropertiesFilterIsApplied() throws Exception + { + RestTagModel returnedTag = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withParams("properties=id,tag").withCoreAPI().getTag(documentTag); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedTag.assertThat().field("id").is(documentTag.getId()) + .assertThat().field("tag").is(documentTag.getTag().toLowerCase()) + .assertThat().fieldsCount().is(2); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, + executionType = ExecutionType.REGRESSION, description = "Check that Manager user can get tag of a folder.") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void getTagOfAFolder() throws Exception + { + RestTagModel returnedTag = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().getTag(folderTag); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedTag.assertThat().field("tag").is(folderTagValue.toLowerCase()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, + executionType = ExecutionType.REGRESSION, description = "Check default error model schema. Use invalid skipCount parameter.") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void checkDefaultErrorModelSchema() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withParams("skipCount=abc").withCoreAPI().getTag(documentTag); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsErrorKey(String.format(RestErrorModel.INVALID_SKIPCOUNT, "abc")) + .containsSummary(String.format(RestErrorModel.INVALID_SKIPCOUNT, "abc")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } +} \ No newline at end of file diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagsTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagsTests.java new file mode 100644 index 0000000000..5fb830d2c6 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagsTests.java @@ -0,0 +1,229 @@ +package org.alfresco.rest.tags; + +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestTagModel; +import org.alfresco.rest.model.RestTagModelsCollection; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.RandomData; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +@Test(groups = {TestGroup.REQUIRE_SOLR}) +public class GetTagsTests extends TagsDataPrep +{ + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + init(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.SANITY, description = "Verify user with Manager role gets tags using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY }) + public void getTagsWithManagerRole() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedCollection.assertThat().entriesListIsNotEmpty() + .and().entriesListContains("tag", documentTagValue.toLowerCase()) + .and().entriesListContains("tag", documentTagValue2.toLowerCase()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify user with Collaborator role gets tags using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void getTagsWithCollaboratorRole() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); + returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedCollection.assertThat().entriesListIsNotEmpty() + .and().entriesListContains("tag", documentTagValue.toLowerCase()) + .and().entriesListContains("tag", documentTagValue2.toLowerCase()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify user with Contributor role gets tags using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void getTagsWithContributorRole() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); + returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedCollection.assertThat().entriesListIsNotEmpty() + .and().entriesListContains("tag", documentTagValue.toLowerCase()) + .and().entriesListContains("tag", documentTagValue2.toLowerCase()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify user with Consumer role gets tags using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void getTagsWithConsumerRole() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)); + returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedCollection.assertThat().entriesListIsNotEmpty() + .and().entriesListContains("tag", documentTagValue.toLowerCase()) + .and().entriesListContains("tag", documentTagValue2.toLowerCase()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.SANITY, description = "Failed authentication get tags call returns status code 401 with Manager role") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY }) +// @Bug(id="MNT-16904", description = "It fails only on environment with tenants") + public void failedAuthenticationReturnsUnauthorizedStatus() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + userModel = dataUser.createRandomTestUser(); + userModel.setPassword("user wrong password"); + dataUser.addUserToSite(userModel, siteModel, UserRole.SiteManager); + restClient.authenticateUser(userModel); + restClient.withCoreAPI().getTags(); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that if maxItems is invalid status code returned is 400") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION}) + public void maxItemsInvalidValueTest() throws Exception + { + restClient.authenticateUser(adminUserModel).withParams("maxItems=abc").withCoreAPI().getTags(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(String.format(RestErrorModel.INVALID_MAXITEMS, "abc")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that if skipCount is invalid status code returned is 400") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION}) + public void skipCountInvalidValueTest() throws Exception + { + restClient.authenticateUser(adminUserModel).withParams("skipCount=abc").withCoreAPI().getTags(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(String.format(RestErrorModel.INVALID_SKIPCOUNT, "abc")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that file tag is retrieved") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION}) + public void fileTagIsRetrieved() throws Exception + { + restClient.authenticateUser(adminUserModel); + returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedCollection.assertThat().entriesListIsNotEmpty() + .and().entriesListContains("tag", documentTagValue.toLowerCase()) + .and().entriesListContains("tag", documentTagValue2.toLowerCase()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that folder tag is retrieved") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION}) + public void folderTagIsRetrieved() throws Exception + { + restClient.authenticateUser(adminUserModel); + returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedCollection.assertThat().entriesListIsNotEmpty() + .and().entriesListContains("tag", folderTagValue.toLowerCase()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify site Manager is able to get tags using properties parameter." + + "Check that properties filter is applied.") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void siteManagerIsAbleToRetrieveTagsWithPropertiesParameter() throws Exception + { + returnedCollection = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withParams("maxItems=5000&properties=tag").withCoreAPI().getTags(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedCollection.assertThat().entriesListIsNotEmpty() + .and().entriesListContains("tag", documentTagValue.toLowerCase()) + .and().entriesListContains("tag", documentTagValue2.toLowerCase()) + .and().entriesListDoesNotContain("id"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "With admin get tags and use skipCount parameter. Check pagination") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void useSkipCountCheckPagination() throws Exception + { + returnedCollection = restClient.authenticateUser(adminUserModel).withCoreAPI().getTags(); + restClient.assertStatusCodeIs(HttpStatus.OK); + + RestTagModel firstTag = returnedCollection.getEntries().get(0).onModel(); + RestTagModel secondTag = returnedCollection.getEntries().get(1).onModel(); + RestTagModelsCollection tagsWithSkipCount = restClient.withParams("skipCount=2").withCoreAPI().getTags(); + restClient.assertStatusCodeIs(HttpStatus.OK); + + tagsWithSkipCount.assertThat().entriesListDoesNotContain("tag", firstTag.getTag()) + .assertThat().entriesListDoesNotContain("tag", secondTag.getTag()); + tagsWithSkipCount.assertThat().paginationField("skipCount").is("2"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "With admin get tags and use maxItems parameter. Check pagination") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void useMaxItemsParameterCheckPagination() throws Exception + { + returnedCollection = restClient.authenticateUser(adminUserModel).withCoreAPI().getTags(); + restClient.assertStatusCodeIs(HttpStatus.OK); + + RestTagModel firstTag = returnedCollection.getEntries().get(0).onModel(); + RestTagModel secondTag = returnedCollection.getEntries().get(1).onModel(); + RestTagModelsCollection tagsWithMaxItems = restClient.withParams("maxItems=2").withCoreAPI().getTags(); + restClient.assertStatusCodeIs(HttpStatus.OK); + + tagsWithMaxItems.assertThat().entriesListContains("tag", firstTag.getTag()) + .assertThat().entriesListContains("tag", secondTag.getTag()) + .assertThat().entriesListCountIs(2); + tagsWithMaxItems.assertThat().paginationField("maxItems").is("2"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "With manager get tags and use high skipCount parameter. Check pagination") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void useHighSkipCountCheckPagination() throws Exception + { + returnedCollection = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withParams("skipCount=20000").withCoreAPI().getTags(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedCollection.assertThat().entriesListIsEmpty() + .getPagination().assertThat().field("maxItems").is(100) + .and().field("hasMoreItems").is("false") + .and().field("count").is("0") + .and().field("skipCount").is(20000) + .and().field("totalItems").isNull(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "With Collaborator user get tags and use maxItems with value zero. Check default error model schema") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void useMaxItemsWithValueZeroCheckDefaultErrorModelSchema() throws Exception + { + returnedCollection = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .withParams("maxItems=0").withCoreAPI().getTags(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsErrorKey(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS) + .containsSummary(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "With Manager user delete tag. Check it is not retrieved anymore.") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void checkThatDeletedTagIsNotRetrievedAnymore() throws Exception + { + String removedTag = RandomData.getRandomName("tag3"); + + RestTagModel deletedTag = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingResource(document).addTag(removedTag); + + restClient.withCoreAPI().usingResource(document).deleteTag(deletedTag); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags(); + returnedCollection.assertThat().entriesListIsNotEmpty() + .and().entriesListDoesNotContain("tag", removedTag.toLowerCase()); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/TagsDataPrep.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/TagsDataPrep.java new file mode 100644 index 0000000000..a499ab15b0 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/TagsDataPrep.java @@ -0,0 +1,70 @@ +package org.alfresco.rest.tags; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestTagModel; +import org.alfresco.rest.model.RestTagModelsCollection; +import org.alfresco.utility.Utility; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; +import org.alfresco.utility.data.RandomData; +import org.alfresco.utility.model.FileModel; +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.Test; + +@Test(groups = {TestGroup.REQUIRE_SOLR}) +public class TagsDataPrep extends RestTest +{ + + protected static UserModel adminUserModel; + protected static UserModel userModel; + protected static ListUserWithRoles usersWithRoles; + protected static SiteModel siteModel; + protected static FileModel document; + protected static FolderModel folder; + protected static String documentTagValue, documentTagValue2, folderTagValue; + protected static RestTagModel documentTag, documentTag2, folderTag, returnedModel; + protected static RestTagModelsCollection returnedCollection; + private static boolean isInitialized = false; + + public void init() throws Exception + { + if(!isInitialized) + { + isInitialized = true; + initialization(); + } + } + + public void initialization() throws Exception + { + adminUserModel = dataUser.getAdminUser(); + //Create public site + siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); + usersWithRoles = dataUser.usingAdmin().addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor); + document = dataContent.usingUser(adminUserModel).usingSite(siteModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + folder = dataContent.usingUser(adminUserModel).usingSite(siteModel).createFolder(); + + documentTagValue = RandomData.getRandomName("tag"); + documentTagValue2 = RandomData.getRandomName("tag"); + folderTagValue = RandomData.getRandomName("tag"); + + restClient.authenticateUser(adminUserModel); + documentTag = restClient.withCoreAPI().usingResource(document).addTag(documentTagValue); + documentTag2 = restClient.withCoreAPI().usingResource(document).addTag(documentTagValue2); + folderTag = restClient.withCoreAPI().usingResource(folder).addTag(folderTagValue); + + // Allow indexing to complete. + Utility.sleep(1000, 60000, () -> + { + returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags(); + returnedCollection.assertThat().entriesListContains("tag", documentTagValue.toLowerCase()) + .and().entriesListContains("tag", documentTagValue2.toLowerCase()) + .and().entriesListContains("tag", folderTagValue.toLowerCase()); + }); + + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/UpdateTagTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/UpdateTagTests.java new file mode 100644 index 0000000000..59b0b45843 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/UpdateTagTests.java @@ -0,0 +1,268 @@ +package org.alfresco.rest.tags; + +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestTagModel; +import org.alfresco.utility.Utility; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.RandomData; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.commons.lang3.RandomStringUtils; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 10/4/2016. + */ +@Test(groups = {TestGroup.REQUIRE_SOLR}) +public class UpdateTagTests extends TagsDataPrep +{ + private RestTagModel oldTag; + private String randomTag = ""; + + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + init(); + } + + @BeforeMethod(alwaysRun=true) + public void addTagToDocument() throws Exception + { + restClient.authenticateUser(adminUserModel); + oldTag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("old")); + randomTag = RandomData.getRandomName("tag"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.SANITY, description = "Verify Admin user updates tags and status code is 200") + @Bug(id="REPO-1828") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY }) + public void adminIsAbleToUpdateTags() throws Exception + { + restClient.authenticateUser(adminUserModel); + returnedModel = restClient.withCoreAPI().usingTag(oldTag).update(randomTag); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedModel.assertThat().field("tag").is(randomTag); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify Manager user can't update tags with Rest API and status code is 403") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void managerIsNotAbleToUpdateTag() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + restClient.withCoreAPI().usingTag(oldTag).update(randomTag); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, + executionType = ExecutionType.REGRESSION, description = "Verify Collaborator user can't update tags with Rest API and status code is 403") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void collaboratorIsNotAbleToUpdateTagCheckDefaultErrorModelSchema() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); + restClient.withCoreAPI().usingTag(oldTag).update(randomTag); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED) + .containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, + executionType = ExecutionType.REGRESSION, description = "Verify Contributor user can't update tags with Rest API and status code is 403") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void contributorIsNotAbleToUpdateTag() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); + restClient.withCoreAPI().usingTag(oldTag).update(randomTag); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, + executionType = ExecutionType.SANITY, description = "Verify Consumer user can't update tags with Rest API and status code is 403") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void consumerIsNotAbleToUpdateTag() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)); + restClient.withCoreAPI().usingTag(oldTag).update(randomTag); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, + executionType = ExecutionType.SANITY, description = "Verify user gets status code 401 if authentication call fails") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY }) +// @Bug(id="MNT-16904", description = "It fails only on environment with tenants") + public void userIsNotAbleToUpdateTagIfAuthenticationFails() throws Exception + { + UserModel siteManager = usersWithRoles.getOneUserWithRole(UserRole.SiteManager); + String managerPassword = siteManager.getPassword(); + siteManager.setPassword("wrongPassword"); + restClient.authenticateUser(siteManager); + restClient.withCoreAPI().usingTag(oldTag).update(randomTag); + siteManager.setPassword(managerPassword); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify admin is not able to update tag with invalid id") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void adminIsNotAbleToUpdateTagWithInvalidId() throws Exception + { + String invalidTagId = "invalid-id"; + RestTagModel tag = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag")); + tag.setId(invalidTagId); + restClient.withCoreAPI().usingTag(tag).update(RandomData.getRandomName("tag")); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, invalidTagId)); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify admin is not able to update tag with empty id") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void adminIsNotAbleToUpdateTagWithEmptyId() throws Exception + { + RestTagModel tag = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag")); + tag.setId(""); + restClient.withCoreAPI().usingTag(tag).update(RandomData.getRandomName("tag")); + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED) + .assertLastError().containsSummary(RestErrorModel.PUT_EMPTY_ARGUMENT); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify admin is not able to update tag with invalid body") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void adminIsNotAbleToUpdateTagWithEmptyBody() throws Exception + { + RestTagModel tag = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag")); + restClient.withCoreAPI().usingTag(tag).update(""); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(RestErrorModel.EMPTY_TAG); + } + + @Bug(id="ACE-5629") + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify admin is not able to update tag with invalid body containing '|' symbol") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void adminIsNotAbleToUpdateTagWithInvalidBodyScenario1() throws Exception + { + String invalidTagBody = "|.\"/<>*"; + RestTagModel tag = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag")); + Utility.waitToLoopTime(20); + restClient.withCoreAPI().usingTag(tag).update(invalidTagBody); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.INVALID_TAG, invalidTagBody)); + } + + @Bug(id="ACE-5629") + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify admin is not able to update tag with invalid body without '|' symbol") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void adminIsNotAbleToUpdateTagWithInvalidBodyScenario2() throws Exception + { + String invalidTagBody = ".\"/<>*"; + RestTagModel tag = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag")); + Utility.waitToLoopTime(20); + restClient.withCoreAPI().usingTag(tag).update(invalidTagBody); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.INVALID_TAG, invalidTagBody)); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify admin user can provide large string for new tag value.") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + @Bug(id="REPO-1828") + public void adminIsAbleToUpdateTagsProvideLargeStringTag() throws Exception + { + String largeStringTag = RandomStringUtils.randomAlphanumeric(10000); + + restClient.authenticateUser(adminUserModel); + returnedModel = restClient.withCoreAPI().usingTag(oldTag).update(largeStringTag); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedModel.assertThat().field("tag").is(largeStringTag); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify admin user can provide short string for new tag value.") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + @Bug(id="REPO-1828") + public void adminIsAbleToUpdateTagsProvideShortStringTag() throws Exception + { + String shortStringTag = RandomStringUtils.randomAlphanumeric(2); + + restClient.authenticateUser(adminUserModel); + returnedModel = restClient.withCoreAPI().usingTag(oldTag).update(shortStringTag); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedModel.assertThat().field("tag").is(shortStringTag); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify admin user can provide string with special chars for new tag value.") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + @Bug(id="REPO-1828") + public void adminIsAbleToUpdateTagsProvideSpecialCharsStringTag() throws Exception + { + String specialCharsString = "!@#$%^&*()'\".,<>-_+=|\\"; + + restClient.authenticateUser(adminUserModel); + returnedModel = restClient.withCoreAPI().usingTag(oldTag).update(specialCharsString); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedModel.assertThat().field("tag").is(specialCharsString); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify Admin user can provide existing tag for new tag value.") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + @Bug(id="REPO-1828") + public void adminIsAbleToUpdateTagsProvideExistingTag() throws Exception + { + String existingTag = "oldTag"; + RestTagModel oldExistingTag = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingResource(document).addTag(existingTag); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.authenticateUser(adminUserModel); + returnedModel = restClient.withCoreAPI().usingTag(oldExistingTag).update(existingTag); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedModel.assertThat().field("tag").is(existingTag); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify Admin user can delete a tag, add tag and update it.") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + @Bug(id="REPO-1828") + public void adminDeleteTagAddTagUpdateTag() throws Exception + { + restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingResource(document).deleteTag(oldTag); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + String newTag = "addTag"; + RestTagModel newTagModel = restClient.withCoreAPI().usingResource(document).addTag(newTag); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + returnedModel = restClient.withCoreAPI().usingTag(newTagModel).update(newTag); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedModel.assertThat().field("tag").is(newTag); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify Admin user can update a tag, delete tag and add it.") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + @Bug(id="REPO-1828") + public void adminUpdateTagDeleteTagAddTag() throws Exception + { + String newTag = "addTag"; + + returnedModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingTag(oldTag).update(newTag); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedModel.assertThat().field("tag").is(newTag); + + restClient.withCoreAPI().usingResource(document).deleteTag(returnedModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + restClient.withCoreAPI().usingResource(document).addTag(newTag); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + } +} \ No newline at end of file diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/nodes/AddTagTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/nodes/AddTagTests.java new file mode 100644 index 0000000000..816e5426fb --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/nodes/AddTagTests.java @@ -0,0 +1,336 @@ +package org.alfresco.rest.tags.nodes; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.rest.model.RestCommentModel; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestTagModel; +import org.alfresco.rest.model.RestTagModelsCollection; +import org.alfresco.rest.tags.TagsDataPrep; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.RandomData; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FolderModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.commons.lang3.RandomStringUtils; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 10/3/2016. + */ +@Test(groups = {TestGroup.REQUIRE_SOLR}) +public class AddTagTests extends TagsDataPrep +{ + private String tagValue; + private RestTagModel returnedModel; + private RestCommentModel returnedModelComment; + private RestTagModelsCollection returnedModelTags; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + init(); + } + + @BeforeMethod(alwaysRun = true) + public void generateRandomTag() + { + tagValue = RandomData.getRandomName("tag"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify admin user adds tags with Rest API and status code is 201") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void adminIsAbleToAddTag() throws Exception + { + restClient.authenticateUser(adminUserModel); + returnedModel = restClient.withCoreAPI().usingResource(document).addTag(tagValue); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + returnedModel.assertThat().field("tag").is(tagValue) + .and().field("id").isNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.SANITY, + description = "Verify Manager user adds tags with Rest API and status code is 201") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY }) + public void managerIsAbleToTagAFile() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + returnedModel = restClient.withCoreAPI().usingResource(document).addTag(tagValue); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + returnedModel.assertThat().field("tag").is(tagValue) + .and().field("id").isNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify Collaborator user adds tags with Rest API and status code is 201") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void collaboratorIsAbleToTagAFile() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); + returnedModel = restClient.withCoreAPI().usingResource(document).addTag(tagValue); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + returnedModel.assertThat().field("tag").is(tagValue) + .and().field("id").isNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify Contributor user doesn't have permission to add tags with Rest API and status code is 403") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void contributorIsNotAbleToAddTagToAnotherContent() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); + restClient.withCoreAPI().usingResource(document).addTag(tagValue); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify Contributor user adds tags to his content with Rest API and status code is 201") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void contributorIsAbleToAddTagToHisContent() throws Exception + { + userModel = usersWithRoles.getOneUserWithRole(UserRole.SiteContributor); + restClient.authenticateUser(userModel); + FileModel contributorDoc = dataContent.usingSite(siteModel).usingUser(userModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + returnedModel = restClient.withCoreAPI().usingResource(contributorDoc).addTag(tagValue); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + returnedModel.assertThat().field("id").isNotEmpty() + .and().field("tag").is(tagValue); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify Consumer user doesn't have permission to add tags with Rest API and status code is 403") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void consumerIsNotAbleToTagAFile() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)); + restClient.withCoreAPI().usingResource(document).addTag(tagValue); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.SANITY, + description = "Verify user gets status code 401 if authentication call fails") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY }) +// @Bug(id="MNT-16904", description = "It fails only on environment with tenants") + public void userIsNotAbleToAddTagIfAuthenticationFails() throws Exception + { + UserModel siteManager = usersWithRoles.getOneUserWithRole(UserRole.SiteManager); + String managerPassword = siteManager.getPassword(); + siteManager.setPassword("wrongPassword"); + restClient.authenticateUser(siteManager); + restClient.withCoreAPI().usingResource(document).addTag("tagUnauthorized"); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + siteManager.setPassword(managerPassword); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that adding empty tag returns status code 400") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void emptyTagTest() throws Exception + { + restClient.authenticateUser(adminUserModel); + returnedModel = restClient.withCoreAPI().usingResource(document).addTag(""); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(String.format(RestErrorModel.NULL_ARGUMENT, "tag")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that adding tag with user that has no permissions returns status code 403") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void addTagWithUserThatDoesNotHavePermissions() throws Exception + { + restClient.authenticateUser(dataUser.createRandomTestUser()); + returnedModel = restClient.withCoreAPI().usingResource(document).addTag(tagValue); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that adding tag to a node that does not exist returns status code 404") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void addTagToInexistentNode() throws Exception + { + String oldNodeRef = document.getNodeRef(); + String nodeRef = RandomStringUtils.randomAlphanumeric(10); + document.setNodeRef(nodeRef); + + restClient.authenticateUser(adminUserModel); + returnedModel = restClient.withCoreAPI().usingResource(document).addTag(tagValue); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, nodeRef)); + document.setNodeRef(oldNodeRef); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.SANITY, + description = "Verify that manager is able to tag a folder") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY }) + public void managerIsAbleToTagAFolder() throws Exception + { + FolderModel folderModel = dataContent.usingUser(adminUserModel).usingSite(siteModel).createFolder(); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + returnedModel = restClient.withCoreAPI().usingResource(folderModel).addTag(tagValue); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + returnedModel.assertThat().field("tag").is(tagValue).and().field("id").isNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that tagged file can be tagged again") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void addTagToATaggedFile() throws Exception + { + restClient.authenticateUser(adminUserModel); + + returnedModel = restClient.withCoreAPI().usingResource(document).addTag(tagValue); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + returnedModel.assertThat().field("tag").is(tagValue).and().field("id").isNotEmpty(); + + returnedModel = restClient.withCoreAPI().usingResource(document).addTag(tagValue); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + returnedModel.assertThat().field("tag").is(tagValue).and().field("id").isNotEmpty(); + + returnedModel = restClient.withCoreAPI().usingResource(document).addTag("random_tag_value"); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + returnedModel.assertThat().field("tag").is("random_tag_value").and().field("id").isNotEmpty(); + + restClient.withCoreAPI().usingResource(document).getNodeTags().assertThat() + .entriesListContains("tag", tagValue.toLowerCase()) + .and().entriesListContains("tag", "random_tag_value"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that user cannot add invalid tag") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void addInvalidTag() throws Exception + { + restClient.authenticateUser(adminUserModel); + returnedModel = restClient.withCoreAPI().usingResource(document).addTag("-1~!|@#$%^&*()_="); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(String.format(RestErrorModel.INVALID_TAG, "|")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that contributor is able to tag a folder created by self") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void contributorIsAbleToTagAFolderCreatedBySelf() throws Exception + { + FolderModel folderModel = dataContent.usingUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingSite(siteModel).createFolder(); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); + returnedModel = restClient.withCoreAPI().usingResource(folderModel).addTag(tagValue); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + returnedModel.assertThat().field("tag").is(tagValue).and().field("id").isNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that collaborator is able to tag a folder") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void collaboratorIsAbleToTagAFolder() throws Exception + { + FolderModel folderModel = dataContent.usingUser(adminUserModel).usingSite(siteModel).createFolder(); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); + returnedModel = restClient.withCoreAPI().usingResource(folderModel).addTag(tagValue); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + returnedModel.assertThat().field("tag").is(tagValue).and().field("id").isNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that consumer is not able to tag a folder. Check default error model schema.") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void consumerIsNotAbleToTagAFolder() throws Exception + { + FolderModel folderModel = dataContent.usingUser(adminUserModel).usingSite(siteModel).createFolder(); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .withCoreAPI().usingResource(folderModel).addTag(tagValue); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED) + .containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that tagged folder can be tagged again") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void addTagToATaggedFolder() throws Exception + { + FolderModel folderModel = dataContent.usingUser(adminUserModel).usingSite(siteModel).createFolder(); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + + returnedModel = restClient.withCoreAPI().usingResource(folderModel).addTag(tagValue); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + returnedModel.assertThat().field("tag").is(tagValue).and().field("id").isNotEmpty(); + + returnedModel = restClient.withCoreAPI().usingResource(folderModel).addTag("random_tag_value"); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + returnedModel.assertThat().field("tag").is("random_tag_value").and().field("id").isNotEmpty(); + + restClient.withCoreAPI().usingResource(folderModel).getNodeTags().assertThat() + .entriesListContains("tag", tagValue.toLowerCase()) + .and().entriesListContains("tag", "random_tag_value") + .and().entriesListCountIs(2); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Using collaborator provide more than one tag element") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void provideMoreThanOneTagElement() throws Exception + { + FolderModel folderModel = dataContent.usingUser(adminUserModel).usingSite(siteModel).createFolder(); + String tagValue1 = RandomData.getRandomName("tag1"); + String tagValue2 = RandomData.getRandomName("tag2"); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); + + returnedModelTags = restClient.withCoreAPI().usingResource(folderModel).addTags(tagValue, tagValue1, tagValue2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + returnedModelTags.assertThat().entriesListContains("tag", tagValue) + .and().entriesListContains("tag", tagValue1) + .and().entriesListContains("tag", tagValue2) + .and().entriesListCountIs(3); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that manager cannot add tag with special characters.") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void addTagWithSpecialCharacters() throws Exception + { + FolderModel folderModel = dataContent.usingUser(adminUserModel).usingSite(siteModel).createFolder(); + String specialCharsTag = "!@#$%^&*()'\".,<>-_+=|\\"; + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingResource(folderModel).addTag(specialCharsTag); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(String.format(RestErrorModel.INVALID_TAG, "|")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that you cannot tag a comment and it returns status code 405") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void addTagToAComment() throws Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + String comment = "comment for a tag"; + + restClient.authenticateUser(adminUserModel); + returnedModelComment = restClient.withCoreAPI().usingResource(file).addComment(comment); + file.setNodeRef(returnedModelComment.getId()); + restClient.withCoreAPI().usingResource(file).addTag(tagValue); + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED).assertLastError().containsSummary(RestErrorModel.CANNOT_TAG); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that you cannot tag a tag and it returns status code 405") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void addTagToATag() throws Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(adminUserModel); + returnedModel = restClient.withCoreAPI().usingResource(file).addTag(tagValue); + file.setNodeRef(returnedModel.getId()); + restClient.withCoreAPI().usingResource(file).addTag(tagValue); + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED).assertLastError().containsSummary(RestErrorModel.CANNOT_TAG); + } +} \ No newline at end of file diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/nodes/AddTagsTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/nodes/AddTagsTests.java new file mode 100644 index 0000000000..9beb0c6b3e --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/nodes/AddTagsTests.java @@ -0,0 +1,149 @@ +package org.alfresco.rest.tags.nodes; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestTagModel; +import org.alfresco.rest.model.RestTagModelsCollection; +import org.alfresco.rest.tags.TagsDataPrep; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.RandomData; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 10/7/2016. + */ +@Test(groups = {TestGroup.REQUIRE_SOLR}) +public class AddTagsTests extends TagsDataPrep +{ + private FileModel contributorDoc; + private String tag1, tag2; + private RestTagModelsCollection returnedCollection; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + init(); + } + + @BeforeMethod(alwaysRun = true) + public void generateRandomTagsList() + { + tag1 = RandomData.getRandomName("tag"); + tag2 = RandomData.getRandomName("tag"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify admin user adds multiple tags with Rest API and status code is 201") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void adminIsAbleToAddTags() throws Exception + { + restClient.authenticateUser(adminUserModel); + returnedCollection = restClient.withCoreAPI().usingResource(document).addTags(tag1, tag2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + returnedCollection.assertThat().entriesListContains("tag", tag1) + .and().entriesListContains("tag", tag2); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.SANITY, + description = "Verify Manager user adds multiple tags with Rest API and status code is 201") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY }) + public void managerIsAbleToAddTags() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + returnedCollection = restClient.withCoreAPI().usingResource(document).addTags(tag1, tag2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + returnedCollection.assertThat().entriesListContains("tag", tag1) + .and().entriesListContains("tag", tag2); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, + executionType = ExecutionType.SANITY, description = "Verify Collaborator user adds multiple tags with Rest API and status code is 201") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void collaboratorIsAbleToAddTags() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); + returnedCollection = restClient.withCoreAPI().usingResource(document).addTags(tag1, tag2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + returnedCollection.assertThat().entriesListContains("tag", tag1) + .and().entriesListContains("tag", tag2); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify Contributor user doesn't have permission to add multiple tags with Rest API and status code is 403") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void contributorIsNotAbleToAddTagsToAnotherContent() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); + restClient.withCoreAPI().usingResource(document).addTags(tag1, tag2); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify Contributor user adds multiple tags to his content with Rest API and status code is 201") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void contributorIsAbleToAddTagsToHisContent() throws Exception + { + userModel = usersWithRoles.getOneUserWithRole(UserRole.SiteContributor); + restClient.authenticateUser(userModel); + contributorDoc = dataContent.usingSite(siteModel).usingUser(userModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + returnedCollection = restClient.withCoreAPI().usingResource(contributorDoc).addTags(tag1, tag2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + returnedCollection.assertThat().entriesListContains("tag", tag1) + .and().entriesListContains("tag", tag2); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify Consumer user doesn't have permission to add multiple tags with Rest API and status code is 403") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void consumerIsNotAbleToAddTags() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI().usingResource(document).addTags(tag1, tag2); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.TAGS }, executionType = ExecutionType.SANITY, + description = "Verify user gets status code 401 if authentication call fails") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY }) +// @Bug(id="MNT-16904", description = "It fails only on environment with tenants") + public void userIsNotAbleToAddTagsIfAuthenticationFails() throws Exception + { + UserModel siteManager = usersWithRoles.getOneUserWithRole(UserRole.SiteManager); + String managerPassword = siteManager.getPassword(); + siteManager.setPassword("wrongPassword"); + restClient.authenticateUser(siteManager).withCoreAPI().usingResource(document).addTags(tag1, tag2); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + siteManager.setPassword(managerPassword); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify include count parameter") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void getTagsUsingCountParam() throws Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + String tagName = RandomData.getRandomName("tag"); + returnedModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).addTag(RandomData.getRandomName("tag")); + RestTagModelsCollection tagsWithIncludeParamCount = restClient.withParams("include=count").withCoreAPI().getTags(); + restClient.assertStatusCodeIs(HttpStatus.OK); + for (RestTagModel tagModel : tagsWithIncludeParamCount.getEntries()) + { + if (tagModel != null && tagModel.getTag() != null) + { + if (tagModel.getTag().equals(tagName)) + { + Assert.assertEquals(tagModel.getCount().intValue(), 1); + } + } + } + + } +} \ No newline at end of file diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/nodes/DeleteTagTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/nodes/DeleteTagTests.java new file mode 100644 index 0000000000..586dc42389 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/nodes/DeleteTagTests.java @@ -0,0 +1,286 @@ +package org.alfresco.rest.tags.nodes; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestTagModel; +import org.alfresco.rest.tags.TagsDataPrep; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.RandomData; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FolderModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.commons.lang3.RandomStringUtils; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 10/4/2016. + */ +@Test(groups = {TestGroup.REQUIRE_SOLR}) +public class DeleteTagTests extends TagsDataPrep +{ + private RestTagModel tag; + private FileModel contributorDoc; + + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + init(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify Admin user deletes tags with Rest API and status code is 204") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void adminIsAbleToDeleteTags() throws Exception + { + restClient.authenticateUser(adminUserModel); + tag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag")); + + restClient.withCoreAPI().usingResource(document).deleteTag(tag); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withCoreAPI().usingResource(document).getNodeTags() + .assertThat().entriesListDoesNotContain("tag", tag.getTag()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.SANITY, + description = "Verify Manager user deletes tags created by admin user with Rest API and status code is 204") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY }) + public void managerIsAbleToDeleteTags() throws Exception + { + restClient.authenticateUser(adminUserModel); + tag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag")); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + restClient.withCoreAPI().usingResource(document).deleteTag(tag); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify Collaborator user deletes tags created by admin user with Rest API and status code is 204") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void collaboratorIsAbleToDeleteTags() throws Exception + { + restClient.authenticateUser(adminUserModel); + tag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag")); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); + restClient.withCoreAPI().usingResource(document).deleteTag(tag); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify Contributor user can't delete tags created by admin user with Rest API and status code is 403") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void contributorIsNotAbleToDeleteTagsForAnotherUserContent() throws Exception + { + restClient.authenticateUser(adminUserModel); + tag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag")); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); + restClient.withCoreAPI().usingResource(document).deleteTag(tag); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify Contributor user deletes tags created by him with Rest API and status code is 204") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void contributorIsAbleToDeleteTagsForHisContent() throws Exception + { + userModel = usersWithRoles.getOneUserWithRole(UserRole.SiteContributor); + restClient.authenticateUser(userModel); + contributorDoc = dataContent.usingSite(siteModel).usingUser(userModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN);; + tag = restClient.withCoreAPI().usingResource(contributorDoc).addTag(RandomData.getRandomName("tag")); + + restClient.withCoreAPI().usingResource(document).deleteTag(tag); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify Consumer user can't delete tags created by admin user with Rest API and status code is 403") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void consumerIsNotAbleToDeleteTags() throws Exception + { + restClient.authenticateUser(adminUserModel); + tag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag")); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)); + restClient.withCoreAPI().usingResource(document).deleteTag(tag); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.SANITY, + description = "Verify user gets status code 401 if authentication call fails") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY }) +// @Bug(id="MNT-16904", description = "It fails only on environment with tenants") + public void userIsNotAbleToDeleteTagIfAuthenticationFails() throws Exception + { + restClient.authenticateUser(adminUserModel); + tag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag")); + + UserModel siteManager = usersWithRoles.getOneUserWithRole(UserRole.SiteManager); + String managerPassword = siteManager.getPassword(); + siteManager.setPassword("wrongPassword"); + restClient.authenticateUser(siteManager); + restClient.withCoreAPI().usingResource(document).deleteTag(tag); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + siteManager.setPassword(managerPassword); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that if user has no permission to remove tag returned status code is 403. Check default error model schema") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void deleteTagWithUserWithoutPermissionCheckDefaultErrorModelSchema() throws Exception + { + restClient.authenticateUser(adminUserModel); + RestTagModel tag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag")); + + restClient.authenticateUser(dataUser.createRandomTestUser()); + restClient.withCoreAPI().usingResource(document).deleteTag(tag); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError() + .containsSummary(RestErrorModel.PERMISSION_WAS_DENIED) + .containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that if node does not exist returned status code is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void deleteTagForANonexistentNode() throws Exception + { + restClient.authenticateUser(adminUserModel); + RestTagModel tag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag")); + + FileModel document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + String nodeRef = RandomStringUtils.randomAlphanumeric(10); + document.setNodeRef(nodeRef); + restClient.withCoreAPI().usingResource(document).deleteTag(tag); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, nodeRef)); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that if tag does not exist returned status code is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void deleteTagThatDoesNotExist() throws Exception + { + restClient.authenticateUser(adminUserModel); + RestTagModel tag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag")); + + tag.setId("abc"); + restClient.withCoreAPI().usingResource(document).deleteTag(tag); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "abc")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that if tag id is empty returned status code is 405") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void deleteTagWithEmptyId() throws Exception + { + restClient.authenticateUser(adminUserModel); + RestTagModel tag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag")); + + tag.setId(""); + restClient.withCoreAPI().usingResource(document).deleteTag(tag); + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED).assertLastError().containsSummary(RestErrorModel.DELETE_EMPTY_ARGUMENT); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that folder tag can be deleted") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void deleteFolderTag() throws Exception + { + FolderModel folderModel = dataContent.usingUser(adminUserModel).usingSite(siteModel).createFolder();; + restClient.authenticateUser(adminUserModel); + RestTagModel tag = restClient.withCoreAPI().usingResource(folderModel).addTag(RandomData.getRandomName("tag")); + restClient.withCoreAPI().usingResource(folderModel).deleteTag(tag); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withCoreAPI().usingResource(folderModel).getNodeTags() + .assertThat().entriesListDoesNotContain("tag", tag.getTag()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, + executionType = ExecutionType.REGRESSION, description = "Verify Manager user can't delete deleted tag.") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + @Bug(id = "ACE-5455") + public void managerCannotDeleteDeletedTag() throws Exception + { + tag = restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag")); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingResource(document).deleteTag(tag); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + restClient.withCoreAPI().usingResource(document).deleteTag(tag); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, + executionType = ExecutionType.REGRESSION, description = "Verify Collaborator user can delete long tag.") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void userCollaboratorCanDeleteLongTag() throws Exception + { + String longTag = RandomStringUtils.randomAlphanumeric(800); + + tag = restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingResource(document).addTag(longTag); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .withCoreAPI().usingResource(document).deleteTag(tag); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, + executionType = ExecutionType.REGRESSION, description = "Verify Manager user can delete short tag.") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void managerCanDeleteShortTag() throws Exception + { + String shortTag = RandomStringUtils.randomAlphanumeric(10); + + tag = restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingResource(document).addTag(shortTag); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingResource(document).deleteTag(tag); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, + executionType = ExecutionType.REGRESSION, description = "Verify Admin can delete tag then add it again.") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void adminRemovesTagAndAddsItAgain() throws Exception + { + String tagValue = RandomStringUtils.randomAlphanumeric(10); + + tag = restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingResource(document).addTag(tagValue); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingResource(document).deleteTag(tag); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + tag = restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingResource(document).addTag(tagValue); + RestTagModel returnedTag = restClient.withCoreAPI().getTag(tag); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedTag.assertThat().field("tag").is(tagValue.toLowerCase()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, + executionType = ExecutionType.REGRESSION, description = "Verify Manager user can delete tag added by another user.") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void managerCanDeleteTagAddedByAnotherUser() throws Exception + { + tag = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .withCoreAPI().usingResource(document).addTag(RandomStringUtils.randomAlphanumeric(10)); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingResource(document).deleteTag(tag); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + } +} \ No newline at end of file diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/nodes/GetNodeTagsTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/nodes/GetNodeTagsTests.java new file mode 100644 index 0000000000..f274fc066b --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/nodes/GetNodeTagsTests.java @@ -0,0 +1,318 @@ +package org.alfresco.rest.tags.nodes; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.tags.TagsDataPrep; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.model.FileModel; +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.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.commons.lang3.RandomStringUtils; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +@Test(groups = {TestGroup.REQUIRE_SOLR}) +public class GetNodeTagsTests extends TagsDataPrep +{ + private String tagValue; + private String tagValue2; + + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + init(); + tagValue = documentTagValue; + tagValue2 = documentTagValue2; + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, + executionType = ExecutionType.SANITY, description = "Verify site Manager is able to get node tags") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY }) + public void siteManagerIsAbleToRetrieveNodeTags() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + + returnedCollection = restClient.withCoreAPI().usingResource(document).getNodeTags(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedCollection.assertThat() + .entriesListContains("tag", tagValue.toLowerCase()) + .and().entriesListContains("tag", tagValue2.toLowerCase()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, + executionType = ExecutionType.REGRESSION, description = "Verify site Collaborator is able to get node tags") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void siteCollaboratorIsAbleToRetrieveNodeTags() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); + + returnedCollection = restClient.withCoreAPI().usingResource(document).getNodeTags(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedCollection.assertThat() + .entriesListContains("tag", tagValue.toLowerCase()) + .and().entriesListContains("tag", tagValue2.toLowerCase()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, + executionType = ExecutionType.REGRESSION, description = "Verify site Contributor is able to get node tags") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void siteContributorIsAbleToRetrieveNodeTags() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); + + returnedCollection = restClient.withCoreAPI().usingResource(document).getNodeTags(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedCollection.assertThat() + .entriesListContains("tag", tagValue.toLowerCase()) + .and().entriesListContains("tag", tagValue2.toLowerCase()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, + executionType = ExecutionType.REGRESSION, description = "Verify site Consumer is able to get node tags") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void siteConsumerIsAbleToRetrieveNodeTags() throws Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)); + + returnedCollection = restClient.withCoreAPI().usingResource(document).getNodeTags(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedCollection.assertThat() + .entriesListContains("tag", tagValue.toLowerCase()) + .and().entriesListContains("tag", tagValue2.toLowerCase()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, + executionType = ExecutionType.REGRESSION, description = "Verify admin is able to get node tags") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void adminIsAbleToRetrieveNodeTags() throws Exception + { + restClient.authenticateUser(adminUserModel); + returnedCollection = restClient.withCoreAPI().usingResource(document).getNodeTags(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedCollection.assertThat() + .entriesListContains("tag", tagValue.toLowerCase()) + .and().entriesListContains("tag", tagValue2.toLowerCase()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, + executionType = ExecutionType.SANITY, description = "Verify unauthenticated user is not able to get node tags") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY }) +// @Bug(id = "MNT-16904", description = "fails only on environment with tenants") + public void unauthenticatedUserIsNotAbleToRetrieveNodeTags() throws Exception + { + restClient.authenticateUser(new UserModel("random user", "random password")); + restClient.withCoreAPI().usingResource(document).getNodeTags(); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that using invalid value for skipCount parameter returns status code 400") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION}) + public void invalidSkipCountTest() throws Exception + { + restClient.withParams("skipCount=abc").withCoreAPI().usingResource(document).getNodeTags(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(String.format(RestErrorModel.INVALID_SKIPCOUNT, "abc")); + + restClient.withParams("skipCount=-1").withCoreAPI().usingResource(document).getNodeTags(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(RestErrorModel.NEGATIVE_VALUES_SKIPCOUNT); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that using invalid value for maxItems parameter returns status code 400") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION}) + public void invalidMaxItemsTest() throws Exception + { + restClient.withParams("maxItems=abc").withCoreAPI().usingResource(document).getNodeTags(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(String.format(RestErrorModel.INVALID_MAXITEMS, "abc")); + + restClient.withParams("maxItems=-1").withCoreAPI().usingResource(document).getNodeTags(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that user without permissions returns status code 403") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION}) + public void userWithoutPermissionsTest() throws Exception + { + SiteModel moderatedSite = dataSite.usingUser(adminUserModel).createModeratedRandomSite(); + FileModel moderatedDocument = dataContent.usingSite(moderatedSite).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(dataUser.createRandomTestUser()).withCoreAPI().usingResource(moderatedDocument).getNodeTags(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED) + .containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that if node does not exist returns status code 403") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION}) + public void nonexistentNodeTest() throws Exception + { + FileModel badDocument = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + String nodeRef = RandomStringUtils.randomAlphanumeric(10); + badDocument.setNodeRef(nodeRef); + + restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(badDocument).getNodeTags(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, nodeRef)); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that if node id is empty returns status code 403") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION}) + public void emptyNodeIdTest() throws Exception + { + FileModel badDocument = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + badDocument.setNodeRef(""); + + restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(badDocument).getNodeTags(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify folder tags") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION}) + public void folderTagsTest() throws Exception + { + FolderModel folder = dataContent.usingUser(adminUserModel).usingSite(siteModel).createFolder(); + + restClient.withCoreAPI().usingResource(folder).addTag(tagValue); + restClient.withCoreAPI().usingResource(folder).addTag(tagValue2); + + restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(folder).getNodeTags() + .assertThat() + .entriesListContains("tag", tagValue.toLowerCase()) + .and().entriesListContains("tag", tagValue2.toLowerCase()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify site Manager is able to get node tags using properties parameter") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void siteManagerIsAbleToRetrieveNodeTagsWithPropertiesParameter() throws Exception + { + returnedCollection = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withParams("properties=tag").withCoreAPI().usingResource(document).getNodeTags(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedCollection.assertThat().entriesListContains("tag", tagValue.toLowerCase()) + .and().entriesListContains("tag", tagValue2.toLowerCase()) + .and().entriesListDoesNotContain("id"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that Collaborator user is not able to get node tags using site id instead of node id") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void collaboratorGetNodeTagsUseSiteIdInsteadOfNodeId() throws Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + + file.setNodeRef(siteModel.getId()); + returnedCollection = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingResource(file).getNodeTags(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, file.getNodeRef())); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "With admin get node tags and use skipCount parameter. Check pagination and maxItems") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void useSkipCountCheckPaginationAndMaxItems() throws Exception + { + returnedCollection = restClient.authenticateUser(adminUserModel) + .withParams("skipCount=1").withCoreAPI().usingResource(document).getNodeTags(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedCollection.getPagination().assertThat().field("maxItems").is(100) + .and().field("hasMoreItems").is("false") + .and().field("count").isGreaterThan(1); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "With admin get node tags and use maxItems parameter. Check pagination") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void useMaxItemsParameterCheckPagination() throws Exception + { + returnedCollection = restClient.authenticateUser(adminUserModel) + .withParams("maxItems=1").withCoreAPI().usingResource(document).getNodeTags(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedCollection.getPagination().assertThat().field("maxItems").is(1) + .and().field("hasMoreItems").is("true") + .and().field("count").is("1") + .and().field("skipCount").is("0"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Using manager user get only one tag.") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void usingManagerGetOnlyOneTag() throws Exception + { + FileModel file = dataContent.usingAdmin().usingSite(siteModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).addTag(tagValue); + + returnedCollection = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingResource(file).getNodeTags(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedCollection.getPagination().assertThat().field("maxItems").is(100) + .and().field("hasMoreItems").is("false") + .and().field("totalItems").is("1") + .and().field("count").is("1") + .and().field("skipCount").is("0"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Using admin get last 2 tags and skip first 2 tags") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void adminUserGetLast2TagsAndSkipFirst2Tags() throws Exception + { + String firstTag = "1st tag"; + String secondTag = "2nd tag"; + String thirdTag = "3rd tag"; + String fourthTag = "4th tag"; + FileModel file = dataContent.usingAdmin().usingSite(siteModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).addTag(firstTag); + restClient.withCoreAPI().usingResource(file).addTag(secondTag); + restClient.withCoreAPI().usingResource(file).addTag(thirdTag); + restClient.withCoreAPI().usingResource(file).addTag(fourthTag); + + returnedCollection = restClient.withParams("skipCount=2").withCoreAPI().usingResource(file).getNodeTags(); + restClient.assertStatusCodeIs(HttpStatus.OK); + + returnedCollection.assertThat().entriesListContains("tag", thirdTag.toLowerCase()) + .and().entriesListContains("tag", fourthTag.toLowerCase()); + returnedCollection.getPagination().assertThat().field("maxItems").is(100) + .and().field("hasMoreItems").is("false") + .and().field("totalItems").is("4") + .and().field("count").is("2") + .and().field("skipCount").is("2"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "With admin get node tags and use maxItems=0.") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void getTagsWithZeroMaxItems() throws Exception + { + returnedCollection = restClient.authenticateUser(adminUserModel) + .withParams("maxItems=0").withCoreAPI().usingResource(document).getNodeTags(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, + description = "Verify that using high skipCount parameter returns status code 200.") + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void getTagsWithHighSkipCount() throws Exception + { + returnedCollection = restClient.authenticateUser(adminUserModel).withParams("skipCount=10000") + .withCoreAPI().usingResource(document).getNodeTags(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedCollection.getPagination().assertThat().field("maxItems").is(100) + .and().field("hasMoreItems").is("false") + .and().field("count").is("0") + .and().field("skipCount").is("10000"); + returnedCollection.assertThat().entriesListCountIs(0); + } +} \ No newline at end of file diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/trashcan/GetDeletedNodesTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/trashcan/GetDeletedNodesTests.java new file mode 100644 index 0000000000..1fb8eed888 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/trashcan/GetDeletedNodesTests.java @@ -0,0 +1,249 @@ +/* + * Copyright (C) 2005-2017 Alfresco Software Limited. + * This file is part of Alfresco + * 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 . + */ + +package org.alfresco.rest.trashcan; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestNodeModel; +import org.alfresco.rest.model.RestNodeModelsCollection; +import org.alfresco.rest.model.RestRenditionInfoModel; +import org.alfresco.rest.model.RestRenditionInfoModelCollection; +import org.alfresco.utility.Utility; +import org.alfresco.utility.exception.DataPreparationException; +import org.alfresco.utility.model.FileModel; +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.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Tests for /api-explorer/#!/trashcan/listDeletedNodes + * /api-explorer/#!/trashcan/deleteDeletedNode + * /api-explorer/#!/trashcan/getDeletedNode + * /api-explorer/#!/trashcan/restoreDeletedNode + * + * @author jcule + * + */ +public class GetDeletedNodesTests extends RestTest +{ + private UserModel adminUserModel; + private SiteModel deleteNodesSiteModel; + private FolderModel deleteNodesFolder1, deleteNodesFolder2, deleteNodesFolder3, deleteNodesFolder4, deleteNodesFolder5, getDeleteNodesFolder6; + private FileModel file, file1, file2, file3, file4; + + private RestNodeModelsCollection deletedNodes, deletedNodesMaxItem; + private RestNodeModel node; + + private RestRenditionInfoModelCollection nodeRenditionInfoCollection; + private RestRenditionInfoModel nodeRenditionInfo; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws DataPreparationException + { + adminUserModel = dataUser.getAdminUser(); + restClient.authenticateUser(adminUserModel); + deleteNodesSiteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); + } + + @AfterClass(alwaysRun = true) + public void cleanup() throws Exception + { + dataSite.usingAdmin().deleteSite(deleteNodesSiteModel); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.REGRESSION }) + public void testDeletedNodesBiggerThanMaxCount() throws Exception + { + // get the number of item in the trashcan + deletedNodes = restClient.withCoreAPI().usingTrashcan().findDeletedNodes(); + int count = deletedNodes.getPagination().getCount(); + int totalItems = deletedNodes.getPagination().getTotalItems(); + + // create folders + deleteNodesFolder1 = dataContent.usingUser(adminUserModel).usingSite(deleteNodesSiteModel).createFolder(); + deleteNodesFolder2 = dataContent.usingUser(adminUserModel).usingSite(deleteNodesSiteModel).createFolder(); + deleteNodesFolder3 = dataContent.usingUser(adminUserModel).usingSite(deleteNodesSiteModel).createFolder(); + + // delete folders + dataContent.usingUser(adminUserModel).usingResource(deleteNodesFolder1).deleteContent(); + dataContent.usingUser(adminUserModel).usingResource(deleteNodesFolder2).deleteContent(); + dataContent.usingUser(adminUserModel).usingResource(deleteNodesFolder3).deleteContent(); + + int maxItems = count + 1; + deletedNodesMaxItem = restClient.withCoreAPI().usingTrashcan().usingParams(String.format("maxItems=%s", maxItems)).findDeletedNodes(); + + String countMaxItem = Integer.toString(maxItems); + String totalItemsMaxItem = Integer.toString(totalItems + 3); + String hasMoreItemsMaxItem = Boolean.toString(deletedNodesMaxItem.getPagination().isHasMoreItems()); + String skipCount = Integer.toString(deletedNodesMaxItem.getPagination().getSkipCount()); + + restClient.assertStatusCodeIs(HttpStatus.OK); + deletedNodesMaxItem.getPagination().assertThat().field("totalItems").is(totalItemsMaxItem).and().field("count").is(countMaxItem); + deletedNodesMaxItem.getPagination().assertThat().field("hasMoreItems").is(hasMoreItemsMaxItem).and().field("skipCount").is(skipCount); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TRASHCAN }, executionType = ExecutionType.SANITY, description = "Sanity tests for GET /deleted-nodes and GET /deleted-nodes/{nodeId}") + @Test(groups = { TestGroup.REST_API, TestGroup.TRASHCAN, TestGroup.SANITY }) + public void testGetDeletedNodesFromTrashcan() throws Exception + { + // Create a folder and a file + deleteNodesFolder4 = dataContent.usingUser(adminUserModel).usingSite(deleteNodesSiteModel).createFolder(); + file = dataContent.usingUser(adminUserModel).usingSite(deleteNodesSiteModel).createContent(DocumentType.TEXT_PLAIN); + + // Delete file and folder + dataContent.usingUser(adminUserModel).usingResource(deleteNodesFolder4).deleteContent(); + dataContent.usingUser(adminUserModel).usingResource(file).deleteContent(); + + // GET /deleted-nodes: deleted file and folder are in the trashcan list + deletedNodes = restClient.withCoreAPI().usingTrashcan().findDeletedNodes(); + restClient.assertStatusCodeIs(HttpStatus.OK); + deletedNodes.getEntryByIndex(0).assertThat().field("name").is(file.getName()).and() + .field("id").is(file.getNodeRefWithoutVersion()); + deletedNodes.getEntryByIndex(1).assertThat().field("name").is(deleteNodesFolder4.getName()).and() + .field("id").is(deleteNodesFolder4.getNodeRefWithoutVersion()); + + // GET /deleted-nodes/{nodeId}: check a single deleted object + node = restClient.withCoreAPI().usingTrashcan().findDeletedNode(deleteNodesFolder4); + restClient.assertStatusCodeIs(HttpStatus.OK); + node.assertThat().field("name").is(deleteNodesFolder4.getName()).and() + .field("id").is(deleteNodesFolder4.getNodeRefWithoutVersion()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TRASHCAN }, executionType = ExecutionType.SANITY, description = "Sanity tests for DELETE /deleted-nodes/{nodeId} and POST /deleted-nodes/{nodeId}/restore") + @Test(groups = { TestGroup.REST_API, TestGroup.TRASHCAN, TestGroup.SANITY }) + public void testDeleteAndRestoreNodeFromTrashcan() throws Exception + { + // Create a folder and a file + deleteNodesFolder5 = dataContent.usingUser(adminUserModel).usingSite(deleteNodesSiteModel).createFolder(); + String docLibNodeRef = dataContent.usingUser(adminUserModel).usingSite(deleteNodesSiteModel).getNodeRef(); + file1 = dataContent.usingUser(adminUserModel).usingSite(deleteNodesSiteModel).createContent(DocumentType.TEXT_PLAIN); + + // Delete file and folder + dataContent.usingUser(adminUserModel).usingResource(deleteNodesFolder5).deleteContent(); + dataContent.usingUser(adminUserModel).usingResource(file1).deleteContent(); + + // DELETE /deleted-nodes/{nodeId}: delete an object from trashcan + restClient.withCoreAPI().usingTrashcan().deleteNodeFromTrashcan(file1); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + restClient.withCoreAPI().usingTrashcan().findDeletedNode(file1); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND); + + // POST /deleted-nodes/{nodeId}/restore: restore to repository a deleted object + node = restClient.withCoreAPI().usingTrashcan().restoreNodeFromTrashcan(deleteNodesFolder5); + restClient.assertStatusCodeIs(HttpStatus.OK); + node.assertThat().field("id").is(deleteNodesFolder5.getNodeRefWithoutVersion()).and() + .field("parentId").is(docLibNodeRef); + + // Checks that the node was removed from trashcan + restClient.withCoreAPI().usingTrashcan().findDeletedNode(deleteNodesFolder5); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.TRASHCAN }, executionType = ExecutionType.SANITY, description = "Sanity tests for GET /deleted-nodes/{nodeId}/content") + @Test(groups = { TestGroup.REST_API, TestGroup.TRASHCAN, TestGroup.SANITY }) + public void testGetDeletedNodesContent() throws Exception + { + // Create file2 based on existing resource + FileModel newFile = FileModel.getFileModelBasedOnTestDataFile("sampleContent.txt"); + newFile.setName("sampleContent.txt"); + file2 = dataContent.usingUser(adminUserModel).usingSite(deleteNodesSiteModel).createContent(newFile); + + // Delete file2 to be moved in trashcan + dataContent.usingUser(adminUserModel).usingResource(file2).deleteContent(); + + // Make GET /deleted-nodes/{nodeId}/content and check file content + restClient.withCoreAPI().usingTrashcan().getDeletedNodeContent(file2); + restClient.assertStatusCodeIs(HttpStatus.OK); + restClient.assertHeaderValueContains("Content-Disposition", file2.getName()); + restClient.onResponse().getResponse().body().asString().contains("Sample text."); + } + + @Bug(id = "REPO-4484") + @TestRail(section = { TestGroup.REST_API, TestGroup.TRASHCAN, TestGroup.REQUIRE_SOLR }, executionType = ExecutionType.SANITY, + description = "Sanity tests for GET /deleted-nodes/{nodeId}/renditions, GET /deleted-nodes/{nodeId}/renditions/{renditionId}, GET /deleted-nodes/{nodeId}/renditions/{renditionId}/content") + @Test(groups = { TestGroup.REST_API, TestGroup.TRASHCAN, TestGroup.SANITY, TestGroup.RENDITIONS }) + public void testGetDeletedNodesRenditions() throws Exception + { + // Create file3 based on existing resource + file3 = dataContent.usingUser(adminUserModel).usingSite(deleteNodesSiteModel).createContent(DocumentType.TEXT_PLAIN); + + // Create rendition and delete file3 to be moved in trashcan + restClient.withCoreAPI().usingNode(file3).createNodeRendition("pdf"); + restClient.withCoreAPI().usingNode(file3).createNodeRendition("doclib"); + restClient.assertStatusCodeIs(HttpStatus.ACCEPTED); + dataContent.usingUser(adminUserModel).usingResource(file3).deleteContent(); + + // GET /deleted-nodes/{nodeId}/renditions + Utility.sleep(1000, 30000, () -> + { + nodeRenditionInfoCollection = restClient.authenticateUser(adminUserModel).withCoreAPI().usingTrashcan().getDeletedNodeRenditions(file3); + restClient.assertStatusCodeIs(HttpStatus.OK); + + // Check if renditions are retrieved, created or not. Entries are ordered + nodeRenditionInfoCollection.assertThat().entriesListContains("id", "doclib"); + nodeRenditionInfoCollection.getEntryByIndex(5).assertThat().field("id").is("pdf").and() + .field("status").is("CREATED"); + }); + + // GET /deleted-nodes/{nodeId}/renditions/{id} + nodeRenditionInfo = restClient.authenticateUser(adminUserModel).withCoreAPI().usingTrashcan().getDeletedNodeRendition(file3, "pdf"); + restClient.assertStatusCodeIs(HttpStatus.OK); + nodeRenditionInfo.assertThat().field("id").is("pdf").and() + .field("status").is("CREATED"); + + // GET /deleted-nodes/{nodeId}/renditions/{id}/content + restClient.authenticateUser(adminUserModel).withCoreAPI().usingTrashcan().getDeletedNodeRenditionContent(file3, "pdf"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restClient.assertHeaderValueContains("Content-Type","application/pdf;charset=UTF-8"); + Assert.assertTrue(restClient.onResponse().getResponse().body().asInputStream().available() > 0); + } + + @Bug(id = "REPO-4778") + @TestRail(section = {TestGroup.REST_API, TestGroup.TRASHCAN, TestGroup.REQUIRE_SOLR}, executionType = ExecutionType.SANITY, + description = "Sanity test to verify Range request header on GET /deleted-nodes/{nodeId}/renditions/{renditionId}/content endpoint") + @Test(groups = {TestGroup.REST_API, TestGroup.TRASHCAN, TestGroup.SANITY, TestGroup.RENDITIONS}) + public void testGetDeletedNodesRenditionsandVerifyRangeRequestheader() throws Exception + { + // Create file4 based on existing resource + file4 = dataContent.usingUser(adminUserModel).usingSite(deleteNodesSiteModel).createContent(DocumentType.TEXT_PLAIN); + + // Create rendition and delete file4 to be moved in trashcan + restClient.withCoreAPI().usingNode(file4).createNodeRendition("pdf"); + restClient.assertStatusCodeIs(HttpStatus.ACCEPTED); + dataContent.usingUser(adminUserModel).usingResource(file4).deleteContent(); + + // GET /deleted-nodes/{nodeId}/renditions/{id}/content and verify range request header + Utility.sleep(1000, 30000, () -> + { + restClient.configureRequestSpec().addHeader("content-range", "bytes=1-10"); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingTrashcan().getDeletedNodeRenditionContent(file4, "pdf"); + restClient.assertStatusCodeIs(HttpStatus.PARTIAL_CONTENT); + restClient.assertHeaderValueContains("Content-Type", "application/pdf;charset=UTF-8"); + restClient.assertHeaderValueContains("content-range", "bytes 1-10"); + restClient.assertHeaderValueContains("content-length", String.valueOf(10)); + }); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/deployments/DeleteDeploymentTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/deployments/DeleteDeploymentTests.java new file mode 100644 index 0000000000..0a929fd0e7 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/deployments/DeleteDeploymentTests.java @@ -0,0 +1,144 @@ +package org.alfresco.rest.workflow.deployments; + +import java.util.List; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestDeploymentModel; +import org.alfresco.rest.model.RestDeploymentModelsCollection; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestProcessDefinitionModel; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.rest.model.RestTaskModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Tests for REST API call DELETE "/deployments/{deploymentId}" + * Class has priority 100 in order to be executed last in the list of tests classes + * + * @author Cristina Axinte + * + */ +public class DeleteDeploymentTests extends RestTest +{ + private UserModel adminUser, userModel; + private RestDeploymentModel deployment; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + userModel = dataUser.createRandomTestUser(); + } + + @Bug(id = "REPO-1930") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.DEPLOYMENTS }, + executionType = ExecutionType.SANITY, description = "Verify admin user deletes a specific deployment using REST API and status code is successful (204)") + @Test(groups = { TestGroup.REST_API, TestGroup.DEPLOYMENTS, TestGroup.SANITY, TestGroup.WORKFLOW }, priority = 100) + public void adminDeletesDeploymentWithSuccess() throws Exception + { + dataContent.assertExtensionAmpExists("alfresco-workflow-extension"); + // The deployment with name "customWorkflowExtentionForRest.bpmn" is created by Workflow Extention Point + RestDeploymentModelsCollection allDeployments = restClient.authenticateUser(adminUser).withWorkflowAPI().getDeployments(); + allDeployments.assertThat().entriesListContains("name", "customWorkflowExtentionForRest.bpmn"); + deployment = allDeployments.getDeploymentByName("customWorkflowExtentionForRest.bpmn"); + + RestProcessDefinitionModel processDefinitionAssociated = + restClient.withWorkflowAPI().getAllProcessDefinitions().getProcessDefinitionById(deployment.getId()); + + RestProcessModel addedProcess = + restClient.withWorkflowAPI().addProcess(processDefinitionAssociated.getName(), adminUser, false, CMISUtil.Priority.Normal); + + List processTasks = + restClient.withWorkflowAPI().usingProcess(addedProcess).getProcessTasks().getEntries(); + + restClient.withWorkflowAPI().usingDeployment(deployment).deleteDeployment(); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + //check get deployment returns http status Not Found after deleting the deployment + restClient.withWorkflowAPI().usingDeployment(deployment).getDeployment(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, deployment.getId())); + + //check that process definitions contained by deployment are deleted + restClient.withWorkflowAPI().usingProcessDefinitions(processDefinitionAssociated).getProcessDefinition(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, processDefinitionAssociated.getId())); + + //check that history information associated with the deployment is deleted + restClient.withWorkflowAPI().usingProcess(addedProcess).getProcess(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, addedProcess.getId())); + + for (RestTaskModel processTask: processTasks) + { + restClient.withWorkflowAPI().usingTask(processTask).getTask(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, processTask.getId())); + } + + //check getProcessDefinitionStartFormModel after deletion of process definition + restClient.withWorkflowAPI().usingProcessDefinitions(processDefinitionAssociated).getProcessDefinitionStartFormModel(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, processDefinitionAssociated.getId())); + + //check getProcessDefinitionImage after deletion of process definition + restClient.withWorkflowAPI().usingProcessDefinitions(processDefinitionAssociated).getProcessDefinitionImage(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, processDefinitionAssociated.getId())); + + //delete deployment twice + restClient.withWorkflowAPI().usingDeployment(deployment).deleteDeployment(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, deployment.getId())) + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Bug(id = "REPO-1930") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.DEPLOYMENTS }, + executionType = ExecutionType.SANITY, description = "Verify admin user cannot delete an inexistent deployment using REST API and status code is successful (204)") + @Test(groups = { TestGroup.REST_API, TestGroup.DEPLOYMENTS, TestGroup.SANITY, TestGroup.WORKFLOW }, priority = 100) + public void adminCannotDeleteInexistentDeployment() throws Exception + { + deployment = restClient.authenticateUser(adminUser).withWorkflowAPI().getDeployments().getOneRandomEntry().onModel(); + deployment.setId(String.valueOf(1000)); + + restClient.withWorkflowAPI().usingDeployment(deployment).deleteDeployment(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "1000")); + } + + @Bug(id = "REPO-1930") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.DEPLOYMENTS }, executionType = ExecutionType.REGRESSION, + description = "Verify deleteDeployment is unsupported for empty deployment id with REST API and status code is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.DEPLOYMENTS, TestGroup.REGRESSION, TestGroup.WORKFLOW }) + public void deleteDeploymentIsUnsupportedForEmptyId() throws Exception + { + deployment = restClient.authenticateUser(adminUser).withWorkflowAPI().getDeployments().getOneRandomEntry().onModel(); + deployment.setId(""); + restClient.withWorkflowAPI().usingDeployment(deployment).deleteDeployment(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "")); + } + + @Bug(id = "REPO-1930") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.DEPLOYMENTS }, executionType = ExecutionType.REGRESSION, + description = "Verify deleteDeployment is forbidden using non admin user or different user than creator with REST API and status code is 403") + @Test(groups = { TestGroup.REST_API, TestGroup.DEPLOYMENTS, TestGroup.REGRESSION, TestGroup.WORKFLOW }) + public void deleteDeploymentUsingNonAdminUser() throws Exception + { + deployment = restClient.authenticateUser(adminUser).withWorkflowAPI().getDeployments().getOneRandomEntry().onModel(); + restClient.authenticateUser(userModel).withWorkflowAPI().usingDeployment(deployment).deleteDeployment(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/deployments/GetDeploymentCoreTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/deployments/GetDeploymentCoreTests.java new file mode 100644 index 0000000000..df2aae3a05 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/deployments/GetDeploymentCoreTests.java @@ -0,0 +1,42 @@ +package org.alfresco.rest.workflow.deployments; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestDeploymentModel; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 12/7/2016. + */ +public class GetDeploymentCoreTests extends RestTest +{ + private UserModel adminUser; + private RestDeploymentModel expectedDeployment; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.DEPLOYMENTS }, + executionType = ExecutionType.REGRESSION, + description = "Verify if get deployment request returns status code 404 when invalid deploymentId is used.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.DEPLOYMENTS, TestGroup.REGRESSION }) + public void getNonNetworkDeploymentUsingInvalidDeploymentId() throws Exception + { + expectedDeployment = restClient.authenticateUser(adminUser).withWorkflowAPI().getDeployments().getOneRandomEntry().onModel(); + expectedDeployment.setId("invalidId"); + + restClient.withWorkflowAPI().usingDeployment(expectedDeployment).getDeployment(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "invalidId")); + } + +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/deployments/GetDeploymentFullTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/deployments/GetDeploymentFullTests.java new file mode 100644 index 0000000000..cea14ceca2 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/deployments/GetDeploymentFullTests.java @@ -0,0 +1,57 @@ +package org.alfresco.rest.workflow.deployments; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.model.RestDeploymentModel; +import org.alfresco.rest.model.RestDeploymentModelsCollection; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 1/31/2017. + */ +public class GetDeploymentFullTests extends RestTest +{ + private UserModel adminUser; + private RestDeploymentModel expectedDeployment, actualDeployment; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.DEPLOYMENTS }, + executionType = ExecutionType.REGRESSION, + description = "Verify if get deployment request returns all deployments if empty deploymentId is used.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.DEPLOYMENTS, TestGroup.REGRESSION }) + public void getNonNetworkDeploymentUsingEmptyDeploymentId() throws Exception + { + restClient.authenticateUser(adminUser).withWorkflowAPI(); + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "deployments/{deploymentId}", ""); + RestDeploymentModelsCollection deployments = restClient.processModels(RestDeploymentModelsCollection.class, request); + restClient.assertStatusCodeIs(HttpStatus.OK); + deployments.assertThat().entriesListIsNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.DEPLOYMENTS }, executionType = ExecutionType.REGRESSION, + description = "Verify Admin user gets non-network deployments with properties parameter applied using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.DEPLOYMENTS, TestGroup.REGRESSION}) + public void getNonNetworkDeploymentsWithValidProperties() throws Exception + { + expectedDeployment = restClient.authenticateUser(adminUser).withWorkflowAPI().getDeployments().getOneRandomEntry().onModel(); + actualDeployment = restClient.withParams("properties=id,name").withWorkflowAPI().usingDeployment(expectedDeployment).getDeployment(); + restClient.assertStatusCodeIs(HttpStatus.OK); + actualDeployment.assertThat() + .fieldsCount().is(2).and() + .field("id").is(expectedDeployment.getId()).and() + .field("deployedAt").isNull().and() + .field("name").is(expectedDeployment.getName()); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/deployments/GetDeploymentSanityTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/deployments/GetDeploymentSanityTests.java new file mode 100644 index 0000000000..67bda8b8a6 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/deployments/GetDeploymentSanityTests.java @@ -0,0 +1,57 @@ +package org.alfresco.rest.workflow.deployments; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.exception.JsonToModelConversionException; +import org.alfresco.rest.model.RestDeploymentModel; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Tests for REST API call GET "/deployments/{deploymentId}" + * + * @author Cristina Axinte + * + */ +public class GetDeploymentSanityTests extends RestTest +{ + private UserModel adminUser; + private UserModel anotherUser; + private RestDeploymentModel expectedDeployment, actualDeployment; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + anotherUser = dataUser.createRandomTestUser(); + + expectedDeployment = restClient.authenticateUser(adminUser).withWorkflowAPI().getDeployments().getOneRandomEntry().onModel(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.DEPLOYMENTS }, + executionType = ExecutionType.SANITY, description = "Verify admin user gets a non-network deployment using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.DEPLOYMENTS, TestGroup.SANITY }) + public void adminGetsNonNetworkDeploymentWithSuccess() throws JsonToModelConversionException, Exception + { + actualDeployment = restClient.authenticateUser(adminUser).withWorkflowAPI().usingDeployment(expectedDeployment).getDeployment(); + restClient.assertStatusCodeIs(HttpStatus.OK); + actualDeployment.assertThat().field("deployedAt").isNotEmpty() + .and().field("name").is(expectedDeployment.getName()) + .and().field("id").is(expectedDeployment.getId()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.DEPLOYMENTS }, + executionType = ExecutionType.SANITY, description = "Verify non admin user is forbidden to get a non-network deployment using REST API (403)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.DEPLOYMENTS, TestGroup.SANITY }) + public void nonAdminIsForbiddenToGetNonNetworkDeployment() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(anotherUser).withWorkflowAPI().usingDeployment(expectedDeployment).getDeployment(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/deployments/GetDeploymentsCoreTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/deployments/GetDeploymentsCoreTests.java new file mode 100644 index 0000000000..f35f882a40 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/deployments/GetDeploymentsCoreTests.java @@ -0,0 +1,30 @@ +package org.alfresco.rest.workflow.deployments; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 12/7/2016. + */ +public class GetDeploymentsCoreTests extends RestTest +{ + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.DEPLOYMENTS }, + executionType = ExecutionType.REGRESSION, + description = "Verify non admin user is not able to get non-network deployments using REST API and status code is Forbidden") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.DEPLOYMENTS, TestGroup.REGRESSION}) + public void nonAdminUserCanNotGetNonNetworkDeployments() throws Exception + { + UserModel userModel = dataUser.createRandomTestUser(); + restClient.authenticateUser(userModel).withWorkflowAPI().getDeployments(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/deployments/GetDeploymentsFullTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/deployments/GetDeploymentsFullTests.java new file mode 100644 index 0000000000..6ba152e461 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/deployments/GetDeploymentsFullTests.java @@ -0,0 +1,146 @@ +package org.alfresco.rest.workflow.deployments; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.exception.JsonToModelConversionException; +import org.alfresco.rest.model.RestDeploymentModel; +import org.alfresco.rest.model.RestDeploymentModelsCollection; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 1/30/2017. + */ +public class GetDeploymentsFullTests extends RestTest +{ + private UserModel adminUserModel; + private RestDeploymentModelsCollection deployments; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUserModel = dataUser.getAdminUser(); + restClient.authenticateUser(adminUserModel); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.DEPLOYMENTS }, executionType = ExecutionType.REGRESSION, + description = "Verify Admin user gets non-network deployments with skipCount parameter applied using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.DEPLOYMENTS, TestGroup.REGRESSION}) + public void getNonNetworkDeploymentsWithValidSkipCount() throws JsonToModelConversionException, Exception + { + deployments = restClient.withWorkflowAPI().getDeployments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + RestDeploymentModel firstDeployment = deployments.getEntries().get(0).onModel(); + RestDeploymentModel secondDeployment = deployments.getEntries().get(1).onModel(); + RestDeploymentModelsCollection deploymentsWithSkipCount = restClient.withParams("skipCount=2").withWorkflowAPI().getDeployments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + deploymentsWithSkipCount + .assertThat().entriesListDoesNotContain("name", firstDeployment.getName()) + .assertThat().entriesListDoesNotContain("name", secondDeployment.getName()) + .assertThat().entriesListCountIs(deployments.getEntries().size()-2); + deploymentsWithSkipCount.assertThat().paginationField("skipCount").is("2"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.DEPLOYMENTS }, executionType = ExecutionType.REGRESSION, + description = "Verify Admin user doesn't get non-network deployments when negative skipCount parameter is applied using REST API and status code is 400") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.DEPLOYMENTS, TestGroup.REGRESSION}) + public void getNonNetworkDeploymentsWithNegativeSkipCount() throws JsonToModelConversionException, Exception + { + restClient.withParams("skipCount=-1").withWorkflowAPI().getDeployments(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(RestErrorModel.NEGATIVE_VALUES_SKIPCOUNT) + .containsErrorKey(RestErrorModel.NEGATIVE_VALUES_SKIPCOUNT) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE) + .statusCodeIs(HttpStatus.BAD_REQUEST); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.DEPLOYMENTS }, executionType = ExecutionType.REGRESSION, + description = "Verify Admin user doesn't get non-network deployments when non numeric skipCount parameter is applied using REST API and status code is 400") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.DEPLOYMENTS, TestGroup.REGRESSION}) + public void getNonNetworkDeploymentsWithNotNumericSkipCount() throws JsonToModelConversionException, Exception + { + restClient.withParams("skipCount=A").withWorkflowAPI().getDeployments(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(String.format(RestErrorModel.INVALID_SKIPCOUNT, "A")); + } + + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.DEPLOYMENTS }, executionType = ExecutionType.REGRESSION, + description = "Verify Admin user gets non-network deployments with maxItems parameter applied using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.DEPLOYMENTS, TestGroup.REGRESSION}) + public void getNonNetworkDeploymentsWithValidMaxItems() throws JsonToModelConversionException, Exception + { + deployments = restClient.withWorkflowAPI().getDeployments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + RestDeploymentModel firstDeployment = deployments.getEntries().get(0).onModel(); + RestDeploymentModel secondDeployment = deployments.getEntries().get(1).onModel(); + RestDeploymentModelsCollection deploymentsWithMaxItems = restClient.withParams("maxItems=2").withWorkflowAPI().getDeployments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + deploymentsWithMaxItems + .assertThat().entriesListContains("name", firstDeployment.getName()) + .assertThat().entriesListContains("name", secondDeployment.getName()) + .assertThat().entriesListCountIs(2); + deploymentsWithMaxItems.assertThat().paginationField("maxItems").is("2"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.DEPLOYMENTS }, executionType = ExecutionType.REGRESSION, + description = "Verify Admin user doesn't get non-network deployments when negative maxItems parameter is applied using REST API and status code is 400") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.DEPLOYMENTS, TestGroup.REGRESSION}) + public void getNonNetworkDeploymentsWithNegativeMaxItems() throws JsonToModelConversionException, Exception + { + restClient.withParams("maxItems=-1").withWorkflowAPI().getDeployments(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS) + .containsErrorKey(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE) + .statusCodeIs(HttpStatus.BAD_REQUEST); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.DEPLOYMENTS }, executionType = ExecutionType.REGRESSION, + description = "Verify Admin user doesn't get non-network deployments when non numeric maxItems parameter is applied using REST API and status code is 400") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.DEPLOYMENTS, TestGroup.REGRESSION}) + public void getNonNetworkDeploymentsWithNotNumericMaxItems() throws JsonToModelConversionException, Exception + { + restClient.withParams("maxItems=A").withWorkflowAPI().getDeployments(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(String.format(RestErrorModel.INVALID_MAXITEMS, "A")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.DEPLOYMENTS }, executionType = ExecutionType.REGRESSION, + description = "Verify Admin user gets non-network deployments with properties parameter applied using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.DEPLOYMENTS, TestGroup.REGRESSION}) + public void getNonNetworkDeploymentsWithValidProperties() throws JsonToModelConversionException, Exception + { + deployments = restClient.withParams("properties=name").withWorkflowAPI().getDeployments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + deployments.assertThat().entriesListIsNotEmpty(); + deployments.getOneRandomEntry().onModel().assertThat() + .fieldsCount().is(1).and() + .field("id").isNull().and() + .field("deployedAt").isNull().and() + .field("name").isNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.DEPLOYMENTS }, executionType = ExecutionType.REGRESSION, + description = "Verify Admin user gets non-network deployments with non existing properties parameter applied using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.DEPLOYMENTS, TestGroup.REGRESSION}) + public void getNonNetworkDeploymentsWithNonExistingProperties() throws JsonToModelConversionException, Exception + { + deployments = restClient.withParams("properties=TAS").withWorkflowAPI().getDeployments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + deployments.assertThat().entriesListIsNotEmpty(); + deployments.getOneRandomEntry().onModel().assertThat() + .fieldsCount().is(0).and() + .field("id").isNull().and() + .field("deployedAt").isNull().and() + .field("name").isNull(); + } + +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/deployments/GetDeploymentsSanityTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/deployments/GetDeploymentsSanityTests.java new file mode 100644 index 0000000000..9d1a4025f5 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/deployments/GetDeploymentsSanityTests.java @@ -0,0 +1,44 @@ +package org.alfresco.rest.workflow.deployments; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.exception.JsonToModelConversionException; +import org.alfresco.rest.model.RestDeploymentModelsCollection; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 10/4/2016. + */ +public class GetDeploymentsSanityTests extends RestTest +{ + private UserModel adminUserModel; + private RestDeploymentModelsCollection deployments; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUserModel = dataUser.getAdminUser(); + restClient.authenticateUser(adminUserModel); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.DEPLOYMENTS }, executionType = ExecutionType.SANITY, + description = "Verify Admin user gets non-network deployments using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.DEPLOYMENTS, TestGroup.SANITY}) + public void getNonNetworkDeploymentsWithAdmin() throws JsonToModelConversionException, Exception + { + deployments = restClient.authenticateUser(adminUserModel).withWorkflowAPI().getDeployments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + deployments.assertThat().entriesListIsNotEmpty(); + deployments.getOneRandomEntry().onModel().assertThat() + .fieldsCount().is(3).and() + .field("id").isNotEmpty().and() + .field("deployedAt").isNotEmpty().and() + .field("name").isNotEmpty(); + } + +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processDefinitions/GetProcessDefinitionCoreTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processDefinitions/GetProcessDefinitionCoreTests.java new file mode 100644 index 0000000000..3edb7e0201 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processDefinitions/GetProcessDefinitionCoreTests.java @@ -0,0 +1,45 @@ +package org.alfresco.rest.workflow.processDefinitions; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestProcessDefinitionModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 12/5/2016. + */ +public class GetProcessDefinitionCoreTests extends RestTest +{ + private UserModel adminUser; + private RestProcessDefinitionModel randomProcessDefinition; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION }, + executionType = ExecutionType.REGRESSION, + description = "Verify if get process definition returns status code 404 when invalid processDefinitionId is used") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION, TestGroup.REGRESSION }) + public void getProcessDefinitionUsingInvalidProcessDefinitionId() throws Exception + { + restClient.authenticateUser(adminUser); + randomProcessDefinition = restClient.withWorkflowAPI().getAllProcessDefinitions().getOneRandomEntry().onModel(); + randomProcessDefinition.setId("invalidID"); + restClient.withWorkflowAPI() + .usingProcessDefinitions(randomProcessDefinition).getProcessDefinition(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "invalidID")) + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processDefinitions/GetProcessDefinitionFullTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processDefinitions/GetProcessDefinitionFullTests.java new file mode 100644 index 0000000000..17c2b6972b --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processDefinitions/GetProcessDefinitionFullTests.java @@ -0,0 +1,67 @@ +package org.alfresco.rest.workflow.processDefinitions; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.model.RestProcessDefinitionModel; +import org.alfresco.rest.model.RestProcessDefinitionModelsCollection; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 2/1/2017. + */ +public class GetProcessDefinitionFullTests extends RestTest +{ + private UserModel adminUser; + private RestProcessDefinitionModel randomProcessDefinition, returnedProcessDefinition; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION }, + executionType = ExecutionType.REGRESSION, + description = "Verify if get process definition returns all process definitions when empty processDefinitionId is used") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION, TestGroup.REGRESSION }) + public void getProcessDefinitionUsingEmptyProcessDefinitionId() throws Exception + { + restClient.authenticateUser(adminUser).withWorkflowAPI(); + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "/process-definitions/{processDefinitionId}", ""); + RestProcessDefinitionModelsCollection processDefinitions = restClient.processModels(RestProcessDefinitionModelsCollection.class, request); + restClient.assertStatusCodeIs(HttpStatus.OK); + processDefinitions.assertThat().entriesListIsNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION }, + executionType = ExecutionType.REGRESSION, + description = "Verify Admin user gets a process definition with properties parameter applied using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION, TestGroup.REGRESSION }) + public void getProcessDefinitionWithValidProperties() throws Exception + { + randomProcessDefinition = restClient.authenticateUser(adminUser).withWorkflowAPI().getAllProcessDefinitions().getOneRandomEntry().onModel(); + returnedProcessDefinition = restClient.withParams("properties=id,name,graphicNotationDefined,version") + .withWorkflowAPI() + .usingProcessDefinitions(randomProcessDefinition).getProcessDefinition(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedProcessDefinition.assertThat() + .fieldsCount().is(4).and() + .field("deploymentId").isNull().and() + .field("description").isNull().and() + .field("id").is(randomProcessDefinition.getId()).and() + .field("startFormResourceKey").isNull().and() + .field("category").isNull().and() + .field("title").isNull().and() + .field("version").is(randomProcessDefinition.getVersion()).and() + .field("graphicNotationDefined").is(randomProcessDefinition.getGraphicNotationDefined()).and() + .field("key").isNull().and() + .field("name").is(randomProcessDefinition.getName()); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processDefinitions/GetProcessDefinitionImageCoreTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processDefinitions/GetProcessDefinitionImageCoreTests.java new file mode 100644 index 0000000000..2fe6f5f3cb --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processDefinitions/GetProcessDefinitionImageCoreTests.java @@ -0,0 +1,46 @@ +package org.alfresco.rest.workflow.processDefinitions; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestProcessDefinitionModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 12/6/2016. + */ +public class GetProcessDefinitionImageCoreTests extends RestTest +{ + private UserModel adminUser; + private RestProcessDefinitionModel randomProcessDefinition; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION }, + executionType = ExecutionType.REGRESSION, + description = "Verify if get process definition image returns status code 404 when invalid processDefinitionId is used") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION, TestGroup.REGRESSION }) + public void getProcessDefinitionImageUsingInvalidProcessDefinitionId() throws Exception + { + restClient.authenticateUser(adminUser); + randomProcessDefinition = restClient.withWorkflowAPI().getAllProcessDefinitions().getOneRandomEntry().onModel(); + randomProcessDefinition.setId("invalidID"); + + restClient.withWorkflowAPI() + .usingProcessDefinitions(randomProcessDefinition).getProcessDefinitionImage(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "invalidID")) + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processDefinitions/GetProcessDefinitionImageFullTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processDefinitions/GetProcessDefinitionImageFullTests.java new file mode 100644 index 0000000000..9c37e7c467 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processDefinitions/GetProcessDefinitionImageFullTests.java @@ -0,0 +1,42 @@ +package org.alfresco.rest.workflow.processDefinitions; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestProcessDefinitionModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 2/1/2017. + */ +public class GetProcessDefinitionImageFullTests extends RestTest +{ + private UserModel adminUser; + private RestProcessDefinitionModel randomProcessDefinition; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + } + + @Bug(id = "REPO-1911") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION }, + executionType = ExecutionType.REGRESSION, + description = "Verify if get process definition image returns status code 404 when empty processDefinitionId is used") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION, TestGroup.REGRESSION }) + public void getProcessDefinitionImageUsingEmptyProcessDefinitionId() throws Exception + { + restClient.authenticateUser(adminUser); + randomProcessDefinition = restClient.withWorkflowAPI().getAllProcessDefinitions().getOneRandomEntry().onModel(); + randomProcessDefinition.setId(""); + restClient.withWorkflowAPI() + .usingProcessDefinitions(randomProcessDefinition).getProcessDefinitionImage(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processDefinitions/GetProcessDefinitionImageSanityTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processDefinitions/GetProcessDefinitionImageSanityTests.java new file mode 100644 index 0000000000..7240fb77b3 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processDefinitions/GetProcessDefinitionImageSanityTests.java @@ -0,0 +1,49 @@ +package org.alfresco.rest.workflow.processDefinitions; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestProcessDefinitionModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 10/13/2016. + */ +public class GetProcessDefinitionImageSanityTests extends RestTest +{ + private UserModel testUser; + private RestProcessDefinitionModel randomProcessDefinition; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + testUser = dataUser.createRandomTestUser(); + restClient.authenticateUser(dataUser.getAdminUser()); + randomProcessDefinition = restClient.withWorkflowAPI().getAllProcessDefinitions().getOneRandomEntry().onModel(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION }, executionType = ExecutionType.SANITY, + description = "Verify Any user gets a specific process definition image for non-network deployments using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION, TestGroup.SANITY, TestGroup.RENDITIONS }) + public void anyUserGetsProcessDefinitionImage() throws Exception + { + restClient.authenticateUser(testUser); + restClient.withWorkflowAPI().usingProcessDefinitions(randomProcessDefinition).getProcessDefinitionImage() + .assertResponseContainsImage(); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION }, executionType = ExecutionType.SANITY, + description = "Verify Admin user gets a specific process definition image for non-network deployments using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION, TestGroup.SANITY, TestGroup.RENDITIONS }) + public void adminGetsProcessDefinitionImage() throws Exception + { + restClient.withWorkflowAPI().usingProcessDefinitions(randomProcessDefinition).getProcessDefinitionImage() + .assertResponseContainsImage(); + restClient.assertStatusCodeIs(HttpStatus.OK); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processDefinitions/GetProcessDefinitionSanityTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processDefinitions/GetProcessDefinitionSanityTests.java new file mode 100644 index 0000000000..36d8ef8723 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processDefinitions/GetProcessDefinitionSanityTests.java @@ -0,0 +1,62 @@ +package org.alfresco.rest.workflow.processDefinitions; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestProcessDefinitionModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 10/13/2016. + */ +public class GetProcessDefinitionSanityTests extends RestTest +{ + private UserModel testUser; + private RestProcessDefinitionModel randomProcessDefinition, firstRandomProcessDefinition, returnedProcessDefinition; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + testUser = dataUser.createRandomTestUser(); + restClient.authenticateUser(dataUser.getAdminUser()); + randomProcessDefinition = restClient.withWorkflowAPI().getAllProcessDefinitions().getOneRandomEntry().onModel(); + firstRandomProcessDefinition = restClient.withWorkflowAPI().getAllProcessDefinitions().getProcessDefinitionByDeploymentId("1"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION }, + executionType = ExecutionType.SANITY, + description = "Verify Admin user gets a specific process definition for non-network deployments using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION, TestGroup.SANITY }) + public void adminGetsProcessDefinition() throws Exception + { + returnedProcessDefinition = restClient.withWorkflowAPI().usingProcessDefinitions(randomProcessDefinition).getProcessDefinition(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedProcessDefinition.assertThat().field("name").is(randomProcessDefinition.getName()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION }, + executionType = ExecutionType.SANITY, + description = "Verify Any user gets a specific process definition for non-network deployments using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION, TestGroup.SANITY }) + public void anyUserGetsProcessDefinition() throws Exception + { + restClient.authenticateUser(testUser); + returnedProcessDefinition = restClient.withWorkflowAPI().usingProcessDefinitions(firstRandomProcessDefinition).getProcessDefinition(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedProcessDefinition.assertThat() + .field("name").is(firstRandomProcessDefinition.getName()).and() + .field("deploymentId").is(firstRandomProcessDefinition.getDeploymentId()).and() + .field("description").is(firstRandomProcessDefinition.getDescription()).and() + .field("id").is(firstRandomProcessDefinition.getId()).and() + .field("startFormResourceKey").is(firstRandomProcessDefinition.getStartFormResourceKey()).and() + .field("category").is(firstRandomProcessDefinition.getCategory()).and() + .field("title").is(firstRandomProcessDefinition.getTitle()).and() + .field("version").is(firstRandomProcessDefinition.getVersion()).and() + .field("graphicNotationDefined").is(firstRandomProcessDefinition.getGraphicNotationDefined()).and() + .field("key").is(firstRandomProcessDefinition.getKey()); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processDefinitions/GetProcessDefinitionStartFormModelCoreTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processDefinitions/GetProcessDefinitionStartFormModelCoreTests.java new file mode 100644 index 0000000000..6290ad9f62 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processDefinitions/GetProcessDefinitionStartFormModelCoreTests.java @@ -0,0 +1,80 @@ +package org.alfresco.rest.workflow.processDefinitions; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestProcessDefinitionModel; +import org.alfresco.rest.model.RestProcessDefinitionModelsCollection; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 12/6/2016. + */ +public class GetProcessDefinitionStartFormModelCoreTests extends RestTest +{ + private UserModel adminUser; + private RestProcessDefinitionModel randomProcessDefinition; + private RestProcessDefinitionModelsCollection allProcessDefinitions; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + allProcessDefinitions = restClient.authenticateUser(adminUser).withWorkflowAPI().getAllProcessDefinitions(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION }, + executionType = ExecutionType.REGRESSION, + description = "Verify any user gets a model of the start form type definition for non-network deployments using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION, TestGroup.REGRESSION }) + public void nonNetworkUserGetsStartFormModel() throws Exception + { + UserModel nonNetworkUser = dataUser.createRandomTestUser(); + randomProcessDefinition = allProcessDefinitions.getOneRandomEntry().onModel(); + restClient.authenticateUser(nonNetworkUser).withWorkflowAPI() + .usingProcessDefinitions(randomProcessDefinition).getProcessDefinitionStartFormModel() + .assertThat().entriesListIsNotEmpty(); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Bug(id = "ALF-20187") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION }, + executionType = ExecutionType.REGRESSION, + description = "Verify if get request returns status code 404 when invalid processDefinitionId is used") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION, TestGroup.REGRESSION }) + public void getStartFormModelUsingInvalidProcessDefinitionId() throws Exception + { + randomProcessDefinition = allProcessDefinitions.getOneRandomEntry().onModel(); + randomProcessDefinition.setId("invalidID"); + + restClient.authenticateUser(adminUser).withWorkflowAPI() + .usingProcessDefinitions(randomProcessDefinition).getProcessDefinitionStartFormModel(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format("no deployed process definition found with id '%s'", "invalidID")) + .containsErrorKey(RestErrorModel.API_DEFAULT_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Bug(id = "ALF-20187") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION }, + executionType = ExecutionType.REGRESSION, + description = "Verify if get request returns status code 404 when empty processDefinitionId is used") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION, TestGroup.REGRESSION }) + public void getStartFormModelUsingEmptyProcessDefinitionId() throws Exception + { + randomProcessDefinition = allProcessDefinitions.getOneRandomEntry().onModel(); + randomProcessDefinition.setId(""); + + restClient.authenticateUser(adminUser).withWorkflowAPI() + .usingProcessDefinitions(randomProcessDefinition).getProcessDefinitionStartFormModel(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary("no deployed process definition found with id ''"); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processDefinitions/GetProcessDefinitionStartFormModelFullTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processDefinitions/GetProcessDefinitionStartFormModelFullTests.java new file mode 100644 index 0000000000..fa77452a4f --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processDefinitions/GetProcessDefinitionStartFormModelFullTests.java @@ -0,0 +1,71 @@ +package org.alfresco.rest.workflow.processDefinitions; + +import java.util.Arrays; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestFormModelsCollection; +import org.alfresco.rest.model.RestProcessDefinitionModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 1/31/2017. + */ +public class GetProcessDefinitionStartFormModelFullTests extends RestTest +{ + private UserModel adminUser; + private RestProcessDefinitionModel activitiAdhoc; + private RestFormModelsCollection returnedResponse; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + activitiAdhoc = restClient.authenticateUser(adminUser).withWorkflowAPI().getAllProcessDefinitions().getProcessDefinitionByDeploymentId("1"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION }, + executionType = ExecutionType.REGRESSION, + description = "Verify admin gets a model of the start form type definition for specific process definition using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION, TestGroup.REGRESSION }) + public void adminGetsStartFormModelForActivitiAdhocProcessDefinition() throws Exception + { + returnedResponse = restClient.authenticateUser(adminUser).withWorkflowAPI() + .usingProcessDefinitions(activitiAdhoc).getProcessDefinitionStartFormModel(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedResponse.assertThat().entriesListContains("qualifiedName", "{http://www.alfresco.org/model/bpm/1.0}workflowPriority"); + returnedResponse.getStartFormModelByQualifiedName("{http://www.alfresco.org/model/bpm/1.0}workflowPriority") + .assertThat().field("defaultValue").is("2") + .and().field("dataType").is("d:int") + .and().field("name").is("bpm_workflowPriority") + .and().field("title").is("Workflow Priority") + .and().field("required").is("false") + .and().field("allowedValues").is(Arrays.asList("1", "2", "3")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION }, + executionType = ExecutionType.REGRESSION, + description = "Verify admin gets a model of the start form type definition with properties parameter applied using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION, TestGroup.REGRESSION }) + public void adminGetsStartFormModelWithPropertiesParameterApplied() throws Exception + { + returnedResponse = restClient.authenticateUser(adminUser).withParams("properties=qualifiedName,dataType,title").withWorkflowAPI() + .usingProcessDefinitions(activitiAdhoc).getProcessDefinitionStartFormModel(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedResponse.assertThat().entriesListContains("qualifiedName", "{http://www.alfresco.org/model/bpm/1.0}workflowPriority"); + returnedResponse.getStartFormModelByQualifiedName("{http://www.alfresco.org/model/bpm/1.0}workflowPriority") + .assertThat().fieldsCount().is(3) + .and().field("qualifiedName").is("{http://www.alfresco.org/model/bpm/1.0}workflowPriority") + .and().field("defaultValue").isNull() + .and().field("dataType").is("d:int") + .and().field("name").isNull() + .and().field("title").is("Workflow Priority") + .and().field("required").isNull() + .and().field("allowedValues").isNull(); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processDefinitions/GetProcessDefinitionStartFormModelSanityTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processDefinitions/GetProcessDefinitionStartFormModelSanityTests.java new file mode 100644 index 0000000000..7b3d98aefc --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processDefinitions/GetProcessDefinitionStartFormModelSanityTests.java @@ -0,0 +1,38 @@ +package org.alfresco.rest.workflow.processDefinitions; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestProcessDefinitionModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 10/18/2016. + */ +public class GetProcessDefinitionStartFormModelSanityTests extends RestTest +{ + private UserModel adminUserModel; + private RestProcessDefinitionModel randomProcessDefinition; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUserModel = dataUser.getAdminUser(); + restClient.authenticateUser(adminUserModel); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION }, + executionType = ExecutionType.SANITY, + description = "Verify Admin gets a model of the start form type definition for non-network deployments using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION, TestGroup.SANITY }) + public void nonNetworkAdminGetsStartFormModel() throws Exception + { + randomProcessDefinition = restClient.withWorkflowAPI().getAllProcessDefinitions().getOneRandomEntry().onModel(); + restClient.withWorkflowAPI().usingProcessDefinitions(randomProcessDefinition).getProcessDefinitionStartFormModel().assertThat().entriesListIsNotEmpty(); + restClient.assertStatusCodeIs(HttpStatus.OK); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processDefinitions/GetProcessDefinitionsCoreTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processDefinitions/GetProcessDefinitionsCoreTests.java new file mode 100644 index 0000000000..6d4e492ff6 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processDefinitions/GetProcessDefinitionsCoreTests.java @@ -0,0 +1,53 @@ +package org.alfresco.rest.workflow.processDefinitions; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class GetProcessDefinitionsCoreTests extends RestTest +{ + private UserModel userModel; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + userModel = dataUser.createRandomTestUser(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION }, executionType = ExecutionType.REGRESSION, + description = "Verify call to get process definitions with invalid orderBy parameter with REST API and status code is BAD_REQUEST (400)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION, TestGroup.REGRESSION }) + public void userGetProcessDefinitionsWithInvalidOrderBy() throws Exception + { + restClient.authenticateUser(userModel) + .withParams("orderBy=test") + .withWorkflowAPI() + .getAllProcessDefinitions() + .assertThat().entriesListIsEmpty(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.INVALID_ORDERBY, "test", "deploymentId, name, id, category, version, key")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION }, executionType = ExecutionType.REGRESSION, + description = "Verify call to get process definitions with invalid where parameter with REST API and status code is BAD_REQUEST (400)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION, TestGroup.REGRESSION }) + public void userGetProcessDefinitionsWithInvalidWhere() throws Exception + { + restClient.authenticateUser(userModel) + .withParams("where=test") + .withWorkflowAPI() + .getAllProcessDefinitions() + .assertThat().entriesListIsEmpty(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.INVALID_WHERE_QUERY, "test")) + .containsErrorKey(RestErrorModel.INVALID_QUERY_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processDefinitions/GetProcessDefinitionsFullTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processDefinitions/GetProcessDefinitionsFullTests.java new file mode 100644 index 0000000000..6d4f929e75 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processDefinitions/GetProcessDefinitionsFullTests.java @@ -0,0 +1,174 @@ +package org.alfresco.rest.workflow.processDefinitions; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestProcessDefinitionModel; +import org.alfresco.rest.model.RestProcessDefinitionModelsCollection; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 2/1/2017. + */ +public class GetProcessDefinitionsFullTests extends RestTest +{ + private UserModel adminUserModel; + private RestProcessDefinitionModelsCollection processDefinitions; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUserModel = dataUser.getAdminUser(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION }, executionType = ExecutionType.REGRESSION, + description = "Verify admin gets process definitions with valid skipCount parameter applied using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION, TestGroup.REGRESSION }) + public void getProcessDefinitionsWithValidSkipCount() throws Exception + { + processDefinitions = restClient.authenticateUser(adminUserModel) + .withWorkflowAPI().getAllProcessDefinitions(); + restClient.assertStatusCodeIs(HttpStatus.OK); + RestProcessDefinitionModel firstProcessDefinition = processDefinitions.getEntries().get(0).onModel(); + RestProcessDefinitionModel secondProcessDefinition = processDefinitions.getEntries().get(1).onModel(); + + RestProcessDefinitionModelsCollection procDefWithSkipCount = restClient.withParams("skipCount=2").withWorkflowAPI().getAllProcessDefinitions(); + restClient.assertStatusCodeIs(HttpStatus.OK); + procDefWithSkipCount + .assertThat().entriesListDoesNotContain("name", firstProcessDefinition.getName()) + .assertThat().entriesListDoesNotContain("name", secondProcessDefinition.getName()) + .assertThat().entriesListCountIs(processDefinitions.getEntries().size()-2); + procDefWithSkipCount.assertThat().paginationField("skipCount").is("2"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION }, executionType = ExecutionType.REGRESSION, + description = "Verify admin doesn't get process definitions with negative skipCount parameter applied using REST API") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION, TestGroup.REGRESSION }) + public void getProcessDefinitionsWithNegativeSkipCount() throws Exception + { + restClient.authenticateUser(adminUserModel).withParams("skipCount=-1").withWorkflowAPI().getAllProcessDefinitions(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(RestErrorModel.NEGATIVE_VALUES_SKIPCOUNT) + .containsErrorKey(RestErrorModel.NEGATIVE_VALUES_SKIPCOUNT) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE) + .statusCodeIs(HttpStatus.BAD_REQUEST); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION }, executionType = ExecutionType.REGRESSION, + description = "Verify admin doesn't get process definitions with non numeric skipCount parameter applied using REST API") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION, TestGroup.REGRESSION }) + public void getProcessDefinitionsWithNonNumericSkipCount() throws Exception + { + restClient.authenticateUser(adminUserModel).withParams("skipCount=A").withWorkflowAPI().getAllProcessDefinitions(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(String.format(RestErrorModel.INVALID_SKIPCOUNT, "A")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION }, executionType = ExecutionType.REGRESSION, + description = "Verify admin gets process definitions with valid maxItems parameter applied using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION, TestGroup.REGRESSION }) + public void getProcessDefinitionsWithValidMaxItems() throws Exception + { + processDefinitions = restClient.authenticateUser(adminUserModel) + .withWorkflowAPI().getAllProcessDefinitions(); + restClient.assertStatusCodeIs(HttpStatus.OK); + RestProcessDefinitionModel firstProcessDefinition = processDefinitions.getEntries().get(0).onModel(); + RestProcessDefinitionModel secondProcessDefinition = processDefinitions.getEntries().get(1).onModel(); + + RestProcessDefinitionModelsCollection procDefWithMaxItems = restClient.withParams("maxItems=2").withWorkflowAPI().getAllProcessDefinitions(); + restClient.assertStatusCodeIs(HttpStatus.OK); + procDefWithMaxItems + .assertThat().entriesListContains("name", firstProcessDefinition.getName()) + .assertThat().entriesListContains("name", secondProcessDefinition.getName()) + .assertThat().entriesListCountIs(2); + procDefWithMaxItems.assertThat().paginationField("maxItems").is("2"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION }, executionType = ExecutionType.REGRESSION, + description = "Verify admin doesn't get process definitions with negative maxItems parameter applied using REST API") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION, TestGroup.REGRESSION }) + public void getProcessDefinitionsWithNegativeMaxItems() throws Exception + { + restClient.authenticateUser(adminUserModel).withParams("maxItems=-1").withWorkflowAPI().getAllProcessDefinitions(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS) + .containsErrorKey(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE) + .statusCodeIs(HttpStatus.BAD_REQUEST); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION }, executionType = ExecutionType.REGRESSION, + description = "Verify admin doesn't get process definitions with non numeric maxItems parameter applied using REST API") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION, TestGroup.REGRESSION }) + public void getProcessDefinitionsWithNonNumericMaxItems() throws Exception + { + restClient.authenticateUser(adminUserModel).withParams("maxItems=A").withWorkflowAPI().getAllProcessDefinitions(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(String.format(RestErrorModel.INVALID_MAXITEMS, "A")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION }, executionType = ExecutionType.REGRESSION, + description = "Verify Admin user gets process definitions with properties parameter applied using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION, TestGroup.REGRESSION }) + public void getProcessDefinitionsWithValidProperties() throws Exception + { + processDefinitions =restClient.authenticateUser(adminUserModel).withParams("properties=name,graphicNotationDefined,version").withWorkflowAPI().getAllProcessDefinitions(); + restClient.assertStatusCodeIs(HttpStatus.OK); + processDefinitions.assertThat().entriesListIsNotEmpty(); + processDefinitions.getOneRandomEntry().onModel().assertThat() + .fieldsCount().is(3).and() + .field("deploymentId").isNull().and() + .field("description").isNull().and() + .field("id").isNull().and() + .field("startFormResourceKey").isNull().and() + .field("category").isNull().and() + .field("title").isNull().and() + .field("version").isNotEmpty().and() + .field("graphicNotationDefined").isNotEmpty().and() + .field("key").isNull().and() + .field("name").isNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION }, executionType = ExecutionType.REGRESSION, + description = "Verify admin gets process definitions ordered by name ascendant using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION, TestGroup.REGRESSION }) + public void getProcessDefinitionsOrderedByNameAsc() throws Exception + { + processDefinitions = restClient.authenticateUser(adminUserModel) + .withParams("orderBy=name ASC").withWorkflowAPI().getAllProcessDefinitions(); + restClient.assertStatusCodeIs(HttpStatus.OK); + processDefinitions.assertThat().entriesListIsSortedAscBy("name"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION }, executionType = ExecutionType.REGRESSION, + description = "Verify admin doesn't get process definitions when many fields are used for orderBy parameter") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION, TestGroup.REGRESSION }) + public void getProcessDefinitionsOrderedByManyFields() throws Exception + { + restClient.authenticateUser(adminUserModel) + .withParams("orderBy=name,id").withWorkflowAPI().getAllProcessDefinitions(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(RestErrorModel.ONLY_ONE_ORDERBY); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION }, executionType = ExecutionType.REGRESSION, + description = "Verify admin gets process definitions when where parameter is applied") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION, TestGroup.REGRESSION }) + public void getProcessDefinitionsFilteredByKey() throws Exception + { + processDefinitions = restClient.authenticateUser(adminUserModel) + .withParams("where=(key matches('activitiParallel%'))").withWorkflowAPI().getAllProcessDefinitions(); + restClient.assertStatusCodeIs(HttpStatus.OK); + processDefinitions.assertThat().entriesListCountIs(2) + .assertThat().entriesListContains("key", "activitiParallelReview") + .assertThat().entriesListContains("key", "activitiParallelGroupReview"); + } + +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processDefinitions/GetProcessDefinitionsSanityTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processDefinitions/GetProcessDefinitionsSanityTests.java new file mode 100644 index 0000000000..f0a330d7c2 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processDefinitions/GetProcessDefinitionsSanityTests.java @@ -0,0 +1,48 @@ +package org.alfresco.rest.workflow.processDefinitions; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestProcessDefinitionModelsCollection; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 10/13/2016. + */ +public class GetProcessDefinitionsSanityTests extends RestTest +{ + private UserModel adminUserModel; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUserModel = dataUser.getAdminUser(); + restClient.authenticateUser(adminUserModel); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION }, + executionType = ExecutionType.SANITY, description = "Verify Admin user gets process definitions for non-network deployments using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESS_DEFINITION, TestGroup.SANITY }) + public void nonNetworkAdminGetsProcessDefinitions() throws Exception + { + RestProcessDefinitionModelsCollection processDefinitions = restClient.authenticateUser(adminUserModel) + .withWorkflowAPI() + .getAllProcessDefinitions(); + restClient.assertStatusCodeIs(HttpStatus.OK); + processDefinitions.assertThat().entriesListIsNotEmpty(); + processDefinitions.getProcessDefinitionByDeploymentId("1").assertThat() + .field("name").is("Adhoc Activiti Process").and() + .field("description").is("Assign a new task to yourself or a colleague").and() + .field("id").is("activitiAdhoc:1:4").and() + .field("startFormResourceKey").is("wf:submitAdhocTask").and() + .field("category").is("http://alfresco.org").and() + .field("title").is("New Task").and() + .field("version").is("1").and() + .field("graphicNotationDefined").is("true").and() + .field("key").is("activitiAdhoc"); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/AddProcessCoreTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/AddProcessCoreTests.java new file mode 100644 index 0000000000..8a2eac4461 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/AddProcessCoreTests.java @@ -0,0 +1,130 @@ +package org.alfresco.rest.workflow.processes; + +import org.alfresco.dataprep.CMISUtil.Priority; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.exception.JsonToModelConversionException; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestProcessDefinitionModel; +import org.alfresco.rest.model.RestProcessDefinitionModelsCollection; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.rest.model.RestProcessModelsCollection; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.testng.annotations.Test; + +/** + * + * @author Cristina Axinte + * + */ +public class AddProcessCoreTests extends RestTest +{ + private UserModel assignee, adminUser; + private RestProcessModel addedProcess; + private RestProcessModelsCollection processes; + private RestProcessDefinitionModel processDefinition; + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, + executionType = ExecutionType.REGRESSION, description = "Verify non network admin is able to start new process using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void nonNetworkAdminUserStartsNewProcess() throws JsonToModelConversionException, Exception + { + adminUser = dataUser.getAdminUser(); + assignee = dataUser.createRandomTestUser(); + + addedProcess = restClient.authenticateUser(adminUser).withWorkflowAPI().addProcess("activitiAdhoc", assignee, false, Priority.Normal); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + addedProcess.assertThat().field("id").is(addedProcess.getId()) + .and().field("startUserId").is(adminUser.getUsername()); + + processDefinition = restClient.authenticateUser(adminUser).withWorkflowAPI().getAllProcessDefinitions().getProcessDefinitionByKey("activitiAdhoc"); + processes = restClient.withWorkflowAPI().getProcesses(); + restClient.assertStatusCodeIs(HttpStatus.OK); + processes.assertThat().entriesListContains("id", addedProcess.getId()) + .assertThat().entriesListContains("processDefinitionId", processDefinition.getId()) + .assertThat().entriesListContains("startUserId", adminUser.getUsername()) + .assertThat().entriesListContains("startActivityId", "start") + .assertThat().entriesListContains("completed", "false") + .assertThat().entriesListContains("processDefinitionKey", "activitiAdhoc"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, + executionType = ExecutionType.REGRESSION, description = "Verify start new process with empty request body using REST API returns status code is Bad Request (400)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void startNewProcessWithEmptyProcessBody() throws JsonToModelConversionException, Exception + { + adminUser = dataUser.getAdminUser(); + assignee = dataUser.createRandomTestUser(); + + restClient.authenticateUser(adminUser).withWorkflowAPI(); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, "", "processes"); + restClient.processModel(RestProcessModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST); + } + + @Bug(id = "REPO-1936") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, + executionType = ExecutionType.REGRESSION, description = "Verify start new process with invalid request body using REST API returns status code is Bad Request (400)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void startNewProcessWithInvalidProcessDefInProcessBody() throws JsonToModelConversionException, Exception + { + adminUser = dataUser.getAdminUser(); + assignee = dataUser.createRandomTestUser(); + + restClient.authenticateUser(adminUser).withWorkflowAPI(); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, "{\"processDefinitionKey\":\"activitiAdhoc\"}", "processes"); + restClient.processModel(RestProcessModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, + executionType = ExecutionType.REGRESSION, description = "Verify start new process with invalid request body using REST API returns status code is Bad Request (400)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void startNewProcessWithInvalidVariablesInProcessBody1() throws JsonToModelConversionException, Exception + { + adminUser = dataUser.getAdminUser(); + assignee = dataUser.createRandomTestUser(); + + restClient.authenticateUser(adminUser).withWorkflowAPI(); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, "{\"variables\":{\"bpm_sendEMailNotifications\":false}}", "processes"); + restClient.processModel(RestProcessModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary("Either processDefinitionId or processDefinitionKey is required"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, + executionType = ExecutionType.REGRESSION, description = "Verify start new process with invalid request body using REST API returns status code is Bad Request (400)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void startNewProcessWithInvalidVariablesInProcessBody2() throws JsonToModelConversionException, Exception + { + adminUser = dataUser.getAdminUser(); + assignee = dataUser.createRandomTestUser(); + + restClient.authenticateUser(adminUser).withWorkflowAPI(); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, "{\"variables\":{\"bpm_assignee\":\"admin\"}}", "processes"); + restClient.processModel(RestProcessModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary("Either processDefinitionId or processDefinitionKey is required"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, + executionType = ExecutionType.REGRESSION, description = "Verify start new process with invalid request body using REST API returns status code is Bad Request (400)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void startNewProcessWithInvalidVariablesInProcessBody3() throws JsonToModelConversionException, Exception + { + adminUser = dataUser.getAdminUser(); + assignee = dataUser.createRandomTestUser(); + + restClient.authenticateUser(adminUser).withWorkflowAPI(); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, "{\"variables\":{\"bpm_workflowPriority\":2}}", "processes"); + restClient.processModel(RestProcessModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary("Either processDefinitionId or processDefinitionKey is required"); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/AddProcessFullTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/AddProcessFullTests.java new file mode 100644 index 0000000000..c1eb6b24a0 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/AddProcessFullTests.java @@ -0,0 +1,150 @@ +package org.alfresco.rest.workflow.processes; + +import javax.json.JsonObject; + +import org.alfresco.dataprep.CMISUtil.Priority; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.JsonBodyGenerator; +import org.alfresco.rest.exception.JsonToModelConversionException; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * + * @author Cristina Axinte + * + */ +public class AddProcessFullTests extends RestTest +{ + private UserModel userWhoStartsProcess, assignee; + RestProcessModel addedProcess; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + assignee = dataUser.createRandomTestUser(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify user cannot start new process with invalid processDefinitionKey using REST API and status code is 400") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void userStartsNewProcessWithInvalidProcessDefinitionKey() throws JsonToModelConversionException, Exception + { + userWhoStartsProcess = dataUser.createRandomTestUser(); + + addedProcess = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().addProcess("activitiAdhocc", assignee, false, Priority.Normal); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsErrorKey(String.format(RestErrorModel.NO_WORKFLOW_DEFINITION_FOUND, "activitiAdhocc")) + .containsSummary(String.format(RestErrorModel.NO_WORKFLOW_DEFINITION_FOUND, "activitiAdhocc")) + .stackTraceIs(RestErrorModel.STACKTRACE) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + } + + @Bug(id = "REPO-1970") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify user cannot start new process with invalid processDefinitionKey using REST API and status code is 400") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void userStartsNewProcessWithEmptyVariablesBody() throws JsonToModelConversionException, Exception + { + userWhoStartsProcess = dataUser.createRandomTestUser(); + + JsonObject postJson = JsonBodyGenerator.defineJSON() + .add("processDefinitionKey", "activitiAdhoc") + .add("variables", + JsonBodyGenerator.defineJSON().build() + ).build(); + addedProcess = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().addProcessWithBody(postJson); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsErrorKey(String.format(RestErrorModel.NO_WORKFLOW_DEFINITION_FOUND, "activitiAdhoc")); + } + + @Bug(id = "REPO-1970") + @TestRail(section = { TestGroup.REST_API,TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify user cannot start new process with invalid processDefinitionKey using REST API and status code is 400") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void userStartsNewProcessWithNoAssigneeInVariablesBody() throws JsonToModelConversionException, Exception + { + userWhoStartsProcess = dataUser.createRandomTestUser(); + + JsonObject postJson = JsonBodyGenerator.defineJSON() + .add("processDefinitionKey", "activitiAdhoc") + .add("variables", + JsonBodyGenerator.defineJSON() + .add("bpm_sendEMailNotifications", false) + .add("bpm_workflowPriority", Priority.Low.getLevel()).build() + ).build(); + addedProcess = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().addProcessWithBody(postJson); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsErrorKey(String.format(RestErrorModel.NO_WORKFLOW_DEFINITION_FOUND, "activitiAdhoc")); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify user cannot start new process with invalid assignee using REST API and status code is 400") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void userStartsNewProcessWithInvalidAssignee() throws JsonToModelConversionException, Exception + { + userWhoStartsProcess = dataUser.createRandomTestUser(); + UserModel invalidAssignee = new UserModel("invalidAssignee", "password"); + + addedProcess = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().addProcess("activitiAdhoc", invalidAssignee, false, Priority.Normal); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsErrorKey(String.format(RestErrorModel.INVALID_USER_ID, invalidAssignee.getUsername())) + .containsSummary(String.format(RestErrorModel.INVALID_USER_ID, invalidAssignee.getUsername())) + .stackTraceIs(RestErrorModel.STACKTRACE) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + } + + @Bug(id = "REPO-1970") + @TestRail(section = { TestGroup.REST_API,TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify user cannot start new process with invalid sendEMailNotifications value using REST API and status code is 400") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void userStartsNewProcessWithInvalidEmailNotification() throws JsonToModelConversionException, Exception + { + userWhoStartsProcess = dataUser.createRandomTestUser(); + JsonObject postJson = JsonBodyGenerator.defineJSON() + .add("processDefinitionKey", "activitiAdhoc") + .add("variables", + JsonBodyGenerator.defineJSON() + .add("bpm_assignee", assignee.getUsername()) + .add("bpm_sendEMailNotifications", "111") + .add("bpm_workflowPriority", Priority.Low.getLevel()).build() + ).build(); + + addedProcess = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().addProcessWithBody(postJson); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsErrorKey(String.format(RestErrorModel.UNSUPPORTED_TYPE, "111")) + .stackTraceIs(RestErrorModel.STACKTRACE) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + } + + @Bug(id = "REPO-1970") + @TestRail(section = { TestGroup.REST_API,TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify user cannot start new process with invalid priority using REST API and status code is 400") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void userStartsNewProcessWithInvalidPriority() throws JsonToModelConversionException, Exception + { + userWhoStartsProcess = dataUser.createRandomTestUser(); + JsonObject postJson = JsonBodyGenerator.defineJSON() + .add("processDefinitionKey", "activitiAdhoc") + .add("variables", + JsonBodyGenerator.defineJSON() + .add("bpm_assignee", assignee.getUsername()) + .add("bpm_sendEMailNotifications", false) + .add("bpm_workflowPriority", "test").build() + ).build(); + + addedProcess = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().addProcessWithBody(postJson); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsErrorKey(String.format(RestErrorModel.UNSUPPORTED_TYPE, "test")) + .stackTraceIs(RestErrorModel.STACKTRACE) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/AddProcessSanityTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/AddProcessSanityTests.java new file mode 100644 index 0000000000..e43e592031 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/AddProcessSanityTests.java @@ -0,0 +1,44 @@ +package org.alfresco.rest.workflow.processes; + +import org.alfresco.dataprep.CMISUtil.Priority; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.exception.JsonToModelConversionException; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.rest.model.RestProcessModelsCollection; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 10/18/2016. + */ +public class AddProcessSanityTests extends RestTest +{ + private UserModel userWhoStartsProcess, assignee; + private RestProcessModel addedProcess; + private RestProcessModelsCollection processes; + + @TestRail(section = { TestGroup.REST_API,TestGroup.WORKFLOW, + TestGroup.PROCESSES }, executionType = ExecutionType.SANITY, + description = "Verify non network user is able to start new process using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.SANITY }) + public void nonNetworkUserStartsNewProcess() throws JsonToModelConversionException, Exception + { + userWhoStartsProcess = dataUser.createRandomTestUser(); + assignee = dataUser.createRandomTestUser(); + + addedProcess = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().addProcess("activitiAdhoc", assignee, false, Priority.Normal); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + addedProcess.assertThat().field("id").is(addedProcess.getId()) + .and().field("startUserId").is(addedProcess.getStartUserId()); + + processes = restClient.withWorkflowAPI().getProcesses(); + restClient.assertStatusCodeIs(HttpStatus.OK); + processes.assertThat().entriesListContains("id", addedProcess.getId()); + + } + +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/DeleteProcessCoreTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/DeleteProcessCoreTests.java new file mode 100644 index 0000000000..26253d2b15 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/DeleteProcessCoreTests.java @@ -0,0 +1,69 @@ +package org.alfresco.rest.workflow.processes; + +import org.alfresco.dataprep.CMISUtil.Priority; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class DeleteProcessCoreTests extends RestTest +{ + private UserModel userWhoAddsProcess, assignee; + private RestProcessModel process; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + userWhoAddsProcess = dataUser.createRandomTestUser(); + assignee = dataUser.createRandomTestUser(); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.WORKFLOW, + TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify admin user is able to delete a process started by another user.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void deleteProcessByAdminUser() throws Exception + { + process = restClient.authenticateUser(userWhoAddsProcess).withWorkflowAPI().addProcess("activitiAdhoc", assignee, false, Priority.Normal); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.authenticateUser(dataUser.getAdminUser()) + .withWorkflowAPI().usingProcess(process).deleteProcess(); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withWorkflowAPI().getProcesses() + .assertThat().entriesListDoesNotContain("id", process.getId()); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.WORKFLOW, + TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify User is not able to delete process with invalid id") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void deleteProcessWithInvalidId() throws Exception + { + process = restClient.authenticateUser(userWhoAddsProcess).withWorkflowAPI().addProcess("activitiAdhoc", assignee, false, Priority.Normal); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + process.setId("00001"); + restClient.withWorkflowAPI().usingProcess(process).deleteProcess(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "00001")); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.WORKFLOW, + TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify User is not able to delete process with empty id") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void deleteProcessWithEmptyId() throws Exception + { + process = restClient.authenticateUser(userWhoAddsProcess).withWorkflowAPI().addProcess("activitiAdhoc", assignee, false, Priority.Normal); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + process.setId(""); + restClient.withWorkflowAPI().usingProcess(process).deleteProcess(); + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED) + .assertLastError().containsSummary(RestErrorModel.DELETE_EMPTY_ARGUMENT); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/DeleteProcessFullTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/DeleteProcessFullTests.java new file mode 100644 index 0000000000..e1c295f72c --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/DeleteProcessFullTests.java @@ -0,0 +1,52 @@ +package org.alfresco.rest.workflow.processes; + +import org.alfresco.dataprep.CMISUtil.Priority; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * + * @author Cristina Axinte + * + */ +public class DeleteProcessFullTests extends RestTest +{ + private UserModel userWhoAddsProcess, assignee; + private RestProcessModel process; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + userWhoAddsProcess = dataUser.createRandomTestUser(); + assignee = dataUser.createRandomTestUser(); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify user is NOT able to delete process started by him twice using REST API and status code is NOT FOUND (404)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void deleteProcessByUserWhoStartedProcessTwice() throws Exception + { + process = restClient.authenticateUser(userWhoAddsProcess).withWorkflowAPI().addProcess("activitiAdhoc", assignee, false, Priority.Normal); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.withWorkflowAPI().usingProcess(process).deleteProcess(); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + restClient.withWorkflowAPI().usingProcess(process).deleteProcess(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .containsSummary(String.format(RestErrorModel.ENTITY_WAS_NOT_FOUND, process.getId())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + + restClient.withWorkflowAPI().getProcesses().assertThat().entriesListDoesNotContain("id", process.getId()); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/DeleteProcessSanityTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/DeleteProcessSanityTests.java new file mode 100644 index 0000000000..9478b9d0e2 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/DeleteProcessSanityTests.java @@ -0,0 +1,69 @@ +package org.alfresco.rest.workflow.processes; + +import org.alfresco.dataprep.CMISUtil.Priority; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 10/12/2016. + */ +public class DeleteProcessSanityTests extends RestTest +{ + private UserModel userWhoAddsProcess, assignee, anotherUser; + private RestProcessModel process; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + userWhoAddsProcess = dataUser.createRandomTestUser(); + assignee = dataUser.createRandomTestUser(); + anotherUser = dataUser.createRandomTestUser(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.SANITY, + description = "Verify User is able to delete process started by him using REST API and status code is OK (204)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.SANITY }) + public void deleteProcessByUserWhoStartedProcess() throws Exception + { + process = restClient.authenticateUser(userWhoAddsProcess).withWorkflowAPI().addProcess("activitiAdhoc", assignee, false, Priority.Normal); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.withWorkflowAPI().usingProcess(process).deleteProcess(); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + restClient.withWorkflowAPI().getProcesses().assertThat().entriesListDoesNotContain("id", process.getId()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.SANITY, + description = "Verify User is able to delete process assigned to him using REST API and status code is OK (204)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.SANITY }) + public void deleteProcessByAssignedUser() throws Exception + { + process = restClient.authenticateUser(userWhoAddsProcess).withWorkflowAPI().addProcess("activitiAdhoc", assignee, false, Priority.Normal); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.authenticateUser(assignee).withWorkflowAPI().usingProcess(process).deleteProcess(); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + restClient.withWorkflowAPI().getProcesses().assertThat().entriesListDoesNotContain("id", process.getId()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.SANITY, + description = "Verify User that is not involved in a process is not authorized to delete it using REST API and status code is 403") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.SANITY }) + public void deleteProcessByAnotherUser() throws Exception + { + process = restClient.authenticateUser(userWhoAddsProcess).withWorkflowAPI().addProcess("activitiAdhoc", assignee, false, Priority.Normal); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.authenticateUser(anotherUser).withWorkflowAPI().usingProcess(process).deleteProcess(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary("user is not allowed to access information about process"); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/GetProcessCoreTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/GetProcessCoreTests.java new file mode 100644 index 0000000000..418e4b8a07 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/GetProcessCoreTests.java @@ -0,0 +1,44 @@ +package org.alfresco.rest.workflow.processes; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.commons.lang3.RandomStringUtils; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class GetProcessCoreTests extends RestTest +{ + private UserModel userWhoStartsProcess, assignee; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + userWhoStartsProcess = dataUser.createRandomTestUser(); + assignee = dataUser.createRandomTestUser(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify that using invalid process ID returns status code 404") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION}) + public void invalidProcessIdTest() throws Exception + { + RestProcessModel newProcess = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().addProcess("activitiAdhoc", assignee, false, CMISUtil.Priority.High); + String processId = RandomStringUtils.randomAlphanumeric(10); + newProcess.setId(processId); + restClient.authenticateUser(dataUser.getAdminUser()) + .withWorkflowAPI().usingProcess(newProcess).getProcess(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, processId)) + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } +} \ No newline at end of file diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/GetProcessFullTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/GetProcessFullTests.java new file mode 100644 index 0000000000..01c11e8a25 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/GetProcessFullTests.java @@ -0,0 +1,85 @@ +package org.alfresco.rest.workflow.processes; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestProcessDefinitionModel; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * + * @author Cristina Axinte + * + */ +public class GetProcessFullTests extends RestTest +{ + private UserModel userWhoStartsProcess, assignee; + private RestProcessModel addedProcess, process; + private RestProcessDefinitionModel adhocProcessDefinition; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + userWhoStartsProcess = dataUser.createRandomTestUser(); + assignee = dataUser.createRandomTestUser(); + addedProcess = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().addProcess("activitiAdhoc", assignee, false, CMISUtil.Priority.High); + adhocProcessDefinition = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().getAllProcessDefinitions().getProcessDefinitionByKey("activitiAdhoc"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify user is able to get the process with properties parameter applied using REST API") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void getProcessWithPropertiesParameter() throws Exception + { + process = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().usingParams("properties=startUserId,id").usingProcess(addedProcess).getProcess(); + restClient.assertStatusCodeIs(HttpStatus.OK); + process.assertThat().fieldsCount().is(2) + .and().field("startUserId").is(addedProcess.getStartUserId()) + .and().field("id").is(addedProcess.getId()) + .and().field("processDefinitionKey").isNull(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify user is able to get a process that was deleted, but it has 'deleted through REST API call' deleteReason") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void getDeletedProcess() throws Exception + { + addedProcess = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().addProcess("activitiAdhoc", assignee, false, CMISUtil.Priority.High); + + process = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().usingProcess(addedProcess).getProcess(); + restClient.assertStatusCodeIs(HttpStatus.OK); + process.assertThat() + .field("processDefinitionId").is(adhocProcessDefinition.getId()) + .and().field("startUserId").is(addedProcess.getStartUserId()) + .and().field("startActivityId").is("start") + .and().field("startedAt").isNotEmpty() + .and().field("id").is(addedProcess.getId()) + .and().field("completed").is(false) + .and().field("processDefinitionKey").is("activitiAdhoc"); + + restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().usingProcess(addedProcess).deleteProcess(); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + process = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().usingProcess(addedProcess).getProcess(); + restClient.assertStatusCodeIs(HttpStatus.OK); + process.assertThat() + .field("processDefinitionId").is(adhocProcessDefinition.getId()) + .and().field("durationInMs").isNotNull() + .and().field("startUserId").is(addedProcess.getStartUserId()) + .and().field("startActivityId").is("start") + .and().field("endedAt").isNotEmpty() + .and().field("startedAt").isNotEmpty() + .and().field("id").is(addedProcess.getId()) + .and().field("completed").is(true) + .and().field("deleteReason").is("deleted through REST API call") + .and().field("processDefinitionKey").is("activitiAdhoc"); + + restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().getProcesses().assertThat().entriesListDoesNotContain("id", process.getId()); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/GetProcessSanityTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/GetProcessSanityTests.java new file mode 100644 index 0000000000..b4288002ad --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/GetProcessSanityTests.java @@ -0,0 +1,62 @@ +package org.alfresco.rest.workflow.processes; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 10/19/2016. + */ +public class GetProcessSanityTests extends RestTest +{ + private UserModel userWhoStartsProcess, assignee; + private RestProcessModel addedProcess, process; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + userWhoStartsProcess = dataUser.createRandomTestUser(); + assignee = dataUser.createRandomTestUser(); + addedProcess = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().addProcess("activitiAdhoc", assignee, false, CMISUtil.Priority.High); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PROCESSES }, executionType = ExecutionType.SANITY, + description = "Verify user is able to get the process started by him using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.SANITY }) + public void getProcessByOwner() throws Exception + { + process = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().usingProcess(addedProcess).getProcess(); + restClient.assertStatusCodeIs(HttpStatus.OK); + process.assertThat().field("id").is(addedProcess.getId()) + .and().field("startUserId").is(addedProcess.getStartUserId()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PROCESSES }, executionType = ExecutionType.SANITY, + description = "Verify user is able to get the process assigned to him using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.SANITY }) + public void getProcessByAssignee() throws Exception + { + process = restClient.authenticateUser(assignee).withWorkflowAPI().usingProcess(addedProcess).getProcess(); + restClient.assertStatusCodeIs(HttpStatus.OK); + process.assertThat().field("id").is(addedProcess.getId()) + .and().field("startUserId").is(addedProcess.getStartUserId()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PROCESSES }, executionType = ExecutionType.SANITY, + description = "Verify admin is able to get any process using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.SANITY }) + public void getProcessByAdmin() throws Exception + { + process = restClient.authenticateUser(dataUser.getAdminUser()).withWorkflowAPI().usingProcess(addedProcess).getProcess(); + restClient.assertStatusCodeIs(HttpStatus.OK); + process.assertThat().field("id").is(addedProcess.getId()) + .and().field("startUserId").is(addedProcess.getStartUserId()); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/GetProcessesCoreTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/GetProcessesCoreTests.java new file mode 100644 index 0000000000..f4c066374d --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/GetProcessesCoreTests.java @@ -0,0 +1,75 @@ +package org.alfresco.rest.workflow.processes; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.exception.JsonToModelConversionException; +import org.alfresco.rest.model.RestProcessDefinitionModel; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.rest.model.RestProcessModelsCollection; +import org.alfresco.utility.model.*; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.util.List; + +/** + * + * @author Cristina Axinte + * + */ +public class GetProcessesCoreTests extends RestTest +{ + private FileModel document; + private SiteModel siteModel; + private UserModel adminUser, userWhoStartsTask, assignee ; + private TaskModel task1, task2; + private ProcessModel process3; + private RestProcessDefinitionModel adhocProcessDefinition; + private RestProcessDefinitionModel activitiReviewProcessDefinition; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + userWhoStartsTask = dataUser.createRandomTestUser(); + assignee = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userWhoStartsTask).createPublicRandomSite(); + document = dataContent.usingUser(userWhoStartsTask).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + task1 = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(document).createNewTaskAndAssignTo(assignee); + task2 = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(document).createNewTaskAndAssignTo(adminUser); + process3 = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(document).createSingleReviewerTaskAndAssignTo(assignee); + adhocProcessDefinition = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI().getAllProcessDefinitions().getProcessDefinitionByKey("activitiAdhoc"); + activitiReviewProcessDefinition = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI().getAllProcessDefinitions().getProcessDefinitionByKey("activitiReview"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify user gets all processes started by him ordered descending by id") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void getProcessesOrderedByIdDESC() throws Exception + { + RestProcessModelsCollection processes = restClient.authenticateUser(userWhoStartsTask).withParams("orderBy=id DESC") + .withWorkflowAPI().getProcesses(); + restClient.assertStatusCodeIs(HttpStatus.OK); + processes.assertThat().entriesListIsNotEmpty(); + List processesList = processes.getEntries(); + processesList.get(0).onModel().assertThat().field("id").is(process3.getId()); + processesList.get(1).onModel().assertThat().field("id").is(task2.getProcessId()); + processesList.get(2).onModel().assertThat().field("id").is(task1.getProcessId()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify user gets processes that matches a where clause") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void getProcessesWithWhereClauseAsParameter() throws JsonToModelConversionException, Exception + { + RestProcessModelsCollection processes = restClient.authenticateUser(userWhoStartsTask).where("processDefinitionKey='activitiReview'") + .withWorkflowAPI().getProcesses(); + restClient.assertStatusCodeIs(HttpStatus.OK); + + processes.assertThat().entriesListIsNotEmpty().and().entriesListContains("processDefinitionId", activitiReviewProcessDefinition.getId()) + .and().entriesListDoesNotContain("processDefinitionId", adhocProcessDefinition.getId()); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/GetProcessesFullTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/GetProcessesFullTests.java new file mode 100644 index 0000000000..0c533fc981 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/GetProcessesFullTests.java @@ -0,0 +1,155 @@ +package org.alfresco.rest.workflow.processes; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.rest.model.RestProcessModelsCollection; +import org.alfresco.utility.model.*; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.util.List; + +/** + * + * @author Cristina Axinte + * + */ +public class GetProcessesFullTests extends RestTest +{ + private FileModel document; + private SiteModel siteModel; + private UserModel adminUser, userWhoStartsTask, assignee; + private TaskModel task1, task2; + private ProcessModel process3; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + userWhoStartsTask = dataUser.createRandomTestUser(); + assignee = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userWhoStartsTask).createPublicRandomSite(); + document = dataContent.usingUser(userWhoStartsTask).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + task1 = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(document).createNewTaskAndAssignTo(assignee); + task2 = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(document).createNewTaskAndAssignTo(adminUser); + process3 = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(document).createSingleReviewerTaskAndAssignTo(assignee); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify user gets processes when skipCount parameter is applied") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void getProcessesWithSkipCountParameter() throws Exception + { + RestProcessModelsCollection processes = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI().getProcesses(); + restClient.assertStatusCodeIs(HttpStatus.OK); + processes.assertThat().paginationField("count").is("3"); + RestProcessModel process1 = processes.getEntries().get(0).onModel(); + RestProcessModel process2 = processes.getEntries().get(1).onModel(); + RestProcessModel process3 = processes.getEntries().get(2).onModel(); + + processes = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI().usingParams("skipCount=2").getProcesses(); + restClient.assertStatusCodeIs(HttpStatus.OK); + processes.assertThat().paginationField("count").is("1"); + processes.assertThat().paginationField("skipCount").is("2"); + processes.assertThat().entriesListDoesNotContain("id", process1.getId()); + processes.assertThat().entriesListDoesNotContain("id", process2.getId()); + processes.getEntries().get(0).onModel().assertThat().field("id").is(process3.getId()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify user gets processes when maxItems parameter is applied") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void getProcessesWithMaxItemsParameter() throws Exception + { + RestProcessModelsCollection processes = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI().getProcesses(); + restClient.assertStatusCodeIs(HttpStatus.OK); + processes.assertThat().paginationField("count").is("3"); + RestProcessModel process1 = processes.getEntries().get(0).onModel(); + RestProcessModel process2 = processes.getEntries().get(1).onModel(); + RestProcessModel process3 = processes.getEntries().get(2).onModel(); + + processes = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI().usingParams("maxItems=2").getProcesses(); + restClient.assertStatusCodeIs(HttpStatus.OK); + processes.assertThat().paginationField("count").is("2"); + processes.assertThat().paginationField("maxItems").is("2"); + processes.assertThat().entriesListDoesNotContain("id", process3.getId()); + processes.getEntries().get(0).onModel().assertThat().field("id").is(process1.getId()); + processes.getEntries().get(1).onModel().assertThat().field("id").is(process2.getId()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify user gets processes when properties parameter is applied") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void getProcessesWithPropertiesParameter() throws Exception + { + RestProcessModelsCollection processes = restClient.authenticateUser(userWhoStartsTask).withParams("properties=id") + .withWorkflowAPI().getProcesses(); + restClient.assertStatusCodeIs(HttpStatus.OK); + List processesList = processes.getEntries(); + processesList.get(0).onModel().assertThat().fieldsCount().is(1) + .and().field("id").isNotEmpty() + .and().field("processDefinitionId").isNull() + .and().field("startUserId").isNull(); + processesList.get(1).onModel().assertThat().fieldsCount().is(1) + .and().field("id").isNotEmpty() + .and().field("processDefinitionId").isNull() + .and().field("startUserId").isNull(); + processesList.get(2).onModel().assertThat().fieldsCount().is(1) + .and().field("id").isNotEmpty() + .and().field("processDefinitionId").isNull() + .and().field("startUserId").isNull(); + processes.assertThat().entriesListIsNotEmpty() + .and().entriesListContains("id", process3.getId()) + .and().entriesListContains("id", task2.getProcessId()) + .and().entriesListContains("id", task1.getProcessId()); + } + + @Bug(id = "REPO-1958") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify user cannot get processes when using an invalid orderBy parameter") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void getProcessesWithInvalidOrderByParameter() throws Exception + { + restClient.authenticateUser(userWhoStartsTask).withParams("orderBy=test") + .withWorkflowAPI().getProcesses(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsErrorKey(String.format(RestErrorModel.INVALID_ORDERBY, "test", "processDefinitionId, startUserId, startActivityId,startedAt, id, completed, processDefinitionKey")) + .containsSummary(String.format(RestErrorModel.INVALID_ORDERBY, "test", "processDefinitionId, startUserId, startActivityId,startedAt, id, completed, processDefinitionKey")) + .stackTraceIs(RestErrorModel.STACKTRACE) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify user cannot get processes when using an invalid parameter in where clause") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void getProcessesWithInvalidWhereParameter() throws Exception + { + restClient.authenticateUser(userWhoStartsTask).where("startUserIdd='" + userWhoStartsTask.getUsername() + "'") + .withWorkflowAPI().getProcesses(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsErrorKey(RestErrorModel.INVALID_PROPERTY_ERRORKEY) + .containsSummary(String.format(RestErrorModel.PROPERTY_IS_NOT_SUPPORTED_EQUALS, "startUserIdd", userWhoStartsTask.getUsername())) + .stackTraceIs(RestErrorModel.STACKTRACE) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify user cannot get processes when using an invalid where clause expression") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void getProcessesWithInvalidWhereClauseExpression() throws Exception + { + restClient.authenticateUser(userWhoStartsTask).where("startUserId AND '" + userWhoStartsTask.getUsername() + "'") + .withWorkflowAPI().getProcesses(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsErrorKey(RestErrorModel.INVALID_QUERY_ERRORKEY) + .containsSummary(String.format(RestErrorModel.INVALID_WHERE_QUERY, "(startUserId AND '" + userWhoStartsTask.getUsername() + "')")) + .stackTraceIs(RestErrorModel.STACKTRACE) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/GetProcessesSanityTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/GetProcessesSanityTests.java new file mode 100644 index 0000000000..d522cdbc5e --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/GetProcessesSanityTests.java @@ -0,0 +1,78 @@ +package org.alfresco.rest.workflow.processes; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestProcessModelsCollection; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TaskModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 10/11/2016. + */ +public class GetProcessesSanityTests extends RestTest +{ + private FileModel document; + private SiteModel siteModel; + private UserModel userWhoStartsTask, assignee, anotherUser; + private TaskModel task; + private RestProcessModelsCollection allProcesses; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + userWhoStartsTask = dataUser.createRandomTestUser(); + assignee = dataUser.createRandomTestUser(); + anotherUser = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userWhoStartsTask).createPublicRandomSite(); + document = dataContent.usingUser(userWhoStartsTask).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + task = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(document).createNewTaskAndAssignTo(assignee); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.SANITY, + description = "Verify User gets all processes started by him using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.SANITY }) + public void getProcessesByUserWhoStartedProcess() throws Exception + { + allProcesses = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI().getProcesses(); + restClient.assertStatusCodeIs(HttpStatus.OK); + allProcesses.assertThat().entriesListContains("id", task.getProcessId()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.SANITY, + description = "Verify User gets all processes assigned to him using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.SANITY }) + public void getProcessesByAssignedUser() throws Exception + { + allProcesses = restClient.authenticateUser(assignee).withWorkflowAPI().getProcesses(); + restClient.assertStatusCodeIs(HttpStatus.OK); + allProcesses.assertThat().entriesListContains("id", task.getProcessId()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.SANITY, + description = "Verify User that is not involved in a process can not get that process using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.SANITY }) + public void getProcessesByAnotherUser() throws Exception + { + allProcesses = restClient.authenticateUser(anotherUser).withWorkflowAPI().getProcesses(); + restClient.assertStatusCodeIs(HttpStatus.OK); + allProcesses.assertThat().entriesListDoesNotContain("id", task.getProcessId()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.SANITY, + description = "Verify Admin gets all processes, even if he isn't involved in a process, using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.SANITY }) + public void getProcessesByAdmin() throws Exception + { + allProcesses = restClient.authenticateUser(dataUser.getAdminUser()).withWorkflowAPI().getProcesses(); + restClient.assertStatusCodeIs(HttpStatus.OK); + allProcesses.assertThat().entriesListContains("id", task.getProcessId()); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/items/AddProcessItemCoreTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/items/AddProcessItemCoreTests.java new file mode 100644 index 0000000000..d5c2e78741 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/items/AddProcessItemCoreTests.java @@ -0,0 +1,181 @@ +package org.alfresco.rest.workflow.processes.items; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestItemModel; +import org.alfresco.rest.model.RestItemModelsCollection; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.rest.model.RestProcessModelsCollection; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class AddProcessItemCoreTests extends RestTest +{ + private FileModel document, document2; + private SiteModel siteModel; + private UserModel userWhoStartsProcess, assignee, adminUser, anotherUser; + private RestProcessModel processModel; + private RestItemModel processItem; + private RestItemModelsCollection processItems; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + userWhoStartsProcess = dataUser.createRandomTestUser(); + assignee = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(adminUser).createPublicRandomSite(); + document = dataContent.usingUser(adminUser).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + document2 = dataContent.usingUser(adminUser).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + dataWorkflow.usingUser(userWhoStartsProcess).usingSite(siteModel).usingResource(document).createNewTaskAndAssignTo(assignee); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Add process item using by the user who started the process.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void addProcessItemByUserThatStartedTheProcess() throws Exception + { + processModel = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + processItem = restClient.withWorkflowAPI().usingProcess(processModel).addProcessItem(document); + + restClient.assertStatusCodeIs(HttpStatus.CREATED); + processItem.assertThat().field("createdAt").isNotEmpty().and().field("size").is("19").and().field("createdBy").is(adminUser.getUsername()).and() + .field("modifiedAt").isNotEmpty().and().field("name").is(document.getName()).and().field("modifiedBy").is(userWhoStartsProcess.getUsername()) + .and().field("id").isNotEmpty().and().field("mimeType").is(document.getFileType().mimeType); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Add multiple process items using by the user who started the process.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void addMultipleProcessItemsByUserThatStartedTheProcess() throws Exception + { + processModel = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + processItems = restClient.withWorkflowAPI().usingProcess(processModel).addProcessItems(document, document2); + + restClient.assertStatusCodeIs(HttpStatus.CREATED); + processItems.getEntries().get(0).onModel().assertThat() + .field("createdAt").isNotEmpty().and() + .field("size").is("19").and() + .field("createdBy").is(adminUser.getUsername()).and() + .field("modifiedAt").isNotEmpty().and() + .field("name").is(document.getName()).and() + .field("modifiedBy").is(userWhoStartsProcess.getUsername()).and() + .field("id").isNotEmpty().and() + .field("mimeType").is(document.getFileType().mimeType); + processItems.getEntries().get(1).onModel().assertThat() + .field("createdAt").isNotEmpty().and() + .field("size").is("19").and() + .field("createdBy").is(adminUser.getUsername()).and() + .field("modifiedAt").isNotEmpty().and() + .field("name").is(document2.getName()).and() + .field("modifiedBy").is(userWhoStartsProcess.getUsername()).and() + .field("id").isNotEmpty().and() + .field("mimeType").is(document2.getFileType().mimeType); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Add process item by a random user.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void addProcessItemByAnyUser() throws Exception + { + anotherUser = dataUser.createRandomTestUser(); + + document2 = dataContent.usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + processModel = restClient.authenticateUser(adminUser).withParams("maxItems=1").withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + processItem = restClient.authenticateUser(anotherUser).withWorkflowAPI().usingProcess(processModel).addProcessItem(document2); + + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError() + .containsSummary(String.format(RestErrorModel.ACCESS_INFORMATION_NOT_ALLOWED, processModel.getId())); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Add multiple process item by a random user.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void addMultipleProcessItemByAnyUser() throws Exception + { + anotherUser = dataUser.createRandomTestUser(); + + document2 = dataContent.usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + processModel = restClient.authenticateUser(adminUser).withParams("maxItems=1").withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + processItems = restClient.authenticateUser(anotherUser).withWorkflowAPI().usingProcess(processModel) + .addProcessItems(document2, document); + + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError() + .containsSummary(String.format(RestErrorModel.ACCESS_INFORMATION_NOT_ALLOWED, processModel.getId())); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding process item is falling in case of invalid process id is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void failedAddingProcessItemIfInvalidProcessIdIsProvided() throws Exception + { + RestProcessModelsCollection processes = restClient.authenticateUser(adminUser).withParams("maxItems=1").withWorkflowAPI().getProcesses(); + processModel = processes.assertThat().entriesListIsNotEmpty().when().getOneRandomEntry().onModel(); + FileModel testDocument = dataContent.usingAdmin().usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + + processModel.setId("invalidProcessId"); + processItem = restClient.withWorkflowAPI().usingProcess(processModel).addProcessItem(testDocument); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "invalidProcessId")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding multiple process items is falling in case of invalid process id is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void failedAddingMultipleProcessItemsIfInvalidProcessIdIsProvided() throws Exception + { + RestProcessModelsCollection processes = restClient.authenticateUser(adminUser).withParams("maxItems=1").withWorkflowAPI().getProcesses(); + processModel = processes.assertThat().entriesListIsNotEmpty().when().getOneRandomEntry().onModel(); + FileModel testDocument = dataContent.usingAdmin().usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + + processModel.setId("invalidProcessId"); + processItems = restClient.withWorkflowAPI().usingProcess(processModel).addProcessItems(testDocument, document); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "invalidProcessId")); + } + + @Bug(id = "REPO-1937") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding process item is falling in case of invalid body item is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void failedAddingProcessItemIfInvalidItemBodyIsProvided() throws Exception + { + document.setNodeRef("invalidNodeRef"); + processItem = restClient.withWorkflowAPI().usingProcess(processModel).addProcessItem(document); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "invalidId")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding multiple process items is falling in case of empty body item value is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void failedAddingMultipleProcessItemIfEmptyItemBodyIsProvided() throws Exception + { + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + document.setNodeRef(""); + processItems = restClient.withWorkflowAPI().usingProcess(processModel).addProcessItems(document, document2); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(String.format(RestErrorModel.REQUIRED_TO_ADD, "itemId")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding process item is falling in case of incomplete body (empty) is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void failedAddingProcessItemIfIncompleteBodyIsProvided() throws Exception + { + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, "{}", "processes/{processId}/items", processModel.getId()); + restClient.processModel(RestItemModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(String.format(RestErrorModel.REQUIRED_TO_ADD, "itemId")); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/items/AddProcessItemFullTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/items/AddProcessItemFullTests.java new file mode 100644 index 0000000000..5db98f2c42 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/items/AddProcessItemFullTests.java @@ -0,0 +1,131 @@ +package org.alfresco.rest.workflow.processes.items; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestItemModel; +import org.alfresco.rest.model.RestItemModelsCollection; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.ProcessModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class AddProcessItemFullTests extends RestTest +{ + private FileModel document, document2; + private SiteModel siteModel; + private UserModel userWhoStartsProcess, assignee, adminUser; + private ProcessModel processModel; + private RestItemModel processItem; + private RestItemModelsCollection processItems; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + userWhoStartsProcess = dataUser.createRandomTestUser(); + assignee = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(adminUser).createPublicRandomSite(); + document = dataContent.usingUser(adminUser).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + document2 = dataContent.usingUser(adminUser).usingSite(siteModel).createContent(DocumentType.MSPOWERPOINT); + dataWorkflow.usingUser(userWhoStartsProcess).usingSite(siteModel).usingResource(document).createNewTaskAndAssignTo(assignee); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding multiple process items is falling in case of empty process id is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void failedAddingMultipleProcessItemsIfEmptyProcessIdIsProvided() throws Exception + { + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + FileModel testDocument = dataContent.usingAdmin().usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + + processModel.setId(""); + processItems = restClient.withWorkflowAPI().usingProcess(processModel).addProcessItems(testDocument, document); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_WAS_NOT_FOUND, "")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding process items is falling in case of empty process id is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void failedAddingProcessItemsIfEmptyProcessIdIsProvided() throws Exception + { + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + FileModel testDocument = dataContent.usingAdmin().usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + + processModel.setId(""); + processItem = restClient.withWorkflowAPI().usingProcess(processModel).addProcessItem(testDocument); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_WAS_NOT_FOUND, "")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding process item is falling in case of empty body item value is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void failedAddingProcessItemIfEmptyItemBodyIsProvided() throws Exception + { + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + document.setNodeRef(""); + processItem = restClient.withWorkflowAPI().usingProcess(processModel).addProcessItem(document); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(String.format(RestErrorModel.REQUIRED_TO_ADD, "itemId")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding multiple process items is falling in case of empty body item value is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void failedAddingMultipleProcessItemsIfEmptyItemBodyIsProvided() throws Exception + { + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + document.setNodeRef(""); + + processItems = restClient.withWorkflowAPI().usingProcess(processModel).addProcessItems(document, document2); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(String.format(RestErrorModel.REQUIRED_TO_ADD, "itemId")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Add a new process item, update the item and then delete.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void createDeleteCreateMultipleProcessItems() throws Exception + { + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + document2 = dataContent.usingAdmin().usingSite(siteModel).createContent(DocumentType.MSPOWERPOINT); + processItems = restClient.withWorkflowAPI().usingProcess(processModel).addProcessItems(document, document2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.withWorkflowAPI().usingProcess(processModel).deleteProcessItem(processItems.getEntries().get(0).onModel()); + + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withWorkflowAPI().usingProcess(processModel).getProcessItems() + .assertThat().entriesListDoesNotContain("name", processItems.getEntries().get(0).onModel().getName()); + + processItems = restClient.withWorkflowAPI().usingProcess(processModel).addProcessItems(document); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Add a new process item, delete the item and create it again.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void createDeleteCreateProcessItem() throws Exception + { + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + processItem = restClient.withWorkflowAPI().usingProcess(processModel).addProcessItem( document2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.withWorkflowAPI().usingProcess(processModel).deleteProcessItem(processItem); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withWorkflowAPI().usingProcess(processModel).getProcessItems() + .assertThat().entriesListDoesNotContain("name", processItem.getName()); + + processItem = restClient.withWorkflowAPI().usingProcess(processModel).addProcessItem(document2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.withWorkflowAPI().usingProcess(processModel).getProcessItems() + .assertThat().entriesListContains("name", processItem.getName()); + } + +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/items/AddProcessItemSanityTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/items/AddProcessItemSanityTests.java new file mode 100644 index 0000000000..ab85ea625b --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/items/AddProcessItemSanityTests.java @@ -0,0 +1,174 @@ +package org.alfresco.rest.workflow.processes.items; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.exception.JsonToModelConversionException; +import org.alfresco.rest.model.RestItemModel; +import org.alfresco.rest.model.RestItemModelsCollection; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * @author iulia.cojocea + */ +public class AddProcessItemSanityTests extends RestTest +{ + private FileModel document, document2; + private SiteModel siteModel; + private UserModel userWhoStartsTask, assignee, adminUser; + private RestProcessModel processModel; + private RestItemModel processItem; + private RestItemModelsCollection processItems; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + userWhoStartsTask = dataUser.createRandomTestUser(); + assignee = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(adminUser).createPublicRandomSite(); + document = dataContent.usingUser(adminUser).usingSite(siteModel).createContent(DocumentType.XML); + dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(document).createNewTaskAndAssignTo(assignee); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.SANITY, + description = "Create non-existing process item") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.SANITY}) + public void addProcessItem() throws JsonToModelConversionException, Exception + { + document2 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "This is a test file"); + dataContent.usingSite(siteModel).createContent(document2); + + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + processItem = restClient.withWorkflowAPI().usingProcess(processModel).addProcessItem(document2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + processItem.assertThat().field("createdAt").isNotEmpty() + .and().field("size").is(document2.getContent().length()) + .and().field("createdBy").is(adminUser.getUsername()) + .and().field("modifiedAt").isNotEmpty() + .and().field("name").is(document2.getName()) + .and().field("modifiedBy").is(adminUser.getUsername()) + .and().field("id").isNotEmpty() + .and().field("mimeType").is(document2.getFileType().mimeType); + + restClient.withWorkflowAPI().usingProcess(processModel).getProcessItems() + .assertThat().entriesListContains("id", processItem.getId()); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.SANITY, + description = "Create non-existing process item") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.SANITY}) + public void addMultipleProcessItem() throws JsonToModelConversionException, Exception + { + document2 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "This is a test file"); + dataContent.usingSite(siteModel).createContent(document2); + document = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "This is a test file"); + dataContent.usingSite(siteModel).createContent(document); + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + processItems = restClient.withWorkflowAPI().usingProcess(processModel).addProcessItems(document2, document); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + processItems.getEntries().get(0).onModel() + .assertThat().field("createdAt").isNotEmpty() + .and().field("size").is(document2.getContent().length()) + .and().field("createdBy").is(adminUser.getUsername()) + .and().field("modifiedAt").isNotEmpty() + .and().field("name").is(document2.getName()) + .and().field("modifiedBy").is(adminUser.getUsername()) + .and().field("id").isNotEmpty() + .and().field("mimeType").is(document2.getFileType().mimeType); + + processItems.getEntries().get(1).onModel() + .assertThat().field("createdAt").isNotEmpty() + .and().field("size").is(document.getContent().length()) + .and().field("createdBy").is(adminUser.getUsername()) + .and().field("modifiedAt").isNotEmpty() + .and().field("name").is(document.getName()) + .and().field("modifiedBy").is(adminUser.getUsername()) + .and().field("id").isNotEmpty() + .and().field("mimeType").is(document.getFileType().mimeType); + + restClient.withWorkflowAPI().usingProcess(processModel).getProcessItems() + .assertThat().entriesListContains("id", processItems.getEntries().get(0).onModel().getId()) + .assertThat().entriesListContains("id", processItems.getEntries().get(1).onModel().getId()); + } + + @Bug(id= "REPO-1927") + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.SANITY, + description = "Add process item that already exists") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.SANITY}) + public void addProcessItemThatAlreadyExists() throws JsonToModelConversionException, Exception + { + document2 = dataContent.usingSite(siteModel).createContent(DocumentType.XML); + + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + processItem = restClient.withWorkflowAPI().usingProcess(processModel).addProcessItem(document2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + processItem.assertThat().field("createdAt").isNotEmpty() + .and().field("size").is("19") + .and().field("createdBy").is(adminUser.getUsername()) + .and().field("modifiedAt").isNotEmpty() + .and().field("name").is(document2.getName()) + .and().field("modifiedBy").is(adminUser.getUsername()) + .and().field("id").isNotEmpty() + .and().field("mimeType").is(document2.getFileType().mimeType); + + restClient.withWorkflowAPI().usingProcess(processModel).getProcessItems() + .assertThat().entriesListContains("id", processItem.getId()) + .and().entriesListContains("name", document2.getName()); + restClient.withWorkflowAPI().usingProcess(processModel).addProcessItem(document2); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST); + } + + @Bug(id= "REPO-1927") + @TestRail(section = {TestGroup.REST_API,TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.SANITY, + description = "Add process item that already exists") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.SANITY}) + public void addMultipleProcessItemThatAlreadyExists() throws JsonToModelConversionException, Exception + { + document2 = dataContent.usingSite(siteModel).createContent(DocumentType.XML); + document = dataContent.usingSite(siteModel).createContent(DocumentType.XML); + + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + processItems = restClient.withWorkflowAPI().usingProcess(processModel).addProcessItems(document2, document); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + processItems.getEntries().get(0).onModel() + .assertThat().field("createdAt").isNotEmpty() + .and().field("size").is("19") + .and().field("createdBy").is(adminUser.getUsername()) + .and().field("modifiedAt").isNotEmpty() + .and().field("name").is(document2.getName()) + .and().field("modifiedBy").is(adminUser.getUsername()) + .and().field("id").isNotEmpty() + .and().field("mimeType").is(document2.getFileType().mimeType); + + processItems.getEntries().get(1).onModel() + .assertThat().field("createdAt").isNotEmpty() + .and().field("size").is("19") + .and().field("createdBy").is(adminUser.getUsername()) + .and().field("modifiedAt").isNotEmpty() + .and().field("name").is(document.getName()) + .and().field("modifiedBy").is(adminUser.getUsername()) + .and().field("id").isNotEmpty() + .and().field("mimeType").is(document.getFileType().mimeType); + + restClient.withWorkflowAPI().usingProcess(processModel).getProcessItems() + .assertThat().entriesListContains("id", processItems.getEntries().get(0).onModel().getId()) + .and().entriesListContains("name", document2.getName()) + .assertThat().entriesListContains("id", processItems.getEntries().get(1).onModel().getId()) + .and().entriesListContains("name", document.getName()); + + restClient.withWorkflowAPI().usingProcess(processModel).addProcessItems(document2, document); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/items/DeleteProcessItemCoreTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/items/DeleteProcessItemCoreTests.java new file mode 100644 index 0000000000..9df2a2a3b9 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/items/DeleteProcessItemCoreTests.java @@ -0,0 +1,85 @@ +package org.alfresco.rest.workflow.processes.items; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestItemModel; +import org.alfresco.rest.model.RestItemModelsCollection; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.ProcessModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class DeleteProcessItemCoreTests extends RestTest +{ + private FileModel document, secondDoc; + private SiteModel siteModel; + private UserModel userWhoStartsTask, assignee; + private RestProcessModel restProcessModel; + private ProcessModel processModel; + private RestItemModelsCollection items; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + userWhoStartsTask = dataUser.createRandomTestUser(); + assignee = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userWhoStartsTask).createPublicRandomSite(); + document = dataContent.usingUser(userWhoStartsTask).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + processModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(document) + .createSingleReviewerTaskAndAssignTo(assignee); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Delete process item with invalid id") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void deleteProcessItemWithInvalidItemId() throws Exception + { + restProcessModel = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI() + .getProcesses().getProcessModelByProcessDefId(processModel.getId()); + secondDoc = dataContent.usingUser(userWhoStartsTask).usingSite(siteModel).createContent(DocumentType.MSWORD); + RestItemModel processItem = restClient.withWorkflowAPI().usingProcess(processModel).addProcessItem(secondDoc); + processItem.setId("invalid-id"); + restClient.withWorkflowAPI().usingProcess(processModel).deleteProcessItem(processItem); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.PROCESS_ENTITY_NOT_FOUND, "invalid-id")); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Delete process item with empty id") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void deleteProcessItemWithEmptyItemId() throws Exception + { + restProcessModel = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI() + .getProcesses().getProcessModelByProcessDefId(processModel.getId()); + secondDoc = dataContent.usingUser(userWhoStartsTask).usingSite(siteModel).createContent(DocumentType.MSWORD); + RestItemModel processItem = restClient.withWorkflowAPI().usingProcess(processModel).addProcessItem(secondDoc); + processItem.setId(""); + restClient.withWorkflowAPI().usingProcess(processModel).deleteProcessItem(processItem); + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED) + .assertLastError().containsSummary(String.format(RestErrorModel.DELETE_EMPTY_ARGUMENT)); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Delete process item twice") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void deleteProcessItemTwice() throws Exception + { + restProcessModel = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI() + .getProcesses().getProcessModelByProcessDefId(processModel.getId()); + items = restClient.withWorkflowAPI().usingProcess(restProcessModel).getProcessItems(); + RestItemModel processItem = items.getEntries().get(0); + restClient.withWorkflowAPI().usingProcess(processModel).deleteProcessItem(processItem.onModel()); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withWorkflowAPI().usingProcess(processModel).deleteProcessItem(processItem.onModel()); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.PROCESS_ENTITY_NOT_FOUND, processItem.onModel().getId())); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/items/DeleteProcessItemFullTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/items/DeleteProcessItemFullTests.java new file mode 100644 index 0000000000..13feac4565 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/items/DeleteProcessItemFullTests.java @@ -0,0 +1,210 @@ +package org.alfresco.rest.workflow.processes.items; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.dataprep.CMISUtil.Priority; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.exception.EmptyRestModelCollectionException; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestItemModel; +import org.alfresco.rest.model.RestItemModelsCollection; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.ProcessModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class DeleteProcessItemFullTests extends RestTest +{ + private FileModel document, document2; + private SiteModel siteModel; + private UserModel userWhoStartsProcess, assignee, adminUser, anotherUser; + private ProcessModel processModel; + private RestItemModelsCollection items; + private RestItemModel processItem; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + userWhoStartsProcess = dataUser.createRandomTestUser(); + assignee = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userWhoStartsProcess).createPublicRandomSite(); + document = dataContent.usingUser(userWhoStartsProcess).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Try to delete existing process item using empty processId") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void deleteProcessItemUsingEmptyProcessId() throws Exception + { + processModel = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI() + .addProcess("activitiAdhoc", assignee, false, Priority.Normal); + document2 = dataContent.usingAdmin().usingSite(siteModel).createContent(DocumentType.MSPOWERPOINT); + processItem = restClient.withWorkflowAPI().usingProcess(processModel).addProcessItem(document2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + processModel.setId(""); + restClient.withWorkflowAPI().usingProcess(processModel).deleteProcessItem(processItem); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "The entity with id: ")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Add a new process item, update the item and then delete.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void createUpdateDeleteProcessItem() throws Exception + { + processModel = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI() + .addProcess("activitiAdhoc", assignee, false, Priority.Normal); + document2 = dataContent.usingAdmin().usingSite(siteModel).createContent(DocumentType.MSPOWERPOINT); + processItem = restClient.withWorkflowAPI().usingProcess(processModel).addProcessItem(document2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + processItem.setName("newItemName"); + processItem.assertThat().field("name").is("newItemName"); + + restClient.withWorkflowAPI().usingProcess(processModel).deleteProcessItem(processItem); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withWorkflowAPI().usingProcess(processModel).getProcessItems() + .assertThat().entriesListDoesNotContain("name", processItem.getName()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Delete process item using any user.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void deleteProcessItemByAnyUser() throws Exception + { + anotherUser = dataUser.createRandomTestUser(); + + document2 = dataContent.usingAdmin().usingSite(siteModel).createContent(DocumentType.HTML); + processItem = restClient.withWorkflowAPI().usingProcess(processModel).addProcessItem(document2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.authenticateUser(anotherUser).withWorkflowAPI().usingProcess(processModel) + .deleteProcessItem(processItem); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError() + .containsSummary(String.format(RestErrorModel.ACCESS_INFORMATION_NOT_ALLOWED, processModel.getId())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .containsErrorKey(String.format(RestErrorModel.ACCESS_INFORMATION_NOT_ALLOWED, processModel.getId())) + .stackTraceIs(RestErrorModel.STACKTRACE);; + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Delete process item with admin.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void deleteProcessItemWithAdmin() throws Exception + { + processModel = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI() + .addProcess("activitiAdhoc", assignee, false, Priority.Normal); + + document2 = dataContent.usingAdmin().usingSite(siteModel).createContent(DocumentType.HTML); + processItem = restClient.withWorkflowAPI().usingProcess(processModel).addProcessItem(document2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.authenticateUser(adminUser).withWorkflowAPI().usingProcess(processModel) + .deleteProcessItem(processItem); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withWorkflowAPI().usingProcess(processModel).getProcessVariables() + .assertThat().entriesListDoesNotContain("name", processItem.getName()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Delete process item by the user who is involved in the process.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void deleteProcessItemByUserInvolvedInTheProcess() throws Exception + { + processModel = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI() + .addProcess("activitiAdhoc", assignee, false, Priority.Normal); + + processItem = restClient.withWorkflowAPI().usingProcess(processModel).addProcessItem(document); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.authenticateUser(assignee).withWorkflowAPI().usingProcess(processModel) + .deleteProcessItem(processItem); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withWorkflowAPI().usingProcess(processModel).getProcessVariables() + .assertThat().entriesListDoesNotContain("name", processItem.getName()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Delete process item by the user who started the process.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void deleteProcessItemByUserThatStartedTheProcess() throws Exception + { + processModel = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI() + .addProcess("activitiAdhoc", assignee, false, Priority.Normal); + processItem = restClient.withWorkflowAPI().usingProcess(processModel).addProcessItem(document); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().usingProcess(processModel) + .deleteProcessItem(processItem); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withWorkflowAPI().usingProcess(processModel).getProcessVariables() + .assertThat().entriesListDoesNotContain("name", processItem.getName()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Delete process item for a deleted process.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void deleteProcessItemsForDeletedProcess() throws Exception + { + processModel = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI() + .addProcess("activitiAdhoc", assignee, false, Priority.Normal); + processItem = restClient.withWorkflowAPI().usingProcess(processModel).addProcessItem(document); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.withWorkflowAPI().usingProcess(processModel).deleteProcess(); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + restClient.withWorkflowAPI().usingProcess(processModel).deleteProcessItem(processItem); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, processModel.getId())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Delete process item by inexistent user.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void deleteProcessItemByInexistentUser() throws Exception + { + processModel = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI() + .addProcess("activitiAdhoc", assignee, false, Priority.Normal); + processItem = restClient.withWorkflowAPI().usingProcess(processModel).addProcessItem(document); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.authenticateUser(UserModel.getRandomUserModel()).withWorkflowAPI().usingProcess(processModel) + .deleteProcessItem(processItem); + + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Delete process item for process without items.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION}, + expectedExceptions = EmptyRestModelCollectionException.class) + public void deleteProcessItemsForProcessWithoutItems() throws Exception + { + processModel = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI() + .addProcess("activitiAdhoc", assignee, false, Priority.Normal); + + items = restClient.withWorkflowAPI().usingProcess(processModel).getProcessItems(); + restClient.assertStatusCodeIs(HttpStatus.OK); + items.assertThat().entriesListIsEmpty(); + + restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().usingProcess(processModel) + .deleteProcessItem(items.getOneRandomEntry()); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/items/DeleteProcessItemSanityTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/items/DeleteProcessItemSanityTests.java new file mode 100644 index 0000000000..55d92185aa --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/items/DeleteProcessItemSanityTests.java @@ -0,0 +1,67 @@ +package org.alfresco.rest.workflow.processes.items; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestItemModel; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * @author iulia.cojocea + */ +public class DeleteProcessItemSanityTests extends RestTest +{ + private FileModel document, document2; + private SiteModel siteModel; + private UserModel userWhoStartsTask, assignee, adminUser; + private RestProcessModel processModel; + private RestItemModel processItem; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + userWhoStartsTask = dataUser.createRandomTestUser(); + assignee = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(adminUser).createPublicRandomSite(); + document = dataContent.usingUser(adminUser).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(document).createNewTaskAndAssignTo(assignee); + } + + @TestRail(section = {TestGroup.REST_API,TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.SANITY, + description = "Delete existing process item") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.SANITY }) + public void deleteProcessItem() throws Exception + { + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + document2 = dataContent.usingAdmin().usingSite(siteModel).createContent(DocumentType.MSWORD); + processItem = restClient.withWorkflowAPI().usingProcess(processModel).addProcessItem(document2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.withWorkflowAPI().usingProcess(processModel).deleteProcessItem(processItem); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withWorkflowAPI().usingProcess(processModel).getProcessItems() + .assertThat().entriesListDoesNotContain("id", processItem.getId()); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.SANITY, + description = "Try to delete existing process item using invalid processId") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.SANITY }) + public void deleteProcessItemUsingInvalidProcessId() throws Exception + { + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + document2 = dataContent.usingAdmin().usingSite(siteModel).createContent(DocumentType.MSPOWERPOINT); + processItem = restClient.withWorkflowAPI().usingProcess(processModel).addProcessItem(document2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + processModel.setId("incorrectProcessId"); + restClient.withWorkflowAPI().usingProcess(processModel).deleteProcessItem(processItem); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/items/GetProcessItemsCoreTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/items/GetProcessItemsCoreTests.java new file mode 100644 index 0000000000..e79d42f2b0 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/items/GetProcessItemsCoreTests.java @@ -0,0 +1,70 @@ +package org.alfresco.rest.workflow.processes.items; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class GetProcessItemsCoreTests extends RestTest +{ + private FileModel document; + private SiteModel siteModel; + private UserModel adminUser, userWhoStartsTask, assignee; + private RestProcessModel processModel; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + userWhoStartsTask = dataUser.createRandomTestUser(); + assignee = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userWhoStartsTask).createPublicRandomSite(); + document = dataContent.usingUser(userWhoStartsTask).usingSite(siteModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(document).createNewTaskAndAssignTo(assignee); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify that admin calling getProcessItems can see anything with REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void getProcessItemsAsAdminReturnsAnything() throws Exception + { + processModel = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + restClient.withWorkflowAPI().usingProcess(processModel).addProcessItem(document); + + restClient.authenticateUser(adminUser).withWorkflowAPI().usingProcess(processModel).getProcessItems().assertThat().entriesListIsNotEmpty(); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify getProcessItems for invalid processId with REST API and status code is NOT_FOUND (404)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void getProcessItemsForInvalidProcessId() throws Exception + { + processModel = restClient.authenticateUser(assignee).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + processModel.setId("invalidProcessId"); + restClient.withWorkflowAPI().usingProcess(processModel).getProcessItems().assertThat().entriesListIsEmpty(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "invalidProcessId")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify getProcessItems for empty processId with REST API and status code is NOT_FOUND (404)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void getProcessItemsForEmptyProcessId() throws Exception + { + processModel = restClient.authenticateUser(assignee).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + processModel.setId(""); + restClient.withWorkflowAPI().usingProcess(processModel).getProcessItems().assertThat().entriesListIsEmpty(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "")); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/items/GetProcessItemsFullTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/items/GetProcessItemsFullTests.java new file mode 100644 index 0000000000..c81c5c3f4f --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/items/GetProcessItemsFullTests.java @@ -0,0 +1,198 @@ +package org.alfresco.rest.workflow.processes.items; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestItemModelsCollection; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 2/2/2017. + */ +public class GetProcessItemsFullTests extends RestTest +{ + private FileModel document1, document2, document3; + private SiteModel siteModel; + private UserModel userWhoStartsTask, assignee; + private RestProcessModel processModel; + private RestItemModelsCollection items; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + userWhoStartsTask = dataUser.createRandomTestUser(); + assignee = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userWhoStartsTask).createPublicRandomSite(); + document1 = dataContent.usingUser(userWhoStartsTask).usingSite(siteModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + document2 = dataContent.usingUser(userWhoStartsTask).usingSite(siteModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + document3 = dataContent.usingUser(userWhoStartsTask).usingSite(siteModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Get process items for process without items") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION}) + public void getProcessItemsForProcessWithoutItems() throws Exception + { + processModel = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI().addProcess("activitiAdhoc", assignee, false, CMISUtil.Priority.Normal); + items = restClient.withWorkflowAPI().usingProcess(processModel).getProcessItems(); + restClient.assertStatusCodeIs(HttpStatus.OK); + items.assertThat().entriesListIsEmpty(); + } + + @Bug(id = "REPO-1989") + @TestRail(section = { TestGroup.REST_API, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Get process items for process with valid skipCount parameter") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION}) + public void getProcessItemsWithValidSkipCount() throws Exception + { + processModel = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI().addProcess("activitiAdhoc", assignee, false, CMISUtil.Priority.Normal); + restClient.withWorkflowAPI().usingProcess(processModel).addProcessItem(document1); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.withWorkflowAPI().usingProcess(processModel).addProcessItem(document2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.withWorkflowAPI().usingProcess(processModel).addProcessItem(document3); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + items = restClient.authenticateUser(assignee).withParams("skipCount=2").withWorkflowAPI().usingProcess(processModel).getProcessItems(); + restClient.assertStatusCodeIs(HttpStatus.OK); + items.assertThat().entriesListContains("name", document3.getName()) + .assertThat().entriesListDoesNotContain("name", document1.getName()) + .assertThat().entriesListDoesNotContain("name", document2.getName()) + .assertThat().entriesListCountIs(1) + .assertThat().paginationField("skipCount").is("2"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Get process items for process with negative skipCount") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION}) + public void getProcessItemsWithNegativeSkipCount() throws Exception + { + processModel = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI().addProcess("activitiAdhoc", assignee, false, CMISUtil.Priority.Normal); + restClient.authenticateUser(assignee).withParams("skipCount=-2").withWorkflowAPI().usingProcess(processModel).getProcessItems(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(RestErrorModel.NEGATIVE_VALUES_SKIPCOUNT) + .containsErrorKey(RestErrorModel.NEGATIVE_VALUES_SKIPCOUNT) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE) + .statusCodeIs(HttpStatus.BAD_REQUEST); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Get process items for process with non numeric skipCount") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION}) + public void getProcessItemsWithNonNumericSkipCount() throws Exception + { + processModel = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI().addProcess("activitiAdhoc", assignee, false, CMISUtil.Priority.Normal); + restClient.authenticateUser(assignee).withParams("skipCount=A").withWorkflowAPI().usingProcess(processModel).getProcessItems(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(String.format(RestErrorModel.INVALID_SKIPCOUNT, "A")); + } + + @Bug(id = "MNT-17438") + @TestRail(section = { TestGroup.REST_API, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Get process items for process with valid maxItems parameter") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION}) + public void getProcessItemsWithValidMaxItems() throws Exception + { + processModel = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI().addProcess("activitiAdhoc", assignee, false, CMISUtil.Priority.Normal); + restClient.withWorkflowAPI().usingProcess(processModel).addProcessItem(document1); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.withWorkflowAPI().usingProcess(processModel).addProcessItem(document2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.withWorkflowAPI().usingProcess(processModel).addProcessItem(document3); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + items = restClient.authenticateUser(assignee).withParams("maxItems=2").withWorkflowAPI().usingProcess(processModel).getProcessItems(); + restClient.assertStatusCodeIs(HttpStatus.OK); + items.assertThat().entriesListDoesNotContain("name", document3.getName()) + .assertThat().entriesListContains("name", document1.getName()) + .assertThat().entriesListContains("name", document2.getName()) + .assertThat().entriesListCountIs(2) + .assertThat().paginationField("maxItems").is("2"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Get process items for process with negative maxItems") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION}) + public void getProcessItemsWithNegativeMaxItems() throws Exception + { + processModel = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI().addProcess("activitiAdhoc", assignee, false, CMISUtil.Priority.Normal); + restClient.authenticateUser(assignee).withParams("maxItems=-2").withWorkflowAPI().usingProcess(processModel).getProcessItems(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS) + .containsErrorKey(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE) + .statusCodeIs(HttpStatus.BAD_REQUEST); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Get process items for process with non numeric maxItems") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION}) + public void getProcessItemsWithNonNumericMaxItems() throws Exception + { + processModel = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI().addProcess("activitiAdhoc", assignee, false, CMISUtil.Priority.Normal); + restClient.authenticateUser(assignee).withParams("maxItems=A").withWorkflowAPI().usingProcess(processModel).getProcessItems(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(String.format(RestErrorModel.INVALID_MAXITEMS, "A")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify get all process items with properties parameter.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void getProcessItemsWithPropertiesParameter() throws Exception + { + processModel = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI().addProcess("activitiAdhoc", assignee, false, CMISUtil.Priority.Normal); + restClient.withWorkflowAPI().usingProcess(processModel).addProcessItem(document1); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + items = restClient.authenticateUser(assignee).withParams("properties=createdBy,name,mimeType,size").withWorkflowAPI().usingProcess(processModel).getProcessItems(); + restClient.assertStatusCodeIs(HttpStatus.OK); + items.assertThat().entriesListIsNotEmpty(); + items.getProcessItemByName(document1.getName()) + .assertThat().field("createdBy").is(userWhoStartsTask.getUsername()) + .assertThat().field("name").is(document1.getName()) + .assertThat().field("mimeType").is(document1.getFileType().mimeType) + .assertThat().field("size").isNotNull() + .assertThat().field("modifiedAt").isNull() + .assertThat().field("modifiedBy").isNull() + .assertThat().field("id").isNull() + .assertThat().field("createdAt ").isNull() + .assertThat().fieldsCount().is(4); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify get all process items after process is deleted.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void getProcessItemsAfterDeletingProcess() throws Exception + { + processModel = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI().addProcess("activitiAdhoc", assignee, false, CMISUtil.Priority.Normal); + restClient.withWorkflowAPI().usingProcess(processModel).addProcessItem(document1); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.withWorkflowAPI().usingProcess(processModel).deleteProcess(); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + items = restClient.authenticateUser(assignee).withWorkflowAPI().usingProcess(processModel).getProcessItems(); + restClient.assertStatusCodeIs(HttpStatus.OK); + items.assertThat().entriesListIsNotEmpty(); + items.getProcessItemByName(document1.getName()) + .assertThat().field("createdBy").is(userWhoStartsTask.getUsername()) + .assertThat().field("name").is(document1.getName()) + .assertThat().field("mimeType").is(document1.getFileType().mimeType) + .assertThat().field("size").isNotNull() + .assertThat().field("modifiedAt").isNotNull() + .assertThat().field("modifiedBy").is(userWhoStartsTask.getUsername()) + .assertThat().field("id").is(document1.getNodeRefWithoutVersion()) + .assertThat().field("createdAt ").isNotNull(); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/items/GetProcessItemsSanityTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/items/GetProcessItemsSanityTests.java new file mode 100644 index 0000000000..6c0ce37649 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/items/GetProcessItemsSanityTests.java @@ -0,0 +1,59 @@ +package org.alfresco.rest.workflow.processes.items; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestItemModelsCollection; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * @author iulia.cojocea + */ +public class GetProcessItemsSanityTests extends RestTest +{ + private FileModel document; + private SiteModel siteModel; + private UserModel userWhoStartsTask, assignee; + private RestProcessModel processModel; + private RestItemModelsCollection items; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + userWhoStartsTask = dataUser.createRandomTestUser(); + assignee = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userWhoStartsTask).createPublicRandomSite(); + document = dataContent.usingUser(userWhoStartsTask).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(document).createNewTaskAndAssignTo(assignee); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.PROCESSES }, executionType = ExecutionType.SANITY, + description = "Verify that user that started the process gets all process items") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.SANITY }) + public void getProcessItemsUsingTheUserWhoStartedProcess() throws Exception + { + processModel = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + items = restClient.withWorkflowAPI().usingProcess(processModel).getProcessItems(); + restClient.assertStatusCodeIs(HttpStatus.OK); + items.assertThat().entriesListIsNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.PROCESSES }, executionType = ExecutionType.SANITY, + description = "Verify that user that is involved in the process gets all process items") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.SANITY }) + public void getProcessItemsUsingUserInvolvedInProcess() throws Exception + { + processModel = restClient.authenticateUser(assignee).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + items = restClient.withWorkflowAPI().usingProcess(processModel).getProcessItems(); + restClient.assertStatusCodeIs(HttpStatus.OK); + items.assertThat().entriesListIsNotEmpty(); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/tasks/GetProcessTasksCoreTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/tasks/GetProcessTasksCoreTests.java new file mode 100644 index 0000000000..7247abac74 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/tasks/GetProcessTasksCoreTests.java @@ -0,0 +1,98 @@ +package org.alfresco.rest.workflow.processes.tasks; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestTaskModel; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.GroupModel; +import org.alfresco.utility.model.ProcessModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class GetProcessTasksCoreTests extends RestTest +{ + private FileModel document, document1, document2; + private SiteModel siteModel; + private UserModel userWhoStartsProcess, candidate, anotherAssignee, assignee; + private ProcessModel process; + private GroupModel group; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + userWhoStartsProcess = dataUser.createRandomTestUser(); + candidate = dataUser.createRandomTestUser(); + anotherAssignee = dataUser.createRandomTestUser(); + assignee = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userWhoStartsProcess).createPublicRandomSite(); + document = dataContent.usingUser(userWhoStartsProcess).usingSite(siteModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + document1 = dataContent.usingUser(userWhoStartsProcess).usingSite(siteModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + document2 = dataContent.usingUser(userWhoStartsProcess).usingSite(siteModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + process = dataWorkflow.usingUser(userWhoStartsProcess).usingSite(siteModel).usingResource(document) + .createSingleReviewerTaskAndAssignTo(assignee); + group = dataGroup.createRandomGroup(); + dataGroup.addListOfUsersToGroup(group, candidate); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "getProcessTasks with user that is candidate with REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void getProcessTasksWithUserThatIsCandidate() throws Exception + { + ProcessModel processModel = dataWorkflow.usingUser(userWhoStartsProcess).usingSite(siteModel).usingResource(document1) + .createGroupReviewTaskAndAssignTo(group); + + restClient.authenticateUser(candidate).withWorkflowAPI() + .usingProcess(processModel).getProcessTasks().assertThat().entriesListIsNotEmpty() + .and().entriesListContains("assignee", candidate.getUsername()); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "getProcessTasks for invalid processId with REST API and status code is NOT_FOUND (404)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void getProcessTasksUsingInvalidProcessId() throws Exception + { + ProcessModel processModel = process; + processModel.setId("invalidProcessId"); + restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI() + .usingProcess(processModel).getProcessTasks().assertThat().entriesListIsEmpty(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "getProcessTasks for empty processId with REST API and status code is NOT_FOUND (404)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void getProcessTasksUsingEmptyProcessId() throws Exception + { + ProcessModel processModel = process; + processModel.setId(""); + restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI() + .usingProcess(processModel).getProcessTasks().assertThat().entriesListIsEmpty(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "User completes task then getProcessTasks with REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void completeTaskThenGetProcessTasks() throws Exception + { + ProcessModel processModel = dataWorkflow.usingUser(userWhoStartsProcess).usingSite(siteModel).usingResource(document2) + .createMoreReviewersWorkflowAndAssignTo(anotherAssignee); + RestTaskModel restTaskModel = restClient.authenticateUser(anotherAssignee).withWorkflowAPI() + .usingProcess(processModel).getProcessTasks().assertThat().entriesListIsNotEmpty().getOneRandomEntry().onModel(); + restTaskModel = restClient.withParams("select=state").withWorkflowAPI().usingTask(restTaskModel).updateTask("completed"); + restTaskModel.assertThat().field("id").is(restTaskModel.getId()).and().field("state").is("completed"); + restClient.withWorkflowAPI().getTasks().assertThat().entriesListIsEmpty(); + restClient.assertStatusCodeIs(HttpStatus.OK); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/tasks/GetProcessTasksFullTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/tasks/GetProcessTasksFullTests.java new file mode 100644 index 0000000000..9e194b315b --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/tasks/GetProcessTasksFullTests.java @@ -0,0 +1,207 @@ +package org.alfresco.rest.workflow.processes.tasks; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestTaskModelsCollection; +import org.alfresco.utility.model.*; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 2/3/2017. + */ +public class GetProcessTasksFullTests extends RestTest +{ + private FileModel document; + private SiteModel publicSite; + private UserModel adminUser, userWhoStartsProcess, assignee1, assignee2, assignee3; + private ProcessModel processWithSingleTask, processWithMultipleTasks; + private RestTaskModelsCollection processTasks; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + userWhoStartsProcess = dataUser.createRandomTestUser(); + assignee1 = dataUser.createRandomTestUser("A_1"); + assignee2 = dataUser.createRandomTestUser("B_2"); + assignee3 = dataUser.createRandomTestUser("C_3"); + publicSite = dataSite.usingUser(userWhoStartsProcess).createPublicRandomSite(); + document = dataContent.usingUser(userWhoStartsProcess).usingSite(publicSite).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + processWithSingleTask = dataWorkflow.usingUser(userWhoStartsProcess).usingSite(publicSite).usingResource(document) + .createSingleReviewerTaskAndAssignTo(assignee1); + processWithMultipleTasks = dataWorkflow.usingUser(userWhoStartsProcess).usingSite(publicSite).usingResource(document) + .createMoreReviewersWorkflowAndAssignTo(assignee1, assignee2, assignee3); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify admin user is able to getProcessTasks even if he wasn't involved in process. Check status code is OK") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void getProcessTasksWithAdmin() throws Exception + { + processTasks = restClient.authenticateUser(adminUser).withWorkflowAPI() + .usingProcess(processWithSingleTask).getProcessTasks(); + restClient.assertStatusCodeIs(HttpStatus.OK); + processTasks.assertThat().entriesListCountIs(1) + .and().entriesListContains("assignee", assignee1.getUsername()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Get process tasks with valid skipCount parameter applied") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION}) + public void getProcessTasksWithValidSkipCount() throws Exception + { + processTasks = restClient.authenticateUser(userWhoStartsProcess) + .withParams("orderBy=assignee ASC&skipCount=2").withWorkflowAPI() + .usingProcess(processWithMultipleTasks).getProcessTasks(); + restClient.assertStatusCodeIs(HttpStatus.OK); + processTasks.assertThat().entriesListContains("assignee", assignee3.getUsername()) + .assertThat().entriesListDoesNotContain("assignee", assignee1.getUsername()) + .assertThat().entriesListDoesNotContain("assignee", assignee2.getUsername()) + .assertThat().entriesListCountIs(1) + .assertThat().paginationField("skipCount").is("2"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Get process tasks with negative skipCount parameter applied") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION}) + public void getProcessTasksWithNegativeSkipCount() throws Exception + { + restClient.authenticateUser(userWhoStartsProcess) + .withParams("skipCount=-2").withWorkflowAPI() + .usingProcess(processWithMultipleTasks).getProcessTasks(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(RestErrorModel.NEGATIVE_VALUES_SKIPCOUNT) + .containsErrorKey(RestErrorModel.NEGATIVE_VALUES_SKIPCOUNT) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE) + .statusCodeIs(HttpStatus.BAD_REQUEST); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Get process tasks with non numeric skipCount parameter applied") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION}) + public void getProcessTasksWithNonNumericSkipCount() throws Exception + { + restClient.authenticateUser(userWhoStartsProcess) + .withParams("skipCount=A").withWorkflowAPI() + .usingProcess(processWithMultipleTasks).getProcessTasks(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(String.format(RestErrorModel.INVALID_SKIPCOUNT, "A")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Get process tasks with valid maxItems parameter applied") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION}) + public void getProcessTasksWithValidMaxItems() throws Exception + { + processTasks = restClient.authenticateUser(userWhoStartsProcess) + .withParams("orderBy=assignee ASC&maxItems=2").withWorkflowAPI() + .usingProcess(processWithMultipleTasks).getProcessTasks(); + restClient.assertStatusCodeIs(HttpStatus.OK); + processTasks.assertThat().entriesListDoesNotContain("assignee", assignee3.getUsername()) + .assertThat().entriesListContains("assignee", assignee1.getUsername()) + .assertThat().entriesListContains("assignee", assignee2.getUsername()) + .assertThat().entriesListCountIs(2) + .assertThat().paginationField("maxItems").is("2"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Get process tasks with negative maxItems parameter applied") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION}) + public void getProcessTasksWithNegativeMaxItems() throws Exception + { + restClient.authenticateUser(userWhoStartsProcess) + .withParams("maxItems=-2").withWorkflowAPI() + .usingProcess(processWithMultipleTasks).getProcessTasks(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS) + .containsErrorKey(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE) + .statusCodeIs(HttpStatus.BAD_REQUEST); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Get process tasks with non numeric maxItems parameter applied") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION}) + public void getProcessTasksWithNonNumericMaxItems() throws Exception + { + restClient.authenticateUser(userWhoStartsProcess) + .withParams("maxItems=A").withWorkflowAPI() + .usingProcess(processWithMultipleTasks).getProcessTasks(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(String.format(RestErrorModel.INVALID_MAXITEMS, "A")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify getProcessTasks with properties parameter") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void getProcessTasksWithPropertiesParameter() throws Exception + { + processTasks = restClient.authenticateUser(adminUser) + .withParams("properties=name,assignee,state").withWorkflowAPI() + .usingProcess(processWithSingleTask).getProcessTasks(); + restClient.assertStatusCodeIs(HttpStatus.OK); + processTasks.assertThat().entriesListCountIs(1); + processTasks.getOneRandomEntry().onModel().assertThat() + .field("dueAt").isNull().and() + .field("processDefinitionId").isNull().and() + .field("processId").isNull().and() + .field("description").isNull().and() + .field("startedAt").isNull().and() + .field("id").isNull().and() + .field("activityDefinitionId").isNull().and() + .field("priority").isNull().and() + .field("formResourceKey").isNull().and() + .field("name").is("Review Task").and() + .field("state").is("claimed").and() + .field("assignee").is(assignee1.getUsername()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify admin gets Process Tasks ordered by assignee ascendant using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void getProcessTasksOrderedByAssignee() throws Exception + { + processTasks = restClient.authenticateUser(adminUser) + .withParams("orderBy=assignee").withWorkflowAPI() + .usingProcess(processWithMultipleTasks).getProcessTasks(); + restClient.assertStatusCodeIs(HttpStatus.OK); + processTasks.assertThat().entriesListIsSortedAscBy("assignee"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify admin doesn't get Process Tasks ordered by many fields") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void getProcessTasksOrderedByMultipleFields() throws Exception + { + restClient.authenticateUser(adminUser) + .withParams("orderBy=assignee,state").withWorkflowAPI() + .usingProcess(processWithMultipleTasks).getProcessTasks(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary("Only one order by parameter is supported"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify get all process tasks after process is deleted.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void getProcessTasksAfterDeletingProcess() throws Exception + { + ProcessModel processModel = dataWorkflow.usingUser(userWhoStartsProcess).usingSite(publicSite).usingResource(document) + .createSingleReviewerTaskAndAssignTo(assignee1); + + restClient.authenticateUser(adminUser).withWorkflowAPI().usingProcess(processModel).deleteProcess(); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + processTasks = restClient.authenticateUser(adminUser).withWorkflowAPI() + .usingProcess(processModel).getProcessTasks(); + restClient.assertStatusCodeIs(HttpStatus.OK); + processTasks.assertThat().entriesListIsEmpty(); + } + +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/tasks/GetProcessTasksSanityTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/tasks/GetProcessTasksSanityTests.java new file mode 100644 index 0000000000..b47c1c0a65 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/tasks/GetProcessTasksSanityTests.java @@ -0,0 +1,86 @@ +package org.alfresco.rest.workflow.processes.tasks; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.exception.JsonToModelConversionException; +import org.alfresco.rest.model.RestTaskModelsCollection; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.ProcessModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Tests for GET "/processes/{processId}/tasks" REST API call + * + * @author Cristina Axinte + */ +public class GetProcessTasksSanityTests extends RestTest +{ + private FileModel document; + private SiteModel siteModel; + private UserModel userModel, assignee1, assignee2, assignee3; + private ProcessModel process; + private RestTaskModelsCollection processTasks; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + userModel = dataUser.createRandomTestUser(); + assignee1 = dataUser.createRandomTestUser(); + assignee2 = dataUser.createRandomTestUser(); + assignee3 = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); + document = dataContent.usingUser(userModel).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + process = dataWorkflow.usingUser(userModel).usingSite(siteModel).usingResource(document) + .createMoreReviewersWorkflowAndAssignTo(assignee1, assignee2, assignee3); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.SANITY, + description = "Verify user who started the process gets all tasks of started process with Rest API and response is successfull (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.SANITY }) + public void userWhoStartedProcessCanGetProcessTasks() throws JsonToModelConversionException, Exception + { + processTasks = restClient.authenticateUser(userModel).withWorkflowAPI().usingProcess(process).getProcessTasks(); + restClient.assertStatusCodeIs(HttpStatus.OK); + processTasks.assertThat() + .entriesListCountIs(3).and() + .entriesListContains("assignee", assignee1.getUsername()).and() + .entriesListContains("assignee", assignee2.getUsername()).and() + .entriesListContains("assignee", assignee3.getUsername()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.SANITY, + description = "Verify any assignee user of the process gets all tasks of the process with Rest API and response is successfull (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.SANITY }) + public void assigneeUserCanGetAllProcessTasks() throws JsonToModelConversionException, Exception + { + processTasks = restClient.authenticateUser(assignee1).withWorkflowAPI().usingProcess(process).getProcessTasks(); + restClient.assertStatusCodeIs(HttpStatus.OK); + processTasks.assertThat() + .entriesListContains("assignee", assignee1.getUsername()).and() + .entriesListContains("assignee", assignee2.getUsername()).and() + .entriesListContains("assignee", assignee3.getUsername()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.SANITY, + description = "Verify any assignee user of the process gets all tasks of the process with Rest API and response is successfull (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.SANITY }) + public void involvedUserCanGetAllProcessTasks() throws JsonToModelConversionException, Exception + { + ProcessModel process = dataWorkflow.usingUser(userModel).usingSite(siteModel).usingResource(document) + .createMoreReviewersWorkflowAndAssignTo(assignee1, assignee2, assignee3); + dataWorkflow.usingUser(assignee1).approveTask(process); + + processTasks = restClient.authenticateUser(assignee2).withWorkflowAPI().usingProcess(process).getProcessTasks(); + restClient.assertStatusCodeIs(HttpStatus.OK); + processTasks.assertThat() + .entriesListIsNotEmpty().assertThat() + .entriesListContains("assignee", userModel.getUsername()); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/AddProcessVariableCoreTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/AddProcessVariableCoreTests.java new file mode 100644 index 0000000000..93e4406708 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/AddProcessVariableCoreTests.java @@ -0,0 +1,188 @@ +package org.alfresco.rest.workflow.processes.variables; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.dataprep.CMISUtil.Priority; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.rest.model.RestProcessVariableModel; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class AddProcessVariableCoreTests extends RestTest +{ + private FileModel document; + private SiteModel siteModel; + private UserModel userWhoStartsProcess, assignee, adminUser, anotherUser; + private RestProcessModel processModel; + private RestProcessVariableModel variableModel, processVariable; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + anotherUser = dataUser.createRandomTestUser(); + userWhoStartsProcess = dataUser.createRandomTestUser(); + assignee = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userWhoStartsProcess).createPublicRandomSite(); + document = dataContent.usingUser(userWhoStartsProcess).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + dataWorkflow.usingUser(userWhoStartsProcess).usingSite(siteModel).usingResource(document).createNewTaskAndAssignTo(assignee); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Add process variable using by the user who started the process.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void addProcessVariableByUserThatStartedTheProcess() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + processModel = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().addProcess("activitiAdhoc", assignee, false, Priority.Normal); + + processVariable = restClient.withWorkflowAPI().usingProcess(processModel).updateProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + processVariable.assertThat().field("name").is(variableModel.getName()) + .and().field("type").is(variableModel.getType()) + .and().field("value").is(variableModel.getValue()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Add process variable using by a random user.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void addProcessVariableByAnyUser() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + processModel = restClient.authenticateUser(anotherUser).withWorkflowAPI().addProcess("activitiAdhoc", anotherUser, false, Priority.Normal); + + processVariable = restClient.withWorkflowAPI().usingProcess(processModel).updateProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + processVariable.assertThat().field("name").is(variableModel.getName()) + .and().field("type").is(variableModel.getType()) + .and().field("value").is(variableModel.getValue()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding process variable is falling in case invalid type is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void failedAddingProcessVariableIfInvalidTypeIsProvided() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:textarea"); + + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + restClient.withWorkflowAPI().usingProcess(processModel).updateProcessVariable(variableModel); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsErrorKey(String.format(RestErrorModel.UNSUPPORTED_TYPE, "d:textarea")) + .containsSummary(String.format(RestErrorModel.UNSUPPORTED_TYPE, "d:textarea")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Bug(id = "REPO-1938") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding process variable is falling in case invalid type prefix is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void failedAddingProcessVariableIfInvalidTypePrefixIsProvided() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("ddt:text"); + + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + restClient.withWorkflowAPI().usingProcess(processModel).updateProcessVariable(variableModel); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsErrorKey(RestErrorModel.API_DEFAULT_ERRORKEY) + .containsSummary(String.format(RestErrorModel.INVALID_NAMEPACE_PREFIX, "ddt")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding process variable is falling in case invalid value is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void failedAddingProcessVariableIfInvalidValueIsProvided() throws Exception + { + RestProcessVariableModel variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:int"); + variableModel.setValue("invalidValue"); + + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + restClient.withWorkflowAPI().usingProcess(processModel).updateProcessVariable(variableModel); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsErrorKey(RestErrorModel.API_DEFAULT_ERRORKEY) + .containsSummary(String.format(RestErrorModel.FOR_INPUT_STRING, "invalidValue")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding process variable is falling in case missing required variable body (name) is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void failedAddingProcessVariableIfMissingRequiredVariableNameBodyIsProvided() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, "{\"value\": \"missingVariableName\",\"type\": \"d:text\"}", + "processes/{processId}/variables/{variableName}", processModel.getId(), variableModel.getName()); + restClient.processModel(RestProcessVariableModel.class, request); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsErrorKey(RestErrorModel.VARIABLE_NAME_REQUIRED) + .containsSummary(RestErrorModel.VARIABLE_NAME_REQUIRED) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding process variable is falling in case invalid variableBody (adding extra parameter in body) is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void failedAddingProcessVariableIfInvalidBodyIsProvided() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, "{\"scope\": \"local\",\"value\": \"testing\",\"type\": \"d:text\"}", + "processes/{processId}/variables/{variableName}", processModel.getId(), variableModel.getName()); + restClient.processModel(RestProcessVariableModel.class, request); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsErrorKey(String.format(RestErrorModel.NO_CONTENT, "Unrecognized field \"scope\"")) + .containsSummary(String.format(RestErrorModel.NO_CONTENT, "Unrecognized field \"scope\"")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding process variable is falling in case empty name is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void failedAddingProcessVariableIfEmptyNameIsProvided() throws Exception + { + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().addProcess("activitiAdhoc", assignee, false, Priority.Normal); + RestProcessVariableModel variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + variableModel.setName(""); + + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + restClient.withWorkflowAPI().usingProcess(processModel).updateProcessVariable(variableModel); + + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED) + .assertLastError() + .containsErrorKey(RestErrorModel.PUT_EMPTY_ARGUMENT) + .containsSummary(RestErrorModel.PUT_EMPTY_ARGUMENT) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/AddProcessVariableFullTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/AddProcessVariableFullTests.java new file mode 100644 index 0000000000..acda02df2c --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/AddProcessVariableFullTests.java @@ -0,0 +1,182 @@ +package org.alfresco.rest.workflow.processes.variables; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.rest.model.RestProcessVariableModel; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class AddProcessVariableFullTests extends RestTest +{ + private FileModel document; + private SiteModel siteModel; + private UserModel userWhoStartsProcess, assignee, adminUser; + private RestProcessModel processModel; + private RestProcessVariableModel variableModel, processVariable, updatedProcessVariable; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + userWhoStartsProcess = dataUser.createRandomTestUser(); + assignee = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userWhoStartsProcess).createPublicRandomSite(); + document = dataContent.usingUser(userWhoStartsProcess).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + dataWorkflow.usingUser(userWhoStartsProcess).usingSite(siteModel).usingResource(document).createNewTaskAndAssignTo(assignee); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify addProcessVariable by any user for invalid processID with REST API and status code is NOT_FOUND (404)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void addProcessVariableWithInvalidProcessId() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + processModel = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + processModel.setId("invalidProcessID"); + + processVariable = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().usingProcess(processModel) + .updateProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "invalidProcessID")); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify addProcessVariable by any user for empty processID with REST API and status code is NOT_FOUND (404)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void addProcessVariableWithEmptyProcessId() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + processModel = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + processModel.setId(""); + + processVariable = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().usingProcess(processModel) + .updateProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding process variable in case of having only 'name' field is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void addingProcessVariableWithOnlyNameProvided() throws Exception + { + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, "{\"name\": \"variableName\"}", + "processes/{processId}/variables/{variableName}", processModel.getId(), "variableName"); + processVariable = restClient.processModel(RestProcessVariableModel.class, request); + + restClient.assertStatusCodeIs(HttpStatus.OK); + processVariable.assertThat().field("name").is("variableName") + .and().field("type").is("d:any") + .and().field("value").isNull(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding process variable in case of missing type field is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void addingProcessVariableIfMissingValueIsProvided() throws Exception + { + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, "{\"name\": \"variableName\", \"type\": \"d:text\"}", + "processes/{processId}/variables/{variableName}", processModel.getId(), "variableName"); + processVariable = restClient.processModel(RestProcessVariableModel.class, request); + + restClient.assertStatusCodeIs(HttpStatus.OK); + processVariable.assertThat().field("name").is("variableName") + .and().field("type").is("d:text") + .and().field("value").isNull(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding process variable in case of missing type field is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void addingProcessVariableIfMissingTypeIsProvided() throws Exception + { + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, "{\"value\": \"variableValue\", \"name\": \"variableName\"}", + "processes/{processId}/variables/{variableName}", processModel.getId(), "variableValue"); + processVariable = restClient.processModel(RestProcessVariableModel.class, request); + + restClient.assertStatusCodeIs(HttpStatus.OK); + processVariable.assertThat().field("name").is("variableName") + .and().field("type").is("d:text") + .and().field("value").is("variableValue"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding process variable is case of empty type value is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void addingProcessVariableIfEmptyTypeIsProvided() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel(""); + + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + processVariable = restClient.withWorkflowAPI().usingProcess(processModel).updateProcessVariable(variableModel); + + restClient.assertStatusCodeIs(HttpStatus.OK); + processVariable.assertThat().field("name").is(variableModel.getName()) + .and().field("type").is("d:text") + .and().field("value").is(variableModel.getValue()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding process variable in case of empty body field is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void addingProcessVariableWithEmptyBodyProvided() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel(""); + + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, "{ }", + "processes/{processId}/variables/{variableName}", processModel.getId(), variableModel.getName()); + processVariable = restClient.processModel(RestProcessVariableModel.class, request); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsErrorKey(RestErrorModel.VARIABLE_NAME_REQUIRED) + .containsSummary(RestErrorModel.VARIABLE_NAME_REQUIRED) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Update twice in a row the same variable.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void updateTwiceInARowSameProcessVariable() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + processModel = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + + processVariable = restClient.withWorkflowAPI().usingProcess(processModel) + .updateProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + processVariable.assertThat().field("name").is(variableModel.getName()) + .and().field("type").is(variableModel.getType()) + .and().field("value").is(variableModel.getValue()); + + restClient.withWorkflowAPI().usingProcess(processModel).getProcessVariables() + .assertThat().entriesListContains("name", variableModel.getName()); + + updatedProcessVariable = restClient.withWorkflowAPI().usingProcess(processModel) + .updateProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + updatedProcessVariable.assertThat().field("name").is(variableModel.getName()) + .and().field("type").is(variableModel.getType()) + .and().field("value").is(variableModel.getValue()); + + restClient.withWorkflowAPI().usingProcess(processModel).getProcessVariables() + .assertThat().entriesListContains("name", variableModel.getName()); + } + +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/AddProcessVariableSanityTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/AddProcessVariableSanityTests.java new file mode 100644 index 0000000000..85d7d234b6 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/AddProcessVariableSanityTests.java @@ -0,0 +1,95 @@ +package org.alfresco.rest.workflow.processes.variables; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.rest.model.RestProcessVariableModel; +import org.alfresco.utility.data.RandomData; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * @author iulia.cojocea + */ +public class AddProcessVariableSanityTests extends RestTest +{ + private FileModel document; + private SiteModel siteModel; + private UserModel userWhoStartsTask, assignee, adminUser; + private RestProcessModel processModel; + private RestProcessVariableModel variableModel, processVariable; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + userWhoStartsTask = dataUser.createRandomTestUser(); + assignee = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userWhoStartsTask).createPublicRandomSite(); + document = dataContent.usingUser(userWhoStartsTask).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(document).createNewTaskAndAssignTo(assignee); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.SANITY, + description = "Create non-existing variable") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.SANITY }) + public void addProcessVariable() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + processModel = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + + processVariable = restClient.withWorkflowAPI().usingProcess(processModel).updateProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + processVariable.assertThat().field("name").is(variableModel.getName()) + .and().field("type").is(variableModel.getType()) + .and().field("value").is(variableModel.getValue()); + + restClient.withWorkflowAPI().usingProcess(processModel).getProcessVariables() + .assertThat().entriesListContains("name", variableModel.getName()); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.SANITY, + description = "Update existing variable") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.SANITY }) + public void updateExistingProcessVariable() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + processModel = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + processVariable = restClient.withWorkflowAPI().usingProcess(processModel).updateProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + processVariable.assertThat().field("name").is(variableModel.getName()) + .and().field("type").is(variableModel.getType()) + .and().field("value").is(variableModel.getValue()); + + String newValue = RandomData.getRandomName("value"); + variableModel.setValue(newValue); + processVariable = restClient.withWorkflowAPI().usingProcess(processModel).updateProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + processVariable.assertThat().field("value").is(newValue); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.SANITY, + description = "Adding process variable is falling in case invalid variableBody is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.SANITY }) + public void failedAddingProcessVariableIfInvalidBodyIsProvided() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("incorrect type"); + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + + restClient.withWorkflowAPI().usingProcess(processModel).updateProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsErrorKey(String.format(RestErrorModel.UNSUPPORTED_TYPE, "incorrect type")) + .containsSummary(String.format(RestErrorModel.UNSUPPORTED_TYPE, "incorrect type")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/AddProcessVariablesCoreTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/AddProcessVariablesCoreTests.java new file mode 100644 index 0000000000..8b81bf7598 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/AddProcessVariablesCoreTests.java @@ -0,0 +1,101 @@ +package org.alfresco.rest.workflow.processes.variables; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.rest.model.RestProcessVariableModel; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class AddProcessVariablesCoreTests extends RestTest +{ + private FileModel document; + private SiteModel siteModel; + private UserModel userWhoStartsProcess, assignee; + private RestProcessModel processModel; + private RestProcessVariableModel variableModel, processVariable, variableModel1; + + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + userWhoStartsProcess = dataUser.createRandomTestUser(); + assignee = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userWhoStartsProcess).createPublicRandomSite(); + document = dataContent.usingUser(userWhoStartsProcess).usingSite(siteModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + dataWorkflow.usingUser(userWhoStartsProcess).usingSite(siteModel).usingResource(document).createNewTaskAndAssignTo(assignee); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify addProcessVariable by any user for invalid processID with REST API and status code is NOT_FOUND (404)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void addProcessVariableForInvalidProcessIdIsNotFound() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + processModel = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + processModel.setId("invalidProcessID"); + + processVariable = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().usingProcess(processModel) + .addProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "invalidProcessID")); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify addProcessVariable by any user for empty processID with REST API and status code is NOT_FOUND (404)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void addProcessVariableForEmptyProcessIdIsEmpty() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + processModel = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + processModel.setId(""); + + processVariable = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().usingProcess(processModel) + .addProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding multiple process variables is falling in case invalid process id is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void addMultipleProcessVariablesInvalidProcessId() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:int"); + variableModel1 = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + + processModel = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + processModel.setId("invalidProcessID"); + + restClient.authenticateUser(assignee).withWorkflowAPI().usingProcess(processModel) + .addProcessVariables(variableModel1, variableModel); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "invalidProcessID")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding multiple process variables is falling in case empty process id is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void addMultipleProcessVariablesEmptyProcessId() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:int"); + variableModel1 = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + processModel = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + processModel.setId(""); + + restClient.authenticateUser(assignee).withWorkflowAPI().usingProcess(processModel) + .addProcessVariables(variableModel1, variableModel); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "")); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/AddProcessVariablesFullTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/AddProcessVariablesFullTests.java new file mode 100644 index 0000000000..c153cef2aa --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/AddProcessVariablesFullTests.java @@ -0,0 +1,385 @@ +package org.alfresco.rest.workflow.processes.variables; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.dataprep.CMISUtil.Priority; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.rest.model.RestProcessVariableCollection; +import org.alfresco.rest.model.RestProcessVariableModel; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.ProcessModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class AddProcessVariablesFullTests extends RestTest +{ + private FileModel document; + private SiteModel siteModel; + private UserModel userWhoStartsProcess, assignee, adminUser; + private ProcessModel processModel; + private RestProcessModel restProcessModel; + private RestProcessVariableModel variableModel, processVariable, variableModel1, variableModel2, variableModel3; + private RestProcessVariableCollection processVariableCollection; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + userWhoStartsProcess = dataUser.createRandomTestUser(); + assignee = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userWhoStartsProcess).createPublicRandomSite(); + document = dataContent.usingUser(userWhoStartsProcess).usingSite(siteModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + processModel = dataWorkflow.usingUser(userWhoStartsProcess).usingSite(siteModel).usingResource(document).createSingleReviewerTaskAndAssignTo(assignee); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Add process variables using by the user involved in the process.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void addProcessVariableByUserInvolvedTheProcess() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + restProcessModel = restClient.authenticateUser(assignee).withWorkflowAPI().getProcesses() + .getProcessModelByProcessDefId(processModel.getId()); + + processVariable = restClient.authenticateUser(assignee).withWorkflowAPI().usingProcess(restProcessModel) + .addProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + processVariable.assertThat().field("name").is(variableModel.getName()) + .and().field("type").is(variableModel.getType()) + .and().field("value").is(variableModel.getValue()); + + restClient.withWorkflowAPI().usingProcess(restProcessModel).getProcessVariables() + .assertThat().entriesListContains("name", variableModel.getName()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Add process variables using by the user involved in the process.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void addMultipleProcessVariableByUserInvolvedTheProcess() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + variableModel1 = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + restProcessModel = restClient.authenticateUser(assignee).withWorkflowAPI().getProcesses() + .getProcessModelByProcessDefId(processModel.getId()); + + processVariableCollection = restClient.authenticateUser(assignee).withWorkflowAPI().usingProcess(restProcessModel) + .addProcessVariables(variableModel, variableModel1); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + processVariableCollection.getEntries().get(0).onModel() + .assertThat().field("name").is(variableModel.getName()) + .and().field("type").is(variableModel.getType()) + .and().field("value").is(variableModel.getValue()); + + processVariableCollection.getEntries().get(1).onModel() + .assertThat().field("name").is(variableModel1.getName()) + .and().field("type").is(variableModel1.getType()) + .and().field("value").is(variableModel1.getValue()); + + restClient.withWorkflowAPI().usingProcess(restProcessModel).getProcessVariables() + .assertThat().entriesListContains("name", variableModel.getName()) + .assertThat().entriesListContains("name", variableModel1.getName()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Add process variables using by inexistent user.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void addProcessVariableByInexistentUser() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + restProcessModel = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().getProcesses() + .getProcessModelByProcessDefId(processModel.getId()); + + processVariable = restClient.authenticateUser(UserModel.getRandomUserModel()).withWorkflowAPI() + .usingProcess(restProcessModel) + .addProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Add multiple process variables using by inexistent user.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void addMultipleProcessVariableByInexistentUser() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + variableModel1 = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + restProcessModel = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().getProcesses() + .getProcessModelByProcessDefId(processModel.getId()); + + processVariableCollection = restClient.authenticateUser(UserModel.getRandomUserModel()).withWorkflowAPI() + .usingProcess(restProcessModel) + .addProcessVariables(variableModel,variableModel1); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding process variables is falling in case invalid type is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void failedAddingProcessVariableIfInvalidTypeIsProvided() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:textarea"); + restProcessModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses() + .getProcessModelByProcessDefId(processModel.getId()); + + restClient.withWorkflowAPI().usingProcess(restProcessModel).addProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary( + String.format(RestErrorModel.UNSUPPORTED_TYPE, "d:textarea")) + .containsErrorKey(String.format(RestErrorModel.UNSUPPORTED_TYPE, "d:textarea")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Bug(id = "REPO-1938") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding process variables is falling in case invalid type prefix is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void failedAddingProcessVariableIfInvalidTypePrefixIsProvided() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("ddt:text"); + restProcessModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses() + .getProcessModelByProcessDefId(processModel.getId()); + + restClient.withWorkflowAPI().usingProcess(restProcessModel).addProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsSummary(String.format(RestErrorModel.INVALID_NAMEPACE_PREFIX, "ddt")) + .containsErrorKey(RestErrorModel.API_DEFAULT_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding process variables is falling in case invalid value is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void failedAddingProcessVariableIfInvalidValueIsProvided() throws Exception + { + RestProcessVariableModel variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:int"); + variableModel.setValue("invalidValue"); + restProcessModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses() + .getProcessModelByProcessDefId(processModel.getId()); + + restClient.withWorkflowAPI().usingProcess(restProcessModel).addProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsErrorKey(RestErrorModel.API_DEFAULT_ERRORKEY) + .containsSummary(String.format(RestErrorModel.FOR_INPUT_STRING, "invalidValue")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding process variables is falling in case invalid variableBody (adding extra parameter in body:scope) is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void failedAddingProcessVariableIfInvalidBodyIsProvided() throws Exception + { + restProcessModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses() + .getProcessModelByProcessDefId(processModel.getId()); + + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, "{\"name\": \"variableName\",\"scope\": \"local\",\"value\": \"testing\",\"type\": \"d:text\"}", + "processes/{processId}/variables", processModel.getId()); + restClient.processModel(RestProcessVariableModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsSummary(String.format(RestErrorModel.NO_CONTENT, "Unrecognized field \"scope\"")) + .containsErrorKey(String.format(RestErrorModel.NO_CONTENT, "Unrecognized field \"scope\"")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + //@Bug(id="REPO-1985") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding process variables is falling in case empty name is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void failedAddingProcessVariableIfEmptyNameIsProvided() throws Exception + { + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().addProcess("activitiAdhoc", assignee, false, Priority.Normal); + restProcessModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses() + .getProcessModelByProcessDefId(processModel.getId()); + RestProcessVariableModel variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + variableModel.setName(""); + + restClient.withWorkflowAPI().usingProcess(restProcessModel).addProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsSummary(RestErrorModel.VARIABLE_NAME_REQUIRED) + .containsErrorKey(RestErrorModel.VARIABLE_NAME_REQUIRED) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + //@Bug(id="REPO-1985") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding process variables is falling in case invalid name is provided: ony white spaces") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void failedAddingProcessVariableUsingOnlyWhiteSpaceInName() throws Exception + { + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().addProcess("activitiAdhoc", assignee, false, Priority.Normal); + restProcessModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses() + .getProcessModelByProcessDefId(processModel.getId()); + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + variableModel.setName(" "); + + processVariable = restClient.withWorkflowAPI().usingProcess(restProcessModel).addProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + processVariable.assertThat().field("name").isNull() + .and().field("type").is(variableModel.getType()) + .and().field("value").is(variableModel.getValue()); + + restClient.withWorkflowAPI().usingProcess(restProcessModel).getProcessVariables() + .assertThat().entriesListContains("value", variableModel.getValue()); + } + + @Bug(id="REPO-1987") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding process variables is falling in case invalid name is provided: symbols") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void failedAddingProcessVariableWithSymbolsInName() throws Exception + { + restProcessModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses() + .getProcessModelByProcessDefId(processModel.getId()); + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + variableModel.setName("123_%^&: õÈ,Ì,Ò"); + + processVariable = restClient.withWorkflowAPI().usingProcess(restProcessModel).addProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + processVariable.assertThat().field("name").is(variableModel.getName()) + .and().field("type").is(variableModel.getType()) + .and().field("value").is(variableModel.getValue()); + + restClient.withWorkflowAPI().usingProcess(restProcessModel).getProcessVariables() + .assertThat().entriesListContains("name", variableModel.getName()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Add two process variables using by the user involved in the process.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void addingMultipleValidProcessVariables() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + variableModel2 = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + variableModel3 = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + restProcessModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses() + .getProcessModelByProcessDefId(processModel.getId()); + + processVariableCollection = restClient.authenticateUser(assignee).withWorkflowAPI().usingProcess(restProcessModel) + .addProcessVariables(variableModel, variableModel2, variableModel3); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + processVariableCollection.assertThat().entriesListContains("name", variableModel.getName()) + .assertThat().entriesListContains("name", variableModel2.getName()) + .assertThat().entriesListContains("name", variableModel3.getName()); + + processVariableCollection.getEntries().get(0).onModel().assertThat() + .field("name").is(variableModel.getName()).and() + .field("value").is(variableModel.getValue()).and() + .field("type").is(variableModel.getType()); + processVariableCollection.getEntries().get(1).onModel().assertThat() + .field("name").is(variableModel2.getName()).and() + .field("value").is(variableModel2.getValue()).and() + .field("type").is(variableModel2.getType()); + processVariableCollection.getEntries().get(2).onModel().assertThat() + .field("name").is(variableModel3.getName()).and() + .field("value").is(variableModel3.getValue()).and() + .field("type").is(variableModel3.getType()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Add two process variables using by the user involved in the process.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void failedAddingMultipleProcessVariablesInvalidType() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + variableModel.setType("d:string"); + variableModel2 = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + restProcessModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses() + .getProcessModelByProcessDefId(processModel.getId()); + + processVariableCollection = restClient.authenticateUser(assignee).withWorkflowAPI().usingProcess(restProcessModel) + .addProcessVariables(variableModel, variableModel2); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.UNSUPPORTED_TYPE, "d:string")) + .containsErrorKey(String.format(RestErrorModel.UNSUPPORTED_TYPE, "d:string")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Bug(id = "REPO-1938") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Add two process variables using by the user involved in the process.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void failledAddingMultipleProcessVariablesInvalidTypePrefix() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + variableModel.setType("e:text"); + variableModel2 = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + restProcessModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses() + .getProcessModelByProcessDefId(processModel.getId()); + + processVariableCollection = restClient.authenticateUser(assignee).withWorkflowAPI().usingProcess(restProcessModel) + .addProcessVariables(variableModel, variableModel2); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsSummary(String.format(RestErrorModel.INVALID_NAMEPACE_PREFIX, "e")) + .containsErrorKey(RestErrorModel.API_DEFAULT_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding process variables is falling in case invalid value is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void failledAddingMultipleProcessVariablesInvalidValue() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:int"); + variableModel.setValue("invalidValue"); + variableModel1 = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + variableModel2 = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + restProcessModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses() + .getProcessModelByProcessDefId(processModel.getId()); + + processVariableCollection = restClient.authenticateUser(assignee).withWorkflowAPI().usingProcess(restProcessModel) + .addProcessVariables(variableModel, variableModel1, variableModel2); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsErrorKey(RestErrorModel.API_DEFAULT_ERRORKEY) + .containsSummary(String.format(RestErrorModel.FOR_INPUT_STRING, "invalidValue")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding process variables is falling in case invalid value is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void failledAddingMultipleInvalidProcessVariables() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:int"); + variableModel.setValue("invalidValue"); + variableModel1 = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + variableModel1.setType(""); + restProcessModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses() + .getProcessModelByProcessDefId(processModel.getId()); + + processVariableCollection = restClient.authenticateUser(assignee).withWorkflowAPI().usingProcess(restProcessModel) + .addProcessVariables(variableModel1, variableModel); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsErrorKey(RestErrorModel.API_DEFAULT_ERRORKEY) + .containsSummary(String.format(RestErrorModel.FOR_INPUT_STRING, "invalidValue")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/AddProcessVariablesSanityTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/AddProcessVariablesSanityTests.java new file mode 100644 index 0000000000..97b90696b4 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/AddProcessVariablesSanityTests.java @@ -0,0 +1,158 @@ +package org.alfresco.rest.workflow.processes.variables; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.rest.model.RestProcessVariableCollection; +import org.alfresco.rest.model.RestProcessVariableModel; +import org.alfresco.utility.data.RandomData; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class AddProcessVariablesSanityTests extends RestTest +{ + private FileModel document; + private SiteModel siteModel; + private UserModel userWhoStartsProcess, assignee, adminUser; + private RestProcessModel processModel; + private RestProcessVariableModel variableModel, variableModel1, variableModel2, processVariable; + private RestProcessVariableCollection processVariableCollection; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + userWhoStartsProcess = dataUser.createRandomTestUser(); + assignee = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userWhoStartsProcess).createPublicRandomSite(); + document = dataContent.usingUser(userWhoStartsProcess).usingSite(siteModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + dataWorkflow.usingUser(userWhoStartsProcess).usingSite(siteModel).usingResource(document).createNewTaskAndAssignTo(assignee); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.SANITY, + description = "Create non-existing variable") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.SANITY }) + public void addProcessVariable() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + processModel = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + + processVariable = restClient.withWorkflowAPI().usingProcess(processModel).addProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + processVariable.assertThat().field("name").is(variableModel.getName()) + .and().field("type").is(variableModel.getType()) + .and().field("value").is(variableModel.getValue()); + + restClient.withWorkflowAPI().usingProcess(processModel).getProcessVariables() + .assertThat().entriesListContains("name", variableModel.getName()); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.SANITY, + description = "Create non-existing variable") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.SANITY }) + public void addMultipleProcessVariable() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + variableModel1 = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + variableModel2 = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + processModel = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + + processVariableCollection = restClient.withWorkflowAPI().usingProcess(processModel) + .addProcessVariables(variableModel, variableModel1, variableModel2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + processVariableCollection.getEntries().get(0).onModel() + .assertThat().field("name").is( variableModel.getName()) + .and().field("type").is( variableModel.getType()) + .and().field("value").is( variableModel.getValue()); + + processVariableCollection.getEntries().get(1).onModel() + .assertThat().field("name").is(variableModel1.getName()) + .and().field("type").is(variableModel1.getType()) + .and().field("value").is(variableModel1.getValue()); + + processVariableCollection.getEntries().get(2).onModel() + .assertThat().field("name").is(variableModel2.getName()) + .and().field("type").is(variableModel2.getType()) + .and().field("value").is(variableModel2.getValue()); + + restClient.withWorkflowAPI().usingProcess(processModel).getProcessVariables() + .assertThat().entriesListContains("name", variableModel.getName()) + .assertThat().entriesListContains("name", variableModel1.getName()) + .assertThat().entriesListContains("name", variableModel2.getName()); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.SANITY, + description = "Update existing variables") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.SANITY }) + public void updateExistingProcessVariable() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + processModel = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + + processVariable = restClient.withWorkflowAPI().usingProcess(processModel).addProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + processVariable.assertThat().field("name").is(variableModel.getName()) + .and().field("type").is(variableModel.getType()) + .and().field("value").is(variableModel.getValue()); + + String newValue = RandomData.getRandomName("value"); + variableModel.setValue(newValue); + processVariable = restClient.withWorkflowAPI().usingProcess(processModel).addProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + processVariable.assertThat().field("value").is(newValue); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.SANITY, + description = "Update existing variables") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.SANITY }) + public void updateExistingMultipleProcessVariable() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + variableModel1 = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + processModel = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + + processVariableCollection = restClient.withWorkflowAPI().usingProcess(processModel) + .addProcessVariables(variableModel, variableModel1); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + processVariableCollection.getEntries().get(0).onModel() + .assertThat().field("name").is(variableModel.getName()) + .and().field("type").is(variableModel.getType()) + .and().field("value").is(variableModel.getValue()); + + processVariableCollection.getEntries().get(1).onModel() + .assertThat().field("name").is(variableModel1.getName()) + .and().field("type").is(variableModel1.getType()) + .and().field("value").is(variableModel1.getValue()); + + String newValueVar = RandomData.getRandomName("valueVar"); + variableModel.setValue(newValueVar); + String newValueVar1 = RandomData.getRandomName("valueVar1"); + variableModel1.setValue(newValueVar1); + + processVariableCollection = restClient.withWorkflowAPI().usingProcess(processModel).addProcessVariables(variableModel, variableModel1); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + processVariableCollection.getEntries().get(0).onModel().assertThat().field("value").is(newValueVar); + processVariableCollection.getEntries().get(1).onModel().assertThat().field("value").is(newValueVar1); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.SANITY, + description = "Adding process variables is falling in case invalid variableBody is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.SANITY }) + public void failedAddingProcessVariableIfInvalidBodyIsProvided() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("incorrect type"); + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + + restClient.withWorkflowAPI().usingProcess(processModel).addProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary("Unsupported type of variable: 'incorrect type'."); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/DeleteProcessVariableCoreTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/DeleteProcessVariableCoreTests.java new file mode 100644 index 0000000000..68cbe1faaa --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/DeleteProcessVariableCoreTests.java @@ -0,0 +1,118 @@ +package org.alfresco.rest.workflow.processes.variables; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.exception.JsonToModelConversionException; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.rest.model.RestProcessVariableModel; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.ProcessModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * + * @author bogdan.bocancea + * + */ +public class DeleteProcessVariableCoreTests extends RestTest +{ + private FileModel document; + private SiteModel siteModel; + private UserModel userWhoStartsTask, assignee, adminUser; + private RestProcessModel restProcessModel; + private ProcessModel processModel; + private RestProcessVariableModel variableModel; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + userWhoStartsTask = dataUser.createRandomTestUser(); + assignee = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userWhoStartsTask).createPublicRandomSite(); + document = dataContent.usingUser(userWhoStartsTask).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + processModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(document) + .createSingleReviewerTaskAndAssignTo(assignee); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Delete invalid process variable") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void deleteInvalidProcessVariable() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("x:InvalidVar"); + restProcessModel = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI() + .getProcesses().getProcessModelByProcessDefId(processModel.getId()); + restClient.withWorkflowAPI().usingProcess(restProcessModel).deleteProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, variableModel.getName())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Delete process variable twice") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void deleteProcessVariableTwice() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + restProcessModel = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI() + .getProcesses().getProcessModelByProcessDefId(processModel.getId()); + restClient.withWorkflowAPI().usingProcess(restProcessModel).addProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.withWorkflowAPI().usingProcess(restProcessModel).deleteProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withWorkflowAPI().usingProcess(restProcessModel).deleteProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, variableModel.getName())); + } + + @TestRail(section = {TestGroup.REST_API,TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Remove process variables with empty processId") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void deleteProcessVariableEmptyProcessId() throws JsonToModelConversionException, Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + restProcessModel = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI() + .getProcesses().getProcessModelByProcessDefId(processModel.getId()); + restClient.withWorkflowAPI().usingProcess(restProcessModel).addProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restProcessModel.setId(""); + restClient.withWorkflowAPI().usingProcess(restProcessModel).deleteProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "")) + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Delete process variable with admin.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void deleteProcessVariableWithAdmin() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + restProcessModel = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI() + .getProcesses().getProcessModelByProcessDefId(processModel.getId()); + restClient.withWorkflowAPI().usingProcess(restProcessModel).addProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.authenticateUser(adminUser).withWorkflowAPI().usingProcess(processModel) + .deleteProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withWorkflowAPI().usingProcess(processModel).getProcessVariables() + .assertThat().entriesListDoesNotContain("name", variableModel.getName()); + } + +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/DeleteProcessVariableFullTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/DeleteProcessVariableFullTests.java new file mode 100644 index 0000000000..3f9f3eafbe --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/DeleteProcessVariableFullTests.java @@ -0,0 +1,191 @@ +package org.alfresco.rest.workflow.processes.variables; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.dataprep.CMISUtil.Priority; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.rest.model.RestProcessVariableModel; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.ProcessModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class DeleteProcessVariableFullTests extends RestTest +{ + private FileModel document; + private SiteModel siteModel; + private UserModel userWhoStartsTask, assignee; + private RestProcessModel restProcessModel; + private ProcessModel processModel; + private RestProcessVariableModel variableModel; + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + userWhoStartsTask = dataUser.createRandomTestUser(); + assignee = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userWhoStartsTask).createPublicRandomSite(); + document = dataContent.usingUser(userWhoStartsTask).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + processModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(document).createSingleReviewerTaskAndAssignTo(assignee); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Delete empty process variable") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void deleteEmptyProcessVariable() throws Exception + { + variableModel = new RestProcessVariableModel("", "", "bpm:workflowPackage"); + restProcessModel = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI().getProcesses() + .getProcessModelByProcessDefId(processModel.getId()); + + restClient.withWorkflowAPI().usingProcess(restProcessModel) + .deleteProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED) + .assertLastError() + .containsSummary(RestErrorModel.DELETE_EMPTY_ARGUMENT) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .containsErrorKey(RestErrorModel.DELETE_EMPTY_ARGUMENT) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Delete process then delete process variables, status OK should be returned") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void deleteProcessVariablesForADeletedProcess() throws Exception + { + UserModel userWhoStartsTask = dataUser.createRandomTestUser(); + UserModel assignee = dataUser.createRandomTestUser(); + + RestProcessModel processModel = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI() + .addProcess("activitiAdhoc", assignee, false, Priority.Normal); + + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + restProcessModel = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI() + .getProcesses().getProcessModelByProcessDefId(processModel.getId()); + restClient.withWorkflowAPI().usingProcess(restProcessModel).addProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI().usingProcess(processModel) + .deleteProcess(); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + restClient.withWorkflowAPI().usingProcess(processModel).deleteProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, processModel.getId())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Delete process variable using by the user who started the process.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void deleteProcessVariableByUserThatStartedTheProcess() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + processModel = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI() + .addProcess("activitiAdhoc", assignee, false, Priority.Normal); + + restProcessModel = restClient.withWorkflowAPI().getProcesses() + .getProcessModelByProcessDefId(processModel.getId()); + restClient.withWorkflowAPI().usingProcess(restProcessModel).addProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.withWorkflowAPI().usingProcess(processModel) + .deleteProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withWorkflowAPI().usingProcess(processModel).getProcessVariables() + .assertThat() + .entriesListDoesNotContain("name", variableModel.getName()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Delete process variable using by the user involved in the process.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void deleteProcessVariableByUserInvolvedInTheProcess() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + processModel = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI() + .addProcess("activitiAdhoc", assignee, false, Priority.Normal); + + restProcessModel = restClient.withWorkflowAPI().getProcesses() + .getProcessModelByProcessDefId(processModel.getId()); + restClient.withWorkflowAPI().usingProcess(restProcessModel).addProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.authenticateUser(assignee).withWorkflowAPI().usingProcess(processModel) + .deleteProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withWorkflowAPI().usingProcess(processModel).getProcessVariables() + .assertThat() + .entriesListDoesNotContain("name", variableModel.getName()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Delete process variable with invalid type") + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void deleteProcessVariableInvalidType() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + restProcessModel = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI() + .getProcesses().getProcessModelByProcessDefId(processModel.getId()); + restClient.withWorkflowAPI().usingProcess(restProcessModel).addProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + variableModel.setType("invalid-type"); + restClient.withWorkflowAPI().usingProcess(restProcessModel).deleteProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withWorkflowAPI().usingProcess(processModel).getProcessVariables() + .assertThat() + .entriesListDoesNotContain("name", variableModel.getName()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Delete process variable by non assigned user") + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void deleteProcessVarialbleByNonAssignedUser() throws Exception + { + UserModel nonAssigned = dataUser.createRandomTestUser(); + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + restProcessModel = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI() + .getProcesses().getProcessModelByProcessDefId(processModel.getId()); + restClient.withWorkflowAPI().usingProcess(restProcessModel).addProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.authenticateUser(nonAssigned).withWorkflowAPI().usingProcess(restProcessModel) + .deleteProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError() + .containsSummary(String.format(RestErrorModel.ACCESS_INFORMATION_NOT_ALLOWED, processModel.getId())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .containsErrorKey(String.format(RestErrorModel.ACCESS_INFORMATION_NOT_ALLOWED, processModel.getId())) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Delete process variable by inexistent user") + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void deleteProcessVarialbleByInexistentUser() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + processModel = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI() + .addProcess("activitiAdhoc", userWhoStartsTask, false, Priority.Normal); + restProcessModel = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI() + .getProcesses().getProcessModelByProcessDefId(processModel.getId()); + restClient.withWorkflowAPI().usingProcess(restProcessModel).addProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.authenticateUser(UserModel.getRandomUserModel()).withWorkflowAPI() + .usingProcess(restProcessModel) + .deleteProcessVariable(variableModel); + + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/DeleteProcessVariableSanityTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/DeleteProcessVariableSanityTests.java new file mode 100644 index 0000000000..a6f9ec0169 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/DeleteProcessVariableSanityTests.java @@ -0,0 +1,69 @@ +package org.alfresco.rest.workflow.processes.variables; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.dataprep.CMISUtil.Priority; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.rest.model.RestProcessVariableModel; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * @author iulia.cojocea + */ +public class DeleteProcessVariableSanityTests extends RestTest +{ + private FileModel document; + private SiteModel siteModel; + private UserModel userWhoStartsTask, assignee, adminUser; + private RestProcessModel processModel; + private RestProcessVariableModel variableModel; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + userWhoStartsTask = dataUser.createRandomTestUser(); + assignee = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userWhoStartsTask).createPublicRandomSite(); + document = dataContent.usingUser(userWhoStartsTask).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(document).createNewTaskAndAssignTo(assignee); + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().addProcess("activitiAdhoc", adminUser, false, Priority.Normal); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.SANITY, + description = "Delete existing variable") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.SANITY }) + public void deleteProcessVariable() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + restClient.withWorkflowAPI().usingProcess(processModel).addProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.withWorkflowAPI().usingProcess(processModel).deleteProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withWorkflowAPI().usingProcess(processModel).getProcessVariables() + .assertThat().entriesListDoesNotContain("name", variableModel.getName()); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.SANITY, + description = "Try to delete existing variable using invalid processId") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.SANITY }) + public void deleteProcessVariableUsingInvalidProcessId() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + restClient.withWorkflowAPI().usingProcess(processModel).addProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + processModel.setId("incorrectProcessId"); + restClient.withWorkflowAPI().usingProcess(processModel).deleteProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "incorrectProcessId")); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/GetProcessVariablesCoreTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/GetProcessVariablesCoreTests.java new file mode 100644 index 0000000000..9258cf63d1 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/GetProcessVariablesCoreTests.java @@ -0,0 +1,88 @@ +package org.alfresco.rest.workflow.processes.variables; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.dataprep.CMISUtil.Priority; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.rest.model.RestProcessModelsCollection; +import org.alfresco.rest.model.RestProcessVariableCollection; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.commons.lang3.RandomStringUtils; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class GetProcessVariablesCoreTests extends RestTest +{ + private FileModel document; + private SiteModel siteModel; + private UserModel userWhoStartsTask, assignee, admin; + private RestProcessModel processModel; + private RestProcessVariableCollection variables; + + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + admin = dataUser.getAdminUser(); + userWhoStartsTask = dataUser.createRandomTestUser(); + assignee = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userWhoStartsTask).createPublicRandomSite(); + document = dataContent.usingUser(userWhoStartsTask).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(document).createNewTaskAndAssignTo(assignee); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Get process variables using invalid process ID") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void getProcessVariablesUsingInvalidProcessId() throws Exception + { + restClient.authenticateUser(userWhoStartsTask).withParams("maxItems=2").withWorkflowAPI().addProcess("activitiAdhoc", assignee, false, Priority.Normal); + RestProcessModelsCollection processes = restClient.authenticateUser(userWhoStartsTask).withParams("maxItems=2").withWorkflowAPI().getProcesses(); + processModel = processes.assertThat().entriesListIsNotEmpty().when().getOneRandomEntry().onModel(); + + String id = RandomStringUtils.randomAlphanumeric(10); + processModel.setId(id); + variables = restClient.withParams("maxItems=2").withWorkflowAPI().usingProcess(processModel).getProcessVariables(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, id)) + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Get process variables using empty process ID") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void getProcessVariablesUsingEmptyProcessId() throws Exception + { + processModel = restClient.authenticateUser(userWhoStartsTask).withParams("maxItems=2").withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + processModel.setId(""); + variables = restClient.withWorkflowAPI().usingProcess(processModel).getProcessVariables(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "")); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Delete process then get process variables, status OK should be returned") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void getProcessVariablesForADeletedProcess() throws Exception + { + UserModel userWhoStartsTask = dataUser.createRandomTestUser(); + UserModel assignee = dataUser.createRandomTestUser(); + + RestProcessModel processModel = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI().addProcess("activitiAdhoc", assignee, false, Priority.Normal); + + restClient.authenticateUser(admin).withWorkflowAPI().usingProcess(processModel).deleteProcess(); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + RestProcessVariableCollection variables = restClient.withWorkflowAPI().usingProcess(processModel).getProcessVariables(); + restClient.assertStatusCodeIs(HttpStatus.OK); + variables.assertThat().entriesListIsNotEmpty(); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/GetProcessVariablesFullTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/GetProcessVariablesFullTests.java new file mode 100644 index 0000000000..e7c841cd3c --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/GetProcessVariablesFullTests.java @@ -0,0 +1,161 @@ +package org.alfresco.rest.workflow.processes.variables; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.rest.model.RestProcessVariableCollection; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 2/2/2017. + */ +public class GetProcessVariablesFullTests extends RestTest +{ + private UserModel userWhoStartsProcess, assignee, admin; + private RestProcessModel processModel; + private RestProcessVariableCollection variables; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + admin = dataUser.getAdminUser(); + userWhoStartsProcess = dataUser.createRandomTestUser(); + assignee = dataUser.createRandomTestUser(); + processModel = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().addProcess("activitiAdhoc", assignee, false, CMISUtil.Priority.Normal); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify get all process variables call using admin user. Admin can see the process even if he isn't involved in it.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void getProcessVariablesUsingAdmin() throws Exception + { + variables = restClient.authenticateUser(admin).withWorkflowAPI().usingProcess(processModel).getProcessVariables(); + restClient.assertStatusCodeIs(HttpStatus.OK); + variables.assertThat().entriesListIsNotEmpty(); + variables.getProcessVariableByName("initiator") + .assertThat().field("name").is("initiator") + .assertThat().field("type").is("d:noderef") + .assertThat().field("value").is(userWhoStartsProcess.getUsername()); + variables.getProcessVariableByName("bpm_assignee") + .assertThat().field("name").is("bpm_assignee") + .assertThat().field("type").is("cm:person") + .assertThat().field("value").is(assignee.getUsername()); + variables.getProcessVariableByName("bpm_sendEMailNotifications") + .assertThat().field("name").is("bpm_sendEMailNotifications") + .assertThat().field("type").is("d:boolean") + .assertThat().field("value").is(false); + variables.getProcessVariableByName("bpm_priority") + .assertThat().field("name").is("bpm_priority") + .assertThat().field("type").is("d:int") + .assertThat().field("value").is(CMISUtil.Priority.Normal.getLevel()); + } + + @Bug(id = "MNT-17438") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify get all process variables with valid skip count parameter applied.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void getProcessVariablesWithValidSkipCount() throws Exception + { + variables = restClient.authenticateUser(admin).withWorkflowAPI().usingProcess(processModel).getProcessVariables(); + restClient.assertStatusCodeIs(HttpStatus.OK); + variables.assertThat().entriesListIsNotEmpty(); + + RestProcessVariableCollection variablesSkipped = restClient.authenticateUser(admin).withParams("skipCount=2").withWorkflowAPI().usingProcess(processModel).getProcessVariables(); + restClient.assertStatusCodeIs(HttpStatus.OK); + variablesSkipped + .assertThat().entriesListDoesNotContain("name", variables.getEntries().get(0).onModel().getName()) + .assertThat().entriesListDoesNotContain("name", variables.getEntries().get(1).onModel().getName()) + .assertThat().entriesListCountIs(variables.getEntries().size()-2) + .assertThat().paginationField("skipCount").is("2"); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify get all process variables with negative skip count parameter applied.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void getProcessVariablesWithNegativeSkipCount() throws Exception + { + restClient.authenticateUser(admin).withParams("skipCount=-2").withWorkflowAPI().usingProcess(processModel).getProcessVariables(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(RestErrorModel.NEGATIVE_VALUES_SKIPCOUNT) + .containsErrorKey(RestErrorModel.NEGATIVE_VALUES_SKIPCOUNT) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE) + .statusCodeIs(HttpStatus.BAD_REQUEST); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify get all process variables with not numeric skip count parameter applied.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void getProcessVariablesWithNonNumericSkipCount() throws Exception + { + restClient.authenticateUser(admin).withParams("skipCount=A").withWorkflowAPI().usingProcess(processModel).getProcessVariables(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(String.format(RestErrorModel.INVALID_SKIPCOUNT, "A")); + } + + @Bug(id = "MNT-17438") + @TestRail(section = { TestGroup.REST_API,TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify get all process variables with valid maxItems parameter applied.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void getProcessVariablesWithValidMaxItems() throws Exception + { + variables = restClient.authenticateUser(admin).withWorkflowAPI().usingProcess(processModel).getProcessVariables(); + restClient.assertStatusCodeIs(HttpStatus.OK); + variables.assertThat().entriesListIsNotEmpty(); + + RestProcessVariableCollection variablesSkipped = restClient.authenticateUser(admin).withParams("maxItems=2").withWorkflowAPI().usingProcess(processModel).getProcessVariables(); + restClient.assertStatusCodeIs(HttpStatus.OK); + variablesSkipped + .assertThat().entriesListContains("name", variables.getEntries().get(0).onModel().getName()) + .assertThat().entriesListContains("name", variables.getEntries().get(1).onModel().getName()) + .assertThat().entriesListCountIs(2) + .assertThat().paginationField("maxItems").is("2"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify get all process variables with negative maxItems parameter applied.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void getProcessVariablesWithNegativeMaxItems() throws Exception + { + restClient.authenticateUser(admin).withParams("maxItems=-2").withWorkflowAPI().usingProcess(processModel).getProcessVariables(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS) + .containsErrorKey(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE) + .statusCodeIs(HttpStatus.BAD_REQUEST); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify get all process variables with not numeric maxItems parameter applied.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void getProcessVariablesWithNonNumericMaxItems() throws Exception + { + restClient.authenticateUser(admin).withParams("maxItems=A").withWorkflowAPI().usingProcess(processModel).getProcessVariables(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(String.format(RestErrorModel.INVALID_MAXITEMS, "A")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify get all process variables with properties parameter.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void getProcessVariablesWithPropertiesParameter() throws Exception + { + variables = restClient.authenticateUser(admin).withParams("properties=name").withWorkflowAPI().usingProcess(processModel).getProcessVariables(); + restClient.assertStatusCodeIs(HttpStatus.OK); + variables.assertThat().entriesListIsNotEmpty(); + variables.getProcessVariableByName("initiator") + .assertThat().field("name").is("initiator") + .assertThat().field("type").isNull() + .assertThat().field("value").isNull() + .assertThat().fieldsCount().is(1); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/GetProcessVariablesSanityTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/GetProcessVariablesSanityTests.java new file mode 100644 index 0000000000..31fe133cca --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/GetProcessVariablesSanityTests.java @@ -0,0 +1,60 @@ +package org.alfresco.rest.workflow.processes.variables; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.exception.JsonToModelConversionException; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.rest.model.RestProcessVariableCollection; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * @author iulia.cojocea + */ +public class GetProcessVariablesSanityTests extends RestTest +{ + private FileModel document; + private SiteModel siteModel; + private UserModel userWhoStartsTask, assignee; + private RestProcessModel processModel; + private RestProcessVariableCollection variables; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + userWhoStartsTask = dataUser.createRandomTestUser(); + assignee = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userWhoStartsTask).createPublicRandomSite(); + document = dataContent.usingUser(userWhoStartsTask).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(document).createNewTaskAndAssignTo(assignee); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.SANITY, + description = "Verify that user that started the process gets all process variables") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.SANITY }) + public void getProcessVariablesUsingTheUserWhoStartedProcess() throws JsonToModelConversionException, Exception + { + processModel = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + variables = restClient.withWorkflowAPI().usingProcess(processModel).getProcessVariables(); + restClient.assertStatusCodeIs(HttpStatus.OK); + variables.assertThat().entriesListIsNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.SANITY, + description = "Verify get all process variables call using a user that is involved in the process") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.SANITY }) + public void getProcessVariablesUsingUserInvolvedInProcess() throws JsonToModelConversionException, Exception + { + processModel = restClient.authenticateUser(assignee).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + variables = restClient.withWorkflowAPI().usingProcess(processModel).getProcessVariables(); + restClient.assertStatusCodeIs(HttpStatus.OK); + variables.assertThat().entriesListIsNotEmpty(); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/UpdateProcessVariableTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/UpdateProcessVariableTests.java new file mode 100644 index 0000000000..5f71fb067d --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/processes/variables/UpdateProcessVariableTests.java @@ -0,0 +1,139 @@ +package org.alfresco.rest.workflow.processes.variables; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.rest.model.RestProcessVariableModel; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + + +public class UpdateProcessVariableTests extends RestTest +{ + private FileModel document; + private SiteModel siteModel; + private UserModel userWhoStartsProcess, assignee; + private RestProcessModel processModel; + private RestProcessVariableModel variableModel, updatedVariable; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + userWhoStartsProcess = dataUser.createRandomTestUser(); + assignee = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userWhoStartsProcess).createPublicRandomSite(); + document = dataContent.usingUser(userWhoStartsProcess).usingSite(siteModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + dataWorkflow.usingUser(userWhoStartsProcess).usingSite(siteModel).usingResource(document).createNewTaskAndAssignTo(assignee); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Update existing variable using PUT call - invalid type") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void updateProcessVariableInvalidType() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + processModel = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + restClient.withWorkflowAPI().usingProcess(processModel).addProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + variableModel.setType("dd"); + + updatedVariable = restClient.withWorkflowAPI().usingProcess(processModel).updateProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsErrorKey(String.format(RestErrorModel.UNSUPPORTED_TYPE, "dd")) + .containsSummary(String.format(RestErrorModel.UNSUPPORTED_TYPE, "dd")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Update existing variable using PUT call - invalid type") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void updateProcessVariableTwoUsers() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:any"); + processModel = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + restClient.withWorkflowAPI().usingProcess(processModel).addProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + variableModel.setType("d:text"); + updatedVariable = restClient.authenticateUser(assignee).withWorkflowAPI().usingProcess(processModel) + .updateProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + updatedVariable.assertThat().field("type").is("d:text"); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Update existing variable using PUT call - value") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.SANITY }) + public void updateProcessVariableValue() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + processModel = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + restClient.withWorkflowAPI().usingProcess(processModel).addProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + variableModel.setValue("newValue"); + + updatedVariable = restClient.withWorkflowAPI().usingProcess(processModel).updateProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + updatedVariable.assertThat().field("value").is("newValue"); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Update existing variable using PUT call - name") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.REGRESSION }) + public void updateProcessVariableName() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + processModel = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + restClient.withWorkflowAPI().usingProcess(processModel).addProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + variableModel.setName("newVariableName"); + + updatedVariable = restClient.withWorkflowAPI().usingProcess(processModel).updateProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + updatedVariable.assertThat().field("name").is("newVariableName"); + } + + @TestRail(section = {TestGroup.REST_API,TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Update existing variable created by the user who started the process using put call with a user that is not involved in the process- value") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.SANITY }) + public void cantUpdateProcessVariableValueCreatedWithAnyUser() throws Exception + { + UserModel anotherUser = dataUser.createRandomTestUser(); + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + processModel = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + restClient.withWorkflowAPI().usingProcess(processModel).addProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + variableModel.setValue("newValue"); + + restClient.authenticateUser(anotherUser).withWorkflowAPI().usingProcess(processModel) + .updateProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError().containsSummary(String.format(RestErrorModel.ACCESS_INFORMATION_NOT_ALLOWED, processModel.getId())); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Try to add process variable using an invalid processId") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.SANITY }) + public void updateProcessVariableUsingInvalidProcessId() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + processModel = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + restClient.withWorkflowAPI().usingProcess(processModel).addProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + processModel.setId("abc"); + + restClient.withWorkflowAPI().usingProcess(processModel).updateProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "abc")); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/GetTaskFormModelTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/GetTaskFormModelTests.java new file mode 100644 index 0000000000..5e4c9d364d --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/GetTaskFormModelTests.java @@ -0,0 +1,256 @@ +package org.alfresco.rest.workflow.tasks; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.*; +import org.alfresco.utility.model.*; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 2/3/2017. + */ +public class GetTaskFormModelTests extends RestTest +{ + UserModel userModel, adminUser; + SiteModel siteModel; + FileModel fileModel; + TaskModel taskModel; + RestFormModelsCollection returnedCollection; + + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + userModel = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); + fileModel = dataContent.usingUser(userModel).usingSite(siteModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, + executionType = ExecutionType.SANITY, description = "Verify admin user gets all task form models with Rest API and response is successful (200)") + public void adminGetsTaskFormModels() throws Exception + { + taskModel = dataWorkflow.usingUser(userModel).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(userModel); + returnedCollection = restClient.authenticateUser(dataUser.getAdminUser()).withWorkflowAPI().usingTask(taskModel).getTaskFormModel(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedCollection.assertThat().entriesListIsNotEmpty(); + + String[] qualifiedNames = { + "{http://www.alfresco.org/model/bpm/1.0}percentComplete", + "{http://www.alfresco.org/model/bpm/1.0}context", + "{http://www.alfresco.org/model/bpm/1.0}completedItems", + "{http://www.alfresco.org/model/content/1.0}name", + "{http://www.alfresco.org/model/bpm/1.0}packageActionGroup", + "{http://www.alfresco.org/model/bpm/1.0}reassignable", + "{http://www.alfresco.org/model/content/1.0}owner", + "{http://www.alfresco.org/model/bpm/1.0}outcome", + "{http://www.alfresco.org/model/bpm/1.0}taskId", + "{http://www.alfresco.org/model/bpm/1.0}packageItemActionGroup", + "{http://www.alfresco.org/model/bpm/1.0}completionDate"}; + + for(String formQualifiedName : qualifiedNames) + { + returnedCollection.assertThat().entriesListContains("qualifiedName", formQualifiedName); + } + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, + executionType = ExecutionType.SANITY, description = "Verify user involved in task gets all the task form models with Rest API and response is successful (200)") + public void involvedUserGetsTaskFormModels() throws Exception + { + taskModel = dataWorkflow.usingUser(userModel).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(userModel); + returnedCollection = restClient.authenticateUser(userModel).withWorkflowAPI().usingTask(taskModel).getTaskFormModel(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedCollection.assertThat().entriesListIsNotEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, + executionType = ExecutionType.REGRESSION, + description = "Verify that non involved user in task cannot get form models with Rest API and response is FORBIDDEN (403)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void nonInvolvedUserCannotGetTaskFormModels() throws Exception + { + taskModel = dataWorkflow.usingUser(userModel) + .usingSite(siteModel) + .usingResource(fileModel).createNewTaskAndAssignTo(userModel); + UserModel nonInvolvedUser = dataUser.createRandomTestUser(); + restClient.authenticateUser(nonInvolvedUser); + restClient.withWorkflowAPI().usingTask(taskModel).getTaskFormModel(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, + executionType = ExecutionType.REGRESSION, + description = "Verify user involved in task cannot get task form models with invalid task id") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void getTaskFormModelsInvalidTaskId() throws Exception + { + taskModel = dataWorkflow.usingUser(userModel) + .usingSite(siteModel) + .usingResource(fileModel).createNewTaskAndAssignTo(userModel); + taskModel.setId("0000"); + restClient.authenticateUser(userModel); + restClient.withWorkflowAPI().usingTask(taskModel).getTaskFormModel(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "0000")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, + executionType = ExecutionType.REGRESSION, + description = "Verify user involved in task cannot get task form models with invalid task id") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void getTaskFormModelsEmptyTaskId() throws Exception + { + taskModel = dataWorkflow.usingUser(userModel) + .usingSite(siteModel) + .usingResource(fileModel).createNewTaskAndAssignTo(userModel); + taskModel.setId(""); + restClient.authenticateUser(userModel); + restClient.withWorkflowAPI().usingTask(taskModel).getTaskFormModel(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, + executionType = ExecutionType.REGRESSION, + description = "Verify user involved in task can get completed task form models") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void getTaskFormModelsForCompletedTask() throws Exception + { + UserModel assignedUser = dataUser.createRandomTestUser(); + taskModel = dataWorkflow.usingUser(userModel) + .usingSite(siteModel) + .usingResource(fileModel).createNewTaskAndAssignTo(assignedUser); + dataWorkflow.usingUser(assignedUser).taskDone(taskModel); + dataWorkflow.usingUser(userModel).taskDone(taskModel); + restClient.authenticateUser(userModel); + returnedCollection = restClient.withWorkflowAPI().usingTask(taskModel).getTaskFormModel(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedCollection.assertThat().entriesListIsNotEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, + executionType = ExecutionType.REGRESSION, description = "Verify admin user gets all task form models with properties parameter applied and response is successful (200)") + public void adminGetsTaskFormModelsWithPropertiesParameter() throws Exception + { + taskModel = dataWorkflow.usingUser(userModel).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(userModel); + returnedCollection = restClient.authenticateUser(adminUser).withParams("properties=qualifiedName,required").withWorkflowAPI().usingTask(taskModel).getTaskFormModel(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedCollection.assertThat().entriesListIsNotEmpty(); + returnedCollection.getOneRandomEntry().onModel() + .assertThat() + .field("qualifiedName").isNotEmpty().and() + .field("required").isNotEmpty().and() + .field("dataType").isNull().and() + .field("name").isNull().and() + .field("title").isNull().and() + .field("defaultValue").isNull().and() + .field("allowedValues").isNull().and() + .fieldsCount().is(2); + } + + @Bug(id = "MNT-17438") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify admin gets task form model with valid skipCount parameter applied using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void getTaskFormModelWithValidSkipCount() throws Exception + { + taskModel = dataWorkflow.usingUser(userModel).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(userModel); + returnedCollection = restClient.authenticateUser(adminUser) + .withWorkflowAPI().usingTask(taskModel).getTaskFormModel(); + restClient.assertStatusCodeIs(HttpStatus.OK); + RestFormModel firstTaskFormModel = returnedCollection.getEntries().get(0).onModel(); + RestFormModel secondTaskFormModel = returnedCollection.getEntries().get(1).onModel(); + + RestFormModelsCollection formModelsWithSkipCount = restClient.withParams("skipCount=2").withWorkflowAPI().usingTask(taskModel).getTaskFormModel(); + restClient.assertStatusCodeIs(HttpStatus.OK); + formModelsWithSkipCount + .assertThat().entriesListDoesNotContain("name", firstTaskFormModel.getName()) + .assertThat().entriesListDoesNotContain("name", secondTaskFormModel.getName()) + .assertThat().entriesListCountIs(returnedCollection.getEntries().size()-2); + formModelsWithSkipCount.assertThat().paginationField("skipCount").is("2"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify admin doesn't get task form model with negative skipCount parameter applied using REST API") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void getTaskFormModelWithNegativeSkipCount() throws Exception + { + taskModel = dataWorkflow.usingUser(userModel).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(userModel); + restClient.authenticateUser(adminUser).withParams("skipCount=-1").withWorkflowAPI().usingTask(taskModel).getTaskFormModel(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(RestErrorModel.NEGATIVE_VALUES_SKIPCOUNT) + .containsErrorKey(RestErrorModel.NEGATIVE_VALUES_SKIPCOUNT) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE) + .statusCodeIs(HttpStatus.BAD_REQUEST); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify admin doesn't get task form model with non numeric skipCount parameter applied using REST API") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void getTaskFormModelWithNonNumericSkipCount() throws Exception + { + taskModel = dataWorkflow.usingUser(userModel).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(userModel); + restClient.authenticateUser(adminUser).withParams("skipCount=A").withWorkflowAPI().usingTask(taskModel).getTaskFormModel(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(String.format(RestErrorModel.INVALID_SKIPCOUNT, "A")); + } + + @Bug(id = "MNT-17438") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify admin gets task form model with valid maxItems parameter applied using REST API and status code is OK (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void getTaskFormModelWithValidMaxItems() throws Exception + { + taskModel = dataWorkflow.usingUser(userModel).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(userModel); + returnedCollection = restClient.authenticateUser(adminUser) + .withWorkflowAPI().usingTask(taskModel).getTaskFormModel(); + restClient.assertStatusCodeIs(HttpStatus.OK); + RestFormModel firstTaskFormModel = returnedCollection.getEntries().get(0).onModel(); + RestFormModel secondTaskFormModel = returnedCollection.getEntries().get(1).onModel(); + + RestFormModelsCollection formModelsWithMaxItems = restClient.withParams("maxItems=2").withWorkflowAPI().usingTask(taskModel).getTaskFormModel(); + restClient.assertStatusCodeIs(HttpStatus.OK); + formModelsWithMaxItems + .assertThat().entriesListContains("name", firstTaskFormModel.getName()) + .assertThat().entriesListContains("name", secondTaskFormModel.getName()) + .assertThat().entriesListCountIs(2); + formModelsWithMaxItems.assertThat().paginationField("maxItems").is("2"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify admin doesn't get task form model with negative maxItems parameter applied using REST API") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void getTaskFormModelWithNegativeMaxItems() throws Exception + { + taskModel = dataWorkflow.usingUser(userModel).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(userModel); + restClient.authenticateUser(adminUser).withParams("maxItems=-1").withWorkflowAPI().usingTask(taskModel).getTaskFormModel(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS) + .containsErrorKey(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE) + .statusCodeIs(HttpStatus.BAD_REQUEST); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify admin doesn't get task form model with non numeric maxItems parameter applied using REST API") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void getTaskFormModelWithNonNumericMaxItems() throws Exception + { + taskModel = dataWorkflow.usingUser(userModel).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(userModel); + restClient.authenticateUser(adminUser).withParams("maxItems=A").withWorkflowAPI().usingTask(taskModel).getTaskFormModel(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(String.format(RestErrorModel.INVALID_MAXITEMS, "A")); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/GetTaskTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/GetTaskTests.java new file mode 100644 index 0000000000..c9031c8f14 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/GetTaskTests.java @@ -0,0 +1,212 @@ +package org.alfresco.rest.workflow.tasks; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestTaskModel; +import org.alfresco.rest.model.RestTaskModelsCollection; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.GroupModel; +import org.alfresco.utility.model.ProcessModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TaskModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.commons.lang3.RandomStringUtils; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +/** + * + * @author Cristina Axinte + * + */ +public class GetTaskTests extends RestTest +{ + UserModel userModel, assigneeUser; + UserModel adminTenantUser, tenantUser, tenantUserAssignee, adminUser; + SiteModel siteModel; + FileModel fileModel; + TaskModel taskModel; + RestTaskModel restTaskModel, tenantTask; + RestTaskModelsCollection taskModels; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + userModel = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); + fileModel = dataContent.usingUser(userModel).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + assigneeUser = dataUser.createRandomTestUser(); + } + + @BeforeMethod(alwaysRun=true) + public void createTask() throws Exception + { + taskModel = dataWorkflow.usingUser(userModel).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assigneeUser); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, + TestGroup.TASKS }, executionType = ExecutionType.SANITY, description = "Verify admin user gets any existing task with Rest API and response is successfull (200)") + public void adminUserGetsAnyTaskWithSuccess() throws Exception + { + restTaskModel = restClient.authenticateUser(adminUser).withWorkflowAPI().usingTask(taskModel).getTask(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("description").is(taskModel.getMessage()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, + TestGroup.TASKS }, executionType = ExecutionType.SANITY, description = "Verify assignee user gets its assigned task with Rest API and response is successfull (200)") + public void assigneeUserGetsItsTaskWithSuccess() throws Exception + { + restTaskModel = restClient.authenticateUser(assigneeUser).withWorkflowAPI().usingTask(taskModel).getTask(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("description").is(taskModel.getMessage()).and().field("assignee") + .is(assigneeUser.getUsername()); + + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, + TestGroup.TASKS }, executionType = ExecutionType.SANITY, description = "Verify user that started the task gets the started task with Rest API and response is successfull (200)") + public void starterUserGetsItsTaskWithSuccess() throws Exception + { + restTaskModel = restClient.authenticateUser(userModel).withWorkflowAPI().usingTask(taskModel).getTask(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("description").is(taskModel.getMessage()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, + TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, description = "Verify any user with no relation to task id forbidden to get other task with Rest API (403)") + public void anyUserIsForbiddenToGetOtherTask() throws Exception + { + UserModel anyUser = dataUser.createRandomTestUser(); + + restTaskModel = restClient.authenticateUser(anyUser).withWorkflowAPI().usingTask(taskModel).getTask(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary("Permission was denied"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, + TestGroup.TASKS }, executionType = ExecutionType.SANITY, description = "Verify candidate user gets its specific task and no other user claimed the task with Rest API and response is successfull (200)") + public void candidateUserGetsItsTasks() throws Exception + { + UserModel userModel1 = dataUser.createRandomTestUser(); + UserModel userModel2 = dataUser.createRandomTestUser(); + GroupModel group = dataGroup.createRandomGroup(); + dataGroup.addListOfUsersToGroup(group, userModel1, userModel2); + TaskModel taskModel = dataWorkflow.usingUser(userModel).usingSite(siteModel).usingResource(fileModel).createPooledReviewTaskAndAssignTo(group); + + restTaskModel = restClient.authenticateUser(userModel1).withWorkflowAPI().usingTask(taskModel).getTask(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("description").is(taskModel.getMessage()); + + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + @Bug(id = "MNT-17051") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, + TestGroup.TASKS }, executionType = ExecutionType.SANITY, description = "Verify involved user in a task without claim it gets the task with Rest API and response is successfull (200)") + public void involvedUserWithoutClaimTaskGetsTask() throws Exception + { + UserModel userModel1 = dataUser.createRandomTestUser(); + UserModel userModel2 = dataUser.createRandomTestUser(); + GroupModel group = dataGroup.createRandomGroup(); + dataGroup.addListOfUsersToGroup(group, userModel1, userModel2); + TaskModel taskModel = dataWorkflow.usingUser(userModel).usingSite(siteModel).usingResource(fileModel).createPooledReviewTaskAndAssignTo(group); + dataWorkflow.usingUser(userModel1).claimTask(taskModel); + + restTaskModel = restClient.authenticateUser(userModel2).withWorkflowAPI().usingTask(taskModel).getTask(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("description").is(taskModel.getMessage()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, + executionType = ExecutionType.REGRESSION, description = "Verify user who started a task gets the task with empty taskId with Rest API") + public void starterUserGetsTaskWithEmptyTaskId() throws Exception + { + UserModel userWhoStartsTask = dataUser.createRandomTestUser(); + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(userWhoStartsTask); + + restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI(); + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "tasks/{taskId}", ""); + RestTaskModelsCollection tasks = restClient.processModels(RestTaskModelsCollection.class, request); + + restClient.assertStatusCodeIs(HttpStatus.OK); + tasks.assertThat().entriesListIsNotEmpty() + .and().entriesListCountIs(1) + .and().entriesListContains("id", taskModel.getId()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, + executionType = ExecutionType.REGRESSION, description = "Verify user who started a task gets the task with properties parameter with Rest API") + public void starterUserGetsTaskWithPropertiesParameter() throws Exception + { + restTaskModel = restClient.authenticateUser(userModel).withWorkflowAPI().usingTask(taskModel).usingParams("properties=id,assignee,formResourceKey").getTask(); + + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().fieldsCount().is(3) + .and().field("id").is(taskModel.getId()) + .and().field("assignee").is(taskModel.getAssignee()) + .and().field("formResourceKey").is("wf:adhocTask") + .and().field("processDefinitionId").isNull() + .and().field("processId").isNull(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, + executionType = ExecutionType.REGRESSION, description = "Verify user who started a task gets the task after it is deleted with Rest API") + public void starterUserGetsDeletedTask() throws Exception + { + restTaskModel = restClient.authenticateUser(userModel).withWorkflowAPI().usingTask(taskModel).getTask(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()); + + ProcessModel process = new ProcessModel(); + process.setId(taskModel.getProcessId()); + dataWorkflow.usingUser(userModel).deleteProcess(process); + + restClient.authenticateUser(userModel).withWorkflowAPI().usingTask(taskModel).getTask(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, taskModel.getId())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, + TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, description = "Verify if using invalid taskId status code 404 is returned.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void invalidTaskId() throws Exception + { + taskModel.setId(RandomStringUtils.randomAlphanumeric(20)); + restTaskModel = restClient.authenticateUser(userModel).withWorkflowAPI().usingTask(taskModel).getTask(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, taskModel.getId())); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, + TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, description = "Verify if using empty taskId status code 200 is returned.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void emptyTaskId() throws Exception + { + restClient.authenticateUser(userModel).withWorkflowAPI(); + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "tasks/{taskId}", ""); + taskModels = restClient.processModels(RestTaskModelsCollection.class, request); + restClient.assertStatusCodeIs(HttpStatus.OK); + taskModels.assertThat().entriesListIsNotEmpty(); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/GetTasksTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/GetTasksTests.java new file mode 100644 index 0000000000..fa2fcfd55d --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/GetTasksTests.java @@ -0,0 +1,234 @@ +package org.alfresco.rest.workflow.tasks; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.dataprep.CMISUtil.Priority; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestTaskModel; +import org.alfresco.rest.model.RestTaskModelsCollection; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.GroupModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TaskModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class GetTasksTests extends RestTest +{ + UserModel userModel, userNotInvolved, assigneeUser, adminUser; + UserModel adminTenantUser, tenantUser, tenantUserAssignee; + SiteModel siteModel; + FileModel fileModel; + RestTaskModelsCollection taskModels, taskCollections, tenantTask; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + userModel = dataUser.createRandomTestUser(); + userNotInvolved = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); + fileModel = dataContent.usingUser(userModel).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + + assigneeUser = dataUser.createRandomTestUser(); + dataWorkflow.usingUser(userModel).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assigneeUser); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.SANITY, description = "Verify admin user gets all existing tasks with Rest API and response is successfull (200)") + public void adminUserGetsAllTasks() throws Exception + { + UserModel adminUser = dataUser.getAdminUser(); + + taskModels = restClient.authenticateUser(adminUser).withWorkflowAPI().getTasks(); + restClient.assertStatusCodeIs(HttpStatus.OK); + taskModels.assertThat().entriesListIsNotEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.SANITY, description = "Verify asignee user gets its existing tasks with Rest API and response is successfull (200)") + public void assigneeUserGetsItsTasks() throws Exception + { + taskModels = restClient.authenticateUser(assigneeUser).withWorkflowAPI().getTasks(); + restClient.assertStatusCodeIs(HttpStatus.OK); + taskModels.assertThat().entriesListIsNotEmpty().and().entriesListCountIs(1).and().entriesListContains("assignee", assigneeUser.getUsername()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.SANITY, description = "Verify candidate user that claims the task gets its existing tasks with Rest API and response is successfull (200)") + @Bug(id = "MNT-16967") + public void candidateUserGetsItsTasks() throws Exception + { + UserModel userModel1 = dataUser.createRandomTestUser(); + UserModel userModel2 = dataUser.createRandomTestUser(); + GroupModel group = dataGroup.createRandomGroup(); + + dataGroup.addListOfUsersToGroup(group, userModel1, userModel2); + dataWorkflow.usingUser(userModel).usingSite(siteModel).usingResource(fileModel).createPooledReviewTaskAndAssignTo(group); + + taskModels = restClient.authenticateUser(userModel1).withWorkflowAPI().getTasks(); + restClient.assertStatusCodeIs(HttpStatus.OK); + taskModels.assertThat().entriesListIsNotEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.SANITY, description = "Verify candidate user that claims the task gets its existing tasks with Rest API and response is successfull (200)") + public void candidateUserThatClaimsTaskGetsItsTasks() throws Exception + { + UserModel userModel1 = dataUser.createRandomTestUser(); + UserModel userModel2 = dataUser.createRandomTestUser(); + GroupModel group = dataGroup.createRandomGroup(); + dataGroup.addListOfUsersToGroup(group, userModel1, userModel2); + TaskModel taskModel = dataWorkflow.usingUser(userModel).usingSite(siteModel).usingResource(fileModel).createPooledReviewTaskAndAssignTo(group); + dataWorkflow.usingUser(userModel1).claimTask(taskModel); + + taskModels = restClient.authenticateUser(userModel1).withWorkflowAPI().getTasks(); + restClient.assertStatusCodeIs(HttpStatus.OK); + taskModels.assertThat().entriesListIsNotEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.SANITY, description = "Verify candidate user without claim gets no tasks with Rest API and response is successfull (200)") + public void candidateUserWithoutClaimTaskGetsNoTasks() throws Exception + { + UserModel userModel1 = dataUser.createRandomTestUser(); + UserModel userModel2 = dataUser.createRandomTestUser(); + GroupModel group = dataGroup.createRandomGroup(); + + dataGroup.addListOfUsersToGroup(group, userModel1, userModel2); + TaskModel taskModel = dataWorkflow.usingUser(userModel).usingSite(siteModel).usingResource(fileModel).createPooledReviewTaskAndAssignTo(group); + dataWorkflow.usingUser(userModel1).claimTask(taskModel); + + taskModels = restClient.authenticateUser(userModel2).withWorkflowAPI().getTasks(); + restClient.assertStatusCodeIs(HttpStatus.OK); + taskModels.assertThat().entriesListIsEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, + TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, description = "Check that skipCount parameter is applied.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void skipCountParameterApplied() throws Exception + { + taskCollections = restClient.authenticateUser(dataUser.getAdminUser()).withParams("orderBy=description ASC").withWorkflowAPI().getTasks(); + restClient.assertStatusCodeIs(HttpStatus.OK); + RestTaskModel firstTask = taskCollections.getEntries().get(0).onModel(); + RestTaskModel secondTask = taskCollections.getEntries().get(1).onModel(); + + taskModels = restClient.withParams("orderBy=description ASC&skipCount=2").withWorkflowAPI().getTasks(); + restClient.assertStatusCodeIs(HttpStatus.OK); + taskModels.assertThat().entriesListDoesNotContain("id", firstTask.getId()) + .assertThat().entriesListDoesNotContain("id", secondTask.getId()); + taskModels.assertThat().paginationField("skipCount").is("2"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, + TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, description = "Check that maxItems parameter is applied.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void maxItemsParameterApplied() throws Exception + { + restClient.authenticateUser(userModel).withWorkflowAPI().addProcess("activitiAdhoc", assigneeUser, false, Priority.Low); + restClient.authenticateUser(userModel).withWorkflowAPI().addProcess("activitiAdhoc", adminUser, false, Priority.Low); + taskCollections = restClient.authenticateUser(userModel).withParams("orderBy=assignee ASC").withWorkflowAPI().getTasks(); + restClient.assertStatusCodeIs(HttpStatus.OK); + + taskModels = restClient.withParams("orderBy=startedAt DESC&maxItems=2").withWorkflowAPI().getTasks(); + restClient.assertStatusCodeIs(HttpStatus.OK); + taskModels.assertThat().entriesListIsNotEmpty() + .assertThat().entriesListContains("assignee", assigneeUser.getUsername()) + .assertThat().entriesListDoesNotContain("assignee", userModel.getUsername()); + taskModels.assertThat().paginationField("maxItems").is("2"); + taskModels.assertThat().paginationField("count").is("2"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, + TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, description = "Check that properties parameter is applied.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void propertiesParameterApplied() throws Exception + { + taskModels = restClient.authenticateUser(dataUser.getAdminUser()).withParams("properties=name,description").withWorkflowAPI().getTasks(); + restClient.assertStatusCodeIs(HttpStatus.OK); + taskModels.assertThat().entriesListIsNotEmpty() + .assertThat().entriesListContains("name") + .assertThat().entriesListContains("description") + .assertThat().entriesListDoesNotContain("processDefinitionId") + .assertThat().entriesListDoesNotContain("processId") + .assertThat().entriesListDoesNotContain("startedAt") + .assertThat().entriesListDoesNotContain("id") + .assertThat().entriesListDoesNotContain("state") + .assertThat().entriesListDoesNotContain("activityDefinitionId") + .assertThat().entriesListDoesNotContain("priority") + .assertThat().entriesListDoesNotContain("formResourceKey"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, + TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, description = "Use invalid where parameter. Check default error model schema.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void invalidWhereParameterCheckDefaultErrorModelSchema() throws Exception + { + restClient.authenticateUser(dataUser.getAdminUser()).where("assignee AND '" + assigneeUser.getUsername() + "'").withWorkflowAPI().getTasks(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsErrorKey(RestErrorModel.INVALID_QUERY_ERRORKEY) + .containsSummary(String.format(RestErrorModel.INVALID_WHERE_QUERY, "(assignee AND '" + assigneeUser.getUsername() + "')")) + .stackTraceIs(RestErrorModel.STACKTRACE) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, + TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, description = "Verify the request in case of any user which is not involved.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void requestWithUserNotInvolved() throws Exception + { + taskModels = restClient.authenticateUser(userNotInvolved).withWorkflowAPI().getTasks(); + restClient.assertStatusCodeIs(HttpStatus.OK); + taskModels.assertThat().entriesListIsEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, + TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, description = "Check that orderBy parameter is applied.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void orderByParameterApplied() throws Exception + { + taskModels = restClient.authenticateUser(dataUser.getAdminUser()).withParams("orderBy=id").withWorkflowAPI().getTasks(); + restClient.assertStatusCodeIs(HttpStatus.OK); + taskModels.assertThat().entriesListIsNotEmpty(). + and().entriesListIsSortedAscBy("id"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, + TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, description = "Check that orderBy parameter is applied and supports only one parameter.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void orderByParameterSupportsOnlyOneParameter() throws Exception + { + taskModels = restClient.authenticateUser(dataUser.getAdminUser()).withParams("orderBy=id,processDefinitionId").withWorkflowAPI().getTasks(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary("Only one order by parameter is supported"); + taskModels.assertThat().entriesListIsEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, + TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, description = "Check that where parameter is applied.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void whereParameterApplied() throws Exception + { + UserModel anotherAssignee = dataUser.createRandomTestUser(); + dataWorkflow.usingUser(userModel).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(anotherAssignee); + taskModels = restClient.authenticateUser(dataUser.getAdminUser()).withParams("where=(assignee='" + anotherAssignee.getUsername() + "')").withWorkflowAPI() + .getTasks(); + restClient.assertStatusCodeIs(HttpStatus.OK); + taskModels.assertThat().entriesListIsNotEmpty().and().entriesListContains("assignee", anotherAssignee.getUsername()).and().entriesListCountIs(1); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, + TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, description = "Check that invalid orderBy parameter applied returns 400 status code.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void invalidOrderByParameterApplied() throws Exception + { + restClient.authenticateUser(dataUser.getAdminUser()).withParams("orderBy=invalidParameter").withWorkflowAPI().getTasks(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary("invalidParameter is not supported"); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/UpdateTaskTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/UpdateTaskTests.java new file mode 100644 index 0000000000..968f786bc6 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/UpdateTaskTests.java @@ -0,0 +1,1632 @@ +package org.alfresco.rest.workflow.tasks; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.JsonBodyGenerator; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestProcessDefinitionModel; +import org.alfresco.rest.model.RestTaskModel; +import org.alfresco.rest.model.RestVariableModelsCollection; +import org.alfresco.utility.model.*; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import javax.json.JsonObject; +import java.util.HashMap; + +public class UpdateTaskTests extends RestTest +{ + UserModel owner, anyUser; + SiteModel siteModel; + FileModel fileModel; + UserModel assigneeUser; + TaskModel taskModel; + RestTaskModel restTaskModel; + UserModel adminUser; + RestProcessDefinitionModel activitiReviewProcessDefinition; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + owner = dataUser.createRandomTestUser(); + anyUser = dataUser.createRandomTestUser(); + assigneeUser = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(adminUser).createPublicRandomSite(); + fileModel = dataContent.usingUser(adminUser).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + activitiReviewProcessDefinition = restClient.authenticateUser(adminUser).withWorkflowAPI().getAllProcessDefinitions().getProcessDefinitionByKey("activitiReviewPooled"); + } + + @BeforeMethod(alwaysRun = true) + public void createTask() throws Exception + { + taskModel = dataWorkflow.usingUser(owner).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assigneeUser); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.SANITY, description = "Verify admin user updates task with Rest API and response is successfull (200)") + public void adminUserUpdatesAnyTaskWithSuccess() throws Exception + { + restTaskModel = restClient.authenticateUser(adminUser).withWorkflowAPI().usingTask(taskModel).updateTask("completed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("description").is(taskModel.getMessage()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.SANITY, description = "Verify assignee user updates its assigned task with Rest API and response is successfull (200)") + public void assigneeUserUpdatesItsTaskWithSuccess() throws Exception + { + restTaskModel = restClient.authenticateUser(assigneeUser).withWorkflowAPI().usingTask(taskModel).updateTask("completed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("description").is(taskModel.getMessage()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.SANITY, description = "Verify user that started the task updates the started task with Rest API and response is successfull (200)") + public void starterUserUpdatesItsTaskWithSuccess() throws Exception + { + restTaskModel = restClient.authenticateUser(owner).withWorkflowAPI().usingTask(taskModel).updateTask("completed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, description = "Verify any user with no relation to task is forbidden to update other task with Rest API (403)") + public void anyUserIsForbiddenToUpdateOtherTask() throws Exception + { + restTaskModel = restClient.authenticateUser(anyUser).withWorkflowAPI().usingTask(taskModel).updateTask("completed"); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary("Permission was denied"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.SANITY, description = "Verify candidate user updates its specific task and no other user claimed the task with Rest API and response is successfull (200)") + public void candidateUserUpdatesItsTasks() throws Exception + { + UserModel userModel1 = dataUser.createRandomTestUser(); + UserModel userModel2 = dataUser.createRandomTestUser(); + GroupModel group = dataGroup.createRandomGroup(); + dataGroup.addListOfUsersToGroup(group, userModel1, userModel2); + TaskModel taskModel = dataWorkflow.usingUser(owner).usingSite(siteModel).usingResource(fileModel).createPooledReviewTaskAndAssignTo(group); + + restTaskModel = restClient.authenticateUser(userModel1).withWorkflowAPI().usingTask(taskModel).updateTask("completed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat() + .field("dueAt").isNotEmpty() + .and().field("processDefinitionId").is(activitiReviewProcessDefinition.getId()) + .and().field("processId").is(taskModel.getProcessId()) + .and().field("name").is("Review Task") + .and().field("description").is(taskModel.getMessage()) + .and().field("startedAt").isNotEmpty() + .and().field("id").is(taskModel.getId()) + .and().field("state").is("unclaimed") + .and().field("activityDefinitionId").is("reviewTask") + .and().field("priority").is(taskModel.getPriority().getLevel()) + .and().field("formResourceKey").is("wf:activitiReviewTask"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify task owner can update twice task with status resolve successfully (200)") + public void taskOwnerCanUpdateTaskWithResolveStateTwice() throws Exception + { + restTaskModel = restClient.authenticateUser(assigneeUser) + .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("resolved"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("resolved"); + + restClient.authenticateUser(owner) + .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("resolved"); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify task asignee cannot update twice task with status resolve - Forbidden (403)") + public void taskAssigneeCanNotUpdateTaskWithResolveStateTwice() throws Exception + { + restTaskModel = restClient.authenticateUser(assigneeUser) + .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("resolved"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("resolved"); + + restClient.authenticateUser(assigneeUser) + .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("resolved"); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify task cannot be update using a invalid json body property - Bad Request (400)") + public void taskCanNotBeUpdatedWithInvalidJsonBodyProperty() throws Exception + { + String invalidJsonProperty= "states"; + restClient.authenticateUser(assigneeUser) + .withParams("select=state").withWorkflowAPI().usingTask(taskModel); + String postBody = JsonBodyGenerator.keyValueJson(invalidJsonProperty, "completed"); + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, postBody, "tasks/{taskId}?{parameters}", taskModel.getId(), restClient.getParameters()); + restClient.processModel(RestTaskModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.NO_CONTENT, "Unrecognized field \""+invalidJsonProperty+"\"")); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify task cannot be update using a invalid state - Bad Request (400)") + public void taskCanNotBeUpdatedWithInvalidState() throws Exception + { + restTaskModel = restClient.authenticateUser(assigneeUser) + .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("continued"); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.INVALID_VALUE, "task state", "continued")); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify task cannot be update using a invalid property - Bad Request (400)") + public void taskCanNotBeUpdatedWithInvalidSelectProperty() throws Exception + { + String invalidProperty= "states"; + restClient.authenticateUser(assigneeUser) + .withParams("select=" + invalidProperty).withWorkflowAPI().usingTask(taskModel); + String postBody = JsonBodyGenerator.keyValueJson("state", "completed"); + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, postBody, "tasks/{taskId}?{parameters}", taskModel.getId(), restClient.getParameters()); + restClient.processModel(RestTaskModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.PROPERTY_DOES_NOT_EXIST, invalidProperty)); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify task can be update using multiple select values successfully (200)") + public void taskCanBeUpdatedWithMultipleSelectValues() throws Exception + { + JsonObject inputJson = JsonBodyGenerator.defineJSON() + .add("state", "resolved") + .add("assignee", "admin").build(); + + restTaskModel = restClient.authenticateUser(assigneeUser) + .withParams("select=state,assignee").withWorkflowAPI().usingTask(taskModel).updateTask(inputJson); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("resolved"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.SANITY, + description = "Verify task assignee can complete task successfully (200)") + public void taskAssigneeCanCompleteTask() throws Exception + { + restTaskModel = restClient.authenticateUser(assigneeUser) + .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("completed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("completed"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.SANITY, + description = "Verify task owner can complete task successfully (200))") + public void taskOwnerCanCompleteTask() throws Exception + { + restTaskModel = restClient.authenticateUser(assigneeUser) + .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("completed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("completed"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify any user cannot complete task - Forbidden (403))") + public void anyUserCannotCompleteTask() throws Exception + { + UserModel anyUser = dataUser.createRandomTestUser(); + + restTaskModel = restClient.authenticateUser(anyUser) + .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("completed"); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @Bug(id = "REPO-2062") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify task owner cannot complete task with invalid name - Bad Request(400))") + public void taskOwnerCannotCompleteTaskWithInvalidName() throws Exception + { + JsonObject inputJson = JsonBodyGenerator.defineJSON() + .add("state", "completed") + .add("variables", JsonBodyGenerator.defineJSONArray() + .add(JsonBodyGenerator.defineJSON() + .add("name", "bpmx_priorityx") + .add("type", "d:int") + .add("value", 1) + .add("scope", "global").build()) + ).build(); + + restTaskModel = restClient.authenticateUser(owner) + .withParams("select=state,variables").withWorkflowAPI().usingTask(taskModel).updateTask(inputJson); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.UNSUPPORTED_TYPE,"bpm_priorityx")); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify task owner cannot complete task with invalid Type - Bad Request(400))") + public void taskOwnerCannotCompleteTaskWithInvalidType() throws Exception + { + JsonObject inputJson = JsonBodyGenerator.defineJSON() + .add("state", "completed") + .add("variables", JsonBodyGenerator.defineJSONArray() + .add(JsonBodyGenerator.defineJSON() + .add("name", "bpmx_priority") + .add("type", "d_int") + .add("value", 1) + .add("scope", "global").build()) + ).build(); + + restTaskModel = restClient.authenticateUser(owner) + .withParams("select=state,variables").withWorkflowAPI().usingTask(taskModel).updateTask(inputJson); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.UNSUPPORTED_TYPE,"d_int")); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @Bug(id = "REPO-2062") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify task owner cannot complete task with invalid value - Bad Request(400))") + public void taskOwnerCannotCompleteTaskWithInvalidValue() throws Exception + { + JsonObject inputJson = JsonBodyGenerator.defineJSON() + .add("state", "completed") + .add("variables", JsonBodyGenerator.defineJSONArray() + .add(JsonBodyGenerator.defineJSON() + .add("name", "bpmx_priority") + .add("type", "d:int") + .add("value", "text") + .add("scope", "global").build()) + ).build(); + + restTaskModel = restClient.authenticateUser(owner) + .withParams("select=state,variables").withWorkflowAPI().usingTask(taskModel).updateTask(inputJson); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.UNSUPPORTED_TYPE, "text")); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify task owner cannot complete task with invalid scope - Bad Request(400))") + public void taskOwnerCannotCompleteTaskWithInvalidScope() throws Exception + { + JsonObject inputJson = JsonBodyGenerator.defineJSON() + .add("state", "completed") + .add("variables", JsonBodyGenerator.defineJSONArray() + .add(JsonBodyGenerator.defineJSON() + .add("name", "bpmx_priority") + .add("type", "d:int") + .add("value", 1) + .add("scope", "globalscope").build()) + ).build(); + + restTaskModel = restClient.authenticateUser(owner) + .withParams("select=state,variables").withWorkflowAPI().usingTask(taskModel).updateTask(inputJson); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.ILLEGAL_SCOPE, "globalscope")); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify task assignee can claim task successfully (200)") + public void taskAssigneeCanClaimTask() throws Exception + { + restTaskModel = restClient.authenticateUser(assigneeUser) + .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("claimed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("claimed"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify task assignee can unclaim task successfully (200)") + public void taskAssigneeCanUnclaimTask() throws Exception + { + restTaskModel = restClient.authenticateUser(assigneeUser) + .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("unclaimed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("unclaimed"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify task assignee can delegate task successfully (200)") + public void taskAssigneeCanDelegateTask() throws Exception + { + UserModel delagateToUser = dataUser.createRandomTestUser(); + + JsonObject inputJson = JsonBodyGenerator.defineJSON() + .add("state", "delegated") + .add("assignee", delagateToUser.getUsername()).build(); + + restTaskModel = restClient.authenticateUser(assigneeUser) + .withParams("select=state,assignee").withWorkflowAPI().usingTask(taskModel).updateTask(inputJson); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("delegated") + .and().field("assignee").is(delagateToUser.getUsername()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify task owner can delegate task to same assignee successfully (200)") + public void taskOwnerCanDelegateTaskToSameAssignee() throws Exception + { + JsonObject inputJson = JsonBodyGenerator.defineJSON() + .add("state", "delegated") + .add("assignee", assigneeUser.getUsername()).build(); + + restTaskModel = restClient.authenticateUser(owner) + .withParams("select=state,assignee").withWorkflowAPI().usingTask(taskModel).updateTask(inputJson); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("delegated") + .and().field("assignee").is(assigneeUser.getUsername()); + } + + + @Bug(id = "REPO-2063") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify task assignee cannot delegate task to task owner - (400)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void taskAssigneeCannotDelegateTaskToTaskOwner() throws Exception + { + JsonObject inputJson = JsonBodyGenerator.defineJSON() + .add("state", "delegated") + .add("assignee", owner.getUsername()).build(); + + restTaskModel = restClient.authenticateUser(assigneeUser) + .withParams("select=state,assignee").withWorkflowAPI().usingTask(taskModel).updateTask(inputJson); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @Bug(id = "REPO-2063") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify task assignee cannot delegate task to invalid assignee - (400)") + public void taskAssigneeCannotDelegateTaskToInvalidAssignee() throws Exception + { + UserModel invalidAssignee = new UserModel("invalidAssignee", "password"); + + JsonObject inputJson = JsonBodyGenerator.defineJSON() + .add("state", "delegated") + .add("assignee", invalidAssignee.getUsername()).build(); + + restTaskModel = restClient.authenticateUser(assigneeUser) + .withParams("select=state,assignee").withWorkflowAPI().usingTask(taskModel).updateTask(inputJson); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify task assignee can update task with status resolve") + public void resolveTaskAsCurrentAssignee() throws Exception + { + restTaskModel = restClient.authenticateUser(assigneeUser) + .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("resolved"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("resolved"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify update task using invalid taskId") + public void updateTaskUsingInvalidTaskId() throws Exception + { + taskModel.setId("invalidId"); + + restClient.authenticateUser(owner).withWorkflowAPI().usingTask(taskModel).updateTask("completed"); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "invalidId")); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify update task using another name") + public void updateTaskUsingAnotherName() throws Exception + { + restClient.authenticateUser(owner).withParams("select=name").withWorkflowAPI().usingTask(taskModel); + String postBody = "{\"name\":\"newNameTask\"}"; + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, postBody, "tasks/{taskId}?{parameters}", taskModel.getId(), restClient.getParameters()); + restTaskModel = restClient.processModel(RestTaskModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("name").is("newNameTask"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify update task using another description") + public void updateTaskUsingAnotherDescription() throws Exception + { + restClient.authenticateUser(owner).withParams("select=description").withWorkflowAPI().usingTask(taskModel); + String postBody = "{\"description\":\"newDescription\"}"; + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, postBody, "tasks/{taskId}?{parameters}", taskModel.getId(), restClient.getParameters()); + restTaskModel = restClient.processModel(RestTaskModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("description").is("newDescription"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify update task using another priority") + public void updateTaskUsingAnotherPriority() throws Exception + { + restClient.authenticateUser(owner).withParams("select=priority").withWorkflowAPI().usingTask(taskModel); + String postBody = "{\"priority\":3}"; + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, postBody, "tasks/{taskId}?{parameters}", taskModel.getId(), restClient.getParameters()); + restTaskModel = restClient.processModel(RestTaskModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("priority").is(CMISUtil.Priority.Low.getLevel()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify update task using another priority") + public void updateTaskUsingAnotherOwner() throws Exception + { + UserModel newOwner = dataUser.createRandomTestUser(); + + restClient.authenticateUser(owner).withParams("select=owner").withWorkflowAPI().usingTask(taskModel); + String postBody = "{\"owner\":\""+newOwner.getUsername()+"\"}"; + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, postBody, "tasks/{taskId}?{parameters}", taskModel.getId(), restClient.getParameters()); + restTaskModel = restClient.processModel(RestTaskModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("owner").is(newOwner.getUsername()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, + TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, description = "Verify owner can not update task from completed to claimed and response is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void taskOwnerCanNotUpdateTaskFromCompletedToClaimed() throws Exception + { + restTaskModel = restClient.authenticateUser(owner).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("completed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("completed"); + restTaskModel = restClient.authenticateUser(owner).withWorkflowAPI().usingTask(taskModel).updateTask("claimed"); + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED).assertLastError() + .containsSummary(String.format(RestErrorModel.TASK_ALREADY_COMPLETED, taskModel.getId())); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, + TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, description = "Verify owner can not update task from completed to unclaimed and response is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void taskOwnerCanNotUpdateTaskFromCompletedToUnclaimed() throws Exception + { + restTaskModel = restClient.authenticateUser(assigneeUser).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("completed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("completed"); + restTaskModel = restClient.authenticateUser(owner).withWorkflowAPI().usingTask(taskModel).updateTask("unclaimed"); + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED).assertLastError() + .containsSummary(String.format(RestErrorModel.TASK_ALREADY_COMPLETED, taskModel.getId())); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, + TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, description = "Verify owner can not update task from completed to completed and response is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void taskOwnerCanNotUpdateTaskWithCompleteStateTwice() throws Exception + { + restTaskModel = restClient.authenticateUser(assigneeUser).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("completed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("completed"); + restClient.authenticateUser(owner).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("completed"); + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED).assertLastError() + .containsSummary(String.format(RestErrorModel.TASK_ALREADY_COMPLETED, taskModel.getId())); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, + TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, description = "Verify owner can update task from claimed to completed and response is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void taskOwnerCanUpdateTaskFromClaimedToCompleted() throws Exception + { + restTaskModel = restClient.authenticateUser(assigneeUser).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("claimed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("claimed"); + restTaskModel = restClient.authenticateUser(owner).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("completed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("completed"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, + TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, description = "Verify user can update task from claimed to claimed and response is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void userCanUpdateTaskWithClaimedStateTwice() throws Exception + { + restTaskModel = restClient.authenticateUser(assigneeUser).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("claimed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("claimed"); + restTaskModel = restClient.authenticateUser(assigneeUser).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("claimed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("claimed"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, + TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, description = "Verify owner can update task from unclaimed to completed and response is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void taskOwnerCanUpdateTaskFromUnclaimedToCompleted() throws Exception + { + restTaskModel = restClient.authenticateUser(assigneeUser).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("unclaimed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("unclaimed"); + restTaskModel = restClient.authenticateUser(owner).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("completed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("completed"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, + TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, description = "Verify owner can not update task from unclaimed to unclaimed and response is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void taskOwnerCanNotUpdateTaskWithUnclaimedStateTwice() throws Exception + { + restTaskModel = restClient.authenticateUser(assigneeUser).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("unclaimed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("unclaimed"); + restTaskModel = restClient.authenticateUser(owner).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("unclaimed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("unclaimed"); + } + + @Bug(id = "REPO-1924") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, + TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, description = "Verify owner can not update task from delegated to completed and response is 422") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void taskOwnerCanNotUpdateTaskFromDelegatedToCompleted() throws Exception + { + restClient.authenticateUser(owner).withParams("select=state,assignee").withWorkflowAPI().usingTask(taskModel); + HashMap body = new HashMap(); + body.put("state", "delegated"); + body.put("assignee", assigneeUser.getUsername()); + String postBody = JsonBodyGenerator.keyValueJson(body); + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, postBody, "tasks/{taskId}?{parameters}", taskModel.getId(), + restClient.getParameters()); + restTaskModel = restClient.processModel(RestTaskModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("delegated").and().field("assignee") + .is(assigneeUser.getUsername()); + + restClient.authenticateUser(owner).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("completed"); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY).assertLastError().containsSummary(RestErrorModel.DELEGATED_TASK_CAN_NOT_BE_COMPLETED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, + TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, description = "Verify owner can not update task from delegated to delegated and response is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void taskOwnerCanNotUpdateTaskWithDelegatedStateTwice() throws Exception + { + restClient.authenticateUser(owner).withParams("select=state,assignee").withWorkflowAPI().usingTask(taskModel); + HashMap body = new HashMap(); + body.put("state", "delegated"); + body.put("assignee", assigneeUser.getUsername()); + String postBody = JsonBodyGenerator.keyValueJson(body); + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, postBody, "tasks/{taskId}?{parameters}", taskModel.getId(), + restClient.getParameters()); + restTaskModel = restClient.processModel(RestTaskModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("delegated").and().field("assignee") + .is(assigneeUser.getUsername()); + + request = RestRequest.requestWithBody(HttpMethod.PUT, postBody, "tasks/{taskId}?{parameters}", taskModel.getId(), restClient.getParameters()); + restTaskModel = restClient.processModel(RestTaskModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("delegated").and().field("assignee") + .is(assigneeUser.getUsername()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, + TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, description = "Verify owner can update task from resolved to completed and response is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void taskOwnerCanUpdateTaskFromResolvedToCompleted() throws Exception + { + restTaskModel = restClient.authenticateUser(assigneeUser).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("resolved"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("resolved"); + + restTaskModel = restClient.authenticateUser(owner).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("completed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("completed"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify owner cannot update task from status completed to delegated and response is 404") + public void ownerCannotUpdateTaskFromCompletedToDelegated() throws Exception + { + restTaskModel = restClient.authenticateUser(owner) + .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("completed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("completed"); + + restClient.authenticateUser(owner) + .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("delegated"); + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED).assertLastError() + .containsErrorKey(String.format(RestErrorModel.TASK_ALREADY_COMPLETED, taskModel.getId())) + .containsSummary(String.format(RestErrorModel.TASK_ALREADY_COMPLETED, taskModel.getId())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify assignee cannot update task from status completed to delegated and response is 404") + public void assigneeCannotUpdateTaskFromCompletedToDelegated() throws Exception + { + restTaskModel = restClient.authenticateUser(owner) + .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("completed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("completed"); + + restClient.authenticateUser(assigneeUser) + .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("delegated"); + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED).assertLastError() + .containsErrorKey(String.format(RestErrorModel.TASK_ALREADY_COMPLETED, taskModel.getId())) + .containsSummary(String.format(RestErrorModel.TASK_ALREADY_COMPLETED, taskModel.getId())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify owner cannot update task from status completed to resolved and response is 404") + public void ownerCannotUpdateTaskFromCompletedToResolved() throws Exception + { + restTaskModel = restClient.authenticateUser(owner) + .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("completed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("completed"); + + restClient.authenticateUser(owner) + .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("resolved"); + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED).assertLastError() + .containsErrorKey(String.format(RestErrorModel.TASK_ALREADY_COMPLETED, taskModel.getId())) + .containsSummary(String.format(RestErrorModel.TASK_ALREADY_COMPLETED, taskModel.getId())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify assignee cannot update task from status completed to resolved and response is 404") + public void assigneeCannotUpdateTaskFromCompletedToResolved() throws Exception + { + restTaskModel = restClient.authenticateUser(owner) + .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("completed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("completed"); + + restClient.authenticateUser(assigneeUser) + .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("resolved"); + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED).assertLastError() + .containsErrorKey(String.format(RestErrorModel.TASK_ALREADY_COMPLETED, taskModel.getId())) + .containsSummary(String.format(RestErrorModel.TASK_ALREADY_COMPLETED, taskModel.getId())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify owner cannot update task from status completed to completed and response is 404") + public void ownerCannotUpdateTaskFromCompletedToCompleted() throws Exception + { + restTaskModel = restClient.authenticateUser(owner) + .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("completed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("completed"); + + restClient.authenticateUser(owner) + .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("completed"); + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED).assertLastError() + .containsErrorKey(String.format(RestErrorModel.TASK_ALREADY_COMPLETED, taskModel.getId())) + .containsSummary(String.format(RestErrorModel.TASK_ALREADY_COMPLETED, taskModel.getId())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify assignee cannot update task from status completed to completed and response is 404") + public void assigneeCannotUpdateTaskFromCompletedToCompleted() throws Exception + { + restTaskModel = restClient.authenticateUser(owner) + .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("completed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("completed"); + + restClient.authenticateUser(assigneeUser) + .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("completed"); + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED).assertLastError() + .containsErrorKey(String.format(RestErrorModel.TASK_ALREADY_COMPLETED, taskModel.getId())) + .containsSummary(String.format(RestErrorModel.TASK_ALREADY_COMPLETED, taskModel.getId())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify owner can update task from status claimed to unclaimed and response is 200") + public void ownerCanUpdateTaskFromClaimedToUnclaimed() throws Exception + { + restTaskModel = restClient.authenticateUser(owner).withWorkflowAPI().usingTask(taskModel).getTask(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("claimed"); + + restTaskModel = restClient.authenticateUser(owner) + .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("unclaimed"); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("unclaimed"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify assignee can update task from status claimed to unclaimed and response is 200") + public void assigneeCanUpdateTaskFromClaimedToUnclaimed() throws Exception + { + restTaskModel = restClient.authenticateUser(owner).withWorkflowAPI().usingTask(taskModel).getTask(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("claimed"); + + restTaskModel = restClient.authenticateUser(assigneeUser) + .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("unclaimed"); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("unclaimed"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify owner can update task from status claimed to delegated and response is 200") + public void ownerCanUpdateTaskFromClaimedToDelegated() throws Exception + { + restTaskModel = restClient.authenticateUser(owner).withWorkflowAPI().usingTask(taskModel).getTask(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("claimed"); + + UserModel newAssignee = dataUser.createRandomTestUser(); + JsonObject inputJson = JsonBodyGenerator.defineJSON() + .add("state", "delegated") + .add("assignee", newAssignee.getUsername()).build(); + + restTaskModel = restClient.authenticateUser(owner) + .withParams("select=state,assignee").withWorkflowAPI().usingTask(taskModel).updateTask(inputJson); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("delegated") + .and().field("assignee").is(newAssignee.getUsername()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify assignee can update task from status claimed to delegated and response is 200") + public void assigneeCanUpdateTaskFromClaimedToDelegated() throws Exception + { + restTaskModel = restClient.authenticateUser(owner).withWorkflowAPI().usingTask(taskModel).getTask(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("claimed"); + + UserModel newAssignee = dataUser.createRandomTestUser(); + JsonObject inputJson = JsonBodyGenerator.defineJSON() + .add("state", "delegated") + .add("assignee", newAssignee.getUsername()).build(); + + restTaskModel = restClient.authenticateUser(assigneeUser) + .withParams("select=state,assignee").withWorkflowAPI().usingTask(taskModel).updateTask(inputJson); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("delegated") + .and().field("assignee").is(newAssignee.getUsername()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify owner can update task from status claimed to resolved and response is 200") + public void ownerCanUpdateTaskFromClaimedToResolved() throws Exception + { + restTaskModel = restClient.authenticateUser(owner).withWorkflowAPI().usingTask(taskModel).getTask(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("claimed"); + + restTaskModel = restClient.authenticateUser(owner) + .withParams("select=state,assignee").withWorkflowAPI().usingTask(taskModel).updateTask("resolved"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("resolved"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify assignee can update task from status claimed to resolved and response is 200") + public void assigneeCanUpdateTaskFromClaimedToResolved() throws Exception + { + restTaskModel = restClient.authenticateUser(owner).withWorkflowAPI().usingTask(taskModel).getTask(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("claimed"); + + restTaskModel = restClient.authenticateUser(assigneeUser) + .withParams("select=state,assignee").withWorkflowAPI().usingTask(taskModel).updateTask("resolved"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("resolved"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify owner cannot update task from status claimed to claimed and response is 409") + public void ownerCannotUpdateTaskFromClaimedToClaimed() throws Exception + { + restTaskModel = restClient.authenticateUser(owner).withWorkflowAPI().usingTask(taskModel).getTask(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("claimed"); + + restTaskModel = restClient.authenticateUser(owner) + .withParams("select=state,assignee").withWorkflowAPI().usingTask(taskModel).updateTask("claimed"); + restClient.assertStatusCodeIs(HttpStatus.CONFLICT).assertLastError() + .containsErrorKey(RestErrorModel.TASK_ALREADY_CLAIMED) + .containsSummary(RestErrorModel.TASK_ALREADY_CLAIMED) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify assignee can update task from status claimed to claimed and response is 200") + public void assigneeCanUpdateTaskFromClaimedToClaimed() throws Exception + { + restTaskModel = restClient.authenticateUser(owner).withWorkflowAPI().usingTask(taskModel).getTask(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("claimed"); + + restTaskModel = restClient.authenticateUser(assigneeUser) + .withParams("select=state,assignee").withWorkflowAPI().usingTask(taskModel).updateTask("claimed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("claimed"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify task owner can complete task with valid variables and response is 200") + public void taskOwnerCanCompleteTaskWithValidVariables() throws Exception + { + JsonObject inputJson = JsonBodyGenerator.defineJSON() + .add("state", "completed") + .add("variables", JsonBodyGenerator.defineJSONArray() + .add(JsonBodyGenerator.defineJSON() + .add("name", "bpm_priority") + .add("type", "d:int") + .add("value", 3) + .add("scope", "global").build()) + ).build(); + + restTaskModel = restClient.authenticateUser(owner) + .withParams("select=state,variables").withWorkflowAPI().usingTask(taskModel).updateTask(inputJson); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("priority").is(1) + .and().field("state").is("completed") + .and().field("assignee").is(taskModel.getAssignee()); + RestVariableModelsCollection variables = restClient.authenticateUser(owner).withWorkflowAPI().usingTask(restTaskModel).getTaskVariables(); + restClient.assertStatusCodeIs(HttpStatus.OK); + variables.getVariableByName("bpm_priority").assertThat().field("scope").is("global") + .and().field("name").is("bpm_priority") + .and().field("type").is("d:int") + .and().field("value").is(3); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify task owner cannot complete task with empty variables array and response is 200") + public void taskOwnerCannotUpdateTaskWithEmptyVariablesArray() throws Exception + { + JsonObject inputJson = JsonBodyGenerator.defineJSON() + .add("state", "completed") + .add("variables", JsonBodyGenerator.defineJSONArray() + ).build(); + + restTaskModel = restClient.authenticateUser(owner) + .withParams("select=state,variables").withWorkflowAPI().usingTask(taskModel).updateTask(inputJson); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("priority").is(1) + .and().field("state").is("completed") + .and().field("assignee").is(taskModel.getAssignee()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify task owner cannot complete task with empty variables json body and response is 200") + public void taskOwnerCannotUpdateTaskWithEmptyVariablesJsonBody() throws Exception + { + JsonObject inputJson = JsonBodyGenerator.defineJSON() + .add("state", "completed") + .add("variables", JsonBodyGenerator.defineJSONArray() + .add(JsonBodyGenerator.defineJSON().build()) + ).build(); + + restTaskModel = restClient.authenticateUser(owner) + .withParams("select=state,variables").withWorkflowAPI().usingTask(taskModel).updateTask(inputJson); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsErrorKey(RestErrorModel.VARIABLE_NAME_REQUIRED) + .containsSummary(RestErrorModel.VARIABLE_NAME_REQUIRED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify any user with no relation to task is forbidden to delegate other task with Rest API (403)") + public void anyUserIsForbiddenToDelegateOtherTask() throws Exception + { + restTaskModel = restClient.authenticateUser(anyUser).withWorkflowAPI().usingTask(taskModel).updateTask("delegated"); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary("Permission was denied"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify any user with no relation to task is forbidden to resolve other task with Rest API (403)") + public void anyUserIsForbiddenToResolveOtherTask() throws Exception + { + restTaskModel = restClient.authenticateUser(anyUser).withWorkflowAPI().usingTask(taskModel).updateTask("resolved"); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary("Permission was denied"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify any user with no relation to task is forbidden to claim other task with Rest API (403)") + public void anyUserIsForbiddenToClaimOtherTask() throws Exception + { + restTaskModel = restClient.authenticateUser(anyUser).withWorkflowAPI().usingTask(taskModel).updateTask("claimed"); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary("Permission was denied"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify any user with no relation to task is forbidden to unclaim other task with Rest API (403)") + public void anyUserIsForbiddenToUnclaimOtherTask() throws Exception + { + restTaskModel = restClient.authenticateUser(anyUser).withWorkflowAPI().usingTask(taskModel).updateTask("unclaimed"); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary("Permission was denied"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify user cannot delegate task with emty assignee name and response is 400") + public void updateTaskWithEmptyAssigneeValue() throws Exception + { + JsonObject inputJson = JsonBodyGenerator.defineJSON() + .add("state", "delegated") + .add("assignee", "") + .build(); + + restTaskModel = restClient.authenticateUser(owner) + .withParams("select=state,assignee").withWorkflowAPI().usingTask(taskModel).updateTask(inputJson); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsErrorKey(RestErrorModel.DELEGATING_ASSIGNEE_PROVIDED) + .containsSummary(RestErrorModel.DELEGATING_ASSIGNEE_PROVIDED) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify owner can resolve task when assignee is the owner and response is 200") + public void taskOwnerUpdateTaskResolveStateAndOwnerAssignee() throws Exception + { + JsonObject inputJson = JsonBodyGenerator.defineJSON() + .add("state", "resolved") + .add("assignee", owner.getUsername()) + .build(); + + restTaskModel = restClient.authenticateUser(owner) + .withParams("select=state,assignee").withWorkflowAPI().usingTask(taskModel).updateTask(inputJson); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("state").is("resolved") + .and().field("assignee").isNull(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify owner cannot update task after it was deleted and response is 404") + public void updateTaskAfterItWasDeleted() throws Exception + { + ProcessModel process = new ProcessModel(); + process.setId(taskModel.getProcessId()); + dataWorkflow.usingUser(owner).deleteProcess(process); + + restTaskModel = restClient.authenticateUser(owner) + .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("completed"); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .containsSummary(String.format(RestErrorModel.ENTITY_WAS_NOT_FOUND, taskModel.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify task owner cannot update task with empty input body and response is 400") + public void taskOwnerCannotUpdateTaskWithEmptyInputBody() throws Exception + { + JsonObject inputJson = JsonBodyGenerator.defineJSON().build(); + + restTaskModel = restClient.authenticateUser(owner) + .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask(inputJson); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsErrorKey(String.format(RestErrorModel.TASK_INVALID_STATE, "null")) + .containsSummary(String.format(RestErrorModel.TASK_INVALID_STATE, "null")); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify any user cannot update task using another name") + public void anyUserCannotUpdateTaskUsingAnotherName() throws Exception + { + JsonObject inputJson = JsonBodyGenerator.defineJSON() + .add("name", "Review Task-updated") + .build(); + + restClient.authenticateUser(anyUser).withParams("select=name").withWorkflowAPI().usingTask(taskModel).updateTask(inputJson); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError() + .containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY) + .containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify any user cannot update task using another description") + public void anyUserCannotUpdateTaskUsingAnotherDescription() throws Exception + { + JsonObject inputJson = JsonBodyGenerator.defineJSON() + .add("description", "description updated") + .build(); + + restClient.authenticateUser(anyUser).withParams("select=description").withWorkflowAPI().usingTask(taskModel).updateTask(inputJson); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError() + .containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY) + .containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify any user cannot update task using another dueAt") + public void anyUserCannotUpdateTaskUsingAnotherDueAt() throws Exception + { + JsonObject inputJson = JsonBodyGenerator.defineJSON() + .add("dueAt", "2025-01-01T11:57:32.000+0000") + .build(); + + restClient.authenticateUser(anyUser).withParams("select=dueAt").withWorkflowAPI().usingTask(taskModel).updateTask(inputJson); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError() + .containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY) + .containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify any user cannot update task using another priority") + public void anyUserCannotUpdateTaskUsingAnotherPriority() throws Exception + { + JsonObject inputJson = JsonBodyGenerator.defineJSON() + .add("priority", 3) + .build(); + + restClient.authenticateUser(anyUser).withParams("select=priority").withWorkflowAPI().usingTask(taskModel).updateTask(inputJson); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError() + .containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY) + .containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify any user cannot update task using another priority") + public void anyUserCannotUpdateTaskUsingAnotherOwner() throws Exception + { + UserModel newOwner = dataUser.createRandomTestUser(); + JsonObject inputJson = JsonBodyGenerator.defineJSON() + .add("owner", newOwner.getUsername()) + .build(); + + + restClient.authenticateUser(anyUser).withParams("select=owner").withWorkflowAPI().usingTask(taskModel).updateTask(inputJson); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError() + .containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY) + .containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify any user cannot update task using invalid name") + public void anyUserCannotUpdateTaskUsingInvalidName() throws Exception + { + restClient.authenticateUser(owner).withParams("select=name").withWorkflowAPI().usingTask(taskModel); + String postBody = "{\"name\":\"invalid-\"a\"}"; + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, postBody, "tasks/{taskId}?{parameters}", taskModel.getId(), restClient.getParameters()); + restTaskModel = restClient.processModel(RestTaskModel.class, request); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsErrorKey(String.format(RestErrorModel.NO_CONTENT, "Unexpected character ('a'")) + .containsSummary(String.format(RestErrorModel.NO_CONTENT, "Unexpected character ('a'")); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify any user cannot update task using invalid description") + public void anyUserCannotUpdateTaskUsingInvalidDescription() throws Exception + { + restClient.authenticateUser(owner).withParams("select=description").withWorkflowAPI().usingTask(taskModel); + String postBody = "{\"description\":\"invalid-\"a\"}"; + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, postBody, "tasks/{taskId}?{parameters}", taskModel.getId(), restClient.getParameters()); + restTaskModel = restClient.processModel(RestTaskModel.class, request); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsErrorKey(String.format(RestErrorModel.NO_CONTENT, "Unexpected character ('a'")) + .containsSummary(String.format(RestErrorModel.NO_CONTENT, "Unexpected character ('a'")); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify any user cannot update task using invalid dueAt") + public void anyUserCannotUpdateTaskUsingInvalidDueAt() throws Exception + { + JsonObject inputJson = JsonBodyGenerator.defineJSON() + .add("dueAt", "invalid-date") + .build(); + + restClient.authenticateUser(anyUser).withParams("select=dueAt").withWorkflowAPI().usingTask(taskModel).updateTask(inputJson); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify any user cannot update task using invalid priority") + public void anyUserCannotUpdateTaskUsingInvalidPriority() throws Exception + { + JsonObject inputJson = JsonBodyGenerator.defineJSON() + .add("priority", "a") + .build(); + + restClient.authenticateUser(anyUser).withParams("select=priority").withWorkflowAPI().usingTask(taskModel).updateTask(inputJson); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify any user cannot update task using invalid priority") + public void anyUserCannotUpdateTaskUsingInvalidOwner() throws Exception + { + restClient.authenticateUser(owner).withParams("select=owner").withWorkflowAPI().usingTask(taskModel); + String postBody = "{\"owner\":\"invalid-\"a\"}"; + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, postBody, "tasks/{taskId}?{parameters}", taskModel.getId(), restClient.getParameters()); + restTaskModel = restClient.processModel(RestTaskModel.class, request); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsErrorKey(String.format(RestErrorModel.NO_CONTENT, "Unexpected character ('a'")) + .containsSummary(String.format(RestErrorModel.NO_CONTENT, "Unexpected character ('a'")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify that task can be updated from unclaimed to claimed by task creator") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void taskCreatorCanUpdateTaskFromUnclaimedToClaimed() throws Exception + { + restTaskModel = restClient.authenticateUser(adminUser).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("unclaimed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("unclaimed"); + restTaskModel = restClient.authenticateUser(owner).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("claimed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("claimed"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify that task cannot be updated from unclaimed to claimed by a regular user not connected to the task") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void regularUserCannotUpdateTaskFromUnclaimedToClaimed() throws Exception + { + restTaskModel = restClient.authenticateUser(adminUser).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("unclaimed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("unclaimed"); + restTaskModel = restClient.authenticateUser(assigneeUser).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("claimed"); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError() + .containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY) + .containsSummary(RestErrorModel.PERMISSION_WAS_DENIED) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify that task can be updated from unclaimed to delegated by task creator") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void taskCreatorCanUpdateTaskFromUnclaimedToDelegated() throws Exception + { + restTaskModel = restClient.authenticateUser(adminUser).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("unclaimed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("unclaimed"); + + JsonObject inputJson = JsonBodyGenerator.defineJSON().add("state", "delegated").add("assignee", owner.getUsername()).build(); + + restTaskModel = restClient.authenticateUser(owner).withParams("select=state,assignee").withWorkflowAPI().usingTask(taskModel).updateTask(inputJson); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("delegated"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify that task cannot be updated from unclaimed to delegated by a regular user not connected to the task") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void regularUserCannotUpdateTaskFromUnclaimedToDelegated() throws Exception + { + restTaskModel = restClient.authenticateUser(adminUser).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("unclaimed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("unclaimed"); + + JsonObject inputJson = JsonBodyGenerator.defineJSON().add("state", "delegated").add("assignee", assigneeUser.getUsername()).build(); + + restTaskModel = restClient.authenticateUser(assigneeUser).withParams("select=state,assignee").withWorkflowAPI().usingTask(taskModel).updateTask(inputJson); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError() + .containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY) + .containsSummary(RestErrorModel.PERMISSION_WAS_DENIED) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify that task can be updated from unclaimed to resolved by task creator") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void taskCreatorCanUpdateTaskFromUnclaimedToResolved() throws Exception + { + restTaskModel = restClient.authenticateUser(adminUser).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("unclaimed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("unclaimed"); + restTaskModel = restClient.authenticateUser(owner).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("resolved"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("resolved"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify that task can be updated from unclaimed to resolved by a regular user not connected to the task") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void regularCanNotUpdateTaskFromUnclaimedToResolved() throws Exception + { + restTaskModel = restClient.authenticateUser(adminUser).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("unclaimed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("unclaimed"); + restTaskModel = restClient.authenticateUser(assigneeUser).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("resolved"); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError() + .containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY) + .containsSummary(RestErrorModel.PERMISSION_WAS_DENIED) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify that task can be updated from unclaimed to unclaimed by task creator") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void taskCreatorCanUpdateTaskFromUnclaimedToUnclaimed() throws Exception + { + restTaskModel = restClient.authenticateUser(adminUser).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("unclaimed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("unclaimed"); + restTaskModel = restClient.authenticateUser(owner).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("unclaimed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("unclaimed"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify that task can be updated from unclaimed to unclaimed by a regular user not connected to the task") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void regularUserCannotUpdateTaskFromUnclaimedToUnclaimed() throws Exception + { + restTaskModel = restClient.authenticateUser(adminUser).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("unclaimed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("unclaimed"); + restTaskModel = restClient.authenticateUser(assigneeUser).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("unclaimed"); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError() + .containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY) + .containsSummary(RestErrorModel.PERMISSION_WAS_DENIED) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Bug(id = "REPO-1982") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify that task can be updated from delegated to unclaimed by task creator") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void taskCreatorCanUpdateTaskFromDelegatedToUnclaimed() throws Exception + { + JsonObject inputJson = JsonBodyGenerator.defineJSON().add("state", "delegated").add("assignee", assigneeUser.getUsername()).build(); + restTaskModel = restClient.authenticateUser(adminUser).withParams("select=state,assignee").withWorkflowAPI().usingTask(taskModel).updateTask(inputJson); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("delegated"); + + restTaskModel = restClient.authenticateUser(owner).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("unclaimed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("unclaimed"); + } + + @Bug(id = "REPO-1982") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify that task can be updated from delegated to unclaimed by task assignee") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void taskAssigneeCanUpdateTaskFromDelegatedToUnclaimed() throws Exception + { + JsonObject inputJson = JsonBodyGenerator.defineJSON().add("state", "delegated").add("assignee", assigneeUser.getUsername()).build(); + restTaskModel = restClient.authenticateUser(adminUser).withParams("select=state,assignee").withWorkflowAPI().usingTask(taskModel).updateTask(inputJson); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("delegated"); + + restTaskModel = restClient.authenticateUser(assigneeUser).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("unclaimed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("unclaimed"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify that task cannot be updated from delegated to claimed since it is already claimed by task creator") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void taskCreatorCannotUpdateTaskFromDelegatedToClaimed() throws Exception + { + JsonObject inputJson = JsonBodyGenerator.defineJSON().add("state", "delegated").add("assignee", assigneeUser.getUsername()).build(); + restTaskModel = restClient.authenticateUser(adminUser).withParams("select=state,assignee").withWorkflowAPI().usingTask(taskModel).updateTask(inputJson); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("delegated"); + + restTaskModel = restClient.authenticateUser(owner).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("claimed"); + restClient.assertStatusCodeIs(HttpStatus.CONFLICT).assertLastError() + .containsErrorKey(RestErrorModel.TASK_ALREADY_CLAIMED) + .containsSummary(RestErrorModel.TASK_ALREADY_CLAIMED) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify that task can be updated from delegated to claimed since it is already claimed by task assignee") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void taskAssigneeCanUpdateTaskFromDelegatedToClaimed() throws Exception + { + JsonObject inputJson = JsonBodyGenerator.defineJSON().add("state", "delegated").add("assignee", assigneeUser.getUsername()).build(); + restTaskModel = restClient.authenticateUser(adminUser).withParams("select=state,assignee").withWorkflowAPI().usingTask(taskModel).updateTask(inputJson); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("delegated"); + + restTaskModel = restClient.authenticateUser(assigneeUser).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("claimed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("delegated"); + } + + @Bug(id = "REPO-1924") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify that task can be updated from delegated to completed by task creator") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void taskCreatorCanUpdateTaskFromDelegatedToCompleted() throws Exception + { + JsonObject inputJson = JsonBodyGenerator.defineJSON().add("state", "delegated").add("assignee", assigneeUser.getUsername()).build(); + restTaskModel = restClient.authenticateUser(adminUser).withParams("select=state,assignee").withWorkflowAPI().usingTask(taskModel).updateTask(inputJson); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("delegated"); + + restTaskModel = restClient.authenticateUser(owner).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("completed"); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY).assertLastError() + .containsErrorKey(RestErrorModel.API_DEFAULT_ERRORKEY) + .containsSummary(RestErrorModel.DELEGATED_TASK_CAN_NOT_BE_COMPLETED) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Bug(id = "REPO-1924") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify that task can be updated from delegated to completed by task assignee") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void taskAssigneeCanUpdateTaskFromDelegatedToCompleted() throws Exception + { + JsonObject inputJson = JsonBodyGenerator.defineJSON().add("state", "delegated").add("assignee", assigneeUser.getUsername()).build(); + restTaskModel = restClient.authenticateUser(adminUser).withParams("select=state,assignee").withWorkflowAPI().usingTask(taskModel).updateTask(inputJson); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("delegated"); + + restTaskModel = restClient.authenticateUser(assigneeUser).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("completed"); + restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY).assertLastError() + .containsErrorKey(RestErrorModel.API_DEFAULT_ERRORKEY) + .containsSummary(RestErrorModel.DELEGATED_TASK_CAN_NOT_BE_COMPLETED) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify that task can be updated from delegated to resolved") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void taskCreatorCanUpdateTaskFromDelegatedToResolved() throws Exception + { + JsonObject inputJson = JsonBodyGenerator.defineJSON().add("state", "delegated").add("assignee", assigneeUser.getUsername()).build(); + restTaskModel = restClient.authenticateUser(adminUser).withParams("select=state,assignee").withWorkflowAPI().usingTask(taskModel).updateTask(inputJson); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("delegated"); + + restTaskModel = restClient.authenticateUser(owner).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("resolved"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("resolved"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify that task can be updated from delegated to resolved by task assignee") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void taskAssigneeCanUpdateTaskFromDelegatedToResolved() throws Exception + { + JsonObject inputJson = JsonBodyGenerator.defineJSON().add("state", "delegated").add("assignee", assigneeUser.getUsername()).build(); + restTaskModel = restClient.authenticateUser(adminUser).withParams("select=state,assignee").withWorkflowAPI().usingTask(taskModel).updateTask(inputJson); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("delegated"); + + restTaskModel = restClient.authenticateUser(assigneeUser).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("resolved"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("resolved"); + } + + @Bug(id = "REPO-1982") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify that task can be updated from resolved to unclaimed by task creator") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void taskCreatorCanUpdateTaskFromResolvedToUnclaimed() throws Exception + { + restTaskModel = restClient.authenticateUser(owner).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("resolved"); + + restTaskModel = restClient.authenticateUser(owner).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("unclaimed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("resolved"); + } + + @Bug(id = "REPO-1982") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify that task cannot be updated from resolved to unclaimed by task assignee") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void taskAssigneeCannotUpdateTaskFromResolvedToUnclaimed() throws Exception + { + restTaskModel = restClient.authenticateUser(assigneeUser).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("resolved"); + + restTaskModel = restClient.authenticateUser(assigneeUser).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("unclaimed"); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError() + .containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY) + .containsSummary(RestErrorModel.PERMISSION_WAS_DENIED) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Bug(id = "REPO-1982") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify that task cannot be updated from resolved to claimed by task owner") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void taskOwnerCanUpdateTaskFromResolvedToClaimed() throws Exception + { + restTaskModel = restClient.authenticateUser(adminUser).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("resolved"); + + restTaskModel = restClient.authenticateUser(owner).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("claimed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("resolved"); + } + + @Bug(id = "REPO-1982") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify that task cannot be updated from resolved to claimed by task assignee") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void taskAssigneeCanUpdateTaskFromResolvedToClaimed() throws Exception + { + restTaskModel = restClient.authenticateUser(adminUser).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("resolved"); + + restTaskModel = restClient.authenticateUser(assigneeUser).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("claimed"); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError() + .containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY) + .containsSummary(RestErrorModel.PERMISSION_WAS_DENIED) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Bug(id = "REPO-1982") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify that task can be updated from resolved to delegated by task creator") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void taskCreatorCannotUpdateTaskFromResolvedToDelegated() throws Exception + { + restTaskModel = restClient.authenticateUser(adminUser).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("resolved"); + + JsonObject inputJson = JsonBodyGenerator.defineJSON().add("state", "delegated").add("assignee", assigneeUser.getUsername()).build(); + restTaskModel = restClient.authenticateUser(owner).withParams("select=state,assignee").withWorkflowAPI().usingTask(taskModel).updateTask(inputJson); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("delegated"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify that task can be updated from resolved to delegated by task assignee") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void taskAssigneeCannotUpdateTaskFromResolvedToDelegated() throws Exception + { + restTaskModel = restClient.authenticateUser(adminUser).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("resolved"); + + JsonObject inputJson = JsonBodyGenerator.defineJSON().add("state", "delegated").add("assignee", assigneeUser.getUsername()).build(); + restTaskModel = restClient.authenticateUser(assigneeUser).withParams("select=state,assignee").withWorkflowAPI().usingTask(taskModel).updateTask(inputJson); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError() + .containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY) + .containsSummary(RestErrorModel.PERMISSION_WAS_DENIED) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Bug(id = "REPO-1982") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify that task can be updated from resolved to resolved by task creator") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void taskCreatorCannotUpdateTaskFromResolvedToResolved() throws Exception + { + restTaskModel = restClient.authenticateUser(adminUser).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("resolved"); + + restTaskModel = restClient.authenticateUser(owner).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("resolved"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()).and().field("state").is("resolved"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify that task can be updated from resolved to resolved by task assignee") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void taskAssigneeCannotUpdateTaskFromResolvedToResolved() throws Exception + { + restTaskModel = restClient.authenticateUser(adminUser).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("resolved"); + + restTaskModel = restClient.authenticateUser(assigneeUser).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("resolved"); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError() + .containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY) + .containsSummary(RestErrorModel.PERMISSION_WAS_DENIED) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Bug(id = "REPO-1982") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Update task by providing empty select value") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void updateTaskByProvidingEmptySelectValue() throws Exception + { + restTaskModel = restClient.authenticateUser(owner).withParams("select=").withWorkflowAPI().usingTask(taskModel).updateTask("resolved"); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsErrorKey(RestErrorModel.INVALID_SELECT_ERRORKEY) + .containsSummary(RestErrorModel.INVALID_SELECT) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Update task by providing empty state value") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void updateTaskByProvidingEmptyStateValue() throws Exception + { + restTaskModel = restClient.authenticateUser(owner).withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask(" "); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsErrorKey(String.format(RestErrorModel.TASK_INVALID_STATE, " ")) + .containsSummary(String.format(RestErrorModel.TASK_INVALID_STATE, " ")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/candidates/GetTaskCandidatesRegressionTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/candidates/GetTaskCandidatesRegressionTests.java new file mode 100644 index 0000000000..ba5901cc37 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/candidates/GetTaskCandidatesRegressionTests.java @@ -0,0 +1,264 @@ +package org.alfresco.rest.workflow.tasks.candidates; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestCandidateModelsCollection; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.GroupModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TaskModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * + * @author bogdan.bocancea + * + */ +public class GetTaskCandidatesRegressionTests extends RestTest +{ + private UserModel userModel, userModel1, userModel2; + private SiteModel siteModel; + private FileModel fileModel; + private TaskModel taskModel; + private GroupModel group; + private RestCandidateModelsCollection candidateModels; + + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + userModel = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); + fileModel = dataContent.usingUser(userModel).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + userModel1 = dataUser.createRandomTestUser(); + userModel2 = dataUser.createRandomTestUser(); + group = dataGroup.createRandomGroup(); + dataGroup.addListOfUsersToGroup(group, userModel1, userModel2); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify get task candidates with invalid task id") + public void getTaskCandidatesWithInvalidTaskId() throws Exception + { + taskModel = dataWorkflow.usingUser(userModel) + .usingSite(siteModel) + .usingResource(fileModel).createPooledReviewTaskAndAssignTo(group); + taskModel.setId("invalid-id"); + restClient.authenticateUser(userModel).withWorkflowAPI().usingTask(taskModel).getTaskCandidates(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "invalid-id")) + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .stackTraceIs(RestErrorModel.STACKTRACE) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify get task candidates with empty task id") + public void getTaskCandidatesWithEmptyTaskId() throws Exception + { + taskModel = dataWorkflow.usingUser(userModel) + .usingSite(siteModel) + .usingResource(fileModel).createPooledReviewTaskAndAssignTo(group); + taskModel.setId(""); + restClient.authenticateUser(userModel).withWorkflowAPI().usingTask(taskModel).getTaskCandidates(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "")); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify get task candidates for completed task") + public void getTaskCandidatesForCompletedTask() throws Exception + { + taskModel = dataWorkflow.usingUser(userModel) + .usingSite(siteModel) + .usingResource(fileModel).createPooledReviewTaskAndAssignTo(group); + + restClient.authenticateUser(userModel1).withWorkflowAPI().usingTask(taskModel).getTaskCandidates(); + restClient.assertStatusCodeIs(HttpStatus.OK); + + dataWorkflow.usingUser(userModel1).taskDone(taskModel); + + restClient.authenticateUser(userModel1).withWorkflowAPI().usingTask(taskModel).getTaskCandidates(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, taskModel.getId())); + + restClient.authenticateUser(userModel).withWorkflowAPI().usingTask(taskModel).getTaskCandidates(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, taskModel.getId())); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify get task candidates by non candidate user") + public void getTaskCandidatesByNonCandidateUser() throws Exception + { + UserModel outsider = dataUser.createRandomTestUser(); + taskModel = dataWorkflow.usingUser(userModel) + .usingSite(siteModel) + .usingResource(fileModel).createPooledReviewTaskAndAssignTo(group); + restClient.authenticateUser(outsider).withWorkflowAPI().usingTask(taskModel).getTaskCandidates(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @Bug(id="MNT-17438") + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Get task candidates with skip count parameter") + public void getTaskCandidatesWithSkipCount() throws Exception + { + taskModel = dataWorkflow.usingUser(userModel) + .usingSite(siteModel) + .usingResource(fileModel).createPooledReviewTaskAndAssignTo(group); + candidateModels = restClient.authenticateUser(userModel).withWorkflowAPI() + .usingParams("skipCount=1").usingTask(taskModel).getTaskCandidates(); + restClient.assertStatusCodeIs(HttpStatus.OK); + candidateModels.assertThat() + .entriesListIsNotEmpty() + .and().paginationField("count").is("0"); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Get task candidates with max items parameter set to 0") + public void getTaskCandidatesWithZeroMaxItems() throws Exception + { + taskModel = dataWorkflow.usingUser(userModel) + .usingSite(siteModel) + .usingResource(fileModel).createPooledReviewTaskAndAssignTo(group); + candidateModels = restClient.authenticateUser(userModel).withWorkflowAPI() + .usingParams("maxItems=0").usingTask(taskModel).getTaskCandidates(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsErrorKey(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS) + .containsSummary(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS) + .stackTraceIs(RestErrorModel.STACKTRACE) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Get task candidates with max items parameter") + public void getTaskCandidatesWithMaxItems() throws Exception + { + taskModel = dataWorkflow.usingUser(userModel) + .usingSite(siteModel) + .usingResource(fileModel).createPooledReviewTaskAndAssignTo(group); + candidateModels = restClient.authenticateUser(userModel).withWorkflowAPI() + .usingParams("maxItems=2").usingTask(taskModel).getTaskCandidates(); + restClient.assertStatusCodeIs(HttpStatus.OK); + candidateModels.assertThat() + .entriesListIsNotEmpty() + .and().paginationField("count").is("1"); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Get task candidates with properties") + public void getTaskCandidatesWithProperties() throws Exception + { + taskModel = dataWorkflow.usingUser(userModel) + .usingSite(siteModel) + .usingResource(fileModel).createPooledReviewTaskAndAssignTo(group); + candidateModels = restClient.authenticateUser(userModel).withWorkflowAPI() + .usingParams("properties=candidateId").usingTask(taskModel).getTaskCandidates(); + restClient.assertStatusCodeIs(HttpStatus.OK); + candidateModels.getEntries().get(0).onModel().assertThat() + .field("candidateId").contains(group.getGroupIdentifier()).and() + .field("candidateType").isNull(); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Get task candidates with invalid properties") + public void getTaskCandidatesWithInvalidProperties() throws Exception + { + taskModel = dataWorkflow.usingUser(userModel) + .usingSite(siteModel) + .usingResource(fileModel).createPooledReviewTaskAndAssignTo(group); + candidateModels = restClient.authenticateUser(userModel).withWorkflowAPI() + .usingParams("properties=unknown-prop").usingTask(taskModel).getTaskCandidates(); + restClient.assertStatusCodeIs(HttpStatus.OK); + candidateModels.getEntries().get(0).onModel().assertThat() + .fieldsCount().is(0).and(); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Get task candidates by deleted candidate") + public void getTaskCandidatesByDeletedCandidate() throws Exception + { + UserModel newUser = dataUser.createRandomTestUser(); + dataGroup.addListOfUsersToGroup(group, newUser); + taskModel = dataWorkflow.usingUser(userModel) + .usingSite(siteModel) + .usingResource(fileModel).createPooledReviewTaskAndAssignTo(group); + restClient.authenticateUser(newUser).withWorkflowAPI() + .usingTask(taskModel).getTaskCandidates(); + restClient.assertStatusCodeIs(HttpStatus.OK); + + dataUser.usingAdmin().deleteUser(newUser); + + restClient.authenticateUser(newUser).withWorkflowAPI() + .usingTask(taskModel).getTaskCandidates(); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Get task candidates by deleted group") + public void getTaskCandidatesByDeletedGroup() throws Exception + { + GroupModel deletedGroup = dataGroup.createRandomGroup(); + UserModel newUser = dataUser.createRandomTestUser(); + dataGroup.addListOfUsersToGroup(deletedGroup, userModel2, newUser); + taskModel = dataWorkflow.usingUser(userModel) + .usingSite(siteModel) + .usingResource(fileModel).createPooledReviewTaskAndAssignTo(deletedGroup); + restClient.authenticateUser(newUser).withWorkflowAPI() + .usingTask(taskModel).getTaskCandidates(); + restClient.assertStatusCodeIs(HttpStatus.OK); + + dataGroup.usingAdmin().deleteGroup(deletedGroup); + + restClient.authenticateUser(newUser).withWorkflowAPI() + .usingTask(taskModel).getTaskCandidates(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError().containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY) + .containsSummary(RestErrorModel.PERMISSION_WAS_DENIED) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Get task candidates by user that was removed from group") + public void getTaskCandidatesByUserRemovedFromGroup() throws Exception + { + UserModel newUser = dataUser.createRandomTestUser(); + dataGroup.addListOfUsersToGroup(group, newUser); + taskModel = dataWorkflow.usingUser(userModel) + .usingSite(siteModel) + .usingResource(fileModel).createPooledReviewTaskAndAssignTo(group); + restClient.authenticateUser(newUser).withWorkflowAPI() + .usingTask(taskModel).getTaskCandidates(); + restClient.assertStatusCodeIs(HttpStatus.OK); + + dataGroup.usingAdmin().removeUserFromGroup(group, newUser); + + restClient.authenticateUser(newUser).withWorkflowAPI() + .usingTask(taskModel).getTaskCandidates(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError().containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY) + .containsSummary(RestErrorModel.PERMISSION_WAS_DENIED) + .stackTraceIs(RestErrorModel.STACKTRACE); + } +} \ No newline at end of file diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/candidates/GetTaskCandidatesSanityTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/candidates/GetTaskCandidatesSanityTests.java new file mode 100644 index 0000000000..b49fc3a726 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/candidates/GetTaskCandidatesSanityTests.java @@ -0,0 +1,79 @@ +package org.alfresco.rest.workflow.tasks.candidates; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestCandidateModelsCollection; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.GroupModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TaskModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * + * @author Cristina Axinte + * + */ + +public class GetTaskCandidatesSanityTests extends RestTest +{ + private UserModel userModel, user, userModel1, userModel2; + private SiteModel siteModel; + private FileModel fileModel; + private TaskModel taskModel; + private GroupModel group; + private RestCandidateModelsCollection candidateModels; + + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + userModel = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); + fileModel = dataContent.usingUser(userModel).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + user = dataUser.createRandomTestUser(); + userModel1 = dataUser.createRandomTestUser(); + userModel2 = dataUser.createRandomTestUser(); + group = dataGroup.createRandomGroup(); + dataGroup.addListOfUsersToGroup(group, userModel1, userModel2); + taskModel = dataWorkflow.usingUser(user).usingSite(siteModel).usingResource(fileModel).createPooledReviewTaskAndAssignTo(group); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.SANITY, + description = "Verify that admin gets task candidates") + public void getTaskCandidatesByAdmin() throws Exception + { + candidateModels = restClient.authenticateUser(dataUser.getAdminUser()).withWorkflowAPI().usingTask(taskModel).getTaskCandidates(); + restClient.assertStatusCodeIs(HttpStatus.OK); + candidateModels.assertThat().entriesListContains("candidateType", "group") + .and().entriesListContains("candidateId", String.format("GROUP_%s", group.getGroupIdentifier())); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.SANITY, + description = "Verify that user that started the process gets task candidates") + public void getTaskCandidatesByUserWhoStartedProcess() throws Exception + { + candidateModels = restClient.authenticateUser(user).withWorkflowAPI().usingTask(taskModel).getTaskCandidates(); + restClient.assertStatusCodeIs(HttpStatus.OK); + candidateModels.assertThat().entriesListContains("candidateType", "group") + .and().entriesListContains("candidateId", String.format("GROUP_%s", group.getGroupIdentifier())); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.SANITY, + description = "Verify that user from the assighed group to the process gets task candidates") + public void getTaskCandidatesByCandidateUser() throws Exception + { + candidateModels = restClient.authenticateUser(userModel1).withWorkflowAPI().usingTask(taskModel).getTaskCandidates(); + restClient.assertStatusCodeIs(HttpStatus.OK); + candidateModels.assertThat().entriesListContains("candidateType", "group") + .and().entriesListContains("candidateId", String.format("GROUP_%s", group.getGroupIdentifier())); + } +} \ No newline at end of file diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/items/AddTaskItemTestsBulk1.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/items/AddTaskItemTestsBulk1.java new file mode 100644 index 0000000000..e7b168147a --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/items/AddTaskItemTestsBulk1.java @@ -0,0 +1,158 @@ +package org.alfresco.rest.workflow.tasks.items; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestItemModel; +import org.alfresco.rest.model.RestItemModelsCollection; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TaskModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + + +public class AddTaskItemTestsBulk1 extends RestTest +{ + private UserModel userModel, userWhoStartsTask, assigneeUser; + private SiteModel siteModel; + private FileModel fileModel, document2, document3; + private TaskModel taskModel; + private RestItemModelsCollection taskItems; + private RestItemModel taskItem; + + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + userModel = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); + fileModel = dataContent.usingUser(userModel).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + userWhoStartsTask = dataUser.createRandomTestUser(); + assigneeUser = dataUser.createRandomTestUser(); + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assigneeUser); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.SANITY, + description = "Create non-existing task item") + public void createTaskItem() throws Exception + { + UserModel adminUser = dataUser.getAdminUser(); + restClient.authenticateUser(adminUser); + document2 = dataContent.usingSite(siteModel).createContent(DocumentType.XML); + + taskItem = restClient.withWorkflowAPI().usingTask(taskModel).addTaskItem(document2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + taskItem.assertThat().field("createdAt").is(taskItem.getCreatedAt()) + .assertThat().field("size").is(taskItem.getSize()) + .assertThat().field("createdBy").is(taskItem.getCreatedBy()) + .assertThat().field("modifiedAt").is(taskItem.getModifiedAt()) + .assertThat().field("name").is(taskItem.getName()) + .assertThat().field("modifiedBy").is(taskItem.getModifiedBy()) + .assertThat().field("id").is(taskItem.getId()) + .assertThat().field("mimeType").is(taskItem.getMimeType()); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.SANITY, + description = "Create multiple non-existing task item") + public void createMultipleTaskItem() throws Exception + { + UserModel adminUser = dataUser.getAdminUser(); + restClient.authenticateUser(adminUser); + document2 = dataContent.usingSite(siteModel).createContent(DocumentType.XML); + + taskItems = restClient.withWorkflowAPI().usingTask(taskModel).addTaskItems(document2, fileModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + taskItems.getEntries().get(0).onModel() + .assertThat().field("createdAt").is(taskItems.getEntries().get(0).onModel().getCreatedAt()) + .assertThat().field("size").is(taskItems.getEntries().get(0).onModel().getSize()) + .assertThat().field("createdBy").is(taskItems.getEntries().get(0).onModel().getCreatedBy()) + .assertThat().field("modifiedAt").is(taskItems.getEntries().get(0).onModel().getModifiedAt()) + .assertThat().field("name").is(taskItems.getEntries().get(0).onModel().getName()) + .assertThat().field("modifiedBy").is(taskItems.getEntries().get(0).onModel().getModifiedBy()) + .assertThat().field("id").is(taskItems.getEntries().get(0).onModel().getId()) + .assertThat().field("mimeType").is(taskItems.getEntries().get(0).onModel().getMimeType()); + + taskItems.getEntries().get(1).onModel() + .assertThat().field("createdAt").is(taskItems.getEntries().get(1).onModel().getCreatedAt()) + .assertThat().field("size").is(taskItems.getEntries().get(1).onModel().getSize()) + .assertThat().field("createdBy").is(taskItems.getEntries().get(1).onModel().getCreatedBy()) + .assertThat().field("modifiedAt").is(taskItems.getEntries().get(1).onModel().getModifiedAt()) + .assertThat().field("name").is(taskItems.getEntries().get(1).onModel().getName()) + .assertThat().field("modifiedBy").is(taskItems.getEntries().get(1).onModel().getModifiedBy()) + .assertThat().field("id").is(taskItems.getEntries().get(1).onModel().getId()) + .assertThat().field("mimeType").is(taskItems.getEntries().get(1).onModel().getMimeType()); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @Bug(id = "MNT-16966") + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify that in case task item exists the request fails") + public void createTaskItemThatAlreadyExists() throws Exception + { + UserModel adminUser = dataUser.getAdminUser(); + restClient.authenticateUser(adminUser); + document3 = dataContent.usingSite(siteModel).createContent(DocumentType.XML); + + taskItem = restClient.withWorkflowAPI().usingTask(taskModel).addTaskItem(document3); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + taskItem.assertThat().field("createdAt").is(taskItem.getCreatedAt()) + .assertThat().field("size").is(taskItem.getSize()) + .and().field("createdBy").is(taskItem.getCreatedBy()) + .and().field("modifiedAt").is(taskItem.getModifiedAt()) + .and().field("name").is(taskItem.getName()) + .and().field("modifiedBy").is(taskItem.getModifiedBy()) + .and().field("id").is(taskItem.getId()) + .and().field("mimeType").is(taskItem.getMimeType()); + + taskItem = restClient.withWorkflowAPI().usingTask(taskModel).addTaskItem(document3); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @Bug(id = "MNT-16966") + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify that in case task item exists the request fails") + public void createMultipleTaskItemThatAlreadyExists() throws Exception + { + UserModel adminUser = dataUser.getAdminUser(); + restClient.authenticateUser(adminUser); + document3 = dataContent.usingSite(siteModel).createContent(DocumentType.XML); + document2 = dataContent.usingSite(siteModel).createContent(DocumentType.XML); + + taskItems = restClient.withWorkflowAPI().usingTask(taskModel).addTaskItems(document3, document2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + taskItems.getEntries().get(0).onModel() + .assertThat().field("createdAt").is(taskItems.getEntries().get(0).onModel().getCreatedAt()) + .assertThat().field("size").is(taskItems.getEntries().get(0).onModel().getSize()) + .assertThat().field("createdBy").is(taskItems.getEntries().get(0).onModel().getCreatedBy()) + .assertThat().field("modifiedAt").is(taskItems.getEntries().get(0).onModel().getModifiedAt()) + .assertThat().field("name").is(taskItems.getEntries().get(0).onModel().getName()) + .assertThat().field("modifiedBy").is(taskItems.getEntries().get(0).onModel().getModifiedBy()) + .assertThat().field("id").is(taskItems.getEntries().get(0).onModel().getId()) + .assertThat().field("mimeType").is(taskItems.getEntries().get(0).onModel().getMimeType()); + + taskItems.getEntries().get(1).onModel() + .assertThat().field("createdAt").is(taskItems.getEntries().get(1).onModel().getCreatedAt()) + .assertThat().field("size").is(taskItems.getEntries().get(1).onModel().getSize()) + .assertThat().field("createdBy").is(taskItems.getEntries().get(1).onModel().getCreatedBy()) + .assertThat().field("modifiedAt").is(taskItems.getEntries().get(1).onModel().getModifiedAt()) + .assertThat().field("name").is(taskItems.getEntries().get(1).onModel().getName()) + .assertThat().field("modifiedBy").is(taskItems.getEntries().get(1).onModel().getModifiedBy()) + .assertThat().field("id").is(taskItems.getEntries().get(1).onModel().getId()) + .assertThat().field("mimeType").is(taskItems.getEntries().get(1).onModel().getMimeType()); + + taskItems = restClient.withWorkflowAPI().usingTask(taskModel).addTaskItems(document3, document2); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST); + } +} \ No newline at end of file diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/items/AddTaskItemTestsBulk2.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/items/AddTaskItemTestsBulk2.java new file mode 100644 index 0000000000..25cb8fe05a --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/items/AddTaskItemTestsBulk2.java @@ -0,0 +1,175 @@ +package org.alfresco.rest.workflow.tasks.items; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestVariableModel; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TaskModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class AddTaskItemTestsBulk2 extends RestTest +{ + private UserModel userModel, assigneeUser, anotherUser; + private SiteModel siteModel; + private FileModel fileModel, fileModel1; + private TaskModel taskModel; + private String taskId; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + userModel = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); + fileModel = dataContent.usingUser(userModel).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + fileModel1 = dataContent.usingUser(userModel).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + assigneeUser = dataUser.createRandomTestUser(); + taskModel = dataWorkflow.usingUser(userModel).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assigneeUser); + + taskId = taskModel.getId(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Add task item using random user.") + public void addTaskItemByRandomUser() throws Exception + { + anotherUser = dataUser.createRandomTestUser(); + restClient.authenticateUser(anotherUser).withWorkflowAPI().usingTask(taskModel).addTaskItem(fileModel); + + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError() + .containsSummary(RestErrorModel.PERMISSION_WAS_DENIED) + .containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Add multiple task item using random user.") + public void addMultipleTaskItemByRandomUser() throws Exception + { + anotherUser = dataUser.createRandomTestUser(); + restClient.authenticateUser(anotherUser).withWorkflowAPI().usingTask(taskModel) + .addTaskItems(fileModel,fileModel1); + + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED) + .containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE);; + } + + @Bug(id = "ACE-5683") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Adding task item, is falling in case invalid itemBody is provided") + public void failedAddingTaskItemIfInvalidItemBodyIsProvided() throws Exception + { + fileModel.setNodeRef("invalidNodeRef"); + restClient.authenticateUser(userModel).withWorkflowAPI().usingTask(taskModel).addTaskItem(fileModel); + + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "invalidNodeRef")) + .containsErrorKey(RestErrorModel.NOT_FOUND_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Bug(id = "ACE-5683") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Adding multiple task item, is falling in case invalid itemBody is provided") + public void failedAddingMultipleTaskItemIfInvalidItemBodyIsProvided() throws Exception + { + fileModel.setNodeRef("invalidNodeRef"); + restClient.authenticateUser(userModel).withWorkflowAPI().usingTask(taskModel) + .addTaskItems(fileModel, fileModel1); + + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "invalidNodeRef")) + .containsErrorKey(RestErrorModel.NOT_FOUND_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE);; + } + + @Bug(id = "ACE-5675") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Adding task item is falling in case empty item body is provided") + public void failedAddingTaskItemIfEmptyItemBodyIsProvided() throws Exception + { + fileModel.setNodeRef(""); + restClient.authenticateUser(userModel).withWorkflowAPI().usingTask(taskModel).addTaskItem(fileModel); + + // TODO - expected error message to be added + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(""); + } + + @Bug(id = "ACE-5675") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Adding multiple task item is falling in case empty item body is provided") + public void failedAddingMultipleTaskItemIfEmptyItemBodyIsProvided() throws Exception + { + fileModel.setNodeRef(""); + restClient.authenticateUser(userModel).withWorkflowAPI().usingTask(taskModel).addTaskItems(fileModel, fileModel1); + + // TODO - expected error message to be added + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(""); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Adding task item is falling in case invalid task id is provided") + public void failedAddingTaskItemIfInvalidTaskIdIsProvided() throws Exception + { + taskModel.setId("invalidTaskId"); + restClient.authenticateUser(userModel).withWorkflowAPI().usingTask(taskModel).addTaskItem(fileModel); + + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "invalidTaskId")) + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE);; + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Adding task item is falling in case invalid task id is provided") + public void failedAddingMultipleTaskItemIfInvalidTaskIdIsProvided() throws Exception + { + taskModel.setId("invalidTaskId"); + restClient.authenticateUser(userModel).withWorkflowAPI().usingTask(taskModel).addTaskItems(fileModel,fileModel1); + + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "invalidTaskId")) + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Bug(id = "ACE-5675") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Adding task item is falling in case incomplete body type is provided") + public void failedAddingTaskVariableIfIncompleteBodyIsProvided() throws Exception + { + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, "{}", "tasks/{taskId}/items", taskId); + restClient.processModel(RestVariableModel.class, request); + + // TODO - expected error message to be added + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(""); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/items/AddTaskItemTestsBulk3.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/items/AddTaskItemTestsBulk3.java new file mode 100644 index 0000000000..0e7312e94b --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/items/AddTaskItemTestsBulk3.java @@ -0,0 +1,128 @@ +package org.alfresco.rest.workflow.tasks.items; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestItemModel; +import org.alfresco.rest.model.RestItemModelsCollection; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TaskModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class AddTaskItemTestsBulk3 extends RestTest +{ + private UserModel userModel,userWhoStartsTask, assigneeUser; + private SiteModel siteModel; + private FileModel fileModel, fileModel1, document1, document2,document3; + private TaskModel taskModel; + private RestItemModelsCollection taskItems; + private RestItemModel taskItem; + + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + userModel = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); + fileModel = dataContent.usingUser(userModel).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + userWhoStartsTask = dataUser.createRandomTestUser(); + assigneeUser = dataUser.createRandomTestUser(); + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assigneeUser); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Add task item using random user.") + public void addTaskItemByTheUserThatStartedTheProcess() throws Exception + { + taskItem = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI().usingTask(taskModel).addTaskItem(fileModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + taskItem.assertThat().field("createdAt").is(taskItem.getCreatedAt()) + .and().field("size").is(taskItem.getSize()) + .and().field("createdBy").is(taskItem.getCreatedBy()) + .and().field("modifiedAt").is(taskItem.getModifiedAt()) + .and().field("name").is(taskItem.getName()) + .and().field("modifiedBy").is(taskItem.getModifiedBy()) + .and().field("id").is(taskItem.getId()) + .and().field("mimeType").is(taskItem.getMimeType()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Add multiple task item using random user.") + public void addMultipleTaskItemByTheUserThatStartedTheProcess() throws Exception + { + fileModel1 = dataContent.usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + taskItems = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI().usingTask(taskModel) + .addTaskItems(fileModel, fileModel1); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + taskItems.getEntries().get(0).onModel() + .assertThat().field("createdAt").is(taskItems.getEntries().get(0).onModel().getCreatedAt()) + .and().field("size").is(taskItems.getEntries().get(0).onModel().getSize()) + .and().field("createdBy").is(taskItems.getEntries().get(0).onModel().getCreatedBy()) + .and().field("modifiedAt").is(taskItems.getEntries().get(0).onModel().getModifiedAt()) + .and().field("name").is(taskItems.getEntries().get(0).onModel().getName()) + .and().field("modifiedBy").is(taskItems.getEntries().get(0).onModel().getModifiedBy()) + .and().field("id").is(taskItems.getEntries().get(0).onModel().getId()) + .and().field("mimeType").is(taskItems.getEntries().get(0).onModel().getMimeType()); + + taskItems.getEntries().get(1).onModel() + .assertThat().field("createdAt").is(taskItems.getEntries().get(1).onModel().getCreatedAt()) + .assertThat().field("size").is(taskItems.getEntries().get(1).onModel().getSize()) + .assertThat().field("createdBy").is(taskItems.getEntries().get(1).onModel().getCreatedBy()) + .assertThat().field("modifiedAt").is(taskItems.getEntries().get(1).onModel().getModifiedAt()) + .assertThat().field("name").is(taskItems.getEntries().get(1).onModel().getName()) + .assertThat().field("modifiedBy").is(taskItems.getEntries().get(1).onModel().getModifiedBy()) + .assertThat().field("id").is(taskItems.getEntries().get(1).onModel().getId()) + .assertThat().field("mimeType").is(taskItems.getEntries().get(1).onModel().getMimeType()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW,TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Delete task item then create it again") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION}) + public void deleteTaskItemThenCreateItAgain() throws Exception + { + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel) + .createNewTaskAndAssignTo(assigneeUser); + restClient.authenticateUser(userWhoStartsTask); + document2 = dataContent.usingSite(siteModel).createContent(DocumentType.XML); + taskItem = restClient.withWorkflowAPI().usingTask(taskModel).addTaskItem(document2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.withWorkflowAPI().usingTask(taskModel).deleteTaskItem(taskItem); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + taskItem = restClient.withWorkflowAPI().usingTask(taskModel).addTaskItem(document2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Delete multiple task item then create it again") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION}) + public void deleteMultipleTaskItemsThenCreateThemAgain() throws Exception + { + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel) + .createNewTaskAndAssignTo(assigneeUser); + restClient.authenticateUser(userWhoStartsTask); + document1 = dataContent.usingSite(siteModel).createContent(DocumentType.XML); + document2 = dataContent.usingSite(siteModel).createContent(DocumentType.XML); + document3 = dataContent.usingSite(siteModel).createContent(DocumentType.XML); + taskItems = restClient.withWorkflowAPI().usingTask(taskModel).addTaskItems(document2, document1, document3); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.withWorkflowAPI().usingTask(taskModel).deleteTaskItem(taskItems.getEntries().get(0).onModel()); + restClient.withWorkflowAPI().usingTask(taskModel).deleteTaskItem(taskItems.getEntries().get(1).onModel()); + restClient.withWorkflowAPI().usingTask(taskModel).deleteTaskItem(taskItems.getEntries().get(2).onModel()); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + restClient.withWorkflowAPI().usingTask(taskModel).addTaskItems(document2, document1, document3); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/items/GetTaskItemsRegressionTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/items/GetTaskItemsRegressionTests.java new file mode 100644 index 0000000000..e0cc869607 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/items/GetTaskItemsRegressionTests.java @@ -0,0 +1,253 @@ +package org.alfresco.rest.workflow.tasks.items; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.dataprep.CMISUtil.Priority; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestItemModel; +import org.alfresco.rest.model.RestItemModelsCollection; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.rest.model.RestTaskModel; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TaskModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Claudia Agache on 12/8/2016. + */ +public class GetTaskItemsRegressionTests extends RestTest +{ + private UserModel userWhoStartsTask, assignee, adminUser; + private SiteModel siteModel; + private FileModel fileModel; + private TaskModel taskModel; + private RestItemModelsCollection itemModels; + private RestProcessModel addedProcess; + private RestTaskModel addedTask; + private RestItemModel taskItem; + + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + userWhoStartsTask = dataUser.createRandomTestUser(); + assignee = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userWhoStartsTask).createPublicRandomSite(); + fileModel = dataContent.usingUser(adminUser).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify if get task items call return status code 404 when invalid taskId is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void getTaskItemsUsingInvalidTaskId() throws Exception + { + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assignee); + taskModel.setId("invalidId"); + + restClient.authenticateUser(assignee).withWorkflowAPI() + .usingTask(taskModel).getTaskItems(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "invalidId")); + + taskModel.setId(""); + + restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI() + .usingTask(taskModel).getTaskItems(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, + executionType = ExecutionType.REGRESSION, + description = "Verify if get task items request returns status code 200 after the task is finished.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void getTaskItemsAfterFinishingTask() throws Exception + { + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assignee); + dataWorkflow.usingUser(assignee).taskDone(taskModel); + restClient.authenticateUser(userWhoStartsTask); + itemModels = restClient.withWorkflowAPI().usingTask(taskModel).getTaskItems(); + restClient.assertStatusCodeIs(HttpStatus.OK); + itemModels.assertThat().entriesListIsNotEmpty().and().entriesListContains("name", fileModel.getName()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, + executionType = ExecutionType.REGRESSION, + description = "Verify if get task items request returns status code 200 after the process is deleted (Task state is now completed.)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void getTaskItemsAfterDeletingProcess() throws Exception + { + addedProcess = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI().addProcess("activitiAdhoc", assignee, false, Priority.Normal); + addedTask = restClient.withWorkflowAPI().getTasks().getTaskModelByProcess(addedProcess); + restClient.withWorkflowAPI().usingTask(addedTask).addTaskItem(fileModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.withWorkflowAPI().usingProcess(addedProcess).deleteProcess(); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + itemModels = restClient.withWorkflowAPI().usingTask(addedTask).getTaskItems(); + restClient.assertStatusCodeIs(HttpStatus.OK); + itemModels.assertThat().entriesListIsNotEmpty().and().entriesListContains("name", fileModel.getName()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Check default error model schema for get task items api call") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void getTaskItemsUsingCheckErrorModel() throws Exception + { + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assignee); + taskModel.setId("invalidId"); + restClient.authenticateUser(assignee).withWorkflowAPI() + .usingTask(taskModel).getTaskItems(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "invalidId")) + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .stackTraceIs(RestErrorModel.STACKTRACE) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify that admin user can get task items") + public void getTaskItemsByAdminUser() throws Exception + { + restClient.authenticateUser(userWhoStartsTask); + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assignee); + taskItem = restClient.withWorkflowAPI().usingTask(taskModel).getTaskItems().getOneRandomEntry(); + + itemModels = restClient.authenticateUser(dataUser.getAdminUser()).withWorkflowAPI().usingTask(taskModel).getTaskItems(); + restClient.assertStatusCodeIs(HttpStatus.OK); + itemModels.assertThat() + .entriesListIsNotEmpty().and() + .entriesListContains("id", taskItem.onModel().getId()).and() + .entriesListContains("name", taskItem.onModel().getName()) + .getEntries().get(0).onModel() + .assertThat().field("createdAt").isNotNull() + .assertThat().field("size").isNotNull() + .assertThat().field("createdBy").contains(dataUser.getAdminUser().getUsername()) + .assertThat().field("modifiedAt").isNotNull() + .assertThat().field("name").contains(fileModel.getName()) + .assertThat().field("modifiedBy").contains(userWhoStartsTask.getUsername()) + .assertThat().field("id").contains(fileModel.getNodeRef().split(";")[0]) + .assertThat().field("mimeType").contains(fileModel.getFileType().mimeType); + } + + @Bug(id="MNT-17438") + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify that user who started the process can get task items with skip count parameter") + public void getTaskItemsWithSkipCount() throws Exception + { + restClient.authenticateUser(userWhoStartsTask); + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assignee); + FileModel document1 = dataContent.usingSite(siteModel).createContent(DocumentType.XML); + restClient.withWorkflowAPI().usingTask(taskModel).addTaskItem(document1); + itemModels = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI() + .usingParams("skipCount=1").usingTask(taskModel).getTaskItems(); + restClient.assertStatusCodeIs(HttpStatus.OK); + itemModels.assertThat() + .entriesListIsNotEmpty() + .and().paginationField("count").is("1"); + } + + @Bug(id="MNT-17438") + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify that user who started the process can get task items with max items parameter") + public void getTaskItemsWithMaxItems() throws Exception + { + restClient.authenticateUser(userWhoStartsTask); + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assignee); + FileModel document1 = dataContent.usingSite(siteModel).createContent(DocumentType.XML); + restClient.withWorkflowAPI().usingTask(taskModel).addTaskItem(document1); + itemModels = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI() + .usingParams("maxItems=1").usingTask(taskModel).getTaskItems(); + restClient.assertStatusCodeIs(HttpStatus.OK); + itemModels.assertThat() + .entriesListIsNotEmpty() + .and().paginationField("count").is("1"); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify that user who started the process can get task items with valid properties") + public void getTaskItemsWithValidProperties() throws Exception + { + restClient.authenticateUser(userWhoStartsTask); + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assignee); + taskItem = restClient.withWorkflowAPI().usingTask(taskModel).getTaskItems().getOneRandomEntry(); + itemModels = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI() + .usingParams("properties=createdAt,createdBy,id,size").usingTask(taskModel).getTaskItems(); + restClient.assertStatusCodeIs(HttpStatus.OK); + itemModels.getOneRandomEntry().onModel().assertThat() + .fieldsCount().is(4).and() + .field("createdAt").isNotNull().and() + .field("size").isNotNull().and() + .field("createdBy").isNotNull().and() + .field("modifiedAt").isNull().and() + .field("name").isNull().and() + .field("modifiedBy").isNull().and() + .field("id").isNotNull().and() + .field("mimeType").isNull(); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify that user who started the process can get task items with an invalid property") + public void getTaskItemsWithInvalidProperties() throws Exception + { + restClient.authenticateUser(userWhoStartsTask); + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assignee); + taskItem = restClient.withWorkflowAPI().usingTask(taskModel).getTaskItems().getOneRandomEntry(); + itemModels = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI() + .usingParams("properties=size,fake-prop").usingTask(taskModel).getTaskItems(); + restClient.assertStatusCodeIs(HttpStatus.OK); + itemModels.getOneRandomEntry().onModel().assertThat() + .fieldsCount().is(1).and() + .field("createdAt").isNull().and() + .field("size").isNotNull().and() + .field("createdBy").isNull().and() + .field("modifiedAt").isNull().and() + .field("name").isNull().and() + .field("modifiedBy").isNull().and() + .field("id").isNull().and() + .field("mimeType").isNull(); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify that involved user in process that was deleted cannot get task items") + public void getTaskItemsByDeletedUserInvolvedInProcess() throws Exception + { + UserModel assigneeDeleted = dataUser.createRandomTestUser(); + restClient.authenticateUser(userWhoStartsTask); + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assigneeDeleted); + + dataUser.usingAdmin().deleteUser(assigneeDeleted); + + itemModels = restClient.authenticateUser(assigneeDeleted).withWorkflowAPI().usingTask(taskModel).getTaskItems(); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify that involved user in process that was disabled cannot get task items") + public void getTaskItemsByDisabledUserInvolvedInProcess() throws Exception + { + UserModel assigneeDisabled = dataUser.createRandomTestUser(); + restClient.authenticateUser(userWhoStartsTask); + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assigneeDisabled); + + dataUser.usingAdmin().disableUser(assigneeDisabled); + + itemModels = restClient.authenticateUser(assigneeDisabled).withWorkflowAPI().usingTask(taskModel).getTaskItems(); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/items/GetTaskItemsSanityTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/items/GetTaskItemsSanityTests.java new file mode 100644 index 0000000000..bb2ef2bc58 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/items/GetTaskItemsSanityTests.java @@ -0,0 +1,75 @@ +package org.alfresco.rest.workflow.tasks.items; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestItemModel; +import org.alfresco.rest.model.RestItemModelsCollection; +import org.alfresco.utility.Utility; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TaskModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + + +public class GetTaskItemsSanityTests extends RestTest +{ + private UserModel userModel, userWhoStartsTask, assignee; + private SiteModel siteModel; + private FileModel fileModel, document1; + private TaskModel taskModel; + private RestItemModel taskItem; + private RestItemModelsCollection itemModels; + + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + userModel = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); + fileModel = dataContent.usingUser(userModel).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + userWhoStartsTask = dataUser.createRandomTestUser(); + assignee = dataUser.createRandomTestUser(); + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assignee); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.SANITY, + description = "Verify that user that started the process gets task items") + public void getTaskItemsByUserWhoStartedProcess() throws Exception + { + restClient.authenticateUser(userWhoStartsTask); + document1 = dataContent.usingSite(siteModel).createContent(DocumentType.XML); + taskItem = restClient.withWorkflowAPI().usingTask(taskModel).addTaskItem(document1); + Utility.checkObjectIsInitialized(taskItem, "taskItem"); + + itemModels = restClient.withWorkflowAPI().usingTask(taskModel).getTaskItems(); + restClient.assertStatusCodeIs(HttpStatus.OK); + itemModels.assertThat() + .entriesListIsNotEmpty().and() + .entriesListContains("id", taskItem.getId()).and() + .entriesListContains("name", document1.getName()); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.SANITY, + description = "Verify that involved user in process gets task items") + public void getTaskItemsByUserInvolvedInProcess() throws Exception + { + restClient.authenticateUser(assignee); + document1 = dataContent.usingSite(siteModel).createContent(DocumentType.XML); + taskItem = restClient.withWorkflowAPI().usingTask(taskModel).addTaskItem(document1); + + itemModels = restClient.withWorkflowAPI().usingTask(taskModel).getTaskItems(); + restClient.assertStatusCodeIs(HttpStatus.OK); + itemModels.assertThat() + .entriesListIsNotEmpty().and() + .entriesListContains("id", taskItem.getId()).and() + .entriesListContains("name", document1.getName()); + + } +} \ No newline at end of file diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/items/RemoveTaskItemTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/items/RemoveTaskItemTests.java new file mode 100644 index 0000000000..b452c82478 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/items/RemoveTaskItemTests.java @@ -0,0 +1,255 @@ +package org.alfresco.rest.workflow.tasks.items; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestItemModel; +import org.alfresco.utility.model.*; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * @author bogdan.bocancea + */ +public class RemoveTaskItemTests extends RestTest +{ + private UserModel adminUser, userWhoStartsTask, assigneeUser; + private SiteModel siteModel; + private FileModel fileModel, document2; + private TaskModel taskModel; + private RestItemModel taskItem; + + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + userWhoStartsTask = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userWhoStartsTask).createPublicRandomSite(); + fileModel = dataContent.usingUser(userWhoStartsTask).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + assigneeUser = dataUser.createRandomTestUser(); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.SANITY, + description = "Delete existing task item") + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + public void deleteTaskItem() throws Exception + { + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assigneeUser); + restClient.authenticateUser(adminUser); + document2 = dataContent.usingSite(siteModel).createContent(DocumentType.XML); + + taskItem = restClient.withWorkflowAPI().usingTask(taskModel).addTaskItem(document2); + restClient.withWorkflowAPI().usingTask(taskModel).deleteTaskItem(taskItem); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withWorkflowAPI().usingTask(taskModel).getTaskItems() + .assertThat().entriesListDoesNotContain("id", taskItem.getId()).and() + .entriesListDoesNotContain("name", document2.getName()); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Try to Delete existing task item using invalid taskId") + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void deleteTaskItemUsingInvalidTaskId() throws Exception + { + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assigneeUser); + restClient.authenticateUser(adminUser); + document2 = dataContent.usingSite(siteModel).createContent(DocumentType.XML); + + taskItem = restClient.withWorkflowAPI().usingTask(taskModel).addTaskItem(document2); + taskModel.setId("invalidTaskId"); + restClient.withWorkflowAPI().usingTask(taskModel).deleteTaskItem(taskItem); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "invalidTaskId")); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Try to Delete existing task item using invalid itemId") + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void deleteTaskItemUsingInvalidItemId() throws Exception + { + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assigneeUser); + restClient.authenticateUser(adminUser); + document2 = dataContent.usingSite(siteModel).createContent(DocumentType.XML); + taskItem = restClient.withWorkflowAPI().usingTask(taskModel).addTaskItem(document2); + taskItem.setId("incorrectItemId"); + restClient.withWorkflowAPI().usingTask(taskModel).deleteTaskItem(taskItem); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.PROCESS_ENTITY_NOT_FOUND, "incorrectItemId")); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Delete existing task item with empty task id") + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void deleteTaskItemEmptyTaskId() throws Exception + { + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assigneeUser); + restClient.authenticateUser(userWhoStartsTask); + document2 = dataContent.usingSite(siteModel).createContent(DocumentType.XML); + taskItem = restClient.withWorkflowAPI().usingTask(taskModel).addTaskItem(document2); + taskModel.setId(""); + restClient.withWorkflowAPI().usingTask(taskModel).deleteTaskItem(taskItem); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "")); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Delete existing task item with empty item id") + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void deleteTaskItemEmptyItemId() throws Exception + { + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assigneeUser); + restClient.authenticateUser(userWhoStartsTask); + document2 = dataContent.usingSite(siteModel).createContent(DocumentType.XML); + taskItem = restClient.withWorkflowAPI().usingTask(taskModel).addTaskItem(document2); + taskItem.setId(""); + restClient.withWorkflowAPI().usingTask(taskModel).deleteTaskItem(taskItem); + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED) + .assertLastError().containsSummary(RestErrorModel.DELETE_EMPTY_ARGUMENT); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Delete existing task item for completed task") + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void deleteTaskItemForCompletedTask() throws Exception + { + TaskModel completedTask = dataWorkflow.usingUser(userWhoStartsTask) + .usingSite(siteModel) + .usingResource(fileModel).createNewTaskAndAssignTo(assigneeUser); + restClient.authenticateUser(userWhoStartsTask); + document2 = dataContent.usingUser(userWhoStartsTask).usingSite(siteModel).createContent(DocumentType.XML); + taskItem = restClient.withWorkflowAPI().usingTask(completedTask).addTaskItem(document2); + dataWorkflow.usingUser(assigneeUser).taskDone(completedTask); + dataWorkflow.usingUser(userWhoStartsTask).taskDone(completedTask); + restClient.withWorkflowAPI().usingTask(completedTask).deleteTaskItem(taskItem); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, completedTask.getId())); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.SANITY, + description = "Delete existing task item with candidate user") + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + public void deleteTaskItemWithCandidateUser() throws Exception + { + GroupModel group = dataGroup.createRandomGroup(); + dataGroup.addListOfUsersToGroup(group, assigneeUser); + TaskModel groupTask = dataWorkflow.usingUser(userWhoStartsTask) + .usingSite(siteModel) + .usingResource(fileModel).createPooledReviewTaskAndAssignTo(group); + + restClient.authenticateUser(userWhoStartsTask); + document2 = dataContent.usingUser(userWhoStartsTask).usingSite(siteModel).createContent(DocumentType.XML); + taskItem = restClient.withWorkflowAPI().usingTask(groupTask).addTaskItem(document2); + restClient.authenticateUser(assigneeUser) + .withWorkflowAPI().usingTask(groupTask).deleteTaskItem(taskItem); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Delete existing task item with unauthorized user") + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void deleteTaskItemWithUnauthorizedUser() throws Exception + { + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assigneeUser); + UserModel unauthorizedUser = dataUser.createRandomTestUser(); + document2 = dataContent.usingSite(siteModel).createContent(DocumentType.XML); + taskItem = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI().usingTask(taskModel).addTaskItem(document2); + restClient.authenticateUser(unauthorizedUser).withWorkflowAPI().usingTask(taskModel).deleteTaskItem(taskItem); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.SANITY, + description = "Delete existing task item with inexistent user") + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) +// @Bug(id="MNT-16904", description = "It fails only on environment with tenants") + public void deleteTaskItemWithInexistentUser() throws Exception + { + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assigneeUser); + document2 = dataContent.usingSite(siteModel).createContent(DocumentType.XML); + taskItem = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI().usingTask(taskModel).addTaskItem(document2); + restClient.authenticateUser(UserModel.getRandomUserModel()).withWorkflowAPI().usingTask(taskModel).deleteTaskItem(taskItem); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Delete existing task item for deleted task") + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void deleteTaskItemFromDeletedProcess() throws Exception + { + ProcessModel deletedProcess = dataWorkflow.usingUser(userWhoStartsTask) + .usingSite(siteModel) + .usingResource(fileModel).createMoreReviewersWorkflowAndAssignTo(assigneeUser); + TaskModel task = restClient.authenticateUser(userWhoStartsTask) + .withWorkflowAPI().usingProcess(deletedProcess).getProcessTasks().getEntries().get(0).onModel(); + + document2 = dataContent.usingUser(userWhoStartsTask).usingSite(siteModel).createContent(DocumentType.XML); + taskItem = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI().usingTask(task).addTaskItem(document2); + dataWorkflow.usingUser(userWhoStartsTask).deleteProcess(deletedProcess); + restClient.withWorkflowAPI().usingTask(task).deleteTaskItem(taskItem); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, task.getId())); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Delete task item twice") + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void deleteTaskItemTwice() throws Exception + { + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assigneeUser); + restClient.authenticateUser(userWhoStartsTask); + document2 = dataContent.usingSite(siteModel).createContent(DocumentType.XML); + taskItem = restClient.withWorkflowAPI().usingTask(taskModel).addTaskItem(document2); + + restClient.withWorkflowAPI().usingTask(taskModel).deleteTaskItem(taskItem); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withWorkflowAPI().usingTask(taskModel).deleteTaskItem(taskItem); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.PROCESS_ENTITY_NOT_FOUND, document2.getNodeRefWithoutVersion())) + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Delete task item with locked document") + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void deleteTaskItemWithLockedDocument() throws Exception + { + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assigneeUser); + restClient.authenticateUser(userWhoStartsTask); + document2 = dataContent.usingSite(siteModel).createContent(DocumentType.XML); + taskItem = restClient.withWorkflowAPI().usingTask(taskModel).addTaskItem(document2); + + dataContent.usingUser(userWhoStartsTask).usingResource(document2).checkOutDocument(); + + restClient.withWorkflowAPI().usingTask(taskModel).deleteTaskItem(taskItem); + restClient.assertStatusCodeIs(HttpStatus.CONFLICT) + .assertLastError().containsSummary(String.format(RestErrorModel.LOCKED_NODE_OPERATION, document2.getNodeRefWithoutVersion())) + .containsErrorKey(RestErrorModel.API_DEFAULT_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Delete task item with deleted document") + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void deleteTaskItemWithDeletedDocument() throws Exception + { + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assigneeUser); + restClient.authenticateUser(userWhoStartsTask); + document2 = dataContent.usingSite(siteModel).createContent(DocumentType.XML); + taskItem = restClient.withWorkflowAPI().usingTask(taskModel).addTaskItem(document2); + + dataContent.usingUser(userWhoStartsTask).usingResource(document2).deleteContent(); + + restClient.withWorkflowAPI().usingTask(taskModel).deleteTaskItem(taskItem); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.PROCESS_ENTITY_NOT_FOUND, document2.getNodeRefWithoutVersion())) + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } +} \ No newline at end of file diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/variables/AddTaskVariablesTestsBulk1.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/variables/AddTaskVariablesTestsBulk1.java new file mode 100644 index 0000000000..7d2809a655 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/variables/AddTaskVariablesTestsBulk1.java @@ -0,0 +1,198 @@ +package org.alfresco.rest.workflow.tasks.variables; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestVariableModel; +import org.alfresco.rest.model.RestVariableModelsCollection; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TaskModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * @author iulia.cojocea + */ + +public class AddTaskVariablesTestsBulk1 extends RestTest +{ + private UserModel userModel, userWhoStartsTask; + private SiteModel siteModel; + private FileModel fileModel; + private UserModel assigneeUser; + private TaskModel taskModel; + private RestVariableModel restVariablemodel; + private RestVariableModelsCollection restVariableCollection; + private RestVariableModel variableModel, variableModel1; + + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + userModel = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); + fileModel = dataContent.usingUser(userModel).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + userWhoStartsTask = dataUser.createRandomTestUser(); + assigneeUser = dataUser.createRandomTestUser(); + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assigneeUser); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.SANITY, + description = "Create non-existing task variable with admin") + public void createTaskVariableWithAdmin() throws Exception + { + UserModel adminUser = dataUser.getAdminUser(); + restClient.authenticateUser(adminUser); + RestVariableModel variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + + restVariablemodel = restClient.withWorkflowAPI().usingTask(taskModel).addTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restVariablemodel.assertThat() + .field("scope").is(variableModel.getScope()) + .and().field("name").is(variableModel.getName()) + .and().field("value").is(variableModel.getValue()) + .and().field("type").is(variableModel.getType()); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Create non-existing task variable with admin") + public void createMultipleTaskVariablesWithAdmin() throws Exception + { + UserModel adminUser = dataUser.getAdminUser(); + restClient.authenticateUser(adminUser); + variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + variableModel1 = RestVariableModel.getRandomTaskVariableModel("global", "d:text"); + + restVariableCollection = restClient.withWorkflowAPI().usingTask(taskModel).addTaskVariables(variableModel,variableModel1); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restVariableCollection.getEntries().get(0).onModel().assertThat() + .field("scope").is(variableModel.getScope()) + .and().field("name").is(variableModel.getName()) + .and().field("value").is(variableModel.getValue()) + .and().field("type").is(variableModel.getType()); + + restVariableCollection.getEntries().get(1).onModel().assertThat() + .field("scope").is(variableModel1.getScope()) + .and().field("name").is(variableModel1.getName()) + .and().field("value").is(variableModel1.getValue()) + .and().field("type").is(variableModel1.getType()); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.SANITY, + description = "Create non-existing task variable with user involved in the process") + public void createTaskVariableWithInvolvedUser() throws Exception + { + restClient.authenticateUser(assigneeUser); + RestVariableModel variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + + restVariablemodel = restClient.withWorkflowAPI().usingTask(taskModel).addTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restVariablemodel.assertThat().field("scope").is(variableModel.getScope()) + .and().field("name").is(variableModel.getName()) + .and().field("value").is(variableModel.getValue()) + .and().field("type").is(variableModel.getType()); + + restClient.withWorkflowAPI().usingTask(taskModel).getTaskVariables().assertThat().entriesListContains("name", variableModel.getName()); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Create multiple non-existing task variable with involved user") + public void createMultipleTaskVariableWithInvolvedUser() throws Exception + { + restClient.authenticateUser(assigneeUser); + variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + variableModel1 = RestVariableModel.getRandomTaskVariableModel("global", "d:text"); + + restVariableCollection = restClient.withWorkflowAPI().usingTask(taskModel).addTaskVariables(variableModel,variableModel1); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restVariableCollection.getEntries().get(0).onModel().assertThat() + .field("scope").is(variableModel.getScope()) + .and().field("name").is(variableModel.getName()) + .and().field("value").is(variableModel.getValue()) + .and().field("type").is(variableModel.getType()); + + restVariableCollection.getEntries().get(1).onModel().assertThat() + .field("scope").is(variableModel1.getScope()) + .and().field("name").is(variableModel1.getName()) + .and().field("value").is(variableModel1.getValue()) + .and().field("type").is(variableModel1.getType()); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.SANITY, + description = "Create non-existing task variable with task owner") + public void createTaskVariableWithTaskOwner() throws Exception + { + restClient.authenticateUser(userWhoStartsTask); + RestVariableModel variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + + restVariablemodel = restClient.withWorkflowAPI().usingTask(taskModel).addTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restVariablemodel.assertThat().field("scope").is(variableModel.getScope()) + .and().field("name").is(variableModel.getName()) + .and().field("value").is(variableModel.getValue()) + .and().field("type").is(variableModel.getType()); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Create multiple non-existing task variable with task owner") + public void createMultipleTaskVariableWithTaskOwner() throws Exception + { + restClient.authenticateUser(userWhoStartsTask); + variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + variableModel1 = RestVariableModel.getRandomTaskVariableModel("global", "d:text"); + + restVariableCollection = restClient.withWorkflowAPI().usingTask(taskModel).addTaskVariables(variableModel,variableModel1); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restVariableCollection.getEntries().get(0).onModel().assertThat() + .field("scope").is(variableModel.getScope()) + .and().field("name").is(variableModel.getName()) + .and().field("value").is(variableModel.getValue()) + .and().field("type").is(variableModel.getType()); + + restVariableCollection.getEntries().get(1).onModel().assertThat() + .field("scope").is(variableModel1.getScope()) + .and().field("name").is(variableModel1.getName()) + .and().field("value").is(variableModel1.getValue()) + .and().field("type").is(variableModel1.getType()); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Create non-existing task variable with any user") + public void createTaskVariableWithRandomUser() throws Exception + { + userModel = dataUser.createRandomTestUser(); + restClient.authenticateUser(userModel); + RestVariableModel variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + + restVariablemodel = restClient.withWorkflowAPI().usingTask(taskModel).addTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary("Permission was denied"); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Create multiple non-existing task variable with any user") + public void createMultipleTaskVariableWithRandomUser() throws Exception + { + restClient.authenticateUser(userModel); + variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + variableModel1 = RestVariableModel.getRandomTaskVariableModel("global", "d:text"); + + restVariableCollection = restClient.withWorkflowAPI().usingTask(taskModel).addTaskVariables(variableModel,variableModel1); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary("Permission was denied"); + } + +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/variables/AddTaskVariablesTestsBulk2.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/variables/AddTaskVariablesTestsBulk2.java new file mode 100644 index 0000000000..ab4d077b8a --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/variables/AddTaskVariablesTestsBulk2.java @@ -0,0 +1,241 @@ +package org.alfresco.rest.workflow.tasks.variables; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestVariableModel; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TaskModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + + +public class AddTaskVariablesTestsBulk2 extends RestTest +{ + private UserModel userWhoStartsTask, adminUser; + private SiteModel siteModel; + private FileModel fileModel; + private UserModel assigneeUser; + private TaskModel taskModel; + private RestVariableModel invalidVariableModel, variableModel, variableModel1; + + private String taskId; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + userWhoStartsTask = dataUser.createRandomTestUser(); + assigneeUser = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(adminUser).createPublicRandomSite(); + fileModel = dataContent.usingUser(adminUser).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assigneeUser); + + taskId = taskModel.getId(); + restClient.authenticateUser(adminUser); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, description = "Adding task variable is falling in case invalid variableBody is provided") + public void failedAddingTaskVariableIfInvalidBodyIsProvided() throws Exception + { + invalidVariableModel = RestVariableModel.getRandomTaskVariableModel("instance", "d:char"); + restClient.withWorkflowAPI().usingTask(taskModel).addTaskVariable(invalidVariableModel); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary("Illegal value for variable scope: 'instance'."); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Adding multiple task variable is falling in case invalid variableBody is provided") + public void failedAddingMultipleTaskVariableIfInvalidBodyIsProvided() throws Exception + { + variableModel = RestVariableModel.getRandomTaskVariableModel("instance", "d:char"); + variableModel1 = RestVariableModel.getRandomTaskVariableModel("global", "d:text"); + restClient.withWorkflowAPI().usingTask(taskModel).addTaskVariables(variableModel, variableModel1); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary("Illegal value for variable scope: 'instance'."); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, description = "Adding task variable is falling in case empty body type is provided") + public void failedAddingTaskVariableIfEmptyBodyIsProvided() throws Exception + { + RestVariableModel invalidVariableModel = RestVariableModel.getRandomTaskVariableModel("", ""); + restClient.withWorkflowAPI().usingTask(taskModel).addTaskVariable(invalidVariableModel); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary("Variable scope is required and can only be 'local' or 'global'."); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Adding multiple task variable is falling in case empty body type is provided") + public void failedAddingMultipleTaskVariableIfEmptyBodyIsProvided() throws Exception + { + RestVariableModel invalidVariableModel = RestVariableModel.getRandomTaskVariableModel("", ""); + variableModel1 = RestVariableModel.getRandomTaskVariableModel("global", "d:text"); + restClient.withWorkflowAPI().usingTask(taskModel).addTaskVariables(invalidVariableModel, variableModel1); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary("Variable scope is required and can only be 'local' or 'global'."); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, description = "Adding task variable is falling in case incomplete body type is provided") + public void failedAddingTaskVariableIfIncompleteBodyIsProvided() throws Exception + { + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, "{\"name\": \"missingVariableScope\",\"value\": \"test\",\"type\": \"d:text\"}", + "tasks/{taskId}/variables", taskId); + restClient.processModel(RestVariableModel.class, request); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary("Variable scope is required and can only be 'local' or 'global'."); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, description = "Adding task variable is falling in case incomplete body - missing required: name type is provided") + public void failedAddingTaskVariableIfIncompleteRequiredBodyIsProvided() throws Exception + { + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, "{\"scope\": \"local\",\"value\": \"missingVariableName\",\"type\": \"d:text\"}", + "tasks/{taskId}/variables", taskId); + restClient.processModel(RestVariableModel.class, request); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary("Variable name is required."); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, description = "Adding task variable is falling in case invalid type is provided") + public void failedAddingTaskVariableIfInvalidTypeIsProvided() throws Exception + { + RestVariableModel invalidVariableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:char"); + taskModel.setId(taskId); + + restClient.withWorkflowAPI().usingTask(taskModel).addTaskVariable(invalidVariableModel); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary("Unsupported type of variable: 'd:char'."); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Adding multiple task variable is falling in case invalid type is provided") + public void failedAddingMultipleTaskVariableIfInvalidTypeIsProvided() throws Exception + { + RestVariableModel invalidVariableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:char"); + taskModel.setId(taskId); + variableModel1 = RestVariableModel.getRandomTaskVariableModel("global", "d:text"); + + restClient.withWorkflowAPI().usingTask(taskModel).addTaskVariables(invalidVariableModel, variableModel1); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary("Unsupported type of variable: 'd:char'."); + } + + @Bug(id = "ACE-5674") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, description = "Adding task variable is falling in case invalid type prefix is provided") + public void failedAddingTaskVariableIfInvalidTypePrefixIsProvided() throws Exception + { + RestVariableModel invalidVariableModel = RestVariableModel.getRandomTaskVariableModel("local", "ddm:text"); + taskModel.setId(taskId); + + restClient.withWorkflowAPI().usingTask(taskModel).addTaskVariable(invalidVariableModel); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary("Namespace prefix ddm is not mapped to a namespace URI"); + } + + @Bug(id = "ACE-5674") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Adding multiple task variable is falling in case invalid type prefix is provided") + public void failedAddingMultipleTaskVariableIfInvalidTypePrefixIsProvided() throws Exception + { + RestVariableModel invalidVariableModel = RestVariableModel.getRandomTaskVariableModel("local", "ddm:text"); + taskModel.setId(taskId); + variableModel1 = RestVariableModel.getRandomTaskVariableModel("global", "d:text"); + variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + + restClient.withWorkflowAPI().usingTask(taskModel).addTaskVariables(invalidVariableModel,variableModel1, variableModel); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary("Namespace prefix ddm is not mapped to a namespace URI"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, description = "Adding task variable is falling in case invalid scope is provided") + public void failedAddingTaskVariableIfInvalidScopeIsProvided() throws Exception + { + RestVariableModel invalidVariableModel = RestVariableModel.getRandomTaskVariableModel("instance", "d:text"); + taskModel.setId(taskId); + + restClient.withWorkflowAPI().usingTask(taskModel).addTaskVariable(invalidVariableModel); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary("Illegal value for variable scope: 'instance'."); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Adding multiple task variable is falling in case invalid scope is provided") + public void failedAddingMultipleTaskVariableIfInvalidScopeIsProvided() throws Exception + { + RestVariableModel invalidVariableModel = RestVariableModel.getRandomTaskVariableModel("instance", "d:text"); + taskModel.setId(taskId); + variableModel1 = RestVariableModel.getRandomTaskVariableModel("global", "d:text"); + variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + + restClient.withWorkflowAPI().usingTask(taskModel).addTaskVariables(invalidVariableModel, variableModel, variableModel1); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary("Illegal value for variable scope: 'instance'."); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, description = "Adding task variable is falling in case invalid task id is provided") + public void failedAddingTaskVariableIfInvalidTaskIdIsProvided() throws Exception + { + RestVariableModel variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + taskModel.setId(taskModel.getId() + "TEST"); + restClient.withWorkflowAPI().usingTask(taskModel).addTaskVariable(variableModel); + + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, taskModel.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Adding multiple task variable is falling in case invalid task id is provided") + public void failedAddingMultipleTaskVariableIfInvalidTaskIdIsProvided() throws Exception + { + variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + taskModel.setId(taskModel.getId() + "TEST"); + variableModel1 = RestVariableModel.getRandomTaskVariableModel("global", "d:text"); + restClient.withWorkflowAPI().usingTask(taskModel).addTaskVariables(variableModel, variableModel1); + + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, taskModel.getId())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, description = "Adding task variable is falling in case invalid task id is provided") + public void failedAddingTaskVariableIfInvalidValueIsProvided() throws Exception + { + RestVariableModel variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:int"); + variableModel.setValue("invalidValue"); + + restClient.withWorkflowAPI().usingTask(taskModel).addTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary("For input string: \"invalidValue\""); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Adding multiple task variable is falling in case invalid task id is provided") + public void failedAddingMultipleTaskVariableIfInvalidValueIsProvided() throws Exception + { + variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:int"); + variableModel.setValue("invalidValue"); + variableModel1 = RestVariableModel.getRandomTaskVariableModel("global", "d:text"); + + restClient.withWorkflowAPI().usingTask(taskModel).addTaskVariables(variableModel, variableModel1); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary("For input string: \"invalidValue\""); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/variables/AddTaskVariablesTestsBulk3.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/variables/AddTaskVariablesTestsBulk3.java new file mode 100644 index 0000000000..4f3b937aa1 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/variables/AddTaskVariablesTestsBulk3.java @@ -0,0 +1,155 @@ +package org.alfresco.rest.workflow.tasks.variables; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestVariableModel; +import org.alfresco.rest.model.RestVariableModelsCollection; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TaskModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + + +public class AddTaskVariablesTestsBulk3 extends RestTest +{ + private UserModel userWhoStartsTask, adminUser; + private SiteModel siteModel; + private FileModel fileModel; + private UserModel assigneeUser; + private TaskModel taskModel; + private RestVariableModel restVariablemodel, variableModel, variableModel1; + private RestVariableModelsCollection restVariableCollection; + private String taskId; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + userWhoStartsTask = dataUser.createRandomTestUser(); + assigneeUser = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(adminUser).createPublicRandomSite(); + fileModel = dataContent.usingUser(adminUser).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assigneeUser); + + taskId = taskModel.getId(); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Create task variable with name containing symbols") + public void createTaskVariableWithSymbolsInName() throws Exception + { + UserModel adminUser = dataUser.getAdminUser(); + restClient.authenticateUser(adminUser); + RestVariableModel variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + variableModel.setName("!@#$%^&*({}<>.,;'=_|"); + restVariablemodel = restClient.withWorkflowAPI().usingTask(taskModel).addTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restVariablemodel.assertThat() + .field("scope").is(variableModel.getScope()) + .and().field("name").is(variableModel.getName()) + .and().field("value").is(variableModel.getValue()) + .and().field("type").is(variableModel.getType()); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Create multiple task variable with name containing symbols") + public void createMultipleTaskVariableWithSymbolsInName() throws Exception + { + UserModel adminUser = dataUser.getAdminUser(); + restClient.authenticateUser(adminUser); + variableModel1 = RestVariableModel.getRandomTaskVariableModel("global", "d:text"); + variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + variableModel.setName("!@#$%^&*({}<>.,;'=_|"); + + restVariableCollection = restClient.withWorkflowAPI().usingTask(taskModel).addTaskVariables(variableModel,variableModel1); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restVariableCollection.getEntries().get(0).onModel().assertThat() + .field("scope").is(variableModel.getScope()) + .and().field("name").is(variableModel.getName()) + .and().field("value").is(variableModel.getValue()) + .and().field("type").is(variableModel.getType()); + + restVariableCollection.getEntries().get(1).onModel().assertThat() + .field("scope").is(variableModel1.getScope()) + .and().field("name").is(variableModel1.getName()) + .and().field("value").is(variableModel1.getValue()) + .and().field("type").is(variableModel1.getType()); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Create task variable with empty name") + public void createTaskVariableWithEmptyName() throws Exception + { + UserModel adminUser = dataUser.getAdminUser(); + restClient.authenticateUser(adminUser); + RestVariableModel variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + variableModel.setName(""); + restVariablemodel = restClient.withWorkflowAPI().usingTask(taskModel).addTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsErrorKey(RestErrorModel.VARIABLE_NAME_REQUIRED) + .containsSummary(RestErrorModel.VARIABLE_NAME_REQUIRED) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Update task variable with invalid variable name") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void createTaskVariableWithInvalidVariableName() throws Exception + { + restClient.authenticateUser(adminUser).withWorkflowAPI(); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, "{\"scope\": \"local\",\"names\": \"varName\",\"value\": \"test\"," + + "\"type\": \"d:text\"}", "tasks/{taskId}/variables", taskId); + restClient.processModel(RestVariableModel.class, request); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsSummary(String.format(RestErrorModel.NO_CONTENT,"Unrecognized field " + "\"names\"")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Create task variable with invalid name") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void createTaskVariableWithInvalidName() throws Exception + { + restClient.authenticateUser(adminUser).withWorkflowAPI(); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, "{\"scope\": \"local\",\"name\": ',\"value\": \"test\"," + + "\"type\": \"d:text\"}", "tasks/{taskId}/variables", taskId); + restClient.processModel(RestVariableModel.class, request); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsSummary(String.format(RestErrorModel.NO_CONTENT,"Unexpected character " + "('''")); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Create task variable with empty name") + public void failedCreatingMultipleTaskVariableWithEmptyName() throws Exception + { + UserModel adminUser = dataUser.getAdminUser(); + restClient.authenticateUser(adminUser); + variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + variableModel1 = RestVariableModel.getRandomTaskVariableModel("global", "d:text"); + variableModel.setName(""); + + restVariableCollection = restClient.withWorkflowAPI().usingTask(taskModel).addTaskVariables(variableModel, variableModel1); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsErrorKey(RestErrorModel.VARIABLE_NAME_REQUIRED) + .containsSummary(RestErrorModel.VARIABLE_NAME_REQUIRED) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/variables/DeleteTaskVariableTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/variables/DeleteTaskVariableTests.java new file mode 100644 index 0000000000..5929ec9603 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/variables/DeleteTaskVariableTests.java @@ -0,0 +1,231 @@ +package org.alfresco.rest.workflow.tasks.variables; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestVariableModel; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TaskModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * @author bogdan.bocancea + */ +public class DeleteTaskVariableTests extends RestTest +{ + private UserModel userModel, assigneeUser, adminUser; + private SiteModel siteModel; + private FileModel fileModel; + private TaskModel taskModel; + + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + userModel = dataUser.createRandomTestUser(); + assigneeUser = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); + fileModel = dataContent.usingUser(userModel).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + taskModel = dataWorkflow.usingUser(userModel).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assigneeUser); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.SANITY, + description = "Delete existing task variable") + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + public void deleteTaskVariable() throws Exception + { + restClient.authenticateUser(adminUser); + RestVariableModel variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + + restClient.withWorkflowAPI().usingTask(taskModel).addTaskVariable(variableModel); + restClient.withWorkflowAPI().usingTask(taskModel).deleteTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withWorkflowAPI().usingTask(taskModel).getTaskVariables() + .assertThat().entriesListDoesNotContain("name", variableModel.getName()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Try to delete existing task variable using invalid task id") + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void tryToDeleteTaskVariableUsingInvalidTaskId() throws Exception + { + restClient.authenticateUser(adminUser); + RestVariableModel variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + + restClient.withWorkflowAPI().usingTask(taskModel).updateTaskVariable(variableModel); + taskModel.setId("incorrectTaskId"); + restClient.withWorkflowAPI().usingTask(taskModel).deleteTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.SANITY, + description = "Delete task variable with any user") + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + public void deleteTaskVariableByAnyUser() throws Exception + { + restClient.authenticateUser(userModel); + RestVariableModel variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + + restClient.withWorkflowAPI().usingTask(taskModel).addTaskVariable(variableModel); + restClient.withWorkflowAPI().usingTask(taskModel).deleteTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withWorkflowAPI().usingTask(taskModel).getTaskVariables() + .assertThat().entriesListDoesNotContain("name", variableModel.getName()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Delete task variable with invalid type") + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void deleteTaskVariableInvalidType() throws Exception + { + restClient.authenticateUser(userModel); + RestVariableModel variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + restClient.withWorkflowAPI().usingTask(taskModel).addTaskVariable(variableModel); + variableModel.setType("invalid-type"); + restClient.withWorkflowAPI().usingTask(taskModel).deleteTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withWorkflowAPI().usingTask(taskModel).getTaskVariables() + . assertThat().entriesListDoesNotContain("name", variableModel.getName()); + } + +// The reason the test is not valid is because of `/` malforming the path so that it actually can't land on the URL of the webscript. The request with <>.,;|-+=% (without /) actually is parsed and 404 is thrown (no entity with id <>.,;|-+=% is found) +// @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, +// description = "Delete task variable with invalid name") +// @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) +// public void deleteTaskVariableInvalidName() throws Exception +// { +// restClient.authenticateUser(userModel); +// RestVariableModel variableModel = new RestVariableModel("local", "<>.,;/|-+=%", "d:text", "invalid name"); +// restClient.withWorkflowAPI().usingTask(taskModel).deleteTaskVariable(variableModel); +// restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST); +// } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Create, update, delete task variable with any user") + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void createUpdateDeleteTaskVariableByAnyUser() throws Exception + { + restClient.authenticateUser(userModel); + RestVariableModel variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + + restClient.withWorkflowAPI().usingTask(taskModel).addTaskVariable(variableModel); + variableModel.setName("new-variable"); + restClient.withWorkflowAPI().usingTask(taskModel).updateTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + restClient.withWorkflowAPI().usingTask(taskModel).deleteTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withWorkflowAPI().usingTask(taskModel).getTaskVariables() + .assertThat().entriesListDoesNotContain("name", variableModel.getName()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Delete task variable by non assigned user") + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void deleteTaskVariableByNonAssignedUser() throws Exception + { + UserModel nonAssigned = dataUser.createRandomTestUser(); + RestVariableModel variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + + restClient.authenticateUser(userModel).withWorkflowAPI().usingTask(taskModel).addTaskVariable(variableModel); + restClient.authenticateUser(nonAssigned).withWorkflowAPI().usingTask(taskModel).deleteTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Delete task variable by inexistent user") + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) +// @Bug(id="MNT-16904", description = "It fails only on environment with tenants") + public void deleteTaskVariableByInexistentUser() throws Exception + { + RestVariableModel variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + restClient.authenticateUser(userModel).withWorkflowAPI().usingTask(taskModel).addTaskVariable(variableModel); + restClient.authenticateUser(UserModel.getRandomUserModel()) + .withWorkflowAPI() + .usingTask(taskModel) + .deleteTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Delete task variable twice") + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void deleteTaskVariableTwice() throws Exception + { + restClient.authenticateUser(userModel); + RestVariableModel variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + + restClient.withWorkflowAPI().usingTask(taskModel).addTaskVariable(variableModel); + restClient.withWorkflowAPI().usingTask(taskModel).deleteTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withWorkflowAPI().usingTask(taskModel).getTaskVariables() + .assertThat().entriesListDoesNotContain("name", variableModel.getName()); + + restClient.withWorkflowAPI().usingTask(taskModel).deleteTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, variableModel.getName())) + .stackTraceIs(RestErrorModel.STACKTRACE) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Delete task variable with empty variable name") + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void deleteTaskEmptyVariableName() throws Exception + { + restClient.authenticateUser(userModel); + RestVariableModel variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + + restClient.withWorkflowAPI().usingTask(taskModel).addTaskVariable(variableModel); + variableModel.setName(""); + restClient.withWorkflowAPI().usingTask(taskModel).deleteTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED) + .assertLastError().containsErrorKey(RestErrorModel.DELETE_EMPTY_ARGUMENT) + .containsSummary(RestErrorModel.DELETE_EMPTY_ARGUMENT) + .stackTraceIs(RestErrorModel.STACKTRACE) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Delete task variable with empty variable scope") + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void deleteTaskEmptyVariableScope() throws Exception + { + restClient.authenticateUser(userModel); + RestVariableModel variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + + restClient.withWorkflowAPI().usingTask(taskModel).addTaskVariable(variableModel); + variableModel.setScope(""); + variableModel.setType(""); + restClient.withWorkflowAPI().usingTask(taskModel).deleteTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withWorkflowAPI().usingTask(taskModel).getTaskVariables() + .assertThat().entriesListDoesNotContain("name", variableModel.getName()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Delete task variable with invalid variable name") + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void deleteTaskInvalidVariableName() throws Exception + { + restClient.authenticateUser(userModel); + RestVariableModel variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + + restClient.withWorkflowAPI().usingTask(taskModel).addTaskVariable(variableModel); + variableModel.setName("invalid-name"); + restClient.withWorkflowAPI().usingTask(taskModel).deleteTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "invalid-name")) + .stackTraceIs(RestErrorModel.STACKTRACE) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/variables/GetTaskVariablesTests.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/variables/GetTaskVariablesTests.java new file mode 100644 index 0000000000..ecf6ba4ede --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/variables/GetTaskVariablesTests.java @@ -0,0 +1,252 @@ +package org.alfresco.rest.workflow.tasks.variables; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.rest.model.RestTaskModel; +import org.alfresco.rest.model.RestVariableModelsCollection; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TaskModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class GetTaskVariablesTests extends RestTest +{ + private UserModel userWhoStartsTask, assignee; + private SiteModel siteModel; + private FileModel fileModel; + private TaskModel taskModel; + private RestVariableModelsCollection variableModels; + + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + userWhoStartsTask = dataUser.createRandomTestUser(); + assignee = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userWhoStartsTask).createPublicRandomSite(); + fileModel = dataContent.usingUser(userWhoStartsTask).usingSite(siteModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.SANITY, + description = "Verify that user that started the process gets task variables") + public void getTaskVariablesByUserWhoStartedProcess() throws Exception + { + taskModel = dataWorkflow.usingUser(userWhoStartsTask) + .usingSite(siteModel).usingResource(fileModel) + .createNewTaskAndAssignTo(assignee); + restClient.authenticateUser(userWhoStartsTask); + variableModels = restClient.withWorkflowAPI().usingTask(taskModel).getTaskVariables(); + restClient.assertStatusCodeIs(HttpStatus.OK); + variableModels.assertThat().entriesListIsNotEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.SANITY, + description = "Verify that user that is involved in the process gets task variables") + public void getTaskVariablesByUserInvolvedInProcess() throws Exception + { + taskModel = dataWorkflow.usingUser(userWhoStartsTask) + .usingSite(siteModel).usingResource(fileModel) + .createNewTaskAndAssignTo(assignee); + restClient.authenticateUser(assignee); + variableModels = restClient.withWorkflowAPI().usingTask(taskModel).getTaskVariables(); + restClient.assertStatusCodeIs(HttpStatus.OK); + variableModels.assertThat().entriesListIsNotEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.SANITY, + description = "Verify that user that is not involved in the process gets task variables") + public void getTaskVariablesUsingAnyUser() throws Exception + { + UserModel randomUser = dataUser.createRandomTestUser(); + taskModel = dataWorkflow.usingUser(userWhoStartsTask) + .usingSite(siteModel).usingResource(fileModel) + .createNewTaskAndAssignTo(assignee); + restClient.authenticateUser(randomUser); + restClient.withWorkflowAPI().usingTask(taskModel).getTaskVariables(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.SANITY, + description = "Verify that admin is able to task variables") + public void getTaskVariablesUsingAdmin() throws Exception + { + UserModel adminUser = dataUser.getAdminUser(); + taskModel = dataWorkflow.usingUser(userWhoStartsTask) + .usingSite(siteModel).usingResource(fileModel) + .createNewTaskAndAssignTo(assignee); + restClient.authenticateUser(adminUser); + variableModels = restClient.withWorkflowAPI().usingTask(taskModel).getTaskVariables(); + restClient.assertStatusCodeIs(HttpStatus.OK); + variableModels.assertThat().entriesListIsNotEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify if get task variables request returns status code 404 when invalid taskId is used") + public void getTaskVariablesUsingInvalidTaskId() throws Exception + { + taskModel = dataWorkflow.usingUser(userWhoStartsTask) + .usingSite(siteModel).usingResource(fileModel) + .createNewTaskAndAssignTo(assignee); + taskModel.setId("invalidId"); + + restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI().usingTask(taskModel).getTaskVariables(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "invalidId")) + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .stackTraceIs(RestErrorModel.STACKTRACE) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify if get task variables request returns status code 404 when empty taskId is used") + public void getTaskVariablesUsingEmptyTaskId() throws Exception + { + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assignee); + taskModel.setId(""); + + restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI().usingTask(taskModel).getTaskVariables(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "")); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify if get task variables request returns status code 200 after the task is finished.") + public void getTaskVariablesAfterFinishingTask() throws Exception + { + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assignee); + dataWorkflow.usingUser(assignee).taskDone(taskModel); + + variableModels = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI().usingTask(taskModel).getTaskVariables(); + restClient.assertStatusCodeIs(HttpStatus.OK); + variableModels.assertThat().entriesListIsNotEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify if get task variables request returns status code 200 after the process is deleted (Task state is now completed.)") + public void getTaskVariablesAfterDeletingProcess() throws Exception + { + RestProcessModel addedProcess = restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI().addProcess("activitiAdhoc", assignee, false, CMISUtil.Priority.Normal); + RestTaskModel addedTask = restClient.withWorkflowAPI().getTasks().getTaskModelByProcess(addedProcess); + restClient.withWorkflowAPI().usingProcess(addedProcess).deleteProcess(); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + variableModels = restClient.withWorkflowAPI().usingTask(addedTask).getTaskVariables(); + restClient.assertStatusCodeIs(HttpStatus.OK); + variableModels.assertThat().entriesListIsNotEmpty(); + } + + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify user gets task variables that matches a where clause.") + public void getTaskVariablesWithWhereClauseAsParameter() throws Exception + { + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assignee); + variableModels = restClient.authenticateUser(userWhoStartsTask).where("scope='local'") + .withWorkflowAPI().usingTask(taskModel).getTaskVariables(); + restClient.assertStatusCodeIs(HttpStatus.OK); + variableModels.assertThat().entriesListIsNotEmpty() + .and().entriesListDoesNotContain("scope", "global") + .and().paginationField("totalItems").is("8"); + + variableModels = restClient.authenticateUser(userWhoStartsTask) + .withWorkflowAPI().usingTask(taskModel).getTaskVariables(); + restClient.assertStatusCodeIs(HttpStatus.OK); + variableModels.assertThat().entriesListContains("scope", "global") + .and().paginationField("totalItems").is("30"); + } + + @Bug(id="MNT-17438") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify user gets task with 'maxItems' parameter") + public void getTaskVariablesWithMaxItems() throws Exception + { + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assignee); + variableModels = restClient.authenticateUser(userWhoStartsTask) + .withWorkflowAPI().usingParams("maxItems=2").usingTask(taskModel).getTaskVariables(); + restClient.assertStatusCodeIs(HttpStatus.OK); + variableModels.assertThat().entriesListIsNotEmpty() + .and().paginationField("count").is("2"); + } + + @Bug(id="MNT-17438") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify user gets task with 'skipCount' parameter") + public void getTaskVariablesWithSkipCount() throws Exception + { + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assignee); + variableModels = restClient.authenticateUser(userWhoStartsTask) + .withWorkflowAPI().usingParams("skipCount=10").usingTask(taskModel).getTaskVariables(); + restClient.assertStatusCodeIs(HttpStatus.OK); + variableModels.assertThat().entriesListIsNotEmpty() + .and().paginationField("count").is("20"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify user cannot get task variables with invalid where clause.") + public void getTaskVariablesWithInvalidWhereClauseAsParameter() throws Exception + { + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assignee); + variableModels = restClient.authenticateUser(userWhoStartsTask).where("scope='fake-where'") + .withWorkflowAPI().usingTask(taskModel).getTaskVariables(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.INVALID_WHERE_QUERY, "Invalid value for 'scope' used in query: fake-where.")) + .containsErrorKey(RestErrorModel.INVALID_QUERY_ERRORKEY) + .stackTraceIs(RestErrorModel.STACKTRACE) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify user gets tasks variables with 'properties' parameter") + public void getTaskVariablesWithValidProperties() throws Exception + { + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assignee); + variableModels = restClient.authenticateUser(userWhoStartsTask).withParams("properties=scope,name") + .withWorkflowAPI().usingTask(taskModel).getTaskVariables(); + restClient.assertStatusCodeIs(HttpStatus.OK); + variableModels.assertThat().entriesListIsNotEmpty(); + variableModels.getOneRandomEntry().onModel().assertThat() + .fieldsCount().is(2).and() + .field("type").isNull().and() + .field("value").isNull().and() + .field("scope").isNotEmpty().and() + .field("name").isNotEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify user cannot get tasks variables with invalid 'properties' parameter") + public void getTaskVariablesWithInvalidProperties() throws Exception + { + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assignee); + variableModels = restClient.authenticateUser(userWhoStartsTask).withParams("properties=fake") + .withWorkflowAPI().usingTask(taskModel).getTaskVariables(); + restClient.assertStatusCodeIs(HttpStatus.OK); + variableModels.getOneRandomEntry().onModel().assertThat() + .fieldsCount().is(0).and() + .field("type").isNull().and() + .field("value").isNull().and() + .field("scope").isNull().and() + .field("name").isNull(); + } +} diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/variables/UpdateTaskVariableTestsBulk1.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/variables/UpdateTaskVariableTestsBulk1.java new file mode 100644 index 0000000000..93aebeaefc --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/variables/UpdateTaskVariableTestsBulk1.java @@ -0,0 +1,79 @@ +package org.alfresco.rest.workflow.tasks.variables; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestVariableModel; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TaskModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * @author iulia.cojocea + */ +public class UpdateTaskVariableTestsBulk1 extends RestTest +{ + private UserModel userModel; + private UserModel adminUser; + private SiteModel siteModel; + private FileModel fileModel; + private UserModel assigneeUser; + private TaskModel taskModel; + + private RestVariableModel taskVariable; + private RestVariableModel variableModel; + + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + userModel = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); + fileModel = dataContent.usingUser(userModel).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + assigneeUser = dataUser.createRandomTestUser(); + taskModel = dataWorkflow.usingUser(userModel).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assigneeUser); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.SANITY, + description = "Create non-existing task variable") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + public void createTaskVariable() throws Exception + { + restClient.authenticateUser(adminUser); + variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + + taskVariable = restClient.withWorkflowAPI().usingTask(taskModel).updateTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + taskVariable.assertThat().field("scope").is(taskVariable.getScope()) + .and().field("name").is(taskVariable.getName()) + .and().field("type").is(taskVariable.getType()) + .and().field("value").is(taskVariable.getValue()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.SANITY, + description = "Update existing task variable") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + public void updateExistingTaskVariable() throws Exception + { + restClient.authenticateUser(adminUser); + variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + + taskVariable = restClient.withWorkflowAPI().usingTask(taskModel).updateTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + taskVariable.assertThat().field("scope").is(taskVariable.getScope()) + .and().field("name").is(taskVariable.getName()) + .and().field("type").is(taskVariable.getType()) + .and().field("value").is(taskVariable.getValue()); + + variableModel.setValue("updatedValue"); + taskVariable = restClient.withWorkflowAPI().usingTask(taskModel).updateTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + taskVariable.assertThat().field("value").is("updatedValue"); + } +} \ No newline at end of file diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/variables/UpdateTaskVariableTestsBulk2.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/variables/UpdateTaskVariableTestsBulk2.java new file mode 100644 index 0000000000..43ea324da7 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/variables/UpdateTaskVariableTestsBulk2.java @@ -0,0 +1,172 @@ +package org.alfresco.rest.workflow.tasks.variables; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestVariableModel; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TaskModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * @author bogdan.bocancea + */ +public class UpdateTaskVariableTestsBulk2 extends RestTest +{ + private UserModel userModel; + private SiteModel siteModel; + private FileModel fileModel; + private UserModel assigneeUser; + private TaskModel taskModel; + private RestVariableModel taskVariable; + private RestVariableModel variableModel; + + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + userModel = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); + fileModel = dataContent.usingUser(userModel).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + assigneeUser = dataUser.createRandomTestUser(); + taskModel = dataWorkflow.usingUser(userModel).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assigneeUser); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.SANITY, + description = "Update task variable by user who started the process") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.SANITY }) + public void updateTaskVariableByUserWhoStartedProcess() throws Exception + { + variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + taskVariable = restClient.authenticateUser(userModel) + .withWorkflowAPI().usingTask(taskModel).addTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + variableModel.setValue("new-value"); + variableModel.setName("new-name"); + taskVariable = restClient.authenticateUser(userModel). + withWorkflowAPI().usingTask(taskModel).updateTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + taskVariable.assertThat().field("value").is("new-value") + .and().field("name").is("new-name"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Update task variable with symbols in name") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void updateTaskVariableWithSymbolsInName() throws Exception + { + String symbolName = "<>.,;-'+=%|[]#*&-+"; + variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + taskVariable = restClient.authenticateUser(userModel) + .withWorkflowAPI().usingTask(taskModel).addTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + variableModel.setName(symbolName); + taskVariable = restClient.authenticateUser(userModel). + withWorkflowAPI().usingTask(taskModel).updateTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + taskVariable.assertThat().field("name").is(symbolName); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Update task variable with invalid task id") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void updateTaskVariableWithInvalidTaskId() throws Exception + { + TaskModel invalidTask = new TaskModel(userModel.getUsername()); + invalidTask.setId("invalid-task-id"); + taskVariable = restClient.authenticateUser(userModel). + withWorkflowAPI().usingTask(invalidTask) + .updateTaskVariable(RestVariableModel.getRandomTaskVariableModel("local", "d:text")); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, invalidTask.getId())); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Update task variable with invalid scope") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void updateTaskVariableWithInvalidScope() throws Exception + { + variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + taskVariable = restClient.authenticateUser(userModel) + .withWorkflowAPI().usingTask(taskModel).addTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + variableModel.setScope("invalid-scope"); + taskVariable = restClient.authenticateUser(userModel). + withWorkflowAPI().usingTask(taskModel).updateTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.ILLEGAL_SCOPE, "invalid-scope")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Update task variable with invalid type") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void updateTaskVariableWithInvalidType() throws Exception + { + variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + taskVariable = restClient.authenticateUser(userModel) + .withWorkflowAPI().usingTask(taskModel).addTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + variableModel.setType("d:invalidType"); + taskVariable = restClient.authenticateUser(userModel). + withWorkflowAPI().usingTask(taskModel).updateTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.UNSUPPORTED_TYPE, "d:invalidType")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Update task variable with symbols in value") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void updateTaskVariableWithSymbolsInValue() throws Exception + { + String symbolValue = "<>.,;-'+=%|[]#*&-+/\\#!@"; + variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + taskVariable = restClient.authenticateUser(userModel) + .withWorkflowAPI().usingTask(taskModel).addTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + variableModel.setValue(symbolValue); + taskVariable = restClient.authenticateUser(userModel). + withWorkflowAPI().usingTask(taskModel).updateTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + taskVariable.assertThat().field("value").is(symbolValue); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Update task variable by non assigned user") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void updateTaskVariableByNonAssignedUser() throws Exception + { + UserModel nonAssigned = dataUser.createRandomTestUser(); + variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + taskVariable = restClient.authenticateUser(userModel) + .withWorkflowAPI().usingTask(taskModel).addTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + variableModel.setName("new-name"); + taskVariable = restClient.authenticateUser(nonAssigned) + .withWorkflowAPI().usingTask(taskModel).updateTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Update task variable by inexistent user") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) +// @Bug(id="MNT-16904", description = "It fails only on environment with tenants") + public void updateTaskVariableByNonexistentUser() throws Exception + { + variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + taskVariable = restClient.authenticateUser(userModel) + .withWorkflowAPI().usingTask(taskModel).addTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + variableModel.setName("new-name"); + taskVariable = restClient.authenticateUser(UserModel.getRandomUserModel()) + .withWorkflowAPI().usingTask(taskModel).updateTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + +} \ No newline at end of file diff --git a/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/variables/UpdateTaskVariableTestsBulk3.java b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/variables/UpdateTaskVariableTestsBulk3.java new file mode 100644 index 0000000000..3ccf14f8e7 --- /dev/null +++ b/tests/tas-restapi/src/test/java/org/alfresco/rest/workflow/tasks/variables/UpdateTaskVariableTestsBulk3.java @@ -0,0 +1,247 @@ +package org.alfresco.rest.workflow.tasks.variables; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestVariableModel; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TaskModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class UpdateTaskVariableTestsBulk3 extends RestTest +{ + private SiteModel siteModel; + private FileModel fileModel; + private TaskModel taskModel; + private UserModel userModel; + private RestVariableModel taskVariable, updatedTaskVariable; + + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + userModel = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); + fileModel = dataContent.usingUser(userModel).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + taskModel = dataWorkflow.usingUser(userModel).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(userModel); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Update task variable with invalid name - PUT call") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void updateTaskVariableWithInvalidVariableName() throws Exception + { + taskVariable = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + restClient.authenticateUser(userModel) + .withWorkflowAPI().usingTask(taskModel).addTaskVariable(taskVariable); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, "{\"scope\": \"local\",\"names\": \"varName\",\"value\": \"test\"," + + "\"type\": \"d:text\"}", + "tasks/{taskId}/variables/{variableName}", taskModel.getId(), taskVariable.getName()); + restClient.processModel(RestVariableModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsSummary(String.format(RestErrorModel.NO_CONTENT,"Unrecognized field " + "\"names\"")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Update task variable with invalid name - PUT call") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void updateTaskVariableWithInvalidVariableValue() throws Exception + { + taskVariable = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + restClient.authenticateUser(userModel) + .withWorkflowAPI().usingTask(taskModel).addTaskVariable(taskVariable); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, "{\"scope\": \"local\",\"name\": \"varName\",\"values\": \"test\"," + + "\"type\": \"d:text\"}", + "tasks/{taskId}/variables/{variableName}", taskModel.getId(), taskVariable.getName()); + restClient.processModel(RestVariableModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsSummary(String.format(RestErrorModel.NO_CONTENT,"Unrecognized field " + "\"values\"")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Update task variable with invalid name - PUT call") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void updateTaskVariableWithEmptyVariableName() throws Exception + { + taskVariable = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + restClient.authenticateUser(userModel) + .withWorkflowAPI().usingTask(taskModel).addTaskVariable(taskVariable); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, "{\"scope\": \"local\",\"\": \"varName\",\"value\": \"test\"," + + "\"type\": \"d:text\"}", + "tasks/{taskId}/variables/{variableName}", taskModel.getId(), taskVariable.getName()); + restClient.processModel(RestVariableModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsSummary(String.format(RestErrorModel.NO_CONTENT,"Unrecognized field " + "\"\"")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Update task variable with empty name - PUT call") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void updateTaskVariableWithEmptyName() throws Exception + { + taskVariable = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + restClient.authenticateUser(userModel).withWorkflowAPI().usingTask(taskModel).addTaskVariable(taskVariable); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + taskVariable.setName(""); + restClient.withWorkflowAPI().usingTask(taskModel).updateTaskVariable(taskVariable); + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED) + .assertLastError().containsErrorKey(RestErrorModel.PUT_EMPTY_ARGUMENT) + .containsSummary(RestErrorModel.PUT_EMPTY_ARGUMENT) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Update task variable with empty name - PUT call") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void updateTaskVariableWithInvalidName() throws Exception + { + taskVariable = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + restClient.authenticateUser(userModel).withWorkflowAPI().usingTask(taskModel).addTaskVariable(taskVariable); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, "{\"scope\": \"local\",\"name\": ',\"value\": \"test\"," + + "\"type\": \"d:text\"}", + "tasks/{taskId}/variables/{variableName}", taskModel.getId(), taskVariable.getName()); + restClient.processModel(RestVariableModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsSummary(String.format(RestErrorModel.NO_CONTENT,"Unexpected character " + "('''")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Update task variable with empty name - PUT call") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void updateTaskVariableWithInvalidValue() throws Exception + { + taskVariable = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + restClient.authenticateUser(userModel).withWorkflowAPI().usingTask(taskModel).addTaskVariable(taskVariable); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, "{\"scope\": \"local\",\"name\": \"varName\",\"value\"::," + + "\"type\": \"d:text\"}", + "tasks/{taskId}/variables/{variableName}", taskModel.getId(), taskVariable.getName()); + restClient.processModel(RestVariableModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsSummary(String.format(RestErrorModel.NO_CONTENT,"Unexpected character " + "(':'")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Update task variable with empty name - PUT call") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void updateTaskVariableWithMissingType() throws Exception + { + taskVariable = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + restClient.authenticateUser(userModel) + .withWorkflowAPI().usingTask(taskModel).addTaskVariable(taskVariable); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, "{\"scope\": \"local\",\"name\": \"varName\",\"value\": \"test\"}", + "tasks/{taskId}/variables/{variableName}", taskModel.getId(), taskVariable.getName()); + restClient.processModel(RestVariableModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.OK); + taskVariable.assertThat().field("scope").is(taskVariable.getScope()) + .and().field("name").is(taskVariable.getName()) + .and().field("type").is("d:text") + .and().field("value").is(taskVariable.getValue()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Update task variable with empty name - PUT call") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void updateTaskVariableWithMissingTypeAndValue() throws Exception + { + taskVariable = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + restClient.authenticateUser(userModel) + .withWorkflowAPI().usingTask(taskModel).addTaskVariable(taskVariable); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, "{\"scope\": \"local\",\"name\": \"varName\"}", + "tasks/{taskId}/variables/{variableName}", taskModel.getId(), taskVariable.getName()); + updatedTaskVariable = restClient.processModel(RestVariableModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.OK); + updatedTaskVariable.assertThat().field("scope").is(updatedTaskVariable.getScope()) + .and().field("name").is(updatedTaskVariable.getName()) + .and().field("type").is("d:any"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Update task variable with invalid name - PUT call") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void updateTaskVariableWithEmptyBody() throws Exception + { + taskVariable = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + restClient.authenticateUser(userModel) + .withWorkflowAPI().usingTask(taskModel).addTaskVariable(taskVariable); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, "{}", + "tasks/{taskId}/variables/{variableName}", taskModel.getId(), taskVariable.getName()); + restClient.processModel(RestVariableModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsErrorKey(RestErrorModel.VARIABLE_NAME_REQUIRED) + .containsSummary(RestErrorModel.VARIABLE_NAME_REQUIRED) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Update task variable with invalid name - PUT call") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void updateTaskVariableWithInvalidBody() throws Exception + { + taskVariable = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + restClient.authenticateUser(userModel) + .withWorkflowAPI().usingTask(taskModel).addTaskVariable(taskVariable); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, "{\"scope\": \"local\",\"name\": \"varName\",\"value\": \"test\"," + + "\"type\": \"d:text\", \"errorKey\": \"invalidBody\"}", + "tasks/{taskId}/variables/{variableName}", taskModel.getId(), taskVariable.getName()); + restClient.processModel(RestVariableModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsSummary(String.format(RestErrorModel.NO_CONTENT,"Unrecognized field " + "\"errorKey\"")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Update task variable with empty name - PUT call") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.REGRESSION }) + public void updateTwiceInARowSameTaskVariable() throws Exception + { + taskVariable = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + restClient.authenticateUser(userModel).withWorkflowAPI().usingTask(taskModel).addTaskVariable(taskVariable); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + taskVariable.setName("newName"); + taskVariable.setScope("global"); + updatedTaskVariable = restClient.withWorkflowAPI().usingTask(taskModel).updateTaskVariable(taskVariable); + restClient.assertStatusCodeIs(HttpStatus.OK); + updatedTaskVariable.assertThat().field("scope").is("global"); + updatedTaskVariable.assertThat().field("name").is("newName"); + + updatedTaskVariable = restClient.withWorkflowAPI().usingTask(taskModel).updateTaskVariable(taskVariable); + restClient.assertStatusCodeIs(HttpStatus.OK); + updatedTaskVariable.assertThat().field("scope").is("global"); + updatedTaskVariable.assertThat().field("name").is("newName"); + } +} diff --git a/tests/tas-restapi/src/test/resources/alfresco-restapi-context.xml b/tests/tas-restapi/src/test/resources/alfresco-restapi-context.xml new file mode 100644 index 0000000000..0f730f629c --- /dev/null +++ b/tests/tas-restapi/src/test/resources/alfresco-restapi-context.xml @@ -0,0 +1,14 @@ + + + + + + + + + diff --git a/tests/tas-restapi/src/test/resources/default.properties b/tests/tas-restapi/src/test/resources/default.properties new file mode 100644 index 0000000000..60d58a5b73 --- /dev/null +++ b/tests/tas-restapi/src/test/resources/default.properties @@ -0,0 +1,89 @@ +# dataprep related +alfresco.scheme=http +alfresco.server=localhost +alfresco.port=8082 + +# sync service related +sync.scheme=http +sync.server=localhost +sync.port=9090 + +# Solr Server Settings +solr.scheme=http +solr.server=localhost +solr.port=8083 + +#Solr Indexing Time +solrWaitTimeInSeconds=20 + +# credentials +admin.user=admin +admin.password=admin + +# Identity Service configuration +# set this property to run tests using AIS +# identity-service.auth-server-url=http://localhost:8999/auth + +# in containers we cannot access directly JMX, so we will use http://jolokia.org agent +# disabling this we will use direct JMX calls to server +jmx.useJolokiaAgent=false + +# Server Health section +# in ServerHealth#isServerReachable() - could also be shown. +# enable this option to view if on server there are tenants or not +serverHealth.showTenants=false + +# TEST MANAGEMENT SECTION - Test Rail +# +# (currently supporting Test Rail v5.2.1.3472 integration) +# +# Example of configuration: +# ------------------------------------------------------ +# if testManagement.enabled=true we enabled TestRailExecutorListener (if used in your suite xml file) +# testManagement.updateTestExecutionResultsOnly=true (this will just update the results of a test: no step will be updated - good for performance) +# testManagement.endPoint=https://alfresco.testrail.com/ +# testManagement.username= +# testManagement.apiKey= +# testManagement.project= +# testManagement.includeOnlyTestCasesExecuted=true #if you want to include in your run ONLY the test cases that you run, then set this value to false +# testManagement.rateLimitInSeconds=1 #is the default rate limit after what minimum time, should we upload the next request. http://docs.gurock.com/testrail-api2/introduction #Rate Limit +# testManagement.suiteId=23 (the id of the Master suite) +# ------------------------------------------------------ +testManagement.enabled=false +testManagement.endPoint=https://alfresco.testrail.com/ +testManagement.username= +testManagement.apiKey= +testManagement.project=7 +testManagement.includeOnlyTestCasesExecuted=true +testManagement.rateLimitInSeconds=1 +testManagement.testRun=MyTestRunInTestRail +testManagement.suiteId=12 + +# The location of the reports path +reports.path=./target/reports + +# +# Database Section +# You should provide here the database URL, that can be a differed server as alfresco. +# https://docs.oracle.com/javase/tutorial/jdbc/basics/connecting.html +# +# Current supported db.url: +# +# MySQL: +# db.url = jdbc:mysql://${alfresco.server}:3306/alfresco +# +# PostgreSQL: +# db.url = jdbc:postgresql://:3306/alfresco +# +# Oracle: +# db.url = jdbc:oracle://:3306/alfresco +# +# MariaDB: +# db.url = jdbc:mariadb://:3306/alfresco +# +db.url = jdbc:mysql://${alfresco.server}:3306/alfresco +db.username = alfresco +db.password = alfresco + +environment=default \ No newline at end of file diff --git a/tests/tas-restapi/src/test/resources/log4j.properties b/tests/tas-restapi/src/test/resources/log4j.properties new file mode 100644 index 0000000000..00e9b5a114 --- /dev/null +++ b/tests/tas-restapi/src/test/resources/log4j.properties @@ -0,0 +1,26 @@ +# Root logger option +log4j.rootLogger=INFO, file, stdout + +# Direct log messages to a log file +log4j.appender.file=org.apache.log4j.RollingFileAppender +log4j.appender.file.File=./target/reports/alfresco-tas.log +log4j.appender.file.MaxBackupIndex=10 +log4j.appender.file.layout=org.apache.log4j.PatternLayout +log4j.appender.file.layout.ConversionPattern=[%t] %d{HH:mm:ss} %-5p %c{1}:%L - %m%n + +# Direct log messages to stdout +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=[%t] %d{HH:mm:ss} %-5p %c{1}:%L - %m%n + +# TestRail particular log file +# Direct log messages to a log file +log4j.appender.testrailLog=org.apache.log4j.RollingFileAppender +log4j.appender.testrailLog.File=./target/reports/alfresco-testrail.log +log4j.appender.testrailLog.MaxBackupIndex=10 +log4j.appender.testrailLog.layout=org.apache.log4j.PatternLayout +log4j.appender.testrailLog.layout.ConversionPattern=%d{HH:mm:ss} %-5p %c{1}:%L - %m%n + +log4j.category.testrail=INFO, testrailLog +log4j.additivity.testrail=false \ No newline at end of file diff --git a/tests/tas-restapi/src/test/resources/restapi-suite.xml b/tests/tas-restapi/src/test/resources/restapi-suite.xml new file mode 100644 index 0000000000..9009c8ab92 --- /dev/null +++ b/tests/tas-restapi/src/test/resources/restapi-suite.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/tests/tas-restapi/src/test/resources/shared-resources/testdata/UTF-8File.txt b/tests/tas-restapi/src/test/resources/shared-resources/testdata/UTF-8File.txt new file mode 100644 index 0000000000..2f273e7986 --- /dev/null +++ b/tests/tas-restapi/src/test/resources/shared-resources/testdata/UTF-8File.txt @@ -0,0 +1 @@ + ∮ E⋅da = Q \ No newline at end of file diff --git a/tests/tas-restapi/src/test/resources/shared-resources/testdata/avatar.jpg b/tests/tas-restapi/src/test/resources/shared-resources/testdata/avatar.jpg new file mode 100644 index 0000000000..30db230dbd Binary files /dev/null and b/tests/tas-restapi/src/test/resources/shared-resources/testdata/avatar.jpg differ diff --git a/tests/tas-restapi/src/test/resources/shared-resources/testdata/content-zip-test.zip b/tests/tas-restapi/src/test/resources/shared-resources/testdata/content-zip-test.zip new file mode 100644 index 0000000000..61785e62e5 Binary files /dev/null and b/tests/tas-restapi/src/test/resources/shared-resources/testdata/content-zip-test.zip differ diff --git a/tests/tas-restapi/src/test/resources/shared-resources/testdata/iso8859File.txt b/tests/tas-restapi/src/test/resources/shared-resources/testdata/iso8859File.txt new file mode 100644 index 0000000000..05665b37d5 --- /dev/null +++ b/tests/tas-restapi/src/test/resources/shared-resources/testdata/iso8859File.txt @@ -0,0 +1 @@ +aegif Mind Share Leader Generating New Paradigms by aegif corporation

Test html

\ No newline at end of file diff --git a/tests/tas-restapi/src/test/resources/shared-resources/testdata/larger.pdf b/tests/tas-restapi/src/test/resources/shared-resources/testdata/larger.pdf new file mode 100644 index 0000000000..306c8dfc73 Binary files /dev/null and b/tests/tas-restapi/src/test/resources/shared-resources/testdata/larger.pdf differ diff --git a/tests/tas-restapi/src/test/resources/shared-resources/testdata/my-file.tif b/tests/tas-restapi/src/test/resources/shared-resources/testdata/my-file.tif new file mode 100644 index 0000000000..612bfa9c0b Binary files /dev/null and b/tests/tas-restapi/src/test/resources/shared-resources/testdata/my-file.tif differ diff --git a/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.doc b/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.doc new file mode 100644 index 0000000000..eb307fb218 Binary files /dev/null and b/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.doc differ diff --git a/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.docx b/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.docx new file mode 100644 index 0000000000..64832464bb Binary files /dev/null and b/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.docx differ diff --git a/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.gif b/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.gif new file mode 100644 index 0000000000..5e4e40e091 Binary files /dev/null and b/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.gif differ diff --git a/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.jpg b/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.jpg new file mode 100644 index 0000000000..08473b8e8b Binary files /dev/null and b/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.jpg differ diff --git a/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.msg b/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.msg new file mode 100644 index 0000000000..6ee3750070 Binary files /dev/null and b/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.msg differ diff --git a/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.pdf b/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.pdf new file mode 100644 index 0000000000..a1779afd8b Binary files /dev/null and b/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.pdf differ diff --git a/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.png b/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.png new file mode 100644 index 0000000000..8f1f89b8fc Binary files /dev/null and b/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.png differ diff --git a/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.ppt b/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.ppt new file mode 100644 index 0000000000..5e3f1ef58b Binary files /dev/null and b/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.ppt differ diff --git a/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.pptx b/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.pptx new file mode 100644 index 0000000000..666b5d7ea1 Binary files /dev/null and b/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.pptx differ diff --git a/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.tiff b/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.tiff new file mode 100644 index 0000000000..e8069e0925 Binary files /dev/null and b/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.tiff differ diff --git a/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.txt b/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.txt new file mode 100644 index 0000000000..f6aeb6e983 --- /dev/null +++ b/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.txt @@ -0,0 +1,7 @@ +The quick brown fox jumps over the lazy dog + +Le renard brun rapide saute par-dessus le chien paresseux + +Der schnelle braune Fuchs springt über den faulen Hund + +براون وكس السريع يقفز فوق الكلب كسالي \ No newline at end of file diff --git a/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.xls b/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.xls new file mode 100644 index 0000000000..e6ec64cb4d Binary files /dev/null and b/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.xls differ diff --git a/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.xlsx b/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.xlsx new file mode 100644 index 0000000000..2e1f271ed8 Binary files /dev/null and b/tests/tas-restapi/src/test/resources/shared-resources/testdata/quick/quick.xlsx differ diff --git a/tests/tas-restapi/src/test/resources/shared-resources/testdata/restapi-resource b/tests/tas-restapi/src/test/resources/shared-resources/testdata/restapi-resource new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/tas-restapi/src/test/resources/shared-resources/testdata/sampleContent.txt b/tests/tas-restapi/src/test/resources/shared-resources/testdata/sampleContent.txt new file mode 100644 index 0000000000..1519fdbdbe --- /dev/null +++ b/tests/tas-restapi/src/test/resources/shared-resources/testdata/sampleContent.txt @@ -0,0 +1 @@ +Sample text. \ No newline at end of file diff --git a/tests/tas-webdav/pom.xml b/tests/tas-webdav/pom.xml new file mode 100644 index 0000000000..9c96c26972 --- /dev/null +++ b/tests/tas-webdav/pom.xml @@ -0,0 +1,66 @@ + + + 4.0.0 + org.alfresco.tas + content-repository-community-webdav-test + content-repository-community-webdav-test + 6.3.0-SNAPSHOT + jar + + + org.alfresco + content-repository-community-tas-tests-parent + 6.3.0-SNAPSHOT + ../pom.xml + + + + + Paul Brodner + + Test Automation Architect + + + + + + ${project.basedir}/src/test/resources/webdav-suite.xml + + + + + org.alfresco.tas + webdav + test + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + ${suiteXmlFile} + + + --illegal-access=warn + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + test-jar + + + + + + + diff --git a/tests/tas-webdav/src/test/java/org/alfresco/webdav/CopyTests.java b/tests/tas-webdav/src/test/java/org/alfresco/webdav/CopyTests.java new file mode 100644 index 0000000000..b4256f2ca6 --- /dev/null +++ b/tests/tas-webdav/src/test/java/org/alfresco/webdav/CopyTests.java @@ -0,0 +1,472 @@ +package org.alfresco.webdav; + +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.RandomData; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +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.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.commons.httpclient.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class CopyTests extends WebDavTest +{ + UserModel managerUser, adminUser; + SiteModel testSite; + FolderModel sourceFolder, destinationFolder; + FileModel testFile; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + managerUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(managerUser).createPublicRandomSite(); + destinationFolder = FolderModel.getRandomFolderModel(); + adminUser = dataUser.getAdminUser(); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite).createFolder(destinationFolder); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.SANITY, + description = "Verify that admin user can copy an empty folder in repository") + public void adminShouldCopyEmptyFolderToNewLocation() throws Exception + { + FolderModel guest = FolderModel.getGuestHomeFolderModel(); + sourceFolder = new FolderModel("copy " + RandomData.getRandomFolder()); + + webDavProtocol.authenticateUser(adminUser).usingRoot().createFolder(sourceFolder).then() + .copyTo(guest).and().assertThat().existsInRepo() + .and().assertThat().hasStatus(HttpStatus.SC_CREATED).when() + .usingResource(sourceFolder).assertThat().existsInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType = ExecutionType.REGRESSION, + description = "Verify that an user with site manager role can copy an empty folder with content in site") + public void siteManagerUserShouldCopyEmptyFolder() throws Exception + { + UserModel managerUser = dataUser.createRandomTestUser(); + dataUser.usingUser(managerUser).addUserToSite(managerUser, testSite, UserRole.SiteManager); + sourceFolder = FolderModel.getRandomFolderModel(); + + webDavProtocol.authenticateUser(adminUser).usingSite(testSite).createFolder(sourceFolder).and().assertThat().existsInRepo() + .then().copyTo(destinationFolder).and().assertThat().existsInRepo().and().assertThat() + .hasStatus(HttpStatus.SC_CREATED).when().usingResource(sourceFolder) + .assertThat().existsInRepo(); + } + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType = ExecutionType.REGRESSION, + description = "Verify that site manager can copy an empty folder with content in site") + public void siteManagerShouldCopyEmptyFolder() throws Exception + { + sourceFolder = FolderModel.getRandomFolderModel(); + + webDavProtocol.authenticateUser(managerUser).usingSite(testSite).createFolder(sourceFolder).assertThat().existsInRepo() + .then().copyTo(destinationFolder) + .and().assertThat().existsInRepo().and().assertThat().hasStatus(HttpStatus.SC_CREATED) + .when().usingResource(sourceFolder).assertThat().existsInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType = ExecutionType.SANITY, + description = "Verify that an user with site manager role can copy folder with content in site") + public void siteManagerUserShouldCopyFolderWithContent() throws Exception + { + sourceFolder = FolderModel.getRandomFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.MSEXCEL); + UserModel managerUser = dataUser.createRandomTestUser(); + dataUser.usingUser(managerUser).addUserToSite(managerUser, testSite, UserRole.SiteManager); + + webDavProtocol.authenticateUser(adminUser).usingSite(testSite).createFolder(sourceFolder) + .then().usingResource(sourceFolder).createFile(testFile) + .and().assertThat().existsInRepo().when().usingResource(sourceFolder).copyTo(destinationFolder) + .and().assertThat().existsInRepo().and().assertThat().hasStatus(HttpStatus.SC_CREATED) + .and().assertThat().hasFiles(testFile).then().usingResource(sourceFolder).assertThat() + .existsInRepo().and().usingResource(testFile).assertThat().existsInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType = ExecutionType.SANITY, + description = "Verify that site manager can copy folder with content in site") + public void siteManagerShouldCopyFolderWithContent() throws Exception + { + sourceFolder = FolderModel.getRandomFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.MSEXCEL); + + webDavProtocol.authenticateUser(managerUser).usingSite(testSite).createFolder(sourceFolder) + .then().usingResource(sourceFolder).createFile(testFile).and().assertThat().existsInRepo() + .when().usingResource(sourceFolder) + .copyTo(destinationFolder).and().assertThat().existsInRepo().and() + .assertThat().hasStatus(HttpStatus.SC_CREATED).and().assertThat().hasFiles(testFile).then() + .usingResource(sourceFolder).assertThat() + .existsInRepo().and().usingResource(testFile).assertThat().existsInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType = ExecutionType.REGRESSION, + description = "Verify that user with collaborator role can copy an empty folder in site folder") + public void siteCollaboratorShouldCopyEmptyFolderAddedByOtherUser() throws Exception + { + UserModel collaborator = dataUser.createRandomTestUser(); + dataUser.usingUser(managerUser).addUserToSite(collaborator, testSite, UserRole.SiteCollaborator); + sourceFolder = FolderModel.getRandomFolderModel(); + + webDavProtocol.authenticateUser(managerUser).usingSite(testSite).createFolder(sourceFolder) + .and().assertThat().existsInRepo().then() + .authenticateUser(collaborator).usingResource(sourceFolder).copyTo(destinationFolder) + .and().assertThat().existsInRepo().and() + .assertThat().hasStatus(HttpStatus.SC_CREATED) + .when().usingResource(sourceFolder).assertThat().existsInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.SANITY, + description = "Verify that user with collaborator role can copy folder with content in site folder") + public void siteCollaboratorShouldCopyFolderWithContentAddedByOtherUser() throws Exception + { + sourceFolder = FolderModel.getRandomFolderModel(); + UserModel collaborator = dataUser.createRandomTestUser(); + testFile = FileModel.getRandomFileModel(FileType.XML); + dataUser.usingUser(managerUser).addUserToSite(collaborator, testSite, UserRole.SiteCollaborator); + + webDavProtocol.authenticateUser(managerUser).usingSite(testSite).createFolder(sourceFolder) + .and().usingResource(sourceFolder).createFile(testFile) + .then().authenticateUser(collaborator).usingResource(sourceFolder).copyTo(destinationFolder) + .and().assertThat().existsInRepo().and() + .assertThat().hasStatus(HttpStatus.SC_CREATED).and().assertThat().hasFiles(testFile) + .then().usingResource(sourceFolder).assertThat() + .existsInRepo().and().usingResource(testFile).assertThat().existsInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType = ExecutionType.REGRESSION, + description = "Verify that user with collaborator role can copy a file in site") + public void siteCollaboratorShouldCopyFileAddedByOtherUser() throws Exception + { + UserModel collaborator = dataUser.createRandomTestUser(); + dataUser.usingUser(managerUser).addUserToSite(collaborator, testSite, UserRole.SiteCollaborator); + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + + webDavProtocol.authenticateUser(managerUser).usingSite(testSite).createFile(testFile) + .and().assertThat().existsInRepo().then() + .authenticateUser(collaborator).usingResource(testFile).copyTo(destinationFolder) + .and().assertThat().existsInRepo().and() + .assertThat().hasStatus(HttpStatus.SC_CREATED) + .when().usingResource(testFile).assertThat().existsInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType = ExecutionType.REGRESSION, + description = "Verify that user with contribuitor role can copy an empty folder in site") + public void siteContribuitorShouldCopyEmptyFolderAddedByOtherUser() throws Exception + { + UserModel contributor = dataUser.createRandomTestUser(); + dataUser.usingUser(managerUser).addUserToSite(contributor, testSite, UserRole.SiteContributor); + sourceFolder = FolderModel.getRandomFolderModel(); + + webDavProtocol.authenticateUser(managerUser).usingSite(testSite).createFolder(sourceFolder) + .and().assertThat().existsInRepo().then().authenticateUser(contributor) + .usingResource(sourceFolder).copyTo(destinationFolder).and().assertThat().existsInRepo().and() + .assertThat().hasStatus(HttpStatus.SC_CREATED) + .when().usingResource(sourceFolder).assertThat().existsInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType = ExecutionType.SANITY, + description = "Verify that user with contributor role can copy folder with content in site folder") + public void siteContributorShouldCopyFolderWithContentAddedByOtherUser() throws Exception + { + sourceFolder = FolderModel.getRandomFolderModel(); + UserModel contributor = dataUser.createRandomTestUser(); + testFile = FileModel.getRandomFileModel(FileType.PDF); + dataUser.usingUser(managerUser).addUserToSite(contributor, testSite, UserRole.SiteContributor); + + webDavProtocol.authenticateUser(managerUser).usingSite(testSite).createFolder(sourceFolder) + .and().usingResource(sourceFolder).createFile(testFile) + .then().authenticateUser(contributor).usingResource(sourceFolder).copyTo(destinationFolder) + .and().assertThat().existsInRepo().and() + .assertThat().hasStatus(HttpStatus.SC_CREATED).and().assertThat().hasFiles(testFile) + .when().usingResource(sourceFolder).assertThat() + .existsInRepo().and().usingResource(testFile).assertThat().existsInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType = ExecutionType.REGRESSION, + description = "Verify that user with contributor role can copy a file in site") + public void siteContributorShouldCopyFileAddedByOtherUser() throws Exception + { + UserModel contributor = dataUser.createRandomTestUser(); + dataUser.usingUser(managerUser).addUserToSite(contributor, testSite, UserRole.SiteCollaborator); + testFile = FileModel.getRandomFileModel(FileType.MSWORD); + + webDavProtocol.authenticateUser(managerUser).usingSite(testSite).createFile(testFile) + .and().assertThat().existsInRepo().then() + .authenticateUser(contributor).usingResource(testFile) + .copyTo(destinationFolder).and().assertThat().existsInRepo().and() + .assertThat().hasStatus(HttpStatus.SC_CREATED) + .when().usingResource(testFile).assertThat().existsInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType = ExecutionType.REGRESSION, + description = "Verify that user with consumer role cannot copy an empty folder in site") + public void siteConsumerShouldNotCopyEmptyFolderAddedByOtherUser() throws Exception + { + sourceFolder = FolderModel.getRandomFolderModel(); + UserModel consumer = dataUser.createRandomTestUser(); + dataUser.usingUser(managerUser).addUserToSite(consumer, testSite, UserRole.SiteConsumer); + + webDavProtocol.authenticateUser(managerUser).usingSite(testSite).createFolder(sourceFolder) + .and().assertThat().existsInRepo().then() + .authenticateUser(consumer).usingResource(sourceFolder).copyTo(destinationFolder) + .and().assertThat().doesNotExistInRepo().and() + .assertThat().hasStatus(HttpStatus.SC_FORBIDDEN) + .when().usingResource(sourceFolder).assertThat().existsInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY}) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.SANITY, + description = "Verify that user with consumer role cannot copy folder with content in site folder") + public void siteConsumerShouldNotCopyFolderWithContentAddedByOther() throws Exception + { + sourceFolder = FolderModel.getRandomFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.MSPOWERPOINT); + UserModel consumer = dataUser.createRandomTestUser(); + dataUser.usingUser(managerUser).addUserToSite(consumer, testSite, UserRole.SiteConsumer); + + webDavProtocol.authenticateUser(managerUser).usingSite(testSite).createFolder(sourceFolder) + .and().usingResource(sourceFolder).createFile(testFile) + .then().authenticateUser(consumer).usingResource(sourceFolder).copyTo(destinationFolder) + .and().assertThat().doesNotExistInRepo().and() + .assertThat().hasStatus(HttpStatus.SC_FORBIDDEN) + .when().usingResource(sourceFolder).assertThat().existsInRepo() + .and().usingResource(testFile).assertThat().existsInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType = ExecutionType.REGRESSION, + description = "Verify that user with consumer role cannot copy a file in site") + public void siteConsumerShouldNotCopyFileAddedByOtherUser() throws Exception + { + UserModel consumer = dataUser.createRandomTestUser(); + testFile = FileModel.getRandomFileModel(FileType.HTML); + dataUser.usingUser(managerUser).addUserToSite(consumer, testSite, UserRole.SiteConsumer); + + webDavProtocol.authenticateUser(managerUser).usingSite(testSite).createFile(testFile) + .and().assertThat().existsInRepo().then().authenticateUser(consumer) + .usingResource(testFile).copyTo(destinationFolder).and().assertThat().doesNotExistInRepo().and() + .assertThat().hasStatus(HttpStatus.SC_FORBIDDEN) + .when().usingResource(testFile).assertThat().existsInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.SANITY, + description = "Verify that site manager can copy file from site in repository") + public void siteManagerShouldCopyFileInRepository() throws Exception + { + FolderModel guest = FolderModel.getSharedFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.MSEXCEL); + + webDavProtocol.authenticateUser(managerUser).usingSite(testSite).createFile(testFile) + .copyTo(guest).assertThat().existsInRepo().and().assertThat() + .hasStatus(HttpStatus.SC_CREATED) + .then().usingResource(testFile).assertThat().existsInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.REGRESSION, + description = "Verify that site manager can copy an empty folder twice in same location") + public void siteManagerShouldCopyEmptyFolderTwiceInSameLocation() throws Exception + { + sourceFolder = FolderModel.getRandomFolderModel(); + + webDavProtocol.authenticateUser(managerUser).usingSite(testSite).createFolder(sourceFolder) + .copyTo(destinationFolder).assertThat().existsInRepo() + .and().assertThat().hasStatus(HttpStatus.SC_CREATED) + .then().copyTo(destinationFolder).assertThat().existsInRepo() + .and().assertThat().hasStatus(HttpStatus.SC_CREATED); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.REGRESSION, + description = "Verify that site manager can copy a folder with content twice in same location") + public void siteManagerShouldCopyFolderWithContentTwiceInSameLocation() throws Exception + { + sourceFolder = FolderModel.getRandomFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.HTML); + + webDavProtocol.authenticateUser(managerUser).usingSite(testSite).createFolder(sourceFolder) + .and().usingResource(sourceFolder).createFile(testFile) + .copyTo(destinationFolder).assertThat().existsInRepo() + .and().assertThat().hasStatus(HttpStatus.SC_CREATED).then().copyTo(destinationFolder) + .assertThat().existsInRepo().and().assertThat().hasStatus(HttpStatus.SC_CREATED); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that site manager cannot copy nonexistent folder with content from site") + public void siteManagerShouldNotCopyNonexistentFolderWithContent() throws Exception + { + UserModel managerUser = dataUser.createRandomTestUser(); + dataUser.usingUser(managerUser).addUserToSite(managerUser, testSite, UserRole.SiteManager); + sourceFolder = FolderModel.getRandomFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.HTML); + + webDavProtocol.authenticateUser(managerUser).usingSite(testSite).createFolder(sourceFolder) + .and().usingResource(sourceFolder).createFile(testFile) + .delete().and().assertThat().doesNotExistInRepo() + .when().copyTo(destinationFolder).assertThat().hasStatus(HttpStatus.SC_NOT_FOUND); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that site manager cannot copy nonexistent empty folder from site") + public void siteManagerShouldNotCopyNonexistentEmptyFolder() throws Exception + { + UserModel managerUser = dataUser.createRandomTestUser(); + dataUser.usingUser(managerUser).addUserToSite(managerUser, testSite, UserRole.SiteManager); + sourceFolder = FolderModel.getRandomFolderModel(); + + webDavProtocol.authenticateUser(managerUser).usingSite(testSite).createFolder(sourceFolder) + .delete().and().assertThat().doesNotExistInRepo() + .when().copyTo(destinationFolder).assertThat().hasStatus(HttpStatus.SC_NOT_FOUND); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that site manager cannot copy nonexistent file from site") + public void siteManagerShouldNotCopyNonexistentFile() throws Exception + { + UserModel managerUser = dataUser.createRandomTestUser(); + dataUser.usingUser(managerUser).addUserToSite(managerUser, testSite, UserRole.SiteManager); + testFile = FileModel.getRandomFileModel(FileType.HTML); + + webDavProtocol.authenticateUser(managerUser).usingSite(testSite).createFile(testFile) + .delete().and().assertThat().doesNotExistInRepo().when().copyTo(destinationFolder) + .assertThat().hasStatus(HttpStatus.SC_NOT_FOUND); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that unauthenticated user cannot copy a folder with content from site") + public void unauthenticatedUserShouldNotCopyFolderWithContent() throws Exception + { + sourceFolder = FolderModel.getRandomFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.HTML); + + webDavProtocol.authenticateUser(managerUser).usingSite(testSite).createFolder(sourceFolder) + .and().usingResource(sourceFolder).createFile(testFile) + .and().assertThat().existsInRepo().when().disconnect().usingResource(sourceFolder) + .copyTo(destinationFolder).and().assertThat().doesNotExistInRepo() + .and().assertThat().hasStatus(HttpStatus.SC_UNAUTHORIZED) + .then().usingResource(sourceFolder).assertThat().existsInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that unauthenticated user cannot copy an empty folder from site") + public void unauthenticatedUserShouldNotCopyEmptyFolder() throws Exception + { + sourceFolder = FolderModel.getRandomFolderModel(); + + webDavProtocol.authenticateUser(managerUser).usingSite(testSite).createFolder(sourceFolder) + .and().assertThat().existsInRepo().when().disconnect().usingResource(sourceFolder) + .copyTo(destinationFolder).assertThat().doesNotExistInRepo() + .and().assertThat().hasStatus(HttpStatus.SC_UNAUTHORIZED) + .then().usingResource(sourceFolder).assertThat().existsInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that unauthenticated user cannot copy a file from site") + public void unauthenticatedUserShouldNotCopyFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.HTML); + + webDavProtocol.authenticateUser(managerUser).usingSite(testSite).createFile(testFile) + .and().assertThat().existsInRepo().when().disconnect().usingResource(testFile) + .copyTo(destinationFolder).assertThat().doesNotExistInRepo() + .and().assertThat().hasStatus(HttpStatus.SC_UNAUTHORIZED) + .then().usingResource(testFile).assertThat().existsInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that nonnexistent user cannot copy a folder with content from site") + public void nonexistentUserShouldNotCopyFolderWithContent() throws Exception + { + sourceFolder = FolderModel.getRandomFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.HTML); + + webDavProtocol.authenticateUser(managerUser).usingSite(testSite).createFolder(sourceFolder) + .and().usingResource(sourceFolder).createFile(testFile) + .and().assertThat().existsInRepo().then().authenticateUser(UserModel.getRandomUserModel()).usingResource(sourceFolder) + .copyTo(destinationFolder).then().usingAdmin().and().assertThat().hasStatus(HttpStatus.SC_UNAUTHORIZED) + .assertThat().doesNotExistInRepo().then().usingResource(sourceFolder).assertThat().existsInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that nonexistent user cannot copy an empty folder from site") + public void nonexistentUserShouldNotCopyEmptyFolder() throws Exception + { + sourceFolder = FolderModel.getRandomFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.HTML); + + webDavProtocol.authenticateUser(managerUser).usingSite(testSite).createFolder(sourceFolder) + .and().assertThat().existsInRepo() + .then().authenticateUser(UserModel.getRandomUserModel()).usingResource(sourceFolder) + .copyTo(destinationFolder).then().usingAdmin().and().assertThat().hasStatus(HttpStatus.SC_UNAUTHORIZED) + .assertThat().doesNotExistInRepo().then().usingResource(sourceFolder).assertThat().existsInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that unauthorized user cannot copy an empty folder from site") + public void unauthorizedUserShouldNotCopyEmptyFolder() throws Exception + { + UserModel unauthorizedUser = dataUser.createRandomTestUser(); + sourceFolder = FolderModel.getRandomFolderModel(); + + webDavProtocol.authenticateUser(adminUser).usingRoot().createFolder(sourceFolder).and().assertThat().existsInRepo() + .when().authenticateUser(unauthorizedUser).usingResource(sourceFolder) + .copyTo(destinationFolder).assertThat().hasStatus(HttpStatus.SC_FORBIDDEN).and() + .assertThat().doesNotExistInRepo().then().usingResource(sourceFolder).assertThat().existsInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that unauthorized user cannot copy a folder with content from site") + public void unauthorizedUserShouldNotCopyFolderWithContent() throws Exception + { + UserModel unauthorizedUser = dataUser.createRandomTestUser(); + sourceFolder = FolderModel.getRandomFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.HTML); + + webDavProtocol.authenticateUser(adminUser).usingRoot().createFolder(sourceFolder).and().usingResource(sourceFolder) + .createFile(testFile).and().assertThat().existsInRepo() + .when().authenticateUser(unauthorizedUser).usingResource(sourceFolder) + .copyTo(destinationFolder).assertThat().hasStatus(HttpStatus.SC_FORBIDDEN).and() + .assertThat().doesNotExistInRepo().then().usingResource(sourceFolder).assertThat().existsInRepo(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that site manager can copy a locked file") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + public void siteManagerShouldCopyLockedFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSEXCEL); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo() + .lock() + .copyTo(destinationFolder).and().assertThat().existsInRepo() + .and().assertThat().hasStatus(HttpStatus.SC_CREATED) + .and().assertThat().hasFiles(testFile) + .and().usingResource(testFile).assertThat().existsInRepo(); + } +} diff --git a/tests/tas-webdav/src/test/java/org/alfresco/webdav/CreateFileTests.java b/tests/tas-webdav/src/test/java/org/alfresco/webdav/CreateFileTests.java new file mode 100644 index 0000000000..adc5d644b0 --- /dev/null +++ b/tests/tas-webdav/src/test/java/org/alfresco/webdav/CreateFileTests.java @@ -0,0 +1,212 @@ +package org.alfresco.webdav; + +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.RandomData; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +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.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.commons.httpclient.HttpStatus; +import org.junit.Assert; +import org.testng.SkipException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class CreateFileTests extends WebDavTest +{ + UserModel managerUser; + SiteModel testSite; + FileModel testFile; + private String content = "webdav file content"; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + managerUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(managerUser).createPublicRandomSite(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.SANITY, + description ="Verify that admin user can create a file in Guest Home folder") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY}) + public void adminShouldCreateFile() throws Exception + { + FolderModel guestHomeFolder = FolderModel.getGuestHomeFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + webDavProtocol.authenticateUser(dataUser.getAdminUser()).usingResource(guestHomeFolder) + .createFile(testFile).and().assertThat().hasStatus(HttpStatus.SC_CREATED) + .then().assertThat().existsInRepo() + .and().assertThat().existsInWebdav(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.SANITY, + description ="Verify that site manager can create file in site") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY}) + public void siteManagerShouldCreateFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSEXCEL, content); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).and().assertThat().hasStatus(HttpStatus.SC_CREATED) + .then().assertThat().existsInRepo() + .and().assertThat().existsInWebdav().and().assertThat().hasStatus(HttpStatus.SC_OK); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.SANITY, + description ="Verify that user with contributor role can create file in site") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY}) + public void siteContributorShouldCreateFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSPOWERPOINT, content); + UserModel contributor = dataUser.createRandomTestUser(); + dataUser.usingUser(managerUser).addUserToSite(contributor, testSite, UserRole.SiteContributor); + webDavProtocol.authenticateUser(contributor).usingSite(testSite) + .createFile(testFile).assertThat().hasStatus(HttpStatus.SC_CREATED) + .and().assertThat().existsInRepo() + .and().assertThat().existsInWebdav().and().assertThat().hasStatus(HttpStatus.SC_OK); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.SANITY, + description ="Verify that user with collaborator role can create file in site") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY}) + public void siteCollaboratorShouldCreateFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD, content); + UserModel collaborator = dataUser.createRandomTestUser(); + dataUser.usingUser(managerUser).addUserToSite(collaborator, testSite, UserRole.SiteCollaborator); + webDavProtocol.authenticateUser(collaborator).usingSite(testSite) + .createFile(testFile).assertThat().hasStatus(HttpStatus.SC_CREATED) + .and().assertThat().existsInRepo() + .and().assertThat().existsInWebdav().and().assertThat().hasStatus(HttpStatus.SC_OK); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.SANITY, + description ="Verify that user with consumer role cannot create file in site") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY}) + public void siteConsumerShouldCreateFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + UserModel consumer = dataUser.createRandomTestUser(); + dataUser.usingUser(managerUser).addUserToSite(consumer, testSite, UserRole.SiteConsumer); + webDavProtocol.authenticateUser(consumer).usingSite(testSite) + .createFile(testFile).assertThat().hasStatus(HttpStatus.SC_FORBIDDEN) + .and().assertThat().doesNotExistInRepo() + .and().assertThat().doesNotExistInWebdav() + .and().assertThat().hasStatus(HttpStatus.SC_NOT_FOUND); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that user with manager role can create file with spaces in name") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE}) + public void siteManageShouldCreateFileWithSpacesInName() throws Exception + { + testFile = new FileModel("test file " + RandomData.getRandomFile(FileType.PDF)); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).assertThat().hasStatus(HttpStatus.SC_CREATED) + .and().assertThat().existsInRepo() + .and().assertThat().existsInWebdav().assertThat().hasStatus(HttpStatus.SC_OK); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that site manager cannot create file in site with symbols in name") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE, TestGroup.OS_LINUX}, expectedExceptions=IllegalArgumentException.class) + public void siteManagerShouldCreateFileWithSymbolsInName() throws Exception + { + testFile = new FileModel("<>.|?#()[]{}.txt", FileType.MSWORD2007, content); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite).createFile(testFile); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that user with manager role can create file with no content") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE}) + public void siteManageShouldCreateFileWithNoContent() throws Exception + { + FileModel noContentFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(noContentFile).assertThat().hasStatus(HttpStatus.SC_CREATED) + .and().assertThat().existsInRepo() + .and().assertThat().existsInWebdav() + .and().assertThat().contentIs(""); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that inexistent user cannot create file") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE}) + public void inexistentUserShouldNotCreateFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + webDavProtocol.authenticateUser(UserModel.getRandomUserModel()).usingResource(FolderModel.getSharedFolderModel()) + .createFile(testFile).assertThat().hasStatus(HttpStatus.SC_UNAUTHORIZED) + .then().usingAdmin().assertThat().doesNotExistInRepo() + .and().assertThat().doesNotExistInWebdav(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that unauthorized user cannot create file") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE}) + public void unauthorizedUserShouldNotCreateFile() throws Exception + { + UserModel unauthorized = dataUser.createRandomTestUser(); + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + webDavProtocol.authenticateUser(unauthorized).usingRoot() + .createFile(testFile).assertThat().hasStatus(HttpStatus.SC_FORBIDDEN) + .then().assertThat().doesNotExistInRepo() + .and().assertThat().doesNotExistInWebdav(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that site manager can create file in site") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE}) + public void siteManagerShouldNotCreateFileTwice() throws Exception + { + SiteModel twiceSite = dataSite.usingUser(managerUser).createPublicRandomSite(); + testFile = FileModel.getRandomFileModel(FileType.MSEXCEL, content); + webDavProtocol.authenticateUser(managerUser).usingSite(twiceSite) + .createFile(testFile).and().assertThat().hasStatus(HttpStatus.SC_CREATED) + .createFile(testFile).assertThat().hasStatus(HttpStatus.SC_NO_CONTENT); + Assert.assertTrue(webDavProtocol.usingSite(twiceSite).getFiles().size() == 1); + } + +// @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, +// description ="Verify user cannot create file with a size bigger than the quota limit") +// @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.FULL}) +// public void userCannotCreateFileGreaterThanQuotaLimit() throws Exception +// { +// if (!webDavProtocol.withJMX().getSystemUsagesConfigurationStatus()) +// throw new SkipException("Skipping this test because user quotas are not enabled. Please add " + +// "system.usages.enabled=true to alfresco-global.properties, restart Alfresco and run the test again."); +// +// UserModel quotaUser = dataUser.createRandomTestUser(); +// dataUser.addUserToSite(quotaUser, testSite, UserRole.SiteCollaborator); +// dataUser.usingAdmin().setUserQuota(quotaUser, 1); +// FileModel quotaFile = FileModel.getFileModelWithContentSizeOfxMB(2); +// +// webDavProtocol.authenticateUser(quotaUser).usingSite(testSite).createFile(quotaFile) +// .then() +// .assertThat().doesNotExistInWebdav() +// .assertThat().doesNotExistInRepo(); +// } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify user can create file with a size smaller than the quota limit") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.FULL}) + public void userCanCreateFileSmallerThanQuotaLimit() throws Exception + { +// if (!webDavProtocol.withJMX().getSystemUsagesConfigurationStatus()) +// throw new SkipException("Skipping this test because user quotas are not enabled. Please add " + +// "system.usages.enabled=true to alfresco-global.properties, restart Alfresco and run the test again."); + + UserModel quotaUser = dataUser.createRandomTestUser(); + dataUser.addUserToSite(quotaUser, testSite, UserRole.SiteCollaborator); + dataUser.usingAdmin().setUserQuota(quotaUser, 5); + FileModel quotaFile = FileModel.getFileModelWithContentSizeOfxMB(1); + + webDavProtocol.authenticateUser(quotaUser).usingSite(testSite).createFile(quotaFile) + .then() + .assertThat().existsInWebdav() + .assertThat().existsInRepo(); + } +} diff --git a/tests/tas-webdav/src/test/java/org/alfresco/webdav/CreateFolderTests.java b/tests/tas-webdav/src/test/java/org/alfresco/webdav/CreateFolderTests.java new file mode 100644 index 0000000000..89cdf608b8 --- /dev/null +++ b/tests/tas-webdav/src/test/java/org/alfresco/webdav/CreateFolderTests.java @@ -0,0 +1,148 @@ +package org.alfresco.webdav; + +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.RandomData; +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.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.commons.httpclient.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class CreateFolderTests extends WebDavTest +{ + UserModel managerUser; + SiteModel testSite; + FolderModel testFolder; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + managerUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(managerUser).createPublicRandomSite(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.SANITY, description ="Verify that admin user can create folder") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + public void adminShouldCreateFolder() throws Exception + { + FolderModel guest = FolderModel.getGuestHomeFolderModel(); + testFolder = FolderModel.getRandomFolderModel(); + webDavProtocol.authenticateUser(dataUser.getAdminUser()).usingResource(guest) + .createFolder(testFolder).and().assertThat().hasStatus(HttpStatus.SC_CREATED) + .then().assertThat().existsInRepo() + .and().assertThat().existsInWebdav().and().assertThat().hasStatus(HttpStatus.SC_OK); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.SANITY, description ="Verify that site manager can create folder") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + public void siteManagerShouldCreateFolder() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFolder(testFolder).and().assertThat().hasStatus(HttpStatus.SC_CREATED) + .then().assertThat().existsInRepo() + .and().assertThat().existsInWebdav().and().assertThat().hasStatus(HttpStatus.SC_OK); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.SANITY, description ="Verify that user with contributor role can create folder") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + public void siteContributorShouldCreateFolder() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + UserModel contributor = dataUser.createRandomTestUser(); + dataUser.usingUser(managerUser).addUserToSite(contributor, testSite, UserRole.SiteContributor); + webDavProtocol.authenticateUser(contributor).usingSite(testSite) + .createFolder(testFolder).assertThat().hasStatus(HttpStatus.SC_CREATED) + .then().assertThat().existsInRepo() + .and().assertThat().existsInWebdav().and().assertThat().hasStatus(HttpStatus.SC_OK); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.SANITY, description ="Verify that user with collaborator role can create folder") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + public void siteCollaboraShouldCreateFolder() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + UserModel collaborator = dataUser.createRandomTestUser(); + dataUser.usingUser(managerUser).addUserToSite(collaborator, testSite, UserRole.SiteCollaborator); + webDavProtocol.authenticateUser(collaborator).usingSite(testSite) + .createFolder(testFolder).assertThat().hasStatus(HttpStatus.SC_CREATED) + .then().assertThat().existsInRepo() + .and().assertThat().existsInWebdav().and().assertThat().hasStatus(HttpStatus.SC_OK); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.SANITY, description ="Verify that user with consumer role cannot create folder") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + public void siteConsumerShouldCreateFolder() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + UserModel consumer = dataUser.createRandomTestUser(); + dataUser.usingUser(managerUser).addUserToSite(consumer, testSite, UserRole.SiteConsumer); + webDavProtocol.authenticateUser(consumer).usingSite(testSite) + .createFolder(testFolder).assertThat().hasStatus(HttpStatus.SC_FORBIDDEN) + .then().assertThat().doesNotExistInRepo() + .and().assertThat().doesNotExistInWebdav().and().assertThat().hasStatus(HttpStatus.SC_NOT_FOUND); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.SANITY, + description ="Verify that user with manager role can create folder with spaces in name") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + public void siteManageShouldCreateFolderWithSpacesInName() throws Exception + { + testFolder = new FolderModel("test folder " + RandomData.getRandomFolder()); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFolder(testFolder).assertThat().hasStatus(HttpStatus.SC_CREATED) + .then().assertThat().existsInRepo() + .and().assertThat().existsInWebdav().and().assertThat().hasStatus(HttpStatus.SC_OK); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that user with manager role cannot create folder with special characters in name") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }, expectedExceptions=IllegalArgumentException.class) + public void siteManageShouldNotCreateFolderWithSpecialChars() throws Exception + { + testFolder = new FolderModel("<>.|?#()[]{}"); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFolder(testFolder); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that site manager cannot create folder twice in the same location") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + public void siteManagerShouldNotCreateFolderTwice() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFolder(testFolder).and().assertThat().hasStatus(HttpStatus.SC_CREATED) + .then().assertThat().existsInRepo() + .when().createFolder(testFolder) + .assertThat().hasStatus(HttpStatus.SC_METHOD_NOT_ALLOWED); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, description ="Verify that inexistent user cannot create folder") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + public void inexistentUserShouldNotCreateFolder() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + webDavProtocol.authenticateUser(UserModel.getRandomUserModel()).usingResource(FolderModel.getSharedFolderModel()) + .createFolder(testFolder).and().assertThat().hasStatus(HttpStatus.SC_UNAUTHORIZED) + .then().usingAdmin() + .assertThat().doesNotExistInRepo() + .and().assertThat().doesNotExistInWebdav(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, description ="Verify that unauthorized user cannot create folder") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + public void unauthorizedUserShouldNotCreateFolder() throws Exception + { + UserModel unauthorized = dataUser.createRandomTestUser(); + testFolder = FolderModel.getRandomFolderModel(); + webDavProtocol.authenticateUser(unauthorized).usingRoot() + .createFolder(testFolder).and().assertThat().hasStatus(HttpStatus.SC_FORBIDDEN) + .then().assertThat().doesNotExistInRepo() + .assertThat().doesNotExistInWebdav(); + } +} diff --git a/tests/tas-webdav/src/test/java/org/alfresco/webdav/DeleteFileTests.java b/tests/tas-webdav/src/test/java/org/alfresco/webdav/DeleteFileTests.java new file mode 100644 index 0000000000..fb2d204678 --- /dev/null +++ b/tests/tas-webdav/src/test/java/org/alfresco/webdav/DeleteFileTests.java @@ -0,0 +1,180 @@ +package org.alfresco.webdav; + +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +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.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.commons.httpclient.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class DeleteFileTests extends WebDavTest +{ + UserModel managerUser; + SiteModel testSite; + FileModel testFile; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + managerUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(managerUser).createPublicRandomSite(); + } + + @TestRail(section={ TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType= ExecutionType.SANITY, + description ="Verify that admin user can delete content from repository") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + public void adminShouldDeleteContent() throws Exception + { + FolderModel guest = FolderModel.getGuestHomeFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.HTML); + webDavProtocol.authenticateUser(dataUser.getAdminUser()) + .usingResource(guest) + .createFile(testFile) + .then().delete().and().assertThat().hasStatus(HttpStatus.SC_OK) + .and().assertThat().doesNotExistInRepo() + .assertThat().doesNotExistInWebdav().and().assertThat().hasStatus(HttpStatus.SC_NOT_FOUND); + } + + @TestRail(section={ TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType= ExecutionType.SANITY, + description ="Verify that site manager can delete content from site") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + public void siteManagerShouldDeleteContent() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.HTML); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile) + .then().delete().assertThat().hasStatus(HttpStatus.SC_OK) + .and().assertThat().doesNotExistInRepo() + .and().assertThat().doesNotExistInWebdav().and().assertThat().hasStatus(HttpStatus.SC_NOT_FOUND); + } + + @TestRail(section={ TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType= ExecutionType.SANITY, + description ="Verify that site collaborator cannot delete content from site") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + public void siteCollaboratorShouldNotDeleteContent() throws Exception + { + UserModel collaborator = dataUser.createRandomTestUser(); + dataUser.usingUser(managerUser).addUserToSite(collaborator, testSite, UserRole.SiteCollaborator); + testFile = FileModel.getRandomFileModel(FileType.HTML); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile) + .then().authenticateUser(collaborator).usingResource(testFile) + .delete().and().assertThat().hasStatus(HttpStatus.SC_FORBIDDEN) + .and().assertThat().existsInRepo() + .and().assertThat().existsInWebdav().assertThat().hasStatus(HttpStatus.SC_OK); + } + + @TestRail(section={ TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType= ExecutionType.SANITY, + description ="Verify that site contributor cannot delete content from site") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + public void siteContributorShouldNotDeleteContent() throws Exception + { + UserModel contributor = dataUser.createRandomTestUser(); + dataUser.usingUser(managerUser).addUserToSite(contributor, testSite, UserRole.SiteContributor); + testFile = FileModel.getRandomFileModel(FileType.HTML); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile) + .then().authenticateUser(contributor).usingResource(testFile) + .delete().and().assertThat().hasStatus(HttpStatus.SC_FORBIDDEN) + .and().assertThat().existsInRepo() + .and().assertThat().existsInWebdav().assertThat().hasStatus(HttpStatus.SC_OK); + } + + @TestRail(section={ TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType= ExecutionType.SANITY, + description ="Verify that site consumer cannot delete content from site") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + public void siteConsumerShouldNotDeleteContent() throws Exception + { + UserModel consumer = dataUser.createRandomTestUser(); + dataUser.usingUser(managerUser).addUserToSite(consumer, testSite, UserRole.SiteConsumer); + testFile = FileModel.getRandomFileModel(FileType.HTML); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile) + .then().authenticateUser(consumer).usingResource(testFile) + .delete().and().assertThat().hasStatus(HttpStatus.SC_FORBIDDEN) + .and().assertThat().existsInRepo() + .and().assertThat().existsInWebdav().assertThat().hasStatus(HttpStatus.SC_OK); + } + + @TestRail(section={ TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType= ExecutionType.SANITY, + description ="Verify that site manager cannot delete a file twice from site") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + public void siteManagerShouldNotDeleteAFileTwice() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.XML); + webDavProtocol.authenticateUser(managerUser) + .usingSite(testSite).createFile(testFile).delete().and().assertThat().doesNotExistInRepo() + .when().delete().assertThat().hasStatus(HttpStatus.SC_NOT_FOUND); + } + + @TestRail(section={ TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType= ExecutionType.SANITY, + description ="Verify that site manager cannot delete inexistent file") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + public void siteManagerShouldNotDeleteInexistentContent() throws Exception + { + webDavProtocol.authenticateUser(managerUser) + .usingResource(FileModel.getRandomFileModel(FileType.MSEXCEL)) + .delete().assertThat().hasStatus(HttpStatus.SC_NOT_FOUND); + } + + @TestRail(section={ TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType= ExecutionType.REGRESSION, + description ="Verify that a disconected user cannot delete file from site") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + public void disconectedUserShouldNotDeleteContent() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.HTML); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).and().disconnect() + .then().delete().assertThat().hasStatus(HttpStatus.SC_UNAUTHORIZED) + .then().authenticateUser(managerUser).usingResource(testFile) + .assertThat().existsInRepo().and().assertThat().existsInWebdav(); + } + + @TestRail(section={ TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType= ExecutionType.REGRESSION, + description ="Verify that a unauthorized user cannot delete file from site") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + public void unauthorizedUserShouldNotDeleteContent() throws Exception + { + UserModel unauthorized = dataUser.createRandomTestUser(); + testFile = FileModel.getRandomFileModel(FileType.HTML); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo() + .then().authenticateUser(unauthorized) + .and().delete().assertThat().hasStatus(HttpStatus.SC_FORBIDDEN) + .assertThat().existsInRepo().and().assertThat().existsInWebdav(); + } + + @TestRail(section={ TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType= ExecutionType.REGRESSION, + description ="Verify that a inexistent user cannot delete file") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + public void inexistentUserShouldNotDeleteContent() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.HTML); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo() + .then().authenticateUser(UserModel.getRandomUserModel()) + .and().delete().assertThat().hasStatus(HttpStatus.SC_UNAUTHORIZED) + .then().authenticateUser(managerUser) + .assertThat().existsInRepo().and().assertThat().existsInWebdav(); + } + + @TestRail(section={ TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType= ExecutionType.REGRESSION, + description ="Verify that site manager cannot delete locked file") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + public void siteManagerCannotNotDeleteLockedFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.HTML); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).assertThat().existsInRepo() + .then().lock().assertThat().isLocked() + .then().delete().assertThat().hasStatus(HttpStatus.SC_LOCKED) + .and().assertThat().existsInRepo() + .and().assertThat().existsInWebdav(); + } +} diff --git a/tests/tas-webdav/src/test/java/org/alfresco/webdav/DeleteFolderTests.java b/tests/tas-webdav/src/test/java/org/alfresco/webdav/DeleteFolderTests.java new file mode 100644 index 0000000000..58e67dba4e --- /dev/null +++ b/tests/tas-webdav/src/test/java/org/alfresco/webdav/DeleteFolderTests.java @@ -0,0 +1,185 @@ +package org.alfresco.webdav; + +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +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.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.commons.httpclient.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class DeleteFolderTests extends WebDavTest +{ + UserModel managerUser; + SiteModel testSite; + FolderModel testFolder; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + managerUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(managerUser).createPublicRandomSite(); + } + + @TestRail(section={ TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType= ExecutionType.SANITY, + description ="Verify that admin user can delete folder from repository") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + public void adminShouldDeleteFolder() throws Exception + { + FolderModel guest = FolderModel.getGuestHomeFolderModel(); + testFolder = FolderModel.getRandomFolderModel(); + webDavProtocol.authenticateUser(dataUser.getAdminUser()) + .usingResource(guest).createFolder(testFolder) + .then().delete().and().assertThat().hasStatus(HttpStatus.SC_OK) + .and().assertThat().doesNotExistInRepo() + .assertThat().doesNotExistInWebdav().and().assertThat().hasStatus(HttpStatus.SC_NOT_FOUND); + } + + @TestRail(section={ TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType= ExecutionType.SANITY, + description ="Verify that site manager can delete folder from site") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + public void siteManagerShouldDeleteFolder() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFolder(testFolder) + .then().delete().assertThat().hasStatus(HttpStatus.SC_OK) + .and().assertThat().doesNotExistInRepo() + .and().assertThat().doesNotExistInWebdav().and().assertThat().hasStatus(HttpStatus.SC_NOT_FOUND); + } + + @TestRail(section={ TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType= ExecutionType.SANITY, + description ="Verify that site collaborator cannot delete folder from site") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + public void siteCollaboratorShouldNotDeleteFolder() throws Exception + { + UserModel collaborator = dataUser.createRandomTestUser(); + dataUser.usingUser(managerUser).addUserToSite(collaborator, testSite, UserRole.SiteCollaborator); + testFolder = FolderModel.getRandomFolderModel(); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFolder(testFolder) + .then().authenticateUser(collaborator).usingResource(testFolder) + .delete().and().assertThat().hasStatus(HttpStatus.SC_FORBIDDEN) + .and().assertThat().existsInRepo() + .and().assertThat().existsInWebdav().assertThat().hasStatus(HttpStatus.SC_OK); + } + + @TestRail(section={ TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType= ExecutionType.SANITY, + description ="Verify that site contributor cannot delete folder from site") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + public void siteContributorShouldNotDeleteFolder() throws Exception + { + UserModel contributor = dataUser.createRandomTestUser(); + dataUser.usingUser(managerUser).addUserToSite(contributor, testSite, UserRole.SiteContributor); + testFolder = FolderModel.getRandomFolderModel(); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFolder(testFolder) + .then().authenticateUser(contributor).usingResource(testFolder) + .delete().and().assertThat().hasStatus(HttpStatus.SC_FORBIDDEN) + .and().assertThat().existsInRepo() + .and().assertThat().existsInWebdav().assertThat().hasStatus(HttpStatus.SC_OK); + } + + @TestRail(section={ TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType= ExecutionType.SANITY, + description ="Verify that site consumer cannot delete folder from site") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + public void siteConsumerShouldNotDeleteFolder() throws Exception + { + UserModel consumer = dataUser.createRandomTestUser(); + dataUser.usingUser(managerUser).addUserToSite(consumer, testSite, UserRole.SiteConsumer); + testFolder = FolderModel.getRandomFolderModel(); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFolder(testFolder) + .then().authenticateUser(consumer).usingResource(testFolder) + .delete().and().assertThat().hasStatus(HttpStatus.SC_FORBIDDEN) + .and().assertThat().existsInRepo() + .and().assertThat().existsInWebdav().assertThat().hasStatus(HttpStatus.SC_OK); + } + + @TestRail(section={ TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType= ExecutionType.SANITY, + description ="Verify that site manager cannot delete a folder twice from site") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + public void siteManagerShouldNotDeleteAFolderTwice() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + webDavProtocol.authenticateUser(managerUser) + .usingSite(testSite).createFolder(testFolder).delete().and().assertThat().doesNotExistInRepo() + .when().delete().assertThat().hasStatus(HttpStatus.SC_NOT_FOUND); + } + + @TestRail(section={ TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType= ExecutionType.SANITY, + description ="Verify that site manager cannot delete inexistent folder") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + public void siteManagerShouldNotDeleteInexistentFolder() throws Exception + { + webDavProtocol.authenticateUser(managerUser) + .usingResource(FolderModel.getRandomFolderModel()) + .delete().assertThat().hasStatus(HttpStatus.SC_NOT_FOUND); + } + + @TestRail(section={ TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType= ExecutionType.REGRESSION, + description ="Verify that a disconected user cannot delete folder from site") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + public void disconectedUserShouldNotDeleteFolder() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFolder(testFolder).and().disconnect() + .then().delete().assertThat().hasStatus(HttpStatus.SC_UNAUTHORIZED) + .then().authenticateUser(managerUser).usingResource(testFolder) + .assertThat().existsInRepo().and().assertThat().existsInWebdav(); + } + + @TestRail(section={ TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType= ExecutionType.REGRESSION, + description ="Verify that a unauthorized user cannot delete folder from site") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + public void unauthorizedUserShouldNotDeleteFolder() throws Exception + { + UserModel unauthorized = dataUser.createRandomTestUser(); + testFolder = FolderModel.getRandomFolderModel(); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFolder(testFolder).and().assertThat().existsInRepo() + .then().authenticateUser(unauthorized) + .and().delete().assertThat().hasStatus(HttpStatus.SC_FORBIDDEN) + .assertThat().existsInRepo().and().assertThat().existsInWebdav(); + } + + @TestRail(section={ TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType= ExecutionType.REGRESSION, + description ="Verify that a inexistent user cannot delete folder") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + public void inexistentUserShouldNotDeleteFolder() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFolder(testFolder).and().assertThat().existsInRepo() + .then().authenticateUser(UserModel.getRandomUserModel()) + .and().delete().assertThat().hasStatus(HttpStatus.SC_UNAUTHORIZED) + .then().authenticateUser(managerUser) + .assertThat().existsInRepo().and().assertThat().existsInWebdav(); + } + + @TestRail(section={ TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType= ExecutionType.REGRESSION, + description ="Verify that site manager can delete folder with children") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + public void siteManagerShouldDeleteFolderWithChildren() throws Exception + { + FileModel subFile = FileModel.getRandomFileModel(FileType.MSWORD2007); + FolderModel subFolder = FolderModel.getRandomFolderModel(); + testFolder = FolderModel.getRandomFolderModel(); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFolder(testFolder) + .usingResource(testFolder) + .createFile(subFile) + .createFolder(subFolder) + .usingResource(testFolder).delete().assertThat().hasStatus(HttpStatus.SC_OK) + .and().assertThat().doesNotExistInRepo() + .and().assertThat().doesNotExistInWebdav().and().assertThat().hasStatus(HttpStatus.SC_NOT_FOUND) + .usingResource(subFile).assertThat().doesNotExistInRepo() + .usingResource(subFolder).assertThat().doesNotExistInRepo(); + } +} diff --git a/tests/tas-webdav/src/test/java/org/alfresco/webdav/DownloadTests.java b/tests/tas-webdav/src/test/java/org/alfresco/webdav/DownloadTests.java new file mode 100644 index 0000000000..03b768c37a --- /dev/null +++ b/tests/tas-webdav/src/test/java/org/alfresco/webdav/DownloadTests.java @@ -0,0 +1,28 @@ +package org.alfresco.webdav; + +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +import org.alfresco.utility.model.FolderModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.commons.httpclient.HttpStatus; +import org.testng.annotations.Test; + + +public class DownloadTests extends WebDavTest +{ + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.SANITY, + description ="Verify that admin user can download a file") + public void adminShouldDownloadFile() throws Exception + { + FolderModel guestHomeFolder = FolderModel.getGuestHomeFolderModel(); + FileModel testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + webDavProtocol.authenticateUser(dataUser.getAdminUser()).usingResource(guestHomeFolder) + .createFile(testFile).and().assertThat().hasStatus(HttpStatus.SC_CREATED) + .and().assertThat().existsInWebdav() + .then().download() + .and().assertThat().isDownloaded(); + } +} diff --git a/tests/tas-webdav/src/test/java/org/alfresco/webdav/GetContentsFromParentFolderTests.java b/tests/tas-webdav/src/test/java/org/alfresco/webdav/GetContentsFromParentFolderTests.java new file mode 100644 index 0000000000..a085b7d01a --- /dev/null +++ b/tests/tas-webdav/src/test/java/org/alfresco/webdav/GetContentsFromParentFolderTests.java @@ -0,0 +1,60 @@ +package org.alfresco.webdav; + +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +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.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + + +public class GetContentsFromParentFolderTests extends WebDavTest +{ + UserModel managerUser; + SiteModel testSite; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + managerUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(managerUser).createPublicRandomSite(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.SANITY, + description ="Verify that site manager can get contents from parent folder") + public void siteManagerShouldGetContentsFromParent() throws Exception + { + FolderModel parentFolder = FolderModel.getRandomFolderModel(); + FolderModel subFolder1 = FolderModel.getRandomFolderModel(); + FolderModel subFolder2 = FolderModel.getRandomFolderModel(); + FolderModel subFolder3 = FolderModel.getRandomFolderModel(); + FileModel subFile1 = FileModel.getRandomFileModel(FileType.HTML); + FileModel subFile2 = FileModel.getRandomFileModel(FileType.MSEXCEL); + FileModel subFile3 = FileModel.getRandomFileModel(FileType.MSWORD); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFolder(parentFolder) + .then().usingResource(parentFolder) + .createFolder(subFolder1) + .createFolder(subFolder2) + .createFile(subFile1) + .createFile(subFile2) + .then().usingResource(subFolder1) + .createFolder(subFolder3) + .createFile(subFile3) + .when().usingResource(parentFolder) + .assertThat().hasChildren(subFolder1, subFolder2, subFile1, subFile2) + .and().assertThat().hasFolders(subFolder1, subFolder2) + .assertThat().hasFiles(subFile1, subFile2) + .then().usingResource(subFolder1) + .assertThat().hasChildren(subFolder3, subFile3) + .and().assertThat().hasFolders(subFolder3) + .assertThat().hasFiles(subFile3) + .then().usingSite(testSite) + .assertThat().hasChildren(parentFolder); + } +} diff --git a/tests/tas-webdav/src/test/java/org/alfresco/webdav/LockFileTests.java b/tests/tas-webdav/src/test/java/org/alfresco/webdav/LockFileTests.java new file mode 100644 index 0000000000..03e028e2b0 --- /dev/null +++ b/tests/tas-webdav/src/test/java/org/alfresco/webdav/LockFileTests.java @@ -0,0 +1,219 @@ +package org.alfresco.webdav; + +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +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.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class LockFileTests extends WebDavTest +{ + UserModel managerUser; + SiteModel testSite; + FileModel testFile; + private String content = "webdav file content"; + private ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + managerUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(managerUser).createPublicRandomSite(); + usersWithRoles = dataUser.addUsersWithRolesToSite(testSite, UserRole.SiteCollaborator, UserRole.SiteConsumer,UserRole.SiteContributor); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.SANITY, + description ="Verify that admin user can lock a file created in Guest Home folder") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY}) + public void adminCanLockFile() throws Exception + { + FolderModel guestHomeFolder = FolderModel.getGuestHomeFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + webDavProtocol.authenticateUser(dataUser.getAdminUser()).usingResource(guestHomeFolder) + .createFile(testFile).then().assertThat().existsInRepo() + .then().lock().assertThat().isLocked(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.SANITY, + description ="Verify that site manager user can lock a file") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY}) + public void siteManagerCanLockFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).then().assertThat().existsInRepo() + .then().lock().assertThat().isLocked(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.SANITY, + description ="Verify that site collaborator user can lock a file created by manager") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY}) + public void siteCollaboratorCanLockFileCreatedByManager() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).then().assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .and().lock().assertThat().isLocked(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.SANITY, + description ="Verify that site collaborator user can lock a file created by himself") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY}) + public void siteCollaboratorCanUnlockFileCreatedByHimself() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + webDavProtocol.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingSite(testSite) + .createFile(testFile).then().assertThat().existsInRepo() + .then().lock().assertThat().isLocked(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.SANITY, + description ="Verify that site contributor user cannot lock a file created by manager") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY}) + public void siteContributorCannotLockFileCreatedByManager() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).then().assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .and().lock().assertThat().hasStatus(HttpStatus.FORBIDDEN.value()) + .assertThat().isUnlocked(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.SANITY, + description ="Verify that site contributor user cannot unlock a file created by himself") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY}) + public void siteContributorCanLockFileCreatedByHimself() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + webDavProtocol.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingSite(testSite) + .createFile(testFile).then().assertThat().existsInRepo() + .and().lock().assertThat().isLocked(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.SANITY, + description ="Verify that site consumer user cannot unlock a file created by manager") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY}) + public void siteConsumerCannotLockFileCreatedByManager() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).then().assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .and().lock().assertThat().hasStatus(HttpStatus.FORBIDDEN.value()) + .assertThat().isUnlocked(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that site manager can create inexistent file as locked") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE}) + public void siteManagerCanCreateLockedInexistentFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + webDavProtocol.authenticateUser(managerUser) + .usingSite(testSite) + .usingResource(testFile) + .lock().assertThat().hasStatus(HttpStatus.CREATED.value()) + .and().assertThat().existsInRepo().and().assertThat().existsInWebdav() + .and().assertThat().isLocked(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that site collaborator can create inexistent file as locked") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE}) + public void siteCollaboratorCanCreateLockedInexistentFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + webDavProtocol.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .usingSite(testSite) + .usingResource(testFile) + .lock().assertThat().hasStatus(HttpStatus.CREATED.value()) + .and().assertThat().existsInRepo().and().assertThat().existsInWebdav() + .and().assertThat().isLocked(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that site contributor can create inexistent file as locked") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE}) + public void siteContributorCanCreateLockedInexistentFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + webDavProtocol.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .usingSite(testSite) + .usingResource(testFile) + .lock().assertThat().hasStatus(HttpStatus.CREATED.value()) + .and().assertThat().existsInRepo().and().assertThat().existsInWebdav() + .and().assertThat().isLocked(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that site consumer cannot can create inexistent file as locked") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE}) + public void siteConsumerCannotCreateLockedInexistentFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + webDavProtocol.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .usingSite(testSite) + .usingResource(testFile) + .lock().assertThat().hasStatus(HttpStatus.FORBIDDEN.value()) + .and().assertThat().doesNotExistInRepo().and().assertThat().doesNotExistInWebdav(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that inexistent user cannot lock a file") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE}) + public void inexistentUserCannotLockFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).then().assertThat().existsInRepo() + .then().authenticateUser(UserModel.getRandomUserModel()) + .and().lock().and().assertThat().hasStatus(HttpStatus.UNAUTHORIZED.value()); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that disconected user cannot lock a file") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE}) + public void disconectedUserCannotLockFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).then().assertThat().existsInRepo() + .then().disconnect() + .and().lock().assertThat().hasStatus(HttpStatus.UNAUTHORIZED.value()); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that unauthorized user cannot lock a file") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE}) + public void unauthorizedUserCannotLockFile() throws Exception + { + UserModel unauthorized = dataUser.createRandomTestUser(); + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).then().assertThat().existsInRepo() + .then().authenticateUser(unauthorized) + .and().lock().assertThat().hasStatus(HttpStatus.FORBIDDEN.value()); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that site manager cannot lock a folder") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE}) + public void siteManagerCanLockFolder() throws Exception + { + FolderModel testFolder = FolderModel.getRandomFolderModel(); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFolder(testFolder).then().assertThat().existsInRepo() + .lock().and().assertThat().hasStatus(HttpStatus.OK.value()) + .and().assertThat().isLocked(); + } +} diff --git a/tests/tas-webdav/src/test/java/org/alfresco/webdav/MoveTests.java b/tests/tas-webdav/src/test/java/org/alfresco/webdav/MoveTests.java new file mode 100644 index 0000000000..44a8f29883 --- /dev/null +++ b/tests/tas-webdav/src/test/java/org/alfresco/webdav/MoveTests.java @@ -0,0 +1,225 @@ +package org.alfresco.webdav; + +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.RandomData; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +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.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.commons.httpclient.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class MoveTests extends WebDavTest +{ + UserModel managerUser; + SiteModel testSite; + FolderModel sourceFolder, destinationFolder; + FileModel testFile; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + managerUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(managerUser).createPublicRandomSite(); + destinationFolder = FolderModel.getRandomFolderModel(); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite).createFolder(destinationFolder); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.SANITY, description ="Verify that admin user can move folder") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY}) + public void adminShouldMoveFolder() throws Exception + { + FolderModel guest = FolderModel.getGuestHomeFolderModel(); + sourceFolder = new FolderModel("move " + RandomData.getRandomFolder()); + webDavProtocol.authenticateUser(dataUser.getAdminUser()).usingRoot() + .createFolder(sourceFolder).and().assertThat().existsInRepo() + .then().moveTo(guest).and().assertThat().existsInRepo().and().assertThat().hasStatus(HttpStatus.SC_CREATED) + .when().usingResource(sourceFolder).assertThat().doesNotExistInRepo(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.SANITY, + description ="Verify that site manager can move folder with content in site") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY}) + public void siteManagerShouldMoveFolder() throws Exception + { + sourceFolder = FolderModel.getRandomFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.MSEXCEL); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFolder(sourceFolder) + .then().usingResource(sourceFolder).createFile(testFile).and().assertThat().existsInRepo() + .when().usingResource(sourceFolder).moveTo(destinationFolder).and().assertThat().existsInRepo() + .and().assertThat().hasStatus(HttpStatus.SC_CREATED) + .then().usingResource(sourceFolder).assertThat().doesNotExistInRepo() + .and().usingResource(testFile).assertThat().doesNotExistInRepo(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.SANITY, + description ="Verify that user with contributor role cannot move folder with content in site folder") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY}) + public void siteContributorShouldNotMoveFolder() throws Exception + { + sourceFolder = FolderModel.getRandomFolderModel(); + UserModel contributor = dataUser.createRandomTestUser(); + testFile = FileModel.getRandomFileModel(FileType.MSEXCEL); + dataUser.usingUser(managerUser).addUserToSite(contributor, testSite, UserRole.SiteContributor); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite).createFolder(sourceFolder) + .and().usingResource(sourceFolder).createFile(testFile) + .then().authenticateUser(contributor).usingResource(sourceFolder) + .moveTo(destinationFolder).and().assertThat().doesNotExistInRepo().and().assertThat().hasStatus(HttpStatus.SC_FORBIDDEN) + .when().usingResource(sourceFolder).assertThat().existsInRepo() + .and().usingResource(testFile).assertThat().existsInRepo(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.SANITY, + description ="Verify that user with collaborator role cannot move folder with content in site folder") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY}) + public void siteCollaboratorShouldNotMoveFolder() throws Exception + { + sourceFolder = FolderModel.getRandomFolderModel(); + UserModel collaborator = dataUser.createRandomTestUser(); + testFile = FileModel.getRandomFileModel(FileType.MSEXCEL); + dataUser.usingUser(managerUser).addUserToSite(collaborator, testSite, UserRole.SiteCollaborator); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite).createFolder(sourceFolder) + .and().usingResource(sourceFolder).createFile(testFile) + .then().authenticateUser(collaborator).usingResource(sourceFolder) + .moveTo(destinationFolder).and().assertThat().doesNotExistInRepo().and().assertThat().hasStatus(HttpStatus.SC_FORBIDDEN) + .when().usingResource(sourceFolder).assertThat().existsInRepo() + .and().usingResource(testFile).assertThat().existsInRepo(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.SANITY, + description ="Verify that user with consumer role cannot move folder with content in site folder") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY}) + public void siteConsumerShouldNotMoveFolder() throws Exception + { + sourceFolder = FolderModel.getRandomFolderModel(); + UserModel consumer = dataUser.createRandomTestUser(); + testFile = FileModel.getRandomFileModel(FileType.MSEXCEL); + dataUser.usingUser(managerUser).addUserToSite(consumer, testSite, UserRole.SiteConsumer); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite).createFolder(sourceFolder) + .and().usingResource(sourceFolder).createFile(testFile) + .then().authenticateUser(consumer).usingResource(sourceFolder) + .moveTo(destinationFolder).and().assertThat().doesNotExistInRepo().and().assertThat().hasStatus(HttpStatus.SC_FORBIDDEN) + .when().usingResource(sourceFolder).assertThat().existsInRepo() + .and().usingResource(testFile).assertThat().existsInRepo(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.SANITY, + description ="Verify that site manager can move file from site in repository") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY}) + public void siteManagerShouldMoveFileInRepository() throws Exception + { + FolderModel guest = FolderModel.getSharedFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.MSEXCEL); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile) + .moveTo(guest).assertThat().existsInRepo().and().assertThat().hasStatus(HttpStatus.SC_CREATED) + .then().usingResource(testFile).assertThat().doesNotExistInRepo(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that disconected user cannot move folder") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE}) + public void disconnectedUserShouldNotMoveFolder() throws Exception + { + sourceFolder = FolderModel.getRandomFolderModel(); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFolder(sourceFolder) + .then().disconnect().and() + .moveTo(destinationFolder).and().assertThat().hasStatus(HttpStatus.SC_UNAUTHORIZED) + .then().authenticateUser(managerUser) + .usingResource(sourceFolder).assertThat().existsInRepo().assertThat().existsInWebdav(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that disconected user cannot move file") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE}) + public void disconnectedUserShouldNotMoveFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSEXCEL); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile) + .then().disconnect().and() + .moveTo(destinationFolder).and().assertThat().hasStatus(HttpStatus.SC_UNAUTHORIZED) + .then().authenticateUser(managerUser) + .usingResource(testFile).assertThat().existsInRepo().assertThat().existsInWebdav(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that unauthorized user cannot move file or folder") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE}) + public void unauthorizedUserShouldNotMoveContent() throws Exception + { + UserModel unauthorized = dataUser.createRandomTestUser(); + sourceFolder = FolderModel.getRandomFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.MSEXCEL); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile) + .createFolder(sourceFolder) + .then().authenticateUser(unauthorized) + .usingResource(testFile) + .moveTo(destinationFolder).and().assertThat().hasStatus(HttpStatus.SC_FORBIDDEN) + .usingResource(sourceFolder) + .moveTo(destinationFolder).and().assertThat().hasStatus(HttpStatus.SC_FORBIDDEN) + .usingResource(testFile).assertThat().existsInRepo().assertThat().existsInWebdav() + .usingResource(sourceFolder).assertThat().existsInRepo().assertThat().existsInWebdav(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that inexistent user cannot move file or folder") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE}) + public void inexistentUserShouldNotMoveContent() throws Exception + { + sourceFolder = FolderModel.getRandomFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.MSEXCEL); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile) + .createFolder(sourceFolder) + .then().authenticateUser(UserModel.getRandomUserModel()) + .usingResource(testFile) + .moveTo(destinationFolder).and().assertThat().hasStatus(HttpStatus.SC_UNAUTHORIZED) + .usingResource(sourceFolder) + .moveTo(destinationFolder).and().assertThat().hasStatus(HttpStatus.SC_UNAUTHORIZED) + .authenticateUser(managerUser) + .usingResource(testFile).assertThat().existsInRepo().assertThat().existsInWebdav() + .usingResource(sourceFolder).assertThat().existsInRepo().assertThat().existsInWebdav(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that site manager cannot move locked file") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE}) + public void siteManagerShouldNotMoveLockedFolder() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSEXCEL); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo() + .then().lock().assertThat().isLocked() + .when().usingResource(testFile) + .moveTo(destinationFolder).and().assertThat().doesNotExistInRepo() + .and().assertThat().hasStatus(HttpStatus.SC_LOCKED) + .and().usingResource(testFile).assertThat().existsInRepo() + .assertThat().existsInWebdav().and().assertThat().isLocked(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify the response code for a conflict when a file is moved in a folder that already has a file with the same name") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE}) + public void conflictWhileMovingFile() throws Exception + { + sourceFolder = FolderModel.getRandomFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + FileModel testFileSource = new FileModel(testFile); + FileModel testFileDestination = new FileModel(testFile); + webDavProtocol.authenticateUser(dataUser.getAdminUser()) + .usingSite(testSite).createFolder(sourceFolder).assertThat().existsInRepo() + .then().usingResource(sourceFolder).createFile(testFileSource).assertThat().existsInRepo() + .then().usingResource(destinationFolder).createFile(testFileDestination).assertThat().existsInRepo() + .when().usingResource(testFileSource).doNotOverwriteIfExists() + .moveTo(destinationFolder).and().assertThat().hasStatus(HttpStatus.SC_PRECONDITION_FAILED); + } +} diff --git a/tests/tas-webdav/src/test/java/org/alfresco/webdav/NetworkDriveTests.java b/tests/tas-webdav/src/test/java/org/alfresco/webdav/NetworkDriveTests.java new file mode 100644 index 0000000000..66753fdff6 --- /dev/null +++ b/tests/tas-webdav/src/test/java/org/alfresco/webdav/NetworkDriveTests.java @@ -0,0 +1,332 @@ +package org.alfresco.webdav; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.utility.data.RandomData; +import org.alfresco.utility.model.*; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.commons.lang3.SystemUtils; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.io.FileNotFoundException; +import java.nio.file.FileAlreadyExistsException; + +public class NetworkDriveTests extends WebDavTest +{ + UserModel siteManager; + SiteModel testSite; + FolderModel folderModel; + FileModel fileModel; + String fileContent = "webdav file content"; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + if(SystemUtils.IS_OS_WINDOWS) + webDavProtocol.unmountNetworkDrive(); + + siteManager = dataUser.getAdminUser(); + testSite = dataSite.usingUser(siteManager).createPublicRandomSite(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.FULL, TestGroup.OS_WIN }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.SANITY, + description = "Verify admin can create folder in Alfresco root folder on mapped drive") + public void adminCanCreateFolderInRootOnMappedDrive() throws Exception + { + folderModel = FolderModel.getRandomFolderModel(); + + webDavProtocol.authenticateUser(dataUser.getAdminUser()).usingNetworkDrive().usingRoot().createFolder(folderModel) + .then() + .assertThat().existsInWebdav() + .assertThat().existsInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.FULL, TestGroup.OS_WIN }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.SANITY, + description = "Verify site manager can create folder on mapped drive") + public void siteManagerCanCreateFolderOnMappedDrive() throws Exception + { + folderModel = FolderModel.getRandomFolderModel(); + + webDavProtocol.authenticateUser(siteManager).usingNetworkDrive().usingSite(testSite).createFolder(folderModel) + .then() + .assertThat().existsInWebdav() + .assertThat().existsInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.FULL, TestGroup.OS_WIN }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager can create folder with name that contains spaces on mapped drive") + public void siteManagerCanCreateFolderWithSpacesInNameOnMappedDrive() throws Exception + { + folderModel = new FolderModel("folder with name that contains spaces"); + + webDavProtocol.authenticateUser(siteManager).usingNetworkDrive().usingSite(testSite).createFolder(folderModel) + .then() + .assertThat().existsInWebdav() + .assertThat().existsInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.FULL, TestGroup.OS_WIN }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager can create folder with name that contains special characters on mapped drive") + public void siteManagerCanCreateFolderWithSpecialCharactersInNameOnMappedDrive() throws Exception + { + folderModel = new FolderModel("!$(){}[]_folder"); + + webDavProtocol.authenticateUser(siteManager).usingNetworkDrive().usingSite(testSite).createFolder(folderModel) + .then() + .assertThat().existsInWebdav() + .assertThat().existsInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.FULL, TestGroup.OS_WIN }, expectedExceptions = FileAlreadyExistsException.class) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.REGRESSION, + description = "Verify site manager cannot create folder twice on mapped drive") + public void siteManagerCannotCreateFolderTwiceOnMappedDrive() throws Exception + { + folderModel = FolderModel.getRandomFolderModel(); + + webDavProtocol.authenticateUser(siteManager).usingNetworkDrive().usingSite(testSite).createFolder(folderModel) + .then() + .assertThat().existsInWebdav() + .assertThat().existsInRepo() + .and().usingSite(testSite).createFolder(folderModel); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.FULL, TestGroup.OS_WIN }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.SANITY, + description = "Verify site manager can create folder inside another folder on mapped drive") + public void siteManagerCanCreateFolderInFolderOnMappedDrive() throws Exception + { + FolderModel parentFolder = dataContent.usingUser(siteManager).usingSite(testSite).createFolder(); + folderModel = FolderModel.getRandomFolderModel(); + + webDavProtocol.authenticateUser(siteManager).usingNetworkDrive().usingResource(parentFolder).createFolder(folderModel) + .then() + .assertThat().existsInWebdav() + .assertThat().existsInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.FULL, TestGroup.OS_WIN }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.SANITY, + description = "Verify site manager can create folder with name prefixed by dot on mapped drive") + public void siteManagerCanCreateFolderWithNamePrefixedByDotOnMappedDrive() throws Exception + { + folderModel = new FolderModel("." + RandomData.getRandomName("folder")); + + webDavProtocol.authenticateUser(siteManager).usingNetworkDrive().usingSite(testSite).createFolder(folderModel) + .then() + .assertThat().existsInWebdav() + .assertThat().existsInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.FULL, TestGroup.OS_WIN }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.SANITY, + description = "Verify site manager can create file on mapped drive") + public void siteManagerCanCreateFileOnMappedDrive() throws Exception + { + fileModel = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + + webDavProtocol.authenticateUser(siteManager).usingNetworkDrive().usingSite(testSite).createFile(fileModel) + .then() + .assertThat().existsInWebdav() + .assertThat().existsInRepo() + .assertThat().contentIs(""); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.FULL, TestGroup.OS_WIN }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.SANITY, + description = "Verify site manager can create file with content on mapped drive") + public void siteManagerCanCreateFileWithContentOnMappedDrive() throws Exception + { + fileModel = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, fileContent); + + webDavProtocol.authenticateUser(siteManager).usingNetworkDrive().usingSite(testSite).createFile(fileModel) + .then() + .assertThat().existsInWebdav() + .assertThat().existsInRepo() + .assertThat().contentIs(fileContent); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.FULL, TestGroup.OS_WIN }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.SANITY, + description = "Verify site manager can delete file on mapped drive") + public void siteManagerCanDeleteFileOnMappedDrive() throws Exception + { + fileModel = dataContent.usingUser(siteManager).usingSite(testSite).createContent(FileModel.getRandomFileModel(FileType.TEXT_PLAIN)); + + webDavProtocol.authenticateUser(siteManager).usingNetworkDrive().usingResource(fileModel).delete() + .then() + .assertThat().doesNotExistInWebdav() + .assertThat().doesNotExistInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.FULL, TestGroup.OS_WIN }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.SANITY, + description = "Verify site manager can delete folder on mapped drive") + public void siteManagerCanDeleteFolderOnMappedDrive() throws Exception + { + folderModel = dataContent.usingUser(siteManager).usingSite(testSite).createFolder(); + + webDavProtocol.authenticateUser(siteManager).usingNetworkDrive().usingResource(folderModel).delete() + .then() + .assertThat().doesNotExistInWebdav() + .assertThat().doesNotExistInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.FULL, TestGroup.OS_WIN }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.SANITY, + description = "Verify site manager can rename file on mapped drive") + public void siteManagerCanRenameFileOnMappedDrive() throws Exception + { + fileModel = dataContent.usingUser(siteManager).usingSite(testSite).createContent(FileModel.getRandomFileModel(FileType.TEXT_PLAIN)); + FileModel originalFileModel = new FileModel(fileModel); + + webDavProtocol.authenticateUser(siteManager).usingNetworkDrive().usingResource(fileModel).rename("renamedFile") + .and() + .assertThat().existsInWebdav() + .assertThat().existsInRepo() + .then().usingResource(originalFileModel) + .assertThat().doesNotExistInWebdav() + .assertThat().doesNotExistInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.FULL, TestGroup.OS_WIN }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.SANITY, + description = "Verify site manager can rename folder on mapped drive") + public void siteManagerCanRenameFolderOnMappedDrive() throws Exception + { + folderModel = dataContent.usingUser(siteManager).usingSite(testSite).createFolder(); + FolderModel originalFolderModel = new FolderModel(folderModel); + + webDavProtocol.authenticateUser(siteManager).usingNetworkDrive().usingResource(folderModel).rename("renamedFolder") + .and() + .assertThat().existsInWebdav() + .assertThat().existsInRepo() + .then().usingResource(originalFolderModel) + .assertThat().doesNotExistInWebdav() + .assertThat().doesNotExistInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.FULL, TestGroup.OS_WIN }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.SANITY, + description = "Verify site manager can copy file on mapped drive") + public void siteManagerCanCopyFileOnMappedDrive() throws Exception + { + fileModel = dataContent.usingUser(siteManager).usingSite(testSite).createContent(FileModel.getRandomFileModel(FileType.TEXT_PLAIN)); + FileModel copiedFile = new FileModel("copiedFile.txt"); + copiedFile.setCmisLocation(fileModel.getCmisLocation().replace(fileModel.getName(), copiedFile.getName())); + + webDavProtocol.authenticateUser(siteManager).usingNetworkDrive().usingResource(fileModel).copyTo(copiedFile) + .and() + .assertThat().existsInWebdav() + .assertThat().existsInRepo() + .then().usingResource(fileModel) + .assertThat().existsInWebdav() + .assertThat().existsInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.FULL, TestGroup.OS_WIN }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.SANITY, + description = "Verify site manager can copy folder on mapped drive") + public void siteManagerCanCopyFolderOnMappedDrive() throws Exception + { + folderModel = dataContent.usingUser(siteManager).usingSite(testSite).createFolder(); + fileModel = dataContent.usingUser(siteManager).usingSite(testSite).usingResource(folderModel) + .createContent(FileModel.getRandomFileModel(FileType.TEXT_PLAIN)); + FolderModel copiedFolder = new FolderModel("copiedFolder"); + copiedFolder.setCmisLocation(folderModel.getCmisLocation().replace(folderModel.getName(), copiedFolder.getName())); + + webDavProtocol.authenticateUser(siteManager).usingNetworkDrive().usingSite(testSite).assertThat().hasFolders(folderModel) + .usingResource(folderModel).copyTo(copiedFolder) + .assertThat().existsInWebdav() + .assertThat().existsInRepo() + .assertThat().hasChildren(fileModel) + .assertThat().hasFiles(fileModel) + .then().usingResource(folderModel) + .assertThat().existsInWebdav() + .assertThat().existsInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.FULL, TestGroup.OS_WIN }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.SANITY, + description = "Verify site manager can move file on mapped drive") + public void siteManagerCanMoveFileOnMappedDrive() throws Exception + { + fileModel = dataContent.usingUser(siteManager).usingSite(testSite).createContent(FileModel.getRandomFileModel(FileType.TEXT_PLAIN)); + FileModel movedFile = new FileModel("movedFile"); + movedFile.setCmisLocation(fileModel.getCmisLocation().replace(fileModel.getName(), movedFile.getName())); + + webDavProtocol.authenticateUser(siteManager).usingNetworkDrive().usingResource(fileModel).moveTo(movedFile) + .and() + .assertThat().existsInWebdav() + .assertThat().existsInRepo() + .then().usingResource(fileModel) + .assertThat().doesNotExistInWebdav() + .assertThat().doesNotExistInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.FULL, TestGroup.OS_WIN }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.SANITY, + description = "Verify site manager can move folder on mapped drive") + public void siteManagerCanMoveFolderOnMappedDrive() throws Exception + { + folderModel = dataContent.usingUser(siteManager).usingSite(testSite).createFolder(); + fileModel = dataContent.usingUser(siteManager).usingSite(testSite).usingResource(folderModel) + .createContent(FileModel.getRandomFileModel(FileType.TEXT_PLAIN)); + FolderModel moveFolder = dataContent.usingUser(siteManager).usingSite(testSite).createFolder(); + + webDavProtocol.authenticateUser(siteManager).usingNetworkDrive().usingSite(testSite).assertThat().hasFolders(folderModel) + .usingResource(folderModel).moveTo(moveFolder) + .assertThat().existsInWebdav() + .assertThat().existsInRepo() + .assertThat().hasChildren(fileModel) + .assertThat().hasFiles(fileModel) + .then().usingSite(testSite).usingResource(folderModel) + .assertThat().doesNotExistInWebdav() + .assertThat().doesNotExistInRepo() + .and().usingSite(testSite).usingResource(folderModel).usingResource(fileModel) + .assertThat().doesNotExistInWebdav() + .assertThat().doesNotExistInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.FULL, TestGroup.OS_WIN }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.SANITY, + description = "Verify site manager can update file content on mapped drive") + public void siteManagerCanUpdateFileContentOnMappedDrive() throws Exception + { + fileModel = dataContent.usingUser(siteManager).usingSite(testSite).createContent(FileModel.getRandomFileModel(FileType.TEXT_PLAIN)); + + webDavProtocol.authenticateUser(siteManager).usingNetworkDrive().usingResource(fileModel).assertThat().contentIs("") + .and() + .update("updated content") + .then() + .assertThat().contentIs("updated content"); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.FULL, TestGroup.OS_WIN }, expectedExceptions = FileNotFoundException.class) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.SANITY, + description = "Verify site manager cannot update content for a deleted file on mapped drive") + public void siteManagerCannotUpdateFileContentForADeletedFileOnMappedDrive() throws Exception + { + fileModel = dataContent.usingUser(siteManager).usingSite(testSite).createContent(FileModel.getRandomFileModel(FileType.TEXT_PLAIN)); + + webDavProtocol.authenticateUser(siteManager).usingNetworkDrive().usingResource(fileModel).delete() + .then() + .update("updated content"); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.FULL, TestGroup.OS_WIN }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.SANITY, + description = "Verify that file version is incremented after file is edited on mapped drive") + public void verifyFileVersionIsIncrementedAfterEditOnMappedDrive() throws Exception + { + fileModel = dataContent.usingUser(siteManager).usingSite(testSite).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + + webDavProtocol.authenticateUser(siteManager).usingNetworkDrive().usingResource(fileModel).update("new content"); + dataContent.usingResource(fileModel).assertContentVersionIs("1.1"); + } +} diff --git a/tests/tas-webdav/src/test/java/org/alfresco/webdav/RenameFileTests.java b/tests/tas-webdav/src/test/java/org/alfresco/webdav/RenameFileTests.java new file mode 100644 index 0000000000..f19513bbd2 --- /dev/null +++ b/tests/tas-webdav/src/test/java/org/alfresco/webdav/RenameFileTests.java @@ -0,0 +1,174 @@ +package org.alfresco.webdav; + +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.model.FileModel; +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.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.commons.httpclient.HttpStatus; +import org.apache.commons.lang3.RandomStringUtils; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.alfresco.utility.model.FileType; + +public class RenameFileTests extends WebDavTest +{ + UserModel managerUser; + SiteModel testSite; + FileModel testFile; + private String renamePrefix = "-edit"; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + managerUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(managerUser).createPublicRandomSite(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.SANITY, + description ="Verify that admin user can rename file") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + public void adminShouldRenameFile() throws Exception + { + FolderModel guest = FolderModel.getGuestHomeFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + FileModel originalFileModel = new FileModel(testFile); + webDavProtocol.authenticateUser(dataUser.getAdminUser()).usingResource(guest) + .createFile(testFile).and().assertThat().existsInRepo() + .when().rename(testFile.getName() + renamePrefix).assertThat().existsInRepo() + .and().assertThat().hasStatus(HttpStatus.SC_CREATED) + .then().usingResource(originalFileModel).assertThat().doesNotExistInRepo(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.SANITY, + description ="Verify that site manager can rename file") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + public void siteManagerShouldRenameFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD); + FileModel originalFileModel = new FileModel(testFile); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo() + .when().rename(testFile.getName() + renamePrefix).assertThat().existsInRepo() + .and().assertThat().hasStatus(HttpStatus.SC_CREATED) + .then().usingSite(testSite).usingResource(originalFileModel).assertThat().doesNotExistInRepo(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.SANITY, + description ="Verify that user with contributor role cannot rename file") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + public void siteContributorShouldNotRenameFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSPOWERPOINT); + FileModel originalFileModel = new FileModel(testFile); + UserModel contributor = dataUser.createRandomTestUser(); + dataUser.usingUser(managerUser).addUserToSite(contributor, testSite, UserRole.SiteContributor); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo() + .when().authenticateUser(contributor).usingResource(testFile) + .rename(testFile.getName() + renamePrefix).assertThat().doesNotExistInRepo() + .and().assertThat().hasStatus(HttpStatus.SC_FORBIDDEN) + .then().usingSite(testSite).usingResource(originalFileModel).assertThat().existsInRepo(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that user with collaborator role can rename file") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + public void siteCollaboratorShouldRenameFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSEXCEL); + FileModel originalFileModel = new FileModel(testFile); + UserModel collaborator = dataUser.createRandomTestUser(); + dataUser.usingUser(managerUser).addUserToSite(collaborator, testSite, UserRole.SiteCollaborator); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo() + .when().authenticateUser(collaborator).usingResource(testFile) + .rename(testFile.getName() + renamePrefix).assertThat().existsInRepo() + .and().assertThat().hasStatus(HttpStatus.SC_CREATED) + .then().usingSite(testSite).usingResource(originalFileModel).assertThat().doesNotExistInRepo(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that user with consumer role cannot rename file") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + public void siteConsumerShouldNotRenameFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.PDF); + FileModel originalFileModel = new FileModel(testFile); + UserModel consumer = dataUser.createRandomTestUser(); + dataUser.usingUser(managerUser).addUserToSite(consumer, testSite, UserRole.SiteConsumer); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo() + .when().authenticateUser(consumer).usingResource(testFile) + .rename(testFile.getName() + renamePrefix).assertThat().doesNotExistInRepo() + .and().assertThat().hasStatus(HttpStatus.SC_FORBIDDEN) + .then().usingSite(testSite).usingResource(originalFileModel).assertThat().existsInRepo(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that site manager cannot rename inexistent file") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + public void siteManagerShouldNotRenameInexistentFile() throws Exception + { + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .usingResource(FileModel.getRandomFileModel(FileType.TEXT_PLAIN)) + .rename("inexistent-edited.txt").assertThat().hasStatus(HttpStatus.SC_NOT_FOUND); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that site manager can rename file with 200 characters") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + public void siteManagerShouldRenameFileWithLongName() throws Exception + { + String longName = RandomStringUtils.randomAlphabetic(200); + testFile = FileModel.getRandomFileModel(FileType.MSWORD); + FileModel originalFileModel = new FileModel(testFile); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo() + .when().rename(longName).assertThat().hasStatus(HttpStatus.SC_CREATED) + .and().assertThat().existsInRepo().and().assertThat().existsInWebdav() + .then().usingSite(testSite).usingResource(originalFileModel).assertThat().doesNotExistInRepo(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that site manager cannot rename locked file") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + public void siteManagerShouldNotRenameLockedFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.MSWORD); + FileModel originalFileModel = new FileModel(testFile); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo() + .then().lock().and().assertThat().isLocked() + .when().rename(testFile.getName() + renamePrefix) + .assertThat().doesNotExistInRepo() + .and().assertThat().hasStatus(HttpStatus.SC_LOCKED) + .then().usingSite(testSite).usingResource(originalFileModel).assertThat().existsInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.FULL }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.REGRESSION, + description = "Verify that non existent user cannot rename a file") + public void nonExistentUserShouldNotRenameFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + FileModel originalFileModel = new FileModel(testFile); + webDavProtocol.authenticateUser(managerUser) + .usingSite(testSite) + .createFile(testFile) + .assertThat().existsInRepo(); + + webDavProtocol.authenticateUser(UserModel.getRandomUserModel()) + .usingResource(testFile) + .rename(testFile.getName() + renamePrefix) + .assertThat().hasStatus(HttpStatus.SC_UNAUTHORIZED); + + webDavProtocol.authenticateUser(managerUser) + .usingSite(testSite) + .usingResource(originalFileModel) + .assertThat().existsInRepo(); + } +} diff --git a/tests/tas-webdav/src/test/java/org/alfresco/webdav/RenameFolderTests.java b/tests/tas-webdav/src/test/java/org/alfresco/webdav/RenameFolderTests.java new file mode 100644 index 0000000000..195c6c081d --- /dev/null +++ b/tests/tas-webdav/src/test/java/org/alfresco/webdav/RenameFolderTests.java @@ -0,0 +1,185 @@ +package org.alfresco.webdav; + +import org.alfresco.utility.constants.UserRole; +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.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.commons.httpclient.HttpStatus; +import org.apache.commons.lang3.RandomStringUtils; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class RenameFolderTests extends WebDavTest +{ + UserModel managerUser; + SiteModel testSite; + FolderModel testFolder; + private String renamePrefix = "-edit"; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + managerUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(managerUser).createPublicRandomSite(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.SANITY, description = "Verify that admin user can rename folder") + public void adminShouldRenameFolder() throws Exception + { + FolderModel guest = FolderModel.getGuestHomeFolderModel(); + testFolder = FolderModel.getRandomFolderModel(); + FolderModel originalFolderModel = new FolderModel(testFolder); + webDavProtocol.authenticateUser(dataUser.getAdminUser()) + .usingResource(guest).createFolder(testFolder).and().assertThat().existsInRepo() + .when().rename(testFolder.getName() + renamePrefix).assertThat().existsInRepo() + .and().assertThat().hasStatus(HttpStatus.SC_CREATED) + .then().usingSite(testSite).usingResource(originalFolderModel).assertThat().doesNotExistInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.SANITY, description = "Verify that site manager can rename folder") + public void siteManagerShouldRenameFolder() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + FolderModel originalFolderModel = new FolderModel(testFolder); + webDavProtocol.authenticateUser(managerUser) + .usingSite(testSite) + .createFolder(testFolder).and().assertThat().existsInRepo() + .when().rename(testFolder.getName() + renamePrefix).assertThat().existsInRepo() + .and().assertThat().hasStatus(HttpStatus.SC_CREATED) + .then().usingSite(testSite).usingResource(originalFolderModel).assertThat().doesNotExistInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.SANITY, description = "Verify that user with contributor role cannot rename folder") + public void siteContributorShouldNotRenameFolder() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + FolderModel originalFolderModel = new FolderModel(testFolder); + UserModel contributor = dataUser.createRandomTestUser(); + dataUser.usingUser(managerUser).addUserToSite(contributor, testSite, UserRole.SiteContributor); + webDavProtocol.authenticateUser(managerUser) + .usingSite(testSite) + .createFolder(testFolder).and().assertThat().existsInRepo() + .when().authenticateUser(contributor).usingResource(testFolder) + .rename(testFolder.getName() + renamePrefix).assertThat().doesNotExistInRepo() + .and().assertThat().hasStatus(HttpStatus.SC_FORBIDDEN) + .then().usingSite(testSite).usingResource(originalFolderModel).assertThat().existsInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.SANITY, description = "Verify that user with collaborator role can rename folder") + public void siteCollaboratorShouldRenameFolder() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + FolderModel originalFolderModel = new FolderModel(testFolder); + UserModel collaborator = dataUser.createRandomTestUser(); + dataUser.usingUser(managerUser).addUserToSite(collaborator, testSite, UserRole.SiteCollaborator); + webDavProtocol.authenticateUser(managerUser) + .usingSite(testSite) + .createFolder(testFolder).and().assertThat().existsInRepo() + .when().authenticateUser(collaborator) + .usingResource(testFolder) + .rename(testFolder.getName() + renamePrefix).assertThat().existsInRepo() + .and().assertThat().hasStatus(HttpStatus.SC_CREATED) + .then().usingSite(testSite).usingResource(originalFolderModel).assertThat().doesNotExistInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.SANITY, + description = "Verify that user with consumer role cannot rename folder") + public void siteConsumerShouldNotRenameFolder() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + FolderModel originalFolderModel = new FolderModel(testFolder); + UserModel consumer = dataUser.createRandomTestUser(); + dataUser.usingUser(managerUser).addUserToSite(consumer, testSite, UserRole.SiteConsumer); + + webDavProtocol.authenticateUser(managerUser) + .usingSite(testSite) + .createFolder(testFolder).and().assertThat().existsInRepo() + .when().authenticateUser(consumer) + .usingResource(testFolder) + .rename(testFolder.getName() + renamePrefix).assertThat().doesNotExistInRepo() + .and().assertThat().hasStatus(HttpStatus.SC_FORBIDDEN) + .then().usingSite(testSite).usingResource(originalFolderModel).assertThat().existsInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.REGRESSION, + description = "Verify that disconected user cannot rename a folder") + public void disconectedUserShouldNotRenameFolder() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + FolderModel originalFolderModel = new FolderModel(testFolder); + webDavProtocol.authenticateUser(managerUser) + .usingSite(testSite) + .createFolder(testFolder).and().assertThat().existsInRepo() + .when().disconnect() + .usingResource(testFolder).rename(testFolder.getName() + renamePrefix).assertThat().doesNotExistInRepo() + .and().assertThat().hasStatus(HttpStatus.SC_UNAUTHORIZED); + + webDavProtocol.authenticateUser(managerUser).usingSite(testSite).usingResource(originalFolderModel).assertThat().existsInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.REGRESSION, + description = "Verify that unauthorized user cannot rename a folder") + public void unauthorizedUserShouldNotRenameFolder() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + FolderModel originalFolderModel = new FolderModel(testFolder); + + webDavProtocol.authenticateUser(dataUser.getAdminUser()) + .usingRoot() + .createFolder(testFolder) + .assertThat().existsInRepo(); + + webDavProtocol.authenticateUser(dataUser.createRandomTestUser()) + .usingResource(testFolder) + .rename(testFolder.getName() + renamePrefix) + .assertThat().doesNotExistInRepo() + .assertThat().hasStatus(HttpStatus.SC_FORBIDDEN); + + webDavProtocol.authenticateUser(dataUser.getAdminUser()).usingRoot() + .usingResource(originalFolderModel).assertThat().existsInRepo(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.REGRESSION, + description = "Verify that inexistent user cannot rename a folder") + public void inexistentUserShouldNotRenameFolder() throws Exception + { + testFolder = FolderModel.getRandomFolderModel(); + FolderModel originalFolderModel = new FolderModel(testFolder); + webDavProtocol.authenticateUser(managerUser) + .usingSite(testSite) + .createFolder(testFolder).and().assertThat().existsInRepo(); + + webDavProtocol.authenticateUser(UserModel.getRandomUserModel()) + .usingResource(testFolder).rename(testFolder.getName() + renamePrefix) + .assertThat().hasStatus(HttpStatus.SC_UNAUTHORIZED); + + webDavProtocol.authenticateUser(managerUser).usingSite(testSite).usingResource(originalFolderModel).assertThat().existsInRepo(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that site manager can rename folder with 200 characters") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + public void siteManagerShouldRenameFolderWithLongName() throws Exception + { + String longName = RandomStringUtils.randomAlphabetic(200); + testFolder = FolderModel.getRandomFolderModel(); + FolderModel originalFolderModel = new FolderModel(testFolder); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFolder(testFolder).and().assertThat().existsInRepo() + .when().rename(longName) + .and().assertThat().hasStatus(HttpStatus.SC_CREATED) + .and().assertThat().existsInRepo().and().assertThat().existsInWebdav() + .then().usingSite(testSite).usingResource(originalFolderModel).assertThat().doesNotExistInRepo(); + } +} diff --git a/tests/tas-webdav/src/test/java/org/alfresco/webdav/RequestResponseTests.java b/tests/tas-webdav/src/test/java/org/alfresco/webdav/RequestResponseTests.java new file mode 100644 index 0000000000..c763fc23d1 --- /dev/null +++ b/tests/tas-webdav/src/test/java/org/alfresco/webdav/RequestResponseTests.java @@ -0,0 +1,33 @@ +package org.alfresco.webdav; + +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +import org.alfresco.utility.model.FolderModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.report.Bug.Status; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.commons.httpclient.HttpStatus; +import org.testng.annotations.Test; + +public class RequestResponseTests extends WebDavTest +{ + @Bug(id = "MNT-17475", status = Status.FIXED) + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.REGRESSION, + description = "Verify that the Content-Disposition response header value contains filename as attachment") + public void contentDispositionResponseHeaderValueIsCorrect() throws Exception + { + FolderModel guestHomeFolder = FolderModel.getGuestHomeFolderModel(); + FileModel testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + + webDavProtocol.authenticateUser(dataUser.getAdminUser()).usingResource(guestHomeFolder).createFile(testFile) + .and().assertThat().hasStatus(HttpStatus.SC_CREATED).and().assertThat().existsInWebdav().then() + .assertThat().hasResponseHeaderValue(WebDavWrapper.RESPONSE_HEADER_CONTENT_TYPE, "text/plain") + .and().assertThat().hasResponseHeaderValue(WebDavWrapper.RESPONSE_HEADER_CONTENT_DISPOSITION, + "attachment; filename=\"" + testFile.getName() + "\"; filename*=UTF-8'"); + + } + +} diff --git a/tests/tas-webdav/src/test/java/org/alfresco/webdav/UnlockFileTests.java b/tests/tas-webdav/src/test/java/org/alfresco/webdav/UnlockFileTests.java new file mode 100644 index 0000000000..c568a783c1 --- /dev/null +++ b/tests/tas-webdav/src/test/java/org/alfresco/webdav/UnlockFileTests.java @@ -0,0 +1,201 @@ +package org.alfresco.webdav; + +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +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.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class UnlockFileTests extends WebDavTest +{ + UserModel managerUser; + SiteModel testSite; + FileModel testFile; + private String content = "webdav file content"; + private ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + managerUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(managerUser).createPublicRandomSite(); + usersWithRoles = dataUser.addUsersWithRolesToSite(testSite, UserRole.SiteCollaborator, UserRole.SiteConsumer,UserRole.SiteContributor); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.SANITY, + description ="Verify that admin user can unlock a file created in Guest Home folder") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY}) + public void adminCanUnlockFile() throws Exception + { + FolderModel guestHomeFolder = FolderModel.getGuestHomeFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + webDavProtocol.authenticateUser(dataUser.getAdminUser()).usingResource(guestHomeFolder) + .createFile(testFile).then().assertThat().existsInRepo() + .then().lock().assertThat().isLocked() + .and().unlock().and().assertThat().isUnlocked(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.SANITY, + description ="Verify that site manager user can unlock a file") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY}) + public void siteManagerCanUnlockFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).then().assertThat().existsInRepo() + .then().lock().assertThat().isLocked() + .and().unlock().assertThat().hasStatus(HttpStatus.NO_CONTENT.value()) + .and().assertThat().isUnlocked(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.SANITY, + description ="Verify that site collaborator user cannot unlock a file locked by manager") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY}) + public void siteCollaboratorCannotUnlockFileLockedByManager() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).then().assertThat().existsInRepo() + .and().lock().assertThat().isLocked() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .and().unlock().and().assertThat().isLocked(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.SANITY, + description ="Verify that site collaborator user can unlock a file locked by himself") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY}) + public void siteCollaboratorCanUnlockFileLockedByHimself() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).then().assertThat().existsInRepo() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .and().lock().assertThat().isLocked() + .and().unlock().and().assertThat().isUnlocked(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.SANITY, + description ="Verify that site contributor user cannot unlock a file locked by manager") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY}) + public void siteContributorCannotUnlockFileLockedByManager() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).then().assertThat().existsInRepo() + .and().lock().assertThat().isLocked() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .unlock().and().assertThat().isLocked(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.SANITY, + description ="Verify that site contributor user cannot unlock a file created by himself") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY}) + public void siteContributorCanUnlockFileCreatedByHimself() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + webDavProtocol.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).usingSite(testSite) + .createFile(testFile).then().assertThat().existsInRepo() + .and().lock().assertThat().isLocked() + .unlock().and().assertThat().hasStatus(HttpStatus.NO_CONTENT.value()).and().assertThat().isUnlocked(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.SANITY, + description ="Verify that site consumer user cannot unlock a file locked by manager") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY}) + public void siteConsumerCannotUnlockFileLockedByManager() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).then().assertThat().existsInRepo() + .and().lock().assertThat().isLocked() + .then().authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .unlock().and().assertThat().isLocked(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that site manager user cannot unlock inexistent file") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE}) + public void siteManagerCannotUnlockInexistentFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + webDavProtocol.authenticateUser(managerUser) + .usingResource(FileModel.getRandomFileModel(FileType.MSEXCEL2007)) + .unlock().assertThat().hasStatus(HttpStatus.BAD_REQUEST.value()); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that inexistent user cannot unlock a file") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE}) + public void inexistentUserCannotUnlockFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).then().assertThat().existsInRepo() + .and().lock().assertThat().isLocked() + .then().authenticateUser(UserModel.getRandomUserModel()) + .unlock().and().assertThat().hasStatus(HttpStatus.UNAUTHORIZED.value()) + .and().authenticateUser(managerUser).assertThat().isLocked(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that disconected user cannot unlock a file") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE}) + public void disconectedUserCannotUnlockFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).then().assertThat().existsInRepo() + .and().lock().assertThat().isLocked() + .then().disconnect() + .unlock().and().assertThat().hasStatus(HttpStatus.UNAUTHORIZED.value()) + .and().authenticateUser(managerUser).assertThat().isLocked(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that unauthorized user cannot unlock a file") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE}) + public void unauthorizedUserCannotUnlockFile() throws Exception + { + UserModel unauthorized = dataUser.createRandomTestUser(); + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).then().assertThat().existsInRepo() + .and().lock().assertThat().isLocked() + .then().authenticateUser(unauthorized) + .unlock().and().assertThat().hasStatus(HttpStatus.PRECONDITION_FAILED.value()) + .and().assertThat().isLocked(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that site manager cannot unlock a file that is not locked") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE}) + public void unlockFileThatIsNotLocked() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).then().assertThat().existsInRepo() + .unlock().and().assertThat().hasStatus(HttpStatus.BAD_REQUEST.value()) + .and().assertThat().isUnlocked(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that site manager cannot unlock a folder") + @Test(groups = {TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE}) + public void siteManagerCanUnlockFolder() throws Exception + { + FolderModel testFolder = FolderModel.getRandomFolderModel(); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFolder(testFolder).then().assertThat().existsInRepo() + .lock().assertThat().isLocked() + .then().unlock() + .and().assertThat().hasStatus(HttpStatus.NO_CONTENT.value()).and().assertThat().isUnlocked(); + } +} diff --git a/tests/tas-webdav/src/test/java/org/alfresco/webdav/UpdateContentTests.java b/tests/tas-webdav/src/test/java/org/alfresco/webdav/UpdateContentTests.java new file mode 100644 index 0000000000..a7b9ef2bca --- /dev/null +++ b/tests/tas-webdav/src/test/java/org/alfresco/webdav/UpdateContentTests.java @@ -0,0 +1,233 @@ +package org.alfresco.webdav; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +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.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.commons.httpclient.HttpStatus; +import org.testng.SkipException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class UpdateContentTests extends WebDavTest +{ + UserModel managerUser, adminUser; + SiteModel testSite; + FileModel testFile, nonExistingFile; + private String content = "content webdav file"; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + managerUser = dataUser.createRandomTestUser(); + testSite = dataSite.usingUser(managerUser).createPublicRandomSite(); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.SANITY, + description = "Verify that admin user can update the content of a file created by self.") + public void adminShouldEditContentFile() throws Exception + { + FolderModel guestHomeFolder = FolderModel.getGuestHomeFolderModel(); + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + + webDavProtocol.authenticateUser(adminUser).usingResource(guestHomeFolder).createFile(testFile).and().assertThat().existsInRepo().then() + .update(content + "-update").and().assertThat().hasStatus(HttpStatus.SC_NO_CONTENT).and().assertThat().contentIs(content + "-update"); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.REGRESSION, + description = "Verify that SiteManager user can update the content of a file created by self.") + public void siteManagerShouldEditContentFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite).createFile(testFile).and().assertThat().existsInRepo().then() + .update(content + "-update " + UserRole.SiteManager).and().assertThat().hasStatus(HttpStatus.SC_NO_CONTENT).and().assertThat() + .contentIs(content + "-update " + UserRole.SiteManager); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.REGRESSION, + description = "Verify that SiteCollaborator user can update the content of a file created by other user.") + public void siteCollaboratorShouldEditContentFileCreatedByOtherUser() throws Exception + { + UserModel collaborator = dataUser.createRandomTestUser(); + dataUser.usingUser(managerUser).addUserToSite(collaborator, testSite, UserRole.SiteCollaborator); + + testFile = FileModel.getRandomFileModel(FileType.HTML, content); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite).createFile(testFile).and().assertThat().existsInRepo().then() + .authenticateUser(collaborator).usingResource(testFile).update(content + "-update " + UserRole.SiteCollaborator).and().assertThat() + .hasStatus(HttpStatus.SC_NO_CONTENT).and().assertThat().contentIs(content + "-update " + UserRole.SiteCollaborator); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.REGRESSION, + description = "Verify that SiteCollaborator user can update the content of a file created by self.") + public void siteCollaboratorShouldEditContentFileCreatedBySelf() throws Exception + { + UserModel collaborator = dataUser.createRandomTestUser(); + dataUser.usingUser(managerUser).addUserToSite(collaborator, testSite, UserRole.SiteCollaborator); + + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + webDavProtocol.authenticateUser(collaborator).usingSite(testSite).createFile(testFile).and().assertThat().existsInRepo().then() + .update(content + "-update " + UserRole.SiteCollaborator).and().assertThat().hasStatus(HttpStatus.SC_NO_CONTENT).and().assertThat() + .contentIs(content + "-update " + UserRole.SiteCollaborator); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.REGRESSION, + description = "Verify that SiteContributor user cannot update inline the content of a file created by other user.") + public void siteContributorShouldNotEditContentFileCreatedByOtherUser() throws Exception + { + UserModel contributor = dataUser.createRandomTestUser(); + dataUser.usingUser(managerUser).addUserToSite(contributor, testSite, UserRole.SiteContributor); + + testFile = FileModel.getRandomFileModel(FileType.MSPOWERPOINT, content); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite).createFile(testFile).and().assertThat().existsInRepo().then() + .authenticateUser(contributor).usingResource(testFile).update(content + "-update").and().assertThat().hasStatus(HttpStatus.SC_FORBIDDEN).and() + .assertThat().contentIs(content); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.REGRESSION, + description = "Verify that SiteContributor user can update the content of a file created by self.") + public void siteContributorShouldEditContentFileCreatedBySelf() throws Exception + { + UserModel contributor = dataUser.createRandomTestUser(); + dataUser.usingUser(managerUser).addUserToSite(contributor, testSite, UserRole.SiteManager); + + testFile = FileModel.getRandomFileModel(FileType.MSEXCEL, content); + webDavProtocol.authenticateUser(contributor).usingSite(testSite).createFile(testFile).and().assertThat().existsInRepo().then() + .update(content + "-update " + UserRole.SiteManager).and().assertThat().hasStatus(HttpStatus.SC_NO_CONTENT).and().assertThat() + .contentIs(content + "-update " + UserRole.SiteManager); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.REGRESSION, + description = "Verify that SiteConsumer user cannot update the content of a file created by other user.") + public void siteConsumerShouldNotEditContentFileCreatedByOtherUser() throws Exception + { + UserModel consumer = dataUser.createRandomTestUser(); + dataUser.usingUser(managerUser).addUserToSite(consumer, testSite, UserRole.SiteConsumer); + + testFile = FileModel.getRandomFileModel(FileType.MSWORD, content); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite).createFile(testFile).and().assertThat().existsInRepo().then() + .authenticateUser(consumer).usingResource(testFile).update(content + "-update " + UserRole.SiteConsumer).and().assertThat() + .hasStatus(HttpStatus.SC_FORBIDDEN).and().assertThat().contentIs(content); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.REGRESSION, + description = "Verify that unauthenticated user cannot update the content of a file.") + public void unauthenticatedUserShouldNotEditContentFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite).createFile(testFile).and().assertThat().existsInRepo().then().disconnect() + .usingResource(testFile).update(content + "-update " + "unauthenticated").and().assertThat().hasStatus(HttpStatus.SC_UNAUTHORIZED); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.REGRESSION, + description = "Verify that inexistent user cannot update the content of a file.") + public void inexistentUserShouldNotEditContentFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo() + .then().authenticateUser(UserModel.getRandomUserModel()) + .update(content + "-update") + .and().assertThat().hasStatus(HttpStatus.SC_UNAUTHORIZED); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.REGRESSION, + description = "Verify that SiteManager user cannot update the content of a folder") + public void siteManagerShouldNotEditFolderContent() throws Exception + { + FolderModel folder = FolderModel.getRandomFolderModel(); + webDavProtocol.authenticateUser(managerUser) + .usingSite(testSite).createFolder(folder).and().assertThat().existsInRepo() + .then().update(content + "-update ").assertThat().hasStatus(HttpStatus.SC_BAD_REQUEST); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.REGRESSION, + description = "Verify that SiteManager user cannot update the content of an inexisting file.") + public void editContentFileForNonExistingFile() throws Exception + { + nonExistingFile = FileModel.getRandomFileModel(FileType.PDF, content); + webDavProtocol.authenticateUser(managerUser).usingSite(testSite) + .createFile(nonExistingFile).delete() + .and().assertThat().doesNotExistInRepo().and().assertThat().doesNotExistInWebdav() + .when().update(content + "-update").assertThat().hasStatus(HttpStatus.SC_NOT_FOUND); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.REGRESSION, + description = "Verify that SiteManager user cannot update the content of a locked file") + public void siteManagerCannotEditContentOfLockedFile() throws Exception + { + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + webDavProtocol.authenticateUser(managerUser) + .usingSite(testSite) + .createFile(testFile).and().assertThat().existsInRepo() + .then().lock().assertThat().isLocked() + .then().update(content + "-update " ).and().assertThat().hasStatus(HttpStatus.SC_LOCKED) + .and().assertThat().contentIs(content); + } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.FULL }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.REGRESSION, + description = "Verify user can update file with a size smaller than the quota limit") + public void userCanUpdateFileSmallerThanQuotaLimit() throws Exception + { +// if (!webDavProtocol.withJMX().getSystemUsagesConfigurationStatus()) +// throw new SkipException("Skipping this test because user quotas are not enabled. Please add " + +// "system.usages.enabled=true to alfresco-global.properties, restart Alfresco and run the test again."); + + UserModel quotaUser = dataUser.createRandomTestUser(); + dataUser.addUserToSite(quotaUser, testSite, UserRole.SiteManager); + dataUser.usingAdmin().setUserQuota(quotaUser, 5); + FileModel quotaFile = FileModel.getFileModelWithContentSizeOfxMB(1); + testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); + + webDavProtocol.authenticateUser(quotaUser).usingSite(testSite).createFile(testFile).and().assertThat().existsInRepo() + .then().update(quotaFile.getContent()).and().assertThat().contentIs(quotaFile.getContent()); + } + +// @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.FULL }) +// @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.REGRESSION, +// description = "Verify user cannot update file with a size bigger than the quota limit") +// public void userCannotUpdateFileBiggerThanQuotaLimit() throws Exception +// { +// if (!webDavProtocol.withJMX().getSystemUsagesConfigurationStatus()) +// throw new SkipException("Skipping this test because user quotas are not enabled. Please add " + +// "system.usages.enabled=true to alfresco-global.properties, restart Alfresco and run the test again."); +// +// UserModel quotaUser = dataUser.createRandomTestUser(); +// dataUser.addUserToSite(quotaUser, testSite, UserRole.SiteManager); +// dataUser.usingAdmin().setUserQuota(quotaUser, 1); +// FileModel quotaFile = FileModel.getFileModelWithContentSizeOfxMB(2); +// testFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, content); +// +// webDavProtocol.authenticateUser(quotaUser).usingSite(testSite).createFile(testFile).and().assertThat().existsInRepo() +// .then().update(quotaFile.getContent()).and().assertThat().contentIs(content); +// } + + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.FULL }) + @TestRail(section = { TestGroup.PROTOCOLS, TestGroup.WEBDAV }, executionType = ExecutionType.REGRESSION, + description = "Verify that file version is incremented after file is edited") + public void verifyFileVersionIsIncrementedAfterEdit() throws Exception + { + testFile = dataContent.usingUser(managerUser).usingSite(testSite).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + webDavProtocol.authenticateUser(managerUser).usingResource(testFile).update("new content"); + dataContent.usingResource(testFile).assertContentVersionIs("1.1"); + } +} diff --git a/tests/tas-webdav/src/test/java/org/alfresco/webdav/WebDavRootTests.java b/tests/tas-webdav/src/test/java/org/alfresco/webdav/WebDavRootTests.java new file mode 100644 index 0000000000..6e201fa200 --- /dev/null +++ b/tests/tas-webdav/src/test/java/org/alfresco/webdav/WebDavRootTests.java @@ -0,0 +1,59 @@ +package org.alfresco.webdav; + +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FolderModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.jackrabbit.webdav.DavException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class WebDavRootTests extends WebDavTest +{ + UserModel testUser; + FolderModel testFolder; + FileModel testFile; + FolderModel shared = new FolderModel("Shared"); + FolderModel imapAttachments = new FolderModel("Imap Attachments"); + FolderModel guest = new FolderModel("Guest Home"); + FolderModel userHome = new FolderModel("User Homes"); + FolderModel sites = new FolderModel("Sites"); + FolderModel dataDictionary = new FolderModel("Data Dictionary"); + FolderModel imapHome = new FolderModel("IMAP Home"); + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + testUser = dataUser.createRandomTestUser(); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.SANITY, + description ="Verify if valid user can get webdav root folders") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + public void siteManagerShouldGetRootFolders() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser(); + webDavProtocol.authenticateUser(testUser).usingRoot() + .assertThat().hasFolders(shared, imapAttachments, guest, userHome, dataDictionary, imapHome); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.SANITY, + description ="Verify if admin user can get webdav root folders") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.SANITY }) + public void adminShouldGetRootFolders() throws Exception + { + webDavProtocol.authenticateUser(dataUser.getAdminUser()).usingRoot() + .assertThat().hasFolders(shared, imapAttachments, guest, userHome, dataDictionary, imapHome); + } + + @TestRail(section={TestGroup.PROTOCOLS, TestGroup.WEBDAV}, executionType= ExecutionType.REGRESSION, + description ="Verify that inexistent user cannot get webdav root folders") + @Test(groups = { TestGroup.PROTOCOLS, TestGroup.WEBDAV, TestGroup.CORE }, expectedExceptions=DavException.class) + public void inexistentUserShouldNotGetRootFolders() throws Exception + { + webDavProtocol.authenticateUser(UserModel.getRandomUserModel()).usingRoot() + .assertThat().hasFolders(shared, imapAttachments, guest, userHome, dataDictionary, imapHome); + } +} diff --git a/tests/tas-webdav/src/test/java/org/alfresco/webdav/WebDavTest.java b/tests/tas-webdav/src/test/java/org/alfresco/webdav/WebDavTest.java new file mode 100644 index 0000000000..f75eed0f92 --- /dev/null +++ b/tests/tas-webdav/src/test/java/org/alfresco/webdav/WebDavTest.java @@ -0,0 +1,39 @@ +package org.alfresco.webdav; + +import org.alfresco.utility.data.DataContent; +import org.alfresco.utility.data.DataSite; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.network.ServerHealth; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; +import org.testng.annotations.BeforeSuite; + +@ContextConfiguration("classpath:alfresco-webdav-context.xml") +public abstract class WebDavTest extends AbstractTestNGSpringContextTests +{ + @Autowired + protected DataSite dataSite; + + @Autowired + protected DataUser dataUser; + + @Autowired + protected DataContent dataContent; + + @Autowired + ServerHealth serverHealth; + + @Autowired + WebDavWrapper webDavProtocol; + + @BeforeSuite(alwaysRun=true) + public void setup() throws Exception + { + super.springTestContextPrepareTestInstance(); + serverHealth.assertServerIsOnline(); + // Since alfresco 6.0 JMX connection is deprecated + // The webdav protocol is enabled by default. + //webDavProtocol.assertThat().protocolIsEnabled(); + } +} diff --git a/tests/tas-webdav/src/test/resources/alfresco-webdav-context.xml b/tests/tas-webdav/src/test/resources/alfresco-webdav-context.xml new file mode 100644 index 0000000000..f9e3b248ab --- /dev/null +++ b/tests/tas-webdav/src/test/resources/alfresco-webdav-context.xml @@ -0,0 +1,15 @@ + + + + + + + + + + \ No newline at end of file diff --git a/tests/tas-webdav/src/test/resources/default.properties b/tests/tas-webdav/src/test/resources/default.properties new file mode 100644 index 0000000000..9ca5f0f517 --- /dev/null +++ b/tests/tas-webdav/src/test/resources/default.properties @@ -0,0 +1,74 @@ +# dataprep related +alfresco.scheme=http +alfresco.server=localhost +alfresco.port=8082 + +# credentials +admin.user=admin +admin.password=admin + +# in containers we cannot access directly JMX, so we will use http://jolokia.org agent +# disabling this we will use direct JMX calls to server +jmx.useJolokiaAgent=false + +# Server Health section +# in ServerHealth#isServerReachable() - could also be shown. +# enable this option to view if on server there are tenants or not +serverHealth.showTenants=true + +# WEBDAV related +webdav.port=${alfresco.port} + +# TEST MANAGEMENT SECTION - Test Rail +# +# (currently supporting Test Rail v5.2.1.3472 integration) +# +# Example of configuration: +# ------------------------------------------------------ +# if testManagement.enabled=true we enabled TestRailExecutorListener (if used in your suite xml file) +# testManagement.updateTestExecutionResultsOnly=true (this will just update the results of a test: no step will be updated - good for performance) +# testManagement.endPoint=https://alfresco.testrail.com/ +# testManagement.username= +# testManagement.apiKey= +# testManagement.project= +# testManagement.includeOnlyTestCasesExecuted=true #if you want to include in your run ONLY the test cases that you run, then set this value to false +# testManagement.rateLimitInSeconds=1 #is the default rate limit after what minimum time, should we upload the next request. http://docs.gurock.com/testrail-api2/introduction #Rate Limit +# testManagement.suiteId=23 (the id of the Master suite) +# ------------------------------------------------------ +testManagement.enabled=false +testManagement.endPoint= +testManagement.username= +testManagement.apiKey= +testManagement.project=7 +testManagement.includeOnlyTestCasesExecuted=true +testManagement.rateLimitInSeconds=1 +testManagement.testRun=MyTestRunInTestRail +testManagement.suiteId=12 + +# The location of the reports path +reports.path=./target/reports + +# +# Database Section +# You should provide here the database URL, that can be a differed server as alfresco. +# https://docs.oracle.com/javase/tutorial/jdbc/basics/connecting.html +# +# Current supported db.url: +# +# MySQL: +# db.url = jdbc:mysql://${alfresco.server}:3306/alfresco +# +# PostgreSQL: +# db.url = jdbc:postgresql://:3306/alfresco +# +# Oracle: +# db.url = jdbc:oracle://:3306/alfresco +# +# MariaDB: +# db.url = jdbc:mariadb://:3306/alfresco +# +db.url = jdbc:mysql://${alfresco.server}:3306/alfresco +db.username = alfresco +db.password = alfresco + diff --git a/tests/tas-webdav/src/test/resources/log4j.properties b/tests/tas-webdav/src/test/resources/log4j.properties new file mode 100644 index 0000000000..00e9b5a114 --- /dev/null +++ b/tests/tas-webdav/src/test/resources/log4j.properties @@ -0,0 +1,26 @@ +# Root logger option +log4j.rootLogger=INFO, file, stdout + +# Direct log messages to a log file +log4j.appender.file=org.apache.log4j.RollingFileAppender +log4j.appender.file.File=./target/reports/alfresco-tas.log +log4j.appender.file.MaxBackupIndex=10 +log4j.appender.file.layout=org.apache.log4j.PatternLayout +log4j.appender.file.layout.ConversionPattern=[%t] %d{HH:mm:ss} %-5p %c{1}:%L - %m%n + +# Direct log messages to stdout +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=[%t] %d{HH:mm:ss} %-5p %c{1}:%L - %m%n + +# TestRail particular log file +# Direct log messages to a log file +log4j.appender.testrailLog=org.apache.log4j.RollingFileAppender +log4j.appender.testrailLog.File=./target/reports/alfresco-testrail.log +log4j.appender.testrailLog.MaxBackupIndex=10 +log4j.appender.testrailLog.layout=org.apache.log4j.PatternLayout +log4j.appender.testrailLog.layout.ConversionPattern=%d{HH:mm:ss} %-5p %c{1}:%L - %m%n + +log4j.category.testrail=INFO, testrailLog +log4j.additivity.testrail=false \ No newline at end of file diff --git a/tests/tas-webdav/src/test/resources/shared-resources/testdata/nonemptyupload.txt b/tests/tas-webdav/src/test/resources/shared-resources/testdata/nonemptyupload.txt new file mode 100644 index 0000000000..44f73e0fc5 --- /dev/null +++ b/tests/tas-webdav/src/test/resources/shared-resources/testdata/nonemptyupload.txt @@ -0,0 +1 @@ +text file to upload \ No newline at end of file diff --git a/tests/tas-webdav/src/test/resources/shared-resources/testdata/textFile.txt b/tests/tas-webdav/src/test/resources/shared-resources/testdata/textFile.txt new file mode 100644 index 0000000000..273c1a9ffd --- /dev/null +++ b/tests/tas-webdav/src/test/resources/shared-resources/testdata/textFile.txt @@ -0,0 +1 @@ +This is a test. \ No newline at end of file diff --git a/tests/tas-webdav/src/test/resources/shared-resources/testdata/webdav-resource b/tests/tas-webdav/src/test/resources/shared-resources/testdata/webdav-resource new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/tas-webdav/src/test/resources/webdav-suite.xml b/tests/tas-webdav/src/test/resources/webdav-suite.xml new file mode 100644 index 0000000000..cd3f8a8447 --- /dev/null +++ b/tests/tas-webdav/src/test/resources/webdav-suite.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + +