-
Notifications
You must be signed in to change notification settings - Fork 749
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
122 additions
and
160 deletions.
There are no files selected for viewing
86 changes: 0 additions & 86 deletions
86
src/test/java/uk/co/jemos/podam/test/unit/XMLDatatypeUnitTest.java
This file was deleted.
Oops, something went wrong.
61 changes: 61 additions & 0 deletions
61
src/test/java/uk/co/jemos/podam/test/unit/features/xmlTypes/XMLDatatypeUnitTest.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,61 @@ | ||
package uk.co.jemos.podam.test.unit.features.xmlTypes; | ||
|
||
import net.serenitybdd.junit.runners.SerenityRunner; | ||
import net.thucydides.core.annotations.Title; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import uk.co.jemos.podam.api.PodamFactory; | ||
import uk.co.jemos.podam.test.dto.XMLDatatypePojo; | ||
import uk.co.jemos.podam.test.unit.AbstractPodamSteps; | ||
|
||
import javax.xml.datatype.Duration; | ||
import javax.xml.datatype.XMLGregorianCalendar; | ||
|
||
/** | ||
* Test @uk.co.jemos.podam.test.dto.JAXBElementPojo@ construction | ||
* | ||
* @author daivanov | ||
* | ||
*/ | ||
@RunWith(SerenityRunner.class) | ||
public class XMLDatatypeUnitTest extends AbstractPodamSteps{ | ||
|
||
private static final org.apache.logging.log4j.Logger LOG = org.apache.logging.log4j.LogManager.getLogger(XMLDatatypeUnitTest.class); | ||
|
||
|
||
@Test | ||
@Title("When given an external factory, Podam should be able to create instances of XMLGregorianCalendar") | ||
public void testXMLGregorianCalendarManufacturing() throws Exception { | ||
|
||
PodamFactory podamFactory = podamFactorySteps.givenAPodamFactoryWithXmlTypesExternalFactory(); | ||
|
||
XMLGregorianCalendar pojo = podamInvocationSteps.whenIInvokeTheFactoryForClass( | ||
XMLGregorianCalendar.class, podamFactory); | ||
|
||
podamValidationSteps.theObjectShouldNotBeNull(pojo); | ||
} | ||
|
||
@Test | ||
@Title("When given an external factory, Podam should be able to create instances of the Duration class") | ||
public void testDurationManufacturing() throws Exception { | ||
|
||
PodamFactory podamFactory = podamFactorySteps.givenAPodamFactoryWithXmlTypesExternalFactory(); | ||
|
||
Duration pojo = podamInvocationSteps.whenIInvokeTheFactoryForClass(Duration.class, podamFactory); | ||
podamValidationSteps.theObjectShouldNotBeNull(pojo); | ||
} | ||
|
||
@Test | ||
@Title("When given an external factory, Podam should be able to fill POJOs with instance attributes" + | ||
" containing XMLGregorianCalendar and Duration") | ||
public void testXMLDatatypesFieldSetting() throws Exception { | ||
|
||
PodamFactory podamFactory = podamFactorySteps.givenAPodamFactoryWithXmlTypesExternalFactory(); | ||
|
||
XMLDatatypePojo pojo = podamInvocationSteps.whenIInvokeTheFactoryForClass(XMLDatatypePojo.class, podamFactory); | ||
podamValidationSteps.theObjectShouldNotBeNull(pojo); | ||
podamValidationSteps.theObjectShouldNotBeNull(pojo.getCalendar()); | ||
podamValidationSteps.theObjectShouldNotBeNull(pojo.getDuration()); | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
src/test/java/uk/co/jemos/podam/test/unit/features/xmlTypes/XmlTypesExternalFactory.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,47 @@ | ||
package uk.co.jemos.podam.test.unit.features.xmlTypes; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import uk.co.jemos.podam.api.AbstractExternalFactory; | ||
|
||
import javax.xml.datatype.DatatypeFactory; | ||
import javax.xml.datatype.Duration; | ||
import javax.xml.datatype.XMLGregorianCalendar; | ||
import java.lang.reflect.Type; | ||
import java.util.GregorianCalendar; | ||
|
||
/** | ||
* Created by tedonema on 21/06/2015. | ||
*/ | ||
public class XmlTypesExternalFactory extends AbstractExternalFactory { | ||
|
||
|
||
/** The application logger */ | ||
private static final Logger LOG = LogManager.getLogger(XmlTypesExternalFactory.class); | ||
|
||
@Override | ||
public <T> T manufacturePojo(Class<T> pojoClass, Type... genericTypeArgs) { | ||
try { | ||
if (pojoClass.isAssignableFrom(XMLGregorianCalendar.class)) { | ||
DatatypeFactory factory = DatatypeFactory.newInstance(); | ||
T calendar = (T) factory.newXMLGregorianCalendar(new GregorianCalendar()); | ||
LOG.info("Externally created XMLGregorianCalendar"); | ||
return calendar; | ||
} else if (pojoClass.isAssignableFrom(Duration.class)) { | ||
DatatypeFactory factory = DatatypeFactory.newInstance(); | ||
@SuppressWarnings("unchecked") | ||
T duration = (T) factory.newDuration(0L); | ||
LOG.info("Externally created Duration"); | ||
return duration; | ||
} | ||
} catch (Exception e) { | ||
throw new IllegalStateException("Manufacturing failed", e); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public <T> T populatePojo(T pojo, Type... genericTypeArgs) { | ||
return pojo; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/test/java/uk/co/jemos/podam/test/unit/features/xmlTypes/package-info.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,5 @@ | ||
/** | ||
* Contains tests for XML types. | ||
* Created by tedonema on 21/06/2015. | ||
*/ | ||
package uk.co.jemos.podam.test.unit.features.xmlTypes; |
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
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