[otrs-cvs] ITSMConfigItem/scripts/test ITSMConfigItem.t,1.1,1.2

CVS commits notifications of OTRS.org cvs-log at otrs.org
Sat Apr 26 11:59:16 GMT 2008


Comments:
Update of /home/cvs/ITSMConfigItem/scripts/test
In directory lancelot:/tmp/cvs-serv835/scripts/test

Modified Files:
	ITSMConfigItem.t 
Log Message:
Added some unittests.

Author: mh

Index: ITSMConfigItem.t
===================================================================
RCS file: /home/cvs/ITSMConfigItem/scripts/test/ITSMConfigItem.t,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** ITSMConfigItem.t	25 Apr 2008 16:11:54 -0000	1.1
--- ITSMConfigItem.t	26 Apr 2008 11:59:11 -0000	1.2
***************
*** 16,19 ****
--- 16,20 ----
  use vars qw($Self);
  
+ use Data::Dumper;
  use Kernel::System::GeneralCatalog;
  use Kernel::System::ITSMConfigItem;
***************
*** 260,264 ****
  # create some random numbers
  my @ConfigItemNumbers;
! for ( 1 .. 10 ) {
      push @ConfigItemNumbers, int rand 1_000_000;
  }
--- 261,265 ----
  # create some random numbers
  my @ConfigItemNumbers;
! for ( 1 .. 50 ) {
      push @ConfigItemNumbers, int rand 1_000_000;
  }
***************
*** 322,326 ****
      },
  
