Skip to content

Commit

Permalink
HSEARCH-1442 Adding testcase, something goes wrong when an entity has…
Browse files Browse the repository at this point in the history
… some @IndexedEmbedded annotations with includePath set and some with depth
  • Loading branch information
yrodiere authored and hferentschik committed Dec 13, 2013
1 parent 9dbefe1 commit f9ff34a
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 0 deletions.
@@ -0,0 +1,76 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* JBoss, Home of Professional Open Source
* Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @authors tag. All rights reserved.
* See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License, v. 2.1.
* This program is distributed in the hope that it will be useful, but WITHOUT A
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License,
* v.2.1 along with this distribution; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
package org.hibernate.search.test.metadata;

import org.hibernate.search.annotations.Analyze;
import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.IndexedEmbedded;

@Indexed
public class DepthAndIncludePathIndexedEmbeddedEntity {

@DocumentId
private Long id;

@Field(analyze = Analyze.NO)
private String name;

@IndexedEmbedded(includePaths = "name")
private DepthAndIncludePathIndexedEmbeddedEntity indexedEmbeddedWithIncludePath;

@IndexedEmbedded(depth = 1)
private DepthAndIncludePathIndexedEmbeddedEntity indexedEmbeddedWithDepth;

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public DepthAndIncludePathIndexedEmbeddedEntity getIndexedEmbeddedWithIncludePath() {
return indexedEmbeddedWithIncludePath;
}

public void setIndexedEmbeddedWithIncludePath(DepthAndIncludePathIndexedEmbeddedEntity indexedEmbeddedWithIncludePath) {
this.indexedEmbeddedWithIncludePath = indexedEmbeddedWithIncludePath;
}

public DepthAndIncludePathIndexedEmbeddedEntity getIndexedEmbeddedWithDepth() {
return indexedEmbeddedWithDepth;
}

public void setIndexedEmbeddedWithDepth(DepthAndIncludePathIndexedEmbeddedEntity indexedEmbeddedWithDepth) {
this.indexedEmbeddedWithDepth = indexedEmbeddedWithDepth;
}

}
@@ -0,0 +1,62 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* JBoss, Home of Professional Open Source
* Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @authors tag. All rights reserved.
* See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License, v. 2.1.
* This program is distributed in the hope that it will be useful, but WITHOUT A
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License,
* v.2.1 along with this distribution; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
package org.hibernate.search.test.metadata;

import static org.junit.Assert.*;

import org.hibernate.annotations.common.reflection.java.JavaReflectionManager;
import org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider;
import org.hibernate.search.engine.metadata.impl.EmbeddedTypeMetadata;
import org.hibernate.search.engine.metadata.impl.TypeMetadata;
import org.hibernate.search.impl.ConfigContext;
import org.hibernate.search.test.util.ManualConfiguration;
import org.hibernate.search.test.util.TestForIssue;
import org.junit.Before;
import org.junit.Test;

@TestForIssue(jiraKey = "HSEARCH-1442")
public class DepthAndIncludePathIndexedEmbeddedEntityTest {

private AnnotationMetadataProvider metadataProvider;

@Before
public void setUp() {
ConfigContext configContext = new ConfigContext( new ManualConfiguration() );
metadataProvider = new AnnotationMetadataProvider( new JavaReflectionManager(), configContext );
}

@Test
public void testDepthIsProperlyHandled() {
TypeMetadata rootTypeMetadata = metadataProvider
.getTypeMetadataFor( DepthAndIncludePathIndexedEmbeddedEntity.class );

EmbeddedTypeMetadata embeddedWithDepthTypeMetadata = null;
for ( EmbeddedTypeMetadata typeMetadata : rootTypeMetadata.getEmbeddedTypeMetadata() ) {
if ( "indexedEmbeddedWithDepth".equals( typeMetadata.getEmbeddedFieldName() ) ) {
embeddedWithDepthTypeMetadata = typeMetadata;
}
}

assertNotNull( embeddedWithDepthTypeMetadata );
assertNotNull( embeddedWithDepthTypeMetadata.getPropertyMetadataForProperty( "name" ) );
}

}

0 comments on commit f9ff34a

Please sign in to comment.