@Test
public void testValidation() throws Exception
{
final TestModel model = TestModel.TYPE.instantiate();
final FileExtensionsService service = model.property( TestModel.PROP_FILE_PATH_4 ).service( FileExtensionsService.class );
final IProject project = project();
final IFile txtFile = project.getFile( "file.txt" );
final String txtFilePath = txtFile.getLocation().toOSString();
txtFile.create( new ByteArrayInputStream( new byte[ 0 ] ), true, new NullProgressMonitor() );
final IFile jpegFile = project.getFile( "file.jpeg" );
final String jpegFilePath = jpegFile.getLocation().toOSString();
jpegFile.create( new ByteArrayInputStream( new byte[ 0 ] ), true, new NullProgressMonitor() );
final IFile pngFile = project.getFile( "file.png" );
final String pngFilePath = pngFile.getLocation().toOSString();
pngFile.create( new ByteArrayInputStream( new byte[ 0 ] ), true, new NullProgressMonitor() );
assertNotNull( service );
model.setLossyCompression( true );
assertEquals( list( "jpeg" ), service.extensions() );
model.setFilePath4( txtFilePath );
assertValidationError( model.getFilePath4(), "File \"file.txt\" has an invalid extension. Only \"jpeg\" extension is allowed" );
model.setFilePath4( jpegFilePath );
assertValidationOk( model.getFilePath4() );
model.setLossyCompression( false );
assertEquals( list( "png", "gif" ), service.extensions() );
assertValidationError( model.getFilePath4(), "File \"file.jpeg\" has an invalid extension. Only extensions \"png\" and \"gif\" are allowed" );
model.setFilePath4( pngFilePath );
assertValidationOk( model.getFilePath4() );