use of org.opencastproject.usertracking.api.UserAction in project opencast by opencast.
the class UserActionImplTest method testBackwardLength.
/**
* Ensures a negative length user action calculates its length correctly.
*/
@Test
public void testBackwardLength() {
UserSession us = new UserSessionImpl();
us.setSessionId("4");
us.setUserId("testing user");
us.setUserIp("127.0.0.1");
UserAction ua = new UserActionImpl();
ua.setId(4L);
ua.setInpoint(100);
ua.setIsPlaying(true);
ua.setMediapackageId("false");
ua.setOutpoint(90);
ua.setSession(us);
ua.setType("test");
Assert.assertEquals(new Long(4), ua.getId());
Assert.assertEquals(100, ua.getInpoint());
Assert.assertEquals(true, ua.getIsPlaying());
Assert.assertEquals("false", ua.getMediapackageId());
Assert.assertEquals(90, ua.getOutpoint());
Assert.assertEquals("4", ua.getSession().getSessionId());
Assert.assertEquals("test", ua.getType());
Assert.assertEquals("testing user", ua.getSession().getUserId());
Assert.assertEquals("127.0.0.1", ua.getSession().getUserIp());
Assert.assertEquals(-10, ua.getLength());
}
use of org.opencastproject.usertracking.api.UserAction in project opencast by opencast.
the class UserActionListImplTest method testBasicAddition.
/**
* Tests that adding events to a UserActionList works using the basic .add method
*/
@Test
public void testBasicAddition() {
UserSession us1 = new UserSessionImpl();
us1.setSessionId("4");
us1.setUserId("testing user");
us1.setUserIp("127.0.0.1");
UserSession us2 = new UserSessionImpl();
us2.setSessionId("6");
us2.setUserId("testing user 2");
us2.setUserIp("127.0.0.5");
UserAction ua1 = new UserActionImpl();
ua1.setId(4L);
ua1.setInpoint(90);
ua1.setIsPlaying(true);
ua1.setMediapackageId("false");
ua1.setOutpoint(100);
ua1.setSession(us1);
ua1.setType("test");
UserAction ua2 = new UserActionImpl();
ua2.setId(6L);
ua2.setInpoint(5);
ua2.setIsPlaying(false);
ua2.setMediapackageId("other");
ua2.setOutpoint(20);
ua2.setSession(us2);
ua2.setType("other test");
UserActionList ual1 = new UserActionListImpl();
ual1.add(ua1);
ual1.setTotal(1);
Assert.assertEquals(1, ual1.getTotal());
Assert.assertEquals(1, ual1.getUserActions().size());
Assert.assertEquals(new Long(4), ual1.getUserActions().get(0).getId());
Assert.assertEquals(90, ual1.getUserActions().get(0).getInpoint());
Assert.assertEquals(true, ual1.getUserActions().get(0).getIsPlaying());
Assert.assertEquals("false", ual1.getUserActions().get(0).getMediapackageId());
Assert.assertEquals(100, ual1.getUserActions().get(0).getOutpoint());
Assert.assertEquals("4", ual1.getUserActions().get(0).getSession().getSessionId());
Assert.assertEquals("test", ual1.getUserActions().get(0).getType());
Assert.assertEquals("testing user", ual1.getUserActions().get(0).getSession().getUserId());
Assert.assertEquals("127.0.0.1", ual1.getUserActions().get(0).getSession().getUserIp());
Assert.assertEquals(10, ual1.getUserActions().get(0).getLength());
UserActionList ual2 = new UserActionListImpl();
ual2.add(ua2);
ual2.setTotal(1);
Assert.assertEquals(1, ual2.getTotal());
Assert.assertEquals(1, ual2.getUserActions().size());
Assert.assertEquals(new Long(6), ual2.getUserActions().get(0).getId());
Assert.assertEquals(5, ual2.getUserActions().get(0).getInpoint());
Assert.assertEquals(false, ual2.getUserActions().get(0).getIsPlaying());
Assert.assertEquals("other", ual2.getUserActions().get(0).getMediapackageId());
Assert.assertEquals(20, ual2.getUserActions().get(0).getOutpoint());
Assert.assertEquals("6", ual2.getUserActions().get(0).getSession().getSessionId());
Assert.assertEquals("other test", ual2.getUserActions().get(0).getType());
Assert.assertEquals("testing user 2", ual2.getUserActions().get(0).getSession().getUserId());
Assert.assertEquals("127.0.0.5", ual2.getUserActions().get(0).getSession().getUserIp());
Assert.assertEquals(15, ual2.getUserActions().get(0).getLength());
}
use of org.opencastproject.usertracking.api.UserAction in project opencast by opencast.
the class UserActionListImplTest method testListAddition.
/**
* Tests that adding events to a UserActionList works using the list add method
*/
@Test
public void testListAddition() {
UserSession us1 = new UserSessionImpl();
us1.setSessionId("4");
us1.setUserId("testing user");
us1.setUserIp("127.0.0.1");
UserSession us2 = new UserSessionImpl();
us2.setSessionId("6");
us2.setUserId("testing user 2");
us2.setUserIp("127.0.0.5");
UserAction ua1 = new UserActionImpl();
ua1.setId(4L);
ua1.setInpoint(90);
ua1.setIsPlaying(true);
ua1.setMediapackageId("false");
ua1.setOutpoint(100);
ua1.setSession(us1);
ua1.setType("test");
UserAction ua2 = new UserActionImpl();
ua2.setId(6L);
ua2.setInpoint(5);
ua2.setIsPlaying(false);
ua2.setMediapackageId("other");
ua2.setOutpoint(20);
ua2.setSession(us2);
ua2.setType("other test");
List<UserAction> list = new LinkedList<UserAction>();
list.add(ua1);
list.add(ua2);
UserActionList ual = new UserActionListImpl();
ual.add(list);
ual.setTotal(2);
Assert.assertEquals(2, ual.getTotal());
Assert.assertEquals(2, ual.getUserActions().size());
Assert.assertEquals(new Long(4), ual.getUserActions().get(0).getId());
Assert.assertEquals(90, ual.getUserActions().get(0).getInpoint());
Assert.assertEquals(true, ual.getUserActions().get(0).getIsPlaying());
Assert.assertEquals("false", ual.getUserActions().get(0).getMediapackageId());
Assert.assertEquals(100, ual.getUserActions().get(0).getOutpoint());
Assert.assertEquals("4", ual.getUserActions().get(0).getSession().getSessionId());
Assert.assertEquals("test", ual.getUserActions().get(0).getType());
Assert.assertEquals("testing user", ual.getUserActions().get(0).getSession().getUserId());
Assert.assertEquals("127.0.0.1", ual.getUserActions().get(0).getSession().getUserIp());
Assert.assertEquals(new Long(6), ual.getUserActions().get(1).getId());
Assert.assertEquals(5, ual.getUserActions().get(1).getInpoint());
Assert.assertEquals(false, ual.getUserActions().get(1).getIsPlaying());
Assert.assertEquals("other", ual.getUserActions().get(1).getMediapackageId());
Assert.assertEquals(20, ual.getUserActions().get(1).getOutpoint());
Assert.assertEquals("6", ual.getUserActions().get(1).getSession().getSessionId());
Assert.assertEquals("other test", ual.getUserActions().get(1).getType());
Assert.assertEquals("testing user 2", ual.getUserActions().get(1).getSession().getUserId());
Assert.assertEquals("127.0.0.5", ual.getUserActions().get(1).getSession().getUserIp());
Assert.assertEquals(15, ual.getUserActions().get(1).getLength());
}
use of org.opencastproject.usertracking.api.UserAction in project opencast by opencast.
the class UserTrackingServiceImplTest method createAndVerifyUserAction.
/**
* Creates and verifies a user action with an arbitrary date
* @throws Exception
*/
private UserAction createAndVerifyUserAction(String type, String sessionId, String mediapackageId, String userId, String userIp, int inpoint, int outpoint, Date createdDate) throws Exception {
UserSession userSession = createUserSession(sessionId, userId, userIp);
UserAction userAction = createUserAction(type, mediapackageId, inpoint, outpoint, createdDate, userSession);
if (UserTrackingServiceImpl.FOOTPRINT_KEY.equals(type)) {
userAction = service.addUserFootprint(userAction, userSession);
} else {
userAction = service.addUserTrackingEvent(userAction, userSession);
}
Long id = userAction.getId();
// Ensure that, once persisted, the user action has an ID
Assert.assertNotNull(id);
// Sanity checks
UserActionImpl fromDb = (UserActionImpl) service.getUserAction(id);
Assert.assertNotNull(fromDb);
Assert.assertNotNull(fromDb.getCreated());
Assert.assertEquals(id, fromDb.getId());
Assert.assertEquals(userAction.getMediapackageId(), fromDb.getMediapackageId());
Assert.assertEquals(userAction.getSession().getSessionId(), fromDb.getSession().getSessionId());
Assert.assertEquals(userAction.getType(), fromDb.getType());
Assert.assertEquals(userAction.getSession().getUserId(), fromDb.getSession().getUserId());
Assert.assertEquals(userAction.getSession().getUserIp(), fromDb.getSession().getUserIp());
Assert.assertEquals(userAction.getInpoint(), fromDb.getInpoint());
Assert.assertEquals(userAction.getOutpoint(), fromDb.getOutpoint());
Assert.assertEquals(userAction.getIsPlaying(), fromDb.getIsPlaying());
Assert.assertEquals(userAction.getSession().getUserIp(), fromDb.getSession().getUserIp());
return userAction;
}
use of org.opencastproject.usertracking.api.UserAction in project opencast by opencast.
the class UserTrackingServiceImplTest method createUserAction.
/**
* Creates a user action with an arbitrary date
* @throws Exception
*/
private UserAction createUserAction(String type, String mediapackageId, int inpoint, int outpoint, Date createdDate, UserSession userSession) {
UserAction userAction = new UserActionImpl();
userAction.setInpoint(inpoint);
userAction.setOutpoint(outpoint);
userAction.setMediapackageId(mediapackageId);
userAction.setSession(userSession);
userAction.setType(type);
((UserActionImpl) userAction).setCreated(createdDate);
return userAction;
}
Aggregations