1515 *******************************************************************************/
1616package com .intuit .ipp .services ;
1717
18+ import com .intuit .ipp .security .IAuthorizer ;
1819import org .testng .Assert ;
1920import org .testng .annotations .BeforeClass ;
2021import org .testng .annotations .Test ;
2526import com .intuit .ipp .security .OAuthAuthorizer ;
2627import com .intuit .ipp .util .Config ;
2728
29+ import javax .xml .ws .Service ;
30+ import java .util .ArrayList ;
31+ import java .util .HashMap ;
32+ import java .util .List ;
33+ import java .util .UUID ;
34+
2835public class ContextTest {
2936
3037 @ BeforeClass
3138 public static void setup (){
3239 Config .setProperty (Config .HTTP_TRANSPORT , "" );
3340 }
34-
3541
36- @ Test (enabled = false )
42+ private Context getContextForTest () {
43+ Context context ;
44+ IPPHelper ippHelper = IPPHelper .getInstance ();
45+ OAuthAuthorizer oauth = new OAuthAuthorizer (ippHelper .getQboConsumerKey (), ippHelper .getQboConsumerSecret (), ippHelper .getQboAccessToken (), ippHelper .getQboAccessTokenSecret ());
46+ try {
47+ context = new Context (oauth , ippHelper .getQboAppToken (), ServiceType .QBO , ippHelper .getQboRealmID ());
48+ } catch (FMSException e ) {
49+ context = null ;
50+ }
51+ return context ;
52+ }
53+
54+ @ Test
3755 public void testServiceType_null () {
3856 IPPHelper ippHelper = IPPHelper .getInstance ();
3957 OAuthAuthorizer oauth = new OAuthAuthorizer (ippHelper .getQboConsumerKey (), ippHelper .getQboConsumerSecret (), ippHelper .getQboAccessToken (), ippHelper .getQboAccessTokenSecret ());
@@ -44,6 +62,130 @@ public void testServiceType_null() {
4462 Assert .assertNotNull (e );
4563 }
4664 }
47-
48-
65+
66+
67+ @ Test
68+ public void testServiceType_nullConstructor () {
69+ IPPHelper ippHelper = IPPHelper .getInstance ();
70+ OAuthAuthorizer oauth = new OAuthAuthorizer (ippHelper .getQboConsumerKey (), ippHelper .getQboConsumerSecret (), ippHelper .getQboAccessToken (), ippHelper .getQboAccessTokenSecret ());
71+ ServiceType serviceType = null ;
72+ try {
73+ new Context (oauth , serviceType , ippHelper .getQboRealmID ());
74+ } catch (FMSException e ) {
75+ Assert .assertNotNull (e );
76+ }
77+ }
78+
79+ @ Test
80+ public void testCustomerRequestTimeout () {
81+ Context context = getContextForTest ();
82+ Assert .assertNotNull (context );
83+ Integer timeout = 2 ;
84+ context .setCustomerRequestTimeout (timeout );
85+ Assert .assertEquals (context .getCustomerRequestTimeout (), timeout );
86+ }
87+
88+ @ Test
89+ public void testIncludeParam () {
90+ Context context = getContextForTest ();
91+ Assert .assertNotNull (context );
92+ List <String > testList = new ArrayList <>();
93+ testList .add ("testString" );
94+ context .setIncludeParam (testList );
95+ Assert .assertEquals (context .getIncludeParam (), testList );
96+ }
97+
98+ @ Test
99+ public void testTicket () {
100+ Context context = getContextForTest ();
101+ Assert .assertNotNull (context );
102+ String ticket = "testTicket" ;
103+ context .setTicket (ticket );
104+ Assert .assertEquals (context .getTicket (), ticket );
105+ }
106+
107+ @ Test
108+ public void testAppToken () {
109+ Context context = getContextForTest ();
110+ Assert .assertNotNull (context );
111+ String token = "testToken" ;
112+ context .setAppToken (token );
113+ Assert .assertEquals (context .getAppToken (), token );
114+ }
115+
116+ @ Test
117+ public void testAppDBID () {
118+ Context context = getContextForTest ();
119+ Assert .assertNotNull (context );
120+ String ticket = "testDBID" ;
121+ context .setAppDBID (ticket );
122+ Assert .assertEquals (context .getAppDBID (), ticket );
123+ }
124+
125+ @ Test
126+ public void testRealmID () {
127+ Context context = getContextForTest ();
128+ Assert .assertNotNull (context );
129+ String realmId = "testID" ;
130+ context .setRealmID (realmId );
131+ Assert .assertEquals (context .getRealmID (), realmId );
132+ }
133+
134+ @ Test
135+ public void testTrackingID () {
136+ Context context = getContextForTest ();
137+ Assert .assertNotNull (context );
138+ UUID trackingID = UUID .randomUUID ();
139+ context .setTrackingID (trackingID );
140+ Assert .assertEquals (context .getTrackingID (), trackingID );
141+ }
142+
143+ @ Test
144+ public void testRequestID () {
145+ Context context = getContextForTest ();
146+ Assert .assertNotNull (context );
147+ String requestID = "testRequestID" ;
148+ context .setRequestID (requestID );
149+ Assert .assertEquals (context .getRequestID (), requestID );
150+ }
151+
152+ @ Test
153+ public void testRequestIDNull () {
154+ Context context = getContextForTest ();
155+ Assert .assertNotNull (context );
156+ String requestID = null ;
157+ context .setRequestID (requestID );
158+ Assert .assertNotNull (context .getRequestID ());
159+ }
160+
161+ @ Test
162+ public void testIntuitServiceType () {
163+ Context context = getContextForTest ();
164+ Assert .assertNotNull (context );
165+ ServiceType serviceType = ServiceType .IPS ;
166+ context .setIntuitServiceType (serviceType );
167+ Assert .assertEquals (context .getIntuitServiceType (), serviceType );
168+ }
169+
170+ @ Test
171+ public void testAuthorizer () {
172+ Context context = getContextForTest ();
173+ Assert .assertNotNull (context );
174+ IPPHelper ippHelper = IPPHelper .getInstance ();
175+ OAuthAuthorizer oauth = new OAuthAuthorizer (ippHelper .getQboConsumerKey (), ippHelper .getQboConsumerSecret () + "1" , ippHelper .getQboAccessToken (), ippHelper .getQboAccessTokenSecret ());
176+ context .setAuthorizer (oauth );
177+ Assert .assertEquals (context .getAuthorizer (), oauth );
178+ }
179+
180+ @ Test
181+ public void testInvalidate () {
182+ Context context = getContextForTest ();
183+ Assert .assertNotNull (context );
184+ context .invalidate ();
185+ Assert .assertNull (context .getAppToken ());
186+ Assert .assertNull (context .getAppDBID ());
187+ Assert .assertNull (context .getAuthorizer ());
188+ Assert .assertNull (context .getIntuitServiceType ());
189+ Assert .assertNull (context .getRealmID ());
190+ }
49191}
0 commit comments