本文整理汇总了Java中com.squareup.okhttp.mockwebserver.MockResponse类的典型用法代码示例。如果您正苦于以下问题:Java MockResponse类的具体用法?Java MockResponse怎么用?Java MockResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MockResponse类属于com.squareup.okhttp.mockwebserver包,在下文中一共展示了MockResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldReturnValidResponseGivenValidClientRegisterRequest
import com.squareup.okhttp.mockwebserver.MockResponse; //导入依赖的package包/类
@Test
public void shouldReturnValidResponseGivenValidClientRegisterRequest()
throws Exception {
MockResponse mockResponse = new MockResponse()
.setBody(FileUtil.readFile("register.json"));
mockWebServer.enqueue(mockResponse);
final String testSigningKey = "testSigningKey";
final String testEncryptionKey = "testEncryptionKey";
CreateIdentityRequest request = new CreateIdentityRequest(
testSigningKey, testEncryptionKey, null, null);
String clientId = apiClient.createIdentity(request).getIdentityId();
Map expectedRequestBody = ImmutableMap.of(
ATTR_CRYPTO_PUBLIC_KEY, testEncryptionKey,
ATTR_SIGNING_PUBLIC_KEY, testSigningKey);
assertThat(getBodyAsMap(mockWebServer.takeRequest()), equalTo(expectedRequestBody));
assertEquals(clientId, IDENTITY_ID);
}
示例2: testDeleteCondition
import com.squareup.okhttp.mockwebserver.MockResponse; //导入依赖的package包/类
public void testDeleteCondition() throws Exception {
final MockWebServer server = mockWebServer();
server.enqueue(new MockResponse().setResponseCode(200));
try (final BitbucketApi baseApi = api(server.getUrl("/"))) {
final RequestStatus success = baseApi.defaultReviewersApi().deleteCondition(projectKey, repoKey, 10L);
assertThat(success).isNotNull();
assertThat(success.value()).isTrue();
assertThat(success.errors()).isEmpty();
assertSent(server, "DELETE", defaultReviewersPath + BitbucketApiMetadata.API_VERSION
+ projectsPath + projectKey + reposPath + repoKey + "/condition/10");
} finally {
server.shutdown();
}
}
示例3: testDeleteConditionOnError
import com.squareup.okhttp.mockwebserver.MockResponse; //导入依赖的package包/类
public void testDeleteConditionOnError() throws Exception {
final MockWebServer server = mockWebServer();
server.enqueue(new MockResponse().setBody(payloadFromResource("/repository-not-exist.json")).setResponseCode(404));
try (final BitbucketApi baseApi = api(server.getUrl("/"))) {
final RequestStatus success = baseApi.defaultReviewersApi().deleteCondition(projectKey, repoKey, 10L);
assertThat(success).isNotNull();
assertThat(success.value()).isFalse();
assertThat(success.errors()).isNotEmpty();
assertSent(server, "DELETE", defaultReviewersPath + BitbucketApiMetadata.API_VERSION
+ projectsPath + projectKey + reposPath + repoKey + "/condition/10");
} finally {
server.shutdown();
}
}
示例4: testDeleteBranchModelConfiguration
import com.squareup.okhttp.mockwebserver.MockResponse; //导入依赖的package包/类
public void testDeleteBranchModelConfiguration() throws Exception {
final MockWebServer server = mockWebServer();
server.enqueue(new MockResponse().setResponseCode(204));
try (final BitbucketApi baseApi = api(server.getUrl("/"))) {
final RequestStatus success = baseApi.branchApi().deleteModelConfiguration(projectKey, repoKey);
assertThat(success).isNotNull();
assertThat(success.value()).isTrue();
assertThat(success.errors()).isEmpty();
assertSent(server, localDeleteMethod, localRestPath + BitbucketApiMetadata.API_VERSION
+ localProjectsPath + projectKey + localReposPath + repoKey + branchModelPath);
} finally {
server.shutdown();
}
}
示例5: testUpdateConditionOnError
import com.squareup.okhttp.mockwebserver.MockResponse; //导入依赖的package包/类
public void testUpdateConditionOnError() throws Exception {
final MockWebServer server = mockWebServer();
server.enqueue(new MockResponse().setBody(payloadFromResource("/repository-not-exist.json")).setResponseCode(404));
try (final BitbucketApi baseApi = api(server.getUrl("/"))) {
final Long requiredApprover = 1L;
final Matcher matcherSrc = Matcher.create(Matcher.MatcherId.ANY, true);
final Matcher matcherDst = Matcher.create(Matcher.MatcherId.ANY, true);
final List<User> listUser = new ArrayList<>();
listUser.add(User.create(projectKey, testEmail, 1, projectKey, true, projectKey, normalKeyword));
final CreateCondition condition = CreateCondition.create(10L, matcherSrc, matcherDst, listUser, requiredApprover);
final Condition returnCondition = baseApi.defaultReviewersApi().updateCondition(projectKey, "123456", 10L, condition);
assertThat(returnCondition).isNotNull();
assertThat(returnCondition.errors()).isNotEmpty();
assertThat(returnCondition.errors().size()).isEqualTo(1);
assertSent(server, "PUT", defaultReviewersPath + BitbucketApiMetadata.API_VERSION
+ projectsPath + projectKey + "/repos/123456/condition/10");
} finally {
server.shutdown();
}
}
示例6: shouldReturnValidResponseGivenValidSecretCreationRequest
import com.squareup.okhttp.mockwebserver.MockResponse; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void shouldReturnValidResponseGivenValidSecretCreationRequest() throws Exception {
// set up mock server
mockWebServer.enqueue(new MockResponse().setBody(FileUtil.readFile("createSecret.json")));
// create request
String content = "base64String";
String secretKey = BaseEncoding.base64().encode(SharedTestKeys.SECRET_KEY_A.getEncoded());
CreateSecretRequest createSecretRequest = new CreateSecretRequest(IDENTITY_ID, content, new EncryptionDetails(secretKey, "1"));
// make a test call
CreateSecretResponse response = createDeltaApiClient().createSecret(createSecretRequest);
// assert response
assertEquals(SECRET_ID, response.getSecretId());
// assert the request we made during the test call
RecordedRequest request = mockWebServer.takeRequest(1, TimeUnit.SECONDS);
assertEquals(IDENTITY_ID, getAuthIdentity(request.getHeader(AUTHORIZATION)));
Map<String, Object> requestBody = getBodyAsMap(request);
assertEquals(content, requestBody.get("content"));
Map<String, String> encryptionDetails = (Map<String, String>) requestBody.get("encryptionDetails");
assertEquals("1", encryptionDetails.get("initialisationVector"));
assertEquals(secretKey, encryptionDetails.get("symmetricKey"));
}
示例7: shouldReturnValidResponseGivenValidGetSecretRequest
import com.squareup.okhttp.mockwebserver.MockResponse; //导入依赖的package包/类
@Test
public void shouldReturnValidResponseGivenValidGetSecretRequest() throws Exception {
// set up mock server
mockWebServer.enqueue(new MockResponse().setBody(FileUtil.readFile("getSecret.json")));
SecretRequest secretRequest = new SecretRequest(IDENTITY_ID, SECRET_ID);
// make a test call
GetSecretResponse response = createDeltaApiClient().getSecret(secretRequest);
// assert the response
assertEquals(SECRET_ID, response.getId());
assertEquals("2016-08-23T17:02:47Z", response.getCreated());
assertEquals("b15e50ea-ce07-4a3d-a4fc-0cd6b4d9ab13", response.getCreatedBy());
assertEquals(IDENTITY_ID, response.getRsaKeyOwner());
// assert the request we made during the test call
RecordedRequest request = mockWebServer.takeRequest(1, TimeUnit.SECONDS);
assertEquals(IDENTITY_ID, getAuthIdentity(request.getHeader(AUTHORIZATION)));
assertTrue(request.getPath().endsWith("/" + SECRET_ID));
}
示例8: shouldReturnValidResponseGivenValidGetSecretContentRequest
import com.squareup.okhttp.mockwebserver.MockResponse; //导入依赖的package包/类
@Test
public void shouldReturnValidResponseGivenValidGetSecretContentRequest() throws Exception {
// set up mock server
mockWebServer.enqueue(new MockResponse().setBody(FileUtil.readFile("getSecretContent.json")));
SecretRequest secretRequest = new SecretRequest(IDENTITY_ID, SECRET_ID);
// make a test call
String response = createDeltaApiClient().getSecretContent(secretRequest);
// assert the response
assertEquals("base64String", response);
// assert the request we made during the test call
RecordedRequest request = mockWebServer.takeRequest(1, TimeUnit.SECONDS);
assertEquals(IDENTITY_ID, getAuthIdentity(request.getHeader(AUTHORIZATION)));
assertTrue(request.getPath().endsWith("/" + SECRET_ID + "/content"));
}
示例9: shouldReturnValidResponseGivenValidGetSecretMetadataRequest
import com.squareup.okhttp.mockwebserver.MockResponse; //导入依赖的package包/类
@Test
public void shouldReturnValidResponseGivenValidGetSecretMetadataRequest() throws Exception {
// set up mock server
mockWebServer.enqueue(new MockResponse()
.setBody(FileUtil.readFile("getSecretMetadata.json"))
.addHeader(HttpHeaders.ETAG, "2"));
SecretRequest secretRequest = new SecretRequest(IDENTITY_ID, SECRET_ID);
// make a test call
GetSecretMetadataResponse response = createDeltaApiClient().getSecretMetadata(secretRequest);
// assert the response
assertEquals(METADATA, response.getMetadata());
// assert the request we made during the test call
RecordedRequest request = mockWebServer.takeRequest(1, TimeUnit.SECONDS);
assertEquals(IDENTITY_ID, getAuthIdentity(request.getHeader(AUTHORIZATION)));
assertTrue(request.getPath().endsWith("/" + SECRET_ID + "/metadata"));
}
示例10: testDeleteProjectNonExistent
import com.squareup.okhttp.mockwebserver.MockResponse; //导入依赖的package包/类
public void testDeleteProjectNonExistent() throws Exception {
final MockWebServer server = mockWebServer();
server.enqueue(new MockResponse()
.setBody(payloadFromResource("/project-not-exist.json"))
.setResponseCode(404));
try (final BitbucketApi baseApi = api(server.getUrl("/"))) {
final String projectKey = "NOTEXIST";
final RequestStatus success = baseApi.projectApi().delete(projectKey);
assertThat(success).isNotNull();
assertThat(success.value()).isFalse();
assertThat(success.errors()).isNotEmpty();
assertSent(server, "DELETE", "/rest/api/" + BitbucketApiMetadata.API_VERSION + "/projects/" + projectKey);
} finally {
server.shutdown();
}
}
示例11: shouldReturnValidResponseGivenValidGetDerivedSecretsRequest
import com.squareup.okhttp.mockwebserver.MockResponse; //导入依赖的package包/类
@Test
public void shouldReturnValidResponseGivenValidGetDerivedSecretsRequest() throws Exception {
// set up mock server
mockWebServer.enqueue(new MockResponse().setBody(FileUtil.readFile("getDerivedSecrets.json")));
GetDerivedSecretsRequest getDerivedSecretsRequest = new GetDerivedSecretsRequest(IDENTITY_ID, SECRET_ID, 0, 10);
// make a test call
List<GetSecretsResponse> response = createDeltaApiClient().getDerivedSecrets(getDerivedSecretsRequest);
// assert the response
assertEquals(1, response.size());
GetSecretsResponse secret = response.get(0);
assertEquals(SECRET_ID, secret.getId());
assertEquals("https://example.server/secrets/067e6162-3b6f-4ae2-a171-2470b63dff00", secret.getHref());
assertEquals("b15e50ea-ce07-4a3d-a4fc-0cd6b4d9ab13", secret.getCreatedBy());
assertEquals("2016-08-23T17:02:47Z", secret.getCreated());
assertEquals("eb4f44d0-1b47-4981-9661-1c1101d7a049", secret.getBaseSecret());
assertEquals(METADATA, secret.getMetadata());
// assert the request we made during the test call
RecordedRequest request = mockWebServer.takeRequest(1, TimeUnit.SECONDS);
assertEquals(IDENTITY_ID, getAuthIdentity(request.getHeader(AUTHORIZATION)));
assertEquals("GET", request.getMethod());
assertTrue(request.getPath()
.endsWith("/secrets?baseSecret=" + SECRET_ID + "&createdBy=" + IDENTITY_ID + "&page=0&pageSize=10"));
}
示例12: shouldReturnValidResponseGivenValidUpdateIdentityMetadataRequest
import com.squareup.okhttp.mockwebserver.MockResponse; //导入依赖的package包/类
@Test
public void shouldReturnValidResponseGivenValidUpdateIdentityMetadataRequest() throws Exception {
// set up mock server
mockWebServer.enqueue(new MockResponse().setBody(FileUtil.readFile("getIdentitiesByMetadata.json")));
UpdateIdentityMetadataRequest updateIdentityMetadataRequest = new UpdateIdentityMetadataRequest(
IDENTITY_ID,
"identity2",
10L,
METADATA);
// make a test call
createDeltaApiClient().updateIdentityMetadata(updateIdentityMetadataRequest);
// assert the request we made during the test call
RecordedRequest request = mockWebServer.takeRequest(1, TimeUnit.SECONDS);
assertEquals(IDENTITY_ID, getAuthIdentity(request.getHeader(AUTHORIZATION)));
assertEquals("PUT", request.getMethod());
assertTrue(request.getPath().endsWith("/identity2"));
}
示例13: sessionInitShouldReturnSessionKey
import com.squareup.okhttp.mockwebserver.MockResponse; //导入依赖的package包/类
@Ignore("There is a problem in this test as the sessionKey gets updated by the integration tests and failing this tests.")
@Test
public void sessionInitShouldReturnSessionKey() throws IOException {
HttpUrl baseUrl = server.url("/next/2/");
JSONObject sessionInitRecorded = recordedResponses.sessionInit();
server.enqueue(new MockResponse().setBody(sessionInitRecorded.toString()));
Properties properties = resourceReader.getProperties("test.properties");
properties.setProperty("baseurl", baseUrl.toString());
Session session = new Session(properties);
Login loginObject = session.getLoginObject();
assertThat("The sessionkey from login object should match the recorded session key",
loginObject.getSessionKey(), equalTo(sessionInitRecorded.getString("session_key")));
assertThat("Only one request was made to the mock server",
server.getRequestCount(), equalTo(1));
}
示例14: testGetBranchModel
import com.squareup.okhttp.mockwebserver.MockResponse; //导入依赖的package包/类
public void testGetBranchModel() throws Exception {
final MockWebServer server = mockWebServer();
server.enqueue(new MockResponse().setBody(payloadFromResource("/branch-model.json")).setResponseCode(200));
try (final BitbucketApi baseApi = api(server.getUrl("/"))) {
final BranchModel branchModel = baseApi.branchApi().model(projectKey, repoKey);
assertThat(branchModel).isNotNull();
System.out.println(branchModel.errors());
assertThat(branchModel.errors().isEmpty()).isTrue();
assertThat(branchModel.types().size() > 0).isTrue();
assertSent(server, localGetMethod, localRestPath + BitbucketApiMetadata.API_VERSION
+ localProjectsPath + projectKey + localReposPath + repoKey + "/branchmodel");
} finally {
server.shutdown();
}
}
示例15: testListBranchePermissions
import com.squareup.okhttp.mockwebserver.MockResponse; //导入依赖的package包/类
public void testListBranchePermissions() throws Exception {
final MockWebServer server = mockWebServer();
server.enqueue(new MockResponse().setBody(payloadFromResource("/branch-permission-list.json")).setResponseCode(200));
try (final BitbucketApi baseApi = api(server.getUrl("/"))) {
final BranchRestrictionPage branch = baseApi.branchApi().listBranchRestriction(projectKey, repoKey, null, 1);
assertThat(branch).isNotNull();
assertThat(branch.errors().isEmpty()).isTrue();
assertThat(branch.values().size() > 0).isTrue();
assertThat(839L == branch.values().get(0).id()).isTrue();
assertThat(2 == branch.values().get(0).accessKeys().size()).isTrue();
final Map<String, ?> queryParams = ImmutableMap.of(localLimit, 1);
assertSent(server, localGetMethod, branchPermissionsPath
+ localProjectsPath + projectKey + localReposPath + repoKey + "/restrictions", queryParams);
} finally {
server.shutdown();
}
}