package tests.wurstscript.tests;

import com.google.common.io.Files;
import de.peeeq.wurstio.mpq.MpqEditor;
import de.peeeq.wurstio.mpq.MpqEditorFactory;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.io.File;
import java.io.IOException;

public class MpqTest {
    private static final String TEST_W3X = "./testscripts/mpq/test_temp.w3x";
    private static final String TEST_W3X_ORIG = "./testscripts/mpq/test.w3x";

    @BeforeClass
    public void before() throws IOException {
        File testMap = new File(TEST_W3X);
        Files.copy(new File(TEST_W3X_ORIG), testMap);
        Assert.assertTrue(testMap.exists());
    }

    @AfterClass
    public void after() {
        File f = new File(TEST_W3X);
        if (f.exists()) {
            f.delete();
        }
    }

    @Test
    public void test_extract() throws Exception {
        try (MpqEditor edit = MpqEditorFactory.getEditor(new File(TEST_W3X))) {
            byte[] f = edit.extractFile("war3map.j");
            Assert.assertTrue(f.length > 5);
        }

    }

    @Test
    public void test_insert() throws Exception {
        try (MpqEditor edit = MpqEditorFactory.getEditor(new File(TEST_W3X))) {
            edit.insertFile("test.txt", new File("./testscripts/mpq/test.txt"));
        }
        Assert.assertTrue(true);

    }

    @Test
    public void test_delete() throws Exception {
        try (MpqEditor edit = MpqEditorFactory.getEditor(new File(TEST_W3X))) {
            edit.deleteFile("test.txt");
        }
        Assert.assertTrue(true);
    }

}

@@ -884,32 +884,46 @@
     %7D%0A%0A    @Test
+(priority = 1)
 %0A    public void
@@ -928,22 +928,21 @@
 id test_
-extrac
+inser
 t() thro
@@ -1052,54 +1052,87 @@
     
-byte%5B%5D f = edit.extractFile(%22war3map.j
+edit.insertFile(%22test.txt%22, new File(%22./testscripts/mpq/test.txt
 %22)
+)
 ;%0A    
+    %7D%0A
     
@@ -1157,32 +1157,14 @@
 rue(
-f.length %3E 5);%0A        %7D
+true);
 %0A%0A  
@@ -1169,32 +1169,46 @@
     %7D%0A%0A    @Test
+(priority = 2)
 %0A    public void
@@ -1205,37 +1205,38 @@
 ublic void test_
-inser
+extrac
 t() throws Excep
@@ -1338,87 +1338,54 @@
     
-edit.insertFile(%22test.txt%22, new File(%22./testscripts/mpq/test.txt%22)
+byte%5B%5D f = edit.extractFile(%22war3map.j%22
 );%0A    
-    %7D%0A
     
@@ -1398,38 +1398,56 @@
 sert.assertTrue(
-true);
+f.length %3E 5);%0A        %7D
 %0A%0A    %7D%0A%0A    @Te
@@ -1448,16 +1448,30 @@
    @Test
+(priority = 3)
 %0A    pub

fix mpq test priorities