1+ package com .intuit .ipp .interceptors ;
2+
3+
4+ import com .intuit .ipp .core .Response ;
5+ import com .intuit .ipp .data .IntuitEntity ;
6+ import com .intuit .ipp .data .IntuitResponse ;
7+ import com .intuit .ipp .data .QueryResponse ;
8+ import com .intuit .ipp .exception .FMSException ;
9+ import com .intuit .ipp .services .CallbackHandler ;
10+ import com .intuit .ipp .services .CallbackMessage ;
11+ import org .testng .annotations .Test ;
12+
13+ import javax .xml .bind .JAXBElement ;
14+ import javax .xml .namespace .QName ;
15+
16+ import static org .testng .Assert .*;
17+
18+ public class CallbackHandlerInterceptorTest extends CallbackHandlerBase {
19+
20+
21+ @ Test (expectedExceptions = NullPointerException .class )
22+ public void nullMessageNotOK () throws FMSException {
23+ callback ().execute (null );
24+ }
25+
26+ @ Test (expectedExceptions = NullPointerException .class )
27+ public void emptyMessageNotOK () throws FMSException {
28+ callback ().execute (new IntuitMessage ());
29+ }
30+
31+ @ Test (expectedExceptions = ClassCastException .class )
32+ public void arbitraryResponseNotOk () throws FMSException {
33+ IntuitMessage m = new IntuitMessage ();
34+ m .getResponseElements ().setResponse (new Response () {});
35+ callback ().execute (m );
36+ }
37+
38+ @ Test (expectedExceptions = NullPointerException .class )
39+ public void noCallBackMessageNotOk () throws FMSException {
40+ IntuitMessage m = new IntuitMessage ();
41+ m .getResponseElements ().setResponse (new IntuitResponse ());
42+ callback ().execute (m );
43+ }
44+
45+ @ Test (expectedExceptions = NullPointerException .class )
46+ public void noCallBackHandlerNotOk () throws FMSException {
47+ IntuitMessage m = new IntuitMessage ();
48+ m .getResponseElements ().setResponse (new IntuitResponse ());
49+ m .getResponseElements ().setCallbackMessage (new CallbackMessage ());
50+ callback ().execute (m );
51+ }
52+
53+ /**
54+ * This test demonstrates minimum required setup
55+ * for interceptor to successfully execute on request
56+ *
57+ * @throws FMSException
58+ */
59+ @ Test
60+ public void stubOK () throws FMSException {
61+ IntuitMessage m = new IntuitMessage ();
62+ m .getResponseElements ().setResponse (new IntuitResponse ());
63+ final CallbackMessage message = new CallbackMessage ();
64+ m .getResponseElements ().setCallbackMessage (message );
65+ m .getRequestElements ().setCallbackHandler (new CallbackHandler () {
66+ @ Override
67+ public void execute (CallbackMessage callbackMessage ) {
68+ assertEquals (message ,callbackMessage , "Callback message is not the same as one in response" );
69+ }
70+ });
71+ callback ().execute (m );
72+ }
73+
74+ @ Test
75+ public void entityIsOk () throws FMSException {
76+ final IntuitResponse response = new IntuitResponse ();
77+ response .setIntuitObject (getDummyTestEntity ());
78+
79+ final CallbackMessage message = invokeInterceptor (response );
80+ assertNotNull (message .getEntity ());
81+ assertTrue (message .getEntity () instanceof IntuitTestEntity );
82+ }
83+
84+ @ Test
85+ public void queryIsOk () throws FMSException {
86+
87+ final QueryResponse value = new QueryResponse ();
88+ value .setMaxResults (10 );
89+
90+ final IntuitResponse response = new IntuitResponse ();
91+ response .setQueryResponse (value );
92+
93+ final CallbackMessage message = invokeInterceptor (response );
94+ assertNotNull (message .getQueryResult ());
95+ assertEquals (10 , (int )message .getQueryResult ().getMaxResults ());
96+ }
97+
98+
99+
100+ public class IntuitTestEntity extends IntuitEntity {}
101+
102+ public JAXBElement <? extends IntuitEntity > getDummyTestEntity () {
103+ QName qname = new QName ("http://www.example.com" , "interceptor-test" );
104+ return new JAXBElement <>(qname , IntuitTestEntity .class , new IntuitTestEntity ());
105+ }
106+ }
0 commit comments