gitgabrio commented on code in PR #2142: URL: https://github.com/apache/incubator-kie-kogito-apps/pull/2142#discussion_r1837921735
########## jitexecutor/jitexecutor-dmn/src/test/java/org/kie/kogito/jitexecutor/dmn/DMNResourceHelperTest.java: ########## @@ -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); Review Comment: Hi @AthiraHari77 many thanks for the PR! Could you please implement the auto-closeable try-with-resources here ? ########## jitexecutor/jitexecutor-dmn/src/test/java/org/kie/kogito/jitexecutor/dmn/DMNEvaluatorTest.java: ########## @@ -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); Review Comment: What's the need of those mocked instances ? 🤔 ########## jitexecutor/jitexecutor-dmn/src/test/java/org/kie/kogito/jitexecutor/dmn/DMNEvaluatorTest.java: ########## @@ -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)); + + DMNEvaluator evaluator = DMNEvaluator.fromXML(modelXML); + assertNotNull(evaluator); + + } + + @Test + public void testFromXMLModelWithError() { + String modelXML = invalidModel; + when(dmnRuntime.getModels()).thenReturn(Collections.singletonList(dmnModel)); Review Comment: Same comment as above ########## jitexecutor/jitexecutor-dmn/src/test/java/org/kie/kogito/jitexecutor/dmn/DMNResourceHelperTest.java: ########## @@ -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); + 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); Review Comment: Same comment as above (try-with resources) ########## jitexecutor/jitexecutor-dmn/src/test/java/org/kie/kogito/jitexecutor/dmn/DMNEvaluatorTest.java: ########## @@ -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)); Review Comment: What's the need of this mocked `when(dmnRuntime.getModels()).thenReturn(Collections.singletonList(dmnModel));` ? 🤔 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
