package com.axelor.apps.base.test;

import com.axelor.app.AxelorModule;
import com.axelor.apps.base.module.AdminModule;
import com.axelor.apps.base.module.BaseModule;
import com.axelor.apps.base.service.user.UserService;
import com.axelor.apps.base.test.UserServiceTest.MyModule;
import com.axelor.apps.message.module.MessageModule;
import com.axelor.apps.tool.module.ToolModule;
import com.axelor.inject.Beans;
import com.axelor.test.GuiceModules;
import com.axelor.test.GuiceRunner;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(GuiceRunner.class)
@GuiceModules({MyModule.class})
public class UserServiceTest {

  static UserService userService;

  public static class MyModule extends AxelorModule {

    @Override
    protected void configure() {
      bind(Beans.class).asEagerSingleton();
      install(new ToolModule());
      install(new MessageModule());
      install(new AdminModule());
      install(new BaseModule());
    }
  }

  @BeforeClass
  public static void setUpBeforeClass() throws Exception {
    userService = Beans.get(UserService.class);
  }

  @Test
  public void testMatchPasswordPatternUpperLowerDigit() {
    Assert.assertTrue(userService.matchPasswordPattern("Axelor123"));
    Assert.assertTrue(userService.matchPasswordPattern("123Axelor"));
    Assert.assertTrue(userService.matchPasswordPattern("axelor123A"));
  }
  
  @Test
  public void testMatchPasswordPatternUpperLowerSpecial() {
    Assert.assertTrue(userService.matchPasswordPattern("Axelor12"));
    Assert.assertTrue(userService.matchPasswordPattern("123Axelor"));
    Assert.assertTrue(userService.matchPasswordPattern("axelor123A"));
  }
  
  @Test
  public void testMatchPasswordPatternLowerSpecialDigit() {
    Assert.assertTrue(userService.matchPasswordPattern(";axelor12"));
    Assert.assertTrue(userService.matchPasswordPattern("axelor12?"));
    Assert.assertTrue(userService.matchPasswordPattern("axelor123A"));
  }
  
  @Test
  public void testMatchPasswordPatternUpperSpecialDigit() {
    Assert.assertTrue(userService.matchPasswordPattern("AXELOR12!"));
    Assert.assertTrue(userService.matchPasswordPattern("123!AXELOR"));
    Assert.assertTrue(userService.matchPasswordPattern(";XELOR123"));
  }

  @Test
  public void testNotMatchPasswordPattern() {
    Assert.assertFalse(userService.matchPasswordPattern("Xlr1!"));
    Assert.assertFalse(userService.matchPasswordPattern("AxelorAxelor"));
    Assert.assertFalse(userService.matchPasswordPattern("axelor123456"));
  }

}

@@ -1410,34 +1410,32 @@
 lor123A%22));%0A  %7D%0A
-  
 %0A  @Test%0A  publi
@@ -1545,26 +1545,26 @@
 tern(%22Axelor
-12
+=%5B
 %22));%0A    Ass
@@ -1604,35 +1604,34 @@
 asswordPattern(%22
-123
+%5D-
 Axelor%22));%0A    A
@@ -1679,35 +1679,34 @@
 dPattern(%22axelor
-123
+%5C%22
 A%22));%0A  %7D%0A  %0A  @
@@ -1691,34 +1691,32 @@
 elor%5C%22A%22));%0A  %7D%0A
-  
 %0A  @Test%0A  publi
@@ -1983,18 +1983,16 @@
 ));%0A  %7D%0A
-  
 %0A  @Test
@@ -2258,32 +2258,325 @@
 XELOR123%22));%0A  %7D
+%0A  %0A  @Test%0A  public void testMatchPasswordPatternUpperLowerSpecialDigit() %7B%0A    Assert.assertTrue(userService.matchPasswordPattern(%22Axelor!12%22));%0A    Assert.assertTrue(userService.matchPasswordPattern(%22123Axe+lor%22));%0A    Assert.assertTrue(userService.matchPasswordPattern(%22ax%5Belor123A%22));%0A  %7D
 %0A%0A  @Test%0A  publ
@@ -2677,16 +2677,18 @@
 n(%22Xlr1!
+2*
 %22));%0A   
@@ -2836,11 +2836,10 @@
 ));%0A  %7D%0A
-%0A
 %7D%0A

improve unitary tests.