1   /*
2    * Copyright 2005 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.ws.soap.server.endpoint;
18  
19  import java.util.Locale;
20  import javax.xml.namespace.QName;
21  
22  import junit.framework.TestCase;
23  
24  public class SoapFaultDefinitionEditorTest extends TestCase {
25  
26      private SoapFaultDefinitionEditor editor;
27  
28      protected void setUp() throws Exception {
29          editor = new SoapFaultDefinitionEditor();
30      }
31  
32      public void testSetAsTextNoLocale() throws Exception {
33          editor.setAsText("Server, Server error");
34          SoapFaultDefinition definition = (SoapFaultDefinition) editor.getValue();
35          assertNotNull("fault not set", definition);
36          assertEquals("Invalid fault code", new QName("Server"), definition.getFaultCode());
37          assertEquals("Invalid fault string", "Server error", definition.getFaultStringOrReason());
38          assertEquals("Invalid fault string locale", Locale.ENGLISH, definition.getLocale());
39      }
40  
41      public void testSetAsTextLocale() throws Exception {
42          editor.setAsText("Server, Server error, nl");
43          SoapFaultDefinition definition = (SoapFaultDefinition) editor.getValue();
44          assertNotNull("fault not set", definition);
45          assertEquals("Invalid fault code", new QName("Server"), definition.getFaultCode());
46          assertEquals("Invalid fault string", "Server error", definition.getFaultStringOrReason());
47          assertEquals("Invalid fault string locale", new Locale("nl"), definition.getLocale());
48      }
49  
50      public void testSetAsTextSender() throws Exception {
51          editor.setAsText("SENDER, Server error");
52          SoapFaultDefinition definition = (SoapFaultDefinition) editor.getValue();
53          assertNotNull("fault not set", definition);
54          assertEquals("Invalid fault code", SoapFaultDefinition.SENDER, definition.getFaultCode());
55          assertEquals("Invalid fault string", "Server error", definition.getFaultStringOrReason());
56      }
57  
58      public void testSetAsTextReceiver() throws Exception {
59          editor.setAsText("RECEIVER, Server error");
60          SoapFaultDefinition definition = (SoapFaultDefinition) editor.getValue();
61          assertNotNull("fault not set", definition);
62          assertEquals("Invalid fault code", SoapFaultDefinition.RECEIVER, definition.getFaultCode());
63          assertEquals("Invalid fault string", "Server error", definition.getFaultStringOrReason());
64      }
65  
66      public void testSetAsTextIllegalArgument() throws Exception {
67          try {
68              editor.setAsText("SOAP-ENV:Server");
69          }
70          catch (IllegalArgumentException ex) {
71          }
72      }
73  
74      public void testSetAsTextEmpty() throws Exception {
75          editor.setAsText("");
76          assertNull("definition not set to null", editor.getValue());
77      }
78  }