// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.application.container; import com.yahoo.application.Networking; import com.yahoo.application.container.searchers.AddHitSearcher; import com.yahoo.component.ComponentSpecification; import com.yahoo.search.Query; import com.yahoo.search.Result; import org.junit.Test; import java.nio.charset.StandardCharsets; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; /** * @author gjoranv * @author ollivir */ public class ContainerSchemaTest { @Test public void processing_and_rendering_works() throws Exception { final String searcherId = AddHitSearcher.class.getName(); try (JDisc container = containerWithSearch(searcherId)) { byte[] rendered = container.search().processAndRender(ComponentSpecification.fromString("mychain"), ComponentSpecification.fromString("XmlRenderer"), new Query("")); String renderedAsString = new String(rendered, StandardCharsets.UTF_8); assertTrue(renderedAsString.contains(searcherId)); } } @Test public void searching_works() { final String searcherId = AddHitSearcher.class.getName(); try (JDisc container = containerWithSearch(searcherId)) { Search searching = container.search(); Result result = searching.process(ComponentSpecification.fromString("mychain"), new Query("")); String hitTitle = result.hits().get(0).getField("title").toString(); assertEquals(searcherId, hitTitle); } } public JDisc containerWithSearch(String searcherId) { return JDisc.fromServicesXml("" + // " " + // " " + // " " + // " " + // " " + // " " + // "", Networking.disable); } @Test(expected = UnsupportedOperationException.class) public void retrieving_search_from_container_without_search_is_illegal() { try (JDisc container = JDisc.fromServicesXml("", Networking.disable)) { container.search(); // throws } } }