TSK-1571: fixed test which breaks after 22:00 local time

This commit is contained in:
Mustapha Zorgati 2021-02-13 23:34:20 +01:00
parent 2a643bc298
commit c8a7660208
3 changed files with 30 additions and 5 deletions

View File

@ -1,7 +1,7 @@
package pro.taskana.common.test.security;
import static org.junit.platform.commons.support.AnnotationSupport.isAnnotated;
import static pro.taskana.common.internal.util.CheckedFunction.wrap;
import static pro.taskana.common.internal.util.CheckedFunction.wrapExceptFor;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Constructor;
@ -34,6 +34,7 @@ import org.junit.jupiter.api.extension.TestTemplateInvocationContext;
import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider;
import org.junit.platform.commons.JUnitException;
import org.junit.platform.commons.support.AnnotationSupport;
import org.opentest4j.TestAbortedException;
import pro.taskana.common.api.exceptions.SystemException;
import pro.taskana.common.api.security.GroupPrincipal;
@ -243,7 +244,8 @@ public class JaasExtension implements InvocationInterceptor, TestTemplateInvocat
Subject subject = new Subject();
subject.getPrincipals().addAll(getPrincipals(withAccessId));
Function<Invocation<T>, T> proceedInvocation = wrap(Invocation::proceed);
Function<Invocation<T>, T> proceedInvocation =
wrapExceptFor(Invocation::proceed, TestAbortedException.class);
PrivilegedAction<T> performInvocation = () -> proceedInvocation.apply(invocation);
return Subject.doAs(subject, performInvocation);
}

View File

@ -16,5 +16,20 @@ public interface CheckedFunction<T, E> {
};
}
static <T, E> Function<T, E> wrapExceptFor(
CheckedFunction<T, E> checkedFunction, Class<? extends RuntimeException> ignore) {
return t -> {
try {
return checkedFunction.apply(t);
} catch (Throwable e) {
if (e.getClass().equals(ignore)) {
throw (RuntimeException) e;
} else {
throw new SystemException("Caught exception", e);
}
}
};
}
E apply(T t) throws Throwable;
}

View File

@ -3,10 +3,12 @@ package acceptance.task;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assumptions.assumeThat;
import acceptance.AbstractAccTest;
import java.time.Duration;
import java.time.Instant;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
@ -146,11 +148,17 @@ class ServiceLevelPriorityAccTest extends AbstractAccTest {
@WithAccessId(user = "user-1-1")
@Test
void should_VerifyThatCreateAndPlannedAreClose() throws Exception {
Instant now = Instant.now().truncatedTo(ChronoUnit.MILLIS);
Instant inTwoHours = now.plus(2, ChronoUnit.HOURS);
assumeThat(now.atZone(ZoneId.systemDefault()).getDayOfYear())
.describedAs(
"Today (%s) and in two hours (%s) should be the same day",
now.atZone(ZoneId.systemDefault()), inTwoHours.atZone(ZoneId.systemDefault()))
.isEqualTo(inTwoHours.atZone(ZoneId.systemDefault()).getDayOfYear());
Task newTask = taskService.newTask("USER-1-1", "DOMAIN_A");
Instant planned =
moveForwardToWorkingDay(
Instant.now().truncatedTo(ChronoUnit.MILLIS).plus(2, ChronoUnit.HOURS));
Instant planned = moveForwardToWorkingDay(inTwoHours);
newTask.setClassificationKey("T2100");
newTask.setPrimaryObjRef(
createObjectReference("COMPANY_A", "SYSTEM_A", "INSTANCE_A", "VNR", "1234567"));