Axon.ivy 7.0 - the Digital Business Platform - is out now...

Hello everybody I have two projects, one is A and one is A_Test. And i try to run JUnit Test case from project A_Test to test some functionalities of A. Here is a portion of code Project A

public CalendarEventRequest(){
    this.organizer = **Ivy.var().get("xabs_calendarEvent_organizer").toString();**
    Calendar c = new GregorianCalendar(Ivy.session().getContentLocale());
    this.timezone= c.getTimeZone();

Test case

public void testCreateCalendarEvent002() throws Exception {
    CalendarEventRequest request = new CalendarEventRequest();
    CalendarEventResult result = CalendarUtil.createCalendarEvent(request);

And JUnit threw this exception:

    ch.ivyteam.ivy.environment.EnvironmentNotAvailableException: Access to ivy environment outside a process request thread is not possible.
Current thread: Thread[main,5,main]
    at ch.ivyteam.ivy.environment.Ivy.getEnvironmentData(
    at ch.ivyteam.ivy.environment.Ivy.var(
    at ch.soreco.customers.xabs.bean.CalendarEventRequest.<init>(
    at ch.soreco.customers.xabs.bean.CalendarUtilTest.createRequestForOneDay(
    at ch.soreco.customers.xabs.bean.CalendarUtilTest.testCreateCalendarEvent002(
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(
    at org.junit.runners.ParentRunner.runLeaf(
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(
    at org.junit.runners.ParentRunner$
    at org.junit.runners.ParentRunner$1.schedule(
    at org.junit.runners.ParentRunner.runChildren(
    at org.junit.runners.ParentRunner.access$000(
    at org.junit.runners.ParentRunner$2.evaluate(
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(

anyone can help me?

This question is marked "community wiki".

asked 07.04.2014 at 09:34

trungdv's gravatar image

accept rate: 52%

edited 07.04.2014 at 09:44


My Co-worker changed the current unittesting code to a more convenient one. He simply mocks the the ivy engine with Jmockit.

public class IvyMock extends MockUp<Ivy> {

    public static IPersistenceContext persistence() {
        return new IPersistenceContext() {
            public IIvyEntityManager get(String persistenceUnitName) {
                return new IIvyEntityManager() {...}

so we can use the mock in the unittests without starting any ivy relevant stuff.

(09.04.2014 at 12:49) Daniel Oechslin Daniel%20Oechslin's gravatar image

The unit test looks like:

public void init() {
  new IvyMock();
  new MockUp<ProjectActivityDao>() {
     public ProjectActivity getLatestProjectActivity(long projectId) {
          return oldProjectActivity;
(09.04.2014 at 12:50) Daniel Oechslin Daniel%20Oechslin's gravatar image

Base on the comment of Daniel Oechslin, we should have the function in your case like this:

public class IvyMock extends MockUp<Ivy> {

    public static IGlobalVariableContext var() {
        return new IGlobalVariableContext() {
            public String get(String varName) {
                String value = "";
                if(varName.equalsIgnoreCase(yourVarName)){ //example: xabs_dateFormat_portal
                    value = yourValueVar; //example: yyyy/MM/dd
                //else if(...
                // other cases here
                return value;
            public Set<String> getVariableNames() {
                return null;

answered 09.05.2014 at 13:03

nvhuong's gravatar image

accept rate: 66%

edited 13.05.2014 at 16:47

Thanks Mr Huong and Daniel Oechslin I have tried and it worked perfectly.

(13.05.2014 at 04:04) trungdv trungdv's gravatar image

I once wrote an roundabout how you can use Unittests in XpertIvy. I hope this helps.


answered 07.04.2014 at 10:14

Daniel%20Oechslin's gravatar image

Daniel Oechslin
accept rate: 36%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 07.04.2014 at 09:34

Seen: 2,443 times

Last updated: 13.05.2014 at 16:47