forked from cucumber/cucumber-jvm
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed child spring context and implemented custom scope for glue code. cucumber-glue.xml is internal now. All context configuration may be done in cucumber.xml
- Loading branch information
1 parent
0825e59
commit 5afbb92
Showing
6 changed files
with
133 additions
and
34 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
spring/src/main/java/cucumber/runtime/java/spring/GlueCodeContext.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,55 @@ | ||
package cucumber.runtime.java.spring; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class GlueCodeContext { | ||
public static final GlueCodeContext INSTANCE = new GlueCodeContext(); | ||
private final Map<String, Object> objects = new HashMap<String, Object>(); | ||
private final Map<String, Runnable> callbacks = new HashMap<String, Runnable>(); | ||
private int counter; | ||
|
||
private GlueCodeContext() { | ||
} | ||
|
||
public void start () { | ||
cleanUp(); | ||
counter++; | ||
} | ||
|
||
public String getCounter() { | ||
return "cucumber_glue_"+ counter; | ||
} | ||
|
||
public void stop() { | ||
for (Runnable callback : callbacks.values()) { | ||
callback.run(); | ||
} | ||
cleanUp(); | ||
} | ||
|
||
public Object get(String name){ | ||
return objects.get(name); | ||
} | ||
|
||
public void put(String name, Object object){ | ||
objects.put(name, object); | ||
} | ||
|
||
public Object remove (String name){ | ||
callbacks.remove(name); | ||
return objects.remove(name); | ||
} | ||
|
||
|
||
|
||
private void cleanUp() { | ||
objects.clear(); | ||
callbacks.clear(); | ||
} | ||
|
||
|
||
public void registerDestructionCallback(String name, Runnable callback) { | ||
callbacks.put(name, callback); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
spring/src/main/java/cucumber/runtime/java/spring/GlueCodeScope.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,41 @@ | ||
package cucumber.runtime.java.spring; | ||
|
||
import org.springframework.beans.factory.ObjectFactory; | ||
import org.springframework.beans.factory.config.Scope; | ||
|
||
public class GlueCodeScope implements Scope { | ||
public static final String NAME = "cucumber-glue"; | ||
|
||
private final GlueCodeContext context = GlueCodeContext.INSTANCE; | ||
|
||
@Override | ||
public Object get(String name, ObjectFactory<?> objectFactory) { | ||
Object obj = context.get(name); | ||
if (obj == null) { | ||
obj = objectFactory.getObject(); | ||
context.put(name, obj); | ||
} | ||
|
||
return obj; | ||
} | ||
|
||
@Override | ||
public Object remove(String name) { | ||
return context.remove(name); | ||
} | ||
|
||
@Override | ||
public void registerDestructionCallback(String name, Runnable callback) { | ||
context.registerDestructionCallback(name, callback); | ||
} | ||
|
||
@Override | ||
public Object resolveContextualObject(String key) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getConversationId() { | ||
return context.getCounter(); | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.