Skip to content

Instantly share code, notes, and snippets.

View djangofan's full-sized avatar

Jon Austen djangofan

View GitHub Profile
@djangofan
djangofan / stripAttributes.groovy
Created May 25, 2012 16:51
A Groovy script that can strip XML attributes from a XML file
:: related to this Gist: https://gist.github.com/2790685
import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.util.HashSet;
import java.util.Set;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
@djangofan
djangofan / script.bat
Created May 25, 2012 21:24
Batch script to run a Groovy script over each file found in recursive subdirectories
@ECHO off
:: https://gist.github.com/2789163
del list.txt
del list.bak
dir /s /b arrest.xml > list.txt
::FOR /F "tokens=2,3* delims=^\" %%i in (list.txt) do (
:: ECHO %%i %%j %%k
::)
@djangofan
djangofan / TLSGMailer.java
Created May 29, 2012 04:56
Java class to send a GMail email
package test.ra;
/**
* TLSGMailer class
* INFO: This class sends smtp TLS email via the Gmail service on port 587.
* The port for smtp SSL email is 465 and isn't supported by this class.
* The POP port for SSL Gmail is 995.
* Always use full email address as login id.
* AUTHOR: Jon Thor Austen, May 2012
@djangofan
djangofan / SendResults.java
Created May 29, 2012 04:57
Java class to get TestNG results ready for emailing
package test.ra;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
@djangofan
djangofan / gist:2822641
Created May 29, 2012 04:59
Code to send the email
// this method can be within any of the classes belonging to the
// group running from the suite, as configured in your testng.xml file
@AfterSuite(alwaysRun = true)
public void tearDown() throws Exception {
SendResults sr = new SendResults("frommail@gmail.com", "tomail@gmail.com", "Title email", "Message");
sr.sendTestNGResult();
}
@djangofan
djangofan / gist:2865534
Created June 4, 2012 00:08
Load a DataProvider from another class using TestNG
@Test(groups = {"all"}, dataProvider = "DPMethodAlias", dataProviderClass = DataProviders.class)
@djangofan
djangofan / gist:2865537
Created June 4, 2012 00:09
Dynamically load data into a DataProvider from a file using TestNG
@DataProvider(name = "DPMethodAlias") // Get A Form
public static Object[][] getFromFile() {
System.out.println("Loading data provider DPMethodAlias...");
// lastRun is a timestamp value used to find the .tests file
File tFile = new File( "test-output/work/" + WSUtils.getTestProperty("lastRun", "testng.config") + ".tests");
FileReader fileReader = null;
List<String> lines = new ArrayList<String>();
try {
String line = null;
fileReader = new FileReader( tFile );
@djangofan
djangofan / gist:2871851
Created June 5, 2012 01:20
Groovy script to determine max strength of all your JDK ciphers
import javax.crypto.Cipher
import java.security.*
import javax.crypto.*
// Groovy script
class SecurityTests {
static void main(String[] args) {
for (Provider provider : Security.getProviders())
{
System.out.println("Provider: " + provider.getName())
for (Provider.Service service : provider.getServices() )
@djangofan
djangofan / gist:2876130
Created June 5, 2012 16:37
Run groovy from 2 different JDK distros
@echo off
set JAVA_HOME1=C:\jdk1.6.0_31
set JAVA_HOME2=C:\jdk1.6.0_16
ECHO Listings from %JAVA_HOME1%
groovy.exe --javahome %JAVA_HOME1% SecurityListings.groovy > 31.result.txt
ECHO Listings from %JAVA_HOME2%
groovy.exe --javahome %JAVA_HOME2% SecurityListings.groovy > 16.result.txt
@djangofan
djangofan / gist:2939264
Created June 15, 2012 23:55
batch file groovy launcher
@ECHO off
:: SET JAVA_HOME=%JAVA_HOME%
SET WDIR=C:\CTemp
groovy.exe DirectoryWatcher.groovy %WDIR%
pause