1+ // Licensed to the Apache Software Foundation (ASF) under one
2+ // or more contributor license agreements. See the NOTICE file
3+ // distributed with this work for additional information
4+ // regarding copyright ownership. The ASF licenses this file
5+ // to you under the Apache License, Version 2.0 (the
6+ // "License"); you may not use this file except in compliance
7+ // with the License. You may obtain a copy of the License at
8+ //
9+ // http://www.apache.org/licenses/LICENSE-2.0
10+ //
11+ // Unless required by applicable law or agreed to in writing,
12+ // software distributed under the License is distributed on an
13+ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+ // KIND, either express or implied. See the License for the
15+ // specific language governing permissions and limitations
16+ // under the License.
17+ package org .apache .cloudstack .agent .api ;
18+
19+ import org .apache .cloudstack .resource .NetrisPortGroup ;
20+ import org .junit .Assert ;
21+ import org .junit .Test ;
22+
23+ public class CreateNetrisACLCommandTest {
24+
25+ private static final long ZONE_ID = 1L ;
26+ private static final Long ACCOUNT_ID = 2L ;
27+ private static final Long DOMAIN_ID = 3L ;
28+ private static final String NAME = "test-network" ;
29+ private static final Long ID = 4L ;
30+ private static final String VPC_NAME = "test-vpc" ;
31+ private static final Long VPC_ID = 5L ;
32+ private static final boolean IS_VPC = true ;
33+ private static final String ACTION = "allow" ;
34+ private static final String SOURCE_PREFIX = "10.0.0.0/24" ;
35+ private static final String DEST_PREFIX = "10.0.1.0/24" ;
36+ private static final Integer DEST_PORT_START = 80 ;
37+ private static final Integer DEST_PORT_END = 80 ;
38+ private static final String PROTOCOL = "tcp" ;
39+ private static final Integer ICMP_TYPE = 8 ;
40+ private static final String NETRIS_ACL_NAME = "test-acl" ;
41+ private static final String REASON = "test reason" ;
42+ private static final String PORTS = "80,443" ;
43+
44+ @ Test
45+ public void testConstructorAndGetters () {
46+ // Act
47+ CreateNetrisACLCommand command = new CreateNetrisACLCommand (
48+ ZONE_ID , ACCOUNT_ID , DOMAIN_ID , NAME , ID , VPC_NAME , VPC_ID , IS_VPC , ACTION ,
49+ SOURCE_PREFIX , DEST_PREFIX , DEST_PORT_START , DEST_PORT_END , PROTOCOL );
50+
51+ // Assert
52+ Assert .assertEquals (ZONE_ID , command .getZoneId ());
53+ Assert .assertEquals (ACCOUNT_ID , command .getAccountId ());
54+ Assert .assertEquals (DOMAIN_ID , command .getDomainId ());
55+ Assert .assertEquals (NAME , command .getName ());
56+ Assert .assertEquals (ID , command .getId ());
57+ Assert .assertEquals (IS_VPC , command .isVpc ());
58+ Assert .assertEquals (VPC_NAME , command .getVpcName ());
59+ Assert .assertEquals (VPC_ID , command .getVpcId ());
60+ Assert .assertEquals (ACTION , command .getAction ());
61+ Assert .assertEquals (SOURCE_PREFIX , command .getSourcePrefix ());
62+ Assert .assertEquals (DEST_PREFIX , command .getDestPrefix ());
63+ Assert .assertEquals (DEST_PORT_START , command .getDestPortStart ());
64+ Assert .assertEquals (DEST_PORT_END , command .getDestPortEnd ());
65+ Assert .assertEquals (PROTOCOL , command .getProtocol ());
66+ }
67+
68+ @ Test
69+ public void testConstructorWithNullValues () {
70+ // Act
71+ CreateNetrisACLCommand command = new CreateNetrisACLCommand (
72+ ZONE_ID , null , null , NAME , null , VPC_NAME , null , IS_VPC , ACTION ,
73+ SOURCE_PREFIX , DEST_PREFIX , null , null , PROTOCOL );
74+
75+ // Assert
76+ Assert .assertEquals (ZONE_ID , command .getZoneId ());
77+ Assert .assertNull (command .getAccountId ());
78+ Assert .assertNull (command .getDomainId ());
79+ Assert .assertEquals (NAME , command .getName ());
80+ Assert .assertNull (command .getId ());
81+ Assert .assertEquals (IS_VPC , command .isVpc ());
82+ Assert .assertEquals (VPC_NAME , command .getVpcName ());
83+ Assert .assertNull (command .getVpcId ());
84+ Assert .assertEquals (ACTION , command .getAction ());
85+ Assert .assertEquals (SOURCE_PREFIX , command .getSourcePrefix ());
86+ Assert .assertEquals (DEST_PREFIX , command .getDestPrefix ());
87+ Assert .assertNull (command .getDestPortStart ());
88+ Assert .assertNull (command .getDestPortEnd ());
89+ Assert .assertEquals (PROTOCOL , command .getProtocol ());
90+ }
91+
92+ @ Test
93+ public void testSetters () {
94+ // Arrange
95+ CreateNetrisACLCommand command = new CreateNetrisACLCommand (
96+ ZONE_ID , ACCOUNT_ID , DOMAIN_ID , NAME , ID , VPC_NAME , VPC_ID , IS_VPC , ACTION ,
97+ SOURCE_PREFIX , DEST_PREFIX , DEST_PORT_START , DEST_PORT_END , PROTOCOL );
98+
99+ NetrisPortGroup portGroup = new NetrisPortGroup (PORTS );
100+ String newVpcName = "new-vpc" ;
101+ Long newVpcId = 6L ;
102+
103+ // Act
104+ command .setVpcName (newVpcName );
105+ command .setVpcId (newVpcId );
106+ command .setPortGroup (portGroup );
107+ command .setIcmpType (ICMP_TYPE );
108+ command .setNetrisAclName (NETRIS_ACL_NAME );
109+ command .setReason (REASON );
110+
111+ // Assert
112+ Assert .assertEquals (newVpcName , command .getVpcName ());
113+ Assert .assertEquals (newVpcId , command .getVpcId ());
114+ Assert .assertEquals (portGroup , command .getPortGroup ());
115+ Assert .assertEquals (ICMP_TYPE , command .getIcmpType ());
116+ Assert .assertEquals (NETRIS_ACL_NAME , command .getNetrisAclName ());
117+ Assert .assertEquals (REASON , command .getReason ());
118+ Assert .assertEquals (PORTS , command .getPortGroup ().getPorts ());
119+ }
120+
121+ @ Test
122+ public void testConstructorWithEmptyStrings () {
123+ // Act
124+ CreateNetrisACLCommand command = new CreateNetrisACLCommand (
125+ ZONE_ID , ACCOUNT_ID , DOMAIN_ID , "" , ID , "" , VPC_ID , IS_VPC , "" ,
126+ "" , "" , DEST_PORT_START , DEST_PORT_END , "" );
127+
128+ // Assert
129+ Assert .assertEquals (ZONE_ID , command .getZoneId ());
130+ Assert .assertEquals (ACCOUNT_ID , command .getAccountId ());
131+ Assert .assertEquals (DOMAIN_ID , command .getDomainId ());
132+ Assert .assertEquals ("" , command .getName ());
133+ Assert .assertEquals (ID , command .getId ());
134+ Assert .assertEquals (IS_VPC , command .isVpc ());
135+ Assert .assertEquals ("" , command .getVpcName ());
136+ Assert .assertEquals (VPC_ID , command .getVpcId ());
137+ Assert .assertEquals ("" , command .getAction ());
138+ Assert .assertEquals ("" , command .getSourcePrefix ());
139+ Assert .assertEquals ("" , command .getDestPrefix ());
140+ Assert .assertEquals (DEST_PORT_START , command .getDestPortStart ());
141+ Assert .assertEquals (DEST_PORT_END , command .getDestPortEnd ());
142+ Assert .assertEquals ("" , command .getProtocol ());
143+ }
144+ }
0 commit comments