Search in sources :

Example 1 with QueryVarParamWriter

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

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(io.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)

Aggregations

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