#!perl
use Cassandane::Tiny;

sub test_permessage_unknown_allowed
    :AnnotationAllowUndefined
{
    my ($self) = @_;

    xlog $self, "testing getting and setting unknown annotations on a message";
    xlog $self, "with config allowing this";

    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 succeed";
    $talk->store('1', 'annotation',
                 [$entry, [$attrib, $value1]]);
    $self->assert_str_equals('ok', $talk->get_last_completion_response());

    xlog $self, "fetch the annotation again, should see the value";
    $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 => $value1 } } }
            },
            $res);
}
