summaryrefslogtreecommitdiffstats
path: root/node-admin/basic-search-for-docker/src/test/java/com/yahoo
diff options
context:
space:
mode:
Diffstat (limited to 'node-admin/basic-search-for-docker/src/test/java/com/yahoo')
-rw-r--r--node-admin/basic-search-for-docker/src/test/java/com/yahoo/example/ExampleSearcherTest.java38
-rw-r--r--node-admin/basic-search-for-docker/src/test/java/com/yahoo/example/ExampleSystemTest.java39
2 files changed, 77 insertions, 0 deletions
diff --git a/node-admin/basic-search-for-docker/src/test/java/com/yahoo/example/ExampleSearcherTest.java b/node-admin/basic-search-for-docker/src/test/java/com/yahoo/example/ExampleSearcherTest.java
new file mode 100644
index 00000000000..87592f2a2ba
--- /dev/null
+++ b/node-admin/basic-search-for-docker/src/test/java/com/yahoo/example/ExampleSearcherTest.java
@@ -0,0 +1,38 @@
+package com.yahoo.example;
+
+import com.yahoo.application.Application;
+import com.yahoo.application.Networking;
+import com.yahoo.application.container.Search;
+import com.yahoo.component.ComponentSpecification;
+import com.yahoo.search.Query;
+import com.yahoo.search.Result;
+import com.yahoo.search.result.Hit;
+import org.junit.Test;
+
+import java.nio.file.Paths;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+
+/**
+ * @author tonyv
+ */
+public class ExampleSearcherTest {
+ @Test
+ public void hit_is_added() throws Exception {
+ try (Application app = Application.fromApplicationPackage(
+ Paths.get("src/test/application"),
+ Networking.disable))
+ {
+ Search search = app.getJDisc("jdisc").search();
+ Result result = search.process(ComponentSpecification.fromString("default"), new Query("?query=ignored"));
+
+ Hit hit = result.hits().get(ExampleSearcher.hitId);
+ assertNotNull("Hit was not added by ExampleSearcher", hit);
+
+ Object messageFromConfig = "Hello, Vespa!";
+ assertThat(hit.getField("message"), is(messageFromConfig));
+ }
+ }
+}
diff --git a/node-admin/basic-search-for-docker/src/test/java/com/yahoo/example/ExampleSystemTest.java b/node-admin/basic-search-for-docker/src/test/java/com/yahoo/example/ExampleSystemTest.java
new file mode 100644
index 00000000000..2bed440868e
--- /dev/null
+++ b/node-admin/basic-search-for-docker/src/test/java/com/yahoo/example/ExampleSystemTest.java
@@ -0,0 +1,39 @@
+package com.yahoo.example;
+
+import com.yahoo.vespa.tenant.systemtest.Feed;
+import com.yahoo.vespa.tenant.systemtest.FeedResult;
+import com.yahoo.vespa.tenant.systemtest.Query;
+import com.yahoo.vespa.tenant.systemtest.QueryResult;
+import com.yahoo.vespa.tenant.systemtest.VespaEndpoints;
+import com.yahoo.vespa.tenant.systemtest.base.MutableVespaEndpoint;
+import com.yahoo.vespa.tenant.systemtest.base.SystemTest;
+import com.yahoo.vespa.tenant.systemtest.hitchecker.HitChecker;
+import org.junit.Test;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+public class ExampleSystemTest extends SystemTest {
+ @Override
+ /**
+ * In order to develop and test the system tests, you can create a dev instance and push this
+ * (e.g. mvn deploy:vespa) to your personal vespa dev instance. You will need to change this
+ * function to point to this instance. This is only for testing and debugging the test.
+ */
+ protected VespaEndpoints createVespaSystemTestInstanceEndpointsWhenNotOnScrewdriver() {
+ return new VespaEndpoints.Builder().fromPom().inDevCluster()
+ .withRegion("corp-us-east-1").withTenant("ENTER TENANT USER FOR USED FOR LOCAL DEVELOPMENT HERE").build();
+ }
+ @Test
+ public void testWithOneDocument() throws Exception {
+ MutableVespaEndpoint endpoint = getSystemTestsInstance().getDefaultVespaEndpoint();
+ FeedResult feedResult = endpoint.feed(Feed.createFromResource("/minifeed.json"));
+ assertThat(feedResult.numOk(), is(1l));
+ QueryResult result = endpoint.search(new Query("bad"));
+ assertThat(result.totalHitCount(), is(1l));
+ result.expectHit(1, new HitChecker()
+ .fieldRegex("title", ".*Bad")
+ .relevance(0.254, 0.2)
+ .fieldNull("nosuchfield"));
+ }
+}