#!/usr/bin/perl

use strict;
use warnings;

use Apache::Test qw( -withtestmore );

plan tests => 11;

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

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

my $hostport = Apache::Test->config->{ 'hostport' };

Test::IData->setup;

{
    # key
    my $idata = PS::IPP::IData::Client->new(
        proxy => "http://$hostport/idata",
    );
    $idata->create( "foo" );

    my $uri = $idata->replicate( "foo" );

    ok( $uri, "good replication" );
    ok( -e _get_file_path( $uri ), "file exists" );
}

Test::IData->setup;

{
    # key, $volume
    my $idata = PS::IPP::IData::Client->new(
        proxy => "http://$hostport/idata",
    );
    $idata->create( "foo" );

    my $uri = $idata->replicate( "foo", "node01" );

    ok( $uri, "good replication" );
    ok( -e _get_file_path( $uri ), "file exists" );
}

Test::IData->setup;

{
    # key, $volume
    my $idata = PS::IPP::IData::Client->new(
        proxy => "http://$hostport/idata",
    );
    $idata->create( "foo" );

    my $uri1 = $idata->replicate( "foo", "node01" );
    my $uri2 = $idata->replicate( "foo", "node02" );

    ok( $uri1, "good replication" );
    ok( $uri2, "good replication" );
    ok( -e _get_file_path( $uri1 ), "file exists" );
    ok( -e _get_file_path( $uri2 ), "file exists" );
}

Test::IData->setup;

{
    my $idata = PS::IPP::IData::Client->new(
        proxy => "http://$hostport/idata",
    );
    my $uri = $idata->replicate( "foo" );

    is( $uri, undef, "storage object does not exist" );
}

Test::IData->setup;

eval {
    my $idata = PS::IPP::IData::Client->new(
        proxy => "http://$hostport/idata",
    );
    $idata->replicate();
};
like( $@, qr/1 - 2 were expected/, "no params" );

Test::IData->setup;

eval {
    my $idata = PS::IPP::IData::Client->new(
        proxy => "http://$hostport/idata",
    );
    $idata->replicate( 1, 2, 3 );
};
like( $@, qr/1 - 2 were expected/, "too many params" );

Test::IData->cleanup;
