#!/usr/bin/perl

use strict;
use warnings;

use Apache::Test qw( -withtestmore );

plan tests => 7;

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",
    );

    my $fh = $idata->create( "foo" );

    is( ref $fh, 'GLOB', "good filehandle" );
}

Test::IData->setup;

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

    my $fh = $idata->create( "foo", 0 );

    is( ref $fh, 'GLOB', "good filehandle" );
}

Test::IData->setup;

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

    my $fh = $idata->create( "foo", 0, "node01" );

    is( ref $fh, 'GLOB', "good filehandle" );
}

Test::IData->setup;

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

    my $fh = $idata->create( "foo", 0, "node01", "this is foo" );

    is( ref $fh, 'GLOB', "good filehandle" );
}

Test::IData->setup;

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

    $idata->create( "foo" );
    is( $idata->create( "foo" ), undef, "object already exists" );
}

Test::IData->setup;

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

    $idata->create();
};
like( $@, qr/2 - 4 were expected/, "no params" );

Test::IData->setup;

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

    $idata->create( 1, 2, 3, 4, 5 );
};
like( $@, qr/2 - 4 were expected/, "too many params" );

Test::IData->cleanup;
