add unit tests

This commit is contained in:
Rodica Sutu
2019-11-04 11:39:35 +02:00
parent c33e703be9
commit 671d6b954c
2 changed files with 34 additions and 3 deletions

View File

@@ -95,7 +95,7 @@ public class PropertyModificationAllowedCheck
if (!before.containsKey(key) || !after.containsKey(key))
{
//Property modified check to see if allowed
proceed = whiteList.contains(key);
proceed = allowPropertyUpdate(key);
if (!proceed)
{
break;
@@ -106,7 +106,7 @@ public class PropertyModificationAllowedCheck
(after.get(key) == null && before.get(key) != null))
{
//Property modified check to see if allowed
proceed = whiteList.contains(key);
proceed = allowPropertyUpdate(key);
if (!proceed)
{
break;
@@ -116,7 +116,7 @@ public class PropertyModificationAllowedCheck
if (before.get(key) != null && after.get(key) != null && !(after.get(key).equals(before.get(key))))
{
//Property modified check to see if allowed
proceed = whiteList.contains(key) || getEditableURIs().contains(key.getNamespaceURI());
proceed = allowPropertyUpdate(key);
if (!proceed)
{
break;
@@ -126,5 +126,14 @@ public class PropertyModificationAllowedCheck
return proceed;
}
/**
* Determines whether the property should be allowed to be updated or not.
* @param key property
* @return true if property update us allowed
*/
private boolean allowPropertyUpdate(QName key)
{
return whiteList.contains(key) || getEditableURIs().contains(key.getNamespaceURI());
}
}

View File

@@ -236,4 +236,26 @@ public class PropertyModificationAllowedCheckUnitTest
after.put(qName, null);
assertTrue(propertyModificationAllowedCheck.check(before, after));
}
/**
* Test update of a property from the model URI for which properties can be updated
*/
@Test
public void testUpdatePropertyFromAllowedModelURI()
{
editableURIs.add("foo");
propertyModificationAllowedCheck.setEditableURIs(editableURIs);
assertTrue(propertyModificationAllowedCheck.check(before, after));
}
/**
* Test update of a property that is not in the model URI for which properties can be updated
*/
@Test
public void testUpdatePropertyFromNotAllowedModelURI()
{
editableURIs.add("bar");
propertyModificationAllowedCheck.setEditableURIs(editableURIs);
assertFalse(propertyModificationAllowedCheck.check(before, after));
}
}