Skip to content

Commit 358b6b9

Browse files
author
Ben Asmussen
committed
#9 Add integration tests for verify and generate Maven goals
1 parent e3a90fe commit 358b6b9

File tree

5 files changed

+264
-0
lines changed

5 files changed

+264
-0
lines changed

pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@
174174
<exclude>.github/**</exclude>
175175
<exclude>README.adoc</exclude>
176176
<exclude>Jenkinsfile</exclude>
177+
<exclude>src/test/java/com/dataliquid/maven/distribution/verifier/mojo/*IT.java</exclude>
178+
<exclude>src/test/resources/test-poms/**</exclude>
177179
</excludes>
178180
</configuration>
179181
<executions>
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Copyright © 2019 dataliquid GmbH | www.dataliquid.com
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.dataliquid.maven.distribution.verifier.mojo;
17+
18+
import org.junit.Test;
19+
import org.junit.Rule;
20+
import org.junit.rules.TemporaryFolder;
21+
import java.io.File;
22+
import org.apache.commons.io.FileUtils;
23+
24+
import static org.junit.Assert.*;
25+
26+
/**
27+
* Integration test for GenerateMojo
28+
*/
29+
public class GenerateMojoIT {
30+
31+
@Rule
32+
public TemporaryFolder temporaryFolder = new TemporaryFolder();
33+
34+
@Test
35+
public void testGenerateMojoInstantiation() throws Exception {
36+
GenerateMojo mojo = new GenerateMojo();
37+
assertNotNull("Mojo should be instantiated", mojo);
38+
}
39+
40+
@Test
41+
public void testGenerateWhitelist() throws Exception {
42+
GenerateMojo mojo = new GenerateMojo();
43+
44+
File distributionFile = new File("src/test/resources/generate-whitelist/generate_whitelist.zip");
45+
File outputFile = new File(temporaryFolder.getRoot(), "generated-whitelist.xml");
46+
47+
mojo.setDistributionArchiveFile(distributionFile);
48+
mojo.setWhitelist(outputFile);
49+
50+
// Execute the generation
51+
mojo.execute();
52+
53+
// Verify the file was created
54+
assertTrue("Whitelist file should be created", outputFile.exists());
55+
56+
// Verify the content contains expected structure
57+
String content = FileUtils.readFileToString(outputFile, "UTF-8");
58+
assertTrue("Should contain whitelist root element", content.contains("<whitelist>"));
59+
assertTrue("Should contain entry elements", content.contains("<entry"));
60+
assertTrue("Should contain path attributes", content.contains("path="));
61+
}
62+
63+
@Test
64+
public void testGenerateWhitelistWithTemplateComparison() throws Exception {
65+
GenerateMojo mojo = new GenerateMojo();
66+
67+
File distributionFile = new File("src/test/resources/generate-whitelist/generate_whitelist.zip");
68+
File outputFile = new File(temporaryFolder.getRoot(), "generated-whitelist.xml");
69+
File templateFile = new File("src/test/resources/generate-whitelist/whitelist.tmpl.xml");
70+
71+
mojo.setDistributionArchiveFile(distributionFile);
72+
mojo.setWhitelist(outputFile);
73+
74+
// Execute the generation
75+
mojo.execute();
76+
77+
// Read both files
78+
String generatedContent = FileUtils.readFileToString(outputFile, "UTF-8");
79+
String templateContent = FileUtils.readFileToString(templateFile, "UTF-8");
80+
81+
// Both should have similar structure (though MD5s might differ)
82+
assertTrue("Generated content should contain whitelist element", generatedContent.contains("<whitelist>"));
83+
assertTrue("Template content should contain whitelist element", templateContent.contains("<whitelist>"));
84+
85+
// Count entries - should be similar
86+
int generatedEntries = countOccurrences(generatedContent, "<entry");
87+
int templateEntries = countOccurrences(templateContent, "<entry");
88+
assertEquals("Should have same number of entries", templateEntries, generatedEntries);
89+
}
90+
91+
@Test(expected = org.apache.maven.plugin.MojoExecutionException.class)
92+
public void testGenerateWhitelistMissingDistribution() throws Exception {
93+
GenerateMojo mojo = new GenerateMojo();
94+
95+
File distributionFile = new File("src/test/resources/non-existent.zip");
96+
File outputFile = new File(temporaryFolder.getRoot(), "generated-whitelist.xml");
97+
98+
mojo.setDistributionArchiveFile(distributionFile);
99+
mojo.setWhitelist(outputFile);
100+
101+
// This should throw MojoExecutionException
102+
mojo.execute();
103+
}
104+
105+
private int countOccurrences(String str, String findStr) {
106+
int lastIndex = 0;
107+
int count = 0;
108+
while (lastIndex != -1) {
109+
lastIndex = str.indexOf(findStr, lastIndex);
110+
if (lastIndex != -1) {
111+
count++;
112+
lastIndex += findStr.length();
113+
}
114+
}
115+
return count;
116+
}
117+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright © 2019 dataliquid GmbH | www.dataliquid.com
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.dataliquid.maven.distribution.verifier.mojo;
17+
18+
import org.junit.Test;
19+
import java.io.File;
20+
21+
import static org.junit.Assert.*;
22+
23+
/**
24+
* Integration test for VerifyMojo
25+
*/
26+
public class VerifyMojoIT {
27+
28+
@Test
29+
public void testVerifyMojoInstantiation() throws Exception {
30+
VerifyMojo mojo = new VerifyMojo();
31+
assertNotNull("Mojo should be instantiated", mojo);
32+
}
33+
34+
@Test
35+
public void testValidFullMatch() throws Exception {
36+
// Test can be run with Maven directly using the test POMs
37+
// mvn -f src/test/resources/test-poms/valid-fullmatch-test-pom.xml distribution-verifier:verify
38+
assertTrue("Valid full match test pom exists",
39+
new File("src/test/resources/test-poms/valid-fullmatch-test-pom.xml").exists());
40+
}
41+
42+
@Test
43+
public void testValidWithVariables() throws Exception {
44+
// Test distribution with variable substitution
45+
File distributionFile = new File("src/test/resources/valid-fullmatch-variables/valid_fullmatch_variables.zip");
46+
File whitelistFile = new File("src/test/resources/valid-fullmatch-variables/whitelist.xml");
47+
48+
assertTrue("Distribution file exists", distributionFile.exists());
49+
assertTrue("Whitelist file exists", whitelistFile.exists());
50+
}
51+
52+
@Test
53+
public void testInvalidMissingFile() throws Exception {
54+
// Test can be run with Maven directly using the test POMs
55+
// This should fail: mvn -f src/test/resources/test-poms/invalid-missingfile-test-pom.xml distribution-verifier:verify
56+
assertTrue("Invalid missing file test pom exists",
57+
new File("src/test/resources/test-poms/invalid-missingfile-test-pom.xml").exists());
58+
}
59+
60+
@Test
61+
public void testInvalidDifferentChecksum() throws Exception {
62+
// Test distribution with different checksum
63+
File distributionFile = new File("src/test/resources/invalid-different-md5-checksum/invalid_different_md5_checksum.zip");
64+
File whitelistFile = new File("src/test/resources/invalid-different-md5-checksum/whitelist.xml");
65+
66+
assertTrue("Distribution file exists", distributionFile.exists());
67+
assertTrue("Whitelist file exists", whitelistFile.exists());
68+
}
69+
70+
@Test
71+
public void testInvalidUndefinedFile() throws Exception {
72+
// Test distribution with undefined file
73+
File distributionFile = new File("src/test/resources/invalid-found-undefined-file/invalid_found_undefined_file.zip");
74+
File whitelistFile = new File("src/test/resources/invalid-found-undefined-file/whitelist.xml");
75+
76+
assertTrue("Distribution file exists", distributionFile.exists());
77+
assertTrue("Whitelist file exists", whitelistFile.exists());
78+
}
79+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
5+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
6+
<modelVersion>4.0.0</modelVersion>
7+
8+
<groupId>com.dataliquid.test</groupId>
9+
<artifactId>test-invalid-missingfile</artifactId>
10+
<version>1.0.0</version>
11+
12+
<build>
13+
<plugins>
14+
<plugin>
15+
<groupId>com.dataliquid.maven</groupId>
16+
<artifactId>distribution-verifier-maven-plugin</artifactId>
17+
<version>1.0.4-SNAPSHOT</version>
18+
<configuration>
19+
<distributionArchiveFile>${basedir}/src/test/resources/invalid-missingfile/invalid_missingfile.zip</distributionArchiveFile>
20+
<whitelist>${basedir}/src/test/resources/invalid-missingfile/whitelist.xml</whitelist>
21+
<reportType>xml</reportType>
22+
</configuration>
23+
<executions>
24+
<execution>
25+
<goals>
26+
<goal>verify</goal>
27+
</goals>
28+
</execution>
29+
</executions>
30+
</plugin>
31+
</plugins>
32+
</build>
33+
</project>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
5+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
6+
<modelVersion>4.0.0</modelVersion>
7+
8+
<groupId>com.dataliquid.test</groupId>
9+
<artifactId>test-valid-fullmatch</artifactId>
10+
<version>1.0.0</version>
11+
12+
<build>
13+
<plugins>
14+
<plugin>
15+
<groupId>com.dataliquid.maven</groupId>
16+
<artifactId>distribution-verifier-maven-plugin</artifactId>
17+
<version>1.0.4-SNAPSHOT</version>
18+
<configuration>
19+
<distributionArchiveFile>${basedir}/src/test/resources/valid-fullmatch/valid_fullmatch.zip</distributionArchiveFile>
20+
<whitelist>${basedir}/src/test/resources/valid-fullmatch/whitelist.xml</whitelist>
21+
<reportType>xml</reportType>
22+
</configuration>
23+
<executions>
24+
<execution>
25+
<goals>
26+
<goal>verify</goal>
27+
</goals>
28+
</execution>
29+
</executions>
30+
</plugin>
31+
</plugins>
32+
</build>
33+
</project>

0 commit comments

Comments
 (0)