<commit_before># --
# ObjectLockState.t - ObjectLockState tests
# Copyright (C) 2001-2011 OTRS AG, http://otrs.org/
# --
# $Id: ObjectLockState.t,v 1.1 2011-02-28 11:32:25 mg Exp $
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --

use strict;
use warnings;
use vars (qw($Self));
use utf8;

use Kernel::System::GenericInterface::Webservice;
use Kernel::System::GenericInterface::ObjectLockState;

my $WebserviceObject      = Kernel::System::GenericInterface::Webservice->new( %{$Self} );
my $ObjectLockStateObject = Kernel::System::GenericInterface::ObjectLockState->new( %{$Self} );

my $RandomNumber     = int rand(10000000);
my $CustomObjectType = "TestObject$RandomNumber";

# add config
my $WebserviceID = $WebserviceObject->WebserviceAdd(
    Config => {
        Debugger => {
            DebugThreshold => 'debug',
        },
    },
    Name    => "Test$RandomNumber",
    ValidID => 1,
    UserID  => 1,
);

$Self->True(
    $WebserviceID,
    "WebserviceAdd()",
);

my $Success = $ObjectLockStateObject->ObjectLockStateSet(
    WebserviceID     => $WebserviceID,
    ObjectType       => $CustomObjectType,
    ObjectID         => $RandomNumber,
    LockState        => 'locked',
    LockStateCounter => 0,
);

$Self->True(
    $Success,
    'ObjectLockStateSet() for new entry',
);

my $ObjectLockState = $ObjectLockStateObject->ObjectLockStateGet(
    WebserviceID => $WebserviceID,
    ObjectType   => $CustomObjectType,
    ObjectID     => $RandomNumber,
);

my %Check = (
    ObjectType       => $CustomObjectType,
    ObjectID         => $RandomNumber,
    LockState        => 'locked',
    LockStateCounter => 0,
);

for my $Key ( sort keys %Check ) {
    $Self->Is(
        $ObjectLockState->{$Key},
        $Check{$Key},
        "ObjectLockStateGet() $Key for new entry",
    );
}

$Success = $ObjectLockStateObject->ObjectLockStateSet(
    WebserviceID     => $WebserviceID,
    ObjectType       => $CustomObjectType,
    ObjectID         => $RandomNumber,
    LockState        => 'locked2',
    LockStateCounter => 3,
);

$Self->True(
    $Success,
    'ObjectLockStateSet() for existing entry',
);

$ObjectLockState = $ObjectLockStateObject->ObjectLockStateGet(
    WebserviceID => $WebserviceID,
    ObjectType   => $CustomObjectType,
    ObjectID     => $RandomNumber,
);

%Check = (
    ObjectType       => $CustomObjectType,
    ObjectID         => $RandomNumber,
    LockState        => 'locked2',
    LockStateCounter => 3,
);

for my $Key ( sort keys %Check ) {
    $Self->Is(
        $ObjectLockState->{$Key},
        $Check{$Key},
        "ObjectLockStateGet() $Key for existing entry",
    );
}

my $ObjectLockStates = $ObjectLockStateObject->ObjectLockStateList(
    WebserviceID => $WebserviceID,
    ObjectType   => $CustomObjectType,
    ObjectID     => $RandomNumber,
);

$Self->Is(
    scalar @{$ObjectLockStates},
    1,
    "ObjectLockStateList() for ObjectType",
);

for my $Key ( sort keys %Check ) {
    $Self->Is(
        $ObjectLockStates->[0]->{$Key},
        $Check{$Key},
        "ObjectLockStateList() $Key for existing entry",
    );
}

$Success = $ObjectLockStateObject->ObjectLockStateDelete(
    WebserviceID => $WebserviceID,
    ObjectType   => $CustomObjectType,
    ObjectID     => $RandomNumber,
);

$Self->True(
    $Success,
    'ObjectLockStateDelete() for existing entry',
);

