Skip to content

Commit dcfb098

Browse files
committed
Merge branch '812-services-routes-test' into 2.x
2 parents 2cd7a04 + dd67731 commit dcfb098

File tree

4 files changed

+564
-22
lines changed

4 files changed

+564
-22
lines changed

integration-test/src/test/java/org/cloudfoundry/RandomNameFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525

2626
final class RandomNameFactory implements NameFactory {
2727

28-
private static final int PORT_MAXIMUM = 65_535;
28+
private static final int PORT_MAXIMUM = 61_099;
2929

30-
private static final int PORT_MINIMUM = 1_024;
30+
private static final int PORT_MINIMUM = 61_001;
3131

3232
private final Random random;
3333

integration-test/src/test/java/org/cloudfoundry/client/v2/ServiceInstancesTest.java

Lines changed: 261 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,17 @@
4646
import org.cloudfoundry.client.v2.serviceplans.ServicePlanResource;
4747
import org.cloudfoundry.client.v2.services.ListServicesRequest;
4848
import org.cloudfoundry.client.v2.services.ServiceResource;
49+
import org.cloudfoundry.client.v2.shareddomains.CreateSharedDomainRequest;
50+
import org.cloudfoundry.client.v2.shareddomains.CreateSharedDomainResponse;
51+
import org.cloudfoundry.routing.RoutingClient;
52+
import org.cloudfoundry.routing.v1.routergroups.ListRouterGroupsRequest;
53+
import org.cloudfoundry.routing.v1.routergroups.ListRouterGroupsResponse;
54+
import org.cloudfoundry.routing.v1.routergroups.RouterGroup;
4955
import org.cloudfoundry.util.JobUtils;
5056
import org.cloudfoundry.util.LastOperationUtils;
5157
import org.cloudfoundry.util.PaginationUtils;
5258
import org.cloudfoundry.util.ResourceUtils;
59+
import org.junit.Ignore;
5360
import org.junit.Test;
5461
import org.springframework.beans.factory.annotation.Autowired;
5562
import reactor.core.publisher.Flux;
@@ -65,12 +72,17 @@
6572

6673
public final class ServiceInstancesTest extends AbstractIntegrationTest {
6774

75+
private static final String DEFAULT_ROUTER_GROUP = "default-tcp";
76+
6877
@Autowired
6978
private CloudFoundryClient cloudFoundryClient;
7079

7180
@Autowired
7281
private Mono<String> organizationId;
7382

83+
@Autowired
84+
private RoutingClient routingClient;
85+
7486
@Autowired
7587
private Mono<String> serviceBrokerId;
7688

@@ -90,7 +102,7 @@ public void bindRoute() {
90102
Mono.just(spaceId)
91103
)))
92104
.then(function((domainId, serviceInstanceId, spaceId) -> Mono.when(
93-
createRouteId(this.cloudFoundryClient, domainId, hostName, spaceId),
105+
createRouteId(this.cloudFoundryClient, domainId, hostName, null, spaceId),
94106
Mono.just(serviceInstanceId))
95107
))
96108
.then(function((routeId, serviceInstanceId) -> this.cloudFoundryClient.serviceInstances()
@@ -469,6 +481,216 @@ public void listFilterBySpaceId() {
469481
.verify(Duration.ofMinutes(5));
470482
}
471483

484+
@Test
485+
public void listRoutes() {
486+
String domainName = this.nameFactory.getDomainName();
487+
String hostName = this.nameFactory.getHostName();
488+
String serviceInstanceName = this.nameFactory.getServiceInstanceName();
489+
490+
Mono.when(this.organizationId, this.spaceId)
491+
.then(function((organizationId, spaceId) -> Mono.when(
492+
createPrivateDomainId(this.cloudFoundryClient, domainName, organizationId),
493+
createServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, serviceInstanceName, spaceId),
494+
Mono.just(spaceId)
495+
)))
496+
.then(function((domainId, serviceInstanceId, spaceId) -> Mono.when(
497+
createRouteId(this.cloudFoundryClient, domainId, hostName, null, spaceId),
498+
Mono.just(serviceInstanceId))
499+
))
500+
.then(function((routeId, serviceInstanceId) -> requestBindServiceInstanceRoute(this.cloudFoundryClient, routeId, serviceInstanceId)
501+
.then(Mono.just(serviceInstanceId))))
502+
.flatMapMany(serviceInstanceId -> Mono.when(
503+
Mono.just(serviceInstanceId),
504+
PaginationUtils.requestClientV2Resources(page -> this.cloudFoundryClient.serviceInstances()
505+
.listRoutes(ListServiceInstanceRoutesRequest.builder()
506+
.page(page)
507+
.serviceInstanceId(serviceInstanceId)
508+
.build()))
509+
.map(resource -> ResourceUtils.getEntity(resource).getServiceInstanceId())
510+
.single()))
511+
.as(StepVerifier::create)
512+
.consumeNextWith(tupleEquality())
513+
.expectComplete()
514+
.verify(Duration.ofMinutes(5));
515+
}
516+
517+
@Test
518+
public void listRoutesFilterByDomainId() {
519+
String domainName = this.nameFactory.getDomainName();
520+
String hostName = this.nameFactory.getHostName();
521+
String serviceInstanceName = this.nameFactory.getServiceInstanceName();
522+
523+
Mono.when(this.organizationId, this.spaceId)
524+
.then(function((organizationId, spaceId) -> Mono.when(
525+
createPrivateDomainId(this.cloudFoundryClient, domainName, organizationId),
526+
createServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, serviceInstanceName, spaceId),
527+
Mono.just(spaceId)
528+
)))
529+
.then(function((domainId, serviceInstanceId, spaceId) -> Mono.when(
530+
Mono.just(domainId),
531+
createRouteId(this.cloudFoundryClient, domainId, hostName, null, spaceId),
532+
Mono.just(serviceInstanceId))
533+
))
534+
.then(function((domainId, routeId, serviceInstanceId) -> requestBindServiceInstanceRoute(this.cloudFoundryClient, routeId, serviceInstanceId)
535+
.then(Mono.just(Tuples.of(domainId, serviceInstanceId)))))
536+
.flatMapMany(function((domainId, serviceInstanceId) -> Mono.when(
537+
Mono.just(serviceInstanceId),
538+
PaginationUtils.requestClientV2Resources(page -> this.cloudFoundryClient.serviceInstances()
539+
.listRoutes(ListServiceInstanceRoutesRequest.builder()
540+
.domainId(domainId)
541+
.page(page)
542+
.serviceInstanceId(serviceInstanceId)
543+
.build()))
544+
.map(resource -> ResourceUtils.getEntity(resource).getServiceInstanceId())
545+
.single())))
546+
.as(StepVerifier::create)
547+
.consumeNextWith(tupleEquality())
548+
.expectComplete()
549+
.verify(Duration.ofMinutes(5));
550+
}
551+
552+
@Test
553+
public void listRoutesFilterByHost() {
554+
String domainName = this.nameFactory.getDomainName();
555+
String hostName = this.nameFactory.getHostName();
556+
String serviceInstanceName = this.nameFactory.getServiceInstanceName();
557+
558+
Mono.when(this.organizationId, this.spaceId)
559+
.then(function((organizationId, spaceId) -> Mono.when(
560+
createPrivateDomainId(this.cloudFoundryClient, domainName, organizationId),
561+
createServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, serviceInstanceName, spaceId),
562+
Mono.just(spaceId)
563+
)))
564+
.then(function((domainId, serviceInstanceId, spaceId) -> Mono.when(
565+
createRouteId(this.cloudFoundryClient, domainId, hostName, null, spaceId),
566+
Mono.just(serviceInstanceId))
567+
))
568+
.then(function((routeId, serviceInstanceId) -> requestBindServiceInstanceRoute(this.cloudFoundryClient, routeId, serviceInstanceId)
569+
.then(Mono.just(serviceInstanceId))))
570+
.flatMapMany(serviceInstanceId -> Mono.when(
571+
Mono.just(serviceInstanceId),
572+
PaginationUtils.requestClientV2Resources(page -> this.cloudFoundryClient.serviceInstances()
573+
.listRoutes(ListServiceInstanceRoutesRequest.builder()
574+
.host(hostName)
575+
.page(page)
576+
.serviceInstanceId(serviceInstanceId)
577+
.build()))
578+
.map(resource -> ResourceUtils.getEntity(resource).getServiceInstanceId())
579+
.single()))
580+
.as(StepVerifier::create)
581+
.consumeNextWith(tupleEquality())
582+
.expectComplete()
583+
.verify(Duration.ofMinutes(5));
584+
}
585+
586+
//TODO: Await https://github.com/cloudfoundry/cloud_controller_ng/issues/900
587+
@Ignore("Await https://github.com/cloudfoundry/cloud_controller_ng/issues/900")
588+
@Test
589+
public void listRoutesFilterByOrganizationId() {
590+
String domainName = this.nameFactory.getDomainName();
591+
String hostName = this.nameFactory.getHostName();
592+
String serviceInstanceName = this.nameFactory.getServiceInstanceName();
593+
594+
Mono.when(this.organizationId, this.spaceId)
595+
.then(function((organizationId, spaceId) -> Mono.when(
596+
createPrivateDomainId(this.cloudFoundryClient, domainName, organizationId),
597+
Mono.just(organizationId),
598+
createServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, serviceInstanceName, spaceId),
599+
Mono.just(spaceId)
600+
)))
601+
.then(function((domainId, organizationId, serviceInstanceId, spaceId) -> Mono.when(
602+
createRouteId(this.cloudFoundryClient, domainId, hostName, null, spaceId),
603+
Mono.just(organizationId),
604+
Mono.just(serviceInstanceId))
605+
))
606+
.then(function((routeId, organizationId, serviceInstanceId) -> requestBindServiceInstanceRoute(this.cloudFoundryClient, routeId, serviceInstanceId)
607+
.then(Mono.just(Tuples.of(organizationId, serviceInstanceId)))))
608+
.flatMapMany(function((organizationId, serviceInstanceId) -> Mono.when(
609+
Mono.just(serviceInstanceId),
610+
PaginationUtils.requestClientV2Resources(page -> this.cloudFoundryClient.serviceInstances()
611+
.listRoutes(ListServiceInstanceRoutesRequest.builder()
612+
.organizationId(organizationId)
613+
.page(page)
614+
.serviceInstanceId(serviceInstanceId)
615+
.build()))
616+
.map(resource -> ResourceUtils.getEntity(resource).getServiceInstanceId())
617+
.single())))
618+
.as(StepVerifier::create)
619+
.consumeNextWith(tupleEquality())
620+
.expectComplete()
621+
.verify(Duration.ofMinutes(5));
622+
}
623+
624+
@Test
625+
public void listRoutesFilterByPath() {
626+
String domainName = this.nameFactory.getDomainName();
627+
String serviceInstanceName = this.nameFactory.getServiceInstanceName();
628+
String path = this.nameFactory.getPath();
629+
630+
Mono.when(this.organizationId, this.spaceId)
631+
.then(function((organizationId, spaceId) -> Mono.when(
632+
createPrivateDomainId(this.cloudFoundryClient, domainName, organizationId),
633+
createServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, serviceInstanceName, spaceId),
634+
Mono.just(spaceId)
635+
)))
636+
.then(function((domainId, serviceInstanceId, spaceId) -> Mono.when(
637+
createRouteId(this.cloudFoundryClient, domainId, null, path, spaceId),
638+
Mono.just(serviceInstanceId))
639+
))
640+
.then(function((routeId, serviceInstanceId) -> requestBindServiceInstanceRoute(this.cloudFoundryClient, routeId, serviceInstanceId)
641+
.then(Mono.just(serviceInstanceId))))
642+
.flatMapMany(serviceInstanceId -> Mono.when(
643+
Mono.just(serviceInstanceId),
644+
PaginationUtils.requestClientV2Resources(page -> this.cloudFoundryClient.serviceInstances()
645+
.listRoutes(ListServiceInstanceRoutesRequest.builder()
646+
.page(page)
647+
.path(path)
648+
.serviceInstanceId(serviceInstanceId)
649+
.build()))
650+
.map(resource -> ResourceUtils.getEntity(resource).getServiceInstanceId())
651+
.single()))
652+
.as(StepVerifier::create)
653+
.consumeNextWith(tupleEquality())
654+
.expectComplete()
655+
.verify(Duration.ofMinutes(5));
656+
}
657+
658+
@Test
659+
public void listRoutesFilterByPort() {
660+
String domainName = this.nameFactory.getDomainName();
661+
String hostName = this.nameFactory.getHostName();
662+
Integer port = this.nameFactory.getPort();
663+
String serviceInstanceName = this.nameFactory.getServiceInstanceName();
664+
665+
Mono.when(this.organizationId, this.spaceId)
666+
.then(function((organizationId, spaceId) -> Mono.when(
667+
getRouterGroupId(this.routingClient, DEFAULT_ROUTER_GROUP)
668+
.then(routerGroupId -> createTcpDomainId(this.cloudFoundryClient, domainName, routerGroupId)),
669+
createServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, serviceInstanceName, spaceId),
670+
Mono.just(spaceId)
671+
)))
672+
.then(function((domainId, serviceInstanceId, spaceId) -> Mono.when(
673+
createRouteId(this.cloudFoundryClient, domainId, port, spaceId),
674+
Mono.just(serviceInstanceId))
675+
))
676+
.then(function((routeId, serviceInstanceId) -> requestBindServiceInstanceRoute(this.cloudFoundryClient, routeId, serviceInstanceId)
677+
.then(Mono.just(serviceInstanceId))))
678+
.flatMapMany(serviceInstanceId -> Mono.when(
679+
Mono.just(serviceInstanceId),
680+
PaginationUtils.requestClientV2Resources(page -> this.cloudFoundryClient.serviceInstances()
681+
.listRoutes(ListServiceInstanceRoutesRequest.builder()
682+
.page(page)
683+
.port(port.toString())
684+
.serviceInstanceId(serviceInstanceId)
685+
.build()))
686+
.map(resource -> ResourceUtils.getEntity(resource).getServiceInstanceId())
687+
.single()))
688+
.as(StepVerifier::create)
689+
.consumeNextWith(tupleEquality())
690+
.expectComplete()
691+
.verify(Duration.ofMinutes(5));
692+
}
693+
472694
@Test
473695
public void listServiceBindings() {
474696
String applicationName = this.nameFactory.getApplicationName();
@@ -539,7 +761,7 @@ public void unbindRoute() {
539761
Mono.just(spaceId)
540762
)))
541763
.then(function((domainId, serviceInstanceId, spaceId) -> Mono.when(
542-
createRouteId(this.cloudFoundryClient, domainId, hostName, spaceId),
764+
createRouteId(this.cloudFoundryClient, domainId, hostName, null, spaceId),
543765
Mono.just(serviceInstanceId))
544766
))
545767
.then(function((routeId, serviceInstanceId) -> requestBindServiceInstanceRoute(this.cloudFoundryClient, routeId, serviceInstanceId)
@@ -598,7 +820,7 @@ public void updateEmptyCollections() {
598820
private static Mono<BindServiceInstanceRouteResponse> createAndBindRoute(CloudFoundryClient cloudFoundryClient, String domainName, String organizationId, String spaceId, String
599821
serviceInstanceId) {
600822
return createPrivateDomainId(cloudFoundryClient, domainName, organizationId)
601-
.then(domainId -> createRouteId(cloudFoundryClient, domainId, spaceId))
823+
.then(domainId -> createRouteId(cloudFoundryClient, domainId, null, null, spaceId))
602824
.then(routeId -> requestBindServiceInstanceRoute(cloudFoundryClient, routeId, serviceInstanceId));
603825
}
604826

@@ -612,13 +834,13 @@ private static Mono<String> createPrivateDomainId(CloudFoundryClient cloudFoundr
612834
.map(ResourceUtils::getId);
613835
}
614836

615-
private static Mono<String> createRouteId(CloudFoundryClient cloudFoundryClient, String domainId, String hostName, String spaceId) {
616-
return requestCreateRoute(cloudFoundryClient, domainId, hostName, spaceId)
837+
private static Mono<String> createRouteId(CloudFoundryClient cloudFoundryClient, String domainId, String hostName, String path, String spaceId) {
838+
return requestCreateRoute(cloudFoundryClient, domainId, hostName, path, spaceId)
617839
.map(ResourceUtils::getId);
618840
}
619841

620-
private static Mono<String> createRouteId(CloudFoundryClient cloudFoundryClient, String domainId, String spaceId) {
621-
return requestCreateRoute(cloudFoundryClient, domainId, spaceId)
842+
private static Mono<String> createRouteId(CloudFoundryClient cloudFoundryClient, String domainId, Integer port, String spaceId) {
843+
return requestCreateRoute(cloudFoundryClient, domainId, port, spaceId)
622844
.map(ResourceUtils::getId);
623845
}
624846

@@ -639,6 +861,11 @@ private static Mono<String> createServiceKeyId(CloudFoundryClient cloudFoundryCl
639861
.map(ResourceUtils::getId);
640862
}
641863

864+
private static Mono<String> createTcpDomainId(CloudFoundryClient cloudFoundryClient, String name, String routerGroupId) {
865+
return requestCreateTcpDomain(cloudFoundryClient, name, routerGroupId)
866+
.map(ResourceUtils::getId);
867+
}
868+
642869
private static Mono<String> getPlanId(CloudFoundryClient cloudFoundryClient, String serviceBrokerId) {
643870
return requestListServices(cloudFoundryClient, serviceBrokerId)
644871
.single()
@@ -648,6 +875,14 @@ private static Mono<String> getPlanId(CloudFoundryClient cloudFoundryClient, Str
648875
.map(ResourceUtils::getId);
649876
}
650877

878+
private static Mono<String> getRouterGroupId(RoutingClient routingClient, String routerGroupName) {
879+
return requestListRouterGroups(routingClient)
880+
.flatMapIterable(ListRouterGroupsResponse::getRouterGroups)
881+
.filter(group -> routerGroupName.equals(group.getName()))
882+
.single()
883+
.map(RouterGroup::getRouterGroupId);
884+
}
885+
651886
private static Mono<BindServiceInstanceRouteResponse> requestBindServiceInstanceRoute(CloudFoundryClient cloudFoundryClient, String routeId, String serviceInstanceId) {
652887
return cloudFoundryClient.serviceInstances()
653888
.bindRoute(BindServiceInstanceRouteRequest.builder()
@@ -672,19 +907,21 @@ private static Mono<CreatePrivateDomainResponse> requestCreatePrivateDomain(Clou
672907
.build());
673908
}
674909

675-
private static Mono<CreateRouteResponse> requestCreateRoute(CloudFoundryClient cloudFoundryClient, String domainId, String hostName, String spaceId) {
910+
private static Mono<CreateRouteResponse> requestCreateRoute(CloudFoundryClient cloudFoundryClient, String domainId, Integer port, String spaceId) {
676911
return cloudFoundryClient.routes()
677912
.create(CreateRouteRequest.builder()
678913
.domainId(domainId)
679-
.host(hostName)
914+
.port(port)
680915
.spaceId(spaceId)
681916
.build());
682917
}
683918

684-
private static Mono<CreateRouteResponse> requestCreateRoute(CloudFoundryClient cloudFoundryClient, String domainId, String spaceId) {
919+
private static Mono<CreateRouteResponse> requestCreateRoute(CloudFoundryClient cloudFoundryClient, String domainId, String hostName, String path, String spaceId) {
685920
return cloudFoundryClient.routes()
686921
.create(CreateRouteRequest.builder()
687922
.domainId(domainId)
923+
.host(hostName)
924+
.path(path)
688925
.spaceId(spaceId)
689926
.build());
690927
}
@@ -715,6 +952,20 @@ private static Mono<CreateServiceKeyResponse> requestCreateServiceKey(CloudFound
715952
.build());
716953
}
717954

955+
private static Mono<CreateSharedDomainResponse> requestCreateTcpDomain(CloudFoundryClient cloudFoundryClient, String name, String routerGroupId) {
956+
return cloudFoundryClient.sharedDomains()
957+
.create(CreateSharedDomainRequest.builder()
958+
.name(name)
959+
.routerGroupId(routerGroupId)
960+
.build());
961+
}
962+
963+
private static Mono<ListRouterGroupsResponse> requestListRouterGroups(RoutingClient routingClient) {
964+
return routingClient.routerGroups()
965+
.list(ListRouterGroupsRequest.builder()
966+
.build());
967+
}
968+
718969
private static Flux<RouteResource> requestListRoutes(CloudFoundryClient cloudFoundryClient, String serviceInstanceId) {
719970
return PaginationUtils
720971
.requestClientV2Resources(page -> cloudFoundryClient.serviceInstances()

0 commit comments

Comments
 (0)