/**
 * 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.activeblaze.util;

import junit.framework.TestCase;

import java.net.URI;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * Test cases for PropertyUtil
 */
public class PropertyUtilTest extends TestCase {
    /**
     * Test method for {@link org.apache.activeblaze.util.PropertyUtil#parseParameters(java.net.URI)}.
     */
    public void testParseParametersURI() throws Exception {
        String query = "name=foo&type=blah";
        URI uri = new URI("http://blah:60606?" + query);
        Map<String, String> result = PropertyUtil.parseParameters(uri);
        assertEquals(2, result.size());
        assertEquals("foo", result.get("name"));
        assertEquals("blah", result.get("type"));
    }

    /**
     * Test method for {@link org.apache.activeblaze.util.PropertyUtil#parseParameters(java.lang.String)}.
     */
    public void testParseParametersString() throws Exception {
        String query = "name=foo&type=blah";
        String uri = "somestring?" + query;
        Map<String, String> result = PropertyUtil.parseParameters(uri);
        assertEquals(2, result.size());
        assertEquals("foo", result.get("name"));
        assertEquals("blah", result.get("type"));
    }

    /**
     * Test method for
     * {@link org.apache.activeblaze.util.PropertyUtil#addPropertiesToURI(java.lang.String, java.util.Map)}.
     */
    public void testAddPropertiesToURI() throws Exception {
        String query = "type=blah&name=foo";
        Map<String, String> map = new LinkedHashMap<String, String>();
        map.put("type", "blah");
        map.put("name", "foo");
        String test = "somestring?" + query;
        String result = PropertyUtil.addPropertiesToURI(test, map);
        URI uri = new URI(result);
        assertEquals(uri.getQuery(), query);
    }
}
