001/**
002 * Copyright 2005-2016 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.krad.service.impl;
017
018import org.apache.ojb.broker.metadata.ClassDescriptor;
019import org.apache.ojb.broker.metadata.MetadataManager;
020import org.junit.Before;
021import org.junit.Test;
022import org.junit.runner.RunWith;
023import org.kuali.rice.core.api.CoreConstants;
024import org.kuali.rice.core.api.config.property.ConfigContext;
025import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
026import org.kuali.rice.core.api.resourceloader.ResourceLoader;
027import org.kuali.rice.core.framework.config.property.SimpleConfig;
028import org.kuali.rice.core.framework.resourceloader.BeanFactoryResourceLoader;
029import org.kuali.rice.krad.bo.PersistableBusinessObject;
030import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
031import org.kuali.rice.krad.data.metadata.MetadataRepository;
032import org.kuali.rice.krad.document.Document;
033import org.kuali.rice.krad.document.DocumentBase;
034import org.kuali.rice.krad.service.DataDictionaryService;
035import org.kuali.rice.krad.service.LegacyDataAdapter;
036import org.kuali.rice.krad.util.KRADConstants;
037import org.kuali.rice.krad.util.LegacyUtils;
038import org.mockito.InjectMocks;
039import org.mockito.Mock;
040import org.mockito.runners.MockitoJUnitRunner;
041import org.springframework.beans.factory.support.StaticListableBeanFactory;
042
043import javax.xml.namespace.QName;
044import java.io.Serializable;
045import java.util.ArrayList;
046import java.util.HashMap;
047import java.util.concurrent.Callable;
048
049import static org.junit.Assert.assertEquals;
050import static org.junit.Assert.assertNull;
051import static org.mockito.Matchers.*;
052import static org.mockito.Mockito.verify;
053import static org.mockito.Mockito.verifyZeroInteractions;
054
055/**
056 * Unit test for the {@link LegacyDataAdapterImpl}. Tests that the various methods delegate to KNS or KRAD under the
057 * appropriate circumstances. Also tests some of the internal code in this class is functioning properly.
058 *
059 * @author Kuali Rice Team (rice.collab@kuali.org)
060 */
061@RunWith(MockitoJUnitRunner.class)
062public class LegacyDataAdapterImplTest {
063
064    @Mock private LegacyDataAdapter knsLegacyDataAdapter;
065    @Mock private LegacyDataAdapter kradLegacyDataAdapter;
066    @Mock private DataDictionaryService dataDictionaryService;
067    @Mock private MetadataRepository metadataRepository;
068
069    @InjectMocks private LegacyDataAdapterImpl lda = new LegacyDataAdapterImpl();
070
071    @Before
072    public void setup() throws Exception {
073        GlobalResourceLoader.stop();
074
075        SimpleConfig config = new SimpleConfig();
076        config.putProperty(CoreConstants.Config.APPLICATION_ID, getClass().getName());
077        ConfigContext.init(config);
078        ConfigContext.getCurrentContextConfig().removeProperty(KRADConstants.Config.ENABLE_LEGACY_DATA_FRAMEWORK);
079        ConfigContext.getCurrentContextConfig().removeProperty(KRADConstants.Config.KNS_ENABLED);
080
081        StaticListableBeanFactory testBf = new StaticListableBeanFactory();
082        testBf.addBean("metadataRepository", metadataRepository);
083        testBf.addBean("dataDictionaryService", dataDictionaryService);
084        testBf.addBean("knsLegacyDataAdapter", knsLegacyDataAdapter);
085        testBf.addBean("kradLegacyDataAdapter", kradLegacyDataAdapter);
086
087        ResourceLoader rl = new BeanFactoryResourceLoader(new QName(getClass().getName()), testBf);
088        GlobalResourceLoader.addResourceLoader(rl);
089        GlobalResourceLoader.start();
090
091        MetadataManager mm = MetadataManager.getInstance();
092
093        // register Legacy object
094        ClassDescriptor legacyDescriptor = new ClassDescriptor(mm.getGlobalRepository());
095        legacyDescriptor.setClassOfObject(Legacy.class);
096        mm.getGlobalRepository().put(Legacy.class, legacyDescriptor);
097
098        // register LegacyDocument object
099        ClassDescriptor legacyDocumentDescriptor = new ClassDescriptor(mm.getGlobalRepository());
100        legacyDocumentDescriptor.setClassOfObject(LegacyDocument.class);
101        mm.getGlobalRepository().put(LegacyDocument.class, legacyDocumentDescriptor);
102    }
103
104    protected void enableLegacy() {
105        ConfigContext.getCurrentContextConfig().putProperty(KRADConstants.Config.KNS_ENABLED, "true");
106    }
107
108    protected NonLegacy newNonLegacyObject() {
109        return new NonLegacy();
110    }
111
112    protected NonLegacyPersistableBusinessObject newNonLegacyPersistableBusinessObject() {
113        return new NonLegacyPersistableBusinessObject();
114    }
115
116    protected Legacy newLegacyObject() {
117        return new Legacy();
118    }
119
120    protected NonLegacyDocument newNonLegacyDocument() {
121        return new NonLegacyDocument();
122    }
123
124    protected LegacyDocument newLegacyDocument() {
125        return new LegacyDocument();
126    }
127
128    @Test
129    public void testSave() throws Exception {
130        Serializable object = newNonLegacyObject();
131        lda.save(object);
132        verify(kradLegacyDataAdapter).save(object);
133        verifyZeroInteractions(knsLegacyDataAdapter);
134    }
135
136    @Test
137    public void testSave_Legacy() throws Exception {
138        enableLegacy();
139        PersistableBusinessObject object = newLegacyObject();
140        lda.save(object);
141        verify(knsLegacyDataAdapter).save(object);
142        verifyZeroInteractions(kradLegacyDataAdapter);
143    }
144
145    @Test
146    public void testLinkAndSave() throws Exception {
147        Serializable object = newNonLegacyObject();
148        lda.linkAndSave(object);
149        verify(kradLegacyDataAdapter).linkAndSave(object);
150        verifyZeroInteractions(knsLegacyDataAdapter);
151    }
152
153    @Test
154    public void testLinkAndSave_Legacy() throws Exception {
155        enableLegacy();
156        Serializable object = newLegacyObject();
157        lda.linkAndSave(object);
158        verify(knsLegacyDataAdapter).linkAndSave(object);
159        verifyZeroInteractions(kradLegacyDataAdapter);
160    }
161
162    @Test
163    public void testSaveDocument() throws Exception {
164        Document document = newNonLegacyDocument();
165        lda.saveDocument(document);
166        verify(kradLegacyDataAdapter).saveDocument(document);
167        verifyZeroInteractions(knsLegacyDataAdapter);
168    }
169
170    @Test
171    public void testSaveDocument_Legacy() throws Exception {
172        enableLegacy();
173        Document document = newLegacyDocument();
174        lda.saveDocument(document);
175        verify(knsLegacyDataAdapter).saveDocument(document);
176        verifyZeroInteractions(kradLegacyDataAdapter);
177    }
178
179    @Test
180    public void testFindByPrimaryKey() throws Exception {
181        lda.findByPrimaryKey(NonLegacy.class, new HashMap<String, Object>());
182        verify(kradLegacyDataAdapter).findByPrimaryKey(eq(NonLegacy.class), anyMapOf(String.class, Object.class));
183        verifyZeroInteractions(knsLegacyDataAdapter);
184    }
185
186    @Test
187    public void testFindByPrimaryKey_Legacy() throws Exception {
188        enableLegacy();
189        lda.findByPrimaryKey(Legacy.class, new HashMap<String, Object>());
190        verify(knsLegacyDataAdapter).findByPrimaryKey(eq(Legacy.class), anyMapOf(String.class, Object.class));
191        verifyZeroInteractions(kradLegacyDataAdapter);
192    }
193
194    @Test
195    public void testFindBySinglePrimaryKey() throws Exception {
196        lda.findBySinglePrimaryKey(NonLegacy.class, new Object());
197        verify(kradLegacyDataAdapter).findBySinglePrimaryKey(eq(NonLegacy.class), anyObject());
198        verifyZeroInteractions(knsLegacyDataAdapter);
199    }
200
201    @Test
202    public void testFindBySinglePrimaryKey_Legacy() throws Exception {
203        enableLegacy();
204        lda.findBySinglePrimaryKey(Legacy.class, new Object());
205        verify(knsLegacyDataAdapter).findBySinglePrimaryKey(eq(Legacy.class), anyObject());
206        verifyZeroInteractions(kradLegacyDataAdapter);
207    }
208
209    @Test
210    public void testDelete() throws Exception {
211        Object object = newNonLegacyObject();
212        lda.delete(object);
213        verify(kradLegacyDataAdapter).delete(eq(object));
214        verifyZeroInteractions(knsLegacyDataAdapter);
215    }
216
217    @Test
218    public void testDelete_Legacy() throws Exception {
219        enableLegacy();
220        Object object = newLegacyObject();
221        lda.delete(object);
222        verify(knsLegacyDataAdapter).delete(eq(object));
223        verifyZeroInteractions(kradLegacyDataAdapter);
224    }
225
226    @Test
227    public void testDeleteMatching() throws Exception {
228        lda.deleteMatching(NonLegacy.class, new HashMap<String, String>());
229        verify(kradLegacyDataAdapter).deleteMatching(eq(NonLegacy.class), anyMapOf(String.class, String.class));
230        verifyZeroInteractions(knsLegacyDataAdapter);
231    }
232
233    @Test
234    public void testDeleteMatching_Legacy() throws Exception {
235        enableLegacy();
236        lda.deleteMatching(Legacy.class, new HashMap<String, String>());
237        verify(knsLegacyDataAdapter).deleteMatching(eq(Legacy.class), anyMapOf(String.class, String.class));
238        verifyZeroInteractions(kradLegacyDataAdapter);
239    }
240
241    @Test
242    public void testRetrieve() throws Exception {
243        Object object = newNonLegacyObject();
244        lda.retrieve(object);
245        verify(kradLegacyDataAdapter).retrieve(eq(object));
246        verifyZeroInteractions(knsLegacyDataAdapter);
247    }
248
249    @Test
250    public void testRetrieve_Legacy() throws Exception {
251        enableLegacy();
252        Object object = newLegacyObject();
253        lda.retrieve(object);
254        verify(knsLegacyDataAdapter).retrieve(eq(object));
255        verifyZeroInteractions(kradLegacyDataAdapter);
256    }
257
258    @Test
259    public void testFindAll() throws Exception {
260        lda.findAll(NonLegacy.class);
261        verify(kradLegacyDataAdapter).findAll(eq(NonLegacy.class));
262        verifyZeroInteractions(knsLegacyDataAdapter);
263    }
264
265    @Test
266    public void testFindAll_Legacy() throws Exception {
267        enableLegacy();
268        lda.findAll(Legacy.class);
269        verify(knsLegacyDataAdapter).findAll(eq(Legacy.class));;
270        verifyZeroInteractions(kradLegacyDataAdapter);
271    }
272
273    @Test
274    public void testFindMatching() throws Exception {
275        lda.findMatching(NonLegacy.class, new HashMap<String, String>());
276        verify(kradLegacyDataAdapter).findMatching(eq(NonLegacy.class), anyMapOf(String.class, String.class));
277        verifyZeroInteractions(knsLegacyDataAdapter);
278    }
279
280    @Test
281    public void testFindMatching_Legacy() throws Exception {
282        enableLegacy();
283        lda.findMatching(Legacy.class, new HashMap<String, String>());
284        verify(knsLegacyDataAdapter).findMatching(eq(Legacy.class), anyMapOf(String.class, String.class));
285        verifyZeroInteractions(kradLegacyDataAdapter);
286    }
287
288
289    @Test
290    public void testFindMatchingOrderBy() throws Exception {
291        lda.findMatchingOrderBy(NonLegacy.class, new HashMap<String, String>(), "a", true);
292        verify(kradLegacyDataAdapter).findMatchingOrderBy(eq(NonLegacy.class), anyMapOf(String.class, String.class), eq(
293                "a"), eq(Boolean.TRUE));
294        verifyZeroInteractions(knsLegacyDataAdapter);
295    }
296
297    @Test
298    public void testFindMatchingOrderBy_Legacy() throws Exception {
299        enableLegacy();
300        lda.findMatchingOrderBy(Legacy.class, new HashMap<String, String>(), "a", true);
301        verify(knsLegacyDataAdapter).findMatchingOrderBy(eq(Legacy.class), anyMapOf(String.class, String.class), eq(
302                "a"), eq(Boolean.TRUE));
303        verifyZeroInteractions(kradLegacyDataAdapter);
304    }
305
306
307    @Test
308    public void testGetPrimaryKeyFieldValues() throws Exception {
309        Object object = newNonLegacyObject();
310        lda.getPrimaryKeyFieldValues(object);
311        verify(kradLegacyDataAdapter).getPrimaryKeyFieldValues(eq(object));
312        verifyZeroInteractions(knsLegacyDataAdapter);
313    }
314
315    @Test
316    public void testGetPrimaryKeyFieldValues_Legacy() throws Exception {
317        enableLegacy();
318        Object object = newLegacyObject();
319        lda.getPrimaryKeyFieldValues(object);
320        verify(knsLegacyDataAdapter).getPrimaryKeyFieldValues(eq(object));
321        verifyZeroInteractions(kradLegacyDataAdapter);
322    }
323
324    @Test
325    public void testRetrieveNonKeyFields() throws Exception {
326        Object object = newNonLegacyObject();
327        lda.retrieveNonKeyFields(object);
328        verify(kradLegacyDataAdapter).retrieveNonKeyFields(eq(object));
329        verifyZeroInteractions(knsLegacyDataAdapter);
330    }
331
332    @Test
333    public void testRetrieveNonKeyFields_Legacy() throws Exception {
334        enableLegacy();
335        Object object = newLegacyObject();
336        lda.retrieveNonKeyFields(object);
337        verify(knsLegacyDataAdapter).retrieveNonKeyFields(eq(object));
338        verifyZeroInteractions(kradLegacyDataAdapter);
339    }
340
341    @Test
342    public void testRetrieveReferenceObject() throws Exception {
343        Object object = newNonLegacyObject();
344        lda.retrieveReferenceObject(object, "blah");
345        verify(kradLegacyDataAdapter).retrieveReferenceObject(eq(object), eq("blah"));
346        verifyZeroInteractions(knsLegacyDataAdapter);
347    }
348
349    @Test
350    public void testRetrieveReferenceObject_Legacy() throws Exception {
351        enableLegacy();
352        Object object = newLegacyObject();
353        lda.retrieveReferenceObject(object, "blah");
354        verify(knsLegacyDataAdapter).retrieveReferenceObject(eq(object), eq("blah"));
355        verifyZeroInteractions(kradLegacyDataAdapter);
356    }
357
358    @Test
359    public void testRefreshAllNonUpdatingReferences() throws Exception {
360        Object object = newNonLegacyObject();
361        lda.refreshAllNonUpdatingReferences(object);
362        verify(kradLegacyDataAdapter).refreshAllNonUpdatingReferences(eq(object));
363        verifyZeroInteractions(knsLegacyDataAdapter);
364    }
365
366    @Test
367    public void testRefreshAllNonUpdatingReferences_Legacy() throws Exception {
368        enableLegacy();
369        Object object = newLegacyObject();
370        lda.refreshAllNonUpdatingReferences(object);
371        verify(knsLegacyDataAdapter).refreshAllNonUpdatingReferences(eq(object));
372        verifyZeroInteractions(kradLegacyDataAdapter);
373    }
374
375
376    @Test
377    public void testIsProxied() throws Exception {
378        Object object = newNonLegacyObject();
379        lda.isProxied(object);
380        verify(kradLegacyDataAdapter).isProxied(eq(object));
381        verifyZeroInteractions(knsLegacyDataAdapter);
382    }
383
384    @Test
385    public void testIsProxied_Legacy() throws Exception {
386        enableLegacy();
387        Object object = newLegacyObject();
388        lda.isProxied(object);
389        verify(knsLegacyDataAdapter).isProxied(eq(object));
390        verifyZeroInteractions(kradLegacyDataAdapter);
391    }
392
393
394    @Test
395    public void testResolveProxy() throws Exception {
396        Object object = newNonLegacyObject();
397        lda.resolveProxy(object);
398        verify(kradLegacyDataAdapter).resolveProxy(eq(object));
399        verifyZeroInteractions(knsLegacyDataAdapter);
400    }
401
402    @Test
403    public void testResolveProxy_Legacy() throws Exception {
404        enableLegacy();
405        Object object = newLegacyObject();
406        lda.resolveProxy(object);
407        verify(knsLegacyDataAdapter).resolveProxy(eq(object));
408        verifyZeroInteractions(kradLegacyDataAdapter);
409    }
410
411    @Test
412    public void testFindCollectionBySearchHelper() throws Exception {
413        lda.findCollectionBySearchHelper(NonLegacy.class, new HashMap<String, String>(), true, true, 50);
414        verify(kradLegacyDataAdapter).findCollectionBySearchHelper(eq(NonLegacy.class), anyMapOf(String.class,
415                String.class), eq(true), eq(true), eq(50));
416        verifyZeroInteractions(knsLegacyDataAdapter);
417    }
418
419    @Test
420    public void testFindCollectionBySearchHelper_Legacy() throws Exception {
421        enableLegacy();
422        lda.findCollectionBySearchHelper(Legacy.class, new HashMap<String, String>(), true, true, 50);
423        verify(knsLegacyDataAdapter).findCollectionBySearchHelper(eq(Legacy.class), anyMapOf(String.class,
424                String.class), eq(true), eq(true), eq(50));
425        verifyZeroInteractions(kradLegacyDataAdapter);
426    }
427
428    @Test
429    public void testFindObjectBySearch() throws Exception {
430        lda.findObjectBySearch(NonLegacy.class, new HashMap<String, String>());
431        verify(kradLegacyDataAdapter).findObjectBySearch(eq(NonLegacy.class), anyMapOf(String.class, String.class));
432        verifyZeroInteractions(knsLegacyDataAdapter);
433    }
434
435    @Test
436    public void testFindObjectBySearch_Legacy() throws Exception {
437        enableLegacy();
438        lda.findObjectBySearch(Legacy.class, new HashMap<String, String>());
439        verify(knsLegacyDataAdapter).findObjectBySearch(eq(Legacy.class), anyMapOf(String.class, String.class));
440        verifyZeroInteractions(kradLegacyDataAdapter);
441    }
442
443    @Test
444    public void testAllPrimaryKeyValuesPresentAndNotWildcard() throws Exception {
445        lda.allPrimaryKeyValuesPresentAndNotWildcard(NonLegacy.class, new HashMap<String, String>());
446        verify(kradLegacyDataAdapter).allPrimaryKeyValuesPresentAndNotWildcard(eq(NonLegacy.class), anyMapOf(
447                String.class, String.class));
448        verifyZeroInteractions(knsLegacyDataAdapter);
449    }
450
451    @Test
452    public void testAllPrimaryKeyValuesPresentAndNotWildcard_Legacy() throws Exception {
453        enableLegacy();
454        lda.allPrimaryKeyValuesPresentAndNotWildcard(Legacy.class, new HashMap<String, String>());
455        verify(knsLegacyDataAdapter).allPrimaryKeyValuesPresentAndNotWildcard(eq(Legacy.class), anyMapOf(String.class, String.class));
456        verifyZeroInteractions(kradLegacyDataAdapter);
457    }
458
459    @Test
460    public void testListPrimaryKeyFieldNames() throws Exception {
461        lda.listPrimaryKeyFieldNames(NonLegacy.class);
462        verify(kradLegacyDataAdapter).listPrimaryKeyFieldNames(eq(NonLegacy.class));
463        verifyZeroInteractions(knsLegacyDataAdapter);
464    }
465
466    @Test
467    public void testListPrimaryKeyFieldNames_Legacy() throws Exception {
468        enableLegacy();
469        lda.listPrimaryKeyFieldNames(Legacy.class);
470        verify(knsLegacyDataAdapter).listPrimaryKeyFieldNames(eq(Legacy.class));
471        verifyZeroInteractions(kradLegacyDataAdapter);
472    }
473
474    @Test
475    public void testDetermineCollectionObjectType() throws Exception {
476        lda.determineCollectionObjectType(NonLegacy.class, "blah");
477        verify(kradLegacyDataAdapter).determineCollectionObjectType(eq(NonLegacy.class), eq("blah"));
478        verifyZeroInteractions(knsLegacyDataAdapter);
479    }
480
481    @Test
482    public void testDetermineCollectionObjectType_Legacy() throws Exception {
483        enableLegacy();
484        lda.determineCollectionObjectType(Legacy.class, "blah");
485        verify(knsLegacyDataAdapter).determineCollectionObjectType(eq(Legacy.class), eq("blah"));
486        verifyZeroInteractions(kradLegacyDataAdapter);
487    }
488
489    @Test
490    public void testHasReference() throws Exception {
491        lda.hasReference(NonLegacy.class, "blah");
492        verify(kradLegacyDataAdapter).hasReference(eq(NonLegacy.class), eq("blah"));
493        verifyZeroInteractions(knsLegacyDataAdapter);
494    }
495
496    @Test
497    public void testHasReference_Legacy() throws Exception {
498        enableLegacy();
499        lda.hasReference(Legacy.class, "blah");
500        verify(knsLegacyDataAdapter).hasReference(eq(Legacy.class), eq("blah"));
501        verifyZeroInteractions(kradLegacyDataAdapter);
502    }
503
504    @Test
505    public void testHasCollection() throws Exception {
506        lda.hasCollection(NonLegacy.class, "blah");
507        verify(kradLegacyDataAdapter).hasCollection(eq(NonLegacy.class), eq("blah"));
508        verifyZeroInteractions(knsLegacyDataAdapter);
509    }
510
511    @Test
512    public void testHasCollection_Legacy() throws Exception {
513        enableLegacy();
514        lda.hasCollection(Legacy.class, "blah");
515        verify(knsLegacyDataAdapter).hasCollection(eq(Legacy.class), eq("blah"));
516        verifyZeroInteractions(kradLegacyDataAdapter);
517    }
518
519    @Test
520    public void testIsExtensionAttribute() throws Exception {
521        lda.isExtensionAttribute(NonLegacy.class, "blah", NonLegacy.class);
522        verify(kradLegacyDataAdapter).isExtensionAttribute(eq(NonLegacy.class), eq("blah"), eq(NonLegacy.class));
523        verifyZeroInteractions(knsLegacyDataAdapter);
524    }
525
526    @Test
527    public void testIsExtensionAttribute_Legacy() throws Exception {
528        enableLegacy();
529        lda.isExtensionAttribute(Legacy.class, "blah", Legacy.class);
530        verify(knsLegacyDataAdapter).isExtensionAttribute(eq(Legacy.class), eq("blah"), eq(Legacy.class));
531        verifyZeroInteractions(kradLegacyDataAdapter);
532    }
533
534    @Test
535    public void testGetExtensionAttributeClass() throws Exception {
536        lda.getExtensionAttributeClass(NonLegacy.class, "blah");
537        verify(kradLegacyDataAdapter).getExtensionAttributeClass(eq(NonLegacy.class), eq("blah"));
538        verifyZeroInteractions(knsLegacyDataAdapter);
539    }
540
541    @Test
542    public void testGetExtensionAttributeClass_Legacy() throws Exception {
543        enableLegacy();
544        lda.getExtensionAttributeClass(Legacy.class, "blah");
545        verify(knsLegacyDataAdapter).getExtensionAttributeClass(eq(Legacy.class), eq("blah"));
546        verifyZeroInteractions(kradLegacyDataAdapter);
547    }
548
549    @Test
550    public void testGetPrimaryKeyFieldValuesDOMDS() throws Exception {
551        Object object = newNonLegacyObject();
552        lda.getPrimaryKeyFieldValuesDOMDS(object);
553        verify(kradLegacyDataAdapter).getPrimaryKeyFieldValuesDOMDS(eq(object));
554        verifyZeroInteractions(knsLegacyDataAdapter);
555    }
556
557    @Test
558    public void testGetPrimaryKeyFieldValuesDOMDS_Legacy() throws Exception {
559        enableLegacy();
560        Object object = newLegacyObject();
561        lda.getPrimaryKeyFieldValuesDOMDS(object);
562        verify(knsLegacyDataAdapter).getPrimaryKeyFieldValuesDOMDS(eq(object));
563        verifyZeroInteractions(kradLegacyDataAdapter);
564    }
565
566    @Test
567    public void testEqualsByPrimaryKeys() throws Exception {
568        Object object1 = newNonLegacyObject();
569        Object object2 = newNonLegacyObject();
570        lda.equalsByPrimaryKeys(object1, object2);
571        verify(kradLegacyDataAdapter).equalsByPrimaryKeys(eq(object1), eq(object2));
572        verifyZeroInteractions(knsLegacyDataAdapter);
573    }
574
575    @Test
576    public void testEqualsByPrimaryKeys_Legacy() throws Exception {
577        enableLegacy();
578        Object object1 = newLegacyObject();
579        Object object2 = newLegacyObject();
580        lda.equalsByPrimaryKeys(object1, object2);
581        verify(knsLegacyDataAdapter).equalsByPrimaryKeys(eq(object1), eq(object2));
582        verifyZeroInteractions(kradLegacyDataAdapter);
583    }
584
585//    @Test
586//    public void testToPersistableBusinessObject() throws Exception {
587//        Object object = newNonLegacyObject();
588//        lda.toPersistableBusinessObject(object);
589//        verify(kradLegacyDataAdapter).toPersistableBusinessObject(eq(object));
590//        verifyZeroInteractions(knsLegacyDataAdapter);
591//    }
592//
593//    @Test
594//    public void testToPersistableBusinessObject_Legacy() throws Exception {
595//        enableLegacy();
596//        Object object = newLegacyObject();
597//        lda.toPersistableBusinessObject(object);
598//        verify(knsLegacyDataAdapter).toPersistableBusinessObject(eq(object));
599//        verifyZeroInteractions(kradLegacyDataAdapter);
600//    }
601
602    @Test
603    public void testMaterializeAllSubObjects() throws Exception {
604        Object object = newNonLegacyObject();
605        lda.materializeAllSubObjects(object);
606        verify(kradLegacyDataAdapter).materializeAllSubObjects(eq(object));
607        verifyZeroInteractions(knsLegacyDataAdapter);
608    }
609
610    @Test
611    public void testMaterializeAllSubObjects_Legacy() throws Exception {
612        enableLegacy();
613        Object object = newLegacyObject();
614        lda.materializeAllSubObjects(object);
615        verify(knsLegacyDataAdapter).materializeAllSubObjects(eq(object));
616        verifyZeroInteractions(kradLegacyDataAdapter);
617    }
618
619    @Test
620    public void testGetPropertyType() throws Exception {
621        Object object = newNonLegacyObject();
622        lda.getPropertyType(object, "blah");
623        verify(kradLegacyDataAdapter).getPropertyType(eq(object), eq("blah"));
624        verifyZeroInteractions(knsLegacyDataAdapter);
625    }
626
627    @Test
628    public void testGetPropertyType_Legacy() throws Exception {
629        enableLegacy();
630        Object object = newLegacyObject();
631        lda.getPropertyType(object, "blah");
632        verify(knsLegacyDataAdapter).getPropertyType(eq(object), eq("blah"));
633        verifyZeroInteractions(kradLegacyDataAdapter);
634    }
635
636    @Test
637    public void testGetExtension() throws Exception {
638        lda.getExtension(NonLegacyPersistableBusinessObject.class);
639        verify(kradLegacyDataAdapter).getExtension(eq(NonLegacyPersistableBusinessObject.class));
640        verifyZeroInteractions(knsLegacyDataAdapter);
641    }
642
643    @Test
644    public void testGetExtension_Legacy() throws Exception {
645        enableLegacy();
646        lda.getExtension(Legacy.class);
647        verify(knsLegacyDataAdapter).getExtension(eq(Legacy.class));
648        verifyZeroInteractions(kradLegacyDataAdapter);
649    }
650
651    @Test
652    public void testRefreshReferenceObject() throws Exception {
653        PersistableBusinessObject object = newNonLegacyPersistableBusinessObject();
654        lda.refreshReferenceObject(object, "blah");
655        verify(kradLegacyDataAdapter).refreshReferenceObject(eq(object), eq("blah"));
656        verifyZeroInteractions(knsLegacyDataAdapter);
657    }
658
659    @Test
660    public void testRefreshReferenceObject_Legacy() throws Exception {
661        enableLegacy();
662        PersistableBusinessObject object = newLegacyObject();
663        lda.refreshReferenceObject(object, "blah");
664        verify(knsLegacyDataAdapter).refreshReferenceObject(eq(object), eq("blah"));
665        verifyZeroInteractions(kradLegacyDataAdapter);
666    }
667
668    @Test
669    public void testIsLockable() throws Exception {
670        Object object = newNonLegacyObject();
671        lda.isLockable(object);
672        verify(kradLegacyDataAdapter).isLockable(eq(object));
673        verifyZeroInteractions(knsLegacyDataAdapter);
674    }
675
676    @Test
677    public void testIsLockable_Legacy() throws Exception {
678        enableLegacy();
679        Object object = newLegacyObject();
680        lda.isLockable(object);
681        verify(knsLegacyDataAdapter).isLockable(eq(object));
682        verifyZeroInteractions(kradLegacyDataAdapter);
683    }
684
685    @Test
686    public void testVerifyVersionNumber() throws Exception {
687        Object object = newNonLegacyObject();
688        lda.verifyVersionNumber(object);
689        verify(kradLegacyDataAdapter).verifyVersionNumber(eq(object));
690        verifyZeroInteractions(knsLegacyDataAdapter);
691    }
692
693    @Test
694    public void testVerifyVersionNumber_Legacy() throws Exception {
695        enableLegacy();
696        Object object = newLegacyObject();
697        lda.verifyVersionNumber(object);
698        verify(knsLegacyDataAdapter).verifyVersionNumber(eq(object));
699        verifyZeroInteractions(kradLegacyDataAdapter);
700    }
701
702    @Test
703    public void testCreateQuickFinder() throws Exception {
704        lda.createQuickFinder(NonLegacy.class, "blah");
705        verify(kradLegacyDataAdapter).createQuickFinder(eq(NonLegacy.class), eq("blah"));
706        verifyZeroInteractions(knsLegacyDataAdapter);
707    }
708
709    @Test
710    public void testCreateQuickFinder_Legacy() throws Exception {
711        enableLegacy();
712        lda.createQuickFinder(Legacy.class, "blah");
713        verify(knsLegacyDataAdapter).createQuickFinder(eq(Legacy.class), eq("blah"));
714        verifyZeroInteractions(kradLegacyDataAdapter);
715    }
716
717    @Test
718    public void testIsReferenceUpdatable() throws Exception {
719        lda.isReferenceUpdatable(NonLegacy.class, "blah");
720        verify(kradLegacyDataAdapter).isReferenceUpdatable(eq(NonLegacy.class), eq("blah"));
721        verifyZeroInteractions(knsLegacyDataAdapter);
722    }
723
724    @Test
725    public void testIsReferenceUpdatable_Legacy() throws Exception {
726        enableLegacy();
727        lda.isReferenceUpdatable(Legacy.class, "blah");
728        verify(knsLegacyDataAdapter).isReferenceUpdatable(eq(Legacy.class), eq("blah"));
729        verifyZeroInteractions(kradLegacyDataAdapter);
730    }
731
732    @Test
733    public void testListReferenceObjectFields() throws Exception {
734        lda.listReferenceObjectFields(NonLegacy.class);
735        verify(kradLegacyDataAdapter).listReferenceObjectFields(eq(NonLegacy.class));
736        verifyZeroInteractions(knsLegacyDataAdapter);
737    }
738
739    @Test
740    public void testListReferenceObjectFields_Legacy() throws Exception {
741        enableLegacy();
742        lda.listReferenceObjectFields(Legacy.class);
743        verify(knsLegacyDataAdapter).listReferenceObjectFields(eq(Legacy.class));
744        verifyZeroInteractions(kradLegacyDataAdapter);
745    }
746
747    @Test
748    public void testIsCollectionUpdatable() throws Exception {
749        lda.isCollectionUpdatable(NonLegacy.class, "blah");
750        verify(kradLegacyDataAdapter).isCollectionUpdatable(eq(NonLegacy.class), eq("blah"));
751        verifyZeroInteractions(knsLegacyDataAdapter);
752    }
753
754    @Test
755    public void testIsCollectionUpdatable_Legacy() throws Exception {
756        enableLegacy();
757        lda.isCollectionUpdatable(Legacy.class, "blah");
758        verify(knsLegacyDataAdapter).isCollectionUpdatable(eq(Legacy.class), eq("blah"));
759        verifyZeroInteractions(kradLegacyDataAdapter);
760    }
761
762    @Test
763    public void testListCollectionObjectTypes() throws Exception {
764        lda.listCollectionObjectTypes(NonLegacy.class);
765        verify(kradLegacyDataAdapter).listCollectionObjectTypes(eq(NonLegacy.class));
766        verifyZeroInteractions(knsLegacyDataAdapter);
767    }
768
769    @Test
770    public void testListCollectionObjectTypes_Legacy() throws Exception {
771        enableLegacy();
772        lda.listCollectionObjectTypes(Legacy.class);
773        verify(knsLegacyDataAdapter).listCollectionObjectTypes(eq(Legacy.class));
774        verifyZeroInteractions(kradLegacyDataAdapter);
775    }
776
777    @Test
778    public void testGetReferenceIfExists() throws Exception {
779        PersistableBusinessObject object = newNonLegacyPersistableBusinessObject();
780        lda.getReferenceIfExists(object, "blah");
781        verify(kradLegacyDataAdapter).getReferenceIfExists(eq(object), eq("blah"));
782        verifyZeroInteractions(knsLegacyDataAdapter);
783    }
784
785    @Test
786    public void testGetReferenceIfExists_Legacy() throws Exception {
787        enableLegacy();
788        PersistableBusinessObject object = newLegacyObject();
789        lda.getReferenceIfExists(object, "blah");
790        verify(knsLegacyDataAdapter).getReferenceIfExists(eq(object), eq("blah"));
791        verifyZeroInteractions(kradLegacyDataAdapter);
792    }
793
794    @Test
795    public void testAllForeignKeyValuesPopulatedForReference() throws Exception {
796        PersistableBusinessObject object = newNonLegacyPersistableBusinessObject();
797        lda.allForeignKeyValuesPopulatedForReference(object, "blah");
798        verify(kradLegacyDataAdapter).allForeignKeyValuesPopulatedForReference(eq(object), eq("blah"));
799        verifyZeroInteractions(knsLegacyDataAdapter);
800    }
801
802    @Test
803    public void testAllForeignKeyValuesPopulatedForReference_Legacy() throws Exception {
804        enableLegacy();
805        PersistableBusinessObject object = newLegacyObject();
806        lda.allForeignKeyValuesPopulatedForReference(object, "blah");
807        verify(knsLegacyDataAdapter).allForeignKeyValuesPopulatedForReference(eq(object), eq("blah"));
808        verifyZeroInteractions(kradLegacyDataAdapter);
809    }
810
811    @Test
812    public void testGetDictionaryRelationship() throws Exception {
813        lda.getDictionaryRelationship(NonLegacy.class, "blah");
814        verify(kradLegacyDataAdapter).getDictionaryRelationship(eq(NonLegacy.class), eq("blah"));
815        verifyZeroInteractions(knsLegacyDataAdapter);
816    }
817
818    @Test
819    public void testGetDictionaryRelationship_Legacy() throws Exception {
820        enableLegacy();
821        lda.getDictionaryRelationship(Legacy.class, "blah");
822        verify(knsLegacyDataAdapter).getDictionaryRelationship(eq(Legacy.class), eq("blah"));
823        verifyZeroInteractions(kradLegacyDataAdapter);
824    }
825
826    @Test
827    public void testGetTitleAttribute() throws Exception {
828        lda.getTitleAttribute(NonLegacy.class);
829        verify(kradLegacyDataAdapter).getTitleAttribute(eq(NonLegacy.class));
830        verifyZeroInteractions(knsLegacyDataAdapter);
831    }
832
833    @Test
834    public void testGetTitleAttribute_Legacy() throws Exception {
835        enableLegacy();
836        lda.getTitleAttribute(Legacy.class);
837        verify(knsLegacyDataAdapter).getTitleAttribute(eq(Legacy.class));
838        verifyZeroInteractions(kradLegacyDataAdapter);
839    }
840
841    @Test
842    public void testAreNotesSupported() throws Exception {
843        lda.areNotesSupported(NonLegacy.class);
844        verify(kradLegacyDataAdapter).areNotesSupported(eq(NonLegacy.class));
845        verifyZeroInteractions(knsLegacyDataAdapter);
846    }
847
848    @Test
849    public void testAreNotesSupported_Legacy() throws Exception {
850        enableLegacy();
851        lda.areNotesSupported(Legacy.class);
852        verify(knsLegacyDataAdapter).areNotesSupported(eq(Legacy.class));
853        verifyZeroInteractions(kradLegacyDataAdapter);
854    }
855
856    @Test
857    public void testGetDataObjectIdentifierString() throws Exception {
858        Object object = newNonLegacyObject();
859        lda.getDataObjectIdentifierString(object);
860        verify(kradLegacyDataAdapter).getDataObjectIdentifierString(eq(object));
861        verifyZeroInteractions(knsLegacyDataAdapter);
862    }
863
864    @Test
865    public void testGetDataObjectIdentifierString_Legacy() throws Exception {
866        enableLegacy();
867        Object object = newLegacyObject();
868        lda.getDataObjectIdentifierString(object);
869        verify(knsLegacyDataAdapter).getDataObjectIdentifierString(eq(object));
870        verifyZeroInteractions(kradLegacyDataAdapter);
871    }
872
873    @Test
874    public void testGetInquiryObjectClassIfNotTitle() throws Exception {
875        Object object = newNonLegacyObject();
876        lda.getInquiryObjectClassIfNotTitle(object, "blah");
877        verify(kradLegacyDataAdapter).getInquiryObjectClassIfNotTitle(eq(object), eq("blah"));
878        verifyZeroInteractions(knsLegacyDataAdapter);
879    }
880
881    @Test
882    public void testGetInquiryObjectClassIfNotTitle_Legacy() throws Exception {
883        enableLegacy();
884        Object object = newLegacyObject();
885        lda.getInquiryObjectClassIfNotTitle(object, "blah");
886        verify(knsLegacyDataAdapter).getInquiryObjectClassIfNotTitle(eq(object), eq("blah"));
887        verifyZeroInteractions(kradLegacyDataAdapter);
888    }
889
890    @Test
891    public void testGetInquiryParameters() throws Exception {
892        Object object = newNonLegacyObject();
893        lda.getInquiryParameters(object, new ArrayList<String>(), "blah");
894        verify(kradLegacyDataAdapter).getInquiryParameters(eq(object), anyListOf(String.class), eq("blah"));
895        verifyZeroInteractions(knsLegacyDataAdapter);
896    }
897
898    @Test
899    public void testGetInquiryParameters_Legacy() throws Exception {
900        enableLegacy();
901        Object object = newLegacyObject();
902        lda.getInquiryParameters(object, new ArrayList<String>(), "blah");
903        verify(knsLegacyDataAdapter).getInquiryParameters(eq(object), anyListOf(String.class), eq("blah"));
904        verifyZeroInteractions(kradLegacyDataAdapter);
905    }
906
907    // the hasLocalLookup method only cares if you are checking it within a legacy context or not, the data object
908    // class doesn't matter
909    @Test
910    public void testHasLocalLookup() throws Exception {
911        lda.hasLocalLookup(NonLegacy.class);
912        verify(kradLegacyDataAdapter).hasLocalLookup(eq(NonLegacy.class));
913        verifyZeroInteractions(knsLegacyDataAdapter);
914    }
915
916    // the hasLocalLookup method only cares if you are checking it within a legacy context or not, the data object
917    // class doesn't matter
918    @Test
919    public void testHasLocalLookup_NonLegacyClass_In_LegacyContext() throws Exception {
920        enableLegacy();
921        LegacyUtils.doInLegacyContext(new Callable<Object>() {
922            @Override
923            public Object call() throws Exception {
924                lda.hasLocalLookup(NonLegacy.class);
925                verify(knsLegacyDataAdapter).hasLocalLookup(eq(NonLegacy.class));
926                verifyZeroInteractions(kradLegacyDataAdapter);
927                return null;
928            }
929        });
930    }
931
932    // the hasLocalLookup method only cares if you are checking it within a legacy context or not, the data object
933    // class doesn't matter
934    @Test
935    public void testHasLocalLookup_Legacy() throws Exception {
936        enableLegacy();
937        lda.hasLocalLookup(Legacy.class);
938        verify(kradLegacyDataAdapter).hasLocalLookup(eq(Legacy.class));
939        verifyZeroInteractions(knsLegacyDataAdapter);
940    }
941
942    // the hasLocalInquiry method only cares if you are checking it within a legacy context or not, the data object
943    // class doesn't matter
944    @Test
945    public void testHasLocalInquiry() throws Exception {
946        lda.hasLocalInquiry(NonLegacy.class);
947        verify(kradLegacyDataAdapter).hasLocalInquiry(eq(NonLegacy.class));
948        verifyZeroInteractions(knsLegacyDataAdapter);
949    }
950
951    // the hasLocalInquiry method only cares if you are checking it within a legacy context or not, the data object
952    // class doesn't matter
953    @Test
954    public void testHasLocalInquiry_NonLegacyClass_In_LegacyContext() throws Exception {
955        enableLegacy();
956        LegacyUtils.doInLegacyContext(new Callable<Object>() {
957            @Override
958            public Object call() throws Exception {
959                lda.hasLocalInquiry(NonLegacy.class);
960                verify(knsLegacyDataAdapter).hasLocalInquiry(eq(NonLegacy.class));
961                verifyZeroInteractions(kradLegacyDataAdapter);
962                return null;
963            }
964        });
965    }
966
967    // the hasLocalInquiry method only cares if you are checking it within a legacy context or not, the data object
968    // class doesn't matter
969    @Test
970    public void testHasLocalInquiry_Legacy() throws Exception {
971        enableLegacy();
972        lda.hasLocalInquiry(Legacy.class);
973        verify(kradLegacyDataAdapter).hasLocalInquiry(eq(Legacy.class));
974        verifyZeroInteractions(knsLegacyDataAdapter);
975    }
976
977    @Test
978    public void testGetDataObjectRelationship() throws Exception {
979        Object object = newNonLegacyObject();
980        lda.getDataObjectRelationship(object, NonLegacy.class, "blah", "prefix", true, true, true);
981        verify(kradLegacyDataAdapter).getDataObjectRelationship(eq(object), eq(NonLegacy.class), eq("blah"), eq(
982                "prefix"), eq(true), eq(true), eq(true));
983        verifyZeroInteractions(knsLegacyDataAdapter);
984    }
985
986    @Test
987    public void testGetDataObjectRelationship_Legacy() throws Exception {
988        enableLegacy();
989        Object object = newLegacyObject();
990        lda.getDataObjectRelationship(object, Legacy.class, "blah", "prefix", true, true, true);
991        verify(knsLegacyDataAdapter).getDataObjectRelationship(eq(object), eq(Legacy.class), eq("blah"), eq(
992                "prefix"), eq(true), eq(true), eq(true));
993        verifyZeroInteractions(kradLegacyDataAdapter);
994    }
995
996    @Test
997    public void testIsPersistable() throws Exception {
998        lda.isPersistable(NonLegacy.class);
999        verify(kradLegacyDataAdapter).isPersistable(eq(NonLegacy.class));
1000        verifyZeroInteractions(knsLegacyDataAdapter);
1001    }
1002
1003    @Test
1004    public void testIsPersistable_Legacy() throws Exception {
1005        enableLegacy();
1006        lda.isPersistable(Legacy.class);
1007        verify(knsLegacyDataAdapter).isPersistable(eq(Legacy.class));
1008        verifyZeroInteractions(kradLegacyDataAdapter);
1009    }
1010
1011    @Test
1012    public void testGetForeignKeyFieldsPopulationState() throws Exception {
1013        Object object = newNonLegacyObject();
1014        lda.getForeignKeyFieldsPopulationState(object, "blah");
1015        verify(kradLegacyDataAdapter).getForeignKeyFieldsPopulationState(eq(object), eq("blah"));
1016        verifyZeroInteractions(knsLegacyDataAdapter);
1017    }
1018
1019    @Test
1020    public void testGetForeignKeyFieldsPopulationState_Legacy() throws Exception {
1021        enableLegacy();
1022        Object object = newLegacyObject();
1023        lda.getForeignKeyFieldsPopulationState(object, "blah");
1024        verify(knsLegacyDataAdapter).getForeignKeyFieldsPopulationState(eq(object), eq("blah"));
1025        verifyZeroInteractions(kradLegacyDataAdapter);
1026    }
1027
1028    @Test
1029    public void testGetForeignKeysForReference() throws Exception {
1030        lda.getForeignKeysForReference(NonLegacy.class, "blah");
1031        verify(kradLegacyDataAdapter).getForeignKeysForReference(eq(NonLegacy.class), eq("blah"));
1032        verifyZeroInteractions(knsLegacyDataAdapter);
1033    }
1034
1035    @Test
1036    public void testGetForeignKeysForReference_Legacy() throws Exception {
1037        enableLegacy();
1038        lda.getForeignKeysForReference(Legacy.class, "blah");
1039        verify(knsLegacyDataAdapter).getForeignKeysForReference(eq(Legacy.class), eq("blah"));
1040        verifyZeroInteractions(kradLegacyDataAdapter);
1041    }
1042
1043    @Test
1044    public void testHasPrimaryKeyFieldValues() throws Exception {
1045        Object object = newNonLegacyObject();
1046        lda.hasPrimaryKeyFieldValues(object);
1047        verify(kradLegacyDataAdapter).hasPrimaryKeyFieldValues(eq(object));
1048        verifyZeroInteractions(knsLegacyDataAdapter);
1049    }
1050
1051    @Test
1052    public void testHasPrimaryKeyFieldValues_Legacy() throws Exception {
1053        enableLegacy();
1054        Object object = newLegacyObject();
1055        lda.hasPrimaryKeyFieldValues(object);
1056        verify(knsLegacyDataAdapter).hasPrimaryKeyFieldValues(eq(object));
1057        verifyZeroInteractions(kradLegacyDataAdapter);
1058    }
1059
1060    @Test
1061    public void testSetObjectPropertyDeep() throws Exception {
1062        Object object = newNonLegacyObject();
1063        lda.setObjectPropertyDeep(object, "blahName", NonLegacy.class, "blahValue");
1064        verify(kradLegacyDataAdapter).setObjectPropertyDeep(eq(object), eq("blahName"), eq(NonLegacy.class), eq(
1065                "blahValue"));
1066        verifyZeroInteractions(knsLegacyDataAdapter);
1067    }
1068
1069    @Test
1070    public void testSetObjectPropertyDeep_Legacy() throws Exception {
1071        enableLegacy();
1072        Object object = newLegacyObject();
1073        lda.setObjectPropertyDeep(object, "blahName", Legacy.class, "blahValue");
1074        verify(knsLegacyDataAdapter).setObjectPropertyDeep(eq(object), eq("blahName"), eq(Legacy.class), eq(
1075                "blahValue"));
1076        verifyZeroInteractions(kradLegacyDataAdapter);
1077    }
1078
1079    @Test
1080    public void testMaterializeClassForProxiedObject() throws Exception {
1081        Object object = newNonLegacyObject();
1082        lda.materializeClassForProxiedObject(object);
1083        verify(kradLegacyDataAdapter).materializeClassForProxiedObject(eq(object));
1084        verifyZeroInteractions(knsLegacyDataAdapter);
1085    }
1086
1087    @Test
1088    public void testMaterializeClassForProxiedObject_Legacy() throws Exception {
1089        enableLegacy();
1090        Object object = newLegacyObject();
1091        lda.materializeClassForProxiedObject(object);
1092        verify(knsLegacyDataAdapter).materializeClassForProxiedObject(eq(object));
1093        verifyZeroInteractions(kradLegacyDataAdapter);
1094    }
1095
1096    @Test
1097    public void testGetNestedValue() throws Exception {
1098        Object object = newNonLegacyObject();
1099        lda.getNestedValue(object, "blah");
1100        verify(kradLegacyDataAdapter).getNestedValue(eq(object), eq("blah"));
1101        verifyZeroInteractions(knsLegacyDataAdapter);
1102    }
1103
1104    @Test
1105    public void testGetNestedValue_Legacy() throws Exception {
1106        enableLegacy();
1107        Object object = newLegacyObject();
1108        lda.getNestedValue(object, "blah");
1109        verify(knsLegacyDataAdapter).getNestedValue(eq(object), eq("blah"));
1110        verifyZeroInteractions(kradLegacyDataAdapter);
1111    }
1112
1113    @Test
1114    public void testCreateNewObjectFromClass() throws Exception {
1115        lda.createNewObjectFromClass(NonLegacy.class);
1116        verify(kradLegacyDataAdapter).createNewObjectFromClass(eq(NonLegacy.class));
1117        verifyZeroInteractions(knsLegacyDataAdapter);
1118    }
1119
1120    @Test
1121    public void testCreateNewObjectFromClass_Legacy() throws Exception {
1122        enableLegacy();
1123        lda.createNewObjectFromClass(Legacy.class);
1124        verify(knsLegacyDataAdapter).createNewObjectFromClass(eq(Legacy.class));
1125        verifyZeroInteractions(kradLegacyDataAdapter);
1126    }
1127
1128    @Test
1129    public void testIsNull() throws Exception {
1130        Object object = newNonLegacyObject();
1131        lda.isNull(object);
1132        verify(kradLegacyDataAdapter).isNull(eq(object));
1133        verifyZeroInteractions(knsLegacyDataAdapter);
1134    }
1135
1136    @Test
1137    public void testIsNull_Legacy() throws Exception {
1138        enableLegacy();
1139        Object object = newLegacyObject();
1140        lda.isNull(object);
1141        verify(knsLegacyDataAdapter).isNull(eq(object));
1142        verifyZeroInteractions(kradLegacyDataAdapter);
1143    }
1144
1145    @Test
1146    public void testSetObjectProperty() throws Exception {
1147        Object object = newNonLegacyObject();
1148        lda.setObjectProperty(object, "blahName", NonLegacy.class, "blahValue");
1149        verify(kradLegacyDataAdapter).setObjectProperty(eq(object), eq("blahName"), eq(NonLegacy.class),
1150                eq("blahValue"));
1151        verifyZeroInteractions(knsLegacyDataAdapter);
1152    }
1153
1154    @Test
1155    public void testSetObjectProperty_Legacy() throws Exception {
1156        enableLegacy();
1157        Object object = newLegacyObject();
1158        lda.setObjectProperty(object, "blahName", Legacy.class, "blahValue");
1159        verify(knsLegacyDataAdapter).setObjectProperty(eq(object), eq("blahName"), eq(Legacy.class), eq("blahValue"));
1160        verifyZeroInteractions(kradLegacyDataAdapter);
1161    }
1162
1163
1164    @Test
1165    public void testFindByDocumentHeaderId() throws Exception {
1166        lda.findByDocumentHeaderId(NonLegacyDocument.class, "1234");
1167        verify(kradLegacyDataAdapter).findByDocumentHeaderId(eq(NonLegacyDocument.class), eq("1234"));
1168        verifyZeroInteractions(knsLegacyDataAdapter);
1169    }
1170
1171    @Test
1172    public void testFindByDocumentHeaderId_Legacy() throws Exception {
1173        enableLegacy();
1174        lda.findByDocumentHeaderId(LegacyDocument.class, "1234");
1175        verify(knsLegacyDataAdapter).findByDocumentHeaderId(eq(LegacyDocument.class), eq("1234"));
1176        verifyZeroInteractions(kradLegacyDataAdapter);
1177    }
1178
1179    @Test
1180    public void testFindByDocumentHeaderIds() throws Exception {
1181        lda.findByDocumentHeaderIds(NonLegacyDocument.class, new ArrayList<String>());
1182        verify(kradLegacyDataAdapter).findByDocumentHeaderIds(eq(NonLegacyDocument.class), anyListOf(String.class));
1183        verifyZeroInteractions(knsLegacyDataAdapter);
1184    }
1185
1186    @Test
1187    public void testFindByDocumentHeaderIds_Legacy() throws Exception {
1188        enableLegacy();
1189        lda.findByDocumentHeaderIds(LegacyDocument.class, new ArrayList<String>());
1190        verify(knsLegacyDataAdapter).findByDocumentHeaderIds(eq(LegacyDocument.class), anyListOf(String.class));
1191        verifyZeroInteractions(kradLegacyDataAdapter);
1192    }
1193
1194    @Test
1195    public void testGetKnsLegacyDataAdapter() throws Exception {
1196        assertEquals(knsLegacyDataAdapter, lda.getKnsLegacyDataAdapter());
1197    }
1198
1199    @Test
1200    public void testSetKnsLegacyDataAdapter() throws Exception {
1201        lda.setKnsLegacyDataAdapter(null);
1202        assertNull(lda.getKnsLegacyDataAdapter());
1203    }
1204
1205
1206    @Test
1207    public void testGetKradLegacyDataAdapter() throws Exception {
1208        assertEquals(kradLegacyDataAdapter, lda.getKradLegacyDataAdapter());
1209    }
1210
1211    @Test
1212    public void testSetKradLegacyDataAdapter() throws Exception {
1213        lda.setKradLegacyDataAdapter(null);
1214        assertNull(lda.getKradLegacyDataAdapter());
1215    }
1216
1217    @Test
1218    public void testSelectAdapter() throws Exception {
1219
1220        // Scenario 1: KNS is not enabled, in this case it will always default to KRAD adapter
1221        assertEquals(kradLegacyDataAdapter, lda.selectAdapter(NonLegacy.class));
1222        assertEquals(kradLegacyDataAdapter, lda.selectAdapter(newNonLegacyObject()));
1223        assertEquals(kradLegacyDataAdapter, lda.selectAdapter(Legacy.class));
1224        assertEquals(kradLegacyDataAdapter, lda.selectAdapter(newLegacyObject()));
1225
1226        // Now let's enable the KNS
1227        enableLegacy();
1228
1229        // Scenario 2: Using a Class which is a valid legacy Class, should use KNS adapter
1230        assertEquals(knsLegacyDataAdapter, lda.selectAdapter(Legacy.class));
1231
1232        // Scenario 3: Using an Object which is a valid legacy Object, should use KNS adapter
1233        assertEquals(knsLegacyDataAdapter, lda.selectAdapter(newLegacyObject()));
1234
1235        // Scenario 4: Using a Class which is a not a legacy Class, should fall back to KRAD adapter even though legacy is enabled
1236        assertEquals(kradLegacyDataAdapter, lda.selectAdapter(NonLegacy.class));
1237
1238        // Scenario 5: Using an Object which is a not a legacy Object, should fall back to KRAD adapter even though legacy is enabled
1239        assertEquals(kradLegacyDataAdapter, lda.selectAdapter(newNonLegacyObject()));
1240
1241    }
1242
1243    public static final class NonLegacy implements Serializable {}
1244    public static final class Legacy extends PersistableBusinessObjectBase {}
1245    public static final class NonLegacyPersistableBusinessObject extends PersistableBusinessObjectBase {}
1246
1247    public static final class NonLegacyDocument extends DocumentBase {}
1248    public static final class LegacyDocument extends DocumentBase {}
1249
1250}