-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#665] Add builder pattern for ExecutionContext
- Loading branch information
1 parent
a40c11a
commit b029863
Showing
16 changed files
with
144 additions
and
84 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
59 changes: 59 additions & 0 deletions
59
dmn-runtime/src/main/java/com/gs/dmn/runtime/ExecutionContextBuilder.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,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); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
dmn-runtime/src/test/java/com/gs/dmn/runtime/ExecutionContextBuilderTest.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,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()); | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.