/**
 * Copyright (c) 2017-2024 Linagora
 * 
 * This program/library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 2.1 of the License, or (at your
 * option) any later version.
 * 
 * This program/library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
 * for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program/library; If not, see http://www.gnu.org/licenses/
 * for the GNU Lesser General Public License version 2.1.
 */
package org.ow2.petals.binding.soap.util;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.net.URL;
import java.util.Collections;

import org.junit.Test;
import org.ow2.easywsdl.extensions.wsdl4complexwsdl.WSDL4ComplexWsdlFactory;
import org.ow2.easywsdl.extensions.wsdl4complexwsdl.api.Description;
import org.ow2.easywsdl.extensions.wsdl4complexwsdl.api.WSDL4ComplexWsdlException;

import com.ebmwebsourcing.easycommons.stream.EasyByteArrayOutputStream;

public class WsdlHelperTest {

    @Test
    public void printWSDL_withImports() throws WSDL4ComplexWsdlException, Exception {

        final String serviceAddress = "http://localhost:8080/Simple";
        
        // The WSDL must be read by EasyWSDL4ComplexWSDL to simulate a WSDL loaded in registry
        final URL wsdlUrl = Thread.currentThread().getContextClassLoader()
                .getResource("wsdl/simpleServiceWithImport.wsdl");
        assertNotNull("WSDL not found", wsdlUrl);
        final Description wsdlDescr = WSDL4ComplexWsdlFactory.newInstance().newWSDLReader().read(wsdlUrl);
        wsdlDescr.addImportedDocumentsInWsdl();

        final EasyByteArrayOutputStream ebaos = new EasyByteArrayOutputStream();

        WsdlHelper.printWSDL(WSDL4ComplexWsdlFactory.newInstance().newWSDLWriter().getDocument(wsdlDescr),
                serviceAddress, Collections.emptyList(), ebaos);

        assertTrue(ebaos.toString().contains(serviceAddress + "?wsdl=simpleServiceWithImport.xsd"));

    }

}
