/*
* 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.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.localentry.stub.types.LocalEntryAdminException;
import org.wso2.carbon.localentry.stub.types.LocalEntryAdminServiceStub;
import org.wso2.esb.integration.ESBIntegrationTest;
import java.rmi.RemoteException;
public class SourceURLLocalEntryTest extends ESBIntegrationTest {
private static final String ENTRY_NAME = "SourceURLTestEntry";
public SourceURLLocalEntryTest() {
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("Source URL entry test passed");
}
private void testEntryAddition(LocalEntryAdminServiceStub stub) throws RemoteException {
try {
int before = stub.getEntryDataCount();
assertTrue(stub.addEntry("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<localEntry xmlns=\"http://ws.apache.org/ns/synapse\" key=\"" + ENTRY_NAME +
"\" src=\"file:repository/samples/resources/transform/transform.xslt\"/>"));
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);
}
}
}