use of org.pentaho.platform.api.action.IAction in project pentaho-platform by pentaho.
the class QuartzSchedulerIT method fireJobCompletedTest.
@Test
public void fireJobCompletedTest() throws Exception {
final IAction actionBean = mock(IAction.class);
final String actionUser = "actionUser";
final ISchedulerListener schedulerListener = mock(ISchedulerListener.class);
scheduler.addListener(schedulerListener);
final Map<String, Serializable> params = new HashMap<>();
final IBackgroundExecutionStreamProvider streamProvider = mock(IBackgroundExecutionStreamProvider.class);
scheduler.fireJobCompleted(actionBean, actionUser, params, streamProvider);
verify(schedulerListener, times(1)).jobCompleted(eq(actionBean), eq(actionUser), eq(params), eq(streamProvider));
}
use of org.pentaho.platform.api.action.IAction in project pentaho-platform by pentaho.
the class DefaultPluginManager method getAction.
public IAction getAction(String type, String perspectiveName) {
IAction action = null;
// $NON-NLS-1$
String beanId = (perspectiveName == null) ? type : type + "." + perspectiveName;
try {
action = (IAction) getBean(beanId, IAction.class);
} catch (NoSuchBeanDefinitionException e) {
// fallback condition, look for a type agnostic content generator
try {
action = (IAction) getBean(perspectiveName, IAction.class);
} catch (NoSuchBeanDefinitionException e2) {
throw new NoSuchBeanDefinitionException("Failed to find bean: " + e.getMessage() + " : " + e2.getMessage());
}
}
return action;
}
use of org.pentaho.platform.api.action.IAction in project pentaho-platform by pentaho.
the class ActionRunnerTest method testCallWithStreamProvider.
@Test
public void testCallWithStreamProvider() throws Exception {
Map<String, Serializable> paramsMap = createMapWithUserLocale();
IAction actionBeanSpy = Mockito.spy(new TestAction());
IBackgroundExecutionStreamProvider mockStreamProvider = Mockito.mock(IBackgroundExecutionStreamProvider.class);
InputStream mockInputStream = Mockito.mock(InputStream.class);
OutputStream mockOutputStream = Mockito.mock(OutputStream.class);
when(mockStreamProvider.getInputStream()).thenReturn(mockInputStream);
String mockOutputPath = "/someUser/someOutput";
when(mockStreamProvider.getOutputPath()).thenReturn(mockOutputPath);
when(mockStreamProvider.getOutputStream()).thenReturn(mockOutputStream);
ISecurityHelper mockSecurityHelper = Mockito.mock(ISecurityHelper.class);
SecurityHelper.setMockInstance(mockSecurityHelper);
when(mockSecurityHelper.runAsUser(Mockito.anyString(), Mockito.any())).thenReturn(mockOutputPath);
PowerMockito.mockStatic(PentahoSystem.class);
IUnifiedRepository mockRepository = Mockito.mock(IUnifiedRepository.class);
when(PentahoSystem.get(isA(IUnifiedRepository.class.getClass()), Mockito.any())).thenReturn(mockRepository);
IAuthorizationPolicy mockAuthorizationPolicy = Mockito.mock(IAuthorizationPolicy.class);
when(PentahoSystem.get(isA(IAuthorizationPolicy.class.getClass()), Mockito.any())).thenReturn(mockAuthorizationPolicy);
when(mockAuthorizationPolicy.isAllowed(SchedulerOutputPathResolver.SCHEDULER_ACTION_NAME)).thenReturn(true);
String repoId = "SOME_REPO_ID";
Map<String, Serializable> dummyMetaData = new HashMap<>();
dummyMetaData.put(RepositoryFile.SCHEDULABLE_KEY, true);
when(mockRepository.getFileMetadata(repoId)).thenReturn(dummyMetaData);
RepositoryFile mockRepoFile = Mockito.mock(RepositoryFile.class);
when(mockRepoFile.isFolder()).thenReturn(true);
when(mockRepoFile.getId()).thenReturn(repoId);
ActionRunner actionRunner = new ActionRunner(actionBeanSpy, "actionUser", paramsMap, mockStreamProvider);
actionRunner.call();
Mockito.verify(actionBeanSpy).execute();
}
use of org.pentaho.platform.api.action.IAction in project pentaho-platform by pentaho.
the class ActionDelegate method executeAction.
/**
* Wires up inputs outputs and resources to an Action and executes it.
*/
@Override
protected boolean executeAction() throws Throwable {
//
// Set inputs
//
InputErrorCallback errorCallback = new InputErrorCallback();
for (IActionInput input : getActionDefinition().getInputs()) {
Object inputValue = input.getValue();
if (input instanceof ActionInputConstant) {
// if the input is coming from the component definition section,
// do parameter replacement on the string and the result of that
// is the input value
inputValue = input.getStringValue(true);
}
errorCallback.setValue(inputValue);
actionHarness.setValue(input.getName(), inputValue, errorCallback, COMPATIBILITY_FORMATTER, ALTERNATE_INDEX_FORMATTER);
}
//
// Set resources
//
ResourceCallback resourceCallback = new ResourceCallback();
for (IActionResource res : getActionDefinition().getResources()) {
actionHarness.setValue(res.getName(), res.getInputStream(), resourceCallback, COMPATIBILITY_FORMATTER, ALTERNATE_INDEX_FORMATTER);
}
//
// Provide output stream for the streaming action. We are going to look for all outputs where
// type = "content", and derive output streams to hand to the IStreamingAction.
//
Map<String, IContentItem> outputContentItems = new HashMap<String, IContentItem>();
StreamOutputErrorCallback streamingOutputCallback = new StreamOutputErrorCallback();
OuputStreamGenerator outputStreamGenerator = new OuputStreamGenerator(outputContentItems);
IActionOutput[] contentOutputs = getActionDefinition().getOutputs(ActionSequenceDocument.CONTENT_TYPE);
if (contentOutputs.length > 0) {
for (IActionOutput contentOutput : contentOutputs) {
outputStreamGenerator.setContentOutput(contentOutput);
actionHarness.setValue(contentOutput.getName(), outputStreamGenerator, streamingOutputCallback, STREAM_APPENDER_FORMATTER, COMPATIBILITY_FORMATTER, ALTERNATE_INDEX_FORMATTER);
}
}
//
if (actionBean instanceof IAction) {
((IAction) actionBean).execute();
}
//
for (IActionOutput output : actionDefintionOutputs) {
String outputName = output.getName();
outputName = COMPATIBILITY_FORMATTER.format(outputName);
// if streaming output, add it to the context and don't try to get it from the Action bean
if (outputContentItems.containsKey(outputName)) {
IContentItem contentItem = outputContentItems.get(outputName);
if (!(contentItem instanceof SimpleContentItem)) {
// this is a special output for streaming actions and does not require a bean accessor
output.setValue(contentItem);
}
} else if (actionHarness.isReadable(outputName)) {
Object outputVal = actionHarness.getValue(outputName);
output.setValue(outputVal);
} else {
if (loggingLevel <= ILogger.WARN) {
warn(// $NON-NLS-1$
Messages.getInstance().getString(// $NON-NLS-1$
"ActionDelegate.WARN_OUTPUT_NOT_READABLE", outputName, output.getType(), actionBean.getClass().getSimpleName()));
}
}
}
return true;
}
use of org.pentaho.platform.api.action.IAction in project pentaho-platform by pentaho.
the class LocalActionInvokerTest method invokeActionTest.
@Test
public void invokeActionTest() throws Exception {
Map<String, Serializable> testMap = new HashMap<>();
testMap.put(ActionUtil.QUARTZ_ACTIONCLASS, "one");
testMap.put(ActionUtil.QUARTZ_ACTIONUSER, "two");
IAction iaction = ActionUtil.createActionBean(ActionSequenceAction.class.getName(), null);
ActionInvokeStatus actionInvokeStatus = (ActionInvokeStatus) defaultActionInvoker.invokeAction(iaction, "aUser", testMap);
Assert.assertFalse(actionInvokeStatus.requiresUpdate());
}
Aggregations