HHH-11587 - Add test for issue

This commit is contained in:
Andrea Boriero 2018-01-31 09:28:29 +00:00
parent c488e8e081
commit aaa6df26e1
1 changed files with 64 additions and 6 deletions

View File

@ -7,32 +7,37 @@
package org.hibernate.jpa.test.mapping;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OrderColumn;
import javax.persistence.Table;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.TestForIssue;
import org.junit.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
@TestForIssue(jiraKey = "HHH-11587")
public class UnidirectionalOneToManyOrderColumnTest extends BaseEntityManagerFunctionalTestCase {
@Test
@FailureExpected( jiraKey = "HHH-11587" )
public void testQuote() {
public void testRemovingAnElement() {
doInJPA( this::entityManagerFactory, entityManager -> {
ParentData parent = new ParentData();
entityManager.persist( parent );
String[] childrenStr = new String[] { "One", "Two", "Three", "Four", "Five" };
String[] childrenStr = new String[] {"One", "Two", "Three"};
for ( String str : childrenStr ) {
ChildData child = new ChildData( str );
entityManager.persist( child );
@ -46,6 +51,57 @@ public class UnidirectionalOneToManyOrderColumnTest extends BaseEntityManagerFun
} );
}
@Test
public void testAddingAnElement() {
doInJPA( this::entityManagerFactory, entityManager -> {
ParentData parent = new ParentData();
entityManager.persist( parent );
String[] childrenStr = new String[] {"One", "Two", "Three"};
for ( String str : childrenStr ) {
ChildData child = new ChildData( str );
entityManager.persist( child );
parent.getChildren().add( child );
}
entityManager.flush();
List<ChildData> children = parent.getChildren();
children.add( 1, new ChildData( "Another" ) );
} );
}
@Test
public void testRemovingAndAddingAnElement() {
doInJPA( this::entityManagerFactory, entityManager -> {
ParentData parent = new ParentData();
entityManager.persist( parent );
String[] childrenStr = new String[] {"One", "Two", "Three"};
for ( String str : childrenStr ) {
ChildData child = new ChildData( str );
entityManager.persist( child );
parent.getChildren().add( child );
}
entityManager.flush();
List<ChildData> children = parent.getChildren();
children.remove( 0 );
children.add( 1, new ChildData( "Another" ) );
} );
doInJPA( this::entityManagerFactory, entityManager -> {
ParentData parent = entityManager.find( ParentData.class, 1L );
List<String> childIds = parent.getChildren().stream().map( ChildData::toString ).collect( Collectors.toList() );
int i = 0;
assertEquals( "Two", childIds.get( i++ ));
assertEquals( "Another", childIds.get( i++ ));
assertEquals( "Three", childIds.get( i++ ));
} );
}
@Override
protected Class<?>[] getAnnotatedClasses() {
@ -55,7 +111,8 @@ public class UnidirectionalOneToManyOrderColumnTest extends BaseEntityManagerFun
};
}
@Entity
@Entity(name = "ParentData")
@Table(name = "PARENT")
public static class ParentData {
@Id
@GeneratedValue
@ -70,7 +127,8 @@ public class UnidirectionalOneToManyOrderColumnTest extends BaseEntityManagerFun
}
}
@Entity
@Entity(name = "ChildData")
@Table(name = "CHILD")
public static class ChildData {
@Id
@GeneratedValue