StoredProcedureImpl extends AbstractProcedureImpl implements StoredProcedure { @Override public Map< String, String > getStandardOptions() { if ( _defaultValues == null ) { final Map< String, String > superOptions = super.getStandardOptions(); final Map< String, String > options = StandardOption.defaultValues(); final Map< String, String > combined = new HashMap< >( superOptions.size() + options.size() ); combined.putAll( superOptions ); combined.putAll( options ); _defaultValues = Collections.unmodifiableMap( combined ); } return _defaultValues; } StoredProcedureImpl( final UnitOfWork uow,
                                final Repository repository,
                                final String workspacePath ); @Override KomodoType[] getChildTypes(); @Override String getNativeQuery( final UnitOfWork transaction ); @Override ProcedureResultSet getResultSet( final UnitOfWork transaction ); @Override Map< String, String > getStandardOptions(); @Override KomodoType getTypeIdentifier( final UnitOfWork transaction ); @Override Model getParent( final UnitOfWork transaction ); @Override boolean isNonPrepared( final UnitOfWork transaction ); @Override boolean isStandardOption( final String name ); @Override void removeResultSet( final UnitOfWork transaction ); @Override void setNativeQuery( final UnitOfWork transaction,
                                final String newNativeQuery ); @Override void setNonPrepared( final UnitOfWork transaction,
                                final boolean newNonPrepared ); @SuppressWarnings( "unchecked" ) @Override T setResultSet( final UnitOfWork transaction,
                                                            final Class< T > resultSetType );  }
@Test public void shouldIncludeOptionsWithPropertyNames() throws Exception { final String custom = "blah"; this.procedure.setStatementOption( getTransaction(), custom, "sledge" ); boolean customFound = false; final String standard = this.procedure.getStandardOptions().keySet().iterator().next(); this.procedure.setStatementOption( getTransaction(), standard, "hammer" ); boolean standardFound = false; for ( final String prop : this.procedure.getPropertyNames( getTransaction() ) ) { if ( custom.equals( prop ) ) { if ( customFound ) { fail( "Custom option included multiple times in property names" ); } customFound = true; } else if ( standard.equals( prop ) ) { if ( standardFound ) { fail( "Standard option included multiple times in property names" ); } standardFound = true; } if ( customFound && standardFound ) { break; } } if ( !customFound ) { fail( "Custom option not included in property names" ); } if ( !standardFound ) { fail( "Standard option not included in property names" ); } }
@Test public void shouldIncludeStandardOptionDefaultValuesWithPropertyDescriptors() throws Exception { final Map< String, String > options = this.procedure.getStandardOptions(); final PropertyDescriptor[] propDescriptors = this.procedure.getPropertyDescriptors( getTransaction() ); for ( final Entry< String, String > entry : options.entrySet() ) { for ( final PropertyDescriptor descriptor : propDescriptors ) { if ( entry.getKey().equals( descriptor.getName() ) ) { final String value = entry.getValue(); final Object[] defaultValues = descriptor.getDefaultValues(); if ( StringUtils.isBlank( value ) ) { assertThat( defaultValues.length, is( 0 ) ); } else { assertThat( defaultValues.length, is( 1 ) ); assertThat( value, is( defaultValues[0] ) ); } } } } }
@Test public void shouldIncludeStandardOptionsWithPrimaryTypePropertyDescriptors() throws Exception { final Set< String > optionNames = this.procedure.getStandardOptions().keySet(); final PropertyDescriptor[] propDescriptors = this.procedure.getPrimaryType( getTransaction() ).getPropertyDescriptors( getTransaction() ); for ( final String optionName : optionNames ) { boolean found = false; for ( final PropertyDescriptor descriptor : propDescriptors ) { if ( optionName.equals( descriptor.getName() ) ) { found = true; break; } } if ( !found ) { fail( "Option '" + optionName + "'was not included in the primary type property descriptors" ); } } }
@Test public void shouldIncludeStandardOptionsWithPropertyDescriptors() throws Exception { final Set< String > optionNames = this.procedure.getStandardOptions().keySet(); final PropertyDescriptor[] propDescriptors = this.procedure.getPropertyDescriptors( getTransaction() ); for ( final String optionName : optionNames ) { boolean found = false; for ( final PropertyDescriptor descriptor : propDescriptors ) { if ( optionName.equals( descriptor.getName() ) ) { found = true; break; } } if ( !found ) { fail( "Option '" + optionName + "'was not included in the property descriptors" ); } } }
@Test public void shouldObtainPropertyDescriptorOfStandardOption() throws Exception { final String standard = this.procedure.getStandardOptions().keySet().iterator().next(); this.procedure.setStatementOption( getTransaction(), standard, "blah" ); assertThat( this.procedure.getPropertyDescriptor( getTransaction(), standard ), is( notNullValue() ) ); assertThat( this.procedure.getPropertyDescriptor( getTransaction(), standard ).getName(), is( standard ) ); }
@Test public void shouldObtainStatementOptionNames() throws Exception { final String custom = "blah"; this.procedure.setStatementOption( getTransaction(), custom, "sledge" ); final String standard = this.procedure.getStandardOptions().keySet().iterator().next(); this.procedure.setStatementOption( getTransaction(), standard, "hammer" ); assertThat( this.procedure.getStatementOptionNames( getTransaction() ).length, is( 2 ) ); assertThat( Arrays.asList( this.procedure.getStatementOptionNames( getTransaction() ) ), hasItems( custom, standard ) ); }
@Test public void shouldRemoveStandardOptionAsIfProperty() throws Exception { final String option = this.procedure.getStandardOptions().keySet().iterator().next(); final String value = "newValue"; this.procedure.setProperty( getTransaction(), option, value ); this.procedure.setProperty( getTransaction(), option, (Object)null ); assertThat( this.procedure.hasProperty( getTransaction(), option ), is( false ) ); assertThat( this.procedure.hasChild( getTransaction(), option ), is( false ) ); }
@Test public void shouldSetStandardOptionAsIfProperty() throws Exception { final String option = this.procedure.getStandardOptions().keySet().iterator().next(); this.procedure.setStatementOption( getTransaction(), option, "initialValue" ); final String value = "newValue"; this.procedure.setProperty( getTransaction(), option, value ); assertThat( this.procedure.hasProperty( getTransaction(), option ), is( true ) ); assertThat( this.procedure.getProperty( getTransaction(), option ), is( instanceOf( StatementOption.class ) ) ); assertThat( this.procedure.isCustomOption( getTransaction(), option ), is( false ) ); assertThat( this.procedure.getStatementOptions( getTransaction() ).length, is( 1 ) ); final StatementOption statementOption = this.procedure.getStatementOptions( getTransaction() )[0]; assertThat( statementOption.getName( getTransaction() ), is( option ) ); assertThat( statementOption.getValue( getTransaction() ), is( ( Object )value ) ); }