#!/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
    my $uri = $idata->create_object( "foo" );

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

Test::IData->setup;

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

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

Test::IData->setup;

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

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

Test::IData->setup;

{
    # key, class, volume, comment
    my $uri = $idata->create_object( "foo", 0, "node01", "this is foo" );

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

Test::IData->setup;

eval {
    $idata->create_object( "foo" );
    $idata->create_object( "foo" );
};
like( $@, qr/Duplicate entry/, "object already exists" );

Test::IData->setup;

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

Test::IData->setup;

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

Test::IData->cleanup;
