package net.timbusproject.extractors.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import net.sf.taverna.t2.commandline.exceptions.DatabaseConfigurationException;
import net.sf.taverna.t2.commandline.exceptions.InvalidOptionException;
import net.sf.taverna.t2.commandline.exceptions.OpenDataflowException;
import net.sf.taverna.t2.commandline.exceptions.ReadInputException;
import net.sf.taverna.t2.invocation.TokenOrderException;
import net.sf.taverna.t2.security.credentialmanager.CMException;
import net.sf.taverna.t2.workflowmodel.EditException;
import net.sf.taverna.t2.workflowmodel.InvalidDataflowException;
import net.sf.taverna.t2.workflowmodel.processor.iteration.IterationTypeMismatchException;
import net.sf.taverna.t2.workflowmodel.serialization.DeserializationException;
import net.timbusproject.extractors.TavernaExtractor;
import net.timbusproject.extractors.utils.ArchiUtils;
import org.junit.Ignore;
import org.junit.Test;
import uk.ac.bolton.archimate.model.IAccessRelationship;
import uk.ac.bolton.archimate.model.IArchimateElement;
import uk.ac.bolton.archimate.model.IBusinessObject;
import uk.ac.bolton.archimate.model.IBusinessProcess;
import uk.ac.bolton.archimate.model.IRelationship;
import uk.ac.bolton.archimate.model.ITriggeringRelationship;
import com.google.common.base.Joiner;
public class ArchiUtilsTest {
/*
* Following constants are related to the matchbox.archi file found in the resource folder
*/
final int RELATIONS_COUNT = 168;
final int TRIGGERING_RELATIONS_COUNT = 11;
final String ELEMENT_NAME = "stdout";
private static List<IRelationship> ALL_RELATIONS;
private static List<IArchimateElement> ALL_PROCESSES;
private static List<IArchimateElement> ALL_BUSINESSOBJECTS;
private static TavernaExtractor matchboxExtractor;
private static TavernaExtractor wsdlActivityExtractor;
private static TavernaExtractor beanshellActivityExtractor;
private static TavernaExtractor loopingExtractor;
// @BeforeClass
public static void customInit() throws EditException, OpenDataflowException, InvalidOptionException,
InvalidDataflowException, TokenOrderException, ReadInputException, DatabaseConfigurationException,
CMException, IOException, DeserializationException, IterationTypeMismatchException {
matchboxExtractor = new TavernaExtractor(true);
TavernaExtractor.setArchimateOutputPath(Joiner.on(File.separator).skipNulls()
.join("test", "resources", "matchbox.archi"));
TavernaExtractor.setInputFileName(Joiner.on(File.separator).skipNulls()
.join("test", "resources", "matchbox.t2flow"));
matchboxExtractor.process();
ALL_RELATIONS = matchboxExtractor.getRelations();
ALL_PROCESSES = matchboxExtractor.getBusinessProcesses();
ALL_BUSINESSOBJECTS = matchboxExtractor.getBusinessObjects();
}
@Test
public void test_Looping() throws EditException, OpenDataflowException, InvalidOptionException,
InvalidDataflowException, TokenOrderException, ReadInputException, DatabaseConfigurationException,
CMException, IOException, DeserializationException, IterationTypeMismatchException {
loopingExtractor = new TavernaExtractor(true);
TavernaExtractor.setArchimateOutputPath(Joiner.on(File.separator).skipNulls()
.join("test", "resources", "looping.archimate"));
TavernaExtractor.setInputFileName(Joiner.on(File.separator).skipNulls()
.join("test", "resources", "looping.t2flow"));
loopingExtractor.process();
}
@Test
public void test_processWSDLActivity() throws EditException, OpenDataflowException, InvalidOptionException,
InvalidDataflowException, TokenOrderException, ReadInputException, DatabaseConfigurationException,
CMException, IOException, DeserializationException, IterationTypeMismatchException {
wsdlActivityExtractor = new TavernaExtractor(true);
TavernaExtractor.setArchimateOutputPath(Joiner.on(File.separator).skipNulls()
.join("test", "resources", "WSDLActivity.archimate"));
TavernaExtractor.setInputFileName(Joiner.on(File.separator).skipNulls()
.join("test", "resources", "WSDLActivity.t2flow"));
wsdlActivityExtractor.process();
}
@Test
public void test_processLocalToolActivity() throws EditException, OpenDataflowException, InvalidOptionException,
InvalidDataflowException, TokenOrderException, ReadInputException, DatabaseConfigurationException,
CMException, IOException, DeserializationException, IterationTypeMismatchException {
wsdlActivityExtractor = new TavernaExtractor(true);
TavernaExtractor.setArchimateOutputPath(Joiner.on(File.separator).skipNulls()
.join("test", "resources", "localTool.archimate"));
TavernaExtractor.setInputFileName(Joiner.on(File.separator).skipNulls()
.join("test", "resources", "localTool.t2flow"));
wsdlActivityExtractor.process();
}
@Test
public void test_processSSHToolActivity() throws EditException, OpenDataflowException, InvalidOptionException,
InvalidDataflowException, TokenOrderException, ReadInputException, DatabaseConfigurationException,
CMException, IOException, DeserializationException, IterationTypeMismatchException {
wsdlActivityExtractor = new TavernaExtractor(true);
TavernaExtractor.setArchimateOutputPath(Joiner.on(File.separator).skipNulls()
.join("test", "resources", "sshTool.archimate"));
TavernaExtractor.setInputFileName(Joiner.on(File.separator).skipNulls()
.join("test", "resources", "sshTool.t2flow"));
wsdlActivityExtractor.process();
}
@Test
@Ignore
public void test_processBeanshellActivity() throws EditException, OpenDataflowException, InvalidOptionException,
InvalidDataflowException, TokenOrderException, ReadInputException, DatabaseConfigurationException,
CMException, IOException, DeserializationException, IterationTypeMismatchException {
beanshellActivityExtractor = new TavernaExtractor(true);
TavernaExtractor.setArchimateOutputPath(Joiner.on(File.separator).skipNulls()
.join("test", "resources", "beanshellLActivity.archimate"));
TavernaExtractor.setInputFileName(Joiner.on(File.separator).skipNulls()
.join("test", "resources", "beanshellLActivity.t2flow"));
beanshellActivityExtractor.process();
}
@Test
@Ignore("Grouping already implemented!")
public void test_getAllRelations() {
assertNotNull(ALL_RELATIONS);
assertEquals(ALL_RELATIONS.size(), RELATIONS_COUNT);
}
@Test
@Ignore("Grouping already implemented!")
public void test_getTriggeringSubset() {
assertNotNull(ALL_RELATIONS);
assertEquals(TRIGGERING_RELATIONS_COUNT, ArchiUtils.ofClass(ALL_RELATIONS, ITriggeringRelationship.class)
.size());
}
@Test
@Ignore("Grouping already implemented!")
public void test_getTriggeringSubsetForElement() {
List<IArchimateElement> businessProcesses = matchboxExtractor.getBusinessProcesses();
IBusinessProcess source = (IBusinessProcess) ArchiUtils.getElementsByname("matchbox_evaluate",
businessProcesses).get(0);
assertNotNull(ALL_RELATIONS);
assertEquals(3, ArchiUtils.ofClass(ALL_RELATIONS, ITriggeringRelationship.class, source).size());
}
@Test
@Ignore("Grouping already implemented!")
public void test_getAllOutgoingAccessRelations() {
List<IArchimateElement> businessProcesses = matchboxExtractor.getBusinessProcesses();
IBusinessProcess source = (IBusinessProcess) ArchiUtils.getElementsByname("matchbox_evaluate",
businessProcesses).get(0);
int numberOfOutgoingAccessRelations = ArchiUtils
.ofClass(ALL_RELATIONS, IAccessRelationship.class, source, true).size();
assertEquals(7, numberOfOutgoingAccessRelations);
}
@Test
@Ignore("Grouping already implemented!")
public void test_getAllIngoingAccessRelations() {
List<IArchimateElement> businessProcesses = matchboxExtractor.getBusinessProcesses();
IBusinessProcess source = (IBusinessProcess) ArchiUtils.getElementsByname("matchbox_evaluate",
businessProcesses).get(0);
int numberOfOutgoingAccessRelations = ArchiUtils.ofClass(ALL_RELATIONS, IAccessRelationship.class, source,
false).size();
assertEquals(2, numberOfOutgoingAccessRelations);
}
@Test
@Ignore("Grouping already implemented!")
public void test_getElementsInBetween() {
IBusinessProcess source = (IBusinessProcess) ArchiUtils.getElementsByname("matchbox_evaluate", ALL_PROCESSES)
.get(0);
IBusinessProcess target = (IBusinessProcess) ArchiUtils.getElementsByname("report", ALL_PROCESSES).get(0);
List<IArchimateElement> elements = ArchiUtils.getElementsInBetween(source, target, ALL_RELATIONS);
assertNotNull(elements);
int numberOfElements = elements.size();
assertEquals(6, numberOfElements);
// dirty - check if each item is of type IBusinessObject and if
// the list contains the correct elements via their names
List<String> list = new ArrayList<String>();
for (IArchimateElement element : elements) {
assertTrue(element instanceof IBusinessObject);
list.add(element.getName());
}
ArrayList<String> expected_list = new ArrayList<String>() {
{
add("cid");
add("fm");
add("iid");
add("rec");
add("md");
add("prec");
}
};
assertTrue(list.containsAll(expected_list));
}
@Test
@Ignore("Grouping already implemented!")
public void test_isListComplete() {
IBusinessProcess source = (IBusinessProcess) ArchiUtils.getElementsByname("matchbox_evaluate", ALL_PROCESSES)
.get(0);
IBusinessProcess target = (IBusinessProcess) ArchiUtils.getElementsByname("report", ALL_PROCESSES).get(0);
List<IArchimateElement> completeList = ArchiUtils.getElementsInBetween(source, target, ALL_RELATIONS);
// testlist - get each element by name
List<IArchimateElement> testList = new ArrayList<IArchimateElement>();
testList.add(ArchiUtils.getElementsByname("cid", ALL_BUSINESSOBJECTS).get(0));
testList.add(ArchiUtils.getElementsByname("fm", ALL_BUSINESSOBJECTS).get(0));
testList.add(ArchiUtils.getElementsByname("iid", ALL_BUSINESSOBJECTS).get(0));
testList.add(ArchiUtils.getElementsByname("md", ALL_BUSINESSOBJECTS).get(0));
testList.add(ArchiUtils.getElementsByname("prec", ALL_BUSINESSOBJECTS).get(0));
testList.add(ArchiUtils.getElementsByname("rec", ALL_BUSINESSOBJECTS).get(0));
assertTrue(ArchiUtils.isListComplete(testList, completeList));
}
}