Java Code Examples for javax.ws.rs.core.MultivaluedHashMap#put()

The following examples show how to use javax.ws.rs.core.MultivaluedHashMap#put() . 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: PermissionFilterTest.java    From gravitee-management-rest-api with Apache License 2.0 6 votes vote down vote up
/**
 * API Tests
 */
private ApiEntity initApiMocks() {
    ApiEntity api = new ApiEntity();
    api.setId(API_ID);
    Principal user = () -> USERNAME;
    when(apiService.findById(api.getId())).thenReturn(api);
    when(securityContext.getUserPrincipal()).thenReturn(user);
    Permission perm = mock(Permission.class);
    when(perm.value()).thenReturn(RolePermission.API_ANALYTICS);
    when(perm.acls()).thenReturn(new RolePermissionAction[]{RolePermissionAction.UPDATE});
    when(permissions.value()).thenReturn(new Permission[]{perm});
    UriInfo uriInfo = mock(UriInfo.class);
    MultivaluedHashMap<String, String> map = new MultivaluedHashMap<>();
    map.put("api", Collections.singletonList(api.getId()));
    when(uriInfo.getPathParameters()).thenReturn(map);
    when(containerRequestContext.getUriInfo()).thenReturn(uriInfo);
    return api;
}
 
Example 2
Source File: PermissionFilterTest.java    From gravitee-management-rest-api with Apache License 2.0 6 votes vote down vote up
/**
 * APPLICATION Tests
 */
private ApplicationEntity initApplicationMocks() {
    ApplicationEntity application = new ApplicationEntity();
    application.setId(APPLICATION_ID);
    Principal user = () -> USERNAME;
    when(applicationService.findById(application.getId())).thenReturn(application);
    when(securityContext.getUserPrincipal()).thenReturn(user);
    Permission perm = mock(Permission.class);
    when(perm.value()).thenReturn(RolePermission.APPLICATION_ANALYTICS);
    when(perm.acls()).thenReturn(new RolePermissionAction[]{RolePermissionAction.UPDATE});
    when(permissions.value()).thenReturn(new Permission[]{perm});
    UriInfo uriInfo = mock(UriInfo.class);
    MultivaluedHashMap<String, String> map = new MultivaluedHashMap<>();
    map.put("application", Collections.singletonList(application.getId()));
    when(uriInfo.getPathParameters()).thenReturn(map);
    when(containerRequestContext.getUriInfo()).thenReturn(uriInfo);
    return application;
}
 
Example 3
Source File: PermissionFilterTest.java    From gravitee-management-rest-api with Apache License 2.0 6 votes vote down vote up
/**
 * API Tests
 */
private ApiEntity initApiMocks() {
    ApiEntity api = new ApiEntity();
    api.setId(API_ID);
    Principal user = () -> USERNAME;
    when(apiService.findById(api.getId())).thenReturn(api);
    when(securityContext.getUserPrincipal()).thenReturn(user);
    Permission perm = mock(Permission.class);
    when(perm.value()).thenReturn(RolePermission.API_ANALYTICS);
    when(perm.acls()).thenReturn(new RolePermissionAction[] { RolePermissionAction.UPDATE });
    when(permissions.value()).thenReturn(new Permission[] { perm });
    UriInfo uriInfo = mock(UriInfo.class);
    MultivaluedHashMap<String, String> map = new MultivaluedHashMap<>();
    map.put("apiId", Collections.singletonList(api.getId()));
    when(uriInfo.getPathParameters()).thenReturn(map);
    when(containerRequestContext.getUriInfo()).thenReturn(uriInfo);
    return api;
}
 
Example 4
Source File: PermissionFilterTest.java    From gravitee-management-rest-api with Apache License 2.0 6 votes vote down vote up
/**
 * APPLICATION Tests
 */
