Skip to content

Commit 9250b80

Browse files
jeffjensenclaude
andcommitted
feat(spring): Add disabledTests archetype property
Add a disabledTests archetype property (default false). When true, every generated test method is annotated with JUnit's @disabled, so the scaffolded suite compiles but does not run -- useful for adding the audits to a project that does not pass them yet and enabling them one at a time. * Declare disabledTests (default false) in archetype-metadata.xml. * Guard a Disabled import and a per-method @disabled annotation with #if($disabledTests == 'true') in all 11 test templates; the default renders identically to before. * List disabledTests=false in the four existing self-test variants and add a new disabled-tests project-mode self-test (disabledTests=true) that compiles the generated @disabled code and verifies every test is skipped. * Document the property in the site archetype reference and CLAUDE.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017xn2cPgARPz3joQXUbtejf
1 parent 8266c0f commit 9250b80

20 files changed

Lines changed: 99 additions & 1 deletion

CLAUDE.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ mvn archetype:generate -DinteractiveMode=false `
136136
and `#[[$]]#` produces `$`.
137137
- **Properties** (`META-INF/maven/archetype-metadata.xml`): `generateMode` (`project`), `schemaName` (`public`),
138138
`schemaPropertyName` (`database.datasource.schema-name`), `parentClass` (`none`), `databaseAuditsVersion`
139-
(`1.0.0-SNAPSHOT`), `springBootVersion` (`4.1.0`), `postgresImage` (`postgres:16`).
139+
(`1.0.0-SNAPSHOT`), `springBootVersion` (`4.1.0`), `postgresImage` (`postgres:16`), `disabledTests` (`false`,
140+
annotates every generated test method with JUnit's `@Disabled` when `true`).
140141
All have defaults; none are required. The self-test's `archetype.properties` must list every property that the
141142
templates reference — the IT mojo does not apply defaults the way `archetype:generate` does.
142143
- **`projectDirectory` is NOT a declared archetype property** (deliberately). `archetype:generate` therefore

archetype/src/main/resources/META-INF/maven/archetype-metadata.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@
3636
<requiredProperty key="postgresImage">
3737
<defaultValue>postgres:16</defaultValue>
3838
</requiredProperty>
39+
<!-- When 'true', every generated test method is annotated with JUnit's @Disabled, so the suite is
40+
generated and compiles but does not run. Default 'false' runs the audits. Useful for scaffolding the
41+
suite into a project that does not pass it yet, then enabling audits one at a time. -->
42+
<requiredProperty key="disabledTests">
43+
<defaultValue>false</defaultValue>
44+
</requiredProperty>
3945
</requiredProperties>
4046

4147
<fileSets>

archetype/src/main/resources/archetype-resources/src/test/java/catalog/ForeignKeyIndexAuditIT.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package ${package}.catalog;
22

3+
#if($disabledTests == 'true')
4+
import org.junit.jupiter.api.Disabled;
5+
#end
36
import org.junit.jupiter.api.Test;
47
import org.springframework.beans.factory.annotation.Autowired;
58
import org.springframework.beans.factory.annotation.Value;
@@ -27,6 +30,9 @@ public class ForeignKeyIndexAuditIT extends AbstractDatabaseAuditIT {
2730
private String schema;
2831

2932
@Test
33+
#if($disabledTests == 'true')
34+
@Disabled("Generated as disabled; remove @Disabled to enable")
35+
#end
3036
void testEveryForeignKeyHasSupportingIndex() {
3137
foreignKeyIndexAuditAssertion.assertClean(schema);
3238
}

archetype/src/main/resources/archetype-resources/src/test/java/catalog/ForeignKeyNotNullAuditIT.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import java.util.Set;
44

5+
#if($disabledTests == 'true')
6+
import org.junit.jupiter.api.Disabled;
7+
#end
58
import org.junit.jupiter.api.Test;
69
import org.springframework.beans.factory.annotation.Autowired;
710
import org.springframework.beans.factory.annotation.Value;
@@ -32,6 +35,9 @@ public class ForeignKeyNotNullAuditIT extends AbstractDatabaseAuditIT {
3235
private String schema;
3336

3437
@Test
38+
#if($disabledTests == 'true')
39+
@Disabled("Generated as disabled; remove @Disabled to enable")
40+
#end
3541
void testEveryForeignKeyColumnIsConfiguredNotNullOrOptional() {
3642
foreignKeyNotNullAuditAssertion.assertClean(schema, EXCLUDED_COLUMNS);
3743
}

archetype/src/main/resources/archetype-resources/src/test/java/catalog/ForeignKeyTypeMatchAuditIT.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import java.util.Set;
44

5+
#if($disabledTests == 'true')
6+
import org.junit.jupiter.api.Disabled;
7+
#end
58
import org.junit.jupiter.api.Test;
69
import org.springframework.beans.factory.annotation.Autowired;
710
import org.springframework.beans.factory.annotation.Value;
@@ -33,6 +36,9 @@ public class ForeignKeyTypeMatchAuditIT extends AbstractDatabaseAuditIT {
3336
private String schema;
3437

3538
@Test
39+
#if($disabledTests == 'true')
40+
@Disabled("Generated as disabled; remove @Disabled to enable")
41+
#end
3642
void testEveryForeignKeyColumnTypeMatchesItsReferencedColumn() {
3743
foreignKeyTypeMatchAuditAssertion.assertClean(schema, EXCLUDED_COLUMNS);
3844
}

archetype/src/main/resources/archetype-resources/src/test/java/catalog/PrimaryKeyPresenceAuditIT.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package ${package}.catalog;
22

3+
#if($disabledTests == 'true')
4+
import org.junit.jupiter.api.Disabled;
5+
#end
36
import org.junit.jupiter.api.Test;
47
import org.springframework.beans.factory.annotation.Autowired;
58
import org.springframework.beans.factory.annotation.Value;
@@ -27,6 +30,9 @@ public class PrimaryKeyPresenceAuditIT extends AbstractDatabaseAuditIT {
2730
private String schema;
2831

2932
@Test
33+
#if($disabledTests == 'true')
34+
@Disabled("Generated as disabled; remove @Disabled to enable")
35+
#end
3036
void testEveryBaseTableHasPrimaryKey() {
3137
primaryKeyPresenceAuditAssertion.assertClean(schema);
3238
}

archetype/src/main/resources/archetype-resources/src/test/java/catalog/RedundantIndexAuditIT.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import java.util.Set;
44

5+
#if($disabledTests == 'true')
6+
import org.junit.jupiter.api.Disabled;
7+
#end
58
import org.junit.jupiter.api.Test;
69
import org.springframework.beans.factory.annotation.Autowired;
710
import org.springframework.beans.factory.annotation.Value;
@@ -32,6 +35,9 @@ public class RedundantIndexAuditIT extends AbstractDatabaseAuditIT {
3235
private String schema;
3336

3437
@Test
38+
#if($disabledTests == 'true')
39+
@Disabled("Generated as disabled; remove @Disabled to enable")
40+
#end
3541
void testNoRedundantIndexes() {
3642
redundantIndexAuditAssertion.assertClean(schema, EXCLUDED_INDEXES);
3743
}

archetype/src/main/resources/archetype-resources/src/test/java/jpa/SchemaEntityValidationAuditIT.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package ${package}.jpa;
22

3+
#if($disabledTests == 'true')
4+
import org.junit.jupiter.api.Disabled;
5+
#end
36
import org.junit.jupiter.api.Test;
47
import org.springframework.beans.factory.annotation.Autowired;
58
import org.springframework.test.context.TestPropertySource;
@@ -26,6 +29,9 @@ public class SchemaEntityValidationAuditIT extends AbstractDatabaseAuditIT {
2629
private SchemaEntityValidationAuditAssertion schemaEntityValidationAuditAssertion;
2730

2831
@Test
32+
#if($disabledTests == 'true')
33+
@Disabled("Generated as disabled; remove @Disabled to enable")
34+
#end
2935
void testEntitiesMatchSchema() {
3036
schemaEntityValidationAuditAssertion.assertClean();
3137
}

archetype/src/main/resources/archetype-resources/src/test/java/runtime/JoinIndexAuditIT.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import java.util.List;
44
import java.util.Set;
55

6+
#if($disabledTests == 'true')
7+
import org.junit.jupiter.api.Disabled;
8+
#end
69
import org.junit.jupiter.api.Order;
710
import org.junit.jupiter.api.Test;
811
import org.springframework.beans.factory.annotation.Autowired;
@@ -35,6 +38,9 @@ public class JoinIndexAuditIT extends AbstractDatabaseAuditIT {
3538
private JoinIndexAuditAssertion joinIndexAuditAssertion;
3639

3740
@Test
41+
#if($disabledTests == 'true')
42+
@Disabled("Generated as disabled; remove @Disabled to enable")
43+
#end
3844
void testEveryJoinKeyIsServedByAnIndex() {
3945
joinIndexAuditAssertion.assertClean(EXCLUDED_RELATIONS, EXCLUDED_SQL_FRAGMENTS);
4046
}

archetype/src/main/resources/archetype-resources/src/test/java/runtime/OrderByIndexAuditIT.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import java.util.List;
44
import java.util.Set;
55

6+
#if($disabledTests == 'true')
7+
import org.junit.jupiter.api.Disabled;
8+
#end
69
import org.junit.jupiter.api.Order;
710
import org.junit.jupiter.api.Test;
811
import org.springframework.beans.factory.annotation.Autowired;
@@ -35,6 +38,9 @@ public class OrderByIndexAuditIT extends AbstractDatabaseAuditIT {
3538
private OrderByIndexAuditAssertion orderByIndexAuditAssertion;
3639

3740
@Test
41+
#if($disabledTests == 'true')
42+
@Disabled("Generated as disabled; remove @Disabled to enable")
43+
#end
3844
void testEveryOrderByIsServedByAnIndexNotAnExplicitSort() {
3945
orderByIndexAuditAssertion.assertClean(EXCLUDED_RELATIONS, EXCLUDED_SQL_FRAGMENTS);
4046
}

0 commit comments

Comments
 (0)