chenqinghong
2024-05-07 3ec06a830367465068963156dcc1d8e522571c13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Quintiq file version 2.0
#parent: #root
Method VerifyHasSanityCheckFor (
  MacroPlan macroplan,
  String expectedSanityCheckGroupName,
  String expectedInstance,
  String expectedSanityCheckDescription
)
{
  TextBody:
  [*
    SanityCheckGroup::DoSanityCheck( macroplan ); // Refresh sanity check message
    
    sanityCheckGroup := select( macroplan, SanityCheckGroup, g, g.Group() = expectedSanityCheckGroupName );
    
    // Ensure sanity check group exists before checking for the specific sanity check message
    if( isnull( sanityCheckGroup ) )
    {
      this.Run().RegisterFailure( 'Verify sanity check fail. Sanity check group "' + expectedSanityCheckGroupName + '" not found.' + String::NewLine() +
                                  'Object = ' + expectedInstance + String::NewLine() + 
                                  'Description = ' + expectedSanityCheckDescription );
    } 
    else
    {
      // Check if sanity check message contains the PARTIAL expected text (not exact match as sanity check message prefix with more details such as object type involved)
      // Also checks the message contains the object type (e.g PISP name, unit name, etc)
      sanityCheckExists := exists( sanityCheckGroup, SanityCheckMessage, m, not m.IsValid() // SanityCheckMessage that is resolved by user still exist, thus we check this boolean
                                                                            and m.Description() ~ expectedInstance 
                                                                            and m.Description() ~ expectedSanityCheckDescription );
      
      this.Run().AssertTrue( sanityCheckExists, 'Verify sanity check fail. Cannot find sanity check message "' + expectedSanityCheckDescription + '".' + String::NewLine() +
                                                'Group = ' + expectedSanityCheckGroupName + String::NewLine() + 
                                                'Object = ' + expectedInstance );
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}