private ApplicationEntity initApplicationMocks() {
    ApplicationEntity application = new ApplicationEntity();
    application.setId(APPLICATION_ID);
    Principal user = () -> USERNAME;
    when(applicationService.findById(application.getId())).thenReturn(application);
    when(securityContext.getUserPrincipal()).thenReturn(user);
    Permission perm = mock(Permission.class);
    when(perm.value()).thenReturn(RolePermission.APPLICATION_ANALYTICS);
    when(perm.acls()).thenReturn(new RolePermissionAction[] { RolePermissionAction.UPDATE });
    when(permissions.value()).thenReturn(new Permission[] { perm });
    UriInfo uriInfo = mock(UriInfo.class);
    MultivaluedHashMap<String, String> map = new MultivaluedHashMap<>();
    map.put("applicationId", Collections.singletonList(application.getId()));
    when(uriInfo.getPathParameters()).thenReturn(map);
    when(containerRequestContext.getUriInfo()).thenReturn(uriInfo);
    return application;
}
 
Example 5
Source File: CypherInflectorTest.java    From SciGraph with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
  CypherUtil cypherUtil = new CypherUtil(graphDb, curieUtil);
  addRelationship("http://x.org/#foo", "http://x.org/#fizz", OwlRelationships.RDFS_SUB_PROPERTY_OF);
  addRelationship("http://x.org/#bar", "http://x.org/#baz", OwlRelationships.RDFS_SUB_PROPERTY_OF);
  addRelationship("http://x.org/#1", "http://x.org/#2", RelationshipType.withName("http://x.org/#fizz"));
  when(context.getUriInfo()).thenReturn(uriInfo);
  MultivaluedHashMap<String, String> map = new MultivaluedHashMap<>();
  map.put("rel_id", newArrayList("http://x.org/#fizz"));
  when(uriInfo.getQueryParameters()).thenReturn(map);
  map = new MultivaluedHashMap<>();
  map.put("pathParam", newArrayList("pathValue"));
  when(uriInfo.getPathParameters()).thenReturn(map);
  when(curieUtil.getIri(anyString())).thenReturn(Optional.<String>empty());
  when(curieUtil.getCurie(anyString())).thenReturn(Optional.<String>empty());
  when(curieUtil.getIri("X:foo")).thenReturn(Optional.of("http://x.org/#foo"));
  inflector = new CypherInflector(graphDb, cypherUtil, curieUtil, "dynamic", path, new HashMap<String, GraphAspect>());
}
 
Example 6
Source File: JerseyHttpClient.java    From karate with MIT License 5 votes vote down vote up
@Override
public Entity getEntity(MultiValuedMap fields, String mediaType) {
    MultivaluedHashMap<String, Object> map = new MultivaluedHashMap<>();
    for (Entry<String, List> entry : fields.entrySet()) {
        map.put(entry.getKey(), entry.getValue());
    }
    // special handling, charset is not valid in content-type header here
    int pos = mediaType.indexOf(';');
    if (pos != -1) {
        mediaType = mediaType.substring(0, pos);
    }
    MediaType mt = MediaType.valueOf(mediaType);
    return Entity.entity(map, mt);
}
 
Example 7
Source File: UriBuilderRequestFilterTest.java    From gravitee-management-rest-api with Apache License 2.0 5 votes vote down vote up
private void givenHeaders(String... headers) {
    MultivaluedHashMap<String, String> mockHeaders = new MultivaluedHashMap<>();
    for (int i = 0; i < headers.length / 2; i++) {
        String hName = headers[2 * i];
        String hValue = headers[(2 * i) + 1];
        mockHeaders.put(hName, Collections.singletonList(hValue));
    }
    when(containerRequestContext.getHeaders()).thenReturn(mockHeaders);

}
 
