added esapi config
This commit is contained in:
@ -1,7 +1,3 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package de.muehlencord.shared.util;
|
||||
|
||||
/**
|
||||
@ -10,11 +6,14 @@ package de.muehlencord.shared.util;
|
||||
*/
|
||||
public class StringEncodingException extends Exception {
|
||||
|
||||
protected final static String DEFAULT_MSG = "An encoding exception occurred";
|
||||
|
||||
/**
|
||||
* Creates a new instance of
|
||||
* <code>StringEncodingException</code> without detail message.
|
||||
*/
|
||||
public StringEncodingException() {
|
||||
super (DEFAULT_MSG);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
*/
|
||||
package de.muehlencord.shared.util;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.text.ParseException;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
@ -29,7 +30,7 @@ public abstract class StringUtil {
|
||||
try {
|
||||
byte[] b = input.getBytes("UTF-8");
|
||||
return new String(b, "ISO-8859-1");
|
||||
} catch (Exception ex) {
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
logger.debug(getStackTraceString(ex));
|
||||
throw new StringEncodingException("Cannot convert string from UTF-8 to ISO-8859-1. Reason: " + ex.getMessage(), ex);
|
||||
}
|
||||
@ -44,8 +45,8 @@ public abstract class StringUtil {
|
||||
public static String getStackTraceString(Throwable ex) {
|
||||
String logString = ex.toString() + "\n";
|
||||
StackTraceElement[] stack = ex.getStackTrace();
|
||||
for (int i = 0; i < stack.length; i++) {
|
||||
logString += (stack[i].toString()) + "\n";
|
||||
for (StackTraceElement stack1 : stack) {
|
||||
logString += (stack1.toString()) + "\n";
|
||||
}
|
||||
return logString;
|
||||
}
|
||||
|
||||
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package de.muehlencord.shared.util;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jomu
|
||||
*/
|
||||
public class OSUtilTest {
|
||||
|
||||
/**
|
||||
* executes getOS method
|
||||
*/
|
||||
@Test
|
||||
public void testGetOS() {
|
||||
String osName = System.getProperties().getProperty("os.name").toUpperCase();
|
||||
int os = OSUtil.getOperationSystem();
|
||||
|
||||
switch (osName) {
|
||||
case "LINUX":
|
||||
assertTrue(os == OSUtil.OS_LINUX);
|
||||
break;
|
||||
case "WINDOWS":
|
||||
assertTrue(os == OSUtil.OS_WINDOWS);
|
||||
break;
|
||||
default:
|
||||
fail("Unknown / unsupported OS for test case");
|
||||
}
|
||||
|
||||
System.out.println(osName);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package de.muehlencord.shared.util;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jomu
|
||||
*/
|
||||
public class StringEncodingExceptionTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void testDefaultConstructor() {
|
||||
StringEncodingException ex = new StringEncodingException();
|
||||
assertTrue (ex.getMessage().equals (StringEncodingException.DEFAULT_MSG));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageConstructor() {
|
||||
String msg = "Test message";
|
||||
StringEncodingException ex = new StringEncodingException(msg);
|
||||
assertTrue (ex.getMessage().equals (msg));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testRootcauseConstructor() {
|
||||
String msg = "Test message";
|
||||
StringEncodingException rootCause = new StringEncodingException();
|
||||
StringEncodingException ex = new StringEncodingException(msg, rootCause);
|
||||
assertTrue (ex.getMessage().equals (msg));
|
||||
assertTrue (ex.getCause().equals (rootCause));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,4 +1,3 @@
|
||||
|
||||
package de.muehlencord.shared.util;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -8,11 +7,11 @@ import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Basic StringUtilTests
|
||||
*
|
||||
* @author joern@muehlencord.de
|
||||
*/
|
||||
public class StringUtilTest extends DefaultTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetValueBetweenKeywords() throws ParseException, IOException {
|
||||
String content = readContentFromFile("test.txt");
|
||||
|
||||
Reference in New Issue
Block a user