-
1. Re: Having the most difficult time getting my MyBatis test to work...
dibu Feb 23, 2015 4:48 AM (in response to rickcr)You must add all used test classes to the web archive too.
-
2. Re: Having the most difficult time getting my MyBatis test to work...
rickcr Feb 23, 2015 9:49 AM (in response to dibu)Thanks Dirk. I'm now just trying to use the entire war generated by Maven first. (Tried adding a few more things missing and still the same issue.) I figure if I can get the tests to work using the generated maven war, then maybe at some point I can work backwards and just add the classes I want to test later.
However even trying to use the entire war, I'm having some issues. Seems to appear to 'sort of work' as I see in the logs the mapper dependencies discovered, but then I get that cryptic "Could not inject members" error
Currently I'm defining the archive now as
WebArchive archive = ShrinkWrap.create(ZipImporter.class, "mybatis-cdi-zk-1.0.war").importFrom(new File("target/mybatis-cdi-zk-1.0.war"))
.as(WebArchive.class);
Feb 23, 2015 8:32:33 AM org.mybatis.cdi.Extension afterBeanDiscovery
INFO: MyBatis CDI Module - Activated
Feb 23, 2015 8:32:33 AM org.mybatis.cdi.Extension afterBeanDiscovery
INFO: MyBatis CDI Module - Mapper dependency discovered: net.learntechnology.empmaint.mapper.DepartmentMapper
Feb 23, 2015 8:32:33 AM org.mybatis.cdi.Extension afterBeanDiscovery
INFO: MyBatis CDI Module - Mapper dependency discovered: net.learntechnology.empmaint.mapper.EmployeeMapper
java.lang.RuntimeException: Could not inject members....
I assume even though it's a war I'm using, I should still be able to directly test any of the java methods that are bundled in the war?
For example my test is trying to test one of the service methods in the war....
@Deployment
public static WebArchive createDeployment() { ... }@Inject
private DepartmentService departmentService;@Test
public void getDepartmentsTest() {List<Department> departments = departmentService.getAllDepartments();
....
-
3. Re: Re: Having the most difficult time getting my MyBatis test to work...
dibu Feb 24, 2015 1:28 AM (in response to rickcr)I look at you code and the problem is still missing dependencies in the test archive. You must add ALL dependencies (classes, test classes and used libraries).
You can use the Maven resolver like this:
WebArchive archive = ...
Srting key = "org.mybatis:mybatis-cdi";
JavaArchive[] libraries = Maven.resolver().loadPomFromFile("pom.xml").resolve(key).withTransitivity().as(JavaArchive.class);
archive.addAsLibraries(libraries);
-
4. Re: Having the most difficult time getting my MyBatis test to work...
rickcr Feb 24, 2015 8:53 AM (in response to dibu)Thanks Dirk...
I set it up like this now and it worked!
My final deployment that works is set up as:
WebArchive archive = ShrinkWrap.create(ZipImporter.class, "mybatis-cdi-zk-1.0.war").importFrom(new File("target/mybatis-cdi-zk-1.0.war"))
.as(WebArchive.class);
String key = "org.mybatis:mybatis-cdi";
JavaArchive[] libraries = Maven.resolver().loadPomFromFile("pom.xml").resolve(key).withTransitivity().as(JavaArchive.class);
archive.addAsLibraries(libraries);
Why isn't what you mentioned listed in any of the startup guides Guides · Arquillian ? What you proposed worked and is a million times easier than trying to figure out every dependency my project has in it in order to add it to my archive. Thank you!
-
5. Re: Having the most difficult time getting my MyBatis test to work...
rickcr Feb 24, 2015 11:43 AM (in response to rickcr)Problem with using the war directly though is it doesn't use my test resources. I'll try to package all my mybatis-cdi services into its own jar for testing and see how that goes.
Worst case the war can be used directly as is for testing... I'd just have to use a different profile for the maven build.