/* Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.camunda.bpm.engine.test.standalone.testing;

import static org.junit.Assert.assertEquals;

import java.util.Arrays;
import java.util.Collection;

import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.TaskService;
import org.camunda.bpm.engine.task.Task;
import org.camunda.bpm.engine.test.Deployment;
import org.camunda.bpm.engine.test.ProcessEngineRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;


/**
 * Test runners follow the this rule:
 *   - if the class extends Testcase, run as Junit 3
 *   - otherwise use Junit 4
 *
 * So this test can be included in the regular test suite without problems.
 *
 * @author Joram Barrez
 */
@RunWith(Parameterized.class)
public class ProcessEngineRuleParameterizedJunit4Test {

  @Parameters
  public static Collection<Object[]> data() {
    return Arrays.asList(new Object[][] {
      { 1 }, { 2 }
    });
  }

  @Rule
  public ProcessEngineRule engineRule = new ProcessEngineRule();

  public ProcessEngineRuleParameterizedJunit4Test(int parameter) {

  }

  @Test
  @Deployment(resources = "org/camunda/bpm/engine/test/standalone/testing/ProcessEngineRuleParameterizedJunit4Test.ruleUsageExample.bpmn20.xml")
  public void ruleUsageExample() {
    RuntimeService runtimeService = engineRule.getRuntimeService();
    runtimeService.startProcessInstanceByKey("ruleUsage");

    TaskService taskService = engineRule.getTaskService();
    Task task = taskService.createTaskQuery().singleResult();
    assertEquals("My Task", task.getName());

    taskService.complete(task.getId());
    assertEquals(0, runtimeService.createProcessInstanceQuery().count());
  }

  /**
   * The rule should work with tests that have no deployment annotation
   */
  @Test
  public void testWithoutDeploymentAnnotation() {
    assertEquals("aString", "aString");
  }

}

@@ -939,24 +939,49 @@
 EngineRule;%0A
+import org.junit.Ignore;%0A
 import org.j
@@ -987,24 +987,24 @@
 junit.Rule;%0A
-
 import org.j
@@ -1151,230 +1151,33 @@
 %0A * 
-Test runners follow the this rule:%0A *   - if the class extends Testcase, run as Junit 3%0A *   - otherwise use Junit 4%0A *%0A * So this test can be included in the regular test suite without problems.%0A *%0A * @author Joram Barrez
+@author Thorben Lindhauer
 %0A */
@@ -1545,16 +1545,587 @@
 %7B%0A%0A  %7D%0A%0A
+  /**%0A   * Unnamed @Deployment annotations don't work with parameterized Unit tests%0A   */%0A  @Ignore%0A  @Test%0A  @Deployment%0A  public void ruleUsageExample() %7B%0A    RuntimeService runtimeService = engineRule.getRuntimeService();%0A    runtimeService.startProcessInstanceByKey(%22ruleUsage%22);%0A%0A    TaskService taskService = engineRule.getTaskService();%0A    Task task = taskService.createTaskQuery().singleResult();%0A    assertEquals(%22My Task%22, task.getName());%0A%0A    taskService.complete(task.getId());%0A    assertEquals(0, runtimeService.createProcessInstanceQuery().count());%0A  %7D%0A%0A
   @Test%0A
@@ -2269,16 +2269,16 @@
 0.xml%22)%0A
-
   public
@@ -2291,32 +2291,51 @@
 ruleUsageExample
+WithNamedAnnotation
 () %7B%0A    Runtime

add test case for unnamed @Deployment annotation