use of org.springframework.cloud.gcp.core.GcpProjectIdProvider in project spring-cloud-gcp by spring-cloud.
the class GcpDatastoreEmulatorIntegrationTests method testDatastoreEmulatorConfiguration.
@Test
public void testDatastoreEmulatorConfiguration() {
DatastoreOptions.Builder builder = DatastoreOptions.newBuilder();
new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(GcpDatastoreAutoConfiguration.class, GcpContextAutoConfiguration.class, DatastoreTransactionManagerAutoConfiguration.class, DatastoreRepositoriesAutoConfiguration.class, GcpDatastoreEmulatorAutoConfiguration.class)).withUserConfiguration(TestConfiguration.class).withPropertyValues("spring.cloud.gcp.project-id=test-project", "spring.cloud.gcp.datastore.namespace=test-namespace", "spring.cloud.gcp.datastore.emulator.port=8181", "spring.cloud.gcp.datastore.emulator.enabled=true", "spring.cloud.gcp.datastore.emulator.consistency=0.9").run((context) -> {
DatastoreTemplate datastore = context.getBean(DatastoreTemplate.class);
Datastore datastoreClient = (Datastore) ((Supplier) context.getBean(context.getBeanNamesForType(ResolvableType.forClassWithGenerics(Supplier.class, Datastore.class))[0])).get();
GcpProjectIdProvider projectIdProvider = context.getBean(GcpProjectIdProvider.class);
builder.setServiceFactory(datastoreOptions -> datastoreClient).setProjectId(projectIdProvider.getProjectId());
EmulatorEntityTest entity = new EmulatorEntityTest();
entity.setProperty("property-test");
datastore.save(entity);
assertThat(entity.getId()).isNotNull();
assertThat(datastore.findById(entity.getId(), EmulatorEntityTest.class).getProperty()).isEqualTo("property-test");
});
Datastore datastore = builder.build().getService();
EntityQuery query = Query.newEntityQueryBuilder().setKind("RandomKind").setFilter(StructuredQuery.PropertyFilter.eq("key", "value")).build();
assertThatExceptionOfType(DatastoreException.class).isThrownBy(() -> datastore.run(query));
}
use of org.springframework.cloud.gcp.core.GcpProjectIdProvider in project spring-cloud-gcp by spring-cloud.
the class StackdriverJsonLayout method start.
@Override
public void start() {
super.start();
// If no Project ID set, then attempt to resolve it with the default project ID provider
if (StringUtils.isEmpty(this.projectId) || this.projectId.endsWith("_IS_UNDEFINED")) {
GcpProjectIdProvider projectIdProvider = new DefaultGcpProjectIdProvider();
this.projectId = projectIdProvider.getProjectId();
}
}
use of org.springframework.cloud.gcp.core.GcpProjectIdProvider in project spring-cloud-gcp by spring-cloud.
the class GcpContextAutoConfigurationTests method testGetProjectIdProvider_withGcpProperties.
@Test
public void testGetProjectIdProvider_withGcpProperties() {
this.contextRunner.withPropertyValues("spring.cloud.gcp.projectId=tonberry").run((context) -> {
GcpProjectIdProvider projectIdProvider = context.getBean(GcpProjectIdProvider.class);
assertThat(projectIdProvider.getProjectId()).isEqualTo("tonberry");
});
}
use of org.springframework.cloud.gcp.core.GcpProjectIdProvider in project spring-cloud-gcp by spring-cloud.
the class GcpContextAutoConfigurationTests method testGetProjectIdProvider_withoutGcpProperties.
@Test
public void testGetProjectIdProvider_withoutGcpProperties() {
this.contextRunner.run((context) -> {
GcpProjectIdProvider projectIdProvider = context.getBean(GcpProjectIdProvider.class);
assertThat(projectIdProvider).isInstanceOf(DefaultGcpProjectIdProvider.class);
});
}
Aggregations