Change the machine, the previous machine inside, wrote a lot of test procedures, to test the various aspects of the program. To sum up, the future of the province has been forgotten.
1.List AddAll Test
Import java.util.ArrayList;
Import java.util.List;
/**
* AddAll method to test list objects
* Summary: List of the AddAll method will be the list of the value of the past, the original list unchanged.
* @author Administrator
*
*/
public class Testlistaddall
{
public static void Main (string[] args) {
list<string> testlist = new arraylist<string> ();
for (int i=0;i<10;i++) {
Testlist.add (string.valueof (i));
}
list<string> testList2 = new arraylist<string> ();
Testlist2.addall (testlist);
System.out.println ("added List2");
for (int i=0;i<testlist2.size (); i++) {
System.out.println (Testlist2.get (i));
}
Modlist (TESTLIST2);
System.out.println ();
SYSTEM.OUT.PRINTLN ("List2 modified List1");
for (int i=0;i<testlist.size (); i++) {
System.out.println (Testlist.get (i));
}
System.out.println ();
SYSTEM.OUT.PRINTLN ("List2 modified List2");
for (int i=0;i<testlist.size (); i++) {
System.out.println (Testlist2.get (i));
}
}
public static void Modlist (List<string> List) {
for (int i=0;i<list.size (); i++) {
List.set (i, "a");
}
}
}
2. Object Initialization
/**
* Initialize default values for test member variables
* Summary: Boolean=false;int=0;float=0.0;double=0.0;object=null;
* @author Administrator
*
*/
public class Testobjectinit {
public Boolean boolobj;
public int intnum;
public float Floatnum;
public double doublenum;
Public String stringobj;
public Object obj;
public static void Main (string[] args) {
Testobjectinit testobjectinit = new Testobjectinit ();
System.out.println (Testobjectinit.boolobj);
System.out.println (Testobjectinit.intnum);
System.out.println (Testobjectinit.floatnum);
System.out.println (Testobjectinit.doublenum);
System.out.println (Testobjectinit.stringobj);
System.out.println (Testobjectinit.obj);
}
}
3.DBUnit Test
Import Java.io.FileInputStream;
Import java.sql.Connection;
Import Java.sql.DriverManager;
Import Java.sql.ResultSet;
Import java.sql.SQLException;
Import java.sql.Statement;
Import Org.dbunit.DBTestCase;
Import Org.dbunit.PropertiesBasedJdbcDatabaseTester;
Import Org.dbunit.dataset.IDataSet;
Import Org.dbunit.dataset.xml.FlatXmlDataSetBuilder;
Import org.dbunit.operation.DatabaseOperation;
Import Org.junit.Test;
/**
* Dbunit Test
* Test Results:
* 1.dbunit will change database data
* 2. The purpose of providing dbunit capability independently can be achieved by sequentially invoking setup, test, and teardown.
* 3.dbunit The database connection modification data when needed, independent of the original database connection
* @author WJX
*
*/
public class Testsql extends Dbtestcase {
@Override
Protected Databaseoperation getsetupoperation () throws Exception {
return databaseoperation.delete_all;
}
Public Testsql () {
Super ();
System.setproperty (Propertiesbasedjdbcdatabasetester.dbunit_driver_class, "com.mysql.jdbc.Driver");
System.setproperty (Propertiesbasedjdbcdatabasetester.dbunit_connection_url, "jdbc:mysql://localhost:3306/ Zshop-demo ");
System.setproperty (propertiesbasedjdbcdatabasetester.dbunit_username, "root");
System.setproperty (Propertiesbasedjdbcdatabasetester.dbunit_password, "root");
}
@Test
public void Testsql () throws SQLException, exception{
Class Driverclass = Class.forName ("Com.mysql.jdbc.Driver");
Connection jdbcconnection = drivermanager.getconnection (
"Jdbc:mysql://localhost:3306/zshop-demo", "root", "root");
Statement Statement = Jdbcconnection.createstatement ();
ResultSet rs = statement.executequery ("SELECT count (*) as NUM from ' Zshop-demo '. ' Uc_account ' LIMIT 0, 100;");
Rs.next ();
System.out.println (rs.getstring ("NUM"));
int num = rs.getint ("num");
Asserttrue (num>0);
}
@Override
Protected Idataset GetDataSet () throws Exception {
Return to New Flatxmldatasetbuilder (). Build (New FileInputStream ("Student_exp.xml"));
}
}
3.apache DDoS Module
Package Com.ceopen.wjx.test.ddos;
Import java.io.IOException;
Import Java.io.InputStream;
Import Java.net.URL;
Import java.net.URLConnection;
Import java.util.List;
Import Java.util.Map;
Import Java.util.Set;
/**
* Apache DDoS attack Prevention module test
* Test Results:
* Apache DDoS attack prevention module for the entire Apache server,
* Unable to differentiate the server site for DDoS attack prevention, if needed, can improve the original code completion needs
* @author WJX
*
*/
public class Threadgethtmlpage extends Thread {
Private String urlstring;
Public threadgethtmlpage (String URL) {
this.urlstring = URL;
}
@Override
public void Run () {
try {
Printheader ();
catch (IOException e) {
E.printstacktrace ();
}
}
private void Printheader () throws ioexception{
URL url = new URL (urlstring);
URLConnection urlconnection = Url.openconnection ();
map<string,list<string>> headers = Urlconnection.getheaderfields ();
Set<string> keyset = Headers.keyset ();
System.out.println ("URL:" +urlstring);
for (String Key:keyset) {
list<string> headervalues = Headers.get (key);
System.out.print ("Key:" +key+ "value:[");
for (String headvalue:headervalues) {
System.out.print ("" "+headvalue+");
}
System.out.println ("]");
}
InputStream input = Urlconnection.getinputstream ();
byte[] bytes = new Byte[1024*5];
Input.read (bytes);
String html = new string (bytes);
SYSTEM.OUT.PRINTLN (HTML);
System.out.println ();
System.out.println ();
}
}
4.HttpClient Test
Import java.io.IOException;
Import Org.apache.commons.httpclient.Header;
Import org.apache.commons.httpclient.HttpClient;
Import org.apache.commons.httpclient.HttpException;
Import Org.apache.commons.httpclient.URI;
Import Org.apache.commons.httpclient.methods.OptionsMethod;
Import Org.apache.commons.httpclient.methods.PostMethod;
/**
* Apache HTTP Client Test
* Send a POST request, take the result
* @author WJX
*
*/
public class MainTest01 {
/**
* @param args
* @throws IOException
* @throws HttpException
*/
public static void Main (string[] args) throws HttpException, IOException {
HttpClient httpclient = new HttpClient ();
Postmethod method = new Postmethod ("http://www.zshop186.com/Consult.do?method=create01");
Method.setparameter ("Compid", "consult_create01-103");
Method.setparameter ("ProductId", "24>%22%27>
int StatusCode = Httpclient.executemethod (method);
System.out.println ("... header ...)."...............
Header[] Headers=method.getresponseheaders ();
listif (headers!=null) {
for (Header header:headers) {
System.out.println (Header.getname () + ":" +header.getvalue ());
}
}
System.out.println ("........................... ...);
System.err.println ("Method Status:" + Method.getstatusline ());
byte[] Responsebody = Method.getresponsebody ();
String respbodystr = new string (responsebody);
System.out.println (Respbodystr.indexof ("Javascript:alert (590186)"));
System.out.println (RESPBODYSTR);
System.out.println ();
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////
Import java.io.IOException;
Import Org.apache.commons.httpclient.Header;
Import org.apache.commons.httpclient.HttpClient;
Import org.apache.commons.httpclient.HttpException;
Import Org.apache.commons.httpclient.methods.OptionsMethod;
/**
* Apache HTTP Client Test
* Send the parameter method, take the result
* @author WJX
*
*/
public class MainTest03 {
public static void Main (string[] args) throws HttpException, ioexception{
HttpClient httpclient = new HttpClient ();
Optionsmethod method = new Optionsmethod ("http://www.dyccb.net/maker/pages/");
Httpclient.executemethod (method);
Header Allowheader = (header) method.getresponseheader ("Allow");
System.out.println (Allowheader.getvalue ());
}
}
Import java.io.IOException;
Import Org.apache.commons.httpclient.Header;
Import org.apache.commons.httpclient.HttpClient;
Import org.apache.commons.httpclient.HttpException;
Import Org.apache.commons.httpclient.methods.OptionsMethod;
/**
* Apache HTTP Client Test
* Send the parameter method, take the result
* @author WJX
*
*/
public class MainTest03 {
public static void Main (string[] args) throws HttpException, ioexception{
HttpClient httpclient = new HttpClient ();
Optionsmethod method = new Optionsmethod ("http://www.dyccb.net/maker/pages/");
Httpclient.executemethod (method);
Header Allowheader = (header) method.getresponseheader ("Allow");
System.out.println (Allowheader.getvalue ());
}
}
5.im4java Test
Import Java.awt.image.BufferedImage;
Import Java.io.FileOutputStream;
Import java.io.IOException;
Import Java.io.OutputStream;
Import Javax.imageio.ImageIO;
Import Junit.framework.TestCase;
Import ORG.IM4JAVA.CORE.CONVERTCMD;
Import org.im4java.core.IM4JavaException;
Import org.im4java.core.IMOperation;
Import Org.im4java.core.Stream2BufferedImage;
/**
* Im4java Test
* Basic test, set picture size and format
* @author WJX
*
*/
public class Testim4java extends TestCase {
public void Testuseim4java () throws IOException, Interruptedexception, im4javaexception{
Create command
Stream2bufferedimage Myoutputconsumer = new Stream2bufferedimage ();
Convertcmd cmd = new Convertcmd ();
Cmd.setsearchpath ("/usr/local/imagemagick-6.5.9-0; C:/Program files/imagemagick-6.7.3-q16 ");
Create the operation, add images and operators/options
Imoperation op = new Imoperation ();
Op.addimage ();
Op.resize (800, 600);
Op.wave (10d,100d);
Op.blur (0.5D);
Op.addimage ("jpg:-");
Cmd.setoutputconsumer (Myoutputconsumer);
Execute the operation
String inputfilename= "Myimage.jpg";
String outputfilename= "Myoutputimage.jpg";
Cmd.run (Op,inputfilename);
BufferedImage bufimg = Myoutputconsumer.getimage ();
OutputStream outputstream = new FileOutputStream (outputfilename);
Imageio.write (bufimg, "JPG", outputstream);
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////
Import Java.awt.image.BufferedImage;
Import Java.io.File;
Import Java.io.FileOutputStream;
Import java.io.IOException;
Import Java.io.OutputStream;
Import Javax.imageio.ImageIO;
Import Junit.framework.TestCase;
Import ORG.IM4JAVA.CORE.CONVERTCMD;
Import org.im4java.core.IM4JavaException;
Import org.im4java.core.IMOperation;
Import Org.im4java.core.Stream2BufferedImage;
/**
* Im4java Test
* Filter test, test various filter effects
* @author WJX
*
*/
public class Testim4java6 extends TestCase {
public void Testuseim4java () throws IOException, Interruptedexception, im4javaexception{
Create command
Convertcmd cmd = new Convertcmd ();
Cmd.setsearchpath ("/usr/local/imagemagick-6.5.9-0; C:/Program files/imagemagick-6.7.3-q16 ");
Stream2bufferedimage Myoutputconsumer = new Stream2bufferedimage ();
Cmd.setoutputconsumer (Myoutputconsumer)
;
Create the operation, add images and operators/options
Imoperation op = new Imoperation ();
Op.addimage ();
Op.resize (800, 600);
Op.wave (10d,100d);
Op.blur (0.5D);
Op.noise (15.0D);
Op.addimage ("jpg:-");
Execute the operation
String inputfilename= "Myimage.jpg";
String outputfilename= "Myoutputimage3.jpg";
BufferedImage inputimage = Imageio.read (new File (InputFileName));
Cmd.run (Op,inputimage);
BufferedImage bufimg = Myoutputconsumer.getimage ();
OutputStream outputstream = new FileOutputStream (outputfilename);
Imageio.write (bufimg, "JPG", outputstream);
}
}
6. File Operation Test
Import Java.io.File;
Import Java.io.FileOutputStream;
Import java.io.IOException;
Import Java.util.Random;
/**
* Create a file of the specified size, calculated by byte
* @author WJX
*
*/
public class CreateFile {
public static long filesize=1024*1024*200;
public static String FilePath = "/usr/local/apache-tomcat-6.0.32/create_file.txt";
public static string[] Charary = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"};
public static int writesize = 1024*1024;
public static void Main (string[] args) throws ioexception{
File File=new file (FilePath);
if (!file.exists ()) {
File Filedir = new file (File.getparent ());
if (!filedir.exists ()) {
Filedir.mkdirs ();
}
File.createnewfile ();
}
Random rd = new Random (10);
FileOutputStream FileOutputStream = new FileOutputStream (file);
StringBuffer SBF = new StringBuffer ();
int size = 0;
for (int i=0;i<filesize;i++) {
int pos = Math.Abs (rd.nextint ()% 10);
Sbf.append (Charary[pos]);
size++;
if (size>writesize) {
Fileoutputstream.write (Sbf.tostring (). GetBytes ());
System.out.println ("File writed");
Sbf.delete (0, size);
size=0;
}
}
Fileoutputstream.close ();
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////
Import Java.io.File;
Import Java.io.FileInputStream;
Import java.io.IOException;
/**
* Read files
* @author WJX
*
*/
public class ReadFile {
public static String FilePath = "/usr/local/apache-tomcat-6.0.32/create_file.txt";
public static int readsize = 16;
public static void Main (string[] args) throws ioexception{
File File = new file (FilePath);
byte[] bytes = new Byte[readsize];
if (file.exists ()) {
FileInputStream fis = new FileInputStream (file);
int readlength = 0;
do{
readlength = Fis.read (bytes);
String memo = new string (bytes,0,readlength);
SYSTEM.OUT.PRINTLN ("Read file:" +readlength);
System.out.println ("File content:" +memo);
}while (readlength>=0);
Fis.close ();
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////
Import Java.io.File;
/**
* File name change
* @author WJX
*
*/
public class RenameFile {
public static String FilePath = "/usr/local/apache-tomcat-6.0.32/create_file.txt";
public static String filepathnew = "/usr/local/apache-tomcat-6.0.32/create_file_new.txt";
public static void Main (string[] args) {
File File = new file (FilePath);
File FileNew = new file (filepathnew);
if (file.exists ()) {
Boolean renamefile = File.renameto (filenew);
System.out.println ("File Rename:" +renamefile);
}else{
System.out.println ("Not found File");
}
}
}
7. System Command Call
Package com.ceopen.wjx.test.runtime;
Import Java.io.BufferedReader;
Import Java.io.InputStreamReader;
public class Runtimeexetest {
public static void Main (string[] args) throws Exception {
Process p = runtime.getruntime (). EXEC (
"C:/Program Files/imagemagick-6.7.3-q16/convert/?");
BufferedReader input = new BufferedReader (New InputStreamReader (
P.getinputstream ()));
String Line;
while (line = Input.readline ())!= null) {
System.out.println (line);
}
Input.close ();
}
}