Skip to content
Snippets Groups Projects
Commit 782bc304 authored by Paul-Christian Volkmer's avatar Paul-Christian Volkmer
Browse files

Removed type target definition

parent 82501e49
No related merge requests found
......@@ -5,7 +5,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ ElementType.TYPE, ElementType.METHOD })
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface CacheControl {
enum Policy {
......
package de.thm.arsnova.web;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface DeprecatedApi {
}
package de.thm.arsnova.web;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
@Component
public class DeprecatedApiInterceptorHandler extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(
HttpServletRequest request,
HttpServletResponse response,
Object handler) throws Exception {
if (getDeprecatedApiAnnotation(request, response, handler) != null) {
response.addHeader("X-Deprecated-Api", "1");
}
return super.preHandle(request, response, handler);
}
private DeprecatedApi getDeprecatedApiAnnotation(
HttpServletRequest request,
HttpServletResponse response,
Object handler
) {
if (handler == null || !(handler instanceof HandlerMethod)) {
return null;
}
final HandlerMethod handlerMethod = (HandlerMethod) handler;
return handlerMethod.getMethodAnnotation(DeprecatedApi.class);
}
}
......@@ -47,6 +47,13 @@ public class StatisticsControllerTest {
.andExpect(content().string("0"));
}
@Test
public final void testShouldSendXDeprecatedApiForGetCurrentOnlineUsers() throws Exception {
mockMvc.perform(get("/statistics/activeusercount"))
.andExpect(status().isOk())
.andExpect(header().string(AbstractController.X_DEPRECATED_API,"1"));
}
@Test
public final void testShouldGetSessionCount() throws Exception {
mockMvc.perform(get("/statistics/sessioncount"))
......@@ -54,6 +61,13 @@ public class StatisticsControllerTest {
.andExpect(content().string("3"));
}
@Test
public final void testShouldSendXDeprecatedApiForGetSessionCount() throws Exception {
mockMvc.perform(get("/statistics/sessioncount"))
.andExpect(status().isOk())
.andExpect(header().string(AbstractController.X_DEPRECATED_API,"1"));
}
@Test
public final void testShouldGetStatistics() throws Exception {
mockMvc.perform(get("/statistics"))
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment