javaquery/demo-calculator/src/test/java/org/apidesign/bck2brwsr/demo/calc/staticcompilation/MinifiedTest.java
Can run from unpackaged directories. E.g. mvn clean install -DskipTests; mvn test works now on JDK8.
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;
22 import java.io.InputStreamReader;
24 import java.util.Enumeration;
26 import java.util.jar.Attributes;
27 import java.util.jar.Manifest;
28 import org.testng.annotations.Test;
29 import static org.testng.Assert.*;
30 import org.testng.SkipException;
32 public class MinifiedTest {
33 @Test public void minifiedVersionDoesNotContainFQN() throws Exception {
34 final ClassLoader l = MinifiedTest.class.getClassLoader();
35 Enumeration<URL> en = l.getResources("META-INF/MANIFEST.MF");
36 while (en.hasMoreElements()) {
37 URL u = en.nextElement();
38 Manifest mf = new Manifest(u.openStream());
39 for (Map.Entry<String, Attributes> entrySet : mf.getEntries().entrySet()) {
40 String key = entrySet.getKey();
41 if (!key.contains("-min.js")) {
44 if (!key.contains("javaquery.api")) {
47 try (BufferedReader r = new BufferedReader(new InputStreamReader(l.getResourceAsStream(key)))) {
49 String line = r.readLine();
53 if (line.contains(" org_apidesign_bck2brwsr_htmlpage_Knockout")) {
54 fail("Found FQN of non-public class. Is it minified version?: " + line + " in " + key);
62 final String cp = System.getProperty("java.class.path");
63 if (cp.contains("javaquery" + File.separatorChar + "api" + File.separatorChar + "target" + File.separatorChar + "classes")) {
64 throw new SkipException("Classpath seems to contain classes directories, not JARs. Cannot test.\nCP: " + cp);
66 fail("No minified javaquery found: " + cp);
69 @Test public void debugVersionContainsFQN() throws Exception {
70 final ClassLoader l = MinifiedTest.class.getClassLoader();
71 Enumeration<URL> en = l.getResources("META-INF/MANIFEST.MF");
72 while (en.hasMoreElements()) {
73 URL u = en.nextElement();
74 Manifest mf = new Manifest(u.openStream());
75 for (Map.Entry<String, Attributes> entrySet : mf.getEntries().entrySet()) {
76 String key = entrySet.getKey();
77 if (!key.contains("-debug.js")) {
80 if (!key.contains("javaquery.api")) {
83 try (BufferedReader r = new BufferedReader(new InputStreamReader(l.getResourceAsStream(key)))) {
85 String line = r.readLine();
89 if (line.contains(" org_apidesign_bck2brwsr_htmlpage_Knockout")) {
90 // ok, it should be there
95 fail("Found no FQN of non-public Knockout class. Is it debug version?:" + key);
98 final String cp = System.getProperty("java.class.path");
99 if (cp.contains("javaquery" + File.separatorChar + "api" + File.separatorChar + "target" + File.separatorChar + "classes")) {
100 throw new SkipException("Classpath seems to contain classes directories, not JARs. Cannot test.\nCP: " + cp);
102 fail("No debug javaquery found: " + cp);