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

Java tutorial

Introduction

Here is the source code for jp.terasoluna.fw.beans.jxpath.BeanPropertyPointerExTest.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.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.Locale;

import org.apache.commons.jxpath.JXPathBasicBeanInfo;
import org.apache.commons.jxpath.ri.QName;
import org.apache.commons.jxpath.ri.model.NodePointer;
import org.junit.Test;

/**
 * {@link jp.terasoluna.fw.beans.jxpath.BeanPropertyPointerEx} ?
 * 
 * <p>
 * <h4>???</h4>
 * null????Bean?<br>
 * ????
 * <p>
 * 
 * @see jp.terasoluna.fw.beans.jxpath.BeanPropertyPointerEx
 */
public class BeanPropertyPointerExTest {

    /**
     * testGetLength01()
     * <br><br>
     * 
     * ()
     * <br>
     * A
     * <br><br>
     * () super.getLength():1<br>
     *         
     * <br>
     * () -:1<br>
     *         
     * <br>
     * ???
     * <br>
     * 
     * @throws Exception ?????
     */
    @Test
    public void testGetLength01() throws Exception {
        // ??
        QName qName = new QName("property");
        BeanPropertyPointerEx_JavaBeanStub01 bean = new BeanPropertyPointerEx_JavaBeanStub01();
        Locale locale = new Locale("ja");
        NodePointer nodePointer = NodePointer.newNodePointer(qName, bean, locale);

        JXPathBasicBeanInfo beanInfo = new JXPathBasicBeanInfo(bean.getClass());
        BeanPropertyPointerEx pointer = new BeanPropertyPointerEx(nodePointer, beanInfo);
        pointer.setPropertyName("property");

        // 
        assertEquals(1, pointer.getLength());
    }

    /**
     * testGetLength02()
     * <br><br>
     * 
     * ()
     * <br>
     * A
     * <br><br>
     * () super.getLength():0<br>
     *         () getBaseValue():null<br>
     *         
     * <br>
     * () -:1<br>
     *         
     * <br>
     * ?????null???
     * <br>
     * 
     * @throws Exception ?????
     */
    @Test
    public void testGetLength02() throws Exception {
        // ??
        QName qName = new QName("property");
        BeanPropertyPointerEx_JavaBeanStub01 bean = new BeanPropertyPointerEx_JavaBeanStub01();
        bean.setListProperty(null);
        Locale locale = new Locale("ja");
        NodePointer nodePointer = NodePointer.newNodePointer(qName, bean, locale);

        JXPathBasicBeanInfo beanInfo = new JXPathBasicBeanInfo(bean.getClass());
        BeanPropertyPointerEx pointer = new BeanPropertyPointerEx(nodePointer, beanInfo);
        pointer.setPropertyName("listProperty");

        // 
        assertEquals(1, pointer.getLength());
    }

    /**
     * testGetLength03()
     * <br><br>
     * 
     * ()
     * <br>
     * C
     * <br><br>
     * () super.getLength():0<br>
     *         () getBaseValue():not null<br>
     *         
     * <br>
     * () -:0<br>
     *         
     * <br>
     * ?????not null????
     * <br>
     * 
     * @throws Exception ?????
     */
    @Test
    public void testGetLength03() throws Exception {
        // ??
        QName qName = new QName("property");
        BeanPropertyPointerEx_JavaBeanStub01 bean = new BeanPropertyPointerEx_JavaBeanStub01();
        Locale locale = new Locale("ja");
        NodePointer nodePointer = NodePointer.newNodePointer(qName, bean, locale);

        JXPathBasicBeanInfo beanInfo = new JXPathBasicBeanInfo(bean.getClass());
        BeanPropertyPointerEx pointer = new BeanPropertyPointerEx(nodePointer, beanInfo);
        pointer.setPropertyName("listProperty");

        // 
        assertEquals(0, pointer.getLength());
    }

    /**
     * testIsCollection01()
     * <br><br>
     * 
     * ()
     * <br>
     * C
     * <br><br>s
     * () getBaseValue():null<br>
     *         
     * <br>
     * () boolean:false<br>
     *         
     * <br>
     * ?null???False?
     * <br>
     * 
     * @throws Exception ?????
     */
    @Test
    public void testIsCollection01() throws Exception {
        // ??
        QName qName = new QName("property");
        BeanPropertyPointerEx_JavaBeanStub01 bean = new BeanPropertyPointerEx_JavaBeanStub01();
        Locale locale = new Locale("ja");
        NodePointer nodePointer = NodePointer.newNodePointer(qName, bean, locale);

        JXPathBasicBeanInfo beanInfo = new JXPathBasicBeanInfo(bean.getClass());
        BeanPropertyPointerEx pointer = new BeanPropertyPointerEx(nodePointer, beanInfo);
        pointer.setPropertyName("property");

        // 
        assertFalse(pointer.isCollection());
    }

    /**
     * testIsCollection02()
     * <br><br>
     * 
     * ()
     * <br>
     * A
     * <br><br>
     * () getBaseValue():not null<br>
     *         () super.isCollection():?????<br>
     *         
     * <br>
     * () boolean:super.isCollection()??<br>
     *         
     * <br>
     * ?null??????Super.isCollection()??
     * <br>
     * 
     * @throws Exception ?????
     */
    @Test
    public void testIsCollection02() throws Exception {
        // ??
        QName qName = new QName("property");
        BeanPropertyPointerEx_JavaBeanStub01 bean = new BeanPropertyPointerEx_JavaBeanStub01();
        Locale locale = new Locale("ja");
        NodePointer nodePointer = NodePointer.newNodePointer(qName, bean, locale);

        JXPathBasicBeanInfo beanInfo = new JXPathBasicBeanInfo(bean.getClass());
        BeanPropertyPointerEx pointer = new BeanPropertyPointerEx(nodePointer, beanInfo);
        pointer.setPropertyName("listProperty");

        // 
        assertTrue(pointer.isCollection());
    }

}