You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
193 lines
8.2 KiB
193 lines
8.2 KiB
9 years ago
|
|
||
|
/**
|
||
8 years ago
|
* yacysearchitemTest
|
||
|
* Copyright 2016 by luccioman; https://github.com/luccioman
|
||
|
*
|
||
9 years ago
|
* 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 {
|
||
|
|
||
|
/**
|
||
8 years ago
|
* Three standard icons with different sizes, one non-standard with a larger
|
||
9 years ago
|
* 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 */
|
||
9 years ago
|
DigestURL faviconURL = yacysearchitem.getFaviconURL(metadataNode, new Dimension(32, 32));
|
||
9 years ago
|
Assert.assertNotNull(faviconURL);
|
||
|
Assert.assertEquals("http://somehost.org/static/images/icon32.png", faviconURL.toNormalform(false));
|
||
|
|
||
|
/* Search for a size not in icons collection */
|
||
9 years ago
|
faviconURL = yacysearchitem.getFaviconURL(metadataNode, new Dimension(40, 40));
|
||
9 years ago
|
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
|
||
|
*/
|
||
9 years ago
|
faviconURL = yacysearchitem.getFaviconURL(metadataNode, new Dimension(128, 128));
|
||
9 years ago
|
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 */
|
||
9 years ago
|
DigestURL faviconURL = yacysearchitem.getFaviconURL(metadataNode, new Dimension(32, 32));
|
||
9 years ago
|
Assert.assertNotNull(faviconURL);
|
||
|
Assert.assertEquals("http://somehost.org/static/images/mask32.png", faviconURL.toNormalform(false));
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
/**
|
||
|
* One standard icon with multiple sizes
|
||
|
*
|
||
|
* @throws MalformedURLException
|
||
|
*/
|
||
|
@Test
|
||
|
public final void testGetFaviconURLMultiSizes() throws MalformedURLException {
|
||
|
URIMetadataNode metadataNode = new URIMetadataNode(new DigestURL("http://somehost.org"));
|
||
9 years ago
|
metadataNode.setField(CollectionSchema.icons_urlstub_sxt.getSolrFieldName(),
|
||
|
new String[] { "somehost.org/static/images/favicon.ico" });
|
||
9 years ago
|
List<String> protocols = CollectionConfiguration
|
||
9 years ago
|
.protocolList2indexedList(Arrays.asList(new String[] { "http" }));
|
||
9 years ago
|
metadataNode.setField(CollectionSchema.icons_protocol_sxt.getSolrFieldName(), protocols);
|
||
9 years ago
|
metadataNode.setField(CollectionSchema.icons_rel_sxt.getSolrFieldName(), new String[] { "icon" });
|
||
9 years ago
|
metadataNode.setField(CollectionSchema.icons_sizes_sxt.getSolrFieldName(),
|
||
9 years ago
|
new String[] { "16x16 32x32 64x64", });
|
||
9 years ago
|
|
||
|
/* Search for a size in sizes set */
|
||
9 years ago
|
DigestURL faviconURL = yacysearchitem.getFaviconURL(metadataNode, new Dimension(32, 32));
|
||
9 years ago
|
Assert.assertNotNull(faviconURL);
|
||
|
Assert.assertEquals("http://somehost.org/static/images/favicon.ico", faviconURL.toNormalform(false));
|
||
|
|
||
|
/* Search for a size not in sizes set */
|
||
9 years ago
|
faviconURL = yacysearchitem.getFaviconURL(metadataNode, new Dimension(40, 40));
|
||
9 years ago
|
Assert.assertNotNull(faviconURL);
|
||
|
Assert.assertEquals("http://somehost.org/static/images/favicon.ico", faviconURL.toNormalform(false));
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
/**
|
||
|
* One standard icon with no size
|
||
|
*
|
||
|
* @throws MalformedURLException
|
||
|
*/
|
||
|
@Test
|
||
|
public final void testGetFaviconURLNoSize() throws MalformedURLException {
|
||
|
URIMetadataNode metadataNode = new URIMetadataNode(new DigestURL("http://somehost.org"));
|
||
9 years ago
|
metadataNode.setField(CollectionSchema.icons_urlstub_sxt.getSolrFieldName(),
|
||
|
new String[] { "somehost.org/static/images/favicon.ico" });
|
||
9 years ago
|
List<String> protocols = CollectionConfiguration
|
||
9 years ago
|
.protocolList2indexedList(Arrays.asList(new String[] { "http" }));
|
||
9 years ago
|
metadataNode.setField(CollectionSchema.icons_protocol_sxt.getSolrFieldName(), protocols);
|
||
9 years ago
|
metadataNode.setField(CollectionSchema.icons_rel_sxt.getSolrFieldName(), new String[] { "icon" });
|
||
9 years ago
|
|
||
9 years ago
|
DigestURL faviconURL = yacysearchitem.getFaviconURL(metadataNode, new Dimension(32, 32));
|
||
9 years ago
|
Assert.assertNotNull(faviconURL);
|
||
|
Assert.assertEquals("http://somehost.org/static/images/favicon.ico", faviconURL.toNormalform(false));
|
||
|
}
|
||
9 years ago
|
|
||
|
/**
|
||
|
* 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));
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
/**
|
||
|
* 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 */
|
||
9 years ago
|
DigestURL faviconURL = yacysearchitem.getFaviconURL(metadataNode, new Dimension(32, 32));
|
||
9 years ago
|
Assert.assertEquals("http://somehost.org/favicon.ico", faviconURL.toNormalform(false));
|
||
|
}
|
||
|
|
||
|
}
|