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.krad.data.DataObjectService;
22 import org.kuali.rice.krms.api.repository.NaturalLanguageTemplateGenTest;
23 import org.kuali.rice.krms.api.repository.language.NaturalLanguageTemplate;
24 import org.kuali.rice.krms.api.repository.language.NaturalLanguageUsage;
25 import org.kuali.rice.krms.api.repository.type.KrmsAttributeDefinition;
26 import org.kuali.rice.krms.api.repository.type.KrmsTypeDefinition;
27 import org.kuali.rice.krms.api.repository.type.KrmsTypeRepositoryService;
28 import org.mockito.runners.MockitoJUnitRunner;
29
30 import java.util.Map;
31
32 import static org.mockito.Mockito.mock;
33
34
35
36
37
38 @RunWith(MockitoJUnitRunner.class)
39 public class NaturalLanguageTemplateBoServiceImplGenTest {
40 private NaturalLanguageTemplateBoServiceImpl naturalLanguageTemplateBoServiceImpl;
41 private NaturalLanguageTemplate naturalLanguageTemplate;
42 private KrmsAttributeDefinitionService krmsAttributeDefinitionService;
43
44 NaturalLanguageTemplate getNaturalLanguageTemplate() {
45 return naturalLanguageTemplate;
46 }
47
48 public void setNaturalLanguageTemplateBoServiceImpl(NaturalLanguageTemplateBoServiceImpl impl) {
49 this.naturalLanguageTemplateBoServiceImpl = impl;
50 }
51
52 public void setKrmsAttributeDefinitionService(KrmsAttributeDefinitionService impl) {
53 krmsAttributeDefinitionService = impl;
54 }
55
56 public static org.kuali.rice.krms.impl.repository.NaturalLanguageTemplateBoServiceImplGenTest create(
57 NaturalLanguageTemplateBoServiceImpl nlTemplateBoService,
58 KrmsAttributeDefinitionService attributeDefService) {
59
60 org.kuali.rice.krms.impl.repository.NaturalLanguageTemplateBoServiceImplGenTest test =
61 new org.kuali.rice.krms.impl.repository.NaturalLanguageTemplateBoServiceImplGenTest();
62 test.setKrmsAttributeDefinitionService(attributeDefService);
63 test.setNaturalLanguageTemplateBoServiceImpl(nlTemplateBoService);
64 return test;
65 }
66
67 @Before
68 public void setUp() {
69 naturalLanguageTemplateBoServiceImpl = new NaturalLanguageTemplateBoServiceImpl();
70 KrmsAttributeDefinitionService mockAttributeService = mock(KrmsAttributeDefinitionService.class);
71 NaturalLanguageTemplateBo.setAttributeDefinitionService(mockAttributeService);
72 KrmsTypeRepositoryService mockTypeRepositoryService = mock(KrmsTypeRepositoryService.class);
73 NaturalLanguageTemplateBo.setTypeRepositoryService(mockTypeRepositoryService);
74 naturalLanguageTemplateBoServiceImpl.setAttributeDefinitionService(mockAttributeService);
75 naturalLanguageTemplateBoServiceImpl.setDataObjectService(mock(DataObjectService.class));
76 }
77
78 @Test(expected = java.lang.IllegalArgumentException.class)
79 public void test_getNaturalLanguageTemplatesByAttributes_null_fail() {
80 naturalLanguageTemplateBoServiceImpl.findNaturalLanguageTemplatesByAttributes(null);
81 }
82
83 @Test(expected = java.lang.IllegalArgumentException.class)
84 public void test_getNaturalLanguageTemplatesByLanguageCode_null_fail() {
85 naturalLanguageTemplateBoServiceImpl.findNaturalLanguageTemplatesByLanguageCode(null);
86 }
87
88 @Test(expected = java.lang.IllegalArgumentException.class)
89 public void test_getNaturalLanguageTemplatesByNaturalLanguageUsage_null_fail() {
90 naturalLanguageTemplateBoServiceImpl.findNaturalLanguageTemplatesByNaturalLanguageUsage(null);
91 }
92
93 @Test(expected = java.lang.IllegalArgumentException.class)
94 public void test_getNaturalLanguageTemplatesByType_null_fail() {
95 naturalLanguageTemplateBoServiceImpl.findNaturalLanguageTemplatesByType(null);
96 }
97
98 @Test(expected = java.lang.IllegalArgumentException.class)
99 public void test_getNaturalLanguageTemplatesByTemplate_null_fail() {
100 naturalLanguageTemplateBoServiceImpl.findNaturalLanguageTemplatesByTemplate(null);
101 }
102
103 @Test
104 public void test_from_null_yields_null() {
105 assert(naturalLanguageTemplateBoServiceImpl.from(null) == null);
106 }
107
108 @Test
109 public void test_from() {
110 NaturalLanguageTemplate def = NaturalLanguageTemplateGenTest.buildFullNaturalLanguageTemplate();
111 NaturalLanguageTemplateBo naturalLanguageTemplateBo = naturalLanguageTemplateBoServiceImpl.from(def);
112 assert(naturalLanguageTemplateBo.getLanguageCode().equals(def.getLanguageCode()));
113 assert(naturalLanguageTemplateBo.getNaturalLanguageUsageId().equals(def.getNaturalLanguageUsageId()));
114 assert(naturalLanguageTemplateBo.getTypeId().equals(def.getTypeId()));
115 assert(naturalLanguageTemplateBo.getTemplate().equals(def.getTemplate()));
116 assert(naturalLanguageTemplateBo.getId().equals(def.getId()));
117 }
118
119 @Test
120 public void test_to() {
121 NaturalLanguageTemplate def = NaturalLanguageTemplateGenTest.buildFullNaturalLanguageTemplate();
122 NaturalLanguageTemplateBo naturalLanguageTemplateBo = naturalLanguageTemplateBoServiceImpl.from(def);
123 NaturalLanguageTemplate def2 = NaturalLanguageTemplateBo.to(naturalLanguageTemplateBo);
124 assert(def.equals(def2));
125 }
126
127 @Test
128 public void test_createNaturalLanguageTemplate() {
129 NaturalLanguageTemplate def = NaturalLanguageTemplateGenTest.buildFullNaturalLanguageTemplate();
130 naturalLanguageTemplate = naturalLanguageTemplateBoServiceImpl.createNaturalLanguageTemplate(def);
131 }
132
133 @Test(expected = java.lang.IllegalArgumentException.class)
134 public void test_createNaturalLanguageTemplate_null_fail() {
135 naturalLanguageTemplateBoServiceImpl.createNaturalLanguageTemplate(null);
136 }
137
138 @Test(expected = java.lang.IllegalArgumentException.class)
139 public void test_updateNaturalLanguageTemplate_null_fail() {
140 naturalLanguageTemplateBoServiceImpl.updateNaturalLanguageTemplate(null);
141 }
142
143 @Test(expected = java.lang.IllegalArgumentException.class)
144 public void test_deleteNaturalLanguageTemplate_null_fail() {
145 naturalLanguageTemplateBoServiceImpl.deleteNaturalLanguageTemplate(null);
146 }
147
148 void createNaturalLanguageTemplate(NaturalLanguageUsage naturalLanguageUsage, KrmsTypeDefinition type) {
149 NaturalLanguageTemplate def = NaturalLanguageTemplateGenTest.buildFullNaturalLanguageTemplate(naturalLanguageUsage, type);
150
151 for (Map.Entry<String, String> attributeEntry : def.getAttributes().entrySet()) {
152
153 KrmsAttributeDefinition attrDef = krmsAttributeDefinitionService.getAttributeDefinitionByNameAndNamespace(
154 attributeEntry.getKey(), type.getNamespace());
155
156
157
158 KrmsAttributeDefinition.Builder attrDefBuilder =
159 KrmsAttributeDefinition.Builder.create(null, attributeEntry.getKey(), type.getNamespace());
160 krmsAttributeDefinitionService.createAttributeDefinition(attrDefBuilder.build());
161
162 }
163
164 naturalLanguageTemplate = naturalLanguageTemplateBoServiceImpl.createNaturalLanguageTemplate(def);
165 }
166
167 }