Skip to content

Commit

Permalink
[#508] add test project for fluent-api plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentschoelens authored and mattrpav committed Feb 22, 2024
1 parent 4dff06f commit d3c731c
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 0 deletions.
41 changes: 41 additions & 0 deletions jaxb-plugins-parent/tests/fluentapi/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<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>
<parent>
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-plugins-tests</artifactId>
<version>4.0.6-SNAPSHOT</version>
</parent>
<artifactId>jaxb-plugins-test-fluentapi</artifactId>
<packaging>jar</packaging>
<name>JAXB Tools :: JAXB Plugins :: Test [fluent-api]</name>
<dependencies>
<dependency>
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-maven-plugin-testing</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<defaultGoal>test</defaultGoal>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-maven-plugin</artifactId>
<configuration>
<extension>true</extension>
<args>
<arg>-Xfluent-api</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-plugins</artifactId>
</plugin>
</plugins>
</configuration>
</plugin>
</plugins>
</build>
</project>
41 changes: 41 additions & 0 deletions jaxb-plugins-parent/tests/fluentapi/src/main/resources/Example.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="base">
<xs:complexType>
<xs:sequence>
<xs:element name="a" type="xs:string" minOccurs="0" />
<xs:element name="b" type="xs:date" minOccurs="0" />
<xs:element name="c" type="xs:dateTime" minOccurs="0" />
<xs:element name="d" type="xs:time" minOccurs="0" />
<xs:element name="e" type="xs:base64Binary" minOccurs="0" />
<xs:element name="listOfString" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:complexType name="primitives">
<xs:sequence>
<xs:element name="boolean" type="xs:boolean" />
<xs:element name="byte" type="xs:byte" />
<!--xs:element name="char" type="xs:char" /-->
<xs:element name="double" type="xs:double" />
<xs:element name="float" type="xs:float" />
<xs:element name="long" type="xs:long" />
<xs:element name="int" type="xs:int" />
<xs:element name="short" type="xs:short" />
</xs:sequence>
</xs:complexType>

<xs:element name="unboxedPrimitives">
<xs:complexType>
<xs:attribute name="unboxedBoolean" type="xs:boolean" use="optional" />
<xs:attribute name="unboxedByte" type="xs:byte" use="optional" />
<!--xs:attribute name="unboxedChar" type="xs:char" use="optional" /-->
<xs:attribute name="unboxedDouble" type="xs:double" use="optional" />
<xs:attribute name="unboxedFloat" type="xs:float" use="optional" />
<xs:attribute name="unboxedLong" type="xs:long" use="optional" />
<xs:attribute name="unboxedInt" type="xs:int" use="optional" />
<xs:attribute name="unboxedShort" type="xs:short" use="optional" />
</xs:complexType>
</xs:element>
</xs:schema>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.jvnet.jaxb.tests.fluentapi;

import generated.Base;
import org.junit.Assert;
import org.junit.Test;

import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.GregorianCalendar;

public class BaseTest {

@Test
public void testBase() throws DatatypeConfigurationException {
XMLGregorianCalendar xgc = DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar());
byte[] textBytes = "String".getBytes(StandardCharsets.UTF_8);
Base b = new Base()
.withA("String")
.withB(xgc)
.withC(xgc)
.withD(xgc)
.withE(textBytes)
.withListOfString("a", "b", "c")
.withListOfString(Arrays.asList("e", "f", "g"));

Assert.assertEquals("String", b.getA());
Assert.assertEquals(xgc, b.getB());
Assert.assertEquals(xgc, b.getC());
Assert.assertEquals(xgc, b.getD());
Assert.assertEquals(textBytes, b.getE());
Assert.assertNotNull(b.getListOfString());
Assert.assertEquals(6, b.getListOfString().size());
Assert.assertTrue(b.getListOfString().containsAll(Arrays.asList("a", "b", "c", "e", "f", "g")));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.jvnet.jaxb.tests.fluentapi;

import generated.Primitives;
import generated.UnboxedPrimitives;
import org.junit.Assert;
import org.junit.Test;

public class PrimitivesAndUnboxedPrimitivesTest {

@Test
public void testPrimitives() {
Primitives p = new Primitives()
.withBoolean(true)
.withInt(1)
.withLong(10L)
.withDouble(20d)
.withFloat(40.0f)
.withByte((byte) 80)
.withShort((short) 160);

Assert.assertEquals(true, p.isBoolean());
Assert.assertEquals(1, p.getInt());
Assert.assertEquals(10L, p.getLong());
Assert.assertEquals(20d, p.getDouble(), 0);
Assert.assertEquals(40.0f, p.getFloat(), 0);
Assert.assertEquals((byte) 80, p.getByte());
Assert.assertEquals((short) 160, p.getShort());
}

@Test
public void testUnboxedPrimitives() {
UnboxedPrimitives u = new UnboxedPrimitives()
.withUnboxedBoolean(Boolean.TRUE)
.withUnboxedInt(Integer.valueOf(1))
.withUnboxedLong(Long.valueOf(10))
.withUnboxedDouble(Double.valueOf(20d))
.withUnboxedFloat(Float.valueOf(40.0f))
.withUnboxedByte(Byte.valueOf((byte) 80))
.withUnboxedShort(Short.valueOf((short) 160));

Assert.assertEquals(Boolean.TRUE, u.isUnboxedBoolean());
Assert.assertEquals(Integer.valueOf(1), u.getUnboxedInt());
Assert.assertEquals(Long.valueOf(10), u.getUnboxedLong());
Assert.assertEquals(Double.valueOf(20d), u.getUnboxedDouble());
Assert.assertEquals(Float.valueOf(40.0f), u.getUnboxedFloat());
Assert.assertEquals(Byte.valueOf((byte) 80), u.getUnboxedByte());
Assert.assertEquals(Short.valueOf((short) 160), u.getUnboxedShort());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
log4j.rootCategory=DEBUG, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.target=system.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n
1 change: 1 addition & 0 deletions jaxb-plugins-parent/tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<module>defaultvalue</module>
<module>elementwrapper</module>
<module>episodes</module>
<module>fluentapi</module>
<module>ignoring</module>
<module>issues</module>
<module>issues-legacy-ns</module>
Expand Down

0 comments on commit d3c731c

Please sign in to comment.