type) {
return type.cast(extensions.get(key));
}
- public Injector getInjector() {
+ public BizlogicInstanceProvider getInjector() {
return injector;
}
diff --git a/tef-impl/src/main/java/flipkart/tef/execution/DataDependencyException.java b/tef-core/src/main/java/flipkart/tef/exception/DataDependencyException.java
similarity index 96%
rename from tef-impl/src/main/java/flipkart/tef/execution/DataDependencyException.java
rename to tef-core/src/main/java/flipkart/tef/exception/DataDependencyException.java
index f45368e..e57a495 100644
--- a/tef-impl/src/main/java/flipkart/tef/execution/DataDependencyException.java
+++ b/tef-core/src/main/java/flipkart/tef/exception/DataDependencyException.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package flipkart.tef.execution;
+package flipkart.tef.exception;
/**
*
diff --git a/tef-impl/src/main/java/flipkart/tef/TefGuiceModule.java b/tef-core/src/main/java/flipkart/tef/interfaces/BizlogicInstanceProvider.java
similarity index 55%
rename from tef-impl/src/main/java/flipkart/tef/TefGuiceModule.java
rename to tef-core/src/main/java/flipkart/tef/interfaces/BizlogicInstanceProvider.java
index 0de8d55..c16e886 100644
--- a/tef-impl/src/main/java/flipkart/tef/TefGuiceModule.java
+++ b/tef-core/src/main/java/flipkart/tef/interfaces/BizlogicInstanceProvider.java
@@ -14,21 +14,18 @@
* limitations under the License.
*/
-package flipkart.tef;
-
-import com.google.inject.AbstractModule;
-import flipkart.tef.execution.DataInjector;
-import flipkart.tef.execution.DefaultDataInjector;
+package flipkart.tef.interfaces;
/**
- * This class contains guice binding relevant for tef.
- *
- * Date: 01/07/21
+ * This interface is intended to expose methods that can help the flow executor eliminate its
+ * dependency on concrete implementations of DI (like google guice).
+ *
+ * Flow Executor needs instances of Bizlogic during execution and this interface is queried for those instances.
+ * Clients can stub this with the `Injector` in guice or a similar implementation
+ *
+ * Date: 16/07/23
*/
-public class TefGuiceModule extends AbstractModule {
+public interface BizlogicInstanceProvider {
- @Override
- protected void configure() {
- bind(DataInjector.class).to(DefaultDataInjector.class);
- }
+ T getInstance(Class var1);
}
diff --git a/tef-impl/src/main/java/flipkart/tef/execution/DataInjector.java b/tef-core/src/main/java/flipkart/tef/interfaces/DataInjector.java
similarity index 94%
rename from tef-impl/src/main/java/flipkart/tef/execution/DataInjector.java
rename to tef-core/src/main/java/flipkart/tef/interfaces/DataInjector.java
index 0559cc9..89d0c32 100644
--- a/tef-impl/src/main/java/flipkart/tef/execution/DataInjector.java
+++ b/tef-core/src/main/java/flipkart/tef/interfaces/DataInjector.java
@@ -14,8 +14,9 @@
* limitations under the License.
*/
-package flipkart.tef.execution;
+package flipkart.tef.interfaces;
+import flipkart.tef.exception.DataDependencyException;
import flipkart.tef.exception.TefExecutionException;
/**
diff --git a/tef-impl/src/main/java/flipkart/tef/execution/InjectableValueProvider.java b/tef-core/src/main/java/flipkart/tef/interfaces/InjectableValueProvider.java
similarity index 96%
rename from tef-impl/src/main/java/flipkart/tef/execution/InjectableValueProvider.java
rename to tef-core/src/main/java/flipkart/tef/interfaces/InjectableValueProvider.java
index 2deced0..294ffe8 100644
--- a/tef-impl/src/main/java/flipkart/tef/execution/InjectableValueProvider.java
+++ b/tef-core/src/main/java/flipkart/tef/interfaces/InjectableValueProvider.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package flipkart.tef.execution;
+package flipkart.tef.interfaces;
import flipkart.tef.exception.TefExecutionException;
diff --git a/tef-impl/src/main/java/flipkart/tef/execution/MutationListener.java b/tef-core/src/main/java/flipkart/tef/interfaces/MutationListener.java
similarity index 96%
rename from tef-impl/src/main/java/flipkart/tef/execution/MutationListener.java
rename to tef-core/src/main/java/flipkart/tef/interfaces/MutationListener.java
index 4910673..ca83324 100644
--- a/tef-impl/src/main/java/flipkart/tef/execution/MutationListener.java
+++ b/tef-core/src/main/java/flipkart/tef/interfaces/MutationListener.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package flipkart.tef.execution;
+package flipkart.tef.interfaces;
import flipkart.tef.bizlogics.DataAdapterResult;
diff --git a/tef-guice-bridge/README.md b/tef-guice-bridge/README.md
new file mode 100644
index 0000000..ca5b023
--- /dev/null
+++ b/tef-guice-bridge/README.md
@@ -0,0 +1,21 @@
+### Tef Guice Bridge
+
+The objective of this module is to use Guice's Dependency Injection techniques to inject data available within tef.
+
+While Guice uses `@Inject` to inject any arbitrary dependency in fields or methods, TEF uses `@InjectData`
+to inject data that is emitted from data adapters, to stitch the data dependency. For classes that are using both Guice
+and TEF can leverage this module to use `@Inject` instead of `@InjectData` to inject data objects as well.
+
+Please note that this data injection is outside the Flow Graph Execution and dependency checks are not performed. i.e.
+Use Guice bridge on classes that are not part of simple flow.
+
+A class has to add the annotation `@TefRequestScoped` if it wants to leverage this capability.
+
+### Usage Instructions
+
+1. Install the Guice Module `GuiceBridgeModule`
+2. Mark the class with `@TefRequestScoped` wherever required
+3. Use `@Inject` for data objects if they are being emitted via Data Adapters from Simple Flow
+4. Use them anywhere in code without propagating it throughout.
+5. Dependency Checks will not be performed on the data being injected. If the relevant DataAdapter has not been executed
+ yet, a null injection will be made.
\ No newline at end of file
diff --git a/tef-guice-bridge/pom.xml b/tef-guice-bridge/pom.xml
new file mode 100644
index 0000000..8c91d1a
--- /dev/null
+++ b/tef-guice-bridge/pom.xml
@@ -0,0 +1,47 @@
+
+
+
+
+ tef
+ flipkart.tef
+ ${revision}
+
+ 4.0.0
+
+ tef-guice-bridge
+
+
+ 5.1.0
+
+
+
+
+ com.google.inject
+ guice
+ ${guice.version}
+
+
+
+ flipkart.tef
+ ${revision}
+ tef-core
+
+
+
+
\ No newline at end of file
diff --git a/tef-impl/src/main/java/flipkart/tef/guicebridge/GuiceBridgeModule.java b/tef-guice-bridge/src/main/java/flipkart/tef/guicebridge/GuiceBridgeModule.java
similarity index 55%
rename from tef-impl/src/main/java/flipkart/tef/guicebridge/GuiceBridgeModule.java
rename to tef-guice-bridge/src/main/java/flipkart/tef/guicebridge/GuiceBridgeModule.java
index 6c5cae5..d0b50a1 100644
--- a/tef-impl/src/main/java/flipkart/tef/guicebridge/GuiceBridgeModule.java
+++ b/tef-guice-bridge/src/main/java/flipkart/tef/guicebridge/GuiceBridgeModule.java
@@ -1,3 +1,19 @@
+/*
+ *Copyright [2024] [The Original Author]
+ *
+ * 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 flipkart.tef.guicebridge;
import com.google.inject.AbstractModule;
diff --git a/tef-impl/src/main/java/flipkart/tef/guicebridge/InjectDataGuiceMembersInjector.java b/tef-guice-bridge/src/main/java/flipkart/tef/guicebridge/InjectDataGuiceMembersInjector.java
similarity index 69%
rename from tef-impl/src/main/java/flipkart/tef/guicebridge/InjectDataGuiceMembersInjector.java
rename to tef-guice-bridge/src/main/java/flipkart/tef/guicebridge/InjectDataGuiceMembersInjector.java
index 5302ca9..c99875b 100644
--- a/tef-impl/src/main/java/flipkart/tef/guicebridge/InjectDataGuiceMembersInjector.java
+++ b/tef-guice-bridge/src/main/java/flipkart/tef/guicebridge/InjectDataGuiceMembersInjector.java
@@ -1,10 +1,26 @@
+/*
+ *Copyright [2024] [The Original Author]
+ *
+ * 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 flipkart.tef.guicebridge;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.MembersInjector;
import flipkart.tef.exception.TefExecutionException;
-import flipkart.tef.execution.InjectableValueProvider;
+import flipkart.tef.interfaces.InjectableValueProvider;
import java.lang.reflect.Field;
diff --git a/tef-impl/src/main/java/flipkart/tef/guicebridge/SubclassOrAnnotationMatcher.java b/tef-guice-bridge/src/main/java/flipkart/tef/guicebridge/SubclassOrAnnotationMatcher.java
similarity index 70%
rename from tef-impl/src/main/java/flipkart/tef/guicebridge/SubclassOrAnnotationMatcher.java
rename to tef-guice-bridge/src/main/java/flipkart/tef/guicebridge/SubclassOrAnnotationMatcher.java
index c17b01b..4ebad97 100644
--- a/tef-impl/src/main/java/flipkart/tef/guicebridge/SubclassOrAnnotationMatcher.java
+++ b/tef-guice-bridge/src/main/java/flipkart/tef/guicebridge/SubclassOrAnnotationMatcher.java
@@ -1,3 +1,19 @@
+/*
+ *Copyright [2024] [The Original Author]
+ *
+ * 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 flipkart.tef.guicebridge;
import com.google.inject.TypeLiteral;
diff --git a/tef-impl/src/main/java/flipkart/tef/guicebridge/TefGuiceScope.java b/tef-guice-bridge/src/main/java/flipkart/tef/guicebridge/TefGuiceScope.java
similarity index 71%
rename from tef-impl/src/main/java/flipkart/tef/guicebridge/TefGuiceScope.java
rename to tef-guice-bridge/src/main/java/flipkart/tef/guicebridge/TefGuiceScope.java
index 6ddb3e8..0076547 100644
--- a/tef-impl/src/main/java/flipkart/tef/guicebridge/TefGuiceScope.java
+++ b/tef-guice-bridge/src/main/java/flipkart/tef/guicebridge/TefGuiceScope.java
@@ -1,10 +1,26 @@
+/*
+ *Copyright [2024] [The Original Author]
+ *
+ * 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 flipkart.tef.guicebridge;
import com.google.common.base.Preconditions;
import com.google.inject.Key;
import com.google.inject.Provider;
import com.google.inject.Scope;
-import flipkart.tef.execution.InjectableValueProvider;
+import flipkart.tef.interfaces.InjectableValueProvider;
/**
* Custom guice scope (request-scoped) that injects an instance of
diff --git a/tef-impl/src/main/java/flipkart/tef/guicebridge/TefRequestScoped.java b/tef-guice-bridge/src/main/java/flipkart/tef/guicebridge/TefRequestScoped.java
similarity index 51%
rename from tef-impl/src/main/java/flipkart/tef/guicebridge/TefRequestScoped.java
rename to tef-guice-bridge/src/main/java/flipkart/tef/guicebridge/TefRequestScoped.java
index a8491a0..ee057da 100644
--- a/tef-impl/src/main/java/flipkart/tef/guicebridge/TefRequestScoped.java
+++ b/tef-guice-bridge/src/main/java/flipkart/tef/guicebridge/TefRequestScoped.java
@@ -1,3 +1,19 @@
+/*
+ *Copyright [2024] [The Original Author]
+ *
+ * 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 flipkart.tef.guicebridge;
diff --git a/tef-impl/src/main/java/flipkart/tef/guicebridge/TypeListenerForDataInjection.java b/tef-guice-bridge/src/main/java/flipkart/tef/guicebridge/TypeListenerForDataInjection.java
similarity index 74%
rename from tef-impl/src/main/java/flipkart/tef/guicebridge/TypeListenerForDataInjection.java
rename to tef-guice-bridge/src/main/java/flipkart/tef/guicebridge/TypeListenerForDataInjection.java
index 723300f..36587c3 100644
--- a/tef-impl/src/main/java/flipkart/tef/guicebridge/TypeListenerForDataInjection.java
+++ b/tef-guice-bridge/src/main/java/flipkart/tef/guicebridge/TypeListenerForDataInjection.java
@@ -1,3 +1,19 @@
+/*
+ *Copyright [2024] [The Original Author]
+ *
+ * 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 flipkart.tef.guicebridge;
import com.google.inject.TypeLiteral;
diff --git a/tef-impl/src/test/java/flipkart/tef/guicebridge/InjectDataGuiceMembersInjectorTest.java b/tef-guice-bridge/src/test/java/flipkart/tef/guicebridge/InjectDataGuiceMembersInjectorTest.java
similarity index 68%
rename from tef-impl/src/test/java/flipkart/tef/guicebridge/InjectDataGuiceMembersInjectorTest.java
rename to tef-guice-bridge/src/test/java/flipkart/tef/guicebridge/InjectDataGuiceMembersInjectorTest.java
index ec630d9..8a8973e 100644
--- a/tef-impl/src/test/java/flipkart/tef/guicebridge/InjectDataGuiceMembersInjectorTest.java
+++ b/tef-guice-bridge/src/test/java/flipkart/tef/guicebridge/InjectDataGuiceMembersInjectorTest.java
@@ -1,3 +1,19 @@
+/*
+ *Copyright [2024] [The Original Author]
+ *
+ * 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 flipkart.tef.guicebridge;
import com.google.inject.AbstractModule;
@@ -8,23 +24,45 @@
import flipkart.tef.annotations.InjectData;
import flipkart.tef.bizlogics.DataAdapterKey;
import flipkart.tef.bizlogics.DataAdapterResult;
-import flipkart.tef.exception.TefExecutionException;
-import flipkart.tef.execution.DataContext;
-import flipkart.tef.execution.InjectableValueProvider;
+import flipkart.tef.interfaces.InjectableValueProvider;
import org.junit.Assert;
import org.junit.Test;
import java.io.Serializable;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+@SuppressWarnings({"unused"})
public class InjectDataGuiceMembersInjectorTest {
+ static class TestValueProvider implements InjectableValueProvider {
+
+ Map, DataAdapterResult> dataContext = new HashMap<>();
+
+ TestValueProvider() {
+ Long threadId = Thread.currentThread().getId();
+
+ putInDataContext(dataContext, new DataAdapterResult(new SimpleData()));
+ putInDataContext(dataContext, new DataAdapterResult(threadId));
+ }
+
+ private void putInDataContext(Map, DataAdapterResult> dataContext, DataAdapterResult dataAdapterResult) {
+ dataContext.put(dataAdapterResult.getKey(), dataAdapterResult);
+ }
+
+ @Override
+ public Object getValueToInject(Class> fieldType, String name) {
+ return dataContext.get(new DataAdapterKey<>(name, fieldType)).getResult();
+ }
+ }
+
@Test
public void testRequestScopeBasic() {
@@ -63,6 +101,7 @@ protected void configure() {
}
}
+
@Test
public void testRequestScopeWithoutEnteringScope() {
@@ -73,17 +112,8 @@ protected void configure() {
}
});
- Long threadId = Thread.currentThread().getId();
- DataContext dataContext = new DataContext();
- dataContext.put(new DataAdapterResult(new SimpleData()));
- dataContext.put(new DataAdapterResult(threadId));
- InjectableValueProvider valueProvider = new InjectableValueProvider() {
+ InjectableValueProvider valueProvider = new TestValueProvider();
- @Override
- public Object getValueToInject(Class> fieldType, String name) throws TefExecutionException {
- return dataContext.get(new DataAdapterKey<>(name, fieldType));
- }
- };
try {
rootInjector.getInstance(SimpleInterface.class);
Assert.fail("Injection should have failed");
@@ -103,27 +133,9 @@ protected void configure() {
}
});
- Long threadId = Thread.currentThread().getId();
try (TefGuiceScope scope = rootInjector.getInstance(TefGuiceScope.class)) {
- DataContext dataContext = new DataContext();
- dataContext.put(new DataAdapterResult(new SimpleData()));
- dataContext.put(new DataAdapterResult(threadId));
- InjectableValueProvider valueProvider = new InjectableValueProvider() {
-
- @Override
- public Object getValueToInject(Class> fieldType, String name) throws TefExecutionException {
- return dataContext.get(new DataAdapterKey<>(name, fieldType));
- }
- };
-
- InjectableValueProvider valueProvider2 = new InjectableValueProvider() {
-
- @Override
- public Object getValueToInject(Class> fieldType, String name) throws TefExecutionException {
- return dataContext.get(new DataAdapterKey<>(name, fieldType));
- }
- };
-
+ InjectableValueProvider valueProvider = new TestValueProvider();
+ InjectableValueProvider valueProvider2 = new TestValueProvider();
scope.open(valueProvider);
try {
scope.open(valueProvider2);
@@ -147,17 +159,7 @@ protected void configure() {
Long threadId = Thread.currentThread().getId();
try (TefGuiceScope scope = rootInjector.getInstance(TefGuiceScope.class)) {
- DataContext dataContext = new DataContext();
- dataContext.put(new DataAdapterResult(new SimpleData()));
- dataContext.put(new DataAdapterResult(threadId));
- InjectableValueProvider valueProvider = new InjectableValueProvider() {
-
- @Override
- public Object getValueToInject(Class> fieldType, String name) throws TefExecutionException {
- return dataContext.get(new DataAdapterKey<>(name, fieldType));
- }
- };
-
+ InjectableValueProvider valueProvider = new TestValueProvider();
scope.open(valueProvider);
// Implementations of Serializable
@@ -190,17 +192,7 @@ public TesterThread(Injector rootInjector) {
public void run() {
Long threadId = Thread.currentThread().getId();
try (TefGuiceScope scope = rootInjector.getInstance(TefGuiceScope.class)) {
- DataContext dataContext = new DataContext();
- dataContext.put(new DataAdapterResult(new SimpleData()));
- dataContext.put(new DataAdapterResult(threadId));
- InjectableValueProvider valueProvider = new InjectableValueProvider() {
-
- @Override
- public Object getValueToInject(Class> fieldType, String name) throws TefExecutionException {
- return dataContext.get(new DataAdapterKey<>(name, fieldType));
- }
- };
-
+ InjectableValueProvider valueProvider = new TestValueProvider();
scope.open(valueProvider);
SimpleInterface result = rootInjector.getInstance(SimpleInterface.class);
assertNotNull("Data injection failed", result.simpleData);
@@ -212,7 +204,6 @@ public Object getValueToInject(Class> fieldType, String name) throws TefExecut
static class SimpleData {
}
-
static class SimpleInterface {
@InjectData
private SimpleData simpleData;
diff --git a/tef-impl/src/main/java/flipkart/tef/bizlogics/DataAdapterBizlogic.java b/tef-impl/src/main/java/flipkart/tef/bizlogics/DataAdapterBizlogic.java
index 91e6833..32e9554 100644
--- a/tef-impl/src/main/java/flipkart/tef/bizlogics/DataAdapterBizlogic.java
+++ b/tef-impl/src/main/java/flipkart/tef/bizlogics/DataAdapterBizlogic.java
@@ -19,7 +19,7 @@
import flipkart.tef.annotations.EmitData;
import flipkart.tef.annotations.InjectData;
import flipkart.tef.exception.TefExecutionException;
-import flipkart.tef.execution.MutationListener;
+import flipkart.tef.interfaces.MutationListener;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
diff --git a/tef-impl/src/main/java/flipkart/tef/execution/DataContext.java b/tef-impl/src/main/java/flipkart/tef/execution/DataContext.java
index 4688312..0ec1300 100644
--- a/tef-impl/src/main/java/flipkart/tef/execution/DataContext.java
+++ b/tef-impl/src/main/java/flipkart/tef/execution/DataContext.java
@@ -18,6 +18,7 @@
import flipkart.tef.bizlogics.DataAdapterKey;
import flipkart.tef.bizlogics.DataAdapterResult;
+import flipkart.tef.interfaces.MutationListener;
import java.util.ArrayList;
import java.util.HashMap;
diff --git a/tef-impl/src/main/java/flipkart/tef/execution/DefaultDataInjector.java b/tef-impl/src/main/java/flipkart/tef/execution/DefaultDataInjector.java
index c3f7816..dbf6580 100644
--- a/tef-impl/src/main/java/flipkart/tef/execution/DefaultDataInjector.java
+++ b/tef-impl/src/main/java/flipkart/tef/execution/DefaultDataInjector.java
@@ -17,13 +17,18 @@
package flipkart.tef.execution;
import flipkart.tef.annotations.InjectData;
+import flipkart.tef.exception.DataDependencyException;
import flipkart.tef.exception.TefExecutionException;
+import flipkart.tef.interfaces.DataInjector;
+import flipkart.tef.interfaces.InjectableValueProvider;
import java.lang.reflect.Field;
/**
- * This class is used for injecting data into bizlogics
- *
+ * This class is used for injecting data into bizlogics.
+ *
+ * Clients should find a way to use this default implementation and bind it suitably.
+ *
* Date: 16/04/21
*/
public class DefaultDataInjector implements DataInjector {
diff --git a/tef-impl/src/main/java/flipkart/tef/execution/FlowExecutor.java b/tef-impl/src/main/java/flipkart/tef/execution/FlowExecutor.java
index bcc4b66..beb09eb 100644
--- a/tef-impl/src/main/java/flipkart/tef/execution/FlowExecutor.java
+++ b/tef-impl/src/main/java/flipkart/tef/execution/FlowExecutor.java
@@ -23,8 +23,12 @@
import flipkart.tef.bizlogics.IBizlogic;
import flipkart.tef.bizlogics.IDataBizlogic;
import flipkart.tef.bizlogics.TefContext;
+import flipkart.tef.exception.DataDependencyException;
import flipkart.tef.exception.TefExecutionException;
import flipkart.tef.flow.SimpleFlow;
+import flipkart.tef.interfaces.DataInjector;
+import flipkart.tef.interfaces.InjectableValueProvider;
+import flipkart.tef.interfaces.MutationListener;
import java.util.ArrayList;
import java.util.HashMap;
@@ -57,12 +61,12 @@ public class FlowExecutor implements MutationListener, InjectableValueProvider {
/**
* Create an instance of FlowExecutor.
- * @param flow
+ *
+ * @param flow
* @param context
* @param tefContext
*/
- public FlowExecutor(SimpleFlow flow, DataContext context,
- TefContext tefContext) {
+ public FlowExecutor(SimpleFlow flow, DataContext context, TefContext tefContext) {
this.flow = flow;
this.context = context;
this.tefContext = tefContext;
@@ -70,7 +74,6 @@ public FlowExecutor(SimpleFlow flow, DataContext context,
this.listener = new AllFlowExecutionListener(tefContext);
this.mutationListeners = new ArrayList<>();
this.context.addMutationListener(this);
-
this.dataInjector = tefContext.getInjector().getInstance(DataInjector.class);
}
diff --git a/tef-impl/src/test/java/flipkart/tef/TestGuiceModule.java b/tef-impl/src/test/java/flipkart/tef/TestGuiceModule.java
deleted file mode 100644
index 5645649..0000000
--- a/tef-impl/src/test/java/flipkart/tef/TestGuiceModule.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- *Copyright [2024] [The Original Author]
- *
- * 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 flipkart.tef;
-
-import com.google.inject.AbstractModule;
-import flipkart.tef.execution.DataInjector;
-import flipkart.tef.execution.DefaultDataInjector;
-
-/**
- * This class is used for injecting common test classes
- *
- * Date: 16/04/21
- */
-public class TestGuiceModule extends AbstractModule {
- @Override
- protected void configure() {
- bind(DataInjector.class).to(DefaultDataInjector.class);
- }
-}
diff --git a/tef-impl/src/test/java/flipkart/tef/TestTefContext.java b/tef-impl/src/test/java/flipkart/tef/TestTefContext.java
index 6553eb8..41b1f3d 100644
--- a/tef-impl/src/test/java/flipkart/tef/TestTefContext.java
+++ b/tef-impl/src/test/java/flipkart/tef/TestTefContext.java
@@ -16,31 +16,48 @@
package flipkart.tef;
-import com.google.inject.AbstractModule;
-import com.google.inject.Guice;
-import com.google.inject.Injector;
import flipkart.tef.bizlogics.TefContext;
+import flipkart.tef.execution.DefaultDataInjector;
+import flipkart.tef.interfaces.BizlogicInstanceProvider;
+import flipkart.tef.interfaces.DataInjector;
+import java.lang.reflect.Constructor;
import java.util.HashMap;
import java.util.Map;
-import java.util.function.Consumer;
/**
- * This class is used for
- *
+ * This class creates a test version of TefContext
+ *
* Date: 17/12/21
*/
public class TestTefContext extends TefContext {
public TestTefContext() {
- super(new HashMap<>(), Guice.createInjector(new TestGuiceModule()), System.out::println);
+ super(new HashMap<>(), new TestBizlogicInstanceProvider(), System.out::println);
}
- public TestTefContext(AbstractModule... modules) {
- super(new HashMap<>(), Guice.createInjector(modules), System.out::println);
- }
+ static class TestBizlogicInstanceProvider implements BizlogicInstanceProvider {
+
+ Map, Object> crudeDI;
+
+ TestBizlogicInstanceProvider() {
+ crudeDI = new HashMap<>();
+ crudeDI.put(DataInjector.class, new DefaultDataInjector());
+ }
- public TestTefContext(Map additionalContext, Injector injector, Consumer exceptionLogger) {
- super(additionalContext, injector, exceptionLogger);
+ @SuppressWarnings({"unchecked"})
+ @Override
+ public T getInstance(Class clazz) {
+ return (T) crudeDI.computeIfAbsent(clazz, (c) -> {
+ try {
+ Constructor> declaredConstructor = c.getDeclaredConstructor();
+ declaredConstructor.setAccessible(true);
+ return declaredConstructor.newInstance();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ throw new RuntimeException("Unable to create instance of " + clazz.getName());
+ });
+ }
}
}
diff --git a/tef-impl/src/test/java/flipkart/tef/bizlogics/AsyncDataAdapterBizlogicTest.java b/tef-impl/src/test/java/flipkart/tef/bizlogics/AsyncDataAdapterBizlogicTest.java
index e371a07..3d85d0b 100644
--- a/tef-impl/src/test/java/flipkart/tef/bizlogics/AsyncDataAdapterBizlogicTest.java
+++ b/tef-impl/src/test/java/flipkart/tef/bizlogics/AsyncDataAdapterBizlogicTest.java
@@ -1,12 +1,28 @@
+/*
+ *Copyright [2024] [The Original Author]
+ *
+ * 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 flipkart.tef.bizlogics;
import com.google.common.collect.Queues;
import flipkart.tef.TestTefContext;
import flipkart.tef.annotations.EmitData;
import flipkart.tef.annotations.InjectData;
+import flipkart.tef.exception.DataDependencyException;
import flipkart.tef.exception.TefExecutionException;
import flipkart.tef.execution.DataContext;
-import flipkart.tef.execution.DataDependencyException;
import flipkart.tef.execution.FlowExecutor;
import flipkart.tef.execution.FluentCapabilityBuilder;
import flipkart.tef.execution.MyFlowExecutionListener;
diff --git a/tef-impl/src/test/java/flipkart/tef/bizlogics/DataAdapterKeyTest.java b/tef-impl/src/test/java/flipkart/tef/bizlogics/DataAdapterKeyTest.java
index 653dfc9..8db0ad6 100644
--- a/tef-impl/src/test/java/flipkart/tef/bizlogics/DataAdapterKeyTest.java
+++ b/tef-impl/src/test/java/flipkart/tef/bizlogics/DataAdapterKeyTest.java
@@ -20,9 +20,9 @@
import flipkart.tef.TestTefContext;
import flipkart.tef.annotations.EmitData;
import flipkart.tef.annotations.InjectData;
+import flipkart.tef.exception.DataDependencyException;
import flipkart.tef.exception.TefExecutionException;
import flipkart.tef.execution.DataContext;
-import flipkart.tef.execution.DataDependencyException;
import flipkart.tef.execution.FlowExecutor;
import flipkart.tef.execution.FluentCapabilityBuilder;
import flipkart.tef.flow.SimpleFlow;
diff --git a/tef-impl/src/test/java/flipkart/tef/execution/FlowExecutorMutationTest.java b/tef-impl/src/test/java/flipkart/tef/execution/FlowExecutorMutationTest.java
index 2915779..fe72884 100644
--- a/tef-impl/src/test/java/flipkart/tef/execution/FlowExecutorMutationTest.java
+++ b/tef-impl/src/test/java/flipkart/tef/execution/FlowExecutorMutationTest.java
@@ -29,6 +29,7 @@
import flipkart.tef.bizlogics.DataAdapterResult;
import flipkart.tef.bizlogics.IBizlogic;
import flipkart.tef.bizlogics.TefContext;
+import flipkart.tef.exception.DataDependencyException;
import flipkart.tef.exception.TefExecutionException;
import flipkart.tef.flow.SimpleFlow;
import org.junit.Before;
diff --git a/tef-impl/src/test/java/flipkart/tef/execution/FlowExecutorTest.java b/tef-impl/src/test/java/flipkart/tef/execution/FlowExecutorTest.java
index 1c4b0c0..7ffc26f 100644
--- a/tef-impl/src/test/java/flipkart/tef/execution/FlowExecutorTest.java
+++ b/tef-impl/src/test/java/flipkart/tef/execution/FlowExecutorTest.java
@@ -25,6 +25,7 @@
import flipkart.tef.bizlogics.TefContext;
import flipkart.tef.capability.model.EnrichmentResultData;
import flipkart.tef.capability.model.MapBaseData;
+import flipkart.tef.exception.DataDependencyException;
import flipkart.tef.exception.TefExecutionException;
import flipkart.tef.flow.SimpleFlow;
import org.junit.Before;