1 18 19 package org.apache.beehive.netui.tools.testrecorder.server; 20 21 import org.apache.beehive.netui.tools.testrecorder.shared.RequestData; 22 import org.apache.beehive.netui.tools.testrecorder.shared.DiffFailedException; 23 import org.apache.beehive.netui.tools.testrecorder.shared.NVPair; 24 import org.apache.beehive.netui.tools.testrecorder.shared.ResponseData; 25 import org.apache.beehive.netui.tools.testrecorder.shared.Logger; 26 import org.apache.beehive.netui.tools.testrecorder.shared.TestResults; 27 28 33 public abstract class AbstractDiffEngine implements DiffEngine { 34 35 private static final Logger log = Logger.getInstance( AbstractDiffEngine.class ); 36 37 public TestResults diff( RequestData recordRequest, ResponseData recordResponse, RequestData playbackRequest, 38 ResponseData playbackResponse, TestResults results ) throws DiffFailedException { 39 results = diff( recordRequest, playbackRequest, results ); 40 results = diff( recordResponse, playbackResponse, results ); 41 return results; 42 } 43 44 public abstract TestResults responseBodyDiff( String record, String playback, TestResults results ) 45 throws DiffFailedException; 46 47 public TestResults diff( RequestData record, RequestData playback, 48 TestResults results ) throws DiffFailedException { 49 if ( !record.getProtocol().equals( playback.getProtocol() ) ) { 50 results.addDiffResult( "record request protocol( " + record.getProtocol() + 51 " ) does not match playback request protocol( " + 52 playback.getProtocol() + " )" ); 53 } 54 55 59 if ( !record.getMethod().equals( playback.getMethod() ) ) { 60 results.addDiffResult( "record request method( " + record.getMethod() + 61 " ) does not match playback request method( " + 62 playback.getMethod() + " )" ); 63 } 64 results = diffParams( record.getParameters(), playback.getParameters(), results ); 65 return results; 66 } 67 68 public TestResults diffParams( NVPair[] record, NVPair[] playback, 69 TestResults results ) throws DiffFailedException { 70 NVPair recPair = null; 72 NVPair playPair = null; 73 int i = 0; 74 boolean match = false; 75 if ( record != null ) { 76 for ( i = 0; i < record.length; i++, match = false ) { 77 recPair = record[i]; 78 if ( playback != null && i < playback.length ) { 79 playPair = playback[i]; 80 if ( recPair.equals( playPair ) ) { 81 match = true; 82 } 83 } 84 else { 85 playPair = null; 87 } 88 if ( !match ) { 89 results.addDiffResult( "record request parameter( " + recPair + 90 " ) does not match playback request parameter( " + 91 playPair + " )" ); 92 } 93 } 94 } 95 if ( playback != null ) { 96 recPair = null; 98 for ( ; i < playback.length; i++ ) { 99 playPair = playback[i]; 100 results.addDiffResult( "record request parameter( " + recPair + 101 " ) does not match playback request parameter( " + 102 playPair + " )" ); 103 } 104 } 105 return results; 106 } 107 108 public TestResults diff( ResponseData record, ResponseData playback, TestResults results ) 109 throws DiffFailedException { 110 if ( record.getStatusCode() != playback.getStatusCode() ) { 111 results.addDiffResult( "record response status code( " + record.getStatusCode() + 112 " ) does not match playback response status code( " + 113 playback.getStatusCode() + " )" ); 114 } 115 results = responseBodyDiff( record.getNormalizedBody(), playback.getNormalizedBody(), results ); 116 return results; 117 } 118 119 } 120 | Popular Tags |