View Javadoc
1   /**
2    * Copyright 2005-2014 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.apache.commons.collections.CollectionUtils;
19  import org.junit.Before;
20  import org.junit.Test;
21  import org.kuali.rice.krms.api.repository.language.NaturalLanguageTemplate;
22  import org.kuali.rice.krms.api.repository.language.NaturalLanguageUsage;
23  import org.kuali.rice.krms.test.AbstractBoTest;
24  
25  import java.util.List;
26  
27  /**
28   * @author Kuali Rice Team (rice.collab@kuali.org)
29   *
30   */
31  public final class NaturalLanguageUsageIntegrationGenTest extends AbstractBoTest{
32  
33      NaturalLanguageUsageBoServiceImpl naturalLanguageUsageBoServiceImpl;
34      NaturalLanguageTemplateBoServiceImpl naturalLanguageTemplateBoServiceImpl;
35      NaturalLanguageUsage naturalLanguageUsage;
36  
37      NaturalLanguageUsage getNaturalLanguageUsage() {
38          return naturalLanguageUsage;
39      }
40  
41      /**
42       * Note lower case u, do not override superclasses setUp
43       *
44       */
45      @Before
46      public void setup() {
47          naturalLanguageUsageBoServiceImpl = new NaturalLanguageUsageBoServiceImpl();
48          naturalLanguageUsageBoServiceImpl.setDataObjectService(getDataObjectService());
49  
50          // NOTE: this is not fully wired, we only need the BusinessObjectService for what we do with this impl
51          naturalLanguageTemplateBoServiceImpl = new NaturalLanguageTemplateBoServiceImpl();
52          naturalLanguageTemplateBoServiceImpl.setDataObjectService(getDataObjectService());
53      }
54  
55      @Test(expected = java.lang.IllegalArgumentException.class)
56      public void test_findNaturalLanguageUsagesByName_null_fail() {
57          (NaturalLanguageUsageBoServiceImplGenTest.create(naturalLanguageUsageBoServiceImpl)).test_findNaturalLanguageUsagesByName_null_fail();
58      }
59  
60      @Test(expected = java.lang.IllegalArgumentException.class)
61      public void test_findNaturalLanguageUsagesByDescription_null_fail() {
62          (NaturalLanguageUsageBoServiceImplGenTest.create(naturalLanguageUsageBoServiceImpl)).test_findNaturalLanguageUsagesByDescription_null_fail();
63      }
64  
65      @Test(expected = java.lang.IllegalArgumentException.class)
66      public void test_findNaturalLanguageUsagesByNamespace_null_fail() {
67          (NaturalLanguageUsageBoServiceImplGenTest.create(naturalLanguageUsageBoServiceImpl)).test_findNaturalLanguageUsagesByNamespace_null_fail();
68      }
69  
70      @Test
71      public void test_from_null_yields_null() {
72          (NaturalLanguageUsageBoServiceImplGenTest.create(naturalLanguageUsageBoServiceImpl)).test_from_null_yields_null();
73      }
74  
75      @Test
76      public void test_to() {
77          (NaturalLanguageUsageBoServiceImplGenTest.create(naturalLanguageUsageBoServiceImpl)).test_to();
78      }
79  
80      @Test
81      public void test_createNaturalLanguageUsage() {
82          NaturalLanguageUsageBoServiceImplGenTest test = NaturalLanguageUsageBoServiceImplGenTest.create(naturalLanguageUsageBoServiceImpl);
83          test.test_createNaturalLanguageUsage();
84          naturalLanguageUsage = test.getNaturalLanguageUsage();
85          assert(naturalLanguageUsage != null);
86          assert(naturalLanguageUsage.getId() != null);
87      }
88  
89      @Test
90      public void test_createNaturalLanguageUsageGeneratedId() {
91          NaturalLanguageUsageBoServiceImplGenTest test = NaturalLanguageUsageBoServiceImplGenTest.create(naturalLanguageUsageBoServiceImpl);
92          test.test_createNaturalLanguageUsageGeneratedId();
93          naturalLanguageUsage = test.getNaturalLanguageUsage();
94          assert(naturalLanguageUsage != null);
95          assert(naturalLanguageUsage.getId() != null);
96      }
97  
98      @Test(expected = java.lang.IllegalArgumentException.class)
99      public void test_createNaturalLanguageUsage_null_fail() {
100         (NaturalLanguageUsageBoServiceImplGenTest.create(naturalLanguageUsageBoServiceImpl)).test_createNaturalLanguageUsage_null_fail();
101     }
102 
103     @Test
104     public void test_getNaturalLanguageUsage() {
105         test_createNaturalLanguageUsage();
106         NaturalLanguageUsage def = getNaturalLanguageUsage();
107         NaturalLanguageUsage def2 = naturalLanguageUsageBoServiceImpl.getNaturalLanguageUsage(def.getId());
108         assert(def2 != null);
109         assert(def2.equals(def));
110     }
111 
112     @Test
113     public void test_updateNaturalLanguageUsage() {
114         test_createNaturalLanguageUsage();
115         NaturalLanguageUsage def = getNaturalLanguageUsage();
116         String id = def.getId();
117         assert(!"UpdateTest".equals(def.getName()));
118         NaturalLanguageUsageBo bo = naturalLanguageUsageBoServiceImpl.from(def);
119         bo.setName("UpdateTest");
120         naturalLanguageUsageBoServiceImpl.updateNaturalLanguageUsage(NaturalLanguageUsage.Builder.create(bo).build());
121         NaturalLanguageUsage def2 = naturalLanguageUsageBoServiceImpl.getNaturalLanguageUsage(id);
122         assert("UpdateTest".equals(def2.getName()));
123     }
124 
125     @Test(expected = java.lang.IllegalArgumentException.class)
126     public void test_updateNaturalLanguageUsage_null_fail() {
127         (NaturalLanguageUsageBoServiceImplGenTest.create(naturalLanguageUsageBoServiceImpl)).test_updateNaturalLanguageUsage_null_fail();
128     }
129 
130     @Test
131     public void test_deleteNaturalLanguageUsage() {
132         test_createNaturalLanguageUsage();
133         NaturalLanguageUsage def = getNaturalLanguageUsage();
134         String id = def.getId();
135 
136         // make sure there aren't any templates for this usage which will cause deleting the usage to fail
137         List<NaturalLanguageTemplate> templates =
138                 naturalLanguageTemplateBoServiceImpl.findNaturalLanguageTemplatesByNaturalLanguageUsage(id);
139 
140         if (!CollectionUtils.isEmpty(templates)) {
141             for (NaturalLanguageTemplate template : templates) {
142                 naturalLanguageTemplateBoServiceImpl.deleteNaturalLanguageTemplate(template.getId());
143             }
144         }
145 
146         naturalLanguageUsageBoServiceImpl.deleteNaturalLanguageUsage(id);
147         NaturalLanguageUsage def2 = naturalLanguageUsageBoServiceImpl.getNaturalLanguageUsage(id);
148         assert(def2 == null);
149     }
150 
151     @Test(expected = java.lang.IllegalArgumentException.class)
152     public void test_deleteNaturalLanguageUsage_null_fail() {
153         (NaturalLanguageUsageBoServiceImplGenTest.create(naturalLanguageUsageBoServiceImpl)).test_deleteNaturalLanguageUsage_null_fail();
154     }
155 
156     @Test(expected = java.lang.IllegalStateException.class)
157     public void test_createNaturalLanguageUsageDuplicateNamespaceAndName() {
158         NaturalLanguageUsageBoServiceImplGenTest test = NaturalLanguageUsageBoServiceImplGenTest.create(naturalLanguageUsageBoServiceImpl);
159         test.test_createNaturalLanguageUsageGeneratedId();
160         naturalLanguageUsage = test.getNaturalLanguageUsage();
161         assert(naturalLanguageUsage != null);
162         assert(naturalLanguageUsage.getId() != null);
163 
164         NaturalLanguageUsageBoServiceImplGenTest test2 = NaturalLanguageUsageBoServiceImplGenTest.create(naturalLanguageUsageBoServiceImpl);
165         test2.test_createNaturalLanguageUsageGeneratedId();
166         naturalLanguageUsage = test2.getNaturalLanguageUsage();
167     }
168 }