Java Code Examples for org.glassfish.jersey.media.multipart.FormDataMultiPart#field()
The following examples show how to use
org.glassfish.jersey.media.multipart.FormDataMultiPart#field() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MergeRequestRestTest.java From mobi with GNU Affero General Public License v3.0 | 6 votes |
@Test public void createMergeRequestWithErrorTest() { // Setup: FormDataMultiPart fd = new FormDataMultiPart(); fd.field("title", "Title"); fd.field("recordId", RECORD_ID); fd.field("sourceBranchId", BRANCH_ID); fd.field("targetBranchId", BRANCH_ID); doThrow(new MobiException()).when(requestManager).createMergeRequest(any(MergeRequestConfig.class), any(Resource.class)); Response response = target().path("merge-requests").request().post(Entity.entity(fd, MediaType.MULTIPART_FORM_DATA)); assertEquals(response.getStatus(), 500); verify(engineManager, atLeastOnce()).retrieveUser(UsernameTestFilter.USERNAME); verify(requestManager).createMergeRequest(any(MergeRequestConfig.class), any(Resource.class)); verify(requestManager, times(0)).addMergeRequest(any(MergeRequest.class)); }
Example 2
Source File: MergeRequestRestTest.java From mobi with GNU Affero General Public License v3.0 | 6 votes |
@Test public void createMergeRequestWithMissingRepoTest() { // Setup: FormDataMultiPart fd = new FormDataMultiPart(); fd.field("title", "Title"); fd.field("recordId", RECORD_ID); fd.field("sourceBranchId", BRANCH_ID); fd.field("targetBranchId", BRANCH_ID); doThrow(new IllegalStateException()).when(requestManager).createMergeRequest(any(MergeRequestConfig.class), any(Resource.class)); Response response = target().path("merge-requests").request().post(Entity.entity(fd, MediaType.MULTIPART_FORM_DATA)); assertEquals(response.getStatus(), 500); verify(engineManager, atLeastOnce()).retrieveUser(UsernameTestFilter.USERNAME); verify(requestManager).createMergeRequest(any(MergeRequestConfig.class), any(Resource.class)); verify(requestManager, times(0)).addMergeRequest(any(MergeRequest.class)); }
Example 3
Source File: MappingRestTest.java From mobi with GNU Affero General Public License v3.0 | 6 votes |
@Test public void uploadFileTest() throws Exception { FormDataMultiPart fd = new FormDataMultiPart(); fd.field("title", "Title"); fd.field("description", "Description"); fd.field("markdown", "#Markdown"); fd.field("keywords", "keyword"); InputStream content = getClass().getResourceAsStream("/mapping.jsonld"); fd.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("file").fileName("mapping.jsonld").build(), content, MediaType.APPLICATION_OCTET_STREAM_TYPE)); Response response = target().path("mappings").request().post(Entity.entity(fd, MediaType.MULTIPART_FORM_DATA)); assertEquals(response.getStatus(), 201); assertEquals(MAPPING_RECORD_IRI, response.readEntity(String.class)); ArgumentCaptor<RecordOperationConfig> config = ArgumentCaptor.forClass(RecordOperationConfig.class); verify(catalogManager).createRecord(eq(user), config.capture(), eq(MappingRecord.class)); assertEquals("Title", config.getValue().get(RecordCreateSettings.RECORD_TITLE)); assertEquals("Description", config.getValue().get(RecordCreateSettings.RECORD_DESCRIPTION)); assertEquals("#Markdown", config.getValue().get(RecordCreateSettings.RECORD_MARKDOWN)); assertEquals(Collections.singleton("keyword"), config.getValue().get(RecordCreateSettings.RECORD_KEYWORDS)); assertEquals(Collections.singleton(user), config.getValue().get(RecordCreateSettings.RECORD_PUBLISHERS)); assertNotNull(config.getValue().get(MappingRecordCreateSettings.INPUT_STREAM)); assertNotNull(config.getValue().get(MappingRecordCreateSettings.RDF_FORMAT)); verify(engineManager, atLeastOnce()).retrieveUser(anyString()); }
Example 4
Source File: MappingRestTest.java From mobi with GNU Affero General Public License v3.0 | 6 votes |
@Test public void uploadStringTest() throws Exception { FormDataMultiPart fd = new FormDataMultiPart(); fd.field("title", "Title"); fd.field("description", "Description"); fd.field("markdown", "#Markdown"); fd.field("keywords", "keyword"); fd.field("jsonld", mappingJsonld); Response response = target().path("mappings").request().post(Entity.entity(fd, MediaType.MULTIPART_FORM_DATA)); assertEquals(response.getStatus(), 201); assertEquals(MAPPING_RECORD_IRI, response.readEntity(String.class)); ArgumentCaptor<RecordOperationConfig> config = ArgumentCaptor.forClass(RecordOperationConfig.class); verify(catalogManager).createRecord(eq(user), config.capture(), eq(MappingRecord.class)); assertEquals("Title", config.getValue().get(RecordCreateSettings.RECORD_TITLE)); assertEquals("Description", config.getValue().get(RecordCreateSettings.RECORD_DESCRIPTION)); assertEquals("#Markdown", config.getValue().get(RecordCreateSettings.RECORD_MARKDOWN)); assertEquals(Collections.singleton("keyword"), config.getValue().get(RecordCreateSettings.RECORD_KEYWORDS)); assertEquals(Collections.singleton(user), config.getValue().get(RecordCreateSettings.RECORD_PUBLISHERS)); assertNotNull(config.getValue().get(VersionedRDFRecordCreateSettings.INITIAL_COMMIT_DATA)); verify(engineManager, atLeastOnce()).retrieveUser(anyString()); }
Example 5
Source File: MergeRequestRestTest.java From mobi with GNU Affero General Public License v3.0 | 6 votes |
@Test public void createMergeRequestWithInvalidPathTest() { // Setup: FormDataMultiPart fd = new FormDataMultiPart(); fd.field("title", "Title"); fd.field("recordId", RECORD_ID); fd.field("sourceBranchId", BRANCH_ID); fd.field("targetBranchId", BRANCH_ID); doThrow(new IllegalArgumentException()).when(requestManager).createMergeRequest(any(MergeRequestConfig.class), any(Resource.class)); Response response = target().path("merge-requests").request().post(Entity.entity(fd, MediaType.MULTIPART_FORM_DATA)); assertEquals(response.getStatus(), 400); verify(engineManager, atLeastOnce()).retrieveUser(UsernameTestFilter.USERNAME); verify(requestManager).createMergeRequest(any(MergeRequestConfig.class), any(Resource.class)); verify(requestManager, times(0)).addMergeRequest(any(MergeRequest.class)); }
Example 6
Source File: XACMLRequestFilterTest.java From mobi with GNU Affero General Public License v3.0 | 6 votes |
@Test public void resourceIdFormDataExistsWithDefaultTest() throws Exception { FormDataMultiPart formPart = new FormDataMultiPart(); formPart.field(FORM_DATA_FIELD, FORM_DATA_VALUE); when(context.readEntity(FormDataMultiPart.class)).thenReturn(formPart); when(context.hasEntity()).thenReturn(true); when(context.getMediaType()).thenReturn(MediaType.MULTIPART_FORM_DATA_TYPE); when(uriInfo.getPathParameters()).thenReturn(new MultivaluedHashMap<>()); when(uriInfo.getQueryParameters()).thenReturn(new MultivaluedHashMap<>()); when(resourceInfo.getResourceMethod()).thenReturn(MockResourceIdFormDataClass.class.getDeclaredMethod("formDataWithDefault")); IRI actionId = VALUE_FACTORY.createIRI(Read.TYPE); IRI resourceId = VALUE_FACTORY.createIRI(FORM_DATA_VALUE); IRI subjectId = VALUE_FACTORY.createIRI(ANON_USER); filter.filter(context); Mockito.verify(pdp).createRequest(subjectId, new HashMap<>(), resourceId, new HashMap<>(), actionId, new HashMap<>()); }
Example 7
Source File: CatalogRestTest.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@Test public void createRecordForUserThatDoesNotExistTest() { // Setup: when(engineManager.retrieveUser(anyString())).thenReturn(Optional.empty()); FormDataMultiPart fd = new FormDataMultiPart(); fd.field("type", Record.TYPE); fd.field("title", "Title"); Response response = target().path("catalogs/" + encode(LOCAL_IRI) + "/records") .request().post(Entity.entity(fd, MediaType.MULTIPART_FORM_DATA)); assertEquals(response.getStatus(), 401); verify(provUtils, times(0)).startCreateActivity(user); }
Example 8
Source File: CatalogRestTest.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@Test public void createTagForCommitNotInRecordTest() { //Setup: FormDataMultiPart fd = new FormDataMultiPart(); fd.field("title", "Title"); fd.field("iri", "urn:test"); fd.field("commit", COMMIT_IRIS[1]); Response response = target().path("catalogs/" + encode(LOCAL_IRI) + "/records/" + encode(RECORD_IRI) + "/tags") .request().post(Entity.entity(fd, MediaType.MULTIPART_FORM_DATA)); assertEquals(response.getStatus(), 400); }
Example 9
Source File: CatalogRestTest.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@Test public void createVersionForUserThatDoesNotExistTest() { // Setup: when(engineManager.retrieveUser(anyString())).thenReturn(Optional.empty()); FormDataMultiPart fd = new FormDataMultiPart(); fd.field("type", Version.TYPE); fd.field("title", "Title"); Response response = target().path("catalogs/" + encode(LOCAL_IRI) + "/records/" + encode(RECORD_IRI) + "/versions") .request().post(Entity.entity(fd, MediaType.MULTIPART_FORM_DATA)); assertEquals(response.getStatus(), 401); }
Example 10
Source File: CatalogRestTest.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@Test public void createVersionWithInvalidTypeTest() { //Setup: FormDataMultiPart fd = new FormDataMultiPart(); fd.field("type", Thing.TYPE); fd.field("title", "Title"); Response response = target().path("catalogs/" + encode(LOCAL_IRI) + "/records/" + encode(RECORD_IRI) + "/versions") .request().post(Entity.entity(fd, MediaType.MULTIPART_FORM_DATA)); assertEquals(response.getStatus(), 400); }
Example 11
Source File: MergeRequestRestTest.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@Test public void createMergeRequestWithInvalidSourceTest() { // Setup: FormDataMultiPart fd = new FormDataMultiPart(); fd.field("title", "Title"); fd.field("recordId", RECORD_ID); fd.field("sourceBranchId", invalidIRIString); fd.field("targetBranchId", BRANCH_ID); Response response = target().path("merge-requests").request().post(Entity.entity(fd, MediaType.MULTIPART_FORM_DATA)); assertEquals(response.getStatus(), 400); }
Example 12
Source File: CatalogRestTest.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@Test public void updateInProgressCommitWithIncorrectPathTest() { // Setup: JSONArray adds = new JSONArray(); adds.add(new JSONObject().element("@id", "http://example.com/add").element("@type", new JSONArray().element("http://example.com/Add"))); FormDataMultiPart fd = new FormDataMultiPart(); fd.field("additions", adds.toString()); doThrow(new IllegalArgumentException()).when(catalogManager).updateInProgressCommit(eq(vf.createIRI(LOCAL_IRI)), eq(vf.createIRI(ERROR_IRI)), any(User.class), any(Model.class), any(Model.class)); Response response = target().path("catalogs/" + encode(LOCAL_IRI) + "/records/" + encode(ERROR_IRI) + "/in-progress-commit") .request().put(Entity.entity(fd, MediaType.MULTIPART_FORM_DATA)); assertEquals(response.getStatus(), 400); }
Example 13
Source File: UserRestTest.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@Test public void createUserWithoutPasswordTest() { //Setup: FormDataMultiPart fd = new FormDataMultiPart(); fd.field("username", "testUser"); fd.field("email", "[email protected]"); fd.field("firstName", "John"); fd.field("lastName", "Doe"); when(engineManager.userExists(anyString())).thenReturn(false); Response response = target().path("users") .request().post(Entity.entity(fd, MediaType.MULTIPART_FORM_DATA)); assertEquals(response.getStatus(), 400); }
Example 14
Source File: CatalogRestTest.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@Test public void createRecordWithInvalidTypeTest() { //Setup: FormDataMultiPart fd = new FormDataMultiPart(); fd.field("type", Thing.TYPE); fd.field("title", "Title"); Response response = target().path("catalogs/" + encode(LOCAL_IRI) + "/records") .request().post(Entity.entity(fd, MediaType.MULTIPART_FORM_DATA)); assertEquals(response.getStatus(), 400); verify(provUtils, times(0)).startCreateActivity(user); }
Example 15
Source File: DelimitedRestTest.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
private Response testMapPreview(String fileName, String jsonld, Map<String, Object> params) { FormDataMultiPart fd = new FormDataMultiPart(); fd.field("jsonld", jsonld); WebTarget wt = target().path("delimited-files/" + fileName + "/map-preview"); if (params != null) { for (String k : params.keySet()) { wt = wt.queryParam(k, params.get(k)); } } Response response = wt.request().post(Entity.entity(fd, MediaType.MULTIPART_FORM_DATA)); assertEquals(response.getStatus(), 200); return response; }
Example 16
Source File: MergeRequestRestTest.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@Test public void createMergeRequestWithoutRecordTest() { // Setup: FormDataMultiPart fd = new FormDataMultiPart(); fd.field("title", "Title"); fd.field("sourceBranchId", BRANCH_ID); fd.field("targetBranchId", BRANCH_ID); Response response = target().path("merge-requests").request().post(Entity.entity(fd, MediaType.MULTIPART_FORM_DATA)); assertEquals(response.getStatus(), 400); verify(engineManager, times(0)).retrieveUser(UsernameTestFilter.USERNAME); verify(requestManager, times(0)).createMergeRequest(any(MergeRequestConfig.class), any(Resource.class)); verify(requestManager, times(0)).addMergeRequest(any(MergeRequest.class)); }
Example 17
Source File: DelimitedRestTest.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@Test public void mapPreviewWithoutMappingTest() { String mapping = ""; FormDataMultiPart fd = new FormDataMultiPart(); fd.field("jsonld", mapping); Response response = target().path("delimited-files/test.csv/map-preview").request().post(Entity.entity(fd, MediaType.MULTIPART_FORM_DATA)); assertEquals(response.getStatus(), 400); response = target().path("delimited-files/test.csv/map-preview").request().post(Entity.entity(null, MediaType.MULTIPART_FORM_DATA)); assertEquals(response.getStatus(), 400); }
Example 18
Source File: UserRestTest.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@Test public void createUserWithoutUsernameTest() { //Setup: FormDataMultiPart fd = new FormDataMultiPart(); fd.field("email", "[email protected]"); fd.field("firstName", "John"); fd.field("lastName", "Doe"); fd.field("password", "123"); when(engineManager.userExists(anyString())).thenReturn(false); Response response = target().path("users") .request().post(Entity.entity(fd, MediaType.MULTIPART_FORM_DATA)); assertEquals(response.getStatus(), 400); }
Example 19
Source File: CatalogRestTest.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@Test public void createBranchWithCommitNotInRecordTest() { //Setup: FormDataMultiPart fd = new FormDataMultiPart(); fd.field("type", Branch.TYPE); fd.field("title", "Title"); fd.field("commitId", COMMIT_IRIS[1]); Response response = target().path("catalogs/" + encode(LOCAL_IRI) + "/records/" + encode(RECORD_IRI) + "/branches") .request().post(Entity.entity(fd, MediaType.MULTIPART_FORM_DATA)); assertEquals(response.getStatus(), 400); }
Example 20
Source File: UserRestTest.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@Test public void createExistingUserTest() { //Setup: FormDataMultiPart fd = new FormDataMultiPart(); fd.field("username", "testUser"); fd.field("email", "[email protected]"); fd.field("firstName", "John"); fd.field("lastName", "Doe"); fd.field("password", "123"); Response response = target().path("users") .request().post(Entity.entity(fd, MediaType.MULTIPART_FORM_DATA)); assertEquals(response.getStatus(), 400); }