-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(TCOMP-2408): all causes of ComponentException are Exception.class (
#706) * feat(TCOMP-2408): all causes of ComponentException are Exception.class --------- Co-authored-by: Emmanuel GALLOIS <[email protected]> Co-authored-by: yyin <[email protected]> Co-authored-by: Axel Catoire <[email protected]>
- Loading branch information
1 parent
d9dfbf0
commit 4386f7c
Showing
8 changed files
with
193 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...nent-api/src/test/java/org/talend/sdk/component/api/exception/ComponentExceptionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* Copyright (C) 2006-2024 Talend Inc. - www.talend.com | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.talend.sdk.component.api.exception; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class ComponentExceptionTest { | ||
|
||
@Test | ||
void testTypedCauseExceptionTransformation() { | ||
IndexOutOfBoundsException indexOutOfBoundsException = new IndexOutOfBoundsException("AAA"); | ||
IllegalArgumentException illegalArgumentException = | ||
new IllegalArgumentException("BBB", indexOutOfBoundsException); | ||
IllegalStateException illegalStateException = new IllegalStateException("CCC", illegalArgumentException); | ||
|
||
ComponentException componentException = new ComponentException("DDD", illegalStateException); | ||
|
||
Throwable ccc = componentException.getCause(); | ||
Assertions.assertEquals(Throwable.class, ccc.getClass()); | ||
|
||
Throwable bbb = ccc.getCause(); | ||
Assertions.assertEquals(Throwable.class, bbb.getClass()); | ||
|
||
Throwable aaa = bbb.getCause(); | ||
Assertions.assertEquals(Throwable.class, aaa.getClass()); | ||
} | ||
|
||
@Test | ||
void testConstructor() { | ||
ComponentException componentException = new ComponentException("message"); | ||
Assertions.assertNull(componentException.getCause()); | ||
} | ||
|
||
@Test | ||
void testParameters() { | ||
ComponentException componentException = new ComponentException(new IndexOutOfBoundsException("cause")); | ||
Assertions.assertNotNull(componentException.getCause()); | ||
Assertions.assertEquals("java.lang.IndexOutOfBoundsException", componentException.getOriginalType()); | ||
Assertions.assertEquals(ComponentException.ErrorOrigin.UNKNOWN, componentException.getErrorOrigin()); | ||
|
||
componentException = new ComponentException(ComponentException.ErrorOrigin.USER, "message"); | ||
Assertions.assertEquals(ComponentException.ErrorOrigin.USER, componentException.getErrorOrigin()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...main/java/org/talend/sdk/component/test/connectors/service/GenerateExceptionServices.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* Copyright (C) 2006-2024 Talend Inc. - www.talend.com | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.talend.sdk.component.test.connectors.service; | ||
|
||
import java.io.Serializable; | ||
import java.lang.reflect.InvocationTargetException; | ||
|
||
import org.talend.sdk.component.api.exception.ComponentException; | ||
import org.talend.sdk.component.api.service.Service; | ||
import org.talend.sdk.component.runtime.base.lang.exception.InvocationExceptionWrapper; | ||
|
||
@Service | ||
public class GenerateExceptionServices implements Serializable { | ||
|
||
public void generateException() throws ComponentException { | ||
IndexOutOfBoundsException indexOutOfBoundsException = | ||
new IndexOutOfBoundsException("This is an index out of bound exception"); | ||
IllegalArgumentException illegalArgumentException = | ||
new IllegalArgumentException("This is an illegal argument exception", indexOutOfBoundsException); | ||
IllegalStateException illegalStateException = | ||
new IllegalStateException("This is an illegal state exception", illegalArgumentException); | ||
throw new ComponentException("This is component exception", illegalStateException); | ||
} | ||
|
||
public void generateRuntimeException() throws ComponentException { | ||
throw InvocationExceptionWrapper | ||
.toRuntimeException(new InvocationTargetException(new CustomException("custom for test"))); | ||
} | ||
|
||
public static class CustomException extends RuntimeException { | ||
|
||
public CustomException(final String message) { | ||
super(message, new AnotherException("other")); | ||
} | ||
} | ||
|
||
public static class AnotherException extends RuntimeException { | ||
|
||
public AnotherException(final String message) { | ||
super(message); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters