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.kuali.rice.krms.api.repository.language.NaturalLanguageTemplate;
21 import org.kuali.rice.krms.api.repository.language.NaturalLanguageTemplaterContract;
22 import org.kuali.rice.krms.api.repository.language.NaturalLanguageUsage;
23 import org.kuali.rice.krms.api.repository.type.KrmsTypeDefinition;
24 import org.kuali.rice.krms.test.AbstractBoTest;
25 import org.kuali.rice.test.BaselineTestCase;
26
27 import java.util.Iterator;
28 import java.util.Map;
29
30
31
32
33
34 @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.ROLLBACK_CLEAR_DB)
35 public final class NaturalLanguageTemplateIntegrationGenTest extends AbstractBoTest {
36
37 NaturalLanguageTemplateBoServiceImpl naturalLanguageTemplateBoServiceImpl;
38 NaturalLanguageTemplate naturalLanguageTemplate;
39 KrmsAttributeDefinitionService krmsAttributeDefinitionService;
40 KrmsTypeBoServiceImpl krmsTypeBoServiceImpl;
41 NaturalLanguageUsageBoServiceImpl naturalLanguageUsageBoServiceImpl;
42
43 NaturalLanguageTemplate getNaturalLanguageTemplate() {
44 return naturalLanguageTemplate;
45 }
46
47
48
49
50
51 @Before
52 public void setup() {
53 naturalLanguageTemplateBoServiceImpl = new NaturalLanguageTemplateBoServiceImpl();
54 naturalLanguageTemplateBoServiceImpl.setNaturalLanguageTemplater(newStringReplaceTemplater());
55 krmsAttributeDefinitionService = KrmsRepositoryServiceLocator.getKrmsAttributeDefinitionService();
56 naturalLanguageTemplateBoServiceImpl.setAttributeDefinitionService(krmsAttributeDefinitionService);
57 naturalLanguageTemplateBoServiceImpl.setBusinessObjectService(getBoService());
58 krmsTypeBoServiceImpl = new KrmsTypeBoServiceImpl();
59 krmsTypeBoServiceImpl.setBusinessObjectService(getBoService());
60 naturalLanguageUsageBoServiceImpl = new NaturalLanguageUsageBoServiceImpl();
61 naturalLanguageUsageBoServiceImpl.setBusinessObjectService(getBoService());
62 }
63
64 public static NaturalLanguageTemplaterContract newStringReplaceTemplater() {
65 return new NaturalLanguageTemplaterContract() {
66 @Override
67 public String template(NaturalLanguageTemplate naturalLanguageTemplate) {
68 String template = naturalLanguageTemplate.getTemplate();
69 Map<String, String> attributes = naturalLanguageTemplate.getAttributes();
70 Iterator<String> keys = attributes.keySet().iterator();
71 while (keys.hasNext()) {
72 String key = keys.next();
73 template.replace(key, attributes.get(key));
74 }
75 return template;
76 }
77 };
78 }
79
80 @Test(expected = java.lang.IllegalArgumentException.class)
81 public void test_getNaturalLanguageTemplatesByAttributes_null_fail() {
82 (NaturalLanguageTemplateBoServiceImplGenTest.create(naturalLanguageTemplateBoServiceImpl, krmsAttributeDefinitionService)).test_getNaturalLanguageTemplatesByAttributes_null_fail();
83 }
84
85 @Test(expected = java.lang.IllegalArgumentException.class)
86 public void test_getNaturalLanguageTemplatesByLanguageCode_null_fail() {
87 (NaturalLanguageTemplateBoServiceImplGenTest.create(naturalLanguageTemplateBoServiceImpl, krmsAttributeDefinitionService)).test_getNaturalLanguageTemplatesByLanguageCode_null_fail();
88 }
89
90 @Test(expected = java.lang.IllegalArgumentException.class)
91 public void test_getNaturalLanguageTemplatesByNaturalLanguageUsage_null_fail() {
92 (NaturalLanguageTemplateBoServiceImplGenTest.create(naturalLanguageTemplateBoServiceImpl, krmsAttributeDefinitionService)).test_getNaturalLanguageTemplatesByNaturalLanguageUsage_null_fail();
93 }
94
95 @Test(expected = java.lang.IllegalArgumentException.class)
96 public void test_getNaturalLanguageTemplatesByType_null_fail() {
97 (NaturalLanguageTemplateBoServiceImplGenTest.create(naturalLanguageTemplateBoServiceImpl, krmsAttributeDefinitionService)).test_getNaturalLanguageTemplatesByType_null_fail();
98 }
99
100 @Test(expected = java.lang.IllegalArgumentException.class)
101 public void test_getNaturalLanguageTemplatesByTemplate_null_fail() {
102 (NaturalLanguageTemplateBoServiceImplGenTest.create(naturalLanguageTemplateBoServiceImpl, krmsAttributeDefinitionService)).test_getNaturalLanguageTemplatesByTemplate_null_fail();
103 }
104
105 @Test
106 public void test_from_null_yields_null() {
107 (NaturalLanguageTemplateBoServiceImplGenTest.create(naturalLanguageTemplateBoServiceImpl, krmsAttributeDefinitionService)).test_from_null_yields_null();
108 }
109
110 @Test
111 public void test_to() {
112 (NaturalLanguageTemplateBoServiceImplGenTest.create(naturalLanguageTemplateBoServiceImpl, krmsAttributeDefinitionService)).test_to();
113 }
114
115 @Test
116 public void test_from() {
117 (NaturalLanguageTemplateBoServiceImplGenTest.create(naturalLanguageTemplateBoServiceImpl, krmsAttributeDefinitionService)).test_from();
118 }
119
120 public void test_createNaturalLanguageTemplate() {
121 KrmsTypeIntegrationGenTest krmsTypeTest = new KrmsTypeIntegrationGenTest();
122 krmsTypeTest.setup();
123 krmsTypeTest.test_createKrmsType();
124 KrmsTypeDefinition krmsType = krmsTypeTest.getKrmsType();
125 NaturalLanguageUsageIntegrationGenTest naturalLanguageUsageTest = new NaturalLanguageUsageIntegrationGenTest();
126 naturalLanguageUsageTest.setup();
127 naturalLanguageUsageTest.test_createNaturalLanguageUsage();
128 NaturalLanguageUsage naturalLanguageUsage = naturalLanguageUsageTest.getNaturalLanguageUsage();
129 NaturalLanguageTemplateBoServiceImplGenTest test = NaturalLanguageTemplateBoServiceImplGenTest.create(naturalLanguageTemplateBoServiceImpl, krmsAttributeDefinitionService);
130 test.createNaturalLanguageTemplate(naturalLanguageUsage, krmsType);
131 naturalLanguageTemplate = test.getNaturalLanguageTemplate();
132 assert(naturalLanguageTemplate != null);
133 assert(naturalLanguageTemplate.getId() != null);
134 assert(naturalLanguageTemplate.getAttributes() != null && !naturalLanguageTemplate.getAttributes().isEmpty());
135 }
136
137 @Test(expected = java.lang.IllegalStateException.class)
138 public void test_createNaturalLanguageTemplate_fail_existing() {
139 test_createNaturalLanguageTemplate();
140 test_createNaturalLanguageTemplate();
141 }
142
143 @Test(expected = java.lang.IllegalArgumentException.class)
144 public void test_createNaturalLanguageTemplate_null_fail() {
145 (NaturalLanguageTemplateBoServiceImplGenTest.create(naturalLanguageTemplateBoServiceImpl, krmsAttributeDefinitionService)).test_createNaturalLanguageTemplate_null_fail();
146 }
147
148 public void test_getNaturalLanguageTemplate() {
149 test_createNaturalLanguageTemplate();
150 NaturalLanguageTemplate def = getNaturalLanguageTemplate();
151 NaturalLanguageTemplate def2 = naturalLanguageTemplateBoServiceImpl.getNaturalLanguageTemplate(def.getId());
152 assert(def2 != null);
153 assert(def2.equals(def));
154 }
155
156 public void test_updateNaturalLanguageTemplate() {
157 test_createNaturalLanguageTemplate();
158 NaturalLanguageTemplate def = getNaturalLanguageTemplate();
159 String id = def.getId();
160 assert(!"UpdateTest".equals(def.getTemplate()));
161 NaturalLanguageTemplateBo bo = naturalLanguageTemplateBoServiceImpl.from(def);
162 bo.setTemplate("UpdateTest");
163 naturalLanguageTemplateBoServiceImpl.updateNaturalLanguageTemplate(NaturalLanguageTemplate.Builder.create(bo).build());
164 NaturalLanguageTemplate def2 = naturalLanguageTemplateBoServiceImpl.getNaturalLanguageTemplate(id);
165 assert("UpdateTest".equals(def2.getTemplate()));
166 }
167
168 @Test(expected = java.lang.IllegalArgumentException.class)
169 public void test_updateNaturalLanguageTemplate_null_fail() {
170 (NaturalLanguageTemplateBoServiceImplGenTest.create(naturalLanguageTemplateBoServiceImpl, krmsAttributeDefinitionService)).test_updateNaturalLanguageTemplate_null_fail();
171 }
172
173 public void test_deleteNaturalLanguageTemplate() {
174 test_createNaturalLanguageTemplate();
175 NaturalLanguageTemplate def = getNaturalLanguageTemplate();
176 String id = def.getId();
177 naturalLanguageTemplateBoServiceImpl.deleteNaturalLanguageTemplate(id);
178 NaturalLanguageTemplate def2 = naturalLanguageTemplateBoServiceImpl.getNaturalLanguageTemplate(id);
179 assert(def2 == null);
180 }
181
182 @Test(expected = java.lang.IllegalArgumentException.class)
183 public void test_deleteNaturalLanguageTemplate_null_fail() {
184 (NaturalLanguageTemplateBoServiceImplGenTest.create(naturalLanguageTemplateBoServiceImpl, krmsAttributeDefinitionService)).test_deleteNaturalLanguageTemplate_null_fail();
185 }
186 }