本文整理汇总了Java中org.jboss.resteasy.mock.MockHttpRequest类的典型用法代码示例。如果您正苦于以下问题:Java MockHttpRequest类的具体用法?Java MockHttpRequest怎么用?Java MockHttpRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MockHttpRequest类属于org.jboss.resteasy.mock包,在下文中一共展示了MockHttpRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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"));
}
示例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"));
}
示例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"));
}
示例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"));
}
示例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;
}
示例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);
}
示例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));
}
示例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));
}
示例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));
}
示例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));
}
示例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"));
}
示例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());
}
示例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);
}
示例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());
}
}
}
示例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));
}