/**

   Copyright 2010 OpenEngSB Division, Vienna University of Technology

   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.openengsb.integrationtest.exam;

import java.util.Collection;
import java.util.List;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openengsb.core.common.Event;
import org.openengsb.core.common.context.ContextCurrentService;
import org.openengsb.core.workflow.RuleManager;
import org.openengsb.core.workflow.WorkflowService;
import org.openengsb.core.workflow.model.RuleBaseElementId;
import org.openengsb.core.workflow.model.RuleBaseElementType;
import org.openengsb.integrationtest.util.AbstractExamTestHelper;
import org.openengsb.integrationtest.util.BaseExamConfiguration;
import org.ops4j.pax.exam.CoreOptions;
import org.ops4j.pax.exam.Inject;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.Configuration;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.osgi.framework.BundleContext;

@RunWith(JUnit4TestRunner.class)
public class WorkflowIT extends AbstractExamTestHelper {

    @Inject
    private BundleContext bundleContext;

    @Configuration
    public static Option[] configuration() {
        List<Option> baseConfiguration = BaseExamConfiguration.getBaseExamOptions("../");
        BaseExamConfiguration.addEntireOpenEngSBPlatform(baseConfiguration);
        Option[] options = BaseExamConfiguration.convertOptionListToArray(baseConfiguration);
        return CoreOptions.options(options);
    }

    @Test
    public void testHasHelloRule() throws Exception {
        RuleManager ruleManager = retrieveService(bundleContext, RuleManager.class);
        Collection<RuleBaseElementId> list = ruleManager.list(RuleBaseElementType.Rule);
        Assert.assertTrue(list.contains(new RuleBaseElementId(RuleBaseElementType.Rule, "hello1")));
    }

    @Test
    public void testSendEvent() throws Exception {
        ContextCurrentService contextCurrentService = retrieveService(bundleContext, ContextCurrentService.class);
        contextCurrentService.createContext("42");

        WorkflowService workflowService = retrieveService(bundleContext, WorkflowService.class);
        Event e = new Event("42");
        workflowService.processEvent(e);
    }
}
@@ -695,24 +695,81 @@
 Collection;%0A
+import java.util.Dictionary;%0Aimport java.util.Hashtable;%0A
 import java.
@@ -779,16 +779,16 @@
 l.List;%0A
-
 %0Aimport 
@@ -861,16 +861,57 @@
 unWith;%0A
+import org.openengsb.core.common.Domain;%0A
 import o
@@ -1228,16 +1228,140 @@
 ntType;%0A
+import org.openengsb.domains.notification.NotificationDomain;%0Aimport org.openengsb.domains.notification.model.Notification;%0A
 import o
@@ -1820,16 +1820,278 @@
 lper %7B%0A%0A
+    public static class DummyNotificationDomain implements NotificationDomain %7B%0A%0A        private Notification notification;%0A%0A        @Override%0A        public void notify(Notification notification) %7B%0A            this.notification = notification;%0A        %7D%0A    %7D%0A%0A
     @Inj
@@ -2953,31 +2953,24 @@
 vice context
-Current
 Service = re
@@ -3039,31 +3039,24 @@
      context
-Current
 Service.crea
@@ -3069,16 +3069,537 @@
 ext(%2242%22
+);%0A        contextService.setThreadLocalContext(%2242%22);%0A        contextService.putValue(%22/domains/notification/defaultConnector/id%22, %22dummyConnector%22);%0A%0A        DummyNotificationDomain dummy = new DummyNotificationDomain();%0A        String%5B%5D clazzes = new String%5B%5D %7B Domain.class.getName(), NotificationDomain.class.getName() %7D;%0A        Dictionary%3CString, String%3E properties = new Hashtable%3CString, String%3E();%0A        properties.put(%22id%22, %22dummyConnector%22);%0A%0A        bundleContext.registerService(clazzes, dummy, properties
 );%0A%0A    
@@ -3718,32 +3718,32 @@
 ew Event(%2242%22);%0A
-
         workflow
@@ -3766,16 +3766,67 @@
 vent(e);
+%0A%0A        Assert.assertNotNull(dummy.notification);
 %0A    %7D%0A%7D

fix testSendEvent integration test