Added check to declared version and changelog versions

This commit is contained in:
Luca Frosini 2023-02-10 17:03:50 +01:00
parent e5ccf89c0c
commit 5278282866
2 changed files with 49 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package org.gcube.informationsystem.types;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -181,6 +182,22 @@ public class TypeMapper {
throw new RuntimeException("The Type " + clz.getSimpleName() + " does not provided the appropriated changelog Map");
}
List<Version> versions = new ArrayList<>(map.keySet());
versions.sort(new Comparator<Version>() {
@Override
public int compare(Version o1, Version o2) {
/* o2.compareTo(o1) and not vice-versa
* because we want descending order
*/
return o2.compareTo(o1);
}
});
if(versions.get(0).compareTo(typeVersion)!=0) {
throw new RuntimeException("The Type declared version (i.e."+ typeVersion.toString() +") does not match the highest version declared in changelog (i.e. "+ versions.get(0) + "). Please fix your type.");
}
return map;
}

View File

@ -18,6 +18,9 @@ import org.gcube.informationsystem.model.reference.relations.Relation;
import org.gcube.informationsystem.queries.templates.reference.entities.QueryTemplate;
import org.gcube.informationsystem.queries.templates.reference.properties.TemplateVariable;
import org.gcube.informationsystem.serialization.ElementMapper;
import org.gcube.informationsystem.types.annotations.Final;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.types.reference.entities.EntityType;
import org.gcube.informationsystem.types.reference.entities.FacetType;
import org.gcube.informationsystem.types.reference.entities.ResourceType;
@ -211,4 +214,33 @@ public class SerializationTest {
}
@TypeMetadata(name = TestVersionNotInChangelog.NAME, description = "This type is a test to check version compliancy", version = "2.1.0")
@Change(version = "1.1.0", description = "A test of the declared version which is not in changelog")
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
@Final
interface TestVersionNotInChangelog extends Property {
public static final String NAME = "TestVersionNotInChangelog"; // TestVersionNotInChangelog.class.getSimpleName();
}
@TypeMetadata(name = TestVersionNotHighest.NAME, description = "This type is a test to check version compliancy", version = "1.0.0")
@Change(version = "1.1.0", description = "A test of the declared version which is not the highest in changelog")
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
@Final
interface TestVersionNotHighest extends Property {
public static final String NAME = "TestVersionNotHighest"; // TestVersionNotHighest.class.getSimpleName();
}
@Test(expected = RuntimeException.class)
public void testVersionNotInChangelog() throws Exception{
TypeMapper.serializeType(TestVersionNotInChangelog.class);
}
@Test(expected = RuntimeException.class)
public void testVersionNotHighest() throws Exception{
TypeMapper.serializeType(TestVersionNotHighest.class);
}
}