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


Java Method类代码示例

本文整理汇总了Java中com.github.kristofa.test.http.Method的典型用法代码示例。如果您正苦于以下问题:Java Method类的具体用法?Java Method怎么用?Java Method使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Method类属于com.github.kristofa.test.http包,在下文中一共展示了Method类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testShouldHandleGetRequests

import com.github.kristofa.test.http.Method; //导入依赖的package包/类
@Test
public void testShouldHandleGetRequests() throws IOException {
    // Given a mock server configured to respond to a GET / with "OK"
    responseProvider.expect(Method.GET, "/").respondWith(200, "text/plain", "OK");

    // When a request for GET / arrives
    final HttpGet req = new HttpGet(baseUrl + "/");
    final HttpResponse response = client.execute(req);
    final String responseBody = IOUtils.toString(response.getEntity().getContent());
    final int statusCode = response.getStatusLine().getStatusCode();

    // Then the response is "OK"
    Assert.assertEquals("OK", responseBody);

    // And the status code is 200
    Assert.assertEquals(200, statusCode);
}
 
开发者ID:soujava,项目名称:soujava-test-kit,代码行数:18,代码来源:MockHttpServerTest.java

示例2: testShouldHandlePostRequests

import com.github.kristofa.test.http.Method; //导入依赖的package包/类
@Test
public void testShouldHandlePostRequests() throws IOException {
    // Given a mock server configured to respond to a POST / with data
    // "Hello World" with an ID
    responseProvider.expect(Method.POST, "/", "text/plain; charset=UTF-8", "Hello World").respondWith(200, "text/plain",
            "ABCD1234");

    // When a request for POST / arrives
    final HttpPost req = new HttpPost(baseUrl + "/");
    req.setEntity(new StringEntity("Hello World", UTF_8));
    final ResponseHandler<String> handler = new BasicResponseHandler();
    final String responseBody = client.execute(req, handler);

    // Then the response is "ABCD1234"
    Assert.assertEquals("ABCD1234", responseBody);
}
 
开发者ID:soujava,项目名称:soujava-test-kit,代码行数:17,代码来源:MockHttpServerTest.java

示例3: testShouldHandlePutRequests

import com.github.kristofa.test.http.Method; //导入依赖的package包/类
@Test
public void testShouldHandlePutRequests() throws  IOException {
    // Given a mock server configured to respond to a DELETE /test
    responseProvider.expect(Method.PUT, "/test", "text/plain; charset=UTF-8", "Hello World").respondWith(200,
            "text/plain", "Welcome");

    // When a request for DELETE /test arrives
    final HttpPut req = new HttpPut(baseUrl + "/test");
    req.setEntity(new StringEntity("Hello World", UTF_8));
    final HttpResponse response = client.execute(req);

    final String responseBody = IOUtils.toString(response.getEntity().getContent());
    final int statusCode = response.getStatusLine().getStatusCode();

    // Then the response status is 204
    Assert.assertEquals(200, statusCode);
    Assert.assertEquals("Welcome", responseBody);
}
 
开发者ID:soujava,项目名称:soujava-test-kit,代码行数:19,代码来源:MockHttpServerTest.java

示例4: testShouldRespondWithCustomResponseCodeWhenNotMatchingAnyRequestExpectation

import com.github.kristofa.test.http.Method; //导入依赖的package包/类
@Test
public void testShouldRespondWithCustomResponseCodeWhenNotMatchingAnyRequestExpectation()
        throws IOException {
    server.setNoMatchFoundResponseCode(403);
    try {
        responseProvider.expect(Method.GET, "/foo").respondWith(200, "text/plain", "OK");

        final HttpGet req = new HttpGet(baseUrl + "/bar");
        final HttpResponse response = client.execute(req);

        Assert.assertEquals(403, response.getStatusLine().getStatusCode());
    } finally {
        // Set to default value again to make sure potential other tests succeed.
        server.setNoMatchFoundResponseCode(598);
    }
}
 
开发者ID:soujava,项目名称:soujava-test-kit,代码行数:17,代码来源:MockHttpServerTest.java

示例5: testOpenJiraReaderForQueryWithoutExpectedField

