[Yanel-commits] rev 20904 - in
public/yanel/trunk/src/contributions/resources: nutch/src
nutch/src/test nutch/src/test/htmlunit
nutch/src/test/htmlunit/org nutch/src/test/htmlunit/org/wyona
nutch/src/test/htmlunit/org/wyona/yanel
nutch/src/test/htmlunit/org/wyona/yanel/impl
nutch/src/test/htmlunit/org/wyona/yanel/impl/resources
nutch/src/test/junit nutch/src/test/junit/org
nutch/src/test/junit/org/wyona nutch/src/test/junit/org/wyona/yanel
nutch/src/test/junit/org/wyona/yanel/impl
nutch/src/test/junit/org/wyona/yanel/impl/resources
wiki/src/test wiki/src/test/junit wiki/src/test/junit/org
wiki/src/test/junit/org/wyona wiki/src/test/junit/org/wyona/yanel
wiki/src/test/junit/org/wyona/yanel/impl
michi at wyona.com
michi at wyona.com
Fri Dec 15 14:31:38 CET 2006
Author: michi
Date: 2006-12-15 14:31:36 +0100 (Fri, 15 Dec 2006)
New Revision: 20904
Added:
public/yanel/trunk/src/contributions/resources/nutch/src/test/
public/yanel/trunk/src/contributions/resources/nutch/src/test/htmlunit/
public/yanel/trunk/src/contributions/resources/nutch/src/test/htmlunit/org/
public/yanel/trunk/src/contributions/resources/nutch/src/test/htmlunit/org/wyona/
public/yanel/trunk/src/contributions/resources/nutch/src/test/htmlunit/org/wyona/yanel/
public/yanel/trunk/src/contributions/resources/nutch/src/test/htmlunit/org/wyona/yanel/impl/
public/yanel/trunk/src/contributions/resources/nutch/src/test/htmlunit/org/wyona/yanel/impl/resources/
public/yanel/trunk/src/contributions/resources/nutch/src/test/htmlunit/org/wyona/yanel/impl/resources/NutchResourceWebTest.java
public/yanel/trunk/src/contributions/resources/nutch/src/test/junit/
public/yanel/trunk/src/contributions/resources/nutch/src/test/junit/org/
public/yanel/trunk/src/contributions/resources/nutch/src/test/junit/org/wyona/
public/yanel/trunk/src/contributions/resources/nutch/src/test/junit/org/wyona/yanel/
public/yanel/trunk/src/contributions/resources/nutch/src/test/junit/org/wyona/yanel/impl/
public/yanel/trunk/src/contributions/resources/nutch/src/test/junit/org/wyona/yanel/impl/resources/
public/yanel/trunk/src/contributions/resources/nutch/src/test/junit/org/wyona/yanel/impl/resources/NutchResourceTest.java
public/yanel/trunk/src/contributions/resources/wiki/src/test/junit/
public/yanel/trunk/src/contributions/resources/wiki/src/test/junit/org/
public/yanel/trunk/src/contributions/resources/wiki/src/test/junit/org/wyona/
public/yanel/trunk/src/contributions/resources/wiki/src/test/junit/org/wyona/yanel/
public/yanel/trunk/src/contributions/resources/wiki/src/test/junit/org/wyona/yanel/impl/
public/yanel/trunk/src/contributions/resources/wiki/src/test/junit/org/wyona/yanel/impl/resources/
Log:
tests added for Wiki and Nutch resources
Added: public/yanel/trunk/src/contributions/resources/nutch/src/test/htmlunit/org/wyona/yanel/impl/resources/NutchResourceWebTest.java
===================================================================
--- public/yanel/trunk/src/contributions/resources/nutch/src/test/htmlunit/org/wyona/yanel/impl/resources/NutchResourceWebTest.java 2006-12-15 13:26:45 UTC (rev 20903)
+++ public/yanel/trunk/src/contributions/resources/nutch/src/test/htmlunit/org/wyona/yanel/impl/resources/NutchResourceWebTest.java 2006-12-15 13:31:36 UTC (rev 20904)
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2006 Wyona
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.wyona.org/licenses/APACHE-LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wyona.yanel.impl.resources;
+
+import com.gargoylesoftware.htmlunit.WebClient;
+import com.gargoylesoftware.htmlunit.html.HtmlForm;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
+import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
+
+import java.net.URL;
+
+import org.wyona.yanel.htmlunit.AbstractHtmlUnitTest;
+
+/**
+ * Test loading a page which is an xml resource and verifies the title and
+ * page content.
+ */
+public class NutchResourceWebTest extends AbstractHtmlUnitTest {
+
+ protected void setUp() throws Exception {
+ this.testName = "Nutch Resource Web Test";
+ super.setUp();
+ }
+
+ /**
+ * Loads a page and verifies its title.
+ */
+ public void testNutchResource() throws Exception {
+ loadHtmlPage("yanel-website/en/search.html");
+ assertTitleEquals("Results for query: - Yanel");
+ System.err.println("\n\n\nAAAAAAAAAAAAAAAAa\n\n");
+ }
+
+/*
+ public void testSearchResults() throws Exception {
+ String searchTerm = this.config.getString("nutchSearchTerm");
+ int totalHits = searchResults(searchTerm);
+ int minHints = this.config.getInt("nutchSearchResults");
+ assertTrue("search term " + searchTerm + " only found " + totalHits + " times, " +
+ "minimum expected was " + minHints + " times", totalHits >= minHints);
+ }
+*/
+
+ /**
+ * performs a search and returns the number of hits
+ */
+ public int searchResults(String searchTerm) throws Exception {
+
+ final WebClient webClient = new WebClient();
+ final URL url = new URL("http://127.0.0.1:8080/yanel/yanel-website/en/search.html");
+ //final URL url = new URL(this.config.getString("baseUrl") + "yanel-website/en/search.html");
+ final HtmlPage searchPage = (HtmlPage) webClient.getPage(url);
+ final HtmlForm form = searchPage.getFormByName("search");
+ final HtmlSubmitInput button = (HtmlSubmitInput) form.getInputByName("submit");
+ final HtmlTextInput textField = (HtmlTextInput) form.getInputByName("query");
+ textField.setValueAttribute(searchTerm);
+ HtmlPage resultPage = (HtmlPage) button.click();
+
+ String totalHits = resultPage.getHtmlElementById("resultHits").getAttributeValue("hits");
+ return Integer.parseInt(totalHits);
+ }
+}
Added: public/yanel/trunk/src/contributions/resources/nutch/src/test/junit/org/wyona/yanel/impl/resources/NutchResourceTest.java
===================================================================
--- public/yanel/trunk/src/contributions/resources/nutch/src/test/junit/org/wyona/yanel/impl/resources/NutchResourceTest.java 2006-12-15 13:26:45 UTC (rev 20903)
+++ public/yanel/trunk/src/contributions/resources/nutch/src/test/junit/org/wyona/yanel/impl/resources/NutchResourceTest.java 2006-12-15 13:31:36 UTC (rev 20904)
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2006 Wyona
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.wyona.org/licenses/APACHE-LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wyona.yanel.impl.resources;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Reader;
+import java.io.Writer;
+import java.io.File;
+
+import org.wyona.yanel.core.Path;
+import org.wyona.yanel.core.Resource;
+import org.wyona.yanel.core.api.attributes.ModifiableV2;
+import org.wyona.yanel.core.map.Map;
+import org.wyona.yanel.core.map.Realm;
+import org.wyona.yanel.junit.AbstractYanelTest;
+
+/**
+ * Test for the XML Resource.
+ */
+public class NutchResourceTest extends AbstractYanelTest {
+
+ protected NutchResource resource;
+ protected String confDir = null;
+
+ public void setUp() throws Exception {
+ super.setUp();
+ this.testName = "Test for the NUTCH Resource";
+
+ String url = "/yanel-website/en/search.html";
+ Map map = yanel.getMap();
+ Realm realm = yanel.getMap().getRealm(url);
+ Path path = yanel.getMap().getPath(realm, url);
+ this.resource = (NutchResource)yanel.getResourceManager().getResource(null, null, realm, path);
+ confDir = this.resource.getRTD().getConfigFile().getParentFile().getAbsolutePath() +
+ File.separator + "conf" + File.separator;
+ }
+
+ public void testNutchLocalExists() throws Exception {
+ File nutchLocalFile = new File(confDir + "nutch-local.xml");
+ //System.err.println("nutch-local --> " + nutchLocalFile.getAbsolutePath());
+ assertTrue("the nutch-local dir exists: ", nutchLocalFile.isFile());
+ }
+
+ public void testCrawlDirectoryExists() throws Exception {
+ org.apache.hadoop.conf.Configuration configuration = new org.apache.hadoop.conf.Configuration();
+ java.net.URL defaultResource = new java.net.URL("file:" + confDir + "nutch-default.xml");
+ configuration.addDefaultResource(defaultResource);
+ java.net.URL finalResource = new java.net.URL("file:" + confDir + "nutch-local.xml");
+ configuration.addFinalResource(finalResource);
+ File crawlDir = new File(configuration.get("searcher.dir"));
+ //System.err.println("crawlDir --> " + crawlDir.getAbsolutePath());
+ assertTrue("crawl dir exists: ", crawlDir.exists());
+ }
+}
More information about the Yanel-commits
mailing list