Java Code Examples for javax.ws.rs.core.MultivaluedHashMap#putSingle()
The following examples show how to use
javax.ws.rs.core.MultivaluedHashMap#putSingle() .
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: Encoder_VisitIT.java From agrest with Apache License 2.0 | 6 votes |
@Test public void testRelated() { e2().insertColumns("id_", "name") .values(1, "xxx") .values(2, "yyy") .values(3, "zzz").exec(); e3().insertColumns("id_", "name", "e2_id") .values(7, "zzz", 2) .values(8, "yyy", 1) .values(9, "zzz", 1).exec(); MultivaluedHashMap<String, String> params = new MultivaluedHashMap<>(); params.putSingle("include", "{\"path\":\"e3s\",\"sort\":\"id\"}"); UriInfo mockUri = mock(UriInfo.class); when(mockUri.getQueryParameters()).thenReturn(params); DataResponse<E2> response = ag().select(E2.class).uri(mockUri).get(); assertEquals("6;E2:1;E3:8;E3:9;E2:2;E3:7;E2:3", responseContents(response)); }
Example 2
Source File: EdgeAPI.java From hugegraph-client with Apache License 2.0 | 6 votes |
public List<String> create(List<Edge> edges, boolean checkVertex) { MultivaluedHashMap<String, Object> headers = new MultivaluedHashMap<>(); headers.putSingle("Content-Encoding", BATCH_ENCODING); Map<String, Object> params = ImmutableMap.of("check_vertex", checkVertex); RestResult result = this.client.post(this.batchPath(), edges, headers, params); List<String> ids = result.readList(String.class); if (edges.size() != ids.size()) { throw new NotAllCreatedException( "Not all edges are successfully created, " + "expect '%s', the actual is '%s'", ids, edges.size(), ids.size()); } return ids; }
Example 3
Source File: Encoder_VisitIT.java From agrest with Apache License 2.0 | 6 votes |
@Test public void testStartLimit() { e2().insertColumns("id_", "name") .values(1, "xxx") .values(2, "yyy") .values(3, "zzz") .values(4, "zzz").exec(); MultivaluedHashMap<String, String> params = new MultivaluedHashMap<>(); params.putSingle("sort", "id"); params.putSingle("start", "1"); params.putSingle("limit", "2"); UriInfo mockUri = mock(UriInfo.class); when(mockUri.getQueryParameters()).thenReturn(params); DataResponse<E2> response = ag().select(E2.class).uri(mockUri).get(); assertEquals("2;E2:2;E2:3", responseContents(response)); }
Example 4
Source File: BaggageHeadersFactory.java From istio-tutorial with Apache License 2.0 | 6 votes |
@Override public MultivaluedMap<String, String> update(MultivaluedMap<String, String> incomingHeaders, MultivaluedMap<String, String> clientOutgoingHeaders) { MultivaluedHashMap<String, String> headers = new MultivaluedHashMap<>(); String userAgent = incomingHeaders.getFirst("user-agent"); headers.putSingle("baggage-user-agent", userAgent); String authorization = incomingHeaders.getFirst("Authorization"); if (authorization != null) { headers.putSingle("Authorization", authorization); } String userPreference = incomingHeaders.getFirst("user-preference"); if (userPreference != null) { headers.putSingle("user-preference", userPreference); } return headers; }
Example 5
Source File: BaggageHeadersFactory.java From istio-tutorial with Apache License 2.0 | 6 votes |
@Override public MultivaluedMap<String, String> update(MultivaluedMap<String, String> incomingHeaders, MultivaluedMap<String, String> clientOutgoingHeaders) { MultivaluedHashMap<String, String> headers = new MultivaluedHashMap<>(); String userAgent = incomingHeaders.getFirst("baggage-user-agent"); headers.putSingle("baggage-user-agent", userAgent); String authorization = incomingHeaders.getFirst("Authorization"); if (authorization != null) { headers.putSingle("Authorization", authorization); } String userPreference = incomingHeaders.getFirst("user-preference"); if (userPreference != null) { headers.putSingle("user-preference", userPreference); } return headers; }
Example 6
Source File: SelectBuilderIT.java From agrest with Apache License 2.0 | 6 votes |
@Test public void testGetIncludedObjects_Related() { Ts ts1 = new Ts(11, "p"); Ts ts2 = new Ts(12, "q"); Ts ts3 = new Ts(13, "r"); bucket(Ts.class).put(11, ts1); bucket(Ts.class).put(12, ts1); bucket(Ts.class).put(13, ts1); bucket(Tr.class).put(1, new Tr(1, "a", ts1, ts2)); bucket(Tr.class).put(2, new Tr(2, "b", ts3)); bucket(Tr.class).put(3, new Tr(3, "c")); MultivaluedHashMap<String, String> params = new MultivaluedHashMap<>(); params.putSingle("include", "{\"path\":\"rtss\",\"sort\":\"id\"}"); UriInfo mockUri = mock(UriInfo.class); when(mockUri.getQueryParameters()).thenReturn(params); DataResponse<Tr> response = ag().select(Tr.class).uri(mockUri).get(); String names = response.getIncludedObjects(Ts.class, "rtss").stream().map(Ts::getName).collect(joining(",")); assertEquals("p,q,r", names); }
Example 7
Source File: SelectBuilderIT.java From agrest with Apache License 2.0 | 6 votes |
@Test public void testGetIncludedObjects_Root_StartLimit() { bucket(Tr.class).put(1, new Tr(1, "a")); bucket(Tr.class).put(2, new Tr(2, "b")); bucket(Tr.class).put(3, new Tr(3, "c")); bucket(Tr.class).put(4, new Tr(4, "d")); MultivaluedHashMap<String, String> params = new MultivaluedHashMap<>(); params.putSingle("sort", "id"); params.putSingle("start", "1"); params.putSingle("limit", "2"); UriInfo mockUri = mock(UriInfo.class); when(mockUri.getQueryParameters()).thenReturn(params); DataResponse<Tr> response = ag().select(Tr.class).uri(mockUri).get(); String names = response.getIncludedObjects(Tr.class, "").stream().map(Tr::getName).collect(joining(",")); assertEquals("b,c", names); }
Example 8
Source File: SelectBuilderIT.java From agrest with Apache License 2.0 | 6 votes |
@Test public void testGetIncludedObjects_Root_MapBy() { bucket(Tr.class).put(1, new Tr(1, "a")); bucket(Tr.class).put(2, new Tr(2, "b")); bucket(Tr.class).put(3, new Tr(3, "c")); MultivaluedHashMap<String, String> params = new MultivaluedHashMap<>(); params.putSingle("mapBy", "name"); UriInfo mockUri = mock(UriInfo.class); when(mockUri.getQueryParameters()).thenReturn(params); DataResponse<Tr> response = ag().select(Tr.class).uri(mockUri).get(); String names = response.getIncludedObjects(Tr.class, "").stream().map(Tr::getName).collect(joining(",")); assertEquals("a,b,c", names); }
Example 9
Source File: XACMLRequestFilterTest.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@Test public void resourceIdPathParamExistsWithDefaultTest() throws Exception { MultivaluedHashMap<String, String> pathParameters = new MultivaluedHashMap<>(); pathParameters.putSingle(PATH_PARAM_KEY, PATH_PARAM_VALUE); when(uriInfo.getPathParameters()).thenReturn(pathParameters); when(uriInfo.getQueryParameters()).thenReturn(new MultivaluedHashMap<>()); when(resourceInfo.getResourceMethod()).thenReturn(MockResourceIdPathParamClass.class.getDeclaredMethod("pathParamWithDefault")); IRI actionId = VALUE_FACTORY.createIRI(Read.TYPE); IRI resourceId = VALUE_FACTORY.createIRI(PATH_PARAM_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 10
Source File: Encoder_VisitPushPopIT.java From agrest with Apache License 2.0 | 5 votes |
@Test public void testVisit_Tree_MapBy() { e2().insertColumns("id_", "name") .values(1, "xxx") .values(2, "yyy") .values(3, "zzz").exec(); e5().insertColumns("id", "name") .values(1, "xxx") .values(2, "yyy").exec(); e3().insertColumns("id_", "name", "e2_id", "e5_id") .values(7, "zzz", 2, 1) .values(8, "yyy", 1, 1) .values(9, "zzz", 1, 2).exec(); MultivaluedHashMap<String, String> params = new MultivaluedHashMap<>(); params.putSingle("include", "{\"path\":\"e3s\",\"sort\":\"id\"}"); params.putSingle("include", "e3s.e5"); params.putSingle("mapBy", "name"); UriInfo mockUri = mock(UriInfo.class); when(mockUri.getQueryParameters()).thenReturn(params); DataResponse<E2> response = ag().select(E2.class).uri(mockUri).get(); PushPopVisitor visitor = new PushPopVisitor(); assertEquals("E3:8;E3:9;E3:7", responseContents(response, visitor)); }
Example 11
Source File: Encoder_VisitPushPopIT.java From agrest with Apache License 2.0 | 5 votes |
@Test public void testVisit_Tree() { e2().insertColumns("id_", "name") .values(1, "xxx") .values(2, "yyy") .values(3, "zzz").exec(); e5().insertColumns("id", "name") .values(1, "xxx") .values(2, "yyy").exec(); e3().insertColumns("id_", "name", "e2_id", "e5_id") .values(7, "zzz", 2, 1) .values(8, "yyy", 1, 1) .values(9, "zzz", 1, 2).exec(); MultivaluedHashMap<String, String> params = new MultivaluedHashMap<>(); params.putSingle("include", "{\"path\":\"e3s\",\"sort\":\"id\"}"); params.putSingle("include", "e3s.e5"); UriInfo mockUri = mock(UriInfo.class); when(mockUri.getQueryParameters()).thenReturn(params); DataResponse<E2> response = ag().select(E2.class).uri(mockUri).get(); PushPopVisitor visitor = new PushPopVisitor(); assertEquals("E3:8;E3:9;E3:7", responseContents(response, visitor)); }
Example 12
Source File: ParseRequestStage_IncludeObjectTest.java From agrest with Apache License 2.0 | 5 votes |
@Test public void testExecute_IncludeObject_MapBy() { MultivaluedHashMap<String, String> params = new MultivaluedHashMap<>(); params.putSingle("include", "{\"path\":\"rtt\",\"mapBy\":\"rtu\"}"); SelectContext<Ts> context = prepareContext(Ts.class, params); stage.execute(context); assertNotNull(context.getMergedRequest()); assertEquals(1, context.getMergedRequest().getIncludes().size()); assertTrue(context.getMergedRequest().getIncludes().get(0).getPath().equalsIgnoreCase("rtt")); assertTrue(context.getMergedRequest().getIncludes().get(0).getMapBy().equalsIgnoreCase("rtu")); }
Example 13
Source File: ParseRequestStage_IncludeObjectTest.java From agrest with Apache License 2.0 | 5 votes |
@Test public void testExecute_IncludeObject_Path() { MultivaluedHashMap<String, String> params = new MultivaluedHashMap<>(); params.putSingle("include", "{\"path\":\"rtt\"}"); SelectContext<Ts> context = prepareContext(Ts.class, params); stage.execute(context); assertNotNull(context.getMergedRequest()); assertEquals(1, context.getMergedRequest().getIncludes().size()); assertEquals("rtt", context.getMergedRequest().getIncludes().get(0).getPath()); }
Example 14
Source File: VertexAPI.java From hugegraph-client with Apache License 2.0 | 5 votes |
public List<Object> create(List<Vertex> vertices) { MultivaluedHashMap<String, Object> headers = new MultivaluedHashMap<>(); headers.putSingle("Content-Encoding", BATCH_ENCODING); RestResult result = this.client.post(this.batchPath(), vertices, headers); List<Object> ids = result.readList(Object.class); if (vertices.size() != ids.size()) { throw new NotAllCreatedException( "Not all vertices are successfully created, " + "expect '%s', the actual is '%s'", ids, vertices.size(), ids.size()); } return ids; }
Example 15
Source File: XACMLRequestFilterTest.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@Test public void resourceIdPathParamExistsNoDefaultTest() throws Exception { MultivaluedHashMap<String, String> pathParameters = new MultivaluedHashMap<>(); pathParameters.putSingle(PATH_PARAM_KEY, PATH_PARAM_VALUE); when(uriInfo.getPathParameters()).thenReturn(pathParameters); when(uriInfo.getQueryParameters()).thenReturn(new MultivaluedHashMap<>()); when(resourceInfo.getResourceMethod()).thenReturn(MockResourceIdPathParamClass.class.getDeclaredMethod("pathParamNoDefault")); IRI actionId = VALUE_FACTORY.createIRI(Read.TYPE); IRI resourceId = VALUE_FACTORY.createIRI(PATH_PARAM_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 16
Source File: XACMLRequestFilterTest.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@Test public void resourceIdQueryParamExistsWithDefaultTest() throws Exception { MultivaluedHashMap<String, String> queryParameters = new MultivaluedHashMap<>(); queryParameters.putSingle(QUERY_PARAM_KEY, QUERY_PARAM_VALUE); when(uriInfo.getQueryParameters()).thenReturn(queryParameters); when(uriInfo.getPathParameters()).thenReturn(new MultivaluedHashMap<>()); when(resourceInfo.getResourceMethod()).thenReturn(MockResourceIdQueryParamClass.class.getDeclaredMethod("queryParamWithDefault")); IRI actionId = VALUE_FACTORY.createIRI(Read.TYPE); IRI resourceId = VALUE_FACTORY.createIRI(QUERY_PARAM_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 17
Source File: XACMLRequestFilterTest.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@Test public void resourceIdQueryParamExistsNoDefaultTest() throws Exception { MultivaluedHashMap<String, String> queryParameters = new MultivaluedHashMap<>(); queryParameters.putSingle(QUERY_PARAM_KEY, QUERY_PARAM_VALUE); when(uriInfo.getQueryParameters()).thenReturn(queryParameters); when(uriInfo.getPathParameters()).thenReturn(new MultivaluedHashMap<>()); when(resourceInfo.getResourceMethod()).thenReturn(MockResourceIdQueryParamClass.class.getDeclaredMethod("queryParamNoDefault")); IRI actionId = VALUE_FACTORY.createIRI(Read.TYPE); IRI resourceId = VALUE_FACTORY.createIRI(QUERY_PARAM_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 18
Source File: EdgeAPI.java From hugegraph-client with Apache License 2.0 | 5 votes |
public List<Edge> update(BatchEdgeRequest request) { this.client.checkApiVersion("0.45", "batch property update"); MultivaluedHashMap<String, Object> headers = new MultivaluedHashMap<>(); headers.putSingle("Content-Encoding", BATCH_ENCODING); RestResult result = this.client.put(this.batchPath(), null, request, headers); return result.readList(this.type(), Edge.class); }
Example 19
Source File: VertexAPI.java From hugegraph-client with Apache License 2.0 | 5 votes |
public List<Vertex> update(BatchVertexRequest request) { this.client.checkApiVersion("0.45", "batch property update"); MultivaluedHashMap<String, Object> headers = new MultivaluedHashMap<>(); headers.putSingle("Content-Encoding", BATCH_ENCODING); RestResult result = this.client.put(this.batchPath(), null, request, headers); return result.readList(this.type(), Vertex.class); }