Skip to content

Commit

Permalink
HSEARCH-886 Validation test for renamed field
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideD authored and Sanne committed Feb 12, 2012
1 parent a6f09e6 commit e80e243
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2012, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hibernate.search.test.embedded.path.validation;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToOne;

import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.IndexedEmbedded;

/**
* @author Davide D'Alto
*/
@Entity
@Indexed
class FieldRenamedContainerEntity {

@Id
@GeneratedValue
Integer id;

@OneToOne
@IndexedEmbedded(depth = 0, paths = {"embedded.field"})
FieldRenamedEmbeddedEntity embedded;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2012, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hibernate.search.test.embedded.path.validation;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToOne;

import org.hibernate.search.annotations.ContainedIn;
import org.hibernate.search.annotations.Field;

/**
* @author Davide D'Alto
*/
@Entity
class FieldRenamedEmbeddedEntity {

@Id
@GeneratedValue
Integer id;

@Field(name = "renamed")
public String field;

@OneToOne
@ContainedIn
public FieldRenamedContainerEntity container;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
import org.junit.Test;

/**
*
* @author zkurey
*
*/
public class TestInvalidPaths {

Expand Down Expand Up @@ -162,7 +160,6 @@ public void testNonLeafEmbeddedPath() {
assertFalse(
"Expected search exception to NOT contain information about invalid path emb.e1, instead got error: "
+ se.getMessage(), se.getMessage().contains( "emb.e1" ) );

}
}

Expand All @@ -185,6 +182,22 @@ public void testNonIndexedPath() {
}
}

@Test
public void testRenamedFieldInPath() {
FullTextSessionBuilder cfg = new FullTextSessionBuilder();
cfg.addAnnotatedClass( FieldRenamedContainerEntity.class );
cfg.addAnnotatedClass( FieldRenamedEmbeddedEntity.class );
try {
cfg.build();
fail( "Exception should have been thrown for FieldRenamedContainerEntity having invalid path (attribute instead of field name): embedded.field" );
}
catch ( SearchException se ) {
assertTrue(
"Expected search exception to contain information about invalid leaf path embedded.field, instead got error: "
+ se.getMessage(), se.getMessage().contains( "embedded.field" ) );
}
}

/**
* Ensures that path still marked as encountered if depth is the cause of the path being
* traversed, and they are the same depth
Expand Down

0 comments on commit e80e243

Please sign in to comment.