Skip to content
This repository has been archived by the owner on Aug 13, 2020. It is now read-only.

Commit

Permalink
Merge 9796a63 into be34692
Browse files Browse the repository at this point in the history
  • Loading branch information
purple52 committed Apr 21, 2016
2 parents be34692 + 9796a63 commit fd83d32
Show file tree
Hide file tree
Showing 52 changed files with 2,138 additions and 347 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ bower_components/
pom.xml~
.gitignore~
activemq-data/
.sonar

### SublimeText ###
# cache files for sublime text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.raml.model.ActionType;

import static org.raml.model.ActionType.GET;
import static org.raml.model.ActionType.HEAD;
Expand Down Expand Up @@ -56,7 +55,7 @@ public void shouldThrowExceptionIfMediaTypeNotSet() throws Exception {

validator.validate(raml()
.with(resource()
.with(action().with(ActionType.POST)))
.with(action().withActionType(POST)))
.build());

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
import org.raml.model.Action;
import org.raml.model.ActionType;
import org.raml.model.MimeType;
import org.raml.model.ParamType;
import org.raml.model.Response;
import org.raml.model.parameter.QueryParameter;

import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import static java.util.Arrays.stream;
import static org.raml.model.ActionType.GET;
import static org.raml.model.ActionType.POST;
import static org.raml.model.ParamType.STRING;

