Skip to content

Commit

Permalink
kamelets: create a camel-kamelet component apache#375
Browse files Browse the repository at this point in the history
  • Loading branch information
lburgazzoli committed Aug 13, 2020
1 parent 068e20c commit 5e28277
Show file tree
Hide file tree
Showing 54 changed files with 1,511 additions and 566 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import org.apache.camel.builder.RouteBuilder
import org.apache.camel.impl.DefaultCamelContext
import org.apache.camel.k.Runtime
import org.apache.camel.k.Sources
import org.apache.camel.k.listener.RoutesConfigurer
import org.apache.camel.k.support.SourcesSupport
import org.apache.camel.model.FromDefinition
import org.apache.camel.model.ToDefinition
import spock.lang.Specification
Expand All @@ -35,7 +35,7 @@ class LoaderTest extends Specification {
def source = Sources.fromURI("classpath:routes.groovy")

when:
def loader = RoutesConfigurer.load(runtime, source)
def loader = SourcesSupport.load(runtime, source)

then:
loader instanceof GroovySourceLoader
Expand All @@ -60,7 +60,7 @@ class LoaderTest extends Specification {
def source = Sources.fromURI("classpath:routes-with-endpoint-dsl.groovy")

when:
def loader = RoutesConfigurer.load(runtime, source)
def loader = SourcesSupport.load(runtime, source)

then:
loader instanceof GroovySourceLoader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import spock.lang.Specification

import javax.sql.DataSource

import static org.apache.camel.k.listener.RoutesConfigurer.forRoutes
import static org.apache.camel.k.support.SourcesSupport.forRoutes

class IntegrationTest extends Specification {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.apache.camel.k.Source;
import org.apache.camel.k.SourceLoader;
import org.apache.camel.k.Sources;
import org.apache.camel.k.listener.RoutesConfigurer;
import org.apache.camel.k.support.SourcesSupport;
import org.apache.camel.model.ProcessDefinition;
import org.apache.camel.model.RouteDefinition;
import org.apache.camel.model.SetBodyDefinition;
Expand All @@ -47,7 +47,7 @@ public class RoutesLoaderTest {
public void testLoadJavaWithNestedClass() throws Exception {
TestRuntime runtime = new TestRuntime();
Source source = Sources.fromURI("classpath:MyRoutesWithNestedClass.java");
SourceLoader loader = RoutesConfigurer.load(runtime, source);
SourceLoader loader = SourcesSupport.load(runtime, source);

assertThat(loader).isInstanceOf(JavaSourceLoader.class);
assertThat(runtime.builders).hasSize(1);
Expand All @@ -69,7 +69,7 @@ public void testLoadJavaWithNestedClass() throws Exception {
public void testLoadJavaWithRestConfiguration() throws Exception {
TestRuntime runtime = new TestRuntime();
Source source = Sources.fromURI("classpath:MyRoutesWithRestConfiguration.java");
SourceLoader loader = RoutesConfigurer.load(runtime, source);
SourceLoader loader = SourcesSupport.load(runtime, source);

assertThat(loader).isInstanceOf(JavaSourceLoader.class);
assertThat(runtime.builders).hasSize(1);
Expand All @@ -84,7 +84,7 @@ public void testLoadJavaWithRestConfiguration() throws Exception {
public void testLoadJavaConfiguration() throws Exception {
TestRuntime runtime = new TestRuntime();
Source source = Sources.fromURI("classpath:MyRoutesConfig.java");
SourceLoader loader = RoutesConfigurer.load(runtime, source);
SourceLoader loader = SourcesSupport.load(runtime, source);

assertThat(loader).isInstanceOf(JavaSourceLoader.class);
assertThat(runtime.builders).isEmpty();
Expand All @@ -95,7 +95,7 @@ public void testLoadJavaConfiguration() throws Exception {
public void testLoadJavaWithModel() throws Exception {
TestRuntime runtime = new TestRuntime();
Source source = Sources.fromURI("classpath:MyRoutesWithModel.java");
SourceLoader loader = RoutesConfigurer.load(runtime, source);
SourceLoader loader = SourcesSupport.load(runtime, source);

assertThat(loader).isInstanceOf(JavaSourceLoader.class);
assertThat(runtime.builders).hasSize(1);
Expand All @@ -114,7 +114,7 @@ public void testLoadJavaWithModel() throws Exception {
public void testLoadJavaWithNestedType() throws Exception {
TestRuntime runtime = new TestRuntime();
Source source = Sources.fromURI("classpath:MyRoutesWithNestedTypes.java");
SourceLoader loader = RoutesConfigurer.load(runtime, source);
SourceLoader loader = SourcesSupport.load(runtime, source);

assertThat(loader).isInstanceOf(JavaSourceLoader.class);
assertThat(runtime.builders).hasSize(1);
Expand All @@ -129,7 +129,7 @@ public void testLoadJavaWithNestedType() throws Exception {
public void testLoaders(String location, Class<? extends SourceLoader> type) throws Exception {
TestRuntime runtime = new TestRuntime();
Source source = Sources.fromURI(location);
SourceLoader loader = RoutesConfigurer.load(runtime, source);
SourceLoader loader = SourcesSupport.load(runtime, source);

assertThat(loader).isInstanceOf(type);
assertThat(runtime.builders).hasSize(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.apache.camel.k.Source;
import org.apache.camel.k.SourceLoader;
import org.apache.camel.k.Sources;
import org.apache.camel.k.listener.RoutesConfigurer;
import org.apache.camel.k.support.SourcesSupport;
import org.apache.camel.model.RouteDefinition;
import org.apache.camel.model.ToDefinition;
import org.junit.jupiter.params.ParameterizedTest;
Expand All @@ -44,7 +44,7 @@ public class RoutesLoaderTest {
public void testLoaders(String location, Class<? extends SourceLoader> type) throws Exception {
TestRuntime runtime = new TestRuntime();
Source source = Sources.fromURI(location);
SourceLoader loader = RoutesConfigurer.load(runtime, source);
SourceLoader loader = SourcesSupport.load(runtime, source);

assertThat(loader).isInstanceOf(type);
assertThat(runtime.builders).hasSize(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.apache.camel.component.seda.SedaComponent;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.k.Runtime;
import org.apache.camel.k.listener.RoutesConfigurer;
import org.apache.camel.k.support.SourcesSupport;
import org.apache.camel.model.FromDefinition;
import org.apache.camel.model.ModelCamelContext;
import org.apache.camel.model.RouteDefinition;
Expand Down Expand Up @@ -55,7 +55,7 @@ public void shutDown() {
}

private void configureRoutes(String... routes) {
RoutesConfigurer.forRoutes(routes).accept(Runtime.Phase.ConfigureRoutes, runtime);
SourcesSupport.forRoutes(routes).accept(Runtime.Phase.ConfigureRoutes, runtime);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.apache.camel.k.Runtime;
import org.apache.camel.k.Source;
import org.apache.camel.k.Sources;
import org.apache.camel.k.listener.RoutesConfigurer;
import org.apache.camel.k.support.SourcesSupport;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -33,7 +33,7 @@ public void testLoad() throws Exception {
final Runtime runtime = Runtime.on(context);
final Source source = Sources.fromURI("classpath:routes.kts");

RoutesConfigurer.load(runtime, source);
SourcesSupport.load(runtime, source);

try {
context.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import org.apache.camel.builder.RouteBuilder
import org.apache.camel.impl.DefaultCamelContext
import org.apache.camel.k.Runtime
import org.apache.camel.k.Sources
import org.apache.camel.k.listener.RoutesConfigurer
import org.apache.camel.k.support.SourcesSupport
import org.apache.camel.model.ProcessDefinition
import org.apache.camel.model.ToDefinition
import org.assertj.core.api.Assertions.assertThat
Expand All @@ -35,7 +35,7 @@ class LoaderTest {
fun `load routes`() {
val runtime = TestRuntime()
val source = Sources.fromURI("classpath:routes.kts")
val loader = RoutesConfigurer.load(runtime, source)
val loader = SourcesSupport.load(runtime, source)

assertThat(loader).isInstanceOf(KotlinSourceLoader::class.java)
assertThat(runtime.builders).hasSize(1)
Expand All @@ -56,7 +56,7 @@ class LoaderTest {
fun `load routes with endpoint dsl`() {
val runtime = TestRuntime()
val source = Sources.fromURI("classpath:routes-with-endpoint-dsl.kts")
val loader = RoutesConfigurer.load(runtime, source)
val loader = SourcesSupport.load(runtime, source)

assertThat(loader).isInstanceOf(KotlinSourceLoader::class.java)
assertThat(runtime.builders).hasSize(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.apache.camel.component.log.LogComponent
import org.apache.camel.component.seda.SedaComponent
import org.apache.camel.impl.DefaultCamelContext
import org.apache.camel.k.Runtime
import org.apache.camel.k.listener.RoutesConfigurer.forRoutes
import org.apache.camel.k.support.SourcesSupport.forRoutes
import org.apache.camel.language.bean.BeanLanguage
import org.apache.camel.model.ModelCamelContext
import org.apache.camel.model.rest.GetVerbDefinition
Expand Down
5 changes: 5 additions & 0 deletions camel-k-main/camel-k-runtime-main/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@
<artifactId>camel-k-runtime-knative</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel.k</groupId>
<artifactId>camel-kamelet</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.k.CompositeClassloader;
import org.apache.camel.k.Runtime;
import org.apache.camel.k.support.PropertiesSupport;
import org.apache.camel.main.BaseMainSupport;
import org.apache.camel.main.MainSupport;
import org.apache.camel.main.RoutesCollector;
import org.apache.camel.model.RouteTemplatesDefinition;
import org.apache.camel.model.RoutesDefinition;
import org.apache.camel.model.rest.RestsDefinition;
import org.apache.camel.spi.HasId;
import org.apache.camel.util.function.ThrowingConsumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -103,15 +101,6 @@ public void addListeners(Iterable<Runtime.Listener> listeners) {
}

public void addListener(Runtime.Listener listener) {
if (listener instanceof HasId) {
String id = ((HasId) listener).getId();
if (!id.endsWith(".")) {
id = id + ".";
}

PropertiesSupport.bindProperties(getCamelContext(), listener, id);
}

LOGGER.info("Add listener: {}", listener);

this.listeners.add(listener);
Expand Down
Loading

0 comments on commit 5e28277

Please sign in to comment.