From 59836574c728d1568799f9e9df919d6b50fffbef Mon Sep 17 00:00:00 2001 From: Eva Vasques Date: Tue, 10 Oct 2023 14:17:36 +0100 Subject: [PATCH] Add tas-distribution-zip to tests --- tests/pom.xml | 1 + tests/tas-distribution-zip/pom.xml | 76 +++++++++ .../CheckDistributionZipContents.java | 156 ++++++++++++++++++ .../src/test/resources/distribution-suite.xml | 9 + 4 files changed, 242 insertions(+) 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/tests/pom.xml b/tests/pom.xml index d99404b21f..12e3162f1e 100644 --- a/tests/pom.xml +++ b/tests/pom.xml @@ -19,6 +19,7 @@ tas-sync-service tas-all-amps tas-elasticsearch + tas-distribution-zip diff --git a/tests/tas-distribution-zip/pom.xml b/tests/tas-distribution-zip/pom.xml new file mode 100644 index 0000000000..f8818d6d13 --- /dev/null +++ b/tests/tas-distribution-zip/pom.xml @@ -0,0 +1,76 @@ + + + 4.0.0 + org.alfresco.tas + content-repository-distribution-test + Distribution test + jar + + + org.alfresco + content-repository-tests + 7.1.0.5-SNAPSHOT + + + + 3.13.2 + ${project.basedir}/src/test/resources/distribution-suite.xml + + + + + org.assertj + assertj-core + 3.22.0 + test + + + org.alfresco.tas + restapi + test + + + org.apache.maven + maven-model + 3.8.4 + + + + + + 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 0000000000..f1223969cb --- /dev/null +++ b/tests/tas-distribution-zip/src/test/java/org/alfresco/distribution/CheckDistributionZipContents.java @@ -0,0 +1,156 @@ +/* + * #%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-distribution"; + public static final String ACS_DIR_NAME = "distribution"; + public static final String AGS_PREFIX = "alfresco-governance-services-enterprise"; + public static final String AGS_DIR_NAME = "distribution-ags"; + public static final String SHARE_PREFIX = "alfresco-content-services-share-distribution"; + public static final String SHARE_DIR_NAME = "distribution-share"; + 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/share.xml", + "web-server/conf/Catalina/localhost/alfresco.xml", + "amps/alfresco-share-services.amp" + ); + } + } + + @Test + public void testAgsDistributionZipContents() throws Exception + { + String repoVersion = getPomValues().getProperties().getProperty("dependency.alfresco-enterprise-repo.version"); + String shareVersion = getPomValues().getProperties().getProperty("dependency.alfresco-enterprise-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-enterprise-repo-" + repoVersion + ".amp", + "alfresco-governance-services-enterprise-rest-api-explorer-" + repoVersion + ".war", + "alfresco-governance-services-enterprise-share-" + shareVersion + ".amp" + ); + } + } + + @Test + public void testShareDistributionZipContents() throws Exception + { + String projectVersion = getPomValues().getVersion(); + File filesList[] = getDistributionZip(SHARE_DIR_NAME, SHARE_PREFIX); + for (File file : filesList) + { + List zipEntries = getZipEntries(file.getAbsolutePath()); + assertThat(zipEntries). + contains( + "alfresco-content-services-share-distribution-" + projectVersion + "/bin/alfresco-mmt.jar", + "alfresco-content-services-share-distribution-" + projectVersion + "/web-server/conf/Catalina/localhost/share.xml", + "alfresco-content-services-share-distribution-" + projectVersion + "/web-server/webapps/share.war", + "alfresco-content-services-share-distribution-" + projectVersion + "/alfresco-share-encryption/alfresco-share-encryption.jar", + "alfresco-content-services-share-distribution-" + projectVersion + "/amps/alfresco-share-services.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 0000000000..5d509c8c3a --- /dev/null +++ b/tests/tas-distribution-zip/src/test/resources/distribution-suite.xml @@ -0,0 +1,9 @@ + + + + + + + + +