1 /* 2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.javafx.tools.packager; 27 28 import java.io.File; 29 import static org.junit.Assert.*; 30 import org.junit.Test; 31 import org.junit.Before; 32 import org.junit.After; 33 34 public class DeployParamsTest { 35 36 private File testRoot = null; 37 38 @Before 39 public void setUp() { 40 testRoot = new File("build/tmp/tests/deployParamsTest"); 41 testRoot.mkdirs(); 42 } 43 44 @After 45 public void tearDown() { 46 if (testRoot != null) { 47 testRoot.delete(); 48 } 49 } 50 51 @Test 52 public void testValidateAppName1() throws PackagerException { 53 DeployParams params = getParamsAppName(); 54 55 params.setAppName("Test"); 56 params.validate(); 57 58 params.setAppName("Test Name"); 59 params.validate(); 60 61 params.setAppName("Test - Name !!!"); 62 params.validate(); 63 } 64 65 @Test 66 public void testValidateAppName2() throws PackagerException { 67 DeployParams params = getParamsAppName(); 68 69 params.setAppName("Test\nName"); 70 appName2TestHelper(params); 71 72 params.setAppName("Test\rName"); 73 appName2TestHelper(params); 74 75 params.setAppName("TestName\\"); 76 appName2TestHelper(params); 77 78 params.setAppName("Test \" Name"); 79 appName2TestHelper(params); 80 } 81 82 private void appName2TestHelper(DeployParams params) { 83 try { 84 params.validate(); 85 fail("An exception should have been thrown"); 86 } catch (PackagerException pe) { } 87 } 88 89 // Returns deploy params initialized to pass all validation, except for 90 // app name 91 private DeployParams getParamsAppName() { 92 DeployParams params = new DeployParams(); 93 params.setOutdir(testRoot); 94 params.setOutfile("Test"); 95 params.addResource(testRoot, new File(testRoot, "test.jar")); 96 params.setApplicationClass("TestClass"); 97 return params; 98 } 99 100 }