Skip to content

Commit

Permalink
Merge pull request #793 from citrusframework/pr/camel-support
Browse files Browse the repository at this point in the history
chore: Improve Apache Camel support
  • Loading branch information
christophd authored Aug 25, 2021
2 parents f2e33eb + 851cb6a commit cb61663
Show file tree
Hide file tree
Showing 30 changed files with 1,891 additions and 219 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2021 the original author or authors.
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.consol.citrus.endpoint;

/**
* @author Christoph Deppisch
*/
@FunctionalInterface
public interface EndpointUriBuilder {

String getUri();
}
11 changes: 11 additions & 0 deletions endpoints/citrus-camel/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-xml</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-endpointdsl</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>jakarta.xml.bind</groupId>
Expand Down Expand Up @@ -79,6 +84,12 @@
<version>${apache.camel.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jsonpath</artifactId>
<version>${apache.camel.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
public class CamelControlBusAction extends AbstractCamelRouteAction {

/** Logger */
private static Logger log = LoggerFactory.getLogger(CamelControlBusAction.class);
private static final Logger LOG = LoggerFactory.getLogger(CamelControlBusAction.class);

/** The control bus action */
private final String action;
Expand Down Expand Up @@ -90,12 +90,12 @@ public void doExecute(TestContext context) {
if (StringUtils.hasText(result)) {
String expectedResult = context.replaceDynamicContentInString(result);

if (log.isDebugEnabled()) {
log.debug(String.format("Validating Camel controlbus response = '%s'", expectedResult));
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("Validating Camel controlbus response = '%s'", expectedResult));
}

ValidationUtils.validateValues(response.getPayload(String.class), expectedResult, "camelControlBusResult", context);
log.info("Validation of Camel controlbus response successful - All values OK");
LOG.info("Validation of Camel controlbus response successful - All values OK");
}
}

Expand Down Expand Up @@ -150,6 +150,23 @@ public static final class Builder extends AbstractCamelRouteAction.Builder<Camel
private String languageExpression = "";
private String result;

/**
* Static entry method for the fluent API.
* @return
*/
public static Builder controlBus() {
return new Builder();
}

/**
* Sets route action to execute.
* @param id
*/
public ControlBusRouteActionBuilder route(String id) {
this.routeId = id;
return new ControlBusRouteActionBuilder(this);
}

/**
* Sets route action to execute.
* @param id
Expand Down Expand Up @@ -208,5 +225,54 @@ public Builder result(String result) {
public CamelControlBusAction build() {
return new CamelControlBusAction(this);
}

/**
* Route action builder
*/
public static class ControlBusRouteActionBuilder {

private final Builder parent;

public ControlBusRouteActionBuilder(Builder builder) {
this.parent = builder;
}

/**
* Performs generic action on the given route.
* @param action
* @return
*/
public Builder action(String action) {
parent.action = action;
return parent;
}

/**
* Start given route.
* @return
*/
public Builder start() {
parent.action = "start";
return parent;
}

/**
* Stop given route.
* @return
*/
public Builder stop() {
parent.action = "stop";
return parent;
}

/**
* Retrieve status of given route.
* @return
*/
public Builder status() {
parent.action = "status";
return parent;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.consol.citrus.camel.actions;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.consol.citrus.TestActionBuilder;
import com.consol.citrus.camel.message.CamelRouteProcessor;
import com.consol.citrus.spi.ReferenceResolver;
import com.consol.citrus.spi.ReferenceResolverAware;
import org.apache.camel.CamelContext;
Expand All @@ -21,7 +18,6 @@ public class CamelRouteActionBuilder implements TestActionBuilder.DelegatingTest
private ReferenceResolver referenceResolver;

private CamelContext camelContext;
private List<String> routeIds = new ArrayList<>();

private TestActionBuilder<? extends AbstractCamelRouteAction> delegate;

Expand All @@ -33,6 +29,15 @@ public static CamelRouteActionBuilder camel() {
return new CamelRouteActionBuilder();
}

/**
* Processor calling given Camel route as part of the message processing.
* @return
*/
public CamelRouteProcessor.Builder processor() {
return CamelRouteProcessor.Builder.route()
.camelContext(camelContext);
}

/**
* Sets the Camel context to use.
* @param camelContext
Expand All @@ -54,25 +59,6 @@ public CamelRouteActionBuilder context(CamelContext camelContext) {
return this;
}

/**
* Adds route ids.
* @param routeIds
* @return
*/
public CamelRouteActionBuilder routes(String... routeIds) {
return routes(Arrays.asList(routeIds));
}

/**
* Add list of route ids.
* @param routeIds
* @return
*/
public CamelRouteActionBuilder routes(List<String> routeIds) {
this.routeIds.addAll(routeIds);
return this;
}

/**
* Creates new Camel routes in route builder.
* @param routeBuilder
Expand All @@ -85,7 +71,6 @@ public CreateCamelRouteAction.Builder create(RouteBuilder routeBuilder) {

CreateCamelRouteAction.Builder builder = new CreateCamelRouteAction.Builder()
.context(getCamelContext())
.routeIds(routeIds)
.route(routeBuilder);

this.delegate = builder;
Expand All @@ -100,7 +85,6 @@ public CreateCamelRouteAction.Builder create(RouteBuilder routeBuilder) {
public CreateCamelRouteAction.Builder create(String routeContext) {
CreateCamelRouteAction.Builder builder = new CreateCamelRouteAction.Builder()
.context(getCamelContext())
.routeIds(routeIds)
.routeContext(routeContext);

this.delegate = builder;
Expand All @@ -113,8 +97,7 @@ public CreateCamelRouteAction.Builder create(String routeContext) {
*/
public CamelControlBusAction.Builder controlBus() {
CamelControlBusAction.Builder builder = new CamelControlBusAction.Builder()
.context(getCamelContext())
.routeIds(routeIds);
.context(getCamelContext());

this.delegate = builder;
return builder;
Expand All @@ -126,7 +109,6 @@ public CamelControlBusAction.Builder controlBus() {
public StartCamelRouteAction.Builder start(String ... routes) {
StartCamelRouteAction.Builder builder = new StartCamelRouteAction.Builder()
.context(getCamelContext())
.routeIds(routeIds)
.routes(routes);

this.delegate = builder;
Expand All @@ -139,7 +121,6 @@ public StartCamelRouteAction.Builder start(String ... routes) {
public StopCamelRouteAction.Builder stop(String ... routes) {
StopCamelRouteAction.Builder builder = new StopCamelRouteAction.Builder()
.context(getCamelContext())
.routeIds(routeIds)
.routes(routes);

this.delegate = builder;
Expand All @@ -152,7 +133,6 @@ public StopCamelRouteAction.Builder stop(String ... routes) {
public RemoveCamelRouteAction.Builder remove(String ... routes) {
RemoveCamelRouteAction.Builder builder = new RemoveCamelRouteAction.Builder()
.context(getCamelContext())
.routeIds(routeIds)
.routes(routes);

this.delegate = builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public String getRouteContext() {
*/
public static final class Builder extends AbstractCamelRouteAction.Builder<CreateCamelRouteAction, Builder> {

private List<RouteDefinition> routes = new ArrayList<>();
private final List<RouteDefinition> routes = new ArrayList<>();
private String routeContext;

public Builder route(RouteBuilder routeBuilder) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2021 the original author or authors.
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.consol.citrus.camel.dsl;

import org.apache.camel.CamelContext;

/**
* @author Christoph Deppisch
*/
public interface CamelContextAware<T> {

T camelContext(CamelContext camelContext);
}
Loading

0 comments on commit cb61663

Please sign in to comment.