Search in sources :

Example 51 with RestLiResponseException

use of com.linkedin.restli.client.RestLiResponseException in project incubator-gobblin by apache.

the class GobblinServiceManagerTest method testBadUpdate.

@Test
public void testBadUpdate() throws Exception {
    Map<String, String> flowProperties = Maps.newHashMap();
    flowProperties.put("param1", "value1b");
    flowProperties.put("param2", "value2b");
    FlowConfig flowConfig = new FlowConfig().setId(new FlowId().setFlowGroup(TEST_DUMMY_GROUP_NAME).setFlowName(TEST_DUMMY_FLOW_NAME)).setTemplateUris(TEST_TEMPLATE_URI).setSchedule(new Schedule().setCronSchedule(TEST_SCHEDULE)).setProperties(new StringMap(flowProperties));
    try {
        this.flowConfigClient.updateFlowConfig(flowConfig);
    } catch (RestLiResponseException e) {
        Assert.fail("Bad update should pass without complaining that the spec does not exists.");
    }
    cleanUpDir(FLOW_SPEC_STORE_DIR);
}
Also used : FlowConfig(org.apache.gobblin.service.FlowConfig) FlowId(org.apache.gobblin.service.FlowId) StringMap(com.linkedin.data.template.StringMap) Schedule(org.apache.gobblin.service.Schedule) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) Test(org.testng.annotations.Test)

Example 52 with RestLiResponseException

use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.

the class TestNullGreetingsClient method sendUpdateAndAssert.

private void sendUpdateAndAssert(final RootBuilderWrapper<Long, Greeting> builders, Long id) throws RemoteInvocationException {
    try {
        final Greeting someGreeting = new Greeting().setMessage("Hello").setTone(Tone.INSULTING);
        getClient().sendRequest(builders.update().id(id).input(someGreeting).build()).getResponse();
    } catch (final RestLiResponseException responseException) {
        assertCorrectInternalServerMessageForNull(responseException, "update");
    }
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException)

Example 53 with RestLiResponseException

use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.

the class TestGroupsClient method testAssociationCreateGetDelete.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestMembershipsBuilderDataProvider")
public void testAssociationCreateGetDelete(ProtocolVersion version, RootBuilderWrapper<CompoundKey, GroupMembership> membershipBuilders) throws RemoteInvocationException {
    // Setup - create group memberships
    CompoundKey key1 = buildCompoundKey(1, 1);
    GroupMembership groupMembership1 = buildGroupMembership(null, "alfred@test.linkedin.com", "Alfred", "Hitchcock");
    Response<EmptyRecord> response = getClient().sendRequest(membershipBuilders.update().id(key1).input(groupMembership1).build()).getResponse();
    Assert.assertEquals(response.getStatus(), 204);
    // Get membership
    Request<GroupMembership> getRequest = membershipBuilders.get().id(key1).fields(GroupMembership.fields().contactEmail()).build();
    GroupMembership groupMembership = getClient().sendRequest(getRequest).getResponse().getEntity();
    Assert.assertEquals(groupMembership.getContactEmail(), "alfred@test.linkedin.com");
    // Delete the newly created group membership
    Response<EmptyRecord> deleteResponse = getClient().sendRequest(membershipBuilders.delete().id(key1).build()).getResponse();
    Assert.assertEquals(deleteResponse.getStatus(), 204);
    // Make sure it is gone
    try {
        getClient().sendRequest(getRequest).getResponse();
    } catch (RestLiResponseException e) {
        Assert.assertEquals(e.getStatus(), 404);
    }
}
Also used : EmptyRecord(com.linkedin.restli.common.EmptyRecord) CompoundKey(com.linkedin.restli.common.CompoundKey) GroupMembership(com.linkedin.restli.examples.groups.api.GroupMembership) ComplexKeyGroupMembership(com.linkedin.restli.examples.groups.api.ComplexKeyGroupMembership) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) Test(org.testng.annotations.Test)

Example 54 with RestLiResponseException

use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.

the class TestGroupsClient method testDefaultValue.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestGroupsBuilderDataProvider")
public void testDefaultValue(RootBuilderWrapper<Integer, Group> groupBuilders) throws RemoteInvocationException {
    // use server side default value for the RecordTemplate
    getClient().sendRequest(groupBuilders.findBy("ComplexCircuit").build()).getResponse();
    try {
        // specifying an instance of the RecordTemplate which mismatches the default will fail the request
        final GroupMembershipParam newValue = new GroupMembershipParam();
        newValue.setIntParameter(0);
        newValue.setStringParameter("fail");
        getClient().sendRequest(groupBuilders.findBy("ComplexCircuit").setQueryParam("record", newValue).build()).getResponse();
        Assert.fail("Expect exception when specifying the \"record\" query parameter different from the default");
    } catch (RestLiResponseException e) {
        Assert.assertEquals(e.getStatus(), 500);
    }
}
Also used : GroupMembershipParam(com.linkedin.restli.examples.groups.api.GroupMembershipParam) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) Test(org.testng.annotations.Test)

Example 55 with RestLiResponseException

use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.

the class TestMaxBatchSize method testBatchPartialUpdateWithMaxBatchSizeBeyondLimitation.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testBatchPartialUpdateWithMaxBatchSizeBeyondLimitation(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    Greeting patchedGreetingOne = new Greeting().setTone(Tone.INSULTING).setId(1l).setMessage("Hello");
    Greeting patchedGreetingTwo = new Greeting().setTone(Tone.FRIENDLY).setId(2l).setMessage("Hi");
    Greeting patchedGreetingThree = new Greeting().setTone(Tone.SINCERE).setId(3l).setMessage("Hello world");
    Map<Long, PatchRequest<Greeting>> patchInputs = new HashMap<>();
    patchInputs.put(1l, PatchGenerator.diff(GREETING_ONE, patchedGreetingOne));
    patchInputs.put(2l, PatchGenerator.diff(GREETING_TWO, patchedGreetingTwo));
    patchInputs.put(3l, PatchGenerator.diff(GREETING_THREE, patchedGreetingThree));
    Request<BatchKVResponse<Long, UpdateStatus>> request = builders.batchPartialUpdate().patchInputs(patchInputs).build();
    try {
        getClient().sendRequest(request).getResponse();
        Assert.fail("The batch size is larger than the allowed max batch size should cause an exception.");
    } catch (RestLiResponseException e) {
        Assert.assertEquals(e.getStatus(), HttpStatus.S_400_BAD_REQUEST.getCode());
        Assert.assertEquals(e.getServiceErrorMessage(), "The request batch size: " + "3 is larger than the allowed max batch size: 2 for method: batch_partial_update");
    }
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) HashMap(java.util.HashMap) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) PatchRequest(com.linkedin.restli.common.PatchRequest) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) Test(org.testng.annotations.Test)

Aggregations

RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)85 Test (org.testng.annotations.Test)75 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)30 StringMap (com.linkedin.data.template.StringMap)15 FlowId (org.apache.gobblin.service.FlowId)11 EmptyRecord (com.linkedin.restli.common.EmptyRecord)10 ValidationDemo (com.linkedin.restli.examples.greetings.api.ValidationDemo)10 ExecutionException (java.util.concurrent.ExecutionException)9 RestResponse (com.linkedin.r2.message.rest.RestResponse)7 FlowConfig (org.apache.gobblin.service.FlowConfig)7 RootBuilderWrapper (com.linkedin.restli.test.util.RootBuilderWrapper)6 ErrorResponse (com.linkedin.restli.common.ErrorResponse)5 HashMap (java.util.HashMap)5 Schedule (org.apache.gobblin.service.Schedule)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