diff options
| author | luccioman <luccioman@users.noreply.github.com> | 2016-10-15 11:34:23 +0200 |
|---|---|---|
| committer | luccioman <luccioman@users.noreply.github.com> | 2016-10-15 11:34:23 +0200 |
| commit | 4c0be4d5d41bda410921158a9666b215284cceac (patch) | |
| tree | 1132fdcd2d06c398e76d1cbb5b35079881e073e5 /test/yacysearchitemTest.java | |
| parent | ba77e8f8ec42b82a3ca50ee024231fd569d1a8ae (diff) | |
Fixed maven compilation error
Removed unit test yacysearchitemTest from default maven Junit tests
path, as yacysearchitem class is not in maven build classpath.
Diffstat (limited to 'test/yacysearchitemTest.java')
| -rw-r--r-- | test/yacysearchitemTest.java | 192 |
1 files changed, 192 insertions, 0 deletions
diff --git a/test/yacysearchitemTest.java b/test/yacysearchitemTest.java new file mode 100644 index 000000000..6fda4ce48 --- /dev/null +++ b/test/yacysearchitemTest.java @@ -0,0 +1,192 @@ + +/** + * yacysearchitemTest + * Copyright 2016 by luccioman; https://github.com/luccioman + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program in the file lgpl21.txt + * If not, see <http://www.gnu.org/licenses/>. + */ + +import java.awt.Dimension; +import java.net.MalformedURLException; +import java.util.Arrays; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; + +import net.yacy.cora.document.id.DigestURL; +import net.yacy.kelondro.data.meta.URIMetadataNode; +import net.yacy.search.schema.CollectionConfiguration; +import net.yacy.search.schema.CollectionSchema; + +/** + * Unit tests for yacysearchitem class. + * + * @author luc + * + */ +public class yacysearchitemTest { + + /** + * Three standard icons with different sizes, one non-standard with a larger + * size + * + * @throws MalformedURLException + */ + @Test + public final void testGetFaviconURL() throws MalformedURLException { + URIMetadataNode metadataNode = new URIMetadataNode(new DigestURL("http://somehost.org")); + metadataNode + .setField(CollectionSchema.icons_urlstub_sxt.getSolrFieldName(), + new String[] { "someHost.org/static/images/icon16.png", "somehost.org/static/images/icon32.png", + "somehost.org/static/images/icon64.png", + "somehost.org/static/images/iconApple124.png" }); + List<String> protocols = CollectionConfiguration + .protocolList2indexedList(Arrays.asList(new String[] { "http", "http", "http", "http" })); + metadataNode.setField(CollectionSchema.icons_protocol_sxt.getSolrFieldName(), protocols); + metadataNode.setField(CollectionSchema.icons_rel_sxt.getSolrFieldName(), + new String[] { "icon", "icon", "icon", "apple-touch-icon" }); + metadataNode.setField(CollectionSchema.icons_sizes_sxt.getSolrFieldName(), + new String[] { "16x16", "32x32", "64x64", "128x128" }); + + /* Search for a size present in icons collection */ + DigestURL faviconURL = yacysearchitem.getFaviconURL(metadataNode, new Dimension(32, 32)); + Assert.assertNotNull(faviconURL); + Assert.assertEquals("http://somehost.org/static/images/icon32.png", faviconURL.toNormalform(false)); + + /* Search for a size not in icons collection */ + faviconURL = yacysearchitem.getFaviconURL(metadataNode, new Dimension(40, 40)); + Assert.assertNotNull(faviconURL); + Assert.assertEquals("http://somehost.org/static/images/icon32.png", faviconURL.toNormalform(false)); + + /* + * Search for a size equals to non-standard : standard icon is stil + * preffered + */ + faviconURL = yacysearchitem.getFaviconURL(metadataNode, new Dimension(128, 128)); + Assert.assertNotNull(faviconURL); + Assert.assertEquals("http://somehost.org/static/images/icon64.png", faviconURL.toNormalform(false)); + } + + /** + * Only non-standard icons + * + * @throws MalformedURLException + */ + @Test + public final void testGetFaviconURLNonStandard() throws MalformedURLException { + URIMetadataNode metadataNode = new URIMetadataNode(new DigestURL("http://somehost.org")); + metadataNode + .setField(CollectionSchema.icons_urlstub_sxt.getSolrFieldName(), + new String[] { "somehost.org/static/images/mask32.png", + "somehost.org/static/images/fluid.64.png", + "somehost.org/static/images/iconApple124.png" }); + List<String> protocols = CollectionConfiguration + .protocolList2indexedList(Arrays.asList(new String[] { "http", "http", "http" })); + metadataNode.setField(CollectionSchema.icons_protocol_sxt.getSolrFieldName(), protocols); + metadataNode.setField(CollectionSchema.icons_rel_sxt.getSolrFieldName(), + new String[] { "mask-icon", "fluid-icon", "apple-touch-icon" }); + metadataNode.setField(CollectionSchema.icons_sizes_sxt.getSolrFieldName(), + new String[] { "32x32", "64x64", "128x128" }); + + /* Non standard icon is returned as fallback */ + DigestURL faviconURL = yacysearchitem.getFaviconURL(metadataNode, new Dimension(32, 32)); + Assert.assertNotNull(faviconURL); + Assert.assertEquals("http://somehost.org/static/images/mask32.png", faviconURL.toNormalform(false)); + } + + /** + * One standard icon with multiple sizes + * + * @throws MalformedURLException + */ + @Test + public final void testGetFaviconURLMultiSizes() throws MalformedURLException { + URIMetadataNode metadataNode = new URIMetadataNode(new DigestURL("http://somehost.org")); + metadataNode.setField(CollectionSchema.icons_urlstub_sxt.getSolrFieldName(), + new String[] { "somehost.org/static/images/favicon.ico" }); + List<String> protocols = CollectionConfiguration + .protocolList2indexedList(Arrays.asList(new String[] { "http" })); + metadataNode.setField(CollectionSchema.icons_protocol_sxt.getSolrFieldName(), protocols); + metadataNode.setField(CollectionSchema.icons_rel_sxt.getSolrFieldName(), new String[] { "icon" }); + metadataNode.setField(CollectionSchema.icons_sizes_sxt.getSolrFieldName(), + new String[] { "16x16 32x32 64x64", }); + + /* Search for a size in sizes set */ + DigestURL faviconURL = yacysearchitem.getFaviconURL(metadataNode, new Dimension(32, 32)); + Assert.assertNotNull(faviconURL); + Assert.assertEquals("http://somehost.org/static/images/favicon.ico", faviconURL.toNormalform(false)); + + /* Search for a size not in sizes set */ + faviconURL = yacysearchitem.getFaviconURL(metadataNode, new Dimension(40, 40)); + Assert.assertNotNull(faviconURL); + Assert.assertEquals("http://somehost.org/static/images/favicon.ico", faviconURL.toNormalform(false)); + } + + /** + * One standard icon with no size + * + * @throws MalformedURLException + */ + @Test + public final void testGetFaviconURLNoSize() throws MalformedURLException { + URIMetadataNode metadataNode = new URIMetadataNode(new DigestURL("http://somehost.org")); + metadataNode.setField(CollectionSchema.icons_urlstub_sxt.getSolrFieldName(), + new String[] { "somehost.org/static/images/favicon.ico" }); + List<String> protocols = CollectionConfiguration + .protocolList2indexedList(Arrays.asList(new String[] { "http" })); + metadataNode.setField(CollectionSchema.icons_protocol_sxt.getSolrFieldName(), protocols); + metadataNode.setField(CollectionSchema.icons_rel_sxt.getSolrFieldName(), new String[] { "icon" }); + + DigestURL faviconURL = yacysearchitem.getFaviconURL(metadataNode, new Dimension(32, 32)); + Assert.assertNotNull(faviconURL); + Assert.assertEquals("http://somehost.org/static/images/favicon.ico", faviconURL.toNormalform(false)); + } + + /** + * One non-standard icon with no size + * + * @throws MalformedURLException + */ + @Test + public final void testGetFaviconURLNonStandardNoSize() throws MalformedURLException { + URIMetadataNode metadataNode = new URIMetadataNode(new DigestURL("http://somehost.org")); + metadataNode.setField(CollectionSchema.icons_urlstub_sxt.getSolrFieldName(), + new String[] { "somehost.org/static/images/favicon.png" }); + List<String> protocols = CollectionConfiguration + .protocolList2indexedList(Arrays.asList(new String[] { "http" })); + metadataNode.setField(CollectionSchema.icons_protocol_sxt.getSolrFieldName(), protocols); + metadataNode.setField(CollectionSchema.icons_rel_sxt.getSolrFieldName(), new String[] { "appel-touch-icon" }); + + DigestURL faviconURL = yacysearchitem.getFaviconURL(metadataNode, new Dimension(32, 32)); + Assert.assertNotNull(faviconURL); + Assert.assertEquals("http://somehost.org/static/images/favicon.png", faviconURL.toNormalform(false)); + } + + /** + * No icon in document + * + * @throws MalformedURLException + */ + @Test + public final void testGetFaviconURLNoIcon() throws MalformedURLException { + URIMetadataNode metadataNode = new URIMetadataNode(new DigestURL("http://someHost.org")); + + /* Default fallback favicon URL should be generated */ + DigestURL faviconURL = yacysearchitem.getFaviconURL(metadataNode, new Dimension(32, 32)); + Assert.assertEquals("http://somehost.org/favicon.ico", faviconURL.toNormalform(false)); + } + +} |
