22
33import static org .testng .Assert .assertEquals ;
44import static org .testng .Assert .assertFalse ;
5+ import static org .testng .Assert .assertNotNull ;
56import static org .testng .Assert .assertTrue ;
67
8+ import java .io .IOException ;
79import java .util .HashMap ;
810import java .util .List ;
911import java .util .Map ;
1719import org .openstack4j .model .network .ext .LbPoolUpdate ;
1820import org .openstack4j .openstack .networking .domain .ext .LbMethod ;
1921import org .openstack4j .openstack .networking .domain .ext .Protocol ;
22+ import org .testng .Assert ;
2023import org .testng .annotations .Test ;
2124
22- /**
23- *
24- * @author liujunpeng
25- *
26- */
27- @ Test (suiteName ="Network/lbpool" , enabled =false )
28- public class LbPoolTests extends AbstractTest {
29- public void testListPool () {
25+ @ Test (suiteName ="Network/lbpool" , enabled =true )
26+ public class LbPoolTests extends AbstractTest {
27+
28+ private static final String LBPOOLS_JSON = "/network/lbpools.json" ;
29+ private static final String LBPOOL_JSON = "/network/lbpool.json" ;
30+ private static final String LBPOOL_UPDATE_JSON = "/network/lbpool_update.json" ;
31+
32+ public void testListPool () throws IOException {
33+ respondWith (LBPOOLS_JSON );
3034 List <? extends LbPool > list = os ().networking ().loadbalancers ().lbPool ().list ();
31- System .out .println ("test lb pool List" + list );
3235 assertEquals (1 , list .size ());
36+ assertEquals (list .get (0 ).getSubnetId (), "8032909d-47a1-4715-90af-5153ffe39861" );
3337 }
3438
35- public void testListPoolFilter () {
39+ public void testListPoolFilter () throws IOException {
40+ respondWith (LBPOOLS_JSON );
3641 Map <String , String > map = new HashMap <String , String >();
3742 map .put ("name" , "pool" );
3843 List <? extends LbPool > list = os ().networking ().loadbalancers ().lbPool ().list (map );
39- System .out .println ("test lb pool List filter" + list );
4044 assertEquals (1 , list .size ());
4145 }
4246
43- public void testGetPool () {
44- String id = "f6f1a5bb-2c5d-4c41-941c-024eb39414a6" ;
47+ public void testGetPool () throws IOException {
48+ respondWith (LBPOOL_JSON );
49+ String id = "4c0a0a5f-cf8f-44b7-b912-957daa8ce5e5" ;
4550 LbPool pool = os ().networking ().loadbalancers ().lbPool ().get (id );
46- System . out . println ( "test get a pool" + pool );
51+ assertNotNull ( pool );
4752 assertEquals (id , pool .getId ());
4853 }
4954
50- public void testCreatePool () {
51- String name = "create" ;
55+ public void testCreatePool () throws IOException {
56+ respondWith (LBPOOL_JSON );
57+ String name = "pool1" ;
5258 String protocol = Protocol .HTTP .toString ();
5359 LbPool create = Builders .lbPool ().adminStateUp (true )
5460 .description ("pool" ).lbMethod (LbMethod .ROUND_ROBIN .toString ())
@@ -58,11 +64,11 @@ public void testCreatePool() {
5864 .protocol (protocol ).build ();
5965 LbPool result = os ().networking ().loadbalancers ().lbPool ().create (create );
6066 assertEquals (name , result .getName ());
61- assertEquals (LbMethod . ROUND_ROBIN . toString (), result . getLbMethod ());
67+ assertEquals (result . getLbMethod (), LbMethod . ROUND_ROBIN . toString ());
6268 assertEquals (protocol , result .getProtocol ());
6369 }
64-
65- public void testUpdatePool () {
70+ public void testUpdatePool () throws IOException {
71+ respondWith ( LBPOOL_UPDATE_JSON );
6672 String poolId = "db083bf7-c455-4758-b1ad-203cf441a73a" ;
6773 String name = "update" ;
6874 LbPoolUpdate update = Builders .lbPoolUpdate ().adminStateUp (false )
@@ -76,28 +82,30 @@ public void testUpdatePool() {
7682 assertFalse (result .isAdminStateUp ());
7783 }
7884
85+ @ Test (enabled =false )
7986 public void testAssociateHealthMonitor () {
8087 String poolId = "db083bf7-c455-4758-b1ad-203cf441a73a" ;
8188 String healthId = "8767284a-b542-4db6-8393-0a404a959c1d" ;
8289 HealthMonitorAssociate associate = Builders .lbPoolAssociateHealthMonitor ().id (healthId ).build ();
8390 HealthMonitor result = os ().networking ().loadbalancers ().lbPool ().associateHealthMonitor (poolId , associate );
8491 assertTrue (result != null );
8592 }
86-
93+
94+ @ Test (enabled =false )
8795 public void testDisAssociateHealthMonitor () {
8896 String poolId = "db083bf7-c455-4758-b1ad-203cf441a73a" ;
8997 String healthId = "8767284a-b542-4db6-8393-0a404a959c1d" ;
9098 ActionResponse result = os ().networking ().loadbalancers ().lbPool ()
9199 .disAssociateHealthMonitor (poolId , healthId );
92100 assertTrue (result .isSuccess ());
93101 }
94-
102+
95103 public void testDeletePool () {
96- String id = "02ae87ec-5502-469e-8c41-f2c57d185054" ;
97- ActionResponse result = os ().networking ().loadbalancers ().lbPool ().delete (id );
98- System .out .println ("delete a pool" + result );
104+ respondWith (200 );
105+ ActionResponse result = os ().networking ().loadbalancers ().lbPool ().delete ("02ae87ec-5502-469e-8c41-f2c57d185054" );
99106 assertTrue (result .isSuccess ());
100107 }
108+
101109 @ Override
102110 protected Service service () {
103111 return Service .NETWORK ;
0 commit comments