use of io.swagger.models.parameters.QueryParameter 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);
}
use of io.swagger.models.parameters.QueryParameter in project java-chassis by ServiceComb.
the class TestPath method testUrlPathBuilder.
@Test
public void testUrlPathBuilder() throws Exception {
Map<String, RestParam> paramMap = new HashMap<>();
Parameter pathParameter = new PathParameter();
pathParameter.setName("id");
RestParam oRestParam = new RestParam(0, pathParameter, int.class);
paramMap.put(oRestParam.getParamName(), oRestParam);
Parameter queryParameter = new QueryParameter();
queryParameter.setName("q");
oRestParam = new RestParam(1, queryParameter, String.class);
paramMap.put(oRestParam.getParamName(), oRestParam);
URLPathBuilder oURLPathBuilder = new URLPathBuilder("/root/{id}", paramMap);
Object[] args = new Object[] { 100, "query" };
Assert.assertEquals("/root/100?q=query", oURLPathBuilder.createRequestPath(args));
Assert.assertEquals("/root/100", oURLPathBuilder.createPathString(args));
}
use of io.swagger.models.parameters.QueryParameter in project swagger-core by swagger-api.
the class ScannerTest method scanBeanParamResource.
@Test(description = "scan a bean param resource")
public void scanBeanParamResource() {
final Swagger swagger = getSwagger(ResourceWithBeanParams.class);
final List<Parameter> params = getParameters(swagger, "/bean/{id}");
final HeaderParameter headerParam1 = (HeaderParameter) params.get(0);
assertEquals(headerParam1.getDefaultValue(), 1);
assertEquals(headerParam1.getName(), "test order annotation 1");
final HeaderParameter headerParam2 = (HeaderParameter) params.get(1);
assertEquals(headerParam2.getDefaultValue(), 2);
assertEquals(headerParam2.getName(), "test order annotation 2");
final QueryParameter priority1 = (QueryParameter) params.get(2);
assertNull(priority1.getDefaultValue());
assertEquals(priority1.getName(), "test priority 1");
final QueryParameter priority2 = (QueryParameter) params.get(3);
assertEquals(priority2.getDefaultValue(), 4);
assertEquals(priority2.getName(), "test priority 2");
final ModelImpl bodyParam1 = (ModelImpl) ((BodyParameter) params.get(4)).getSchema();
assertEquals(bodyParam1.getDefaultValue(), "bodyParam");
}
use of io.swagger.models.parameters.QueryParameter in project swagger-core by swagger-api.
the class ReaderTest method scanBeanValidation.
@Test(description = "it should scan parameters with Swagger and JSR-303 bean validation annotations")
public void scanBeanValidation() {
Swagger swagger = getSwagger(ResourceWithValidation.class);
assertNotNull(swagger);
QueryParameter par = (QueryParameter) swagger.getPaths().get("/303").getOperations().get(0).getParameters().get(0);
assertTrue(par.getRequired());
assertEquals(par.getMinimum(), new BigDecimal(10));
par = (QueryParameter) swagger.getPaths().get("/swagger-and-303").getOperations().get(0).getParameters().get(0);
assertTrue(par.getRequired());
assertEquals(par.getMinimum(), new BigDecimal(7));
par = (QueryParameter) swagger.getPaths().get("/swagger").getOperations().get(0).getParameters().get(0);
assertTrue(par.getRequired());
assertEquals(par.getMinimum(), new BigDecimal(7));
}
use of io.swagger.models.parameters.QueryParameter in project swagger-core by swagger-api.
the class SimpleReaderTest method scanClassWithImplicitExampleQuery.
@Test(description = "scan a resource with implicit operation query example")
public void scanClassWithImplicitExampleQuery() {
Swagger swagger = getSwagger(ClassWithExamplePost.class);
Parameter param = swagger.getPaths().get("/external/info2").getGet().getParameters().get(0);
QueryParameter bp = (QueryParameter) param;
assertNotNull(bp.getExample());
Object value = bp.getExample();
assertEquals("77", value);
}
Aggregations