From b02986398c26fbc893fce5378b5827406715ecdc Mon Sep 17 00:00:00 2001 From: Octavian Patrascoiu Date: Fri, 24 May 2024 11:33:21 +0100 Subject: [PATCH] [#665] Add builder pattern for ExecutionContext --- .../com/gs/dmn/runtime/ExecutionContext.java | 8 +++ .../dmn/runtime/ExecutionContextBuilder.java | 59 +++++++++++++++++++ .../runtime/ExecutionContextBuilderTest.java | 45 ++++++++++++++ .../AbstractHandwrittenDecisionTest.java | 8 +-- .../PostorderTraceListenerTest.java | 6 +- .../TreeTraceListenerTest.java | 7 +-- .../HandwrittenGenerateOutputDataTest.java | 2 - .../AbstractHandwrittenDecisionTest.java | 8 +-- .../PostorderTraceListenerTest.java | 6 +- .../TreeTraceListenerTest.java | 7 +-- .../tck/AbstractHandwrittenDecisionTest.java | 18 +----- .../PostorderTraceListenerTest.java | 8 +-- .../TreeTraceListenerTest.java | 10 ++-- .../dmn/AbstractHandwrittenDecisionTest.java | 18 +----- .../PostorderTraceListenerTest.java | 8 +-- .../TreeTraceListenerTest.java | 10 ++-- 16 files changed, 144 insertions(+), 84 deletions(-) create mode 100644 dmn-runtime/src/main/java/com/gs/dmn/runtime/ExecutionContextBuilder.java create mode 100644 dmn-runtime/src/test/java/com/gs/dmn/runtime/ExecutionContextBuilderTest.java diff --git a/dmn-runtime/src/main/java/com/gs/dmn/runtime/ExecutionContext.java b/dmn-runtime/src/main/java/com/gs/dmn/runtime/ExecutionContext.java index 297b17a45..227e1e99b 100644 --- a/dmn-runtime/src/main/java/com/gs/dmn/runtime/ExecutionContext.java +++ b/dmn-runtime/src/main/java/com/gs/dmn/runtime/ExecutionContext.java @@ -30,6 +30,10 @@ public class ExecutionContext { private final ExternalFunctionExecutor externalFunctionExecutor; private final Cache cache; + /** + * @deprecated As of release 8.4.0, replaced by {@link ExecutionContextBuilder} + */ + @Deprecated public ExecutionContext() { this.annotations = new AnnotationSet(); this.eventListener = new LoggingEventListener(LOGGER); @@ -37,6 +41,10 @@ public ExecutionContext() { this.cache = new DefaultCache(); } + /** + * @deprecated As of release 8.4.0, replaced by {@link ExecutionContextBuilder} + */ + @Deprecated public ExecutionContext(AnnotationSet annotations, EventListener eventListener, ExternalFunctionExecutor externalFunctionExecutor, Cache cache) { this.annotations = annotations; this.eventListener = eventListener; diff --git a/dmn-runtime/src/main/java/com/gs/dmn/runtime/ExecutionContextBuilder.java b/dmn-runtime/src/main/java/com/gs/dmn/runtime/ExecutionContextBuilder.java new file mode 100644 index 000000000..7db24899d --- /dev/null +++ b/dmn-runtime/src/main/java/com/gs/dmn/runtime/ExecutionContextBuilder.java @@ -0,0 +1,59 @@ +/* + * Copyright 2016 Goldman Sachs. + * + * 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 com.gs.dmn.runtime; + +import com.gs.dmn.runtime.annotation.AnnotationSet; +import com.gs.dmn.runtime.cache.Cache; +import com.gs.dmn.runtime.cache.DefaultCache; +import com.gs.dmn.runtime.external.DefaultExternalFunctionExecutor; +import com.gs.dmn.runtime.external.ExternalFunctionExecutor; +import com.gs.dmn.runtime.listener.EventListener; +import com.gs.dmn.runtime.listener.NopEventListener; + +public final class ExecutionContextBuilder { + private AnnotationSet annotations = new AnnotationSet(); + private EventListener eventListener = new NopEventListener(); + private ExternalFunctionExecutor externalFunctionExecutor = new DefaultExternalFunctionExecutor(); + private Cache cache = new DefaultCache(); + + private ExecutionContextBuilder() { + } + + public static ExecutionContextBuilder executionContext() { + return new ExecutionContextBuilder(); + } + + public ExecutionContextBuilder withAnnotations(AnnotationSet annotations) { + this.annotations = annotations; + return this; + } + + public ExecutionContextBuilder withEventListener(EventListener eventListener) { + this.eventListener = eventListener; + return this; + } + + public ExecutionContextBuilder withExternalFunctionExecutor(ExternalFunctionExecutor externalFunctionExecutor) { + this.externalFunctionExecutor = externalFunctionExecutor; + return this; + } + + public ExecutionContextBuilder withCache(Cache cache) { + this.cache = cache; + return this; + } + + public ExecutionContext build() { + return new ExecutionContext(annotations, eventListener, externalFunctionExecutor, cache); + } +} diff --git a/dmn-runtime/src/test/java/com/gs/dmn/runtime/ExecutionContextBuilderTest.java b/dmn-runtime/src/test/java/com/gs/dmn/runtime/ExecutionContextBuilderTest.java new file mode 100644 index 000000000..477ce23ab --- /dev/null +++ b/dmn-runtime/src/test/java/com/gs/dmn/runtime/ExecutionContextBuilderTest.java @@ -0,0 +1,45 @@ +/* + * Copyright 2016 Goldman Sachs. + * + * 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 com.gs.dmn.runtime; + +import com.gs.dmn.runtime.annotation.AnnotationSet; +import com.gs.dmn.runtime.cache.Cache; +import com.gs.dmn.runtime.cache.DefaultCache; +import com.gs.dmn.runtime.external.DefaultExternalFunctionExecutor; +import com.gs.dmn.runtime.external.ExternalFunctionExecutor; +import com.gs.dmn.runtime.listener.EventListener; +import com.gs.dmn.runtime.listener.NopEventListener; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class ExecutionContextBuilderTest { + @Test + void testBuild() { + AnnotationSet annotations = new AnnotationSet(); + EventListener eventListener = new NopEventListener(); + ExternalFunctionExecutor externalFunctionExecutor = new DefaultExternalFunctionExecutor(); + Cache cache = new DefaultCache(); + ExecutionContext context = ExecutionContextBuilder.executionContext(). + withAnnotations(annotations). + withEventListener(eventListener). + withExternalFunctionExecutor(externalFunctionExecutor). + withCache(cache). + build(); + + assertEquals(annotations, context.getAnnotations()); + assertEquals(eventListener, context.getEventListener()); + assertEquals(externalFunctionExecutor, context.getExternalFunctionExecutor()); + assertEquals(cache, context.getCache()); + } +} \ No newline at end of file diff --git a/dmn-signavio-it/dmn-signavio-it-kotlin-translator/src/test/java/com/gs/dmn/generated/AbstractHandwrittenDecisionTest.java b/dmn-signavio-it/dmn-signavio-it-kotlin-translator/src/test/java/com/gs/dmn/generated/AbstractHandwrittenDecisionTest.java index dc20c1ef7..833e0c72c 100644 --- a/dmn-signavio-it/dmn-signavio-it-kotlin-translator/src/test/java/com/gs/dmn/generated/AbstractHandwrittenDecisionTest.java +++ b/dmn-signavio-it/dmn-signavio-it-kotlin-translator/src/test/java/com/gs/dmn/generated/AbstractHandwrittenDecisionTest.java @@ -14,10 +14,8 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.gs.dmn.runtime.ExecutionContext; +import com.gs.dmn.runtime.ExecutionContextBuilder; import com.gs.dmn.runtime.annotation.AnnotationSet; -import com.gs.dmn.runtime.cache.DefaultCache; -import com.gs.dmn.runtime.external.DefaultExternalFunctionExecutor; -import com.gs.dmn.runtime.listener.NopEventListener; import com.gs.dmn.serialization.JsonSerializer; import org.junit.jupiter.api.BeforeEach; @@ -37,7 +35,7 @@ protected String toJson(Object object) { @BeforeEach public void setUp() { - this.annotationSet = new AnnotationSet(); - this.context = new ExecutionContext(annotationSet, new NopEventListener(), new DefaultExternalFunctionExecutor(), new DefaultCache()); + this.context = ExecutionContextBuilder.executionContext().build(); + this.annotationSet = context.getAnnotations(); } } diff --git a/dmn-signavio-it/dmn-signavio-it-kotlin-translator/src/test/java/com/gs/dmn/generated/example_credit_decision/PostorderTraceListenerTest.java b/dmn-signavio-it/dmn-signavio-it-kotlin-translator/src/test/java/com/gs/dmn/generated/example_credit_decision/PostorderTraceListenerTest.java index 03a32250e..8c14ef464 100644 --- a/dmn-signavio-it/dmn-signavio-it-kotlin-translator/src/test/java/com/gs/dmn/generated/example_credit_decision/PostorderTraceListenerTest.java +++ b/dmn-signavio-it/dmn-signavio-it-kotlin-translator/src/test/java/com/gs/dmn/generated/example_credit_decision/PostorderTraceListenerTest.java @@ -16,9 +16,7 @@ import com.gs.dmn.generated.example_credit_decision.type.ApplicantImpl; import com.gs.dmn.runtime.Assert; import com.gs.dmn.runtime.ExecutionContext; -import com.gs.dmn.runtime.annotation.AnnotationSet; -import com.gs.dmn.runtime.cache.DefaultCache; -import com.gs.dmn.runtime.external.DefaultExternalFunctionExecutor; +import com.gs.dmn.runtime.ExecutionContextBuilder; import com.gs.dmn.runtime.listener.PostorderTraceEventListener; import com.gs.dmn.runtime.listener.node.DRGElementNode; import org.junit.jupiter.api.Test; @@ -68,7 +66,7 @@ public void testListenerWithFilter() throws Exception { } private List applyDecision(Applicant toApplicant, BigDecimal currentRiskAppetite, BigDecimal lendingThreshold, PostorderTraceEventListener listener) { - ExecutionContext context = new ExecutionContext(new AnnotationSet(), listener, new DefaultExternalFunctionExecutor(), new DefaultCache()); + ExecutionContext context = ExecutionContextBuilder.executionContext().withEventListener(listener).build(); return decision.apply(toApplicant, currentRiskAppetite, lendingThreshold, context); } diff --git a/dmn-signavio-it/dmn-signavio-it-kotlin-translator/src/test/java/com/gs/dmn/generated/example_credit_decision/TreeTraceListenerTest.java b/dmn-signavio-it/dmn-signavio-it-kotlin-translator/src/test/java/com/gs/dmn/generated/example_credit_decision/TreeTraceListenerTest.java index 75c33e30d..b36c2f045 100644 --- a/dmn-signavio-it/dmn-signavio-it-kotlin-translator/src/test/java/com/gs/dmn/generated/example_credit_decision/TreeTraceListenerTest.java +++ b/dmn-signavio-it/dmn-signavio-it-kotlin-translator/src/test/java/com/gs/dmn/generated/example_credit_decision/TreeTraceListenerTest.java @@ -15,10 +15,7 @@ import com.gs.dmn.generated.example_credit_decision.type.Applicant; import com.gs.dmn.generated.example_credit_decision.type.ApplicantImpl; import com.gs.dmn.runtime.Assert; -import com.gs.dmn.runtime.ExecutionContext; -import com.gs.dmn.runtime.annotation.AnnotationSet; -import com.gs.dmn.runtime.cache.DefaultCache; -import com.gs.dmn.runtime.external.DefaultExternalFunctionExecutor; +import com.gs.dmn.runtime.ExecutionContextBuilder; import com.gs.dmn.runtime.listener.TreeTraceEventListener; import com.gs.dmn.runtime.listener.node.DRGElementNode; import org.junit.jupiter.api.Test; @@ -85,7 +82,7 @@ public void testPostorder() throws Exception { } private List applyDecision(Applicant applicant, BigDecimal currentRiskAppetite, BigDecimal lendingThreshold, TreeTraceEventListener listener) { - return decision.apply(applicant, currentRiskAppetite, lendingThreshold, new ExecutionContext(new AnnotationSet(), listener, new DefaultExternalFunctionExecutor(), new DefaultCache())); + return decision.apply(applicant, currentRiskAppetite, lendingThreshold, ExecutionContextBuilder.executionContext().withEventListener(listener).build()); } private String getExpectedPath() { diff --git a/dmn-signavio-it/dmn-signavio-it-kotlin-translator/src/test/java/com/gs/dmn/generated/example_credit_decision_mixed_tree/HandwrittenGenerateOutputDataTest.java b/dmn-signavio-it/dmn-signavio-it-kotlin-translator/src/test/java/com/gs/dmn/generated/example_credit_decision_mixed_tree/HandwrittenGenerateOutputDataTest.java index 4d7d40185..c6708ccf6 100644 --- a/dmn-signavio-it/dmn-signavio-it-kotlin-translator/src/test/java/com/gs/dmn/generated/example_credit_decision_mixed_tree/HandwrittenGenerateOutputDataTest.java +++ b/dmn-signavio-it/dmn-signavio-it-kotlin-translator/src/test/java/com/gs/dmn/generated/example_credit_decision_mixed_tree/HandwrittenGenerateOutputDataTest.java @@ -42,8 +42,6 @@ public void testCase1() { assertEquals("compareAgainstLendingThreshold", annotation.getDecisionName()); assertEquals(1, annotation.getRuleIndex()); assertEquals("Raw issue score is -7.50, Age-weighted score is 60, Acceptance threshold is 25", annotation.getAnnotation()); - - assertEquals(1, annotationSet.size()); } @Test diff --git a/dmn-signavio-it/dmn-signavio-it-translator/src/test/java/com/gs/dmn/generated/AbstractHandwrittenDecisionTest.java b/dmn-signavio-it/dmn-signavio-it-translator/src/test/java/com/gs/dmn/generated/AbstractHandwrittenDecisionTest.java index dc20c1ef7..833e0c72c 100644 --- a/dmn-signavio-it/dmn-signavio-it-translator/src/test/java/com/gs/dmn/generated/AbstractHandwrittenDecisionTest.java +++ b/dmn-signavio-it/dmn-signavio-it-translator/src/test/java/com/gs/dmn/generated/AbstractHandwrittenDecisionTest.java @@ -14,10 +14,8 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.gs.dmn.runtime.ExecutionContext; +import com.gs.dmn.runtime.ExecutionContextBuilder; import com.gs.dmn.runtime.annotation.AnnotationSet; -import com.gs.dmn.runtime.cache.DefaultCache; -import com.gs.dmn.runtime.external.DefaultExternalFunctionExecutor; -import com.gs.dmn.runtime.listener.NopEventListener; import com.gs.dmn.serialization.JsonSerializer; import org.junit.jupiter.api.BeforeEach; @@ -37,7 +35,7 @@ protected String toJson(Object object) { @BeforeEach public void setUp() { - this.annotationSet = new AnnotationSet(); - this.context = new ExecutionContext(annotationSet, new NopEventListener(), new DefaultExternalFunctionExecutor(), new DefaultCache()); + this.context = ExecutionContextBuilder.executionContext().build(); + this.annotationSet = context.getAnnotations(); } } diff --git a/dmn-signavio-it/dmn-signavio-it-translator/src/test/java/com/gs/dmn/generated/example_credit_decision/PostorderTraceListenerTest.java b/dmn-signavio-it/dmn-signavio-it-translator/src/test/java/com/gs/dmn/generated/example_credit_decision/PostorderTraceListenerTest.java index 03a32250e..8c14ef464 100644 --- a/dmn-signavio-it/dmn-signavio-it-translator/src/test/java/com/gs/dmn/generated/example_credit_decision/PostorderTraceListenerTest.java +++ b/dmn-signavio-it/dmn-signavio-it-translator/src/test/java/com/gs/dmn/generated/example_credit_decision/PostorderTraceListenerTest.java @@ -16,9 +16,7 @@ import com.gs.dmn.generated.example_credit_decision.type.ApplicantImpl; import com.gs.dmn.runtime.Assert; import com.gs.dmn.runtime.ExecutionContext; -import com.gs.dmn.runtime.annotation.AnnotationSet; -import com.gs.dmn.runtime.cache.DefaultCache; -import com.gs.dmn.runtime.external.DefaultExternalFunctionExecutor; +import com.gs.dmn.runtime.ExecutionContextBuilder; import com.gs.dmn.runtime.listener.PostorderTraceEventListener; import com.gs.dmn.runtime.listener.node.DRGElementNode; import org.junit.jupiter.api.Test; @@ -68,7 +66,7 @@ public void testListenerWithFilter() throws Exception { } private List applyDecision(Applicant toApplicant, BigDecimal currentRiskAppetite, BigDecimal lendingThreshold, PostorderTraceEventListener listener) { - ExecutionContext context = new ExecutionContext(new AnnotationSet(), listener, new DefaultExternalFunctionExecutor(), new DefaultCache()); + ExecutionContext context = ExecutionContextBuilder.executionContext().withEventListener(listener).build(); return decision.apply(toApplicant, currentRiskAppetite, lendingThreshold, context); } diff --git a/dmn-signavio-it/dmn-signavio-it-translator/src/test/java/com/gs/dmn/generated/example_credit_decision/TreeTraceListenerTest.java b/dmn-signavio-it/dmn-signavio-it-translator/src/test/java/com/gs/dmn/generated/example_credit_decision/TreeTraceListenerTest.java index 75c33e30d..b36c2f045 100644 --- a/dmn-signavio-it/dmn-signavio-it-translator/src/test/java/com/gs/dmn/generated/example_credit_decision/TreeTraceListenerTest.java +++ b/dmn-signavio-it/dmn-signavio-it-translator/src/test/java/com/gs/dmn/generated/example_credit_decision/TreeTraceListenerTest.java @@ -15,10 +15,7 @@ import com.gs.dmn.generated.example_credit_decision.type.Applicant; import com.gs.dmn.generated.example_credit_decision.type.ApplicantImpl; import com.gs.dmn.runtime.Assert; -import com.gs.dmn.runtime.ExecutionContext; -import com.gs.dmn.runtime.annotation.AnnotationSet; -import com.gs.dmn.runtime.cache.DefaultCache; -import com.gs.dmn.runtime.external.DefaultExternalFunctionExecutor; +import com.gs.dmn.runtime.ExecutionContextBuilder; import com.gs.dmn.runtime.listener.TreeTraceEventListener; import com.gs.dmn.runtime.listener.node.DRGElementNode; import org.junit.jupiter.api.Test; @@ -85,7 +82,7 @@ public void testPostorder() throws Exception { } private List applyDecision(Applicant applicant, BigDecimal currentRiskAppetite, BigDecimal lendingThreshold, TreeTraceEventListener listener) { - return decision.apply(applicant, currentRiskAppetite, lendingThreshold, new ExecutionContext(new AnnotationSet(), listener, new DefaultExternalFunctionExecutor(), new DefaultCache())); + return decision.apply(applicant, currentRiskAppetite, lendingThreshold, ExecutionContextBuilder.executionContext().withEventListener(listener).build()); } private String getExpectedPath() { diff --git a/dmn-tck-it/dmn-tck-it-kotlin-translator/src/test/java/com/gs/dmn/generated/tck/AbstractHandwrittenDecisionTest.java b/dmn-tck-it/dmn-tck-it-kotlin-translator/src/test/java/com/gs/dmn/generated/tck/AbstractHandwrittenDecisionTest.java index e76583ea0..d8f69201a 100644 --- a/dmn-tck-it/dmn-tck-it-kotlin-translator/src/test/java/com/gs/dmn/generated/tck/AbstractHandwrittenDecisionTest.java +++ b/dmn-tck-it/dmn-tck-it-kotlin-translator/src/test/java/com/gs/dmn/generated/tck/AbstractHandwrittenDecisionTest.java @@ -13,23 +13,13 @@ package com.gs.dmn.generated.tck; import com.gs.dmn.runtime.ExecutionContext; -import com.gs.dmn.runtime.annotation.AnnotationSet; -import com.gs.dmn.runtime.cache.Cache; -import com.gs.dmn.runtime.cache.DefaultCache; -import com.gs.dmn.runtime.external.DefaultExternalFunctionExecutor; -import com.gs.dmn.runtime.external.ExternalFunctionExecutor; -import com.gs.dmn.runtime.listener.EventListener; -import com.gs.dmn.runtime.listener.NopEventListener; +import com.gs.dmn.runtime.ExecutionContextBuilder; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertTrue; public abstract class AbstractHandwrittenDecisionTest { - protected AnnotationSet annotationSet; - protected EventListener eventListener; - protected ExternalFunctionExecutor externalFunctionExecutor; - protected Cache cache; protected ExecutionContext context; protected abstract void applyDecision(); @@ -44,10 +34,6 @@ public void testPerformance() { @BeforeEach public void setUp() { - this.annotationSet = new AnnotationSet(); - this.eventListener = new NopEventListener(); - this.externalFunctionExecutor = new DefaultExternalFunctionExecutor(); - this.cache = new DefaultCache(); - this.context = new ExecutionContext(annotationSet, eventListener, externalFunctionExecutor, cache); + this.context = ExecutionContextBuilder.executionContext().build(); } } diff --git a/dmn-tck-it/dmn-tck-it-kotlin-translator/src/test/java/com/gs/dmn/generated/tck/cl3_0020_vacation_days/PostorderTraceListenerTest.java b/dmn-tck-it/dmn-tck-it-kotlin-translator/src/test/java/com/gs/dmn/generated/tck/cl3_0020_vacation_days/PostorderTraceListenerTest.java index 1d2aa5d8f..dc4ee0d25 100644 --- a/dmn-tck-it/dmn-tck-it-kotlin-translator/src/test/java/com/gs/dmn/generated/tck/cl3_0020_vacation_days/PostorderTraceListenerTest.java +++ b/dmn-tck-it/dmn-tck-it-kotlin-translator/src/test/java/com/gs/dmn/generated/tck/cl3_0020_vacation_days/PostorderTraceListenerTest.java @@ -13,9 +13,7 @@ package com.gs.dmn.generated.tck.cl3_0020_vacation_days; import com.gs.dmn.runtime.ExecutionContext; -import com.gs.dmn.runtime.annotation.AnnotationSet; -import com.gs.dmn.runtime.cache.DefaultCache; -import com.gs.dmn.runtime.external.DefaultExternalFunctionExecutor; +import com.gs.dmn.runtime.ExecutionContextBuilder; import com.gs.dmn.runtime.listener.PostorderTraceEventListener; import com.gs.dmn.runtime.listener.node.DRGElementNode; import org.junit.jupiter.api.Test; @@ -35,7 +33,7 @@ public class PostorderTraceListenerTest extends AbstractTraceListenerTest { @Test public void testListener() throws Exception { PostorderTraceEventListener listener = new PostorderTraceEventListener(); - ExecutionContext context = new ExecutionContext(new AnnotationSet(), listener, new DefaultExternalFunctionExecutor(), new DefaultCache()); + ExecutionContext context = ExecutionContextBuilder.executionContext().withEventListener(listener).build(); String expectedResult = "27"; String age = "16"; @@ -52,7 +50,7 @@ public void testListener() throws Exception { @Test public void testListenerWithFilter() throws Exception { PostorderTraceEventListener listener = new PostorderTraceEventListener(Arrays.asList("Extra days case 1", "Extra days case 2")); - ExecutionContext context = new ExecutionContext(new AnnotationSet(), listener, new DefaultExternalFunctionExecutor(), new DefaultCache()); + ExecutionContext context = ExecutionContextBuilder.executionContext().withEventListener(listener).build(); String expectedResult = "27"; String age = "16"; diff --git a/dmn-tck-it/dmn-tck-it-kotlin-translator/src/test/java/com/gs/dmn/generated/tck/cl3_0020_vacation_days/TreeTraceListenerTest.java b/dmn-tck-it/dmn-tck-it-kotlin-translator/src/test/java/com/gs/dmn/generated/tck/cl3_0020_vacation_days/TreeTraceListenerTest.java index feb2601b9..0ec33447d 100644 --- a/dmn-tck-it/dmn-tck-it-kotlin-translator/src/test/java/com/gs/dmn/generated/tck/cl3_0020_vacation_days/TreeTraceListenerTest.java +++ b/dmn-tck-it/dmn-tck-it-kotlin-translator/src/test/java/com/gs/dmn/generated/tck/cl3_0020_vacation_days/TreeTraceListenerTest.java @@ -13,9 +13,7 @@ package com.gs.dmn.generated.tck.cl3_0020_vacation_days; import com.gs.dmn.runtime.ExecutionContext; -import com.gs.dmn.runtime.annotation.AnnotationSet; -import com.gs.dmn.runtime.cache.DefaultCache; -import com.gs.dmn.runtime.external.DefaultExternalFunctionExecutor; +import com.gs.dmn.runtime.ExecutionContextBuilder; import com.gs.dmn.runtime.listener.TreeTraceEventListener; import com.gs.dmn.runtime.listener.node.DRGElementNode; import org.junit.jupiter.api.Test; @@ -34,7 +32,7 @@ public class TreeTraceListenerTest extends AbstractTraceListenerTest { @Test public void testTree() throws Exception { TreeTraceEventListener listener = new TreeTraceEventListener(); - ExecutionContext context = new ExecutionContext(new AnnotationSet(), listener, new DefaultExternalFunctionExecutor(), new DefaultCache()); + ExecutionContext context = ExecutionContextBuilder.executionContext().withEventListener(listener).build(); String expectedResult = "27"; String age = "16"; @@ -51,7 +49,7 @@ public void testTree() throws Exception { @Test public void testPreorder() throws Exception { TreeTraceEventListener listener = new TreeTraceEventListener(); - ExecutionContext context = new ExecutionContext(new AnnotationSet(), listener, new DefaultExternalFunctionExecutor(), new DefaultCache()); + ExecutionContext context = ExecutionContextBuilder.executionContext().withEventListener(listener).build(); String expectedResult = "27"; String age = "16"; @@ -68,7 +66,7 @@ public void testPreorder() throws Exception { @Test public void testPostorder() throws Exception { TreeTraceEventListener listener = new TreeTraceEventListener(); - ExecutionContext context = new ExecutionContext(new AnnotationSet(), listener, new DefaultExternalFunctionExecutor(), new DefaultCache()); + ExecutionContext context = ExecutionContextBuilder.executionContext().withEventListener(listener).build(); String expectedResult = "27"; String age = "16"; diff --git a/dmn-tck-it/dmn-tck-it-translator/src/test/java/com/gs/dmn/AbstractHandwrittenDecisionTest.java b/dmn-tck-it/dmn-tck-it-translator/src/test/java/com/gs/dmn/AbstractHandwrittenDecisionTest.java index a0d9c60c1..a9bd2d576 100644 --- a/dmn-tck-it/dmn-tck-it-translator/src/test/java/com/gs/dmn/AbstractHandwrittenDecisionTest.java +++ b/dmn-tck-it/dmn-tck-it-translator/src/test/java/com/gs/dmn/AbstractHandwrittenDecisionTest.java @@ -13,23 +13,13 @@ package com.gs.dmn; import com.gs.dmn.runtime.ExecutionContext; -import com.gs.dmn.runtime.annotation.AnnotationSet; -import com.gs.dmn.runtime.cache.Cache; -import com.gs.dmn.runtime.cache.DefaultCache; -import com.gs.dmn.runtime.external.DefaultExternalFunctionExecutor; -import com.gs.dmn.runtime.external.ExternalFunctionExecutor; -import com.gs.dmn.runtime.listener.EventListener; -import com.gs.dmn.runtime.listener.NopEventListener; +import com.gs.dmn.runtime.ExecutionContextBuilder; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertTrue; public abstract class AbstractHandwrittenDecisionTest { - protected AnnotationSet annotationSet; - protected EventListener eventListener; - protected ExternalFunctionExecutor externalFunctionExecutor; - protected Cache cache; protected ExecutionContext context; protected abstract void applyDecision(); @@ -44,10 +34,6 @@ public void testPerformance() { @BeforeEach public void setUp() { - this.annotationSet = new AnnotationSet(); - this.eventListener = new NopEventListener(); - this.externalFunctionExecutor = new DefaultExternalFunctionExecutor(); - this.cache = new DefaultCache(); - this.context = new ExecutionContext(annotationSet, eventListener, externalFunctionExecutor, cache); + this.context = ExecutionContextBuilder.executionContext().build(); } } diff --git a/dmn-tck-it/dmn-tck-it-translator/src/test/java/com/gs/dmn/generated/tck/cl3_0020_vacation_days/PostorderTraceListenerTest.java b/dmn-tck-it/dmn-tck-it-translator/src/test/java/com/gs/dmn/generated/tck/cl3_0020_vacation_days/PostorderTraceListenerTest.java index 1d2aa5d8f..dc4ee0d25 100644 --- a/dmn-tck-it/dmn-tck-it-translator/src/test/java/com/gs/dmn/generated/tck/cl3_0020_vacation_days/PostorderTraceListenerTest.java +++ b/dmn-tck-it/dmn-tck-it-translator/src/test/java/com/gs/dmn/generated/tck/cl3_0020_vacation_days/PostorderTraceListenerTest.java @@ -13,9 +13,7 @@ package com.gs.dmn.generated.tck.cl3_0020_vacation_days; import com.gs.dmn.runtime.ExecutionContext; -import com.gs.dmn.runtime.annotation.AnnotationSet; -import com.gs.dmn.runtime.cache.DefaultCache; -import com.gs.dmn.runtime.external.DefaultExternalFunctionExecutor; +import com.gs.dmn.runtime.ExecutionContextBuilder; import com.gs.dmn.runtime.listener.PostorderTraceEventListener; import com.gs.dmn.runtime.listener.node.DRGElementNode; import org.junit.jupiter.api.Test; @@ -35,7 +33,7 @@ public class PostorderTraceListenerTest extends AbstractTraceListenerTest { @Test public void testListener() throws Exception { PostorderTraceEventListener listener = new PostorderTraceEventListener(); - ExecutionContext context = new ExecutionContext(new AnnotationSet(), listener, new DefaultExternalFunctionExecutor(), new DefaultCache()); + ExecutionContext context = ExecutionContextBuilder.executionContext().withEventListener(listener).build(); String expectedResult = "27"; String age = "16"; @@ -52,7 +50,7 @@ public void testListener() throws Exception { @Test public void testListenerWithFilter() throws Exception { PostorderTraceEventListener listener = new PostorderTraceEventListener(Arrays.asList("Extra days case 1", "Extra days case 2")); - ExecutionContext context = new ExecutionContext(new AnnotationSet(), listener, new DefaultExternalFunctionExecutor(), new DefaultCache()); + ExecutionContext context = ExecutionContextBuilder.executionContext().withEventListener(listener).build(); String expectedResult = "27"; String age = "16"; diff --git a/dmn-tck-it/dmn-tck-it-translator/src/test/java/com/gs/dmn/generated/tck/cl3_0020_vacation_days/TreeTraceListenerTest.java b/dmn-tck-it/dmn-tck-it-translator/src/test/java/com/gs/dmn/generated/tck/cl3_0020_vacation_days/TreeTraceListenerTest.java index feb2601b9..0ec33447d 100644 --- a/dmn-tck-it/dmn-tck-it-translator/src/test/java/com/gs/dmn/generated/tck/cl3_0020_vacation_days/TreeTraceListenerTest.java +++ b/dmn-tck-it/dmn-tck-it-translator/src/test/java/com/gs/dmn/generated/tck/cl3_0020_vacation_days/TreeTraceListenerTest.java @@ -13,9 +13,7 @@ package com.gs.dmn.generated.tck.cl3_0020_vacation_days; import com.gs.dmn.runtime.ExecutionContext; -import com.gs.dmn.runtime.annotation.AnnotationSet; -import com.gs.dmn.runtime.cache.DefaultCache; -import com.gs.dmn.runtime.external.DefaultExternalFunctionExecutor; +import com.gs.dmn.runtime.ExecutionContextBuilder; import com.gs.dmn.runtime.listener.TreeTraceEventListener; import com.gs.dmn.runtime.listener.node.DRGElementNode; import org.junit.jupiter.api.Test; @@ -34,7 +32,7 @@ public class TreeTraceListenerTest extends AbstractTraceListenerTest { @Test public void testTree() throws Exception { TreeTraceEventListener listener = new TreeTraceEventListener(); - ExecutionContext context = new ExecutionContext(new AnnotationSet(), listener, new DefaultExternalFunctionExecutor(), new DefaultCache()); + ExecutionContext context = ExecutionContextBuilder.executionContext().withEventListener(listener).build(); String expectedResult = "27"; String age = "16"; @@ -51,7 +49,7 @@ public void testTree() throws Exception { @Test public void testPreorder() throws Exception { TreeTraceEventListener listener = new TreeTraceEventListener(); - ExecutionContext context = new ExecutionContext(new AnnotationSet(), listener, new DefaultExternalFunctionExecutor(), new DefaultCache()); + ExecutionContext context = ExecutionContextBuilder.executionContext().withEventListener(listener).build(); String expectedResult = "27"; String age = "16"; @@ -68,7 +66,7 @@ public void testPreorder() throws Exception { @Test public void testPostorder() throws Exception { TreeTraceEventListener listener = new TreeTraceEventListener(); - ExecutionContext context = new ExecutionContext(new AnnotationSet(), listener, new DefaultExternalFunctionExecutor(), new DefaultCache()); + ExecutionContext context = ExecutionContextBuilder.executionContext().withEventListener(listener).build(); String expectedResult = "27"; String age = "16";