Модульный тест Red Hat Fuse 7.2 приводит к сбивающему с толку RuntimeException - т.е. - PullRequest
0 голосов
/ 08 февраля 2019

Проблема:

Проведенный ниже модульный тест завершается неудачно с сообщением:

java.lang.RuntimeException: Gave up waiting for BlueprintContainer from bundle "RouteXmlTest"

Исключение является неопределенным и существуетнет убедительной документации или примеров, которые иллюстрируют, как выполнить модульное тестирование этого сценария.

Поэтому, нужна помощь: -)

Ниже я перечислил код, использованный в моей неудачной попытке, пока,то есть расширение тестового файла с помощью «CamelBlueprintTestSupport.java».

Обратите внимание, что приложение (код также приведен ниже) успешно запускается при развертывании в контейнере Red Hat Fuse 7.2.

Любое руководство /Решение приветствуется.

Thx!

Вот класс модульных испытаний ...

src / main / test / aaa / bbb.ccc.jar / RouteXmlTest.java

package aaa.bbb.ccc.jar;

import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;

import org.apache.camel.Consume;
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.blueprint.CamelBlueprintTestSupport;
//import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;

public class RouteXmlTest extends CamelBlueprintTestSupport {  //CamelTestSupport {

    protected Object[] expectedBodies = {}; // empty to start

    @Produce(uri = "file:work/cbr/input")
    protected ProducerTemplate inputEndpoint;

    @Consume(uri = "jms:queue:myFromQueueA")
    protected MockEndpoint myFromQueueA;

    @Consume(uri = "jms:queue:myToQueueB")
    protected MockEndpoint myToQueueB;

    @Consume(uri = "jms:queue:myToQueueC")
    protected MockEndpoint myToQueueC;

    @Consume(uri = "jms:queue:myToQueueD")
    protected MockEndpoint myToQueueD;

    @Override
    protected RouteBuilder createRouteBuilder() throws Exception {
        return new CamelRoute();
    }

    @Override
    public String isMockEndpoints() {
        return "*";
    }

    @Test
    public void testCamelRoute() throws Exception {
        // Define some input data based on the files we have to test against
        String value1 = getFileContents("src/test/resources/data/order1.xml");
        String value2 = getFileContents("src/test/resources/data/order2.xml");
        String value3 = getFileContents("src/test/resources/data/order3.xml");
        String value4 = getFileContents("src/test/resources/data/order4.xml");
        String value5 = getFileContents("src/test/resources/data/order5.xml");

        expectedBodies = new Object[]{value1, value2, value3, value4, value5};

        // Define some expectations
        getMockEndpoint("mock:jms:queue:myToQueueB").expectedMinimumMessageCount(5);
        getMockEndpoint("mock:jms:queue:myToQueueC").expectedMinimumMessageCount(5);
        getMockEndpoint("mock:jms:queue:myToQueueD").expectedMinimumMessageCount(5);

        // Send some messages to input endpoints
        for (Object expectedBody : expectedBodies) {
            inputEndpoint.sendBody(expectedBody);
        }

        // Validate our expectations
        assertMockEndpointsSatisfied();
    }

    @Override
    protected String getBlueprintDescriptor() {
        return "OSGI-INF/blueprint/camel-route.xml";
    }

    private String getFileContents(String path) throws Exception {
        Path filePath = new File(path).toPath();
        return new String(Files.readAllBytes(filePath), StandardCharsets.UTF_8);
    }
}

вот верблюд-route.xml ...

src / main / resources / OSGI-INF / blueprint / camel-route

<?xml version="1.0" encoding="UTF-8"?>
<blueprint  xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
            xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 
                                https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd              
                                http://camel.apache.org/schema/blueprint 
                                http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">

    <reference id="transactionManager" interface="org.springframework.transaction.PlatformTransactionManager"/>  

    <bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
        <property name="connectionFactory">
            <reference interface="javax.jms.ConnectionFactory" />
        </property>
        <property name="transactionManager" ref="transactionManager"/>
    </bean>    

    <bean class="aaa.bbb.ccc.jar.CamelRoute" id="myRouteBuilder"/>

    <camelContext id="cbr-example-context" xmlns="http://camel.apache.org/schema/blueprint">
        <routeBuilder ref="myRouteBuilder"/>
    </camelContext>
</blueprint>

Ниже приведено исключение, полученное приПройдя тест модуля ...

