本文整理汇总了Java中com.jcabi.http.request.ApacheRequest类的典型用法代码示例。如果您正苦于以下问题:Java ApacheRequest类的具体用法?Java ApacheRequest怎么用?Java ApacheRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ApacheRequest类属于com.jcabi.http.request包,在下文中一共展示了ApacheRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: serverIsDown
import com.jcabi.http.request.ApacheRequest; //导入依赖的package包/类
/**
* Follow can stay silent if there's an exception.
* @throws Exception If something goes wrong.
*/
@Test
public void serverIsDown() throws Exception {
final Command com = this.mockMention();
Mockito.when(com.issue().repo().github().entry())
.thenReturn(
new ApacheRequest("http://localhost:" + this.port() + "/")
);
final Log log = Mockito.mock(Log.class);
final Logger slf4j = Mockito.mock(Logger.class);
Mockito.when(log.logger()).thenReturn(slf4j);
new FollowUser(new Step.Fake(true)).perform(com, log);
Mockito.verify(slf4j).info(
"Following Github user " + com.author() + " ..."
);
Mockito.verify(slf4j).warn(
"IOException while trying to follow the user."
);
}
示例2: hasGhPagesBranch
import com.jcabi.http.request.ApacheRequest; //导入依赖的package包/类
/**
* Returns true if the repository has a gh-pages branch, false otherwise.
* The result is <b>cached</b> and so the http call to Github API is performed only at the first call.
* @return true if there is a gh-pages branch, false otherwise.
* @throws IOException If an error occurs
* while communicating with the Github API.
*/
public boolean hasGhPagesBranch() throws IOException {
try {
if(this.ghPagesBranch == null) {
String branchesUrlPattern = this.json().getString("branches_url");
String ghPagesUrl = branchesUrlPattern.substring(0, branchesUrlPattern.indexOf("{")) + "/gh-pages";
Request req = new ApacheRequest(ghPagesUrl);
this.ghPagesBranch = req.fetch().as(RestResponse.class)
.assertStatus(
Matchers.isOneOf(
HttpURLConnection.HTTP_OK,
HttpURLConnection.HTTP_NOT_FOUND
)
).status() == HttpURLConnection.HTTP_OK;
return this.ghPagesBranch;
}
return this.ghPagesBranch;
} catch (AssertionError aerr) {
throw new IOException ("Unexpected HTTP status response.", aerr);
}
}
示例3: retrievesKeys
import com.jcabi.http.request.ApacheRequest; //导入依赖的package包/类
/**
* RtPublicKeys should be able to iterate its keys.
*
* @throws Exception if a problem occurs.
*/
@Test
public void retrievesKeys() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(
new MkAnswer.Simple(
HttpURLConnection.HTTP_OK,
Json.createArrayBuilder()
.add(key(1))
.add(key(2))
.build().toString()
)
).start();
final RtPublicKeys keys = new RtPublicKeys(
new ApacheRequest(container.home()),
Mockito.mock(User.class)
);
MatcherAssert.assertThat(
keys.iterate(),
Matchers.<PublicKey>iterableWithSize(2)
);
container.stop();
}
示例4: canFetchSingleKey
import com.jcabi.http.request.ApacheRequest; //导入依赖的package包/类
/**
* RtPublicKeys should be able to obtain a single key.
*
* @throws Exception if a problem occurs.
*/
@Test
public void canFetchSingleKey() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(
new MkAnswer.Simple(
HttpURLConnection.HTTP_OK,
""
)
).start();
final RtPublicKeys keys = new RtPublicKeys(
new ApacheRequest(container.home()),
Mockito.mock(User.class)
);
try {
MatcherAssert.assertThat(
keys.get(1),
Matchers.notNullValue()
);
} finally {
container.stop();
}
}
示例5: throwsIfNoMoreElement
import com.jcabi.http.request.ApacheRequest; //导入依赖的package包/类
/**
* RtPagination can throw if there is no more elements in pagination.
*
* @throws Exception if there is any problem
*/
@Test(expected = NoSuchElementException.class)
public void throwsIfNoMoreElement() throws Exception {
final MkContainer container = new MkGrizzlyContainer()
.next(simple("Hi there")).start();
try {
final Request request = new ApacheRequest(container.home());
final RtPagination<JsonObject> page = new RtPagination<JsonObject>(
request,
new RtValuePagination.Mapping<JsonObject, JsonObject>() {
@Override
public JsonObject map(final JsonObject object) {
return object;
}
}
);
final Iterator<JsonObject> iterator = page.iterator();
iterator.next();
MatcherAssert.assertThat(
iterator.next(),
Matchers.notNullValue()
);
} finally {
container.stop();
}
}
示例6: checkIfRepoStarred
import com.jcabi.http.request.ApacheRequest; //导入依赖的package包/类
/**
* RtStars can check if repo is starred.
*
* @throws Exception If something goes wrong.
*/
@Test
public void checkIfRepoStarred() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(
new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT)
).next(new MkAnswer.Simple(HttpURLConnection.HTTP_NOT_FOUND))
.start();
try {
final Stars starred = new RtStars(
new ApacheRequest(container.home()),
RtStarsTest.repo("someuser", "starredrepo")
);
MatcherAssert.assertThat(
starred.starred(), Matchers.is(true)
);
final Stars unstarred = new RtStars(
new ApacheRequest(container.home()),
RtStarsTest.repo("otheruser", "notstarredrepo")
);
MatcherAssert.assertThat(
unstarred.starred(), Matchers.is(false)
);
} finally {
container.stop();
}
}
示例7: givesToString
import com.jcabi.http.request.ApacheRequest; //导入依赖的package包/类
/**
* This tests that the toString() method is working fine.
* @throws Exception - if anything goes wrong.
*/
@Test
public void givesToString() 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("testing6", "issue6");
final RtComment comment = new RtComment(
new ApacheRequest(container.home()), issue, 10
);
try {
final String stringComment = comment.toString();
MatcherAssert.assertThat(
stringComment, Matchers.not(Matchers.isEmptyOrNullString())
);
MatcherAssert.assertThat(stringComment, Matchers.endsWith("10"));
} finally {
container.stop();
}
}
示例8: iteratePulls
import com.jcabi.http.request.ApacheRequest; //导入依赖的package包/类
/**
* RtPulls can iterate pulls.
* @throws Exception if there is any error
*/
@Test
public void iteratePulls() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(
new MkAnswer.Simple(
HttpURLConnection.HTTP_OK,
Json.createArrayBuilder()
.add(pull("new-topic"))
.add(pull("Amazing new feature"))
.build().toString()
)
).start();
final RtPulls pulls = new RtPulls(
new ApacheRequest(container.home()),
repo()
);
MatcherAssert.assertThat(
pulls.iterate(new ArrayMap<String, String>()),
Matchers.<Pull>iterableWithSize(2)
);
container.stop();
}
示例9: canFetchNonEmptyListOfDeployKeys
import com.jcabi.http.request.ApacheRequest; //导入依赖的package包/类
/**
* RtDeployKeys can fetch non empty list of deploy keys.
*
* @throws IOException If some problem inside.
*/
@Test
public void canFetchNonEmptyListOfDeployKeys() throws IOException {
final MkContainer container = new MkGrizzlyContainer().next(
new MkAnswer.Simple(
HttpURLConnection.HTTP_OK,
Json.createArrayBuilder()
.add(key(1))
.add(key(2))
.build().toString()
)
);
container.start();
try {
MatcherAssert.assertThat(
new RtDeployKeys(
new ApacheRequest(container.home()),
RtDeployKeysTest.repo()
).iterate(),
Matchers.<DeployKey>iterableWithSize(2)
);
} finally {
container.stop();
}
}
示例10: canCreateDeployKey
import com.jcabi.http.request.ApacheRequest; //导入依赖的package包/类
/**
* RtDeployKeys can create a key.
* @throws IOException If some problem inside.
*/
@Test
public void canCreateDeployKey() throws IOException {
final int number = 2;
final MkContainer container = new MkGrizzlyContainer().next(
new MkAnswer.Simple(
HttpURLConnection.HTTP_CREATED,
String.format("{\"id\":%d}", number)
)
);
container.start();
try {
final DeployKeys keys = new RtDeployKeys(
new ApacheRequest(container.home()), RtDeployKeysTest.repo()
);
MatcherAssert.assertThat(
keys.create("Title", "Key").number(),
Matchers.equalTo(number)
);
} finally {
container.stop();
}
}
示例11: executePatchRequest
import com.jcabi.http.request.ApacheRequest; //导入依赖的package包/类
/**
* RtUser can execute PATCH request.
*
* @throws Exception if there is any problem
*/
@Test
public void executePatchRequest() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(
new MkAnswer.Simple(
HttpURLConnection.HTTP_OK,
"{\"login\":\"octocate\"}"
)
).start();
final RtUser json = new RtUser(
Mockito.mock(Github.class),
new ApacheRequest(container.home())
);
json.patch(
Json.createObjectBuilder()
.add("location", "San Francisco")
.build()
);
MatcherAssert.assertThat(
container.take().method(),
Matchers.equalTo(Request.PATCH)
);
container.stop();
}
示例12: canDeleteDeployKey
import com.jcabi.http.request.ApacheRequest; //导入依赖的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();
}
示例13: removesAsset
import com.jcabi.http.request.ApacheRequest; //导入依赖的package包/类
/**
* RtReleaseAsset can remove itself.
* @throws Exception If a problem occurs.
*/
@Test
public void removesAsset() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(
new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, "")
).start();
final RtReleaseAsset asset = new RtReleaseAsset(
new ApacheRequest(container.home()),
release(),
3
);
try {
asset.remove();
final MkQuery query = container.take();
MatcherAssert.assertThat(
query.method(),
Matchers.equalTo(Request.DELETE)
);
} finally {
container.stop();
}
}
示例14: rawAsset
import com.jcabi.http.request.ApacheRequest; //导入依赖的package包/类
/**
* RtReleaseAsset can stream raw content.
* @throws Exception If a problem occurs.
*/
@Test
public void rawAsset() throws Exception {
final MkContainer container = new MkGrizzlyContainer().next(
new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "")
).start();
final RtReleaseAsset asset = new RtReleaseAsset(
new ApacheRequest(container.home()),
release(),
4
);
try {
final InputStream stream = asset.raw();
final MkQuery query = container.take();
MatcherAssert.assertThat(
query.method(), Matchers.equalTo(Request.GET)
);
MatcherAssert.assertThat(
IOUtils.toString(stream),
Matchers.notNullValue()
);
} finally {
container.stop();
}
}
示例15: addsEmails
import com.jcabi.http.request.ApacheRequest; //导入依赖的package包/类
/**
* RtUserEmails can add emails.
* @throws Exception If some problem inside
*/
@Test
public void addsEmails() throws Exception {
final String email = "[email protected]";
final MkContainer container = new MkGrizzlyContainer().next(
new MkAnswer.Simple(
HttpURLConnection.HTTP_CREATED,
String.format("[{\"email\":\"%s\"}]", email)
)
);
container.start();
try {
final UserEmails emails = new RtUserEmails(
new ApacheRequest(container.home())
);
MatcherAssert.assertThat(
emails.add(Collections.singletonList(email)).iterator().next(),
Matchers.equalTo(email)
);
} finally {
container.stop();
}
}