Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.ly.server.application.persistence.service;
- import org.junit.Before;
- import org.junit.Test;
- import org.ly.server.application.persistence.model.accounting.ModelUser;
- import org.lyj.commons.util.CollectionUtils;
- import org.lyj.commons.util.FormatUtils;
- import org.lyj.commons.util.RandomUtils;
- import org.lyj.server.TestInitializer;
- import static org.junit.Assert.assertEquals;
- public class ServiceUserTest {
- // ------------------------------------------------------------------------
- // c o n s t
- // ------------------------------------------------------------------------
- private final String NAME = "Marco %s";
- private final String[] DATA = {"Rossi", "Bianchi", "Verdi", "Azzurri"};
- @Before
- public void setUp() throws Exception {
- TestInitializer.init();
- }
- @Test
- public void appTest() {
- long count = ServiceUser.instance().count();
- if(count <10000){
- create10000Users(NAME);
- }
- }
- // ------------------------------------------------------------------------
- // p r i v a t e
- // ------------------------------------------------------------------------
- private void create10000Users(final String name){
- //generate random alias
- for(int i=0; i<=1000; i++){
- final int n = (int)RandomUtils.rnd(0, DATA.length-1);
- final String alias = CollectionUtils.get(DATA,n,"peppapig");
- //combine with username
- final String fullname = FormatUtils.format(name,alias);
- final String email = RandomUtils.randomAlphanumericLower(8)+ "@sergiomottola.it";
- final ModelUser user = new ModelUser();
- user.name(fullname);
- user.email(email);
- System.out.println(user.name());
- ServiceUser.instance().upsert(user);
- }
- }
- @Test
- public void enumTest(){
- ServiceUser.instance().forEach((user)->{
- System.out.println(user.name());
- });
- }
- @Test
- public void alias(){
- for(final String ins : DATA) {
- String fullname = FormatUtils.format(NAME, ins);
- long count = ServiceUser.instance().countByName(fullname);
- System.out.println(fullname + ": " + count);
- }
- }
- @Test
- public void pageTest(){
- ModelUser[] userArray = ServiceUser.instance()
- .getPage(0,100)
- .toArray(new ModelUser[0]);
- assertEquals(userArray.length,100);
- ModelUser[] page1 = ServiceUser.instance()
- .getPage(0,10)
- .toArray(new ModelUser[0]);
- ModelUser[] page2 = ServiceUser.instance()
- .getPage(10,10)
- .toArray(new ModelUser[0]);
- assertEquals(page1.length,10);
- assertEquals(page2.length,10);
- for(int i = 0; i<10; i++){
- final String key_1 = userArray[i].key();
- final String key_2 = page1[i].key();
- assertEquals(key_1,key_2);
- }
- for(int i = 0; i<10; i++){
- final String key_1 = userArray[i+10].key();
- final String key_2 = page2[i].key();
- assertEquals(key_1,key_2);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement