Search in sources :

Example 46 with Operation

use of com.sequenceiq.freeipa.entity.Operation in project cloudbreak by hortonworks.

the class UserSyncAcceptorTest method testSingleUserSyncRejectedOnUserAndEnvOverlap.

@Test
void testSingleUserSyncRejectedOnUserAndEnvOverlap() {
    Operation syncOperation = mock(Operation.class);
    when(syncOperation.getUserList()).thenReturn(List.of("userA", "userB"));
    when(syncOperation.getEnvironmentList()).thenReturn(List.of("envA"));
    Operation runningSyncOperation = mock(Operation.class);
    when(runningSyncOperation.getUserList()).thenReturn(List.of("userA"));
    when(runningSyncOperation.getEnvironmentList()).thenReturn(List.of("envA"));
    assertTrue(userSyncAcceptor.doOperationsConflict(syncOperation, runningSyncOperation));
}
Also used : Operation(com.sequenceiq.freeipa.entity.Operation) Test(org.junit.jupiter.api.Test)

Example 47 with Operation

use of com.sequenceiq.freeipa.entity.Operation in project cloudbreak by hortonworks.

the class BindUserCreateServiceTest method testOperationRejected.

@Test
public void testOperationRejected() {
    BindUserCreateRequest request = createRequest();
    Operation operation = new Operation();
    operation.setOperationId("op");
    operation.setStatus(OperationState.REJECTED);
    when(operationService.startOperation(eq(ACCOUNT), eq(OperationType.BIND_USER_CREATE), anyCollection(), anyCollection())).thenReturn(operation);
    OperationStatus operationStatus = new OperationStatus();
    when(operationConverter.convert(operation)).thenReturn(operationStatus);
    OperationStatus response = underTest.createBindUser(ACCOUNT, request);
    assertEquals(operationStatus, response);
    verifyNoInteractions(flowManager);
}
Also used : BindUserCreateRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.binduser.BindUserCreateRequest) OperationStatus(com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus) Operation(com.sequenceiq.freeipa.entity.Operation) Test(org.junit.jupiter.api.Test)

Example 48 with Operation

use of com.sequenceiq.freeipa.entity.Operation in project cloudbreak by hortonworks.

the class BindUserCreateServiceTest method testFlowRejected.

@Test
public void testFlowRejected() {
    BindUserCreateRequest request = createRequest();
    Operation operation = new Operation();
    operation.setOperationId("op");
    operation.setStatus(OperationState.RUNNING);
    Operation failedOperation = new Operation();
    failedOperation.setOperationId("op");
    failedOperation.setStatus(OperationState.FAILED);
    when(operationService.startOperation(eq(ACCOUNT), eq(OperationType.BIND_USER_CREATE), anyCollection(), anyCollection())).thenReturn(operation);
    when(operationService.failOperation(ACCOUNT, operation.getOperationId(), "Couldn't start create bind user flow: Flow failure")).thenReturn(failedOperation);
    OperationStatus failedOperationStatus = new OperationStatus();
    failedOperationStatus.setStatus(OperationState.FAILED);
    when(operationConverter.convert(failedOperation)).thenReturn(failedOperationStatus);
    when(flowManager.notify(anyString(), any(Acceptable.class))).thenThrow(new RuntimeException("Flow failure"));
    OperationStatus response = underTest.createBindUser(ACCOUNT, request);
    assertEquals(failedOperationStatus, response);
}
Also used : BindUserCreateRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.binduser.BindUserCreateRequest) OperationStatus(com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) Operation(com.sequenceiq.freeipa.entity.Operation) Test(org.junit.jupiter.api.Test)

Example 49 with Operation

use of com.sequenceiq.freeipa.entity.Operation in project cloudbreak by hortonworks.

the class EnvironmentUserSyncStateCalculatorTest method internalCalculateEnvironmentUserSyncStateLastSyncTimedout.

@Test
void internalCalculateEnvironmentUserSyncStateLastSyncTimedout() {
    UserSyncStatus userSyncStatus = new UserSyncStatus();
    Operation lastSync = new Operation();
    lastSync.setOperationId(UUID.randomUUID().toString());
    lastSync.setStatus(OperationState.FAILED);
    userSyncStatus.setLastStartedFullSync(lastSync);
    EnvironmentUserSyncState result = underTest.internalCalculateEnvironmentUserSyncState(ACCOUNT_ID, ENVIRONMENT_CRN, Optional.of(userSyncStatus));
    assertEquals(UserSyncState.SYNC_FAILED, result.getState());
    assertEquals(lastSync.getOperationId(), result.getLastUserSyncOperationId());
}
Also used : UserSyncStatus(com.sequenceiq.freeipa.entity.UserSyncStatus) Operation(com.sequenceiq.freeipa.entity.Operation) EnvironmentUserSyncState(com.sequenceiq.freeipa.api.v1.freeipa.user.model.EnvironmentUserSyncState) Test(org.junit.jupiter.api.Test)

Example 50 with Operation

use of com.sequenceiq.freeipa.entity.Operation in project cloudbreak by hortonworks.

the class EnvironmentUserSyncStateCalculatorTest method internalCalculateEnvironmentUserSyncStateLastSyncRequested.

@Test
void internalCalculateEnvironmentUserSyncStateLastSyncRequested() {
    UserSyncStatus userSyncStatus = new UserSyncStatus();
    Operation lastSync = new Operation();
    lastSync.setOperationId(UUID.randomUUID().toString());
    lastSync.setStatus(OperationState.REQUESTED);
    userSyncStatus.setLastStartedFullSync(lastSync);
    assertThrows(IllegalStateException.class, () -> underTest.internalCalculateEnvironmentUserSyncState(ACCOUNT_ID, ENVIRONMENT_CRN, Optional.of(userSyncStatus)));
}
Also used : UserSyncStatus(com.sequenceiq.freeipa.entity.UserSyncStatus) Operation(com.sequenceiq.freeipa.entity.Operation) Test(org.junit.jupiter.api.Test)

Aggregations

Operation (com.sequenceiq.freeipa.entity.Operation)88 Test (org.junit.jupiter.api.Test)55 Stack (com.sequenceiq.freeipa.entity.Stack)23 UserSyncStatus (com.sequenceiq.freeipa.entity.UserSyncStatus)18 SyncOperationStatus (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus)15 OperationToSyncOperationStatus (com.sequenceiq.freeipa.converter.freeipa.user.OperationToSyncOperationStatus)12 AcceptResult (com.sequenceiq.freeipa.service.freeipa.user.AcceptResult)11 UserSyncRequestFilter (com.sequenceiq.freeipa.service.freeipa.user.UserSyncRequestFilter)10 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)9 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)8 EnvironmentUserSyncState (com.sequenceiq.freeipa.api.v1.freeipa.user.model.EnvironmentUserSyncState)7 OperationType (com.sequenceiq.freeipa.api.v1.operation.model.OperationType)7 OperationStatus (com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus)6 UserSyncOptions (com.sequenceiq.freeipa.service.freeipa.user.model.UserSyncOptions)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 Acceptable (com.sequenceiq.cloudbreak.common.event.Acceptable)5 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)5 FreeIpaUpgradeResponse (com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.FreeIpaUpgradeResponse)4 SynchronizeAllUsersRequest (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizeAllUsersRequest)4 CustomPermissionCheck (com.sequenceiq.authorization.annotation.CustomPermissionCheck)3