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;
|
package de.muehlencord.shared.util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -9,12 +5,15 @@ package de.muehlencord.shared.util;
|
|||||||
* @author joern@muehlencord.de
|
* @author joern@muehlencord.de
|
||||||
*/
|
*/
|
||||||
public class StringEncodingException extends Exception {
|
public class StringEncodingException extends Exception {
|
||||||
|
|
||||||
|
protected final static String DEFAULT_MSG = "An encoding exception occurred";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of
|
* Creates a new instance of
|
||||||
* <code>StringEncodingException</code> without detail message.
|
* <code>StringEncodingException</code> without detail message.
|
||||||
*/
|
*/
|
||||||
public StringEncodingException() {
|
public StringEncodingException() {
|
||||||
|
super (DEFAULT_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
package de.muehlencord.shared.util;
|
package de.muehlencord.shared.util;
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
@ -29,7 +30,7 @@ public abstract class StringUtil {
|
|||||||
try {
|
try {
|
||||||
byte[] b = input.getBytes("UTF-8");
|
byte[] b = input.getBytes("UTF-8");
|
||||||
return new String(b, "ISO-8859-1");
|
return new String(b, "ISO-8859-1");
|
||||||
} catch (Exception ex) {
|
} catch (UnsupportedEncodingException ex) {
|
||||||
logger.debug(getStackTraceString(ex));
|
logger.debug(getStackTraceString(ex));
|
||||||
throw new StringEncodingException("Cannot convert string from UTF-8 to ISO-8859-1. Reason: " + ex.getMessage(), 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) {
|
public static String getStackTraceString(Throwable ex) {
|
||||||
String logString = ex.toString() + "\n";
|
String logString = ex.toString() + "\n";
|
||||||
StackTraceElement[] stack = ex.getStackTrace();
|
StackTraceElement[] stack = ex.getStackTrace();
|
||||||
for (int i = 0; i < stack.length; i++) {
|
for (StackTraceElement stack1 : stack) {
|
||||||
logString += (stack[i].toString()) + "\n";
|
logString += (stack1.toString()) + "\n";
|
||||||
}
|
}
|
||||||
return logString;
|
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;
|
package de.muehlencord.shared.util;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -8,16 +7,16 @@ import org.junit.Test;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Basic StringUtilTests
|
* Basic StringUtilTests
|
||||||
|
*
|
||||||
* @author joern@muehlencord.de
|
* @author joern@muehlencord.de
|
||||||
*/
|
*/
|
||||||
public class StringUtilTest extends DefaultTest {
|
public class StringUtilTest extends DefaultTest {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetValueBetweenKeywords() throws ParseException, IOException {
|
public void testGetValueBetweenKeywords() throws ParseException, IOException {
|
||||||
String content = readContentFromFile("test.txt");
|
String content = readContentFromFile("test.txt");
|
||||||
|
|
||||||
String ipAddress = StringUtil.getValueBetweenKeywords(content, "The IP", "has just");
|
String ipAddress = StringUtil.getValueBetweenKeywords(content, "The IP", "has just");
|
||||||
assertEquals ("ipAddress", "222.184.230.118", ipAddress);
|
assertEquals("ipAddress", "222.184.230.118", ipAddress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user