use of org.mockito.Mock in project CzechIdMng by bcvsolutions.
the class RemoveRoleCompositionTaskExecutorIntegrationTest method testRemoveAssignedRolesWithExceptionOnEnd.
@Test
public void testRemoveAssignedRolesWithExceptionOnEnd() {
// prepare role composition
IdmRoleDto superior = getHelper().createRole();
IdmRoleDto subOne = getHelper().createRole();
IdmRoleDto subOneSub = getHelper().createRole();
getHelper().createRoleComposition(superior, subOne);
IdmRoleCompositionDto subOneSubRoleComposition = getHelper().createRoleComposition(subOne, subOneSub);
//
// assign superior role
IdmIdentityDto identity = getHelper().createIdentity();
getHelper().createIdentityRole(identity, superior);
//
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(3, assignedRoles.size());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(superior.getId())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(subOne.getId())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(subOneSub.getId())));
//
// remove role composition by task with mock service => we want to throw exception
Mockito.when(mockIdentityRoleService.count(ArgumentMatchers.any(IdmIdentityRoleFilter.class))).thenReturn(1L);
Mockito.when(mockIdentityRoleService.find(ArgumentMatchers.any(IdmIdentityRoleFilter.class), ArgumentMatchers.isNull())).then(new AssignedRolesAnswer(subOneSubRoleComposition.getId()));
RemoveRoleCompositionTaskExecutor taskExecutor = new RemoveRoleCompositionTaskExecutor();
AutowireHelper.autowire(taskExecutor);
IdmLongRunningTaskDto lrt = longRunningTaskManager.resolveLongRunningTask(taskExecutor, null, OperationState.RUNNING);
UUID taskId = lrt.getId();
taskExecutor.setIdentityRoleService(mockIdentityRoleService);
taskExecutor.setRoleCompositionId(subOneSubRoleComposition.getId());
//
try {
getHelper().setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, true);
taskExecutor.call();
getHelper().waitForResult(res -> {
return longRunningTaskManager.getLongRunningTask(taskId).getResultState().isRunnable();
});
} finally {
getHelper().setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, false);
}
//
// long running task has a proper state with exception
lrt = longRunningTaskManager.getLongRunningTask(lrt.getId());
Assert.assertEquals(OperationState.EXCEPTION, lrt.getResultState());
Assert.assertEquals(CoreResultCode.ROLE_COMPOSITION_REMOVE_HAS_ASSIGNED_ROLES.name(), lrt.getResult().getCode());
//
// start event is ended
IdmEntityEventFilter eventFilter = new IdmEntityEventFilter();
eventFilter.setTransactionId(lrt.getTransactionId());
eventFilter.setEventType(LongRunningTaskEventType.START.name());
List<IdmEntityEventDto> startEvents = entityEventManager.findEvents(eventFilter, null).getContent();
Assert.assertEquals(1, startEvents.size());
Assert.assertEquals(OperationState.EXECUTED, startEvents.get(0).getResult().getState());
//
// business role still exists
Assert.assertNotNull(roleCompositionService.get(subOneSubRoleComposition));
//
// but assigned roles should be removed
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(2, assignedRoles.size());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(superior.getId())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(subOne.getId())));
}
use of org.mockito.Mock in project pravega by pravega.
the class FlowHandlerTest method testHelloWithErrorReplyProcessor.
@Test
public void testHelloWithErrorReplyProcessor() throws Exception {
ReplyProcessor errorProcessor = mock(ReplyProcessor.class);
@Cleanup ClientConnection connection1 = flowHandler.createFlow(new Flow(11, 0), errorProcessor);
@Cleanup ClientConnection connection2 = flowHandler.createFlow(flow, processor);
doAnswer((Answer<Void>) invocation -> {
throw new RuntimeException("Reply processor error");
}).when(errorProcessor).hello(any(WireCommands.Hello.class));
final WireCommands.Hello msg = new WireCommands.Hello(5, 4);
flowHandler.process(msg);
verify(processor).hello(msg);
verify(errorProcessor).hello(msg);
}
use of org.mockito.Mock in project sonarlint-core by SonarSource.
the class IssueExclusionsRegexpScannerTests method init.
@BeforeEach
void init() {
MockitoAnnotations.initMocks(this);
blockPatterns = Arrays.asList(new DoubleRegexpMatcher(Pattern.compile("// SONAR-OFF"), Pattern.compile("// SONAR-ON")), new DoubleRegexpMatcher(Pattern.compile("// FOO-OFF"), Pattern.compile("// FOO-ON")));
allFilePatterns = Collections.singletonList(Pattern.compile("@SONAR-IGNORE-ALL"));
javaFile = new SonarLintInputFile(new OnDiskTestClientInputFile(Paths.get("src/Foo.java"), "src/Foo.java", false, StandardCharsets.UTF_8), f -> mock(Metadata.class));
regexpScanner = new IssueExclusionsRegexpScanner(javaFile, allFilePatterns, blockPatterns);
}
use of org.mockito.Mock in project kie-wb-common by kiegroup.
the class GeneralSettingsPresenterTest method testExecuteValidationFailing.
@Test
public void testExecuteValidationFailing() {
final POM pom = mock(POM.class);
doReturn(false).when(validationService).validate(eq(pom));
generalSettingsPresenter.executeValidation(s -> s.validate(pom), "Test message").then(valid -> {
Assert.fail("Promise should've been resolved!");
return promises.resolve();
}).catch_(e -> {
verify(validationService).validate(eq(pom));
Assert.assertEquals(e, "Test message");
return promises.resolve();
});
}
use of org.mockito.Mock in project kie-wb-common by kiegroup.
the class GeneralSettingsPresenterTest method testExecuteValidation.
@Test
public void testExecuteValidation() {
final POM pom = mock(POM.class);
doReturn(true).when(validationService).validate(eq(pom));
generalSettingsPresenter.executeValidation(s -> s.validate(pom), "Test message").then(valid -> {
verify(validationService).validate(eq(pom));
Assert.assertEquals(valid, true);
return promises.resolve();
}).catch_(e -> {
Assert.fail("Promise should've been resolved!");
return promises.resolve();
});
}
Aggregations