package de.superx.common; import static de.superx.servlet.SxSQL_Server.DEFAULT_MANDANTEN_ID; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.sql.SQLException; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; /** * Class to test {@link de.superx.common.TemplateProcessor} * @author hiber * */ public class TemplateProcessorTest { private TemplateProcessor templateProcessor; @Before public void testConstructor() { this.templateProcessor = new TemplateProcessor(DEFAULT_MANDANTEN_ID); assertNotNull("TemplateProcessor initialized", this.templateProcessor); } @Ignore @Test public void testBuildTemplateObject() { // Template testTemplate = // this.templateProcessor.buildTemplateObject(templateName, template); // assertNotNull("TemplateProcessor initialized", this.templateProcessor); } @Test public void testCleanName() { final String EXPECTED_RESULT = " test_template_name"; String testTemplateName = "/test_template_name"; String result = this.templateProcessor.cleanName(testTemplateName); assertEquals("template name has been modified correctly", EXPECTED_RESULT, result); testTemplateName = "\\test_template_name"; result = this.templateProcessor.cleanName(testTemplateName); assertEquals("template name has been modified correctly", EXPECTED_RESULT, result); } @Test public void testAddSqlVarSicht() { final String EXPECTED_MESSAGE = "sqlvar mit type Sicht wird hier nicht unterstützt"; Exception expectedException = null; try { this.templateProcessor.addSqlVarSicht(null, null, null, null); }catch(Exception e) { expectedException = e; } assertNotNull("exception has been thrown", expectedException); assertTrue("exception is instance of IllegalStateException", expectedException instanceof IllegalStateException); assertEquals("exception message equals expected message", EXPECTED_MESSAGE, expectedException.getMessage()); } @Test public void testReadFromDb() { SxResultSet result = null; Exception ex = null; try { result = this.templateProcessor.readFromDb(null); } catch (SQLException e) { ex = e; } assertNull("exception has not been thrown", ex); assertNotNull("method returns new SxResultSet has been thrown", result); } private Method getMethod(String methodName, Class... parameterTypes) throws NoSuchMethodException, SecurityException { Method method = this.templateProcessor.getClass().getDeclaredMethod(methodName, parameterTypes); method.setAccessible(true); assertTrue("Method is accessible", method.isAccessible()); return method; } }