View Javadoc

1   /**
2    * Copyright 2005-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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.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   * @author Kuali Rice Team (rice.collab@kuali.org)
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; // TODO gen
42  
43      NaturalLanguageTemplate getNaturalLanguageTemplate() {
44          return naturalLanguageTemplate;
45      }
46  
47      /**
48       * Note lower case u, do not override superclasses setUp
49       *
50       */
51      @Before
52      public void setup() {
53          naturalLanguageTemplateBoServiceImpl = new NaturalLanguageTemplateBoServiceImpl();
54          naturalLanguageTemplateBoServiceImpl.setNaturalLanguageTemplater(newStringReplaceTemplater()); // TODO gen?
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() { // TODO gen
117         (NaturalLanguageTemplateBoServiceImplGenTest.create(naturalLanguageTemplateBoServiceImpl, krmsAttributeDefinitionService)).test_from();
118     }
119 
120     public void test_createNaturalLanguageTemplate() {
121         KrmsTypeIntegrationGenTest krmsTypeTest = new KrmsTypeIntegrationGenTest();
122         krmsTypeTest.setup(); // Note lowercase u
123         krmsTypeTest.test_createKrmsType();
124         KrmsTypeDefinition krmsType = krmsTypeTest.getKrmsType();
125         NaturalLanguageUsageIntegrationGenTest naturalLanguageUsageTest = new NaturalLanguageUsageIntegrationGenTest();
126         naturalLanguageUsageTest.setup(); // Note lowercase u
127         naturalLanguageUsageTest.test_createNaturalLanguageUsage();
128         NaturalLanguageUsage naturalLanguageUsage = naturalLanguageUsageTest.getNaturalLanguageUsage();
129         NaturalLanguageTemplateBoServiceImplGenTest test = NaturalLanguageTemplateBoServiceImplGenTest.create(naturalLanguageTemplateBoServiceImpl, krmsAttributeDefinitionService);
130         test.createNaturalLanguageTemplate(naturalLanguageUsage, krmsType); // TODO gen order of params
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 // TODO gen use mutliple catches
138     public void test_createNaturalLanguageTemplate_fail_existing() {
139         test_createNaturalLanguageTemplate();
140         try {
141             test_createNaturalLanguageTemplate();
142         } catch (IllegalStateException ise) {
143             return; // local
144         } catch (org.springframework.dao.DataIntegrityViolationException dive) {
145             return; // ci
146         }
147         assert(false); // exception should be thrown
148     }
149 
150     @Test(expected = java.lang.IllegalArgumentException.class)
151     public void test_createNaturalLanguageTemplate_null_fail() {
152         (NaturalLanguageTemplateBoServiceImplGenTest.create(naturalLanguageTemplateBoServiceImpl, krmsAttributeDefinitionService)).test_createNaturalLanguageTemplate_null_fail();
153     }
154 
155     public void test_getNaturalLanguageTemplate() {
156         test_createNaturalLanguageTemplate();
157         NaturalLanguageTemplate def = getNaturalLanguageTemplate();
158         NaturalLanguageTemplate def2 = naturalLanguageTemplateBoServiceImpl.getNaturalLanguageTemplate(def.getId());
159         assert(def2 != null);
160         assert(def2.equals(def));
161     }
162 
163     public void test_updateNaturalLanguageTemplate() {
164         test_createNaturalLanguageTemplate();
165         NaturalLanguageTemplate def = getNaturalLanguageTemplate();
166         String id = def.getId();
167         assert(!"UpdateTest".equals(def.getTemplate()));
168         NaturalLanguageTemplateBo bo = naturalLanguageTemplateBoServiceImpl.from(def);
169         bo.setTemplate("UpdateTest");
170         naturalLanguageTemplateBoServiceImpl.updateNaturalLanguageTemplate(NaturalLanguageTemplate.Builder.create(bo).build());
171         NaturalLanguageTemplate def2 = naturalLanguageTemplateBoServiceImpl.getNaturalLanguageTemplate(id);
172         assert("UpdateTest".equals(def2.getTemplate()));
173     }
174 
175     @Test(expected = java.lang.IllegalArgumentException.class)
176     public void test_updateNaturalLanguageTemplate_null_fail() {
177         (NaturalLanguageTemplateBoServiceImplGenTest.create(naturalLanguageTemplateBoServiceImpl, krmsAttributeDefinitionService)).test_updateNaturalLanguageTemplate_null_fail();
178     }
179 
180     public void test_deleteNaturalLanguageTemplate() {
181         test_createNaturalLanguageTemplate();
182         NaturalLanguageTemplate def = getNaturalLanguageTemplate();
183         String id = def.getId();
184         naturalLanguageTemplateBoServiceImpl.deleteNaturalLanguageTemplate(id);
185         NaturalLanguageTemplate def2 = naturalLanguageTemplateBoServiceImpl.getNaturalLanguageTemplate(id);
186         assert(def2 == null);
187     }
188 
189     @Test(expected = java.lang.IllegalArgumentException.class)
190     public void test_deleteNaturalLanguageTemplate_null_fail() {
191         (NaturalLanguageTemplateBoServiceImplGenTest.create(naturalLanguageTemplateBoServiceImpl, krmsAttributeDefinitionService)).test_deleteNaturalLanguageTemplate_null_fail();
192     }
193 }