/**
 * Copyright (c) 2013-2016, The SeedStack authors <http://seedstack.org>
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package org.seedstack.validation.internal;

import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.seedstack.seed.it.SeedITRunner;
import org.seedstack.validation.internal.pojo.*;

import javax.inject.Inject;
import javax.validation.ConstraintViolationException;

@RunWith(SeedITRunner.class)
public class ValidationPluginIT {

    @Inject
    ParamValidation serviceParam;

    @Inject
    FieldValidationOK serviceField;

    @Inject
    ParamReturnType serviceReturnType;

    @Inject
    WithoutValidation serviceWithoutValidation;

    @Test
    public void services_are_well_injected() {
        Assertions.assertThat(serviceParam).isNotNull();
        Assertions.assertThat(serviceField).isNotNull();
        Assertions.assertThat(serviceReturnType).isNotNull();
        Assertions.assertThat(serviceWithoutValidation).isNotNull();
    }

    @Test
    public void param_not_null_validations_ok() {
        serviceParam.validateNotNullParam("");
    }

    @Test(expected = ConstraintViolationException.class)
    public void param_not_null_validations_are_well_intercepted() {
        serviceParam.validateNotNullParam(null);
    }

    @Test
    public void param_valid_validations_ok() {
        serviceParam.validateValidParam(new Pojo(Pojo.State.VALID));
    }


    @Test(expected = ConstraintViolationException.class)
    public void param_valid_validations_are_well_intercepted() {
        serviceParam.validateValidParam(new Pojo(Pojo.State.INVALID));
    }

    @Test
    public void not_null_return_validations_ok() {
        serviceReturnType.validateNotNullReturn("");
    }

    @Test(expected = ConstraintViolationException.class)
    public void not_null_return_validations_are_well_intercepted() {
        serviceReturnType.validateNotNullReturn(null);
    }

    @Test
    public void valid_return_validations_ok() {
        serviceReturnType.validateValidReturn(Pojo.State.VALID);
    }

    @Test(expected = ConstraintViolationException.class)
    public void valid_return_validations_are_well_intercepted() {
        serviceReturnType.validateValidReturn(Pojo.State.INVALID);
    }

}

@@ -327,48 +327,8 @@
 l;%0A%0A
-import org.assertj.core.api.Assertions;%0A
 impo
@@ -472,92 +472,503 @@
 ojo.
-*;%0A%0Aimport javax.inject.Inject;%0Aimport javax.validation.ConstraintViolationException
+CustomPojo;%0Aimport org.seedstack.validation.internal.pojo.FieldValidationOK;%0Aimport org.seedstack.validation.internal.pojo.ParamReturnType;%0Aimport org.seedstack.validation.internal.pojo.ParamValidation;%0Aimport org.seedstack.validation.internal.pojo.Pojo;%0Aimport org.seedstack.validation.internal.pojo.WithoutValidation;%0A%0Aimport javax.inject.Inject;%0Aimport javax.validation.ConstraintViolationException;%0Aimport javax.validation.Validator;%0A%0Aimport static org.assertj.core.api.Assertions.assertThat
 ;%0A%0A@
@@ -1239,16 +1239,54 @@
 ation;%0A%0A
+    @Inject%0A    Validator validator;%0A%0A
     @Tes
@@ -1338,35 +1338,24 @@
 ) %7B%0A        
-Assertions.
 assertThat(s
@@ -1384,35 +1384,24 @@
 ();%0A        
-Assertions.
 assertThat(s
@@ -1430,35 +1430,24 @@
 ();%0A        
-Assertions.
 assertThat(s
@@ -1485,27 +1485,16 @@
         
-Assertions.
 assertTh
@@ -2807,10 +2807,229 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void custom_validator() %7B%0A        assertThat(validator.validate(new CustomPojo(%22abc%22)).size()).isEqualTo(1);%0A        assertThat(validator.validate(new CustomPojo(%22ABC%22)).size()).isEqualTo(0);%0A    %7D%0A
 %7D%0A

Add test for custom validator