Revision 07e4e710
Added by Cherian Mathew about 10 years ago
eu.etaxonomy.taxeditor.cdmlib/src/test/java/eu/etaxonomy/taxeditor/remoting/RemoteLazyLoadingTest.java | ||
---|---|---|
14 | 14 |
import java.util.Set; |
15 | 15 |
import java.util.UUID; |
16 | 16 |
|
17 |
import org.hibernate.collection.internal.AbstractPersistentCollection; |
|
18 |
import org.hibernate.proxy.AbstractLazyInitializer; |
|
17 | 19 |
import org.junit.Assert; |
20 |
import org.junit.Before; |
|
18 | 21 |
import org.junit.Test; |
22 |
import org.springframework.core.io.ClassPathResource; |
|
23 |
import org.springframework.core.io.Resource; |
|
19 | 24 |
import org.unitils.UnitilsJUnit4; |
20 | 25 |
import org.unitils.database.annotations.Transactional; |
21 | 26 |
import org.unitils.database.util.TransactionMode; |
22 | 27 |
import org.unitils.spring.annotation.SpringApplicationContext; |
23 | 28 |
import org.unitils.spring.annotation.SpringBeanByType; |
24 | 29 |
|
30 |
import eu.etaxonomy.cdm.api.application.CdmApplicationController; |
|
31 |
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration; |
|
25 | 32 |
import eu.etaxonomy.cdm.api.service.ITaxonService; |
33 |
import eu.etaxonomy.cdm.database.CdmPersistentDataSource; |
|
34 |
import eu.etaxonomy.cdm.database.DataSourceNotFoundException; |
|
35 |
import eu.etaxonomy.cdm.database.ICdmDataSource; |
|
26 | 36 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
27 | 37 |
import eu.etaxonomy.cdm.model.name.NonViralName; |
28 | 38 |
import eu.etaxonomy.cdm.model.taxon.SynonymRelationship; |
29 | 39 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
30 | 40 |
|
31 | 41 |
|
42 |
|
|
32 | 43 |
/** |
33 | 44 |
* This test class is a testing ground for solving the hibernate lazy loading problem using aspects |
45 |
* |
|
46 |
* FIXME:Remoting Neet to be able to launch a cdm server here a-la CdmIntegrationTests |
|
47 |
* To execute this test you need a local eclipse jetty cdmserver already running. |
|
48 |
* The data used in this test corresponds to the cyprus db, so the data should be changed to |
|
49 |
* suit the target datasource |
|
34 | 50 |
* |
35 | 51 |
* @author c.mathew |
36 | 52 |
* |
37 | 53 |
*/ |
38 |
@SpringApplicationContext("classpath:/eu/etaxonomy/cdm/remotingApplicationContext.xml") |
|
54 |
//@SpringApplicationContext("classpath:/eu/etaxonomy/cdm/remotingApplicationContext.xml")
|
|
39 | 55 |
@Transactional(TransactionMode.DISABLED) |
40 | 56 |
public class RemoteLazyLoadingTest extends UnitilsJUnit4 { |
41 | 57 |
|
42 |
@SpringBeanByType |
|
58 |
//@SpringBeanByType
|
|
43 | 59 |
private ITaxonService taxonService; |
44 | 60 |
|
45 | 61 |
private UUID taxonUuid1 = UUID.fromString("8217ef77-2ab1-4318-bd67-ccd0cdef07c4"); |
46 | 62 |
private UUID taxonUuid2 = UUID.fromString("ef96fafa-7750-4141-b31b-1ad1daab3e76"); |
47 | 63 |
|
64 |
ICdmApplicationConfiguration applicationController; |
|
65 |
|
|
48 | 66 |
/** |
67 |
* @throws DataSourceNotFoundException |
|
49 | 68 |
*/ |
50 |
|
|
51 |
// @Test |
|
52 |
// public void testLazyLoading(){ |
|
53 |
// |
|
54 |
// Taxon taxon = (Taxon)taxonService.find(taxonUuid1); |
|
55 |
// System.out.println("Taxon title : " + taxon.getTitleCache()); |
|
56 |
// taxon.setTitleCache("Taxon Title Cache 1"); |
|
57 |
// taxonService.merge(taxon); |
|
58 |
// |
|
59 |
// NonViralName nvn = CdmBase.deproxy(taxon.getName(),NonViralName.class); |
|
60 |
// |
|
61 |
// |
|
62 |
// System.out.println("name : " + nvn.getTitleCache()); |
|
63 |
// nvn.setTitleCache("Taxon Name Title Cache 1"); |
|
64 |
// taxonService.merge(taxon); |
|
65 |
// |
|
66 |
// Reference ref = taxon.getSec(); |
|
67 |
// System.out.println("Secundum : " + ref.getTitleCache()); |
|
68 |
// |
|
69 |
// Rank rank = nvn.getRank(); |
|
70 |
// System.out.println("rank : " + rank.getTitleCache()); |
|
71 |
// |
|
72 |
// Set<SynonymRelationship> synRelations = taxon.getSynonymRelations(); |
|
73 |
// Iterator<SynonymRelationship> srItr = synRelations.iterator(); |
|
74 |
// while(srItr.hasNext()) { |
|
75 |
// SynonymRelationship sr = srItr.next(); |
|
76 |
// System.out.println("Synonym Relationship : " + sr.getType().getTitleCache()); |
|
77 |
// sr.getType().setTitleCache(sr.getType().getTitleCache() + "*"); |
|
78 |
// } |
|
79 |
// taxonService.merge(taxon); |
|
80 |
// |
|
81 |
// Set<TaxonRelationship> taxonRelationsFrom = taxon.getRelationsFromThisTaxon(); |
|
82 |
// Iterator<TaxonRelationship> trItrFrom = taxonRelationsFrom.iterator(); |
|
83 |
// while(trItrFrom.hasNext()) { |
|
84 |
// TaxonRelationship tr = trItrFrom.next(); |
|
85 |
// System.out.println("Taxon From Relationship : " + tr.getType().getTitleCache()); |
|
86 |
// tr.getType().setTitleCache(tr.getType().getTitleCache() + "*"); |
|
87 |
// } |
|
88 |
// taxonService.merge(taxon); |
|
89 |
// Set<TaxonRelationship> taxonRelationsTo = taxon.getRelationsToThisTaxon(); |
|
90 |
// Iterator<TaxonRelationship> trItrTo = taxonRelationsTo.iterator(); |
|
91 |
// while(trItrTo.hasNext()) { |
|
92 |
// TaxonRelationship tr = trItrTo.next(); |
|
93 |
// System.out.println("Taxon To Relationship : " + tr.getType().getTitleCache()); |
|
94 |
// tr.getType().setTitleCache(tr.getType().getTitleCache() + "*"); |
|
95 |
// } |
|
96 |
// taxonService.merge(taxon); |
|
97 |
// } |
|
69 |
@Before |
|
70 |
public void initializeContext() throws DataSourceNotFoundException { |
|
71 |
Resource DEFAULT_APPLICATION_CONTEXT = new ClassPathResource( |
|
72 |
"/eu/etaxonomy/cdm/remotingApplicationContext.xml"); |
|
73 |
ICdmDataSource datasource = CdmPersistentDataSource.NewInstance("local-cyprus"); |
|
74 |
ICdmApplicationConfiguration applicationController = |
|
75 |
CdmApplicationController.NewInstance(DEFAULT_APPLICATION_CONTEXT, |
|
76 |
datasource, |
|
77 |
null, |
|
78 |
false, |
|
79 |
null); |
|
80 |
AbstractLazyInitializer.setConfiguration(applicationController); |
|
81 |
AbstractPersistentCollection.setConfiguration(applicationController); |
|
82 |
taxonService = applicationController.getTaxonService(); |
|
83 |
} |
|
98 | 84 |
|
99 | 85 |
@Test |
100 | 86 |
public void testCDMEntityGet() { |
Also available in: Unified diff
RemoteLazyLoadingTest : Creating application configuration programmatically
AbstractPersistentCollection, AbstractLazyInitializer : Copied aspect code here
CdmApplicationRemoteConfiguration : overriding datasource since it is not required in remoting
remotingApplicationContext : added autowiring config