// Copyright (C) 2003-2009 by Object Mentor, Inc. All rights reserved.
// Released under the terms of the CPL Common Public License version 1.0.
package fitnesse.slim;

import java.io.IOException;

import org.junit.Test;

import static org.junit.Assert.*;

public class SlimServiceTest extends SlimServiceTestBase {

  @Override
  protected String getImport() {
    return "fitnesse.slim.test";
  }

  @Override
  protected void startSlimService() throws IOException {
    SlimService.Options options = SlimService.parseCommandLine(new String[]{"8099"});
    startWithFactoryAsync(JavaSlimFactory.createJavaSlimFactory(options), options);
  }

  @Override
  protected void closeSlimService() throws InterruptedException {
    waitForServiceToStopAsync();
    assertFalse(service.isAlive());
  }

  @Override
  protected String expectedExceptionMessage() {
    return "java.lang.Exception: This is my exception";
  }

  @Override
  protected String expectedStopTestExceptionMessage() {
    return "ABORT_SLIM_TEST:fitnesse.slim.test.TestSlim$StopTestException: This is a stop test exception";
  }

  @Test
  public void nullInteractionService_returnsDefaultClass() {
    SlimService.Options options = SlimService.parseCommandLine(new String[]{"8099"});
    assertEquals("fitnesse.slim.fixtureInteraction.DefaultInteraction", options.interaction.getClass().getName());
  }

  @Test
  public void definedInteractionService_returnsCorrectClass() {
    SlimService.Options options = SlimService.parseCommandLine(new String[]{"-i", "fitnesse.slim.fixtureInteraction.InteractionDemo", "8099"});
    assertEquals("fitnesse.slim.fixtureInteraction.InteractionDemo", options.interaction.getClass().getName());
  }

  @Test
  public void undefinedStatementTimeout() {
    SlimService.Options options = SlimService.parseCommandLine(new String[]{"8099"});
    assertNull(options.statementTimeout);
  }

  @Test
  public void definedStatementTimeout_returnsTimeout() {
    SlimService.Options options = SlimService.parseCommandLine(new String[]{"-s", "1000", "8099"});
    assertEquals(1000, (int) options.statementTimeout);
  }
}

@@ -191,16 +191,73 @@
 ption;%0A%0A
+import fitnesse.slim.fixtureInteraction.InteractionDemo;%0A
 import o
@@ -1208,32 +1208,130 @@
 efaultClass() %7B%0A
+    String defaultInteractionName = JavaSlimFactory.createInteraction(null).getClass().getName();%0A
     SlimService.
@@ -1421,43 +1421,9 @@
 als(
-%22fitnesse.slim.fixtureInteraction.D
+d
 efau
@@ -1435,17 +1435,20 @@
 eraction
-%22
+Name
 , option
@@ -1557,24 +1557,91 @@
 ctClass() %7B%0A
+    String interactionClassName = InteractionDemo.class.getName();%0A
     SlimServ
@@ -1714,137 +1714,77 @@
 i%22, 
-%22fitnesse.slim.fixtureInteraction.InteractionDemo%22, %228099%22%7D);%0A    assertEquals(%22fitnesse.slim.fixtureInteraction.InteractionDemo%22
+interactionClassName, %228099%22%7D);%0A    assertEquals(interactionClassName
 , op

Make test more robust