Skip to content

Commit

Permalink
Add test for @RecipientList annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
astefanutti committed Sep 1, 2014
1 parent 7ab81fb commit 90e75ab
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright (C) 2014 Antonin Stefanutti (antonin.stefanutti@gmail.com)
*
* Licensed 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.se.bean;

import org.apache.camel.Consume;
import org.apache.camel.RecipientList;

import javax.enterprise.context.ApplicationScoped;
import java.util.Arrays;
import java.util.List;

@ApplicationScoped
public class RecipientListMethodBean {

@RecipientList
@Consume(uri = "direct:inbound")
public List<String> route() {
return Arrays.asList("mock:outbound1", "mock:outbound2");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/**
* Copyright (C) 2014 Antonin Stefanutti (antonin.stefanutti@gmail.com)
*
* Licensed 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.se;

import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.cdi.CdiCamelExtension;
import org.apache.camel.cdi.Uri;
import org.apache.camel.cdi.se.bean.RecipientListMethodBean;
import org.apache.camel.component.mock.MockEndpoint;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.junit.InSequence;
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.Test;
import org.junit.runner.RunWith;

import javax.inject.Inject;
import java.util.concurrent.TimeUnit;

import static org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied;

@RunWith(Arquillian.class)
public class RecipientListMethodTest {

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

@Inject
@Uri("direct:inbound")
private ProducerTemplate inbound;

@Inject
@Uri("mock:outbound1")
private MockEndpoint outbound1;

@Inject
@Uri("mock:outbound2")
private MockEndpoint outbound2;

@Test
@InSequence(1)
public void startCamelContext(CamelContext context) throws Exception {
context.start();
}

@Test
@InSequence(2)
public void consumeAnnotation() throws InterruptedException {
outbound1.expectedMessageCount(1);
outbound1.expectedBodiesReceived("test");

outbound2.expectedMessageCount(1);
outbound2.expectedBodiesReceived("test");

inbound.sendBody("test");

assertIsSatisfied(2L, TimeUnit.SECONDS, outbound1);
assertIsSatisfied(2L, TimeUnit.SECONDS, outbound2);
}

@Test
@InSequence(3)
public void stopCamelContext(CamelContext context) throws Exception {
context.stop();
}
}

0 comments on commit 90e75ab

Please sign in to comment.