import org.sonar.updatecenter.common.UpdateCenterDeserializer.Mode;
/**
- * HTTP client to load data from the remote update center hosted at https://update.sonarsource.org.
+ * HTTP client to load data from the remote update center hosted at https://downloads.sonarsource.com/?prefix=sonarqube/update
*
* @since 2.4
*/
@Properties({
@Property(
key = UpdateCenterClient.URL_PROPERTY,
- defaultValue = "https://update.sonarsource.org/update-center.properties",
+ defaultValue = UpdateCenterClient.URL_DEFAULT_VALUE,
name = "Update Center URL",
category = "Update Center",
// hidden from UI
global = false),
@Property(
key = UpdateCenterClient.CACHE_TTL_PROPERTY,
- defaultValue = "3600000",
+ defaultValue = UpdateCenterClient.CACHE_TTL_DEFAULT_VALUE,
name = "Update Center cache time-to-live in milliseconds",
category = "Update Center",
// hidden from UI
public class UpdateCenterClient {
private static final Logger LOG = LoggerFactory.getLogger(UpdateCenterClient.class);
- public static final String URL_PROPERTY = "sonar.updatecenter.url";
- public static final String CACHE_TTL_PROPERTY = "sonar.updatecenter.cache.ttl";
+ static final String URL_PROPERTY = "sonar.updatecenter.url";
+ static final String URL_DEFAULT_VALUE = "https://downloads.sonarsource.com/sonarqube/update/update-center.properties";
+ static final String CACHE_TTL_PROPERTY = "sonar.updatecenter.cache.ttl";
+ static final String CACHE_TTL_DEFAULT_VALUE = "3600000";
private final long periodInMilliseconds;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import static org.sonar.server.plugins.UpdateCenterClient.*;
public class UpdateCenterClientTest {
- private static final String BASE_URL = "https://update.sonarsource.org";
- private static final String DEFAULT_CACHE_TTL = "3600000";
private UriReader reader = mock(UriReader.class);
private MapSettings settings = new MapSettings();
private UpdateCenterClient underTest;
@Before
public void startServer() throws Exception {
reader = mock(UriReader.class);
- settings.setProperty(UpdateCenterClient.URL_PROPERTY, BASE_URL);
+ settings.setProperty(URL_PROPERTY, URL_DEFAULT_VALUE);
settings.setProperty(ProcessProperties.Property.SONAR_UPDATECENTER_ACTIVATE.getKey(), true);
- settings.setProperty(UpdateCenterClient.CACHE_TTL_PROPERTY, DEFAULT_CACHE_TTL);
+ settings.setProperty(CACHE_TTL_PROPERTY, CACHE_TTL_DEFAULT_VALUE);
underTest = new UpdateCenterClient(reader, settings.asConfig());
}
@Test
public void downloadUpdateCenter() throws URISyntaxException {
- when(reader.readString(new URI(BASE_URL), StandardCharsets.UTF_8)).thenReturn("publicVersions=2.2,2.3");
+ when(reader.readString(new URI(URL_DEFAULT_VALUE), StandardCharsets.UTF_8)).thenReturn("publicVersions=2.2,2.3");
UpdateCenter plugins = underTest.getUpdateCenter().get();
- verify(reader, times(1)).readString(new URI(BASE_URL), StandardCharsets.UTF_8);
+ verify(reader, times(1)).readString(new URI(URL_DEFAULT_VALUE), StandardCharsets.UTF_8);
assertThat(plugins.getSonar().getVersions()).containsOnly(Version.create("2.2"), Version.create("2.3"));
assertThat(underTest.getLastRefreshDate()).isNotNull();
}
@Test
public void cache_data() throws Exception {
- when(reader.readString(new URI(BASE_URL), StandardCharsets.UTF_8)).thenReturn("sonar.versions=2.2,2.3");
+ when(reader.readString(new URI(URL_DEFAULT_VALUE), StandardCharsets.UTF_8)).thenReturn("sonar.versions=2.2,2.3");
underTest.getUpdateCenter();
underTest.getUpdateCenter();
- verify(reader, times(1)).readString(new URI(BASE_URL), StandardCharsets.UTF_8);
+ verify(reader, times(1)).readString(new URI(URL_DEFAULT_VALUE), StandardCharsets.UTF_8);
}
@Test
public void forceRefresh() throws Exception {
- when(reader.readString(new URI(BASE_URL), StandardCharsets.UTF_8)).thenReturn("sonar.versions=2.2,2.3");
+ when(reader.readString(new URI(URL_DEFAULT_VALUE), StandardCharsets.UTF_8)).thenReturn("sonar.versions=2.2,2.3");
underTest.getUpdateCenter();
underTest.getUpdateCenter(true);
- verify(reader, times(2)).readString(new URI(BASE_URL), StandardCharsets.UTF_8);
+ verify(reader, times(2)).readString(new URI(URL_DEFAULT_VALUE), StandardCharsets.UTF_8);
}
@Test