Switch to unified view

a b/test/net/timbusproject/extractors/test/ArchiUtilsTest.java
1
package net.timbusproject.extractors.test;
2
3
import static org.junit.Assert.assertEquals;
4
import static org.junit.Assert.assertNotNull;
5
import static org.junit.Assert.assertTrue;
6
7
import java.io.File;
8
import java.io.IOException;
9
import java.util.ArrayList;
10
import java.util.List;
11
12
import net.sf.taverna.t2.commandline.exceptions.DatabaseConfigurationException;
13
import net.sf.taverna.t2.commandline.exceptions.InvalidOptionException;
14
import net.sf.taverna.t2.commandline.exceptions.OpenDataflowException;
15
import net.sf.taverna.t2.commandline.exceptions.ReadInputException;
16
import net.sf.taverna.t2.invocation.TokenOrderException;
17
import net.sf.taverna.t2.security.credentialmanager.CMException;
18
import net.sf.taverna.t2.workflowmodel.EditException;
19
import net.sf.taverna.t2.workflowmodel.InvalidDataflowException;
20
import net.sf.taverna.t2.workflowmodel.processor.iteration.IterationTypeMismatchException;
21
import net.sf.taverna.t2.workflowmodel.serialization.DeserializationException;
22
import net.timbusproject.extractors.TavernaExtractor;
23
import net.timbusproject.extractors.utils.ArchiUtils;
24
25
import org.junit.Ignore;
26
import org.junit.Test;
27
28
import uk.ac.bolton.archimate.model.IAccessRelationship;
29
import uk.ac.bolton.archimate.model.IArchimateElement;
30
import uk.ac.bolton.archimate.model.IBusinessObject;
31
import uk.ac.bolton.archimate.model.IBusinessProcess;
32
import uk.ac.bolton.archimate.model.IRelationship;
33
import uk.ac.bolton.archimate.model.ITriggeringRelationship;
34
35
import com.google.common.base.Joiner;
36
37
public class ArchiUtilsTest {
38
39
    /*
40
     * Following constants are related to the matchbox.archi file found in the resource folder
41
     */
42
    final int RELATIONS_COUNT = 168;
43
    final int TRIGGERING_RELATIONS_COUNT = 11;
44
    final String ELEMENT_NAME = "stdout";
45
46
    private static List<IRelationship> ALL_RELATIONS;
47
    private static List<IArchimateElement> ALL_PROCESSES;
48
    private static List<IArchimateElement> ALL_BUSINESSOBJECTS;
49
    private static TavernaExtractor matchboxExtractor;
50
    private static TavernaExtractor wsdlActivityExtractor;
51
    private static TavernaExtractor beanshellActivityExtractor;
52
    private static TavernaExtractor loopingExtractor;
53
54
    // @BeforeClass
55
    public static void customInit() throws EditException, OpenDataflowException, InvalidOptionException,
56
            InvalidDataflowException, TokenOrderException, ReadInputException, DatabaseConfigurationException,
57
            CMException, IOException, DeserializationException, IterationTypeMismatchException {
58
59
        matchboxExtractor = new TavernaExtractor(true);
60
61
        TavernaExtractor.setArchimateOutputPath(Joiner.on(File.separator).skipNulls()
62
                .join("test", "resources", "matchbox.archi"));
63
        TavernaExtractor.setInputFileName(Joiner.on(File.separator).skipNulls()
64
                .join("test", "resources", "matchbox.t2flow"));
65
66
        matchboxExtractor.process();
67
        ALL_RELATIONS = matchboxExtractor.getRelations();
68
        ALL_PROCESSES = matchboxExtractor.getBusinessProcesses();
69
        ALL_BUSINESSOBJECTS = matchboxExtractor.getBusinessObjects();
70
    }
71
72
    @Test
73
    public void test_Looping() throws EditException, OpenDataflowException, InvalidOptionException,
74
            InvalidDataflowException, TokenOrderException, ReadInputException, DatabaseConfigurationException,
75
            CMException, IOException, DeserializationException, IterationTypeMismatchException {
76
77
        loopingExtractor = new TavernaExtractor(true);
78
        TavernaExtractor.setArchimateOutputPath(Joiner.on(File.separator).skipNulls()
79
                .join("test", "resources", "looping.archimate"));
80
        TavernaExtractor.setInputFileName(Joiner.on(File.separator).skipNulls()
81
                .join("test", "resources", "looping.t2flow"));
82
83
        loopingExtractor.process();
84
    }
85
86
    @Test
87
    public void test_processWSDLActivity() throws EditException, OpenDataflowException, InvalidOptionException,
88
            InvalidDataflowException, TokenOrderException, ReadInputException, DatabaseConfigurationException,
89
            CMException, IOException, DeserializationException, IterationTypeMismatchException {
90
91
        wsdlActivityExtractor = new TavernaExtractor(true);
92
        TavernaExtractor.setArchimateOutputPath(Joiner.on(File.separator).skipNulls()
93
                .join("test", "resources", "WSDLActivity.archimate"));
94
        TavernaExtractor.setInputFileName(Joiner.on(File.separator).skipNulls()
95
                .join("test", "resources", "WSDLActivity.t2flow"));
96
97
        wsdlActivityExtractor.process();
98
    }
99
100
    @Test
101
    public void test_processLocalToolActivity() throws EditException, OpenDataflowException, InvalidOptionException,
102
            InvalidDataflowException, TokenOrderException, ReadInputException, DatabaseConfigurationException,
103
            CMException, IOException, DeserializationException, IterationTypeMismatchException {
104
105
        wsdlActivityExtractor = new TavernaExtractor(true);
106
        TavernaExtractor.setArchimateOutputPath(Joiner.on(File.separator).skipNulls()
107
                .join("test", "resources", "localTool.archimate"));
108
        TavernaExtractor.setInputFileName(Joiner.on(File.separator).skipNulls()
109
                .join("test", "resources", "localTool.t2flow"));
110
111
        wsdlActivityExtractor.process();
112
    }
113
114
    @Test
115
    public void test_processSSHToolActivity() throws EditException, OpenDataflowException, InvalidOptionException,
116
            InvalidDataflowException, TokenOrderException, ReadInputException, DatabaseConfigurationException,
117
            CMException, IOException, DeserializationException, IterationTypeMismatchException {
118
119
        wsdlActivityExtractor = new TavernaExtractor(true);
120
        TavernaExtractor.setArchimateOutputPath(Joiner.on(File.separator).skipNulls()
121
                .join("test", "resources", "sshTool.archimate"));
122
        TavernaExtractor.setInputFileName(Joiner.on(File.separator).skipNulls()
123
                .join("test", "resources", "sshTool.t2flow"));
124
125
        wsdlActivityExtractor.process();
126
    }
127
128
    @Test
129
    @Ignore
130
    public void test_processBeanshellActivity() throws EditException, OpenDataflowException, InvalidOptionException,
131
            InvalidDataflowException, TokenOrderException, ReadInputException, DatabaseConfigurationException,
132
            CMException, IOException, DeserializationException, IterationTypeMismatchException {
133
134
        beanshellActivityExtractor = new TavernaExtractor(true);
135
        TavernaExtractor.setArchimateOutputPath(Joiner.on(File.separator).skipNulls()
136
                .join("test", "resources", "beanshellLActivity.archimate"));
137
        TavernaExtractor.setInputFileName(Joiner.on(File.separator).skipNulls()
138
                .join("test", "resources", "beanshellLActivity.t2flow"));
139
140
        beanshellActivityExtractor.process();
141
    }
142
143
    @Test
144
    @Ignore("Grouping already implemented!")
145
    public void test_getAllRelations() {
146
147
        assertNotNull(ALL_RELATIONS);
148
        assertEquals(ALL_RELATIONS.size(), RELATIONS_COUNT);
149
    }
150
151
    @Test
152
    @Ignore("Grouping already implemented!")
153
    public void test_getTriggeringSubset() {
154
155
        assertNotNull(ALL_RELATIONS);
156
        assertEquals(TRIGGERING_RELATIONS_COUNT, ArchiUtils.ofClass(ALL_RELATIONS, ITriggeringRelationship.class)
157
                .size());
158
    }
159
160
    @Test
161
    @Ignore("Grouping already implemented!")
162
    public void test_getTriggeringSubsetForElement() {
163
164
        List<IArchimateElement> businessProcesses = matchboxExtractor.getBusinessProcesses();
165
        IBusinessProcess source = (IBusinessProcess) ArchiUtils.getElementsByname("matchbox_evaluate",
166
                businessProcesses).get(0);
167
168
        assertNotNull(ALL_RELATIONS);
169
        assertEquals(3, ArchiUtils.ofClass(ALL_RELATIONS, ITriggeringRelationship.class, source).size());
170
    }
171
172
    @Test
173
    @Ignore("Grouping already implemented!")
174
    public void test_getAllOutgoingAccessRelations() {
175
176
        List<IArchimateElement> businessProcesses = matchboxExtractor.getBusinessProcesses();
177
        IBusinessProcess source = (IBusinessProcess) ArchiUtils.getElementsByname("matchbox_evaluate",
178
                businessProcesses).get(0);
179
        int numberOfOutgoingAccessRelations = ArchiUtils
180
                .ofClass(ALL_RELATIONS, IAccessRelationship.class, source, true).size();
181
        assertEquals(7, numberOfOutgoingAccessRelations);
182
    }
183
184
    @Test
185
    @Ignore("Grouping already implemented!")
186
    public void test_getAllIngoingAccessRelations() {
187
188
        List<IArchimateElement> businessProcesses = matchboxExtractor.getBusinessProcesses();
189
        IBusinessProcess source = (IBusinessProcess) ArchiUtils.getElementsByname("matchbox_evaluate",
190
                businessProcesses).get(0);
191
        int numberOfOutgoingAccessRelations = ArchiUtils.ofClass(ALL_RELATIONS, IAccessRelationship.class, source,
192
                false).size();
193
        assertEquals(2, numberOfOutgoingAccessRelations);
194
    }
195
196
    @Test
197
    @Ignore("Grouping already implemented!")
198
    public void test_getElementsInBetween() {
199
200
        IBusinessProcess source = (IBusinessProcess) ArchiUtils.getElementsByname("matchbox_evaluate", ALL_PROCESSES)
201
                .get(0);
202
        IBusinessProcess target = (IBusinessProcess) ArchiUtils.getElementsByname("report", ALL_PROCESSES).get(0);
203
204
        List<IArchimateElement> elements = ArchiUtils.getElementsInBetween(source, target, ALL_RELATIONS);
205
206
        assertNotNull(elements);
207
208
        int numberOfElements = elements.size();
209
        assertEquals(6, numberOfElements);
210
211
        // dirty - check if each item is of type IBusinessObject and if
212
        // the list contains the correct elements via their names
213
        List<String> list = new ArrayList<String>();
214
        for (IArchimateElement element : elements) {
215
            assertTrue(element instanceof IBusinessObject);
216
            list.add(element.getName());
217
        }
218
        ArrayList<String> expected_list = new ArrayList<String>() {
219
            {
220
                add("cid");
221
                add("fm");
222
                add("iid");
223
                add("rec");
224
                add("md");
225
                add("prec");
226
            }
227
        };
228
        assertTrue(list.containsAll(expected_list));
229
    }
230
231
    @Test
232
    @Ignore("Grouping already implemented!")
233
    public void test_isListComplete() {
234
235
        IBusinessProcess source = (IBusinessProcess) ArchiUtils.getElementsByname("matchbox_evaluate", ALL_PROCESSES)
236
                .get(0);
237
        IBusinessProcess target = (IBusinessProcess) ArchiUtils.getElementsByname("report", ALL_PROCESSES).get(0);
238
239
        List<IArchimateElement> completeList = ArchiUtils.getElementsInBetween(source, target, ALL_RELATIONS);
240
241
        // testlist - get each element by name
242
        List<IArchimateElement> testList = new ArrayList<IArchimateElement>();
243
        testList.add(ArchiUtils.getElementsByname("cid", ALL_BUSINESSOBJECTS).get(0));
244
        testList.add(ArchiUtils.getElementsByname("fm", ALL_BUSINESSOBJECTS).get(0));
245
        testList.add(ArchiUtils.getElementsByname("iid", ALL_BUSINESSOBJECTS).get(0));
246
        testList.add(ArchiUtils.getElementsByname("md", ALL_BUSINESSOBJECTS).get(0));
247
        testList.add(ArchiUtils.getElementsByname("prec", ALL_BUSINESSOBJECTS).get(0));
248
        testList.add(ArchiUtils.getElementsByname("rec", ALL_BUSINESSOBJECTS).get(0));
249
250
        assertTrue(ArchiUtils.isListComplete(testList, completeList));
251
    }
252
}