2121
2222import static org .junit .Assert .assertEquals ;
2323import static org .junit .Assert .assertTrue ;
24+ import static org .junit .Assert .fail ;
2425
2526import java .util .ArrayList ;
2627import java .util .List ;
@@ -104,36 +105,14 @@ public void testCRUDSecurityProfile() {
104105 }
105106
106107 @ Test
107- public void testCRUDAcl () {
108- Acl acl = new Acl ();
109- acl .setDisplayName ("Acl" + timestamp );
110-
111- // Note that if the protocol is 6 (TCP) then you cannot put ICMP code and type
112- // Note that if the protocol is 1 (ICMP) then you cannot put ports
113- final List <AclRule > egressRules = new ArrayList <AclRule >();
114- acl .setLogicalPortEgressRules (egressRules );
115- egressRules .add (new AclRule (AclRule .ETHERTYPE_IPV4 , 1 , "allow" , null , null , "1.10.10.0" , "1.10.10.1" , null , null , null , null , 0 , 0 , 5 ));
116- egressRules .add (new AclRule (AclRule .ETHERTYPE_IPV4 , 6 , "allow" , null , null , "1.10.10.6" , "1.10.10.7" , 80 , 80 , 80 , 80 , 1 , null , null ));
117-
118- final List <AclRule > ingressRules = new ArrayList <AclRule >();
119- acl .setLogicalPortIngressRules (ingressRules );
120- ingressRules .add (new AclRule (AclRule .ETHERTYPE_IPV4 , 1 , "allow" , null , null , "1.10.10.0" , "1.10.10.1" , null , null , null , null , 0 , 0 , 5 ));
121- ingressRules .add (new AclRule (AclRule .ETHERTYPE_IPV4 , 6 , "allow" , null , null , "1.10.10.6" , "1.10.10.7" , 80 , 80 , 80 , 80 , 1 , null , null ));
122-
123- final List <NiciraNvpTag > tags = new ArrayList <NiciraNvpTag >();
124- acl .setTags (tags );
125- tags .add (new NiciraNvpTag ("nvp" , "MyTag1" ));
126- tags .add (new NiciraNvpTag ("nicira" , "MyTag2" ));
127- // In the creation we don't get to specify UUID, href or schema: they don't exist yet
128-
108+ public void testCRUDAclReadAll () {
129109 try {
130- acl = api . createAcl ( acl );
110+ Acl acl = setupAcl ( );
131111
132- // We can now update the new entity
112+ acl = api . createAcl ( acl );
133113 acl .setDisplayName ("UpdatedAcl" + timestamp );
134114 api .updateAcl (acl , acl .getUuid ());
135115
136- // Read them all
137116 List <Acl > acls = api .findAcl ();
138117 Acl scInList = null ;
139118 for (final Acl iAcl : acls ) {
@@ -143,16 +122,30 @@ public void testCRUDAcl() {
143122 }
144123 assertEquals ("Read a ACL different from the one just created and updated" , acl , scInList );
145124
146- // Read them filtered by uuid (get one)
147- acls = api .findAcl (acl .getUuid ());
125+ api .deleteAcl (acl .getUuid ());
126+ } catch (final NiciraNvpApiException e ) {
127+ e .printStackTrace ();
128+ fail ("Errors in ACL CRUD" );
129+ }
130+ }
131+
132+ @ Test
133+ public void testCRUDAclReadOne () {
134+ try {
135+ Acl acl = setupAcl ();
136+
137+ acl = api .createAcl (acl );
138+ acl .setDisplayName ("UpdatedAcl" + timestamp );
139+ api .updateAcl (acl , acl .getUuid ());
140+
141+ List <Acl > acls = api .findAcl (acl .getUuid ());
148142 assertEquals ("Read a ACL different from the one just created and updated" , acl , acls .get (0 ));
149143 assertEquals ("Read a ACL filtered by unique id (UUID) with more than one item" , 1 , acls .size ());
150144
151- // We can now delete the new entity
152145 api .deleteAcl (acl .getUuid ());
153146 } catch (final NiciraNvpApiException e ) {
154147 e .printStackTrace ();
155- assertTrue ("Errors in ACL CRUD" , false );
148+ fail ("Errors in ACL CRUD" );
156149 }
157150 }
158151
@@ -316,4 +309,29 @@ public void testGetControlClusterStatus() throws NiciraNvpApiException {
316309 assertTrue ("Not recognizable cluster status" , correctStatus );
317310 }
318311
312+ private Acl setupAcl () {
313+ Acl acl = new Acl ();
314+ acl .setDisplayName ("Acl" + timestamp );
315+
316+ // Note that if the protocol is 6 (TCP) then you cannot put ICMP code and type
317+ // Note that if the protocol is 1 (ICMP) then you cannot put ports
318+ final List <AclRule > egressRules = new ArrayList <>();
319+ acl .setLogicalPortEgressRules (egressRules );
320+ egressRules .add (new AclRule (AclRule .ETHERTYPE_IPV4 , 1 , "allow" , null , null , "1.10.10.0" , "1.10.10.1" , null , null , null , null , 0 , 0 , 5 ));
321+ egressRules .add (new AclRule (AclRule .ETHERTYPE_IPV4 , 6 , "allow" , null , null , "1.10.10.6" , "1.10.10.7" , 80 , 80 , 80 , 80 , 1 , null , null ));
322+
323+ final List <AclRule > ingressRules = new ArrayList <>();
324+ acl .setLogicalPortIngressRules (ingressRules );
325+ ingressRules .add (new AclRule (AclRule .ETHERTYPE_IPV4 , 1 , "allow" , null , null , "1.10.10.0" , "1.10.10.1" , null , null , null , null , 0 , 0 , 5 ));
326+ ingressRules .add (new AclRule (AclRule .ETHERTYPE_IPV4 , 6 , "allow" , null , null , "1.10.10.6" , "1.10.10.7" , 80 , 80 , 80 , 80 , 1 , null , null ));
327+
328+ final List <NiciraNvpTag > tags = new ArrayList <>();
329+ acl .setTags (tags );
330+ tags .add (new NiciraNvpTag ("nvp" , "MyTag1" ));
331+ tags .add (new NiciraNvpTag ("nicira" , "MyTag2" ));
332+ // In the creation we don't get to specify UUID, href or schema: they don't exist yet
333+
334+ return acl ;
335+ }
336+
319337}
0 commit comments