use of org.eclipse.xtext.junit4.util.URIBasedTestResourceDescription in project xtext-eclipse by eclipse.
the class AbstractContainerRelatedTests method createFileAndRegisterResource.
protected URI createFileAndRegisterResource(IProject project, String name) throws CoreException, InvocationTargetException, InterruptedException {
IFile file = createFile(project.getFullPath().append(name + ".name"), name + "Content");
URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
uriToResourceDescription.put(uri, new URIBasedTestResourceDescription(uri));
return uri;
}
use of org.eclipse.xtext.junit4.util.URIBasedTestResourceDescription in project xtext-eclipse by eclipse.
the class StateBasedContainerManagerTest method testGetVisibleContainers_01.
@Test
public void testGetVisibleContainers_01() {
IResourceDescription description = new URIBasedTestResourceDescription(uri1);
List<IContainer> visibleContainers = containerManager.getVisibleContainers(description, this);
assertEquals(2, visibleContainers.size());
assertEquals(2, Iterables.size(visibleContainers.get(0).getResourceDescriptions()));
assertEquals(1, Iterables.size(visibleContainers.get(1).getResourceDescriptions()));
assertNotNull(visibleContainers.get(0).getResourceDescription(uri1));
assertNotNull(visibleContainers.get(0).getResourceDescription(uri2));
assertNotNull(visibleContainers.get(1).getResourceDescription(uri3));
}
use of org.eclipse.xtext.junit4.util.URIBasedTestResourceDescription in project xtext-eclipse by eclipse.
the class AbstractScopeResourceDescriptionsTest method assertDirtyState.
protected void assertDirtyState(boolean enabled) throws IOException {
String dirtyResourceName = "test/test." + fileExt.getPrimaryFileExtension();
final URI dirtyResourceURI = URI.createPlatformResourceURI(dirtyResourceName, true);
final String testModel = "stuff foo stuff bar refs foo";
IDirtyResource mockDirtyResource = new IDirtyResource() {
@Override
public String getActualContents() {
return testModel;
}
@Override
public String getContents() {
return testModel;
}
@Override
public IResourceDescription getDescription() {
return new URIBasedTestResourceDescription(dirtyResourceURI);
}
@Override
public URI getURI() {
return dirtyResourceURI;
}
};
try {
assertTrue(dirtyStateManager.manageDirtyState(mockDirtyResource));
Resource dirtyResource = resourceSet.getResource(dirtyResourceURI, true);
assertTrue(dirtyResource instanceof XtextResource);
assertTrue(dirtyResource.isLoaded());
assertFalse(dirtyResource.getContents().isEmpty());
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
dirtyResource.save(byteArrayOutputStream, null);
assertEquals(testModel, new String(byteArrayOutputStream.toByteArray()));
assertTrue(enabled);
} catch (Throwable t) {
assertFalse(enabled);
boolean isResourceException = false;
for (Throwable tx : Throwables.getCausalChain(t)) {
if (tx instanceof org.eclipse.core.internal.resources.ResourceException) {
isResourceException = true;
break;
}
}
if (!isResourceException)
Exceptions.throwUncheckedException(t);
} finally {
dirtyStateManager.discardDirtyState(mockDirtyResource);
}
}
use of org.eclipse.xtext.junit4.util.URIBasedTestResourceDescription in project xtext-eclipse by eclipse.
the class StateBasedContainerManagerTest method testGetContainer_01.
@Test
public void testGetContainer_01() {
IResourceDescription description = new URIBasedTestResourceDescription(uri1);
IContainer container = containerManager.getContainer(description, this);
assertEquals(2, Iterables.size(container.getResourceDescriptions()));
assertNotNull(container.getResourceDescription(uri1));
assertNotNull(container.getResourceDescription(uri2));
assertNull(container.getResourceDescription(uri3));
}
use of org.eclipse.xtext.junit4.util.URIBasedTestResourceDescription in project xtext-eclipse by eclipse.
the class StateBasedContainerManagerTest method testGetContainer_02.
@Test
public void testGetContainer_02() {
IFile file = getFile(project1, "doesNotExist");
URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
IResourceDescription description = new URIBasedTestResourceDescription(uri);
IContainer container = containerManager.getContainer(description, this);
assertEquals(3, Iterables.size(container.getResourceDescriptions()));
assertNotNull(container.getResourceDescription(uri));
assertNotNull(container.getResourceDescription(uri1));
assertNotNull(container.getResourceDescription(uri2));
assertNull(container.getResourceDescription(uri3));
}
Aggregations