GlobalNamesArchitecture / gnparser

Split scientific names to meaningful elements with meta information
https://parser.globalnames.org/
MIT License
20 stars 2 forks source link

Extend test coverage #381

Closed alexander-myltsev closed 6 years ago

alexander-myltsev commented 7 years ago

Currently GnParser is tightly coupled to main method args. We need to extract runners (web, tcp, file) to test each of them.

alexander-myltsev commented 7 years ago

Starting point to test TcpServer:

package org.globalnames
package parser
package runner
package tcp

import akka.actor.ActorSystem
import akka.stream._
import akka.stream.scaladsl._
import akka.util._
import GnParser.Config
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}

class TcpServerSpec extends WordSpecLike with Matchers with BeforeAndAfterAll with ScalaFutures {

  "An Echo actor" must {

    "send back messages unchanged" in {
      val address = "127.0.0.1"
      val port = 4356

      val config = Config(simpleFormat = true, host = address, port = port)
      TcpServer.run(config)

      implicit val client: ActorSystem = ActorSystem("SimpleTcpClient")
      implicit val materializer: ActorMaterializer = ActorMaterializer()

      val connection = Tcp().outgoingConnection(address, port)

      val flow = Flow[ByteString]
        .via(Framing.delimiter(ByteString("\n"), maximumFrameLength = 256, allowTruncation = true))
        .map(_.utf8String)
        .map(println)
        .map(_ => "STOP")
        .map(_+"\n")
        .map(ByteString(_))

      whenReady(connection.join(flow).run()) { r =>
        println(r)
      }
    }
  }
}