Search in sources :

Example 41 with TDPException

use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.

the class ErrorMessageTest method shouldReturnRightErrorMessageWhenDatasetStillInUseThrown.

@Test
public void shouldReturnRightErrorMessageWhenDatasetStillInUseThrown() {
    // given
    ErrorCode errorCode = DATASET_STILL_IN_USE;
    // when
    TDPException exception = new TDPException(errorCode, null, null);
    // then
    assertEquals(errorCode, exception.getCode());
    assertEquals("You cannot delete the dataset, it is being used by preparation(s)", exception.getMessage());
    assertEquals("Deletion forbidden", exception.getMessageTitle());
    assertFalse(exception.getContext().entries().iterator().hasNext());
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) ErrorCode(org.talend.daikon.exception.error.ErrorCode) Test(org.junit.Test) ServiceBaseTest(org.talend.ServiceBaseTest)

Example 42 with TDPException

use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.

the class ErrorMessageTest method shouldReturnRightErrorMessageWhenPreparationStepCannotBeDeletedInSingleModeThrown.

@Test
public void shouldReturnRightErrorMessageWhenPreparationStepCannotBeDeletedInSingleModeThrown() {
    // given
    ErrorCode errorCode = PREPARATION_STEP_CANNOT_BE_DELETED_IN_SINGLE_MODE;
    // when
    TDPException exception = new TDPException(errorCode, null, null);
    // then
    assertEquals(errorCode, exception.getCode());
    assertEquals("This action cannot be deleted because subsequent actions depend on it", exception.getMessage());
    assertEquals("Delete action not authorized", exception.getMessageTitle());
    assertFalse(exception.getContext().entries().iterator().hasNext());
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) ErrorCode(org.talend.daikon.exception.error.ErrorCode) Test(org.junit.Test) ServiceBaseTest(org.talend.ServiceBaseTest)

Example 43 with TDPException

use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.

the class ErrorMessageTest method shouldReturnRightErrorMessageWhenUnsupportedContentThrown.

@Test
public void shouldReturnRightErrorMessageWhenUnsupportedContentThrown() {
    // given
    ErrorCode errorCode = UNSUPPORTED_CONTENT;
    // when
    TDPException exception = new TDPException(errorCode, null, null);
    // then
    assertEquals(errorCode, exception.getCode());
    assertEquals("Unable to create dataset, content is not supported. Try with a csv or xls file!", exception.getMessage());
    assertEquals("Unsupported content", exception.getMessageTitle());
    assertFalse(exception.getContext().entries().iterator().hasNext());
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) ErrorCode(org.talend.daikon.exception.error.ErrorCode) Test(org.junit.Test) ServiceBaseTest(org.talend.ServiceBaseTest)

Example 44 with TDPException

use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.

the class DefaultsTest method shouldPipeInputStream_handleIOError.

@Test
public void shouldPipeInputStream_handleIOError() throws Exception {
    // When
    final BasicHttpResponse response = buildResponse();
    response.setEntity(new StringEntity("") {

        @Override
        public InputStream getContent() throws IOException {
            throw new IOException("Unexpected exception");
        }
    });
    try {
        Defaults.pipeStream().apply(buildRequest(), response);
    } catch (TDPException e) {
        // Then
        assertEquals(CommonErrorCodes.UNEXPECTED_EXCEPTION, e.getCode());
    }
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) StringEntity(org.apache.http.entity.StringEntity) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) InputStream(java.io.InputStream) IOException(java.io.IOException) Test(org.junit.Test)

Example 45 with TDPException

use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.

the class DefaultsTest method shoudPassthrough.

@Test
public void shoudPassthrough() throws Exception {
    // Given
    final RuntimeException runtimeException = new RuntimeException();
    final Exception exception = new Exception();
    // When
    try {
        Defaults.passthrough().apply(runtimeException);
    } catch (Exception e) {
        // Then
        assertEquals(runtimeException, e);
    }
    // When
    try {
        Defaults.passthrough().apply(exception);
    } catch (TDPException e) {
        // Then
        assertEquals(CommonErrorCodes.UNEXPECTED_EXCEPTION, e.getCode());
    }
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) TDPException(org.talend.dataprep.exception.TDPException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

TDPException (org.talend.dataprep.exception.TDPException)123 IOException (java.io.IOException)43 InputStream (java.io.InputStream)25 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)21 Test (org.junit.Test)17 ApiOperation (io.swagger.annotations.ApiOperation)16 Timed (org.talend.dataprep.metrics.Timed)14 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 DataSet (org.talend.dataprep.api.dataset.DataSet)13 ServiceBaseTest (org.talend.ServiceBaseTest)11 StringEntity (org.apache.http.entity.StringEntity)10 JsonParser (com.fasterxml.jackson.core.JsonParser)9 URISyntaxException (java.net.URISyntaxException)9 HttpPost (org.apache.http.client.methods.HttpPost)9 Autowired (org.springframework.beans.factory.annotation.Autowired)9 ColumnMetadata (org.talend.dataprep.api.dataset.ColumnMetadata)9 List (java.util.List)8 URIBuilder (org.apache.http.client.utils.URIBuilder)8 Marker (org.slf4j.Marker)8 ErrorCode (org.talend.daikon.exception.error.ErrorCode)8