コード例 #1
0
  @Test
  @Ignore
  public void testNullContext() {
    service.activate(null);
    // This is broken, the Response object generated in the REST service can't find the appropriate
    // class :(
    HttpServletRequest request = getMockHttpSession();
    Response r = service.addFootprint("test", "0", "10", "FOOTPRINT", "true", request);
    UserAction a = (UserAction) r.getEntity();
    Assert.assertEquals(0, a.getInpoint());
    Assert.assertEquals(10, a.getOutpoint());
    Assert.assertEquals(10, a.getLength());
    Assert.assertEquals("FOOTPRINT", a.getType());
    Assert.assertTrue(a.getIsPlaying());
    Assert.assertEquals("test", a.getMediapackageId());
    Assert.assertEquals(MOCK_SESSION_ID, a.getSessionId());
    Assert.assertEquals(REMOTE_IP, a.getUserIp());
    Assert.assertEquals(MOCK_USER, a.getUserId());

    request = getMockHttpSessionWithProxy();
    r = service.addFootprint("test", "20", "30", "FOOTPRINT", "true", request);
    a = (UserAction) r.getEntity();
    Assert.assertEquals(20, a.getInpoint());
    Assert.assertEquals(30, a.getOutpoint());
    Assert.assertEquals(10, a.getLength());
    Assert.assertEquals("FOOTPRINT", a.getType());
    Assert.assertTrue(a.getIsPlaying());
    Assert.assertEquals("test", a.getMediapackageId());
    Assert.assertEquals(MOCK_SESSION_ID, a.getSessionId());
    Assert.assertEquals(REMOTE_IP, a.getUserIp());
    Assert.assertEquals(MOCK_USER, a.getUserId());
  }
コード例 #2
0
  @Before
  public void setUp() throws UserTrackingException {
    SecurityService security = EasyMock.createMock(SecurityService.class);
    EasyMock.expect(security.getUser())
        .andReturn(new User(MOCK_USER, "mh_default", new String[] {"ROLE_USER"}))
        .anyTimes();

    BundleContext bc = EasyMock.createMock(BundleContext.class);
    EasyMock.expect(bc.getProperty("org.opencastproject.server.url"))
        .andReturn("http://www.example.org:8080")
        .anyTimes();

    @SuppressWarnings("rawtypes")
    Dictionary dict = EasyMock.createMock(Dictionary.class);
    EasyMock.expect(dict.get(RestConstants.SERVICE_PATH_PROPERTY))
        .andReturn("/usertracking")
        .anyTimes();

    ComponentContext context = EasyMock.createMock(ComponentContext.class);
    EasyMock.expect(context.getBundleContext()).andReturn(bc).anyTimes();
    EasyMock.expect(context.getProperties()).andReturn(dict).anyTimes();

    UserActionImpl ua = EasyMock.createMock(UserActionImpl.class);
    EasyMock.expect(ua.getId()).andReturn(4L).anyTimes();

    UserTrackingService usertracking = EasyMock.createMock(UserTrackingService.class);
    EasyMock.expect(usertracking.addUserFootprint(EasyMock.isA(UserAction.class)))
        .andReturn(ua)
        .anyTimes();

    EasyMock.replay(security, bc, dict, context, ua, usertracking);

    service = new UserTrackingRestService();
    service.setSecurityService(security);
    service.setService(usertracking);
    service.activate(context);
  }