-
-
-
-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running aaa.bbb.ccc.jar.RouteXmlTest
[                          main] CamelBlueprintHelper           INFO  Using Blueprint XML file: /C:/tools/rfhpoc/target/classes/OSGI-INF/blueprint/camel-route.xml
[                      Thread-0] RawBuilder                     INFO  Copy thread finished.
[                      Thread-1] RawBuilder                     INFO  Copy thread finished.
[                          main] Activator                      INFO  Camel activator starting
[                          main] Activator                      INFO  Camel activator started
[         Blueprint Extender: 1] BlueprintContainerImpl         INFO  Bundle RouteXmlTest/1.0.0 is waiting for namespace handlers [http://camel.apache.org/schema/blueprint]
[         Blueprint Extender: 1] BlueprintContainerImpl         INFO  Bundle RouteXmlTest/1.0.0 is waiting for dependencies [(objectClass=javax.jms.ConnectionFactory), (objectClass=org.springframework.transaction.PlatformTransactionManager)]
[                          main] RouteXmlTest                   INFO  ********************************************************************************
[                          main] RouteXmlTest                   INFO  Testing done: testCamelRoute(aaa.bbb.ccc.jar.RouteXmlTest)
[                          main] RouteXmlTest                   INFO  Took: 32.815 seconds (32815 millis)
[                          main] RouteXmlTest                   INFO  ********************************************************************************
[                          main] CamelBlueprintHelper           INFO  Deleting work directory target/bundles/1549574455436
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 33.338 s <<< FAILURE! - in aaa.bbb.ccc.jar.RouteXmlTest
testCamelRoute(aaa.bbb.ccc.jar.RouteXmlTest)  Time elapsed: 32.952 s  <<< ERROR!
java.lang.RuntimeException: Gave up waiting for BlueprintContainer from bundle "RouteXmlTest"


Results:

Errors: 
  RouteXmlTest>CamelBlueprintTestSupport.setUp:241->CamelBlueprintTestSupport.createBundleContext:175 » Runtime

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0

------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 01:13 min
Finished at: 2019-02-07T16:21:28-05:00
------------------------------------------------------------------------
-
-
-

ДРУГИЕ СООТВЕТСТВУЮЩИЕ ФАЙЛЫ НИЖЕ

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <groupId>aaa.bbb.ccc</groupId>
    <artifactId>rfhpoc</artifactId>
    <version>1.0</version>
    <packaging>bundle</packaging>
    <name>rfhpoc</name>
    <description>rfhpoc - show dsl routing from queue to multiple queues ("spray")</description>
    <licenses>
        <license>
            <name>Apache License, Version 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
            <distribution>repo</distribution>
        </license>
    </licenses>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <maven.test.skip>false</maven.test.skip>
    </properties>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.jboss.redhat-fuse</groupId>
                <artifactId>fuse-karaf-bom</artifactId>
                <version>7.1.0.fuse-710019-redhat-00002</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>artemis-core-client</artifactId>
        </dependency> 
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>artemis-jms-client</artifactId>
        </dependency>  
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jms</artifactId>
        </dependency>     
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-blueprint</artifactId>
            <scope>provided</scope> <!--***-->
        </dependency>                    
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12.0.redhat-003</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-test-blueprint</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <defaultGoal>install</defaultGoal>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>3.2.0</version>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Bundle-SymbolicName>rfhpoc</Bundle-SymbolicName>
                        <Bundle-Name>rfhpoc</Bundle-Name>
                    </instructions>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

src / main / java / aaa.bbb.ccc.jar / CamelRoute.java

package aaa.bbb.ccc.jar;

import org.apache.camel.builder.RouteBuilder;

public class CamelRoute extends RouteBuilder {

    @Override
    public void configure() throws Exception {

        System.getProperties().list(System.out);

        from("file:work/cbr/input")
                .log("from ${file:name}")
                .to("jms:queue:myFromQueueA");

        from("jms:queue:myFromQueueA")
                //.transacted()
                .log("from jms:queue:myFromQueueA")
                .to("jms:queue:myToQueueB")
                .to("jms:queue:myToQueueC")
                .to("jms:queue:myToQueueD");                
    }   
}

среда

red hat fuse 7.2
java 8
active mq 7.2.3
apache maven 3.5.3

1 Ответ

0 голосов
/ 05 марта 2019

Я сталкиваюсь с похожей ошибкой в ​​моем тесте CamelBlueprintTestSupport.После того, как я добавил транзакционное поведение с помощью приведенного ниже кода, произошла ошибка файла blueprint.xml.

<reference id="osgiPlatformTransactionManager" interface="org.springframework.transaction.PlatformTransactionManager" />

<bean id="XA_TX_REQUIRED" class="org.apache.camel.spring.spi.SpringTransactionPolicy">
    <property name="transactionManager" ref="osgiPlatformTransactionManager"/>
</bean>

<route id="transactedRoute">
   <from uri="direct:transactedRoute" />
   ...
   <transacted ref="XA_TX_REQUIRED"/>
   ...
</route>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...