Search in sources :

Example 46 with RestLiResponseException

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

the class FlowConfigTest method testCreateBadTemplateUri.

@Test
public void testCreateBadTemplateUri() 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("FILE://bad/uri").setSchedule(new Schedule().setCronSchedule(TEST_SCHEDULE).setRunImmediately(true)).setProperties(new StringMap(flowProperties));
    try {
        _client.createFlowConfig(flowConfig);
    } catch (RestLiResponseException e) {
        Assert.assertEquals(e.getStatus(), HttpStatus.S_422_UNPROCESSABLE_ENTITY.getCode());
        return;
    }
    Assert.fail("Get should have gotten a 422 error");
}
Also used : StringMap(com.linkedin.data.template.StringMap) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) Test(org.testng.annotations.Test)

Example 47 with RestLiResponseException

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

the class FlowConfigTest 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 {
        _client.updateFlowConfig(flowConfig);
    } catch (RestLiResponseException e) {
        Assert.assertEquals(e.getStatus(), HttpStatus.S_404_NOT_FOUND.getCode());
        return;
    }
    Assert.fail("Update should have raised a 404 error");
}
Also used : StringMap(com.linkedin.data.template.StringMap) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) Test(org.testng.annotations.Test)

Example 48 with RestLiResponseException

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

the class FlowConfigV2Test method testInvalidFlowId.

@Test
public void testInvalidFlowId() throws Exception {
    Map<String, String> flowProperties = Maps.newHashMap();
    flowProperties.put("param1", "value1");
    StringBuilder sb1 = new StringBuilder();
    StringBuilder sb2 = new StringBuilder();
    int maxFlowNameLength = ServiceConfigKeys.MAX_FLOW_NAME_LENGTH;
    int maxFlowGroupLength = ServiceConfigKeys.MAX_FLOW_GROUP_LENGTH;
    while (maxFlowGroupLength-- >= 0) {
        sb1.append("A");
    }
    while (maxFlowNameLength-- >= 0) {
        sb2.append("A");
    }
    String TOO_LONG_FLOW_GROUP = sb1.toString();
    String TOO_LONG_FLOW_NAME = sb2.toString();
    FlowConfig flowConfig = new FlowConfig().setId(new FlowId().setFlowGroup(TOO_LONG_FLOW_GROUP).setFlowName(TOO_LONG_FLOW_NAME)).setTemplateUris(TEST_TEMPLATE_URI).setProperties(new StringMap(flowProperties));
    try {
        _client.createFlowConfig(flowConfig);
    } catch (RestLiResponseException e) {
        Assert.assertEquals(e.getStatus(), HttpStatus.ORDINAL_422_Unprocessable_Entity);
        Assert.assertTrue(e.getMessage().contains("is out of range"));
        return;
    }
    Assert.fail();
}
Also used : StringMap(com.linkedin.data.template.StringMap) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) Test(org.testng.annotations.Test)

Example 49 with RestLiResponseException

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

the class FlowConfigV2Test method testDisallowedRequester.

@Test
public void testDisallowedRequester() throws Exception {
    try {
        ServiceRequester testRequester = new ServiceRequester("testName", "testType", "testFrom");
        _requesterService.setRequester(testRequester);
        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_4)).setTemplateUris(TEST_TEMPLATE_URI).setProperties(new StringMap(flowProperties));
        _client.createFlowConfig(flowConfig);
        testRequester.setName("testName2");
        _client.deleteFlowConfig(new FlowId().setFlowGroup(TEST_GROUP_NAME).setFlowName(TEST_FLOW_NAME_4));
    } catch (RestLiResponseException e) {
        Assert.assertEquals(e.getStatus(), HttpStatus.ORDINAL_401_Unauthorized);
    }
}
Also used : StringMap(com.linkedin.data.template.StringMap) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) Test(org.testng.annotations.Test)

Example 50 with RestLiResponseException

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

the class FlowConfigV2Test method testRequesterUpdateRejected.

@Test
public void testRequesterUpdateRejected() throws Exception {
    _requesterService.setRequester(TEST_REQUESTER);
    Map<String, String> flowProperties = Maps.newHashMap();
    FlowConfig flowConfig = new FlowConfig().setId(new FlowId().setFlowGroup(TEST_GROUP_NAME).setFlowName(TEST_FLOW_NAME_9)).setTemplateUris(TEST_TEMPLATE_URI).setProperties(new StringMap(flowProperties));
    _client.createFlowConfig(flowConfig);
    // Update should be rejected because testName is not allowed to update the owner to testName2
    flowProperties.put(RequesterService.REQUESTER_LIST, RequesterService.serialize(Lists.newArrayList(TEST_REQUESTER2)));
    flowConfig.setProperties(new StringMap(flowProperties));
    try {
        _client.updateFlowConfig(flowConfig);
        Assert.fail("Expected update to be rejected");
    } catch (RestLiResponseException e) {
        Assert.assertEquals(e.getStatus(), HttpStatus.ORDINAL_401_Unauthorized);
    }
}
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)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