package jnpf.dmsController.filecenter; import cn.dev33.satoken.same.SaSameUtil; import jnpf.base.ActionResult; import jnpf.dmsEntity.center.DmsCenterDisableCommand; import jnpf.dmsPermission.DmsTrustedServiceGuard; import jnpf.dmsService.DmsApprovedDisableClient; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; class DmsCenterCommandControllerTest { @Test void returnsRealResultOnlyAfterSameTokenAndTrustedCallerChecks() { DmsTrustedServiceGuard guard=mock(DmsTrustedServiceGuard.class); DmsApprovedDisableClient executor=mock(DmsApprovedDisableClient.class); DmsCenterCommandController controller=new DmsCenterCommandController(guard,executor); DmsCenterDisableCommand command=new DmsCenterDisableCommand(); ActionResult ok=new ActionResult<>();ok.setCode(200); when(executor.disable(command)).thenReturn(ok); try(var same=mockStatic(SaSameUtil.class)) { var result=controller.disable("jnpf-file",command); assertEquals(200,result.getStatusCode().value());assertSame(ok,result.getBody()); same.verify(SaSameUtil::checkCurrentRequestToken); var order=inOrder(guard,executor);order.verify(guard).requireAllowed("jnpf-file");order.verify(executor).disable(command); clearInvocations(executor); doThrow(new IllegalArgumentException("untrusted")).when(guard).requireAllowed("unknown"); assertThrows(IllegalArgumentException.class,()->controller.disable("unknown",command));verifyNoInteractions(executor); } } }