Skip to content

Commit a285e92

Browse files
author
Ben Asmussen
committed
#1 Add comprehensive error handling to all verify.groovy scripts
1 parent c02f8dd commit a285e92

File tree

7 files changed

+558
-271
lines changed

7 files changed

+558
-271
lines changed
Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,45 @@
11
// Verify the generated project
22
def projectDir = new File(basedir, "project/test-project")
33

4-
// Check basic structure
5-
assert projectDir.exists() : "Project directory should exist: ${projectDir}"
6-
assert new File(projectDir, "pom.xml").exists() : "pom.xml should exist"
7-
assert new File(projectDir, "LICENSE").exists() : "LICENSE should exist"
8-
assert new File(projectDir, ".gitignore").exists() : ".gitignore should exist"
9-
10-
// Check GitHub workflows
11-
assert new File(projectDir, ".github/workflows").exists() : ".github/workflows should exist"
12-
assert new File(projectDir, ".github/workflows/ci.yml").exists() : "CI workflow should exist"
13-
assert new File(projectDir, ".github/workflows/dependency-check.yml").exists() : "Dependency check workflow should exist"
14-
assert new File(projectDir, ".github/workflows/gitflow-release.yml").exists() : "Gitflow release workflow should exist"
15-
assert new File(projectDir, ".github/workflows/gitflow-hotfix.yml").exists() : "Gitflow hotfix workflow should exist"
16-
17-
// Check source directories
18-
assert new File(projectDir, "src/main/java/com/example/test/App.java").exists() : "Main App.java should exist"
19-
assert new File(projectDir, "src/test/java/com/example/test/AppTest.java").exists() : "Test AppTest.java should exist"
20-
21-
println "Integration test passed: All expected files were created!"
22-
return true
4+
try {
5+
println "Starting verification for: ${basedir}"
6+
7+
// Check basic structure
8+
println "Checking project directory exists: ${projectDir}"
9+
assert projectDir.exists() : "Project directory should exist: ${projectDir}"
10+
11+
println "Checking pom.xml..."
12+
assert new File(projectDir, "pom.xml").exists() : "pom.xml should exist"
13+
14+
println "Checking LICENSE..."
15+
assert new File(projectDir, "LICENSE").exists() : "LICENSE should exist"
16+
17+
println "Checking .gitignore..."
18+
assert new File(projectDir, ".gitignore").exists() : ".gitignore should exist"
19+
println "PASS: Basic structure validated"
20+
21+
// Check GitHub workflows
22+
println "Checking GitHub workflows..."
23+
assert new File(projectDir, ".github/workflows").exists() : ".github/workflows should exist"
24+
assert new File(projectDir, ".github/workflows/ci.yml").exists() : "CI workflow should exist"
25+
assert new File(projectDir, ".github/workflows/dependency-check.yml").exists() : "Dependency check workflow should exist"
26+
assert new File(projectDir, ".github/workflows/gitflow-release.yml").exists() : "Gitflow release workflow should exist"
27+
assert new File(projectDir, ".github/workflows/gitflow-hotfix.yml").exists() : "Gitflow hotfix workflow should exist"
28+
println "PASS: GitHub workflows validated"
29+
30+
// Check source directories
31+
println "Checking source directories..."
32+
assert new File(projectDir, "src/main/java/com/example/test/App.java").exists() : "Main App.java should exist"
33+
assert new File(projectDir, "src/test/java/com/example/test/AppTest.java").exists() : "Test AppTest.java should exist"
34+
println "PASS: Source directories validated"
35+
36+
println "VERIFICATION PASSED"
37+
return true
38+
} catch (AssertionError e) {
39+
println "ERROR: ASSERTION FAILED: ${e.message}"
40+
throw e
41+
} catch (Exception e) {
42+
println "ERROR: UNEXPECTED: ${e.message}"
43+
e.printStackTrace()
44+
throw e
45+
}
Lines changed: 86 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,89 @@
11
// Verify custom package parameter works correctly
22
def projectDir = new File(basedir, "project/custom-pkg-app")
33

