package com.camunda.consulting.webserviceExample.nonarquillian;

import java.util.Date;

import org.apache.ibatis.logging.LogFactory;
import org.camunda.bpm.engine.impl.util.LogUtil;
import org.camunda.bpm.engine.runtime.ProcessInstance;
import org.camunda.bpm.engine.task.Task;
import org.camunda.bpm.engine.test.ProcessEngineRule;
import org.camunda.bpm.engine.test.Deployment;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import com.camunda.consulting.webservice.offertantrag.Basispaket;
import com.camunda.consulting.webservice.offertantrag.Offertantrag;
import com.camunda.consulting.webservice.offertantrag.VersicherungsdauerEnum;
import com.camunda.consulting.webservice.offertantrag.VersicherungsdeckungEnum;

import static org.camunda.bpm.engine.test.assertions.ProcessEngineTests.*;
import static org.junit.Assert.*;

/**
 * Test case starting an in-memory database-backed Process Engine.
 */
public class InMemoryH2Test {

  @Rule
  public ProcessEngineRule rule = new ProcessEngineRule();

  private static final String PROCESS_DEFINITION_KEY = "webservice-example";

  // enable more detailed logging
  static {
    LogUtil.readJavaUtilLoggingConfigFromClasspath(); // process engine
    LogFactory.useJdkLogging(); // MyBatis
  }
  
  @Before
  public void setup() {
	init(rule.getProcessEngine());
  }

  /**
   * Just tests if the process definition is deployable.
   */
  @Test
  @Deployment(resources = "process.bpmn")
  public void testParsingAndDeployment() {
    // nothing is done here, as we just want to check for exceptions during deployment
  }
  
  @Test
  @Deployment(resources = "Offerterstellung.bpmn")
  public void testStartProcessInstance() {
    ProcessInstance pi = runtimeService().startProcessInstanceByKey("offerterstellung");
    
    assertThat(pi).isWaitingAt("offertantrag_erfassen");
    
    Offertantrag offertantrag = new Offertantrag(VersicherungsdeckungEnum.Einzelperson, new Date(), VersicherungsdauerEnum.Kurzfristversicherung31Tage, new Basispaket());
    Task offertantragErfassen = taskQuery().singleResult();
    complete(offertantragErfassen, withVariables("offertantrag", offertantrag));
    
    
  }

}

@@ -373,16 +373,131 @@
 oyment;%0A
+import org.camunda.bpm.engine.variable.value.ObjectValue;%0Aimport org.camunda.bpm.engine.variable.value.TypedValue;%0A
 import o
@@ -513,16 +513,16 @@
 Before;%0A
-
 import o
@@ -1260,16 +1260,18 @@
 tatic %7B%0A
+//
     LogU
@@ -1334,16 +1334,18 @@
  engine%0A
+//
     LogF
@@ -2288,20 +2288,499 @@
 );%0A    %0A
-
     
+ObjectValue variableTyped = runtimeService().getVariableTyped(pi.getProcessInstanceId(), %22offertantrag%22, false);%0A    System.out.println(%22Offerte als XML? %22 + variableTyped.getValueSerialized());%0A    %0A    variableTyped = runtimeService().getVariableTyped(pi.getProcessInstanceId(), %22offertantrag%22, true);%0A    Offertantrag offertantragAusgelesen = (Offertantrag) variableTyped.getValue();%0A    assertThat(offertantragAusgelesen.getEnthaltenesPaket()).isInstanceOf(Basispaket.class);
 %0A  %7D%0A%0A%7D%0A

test with json