Changeset 1623 for trunk/autoquest-plugin-http-test/src/test/java/de/ugoe/cs/autoquest/http/HTTPLogParserTest.java
- Timestamp:
- 07/29/14 10:32:32 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-plugin-http-test/src/test/java/de/ugoe/cs/autoquest/http/HTTPLogParserTest.java
r1591 r1623 46 46 /** 47 47 * Test for the new HTMLLogParser 48 * 48 49 * @author Fabian Glaser 49 * 50 * 50 51 */ 51 52 public class HTTPLogParserTest { 52 53 53 54 /** 54 55 * … … 71 72 deleteFiles(new File(LOG_FILE_DIR)); 72 73 } 73 74 74 75 /** 75 76 * Tests the parseFile method with a given trace file. 77 * 76 78 * @throws Exception 77 79 */ … … 81 83 File logFile = new File(LOG_FILE_DIR, "session" + i + ".xml"); 82 84 83 Session session = HTTPTestUtils.createRandomSession(100); 85 Session session = HTTPTestUtils.createRandomSession(100); 84 86 writeToFile(session, logFile); 85 87 … … 116 118 assertTrue(sequence.get(j).getTarget() instanceof HTTPTarget); 117 119 118 HTTPTestUtils.assertExchangeEquals 119 (session.getHttpExchange().get(j),120 ((HTTPEventType) sequence.get(j).getType()).getExchange());120 HTTPTestUtils.assertExchangeEquals(session.getHttpExchange().get(j), 121 ((HTTPEventType) sequence.get(j).getType()) 122 .getExchange()); 121 123 122 124 assertEquals(HTTPUtils.toString(session.getHttpExchange().get(j).getReceiver()), … … 129 131 } 130 132 } 131 133 132 134 /** 133 135 * Tests the parseFile method with a given trace file. 136 * 134 137 * @throws Exception 135 138 */ … … 137 140 public void testParseFile_2() throws Exception { 138 141 HTTPLogParser parser = new HTTPLogParser(); 139 parser.parseFile 140 (new File(ClassLoader.getSystemResource("httpmonitor_testtrace_1.xml").getFile()));142 parser.parseFile(new File(ClassLoader.getSystemResource("httpmonitor_testtrace_1.xml") 143 .getFile())); 141 144 Collection<List<Event>> events = parser.getSequences(); 142 145 143 146 assertNotNull(events); 144 147 assertEquals(1, events.size()); 145 148 146 149 Iterator<List<Event>> iterator = events.iterator(); 147 150 assertNotNull(iterator); … … 157 160 System.out.print(event); 158 161 System.out.println(","); 159 162 160 163 if (event.getType() instanceof SOAPEventType) { 161 164 assertNotNull(((SOAPEventType) event.getType()).getCalledMethod()); … … 167 170 System.out.println("}"); 168 171 System.out.println("\n\n"); 169 172 170 173 assertEquals(870, soapEvents.size()); 171 174 } 172 175 176 /** 177 * Tests the parseFile method with a given trace file. 178 * 179 * @throws Exception 180 */ 181 @Test 182 public void testParseFile_3() throws Exception { 183 // tests parsing with properties 184 HTTPLogParser parser = 185 new HTTPLogParser(new File(ClassLoader 186 .getSystemResource("testParseFile_3_properties.txt").getFile())); 187 parser.parseFile(new File(ClassLoader.getSystemResource("testParseFile_3_logfile.log") 188 .getFile())); 189 Collection<List<Event>> events = parser.getSequences(); 190 191 assertNotNull(events); 192 assertEquals(1, events.size()); 193 194 Iterator<List<Event>> iterator = events.iterator(); 195 assertNotNull(iterator); 196 assertEquals(153, iterator.next().size()); 197 assertFalse(iterator.hasNext()); 198 199 List<Event> soapEvents = new LinkedList<Event>(); 200 System.out.println("{"); 201 for (List<Event> session : events) { 202 System.out.println(" {"); 203 for (Event event : session) { 204 System.out.print(" "); 205 System.out.print(event); 206 System.out.println(","); 207 208 if (event.getType() instanceof SOAPEventType) { 209 assertNotNull(((SOAPEventType) event.getType()).getCalledMethod()); 210 soapEvents.add(event); 211 } 212 } 213 System.out.println(" }"); 214 } 215 System.out.println("}"); 216 System.out.println("\n\n"); 217 218 assertEquals(147, soapEvents.size()); 219 } 220 173 221 /** 174 222 * @throws Exception … … 177 225 public void testSerializability_1() throws Exception { 178 226 HTTPLogParser parser = new HTTPLogParser(); 179 parser.parseFile 180 (new File(ClassLoader.getSystemResource("httpmonitor_testtrace_1.xml").getFile()));227 parser.parseFile(new File(ClassLoader.getSystemResource("httpmonitor_testtrace_1.xml") 228 .getFile())); 181 229 Collection<List<Event>> events = parser.getSequences(); 182 230 183 231 assertNotNull(events); 184 232 assertEquals(1, events.size()); 185 233 186 234 Iterator<List<Event>> iterator = events.iterator(); 187 235 assertNotNull(iterator); … … 196 244 } 197 245 } 198 246 199 247 /** 200 248 * … … 202 250 private void writeToFile(Session session, File logFile) throws Exception { 203 251 System.out.println("writing session to " + logFile); 204 252 205 253 logFile.getParentFile().mkdirs(); 206 254 207 255 JAXBContext jaxbContext = JAXBContext.newInstance(Session.class.getPackage().getName()); 208 256 Marshaller marshaller = jaxbContext.createMarshaller(); 209 257 StreamResult result = new StreamResult(new FileOutputStream(logFile)); 210 258 marshaller.marshal(new ObjectFactory().createSession(session), result); 211 259 212 260 result.getOutputStream().close(); 213 261 } … … 223 271 } 224 272 } 225 273 226 274 try { 227 275 file.delete();
Note: See TracChangeset
for help on using the changeset viewer.