Search in sources :

Example 1 with URIBasedTestResourceDescription

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;
}
Also used : URIBasedTestResourceDescription(org.eclipse.xtext.junit4.util.URIBasedTestResourceDescription) IFile(org.eclipse.core.resources.IFile) URI(org.eclipse.emf.common.util.URI)

Example 2 with URIBasedTestResourceDescription

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));
}
Also used : URIBasedTestResourceDescription(org.eclipse.xtext.junit4.util.URIBasedTestResourceDescription) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) IContainer(org.eclipse.xtext.resource.IContainer) Test(org.junit.Test)

Example 3 with URIBasedTestResourceDescription

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);
    }
}
Also used : IDirtyResource(org.eclipse.xtext.ui.editor.IDirtyResource) URIBasedTestResourceDescription(org.eclipse.xtext.junit4.util.URIBasedTestResourceDescription) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) IDirtyResource(org.eclipse.xtext.ui.editor.IDirtyResource) XtextResource(org.eclipse.xtext.resource.XtextResource) ByteArrayOutputStream(java.io.ByteArrayOutputStream) URI(org.eclipse.emf.common.util.URI)

Example 4 with URIBasedTestResourceDescription

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));
}
Also used : URIBasedTestResourceDescription(org.eclipse.xtext.junit4.util.URIBasedTestResourceDescription) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) IContainer(org.eclipse.xtext.resource.IContainer) Test(org.junit.Test)

Example 5 with URIBasedTestResourceDescription

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));
}
Also used : URIBasedTestResourceDescription(org.eclipse.xtext.junit4.util.URIBasedTestResourceDescription) IFile(org.eclipse.core.resources.IFile) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) IContainer(org.eclipse.xtext.resource.IContainer) URI(org.eclipse.emf.common.util.URI) Test(org.junit.Test)

Aggregations

URIBasedTestResourceDescription (org.eclipse.xtext.junit4.util.URIBasedTestResourceDescription)6 URI (org.eclipse.emf.common.util.URI)4 IContainer (org.eclipse.xtext.resource.IContainer)4 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)4 Test (org.junit.Test)4 IFile (org.eclipse.core.resources.IFile)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 IDirtyResource (org.eclipse.xtext.ui.editor.IDirtyResource)1