alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Axis 2 example source code file (NodeTest.java)

This example Axis 2 source code file (NodeTest.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Axis 2 tags/keywords

exception, exception, expected, illegalargumentexception, illegalargumentexception, nodetest, parent, soapbody, soapelement, soapelement, soapenvelope, soapheader, soapheader, soapmessage, util

The Axis 2 NodeTest.java source code

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.apache.axis2.saaj;

import junit.framework.TestCase;

import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPHeaderElement;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
import java.util.Iterator;

/**
 * 
 */
public class NodeTest extends TestCase {
    private SOAPMessage msg = null;
    private SOAPPart sp = null;
    private SOAPBody body = null;
    private SOAPEnvelope envelope = null;
    private SOAPHeader header = null;
    private SOAPHeaderElement headerEle = null;

    protected void setUp() throws Exception {
        msg = MessageFactory.newInstance().createMessage();
        sp = msg.getSOAPPart();
        envelope = sp.getEnvelope();
        body = envelope.getBody();
        header = envelope.getHeader();
        headerEle = header.addHeaderElement(envelope.createName("foo", "f", "foo-URI"));
        headerEle.setActor("actor-URI");
    }

    public void testDetachNode() {
        try {
            headerEle.detachNode();
            Iterator iterator = header.examineHeaderElements("actor-URI");
            assertFalse("SOAPHeader element is not detached - unexpected", iterator.hasNext());
        } catch (Exception e) {
            fail("Exception: " + e);
        }
    }

    public void testParentElement() {
        try {
            headerEle.detachNode();
            SOAPElement parentElement = headerEle.getParentElement();
            assertNull("Parent is not null : " + parentElement, parentElement);
        } catch (Exception e) {
            fail("Exception: " + e);
        }
    }

    public void testSetParentElement1() {
        try {
            headerEle.detachNode();
            headerEle.setParentElement(header);
            SOAPElement se = headerEle.getParentElement();
            assertTrue("SOAPHeader element not returned - unexpected",
                       se instanceof SOAPHeader);
            SOAPHeader sh = (SOAPHeader)se;
            assertTrue("SOAPHeader element does not match", sh.equals(header));
        } catch (Exception e) {
            fail("Exception: " + e);
        }
    }

    public void testSetParentElement2() {
        try {
            try {
                headerEle.setParentElement(body);
                fail("Expected IllegalArgumentException did not occur");
            } catch (IllegalArgumentException e) {
                assertTrue("Expected IllegalArgumentException occurred", true);
            }
        } catch (Exception e) {
            fail("Exception: " + e);
        }
    }

    public void testSetValue() {
        try {
            headerEle.addTextNode("foo-bar");
            String value = headerEle.getValue();
            assertNotNull(value);
            assertEquals("foo-bar", value);

            headerEle.setValue("foo-bar2");
            value = headerEle.getValue();
            assertNotNull(value);
            assertEquals("foo-bar2", value);
        } catch (Exception e) {
            e.printStackTrace();
            fail("Exception: " + e);
        }
    }
}

Other Axis 2 examples (source code examples)

Here is a short list of links related to this Axis 2 NodeTest.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.