Unit tests that depend on @OpenmrsProfile fail to run in IntelliJ

3 views
Skip to first unread message

Darius Jazayeri

unread,
Apr 2, 2015, 11:21:04 AM4/2/15
to dev
Hi All,

For a long time I have been unable to run individual context-sensitive tests in my Mirebalais project (and various others) from within IntelliJ. The error is failure to load the application context caused by "No bean named 'emrOrderService' is defined". (It works fine to run a maven build.)

I finally looked into this and figure out the reason. I'm expecting to load this bean from the emrapi module:
@Component(value = "emrOrderService")
@OpenmrsProfile(openmrsVersion = "1.9.*")
public class DefaultOrderServiceImpl implements EmrOrderService

But when checking whether the bean should be loaded (OpenmrsProfileExcludeFilter and OpenmrsProfileIncludeFilter) the value of OpenmrsConstants.OPENMRS_VERSION_SHORT is this:
${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}-${revisionNumber}

I guess that since maven filtering hasn't happened, the following definition in OpenmrsConstants.java doesn't work right:
public static final String OPENMRS_VERSION_SHORT = THIS_PACKAGE.getSpecificationVersion() != null ? THIS_PACKAGE
       .getSpecificationVersion() : (getBuildVersionShort() != null ? getBuildVersionShort() : getVersion());

Can anyone think of a workaround for this?

-Darius

Rafal Korytkowski

unread,
Apr 2, 2015, 12:08:28 PM4/2/15
to Developers List
Apparently IntelliJ doesn't do filtering of resources when building openmrs-core. You could try to prevent IntelliJ from building openmrs-core entirely by closing openmrs project in IntelliJ. Then you just run mvn clean install from command line on openmrs-core and all should work.

-Rafał

--
OpenMRS Developers: http://om.rs/dev
Post: d...@openmrs.org | Unsubscribe: dev+uns...@openmrs.org
Manage your OpenMRS subscriptions: http://om.rs/id
 
*** THIS GROUP WILL BE MOVED to OpenMRS Talk effective 10 April 2015 at 19:00 UTC. Please visit https://talk.openmrs.org/t/openmrs-developers-group-changes-2015-04-10/1508 for details and to make necessary changes.

Darius Jazayeri

unread,
Apr 2, 2015, 12:26:24 PM4/2/15
to dev
Hi Rafal,

The issue is that I want to run one specific unit test (in debug mode). So the whole point is to run it from IntelliJ and not the command line...

-Darius

Rafal Korytkowski

unread,
Apr 2, 2015, 3:18:19 PM4/2/15
to Developers List
I understand. My point was to run mvn clean install on openmrs-core so that SNAPSHOT with the correct OpenmrsConstants.OPENMRS_VERSION_SHORT gets deployed to your local repo and IntelliJ uses it for running unit tests in emrapi. Yet first you must make sure that IntelliJ will not overwrite that version by building openmrs-core automatically from source.


-Rafał

Darius Jazayeri

unread,
Apr 2, 2015, 3:24:00 PM4/2/15
to dev
I think the problem is that I have openmrs-core as one of the modules in my IntelliJ project, so it resolves from there, rather than from maven. Presumably I could have a different maven project that only has the mirebalais module, and I could run the unit test there. (Thanks for helping me think through this -- I hadn't thought of this alone.)

I already did the hacky workaround of locally changing OpenmrsConstants like:
public static final String OPENMRS_VERSION = "1.9.8";

At least it let me debug the unit test and find the problem...

-Darius
Reply all
Reply to author
Forward
0 new messages