import com.github.kristofa.test.http.Method; //导入依赖的package包/类
@Test
public void testOpenJiraReaderForQueryWithoutExpectedField()
        throws Exception {
    String mockOutput = "{\"expand\":\"schema,names\",\"startAt\":0,\"maxResults\":50,\"total\":8,"
            + "\"issues\":["
            + "{\"expand\":\"operations,editmeta,changelog,transitions,renderedFields\","
                + "\"id\":\"384458\","
                + "\"self\":\"https://jira.atlassian.com/rest/api/2/issue/384458\","
                + "\"key\":\"WBS-193\","
                + "\"fields\":{"
                + "\"description\":\"gg\"}},"
            + "{\"expand\":\"operations,editmeta,changelog,transitions,renderedFields\",\"id\":\"382505\",\"self\":\"https://jira.atlassian.com/rest/api/2/issue/382505\",\"key\":\"WBS-192\",\"fields\":{\"description\":\"ddddd\"}},"
            + "{\"expand\":\"operations,editmeta,changelog,transitions,renderedFields\",\"id\":\"350850\",\"self\":\"https://jira.atlassian.com/rest/api/2/issue/350850\",\"key\":\"WBS-181\",\"fields\":{\"description\":null}},"
            + "{\"expand\":\"operations,editmeta,changelog,transitions,renderedFields\",\"id\":\"350849\",\"self\":\"https://jira.atlassian.com/rest/api/2/issue/350849\",\"key\":\"WBS-180\",\"fields\":{\"description\":null}},"
            + "{\"expand\":\"operations,editmeta,changelog,transitions,renderedFields\",\"id\":\"350848\",\"self\":\"https://jira.atlassian.com/rest/api/2/issue/350848\",\"key\":\"WBS-179\",\"fields\":{\"description\":null}},"
            + "{\"expand\":\"operations,editmeta,changelog,transitions,renderedFields\",\"id\":\"350847\",\"self\":\"https://jira.atlassian.com/rest/api/2/issue/350847\",\"key\":\"WBS-178\",\"fields\":{\"description\":null}},"
            + "{\"expand\":\"operations,editmeta,changelog,transitions,renderedFields\",\"id\":\"350846\",\"self\":\"https://jira.atlassian.com/rest/api/2/issue/350846\",\"key\":\"WBS-177\",\"fields\":{\"description\":null}},"
            + "{\"expand\":\"operations,editmeta,changelog,transitions,renderedFields\",\"id\":\"346867\",\"self\":\"https://jira.atlassian.com/rest/api/2/issue/346867\",\"key\":\"WBS-176\",\"fields\":{\"description\":\"I wondered when the Wallboard Plugin will be compatible in the latest version of Jira 6.3.1.For now we upgraded Jira in the latest version,and found this plugin is incompatible.\"}}]}";
    responseProvider
            .expect(Method.GET,
                    "/rest/api/2/search?jql=project%3DWallboards+AND+status%3DOpen&fields=key,some_field")
            .respondWith(HttpStatus.SC_OK, "application/json", mockOutput);
    initReader("some_field");
    Assert.assertFalse(reader.hasNext());
    Assert.assertNull(reader.readNext());
}
 
开发者ID:mkolisnyk,项目名称:aerial,代码行数:27,代码来源:AerialJiraReaderTest.java

示例6: testShouldHandleDeleteRequests

import com.github.kristofa.test.http.Method; //导入依赖的package包/类
@Test
public void testShouldHandleDeleteRequests() throws IOException {
    // Given a mock server configured to respond to a DELETE /test
    responseProvider.expect(Method.DELETE, "/test").respondWith(204, "text/plain", "");

    // When a request for DELETE /test arrives
    final HttpDelete req = new HttpDelete(baseUrl + "/test");
    final HttpResponse response = client.execute(req);

    // Then the response status is 204
    Assert.assertEquals(204, response.getStatusLine().getStatusCode());
}
 
开发者ID:soujava,项目名称:soujava-test-kit,代码行数:13,代码来源:MockHttpServerTest.java

示例7: testShouldNotMatchDataWhenExceptedDataIsNull

import com.github.kristofa.test.http.Method; //导入依赖的package包/类
@Test
public void testShouldNotMatchDataWhenExceptedDataIsNull() throws ClientProtocolException, IOException {
    // Given a mock server configured to respond to a POST /test with no data
    responseProvider.expect(Method.POST, "/test").respondWith(204, "text/plain", "");

    // When a request for POST /test arrives with parameters
    final HttpPost req = new HttpPost(baseUrl + "/test");
    req.setEntity(new StringEntity("Hello World", UTF_8));

    final HttpResponse response = client.execute(req);

    // Then the response status is 598
    Assert.assertEquals(598, response.getStatusLine().getStatusCode());
}
 
开发者ID:soujava,项目名称:soujava-test-kit,代码行数:15,代码来源:MockHttpServerTest.java

示例8: testShouldFailWhenGetExpectationNotInvoqued

import com.github.kristofa.test.http.Method; //导入依赖的package包/类
@Test(expectedExceptions = UnsatisfiedExpectationException.class)
public void testShouldFailWhenGetExpectationNotInvoqued() throws IOException,
        UnsatisfiedExpectationException {
    // Given a mock server configured to respond to a GET / with "OK"
    responseProvider.expect(Method.GET, "/").respondWith(200, "text/plain", "OK");

    server.verify();
}
 
开发者ID:soujava,项目名称:soujava-test-kit,代码行数:9,代码来源:MockHttpServerTest.java

