1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krms.impl.repository;
17
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.junit.runner.RunWith;
21 import org.kuali.rice.core.api.criteria.GenericQueryResults;
22 import org.kuali.rice.core.api.criteria.QueryByCriteria;
23 import org.kuali.rice.krad.data.DataObjectService;
24 import org.kuali.rice.krad.data.PersistenceOption;
25 import org.kuali.rice.krms.api.repository.KrmsTypeGenTest;
26 import org.kuali.rice.krms.api.repository.NaturalLanguageUsageGenTest;
27 import org.kuali.rice.krms.api.repository.language.NaturalLanguageUsage;
28 import org.kuali.rice.krms.api.repository.type.KrmsTypeDefinition;
29 import org.mockito.Mock;
30 import org.mockito.MockitoAnnotations;
31 import org.mockito.runners.MockitoJUnitRunner;
32
33 import java.util.ArrayList;
34 import java.util.List;
35
36 import static org.junit.Assert.assertEquals;
37 import static org.junit.Assert.assertNotNull;
38 import static org.junit.Assert.assertNull;
39 import static org.mockito.Matchers.any;
40 import static org.mockito.Mockito.mock;
41 import static org.mockito.Mockito.when;
42
43
44
45
46
47 @RunWith(MockitoJUnitRunner.class)
48 public class NaturalLanguageUsageBoServiceImplGenTest {
49 private NaturalLanguageUsageBoServiceImpl service;
50 private NaturalLanguageUsage naturalLanguageUsage;
51 private DataObjectService mockDataObjectService;
52
53 public NaturalLanguageUsageBoServiceImplGenTest() {
54 mockDataObjectService = mock(DataObjectService.class);
55 }
56
57 @Before
58 public void setUp() {
59 service = new NaturalLanguageUsageBoServiceImpl();
60 service.setDataObjectService(mockDataObjectService);
61 }
62
63 @Test
64 public void test_createNaturalLanguageUsage() {
65 NaturalLanguageUsage def = NaturalLanguageUsageGenTest.buildFullNaturalLanguageUsage();
66 naturalLanguageUsage = service.getNaturalLanguageUsageByName(def.getNamespace(), def.getName());
67 if (naturalLanguageUsage == null) {
68 naturalLanguageUsage = service.createNaturalLanguageUsage(def);
69 }
70 }
71
72 @Test
73 public void test_createNaturalLanguageUsageGeneratedId() {
74 NaturalLanguageUsage def = NaturalLanguageUsageGenTest.buildFullNaturalLanguageUsageNoId();
75 naturalLanguageUsage = service.createNaturalLanguageUsage(def);
76 }
77
78 @Test
79 public void test_createNaturalLanguageUsage_GeneratedId_success() {
80 NaturalLanguageUsageBo saveResult = service.from(NaturalLanguageUsageGenTest.buildFullNaturalLanguageUsage());
81 when(mockDataObjectService.findMatching(any(Class.class), any(QueryByCriteria.class))).thenReturn(null);
82 when(mockDataObjectService.save(any(NaturalLanguageUsageBo.class), any(PersistenceOption.class))).thenReturn(saveResult);
83 NaturalLanguageUsage def = NaturalLanguageUsageGenTest.buildFullNaturalLanguageUsageNoId();
84 naturalLanguageUsage = service.createNaturalLanguageUsage(def);
85 assertNotNull(naturalLanguageUsage);
86 }
87
88 @Test
89 public void test_getNaturalLanguageUsageByName_success() {
90 final GenericQueryResults.Builder findMatchingResult = GenericQueryResults.Builder.create();
91 final List<NaturalLanguageUsageBo> resultList = new ArrayList<NaturalLanguageUsageBo>();
92 NaturalLanguageUsageBo e = service.from(NaturalLanguageUsageGenTest.buildFullNaturalLanguageUsage());
93 resultList.add(e);
94 findMatchingResult.setResults(resultList);
95 when(mockDataObjectService.findMatching(any(Class.class), any(QueryByCriteria.class))).thenReturn(findMatchingResult);
96 NaturalLanguageUsage def = NaturalLanguageUsageGenTest.buildFullNaturalLanguageUsage();
97 naturalLanguageUsage = service.getNaturalLanguageUsageByName(def.getNamespace(), def.getName());
98 assertNotNull(naturalLanguageUsage);
99 }
100
101 @Test
102 public void test_updateNaturalLanguageUsage_success() {
103 NaturalLanguageUsage data = NaturalLanguageUsageGenTest.buildFullNaturalLanguageUsage();
104 NaturalLanguageUsage findResult = NaturalLanguageUsageGenTest.buildFullNaturalLanguageUsage();
105 NaturalLanguageUsageBo saveResult = service.from(NaturalLanguageUsageGenTest.buildFullNaturalLanguageUsage());
106 when(mockDataObjectService.find(any(Class.class), any(String.class))).thenReturn(service.from(findResult));
107 when(mockDataObjectService.save(any(NaturalLanguageUsageBo.class), any(PersistenceOption.class))).thenReturn(saveResult);
108 NaturalLanguageUsage updatedData = service.updateNaturalLanguageUsage(data);
109 assertNotNull(updatedData);
110 }
111
112 @Test
113 public void test_from_null_yields_null() {
114 assertNull(service.from(null));
115 }
116
117 @Test
118 public void test_from() {
119 NaturalLanguageUsage def = NaturalLanguageUsageGenTest.buildFullNaturalLanguageUsage();
120 NaturalLanguageUsageBo def2 = service.from(def);
121 assertEquals(def2.getName(), def.getName());
122 assertEquals(def2.getNamespace(),def.getNamespace());
123 assertEquals(def2.getId(), def.getId());
124 }
125
126 @Test
127 public void test_to() {
128 NaturalLanguageUsage def = NaturalLanguageUsageGenTest.buildFullNaturalLanguageUsage();
129 NaturalLanguageUsageBo naturalLanguageUsageBo = service.from(def);
130 NaturalLanguageUsage def2 = NaturalLanguageUsageBo.to(naturalLanguageUsageBo);
131 assertEquals(def, def2);
132 }
133
134 @Test(expected = IllegalArgumentException.class)
135 public void test_findNaturalLanguageUsagesByName_null_fail() {
136 service.findNaturalLanguageUsagesByName(null);
137 }
138
139 @Test(expected = IllegalArgumentException.class)
140 public void test_findNaturalLanguageUsagesByDescription_null_fail() {
141 service.findNaturalLanguageUsagesByDescription(null);
142 }
143
144 @Test(expected = IllegalArgumentException.class)
145 public void test_findNaturalLanguageUsagesByNamespace_null_fail() {
146 service.findNaturalLanguageUsagesByNamespace(null);
147 }
148
149 @Test(expected = IllegalArgumentException.class)
150 public void test_createNaturalLanguageUsage_null_fail() {
151 service.createNaturalLanguageUsage(null);
152 }
153
154 @Test(expected = IllegalArgumentException.class)
155 public void test_updateNaturalLanguageUsage_null_fail() {
156 service.updateNaturalLanguageUsage(null);
157 }
158
159 @Test(expected = IllegalArgumentException.class)
160 public void test_deleteNaturalLanguageUsage_null_fail() {
161 service.deleteNaturalLanguageUsage(null);
162 }
163
164 public NaturalLanguageUsage getNaturalLanguageUsage() {
165 return naturalLanguageUsage;
166 }
167
168 public void setNaturalLanguageUsageBoServiceImpl(NaturalLanguageUsageBoServiceImpl impl) {
169 this.service = impl;
170 }
171
172 public static NaturalLanguageUsageBoServiceImplGenTest create(NaturalLanguageUsageBoServiceImpl impl) {
173 NaturalLanguageUsageBoServiceImplGenTest test = new NaturalLanguageUsageBoServiceImplGenTest();
174 test.setNaturalLanguageUsageBoServiceImpl(impl);
175 return test;
176 }
177
178
179
180
181
182
183
184 }