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;
18  
19  import java.util.Iterator;
20  import javax.xml.namespace.QName;
21  import javax.xml.transform.Transformer;
22  import javax.xml.transform.TransformerFactory;
23  
24  import org.junit.Assert;
25  import org.junit.Before;
26  import org.junit.Test;
27  
28  public abstract class AbstractSoapElementTestCase {
29  
30      private SoapElement soapElement;
31  
32      protected Transformer transformer;
33  
34      @Before
35      public final void setUp() throws Exception {
36          TransformerFactory transformerFactory = TransformerFactory.newInstance();
37          transformer = transformerFactory.newTransformer();
38          soapElement = createSoapElement();
39      }
40  
41      protected abstract SoapElement createSoapElement() throws Exception;
42  
43      @Test
44      public void testAttributes() throws Exception {
45          QName name = new QName("http://springframework.org/spring-ws", "attribute");
46          String value = "value";
47          soapElement.addAttribute(name, value);
48          Assert.assertEquals("Invalid attribute value", value, soapElement.getAttributeValue(name));
49          Iterator<QName> allAttributes = soapElement.getAllAttributes();
50          Assert.assertTrue("Iterator is empty", allAttributes.hasNext());
51      }
52  
53      @Test
54      public void testAddNamespaceDeclaration() throws Exception {
55          String prefix = "p";
56          String namespace = "http://springframework.org/spring-ws";
57          soapElement.addNamespaceDeclaration(prefix, namespace);
58      }
59  
60      @Test
61      public void testAddDefaultNamespaceDeclaration() throws Exception {
62          String prefix = "";
63          String namespace = "http://springframework.org/spring-ws";
64          soapElement.addNamespaceDeclaration(prefix, namespace);
65      }
66  
67  
68  }