Search in sources :

Example 16 with Action

use of org.raml.model.Action in project microservice_framework by CJSCommonPlatform.

the class ResourceBuilder method build.

public Resource build() {
    final Resource resource = new Resource();
    resource.setParentUri(parentUri);
    resource.setRelativeUri(relativeUri);
    resource.setUriParameters(uriParameters);
    final Map<ActionType, Action> actions = new HashMap<>();
    for (final HttpActionBuilder httpActionBuilder : httpActionBuilders) {
        final Action action = httpActionBuilder.build();
        action.setResource(resource);
        actions.put(action.getType(), action);
    }
    resource.setActions(actions);
    return resource;
}
Also used : HttpActionBuilder.defaultPostAction(uk.gov.justice.services.generators.test.utils.builder.HttpActionBuilder.defaultPostAction) HttpActionBuilder.defaultGetAction(uk.gov.justice.services.generators.test.utils.builder.HttpActionBuilder.defaultGetAction) HttpActionBuilder.defaultPutAction(uk.gov.justice.services.generators.test.utils.builder.HttpActionBuilder.defaultPutAction) HttpActionBuilder.defaultPatchAction(uk.gov.justice.services.generators.test.utils.builder.HttpActionBuilder.defaultPatchAction) HttpActionBuilder.defaultDeleteAction(uk.gov.justice.services.generators.test.utils.builder.HttpActionBuilder.defaultDeleteAction) Action(org.raml.model.Action) ActionType(org.raml.model.ActionType) HashMap(java.util.HashMap) Resource(org.raml.model.Resource)

Example 17 with Action

use of org.raml.model.Action in project microservice_framework by CJSCommonPlatform.

the class ActionsTest method shouldReturnEmptyListForActionContainingResponseAndNoBodyType.

@Test
public void shouldReturnEmptyListForActionContainingResponseAndNoBodyType() throws Exception {
    final Action action = httpAction().withHttpActionResponseAndNoBody().build();
    assertThat(responseMimeTypesOf(action), equalTo(EMPTY_LIST));
}
Also used : HttpActionBuilder.httpAction(uk.gov.justice.services.generators.test.utils.builder.HttpActionBuilder.httpAction) Action(org.raml.model.Action) Actions.isSynchronousAction(uk.gov.justice.services.generators.commons.helper.Actions.isSynchronousAction) Test(org.junit.Test)

Example 18 with Action

use of org.raml.model.Action in project microservice_framework by CJSCommonPlatform.

the class ActionsTest method shouldReturnFalseIfActionHasResponseTypesWithAcceptedType.

@Test
public void shouldReturnFalseIfActionHasResponseTypesWithAcceptedType() throws Exception {
    final Map<String, Response> responses = new HashMap<>();
    responses.put(valueOf(INTERNAL_SERVER_ERROR.getStatusCode()), response().build());
    responses.put(valueOf(BAD_REQUEST.getStatusCode()), response().build());
    responses.put(valueOf(ACCEPTED.getStatusCode()), response().build());
    final Action action = httpAction().withResponsesFrom(responses).build();
    assertThat(isSynchronousAction(action), equalTo(false));
}
Also used : Response(org.raml.model.Response) HttpActionBuilder.httpAction(uk.gov.justice.services.generators.test.utils.builder.HttpActionBuilder.httpAction) Action(org.raml.model.Action) Actions.isSynchronousAction(uk.gov.justice.services.generators.commons.helper.Actions.isSynchronousAction) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 19 with Action

use of org.raml.model.Action in project microservice_framework by CJSCommonPlatform.

the class NamesTest method shouldBuildResourceMethodNameFromAction.

@Test
public void shouldBuildResourceMethodNameFromAction() throws Exception {
    final MappingBuilder mappingBuilder = mapping().withName("command.create-user").withRequestType("application/vnd.command.create-user+json");
    final Action action = httpAction().withHttpActionType(GET).withDescription(mappingDescriptionWith(mappingBuilder).build()).build();
    action.setResource(resource().withRelativeUri("test").build());
    final String shortMimeType = Names.resourceMethodNameWithNoMimeTypeFrom(action);
    assertThat(shortMimeType, is("getTest"));
}
Also used : HttpActionBuilder.httpAction(uk.gov.justice.services.generators.test.utils.builder.HttpActionBuilder.httpAction) Action(org.raml.model.Action) MappingBuilder(uk.gov.justice.services.generators.test.utils.builder.MappingBuilder) Test(org.junit.Test)

Example 20 with Action

use of org.raml.model.Action in project microservice_framework by CJSCommonPlatform.

the class NamesTest method shouldGenerateCorrectResourceNameForGetWithResponseMimeType.

@Test
public void shouldGenerateCorrectResourceNameForGetWithResponseMimeType() {
    final Action action = HttpActionBuilder.defaultGetAction().withResourceUri("/some/path/{recipeId}/").build();
    final ActionMimeTypeDefinition actionMimeTypeDefinition = ActionMimeTypeDefinition.definitionWithResponse(new MimeType("application/vnd.command.create-user+json"));
    assertThat(Names.buildResourceMethodNameFromVerbUriAndMimeType(action, actionMimeTypeDefinition), equalTo("getSomePathRecipeIdCommandCreateUser"));
}
Also used : ActionMimeTypeDefinition(uk.gov.justice.services.generators.commons.client.ActionMimeTypeDefinition) HttpActionBuilder.httpAction(uk.gov.justice.services.generators.test.utils.builder.HttpActionBuilder.httpAction) Action(org.raml.model.Action) MimeType(org.raml.model.MimeType) Test(org.junit.Test)

Aggregations

Action (org.raml.model.Action)21 Test (org.junit.Test)18 HttpActionBuilder.httpAction (uk.gov.justice.services.generators.test.utils.builder.HttpActionBuilder.httpAction)15 Actions.isSynchronousAction (uk.gov.justice.services.generators.commons.helper.Actions.isSynchronousAction)8 MimeType (org.raml.model.MimeType)6 HashMap (java.util.HashMap)4 Resource (org.raml.model.Resource)4 MappingBuilder (uk.gov.justice.services.generators.test.utils.builder.MappingBuilder)3 Subscription (uk.gov.justice.subscription.domain.Subscription)3 ActionType (org.raml.model.ActionType)2 Response (org.raml.model.Response)2 ActionMimeTypeDefinition (uk.gov.justice.services.generators.commons.client.ActionMimeTypeDefinition)2 TypeSpec (com.squareup.javapoet.TypeSpec)1 HttpActionBuilder.defaultDeleteAction (uk.gov.justice.services.generators.test.utils.builder.HttpActionBuilder.defaultDeleteAction)1 HttpActionBuilder.defaultGetAction (uk.gov.justice.services.generators.test.utils.builder.HttpActionBuilder.defaultGetAction)1 HttpActionBuilder.defaultPatchAction (uk.gov.justice.services.generators.test.utils.builder.HttpActionBuilder.defaultPatchAction)1 HttpActionBuilder.defaultPostAction (uk.gov.justice.services.generators.test.utils.builder.HttpActionBuilder.defaultPostAction)1 HttpActionBuilder.defaultPutAction (uk.gov.justice.services.generators.test.utils.builder.HttpActionBuilder.defaultPutAction)1 Event (uk.gov.justice.subscription.domain.Event)1 SubscriptionDescriptor (uk.gov.justice.subscription.domain.SubscriptionDescriptor)1