summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNoopur Gupta2013-01-21 07:24:33 (EST)
committer Dani Megert2013-01-21 07:24:33 (EST)
commit9a9b9d6fd7d116505f8f2933d6c8047f391e366a (patch)
tree0bfe0f9593861ccf063cfe5b159300efbd24945d
parent4628086c831c2e0cecea6c69877495de98b7ce62 (diff)
downloadeclipse.jdt.ui-9a9b9d6fd7d116505f8f2933d6c8047f391e366a.zip
eclipse.jdt.ui-9a9b9d6fd7d116505f8f2933d6c8047f391e366a.tar.gz
eclipse.jdt.ui-9a9b9d6fd7d116505f8f2933d6c8047f391e366a.tar.bz2
Fixed bug 398076: Add test cases for bug 357450
-rw-r--r--org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/ContentProviderTests6.java224
-rw-r--r--org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/PackageExplorerTests.java3
2 files changed, 226 insertions, 1 deletions
diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/ContentProviderTests6.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/ContentProviderTests6.java
new file mode 100644
index 0000000..1670ce2
--- /dev/null
+++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/ContentProviderTests6.java
@@ -0,0 +1,224 @@
+/*******************************************************************************
+ * Copyright (c) 2013 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.ui.tests.packageview;
+
+import java.io.ByteArrayInputStream;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.jdt.testplugin.JavaProjectHelper;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceDescription;
+import org.eclipse.core.resources.ResourcesPlugin;
+
+import org.eclipse.jface.viewers.ITreeContentProvider;
+
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PlatformUI;
+
+import org.eclipse.jdt.core.ElementChangedEvent;
+import org.eclipse.jdt.core.IElementChangedListener;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.JavaCore;
+
+import org.eclipse.jdt.internal.core.JavaElementDelta;
+
+import org.eclipse.jdt.internal.ui.packageview.LibraryContainer;
+import org.eclipse.jdt.internal.ui.packageview.PackageExplorerContentProvider;
+import org.eclipse.jdt.internal.ui.util.CoreUtility;
+
+
+/**
+ * Tests for the PackageExplorerContentProvider.
+ * <ul>
+ * <li>Bug 357450: Class folder in Java project have refresh problem</li>
+ * </ul>
+ *
+ * @since 3.9
+ */
+public class ContentProviderTests6 extends TestCase {
+ private IWorkspace fWorkspace;
+ private boolean fEnableAutoBuildAfterTesting;
+
+ private IWorkbench fWorkbench;
+ private IWorkbenchPage page;
+ private MockPluginView fMyPart;
+
+ private ITreeContentProvider fProvider;
+
+ private IJavaProject fJProject;
+ private IPackageFragmentRoot classFolder;
+
+
+ public ContentProviderTests6(String name) {
+ super(name);
+ }
+
+ public static Test suite() {
+ TestSuite suite= new TestSuite("org.eclipse.jdt.ui.tests.ContentProviderTests6"); //$NON-NLS-1$
+ //$JUnit-BEGIN$
+ suite.addTestSuite(ContentProviderTests6.class);
+ //$JUnit-END$
+ return suite;
+ }
+
+ public void testAddFileToClassFolder() throws Exception {
+ IFile file= ((IFolder)classFolder.getResource()).getFile("testFile.class"); //$NON-NLS-1$
+ if (!file.exists()) {
+ file.create(new ByteArrayInputStream(new byte[] {}), false, null);
+ }
+
+ //send a delta indicating file added
+ JavaElementDelta delta= new JavaElementDelta(classFolder.getJavaModel());
+ delta.added(JavaCore.create(file));
+ IElementChangedListener listener= (IElementChangedListener)fProvider;
+ listener.elementChanged(new ElementChangedEvent(delta, ElementChangedEvent.POST_CHANGE));
+
+ //force events from display
+ while (fMyPart.getTreeViewer().getControl().getDisplay().readAndDispatch()) {
+ }
+
+ assertTrue("No add happened", !fMyPart.hasAddHappened()); //$NON-NLS-1$
+ assertions();
+ }
+
+ public void testAddFolderToClassFolder() throws Exception {
+ IFolder folder= ((IFolder)classFolder.getResource()).getFolder("testFolder"); //$NON-NLS-1$
+ if (!folder.exists()) {
+ folder.create(false, true, null);
+ }
+
+ //send a delta indicating folder added
+ JavaElementDelta delta= new JavaElementDelta(classFolder.getJavaModel());
+ delta.added(JavaCore.create(folder));
+ IElementChangedListener listener= (IElementChangedListener)fProvider;
+ listener.elementChanged(new ElementChangedEvent(delta, ElementChangedEvent.POST_CHANGE));
+
+ //force events from display
+ while (fMyPart.getTreeViewer().getControl().getDisplay().readAndDispatch()) {
+ }
+
+ assertTrue("No add happened", !fMyPart.hasAddHappened()); //$NON-NLS-1$
+ assertions();
+ }
+
+ public void testRemoveFileFromClassFolder() throws Exception {
+ IFile file= ((IFolder)classFolder.getResource()).getFile("testFile.class"); //$NON-NLS-1$
+ if (!file.exists()) {
+ file.create(new ByteArrayInputStream(new byte[] {}), false, null);
+ }
+ file.delete(false, null);
+
+ //send a delta indicating file removed
+ JavaElementDelta delta= new JavaElementDelta(classFolder.getJavaModel());
+ delta.removed(JavaCore.create(file));
+ IElementChangedListener listener= (IElementChangedListener)fProvider;
+ listener.elementChanged(new ElementChangedEvent(delta, ElementChangedEvent.POST_CHANGE));
+
+ //force events from display
+ while (fMyPart.getTreeViewer().getControl().getDisplay().readAndDispatch()) {
+ }
+
+ assertTrue("No remove happened", !fMyPart.hasRemoveHappened()); //$NON-NLS-1$
+ assertions();
+ }
+
+ public void testRemoveFolderFromClassFolder() throws Exception {
+ IFolder folder= ((IFolder)classFolder.getResource()).getFolder("testFolder"); //$NON-NLS-1$
+ if (!folder.exists()) {
+ folder.create(false, true, null);
+ }
+ folder.delete(false, null);
+
+ //send a delta indicating folder deleted
+ JavaElementDelta delta= new JavaElementDelta(classFolder.getJavaModel());
+ delta.removed(JavaCore.create(folder));
+ IElementChangedListener listener= (IElementChangedListener)fProvider;
+ listener.elementChanged(new ElementChangedEvent(delta, ElementChangedEvent.POST_CHANGE));
+
+ //force events from display
+ while (fMyPart.getTreeViewer().getControl().getDisplay().readAndDispatch()) {
+ }
+
+ assertTrue("No remove happened", !fMyPart.hasRemoveHappened()); //$NON-NLS-1$
+ assertions();
+ }
+
+ private void assertions() {
+ assertTrue("Refresh happened", fMyPart.hasRefreshHappened()); //$NON-NLS-1$
+ assertTrue("LibraryContainer Refreshed", fMyPart.wasObjectRefreshed(new LibraryContainer(fJProject))); //$NON-NLS-1$
+ assertTrue("Resource Refreshed", fMyPart.wasObjectRefreshed(classFolder.getResource())); //$NON-NLS-1$
+ assertTrue("Number of refreshed objects", fMyPart.getRefreshedObject().size() == 2); //$NON-NLS-1$
+ }
+
+ /*
+ * @see TestCase#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ fWorkspace= ResourcesPlugin.getWorkspace();
+ assertNotNull(fWorkspace);
+ IWorkspaceDescription workspaceDesc= fWorkspace.getDescription();
+ fEnableAutoBuildAfterTesting= workspaceDesc.isAutoBuilding();
+ if (fEnableAutoBuildAfterTesting)
+ CoreUtility.setAutoBuilding(false);
+
+ fJProject= JavaProjectHelper.createJavaProject("TestProject", "bin");//$NON-NLS-1$//$NON-NLS-2$
+ assertNotNull("project null", fJProject);//$NON-NLS-1$
+
+ //set up project : Add classFolder
+ classFolder= JavaProjectHelper.addClassFolder(fJProject, "classFolder", null, null); //$NON-NLS-1$
+ assertNotNull("class folder null", classFolder); //$NON-NLS-1$
+
+ //set up the mock view
+ setUpMockView();
+ }
+
+ public void setUpMockView() throws Exception{
+ fWorkbench= PlatformUI.getWorkbench();
+ assertNotNull(fWorkbench);
+
+ page= fWorkbench.getActiveWorkbenchWindow().getActivePage();
+ assertNotNull(page);
+
+ IViewPart myPart= page.showView("org.eclipse.jdt.ui.tests.packageview.MockPluginView"); //$NON-NLS-1$
+ if (myPart instanceof MockPluginView) {
+ fMyPart= (MockPluginView)myPart;
+ fMyPart.clear();
+ fProvider= (ITreeContentProvider)fMyPart.getTreeViewer().getContentProvider();
+ ((PackageExplorerContentProvider)fProvider).setShowLibrariesNode(true);
+ } else {
+ assertTrue("Unable to get view", false);//$NON-NLS-1$
+ }
+ assertNotNull(fProvider);
+ }
+
+ /**
+ * @see TestCase#tearDown()
+ */
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ JavaProjectHelper.delete(fJProject);
+ if (fEnableAutoBuildAfterTesting)
+ CoreUtility.setAutoBuilding(true);
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/PackageExplorerTests.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/PackageExplorerTests.java
index fd3a4de..cb30039 100644
--- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/PackageExplorerTests.java
+++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/PackageExplorerTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -24,6 +24,7 @@ public class PackageExplorerTests {
suite.addTest(ContentProviderTests3.suite());
suite.addTest(ContentProviderTests4.suite());
suite.addTest(ContentProviderTests5.suite());
+ suite.addTest(ContentProviderTests6.suite());
suite.addTest(PackageExplorerShowInTests.suite());
suite.addTestSuite(WorkingSetDropAdapterTest.class);
suite.addTest(HierarchicalContentProviderTests.suite());