jp.terasoluna.fw.beans.jxpath.DynamicPointerFactoryExTest.java Source code

Java tutorial

Introduction

Here is the source code for jp.terasoluna.fw.beans.jxpath.DynamicPointerFactoryExTest.java

Source

/*
 * Copyright (c) 2007 NTT DATA Corporation
 *
 * Licensed 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 jp.terasoluna.fw.beans.jxpath;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;

import java.util.HashMap;
import java.util.Locale;

import org.apache.commons.jxpath.ri.QName;
import org.apache.commons.jxpath.ri.model.NodePointer;
import org.apache.commons.jxpath.ri.model.beans.NullPointer;
import org.junit.Test;
import org.springframework.test.util.ReflectionTestUtils;

/**
 * {@link jp.terasoluna.fw.beans.jxpath.DynamicPointerFactoryEx} ?
 * <p>
 * <h4>???</h4> Map??<br>
 * ????
 * <p>
 * @see jp.terasoluna.fw.beans.jxpath.DynamicPointerFactoryEx
 */
public class DynamicPointerFactoryExTest {

    /**
     * testGetOrder01() <br>
     * <br>
     * () <br>
     * A <br>
     * <br>
     *  <br>
     * () -:750<br>
     * <br>
     * ??? <br>
     * @throws Exception ?????
     */
    @Test
    public void testGetOrder01() throws Exception {
        // ??
        DynamicPointerFactoryEx factory = new DynamicPointerFactoryEx();

        // 
        assertEquals(750, factory.getOrder());
    }

    /**
     * testCreateNodePointerQname01() <br>
     * <br>
     * () <br>
     * A <br>
     * <br>
     * () name:not null<br>
     * () bean:new HashMap() {<br>
     * key="value"<br>
     * }<br>
     * () locale:Locale("ja")<br>
     * () bi.isDynamic():true<br>
     * <br>
     * () NodePointer:new DynamicPointerEX {<br>
     * locale=?locale<br>
     * name=?name<br>
     * bean=?bean<br>
     * }<br>
     * <br>
     * Map?? <br>
     * @throws Exception ?????
     */
    @Test
    public void testCreateNodePointerQname01() throws Exception {
        // ??
        DynamicPointerFactoryEx factory = new DynamicPointerFactoryEx();
        QName qName = new QName("name");
        Object bean = new HashMap<Object, Object>();
        Locale locale = new Locale("ja");

        // 
        NodePointer result = factory.createNodePointer(qName, bean, locale);

        // 
        assertSame(DynamicPointerEx.class, result.getClass());
        assertSame(locale, result.getLocale());
        assertSame(qName, result.getName());
        assertSame(bean, ReflectionTestUtils.getField(result, "bean"));
    }

    /**
     * testCreateNodePointerQname02() <br>
     * <br>
     * () <br>
     * A <br>
     * <br>
     * () name:not null<br>
     * () bean:new Object()<br>
     * () locale:Locale("ja")<br>
     * () bi.isDynamic():false<br>
     * <br>
     * () NodePointer:null<br>
     * <br>
     * Map?????Null? <br>
     * @throws Exception ?????
     */
    @Test
    public void testCreateNodePointerQname02() throws Exception {
        // ??
        DynamicPointerFactoryEx factory = new DynamicPointerFactoryEx();
        QName qName = new QName("name");
        Object bean = new Object();
        Locale locale = new Locale("ja");

        // 
        assertNull(factory.createNodePointer(qName, bean, locale));
    }

    /**
     * testCreateNodePointerNodePointer01() <br>
     * <br>
     * () <br>
     * A <br>
     * <br>
     * () parent:not null<br>
     * () name:not null<br>
     * () bean:null<br>
     * <br>
     * () NodePointer:new NullPointer {<br>
     * parent=?parent<br>
     * name=?name<br>
     * }<br>
     * <br>
     * ?null??? <br>
     * @throws Exception ?????
     */
    @Test
    public void testCreateNodePointerNodePointer01() throws Exception {
        // ??
        DynamicPointerFactoryEx factory = new DynamicPointerFactoryEx();
        QName qName = new QName("name");
        Locale locale = new Locale("ja");
        NodePointer nodePointer = NodePointer.newNodePointer(qName, null, locale);

        // 
        NodePointer result = factory.createNodePointer(nodePointer, qName, null);

        // 
        assertSame(NullPointer.class, result.getClass());
        assertSame(qName, result.getName());
        assertSame(nodePointer, result.getParent());
    }

    /**
     * testCreateNodePointerNodePointer02() <br>
     * <br>
     * () <br>
     * A <br>
     * <br>
     * () parent:not null<br>
     * () name:not null<br>
     * () bean:new HashMap() {<br>
     * key="value"<br>
     * }<br>
     * () bi.isDynamic():true<br>
     * <br>
     * () NodePointer:new DynamicPointerEX {<br>
     * parent=?parent<br>
     * name=?name<br>
     * bean=?bean<br>
     * }<br>
     * <br>
     * Map?? <br>
     * @throws Exception ?????
     */
    @Test
    public void testCreateNodePointerNodePointer02() throws Exception {
        // ??
        DynamicPointerFactoryEx factory = new DynamicPointerFactoryEx();
        QName qName = new QName("name");
        Object bean = new HashMap<Object, Object>();

        Locale locale = new Locale("ja");
        NodePointer nodePointer = NodePointer.newNodePointer(qName, bean, locale);

        // 
        NodePointer result = factory.createNodePointer(nodePointer, qName, bean);

        // 
        assertSame(DynamicPointerEx.class, result.getClass());
        assertSame(nodePointer, result.getParent());
        assertSame(qName, result.getName());
        assertSame(bean, ReflectionTestUtils.getField(result, "bean"));
    }

    /**
     * testCreateNodePointerNodePointer03() <br>
     * <br>
     * () <br>
     * A <br>
     * <br>
     * () parent:not null<br>
     * () name:not null<br>
     * () bean:new Object()<br>
     * () bi.isDynamic():false<br>
     * <br>
     * () NodePointer:null<br>
     * <br>
     * Map?????Null? <br>
     * @throws Exception ?????
     */
    @Test
    public void testCreateNodePointerNodePointer03() throws Exception {
        // ??
        DynamicPointerFactoryEx factory = new DynamicPointerFactoryEx();
        QName qName = new QName("name");
        Object bean = new Object();

        Locale locale = new Locale("ja");
        NodePointer nodePointer = NodePointer.newNodePointer(qName, bean, locale);

        // 
        assertNull(factory.createNodePointer(nodePointer, qName, bean));
    }

}