Package org.wso2.carbon.localentry.test

Source Code of org.wso2.carbon.localentry.test.InlineTextEntryTest

/*
*  Copyright (c) WSO2 Inc. (http://wso2.com) 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.localentry.test;

import org.wso2.carbon.localentry.stub.types.LocalEntryAdminException;
import org.wso2.carbon.localentry.stub.types.LocalEntryAdminServiceStub;
import org.wso2.esb.integration.ESBIntegrationTest;

import java.rmi.RemoteException;

public class InlineTextEntryTest extends ESBIntegrationTest {

    private static final String ENTRY_NAME = "TestEntryText";

    public InlineTextEntryTest() {
        super("LocalEntryAdmin");
    }

    @Override
    public void successfulScenario() throws RemoteException {

        LocalEntryAdminServiceStub stub = new LocalEntryAdminServiceStub(getAdminServiceURL());
        authenticate(stub);

        try {
            String entryNames = stub.getEntryNamesString();
            if (entryNames != null && entryNames.contains(ENTRY_NAME)) {
                assertTrue(stub.deleteEntry(ENTRY_NAME));
            }
        } catch (LocalEntryAdminException e) {
            handleError("Error while invoking the local entry admin service", e);
        }

        testEntryAddition(stub);
        testEntryRemoval(stub);

        log.info("Inline text entry test passed");
    }

    private void testEntryAddition(LocalEntryAdminServiceStub stub) throws RemoteException {
        try {
            int before = stub.getEntryDataCount();
            assertTrue(stub.addEntry("<localEntry xmlns=\"http://ws.apache.org/ns/synapse\" " +
                    "key=\"" + ENTRY_NAME + "\">This is test entry for checking Inline Text admin " +
                    "service</localEntry>"));
            int after = stub.getEntryDataCount();
            assertEquals(1, after - before);

            String entryNames = stub.getEntryNamesString();
            assertTrue(entryNames.contains(ENTRY_NAME));
        } catch (LocalEntryAdminException e) {
            handleError("Error while invoking the local entry admin service", e);
        }
    }

    private void testEntryRemoval(LocalEntryAdminServiceStub stub) throws RemoteException {
        try {
            int before = stub.getEntryDataCount();
            assertTrue(stub.deleteEntry(ENTRY_NAME));
            int after = stub.getEntryDataCount();
            assertEquals(1, before - after);
        } catch (LocalEntryAdminException e) {
            handleError("Error while invoking the local entry admin service", e);
        }
    }
}
TOP

Related Classes of org.wso2.carbon.localentry.test.InlineTextEntryTest

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.