Download this file

ArchiUtilsTest.java    253 lines (202 with data), 11.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
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));
}
}