Skip to content

Commit

Permalink
Failure of Bug468PerformanceTest.test eclipse-platform#715
Browse files Browse the repository at this point in the history
Convert performance test to functional test case.

Fixes eclipse-platform#715
  • Loading branch information
lathapatil committed Dec 20, 2023
1 parent 7920ebd commit 12b0032
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 171 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
import org.junit.runners.Suite;

@RunWith(Suite.class)
@Suite.SuiteClasses({ PropertyManagerTest.class,
// Bug468PerformanceTest.class
})

@Suite.SuiteClasses({ PropertyManagerTest.class, Bug468FunctionalTest.class })
public class AllPropertiesTests {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*******************************************************************************
* Copyright (c) 2023 ETAS GmbH and others, all rights reserved.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* ETAS GmbH - initial API and implementation
*******************************************************************************/
package org.eclipse.core.tests.internal.properties;

import static org.junit.Assert.assertEquals;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import org.eclipse.core.internal.properties.PropertyManager2;
import org.eclipse.core.internal.resources.Workspace;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.ICoreRunnable;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.QualifiedName;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;

//Test case for GitHub Issue 468
@RunWith(JUnit4.class)
public class Bug468FunctionalTest {

private static final String TO_BE_DELETED_FILE_NAME_PREFIX = "file_";

private static final String TEMP_FOLDER_NAME = "temp";

private IProject project;

/*
* @throws Exception If anything goes wrong during the set up.
*/

@Before
public void setUp() throws Exception {
ResourcesPlugin.getWorkspace().run((ICoreRunnable) monitor -> {

createTestProject();
IFolder tempFolder = Bug468FunctionalTest.this.project.getFolder(TEMP_FOLDER_NAME);
tempFolder.create(true, true, new NullProgressMonitor());
createFile(tempFolder, TO_BE_DELETED_FILE_NAME_PREFIX + 0);

}, this.project, IWorkspace.AVOID_UPDATE, new NullProgressMonitor());
}

private void createTestProject() throws CoreException {
Bug468FunctionalTest.this.project = ResourcesPlugin.getWorkspace().getRoot()
.getProject("TestProject");
Bug468FunctionalTest.this.project.create(new NullProgressMonitor());
Bug468FunctionalTest.this.project.open(new NullProgressMonitor());
}
private IFile createFile(final IFolder parent, final String fileName) throws CoreException {
IFile file = parent.getFile(fileName);
InputStream source = new ByteArrayInputStream(file.getName().getBytes());
file.create(source, true, new NullProgressMonitor());
file.setPersistentProperty(new QualifiedName(this.getClass().getName(), file.getName()), file.getName());
return file;
}

/**
* Deletes the project
*
* @throws Exception
* if any exception happens during the deleting of the project.
*/
@After
public void tearDown() throws Exception {
this.project.delete(true, new NullProgressMonitor());
}

Workspace ws;
PropertyManager2 manager;
/**
* Whenever a delete operation is called on an IFile it's properties also
* deleted from .index file .This Test case validates for given IFile resource
* Zero depth is calculated to traverse through folders for loading right index
* file and delete its properties . because the required index file is present
* under corresponding bucket of the folder same as the IFile and no need to
* traverse to Infinite depth.
*/

@Captor
ArgumentCaptor<IResource> resourceArgCaptor;
@Captor
ArgumentCaptor<Integer> depthArgCapture;
@Test
public void test() throws CoreException {

MockitoAnnotations.openMocks(this);
ws = Mockito.spy(new Workspace());
manager = Mockito.spy(new PropertyManager2(ws));

IFolder tempFolder = this.project.getFolder(TEMP_FOLDER_NAME);
IFile fileToBeDeleted = tempFolder.getFile(TO_BE_DELETED_FILE_NAME_PREFIX + 0);

manager.deleteResource(fileToBeDeleted);

Mockito.verify(manager).deleteProperties(resourceArgCaptor.capture(), depthArgCapture.capture());
Integer expectedDepth = 0;
assertEquals(expectedDepth, depthArgCapture.getValue());

}
}

This file was deleted.

0 comments on commit 12b0032

Please sign in to comment.