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);
}
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);
}
Aggregations