package eu.alfred.recommendation_engine;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import eu.alfred.personalization_manager.model.*;
import org.junit.Before;
import org.junit.Test;
import eu.alfred.event_manager.client.EventManagerClient;
import eu.alfred.event_manager.model.AnalyticsParameters;
import eu.alfred.event_manager.model.Event;
import eu.alfred.event_manager.model.Organizer;
import eu.alfred.event_manager.model.Tickets;
import eu.alfred.event_manager.model.Venue;
import eu.alfred.personalization_manager.client.PersonalProfileClient;
import eu.alfred.personalization_manager.client.UserContactsClient;
import static org.junit.Assert.*;
public class FriendsBasedEventsFinderTests {
private Event testEventA = new Event();
private EventManagerClient emClient = new EventManagerClient();
private String eventAID;
private Event event1Created;
private Date d;
// TestUser
private UserProfile testUser = new UserProfile();
private UserProfile createdTestUser = new UserProfile();
private String testUserId;
// Contact 1
private UserProfile user1 = new UserProfile();
private UserProfile createdUser1 = new UserProfile();
private String user1Id;
// Contact 2
private UserProfile user2 = new UserProfile();
private UserProfile createdUser2 = new UserProfile();
private String user2Id;
// Contact 3
private UserProfile user3 = new UserProfile();
private UserProfile createdUser3 = new UserProfile();
private String user3Id;
// Contact 4
private UserProfile user4 = new UserProfile();
private UserProfile createdUser4 = new UserProfile();
private String user4Id;
private PersonalProfileClient ppClient = new PersonalProfileClient();
private UserContactsClient usClient = new UserContactsClient();
private FriendsBasedEventsFinder friendsBasedFinder = new FriendsBasedEventsFinder();
@Before
public void setup() {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_YEAR, 2);
d = cal.getTime();
// Create a user and another user as a friend contact
testUser.setAlfredUserName("swen");
testUser.setFirstName("Swen");
testUser.setLastName("Papst");
Address testUserAddress = new Address();
testUserAddress.setCity("Munich");
testUser.setResidentialAddress(testUserAddress);
testUser.setInterests(new String[] {"music","opera"});
testUser.setDateOfBirth(new Date(Long.parseLong("-630374400000")));
testUser.setMobilePhone("03591 23 12 27");
testUser.setEmail("SwenPapst@cuvox.de");
testUser.setMobilityLevel(MobilityLevel.HEALTHY);
testUserId = ppClient.createUserProfile(testUser);
createdTestUser = (UserProfile)ppClient.retrieveUserProfile(testUserId).get(0);
// Contact 1
user1.setAlfredUserName("peter");
user1.setFirstName("Peter");
user1.setLastName("Merz");
user1.setMobilePhone("00491727759581");
user1.setEmail("Peter.Merz@tiekinetix.com");
Address user1Address = new Address();
testUserAddress.setCity("Munich");
user1.setResidentialAddress(user1Address);
user1.setInterests(new String[] {"music","opera"});
user1.setDateOfBirth(new Date(Long.parseLong("-535680000000")));
user1Id = ppClient.createUserProfile(user1);
createdUser1 = (UserProfile)ppClient.retrieveUserProfile(user1Id).get(0);
Contact userContact = new Contact();
userContact.setContactsAlfredId(user1Id);
userContact.setAlfredUserName("peter");
userContact.setFirstName("Peter");
userContact.setLastName("Merz");
userContact.setPhone("00491727759581");
userContact.setEmail("Peter.Merz@tiekinetix.com");
userContact.setResidentialAddress(user1Address);
userContact.setRelationToUser(new Relation[] {Relation.FRIEND});
usClient.createUserContact(testUserId, userContact);
// Contact 2
user2.setAlfredUserName("deniz");
user2.setFirstName("Deniz");
user2.setLastName("Coskun");
user2.setMobilePhone("00491771708328");
user2.setEmail("Deniz.Coskun@tiekinetix.com");
Address user2Address = new Address();
testUserAddress.setCity("Munich");
user2.setResidentialAddress(user2Address);
user2.setInterests(new String[] {"music","opera"});
user2.setDateOfBirth(new Date(Long.parseLong("-535680000000")));
user2Id = ppClient.createUserProfile(user2);
createdUser2 = (UserProfile)ppClient.retrieveUserProfile(user2Id).get(0);
Contact userContact2 = new Contact();
userContact2.setContactsAlfredId(user2Id);
userContact2.setAlfredUserName("deniz");
userContact2.setFirstName("Deniz");
userContact2.setLastName("Coskun");
userContact2.setPhone("00491726391814");
userContact2.setEmail("Deniz.Coskun@tiekinetix.com");
userContact2.setResidentialAddress(user2Address);
userContact2.setRelationToUser(new Relation[] {Relation.FRIEND});
usClient.createUserContact(testUserId, userContact2);
// Contact 3
user3.setAlfredUserName("lill");
user3.setFirstName("Robert");
user3.setLastName("Lill");
user3.setMobilePhone("004915209119016");
user3.setEmail("Robert.Lill@tiekinetix.com");
Address user3Address = new Address();
testUserAddress.setCity("Munich");
user3.setResidentialAddress(user3Address);
user3.setInterests(new String[] {"music","opera"});
user3.setDateOfBirth(new Date(Long.parseLong("-535680000000")));
user3Id = ppClient.createUserProfile(user3);
createdUser3 = (UserProfile)ppClient.retrieveUserProfile(user3Id).get(0);
Contact userContact3 = new Contact();
userContact3.setContactsAlfredId(user3Id);
userContact3.setAlfredUserName("lill");
userContact3.setFirstName("Robert");
userContact3.setLastName("Lill");
userContact3.setPhone("004915209119016");
userContact3.setEmail("Robert.Lill@tiekinetix.com");
userContact3.setResidentialAddress(user3Address);
userContact3.setRelationToUser(new Relation[] {Relation.FRIEND});
usClient.createUserContact(testUserId, userContact3);
// Contact 4
user4.setAlfredUserName("arian");
user4.setFirstName("Arian");
user4.setLastName("Kuschki");
user4.setMobilePhone("004915222619029");
user4.setEmail("Arian.Kuschki@tiekinetix.com");
Address user4Address = new Address();
testUserAddress.setCity("Munich");
user4.setResidentialAddress(user4Address);
user4.setInterests(new String[] {"music","opera"});
user4.setDateOfBirth(new Date(Long.parseLong("-535680000000")));
user4Id = ppClient.createUserProfile(user4);
createdUser4 = (UserProfile)ppClient.retrieveUserProfile(user4Id).get(0);
Contact userContact4 = new Contact();
userContact4.setContactsAlfredId(user4Id);
userContact4.setAlfredUserName("arian");
userContact4.setFirstName("Arian");
userContact4.setLastName("Kuschki");
userContact4.setPhone("004915222619029");
userContact4.setEmail("Arian.Kuschki@tiekinetix.com");
userContact4.setResidentialAddress(user4Address);
userContact4.setRelationToUser(new Relation[] {Relation.FRIEND});
usClient.createUserContact(testUserId, userContact4);
// create some events
eventAID = "1_event-" + UUID.randomUUID().toString();
testEventA.setEventID(eventAID);
testEventA.setTags(Arrays.asList(new String[] {"music","opera"}));
testEventA.setCategories(Arrays.asList(new String[] {"N.A."}));
Venue venueA = new Venue();
venueA.setCity("Utrecht");
testEventA.setVenue(venueA);
testEventA.setStart_date(d);
testEventA.setEnd_date(d);
Organizer tasos = new Organizer();
tasos.setName("Tasos");
testEventA.setOrganizer(tasos);
testEventA.setStatus("Live");
testEventA.setTickets(Arrays.asList(new Tickets[] {}));
event1Created = emClient.addEvent(testEventA);
// add friends as participants to the events
emClient.addParticipant(event1Created.getEventID(), user1Id);
emClient.addParticipant(event1Created.getEventID(), user2Id);
emClient.addParticipant(event1Created.getEventID(), user3Id);
emClient.addParticipant(event1Created.getEventID(), user4Id);
}
@Test
public void testFindingEventsWithFriendsParticipating() {
try {
friendsBasedFinder.getEventsMyFriendsAlsoJoin(createdTestUser.getId());
assertTrue(friendsBasedFinder.getEventsMyFriendsAlsoJoin(createdTestUser.getId()).contains(event1Created));
} catch (Exception e) {
e.printStackTrace();
}
}
}