001/*
002 *   Copyright (C) 2005 Christian Schulte <cs@schulte.it>
003 *   All rights reserved.
004 *
005 *   Redistribution and use in source and binary forms, with or without
006 *   modification, are permitted provided that the following conditions
007 *   are met:
008 *
009 *     o Redistributions of source code must retain the above copyright
010 *       notice, this list of conditions and the following disclaimer.
011 *
012 *     o Redistributions in binary form must reproduce the above copyright
013 *       notice, this list of conditions and the following disclaimer in
014 *       the documentation and/or other materials provided with the
015 *       distribution.
016 *
017 *   THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
018 *   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
019 *   AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
020 *   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
021 *   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
022 *   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
023 *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
024 *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
025 *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
026 *   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027 *
028 *   $JOMC: ToolsModelValidatorTest.java 5135 2016-04-08 13:53:07Z schulte $
029 *
030 */
031package org.jomc.tools.modlet.test;
032
033import java.util.List;
034import javax.xml.bind.util.JAXBSource;
035import org.jomc.model.Dependencies;
036import org.jomc.model.Dependency;
037import org.jomc.model.Implementation;
038import org.jomc.model.Implementations;
039import org.jomc.model.Message;
040import org.jomc.model.Messages;
041import org.jomc.model.ModelObject;
042import org.jomc.model.Module;
043import org.jomc.model.Modules;
044import org.jomc.model.Specification;
045import org.jomc.model.Specifications;
046import org.jomc.model.Text;
047import org.jomc.model.Texts;
048import org.jomc.model.modlet.ModelHelper;
049import org.jomc.modlet.Model;
050import org.jomc.modlet.ModelContext;
051import org.jomc.modlet.ModelContextFactory;
052import org.jomc.modlet.ModelValidationReport;
053import org.jomc.tools.model.ObjectFactory;
054import org.jomc.tools.model.SourceFileType;
055import org.jomc.tools.model.SourceFilesType;
056import org.jomc.tools.model.SourceSectionType;
057import org.jomc.tools.model.SourceSectionsType;
058import org.jomc.tools.model.TemplateParameterType;
059import org.jomc.tools.modlet.ToolsModelValidator;
060import org.junit.Test;
061import static org.junit.Assert.assertNotNull;
062import static org.junit.Assert.assertTrue;
063import static org.junit.Assert.fail;
064
065/**
066 * Test cases for class {@code org.jomc.tools.modlet.ToolsModelValidator}.
067 *
068 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> 1.0
069 * @version $JOMC: ToolsModelValidatorTest.java 5135 2016-04-08 13:53:07Z schulte $
070 */
071public class ToolsModelValidatorTest
072{
073
074    /**
075     * The {@code ToolsModelValidator} instance tests are performed with.
076     */
077    private ToolsModelValidator toolsModelValidator;
078
079    /**
080     * Creates a new {@code ToolsModelValidatorTest} instance.
081     */
082    public ToolsModelValidatorTest()
083    {
084        super();
085    }
086
087    /**
088     * Gets the {@code ToolsModelValidator} instance tests are performed with.
089     *
090     * @return The {@code ToolsModelValidator} instance tests are performed with.
091     *
092     * @see #newModelValidator()
093     */
094    public ToolsModelValidator getModelValidator()
095    {
096        if ( this.toolsModelValidator == null )
097        {
098            this.toolsModelValidator = this.newModelValidator();
099        }
100
101        return this.toolsModelValidator;
102    }
103
104    /**
105     * Create a new {@code ToolsModelValidator} instance to test.
106     *
107     * @return A new {@code ToolsModelValidator} instance to test.
108     *
109     * @see #getModelValidator()
110     */
111    protected ToolsModelValidator newModelValidator()
112    {
113        return new ToolsModelValidator();
114    }
115
116    @Test
117    public final void testValidateModel() throws Exception
118    {
119        final ModelContext modelContext = ModelContextFactory.newInstance().newModelContext();
120
121        try
122        {
123            this.getModelValidator().validateModel( modelContext, null );
124            fail( "Expected NullPointerException not thrown." );
125        }
126        catch ( final NullPointerException e )
127        {
128            assertNotNull( e.getMessage() );
129            System.out.println( e.toString() );
130        }
131
132        try
133        {
134            this.getModelValidator().validateModel( null, new Model() );
135            fail( "Expected NullPointerException not thrown." );
136        }
137        catch ( final NullPointerException e )
138        {
139            assertNotNull( e.getMessage() );
140            System.out.println( e.toString() );
141        }
142
143        ModelValidationReport report = this.getModelValidator().validateModel( modelContext, new Model() );
144        assertNotNull( report );
145        assertTrue( report.isModelValid() );
146
147        final Model model = new Model();
148        model.setIdentifier( ModelObject.MODEL_PUBLIC_ID );
149
150        final SourceFileType sourceFile1 = new SourceFileType();
151        sourceFile1.setIdentifier( this.getClass().getSimpleName() + " 1" );
152        sourceFile1.getTemplateParameter().add( new TemplateParameterType() );
153        sourceFile1.getTemplateParameter().get( 0 ).setName( "SourceFile1" );
154        sourceFile1.getTemplateParameter().get( 0 ).setType( "DOES_NOT_EXIST" );
155        sourceFile1.getTemplateParameter().get( 0 ).setValue( "TEST" );
156
157        final SourceFileType sourceFile2 = new SourceFileType();
158        sourceFile2.setIdentifier( this.getClass().getSimpleName() + " 2" );
159        sourceFile2.getTemplateParameter().add( new TemplateParameterType() );
160        sourceFile2.getTemplateParameter().get( 0 ).setName( "SourceFile2" );
161        sourceFile2.getTemplateParameter().get( 0 ).setType( "DOES_NOT_EXIST" );
162        sourceFile2.getTemplateParameter().get( 0 ).setValue( "TEST" );
163
164        final SourceFilesType sourceFiles1 = new SourceFilesType();
165        sourceFiles1.getSourceFile().add( sourceFile1 );
166        sourceFiles1.getSourceFile().add( sourceFile2 );
167
168        final SourceFilesType sourceFiles2 = new SourceFilesType();
169        sourceFiles2.getSourceFile().add( sourceFile1 );
170        sourceFiles2.getSourceFile().add( sourceFile2 );
171
172        final SourceSectionType sourceSection1 = new SourceSectionType();
173        sourceSection1.setName( this.getClass().getSimpleName() + " 1" );
174        sourceSection1.getTemplateParameter().add( new TemplateParameterType() );
175        sourceSection1.getTemplateParameter().get( 0 ).setName( "SourceSection1" );
176        sourceSection1.getTemplateParameter().get( 0 ).setType( "DOES_NOT_EXIST" );
177        sourceSection1.getTemplateParameter().get( 0 ).setValue( "TEST" );
178        sourceSection1.setSourceSections( new SourceSectionsType() );
179        sourceSection1.getSourceSections().getSourceSection().add( sourceSection1.clone() );
180        sourceSection1.getSourceSections().getSourceSection().get( 0 ).setName( "SourceSection1 - nested" );
181
182        final SourceSectionType sourceSection2 = new SourceSectionType();
183        sourceSection2.setName( this.getClass().getSimpleName() + " 2" );
184        sourceSection2.getTemplateParameter().add( new TemplateParameterType() );
185        sourceSection2.getTemplateParameter().get( 0 ).setName( "SourceSection2" );
186        sourceSection2.getTemplateParameter().get( 0 ).setType( "DOES_NOT_EXIST" );
187        sourceSection2.getTemplateParameter().get( 0 ).setValue( "TEST" );
188        sourceSection2.setSourceSections( new SourceSectionsType() );
189        sourceSection2.getSourceSections().getSourceSection().add( sourceSection2.clone() );
190        sourceSection2.getSourceSections().getSourceSection().get( 0 ).setName( "SourceSection2 - nested" );
191
192        final SourceSectionsType sourceSections1 = new SourceSectionsType();
193        sourceSections1.getSourceSection().add( sourceSection1 );
194        sourceSections1.getSourceSection().add( sourceSection2 );
195
196        final SourceSectionsType sourceSections2 = new SourceSectionsType();
197        sourceSections2.getSourceSection().add( sourceSection1 );
198        sourceSections2.getSourceSection().add( sourceSection2 );
199
200        sourceFile1.setSourceSections( sourceSections1 );
201        sourceFile2.setSourceSections( sourceSections2 );
202
203        model.getAny().add( new ObjectFactory().createSourceFile( sourceFile1 ) );
204        model.getAny().add( new ObjectFactory().createSourceFile( sourceFile2 ) );
205        model.getAny().add( new ObjectFactory().createSourceFiles( sourceFiles1 ) );
206        model.getAny().add( new ObjectFactory().createSourceFiles( sourceFiles2 ) );
207        model.getAny().add( new ObjectFactory().createSourceFiles( new SourceFilesType() ) );
208        model.getAny().add( new ObjectFactory().createSourceSection( sourceSection1 ) );
209        model.getAny().add( new ObjectFactory().createSourceSection( sourceSection2 ) );
210        model.getAny().add( new ObjectFactory().createSourceSections( sourceSections1 ) );
211        model.getAny().add( new ObjectFactory().createSourceSections( sourceSections2 ) );
212        model.getAny().add( new ObjectFactory().createSourceSections( new SourceSectionsType() ) );
213
214        final Modules modules = new Modules();
215        ModelHelper.setModules( model, modules );
216
217        final Module module = new Module();
218        modules.getModule().add( module );
219        module.setSpecifications( new Specifications() );
220        module.setImplementations( new Implementations() );
221        module.setName( this.getClass().getSimpleName() );
222
223        module.getAny().add( new ObjectFactory().createSourceFile( sourceFile1 ) );
224        module.getAny().add( new ObjectFactory().createSourceFile( sourceFile2 ) );
225        module.getAny().add( new ObjectFactory().createSourceFiles( sourceFiles1 ) );
226        module.getAny().add( new ObjectFactory().createSourceFiles( sourceFiles2 ) );
227        module.getAny().add( new ObjectFactory().createSourceFiles( new SourceFilesType() ) );
228        module.getAny().add( new ObjectFactory().createSourceSection( sourceSection1 ) );
229        module.getAny().add( new ObjectFactory().createSourceSection( sourceSection2 ) );
230        module.getAny().add( new ObjectFactory().createSourceSections( sourceSections1 ) );
231        module.getAny().add( new ObjectFactory().createSourceSections( sourceSections2 ) );
232        module.getAny().add( new ObjectFactory().createSourceSections( new SourceSectionsType() ) );
233        module.setMessages( new Messages() );
234
235        final Specification specification = new Specification();
236        specification.setIdentifier( this.getClass().getSimpleName() );
237        specification.getAny().add( new ObjectFactory().createSourceFile( sourceFile1 ) );
238        specification.getAny().add( new ObjectFactory().createSourceFile( sourceFile2 ) );
239        specification.getAny().add( new ObjectFactory().createSourceFiles( sourceFiles1 ) );
240        specification.getAny().add( new ObjectFactory().createSourceFiles( sourceFiles2 ) );
241        specification.getAny().add( new ObjectFactory().createSourceFiles( new SourceFilesType() ) );
242        specification.getAny().add( new ObjectFactory().createSourceSection( sourceSection1 ) );
243        specification.getAny().add( new ObjectFactory().createSourceSection( sourceSection2 ) );
244        specification.getAny().add( new ObjectFactory().createSourceSections( sourceSections1 ) );
245        specification.getAny().add( new ObjectFactory().createSourceSections( sourceSections2 ) );
246        specification.getAny().add( new ObjectFactory().createSourceSections( new SourceSectionsType() ) );
247
248        final Implementation implementation = new Implementation();
249        implementation.setIdentifier( this.getClass().getSimpleName() );
250        implementation.setName( this.getClass().getSimpleName() );
251        implementation.getAny().add( new ObjectFactory().createSourceFile( sourceFile1 ) );
252        implementation.getAny().add( new ObjectFactory().createSourceFile( sourceFile2 ) );
253        implementation.getAny().add( new ObjectFactory().createSourceFiles( sourceFiles1 ) );
254        implementation.getAny().add( new ObjectFactory().createSourceFiles( sourceFiles2 ) );
255        implementation.getAny().add( new ObjectFactory().createSourceFiles( new SourceFilesType() ) );
256        implementation.getAny().add( new ObjectFactory().createSourceSection( sourceSection1 ) );
257        implementation.getAny().add( new ObjectFactory().createSourceSection( sourceSection2 ) );
258        implementation.getAny().add( new ObjectFactory().createSourceSections( sourceSections1 ) );
259        implementation.getAny().add( new ObjectFactory().createSourceSections( sourceSections2 ) );
260        implementation.getAny().add( new ObjectFactory().createSourceSections( new SourceSectionsType() ) );
261
262        implementation.setDependencies( new Dependencies() );
263        implementation.setMessages( new Messages() );
264
265        final Dependency dependency = new Dependency();
266        dependency.setName( this.getClass().getSimpleName() );
267        dependency.setIdentifier( this.getClass().getSimpleName() );
268        dependency.getAny().add( new ObjectFactory().createSourceFile( sourceFile1 ) );
269        dependency.getAny().add( new ObjectFactory().createSourceFile( sourceFile2 ) );
270        dependency.getAny().add( new ObjectFactory().createSourceFiles( sourceFiles1 ) );
271        dependency.getAny().add( new ObjectFactory().createSourceFiles( sourceFiles2 ) );
272        dependency.getAny().add( new ObjectFactory().createSourceFiles( new SourceFilesType() ) );
273        dependency.getAny().add( new ObjectFactory().createSourceSection( sourceSection1 ) );
274        dependency.getAny().add( new ObjectFactory().createSourceSection( sourceSection2 ) );
275        dependency.getAny().add( new ObjectFactory().createSourceSections( sourceSections1 ) );
276        dependency.getAny().add( new ObjectFactory().createSourceSections( sourceSections2 ) );
277        dependency.getAny().add( new ObjectFactory().createSourceSections( new SourceSectionsType() ) );
278
279        final Message message = new Message();
280        message.setName( this.getClass().getSimpleName() );
281        message.setTemplate( new Texts() );
282        message.getTemplate().setDefaultLanguage( "en" );
283
284        final Text text = new Text();
285        text.setLanguage( "en" );
286        message.getTemplate().getText().add( text );
287
288        message.getAny().add( new ObjectFactory().createSourceFile( sourceFile1 ) );
289        message.getAny().add( new ObjectFactory().createSourceFile( sourceFile2 ) );
290        message.getAny().add( new ObjectFactory().createSourceFiles( sourceFiles1 ) );
291        message.getAny().add( new ObjectFactory().createSourceFiles( sourceFiles2 ) );
292        message.getAny().add( new ObjectFactory().createSourceFiles( new SourceFilesType() ) );
293        message.getAny().add( new ObjectFactory().createSourceSection( sourceSection1 ) );
294        message.getAny().add( new ObjectFactory().createSourceSection( sourceSection2 ) );
295        message.getAny().add( new ObjectFactory().createSourceSections( sourceSections1 ) );
296        message.getAny().add( new ObjectFactory().createSourceSections( sourceSections2 ) );
297        message.getAny().add( new ObjectFactory().createSourceSections( new SourceSectionsType() ) );
298
299        implementation.getDependencies().getDependency().add( dependency );
300        implementation.getMessages().getMessage().add( message );
301
302        module.getImplementations().getImplementation().add( implementation );
303        module.getMessages().getMessage().add( message );
304        module.getSpecifications().getSpecification().add( specification );
305
306        final Specification deprecatedSpecification = new Specification();
307        deprecatedSpecification.setIdentifier( this.getClass().getSimpleName() + " 2" );
308        deprecatedSpecification.getAny().add( new ObjectFactory().createSourceFile( sourceFile1 ) );
309
310        final Implementation deprecatedImplementation = new Implementation();
311        deprecatedImplementation.setIdentifier( this.getClass().getSimpleName() + " 2" );
312        deprecatedImplementation.setName( this.getClass().getSimpleName() );
313        deprecatedImplementation.getAny().add( new ObjectFactory().createSourceFile( sourceFile1 ) );
314
315        module.getSpecifications().getSpecification().add( deprecatedSpecification );
316        module.getImplementations().getImplementation().add( deprecatedImplementation );
317
318        final JAXBSource jaxbSource = new JAXBSource( modelContext.createMarshaller(
319            ModelObject.MODEL_PUBLIC_ID ), new org.jomc.modlet.ObjectFactory().createModel( model ) );
320
321        report = modelContext.validateModel( ModelObject.MODEL_PUBLIC_ID, jaxbSource );
322        assertValidModel( report );
323
324        report = this.getModelValidator().validateModel( modelContext, model );
325        assertInvalidModel( report );
326        assertModelValidationReportDetail( report, "MODEL_SOURCE_FILE_CONSTRAINT", 6 );
327        assertModelValidationReportDetail( report, "MODEL_SOURCE_FILES_CONSTRAINT", 1 );
328        assertModelValidationReportDetail( report, "MODEL_SOURCE_SECTION_CONSTRAINT", 6 );
329        assertModelValidationReportDetail( report, "MODEL_SOURCE_SECTIONS_CONSTRAINT", 1 );
330        assertModelValidationReportDetail( report, "MODULE_SOURCE_FILE_CONSTRAINT", 6 );
331        assertModelValidationReportDetail( report, "MODULE_SOURCE_FILES_CONSTRAINT", 1 );
332        assertModelValidationReportDetail( report, "MODULE_SOURCE_SECTION_CONSTRAINT", 6 );
333        assertModelValidationReportDetail( report, "MODULE_SOURCE_SECTIONS_CONSTRAINT", 1 );
334        assertModelValidationReportDetail( report, "IMPLEMENTATION_SOURCE_FILE_MULTIPLICITY_CONSTRAINT", 1 );
335        assertModelValidationReportDetail( report, "IMPLEMENTATION_SOURCE_FILES_MULTIPLICITY_CONSTRAINT", 1 );
336        assertModelValidationReportDetail( report, "IMPLEMENTATION_SOURCE_SECTION_CONSTRAINT", 6 );
337        assertModelValidationReportDetail( report, "IMPLEMENTATION_SOURCE_SECTIONS_CONSTRAINT", 1 );
338        assertModelValidationReportDetail( report, "IMPLEMENTATION_SOURCE_FILE_INFORMATION", 1 );
339        assertModelValidationReportDetail( report, "IMPLEMENTATION_DEPENDENCY_SOURCE_FILE_CONSTRAINT", 6 );
340        assertModelValidationReportDetail( report, "IMPLEMENTATION_DEPENDENCY_SOURCE_FILES_CONSTRAINT", 1 );
341        assertModelValidationReportDetail( report, "IMPLEMENTATION_DEPENDENCY_SOURCE_SECTION_CONSTRAINT", 6 );
342        assertModelValidationReportDetail( report, "IMPLEMENTATION_DEPENDENCY_SOURCE_SECTIONS_CONSTRAINT", 1 );
343        assertModelValidationReportDetail( report, "IMPLEMENTATION_MESSAGE_SOURCE_FILE_CONSTRAINT", 6 );
344        assertModelValidationReportDetail( report, "IMPLEMENTATION_MESSAGE_SOURCE_FILES_CONSTRAINT", 1 );
345        assertModelValidationReportDetail( report, "IMPLEMENTATION_MESSAGE_SOURCE_SECTION_CONSTRAINT", 6 );
346        assertModelValidationReportDetail( report, "IMPLEMENTATION_MESSAGE_SOURCE_SECTIONS_CONSTRAINT", 1 );
347        assertModelValidationReportDetail( report, "SPECIFICATION_SOURCE_FILE_MULTIPLICITY_CONSTRAINT", 1 );
348        assertModelValidationReportDetail( report, "SPECIFICATION_SOURCE_FILES_MULTIPLICITY_CONSTRAINT", 1 );
349        assertModelValidationReportDetail( report, "SPECIFICATION_SOURCE_SECTION_CONSTRAINT", 6 );
350        assertModelValidationReportDetail( report, "SPECIFICATION_SOURCE_SECTIONS_CONSTRAINT", 1 );
351        assertModelValidationReportDetail( report, "SPECIFICATION_SOURCE_FILE_INFORMATION", 1 );
352        assertModelValidationReportDetail( report, "MODEL_SOURCE_FILE_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT", 6 );
353        assertModelValidationReportDetail( report, "MODEL_SOURCE_FILE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
354                                           24 );
355
356        assertModelValidationReportDetail( report, "MODEL_SOURCE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
357                                           12 );
358
359        assertModelValidationReportDetail( report, "MODULE_SOURCE_FILE_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT", 6 );
360
361        assertModelValidationReportDetail( report,
362                                           "MODULE_SOURCE_FILE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
363                                           24 );
364
365        assertModelValidationReportDetail( report, "MODULE_SOURCE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
366                                           12 );
367
368        assertModelValidationReportDetail( report,
369                                           "IMPLEMENTATION_SOURCE_FILE_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
370                                           7 );
371
372        assertModelValidationReportDetail( report,
373                                           "IMPLEMENTATION_SOURCE_FILE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
374                                           28 );
375
376        assertModelValidationReportDetail( report,
377                                           "IMPLEMENTATION_SOURCE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
378                                           12 );
379
380        assertModelValidationReportDetail( report,
381                                           "IMPLEMENTATION_DEPENDENCY_SOURCE_FILE_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
382                                           6 );
383
384        assertModelValidationReportDetail( report,
385                                           "IMPLEMENTATION_DEPENDENCY_SOURCE_FILE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
386                                           24 );
387
388        assertModelValidationReportDetail( report,
389                                           "IMPLEMENTATION_DEPENDENCY_SOURCE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
390                                           12 );
391
392        assertModelValidationReportDetail( report,
393                                           "IMPLEMENTATION_MESSAGE_SOURCE_FILE_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
394                                           6 );
395
396        assertModelValidationReportDetail( report,
397                                           "IMPLEMENTATION_MESSAGE_SOURCE_FILE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
398                                           24 );
399
400        assertModelValidationReportDetail( report,
401                                           "IMPLEMENTATION_MESSAGE_SOURCE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
402                                           12 );
403
404        assertModelValidationReportDetail( report,
405                                           "SPECIFICATION_SOURCE_FILE_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
406                                           7 );
407
408        assertModelValidationReportDetail( report,
409                                           "SPECIFICATION_SOURCE_FILE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
410                                           28 );
411
412        assertModelValidationReportDetail( report,
413                                           "SPECIFICATION_SOURCE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
414                                           12 );
415    }
416
417    private static void assertValidModel( final ModelValidationReport report )
418    {
419        assertNotNull( report );
420
421        if ( !report.isModelValid() )
422        {
423            System.out.println( ">>>Unexpected invalid model:" );
424            logModelValidationReport( report );
425            fail( report.toString() );
426        }
427        else
428        {
429            System.out.println( ">>>Valid model:" );
430            logModelValidationReport( report );
431        }
432    }
433
434    private static void assertInvalidModel( final ModelValidationReport report )
435    {
436        assertNotNull( report );
437
438        if ( report.isModelValid() )
439        {
440            System.out.println( ">>>Unexpected valid model:" );
441            logModelValidationReport( report );
442            fail( report.toString() );
443        }
444        else
445        {
446            System.out.println( ">>>Invalid model:" );
447            logModelValidationReport( report );
448        }
449    }
450
451    private static void assertModelValidationReportDetail( final ModelValidationReport report, final String identifier,
452                                                           final int count )
453    {
454        final List<ModelValidationReport.Detail> details = report.getDetails( identifier );
455
456        if ( details.size() != count )
457        {
458            System.out.println( ">>>Unexpected number of '" + identifier + "' details. Expected " + count + " - found "
459                                    + details.size() + "." );
460
461            logModelValidationReport( report );
462            fail( report.toString() );
463        }
464    }
465
466    private static void logModelValidationReport( final ModelValidationReport report )
467    {
468        for ( final ModelValidationReport.Detail d : report.getDetails() )
469        {
470            System.out.println( "\t" + d );
471        }
472    }
473
474}