/*
* 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 SequenceAddRemoveTest extends TestTemplate {
private static final Log log = LogFactory.getLog(SequenceAddRemoveTest.class);
private static final String SEQUENCE_NAME = "testFwSeq";
@Override
public void init() {
log.info("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.getSequencesCount();
ArtifactReader artifactReader = new ArtifactReader();
OMElement omElement = artifactReader.getOMElement(SequenceAddRemoveTest.class.getResource("/synapse.xml").getPath());
// add new sequence
sequenceAdminServiceStub.addSequence(omElement);
int after = sequenceAdminServiceStub.getSequencesCount();
assertEquals(1, after - before);
assertNotNull(sequenceAdminServiceStub.getSequence(SEQUENCE_NAME));
assertEquals(SEQUENCE_NAME, sequenceAdminServiceStub.enableStatistics(SEQUENCE_NAME));
assertEquals(SEQUENCE_NAME, sequenceAdminServiceStub.enableTracing(SEQUENCE_NAME));
sequenceAdminServiceStub.deleteSequence(SEQUENCE_NAME);
after = sequenceAdminServiceStub.getSequencesCount();
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() {
}
}