!     # all required config item values are given (check required attributes)
      {
          SourceData => {
--- 323,327 ----
      },
  
!     # all required config item values are given (check returned config item values)
      {
          SourceData => {
***************
*** 427,431 ****
              VersionAdd => [
                  {
!                     Name        => 'UnitTest - ConfigItem 1 Version 1',
                      DeplStateID => $DeplStateListReverse{Production},
                      InciStateID => $InciStateListReverse{Operational},
--- 428,432 ----
              VersionAdd => [
                  {
!                     Name        => 'UnitTest - ConfigItem 2 Version 1',
                      DeplStateID => $DeplStateListReverse{Production},
                      InciStateID => $InciStateListReverse{Operational},
***************
*** 461,465 ****
              VersionAdd => [
                  {
!                     Name         => 'UnitTest - ConfigItem 1 Version 1',
                      DefinitionID => $ConfigItemDefinitionIDs[0],
                      InciStateID  => $InciStateListReverse{Operational},
--- 462,466 ----
              VersionAdd => [
                  {
!                     Name         => 'UnitTest - ConfigItem 3 Version 1',
                      DefinitionID => $ConfigItemDefinitionIDs[0],
                      InciStateID  => $InciStateListReverse{Operational},
***************
*** 495,499 ****
              VersionAdd => [
                  {
!                     Name         => 'UnitTest - ConfigItem 1 Version 1',
                      DefinitionID => $ConfigItemDefinitionIDs[0],
                      DeplStateID  => $DeplStateListReverse{Production},
--- 496,500 ----
              VersionAdd => [
                  {
!                     Name         => 'UnitTest - ConfigItem 4 Version 1',
                      DefinitionID => $ConfigItemDefinitionIDs[0],
                      DeplStateID  => $DeplStateListReverse{Production},
***************
*** 529,533 ****
              VersionAdd => [
                  {
!                     Name         => 'UnitTest - ConfigItem 1 Version 1',
                      DefinitionID => $ConfigItemDefinitionIDs[0],
                      DeplStateID  => $DeplStateListReverse{Production},
--- 530,534 ----
              VersionAdd => [
                  {
!                     Name         => 'UnitTest - ConfigItem 5 Version 1',
                      DefinitionID => $ConfigItemDefinitionIDs[0],
                      DeplStateID  => $DeplStateListReverse{Production},
***************
*** 553,595 ****
      },
  
!     #    {
!     #        SourceData => {
!     #            ConfigItemAdd => {
!     #                Number  => '111',  # (optional)
!     #                ClassID => 123,
!     #                UserID  => 1,
!     #            },
!     #            VersionAdd => [
!     #                {
!     #                    Name         => 'The Name',
!     #                    DefinitionID => 1212,
!     #                    DeplStateID  => 8,
!     #                    InciStateID  => 4,
!     #                    XMLData      => '$ArrayHashRef',  # (optional)
!     #                    UserID       => 1,
!     #                },
!     #            ],
!     #        },
!     #        ReferenceData => {
!     #            ConfigItemGet => {
!     #                Number         => '',
!     #                ClassID => '',
!     #                Class => '',
!     #                CurDeplStateID => '',
!     #                CurDeplState => '',
!     #                CurDeplStateType => '',
!     #                CurInciStateID => '',
!     #                CurInciState => '',
!     #                CurInciStateType => '',
!     #                CreateTime => '',
!     #                CreateBy => '',
!     #                ChangeTime => '',
!     #                ChangeBy => '',
!     #            },
!     #            VersionGet => [
!     #
!     #            ],
!     #        },
!     #    },
  ];
  
--- 554,856 ----
      },
  
!     # invalid deployment state id is given (check returned values)
!     {
!         SourceData => {
!             ConfigItemAdd => {
!                 Number  => $ConfigItemNumbers[6],
!                 ClassID => $ConfigItemClassIDs[0],
!                 UserID  => 1,
!             },
!             VersionAdd => [
!                 {
!                     Name         => 'UnitTest - ConfigItem 6 Version 1',
!                     DefinitionID => $ConfigItemDefinitionIDs[0],
!                     DeplStateID  => 9999999,
!                     InciStateID  => $InciStateListReverse{Operational},
!                     UserID       => 1,
!                 },
!             ],
!         },
!         ReferenceData => {
!             ConfigItemGet => {
!                 Number           => $ConfigItemNumbers[6],
!                 ClassID          => $ConfigItemClassIDs[0],
!                 Class            => $ClassList->{ $ConfigItemClassIDs[0] },
!                 CurDeplStateID   => undef,
!                 CurDeplState     => undef,
!                 CurDeplStateType => undef,
!                 CurInciStateID   => undef,
!                 CurInciState     => undef,
!                 CurInciStateType => undef,
!                 CreateBy         => 1,
!                 ChangeBy         => 1,
!             },
!         },
!     },
! 
!     # invalid incident state id is given (check returned values)
!     {
!         SourceData => {
!             ConfigItemAdd => {
!                 Number  => $ConfigItemNumbers[7],
!                 ClassID => $ConfigItemClassIDs[0],
!                 UserID  => 1,
!             },
!             VersionAdd => [
!                 {
!                     Name         => 'UnitTest - ConfigItem 7 Version 1',
!                     DefinitionID => $ConfigItemDefinitionIDs[0],
!                     DeplStateID  => $DeplStateListReverse{Production},
!                     InciStateID  => 9999999,
!                     UserID       => 1,
!                 },
!             ],
!         },
!         ReferenceData => {
!             ConfigItemGet => {
!                 Number           => $ConfigItemNumbers[7],
!                 ClassID          => $ConfigItemClassIDs[0],
!                 Class            => $ClassList->{ $ConfigItemClassIDs[0] },
!                 CurDeplStateID   => undef,
!                 CurDeplState     => undef,
!                 CurDeplStateType => undef,
!                 CurInciStateID   => undef,
!                 CurInciState     => undef,
!                 CurInciStateType => undef,
!                 CreateBy         => 1,
!                 ChangeBy         => 1,
!             },
!         },
!     },
! 
!     # all required values are given (check returned values)
!     {
!         SourceData => {
!             ConfigItemAdd => {
!                 Number  => $ConfigItemNumbers[8],
!                 ClassID => $ConfigItemClassIDs[0],
!                 UserID  => 1,
!             },
!             VersionAdd => [
!                 {
!                     Name         => 'UnitTest - ConfigItem 8 Version 1',
!                     DefinitionID => $ConfigItemDefinitionIDs[0],
!                     DeplStateID  => $DeplStateListReverse{Production},
!                     InciStateID  => $InciStateListReverse{Operational},
!                     UserID       => 1,
!                 },
!             ],
!         },
!         ReferenceData => {
!             ConfigItemGet => {
!                 Number           => $ConfigItemNumbers[8],
!                 ClassID          => $ConfigItemClassIDs[0],
!                 Class            => $ClassList->{ $ConfigItemClassIDs[0] },
!                 CurDeplStateID   => $DeplStateListReverse{Production},
!                 CurDeplState     => 'Production',
!                 CurDeplStateType => 'productive',
!                 CurInciStateID   => $InciStateListReverse{Operational},
!                 CurInciState     => 'Operational',
!                 CurInciStateType => 'operational',
!                 CreateBy         => 1,
!                 ChangeBy         => 1,
!             },
!             VersionGet => [
!                 {
!                     Number           => $ConfigItemNumbers[8],
!                     ClassID          => $ConfigItemClassIDs[0],
!                     Class            => $ClassList->{ $ConfigItemClassIDs[0] },
!                     Name             => 'UnitTest - ConfigItem 8 Version 1',
!                     DefinitionID     => $ConfigItemDefinitionIDs[0],
!                     DeplStateID      => $DeplStateListReverse{Production},
!                     DeplState        => 'Production',
!                     DeplStateType    => 'productive',
!                     CurDeplStateID   => $DeplStateListReverse{Production},
!                     CurDeplState     => 'Production',
!                     CurDeplStateType => 'productive',
!                     InciStateID      => $InciStateListReverse{Operational},
!                     InciState        => 'Operational',
!                     InciStateType    => 'operational',
!                     CurInciStateID   => $InciStateListReverse{Operational},
!                     CurInciState     => 'Operational',
!                     CurInciStateType => 'operational',
!                     XMLData          => [],
!                     CreateBy         => 1,
!                 },
!             ],
!         },
!     },
! 
!     # all required values are given (general check with two versions)
!     {
!         SourceData => {
!             ConfigItemAdd => {
!                 Number  => $ConfigItemNumbers[9],
!                 ClassID => $ConfigItemClassIDs[0],
!                 UserID  => 1,
!             },
!             VersionAdd => [
!                 {
!                     Name         => 'UnitTest - ConfigItem 9 Version 1',
!                     DefinitionID => $ConfigItemDefinitionIDs[0],
!                     DeplStateID  => $DeplStateListReverse{Production},
!                     InciStateID  => $InciStateListReverse{Operational},
!                     UserID       => 1,
!                 },
!                 {
!                     Name         => 'UnitTest - ConfigItem 9 Version 2',
!                     DefinitionID => $ConfigItemDefinitionIDs[0],
!                     DeplStateID  => $DeplStateListReverse{Production},
!                     InciStateID  => $InciStateListReverse{Operational},
!                     UserID       => 1,
!                 },
!             ],
!         },
!         ReferenceData => {
!             ConfigItemGet => {
!                 Number           => $ConfigItemNumbers[9],
!                 ClassID          => $ConfigItemClassIDs[0],
!                 Class            => $ClassList->{ $ConfigItemClassIDs[0] },
!                 CurDeplStateID   => $DeplStateListReverse{Production},
!                 CurDeplState     => 'Production',
!                 CurDeplStateType => 'productive',
!                 CurInciStateID   => $InciStateListReverse{Operational},
!                 CurInciState     => 'Operational',
!                 CurInciStateType => 'operational',
!                 CreateBy         => 1,
!                 ChangeBy         => 1,
!             },
!             VersionGet => [
!                 {
!                     Number           => $ConfigItemNumbers[9],
!                     ClassID          => $ConfigItemClassIDs[0],
!                     Class            => $ClassList->{ $ConfigItemClassIDs[0] },
!                     Name             => 'UnitTest - ConfigItem 9 Version 1',
!                     DefinitionID     => $ConfigItemDefinitionIDs[0],
!                     DeplStateID      => $DeplStateListReverse{Production},
!                     DeplState        => 'Production',
!                     DeplStateType    => 'productive',
!                     CurDeplStateID   => $DeplStateListReverse{Production},
!                     CurDeplState     => 'Production',
!                     CurDeplStateType => 'productive',
!                     InciStateID      => $InciStateListReverse{Operational},
!                     InciState        => 'Operational',
!                     InciStateType    => 'operational',
!                     CurInciStateID   => $InciStateListReverse{Operational},
!                     CurInciState     => 'Operational',
!                     CurInciStateType => 'operational',
!                     XMLData          => [],
!                     CreateBy         => 1,
!                 },
!                 {
!                     Number           => $ConfigItemNumbers[9],
!                     ClassID          => $ConfigItemClassIDs[0],
!                     Class            => $ClassList->{ $ConfigItemClassIDs[0] },
!                     Name             => 'UnitTest - ConfigItem 9 Version 2',
!                     DefinitionID     => $ConfigItemDefinitionIDs[0],
!                     DeplStateID      => $DeplStateListReverse{Production},
!                     DeplState        => 'Production',
!                     DeplStateType    => 'productive',
!                     CurDeplStateID   => $DeplStateListReverse{Production},
!                     CurDeplState     => 'Production',
!                     CurDeplStateType => 'productive',
!                     InciStateID      => $InciStateListReverse{Operational},
!                     InciState        => 'Operational',
!                     InciStateType    => 'operational',
!                     CurInciStateID   => $InciStateListReverse{Operational},
!                     CurInciState     => 'Operational',
!                     CurInciStateType => 'operational',
!                     XMLData          => [],
!                     CreateBy         => 1,
!                 },
!             ],
!         },
!     },
! 
!     # all required values are given (check the calculation of deployment and incident state)
!     {
!         SourceData => {
!             ConfigItemAdd => {
!                 Number  => $ConfigItemNumbers[10],
!                 ClassID => $ConfigItemClassIDs[0],
!                 UserID  => 1,
!             },
!             VersionAdd => [
!                 {
!                     Name         => 'UnitTest - ConfigItem 10 Version 1',
!                     DefinitionID => $ConfigItemDefinitionIDs[0],
!                     DeplStateID  => $DeplStateListReverse{Planned},
!                     InciStateID  => $InciStateListReverse{Operational},
!                     UserID       => 1,
!                 },
!                 {
!                     Name         => 'UnitTest - ConfigItem 10 Version 2',
!                     DefinitionID => $ConfigItemDefinitionIDs[0],
!                     DeplStateID  => $DeplStateListReverse{Maintenance},
!                     InciStateID  => $InciStateListReverse{Incident},
!                     UserID       => 1,
!                 },
!             ],
!         },
!         ReferenceData => {
!             ConfigItemGet => {
!                 Number           => $ConfigItemNumbers[10],
!                 ClassID          => $ConfigItemClassIDs[0],
!                 Class            => $ClassList->{ $ConfigItemClassIDs[0] },
!                 CurDeplStateID   => $DeplStateListReverse{Maintenance},
!                 CurDeplState     => 'Maintenance',
!                 CurDeplStateType => 'productive',
!                 CurInciStateID   => $InciStateListReverse{Incident},
!                 CurInciState     => 'Incident',
!                 CurInciStateType => 'incident',
!                 CreateBy         => 1,
!                 ChangeBy         => 1,
!             },
!             VersionGet => [
!                 {
!                     Number           => $ConfigItemNumbers[10],
!                     ClassID          => $ConfigItemClassIDs[0],
!                     Class            => $ClassList->{ $ConfigItemClassIDs[0] },
!                     Name             => 'UnitTest - ConfigItem 10 Version 1',
!                     DefinitionID     => $ConfigItemDefinitionIDs[0],
!                     DeplStateID      => $DeplStateListReverse{Planned},
!                     DeplState        => 'Planned',
!                     DeplStateType    => 'preproductive',
!                     CurDeplStateID   => $DeplStateListReverse{Maintenance},
!                     CurDeplState     => 'Maintenance',
!                     CurDeplStateType => 'productive',
!                     InciStateID      => $InciStateListReverse{Operational},
!                     InciState        => 'Operational',
!                     InciStateType    => 'operational',
!                     CurInciStateID   => $InciStateListReverse{Incident},
!                     CurInciState     => 'Incident',
!                     CurInciStateType => 'incident',
!                     XMLData          => [],
!                     CreateBy         => 1,
!                 },
!                 {
!                     Number           => $ConfigItemNumbers[10],
!                     ClassID          => $ConfigItemClassIDs[0],
!                     Class            => $ClassList->{ $ConfigItemClassIDs[0] },
!                     Name             => 'UnitTest - ConfigItem 10 Version 2',
!                     DefinitionID     => $ConfigItemDefinitionIDs[0],
!                     DeplStateID      => $DeplStateListReverse{Maintenance},
!                     DeplState        => 'Maintenance',
!                     DeplStateType    => 'productive',
!                     CurDeplStateID   => $DeplStateListReverse{Maintenance},
!                     CurDeplState     => 'Maintenance',
!                     CurDeplStateType => 'productive',
!                     InciStateID      => $InciStateListReverse{Incident},
!                     InciState        => 'Incident',
!                     InciStateType    => 'incident',
!                     CurInciStateID   => $InciStateListReverse{Incident},
!                     CurInciState     => 'Incident',
!                     CurInciStateType => 'incident',
!                     XMLData          => [],
!                     CreateBy         => 1,
!                 },
!             ],
!         },
!     },
  ];
  
***************
*** 641,644 ****
--- 902,937 ----
  
          next TEST if !$ConfigItemID;
+     }
+     else {
+ 
+         $Self->False(
+             $ConfigItemID,
+             "Test $TestCount: ConfigItemAdd() Add new config item. Return false.",
+         );
+     }
+ 
+     # add all defined versions
+     my @VersionIDs;
+     if ( $SourceData->{VersionAdd} ) {
+ 
+         for my $Version ( @{ $SourceData->{VersionAdd} } ) {
+ 
+             if ($ConfigItemID) {
+                 $Version->{ConfigItemID} = $ConfigItemID;
+             }
+ 
+             # add a new version
+             my $VersionID = $Self->{ConfigItemObject}->VersionAdd(
+                 %{$Version},
+             );
+ 
+             if ($VersionID) {
+                 push @VersionIDs, $VersionID;
+             }
+         }
+     }
+ 
+     # check the config item
+     if ( $Test->{ReferenceData} && $Test->{ReferenceData}->{ConfigItemGet} ) {
  
          # get the confi item data
***************
*** 653,658 ****
                  "Test $TestCount: ConfigItemGet() get config item data."
              );
- 
-             next TEST;
          }
  
--- 946,949 ----
***************
*** 679,710 ****
          }
      }
-     else {
- 
-         $Self->False(
-             $ConfigItemID,
-             "Test $TestCount: ConfigItemAdd() Add new config item. Return false.",
-         );
-     }
- 
-     # add all defined versions
-     my @VersionIDs;
-     if ( $SourceData->{VersionAdd} ) {
- 
-         for my $Version ( @{ $SourceData->{VersionAdd} } ) {
- 
-             if ($ConfigItemID) {
-                 $Version->{ConfigItemID} = $ConfigItemID;
-             }
- 
-             # add a new version
-             my $VersionID = $Self->{ConfigItemObject}->VersionAdd(
-                 %{$Version},
-             );
- 
-             if ($VersionID) {
-                 push @VersionIDs, $VersionID;
-             }
-         }
-     }
  
      # check the versions
--- 970,973 ----
***************
*** 735,738 ****
--- 998,1002 ----
      next TEST if !$Test->{ReferenceData}->{VersionGet};
  
+     my $Counter = 0;
      VERSIONID:
      for my $VersionID (@VersionIDs) {
***************
*** 755,778 ****
  
          # check all version attributes
-         my $Counter = 0;
          for my $Attribute ( keys %{ $Test->{ReferenceData}->{VersionGet}->[$Counter] } ) {
  
              # set content if values are undef
!             if ( !defined $VersionData->{$Attribute} ) {
!                 $VersionData->{$Attribute} = 'UNDEF-unittest';
              }
!             if ( !defined $Test->{ReferenceData}->{VersionGet}->[$Counter]->{$Attribute} ) {
!                 $Test->{ReferenceData}->{VersionGet}->[$Counter]->{$Attribute} = 'UNDEF-unittest';
              }
  
              # check attributes
              $Self->Is(
!                 $VersionData->{$Attribute},
!                 $Test->{ReferenceData}->{VersionGet}->[$Counter]->{$Attribute},
                  "Test $TestCount: VersionGet() - $Attribute",
              );
- 
-             $Counter++;
          }
      }
  }
--- 1019,1057 ----
  
          # check all version attributes
          for my $Attribute ( keys %{ $Test->{ReferenceData}->{VersionGet}->[$Counter] } ) {
  
+             # extract the needed attributes
+             my $VersionAttribute   = $VersionData->{$Attribute};
+             my $ReferenceAttribute = $Test->{ReferenceData}->{VersionGet}->[$Counter]->{$Attribute};
+ 
              # set content if values are undef
!             if ( !defined $VersionAttribute ) {
!                 $VersionAttribute = 'UNDEF-unittest';
              }
!             if ( !defined $ReferenceAttribute ) {
!                 $ReferenceAttribute = 'UNDEF-unittest';
!             }
! 
!             if ( $Attribute eq 'XMLDefinition' || $Attribute eq 'XMLData' ) {
! 
!                 # turn off all pretty print
!                 $Data::Dumper::Indent = 0;
! 
!                 # dump the attribute from VersionGet()
!                 $VersionAttribute = Data::Dumper::Dumper($VersionAttribute);
! 
!                 # dump the reference attribute
!                 $ReferenceAttribute = Data::Dumper::Dumper($ReferenceAttribute);
              }
  
              # check attributes
              $Self->Is(
!                 $VersionAttribute,
!                 $ReferenceAttribute,
                  "Test $TestCount: VersionGet() - $Attribute",
              );
          }
+ 
+         $Counter++;
      }
  }


More information about the cvs-log mailing list