1818import org .testng .Assert ;
1919import org .testng .annotations .BeforeClass ;
2020import org .testng .annotations .Test ;
21- import com .intuit .ipp .services .IPPHelper ;
2221import com .intuit .ipp .core .Context ;
2322import com .intuit .ipp .core .ServiceType ;
2423import com .intuit .ipp .exception .FMSException ;
2524import com .intuit .ipp .security .OAuthAuthorizer ;
2625import com .intuit .ipp .util .Config ;
2726
27+ import java .util .ArrayList ;
28+ import java .util .List ;
29+ import java .util .UUID ;
30+
2831public class ContextTest {
2932
3033 @ BeforeClass
3134 public static void setup (){
3235 Config .setProperty (Config .HTTP_TRANSPORT , "" );
3336 }
34-
3537
36- @ Test (enabled = false )
38+ private Context getContextForTest () {
39+ Context context ;
40+ IPPHelper ippHelper = IPPHelper .getInstance ();
41+ OAuthAuthorizer oauth = new OAuthAuthorizer (ippHelper .getQboConsumerKey (), ippHelper .getQboConsumerSecret (), ippHelper .getQboAccessToken (), ippHelper .getQboAccessTokenSecret ());
42+ try {
43+ context = new Context (oauth , ippHelper .getQboAppToken (), ServiceType .QBO , ippHelper .getQboRealmID ());
44+ } catch (FMSException e ) {
45+ context = null ;
46+ }
47+ return context ;
48+ }
49+
50+ @ Test
3751 public void testServiceType_null () {
3852 IPPHelper ippHelper = IPPHelper .getInstance ();
3953 OAuthAuthorizer oauth = new OAuthAuthorizer (ippHelper .getQboConsumerKey (), ippHelper .getQboConsumerSecret (), ippHelper .getQboAccessToken (), ippHelper .getQboAccessTokenSecret ());
@@ -44,6 +58,130 @@ public void testServiceType_null() {
4458 Assert .assertNotNull (e );
4559 }
4660 }
47-
48-
61+
62+
63+ @ Test
64+ public void testServiceType_nullConstructor () {
65+ IPPHelper ippHelper = IPPHelper .getInstance ();
66+ OAuthAuthorizer oauth = new OAuthAuthorizer (ippHelper .getQboConsumerKey (), ippHelper .getQboConsumerSecret (), ippHelper .getQboAccessToken (), ippHelper .getQboAccessTokenSecret ());
67+ ServiceType serviceType = null ;
68+ try {
69+ new Context (oauth , serviceType , ippHelper .getQboRealmID ());
70+ } catch (FMSException e ) {
71+ Assert .assertNotNull (e );
72+ }
73+ }
74+
75+ @ Test
76+ public void testCustomerRequestTimeout () {
77+ Context context = getContextForTest ();
78+ Assert .assertNotNull (context );
79+ Integer timeout = 2 ;
80+ context .setCustomerRequestTimeout (timeout );
81+ Assert .assertEquals (context .getCustomerRequestTimeout (), timeout );
82+ }
83+
84+ @ Test
85+ public void testIncludeParam () {
86+ Context context = getContextForTest ();
87+ Assert .assertNotNull (context );
88+ List <String > testList = new ArrayList <>();
89+ testList .add ("testString" );
90+ context .setIncludeParam (testList );
91+ Assert .assertEquals (context .getIncludeParam (), testList );
92+ }
93+
94+ @ Test
95+ public void testTicket () {
96+ Context context = getContextForTest ();
97+ Assert .assertNotNull (context );
98+ String ticket = "testTicket" ;
99+ context .setTicket (ticket );
100+ Assert .assertEquals (context .getTicket (), ticket );
101+ }
102+
103+ @ Test
104+ public void testAppToken () {
105+ Context context = getContextForTest ();
106+ Assert .assertNotNull (context );
107+ String token = "testToken" ;
108+ context .setAppToken (token );
109+ Assert .assertEquals (context .getAppToken (), token );
110+ }
111+
112+ @ Test
113+ public void testAppDBID () {
114+ Context context = getContextForTest ();
115+ Assert .assertNotNull (context );
116+ String ticket = "testDBID" ;
117+ context .setAppDBID (ticket );
118+ Assert .assertEquals (context .getAppDBID (), ticket );
119+ }
120+
121+ @ Test
122+ public void testRealmID () {
123+ Context context = getContextForTest ();
124+ Assert .assertNotNull (context );
125+ String realmId = "testID" ;
126+ context .setRealmID (realmId );
127+ Assert .assertEquals (context .getRealmID (), realmId );
128+ }
129+
130+ @ Test
131+ public void testTrackingID () {
132+ Context context = getContextForTest ();
133+ Assert .assertNotNull (context );
134+ UUID trackingID = UUID .randomUUID ();
135+ context .setTrackingID (trackingID );
136+ Assert .assertEquals (context .getTrackingID (), trackingID );
137+ }
138+
139+ @ Test
140+ public void testRequestID () {
141+ Context context = getContextForTest ();
142+ Assert .assertNotNull (context );
143+ String requestID = "testRequestID" ;
144+ context .setRequestID (requestID );
145+ Assert .assertEquals (context .getRequestID (), requestID );
146+ }
147+
148+ @ Test
149+ public void testRequestIDNull () {
150+ Context context = getContextForTest ();
151+ Assert .assertNotNull (context );
152+ String requestID = null ;
153+ context .setRequestID (requestID );
154+ Assert .assertNotNull (context .getRequestID ());
155+ }
156+
157+ @ Test
158+ public void testIntuitServiceType () {
159+ Context context = getContextForTest ();
160+ Assert .assertNotNull (context );
161+ ServiceType serviceType = ServiceType .IPS ;
162+ context .setIntuitServiceType (serviceType );
163+ Assert .assertEquals (context .getIntuitServiceType (), serviceType );
164+ }
165+
166+ @ Test
167+ public void testAuthorizer () {
168+ Context context = getContextForTest ();
169+ Assert .assertNotNull (context );
170+ IPPHelper ippHelper = IPPHelper .getInstance ();
171+ OAuthAuthorizer oauth = new OAuthAuthorizer (ippHelper .getQboConsumerKey (), ippHelper .getQboConsumerSecret () + "1" , ippHelper .getQboAccessToken (), ippHelper .getQboAccessTokenSecret ());
172+ context .setAuthorizer (oauth );
173+ Assert .assertEquals (context .getAuthorizer (), oauth );
174+ }
175+
176+ @ Test
177+ public void testInvalidate () {
178+ Context context = getContextForTest ();
179+ Assert .assertNotNull (context );
180+ context .invalidate ();
181+ Assert .assertNull (context .getAppToken ());
182+ Assert .assertNull (context .getAppDBID ());
183+ Assert .assertNull (context .getAuthorizer ());
184+ Assert .assertNull (context .getIntuitServiceType ());
185+ Assert .assertNull (context .getRealmID ());
186+ }
49187}
0 commit comments