Skip to content

Commit e5a2ebc

Browse files
authored
chore: TestConfig.java in unit tests no longer collides with TestConfig.java in integration tests (#1084)
1 parent 7b25df2 commit e5a2ebc

39 files changed

Lines changed: 335 additions & 815 deletions

src/intTest/java/com/box/sdk/BoxAPIConnectionIT.java

Lines changed: 12 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
package com.box.sdk;
22

33
import static com.box.sdk.BoxApiProvider.jwtApiForServiceAccount;
4+
import static com.box.sdk.BoxApiProvider.jwtBoxConfig;
45
import static org.hamcrest.MatcherAssert.assertThat;
56
import static org.hamcrest.Matchers.equalTo;
67
import static org.hamcrest.Matchers.is;
78
import static org.hamcrest.Matchers.not;
89
import static org.hamcrest.Matchers.notNullValue;
910
import static org.junit.Assert.assertEquals;
1011

11-
import java.io.FileReader;
12-
import java.io.IOException;
13-
import java.io.Reader;
1412
import java.net.MalformedURLException;
1513
import java.net.URL;
1614
import java.util.ArrayList;
1715
import java.util.Calendar;
1816
import java.util.List;
1917
import org.junit.Ignore;
2018
import org.junit.Test;
21-
import org.junit.experimental.categories.Category;
2219

2320

2421
public 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

src/intTest/java/com/box/sdk/BoxApiProvider.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@ private BoxApiProvider() {
1515
}
1616

1717
static BoxDeveloperEditionAPIConnection jwtApiForServiceAccount() {
18+
BoxConfig boxConfig = jwtBoxConfig();
19+
InMemoryLRUAccessTokenCache tokenCache = new InMemoryLRUAccessTokenCache(10);
20+
return BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(boxConfig, tokenCache);
21+
}
22+
23+
static BoxConfig jwtBoxConfig() {
1824
Map<String, String> environmentProperties = System.getenv();
1925
String jwtConfigEncoded = getEnvProperty(environmentProperties, JWT_CONFIG_ENV_NAME);
2026
byte[] decodedJwtConfig = Base64.getDecoder().decode(jwtConfigEncoded);
21-
BoxConfig boxConfig = BoxConfig.readFrom(new String(decodedJwtConfig));
22-
InMemoryLRUAccessTokenCache tokenCache = new InMemoryLRUAccessTokenCache(10);
23-
return BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(boxConfig, tokenCache);
27+
return BoxConfig.readFrom(new String(decodedJwtConfig));
2428
}
2529

2630
private static String getEnvProperty(Map<String, String> environmentProperties, String name) {

src/test/java/com/box/sdk/BatchAPIRequestTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class BatchAPIRequestTest {
2929

3030
@Rule
3131
public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
32-
private final BoxAPIConnection api = TestConfig.getAPIConnection();
32+
private final BoxAPIConnection api = TestUtils.getAPIConnection();
3333

3434
@Before
3535
public void setUpBaseUrl() {
@@ -261,8 +261,8 @@ public void testBatchRequestEndToEnd() throws IOException {
261261
.add("$scope", "global")
262262
.add("$canEdit", true);
263263

264-
String request = TestConfig.getFixture("BoxBatch/BatchCreateMetadataRequest");
265-
String response = TestConfig.getFixture("BoxBatch/BatchCreateMetadataResponse");
264+
String request = TestUtils.getFixture("BoxBatch/BatchCreateMetadataRequest");
265+
String response = TestUtils.getFixture("BoxBatch/BatchCreateMetadataResponse");
266266

267267
wireMockRule.stubFor(WireMock.post(WireMock.urlPathEqualTo(batchURL))
268268
.withRequestBody(WireMock.equalToJson(request))

0 commit comments

Comments
 (0)