-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Backport 2.16] Have FlowFrameworkException status recognized by Exce…
…ptionsHelper (#817) Have FlowFrameworkException status recognized by ExceptionsHelper (#811) * Have FlowFrameworkException status recognized by ExceptionsHelper * Add tests --------- (cherry picked from commit 7ec848a) Signed-off-by: Daniel Widdis <[email protected]> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
349db41
commit e28e18a
Showing
4 changed files
with
85 additions
and
1 deletion.
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
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
51 changes: 51 additions & 0 deletions
51
src/test/java/org/opensearch/flowframework/exception/FlowFrameworkExceptionTests.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,51 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
package org.opensearch.flowframework.exception; | ||
|
||
import org.opensearch.ExceptionsHelper; | ||
import org.opensearch.OpenSearchException; | ||
import org.opensearch.common.io.stream.BytesStreamOutput; | ||
import org.opensearch.common.xcontent.json.JsonXContent; | ||
import org.opensearch.core.common.bytes.BytesReference; | ||
import org.opensearch.core.common.io.stream.BytesStreamInput; | ||
import org.opensearch.core.rest.RestStatus; | ||
import org.opensearch.core.xcontent.ToXContent; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
|
||
import java.io.IOException; | ||
|
||
public class FlowFrameworkExceptionTests extends OpenSearchTestCase { | ||
|
||
public void testExceptions() { | ||
WorkflowStepException wse = new WorkflowStepException("WSE", RestStatus.OK); | ||
assertTrue(wse instanceof FlowFrameworkException); | ||
assertTrue(wse instanceof OpenSearchException); | ||
assertEquals(RestStatus.OK, ExceptionsHelper.status(wse)); | ||
assertFalse(wse.isFragment()); | ||
} | ||
|
||
public void testSerialize() throws IOException { | ||
FlowFrameworkException ffe = new FlowFrameworkException("FFE", RestStatus.OK); | ||
assertTrue(ffe instanceof OpenSearchException); | ||
assertEquals(RestStatus.OK, ExceptionsHelper.status(ffe)); | ||
|
||
try (BytesStreamOutput out = new BytesStreamOutput()) { | ||
ffe.writeTo(out); | ||
try (BytesStreamInput in = new BytesStreamInput(BytesReference.toBytes(out.bytes()))) { | ||
ffe = new FlowFrameworkException(in); | ||
assertTrue(ffe instanceof OpenSearchException); | ||
assertEquals(RestStatus.OK, ExceptionsHelper.status(ffe)); | ||
} | ||
} | ||
|
||
XContentBuilder builder = JsonXContent.contentBuilder(); | ||
assertEquals("{\"error\":\"FFE\"}", ffe.toXContent(builder, ToXContent.EMPTY_PARAMS).toString()); | ||
} | ||
} |