1 /******************************************************************************* 2 * Copyright (c) 2009, 2010 Cloudsmith Inc. and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * Cloudsmith Inc. - initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.equinox.p2.tests.artifact.repository; 15 16 import java.io.*; 17 import java.net.URI; 18 import java.net.URISyntaxException; 19 import org.eclipse.core.runtime.*; 20 import org.eclipse.equinox.p2.tests.AbstractProvisioningTest; 21 import org.osgi.framework.BundleException; 22 23 /** 24 * Test supposed to be used interactively to monitor the error message output. 25 * 26 */ 27 public class TransferExceptionsTest extends AbstractProvisioningTest { 28 testErrorMessages()29 public void testErrorMessages() { 30 FileOutputStream fos = null; 31 File f = null; 32 try { 33 f = File.createTempFile("TransferTest", "dummy.txt"); 34 fos = new FileOutputStream(f); 35 Platform.getBundle("org.eclipse.ecf.provider.filetransfer").start(); 36 } catch (IOException e) { 37 fail("1.0", e); 38 } catch (BundleException e) { 39 fail("1.5", e); 40 } 41 try { 42 IStatus s = getTransport().download(new URI("bogus!bogus"), fos, new NullProgressMonitor()); 43 assertNotOK(s); 44 printStatus("1", s); 45 s = getTransport().download(new URI("bogus://somewhere.else"), fos, new NullProgressMonitor()); 46 assertNotOK(s); 47 printStatus("2", s); 48 s = getTransport().download(new URI("http:bogusURL"), fos, new NullProgressMonitor()); 49 assertNotOK(s); 50 printStatus("3", s); 51 s = getTransport().download(new URI("http://bogusURL:80/"), fos, new NullProgressMonitor()); 52 assertNotOK(s); 53 printStatus("4", s); 54 s = getTransport().download(new URI("http:/bogusURL:999999999999/"), fos, new NullProgressMonitor()); 55 assertNotOK(s); 56 printStatus("5", s); 57 s = getTransport().download(new URI("http://bogus.nowhere"), fos, new NullProgressMonitor()); 58 assertNotOK(s); 59 printStatus("6", s); 60 s = getTransport().download(new URI("http://www.eclipse.org/AFileThatDoesNotExist.foo"), fos, new NullProgressMonitor()); 61 assertNotOK(s); 62 printStatus("7", s); 63 } catch (URISyntaxException e) { 64 fail("URI syntax exception where none was expected: " + e.getMessage()); 65 } 66 } 67 printStatus(String msg, IStatus s)68 private static void printStatus(String msg, IStatus s) { 69 System.err.print("TEST OUTPUT: " + msg + "\n"); 70 System.err.print(" "); 71 System.err.print("Message [" + s.getMessage() + "] Exception Class[" + s.getException().getClass().getName() + "] ExceptionMessage[ "); 72 System.err.print(s.getException().getMessage() + "]\n"); 73 74 } 75 76 } 77