com.consol.citrus.http.message.HttpMessageHeaders Java Examples

The following examples show how to use com.consol.citrus.http.message.HttpMessageHeaders. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PetstoreConfiguration.java    From yaks with Apache License 2.0 6 votes vote down vote up
@Bean
public EndpointAdapter staticResponseAdapter(TestContextFactory contextFactory) {
    RequestDispatchingEndpointAdapter dispatchingEndpointAdapter = new RequestDispatchingEndpointAdapter();

    Map<String, EndpointAdapter> mappings = new HashMap<>();

    mappings.put(HttpMethod.GET.name(), handleGetRequestAdapter(contextFactory));
    mappings.put(HttpMethod.POST.name(), handlePostRequestAdapter());
    mappings.put(HttpMethod.PUT.name(), handlePutRequestAdapter());
    mappings.put(HttpMethod.DELETE.name(), handleDeleteRequestAdapter());

    SimpleMappingStrategy mappingStrategy = new SimpleMappingStrategy();
    mappingStrategy.setAdapterMappings(mappings);
    dispatchingEndpointAdapter.setMappingStrategy(mappingStrategy);

    dispatchingEndpointAdapter.setMappingKeyExtractor(new HeaderMappingKeyExtractor(HttpMessageHeaders.HTTP_REQUEST_METHOD));

    return dispatchingEndpointAdapter;
}
 
Example #2
Source File: HttpEndpointConfiguration.java    From yaks with Apache License 2.0 6 votes vote down vote up
@Bean
public EndpointAdapter staticResponseAdapter(TestContextFactory contextFactory) {
    RequestDispatchingEndpointAdapter dispatchingEndpointAdapter = new RequestDispatchingEndpointAdapter();

    Map<String, EndpointAdapter> mappings = new HashMap<>();

    mappings.put(HttpMethod.GET.name(), handleGetRequestAdapter(contextFactory));
    mappings.put(HttpMethod.HEAD.name(), handleHeadRequestAdapter(contextFactory));
    mappings.put(HttpMethod.POST.name(), handlePostRequestAdapter());
    mappings.put(HttpMethod.PUT.name(), handlePutRequestAdapter());
    mappings.put(HttpMethod.DELETE.name(), handleDeleteRequestAdapter());

    SimpleMappingStrategy mappingStrategy = new SimpleMappingStrategy();
    mappingStrategy.setAdapterMappings(mappings);
    dispatchingEndpointAdapter.setMappingStrategy(mappingStrategy);

    dispatchingEndpointAdapter.setMappingKeyExtractor(new HeaderMappingKeyExtractor(HttpMessageHeaders.HTTP_REQUEST_METHOD));

    return dispatchingEndpointAdapter;
}
 
