AccessKeyUtil { public String extractAppIdFromRequest(HttpServletRequest request) { String appId = null; String servletPath = request.getServletPath(); if (StringUtils.startsWith(servletPath, URL_CONFIGS_PREFIX)) { appId = StringUtils.substringBetween(servletPath, URL_CONFIGS_PREFIX, URL_SEPARATOR); } else if (StringUtils.startsWith(servletPath, URL_CONFIGFILES_JSON_PREFIX)) { appId = StringUtils.substringBetween(servletPath, URL_CONFIGFILES_JSON_PREFIX, URL_SEPARATOR); } else if (StringUtils.startsWith(servletPath, URL_CONFIGFILES_PREFIX)) { appId = StringUtils.substringBetween(servletPath, URL_CONFIGFILES_PREFIX, URL_SEPARATOR); } else if (StringUtils.startsWith(servletPath, URL_NOTIFICATIONS_PREFIX)) { appId = request.getParameter("appId"); } return appId; } AccessKeyUtil(AccessKeyServiceWithCache accessKeyServiceWithCache); List<String> findAvailableSecret(String appId); String extractAppIdFromRequest(HttpServletRequest request); String buildSignature(String path, String query, String timestampString, String secret);  }
@Test public void testExtractAppIdFromRequest1() { when(request.getServletPath()).thenReturn("/configs/someAppId/default/application"); String appId = accessKeyUtil.extractAppIdFromRequest(request); assertThat(appId).isEqualTo("someAppId"); }
@Test public void testExtractAppIdFromRequest2() { when(request.getServletPath()).thenReturn("/configfiles/json/someAppId/default/application"); String appId = accessKeyUtil.extractAppIdFromRequest(request); assertThat(appId).isEqualTo("someAppId"); }
@Test public void testExtractAppIdFromRequest3() { when(request.getServletPath()).thenReturn("/configfiles/someAppId/default/application"); String appId = accessKeyUtil.extractAppIdFromRequest(request); assertThat(appId).isEqualTo("someAppId"); }
@Test public void testExtractAppIdFromRequest4() { when(request.getServletPath()).thenReturn("/notifications/v2"); when(request.getParameter("appId")).thenReturn("someAppId"); String appId = accessKeyUtil.extractAppIdFromRequest(request); assertThat(appId).isEqualTo("someAppId"); }