2020import org .cloudfoundry .operations .applications .ApplicationHealthCheck ;
2121import org .cloudfoundry .operations .applications .PushApplicationRequest ;
2222import org .cloudfoundry .operations .domains .CreateDomainRequest ;
23+ import org .cloudfoundry .operations .domains .CreateSharedDomainRequest ;
2324import org .cloudfoundry .operations .routes .CheckRouteRequest ;
2425import org .cloudfoundry .operations .routes .CreateRouteRequest ;
2526import org .cloudfoundry .operations .routes .DeleteRouteRequest ;
2627import org .cloudfoundry .operations .routes .ListRoutesRequest ;
2728import org .cloudfoundry .operations .routes .MapRouteRequest ;
2829import org .cloudfoundry .operations .routes .Route ;
2930import org .cloudfoundry .operations .routes .UnmapRouteRequest ;
31+ import org .junit .Ignore ;
3032import org .junit .Test ;
3133import org .springframework .beans .factory .annotation .Autowired ;
3234import org .springframework .core .io .ClassPathResource ;
@@ -68,13 +70,30 @@ public void checkFalse() {
6870 .assertEquals (false ));
6971 }
7072
73+ @ Ignore ("Awaiting resolution of https://github.com/cloudfoundry/cloud_controller_ng/issues/650" )
7174 @ Test
72- public void checkTrue () {
75+ public void checkTruePrivateDomainNoHost () {
7376 String domainName = getDomainName ();
7477 String hostName = getHostName ();
7578 String path = getPath ();
7679
77- createRoute (this .cloudFoundryOperations , this .organizationName , this .spaceName , domainName , hostName , path )
80+ createDomainAndRoute (this .cloudFoundryOperations , this .organizationName , this .spaceName , domainName , hostName , path )
81+ .then (this .cloudFoundryOperations .routes ()
82+ .check (CheckRouteRequest .builder ()
83+ .domain (domainName )
84+ .path (path )
85+ .build ()))
86+ .subscribe (testSubscriber ()
87+ .assertEquals (true ));
88+ }
89+
90+ @ Test
91+ public void checkTrueSharedDomain () {
92+ String domainName = getDomainName ();
93+ String hostName = getHostName ();
94+ String path = getPath ();
95+
96+ createSharedDomainAndRoute (this .cloudFoundryOperations , this .spaceName , domainName , hostName , path )
7897 .then (this .cloudFoundryOperations .routes ()
7998 .check (CheckRouteRequest .builder ()
8099 .domain (domainName )
@@ -91,7 +110,7 @@ public void create() {
91110 String hostName = getHostName ();
92111 String path = getPath ();
93112
94- createRoute (this .cloudFoundryOperations , this .organizationName , this .spaceName , domainName , hostName , path )
113+ createDomainAndRoute (this .cloudFoundryOperations , this .organizationName , this .spaceName , domainName , hostName , path )
95114 .then (this .cloudFoundryOperations .routes ()
96115 .check (CheckRouteRequest .builder ()
97116 .domain (domainName )
@@ -125,7 +144,7 @@ public void delete() {
125144 String hostName = getHostName ();
126145 String path = getPath ();
127146
128- createRoute (this .cloudFoundryOperations , this .organizationName , this .spaceName , domainName , hostName , path )
147+ createDomainAndRoute (this .cloudFoundryOperations , this .organizationName , this .spaceName , domainName , hostName , path )
129148 .then (this .cloudFoundryOperations .routes ()
130149 .delete (DeleteRouteRequest .builder ()
131150 .domain (domainName )
@@ -164,7 +183,7 @@ public void deleteOrphanedRoutes() {
164183 String hostName = getHostName ();
165184 String path = getPath ();
166185
167- createRoute (this .cloudFoundryOperations , this .organizationName , this .spaceName , domainName , hostName , path )
186+ createDomainAndRoute (this .cloudFoundryOperations , this .organizationName , this .spaceName , domainName , hostName , path )
168187 .then (this .cloudFoundryOperations .routes ()
169188 .deleteOrphanedRoutes ())
170189 .then (this .cloudFoundryOperations .routes ()
@@ -183,7 +202,7 @@ public void listWithOrganizationLevel() {
183202 String hostName = getHostName ();
184203 String path = getPath ();
185204
186- createRoute (this .cloudFoundryOperations , this .organizationName , this .spaceName , domainName , hostName , path )
205+ createDomainAndRoute (this .cloudFoundryOperations , this .organizationName , this .spaceName , domainName , hostName , path )
187206 .thenMany (this .cloudFoundryOperations .routes ()
188207 .list (ListRoutesRequest .builder ()
189208 .level (ORGANIZATION )
@@ -199,7 +218,7 @@ public void listWithSpaceLevel() {
199218 String hostName = getHostName ();
200219 String path = getPath ();
201220
202- createRoute (this .cloudFoundryOperations , this .organizationName , this .spaceName , domainName , hostName , path )
221+ createDomainAndRoute (this .cloudFoundryOperations , this .organizationName , this .spaceName , domainName , hostName , path )
203222 .thenMany (this .cloudFoundryOperations .routes ()
204223 .list (ListRoutesRequest .builder ()
205224 .level (SPACE )
@@ -218,7 +237,7 @@ public void map() {
218237
219238 Mono
220239 .when (
221- createRoute (this .cloudFoundryOperations , this .organizationName , this .spaceName , domainName , hostName , path ),
240+ createDomainAndRoute (this .cloudFoundryOperations , this .organizationName , this .spaceName , domainName , hostName , path ),
222241 createApplication (this .cloudFoundryOperations , getApplicationBits (), applicationName , true )
223242 )
224243 .then (this .cloudFoundryOperations .routes ()
@@ -246,7 +265,7 @@ public void mapNoHost() {
246265
247266 Mono
248267 .when (
249- createRoute (this .cloudFoundryOperations , this .organizationName , this .spaceName , domainName , hostName , path ),
268+ createDomainAndRoute (this .cloudFoundryOperations , this .organizationName , this .spaceName , domainName , hostName , path ),
250269 createApplication (this .cloudFoundryOperations , getApplicationBits (), applicationName , true )
251270 )
252271 .then (this .cloudFoundryOperations .routes ()
@@ -274,7 +293,7 @@ public void mapNoPath() {
274293
275294 Mono
276295 .when (
277- createRoute (this .cloudFoundryOperations , this .organizationName , this .spaceName , domainName , hostName , path ),
296+ createDomainAndRoute (this .cloudFoundryOperations , this .organizationName , this .spaceName , domainName , hostName , path ),
278297 createApplication (this .cloudFoundryOperations , getApplicationBits (), applicationName , true )
279298 )
280299 .then (this .cloudFoundryOperations .routes ()
@@ -302,7 +321,7 @@ public void unmap() {
302321
303322 Mono
304323 .when (
305- createRoute (this .cloudFoundryOperations , this .organizationName , this .spaceName , domainName , hostName , path ),
324+ createDomainAndRoute (this .cloudFoundryOperations , this .organizationName , this .spaceName , domainName , hostName , path ),
306325 createApplication (this .cloudFoundryOperations , getApplicationBits (), applicationName , true )
307326 )
308327 .then (this .cloudFoundryOperations .routes ()
@@ -336,7 +355,7 @@ public void unmapNoPath() {
336355
337356 Mono
338357 .when (
339- createRoute (this .cloudFoundryOperations , this .organizationName , this .spaceName , domainName , hostName , path ),
358+ createDomainAndRoute (this .cloudFoundryOperations , this .organizationName , this .spaceName , domainName , hostName , path ),
340359 createApplication (this .cloudFoundryOperations , getApplicationBits (), applicationName , true )
341360 )
342361 .then (this .cloudFoundryOperations .routes ()
@@ -374,19 +393,39 @@ private static Mono<Void> createApplication(CloudFoundryOperations cloudFoundryO
374393 .build ());
375394 }
376395
377- private static Mono <Void > createRoute (CloudFoundryOperations cloudFoundryOperations , String organizationName , String spaceName , String domainName , String hostName , String path ) {
396+ private static Mono <Void > createDomain (CloudFoundryOperations cloudFoundryOperations , String organizationName , String domainName ) {
378397 return cloudFoundryOperations .domains ()
379398 .create (CreateDomainRequest .builder ()
380399 .domain (domainName )
381400 .organization (organizationName )
382- .build ())
383- .then (cloudFoundryOperations .routes ()
384- .create (CreateRouteRequest .builder ()
385- .domain (domainName )
386- .host (hostName )
387- .path (path )
388- .space (spaceName )
389- .build ()));
401+ .build ());
402+ }
403+
404+ private static Mono <Void > createSharedDomain (CloudFoundryOperations cloudFoundryOperations , String domainName ) {
405+ return cloudFoundryOperations .domains ()
406+ .createShared (CreateSharedDomainRequest .builder ()
407+ .domain (domainName )
408+ .build ());
409+ }
410+
411+ private static Mono <Void > createDomainAndRoute (CloudFoundryOperations cloudFoundryOperations , String organizationName , String spaceName , String domainName , String hostName , String path ) {
412+ return createDomain (cloudFoundryOperations , organizationName , domainName )
413+ .then (createRoute (cloudFoundryOperations , spaceName , domainName , hostName , path ));
414+ }
415+
416+ private static Mono <Void > createSharedDomainAndRoute (CloudFoundryOperations cloudFoundryOperations , String spaceName , String domainName , String hostName , String path ) {
417+ return createSharedDomain (cloudFoundryOperations , domainName )
418+ .then (createRoute (cloudFoundryOperations , spaceName , domainName , hostName , path ));
419+ }
420+
421+ private static Mono <Void > createRoute (CloudFoundryOperations cloudFoundryOperations , String spaceName , String domainName , String hostName , String path ) {
422+ return cloudFoundryOperations .routes ()
423+ .create (CreateRouteRequest .builder ()
424+ .domain (domainName )
425+ .host (hostName )
426+ .path (path )
427+ .space (spaceName )
428+ .build ());
390429 }
391430
392431 private static Predicate <Route > filterRoutes (String domainName , String host , String path , String applicationName ) {
0 commit comments