Package org.milyn.edisax.unedifact

Examples of org.milyn.edisax.unedifact.UNEdifactInterchangeParser


  public void test_with_groupref() throws IOException, SAXException, EDIConfigurationException {
    EdifactModel model1 = EDIParser.parseMappingModel(getClass().getResourceAsStream("../MSG1-model.xml"));
    EdifactModel model2 = EDIParser.parseMappingModel(getClass().getResourceAsStream("../MSG2-model.xml"));
   
    UNEdifactInterchangeParser parser = new UNEdifactInterchangeParser();
    parser.setMappingsRegistry(new DefaultMappingsRegistry(model1, model2));
    parser.ignoreNewLines(true);

    MockContentHandlerNS handler;
   
    // Test message 01 - no UNA segment...
    handler = new MockContentHandlerNS();
        NamespaceDeclarationStack namespaceDeclarationStack = new NamespaceDeclarationStack(parser);

        parser.setContentHandler(new NamespaceAwareHandler(handler, namespaceDeclarationStack));
    parser.parse(new InputSource(getClass().getResourceAsStream("unedifact-msg-01.edi")));   
    //System.out.println(handler.xmlMapping);
        XMLUnit.setIgnoreWhitespace( true );
        XMLAssert.assertXMLEqual(new InputStreamReader(getClass().getResourceAsStream("unedifact-msg-expected-01.xml")), new StringReader(handler.xmlMapping.toString()));

    // Test message 01 - has a UNA segment...
    handler = new MockContentHandlerNS();
    parser.setContentHandler(handler);   
    parser.parse(new InputSource(getClass().getResourceAsStream("unedifact-msg-02.edi")));
   
//    System.out.println(handler.xmlMapping);
        XMLUnit.setIgnoreWhitespace( true );
        XMLAssert.assertXMLEqual(new InputStreamReader(getClass().getResourceAsStream("unedifact-msg-expected-01.xml")), new StringReader(handler.xmlMapping.toString()));
  }
View Full Code Here


  public void test_without_groupref() throws IOException, SAXException, EDIConfigurationException {
    EdifactModel model1 = EDIParser.parseMappingModel(getClass().getResourceAsStream("../MSG1-model.xml"));
    EdifactModel model2 = EDIParser.parseMappingModel(getClass().getResourceAsStream("../MSG2-model.xml"));
   
    UNEdifactInterchangeParser parser = new UNEdifactInterchangeParser();
    parser.setMappingsRegistry(new DefaultMappingsRegistry(model1, model2));
    parser.ignoreNewLines(true);

    MockContentHandler handler;
   
    handler = new MockContentHandler();
        NamespaceDeclarationStack namespaceDeclarationStack = new NamespaceDeclarationStack(parser);
        parser.setContentHandler(new NamespaceAwareHandler(handler, namespaceDeclarationStack));

    try {
      parser.parse(new InputSource(getClass().getResourceAsStream("unedifact-msg-03.edi")));
      fail("Expected EDIParseException");
    } catch(EDIParseException e) {
      assertEquals("EDI message processing failed [EDI Message Interchange Control Model][N/A].  Segment [UNG], field 5 (groupRef) expected to contain a value.  Currently at segment number 2.", e.getMessage());
    }
  }
View Full Code Here

  public void test_full_group_header() throws IOException, SAXException, EDIConfigurationException {
    EdifactModel model1 = EDIParser.parseMappingModel(getClass().getResourceAsStream("../MSG1-model.xml"));
    EdifactModel model2 = EDIParser.parseMappingModel(getClass().getResourceAsStream("../MSG2-model.xml"));
   
    UNEdifactInterchangeParser parser = new UNEdifactInterchangeParser();
    parser.setMappingsRegistry(new DefaultMappingsRegistry(model1, model2));
    parser.ignoreNewLines(true);

    MockContentHandlerNS handler;
   
    // Test message 01 - no UNA segment...
    handler = new MockContentHandlerNS();
        NamespaceDeclarationStack namespaceDeclarationStack = new NamespaceDeclarationStack(parser);
        parser.setContentHandler(new NamespaceAwareHandler(handler, namespaceDeclarationStack));
    parser.parse(new InputSource(getClass().getResourceAsStream("unedifact-msg-04.edi")));
    //System.out.println(handler.xmlMapping);
        XMLUnit.setIgnoreWhitespace( true );
        XMLAssert.assertXMLEqual(new InputStreamReader(getClass().getResourceAsStream("unedifact-msg-expected-02.xml")), new StringReader(handler.xmlMapping.toString()));
  }
View Full Code Here

  public void test_with_unknown_ucd_segment() throws IOException, SAXException, EDIConfigurationException {
    EdifactModel model1 = EDIParser.parseMappingModel(getClass().getResourceAsStream("../MSG1-model.xml"));
    EdifactModel model2 = EDIParser.parseMappingModel(getClass().getResourceAsStream("../MSG2-model.xml"));
   
    UNEdifactInterchangeParser parser = new UNEdifactInterchangeParser();
    parser.setMappingsRegistry(new DefaultMappingsRegistry(model1, model2));
    parser.ignoreNewLines(true);

    MockContentHandler handler;
   
    // Test message 01 - no UNA segment...
    handler = new MockContentHandler();
        NamespaceDeclarationStack namespaceDeclarationStack = new NamespaceDeclarationStack(parser);
        parser.setContentHandler(new NamespaceAwareHandler(handler, namespaceDeclarationStack));
    parser.parse(new InputSource(getClass().getResourceAsStream("unedifact-msg-05.edi")));
//    System.out.println(handler.xmlMapping);
        XMLUnit.setIgnoreWhitespace( true );
        XMLAssert.assertXMLEqual(new InputStreamReader(getClass().getResourceAsStream("unedifact-msg-expected-03.xml")), new StringReader(handler.xmlMapping.toString()));
  }
View Full Code Here

  public void test_unzipped() throws IOException, SAXException, EDIConfigurationException {
    EdifactModel model1 = EDIParser.parseMappingModel(getClass().getResourceAsStream("../MSG1-model.xml"));
    EdifactModel model2 = EDIParser.parseMappingModel(getClass().getResourceAsStream("../MSG2-model.xml"));
   
    UNEdifactInterchangeParser parser = new UNEdifactInterchangeParser();
    parser.setMappingsRegistry(new DefaultMappingsRegistry(model1, model2));

    testExchanges(parser);
  }
View Full Code Here

    testExchanges(parser);
  }

  public void test_zipped() throws IOException, SAXException, EDIConfigurationException {
    createZip();
    UNEdifactInterchangeParser parser = new UNEdifactInterchangeParser();
    parser.setMappingsRegistry(new DefaultMappingsRegistry("mapping-models.zip", URI.create("./target")));
    testExchanges(parser);
  }
View Full Code Here

 
  private void parseAndValidate(InputStream inputStream) throws IOException,
      SAXException, SAXNotRecognizedException, SAXNotSupportedException {
    assertNotNull(inputStream);
    UNEdifactInterchangeParser parser = new UNEdifactInterchangeParser();
    parser.setFeature(EDIParser.FEATURE_IGNORE_NEWLINES, true);
    SAXHandler handler = new SAXHandler();
    parser.setContentHandler(handler);
    parser.parse(new InputSource(inputStream));
    Document doc = handler.getDocument();
    // Here you have your document
    StringWriter xmlWriter = new StringWriter();
    new XMLOutputter(Format.getPrettyFormat()).output(doc, xmlWriter);
    String xml = xmlWriter.getBuffer().toString();
View Full Code Here

TOP

Related Classes of org.milyn.edisax.unedifact.UNEdifactInterchangeParser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.