|
Apache CXF example source code file (UriInfoImplTest.java)
The Apache CXF UriInfoImplTest.java source code/** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package org.apache.cxf.jaxrs.impl; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.UriInfo; import org.apache.cxf.jaxrs.model.URITemplate; import org.apache.cxf.message.Exchange; import org.apache.cxf.message.ExchangeImpl; import org.apache.cxf.message.Message; import org.apache.cxf.message.MessageImpl; import org.apache.cxf.service.model.EndpointInfo; import org.apache.cxf.transport.servlet.ServletDestination; import org.easymock.classextension.EasyMock; import org.easymock.classextension.IMocksControl; import org.junit.Assert; import org.junit.Before; import org.junit.Test; public class UriInfoImplTest extends Assert { private IMocksControl control; @Before public void setUp() { control = EasyMock.createNiceControl(); control.makeThreadSafe(true); } @Test public void testGetAbsolutePath() { UriInfoImpl u = new UriInfoImpl(mockMessage("http://localhost:8080/baz", "/bar"), null); assertEquals("Wrong absolute path", "http://localhost:8080/baz/bar", u.getAbsolutePath().toString()); u = new UriInfoImpl(mockMessage("http://localhost:8080/baz/", "/bar"), null); assertEquals("Wrong absolute path", "http://localhost:8080/baz/bar", u.getAbsolutePath().toString()); } @Test public void testGetAbsolutePathWithEncodedChars() { UriInfoImpl u = new UriInfoImpl(mockMessage("http://localhost:8080/baz%20foo", "/bar"), null); assertEquals("Wrong absolute path", "http://localhost:8080/baz%20foo/bar", u.getAbsolutePath().toString()); u = new UriInfoImpl(mockMessage("http://localhost:8080/baz/%20foo", "/bar%20foo"), null); assertEquals("Wrong absolute path", "http://localhost:8080/baz/%20foo/bar%20foo", u.getAbsolutePath().toString()); } @Test public void testGetQueryParameters() { UriInfoImpl u = new UriInfoImpl(mockMessage("http://localhost:8080/baz", "/bar"), null); assertEquals("unexpected queries", 0, u.getQueryParameters().size()); u = new UriInfoImpl(mockMessage("http://localhost:8080/baz", "/bar", "n=1%202"), null); MultivaluedMap<String, String> qps = u.getQueryParameters(false); assertEquals("Number of queries is wrong", 1, qps.size()); assertEquals("Wrong query value", qps.getFirst("n"), "1%202"); u = new UriInfoImpl(mockMessage("http://localhost:8080/baz", "/bar", "N=0&n=1%202&n=3&b=2&a%2Eb=ab"), null); qps = u.getQueryParameters(); assertEquals("Number of queiries is wrong", 4, qps.size()); assertEquals("Wrong query value", qps.get("N").get(0), "0"); assertEquals("Wrong query value", qps.get("n").get(0), "1 2"); assertEquals("Wrong query value", qps.get("n").get(1), "3"); assertEquals("Wrong query value", qps.get("b").get(0), "2"); assertEquals("Wrong query value", qps.get("a.b").get(0), "ab"); } @Test public void testGetCaseinsensitiveQueryParameters() { UriInfoImpl u = new UriInfoImpl(mockMessage("http://localhost:8080/baz", "/bar"), null); assertEquals("unexpected queries", 0, u.getQueryParameters().size()); Message m = mockMessage("http://localhost:8080/baz", "/bar", "N=1%202&n=3&b=2&a%2Eb=ab"); m.put("org.apache.cxf.http.case_insensitive_queries", "true"); u = new UriInfoImpl(m, null); MultivaluedMap<String, String> qps = u.getQueryParameters(); assertEquals("Number of queiries is wrong", 3, qps.size()); assertEquals("Wrong query value", qps.get("n").get(0), "1 2"); assertEquals("Wrong query value", qps.get("n").get(1), "3"); assertEquals("Wrong query value", qps.get("b").get(0), "2"); assertEquals("Wrong query value", qps.get("a.b").get(0), "ab"); } @Test public void testGetRequestURI() { UriInfo u = new UriInfoImpl(mockMessage("http://localhost:8080/baz/bar", "/foo", "n=1%202"), null); assertEquals("Wrong request uri", "http://localhost:8080/baz/bar/foo?n=1%202", u.getRequestUri().toString()); } @Test public void testGetRequestURIWithEncodedChars() { UriInfo u = new UriInfoImpl(mockMessage("http://localhost:8080/baz/bar", "/foo/%20bar", "n=1%202"), null); assertEquals("Wrong request uri", "http://localhost:8080/baz/bar/foo/%20bar?n=1%202", u.getRequestUri().toString()); } @Test public void testGetTemplateParameters() { MultivaluedMap<String, String> values = new MetadataMap Other Apache CXF examples (source code examples)Here is a short list of links related to this Apache CXF UriInfoImplTest.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.