$ObjectLockState = $ObjectLockStateObject->ObjectLockStateGet(
    WebserviceID => $WebserviceID,
    ObjectType   => $CustomObjectType,
    ObjectID     => $RandomNumber,
);

$Self->False(
    scalar %{$ObjectLockState},
    "ObjectLockStateGet() for deleted entry",
);

$Success = $ObjectLockStateObject->ObjectLockStateDelete(
    WebserviceID => $WebserviceID,
    ObjectType   => $CustomObjectType,
    ObjectID     => $RandomNumber,
);

$Self->False(
    defined $Success,
    'ObjectLockStateDelete() for deleted entry',
);

# delete config
$Success = $WebserviceObject->WebserviceDelete(
    ID     => $WebserviceID,
    UserID => 1,
);

$Self->True(
    $Success,
    "WebserviceDelete()",
);

1;
<commit_msg>Improved tests.<commit_after># --
# ObjectLockState.t - ObjectLockState tests
# Copyright (C) 2001-2011 OTRS AG, http://otrs.org/
# --
# $Id: ObjectLockState.t,v 1.2 2011-02-28 13:10:21 mg Exp $
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --

use strict;
use warnings;
use vars (qw($Self));
use utf8;

use Kernel::System::GenericInterface::Webservice;
use Kernel::System::GenericInterface::ObjectLockState;

my $WebserviceObject      = Kernel::System::GenericInterface::Webservice->new( %{$Self} );
my $ObjectLockStateObject = Kernel::System::GenericInterface::ObjectLockState->new( %{$Self} );

my $RandomNumber     = int rand(10000000);
my $CustomObjectType = "TestObject$RandomNumber";
my $Success;

# add config
my $WebserviceID = $WebserviceObject->WebserviceAdd(
    Config => {
        Debugger => {
            DebugThreshold => 'debug',
        },
    },
    Name    => "Test$RandomNumber",
    ValidID => 1,
    UserID  => 1,
);

$Self->True(
    $WebserviceID,
    "WebserviceAdd()",
);

sub StateSet {

    # set initial
    $Success = $ObjectLockStateObject->ObjectLockStateSet(
        WebserviceID     => $WebserviceID,
        ObjectType       => $CustomObjectType,
        ObjectID         => $RandomNumber,
        LockState        => 'locked',
        LockStateCounter => 0,
    );

    $Self->True(
        $Success,
        'ObjectLockStateSet() for new entry',
    );

    # get data
    my $ObjectLockState = $ObjectLockStateObject->ObjectLockStateGet(
        WebserviceID => $WebserviceID,
        ObjectType   => $CustomObjectType,
        ObjectID     => $RandomNumber,
    );

    my %Check = (
        ObjectType       => $CustomObjectType,
        ObjectID         => $RandomNumber,
        LockState        => 'locked',
        LockStateCounter => 0,
    );

    for my $Key ( sort keys %Check ) {
        $Self->Is(
            $ObjectLockState->{$Key},
            $Check{$Key},
            "ObjectLockStateGet() $Key for new entry",
        );
    }

    # update
    $Success = $ObjectLockStateObject->ObjectLockStateSet(
        WebserviceID     => $WebserviceID,
        ObjectType       => $CustomObjectType,
        ObjectID         => $RandomNumber,
        LockState        => 'locked2',
        LockStateCounter => 3,
    );

    $Self->True(
        $Success,
        'ObjectLockStateSet() for existing entry',
    );

    # get data
    $ObjectLockState = $ObjectLockStateObject->ObjectLockStateGet(
        WebserviceID => $WebserviceID,
        ObjectType   => $CustomObjectType,
        ObjectID     => $RandomNumber,
    );

    %Check = (
        ObjectType       => $CustomObjectType,
        ObjectID         => $RandomNumber,
        LockState        => 'locked2',
        LockStateCounter => 3,
    );

    for my $Key ( sort keys %Check ) {
        $Self->Is(
            $ObjectLockState->{$Key},
            $Check{$Key},
            "ObjectLockStateGet() $Key for existing entry",
        );
    }

    return;
}

