Repository: olingo-odata2 Updated Branches: refs/heads/OLINGO-231_PocForAndroid 6ee4a3034 -> a4f5d6104
[OLINGO-231] Removed 'javax.xml' from Tests Project: http://git-wip-us.apache.org/repos/asf/olingo-odata2/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata2/commit/a4f5d610 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/a4f5d610 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/a4f5d610 Branch: refs/heads/OLINGO-231_PocForAndroid Commit: a4f5d6104d0bef93b401d28684f1849962e712d1 Parents: 6ee4a30 Author: Michael Bolz <[email protected]> Authored: Tue Apr 8 06:43:47 2014 +0200 Committer: Michael Bolz <[email protected]> Committed: Tue Apr 8 06:43:47 2014 +0200 ---------------------------------------------------------------------- .../producer/AtomServiceDocumentProducer.java | 12 ++---- .../odata2/core/xml/XmlStreamFactory.java | 20 ++++++++++ .../AtomServiceDocumentConsumerTest.java | 24 ++++++------ .../core/ep/producer/AtomEntryProducerTest.java | 40 ++++++++++---------- .../ep/producer/XmlMetadataProducerTest.java | 2 +- 5 files changed, 56 insertions(+), 42 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/a4f5d610/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/AtomServiceDocumentProducer.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/AtomServiceDocumentProducer.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/AtomServiceDocumentProducer.java index 1c82ce2..59d36d7 100644 --- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/AtomServiceDocumentProducer.java +++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/AtomServiceDocumentProducer.java @@ -21,18 +21,16 @@ package org.apache.olingo.odata2.core.ep.producer; import java.io.Writer; import java.util.List; -import javax.xml.stream.FactoryConfigurationError; -import javax.xml.stream.XMLOutputFactory; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamWriter; - import org.apache.olingo.odata2.api.edm.Edm; import org.apache.olingo.odata2.api.edm.EdmEntitySetInfo; import org.apache.olingo.odata2.api.edm.EdmServiceMetadata; import org.apache.olingo.odata2.api.ep.EntityProviderException; import org.apache.olingo.odata2.api.exception.ODataException; +import org.apache.olingo.odata2.api.xml.XMLStreamException; +import org.apache.olingo.odata2.api.xml.XMLStreamWriter; import org.apache.olingo.odata2.core.commons.ContentType; import org.apache.olingo.odata2.core.ep.util.FormatXml; +import org.apache.olingo.odata2.core.xml.XmlStreamFactory; /** * Writes the OData service document in XML. @@ -55,7 +53,7 @@ public class AtomServiceDocumentProducer { EdmServiceMetadata serviceMetadata = edm.getServiceMetadata(); try { - XMLStreamWriter xmlStreamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer); + XMLStreamWriter xmlStreamWriter = XmlStreamFactory.createStreamWriter(writer); xmlStreamWriter.writeStartDocument(DEFAULT_CHARSET, XML_VERSION); xmlStreamWriter.setPrefix(Edm.PREFIX_XML, Edm.NAMESPACE_XML_1998); @@ -112,8 +110,6 @@ public class AtomServiceDocumentProducer { xmlStreamWriter.writeEndDocument(); xmlStreamWriter.flush(); - } catch (FactoryConfigurationError e) { - throw new EntityProviderException(EntityProviderException.COMMON, e); } catch (XMLStreamException e) { throw new EntityProviderException(EntityProviderException.COMMON, e); } catch (ODataException e) { http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/a4f5d610/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XmlStreamFactory.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XmlStreamFactory.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XmlStreamFactory.java index 92a6c91..15af926 100644 --- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XmlStreamFactory.java +++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XmlStreamFactory.java @@ -22,12 +22,32 @@ import org.apache.olingo.odata2.api.ep.EntityProviderException; import org.apache.olingo.odata2.api.xml.*; import java.io.OutputStream; +import java.util.Collections; +import java.util.Map; /** * */ public class XmlStreamFactory implements XMLStreamWriterFactory, XMLStreamReaderFactory { + private final Map<String, Object> properties; + + private XmlStreamFactory() { + this(Collections.EMPTY_MAP); + } + + private XmlStreamFactory(Map<String, Object> properties) { + this.properties = properties; + } + + public static XmlStreamFactory create() { + return create(Collections.EMPTY_MAP); + } + + public static XmlStreamFactory create(Map<String, Object> properties) { + return new XmlStreamFactory(properties); + } + public static XMLStreamReader createStreamReader(final Object content) throws EntityProviderException { XmlStreamFactory factory = new XmlStreamFactory(); http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/a4f5d610/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/consumer/AtomServiceDocumentConsumerTest.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/consumer/AtomServiceDocumentConsumerTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/consumer/AtomServiceDocumentConsumerTest.java index a5e5b3b..254e941 100644 --- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/consumer/AtomServiceDocumentConsumerTest.java +++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/consumer/AtomServiceDocumentConsumerTest.java @@ -26,10 +26,8 @@ import static org.junit.Assert.fail; import java.io.IOException; import java.io.InputStream; - -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; +import java.util.HashMap; +import java.util.Map; import org.apache.olingo.odata2.api.edm.Edm; import org.apache.olingo.odata2.api.ep.EntityProviderException; @@ -41,6 +39,9 @@ import org.apache.olingo.odata2.api.servicedocument.ExtensionElement; import org.apache.olingo.odata2.api.servicedocument.Fixed; import org.apache.olingo.odata2.api.servicedocument.ServiceDocument; import org.apache.olingo.odata2.api.servicedocument.Workspace; +import org.apache.olingo.odata2.api.xml.XMLStreamException; +import org.apache.olingo.odata2.api.xml.XMLStreamReader; +import org.apache.olingo.odata2.core.xml.XmlStreamFactory; import org.junit.Test; public class AtomServiceDocumentConsumerTest extends AbstractXmlConsumerTest { @@ -258,19 +259,18 @@ public class AtomServiceDocumentConsumerTest extends AbstractXmlConsumerTest { } private XMLStreamReader createStreamReader2(final String fileName) throws IOException, EntityProviderException { - XMLInputFactory factory = XMLInputFactory.newInstance(); - factory.setProperty(XMLInputFactory.IS_VALIDATING, false); - factory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true); +// XMLInputFactory factory = XMLInputFactory.newInstance(); +// factory.setProperty(XMLInputFactory.IS_VALIDATING, false); +// factory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true); + + Map<String, Object> properties = new HashMap<String, Object>(); + XmlStreamFactory factory = XmlStreamFactory.create(properties); InputStream in = ClassLoader.class.getResourceAsStream(fileName); if (in == null) { throw new IOException("Requested file '" + fileName + "' was not found."); } XMLStreamReader streamReader; - try { - streamReader = factory.createXMLStreamReader(in); - } catch (XMLStreamException e) { - throw new EntityProviderException(EntityProviderException.COMMON.addContent("Invalid Service Document")); - } + streamReader = factory.createXMLStreamReader(in); return streamReader; } http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/a4f5d610/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryProducerTest.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryProducerTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryProducerTest.java index dd36e11..243d0e2 100644 --- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryProducerTest.java +++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryProducerTest.java @@ -35,9 +35,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.xml.stream.FactoryConfigurationError; -import javax.xml.stream.XMLStreamException; - import org.apache.olingo.odata2.api.edm.Edm; import org.apache.olingo.odata2.api.edm.EdmConcurrencyMode; import org.apache.olingo.odata2.api.edm.EdmCustomizableFeedMappings; @@ -53,6 +50,7 @@ import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties; import org.apache.olingo.odata2.api.exception.ODataException; import org.apache.olingo.odata2.api.exception.ODataMessageException; import org.apache.olingo.odata2.api.processor.ODataResponse; +import org.apache.olingo.odata2.api.xml.XMLStreamException; import org.apache.olingo.odata2.core.commons.ContentType; import org.apache.olingo.odata2.core.ep.AbstractProviderTest; import org.apache.olingo.odata2.core.ep.AtomEntityProvider; @@ -278,7 +276,7 @@ public class AtomEntryProducerTest extends AbstractProviderTest { @Test public void serializeAtomMediaResource() throws IOException, XpathException, SAXException, XMLStreamException, - FactoryConfigurationError, ODataException { + ODataException { AtomEntityProvider ser = createAtomEntityProvider(); ODataResponse response = ser.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees"), employeeData, @@ -320,7 +318,7 @@ public class AtomEntryProducerTest extends AbstractProviderTest { @Test public void serializeAtomMediaResourceWithMimeType() throws IOException, XpathException, SAXException, - XMLStreamException, FactoryConfigurationError, ODataException { + XMLStreamException, ODataException { AtomEntityProvider ser = createAtomEntityProvider(); EntityProviderWriteProperties properties = EntityProviderWriteProperties.serviceRoot(BASE_URI).mediaResourceMimeType("abc").build(); @@ -345,7 +343,7 @@ public class AtomEntryProducerTest extends AbstractProviderTest { */ @Test public void serializeEmployeeWithNullSyndicationTitleProperty() throws IOException, XpathException, SAXException, - XMLStreamException, FactoryConfigurationError, ODataException { + XMLStreamException, ODataException { AtomEntityProvider ser = createAtomEntityProvider(); EntityProviderWriteProperties properties = EntityProviderWriteProperties.serviceRoot(BASE_URI).build(); employeeData.put("EmployeeName", null); @@ -367,7 +365,7 @@ public class AtomEntryProducerTest extends AbstractProviderTest { @Test public void serializeEmployeeAndCheckOrderOfTags() throws IOException, XpathException, SAXException, - XMLStreamException, FactoryConfigurationError, ODataException { + XMLStreamException, ODataException { AtomEntityProvider ser = createAtomEntityProvider(); EntityProviderWriteProperties properties = EntityProviderWriteProperties.serviceRoot(BASE_URI).mediaResourceMimeType("abc").build(); @@ -401,7 +399,7 @@ public class AtomEntryProducerTest extends AbstractProviderTest { @Test public void serializeEmployeeAndCheckOrderOfPropertyTags() throws IOException, XpathException, SAXException, - XMLStreamException, FactoryConfigurationError, ODataException { + XMLStreamException, ODataException { AtomEntityProvider ser = createAtomEntityProvider(); EntityProviderWriteProperties properties = EntityProviderWriteProperties.serviceRoot(BASE_URI).mediaResourceMimeType("abc").build(); @@ -424,7 +422,7 @@ public class AtomEntryProducerTest extends AbstractProviderTest { @Test public void serializeEmployeeAndCheckKeepInContentFalse() throws IOException, XpathException, SAXException, - XMLStreamException, FactoryConfigurationError, ODataException { + XMLStreamException, ODataException { AtomEntityProvider ser = createAtomEntityProvider(); EntityProviderWriteProperties properties = EntityProviderWriteProperties.serviceRoot(BASE_URI).mediaResourceMimeType("abc").build(); @@ -457,7 +455,7 @@ public class AtomEntryProducerTest extends AbstractProviderTest { @Test(expected = EntityProviderException.class) public void serializeAtomEntryWithNullData() throws IOException, XpathException, SAXException, XMLStreamException, - FactoryConfigurationError, ODataException { + ODataException { final EntityProviderWriteProperties properties = EntityProviderWriteProperties.serviceRoot(BASE_URI).build(); AtomEntityProvider ser = createAtomEntityProvider(); ser.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms"), null, properties); @@ -465,7 +463,7 @@ public class AtomEntryProducerTest extends AbstractProviderTest { @Test(expected = EntityProviderException.class) public void serializeAtomEntryWithEmptyHashMap() throws IOException, XpathException, SAXException, - XMLStreamException, FactoryConfigurationError, ODataException { + XMLStreamException, ODataException { final EntityProviderWriteProperties properties = EntityProviderWriteProperties.serviceRoot(BASE_URI).build(); AtomEntityProvider ser = createAtomEntityProvider(); ser.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms"), @@ -474,7 +472,7 @@ public class AtomEntryProducerTest extends AbstractProviderTest { @Test public void serializeAtomEntry() throws IOException, XpathException, SAXException, XMLStreamException, - FactoryConfigurationError, ODataException { + ODataException { final EntityProviderWriteProperties properties = EntityProviderWriteProperties.serviceRoot(BASE_URI).build(); AtomEntityProvider ser = createAtomEntityProvider(); ODataResponse response = @@ -508,7 +506,7 @@ public class AtomEntryProducerTest extends AbstractProviderTest { @Test public void serializeEntryId() throws IOException, XpathException, SAXException, XMLStreamException, - FactoryConfigurationError, ODataException { + ODataException { AtomEntityProvider ser = createAtomEntityProvider(); ODataResponse response = ser.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees"), employeeData, @@ -548,7 +546,7 @@ public class AtomEntryProducerTest extends AbstractProviderTest { @Test public void serializeIds() throws IOException, XpathException, SAXException, XMLStreamException, - FactoryConfigurationError, ODataException { + ODataException { AtomEntityProvider ser = createAtomEntityProvider(); ODataResponse response = ser.writeEntry(MockFacade.getMockEdm().getEntityContainer("Container2").getEntitySet("Photos"), photoData, @@ -564,7 +562,7 @@ public class AtomEntryProducerTest extends AbstractProviderTest { @Test public void serializeProperties() throws IOException, XpathException, SAXException, XMLStreamException, - FactoryConfigurationError, ODataException { + ODataException { AtomEntityProvider ser = createAtomEntityProvider(); ODataResponse response = ser.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees"), employeeData, @@ -578,7 +576,7 @@ public class AtomEntryProducerTest extends AbstractProviderTest { @Test public void serializeWithValueEncoding() throws IOException, XpathException, SAXException, XMLStreamException, - FactoryConfigurationError, ODataException { + ODataException { photoData.put("Type", "< Ã >"); AtomEntityProvider ser = createAtomEntityProvider(); @@ -597,7 +595,7 @@ public class AtomEntryProducerTest extends AbstractProviderTest { @Test public void serializeCategory() throws IOException, XpathException, SAXException, XMLStreamException, - FactoryConfigurationError, ODataException { + ODataException { AtomEntityProvider ser = createAtomEntityProvider(); ODataResponse response = ser.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees"), employeeData, @@ -613,7 +611,7 @@ public class AtomEntryProducerTest extends AbstractProviderTest { @Test public void serializeETag() throws IOException, XpathException, SAXException, XMLStreamException, - FactoryConfigurationError, ODataException { + ODataException { AtomEntityProvider ser = createAtomEntityProvider(); ODataResponse response = ser.writeEntry(MockFacade.getMockEdm().getEntityContainer("Container2").getEntitySet("Photos"), photoData, @@ -628,7 +626,7 @@ public class AtomEntryProducerTest extends AbstractProviderTest { @Test public void serializeETagEncoding() throws IOException, XpathException, SAXException, XMLStreamException, - FactoryConfigurationError, ODataException { + ODataException { Edm edm = MockFacade.getMockEdm(); EdmTyped roomIdProperty = edm.getEntityType("RefScenario", "Room").getProperty("Id"); EdmFacets facets = mock(EdmFacets.class); @@ -655,7 +653,7 @@ public class AtomEntryProducerTest extends AbstractProviderTest { @Test public void serializeCustomMapping() throws IOException, XpathException, SAXException, XMLStreamException, - FactoryConfigurationError, ODataException { + ODataException { AtomEntityProvider ser = createAtomEntityProvider(); ODataResponse response = ser.writeEntry(MockFacade.getMockEdm().getEntityContainer("Container2").getEntitySet("Photos"), photoData, @@ -704,7 +702,7 @@ public class AtomEntryProducerTest extends AbstractProviderTest { @Test public void serializeAtomMediaResourceLinks() throws IOException, XpathException, SAXException, XMLStreamException, - FactoryConfigurationError, ODataException { + ODataException { AtomEntityProvider ser = createAtomEntityProvider(); ODataResponse response = ser.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees"), employeeData, http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/a4f5d610/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlMetadataProducerTest.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlMetadataProducerTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlMetadataProducerTest.java index f32f6f2..f8eb00b 100644 --- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlMetadataProducerTest.java +++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlMetadataProducerTest.java @@ -60,7 +60,7 @@ public class XmlMetadataProducerTest extends AbstractXmlProducerTestHelper { @Before public void before() throws EntityProviderException { - xmlStreamWriterFactory = new XmlStreamFactory().createWriterFactory(); + xmlStreamWriterFactory = XmlStreamFactory.create().createWriterFactory(); } @Test
