javaquery/demo-calculator/src/test/java/org/apidesign/bck2brwsr/demo/calc/staticcompilation/MinifiedTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 24 Feb 2015 11:01:47 +0100
changeset 1785 3085649750a4
child 1787 ea12a3bb4b33
permissions -rw-r--r--
The closure compiler was broken due to presence of old version of sisu-guava. Exclude and test minification works on JavaQuery API.
jaroslav@1785
     1
/**
jaroslav@1785
     2
 * Back 2 Browser Bytecode Translator
jaroslav@1785
     3
 * Copyright (C) 2012 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@1785
    18
package org.apidesign.bck2brwsr.demo.calc.staticcompilation;
jaroslav@1785
    19
jaroslav@1785
    20
import java.io.BufferedReader;
jaroslav@1785
    21
import java.io.InputStreamReader;
jaroslav@1785
    22
import java.net.URL;
jaroslav@1785
    23
import java.util.Enumeration;
jaroslav@1785
    24
import java.util.Map;
jaroslav@1785
    25
import java.util.jar.Attributes;
jaroslav@1785
    26
import java.util.jar.Manifest;
jaroslav@1785
    27
import org.testng.annotations.Test;
jaroslav@1785
    28
import static org.testng.Assert.*;
jaroslav@1785
    29
jaroslav@1785
    30
public class MinifiedTest {
jaroslav@1785
    31
    @Test public void minifiedVersionDoesNotContainFQN() throws Exception {
jaroslav@1785
    32
        final ClassLoader l = MinifiedTest.class.getClassLoader();
jaroslav@1785
    33
        Enumeration<URL> en = l.getResources("META-INF/MANIFEST.MF");
jaroslav@1785
    34
        while (en.hasMoreElements()) {
jaroslav@1785
    35
            URL u = en.nextElement();
jaroslav@1785
    36
            Manifest mf = new Manifest(u.openStream());
jaroslav@1785
    37
            for (Map.Entry<String, Attributes> entrySet : mf.getEntries().entrySet()) {
jaroslav@1785
    38
                String key = entrySet.getKey();
jaroslav@1785
    39
                if (!key.contains("-min.js")) {
jaroslav@1785
    40
                    continue;
jaroslav@1785
    41
                }
jaroslav@1785
    42
                if (!key.contains("javaquery.api")) {
jaroslav@1785
    43
                    continue;
jaroslav@1785
    44
                }
jaroslav@1785
    45
                try (BufferedReader r = new BufferedReader(new InputStreamReader(l.getResourceAsStream(key)))) {
jaroslav@1785
    46
                    for (;;) {
jaroslav@1785
    47
                        String line = r.readLine();
jaroslav@1785
    48
                        if (line == null) {
jaroslav@1785
    49
                            break;
jaroslav@1785
    50
                        }
jaroslav@1785
    51
                        if (line.contains(" org_apidesign_bck2brwsr_htmlpage_Knockout")) {
jaroslav@1785
    52
                            fail("Found FQN of non-public class. Is it minified version?: " + line + " in " + key);
jaroslav@1785
    53
                        } 
jaroslav@1785
    54
                    }
jaroslav@1785
    55
                }
jaroslav@1785
    56
                // success
jaroslav@1785
    57
                return;
jaroslav@1785
    58
            }
jaroslav@1785
    59
        }
jaroslav@1785
    60
        fail("No minified javaquery found: " + System.getProperty("java.class.path"));
jaroslav@1785
    61
    }
jaroslav@1785
    62
jaroslav@1785
    63
    @Test public void debugVersionContainsFQN() throws Exception {
jaroslav@1785
    64
        final ClassLoader l = MinifiedTest.class.getClassLoader();
jaroslav@1785
    65
        Enumeration<URL> en = l.getResources("META-INF/MANIFEST.MF");
jaroslav@1785
    66
        while (en.hasMoreElements()) {
jaroslav@1785
    67
            URL u = en.nextElement();
jaroslav@1785
    68
            Manifest mf = new Manifest(u.openStream());
jaroslav@1785
    69
            for (Map.Entry<String, Attributes> entrySet : mf.getEntries().entrySet()) {
jaroslav@1785
    70
                String key = entrySet.getKey();
jaroslav@1785
    71
                if (!key.contains("-debug.js")) {
jaroslav@1785
    72
                    continue;
jaroslav@1785
    73
                }
jaroslav@1785
    74
                if (!key.contains("javaquery.api")) {
jaroslav@1785
    75
                    continue;
jaroslav@1785
    76
                }
jaroslav@1785
    77
                try (BufferedReader r = new BufferedReader(new InputStreamReader(l.getResourceAsStream(key)))) {
jaroslav@1785
    78
                    for (;;) {
jaroslav@1785
    79
                        String line = r.readLine();
jaroslav@1785
    80
                        if (line == null) {
jaroslav@1785
    81
                            break;
jaroslav@1785
    82
                        }
jaroslav@1785
    83
                        if (line.contains(" org_apidesign_bck2brwsr_htmlpage_Knockout")) {
jaroslav@1785
    84
                            // ok, it should be there
jaroslav@1785
    85
                            return;
jaroslav@1785
    86
                        } 
jaroslav@1785
    87
                    }
jaroslav@1785
    88
                }
jaroslav@1785
    89
                fail("Found no FQN of non-public Knockout class. Is it debug version?:" + key);
jaroslav@1785
    90
            }
jaroslav@1785
    91
        }
jaroslav@1785
    92
        fail("No debug javaquery found: " + System.getProperty("java.class.path"));
jaroslav@1785
    93
    }
jaroslav@1785
    94
    
jaroslav@1785
    95
}