StateSet();

# check list
my $ObjectLockStates = $ObjectLockStateObject->ObjectLockStateList(
    WebserviceID => $WebserviceID,
    ObjectType   => $CustomObjectType,
    ObjectID     => $RandomNumber,
);

$Self->Is(
    scalar @{$ObjectLockStates},
    1,
    "ObjectLockStateList() for ObjectType",
);

my %Check = (
    ObjectType       => $CustomObjectType,
    ObjectID         => $RandomNumber,
    LockState        => 'locked2',
    LockStateCounter => 3,
);

for my $Key ( sort keys %Check ) {
    $Self->Is(
        $ObjectLockStates->[0]->{$Key},
        $Check{$Key},
        "ObjectLockStateList() $Key for existing entry",
    );
}

# delete first time
$Success = $ObjectLockStateObject->ObjectLockStateDelete(
    WebserviceID => $WebserviceID,
    ObjectType   => $CustomObjectType,
    ObjectID     => $RandomNumber,
);

$Self->True(
    $Success,
    'ObjectLockStateDelete() for existing entry',
);

# check
my $ObjectLockState = $ObjectLockStateObject->ObjectLockStateGet(
    WebserviceID => $WebserviceID,
    ObjectType   => $CustomObjectType,
    ObjectID     => $RandomNumber,
);

$Self->False(
    scalar %{$ObjectLockState},
    "ObjectLockStateGet() for deleted entry",
);

# check list
$ObjectLockStates = $ObjectLockStateObject->ObjectLockStateList(
    WebserviceID => $WebserviceID,
    ObjectType   => $CustomObjectType,
    ObjectID     => $RandomNumber,
);

$Self->Is(
    scalar @{$ObjectLockStates},
    0,
    "ObjectLockStateList() for ObjectType",
);

# delete second time - fail
$Success = $ObjectLockStateObject->ObjectLockStateDelete(
    WebserviceID => $WebserviceID,
    ObjectType   => $CustomObjectType,
    ObjectID     => $RandomNumber,
);

$Self->False(
    defined $Success,
    'ObjectLockStateDelete() for deleted entry',
);

StateSet();

# purge
$Success = $ObjectLockStateObject->ObjectLockStatePurge(
    WebserviceID => $WebserviceID,
);

$Self->True(
    $Success,
    'ObjectLockStatePurge() for existing entry',
);

# check
$ObjectLockState = $ObjectLockStateObject->ObjectLockStateGet(
    WebserviceID => $WebserviceID,
    ObjectType   => $CustomObjectType,
    ObjectID     => $RandomNumber,
);

$Self->False(
    scalar %{$ObjectLockState},
    "ObjectLockStateGet() for deleted entry",
);

# check list
$ObjectLockStates = $ObjectLockStateObject->ObjectLockStateList(
    WebserviceID => $WebserviceID,
    ObjectType   => $CustomObjectType,
    ObjectID     => $RandomNumber,
);

$Self->Is(
    scalar @{$ObjectLockStates},
    0,
    "ObjectLockStateList() for ObjectType",
);

# Add entries again to check that WebserviceDelete() still works,
#   deleting all remaining entries.
StateSet();

# delete config
$Success = $WebserviceObject->WebserviceDelete(
    ID     => $WebserviceID,
    UserID => 1,
);

$Self->True(
    $Success,
    "WebserviceDelete()",
);

1;

{'fraction_non_alphanumeric': 0.136510738452486, 'fraction_numerical': 0.00921839756791213, 'mean_word_length': 2.9976479811838495, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 167, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5562727', 'n_tokens_mistral': 3192, 'n_tokens_neox': 3108, 'n_words': 664}