sysmodelmgr/com.symbian.smt.gui.test/src/com/symbian/smt/gui/smtwidgets/resources/ResourceFileSelectionValidatorTest.java
changeset 0 522a326673b6
equal deleted inserted replaced
-1:000000000000 0:522a326673b6
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 package com.symbian.smt.gui.smtwidgets.resources;
       
    16 
       
    17 import java.util.ArrayList;
       
    18 import java.util.List;
       
    19 
       
    20 import junit.framework.TestCase;
       
    21 
       
    22 import org.eclipse.swt.widgets.Shell;
       
    23 import org.eclipse.ui.IWorkbench;
       
    24 import org.eclipse.ui.PlatformUI;
       
    25 
       
    26 import com.symbian.smt.gui.ResourcesEnums;
       
    27 import com.symbian.smt.gui.preferences.SmmPreferencesInitializer;
       
    28 import com.symbian.smt.gui.smtwidgets.InvalidPathException;
       
    29 import com.symbian.smt.gui.smtwidgets.XmlFileSelectionDialog;
       
    30 
       
    31 /**
       
    32  * @author barbararosi-schwartz
       
    33  *
       
    34  */
       
    35 public class ResourceFileSelectionValidatorTest extends TestCase {
       
    36 
       
    37 	private XmlFileSelectionDialog dialog;
       
    38 	private String smgFolder;
       
    39 	private ResourceFileSelectionValidator validator;
       
    40 	
       
    41 	/* (non-Javadoc)
       
    42 	 * @see junit.framework.TestCase#setUp()
       
    43 	 */
       
    44 	protected void setUp() throws Exception {
       
    45 		// Initialise the default values
       
    46 		SmmPreferencesInitializer initialiser = new SmmPreferencesInitializer();
       
    47 
       
    48 		initialiser.initializeDefaultPreferences();
       
    49 
       
    50 		smgFolder = initialiser.getSmgFolder();
       
    51 		IWorkbench workbench = PlatformUI.getWorkbench();
       
    52 		Shell shell = workbench.getActiveWorkbenchWindow().getShell();
       
    53 		String dialogTitle = "New System Definition File";
       
    54 		String dialogMessage = "Enter the path or URL to the system definition file";
       
    55 		String initialPath = "";
       
    56 		String[] filterNames = { "*.xml" };
       
    57 		List<CheckableResourceFilename> filenames = new ArrayList<CheckableResourceFilename>();
       
    58 		validator = new ResourceFileSelectionValidator(ResourcesEnums.COLOURS, filenames);
       
    59 		dialog = new XmlFileSelectionDialog(shell, dialogTitle, dialogMessage, initialPath, filterNames, validator); 
       
    60 
       
    61 		dialog.setBlockOnOpen(false);
       
    62 		dialog.open();
       
    63 	}
       
    64 
       
    65 	/* (non-Javadoc)
       
    66 	 * @see junit.framework.TestCase#tearDown()
       
    67 	 */
       
    68 	protected void tearDown() throws Exception {
       
    69 		super.tearDown();
       
    70 	}
       
    71 
       
    72 	/**
       
    73 	 * Test method for {@link com.symbian.smt.gui.smtwidgets.resources.ResourceFileSelectionValidator#ResourceFileSelectionValidator(com.symbian.smt.gui.ResourcesEnums, java.util.List)}.
       
    74 	 */
       
    75 	public final void testResourceFileSelectionValidator() {
       
    76 	}
       
    77 
       
    78 	/**
       
    79 	 * Test method for {@link com.symbian.smt.gui.smtwidgets.resources.ResourceFileSelectionValidator#isFileReadable(java.lang.String)}.
       
    80 	 */
       
    81 	public final void testIsFileReadable() {
       
    82 		String localPath = smgFolder + "/foobar.xml";
       
    83 		
       
    84 		String actual = validator.isFileReadable(localPath);
       
    85 		
       
    86 		assertEquals("Selected file cannot be read.", actual);
       
    87 		
       
    88 		localPath = smgFolder + "/resources/auxiliary/system_model_colors.xml";
       
    89 		
       
    90 		actual = validator.isFileReadable(localPath);
       
    91 		
       
    92 		assertNull(actual);
       
    93 	}
       
    94 
       
    95 	/**
       
    96 	 * Test method for {@link com.symbian.smt.gui.smtwidgets.resources.ResourceFileSelectionValidator#isUrl(java.lang.String)}.
       
    97 	 */
       
    98 	public final void testIsUrl() {
       
    99 		try {
       
   100 			String path = "foo.bar";
       
   101 			boolean result = validator.isUrl(path);
       
   102 			
       
   103 			assertFalse(result);
       
   104 			
       
   105 			path = ":foo.bar:baz";
       
   106 			result = validator.isUrl(path);
       
   107 			
       
   108 			assertFalse(result);
       
   109 			
       
   110 			path = "http://bar.baz";
       
   111 			result = validator.isUrl(path);
       
   112 			
       
   113 			assertTrue(result);
       
   114 		} catch (InvalidPathException e) {
       
   115 			throw new AssertionError(e.getMessage());
       
   116 		}
       
   117 	}
       
   118 
       
   119 	/**
       
   120 	 * Test method for {@link com.symbian.smt.gui.smtwidgets.resources.ResourceFileSelectionValidator#isUrlResourceReadable(java.lang.String)}.
       
   121 	 */
       
   122 	public final void testIsUrlResourceReadable() {
       
   123 		// Not yet implemented
       
   124 	}
       
   125 
       
   126 	/**
       
   127 	 * Test method for {@link com.symbian.smt.gui.smtwidgets.resources.ResourceFileSelectionValidator#isValid(java.lang.String)}.
       
   128 	 */
       
   129 	public final void testIsValid() {
       
   130 		// Not yet implemented
       
   131 	}
       
   132 
       
   133 	/**
       
   134 	 * Test method for {@link com.symbian.smt.gui.smtwidgets.resources.ResourceFileSelectionValidator#isXmlValid(java.lang.String)}.
       
   135 	 */
       
   136 	public final void testIsXmlValid() {
       
   137 		// Not yet implemented
       
   138 	}
       
   139 
       
   140 }