public class ActionBuilder {
private ActionType actionType;
private final Map<String, MimeType> body = new HashMap<>();
Expand All @@ -23,29 +26,37 @@ public static ActionBuilder action() {
return new ActionBuilder();
}

public static ActionBuilder defaultPostAction() {
return action(POST, "application/vnd.structure.command.test-cmd+json");
}

public static ActionBuilder defaultGetAction() {
return action().withActionType(GET).withDefaultResponseType();
}

public static ActionBuilder action(final ActionType actionType, final String... mimeTypes) {
ActionBuilder actionBuilder = new ActionBuilder()
.with(actionType);
.withActionType(actionType);
for (String mimeType : mimeTypes) {
actionBuilder = actionBuilder.withMediaType(mimeType);
}
return actionBuilder;
}

public ActionBuilder with(final ActionType actionType) {
public ActionBuilder withActionType(final ActionType actionType) {
this.actionType = actionType;
return this;
}

public ActionBuilder withDefaultRequestType() {
public ActionBuilder withActionOfDefaultRequestType() {
return withMediaType("application/vnd.ctx.command.defcmd+json");
}

public ActionBuilder withDefaultResponseType() {
return withResponse("application/vnd.ctx.query.defquery+json");
return withActionWithResponseTypes("application/vnd.ctx.query.defquery+json");
}

public ActionBuilder withResponse(final String... responseTypes) {
public ActionBuilder withActionWithResponseTypes(final String... responseTypes) {
Response response = new Response();
Map<String, MimeType> respBody = new HashMap<>();
for (String responseType : responseTypes) {
Expand All @@ -56,12 +67,17 @@ public ActionBuilder withResponse(final String... responseTypes) {
return this;
}

public ActionBuilder withQueryParameters(final String... queryParameters) {
Arrays.stream(queryParameters).forEach(s -> {
public ActionBuilder withQueryParameters(final QueryParameter... queryParameters) {
stream(queryParameters).forEach(queryParameter -> this.queryParameters.put(queryParameter.getDisplayName(), queryParameter));
return this;
}

public ActionBuilder withQueryParameters(final String... paramNames) {
stream(paramNames).forEach(paramName -> {
QueryParameter queryParameter = new QueryParameter();
queryParameter.setDisplayName(s);
queryParameter.setType(ParamType.STRING);
this.queryParameters.put(s, queryParameter);
queryParameter.setDisplayName(paramName);
queryParameter.setType(STRING);
this.queryParameters.put(paramName, queryParameter);
});

return this;
Expand All @@ -82,7 +98,7 @@ public Action build() {
action.setBody(body);

HashMap<String, Response> responsesMap = new HashMap<>();
this.responses.forEach(r -> responsesMap.put("", r));
this.responses.forEach(r -> responsesMap.put("200", r));
action.setResponses(responsesMap);

action.setQueryParameters(queryParameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

import static org.raml.model.ActionType.POST;
import static uk.gov.justice.services.adapters.test.utils.builder.ActionBuilder.action;
import static uk.gov.justice.services.adapters.test.utils.builder.ResourceBuilder.defaultGetResource;
import static uk.gov.justice.services.adapters.test.utils.builder.ResourceBuilder.defaultPostResource;
import static uk.gov.justice.services.adapters.test.utils.builder.ResourceBuilder.resource;

public class RamlBuilder {
Expand Down Expand Up @@ -55,12 +57,20 @@ public RamlBuilder with(final ResourceBuilder resource) {
return this;
}

public RamlBuilder withDefaultPostResource() {
return this.with(defaultPostResource());
}

public RamlBuilder withDefaultGetResource() {
return this.with(defaultGetResource());
}

public RamlBuilder withDefaultMessagingResource() {
return this
.withDefaultMessagingBaseUri()
.with(resource()
.withRelativeUri("/somecontext.controller.command")
.with(action(POST,"application/vnd.somecontext.command.command1+json")));
.withRelativeUri("/somecontext.controller.command")
.with(action(POST, "application/vnd.somecontext.command.command1+json")));
}

public RamlBuilder withVersion(final String version) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import java.util.List;
import java.util.Map;

import static org.raml.model.ActionType.POST;
import static uk.gov.justice.services.adapters.test.utils.builder.ActionBuilder.action;
import static uk.gov.justice.services.adapters.test.utils.builder.ActionBuilder.defaultGetAction;
import static uk.gov.justice.services.adapters.test.utils.builder.ActionBuilder.defaultPostAction;

public class ResourceBuilder {
private final List<ActionBuilder> actionBuilders = new ArrayList<>();
Expand All @@ -33,13 +33,25 @@ public static ResourceBuilder resource(final String relativeUri, final String...
return resourceBuilder;
}

public static ResourceBuilder defaultPostResource() {
return resource("/some/path/{recipeId}")
.with(defaultPostAction());

}

public static ResourceBuilder defaultGetResource() {
return resource("/some/path/{recipeId}")
.with(defaultGetAction());

}

public ResourceBuilder with(final ActionBuilder action) {
actionBuilders.add(action);
return this;
}

public ResourceBuilder withDefaultAction() {
with(action(POST, "application/vnd.structure.command.test-cmd+json"));
with(defaultPostAction());
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;

public class GeneratorConfigUtil {

public static GeneratorConfig configurationWithBasePackage(String basePackageName, TemporaryFolder outputFolder) {
public static GeneratorConfig configurationWithBasePackage(final String basePackageName,
final TemporaryFolder outputFolder,
final Map<String, String> generatorProperties) {
Path outputPath = Paths.get(outputFolder.getRoot().getAbsolutePath());
return new GeneratorConfig(outputPath, outputPath, basePackageName);
return new GeneratorConfig(outputPath, outputPath, basePackageName, generatorProperties);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package uk.gov.justice.raml.jms.validator;

import org.raml.model.Raml;

import uk.gov.justice.raml.common.validator.RamlValidationException;
import uk.gov.justice.raml.common.validator.RamlValidator;
import uk.gov.justice.raml.jms.uri.BaseUri;
Expand All @@ -9,11 +10,11 @@
import static org.apache.commons.lang3.StringUtils.isEmpty;

/**
* Checks if @Raml contain base uris that correctly adeheres to the framework's standard
* Checks if RAML contain base uris that correctly adheres to the framework's standard.
*
*/
public class BaseUriRamlValidator implements RamlValidator {
private static final String ERROR_MSG = "Inavlid base uri: %s";
private static final String ERROR_MSG = "Invalid base uri: %s";
private static final String BASE_URI_NOT_SET_MSG = "Base uri not set";

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.raml.model.ActionType;

import uk.gov.justice.raml.common.validator.RamlValidationException;
import uk.gov.justice.raml.core.Generator;

import static java.util.Collections.emptyMap;
import static org.raml.model.ActionType.POST;
import static uk.gov.justice.services.adapters.test.utils.builder.ActionBuilder.action;
import static uk.gov.justice.services.adapters.test.utils.builder.RamlBuilder.raml;
import static uk.gov.justice.services.adapters.test.utils.builder.ResourceBuilder.resource;
import static uk.gov.justice.services.adapters.test.utils.config.GeneratorConfigUtil.configurationWithBasePackage;


public class JmsEndpointGeneratorErrorHandlingTest {

private static final String BASE_PACKAGE = "uk.test";
Expand All @@ -38,7 +40,7 @@ public void shouldThrowExceptionIfInvalidTierPassedInUri() throws Exception {
.withRelativeUri("/structure.unknowntier.command")
.withDefaultAction())
.build(),
configurationWithBasePackage(BASE_PACKAGE, outputFolder));
configurationWithBasePackage(BASE_PACKAGE, outputFolder, emptyMap()));
}

@Test
Expand All @@ -51,9 +53,10 @@ public void shouldThrowExceptionIfInvalidPillarPassedInUri() throws Exception {
raml()
.with(resource()
.withRelativeUri("/lifecycle.controller.unknown")
.withDefaultAction())
.withDefaultAction()
)
.build(),
configurationWithBasePackage(BASE_PACKAGE, outputFolder));
configurationWithBasePackage(BASE_PACKAGE, outputFolder, emptyMap()));
}

@Test
Expand All @@ -68,7 +71,7 @@ public void shouldThrowExceptionIfNoPillarPassedInUri() throws Exception {
.withRelativeUri("/structure.controller")
.withDefaultAction())
.build(),
configurationWithBasePackage(BASE_PACKAGE, outputFolder));
configurationWithBasePackage(BASE_PACKAGE, outputFolder, emptyMap()));
}

@Test
Expand All @@ -79,7 +82,7 @@ public void shouldThrowExceptionIfNoResourcesInRaml() throws Exception {

generator.run(
raml().build(),
configurationWithBasePackage(BASE_PACKAGE, outputFolder));
configurationWithBasePackage(BASE_PACKAGE, outputFolder, emptyMap()));

}

Expand All @@ -94,7 +97,7 @@ public void shouldThrowExceptionIfNoActionsInRaml() throws Exception {
.with(resource()
.withRelativeUri("/structure.controller.command"))
.build(),
configurationWithBasePackage(BASE_PACKAGE, outputFolder));
configurationWithBasePackage(BASE_PACKAGE, outputFolder, emptyMap()));
}

@Test
Expand All @@ -106,9 +109,9 @@ public void shouldThrowExceptionIfMediaTypeNotSet() throws Exception {
generator.run(
raml()
.with(resource()
.with(action().with(ActionType.POST)))
.with(action().withActionType(POST)))
.build(),
configurationWithBasePackage(BASE_PACKAGE, outputFolder));
configurationWithBasePackage(BASE_PACKAGE, outputFolder, emptyMap()));

}

Expand All @@ -123,7 +126,7 @@ public void shouldThrowExceptionIfMediaTypeDoesNotContainAValidCommand() throws
.with(resource()
.with(action(POST, "application/vnd.people.unknown.command1+json")))
.build(),
configurationWithBasePackage(BASE_PACKAGE, outputFolder));
configurationWithBasePackage(BASE_PACKAGE, outputFolder, emptyMap()));

}

Expand All @@ -138,26 +141,26 @@ public void shouldThrowExceptionIfNotvalidMediaType() throws Exception {
.with(resource()
.with(action(POST, "nd.people.unknown.command1+json")))
.build(),
configurationWithBasePackage(BASE_PACKAGE, outputFolder));
configurationWithBasePackage(BASE_PACKAGE, outputFolder, emptyMap()));

}

