diff --git a/sharepoint/api/src/test/java/de/muehlencord/shared/sharepoint/api/BaseTest.java b/sharepoint/api/src/test/java/de/muehlencord/shared/sharepoint/api/BaseTest.java new file mode 100644 index 0000000..b707a1c --- /dev/null +++ b/sharepoint/api/src/test/java/de/muehlencord/shared/sharepoint/api/BaseTest.java @@ -0,0 +1,88 @@ +package de.muehlencord.shared.sharepoint.api; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; +import java.net.MalformedURLException; +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.xml.bind.JAXBException; +import org.junit.Before; + +/** + * + * @author jomu + */ +public class BaseTest { + + protected SPContext context = null; + + @Before + public void init() throws MalformedURLException, NoSuchAlgorithmException, KeyManagementException, JAXBException { + // FIXME - needs to be implemented using mock; replace with real data but make sure password is not commited + NtlmAuthenticator credentials = null; + context = null; + } + + /** + * reads a file availabe in the test source path and returns its content + * + * @param fileName fhe filename to read. This is the name realative to the path of class calling this method (the JUnit testclass) + * @param encoding the encoding to use while reading + * @return the filecontent as string + * + * @throws java.io.UnsupportedEncodingException + */ + public static String readFileContentFromTest(String fileName, String encoding) throws UnsupportedEncodingException, IOException { + StringBuilder sb = new StringBuilder(); + InputStreamReader irs = null; + InputStream is = null; + BufferedReader br = null; + String line = null; + try { + is = BaseTest.class.getResourceAsStream(fileName); + irs = new InputStreamReader(is, encoding); + br = new BufferedReader(irs); + while (null != (line = br.readLine())) { + sb.append(line); + sb.append("\n"); + } + } catch (UnsupportedEncodingException ex) { + Logger.getLogger(BaseTest.class.getName()).log(Level.SEVERE, null, ex); + throw ex; + } catch (IOException ioex) { + Logger.getLogger(BaseTest.class.getName()).log(Level.SEVERE, null, ioex); + throw ioex; + } finally { + try { + if (br != null) { + br.close(); + } + } catch (IOException ex) { + Logger.getLogger(BaseTest.class.getName()).log(Level.SEVERE, null, ex); + } + + try { + if (irs != null) { + irs.close(); + } + } catch (IOException ex) { + Logger.getLogger(BaseTest.class.getName()).log(Level.SEVERE, null, ex); + } + try { + if (is != null) { + is.close(); + } + } catch (IOException ex) { + Logger.getLogger(BaseTest.class.getName()).log(Level.SEVERE, null, ex); + } + } + + return sb.toString(); + } + +}