DATACOUCH-451 - Should be able to run integration tests and all unit tests
This change enables running the integration tests with the command:
mvn verify
Update the integration tests so they compile and pass. Rename them according
to Spring Data convention (*IntegrationTests.java) so they are executed by the
failsafe plugin instead of the surefire plugin. Move them to same folder as
unit tests according to Spring Data convention.
Update the surefire plugin configuration to include unit tests in classes
named `*Test` as well as `*Tests`. Prior to this change about half of the unit
tests were being ignored.
Integration test changes
========================
Use static factory methods for Sort and PageRequest instead of calling the
constructors which are now private.
Import EvaluationContextExtension from its new package. Remove reference to
deprecated EvaluationContextExtensionSupport.
Retry all calls to `getRepository` because otherwise they may fail due to
concurrent index creation.
Fix test `shouldDeriveViewParameters` to assume results are unordered.
Fail fast if the `server.properties` resource is missing.
Increase query and view timeouts; container is a big sluggish sometimes.
This commit is contained in:
34
pom.xml
34
pom.xml
@@ -220,6 +220,40 @@
|
||||
<groupId>org.asciidoctor</groupId>
|
||||
<artifactId>asciidoctor-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<useSystemClassLoader>false</useSystemClassLoader>
|
||||
<useFile>false</useFile>
|
||||
<includes>
|
||||
<include>**/*Test.java</include>
|
||||
<include>**/*Tests.java</include>
|
||||
</includes>
|
||||
<excludes>
|
||||
<exclude>**/*IntegrationTest.java</exclude>
|
||||
<exclude>**/*IntegrationTests.java</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<configuration>
|
||||
<includes>
|
||||
<include>**/*IntegrationTest.java</include>
|
||||
<include>**/*IntegrationTests.java</include>
|
||||
</includes>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>integration-test</goal>
|
||||
<goal>verify</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2019 Couchbase, Inc.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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.data.couchbase;
|
||||
|
||||
import org.rnorth.ducttape.unreliables.Unreliables;
|
||||
import org.springframework.data.repository.core.support.RepositoryFactorySupport;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class CouchbaseTestHelper {
|
||||
private CouchbaseTestHelper() {
|
||||
throw new AssertionError("not instantiable");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a repository instance for the given interface.
|
||||
* <p>
|
||||
* Retry because concurrent index creation throws exception.
|
||||
* See https://issues.couchbase.com/browse/MB-32238
|
||||
*/
|
||||
public static <T> T getRepositoryWithRetry(RepositoryFactorySupport factory, Class<T> repositoryInterface) {
|
||||
return retryUntilSuccess(() -> factory.getRepository(repositoryInterface));
|
||||
}
|
||||
|
||||
private static <T> T retryUntilSuccess(final Callable<T> lambda) {
|
||||
return Unreliables.retryUntilSuccess(10, TimeUnit.SECONDS, lambda);
|
||||
}
|
||||
}
|
||||
@@ -50,8 +50,8 @@ public class IntegrationTestApplicationConfig extends AbstractCouchbaseConfigura
|
||||
return DefaultCouchbaseEnvironment.builder()
|
||||
.connectTimeout(10000)
|
||||
.kvTimeout(10000)
|
||||
.queryTimeout(10000)
|
||||
.viewTimeout(10000)
|
||||
.queryTimeout(20000)
|
||||
.viewTimeout(20000)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.springframework.data.couchbase;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import org.junit.rules.ExternalResource;
|
||||
@@ -25,11 +26,11 @@ public class TestContainerResource extends ExternalResource {
|
||||
Properties properties = new Properties();
|
||||
properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("server.properties"));
|
||||
serverVersion = properties.getProperty("server.version");
|
||||
if(!properties.getProperty("server.resource").contentEquals("container")) {
|
||||
if(!"container".equals(properties.getProperty("server.resource"))) {
|
||||
return null;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
serverVersion = "5.0.1";
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
couchbaseContainer = new FixedHostPortGenericContainer("couchbase:" + serverVersion)
|
||||
.withFixedExposedPort(8091, 8091)
|
||||
@@ -64,4 +65,4 @@ public class TestContainerResource extends ExternalResource {
|
||||
currentInstance = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,6 @@ package org.springframework.data.couchbase.config;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import com.couchbase.client.java.Bucket;
|
||||
import com.couchbase.client.java.Cluster;
|
||||
import com.couchbase.client.java.CouchbaseCluster;
|
||||
@@ -35,7 +33,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
@SuppressWarnings("SpringJavaAutowiringInspection")
|
||||
@RunWith(ContainerResourceRunner.class)
|
||||
@ContextConfiguration
|
||||
public class AbstractCouchbaseDataConfigurationTest {
|
||||
public class AbstractCouchbaseDataConfigurationIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
ItemRepository repository;
|
||||
@@ -76,7 +74,7 @@ public class AbstractCouchbaseDataConfigurationTest {
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableCouchbaseRepositories(basePackageClasses = AbstractCouchbaseDataConfigurationTest.class, considerNestedRepositories = true)
|
||||
@EnableCouchbaseRepositories(basePackageClasses = AbstractCouchbaseDataConfigurationIntegrationTests.class, considerNestedRepositories = true)
|
||||
static class Config extends AbstractCouchbaseDataConfiguration {
|
||||
|
||||
@Autowired
|
||||
@@ -163,4 +161,4 @@ public class AbstractCouchbaseDataConfigurationTest {
|
||||
|
||||
@Repository
|
||||
interface ItemRepository extends CouchbaseRepository<Item, String> {}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
*/
|
||||
@RunWith(ContainerResourceRunner.class)
|
||||
@ContextConfiguration(classes = IntegrationTestNoShutdownApplicationConfig.class)
|
||||
public class CouchbaseEnvironmentNoShutdownProxyTest {
|
||||
public class CouchbaseEnvironmentNoShutdownProxyIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
public CouchbaseEnvironment environment;
|
||||
@@ -23,4 +23,4 @@ public class CouchbaseEnvironmentNoShutdownProxyTest {
|
||||
public void testEnvironmentShutDown() {
|
||||
Assert.assertEquals("Should return false", false, environment.shutdown());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,6 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import com.couchbase.client.core.env.DefaultCoreEnvironment;
|
||||
import com.couchbase.client.java.env.CouchbaseEnvironment;
|
||||
@@ -35,15 +34,15 @@ import com.couchbase.client.java.env.DefaultCouchbaseEnvironment;
|
||||
* @author Simon Bland
|
||||
*/
|
||||
public class CouchbaseSingleEnvironmentParserTest {
|
||||
|
||||
|
||||
/**
|
||||
* @see DATACOUCH-235
|
||||
* See DATACOUCH-235
|
||||
*/
|
||||
@Test
|
||||
public void testSingleCouchbaseEnvironment() throws Exception {
|
||||
|
||||
Integer instanceCounterBefore = (Integer) ReflectionTestUtils.getField(DefaultCoreEnvironment.class, "instanceCounter");
|
||||
|
||||
|
||||
int instanceCounterBefore = DefaultCoreEnvironment.instanceCounter();
|
||||
|
||||
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
|
||||
BeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
|
||||
reader.loadBeanDefinitions(new ClassPathResource("configurations/couchbaseSingleEnv-bean.xml"));
|
||||
@@ -51,9 +50,9 @@ public class CouchbaseSingleEnvironmentParserTest {
|
||||
context.refresh();
|
||||
CouchbaseEnvironment env = context.getBean("singleEnv", CouchbaseEnvironment.class);
|
||||
context.close();
|
||||
|
||||
Integer instanceCounterAfter = (Integer) ReflectionTestUtils.getField(DefaultCoreEnvironment.class, "instanceCounter");
|
||||
|
||||
|
||||
int instanceCounterAfter = DefaultCoreEnvironment.instanceCounter();
|
||||
|
||||
assertThat(env, is(instanceOf(DefaultCouchbaseEnvironment.class)));
|
||||
assertThat(instanceCounterAfter, is(instanceCounterBefore + 1));
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
* @author Simon Baslé
|
||||
*/
|
||||
@RunWith(ContainerResourceRunner.class)
|
||||
@ContextConfiguration(classes=CouchbaseTemplateParserIntegrationTests.class)
|
||||
@ContextConfiguration(classes = CouchbaseTemplateParserIntegrationTests.class)
|
||||
public class CouchbaseTemplateParserIntegrationTests {
|
||||
|
||||
DefaultListableBeanFactory factory;
|
||||
@@ -25,7 +25,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
*/
|
||||
@RunWith(ContainerResourceRunner.class)
|
||||
@ContextConfiguration(classes = IntegrationTestApplicationConfig.class)
|
||||
public class CouchbaseTemplateIdGenerationTests {
|
||||
public class CouchbaseTemplateIdGenerationIntegrationTests {
|
||||
|
||||
@Rule
|
||||
public TestName testName = new TestName();
|
||||
@@ -144,4 +144,4 @@ public class CouchbaseTemplateIdGenerationTests {
|
||||
|
||||
public String value = "new";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -69,7 +69,7 @@ import org.springframework.test.context.TestExecutionListeners;
|
||||
@RunWith(ContainerResourceRunner.class)
|
||||
@ContextConfiguration(classes = IntegrationTestApplicationConfig.class)
|
||||
@TestExecutionListeners(CouchbaseTemplateQueryListener.class)
|
||||
public class CouchbaseTemplateTests {
|
||||
public class CouchbaseTemplateIntegrationTests {
|
||||
@Rule
|
||||
public TestName testName = new TestName();
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
@RunWith(ContainerResourceRunner.class)
|
||||
@ContextConfiguration(classes = IntegrationTestCustomKeySettings.class)
|
||||
public class CouchbaseTemplateKeySettingsTests {
|
||||
public class CouchbaseTemplateKeySettingsIntegrationTests {
|
||||
|
||||
@Rule
|
||||
public TestName testName = new TestName();
|
||||
@@ -58,4 +58,4 @@ public class CouchbaseTemplateKeySettingsTests {
|
||||
@Id
|
||||
public String id = "myId";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,6 @@ import com.couchbase.client.java.view.DesignDocument;
|
||||
import com.couchbase.client.java.view.View;
|
||||
|
||||
import org.springframework.data.couchbase.config.BeanNames;
|
||||
import org.springframework.data.couchbase.repository.index.IndexedRepositoryTests;
|
||||
import org.springframework.test.context.TestContext;
|
||||
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
|
||||
|
||||
@@ -64,7 +64,7 @@ import rx.observers.TestSubscriber;
|
||||
@RunWith(ContainerResourceRunner.class)
|
||||
@ContextConfiguration(classes = ReactiveIntegrationTestApplicationConfig.class)
|
||||
@TestExecutionListeners(RxCouchbaseTemplateQueryListener.class)
|
||||
public class RxJavaCouchbaseTemplateTests {
|
||||
public class RxJavaCouchbaseTemplateIntegrationTests {
|
||||
|
||||
@Rule
|
||||
public TestName testName = new TestName();
|
||||
@@ -41,7 +41,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
*/
|
||||
@RunWith(ContainerResourceRunner.class)
|
||||
@ContextConfiguration(classes = IntegrationTestCustomTypeKeyConfig.class)
|
||||
public class TypeKeyTests {
|
||||
public class TypeKeyIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private Bucket client;
|
||||
@@ -39,12 +39,14 @@ import org.springframework.data.repository.core.support.RepositoryFactorySupport
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.springframework.data.couchbase.CouchbaseTestHelper.getRepositoryWithRetry;
|
||||
|
||||
/**
|
||||
* @author Subhashni Balakrishnan
|
||||
*/
|
||||
@RunWith(ContainerResourceRunner.class)
|
||||
@ContextConfiguration(classes = IntegrationTestApplicationConfig.class)
|
||||
public class CustomConverterTests {
|
||||
public class CustomConverterIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private MappingCouchbaseConverter converter;
|
||||
@@ -83,7 +85,7 @@ public class CustomConverterTests {
|
||||
converter.setCustomConversions(new CouchbaseCustomConversions(Arrays.asList(UUIDToStringConverter.INSTANCE, StringToUUIDConverter.INSTANCE)));
|
||||
converter.afterPropertiesSet();
|
||||
RepositoryFactorySupport factory = new CouchbaseRepositoryFactory(operationsMapping, indexManager);
|
||||
repository = factory.getRepository(TestUUIDRepository.class);
|
||||
repository = getRepositoryWithRetry(factory, TestUUIDRepository.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -34,7 +34,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
*/
|
||||
@RunWith(ContainerResourceRunner.class)
|
||||
@ContextConfiguration(classes = IntegrationTestApplicationConfig.class)
|
||||
public class ClientInfoTests {
|
||||
public class ClientInfoIntegrationTests {
|
||||
|
||||
/**
|
||||
* Contains a reference to the actual CouchbaseClient.
|
||||
@@ -40,7 +40,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@Ignore(value = "Cant run get cluster info on test container")
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = IntegrationTestApplicationConfig.class)
|
||||
public class ClusterInfoTests {
|
||||
public class ClusterInfoIntegrationTests {
|
||||
|
||||
/**
|
||||
* Contains a reference to the actual CouchbaseClient.
|
||||
@@ -40,7 +40,7 @@ import static org.springframework.data.couchbase.core.mapping.id.GenerationStrat
|
||||
*/
|
||||
@RunWith(ContainerResourceRunner.class)
|
||||
@ContextConfiguration(classes = IntegrationTestApplicationConfig.class)
|
||||
public class CouchbaseIdGenerationTests {
|
||||
public class CouchbaseIdGenerationIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private RepositoryOperationsMapping operationsMapping;
|
||||
@@ -22,19 +22,23 @@ import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.couchbase.client.java.Bucket;
|
||||
import com.couchbase.client.java.document.json.JsonObject;
|
||||
import com.couchbase.client.java.view.Stale;
|
||||
import com.couchbase.client.java.view.ViewQuery;
|
||||
import com.couchbase.client.java.view.ViewResult;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.InvalidDataAccessResourceUsageException;
|
||||
import org.springframework.data.couchbase.ContainerResourceRunner;
|
||||
import org.springframework.data.couchbase.IntegrationTestApplicationConfig;
|
||||
import org.springframework.data.couchbase.repository.config.RepositoryOperationsMapping;
|
||||
import org.springframework.data.couchbase.repository.support.CouchbaseRepositoryFactory;
|
||||
@@ -42,16 +46,15 @@ import org.springframework.data.couchbase.repository.support.IndexManager;
|
||||
import org.springframework.data.mapping.PropertyReferenceException;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestExecutionListeners;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author David Harrigan
|
||||
* @author Simon Baslé
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@RunWith(ContainerResourceRunner.class)
|
||||
@ContextConfiguration(classes = IntegrationTestApplicationConfig.class)
|
||||
@TestExecutionListeners(CouchbaseRepositoryViewListener.class)
|
||||
public class CouchbaseRepositoryViewTests {
|
||||
public class CouchbaseRepositoryViewIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private Bucket client;
|
||||
@@ -73,11 +76,7 @@ public class CouchbaseRepositoryViewTests {
|
||||
public void shouldFindAllWithCustomView() {
|
||||
client.query(ViewQuery.from("user", "customFindAllView").stale(Stale.FALSE));
|
||||
Iterable<User> allUsers = repository.findAll();
|
||||
int i = 0;
|
||||
for (final User allUser : allUsers) {
|
||||
i++;
|
||||
}
|
||||
assertThat(i, is(100));
|
||||
assertThat(allUsers, Matchers.iterableWithSize(100));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -138,27 +137,21 @@ public class CouchbaseRepositoryViewTests {
|
||||
User u2 = repository.findByUsernameIs(middleKey).get(0);
|
||||
User u3 = repository.findByUsernameIs(highKey).get(0);
|
||||
|
||||
assertEquals(lowKey, u1.getUsername());
|
||||
assertEquals(middleKey, u2.getUsername());
|
||||
assertEquals(highKey, u3.getUsername());
|
||||
|
||||
List<User> in = repository.findAllByUsernameIn(keys);
|
||||
List<User> gteLte = repository.findByUsernameGreaterThanEqualAndUsernameLessThanEqual(lowKey, highKey);
|
||||
List<User> between = repository.findByUsernameBetween(lowKey, highKey);
|
||||
List<User> gteLimited = repository.findTop3ByUsernameGreaterThanEqual(lowKey);
|
||||
|
||||
assertNotNull(u1);
|
||||
assertNotNull(u2);
|
||||
assertNotNull(u3);
|
||||
|
||||
assertEquals(lowKey, u1.getUsername());
|
||||
assertEquals(middleKey, u2.getUsername());
|
||||
assertEquals(highKey, u3.getUsername());
|
||||
|
||||
List<User> expected = Arrays.asList(u1, u2, u3);
|
||||
assertEquals(expected, in);
|
||||
assertEquals(expected, gteLte);
|
||||
assertEquals(expected, between);
|
||||
assertTrue(gteLimited.contains(u1));
|
||||
assertTrue(gteLimited.contains(u2));
|
||||
assertTrue(gteLimited.contains(u3));
|
||||
// the results are unordered, so compare using Set
|
||||
Set<User> expected = new HashSet<>(Arrays.asList(u1, u2, u3));
|
||||
assertEquals(expected, new HashSet<>(in));
|
||||
assertEquals(expected, new HashSet<>(gteLte));
|
||||
assertEquals(expected, new HashSet<>(between));
|
||||
assertEquals(expected, new HashSet<>(gteLimited));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.springframework.data.couchbase.repository;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.data.couchbase.CouchbaseTestHelper.getRepositoryWithRetry;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -34,7 +35,7 @@ import org.springframework.test.context.TestExecutionListeners;
|
||||
@RunWith(ContainerResourceRunner.class)
|
||||
@ContextConfiguration(classes = IntegrationTestApplicationConfig.class)
|
||||
@TestExecutionListeners(PartyPopulatorListener.class)
|
||||
public class DimensionalQueryTests {
|
||||
public class DimensionalQueryIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private RepositoryOperationsMapping templateMapping;
|
||||
@@ -47,7 +48,7 @@ public class DimensionalQueryTests {
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
RepositoryFactorySupport factory = new CouchbaseRepositoryFactory(templateMapping, indexManager);
|
||||
repository = factory.getRepository(DimensionalPartyRepository.class);
|
||||
repository = getRepositoryWithRetry(factory, DimensionalPartyRepository.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.data.couchbase.repository;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.data.couchbase.CouchbaseTestHelper.getRepositoryWithRetry;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -43,6 +44,7 @@ import org.springframework.test.context.TestExecutionListeners;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* This tests PaginAndSortingRepository features in the Couchbase connector.
|
||||
@@ -53,7 +55,7 @@ import java.util.List;
|
||||
@RunWith(ContainerResourceRunner.class)
|
||||
@ContextConfiguration(classes = IntegrationTestApplicationConfig.class)
|
||||
@TestExecutionListeners(PartyPopulatorListener.class)
|
||||
public class N1qlCouchbaseRepositoryTests {
|
||||
public class N1qlCouchbaseRepositoryIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private RepositoryOperationsMapping operationsMapping;
|
||||
@@ -74,9 +76,10 @@ public class N1qlCouchbaseRepositoryTests {
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
RepositoryFactorySupport factory = new CouchbaseRepositoryFactory(operationsMapping, indexManager);
|
||||
repository = factory.getRepository(PartyPagingRepository.class);
|
||||
partyRepository = factory.getRepository(PartyRepository.class);
|
||||
itemRepository = factory.getRepository(ItemRepository.class);
|
||||
repository = getRepositoryWithRetry(factory, PartyPagingRepository.class);
|
||||
partyRepository = getRepositoryWithRetry(factory, PartyRepository.class);
|
||||
itemRepository = getRepositoryWithRetry(factory, ItemRepository.class);
|
||||
|
||||
partyRepository.save(new Party(KEY_PARTY, "partyName", "MatchingDescription", null, 1, null));
|
||||
itemRepository.save(new Item(KEY_ITEM, "MatchingDescription"));
|
||||
}
|
||||
@@ -89,7 +92,7 @@ public class N1qlCouchbaseRepositoryTests {
|
||||
|
||||
@Test
|
||||
public void shouldFindAllWithSort() {
|
||||
Iterable<Party> allByAttendanceDesc = repository.findAll(new Sort(Sort.Direction.DESC, "attendees"));
|
||||
Iterable<Party> allByAttendanceDesc = repository.findAll(Sort.by(Sort.Direction.DESC, "attendees"));
|
||||
long previousAttendance = Long.MAX_VALUE;
|
||||
for (Party party : allByAttendanceDesc) {
|
||||
assertTrue(party.getAttendees() <= previousAttendance);
|
||||
@@ -100,7 +103,7 @@ public class N1qlCouchbaseRepositoryTests {
|
||||
|
||||
@Test
|
||||
public void shouldSortOnRenamedFieldIfJsonNameIsProvidedInSort() {
|
||||
Iterable<Party> parties = repository.findAll(new Sort(Sort.Direction.DESC, "desc"));
|
||||
Iterable<Party> parties = repository.findAll(Sort.by(Sort.Direction.DESC, "desc"));
|
||||
String previousDesc = null;
|
||||
for (Party party : parties) {
|
||||
if (previousDesc != null) {
|
||||
@@ -113,7 +116,7 @@ public class N1qlCouchbaseRepositoryTests {
|
||||
|
||||
@Test
|
||||
public void shouldSortWithoutCaseSensitivity() {
|
||||
Iterable<Party> parties = repository.findAll(new Sort(new Sort.Order(Sort.Direction.DESC, "desc").ignoreCase()));
|
||||
Iterable<Party> parties = repository.findAll(Sort.by(new Sort.Order(Sort.Direction.DESC, "desc").ignoreCase()));
|
||||
String previousDesc = null;
|
||||
for (Party party : parties) {
|
||||
if (previousDesc != null) {
|
||||
@@ -126,7 +129,7 @@ public class N1qlCouchbaseRepositoryTests {
|
||||
|
||||
@Test
|
||||
public void shouldPageThroughEntities() {
|
||||
Pageable pageable = new PageRequest(0, 8);
|
||||
Pageable pageable = PageRequest.of(0, 8);
|
||||
|
||||
Page<Party> page1 = repository.findAll(pageable);
|
||||
assertTrue("Query for parties should be atleast 12", page1.getTotalElements() >= 12);
|
||||
@@ -135,7 +138,7 @@ public class N1qlCouchbaseRepositoryTests {
|
||||
|
||||
@Test
|
||||
public void shouldPageThroughSortedEntities() {
|
||||
Pageable pageable = new PageRequest(0, 8, Sort.Direction.DESC, "attendees");
|
||||
Pageable pageable = PageRequest.of(0, 8, Sort.Direction.DESC, "attendees");
|
||||
|
||||
Page<Party> page1 = repository.findAll(pageable);
|
||||
assertTrue("Query for parties should be atleast 12", page1.getTotalElements() >= 12);
|
||||
@@ -159,7 +162,7 @@ public class N1qlCouchbaseRepositoryTests {
|
||||
|
||||
@Test
|
||||
public void shouldPageWithStringBasedQuery() {
|
||||
Pageable pageable = new PageRequest(0, 8, Sort.Direction.DESC, "attendees");
|
||||
Pageable pageable = PageRequest.of(0, 8, Sort.Direction.DESC, "attendees");
|
||||
Page<Party> page1 = partyRepository.findPartiesWithAttendee(1, pageable);
|
||||
assertTrue("Query for parties with attendees should be atleast 12", page1.getTotalElements() >= 12);
|
||||
assertEquals(8, page1.getNumberOfElements());
|
||||
@@ -186,7 +189,7 @@ public class N1qlCouchbaseRepositoryTests {
|
||||
//Fails on deserialization as a different entity item is also present
|
||||
@Test(expected = MappingInstantiationException.class)
|
||||
public void shouldFailWithMissingFilterStringBasedQuery() {
|
||||
Sort sort = new Sort(Sort.Direction.DESC, "attendees");
|
||||
Sort sort = Sort.by(Sort.Direction.DESC, "attendees");
|
||||
partyRepository.findParties(sort);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.data.couchbase.repository;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.data.couchbase.CouchbaseTestHelper.getRepositoryWithRetry;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@@ -44,7 +45,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
*/
|
||||
@RunWith(ContainerResourceRunner.class)
|
||||
@ContextConfiguration(classes = IntegrationTestApplicationConfig.class)
|
||||
public class N1qlCrudRepositoryTests {
|
||||
public class N1qlCrudRepositoryIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private Bucket client;
|
||||
@@ -67,8 +68,10 @@ public class N1qlCrudRepositoryTests {
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
partyRepository = new CouchbaseRepositoryFactory(operationsMapping, indexManager).getRepository(PartyRepository.class);
|
||||
itemRepository = new CouchbaseRepositoryFactory(operationsMapping, indexManager).getRepository(ItemRepository.class);
|
||||
CouchbaseRepositoryFactory factory = new CouchbaseRepositoryFactory(operationsMapping, indexManager);
|
||||
|
||||
partyRepository = getRepositoryWithRetry(factory, PartyRepository.class);
|
||||
itemRepository = getRepositoryWithRetry(factory, ItemRepository.class);
|
||||
|
||||
itemRepository.save(item);
|
||||
partyRepository.save(party);
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.data.couchbase.repository;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.data.couchbase.CouchbaseTestHelper.getRepositoryWithRetry;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -42,7 +43,7 @@ import org.springframework.test.context.TestExecutionListeners;
|
||||
@RunWith(ContainerResourceRunner.class)
|
||||
@ContextConfiguration(classes = IntegrationTestApplicationConfig.class)
|
||||
@TestExecutionListeners(PartyPopulatorListener.class)
|
||||
public class N1qlPlaceholderTests {
|
||||
public class N1qlPlaceholderIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private RepositoryOperationsMapping operationsMapping;
|
||||
@@ -56,7 +57,7 @@ public class N1qlPlaceholderTests {
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
factory = new CouchbaseRepositoryFactory(operationsMapping, indexManager);
|
||||
partyRepository = factory.getRepository(PartyRepository.class);
|
||||
partyRepository = getRepositoryWithRetry(factory, PartyRepository.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -3,6 +3,7 @@ package org.springframework.data.couchbase.repository;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.data.couchbase.CouchbaseTestHelper.getRepositoryWithRetry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -28,7 +29,7 @@ import org.springframework.test.context.TestExecutionListeners;
|
||||
@RunWith(ContainerResourceRunner.class)
|
||||
@ContextConfiguration(classes = IntegrationTestApplicationConfig.class)
|
||||
@TestExecutionListeners(SimpleCouchbaseRepositoryListener.class)
|
||||
public class PageAndSliceTests {
|
||||
public class PageAndSliceIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private Bucket client;
|
||||
@@ -44,11 +45,11 @@ public class PageAndSliceTests {
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
RepositoryFactorySupport factory = new CouchbaseRepositoryFactory(operationsMapping, indexManager);
|
||||
repository = factory.getRepository(UserRepository.class);
|
||||
repository = getRepositoryWithRetry(factory, UserRepository.class);
|
||||
}
|
||||
@Test
|
||||
public void shouldPageThroughResults() {
|
||||
Page<User> page1 = repository.findByAgeGreaterThan(9, new PageRequest(0, 40)); //there are 90 matching users
|
||||
Page<User> page1 = repository.findByAgeGreaterThan(9, PageRequest.of(0, 40)); //there are 90 matching users
|
||||
Page<User> page2 = repository.findByAgeGreaterThan(9, page1.nextPageable());
|
||||
Page<User> page3 = repository.findByAgeGreaterThan(9, page2.nextPageable());
|
||||
|
||||
@@ -76,7 +77,7 @@ public class PageAndSliceTests {
|
||||
public void shouldSliceThroughResults() {
|
||||
int count = 0;
|
||||
List<User> allMatching = new ArrayList<User>(10);
|
||||
Slice<User> slice = repository.findByAgeLessThan(9, new PageRequest(0, 3)); //9 matching users (ages 0-8)
|
||||
Slice<User> slice = repository.findByAgeLessThan(9, PageRequest.of(0, 3)); //9 matching users (ages 0-8)
|
||||
allMatching.addAll(slice.getContent());
|
||||
while(slice.hasNext()) {
|
||||
slice = repository.findByAgeLessThan(9, slice.nextPageable());
|
||||
@@ -32,7 +32,7 @@ import org.springframework.test.context.TestExecutionListeners;
|
||||
@RunWith(ContainerResourceRunner.class)
|
||||
@ContextConfiguration(classes = IntegrationTestApplicationConfig.class)
|
||||
@TestExecutionListeners(PartyPopulatorListener.class)
|
||||
public class QueryDerivationConversionTests {
|
||||
public class QueryDerivationConversionIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private Bucket client;
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.data.couchbase.repository;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.data.couchbase.CouchbaseTestHelper.getRepositoryWithRetry;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
@@ -47,7 +48,7 @@ import org.springframework.test.context.TestExecutionListeners;
|
||||
@RunWith(ContainerResourceRunner.class)
|
||||
@ContextConfiguration(classes = ReactiveIntegrationTestApplicationConfig.class)
|
||||
@TestExecutionListeners(PartyPopulatorListener.class)
|
||||
public class ReactiveN1qlCouchbaseRepositoryTests {
|
||||
public class ReactiveN1qlCouchbaseRepositoryIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private ReactiveRepositoryOperationsMapping operationsMapping;
|
||||
@@ -68,9 +69,9 @@ public class ReactiveN1qlCouchbaseRepositoryTests {
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
ReactiveRepositoryFactorySupport factory = new ReactiveCouchbaseRepositoryFactory(operationsMapping, indexManager);
|
||||
repository = factory.getRepository(ReactivePartySortingRepository.class);
|
||||
partyRepository = factory.getRepository(ReactivePartyRepository.class);
|
||||
itemRepository = factory.getRepository(ItemRepository.class);
|
||||
repository = getRepositoryWithRetry(factory, ReactivePartySortingRepository.class);
|
||||
partyRepository = getRepositoryWithRetry(factory, ReactivePartyRepository.class);
|
||||
itemRepository = getRepositoryWithRetry(factory, ItemRepository.class);
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -81,7 +82,7 @@ public class ReactiveN1qlCouchbaseRepositoryTests {
|
||||
|
||||
@Test
|
||||
public void shouldFindAllWithSort() {
|
||||
Iterable<Party> allByAttendanceDesc = repository.findAll(new Sort(Sort.Direction.DESC, "attendees")).collectList().block();
|
||||
Iterable<Party> allByAttendanceDesc = repository.findAll(Sort.by(Sort.Direction.DESC, "attendees")).collectList().block();
|
||||
long previousAttendance = Long.MAX_VALUE;
|
||||
for (Party party : allByAttendanceDesc) {
|
||||
assertTrue(party.getAttendees() <= previousAttendance);
|
||||
@@ -92,7 +93,7 @@ public class ReactiveN1qlCouchbaseRepositoryTests {
|
||||
|
||||
@Test
|
||||
public void shouldSortOnRenamedFieldIfJsonNameIsProvidedInSort() {
|
||||
Iterable<Party> parties = repository.findAll(new Sort(Sort.Direction.DESC, "desc")).collectList().block();
|
||||
Iterable<Party> parties = repository.findAll(Sort.by(Sort.Direction.DESC, "desc")).collectList().block();
|
||||
String previousDesc = null;
|
||||
for (Party party : parties) {
|
||||
if (previousDesc != null) {
|
||||
@@ -105,7 +106,7 @@ public class ReactiveN1qlCouchbaseRepositoryTests {
|
||||
|
||||
@Test
|
||||
public void shouldSortWithoutCaseSensitivity() {
|
||||
Iterable<Party> parties = repository.findAll(new Sort(new Sort.Order(Sort.Direction.DESC, "desc").ignoreCase())).collectList().block();
|
||||
Iterable<Party> parties = repository.findAll(Sort.by(new Sort.Order(Sort.Direction.DESC, "desc").ignoreCase())).collectList().block();
|
||||
String previousDesc = null;
|
||||
for(Party party : parties) {
|
||||
if (previousDesc != null) {
|
||||
@@ -55,6 +55,8 @@ public class RepositoryIndexUsageTest {
|
||||
|
||||
CouchbaseConverter mockConverter = mock(CouchbaseConverter.class);
|
||||
when(mockConverter.getTypeKey()).thenReturn("mockType");
|
||||
when(mockConverter.convertForWriteIfNeeded(any(Object.class))).thenAnswer(
|
||||
invocation -> invocation.getArgument(0));
|
||||
|
||||
couchbaseOperations = mock(CouchbaseOperations.class);
|
||||
when(couchbaseOperations.getDefaultConsistency()).thenReturn(CONSISTENCY);
|
||||
@@ -184,4 +186,4 @@ public class RepositoryIndexUsageTest {
|
||||
verify(couchbaseOperations).remove("id1");
|
||||
verify(couchbaseOperations).remove("id2");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.data.couchbase.repository;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.data.couchbase.CouchbaseTestHelper.getRepositoryWithRetry;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -60,7 +61,7 @@ import com.couchbase.client.java.view.ViewQuery;
|
||||
@RunWith(ContainerResourceRunner.class)
|
||||
@ContextConfiguration(classes = IntegrationTestApplicationConfig.class)
|
||||
@TestExecutionListeners(SimpleCouchbaseRepositoryListener.class)
|
||||
public class SimpleCouchbaseRepositoryTests {
|
||||
public class SimpleCouchbaseRepositoryIntegrationTests {
|
||||
|
||||
@Rule
|
||||
public TestName testName = new TestName();
|
||||
@@ -80,8 +81,8 @@ public class SimpleCouchbaseRepositoryTests {
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
RepositoryFactorySupport factory = new CouchbaseRepositoryFactory(operationsMapping, indexManager);
|
||||
repository = factory.getRepository(UserRepository.class);
|
||||
versionedDataRepository = factory.getRepository(VersionedDataRepository.class);
|
||||
repository = getRepositoryWithRetry(factory, UserRepository.class);
|
||||
versionedDataRepository = getRepositoryWithRetry(factory, VersionedDataRepository.class);
|
||||
}
|
||||
|
||||
private void remove(String key) {
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.data.couchbase.repository;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.data.couchbase.CouchbaseTestHelper.getRepositoryWithRetry;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -47,7 +48,7 @@ import com.couchbase.client.java.view.ViewQuery;
|
||||
@RunWith(ContainerResourceRunner.class)
|
||||
@ContextConfiguration(classes = ReactiveIntegrationTestApplicationConfig.class)
|
||||
@TestExecutionListeners(SimpleReactiveCouchbaseRepositoryListener.class)
|
||||
public class SimpleReactiveCouchbaseRepositoryTests {
|
||||
public class SimpleReactiveCouchbaseRepositoryIntegrationTests {
|
||||
|
||||
@Rule
|
||||
public TestName testName = new TestName();
|
||||
@@ -66,7 +67,7 @@ public class SimpleReactiveCouchbaseRepositoryTests {
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
ReactiveRepositoryFactorySupport factory = new ReactiveCouchbaseRepositoryFactory(operationsMapping, indexManager);
|
||||
repository = factory.getRepository(ReactiveUserRepository.class);
|
||||
repository = getRepositoryWithRetry(factory, ReactiveUserRepository.class);
|
||||
}
|
||||
|
||||
private void remove(String key) {
|
||||
@@ -23,7 +23,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
*/
|
||||
@RunWith(ContainerResourceRunner.class)
|
||||
@ContextConfiguration(classes = AuditedApplicationConfig.class)
|
||||
public class AuditingTests {
|
||||
public class AuditingIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private AuditedRepository repository;
|
||||
@@ -42,8 +42,8 @@ import javax.enterprise.inject.se.SeContainerInitializer;
|
||||
*/
|
||||
@SuppressWarnings("SpringJavaAutowiringInspection")
|
||||
@RunWith(ContainerResourceRunner.class)
|
||||
@ContextConfiguration(classes = CdiRepositoryTests.class)
|
||||
public class CdiRepositoryTests {
|
||||
@ContextConfiguration(classes = CdiRepositoryIntegrationTests.class)
|
||||
public class CdiRepositoryIntegrationTests {
|
||||
|
||||
private static SeContainer cdiContainer;
|
||||
private CdiPersonRepository repository;
|
||||
@@ -53,7 +53,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
@SuppressWarnings("SpringJavaAutowiringInspection")
|
||||
@RunWith(ContainerResourceRunner.class)
|
||||
@ContextConfiguration
|
||||
public class RepositoryBaseTest {
|
||||
public class RepositoryBaseIntegrationTests {
|
||||
|
||||
private static CouchbaseOperations mockOpsA;
|
||||
|
||||
@@ -40,7 +40,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@SuppressWarnings("SpringJavaAutowiringInspection")
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class RepositoryCustomMethodTest {
|
||||
public class RepositoryCustomMethodIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
MyRepository repository;
|
||||
@@ -19,6 +19,7 @@ package org.springframework.data.couchbase.repository.feature;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.springframework.data.couchbase.CouchbaseTestHelper.getRepositoryWithRetry;
|
||||
|
||||
import com.couchbase.client.java.cluster.ClusterInfo;
|
||||
import com.couchbase.client.java.query.N1qlQuery;
|
||||
@@ -49,7 +50,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
*/
|
||||
@RunWith(ContainerResourceRunner.class)
|
||||
@ContextConfiguration(classes = FeatureDetectionTestApplicationConfig.class)
|
||||
public class FeatureDetectionRepositoryTests {
|
||||
public class FeatureDetectionRepositoryIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private RepositoryOperationsMapping operationsMapping;
|
||||
@@ -79,7 +80,7 @@ public class FeatureDetectionRepositoryTests {
|
||||
@Test
|
||||
public void testN1qlIncompatibleClusterDoesntFailForViewBasedRepository() throws Exception {
|
||||
RepositoryFactorySupport factory = new CouchbaseRepositoryFactory(operationsMapping, indexManager);
|
||||
ViewOnlyUserRepository repository = factory.getRepository(ViewOnlyUserRepository.class);
|
||||
ViewOnlyUserRepository repository = getRepositoryWithRetry(factory, ViewOnlyUserRepository.class);
|
||||
assertNotNull(repository);
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ import org.springframework.data.couchbase.core.query.ViewIndexed;
|
||||
import org.springframework.data.couchbase.repository.CouchbaseRepository;
|
||||
import org.springframework.data.couchbase.repository.User;
|
||||
|
||||
@N1qlSecondaryIndexed(indexName = IndexedRepositoryTests.IGNORED_SECONDARY)
|
||||
@ViewIndexed(designDoc = IndexedRepositoryTests.VIEW_DOC, viewName = IndexedRepositoryTests.IGNORED_VIEW_NAME)
|
||||
@N1qlSecondaryIndexed(indexName = IndexedRepositoryIntegrationTests.IGNORED_SECONDARY)
|
||||
@ViewIndexed(designDoc = IndexedRepositoryIntegrationTests.VIEW_DOC, viewName = IndexedRepositoryIntegrationTests.IGNORED_VIEW_NAME)
|
||||
public interface AnotherIndexedUserRepository extends CouchbaseRepository<User, String> {
|
||||
|
||||
public List<User> findByAge(int age);
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.data.couchbase.repository.index;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.data.couchbase.CouchbaseTestHelper.getRepositoryWithRetry;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -30,7 +31,6 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
;
|
||||
import org.springframework.data.couchbase.ContainerResourceRunner;
|
||||
import org.springframework.data.couchbase.IntegrationTestApplicationConfig;
|
||||
import org.springframework.data.couchbase.core.CouchbaseOperations;
|
||||
@@ -50,7 +50,7 @@ import org.springframework.test.context.TestExecutionListeners;
|
||||
@RunWith(ContainerResourceRunner.class)
|
||||
@ContextConfiguration(classes = IntegrationTestApplicationConfig.class)
|
||||
@TestExecutionListeners(IndexedRepositoryTestListener.class)
|
||||
public class IndexedRepositoryTests {
|
||||
public class IndexedRepositoryIntegrationTests {
|
||||
|
||||
public static final String SECONDARY = "autogeneratedIndexIndexedUserN1qlSecondary";
|
||||
public static final String VIEW_DOC = "autogeneratedIndex";
|
||||
@@ -80,7 +80,7 @@ public class IndexedRepositoryTests {
|
||||
|
||||
@Test
|
||||
public void shouldFindN1qlPrimaryIndex() {
|
||||
IndexedUserRepository repository = factory.getRepository(IndexedUserRepository.class);
|
||||
IndexedUserRepository repository = getRepositoryWithRetry(factory, IndexedUserRepository.class);
|
||||
|
||||
String bucket = template.getCouchbaseBucket().name();
|
||||
N1qlQuery existQuery = N1qlQuery.simple("SELECT 1 FROM `"+ bucket +"`");
|
||||
@@ -91,7 +91,7 @@ public class IndexedRepositoryTests {
|
||||
|
||||
@Test
|
||||
public void shouldFindN1qlSecondaryIndex() {
|
||||
IndexedUserRepository repository = factory.getRepository(IndexedUserRepository.class);
|
||||
IndexedUserRepository repository = getRepositoryWithRetry(factory, IndexedUserRepository.class);
|
||||
|
||||
String bucket = template.getCouchbaseBucket().name();
|
||||
N1qlQuery existQuery = N1qlQuery.simple("SELECT 1 FROM `"+ bucket +"` USE INDEX (" + SECONDARY +")");
|
||||
@@ -102,7 +102,7 @@ public class IndexedRepositoryTests {
|
||||
|
||||
@Test
|
||||
public void shouldFindViewIndex() {
|
||||
IndexedUserRepository repository = factory.getRepository(IndexedUserRepository.class);
|
||||
IndexedUserRepository repository = getRepositoryWithRetry(factory, IndexedUserRepository.class);
|
||||
|
||||
DesignDocument designDoc = null;
|
||||
try {
|
||||
@@ -121,7 +121,7 @@ public class IndexedRepositoryTests {
|
||||
}
|
||||
@Test
|
||||
public void shouldNotFindN1qlSecondaryIndexWithIgnoringIndexManager() {
|
||||
AnotherIndexedUserRepository repository = ignoringIndexFactory.getRepository(AnotherIndexedUserRepository.class);
|
||||
AnotherIndexedUserRepository repository = getRepositoryWithRetry(ignoringIndexFactory, AnotherIndexedUserRepository.class);
|
||||
|
||||
String bucket = template.getCouchbaseBucket().name();
|
||||
N1qlQuery existQuery = N1qlQuery.simple("SELECT 1 FROM `"+ bucket +"` USE INDEX (" + IGNORED_SECONDARY +")");
|
||||
@@ -132,7 +132,7 @@ public class IndexedRepositoryTests {
|
||||
|
||||
@Test
|
||||
public void shouldNotFindViewIndexWithIgnoringIndexManager() {
|
||||
AnotherIndexedUserRepository repository = ignoringIndexFactory.getRepository(AnotherIndexedUserRepository.class);
|
||||
AnotherIndexedUserRepository repository = getRepositoryWithRetry(ignoringIndexFactory, AnotherIndexedUserRepository.class);
|
||||
|
||||
DesignDocument designDoc = null;
|
||||
try {
|
||||
@@ -155,7 +155,7 @@ public class IndexedRepositoryTests {
|
||||
IndexedFooRepository.Foo foo1 = new IndexedFooRepository.Foo("foo1", "foo", 1);
|
||||
IndexedFooRepository.Foo foo2 = new IndexedFooRepository.Foo("foo2", "bar", 2);
|
||||
|
||||
IndexedFooRepository repository = factory.getRepository(IndexedFooRepository.class);
|
||||
IndexedFooRepository repository = getRepositoryWithRetry(factory, IndexedFooRepository.class);
|
||||
|
||||
DesignDocument designDoc = template.getCouchbaseBucket()
|
||||
.bucketManager()
|
||||
@@ -10,7 +10,7 @@ import org.springframework.test.context.TestContext;
|
||||
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
|
||||
|
||||
/**
|
||||
* A test listener that will remove the indexes created in {@link IndexedRepositoryTests} before test case is run.
|
||||
* A test listener that will remove the indexes created in {@link IndexedRepositoryIntegrationTests} before test case is run.
|
||||
*
|
||||
* @author Simon Baslé
|
||||
*/
|
||||
@@ -20,12 +20,12 @@ public class IndexedRepositoryTestListener extends DependencyInjectionTestExecut
|
||||
public void beforeTestClass(final TestContext testContext) throws Exception {
|
||||
Bucket client = (Bucket) testContext.getApplicationContext().getBean(BeanNames.COUCHBASE_BUCKET);
|
||||
try {
|
||||
client.bucketManager().removeDesignDocument(IndexedRepositoryTests.VIEW_DOC);
|
||||
client.bucketManager().removeDesignDocument(IndexedRepositoryIntegrationTests.VIEW_DOC);
|
||||
client.bucketManager().removeDesignDocument("foo");
|
||||
} catch (DesignDocumentDoesNotExistException ex) {
|
||||
//ignore
|
||||
}
|
||||
client.query(N1qlQuery.simple(Index.dropPrimaryIndex(client.name())));
|
||||
client.query(N1qlQuery.simple(Index.dropIndex(client.name(), IndexedRepositoryTests.SECONDARY)));
|
||||
client.query(N1qlQuery.simple(Index.dropIndex(client.name(), IndexedRepositoryIntegrationTests.SECONDARY)));
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import org.springframework.data.couchbase.repository.CouchbaseRepository;
|
||||
import org.springframework.data.couchbase.repository.User;
|
||||
|
||||
@N1qlPrimaryIndexed
|
||||
@N1qlSecondaryIndexed(indexName = IndexedRepositoryTests.SECONDARY)
|
||||
@ViewIndexed(designDoc = IndexedRepositoryTests.VIEW_DOC, viewName = IndexedRepositoryTests.VIEW_NAME)
|
||||
@N1qlSecondaryIndexed(indexName = IndexedRepositoryIntegrationTests.SECONDARY)
|
||||
@ViewIndexed(designDoc = IndexedRepositoryIntegrationTests.VIEW_DOC, viewName = IndexedRepositoryIntegrationTests.VIEW_NAME)
|
||||
public interface IndexedUserRepository extends CouchbaseRepository<User, String> {
|
||||
}
|
||||
@@ -29,6 +29,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestExecutionListeners;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.data.couchbase.CouchbaseTestHelper.getRepositoryWithRetry;
|
||||
|
||||
/**
|
||||
* N1ql Join tests
|
||||
@@ -39,7 +40,7 @@ import static org.junit.Assert.*;
|
||||
@RunWith(ContainerResourceRunner.class)
|
||||
@ContextConfiguration(classes = IntegrationTestApplicationConfig.class)
|
||||
@TestExecutionListeners(listeners = {AuthorAndBookPopulatorListener.class})
|
||||
public class N1qlJoinTests {
|
||||
public class N1qlJoinIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private RepositoryOperationsMapping operationsMapping;
|
||||
@@ -56,9 +57,9 @@ public class N1qlJoinTests {
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
RepositoryFactorySupport factory = new CouchbaseRepositoryFactory(operationsMapping, indexManager);
|
||||
bookRepository = factory.getRepository(BookRepository.class);
|
||||
authorRepository = factory.getRepository(AuthorRepository.class);
|
||||
addressRepository = factory.getRepository(AddressRepository.class);
|
||||
bookRepository = getRepositoryWithRetry(factory, BookRepository.class);
|
||||
authorRepository = getRepositoryWithRetry(factory, AuthorRepository.class);
|
||||
addressRepository = getRepositoryWithRetry(factory, AddressRepository.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -82,4 +83,4 @@ public class N1qlJoinTests {
|
||||
assertTrue(saveda.books.isEmpty());
|
||||
assertNull(saveda.address);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.couchbase.IntegrationTestApplicationConfig;
|
||||
import org.springframework.data.couchbase.repository.config.EnableCouchbaseRepositories;
|
||||
import org.springframework.data.repository.query.spi.EvaluationContextExtension;
|
||||
import org.springframework.data.repository.query.spi.EvaluationContextExtensionSupport;
|
||||
import org.springframework.data.spel.spi.EvaluationContextExtension;
|
||||
|
||||
@Configuration
|
||||
@EnableCouchbaseRepositories
|
||||
@@ -19,7 +18,7 @@ public class SpelConfig extends IntegrationTestApplicationConfig {
|
||||
return new CustomSpelExtension();
|
||||
}
|
||||
|
||||
public static class CustomSpelExtension extends EvaluationContextExtensionSupport {
|
||||
public static class CustomSpelExtension implements EvaluationContextExtension {
|
||||
|
||||
/**
|
||||
* Returns the identifier of the extension. The id can be leveraged by users to fully qualify property lookups and
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user