| 1 |
/* ManifestedJar1Test.java |
| 2 |
Copyright (C) 2011 Red Hat, Inc. |
| 3 |
|
| 4 |
This file is part of IcedTea. |
| 5 |
|
| 6 |
IcedTea is free software; you can redistribute it and/or |
| 7 |
modify it under the terms of the GNU General Public License as published by |
| 8 |
the Free Software Foundation, version 2. |
| 9 |
|
| 10 |
IcedTea is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
General Public License for more details. |
| 14 |
|
| 15 |
You should have received a copy of the GNU General Public License |
| 16 |
along with IcedTea; see the file COPYING. If not, write to |
| 17 |
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 18 |
02110-1301 USA. |
| 19 |
|
| 20 |
Linking this library statically or dynamically with other modules is |
| 21 |
making a combined work based on this library. Thus, the terms and |
| 22 |
conditions of the GNU General Public License cover the whole |
| 23 |
combination. |
| 24 |
|
| 25 |
As a special exception, the copyright holders of this library give you |
| 26 |
permission to link this library with independent modules to produce an |
| 27 |
executable, regardless of the license terms of these independent |
| 28 |
modules, and to copy and distribute the resulting executable under |
| 29 |
terms of your choice, provided that you also meet, for each linked |
| 30 |
independent module, the terms and conditions of the license of that |
| 31 |
module. An independent module is a module which is not derived from |
| 32 |
or based on this library. If you modify this library, you may extend |
| 33 |
this exception to your version of the library, but you are not |
| 34 |
obligated to do so. If you do not wish to do so, delete this |
| 35 |
exception statement from your version. |
| 36 |
*/ |
| 37 |
|
| 38 |
import java.util.Arrays; |
| 39 |
import net.sourceforge.jnlp.ProcessResult; |
| 40 |
import net.sourceforge.jnlp.ServerAccess; |
| 41 |
import net.sourceforge.jnlp.annotations.Bug; |
| 42 |
import net.sourceforge.jnlp.runtime.Translator; |
| 43 |
|
| 44 |
import org.junit.Assert; |
| 45 |
import org.junit.Test; |
| 46 |
|
| 47 |
@Bug(id="http://mail.openjdk.java.net/pipermail/distro-pkg-dev/2012-February/017435.html") |
| 48 |
public class ManifestedJar1Test { |
| 49 |
|
| 50 |
private static ServerAccess server = new ServerAccess(); |
| 51 |
private static final String nonLunchableMessage = "net.sourceforge.jnlp.LaunchException: Fatal: Application Error: Not a launchable JNLP file. File must be a JNLP application, applet, or installer type."; |
| 52 |
//actually this on eis never printed as stderr will not recieve this message in headless mode :( |
| 53 |
private static final String twoMainException = "net.sourceforge.jnlp.ParseException: Invalid XML document syntax"; |
| 54 |
|
| 55 |
private void assertManifestedJar1(String id, ProcessResult q) { |
| 56 |
String s = "Hello from ManifestedJar1"; |
| 57 |
Assert.assertTrue(id + " stdout should contains `" + s + "`, but didn't ", q.stdout.contains(s)); |
| 58 |
} |
| 59 |
|
| 60 |
private void assertManifestedJar2(String id, ProcessResult q) { |
| 61 |
String s = "Hello from ManifestedJar2"; |
| 62 |
Assert.assertTrue(id + " stdout should contains `" + s + "`, but didn't ", q.stdout.contains(s)); |
| 63 |
} |
| 64 |
|
| 65 |
private void assertNotManifestedJar1(String id, ProcessResult q) { |
| 66 |
String s = "Hello from ManifestedJar1"; |
| 67 |
Assert.assertFalse(id + " stdout should NOT contains `" + s + "`, but didn ", q.stdout.contains(s)); |
| 68 |
} |
| 69 |
private void assertAppError(String id, ProcessResult q) { |
| 70 |
Assert.assertTrue(id + " stderr should contains `" + nonLunchableMessage + "`, but didnn't ", q.stderr.contains(nonLunchableMessage)); |
| 71 |
} |
| 72 |
|
| 73 |
private void assertNotManifestedJar2(String id, ProcessResult q) { |
| 74 |
String s = "Hello from ManifestedJar2"; |
| 75 |
Assert.assertFalse(id + " stdout should NOT contains `" + s + "`, but didn ", q.stdout.contains(s)); |
| 76 |
} |
| 77 |
|
| 78 |
private void assertNotDead(String id, ProcessResult pr) { |
| 79 |
assertNearlyNotDead(id, pr, 0); |
| 80 |
} |
| 81 |
|
| 82 |
private void assertNearlyNotDead(String id, ProcessResult pr, int i) { |
| 83 |
String cc = "ClassNotFoundException"; |
| 84 |
Assert.assertFalse(id + " stderr should NOT contains `" + cc + "`, but did", pr.stderr.contains(cc)); |
| 85 |
Assert.assertFalse(id + " should not be terminated, but was", pr.wasTerminated); |
| 86 |
Assert.assertEquals((Integer) i, pr.returnValue); |
| 87 |
} |
| 88 |
|
| 89 |
@Test |
| 90 |
/** |
| 91 |
* if two jars with manifest specified, none is main and no main class, then first one is loaded |
| 92 |
*/ |
| 93 |
public void manifestedJar1nothing2nothingNoAppDesc() throws Exception { |
| 94 |
String id = "ManifestedJar-1nothing2nothingNoAppDesc"; |
| 95 |
ProcessResult pr = server.executeJavawsHeadless(null, "/" + id + ".jnlp"); |
| 96 |
assertManifestedJar1(id, pr); |
| 97 |
assertNotDead(id, pr); |
| 98 |
} |
| 99 |
|
| 100 |
/** |
| 101 |
*if one jar with manifest, is not main, and no main class then is lunched |
| 102 |
* |
| 103 |
*/ |
| 104 |
@Test |
| 105 |
public void manifestedJar1noAppDesc() throws Exception { |
| 106 |
String id = "ManifestedJar-1noAppDesc"; |
| 107 |
ProcessResult pr = server.executeJavawsHeadless(null, "/" + id + ".jnlp"); |
| 108 |
assertManifestedJar1(id, pr); |
| 109 |
assertNotDead(id, pr); |
| 110 |
} |
| 111 |
|
| 112 |
/** |
| 113 |
*if one jar with manifest, but not marked as main and no main class then is lunched |
| 114 |
* |
| 115 |
*/ |
| 116 |
@Test |
| 117 |
public void manifestedJar1mainNoAppDesc() throws Exception { |
| 118 |
String id = "ManifestedJar-1mainNoAppDesc"; |
| 119 |
ProcessResult pr = server.executeJavawsHeadless(null, "/" + id + ".jnlp"); |
| 120 |
assertManifestedJar1(id, pr); |
| 121 |
assertNotDead(id, pr); |
| 122 |
} |
| 123 |
|
| 124 |
/** |
| 125 |
*if one jar with manifest, marked as main and no main class then is lunched |
| 126 |
* |
| 127 |
*/ |
| 128 |
@Test |
| 129 |
public void ManifestedJar1mainHaveAppDesc() throws Exception { |
| 130 |
String id = "ManifestedJar-1mainHaveAppDesc"; |
| 131 |
ProcessResult pr = server.executeJavawsHeadless(null, "/" + id + ".jnlp"); |
| 132 |
assertManifestedJar2(id, pr); |
| 133 |
assertNotDead(id, pr); |
| 134 |
} |
| 135 |
|
| 136 |
/** |
| 137 |
* |
| 138 |
* Two jars, both with manifest, First is main, but specified mainclass belongs to second one, then second one should be lunched |
| 139 |
*/ |
| 140 |
@Test |
| 141 |
public void ManifestedJar1main2nothingNoAppDesc() throws Exception { |
| 142 |
String id = "ManifestedJar-1main2nothingNoAppDesc"; |
| 143 |
ProcessResult pr = server.executeJavawsHeadless(null, "/" + id + ".jnlp"); |
| 144 |
assertManifestedJar2(id, pr); |
| 145 |
assertNotDead(id, pr); |
| 146 |
} |
| 147 |
|
| 148 |
/** |
| 149 |
* |
| 150 |
* Two jars, both with manifest, seconds is main, no mainclass, then the one marked as main is lunched |
| 151 |
*/ |
| 152 |
@Test |
| 153 |
public void manifestedJar1main2nothingNoAppDesc() throws Exception { |
| 154 |
String id = "ManifestedJar-1main2nothingNoAppDesc"; |
| 155 |
ProcessResult pr = server.executeJavawsHeadless(null, "/" + id + ".jnlp"); |
| 156 |
assertManifestedJar2(id, pr); |
| 157 |
assertNotDead(id, pr); |
| 158 |
} |
| 159 |
|
| 160 |
/** |
| 161 |
* |
| 162 |
* Two jars, both with manifest, sboth with main tag, no app desc |
| 163 |
* first jar is taken |
| 164 |
* |
| 165 |
*/ |
| 166 |
@Test |
| 167 |
public void manifestedJar1main2mainNoAppDesc() throws Exception { |
| 168 |
String id = "ManifestedJar-1main2mainNoAppDesc"; |
| 169 |
ProcessResult pr = server.executeJavawsHeadless(null, "/" + id + ".jnlp"); |
| 170 |
assertManifestedJar1(id, pr); |
| 171 |
assertNotManifestedJar2(id, pr); |
| 172 |
assertNotDead(id, pr); |
| 173 |
} |
| 174 |
|
| 175 |
/** |
| 176 |
* |
| 177 |
* Two jars, both with manifest, sboth with main tag, no app desc |
| 178 |
* two main jars reported |
| 179 |
* |
| 180 |
*/ |
| 181 |
@Test |
| 182 |
public void manifestedJar1main2mainNoAppDescStrict() throws Exception { |
| 183 |
String id = "ManifestedJar-1main2mainNoAppDesc"; |
| 184 |
ProcessResult pr = server.executeJavawsHeadless(Arrays.asList(new String[]{"-strict"}), "/" + id + ".jnlp"); |
| 185 |
assertNotManifestedJar1(id, pr); |
| 186 |
assertNotManifestedJar2(id, pr); |
| 187 |
assertNearlyNotDead(id, pr, 1); |
| 188 |
Assert.assertTrue(pr.stderr.contains(Translator.R("PTwoMains")) || pr.stdout.contains(Translator.R("PTwoMains"))); |
| 189 |
} |
| 190 |
|
| 191 |
/** |
| 192 |
* |
| 193 |
* Two jars, both with manifest, sboth with main tag, have app desc |
| 194 |
* |
| 195 |
* launching first |
| 196 |
*/ |
| 197 |
@Test |
| 198 |
public void manifestedJar1main2mainAppDesc() throws Exception { |
| 199 |
String id = "ManifestedJar-1main2mainAppDesc"; |
| 200 |
ProcessResult pr = server.executeJavawsHeadless(null, "/" + id + ".jnlp"); |
| 201 |
assertManifestedJar1(id, pr); |
| 202 |
assertNotManifestedJar2(id, pr); |
| 203 |
assertNotDead(id, pr); |
| 204 |
} |
| 205 |
|
| 206 |
/** |
| 207 |
* |
| 208 |
* Two jars, both with manifest, sboth with main tag, have app desc |
| 209 |
* |
| 210 |
* corectly failing |
| 211 |
*/ |
| 212 |
@Test |
| 213 |
public void manifestedJar1noAppDescAtAll() throws Exception { |
| 214 |
String id = "ManifestedJar-1noAppDescAtAll"; |
| 215 |
ProcessResult pr = server.executeJavawsHeadless(null, "/" + id + ".jnlp"); |
| 216 |
assertNotManifestedJar1(id, pr); |
| 217 |
assertNotManifestedJar2(id, pr); |
| 218 |
assertAppError(id, pr); |
| 219 |
assertNearlyNotDead(id, pr, 1); |
| 220 |
} |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
/** |
| 225 |
* |
| 226 |
* Two jars, both with manifest, non with main tag, have app desc |
| 227 |
* |
| 228 |
* this jnlp is NOT lunched, twoMainException thrown - ok |
| 229 |
* |
| 230 |
*/ |
| 231 |
@Test |
| 232 |
public void manifestedJar1nothing2nothingAppDesc() throws Exception { |
| 233 |
String id = "ManifestedJar-1nothing2nothingAppDesc"; |
| 234 |
ProcessResult pr = server.executeJavawsHeadless(null, "/" + id + ".jnlp"); |
| 235 |
assertManifestedJar2(id, pr); |
| 236 |
assertNotManifestedJar1(id, pr); |
| 237 |
assertNotDead(id, pr); |
| 238 |
} |
| 239 |
|
| 240 |
} |