|
1 |
| -///* |
2 |
| -// * Copyright 2014 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.is; |
19 |
| -//import static org.junit.Assert.*; |
20 |
| -// |
21 |
| -//import org.apache.webbeans.cditest.CdiTestContainer; |
22 |
| -//import org.apache.webbeans.cditest.CdiTestContainerLoader; |
23 |
| -//import org.junit.AfterClass; |
24 |
| -//import org.junit.Before; |
25 |
| -//import org.junit.BeforeClass; |
26 |
| -//import org.junit.Test; |
27 |
| -//import org.springframework.data.elasticsearch.entities.Product; |
28 |
| -// |
29 |
| -///** |
30 |
| -// * @author Mohsin Husen |
31 |
| -// */ |
32 |
| -//TODO: ako cdi - jar hell |
33 |
| -//public class CdiRepositoryTests { |
34 |
| -// |
35 |
| -// private static CdiTestContainer cdiContainer; |
36 |
| -// private CdiProductRepository repository; |
37 |
| -// private SamplePersonRepository personRepository; |
38 |
| -// |
39 |
| -// @BeforeClass |
40 |
| -// public static void init() throws Exception { |
41 |
| -// cdiContainer = CdiTestContainerLoader.getCdiContainer(); |
42 |
| -// cdiContainer.startApplicationScope(); |
43 |
| -// cdiContainer.bootContainer(); |
44 |
| -// } |
45 |
| -// |
46 |
| -// @AfterClass |
47 |
| -// public static void shutdown() throws Exception { |
48 |
| -// cdiContainer.stopContexts(); |
49 |
| -// cdiContainer.shutdownContainer(); |
50 |
| -// } |
51 |
| -// |
52 |
| -// @Before |
53 |
| -// public void setUp() { |
54 |
| -// CdiRepositoryClient client = cdiContainer.getInstance(CdiRepositoryClient.class); |
55 |
| -// repository = client.getRepository(); |
56 |
| -// personRepository = client.getSamplePersonRepository(); |
57 |
| -// } |
58 |
| -// |
59 |
| -// @Test |
60 |
| -// public void testCdiRepository() { |
61 |
| -// assertNotNull(repository); |
62 |
| -// |
63 |
| -// Product bean = new Product(); |
64 |
| -// bean.setId("id-1"); |
65 |
| -// bean.setName("cidContainerTest-1"); |
66 |
| -// |
67 |
| -// repository.save(bean); |
68 |
| -// |
69 |
| -// assertTrue(repository.exists(bean.getId())); |
70 |
| -// |
71 |
| -// Product retrieved = repository.findOne(bean.getId()); |
72 |
| -// assertNotNull(retrieved); |
73 |
| -// assertEquals(bean.getId(), retrieved.getId()); |
74 |
| -// assertEquals(bean.getName(), retrieved.getName()); |
75 |
| -// |
76 |
| -// assertEquals(1, repository.count()); |
77 |
| -// |
78 |
| -// assertTrue(repository.exists(bean.getId())); |
79 |
| -// |
80 |
| -// repository.delete(bean); |
81 |
| -// |
82 |
| -// assertEquals(0, repository.count()); |
83 |
| -// retrieved = repository.findOne(bean.getId()); |
84 |
| -// assertNull(retrieved); |
85 |
| -// } |
86 |
| -// |
87 |
| -// /** |
88 |
| -// * @see DATAES-113 |
89 |
| -// */ |
90 |
| -// @Test |
91 |
| -// public void returnOneFromCustomImpl() { |
92 |
| -// |
93 |
| -// assertThat(personRepository.returnOne(), is(1)); |
94 |
| -// } |
95 |
| -//} |
| 1 | +/* |
| 2 | + * Copyright 2014 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.is; |
| 19 | +import static org.junit.Assert.*; |
| 20 | + |
| 21 | +import org.apache.webbeans.cditest.CdiTestContainer; |
| 22 | +import org.apache.webbeans.cditest.CdiTestContainerLoader; |
| 23 | +import org.junit.AfterClass; |
| 24 | +import org.junit.Before; |
| 25 | +import org.junit.BeforeClass; |
| 26 | +import org.junit.Test; |
| 27 | +import org.springframework.data.elasticsearch.entities.Product; |
| 28 | + |
| 29 | +/** |
| 30 | + * @author Mohsin Husen |
| 31 | + */ |
| 32 | + |
| 33 | +public class CdiRepositoryTests { |
| 34 | + |
| 35 | + private static CdiTestContainer cdiContainer; |
| 36 | + private CdiProductRepository repository; |
| 37 | + private SamplePersonRepository personRepository; |
| 38 | + |
| 39 | + @BeforeClass |
| 40 | + public static void init() throws Exception { |
| 41 | + cdiContainer = CdiTestContainerLoader.getCdiContainer(); |
| 42 | + cdiContainer.startApplicationScope(); |
| 43 | + cdiContainer.bootContainer(); |
| 44 | + } |
| 45 | + |
| 46 | + @AfterClass |
| 47 | + public static void shutdown() throws Exception { |
| 48 | + cdiContainer.stopContexts(); |
| 49 | + cdiContainer.shutdownContainer(); |
| 50 | + } |
| 51 | + |
| 52 | + @Before |
| 53 | + public void setUp() { |
| 54 | + CdiRepositoryClient client = cdiContainer.getInstance(CdiRepositoryClient.class); |
| 55 | + repository = client.getRepository(); |
| 56 | + personRepository = client.getSamplePersonRepository(); |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + public void testCdiRepository() { |
| 61 | + assertNotNull(repository); |
| 62 | + |
| 63 | + Product bean = new Product(); |
| 64 | + bean.setId("id-1"); |
| 65 | + bean.setName("cidContainerTest-1"); |
| 66 | + |
| 67 | + repository.save(bean); |
| 68 | + |
| 69 | + assertTrue(repository.exists(bean.getId())); |
| 70 | + |
| 71 | + Product retrieved = repository.findOne(bean.getId()); |
| 72 | + assertNotNull(retrieved); |
| 73 | + assertEquals(bean.getId(), retrieved.getId()); |
| 74 | + assertEquals(bean.getName(), retrieved.getName()); |
| 75 | + |
| 76 | + assertEquals(1, repository.count()); |
| 77 | + |
| 78 | + assertTrue(repository.exists(bean.getId())); |
| 79 | + |
| 80 | + repository.delete(bean); |
| 81 | + |
| 82 | + assertEquals(0, repository.count()); |
| 83 | + retrieved = repository.findOne(bean.getId()); |
| 84 | + assertNull(retrieved); |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * @see DATAES-113 |
| 89 | + */ |
| 90 | + @Test |
| 91 | + public void returnOneFromCustomImpl() { |
| 92 | + |
| 93 | + assertThat(personRepository.returnOne(), is(1)); |
| 94 | + } |
| 95 | +} |
0 commit comments