View Javadoc
1   package fr.ifremer.dali.service.control;
2   
3   import fr.ifremer.dali.config.DaliConfiguration;
4   import fr.ifremer.dali.dao.DaliDatabaseResource;
5   import fr.ifremer.dali.service.DaliServiceLocator;
6   import org.apache.commons.lang3.mutable.MutableInt;
7   import org.junit.Assert;
8   import org.junit.Before;
9   import org.junit.ClassRule;
10  import org.junit.Test;
11  
12  /**
13   * @author peck7 on 02/01/2019.
14   */
15  public class RuleListServiceTest {
16  
17      @ClassRule
18      public static final DaliDatabaseResource dbResource = DaliDatabaseResource.readDb();
19  
20      private RuleListService service;
21  
22      private DaliConfiguration config;
23  
24      static final String SMALL_STRING = "SMALL_STRING";
25      static final String LONG_STRING = "LONG_STRING_123456789012346579801234567890";
26  
27      @Before
28      public void setUp() {
29          service = DaliServiceLocator.instance().getRuleListService();
30          config = DaliConfiguration.getInstance();
31      }
32  
33      @Test
34      public void getNextRuleCode() {
35  
36          String smallString = SMALL_STRING;
37          String longString = LONG_STRING;
38  
39          MutableInt index = service.getUniqueMutableIndex();
40          String newCode = service.getNextRuleCode(smallString, index);
41          Assert.assertEquals(SMALL_STRING, smallString);
42          Assert.assertNotNull(newCode);
43          Assert.assertTrue(newCode.length() < 40);
44          Assert.assertEquals(String.format("%S_%s", smallString, index.getValue() - 1), newCode);
45  
46          newCode = service.getNextRuleCode(longString, index);
47          Assert.assertEquals(LONG_STRING, longString);
48          Assert.assertNotNull(newCode);
49          Assert.assertEquals(40, newCode.length());
50          Assert.assertEquals(String.format("%s_%s", longString.substring(0, 29), index.getValue() - 1), newCode);
51      }
52  
53  }