Maven, testng - include and exclude tests - maven

I have a scenario where i need to run my tests by including & excluding certain testng groups.
Consider below scenario
import org.testng.annotations.Test;
public class GroupingTest {
#Test(groups = {"bat"})
public void batTest(){
System.out.println("Am bat");
}
#Test(groups = {"p1"})
public void p1Test(){
System.out.println("Am p1");
}
#Test(groups = {"p2"})
public void p2Test(){
System.out.println("Am p2");
}
#Test(groups = {"bat","p3"})
public void batp3Test(){
System.out.println("Am bat p3 ");
}
}
Here, how i can run only "bat" test group and it should NOTrun a "bat" test which is also a "33" .
In the above case when i run.. it should print only "Am bat"
How can i achieve it? Any recommendations?

There are basically two ways of getting this done.
Approach #1: Using a beanshell selector
Make sure you are using the latest released version of TestNG. Its 7.0.0-beta1 as of today.
Add a dependency on beanshell (below is how you would do it if you were using maven)
<dependency>
<groupId>org.apache-extras.beanshell</groupId>
<artifactId>bsh</artifactId>
<version>2.0b6</version>
</dependency>
Alter your TestNG suite xml to look like below:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="53799427_suite" parallel="false" verbose="2">
<method-selectors>
<method-selector>
<script language="beanshell">
<![CDATA[
whatGroup = System.getProperty("group");
shouldRun = Arrays.equals(new String[]{whatGroup}, testngMethod.getGroups());
return shouldRun;
]]>
</script>
</method-selector>
</method-selectors>
<test name="53799427_test">
<classes>
<class name="com.rationaleemotions.stackoverflow.qn53799427.TestClassSample"/>
</classes>
</test>
</suite>
Here the test class com.rationaleemotions.stackoverflow.qn53799427.TestClassSample looks exactly like the sample you shared.
Now when you run this suite xml file by passing the JVM argument -Dgroup=bat you will see an output which looks like below (which is what are after)
...
... TestNG 7.0.0-beta1 by Cédric Beust (cedric#beust.com)
...
Am bat
PASSED: batTest
===============================================
53799427_test
Tests run: 1, Failures: 0, Skips: 0
===============================================
===============================================
53799427_suite
Total tests run: 1, Passes: 1, Failures: 0, Skips: 0
===============================================
Approach #2: Using a custom method selector
Make sure you are depending on TestNG 7.0.0-SNAPSHOT (The reason I say so is because, there was a bug in TestNG which prevented this feature from working properly. I went ahead and fixed it as part of GITHUB-1985. But its yet to be released as of today)
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.0.0-SNAPSHOT</version>
</dependency>
To consume the snapshot version, you may need to add a <repository> tag as shown below to your pom file.
<repositories>
<repository>
<id>sonatype-nexus-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
</repositories>
Now create a custom org.testng.IMethodSelector implementation which looks like below:
import java.util.Arrays;
import java.util.List;
import org.testng.IMethodSelector;
import org.testng.IMethodSelectorContext;
import org.testng.ITestNGMethod;
public class FilteringMethodSelector implements IMethodSelector {
#Override
public boolean includeMethod(
IMethodSelectorContext context, ITestNGMethod method, boolean isTestMethod) {
String whichGroup = System.getProperty("group", "all");
if ("all".equalsIgnoreCase(whichGroup)) {
return true;
}
boolean isEqual = Arrays.equals(new String[]{whichGroup}, method.getGroups());
if (context != null) {
context.setStopped(true);
}
return isEqual;
}
#Override
public void setTestMethods(List<ITestNGMethod> testMethods) {}
}
Create a testng suite xml file that looks like below:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="53799427_suite" parallel="false" verbose="2">
<method-selectors>
<method-selector>
<selector-class
name="com.rationaleemotions.stackoverflow.qn53799427.FilteringMethodSelector" priority="0"/>
</method-selector>
</method-selectors>
<test name="53799427_test">
<classes>
<class name="com.rationaleemotions.stackoverflow.qn53799427.TestClassSample"/>
</classes>
</test>
</suite>
Here the test class com.rationaleemotions.stackoverflow.qn53799427.TestClassSample looks exactly like the sample you shared.
Now when you run this suite xml file by passing the JVM argument -Dgroup=bat you will see an output which looks like below (which is what are after)
...
... TestNG 7.0.0-SNAPSHOT by Cédric Beust (cedric#beust.com)
...
Am bat
PASSED: batTest
===============================================
53799427_test
Tests run: 1, Failures: 0, Skips: 0
===============================================
===============================================
53799427_suite
Total tests run: 1, Passes: 1, Failures: 0, Skips: 0
===============================================

Related

TestNg - Exclude a class(testrunner) via mvn command line

Description :
As a user, I would like to exclude a class ( Test Runner ) when I am running mvn clean test
Pseudo Code :
~ mvn clean verify -Dexclude=SampleTest
How I run my build :
~ mvn clean verify; this triggers a surefire plugin that targets the testng.xml
XML: ( TESTNG )
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Automated UI Tests">
<test name = "Cucumber Test" verbose="2">
<classes>
<class name="com.testrunners.SampleTest"/>
<class name="com.testrunners.Sample2Test"/>
<class name="com.testrunners.Sample3Test"/>
</classes>
</test>
</suite>
I tried grouping ( #Test groups=sample ), but that doesn't seem to work with my case.
Not sure if it matters, but here's a snippet of my test runner.
package com.testrunners;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import cucumber.api.testng.AbstractTestNGCucumberTests;
import org.junit.runner.RunWith;
#RunWith(Cucumber.class)
#CucumberOptions(
features = {
"src/test/java/com/features/",
},
glue = {
"com.stepdefinitions"
},
monochrome = true,
tags = {
"#smoke"
},
plugin = {"pretty",
"html:target/cucumber/sample",
"json:target/cucumber-report/sample/cucumber.json",
"json:target/sample/cucumber.json",
"com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter: target/sample/report.html"}
)
public class SampleTest extends AbstractTestNGCucumberTests {
}
Any help would be appreciated.
Thank you.
From your question, it seems to me you are using maven failsafe plugin for execution.
2 approaches can be used:
From Maven Failsafe plugin:
You can can use excludes property in POM.xml. Please see the configuration to do it. Reference from Maven failsafe official doc plugin.
1 <project>
2 [...]
3 <build>
4 <plugins>
5 <plugin>
6 <groupId>org.apache.maven.plugins</groupId>
7 <artifactId>maven-failsafe-plugin</artifactId>
8 <version>3.0.0-M4</version>
9 <configuration>
10 <excludes>
11 <exclude>**/CircleIT.java</exclude>
12 <exclude>**/SquareIT.java</exclude>
13 </excludes>
14 </configuration>
15 </plugin>
16 </plugins>
17 </build>
18 [...]
19 </project>
You can check this here:
https://maven.apache.org/surefire/maven-failsafe-plugin/examples/inclusion-exclusion.html
This way you can run test cases using
mvn clean verify
From TestNG:
Test classes and class cannot be directly excluded; however, you can exclude classes through groups:
#Test(groups = { "ClassTest1" })
public class Test1 {
public void testMethod1() {
}
public void testMethod2() {
}
}
Then you will define the testng.xml:
<suite>
<test>
<groups>
<run>
<exclude name="ClassTest1"/>
</run>
</groups>
<classes>
<class name="Test1">
</classes>
</test>

Mybatis - Invalid bound statement (not found)

I have created a new project using mybatis to connect to a mysql database. This is my second project using mybatis so I am familiar with it but am getting the following error when I call the save method:
2019-03-05 10:08:01.031 ERROR 86438 --- [nio-9905-exec-1] c.q.f.r.c.ResolveRestController : Error starting preset: Invalid bound statement (not found): com.qlsdistribution.fps.resolverender.data.mybatis.mapper.ResolveJobReportMapper.saveResolveJobReport
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.qlsdistribution.fps.resolverender.data.mybatis.mapper.ResolveJobReportMapper.saveResolveJobReport
at org.apache.ibatis.binding.MapperMethod$SqlCommand.(MapperMethod.java:232) ~[mybatis-3.5.0.jar:3.5.0]
at org.apache.ibatis.binding.MapperMethod.(MapperMethod.java:50) ~[mybatis-3.5.0.jar:3.5.0]
at org.apache.ibatis.binding.MapperProxy.lambda$cachedMapperMethod$0(MapperProxy.java:62) ~[mybatis-3.5.0.jar:3.5.0]
at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660) ~[na:1.8.0_101]
at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:62) ~[mybatis-3.5.0.jar:3.5.0]
.....
My mybatis config file is as follows (in src/main/resources):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<!-- changes from the defaults -->
<setting name="lazyLoadingEnabled" value="true" />
<!-- Mybatis logging -->
<setting name="logImpl" value="LOG4J2"/>
</settings>
<typeAliases>
<package name="com.qlsdistribution.fps.resolverender.data.mybatis.domain"/>
</typeAliases>
<mappers>
<mapper resource="mapper/ResolveJobReport.xml"/>
<!-- <mapper resource="com/qlsdistribution/fps/resolverender/data/mybatis/mapper/ResolveJobReport.xml"/> -->
</mappers>
</configuration>
As you can see I have tried different locations for the mapper xml file but if I put invalid syntax in the mapper xml file, it fails with invalid syntax (SAXParseException) instead so I know the mapper xml file is being read.
The mapper xml file is as follows (in src/main/resources/mapper):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.qlsdistribution.fps.resolverender.data.mybatis.ResolveJobReportMapper">
<resultMap id="resolveJobReport" type="com.qlsdistribution.fps.resolverender.data.mybatis.domain.ResolveJobReport">
<result property="id" column="id" />
<result property="fpsProjectName" column="fps_project_name" />
<result property="inputPath" column="input_path" />
<result property="destinationPath" column="destination_path" />
<result property="presetName" column="preset_name" />
<result property="ipAddress" column="ip_address" />
<result property="frameRate" column="frame_rate" />
<result property="resolveProjectName" column="resolve_project_name" />
<result property="width" column="width" />
<result property="height" column="height" />
<result property="renderFormat" column="render_format" />
<result property="renderCodec" column="render_codec" />
<result property="scriptPath" column="script_path" />
<result property="cliOutput" column="cli_output" />
<result property="jobStartedDate" column="job_started_date" />
<result property="jobFinishedDate" column="job_finished_date" />
<result property="createdBy" column="created_by" />
<result property="createdDate" column="created_date" />
<result property="modifiedBy" column="modified_by" />
<result property="modifiedDate" column="modified_date" />
</resultMap>
<select id="getAllResolveJobReports" resultMap="resolveJobReport">
SELECT id, fps_project_name, input_path, destination_path, preset_name, ip_address, frame_rate, resolve_project_name, width, height,
render_format, render_codec, script_path, cli_output, job_started_date, job_finished_date, created_by, created_date, modified_by, modified_date
FROM resolve_job_report
WHERE fps_setting_id = #{value}
ORDER by id desc;
</select>
<select id="getAllResolveJobReportsById" parameterType="Long" resultMap="resolveJobReport">
SELECT id, fps_project_name, input_path, destination_path, preset_name, ip_address, frame_rate, resolve_project_name, width, height,
render_format, render_codec, script_path, cli_output, job_started_date, job_finished_date, created_by, created_date, modified_by, modified_date
FROM resolve_job_report
WHERE id = #{value};
</select>
<insert id="saveResolveJobReport" parameterType="com.qlsdistribution.fps.resolverender.data.mybatis.domain.ResolveJobReport">
INSERT INTO resolve_job_report
(fps_project_name, input_path, destination_path, preset_name, ip_address, frame_rate, resolve_project_name, width, height,
render_format, render_codec, script_path, cli_output, job_started_date, job_finished_date, created_by)
VALUE
(#{fpsProjectName},#{inputPath},#{destinationPath},#{presetName},#{ipAddress},#{frameRate},#{resolveProjectName},#{width},#{height},
#{renderFormat},#{renderCodec}, #{scriptPath},#{cliOutput},#{jobStartedDate},#{jobFinishedDate},#{createdBy});
</insert>
<update id="updateResolveJobReportById" parameterType="resolveJobReport">
UPDATE resolve_job_report
SET
fps_project_name = #{fpsProjectName},
input_path = #{inputPath},
destination_path = #{destinationPath},
preset_name = #{presetName},
ip_address = #{ipAddress},
frame_rate = #{frameRate},
resolve_project_name = #{resolveProjectName},
width = #{width},
height = #{height},
render_format = #{renderFormat},
render_codec = #{renderCodec},
script_path = #{scriptPath},
cli_output = #{cliOutput},
job_started_date = #{jobStartedDate},
job_finished_date = #{jobFinishedDate},
modified_by = #{modifiedBy}
where id = #{id};
</update>
<delete id="deleteResolveJobReporttById" parameterType="Long">
DELETE FROM resolve_job_report
WHERE id = #{value}
</delete>
</mapper>
My application.properties file contains the following (in (src/main/resources):
spring.datasource.url=jdbc:mysql://localhost:3306/fpsresolvetool?createDatabaseIfNotExist=true&autoReconnect=true&useSSL=false
spring.datasource.username=root
spring.datasource.password=
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.datasource.schema=classpath:schema.sql
mybatis.config-location=classpath:SqlMapConfig.xml
I have even tried using the latest mybatis versions in my pom.xml:
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>
My spring boot application is as follows:
#SpringBootApplication
#EnableScheduling
#ComponentScan({"com.qlsdistribution.fps.resolverender"})
#EnableJms
#MapperScan("com.qlsdistribution.fps.resolverender.data.mybatis")
public class FPSResolveRenderApp implements WebMvcConfigurer {
/** UTF-8 Character set name */
private static final String UTF_8 = "UTF-8";
/** Logger */
private static final Logger logger = LogManager.getLogger(FPSResolveRenderApp.class);
public static void main(String[] args) {
new SpringApplicationBuilder(FPSResolveRenderApp.class).run(args);
}
/**
* Creates and gets the FilterRegistrationBean
* #return
*/
#Bean
public FilterRegistrationBean<CharacterEncodingFilter> filterRegistrationBean() {
FilterRegistrationBean<CharacterEncodingFilter> registrationBean = new FilterRegistrationBean<CharacterEncodingFilter>();
CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
characterEncodingFilter.setEncoding(UTF_8);
registrationBean.setFilter(characterEncodingFilter);
return registrationBean;
}
}
The mapper interface is as follows:
#Mapper
public interface ResolveJobReportMapper {
public List<ResolveJobReport> getAllResolveJobReports();
public List<ResolveJobReport> getAllResolveJobReports(RowBounds rowBounds);
public List<ResolveJobReport> getAllResolveJobReportsById(Long id);
public List<ResolveJobReport> getAllResolveJobReportsById(Long id, RowBounds rowBounds);
public void saveResolveJobReport(ResolveJobReport resolveJobReport);
public void updateResolveJobReportById(ResolveJobReport resolveJobReport);
public void deleteResolveJobReporttById(Long id);
}
And the service class is as follows:
#Service("ResolveJobReportService")
public class ResolveJobReportService {
#Autowired
private ResolveJobReportMapper resolveJobReportMapper= null;
public List<ResolveJobReport> getAllResolveJobReports() {
return resolveJobReportMapper.getAllResolveJobReports();
}
public List<ResolveJobReport> getAllResolveJobReports(RowBounds rowBounds) {
return resolveJobReportMapper.getAllResolveJobReports();
}
public List<ResolveJobReport> getAllResolveJobReportsById(Long id) {
return resolveJobReportMapper.getAllResolveJobReportsById(id);
}
public List<ResolveJobReport> getAllResolveJobReportsById(Long id, RowBounds rowBounds) {
return resolveJobReportMapper.getAllResolveJobReportsById(id);
}
public void saveResolveJobReport(ResolveJobReport resolveJobReport) {
resolveJobReportMapper.saveResolveJobReport(resolveJobReport);
}
public void updateResolveJobReportById(ResolveJobReport resolveJobReport) {
resolveJobReportMapper.updateResolveJobReportById(resolveJobReport);
}
public void deleteResolveJobReporttById(Long id) {
resolveJobReportMapper.deleteResolveJobReporttById(id);
}
}
Can anyone see what is wrong.
The problem happens because the namespace in mapper xml is com.qlsdistribution.fps.resolverender.data.mybatis.ResolveJobReportMapper but the package the mapper interface is com.qlsdistribution.fps.resolverender.data.mybatis.mapper.ResolveJobReportMapper.
To fix it make sure they match.
Put it in application.properties mybatis.mapper-locations=classpath*:**/mappers/*Mapper.xml
For those people using MyBatis without xml in spring boot project:
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</dependency>
Please check your spring boot application class, make sure your #MapperScan matches your dao package.
#MapperScan("com.jjs.videoservice.dao")
The path must be SAME as your dao package (contains your mapper interface), I ignored "dao" and caused the issue.
Hope it helps someone, thanks
I had the same error message when I changed my project from a JavaFX Project to a Maven Project.
I had to move all my xml mapper files to the resource folder. After that, worked just fine.
I hit this problem recenly, and checked everything that can be found in the internet. Cost me a whole day.
Finally I put the xml files in the same place with the interface java files, which solved the problem.
I think that is because for some reasons the xml files can not be found, and putting them there make them visiable.
I had the same issue
for me the fix was giving same filename for both the java (mapper interface class) and corresponding xml file
I had 2 mappers in the same package. It was the root cause of the problem. Once each mapper interface was moved to separate package, the problem was resolved.
in my case, I used the same name for mapper and java class but the mapping in mapper.xml was pointing to the wrong java class
I faced the same problem recently, I noticed, that I added the new method in the production xml mapper file by mistake and not in the actual xml mappers in resources folder. Once the actual xml mappers in resources folder was updated, it fixed the problem. So please make sure you update the right mapper files in your src folder that gets compiled.
Sometimes people do this mistake:
In resources folder the created folder like "org.my_app.mybatis", but the correct way is do separate folder for each part of package
-org
--my_app
---mybatis
It is hard to recognize when you do it in code editor.
Visually we have the same result
But actually a different structure
Green will work, red - won't.

How to test OSGi declarative services using JUnit and tycho-surefire-plugin?

Tried to test an OSGi service using JUnit and the tycho-surefire-plugin.
Configuration of the plugin
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<version>${tycho.version}</version>
<configuration>
<showEclipseLog>true</showEclipseLog>
<dependencies>
<dependency>
<type>p2-installable-unit</type>
<artifactId>org.eclipse.equinox.ds</artifactId>
</dependency>
</dependencies>
</configuration>
</plugin>
Testcase (logging statements etc. omitted). The test class is contained in it's own OSGi bundle, separated from the code under test.
#Component(name = "LdapConnectionConfigurationServiceTest", immediate = true)
public class LdapConnectionConfigurationServiceTest {
private LdapConnectionConfiguration testObject;
#Reference
public void bindTestObject(final LdapConnectionConfiguration testObject) {
this.testObject = testObject;
}
public void unbindTestObject(final LdapConnectionConfiguration testObject) {
this.testObject = null;
}
#Test
public void testLdapPort() {
assertEquals(10389, testObject.getLdapPort());
}
}
Tycho starts an OSGi container, the test bundle, starts the LdapConnectionConfigurationServiceTest service and properly injects the testObject.
Subsequently JUnit runs this test case, but creates another instance of this class. Which doesn't get the testObject injected, so I'm getting NullPointerExceptions.
Don't know what I'm missing... What I want is running the test case against an injected service provided by the OSGi framework.

OSGI Declarative Service prints nothing

Dear talented programmers!
I have been working with OSGI framework and was trying to applied Declarative Service in my program, but it printed nothing on the screen.
My program is simple, just have one interface, one class implements it and one class consume the interface as the client.
- The Interface is:
package test.osdids.date;
public interface IDateService {
String getDate();
}
- The class implements Interface as the Service is:
package test.osdids.date.service;
import java.util.Calendar;
import test.osdids.date.IDateService;
public class DateService implements IDateService {
#Override
public String getDate() {
String date = Calendar.getInstance().getTime().toString();
return date;
}
}
The XML to registered the service is:
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0"
name="test.osdids.date.service">
<implementation class="test.osdids.date.service.DateService" />
<service>
<provide interface="test.osdids.date.IDateService" />
</service>
</scr:component>
The Manifest file of the service is:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: TESTOSDIDSDATESERVICE
Bundle-SymbolicName: TESTOSDIDSDATESERVICE
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Service-Component: OSGI-INF/DateBridge.xml
Export-Package: test.osdids.date
Bundle-ActivationPolicy: lazy
- And now, this is the class which will consume the service as the client and prints out the result ( This class was located in other plug-in project, different from the former plug-in project which stored the interface and the implementation class above):
package test.osdids.date.consumer;
import test.osdids.date.IDateService;
public class DateConsumer {
private IDateService dateService;
public synchronized void setService(IDateService dateService) {
this.dateService = dateService;
System.out
.println("The Date Service has been registered successfully!");
System.out.println("The current time is: " + dateService.getDate());
}
public synchronized void unsetService(IDateService dateService) {
System.out
.println("The Date Service has been unregistered successfully!");
}
public void activate() {
System.out.println("Test again...");
System.out.println("The current time is: " + dateService.getDate());
}
public void deactivate() {
System.out.println("Stop the service!");
}
}
- This is the XML file to consume and bind the service of consumer class:
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0"
name="test.osdids.date.consumer" activate="activate"
deactivate="deactivate" enabled="true" immediate="true">
<implementation class="test.osdids.date.consumer.DateConsumer" />
<reference bind="setService" cardinality="1..1"
interface="test.osdids.date.IDateService" name="IDateService" policy="static"
unbind="unsetService" />
</scr:component>
- This is the manifest file:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: TESTOSDIDSDATECONSUMER
Bundle-SymbolicName: TESTOSDIDSDATECONSUMER
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Require-Bundle: TESTOSDIDSDATESERVICE;bundle-version="1.0.0"
Service-Component: OSGI-INF/DateBridgeConsumer.xml
Import-Package: test.osdids.date
Bundle-ActivationPolicy: lazy
- And here is the result on the screen:
osgi>
(Nothing happened)
But when I use jUnit test to test the method activate() in class DateConsumer, it worked. However, when I tried to run the plug-in project by OSGI framework, nothing happened.
I hope that someone who knows this problem and help me.
Thanks a lot in advance!
I got the answer, just launch the bundle consumer by Eclipse framework (product), not by OSGI framework, then the bundles will work smoothly

Maven surefire tests failing in Spring framework project

Maven is unable to successfully run my JUnit tests though they are being run without any problem on my Eclipse. I'm unable to solve it from the debug messages.
It is probably something to do with the Spring config because my other JUnit tests not relying on Spring are working fine.
Adding the surefire plugin forkMode as Always didn't work either.
Maven output
mvn install ... ... [INFO] --- maven-surefire-plugin:2.10:test (default-test) # AppServer --- [INFO] Surefire report directory:
C:..\surefire-reports
Running com.ws.impl.BrowserServiceImplTest Tests run: 2, Failures: 2,
Errors: 0, Skipped: 0, Time elapsed: 0.016 sec <<< FAILURE!
Failed tests: com.ws.impl.BrowserServiceImplTest.testGetStatuses()
com.ws.impl.BrowserServiceImplTest.testGetSellers()
Test class
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration("classpath:test-context.xml")
public class BrowserServiceImplTest {
#Autowired
private BrowserServiceImpl browserServiceImpl;
#Test
public void testGetStatuses() {
// test code
}
// more code
}
Surefire report
<failure type="java.lang.NullPointerException">java.lang.NullPointerException
at com.ws.impl.BrowserServiceImplTest.testGetStatuses(BrowserServiceImplTest.java:48)
</failure>
Edit
Lines 48-49
List<String> statuses = browserServiceImpl.getStatuses();
assertEquals(12, statuses.size());
Edit 2
test-context.xml
<bean id="browserSvc" class="com.ws.impl.BrowserServiceImpl">
<property name="filterOptionsService" ref="filterOptionsService" />
</bean>
BrowserServiceImpl.java
#WebService(targetNamespace = "http://abc.def.com", portName = "BrowserPort", serviceName = "BrowserService")
public class BrowserServiceImpl implements BrowserService {
private FilterOptionsService filterOptionsService;
// more code
}

Resources