SoapFaultDefinitionEditor extends PropertyEditorSupport { @Override public void setAsText(String text) throws IllegalArgumentException { if (!StringUtils.hasLength(text)) { setValue(null); } else { String[] tokens = StringUtils.commaDelimitedListToStringArray(text); if (tokens.length < FAULT_STRING_INDEX) { throw new IllegalArgumentException("Invalid amount of comma delimited values in [" + text + "]: SoapFaultDefinitionEditor requires at least 1"); } SoapFaultDefinition definition = new SoapFaultDefinition(); QNameEditor qNameEditor = new QNameEditor(); qNameEditor.setAsText(tokens[FAULT_CODE_INDEX].trim()); definition.setFaultCode((QName) qNameEditor.getValue()); if (tokens.length > 1) { definition.setFaultStringOrReason(tokens[FAULT_STRING_INDEX].trim()); if (tokens.length > 2) { LocaleEditor localeEditor = new LocaleEditor(); localeEditor.setAsText(tokens[FAULT_STRING_LOCALE_INDEX].trim()); definition.setLocale((Locale) localeEditor.getValue()); } } setValue(definition); } }  @Override void setAsText(String text);  }
@Test public void testSetAsTextNoLocale() throws Exception { editor.setAsText("Server, Server error"); SoapFaultDefinition definition = (SoapFaultDefinition) editor.getValue(); Assert.assertNotNull("fault not set", definition); Assert.assertEquals("Invalid fault code", new QName("Server"), definition.getFaultCode()); Assert.assertEquals("Invalid fault string", "Server error", definition.getFaultStringOrReason()); Assert.assertEquals("Invalid fault string locale", Locale.ENGLISH, definition.getLocale()); }
@Test public void testSetAsTextLocale() throws Exception { editor.setAsText("Server, Server error, nl"); SoapFaultDefinition definition = (SoapFaultDefinition) editor.getValue(); Assert.assertNotNull("fault not set", definition); Assert.assertEquals("Invalid fault code", new QName("Server"), definition.getFaultCode()); Assert.assertEquals("Invalid fault string", "Server error", definition.getFaultStringOrReason()); Assert.assertEquals("Invalid fault string locale", new Locale("nl"), definition.getLocale()); }
@Test public void testSetAsTextSender() throws Exception { editor.setAsText("SENDER, Server error"); SoapFaultDefinition definition = (SoapFaultDefinition) editor.getValue(); Assert.assertNotNull("fault not set", definition); Assert.assertEquals("Invalid fault code", SoapFaultDefinition.SENDER, definition.getFaultCode()); Assert.assertEquals("Invalid fault string", "Server error", definition.getFaultStringOrReason()); }
@Test public void testSetAsTextReceiver() throws Exception { editor.setAsText("RECEIVER, Server error"); SoapFaultDefinition definition = (SoapFaultDefinition) editor.getValue(); Assert.assertNotNull("fault not set", definition); Assert.assertEquals("Invalid fault code", SoapFaultDefinition.RECEIVER, definition.getFaultCode()); Assert.assertEquals("Invalid fault string", "Server error", definition.getFaultStringOrReason()); }
@Test public void testSetAsTextIllegalArgument() throws Exception { try { editor.setAsText("SOAP-ENV:Server"); } catch (IllegalArgumentException ex) {} }
@Test public void testSetAsTextEmpty() throws Exception { editor.setAsText(""); Assert.assertNull("definition not set to null", editor.getValue()); }