Example 8
Source File: MapUtilsTest.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@Test
public void mergesPathAndQueryParams() {
  MultivaluedHashMap<String, String> pathParamMap = new MultivaluedHashMap<>();
  pathParamMap.put("pathParam", newArrayList("paramValue"));
  MultivaluedHashMap<String, String> queryParamMap = new MultivaluedHashMap<>();
  pathParamMap.put("rel_id", newArrayList("fizz"));
  when(uriInfo.getPathParameters()).thenReturn(pathParamMap);
  when(uriInfo.getQueryParameters()).thenReturn(queryParamMap);
  Multimap<String, Object> actual = MultivaluedMapUtils.merge(uriInfo);
  assertThat(actual.get("pathParam"), contains((Object)"paramValue"));
  assertThat(actual.get("rel_id"), contains((Object)"fizz"));
}
 
Example 9
Source File: MapUtilsTest.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@Test
public void splitsMultivaluedPathParams() {
  MultivaluedHashMap<String, String> paramMap = new MultivaluedHashMap<>();
  paramMap.put("key", newArrayList("value1+value2"));
  Multimap<String, Object> actual = MultivaluedMapUtils.multivaluedMapToMultimap(paramMap, Optional.of('+'));
  assertThat(actual.get("key"), contains((Object)"value1", (Object)"value2"));
}
 
Example 10
Source File: DynamicResourceModuleIT.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setup() {
  try (Transaction tx = graphDb.beginTx()) {
    Node node = graphDb.createNode();
    Node node2 = graphDb.createNode();
    node.createRelationshipTo(node2, RelationshipType.withName("foo"));
    node.setProperty("foo", "bar");
    tx.success();
  }
  when(context.getUriInfo()).thenReturn(uriInfo);
  MultivaluedHashMap<String, String> map = new MultivaluedHashMap<>();
  map.put("foo", newArrayList("bar"));
  when(uriInfo.getQueryParameters()).thenReturn(map);
  when(uriInfo.getPathParameters()).thenReturn(new MultivaluedHashMap<String, String>());
}
 
Example 11
Source File: YandexTranslate.java    From nifi with Apache License 2.0 5 votes vote down vote up
protected Invocation prepareResource(final String key, final List<String> text, final String sourceLanguage, final String destLanguage) {
    Invocation.Builder builder = client.target(URL).request(MediaType.APPLICATION_JSON);

    final MultivaluedHashMap entity = new MultivaluedHashMap();
    entity.put("text", text);
    entity.add("key", key);
    if ((StringUtils.isBlank(sourceLanguage))) {
        entity.add("lang", destLanguage);
    } else {
        entity.add("lang", sourceLanguage + "-" + destLanguage);
    }

    return builder.buildPost(Entity.form(entity));
}
 
Example 12
Source File: ViewableWriterTest.java    From krazo with Apache License 2.0 4 votes vote down vote up
/**
 * Test writeTo method.
 *
 * @throws Exception when a serious error occurs.
 */
