TSK-1115: Validate that Service Level is not negative (#1454)
This commit is contained in:
parent
92b49fc850
commit
abfa07ce6a
|
@ -315,9 +315,10 @@ public class ClassificationServiceImpl implements ClassificationService {
|
|||
}
|
||||
|
||||
private static void validateServiceLevel(String serviceLevel) throws InvalidArgumentException {
|
||||
try {
|
||||
Duration.parse(serviceLevel);
|
||||
Duration duration;
|
||||
|
||||
try {
|
||||
duration = Duration.parse(serviceLevel);
|
||||
} catch (Exception e) {
|
||||
throw new InvalidArgumentException(
|
||||
String.format(
|
||||
|
@ -328,10 +329,16 @@ public class ClassificationServiceImpl implements ClassificationService {
|
|||
serviceLevel),
|
||||
e.getCause());
|
||||
}
|
||||
// check that the duration is based on format PnD, i.e. it must start with a P, end with a D
|
||||
String serviceLevelLower = serviceLevel.toLowerCase();
|
||||
if (!serviceLevelLower.startsWith("p") || !serviceLevelLower.endsWith("d")) {
|
||||
|
||||
if (duration.isNegative()) {
|
||||
throw new InvalidArgumentException(
|
||||
String.format(
|
||||
"Invalid service level %s. Taskana does not support a negative service level.",
|
||||
serviceLevel));
|
||||
}
|
||||
|
||||
// check that the duration is based on format PnD, i.e. it must start with a P, end with a D
|
||||
if (!serviceLevel.toLowerCase().startsWith("p") || !serviceLevel.toLowerCase().endsWith("d")) {
|
||||
throw new InvalidArgumentException(
|
||||
String.format(
|
||||
"Invalid service level %s. Taskana only supports service "
|
||||
|
|
|
@ -165,6 +165,17 @@ class CreateClassificationAccTest extends AbstractAccTest {
|
|||
.isInstanceOf(InvalidArgumentException.class);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "businessadmin")
|
||||
@Test
|
||||
void should_ThrowException_When_TryingToCreateClassificationWithNegativeServiceLevel() {
|
||||
Classification classification =
|
||||
CLASSIFICATION_SERVICE.newClassification("someKey234", "DOMAIN_A", "TASK");
|
||||
classification.setServiceLevel("P-1D");
|
||||
|
||||
assertThatThrownBy(() -> CLASSIFICATION_SERVICE.createClassification(classification))
|
||||
.isInstanceOf(InvalidArgumentException.class);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "businessadmin")
|
||||
@Test
|
||||
void testCreateClassificationWithInvalidValues() {
|
||||
|
|
Loading…
Reference in New Issue