Skip to content

Commit

Permalink
HSEARCH-782 Have the test fail properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanne committed Aug 10, 2011
1 parent f7116d3 commit b05dfe9
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 6 deletions.
Expand Up @@ -20,25 +20,39 @@
package org.hibernate.search.test.engine.optimizations;

import java.lang.annotation.ElementType;
import java.util.List;

import junit.framework.Assert;

import org.hibernate.Transaction;
import org.hibernate.search.FullTextSession;
import org.hibernate.search.cfg.EntityMapping;
import org.hibernate.search.backend.LuceneWork;
import org.hibernate.search.cfg.SearchMapping;
import org.hibernate.search.test.embedded.depth.LeakingLuceneBackend;
import org.hibernate.search.test.util.FullTextSessionBuilder;
import org.junit.Test;

/**
* Related to test case of HSEARCH-782
*
* @author Adam Harris
* @author Sanne Grinovero <sanne@hibernate.org> (C) 2011 Red Hat Inc.
*/
public class CollectionUpdateEventTest2 {

@Test
public void testScenario() {

FullTextSessionBuilder fullTextSessionBuilder = createSearchFactory();
try {
assertOperationsPerformed( 0 );
initializeData( fullTextSessionBuilder );
assertOperationsPerformed( 5 );
FullTextSession fullTextSession = fullTextSessionBuilder.openFullTextSession();
try {
LocationGroup group = (LocationGroup) fullTextSession.get( LocationGroup.class, 1L );
addLocationToGroupCollection( fullTextSession, group );
assertOperationsPerformed( 1 );
}
finally {
fullTextSession.close();
Expand All @@ -49,16 +63,31 @@ public void testScenario() {
}
}

private void assertOperationsPerformed(int expectedOperationCount) {
List<LuceneWork> lastProcessedQueue = LeakingLuceneBackend.getLastProcessedQueue();
Assert.assertEquals( expectedOperationCount, lastProcessedQueue.size() );
LeakingLuceneBackend.reset();
}

private FullTextSessionBuilder createSearchFactory() {
FullTextSessionBuilder builder = new FullTextSessionBuilder()
.setProperty( "hibernate.search.worker.backend",
org.hibernate.search.test.embedded.depth.LeakingLuceneBackend.class.getName() )
.addAnnotatedClass( LocationGroup.class )
.addAnnotatedClass( Location.class );
SearchMapping fluentMapping = builder.fluentMapping();
EntityMapping locationGroupMapping = fluentMapping.entity( LocationGroup.class );
locationGroupMapping.property( "name", ElementType.FIELD ).property( "locations", ElementType.FIELD )
.containedIn().entity( Location.class ).indexed().property( "locationId", ElementType.FIELD )
.documentId().property( "name", ElementType.FIELD ).property( "locationGroup", ElementType.FIELD )
.indexEmbedded().depth( 1 );
fluentMapping.entity( LocationGroup.class )
.property( "name", ElementType.FIELD )
.property( "locations", ElementType.FIELD )
.containedIn()
.entity( Location.class )
.indexed()
.property( "locationId", ElementType.FIELD )
.documentId()
.property( "name", ElementType.FIELD )
.property( "locationGroup", ElementType.FIELD )
.indexEmbedded()
.depth( 1 );
return builder.build();
}

Expand Down
Expand Up @@ -33,21 +33,33 @@
import org.hibernate.annotations.LazyToOneOption;
import org.hibernate.annotations.Proxy;

/**
* Related to test case of HSEARCH-782; indexed properties are defined
* via a programmatic configuration.
*
* @author Adam Harris
* @author Sanne Grinovero <sanne@hibernate.org> (C) 2011 Red Hat Inc.
*/
@Entity
@Proxy(lazy = false)
@Table(name = "location")
//indexed
public class Location {

@Id()
@GeneratedValue(strategy = GenerationType.AUTO)
//indexed & documentId
private Long locationId;

@Column(length = 255)
//indexed
private String name;

@ManyToOne(fetch = FetchType.LAZY, targetEntity = LocationGroup.class)
@JoinColumn(name = "location_group_id")
@LazyToOne(LazyToOneOption.PROXY)
//indexed
//indexedEmbedded(depth=1)
private LocationGroup locationGroup;

public Location() {
Expand Down
Expand Up @@ -34,18 +34,28 @@

import org.hibernate.annotations.Proxy;

/**
* Related to test case of HSEARCH-782; indexed properties are defined
* via a programmatic configuration.
*
* @author Adam Harris
* @author Sanne Grinovero <sanne@hibernate.org> (C) 2011 Red Hat Inc.
*/
@Entity
@Proxy(lazy = false)
@Table(name = "location_group")
//not indexed
public class LocationGroup {

@Id()
@GeneratedValue(strategy = GenerationType.AUTO)
private Long groupId;

//indexed
@Column(length = 255)
private String name;

//contained-in Location
@OneToMany(mappedBy = "locationGroup", cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
Collection<Location> locations = new ArrayList<Location>();

Expand Down

0 comments on commit b05dfe9

Please sign in to comment.