You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
2.0 KiB
70 lines
2.0 KiB
package de.superx.masken; |
|
|
|
import static org.junit.Assert.assertNotNull; |
|
import static org.junit.Assert.assertTrue; |
|
import static org.junit.Assert.fail; |
|
import static org.mockito.Mockito.atLeast; |
|
import static org.mockito.Mockito.mock; |
|
import static org.mockito.Mockito.verify; |
|
import static org.mockito.Mockito.when; |
|
|
|
import java.io.File; |
|
import java.io.IOException; |
|
import java.io.PrintWriter; |
|
|
|
import jakarta.servlet.http.HttpServletRequest; |
|
import jakarta.servlet.http.HttpServletResponse; |
|
|
|
import org.apache.commons.io.FileUtils; |
|
import org.junit.Ignore; |
|
import org.junit.Test; |
|
|
|
import de.superx.servlet.SuperXmlTabelle; |
|
|
|
/** |
|
* Vorerst ein Beispiel wie Servlets zukünftig mit Mockito getestet werden könnten. |
|
* Die muss noch näher analysiert werden. |
|
* @author grall |
|
* |
|
*/ |
|
public class ZULMaskenTest { |
|
|
|
@Ignore |
|
@Test |
|
public void testServlet() { |
|
HttpServletRequest request = mock(HttpServletRequest.class); |
|
HttpServletResponse response = mock(HttpServletResponse.class); |
|
assertNotNull(request); |
|
|
|
when(request.getParameter("username")).thenReturn("sander"); |
|
when(request.getParameter("password")).thenReturn("sander!"); |
|
when(request.getParameter("tid")).thenReturn("26020"); |
|
PrintWriter writer = null; |
|
try { |
|
writer = new PrintWriter("result.txt"); |
|
|
|
when(response.getWriter()).thenReturn(writer); |
|
|
|
new SuperXmlTabelle().doPost(request, response); |
|
|
|
verify(request, atLeast(1)).getParameter("username"); // only if you want to verify username was called... |
|
writer.flush(); |
|
} catch (Exception e) { |
|
e.printStackTrace(); |
|
fail(e.toString()); |
|
|
|
} finally { |
|
if (writer != null) { |
|
writer.close(); |
|
} |
|
} |
|
try { |
|
assertTrue(FileUtils.readFileToString(new File("result.txt"), "UTF-8").contains("My Expected String")); |
|
} catch (IOException e) { |
|
fail(e.toString()); |
|
} |
|
|
|
} |
|
|
|
|
|
}
|
|
|