-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ketoth Xupack <ketoth.xupack@gmail.com>
- Loading branch information
1 parent
a68c69c
commit 1d5d614
Showing
4 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...s/jaxb2-plugins/src/test/java/org/nohope/jaxb2/plugin/metadata/RunMetadataPluginTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package org.nohope.jaxb2.plugin.metadata; | ||
|
||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.jvnet.jaxb2.maven2.AbstractXJC2Mojo; | ||
|
||
import java.io.File; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static java.lang.Class.forName; | ||
import static org.junit.Assert.*; | ||
import static org.nohope.reflection.IntrospectionUtils.instanceOf; | ||
import static org.nohope.reflection.IntrospectionUtils.invoke; | ||
import static org.nohope.reflection.ModifierMatcher.*; | ||
|
||
/** | ||
* @author <a href="mailto:ketoth.xupack@gmail.com">Ketoth Xupack</a> | ||
* @since 2013-10-11 16:31 | ||
*/ | ||
public class RunMetadataPluginTest { | ||
//static { | ||
// System.setProperty("javax.xml.accessExternalStylesheet", "all"); | ||
// System.setProperty("javax.xml.accessExternalSchema", "all"); | ||
// System.setProperty("javax.xml.accessExternalDTD", "all"); | ||
//} | ||
|
||
private static class RunMetadataPlugin extends org.jvnet.jaxb2.maven2.test.RunXJC2Mojo { | ||
|
||
@Override | ||
public File getSchemaDirectory() { | ||
return new File(getBaseDir(), "src/test/resources/metadata"); | ||
} | ||
|
||
@Override | ||
protected void configureMojo(final AbstractXJC2Mojo mojo) { | ||
super.configureMojo(mojo); | ||
mojo.setForceRegenerate(true); | ||
} | ||
|
||
@Override | ||
public List<String> getArgs() { | ||
final List<String> args = new ArrayList<>(super.getArgs()); | ||
args.add("-Xmetadata"); | ||
return args; | ||
} | ||
} | ||
|
||
@BeforeClass | ||
public static void generateCode() throws Exception { | ||
new RunMetadataPlugin().testExecute(); | ||
} | ||
|
||
@Test | ||
public void checkGeneratedObjectsValidity() throws Exception { | ||
final Class<?> cobj1 = forName("org.nohope.metadata.ComplexObjectType"); | ||
final Object descriptor = invoke(cobj1, ALL, "descriptor"); | ||
|
||
final CallChain callChain = | ||
(CallChain) invoke(invoke(invoke(descriptor, | ||
not(ABSTRACT), "getObjectField"), | ||
not(ABSTRACT), "getFloatField"), | ||
not(ABSTRACT), "getCallChain"); | ||
|
||
final List<NamedDescriptor<?>> chain = callChain.getChain(); | ||
assertEquals(2, chain.size()); | ||
assertEquals("object_field", chain.get(0).getProperty()); | ||
assertTrue(instanceOf(chain.get(0).getParentDescriptor(), | ||
forName("org.nohope.metadata.ComplexObjectType$IDescriptor"))); | ||
|
||
assertEquals("float_field", chain.get(1).getProperty()); | ||
assertTrue(instanceOf(chain.get(1).getParentDescriptor(), | ||
forName("org.nohope.metadata.ComplexObjectType2$IDescriptor"))); | ||
assertEquals(forName("org.nohope.metadata.ComplexObjectType2"), | ||
chain.get(1).getParentDescriptor().getFieldType().getTypeClass()); | ||
} | ||
|
||
@Test | ||
public void properties() { | ||
final MetadataPlugin plugin = new MetadataPlugin(); | ||
assertNotNull(plugin.getUsage()); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
projects/jaxb2-plugins/src/test/resources/metadata/schema.xsd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?xml version="1.0"?> | ||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" | ||
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" | ||
xmlns:tns="http://no-hope.org/" | ||
targetNamespace="http://no-hope.org/" | ||
jaxb:version="1.0"> | ||
|
||
<xs:annotation> | ||
<xs:appinfo> | ||
<jaxb:globalBindings choiceContentProperty="true" generateIsSetMethod="true" /> | ||
<jaxb:schemaBindings> | ||
<jaxb:package name="org.nohope.metadata"/> | ||
</jaxb:schemaBindings> | ||
</xs:appinfo> | ||
</xs:annotation> | ||
|
||
<xs:element name="complexObject" type="tns:complexObjectType"/> | ||
<xs:complexType name="complexObjectType"> | ||
<xs:sequence> | ||
<xs:element name="object_field" type="tns:complexObjectType2"/> | ||
|
||
<xs:element name="datetime_field" type="xs:dateTime"/> | ||
<xs:element name="time_field" type="xs:time"/> | ||
<xs:element name="date_field" type="xs:date"/> | ||
<xs:element name="float_field" type="xs:float"/> | ||
<xs:element name="string_field" type="xs:string"/> | ||
<xs:element name="boolean_field" type="xs:boolean"/> | ||
</xs:sequence> | ||
</xs:complexType> | ||
|
||
<xs:element name="complexObject2" type="tns:complexObjectType2"/> | ||
<xs:complexType name="complexObjectType2"> | ||
<xs:sequence> | ||
<xs:element name="datetime_field" type="xs:dateTime"/> | ||
<xs:element name="time_field" type="xs:time"/> | ||
<xs:element name="date_field" type="xs:date"/> | ||
<xs:element name="float_field" type="xs:float"/> | ||
<xs:element name="string_field" type="xs:string"/> | ||
<xs:element name="boolean_field" type="xs:boolean"/> | ||
|
||
<!-- this field should not have name attribute in @XmlElement --> | ||
<xs:element name="simple" type="xs:string"/> | ||
</xs:sequence> | ||
</xs:complexType> | ||
</xs:schema> |