@Test
public void addManyTest() {
Center sgp = CenterRepository.add("singapore");
List<ContactDetails> contactDetailsList = new ArrayList<>();
ContactDetails contactDetails1 = new ContactDetails();
contactDetails1.email = "sathya.t@ishafoundation.org";
contactDetails1.firstName = "sathyanarayanan";
contactDetails1.lastName = "thilakan";
contactDetails1.phone = "+6598361844";
contactDetailsList.add(contactDetails1);
ContactDetails contactDetails2 = new ContactDetails();
contactDetails2.email = "ramya.c@ishafoundation.org";
contactDetails2.firstName = "ramya";
contactDetails2.lastName = "chidambaram";
contactDetailsList.add(contactDetails2);
ContactDetails contactDetails3 = new ContactDetails();
contactDetails3.email = "thulasidhar@gmail.com";
contactDetails3.firstName = "thulasidhar";
contactDetails3.phone = "+6592705371";
contactDetailsList.add(contactDetails3);
MemberRepository.addMany(contactDetailsList, sgp.id, USER_WITH_EDITMEMBER_PRIVILEGE);
Member member = MemberRepository.get("sathya.t@ishafoundation.org", SUPER_USER);
assertTrue(member != null);
assertTrue(member.contactDetails.email.equals("sathya.t@ishafoundation.org"));
assertTrue(member.contactDetails.firstName.equals("sathyanarayanan"));
assertTrue(member.contactDetails.lastName.equals("thilakan"));
assertTrue(member.contactDetails.phone.equals("+6598361844"));
assertTrue(member.owningCenter.id == sgp.id);
member = MemberRepository.get("ramya.c@ishafoundation.org", USER_WITH_EDITMEMBER_PRIVILEGE);
assertTrue(member != null);
assertTrue(member.contactDetails.email.equals("ramya.c@ishafoundation.org"));
assertTrue(member.contactDetails.firstName.equals("ramya"));
assertTrue(member.contactDetails.lastName.equals("chidambaram"));
assertTrue(member.owningCenter.id == sgp.id);
member = MemberRepository.get("thulasidhar@gmail.com", "thulasidhar@gmail.com");
assertTrue(member != null);
assertTrue(member.contactDetails.email.equals("thulasidhar@gmail.com"));
assertTrue(member.contactDetails.firstName.equals("thulasidhar"));
assertTrue(member.contactDetails.phone.equals("+6592705371"));
assertTrue(member.owningCenter.id == sgp.id);
//if an error occurs - whole transaction should be rolled back
contactDetailsList.clear();
contactDetails1 = new ContactDetails();
contactDetails1.email = "simansmile@yahoo.com";
contactDetailsList.add(contactDetails1);
contactDetails2 = new ContactDetails();
contactDetails2.email = "isha.meena@gmail.com";
contactDetailsList.add(contactDetails2);
try {
MemberRepository.addMany(contactDetailsList, 189000, USER_WITH_EDITMEMBER_PRIVILEGE);
assertTrue(false); //as center id is non existent
} catch (Exception ex) {
assertTrue(true);
}
//check whole transaction is rolled back
assertTrue(null == MemberRepository.get("simansmile@yahoo.com", "simansmile@yahoo.com"));
assertTrue(null == MemberRepository.get("isha.meena@gmail.com", "isha.meena@gmail.com"));
//privilege
contactDetailsList.clear();
contactDetails1 = new ContactDetails();
contactDetails1.email = "chandru@yahoo.com";
contactDetailsList.add(contactDetails1);
try {
MemberRepository.addMany(contactDetailsList, 189000, VALID_USER);