|
15 | 15 | import org.cloudfoundry.multiapps.controller.persistence.util.EnvironmentServicesFinder; |
16 | 16 | import org.cloudfoundry.multiapps.controller.web.Constants; |
17 | 17 | import org.cloudfoundry.multiapps.controller.web.Messages; |
| 18 | +import org.cloudfoundry.multiapps.controller.web.configuration.service.ImmutableObjectStoreServiceInfo; |
18 | 19 | import org.cloudfoundry.multiapps.controller.web.configuration.service.ObjectStoreServiceInfo; |
19 | 20 | import org.cloudfoundry.multiapps.controller.web.configuration.service.ObjectStoreServiceInfoCreator; |
20 | 21 | import org.jclouds.blobstore.BlobStoreContext; |
@@ -59,6 +60,9 @@ class ObjectStoreFileStorageFactoryBeanTest { |
59 | 60 | @Mock |
60 | 61 | private AzureObjectStoreFileStorage azureObjectStoreFileStorage; |
61 | 62 |
|
| 63 | + private ObjectStoreServiceInfo capturedGcpServiceInfo; |
| 64 | + private ObjectStoreServiceInfo capturedAzureServiceInfo; |
| 65 | + |
62 | 66 | @BeforeEach |
63 | 67 | void setUp() throws Exception { |
64 | 68 | MockitoAnnotations.openMocks(this) |
@@ -149,6 +153,61 @@ void testObjectStoreCreationWhenEnvIsInvalid() { |
149 | 153 | .createObjectStoreFromFirstReachableProvider(anyMap(), anyList()); |
150 | 154 | } |
151 | 155 |
|
| 156 | + @Test |
| 157 | + void testGcpFactoryReceivesPopulatedCredentialsWhenEnvIsGcp() { |
| 158 | + mockCfService(); |
| 159 | + when(applicationConfiguration.getObjectStoreClientType()).thenReturn(Constants.GCP); |
| 160 | + |
| 161 | + objectStoreFileStorageFactoryBean.afterPropertiesSet(); |
| 162 | + |
| 163 | + assertNotNull(capturedGcpServiceInfo); |
| 164 | + assertEquals(Constants.GOOGLE_CLOUD_STORAGE, capturedGcpServiceInfo.getProvider()); |
| 165 | + assertNotNull(capturedGcpServiceInfo.getCredentials(), |
| 166 | + "GCP factory must receive an ObjectStoreServiceInfo carrying the bound credentials map"); |
| 167 | + assertEquals(ACCESS_KEY_ID_VALUE, capturedGcpServiceInfo.getCredentials() |
| 168 | + .get(Constants.ACCESS_KEY_ID)); |
| 169 | + assertEquals(BUCKET_VALUE, capturedGcpServiceInfo.getCredentials() |
| 170 | + .get(Constants.BUCKET)); |
| 171 | + } |
| 172 | + |
| 173 | + @Test |
| 174 | + void testAzureFactoryReceivesPopulatedCredentialsWhenEnvIsAzure() { |
| 175 | + mockCfService(); |
| 176 | + when(applicationConfiguration.getObjectStoreClientType()).thenReturn(Constants.AZURE); |
| 177 | + |
| 178 | + objectStoreFileStorageFactoryBean.afterPropertiesSet(); |
| 179 | + |
| 180 | + assertNotNull(capturedAzureServiceInfo); |
| 181 | + assertEquals(Constants.AZUREBLOB, capturedAzureServiceInfo.getProvider()); |
| 182 | + assertNotNull(capturedAzureServiceInfo.getCredentials(), |
| 183 | + "Azure factory must receive an ObjectStoreServiceInfo carrying the bound credentials map"); |
| 184 | + assertEquals(SECRET_ACCESS_KEY_VALUE, capturedAzureServiceInfo.getCredentials() |
| 185 | + .get(Constants.SECRET_ACCESS_KEY)); |
| 186 | + } |
| 187 | + |
| 188 | + @Test |
| 189 | + void testGcpEnvWithNoMatchingProviderInfoFallsThroughToNoValidStore() { |
| 190 | + mockCfService(); |
| 191 | + when(applicationConfiguration.getObjectStoreClientType()).thenReturn(Constants.GCP); |
| 192 | + |
| 193 | + ObjectStoreFileStorageFactoryBean bean = new ObjectStoreFileStorageFactoryBean("deploy-service-os", environmentServicesFinder, |
| 194 | + applicationConfiguration) { |
| 195 | + @Override |
| 196 | + public List<ObjectStoreServiceInfo> getProvidersServiceInfo() { |
| 197 | + return List.of(ImmutableObjectStoreServiceInfo.builder() |
| 198 | + .provider(Constants.AWS_S_3) |
| 199 | + .identity(ACCESS_KEY_ID_VALUE) |
| 200 | + .credential(SECRET_ACCESS_KEY_VALUE) |
| 201 | + .container(BUCKET_VALUE) |
| 202 | + .build()); |
| 203 | + } |
| 204 | + }; |
| 205 | + |
| 206 | + Exception exception = assertThrows(IllegalStateException.class, bean::afterPropertiesSet); |
| 207 | + assertEquals(Messages.NO_VALID_OBJECT_STORE_CONFIGURATION_FOUND, exception.getMessage()); |
| 208 | + assertNull(capturedGcpServiceInfo, "GCP factory must not be invoked when no matching provider info is bound"); |
| 209 | + } |
| 210 | + |
152 | 211 | @Test |
153 | 212 | void testObjectStoreCreationWhenEnvProviderFailsToConnect() { |
154 | 213 | mockCfService(); |
@@ -203,11 +262,13 @@ protected JCloudsObjectStoreFileStorage createFileStorage(ObjectStoreServiceInfo |
203 | 262 |
|
204 | 263 | @Override |
205 | 264 | protected GcpObjectStoreFileStorage createGcpFileStorage(ObjectStoreServiceInfo credentials) { |
| 265 | + ObjectStoreFileStorageFactoryBeanTest.this.capturedGcpServiceInfo = credentials; |
206 | 266 | return ObjectStoreFileStorageFactoryBeanTest.this.gcpObjectStoreFileStorage; |
207 | 267 | } |
208 | 268 |
|
209 | 269 | @Override |
210 | 270 | protected AzureObjectStoreFileStorage createAzureFileStorage(ObjectStoreServiceInfo objectStoreServiceInfo) { |
| 271 | + ObjectStoreFileStorageFactoryBeanTest.this.capturedAzureServiceInfo = objectStoreServiceInfo; |
211 | 272 | return ObjectStoreFileStorageFactoryBeanTest.this.azureObjectStoreFileStorage; |
212 | 273 | } |
213 | 274 |
|
|
0 commit comments