package core.framework.impl.web.service;

import core.framework.impl.web.bean.RequestBeanMapper;
import core.framework.impl.web.bean.ResponseBeanTypeValidator;
import core.framework.util.Types;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Method;

import static org.assertj.core.api.Assertions.assertThatThrownBy;

/**
 * @author neo
 */
class WebServiceInterfaceValidatorTest {
    private WebServiceInterfaceValidator validator;

    @BeforeEach
    void createWebServiceInterfaceValidator() {
        validator = new WebServiceInterfaceValidator(TestWebService.class, new RequestBeanMapper(), new ResponseBeanTypeValidator());
    }

    @Test
    void validate() {
        validator.validate();
    }

    @Test
    void validateRequestBeanType() throws NoSuchMethodException {
        Method method = TestWebService.class.getDeclaredMethod("get", Integer.class);

        assertThatThrownBy(() -> validator.validateRequestBeanType(Integer.class, method))
                .isInstanceOf(Error.class).hasMessageContaining("if it is path param, please add @PathParam");
    }

    @Test
    void validateResponseBeanType() throws NoSuchMethodException {
        Method method = TestWebService.class.getDeclaredMethod("get", Integer.class);

        assertThatThrownBy(() -> validator.validateResponseBeanType(Integer.class, method))
                .isInstanceOf(Error.class).hasMessageContaining("response bean type must be bean class");

        assertThatThrownBy(() -> validator.validateResponseBeanType(Types.map(String.class, String.class), method))
                .isInstanceOf(Error.class).hasMessageContaining("response bean type must be bean class");
    }
}

@@ -1120,16 +1120,452 @@
 Param%22);
+%0A%0A        assertThatThrownBy(() -%3E validator.validateRequestBeanType(TestEnum.class, method))%0A                .isInstanceOf(Error.class).hasMessageContaining(%22if it is path param, please add @PathParam%22);%0A%0A        assertThatThrownBy(() -%3E validator.validateRequestBeanType(Types.map(String.class, String.class), method))%0A                .isInstanceOf(Error.class).hasMessageContaining(%22request bean type must be bean class or List%3CT%3E%22);
 %0A    %7D%0A%0A
@@ -1918,24 +1918,48 @@
 e bean class
+, Optional%3CT%3E or List%3CT%3E
 %22);%0A%0A       
@@ -2169,19 +2169,80 @@
 an class
-%22);
+, Optional%3CT%3E or List%3CT%3E%22);%0A    %7D%0A%0A    enum TestEnum %7B%0A        A
 %0A    %7D%0A%7D

add unit test