MDXBaseComponent extends ComponentBase implements IDataComponent, IPreparedComponent { @Override protected boolean validateAction() { boolean actionValidated = true; MdxQueryAction queryAction = null; MdxConnectionAction connAction = null; try { if ( getActionDefinition() instanceof MdxQueryAction ) { queryAction = (MdxQueryAction) getActionDefinition(); actionValidated = isConnectionInfoSpecified( queryAction ); if ( actionValidated ) { if ( queryAction.getQuery() == ActionInputConstant.NULL_INPUT ) { error( Messages.getInstance().getErrorString( "MDXBaseComponent.ERROR_0001_QUERY_NOT_SPECIFIED", getActionName() ) ); actionValidated = false; } } if ( actionValidated ) { if ( ( queryAction.getOutputResultSet() == null ) && ( queryAction.getOutputPreparedStatement() == null ) ) { error( Messages.getInstance().getErrorString( "MDXBaseComponent.ERROR_0003_OUTPUT_NOT_SPECIFIED", getActionName() ) ); actionValidated = false; } } } else if ( getActionDefinition() instanceof MdxConnectionAction ) { connAction = (MdxConnectionAction) getActionDefinition(); actionValidated = isConnectionInfoSpecified( connAction ); if ( connAction.getOutputConnection() == null ) { error( Messages.getInstance().getErrorString( "MDXBaseComponent.ERROR_0003_OUTPUT_NOT_SPECIFIED", getActionName() ) ); actionValidated = false; } } } catch ( Exception e ) { actionValidated = false; error( Messages.getInstance().getErrorString( "MDXBaseComponent.ERROR_0004_VALIDATION_FAILED", getActionName() ), e ); } return actionValidated; }  @Override abstract boolean validateSystemSettings(); @Override abstract Log getLogger(); IPentahoResultSet getResultSet(); @Override void done(); void dispose(); IPentahoConnection shareConnection(); IPentahoResultSet executePrepared( final Map preparedParams ); IPentahoConnection getDatasourceConnection(); @Override boolean init(); static final String FORMATTED_CELL_VALUES; }
@Test public void testValidateAction_noActionDefinition() throws Exception { boolean action = mdxBaseComponent.validateAction(); assertTrue( action ); }
@Test public void testValidateAction_queryAction_nullInput() throws Exception { mdxBaseComponent.setActionDefinition( queryAction ); when( queryAction.getQuery() ).thenReturn( ActionInputConstant.NULL_INPUT ); boolean action = mdxBaseComponent.validateAction(); assertFalse( action ); verify( mdxBaseComponent ).error( anyString() ); }
@Test public void testValidateAction_queryAction_nullResult() throws Exception { mdxBaseComponent.setActionDefinition( queryAction ); when( queryAction.getOutputResultSet() ).thenReturn( null ); when( queryAction.getOutputPreparedStatement() ).thenReturn( null ); boolean action = mdxBaseComponent.validateAction(); assertFalse( action ); verify( mdxBaseComponent ).error( anyString() ); }
@Test public void testValidateAction_queryAction() throws Exception { mdxBaseComponent.setActionDefinition( queryAction ); when( queryAction.getOutputResultSet() ).thenReturn( outputResultSet ); when( queryAction.getOutputPreparedStatement() ).thenReturn( null ); boolean action = mdxBaseComponent.validateAction(); assertTrue( action ); verify( mdxBaseComponent, never() ).error( anyString(), any( Throwable.class ) ); }
@Test public void testValidateAction_connectionAction_noConnection() throws Exception { mdxBaseComponent.setActionDefinition( connAction ); boolean action = mdxBaseComponent.validateAction(); assertFalse( action ); verify( mdxBaseComponent ).error( anyString() ); }
@Test public void testValidateAction_connectionAction() throws Exception { mdxBaseComponent.setActionDefinition( connAction ); when( connAction.getOutputConnection() ).thenReturn( outputResultSet ); boolean action = mdxBaseComponent.validateAction(); assertTrue( action ); verify( mdxBaseComponent, never() ).error( anyString(), any( Throwable.class ) ); }