[otrs-cvs] ITSMConfigItem/scripts/test ITSMConfigItem.t,NONE,1.1
CVS commits notifications of OTRS.org
cvs-log at otrs.org
Fri Apr 25 16:11:59 GMT 2008
Comments:
Update of /home/cvs/ITSMConfigItem/scripts/test
In directory lancelot:/tmp/cvs-serv22190
Added Files:
ITSMConfigItem.t
Log Message:
Init.
Author: mh
--- NEW FILE: ITSMConfigItem.t ---
# --
# ITSMConfigItem.t - config item tests
# Copyright (C) 2001-2008 OTRS AG, http://otrs.org/
# --
# $Id: ITSMConfigItem.t,v 1.1 2008/04/25 16:11:54 mh Exp $
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license inobjection (GPL). If you
# did not receive this file, see http://www.gnu.org/licenses/gpl-2.0.txt.
# --
use strict;
use warnings;
use utf8;
use vars qw($Self);
use Kernel::System::GeneralCatalog;
use Kernel::System::ITSMConfigItem;
$Self->{GeneralCatalogObject} = Kernel::System::GeneralCatalog->new( %{$Self} );
$Self->{ConfigItemObject} = Kernel::System::ITSMConfigItem->new( %{$Self} );
# ------------------------------------------------------------ #
# make preparations
# ------------------------------------------------------------ #
my $GeneralCatalogClass = 'UnitTest' . int rand 1_000_000;
# add a general catalog test list
for my $Name (qw(Test1 Test2 Test3 Test4)) {
# add a new item
my $ItemID = $Self->{GeneralCatalogObject}->ItemAdd(
Class => $GeneralCatalogClass,
Name => $Name,
ValidID => 1,
UserID => 1,
);
# check item id
if ( !$ItemID ) {
$Self->True(
0,
"Can't add new general catalog item.",
);
}
}
# define the first test definition (all provided data types)
my @ConfigItemDefinitions;
$ConfigItemDefinitions[0] = " [
{
Key => 'Customer1',
Name => 'Customer 1',
Searchable => 1,
Input => {
Type => 'Customer',
},
},
{
Key => 'Date1',
Name => 'Date 1',
Searchable => 1,
Input => {
Type => 'Date',
},
},
{
Key => 'DateTime1',
Name => 'Date Time 1',
Searchable => 1,
Input => {
Type => 'DateTime',
},
},
{
Key => 'Dummy1',
Name => 'Dummy 1',
Input => {
Type => 'Dummy',
},
},
{
Key => 'GeneralCatalog1',
Name => 'GeneralCatalog 1',
Searchable => 1,
Input => {
Type => 'GeneralCatalog',
Class => '$GeneralCatalogClass',
},
},
{
Key => 'Integer1',
Name => 'Integer 1',
Searchable => 1,
Input => {
Type => 'Integer',
},
},
{
Key => 'Text1',
Name => 'Text 1',
Searchable => 1,
Input => {
Type => 'Text',
Size => 50,
MaxLength => 50,
},
},
{
Key => 'TextArea1',
Name => 'TextArea 1',
Searchable => 1,
Input => {
Type => 'TextArea',
},
},
] ";
# define the second test definition (sub data types)
$ConfigItemDefinitions[1] = " [
{
Key => 'Main1',
Name => 'Main 1',
Searchable => 1,
Input => {
Type => 'Text',
Size => 50,
MaxLength => 50,
},
CountMax => 10,
Sub => [
{
Key => 'Main1Sub1',
Name => 'Main 1 Sub 1',
Searchable => 1,
Input => {
Type => 'Text',
Size => 50,
MaxLength => 50,
},
CountMax => 10,
Sub => [
{
Key => 'Main1Sub1SubSub1',
Name => 'Main 1 Sub 1 SubSub 1',
Searchable => 1,
Input => {
Type => 'Text',
Size => 50,
MaxLength => 50,
},
CountMax => 10,
},
{
Key => 'Main1Sub1SubSub2',
Name => 'Main 1 Sub 1 SubSub 2',
Searchable => 1,
Input => {
Type => 'TextArea',
},
CountMax => 10,
},
],
},
{
Key => 'Main1Sub2',
Name => 'Main 1 Sub 2',
Searchable => 1,
Input => {
Type => 'TextArea',
},
CountMax => 10,
},
],
},
{
Key => 'Main2',
Name => 'Main 2',
Searchable => 1,
Input => {
Type => 'TextArea',
},
CountMax => 10,
Sub => [
{
Key => 'Main2Sub1',
Name => 'Main 2 Sub 1',
Searchable => 1,
Input => {
Type => 'Text',
Size => 50,
MaxLength => 50,
},
CountMax => 10,
},
{
Key => 'Main2Sub2',
Name => 'Main 2 Sub 2',
Searchable => 1,
Input => {
Type => 'TextArea',
},
CountMax => 10,
},
],
},
] ";
# add the test classes
my @ConfigItemClassIDs;
my @ConfigItemClasses;
my @ConfigItemDefinitionIDs;
for my $Definition (@ConfigItemDefinitions) {
# generate a random name
my $ClassName = 'UnitTest' . int rand 1_000_000;
# add an unittest config item class
my $ClassID = $Self->{GeneralCatalogObject}->ItemAdd(
Class => 'ITSM::ConfigItem::Class',
Name => $ClassName,
ValidID => 1,
UserID => 1,
);
# check class id
if ( !$ClassID ) {
$Self->True(
0,
"Can't add new config item class.",
);
}
push @ConfigItemClassIDs, $ClassID;
push @ConfigItemClasses, $ClassName;
# add a definition to the class
my $DefinitionID = $Self->{ConfigItemObject}->DefinitionAdd(
ClassID => $ClassID,
Definition => $Definition,
UserID => 1,
);
# check definition id
if ( !$DefinitionID ) {
$Self->True(
0,
"Can't add new config item definition.",
);
}
push @ConfigItemDefinitionIDs, $DefinitionID;
}
# create some random numbers
my @ConfigItemNumbers;
for ( 1 .. 10 ) {
push @ConfigItemNumbers, int rand 1_000_000;
}
# get class list
my $ClassList = $Self->{GeneralCatalogObject}->ItemList(
Class => 'ITSM::ConfigItem::Class',
);
my %ClassListReverse = reverse %{$ClassList};
# get deployment state list
my $DeplStateList = $Self->{GeneralCatalogObject}->ItemList(
Class => 'ITSM::ConfigItem::DeploymentState',
);
my %DeplStateListReverse = reverse %{$DeplStateList};
# get incident state list
my $InciStateList = $Self->{GeneralCatalogObject}->ItemList(
Class => 'ITSM::ConfigItem::IncidentState',
);
my %InciStateListReverse = reverse %{$InciStateList};
# get general catalog test list
my $GeneralCatalogList = $Self->{GeneralCatalogObject}->ItemList(
Class => $GeneralCatalogClass,
);
my %GeneralCatalogListReverse = reverse %{$GeneralCatalogList};
# ------------------------------------------------------------ #
# define general config item tests
# ------------------------------------------------------------ #
my $ConfigItemTests = [
# ConfigItemAdd doesn't contains all data (check required attributes)
{
SourceData => {
ConfigItemAdd => {
UserID => 1,
},
},
},
# ConfigItemAdd doesn't contains all data (check required attributes)
{
SourceData => {
ConfigItemAdd => {
ClassID => $ConfigItemClassIDs[0],
},
},
},
# invalid class id is given (check return false)
{
SourceData => {
ConfigItemAdd => {
ClassID => $ConfigItemClassIDs[-1] + 1,
UserID => 1,
},
},
},
# all required config item values are given (check required attributes)
{
SourceData => {
ConfigItemAdd => {
ClassID => $ConfigItemClassIDs[0],
UserID => 1,
},
},
ReferenceData => {
ConfigItemGet => {
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 config item values are given (check number attribute)
{
SourceData => {
ConfigItemAdd => {
Number => $ConfigItemNumbers[0],
ClassID => $ConfigItemClassIDs[0],
UserID => 1,
},
},
ReferenceData => {
ConfigItemGet => {
Number => $ConfigItemNumbers[0],
ClassID => $ConfigItemClassIDs[0],
Class => $ClassList->{ $ConfigItemClassIDs[0] },
CurDeplStateID => undef,
CurDeplState => undef,
CurDeplStateType => undef,
CurInciStateID => undef,
CurInciState => undef,
CurInciStateType => undef,
CreateBy => 1,
ChangeBy => 1,
},
},
},
# config item with this number already exists (check return false)
{
SourceData => {
ConfigItemAdd => {
Number => $ConfigItemNumbers[0],
ClassID => $ConfigItemClassIDs[0],
UserID => 1,
},
},
},
# VersionAdd doesn't contains all data (check required attributes)
{
SourceData => {
ConfigItemAdd => {
Number => $ConfigItemNumbers[1],
ClassID => $ConfigItemClassIDs[0],
UserID => 1,
},
VersionAdd => [
{
DefinitionID => $ConfigItemDefinitionIDs[0],
DeplStateID => $DeplStateListReverse{Production},
InciStateID => $InciStateListReverse{Operational},
UserID => 1,
},
],
},
ReferenceData => {
ConfigItemGet => {
Number => $ConfigItemNumbers[1],
ClassID => $ConfigItemClassIDs[0],
Class => $ClassList->{ $ConfigItemClassIDs[0] },
CurDeplStateID => undef,
CurDeplState => undef,
CurDeplStateType => undef,
CurInciStateID => undef,
CurInciState => undef,
CurInciStateType => undef,
CreateBy => 1,
ChangeBy => 1,
},
},
},
# VersionAdd doesn't contains all data (check required attributes)
{
SourceData => {
ConfigItemAdd => {
Number => $ConfigItemNumbers[2],
ClassID => $ConfigItemClassIDs[0],
UserID => 1,
},
VersionAdd => [
{
Name => 'UnitTest - ConfigItem 1 Version 1',
DeplStateID => $DeplStateListReverse{Production},
InciStateID => $InciStateListReverse{Operational},
UserID => 1,
},
],
},
ReferenceData => {
ConfigItemGet => {
Number => $ConfigItemNumbers[2],
ClassID => $ConfigItemClassIDs[0],
Class => $ClassList->{ $ConfigItemClassIDs[0] },
CurDeplStateID => undef,
CurDeplState => undef,
CurDeplStateType => undef,
CurInciStateID => undef,
CurInciState => undef,
CurInciStateType => undef,
CreateBy => 1,
ChangeBy => 1,
},
},
},
# VersionAdd doesn't contains all data (check required attributes)
{
SourceData => {
ConfigItemAdd => {
Number => $ConfigItemNumbers[3],
ClassID => $ConfigItemClassIDs[0],
UserID => 1,
},
VersionAdd => [
{
Name => 'UnitTest - ConfigItem 1 Version 1',
DefinitionID => $ConfigItemDefinitionIDs[0],
InciStateID => $InciStateListReverse{Operational},
UserID => 1,
},
],
},
ReferenceData => {
ConfigItemGet => {
Number => $ConfigItemNumbers[3],
ClassID => $ConfigItemClassIDs[0],
Class => $ClassList->{ $ConfigItemClassIDs[0] },
CurDeplStateID => undef,
CurDeplState => undef,
CurDeplStateType => undef,
CurInciStateID => undef,
CurInciState => undef,
CurInciStateType => undef,
CreateBy => 1,
ChangeBy => 1,
},
},
},
# VersionAdd doesn't contains all data (check required attributes)
{
SourceData => {
ConfigItemAdd => {
Number => $ConfigItemNumbers[4],
ClassID => $ConfigItemClassIDs[0],
UserID => 1,
},
VersionAdd => [
{
Name => 'UnitTest - ConfigItem 1 Version 1',
DefinitionID => $ConfigItemDefinitionIDs[0],
DeplStateID => $DeplStateListReverse{Production},
UserID => 1,
},
],
},
ReferenceData => {
ConfigItemGet => {
Number => $ConfigItemNumbers[4],
ClassID => $ConfigItemClassIDs[0],
Class => $ClassList->{ $ConfigItemClassIDs[0] },
CurDeplStateID => undef,
CurDeplState => undef,
CurDeplStateType => undef,
CurInciStateID => undef,
CurInciState => undef,
CurInciStateType => undef,
CreateBy => 1,
ChangeBy => 1,
},
},
},
# VersionAdd doesn't contains all data (check required attributes)
{
SourceData => {
ConfigItemAdd => {
Number => $ConfigItemNumbers[5],
ClassID => $ConfigItemClassIDs[0],
UserID => 1,
},
VersionAdd => [
{
Name => 'UnitTest - ConfigItem 1 Version 1',
DefinitionID => $ConfigItemDefinitionIDs[0],
DeplStateID => $DeplStateListReverse{Production},
InciStateID => $InciStateListReverse{Operational},
},
],
},
ReferenceData => {
ConfigItemGet => {
Number => $ConfigItemNumbers[5],
ClassID => $ConfigItemClassIDs[0],
Class => $ClassList->{ $ConfigItemClassIDs[0] },
CurDeplStateID => undef,
CurDeplState => undef,
CurDeplStateType => undef,
CurInciStateID => undef,
CurInciState => undef,
CurInciStateType => undef,
CreateBy => 1,
ChangeBy => 1,
},
},
},
# {
# 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 => [
#
# ],
# },
# },
];
# ------------------------------------------------------------ #
# run general config item tests
# ------------------------------------------------------------ #
my $TestCount = 1;
my @ConfigItemIDs;
TEST:
for my $Test ( @{$ConfigItemTests} ) {
# check SourceData attribute
if ( !$Test->{SourceData} || ref $Test->{SourceData} ne 'HASH' ) {
$Self->True(
0,
"Test $TestCount: No SourceData found for this test.",
);
next TEST;
}
# extract source data
my $SourceData = $Test->{SourceData};
# add a new config item
my $ConfigItemID;
if ( $SourceData->{ConfigItemAdd} ) {
# add the new config item
$ConfigItemID = $Self->{ConfigItemObject}->ConfigItemAdd(
%{ $SourceData->{ConfigItemAdd} },
);
if ($ConfigItemID) {
push @ConfigItemIDs, $ConfigItemID;
}
}
# check the config item
if ( $Test->{ReferenceData} && $Test->{ReferenceData}->{ConfigItemGet} ) {
$Self->True(
$ConfigItemID,
"Test $TestCount: ConfigItemAdd() Add new config item. Insert success.",
);
next TEST if !$ConfigItemID;
# get the confi item data
my $ConfigItemData = $Self->{ConfigItemObject}->ConfigItemGet(
ConfigItemID => $ConfigItemID,
);
if ( !$ConfigItemData ) {
$Self->True(
0,
"Test $TestCount: ConfigItemGet() get config item data."
);
next TEST;
}
# check all config item attributes
my $Counter = 0;
for my $Attribute ( keys %{ $Test->{ReferenceData}->{ConfigItemGet} } ) {
# set content if values are undef
if ( !defined $ConfigItemData->{$Attribute} ) {
$ConfigItemData->{$Attribute} = 'UNDEF-unittest';
}
if ( !defined $Test->{ReferenceData}->{ConfigItemGet}->{$Attribute} ) {
$Test->{ReferenceData}->{ConfigItemGet}->{$Attribute} = 'UNDEF-unittest';
}
# check attributes
$Self->Is(
$ConfigItemData->{$Attribute},
$Test->{ReferenceData}->{ConfigItemGet}->{$Attribute},
"Test $TestCount: ConfigItemGet() - $Attribute",
);
$Counter++;
}
}
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
if (
$Test->{ReferenceData}
&& $Test->{ReferenceData}->{VersionGet}
&& @{ $Test->{ReferenceData}->{VersionGet} }
)
{
$Self->Is(
scalar @VersionIDs,
scalar @{ $Test->{ReferenceData}->{VersionGet} },
"Test $TestCount: VersionAdd() correct number of versions",
);
next TEST if !$ConfigItemID;
}
else {
$Self->False(
scalar @VersionIDs,
"Test $TestCount: VersionAdd() no versions exits",
);
}
next TEST if !$Test->{ReferenceData};
next TEST if !$Test->{ReferenceData}->{VersionGet};
VERSIONID:
for my $VersionID (@VersionIDs) {
# get this version
my $VersionData = $Self->{ConfigItemObject}->VersionGet(
VersionID => $VersionID,
XMLDataGet => 1,
);
if ( !$VersionData ) {
$Self->True(
0,
"Test $TestCount: VersionGet() get version data."
);
next VERSIONID;
}
# 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++;
}
}
}
continue {
$TestCount++;
}
# ------------------------------------------------------------ #
# clean the system
# ------------------------------------------------------------ #
# get current class list
$ClassList = $Self->{GeneralCatalogObject}->ItemList(
Class => 'ITSM::ConfigItem::Class',
);
# set unittest classes invalid
ITEMID:
for my $ItemID ( keys %{$ClassList} ) {
next ITEMID if $ClassList->{$ItemID} !~ m{ \A UnitTest }xms;
# update item
$Self->{GeneralCatalogObject}->ItemUpdate(
ItemID => $ItemID,
Name => $ClassList->{$ItemID},
ValidID => 2,
UserID => 1,
);
}
# delete the test config items
for my $ConfigItemID (@ConfigItemIDs) {
$Self->{ConfigItemObject}->ConfigItemDelete(
ConfigItemID => $ConfigItemID,
UserID => 1,
);
}
1;
More information about the cvs-log
mailing list