From 8fc08ab6cf8058a80dbe544d53bec8ae83a21fd7 Mon Sep 17 00:00:00 2001 From: Abdul Mohammed Date: Tue, 16 Nov 2021 14:20:40 +0000 Subject: [PATCH] ACS-106: No tests check that the distribution zip contains files from the main components (#1452) * Community Distribution Zip basic tests added * Includes fix for a real bug found by the new test. The share.war not being unpacked unless the acs-community-packaging and acs-packaging versions were identical Co-authored-by: alandavis --- .travis.yml | 6 + distribution/src/assembly/distribution.xml | 4 +- tests/pom.xml | 1 + tests/tas-distribution-zip/pom.xml | 76 ++++++++++ .../CheckDistributionZipContents.java | 134 ++++++++++++++++++ .../src/test/resources/distribution-suite.xml | 9 ++ 6 files changed, 228 insertions(+), 2 deletions(-) create mode 100644 tests/tas-distribution-zip/pom.xml create mode 100644 tests/tas-distribution-zip/src/test/java/org/alfresco/distribution/CheckDistributionZipContents.java create mode 100644 tests/tas-distribution-zip/src/test/resources/distribution-suite.xml diff --git a/.travis.yml b/.travis.yml index 2ea2233e0..fd4b91ee0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -119,6 +119,12 @@ jobs: script: - travis_wait 30 mvn -B install -f tests/tas-integration/pom.xml -Pall-tas-tests -Denvironment=default -DrunBugs=false + - name: "Community Distribution Zip content tests" + before_script: + - travis_retry travis_wait 20 mvn -B -V clean install -Pags -DskipTests -Dmaven.javadoc.skip=true + script: + - travis_wait 20 mvn -B install -f tests/tas-distribution-zip/pom.xml -Prun-distribution-zip-contents-check -DrunBugs=false + - name: "Update latest images" stage: docker_latest script: travis_retry travis_wait 30 mvn -B -V clean install -DskipTests -Dmaven.javadoc.skip=true -Pags -Ppush-docker-images diff --git a/distribution/src/assembly/distribution.xml b/distribution/src/assembly/distribution.xml index cbbf2067c..926fae2a4 100644 --- a/distribution/src/assembly/distribution.xml +++ b/distribution/src/assembly/distribution.xml @@ -38,7 +38,7 @@ - ${project.build.directory}/dependency/alfresco-content-services-share-distribution-${project.version} + ${project.build.directory}/dependency/alfresco-content-services-share-distribution-${dependency.acs-packaging.version} web-server/** @@ -47,7 +47,7 @@ - ${project.build.directory}/dependency/alfresco-content-services-share-distribution-${project.version}/web-extension-samples + ${project.build.directory}/dependency/alfresco-content-services-share-distribution-${dependency.acs-packaging.version}/web-extension-samples web-server/shared/classes/alfresco/web-extension diff --git a/tests/pom.xml b/tests/pom.xml index 93b7e62be..52bd5604a 100644 --- a/tests/pom.xml +++ b/tests/pom.xml @@ -15,6 +15,7 @@ tas-email tas-webdav tas-integration + tas-distribution-zip diff --git a/tests/tas-distribution-zip/pom.xml b/tests/tas-distribution-zip/pom.xml new file mode 100644 index 000000000..6ef9900d1 --- /dev/null +++ b/tests/tas-distribution-zip/pom.xml @@ -0,0 +1,76 @@ + + + 4.0.0 + org.alfresco.tas + content-repository-community-distribution-test + Community Distribution test + jar + + + org.alfresco + content-repository-community-tests + 7.2.0-A7-SNAPSHOT + + + + 3.13.2 + ${project.basedir}/src/test/resources/distribution-suite.xml + + + + + org.assertj + assertj-core + 3.13.2 + test + + + org.alfresco.tas + restapi + test + + + org.apache.maven + maven-model + 3.8.2 + + + + + + run-distribution-zip-contents-check + + ${project.basedir}/src/test/resources/distribution-suite.xml + + + + + + + + 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-distribution-zip/src/test/java/org/alfresco/distribution/CheckDistributionZipContents.java b/tests/tas-distribution-zip/src/test/java/org/alfresco/distribution/CheckDistributionZipContents.java new file mode 100644 index 000000000..c0c07d611 --- /dev/null +++ b/tests/tas-distribution-zip/src/test/java/org/alfresco/distribution/CheckDistributionZipContents.java @@ -0,0 +1,134 @@ +/* + * #%L + * Alfresco Remote API + * %% + * Copyright (C) 2005 - 2021 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ +package org.alfresco.distribution; + +import org.testng.annotations.Test; +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.File; +import java.io.FileReader; +import java.io.FilenameFilter; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +import org.apache.maven.model.Model; +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; + +public class CheckDistributionZipContents +{ + public static final String ACS_PREFIX = "alfresco-content-services-community-distribution"; + public static final String ACS_DIR_NAME = "distribution"; + public static final String AGS_PREFIX = "alfresco-governance-services-community"; + public static final String AGS_DIR_NAME = "distribution-ags"; + public static final String FORMAT = ".zip"; + + @Test + public void testAcsDistributionZipContents() throws Exception + { + File filesList[] = getDistributionZip(ACS_DIR_NAME, ACS_PREFIX); + for (File file : filesList) + { + List zipEntries = getZipEntries(file.getAbsolutePath()); + assertThat(zipEntries). + contains( + "keystore/metadata-keystore/keystore-passwords.properties", + "keystore/metadata-keystore/keystore", + "keystore/generate_keystores.bat", + "keystore/generate_keystores.sh", + "bin/alfresco-mmt.jar", + "bin/apply_amps.bat", + "bin/apply_amps.sh", + "web-server/webapps/ROOT.war", + "web-server/webapps/alfresco.war", + "web-server/webapps/share.war", + "web-server/webapps/_vti_bin.war", + "web-server/conf/Catalina/localhost/alfresco.xml", + "web-server/shared/classes/alfresco/web-extension/share-config-custom.xml" + ); + } + } + + @Test + public void testAgsDistributionZipContents() throws Exception + { + String repoVersion = getPomValues().getProperties().getProperty("dependency.alfresco-community-repo.version"); + String shareVersion = getPomValues().getProperties().getProperty("dependency.alfresco-community-share.version"); + File filesList[] = getDistributionZip(AGS_DIR_NAME, AGS_PREFIX); + for (File file : filesList) + { + List zipEntries = getZipEntries(file.getAbsolutePath()); + assertThat(zipEntries). + contains( + "alfresco-governance-services-community-repo-" + repoVersion + ".amp", + "alfresco-governance-services-community-rest-api-explorer-" + repoVersion + ".war", + "alfresco-governance-services-community-share-" + shareVersion + ".amp" + ); + } + } + + private File[] getDistributionZip(String dirName, String prefix) throws Exception + { + String resourcePath = Paths.get("").toAbsolutePath().getParent().getParent().toString() + "/" + dirName + "/" + "target" + "/"; + File distributionZip = new File(resourcePath); + FilenameFilter zipFileFilter = (dir, name) -> { + if (name.startsWith(prefix) && name.endsWith(FORMAT)) + { + return true; + } + else + { + return false; + } + }; + + return distributionZip.listFiles(zipFileFilter); + } + + private List getZipEntries(String filePath) throws Exception + { + List zipEntries = new ArrayList<>(); + ZipFile zipFile = new ZipFile(new File(filePath)); + Enumeration entries = zipFile.entries(); + while (entries.hasMoreElements()) + { + ZipEntry entry = entries.nextElement(); + zipEntries.add(entry.toString()); + } + return zipEntries; + } + + private Model getPomValues() throws Exception + { + String parentPom = Paths.get("").toAbsolutePath().getParent().getParent().toString() + "/pom.xml"; + MavenXpp3Reader reader = new MavenXpp3Reader(); + Model model = reader.read(new FileReader(parentPom)); + return model; + } +} diff --git a/tests/tas-distribution-zip/src/test/resources/distribution-suite.xml b/tests/tas-distribution-zip/src/test/resources/distribution-suite.xml new file mode 100644 index 000000000..ebd833c17 --- /dev/null +++ b/tests/tas-distribution-zip/src/test/resources/distribution-suite.xml @@ -0,0 +1,9 @@ + + + + + + + + +