[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;
|
---|
[1927] | 18 | import java.io.FileInputStream;
|
---|
[1929] | 19 | import java.io.FileOutputStream;
|
---|
[1603] | 20 | import java.util.Collection;
|
---|
| 21 | import java.util.LinkedList;
|
---|
| 22 | import java.util.List;
|
---|
[1927] | 23 | import java.util.Properties;
|
---|
[1643] | 24 | import java.util.Random;
|
---|
[1898] | 25 | import java.util.logging.Level;
|
---|
[1603] | 26 |
|
---|
[1931] | 27 | import static org.junit.Assert.*;
|
---|
[1926] | 28 |
|
---|
[1643] | 29 | import org.eclipse.uml2.uml.Interaction;
|
---|
[1603] | 30 | import org.eclipse.uml2.uml.Model;
|
---|
| 31 | import org.eclipse.uml2.uml.StateMachine;
|
---|
| 32 | import org.eclipse.uml2.uml.UMLPackage;
|
---|
| 33 | import org.junit.After;
|
---|
[1898] | 34 | import org.junit.BeforeClass;
|
---|
[1603] | 35 | import org.junit.Test;
|
---|
| 36 |
|
---|
[1759] | 37 | import de.fraunhofer.fokus.testing.ModelUtils;
|
---|
[1603] | 38 | import de.ugoe.cs.autoquest.eventcore.Event;
|
---|
| 39 | import de.ugoe.cs.autoquest.plugin.http.HTTPLogParser;
|
---|
[1926] | 40 | import de.ugoe.cs.autoquest.plugin.http.SOAPUtils;
|
---|
[1929] | 41 | import de.ugoe.cs.autoquest.plugin.http.eventcore.SimpleSOAPEventType;
|
---|
[1643] | 42 | import de.ugoe.cs.autoquest.testgeneration.RandomWalkGenerator;
|
---|
| 43 | import de.ugoe.cs.autoquest.usageprofiles.FirstOrderMarkovModel;
|
---|
[1763] | 44 | import de.ugoe.cs.autoquest.usageprofiles.IStochasticProcess;
|
---|
[1929] | 45 | import de.ugoe.cs.util.SerializationUtils;
|
---|
[1898] | 46 | import de.ugoe.cs.util.console.TextConsole;
|
---|
[1603] | 47 |
|
---|
| 48 | /**
|
---|
| 49 | * <p>
|
---|
| 50 | * Tests for AutoQUESTs UMLUtils
|
---|
| 51 | * </p>
|
---|
| 52 | *
|
---|
| 53 | * @author Steffen Herbold
|
---|
| 54 | */
|
---|
| 55 | public class UMLUtilsTest {
|
---|
[1625] | 56 |
|
---|
[1606] | 57 | private final static String OUTPUT_DIR = "target/tmp/test-outputs/";
|
---|
[1929] | 58 |
|
---|
| 59 | private final static boolean DELETE_OUTPUTS = false;
|
---|
| 60 |
|
---|
[1927] | 61 | // for RLUS
|
---|
| 62 | private final static TestData deda_1 = new TestData("deda_rlus_properties.prop",
|
---|
[1929] | 63 | "deda_usagejournal.log",
|
---|
| 64 | "deda_rlus_usageprofile.dat",
|
---|
| 65 | "deda_model.uml",
|
---|
| 66 | "deda_rlus_model_testsuite.uml",
|
---|
| 67 | "deda_rlus_model_scheduling.uml");
|
---|
[1625] | 68 |
|
---|
[1927] | 69 | // for IXS
|
---|
| 70 | private final static TestData deda_2 = new TestData("deda_ixs_properties.prop",
|
---|
[1929] | 71 | "deda_usagejournal.log",
|
---|
| 72 | "deda_ixs_usageprofile.dat",
|
---|
| 73 | "deda_model.uml",
|
---|
| 74 | "deda_ixs_model_testsuite.uml",
|
---|
| 75 | "deda_ixs_model_scheduling.uml");
|
---|
[1927] | 76 |
|
---|
[1979] | 77 | private final static TestData ita_1 = new TestData("ita_imported_properties.prop",
|
---|
| 78 | "ita_imported_usagejournal.log",
|
---|
| 79 | "ita_imported_usageprofile.dat",
|
---|
| 80 | "ita_imported_model.uml",
|
---|
| 81 | "ita_imported_model_testsuite.uml",
|
---|
| 82 | "ita_imported_model_scheduling.uml");
|
---|
[1929] | 83 |
|
---|
[1927] | 84 | private static class TestData {
|
---|
| 85 | public final String propertiesFile;
|
---|
| 86 | public final String usageJournalFile;
|
---|
| 87 | public final String usageProfileFile;
|
---|
| 88 | public final String dslModelFile;
|
---|
| 89 | public final String testSuiteFile;
|
---|
| 90 | public final String schedulingFile;
|
---|
| 91 |
|
---|
| 92 | public TestData(String propertiesFile,
|
---|
[1929] | 93 | String usageJournalFile,
|
---|
| 94 | String usageProfileFile,
|
---|
| 95 | String dslModelFile,
|
---|
| 96 | String testSuiteFile,
|
---|
| 97 | String schedulingFile)
|
---|
[1927] | 98 | {
|
---|
| 99 | this.propertiesFile = propertiesFile;
|
---|
| 100 | this.usageJournalFile = usageJournalFile;
|
---|
| 101 | this.usageProfileFile = usageProfileFile;
|
---|
| 102 | this.dslModelFile = dslModelFile;
|
---|
| 103 | this.testSuiteFile = testSuiteFile;
|
---|
| 104 | this.schedulingFile = schedulingFile;
|
---|
[1929] | 105 |
|
---|
[1927] | 106 | }
|
---|
| 107 |
|
---|
| 108 | @Override
|
---|
| 109 | public String toString() {
|
---|
| 110 | StringBuilder strBld = new StringBuilder();
|
---|
| 111 | strBld.append("Properties " + propertiesFile + "\n");
|
---|
| 112 | strBld.append("Usage Journal " + usageJournalFile + "\n");
|
---|
| 113 | strBld.append("Usage Profile " + usageProfileFile + "\n");
|
---|
| 114 | strBld.append("DSL Model " + dslModelFile + "\n");
|
---|
| 115 | strBld.append("Test Suite " + testSuiteFile + "\n");
|
---|
| 116 | strBld.append("Scheduling " + schedulingFile + "\n");
|
---|
| 117 | return strBld.toString();
|
---|
| 118 | }
|
---|
| 119 | }
|
---|
| 120 |
|
---|
[1898] | 121 | @BeforeClass
|
---|
| 122 | public static void setUpBeforeClass() throws Exception {
|
---|
[1979] | 123 | new TextConsole(Level.FINE);
|
---|
[1898] | 124 | }
|
---|
[1926] | 125 |
|
---|
[1625] | 126 | @After
|
---|
| 127 | public void tearDown() throws Exception {
|
---|
[1929] | 128 | if (DELETE_OUTPUTS) {
|
---|
| 129 | deleteFiles(new File(OUTPUT_DIR));
|
---|
| 130 | }
|
---|
[1625] | 131 | }
|
---|
[1603] | 132 |
|
---|
[1931] | 133 | @Test
|
---|
[1927] | 134 | public void testCreateUMLTransitionSequence_ITA_1() throws Exception {
|
---|
| 135 | TestData testdata = ita_1;
|
---|
[1929] | 136 |
|
---|
[1931] | 137 | /*
|
---|
| 138 | * Properties properties = loadProperties(testdata); //Collection<List<Event>> sequences =
|
---|
| 139 | * loadAndPreprocessUsageJournal(testdata, properties);
|
---|
| 140 | *
|
---|
[1979] | 141 | * Model model = ModelUtils.loadModel(new
|
---|
| 142 | * File(ClassLoader.getSystemResource(testdata.dslModelFile).getFile()));
|
---|
[1931] | 143 | *
|
---|
| 144 | * StateMachine stateMachine = (StateMachine)
|
---|
| 145 | * model.getPackagedElement("StateMachineTransportService", true,
|
---|
| 146 | * UMLPackage.Literals.STATE_MACHINE, true);
|
---|
| 147 | *
|
---|
| 148 | *
|
---|
| 149 | * Collection<List<Event>> umlSequences = new LinkedList<>();
|
---|
| 150 | *
|
---|
| 151 | * // remove everything but transport from sequences for (List<Event> sequence : sequences)
|
---|
| 152 | * { for (Iterator<Event> eventIter = sequence.iterator(); eventIter.hasNext();) { Event
|
---|
| 153 | * event = eventIter.next(); if
|
---|
| 154 | * (!"TransportService".equals(SOAPUtils.getServiceNameFromEvent(event))) {
|
---|
| 155 | * eventIter.remove(); } } umlSequences.add(UMLUtils.createUMLTransitionSequence(sequence,
|
---|
| 156 | * stateMachine)); }
|
---|
| 157 | */
|
---|
| 158 |
|
---|
[1603] | 159 | Model model =
|
---|
[1979] | 160 | ModelUtils.loadModel(new File(ClassLoader.getSystemResource(testdata.dslModelFile)
|
---|
| 161 | .getFile()));
|
---|
[1603] | 162 |
|
---|
| 163 | StateMachine stateMachine =
|
---|
[1929] | 164 | (StateMachine) model.getPackagedElement("StateMachineTransportService", true,
|
---|
| 165 | UMLPackage.Literals.STATE_MACHINE, true);
|
---|
[1603] | 166 |
|
---|
[1931] | 167 | List<Event> manuallyCreatedSequence = new LinkedList<>();
|
---|
| 168 | manuallyCreatedSequence
|
---|
| 169 | .add(new Event(new SimpleSOAPEventType("transportInstructionRequest",
|
---|
| 170 | "TransportService", "Logistics_Environment",
|
---|
[1994] | 171 | null, null, null)));
|
---|
[1931] | 172 | manuallyCreatedSequence
|
---|
| 173 | .add(new Event(new SimpleSOAPEventType("transportInstructionConfirmationRequest",
|
---|
| 174 | "materialSupplierService",
|
---|
[1994] | 175 | "Logistics_Environment", null, null, null)));
|
---|
[1929] | 176 |
|
---|
[1942] | 177 | // TODO make test case run
|
---|
[1979] | 178 | // UMLUtils.createUMLTransitionSequence(manuallyCreatedSequence, stateMachine);
|
---|
[1603] | 179 | }
|
---|
[1625] | 180 |
|
---|
[1603] | 181 | @Test
|
---|
[1927] | 182 | public void testConvertStateMachineToUsageProfile__ITA_1() throws Exception {
|
---|
[1942] | 183 | // TODO make test run
|
---|
[1979] | 184 | /*
|
---|
| 185 | * TestData testdata = ita_1;
|
---|
| 186 | *
|
---|
| 187 | * assertTrue("test currently not working", false);
|
---|
| 188 | *
|
---|
| 189 | * Properties properties = loadProperties(testdata); Collection<List<Event>> sequences =
|
---|
| 190 | * loadAndPreprocessUsageJournal(testdata, properties); Model model =
|
---|
| 191 | * ModelUtils.loadModel(ClassLoader.getSystemResourceAsStream(testdata.dslModelFile));
|
---|
| 192 | * StateMachine stateMachine = (StateMachine)
|
---|
| 193 | * model.getPackagedElement("StateMachineTransportService", true,
|
---|
| 194 | * UMLPackage.Literals.STATE_MACHINE, true);
|
---|
| 195 | *
|
---|
| 196 | * Collection<List<Event>> umlSequences = new LinkedList<>();
|
---|
| 197 | *
|
---|
| 198 | * // remove everything but transport from sequences for (List<Event> sequence : sequences)
|
---|
| 199 | * { for (Iterator<Event> eventIter = sequence.iterator(); eventIter.hasNext();) { Event
|
---|
| 200 | * event = eventIter.next(); if
|
---|
| 201 | * (!"TransportService".equals(SOAPUtils.getServiceNameFromEvent(event))) {
|
---|
| 202 | * eventIter.remove(); } } umlSequences.add(UMLUtils.createUMLTransitionSequence(sequence,
|
---|
| 203 | * stateMachine)); }
|
---|
| 204 | *
|
---|
| 205 | * UMLUtils.convertStateMachineToUsageProfile(umlSequences, stateMachine);
|
---|
| 206 | *
|
---|
| 207 | * ModelUtils.writeModelToFile(model, OUTPUT_DIR + "ita_v2_result.uml");
|
---|
| 208 | */
|
---|
[1603] | 209 | }
|
---|
[1625] | 210 |
|
---|
| 211 | @Test
|
---|
[1927] | 212 | public void testCreateInteractionFromEventSequence_DEDA_1() throws Exception {
|
---|
| 213 | createInteractionFromEventSequenceWorkflow(deda_1);
|
---|
| 214 | }
|
---|
[1929] | 215 |
|
---|
[1927] | 216 | @Test
|
---|
| 217 | public void testCreateInteractionFromEventSequence_DEDA_2() throws Exception {
|
---|
| 218 | createInteractionFromEventSequenceWorkflow(deda_2);
|
---|
| 219 | }
|
---|
[1929] | 220 |
|
---|
[1927] | 221 | @Test
|
---|
| 222 | public void testCreateInteractionFromEventSequence_ITA_1() throws Exception {
|
---|
| 223 | createInteractionFromEventSequenceWorkflow(ita_1);
|
---|
| 224 | }
|
---|
[1759] | 225 |
|
---|
[1927] | 226 | @Test
|
---|
| 227 | public void testCalculateUsageScore_DEDA_1() throws Exception {
|
---|
| 228 | calculateUsageScoreWorkflow(deda_1);
|
---|
| 229 | }
|
---|
[1929] | 230 |
|
---|
[1927] | 231 | @Test
|
---|
| 232 | public void testCalculateUsageScore_DEDA_2() throws Exception {
|
---|
| 233 | calculateUsageScoreWorkflow(deda_2);
|
---|
| 234 | }
|
---|
[1625] | 235 |
|
---|
[1927] | 236 | @Test
|
---|
| 237 | public void testCalculateUsageScore_ITA_1() throws Exception {
|
---|
| 238 | calculateUsageScoreWorkflow(ita_1);
|
---|
[1625] | 239 | }
|
---|
[1926] | 240 |
|
---|
[1835] | 241 | @Test
|
---|
[1927] | 242 | public void testCreateScheduling_DEDA_1() throws Exception {
|
---|
| 243 | createSchedulingWorkflow(deda_1);
|
---|
[1835] | 244 | }
|
---|
[1929] | 245 |
|
---|
[1927] | 246 | @Test
|
---|
| 247 | public void testCreateScheduling_DEDA_2() throws Exception {
|
---|
| 248 | createSchedulingWorkflow(deda_2);
|
---|
| 249 | }
|
---|
[1929] | 250 |
|
---|
[1927] | 251 | @Test
|
---|
| 252 | public void testCreateScheduling_ITA() throws Exception {
|
---|
| 253 | createSchedulingWorkflow(ita_1);
|
---|
| 254 | }
|
---|
[1926] | 255 |
|
---|
[1896] | 256 | @Test
|
---|
[1927] | 257 | public void testValidateModelWithLog_DEDA_1() throws Exception {
|
---|
| 258 | validateModelWithLogWorkflow(deda_1);
|
---|
[1643] | 259 | }
|
---|
[1926] | 260 |
|
---|
[1763] | 261 | @Test
|
---|
[1927] | 262 | public void testValidateModelWithLog_DEDA_2() throws Exception {
|
---|
| 263 | validateModelWithLogWorkflow(deda_2);
|
---|
[1763] | 264 | }
|
---|
[1926] | 265 |
|
---|
[1898] | 266 | @Test
|
---|
[1927] | 267 | public void testValidateModelWithLog_ITA_1() throws Exception {
|
---|
| 268 | validateModelWithLogWorkflow(ita_1);
|
---|
| 269 | }
|
---|
[1994] | 270 |
|
---|
| 271 | @Test
|
---|
| 272 | public void testSerialization_ITA_1() throws Exception {
|
---|
| 273 | TestData testdata = ita_1;
|
---|
| 274 | Properties properties = loadProperties(testdata);
|
---|
| 275 | Collection<List<Event>> sequences = loadAndPreprocessUsageJournal(testdata, properties);
|
---|
| 276 | IStochasticProcess model = createUsageProfile(testdata, sequences);
|
---|
| 277 | byte[] serialized = SerializationUtils.serialize(model);
|
---|
| 278 | SerializationUtils.deserialize(serialized);
|
---|
| 279 | }
|
---|
[1929] | 280 |
|
---|
[1927] | 281 | private void validateModelWithLogWorkflow(TestData testdata) throws Exception {
|
---|
| 282 | Properties properties = loadProperties(testdata);
|
---|
| 283 | Collection<List<Event>> sequences = loadAndPreprocessUsageJournal(testdata, properties);
|
---|
[1929] | 284 | Model model =
|
---|
[1979] | 285 | ModelUtils.loadModel(new File(ClassLoader.getSystemResource(testdata.dslModelFile)
|
---|
| 286 | .getFile()));
|
---|
[1929] | 287 |
|
---|
[1927] | 288 | // run validation
|
---|
[1929] | 289 | int violations =
|
---|
| 290 | UMLUtils.validateModelWithLog(sequences, model, properties.getProperty("test.context"));
|
---|
[1926] | 291 | if (violations == 0) {
|
---|
[1900] | 292 | System.out.println("No problems found.");
|
---|
| 293 | }
|
---|
[1926] | 294 | else {
|
---|
| 295 | System.out.println(violations + " violations found.");
|
---|
| 296 | }
|
---|
[1898] | 297 | }
|
---|
[1929] | 298 |
|
---|
[1927] | 299 | private void createInteractionFromEventSequenceWorkflow(TestData testdata) throws Exception {
|
---|
| 300 | Properties properties = loadProperties(testdata);
|
---|
| 301 | Collection<List<Event>> sequences = loadAndPreprocessUsageJournal(testdata, properties);
|
---|
[1929] | 302 | Model model =
|
---|
[1979] | 303 | ModelUtils.loadModel(new File(ClassLoader.getSystemResource(testdata.dslModelFile)
|
---|
| 304 | .getFile()));
|
---|
[1929] | 305 |
|
---|
[1927] | 306 | // create a test case for each observed sequence
|
---|
[1929] | 307 | int i = 0;
|
---|
| 308 | for (List<Event> sequence : sequences) {
|
---|
| 309 | UMLUtils.createInteractionFromEventSequence(sequence, model,
|
---|
| 310 | properties.getProperty("testcases.prefix") +
|
---|
| 311 | "_" + i,
|
---|
[1989] | 312 | properties.getProperty("test.context"),
|
---|
| 313 | false);
|
---|
[1927] | 314 | i++;
|
---|
[1926] | 315 | }
|
---|
[1929] | 316 |
|
---|
| 317 | ModelUtils.writeModelToFile(model, OUTPUT_DIR + testdata.testSuiteFile);
|
---|
[1927] | 318 | }
|
---|
[1929] | 319 |
|
---|
[1927] | 320 | private void calculateUsageScoreWorkflow(TestData testdata) throws Exception {
|
---|
| 321 | Properties properties = loadProperties(testdata);
|
---|
| 322 | Collection<List<Event>> sequences = loadAndPreprocessUsageJournal(testdata, properties);
|
---|
[1898] | 323 | Model model =
|
---|
[1979] | 324 | ModelUtils.loadModel(new File(ClassLoader.getSystemResource(testdata.dslModelFile)
|
---|
| 325 | .getFile()));
|
---|
[1929] | 326 | IStochasticProcess usageProfile = createUsageProfile(testdata, sequences);
|
---|
| 327 | Collection<List<Event>> generatedSequences =
|
---|
| 328 | createRandomSequences(usageProfile, properties);
|
---|
| 329 |
|
---|
[1927] | 330 | int i = 1;
|
---|
[1929] | 331 | List<Interaction> interactions = new LinkedList<>();
|
---|
[1927] | 332 | int[] lengths = new int[generatedSequences.size()];
|
---|
| 333 | for (List<Event> sequence : generatedSequences) {
|
---|
[1931] | 334 | interactions.add(UMLUtils
|
---|
| 335 | .createInteractionFromEventSequence(sequence, model,
|
---|
| 336 | properties.getProperty("testcases.prefix") +
|
---|
| 337 | "_" + i,
|
---|
[1989] | 338 | properties.getProperty("test.context"),
|
---|
[1992] | 339 | Boolean.parseBoolean(properties.getProperty("testcases.data.random", "false"))));
|
---|
[1927] | 340 | lengths[i - 1] = sequence.size();
|
---|
| 341 | i++;
|
---|
[1926] | 342 | }
|
---|
[1929] | 343 | for (int j = 0; j < interactions.size(); j++) {
|
---|
| 344 | double usageScore = UMLUtils.calculateUsageScore(interactions.get(j), usageProfile);
|
---|
[1927] | 345 | System.out.format("usage score %02d: %.2f \t %d\n", j + 1, usageScore, lengths[j]);
|
---|
[1900] | 346 | }
|
---|
[1898] | 347 | }
|
---|
[1929] | 348 |
|
---|
[1927] | 349 | private void createSchedulingWorkflow(TestData testdata) throws Exception {
|
---|
| 350 | Properties properties = loadProperties(testdata);
|
---|
| 351 | Collection<List<Event>> sequences = loadAndPreprocessUsageJournal(testdata, properties);
|
---|
[1929] | 352 | Model model =
|
---|
[1979] | 353 | ModelUtils.loadModel(new File(ClassLoader.getSystemResource(testdata.dslModelFile)
|
---|
| 354 | .getFile()));
|
---|
[1929] | 355 | IStochasticProcess usageProfile = createUsageProfile(testdata, sequences);
|
---|
| 356 | Collection<List<Event>> generatedSequences =
|
---|
| 357 | createRandomSequences(usageProfile, properties);
|
---|
[1927] | 358 | int i = 1;
|
---|
| 359 | for (List<Event> sequence : generatedSequences) {
|
---|
[1929] | 360 | UMLUtils.createInteractionFromEventSequence(sequence, model,
|
---|
| 361 | properties.getProperty("testcases.prefix") +
|
---|
| 362 | "_" + i,
|
---|
[1989] | 363 | properties.getProperty("test.context"),
|
---|
| 364 | true);
|
---|
[1927] | 365 | i++;
|
---|
[1926] | 366 | }
|
---|
| 367 |
|
---|
[1929] | 368 | UMLUtils.createScheduling(model, usageProfile, properties.getProperty("test.context"));
|
---|
| 369 |
|
---|
| 370 | ModelUtils.writeModelToFile(model, OUTPUT_DIR + testdata.schedulingFile);
|
---|
[1914] | 371 | }
|
---|
[1929] | 372 |
|
---|
[1927] | 373 | private Properties loadProperties(TestData testdata) throws Exception {
|
---|
| 374 | Properties properties = new Properties();
|
---|
[1929] | 375 | properties.load(new FileInputStream(ClassLoader.getSystemResource(testdata.propertiesFile)
|
---|
| 376 | .getFile()));
|
---|
[1927] | 377 | return properties;
|
---|
| 378 | }
|
---|
[1929] | 379 |
|
---|
| 380 | private Collection<List<Event>> loadAndPreprocessUsageJournal(TestData testdata,
|
---|
| 381 | Properties properties)
|
---|
| 382 | throws Exception
|
---|
| 383 | {
|
---|
[1927] | 384 | // load usage journal
|
---|
[1914] | 385 | HTTPLogParser parser =
|
---|
[1927] | 386 | new HTTPLogParser(new File(ClassLoader.getSystemResource(testdata.propertiesFile)
|
---|
[1926] | 387 | .getFile()));
|
---|
[1929] | 388 | parser.parseFile(new File(ClassLoader.getSystemResource(testdata.usageJournalFile)
|
---|
| 389 | .getFile()));
|
---|
[1927] | 390 | Collection<List<Event>> sequences = parser.getSequences();
|
---|
[1914] | 391 |
|
---|
[1992] | 392 | sequences = SOAPUtils.removeNonSOAPEvents(sequences);
|
---|
[1993] | 393 | sequences = SOAPUtils.sortAndConvertSequences(sequences, true, true);
|
---|
[1992] | 394 | sequences = SOAPUtils.normalizeOperationNames(sequences, properties
|
---|
[1979] | 395 | .getProperty("methodName.prefixToRemove"), properties
|
---|
| 396 | .getProperty("methodName.suffixToRemove"));
|
---|
[1992] | 397 | sequences = SOAPUtils.removeCallsToIgnoredServices(sequences, properties.getProperty("test.ignored.services"));
|
---|
| 398 |
|
---|
| 399 | return sequences;
|
---|
[1898] | 400 | }
|
---|
| 401 |
|
---|
[1931] | 402 | private IStochasticProcess createUsageProfile(TestData testdata,
|
---|
| 403 | Collection<List<Event>> sequences)
|
---|
[1929] | 404 | throws Exception
|
---|
| 405 | {
|
---|
[1927] | 406 | FirstOrderMarkovModel usageProfile = new FirstOrderMarkovModel(new Random(1));
|
---|
[1929] | 407 | usageProfile.train(sequences);
|
---|
| 408 | FileOutputStream fos = new FileOutputStream(OUTPUT_DIR + testdata.usageProfileFile);
|
---|
| 409 | SerializationUtils.serialize(usageProfile, fos);
|
---|
| 410 | fos.close();
|
---|
[1927] | 411 | return usageProfile;
|
---|
[1908] | 412 | }
|
---|
[1929] | 413 |
|
---|
| 414 | private Collection<List<Event>> createRandomSequences(IStochasticProcess usageProfile,
|
---|
| 415 | Properties properties) throws Exception
|
---|
| 416 | {
|
---|
[1927] | 417 | int numberOfTestCases = Integer.parseInt(properties.getProperty("testcases.number"));
|
---|
| 418 | int testCaseMinLength = Integer.parseInt(properties.getProperty("testcases.minlenth", "1"));
|
---|
[1929] | 419 | int testCaseMaxLength =
|
---|
| 420 | Integer.parseInt(properties.getProperty("testcases.maxlenth", "100"));
|
---|
[1927] | 421 | int maxIter = numberOfTestCases * 100;
|
---|
[1929] | 422 | RandomWalkGenerator testGenerator =
|
---|
| 423 | new RandomWalkGenerator(numberOfTestCases, testCaseMinLength, testCaseMaxLength, true,
|
---|
| 424 | maxIter);
|
---|
[1927] | 425 | return testGenerator.generateTestSuite(usageProfile);
|
---|
| 426 | }
|
---|
[1929] | 427 |
|
---|
[1625] | 428 | private void deleteFiles(File file) {
|
---|
| 429 | if (file.exists()) {
|
---|
| 430 | if (file.isDirectory()) {
|
---|
| 431 | for (File child : file.listFiles()) {
|
---|
| 432 | deleteFiles(child);
|
---|
| 433 | }
|
---|
| 434 | }
|
---|
[1603] | 435 |
|
---|
[1625] | 436 | try {
|
---|
| 437 | file.delete();
|
---|
| 438 | }
|
---|
| 439 | catch (Exception e) {
|
---|
| 440 | // ignore and delete as much as possible
|
---|
| 441 | }
|
---|
| 442 | }
|
---|
| 443 | }
|
---|
| 444 |
|
---|
[1603] | 445 | }
|
---|