javaquery/demo-calculator/src/test/java/org/apidesign/bck2brwsr/demo/calc/staticcompilation/MinifiedTest.java
changeset 1785 3085649750a4
child 1787 ea12a3bb4b33
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/javaquery/demo-calculator/src/test/java/org/apidesign/bck2brwsr/demo/calc/staticcompilation/MinifiedTest.java	Tue Feb 24 11:01:47 2015 +0100
     1.3 @@ -0,0 +1,95 @@
     1.4 +/**
     1.5 + * Back 2 Browser Bytecode Translator
     1.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     1.7 + *
     1.8 + * This program is free software: you can redistribute it and/or modify
     1.9 + * it under the terms of the GNU General Public License as published by
    1.10 + * the Free Software Foundation, version 2 of the License.
    1.11 + *
    1.12 + * This program is distributed in the hope that it will be useful,
    1.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.15 + * GNU General Public License for more details.
    1.16 + *
    1.17 + * You should have received a copy of the GNU General Public License
    1.18 + * along with this program. Look for COPYING file in the top folder.
    1.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
    1.20 + */
    1.21 +package org.apidesign.bck2brwsr.demo.calc.staticcompilation;
    1.22 +
    1.23 +import java.io.BufferedReader;
    1.24 +import java.io.InputStreamReader;
    1.25 +import java.net.URL;
    1.26 +import java.util.Enumeration;
    1.27 +import java.util.Map;
    1.28 +import java.util.jar.Attributes;
    1.29 +import java.util.jar.Manifest;
    1.30 +import org.testng.annotations.Test;
    1.31 +import static org.testng.Assert.*;
    1.32 +
    1.33 +public class MinifiedTest {
    1.34 +    @Test public void minifiedVersionDoesNotContainFQN() throws Exception {
    1.35 +        final ClassLoader l = MinifiedTest.class.getClassLoader();
    1.36 +        Enumeration<URL> en = l.getResources("META-INF/MANIFEST.MF");
    1.37 +        while (en.hasMoreElements()) {
    1.38 +            URL u = en.nextElement();
    1.39 +            Manifest mf = new Manifest(u.openStream());
    1.40 +            for (Map.Entry<String, Attributes> entrySet : mf.getEntries().entrySet()) {
    1.41 +                String key = entrySet.getKey();
    1.42 +                if (!key.contains("-min.js")) {
    1.43 +                    continue;
    1.44 +                }
    1.45 +                if (!key.contains("javaquery.api")) {
    1.46 +                    continue;
    1.47 +                }
    1.48 +                try (BufferedReader r = new BufferedReader(new InputStreamReader(l.getResourceAsStream(key)))) {
    1.49 +                    for (;;) {
    1.50 +                        String line = r.readLine();
    1.51 +                        if (line == null) {
    1.52 +                            break;
    1.53 +                        }
    1.54 +                        if (line.contains(" org_apidesign_bck2brwsr_htmlpage_Knockout")) {
    1.55 +                            fail("Found FQN of non-public class. Is it minified version?: " + line + " in " + key);
    1.56 +                        } 
    1.57 +                    }
    1.58 +                }
    1.59 +                // success
    1.60 +                return;
    1.61 +            }
    1.62 +        }
    1.63 +        fail("No minified javaquery found: " + System.getProperty("java.class.path"));
    1.64 +    }
    1.65 +
    1.66 +    @Test public void debugVersionContainsFQN() throws Exception {
    1.67 +        final ClassLoader l = MinifiedTest.class.getClassLoader();
    1.68 +        Enumeration<URL> en = l.getResources("META-INF/MANIFEST.MF");
    1.69 +        while (en.hasMoreElements()) {
    1.70 +            URL u = en.nextElement();
    1.71 +            Manifest mf = new Manifest(u.openStream());
    1.72 +            for (Map.Entry<String, Attributes> entrySet : mf.getEntries().entrySet()) {
    1.73 +                String key = entrySet.getKey();
    1.74 +                if (!key.contains("-debug.js")) {
    1.75 +                    continue;
    1.76 +                }
    1.77 +                if (!key.contains("javaquery.api")) {
    1.78 +                    continue;
    1.79 +                }
    1.80 +                try (BufferedReader r = new BufferedReader(new InputStreamReader(l.getResourceAsStream(key)))) {
    1.81 +                    for (;;) {
    1.82 +                        String line = r.readLine();
    1.83 +                        if (line == null) {
    1.84 +                            break;
    1.85 +                        }
    1.86 +                        if (line.contains(" org_apidesign_bck2brwsr_htmlpage_Knockout")) {
    1.87 +                            // ok, it should be there
    1.88 +                            return;
    1.89 +                        } 
    1.90 +                    }
    1.91 +                }
    1.92 +                fail("Found no FQN of non-public Knockout class. Is it debug version?:" + key);
    1.93 +            }
    1.94 +        }
    1.95 +        fail("No debug javaquery found: " + System.getProperty("java.class.path"));
    1.96 +    }
    1.97 +    
    1.98 +}