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  
17  package org.kuali.rice.krad.jpa;
18  
19  import org.junit.Test;
20  import org.kuali.rice.coreservice.impl.parameter.ParameterBo;
21  import org.kuali.rice.krad.bo.PersistableBusinessObjectExtension;
22  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
23  import org.kuali.rice.krad.service.LegacyDataAdapter;
24  import org.kuali.rice.krad.test.KRADTestCase;
25  import org.kuali.rice.krad.test.document.bo.Account;
26  import org.kuali.rice.krad.test.document.bo.AccountExtension;
27  import org.kuali.rice.krad.util.KRADUtils;
28  
29  import static org.junit.Assert.assertNotNull;
30  import static org.junit.Assert.assertTrue;
31  
32  public class LegacyDataAdapterTest extends KRADTestCase {
33  
34      private LegacyDataAdapter legacyDataAdapter;
35  
36      @Override
37      public void setUp() throws Exception {
38          super.setUp();
39          legacyDataAdapter = KRADServiceLocatorWeb.getLegacyDataAdapter();
40      }
41  
42      @Test
43      public void testGetPropertyType() throws Exception {
44          //Confirm simple nested property type works
45          ParameterBo param = KRADUtils.createNewObjectFromClass(ParameterBo.class);
46          Class propertyType = legacyDataAdapter.getPropertyType(param, "namespaceCode");
47          assertTrue("PropertyType is String",propertyType.isAssignableFrom(String.class));
48          //Confirm simple nested property type works
49          propertyType = legacyDataAdapter.getPropertyType(param, "component.name");
50          assertTrue("PropertyType is String",propertyType.isAssignableFrom(String.class));
51          //Confirm double nested property type works
52          propertyType =  legacyDataAdapter.getPropertyType(param, "component.namespace.name");
53          assertTrue("PropertyType is String",propertyType.isAssignableFrom(String.class));
54      }
55  
56      /**
57       * Verifies that new instances of the extension object are created properly when in Legacy mode.
58       * The {@link org.kuali.rice.krad.test.document.bo.Account} object has it's extension mapped both using the
59       * legacy KNS and non-Legacy KRAD approaches and it extends from PersistableBusinessObjectBase.
60       */
61      @Test
62      @Legacy
63      public void testGetExtension_Legacy() throws Exception {
64          testGetExtension();
65      }
66  
67      /**
68       * Verifies that new instances of the extension object are created properly when using KRAD.
69       * The {@link org.kuali.rice.krad.test.document.bo.Account} object has it's extension mapped both using the
70       * legacy KNS and non-Legacy KRAD approaches and it extends from PersistableBusinessObjectBase.
71       */
72      @Test
73      public void testGetExtension() throws Exception {
74          Account account = new Account();
75          Object extension = account.getExtension();
76          assertNotNull(extension);
77          assertTrue(extension instanceof AccountExtension);
78  
79          extension = legacyDataAdapter.getExtension(Account.class);
80          assertNotNull(extension);
81          assertTrue(extension instanceof AccountExtension);
82      }
83  
84  }