Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namespaceconfigtest #22

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 145 additions & 0 deletions src/test/groovy/com/intershop/gradle/jaxb/SamplesSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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<String> 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<String> 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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;