Skip to content

Commit

Permalink
JBIDE-18690 - ResourceException while deleting project
Browse files Browse the repository at this point in the history
  • Loading branch information
xcoulon committed Jan 6, 2015
1 parent fc5119d commit 89789d9
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
Expand Up @@ -110,6 +110,10 @@ public static JaxrsMetamodel get(final IJavaProject javaProject, final boolean f
}

final IProject project = javaProject.getProject();
if(!project.isAccessible()) {
Logger.debug("Returning a null metamodel because the underlying project does not exist or is not opened.");
return null;
}
final JaxrsMetamodel metamodel = (JaxrsMetamodel) project.getSessionProperty(
JaxrsMetamodel.METAMODEL_QUALIFIED_NAME);
if (metamodel == null && force) {
Expand Down
Expand Up @@ -111,6 +111,10 @@ public final IJavaProject getJavaProject() {
return javaProject;
}

/**
* Returns {@code true} if the {@link IJaxrsMetamodel} associated with the {@link IJavaProject} given in the constructor has {@link IJaxrsElement}. Returns {@code false} otherwise (or if there is no {@link IJaxrsMetamodel} for the current {@link IJavaProject}).
* @param element not used (mandatory to implement the {@link ITreeContentProvider#hasChildren(Object)} method.
*/
@Override
public boolean hasChildren(Object element) {
try {
Expand All @@ -123,7 +127,7 @@ public boolean hasChildren(Object element) {
} catch (CoreException e) {
Logger.error("Failed to retrieve JAX-RS Metamodel in project '" + javaProject.getElementName() + "'", e);
}
return true;
return false;
}

/**
Expand Down
@@ -0,0 +1,69 @@
/**
*
*/
package org.jboss.tools.ws.jaxrs.ui.cnf;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IJavaProject;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsMetamodel;
import org.jboss.tools.ws.jaxrs.core.junitrules.JaxrsMetamodelMonitor;
import org.jboss.tools.ws.jaxrs.core.junitrules.WorkspaceSetupRule;
import org.junit.Assert;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;

import static org.hamcrest.Matchers.equalTo;

/**
* @author xcoulon
*
*/
public class UriMappingsContentProviderTestCase {

@ClassRule
public static WorkspaceSetupRule workspaceSetupRule = new WorkspaceSetupRule("org.jboss.tools.ws.jaxrs.tests.sampleproject");

@Rule
public JaxrsMetamodelMonitor metamodelMonitor = new JaxrsMetamodelMonitor("org.jboss.tools.ws.jaxrs.tests.sampleproject", true);

private JaxrsMetamodel metamodel = null;

private IProject project = null;

private IJavaProject javaProject = null;

@Before
public void setup() throws CoreException {
this.metamodel = metamodelMonitor.getMetamodel();
this.project = metamodel.getProject();
this.javaProject = metamodel.getJavaProject();
}

@Test
// @see https://issues.jboss.org/browse/JBIDE-18690
public void shouldReturnTrueWhenProjectExists() {
// given
final UriMappingsContentProvider uriMappingsContentProvider = new UriMappingsContentProvider();
final UriPathTemplateCategory uriPathTemplateCategory = new UriPathTemplateCategory(uriMappingsContentProvider, javaProject);
// when
boolean hasChildren = uriMappingsContentProvider.hasChildren(uriPathTemplateCategory);
// then
Assert.assertThat(hasChildren, equalTo(true));
}

@Test
// @see https://issues.jboss.org/browse/JBIDE-18690
public void shouldNotFailWhenProjectIsDeleted() throws CoreException {
// given
final UriMappingsContentProvider uriMappingsContentProvider = new UriMappingsContentProvider();
final UriPathTemplateCategory uriPathTemplateCategory = new UriPathTemplateCategory(uriMappingsContentProvider, javaProject);
// when
project.delete(true, null);
boolean hasChildren = uriMappingsContentProvider.hasChildren(uriPathTemplateCategory);
// then
Assert.assertThat(hasChildren, equalTo(false));
}
}

0 comments on commit 89789d9

Please sign in to comment.