| 1 |
/* |
| 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 java.util.List; |
| 40 |
import net.sourceforge.jnlp.OptionsDefinitions; |
| 41 |
import net.sourceforge.jnlp.ProcessResult; |
| 42 |
import net.sourceforge.jnlp.ServerAccess; |
| 43 |
import net.sourceforge.jnlp.annotations.Bug; |
| 44 |
import net.sourceforge.jnlp.closinglisteners.AutoOkClosingListener; |
| 45 |
import org.junit.Assert; |
| 46 |
|
| 47 |
import org.junit.Test; |
| 48 |
|
| 49 |
public class LoadResourcesTest { |
| 50 |
|
| 51 |
private static final ServerAccess server = new ServerAccess(); |
| 52 |
|
| 53 |
static void checkLaunched(ProcessResult pr, boolean app1, boolean javaws) { |
| 54 |
String s11 = "LoadResources started"; |
| 55 |
String s12 = "LoadResourcesPackaged started"; |
| 56 |
if (app1) { |
| 57 |
assertContains(s12, pr); |
| 58 |
assertNotContains(s11, pr); |
| 59 |
} else { |
| 60 |
assertContains(s11, pr); |
| 61 |
assertNotContains(s12, pr); |
| 62 |
} |
| 63 |
if (!javaws) { |
| 64 |
String c01 = "[CONSTRUCTOR]context(some.file): Pass - "; |
| 65 |
//without fix for 2968, this fails |
| 66 |
assertContains(c01, pr); |
| 67 |
String c02 = "[CONSTRUCTOR]class(some.file): Pass - "; |
| 68 |
assertContains(c02, pr); |
| 69 |
String c03 = "[CONSTRUCTOR]system(some.file): Fail - "; |
| 70 |
//why so?, still everywhere... |
| 71 |
assertContains(c03, pr); |
| 72 |
String c04 = "[CONSTRUCTOR]context(LoadResources.class): Pass - "; |
| 73 |
//without fix for 2968, this fails |
| 74 |
assertContains(c04, pr); |
| 75 |
String c05 = "[CONSTRUCTOR]class(LoadResources.class): Pass - "; |
| 76 |
assertContains(c05, pr); |
| 77 |
String c06 = "[CONSTRUCTOR]system(LoadResources.class): Fail - "; |
| 78 |
assertContains(c06, pr); |
| 79 |
String c07 = "[CONSTRUCTOR]context(some/pkg/LoadResourcesPackaged.class): Pass - "; |
| 80 |
assertContains(c07, pr); |
| 81 |
String c08 = "[CONSTRUCTOR]class(some/pkg/LoadResourcesPackaged.class): Pass - "; |
| 82 |
assertContains(c08, pr); |
| 83 |
String c09 = "[CONSTRUCTOR]system(some/pkg/LoadResourcesPackaged.class): Fail - "; |
| 84 |
assertContains(c09, pr); |
| 85 |
String c10 = "[CONSTRUCTOR]this(some.file): Pass - "; |
| 86 |
assertContains(c10, pr); |
| 87 |
String c11 = "[CONSTRUCTOR]this(LoadResources.class): Pass - "; |
| 88 |
assertContains(c11, pr); |
| 89 |
String c12 = "[CONSTRUCTOR]this(some/pkg/LoadResourcesPackaged.class): Pass - "; |
| 90 |
assertContains(c12, pr); |
| 91 |
String c13 = "[INIT]context(some.file): Fail - "; |
| 92 |
// this is weird. Why fix for 2968 fixed only constructor? |
| 93 |
assertContains(c13, pr); |
| 94 |
String c14 = "[INIT]class(some.file): Pass - "; |
| 95 |
//safest as ususlly |
| 96 |
assertContains(c14, pr); |
| 97 |
String c15 = "[INIT]system(some.file): Fail - "; |
| 98 |
//failing as usually |
| 99 |
assertContains(c15, pr); |
| 100 |
String c16 = "[INIT]context(LoadResources.class): Fail - "; |
| 101 |
// this is weird. Why fix for 2968 fixed only constructor? |
| 102 |
assertContains(c16, pr); |
| 103 |
String c17 = "[INIT]class(LoadResources.class): Pass - "; |
| 104 |
assertContains(c17, pr); |
| 105 |
String c18 = "[INIT]system(LoadResources.class): Fail - "; |
| 106 |
assertContains(c18, pr); |
| 107 |
String c19 = "[INIT]context(some/pkg/LoadResourcesPackaged.class): Fail - "; |
| 108 |
assertContains(c19, pr); |
| 109 |
String c20 = "[INIT]class(some/pkg/LoadResourcesPackaged.class): Pass - "; |
| 110 |
assertContains(c20, pr); |
| 111 |
String c21 = "[INIT]system(some/pkg/LoadResourcesPackaged.class): Fail - "; |
| 112 |
assertContains(c21, pr); |
| 113 |
String c22 = "[INIT]this(some.file): Pass - "; |
| 114 |
assertContains(c22, pr); |
| 115 |
String c23 = "[INIT]this(LoadResources.class): Pass - "; |
| 116 |
assertContains(c23, pr); |
| 117 |
String c24 = "[INIT]this(some/pkg/LoadResourcesPackaged.class): Pass - "; |
| 118 |
assertContains(c24, pr); |
| 119 |
String c25 = "[START]context(some.file): Fail - "; |
| 120 |
//still the surprise |
| 121 |
assertContains(c15, pr); |
| 122 |
String c26 = "[START]class(some.file): Pass - "; |
| 123 |
assertContains(c16, pr); |
| 124 |
String c27 = "[START]system(some.file): Fail - "; |
| 125 |
assertContains(c27, pr); |
| 126 |
String c28 = "[START]context(LoadResources.class): Fail - "; |
| 127 |
assertContains(c28, pr); |
| 128 |
String c29 = "[START]class(LoadResources.class): Pass - "; |
| 129 |
assertContains(c29, pr); |
| 130 |
String c30 = "[START]system(LoadResources.class): Fail - "; |
| 131 |
assertContains(c30, pr); |
| 132 |
String c31 = "[START]context(some/pkg/LoadResourcesPackaged.class): Fail - "; |
| 133 |
assertContains(c31, pr); |
| 134 |
String c32 = "[START]class(some/pkg/LoadResourcesPackaged.class): Pass - "; |
| 135 |
assertContains(c32, pr); |
| 136 |
String c33 = "[START]system(some/pkg/LoadResourcesPackaged.class): Fail - "; |
| 137 |
assertContains(c33, pr); |
| 138 |
String c34 = "[START]this(some.file): Pass - "; |
| 139 |
assertContains(c34, pr); |
| 140 |
String c35 = "[START]this(LoadResources.class): Pass - "; |
| 141 |
assertContains(c35, pr); |
| 142 |
String c36 = "[START]this(some/pkg/LoadResourcesPackaged.class): Pass - "; |
| 143 |
assertContains(c36, pr); |
| 144 |
} else { |
| 145 |
String c1 = "[MAIN]context(some.file): Pass - "; |
| 146 |
//javaws was never affeted by 2968 |
| 147 |
assertContains(c1, pr); |
| 148 |
String c2 = "[MAIN]class(some.file): Pass - "; |
| 149 |
assertContains(c2, pr); |
| 150 |
String c3 = "[MAIN]system(some.file): Fail - "; |
| 151 |
assertContains(c3, pr); |
| 152 |
String c4 = "[MAIN]context(LoadResources.class): Pass - "; |
| 153 |
//interesting difference compared to start/init of same call |
| 154 |
assertContains(c4, pr); |
| 155 |
String c5 = "[MAIN]class(LoadResources.class): Pass - "; |
| 156 |
assertContains(c5, pr); |
| 157 |
String c6 = "[MAIN]system(LoadResources.class): Fail - "; |
| 158 |
assertContains(c6, pr); |
| 159 |
String c7 = "[MAIN]context(some/pkg/LoadResourcesPackaged.class): Pass - "; |
| 160 |
//interesting difference compared to start/init of same call |
| 161 |
assertContains(c7, pr); |
| 162 |
String c8 = "[MAIN]class(some/pkg/LoadResourcesPackaged.class): Pass - "; |
| 163 |
assertContains(c8, pr); |
| 164 |
String c9 = "[MAIN]system(some/pkg/LoadResourcesPackaged.class): Fail - "; |
| 165 |
assertContains(c9, pr); |
| 166 |
|
| 167 |
} |
| 168 |
|
| 169 |
} |
| 170 |
|
| 171 |
private static void assertContains(String c01, ProcessResult pr) { |
| 172 |
Assert.assertTrue("loadResourcesTest stdout should contains " + c01 + " bud didn't", pr.stdout.contains(c01)); |
| 173 |
} |
| 174 |
|
| 175 |
private static void assertNotContains(String s11, ProcessResult pr) { |
| 176 |
Assert.assertFalse("loadResourcesTest stdout should contains " + s11 + " bud didn", pr.stdout.contains(s11)); |
| 177 |
} |
| 178 |
|
| 179 |
@Test |
| 180 |
public void loadResourcesTest1() throws Exception { |
| 181 |
//with args, dont forget -jnlp |
| 182 |
final List<String> args = Arrays.asList(new String[]{ |
| 183 |
OptionsDefinitions.OPTIONS.ARG.option, |
| 184 |
"type1", |
| 185 |
"some.file", |
| 186 |
OptionsDefinitions.OPTIONS.JNLP.option}); |
| 187 |
ProcessResult pr = server.executeJavawsHeadless(args, "/LoadResources1.jnlp"); |
| 188 |
checkLaunched(pr, false, true); |
| 189 |
} |
| 190 |
|
| 191 |
@Test |
| 192 |
public void loadResourcesTest2() throws Exception { |
| 193 |
//with args, dont forget -jnlp |
| 194 |
final List<String> args = Arrays.asList(new String[]{ |
| 195 |
OptionsDefinitions.OPTIONS.ARG.option, |
| 196 |
"type1", |
| 197 |
"some.file", |
| 198 |
OptionsDefinitions.OPTIONS.JNLP.option}); |
| 199 |
ProcessResult pr = server.executeJavawsHeadless(args, "/LoadResources2.jnlp"); |
| 200 |
checkLaunched(pr, true, true); |
| 201 |
} |
| 202 |
|
| 203 |
@Test |
| 204 |
@Bug(id = "2968") |
| 205 |
public void loadResourcesAppletTest1() throws Exception { |
| 206 |
//with args, dont forget -jnlp |
| 207 |
final List<String> args = Arrays.asList(new String[]{ |
| 208 |
OptionsDefinitions.OPTIONS.JNLP.option}); |
| 209 |
ProcessResult pr = server.executeJavawsHeadless(args, "/LoadResourcesApplet1.jnlp", new AutoOkClosingListener(), null, null); |
| 210 |
checkLaunched(pr, false, false); |
| 211 |
} |
| 212 |
|
| 213 |
@Test |
| 214 |
@Bug(id = "2968") |
| 215 |
public void loadResourcesTestApplet2() throws Exception { |
| 216 |
//with args, dont forget -jnlp |
| 217 |
final List<String> args = Arrays.asList(new String[]{ |
| 218 |
OptionsDefinitions.OPTIONS.JNLP.option}); |
| 219 |
ProcessResult pr = server.executeJavawsHeadless(args, "/LoadResourcesApplet2.jnlp", new AutoOkClosingListener(), null, null); |
| 220 |
checkLaunched(pr, true, false); |
| 221 |
} |
| 222 |
|
| 223 |
} |