Created
October 11, 2017 15:57
-
-
Save soufDev/4ef6572c0f057dc4e09973f8c31a1f2c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void createUsersForTest(int nb, List<String> groupsID) { | |
for(int i=1; i<=nb ; i++) { | |
UserDTO userDTO = new UserDTO(); | |
userDTO.setFirstName("firstname"+i); | |
userDTO.setLastName("lastname"+i); | |
userDTO.setUsername("username"+i); | |
userDTO.setPassword("12345678"); | |
Set<String> authority = new HashSet<String>(); | |
authority.add("USER_ROLE"); | |
userDTO.setAuthorities(authority); | |
userDTO.setUserProfile(createProfile(i)); | |
Double ramdom = Math.random()*(groupsID.size()); | |
int size = Integer.parseInt(ramdom.toString()); | |
userDTO.setUserGroupId(groupsID.subList(0,size)); | |
createUser(userDTO); | |
} | |
} | |
public Profile createProfile(int index) { | |
Profile profile = new Profile(); | |
profile.setLangKey("EN"); | |
profile.setImageUrl("http://localhost/media/image.png"); | |
profile.setCivility("single"); | |
profile.setSerialNumber("6897-9887-132"); | |
profile.setPhoneNumber("+213765963214"); | |
profile.setAddress("299"+index+" Kinney Street"); | |
return profile; | |
} | |
/**************************** Group ***********************************/ | |
public void createGroup(int i) { | |
GroupDTO groupDTO = new GroupDTO(); | |
groupDTO.setName("G"+i); | |
String[] tags = new String[] {"tag1", "tag2", "tag3"}; | |
groupDTO.setTags(Arrays.asList(tags)); | |
createGroup(groupDTO); | |
} | |
public void setChildren(Group group) { | |
List<Group> groups = groupRepository.findAll(); | |
Double ramdom = Math.random()*(groups.size()); | |
int size = Integer.parseInt(ramdom.toString()); | |
group.setChildrenId(groups.subList(0, size)); | |
groupRepository.save(group); | |
} | |
public List<Group> createGroups(int nb) { | |
for(int i=1; i<=nb ; i++) { | |
createGroup(i); | |
} | |
List<Group> groups = groupRepository.findAll(); | |
for(int i=0; i<groups.size() ; i++) { | |
setChildren(groups.get(i)); | |
} | |
return groupRepository.findAll(); | |
} | |
public List<String> extractGroupsID(List<Group> groups) { | |
List<String> list = new LinkedList<String>(); | |
for(Group group: groups) { | |
list.add(group.getId()); | |
} | |
return list; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment