[622] | 1 | // Module : $RCSfile: ReplayReaderTest.java,v $
|
---|
| 2 | // Version : $Revision: 0.0 $ $Author: Patrick $ $Date: 26.11.2011 15:10:08 $
|
---|
| 3 | // Project : TaskTreePerformanceTest
|
---|
| 4 | // Creation : 2011 by Patrick
|
---|
| 5 | // Copyright : Patrick Harms, 2011
|
---|
| 6 |
|
---|
| 7 | package de.ugoe.cs.quest.plugin.mfc;
|
---|
| 8 |
|
---|
| 9 | import static org.junit.Assert.assertEquals;
|
---|
| 10 | import static org.junit.Assert.assertNotNull;
|
---|
| 11 | import static org.junit.Assert.assertNotSame;
|
---|
| 12 | import static org.junit.Assert.assertTrue;
|
---|
| 13 |
|
---|
| 14 | import java.io.File;
|
---|
| 15 | import java.io.FileInputStream;
|
---|
[649] | 16 | import java.io.FileOutputStream;
|
---|
[622] | 17 | import java.io.InputStreamReader;
|
---|
[649] | 18 | import java.io.PrintStream;
|
---|
[622] | 19 | import java.util.Collection;
|
---|
| 20 | import java.util.List;
|
---|
| 21 |
|
---|
| 22 | import org.junit.After;
|
---|
| 23 | import org.junit.Before;
|
---|
| 24 | import org.junit.Test;
|
---|
| 25 |
|
---|
| 26 | import de.ugoe.cs.quest.ReplayGenerator;
|
---|
| 27 | import de.ugoe.cs.quest.eventcore.Event;
|
---|
| 28 | import de.ugoe.cs.quest.eventcore.guimodel.GUIModel;
|
---|
[649] | 29 | import de.ugoe.cs.util.console.Console;
|
---|
| 30 | import de.ugoe.cs.util.console.listener.IOutputListener;
|
---|
[622] | 31 |
|
---|
| 32 | /**
|
---|
| 33 | * TODO comment
|
---|
| 34 | *
|
---|
| 35 | * @version $Revision: $ $Date: $
|
---|
| 36 | * @author 2011, last modified by $Author: $
|
---|
| 37 | */
|
---|
[649] | 38 | public class MFCLogParserTest implements IOutputListener {
|
---|
[622] | 39 |
|
---|
| 40 | /** */
|
---|
| 41 | private File tmpFile;
|
---|
| 42 |
|
---|
[649] | 43 | /** */
|
---|
| 44 | private PrintStream outputStream;
|
---|
| 45 |
|
---|
[622] | 46 | /**
|
---|
| 47 | *
|
---|
| 48 | */
|
---|
| 49 | @Before
|
---|
| 50 | public void setUp() throws Exception {
|
---|
[649] | 51 | outputStream = new PrintStream(new FileOutputStream("blub.log"));
|
---|
| 52 | Console.getInstance().registerOutputListener(this);
|
---|
| 53 |
|
---|
[622] | 54 | tmpFile = new File("tmp.xml");
|
---|
| 55 |
|
---|
| 56 | if (tmpFile.exists()) {
|
---|
| 57 | assertTrue(tmpFile.delete());
|
---|
| 58 | }
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | /**
|
---|
| 62 | *
|
---|
| 63 | */
|
---|
| 64 | @After
|
---|
| 65 | public void tearDown() throws Exception {
|
---|
[649] | 66 | if (!System.out.equals(outputStream) && !System.err.equals(outputStream)) {
|
---|
| 67 | outputStream.close();
|
---|
| 68 | }
|
---|
| 69 |
|
---|
[622] | 70 | if (tmpFile.exists()) {
|
---|
| 71 | assertTrue(tmpFile.delete());
|
---|
| 72 | }
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 |
|
---|
| 76 | /**
|
---|
| 77 | *
|
---|
| 78 | */
|
---|
| 79 | @Test
|
---|
| 80 | public void testTrace() throws Exception {
|
---|
| 81 | File traceFile = new File(ClassLoader.getSystemResource("trace.txt").getFile());
|
---|
| 82 |
|
---|
| 83 | new LogPreprocessor().convertToXml(traceFile.getAbsolutePath(),
|
---|
| 84 | tmpFile.getAbsolutePath());
|
---|
| 85 |
|
---|
| 86 | MFCLogParser parser = new MFCLogParser();
|
---|
| 87 | parser.parseFile(tmpFile);
|
---|
| 88 | Collection<List<Event>> events = parser.getSequences();
|
---|
| 89 |
|
---|
| 90 | assertNotNull(events);
|
---|
| 91 | assertTrue(events.size() > 0);
|
---|
| 92 |
|
---|
| 93 | System.err.println("{");
|
---|
| 94 | for (List<Event> session : events) {
|
---|
| 95 | System.err.println(" {");
|
---|
| 96 | for (Event event : session) {
|
---|
| 97 | System.err.print(" ");
|
---|
| 98 | System.err.print(event);
|
---|
| 99 | System.err.println(",");
|
---|
| 100 | }
|
---|
| 101 | System.err.println(" }");
|
---|
| 102 | }
|
---|
| 103 | System.err.println("}");
|
---|
| 104 | System.err.println("\n\n");
|
---|
| 105 |
|
---|
| 106 | GUIModel guiModel = parser.getGuiModel();
|
---|
| 107 | assertNotNull(guiModel);
|
---|
| 108 | assertNotSame(0, guiModel.getRootElements().size());
|
---|
| 109 |
|
---|
[649] | 110 | guiModel.dump(System.err);
|
---|
[622] | 111 | }
|
---|
| 112 |
|
---|
| 113 | /**
|
---|
| 114 | *
|
---|
| 115 | */
|
---|
| 116 | @Test
|
---|
| 117 | public void testLogfile() throws Exception {
|
---|
| 118 | File logFile = new File(ClassLoader.getSystemResource("log.xml").getFile());
|
---|
| 119 |
|
---|
| 120 | MFCLogParser parser = new MFCLogParser();
|
---|
| 121 | parser.parseFile(logFile);
|
---|
| 122 | Collection<List<Event>> events = parser.getSequences();
|
---|
| 123 |
|
---|
| 124 | assertNotNull(events);
|
---|
| 125 | assertTrue(events.size() > 0);
|
---|
| 126 |
|
---|
| 127 | System.err.println("{");
|
---|
| 128 | for (List<Event> session : events) {
|
---|
| 129 | System.err.println(" {");
|
---|
| 130 | for (Event event : session) {
|
---|
| 131 | System.err.print(" ");
|
---|
| 132 | System.err.print(event);
|
---|
| 133 | System.err.println(",");
|
---|
| 134 | }
|
---|
| 135 | System.err.println(" }");
|
---|
| 136 | }
|
---|
| 137 | System.err.println("}");
|
---|
| 138 | System.err.println("\n\n");
|
---|
| 139 |
|
---|
| 140 | GUIModel guiModel = parser.getGuiModel();
|
---|
| 141 | assertNotNull(guiModel);
|
---|
| 142 |
|
---|
[649] | 143 | guiModel.dump(System.err);
|
---|
[622] | 144 |
|
---|
| 145 | ReplayGenerator generator = new ReplayGenerator();
|
---|
| 146 | generator.createLogfileMultipleSessions(parser.getSequences(), tmpFile.getAbsolutePath());
|
---|
| 147 |
|
---|
| 148 | InputStreamReader reader1 =
|
---|
| 149 | new InputStreamReader(ClassLoader.getSystemResourceAsStream("replay.xml"), "UTF-8");
|
---|
| 150 |
|
---|
| 151 | InputStreamReader reader2 = new InputStreamReader(new FileInputStream(tmpFile), "UTF-8");
|
---|
| 152 |
|
---|
| 153 | try {
|
---|
| 154 | int sign1;
|
---|
| 155 | do {
|
---|
| 156 | sign1 = reader1.read();
|
---|
| 157 | assertEquals(sign1, reader2.read());
|
---|
| 158 | }
|
---|
| 159 | while (sign1 > -1);
|
---|
| 160 | }
|
---|
| 161 | finally {
|
---|
| 162 | reader1.close();
|
---|
| 163 | reader2.close();
|
---|
| 164 | }
|
---|
| 165 | }
|
---|
| 166 |
|
---|
[649] | 167 | /* (non-Javadoc)
|
---|
| 168 | * @see de.ugoe.cs.util.console.listener.IOutputListener#outputMsg(java.lang.String)
|
---|
[622] | 169 | */
|
---|
[649] | 170 | @Override
|
---|
| 171 | public void outputMsg(String newMessage) {
|
---|
| 172 | outputStream.println(newMessage);
|
---|
[622] | 173 | }
|
---|
| 174 |
|
---|
| 175 | }
|
---|