/**
 * Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies
 * 
 * Please see distribution for license.
 */
package com.opengamma.engine.view.calcnode;

import static org.testng.AssertJUnit.assertNull;
import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.assertTrue;
import org.testng.annotations.Test;
import com.opengamma.engine.test.TestCalculationNode;
import com.opengamma.util.test.Timeout;

/**
 * Tests the LocalNodeJobInvoker class
 */
@Test
public class LocalNodeJobInvokerTest implements JobInvokerRegister {

  private static final long TIMEOUT = Timeout.standardTimeoutMillis ();

  private JobInvoker _invoker;

  public void addNodeWithCallbackPending() {
    final LocalNodeJobInvoker invoker = new LocalNodeJobInvoker();
    _invoker = null;
    assertFalse (invoker.notifyWhenAvailable(this));
    assertNull(_invoker);
    invoker.addNode(new TestCalculationNode());
    assertEquals(invoker, _invoker);
  }

  public void addCallbackWithNodePending() {
    final LocalNodeJobInvoker invoker = new LocalNodeJobInvoker();
    _invoker = null;
    invoker.addNode(new TestCalculationNode());
    assertTrue (invoker.notifyWhenAvailable(this));
    assertNull(_invoker);
  }

  @Override
  public void registerJobInvoker(final JobInvoker invoker) {
    _invoker = invoker;
  }

  public void invokeWithNoNodes() {
    final LocalNodeJobInvoker invoker = new LocalNodeJobInvoker();
    final TestJobInvocationReceiver receiver = new TestJobInvocationReceiver();
    assertFalse(invoker.invoke(JobDispatcherTest.createTestJob(), receiver));
    assertNull(receiver.getCompletionResult());
  }

  public void invokeWithOneNode() {
    final LocalNodeJobInvoker invoker = new LocalNodeJobInvoker(new TestCalculationNode());
    final TestJobInvocationReceiver receiver = new TestJobInvocationReceiver();
    final CalculationJob job = JobDispatcherTest.createTestJob();
    assertTrue(invoker.invoke(job, receiver));
    final CalculationJobResult jobResult = receiver.waitForCompletionResult(TIMEOUT);
    assertNotNull(jobResult);
    assertEquals(job.getSpecification(), jobResult.getSpecification());
  }

}

@@ -427,16 +427,61 @@
 ertTrue;
+%0A%0Aimport org.testng.annotations.BeforeMethod;
 %0Aimport 
@@ -698,38 +698,8 @@
 est 
-implements JobInvokerRegister 
 %7B%0A%0A 
@@ -764,17 +764,16 @@
 utMillis
- 
 ();%0A%0A  p
@@ -800,32 +800,164 @@
 nvoker;%0A
-%0A  public void a
+  private Register _register;%0A%0A  @BeforeMethod%0A  public void setUp() %7B%0A    _invoker = null;%0A    _register = new Register();%0A  %7D%0A%0A  public void testA
 ddNodeWi
@@ -1081,17 +1081,16 @@
 ertFalse
- 
 (invoker
@@ -1102,36 +1102,41 @@
 fyWhenAvailable(
-this
+_register
 ));%0A    assertNu
@@ -1253,17 +1253,21 @@
 ic void 
-a
+testA
 ddCallba
@@ -1438,17 +1438,16 @@
 sertTrue
- 
 (invoker
@@ -1471,12 +1471,17 @@
 ble(
-this
+_register
 ));%0A
@@ -1517,123 +1517,25 @@
 %0A%0A  
-@Override%0A  public void registerJobInvoker(final JobInvoker invoker) %7B%0A    _invoker = invoker;%0A  %7D%0A%0A  public void i
+public void testI
 nvok
@@ -1843,17 +1843,21 @@
 ic void 
-i
+testI
 nvokeWit
@@ -2347,10 +2347,172 @@
 );%0A  %7D%0A%0A
+  class Register implements JobInvokerRegister %7B%0A    @Override%0A    public void registerJobInvoker(final JobInvoker invoker) %7B%0A      _invoker = invoker;%0A    %7D%0A  %7D%0A
 %7D%0A

Move to TestNG, fix test