Search in sources :

Example 91 with QueryParameter

use of io.swagger.models.parameters.QueryParameter in project incubator-servicecomb-java-chassis by apache.

the class TestQueryProcessorCreator method testCreateNullAsEmpty.

@SuppressWarnings("UnusedAssignment")
@Test
public void testCreateNullAsEmpty() throws Exception {
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    ArchaiusUtils.setProperty("servicecomb.rest.parameter.query.emptyAsNull", "true");
    ParamValueProcessorCreator creator = ParamValueProcessorCreatorManager.INSTANCE.findValue(QueryProcessorCreator.PARAMTYPE);
    Parameter parameter = new QueryParameter();
    parameter.setName("query");
    ParamValueProcessor processor = creator.create(parameter, String.class);
    Assert.assertEquals(QueryProcessor.class, processor.getClass());
    Mockito.when(request.getParameter("query")).thenReturn("Hello");
    String result = (String) processor.getValue(request);
    Assert.assertEquals("Hello", result);
    Mockito.when(request.getParameter("query")).thenReturn("");
    result = (String) processor.getValue(request);
    Assert.assertEquals(null, result);
    Mockito.when(request.getParameter("query")).thenReturn(null);
    result = (String) processor.convertValue(null, TypeFactory.defaultInstance().constructType(String.class));
    result = (String) processor.getValue(request);
    Assert.assertEquals(null, result);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) QueryParameter(io.swagger.models.parameters.QueryParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) Test(org.junit.Test)

Example 92 with QueryParameter

use of io.swagger.models.parameters.QueryParameter in project incubator-servicecomb-java-chassis by apache.

the class QueryVarParamWriterTest method beforeClass.

@BeforeClass
public static void beforeClass() {
    QueryParameter parameter = new QueryParameter();
    parameter.setName("q");
    parameter.setCollectionFormat("csv");
    queryVarParamWriterCsv = new QueryVarParamWriter(new RestParam(parameter, String[].class));
    parameter = new QueryParameter();
    parameter.setName("q");
    parameter.setCollectionFormat("multi");
    queryVarParamWriterMulti = new QueryVarParamWriter(new RestParam(parameter, String[].class));
    parameter = new QueryParameter();
    parameter.setName("q");
    queryVarParamWriterDefault = new QueryVarParamWriter(new RestParam(parameter, String[].class));
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) RestParam(org.apache.servicecomb.common.rest.definition.RestParam) BeforeClass(org.junit.BeforeClass)

Aggregations

QueryParameter (io.swagger.models.parameters.QueryParameter)92 Test (org.testng.annotations.Test)58 Parameter (io.swagger.models.parameters.Parameter)42 PathParameter (io.swagger.models.parameters.PathParameter)34 BodyParameter (io.swagger.models.parameters.BodyParameter)28 Swagger (io.swagger.models.Swagger)25 HeaderParameter (io.swagger.models.parameters.HeaderParameter)15 Test (org.junit.Test)12 Operation (io.swagger.models.Operation)11 FormParameter (io.swagger.models.parameters.FormParameter)11 SerializableParameter (io.swagger.models.parameters.SerializableParameter)10 StringProperty (io.swagger.models.properties.StringProperty)10 HashMap (java.util.HashMap)10 Path (io.swagger.models.Path)9 RefModel (io.swagger.models.RefModel)9 Type (java.lang.reflect.Type)9 BigDecimal (java.math.BigDecimal)9 RefProperty (io.swagger.models.properties.RefProperty)8 Response (io.swagger.models.Response)7 Method (java.lang.reflect.Method)7