Skip to content

Commit

Permalink
Merge pull request #33 from /issues/26
Browse files Browse the repository at this point in the history
Suppresses notification logging #26
  • Loading branch information
ujhelyiz authored Aug 14, 2019
2 parents 3ecb84f + 1053d07 commit 7a27ba1
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -85,4 +107,6 @@ public void removeRoot(Notifier root) {
}
notifyBaseIndexChangeListeners();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

@RunWith(Suite.class)
@SuiteClasses({
QueryTests.class
//QueryTests.class,
ModelUpdateTests.class
})
public class AllTests {}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Binary file not shown.

0 comments on commit 7a27ba1

Please sign in to comment.