Skip to content

Instantly share code, notes, and snippets.

@Test
public void addTodo() throws Exception {
final Todo formObject = new Todo();
formObject.setTitle("my title");
formObject.setDescription("some description");
mockMvc.perform(post("/todo/add")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.with(new RequestPostProcessor() {
@Override
ls -l | awk '{print $9}'
@dannyduc
dannyduc / MockitoSetup.java
Created October 8, 2013 16:22
Sample setup for Mockito test
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.mockito.Mockito.*;
import static org.mockito.MockitoAnnotations.*;
@RunWith(MockitoJUnitRunner.class)
public class MyAppTest {
http://www.baeldung.com/rest-with-spring-series/
public abstract class AuthenticationUtil {
public static String getUserName() {
if (isAnonymous()) {
return "anonymous";
}
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
return authentication == null ? null : authentication.getName();
}
@dannyduc
dannyduc / GatewayRequestHandler.java
Created October 2, 2013 16:37
Snippet from Google JS Test Driver. Forwards requests to another server and feeds the responses back to the client. git clone https://code.google.com/p/js-test-driver/
@Override
public void handleIt() throws IOException {
final HttpMethodBase method = getMethod(request);
addRequestHeaders(method, request);
method.setQueryString(request.getQueryString());
spoofHostHeader(method);
try {
final int statusCode = client.executeMethod(method);
response.setStatus(statusCode);
addResponseHeaders(method, response);
@dannyduc
dannyduc / HeaderContentNegotiationStrategy.java
Last active December 24, 2015 08:29
extending CasProcessingFilterEntryPoint to return 401 instead of 302 for ajax session timedout request
HttpServletRequest request = (HttpServletRequest) servletRequest;
HttpServletResponse response = (HttpServletResponse) servletResponse;
if ("XMLHttpRequest".equals(request.getHeader("X-Requested-With")) {
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
return;
}
@dannyduc
dannyduc / spring-beans.schema.xml
Last active December 24, 2015 02:39
Sample spring beans configuration file
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
</beans>
@dannyduc
dannyduc / fetchSamples.js
Created September 25, 2013 04:32
Sample jQuery code to fetch and render list of sample iReports
$(function () {
$.getJSON('https://apps.ingenuity.com/irs/data/public/samplereports?jsoncallback=?')
.done(function (samples) {
var ul = $('<ul>');
$.each(samples, function (index, sample) {
$("<li>")
.append(
$("<a>")
.attr('href', 'https://apps.ingenuity.com/ireport/data/report?reportid=' + sample.reportId)
.attr('target', '_blank')
@dannyduc
dannyduc / web.xml
Created September 24, 2013 20:56
sample 2.5 web.xml file
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
</web-app>