mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-07-07 19:22:10 +00:00
DATAES-395 - Polishing.
Fix line endings.
This commit is contained in:
parent
6dd4d28067
commit
960263837b
@ -1,141 +1,141 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014-2017 the original author or authors.
|
* Copyright 2014-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.repositories.cdi;
|
package org.springframework.data.elasticsearch.repositories.cdi;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.*;
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import javax.enterprise.inject.se.SeContainer;
|
import javax.enterprise.inject.se.SeContainer;
|
||||||
import javax.enterprise.inject.se.SeContainerInitializer;
|
import javax.enterprise.inject.se.SeContainerInitializer;
|
||||||
|
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.data.elasticsearch.entities.Product;
|
import org.springframework.data.elasticsearch.entities.Product;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
*/
|
*/
|
||||||
public class CdiRepositoryTests {
|
public class CdiRepositoryTests {
|
||||||
|
|
||||||
private static SeContainer cdiContainer;
|
private static SeContainer cdiContainer;
|
||||||
private CdiProductRepository repository;
|
private CdiProductRepository repository;
|
||||||
private SamplePersonRepository personRepository;
|
private SamplePersonRepository personRepository;
|
||||||
private QualifiedProductRepository qualifiedProductRepository;
|
private QualifiedProductRepository qualifiedProductRepository;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void init() {
|
public static void init() {
|
||||||
|
|
||||||
cdiContainer = SeContainerInitializer.newInstance() //
|
cdiContainer = SeContainerInitializer.newInstance() //
|
||||||
.disableDiscovery() //
|
.disableDiscovery() //
|
||||||
.addPackages(CdiRepositoryClient.class) //
|
.addPackages(CdiRepositoryClient.class) //
|
||||||
.initialize();
|
.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void shutdown() {
|
public static void shutdown() {
|
||||||
cdiContainer.close();
|
cdiContainer.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
|
|
||||||
CdiRepositoryClient client = cdiContainer.select(CdiRepositoryClient.class).get();
|
CdiRepositoryClient client = cdiContainer.select(CdiRepositoryClient.class).get();
|
||||||
repository = client.getRepository();
|
repository = client.getRepository();
|
||||||
personRepository = client.getSamplePersonRepository();
|
personRepository = client.getSamplePersonRepository();
|
||||||
repository.deleteAll();
|
repository.deleteAll();
|
||||||
qualifiedProductRepository = client.getQualifiedProductRepository();
|
qualifiedProductRepository = client.getQualifiedProductRepository();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCdiRepository() {
|
public void testCdiRepository() {
|
||||||
|
|
||||||
assertNotNull(repository);
|
assertNotNull(repository);
|
||||||
|
|
||||||
Product bean = new Product();
|
Product bean = new Product();
|
||||||
bean.setId("id-1");
|
bean.setId("id-1");
|
||||||
bean.setName("cidContainerTest-1");
|
bean.setName("cidContainerTest-1");
|
||||||
|
|
||||||
repository.save(bean);
|
repository.save(bean);
|
||||||
|
|
||||||
assertTrue(repository.existsById(bean.getId()));
|
assertTrue(repository.existsById(bean.getId()));
|
||||||
|
|
||||||
Optional<Product> retrieved = repository.findById(bean.getId());
|
Optional<Product> retrieved = repository.findById(bean.getId());
|
||||||
|
|
||||||
assertTrue(retrieved.isPresent());
|
assertTrue(retrieved.isPresent());
|
||||||
retrieved.ifPresent(product -> {
|
retrieved.ifPresent(product -> {
|
||||||
assertEquals(bean.getId(), product.getId());
|
assertEquals(bean.getId(), product.getId());
|
||||||
assertEquals(bean.getName(), product.getName());
|
assertEquals(bean.getName(), product.getName());
|
||||||
});
|
});
|
||||||
|
|
||||||
assertEquals(1, repository.count());
|
assertEquals(1, repository.count());
|
||||||
|
|
||||||
assertTrue(repository.existsById(bean.getId()));
|
assertTrue(repository.existsById(bean.getId()));
|
||||||
|
|
||||||
repository.delete(bean);
|
repository.delete(bean);
|
||||||
|
|
||||||
assertEquals(0, repository.count());
|
assertEquals(0, repository.count());
|
||||||
retrieved = repository.findById(bean.getId());
|
retrieved = repository.findById(bean.getId());
|
||||||
assertFalse(retrieved.isPresent());
|
assertFalse(retrieved.isPresent());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see DATAES-234
|
* @see DATAES-234
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testQualifiedCdiRepository() {
|
public void testQualifiedCdiRepository() {
|
||||||
assertNotNull(qualifiedProductRepository);
|
assertNotNull(qualifiedProductRepository);
|
||||||
|
|
||||||
Product bean = new Product();
|
Product bean = new Product();
|
||||||
bean.setId("id-1");
|
bean.setId("id-1");
|
||||||
bean.setName("cidContainerTest-1");
|
bean.setName("cidContainerTest-1");
|
||||||
|
|
||||||
qualifiedProductRepository.save(bean);
|
qualifiedProductRepository.save(bean);
|
||||||
|
|
||||||
assertTrue(qualifiedProductRepository.existsById(bean.getId()));
|
assertTrue(qualifiedProductRepository.existsById(bean.getId()));
|
||||||
|
|
||||||
Optional<Product> retrieved = qualifiedProductRepository.findById(bean.getId());
|
Optional<Product> retrieved = qualifiedProductRepository.findById(bean.getId());
|
||||||
|
|
||||||
assertTrue(retrieved.isPresent());
|
assertTrue(retrieved.isPresent());
|
||||||
retrieved.ifPresent(product -> {
|
retrieved.ifPresent(product -> {
|
||||||
assertEquals(bean.getId(), product.getId());
|
assertEquals(bean.getId(), product.getId());
|
||||||
assertEquals(bean.getName(), product.getName());
|
assertEquals(bean.getName(), product.getName());
|
||||||
});
|
});
|
||||||
|
|
||||||
assertEquals(1, qualifiedProductRepository.count());
|
assertEquals(1, qualifiedProductRepository.count());
|
||||||
|
|
||||||
assertTrue(qualifiedProductRepository.existsById(bean.getId()));
|
assertTrue(qualifiedProductRepository.existsById(bean.getId()));
|
||||||
|
|
||||||
qualifiedProductRepository.delete(bean);
|
qualifiedProductRepository.delete(bean);
|
||||||
|
|
||||||
assertEquals(0, qualifiedProductRepository.count());
|
assertEquals(0, qualifiedProductRepository.count());
|
||||||
retrieved = qualifiedProductRepository.findById(bean.getId());
|
retrieved = qualifiedProductRepository.findById(bean.getId());
|
||||||
assertFalse(retrieved.isPresent());
|
assertFalse(retrieved.isPresent());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see DATAES-113
|
* @see DATAES-113
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void returnOneFromCustomImpl() {
|
public void returnOneFromCustomImpl() {
|
||||||
assertThat(personRepository.returnOne(), is(1));
|
assertThat(personRepository.returnOne(), is(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user