当前位置: 首页>>代码示例>>Java>>正文


Java ApacheRequest类代码示例

本文整理汇总了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."
    );
}
 
开发者ID:amihaiemil,项目名称:comdor,代码行数:25,代码来源:FollowUserTestCase.java

示例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);
    }
}
 
开发者ID:opencharles,项目名称:charles-rest,代码行数:28,代码来源:CachedRepo.java

示例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();
}
 
开发者ID:cvrebert,项目名称:typed-github,代码行数:27,代码来源:RtPublicKeysTest.java

示例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();
    }
}
 
开发者ID:cvrebert,项目名称:typed-github,代码行数:27,代码来源:RtPublicKeysTest.java

示例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();
    }
}
 
开发者ID:cvrebert,项目名称:typed-github,代码行数:31,代码来源:RtPaginationTest.java

示例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();
    }
}
 
开发者ID:cvrebert,项目名称:typed-github,代码行数:31,代码来源:RtStarsTest.java

示例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();
    }
}
 
开发者ID:cvrebert,项目名称:typed-github,代码行数:25,代码来源:RtCommentTest.java

示例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();
}
 
开发者ID:cvrebert,项目名称:typed-github,代码行数:26,代码来源:RtPullsTest.java

示例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();
    }
}
 
开发者ID:cvrebert,项目名称:typed-github,代码行数:30,代码来源:RtDeployKeysTest.java

示例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();
    }
}
 
开发者ID:cvrebert,项目名称:typed-github,代码行数:27,代码来源:RtDeployKeysTest.java

示例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();
}
 
开发者ID:cvrebert,项目名称:typed-github,代码行数:29,代码来源:RtUserTest.java

示例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();
}
 
开发者ID:cvrebert,项目名称:typed-github,代码行数:27,代码来源:RtDeployKeyTest.java

示例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();
    }
}
 
开发者ID:cvrebert,项目名称:typed-github,代码行数:26,代码来源:RtReleaseAssetTest.java

示例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();
    }
}
 
开发者ID:cvrebert,项目名称:typed-github,代码行数:29,代码来源:RtReleaseAssetTest.java

示例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();
    }
}
 
开发者ID:cvrebert,项目名称:typed-github,代码行数:27,代码来源:RtUserEmailsTest.java


注:本文中的com.jcabi.http.request.ApacheRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。