-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrote a first test, doesn't quite work yet.
- Loading branch information
1 parent
63fe9f5
commit ddb74d0
Showing
8 changed files
with
108 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
common/src/main/scala/au/csiro/data61/magda/search/elasticsearch/ElasticClientTrait.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package au.csiro.data61.magda.search.elasticsearch | ||
|
||
import com.sksamuel.elastic4s.{ElasticClient, Executable, RichSearchResponse, SearchDefinition} | ||
import org.elasticsearch.client.{AdminClient, Client} | ||
|
||
import scala.concurrent.Future | ||
import scala.concurrent.duration.Duration | ||
|
||
trait ElasticClientTrait { | ||
def execute[T, R, Q](t: T)(implicit executable: Executable[T, R, Q]): Future[Q] | ||
def close(): Unit | ||
def java: Client | ||
def admin: AdminClient | ||
def iterateSearch(query: SearchDefinition)(implicit timeout: Duration): Iterator[RichSearchResponse] | ||
} | ||
|
||
class ElasticClientAdapter(client: ElasticClient) extends ElasticClientTrait{ | ||
override def execute[T, R, Q](t: T)(implicit executable: Executable[T, R, Q]): Future[Q] = client.execute(t)(executable) | ||
override def close(): Unit = client.close | ||
override def java: Client = client.java | ||
override def admin: AdminClient = client.admin | ||
override def iterateSearch(query: SearchDefinition)(implicit timeout: Duration): Iterator[RichSearchResponse] = client.iterateSearch(query)(timeout) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
search-api/src/test/scala/ai/csiro/data61/magda/api/ApiSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package ai.csiro.data61.magda.api | ||
|
||
import akka.actor.Scheduler | ||
import akka.event.{Logging, LoggingAdapter, NoLogging} | ||
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._ | ||
import akka.http.scaladsl.model.ContentTypes._ | ||
import akka.http.scaladsl.model.StatusCodes._ | ||
import akka.http.scaladsl.model.{HttpRequest, HttpResponse} | ||
import akka.http.scaladsl.testkit.ScalatestRouteTest | ||
import akka.stream.scaladsl.Flow | ||
import au.csiro.data61.magda.AppConfig | ||
import au.csiro.data61.magda.MagdaApp.getClass | ||
import au.csiro.data61.magda.api.Api | ||
import au.csiro.data61.magda.search.elasticsearch.{ClientProvider, ElasticClientTrait, ElasticSearchQueryer} | ||
import com.sksamuel.elastic4s.ElasticClient | ||
import org.elasticsearch.client.ElasticsearchClient | ||
import org.scalamock.proxy.ProxyMockFactory | ||
import org.scalamock.scalatest.MockFactory | ||
import org.scalatest._ | ||
|
||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
class ApiSpec extends FlatSpec with Matchers with ScalatestRouteTest with MockFactory with ProxyMockFactory { | ||
// override def testConfigSource = "akka.loglevel = DEBUG" | ||
val logger = Logging(system, getClass) | ||
|
||
implicit val config = AppConfig.conf | ||
|
||
val mockEsClient = mock[ElasticClientTrait] | ||
implicit object MockClientProvider extends ClientProvider { | ||
override def getClient(implicit scheduler: Scheduler, logger: LoggingAdapter, ec: ExecutionContext): Future[ElasticClientTrait] = Future(mockEsClient) | ||
} | ||
|
||
val searchQueryer = new ElasticSearchQueryer() | ||
val api = new Api(logger, config, searchQueryer) | ||
val routes = api.routes | ||
|
||
// override lazy val ipApiConnectionFlow = Flow[HttpRequest].map { request => | ||
// if (request.uri.toString().endsWith(ip1Info.query)) | ||
// HttpResponse(status = OK, entity = marshal(ip1Info)) | ||
// else if (request.uri.toString().endsWith(ip2Info.query)) | ||
// HttpResponse(status = OK, entity = marshal(ip2Info)) | ||
// else | ||
// HttpResponse(status = BadRequest, entity = marshal("Bad ip format")) | ||
// } | ||
|
||
it should "respond to query" in { | ||
Get(s"/datasets/search?query=hello") ~> routes ~> check { | ||
status shouldBe OK | ||
contentType shouldBe `application/json` | ||
// responseAs[IpInfo] shouldBe ip1Info | ||
} | ||
|
||
} | ||
|
||
} |