⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 searchtest.java

📁 simple spider 源码 better light faster java 书籍源码.
💻 JAVA
字号:
package com.develop.ss.httpunit;

import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebResponse;
import com.meterware.httpunit.WebForm;
import com.meterware.httpunit.WebLink;
import com.develop.ss.test.ConfigBean;
import junit.framework.TestCase;
import org.xml.sax.SAXException;

import java.io.IOException;
import java.beans.Introspector;
import java.beans.IntrospectionException;
import java.beans.BeanInfo;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;

public class SearchTest extends TestCase {
  private WebConversation conversation= new WebConversation();
  private ConfigBean config;

  public SearchTest(String name) {
    super(name);
  }

  protected void setUp() throws Exception {
    config = new ConfigBean();
  }

  public void doTestFindOccurences(String searchString, int expected) throws SAXException, IOException {
    WebResponse searchPage = conversation.getResponse(config.getSearchJspUrl());
    WebForm webForm = searchPage.getForms()[0];
    webForm.setParameter("query", searchString);
    WebResponse responsePage = webForm.submit();
    WebLink[] links = responsePage.getLinks();
    assertEquals(expected, links.length);
  }
  public void testFindOne() throws Exception {
    doTestFindOccurences("one", 1);
  }
  public void testFindNada() throws Exception {
    doTestFindOccurences("nada", 0);
  }
  public void testFindMany() throws Exception {
    doTestFindOccurences("SPIDER", 3);
  }

//  public void logStringProperties(Object o) throws IntrospectionException, InvocationTargetException, IllegalAccessException {
//    BeanInfo beanInfo = Introspector.getBeanInfo(o.getClass());
//    PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
//    for (int i = 0; i < propertyDescriptors.length; i++) {
//      PropertyDescriptor pd = propertyDescriptors[i];
//      Method readMethod = pd.getReadMethod();
//      if (readMethod.getReturnType() == String.class) {
//        if (readMethod.getParameterTypes().length == 0) {
//          System.out.println(readMethod.getName() + ": " + readMethod.invoke(o, new Object[0]));
//        }
//      }
//    }
//  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -