Package org.wso2.carbon.endpoint.test

Source Code of org.wso2.carbon.endpoint.test.InlinedWSDLEndpointTest

/*
*  Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
*  WSO2 Inc. 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.wso2.carbon.endpoint.test;

import org.apache.axiom.om.OMElement;
import org.apache.axis2.AxisFault;
import org.wso2.carbon.endpoint.stub.types.*;
import org.wso2.esb.integration.ESBIntegrationTest;

import javax.xml.stream.XMLStreamException;
import java.rmi.RemoteException;
import java.util.Arrays;
import java.util.List;

public class InlinedWSDLEndpointTest extends ESBIntegrationTest {

    private static final String ENDPOINT_NAME = "wsdlEpTest";

    public InlinedWSDLEndpointTest() {
        super("EndpointAdmin");
    }

    @Override
    public void successfulScenario() throws RemoteException {
        EndpointAdminStub endpointAdminStub = null;
        try {
            endpointAdminStub = new EndpointAdminStub(getAdminServiceURL());
        } catch (AxisFault axisFault) {
            handleError("Error while creating the endpoint admin stub", axisFault);
        }

        authenticate(endpointAdminStub);

        cleanupEndpoints(endpointAdminStub);
        endpointAdditionScenario(endpointAdminStub);
        endpointStatisticsScenario(endpointAdminStub);
        endpointDeletionScenario(endpointAdminStub);
    }

    private void cleanupEndpoints(EndpointAdminStub endpointAdminStub) throws RemoteException {
        String[] endpointNames = new String[0];
        try {
            endpointNames = endpointAdminStub.getEndPointsNames();
        } catch (EndpointAdminEndpointAdminException e) {
            handleError("Unexpected error while obtaining the endpoint names", e);
        }
        List endpointList;
        if (endpointNames != null && endpointNames.length > 0 && endpointNames[0] != null) {
            endpointList = Arrays.asList(endpointNames);

            if (endpointList.contains(ENDPOINT_NAME)) {
                try {
                    endpointAdminStub.deleteEndpoint(ENDPOINT_NAME);
                } catch (EndpointAdminEndpointAdminException e) {
                    handleError("Unexpected error while deleting an endpoint", e);
                }
            }
        }
    }

    private void endpointAdditionScenario(EndpointAdminStub endpointAdminStub) throws RemoteException {
        int beforeCount = 0;
        try {
            beforeCount = endpointAdminStub.getEndpointCount();
        } catch (EndpointAdminEndpointAdminException e) {
            handleError("Error while obtaining the endpoint count", e);
        }

        OMElement omElement;
        String wsdlTestEp = null;
        try {
            omElement = loadResource("/wsdlTestEp.xml");
            wsdlTestEp = omElement.toStringWithConsume();
        } catch (XMLStreamException e) {
            handleError("Error while loading test resources for WSDL endpoint", e);
        }
        try {
            endpointAdminStub.addEndpoint(wsdlTestEp);
        } catch (EndpointAdminEndpointAdminException e) {
            handleError("Error while adding a new endpoint", e);
        }

        int afterCount = 0;
        try {
            afterCount = endpointAdminStub.getEndpointCount();
        } catch (EndpointAdminEndpointAdminException e) {
            handleError("Error while obtaining the endpoint count", e);
        }
        assertEquals(1, afterCount - beforeCount);

        String[] endpoints = new String[0];
        try {
            endpoints = endpointAdminStub.getEndPointsNames();
        } catch (EndpointAdminEndpointAdminException e) {
            handleError("Error while obtaining endpoint names", e);
        }
        if (endpoints != null && endpoints.length > 0 && endpoints[0] != null) {
            List endpointList = Arrays.asList(endpoints);
            assertTrue(endpointList.contains(ENDPOINT_NAME));
        } else {
            fail("Endpoint has not been added to the system properly");
        }
    }

    private void endpointStatisticsScenario(EndpointAdminStub endpointAdminStub) throws RemoteException {
        try {
            endpointAdminStub.enableStatistics(ENDPOINT_NAME);
        } catch (EndpointAdminEndpointAdminException e) {
            handleError("Error while enabling statistics on an endpoint", e);
        }
        String endpoint = null;
        try {
            endpoint = endpointAdminStub.getEndpoint(ENDPOINT_NAME);
        } catch (EndpointAdminEndpointAdminException e) {
            handleError("Error while obtaining endpoint information", e);
        }
        assertTrue(endpoint.contains("statistics=\"enable"));
    }

    private void endpointDeletionScenario(EndpointAdminStub endpointAdminStub) throws RemoteException {
        int beforeCount = 0;
        try {
            beforeCount = endpointAdminStub.getEndpointCount();
        } catch (EndpointAdminEndpointAdminException e) {
            handleError("Error while obtaining the endpoint count", e);
        }
        try {
            endpointAdminStub.deleteEndpoint(ENDPOINT_NAME);
        } catch (EndpointAdminEndpointAdminException e) {
            handleError("Error while deleting an endpoint", e);
        }
        int afterCount = 0;
        try {
            afterCount = endpointAdminStub.getEndpointCount();
        } catch (EndpointAdminEndpointAdminException e) {
            handleError("Error while obtaining the endpoint count", e);
        }
        assertEquals(1, beforeCount - afterCount);

    }
}
TOP

Related Classes of org.wso2.carbon.endpoint.test.InlinedWSDLEndpointTest

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.