/*
* Copyright 2004 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.apache.agila.services;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
import org.apache.agila.impl.BusinessProcessImpl;
import org.apache.agila.impl.memory.BusinessProcessServiceImpl;
import org.apache.agila.model.BusinessProcess;
import org.apache.agila.model.BusinessProcessID;
import org.apache.agila.model.Connection;
import org.apache.agila.model.Node;
import org.apache.agila.model.NodeContext;
import org.apache.agila.model.NodeID;
import org.apache.agila.model.node.BaseNodeImpl;
import junit.framework.TestCase;
/**
* @author Glenn
*
*/
public class BusinessProcessServiceTestCase extends TestCase {
AbstractBusinessProcessService bpService;
public void testAddGraph_String() {
BusinessProcessID bpID = bpService.addGraph( getXMLAsString() );
assertNotNull( bpID );
}
public void testAddGraph() {
// create a business process with a root node and get a business process
// id
BusinessProcessImpl bProcess = new BusinessProcessImpl();
String graphName = "Graph1";
bProcess.setName( graphName );
Node rootNode = new BaseNodeImpl() {
public Connection[] doEnd( NodeContext ctx ) {
return null;
}
};
rootNode.setNodeId(new NodeID(1));
rootNode.setDisplayName("root");
bProcess.setRoot( rootNode );
// add the business process graph
BusinessProcessID bpId = bpService.addGraph( bProcess );
// confirm that the graph has been saved by retrieving all current
// graphs
List processList = bpService.getCurrentProcessInfos();
assertNotNull( processList );
assertEquals( 1, processList.size() );
assertEquals( "org.apache.agila.services.BusinessProcessInfo", processList.get( 0 ).getClass().getName() );
// confirm that the graph has been saved by retrieving using the
// business process id
BusinessProcess gotBusinessProcess = bpService.getGraphByID( bpId );
assertEquals( bProcess, gotBusinessProcess );
}
private String getXMLAsString() {
BufferedReader reader = new BufferedReader( new InputStreamReader( getClass().getClassLoader().getResourceAsStream(
"org/apache/agila/workflow_simple.xml" ) ) );
String readLine = "";
StringBuffer buffer = new StringBuffer();
try {
while ((readLine = reader.readLine()) != null) {
buffer.append( readLine + "\n" );
}
reader.close();
} catch( IOException e ) {
fail( e.getMessage() );
e.printStackTrace();
}
return( buffer.toString() );
}
protected void setUp() throws Exception {
super.setUp();
bpService = new BusinessProcessServiceImpl();
}
protected void tearDown() throws Exception {
super.tearDown();
}
}