diff --git a/com.incquerylabs.v4md/src/main/com/incquerylabs/v4md/internal/MagicDrawProjectNavigationHelper.java b/com.incquerylabs.v4md/src/main/com/incquerylabs/v4md/internal/MagicDrawProjectNavigationHelper.java index 4ded690..eb0eb68 100644 --- a/com.incquerylabs.v4md/src/main/com/incquerylabs/v4md/internal/MagicDrawProjectNavigationHelper.java +++ b/com.incquerylabs.v4md/src/main/com/incquerylabs/v4md/internal/MagicDrawProjectNavigationHelper.java @@ -26,10 +26,32 @@ */ public class MagicDrawProjectNavigationHelper extends NavigationHelperImpl { + /** + * TODO this logger wrapping is a very hacky solution, but until bug + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=549955 is fixed, it is not + * possible to overwrite the message any other way + */ + private static final class WrappedLogger extends Logger { + private WrappedLogger(Logger source) { + super(source.getName()); + parent = source; + repository = source.getLoggerRepository(); + } + + @Override + public void error(Object message) { + if (message instanceof String && ((String)message).contains("This indicates some errors in underlying model representation.")) { + super.debug(message); + } else { + super.error(message); + } + } + } + private Logger logger; public MagicDrawProjectNavigationHelper(Notifier emfRoot, BaseIndexOptions options, EventSupport eventSupport, Logger logger) { - super(emfRoot, options, logger); + super(emfRoot, options, new WrappedLogger(logger)); this.logger = logger; // TODO While this change helps avoiding some duplicate notifications, it causes // a regression when adding a new project usage to a local project: when the @@ -85,4 +107,6 @@ public void removeRoot(Notifier root) { } notifyBaseIndexChangeListeners(); } + + } \ No newline at end of file diff --git a/com.incquerylabs.v4md/src/test/com/incquerylabs/v4md/test/AllTests.java b/com.incquerylabs.v4md/src/test/com/incquerylabs/v4md/test/AllTests.java index 1df54c2..e59e41b 100644 --- a/com.incquerylabs.v4md/src/test/com/incquerylabs/v4md/test/AllTests.java +++ b/com.incquerylabs.v4md/src/test/com/incquerylabs/v4md/test/AllTests.java @@ -6,6 +6,7 @@ @RunWith(Suite.class) @SuiteClasses({ - QueryTests.class + //QueryTests.class, + ModelUpdateTests.class }) public class AllTests {} diff --git a/com.incquerylabs.v4md/src/test/com/incquerylabs/v4md/test/ModelUpdateTests.java b/com.incquerylabs.v4md/src/test/com/incquerylabs/v4md/test/ModelUpdateTests.java new file mode 100644 index 0000000..0efe10f --- /dev/null +++ b/com.incquerylabs.v4md/src/test/com/incquerylabs/v4md/test/ModelUpdateTests.java @@ -0,0 +1,65 @@ +package com.incquerylabs.v4md.test; + +import java.io.File; + +import org.apache.log4j.Appender; +import org.apache.log4j.Level; +import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; +import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; +import org.eclipse.viatra.query.testing.core.TestingSeverityAggregatorLogAppender; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; + +import com.incquerylabs.v4md.ViatraQueryAdapter; +import com.incquerylabs.v4md.test.queries.PortConnections; +import com.incquerylabs.v4md.test.queries.PortConnections.Matcher; +import com.nomagic.magicdraw.core.Project; +import com.nomagic.magicdraw.openapi.uml.SessionManager; +import com.nomagic.magicdraw.tests.MagicDrawTestCase; +import com.nomagic.magicdraw.tests.common.TestEnvironment; +import com.nomagic.uml2.ext.magicdraw.compositestructures.mdinternalstructures.Connector; + +public class ModelUpdateTests extends MagicDrawTestCase { + + protected Project project; + protected static String projectToUse = "ConnectorRemoveTest.mdzip"; + + @Before + protected void setUpTest() throws Exception + { + project = loadProject(new File(TestEnvironment.getResourceDir(), projectToUse).getAbsolutePath()); + setSkipMemoryTest(true); + super.setUpTest(); + } + + @After + protected void tearDownTest() throws Exception { + closeAllProjects(); + super.tearDownTest(); + } + + public void testListener() { + ViatraQueryAdapter adapter = ViatraQueryAdapter.getOrCreateAdapter(project); + Appender appender = ViatraQueryLoggingUtil.getLogger(ViatraQueryEngine.class).getAppender(this.getClass().getName()); + TestingSeverityAggregatorLogAppender testAppender; + if (appender instanceof TestingSeverityAggregatorLogAppender) { + testAppender = (TestingSeverityAggregatorLogAppender) appender; + testAppender.clear(); + } else { + testAppender = new TestingSeverityAggregatorLogAppender(); + testAppender.setName(this.getClass().getName()); + ViatraQueryLoggingUtil.getLogger(ViatraQueryEngine.class).addAppender(testAppender); + } + + Matcher matcher = PortConnections.Matcher.on(adapter.getEngine()); + + matcher.countMatches(); + + final Connector connector = (Connector) project.getElementByID("_19_0_1_c0402f4_1551707958244_224488_42396"); + SessionManager.getInstance().executeInsideSession(project, "Modification", connector::dispose); + + Assert.assertTrue(testAppender.getSeverity().toInt() < Level.ERROR_INT); + } + +} diff --git a/com.incquerylabs.v4md/src/test/data/ConnectorRemoveTest.mdzip b/com.incquerylabs.v4md/src/test/data/ConnectorRemoveTest.mdzip new file mode 100644 index 0000000..94ebb56 Binary files /dev/null and b/com.incquerylabs.v4md/src/test/data/ConnectorRemoveTest.mdzip differ