@Test
public void shouldThrowExceptionIfOneOfMediaTypesNotValid() throws Exception {

exception.expect(RamlValidationException.class);
exception.expectMessage("Invalid request type: application/vnd.people.commaod.command1+json");
exception.expectMessage("Invalid request type: application/vnd.people.commaods.command1+json");

generator.run(
raml()
.with(resource()
.with(action()
.with(ActionType.POST)
.withMediaType("application/vnd.people.commaod.command1+json")
.withActionType(POST)
.withMediaType("application/vnd.people.commaods.command1+json")
.withMediaType("application/vnd.people.command.command1+json")
))
.build(),
configurationWithBasePackage(BASE_PACKAGE, outputFolder));
configurationWithBasePackage(BASE_PACKAGE, outputFolder, emptyMap()));

}

Expand All @@ -173,15 +176,15 @@ public void shouldThrowExceptionWhenBaseUriNotSetWhileGeneratingEventListener()
.withRelativeUri("/structure.event")
.withDefaultAction())
.build(),
configurationWithBasePackage("uk.somepackage", outputFolder));
configurationWithBasePackage("uk.somepackage", outputFolder, emptyMap()));


}

@Test
public void shouldThrowExceptionWhenInvalidBaseUriWhileGeneratingEventListener() throws Exception {
exception.expect(RamlValidationException.class);
exception.expectMessage("Inavlid base uri: message://too/short/uri");
exception.expectMessage("Invalid base uri: message://too/short/uri");

generator.run(
raml()
Expand All @@ -190,7 +193,7 @@ public void shouldThrowExceptionWhenInvalidBaseUriWhileGeneratingEventListener()
.withRelativeUri("/structure.event")
.withDefaultAction())
.build(),
configurationWithBasePackage("uk.somepackage", outputFolder));
configurationWithBasePackage("uk.somepackage", outputFolder, emptyMap()));


}
Expand Down
Loading

0 comments on commit fd83d32

Please sign in to comment.