- Timestamp:
- 08/01/14 16:03:43 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-plugin-uml-test/src/test/java/de/ugoe/cs/autoquest/plugin/uml/UMLUtilsTest.java
r1628 r1643 24 24 import java.util.List; 25 25 import java.util.Map; 26 import java.util.Random; 26 27 27 28 import org.eclipse.emf.common.util.URI; … … 36 37 import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; 37 38 import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl; 39 import org.eclipse.uml2.uml.Interaction; 38 40 import org.eclipse.uml2.uml.Model; 39 41 import org.eclipse.uml2.uml.StateMachine; … … 47 49 import de.ugoe.cs.autoquest.eventcore.Event; 48 50 import de.ugoe.cs.autoquest.plugin.http.HTTPLogParser; 51 import de.ugoe.cs.autoquest.plugin.http.HTTPUtils; 49 52 import de.ugoe.cs.autoquest.plugin.http.eventcore.SOAPEventType; 50 53 import de.ugoe.cs.autoquest.plugin.uml.eventcore.UMLTransitionType; 54 import de.ugoe.cs.autoquest.testgeneration.RandomWalkGenerator; 55 import de.ugoe.cs.autoquest.usageprofiles.FirstOrderMarkovModel; 51 56 52 57 /** … … 151 156 HTTPLogParser parser = 152 157 new HTTPLogParser(new File(ClassLoader 153 .getSystemResource("testCreateInteractionFromEventSequence_1_properties.txt").getFile())); 154 parser.parseFile(new File(ClassLoader 155 .getSystemResource("testCreateInteractionFromEventSequence_1_usagedata.log").getFile())); 158 .getSystemResource("testCreateInteractionFromEventSequence_1_properties.txt") 159 .getFile())); 160 parser 161 .parseFile(new File(ClassLoader 162 .getSystemResource("testCreateInteractionFromEventSequence_1_usagedata.log") 163 .getFile())); 156 164 Collection<List<Event>> httpSequences = parser.getSequences(); 157 165 Model model = … … 169 177 UMLUtils.createInteractionFromEventSequence(httpSequence, model, "testSequence"); 170 178 } 171 //writeModelToFile(model, "testCreateInteractionFromEventSequence_1_result.uml"); 179 // writeModelToFile(model, "testCreateInteractionFromEventSequence_1_result.uml"); 180 } 181 182 @Test 183 public void testCalculateUsageScore_1() throws Exception { 184 // parse log file 185 HTTPLogParser parser = 186 new HTTPLogParser(new File(ClassLoader 187 .getSystemResource("testCalculateUsageScore_1_properties.txt").getFile())); 188 parser.parseFile(new File(ClassLoader 189 .getSystemResource("testCalculateUsageScore_1_usagedata.log").getFile())); 190 Collection<List<Event>> httpSequences = parser.getSequences(); 191 Model model = 192 loadModelFromInputStream(ClassLoader 193 .getSystemResourceAsStream("testCalculateUsageScore_1_model.uml")); 194 195 Collection<List<Event>> simpleSOAPSequences = new LinkedList<>(); 196 for (List<Event> httpSequence : httpSequences) { 197 for (Iterator<Event> eventIter = httpSequence.iterator(); eventIter.hasNext();) { 198 Event event = eventIter.next(); 199 if (!(event.getType() instanceof SOAPEventType)) { 200 eventIter.remove(); 201 } 202 } 203 simpleSOAPSequences.add(HTTPUtils.convertToSimpleSOAPEvent(httpSequence)); 204 // simpleSOAPSequences.add(httpSequence); 205 } 206 207 FirstOrderMarkovModel usageProfile = new FirstOrderMarkovModel(new Random(1)); 208 usageProfile.train(simpleSOAPSequences); 209 210 Collection<List<Event>> genSeqs = 211 (new RandomWalkGenerator(10, 1, 100, true, 500)).generateTestSuite(usageProfile); 212 213 int i = 1; 214 int[] lengths = new int[genSeqs.size()]; 215 for (List<Event> seq : genSeqs) { 216 UMLUtils.createInteractionFromEventSequence(seq, model, "seq_" + i); 217 lengths[i - 1] = seq.size(); 218 i++; 219 } 220 for (int j = 0; j < genSeqs.size(); j++) { 221 Interaction interaction = 222 (Interaction) model.getPackagedElement("seq_" + j, true, 223 UMLPackage.Literals.INTERACTION, true); 224 double usageScore = UMLUtils.calculateUsageScore(interaction, usageProfile); 225 System.out.format("usage score %02d: %.2f \t %d\n",j+1, usageScore, lengths[j]); 226 } 172 227 } 173 228 … … 181 236 return new XMIResourceImpl(uri) { 182 237 @Override 183 public boolean useUUIDs() 184 { 185 return true; 238 public boolean useUUIDs() { 239 return true; 186 240 } 187 241 }; … … 190 244 191 245 Resource resource = resourceSet.createResource(URI.createURI("binresource")); 192 246 193 247 resource.getContents().add(model); 194 248 FileOutputStream fos; 195 249 File file = new File(filename); 196 if ( file.getParent()!=null) {250 if (file.getParent() != null) { 197 251 file.getParentFile().mkdirs(); 198 252 }
Note: See TracChangeset
for help on using the changeset viewer.