use of com.vdurmont.semver4j.Semver in project graylog2-server by Graylog2.
the class SemverDeserializerTest method successfullyDeserializesInteger.
@Test
public void successfullyDeserializesInteger() throws IOException {
final Semver version = objectMapper.readValue("5", Semver.class);
assertThat(version).isEqualTo(new Semver("5", Semver.SemverType.LOOSE));
}
use of com.vdurmont.semver4j.Semver in project dhis2-core by dhis2.
the class SystemUpdateService method extractNewerPatchVersions.
protected static List<JsonElement> extractNewerPatchVersions(Semver currentVersion, JsonObject allVersions) {
List<JsonElement> newerPatchVersions = new ArrayList<>();
for (JsonElement versionElement : allVersions.getAsJsonArray("versions")) {
String majorDotMinor = versionElement.getAsJsonObject().getAsJsonPrimitive(FIELD_NAME_NAME).getAsString();
Semver semver = new Semver(String.format("%s.0", majorDotMinor));
// patch versions higher than the currentVersion's patch version
if (Objects.equals(currentVersion.getMajor(), semver.getMajor()) && Objects.equals(currentVersion.getMinor(), semver.getMinor())) {
int latestPatchVersion = versionElement.getAsJsonObject().getAsJsonPrimitive("latestPatchVersion").getAsInt();
if (currentVersion.getPatch() < latestPatchVersion) {
for (JsonElement patchElement : versionElement.getAsJsonObject().getAsJsonArray("patchVersions")) {
int patchVersion = patchElement.getAsJsonObject().getAsJsonPrimitive(FIELD_NAME_VERSION).getAsInt();
if (currentVersion.getPatch() < patchVersion) {
log.debug("Found a newer patch version, " + "adding it the result list; version={}", patchVersion);
newerPatchVersions.add(patchElement);
}
}
}
}
}
return newerPatchVersions;
}
use of com.vdurmont.semver4j.Semver in project dhis2-core by dhis2.
the class SystemUpdateServiceTest method testParseJsonPatchVersions_Success.
@Test
void testParseJsonPatchVersions_Success() {
List<JsonElement> newerPatchVersions = new ArrayList<>();
JsonObject patchJsonObject = new JsonObject();
patchJsonObject.addProperty("name", "1.2.3");
patchJsonObject.addProperty("releaseDate", "2018-01-01");
patchJsonObject.addProperty("url", "https://example.com/download/1.2.3");
newerPatchVersions.add(patchJsonObject);
Map<Semver, Map<String, String>> versionsAndMetadata = SystemUpdateService.convertJsonToMap(newerPatchVersions);
assertNotNull(versionsAndMetadata);
assertEquals(1, newerPatchVersions.size());
Semver semverKey = new Semver("1.2.3");
assertEquals("1.2.3", versionsAndMetadata.get(semverKey).get("version"));
assertEquals("2018-01-01", versionsAndMetadata.get(semverKey).get("releaseDate"));
assertEquals("https://example.com/download/1.2.3", versionsAndMetadata.get(semverKey).get("downloadUrl"));
}
use of com.vdurmont.semver4j.Semver in project dhis2-core by dhis2.
the class SystemUpdateServiceTest method testGetNewerPatchVersions_NoNewerPatchVersions.
@Test
void testGetNewerPatchVersions_NoNewerPatchVersions() {
Semver currentVersion = new Semver("1.2.3");
JsonObject allVersions = new JsonObject();
allVersions.add("versions", new JsonArray());
List<JsonElement> newerPatchVersions = SystemUpdateService.extractNewerPatchVersions(currentVersion, allVersions);
assertTrue(newerPatchVersions.isEmpty());
}
use of com.vdurmont.semver4j.Semver in project dhis2-core by dhis2.
the class SystemUpdateServiceTest method testGetNewerPatchVersions_Success.
@Test
void testGetNewerPatchVersions_Success() {
// Given
Semver currentVersion = new Semver("1.2.2");
JsonObject allVersions = new JsonObject();
allVersions.add("versions", new JsonArray());
JsonObject versionElement = new JsonObject();
versionElement.add("name", new JsonPrimitive("1.2"));
versionElement.add("version", new JsonPrimitive(2));
versionElement.add("latestPatchVersion", new JsonPrimitive(3));
versionElement.add("patchVersions", new JsonArray());
JsonObject patchElement = new JsonObject();
patchElement.add("version", new JsonPrimitive(3));
versionElement.getAsJsonArray("patchVersions").add(patchElement);
allVersions.getAsJsonArray("versions").add(versionElement);
// When
List<JsonElement> newerPatchVersions = SystemUpdateService.extractNewerPatchVersions(currentVersion, allVersions);
// Then
assertNotNull(newerPatchVersions);
assertEquals(1, newerPatchVersions.size());
}
Aggregations