ko/bck2brwsr/src/test/java/org/apidesign/bck2brwsr/ko2brwsr/MinifiedIT.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Wed, 15 Apr 2015 17:21:28 +0200
changeset 1825 e678bb6beb1f
parent 1809 javaquery/demo-calculator/src/test/java/org/apidesign/bck2brwsr/demo/calc/staticcompilation/MinifiedTest.java@72a0dbfa2ae8
permissions -rw-r--r--
Never include @JavaScriptResource files in generated library wrappers
jaroslav@1785
     1
/**
jaroslav@1785
     2
 * Back 2 Browser Bytecode Translator
jaroslav@1787
     3
 * Copyright (C) 2012-2015 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@1785
     4
 *
jaroslav@1785
     5
 * This program is free software: you can redistribute it and/or modify
jaroslav@1785
     6
 * it under the terms of the GNU General Public License as published by
jaroslav@1785
     7
 * the Free Software Foundation, version 2 of the License.
jaroslav@1785
     8
 *
jaroslav@1785
     9
 * This program is distributed in the hope that it will be useful,
jaroslav@1785
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@1785
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@1785
    12
 * GNU General Public License for more details.
jaroslav@1785
    13
 *
jaroslav@1785
    14
 * You should have received a copy of the GNU General Public License
jaroslav@1785
    15
 * along with this program. Look for COPYING file in the top folder.
jaroslav@1785
    16
 * If not, see http://opensource.org/licenses/GPL-2.0.
jaroslav@1785
    17
 */
jaroslav@1825
    18
package org.apidesign.bck2brwsr.ko2brwsr;
jaroslav@1785
    19
jaroslav@1809
    20
import java.io.File;
jaroslav@1825
    21
import java.io.InputStream;
jaroslav@1785
    22
import java.net.URL;
jaroslav@1785
    23
import java.util.Enumeration;
jaroslav@1825
    24
import java.util.jar.JarEntry;
jaroslav@1825
    25
import java.util.jar.JarFile;
jaroslav@1785
    26
import org.testng.annotations.Test;
jaroslav@1785
    27
import static org.testng.Assert.*;
jaroslav@1825
    28
import org.testng.annotations.BeforeMethod;
jaroslav@1825
    29
import org.testng.reporters.Files;
jaroslav@1785
    30
jaroslav@1825
    31
public class MinifiedIT {
jaroslav@1825
    32
    private File file;
jaroslav@1825
    33
    
jaroslav@1825
    34
    @BeforeMethod public void findPrecompiledLibraries() throws Exception {
jaroslav@1825
    35
        File dir = new File(getClass().getProtectionDomain().getCodeSource().getLocation().toURI()).getParentFile();
jaroslav@1825
    36
        for (File f : dir.listFiles()) {
jaroslav@1825
    37
            if (f.getName().endsWith("-bck2brwsr.jar")) {
jaroslav@1825
    38
                file = f;
jaroslav@1785
    39
                return;
jaroslav@1785
    40
            }
jaroslav@1785
    41
        }
jaroslav@1825
    42
        fail("Cannot find precompiled libraries in " + dir);
jaroslav@1785
    43
    }
jaroslav@1825
    44
    
jaroslav@1825
    45
    @Test public void minifiedVersionDoesNotContainFQN() throws Exception {
jaroslav@1825
    46
        JarFile jf = new JarFile(file);
jaroslav@1825
    47
        Enumeration<JarEntry> en = jf.entries();
jaroslav@1785
    48
        while (en.hasMoreElements()) {
jaroslav@1825
    49
            JarEntry e = en.nextElement();
jaroslav@1825
    50
            String content;
jaroslav@1825
    51
            try (InputStream is = jf.getInputStream(e)) {
jaroslav@1825
    52
                content = Files.readFile(is);
jaroslav@1825
    53
            }
jaroslav@1825
    54
            if (content.contains("registerResource']('org/netbeans/html/ko4j/knockout")) {
jaroslav@1825
    55
                fail("@JavaScriptResource resource should be missing: "+ e.getName() + " in " + file);
jaroslav@1785
    56
            }
jaroslav@1785
    57
        }
jaroslav@1785
    58
    }
jaroslav@1785
    59
    
jaroslav@1785
    60
}