本文整理汇总了Java中org.jboss.resteasy.mock.MockHttpRequest类的典型用法代码示例。如果您正苦于以下问题:Java MockHttpRequest类的具体用法?Java MockHttpRequest怎么用?Java MockHttpRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MockHttpRequest类属于org.jboss.resteasy.mock包,在下文中一共展示了MockHttpRequest类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testGetPatientHapi
import org.jboss.resteasy.mock.MockHttpRequest; //导入依赖的package包/类
@Test
public void testGetPatientHapi() {
MockHttpRequest request = null;
try {
request = MockHttpRequest.get("/fhir/patient/fhirTest?group_id=4");
//http://fhirtest.uhn.ca/baseDstu2/Patient?_id=fhirTest
} catch (URISyntaxException e) {
fail(e.getMessage());
}
MockHttpResponse response = new MockHttpResponse();
dispatcher.invoke(request, response);
assertEquals(HttpServletResponse.SC_OK, response.getStatus());
assertTrue(response.getContentAsString().contains("fhirTest"));
}
开发者ID:Discovery-Research-Network-SCCM,项目名称:FHIR-CQL-ODM-service,代码行数:17,代码来源:FhirServiceIT.java
示例2: testGetPatientOpenEpic
import org.jboss.resteasy.mock.MockHttpRequest; //导入依赖的package包/类
@Test
public void testGetPatientOpenEpic() {
MockHttpRequest request = null;
try {
request = MockHttpRequest.get("/fhir/patient/Tbt3KuCY0B5PSrJvCu2j-PlK.aiHsu2xUjUM8bWpetXoB?group_id=2");
//https://open-ic.epic.com/FHIR/api/FHIR/DSTU2/Patient?_id=Tbt3KuCY0B5PSrJvCu2j-PlK.aiHsu2xUjUM8bWpetXoB
} catch (URISyntaxException e) {
fail(e.getMessage());
}
MockHttpResponse response = new MockHttpResponse();
dispatcher.invoke(request, response);
assertEquals(HttpServletResponse.SC_OK, response.getStatus());
assertTrue(response.getContentAsString().contains("Argonaut, Jason"));
}
开发者ID:Discovery-Research-Network-SCCM,项目名称:FHIR-CQL-ODM-service,代码行数:17,代码来源:FhirServiceIT.java
示例3: testGetOdmHapi
import org.jboss.resteasy.mock.MockHttpRequest; //导入依赖的package包/类
@Test
public void testGetOdmHapi() {
MockHttpRequest request = null;
try {
request = MockHttpRequest.get(
"/fhir/patient/fhirTest/odm?project_id=29&instrument=usciit_prep_flu_study&group_id=4&encounter_start=2016-05-29T09:00:00&encounter_end=2016-06-20");
} catch (URISyntaxException e) {
fail(e.getMessage());
}
MockHttpResponse response = new MockHttpResponse();
dispatcher.invoke(request, response);
assertEquals(HttpServletResponse.SC_OK, response.getStatus());
assertTrue(response.getContentAsString().contains("fhirTest"));
}
开发者ID:Discovery-Research-Network-SCCM,项目名称:FHIR-CQL-ODM-service,代码行数:17,代码来源:FhirServiceIT.java
示例4: testGetOdmOpenEpic
import org.jboss.resteasy.mock.MockHttpRequest; //导入依赖的package包/类
@Test
public void testGetOdmOpenEpic() {
MockHttpRequest request = null;
try {
request = MockHttpRequest.get(
"/fhir/patient/Tbt3KuCY0B5PSrJvCu2j-PlK.aiHsu2xUjUM8bWpetXoB/odm?project_id=29&instrument=usciit_prep_flu_study&group_id=2&encounter_start=2016-04-18&encounter_end=2016-04-20");
} catch (URISyntaxException e) {
fail(e.getMessage());
}
MockHttpResponse response = new MockHttpResponse();
dispatcher.invoke(request, response);
assertEquals(HttpServletResponse.SC_OK, response.getStatus());
assertTrue(response.getContentAsString().contains("Tbt3KuCY0B5PSrJvCu2j-PlK.aiHsu2xUjUM8bWpetXoB"));
}
开发者ID:Discovery-Research-Network-SCCM,项目名称:FHIR-CQL-ODM-service,代码行数:17,代码来源:FhirServiceIT.java
示例5: createRequest
import org.jboss.resteasy.mock.MockHttpRequest; //导入依赖的package包/类
private MockHttpRequest createRequest(ClientInvocation request) {
MockHttpRequest mockRequest =
MockHttpRequest.create(request.getMethod(), request.getUri(), baseUri);
if (request.getEntity() != null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
request.getDelegatingOutputStream().setDelegate(baos);
try {
request.writeRequestBody(request.getEntityStream());
baos.close();
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
mockRequest.setInputStream(new ByteArrayInputStream(baos.toByteArray()));
}
MultivaluedMap<String, String> requestHeaders = request.getHeaders().asMap();
mockRequest.getMutableHeaders().putAll(requestHeaders);
copyCookies(mockRequest, requestHeaders);
return mockRequest;
}
开发者ID:tbroyer,项目名称:jaxrs-utils,代码行数:23,代码来源:InProcessClientHttpEngine.java
示例6: testDeleteNote
import org.jboss.resteasy.mock.MockHttpRequest; //导入依赖的package包/类
@Test(dataProvider = DEFAULT_DP)
public void testDeleteNote(Context context) throws URISyntaxException {
// Given that a note with id=1 exists...
// ... when the user requests the note deleted...
MockHttpRequest request = MockHttpRequest
.post("/notes/delete")
.addFormHeader("id", "1")
.accept(MediaType.TEXT_HTML);
HttpResponse response = context.invoke(request);
// ... Then the note should be deleted, and the client instructed to
// redirect to the notes list page.
assertEquals(response.getStatus(), HttpServletResponse.SC_SEE_OTHER);
URI actualLocation = (URI) response.getOutputHeaders().getFirst("Location");
URI expectedLocation = URI.create("/notes");
assertEquals(actualLocation, expectedLocation);
verify(context.notesService).deleteNote(1L);
}
开发者ID:redsaz,项目名称:deciservice,代码行数:19,代码来源:BrowserNotesResourceTest.java
示例7: testFinishEditOrCreateNote_Edit
import org.jboss.resteasy.mock.MockHttpRequest; //导入依赖的package包/类
@Test(dataProvider = DEFAULT_DP)
public void testFinishEditOrCreateNote_Edit(Context context) throws URISyntaxException {
// Given that a note with id=1 exists...
// ... when the user requests the note edited...
MockHttpRequest request = MockHttpRequest
.post("/notes")
.addFormHeader("id", "1")
.addFormHeader("title", "Example Title")
.addFormHeader("body", "Example Body")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.accept(MediaType.TEXT_HTML);
when(context.notesService.updateAll(any(List.class)))
.thenReturn(Collections.singletonList(
new Note(1, "example-title", "Example Title", "Example Body")));
HttpResponse response = context.invoke(request);
// ... Then the note should be edited, and the client instructed to
// redirect to the notes list page.
assertEquals(response.getStatus(), HttpServletResponse.SC_SEE_OTHER);
URI actualLocation = (URI) response.getOutputHeaders().getFirst("Location");
URI expectedLocation = URI.create("/notes");
assertEquals(actualLocation, expectedLocation);
verify(context.notesService).updateAll(any(List.class));
}
开发者ID:redsaz,项目名称:deciservice,代码行数:25,代码来源:BrowserNotesResourceTest.java
示例8: testFinishEditOrCreateNote_EditNotFound
import org.jboss.resteasy.mock.MockHttpRequest; //导入依赖的package包/类
@Test(dataProvider = DEFAULT_DP)
public void testFinishEditOrCreateNote_EditNotFound(Context context) throws URISyntaxException {
// Given that a note with id=2 does not exist...
// ... when the user requests the note edited...
MockHttpRequest request = MockHttpRequest
.post("/notes")
.addFormHeader("id", "2")
.addFormHeader("title", "Example Title")
.addFormHeader("body", "Example Body")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.accept(MediaType.TEXT_HTML);
when(context.notesService.updateAll(any(List.class)))
.thenThrow(new NotFoundException("Failed to update one or more notes."));
HttpResponse response = context.invoke(request);
// ... Then not found status code should be returned.
assertEquals(response.getStatus(), HttpServletResponse.SC_NOT_FOUND);
verify(context.notesService).updateAll(any(List.class));
}
开发者ID:redsaz,项目名称:deciservice,代码行数:20,代码来源:BrowserNotesResourceTest.java
示例9: testFinishEditOrCreateNote_Create
import org.jboss.resteasy.mock.MockHttpRequest; //导入依赖的package包/类
@Test(dataProvider = DEFAULT_DP)
public void testFinishEditOrCreateNote_Create(Context context) throws URISyntaxException {
// Given that the user is on the create note page...
// ... when the user clicks the button to create the note...
MockHttpRequest request = MockHttpRequest
.post("/notes")
.addFormHeader("id", "0")
.addFormHeader("title", "Example Title")
.addFormHeader("body", "Example Body")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.accept(MediaType.TEXT_HTML);
when(context.notesService.createAll(any(List.class)))
.thenReturn(Collections.singletonList(
new Note(2, "example-title", "Example Title", "Example Body")));
HttpResponse response = context.invoke(request);
// ... Then the note should be edited, and the client instructed to
// redirect to the notes list page.
assertEquals(response.getStatus(), HttpServletResponse.SC_SEE_OTHER);
URI actualLocation = (URI) response.getOutputHeaders().getFirst("Location");
URI expectedLocation = URI.create("/notes");
assertEquals(actualLocation, expectedLocation);
verify(context.notesService).createAll(any(List.class));
}
开发者ID:redsaz,项目名称:deciservice,代码行数:25,代码来源:BrowserNotesResourceTest.java
示例10: testFinishEditOrCreateNote_Create_NoContentError
import org.jboss.resteasy.mock.MockHttpRequest; //导入依赖的package包/类
@Test(dataProvider = DEFAULT_DP)
public void testFinishEditOrCreateNote_Create_NoContentError(Context context) throws URISyntaxException {
// Given that the user is on the create note page...
// ... when the user does not fill out any content and
// clicks the button to create the note...
MockHttpRequest request = MockHttpRequest
.post("/notes")
.addFormHeader("id", "0")
.addFormHeader("title", "")
.addFormHeader("body", "")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.accept(MediaType.TEXT_HTML);
when(context.notesService.createAll(any(List.class)))
.thenThrow(new AppClientException("Note must have at least a uri, title, or body."));
HttpResponse response = context.invoke(request);
// ... Then the note should not be created and the client receives an
// error page.
assertEquals(response.getStatus(), HttpServletResponse.SC_BAD_REQUEST);
verify(context.notesService).createAll(any(List.class));
}
开发者ID:redsaz,项目名称:deciservice,代码行数:22,代码来源:BrowserNotesResourceTest.java
示例11: testSendingHttpRequest
import org.jboss.resteasy.mock.MockHttpRequest; //导入依赖的package包/类
@Test
public void testSendingHttpRequest() throws Exception {
MockHttpRequest request = MockHttpRequest.post("/rest").contentType(MediaType.APPLICATION_XML_TYPE);
MockHttpResponse response = new MockHttpResponse();
Person person = new Person();
person.setAge(25);
StringWriter writer = new StringWriter();
context.createMarshaller().marshal(person, writer);
request.content(writer.toString().getBytes());
dispatcher.invoke(request, response);
assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode()));
assertThat(response.getContentAsString(), is("true"));
}
开发者ID:gtudan,项目名称:camel-cdi-drools-test,代码行数:19,代码来源:RestEndpointTest.java
示例12: get
import org.jboss.resteasy.mock.MockHttpRequest; //导入依赖的package包/类
private ContentTypeHelper get(String uri, String acceptHeader) throws Exception {
MockHttpRequest req = MockHttpRequest.get(uri);
MockHttpResponse res = new MockHttpResponse();
RequestImpl restReq = new RequestImpl(req, res);
if (acceptHeader != null) {
req = req.header(HttpHeaders.ACCEPT, acceptHeader);
}
return new ContentTypeHelper(req, restReq, req.getUri());
}
开发者ID:Doccrazy,项目名称:keycloak-protocol-cas,代码行数:12,代码来源:ContentTypeHelperTest.java
示例13: invoke
import org.jboss.resteasy.mock.MockHttpRequest; //导入依赖的package包/类
@Override
public ClientResponse invoke(ClientInvocation request) {
MockHttpRequest mockRequest = createRequest(request);
MockHttpResponse mockResponse = new MockHttpResponse();
dispatcher.invoke(mockRequest, mockResponse);
return createResponse(request, mockResponse);
}
开发者ID:tbroyer,项目名称:jaxrs-utils,代码行数:10,代码来源:InProcessClientHttpEngine.java
示例14: copyCookies
import org.jboss.resteasy.mock.MockHttpRequest; //导入依赖的package包/类
private void copyCookies(
MockHttpRequest mockRequest, MultivaluedMap<String, String> requestHeaders) {
List<String> cookieHeaders = requestHeaders.get(HttpHeaders.COOKIE);
if (cookieHeaders == null) {
return;
}
for (String cookieHeader : cookieHeaders) {
for (Cookie cookie : CookieParser.parseCookies(cookieHeader)) {
mockRequest.cookie(cookie.getName(), cookie.getValue());
}
}
}
开发者ID:tbroyer,项目名称:jaxrs-utils,代码行数:14,代码来源:InProcessClientHttpEngine.java
示例15: testListNotes
import org.jboss.resteasy.mock.MockHttpRequest; //导入依赖的package包/类
@Test(dataProvider = DEFAULT_DP)
public void testListNotes(Context context) throws URISyntaxException {
// Given that the service is running...
// ... When the user views the notes page...
MockHttpRequest request = MockHttpRequest.get("/notes").accept(MediaType.TEXT_HTML);
HttpResponse response = context.invoke(request);
// ... Then the notes list page should be returned.
assertEquals(response.getStatus(), HttpServletResponse.SC_OK);
verify(context.notesService).getNotes();
verify(context.templater).buildFromTemplate(any(), any(String.class));
}
开发者ID:redsaz,项目名称:deciservice,代码行数:14,代码来源:BrowserNotesResourceTest.java
示例16: testEditNote
import org.jboss.resteasy.mock.MockHttpRequest; //导入依赖的package包/类
@Test(dataProvider = DEFAULT_DP)
public void testEditNote(Context context) throws URISyntaxException {
// Given that a note with id=1 exists...
// ... when the user requests the note edit page...
MockHttpRequest request = MockHttpRequest.get("/notes/1/edit").accept(MediaType.TEXT_HTML);
HttpResponse response = context.invoke(request);
// ... Then the page should be retrieved, and the notes contents accessed.
assertEquals(response.getStatus(), HttpServletResponse.SC_OK);
verify(context.notesService).getNote(1L);
verify(context.templater).buildFromTemplate(any(), any(String.class));
}
开发者ID:redsaz,项目名称:deciservice,代码行数:14,代码来源:BrowserNotesResourceTest.java
示例17: testEditNoteNotFound
import org.jboss.resteasy.mock.MockHttpRequest; //导入依赖的package包/类
@Test(dataProvider = DEFAULT_DP)
public void testEditNoteNotFound(Context context) throws URISyntaxException {
// Given there is not a note with id=0...
// ...when the note id=0 edit page is requested...
MockHttpRequest request = MockHttpRequest.get("/notes/0/edit").accept(MediaType.TEXT_HTML);
HttpResponse response = context.invoke(request);
// ...then a 404 should be returned.
assertEquals(response.getStatus(), HttpServletResponse.SC_NOT_FOUND);
verify(context.notesService).getNote(0L);
}
开发者ID:redsaz,项目名称:deciservice,代码行数:13,代码来源:BrowserNotesResourceTest.java
示例18: testGetNote
import org.jboss.resteasy.mock.MockHttpRequest; //导入依赖的package包/类
@Test(dataProvider = DEFAULT_DP)
public void testGetNote(Context context) throws URISyntaxException {
// Given that a note with id=1 exists...
// ... when the user requests the note page...
MockHttpRequest request = MockHttpRequest.get("/notes/1").accept(MediaType.TEXT_HTML);
HttpResponse response = context.invoke(request);
// ... Then the page should be retrieved, and the notes contents accessed.
assertEquals(response.getStatus(), HttpServletResponse.SC_OK);
verify(context.notesService).getNote(1L);
verify(context.templater).buildFromTemplate(any(), any(String.class));
}
开发者ID:redsaz,项目名称:deciservice,代码行数:14,代码来源:BrowserNotesResourceTest.java
示例19: testGetNoteNotFound
import org.jboss.resteasy.mock.MockHttpRequest; //导入依赖的package包/类
@Test(dataProvider = DEFAULT_DP)
public void testGetNoteNotFound(Context context) throws URISyntaxException {
// Given there is not a note with id=0...
// ...when the note id=0 page is requested...
MockHttpRequest request = MockHttpRequest.get("/notes/0").accept(MediaType.TEXT_HTML);
HttpResponse response = context.invoke(request);
// ...then a 404 should be returned.
assertEquals(response.getStatus(), HttpServletResponse.SC_NOT_FOUND);
verify(context.notesService).getNote(0L);
}
开发者ID:redsaz,项目名称:deciservice,代码行数:13,代码来源:BrowserNotesResourceTest.java
示例20: testCreateNote
import org.jboss.resteasy.mock.MockHttpRequest; //导入依赖的package包/类
@Test(dataProvider = DEFAULT_DP)
public void testCreateNote(Context context) throws URISyntaxException {
// Given that the service is running...
// ... when the user requests the create note page...
MockHttpRequest request = MockHttpRequest.get("/notes/create").accept(MediaType.TEXT_HTML);
HttpResponse response = context.invoke(request);
// ... Then the page should be retrieved.
assertEquals(response.getStatus(), HttpServletResponse.SC_OK);
verify(context.templater).buildFromTemplate(any(), any(String.class));
}
开发者ID:redsaz,项目名称:deciservice,代码行数:13,代码来源:BrowserNotesResourceTest.java
注:本文中的org.jboss.resteasy.mock.MockHttpRequest类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论