use of org.apache.servicecomb.common.rest.definition.RestParam in project incubator-servicecomb-java-chassis by apache.
the class TestRestCodec method testRestToArgsInstanceExcetpion.
@Test
public void testRestToArgsInstanceExcetpion(@Mocked HttpServletRequest request, @Mocked RestOperationMeta restOperation, @Mocked RestParam restParam, @Mocked ParamValueProcessor processer) throws Exception {
List<RestParam> params = new ArrayList<>();
params.add(restParam);
InvocationException exception = new InvocationException(Status.BAD_REQUEST, "Parameter is not valid.");
new Expectations() {
{
restOperation.getParamList();
result = params;
restParam.getParamProcessor();
result = processer;
processer.getValue(request);
result = exception;
}
};
boolean success = false;
try {
RestCodec.restToArgs(request, restOperation);
success = true;
} catch (InvocationException e) {
Assert.assertEquals(e.getStatusCode(), Status.BAD_REQUEST.getStatusCode());
}
Assert.assertEquals(success, false);
}
use of org.apache.servicecomb.common.rest.definition.RestParam in project incubator-servicecomb-java-chassis by apache.
the class RestCodec method argsToRest.
public static void argsToRest(Object[] args, RestOperationMeta restOperation, RestClientRequest clientRequest) throws Exception {
int paramSize = restOperation.getParamList().size();
if (paramSize == 0) {
return;
}
if (paramSize != args.length) {
throw new Exception("wrong number of arguments");
}
for (int idx = 0; idx < paramSize; idx++) {
RestParam param = restOperation.getParamList().get(idx);
param.getParamProcessor().setValue(clientRequest, args[idx]);
}
}
use of org.apache.servicecomb.common.rest.definition.RestParam in project incubator-servicecomb-java-chassis by apache.
the class InvocationToHttpServletRequest method getParameter.
@Override
public String getParameter(String name) {
RestParam param = swaggerOperation.getParamByName(name);
if (param == null) {
return null;
}
Object value = param.getValue(args);
if (value == null) {
return null;
}
return String.valueOf(value);
}
use of org.apache.servicecomb.common.rest.definition.RestParam in project incubator-servicecomb-java-chassis by apache.
the class TestRestCodec method beforeClass.
@BeforeClass
public static void beforeClass() {
restOperation = Mockito.mock(RestOperationMeta.class);
// clientRequest = Mockito.mock(RestClientRequest.class);
paramList = new ArrayList<>();
Parameter hp = new HeaderParameter();
hp.setName("header");
paramList.add(new RestParam(0, hp, int.class));
when(restOperation.getParamList()).thenReturn(paramList);
}
use of org.apache.servicecomb.common.rest.definition.RestParam in project incubator-servicecomb-java-chassis by apache.
the class TestRestCodec method testRestToArgsExcetpion.
@Test
public void testRestToArgsExcetpion(@Mocked HttpServletRequest request, @Mocked RestOperationMeta restOperation, @Mocked RestParam restParam, @Mocked ParamValueProcessor processer) throws Exception {
List<RestParam> params = new ArrayList<>();
params.add(restParam);
new Expectations() {
{
restOperation.getParamList();
result = params;
restParam.getParamProcessor();
result = processer;
processer.getValue(request);
result = new Exception("bad request parame");
}
};
boolean success = false;
try {
RestCodec.restToArgs(request, restOperation);
success = true;
} catch (InvocationException e) {
Assert.assertEquals(590, e.getStatusCode());
Assert.assertEquals("Parameter is not valid.", ((CommonExceptionData) e.getErrorData()).getMessage());
}
Assert.assertEquals(success, false);
}
Aggregations