test_class.declarator: urlSessionTracking
test_class.modifier: private
test_class.original_string: private UrlSessionTracking urlSessionTracking;
test_class.type: UrlSessionTracking
test_class.var_name: urlSessionTracking
test_class.file: session-replacement/src/test/java/com/amadeus/session/servlet/TestUrlSessionTracking.java
test_class.identifier: TestUrlSessionTracking
test_case.body: @Test
    public void testEncodeUrl() {
      SessionConfiguration sc = new SessionConfiguration();
      sc.setSessionIdName("asession");
      urlSessionTracking.configure(sc);
      RequestWithSession request = mock(RequestWithSession.class, withSettings().extraInterfaces(HttpServletRequest.class));
      RepositoryBackedSession session = mock(RepositoryBackedSession.class);
      when(request.getRepositoryBackedSession(false)).thenReturn(session);
      when(session.isValid()).thenReturn(Boolean.FALSE);
      String url = urlSessionTracking.encodeUrl(request, "http://www.example.com");
      assertEquals("Session is not valid, so URL should stay the same", "http://www.example.com", url);
      when(session.isValid()).thenReturn(Boolean.TRUE);
      when(session.getId()).thenReturn("1234");
      url = urlSessionTracking.encodeUrl(request, "http://www.example.com");
      assertEquals("Session is valid, so URL should be encoded", "http://www.example.com;asession=1234", url);
      url = urlSessionTracking.encodeUrl(request, "http://www.example.com/abc");
      assertEquals("Session is valid, so URL should be encoded", "http://www.example.com/abc;asession=1234", url);
      url = urlSessionTracking.encodeUrl(request, "http://www.example.com/def?abc");
      assertEquals("Session is valid, so URL should be encoded", "http://www.example.com/def;asession=1234?abc", url);
      url = urlSessionTracking.encodeUrl(request, "http://www.example.com/def?abc?");
      assertEquals("Session is valid, so URL should be encoded", "http://www.example.com/def;asession=1234?abc?", url);
    }
test_case.class_method_signature: TestUrlSessionTracking.testEncodeUrl()
test_case.full_signature: @Test public void testEncodeUrl()
test_case.identifier: testEncodeUrl
test_case.invocations: setSessionIdName configure mock extraInterfaces withSettings mock thenReturn when getRepositoryBackedSession thenReturn when isValid encodeUrl assertEquals thenReturn when isValid thenReturn when getId encodeUrl assertEquals encodeUrl assertEquals encodeUrl assertEquals encodeUrl assertEquals
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testEncodeUrl()
focal_class.declarator: sessionIdPathItem
focal_class.modifier: private
focal_class.original_string: private String sessionIdPathItem;
focal_class.type: String
focal_class.var_name: sessionIdPathItem
focal_class.file: session-replacement/src/main/java/com/amadeus/session/servlet/UrlSessionTracking.java
focal_class.identifier: UrlSessionTracking
focal_class.interfaces: implements SessionTracking
focal_class.class_method_signature: UrlSessionTracking.configure(SessionConfiguration configuration)
focal_class.full_signature: @Override public void configure(SessionConfiguration configuration)
focal_class.identifier: configure
focal_class.modifiers: @Override public
focal_class.parameters: (SessionConfiguration configuration)
focal_class.return: void
focal_class.signature: void configure(SessionConfiguration configuration)
focal_class.class_method_signature: UrlSessionTracking.retrieveId(RequestWithSession request)
focal_class.full_signature: @Override public IdAndSource retrieveId(RequestWithSession request)
focal_class.identifier: retrieveId
focal_class.modifiers: @Override public
focal_class.parameters: (RequestWithSession request)
focal_class.return: IdAndSource
focal_class.signature: IdAndSource retrieveId(RequestWithSession request)
focal_class.class_method_signature: UrlSessionTracking.propagateSession(RequestWithSession request, Object response)
focal_class.full_signature: @Override public void propagateSession(RequestWithSession request, Object response)
focal_class.identifier: propagateSession
focal_class.modifiers: @Override public
focal_class.parameters: (RequestWithSession request, Object response)
focal_class.return: void
focal_class.signature: void propagateSession(RequestWithSession request, Object response)
focal_class.class_method_signature: UrlSessionTracking.encodeUrl(RequestWithSession request, String url)
focal_class.full_signature: @Override public String encodeUrl(RequestWithSession request, String url)
focal_class.identifier: encodeUrl
focal_class.modifiers: @Override public
focal_class.parameters: (RequestWithSession request, String url)
focal_class.return: String
focal_class.signature: String encodeUrl(RequestWithSession request, String url)
focal_class.class_method_signature: UrlSessionTracking.isCookieTracking()
focal_class.full_signature: @Override public boolean isCookieTracking()
focal_class.identifier: isCookieTracking
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: boolean
focal_class.signature: boolean isCookieTracking()
focal_class.superclass: extends BaseSessionTracking
focal_method.body: @Override
    public String encodeUrl(RequestWithSession request, String url) {
      RepositoryBackedSession session = request.getRepositoryBackedSession(false);
      if (session == null || !session.isValid()) {
        return url;
      }
      String encodedSessionAlias;
      try {
        encodedSessionAlias = URLEncoder.encode(session.getId(), "UTF-8");
      } catch (UnsupportedEncodingException e) {
        throw new IllegalStateException("This exception should never happen!", e);
      }
  
      int queryStart = url.indexOf('?');
      if (queryStart < 0) {
        return url + sessionIdPathItem + encodedSessionAlias;
      }
      String path = url.substring(0, queryStart);
      String query = url.substring(queryStart + 1, url.length());
      path += sessionIdPathItem + encodedSessionAlias;
  
      return path + '?' + query;
    }
focal_method.class_method_signature: UrlSessionTracking.encodeUrl(RequestWithSession request, String url)
focal_method.full_signature: @Override public String encodeUrl(RequestWithSession request, String url)
focal_method.identifier: encodeUrl
focal_method.invocations: getRepositoryBackedSession isValid encode getId indexOf substring substring length
focal_method.modifiers: @Override public
focal_method.parameters: (RequestWithSession request, String url)
focal_method.return: String
focal_method.signature: String encodeUrl(RequestWithSession request, String url)