OptionObjectBundleHook extends AbstractObjectBundleHook { @Override public <T extends IdentifiableObject> List<ErrorReport> validate( T object, ObjectBundle bundle ) { List<ErrorReport> errors = new ArrayList<>(); if ( !(object instanceof Option) ) return new ArrayList<>(); final Option option = (Option) object; if ( option.getOptionSet() != null ) { OptionSet optionSet = bundle.getPreheat().get( bundle.getPreheatIdentifier(), OptionSet.class, option.getOptionSet() ); errors.addAll( checkDuplicateOption( optionSet, option ) ); } return errors; }  @Override List<ErrorReport> validate( T object, ObjectBundle bundle ); @Override void preCreate( T object, ObjectBundle bundle );  }
@Test public void validate() { OptionSet optionSet = new OptionSet(); optionSet.setUid( "optionSet1" ); Option option = new Option(); option.setName( "optionName" ); option.setCode( "optionCode" ); optionSet.addOption( option ); OptionSet persistedOptionSet = new OptionSet(); persistedOptionSet.setUid( "optionSet1" ); Option persistedOption = new Option(); persistedOption.setName( "optionName" ); persistedOption.setCode( "optionCode" ); persistedOptionSet.addOption( persistedOption ); preheat.put( PreheatIdentifier.UID, persistedOptionSet ); ObjectBundleParams objectBundleParams = new ObjectBundleParams(); objectBundleParams.setPreheatIdentifier( PreheatIdentifier.UID ); ObjectBundle bundle = new ObjectBundle( objectBundleParams, preheat, Collections.singletonMap( OptionSet.class, Collections.singletonList( persistedOptionSet ) ) ); List<ErrorReport> errors = hook.validate( option, bundle ); Assert.assertNotNull( errors ); Assert.assertEquals( 1, errors.size() ); Assert.assertEquals( ErrorCode.E4028, errors.get( 0 ).getErrorCode() ); }