2323import org .cloudfoundry .client .v3 .securitygroups .BindStagingSecurityGroupRequest ;
2424import org .cloudfoundry .client .v3 .securitygroups .BindRunningSecurityGroupRequest ;
2525import org .cloudfoundry .client .v3 .securitygroups .CreateSecurityGroupRequest ;
26+ import org .cloudfoundry .client .v3 .securitygroups .CreateSecurityGroupResponse ;
2627import org .cloudfoundry .client .v3 .securitygroups .Rule ;
28+ import org .cloudfoundry .client .v3 .securitygroups .SecurityGroup ;
29+ import org .cloudfoundry .client .v3 .ToManyRelationship ;
30+ import org .cloudfoundry .client .v3 .securitygroups .Relationships ;
31+ import org .cloudfoundry .client .v3 .securitygroups .GloballyEnabled ;
32+ import org .cloudfoundry .client .v3 .securitygroups .SecurityGroup ;
2733import org .cloudfoundry .client .v3 .securitygroups .UpdateSecurityGroupRequest ;
2834import org .cloudfoundry .client .v3 .securitygroups .DeleteSecurityGroupRequest ;
2935import org .cloudfoundry .client .v3 .securitygroups .GetSecurityGroupRequest ;
36+ import org .cloudfoundry .client .v3 .securitygroups .GetSecurityGroupResponse ;
3037import org .cloudfoundry .client .v3 .securitygroups .ListSecurityGroupsRequest ;
3138import org .cloudfoundry .client .v3 .securitygroups .ListRunningSecurityGroupsRequest ;
3239import org .cloudfoundry .client .v3 .securitygroups .ListStagingSecurityGroupsRequest ;
3340import org .cloudfoundry .util .JobUtils ;
34- import org .junit .After ;
35- import org .junit .Before ;
41+
3642import org .junit .Test ;
43+ import org .junit .Before ;
3744import org .springframework .beans .factory .annotation .Autowired ;
3845import reactor .core .publisher .Mono ;
3946import reactor .test .StepVerifier ;
4047
4148import java .time .Duration ;
49+ import java .util .Arrays ;
4250
4351import static org .cloudfoundry .client .v3 .securitygroups .Protocol .TCP ;
4452
@@ -47,159 +55,198 @@ public final class SecurityGroupsTest extends AbstractIntegrationTest {
4755 @ Autowired
4856 private CloudFoundryClient cloudFoundryClient ;
4957
50- private String securityGroupName ;
51- private Mono <String > securityGroupId ;
52-
5358 @ Autowired
5459 private Mono <String > spaceId ;
60+ private Mono <CreateSecurityGroupResponse > securityGroup ;
61+ private String securityGroupName ;
5562
5663 @ Before
5764 public void settup () {
5865 this .securityGroupName = this .nameFactory .getSecurityGroupName ();
59-
60- this .cloudFoundryClient .securityGroupsV3 ()
66+ String spaceID = this . spaceId . block ();
67+ this .securityGroup = this . cloudFoundryClient .securityGroupsV3 ()
6168 .create (CreateSecurityGroupRequest .builder ()
62- .name (securityGroupName )
69+ .name (this .securityGroupName )
70+ .globallyEnabled (GloballyEnabled .builder ()
71+ .staging (true )
72+ .running (true )
73+ .build ())
6374 .rule (Rule .builder ()
6475 .destination ("0.0.0.0/0" )
6576 .log (false )
6677 .ports ("2048-3000" )
6778 .protocol (TCP )
6879 .build ())
69- .build ())
70- .doOnSuccess (response -> this .securityGroupId = Mono .just (response .getId ()))
71- .map (response -> response .getName ())
80+ .build ());
81+ }
82+
83+ @ Test
84+ public void create () {
85+ this .securityGroup
86+ .map (securityGroup -> securityGroup .getName ())
7287 .as (StepVerifier ::create )
73- .expectNext (securityGroupName )
88+ .expectNext (this . securityGroupName )
7489 .expectComplete ()
7590 .verify (Duration .ofMinutes (5 ));
7691 }
7792
78- @ After
79- public void tearDown () {
80- this .cloudFoundryClient .securityGroupsV3 ().delete (
81- DeleteSecurityGroupRequest .builder ()
82- .securityGroupId (this .securityGroupId .block ())
83- .build ())
84- .flatMap (
85- job -> JobUtils .waitForCompletion (this .cloudFoundryClient ,
86- Duration .ofMinutes (5 ), job ))
93+ @ Test
94+ public void get () {
95+ this .securityGroup
96+ .flatMap (securityGroup -> this .cloudFoundryClient .securityGroupsV3 ()
97+ .get (GetSecurityGroupRequest .builder ()
98+ .securityGroupId (securityGroup .getId ())
99+ .build ())
100+ .map (sg -> sg .getName ()))
87101 .as (StepVerifier ::create )
102+ .expectNext (this .securityGroupName )
88103 .expectComplete ()
89104 .verify (Duration .ofMinutes (5 ));
90105 }
91106
92107 @ Test
93108 public void update () {
94- this .cloudFoundryClient .securityGroupsV3 ().update (
95- UpdateSecurityGroupRequest .builder ()
96- .securityGroupId (securityGroupId .block ())
97- .rule (Rule .builder ()
98- .destination ("0.0.0.0/0" )
99- .ports ("8080" )
100- .protocol (TCP )
101- .build ())
102- .build ())
109+ String newSecurityGroupName = this .nameFactory .getSecurityGroupName ();
110+ this .securityGroup
111+ .flatMap (securityGroup -> this .cloudFoundryClient .securityGroupsV3 ().update (
112+ UpdateSecurityGroupRequest .builder ()
113+ .securityGroupId (securityGroup .getId ())
114+ .name (newSecurityGroupName )
115+ .build ()))
116+ .map (securityGroup -> securityGroup .getName ())
103117 .as (StepVerifier ::create )
118+ .expectNext (newSecurityGroupName )
104119 .expectComplete ()
105120 .verify (Duration .ofMinutes (5 ));
106-
107121 }
108122
109123 @ Test
110- public void get () {
111- this .cloudFoundryClient .securityGroupsV3 ().get (
112- GetSecurityGroupRequest .builder ()
113- .securityGroupId (securityGroupId .block ())
114- .build ())
115- .map (securityGroup -> securityGroup .getName ())
124+ public void delete () {
125+ this .securityGroup
126+ .flatMap (securityGroup -> this .cloudFoundryClient .securityGroupsV3 ().delete (
127+ DeleteSecurityGroupRequest .builder ()
128+ .securityGroupId (securityGroup .getId ())
129+ .build ())
130+ .map (id -> Arrays .asList (id )))
116131 .as (StepVerifier ::create )
117- .expectNext ( this . securityGroupName )
132+ .expectNextCount ( 1 )
118133 .expectComplete ()
119134 .verify (Duration .ofMinutes (5 ));
120-
121135 }
122136
123137 @ Test
124138 public void list () {
125- this .cloudFoundryClient .securityGroupsV3 ().list (
126- ListSecurityGroupsRequest .builder ()
127- .build ())
139+ this .securityGroup .map (
140+ securityGroup -> this .cloudFoundryClient .securityGroupsV3 ()
141+ .list (ListSecurityGroupsRequest .builder ()
142+ .names (Arrays .asList (securityGroup .getName ()))
143+ .build ()))
128144 .as (StepVerifier ::create )
145+ .expectNextCount (1 )
129146 .expectComplete ()
130147 .verify (Duration .ofMinutes (5 ));
131148 }
132149
133150 @ Test
134151 public void listRunning () {
135- this .cloudFoundryClient .securityGroupsV3 (). listRunning (
136- ListRunningSecurityGroupsRequest .builder ()
137- .spaceId (this . spaceId . block ())
138- .build ())
152+ Mono . zip ( this .securityGroup , this . spaceId ). flatMap ( v -> this . cloudFoundryClient .securityGroupsV3 ()
153+ . listRunning ( ListRunningSecurityGroupsRequest .builder ()
154+ .spaceId (v . getT2 ())
155+ .names ( Arrays . asList ( v . getT1 (). getName ())). build () ))
139156 .as (StepVerifier ::create )
157+ .expectNextCount (1 )
140158 .expectComplete ()
141159 .verify (Duration .ofMinutes (5 ));
142160 }
143161
144162 @ Test
145163 public void listStaging () {
146- this .cloudFoundryClient .securityGroupsV3 (). listStaging (
147- ListStagingSecurityGroupsRequest .builder ()
148- .spaceId (this . spaceId . block ())
149- .build ())
164+ Mono . zip ( this .securityGroup , this . spaceId ). flatMap ( v -> this . cloudFoundryClient .securityGroupsV3 ()
165+ . listStaging ( ListStagingSecurityGroupsRequest .builder ()
166+ .spaceId (v . getT2 ())
167+ .names ( Arrays . asList ( v . getT1 (). getName ())). build () ))
150168 .as (StepVerifier ::create )
169+ .expectNextCount (1 )
151170 .expectComplete ()
152171 .verify (Duration .ofMinutes (5 ));
153172 }
154173
155174 @ Test
156175 public void bindStagingSecurityGroup () {
157- this .cloudFoundryClient . securityGroupsV3 (). bindStagingSecurityGroup (
158- BindStagingSecurityGroupRequest . builder ()
159- .securityGroupId ( this . securityGroupId . block () )
160- . boundSpaces ( Relationship . builder ( )
161- .id ( this . spaceId . block () )
162- .build ())
163- .build ())
176+ Mono . zip ( this .securityGroup , this . spaceId )
177+ . flatMap ( v -> this . cloudFoundryClient . securityGroupsV3 ()
178+ .bindStagingSecurityGroup ( BindStagingSecurityGroupRequest . builder ( )
179+ . securityGroupId ( v . getT1 (). getId () )
180+ .boundSpaces ( Relationship . builder ( )
181+ . id ( v . getT2 ()) .build ())
182+ .build () ))
164183 .as (StepVerifier ::create )
184+ .expectNextCount (1 )
165185 .expectComplete ()
166186 .verify (Duration .ofMinutes (5 ));
167187 }
168188
169189 @ Test
170- public void bindRunningSecurityGroup () {
171- this .cloudFoundryClient .securityGroupsV3 ().bindRunningSecurityGroup (
172- BindRunningSecurityGroupRequest .builder ()
173- .securityGroupId (this .securityGroupId .block ())
174- .boundSpaces (Relationship .builder ()
175- .id (this .spaceId .block ())
190+ public void unbindStagingSecurityGroup () {
191+ Mono .zip (this .securityGroup , this .spaceId )
192+ .flatMap (v -> this .cloudFoundryClient .securityGroupsV3 ()
193+ .bindStagingSecurityGroup (BindStagingSecurityGroupRequest .builder ()
194+ .securityGroupId (v .getT1 ().getId ())
195+ .boundSpaces (Relationship .builder ().id (v .getT2 ())
196+ .build ())
176197 .build ())
177- .build ())
198+ .then (this .cloudFoundryClient .securityGroupsV3 ()
199+ .unbindStagingSecurityGroup (
200+ UnbindStagingSecurityGroupRequest
201+ .builder ()
202+ .securityGroupId (v
203+ .getT1 ()
204+ .getId ())
205+ .spaceId (v .getT2 ())
206+ .build ())))
207+
178208 .as (StepVerifier ::create )
209+ .expectNextCount (0 )
179210 .expectComplete ()
180211 .verify (Duration .ofMinutes (5 ));
181212 }
182213
183214 @ Test
184- public void unbindRunningSecurityGroup () {
185- this .cloudFoundryClient .securityGroupsV3 ().unbindRunningSecurityGroup (
186- UnbindRunningSecurityGroupRequest .builder ()
187- .securityGroupId (this .securityGroupId .block ())
188- .spaceId (this .spaceId .block ())
189- .build ())
215+ public void bindRunningSecurityGroup () {
216+ Mono .zip (this .securityGroup , this .spaceId )
217+ .flatMap (v -> this .cloudFoundryClient .securityGroupsV3 ()
218+ .bindRunningSecurityGroup (BindRunningSecurityGroupRequest .builder ()
219+ .securityGroupId (v .getT1 ().getId ())
220+ .boundSpaces (Relationship .builder ().id (v .getT2 ())
221+ .build ())
222+ .build ()))
190223 .as (StepVerifier ::create )
224+ .expectNextCount (1 )
191225 .expectComplete ()
192226 .verify (Duration .ofMinutes (5 ));
193227 }
194228
195229 @ Test
196- public void unbindStagingSecurityGroup () {
197- this .cloudFoundryClient .securityGroupsV3 ().unbindStagingSecurityGroup (
198- UnbindStagingSecurityGroupRequest .builder ()
199- .securityGroupId (this .securityGroupId .block ())
200- .spaceId (this .spaceId .block ())
201- .build ())
230+ public void unbindRunnungSecurityGroup () {
231+ Mono .zip (this .securityGroup , this .spaceId )
232+ .flatMap (v -> this .cloudFoundryClient .securityGroupsV3 ()
233+ .bindRunningSecurityGroup (BindRunningSecurityGroupRequest .builder ()
234+ .securityGroupId (v .getT1 ().getId ())
235+ .boundSpaces (Relationship .builder ().id (v .getT2 ())
236+ .build ())
237+ .build ())
238+ .then (this .cloudFoundryClient .securityGroupsV3 ()
239+ .unbindRunningSecurityGroup (
240+ UnbindRunningSecurityGroupRequest
241+ .builder ()
242+ .securityGroupId (v
243+ .getT1 ()
244+ .getId ())
245+ .spaceId (v .getT2 ())
246+ .build ())))
247+
202248 .as (StepVerifier ::create )
249+ .expectNextCount (0 )
203250 .expectComplete ()
204251 .verify (Duration .ofMinutes (5 ));
205252 }
0 commit comments