Skip to content

Commit

Permalink
Fixes #348. Add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
haramon committed Jan 29, 2025
1 parent 6c30935 commit 82c789d
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 0 deletions.
85 changes: 85 additions & 0 deletions src/it/schemagen-encoding-utf8/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.codehaus.mojo.jaxb2.its</groupId>
<artifactId>mjaxb-64</artifactId>
<version>1.0-SNAPSHOT</version>

<description>Purpose: Test for bug reported in MJAXB-64 (Combinations of name attributes for
XmlTypes and XmlRootElement).
</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>3.0.0</version>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>schemagen</id>
<goals>
<goal>schemagen</goal>
</goals>
</execution>
</executions>
<configuration>
<!--
Post-processing: Transform the generated XML Schemas.
-->
<transformSchemas>
<transformSchema>
<uri>test</uri>
<toFile>transform-test.xsd</toFile>
</transformSchema>
</transformSchemas>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package se.west.shauqra;

import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlType;

@XmlType(namespace = "test")
@XmlAccessorType(XmlAccessType.FIELD)
public class Foo {
@XmlElement(name = "utf8-name_äöüÄÖÜáéúàèù")
private String name;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
38 changes: 38 additions & 0 deletions src/it/schemagen-encoding-utf8/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import groovy.xml.XmlSlurper

// Assemble
final File outputDir = new File(basedir, 'target/generated-resources/schemagen');
final File vanillaSchema = new File(basedir, 'target/schemagen-work/compile_scope/schema1.xsd');
final File processedSchema = new File(outputDir, 'transform-test.xsd');

assert vanillaSchema.exists(), "Expected file [" + vanillaSchema.getAbsolutePath() + "] not found."
assert processedSchema.exists(), "Expected file [" + processedSchema.getAbsolutePath() + "] not found."

// Act
def schemaElement = new XmlSlurper().parse(processedSchema)

// Assert
println "\nValidating schema content"
println "==================================="

assert schemaElement.complexType.sequence.element.@name == "utf8-name_äöüÄÖÜáéúàèù"
println "1. Got correct name (utf8-name_äöüÄÖÜáéúàèù) for foo element child."

0 comments on commit 82c789d

Please sign in to comment.