Reputation: 45
I'm trying to test my simple API in wso2 using the Redis connector. The GET request is sent to the API bank via its endpoint to retrieve exchange rates and parsing the data into the Redis cache. I wrote a unit test for the API and mockservice according to the documentation https://ei.docs.wso2.com/en/7.2.0/micro-integrator/develop/creating-unit-test-suite/. But when I tried to run this test, I got the following error :
[error] Artifact data reading failed
java.nio.file.NoSuchFileException: ..\NBU_EXCHANGE_DATA_INDEX_660_EI\NBU_EXCHANGE_DATA_INDEX_660_EIConnector\redis-connector-1.0.1.zip
at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:79)
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:102)
at sun.nio.fs.WindowsFileSystemProvider.newByteChannel(WindowsFileSystemProvider.java:230)
at java.nio.file.Files.newByteChannel(Files.java:361)
at java.nio.file.Files.newByteChannel(Files.java:407)
at java.nio.file.Files.readAllBytes(Files.java:3152)
at org.wso2.synapse.unittest.SynapseTestCaseFileReader.processConnectorResourcesData(SynapseTestCaseFileReader.java:290)
at org.wso2.synapse.unittest.SynapseTestCaseFileReader.processArtifactData(SynapseTestCaseFileReader.java:91)
at org.wso2.synapse.unittest.UnitTestClient.executeTests(UnitTestClient.java:54)
at org.wso2.synapse.unittest.UnitTestCasesMojo.testCaseRunner(UnitTestCasesMojo.java:141)
at org.wso2.synapse.unittest.UnitTestCasesMojo.execute(UnitTestCasesMojo.java:79)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:957)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:193)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
[error] Error while creating a deployable message with test suites`
This my unit-test.xml :
<unit-test>
<artifacts>
<test-artifact>
<artifact>/NBU_EXCHANGE_DATA_INDEX_660_EIConfigs/src/main/synapse-config/api/WRITE_EXCHANGE_TO_REDIS.xml</artifact>
</test-artifact>
<supportive-artifacts>
<artifact>/NBU_EXCHANGE_DATA_INDEX_660_EI/NBU_EXCHANGE_DATA_INDEX_660_EIConfigs/src/main/synapse-config/sequences/WRITE_INDEX_EXCHANGE_TO_REDIS_XML.xml</artifact>
<artifact>/NBU_EXCHANGE_DATA_INDEX_660_EI/NBU_EXCHANGE_DATA_INDEX_660_EIConfigs/src/main/synapse-config/endpoints/EXCHANGE_XML_FROM_SITE_NBU_EP.xml</artifact>
</supportive-artifacts>
<registry-resources/>
<connector-resources>
<connector-resource>/NBU_EXCHANGE_DATA_INDEX_660_EI/NBU_EXCHANGE_DATA_INDEX_660_EIConnector/redis-connector-1.0.1.zip</connector-resource>
</connector-resources>
</artifacts>
<test-cases>
<test-case name="GetXML_exchange">
<input>
<request-path>/nbu-exchange/xml</request-path>
<request-method>GET</request-method>
<request-protocol>http</request-protocol>
</input>
<assertions>
<assertEquals>
<actual>$body</actual>
<expected><![CDATA[{
"Date": "2022-09-14",
"HTTP_SC": "200",
"XML_connect": "true",
"MAIN_XML_isUpdate": "false",
"TMP_XML_isUpdate": "false",
"NBU_XML_isUpdate": "false"
}]]></expected>
<message>not equals</message>
</assertEquals>
<assertNotNull>
<actual>$body</actual>
<message>not null</message>
</assertNotNull>
</assertions>
</test-case>
</test-cases>
<mock-services>
<mock-service>/NBU_EXCHANGE_DATA_INDEX_660_EI/NBU_EXCHANGE_DATA_INDEX_660_EIConfigs/test/resources/mock-services/ImitationNBU_EP_XML.xml</mock-service>
</mock-services>
</unit-test>
This my mock-service.xml :
<mock-service>
<service-name>EXCHANGE_XML_FROM_SITE_NBU_EP</service-name>
<port>9090</port>
<context>/nbu-exchange</context>
<resources>
<resource>
<sub-context>/xml</sub-context>
<method>GET</method>
<response>
<status-code>200</status-code>
<payload><![CDATA[<?xml version="1.0" encoding="utf-8"?>
<exchange>
<currency>
<r030>36</r030>
<txt>Австралійський долар</txt>
<rate>25.2652</rate>
<cc>AUD</cc>
<exchangedate>14.09.2022</exchangedate>
</currency>
<currency>
<r030>124</r030>
<txt>Канадський долар</txt>
<rate>28.1969</rate>
<cc>CAD</cc>
<exchangedate>14.09.2022</exchangedate>
</currency>
</exchange>]]></payload>
<headers>
<header name="Content-Type" value="application/xml"/>
</headers>
</response>
</resource>
</resources>
</mock-service>
This my pom.xml for test
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://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>
<parent>
<groupId>com.example</groupId>
<artifactId>NBU_EXCHANGE_DATA_INDEX_660_EI</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<groupId>com.example</groupId>
<artifactId>NBU_EXCHANGE_DATA_INDEX_660_EIConfigs</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>NBU_EXCHANGE_DATA_INDEX_660_EIConfigs</name>
<description>NBU_EXCHANGE_DATA_INDEX_660_EIConfigs</description>
<properties>
<CApp.type>bpel/workflow=zip,lib/registry/filter=jar,webapp/jaxws=war,lib/library/bundle=jar,service/dataservice=dbs,synapse/local-entry=xml,synapse/proxy-service=xml,carbon/application=car,registry/resource=zip,lib/dataservice/validator=jar,synapse/endpoint=xml,web/application=war,lib/carbon/ui=jar,service/axis2=aar,synapse/sequence=xml,synapse/configuration=xml,wso2/gadget=dar,lib/registry/handlers=jar,lib/synapse/mediator=jar,synapse/task=xml,synapse/api=xml,synapse/template=xml,synapse/message-store=xml,synapse/message-processors=xml,synapse/inbound-endpoint=xml,synapse/metadata=yaml</CApp.type>
<maven.test.skip>false</maven.test.skip>
</properties>
<repositories>
<repository>
<releases>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<id>wso2-nexus</id>
<url>https://maven.wso2.org/nexus/content/groups/wso2-public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<releases>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<id>wso2-nexus</id>
<url>https://maven.wso2.org/nexus/content/groups/wso2-public/</url>
</pluginRepository>
</pluginRepositories>
<build>
<directory>target/capp</directory>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<extensions>true</extensions>
<executions>
<execution>
<id>package</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>mvn</executable>
<workingDirectory>${project.build.directory}</workingDirectory>
<arguments>
<argument>clean</argument>
<argument>package</argument>
<argument>-Dmaven.test.skip=${maven.test.skip}</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>install</id>
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>mvn</executable>
<workingDirectory>${project.build.directory}</workingDirectory>
<arguments>
<argument>clean</argument>
<argument>install</argument>
<argument>-Dmaven.test.skip=${maven.test.skip}</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>deploy</id>
<phase>deploy</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>mvn</executable>
<workingDirectory>${project.build.directory}</workingDirectory>
<arguments>
<argument>deploy</argument>
<argument>-Dmaven.test.skip=${maven.test.skip}</argument>
</arguments>
</configuration>
</execution>
</executions>
<configuration />
</plugin>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<buildcommands />
<projectnatures>
<projectnature>org.wso2.developerstudio.eclipse.esb.project.nature</projectnature>
</projectnatures>
</configuration>
</plugin>
<plugin>
<groupId>org.wso2.maven</groupId>
<artifactId>synapse-unit-test-maven-plugin</artifactId>
<version>5.2.38</version>
<executions>
<execution>
<id>synapse-unit-test</id>
<phase>test</phase>
<goals>
<goal>synapse-unit-test</goal>
</goals>
</execution>
</executions>
<configuration>
<server>
<testServerType>${testServerType}</testServerType>
<testServerHost>${testServerHost}</testServerHost>
<testServerPort>${testServerPort}</testServerPort>
<testServerPath>${testServerPath}</testServerPath>
</server>
<testCasesFilePath>${project.basedir}/test/${testFile}</testCasesFilePath>
<mavenTestSkip>${maven.test.skip}</mavenTestSkip>
</configuration>
</plugin>
<plugin>
<groupId>org.wso2.maven</groupId>
<artifactId>wso2-esb-sequence-plugin</artifactId>
<version>2.1.0</version>
<extensions>true</extensions>
<executions>
<execution>
<id>sequence</id>
<phase>process-resources</phase>
<goals>
<goal>pom-gen</goal>
</goals>
<configuration>
<artifactLocation>.</artifactLocation>
<typeList>${artifact.types}</typeList>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.sun.activation</groupId>
<artifactId>javax.activation</artifactId>
<version>1.2.0</version>
</dependency>
</dependencies>
<configuration />
</plugin>
<plugin>
<groupId>org.wso2.maven</groupId>
<artifactId>wso2-esb-endpoint-plugin</artifactId>
<version>2.1.0</version>
<extensions>true</extensions>
<executions>
<execution>
<id>endpoint</id>
<phase>process-resources</phase>
<goals>
<goal>pom-gen</goal>
</goals>
<configuration>
<artifactLocation>.</artifactLocation>
<typeList>${artifact.types}</typeList>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.sun.activation</groupId>
<artifactId>javax.activation</artifactId>
<version>1.2.0</version>
</dependency>
</dependencies>
<configuration />
</plugin>
<plugin>
<groupId>org.wso2.maven</groupId>
<artifactId>wso2-esb-api-plugin</artifactId>
<version>2.1.0</version>
<extensions>true</extensions>
<executions>
<execution>
<id>api</id>
<phase>process-resources</phase>
<goals>
<goal>pom-gen</goal>
</goals>
<configuration>
<artifactLocation>.</artifactLocation>
<typeList>${artifact.types}</typeList>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.sun.activation</groupId>
<artifactId>javax.activation</artifactId>
<version>1.2.0</version>
</dependency>
</dependencies>
<configuration />
</plugin>
<plugin>
<groupId>org.wso2.maven</groupId>
<artifactId>wso2-esb-metadata-plugin</artifactId>
<version>5.2.34</version>
<extensions>true</extensions>
<executions>
<execution>
<id>metadata</id>
<phase>process-resources</phase>
<goals>
<goal>pom-gen</goal>
</goals>
<configuration>
<artifactLocation>.</artifactLocation>
<typeList>${artifact.types}</typeList>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.sun.activation</groupId>
<artifactId>javax.activation</artifactId>
<version>1.2.0</version>
</dependency>
</dependencies>
<configuration />
</plugin>
<plugin>
<groupId>org.wso2.maven</groupId>
<artifactId>wso2-esb-task-plugin</artifactId>
<version>2.1.0</version>
<extensions>true</extensions>
<executions>
<execution>
<id>task</id>
<phase>process-resources</phase>
<goals>
<goal>pom-gen</goal>
</goals>
<configuration>
<artifactLocation>.</artifactLocation>
<typeList>${artifact.types}</typeList>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.sun.activation</groupId>
<artifactId>javax.activation</artifactId>
<version>1.2.0</version>
</dependency>
</dependencies>
<configuration />
</plugin>
<plugin>
<groupId>org.wso2.maven</groupId>
<artifactId>wso2-esb-proxy-plugin</artifactId>
<version>2.1.0</version>
<extensions>true</extensions>
<executions>
<execution>
<id>proxy</id>
<phase>process-resources</phase>
<goals>
<goal>pom-gen</goal>
</goals>
<configuration>
<artifactLocation>.</artifactLocation>
<typeList>${artifact.types}</typeList>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.sun.activation</groupId>
<artifactId>javax.activation</artifactId>
<version>1.2.0</version>
</dependency>
</dependencies>
<configuration />
</plugin>
</plugins>
</build>
</project>
What am I doing wrong?
Upvotes: 1
Views: 239
Reputation: 14574
If you have a Connector Exporter Project created, you should be able to add the connector as a dependency when creating the Test Suite in the Supportive Artifacts Page
.
Another option is to deploy the connector separately before running the Test Suite. You can create a Common project to pack all the common dependencies and have it deployed to MI runtime so it can be referred to by all the other projects.
Upvotes: 0