-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an option to filter auto-discovered routes #396
- Loading branch information
1 parent
e765b00
commit 68b6096
Showing
12 changed files
with
362 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...ment/src/test/java/org/apache/camel/quarkus/core/deployment/CamelRoutesDiscoveryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* 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 org.apache.camel.quarkus.core.deployment; | ||
|
||
import java.io.IOException; | ||
import java.io.StringWriter; | ||
import java.io.Writer; | ||
import java.util.Properties; | ||
import javax.inject.Inject; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import org.apache.camel.CamelContext; | ||
import org.apache.camel.builder.RouteBuilder; | ||
import org.apache.camel.main.BaseMainSupport; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.Asset; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class CamelRoutesDiscoveryTest { | ||
@RegisterExtension | ||
static final QuarkusUnitTest CONFIG = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addAsResource(applicationProperties(), "application.properties")); | ||
|
||
@Inject | ||
CamelContext camelContext; | ||
@Inject | ||
BaseMainSupport mainSupport; | ||
|
||
public static final Asset applicationProperties() { | ||
Writer writer = new StringWriter(); | ||
|
||
Properties props = new Properties(); | ||
props.setProperty("quarkus.camel.main.routes-discovery.enabled", "false"); | ||
|
||
try { | ||
props.store(writer, ""); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
return new StringAsset(writer.toString()); | ||
} | ||
|
||
@Test | ||
public void testRoutesDiscovery() { | ||
assertThat(camelContext.getRoutes()).isEmpty(); | ||
assertThat(mainSupport.getRoutesBuilders()).isEmpty(); | ||
} | ||
|
||
public static class MyRoute extends RouteBuilder { | ||
@Override | ||
public void configure() throws Exception { | ||
from("direct:in").routeId("my-route").to("log:out"); | ||
} | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
...loyment/src/test/java/org/apache/camel/quarkus/core/deployment/CamelRoutesFilterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* 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 org.apache.camel.quarkus.core.deployment; | ||
|
||
import java.io.IOException; | ||
import java.io.StringWriter; | ||
import java.io.Writer; | ||
import java.util.Properties; | ||
import javax.inject.Inject; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import org.apache.camel.CamelContext; | ||
import org.apache.camel.builder.RouteBuilder; | ||
import org.apache.camel.main.BaseMainSupport; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.Asset; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class CamelRoutesFilterTest { | ||
@RegisterExtension | ||
static final QuarkusUnitTest CONFIG = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addAsResource(applicationProperties(), "application.properties")); | ||
|
||
@Inject | ||
CamelContext camelContext; | ||
@Inject | ||
BaseMainSupport mainSupport; | ||
|
||
public static final Asset applicationProperties() { | ||
Writer writer = new StringWriter(); | ||
|
||
Properties props = new Properties(); | ||
props.setProperty("quarkus.camel.main.routes-discovery.enabled", "true"); | ||
props.setProperty("quarkus.camel.main.routes-discovery.exclude-patterns", "**/*Filtered"); | ||
|
||
try { | ||
props.store(writer, ""); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
return new StringAsset(writer.toString()); | ||
} | ||
|
||
@Test | ||
public void testRoutesFilter() { | ||
assertThat(camelContext.getRoutes()).hasSize(1); | ||
assertThat(camelContext.getRoutes()).first().hasFieldOrPropertyWithValue("id", "my-route"); | ||
assertThat(mainSupport.getRoutesBuilders()).hasSize(1); | ||
assertThat(mainSupport.getRoutesBuilders()).first().isInstanceOf(MyRoute.class); | ||
} | ||
|
||
public static class MyRoute extends RouteBuilder { | ||
@Override | ||
public void configure() throws Exception { | ||
from("direct:in").routeId("my-route").to("log:out"); | ||
} | ||
} | ||
|
||
public static class MyRouteFiltered extends RouteBuilder { | ||
@Override | ||
public void configure() throws Exception { | ||
from("direct:filtered").routeId("my-route-filtered").to("log:filtered"); | ||
} | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...e/deployment/src/test/java/org/apache/camel/quarkus/core/deployment/CamelSupportTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* 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 org.apache.camel.quarkus.core.deployment; | ||
|
||
import java.util.Arrays; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.apache.camel.quarkus.core.deployment.CamelSupport.isPathIncluded; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class CamelSupportTest { | ||
|
||
@Test | ||
public void testPathFiltering() { | ||
assertFalse(isPathIncluded( | ||
"org/acme/MyClass", | ||
Arrays.asList("org/**"), | ||
Arrays.asList())); | ||
assertFalse(isPathIncluded( | ||
"org/acme/MyClass", | ||
Arrays.asList("org/**"), | ||
Arrays.asList("org/**", "org/acme/MyClass"))); | ||
assertFalse(isPathIncluded( | ||
"org/acme/MyClass", | ||
Arrays.asList("org/acme/M*"), | ||
Arrays.asList("org/acme/MyClass"))); | ||
assertFalse(isPathIncluded( | ||
"org/acme/MyClass", | ||
Arrays.asList(), | ||
Arrays.asList("org/acme/A*"))); | ||
|
||
assertTrue(isPathIncluded( | ||
"org/acme/MyClass", | ||
Arrays.asList(), | ||
Arrays.asList())); | ||
assertTrue(isPathIncluded( | ||
"org/acme/MyClass", | ||
Arrays.asList(), | ||
Arrays.asList("org/**"))); | ||
assertTrue(isPathIncluded( | ||
"org/acme/MyClass", | ||
Arrays.asList("org/acme/A*"), | ||
Arrays.asList("org/acme/MyClass"))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.