diff --git a/src/test/groovy/com/intershop/gradle/jaxb/SamplesSpec.groovy b/src/test/groovy/com/intershop/gradle/jaxb/SamplesSpec.groovy index a35b8d0..51fd346 100644 --- a/src/test/groovy/com/intershop/gradle/jaxb/SamplesSpec.groovy +++ b/src/test/groovy/com/intershop/gradle/jaxb/SamplesSpec.groovy @@ -768,6 +768,151 @@ class SamplesSpec extends AbstractIntegrationSpec { gradleVersion << supportedGradleVersions } + def 'Test j2s-xmlAdapter - schemagen - change file name'() { + given: + copyResources('samples/j2s-xmlAdapter') + + buildFile << """ + plugins { + id 'java' + id 'com.intershop.gradle.jaxb' + } + + jaxb { + schemaGen { + test { + javaFiles = fileTree(dir: 'src', + include: '**/**/*.java', + excludes: [ 'Main.java', 'shoppingCart/AdapterPurchaseListToHashMap.java'] ) + namespaceconfigs = [ '' : 'shoppingCart.xsd' ] + } + } + } + + repositories { + mavenCentral() + } + """.stripIndent() + + when: + List args = ['jaxb', '-s', '-d'] + + def result = getPreparedGradleRunner() + .withArguments(args) + .withGradleVersion(gradleVersion) + .build() + + File schemaFile = new File(testProjectDir, 'build/generated/jaxb/schema/test/shoppingCart.xsd') + + then: + result.task(':jaxbSchemaGenTest').outcome == SUCCESS + + schemaFile.exists() + ! schemaFile.text.contains('name="main"') + schemaFile.text.contains('kitchenWorldBasket') + schemaFile.text.contains('purchaseList') + schemaFile.text.contains('KitchenWorldBasketType') + schemaFile.text.contains('PurchaseListType') + + where: + gradleVersion << supportedGradleVersions + } + + def 'Test j2s-namespaceconfig - schemagen with extended configuration'() { + given: + copyResources('samples/j2c-namespaceconfig') + + buildFile << """ + plugins { + id 'java' + id 'com.intershop.gradle.jaxb' + } + + jaxb { + schemaGen { + test { + javaFiles = fileTree(dir: 'src', + include: '**/**/*.java') + + namespaceconfigs = [ 'example' : 'example.xsd' ] + } + } + } + + repositories { + mavenCentral() + } + """.stripIndent() + + when: + List args = ['jaxb', '-s', '-d'] + + def result = getPreparedGradleRunner() + .withArguments(args) + .withGradleVersion(gradleVersion) + .build() + + File schemaFile = new File(testProjectDir, 'build/generated/jaxb/schema/test/example.xsd') + + then: + result.task(':jaxbSchemaGenTest').outcome == SUCCESS + schemaFile.exists() + + where: + gradleVersion << supportedGradleVersions + } + + def 'Test j2s-simple'() { + given: + copyResources('samples/j2s-xmlAdapter') + + buildFile << """ + plugins { + id 'java' + id 'com.intershop.gradle.jaxb' + } + + jaxb { + schemaGen { + test { + javaFiles = fileTree(dir: 'src', + include: '**/**/*.java', + excludes: [ 'Main.java', 'shoppingCart/AdapterPurchaseListToHashMap.java'] ) + } + } + } + + sourceSets { + main { + resources { + srcDir(tasks.jaxbSchemaGenTest.outputs) + } + } + } + + repositories { + mavenCentral() + } + """.stripIndent() + + when: + List args = ['jaxb', '-s', '-d'] + + def result = getPreparedGradleRunner() + .withArguments(args) + .withGradleVersion(gradleVersion) + .build() + + File schemaFile = new File(testProjectDir, 'build/generated/jaxb/schema/test/schema1.xsd') + + then: + result.task(':jaxbSchemaGenTest').outcome == SUCCESS + schemaFile.exists() + + where: + gradleVersion << supportedGradleVersions + } + private boolean fileExists(String path) { File f = new File(testProjectDir, path) return f.isFile() && f.exists() diff --git a/src/test/resources/samples/j2c-namespaceconfig/src/org/testing/xml/MyType.java b/src/test/resources/samples/j2c-namespaceconfig/src/org/testing/xml/MyType.java new file mode 100644 index 0000000..5170876 --- /dev/null +++ b/src/test/resources/samples/j2c-namespaceconfig/src/org/testing/xml/MyType.java @@ -0,0 +1,28 @@ +package org.testing.xml; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * This is a class-level comment. + */ +@XmlRootElement +@XmlAccessorType(XmlAccessType.FIELD) +public class MyType { + + /** + * This is a field-level comment. + */ + @XmlElement(required = true) + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} \ No newline at end of file diff --git a/src/test/resources/samples/j2c-namespaceconfig/src/org/testing/xml/package-info.java b/src/test/resources/samples/j2c-namespaceconfig/src/org/testing/xml/package-info.java new file mode 100644 index 0000000..2712f4e --- /dev/null +++ b/src/test/resources/samples/j2c-namespaceconfig/src/org/testing/xml/package-info.java @@ -0,0 +1,8 @@ +/** + * This is a package-level comment. + */ +@XmlSchema(namespace = "example", elementFormDefault = XmlNsForm.QUALIFIED) +package org.testing.xml; + +import javax.xml.bind.annotation.XmlSchema; +import javax.xml.bind.annotation.XmlNsForm; \ No newline at end of file