Search in sources :

Example 1 with RestLiResponseException

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");
    }
}
Also used : AutoValidationWithProjectionBuilders(com.linkedin.restli.examples.greetings.client.AutoValidationWithProjectionBuilders) CollectionResponse(com.linkedin.restli.common.CollectionResponse) RootBuilderWrapper(com.linkedin.restli.test.util.RootBuilderWrapper) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) ValidationDemo(com.linkedin.restli.examples.greetings.api.ValidationDemo) Test(org.testng.annotations.Test)

Example 2 with RestLiResponseException

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");
    }
}
Also used : AutoValidationWithProjectionBuilders(com.linkedin.restli.examples.greetings.client.AutoValidationWithProjectionBuilders) CollectionResponse(com.linkedin.restli.common.CollectionResponse) RootBuilderWrapper(com.linkedin.restli.test.util.RootBuilderWrapper) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) ValidationDemo(com.linkedin.restli.examples.greetings.api.ValidationDemo) Test(org.testng.annotations.Test)

Example 3 with RestLiResponseException

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();
        }
    }
}
Also used : EmbeddedRestliServer(org.apache.gobblin.restli.EmbeddedRestliServer) RestClient(com.linkedin.restli.client.RestClient) Injector(com.google.inject.Injector) TransportClientAdapter(com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) SharedLimiterKey(org.apache.gobblin.util.limiter.broker.SharedLimiterKey) RestClient(com.linkedin.restli.client.RestClient) Client(com.linkedin.r2.transport.common.Client) HttpClientFactory(com.linkedin.r2.transport.http.client.HttpClientFactory) Test(org.testng.annotations.Test)

Example 4 with RestLiResponseException

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);
}
Also used : RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) Builder(lombok.Builder)

Example 5 with RestLiResponseException

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.");
    }
}
Also used : StringMap(com.linkedin.data.template.StringMap) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) Test(org.testng.annotations.Test)

Aggregations

RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)77 Test (org.testng.annotations.Test)67 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)30 EmptyRecord (com.linkedin.restli.common.EmptyRecord)10 ValidationDemo (com.linkedin.restli.examples.greetings.api.ValidationDemo)10 FlowId (org.apache.gobblin.service.FlowId)10 ExecutionException (java.util.concurrent.ExecutionException)9 StringMap (com.linkedin.data.template.StringMap)8 RestResponse (com.linkedin.r2.message.rest.RestResponse)7 RootBuilderWrapper (com.linkedin.restli.test.util.RootBuilderWrapper)6 FlowConfig (org.apache.gobblin.service.FlowConfig)6 ErrorResponse (com.linkedin.restli.common.ErrorResponse)5 HashMap (java.util.HashMap)5 RemoteInvocationException (com.linkedin.r2.RemoteInvocationException)4 MockRestliResponseExceptionBuilder (com.linkedin.restli.client.testutils.MockRestliResponseExceptionBuilder)4 CollectionResponse (com.linkedin.restli.common.CollectionResponse)4 AutoValidationWithProjectionBuilders (com.linkedin.restli.examples.greetings.client.AutoValidationWithProjectionBuilders)4 CreateGreeting (com.linkedin.restli.examples.greetings.client.CreateGreeting)4 PartialUpdateGreeting (com.linkedin.restli.examples.greetings.client.PartialUpdateGreeting)4 GroupMembershipParam (com.linkedin.restli.examples.groups.api.GroupMembershipParam)4