Skip to content

Commit

Permalink
Add tas-distribution-zip to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
evasques committed Oct 10, 2023
1 parent e7f36c2 commit 5983657
Show file tree
Hide file tree
Showing 4 changed files with 242 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<module>tas-sync-service</module>
<module>tas-all-amps</module>
<module>tas-elasticsearch</module>
<module>tas-distribution-zip</module>
</modules>

<properties>
Expand Down
76 changes: 76 additions & 0 deletions tests/tas-distribution-zip/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.alfresco.tas</groupId>
<artifactId>content-repository-distribution-test</artifactId>
<name>Distribution test</name>
<packaging>jar</packaging>

<parent>
<groupId>org.alfresco</groupId>
<artifactId>content-repository-tests</artifactId>
<version>7.1.0.5-SNAPSHOT</version>
</parent>

<properties>
<dependency.assertj-core.version>3.13.2</dependency.assertj-core.version>
<suiteXmlFile>${project.basedir}/src/test/resources/distribution-suite.xml</suiteXmlFile>
</properties>

<dependencies>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.22.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.alfresco.tas</groupId>
<artifactId>restapi</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<version>3.8.4</version>
</dependency>
</dependencies>

<profiles>
<profile>
<id>run-distribution-zip-contents-check</id>
<properties>
<suiteXmlFile>${project.basedir}/src/test/resources/distribution-suite.xml</suiteXmlFile>
</properties>
</profile>
</profiles>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
</suiteXmlFiles>
<argLine>
--illegal-access=warn
</argLine>
</configuration>
</plugin>
<!-- Build only test jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
* #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<String> 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<String> 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<String> 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<String> getZipEntries(String filePath) throws Exception
{
List<String> zipEntries = new ArrayList<>();
ZipFile zipFile = new ZipFile(new File(filePath));
Enumeration<? extends ZipEntry> 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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Alfresco tests Distribution Zip" preserve-order="true" verbose="1">
<test name="distribution" verbose="3" preserve-order="true">
<classes>
<class name="org.alfresco.distribution.CheckDistributionZipContents"></class>
</classes>
</test>
</suite>

0 comments on commit 5983657

Please sign in to comment.