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