forked from apache/incubator-kie-kogito-apps
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Incubator-kie-issues#1605] DMN JIT Executor successfully executing i…
…nvalid DMN (apache#2142) * [incubator-kie-issues#1605] Added validation checks before model evaluation to handle invalid models * [incubator-kie-issues#1605] WIP * [incubator-kie-issues#1605] Updated test cases * [incubator-kie-issues#1605] Mockito dependency added * [incubator-kie-issues#1605] Fixing imports * [incubator-kie-issues#1605] Fixing review comments * [incubator-kie-issues#1605] Code update for SchemaResource * [incubator-kie-issues#1605] Code update for DMNEvaluator * [incubator-kie-issues#1605] Code refactoring --------- Co-authored-by: athira <athira77@ibm.com>
- Loading branch information
1 parent
2d2ab5a
commit 09037bb
Showing
10 changed files
with
342 additions
and
56 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
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
38 changes: 38 additions & 0 deletions
38
...r/jitexecutor-dmn/src/main/java/org/kie/kogito/jitexecutor/dmn/api/DMNResourceHelper.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,38 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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.kie.kogito.jitexecutor.dmn.api; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import jakarta.ws.rs.core.Response; | ||
|
||
public class DMNResourceHelper { | ||
|
||
private DMNResourceHelper() { | ||
} | ||
|
||
public static Response manageResponse(Supplier<Response> responseSupplier) { | ||
try { | ||
return responseSupplier.get(); | ||
} catch (Exception e) { | ||
String errorMessage = e.getMessage() != null ? e.getMessage() : "Failed to get result due to " + e.getClass().getName(); | ||
return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); | ||
} | ||
} | ||
} |
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
91 changes: 91 additions & 0 deletions
91
...ecutor/jitexecutor-dmn/src/test/java/org/kie/kogito/jitexecutor/dmn/DMNEvaluatorTest.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,91 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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.kie.kogito.jitexecutor.dmn; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
|
||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.kie.dmn.api.core.DMNMessage; | ||
import org.kie.dmn.api.core.DMNModel; | ||
import org.kie.dmn.api.core.DMNRuntime; | ||
import org.kie.dmn.core.impl.DMNRuntimeImpl; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.kie.kogito.jitexecutor.dmn.TestingUtils.getModelFromIoUtils; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class DMNEvaluatorTest { | ||
|
||
private static String model; | ||
private static String invalidModel; | ||
|
||
@BeforeAll | ||
public static void setup() throws IOException { | ||
model = getModelFromIoUtils("invalid_models/DMNv1_x/test.dmn"); | ||
invalidModel = getModelFromIoUtils("invalid_models/DMNv1_5/DMN-Invalid.dmn"); | ||
} | ||
|
||
@Test | ||
void testFromXMLSuccessModel() { | ||
String modelXML = model; | ||
|
||
DMNEvaluator evaluator = DMNEvaluator.fromXML(modelXML); | ||
assertNotNull(evaluator); | ||
} | ||
|
||
@Test | ||
public void testFromXMLModelWithError() { | ||
String modelXML = invalidModel; | ||
|
||
assertThrows(IllegalStateException.class, () -> { | ||
DMNEvaluator.fromXML(modelXML); | ||
}); | ||
} | ||
|
||
@Test | ||
void testValidateForErrorsThrowsException() { | ||
DMNModel dmnModel = mock(DMNModel.class); | ||
DMNRuntime dmnRuntime = mock(DMNRuntime.class); | ||
DMNMessage message = mock(DMNMessage.class); | ||
|
||
String errorMessage = "Error compiling FEEL expression 'Person Age >= 18' for name 'Can Drive?' on node 'Can Drive?': syntax error near 'Age'"; | ||
when(message.getText()).thenReturn(errorMessage); | ||
when(dmnModel.hasErrors()).thenReturn(true); | ||
when(dmnModel.getMessages(DMNMessage.Severity.ERROR)).thenReturn(Collections.singletonList(message)); | ||
|
||
assertThrows(IllegalStateException.class, | ||
() -> DMNEvaluator.validateForErrors(dmnModel, dmnRuntime), errorMessage); | ||
} | ||
|
||
@Test | ||
void testValidateForErrors() { | ||
DMNModel dmnModel = mock(DMNModel.class); | ||
DMNRuntime dmnRuntime = mock(DMNRuntimeImpl.class); | ||
|
||
when(dmnModel.hasErrors()).thenReturn(false); | ||
DMNEvaluator evaluator = DMNEvaluator.validateForErrors(dmnModel, dmnRuntime); | ||
|
||
assertNotNull(evaluator); | ||
} | ||
|
||
} |
Oops, something went wrong.