使用Arquillian进行单元测试,没有默认容器



我收到以下Arquillian错误:org.jboss.arquillian.container.test.impl.client.deployment.ValidationException:DeploymentScenario包含一个与注册表中任何定义的容器不匹配的目标(DEFAULT(。请在类路径中至少包含 1 个可部署容器。

这是我的骆驼路线课

@Singleton公共类应用程序扩展路由生成器{

@Inject
private CamelContext context;
@Override
public void configure() throws Exception {
    from("file://src/main/resources/temp2/").routeId("camelmarian")
            .onException(WrongFileException.class)
            .handled(true)
            .process(new Processor() {
                public void process(Exchange exchange) throws Exception {
                    System.out.println("Wrong File Name " + exchange.getIn().getHeader("CamelFileName"));
                    exchange.getIn().setBody("Wrong extension");
                }
            })
            .id("mockerror")
            .end()
            .choice()
            .when(header("CamelFileName").regex("data[0-9]*.xml"))
            .process(new XmlProcessor())
            .id("mockxml")
            //.to("mock:xml")
            .when(header("CamelFileName").regex("data[0-9]*.csv"))
            .process(new CsvProcessor())
            // .to("mock:csv")
            .id("mockcsv")
            .when(header("CamelFileName").regex("data[0-9]*.txt"))
            .process(new TextProcessor())
            //.to("mock:txt")
            .id("mocktext")
            .otherwise()
            .throwException(new WrongFileException("Wrong file extension"));
}

}

这是具有我将要模拟的端点的类:


@Singleton公共类 CamelContextSetup {

@Inject
private CamelContext camelContext;
private MockEndpoint afterCSV;
private MockEndpoint afterXML;
private MockEndpoint afterTXT;
private MockEndpoint afterError;
@Before
public void setup() throws Exception {
    afterCSV = new MockEndpoint("mockCSV");
    afterXML = new MockEndpoint("mockXML");
    afterTXT = new MockEndpoint("mockTXT");
    afterError = new MockEndpoint("mockError");
    camelContext.getRouteDefinition("camelmarian").adviceWith(((ModelCamelContext) camelContext), new AdviceWithRouteBuilder() {
        @Override
        public void configure() throws Exception {
            weaveById("mockcsv").after().to(afterCSV);
        }
    });
    camelContext.getRouteDefinition("camelmarian").adviceWith(((ModelCamelContext) camelContext), new AdviceWithRouteBuilder() {
        @Override
        public void configure() throws Exception {
            weaveById("mockxml").after().to(afterXML);
        }
    });
    camelContext.getRouteDefinition("camelmarian").adviceWith(((ModelCamelContext) camelContext), new AdviceWithRouteBuilder() {
        @Override
        public void configure() throws Exception {
            weaveById("mocktext").after().to(afterTXT);
        }
    });
    camelContext.getRouteDefinition("camelmarian").adviceWith(((ModelCamelContext) camelContext), new AdviceWithRouteBuilder() {
        @Override
        public void configure() throws Exception {
            weaveById("mockerror").after().to(afterError);
        }
    });
    camelContext.start();
}
@After
public void destroy() {
    afterCSV.reset();
    afterError.reset();
    afterTXT.reset();
    afterCSV.reset();
}
@PreDestroy
public void stopContext() throws Exception {
    camelContext.stop();
}
public MockEndpoint getAfterCSV() {
    return afterCSV;
}
public MockEndpoint getAfterXML() {
    return afterXML;
}
public MockEndpoint getAfterTXT() {
    return afterTXT;
}
public MockEndpoint getAfterError() {
    return afterError;
}

}

这是单元测试。当我运行它们时,出现该错误

@RunWith(阿基利安.class(
公共类 TestFiles 扩展了 CamelTestSupport {

@Inject
CamelContextSetup camelContextSetup;

@Before
public void before() throws Exception {
    camelContextSetup.setup();
}
@After
public void after() {
    camelContextSetup.destroy();
}
@Deployment(testable = false)
public static Archive<?> createArchive() {
        return ShrinkWrap.create(JavaArchive.class)
                .addClass(App.class)
                .addClass(CamelContextSetup.class);
}
@Test
public void testReceived() throws InterruptedException {
    File tempFile = new File("src/main/resources/temp/data.xml");
    if (tempFile.renameTo(new File("src/main/resources/temp2/" + tempFile.getName())))
        System.out.println("failed to move file");
    else {
        camelContextSetup.getAfterXML().expectedMessageCount(1);
        assertMockEndpointsSatisfied();
    }
}
@Test
public void testError() throws InterruptedException {
    File tempFile = new File("src/main/resources/temp/data4.pl");
    if (tempFile.renameTo(new File("src/main/resources/temp2/" + tempFile.getName())))
        System.out.println("failed to move file");
    else {
        camelContextSetup.getAfterError().expectedMessageCount(1);
        assertMockEndpointsSatisfied();
    }
}

}

你必须在你的pom中添加一些依赖项。它看起来像这样:

<dependency>
    <groupId>org.jboss.arquillian.container</groupId>
    <artifactId>arquillian-weld-ee-embedded-1.1</artifactId>
    <version>1.0.0.CR9</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.jboss.weld</groupId>
    <artifactId>weld-core</artifactId>
    <version>2.3.5.Final</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-simple</artifactId>
    <version>1.6.4</version>
    <scope>test</scope>
</dependency>

来源:http://arquillian.org/guides/getting_started_pt/

最新更新