Skip to content

Commit f861542

Browse files
committed
Fix Objectstore problem
1 parent bb7234a commit f861542

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

multiapps-controller-web/src/test/java/org/cloudfoundry/multiapps/controller/web/configuration/bean/factory/ObjectStoreFileStorageFactoryBeanTest.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.cloudfoundry.multiapps.controller.persistence.util.EnvironmentServicesFinder;
1616
import org.cloudfoundry.multiapps.controller.web.Constants;
1717
import org.cloudfoundry.multiapps.controller.web.Messages;
18+
import org.cloudfoundry.multiapps.controller.web.configuration.service.ImmutableObjectStoreServiceInfo;
1819
import org.cloudfoundry.multiapps.controller.web.configuration.service.ObjectStoreServiceInfo;
1920
import org.cloudfoundry.multiapps.controller.web.configuration.service.ObjectStoreServiceInfoCreator;
2021
import org.jclouds.blobstore.BlobStoreContext;
@@ -59,6 +60,9 @@ class ObjectStoreFileStorageFactoryBeanTest {
5960
@Mock
6061
private AzureObjectStoreFileStorage azureObjectStoreFileStorage;
6162

63+
private ObjectStoreServiceInfo capturedGcpServiceInfo;
64+
private ObjectStoreServiceInfo capturedAzureServiceInfo;
65+
6266
@BeforeEach
6367
void setUp() throws Exception {
6468
MockitoAnnotations.openMocks(this)
@@ -149,6 +153,61 @@ void testObjectStoreCreationWhenEnvIsInvalid() {
149153
.createObjectStoreFromFirstReachableProvider(anyMap(), anyList());
150154
}
151155

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+
152211
@Test
153212
void testObjectStoreCreationWhenEnvProviderFailsToConnect() {
154213
mockCfService();
@@ -203,11 +262,13 @@ protected JCloudsObjectStoreFileStorage createFileStorage(ObjectStoreServiceInfo
203262

204263
@Override
205264
protected GcpObjectStoreFileStorage createGcpFileStorage(ObjectStoreServiceInfo credentials) {
265+
ObjectStoreFileStorageFactoryBeanTest.this.capturedGcpServiceInfo = credentials;
206266
return ObjectStoreFileStorageFactoryBeanTest.this.gcpObjectStoreFileStorage;
207267
}
208268

209269
@Override
210270
protected AzureObjectStoreFileStorage createAzureFileStorage(ObjectStoreServiceInfo objectStoreServiceInfo) {
271+
ObjectStoreFileStorageFactoryBeanTest.this.capturedAzureServiceInfo = objectStoreServiceInfo;
211272
return ObjectStoreFileStorageFactoryBeanTest.this.azureObjectStoreFileStorage;
212273
}
213274

0 commit comments

Comments
 (0)