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

Axis 2 example source code file (JAXBContextTest.java)

This example Axis 2 source code file (JAXBContextTest.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

jaxbcontext, jaxbcontext, jaxbcontexttest, jaxbexception, jaxbexception, testcase, testcase, treeset, treeset, util

The Axis 2 JAXBContextTest.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.jaxws.misc;

import java.util.TreeSet;
import java.util.Set;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;

import org.apache.axis2.jaxws.message.databinding.JAXBUtils;
import org.apache.axis2.jaxws.utility.JavaUtils;

import junit.framework.TestCase;

/**
 * Tests Namespace to Package Algorithmh
 *
 */
public class JAXBContextTest extends TestCase {

    /**
     * Test basic functionality of JAXBUtils pooling
     * @throws Exception
     */
    public void test01() throws JAXBException {
        
        // Get a JAXBContext
        TreeSet<String> context1 = new TreeSet();
        context1.add("org.test.addnumbers");
        context1.add("org.test.anytype");
        
        JAXBContext jaxbContext1 = JAXBUtils.getJAXBContext(context1);
        
        // Assert that the JAXBContext was found and the context contains the two valid packages
        assertTrue(jaxbContext1 != null);
        assertTrue(context1.contains("org.test.addnumbers"));
        assertTrue(context1.contains("org.test.anytype"));
        
        // Repeat with the same packages
        TreeSet<String> context2 = new TreeSet();
        context2.add("org.test.addnumbers");
        context2.add("org.test.anytype");
        
        JAXBContext jaxbContext2 = JAXBUtils.getJAXBContext(context2);
        
        // The following assertion is probably true,but GC may have wiped out the weak reference
        //assertTrue(jaxbContext2 == jaxbContext1);
        assertTrue(jaxbContext2 != null);
        assertTrue(jaxbContext2.toString().equals(jaxbContext1.toString()));
        assertTrue(context2.contains("org.test.addnumbers"));
        assertTrue(context2.contains("org.test.anytype"));
        
        // Repeat with the same packages + an invalid package
        TreeSet<String> context3 = new TreeSet();
        context3.add("org.test.addnumbers");
        context3.add("org.test.anytype");
        context3.add("my.grandma.loves.jaxws");
        
        JAXBContext jaxbContext3 = JAXBUtils.getJAXBContext(context3);
        
        // The following assertion is probably true,but GC may have wiped out the weak reference
        //assertTrue(jaxbContext3 == jaxbContext1);
        assertTrue(jaxbContext3 != null);
        assertTrue(jaxbContext1.toString().equals(jaxbContext1.toString()));
        assertTrue(context3.contains("org.test.addnumbers"));
        assertTrue(context3.contains("org.test.anytype")); 
        // TODO FIXME - does not work under m2/surefire
//        assertTrue(!context3.contains("my.grandma.loves.jaxws"));  // invalid package should be silently removed
        
        // Repeat with a subset of packages
        TreeSet<String> context4 = new TreeSet();
        context4.add("org.test.addnumbers");
        
        
        JAXBContext jaxbContext4 = JAXBUtils.getJAXBContext(context4);
        
        assertTrue(jaxbContext4 != null);
        assertTrue(jaxbContext4 != jaxbContext3);
        assertTrue(context4.contains("org.test.addnumbers"));
        
       
    }
}

Other Axis 2 examples (source code examples)

Here is a short list of links related to this Axis 2 JAXBContextTest.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.