As2Disposition { public static As2Disposition valueOf(String s) { String str = s == null ? "" : s.trim(); Matcher matcher = pattern.matcher(str); if (!matcher.matches()) { throw new IllegalArgumentException("'" + str + "'" + " does not match pattern for As2Disposition"); } String actionModeString = matcher.group(1); ActionMode actionMode = ActionMode.createFromTextValue(actionModeString); String sendingModeString = matcher.group(2); SendingMode sendingMode = SendingMode.createFromTextValue(sendingModeString); String dispositionTypeString = matcher.group(3); DispositionType dispositionType = DispositionType.valueOf(dispositionTypeString.toUpperCase()); As2Disposition result; if (matcher.group(4) != null) { DispositionModifier dispositionModifier; String dispositionModifierPrefixString = matcher.group(5); String dispositionModifierString = matcher.group(6); dispositionModifier = new DispositionModifier(DispositionModifier.Prefix.valueOf(dispositionModifierPrefixString.toUpperCase()), dispositionModifierString); result = new As2Disposition(actionMode, sendingMode, dispositionType, dispositionModifier); } else { result = new As2Disposition(actionMode, sendingMode, dispositionType); } return result; } As2Disposition(ActionMode actionMode, SendingMode sendingMode, DispositionType dispositionType);  As2Disposition(ActionMode actionMode, SendingMode sendingMode, DispositionType dispositionType, DispositionModifier dispositionModifier); static As2Disposition processed(); static As2Disposition processedWithWarning(String warningMessage); static As2Disposition processedWithError(String errorMessage); static As2Disposition failed(String message); @Override String toString(); static As2Disposition valueOf(String s); static Pattern pattern; }
@Test public void parseWithValueOf() throws Exception { String s = "automatic-action/MdN-sent-automatically; processed/error: Unknown recipient"; As2Disposition as2Disposition = As2Disposition.valueOf(s); assertNotNull(as2Disposition); assertEquals(as2Disposition.getActionMode(), As2Disposition.ActionMode.AUTOMATIC); assertEquals(as2Disposition.getSendingMode(), As2Disposition.SendingMode.AUTOMATIC); assertEquals(as2Disposition.getDispositionType(), As2Disposition.DispositionType.PROCESSED); assertEquals(as2Disposition.getDispositionModifier().getPrefix(), As2Disposition.DispositionModifier.Prefix.ERROR); assertEquals(as2Disposition.getDispositionModifier().getDispositionModifierExtension(), "Unknown recipient"); }
@Test public void parseWithValueOfAdvanced() throws Exception { String s = "automatic-action/MDN-sent-automatically; processed/ERROR: Payload does not contain Standard Business Document Header "; As2Disposition as2Disposition = As2Disposition.valueOf(s); assertNotNull(as2Disposition); }
@Test(expectedExceptions = IllegalArgumentException.class) public void parseLongDispositionFromRealWorldTesting() { String s = "automatic-action/MDN-sent-automatically; processed\\Error: unexpected-error"; As2Disposition.valueOf(s); }
@Test public void parseLongDispositionFromRealWorldTestingFixed() { String s = " automatic-action/MDN-sent-automatically; processed/Error: unexpected-error "; As2Disposition unimaze = As2Disposition.valueOf(s); assertEquals(unimaze.getDispositionModifier().getDispositionModifierExtension(), "unexpected-error"); }
@Test(expectedExceptions = IllegalArgumentException.class) public void parseShortDispositionFromRealWorldTesting() { String s = "Disposition: \"disposition-mode\"; processed"; s = s.split("Disposition:")[1]; As2Disposition.valueOf(s); }