Example #3
Source File: HttpEndpointConfiguration.java    From yaks with Apache License 2.0 5 votes vote down vote up
@Bean
public EndpointAdapter handleGetRequestAdapter(TestContextFactory contextFactory) {
    StaticResponseEndpointAdapter responseEndpointAdapter = new StaticResponseEndpointAdapter();
    responseEndpointAdapter.getMessageHeader().put(HttpMessageHeaders.HTTP_CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
    responseEndpointAdapter.getMessageHeader().put("X-TodoId", "citrus:randomNumber(5)");
    responseEndpointAdapter.setMessagePayload("{\"id\": \"citrus:randomNumber(5)\", \"task\": \"Sample task\", \"completed\": 0}");
    responseEndpointAdapter.setTestContextFactory(contextFactory);
    return responseEndpointAdapter;
}
 
Example #4
Source File: HttpEndpointConfiguration.java    From yaks with Apache License 2.0 5 votes vote down vote up
@Bean
public EndpointAdapter handleHeadRequestAdapter(TestContextFactory contextFactory) {
    StaticResponseEndpointAdapter responseEndpointAdapter = new StaticResponseEndpointAdapter();
    responseEndpointAdapter.getMessageHeader().put(HttpMessageHeaders.HTTP_CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
    responseEndpointAdapter.getMessageHeader().put("X-TodoId", "citrus:randomNumber(5)");
    responseEndpointAdapter.setTestContextFactory(contextFactory);
    return responseEndpointAdapter;
}
 
Example #5
Source File: PetstoreConfiguration.java    From yaks with Apache License 2.0 4 votes vote down vote up
@Bean
public EndpointAdapter handleGetRequestAdapter(TestContextFactory contextFactory) {
    StaticEndpointAdapter endpointAdapter = new StaticResponseEndpointAdapter() {
        private TestContext context;

        @Override
        public Message handleMessageInternal(Message request) {
            context = super.getTestContext();
            getMessageHeader().clear();
            setMessagePayload("");

            String requestUri = Optional.ofNullable(request.getHeader(HttpMessageHeaders.HTTP_REQUEST_URI))
                                        .map(Object::toString)
                                        .orElse("/openapi.json");

            if (requestUri.endsWith("/v2/openapi.json")) {
                 setMessagePayload("citrus:readFile('classpath:org/citrusframework/yaks/openapi/petstore-v2.json')");
            } else if (requestUri.endsWith("/v3/openapi.json")) {
                 setMessagePayload("citrus:readFile('classpath:org/citrusframework/yaks/openapi/petstore-v3.json')");
            } else {
                int petId = Integer.parseInt(requestUri.substring(requestUri.lastIndexOf("/") + 1));
                getMessageHeader().put(HttpMessageHeaders.HTTP_CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);

                if (petId > 0) {
                    getTestContext().setVariable("petId", petId);
                    setMessagePayload("citrus:readFile('classpath:org/citrusframework/yaks/openapi/pet.json')");
                } else {
                    getMessageHeader().put(HttpMessageHeaders.HTTP_STATUS_CODE, HttpStatus.NOT_FOUND);
                }
            }

            return super.handleMessageInternal(request);
        }

        @Override
        protected TestContext getTestContext() {
            if (context == null) {
                context = super.getTestContext();
            }
            return context;
        }
    };

    endpointAdapter.setTestContextFactory(contextFactory);
    return endpointAdapter;
}
 
Example #6
Source File: SendRequestActionConverter.java    From citrus-admin with Apache License 2.0 4 votes vote down vote up
@Override
public SendRequestModel convertModel(SendMessageAction model) {
    SendRequestModel action = new ObjectFactory().createSendRequestModel();

    if (model.getActor() != null) {
        action.setActor(model.getActor().getName());
    } else if (model.getEndpoint() != null && model.getEndpoint().getActor() != null) {
        action.setActor(model.getEndpoint().getActor().getName());
    }

    action.setClient(model.getEndpoint() != null ? model.getEndpoint().getName() : model.getEndpointUri());
    ClientRequestType request = new ClientRequestType();
    request.setDescription(model.getDescription());

    String method = RequestMethod.POST.name();
    if (model.getMessageBuilder() instanceof StaticMessageContentBuilder) {
        method = ((StaticMessageContentBuilder) model.getMessageBuilder()).getMessage().getHeader(HttpMessageHeaders.HTTP_REQUEST_METHOD).toString();
    } else if (model.getMessageBuilder() instanceof PayloadTemplateMessageBuilder) {
        if (((PayloadTemplateMessageBuilder) model.getMessageBuilder()).getMessageHeaders().containsKey(HttpMessageHeaders.HTTP_REQUEST_METHOD)) {
            method = ((PayloadTemplateMessageBuilder) model.getMessageBuilder()).getMessageHeaders().get(HttpMessageHeaders.HTTP_REQUEST_METHOD).toString();
        }
    }

    if (RequestMethod.GET.name().equals(method)) {
        action.setGET(request);
    } else if (RequestMethod.POST.name().equals(method)) {
        action.setPOST(request);
    } else if (RequestMethod.PUT.name().equals(method)) {
        action.setPUT(request);
    } else if (RequestMethod.DELETE.name().equals(method)) {
        action.setDELETE(request);
    } else if (RequestMethod.HEAD.name().equals(method)) {
        action.setHEAD(request);
    } else if (RequestMethod.OPTIONS.name().equals(method)) {
        action.setPOST(request);
    } else if (RequestMethod.PATCH.name().equals(method)) {
        action.setPATCH(request);
    } else if (RequestMethod.TRACE.name().equals(method)) {
        action.setTRACE(request);
    }

    action.setFork(model.isForkMode());

    return action;
}
 
Example #7
Source File: ReceiveRequestActionConverter.java    From citrus-admin with Apache License 2.0 4 votes vote down vote up
@Override
public ReceiveRequestModel convertModel(ReceiveMessageAction model) {
    ReceiveRequestModel action = new ObjectFactory().createReceiveRequestModel();

    if (model.getActor() != null) {
        action.setActor(model.getActor().getName());
    } else if (model.getEndpoint() != null && model.getEndpoint().getActor() != null) {
        action.setActor(model.getEndpoint().getActor().getName());
    }

    action.setServer(model.getEndpoint() != null ? model.getEndpoint().getName() : model.getEndpointUri());
    ServerRequestType request = new ServerRequestType();
    request.setDescription(model.getDescription());

    String method = RequestMethod.POST.name();
    if (model.getMessageBuilder() instanceof StaticMessageContentBuilder) {
        method = ((StaticMessageContentBuilder) model.getMessageBuilder()).getMessage().getHeader(HttpMessageHeaders.HTTP_REQUEST_METHOD).toString();
    } else if (model.getMessageBuilder() instanceof PayloadTemplateMessageBuilder) {
        if (((PayloadTemplateMessageBuilder) model.getMessageBuilder()).getMessageHeaders().containsKey(HttpMessageHeaders.HTTP_REQUEST_METHOD)) {
            method = ((PayloadTemplateMessageBuilder) model.getMessageBuilder()).getMessageHeaders().get(HttpMessageHeaders.HTTP_REQUEST_METHOD).toString();
        }
    }

    if (RequestMethod.GET.name().equals(method)) {
        action.setGET(request);
    } else if (RequestMethod.POST.name().equals(method)) {
        action.setPOST(request);
    } else if (RequestMethod.PUT.name().equals(method)) {
        action.setPUT(request);
    } else if (RequestMethod.DELETE.name().equals(method)) {
        action.setDELETE(request);
    } else if (RequestMethod.HEAD.name().equals(method)) {
        action.setHEAD(request);
    } else if (RequestMethod.OPTIONS.name().equals(method)) {
        action.setPOST(request);
    } else if (RequestMethod.PATCH.name().equals(method)) {
        action.setPATCH(request);
    } else if (RequestMethod.TRACE.name().equals(method)) {
        action.setTRACE(request);
    }

    return action;
}