2020 * #L%
2121 */
2222
23- import static org .easymock .EasyMock .anyObject ;
24- import static org .easymock .EasyMock .capture ;
25- import static org .easymock .EasyMock .expectLastCall ;
26- import static org .easymock .EasyMock .replay ;
27- import static org .easymock .EasyMock .verify ;
28- import static org .junit .Assert .assertEquals ;
29- import static org .junit .Assert .assertFalse ;
30- import static org .junit .Assert .assertNotNull ;
31- import static org .junit .Assert .assertNull ;
32- import static org .junit .Assert .assertTrue ;
23+ import static org .easymock .EasyMock .*;
24+ import static org .junit .Assert .*;
3325
3426import com .fasterxml .jackson .databind .ObjectMapper ;
3527import com .github .kklisura .cdt .protocol .support .types .EventHandler ;
4537import com .github .kklisura .cdt .services .utils .ProxyUtils ;
4638import java .io .IOException ;
4739import java .util .HashMap ;
40+ import java .util .List ;
4841import org .easymock .Capture ;
4942import org .easymock .EasyMockRunner ;
5043import org .easymock .EasyMockSupport ;
@@ -122,7 +115,7 @@ public void testInvokeVoidMethodThrowsWebSocketException()
122115
123116 ChromeDevToolsInvocationException capturedException = null ;
124117 try {
125- service .invoke (null , Void .TYPE , methodInvocation );
118+ service .invoke (null , Void .TYPE , null , methodInvocation );
126119 } catch (ChromeDevToolsInvocationException ex ) {
127120 capturedException = ex ;
128121 }
@@ -167,7 +160,7 @@ public void testInvokeVoidMethodInterruptsWaiting()
167160
168161 ChromeDevToolsInvocationException capturedException = null ;
169162 try {
170- service .invoke (null , Void .TYPE , methodInvocation );
163+ service .invoke (null , Void .TYPE , null , methodInvocation );
171164 } catch (ChromeDevToolsInvocationException ex ) {
172165 capturedException = ex ;
173166 }
@@ -198,7 +191,7 @@ public void testInvokeVoidMethod() throws WebSocketServiceException, IOException
198191 replayAll ();
199192
200193 resolveMessage ("{\" id\" :1,\" result\" :{}}" );
201- assertNull (service .invoke (null , Void .TYPE , methodInvocation ));
194+ assertNull (service .invoke (null , Void .TYPE , null , methodInvocation ));
202195
203196 verifyAll ();
204197
@@ -223,7 +216,86 @@ public void testInvokeStringMethod() throws WebSocketServiceException, IOExcepti
223216 replayAll ();
224217
225218 resolveMessage ("{\" id\" :1,\" result\" :{\" resultProperty\" :\" resultValue\" }}" );
226- assertEquals ("resultValue" , service .invoke ("resultProperty" , String .class , methodInvocation ));
219+ assertEquals (
220+ "resultValue" , service .invoke ("resultProperty" , String .class , null , methodInvocation ));
221+
222+ verifyAll ();
223+
224+ MethodInvocation sentInvocation =
225+ OBJECT_MAPPER .readerFor (MethodInvocation .class ).readValue (messageCapture .getValue ());
226+ assertEquals (methodInvocation .getId (), sentInvocation .getId ());
227+ assertEquals (methodInvocation .getMethod (), sentInvocation .getMethod ());
228+ assertEquals (methodInvocation .getParams (), sentInvocation .getParams ());
229+ }
230+
231+ @ Test
232+ public void testInvokeMethodReturningListOfComplexObjects ()
233+ throws WebSocketServiceException , IOException {
234+ MethodInvocation methodInvocation = new MethodInvocation ();
235+ methodInvocation .setId (1L );
236+ methodInvocation .setMethod ("SomeMethod" );
237+ methodInvocation .setParams (new HashMap <>());
238+ methodInvocation .getParams ().put ("param" , "value" );
239+
240+ Capture <String > messageCapture = Capture .newInstance ();
241+ webSocketService .send (capture (messageCapture ));
242+
243+ replayAll ();
244+
245+ resolveMessage ("{\" id\" :1,\" result\" :[{\" testProperty\" :\" 1\" },{\" testProperty\" :\" 2\" }]}" );
246+
247+ List <TestMessage > result =
248+ (List <TestMessage >)
249+ service .invoke (null , List .class , new Class [] {TestMessage .class }, methodInvocation );
250+
251+ assertNotNull (result );
252+ assertEquals (2 , result .size ());
253+ assertNotNull (result .get (0 ));
254+ assertNotNull (result .get (1 ));
255+ assertEquals ("1" , result .get (0 ).getTestProperty ());
256+ assertEquals ("2" , result .get (1 ).getTestProperty ());
257+
258+ verifyAll ();
259+
260+ MethodInvocation sentInvocation =
261+ OBJECT_MAPPER .readerFor (MethodInvocation .class ).readValue (messageCapture .getValue ());
262+ assertEquals (methodInvocation .getId (), sentInvocation .getId ());
263+ assertEquals (methodInvocation .getMethod (), sentInvocation .getMethod ());
264+ assertEquals (methodInvocation .getParams (), sentInvocation .getParams ());
265+ }
266+
267+ @ Test
268+ public void testInvokeMethodReturningListOfComplexObjects2 ()
269+ throws WebSocketServiceException , IOException {
270+ MethodInvocation methodInvocation = new MethodInvocation ();
271+ methodInvocation .setId (1L );
272+ methodInvocation .setMethod ("SomeMethod" );
273+ methodInvocation .setParams (new HashMap <>());
274+ methodInvocation .getParams ().put ("param" , "value" );
275+
276+ Capture <String > messageCapture = Capture .newInstance ();
277+ webSocketService .send (capture (messageCapture ));
278+
279+ replayAll ();
280+
281+ resolveMessage ("{\" id\" :1,\" result\" :[[{\" testProperty\" :\" 1\" },{\" testProperty\" :\" 2\" }]]}" );
282+
283+ List <List <TestMessage >> resultWrapper =
284+ (List <List <TestMessage >>)
285+ service .invoke (
286+ null , List .class , new Class [] {List .class , TestMessage .class }, methodInvocation );
287+
288+ assertNotNull (resultWrapper );
289+ assertEquals (1 , resultWrapper .size ());
290+
291+ List <TestMessage > result = resultWrapper .get (0 );
292+
293+ assertNotNull (result );
294+ assertEquals (2 , result .size ());
295+ assertNotNull (result .get (0 ));
296+ assertNotNull (result .get (1 ));
297+ assertEquals ("1" , result .get (0 ).getTestProperty ());
298+ assertEquals ("2" , result .get (1 ).getTestProperty ());
227299
228300 verifyAll ();
229301
@@ -248,7 +320,7 @@ public void testInvokeStringMethodWithNullResult() throws WebSocketServiceExcept
248320 replayAll ();
249321
250322 resolveMessage ("{\" id\" :1}" );
251- service .invoke ("resultProperty" , String .class , methodInvocation );
323+ service .invoke ("resultProperty" , String .class , null , methodInvocation );
252324 }
253325
254326 @ Test
@@ -266,7 +338,7 @@ public void testInvokeTestMessageMethod() throws WebSocketServiceException, IOEx
266338
267339 resolveMessage (
268340 "{\" id\" :1,\" result\" :{\" testProperty\" :\" resultValue\" ,\" testProperty2\" :\" resultValue2\" }}" );
269- TestMessage testMessage = service .invoke (null , TestMessage .class , methodInvocation );
341+ TestMessage testMessage = service .invoke (null , TestMessage .class , null , methodInvocation );
270342
271343 verifyAll ();
272344
@@ -296,7 +368,7 @@ public void testInvokeTestMessageMethodWithUnknownProperty()
296368
297369 resolveMessage (
298370 "{\" id\" :1,\" result\" :{\" testProperty\" :\" resultValue\" ,\" testProperty2\" :\" resultValue2\" ,\" unknownProperty\" :false}}" );
299- TestMessage testMessage = service .invoke (null , TestMessage .class , methodInvocation );
371+ TestMessage testMessage = service .invoke (null , TestMessage .class , null , methodInvocation );
300372
301373 verifyAll ();
302374
@@ -346,7 +418,7 @@ public void testInvokeTestMessageMethodWithBadJson()
346418 "{\" id\" :1,\" result\" :{\" testProperty\" :\" resultValue\" ,\" testProperty2\" -\" resultValue2\" }}" );
347419 ChromeDevToolsInvocationException capturedException = null ;
348420 try {
349- service .invoke (null , Void .TYPE , methodInvocation );
421+ service .invoke (null , Void .TYPE , null , methodInvocation );
350422 } catch (ChromeDevToolsInvocationException ex ) {
351423 capturedException = ex ;
352424 }
@@ -381,7 +453,7 @@ public void testInvokeVoidMethodWithError() throws WebSocketServiceException, IO
381453
382454 ChromeDevToolsInvocationException capturedException = null ;
383455 try {
384- service .invoke (null , Void .TYPE , methodInvocation );
456+ service .invoke (null , Void .TYPE , null , methodInvocation );
385457 } catch (ChromeDevToolsInvocationException ex ) {
386458 capturedException = ex ;
387459 }
@@ -412,7 +484,7 @@ public void testInvokeVoidMethodWithErrorNoTestData()
412484
413485 ChromeDevToolsInvocationException capturedException = null ;
414486 try {
415- service .invoke (null , Void .TYPE , methodInvocation );
487+ service .invoke (null , Void .TYPE , null , methodInvocation );
416488 } catch (ChromeDevToolsInvocationException ex ) {
417489 capturedException = ex ;
418490 }
@@ -591,7 +663,7 @@ public void testEventReceivedWithUnsubscribeOnService() throws InterruptedExcept
591663 }
592664
593665 @ Test
594- public void testEventReceivedHandlerThrowsExeption () throws InterruptedException {
666+ public void testEventReceivedHandlerThrowsException () throws InterruptedException {
595667 // Non existing event handler
596668 service .accept ("{\" method\" :\" Domain.name\" ,\" params\" :{\" testProperty\" :\" testValue\" }}" );
597669
0 commit comments