HttpClient + TestNG Interface Automatic Test fourth chapter

Source: Internet
Author: User
Tags testng

1. The client passes the data in JSON format to the server, and now provides a HASHMAP to JSON format data method

  Public StaticString Hashjson (hashmap<string, string>map) {String String= "[{";  for(iterator<entry<string, string>> it =Map.entryset (). iterator (); It.hasnext ();) {Entry<string, string> e = (entry<string, string>) It.next (); String+ = "'" + e.getkey () + "':"; String+ = "'" + e.getvalue () + "',"; } string= string.substring (0, String.LastIndexOf (",")); String+= "}]"; returnstring; }  

2. Get a specific date format method

 Public classTimesimple { Public StaticString gettimesimple () {SimpleDateFormat SDF=NewSimpleDateFormat ("Yyyymmddhhmmsssss"); returnSdf.format (NewDate ()); }         Public StaticString getdatasimple () {SimpleDateFormat SDF=NewSimpleDateFormat ("Yyyy-mm-dd"); returnSdf.format (NewDate ()); }}

3. Connect the Database method

     Public Staticstring Query (String database, String tablename, String coulmn) {Connection conn=NULL;        String SQL; intCinemaid = 0; Try{class.forname ("Com.mysql.jdbc.Driver"); System.out.println ("Load MySQL driver successfully"); Conn=(Connection) drivermanager.getconnection (URL); Statement stmt=(Statement) conn.createstatement (); SQL= "SELECT * from" + database + "where" + tablename + "= '" + coulmn + "'";            SYSTEM.OUT.PRINTLN (SQL); ResultSet RS=(ResultSet) stmt.executequery (SQL); if(Rs.next ()) {Cinemaid= Rs.getint ("id"); }    Else{System.out.println ("No Cinema ID is queried"); }                    } Catch(Exception e) {System.out.println ("MySQL Operation Error");        E.printstacktrace (); }finally {            Try{conn.close (); } Catch(SQLException e) {e.printstacktrace (); }} System.out.println (Cinemaid+ ""); returnstring.valueof (Cinemaid); }    

HttpClient + TestNG Interface Automatic Test fourth chapter

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.