diff options
author | Christian W. Damus | 2014-03-11 20:54:40 +0000 |
---|---|---|
committer | Christian W. Damus | 2014-03-11 20:54:40 +0000 |
commit | 6c21353faf0dbb249e8c42d0ef3a6c23ff1120ef (patch) | |
tree | 35b3b0404025103c63f1aa4d197cefa53b03c139 /tests/junit | |
parent | 1b5e1fc50200467c3a1bc3dd6614c78a1df293cf (diff) | |
download | org.eclipse.papyrus-6c21353faf0dbb249e8c42d0ef3a6c23ff1120ef.tar.gz org.eclipse.papyrus-6c21353faf0dbb249e8c42d0ef3a6c23ff1120ef.tar.xz org.eclipse.papyrus-6c21353faf0dbb249e8c42d0ef3a6c23ff1120ef.zip |
429826: [Read-Only] Orthogonal Classification of Read-Only Concerns
https://bugs.eclipse.org/bugs/show_bug.cgi?id=429826
Add affinity with specified read-only axes to the extension metadata for read-only handlers and use this to partition the queries for read-only state by axis in the ReadOnlyManager.
A new JUnit test demonstrates that this fixes the problem of read-only *.sash/*.di resources being mistaken as writable because of the SashModelReadOnlyHandler. Because this handler depends on the ModelSet, the JUnit test fixture is updated to use a ModelSet instead of a simple ResourceSet.
The FSReadOnlyHandler is updated to report read-only state of file: scheme URIs and the EMFReadOnlyHandler accepts these URIs in addition to platform:/resource URIs.
Diffstat (limited to 'tests/junit')
2 files changed, 90 insertions, 2 deletions
diff --git a/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/src/org/eclipse/papyrus/infra/emf/readonly/ReadOnlyManagerTest.java b/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/src/org/eclipse/papyrus/infra/emf/readonly/ReadOnlyManagerTest.java index 82157b058fd..584282cb6a8 100644 --- a/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/src/org/eclipse/papyrus/infra/emf/readonly/ReadOnlyManagerTest.java +++ b/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/src/org/eclipse/papyrus/infra/emf/readonly/ReadOnlyManagerTest.java @@ -17,7 +17,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import org.eclipse.emf.common.util.URI; import org.eclipse.papyrus.infra.core.resource.ReadOnlyAxis; -import org.eclipse.papyrus.infra.emf.readonly.tests.PapyrusROEditingDomainFixture; +import org.eclipse.papyrus.infra.emf.readonly.tests.PapyrusModelSetFixture; import org.eclipse.papyrus.junit.utils.rules.JavaResource; import org.eclipse.papyrus.junit.utils.rules.ProjectFixture; import org.junit.After; @@ -33,7 +33,7 @@ import org.junit.Test; public class ReadOnlyManagerTest { @Rule - public final PapyrusROEditingDomainFixture domain = new PapyrusROEditingDomainFixture(); + public final PapyrusModelSetFixture domain = new PapyrusModelSetFixture(); private final ProjectFixture project = domain.getProject(); @@ -69,6 +69,12 @@ public class ReadOnlyManagerTest { assertThat(fixture.canMakeWritable(ReadOnlyAxis.anyAxis(), new URI[]{ uri }).or(false), is(true)); } + @Test + public void testSashModelReadOnlyIfPermissionReadOnly() { + URI sashModelURI = URI.createPlatformPluginURI("org.eclipse.papyrus.foo/models/bogus.di", true); + assertThat(fixture.anyReadOnly(ReadOnlyAxis.anyAxis(), new URI[]{ sashModelURI }).or(false), is(true)); + } + // // Test framework // diff --git a/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/src/org/eclipse/papyrus/infra/emf/readonly/tests/PapyrusModelSetFixture.java b/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/src/org/eclipse/papyrus/infra/emf/readonly/tests/PapyrusModelSetFixture.java new file mode 100644 index 00000000000..6f96df8d47e --- /dev/null +++ b/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/src/org/eclipse/papyrus/infra/emf/readonly/tests/PapyrusModelSetFixture.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2014 CEA 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: + * Christian W. Damus (CEA) - Initial API and implementation + * + */ +package org.eclipse.papyrus.infra.emf.readonly.tests; + +import static org.junit.Assert.fail; + +import java.util.Collections; + +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.papyrus.infra.core.resource.EditingDomainServiceFactory; +import org.eclipse.papyrus.infra.core.resource.ModelSet; +import org.eclipse.papyrus.infra.core.services.ServiceDescriptor; +import org.eclipse.papyrus.infra.core.services.ServiceDescriptor.ServiceTypeKind; +import org.eclipse.papyrus.infra.core.services.ServiceStartKind; +import org.eclipse.papyrus.infra.core.services.ServicesRegistry; +import org.eclipse.papyrus.infra.emf.readonly.PapyrusROTransactionalEditingDomain; +import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResourceInitializerService; +import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResourceSet; +import org.eclipse.papyrus.junit.utils.rules.AbstractModelFixture; +import org.junit.runner.Description; + + +/** + * This is the PapyrusModelSetFixture type. Enjoy. + */ +public class PapyrusModelSetFixture extends AbstractModelFixture<PapyrusROTransactionalEditingDomain> { + + public PapyrusModelSetFixture() { + super(); + } + + protected PapyrusROTransactionalEditingDomain createEditingDomain() { + try { + ServicesRegistry services = createServiceRegistry(); + return (PapyrusROTransactionalEditingDomain)services.getService(ModelSet.class).getTransactionalEditingDomain(); + } catch (Exception e) { + e.printStackTrace(); + fail("Failed to initialize service registry and/or editing domain: " + e.getLocalizedMessage()); + return null; // unreachable + } + } + + @Override + protected void finished(Description description) { + ResourceSet rset = getEditingDomain().getResourceSet(); + + try { + ServicesRegistry services = ServiceUtilsForResourceSet.getInstance().getServiceRegistry(rset); + services.disposeRegistry(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + super.finished(description); + } + } + + protected ServicesRegistry createServiceRegistry() throws Exception { + ServicesRegistry result = new ServicesRegistry(); + result.add(ModelSet.class, 10, new ModelSet()); + result.add(ServiceUtilsForResourceInitializerService.class, 10, new ServiceUtilsForResourceInitializerService()); + + ServiceDescriptor desc = new ServiceDescriptor(TransactionalEditingDomain.class, EditingDomainServiceFactory.class.getName(), ServiceStartKind.STARTUP, 10, Collections.singletonList(ModelSet.class.getName())); + desc.setServiceTypeKind(ServiceTypeKind.serviceFactory); + desc.setClassBundleID(org.eclipse.papyrus.infra.core.Activator.PLUGIN_ID); + result.add(desc); + + result.startRegistry(); + + return result; + } +} |