#!/usr/bin/perl

use strict;
use warnings;

use Test::More tests => 11;

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

use PS::IPP::IData::Server;
use PS::IPP::IData::Util qw( :standard );
use Test::IData;

my $idata = "PS::IPP::IData::Server";

$idata->setup(
    "DBI:mysql:database=test:host=localhost",
    "test",
    "",
);

Test::IData->setup;

{
    # key
    $idata->create_object( "foo" );
    my $uri = $idata->replicate_object( "foo" );

    ok( -e _get_file_path( $uri ), "file exists" );
    like( $uri, qr/^file:\//, "valid URI" );
}

Test::IData->setup;

{
    # key, $volume
    $idata->create_object( "foo" );
    my $uri = $idata->replicate_object( "foo", "node01" );

    ok( -e _get_file_path( $uri ), "file exists" );
    like( $uri, qr/^file:\//, "valid URI" );
}

Test::IData->setup;

{
    # key, $volume
    $idata->create_object( "foo" );
    my $uri1 = $idata->replicate_object( "foo", "node01" );
    my $uri2 = $idata->replicate_object( "foo", "node02" );

    ok( -e _get_file_path( $uri1 ), "file exists" );
    ok( -e _get_file_path( $uri2 ), "file exists" );
    like( $uri1, qr/^file:\//, "valid URI" );
    like( $uri2, qr/^file:\//, "valid URI" );
}

Test::IData->setup;

eval {
    $idata->replicate_object( "foo" );
};
like( $@, qr/storage object does not exist/, "storage object does not exist" );

Test::IData->setup;

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

Test::IData->setup;

eval {
    $idata->replicate_object( 1, 2, 3 );
};
like( $@, qr/1 - 2 were expected/, "too many params" );

Test::IData->cleanup;
