javaquery/demo-calculator/src/test/java/org/apidesign/bck2brwsr/demo/calc/staticcompilation/MinifiedTest.java
2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012-2015 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://opensource.org/licenses/GPL-2.0.
18 package org.apidesign.bck2brwsr.demo.calc.staticcompilation;
20 import java.io.BufferedReader;
21 import java.io.InputStreamReader;
23 import java.util.Enumeration;
25 import java.util.jar.Attributes;
26 import java.util.jar.Manifest;
27 import org.testng.annotations.Test;
28 import static org.testng.Assert.*;
30 public class MinifiedTest {
31 @Test public void minifiedVersionDoesNotContainFQN() throws Exception {
32 final ClassLoader l = MinifiedTest.class.getClassLoader();
33 Enumeration<URL> en = l.getResources("META-INF/MANIFEST.MF");
34 while (en.hasMoreElements()) {
35 URL u = en.nextElement();
36 Manifest mf = new Manifest(u.openStream());
37 for (Map.Entry<String, Attributes> entrySet : mf.getEntries().entrySet()) {
38 String key = entrySet.getKey();
39 if (!key.contains("-min.js")) {
42 if (!key.contains("javaquery.api")) {
45 try (BufferedReader r = new BufferedReader(new InputStreamReader(l.getResourceAsStream(key)))) {
47 String line = r.readLine();
51 if (line.contains(" org_apidesign_bck2brwsr_htmlpage_Knockout")) {
52 fail("Found FQN of non-public class. Is it minified version?: " + line + " in " + key);
60 fail("No minified javaquery found: " + System.getProperty("java.class.path"));
63 @Test public void debugVersionContainsFQN() throws Exception {
64 final ClassLoader l = MinifiedTest.class.getClassLoader();
65 Enumeration<URL> en = l.getResources("META-INF/MANIFEST.MF");
66 while (en.hasMoreElements()) {
67 URL u = en.nextElement();
68 Manifest mf = new Manifest(u.openStream());
69 for (Map.Entry<String, Attributes> entrySet : mf.getEntries().entrySet()) {
70 String key = entrySet.getKey();
71 if (!key.contains("-debug.js")) {
74 if (!key.contains("javaquery.api")) {
77 try (BufferedReader r = new BufferedReader(new InputStreamReader(l.getResourceAsStream(key)))) {
79 String line = r.readLine();
83 if (line.contains(" org_apidesign_bck2brwsr_htmlpage_Knockout")) {
84 // ok, it should be there
89 fail("Found no FQN of non-public Knockout class. Is it debug version?:" + key);
92 fail("No debug javaquery found: " + System.getProperty("java.class.path"));