package de.tse.simplerestfacade;

import static org.junit.Assert.assertEquals;

import java.lang.reflect.Method;

import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;

import org.junit.Test;

import de.tse.simplerestfacade.invocation.MethodCall;
import de.tse.simplerestfacade.invocation.MethodInformation;
import de.tse.simplerestfacade.methodinformation.MethodInformationDetector;

public class MethodInformationDetectorTest {

    public static interface TestDetectMediaType {
        
        void interfaceMethod();
    }
    
    @Test public void testDetectMediaType() {
        
        MethodInformationDetector detector = new MethodInformationDetector();
        
        MethodCall call = methodCall(TestDetectMediaType.class, "interfaceMethod", MediaType.APPLICATION_XML);
        MethodInformation info = detector.detectRestInformations(call);
        assertEquals(MediaType.APPLICATION_XML, info.getMediaType());
    }
    
    @Path("service")
    public static interface TestDetectMethodPath {
        
        @Path("/method")
        void interfaceMethod();
    }
    
    @Test public void testDetectMethoPath() {

        MethodInformationDetector detector = new MethodInformationDetector();
        
        MethodCall call = methodCall(TestDetectMethodPath.class, "interfaceMethod", MediaType.APPLICATION_XML);
        MethodInformation info = detector.detectRestInformations(call);
        
        assertEquals("service/method", info.getMethodUrl());
    }
    
    private MethodCall methodCall(final Class<?> serviceClass, final String methodName, final String mediaType, final Class<?> ...paramTypes) {
        final Method method;
        try {
            method = serviceClass.getMethod(methodName, paramTypes);
        }
        catch (NoSuchMethodException | SecurityException ex) {
            throw new RuntimeException(ex);
        }
        return new MethodCall(method, paramTypes, mediaType);
    }
}

@@ -110,32 +110,87 @@
 od;%0A
-%0Aimport javax.ws.rs.Path
+import java.util.Arrays;%0A%0Aimport javax.ws.rs.Path;%0Aimport javax.ws.rs.PathParam
 ;%0Aim
@@ -1549,147 +1549,996 @@
     
-private MethodCall methodCall(final Class%3C?%3E serviceClass, final String methodName, final String mediaType, final Class%3C?%3E ...paramTypes) %7B
+@Path(%22service%22)%0A    public static interface TestDetectMethodPathWithPathParams %7B%0A        %0A        @Path(%22/method/%7Bid%7D/%7Battribute%7D%22)%0A        void interfaceMethod(@PathParam(%22id%22) String param1, @PathParam(%22attribute%22) String param2);%0A    %7D%0A    %0A    @Test public void testDetectMethodPathWithPathParams() %7B%0A        %0A        MethodInformationDetector detector = new MethodInformationDetector();%0A        %0A        MethodCall call = methodCall(TestDetectMethodPathWithPathParams.class, %22interfaceMethod%22, MediaType.APPLICATION_XML, %221234%22, %22attribute%22);%0A        MethodInformation info = detector.detectRestInformations(call);%0A        %0A        assertEquals(%22service/method/1234/attribute%22, info.getMethodUrl());        %0A    %7D%0A%0A    private MethodCall methodCall(final Class%3C?%3E serviceClass, final String methodName, final String mediaType, final Object ...params) %7B%0A        final Class%3C?%3E%5B%5D paramTypes = Arrays.stream(params).map(param -%3E param.getClass()).toArray(value -%3E new Class%3C?%3E%5Bvalue%5D);
 %0A   
@@ -2765,32 +2765,32 @@
 (ex);%0A        %7D%0A
+
         return n
@@ -2816,20 +2816,16 @@
 d, param
-Type
 s, media

Test MethodUrl with PathParams