示例9: testShouldNotFailWhenGetExpectationIsInvoqued

import com.github.kristofa.test.http.Method; //导入依赖的package包/类
@Test
public void testShouldNotFailWhenGetExpectationIsInvoqued() throws IOException,
        UnsatisfiedExpectationException {
    // Given a mock server configured to respond to a GET / with "OK"
    responseProvider.expect(Method.GET, "/").respondWith(200, "text/plain", "OK");

    final HttpGet req = new HttpGet(baseUrl + "/");
    client.execute(req);

    server.verify();
}
 
开发者ID:soujava,项目名称:soujava-test-kit,代码行数:12,代码来源:MockHttpServerTest.java

示例10: testShouldFailWhenPostExpectationNotInvoqued

import com.github.kristofa.test.http.Method; //导入依赖的package包/类
@Test(expectedExceptions = UnsatisfiedExpectationException.class)
public void testShouldFailWhenPostExpectationNotInvoqued() throws IOException,
        UnsatisfiedExpectationException {
    // Given a mock server configured to respond to a GET / with "OK"
    responseProvider.expect(Method.POST, "/").respondWith(200, "text/plain", "OK");

    server.verify();
}
 
开发者ID:soujava,项目名称:soujava-test-kit,代码行数:9,代码来源:MockHttpServerTest.java

示例11: testShouldNotFailWhenPostExpectationIsInvoqued

import com.github.kristofa.test.http.Method; //导入依赖的package包/类
@Test
public void testShouldNotFailWhenPostExpectationIsInvoqued() throws IOException,
        UnsatisfiedExpectationException {
    // Given a mock server configured to respond to a GET / with "OK"
    responseProvider.expect(Method.POST, "/").respondWith(200, "text/plain", "OK");

    final HttpPost req = new HttpPost(baseUrl + "/");
    client.execute(req);

    server.verify();
}
 
开发者ID:soujava,项目名称:soujava-test-kit,代码行数:12,代码来源:MockHttpServerTest.java

示例12: testShouldFailWhenOneOfSeveralGetExpectationsIsNotInvoqued

import com.github.kristofa.test.http.Method; //导入依赖的package包/类
@Test(expectedExceptions = UnsatisfiedExpectationException.class)
public void testShouldFailWhenOneOfSeveralGetExpectationsIsNotInvoqued() throws IOException,
        UnsatisfiedExpectationException {
    // Given a mock server configured to respond to a GET / with "OK"
    responseProvider.expect(Method.GET, "/").respondWith(200, "text/plain", "OK");
    responseProvider.expect(Method.GET, "/other").respondWith(200, "text/plain", "OK");

    final HttpGet req = new HttpGet(baseUrl + "/");
    client.execute(req);

    server.verify();
}
 
开发者ID:soujava,项目名称:soujava-test-kit,代码行数:13,代码来源:MockHttpServerTest.java

示例13: testShouldRespondWith598WhenNotMatchingAnyRequestExpectation

import com.github.kristofa.test.http.Method; //导入依赖的package包/类
@Test
public void testShouldRespondWith598WhenNotMatchingAnyRequestExpectation() throws IOException {
    responseProvider.expect(Method.GET, "/foo").respondWith(200, "text/plain", "OK");

    final HttpGet req = new HttpGet(baseUrl + "/bar");
    final HttpResponse response = client.execute(req);

    Assert.assertEquals(598, response.getStatusLine().getStatusCode());
}
 
开发者ID:soujava,项目名称:soujava-test-kit,代码行数:10,代码来源:MockHttpServerTest.java

示例14: testResponseWithNullContentTypeAndContent

import com.github.kristofa.test.http.Method; //导入依赖的package包/类
@Test
public void testResponseWithNullContentTypeAndContent() throws IOException {
    responseProvider.expect(Method.GET, "/foo").respondWith(200, null, null);
    final HttpGet req = new HttpGet(baseUrl + "/foo");
    final HttpResponse response = client.execute(req);

    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    Assert.assertEquals("", IOUtils.toString(response.getEntity().getContent()));

}
 
开发者ID:soujava,项目名称:soujava-test-kit,代码行数:11,代码来源:MockHttpServerTest.java

示例15: testQueryParameters

import com.github.kristofa.test.http.Method; //导入依赖的package包/类
@Test
public void testQueryParameters() throws IOException {
    responseProvider.expect(Method.GET, "/query?a=b&b=c").respondWith(200, null, null);
    final HttpGet req = new HttpGet(baseUrl + "/query?a=b&b=c");
    final HttpResponse response = client.execute(req);

    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    Assert.assertEquals("", IOUtils.toString(response.getEntity().getContent()));
}
 
开发者ID:soujava,项目名称:soujava-test-kit,代码行数:10,代码来源:MockHttpServerTest.java


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