<commit_before>package com.stratio.connectors

import java.util

import com.stratio.meta.common.connector.{IConnector, IQueryEngine}
import com.stratio.meta.common.logicalplan.{LogicalStep, LogicalWorkflow}
import com.stratio.meta2.common.data.{CatalogName, TableName}
import com.stratio.meta2.core.query._
import com.stratio.meta2.core.statements.SelectStatement
import com.typesafe.config.ConfigFactory
import org.apache.log4j.Logger
import org.scalamock.scalatest.MockFactory
import org.scalatest.{FunSuite, Suite}
//import com.stratio.meta.server.config.{ServerConfig, ActorReceiveUtils}


//class ConnectorTest extends FunSuite with MockFactory with ServerConfig{
class ConnectorActorTest extends FunSuite with MockFactory {
   this:Suite =>


  lazy val logger =Logger.getLogger(classOf[ConnectorActorTest])

  test("Basic Connector Mock") {
    val m = mock[IConnector]
    (m.getConnectorName _).expects().returning("My New Connector")
    assert(m.getConnectorName().equals("My New Connector"))
  }

  test("Basic Connector App listening on a given port does not break") {
    val port = "2558"
    val m = mock[IConnector]
    (m.getConnectorName _).expects().returning("My New Connector")
    val config = ConfigFactory.parseString("akka.remote.netty.tcp.port=" + port).withFallback(ConfigFactory.load())
    val c = new ConnectorApp()
    //val myReference = c.startup(m, port, config)
    val myReference = c.startup(m, port)
    myReference ! "Hello World"
    assert("Hello World" == "Hello World")
    c.shutdown()
  }

  test("Send SelectInProgressQuery to Connector") {
    val port = "2559"
    val m = mock[IConnector]
    val qe = mock[IQueryEngine]
    //(qe.execute _).expects().returning(new QueryResult())
    (m.getConnectorName _).expects().returning("My New Connector")
    (m.getQueryEngine _).expects().returning(qe)

    val config = ConfigFactory.parseString("akka.remote.netty.tcp.port=" + port).withFallback(ConfigFactory.load())
    val c = new ConnectorApp()
    //val myReference = c.startup(m, port, config)
    val myReference = c.startup(m, port)
    var steps: util.ArrayList[LogicalStep] = new util.ArrayList[LogicalStep]()
    val pq = new SelectPlannedQuery(
        new SelectValidatedQuery(
            new SelectParsedQuery(
              new BaseQuery("query_id-2384234-1341234-23434", "select * from myQuery;", new CatalogName("myCatalog") )
              ,new SelectStatement(new TableName("myCatalog","myTable"))
          )
        ), new LogicalWorkflow(steps)
    )
    val selectQ: SelectInProgressQuery = new SelectInProgressQuery(pq)
    /*
    val beanMap: util.Map[String, String] = BeanUtils.recursiveDescribe(selectQ);
    for (s <- beanMap.keySet().toArray()) {
      println(s);
    }
    */
    myReference ! selectQ
    c.shutdown()
  }

  /*
  test("Send MetadataInProgressQuery to Connector") {<commit_msg>more mocks in test<commit_after>package com.stratio.connectors

import java.util

import com.stratio.meta.common.connector.{IConnector, IQueryEngine}
import com.stratio.meta.common.logicalplan.{LogicalStep, LogicalWorkflow}
import com.stratio.meta2.common.data.{CatalogName, TableName}
import com.stratio.meta2.core.query._
import com.stratio.meta2.core.statements.SelectStatement
import com.typesafe.config.ConfigFactory
import org.apache.log4j.Logger
import org.scalamock.scalatest.MockFactory
import org.scalatest.{FunSuite, Suite}
//import com.stratio.meta.server.config.{ServerConfig, ActorReceiveUtils}


//class ConnectorTest extends FunSuite with MockFactory with ServerConfig{
class ConnectorActorTest extends FunSuite with MockFactory {
   this:Suite =>


  lazy val logger =Logger.getLogger(classOf[ConnectorActorTest])

  test("Basic Connector Mock") {
    val m = mock[IConnector]
    (m.getConnectorName _).expects().returning("My New Connector")
    assert(m.getConnectorName().equals("My New Connector"))
  }

  test("Basic Connector App listening on a given port does not break") {
    val port = "2558"
    val m = mock[IConnector]
    (m.getConnectorName _).expects().returning("My New Connector")
    val config = ConfigFactory.parseString("akka.remote.netty.tcp.port=" + port).withFallback(ConfigFactory.load())
    val c = new ConnectorApp()
    //val myReference = c.startup(m, port, config)
    val myReference = c.startup(m, port)
    myReference ! "Hello World"
    assert("Hello World" == "Hello World")
    c.shutdown()
  }

  test("Send SelectInProgressQuery to Connector") {
    val port = "2559"
    val m = mock[IConnector]
    val qe = mock[IQueryEngine]
    //(qe.execute _).expects(*,*).returning(QueryResult.createSuccessQueryResult())
    //(m.getQueryEngine _).expects().returning(qe)
    (m.getConnectorName _).expects().returning("My New Connector")

    val config = ConfigFactory.parseString("akka.remote.netty.tcp.port=" + port).withFallback(ConfigFactory.load())
    val c = new ConnectorApp()
    //val myReference = c.startup(m, port, config)
    val myReference = c.startup(m, port)
    var steps: util.ArrayList[LogicalStep] = new util.ArrayList[LogicalStep]()
    val pq = new SelectPlannedQuery(
        new SelectValidatedQuery(
            new SelectParsedQuery(
              new BaseQuery("query_id-2384234-1341234-23434", "select * from myQuery;", new CatalogName("myCatalog") )
              ,new SelectStatement(new TableName("myCatalog","myTable"))
          )
        ), new LogicalWorkflow(steps)
    )
    val selectQ: SelectInProgressQuery = new SelectInProgressQuery(pq)
    /*
    val beanMap: util.Map[String, String] = BeanUtils.recursiveDescribe(selectQ);
    for (s <- beanMap.keySet().toArray()) {
      println(s);
    }
    */
    myReference ! selectQ
    c.shutdown()
  }

  /*
  test("Send MetadataInProgressQuery to Connector") {
{'fraction_non_alphanumeric': 0.12255495932144712, 'fraction_numerical': 0.010732213951878138, 'mean_word_length': 3.963917525773196, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1697226', 'n_tokens_mistral': 1858, 'n_tokens_neox': 1817, 'n_words': 386}