Package org.apache.tuscany.databinding.sdo

Source Code of org.apache.tuscany.databinding.sdo.ImportSDOLoaderTestCase$MockFactory

/*
* 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.tuscany.databinding.sdo;

import java.io.StringReader;

import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;

import junit.framework.TestCase;

import org.apache.tuscany.core.deployer.RootDeploymentContext;
import org.apache.tuscany.databinding.sdo.ImportSDOLoader.SDOType;
import org.apache.tuscany.spi.deployer.DeploymentContext;
import org.apache.tuscany.spi.loader.LoaderException;

/**
* @version $Rev: 464402 $ $Date: 2006-10-16 00:01:18 -0700 (Mon, 16 Oct 2006) $
*/
public class ImportSDOLoaderTestCase extends TestCase {
    private static boolean inited;

    private ImportSDOLoader loader;
    private XMLInputFactory xmlFactory;
    private DeploymentContext deploymentContext;

    public void testMinimal() throws XMLStreamException, LoaderException {
        String xml = "<import.sdo xmlns='http://incubator.apache.org/tuscany/xmlns/databinding/sdo/1.0-incubator-M2'/>";
        XMLStreamReader reader = getReader(xml);
        assertTrue(loader.load(null, reader, deploymentContext) instanceof SDOType);
    }

    public void testLocation() throws XMLStreamException, LoaderException {
        String xml = "<import.sdo xmlns='http://incubator.apache.org/tuscany/xmlns/databinding/sdo/1.0-incubator-M2' location='ipo.xsd'/>";
        XMLStreamReader reader = getReader(xml);
        assertTrue(loader.load(null, reader, deploymentContext) instanceof SDOType);
    }
   
    public void testFactory() throws XMLStreamException, LoaderException {
        String xml = "<import.sdo xmlns='http://incubator.apache.org/tuscany/xmlns/databinding/sdo/1.0-incubator-M2' "
                + "factory='org.apache.tuscany.databinding.sdo.ImportSDOLoaderTestCase$MockFactory'/>";
        XMLStreamReader reader = getReader(xml);
        assertFalse(inited);
        assertTrue(loader.load(null, reader, deploymentContext) instanceof SDOType);
        assertTrue(inited);
    }

    protected void setUp() throws Exception {
        super.setUp();
        loader = new ImportSDOLoader(null);
        xmlFactory = XMLInputFactory.newInstance();
        deploymentContext = new RootDeploymentContext(getClass().getClassLoader(), xmlFactory, null, null);
    }

    protected XMLStreamReader getReader(String xml) throws XMLStreamException {
        XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(xml));
        reader.next();
        return reader;
    }

    public static class MockFactory {
        public static final Object INSTANCE = null;

        static {
            ImportSDOLoaderTestCase.inited = true;
        }
    }
}

TOP

Related Classes of org.apache.tuscany.databinding.sdo.ImportSDOLoaderTestCase$MockFactory

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.