ParameterImpl extends RelationalChildRestrictedObject implements Parameter { @Override public StatementOption setStatementOption( final UnitOfWork transaction, final String optionName, final String optionValue ) throws KException { return OptionContainerUtils.setOption( transaction, this, optionName, optionValue ); } ParameterImpl( final UnitOfWork uow,
                          final Repository repository,
                          final String workspacePath ); @Override StatementOption[] getCustomOptions( final UnitOfWork transaction ); @Override String getDatatypeName( final UnitOfWork uow ); @Override String getDefaultValue( final UnitOfWork uow ); @Override Direction getDirection( final UnitOfWork uow ); @Override long getLength( final UnitOfWork uow ); @Override Nullable getNullable( final UnitOfWork uow ); @Override long getPrecision( final UnitOfWork uow ); @Override Descriptor getPrimaryType( final UnitOfWork transaction ); @Override Property getProperty( final UnitOfWork transaction,
                                 final String name ); @Override PropertyDescriptor getPropertyDescriptor( final UnitOfWork transaction,
                                                     final String propName ); @Override String[] getPropertyNames( final UnitOfWork transaction ); @Override long getScale( final UnitOfWork uow ); @Override String[] getStatementOptionNames( final UnitOfWork transaction ); @Override StatementOption[] getStatementOptions( final UnitOfWork transaction ); @Override int getTypeId(); @Override KomodoType getTypeIdentifier( final UnitOfWork uow ); @Override AbstractProcedure getParent( final UnitOfWork transaction ); @Override boolean hasProperties( final UnitOfWork transaction ); @Override boolean hasProperty( final UnitOfWork transaction,
                                final String name ); @Override boolean isCustomOption( final UnitOfWork transaction,
                                   final String name ); @Override boolean isResult( final UnitOfWork transaction ); @Override boolean isStandardOption( final String name ); @Override void removeStatementOption( final UnitOfWork transaction,
                                       final String optionToRemove ); @Override void setDatatypeName( final UnitOfWork uow,
                                 final String newTypeName ); @Override void setDefaultValue( final UnitOfWork uow,
                                 final String newDefaultValue ); @Override void setDirection( final UnitOfWork uow,
                              final Direction newDirection ); @Override void setLength( final UnitOfWork uow,
                           final long newLength ); @Override void setNullable( final UnitOfWork uow,
                             final Nullable newNullable ); @Override void setPrecision( final UnitOfWork uow,
                              final long newPrecision ); @Override void setProperty( final UnitOfWork transaction,
                             final String propertyName,
                             final Object... values ); @Override void setResult( final UnitOfWork transaction,
                           final boolean newResult ); @Override void setScale( final UnitOfWork uow,
                          final long newScale ); @Override StatementOption setStatementOption( final UnitOfWork transaction,
                                               final String optionName,
                                               final String optionValue );  }
@Test public void shouldAddStatementOption() throws Exception { final String name = "statementoption"; final String value = "statementvalue"; final StatementOption statementOption = this.parameter.setStatementOption( getTransaction(), name, value ); assertThat( statementOption, is( notNullValue() ) ); assertThat( statementOption.getName( getTransaction() ), is( name ) ); assertThat( statementOption.getOption( getTransaction() ), is( value ) ); }
@Test( expected = IllegalArgumentException.class ) public void shouldFailAddingEmptyStatementOptionName() throws Exception { this.parameter.setStatementOption( getTransaction(), StringConstants.EMPTY_STRING, "blah" ); }
@Test( expected = IllegalArgumentException.class ) public void shouldFailAddingNullStatementOptionName() throws Exception { this.parameter.setStatementOption( getTransaction(), null, "blah" ); }
@Test( expected = KException.class ) public void shouldFailAddingNullStatementOptionValueWhenNeverAdded() throws Exception { this.parameter.setStatementOption( getTransaction(), "blah", null ); }
@Test( expected = KException.class ) public void shouldFailSettingEmptyStatementOptionValueWhenNeverAdded() throws Exception { this.parameter.setStatementOption( getTransaction(), "blah", StringConstants.EMPTY_STRING ); }
@Test public void shouldNotCountStatementOptionsAsChildren() throws Exception { this.parameter.setStatementOption( getTransaction(), "sledge", "hammer" ); assertThat( this.parameter.getChildren( getTransaction() ).length, is( 0 ) ); }
@Test public void shouldIncludeCustomOptionsWithPropertyDescriptors() throws Exception { final String customName = "blah"; this.parameter.setStatementOption( getTransaction(), customName, "elvis" ); final PropertyDescriptor[] propDescriptors = this.parameter.getPropertyDescriptors( getTransaction() ); boolean found = false; for ( final PropertyDescriptor descriptor : propDescriptors ) { if ( customName.equals( descriptor.getName() ) ) { found = true; break; } } if ( !found ) { fail( "Custom option '" + customName + "'was not included in the property descriptors" ); } }