#!/usr/bin/perl

# Copryight (C) 2007  Joshua Hoblitt
#
# $Id: 13_server_rename_object.t,v 1.2 2007-05-03 22:10:14 jhoblitt Exp $

use strict;
use warnings FATAL => qw( all );

use Test::More tests => 6;

use lib qw( ./t ./lib );

use Nebulous::Server;
use Nebulous::Util qw( :standard );
use Test::Nebulous;

my $neb = Nebulous::Server->new(
    dsn         => "DBI:mysql:database=test:host=localhost",
    dbuser      => "test",
    dbpasswd    => "",
);

Test::Nebulous->setup;

{
    my $uri = $neb->create_object("foo");

    $neb->rename_object("foo", "bar");

    my $keys = $neb->find_objects('^foo$');
    is(scalar @$keys, 0, 'number of keys found');
    $keys = $neb->find_objects('^bar$');
    is(scalar @$keys, 1, 'number of keys found');
}

Test::Nebulous->setup;

# destination key exists
eval {
    $neb->create_object('foo');
    $neb->create_object('bar');

    $neb->rename_object('foo', 'bar');
};
like($@, qr/is not valid object key/, "too few params");

Test::Nebulous->setup;

eval {
    $neb->rename_object();
};
like($@, qr/2 were expected/, "no params");

Test::Nebulous->setup;

eval {
    $neb->create_object("foo");

    $neb->rename_object("foo");
};
like($@, qr/2 were expected/, "too few params");

Test::Nebulous->setup;

eval {
    $neb->create_object("foo");

    $neb->rename_object("foo", "bar", "baz");
};
like($@, qr/2 were expected/, "too many params");

Test::Nebulous->cleanup;
