/**
 * Copyright 2006 Apache Software Foundation 
 *
 * 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 org.apache.woden.wsdl20.xml;

import java.net.URI;

import javax.xml.namespace.QName;

import org.apache.woden.internal.wsdl20.DescriptionImpl;
import org.apache.woden.wsdl20.Description;
import org.apache.woden.wsdl20.Interface;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

/**
 * Setting values on some of the classes in the Element API should cause
 * side effects in the component model. 
 * 
 * @author hughesj@apache.org
 */
public class SideEffectsTest extends TestCase {

    public static Test suite() {
        return new TestSuite(SideEffectsTest.class);
    }

    protected void setUp() throws Exception {

    }
    
    public void testSetTargetNamespace() throws Exception {
        // Set up a description
        Description desc = new DescriptionImpl();
        DescriptionElement descElem = desc.toElement();
        descElem.setTargetNamespace(new URI("http://sample1.org"));
        InterfaceElement ie = descElem.createInterfaceElement();
        QName interfaceName = new QName("http://sample1.org", "interfacelocalpart"); 
        ie.setName(interfaceName);
        descElem.addInterfaceElement(ie);
        
        // Check things are all ok from the component model
        // Note: create new QName in case getInterface() uses == instead of .equals to
        //       lookup interface objects
        QName lookupInterfaceName = new QName("http://sample1.org", "interfacelocalpart");
        Interface ifComp = desc.getInterface(lookupInterfaceName);
        assertTrue("Incorrect interface component returned", ifComp.getName().equals(lookupInterfaceName));
        
        // Now change the targetNamespace of the description element
        descElem.setTargetNamespace(new URI("http://sample2.org"));
        
        // Now see if the namespace URI of the interface component's
        // (QName) name has changed
        assertTrue("Incorrect namespace of Interface component name", ifComp.getName().equals(new QName("http://sample2.org", "interfacelocalpart")));
    }
}
