Posts

Showing posts from 2011

Java equivalent to MySql and PHP SHA1

The following code snippet demonstrates Java's equivalent to PHP and MySql's SHA1 function: import java.math.BigInteger; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class SHA1Test { public static void main(String[] args){ String hashStr = null; String password = "password"; try { MessageDigest md = MessageDigest.getInstance("SHA-1"); md.update(password.getBytes()); BigInteger hash = new BigInteger(1, md.digest()); hashStr = hash.toString(16); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } System.out.println(hashStr); //outputs: 5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8 } } mysql> select sha1('password'); +------------------------------------------+ | sha1('password')                         | +------------------------------------------+ | 5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8 | +----------...

Inserting Into Sql Server Identity and Default Columns

For some reason I always try to insert default or null into Sql Server identity or default columns. So that I remember here is how to do it when not explicitly listing the columns list. When inserting into a table with an identity column, exclude the identity column from the values column list. e.g. Pretend the columns doesn't exist. When inserting into a table with a default column, use the DEFAULT keyword. DECLARE @Test TABLE( id INT IDENTITY(1,1), fname VARCHAR(30) not null, lname VARCHAR(30) not null, ts DATETIME DEFAULT GETDATE() ) INSERT INTO @Test VALUES('Joe', 'Somebody', DEFAULT) SELECT * FROM @Test GO Which results in: id fname lname ts --- ------ -------- ----------------------- 1 Joe Somebody 2011-01-30 12:37:20.353 (1 row(s) affected)

AutoItX4Java - Java AutoIt Bridge

AutoIt is a very useful automation scripting language for Microsoft Windows. It allows for GUI automation using a very simple syntax and can be useful for testing applications. It is packaged with AutoItX which supports accessing AutoIt functions through COM objects. I just created a new project on Google Code for Java AutoItX bindings. The project is called AutoItX4Java and uses the JACOB Java COM Bridge to access AutoItX functions. Currently the project is in an unstable state but hopefully as time goes on things will get better tested. Using AutoItX4Java is simple: Download JACOB . Download and install AutoIt . (or register the dll. See below) Add jacob.jar and autoitx4java.jar to your library path. Place the jacob-1.15-M4-x64.dll file in your library path. A simple example of using this library is below: File file = new File("lib", "jacob-1.15-M4-x64.dll"); //path to the jacob dll System.setProperty(LibraryLoader.JACOB_DLL_PATH, file...

Automated web testing with Java, Selenium RC, LoggingSelenium, HtmlUnit and TestNG

I used the  Selenium  web automation framework extensively for a suite of websites I had tested. Over the course of a year I had ended up with a complete automation framework for a suite of websites. This resulted in lots of project specific code. Now that I need to use Selenium for other sites I thought I would write about setting things up at a basic level which includes using HtmlUnit, Selenium, LoggingSelenium, starting the Selenium server through java and using TestNG. Getting Setup Download Selenium RC and Selenium IDE from http://seleniumhq.org/download/ . Selenium IDE will install right into Firefox as an add-on. I am using Selenium RC 1.0.3. Download LoggingSelenium from http://sourceforge.net/projects/loggingselenium/files/ Download TestNG from http://testng.org/doc/index.html Extract the files into your projects library folder and add the following 4 jars to your project: selenium-server.jar selenium-java-client-driver.jar logging-selenium-1.2.jar ...