|
| 1 | +package org.cloudfoundry.util; |
| 2 | + |
| 3 | +import static org.cloudfoundry.util.ResourceMatchingUtilsV3.getMatchedResources; |
| 4 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 5 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 6 | +import static org.mockito.Mockito.mock; |
| 7 | +import static org.mockito.Mockito.when; |
| 8 | + |
| 9 | +import java.io.IOException; |
| 10 | +import java.nio.file.Path; |
| 11 | +import java.util.List; |
| 12 | +import org.cloudfoundry.client.CloudFoundryClient; |
| 13 | +import org.cloudfoundry.client.v3.resourcematch.ListMatchingResourcesResponse; |
| 14 | +import org.cloudfoundry.client.v3.resourcematch.MatchedResource; |
| 15 | +import org.junit.jupiter.api.Test; |
| 16 | +import org.springframework.core.io.ClassPathResource; |
| 17 | +import reactor.core.publisher.Mono; |
| 18 | + |
| 19 | +class ResourceMatchingUtilsV3Test { |
| 20 | + |
| 21 | + @Test |
| 22 | + void requestListMatchingResources2() throws IOException { |
| 23 | + CloudFoundryClient cloudFoundryClient = mock(CloudFoundryClient.class); |
| 24 | + when(cloudFoundryClient.resourceMatchV3()) |
| 25 | + .thenReturn( |
| 26 | + request -> |
| 27 | + Mono.just( |
| 28 | + ListMatchingResourcesResponse.builder() |
| 29 | + .addAllResources(request.getResources()) |
| 30 | + .build())); |
| 31 | + |
| 32 | + Path testApplication = new ClassPathResource("test-application.zip").getFile().toPath(); |
| 33 | + |
| 34 | + List<MatchedResource> result = |
| 35 | + getMatchedResources(cloudFoundryClient, testApplication).block(); |
| 36 | + assertNotNull(result); |
| 37 | + assertEquals(2, result.size()); |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + void requestListMatchingResources15001() throws IOException { |
| 42 | + CloudFoundryClient cloudFoundryClient = mock(CloudFoundryClient.class); |
| 43 | + when(cloudFoundryClient.resourceMatchV3()) |
| 44 | + .thenReturn( |
| 45 | + request -> |
| 46 | + Mono.just( |
| 47 | + ListMatchingResourcesResponse.builder() |
| 48 | + .addAllResources(request.getResources()) |
| 49 | + .build())); |
| 50 | + Path testApplication = new ClassPathResource("15001_files.zip").getFile().toPath(); |
| 51 | + |
| 52 | + List<MatchedResource> result = |
| 53 | + getMatchedResources(cloudFoundryClient, testApplication).block(); |
| 54 | + assertNotNull(result); |
| 55 | + assertEquals(15001, result.size()); |
| 56 | + } |
| 57 | +} |
0 commit comments