org.jboss.additional.testsuite.jdkall.present.web.mtom.MtomTestCase.java Source code

Java tutorial

Introduction

Here is the source code for org.jboss.additional.testsuite.jdkall.present.web.mtom.MtomTestCase.java

Source

/*
 * JBoss, Home of Professional Open Source.
 * Copyright (c) 2016, Red Hat, Inc., and individual contributors
 * as indicated by the @author tags. See the copyright.txt file in the
 * distribution for a full listing of individual contributors.
 *
 * This 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 software 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 software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.jboss.additional.testsuite.jdkall.present.web.mtom;

import java.awt.Image;
import java.io.FileInputStream;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Service;
import javax.xml.ws.soap.SOAPBinding;
import org.apache.commons.io.IOUtils;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.eap.additional.testsuite.annotations.EapAdditionalTestsuite;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
 * @author <a href="mailto:psotirop@redhat.com">Panos</a>
 */
@RunWith(Arquillian.class)
@RunAsClient
@Ignore // It is available only for localhost tests
@EapAdditionalTestsuite({ "modules/testcases/jdkAll/WildflyRelease-13.0.0.Final/web/src/main/java",
        "modules/testcases/jdkAll/Wildfly/web/src/main/java", "modules/testcases/jdkAll/Eap72x/web/src/main/java",
        "modules/testcases/jdkAll/Eap72x-Proposed/web/src/main/java",
        "modules/testcases/jdkAll/Eap7/web/src/main/java",
        "modules/testcases/jdkAll/Eap71x-Proposed/web/src/main/java",
        "modules/testcases/jdkAll/Eap71x/web/src/main/java",
        "modules/testcases/jdkAll/Eap7.1.0.Beta/web/src/main/java",
        "modules/testcases/jdkAll/Eap70x/web/src/main/java",
        "modules/testcases/jdkAll/Eap70x-Proposed/web/src/main/java",
        "modules/testcases/jdkAll/Eap64x/web/src/main/java",
        "modules/testcases/jdkAll/Eap64x-Proposed/web/src/main/java",
        "modules/testcases/jdkAll/WildflyRelease-10.1.0.Final/web/src/main/java" })
public class MtomTestCase {

    private final String serverLogPath = "surefire-reports/org.jboss.additional.testsuite.jdkall.present.web.mtom.MtomTestCase-output.txt";

    @Deployment
    public static WebArchive deployment() {
        WebArchive war = ShrinkWrap.create(WebArchive.class, "war-mtom.war");
        war.addClasses(ImageServer.class, ImageServerImpl.class);
        war.setWebXML("META-INF/web.xml");
        return war;
    }

    @Test
    public void mtomTest() throws Exception {
        URL url = new URL("http://localhost:8080/war-mtom?wsdl");
        QName qname = new QName("http://mtom.web.present.jdkall.testsuite.additional.jboss.org/",
                "ImageServerImplService");

        String path = this.getClass().getClassLoader().getResource("").getPath();

        FileInputStream inputStream = new FileInputStream(path + "../" + serverLogPath);
        try {
            String everything = IOUtils.toString(inputStream);
            assertFalse("Testing archive has enabled mtom feature", everything.contains("mtomEnabled=true"));
        } finally {
            inputStream.close();
        }

        Service service = Service.create(url, qname);
        ImageServer imageServer = service.getPort(ImageServer.class);

        //enable MTOM in client
        BindingProvider bp = (BindingProvider) imageServer;
        SOAPBinding binding = (SOAPBinding) bp.getBinding();
        binding.setMTOMEnabled(true);

        Image im = imageServer.downloadImage(path + "rss.png");

        if (im == null) {
            fail();
        }

    }
}