Skip to content

Commit

Permalink
Revamp properties sample and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
astefanutti committed Dec 8, 2015
1 parent b48a572 commit 4e9e9d9
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 94 deletions.
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
/**
* 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.cdi.sample.properties;

import org.apache.camel.Body;

public class HelloBean {

public String sayHello(@Body String message) {
return "Hello " + message + " user for example 1.";
}
}
/**
* 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.cdi.sample.properties;

import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.cdi.Uri;
import org.apache.camel.management.event.CamelContextStartedEvent;

import javax.enterprise.event.Observes;

public class HelloRoute extends RouteBuilder {

void hello(@Observes CamelContextStartedEvent event, @Uri("direct:hello") ProducerTemplate producer) {
producer.sendBody(event);
}

@Override
public void configure() {
from("direct:hello").log("{{hello.from:Hello from}} ${body.context}");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,22 @@
*/
package org.apache.camel.cdi.sample.properties;

import org.apache.camel.cdi.ContextName;
import org.apache.camel.component.properties.PropertiesComponent;
import org.apache.camel.impl.DefaultCamelContext;

import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Named;
import java.util.Locale;

@ApplicationScoped
@ContextName("simple")
public class SimpleCamelContext extends DefaultCamelContext {
public class Properties {

@PostConstruct
void postConstruct() {
super.setTracing(false);
getComponent("properties", PropertiesComponent.class).setLocation("classpath:placeholder.properties");
@Produces
@ApplicationScoped
@Named("properties")
PropertiesComponent properties() {
PropertiesComponent component = new PropertiesComponent();
component.setLocation("classpath:hello.properties");
component.setPropertyPrefix(Locale.getDefault().getISO3Language() + ".");
return component;
}
}

This file was deleted.

9 changes: 9 additions & 0 deletions samples/properties/src/main/resources/hello.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
deu.hello.from=Hallo von
eng.hello.from=Hello from
fra.hello.from=Bonjour de
ita.hello.from=Ciao da
jpn.hello.from=もしもし
kor.hello.from=안녕하세요
rus.hello.from=Привет из
spa.hello.from=Hola de
zho.hello.from=你好,从
1 change: 0 additions & 1 deletion samples/properties/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<Logger name="org.jboss.weld" level="info" />
<logger name="org.apache.webbeans" level="info" />
<logger name="org.apache.camel" level="info" />
<logger name="org.apache.camel.cdi" level="debug" />
<Root level="info">
<AppenderRef ref="Console"/>
</Root>
Expand Down

This file was deleted.

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.cdi.sample.properties;

import org.apache.camel.cdi.CdiCamelExtension;
import org.apache.camel.cdi.test.LogVerifier;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.rules.ExternalResource;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;

import java.util.Locale;

import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.core.IsCollectionContaining.hasItems;
import static org.junit.Assert.assertThat;

@RunWith(Arquillian.class)
public class PropertiesSampleTest {

@Deployment
public static Archive<?> deployment() {
return ShrinkWrap.create(JavaArchive.class)
// Camel CDI
.addPackage(CdiCamelExtension.class.getPackage())
// Test classes
.addPackage(PropertiesSampleTest.class.getPackage())
// Bean archive deployment descriptor
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}

@ClassRule
public static TestRule locale = new ExternalResource() {

private final Locale locale = Locale.getDefault();

@Override
protected void before() {
Locale.setDefault(Locale.FRENCH);
}

@Override
protected void after() {
Locale.setDefault(locale);
}
};

@ClassRule
public static TestRule verifier = new LogVerifier() {
@Override
protected void verify() throws Throwable {
assertThat("Log messages not found!", getMessages(),
hasItems(
containsString("(CamelContext: camel-cdi) is starting"),
equalTo("Bonjour de CamelContext(camel-cdi)"),
containsString("(CamelContext: camel-cdi) is shutdown"))
);
}
};

@Test
public void test() {
}
}

0 comments on commit 4e9e9d9

Please sign in to comment.