/**
 * 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.core.workflow.persistence;

import java.io.File;

import org.apache.commons.io.FileUtils;
import org.openengsb.core.common.persistence.PersistenceService;
import org.openengsb.core.common.workflow.RuleManager;
import org.openengsb.core.persistence.internal.NeodatisPersistenceService;
import org.openengsb.core.workflow.internal.persistence.PersistenceRuleManager;

public final class PersistenceTestUtil {

    public static RuleManager getRuleManager() throws Exception {
        FileUtils.deleteQuietly(new File("data"));
        PersistenceRuleManager m = new PersistenceRuleManager();
        PersistenceService service = new NeodatisPersistenceService("data", ClassLoader.getSystemClassLoader());
        m.setPersistence(service);
        m.init();
        return m;
    }

    public static void cleanup() throws Exception {
        FileUtils.deleteQuietly(new File("data"));
    }

    private PersistenceTestUtil() {
    }

}

@@ -697,16 +697,60 @@
 io.File;
+%0Aimport java.net.URL;%0Aimport java.util.List;
 %0A%0Aimport
@@ -783,16 +783,56 @@
 eUtils;%0A
+import org.openengsb.core.common.Event;%0A
 import o
@@ -1010,32 +1010,182 @@
 istenceService;%0A
+import org.openengsb.core.workflow.internal.persistence.GlobalDeclaration;%0Aimport org.openengsb.core.workflow.internal.persistence.ImportDeclaration;%0A
 import org.opene
@@ -1291,16 +1291,68 @@
 Util %7B%0A%0A
+    private static PersistenceService persistence;%0A%0A
     publ
@@ -1525,33 +1525,33 @@
 ager();%0A        
-P
+p
 ersistenceServic
@@ -1548,23 +1548,8 @@
 ence
-Service service
  = n
@@ -1619,24 +1619,502 @@
 sLoader());%0A
+        persistence.create(new ImportDeclaration(Event.class.getName()));%0A        URL globalURL = ClassLoader.getSystemResource(%22rulebase/globals%22);%0A        File globalFile = FileUtils.toFile(globalURL);%0A        @SuppressWarnings(%22unchecked%22)%0A        List%3CString%3E globalLines = FileUtils.readLines(globalFile);%0A        for (String s : globalLines) %7B%0A            String%5B%5D parts = s.split(%22 %22);%0A            persistence.create(new GlobalDeclaration(parts%5B0%5D, parts%5B1%5D));%0A        %7D%0A
         m.se
@@ -2130,13 +2130,17 @@
 nce(
-servi
+persisten
 ce);

add some initialization to PersistenceTestUtil