// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.model.content.cluster; import com.yahoo.vespa.model.builder.xml.dom.ModelElement; import com.yahoo.vespa.model.content.SearchCoverage; import org.junit.Test; import javax.xml.parsers.DocumentBuilderFactory; import java.io.ByteArrayInputStream; import java.nio.charset.StandardCharsets; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; /** * @author Simon Thoresen Hult */ public class DomSchemaCoverageBuilderTest { @Test public void requireThatDefaultsAreNull() throws Exception { SearchCoverage coverage = newSearchCoverage( ""); assertNull(coverage.getMinimum()); assertNull(coverage.getMinWaitAfterCoverageFactor()); assertNull(coverage.getMaxWaitAfterCoverageFactor()); } @Test public void requireThatEmptySearchIsSafe() throws Exception { SearchCoverage coverage = newSearchCoverage( "" + " " + ""); assertNull(coverage.getMinimum()); assertNull(coverage.getMinWaitAfterCoverageFactor()); assertNull(coverage.getMaxWaitAfterCoverageFactor()); } @Test public void requireThatEmptyCoverageIsSafe() throws Exception { SearchCoverage coverage = newSearchCoverage( "" + " " + " " + " " + ""); assertNull(coverage.getMinimum()); assertNull(coverage.getMinWaitAfterCoverageFactor()); assertNull(coverage.getMaxWaitAfterCoverageFactor()); } @Test public void requireThatSearchCoverageCanBeBuilt() throws Exception { SearchCoverage coverage = newSearchCoverage( "" + " " + " " + " 0.11" + " 0.23" + " 0.58" + " " + " " + ""); assertEquals(0.11, coverage.getMinimum(), 1E-6); assertEquals(0.23, coverage.getMinWaitAfterCoverageFactor(), 1E-6); assertEquals(0.58, coverage.getMaxWaitAfterCoverageFactor(), 1E-6); } private static SearchCoverage newSearchCoverage(String xml) throws Exception { return DomSearchCoverageBuilder.build( new ModelElement(DocumentBuilderFactory.newInstance() .newDocumentBuilder() .parse(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8))) .getDocumentElement())); } }