diff options
author | Jon Bratseth <bratseth@oath.com> | 2018-04-13 22:18:11 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@oath.com> | 2018-04-13 22:18:11 +0200 |
commit | 8c54be83e36fa4ba28c747fec2b8040832002b49 (patch) | |
tree | c63d75c05930352205e46fd405b2ddc5272dcd1f /container-search/src/test/java/com/yahoo/search | |
parent | 41969051757a99e5c8ed09fac31fa0658f039c7c (diff) |
Remove usage of old junit
Diffstat (limited to 'container-search/src/test/java/com/yahoo/search')
26 files changed, 235 insertions, 85 deletions
diff --git a/container-search/src/test/java/com/yahoo/search/cluster/test/ClusterSearcherTestCase.java b/container-search/src/test/java/com/yahoo/search/cluster/test/ClusterSearcherTestCase.java index 00202e433e3..2992d8ab896 100644 --- a/container-search/src/test/java/com/yahoo/search/cluster/test/ClusterSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/cluster/test/ClusterSearcherTestCase.java @@ -4,8 +4,6 @@ package com.yahoo.search.cluster.test; import java.util.ArrayList; import java.util.List; -import junit.framework.TestCase; - import com.yahoo.component.ComponentId; import com.yahoo.prelude.Ping; import com.yahoo.prelude.Pong; @@ -18,10 +16,11 @@ import com.yahoo.search.cluster.PingableSearcher; import com.yahoo.search.result.ErrorMessage; import com.yahoo.search.result.Hit; import com.yahoo.search.searchchain.Execution; +import org.junit.Test; -// TODO: Author! -public class ClusterSearcherTestCase extends TestCase { +import static org.junit.Assert.assertEquals; +public class ClusterSearcherTestCase { class TestingBackendSearcher extends PingableSearcher { @@ -145,7 +144,7 @@ public class ClusterSearcherTestCase extends TestCase { } - + @Test public void testSimple() { Hit blockingHit = new Hit("blocking"); Hit nonblockingHit = new Hit("nonblocking"); diff --git a/container-search/src/test/java/com/yahoo/search/cluster/test/ClusteredConnectionTestCase.java b/container-search/src/test/java/com/yahoo/search/cluster/test/ClusteredConnectionTestCase.java index 4c3ed56cd44..a565c171b98 100644 --- a/container-search/src/test/java/com/yahoo/search/cluster/test/ClusteredConnectionTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/cluster/test/ClusteredConnectionTestCase.java @@ -11,16 +11,21 @@ import com.yahoo.search.cluster.ClusterSearcher; import com.yahoo.search.result.ErrorMessage; import com.yahoo.search.result.Hit; import com.yahoo.search.searchchain.Execution; +import org.junit.Test; import java.util.ArrayList; import java.util.List; import java.util.concurrent.Executors; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + /** * @author bratseth */ -public class ClusteredConnectionTestCase extends junit.framework.TestCase { +public class ClusteredConnectionTestCase { + @Test public void testClustering() { Connection connection0=new Connection("0"); Connection connection1=new Connection("1"); @@ -88,6 +93,7 @@ public class ClusteredConnectionTestCase extends junit.framework.TestCase { assertEquals("from:0",r.hits().get(0).getId().stringValue()); } + @Test public void testClusteringWithPing() { Connection connection0=new Connection("0"); Connection connection1=new Connection("1"); diff --git a/container-search/src/test/java/com/yahoo/search/federation/FederationResultTest.java b/container-search/src/test/java/com/yahoo/search/federation/FederationResultTest.java index b0087a173f8..a1e85a454fb 100644 --- a/container-search/src/test/java/com/yahoo/search/federation/FederationResultTest.java +++ b/container-search/src/test/java/com/yahoo/search/federation/FederationResultTest.java @@ -13,14 +13,13 @@ import com.yahoo.search.searchchain.model.federation.FederationOptions; import com.yahoo.test.ManualClock; import org.junit.Test; -import java.time.Clock; import java.time.Duration; import java.util.Optional; import java.util.Set; import java.util.concurrent.TimeUnit; -import static junit.framework.TestCase.assertTrue; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; /** * @author bratseth diff --git a/container-search/src/test/java/com/yahoo/search/federation/http/HttpTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/http/HttpTestCase.java index 6b9b36800e5..b4f3c13b8e2 100644 --- a/container-search/src/test/java/com/yahoo/search/federation/http/HttpTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/federation/http/HttpTestCase.java @@ -10,6 +10,9 @@ import com.yahoo.search.result.HitGroup; import com.yahoo.search.searchchain.Execution; import com.yahoo.statistics.Statistics; import com.yahoo.text.Utf8; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import javax.xml.bind.JAXBException; import java.io.IOException; @@ -19,16 +22,19 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import static org.junit.Assert.assertEquals; + /** * Rudimentary http searcher test. * * @author bratseth */ -public class HttpTestCase extends junit.framework.TestCase { +public class HttpTestCase { private StupidSingleThreadedHttpServer httpServer; private TestHTTPClientSearcher searcher; + @Test public void testSearcher() throws JAXBException { Result result = searchUsingLocalhost(); @@ -44,6 +50,7 @@ public class HttpTestCase extends junit.framework.TestCase { return searcher.search(query, new Execution(searcher, Execution.Context.createContextStub())); } + @Test public void test_that_ip_address_set_on_meta_hit() { Result result = searchUsingLocalhost(); Hit metaHit = getFirstMetaHit(result.hits()); @@ -61,7 +68,7 @@ public class HttpTestCase extends junit.framework.TestCase { return null; } - @Override + @Before public void setUp() throws Exception { httpServer = new StupidSingleThreadedHttpServer(0, 0) { @Override @@ -81,7 +88,7 @@ public class HttpTestCase extends junit.framework.TestCase { return httpServer.getServerPort(); } - @Override + @After public void tearDown() throws Exception { httpServer.stop(); if (searcher != null) { diff --git a/container-search/src/test/java/com/yahoo/search/federation/http/PingTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/http/PingTestCase.java index 75110ce1161..8c1ff69666b 100644 --- a/container-search/src/test/java/com/yahoo/search/federation/http/PingTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/federation/http/PingTestCase.java @@ -13,6 +13,7 @@ import com.yahoo.statistics.Statistics; import com.yahoo.text.Utf8; import com.yahoo.yolean.Exceptions; import org.apache.http.HttpEntity; +import org.junit.Test; import java.io.IOException; import java.io.InputStream; @@ -24,14 +25,20 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + /** * Check for different keep-alive scenarios. What we really want to test * is the server does not hang. * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ -public class PingTestCase extends junit.framework.TestCase { - static final int TIMEOUT_MS = 60000; +public class PingTestCase { + + private static final int TIMEOUT_MS = 60000; + + @Test public void testNiceCase() throws Exception { NiceStupidServer server = new NiceStupidServer(); server.start(); @@ -82,6 +89,7 @@ public class PingTestCase extends junit.framework.TestCase { } } + @Test public void testUselessCase() throws Exception { UselessStupidServer server = new UselessStupidServer(); server.start(); @@ -89,6 +97,7 @@ public class PingTestCase extends junit.framework.TestCase { server.stop(); } + @Test public void testGrumpyCase() throws Exception { GrumpyStupidServer server = new GrumpyStupidServer(); server.start(); @@ -96,6 +105,7 @@ public class PingTestCase extends junit.framework.TestCase { server.stop(); } + @Test public void testPassiveAggressiveCase() throws Exception { PassiveAggressiveStupidServer server = new PassiveAggressiveStupidServer(); server.start(); diff --git a/container-search/src/test/java/com/yahoo/search/federation/http/QueryParametersTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/http/QueryParametersTestCase.java index 6efa6692574..19750cf84cc 100644 --- a/container-search/src/test/java/com/yahoo/search/federation/http/QueryParametersTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/federation/http/QueryParametersTestCase.java @@ -4,22 +4,24 @@ package com.yahoo.search.federation.http; import com.yahoo.component.ComponentId; import com.yahoo.search.Query; import com.yahoo.search.Result; -import com.yahoo.search.federation.vespa.VespaSearcher; import com.yahoo.search.searchchain.Execution; import com.yahoo.statistics.Statistics; import com.yahoo.vespa.defaults.Defaults; +import org.junit.Test; import java.util.Collections; -import java.util.HashMap; import java.util.Map; +import static org.junit.Assert.assertEquals; + /** * Tests that source and backend specific parameters from the query are added correctly to the backend requests * * @author bratseth */ -public class QueryParametersTestCase extends junit.framework.TestCase { +public class QueryParametersTestCase { + @Test public void testQueryParameters() { Query query=new Query(); query.properties().set("a","a-value"); diff --git a/container-search/src/test/java/com/yahoo/search/federation/sourceref/test/SearchChainResolverTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/sourceref/test/SearchChainResolverTestCase.java index 3df5151de0b..4485a016ee6 100644 --- a/container-search/src/test/java/com/yahoo/search/federation/sourceref/test/SearchChainResolverTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/federation/sourceref/test/SearchChainResolverTestCase.java @@ -16,10 +16,10 @@ import java.util.Collections; import java.util.Iterator; import java.util.SortedSet; -import static junit.framework.Assert.assertNull; -import static junit.framework.Assert.fail; import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; /** * @author tonytv @@ -149,4 +149,5 @@ public class SearchChainResolverTestCase { assertThat(res.federationOptions, is(federationOptions)); return res; } + } diff --git a/container-search/src/test/java/com/yahoo/search/federation/sourceref/test/SourceRefResolverTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/sourceref/test/SourceRefResolverTestCase.java index de468a2be2d..714d1803605 100644 --- a/container-search/src/test/java/com/yahoo/search/federation/sourceref/test/SourceRefResolverTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/federation/sourceref/test/SourceRefResolverTestCase.java @@ -20,9 +20,9 @@ import java.util.Set; import java.util.TreeMap; import static com.yahoo.search.federation.sourceref.test.SearchChainResolverTestCase.emptySourceToProviderMap; -import static junit.framework.Assert.fail; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; import static org.junit.matchers.JUnitMatchers.hasItems; diff --git a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/QueryParametersTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/vespa/test/QueryParametersTestCase.java index 2f7ea531f13..8d1ecf4085e 100644 --- a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/QueryParametersTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/federation/vespa/test/QueryParametersTestCase.java @@ -5,12 +5,14 @@ import com.yahoo.search.Query; import com.yahoo.search.federation.vespa.VespaSearcher; import java.util.Map; +import static org.junit.Assert.assertEquals; + /** * Tests that source and backend specific parameters from the query are added correctly to the backend requests * * @author bratseth */ -public class QueryParametersTestCase extends junit.framework.TestCase { +public class QueryParametersTestCase { public void testQueryParameters() { Query query=new Query(); diff --git a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/ResultBuilderTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/vespa/test/ResultBuilderTestCase.java index 8edab711a93..494e3f06a61 100644 --- a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/ResultBuilderTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/federation/vespa/test/ResultBuilderTestCase.java @@ -3,8 +3,6 @@ package com.yahoo.search.federation.vespa.test; import java.util.Iterator; -import junit.framework.TestCase; - import com.yahoo.net.URI; import com.yahoo.search.Query; import com.yahoo.search.Result; @@ -12,18 +10,19 @@ import com.yahoo.search.federation.vespa.ResultBuilder; import com.yahoo.search.result.ErrorHit; import com.yahoo.search.result.ErrorMessage; import com.yahoo.search.result.HitGroup; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; /** * Test XML parsing of results. * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ @SuppressWarnings("deprecation") -public class ResultBuilderTestCase extends TestCase { - - public ResultBuilderTestCase (String name) { - super(name); - } +public class ResultBuilderTestCase { private boolean quickCompare(double a, double b) { double z = Math.min(Math.abs(a), Math.abs(b)); @@ -34,6 +33,7 @@ public class ResultBuilderTestCase extends TestCase { } } + @Test public void testSimpleResult() { boolean gotErrorDetails = false; ResultBuilder r = new ResultBuilder(); @@ -62,6 +62,7 @@ public class ResultBuilderTestCase extends TestCase { + "<x><y><z /></y></x>", res.hits().get(3).getField("annoying").toString()); } + @Test public void testNestedResult() { ResultBuilder r = new ResultBuilder(); Result res = r.parse("file:src/test/java/com/yahoo/search/federation/vespa/test/nestedhits.xml", new Query("?query=a")); @@ -79,6 +80,7 @@ public class ResultBuilderTestCase extends TestCase { assertEquals("badge/Topic Explorer 5", g3.get(0).getField("name").toString()); } + @Test public void testWeirdDocumentID() { ResultBuilder r = new ResultBuilder(); Result res = r.parse("file:src/test/java/com/yahoo/search/federation/vespa/test/idhits.xml", new Query("?query=a")); @@ -88,4 +90,5 @@ public class ResultBuilderTestCase extends TestCase { assertEquals(new URI("tralle"), res.hits().get(1).getId()); assertEquals(new URI("kalle"), res.hits().get(2).getId()); } + } diff --git a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/VespaIntegrationTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/vespa/test/VespaIntegrationTestCase.java index 4ca41f9aa8b..7fbe883bfb7 100644 --- a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/VespaIntegrationTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/federation/vespa/test/VespaIntegrationTestCase.java @@ -7,19 +7,22 @@ import com.yahoo.search.Result; import com.yahoo.search.Searcher; import com.yahoo.search.federation.vespa.VespaSearcher; import com.yahoo.search.searchchain.Execution; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; /** * @author bratseth */ -@SuppressWarnings("deprecation") -public class VespaIntegrationTestCase extends junit.framework.TestCase { +public class VespaIntegrationTestCase { // TODO: Setup the answering vespa searcher from this test.... + @Test public void testIt() { if (System.currentTimeMillis() > 0) return; - Chain<Searcher> chain=new Chain<>(new VespaSearcher("test","example.yahoo.com",19010,"")); - Result result=new Execution(chain, Execution.Context.createContextStub()).search(new Query("?query=test")); - assertEquals(23,result.hits().size()); + Chain<Searcher> chain = new Chain<>(new VespaSearcher("test","example.yahoo.com",19010,"")); + Result result = new Execution(chain, Execution.Context.createContextStub()).search(new Query("?query=test")); + assertEquals(23, result.hits().size()); } } diff --git a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/VespaSearcherTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/vespa/test/VespaSearcherTestCase.java index 8156232f4a4..2db949b8317 100644 --- a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/VespaSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/federation/vespa/test/VespaSearcherTestCase.java @@ -11,30 +11,36 @@ import com.yahoo.search.query.parser.ParserEnvironment; import com.yahoo.search.query.parser.ParserFactory; import com.yahoo.search.result.Hit; import com.yahoo.search.searchchain.Execution; -import junit.framework.TestCase; import org.apache.http.HttpEntity; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + import java.io.IOException; import java.net.URI; +import static org.junit.Assert.assertEquals; + /** * Check query marshaling in VespaSearcher works. * * @author Steinar Knutsen */ -public class VespaSearcherTestCase extends TestCase { - - // TODO: More tests +public class VespaSearcherTestCase { private VespaSearcher searcher; - protected @Override void setUp() { + @Before + protected void setUp() { searcher = new VespaSearcher("cache1","",0,""); } - protected @Override void tearDown() { + @After + protected void tearDown() { searcher.deconstruct(); } + @Test public void testMarshalQuery() { RankItem root = new RankItem(); QueryTree r = new QueryTree(root); @@ -59,6 +65,7 @@ public class VespaSearcherTestCase extends TestCase { assertEquals("( \"new york\" AND shoes AND silly ) RANK nike RANK adidas RANK \"bloody expensive\"", searcher.marshalQuery(r)); } + @Test public void testMarshalQuerySmallTree() { RankItem root = new RankItem(); QueryTree r = new QueryTree(root); @@ -83,6 +90,7 @@ public class VespaSearcherTestCase extends TestCase { // assertMarshals(root) } + @Test public void testWandMarshalling() { WeakAndItem root = new WeakAndItem(); root.setN(32); @@ -92,6 +100,7 @@ public class VespaSearcherTestCase extends TestCase { assertMarshals(root); } + @Test public void testWandMarshalling2() { // AND (WAND(10) a!1 the!10) source:yahoonews AndItem root = new AndItem(); @@ -121,6 +130,7 @@ public class VespaSearcherTestCase extends TestCase { return parser.parse(new Parsable().setQuery(query).setFilter(filter)); } + @Test public void testSourceProviderProperties() throws Exception { /* TODO: update test Server httpServer = new Server(); @@ -163,6 +173,7 @@ public class VespaSearcherTestCase extends TestCase { */ } + @Test public void testVespaSearcher() { VespaSearcher v=new VespaSearcherValidatingSubclass(); new Execution(v, Execution.Context.createContextStub()).search(new Query(com.yahoo.search.test.QueryTestCase.httpEncode("?query=test&filter=myfilter"))); diff --git a/container-search/src/test/java/com/yahoo/search/pagetemplates/config/test/MapPageTemplateXMLReadingTestCase.java b/container-search/src/test/java/com/yahoo/search/pagetemplates/config/test/MapPageTemplateXMLReadingTestCase.java index 8d31814f82a..51f87538aa5 100644 --- a/container-search/src/test/java/com/yahoo/search/pagetemplates/config/test/MapPageTemplateXMLReadingTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/pagetemplates/config/test/MapPageTemplateXMLReadingTestCase.java @@ -4,17 +4,26 @@ package com.yahoo.search.pagetemplates.config.test; import com.yahoo.search.pagetemplates.PageTemplate; import com.yahoo.search.pagetemplates.PageTemplateRegistry; import com.yahoo.search.pagetemplates.config.PageTemplateXMLReader; -import com.yahoo.search.pagetemplates.model.*; +import com.yahoo.search.pagetemplates.model.MapChoice; +import com.yahoo.search.pagetemplates.model.Placeholder; +import com.yahoo.search.pagetemplates.model.Section; +import com.yahoo.search.pagetemplates.model.Source; +import org.junit.Test; import java.util.List; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + /** * @author bratseth */ -public class MapPageTemplateXMLReadingTestCase extends junit.framework.TestCase { +public class MapPageTemplateXMLReadingTestCase { private String root="src/test/java/com/yahoo/search/pagetemplates/config/test/examples/mapexamples/"; + @Test public void testMap1() { PageTemplateRegistry registry=new PageTemplateXMLReader().read(root); assertCorrectMap1(registry.getComponent("map1")); diff --git a/container-search/src/test/java/com/yahoo/search/pagetemplates/config/test/PageTemplateXMLReadingTestCase.java b/container-search/src/test/java/com/yahoo/search/pagetemplates/config/test/PageTemplateXMLReadingTestCase.java index 109e7e75885..a7f79a0ee93 100644 --- a/container-search/src/test/java/com/yahoo/search/pagetemplates/config/test/PageTemplateXMLReadingTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/pagetemplates/config/test/PageTemplateXMLReadingTestCase.java @@ -13,17 +13,24 @@ import com.yahoo.search.pagetemplates.model.Choice; import com.yahoo.search.pagetemplates.model.Renderer; import com.yahoo.search.pagetemplates.model.Section; import com.yahoo.search.pagetemplates.model.Source; +import org.junit.Test; import java.util.HashSet; import java.util.Set; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + /** * @author bratseth */ -public class PageTemplateXMLReadingTestCase extends junit.framework.TestCase { +public class PageTemplateXMLReadingTestCase { private String root="src/test/java/com/yahoo/search/pagetemplates/config/test/"; + @Test public void testExamples() { PageTemplateRegistry registry=new PageTemplateXMLReader().read(root + "examples"); assertCorrectSerp(registry.getComponent("serp")); @@ -34,6 +41,7 @@ public class PageTemplateXMLReadingTestCase extends junit.framework.TestCase { assertCorrectGeneric(registry.getComponent("generic")); } + @Test public void testConfigReading() { PageTemplatesConfig config = new PageTemplatesConfig(new PageTemplatesConfig.Builder() .page("<page id=\"slottingSerp\" layout=\"mainAndRight\">\n <section layout=\"column\" region=\"main\" source=\"*\" order=\"-[rank]\"/>\n <section layout=\"column\" region=\"right\" source=\"ads\"/>\n</page>\n") @@ -48,6 +56,7 @@ public class PageTemplateXMLReadingTestCase extends junit.framework.TestCase { assertCorrectRicherSerp(registry.getComponent("richerSerp")); } + @Test public void testInvalidFilename() { try { PageTemplateRegistry registry=new PageTemplateXMLReader().read(root + "examples/invalidfilename"); diff --git a/container-search/src/test/java/com/yahoo/search/pagetemplates/test/PageTemplateSearcherTestCase.java b/container-search/src/test/java/com/yahoo/search/pagetemplates/test/PageTemplateSearcherTestCase.java index 74b483bfaba..3efaf9a6132 100644 --- a/container-search/src/test/java/com/yahoo/search/pagetemplates/test/PageTemplateSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/pagetemplates/test/PageTemplateSearcherTestCase.java @@ -18,15 +18,22 @@ import com.yahoo.search.result.Hit; import com.yahoo.search.result.HitGroup; import com.yahoo.search.searchchain.Execution; import com.yahoo.text.interpretation.Interpretation; +import org.junit.Test; import java.util.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + /** * @author bratseth */ -@SuppressWarnings("deprecation") -public class PageTemplateSearcherTestCase extends junit.framework.TestCase { +public class PageTemplateSearcherTestCase { + @Test public void testSearcher() { PageTemplateSearcher s = new PageTemplateSearcher(createPageTemplateRegistry(), new FirstChoiceResolver()); Chain<Searcher> chain = new Chain<>(s,new MockFederator()); diff --git a/container-search/src/test/java/com/yahoo/search/pagetemplates/test/SourceParametersTestCase.java b/container-search/src/test/java/com/yahoo/search/pagetemplates/test/SourceParametersTestCase.java index 74891137dab..7a2d3d782a3 100644 --- a/container-search/src/test/java/com/yahoo/search/pagetemplates/test/SourceParametersTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/pagetemplates/test/SourceParametersTestCase.java @@ -7,14 +7,19 @@ import com.yahoo.search.pagetemplates.PageTemplateRegistry; import com.yahoo.search.pagetemplates.PageTemplateSearcher; import com.yahoo.search.pagetemplates.config.PageTemplateXMLReader; import com.yahoo.search.searchchain.Execution; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; /** * @author bratseth */ -public class SourceParametersTestCase extends junit.framework.TestCase { +public class SourceParametersTestCase { private static final String root="src/test/java/com/yahoo/search/pagetemplates/test/"; + @Test public void testSourceParametersWithSourcesDeterminedByTemplate() { // Create the page template PageTemplateRegistry pageTemplateRegistry=new PageTemplateRegistry(); @@ -31,6 +36,7 @@ public class SourceParametersTestCase extends junit.framework.TestCase { assertEquals("We get the correct number of parameters",5,query.properties().listProperties("source").size()); } + @Test public void testSourceParametersWithSourcesDeterminedByParameter() { // Create the page template PageTemplateRegistry pageTemplateRegistry=new PageTemplateRegistry(); diff --git a/container-search/src/test/java/com/yahoo/search/query/context/test/LoggingTestCase.java b/container-search/src/test/java/com/yahoo/search/query/context/test/LoggingTestCase.java index b1b9b05eb54..5a48bc1425c 100644 --- a/container-search/src/test/java/com/yahoo/search/query/context/test/LoggingTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/context/test/LoggingTestCase.java @@ -8,12 +8,17 @@ import java.util.Set; import com.yahoo.processing.execution.Execution; import com.yahoo.search.Query; import com.yahoo.search.query.context.QueryContext; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; /** * @author bratseth */ -public class LoggingTestCase extends junit.framework.TestCase { +public class LoggingTestCase { + @Test public void testLogging() { Query query=new Query(); QueryContext queryContext = query.getContext(true); diff --git a/container-search/src/test/java/com/yahoo/search/query/context/test/PropertiesTestCase.java b/container-search/src/test/java/com/yahoo/search/query/context/test/PropertiesTestCase.java index 57e4c8701d0..e7c6f016ee8 100644 --- a/container-search/src/test/java/com/yahoo/search/query/context/test/PropertiesTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/context/test/PropertiesTestCase.java @@ -3,12 +3,17 @@ package com.yahoo.search.query.context.test; import com.yahoo.search.Query; import com.yahoo.search.query.context.QueryContext; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; /** * @author bratseth */ -public class PropertiesTestCase extends junit.framework.TestCase { +public class PropertiesTestCase { + @Test public void testProperties() { Query query=new Query(); QueryContext h = query.getContext(true); @@ -33,7 +38,7 @@ public class PropertiesTestCase extends junit.framework.TestCase { h2.setProperty("c","c3"); h.setProperty("c","c4"); - assertEquals("a2",h.getProperty("a")); + assertEquals("a@2",h.getProperty("a")); assertEquals("b5",h.getProperty("b")); assertEquals("c4",h.getProperty("c")); assertEquals("d1",h.getProperty("d")); diff --git a/container-search/src/test/java/com/yahoo/search/query/context/test/TraceTestCase.java b/container-search/src/test/java/com/yahoo/search/query/context/test/TraceTestCase.java index e64b1054f41..5882ded367e 100644 --- a/container-search/src/test/java/com/yahoo/search/query/context/test/TraceTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/context/test/TraceTestCase.java @@ -3,17 +3,22 @@ package com.yahoo.search.query.context.test; import com.yahoo.search.Query; import com.yahoo.search.query.context.QueryContext; +import org.junit.Test; import java.io.IOException; import java.io.StringWriter; import java.io.Writer; import java.util.Iterator; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + /** - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ -public class TraceTestCase extends junit.framework.TestCase { +public class TraceTestCase { + @Test public void testBasicTracing() { Query query=new Query(); QueryContext h = query.getContext(true); @@ -22,6 +27,7 @@ public class TraceTestCase extends junit.framework.TestCase { assertEquals("trace: [ [ first message second message ] ]", h.toString()); } + @Test public void testCloning() throws IOException { Query query=new Query(); QueryContext h = query.getContext(true); @@ -53,6 +59,7 @@ public class TraceTestCase extends junit.framework.TestCase { assertEquals("fifth message",i.next()); } + @Test public void testEmpty() throws IOException { Query query=new Query(); QueryContext h = query.getContext(true); @@ -61,6 +68,7 @@ public class TraceTestCase extends junit.framework.TestCase { assertEquals("", w.toString()); } + @Test public void testEmptySubSequence() { Query query=new Query(); QueryContext h = query.getContext(true); @@ -73,6 +81,7 @@ public class TraceTestCase extends junit.framework.TestCase { } } + @Test public void testAttachedTraces() throws IOException { String needle0 = "nalle"; String needle1 = "tralle"; diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/MultiProfileTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/MultiProfileTestCase.java index db874ab3a81..c355186ba44 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/MultiProfileTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/MultiProfileTestCase.java @@ -7,12 +7,17 @@ import java.util.Map; import com.yahoo.search.query.profile.QueryProfile; import com.yahoo.search.query.profile.QueryProfileRegistry; import com.yahoo.search.query.profile.config.QueryProfileXMLReader; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; /** * @author bratseth */ -public class MultiProfileTestCase extends junit.framework.TestCase { +public class MultiProfileTestCase { + @Test public void testValid() { QueryProfileRegistry registry= new QueryProfileXMLReader().read("src/test/java/com/yahoo/search/query/profile/config/test/multiprofile"); diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/QueryProfileIntegrationTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/QueryProfileIntegrationTestCase.java index 5650a7d3e22..67fb5da10a0 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/QueryProfileIntegrationTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/QueryProfileIntegrationTestCase.java @@ -14,19 +14,24 @@ import com.yahoo.search.handler.HttpSearchResponse; import com.yahoo.search.handler.SearchHandler; import com.yahoo.search.result.Hit; import com.yahoo.search.searchchain.Execution; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; /** * Tests using query profiles in searches * * @author bratseth */ -public class QueryProfileIntegrationTestCase extends junit.framework.TestCase { +public class QueryProfileIntegrationTestCase { - @Override + @org.junit.After public void tearDown() { System.getProperties().remove("config.id"); } + @Test public void testUntyped() { String configId = "dir:src/test/java/com/yahoo/search/query/profile/config/test/untyped"; System.setProperty("config.id", configId); @@ -69,6 +74,7 @@ public class QueryProfileIntegrationTestCase extends junit.framework.TestCase { configurer.shutdown(); } + @Test public void testTyped() { String configId = "dir:src/test/java/com/yahoo/search/query/profile/config/test/typed"; System.setProperty("config.id", configId); diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/TypedProfilesConfigurationTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/TypedProfilesConfigurationTestCase.java index 7907c747a31..9a74e1b6766 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/TypedProfilesConfigurationTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/TypedProfilesConfigurationTestCase.java @@ -6,13 +6,19 @@ import com.yahoo.search.query.profile.config.QueryProfileConfigurer; import com.yahoo.search.query.profile.types.FieldDescription; import com.yahoo.search.query.profile.types.QueryProfileType; import com.yahoo.search.query.profile.types.QueryProfileTypeRegistry; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** * @author bratseth */ -public class TypedProfilesConfigurationTestCase extends junit.framework.TestCase { +public class TypedProfilesConfigurationTestCase { /** Asserts that everything is read correctly from this configuration */ + @Test public void testIt() { QueryProfileConfigurer configurer= new QueryProfileConfigurer("file:src/test/java/com/yahoo/search/query/profile/config/test/typed-profiles.cfg"); diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/test/CloningTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/test/CloningTestCase.java index 0a62581eca0..3e01c79b61f 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/test/CloningTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/profile/test/CloningTestCase.java @@ -6,12 +6,16 @@ import com.yahoo.search.Query; import com.yahoo.search.query.profile.QueryProfile; import com.yahoo.search.query.profile.QueryProfileRegistry; import com.yahoo.jdisc.http.HttpRequest.Method; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; /** * @author bratseth */ -public class CloningTestCase extends junit.framework.TestCase { +public class CloningTestCase { + @Test public void testCloningWithVariants() { QueryProfile test = new QueryProfile("test"); test.setDimensions(new String[] {"x"} ); @@ -24,6 +28,7 @@ public class CloningTestCase extends junit.framework.TestCase { assertEquals("a2",q2.properties().get("a")); } + @Test public void testShallowCloning() { QueryProfile test = new QueryProfile("test"); test.freeze(); @@ -35,6 +40,7 @@ public class CloningTestCase extends junit.framework.TestCase { assertEquals("a2",q2.properties().get("a").toString()); } + @Test public void testShallowCloningWithVariants() { QueryProfile test = new QueryProfile("test"); test.setDimensions(new String[] {"x"} ); @@ -47,6 +53,7 @@ public class CloningTestCase extends junit.framework.TestCase { assertEquals("a2",q2.properties().get("a").toString()); } + @Test public void testDeepCloning() { QueryProfile test=new QueryProfile("test"); test.freeze(); @@ -58,6 +65,7 @@ public class CloningTestCase extends junit.framework.TestCase { assertEquals("a2",q2.properties().get("a").toString()); } + @Test public void testDeepCloningWithVariants() { QueryProfile test=new QueryProfile("test"); test.setDimensions(new String[] {"x"} ); @@ -70,6 +78,7 @@ public class CloningTestCase extends junit.framework.TestCase { assertEquals("a2",q2.properties().get("a").toString()); } + @Test public void testReAssignment() { QueryProfile test=new QueryProfile("test"); test.setDimensions(new String[] {"x"} ); @@ -80,6 +89,7 @@ public class CloningTestCase extends junit.framework.TestCase { assertEquals("a2",q1.properties().get("a")); } + @Test public void testThreeLevelsOfCloning() { QueryProfile test = new QueryProfile("test"); test.set("a", "config-a", (QueryProfileRegistry)null); @@ -105,6 +115,7 @@ public class CloningTestCase extends junit.framework.TestCase { assertEquals("q32-a",q32.properties().get("a").toString()); } + @Test public void testThreeLevelsOfCloningReverseSetOrder() { QueryProfile test = new QueryProfile("test"); test.set("a", "config-a", (QueryProfileRegistry)null); @@ -130,6 +141,7 @@ public class CloningTestCase extends junit.framework.TestCase { assertEquals("q32-a",q32.properties().get("a").toString()); } + @Test public void testThreeLevelsOfCloningMiddleFirstSetOrder1() { QueryProfile test = new QueryProfile("test"); test.set("a", "config-a", (QueryProfileRegistry)null); @@ -155,6 +167,7 @@ public class CloningTestCase extends junit.framework.TestCase { assertEquals("q32-a",q32.properties().get("a").toString()); } + @Test public void testThreeLevelsOfCloningMiddleFirstSetOrder2() { QueryProfile test = new QueryProfile("test"); test.set("a", "config-a", (QueryProfileRegistry)null); diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/test/DumpToolTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/test/DumpToolTestCase.java index 3d422767a66..46d574f1713 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/test/DumpToolTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/profile/test/DumpToolTestCase.java @@ -2,33 +2,40 @@ package com.yahoo.search.query.profile.test; import com.yahoo.search.query.profile.DumpTool; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; /** * @author bratseth */ -public class DumpToolTestCase extends junit.framework.TestCase { +public class DumpToolTestCase { String profileDir="src/test/java/com/yahoo/search/query/profile/config/test/multiprofile"; + @Test public void testNoParameters() { assertTrue(new DumpTool().resolveAndDump().startsWith("Dumps all resolved")); } + @Test public void testHelpParameter() { assertTrue(new DumpTool().resolveAndDump("-help").startsWith("Dumps all resolved")); } + @Test public void testNoDimensionValues() { assertTrue(new DumpTool().resolveAndDump("multiprofile1",profileDir).startsWith("a=general-a\n")); } + @Test public void testAllParametersSet() { assertTrue(new DumpTool().resolveAndDump("multiprofile1",profileDir,"").startsWith("a=general-a\n")); } - //This test is order dependent. Fix this!! + // This test is order dependent. Fix this!! + @Test public void testVariant() { - System.out.println(new DumpTool().resolveAndDump("multiprofile1",profileDir,"region=us")); assertTrue(new DumpTool().resolveAndDump("multiprofile1",profileDir,"region=us").startsWith("a=us-a\nb=us-b\nregion=us")); } diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryFromProfileTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryFromProfileTestCase.java index f75444108ff..b4fe6b62d44 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryFromProfileTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryFromProfileTestCase.java @@ -8,14 +8,18 @@ import com.yahoo.search.Query; import com.yahoo.search.query.profile.QueryProfileRegistry; import com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry; import com.yahoo.search.query.profile.types.QueryProfileType; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; /** * Test using the profile to set the query to execute * * @author bratseth */ -public class QueryFromProfileTestCase extends junit.framework.TestCase { +public class QueryFromProfileTestCase { + @Test public void testQueryFromProfile1() { QueryProfileRegistry registry = new QueryProfileRegistry(); QueryProfile topLevel = new QueryProfile("topLevel"); @@ -34,6 +38,7 @@ public class QueryFromProfileTestCase extends junit.framework.TestCase { assertEquals("best", query.getModel().getQueryTree().toString()); } + @Test public void testQueryFromProfile2() { QueryProfileRegistry registry = new QueryProfileRegistry(); QueryProfileType rootType = new QueryProfileType("root"); @@ -56,6 +61,7 @@ public class QueryFromProfileTestCase extends junit.framework.TestCase { assertEquals("overrides", query.getModel().getQueryTree().toString()); } + @Test public void testQueryFromProfile3() { QueryProfileRegistry registry = new QueryProfileRegistry(); QueryProfileType rootType = new QueryProfileType("root"); diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileSubstitutionTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileSubstitutionTestCase.java index 27960aac56c..7ff120ddc70 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileSubstitutionTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileSubstitutionTestCase.java @@ -7,42 +7,49 @@ import com.yahoo.yolean.Exceptions; import com.yahoo.search.query.profile.QueryProfile; import com.yahoo.search.query.profile.QueryProfileProperties; import com.yahoo.search.query.profile.compiled.CompiledQueryProfile; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; /** * @author bratseth */ -public class QueryProfileSubstitutionTestCase extends junit.framework.TestCase { +public class QueryProfileSubstitutionTestCase { + @Test public void testSingleSubstitution() { QueryProfile p=new QueryProfile("test"); - p.set("message","Hello %{world}!", (QueryProfileRegistry)null); - p.set("world", "world", (QueryProfileRegistry)null); + p.set("message","Hello %{world}!", null); + p.set("world", "world", null); assertEquals("Hello world!",p.compile(null).get("message")); QueryProfile p2=new QueryProfile("test2"); p2.addInherited(p); - p2.set("world", "universe", (QueryProfileRegistry)null); + p2.set("world", "universe", null); assertEquals("Hello universe!",p2.compile(null).get("message")); } + @Test public void testMultipleSubstitutions() { QueryProfile p=new QueryProfile("test"); - p.set("message","%{greeting} %{entity}%{exclamation}", (QueryProfileRegistry)null); - p.set("greeting","Hola", (QueryProfileRegistry)null); - p.set("entity","local group", (QueryProfileRegistry)null); - p.set("exclamation","?", (QueryProfileRegistry)null); + p.set("message","%{greeting} %{entity}%{exclamation}", null); + p.set("greeting","Hola", null); + p.set("entity","local group", null); + p.set("exclamation","?", null); assertEquals("Hola local group?",p.compile(null).get("message")); QueryProfile p2=new QueryProfile("test2"); p2.addInherited(p); - p2.set("entity","milky way", (QueryProfileRegistry)null); + p2.set("entity","milky way", null); assertEquals("Hola milky way?",p2.compile(null).get("message")); } + @Test public void testUnclosedSubstitution1() { try { QueryProfile p=new QueryProfile("test"); - p.set("message1","%{greeting} %{entity}%{exclamation", (QueryProfileRegistry)null); + p.set("message1","%{greeting} %{entity}%{exclamation", null); fail("Should have produced an exception"); } catch (IllegalArgumentException e) { @@ -51,10 +58,11 @@ public class QueryProfileSubstitutionTestCase extends junit.framework.TestCase { } } + @Test public void testUnclosedSubstitution2() { try { QueryProfile p=new QueryProfile("test"); - p.set("message1","%{greeting} %{entity%{exclamation}", (QueryProfileRegistry)null); + p.set("message1","%{greeting} %{entity%{exclamation}", null); fail("Should have produced an exception"); } catch (IllegalArgumentException e) { @@ -63,23 +71,25 @@ public class QueryProfileSubstitutionTestCase extends junit.framework.TestCase { } } + @Test public void testNullSubstitution() { QueryProfile p=new QueryProfile("test"); - p.set("message","%{greeting} %{entity}%{exclamation}", (QueryProfileRegistry)null); - p.set("greeting","Hola", (QueryProfileRegistry)null); + p.set("message","%{greeting} %{entity}%{exclamation}", null); + p.set("greeting","Hola", null); assertEquals("Hola ", p.compile(null).get("message")); QueryProfile p2=new QueryProfile("test2"); p2.addInherited(p); - p2.set("greeting","Hola", (QueryProfileRegistry)null); - p2.set("exclamation", "?", (QueryProfileRegistry)null); + p2.set("greeting","Hola", null); + p2.set("exclamation", "?", null); assertEquals("Hola ?",p2.compile(null).get("message")); } + @Test public void testNoOverridingOfPropertiesSetAtRuntime() { QueryProfile p=new QueryProfile("test"); - p.set("message","Hello %{world}!", (QueryProfileRegistry)null); - p.set("world","world", (QueryProfileRegistry)null); + p.set("message","Hello %{world}!", null); + p.set("world","world", null); p.freeze(); Properties runtime=new QueryProfileProperties(p.compile(null)); @@ -88,27 +98,30 @@ public class QueryProfileSubstitutionTestCase extends junit.framework.TestCase { assertEquals("Hello %{world}!",runtime.get("runtimeMessage")); } + @Test public void testButPropertiesSetAtRuntimeAreUsedInSubstitutions() { QueryProfile p=new QueryProfile("test"); - p.set("message","Hello %{world}!", (QueryProfileRegistry)null); - p.set("world","world", (QueryProfileRegistry)null); + p.set("message","Hello %{world}!", null); + p.set("world","world", null); Properties runtime=new QueryProfileProperties(p.compile(null)); runtime.set("world","Earth"); assertEquals("Hello Earth!",runtime.get("message")); } + @Test public void testInspection() { QueryProfile p=new QueryProfile("test"); - p.set("message", "%{greeting} %{entity}%{exclamation}", (QueryProfileRegistry)null); + p.set("message", "%{greeting} %{entity}%{exclamation}", null); assertEquals("message","%{greeting} %{entity}%{exclamation}", p.declaredContent().entrySet().iterator().next().getValue().toString()); } + @Test public void testVariants() { QueryProfile p=new QueryProfile("test"); - p.set("message","Hello %{world}!", (QueryProfileRegistry)null); - p.set("world","world", (QueryProfileRegistry)null); + p.set("message","Hello %{world}!", null); + p.set("world","world", null); p.setDimensions(new String[] {"x"}); p.set("message","Halo %{world}!",new String[] {"x1"}, null); p.set("world","Europe",new String[] {"x2"}, null); @@ -119,11 +132,12 @@ public class QueryProfileSubstitutionTestCase extends junit.framework.TestCase { assertEquals("Hello Europe!", cp.get("message", QueryProfileVariantsTestCase.toMap("x=x2"))); } + @Test public void testRecursion() { QueryProfile p=new QueryProfile("test"); - p.set("message","Hello %{world}!", (QueryProfileRegistry)null); - p.set("world","sol planet number %{number}", (QueryProfileRegistry)null); - p.set("number",3, (QueryProfileRegistry)null); + p.set("message","Hello %{world}!", null); + p.set("world","sol planet number %{number}", null); + p.set("number",3, null); assertEquals("Hello sol planet number 3!",p.compile(null).get("message")); } |