Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing 使用Arquillian进行单元测试,无默认容器_Unit Testing_Jboss_Jboss Arquillian - Fatal编程技术网

Unit testing 使用Arquillian进行单元测试,无默认容器

Unit testing 使用Arquillian进行单元测试,无默认容器,unit-testing,jboss,jboss-arquillian,Unit Testing,Jboss,Jboss Arquillian,我得到以下Arquillian错误:org.jboss.Arquillian.container.test.impl.client.deployment.ValidationException:DeploymentScenario包含一个与注册表中任何定义的容器都不匹配的目标(默认)。 请在类路径中至少包含一个可部署容器。 这是我的课程 @独生子女 公共类应用程序扩展RouteBuilder{ @Inject private CamelContext context; @Override pu

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

这是我的课程

@独生子女 公共类应用程序扩展RouteBuilder{

@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"));

}
}

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

@单身人士
公共类上下文设置{

@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(Arquillian.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();
    }
}
@Inject
CamelContextSetup CamelContextSetup;
@以前
public void before()引发异常{
camelContextSetup.setup();
}
@之后
在()之后公共无效{
camelContextSetup.destroy();
}
@部署(可测试=错误)
公共静态存档createArchive(){
返回ShrinkWrap.create(JavaArchive.class)
.addClass(应用程序类)
.addClass(CamelContextSetup.class);
}
@试验
public void testReceived()引发InterruptedException{
File tempFile=新文件(“src/main/resources/temp/data.xml”);
if(tempFile.renameTo(新文件(“src/main/resources/temp2/”+tempFile.getName()))
System.out.println(“无法移动文件”);
否则{
camelContextSetup.getAfterXML().expectedMessageCount(1);
AssertMockEndpointsAssertified();
}
}
@试验
public void testError()引发InterruptedException{
File tempFile=新文件(“src/main/resources/temp/data4.pl”);
if(tempFile.renameTo(新文件(“src/main/resources/temp2/”+tempFile.getName()))
System.out.println(“无法移动文件”);
否则{
camelContextSetup.getAfterError().expectedMessageCount(1);
AssertMockEndpointsAssertified();
}
}

}您必须在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>

org.jboss.arquillian.container

是什么代码尝试导致了此错误?请尽量让你的案例重现。我上传了我的代码。太好了!您的代码似乎存在缩进问题,请只保留相关的代码片段,这样人们就不必运行整个代码,只需运行所需的部分。