21 changed files with 823 additions and 0 deletions
@ -0,0 +1,31 @@
@@ -0,0 +1,31 @@
|
||||
/* |
||||
* Copyright 2012-2021 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.docs.features.testing.springbootapplications.autoconfiguredspringdatacouchbase; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.boot.test.autoconfigure.data.couchbase.DataCouchbaseTest; |
||||
|
||||
@DataCouchbaseTest |
||||
class MyDataCouchbaseTests { |
||||
|
||||
@Autowired |
||||
@SuppressWarnings("unused") |
||||
private SomeRepository repository; |
||||
|
||||
// ...
|
||||
|
||||
} |
||||
@ -0,0 +1,21 @@
@@ -0,0 +1,21 @@
|
||||
/* |
||||
* Copyright 2012-2021 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.docs.features.testing.springbootapplications.autoconfiguredspringdatacouchbase; |
||||
|
||||
interface SomeRepository { |
||||
|
||||
} |
||||
@ -0,0 +1,27 @@
@@ -0,0 +1,27 @@
|
||||
/* |
||||
* Copyright 2012-2022 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0 |
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.docs.features.testing.springbootapplications.autoconfiguredspringdatacouchbase |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired |
||||
import org.springframework.boot.test.autoconfigure.data.couchbase.DataCouchbaseTest |
||||
|
||||
@DataCouchbaseTest |
||||
class MyDataCouchbaseTests(@Autowired val repository: SomeRepository) { |
||||
|
||||
// ... |
||||
|
||||
} |
||||
@ -0,0 +1,19 @@
@@ -0,0 +1,19 @@
|
||||
/* |
||||
* Copyright 2012-2022 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0 |
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.docs.features.testing.springbootapplications.autoconfiguredspringdatacouchbase |
||||
|
||||
interface SomeRepository |
||||
@ -0,0 +1,44 @@
@@ -0,0 +1,44 @@
|
||||
/* |
||||
* Copyright 2012-2022 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.test.autoconfigure.data.couchbase; |
||||
|
||||
import java.lang.annotation.Documented; |
||||
import java.lang.annotation.ElementType; |
||||
import java.lang.annotation.Inherited; |
||||
import java.lang.annotation.Retention; |
||||
import java.lang.annotation.RetentionPolicy; |
||||
import java.lang.annotation.Target; |
||||
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration; |
||||
|
||||
/** |
||||
* {@link ImportAutoConfiguration Auto-configuration imports} for typical Data Couchbase |
||||
* tests. Most tests should consider using {@link DataCouchbaseTest @DataCouchbaseTest} |
||||
* rather than using this annotation directly. |
||||
* |
||||
* @author Eddú Meléndez |
||||
* @since 2.7.0 |
||||
* @see DataCouchbaseTest |
||||
*/ |
||||
@Target(ElementType.TYPE) |
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
@Documented |
||||
@Inherited |
||||
@ImportAutoConfiguration |
||||
public @interface AutoConfigureDataCouchbase { |
||||
|
||||
} |
||||
@ -0,0 +1,103 @@
@@ -0,0 +1,103 @@
|
||||
/* |
||||
* Copyright 2012-2022 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.test.autoconfigure.data.couchbase; |
||||
|
||||
import java.lang.annotation.Documented; |
||||
import java.lang.annotation.ElementType; |
||||
import java.lang.annotation.Inherited; |
||||
import java.lang.annotation.Retention; |
||||
import java.lang.annotation.RetentionPolicy; |
||||
import java.lang.annotation.Target; |
||||
|
||||
import org.junit.jupiter.api.extension.ExtendWith; |
||||
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration; |
||||
import org.springframework.boot.autoconfigure.SpringBootApplication; |
||||
import org.springframework.boot.test.autoconfigure.OverrideAutoConfiguration; |
||||
import org.springframework.boot.test.autoconfigure.core.AutoConfigureCache; |
||||
import org.springframework.boot.test.autoconfigure.filter.TypeExcludeFilters; |
||||
import org.springframework.context.annotation.ComponentScan.Filter; |
||||
import org.springframework.core.annotation.AliasFor; |
||||
import org.springframework.core.env.Environment; |
||||
import org.springframework.test.context.BootstrapWith; |
||||
import org.springframework.test.context.junit.jupiter.SpringExtension; |
||||
|
||||
/** |
||||
* Annotation that can be used for a Data Couchbase test that focuses |
||||
* <strong>only</strong> on Data Couchbase components. |
||||
* <p> |
||||
* Using this annotation will disable full auto-configuration and instead apply only |
||||
* configuration relevant to Data Couchbase tests. |
||||
* <p> |
||||
* When using JUnit 4, this annotation should be used in combination with |
||||
* {@code @RunWith(SpringRunner.class)}. |
||||
* |
||||
* @author Eddú Meléndez |
||||
* @since 2.7.0 |
||||
*/ |
||||
@Target(ElementType.TYPE) |
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
@Documented |
||||
@Inherited |
||||
@BootstrapWith(DataCouchbaseTestContextBootstrapper.class) |
||||
@ExtendWith(SpringExtension.class) |
||||
@OverrideAutoConfiguration(enabled = false) |
||||
@TypeExcludeFilters(DataCouchbaseTypeExcludeFilter.class) |
||||
@AutoConfigureCache |
||||
@AutoConfigureDataCouchbase |
||||
@ImportAutoConfiguration |
||||
public @interface DataCouchbaseTest { |
||||
|
||||
/** |
||||
* Properties in form {@literal key=value} that should be added to the Spring |
||||
* {@link Environment} before the test runs. |
||||
* @return the properties to add |
||||
*/ |
||||
String[] properties() default {}; |
||||
|
||||
/** |
||||
* Determines if default filtering should be used with |
||||
* {@link SpringBootApplication @SpringBootApplication}. By default no beans are |
||||
* included. |
||||
* @see #includeFilters() |
||||
* @see #excludeFilters() |
||||
* @return if default filters should be used |
||||
*/ |
||||
boolean useDefaultFilters() default true; |
||||
|
||||
/** |
||||
* A set of include filters which can be used to add otherwise filtered beans to the |
||||
* application context. |
||||
* @return include filters to apply |
||||
*/ |
||||
Filter[] includeFilters() default {}; |
||||
|
||||
/** |
||||
* A set of exclude filters which can be used to filter beans that would otherwise be |
||||
* added to the application context. |
||||
* @return exclude filters to apply |
||||
*/ |
||||
Filter[] excludeFilters() default {}; |
||||
|
||||
/** |
||||
* Auto-configuration exclusions that should be applied for this test. |
||||
* @return auto-configuration exclusions to apply |
||||
*/ |
||||
@AliasFor(annotation = ImportAutoConfiguration.class, attribute = "exclude") |
||||
Class<?>[] excludeAutoConfiguration() default {}; |
||||
|
||||
} |
||||
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
/* |
||||
* Copyright 2012-2022 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.test.autoconfigure.data.couchbase; |
||||
|
||||
import org.springframework.boot.test.context.SpringBootTestContextBootstrapper; |
||||
import org.springframework.core.annotation.MergedAnnotations; |
||||
import org.springframework.core.annotation.MergedAnnotations.SearchStrategy; |
||||
import org.springframework.test.context.TestContextBootstrapper; |
||||
|
||||
/** |
||||
* {@link TestContextBootstrapper} for {@link DataCouchbaseTest @DataCouchbaseTest} |
||||
* support. |
||||
* |
||||
* @author Eddú Meléndez |
||||
*/ |
||||
class DataCouchbaseTestContextBootstrapper extends SpringBootTestContextBootstrapper { |
||||
|
||||
@Override |
||||
protected String[] getProperties(Class<?> testClass) { |
||||
return MergedAnnotations.from(testClass, SearchStrategy.INHERITED_ANNOTATIONS).get(DataCouchbaseTest.class) |
||||
.getValue("properties", String[].class).orElse(null); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
/* |
||||
* Copyright 2012-2022 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.test.autoconfigure.data.couchbase; |
||||
|
||||
import org.springframework.boot.context.TypeExcludeFilter; |
||||
import org.springframework.boot.test.autoconfigure.filter.StandardAnnotationCustomizableTypeExcludeFilter; |
||||
|
||||
/** |
||||
* {@link TypeExcludeFilter} for {@link DataCouchbaseTest @DataCouchbaseaTest}. |
||||
* |
||||
* @author Eddú Meléndez |
||||
*/ |
||||
class DataCouchbaseTypeExcludeFilter extends StandardAnnotationCustomizableTypeExcludeFilter<DataCouchbaseTest> { |
||||
|
||||
protected DataCouchbaseTypeExcludeFilter(Class<?> testClass) { |
||||
super(testClass); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,20 @@
@@ -0,0 +1,20 @@
|
||||
/* |
||||
* Copyright 2012-2022 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
/** |
||||
* Auto-configuration for Data Couchbase tests. |
||||
*/ |
||||
package org.springframework.boot.test.autoconfigure.data.couchbase; |
||||
@ -0,0 +1,7 @@
@@ -0,0 +1,7 @@
|
||||
# AutoConfigureDataCouchbase auto-configuration imports |
||||
|
||||
org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfiguration |
||||
org.springframework.boot.autoconfigure.data.couchbase.CouchbaseDataAutoConfiguration |
||||
org.springframework.boot.autoconfigure.data.couchbase.CouchbaseReactiveDataAutoConfiguration |
||||
org.springframework.boot.autoconfigure.data.couchbase.CouchbaseReactiveRepositoriesAutoConfiguration |
||||
org.springframework.boot.autoconfigure.data.couchbase.CouchbaseRepositoriesAutoConfiguration |
||||
@ -0,0 +1,87 @@
@@ -0,0 +1,87 @@
|
||||
/* |
||||
* Copyright 2012-2022 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.test.autoconfigure.data.couchbase; |
||||
|
||||
import java.time.Duration; |
||||
|
||||
import org.junit.jupiter.api.Test; |
||||
import org.testcontainers.couchbase.BucketDefinition; |
||||
import org.testcontainers.couchbase.CouchbaseContainer; |
||||
import org.testcontainers.junit.jupiter.Container; |
||||
import org.testcontainers.junit.jupiter.Testcontainers; |
||||
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.boot.testsupport.testcontainers.DockerImageNames; |
||||
import org.springframework.context.ApplicationContext; |
||||
import org.springframework.data.couchbase.core.CouchbaseTemplate; |
||||
import org.springframework.test.context.DynamicPropertyRegistry; |
||||
import org.springframework.test.context.DynamicPropertySource; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
||||
|
||||
/** |
||||
* Integration test for {@link DataCouchbaseTest @DataCouchbaseTest}. |
||||
* |
||||
* @author Eddú Meléndez |
||||
*/ |
||||
@DataCouchbaseTest |
||||
@Testcontainers(disabledWithoutDocker = true) |
||||
class DataCouchbaseTestIntegrationTests { |
||||
|
||||
private static final String BUCKET_NAME = "cbbucket"; |
||||
|
||||
@Container |
||||
static final CouchbaseContainer couchbase = new CouchbaseContainer(DockerImageNames.couchbase()) |
||||
.withStartupAttempts(5).withStartupTimeout(Duration.ofMinutes(10)) |
||||
.withBucket(new BucketDefinition(BUCKET_NAME)); |
||||
|
||||
@DynamicPropertySource |
||||
static void couchbaseProperties(DynamicPropertyRegistry registry) { |
||||
registry.add("spring.couchbase.connection-string", couchbase::getConnectionString); |
||||
registry.add("spring.couchbase.username", couchbase::getUsername); |
||||
registry.add("spring.couchbase.password", couchbase::getPassword); |
||||
registry.add("spring.data.couchbase.bucket-name", () -> BUCKET_NAME); |
||||
} |
||||
|
||||
@Autowired |
||||
private CouchbaseTemplate couchbaseTemplate; |
||||
|
||||
@Autowired |
||||
private ExampleRepository exampleRepository; |
||||
|
||||
@Autowired |
||||
private ApplicationContext applicationContext; |
||||
|
||||
@Test |
||||
void didNotInjectExampleService() { |
||||
assertThatExceptionOfType(NoSuchBeanDefinitionException.class) |
||||
.isThrownBy(() -> this.applicationContext.getBean(ExampleService.class)); |
||||
} |
||||
|
||||
@Test |
||||
void testRepository() { |
||||
ExampleDocument document = new ExampleDocument(); |
||||
document.setText("Look, new @DataCouchbaseTest!"); |
||||
document = this.exampleRepository.save(document); |
||||
assertThat(document.getId()).isNotNull(); |
||||
assertThat(this.couchbaseTemplate.getBucketName()).isEqualTo(BUCKET_NAME); |
||||
this.exampleRepository.deleteAll(); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,43 @@
@@ -0,0 +1,43 @@
|
||||
/* |
||||
* Copyright 2012-2022 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.test.autoconfigure.data.couchbase; |
||||
|
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.core.env.Environment; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
/** |
||||
* Tests for the {@link DataCouchbaseTest#properties properties} attribute of |
||||
* {@link DataCouchbaseTest @DataCouchbaseTest}. |
||||
* |
||||
* @author Eddú Meléndez |
||||
*/ |
||||
@DataCouchbaseTest(properties = "spring.profiles.active=test") |
||||
class DataCouchbaseTestPropertiesIntegrationTests { |
||||
|
||||
@Autowired |
||||
private Environment environment; |
||||
|
||||
@Test |
||||
void environmentWithNewProfile() { |
||||
assertThat(this.environment.getActiveProfiles()).containsExactly("test"); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,76 @@
@@ -0,0 +1,76 @@
|
||||
/* |
||||
* Copyright 2012-2022 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.test.autoconfigure.data.couchbase; |
||||
|
||||
import java.time.Duration; |
||||
|
||||
import org.junit.jupiter.api.Test; |
||||
import org.testcontainers.couchbase.BucketDefinition; |
||||
import org.testcontainers.couchbase.CouchbaseContainer; |
||||
import org.testcontainers.junit.jupiter.Container; |
||||
import org.testcontainers.junit.jupiter.Testcontainers; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.boot.testsupport.testcontainers.DockerImageNames; |
||||
import org.springframework.data.couchbase.core.ReactiveCouchbaseTemplate; |
||||
import org.springframework.test.context.DynamicPropertyRegistry; |
||||
import org.springframework.test.context.DynamicPropertySource; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
/** |
||||
* Sample tests for {@link DataCouchbaseTest @DataCouchbaseTest} using reactive |
||||
* repositories. |
||||
* |
||||
* @author Eddú Meléndez |
||||
*/ |
||||
@DataCouchbaseTest |
||||
@Testcontainers(disabledWithoutDocker = true) |
||||
class DataCouchbaseTestReactiveIntegrationTests { |
||||
|
||||
private static final String BUCKET_NAME = "cbbucket"; |
||||
|
||||
@Container |
||||
static final CouchbaseContainer couchbase = new CouchbaseContainer(DockerImageNames.couchbase()) |
||||
.withStartupAttempts(5).withStartupTimeout(Duration.ofMinutes(10)) |
||||
.withBucket(new BucketDefinition(BUCKET_NAME)); |
||||
|
||||
@DynamicPropertySource |
||||
static void couchbaseProperties(DynamicPropertyRegistry registry) { |
||||
registry.add("spring.couchbase.connection-string", couchbase::getConnectionString); |
||||
registry.add("spring.couchbase.username", couchbase::getUsername); |
||||
registry.add("spring.couchbase.password", couchbase::getPassword); |
||||
registry.add("spring.data.couchbase.bucket-name", () -> BUCKET_NAME); |
||||
} |
||||
|
||||
@Autowired |
||||
private ReactiveCouchbaseTemplate couchbaseTemplate; |
||||
|
||||
@Autowired |
||||
private ExampleReactiveRepository exampleReactiveRepository; |
||||
|
||||
@Test |
||||
void testRepository() { |
||||
ExampleDocument document = new ExampleDocument(); |
||||
document.setText("Look, new @DataCouchbaseTest!"); |
||||
document = this.exampleReactiveRepository.save(document).block(Duration.ofSeconds(30)); |
||||
assertThat(document.getId()).isNotNull(); |
||||
assertThat(this.couchbaseTemplate.getBucketName()).isEqualTo(BUCKET_NAME); |
||||
this.exampleReactiveRepository.deleteAll(); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,75 @@
@@ -0,0 +1,75 @@
|
||||
/* |
||||
* Copyright 2012-2022 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.test.autoconfigure.data.couchbase; |
||||
|
||||
import java.time.Duration; |
||||
|
||||
import org.junit.jupiter.api.Test; |
||||
import org.testcontainers.couchbase.BucketDefinition; |
||||
import org.testcontainers.couchbase.CouchbaseContainer; |
||||
import org.testcontainers.junit.jupiter.Container; |
||||
import org.testcontainers.junit.jupiter.Testcontainers; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.boot.testsupport.testcontainers.DockerImageNames; |
||||
import org.springframework.context.annotation.ComponentScan.Filter; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.test.context.DynamicPropertyRegistry; |
||||
import org.springframework.test.context.DynamicPropertySource; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
/** |
||||
* Integration test with custom include filter for |
||||
* {@link DataCouchbaseTest @DataCouchbaseTest}. |
||||
* |
||||
* @author Eddú Meléndez |
||||
*/ |
||||
@DataCouchbaseTest(includeFilters = @Filter(Service.class)) |
||||
@Testcontainers(disabledWithoutDocker = true) |
||||
class DataCouchbaseTestWithIncludeFilterIntegrationTests { |
||||
|
||||
private static final String BUCKET_NAME = "cbbucket"; |
||||
|
||||
@Container |
||||
static final CouchbaseContainer couchbase = new CouchbaseContainer(DockerImageNames.couchbase()) |
||||
.withStartupAttempts(5).withStartupTimeout(Duration.ofMinutes(10)) |
||||
.withBucket(new BucketDefinition(BUCKET_NAME)); |
||||
|
||||
@DynamicPropertySource |
||||
static void couchbaseProperties(DynamicPropertyRegistry registry) { |
||||
registry.add("spring.couchbase.connection-string", couchbase::getConnectionString); |
||||
registry.add("spring.couchbase.username", couchbase::getUsername); |
||||
registry.add("spring.couchbase.password", couchbase::getPassword); |
||||
registry.add("spring.data.couchbase.bucket-name", () -> BUCKET_NAME); |
||||
} |
||||
|
||||
@Autowired |
||||
private ExampleRepository exampleRepository; |
||||
|
||||
@Autowired |
||||
private ExampleService service; |
||||
|
||||
@Test |
||||
void testService() { |
||||
ExampleDocument document = new ExampleDocument(); |
||||
document.setText("Look, new @DataCouchbaseTest!"); |
||||
document = this.exampleRepository.save(document); |
||||
assertThat(this.service.findById(document.getId())).isNotNull(); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,30 @@
@@ -0,0 +1,30 @@
|
||||
/* |
||||
* Copyright 2012-2022 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.test.autoconfigure.data.couchbase; |
||||
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication; |
||||
|
||||
/** |
||||
* Example {@link SpringBootApplication @SpringBootApplication} used with |
||||
* {@link DataCouchbaseTest @DataCouchbaseTest} tests. |
||||
* |
||||
* @author Eddú Meléndez |
||||
*/ |
||||
@SpringBootApplication |
||||
public class ExampleCouchbaseApplication { |
||||
|
||||
} |
||||
@ -0,0 +1,54 @@
@@ -0,0 +1,54 @@
|
||||
/* |
||||
* Copyright 2012-2022 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.test.autoconfigure.data.couchbase; |
||||
|
||||
import org.springframework.data.annotation.Id; |
||||
import org.springframework.data.couchbase.core.mapping.Document; |
||||
import org.springframework.data.couchbase.core.mapping.id.GeneratedValue; |
||||
import org.springframework.data.couchbase.core.mapping.id.GenerationStrategy; |
||||
|
||||
/** |
||||
* Example document used with {@link DataCouchbaseTest @DataCouchbaseTest} tests. |
||||
* |
||||
* @author Eddú Meléndez |
||||
*/ |
||||
@Document |
||||
public class ExampleDocument { |
||||
|
||||
@Id |
||||
@GeneratedValue(strategy = GenerationStrategy.UNIQUE) |
||||
private String id; |
||||
|
||||
private String text; |
||||
|
||||
public String getId() { |
||||
return this.id; |
||||
} |
||||
|
||||
public void setId(String id) { |
||||
this.id = id; |
||||
} |
||||
|
||||
public String getText() { |
||||
return this.text; |
||||
} |
||||
|
||||
public void setText(String text) { |
||||
this.text = text; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,29 @@
@@ -0,0 +1,29 @@
|
||||
/* |
||||
* Copyright 2012-2022 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.test.autoconfigure.data.couchbase; |
||||
|
||||
import org.springframework.data.couchbase.repository.ReactiveCouchbaseRepository; |
||||
|
||||
/** |
||||
* Example reactive repository used with {@link DataCouchbaseTest @DataCouchbaseTest} |
||||
* tests. |
||||
* |
||||
* @author Eddú Meléndez |
||||
*/ |
||||
interface ExampleReactiveRepository extends ReactiveCouchbaseRepository<ExampleDocument, String> { |
||||
|
||||
} |
||||
@ -0,0 +1,28 @@
@@ -0,0 +1,28 @@
|
||||
/* |
||||
* Copyright 2012-2022 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.test.autoconfigure.data.couchbase; |
||||
|
||||
import org.springframework.data.couchbase.repository.CouchbaseRepository; |
||||
|
||||
/** |
||||
* Example repository used with {@link DataCouchbaseTest @DataCouchbaseTest} tests. |
||||
* |
||||
* @author Eddú Meléndez |
||||
*/ |
||||
interface ExampleRepository extends CouchbaseRepository<ExampleDocument, String> { |
||||
|
||||
} |
||||
@ -0,0 +1,40 @@
@@ -0,0 +1,40 @@
|
||||
/* |
||||
* Copyright 2012-2022 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.test.autoconfigure.data.couchbase; |
||||
|
||||
import org.springframework.data.couchbase.core.CouchbaseTemplate; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
/** |
||||
* Example service used with {@link DataCouchbaseTest @DataCouchbaseTest} tests. |
||||
* |
||||
* @author Eddú Meléndez |
||||
*/ |
||||
@Service |
||||
public class ExampleService { |
||||
|
||||
private final CouchbaseTemplate couchbaseTemplate; |
||||
|
||||
public ExampleService(CouchbaseTemplate couchbaseTemplate) { |
||||
this.couchbaseTemplate = couchbaseTemplate; |
||||
} |
||||
|
||||
public ExampleDocument findById(String id) { |
||||
return this.couchbaseTemplate.findById(ExampleDocument.class).one(id); |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue