// Path: src/test/java/de/idrinth/stellaris/modtools/abstract_cases/TestATask.java
// public abstract class TestATask extends FileBased {
//     
//     protected abstract ProcessTask get();
// 
//     @Test
//     public void testInterface() {
//         System.out.println("interface");
//         Assert.assertTrue("This task does not implement the required interface.", ProcessTask.class.isAssignableFrom(get().getClass()));
//     }
// 
//     /**
//      * Test of getFullIdentifier method, of class Task.
//      */
//     @Test
//     public void testGetFullIdentifier() {
//         System.out.println("getIdentifier");
//         Assert.assertTrue("Full Identifier is not correct", get().getIdentifier().length() > 0);
//     }
//     
// }
// 
// Path: src/main/java/de/idrinth/stellaris/modtools/filesystem/FileSystemLocation.java
// public interface FileSystemLocation {
//     public File get();
// }
// 
// Path: src/main/java/de/idrinth/stellaris/modtools/persistence/PersistenceProvider.java
// public class PersistenceProvider {
// 
//     private final EntityManagerFactory entityManager;
// 
//     public EntityManager get() {
//         return entityManager.createEntityManager();
//     }
// 
//     public PersistenceProvider() {
//         entityManager = Persistence.createEntityManagerFactory("de.idrinth_Stellaris.ModTools");
//     }
// }
// 
// Path: src/main/java/de/idrinth/stellaris/modtools/persistence/entity/Original.java
// @NamedQueries({
//     @NamedQuery(
//             name = "originals",
//             query = "select f from Original f"
//     )
//     ,
//     @NamedQuery(
//             name = "original.path",
//             query = "select f from Original f where f.relativePath=:path"
//     )
// })
// @Entity
// public class Original extends EntityCompareAndHash {
// 
//     @Id
//     @GeneratedValue
//     private long aid;
//     //original
//     @OneToOne(fetch = FetchType.LAZY)
//     @Cascade({CascadeType.DELETE,CascadeType.PERSIST})
//     private LazyText content;
//     protected String relativePath;
//     //connection
//     @OneToMany(fetch = FetchType.LAZY, mappedBy="file")
//     @Cascade({CascadeType.DELETE})
//     protected Set<Patch> patches = new HashSet<>();
// 
//     public Original() {
//     }
// 
//     public Original(String relativePath) {
//         this.relativePath = relativePath;
//     }
// 
//     @Override
//     public long getAid() {
//         return aid;
//     }
// 
//     @Override
//     public void setAid(long aid) {
//         this.aid = aid;
//     }
// 
//     public String getContent() {
//         if(null == content) {
//             content = new LazyText();
//         }
//         return content.getText();
//     }
// 
//     public void setContent(String content) {
//         if(null == this.content) {
//             this.content = new LazyText();
//         }
//         this.content.setText(content);
//     }
// 
//     public String getRelativePath() {
//         return relativePath;
//     }
// 
//     public void setRelativePath(String relativePath) {
//         this.relativePath = relativePath;
//     }
// 
//     public Set<Patch> getPatches() {
//         return patches;
//     }
// 
//     public void setPatches(Set<Patch> patches) {
//         this.patches = patches;
//     }
// }
// 
// Path: src/main/java/de/idrinth/stellaris/modtools/process/ProcessTask.java
// public interface ProcessTask {
// 
//     List<ProcessTask> handle(EntityManager manager) throws Exception;
//     String getIdentifier();
// }


import de.idrinth.stellaris.modtools.abstract_cases.TestATask;
import de.idrinth.stellaris.modtools.filesystem.FileSystemLocation;
import de.idrinth.stellaris.modtools.persistence.PersistenceProvider;
import de.idrinth.stellaris.modtools.persistence.entity.Original;
import de.idrinth.stellaris.modtools.process.ProcessTask;
import java.io.File;
import java.util.List;
import javax.persistence.EntityManager;
import org.apache.commons.io.FileUtils;
import org.h2.util.IOUtils;
import org.junit.Assert;
import org.junit.Test;
/*
 * Copyright (C) 2017 Björn Büttner
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package de.idrinth.stellaris.modtools.process3filepatch;


public class OriginalFileFillerTest extends TestATask {

    @Override
    protected ProcessTask get() {
        return get(1);
    }
    protected ProcessTask get(long id) {
        return new OriginalFileFiller(id, new FileSystemLocationImpl(getAllowedFolder()));
    }
    /**
     * Test of handle method, of class Task.
     * @throws java.lang.Exception
     * @deprecated has to be implemented on a case by case basis
     */
    @Test
    public void testHandle() throws Exception {
        System.out.println("handle");
        EntityManager manager = new PersistenceProvider().get();
        manager.getTransaction().begin();
        IOUtils.copyAndClose(
            getClass().getResourceAsStream("/test.txt"),
            FileUtils.openOutputStream(new File(getAllowedFolder()+"/steamapps/common/Stellaris/test.txt"))
        );
// Path: src/test/java/de/idrinth/stellaris/modtools/abstract_cases/TestATask.java
// public abstract class TestATask extends FileBased {
//     
//     protected abstract ProcessTask get();
// 
//     @Test
//     public void testInterface() {
//         System.out.println("interface");
//         Assert.assertTrue("This task does not implement the required interface.", ProcessTask.class.isAssignableFrom(get().getClass()));
//     }
// 
//     /**
//      * Test of getFullIdentifier method, of class Task.
//      */
//     @Test
//     public void testGetFullIdentifier() {
//         System.out.println("getIdentifier");
//         Assert.assertTrue("Full Identifier is not correct", get().getIdentifier().length() > 0);
//     }
//     
// }
// 
// Path: src/main/java/de/idrinth/stellaris/modtools/filesystem/FileSystemLocation.java
// public interface FileSystemLocation {
//     public File get();
// }
// 
// Path: src/main/java/de/idrinth/stellaris/modtools/persistence/PersistenceProvider.java
// public class PersistenceProvider {
// 
//     private final EntityManagerFactory entityManager;
// 
//     public EntityManager get() {
//         return entityManager.createEntityManager();
//     }
// 
//     public PersistenceProvider() {
//         entityManager = Persistence.createEntityManagerFactory("de.idrinth_Stellaris.ModTools");
//     }
// }
// 
// Path: src/main/java/de/idrinth/stellaris/modtools/persistence/entity/Original.java
// @NamedQueries({
//     @NamedQuery(
//             name = "originals",
//             query = "select f from Original f"
//     )
//     ,
//     @NamedQuery(
//             name = "original.path",
//             query = "select f from Original f where f.relativePath=:path"
//     )
// })
// @Entity
// public class Original extends EntityCompareAndHash {
// 
//     @Id
//     @GeneratedValue
//     private long aid;
//     //original
//     @OneToOne(fetch = FetchType.LAZY)
//     @Cascade({CascadeType.DELETE,CascadeType.PERSIST})
//     private LazyText content;
//     protected String relativePath;
//     //connection
//     @OneToMany(fetch = FetchType.LAZY, mappedBy="file")
//     @Cascade({CascadeType.DELETE})
//     protected Set<Patch> patches = new HashSet<>();
// 
//     public Original() {
//     }
// 
//     public Original(String relativePath) {
//         this.relativePath = relativePath;
//     }
// 
//     @Override
//     public long getAid() {
//         return aid;
//     }
// 
//     @Override
//     public void setAid(long aid) {
//         this.aid = aid;
//     }
// 
//     public String getContent() {
//         if(null == content) {
//             content = new LazyText();
//         }
//         return content.getText();
//     }
// 
//     public void setContent(String content) {
//         if(null == this.content) {
//             this.content = new LazyText();
//         }
//         this.content.setText(content);
//     }
// 
//     public String getRelativePath() {
//         return relativePath;
//     }
// 
//     public void setRelativePath(String relativePath) {
//         this.relativePath = relativePath;
//     }
// 
//     public Set<Patch> getPatches() {
//         return patches;
//     }
// 
//     public void setPatches(Set<Patch> patches) {
//         this.patches = patches;
//     }
// }
// 
// Path: src/main/java/de/idrinth/stellaris/modtools/process/ProcessTask.java
// public interface ProcessTask {
// 
//     List<ProcessTask> handle(EntityManager manager) throws Exception;
//     String getIdentifier();
// }


// Path: src/test/java/de/idrinth/stellaris/modtools/process3filepatch/OriginalFileFillerTest.java
import de.idrinth.stellaris.modtools.abstract_cases.TestATask;
import de.idrinth.stellaris.modtools.filesystem.FileSystemLocation;
import de.idrinth.stellaris.modtools.persistence.PersistenceProvider;
import de.idrinth.stellaris.modtools.persistence.entity.Original;
import de.idrinth.stellaris.modtools.process.ProcessTask;
import java.io.File;
import java.util.List;
import javax.persistence.EntityManager;
import org.apache.commons.io.FileUtils;
import org.h2.util.IOUtils;
import org.junit.Assert;
import org.junit.Test;

/*
 * Copyright (C) 2017 Björn Büttner
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package de.idrinth.stellaris.modtools.process3filepatch;


public class OriginalFileFillerTest extends TestATask {

    @Override
    protected ProcessTask get() {
        return get(1);
    }
    protected ProcessTask get(long id) {
        return new OriginalFileFiller(id, new FileSystemLocationImpl(getAllowedFolder()));
    }
    /**
     * Test of handle method, of class Task.
     * @throws java.lang.Exception
     * @deprecated has to be implemented on a case by case basis
     */
    @Test
    public void testHandle() throws Exception {
        System.out.println("handle");
        EntityManager manager = new PersistenceProvider().get();
        manager.getTransaction().begin();
        IOUtils.copyAndClose(
            getClass().getResourceAsStream("/test.txt"),
            FileUtils.openOutputStream(new File(getAllowedFolder()+"/steamapps/common/Stellaris/test.txt"))
        );
        Original original = new Original("test.txt");