This repository has been archived by the owner on Aug 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
1,236 additions
and
1 deletion.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
...tils/src/main/java/uk/gov/justice/services/adapters/test/utils/builder/ActionBuilder.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,47 @@ | ||
package uk.gov.justice.services.adapters.test.utils.builder; | ||
|
||
import org.raml.model.Action; | ||
import org.raml.model.ActionType; | ||
import org.raml.model.MimeType; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class ActionBuilder { | ||
private ActionType actionType; | ||
private final Map<String, MimeType> body = new HashMap<>(); | ||
|
||
public static ActionBuilder action() { | ||
return new ActionBuilder(); | ||
} | ||
|
||
public static ActionBuilder action(final ActionType actionType, final String... mimeTypes) { | ||
ActionBuilder actionBuilder = new ActionBuilder() | ||
.with(actionType); | ||
for (String mimeType: mimeTypes) { | ||
actionBuilder = actionBuilder.withMediaType(mimeType); | ||
} | ||
return actionBuilder; | ||
} | ||
|
||
public ActionBuilder with(final ActionType actionType) { | ||
this.actionType = actionType; | ||
return this; | ||
} | ||
|
||
public ActionBuilder withMediaType(final MimeType mimeType) { | ||
body.put(mimeType.toString(), mimeType); | ||
return this; | ||
} | ||
public ActionBuilder withMediaType(String stringMimeType) { | ||
return withMediaType(new MimeType(stringMimeType)); | ||
} | ||
|
||
public Action build() { | ||
final Action action = new Action(); | ||
action.setType(actionType); | ||
action.setBody(body); | ||
return action; | ||
} | ||
|
||
} |
73 changes: 73 additions & 0 deletions
73
...-utils/src/main/java/uk/gov/justice/services/adapters/test/utils/builder/RamlBuilder.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,73 @@ | ||
package uk.gov.justice.services.adapters.test.utils.builder; | ||
|
||
import org.raml.model.ActionType; | ||
import org.raml.model.Raml; | ||
import org.raml.model.Resource; | ||
|
||
import static uk.gov.justice.services.adapters.test.utils.builder.ActionBuilder.action; | ||
import static uk.gov.justice.services.adapters.test.utils.builder.ResourceBuilder.resource; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class RamlBuilder { | ||
private final List<ResourceBuilder> resourceBuilders = new ArrayList<>(); | ||
private String version; | ||
private String title; | ||
private String baseUri; | ||
|
||
public static RamlBuilder raml() { | ||
return new RamlBuilder(); | ||
} | ||
|
||
public static RamlBuilder restRamlWithDefaults() { | ||
return new RamlBuilder() | ||
.withVersion("#%RAML 0.8") | ||
.withTitle("Example Service"); | ||
} | ||
|
||
public RamlBuilder with(final ResourceBuilder resource) { | ||
resourceBuilders.add(resource); | ||
return this; | ||
} | ||
|
||
public RamlBuilder withDefaults() { | ||
return this.with(resource() | ||
.withRelativeUri("/somecontext.controller.commands") | ||
.with(action().with(ActionType.POST))); | ||
} | ||
|
||
public RamlBuilder withVersion(final String version) { | ||
this.version = version; | ||
return this; | ||
} | ||
|
||
public RamlBuilder withTitle(final String title) { | ||
this.title = title; | ||
return this; | ||
} | ||
|
||
public RamlBuilder withBaseUri(final String baseUri) { | ||
this.baseUri = baseUri; | ||
return this; | ||
} | ||
|
||
public Raml build() { | ||
Raml raml = new Raml(); | ||
|
||
raml.setBaseUri(baseUri); | ||
raml.setVersion(version); | ||
raml.setTitle(title); | ||
|
||
Map<String, Resource> resources = new HashMap<>(); | ||
for (ResourceBuilder resourceBuilder : resourceBuilders) { | ||
Resource resource = resourceBuilder.build(); | ||
resources.put(resource.getRelativeUri(), resource); | ||
} | ||
|
||
raml.setResources(resources); | ||
return raml; | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...ls/src/main/java/uk/gov/justice/services/adapters/test/utils/builder/ResourceBuilder.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,70 @@ | ||
package uk.gov.justice.services.adapters.test.utils.builder; | ||
|
||
import org.raml.model.Action; | ||
import org.raml.model.ActionType; | ||
import org.raml.model.Resource; | ||
import org.raml.model.parameter.UriParameter; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import static uk.gov.justice.services.adapters.test.utils.builder.ActionBuilder.action; | ||
|
||
public class ResourceBuilder { | ||
private final List<ActionBuilder> actionBuilders = new ArrayList<>(); | ||
|
||
private String parentUri = ""; | ||
private String relativeUri = "/somecontext.controller.commands"; | ||
private Map<String, UriParameter> uriParameters = new HashMap<>(); | ||
|
||
public static ResourceBuilder resource() { | ||
return new ResourceBuilder(); | ||
} | ||
|
||
public static ResourceBuilder resource(final String relativeUri, final String... pathParams) { | ||
ResourceBuilder resourceBuilder = new ResourceBuilder() | ||
.withRelativeUri(relativeUri); | ||
for(String pathParam: pathParams) { | ||
resourceBuilder = resourceBuilder.withPathParam(pathParam); | ||
} | ||
return resourceBuilder; | ||
} | ||
|
||
public ResourceBuilder with(final ActionBuilder action) { | ||
actionBuilders.add(action); | ||
return this; | ||
} | ||
|
||
public ResourceBuilder withRelativeUri(final String uri) { | ||
relativeUri = uri; | ||
return this; | ||
} | ||
|
||
public ResourceBuilder withPathParam(final String name) { | ||
uriParameters.put(name, new UriParameter(name)); | ||
return this; | ||
} | ||
|
||
public Resource build() { | ||
final Resource resource = new Resource(); | ||
resource.setParentUri(parentUri); | ||
resource.setRelativeUri(relativeUri); | ||
resource.setUriParameters(uriParameters); | ||
|
||
Map<ActionType, Action> actions = new HashMap<>(); | ||
for (ActionBuilder actionBuilder : actionBuilders) { | ||
Action action = actionBuilder.build(); | ||
action.setResource(resource); | ||
actions.put(action.getType(), action); | ||
} | ||
|
||
resource.setActions(actions); | ||
return resource; | ||
} | ||
|
||
public ResourceBuilder withDefaultAction() { | ||
with(action().with(ActionType.POST)); | ||
return this; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...src/main/java/uk/gov/justice/services/adapters/test/utils/compiler/AllObjectsScanner.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,30 @@ | ||
package uk.gov.justice.services.adapters.test.utils.compiler; | ||
|
||
import org.reflections.scanners.SubTypesScanner; | ||
|
||
/** | ||
* Extension of the reflection API to scan for all classes | ||
* | ||
*/ | ||
public class AllObjectsScanner extends SubTypesScanner { | ||
|
||
public AllObjectsScanner() { | ||
super(false); | ||
} | ||
|
||
|
||
/** | ||
* Accepts all classes and puts them in the store as subclasses of @Object | ||
* | ||
*/ | ||
@SuppressWarnings({"unchecked"}) | ||
public void scan(final Object cls) { | ||
String className = getMetadataAdapter().getClassName(cls); | ||
String superclass = Object.class.getName(); | ||
|
||
if (acceptResult(superclass)) { | ||
getStore().put(superclass, className); | ||
} | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
.../main/java/uk/gov/justice/services/adapters/test/utils/compiler/CompilationException.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,14 @@ | ||
package uk.gov.justice.services.adapters.test.utils.compiler; | ||
|
||
public class CompilationException extends RuntimeException { | ||
private static final long serialVersionUID = 1L; | ||
|
||
public CompilationException(String string) { | ||
super(string); | ||
} | ||
|
||
|
||
public CompilationException(Throwable throwable) { | ||
super(throwable); | ||
} | ||
} |
Oops, something went wrong.