package perftest.server

import org.specs.Specification
import org.specs.mock.Mockito
import ccf.transport.Request


class ServerEngineSpec extends Specification with Mockito  {
  "ServerEngine" should {
    class TestServerEngine extends ServerEngine {
      override def fatalError(msg: String) {}
    }

    val engine = spy(new TestServerEngine)

    "decode None as an error" in {
      engine.decodeRequest(None)
      there was one(engine).fatalError("Unable to decode request")
    }

    "decode request header type" in {
      val request = mock[Request]

      "None as an error" in {
        request.header("type") returns None
        engine.decodeRequest(Some(request))
        there was one(engine).fatalError("No request type given")
      }

      "Unknown request type as an error" in {
        val requestType: String = "Unknown"
        request.header("type") returns Some(requestType)
        engine.decodeRequest(Some(request))
        there was one(engine).fatalError("Unknown request type: " + requestType)
      }
    }
  }
}

package perftest.server

import org.specs.Specification
import org.specs.mock.{Mockito, MockitoMatchers}
import ccf.transport.Request
import ccf.session.AbstractRequest


class ServerEngineSpec extends Specification with Mockito with MockitoMatchers  {
  "ServerEngine" should {
    class TestServerEngine extends ServerEngine {
      override def fatalError(msg: String) {}
    }

    val engine = spy(new TestServerEngine)

    "decode None as an error" in {
      engine.decodeRequest(None)
      there was one(engine).fatalError("Unable to decode request")
    }

    "decode request header type" in {
      val request = mock[Request]

      "None as an error" in {
        request.header("type") returns None
        engine.decodeRequest(Some(request))
        there was one(engine).fatalError("No request type given")
      }

      "Unknown request type as an error" in {
        val requestType: String = "Unknown"
        request.header("type") returns Some(requestType)
        engine.decodeRequest(Some(request))
        there was one(engine).fatalError("Unknown request type: " + requestType)
      }

      "AbstractRequest.joinRequestType successfully" in {
        request.header("type") returns Some(AbstractRequest.joinRequestType)
        engine.decodeRequest(Some(request))
        there was no(engine).fatalError(any[String])
      }

      "AbstractRequest.partRequestType successfully" in {
        request.header("type") returns Some(AbstractRequest.partRequestType)
        engine.decodeRequest(Some(request))
        there was no(engine).fatalError(any[String])
      }
    }
  }
}

Add tests for unimplemented request types
perftest: Add tests for unimplemented request types

Signed-off-by: Sami Rosendahl <b33c757bb777642ab0d59c699f8d5782929a814f@reaktor.fi>
Signed-off-by: Timo Mali <93a63fc11b7fc4c8615b3718bbdb07aef12d7334@reaktor.fi>
