/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
}
final AxArtifactKey otherArtifactKey = (AxArtifactKey) otherKey;
- final Compatibility compatibility = this.getCompatibility(otherArtifactKey);
+ final var compatibility = this.getCompatibility(otherArtifactKey);
return !(compatibility == Compatibility.DIFFERENT || compatibility == Compatibility.MAJOR);
}
*/
@Override
public AxValidationResult validate(final AxValidationResult result) {
- final String nameValidationErrorMessage = Assertions.getStringParameterValidationMessage(NAME_TOKEN, name,
+ final var nameValidationErrorMessage = Assertions.getStringParameterValidationMessage(NAME_TOKEN, name,
NAME_REGEXP);
if (nameValidationErrorMessage != null) {
result.addValidationMessage(new AxValidationMessage(this, this.getClass(), ValidationResult.INVALID,
"name invalid-" + nameValidationErrorMessage));
}
- final String versionValidationErrorMessage = Assertions.getStringParameterValidationMessage(VERSION_TOKEN,
+ final var versionValidationErrorMessage = Assertions.getStringParameterValidationMessage(VERSION_TOKEN,
version, VERSION_REGEXP);
if (versionValidationErrorMessage != null) {
result.addValidationMessage(new AxValidationMessage(this, this.getClass(), ValidationResult.INVALID,
*/
@Override
public String toString() {
- final StringBuilder builder = new StringBuilder();
+ final var builder = new StringBuilder();
builder.append(this.getClass().getSimpleName());
builder.append(":(");
builder.append("name=");
*/
@Override
public int hashCode() {
- final int prime = 31;
- int result = 1;
+ final var prime = 31;
+ var result = 1;
result = prime * result + name.hashCode();
result = prime * result + version.hashCode();
return result;
}
return version.compareTo(other.version);
}
-}
\ No newline at end of file
+}
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Assertions.argumentNotNull(conceptKeyName, "conceptKeyName may not be null");
// The very fist key that could have this name
- final AxArtifactKey lowestArtifactKey = new AxArtifactKey(conceptKeyName, "0.0.1");
+ final var lowestArtifactKey = new AxArtifactKey(conceptKeyName, "0.0.1");
// Check if we found a key for our name
AxArtifactKey foundKey = conceptMap.ceilingKey(lowestArtifactKey);
}
// The very fist key that could have this name
- final AxArtifactKey lowestArtifactKey = new AxArtifactKey(conceptKeyName, "0.0.1");
+ final var lowestArtifactKey = new AxArtifactKey(conceptKeyName, "0.0.1");
if (conceptKeyVersion != null) {
lowestArtifactKey.setVersion(conceptKeyVersion);
}
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
*/
@Override
public String toString() {
- final StringBuilder builder = new StringBuilder();
+ final var builder = new StringBuilder();
builder.append(this.getClass().getSimpleName());
builder.append(":(");
builder.append("artifactId=");
*/
@Override
public int hashCode() {
- final int prime = 31;
- int result = 1;
+ final var prime = 31;
+ var result = 1;
result = prime * result + key.hashCode();
result = prime * result + uuid.hashCode();
result = prime * result + description.hashCode();
* @return the uuid
*/
public static UUID generateReproducibleUuid(final String seed) {
- Random random = sharedRandom;
+ var random = sharedRandom;
if (!StringUtils.isEmpty(seed)) {
/*
* This is not used for encryption/security, thus disabling sonar.
*/
random = new Random(seed.hashCode()); // NOSONAR
}
- final byte[] array = new byte[UUID_BYTE_LENGTH_16];
+ final var array = new byte[UUID_BYTE_LENGTH_16];
random.nextBytes(array);
return UUID.nameUUIDFromBytes(array);
}
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
final AxArtifactKey artifactKey = (AxArtifactKey) axKey;
keyInfoMap.computeIfAbsent(artifactKey, unusedKey -> {
- final AxKeyInfo keyInfo = new AxKeyInfo(artifactKey);
+ final var keyInfo = new AxKeyInfo(artifactKey);
// generate a reproducible UUID
keyInfo.setUuid(AxKeyInfo.generateReproducibleUuid(keyInfo.getId() + keyInfo.getDescription()));
return keyInfo;
*/
@Override
public String toString() {
- final StringBuilder builder = new StringBuilder();
+ final var builder = new StringBuilder();
builder.append(this.getClass().getSimpleName());
builder.append(":(");
builder.append("key=");
*/
@Override
public int hashCode() {
- final int prime = 31;
- int result = 1;
+ final var prime = 31;
+ var result = 1;
result = prime * result + key.hashCode();
result = prime * result + keyInfoMap.hashCode();
return result;
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
@Override
public String toString() {
- final StringBuilder builder = new StringBuilder();
+ final var builder = new StringBuilder();
builder.append(this.getClass().getSimpleName());
builder.append(":(");
builder.append("usedKey=");
*/
@Override
public int hashCode() {
- final int prime = 31;
- int result = 1;
+ final var prime = 31;
+ var result = 1;
result = prime * result + usedKey.hashCode();
return result;
}
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
*/
@Override
public String toString() {
- final StringBuilder builder = new StringBuilder();
+ final var builder = new StringBuilder();
builder.append(this.getClass().getSimpleName());
builder.append(":(");
builder.append("key=");
*/
@Override
public int hashCode() {
- final int prime = 31;
- int result = 1;
+ final var prime = 31;
+ var result = 1;
result = prime * result + key.hashCode();
result = prime * result + keyInformation.hashCode();
return result;
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* the key ID in a format that respects the KEY_ID_REGEXP
*/
public AxReferenceKey(final String id) {
- final String conditionedId = Assertions.validateStringParameter("id", id, REFERENCE_KEY_ID_REGEXP);
+ final var conditionedId = Assertions.validateStringParameter("id", id, REFERENCE_KEY_ID_REGEXP);
// Split on colon, if the id passes the regular expression test above
// it'll have just three colons separating the parent name,
*/
@Override
public AxValidationResult validate(final AxValidationResult result) {
- final String parentNameValidationErrorMessage = Assertions.getStringParameterValidationMessage(PARENT_KEY_NAME,
+ final var parentNameValidationErrorMessage = Assertions.getStringParameterValidationMessage(PARENT_KEY_NAME,
parentKeyName, NAME_REGEXP);
if (parentNameValidationErrorMessage != null) {
result.addValidationMessage(new AxValidationMessage(this, this.getClass(), ValidationResult.INVALID,
"parentKeyName invalid-" + parentNameValidationErrorMessage));
}
- final String parentKeyVersionValidationErrorMessage = Assertions
+ final var parentKeyVersionValidationErrorMessage = Assertions
.getStringParameterValidationMessage(PARENT_KEY_VERSION, parentKeyVersion, VERSION_REGEXP);
if (parentKeyVersionValidationErrorMessage != null) {
result.addValidationMessage(new AxValidationMessage(this, this.getClass(), ValidationResult.INVALID,
"parentKeyVersion invalid-" + parentKeyVersionValidationErrorMessage));
}
- final String parentLocalNameValidationErrorMessage = Assertions
+ final var parentLocalNameValidationErrorMessage = Assertions
.getStringParameterValidationMessage(PARENT_LOCAL_NAME, parentLocalName, LOCAL_NAME_REGEXP);
if (parentLocalNameValidationErrorMessage != null) {
result.addValidationMessage(new AxValidationMessage(this, this.getClass(), ValidationResult.INVALID,
"parentLocalName invalid-" + parentLocalNameValidationErrorMessage));
}
- final String localNameValidationErrorMessage = Assertions.getStringParameterValidationMessage(LOCAL_NAME,
+ final var localNameValidationErrorMessage = Assertions.getStringParameterValidationMessage(LOCAL_NAME,
localName, LOCAL_NAME_REGEXP);
if (localNameValidationErrorMessage != null) {
result.addValidationMessage(new AxValidationMessage(this, this.getClass(), ValidationResult.INVALID,
*/
@Override
public String toString() {
- final StringBuilder builder = new StringBuilder();
+ final var builder = new StringBuilder();
builder.append(this.getClass().getSimpleName());
builder.append(":(");
builder.append("parentKeyName=");
*/
@Override
public int hashCode() {
- final int prime = 31;
- int result = 1;
+ final var prime = 31;
+ var result = 1;
result = prime * result + parentKeyName.hashCode();
result = prime * result + parentKeyVersion.hashCode();
result = prime * result + parentLocalName.hashCode();
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
@Override
public final AxReferenceKey unmarshal(final String key) throws Exception {
- final AxReferenceKey axReferenceKey = new AxReferenceKey();
+ final var axReferenceKey = new AxReferenceKey();
axReferenceKey.setLocalName(key);
return axReferenceKey;
}
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix-2020 Foundation.
+ * Modifications Copyright (C) 2019-2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
public class AxKeyInfoTest {
@Test
- public void testAxKeyInfo() {
+ public void testNullAxKeyInfo() {
assertNotNull(new AxKeyInfo());
assertNotNull(new AxKeyInfo(new AxArtifactKey()));
assertNotNull(new AxKeyInfo(new AxArtifactKey(), UUID.randomUUID(), "Key description"));
+ }
+ @Test
+ public void testAxKeyInfo() {
AxKeyInfo testKeyInfo = new AxKeyInfo();
testKeyInfo.setKey((new AxArtifactKey("PN", "0.0.1")));
assertEquals("PN:0.0.1", testKeyInfo.getKey().getId());
assertEquals(0, testKeyInfo.compareTo(new AxKeyInfo(key, uuid, "Key Description")));
assertNotNull(testKeyInfo.getKeys());
+ }
+
+ @Test
+ public void testAxKeyValidation() {
+ AxKeyInfo testKeyInfo = new AxKeyInfo();
+ testKeyInfo.setKey((new AxArtifactKey("PN", "0.0.1")));
AxValidationResult result = new AxValidationResult();
result = testKeyInfo.validate(result);
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import static org.junit.Assert.assertTrue;
import java.lang.reflect.Field;
+import org.junit.Before;
import org.junit.Test;
import org.onap.policy.apex.model.basicmodel.concepts.AxKey.Compatibility;
public class AxKeyTest {
+ private static AxArtifactKey someKey0;
+ private static AxArtifactKey someKey1;
+ private static AxArtifactKey someKey2;
+ private static AxArtifactKey someKey3;
+ private static AxArtifactKey someKey4;
+ private static AxArtifactKey someKey5;
+ private static AxArtifactKey someKey6;
+
+ /**
+ * Sets data in Keys for the tests.
+ */
+ @Before
+ public void setKeys() {
+ someKey0 = new AxArtifactKey();
+ someKey1 = new AxArtifactKey("name", "0.0.1");
+ someKey2 = new AxArtifactKey(someKey1);
+ someKey3 = new AxArtifactKey(someKey1.getId());
+ someKey4 = new AxArtifactKey(someKey1);
+ someKey5 = new AxArtifactKey(someKey1);
+ someKey6 = new AxArtifactKey(someKey1);
+ }
+
+ private void setKeyValues() {
+ someKey0.setName("zero");
+ someKey0.setVersion("0.0.2");
+ someKey3.setVersion("0.0.2");
+ someKey4.setVersion("0.1.2");
+ someKey5.setVersion("1.2.2");
+ someKey6.setVersion("3");
+ }
+
@Test
public void testArtifactKey() {
assertThatThrownBy(() -> new AxArtifactKey("some bad key id"))
.hasMessage("parameter \"id\": value \"some bad key id\", "
+ "does not match regular expression \"[A-Za-z0-9\\-_\\.]+:[0-9].[0-9].[0-9]\"");
- AxArtifactKey someKey0 = new AxArtifactKey();
+
assertEquals(AxArtifactKey.getNullKey(), someKey0);
- AxArtifactKey someKey1 = new AxArtifactKey("name", "0.0.1");
- AxArtifactKey someKey2 = new AxArtifactKey(someKey1);
- AxArtifactKey someKey3 = new AxArtifactKey(someKey1.getId());
assertEquals(someKey1, someKey2);
assertEquals(someKey1, someKey3);
assertEquals(someKey2, someKey1.getKey());
assertEquals(1, someKey1.getKeys().size());
- someKey0.setName("zero");
- someKey0.setVersion("0.0.2");
+ setKeyValues();
- someKey3.setVersion("0.0.2");
+ someKey0.clean();
+ assertNotNull(someKey0.toString());
- AxArtifactKey someKey4 = new AxArtifactKey(someKey1);
- someKey4.setVersion("0.1.2");
+ AxArtifactKey someKey7 = new AxArtifactKey(someKey1);
+ assertEquals(150332875, someKey7.hashCode());
+ assertEquals(0, someKey7.compareTo(someKey1));
+ assertEquals(-12, someKey7.compareTo(someKey0));
- AxArtifactKey someKey5 = new AxArtifactKey(someKey1);
- someKey5.setVersion("1.2.2");
+ assertThatThrownBy(() -> someKey0.compareTo(null))
+ .hasMessage("comparison object may not be null");
+ assertEquals(0, someKey0.compareTo(someKey0));
+ assertEquals(353602977, someKey0.compareTo(new AxReferenceKey()));
- AxArtifactKey someKey6 = new AxArtifactKey(someKey1);
- someKey6.setVersion("3");
+ assertNotNull(someKey0);
+ // disabling sonar because this code tests the equals() method
+ assertEquals(someKey0, someKey0); // NOSONAR
+ assertNotEquals(someKey0, (Object) new AxReferenceKey());
+ }
+
+ @Test
+ public void testAxCompatibility() {
+ setKeyValues();
assertEquals(Compatibility.DIFFERENT, someKey0.getCompatibility(new AxReferenceKey()));
assertEquals(Compatibility.DIFFERENT, someKey0.getCompatibility(someKey1));
assertFalse(someKey1.isCompatible(someKey0));
assertFalse(someKey1.isCompatible(someKey5));
assertFalse(someKey1.isCompatible(new AxReferenceKey()));
+ }
+
+ @Test
+ public void testAxValidation() {
+ setKeyValues();
assertEquals(AxValidationResult.ValidationResult.VALID,
someKey0.validate(new AxValidationResult()).getValidationResult());
someKey5.validate(new AxValidationResult()).getValidationResult());
assertEquals(AxValidationResult.ValidationResult.VALID,
someKey6.validate(new AxValidationResult()).getValidationResult());
+ }
- someKey0.clean();
- assertNotNull(someKey0.toString());
-
- AxArtifactKey someKey7 = new AxArtifactKey(someKey1);
- assertEquals(150332875, someKey7.hashCode());
- assertEquals(0, someKey7.compareTo(someKey1));
- assertEquals(-12, someKey7.compareTo(someKey0));
-
- assertThatThrownBy(() -> someKey0.compareTo(null))
- .hasMessage("comparison object may not be null");
- assertEquals(0, someKey0.compareTo(someKey0));
- assertEquals(353602977, someKey0.compareTo(new AxReferenceKey()));
-
- assertNotNull(someKey0);
- // disabling sonar because this code tests the equals() method
- assertEquals(someKey0, someKey0); // NOSONAR
- assertNotEquals(someKey0, (Object) new AxReferenceKey());
+ @Test
+ public void testNullKey() {
+ setKeyValues();
AxArtifactKey nullKey0 = AxArtifactKey.getNullKey();
assertTrue(nullKey0.isNullKey());
assertTrue(nullKey2.isNullKey());
AxArtifactKey notnullKey = new AxArtifactKey("Blah", AxKey.NULL_KEY_VERSION);
assertFalse(notnullKey.isNullKey());
-
}