package org.docksidestage.app.web.signin;

import org.dbflute.utflute.lastaflute.mock.TestingHtmlData;
import org.docksidestage.app.web.mypage.MypageAction;
import org.docksidestage.mylasta.action.HarborMessages;
import org.docksidestage.unit.UnitHarborTestCase;
import org.lastaflute.core.message.UserMessages;
import org.lastaflute.web.response.HtmlResponse;
import org.lastaflute.web.validation.exception.ValidationErrorException;

/**
 * @author jflute
 */
public class SigninActionTest extends UnitHarborTestCase {

    public void test_signin_success() {
        // ## Arrange ##
        SigninAction action = new SigninAction();
        inject(action);
        SigninForm form = new SigninForm();
        form.account = "Pixy";
        form.password = "sea";

        // ## Act ##
        HtmlResponse response = action.signin(form);

        // ## Assert ##
        TestingHtmlData htmlData = validateHtmlData(response);
        htmlData.assertRedirect(MypageAction.class);
    }

    public void test_signin_validationError() {
        // ## Arrange ##
        SigninAction action = new SigninAction();
        inject(action);
        SigninForm form = new SigninForm();
        form.account = "Pixy";
        form.password = "land";

        // ## Act ##
        // ## Assert ##
        assertException(ValidationErrorException.class, () -> action.signin(form)).handle(cause -> {
            UserMessages messages = cause.getMessages();
            assertTrue(messages.hasMessageOf("account", HarborMessages.ERRORS_LOGIN_FAILURE));
            HtmlResponse response = hookValidationError(cause);
            validateHtmlData(response);
            assertNull(form.password); // should cleared for security
        });
    }
}

@@ -196,24 +196,24 @@
 n.Harbor
-Messages
+HtmlPath
 ;%0Aimport
@@ -235,31 +235,37 @@
 age.
-unit.Unit
+mylasta.action.
 Harbor
-TestCase
+Messages
 ;%0Aim
@@ -277,44 +277,45 @@
 org.
-lastaflute.core.message.UserMessages
+docksidestage.unit.UnitHarborTestCase
 ;%0Aim
@@ -402,42 +402,16 @@
 ion.
-exception.ValidationErrorException
+Required
 ;%0A%0A/
@@ -1006,16 +1006,649 @@
 ionError
+_required() %7B%0A        // ## Arrange ##%0A        SigninAction action = new SigninAction();%0A        inject(action);%0A        SigninForm form = new SigninForm();%0A%0A        // ## Act ##%0A        // ## Assert ##%0A        assertValidationError(() -%3E action.signin(form)).handle(data -%3E %7B%0A            data.requiredMessageOf(%22account%22, Required.class);%0A            data.requiredMessageOf(%22password%22, Required.class);%0A            TestingHtmlData htmlData = validateHtmlData(data.hookError());%0A            htmlData.assertHtmlForward(HarborHtmlPath.path_Signin_SigninHtml);%0A        %7D);%0A    %7D%0A%0A    public void test_signin_validationError_loginFailure
 () %7B%0A   
@@ -1914,18 +1914,8 @@
 sert
-Exception(
 Vali
@@ -1929,25 +1929,9 @@
 rror
-Exception.class, 
+(
 () -
@@ -1960,21 +1960,20 @@
 .handle(
-cause
+data
  -%3E %7B%0A  
@@ -1986,88 +1986,21 @@
     
-UserMessages messages = cause.getMessages();%0A            assertTrue(messages.has
+data.required
 Mess
@@ -2052,17 +2052,16 @@
 FAILURE)
-)
 ;%0A      
@@ -2070,57 +2070,68 @@
     
-HtmlResponse response = hookValidation
+TestingHtmlData htmlData = validateHtmlData(data.hook
 Error(
-cause
+)
 );%0A 
@@ -2145,33 +2145,72 @@
     
-validateHtmlData(response
+htmlData.assertHtmlForward(HarborHtmlPath.path_Signin_SigninHtml
 );%0A 

comment about cache