-
Notifications
You must be signed in to change notification settings - Fork 3
Mocks #94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Mocks #94
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
7f0a14a
Mocks PoC
krystian-panek-vmltech a9dbda5
Rename
krystian-panek-vmltech 4e8c857
Mock WIP
krystian-panek-vmltech 6b06b53
Buggy syntax
krystian-panek-vmltech adb3b81
Minor
krystian-panek-vmltech bff5242
Little syntax revert
krystian-panek-vmltech 685cfae
Minor
krystian-panek-vmltech ae82e7c
Syntaxes bug fix
krystian-panek-vmltech 4d13b87
Almost work
krystian-panek-vmltech ac22e58
Mocks work
krystian-panek-vmltech 7d88cb2
Mocks on script list
krystian-panek-vmltech 5dc0c2b
Mock script list / sep
krystian-panek-vmltech bd28d7d
Mock list
krystian-panek-vmltech 7898c6c
Mock state
krystian-panek-vmltech ea16fd6
Desc
krystian-panek-vmltech 063a25e
Mock UI
krystian-panek-vmltech 3609518
Mock help
krystian-panek-vmltech d4569c0
Minor
krystian-panek-vmltech 9d509f6
Code context
krystian-panek-vmltech f3edd0e
Mock UI fixes
krystian-panek-vmltech 9516af3
Mock types
krystian-panek-vmltech b644f42
Mock missing works
krystian-panek-vmltech 2b93071
Mock / resource sibling
krystian-panek-vmltech cd67333
Fmt
krystian-panek-vmltech c955241
Minor
krystian-panek-vmltech b333c0f
Minor
krystian-panek-vmltech File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
94 changes: 94 additions & 0 deletions
94
core/src/main/java/com/vml/es/aem/acm/core/code/CodeContext.java
This file contains hidden or 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,94 @@ | ||
| package com.vml.es.aem.acm.core.code; | ||
|
|
||
| import com.vml.es.aem.acm.core.acl.Acl; | ||
| import com.vml.es.aem.acm.core.code.script.ExtensionScript; | ||
| import com.vml.es.aem.acm.core.format.Formatter; | ||
| import com.vml.es.aem.acm.core.mock.MockContext; | ||
| import com.vml.es.aem.acm.core.osgi.OsgiContext; | ||
| import com.vml.es.aem.acm.core.replication.Activator; | ||
| import com.vml.es.aem.acm.core.repo.Repo; | ||
| import com.vml.es.aem.acm.core.script.ScriptRepository; | ||
| import com.vml.es.aem.acm.core.script.ScriptType; | ||
| import groovy.lang.Binding; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.stream.Collectors; | ||
| import org.apache.sling.api.resource.ResourceResolver; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| public class CodeContext { | ||
|
|
||
| private final OsgiContext osgiContext; | ||
|
|
||
| private final ResourceResolver resourceResolver; | ||
|
|
||
| private final Binding binding; | ||
|
|
||
| private final List<ExtensionScript> extensionScripts; | ||
|
|
||
| public CodeContext(OsgiContext osgiContext, ResourceResolver resourceResolver) { | ||
| this.osgiContext = osgiContext; | ||
| this.resourceResolver = resourceResolver; | ||
| this.binding = createBinding(osgiContext, resourceResolver); | ||
| this.extensionScripts = findExtensionScripts(resourceResolver); | ||
| } | ||
|
|
||
| private List<ExtensionScript> findExtensionScripts(ResourceResolver resourceResolver) { | ||
| return new ScriptRepository(resourceResolver) | ||
| .findAll(ScriptType.EXTENSION) | ||
| .map(s -> new ExtensionScript(this, s)) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| public Binding createBinding(OsgiContext osgiContext, ResourceResolver resourceResolver) { | ||
| Binding result = new Binding(); | ||
|
|
||
| result.setVariable("log", LoggerFactory.getLogger(getClass())); | ||
| result.setVariable("resourceResolver", resourceResolver); | ||
| result.setVariable("osgi", osgiContext); | ||
| result.setVariable("repo", new Repo(resourceResolver)); | ||
| result.setVariable("acl", new Acl(resourceResolver)); | ||
| result.setVariable("formatter", new Formatter()); | ||
| result.setVariable("activator", new Activator(resourceResolver, osgiContext.getReplicator())); | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| public void prepareRun(ExecutionContext executionContext) { | ||
| for (ExtensionScript script : extensionScripts) { | ||
| script.prepareRun(executionContext); | ||
| } | ||
| } | ||
|
|
||
| public void completeRun(Execution execution) { | ||
| for (ExtensionScript script : extensionScripts) { | ||
| script.completeRun(execution); | ||
| } | ||
| } | ||
|
|
||
| public void prepareMock(MockContext mockContext) { | ||
| for (ExtensionScript script : extensionScripts) { | ||
| script.prepareMock(mockContext); | ||
| } | ||
| } | ||
|
|
||
| public Binding getBinding() { | ||
| return binding; | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| public List<Variable> getBindingVariables() { | ||
| Map<String, Object> variables = binding.getVariables(); | ||
| return variables.entrySet().stream() | ||
| .map(entry -> new Variable(entry.getKey(), entry.getValue().getClass())) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| public ResourceResolver getResourceResolver() { | ||
| return resourceResolver; | ||
| } | ||
|
|
||
| public OsgiContext getOsgiContext() { | ||
| return osgiContext; | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now we have single place to define same binding for all type of scripts (including manual/auto/mocks/extensions etc)