//
// This file is part of the Prose Development Tools for Eclipse package.
//
// The contents of this file are subject to the Mozilla Public License
// Version 1.1 (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://www.mozilla.org/MPL/
//
// Software distributed under the License is distributed on an "AS IS" basis,
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
// for the specific language governing rights and limitations under the
// License.
//
// The Original Code is Prose Development Tools for Eclipse.
//
// The Initial Developer of the Original Code is Angela Nicoara. Portions
// created by Angela Nicoara are Copyright (C) 2006 Angela Nicoara.
// All Rights Reserved.
//
// Contributor(s):
// $Id: ProseRunListenerTest.java,v 1.1 2008/11/18 12:37:15 anicoara Exp $
// ==============================================================================
//
package ch.ethz.prose.eclipse.test;
import junit.framework.TestCase;
import ch.ethz.prose.eclipse.IProseRunListener;
import ch.ethz.prose.eclipse.ProseCore;
import ch.ethz.prose.eclipse.internal.core.ProsePlugin;
import ch.ethz.prose.eclipse.internal.run.AspectManagerNode;
import ch.ethz.prose.eclipse.internal.run.AspectNode;
import ch.ethz.prose.eclipse.internal.run.ProseRunNode;
import ch.ethz.prose.query.AspectSurrogate;
/**
* @author Angela Nicoara
* @author Johann Gyger
* @version $Id: ProseRunListenerTest.java,v 1.1 2008/11/18 12:37:15 anicoara Exp $
*/
public class ProseRunListenerTest extends TestCase {
protected ProseRunListener listener = new ProseRunListener();
protected void setUp() {
ProseCore.addRunListener(listener);
}
protected void tearDown() {
ProseCore.removeRunListener(listener);
}
/**
* Test if listeners are notified on <code>ProseRun</code> additions.
*/
public void testAddRunNotification() {
ProseRunNode run = new ProseRunNode("test", "dummyhost", -1, null);
ProsePlugin.getDefault().addRun(run);
assertEquals(run, listener.run);
}
/**
* Test if listeners are notified on <code>ProseRun</code> removals.
*/
public void testRemoveRunNotification() {
ProseRunNode run = new ProseRunNode("test", "dummyhost", -1, null);
ProsePlugin.getDefault().addRun(run);
ProsePlugin.getDefault().removeRun(run);
assertEquals(run, listener.run);
}
/**
* Test if listeners are notified when a <code>ProseRun</code> is set
* unreachable.
*/
public void testUnreachableRunNotification() {
ProseRunNode run = new ProseRunNode("test", "dummyhost", -1, null);
run.setUnreachable();
assertEquals(run, listener.run);
}
/**
* Test if listeners are notified when an <code>Aspect</code> has been
* inserted.
*/
public void testInsertAspectNotification() {
ProseRunNode run = new ProseRunNode("test", "dummyhost", -1, null);
AspectManagerNode aspectManager = new AspectManagerNode(run, true);
ProsePlugin.getDefault().fireAspectInserted(aspectManager);
assertEquals(aspectManager, listener.aspectManager);
}
/**
* Test if listeners are notified when an <code>Aspect</code> has been
* withdrawn.
*/
public void testWithdrawAspectNotification() {
ProseRunNode run = new ProseRunNode("test", "dummyhost", -1, null);
AspectManagerNode aspectManager = new AspectManagerNode(run, true);
AspectSurrogate surrogate = new AspectSurrogate("Aspect", null);
AspectNode aspect = new AspectNode(aspectManager, surrogate);
ProsePlugin.getDefault().fireAspectWithdrawn(aspect);
assertEquals(aspect, listener.aspect);
}
protected class ProseRunListener implements IProseRunListener {
protected ProseRunNode run;
protected AspectManagerNode aspectManager;
protected AspectNode aspect;
public void runAdded(ProseRunNode node) {
run = node;
}
public void runUnreachable(ProseRunNode node) {
run = node;
}
public void runRemoved(ProseRunNode node) {
run = node;
}
public void aspectInserted(AspectManagerNode node) {
aspectManager = node;
}
public void aspectWithdrawn(AspectNode node) {
aspect = node;
}
}
}