本文整理汇总了Java中com.jcabi.http.mock.MkContainer.take方法的典型用法代码示例。如果您正苦于以下问题:Java MkContainer.take方法的具体用法?Java MkContainer.take怎么用?Java MkContainer.take使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jcabi.http.mock.MkContainer
的用法示例。
在下文中一共展示了MkContainer.take方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deletesProjectBranchAndModifiesRepositoryName
import com.jcabi.http.mock.MkContainer; //导入方法依赖的package包/类
/**
* RtRepository can delete the repository branch from
* the VersionEye server and modifies repository name by replacing
* '/' to ':' and '.' to '~'.
* @throws IOException If something goes wrong.
*/
@Test
public void deletesProjectBranchAndModifiesRepositoryName()
throws IOException {
final MkContainer container = new MkGrizzlyContainer().next(
new MkAnswer.Simple(HttpURLConnection.HTTP_OK)
).start();
final Repository repository = new RtRepository(
Json.createObjectBuilder().add("fullname", "repo/repo").build(),
new JdkRequest(container.home())
);
repository.delete("master");
final MkQuery request = container.take();
MatcherAssert.assertThat(
request.method(), Matchers.equalTo("DELETE")
);
MatcherAssert.assertThat(
request.uri().toString(),
Matchers.equalTo("/repo:repo?branch=master")
);
}
示例2: deletesProject
import com.jcabi.http.mock.MkContainer; //导入方法依赖的package包/类
/**
* RtProject can delete the project from the VersionEye server.
* @throws IOException If something goes wrong.
*/
@Test
public void deletesProject() throws IOException {
final MkContainer container = new MkGrizzlyContainer().next(
new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT)
).start();
final Project project = new RtProject(
new JdkRequest(container.home()),
Mockito.mock(Team.class),
Json.createObjectBuilder().add("ids", "project123").build()
);
project.delete();
final MkQuery request = container.take();
MatcherAssert.assertThat(
request.method(), Matchers.equalTo("DELETE")
);
MatcherAssert.assertThat(
request.uri().toString(), Matchers.equalTo("/project123")
);
}
示例3: hooksOnGithub
import com.jcabi.http.mock.MkContainer; //导入方法依赖的package包/类
/**
* RtProject can hook itself to Github.
* @throws IOException If something goes wrong.
*/
@Test
public void hooksOnGithub() throws IOException {
final MkContainer container = new MkGrizzlyContainer().next(
new MkAnswer.Simple(HttpURLConnection.HTTP_CREATED)
).start();
Team team = Mockito.mock(Team.class);
Mockito.when(team.versionEye())
.thenReturn(
new RtVersionEye(
new JdkRequest(container.home())
)
);
final Project project = new RtProject(
new FakeRequest(), team,
Json.createObjectBuilder().add("ids", "id123").build()
);
MatcherAssert.assertThat(project.hook(), Matchers.is(project));
final MkQuery request = container.take();
MatcherAssert.assertThat(
request.method(), Matchers.equalTo("POST")
);
MatcherAssert.assertThat(
request.uri().toString(), Matchers.equalTo("/github/hook/id123")
);
}
示例4: markAsReadOk
import com.jcabi.http.mock.MkContainer; //导入方法依赖的package包/类
/**
* RtNotifications can mark notifications as read with OK status response
* @throws Exception If something goes wrong.
*/
@Test
public void markAsReadOk() throws Exception {
int port = this.port();
MkContainer server = new MkGrizzlyContainer()
.next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK)).start(port);
try {
Notifications notifications = new RtNotifications(
new Reason.Fake(),
"fake_token",
"http://localhost:"+port+"/"
);
notifications.markAsRead();
MkQuery req = server.take();
assertTrue(req.method().equals(Request.PUT));
assertTrue(req.body().equals("{}"));
assertTrue(req.uri().getQuery().contains("last_read_at="));
} finally {
server.stop();
}
}
示例5: markAsReadReset
import com.jcabi.http.mock.MkContainer; //导入方法依赖的package包/类
/**
* RtNotifications can mark notifications as read with RESET status response.
* @throws Exception If something goes wrong.
*/
@Test
public void markAsReadReset() throws Exception {
int port = this.port();
MkContainer server = new MkGrizzlyContainer()
.next(new MkAnswer.Simple(HttpURLConnection.HTTP_RESET)).start(port);
try {
Notifications notifications = new RtNotifications(
new Reason.Fake(),
"fake_token",
"http://localhost:"+port+"/"
);
notifications.markAsRead();
MkQuery req = server.take();
assertTrue(req.method().equals(Request.PUT));
assertTrue(req.body().equals("{}"));
assertTrue(req.uri().getQuery().contains("last_read_at="));
} finally {
server.stop();
}
}
示例6: sendsNotificationsWithUnauthorized
import com.jcabi.http.mock.MkContainer; //导入方法依赖的package包/类
/**
* NtPost handles unauthorized response.
* @throws Exception If something goes wrong.
*/
@Test
public void sendsNotificationsWithUnauthorized() throws Exception {
int port = this.port();
MkContainer server = new MkGrizzlyContainer()
.next(new MkAnswer.Simple(HttpURLConnection.HTTP_UNAUTHORIZED))
.start(port);
try {
Notifications notifications = new Notifications.FakeErrorOnMarkRead();
Post ntp = new NtPost(
notifications, "fake_token", "http://localhost:"+port+"/"
);
ntp.send();
MkQuery request = server.take();
String auth = request.headers().get(HttpHeaders.AUTHORIZATION).get(0);
assertTrue(auth.contains("fake_token"));
} finally {
server.stop();
}
}
示例7: sendsNotificationsWithServerError
import com.jcabi.http.mock.MkContainer; //导入方法依赖的package包/类
/**
* NtPost throws assertion error on unexpected status response.
* @throws Exception If something goes wrong.
*/
@Test (expected = AssertionError.class)
public void sendsNotificationsWithServerError() throws Exception {
int port = this.port();
MkContainer server = new MkGrizzlyContainer()
.next(new MkAnswer.Simple(HttpURLConnection.HTTP_INTERNAL_ERROR))
.start(port);
try {
Notifications notifications = new Notifications.FakeErrorOnMarkRead();
Post ntp = new NtPost(
notifications, "fake_token", "http://localhost:"+port+"/"
);
ntp.send();
MkQuery request = server.take();
String auth = request.headers().get(HttpHeaders.AUTHORIZATION).get(0);
assertTrue(auth.contains("fake_token"));
} finally {
server.stop();
}
}
示例8: sendsExportRequestToAwsEs
import com.jcabi.http.mock.MkContainer; //导入方法依赖的package包/类
/**
* A request is sent to the AWS Es bulk api service.
* @throws Exception If something goes wrong.
*/
@Test
public void sendsExportRequestToAwsEs() throws Exception {
List<WebPage> pages = new ArrayList<WebPage>();
pages.add(this.mockWebPage("http://www.test.com/crawledpage.html"));
pages.add(this.mockWebPage("https://www.test.com/stuff/crawledpage.html"));
int port = this.port();
MkContainer server = new MkGrizzlyContainer()
.next(new MkAnswer.Simple("{\"status\":\"Unit test successful!\"}"))
.start(port);
try {
new AmazonElasticSearch(
"testIndex",
new AccessKeyId.Fake("access_key"),
new SecretKey.Fake("secret_key"),
new Region.Fake("ro"),
new EsEndPoint.Fake("http://localhost:" + port + "/es")
).export(pages);
MkQuery request = server.take();
assertEquals("/es/_bulk/",request.uri().toString());
assertTrue("POST".equals(request.method()));
} finally {
server.stop();
}
}
示例9: sendsDeleteRequestToAwsEs
import com.jcabi.http.mock.MkContainer; //导入方法依赖的package包/类
/**
* A request to DELETE the index is made to ES.
* @throws Exception If something goes wrong.
*/
@Test
public void sendsDeleteRequestToAwsEs() throws Exception {
int port = this.port();
MkContainer server = new MkGrizzlyContainer()
.next(new MkAnswer.Simple("{\"status\":\"index deleted\"}"))
.start(port);
try {
new AmazonElasticSearch(
"index.to.be.deleted",
new AccessKeyId.Fake("access_key"),
new SecretKey.Fake("secret_key"),
new Region.Fake("ro"),
new EsEndPoint.Fake("http://localhost:" + port + "/es/")
).delete();
MkQuery request = server.take();
assertEquals("/es/index.to.be.deleted/", request.uri().toString());
assertTrue("DELETE".equals(request.method()));
} finally {
server.stop();
}
}
示例10: sendsDeleteDocumentRequestToAwsEs
import com.jcabi.http.mock.MkContainer; //导入方法依赖的package包/类
/**
* A request to DELETE a document, from one index, is made to ES.
* @throws Exception If something goes wrong.
*/
@Test
public void sendsDeleteDocumentRequestToAwsEs() throws Exception {
int port = this.port();
MkContainer server = new MkGrizzlyContainer()
.next(new MkAnswer.Simple("{\"status\":\"index deleted\"}"))
.start(port);
try {
new AmazonElasticSearch(
"index",
new AccessKeyId.Fake("access_key"),
new SecretKey.Fake("secret_key"),
new Region.Fake("ro"),
new EsEndPoint.Fake("http://localhost:" + port + "/es/")
).delete("page", "document_id");
MkQuery request = server.take();
assertEquals("/es/index/page/document_id/", request.uri().toString());
assertTrue("DELETE".equals(request.method()));
} finally {
server.stop();
}
}
示例11: tellsIfIndexExists
import com.jcabi.http.mock.MkContainer; //导入方法依赖的package包/类
/**
* AmazonEsRespository can tell if an index exists or not.
* @throws Exception If something goes wrong.
*/
@Test
public void tellsIfIndexExists() throws Exception {
int port = this.port();
MkContainer server = new MkGrizzlyContainer()
.next(new MkAnswer.Simple(HttpStatus.SC_OK))
.start(port);
try {
boolean exists = new AmazonElasticSearch(
"present.index",
new AccessKeyId.Fake("access_key"),
new SecretKey.Fake("secret_key"),
new Region.Fake("ro"),
new EsEndPoint.Fake("http://localhost:" + port + "/es")
).exists();
assertTrue(exists);
MkQuery request = server.take();
assertEquals("/es/present.index/", request.uri().toString());
assertTrue("HEAD".equals(request.method()));
} finally {
server.stop();
}
}
示例12: tellsIfIndexDoesNotExist
import com.jcabi.http.mock.MkContainer; //导入方法依赖的package包/类
/**
* AmazonEsRespository can tell if an index exists or not.
* @throws Exception If something goes wrong.
*/
@Test
public void tellsIfIndexDoesNotExist() throws Exception {
int port = this.port();
MkContainer server = new MkGrizzlyContainer()
.next(new MkAnswer.Simple(HttpStatus.SC_NOT_FOUND))
.start(port);
try {
boolean exists = new AmazonElasticSearch(
"missing.index",
new AccessKeyId.Fake("access_key"),
new SecretKey.Fake("secret_key"),
new Region.Fake("ro"),
new EsEndPoint.Fake("http://localhost:" + port + "/es/")
).exists();
assertFalse(exists);
MkQuery request = server.take();
assertEquals("/es/missing.index/", request.uri().toString());
assertTrue("HEAD".equals(request.method()));
} finally {
server.stop();
}
}
示例13: canDeleteDeployKey
import com.jcabi.http.mock.MkContainer; //导入方法依赖的package包/类
/**
* RtDeployKey can delete a deploy key.
*
* @throws Exception If some problem inside.
*/
@Test
public void canDeleteDeployKey() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(
new MkAnswer.Simple(
HttpURLConnection.HTTP_NO_CONTENT,
""
)
).start();
final DeployKey key = new RtDeployKey(
new ApacheRequest(container.home()),
3,
RtDeployKeyTest.repo()
);
key.remove();
final MkQuery query = container.take();
MatcherAssert.assertThat(
query.method(),
Matchers.equalTo(Request.DELETE)
);
container.stop();
}
示例14: patchesComment
import com.jcabi.http.mock.MkContainer; //导入方法依赖的package包/类
/**
* RtComment can patch a comment.
* @throws Exception - if anything goes wrong.
*/
@Test
public void patchesComment() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(
new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "")
).start();
final Repo repo = new MkGithub().randomRepo();
final Issue issue = repo.issues().create("testing5", "issue5");
final RtComment comment = new RtComment(
new ApacheRequest(container.home()), issue, 10
);
final JsonObject jsonPatch = Json.createObjectBuilder()
.add("title", "test comment").build();
try {
comment.patch(jsonPatch);
final MkQuery query = container.take();
MatcherAssert.assertThat(
query.method(), Matchers.equalTo(Request.PATCH)
);
} finally {
container.stop();
}
}
示例15: canDeleteHook
import com.jcabi.http.mock.MkContainer; //导入方法依赖的package包/类
/**
* RtHooks can delete a hook.
*
* @throws Exception if something goes wrong.
*/
@Test
public void canDeleteHook() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(
new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, "")
).start();
final Hooks hooks = new RtHooks(
new JdkRequest(container.home()),
RtHooksTest.repo()
);
hooks.remove(1);
try {
final MkQuery query = container.take();
MatcherAssert.assertThat(
query.method(),
Matchers.equalTo(Request.DELETE)
);
MatcherAssert.assertThat(
query.body(),
Matchers.isEmptyString()
);
} finally {
container.stop();
}
}