[1603] | 1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany
|
---|
| 2 | //
|
---|
| 3 | // Licensed under the Apache License, Version 2.0 (the "License");
|
---|
| 4 | // you may not use this file except in compliance with the License.
|
---|
| 5 | // You may obtain a copy of the License at
|
---|
| 6 | //
|
---|
| 7 | // http://www.apache.org/licenses/LICENSE-2.0
|
---|
| 8 | //
|
---|
| 9 | // Unless required by applicable law or agreed to in writing, software
|
---|
| 10 | // distributed under the License is distributed on an "AS IS" BASIS,
|
---|
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
| 12 | // See the License for the specific language governing permissions and
|
---|
| 13 | // limitations under the License.
|
---|
| 14 |
|
---|
| 15 | package de.ugoe.cs.autoquest.plugin.uml;
|
---|
| 16 |
|
---|
| 17 | import java.io.File;
|
---|
| 18 | import java.util.Collection;
|
---|
| 19 | import java.util.Iterator;
|
---|
| 20 | import java.util.LinkedList;
|
---|
| 21 | import java.util.List;
|
---|
[1643] | 22 | import java.util.Random;
|
---|
[1898] | 23 | import java.util.logging.Level;
|
---|
[1603] | 24 |
|
---|
[1926] | 25 | import static org.junit.Assert.*;
|
---|
| 26 |
|
---|
[1763] | 27 | import org.apache.commons.lang.SerializationUtils;
|
---|
[1643] | 28 | import org.eclipse.uml2.uml.Interaction;
|
---|
[1603] | 29 | import org.eclipse.uml2.uml.Model;
|
---|
| 30 | import org.eclipse.uml2.uml.StateMachine;
|
---|
| 31 | import org.eclipse.uml2.uml.UMLPackage;
|
---|
| 32 | import org.junit.After;
|
---|
[1898] | 33 | import org.junit.BeforeClass;
|
---|
[1603] | 34 | import org.junit.Test;
|
---|
| 35 |
|
---|
[1759] | 36 | import de.fraunhofer.fokus.testing.ModelUtils;
|
---|
[1603] | 37 | import de.ugoe.cs.autoquest.eventcore.Event;
|
---|
| 38 | import de.ugoe.cs.autoquest.plugin.http.HTTPLogParser;
|
---|
[1926] | 39 | import de.ugoe.cs.autoquest.plugin.http.SOAPUtils;
|
---|
[1603] | 40 | import de.ugoe.cs.autoquest.plugin.http.eventcore.SOAPEventType;
|
---|
[1643] | 41 | import de.ugoe.cs.autoquest.testgeneration.RandomWalkGenerator;
|
---|
| 42 | import de.ugoe.cs.autoquest.usageprofiles.FirstOrderMarkovModel;
|
---|
[1763] | 43 | import de.ugoe.cs.autoquest.usageprofiles.IStochasticProcess;
|
---|
[1898] | 44 | import de.ugoe.cs.util.console.TextConsole;
|
---|
[1603] | 45 |
|
---|
| 46 | /**
|
---|
| 47 | * <p>
|
---|
| 48 | * Tests for AutoQUESTs UMLUtils
|
---|
| 49 | * </p>
|
---|
| 50 | *
|
---|
| 51 | * @author Steffen Herbold
|
---|
| 52 | */
|
---|
| 53 | public class UMLUtilsTest {
|
---|
[1625] | 54 |
|
---|
[1606] | 55 | private final static String OUTPUT_DIR = "target/tmp/test-outputs/";
|
---|
[1625] | 56 |
|
---|
[1898] | 57 | @BeforeClass
|
---|
| 58 | public static void setUpBeforeClass() throws Exception {
|
---|
[1900] | 59 | new TextConsole(Level.INFO);
|
---|
[1898] | 60 | }
|
---|
[1926] | 61 |
|
---|
[1625] | 62 | @After
|
---|
| 63 | public void tearDown() throws Exception {
|
---|
| 64 | deleteFiles(new File(OUTPUT_DIR));
|
---|
| 65 | }
|
---|
[1603] | 66 |
|
---|
[1625] | 67 | @Test(expected = java.lang.RuntimeException.class)
|
---|
| 68 | public void testCreateUMLTransitionSequence_1() throws Exception {
|
---|
[1603] | 69 | // parse log file
|
---|
[1926] | 70 | HTTPLogParser parser =
|
---|
| 71 | new HTTPLogParser(new File(ClassLoader.getSystemResource("ita_v2_servicenamemap.txt")
|
---|
| 72 | .getFile()));
|
---|
| 73 | parser.parseFile(new File(ClassLoader.getSystemResource("ita_usagejournal_v2_2.log")
|
---|
[1603] | 74 | .getFile()));
|
---|
| 75 | Collection<List<Event>> httpSequences = parser.getSequences();
|
---|
[1926] | 76 |
|
---|
[1603] | 77 | Model model =
|
---|
[1926] | 78 | ModelUtils.loadModel(ClassLoader.getSystemResourceAsStream("ita_model_v2.uml"));
|
---|
[1603] | 79 |
|
---|
| 80 | StateMachine stateMachine =
|
---|
[1926] | 81 | (StateMachine) model.getPackagedElement("StateMachineTransportService", true,
|
---|
| 82 | UMLPackage.Literals.STATE_MACHINE, true);
|
---|
[1603] | 83 |
|
---|
[1926] | 84 |
|
---|
[1603] | 85 | Collection<List<Event>> umlSequences = new LinkedList<>();
|
---|
[1926] | 86 |
|
---|
| 87 | // remove everything but transport from sequences
|
---|
[1603] | 88 | for (List<Event> httpSequence : httpSequences) {
|
---|
| 89 | for (Iterator<Event> eventIter = httpSequence.iterator(); eventIter.hasNext();) {
|
---|
| 90 | Event event = eventIter.next();
|
---|
| 91 | if (!(event.getType() instanceof SOAPEventType)) {
|
---|
| 92 | eventIter.remove();
|
---|
| 93 | }
|
---|
| 94 | else {
|
---|
[1926] | 95 | SOAPEventType eventType = (SOAPEventType) event.getType();
|
---|
| 96 | if (!"TransportService".equals(eventType.getServiceName())) {
|
---|
[1603] | 97 | eventIter.remove();
|
---|
| 98 | }
|
---|
| 99 | }
|
---|
| 100 | }
|
---|
| 101 | umlSequences.add(UMLUtils.createUMLTransitionSequence(httpSequence, stateMachine));
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
[1625] | 104 |
|
---|
[1603] | 105 | @Test
|
---|
[1625] | 106 | public void testConvertStateMachineToUsageProfile_1() throws Exception {
|
---|
[1926] | 107 | HTTPLogParser parser =
|
---|
| 108 | new HTTPLogParser(new File(ClassLoader.getSystemResource("ita_v2_servicenamemap.txt")
|
---|
| 109 | .getFile()));
|
---|
| 110 | parser.parseFile(new File(ClassLoader.getSystemResource("ita_usagejournal_v2_2.log")
|
---|
[1603] | 111 | .getFile()));
|
---|
| 112 | Collection<List<Event>> httpSequences = parser.getSequences();
|
---|
[1926] | 113 |
|
---|
[1603] | 114 | Model model =
|
---|
[1926] | 115 | ModelUtils.loadModel(ClassLoader.getSystemResourceAsStream("ita_model_v2.uml"));
|
---|
[1603] | 116 |
|
---|
[1926] | 117 | // remove everything but transport from sequences
|
---|
[1603] | 118 | for (List<Event> httpSequence : httpSequences) {
|
---|
| 119 | for (Iterator<Event> eventIter = httpSequence.iterator(); eventIter.hasNext();) {
|
---|
| 120 | Event event = eventIter.next();
|
---|
| 121 | if (!(event.getType() instanceof SOAPEventType)) {
|
---|
| 122 | eventIter.remove();
|
---|
| 123 | }
|
---|
| 124 | else {
|
---|
[1926] | 125 | SOAPEventType eventType = (SOAPEventType) event.getType();
|
---|
| 126 | if (!"TransportService".equals(eventType.getServiceName())) {
|
---|
[1603] | 127 | eventIter.remove();
|
---|
| 128 | }
|
---|
| 129 | }
|
---|
| 130 | }
|
---|
| 131 | }
|
---|
[1625] | 132 |
|
---|
[1926] | 133 | StateMachine stateMachine =
|
---|
| 134 | (StateMachine) model.getPackagedElement("StateMachineTransportService", true,
|
---|
| 135 | UMLPackage.Literals.STATE_MACHINE, true);
|
---|
| 136 |
|
---|
| 137 | UMLUtils.convertStateMachineToUsageProfile(httpSequences, stateMachine);
|
---|
| 138 |
|
---|
| 139 | ModelUtils.writeModelToFile(model, OUTPUT_DIR + "ita_v2_result.uml");
|
---|
[1603] | 140 | }
|
---|
[1625] | 141 |
|
---|
| 142 | @Test
|
---|
| 143 | public void testCreateInteractionFromEventSequence_1() throws Exception {
|
---|
| 144 | // parse log file
|
---|
| 145 | HTTPLogParser parser =
|
---|
| 146 | new HTTPLogParser(new File(ClassLoader
|
---|
[1643] | 147 | .getSystemResource("testCreateInteractionFromEventSequence_1_properties.txt")
|
---|
| 148 | .getFile()));
|
---|
| 149 | parser
|
---|
| 150 | .parseFile(new File(ClassLoader
|
---|
| 151 | .getSystemResource("testCreateInteractionFromEventSequence_1_usagedata.log")
|
---|
| 152 | .getFile()));
|
---|
[1625] | 153 | Collection<List<Event>> httpSequences = parser.getSequences();
|
---|
[1759] | 154 |
|
---|
[1625] | 155 | Model model =
|
---|
[1759] | 156 | ModelUtils.loadModel(ClassLoader
|
---|
[1625] | 157 | .getSystemResourceAsStream("testCreateInteractionFromEventSequence_1_model.uml"));
|
---|
| 158 |
|
---|
| 159 | for (List<Event> httpSequence : httpSequences) {
|
---|
| 160 | for (Iterator<Event> eventIter = httpSequence.iterator(); eventIter.hasNext();) {
|
---|
| 161 | Event event = eventIter.next();
|
---|
| 162 | if (!(event.getType() instanceof SOAPEventType)) {
|
---|
| 163 | eventIter.remove();
|
---|
| 164 | }
|
---|
| 165 | }
|
---|
| 166 |
|
---|
[1896] | 167 | UMLUtils.createInteractionFromEventSequence(httpSequence, model, "testSequence", null);
|
---|
[1625] | 168 | }
|
---|
[1752] | 169 |
|
---|
[1926] | 170 | ModelUtils.writeModelToFile(model, OUTPUT_DIR +
|
---|
| 171 | "testCreateInteractionFromEventSequence_1_result.uml");
|
---|
[1625] | 172 | }
|
---|
[1926] | 173 |
|
---|
[1835] | 174 | @Test
|
---|
| 175 | public void testCreateInteractionFromEventSequence_2() throws Exception {
|
---|
| 176 | // parse log file
|
---|
| 177 | HTTPLogParser parser =
|
---|
| 178 | new HTTPLogParser(new File(ClassLoader
|
---|
| 179 | .getSystemResource("testCreateInteractionFromEventSequence_2_properties.txt")
|
---|
| 180 | .getFile()));
|
---|
| 181 | parser
|
---|
| 182 | .parseFile(new File(ClassLoader
|
---|
| 183 | .getSystemResource("testCreateInteractionFromEventSequence_2_usagedata.log")
|
---|
| 184 | .getFile()));
|
---|
| 185 | Collection<List<Event>> httpSequences = parser.getSequences();
|
---|
[1625] | 186 |
|
---|
[1835] | 187 | Model model =
|
---|
| 188 | ModelUtils.loadModel(ClassLoader
|
---|
| 189 | .getSystemResourceAsStream("testCreateInteractionFromEventSequence_2_model.uml"));
|
---|
| 190 |
|
---|
| 191 | for (List<Event> httpSequence : httpSequences) {
|
---|
| 192 | for (Iterator<Event> eventIter = httpSequence.iterator(); eventIter.hasNext();) {
|
---|
| 193 | Event event = eventIter.next();
|
---|
| 194 | if (!(event.getType() instanceof SOAPEventType)) {
|
---|
| 195 | eventIter.remove();
|
---|
| 196 | }
|
---|
| 197 | }
|
---|
| 198 |
|
---|
[1896] | 199 | UMLUtils.createInteractionFromEventSequence(httpSequence, model, "testSequence", null);
|
---|
[1835] | 200 | }
|
---|
| 201 |
|
---|
[1926] | 202 | ModelUtils.writeModelToFile(model, OUTPUT_DIR +
|
---|
| 203 | "testCreateInteractionFromEventSequence_1_result.uml");
|
---|
[1835] | 204 | }
|
---|
[1926] | 205 |
|
---|
[1896] | 206 | @Test
|
---|
[1643] | 207 | public void testCalculateUsageScore_1() throws Exception {
|
---|
| 208 | // parse log file
|
---|
| 209 | HTTPLogParser parser =
|
---|
| 210 | new HTTPLogParser(new File(ClassLoader
|
---|
| 211 | .getSystemResource("testCalculateUsageScore_1_properties.txt").getFile()));
|
---|
| 212 | parser.parseFile(new File(ClassLoader
|
---|
| 213 | .getSystemResource("testCalculateUsageScore_1_usagedata.log").getFile()));
|
---|
| 214 | Collection<List<Event>> httpSequences = parser.getSequences();
|
---|
[1759] | 215 |
|
---|
[1643] | 216 | Model model =
|
---|
[1759] | 217 | ModelUtils.loadModel(ClassLoader
|
---|
[1643] | 218 | .getSystemResourceAsStream("testCalculateUsageScore_1_model.uml"));
|
---|
| 219 |
|
---|
| 220 | Collection<List<Event>> simpleSOAPSequences = new LinkedList<>();
|
---|
| 221 | for (List<Event> httpSequence : httpSequences) {
|
---|
[1926] | 222 | simpleSOAPSequences.add(SOAPUtils.convertToSimpleSOAPEvent(httpSequence, true));
|
---|
[1643] | 223 | }
|
---|
| 224 |
|
---|
| 225 | FirstOrderMarkovModel usageProfile = new FirstOrderMarkovModel(new Random(1));
|
---|
| 226 | usageProfile.train(simpleSOAPSequences);
|
---|
| 227 |
|
---|
| 228 | Collection<List<Event>> genSeqs =
|
---|
| 229 | (new RandomWalkGenerator(10, 1, 100, true, 500)).generateTestSuite(usageProfile);
|
---|
| 230 |
|
---|
| 231 | int i = 1;
|
---|
| 232 | int[] lengths = new int[genSeqs.size()];
|
---|
| 233 | for (List<Event> seq : genSeqs) {
|
---|
[1896] | 234 | UMLUtils.createInteractionFromEventSequence(seq, model, "seq_" + i, null);
|
---|
[1643] | 235 | lengths[i - 1] = seq.size();
|
---|
| 236 | i++;
|
---|
| 237 | }
|
---|
| 238 | for (int j = 0; j < genSeqs.size(); j++) {
|
---|
| 239 | Interaction interaction =
|
---|
| 240 | (Interaction) model.getPackagedElement("seq_" + j, true,
|
---|
| 241 | UMLPackage.Literals.INTERACTION, true);
|
---|
| 242 | double usageScore = UMLUtils.calculateUsageScore(interaction, usageProfile);
|
---|
[1752] | 243 | System.out.format("usage score %02d: %.2f \t %d\n", j + 1, usageScore, lengths[j]);
|
---|
[1643] | 244 | }
|
---|
| 245 | }
|
---|
[1926] | 246 |
|
---|
[1763] | 247 | @Test
|
---|
| 248 | public void testCreateScheduling_1() throws Exception {
|
---|
| 249 | Model model =
|
---|
[1926] | 250 | ModelUtils.loadModel(ClassLoader
|
---|
| 251 | .getSystemResourceAsStream("testCreateScheduling_1_testsuite.uml"));
|
---|
| 252 |
|
---|
| 253 | IStochasticProcess usageProfile =
|
---|
| 254 | (IStochasticProcess) SerializationUtils.deserialize(ClassLoader
|
---|
| 255 | .getSystemResourceAsStream("testCreateScheduling_1_usageprofile.dat"));
|
---|
| 256 |
|
---|
[1896] | 257 | UMLUtils.createScheduling(model, usageProfile, null);
|
---|
[1926] | 258 |
|
---|
[1763] | 259 | ModelUtils.writeModelToFile(model, OUTPUT_DIR + "testCreateScheduling_1_result.uml");
|
---|
| 260 | }
|
---|
[1926] | 261 |
|
---|
[1898] | 262 | @Test
|
---|
| 263 | public void testValidateModelWithLog_1() throws Exception {
|
---|
| 264 | HTTPLogParser parser =
|
---|
[1926] | 265 | new HTTPLogParser(new File(ClassLoader
|
---|
| 266 | .getSystemResource("testCreateInteractionFromEventSequence_1_properties.txt")
|
---|
| 267 | .getFile()));
|
---|
[1898] | 268 | parser
|
---|
| 269 | .parseFile(new File(ClassLoader
|
---|
| 270 | .getSystemResource("testCreateInteractionFromEventSequence_1_usagedata.log")
|
---|
| 271 | .getFile()));
|
---|
| 272 | Collection<List<Event>> httpSequences = parser.getSequences();
|
---|
[1643] | 273 |
|
---|
[1926] | 274 | for (List<Event> httpSequence : httpSequences) {
|
---|
| 275 | SOAPUtils.removeNonSOAPEvents(httpSequence);
|
---|
| 276 | }
|
---|
[1898] | 277 |
|
---|
| 278 | Model model =
|
---|
| 279 | ModelUtils.loadModel(ClassLoader
|
---|
| 280 | .getSystemResourceAsStream("testCreateInteractionFromEventSequence_1_model.uml"));
|
---|
[1926] | 281 |
|
---|
[1900] | 282 | int violations = UMLUtils.validateModelWithLog(httpSequences, model, null);
|
---|
[1926] | 283 | if (violations == 0) {
|
---|
[1900] | 284 | System.out.println("No problems found.");
|
---|
| 285 | }
|
---|
[1926] | 286 | else {
|
---|
| 287 | System.out.println(violations + " violations found.");
|
---|
| 288 | }
|
---|
[1898] | 289 | }
|
---|
[1926] | 290 |
|
---|
[1898] | 291 | @Test
|
---|
| 292 | public void testValidateModelWithLog_2() throws Exception {
|
---|
| 293 | HTTPLogParser parser =
|
---|
[1926] | 294 | new HTTPLogParser(new File(ClassLoader
|
---|
| 295 | .getSystemResource("testCreateInteractionFromEventSequence_2_properties.txt")
|
---|
| 296 | .getFile()));
|
---|
[1898] | 297 | parser
|
---|
| 298 | .parseFile(new File(ClassLoader
|
---|
| 299 | .getSystemResource("testCreateInteractionFromEventSequence_2_usagedata.log")
|
---|
| 300 | .getFile()));
|
---|
| 301 | Collection<List<Event>> httpSequences = parser.getSequences();
|
---|
| 302 |
|
---|
[1926] | 303 | for (List<Event> httpSequence : httpSequences) {
|
---|
| 304 | SOAPUtils.removeNonSOAPEvents(httpSequence);
|
---|
| 305 | }
|
---|
[1898] | 306 |
|
---|
| 307 | Model model =
|
---|
| 308 | ModelUtils.loadModel(ClassLoader
|
---|
| 309 | .getSystemResourceAsStream("testCreateInteractionFromEventSequence_2_model.uml"));
|
---|
[1926] | 310 |
|
---|
[1900] | 311 | int violations = UMLUtils.validateModelWithLog(httpSequences, model, null);
|
---|
[1926] | 312 | if (violations == 0) {
|
---|
[1900] | 313 | System.out.println("No problems found.");
|
---|
[1926] | 314 | }
|
---|
| 315 | else {
|
---|
[1900] | 316 | System.out.println(violations + " violations found.");
|
---|
| 317 | }
|
---|
[1898] | 318 | }
|
---|
[1926] | 319 |
|
---|
[1898] | 320 | @Test
|
---|
[1914] | 321 | public void testValidateModelWithLog_HL7_RLUS_v3() throws Exception {
|
---|
[1898] | 322 | HTTPLogParser parser =
|
---|
[1926] | 323 | new HTTPLogParser(new File(ClassLoader.getSystemResource("hl7_servicenamemap.txt")
|
---|
| 324 | .getFile()));
|
---|
[1898] | 325 | parser
|
---|
| 326 | .parseFile(new File(ClassLoader
|
---|
| 327 | .getSystemResource("testCreateInteractionFromEventSequence_1_usagedata.log")
|
---|
| 328 | .getFile()));
|
---|
| 329 | Collection<List<Event>> httpSequences = parser.getSequences();
|
---|
| 330 |
|
---|
[1926] | 331 | for (List<Event> httpSequence : httpSequences) {
|
---|
| 332 | SOAPUtils.removeNonSOAPEvents(httpSequence);
|
---|
| 333 | }
|
---|
[1898] | 334 |
|
---|
| 335 | Model model =
|
---|
[1926] | 336 | ModelUtils.loadModel(ClassLoader.getSystemResourceAsStream("hl7model_v3.uml"));
|
---|
| 337 |
|
---|
[1914] | 338 | int violations = UMLUtils.validateModelWithLog(httpSequences, model, "RLUSTestSuite_1");
|
---|
[1926] | 339 | if (violations == 0) {
|
---|
[1914] | 340 | System.out.println("No problems found.");
|
---|
[1926] | 341 | }
|
---|
| 342 | else {
|
---|
[1914] | 343 | System.out.println(violations + " violations found.");
|
---|
| 344 | }
|
---|
[1926] | 345 |
|
---|
[1914] | 346 | // remove everything but rlusService from sequences
|
---|
| 347 | for (List<Event> httpSequence : httpSequences) {
|
---|
| 348 | for (Iterator<Event> eventIter = httpSequence.iterator(); eventIter.hasNext();) {
|
---|
| 349 | Event event = eventIter.next();
|
---|
[1926] | 350 | SOAPEventType eventType = (SOAPEventType) event.getType();
|
---|
| 351 | if (!"rlusService".equals(eventType.getServiceName()) ) {
|
---|
[1914] | 352 | eventIter.remove();
|
---|
| 353 | }
|
---|
| 354 | }
|
---|
[1926] | 355 |
|
---|
| 356 | UMLUtils.createInteractionFromEventSequence(httpSequence, model, "rlustest1",
|
---|
| 357 | "RLUSTestSuite_1");
|
---|
| 358 | UMLUtils.createInteractionFromEventSequence(SOAPUtils.convertToSimpleSOAPEvent(httpSequence, true), model, "rlustest2",
|
---|
| 359 | "RLUSTestSuite_1");
|
---|
[1914] | 360 | }
|
---|
[1926] | 361 |
|
---|
[1914] | 362 | ModelUtils.writeModelToFile(model, OUTPUT_DIR + "hl7_v3_result.uml");
|
---|
| 363 | }
|
---|
[1926] | 364 |
|
---|
[1914] | 365 | @Test
|
---|
| 366 | public void testValidateModelWithLog_HL7_IXS_v3() throws Exception {
|
---|
| 367 | HTTPLogParser parser =
|
---|
[1926] | 368 | new HTTPLogParser(new File(ClassLoader.getSystemResource("hl7_ixs_servicenamemap.txt")
|
---|
| 369 | .getFile()));
|
---|
[1914] | 370 | parser
|
---|
| 371 | .parseFile(new File(ClassLoader
|
---|
| 372 | .getSystemResource("testCreateInteractionFromEventSequence_1_usagedata.log")
|
---|
| 373 | .getFile()));
|
---|
| 374 | Collection<List<Event>> httpSequences = parser.getSequences();
|
---|
| 375 |
|
---|
[1926] | 376 | for (List<Event> httpSequence : httpSequences) {
|
---|
| 377 | SOAPUtils.removeNonSOAPEvents(httpSequence);
|
---|
| 378 | }
|
---|
[1914] | 379 |
|
---|
| 380 | Model model =
|
---|
[1926] | 381 | ModelUtils.loadModel(ClassLoader.getSystemResourceAsStream("hl7model_v3.uml"));
|
---|
| 382 |
|
---|
[1900] | 383 | int violations = UMLUtils.validateModelWithLog(httpSequences, model, "IXSTestSuite_1");
|
---|
[1926] | 384 | if (violations == 0) {
|
---|
[1900] | 385 | System.out.println("No problems found.");
|
---|
[1926] | 386 | }
|
---|
| 387 | else {
|
---|
[1900] | 388 | System.out.println(violations + " violations found.");
|
---|
| 389 | }
|
---|
[1926] | 390 |
|
---|
[1914] | 391 | // remove everything but rlusService from sequences
|
---|
| 392 | for (List<Event> httpSequence : httpSequences) {
|
---|
| 393 | for (Iterator<Event> eventIter = httpSequence.iterator(); eventIter.hasNext();) {
|
---|
| 394 | Event event = eventIter.next();
|
---|
[1926] | 395 | SOAPEventType eventType = (SOAPEventType) event.getType();
|
---|
| 396 | if (!"ixsService".equals(eventType.getServiceName())) {
|
---|
[1914] | 397 | eventIter.remove();
|
---|
| 398 | }
|
---|
| 399 | }
|
---|
[1926] | 400 |
|
---|
| 401 | UMLUtils.createInteractionFromEventSequence(httpSequence, model, "foo",
|
---|
| 402 | "IXSTestSuite_1");
|
---|
[1914] | 403 | }
|
---|
[1926] | 404 |
|
---|
[1914] | 405 | ModelUtils.writeModelToFile(model, OUTPUT_DIR + "hl7_v3_result.uml");
|
---|
[1898] | 406 | }
|
---|
[1926] | 407 |
|
---|
[1908] | 408 | @Test
|
---|
| 409 | public void testValidateModelWithLog_ITA_v2() throws Exception {
|
---|
| 410 | HTTPLogParser parser =
|
---|
[1926] | 411 | new HTTPLogParser(new File(ClassLoader.getSystemResource("ita_v2_servicenamemap.txt")
|
---|
[1908] | 412 | .getFile()));
|
---|
[1926] | 413 | parser.parseFile(new File(ClassLoader.getSystemResource("ita_usagejournal_v2_2.log")
|
---|
| 414 | .getFile()));
|
---|
[1908] | 415 | Collection<List<Event>> httpSequences = parser.getSequences();
|
---|
[1926] | 416 |
|
---|
| 417 | for (List<Event> httpSequence : httpSequences) {
|
---|
| 418 | SOAPUtils.removeNonSOAPEvents(httpSequence);
|
---|
| 419 | }
|
---|
[1898] | 420 |
|
---|
[1908] | 421 | Model model =
|
---|
[1926] | 422 | ModelUtils.loadModel(ClassLoader.getSystemResourceAsStream("ita_model_v2.uml"));
|
---|
| 423 |
|
---|
[1908] | 424 | int violations = UMLUtils.validateModelWithLog(httpSequences, model, null);
|
---|
[1926] | 425 | if (violations == 0) {
|
---|
[1908] | 426 | System.out.println("No problems found.");
|
---|
[1926] | 427 | }
|
---|
| 428 | else {
|
---|
[1908] | 429 | System.out.println(violations + " violations found.");
|
---|
| 430 | }
|
---|
[1926] | 431 |
|
---|
[1908] | 432 | // remove everything but transport from sequences
|
---|
| 433 | for (List<Event> httpSequence : httpSequences) {
|
---|
| 434 | for (Iterator<Event> eventIter = httpSequence.iterator(); eventIter.hasNext();) {
|
---|
| 435 | Event event = eventIter.next();
|
---|
[1926] | 436 | SOAPEventType eventType = (SOAPEventType) event.getType();
|
---|
| 437 | if (!"TransportService".equals(eventType.getServiceName())) {
|
---|
[1908] | 438 | eventIter.remove();
|
---|
| 439 | }
|
---|
| 440 | }
|
---|
[1926] | 441 |
|
---|
| 442 | UMLUtils.createInteractionFromEventSequence(httpSequence, model, "foo",
|
---|
| 443 | "LogisticsTestSuite");
|
---|
[1908] | 444 | }
|
---|
[1926] | 445 |
|
---|
[1908] | 446 | ModelUtils.writeModelToFile(model, OUTPUT_DIR + "ita_v2_result.uml");
|
---|
[1926] | 447 |
|
---|
[1908] | 448 | }
|
---|
| 449 |
|
---|
[1625] | 450 | private void deleteFiles(File file) {
|
---|
| 451 | if (file.exists()) {
|
---|
| 452 | if (file.isDirectory()) {
|
---|
| 453 | for (File child : file.listFiles()) {
|
---|
| 454 | deleteFiles(child);
|
---|
| 455 | }
|
---|
| 456 | }
|
---|
[1603] | 457 |
|
---|
[1625] | 458 | try {
|
---|
| 459 | file.delete();
|
---|
| 460 | }
|
---|
| 461 | catch (Exception e) {
|
---|
| 462 | // ignore and delete as much as possible
|
---|
| 463 | }
|
---|
| 464 | }
|
---|
| 465 | }
|
---|
| 466 |
|
---|
[1603] | 467 | }
|
---|