@Test
public void testWriteTo() throws Exception {
    ViewableWriter writer = new ViewableWriter();

    Field mvcField = writer.getClass().getDeclaredField("mvc");
    mvcField.setAccessible(true);
    mvcField.set(writer, new MvcContextImpl());

    ViewEngineFinder finder = EasyMock.createStrictMock(ViewEngineFinder.class);
    Field finderField = writer.getClass().getDeclaredField("engineFinder");
    finderField.setAccessible(true);
    finderField.set(writer, finder);

    HttpServletRequest request = EasyMock.createStrictMock(HttpServletRequest.class);
    Field requestField = writer.getClass().getDeclaredField("injectedRequest");
    requestField.setAccessible(true);
    requestField.set(writer, request);

    Event<MvcEvent> dispatcher = EasyMock.createStrictMock(Event.class);
    Field dispatcherField = writer.getClass().getDeclaredField("dispatcher");
    dispatcherField.setAccessible(true);
    dispatcherField.set(writer, dispatcher);

    EventDispatcher eventDispatcher = EasyMock.createMock(EventDispatcher.class);
    Field eventDispatcherField = writer.getClass().getDeclaredField("eventDispatcher");
    eventDispatcherField.setAccessible(true);
    eventDispatcherField.set(writer, eventDispatcher);

    ViewEngine viewEngine = EasyMock.createStrictMock(ViewEngine.class);

    HttpServletResponse response = EasyMock.createStrictMock(HttpServletResponse.class);
    response.setContentType(eq("text/html;charset=UTF-8"));
    expect(response.getCharacterEncoding()).andReturn("UTF-8");
    Field responseField = writer.getClass().getDeclaredField("injectedResponse");
    responseField.setAccessible(true);
    responseField.set(writer, response);

    Configuration config = EasyMock.createStrictMock(Configuration.class);
    Field configField = writer.getClass().getDeclaredField("config");
    configField.setAccessible(true);
    configField.set(writer, config);

    MultivaluedHashMap map = new MultivaluedHashMap();
    ArrayList<MediaType> contentTypes = new ArrayList<>();
    contentTypes.add(MediaType.TEXT_HTML_TYPE);
    map.put("Content-Type", contentTypes);

    Viewable viewable = new Viewable("myview");
    viewable.setModels(new ModelsImpl());

    expect(finder.find(anyObject())).andReturn(viewEngine);
    viewEngine.processView((ViewEngineContext) anyObject());

    replay(finder, request, viewEngine, response);
    writer.writeTo(viewable, null, null, new Annotation[] {}, MediaType.TEXT_HTML_TYPE, map, null);
    verify(finder, request, viewEngine, response);
}
 
Example 13
Source File: ViewableWriterTest.java    From ozark with Apache License 2.0 4 votes vote down vote up
/**
 * Test writeTo method.
 *
 * @throws Exception when a serious error occurs.
 */
@Test
public void testWriteTo() throws Exception {
    ViewableWriter writer = new ViewableWriter();

    Field mvcField = writer.getClass().getDeclaredField("mvc");
    mvcField.setAccessible(true);
    mvcField.set(writer, new MvcContextImpl());
    
    ViewEngineFinder finder = EasyMock.createStrictMock(ViewEngineFinder.class);
    Field finderField = writer.getClass().getDeclaredField("engineFinder");
    finderField.setAccessible(true);
    finderField.set(writer, finder);

    HttpServletRequest request = EasyMock.createStrictMock(HttpServletRequest.class);
    Field requestField = writer.getClass().getDeclaredField("injectedRequest");
    requestField.setAccessible(true);
    requestField.set(writer, request);

    Event<MvcEvent> dispatcher = EasyMock.createStrictMock(Event.class);
    Field dispatcherField = writer.getClass().getDeclaredField("dispatcher");
    dispatcherField.setAccessible(true);
    dispatcherField.set(writer, dispatcher);

    ViewEngine viewEngine = EasyMock.createStrictMock(ViewEngine.class);

    HttpServletResponse response = EasyMock.createStrictMock(HttpServletResponse.class);
    Field responseField = writer.getClass().getDeclaredField("injectedResponse");
    responseField.setAccessible(true);
    responseField.set(writer, response);

    Configuration config = EasyMock.createStrictMock(Configuration.class);
    Field configField = writer.getClass().getDeclaredField("config");
    configField.setAccessible(true);
    configField.set(writer, config);

    MultivaluedHashMap map = new MultivaluedHashMap();
    ArrayList<MediaType> contentTypes = new ArrayList<>();
    contentTypes.add(MediaType.TEXT_HTML_TYPE);
    map.put("Content-Type", contentTypes);

    Viewable viewable = new Viewable("myview");
    viewable.setModels(new ModelsImpl());

    expect(finder.find(anyObject())).andReturn(viewEngine);
    viewEngine.processView((ViewEngineContext) anyObject());

    replay(finder, request, viewEngine, response);
    writer.writeTo(viewable, null, null, new Annotation[] {}, MediaType.WILDCARD_TYPE, map, null);
    verify(finder, request, viewEngine, response);
}