|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2010 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
| 10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.core.tests.resources.session; |
| 12 |
|
| 13 |
import junit.framework.Test; |
| 14 |
import org.eclipse.core.resources.*; |
| 15 |
import org.eclipse.core.runtime.CoreException; |
| 16 |
import org.eclipse.core.tests.resources.AutomatedTests; |
| 17 |
import org.eclipse.core.tests.resources.WorkspaceSessionTest; |
| 18 |
import org.eclipse.core.tests.session.WorkspaceSessionTestSuite; |
| 19 |
|
| 20 |
/** |
| 21 |
* Test for bug 202384 |
| 22 |
*/ |
| 23 |
public class TestBug202384 extends WorkspaceSessionTest { |
| 24 |
public TestBug202384() { |
| 25 |
super(); |
| 26 |
} |
| 27 |
|
| 28 |
public TestBug202384(String name) { |
| 29 |
super(name); |
| 30 |
} |
| 31 |
|
| 32 |
public void testInitializeWorkspace() { |
| 33 |
IWorkspace workspace = ResourcesPlugin.getWorkspace(); |
| 34 |
IProject project = workspace.getRoot().getProject("project"); |
| 35 |
ensureExistsInWorkspace(project, true); |
| 36 |
try { |
| 37 |
project.setDefaultCharset("UTF-8", getMonitor()); |
| 38 |
} catch (CoreException e1) { |
| 39 |
fail("1.0", e1); |
| 40 |
} |
| 41 |
try { |
| 42 |
assertEquals("UTF-8", project.getDefaultCharset()); |
| 43 |
} catch (CoreException e) { |
| 44 |
fail("2.0", e); |
| 45 |
} |
| 46 |
try { |
| 47 |
project.close(getMonitor()); |
| 48 |
} catch (CoreException e) { |
| 49 |
fail("3.0", e); |
| 50 |
} |
| 51 |
assertFalse(project.isOpen()); |
| 52 |
try { |
| 53 |
workspace.save(true, getMonitor()); |
| 54 |
} catch (CoreException e) { |
| 55 |
fail("4.0", e); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
public void testStartWithClosedProject() { |
| 60 |
IWorkspace workspace = ResourcesPlugin.getWorkspace(); |
| 61 |
IProject project = workspace.getRoot().getProject("project"); |
| 62 |
assertFalse(project.isOpen()); |
| 63 |
try { |
| 64 |
//ProjectPreferences should get created on getDefaultCharset but not |
| 65 |
//initialized hence it is not possible to read correct encoding |
| 66 |
assertNull(project.getDefaultCharset(false)); |
| 67 |
} catch (CoreException e) { |
| 68 |
fail("1.0", e); |
| 69 |
} |
| 70 |
try { |
| 71 |
//opening project should re-initialize already loaded ProjectPreferences |
| 72 |
//because project resources are now available |
| 73 |
project.open(getMonitor()); |
| 74 |
} catch (CoreException e) { |
| 75 |
fail("2.0", e); |
| 76 |
} |
| 77 |
try { |
| 78 |
//correct values should be available after re-initialization |
| 79 |
assertEquals("UTF-8", project.getDefaultCharset()); |
| 80 |
} catch (CoreException e) { |
| 81 |
fail("3.0", e); |
| 82 |
} |
| 83 |
try { |
| 84 |
workspace.save(true, getMonitor()); |
| 85 |
} catch (CoreException e) { |
| 86 |
fail("4.0", e); |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
public void testStartWithOpenProject() { |
| 91 |
IWorkspace workspace = ResourcesPlugin.getWorkspace(); |
| 92 |
IProject project = workspace.getRoot().getProject("project"); |
| 93 |
assertTrue(project.isOpen()); |
| 94 |
try { |
| 95 |
//correct values should be available if ProjectPreferences got |
| 96 |
//initialized upon creation |
| 97 |
assertEquals("UTF-8", project.getDefaultCharset(false)); |
| 98 |
} catch (CoreException e) { |
| 99 |
fail("1.0", e); |
| 100 |
} |
| 101 |
try { |
| 102 |
workspace.save(true, getMonitor()); |
| 103 |
} catch (CoreException e) { |
| 104 |
fail("2.0", e); |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
public static Test suite() { |
| 109 |
return new WorkspaceSessionTestSuite(AutomatedTests.PI_RESOURCES_TESTS, TestBug202384.class); |
| 110 |
} |
| 111 |
} |