Skip to content

Commit 43bb054

Browse files
committed
api: Move test utils out of unit test directories.
https://codereview.appspot.com/107160043/
1 parent 7aecdea commit 43bb054

File tree

13 files changed

+126
-19
lines changed

13 files changed

+126
-19
lines changed
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,22 @@
1212
* the License.
1313
*/
1414

15-
package com.google.api.client.googleapis.extensions.appengine.auth.oauth2;
15+
package com.google.api.client.googleapis.extensions.appengine.testing.auth.oauth2;
1616

1717
import com.google.appengine.api.appidentity.AppIdentityService;
1818
import com.google.appengine.api.appidentity.AppIdentityServiceFailureException;
1919
import com.google.appengine.api.appidentity.PublicCertificate;
20+
import com.google.api.client.util.Beta;
2021

2122
import java.util.Collection;
2223

2324
/**
25+
* {@link Beta} <br/>
2426
* Mock implementation of AppIdentityService interface for testing.
2527
*
28+
* @since 1.19
2629
*/
30+
@Beta
2731
public class MockAppIdentityService implements AppIdentityService {
2832

2933
private int getAccessTokenCallCount = 0;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2014 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License
10+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the License for the specific language governing permissions and limitations under
12+
* the License.
13+
*/
14+
15+
/**
16+
* {@link com.google.api.client.util.Beta} <br/>
17+
* Test utilities for the {@code com.google.api.client.googleapis.extensions.appengine.auth.oauth2}
18+
* package.
19+
*
20+
* @since 1.19
21+
*/
22+
@com.google.api.client.util.Beta
23+
package com.google.api.client.googleapis.extensions.appengine.testing.auth.oauth2;
24+

google-api-client-appengine/src/test/java/com/google/api/client/googleapis/extensions/appengine/auth/oauth2/AppIdentityCredentialTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package com.google.api.client.googleapis.extensions.appengine.auth.oauth2;
1616

1717
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
18+
import com.google.api.client.googleapis.extensions.appengine.testing.auth.oauth2.MockAppIdentityService;
1819
import com.google.api.client.http.HttpHeaders;
1920
import com.google.api.client.http.HttpRequest;
2021
import com.google.api.client.http.HttpTransport;

google-api-client/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@
8585
<dependency>
8686
<groupId>com.google.guava</groupId>
8787
<artifactId>guava-jdk5</artifactId>
88-
<scope>test</scope>
8988
</dependency>
9089
</dependencies>
9190
</project>

google-api-client/src/test/java/com/google/api/client/googleapis/TestUtils.java renamed to google-api-client/src/main/java/com/google/api/client/googleapis/testing/TestUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* the License.
1313
*/
1414

15-
package com.google.api.client.googleapis;
15+
package com.google.api.client.googleapis.testing;
1616

1717
import com.google.common.base.Splitter;
1818
import com.google.common.collect.Lists;
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,34 @@
1212
* the License.
1313
*/
1414

15-
package com.google.api.client.googleapis.auth.oauth2;
15+
package com.google.api.client.googleapis.testing.auth.oauth2;
1616

17-
import com.google.api.client.googleapis.TestUtils;
17+
import com.google.api.client.googleapis.auth.oauth2.GoogleOAuthConstants;
18+
import com.google.api.client.googleapis.testing.TestUtils;
1819
import com.google.api.client.http.LowLevelHttpRequest;
1920
import com.google.api.client.http.LowLevelHttpResponse;
2021
import com.google.api.client.json.GenericJson;
22+
import com.google.api.client.json.jackson2.JacksonFactory;
2123
import com.google.api.client.json.Json;
2224
import com.google.api.client.json.JsonFactory;
23-
import com.google.api.client.json.jackson2.JacksonFactory;
2425
import com.google.api.client.json.webtoken.JsonWebSignature;
2526
import com.google.api.client.testing.http.MockHttpTransport;
2627
import com.google.api.client.testing.http.MockLowLevelHttpRequest;
2728
import com.google.api.client.testing.http.MockLowLevelHttpResponse;
29+
import com.google.api.client.util.Beta;
2830

2931
import java.io.IOException;
3032
import java.util.HashMap;
3133
import java.util.Map;
3234

33-
3435
/**
36+
* {@link Beta} <br/>
3537
* A test transport that simulates Google's token server for refresh tokens and service accounts.
38+
*
39+
* @since 1.19
3640
*/
37-
class MockTokenServerTransport extends MockHttpTransport {
41+
@Beta
42+
public class MockTokenServerTransport extends MockHttpTransport {
3843
static final String EXPECTED_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:jwt-bearer";
3944
static final JsonFactory JSON_FACTORY = new JacksonFactory();
4045
Map<String, String> serviceAccounts = new HashMap<String, String>();
@@ -48,11 +53,11 @@ public void addServiceAccount(String email, String accessToken) {
4853
serviceAccounts.put(email, accessToken);
4954
}
5055

51-
void addClient(String clientId, String clientSecret) {
56+
public void addClient(String clientId, String clientSecret) {
5257
clients.put(clientId, clientSecret);
5358
}
5459

55-
void addRefreshToken(String refreshToken, String accessTokenToReturn) {
60+
public void addRefreshToken(String refreshToken, String accessTokenToReturn) {
5661
refreshTokens.put(refreshToken, accessTokenToReturn);
5762
}
5863

@@ -81,7 +86,6 @@ public LowLevelHttpResponse execute() throws IOException {
8186
throw new IOException("Refresh Token not found.");
8287
}
8388
accessToken = refreshTokens.get(foundRefresh);
84-
8589
} else if (query.containsKey("grant_type")) {
8690
String grantType = query.get("grant_type");
8791
if (!EXPECTED_GRANT_TYPE.equals(grantType)) {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (c) 2014 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License
10+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the License for the specific language governing permissions and limitations under
12+
* the License.
13+
*/
14+
15+
/**
16+
* {@link com.google.api.client.util.Beta} <br/>
17+
* Test utilities for the {@code com.google.api.client.googleapis.auth.oauth2} package.
18+
*
19+
* @since 1.19
20+
*/
21+
@com.google.api.client.util.Beta
22+
package com.google.api.client.googleapis.testing.auth.oauth2;
23+
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* the License.
1313
*/
1414

15-
package com.google.api.client.googleapis.compute;
15+
package com.google.api.client.googleapis.testing.compute;
1616

1717
import com.google.api.client.http.LowLevelHttpRequest;
1818
import com.google.api.client.http.LowLevelHttpResponse;
@@ -23,19 +23,23 @@
2323
import com.google.api.client.testing.http.MockHttpTransport;
2424
import com.google.api.client.testing.http.MockLowLevelHttpRequest;
2525
import com.google.api.client.testing.http.MockLowLevelHttpResponse;
26+
import com.google.api.client.util.Beta;
2627

2728
import java.io.IOException;
2829

2930
/**
30-
* Transport that simulates the GCE metadata server for access tokens
31+
* {@link Beta} <br/>
32+
* Transport that simulates the GCE metadata server for access tokens.
3133
*
34+
* @since 1.19
3235
*/
36+
@Beta
3337
public class MockMetadataServerTransport extends MockHttpTransport {
3438

35-
private final static String METADATA_TOKEN_SERVER_URL =
39+
private static final String METADATA_TOKEN_SERVER_URL =
3640
"http://metadata/computeMetadata/v1/instance/service-accounts/default/token";
3741

38-
private final static String METADATA_SERVER_URL = "http://metadata.google.internal";
42+
private static final String METADATA_SERVER_URL = "http://metadata.google.internal";
3943

4044

4145
static final JsonFactory JSON_FACTORY = new JacksonFactory();
@@ -88,8 +92,7 @@ public LowLevelHttpResponse execute() throws IOException {
8892
}
8993
};
9094
return request;
91-
}
92-
else if (url.equals(METADATA_SERVER_URL)) {
95+
} else if (url.equals(METADATA_SERVER_URL)) {
9396
MockLowLevelHttpRequest request = new MockLowLevelHttpRequest(url) {
9497
@Override
9598
public LowLevelHttpResponse execute() {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (c) 2014 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License
10+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the License for the specific language governing permissions and limitations under
12+
* the License.
13+
*/
14+
15+
/**
16+
* {@link com.google.api.client.util.Beta} <br/>
17+
* Test utilities for the {@code com.google.api.client.googleapis.compute} package.
18+
*
19+
* @since 1.19
20+
*/
21+
@com.google.api.client.util.Beta
22+
package com.google.api.client.googleapis.testing.compute;
23+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (c) 2014 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License
10+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the License for the specific language governing permissions and limitations under
12+
* the License.
13+
*/
14+
15+
/**
16+
* {@link com.google.api.client.util.Beta} <br/>
17+
* Test utilities for the {@code com.google.api.client.googleapis} package.
18+
*
19+
* @since 1.19
20+
*/
21+
@com.google.api.client.util.Beta
22+
package com.google.api.client.googleapis.testing;
23+

0 commit comments

Comments
 (0)