This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.openqa.selenium.By; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.firefox.FirefoxDriver; | |
public class FileUploadTest { | |
private static WebDriver driver; | |
@BeforeClass | |
public static void setUpBeforeClass() throws Exception { | |
driver = new FirefoxDriver(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.dbunit.*; | |
public class DbUnitSampleTest extends DatabaseTestCase { | |
@Override | |
protected IDatabaseConnection getConnection() throws Exception { | |
Class.forName("com.mysql.jdbc.Driver"); | |
Connection jdbcConn = DriverManager.getConnection( | |
"jdbc:mysql://localhost:3306/sample1", "user", "pass"); | |
return new DatabaseConnection(jdbcConn); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE configuration> | |
<project basedir="." default="all" name="sample"> | |
<property name="db.user" value="root" /> | |
<property name="db.pass" value="root" /> | |
<property name="db.host" value="localhost" /> | |
<property name="db.port" value="3306" /> | |
<property name="db.name" value="sample1" /> | |
<property name="db.charset" value="utf8" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function resizeContents() { | |
var contentsElem = document.getElementById("contents"), | |
headerElem = document.getElementById("header"), | |
parentH = contentsElem.offsetParent.clientHeight, | |
headerH = headerElem.offsetHeight, | |
paddingH = 10 * 2; | |
try { | |
contentsElem.style.height = (parentH - headerH - paddingH) + "px"; | |
} catch (e) { | |
// ignore error |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File execute7Zip(String workDir, String baseName, String wildCard) { | |
String path = "C:\\Program Files\\7-Zip\\7z.exe"; | |
WindowsCommandUtils.executeCommand( | |
new ProcessBuilder(path, "a", "-sfx7z.sfx", baseName, wildCard) | |
.directory(new File(workDir))); | |
return new File(workDir, baseName + ".exe"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class WindowsCommandUtils { | |
public static void executeCommand(ProcessBuilder builder) { | |
ProcessResult result = executeAndCollectResult(builder); | |
validateProcessResult(result); | |
} | |
/** | |
* For Windows Scripting Host. (VBScript, etc.) | |
*/ | |
public static void executeWshScript(File file, File workDir, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.commons.io.IOUtils; | |
public static File copyResourceFile(String dir, String name, Class<?> clazz) throws IOException { | |
File file = new File(dir, name); | |
InputStream in = null; | |
OutputStream out = null; | |
try { | |
in = clazz.getResourceAsStream(name); | |
out = new FileOutputStream(file); | |
IOUtils.copy(in, out); | |
} finally { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TempDir { | |
private final File dir; | |
public TempDir(String prefix) { | |
String name = prefix + "_" + UUID.randomUUID().toString(); | |
dir = new File(System.getProperty("java.io.tmpdir"), name); | |
boolean success = dir.mkdir(); | |
if (!success) { | |
throw new RuntimeException(dir.getPath()); | |
} | |
dir.deleteOnExit(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@WebFilter(urlPatterns = { "/*" }) | |
public class LoginFilter implements Filter { | |
private static final String URL_LOGIN = "/login/"; | |
private static final String[] URL_EXCLUDES = {URL_LOGIN, "/common/"}; | |
private static final String ATTR_LOGIN = "login"; | |
private static final String ATTR_ORIGIN_URL = "originUrl"; | |
@Override | |
public void doFilter(ServletRequest request, ServletResponse response, | |
FilterChain chain) throws IOException, ServletException { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CharacterEncodingFilter implements Filter { | |
public void doFilter(ServletRequest request, ServletResponse response, | |
FilterChain chain) throws IOException, ServletException { | |
HttpServletRequest httpReq = (HttpServletRequest) request; | |
if ("POST".equalsIgnoreCase(httpReq.getMethod())) { | |
request.setCharacterEncoding("Windows-31J"); | |
} | |
chain.doFilter(request, response); | |
} | |
} |