/** @throws java.lang.Exception */
  @Before
  public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);

    factory = new AuditLogInfoContainerFactoryImpl(ldapService);
    factory.setRequestResponseConverter(converter);
  }
  /**
   * Test method for {@link
   * se.vgregion.portal.auditlog.AuditLogInfoContainerFactoryImpl#getAuditLogInfoContainer(java.lang.String,
   * java.lang.String, javax.portlet.PortletRequest)} .
   */
  @Test
  public final void testGetAuditLogInfoContainerUserFromLdap() {
    MockPortletRequest portletRequest = new MockPortletRequest();

    Map<String, String> uInfoMap = new HashMap<String, String>();
    uInfoMap.put(PortletRequest.P3PUserInfos.USER_LOGIN_ID.toString(), "remoteUid");
    portletRequest.setAttribute(PortletRequest.USER_INFO, uInfoMap);

    MockHttpServletRequest httpRequest = new MockHttpServletRequest();

    given(converter.getHttpServletRequest(portletRequest)).willReturn(httpRequest);

    LdapUser ldapUser = new SimpleLdapUser("dn");
    ldapUser.setAttributeValue("cn", "searcherId");
    given(ldapService.getLdapUserByUid("remoteUid")).willReturn(ldapUser);

    AuditLogInfoContainer container = factory.getAuditLogInfoContainer("patientId", portletRequest);

    assertEquals("searcherId", container.getSearcherId());
  }
  /**
   * Test method for {@link
   * se.vgregion.portal.auditlog.AuditLogInfoContainerFactoryImpl#getAuditLogInfoContainer(java.lang.String,
   * java.lang.String, javax.portlet.PortletRequest)} .
   */
  @Test
  public final void testGetAuditLogInfoContainer() {
    MockPortletRequest portletRequest = new MockPortletRequest();

    Map<String, String> uInfoMap = new HashMap<String, String>();
    uInfoMap.put(PortletRequest.P3PUserInfos.USER_LOGIN_ID.toString(), "remoteUid");
    portletRequest.setAttribute(PortletRequest.USER_INFO, uInfoMap);

    MockHttpServletRequest httpRequest = new MockHttpServletRequest();
    httpRequest.setRemoteAddr("127.0.0.1");
    httpRequest.setRemoteHost("remoteHost");
    httpRequest.setRemotePort(123);

    given(converter.getHttpServletRequest(portletRequest)).willReturn(httpRequest);

    AuditLogInfoContainer container = factory.getAuditLogInfoContainer("patientId", portletRequest);

    assertEquals("patientId", container.getPatientId());
    assertEquals("[LiferayUser:]remoteUid", container.getSearcherId());
    assertEquals("remoteUid", container.getRemoteUser());
    assertEquals("127.0.0.1 [Default]", container.getRemoteIpAddress());
    assertEquals("remoteHost", container.getRemoteHost());
    assertEquals(123, container.getRemotePort());
  }