11package com .box .sdk ;
22
33import static com .box .sdk .BoxApiProvider .jwtApiForServiceAccount ;
4+ import static com .box .sdk .BoxApiProvider .jwtBoxConfig ;
45import static org .hamcrest .MatcherAssert .assertThat ;
56import static org .hamcrest .Matchers .equalTo ;
67import static org .hamcrest .Matchers .is ;
78import static org .hamcrest .Matchers .not ;
89import static org .hamcrest .Matchers .notNullValue ;
910import static org .junit .Assert .assertEquals ;
1011
11- import java .io .FileReader ;
12- import java .io .IOException ;
13- import java .io .Reader ;
1412import java .net .MalformedURLException ;
1513import java .net .URL ;
1614import java .util .ArrayList ;
1715import java .util .Calendar ;
1816import java .util .List ;
1917import org .junit .Ignore ;
2018import org .junit .Test ;
21- import org .junit .experimental .categories .Category ;
2219
2320
2421public class BoxAPIConnectionIT {
@@ -126,78 +123,16 @@ public void revokeToken() {
126123 }
127124
128125 @ Test
129- @ Ignore ("Configure JWT authentication" )
130- @ Category (IntegrationTestJWT .class )
131- public void developerEditionAppAuthWorks () throws IOException {
132- Reader reader = new FileReader ("src/test/config/config.json" );
133- BoxConfig boxConfig = BoxConfig .readFrom (reader );
134- IAccessTokenCache accessTokenCache = new InMemoryLRUAccessTokenCache (100 );
135-
136- BoxDeveloperEditionAPIConnection api =
137- BoxDeveloperEditionAPIConnection .getAppEnterpriseConnection (boxConfig , accessTokenCache );
138-
139- assertThat (api .getAccessToken (), not (equalTo (null )));
140-
141- final String name = "app user name" ;
142- final String externalAppUserId = "login2@boz.com" ;
143- CreateUserParams params = new CreateUserParams ();
144- params .setExternalAppUserId (externalAppUserId );
145- BoxUser appUser = null ;
146- try {
147- BoxUser .Info createdUserInfo = BoxUser .createAppUser (api , name , params );
148- final String appUserId = createdUserInfo .getID ();
149-
150- assertThat (createdUserInfo .getID (), not (equalTo (null )));
151- assertThat (createdUserInfo .getName (), equalTo (name ));
152-
153- appUser = new BoxUser (api , appUserId );
154- assertEquals (externalAppUserId ,
155- appUser .getInfo (BoxUser .ALL_FIELDS ).getExternalAppUserId ());
156-
157-
158- //Testing update works
159- final String newName = "app user updated name" ;
160- final String updatedExternalAppUserId = "login3@boz.com" ;
161-
162- createdUserInfo .setName (newName );
163- createdUserInfo .setExternalAppUserId (updatedExternalAppUserId );
164- appUser .updateInfo (createdUserInfo );
165-
166- assertThat (createdUserInfo .getName (), equalTo (newName ));
167- assertEquals (updatedExternalAppUserId ,
168- createdUserInfo .getResource ().getInfo ("external_app_user_id" ).getExternalAppUserId ());
169-
170- //Testing getAppUsers works
171- Iterable <BoxUser .Info > users = BoxUser .getAppUsersByExternalAppUserID (api ,
172- updatedExternalAppUserId , "external_app_user_id" );
173- for (BoxUser .Info userInfo : users ) {
174- assertEquals (updatedExternalAppUserId , userInfo .getExternalAppUserId ());
175- }
176- } finally {
177- if (appUser != null ) {
178- appUser .delete (false , true );
179- }
180- }
181- api .refresh ();
182- }
183-
184- @ Test
185- @ Category (IntegrationTestJWT .class )
186- @ Ignore ("Configure JWT authentication" )
187- public void developerEditionAppUserWorks () throws IOException {
188- Reader reader = new FileReader ("src/test/config/config.json" );
189- BoxConfig boxConfig = BoxConfig .readFrom (reader );
190- IAccessTokenCache accessTokenCache = new InMemoryLRUAccessTokenCache (100 );
191-
192- BoxDeveloperEditionAPIConnection appAuthConnection =
193- BoxDeveloperEditionAPIConnection .getAppEnterpriseConnection (boxConfig , accessTokenCache );
126+ public void appAndDeveloperEditionApiConnectionWorks () {
127+ BoxDeveloperEditionAPIConnection appAuthConnection = jwtApiForServiceAccount ();
194128
195129 final String name = "app user name two" ;
196130 BoxUser .Info createdUserInfo = BoxUser .createAppUser (appAuthConnection , name );
197131 final String appUserId = createdUserInfo .getID ();
198132
199- BoxDeveloperEditionAPIConnection api = BoxDeveloperEditionAPIConnection .getUserConnection (appUserId ,
200- boxConfig , accessTokenCache );
133+ InMemoryLRUAccessTokenCache accessTokenCache = new InMemoryLRUAccessTokenCache (1 );
134+ BoxDeveloperEditionAPIConnection api =
135+ BoxDeveloperEditionAPIConnection .getUserConnection (appUserId , jwtBoxConfig (), accessTokenCache );
201136 BoxUser appUser = new BoxUser (api , appUserId );
202137
203138 assertThat (api .getAccessToken (), not (equalTo (null )));
@@ -214,15 +149,9 @@ public void developerEditionAppUserWorks() throws IOException {
214149 }
215150
216151 @ Test
217- @ Category (IntegrationTestJWT .class )
218- @ Ignore ("Configure JWT authentication" )
219- public void appUsersAutomaticallyPaginatesCorrectly () throws IOException {
220- Reader reader = new FileReader ("src/test/config/config.json" );
221- BoxConfig boxConfig = BoxConfig .readFrom (reader );
222- IAccessTokenCache accessTokenCache = new InMemoryLRUAccessTokenCache (100 );
223-
224- BoxDeveloperEditionAPIConnection api =
225- BoxDeveloperEditionAPIConnection .getAppEnterpriseConnection (boxConfig , accessTokenCache );
152+ @ Ignore ("Takes too long to run" )
153+ public void appUsersAutomaticallyPaginatesCorrectly () {
154+ BoxDeveloperEditionAPIConnection api = jwtApiForServiceAccount ();
226155
227156 assertThat (api .getAccessToken (), not (equalTo (null )));
228157
@@ -269,15 +198,9 @@ public void appUsersAutomaticallyPaginatesCorrectly() throws IOException {
269198 }
270199
271200 @ Test
272- @ Category (IntegrationTestJWT .class )
273- @ Ignore ("Configure JWT authentication" )
274- public void appUsersManuallyPaginatesCorrectly () throws IOException {
275- Reader reader = new FileReader ("src/test/config/config.json" );
276- BoxConfig boxConfig = BoxConfig .readFrom (reader );
277- IAccessTokenCache accessTokenCache = new InMemoryLRUAccessTokenCache (100 );
278-
279- BoxDeveloperEditionAPIConnection api =
280- BoxDeveloperEditionAPIConnection .getAppEnterpriseConnection (boxConfig , accessTokenCache );
201+ @ Ignore ("Takes too long to run" )
202+ public void appUsersManuallyPaginatesCorrectly () {
203+ BoxDeveloperEditionAPIConnection api = jwtApiForServiceAccount ();
281204
282205 assertThat (api .getAccessToken (), not (equalTo (null )));
283206
0 commit comments