a3629dd2c6a866aac6fd0744001c11819d84dc3d
[Net-XRC.git] / t / Net-XRC.t
1 # Before `make install' is performed this script should be runnable with
2 # `make test'. After `make install' it should work as `perl Net-XRC.t'
3
4 #########################
5
6 # change 'tests => 1' to 'tests => last_test_to_print';
7
8 #use Test;
9 #BEGIN { plan tests => 3 };
10
11 use Test::More tests => 17;
12 BEGIN{ use_ok('Net::XRC', qw(:types)) }
13
14 #########################
15
16 # Insert your test code below, the Test::More module is use()ed here so read
17 # its man page ( perldoc Test::More ) for help writing this test script.
18
19   $Net::XRC::DEBUG = 0;
20
21   my $clientID = '1551978';
22   my $password = 'password';
23
24   my $xrc = new Net::XRC (
25     'clientID' => $clientID,
26     'password' => $password,
27   );
28
29   my $domain = 'SISD.EVERY1.NET';
30
31   # noop
32
33   my $res = $xrc->noop;
34   ok( $res->is_success, 'noop sucessful' )
35     or diag( $res->error );
36   ok( ! defined($res->content), 'noop returns undef' );
37
38   # lookupMXReadyClientIDByEmailDomain
39
40   $res = $xrc->lookupMXReadyClientIDByEmailDomain($domain);
41   ok( $res->is_success, 'lookupMXReadyClientIDByEmailDomain sucessful' )
42     or diag( $res->error );
43   my $domain_clientID = $res->content;
44   ok( $domain_clientID != -1, 'lookupMXReadyClientIDByEmailDomain' );
45
46   # isAccountName
47
48   my @set = ( 'a'..'z', '0'..'9' );
49   my $username = join('', map { $set[int(rand(scalar(@set)))] } ( 1..32 ) );
50   $res = $xrc->isAccountNameAvailable( $domain_clientID, $username );
51   ok( $res->is_success, 'isAccountName sucessful' )
52     or diag( $res->error );
53   ok( $res->content, 'isAccountName returns true' );
54
55   # isAccountName (numeric)
56
57   my @nset = ( '0'..'9' );
58   my $nusername = join('', map { $nset[int(rand(scalar(@nset)))] } ( 1..32 ) );
59   $res = $xrc->isAccountNameAvailable( $domain_clientID, string($nusername) );
60   ok( $res->is_success, 'isAccountName (numeric) sucessful' )
61     or diag( $res->error );
62   ok( $res->content, 'isAccountName (numeric) returns true' );
63
64   # createUser
65
66   $res = $xrc->createUser( $domain_clientID, [], $username, 'password' );
67   ok( $res->is_success, 'createUser sucessful' )
68     or diag( $res->error );
69   ok( $res->content, 'createUser returns uid' );
70
71   # createUser (numeric)
72
73   $res = $xrc->createUser( $domain_clientID, [], string($nusername), 'password' );
74   ok( $res->is_success, 'createUser (numeric) sucessful' )
75     or diag( $res->error );
76   ok( $res->content, 'createUser (numeric) returns uid' );
77
78
79   # setUserPassword 
80
81   $res = $xrc->setUserPassword ( $domain_clientID, $username, 'newpassword' );
82   ok( $res->is_success, 'setUserPassword sucessful' )
83     or diag( $res->error );
84
85   # suspendUser
86
87   $res = $xrc->suspendUser( $domain_clientID, $username );
88   ok( $res->is_success, 'suspendUser sucessful' )
89     or diag( $res->error );
90
91   # unsuspendUser
92
93   $res = $xrc->unsuspendUser( $domain_clientID, $username );
94   ok( $res->is_success, 'unsuspendUser sucessful' )
95     or diag( $res->error );
96
97
98   # deleteUser
99
100   $res = $xrc->deleteUser( $domain_clientID, $username );
101   ok( $res->is_success, 'deleteUser sucessful' )
102     or diag( $res->error );
103
104