Search in sources :

Example 1 with QueryVarParamWriter

use of org.apache.servicecomb.common.rest.definition.path.QueryVarParamWriter in project incubator-servicecomb-java-chassis by apache.

the class TestPath method testQueryVarParamWriter.

@Test
public void testQueryVarParamWriter() throws Exception {
    boolean status = true;
    new MockUp<RestParam>() {

        @Mock
        public String getParamName() {
            return "queryVar";
        }
    };
    new MockUp<QueryVarParamWriter>() {

        @Mock
        protected Object getParamValue(Object[] args) {
            return args[0];
        }
    };
    Parameter parameter = new QueryParameter();
    QueryVarParamWriter writer = new QueryVarParamWriter('&', new RestParam(0, parameter, String.class));
    try {
        verify(writer, "T", "&queryVar=T");
        verify(writer, null, "&");
        verify(writer, new String[] { "a", "b" }, "&queryVar=a&queryVar=b");
        verify(writer, new String[] { "a", null, "b" }, "&queryVar=a&queryVar=&queryVar=b");
        verify(writer, Arrays.asList("Lars", "Simon"), "&queryVar=Lars&queryVar=Simon");
        verify(writer, "测试", "&queryVar=%E6%B5%8B%E8%AF%95");
        verify(writer, "a b", "&queryVar=a+b");
        verify(writer, "a+b", "&queryVar=a%2Bb");
    } catch (Exception e) {
        status = false;
    }
    Assert.assertTrue(status);
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) QueryVarParamWriter(org.apache.servicecomb.common.rest.definition.path.QueryVarParamWriter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) MockUp(mockit.MockUp) Test(org.junit.Test)

Example 2 with QueryVarParamWriter

use of org.apache.servicecomb.common.rest.definition.path.QueryVarParamWriter in project java-chassis by ServiceComb.

the class TestPath method testQueryVarParamWriter.

@Test
public void testQueryVarParamWriter() {
    boolean status = true;
    new MockUp<RestParam>() {

        @Mock
        public String getParamName() {
            return "queryVar";
        }
    };
    new MockUp<QueryVarParamWriter>() {

        @Mock
        protected Object getParamValue(Object[] args) {
            return args[0];
        }
    };
    Parameter parameter = new QueryParameter();
    QueryVarParamWriter writer = new QueryVarParamWriter(new RestParam(parameter, String.class));
    try {
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("queryVar", "T");
        verify(writer, parameters, "?queryVar=T");
        parameters.put("queryVar", null);
        verify(writer, parameters, "");
        parameters.put("queryVar", new String[] { "a", "b" });
        verify(writer, parameters, "?queryVar=a&queryVar=b");
        parameters.put("queryVar", new String[] { "a", null, "b" });
        verify(writer, parameters, "?queryVar=a&queryVar=b");
        parameters.put("queryVar", Arrays.asList("Lars", "Simon"));
        verify(writer, parameters, "?queryVar=Lars&queryVar=Simon");
        parameters.put("queryVar", "测试");
        verify(writer, parameters, "?queryVar=%E6%B5%8B%E8%AF%95");
        parameters.put("queryVar", "a b");
        verify(writer, parameters, "?queryVar=a+b");
        parameters.put("queryVar", "a+b");
        verify(writer, parameters, "?queryVar=a%2Bb");
    } catch (Exception e) {
        status = false;
    }
    Assert.assertTrue(status);
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) QueryVarParamWriter(org.apache.servicecomb.common.rest.definition.path.QueryVarParamWriter) HashMap(java.util.HashMap) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) MockUp(mockit.MockUp) Test(org.junit.Test)

Aggregations

Parameter (io.swagger.models.parameters.Parameter)2 PathParameter (io.swagger.models.parameters.PathParameter)2 QueryParameter (io.swagger.models.parameters.QueryParameter)2 MockUp (mockit.MockUp)2 QueryVarParamWriter (org.apache.servicecomb.common.rest.definition.path.QueryVarParamWriter)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1