-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from lburgazzoli/customizer-cleanup
customizer: honour cutomizer list property/env
- Loading branch information
Showing
4 changed files
with
198 additions
and
20 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
39 changes: 39 additions & 0 deletions
39
camel-k-runtime-core/src/test/java/org/apache/camel/k/support/NameCustomizer.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,39 @@ | ||
/** | ||
* 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.k.support; | ||
|
||
import org.apache.camel.CamelContext; | ||
import org.apache.camel.impl.ExplicitCamelContextNameStrategy; | ||
import org.apache.camel.k.ContextCustomizer; | ||
import org.apache.camel.k.Runtime; | ||
|
||
public final class NameCustomizer implements ContextCustomizer { | ||
private String name; | ||
|
||
public NameCustomizer() { | ||
this("default"); | ||
} | ||
|
||
public NameCustomizer(String name) { | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public void apply(CamelContext camelContext, Runtime.Registry registry) { | ||
camelContext.setNameStrategy(new ExplicitCamelContextNameStrategy(name)); | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
camel-k-runtime-core/src/test/java/org/apache/camel/k/support/RuntimeSupportTest.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,82 @@ | ||
/** | ||
* 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.k.support; | ||
|
||
import java.util.List; | ||
import java.util.Properties; | ||
|
||
import org.apache.camel.CamelContext; | ||
import org.apache.camel.component.properties.PropertiesComponent; | ||
import org.apache.camel.impl.DefaultCamelContext; | ||
import org.apache.camel.k.Constants; | ||
import org.apache.camel.k.ContextCustomizer; | ||
import org.apache.camel.k.InMemoryRegistry; | ||
import org.apache.camel.k.Runtime; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class RuntimeSupportTest { | ||
|
||
@Test | ||
public void testLoadCustomizers() { | ||
PropertiesComponent pc = new PropertiesComponent(); | ||
Runtime.Registry registry = new InMemoryRegistry(); | ||
CamelContext context = new DefaultCamelContext(registry); | ||
context.addComponent("properties", pc); | ||
|
||
NameCustomizer customizer = new NameCustomizer("from-registry"); | ||
registry.bind("name", customizer); | ||
|
||
List<ContextCustomizer> customizers = RuntimeSupport.configureContext(context, registry); | ||
assertThat(context.getName()).isNotEqualTo("from-registry"); | ||
assertThat(context.getName()).isNotEqualTo("default"); | ||
assertThat(customizers).hasSize(0); | ||
|
||
Properties properties = new Properties(); | ||
properties.setProperty(Constants.PROPERTY_CAMEL_K_CUSTOMIZER, "name"); | ||
pc.setInitialProperties(properties); | ||
|
||
customizers = RuntimeSupport.configureContext(context, registry); | ||
assertThat(context.getName()).isEqualTo("from-registry"); | ||
assertThat(customizers).hasSize(1); | ||
} | ||
|
||
@Test | ||
public void testLoadCustomizersOrdering() { | ||
PropertiesComponent pc = new PropertiesComponent(); | ||
Runtime.Registry registry = new InMemoryRegistry(); | ||
CamelContext context = new DefaultCamelContext(registry); | ||
context.addComponent("properties", pc); | ||
|
||
Properties properties = new Properties(); | ||
properties.setProperty(Constants.PROPERTY_CAMEL_K_CUSTOMIZER, "name"); | ||
pc.setInitialProperties(properties); | ||
|
||
List<ContextCustomizer> customizers = RuntimeSupport.configureContext(context, registry); | ||
assertThat(context.getName()).isEqualTo("default"); | ||
assertThat(customizers).hasSize(1); | ||
|
||
NameCustomizer customizer = new NameCustomizer("from-registry"); | ||
registry.bind("name", customizer); | ||
|
||
customizers = RuntimeSupport.configureContext(context, registry); | ||
assertThat(context.getName()).isEqualTo("from-registry"); | ||
assertThat(customizers).hasSize(1); | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
camel-k-runtime-core/src/test/resources/META-INF/services/org/apache/camel/k/customizer/name
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,18 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
class=org.apache.camel.k.support.NameCustomizer |