4-
assert projectDir.exists()
5-
6-
// Check POM has correct groupId and artifactId
7-
def pomFile = new File(projectDir, "pom.xml")
8-
def pomContent = pomFile.text
9-
assert pomContent.contains("<groupId>com.mycompany</groupId>")
10-
assert pomContent.contains("<artifactId>custom-pkg-app</artifactId>")
11-
assert pomContent.contains("<version>1.5.0</version>")
12-
assert pomContent.contains("<maven.compiler.release>17</maven.compiler.release>")
13-
14-
// Check that package structure uses custom package, NOT groupId
15-
assert new File(projectDir, "src/main/java/org/custompackage/application/App.java").exists()
16-
assert new File(projectDir, "src/test/java/org/custompackage/application/AppTest.java").exists()
17-
18-
// Should NOT have the groupId package structure
19-
assert !new File(projectDir, "src/main/java/com/mycompany").exists()
20-
21-
// Check package declaration in source files
22-
def appFile = new File(projectDir, "src/main/java/org/custompackage/application/App.java")
23-
def appContent = appFile.text
24-
assert appContent.contains("package org.custompackage.application;")
25-
assert !appContent.contains("package com.mycompany;")
26-
27-
def testFile = new File(projectDir, "src/test/java/org/custompackage/application/AppTest.java")
28-
def testContent = testFile.text
29-
assert testContent.contains("package org.custompackage.application;")
30-
31-
// Check test.properties
32-
def testPropsFile = new File(projectDir, "src/test/resources/test.properties")
33-
def testPropsContent = testPropsFile.text
34-
assert testPropsContent.contains("app.test.java.version=17")
35-
assert testPropsContent.contains("app.test.version=1.5.0")
36-
assert testPropsContent.contains("app.test.name=custom-pkg-app-test")
37-
38-
// Check GitHub workflows exist
39-
assert new File(projectDir, ".github/workflows/ci.yml").exists()
40-
assert new File(projectDir, ".github/workflows/dependency-check.yml").exists()
41-
assert new File(projectDir, ".github/workflows/gitflow-release.yml").exists()
42-
assert new File(projectDir, ".github/workflows/gitflow-hotfix.yml").exists()
43-
44-
// Check .gitignore exists
45-
assert new File(projectDir, ".gitignore").exists()
46-
47-
println "Custom package test passed - package parameter correctly overrides groupId!"
48-
return true
4+
try {
5+
println "Starting verification for: ${basedir}"
6+
7+
println "Checking project directory exists: ${projectDir}"
8+
assert projectDir.exists() : "Project directory does not exist: ${projectDir}"
9+
10+
// Check POM has correct groupId and artifactId
11+
def pomFile = new File(projectDir, "pom.xml")
12+
println "Checking POM file: ${pomFile}"
13+
assert pomFile.exists() : "POM file does not exist: ${pomFile}"
14+
15+
def pomContent = pomFile.text
16+
assert pomContent.contains("<groupId>com.mycompany</groupId>") : "POM missing correct groupId"
17+
assert pomContent.contains("<artifactId>custom-pkg-app</artifactId>") : "POM missing correct artifactId"
18+
assert pomContent.contains("<version>1.5.0</version>") : "POM missing correct version"
19+
assert pomContent.contains("<maven.compiler.release>17</maven.compiler.release>") : "POM missing Java 17 compiler release"
20+
println "PASS: POM file validated"
21+
22+
// Check that package structure uses custom package, NOT groupId
23+
println "Checking custom package structure..."
24+
def appJavaFile = new File(projectDir, "src/main/java/org/custompackage/application/App.java")
25+
assert appJavaFile.exists() : "App.java does not exist at: ${appJavaFile}"
26+
27+
def testJavaFile = new File(projectDir, "src/test/java/org/custompackage/application/AppTest.java")
28+
assert testJavaFile.exists() : "AppTest.java does not exist at: ${testJavaFile}"
29+
30+
// Should NOT have the groupId package structure
31+
def wrongPackageDir = new File(projectDir, "src/main/java/com/mycompany")
32+
assert !wrongPackageDir.exists() : "Wrong package structure exists (should use custom package, not groupId): ${wrongPackageDir}"
33+
println "PASS: Custom package structure validated"
34+
35+
// Check package declaration in source files
36+
println "Checking package declarations..."
37+
def appContent = appJavaFile.text
38+
assert appContent.contains("package org.custompackage.application;") :
39+
"App.java has incorrect package declaration"
40+
assert !appContent.contains("package com.mycompany;") :
41+
"App.java contains wrong package declaration (com.mycompany)"
42+
43+
def testContent = testJavaFile.text
44+
assert testContent.contains("package org.custompackage.application;") :
45+
"AppTest.java has incorrect package declaration"
46+
println "PASS: Package declarations validated"
47+
48+
// Check test.properties
49+
def testPropsFile = new File(projectDir, "src/test/resources/test.properties")
50+
println "Checking test properties: ${testPropsFile}"
51+
assert testPropsFile.exists() : "test.properties does not exist: ${testPropsFile}"
52+
53+
def testPropsContent = testPropsFile.text
54+
assert testPropsContent.contains("app.test.java.version=17") :
55+
"test.properties missing java.version=17"
56+
assert testPropsContent.contains("app.test.version=1.5.0") :
57+
"test.properties missing version=1.5.0"
58+
assert testPropsContent.contains("app.test.name=custom-pkg-app-test") :
59+
"test.properties missing name=custom-pkg-app-test"
60+
println "PASS: Test properties validated"
61+
62+
// Check GitHub workflows exist
63+
println "Checking GitHub workflows..."
64+
assert new File(projectDir, ".github/workflows/ci.yml").exists() :
65+
"ci.yml does not exist"
66+
assert new File(projectDir, ".github/workflows/dependency-check.yml").exists() :
67+
"dependency-check.yml does not exist"
68+
assert new File(projectDir, ".github/workflows/gitflow-release.yml").exists() :
69+
"gitflow-release.yml does not exist"
70+
assert new File(projectDir, ".github/workflows/gitflow-hotfix.yml").exists() :
71+
"gitflow-hotfix.yml does not exist"
72+
println "PASS: GitHub workflows exist"
73+
74+
// Check .gitignore exists
75+
def gitignoreFile = new File(projectDir, ".gitignore")
76+
println "Checking .gitignore: ${gitignoreFile}"
77+
assert gitignoreFile.exists() : ".gitignore does not exist: ${gitignoreFile}"
78+
println "PASS: .gitignore exists"
79+
80+
println "VERIFICATION PASSED"
81+
return true
82+
} catch (AssertionError e) {
83+
println "ERROR: ASSERTION FAILED: ${e.message}"
84+
throw e
85+
} catch (Exception e) {
86+
println "ERROR: UNEXPECTED: ${e.message}"
87+
e.printStackTrace()
88+
throw e
89+
}
Lines changed: 77 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,80 @@
11
// Verify default package behavior (should use groupId)
22
def projectDir = new File(basedir, "project/default-pkg-app")
33

