PeppolSBDHDocumentReader { @Nonnull public PeppolSBDHDocument extractData (@Nonnull @WillClose final InputStream aStandardBusinessDocument) throws PeppolSBDHDocumentReadException { ValueEnforcer.notNull (aStandardBusinessDocument, "StandardBusinessDocument"); try { final StandardBusinessDocument aSBD = createSBDMarshaller ().read (aStandardBusinessDocument); if (aSBD == null) throw new PeppolSBDHDocumentReadException (EPeppolSBDHDocumentReadError.INVALID_SBD_XML); return extractData (aSBD); } finally { StreamHelper.close (aStandardBusinessDocument); } } @Deprecated  PeppolSBDHDocumentReader();  PeppolSBDHDocumentReader(@Nonnull final IIdentifierFactory aIdentifierFactory); @Nonnull final IIdentifierFactory getIdentifierFactory(); final boolean isPerformValueChecks(); @Nonnull final PeppolSBDHDocumentReader setPerformValueChecks(final boolean bPerformValueChecks); @Nonnull PeppolSBDHDocument extractData(@Nonnull @WillClose final InputStream aStandardBusinessDocument); @Nonnull PeppolSBDHDocument extractData(@Nonnull final IReadableResource aStandardBusinessDocument); @Nonnull PeppolSBDHDocument extractData(@Nonnull final Node aStandardBusinessDocument); @Nonnull PeppolSBDHDocument extractData(@Nonnull final StandardBusinessDocument aStandardBusinessDocument); static final boolean DEFAULT_PERFORM_VALUE_CHECKS; }
@Test public void testReadGoodV10AndCheckResults () throws PeppolSBDHDocumentReadException { final IReadableResource aRes = PeppolSBDHTestFiles.getFirstGoodCase (); assertTrue (aRes.getPath (), aRes.exists ()); final PeppolSBDHDocumentReader aReader = new PeppolSBDHDocumentReader (SimpleIdentifierFactory.INSTANCE); final PeppolSBDHDocument aData = aReader.extractData (aRes); assertNotNull (aData); assertTrue (aData.areAllFieldsSet ()); assertEquals (PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME, aData.getSenderScheme ()); assertEquals ("0088:7315458756324", aData.getSenderValue ()); assertEquals (PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME, aData.getReceiverScheme ()); assertEquals ("0088:4562458856624", aData.getReceiverValue ()); assertEquals ("urn:oasis:names:specification:ubl:schema:xsd:Invoice-2", aData.getStandard ()); assertEquals ("2.1", aData.getTypeVersion ()); assertEquals ("Invoice", aData.getType ()); assertEquals ("123123", aData.getInstanceIdentifier ()); assertEquals ("2013-02-19T05:10:10.0", PDTWebDateHelper.getAsStringXSD (aData.getCreationDateAndTime ())); assertEquals (PeppolIdentifierHelper.DEFAULT_DOCUMENT_TYPE_SCHEME, aData.getDocumentTypeScheme ()); assertEquals ("urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##urn:www.cenbii.eu:transaction:biitrns010:ver2.0:extended:urn:www.peppol.eu:bis:peppol4a:ver2.0::2.1", aData.getDocumentTypeValue ()); assertEquals (PeppolIdentifierHelper.DEFAULT_PROCESS_SCHEME, aData.getProcessScheme ()); assertEquals ("urn:www.cenbii.eu:profile:bii04:ver1.0", aData.getProcessValue ()); assertNotNull (aData.additionalAttributes ()); assertEquals (0, aData.additionalAttributes ().size ()); assertTrue (aData.hasBusinessMessage ()); assertEquals ("Invoice", aData.getBusinessMessage ().getLocalName ()); CommonsTestHelper.testToStringImplementation (aData); }
@Test public void testReadGoodV11AndCheckResults () throws PeppolSBDHDocumentReadException { final IReadableResource aRes = PeppolSBDHTestFiles.getFirstGoodCaseV11 (); assertTrue (aRes.getPath (), aRes.exists ()); final PeppolSBDHDocumentReader aReader = new PeppolSBDHDocumentReader (SimpleIdentifierFactory.INSTANCE); final PeppolSBDHDocument aData = aReader.extractData (aRes); assertNotNull (aData); assertTrue (aData.areAllFieldsSet ()); assertEquals (PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME, aData.getSenderScheme ()); assertEquals ("0088:7315458756324", aData.getSenderValue ()); assertEquals (PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME, aData.getReceiverScheme ()); assertEquals ("0088:4562458856624", aData.getReceiverValue ()); assertEquals ("urn:oasis:names:specification:ubl:schema:xsd:Invoice-2", aData.getStandard ()); assertEquals ("2.1", aData.getTypeVersion ()); assertEquals ("Invoice", aData.getType ()); assertEquals ("123123", aData.getInstanceIdentifier ()); assertEquals ("2013-02-19T05:10:10.0", PDTWebDateHelper.getAsStringXSD (aData.getCreationDateAndTime ())); assertEquals ("dtype", aData.getDocumentTypeScheme ()); assertEquals ("urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##urn:www.cenbii.eu:transaction:biitrns010:ver2.0:extended:urn:www.peppol.eu:bis:peppol4a:ver2.0::2.1", aData.getDocumentTypeValue ()); assertEquals ("ptype", aData.getProcessScheme ()); assertEquals ("urn:www.cenbii.eu:profile:bii04:ver1.0", aData.getProcessValue ()); assertNotNull (aData.additionalAttributes ()); assertEquals (3, aData.additionalAttributes ().size ()); assertTrue (aData.additionalAttributes ().containsKey ("AddAttr1")); assertEquals ("Value1", aData.additionalAttributes ().get ("AddAttr1")); assertTrue (aData.additionalAttributes ().containsKey ("AddAttr2")); assertNull (aData.additionalAttributes ().get ("AddAttr2")); assertTrue (aData.additionalAttributes ().containsKey ("AddAttr3")); assertNull (aData.additionalAttributes ().get ("AddAttr3")); assertTrue (aData.hasBusinessMessage ()); assertEquals ("Invoice", aData.getBusinessMessage ().getLocalName ()); CommonsTestHelper.testToStringImplementation (aData); }
@Test public void testReadGoodResource () throws PeppolSBDHDocumentReadException { final PeppolSBDHDocumentReader aReader = new PeppolSBDHDocumentReader (SimpleIdentifierFactory.INSTANCE); for (final ClassPathResource aRes : PeppolSBDHTestFiles.getAllGoodCases ()) { assertTrue (aRes.getPath (), aRes.exists ()); final PeppolSBDHDocument aData = aReader.extractData (aRes); assertNotNull (aData); assertTrue (aData.areAllFieldsSet ()); } }
@Test public void testReadGoodInputStream () throws PeppolSBDHDocumentReadException { final PeppolSBDHDocumentReader aReader = new PeppolSBDHDocumentReader (SimpleIdentifierFactory.INSTANCE); for (final ClassPathResource aRes : PeppolSBDHTestFiles.getAllGoodCases ()) { assertTrue (aRes.getPath (), aRes.exists ()); final PeppolSBDHDocument aData = aReader.extractData (aRes.getInputStream ()); assertNotNull (aData); assertTrue (aData.areAllFieldsSet ()); } }
@Test public void testReadGoodNode () throws PeppolSBDHDocumentReadException { final PeppolSBDHDocumentReader aReader = new PeppolSBDHDocumentReader (SimpleIdentifierFactory.INSTANCE); for (final ClassPathResource aRes : PeppolSBDHTestFiles.getAllGoodCases ()) { assertTrue (aRes.getPath (), aRes.exists ()); final PeppolSBDHDocument aData = aReader.extractData (DOMReader.readXMLDOM (aRes)); assertNotNull (aData); assertTrue (aData.areAllFieldsSet ()); } }
@Test public void testReadBadResource () { final PeppolSBDHDocumentReader aReader = new PeppolSBDHDocumentReader (SimpleIdentifierFactory.INSTANCE); for (final Map.Entry <String, EPeppolSBDHDocumentReadError> aEntry : BAD_CASES.entrySet ()) { final IReadableResource aRes = new ClassPathResource ("sbdh/bad/" + aEntry.getKey ()); assertTrue (aRes.getPath (), aRes.exists ()); try { aReader.extractData (aRes); fail (); } catch (final PeppolSBDHDocumentReadException ex) { assertEquals (aRes.getPath (), aEntry.getValue (), ex.getErrorCode ()); } } }
@Test public void testReadBadInputStream () { final PeppolSBDHDocumentReader aReader = new PeppolSBDHDocumentReader (SimpleIdentifierFactory.INSTANCE); for (final Map.Entry <String, EPeppolSBDHDocumentReadError> aEntry : BAD_CASES.entrySet ()) { final IReadableResource aRes = new ClassPathResource ("sbdh/bad/" + aEntry.getKey ()); assertTrue (aRes.getPath (), aRes.exists ()); try { aReader.extractData (aRes.getInputStream ()); fail (); } catch (final PeppolSBDHDocumentReadException ex) { assertEquals (aRes.getPath (), aEntry.getValue (), ex.getErrorCode ()); } } }
@Test public void testReadBadNode () { final PeppolSBDHDocumentReader aReader = new PeppolSBDHDocumentReader (SimpleIdentifierFactory.INSTANCE); final DOMReaderSettings aSettings = new DOMReaderSettings (); aSettings.exceptionCallbacks ().removeAll (); for (final Map.Entry <String, EPeppolSBDHDocumentReadError> aEntry : BAD_CASES.entrySet ()) { final IReadableResource aRes = new ClassPathResource ("sbdh/bad/" + aEntry.getKey ()); assertTrue (aRes.getPath (), aRes.exists ()); final Document aDoc = DOMReader.readXMLDOM (aRes, aSettings); if (aDoc == null) { assertEquals (aRes.getPath (), EPeppolSBDHDocumentReadError.INVALID_SBD_XML, aEntry.getValue ()); } else try { aReader.extractData (aDoc); fail (); } catch (final PeppolSBDHDocumentReadException ex) { assertEquals (aRes.getPath (), aEntry.getValue (), ex.getErrorCode ()); } } }
@Test public void testReadGoodAsBad1 () { final PeppolSBDHDocumentReader aReader = new PeppolSBDHDocumentReader (SimpleIdentifierFactory.INSTANCE) { @Override protected boolean isValidBusinessMessage (@Nonnull final Element aBusinessMessage) { return "OrderXYZ".equals (aBusinessMessage.getLocalName ()); } }; for (final ClassPathResource aRes : PeppolSBDHTestFiles.getAllGoodCases ()) { assertTrue (aRes.getPath (), aRes.exists ()); try { aReader.extractData (DOMReader.readXMLDOM (aRes)); fail (); } catch (final PeppolSBDHDocumentReadException ex) { } } }
@Test public void testReadGoodAsBad2 () { final PeppolSBDHDocumentReader aReader = new PeppolSBDHDocumentReader (SimpleIdentifierFactory.INSTANCE) { @Override protected boolean isValidCreationDateTime (@Nonnull final LocalDateTime aCreationDateTime) { return aCreationDateTime.isAfter (PDTFactory.getCurrentLocalDateTime ()); } }; for (final ClassPathResource aRes : PeppolSBDHTestFiles.getAllGoodCases ()) { assertTrue (aRes.getPath (), aRes.exists ()); try { aReader.extractData (DOMReader.readXMLDOM (aRes)); fail (); } catch (final PeppolSBDHDocumentReadException ex) { } } }