import org.sonar.updatecenter.common.Release;
import org.sonar.updatecenter.common.SonarUpdate;
import org.sonar.updatecenter.common.UpdateCenter;
+import org.sonar.updatecenter.common.Version;
import static org.apache.commons.lang.StringUtils.isNotBlank;
import static org.sonar.server.plugins.edition.EditionBundledPlugins.isEditionBundled;
private static final boolean DO_NOT_FORCE_REFRESH = false;
private static final String ARRAY_UPGRADES = "upgrades";
+ private static final String PROPERTY_UPDATE_CENTER_LTS = "latestLTS";
private static final String PROPERTY_UPDATE_CENTER_REFRESH = "updateCenterRefresh";
private static final String PROPERTY_VERSION = "version";
private static final String PROPERTY_DESCRIPTION = "description";
Optional<UpdateCenter> updateCenter = updateCenterFactory.getUpdateCenter(DO_NOT_FORCE_REFRESH);
writeUpgrades(jsonWriter, updateCenter);
if (updateCenter.isPresent()) {
+ Release ltsRelease = updateCenter.get().getSonar().getLtsRelease();
+ if (ltsRelease != null) {
+ Version ltsVersion = ltsRelease.getVersion();
+ String latestLTS = String.format("%s.%s", ltsVersion.getMajor(), ltsVersion.getMinor());
+ jsonWriter.prop(PROPERTY_UPDATE_CENTER_LTS, latestLTS);
+ }
jsonWriter.propDateTime(PROPERTY_UPDATE_CENTER_REFRESH, updateCenter.get().getDate());
}
private UpdateCenterMatrixFactory updateCenterFactory = mock(UpdateCenterMatrixFactory.class);
private UpdateCenter updateCenter = mock(UpdateCenter.class);
+ private Sonar sonar = mock(Sonar.class);
private UpgradesAction underTest = new UpgradesAction(updateCenterFactory);
private WsActionTester tester = new WsActionTester(underTest);
@Before
public void wireMocks() {
when(updateCenterFactory.getUpdateCenter(anyBoolean())).thenReturn(Optional.of(updateCenter));
+ when(updateCenter.getSonar()).thenReturn(sonar);
when(updateCenter.getDate()).thenReturn(DateUtils.parseDateTime("2015-04-24T16:08:36+0200"));
}
@Test
public void verify_JSON_response_against_example() {
SonarUpdate sonarUpdate = createSonar_51_update();
+ when(sonar.getLtsRelease()).thenReturn(new Release(sonar, Version.create("8.9.2")));
when(updateCenter.findSonarUpdates()).thenReturn(of(sonarUpdate));
TestResponse response = tester.newRequest().execute();