-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Incubator-kie-issues#1605] DMN JIT Executor successfully executing invalid DMN #2142
Changes from 6 commits
2e5f189
925065d
ebdfa70
6941c6f
cb02ef4
d9f1ac9
38e0887
17e787a
4077c03
57b5dad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* 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 org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.kie.dmn.api.core.DMNModel; | ||
import org.kie.dmn.api.core.DMNRuntime; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
|
||
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; | ||
private static DMNRuntime dmnRuntime; | ||
private static DMNModel dmnModel; | ||
|
||
@BeforeAll | ||
public static void setup() throws IOException { | ||
model = getModelFromIoUtils("invalid_models/DMNv1_x/test.dmn"); | ||
invalidModel = getModelFromIoUtils("invalid_models/DMNv1_5/DMN-Invalid.dmn"); | ||
dmnRuntime = mock(DMNRuntime.class); | ||
dmnModel = mock(DMNModel.class); | ||
} | ||
|
||
@Test | ||
void testFromXMLSuccessModel() { | ||
String modelXML = model; | ||
when(dmnRuntime.getModels()).thenReturn(Collections.singletonList(dmnModel)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the need of this mocked |
||
|
||
DMNEvaluator evaluator = DMNEvaluator.fromXML(modelXML); | ||
assertNotNull(evaluator); | ||
|
||
} | ||
|
||
@Test | ||
public void testFromXMLModelWithError() { | ||
String modelXML = invalidModel; | ||
when(dmnRuntime.getModels()).thenReturn(Collections.singletonList(dmnModel)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above |
||
|
||
assertThrows(IllegalStateException.class, () -> { | ||
DMNEvaluator.fromXML(modelXML); | ||
}); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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.util.function.Supplier; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.kie.kogito.jitexecutor.dmn.api.DMNResourceHelper; | ||
|
||
import jakarta.ws.rs.core.Response; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class DMNResourceHelperTest { | ||
|
||
@Test | ||
public void testManageResponseWithSuccess() { | ||
Supplier<Response> responseSupplier = () -> Response.ok("Success").build(); | ||
Response response = DMNResourceHelper.manageResponse(responseSupplier); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @AthiraHari77 |
||
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); | ||
assertEquals("Success", response.getEntity()); | ||
} | ||
|
||
@Test | ||
public void testManageResponseWithFailure() { | ||
Supplier<Response> responseSupplier = mock(Supplier.class); | ||
when(responseSupplier.get()).thenThrow(new IllegalStateException("Error : Failed to validate")); | ||
Response response = DMNResourceHelper.manageResponse(responseSupplier); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above (try-with resources) |
||
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); | ||
assertEquals("Error : Failed to validate", response.getEntity()); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the need of those mocked instances ? 🤔