Issue-ID: POLICY-4885
Change-Id: I036c4ddc41bb817dc28a4b28a842d3139991bd10
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
public static final String NAME_REGEXP = "^[A-Za-z0-9\\-_\\.]+$";
/** Regular expression to specify the structure of key versions. */
public static final String NAME_REGEXP = "^[A-Za-z0-9\\-_\\.]+$";
/** Regular expression to specify the structure of key versions. */
- public static final String VERSION_REGEXP = "^(\\d+.){2}\\d+$";
+ public static final String VERSION_REGEXP
+ = "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)"
+ + "(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$";
/** Regular expression to specify the structure of key IDs. */
public static final String KEY_ID_REGEXP = "^[A-Za-z0-9\\-_\\.]+:(\\d+.){2}\\d+$";
/** Regular expression to specify the structure of key IDs. */
public static final String KEY_ID_REGEXP = "^[A-Za-z0-9\\-_\\.]+:(\\d+.){2}\\d+$";
/*-
* ============LICENSE_START=======================================================
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2021 Nordix Foundation.
+ * Copyright (C) 2019-2021,2023 Nordix Foundation.
* Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
private static final String VERSION123 = "1.2.3";
private static final String VERSION100 = "1.0.0";
private static final String VERSION001 = "0.0.1";
private static final String VERSION123 = "1.2.3";
private static final String VERSION100 = "1.0.0";
private static final String VERSION001 = "0.0.1";
+ private static final String NAME = "name";
private static MyKey someKey;
private static MyKey someKey0;
private static MyKey someKey1;
private static MyKey someKey;
private static MyKey someKey0;
private static MyKey someKey1;
private static MyKey someKey5;
private static MyKey someKey6;
private static MyKey someKey5;
private static MyKey someKey6;
+ private static final MyKey buildKey1 = new MyKey(NAME, "0.0.3+1");
+ private static final MyKey buildKey2 = new MyKey(NAME, "0.1.0-1");
+ private static final MyKey buildKey3 = new MyKey(NAME, "3.0.0-SNAPSHOT");
+ private static final MyKey buildKey4 = new MyKey(NAME, "1.0.0-rc.1");
+
/**
* Sets data in Keys for the tests.
*/
/**
* Sets data in Keys for the tests.
*/
someKey = new MyKey();
someKey0 = new MyKey();
someKey = new MyKey();
someKey0 = new MyKey();
- someKey1 = new MyKey("name", VERSION001);
+ someKey1 = new MyKey(NAME, VERSION001);
someKey2 = new MyKey(someKey1);
someKey3 = new MyKey(someKey1.getId());
someKey2 = new MyKey(someKey1);
someKey3 = new MyKey(someKey1.getId());
assertTrue(someKey.isNullKey());
assertEquals(new MyKey(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_VERSION), someKey);
assertTrue(someKey.isNullKey());
assertEquals(new MyKey(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_VERSION), someKey);
- MyKey someKey11 = new MyKey("name", VERSION001);
+ MyKey someKey11 = new MyKey(NAME, VERSION001);
MyKey someKey22 = new MyKey(someKey11);
MyKey someKey33 = new MyKey(someKey11.getId());
assertEquals(someKey11, someKey22);
MyKey someKey22 = new MyKey(someKey11);
MyKey someKey33 = new MyKey(someKey11.getId());
assertEquals(someKey11, someKey22);
.hasMessageMatching("^otherKey is marked .*on.*ull but is null$");
assertEquals(Compatibility.DIFFERENT, someKey0.getCompatibility(new DummyPfKey()));
.hasMessageMatching("^otherKey is marked .*on.*ull but is null$");
assertEquals(Compatibility.DIFFERENT, someKey0.getCompatibility(new DummyPfKey()));
+ assertEquals(Compatibility.DIFFERENT, buildKey1.getCompatibility(new DummyPfKey()));
assertEquals(Compatibility.DIFFERENT, someKey0.getCompatibility(someKey1));
assertEquals(Compatibility.IDENTICAL, someKey2.getCompatibility(someKey1));
assertEquals(Compatibility.DIFFERENT, someKey0.getCompatibility(someKey1));
assertEquals(Compatibility.IDENTICAL, someKey2.getCompatibility(someKey1));
+ assertEquals(Compatibility.IDENTICAL, buildKey1.getCompatibility(new MyKey(buildKey1)));
assertEquals(Compatibility.PATCH, someKey3.getCompatibility(someKey1));
assertEquals(Compatibility.PATCH, someKey3.getCompatibility(someKey1));
+ assertEquals(Compatibility.PATCH, buildKey1.getCompatibility(someKey1));
assertEquals(Compatibility.MINOR, someKey4.getCompatibility(someKey1));
assertEquals(Compatibility.MINOR, someKey4.getCompatibility(someKey1));
+ assertEquals(Compatibility.MINOR, buildKey2.getCompatibility(buildKey1));
assertEquals(Compatibility.PATCH, someKey4a.getCompatibility(someKey1));
assertEquals(Compatibility.PATCH, someKey1.getCompatibility(someKey4a));
assertEquals(Compatibility.MAJOR, someKey5.getCompatibility(someKey1));
assertEquals(Compatibility.MAJOR, someKey6.getCompatibility(someKey1));
assertEquals(Compatibility.PATCH, someKey4a.getCompatibility(someKey1));
assertEquals(Compatibility.PATCH, someKey1.getCompatibility(someKey4a));
assertEquals(Compatibility.MAJOR, someKey5.getCompatibility(someKey1));
assertEquals(Compatibility.MAJOR, someKey6.getCompatibility(someKey1));
+ assertEquals(Compatibility.MAJOR, buildKey3.getCompatibility(someKey1));
assertTrue(someKey1.isCompatible(someKey2));
assertTrue(someKey1.isCompatible(someKey3));
assertTrue(someKey1.isCompatible(someKey4));
assertFalse(someKey1.isCompatible(someKey0));
assertFalse(someKey1.isCompatible(someKey5));
assertTrue(someKey1.isCompatible(someKey2));
assertTrue(someKey1.isCompatible(someKey3));
assertTrue(someKey1.isCompatible(someKey4));
assertFalse(someKey1.isCompatible(someKey0));
assertFalse(someKey1.isCompatible(someKey5));
+ assertFalse(someKey1.isCompatible(buildKey3));
+ assertFalse(someKey1.isCompatible(buildKey4));
assertFalse(someKey1.isCompatible(new DummyPfKey()));
}
assertFalse(someKey1.isCompatible(new DummyPfKey()));
}
assertTrue(someKey4.validate("").isValid());
assertTrue(someKey5.validate("").isValid());
assertTrue(someKey6.validate("").isValid());
assertTrue(someKey4.validate("").isValid());
assertTrue(someKey5.validate("").isValid());
assertTrue(someKey6.validate("").isValid());
+ assertTrue(buildKey1.validate("").isValid());
+ assertTrue(buildKey2.validate("").isValid());
+ assertTrue(buildKey3.validate("").isValid());
+ assertTrue(buildKey4.validate("").isValid());
assertThatThrownBy(() -> new MyKey(null, null)).hasMessageMatching("name is marked .*on.*ull but is null$");
assertThatThrownBy(() -> new MyKey(null, null)).hasMessageMatching("name is marked .*on.*ull but is null$");
- assertThatThrownBy(() -> new MyKey("name", null))
+ assertThatThrownBy(() -> new MyKey(NAME, null))
.hasMessageMatching("^version is marked .*on.*ull but is null$");
assertThatThrownBy(() -> new MyKey(null, VERSION001))
.hasMessageMatching("^version is marked .*on.*ull but is null$");
assertThatThrownBy(() -> new MyKey(null, VERSION001))
MyKey testKey = new MyKey("TheKey", VERSION001);
assertEquals("TheKey:0.0.1", testKey.getId());
MyKey testKey = new MyKey("TheKey", VERSION001);
assertEquals("TheKey:0.0.1", testKey.getId());
- Field nameField = testKey.getClass().getDeclaredField("name");
+ Field nameField = testKey.getClass().getDeclaredField(NAME);
nameField.setAccessible(true);
nameField.set(testKey, "Key Name");
ValidationResult validationResult = testKey.validate("");
nameField.setAccessible(true);
nameField.set(testKey, "Key Name");
ValidationResult validationResult = testKey.validate("");