#!perl
use Cassandane::Tiny;

sub test_permessage_unknown
{
    my ($self) = @_;

    xlog $self, "testing getting and setting unknown annotations on a message";
    xlog $self, "where this is forbidden by the default config";

    xlog $self, "Append a message";
    my %msg;
    $msg{A} = $self->make_message('Message A');

    my $entry = '/thisentryisnotdefined';
    my $attrib = 'value.priv';
    my $value1 = "Hello World";

    xlog $self, "fetch annotation - should be no values";
    my $talk = $self->{store}->get_client();
    my $res = $talk->fetch('1:*',
                           ['annotation', [$entry, $attrib]]);
    $self->assert_str_equals('ok', $talk->get_last_completion_response());
    $self->assert_not_null($res);
    $self->assert_deep_equals(
            {
                1 => { annotation => { $entry => { $attrib => undef } } }
            },
            $res);

    xlog $self, "store annotation - should fail";
    $talk->store('1', 'annotation',
                 [$entry, [$attrib, $value1]]);
    $self->assert_str_equals('no', $talk->get_last_completion_response());

    xlog $self, "fetch the annotation again, should see nothing";
    $res = $talk->fetch('1:*',
                        ['annotation', [$entry, $attrib]]);
    $self->assert_str_equals('ok', $talk->get_last_completion_response());
    $self->assert_not_null($res);
    $self->assert_deep_equals(
            {
                1 => { annotation => { $entry => { $attrib => undef } } }
            },
            $res);
}
