package org.apache.synapse.transport.nhttp;

import junit.framework.TestCase;
import org.apache.synapse.transport.nhttp.util.NhttpUtil;

public class RestURLPostfixTest extends TestCase {

    /**
     * Test whether the REST_URL_PPOSTFIX contains a prefix as "/"
     */
    public void testPrefixingSlash(){
        String uri = "/epdata?size=10";
        String servicePath = "services";

        String REST_URL_POSTFIX = NhttpUtil.getRestUrlPostfix(uri, servicePath);
        assertTrue(REST_URL_POSTFIX != null && !REST_URL_POSTFIX.startsWith("/"));
    }

    /**
     * Include the service patch (services) keyword in the uri and check whether the REST_URL_POSTFIX is generated properly.
     */
    public void testServicePathInclusion(){
        //When the servicePath is somewhere in the middle of the uri
        String uri = "/epdata/services/?size=10";
        String servicePath = "services";

        String REST_URL_POSTFIX = NhttpUtil.getRestUrlPostfix(uri, servicePath);
        //REST_URL_POSTFIX should not be null and should contain the servicePath.
        assertTrue(REST_URL_POSTFIX != null && REST_URL_POSTFIX.contains(servicePath));

        //When the servicePatch is in the beginning of the uri
        uri = "/services/epdata?size=10";
        REST_URL_POSTFIX = NhttpUtil.getRestUrlPostfix(uri, servicePath);
        //REST_URL_POSTFIX should not be null and should not contain the servicePath.
        assertTrue(REST_URL_POSTFIX != null && !"".equals(REST_URL_POSTFIX) && !REST_URL_POSTFIX.contains(servicePath));
    }
    
    /**
     * check whether REST_URL_POSTFIX is generated properly when
     * there are query parameters with URLs as values
     */
    public void testQueryParamWithURL() {
    	String uri = "/test/admin?a=http://test.com";
        String servicePath = "services";
    
        String REST_URL_POSTFIX = NhttpUtil.getRestUrlPostfix(uri, servicePath);
        assertTrue(REST_URL_POSTFIX != null && REST_URL_POSTFIX.equals("test/admin?a=http://test.com"));
    }
}

@@ -1852,33 +1852,32 @@
 _URL_POSTFIX = N
-h
 ttpUtil.getRestU
@@ -1897,32 +1897,32 @@
 , servicePath);%0A
+
         assertTr
@@ -2010,16 +2010,1137 @@
 com%22));%0A
-
     %7D%0A
+        %0A    /**%0A      * Include the service patch (services) keyword in the complete uri and check whether the REST_URL_POSTFIX is generated properly.%0A      */%0A    public void testServicePathInclusionCompleteUrl()%7B%0A        //When the servicePath is somewhere in the middle of the uri%0A        String uri = %22http://localhost:8080/epdata/services/?size=10%22;%0A        String servicePath = %22services%22;%0A    %0A        String REST_URL_POSTFIX = NhttpUtil.getRestUrlPostfix(uri, servicePath);%0A        //REST_URL_POSTFIX should not be null and should contain the servicePath.%0A        assertTrue(REST_URL_POSTFIX != null && REST_URL_POSTFIX.contains(servicePath));%0A    %0A        //When the servicePatch is in the beginning of the uri%0A        uri = %22http://localhost:8080/services/epdata?size=10%22;%0A        REST_URL_POSTFIX = NhttpUtil.getRestUrlPostfix(uri, servicePath);%0A        System.out.println(REST_URL_POSTFIX);%0A        //REST_URL_POSTFIX should not be null and should not contain the servicePath.%0A        assertTrue(REST_URL_POSTFIX != null && !%22%22.equals(REST_URL_POSTFIX) && !REST_URL_POSTFIX.contains(servicePath));%0A    %7D    %0A
 %7D%0A

fix for ESBJAVA-3172 tests