1   /*
2    * Copyright 2005-2010 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 org.junit.Assert;
23  import org.junit.Before;
24  import org.junit.Test;
25  
26  public class SoapFaultDefinitionEditorTest {
27  
28      private SoapFaultDefinitionEditor editor;
29  
30      @Before
31      public void setUp() throws Exception {
32          editor = new SoapFaultDefinitionEditor();
33      }
34  
35      @Test
36      public void testSetAsTextNoLocale() throws Exception {
37          editor.setAsText("Server, Server error");
38          SoapFaultDefinition definition = (SoapFaultDefinition) editor.getValue();
39          Assert.assertNotNull("fault not set", definition);
40          Assert.assertEquals("Invalid fault code", new QName("Server"), definition.getFaultCode());
41          Assert.assertEquals("Invalid fault string", "Server error", definition.getFaultStringOrReason());
42          Assert.assertEquals("Invalid fault string locale", Locale.ENGLISH, definition.getLocale());
43      }
44  
45      @Test
46      public void testSetAsTextLocale() throws Exception {
47          editor.setAsText("Server, Server error, nl");
48          SoapFaultDefinition definition = (SoapFaultDefinition) editor.getValue();
49          Assert.assertNotNull("fault not set", definition);
50          Assert.assertEquals("Invalid fault code", new QName("Server"), definition.getFaultCode());
51          Assert.assertEquals("Invalid fault string", "Server error", definition.getFaultStringOrReason());
52          Assert.assertEquals("Invalid fault string locale", new Locale("nl"), definition.getLocale());
53      }
54  
55      @Test
56      public void testSetAsTextSender() throws Exception {
57          editor.setAsText("SENDER, Server error");
58          SoapFaultDefinition definition = (SoapFaultDefinition) editor.getValue();
59          Assert.assertNotNull("fault not set", definition);
60          Assert.assertEquals("Invalid fault code", SoapFaultDefinition.SENDER, definition.getFaultCode());
61          Assert.assertEquals("Invalid fault string", "Server error", definition.getFaultStringOrReason());
62      }
63  
64      @Test
65      public void testSetAsTextReceiver() throws Exception {
66          editor.setAsText("RECEIVER, Server error");
67          SoapFaultDefinition definition = (SoapFaultDefinition) editor.getValue();
68          Assert.assertNotNull("fault not set", definition);
69          Assert.assertEquals("Invalid fault code", SoapFaultDefinition.RECEIVER, definition.getFaultCode());
70          Assert.assertEquals("Invalid fault string", "Server error", definition.getFaultStringOrReason());
71      }
72  
73      @Test
74      public void testSetAsTextIllegalArgument() throws Exception {
75          try {
76              editor.setAsText("SOAP-ENV:Server");
77          }
78          catch (IllegalArgumentException ex) {
79          }
80      }
81  
82      @Test
83      public void testSetAsTextEmpty() throws Exception {
84          editor.setAsText("");
85          Assert.assertNull("definition not set to null", editor.getValue());
86      }
87  }