SyntaxBranchingService extends BranchingServiceImp { public void setSyntaxIdentifiers(List<SyntaxIdentifier> l) { syntaxIdentifiers = Args.notNull(l, "identifiers"); }  void doService(AdaptrisMessage msg); void addSyntaxIdentifier(SyntaxIdentifier ident); List<SyntaxIdentifier> getSyntaxIdentifiers(); void setSyntaxIdentifiers(List<SyntaxIdentifier> l); @Override void prepare();  }
@Test public void testDoServiceFirstMatch() throws Exception { SyntaxBranchingService sbs = new SyntaxBranchingService(); sbs.setSyntaxIdentifiers(createStandardIdentifiers()); AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("GU34 1ET"); execute(sbs, msg); assertEquals("isPostcode", msg.getNextServiceId()); }
@Test public void testDoServiceSecondMatch() throws Exception { SyntaxBranchingService sbs = new SyntaxBranchingService(); sbs.setSyntaxIdentifiers(createStandardIdentifiers()); AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage( "<document><envelope>ENVELOPE</envelope><content>CONTENT</content></document>"); execute(sbs, msg); assertEquals("isXml", msg.getNextServiceId()); }
@Test public void testDoServiceNoMatch() throws Exception { SyntaxBranchingService sbs = new SyntaxBranchingService(); sbs.setSyntaxIdentifiers(createStandardIdentifiers()); AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("The quick brown fox"); try { execute(sbs, msg); fail(); } catch (ServiceException e) { assertEquals("Unable to identify the message syntax to branch on", e.getMessage()); } }