Search in sources :

Example 1 with ResponseBody

use of org.flashframework.http.annotation.ResponseBody in project Flash by Minato262.

the class Annotation method annotation.

@SuppressWarnings("unchecked")
@Test
public void annotation() throws InvocationTargetException, IllegalAccessException {
    Annotation annotationTest = new Annotation();
    Class<Annotation> clazz = (Class<Annotation>) annotationTest.getClass();
    RequestMapping annotation = clazz.getAnnotation(RequestMapping.class);
    Assert.assertNotEquals(annotation.value(), null);
    Assert.assertEquals(annotation.value(), "annotation");
    Assert.assertNotEquals(annotation.method(), null);
    Method[] methods = clazz.getDeclaredMethods();
    for (Method method : methods) {
        if (method.isAnnotationPresent(RequestMapping.class)) {
            RequestMapping requestMapping = method.getAnnotation(RequestMapping.class);
            Assert.assertNotEquals(requestMapping, null);
            Assert.assertNotEquals(requestMapping.value(), null);
            Assert.assertNotEquals(requestMapping.method(), null);
            Assert.assertNotEquals(requestMapping.params(), null);
            Assert.assertNotEquals(requestMapping.headers(), null);
            Assert.assertNotEquals(requestMapping.consumes(), null);
            Assert.assertNotEquals(requestMapping.produces(), null);
        }
        if (method.isAnnotationPresent(ResponseBody.class)) {
            ResponseBody responseBody = method.getAnnotation(ResponseBody.class);
            Assert.assertNotEquals(responseBody, null);
        }
        Parameter[] params = method.getParameters();
        if (params.length != 0) {
            method.invoke(annotationTest, 1L);
        }
        for (Parameter param : params) {
            if (param.isAnnotationPresent(RequestParam.class)) {
                RequestParam requestParam = param.getAnnotation(RequestParam.class);
                Assert.assertNotEquals(requestParam, null);
            }
        }
    }
    System.out.println(annotationTest.getGetId());
    System.out.println(annotationTest.getPostId());
    System.out.println(annotationTest.getPutId());
    System.out.println(annotationTest.getDeleteId());
    System.out.println(annotationTest.getHandler());
}
Also used : Parameter(java.lang.reflect.Parameter) RequestMethod(org.flashframework.http.RequestMethod) Method(java.lang.reflect.Method) ResponseBody(org.flashframework.http.annotation.ResponseBody) Test(org.junit.Test)

Aggregations

Method (java.lang.reflect.Method)1 Parameter (java.lang.reflect.Parameter)1 RequestMethod (org.flashframework.http.RequestMethod)1 ResponseBody (org.flashframework.http.annotation.ResponseBody)1 Test (org.junit.Test)1