Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 [Core] Added missing error message for KapuaEntityUniquenessException #4039

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*/
public class KapuaEntityUniquenessException extends KapuaException {

private static final long serialVersionUID = -5398114226720500553L;

private final String entityType;
private final List<Map.Entry<String, Object>> uniquesFieldValues;

Expand All @@ -35,7 +37,7 @@ public class KapuaEntityUniquenessException extends KapuaException {
* @since 1.0.0
*/
public KapuaEntityUniquenessException(String entityType, List<Map.Entry<String, Object>> uniquesFieldValues) {
super(KapuaErrorCodes.ENTITY_UNIQUENESS, uniquesFieldValues);
super(KapuaErrorCodes.ENTITY_UNIQUENESS, entityType, uniquesFieldValues);

this.entityType = entityType;
this.uniquesFieldValues = uniquesFieldValues;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ENTITY_CLONE_ERROR=Severe error while cloning: {0}
ENTITY_NOT_FOUND=The entity of type {0} with id/name {1} was not found.
ENTITY_PROPERTIES_READ_ERROR=Error while reading {0} from KapuaEntity. String-formatted value is: {1}
ENTITY_PROPERTIES_WRITE_ERROR=Error while writing {0} to KapuaEntity. Properties are: {1}
ENTITY_UNIQUENESS=Duplicate {0} entry for values: {1}
EXTERNAL_ID_ALREADY_EXIST_IN_ANOTHER_ACCOUNT=An entity with the same external id {0} already exists in another account.
ILLEGAL_ACCESS=The current subject is not authorized for {0}.
ILLEGAL_ARGUMENT=An illegal value was provided for the argument {0}: {1}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,66 +17,36 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.mockito.Mockito;

import java.util.AbstractMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;



@Category(JUnitTests.class)
public class KapuaEntityUniquenessExceptionTest {

String[] entityType;
List<Map.Entry<String, Object>> uniquesFieldValues;
Map.Entry mapEntry;

@Before
public void initialize() {
entityType = new String[]{"Entity Type", null};
entityType = new String[] { "AEntity", "AnotherEntity" };
uniquesFieldValues = new LinkedList<>();
mapEntry = Mockito.mock(Map.Entry.class);
uniquesFieldValues.add(mapEntry);
uniquesFieldValues.add(mapEntry);
uniquesFieldValues.add(null);
}

@Test
public void kapuaEntityUniquenessExceptionTest() {
for (String type : entityType) {
KapuaEntityUniquenessException kapuaEntityUniquenessException1 = new KapuaEntityUniquenessException(type, uniquesFieldValues);
Assert.assertEquals("Expected and actual values should be the same.", type, kapuaEntityUniquenessException1.getEntityType());
Assert.assertEquals("Expected and actual values should be the same.", uniquesFieldValues, kapuaEntityUniquenessException1.getUniquesFieldValues());
Assert.assertEquals("Expected and actual values should be the same.", KapuaErrorCodes.ENTITY_UNIQUENESS, kapuaEntityUniquenessException1.getCode());
Assert.assertEquals("Expected and actual values should be the same.", "Error: " + uniquesFieldValues, kapuaEntityUniquenessException1.getMessage());
Assert.assertNull("Null expected.", kapuaEntityUniquenessException1.getCause());
}
uniquesFieldValues.add(new AbstractMap.SimpleEntry<>("aField", "aValue"));
uniquesFieldValues.add(new AbstractMap.SimpleEntry<>("anotherField", "anotherValue"));
}

@Test
public void kapuaEntityUniquenessExceptionNullFieldValuesTest() {
for (String type : entityType) {
KapuaEntityUniquenessException kapuaEntityUniquenessException2 = new KapuaEntityUniquenessException(type, null);
Assert.assertEquals("Expected and actual values should be the same.", type, kapuaEntityUniquenessException2.getEntityType());
Assert.assertNull("Null expected.", kapuaEntityUniquenessException2.getUniquesFieldValues());
Assert.assertEquals("Expected and actual values should be the same.", KapuaErrorCodes.ENTITY_UNIQUENESS, kapuaEntityUniquenessException2.getCode());
Assert.assertEquals("Expected and actual values should be the same.", "Error: null", kapuaEntityUniquenessException2.getMessage());
Assert.assertNull("Null expected.", kapuaEntityUniquenessException2.getCause());
}
}

@Test(expected = KapuaEntityUniquenessException.class)
public void throwingExceptionTest() throws KapuaEntityUniquenessException {
for (String type : entityType) {
throw new KapuaEntityUniquenessException(type, uniquesFieldValues);
}
}

@Test(expected = KapuaEntityUniquenessException.class)
public void throwingExceptionNullFieldValuesTest() throws KapuaEntityUniquenessException {
public void kapuaEntityUniquenessExceptionTest() {
for (String type : entityType) {
throw new KapuaEntityUniquenessException(type, null);
KapuaEntityUniquenessException kapuaEntityUniquenessException = new KapuaEntityUniquenessException(type, uniquesFieldValues);
Assert.assertEquals(type, kapuaEntityUniquenessException.getEntityType());
Assert.assertEquals(uniquesFieldValues, kapuaEntityUniquenessException.getUniquesFieldValues());
Assert.assertEquals(KapuaErrorCodes.ENTITY_UNIQUENESS, kapuaEntityUniquenessException.getCode());
Assert.assertEquals("Duplicate " + type + " entry for values: " + uniquesFieldValues, kapuaEntityUniquenessException.getMessage());
Assert.assertNull("Null expected.", kapuaEntityUniquenessException.getCause());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void kapuaIllegalArgumentExceptionKapuaErrorCodesStringParametersTest() {
"Error: " + name + ", " + value,
"An entity with the same name " + name + " already exists.",
"An entity with the same external Id " + name + " already exists.",
"Error: " + name + ", " + value,
"Duplicate " + name + " entry for values: " + value,
"The current subject is not authorized for " + name + ".",
"An illegal value was provided for the argument " + name + ": " + value + ".",
"An illegal null value was provided for the argument " + name + ".",
Expand Down
Loading