|
1 |
| -/* |
2 |
| - * Copyright 2014-2017 the original author or authors. |
3 |
| - * |
4 |
| - * Licensed under the Apache License, Version 2.0 (the "License"); |
5 |
| - * you may not use this file except in compliance with the License. |
6 |
| - * You may obtain a copy of the License at |
7 |
| - * |
8 |
| - * http://www.apache.org/licenses/LICENSE-2.0 |
9 |
| - * |
10 |
| - * Unless required by applicable law or agreed to in writing, software |
11 |
| - * distributed under the License is distributed on an "AS IS" BASIS, |
12 |
| - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 |
| - * See the License for the specific language governing permissions and |
14 |
| - * limitations under the License. |
15 |
| - */ |
16 |
| -package org.springframework.data.elasticsearch.repositories.cdi; |
17 |
| - |
18 |
| -import static org.hamcrest.CoreMatchers.*; |
19 |
| -import static org.junit.Assert.*; |
20 |
| - |
21 |
| -import java.util.Optional; |
22 |
| - |
23 |
| -import javax.enterprise.inject.se.SeContainer; |
24 |
| -import javax.enterprise.inject.se.SeContainerInitializer; |
25 |
| - |
26 |
| -import org.junit.AfterClass; |
27 |
| -import org.junit.Before; |
28 |
| -import org.junit.BeforeClass; |
29 |
| -import org.junit.Test; |
30 |
| -import org.springframework.data.elasticsearch.entities.Product; |
31 |
| - |
32 |
| -/** |
33 |
| - * @author Mohsin Husen |
34 |
| - * @author Mark Paluch |
35 |
| - * @author Christoph Strobl |
36 |
| - */ |
37 |
| -public class CdiRepositoryTests { |
38 |
| - |
39 |
| - private static SeContainer cdiContainer; |
40 |
| - private CdiProductRepository repository; |
41 |
| - private SamplePersonRepository personRepository; |
42 |
| - private QualifiedProductRepository qualifiedProductRepository; |
43 |
| - |
44 |
| - @BeforeClass |
45 |
| - public static void init() { |
46 |
| - |
47 |
| - cdiContainer = SeContainerInitializer.newInstance() // |
48 |
| - .disableDiscovery() // |
49 |
| - .addPackages(CdiRepositoryClient.class) // |
50 |
| - .initialize(); |
51 |
| - } |
52 |
| - |
53 |
| - @AfterClass |
54 |
| - public static void shutdown() { |
55 |
| - cdiContainer.close(); |
56 |
| - } |
57 |
| - |
58 |
| - @Before |
59 |
| - public void setUp() { |
60 |
| - |
61 |
| - CdiRepositoryClient client = cdiContainer.select(CdiRepositoryClient.class).get(); |
62 |
| - repository = client.getRepository(); |
63 |
| - personRepository = client.getSamplePersonRepository(); |
64 |
| - repository.deleteAll(); |
65 |
| - qualifiedProductRepository = client.getQualifiedProductRepository(); |
66 |
| - } |
67 |
| - |
68 |
| - @Test |
69 |
| - public void testCdiRepository() { |
70 |
| - |
71 |
| - assertNotNull(repository); |
72 |
| - |
73 |
| - Product bean = new Product(); |
74 |
| - bean.setId("id-1"); |
75 |
| - bean.setName("cidContainerTest-1"); |
76 |
| - |
77 |
| - repository.save(bean); |
78 |
| - |
79 |
| - assertTrue(repository.existsById(bean.getId())); |
80 |
| - |
81 |
| - Optional<Product> retrieved = repository.findById(bean.getId()); |
82 |
| - |
83 |
| - assertTrue(retrieved.isPresent()); |
84 |
| - retrieved.ifPresent(product -> { |
85 |
| - assertEquals(bean.getId(), product.getId()); |
86 |
| - assertEquals(bean.getName(), product.getName()); |
87 |
| - }); |
88 |
| - |
89 |
| - assertEquals(1, repository.count()); |
90 |
| - |
91 |
| - assertTrue(repository.existsById(bean.getId())); |
92 |
| - |
93 |
| - repository.delete(bean); |
94 |
| - |
95 |
| - assertEquals(0, repository.count()); |
96 |
| - retrieved = repository.findById(bean.getId()); |
97 |
| - assertFalse(retrieved.isPresent()); |
98 |
| - } |
99 |
| - |
100 |
| - /** |
101 |
| - * @see DATAES-234 |
102 |
| - */ |
103 |
| - @Test |
104 |
| - public void testQualifiedCdiRepository() { |
105 |
| - assertNotNull(qualifiedProductRepository); |
106 |
| - |
107 |
| - Product bean = new Product(); |
108 |
| - bean.setId("id-1"); |
109 |
| - bean.setName("cidContainerTest-1"); |
110 |
| - |
111 |
| - qualifiedProductRepository.save(bean); |
112 |
| - |
113 |
| - assertTrue(qualifiedProductRepository.existsById(bean.getId())); |
114 |
| - |
115 |
| - Optional<Product> retrieved = qualifiedProductRepository.findById(bean.getId()); |
116 |
| - |
117 |
| - assertTrue(retrieved.isPresent()); |
118 |
| - retrieved.ifPresent(product -> { |
119 |
| - assertEquals(bean.getId(), product.getId()); |
120 |
| - assertEquals(bean.getName(), product.getName()); |
121 |
| - }); |
122 |
| - |
123 |
| - assertEquals(1, qualifiedProductRepository.count()); |
124 |
| - |
125 |
| - assertTrue(qualifiedProductRepository.existsById(bean.getId())); |
126 |
| - |
127 |
| - qualifiedProductRepository.delete(bean); |
128 |
| - |
129 |
| - assertEquals(0, qualifiedProductRepository.count()); |
130 |
| - retrieved = qualifiedProductRepository.findById(bean.getId()); |
131 |
| - assertFalse(retrieved.isPresent()); |
132 |
| - } |
133 |
| - |
134 |
| - /** |
135 |
| - * @see DATAES-113 |
136 |
| - */ |
137 |
| - @Test |
138 |
| - public void returnOneFromCustomImpl() { |
139 |
| - assertThat(personRepository.returnOne(), is(1)); |
140 |
| - } |
141 |
| -} |
| 1 | +/* |
| 2 | + * Copyright 2014-2017 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package org.springframework.data.elasticsearch.repositories.cdi; |
| 17 | + |
| 18 | +import static org.hamcrest.CoreMatchers.*; |
| 19 | +import static org.junit.Assert.*; |
| 20 | + |
| 21 | +import java.util.Optional; |
| 22 | + |
| 23 | +import javax.enterprise.inject.se.SeContainer; |
| 24 | +import javax.enterprise.inject.se.SeContainerInitializer; |
| 25 | + |
| 26 | +import org.junit.AfterClass; |
| 27 | +import org.junit.Before; |
| 28 | +import org.junit.BeforeClass; |
| 29 | +import org.junit.Test; |
| 30 | +import org.springframework.data.elasticsearch.entities.Product; |
| 31 | + |
| 32 | +/** |
| 33 | + * @author Mohsin Husen |
| 34 | + * @author Mark Paluch |
| 35 | + * @author Christoph Strobl |
| 36 | + */ |
| 37 | +public class CdiRepositoryTests { |
| 38 | + |
| 39 | + private static SeContainer cdiContainer; |
| 40 | + private CdiProductRepository repository; |
| 41 | + private SamplePersonRepository personRepository; |
| 42 | + private QualifiedProductRepository qualifiedProductRepository; |
| 43 | + |
| 44 | + @BeforeClass |
| 45 | + public static void init() { |
| 46 | + |
| 47 | + cdiContainer = SeContainerInitializer.newInstance() // |
| 48 | + .disableDiscovery() // |
| 49 | + .addPackages(CdiRepositoryClient.class) // |
| 50 | + .initialize(); |
| 51 | + } |
| 52 | + |
| 53 | + @AfterClass |
| 54 | + public static void shutdown() { |
| 55 | + cdiContainer.close(); |
| 56 | + } |
| 57 | + |
| 58 | + @Before |
| 59 | + public void setUp() { |
| 60 | + |
| 61 | + CdiRepositoryClient client = cdiContainer.select(CdiRepositoryClient.class).get(); |
| 62 | + repository = client.getRepository(); |
| 63 | + personRepository = client.getSamplePersonRepository(); |
| 64 | + repository.deleteAll(); |
| 65 | + qualifiedProductRepository = client.getQualifiedProductRepository(); |
| 66 | + } |
| 67 | + |
| 68 | + @Test |
| 69 | + public void testCdiRepository() { |
| 70 | + |
| 71 | + assertNotNull(repository); |
| 72 | + |
| 73 | + Product bean = new Product(); |
| 74 | + bean.setId("id-1"); |
| 75 | + bean.setName("cidContainerTest-1"); |
| 76 | + |
| 77 | + repository.save(bean); |
| 78 | + |
| 79 | + assertTrue(repository.existsById(bean.getId())); |
| 80 | + |
| 81 | + Optional<Product> retrieved = repository.findById(bean.getId()); |
| 82 | + |
| 83 | + assertTrue(retrieved.isPresent()); |
| 84 | + retrieved.ifPresent(product -> { |
| 85 | + assertEquals(bean.getId(), product.getId()); |
| 86 | + assertEquals(bean.getName(), product.getName()); |
| 87 | + }); |
| 88 | + |
| 89 | + assertEquals(1, repository.count()); |
| 90 | + |
| 91 | + assertTrue(repository.existsById(bean.getId())); |
| 92 | + |
| 93 | + repository.delete(bean); |
| 94 | + |
| 95 | + assertEquals(0, repository.count()); |
| 96 | + retrieved = repository.findById(bean.getId()); |
| 97 | + assertFalse(retrieved.isPresent()); |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * @see DATAES-234 |
| 102 | + */ |
| 103 | + @Test |
| 104 | + public void testQualifiedCdiRepository() { |
| 105 | + assertNotNull(qualifiedProductRepository); |
| 106 | + |
| 107 | + Product bean = new Product(); |
| 108 | + bean.setId("id-1"); |
| 109 | + bean.setName("cidContainerTest-1"); |
| 110 | + |
| 111 | + qualifiedProductRepository.save(bean); |
| 112 | + |
| 113 | + assertTrue(qualifiedProductRepository.existsById(bean.getId())); |
| 114 | + |
| 115 | + Optional<Product> retrieved = qualifiedProductRepository.findById(bean.getId()); |
| 116 | + |
| 117 | + assertTrue(retrieved.isPresent()); |
| 118 | + retrieved.ifPresent(product -> { |
| 119 | + assertEquals(bean.getId(), product.getId()); |
| 120 | + assertEquals(bean.getName(), product.getName()); |
| 121 | + }); |
| 122 | + |
| 123 | + assertEquals(1, qualifiedProductRepository.count()); |
| 124 | + |
| 125 | + assertTrue(qualifiedProductRepository.existsById(bean.getId())); |
| 126 | + |
| 127 | + qualifiedProductRepository.delete(bean); |
| 128 | + |
| 129 | + assertEquals(0, qualifiedProductRepository.count()); |
| 130 | + retrieved = qualifiedProductRepository.findById(bean.getId()); |
| 131 | + assertFalse(retrieved.isPresent()); |
| 132 | + } |
| 133 | + |
| 134 | + /** |
| 135 | + * @see DATAES-113 |
| 136 | + */ |
| 137 | + @Test |
| 138 | + public void returnOneFromCustomImpl() { |
| 139 | + assertThat(personRepository.returnOne(), is(1)); |
| 140 | + } |
| 141 | +} |
0 commit comments