本文整理汇总了Java中com.jcabi.http.mock.MkContainer.stop方法的典型用法代码示例。如果您正苦于以下问题:Java MkContainer.stop方法的具体用法?Java MkContainer.stop怎么用?Java MkContainer.stop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jcabi.http.mock.MkContainer
的用法示例。
在下文中一共展示了MkContainer.stop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: pathFromUsers
import com.jcabi.http.mock.MkContainer; //导入方法依赖的package包/类
/**
* RtUser return Request with path.
* @throws Exception If fails
*/
@Test
public void pathFromUsers() throws Exception {
final MkContainer container = new MkGrizzlyContainer()
.next(
new MkAnswer.Simple(
HttpURLConnection.HTTP_OK,
"{\"body\":\"hi\"}"
)
).start();
new RtHub(
container.home()
).users().self().json();
container.stop();
MatcherAssert.assertThat(
container.take().uri(),
CoreMatchers.equalTo(
new URI("/hub/api/rest/users/me")
)
);
}
示例2: userAgent
import com.jcabi.http.mock.MkContainer; //导入方法依赖的package包/类
/**
* RtHub return Request with UserAgent.
* @throws Exception If fails
*/
@Test
public void userAgent() throws Exception {
final MkContainer container = new MkGrizzlyContainer()
.next(
new MkAnswer.Simple("hello, world!")
).start();
new RtHub(
container.home()
).entry().fetch();
container.stop();
MatcherAssert.assertThat(
container.take().headers(),
Matchers.hasEntry(
Matchers.equalTo(HttpHeaders.USER_AGENT),
Matchers.hasItem(
String.format(
"jb-hub-api-client %s %s %s",
Manifests.read("Hub-Version"),
Manifests.read("Hub-Build"),
Manifests.read("Hub-Date")
)
)
)
);
}
示例3: path
import com.jcabi.http.mock.MkContainer; //导入方法依赖的package包/类
/**
* RtHub return Request with path.
* @throws Exception If fails
*/
@Test
public void path() throws Exception {
final MkContainer container = new MkGrizzlyContainer()
.next(
new MkAnswer.Simple("hello, world!")
).start();
new RtHub(
container.home()
).entry().fetch();
container.stop();
MatcherAssert.assertThat(
container.take().uri(),
CoreMatchers.equalTo(
new URI("/hub/api/rest")
)
);
}
示例4: authorizationToken
import com.jcabi.http.mock.MkContainer; //导入方法依赖的package包/类
/**
* RtHub return Request with Authorization token.
* @throws Exception If fails
*/
@Test
public void authorizationToken() throws Exception {
final MkContainer container = new MkGrizzlyContainer()
.next(
new MkAnswer.Simple("hello, world!")
).start();
new RtHub(
container.home(),
"token"
).entry().fetch();
container.stop();
MatcherAssert.assertThat(
container.take().headers(),
Matchers.hasEntry(
Matchers.equalTo(HttpHeaders.AUTHORIZATION),
Matchers.hasItem(
"token"
)
)
);
}
示例5: fetchesNotifications
import com.jcabi.http.mock.MkContainer; //导入方法依赖的package包/类
/**
* RtNotifications can fetch the notifications from the server.
* @throws Exception If something goes wrong.
*/
@Test
public void fetchesNotifications() throws Exception {
int port = this.port();
MkContainer server = new MkGrizzlyContainer()
.next(new MkAnswer.Simple("[{\"notification\":\"first\"},{\"notification\":\"second\"}]")).start(port);
try {
Notifications notifications = new RtNotifications(
new Reason.Fake(),
"fake_token",
"http://localhost:"+port+"/"
);
List<JsonObject> found = notifications.fetch();
assertTrue(found.size() == 2);
assertTrue(found.get(0).getString("notification").equals("first"));
assertTrue(found.get(1).getString("notification").equals("second"));
} finally {
server.stop();
}
}
示例6: fetchesNotificationsWithError
import com.jcabi.http.mock.MkContainer; //导入方法依赖的package包/类
/**
* RtNotifications.fetch throws assertion error when the response status is not OK
* @throws Exception If something goes wrong.
*/
@Test (expected = AssertionError.class)
public void fetchesNotificationsWithError() throws Exception {
int port = this.port();
MkContainer server = new MkGrizzlyContainer()
.next(new MkAnswer.Simple(HttpURLConnection.HTTP_BAD_REQUEST)).start(port);
try {
Notifications notifications = new RtNotifications(
new Reason.Fake(),
"fake_token",
"http://localhost:"+port+"/"
);
notifications.fetch();
} finally {
server.stop();
}
}
示例7: nothingFetched
import com.jcabi.http.mock.MkContainer; //导入方法依赖的package包/类
/**
* RtNotifications can fetch 0 notifications from the server.
* @throws Exception If something goes wrong.
*/
@Test
public void nothingFetched() throws Exception {
int port = this.port();
MkContainer server = new MkGrizzlyContainer()
.next(new MkAnswer.Simple("[]")).start(port);
try {
Notifications notifications = new RtNotifications(
new Reason.Fake(),
"fake_token",
"http://localhost:"+port+"/"
);
List<JsonObject> found = notifications.fetch();
assertTrue(found.size() == 0);
} finally {
server.stop();
}
}
示例8: 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();
}
}
示例9: 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();
}
}
示例10: markAsReadServerNotOk
import com.jcabi.http.mock.MkContainer; //导入方法依赖的package包/类
/**
* RtNotifications.markAsRead throws assertion error when there is an
* unexpected status response.
* @throws Exception If something goes wrong.
*/
@Test (expected = AssertionError.class)
public void markAsReadServerNotOk() throws Exception {
int port = this.port();
MkContainer server = new MkGrizzlyContainer()
.next(new MkAnswer.Simple(HttpURLConnection.HTTP_INTERNAL_ERROR)).start(port);
try {
Notifications notifications = new RtNotifications(
new Reason.Fake(),
"fake_token",
"http://localhost:"+port+"/"
);
notifications.markAsRead();
} finally {
server.stop();
}
}
示例11: 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();
}
}
示例12: 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();
}
}
示例13: 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();
}
}
示例14: 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();
}
}
示例15: 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();
}
}