use of com.sequenceiq.flow.core.helloworld.config.HelloWorldFlowConfig in project cloudbreak by hortonworks.
the class Flow2HandlerTest method testNewSyncFlowMaintenanceActive.
@Test
public void testNewSyncFlowMaintenanceActive() {
HelloWorldFlowConfig helloWorldFlowConfig = mock(HelloWorldFlowConfig.class);
given(helloWorldFlowConfig.getFlowTriggerCondition()).willReturn(new DefaultFlowTriggerCondition());
BDDMockito.<FlowConfiguration<?>>given(flowConfigurationMap.get(any())).willReturn(helloWorldFlowConfig);
given(helloWorldFlowConfig.createFlow(anyString(), any(), anyLong(), any())).willReturn(flow);
given(helloWorldFlowConfig.getFlowTriggerCondition()).willReturn(flowTriggerCondition);
given(helloWorldFlowConfig.getFlowOperationType()).willReturn(OperationType.UNKNOWN);
given(flowTriggerCondition.isFlowTriggerable(anyLong())).willReturn(FlowTriggerConditionResult.OK);
given(flow.getCurrentState()).willReturn(flowState);
Event<Payload> event = new Event<>(payload);
event.setKey("KEY");
event.getHeaders().set(FlowConstants.FLOW_TRIGGER_USERCRN, FLOW_TRIGGER_USERCRN);
underTest.accept(event);
verify(flowConfigurationMap, times(1)).get(anyString());
verify(runningFlows, times(1)).put(eq(flow), isNull(String.class));
verify(flowLogService, times(1)).save(any(FlowParameters.class), nullable(String.class), eq("KEY"), any(Payload.class), any(), ArgumentMatchers.eq(helloWorldFlowConfig.getClass()), eq(flowState));
verify(flow, times(1)).sendEvent(anyString(), anyString(), any(), any(), eq(UNKNOWN_OP_TYPE));
}
use of com.sequenceiq.flow.core.helloworld.config.HelloWorldFlowConfig in project cloudbreak by hortonworks.
the class Flow2HandlerTest method testRestartFlow.
@Test
public void testRestartFlow() throws TransactionExecutionException {
FlowLog flowLog = createFlowLog(FLOW_CHAIN_ID);
Payload payload = new TestPayload(STACK_ID);
flowLog.setPayloadType(ClassValue.of(TestPayload.class));
flowLog.setPayload(JsonWriter.objectToJson(payload));
when(flowLogService.findFirstByFlowIdOrderByCreatedDesc(FLOW_ID)).thenReturn(Optional.of(flowLog));
HelloWorldFlowConfig helloWorldFlowConfig = new HelloWorldFlowConfig();
ReflectionTestUtils.setField(helloWorldFlowConfig, "defaultRestartAction", defaultRestartAction);
setUpFlowConfigCreateFlow(helloWorldFlowConfig);
List<FlowConfiguration<?>> flowConfigs = Lists.newArrayList(helloWorldFlowConfig);
ReflectionTestUtils.setField(underTest, "flowConfigs", flowConfigs);
underTest.restartFlow(FLOW_ID);
ArgumentCaptor<Payload> payloadCaptor = ArgumentCaptor.forClass(Payload.class);
ArgumentCaptor<FlowParameters> flowParamsCaptor = ArgumentCaptor.forClass(FlowParameters.class);
verify(flowChainHandler, times(1)).restoreFlowChain(FLOW_CHAIN_ID);
verify(flowLogService, never()).terminate(STACK_ID, FLOW_ID);
verify(defaultRestartAction, times(1)).restart(flowParamsCaptor.capture(), eq(FLOW_CHAIN_ID), eq(NEXT_EVENT), payloadCaptor.capture());
Payload captorValue = payloadCaptor.getValue();
assertEquals(STACK_ID, captorValue.getResourceId());
FlowParameters flowParameters = flowParamsCaptor.getValue();
assertEquals(FLOW_ID, flowParameters.getFlowId());
assertEquals(FLOW_TRIGGER_USERCRN, flowParameters.getFlowTriggerUserCrn());
}
use of com.sequenceiq.flow.core.helloworld.config.HelloWorldFlowConfig in project cloudbreak by hortonworks.
the class Flow2HandlerTest method testRestartFlowNoRestartAction.
@Test
public void testRestartFlowNoRestartAction() throws TransactionExecutionException {
FlowLog flowLog = createFlowLog(FLOW_CHAIN_ID);
Payload payload = new TestPayload(STACK_ID);
flowLog.setPayloadType(ClassValue.of(TestPayload.class));
flowLog.setPayload(JsonWriter.objectToJson(payload));
when(flowLogService.findFirstByFlowIdOrderByCreatedDesc(FLOW_ID)).thenReturn(Optional.of(flowLog));
HelloWorldFlowConfig helloWorldFlowConfig = new HelloWorldFlowConfig();
setUpFlowConfigCreateFlow(helloWorldFlowConfig);
List<FlowConfiguration<?>> flowConfigs = Lists.newArrayList(helloWorldFlowConfig);
ReflectionTestUtils.setField(underTest, "flowConfigs", flowConfigs);
underTest.restartFlow(FLOW_ID);
verify(flowChainHandler, times(1)).restoreFlowChain(FLOW_CHAIN_ID);
verify(flowLogService, times(1)).terminate(STACK_ID, FLOW_ID);
verify(defaultRestartAction, never()).restart(any(), any(), any(), any());
}
use of com.sequenceiq.flow.core.helloworld.config.HelloWorldFlowConfig in project cloudbreak by hortonworks.
the class Flow2ConfigTest method testFlowConfigurationMapInitIfAlreadyExists.
@Test
public void testFlowConfigurationMapInitIfAlreadyExists() {
List<FlowConfiguration<?>> flowConfigs = new ArrayList<>();
HelloWorldFlowConfig helloWorldFlowConfig = new HelloWorldFlowConfig();
flowConfigs.add(helloWorldFlowConfig);
flowConfigs.add(helloWorldFlowConfig);
thrown.expect(UnsupportedOperationException.class);
thrown.expectMessage("Event already registered: " + HelloWorldEvent.HELLOWORLD_TRIGGER_EVENT.event());
underTest.flowConfigurationMap(flowConfigs);
}
use of com.sequenceiq.flow.core.helloworld.config.HelloWorldFlowConfig in project cloudbreak by hortonworks.
the class Flow2HandlerTest method testRestartFlowNoRestartActionNoFlowChainId.
@Test
public void testRestartFlowNoRestartActionNoFlowChainId() throws TransactionExecutionException {
FlowLog flowLog = createFlowLog(null);
Payload payload = new TestPayload(STACK_ID);
flowLog.setPayloadType(ClassValue.of(TestPayload.class));
flowLog.setPayload(JsonWriter.objectToJson(payload));
when(flowLogService.findFirstByFlowIdOrderByCreatedDesc(FLOW_ID)).thenReturn(Optional.of(flowLog));
HelloWorldFlowConfig helloWorldFlowConfig = new HelloWorldFlowConfig();
setUpFlowConfigCreateFlow(helloWorldFlowConfig);
List<FlowConfiguration<?>> flowConfigs = Lists.newArrayList(helloWorldFlowConfig);
ReflectionTestUtils.setField(underTest, "flowConfigs", flowConfigs);
underTest.restartFlow(FLOW_ID);
verify(flowChainHandler, never()).restoreFlowChain(FLOW_CHAIN_ID);
verify(flowLogService, times(1)).terminate(STACK_ID, FLOW_ID);
verify(defaultRestartAction, never()).restart(any(), any(), any(), any());
}
Aggregations