use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.
the class TestResLiValidationWithProjection method testProjectionWithInvalidFields.
@Test
public void testProjectionWithInvalidFields() throws RemoteInvocationException {
RootBuilderWrapper<Integer, ValidationDemo> wrapper = new RootBuilderWrapper<Integer, ValidationDemo>(new AutoValidationWithProjectionBuilders());
Request<CollectionResponse<ValidationDemo>> request = wrapper.findBy("searchWithProjection").fields(//invalid
ValidationDemo.fields().stringA(), ValidationDemo.fields().stringB(), //invalid
ValidationDemo.fields().includedA(), //invalid
ValidationDemo.fields().UnionFieldWithInlineRecord().MyRecord().foo1(), ValidationDemo.fields().UnionFieldWithInlineRecord().MyRecord().foo2(), ValidationDemo.fields().ArrayWithInlineRecord().items().bar1(), //invalid
ValidationDemo.fields().ArrayWithInlineRecord().items().bar2(), ValidationDemo.fields().MapWithTyperefs().values().id(), //invalid
ValidationDemo.fields().MapWithTyperefs().values().tone(), //invalid
ValidationDemo.fields().validationDemoNext().stringA()).build();
try {
_restClientAuto.sendRequest(request).getResponse();
} catch (RestLiResponseException e) {
Assert.assertEquals(e.getServiceErrorMessage(), "ERROR :: /validationDemoNext/stringA :: length of \"invalid, length is larger than the max\" is out of range 1...10\n" + "ERROR :: /includedA :: length of \"invalid, length is larger than the max\" is out of range 1...10\n" + "ERROR :: /UnionFieldWithInlineRecord/com.linkedin.restli.examples.greetings.api.myRecord/foo1 :: field is required but not found and has no default value\n" + "ERROR :: /ArrayWithInlineRecord/0/bar2 :: field is required but not found and has no default value\n" + "ERROR :: /MapWithTyperefs/foo/tone :: field is required but not found and has no default value\n" + "ERROR :: /stringA :: field is required but not found and has no default value\n");
}
}
use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.
the class TestResLiValidationWithProjection method testNoProjection.
@Test
public void testNoProjection() throws RemoteInvocationException {
RootBuilderWrapper<Integer, ValidationDemo> wrapper = new RootBuilderWrapper<Integer, ValidationDemo>(new AutoValidationWithProjectionBuilders());
Request<CollectionResponse<ValidationDemo>> request = wrapper.findBy("searchWithProjection").build();
try {
_restClientAuto.sendRequest(request).getResponse();
} catch (RestLiResponseException e) {
Assert.assertEquals(e.getServiceErrorMessage(), "ERROR :: /validationDemoNext/UnionFieldWithInlineRecord/com.linkedin.restli.examples.greetings.api.myRecord/foo1 :: field is required but not found and has no default value\n" + "ERROR :: /validationDemoNext/stringA :: length of \"invalid, length is larger than the max\" is out of range 1...10\n" + "ERROR :: /validationDemoNext/ArrayWithInlineRecord/0/bar2 :: field is required but not found and has no default value\n" + "ERROR :: /validationDemoNext/MapWithTyperefs/foo/message :: field is required but not found and has no default value\n" + "ERROR :: /validationDemoNext/MapWithTyperefs/foo/tone :: field is required but not found and has no default value\n" + "ERROR :: /validationDemoNext/stringB :: field is required but not found and has no default value\n" + "ERROR :: /includedA :: length of \"invalid, length is larger than the max\" is out of range 1...10\n" + "ERROR :: /UnionFieldWithInlineRecord/com.linkedin.restli.examples.greetings.api.myRecord/foo1 :: field is required but not found and has no default value\n" + "ERROR :: /ArrayWithInlineRecord/0/bar2 :: field is required but not found and has no default value\n" + "ERROR :: /MapWithTyperefs/foo/message :: field is required but not found and has no default value\n" + "ERROR :: /MapWithTyperefs/foo/tone :: field is required but not found and has no default value\n" + "ERROR :: /stringA :: field is required but not found and has no default value\n");
}
}
use of com.linkedin.restli.client.RestLiResponseException in project incubator-gobblin by apache.
the class ThrottlingClientTest method test.
@Test
public void test() throws Exception {
ThrottlingPolicyFactory factory = new ThrottlingPolicyFactory();
SharedLimiterKey res1key = new SharedLimiterKey("res1");
Map<String, String> configMap = ImmutableMap.<String, String>builder().put(BrokerConfigurationKeyGenerator.generateKey(factory, res1key, null, ThrottlingPolicyFactory.POLICY_KEY), CountBasedPolicy.FACTORY_ALIAS).put(BrokerConfigurationKeyGenerator.generateKey(factory, res1key, null, CountBasedPolicy.COUNT_KEY), "50").put(BrokerConfigurationKeyGenerator.generateKey(factory, null, null, ThrottlingPolicyFactory.FAIL_ON_UNKNOWN_RESOURCE_ID), "true").build();
ThrottlingGuiceServletConfig guiceServletConfig = new ThrottlingGuiceServletConfig();
guiceServletConfig.initialize(ConfigFactory.parseMap(configMap));
Injector injector = guiceServletConfig.getInjector();
EmbeddedRestliServer server = EmbeddedRestliServer.builder().resources(Lists.<Class<? extends BaseResource>>newArrayList(LimiterServerResource.class)).injector(injector).build();
try {
server.startAsync();
server.awaitRunning();
final HttpClientFactory http = new HttpClientFactory();
final Client r2Client = new TransportClientAdapter(http.getClient(Collections.<String, String>emptyMap()));
RestClient restClient = new RestClient(r2Client, server.getURIPrefix());
PermitsGetRequestBuilder getBuilder = new PermitsRequestBuilders().get();
PermitRequest res1request = new PermitRequest();
res1request.setPermits(20);
res1request.setResource(res1key.getResourceLimitedPath());
PermitAllocation allocation = getPermitAllocation(res1request, restClient, getBuilder);
Assert.assertEquals(allocation.getPermits(), new Long(20));
allocation = getPermitAllocation(res1request, restClient, getBuilder);
Assert.assertEquals(allocation.getPermits(), new Long(20));
// out of permits
try {
allocation = getPermitAllocation(res1request, restClient, getBuilder);
Assert.fail();
} catch (RestLiResponseException exc) {
Assert.assertEquals(exc.getStatus(), HttpStatus.S_403_FORBIDDEN.getCode());
}
PermitRequest invalidRequest = new PermitRequest();
invalidRequest.setPermits(20);
invalidRequest.setResource("invalidkey");
try {
allocation = getPermitAllocation(invalidRequest, restClient, getBuilder);
Assert.fail();
} catch (RestLiResponseException exc) {
Assert.assertEquals(exc.getStatus(), 422);
}
} finally {
if (server.isRunning()) {
server.stopAsync();
server.awaitTerminated();
}
}
}
use of com.linkedin.restli.client.RestLiResponseException in project incubator-gobblin by apache.
the class BatchedPermitsRequesterTest method failRequest.
@Builder(builderMethodName = "failRequestBuilder", buildMethodName = "fail")
public static void failRequest(RequestAndCallback requestAndCallback, Throwable exception, HttpStatus errorStatus) {
Throwable actualException;
if (errorStatus != null) {
RestLiResponseException restException = Mockito.mock(RestLiResponseException.class);
Mockito.when(restException.getStatus()).thenReturn(errorStatus.getCode());
actualException = restException;
} else if (exception != null) {
actualException = exception;
} else {
actualException = new RuntimeException();
}
requestAndCallback.callback.onError(actualException);
}
use of com.linkedin.restli.client.RestLiResponseException in project incubator-gobblin by apache.
the class FlowConfigTest method testCreateAgain.
@Test(dependsOnMethods = "testCreate")
public void testCreateAgain() throws Exception {
Map<String, String> flowProperties = Maps.newHashMap();
flowProperties.put("param1", "value1");
FlowConfig flowConfig = new FlowConfig().setId(new FlowId().setFlowGroup(TEST_GROUP_NAME).setFlowName(TEST_FLOW_NAME)).setTemplateUris(TEST_TEMPLATE_URI).setSchedule(new Schedule().setCronSchedule(TEST_SCHEDULE)).setProperties(new StringMap(flowProperties));
try {
_client.createFlowConfig(flowConfig);
} catch (RestLiResponseException e) {
Assert.fail("Create Again should pass without complaining that the spec already exists.");
}
}
Aggregations