Application { public URL getBaseURL() { String baseURL = StringUtils.trimToEmpty(System.getProperty(PROPERTY_KEY_SVENTON_BASE_URL)); if (!baseURL.isEmpty()) { if (!baseURL.endsWith("/")) { baseURL = baseURL + "/"; } try { return new URL(baseURL); } catch (MalformedURLException e) { logger.warn("Value of property '" + PROPERTY_KEY_SVENTON_BASE_URL + "' is not a valid URL: " + e.getMessage()); } } return null; } Application(final ConfigDirectory configDirectory); void setScheduler(final Scheduler scheduler); @PostConstruct void init(); @ManagedOperation synchronized void reinit(); File[] getConfigDirectories(); File[] getBackupConfigDirectories(); void initCaches(); void persistRepositoryConfigurations(); void addConfiguration(final RepositoryConfiguration configuration); void deleteConfiguration(final RepositoryName name); void setConfigurationFileName(String configurationFileName); String getConfigurationFileName(); Set<RepositoryName> getRepositoryNames(); RepositoryConfiguration getConfiguration(final RepositoryName name); int getRepositoryConfigurationCount(); boolean hasConfigurations(); boolean isConfigured(); synchronized boolean isUpdating(final RepositoryName name); void setConfigPassword(final String configPassword); boolean isValidConfigPassword(final String configPassword); synchronized void setUpdatingCache(final RepositoryName name, final boolean updating); void setConfigured(final boolean configured); File getConfigurationDirectoryForRepository(final RepositoryName repositoryName); @Autowired void setCacheManagers(final List<CacheManager> cacheManagers); void setEditableConfig(final boolean editableConfig); boolean isEditableConfig(); boolean isConfigurationReloadSupported(); void setConfigurationReloadSupported(boolean configurationReloadSupported); URL getBaseURL(); static final String PROPERTY_KEY_SVENTON_BASE_URL; }
@Test public void testGetBaseURL() throws Exception { final MockServletContext servletContext = new MockServletContext(); servletContext.setContextPath("sventon-test"); configDirectory.setCreateDirectories(false); configDirectory.setServletContext(servletContext); final Application application = new Application(configDirectory); assertNull(application.getBaseURL()); System.setProperty(Application.PROPERTY_KEY_SVENTON_BASE_URL, "not-a-url"); assertNull(application.getBaseURL()); System.setProperty(Application.PROPERTY_KEY_SVENTON_BASE_URL, "http: assertEquals("http: System.setProperty(Application.PROPERTY_KEY_SVENTON_BASE_URL, "http: assertEquals("http: }