Package org.wso2.carbon.mediation.initializer

Source Code of org.wso2.carbon.mediation.initializer.AdvancedPersistenceTest

/*
*  Copyright (c) 2005-2008, 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.mediation.initializer;

import org.apache.synapse.mediators.base.SequenceMediator;
import org.apache.synapse.endpoints.Endpoint;
import org.apache.synapse.core.axis2.ProxyService;
import org.apache.synapse.config.SynapseConfiguration;
import org.apache.synapse.config.xml.MultiXMLConfigurationBuilder;
import org.wso2.carbon.mediation.initializer.persistence.MediationPersistenceManager;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

public class AdvancedPersistenceTest extends MediationPersistenceTest {

    public void testMediationPersistence() {
        String seqFileName = "seq1.xml";
        String proxyFileName = "proxy1.xml";

        SequenceMediator seq = createSequence(getClass().getClassLoader().
                getResourceAsStream(seqFileName));
        seq.setFileName(seqFileName);
        Endpoint endpoint = createEndpoint(getClass().getClassLoader().
                getResourceAsStream("epr1.xml"));
        // Do not set a file name for the endpoint
        ProxyService proxy = createProxy(getClass().getClassLoader().
                getResourceAsStream(proxyFileName));
        proxy.setFileName(proxyFileName);

        SynapseConfiguration synapseConfig = synapseConfigSvc.getSynapseConfiguration();
        synapseConfig.addSequence(seq.getName(), seq);
        synapseConfig.addEndpoint(endpoint.getName(), endpoint);
        synapseConfig.addProxyService(proxy.getName(), proxy);

        MediationPersistenceManager pm = getMediationPersistenceManager();
        pm.saveItem(seq.getName(), ServiceBusConstants.ITEM_TYPE_SEQUENCE);
        pm.saveItem(endpoint.getName(), ServiceBusConstants.ITEM_TYPE_ENDPOINT);
        pm.saveItem(proxy.getName(), ServiceBusConstants.ITEM_TYPE_PROXY_SERVICE);

        hold();

        try {
            File seqFile = new File(path + File.separator +
                    MultiXMLConfigurationBuilder.SEQUENCES_DIR, seq.getFileName());
            SequenceMediator seqCopy = createSequence(new FileInputStream(seqFile));
            assertEquals(seq, seqCopy);

            File proxyFile = new File(path + File.separator +
                    MultiXMLConfigurationBuilder.PROXY_SERVICES_DIR, proxy.getFileName());
            ProxyService proxyCopy = createProxy(new FileInputStream(proxyFile));
            assertEquals(proxy, proxyCopy);

            Endpoint endpointCopy = getConfigurationFromSynapseXML().getDefinedEndpoints().
                    get(endpoint.getName());
            assertEquals(endpoint, endpointCopy);

        } catch (FileNotFoundException e) {
            fail("An item has not been saved to the file system : " + e.getMessage());
        }

    }
}
TOP

Related Classes of org.wso2.carbon.mediation.initializer.AdvancedPersistenceTest

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.