4-
assert projectDir.exists()
5-
6-
// Check POM
7-
def pomFile = new File(projectDir, "pom.xml")
8-
def pomContent = pomFile.text
9-
assert pomContent.contains("<groupId>org.mycompany</groupId>")
10-
assert pomContent.contains("<artifactId>default-pkg-app</artifactId>")
11-
assert pomContent.contains("<version>2.0.0</version>")
12-
13-
// Check that package structure uses groupId
14-
assert new File(projectDir, "src/main/java/org/mycompany/App.java").exists()
15-
assert new File(projectDir, "src/test/java/org/mycompany/AppTest.java").exists()
16-
17-
// Check package declaration
18-
def appFile = new File(projectDir, "src/main/java/org/mycompany/App.java")
19-
def appContent = appFile.text
20-
assert appContent.contains("package org.mycompany;")
21-
22-
def testFile = new File(projectDir, "src/test/java/org/mycompany/AppTest.java")
23-
def testContent = testFile.text
24-
assert testContent.contains("package org.mycompany;")
25-
26-
// Check test.properties
27-
def testPropsFile = new File(projectDir, "src/test/resources/test.properties")
28-
def testPropsContent = testPropsFile.text
29-
assert testPropsContent.contains("app.test.version=2.0.0")
30-
assert testPropsContent.contains("app.test.name=default-pkg-app-test")
31-
32-
// Check GitHub workflows exist
33-
assert new File(projectDir, ".github/workflows/ci.yml").exists()
34-
assert new File(projectDir, ".github/workflows/dependency-check.yml").exists()
35-
assert new File(projectDir, ".github/workflows/gitflow-release.yml").exists()
36-
assert new File(projectDir, ".github/workflows/gitflow-hotfix.yml").exists()
37-
38-
// Check .gitignore exists
39-
assert new File(projectDir, ".gitignore").exists()
40-
41-
println "Default package archetype generation test passed!"
42-
return true
4+
try {
5+
println "Starting verification for: ${basedir}"
6+
7+
println "Checking project directory exists: ${projectDir}"
8+
assert projectDir.exists() : "Project directory does not exist: ${projectDir}"
9+
10+
// Check POM
11+
def pomFile = new File(projectDir, "pom.xml")
12+
println "Checking POM file: ${pomFile}"
13+
assert pomFile.exists() : "POM file does not exist: ${pomFile}"
14+
15+
def pomContent = pomFile.text
16+
assert pomContent.contains("<groupId>org.mycompany</groupId>") : "POM missing correct groupId"
17+
assert pomContent.contains("<artifactId>default-pkg-app</artifactId>") : "POM missing correct artifactId"
18+
assert pomContent.contains("<version>2.0.0</version>") : "POM missing correct version"
19+
println "PASS: POM file validated"
20+
21+
// Check that package structure uses groupId
22+
println "Checking package structure uses groupId..."
23+
def appJavaFile = new File(projectDir, "src/main/java/org/mycompany/App.java")
24+
assert appJavaFile.exists() : "App.java does not exist at: ${appJavaFile}"
25+
26+
def testJavaFile = new File(projectDir, "src/test/java/org/mycompany/AppTest.java")
27+
assert testJavaFile.exists() : "AppTest.java does not exist at: ${testJavaFile}"
28+
println "PASS: Package structure validated (using groupId as default)"
29+
30+
// Check package declaration
31+
println "Checking package declarations..."
32+
def appContent = appJavaFile.text
33+
assert appContent.contains("package org.mycompany;") :
34+
"App.java has incorrect package declaration"
35+
36+
def testContent = testJavaFile.text
37+
assert testContent.contains("package org.mycompany;") :
38+
"AppTest.java has incorrect package declaration"
39+
println "PASS: Package declarations validated"
40+
41+
// Check test.properties
42+
def testPropsFile = new File(projectDir, "src/test/resources/test.properties")
43+
println "Checking test properties: ${testPropsFile}"
44+
assert testPropsFile.exists() : "test.properties does not exist: ${testPropsFile}"
45+
46+
def testPropsContent = testPropsFile.text
47+
assert testPropsContent.contains("app.test.version=2.0.0") :
48+
"test.properties missing version=2.0.0"
49+
assert testPropsContent.contains("app.test.name=default-pkg-app-test") :
50+
"test.properties missing name=default-pkg-app-test"
51+
println "PASS: Test properties validated"
52+
53+
// Check GitHub workflows exist
54+
println "Checking GitHub workflows..."
55+
assert new File(projectDir, ".github/workflows/ci.yml").exists() :
56+
"ci.yml does not exist"
57+
assert new File(projectDir, ".github/workflows/dependency-check.yml").exists() :
58+
"dependency-check.yml does not exist"
59+
assert new File(projectDir, ".github/workflows/gitflow-release.yml").exists() :
60+
"gitflow-release.yml does not exist"
61+
assert new File(projectDir, ".github/workflows/gitflow-hotfix.yml").exists() :
62+
"gitflow-hotfix.yml does not exist"
63+
println "PASS: GitHub workflows exist"
64+
65+
// Check .gitignore exists
66+
def gitignoreFile = new File(projectDir, ".gitignore")
67+
println "Checking .gitignore: ${gitignoreFile}"
68+
assert gitignoreFile.exists() : ".gitignore does not exist: ${gitignoreFile}"
69+
println "PASS: .gitignore exists"
70+
71+
println "VERIFICATION PASSED"
72+
return true
73+
} catch (AssertionError e) {
74+
println "ERROR: ASSERTION FAILED: ${e.message}"
75+
throw e
76+
} catch (Exception e) {
77+
println "ERROR: UNEXPECTED: ${e.message}"
78+
e.printStackTrace()
79+
throw e
80+
}

0 commit comments

Comments
 (0)