Package org.wso2.carbon.sequence.test

Source Code of org.wso2.carbon.sequence.test.DynamicSequenceAddRemoveTest

/*
* Copyright 2004,2005 The 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.wso2.carbon.sequence.test;

import org.apache.axiom.om.OMElement;
import org.apache.axis2.AxisFault;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.integration.core.AuthenticateStub;
import org.wso2.carbon.integration.core.FrameworkSettings;
import org.wso2.carbon.integration.core.TestTemplate;
import org.wso2.carbon.integration.core.utils.ArtifactReader;
import org.wso2.carbon.sequences.stub.types.SequenceAdminServiceStub;
import org.wso2.carbon.sequences.stub.types.SequenceEditorException;

import java.rmi.RemoteException;

public class DynamicSequenceAddRemoveTest extends TestTemplate {

    private static final Log log = LogFactory.getLog(DynamicSequenceAddRemoveTest.class);

    @Override
    public void init() {
        log.info("Dynamic Sequence admin service tests initialized");
    }

    @Override
    public void runSuccessCase() {

        AuthenticateStub authenticateStub = new AuthenticateStub();
        SequenceAdminServiceStub sequenceAdminServiceStub;

        try {
            sequenceAdminServiceStub = new SequenceAdminServiceStub("https://" +
                    FrameworkSettings.HOST_NAME + ":" + FrameworkSettings.HTTPS_PORT +
                    "/services/SequenceAdminService");
            authenticateStub.authenticateAdminStub(sequenceAdminServiceStub, sessionCookie);
        } catch (AxisFault axisFault) {
            handleError("Error while authenticating the sequence admin stub", axisFault);
            return;
        }

        try {
            int before = sequenceAdminServiceStub.getDynamicSequenceCount();
            ArtifactReader artifactReader = new ArtifactReader();
            OMElement omElement = artifactReader.getOMElement(SequenceAddRemoveTest.class.getResource("/synapse.xml").getPath());

            // add new sequence
            sequenceAdminServiceStub.addDynamicSequence("conf:/testDynamicSeq", omElement);
            sequenceAdminServiceStub.addDynamicSequence("gov:/testDynamicSeq", omElement);
            int after = sequenceAdminServiceStub.getDynamicSequenceCount();
            assertEquals(2, after - before);

            sequenceAdminServiceStub.deleteDynamicSequence("conf:/testDynamicSeq");
            sequenceAdminServiceStub.deleteDynamicSequence("gov:/testDynamicSeq");
            after = sequenceAdminServiceStub.getDynamicSequenceCount();
            assertEquals(before, after);
        } catch (RemoteException e) {
            handleError("Error while contacting the sequence admin service", e);
        } catch (SequenceEditorException e) {
            handleError("Error while invoking the sequence admin service", e);
        }
    }

    private void handleError(String msg, Throwable t) {
        log.error(msg, t);
        fail(msg);
    }

    @Override
    public void runFailureCase() {

    }

    @Override
    public void cleanup() {

    }
}
TOP

Related Classes of org.wso2.carbon.sequence.test.DynamicSequenceAddRemoveTest

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.