// Path: core/src/test/java/com/cosium/spring/data/jpa/entity/graph/BaseTest.java
// @TestExecutionListeners({
//   DependencyInjectionTestExecutionListener.class,
//   DirtiesContextTestExecutionListener.class,
//   TransactionalTestExecutionListener.class,
//   DbUnitTestExecutionListener.class
// })
// @RunWith(SpringRunner.class)
// @ContextConfiguration(classes = {DataRepositoryConfiguration.class})
// @DirtiesContext
// public abstract class BaseTest {
// 
//   public static final String DATASET =
//       "classpath:com/cosium/spring/data/jpa/entity/graph/dataset.xml";
// }
// 
// Path: core/src/main/java/com/cosium/spring/data/jpa/entity/graph/domain/EntityGraphs.java
// public final class EntityGraphs {
// 
//   private static final EntityGraph EMPTY = new EmptyEntityGraph();
// 
//   private EntityGraphs() {}
// 
//   /**
//    * @param name The name of the targeted EntityGraph
//    * @return An EntityGraph referenced by name
//    */
//   public static EntityGraph named(String name) {
//     return new NamedEntityGraph(name);
//   }
// 
//   /** @return An EntityGraph representing the absence of entity graph */
//   public static EntityGraph empty() {
//     return EMPTY;
//   }
// 
//   public static boolean isEmpty(EntityGraph entityGraph) {
//     return entityGraph == null
//         || (entityGraph.getEntityGraphAttributePaths() == null
//             && entityGraph.getEntityGraphName() == null
//             && entityGraph.getEntityGraphType() == null);
//   }
// 
//   private static final class EmptyEntityGraph implements EntityGraph {
// 
//     @Override
//     public EntityGraphType getEntityGraphType() {
//       return null;
//     }
// 
//     @Override
//     public String getEntityGraphName() {
//       return null;
//     }
// 
//     @Override
//     public List<String> getEntityGraphAttributePaths() {
//       return null;
//     }
// 
//     @Override
//     public boolean isOptional() {
//       return false;
//     }
//   }
// }
// 
// Path: core/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/sample/Maker.java
// @NamedEntityGraphs({
//   @NamedEntityGraph(
//     name = Maker.COUNTRY_EG,
//     attributeNodes = {@NamedAttributeNode("country")}
//   )
// })
// @Entity
// public class Maker {
// 
//   public static final String COUNTRY_EG = "Marker.country";
// 
//   @Id
//   @GeneratedValue(strategy = GenerationType.IDENTITY)
//   @Access(value = AccessType.PROPERTY)
//   private long id = 0;
// 
//   private String name;
// 
//   @ManyToOne(fetch = FetchType.LAZY)
//   @JoinColumn(nullable = false)
//   private Country country;
// 
//   @OneToMany(fetch = FetchType.LAZY, mappedBy = "maker")
//   private final Set<Product> products = new LinkedHashSet<>();
// 
//   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 Country getCountry() {
//     return country;
//   }
// 
//   public void setCountry(Country country) {
//     this.country = country;
//   }
// 
//   public Set<Product> getProducts() {
//     return products;
//   }
// }
// 
// Path: core/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/sample/MakerRepository.java
// public interface MakerRepository extends Repository<Maker, Long> {
// 
//   List<Maker> findByName(String name, EntityGraph entityGraph);
// 
//   Stream<Maker> readByName(String name, EntityGraph entityGraph);
// }


import com.cosium.spring.data.jpa.entity.graph.BaseTest;
import com.cosium.spring.data.jpa.entity.graph.domain.EntityGraphs;
import com.cosium.spring.data.jpa.entity.graph.repository.sample.Maker;
import com.cosium.spring.data.jpa.entity.graph.repository.sample.MakerRepository;
import com.github.springtestdbunit.annotation.DatabaseSetup;
import com.github.springtestdbunit.annotation.DatabaseTearDown;
import org.hibernate.Hibernate;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.transaction.annotation.Transactional;
import javax.inject.Inject;
import java.util.List;
import java.util.stream.Collectors;
import static org.assertj.core.api.Assertions.assertThat;
package com.cosium.spring.data.jpa.entity.graph.repository;




/**
 * Created on 17/03/17.
 *
 * @author Reda.Housni-Alaoui
 */
@DatabaseSetup(BaseTest.DATASET)
@DatabaseTearDown
public class RepositoryTest extends BaseTest {

  @Inject private MakerRepository makerRepository;

  @Transactional
  @Test
  public void given_empty_eg_when_finding_makers_then_country_should_not_be_initialized() {
    List<Maker> makers = makerRepository.findByName("Maker 1", EntityGraphs.empty());
    assertThat(makers).isNotEmpty();
    for (Maker maker : makers) {
      assertThat(Hibernate.isInitialized(maker.getCountry())).isFalse();
    }
  }

  @Transactional
  @Test
  public void given_country_eg_when_finding_makers_then_country_should_be_initialized() {
    List<Maker> makers =
        makerRepository.findByName("Maker 1", EntityGraphs.named(Maker.COUNTRY_EG));
    assertThat(makers).isNotEmpty();
    for (Maker maker : makers) {
      assertThat(Hibernate.isInitialized(maker.getCountry())).isTrue();
    }
  }

  @Ignore
  @Transactional
  @Test
  public void given_country_eg_when_streaming_makers_then_country_should_be_initialized() {
    List<Maker> makers =
        makerRepository
// Path: core/src/test/java/com/cosium/spring/data/jpa/entity/graph/BaseTest.java
// @TestExecutionListeners({
//   DependencyInjectionTestExecutionListener.class,
//   DirtiesContextTestExecutionListener.class,
//   TransactionalTestExecutionListener.class,
//   DbUnitTestExecutionListener.class
// })
// @RunWith(SpringRunner.class)
// @ContextConfiguration(classes = {DataRepositoryConfiguration.class})
// @DirtiesContext
// public abstract class BaseTest {
// 
//   public static final String DATASET =
//       "classpath:com/cosium/spring/data/jpa/entity/graph/dataset.xml";
// }
// 
// Path: core/src/main/java/com/cosium/spring/data/jpa/entity/graph/domain/EntityGraphs.java
// public final class EntityGraphs {
// 
//   private static final EntityGraph EMPTY = new EmptyEntityGraph();
// 
//   private EntityGraphs() {}
// 
//   /**
//    * @param name The name of the targeted EntityGraph
//    * @return An EntityGraph referenced by name
//    */
//   public static EntityGraph named(String name) {
//     return new NamedEntityGraph(name);
//   }
// 
//   /** @return An EntityGraph representing the absence of entity graph */
//   public static EntityGraph empty() {
//     return EMPTY;
//   }
// 
//   public static boolean isEmpty(EntityGraph entityGraph) {
//     return entityGraph == null
//         || (entityGraph.getEntityGraphAttributePaths() == null
//             && entityGraph.getEntityGraphName() == null
//             && entityGraph.getEntityGraphType() == null);
//   }
// 
//   private static final class EmptyEntityGraph implements EntityGraph {
// 
//     @Override
//     public EntityGraphType getEntityGraphType() {
//       return null;
//     }
// 
//     @Override
//     public String getEntityGraphName() {
//       return null;
//     }
// 
//     @Override
//     public List<String> getEntityGraphAttributePaths() {
//       return null;
//     }
// 
//     @Override
//     public boolean isOptional() {
//       return false;
//     }
//   }
// }
// 
// Path: core/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/sample/Maker.java
// @NamedEntityGraphs({
//   @NamedEntityGraph(
//     name = Maker.COUNTRY_EG,
//     attributeNodes = {@NamedAttributeNode("country")}
//   )
// })
// @Entity
// public class Maker {
// 
//   public static final String COUNTRY_EG = "Marker.country";
// 
//   @Id
//   @GeneratedValue(strategy = GenerationType.IDENTITY)
//   @Access(value = AccessType.PROPERTY)
//   private long id = 0;
// 
//   private String name;
// 
//   @ManyToOne(fetch = FetchType.LAZY)
//   @JoinColumn(nullable = false)
//   private Country country;
// 
//   @OneToMany(fetch = FetchType.LAZY, mappedBy = "maker")
//   private final Set<Product> products = new LinkedHashSet<>();
// 
//   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 Country getCountry() {
//     return country;
//   }
// 
//   public void setCountry(Country country) {
//     this.country = country;
//   }
// 
//   public Set<Product> getProducts() {
//     return products;
//   }
// }
// 
// Path: core/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/sample/MakerRepository.java
// public interface MakerRepository extends Repository<Maker, Long> {
// 
//   List<Maker> findByName(String name, EntityGraph entityGraph);
// 
//   Stream<Maker> readByName(String name, EntityGraph entityGraph);
// }


// Path: core/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/RepositoryTest.java
import com.cosium.spring.data.jpa.entity.graph.BaseTest;
import com.cosium.spring.data.jpa.entity.graph.domain.EntityGraphs;
import com.cosium.spring.data.jpa.entity.graph.repository.sample.Maker;
import com.cosium.spring.data.jpa.entity.graph.repository.sample.MakerRepository;
import com.github.springtestdbunit.annotation.DatabaseSetup;
import com.github.springtestdbunit.annotation.DatabaseTearDown;
import org.hibernate.Hibernate;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.transaction.annotation.Transactional;
import javax.inject.Inject;
import java.util.List;
import java.util.stream.Collectors;
import static org.assertj.core.api.Assertions.assertThat;

package com.cosium.spring.data.jpa.entity.graph.repository;




/**
 * Created on 17/03/17.
 *
 * @author Reda.Housni-Alaoui
 */
@DatabaseSetup(BaseTest.DATASET)
@DatabaseTearDown
public class RepositoryTest extends BaseTest {

  @Inject private MakerRepository makerRepository;

  @Transactional
  @Test
  public void given_empty_eg_when_finding_makers_then_country_should_not_be_initialized() {
    List<Maker> makers = makerRepository.findByName("Maker 1", EntityGraphs.empty());
    assertThat(makers).isNotEmpty();
    for (Maker maker : makers) {
      assertThat(Hibernate.isInitialized(maker.getCountry())).isFalse();
    }
  }

  @Transactional
  @Test
  public void given_country_eg_when_finding_makers_then_country_should_be_initialized() {
    List<Maker> makers =
        makerRepository.findByName("Maker 1", EntityGraphs.named(Maker.COUNTRY_EG));
    assertThat(makers).isNotEmpty();
    for (Maker maker : makers) {
      assertThat(Hibernate.isInitialized(maker.getCountry())).isTrue();
    }
  }

  @Ignore
  @Transactional
  @Test
  public void given_country_eg_when_streaming_makers_then_country_should_be_initialized() {
    List<Maker> makers =
        makerRepository
            .readByName("Maker 1", EntityGraphs.named(Maker.COUNTRY_EG))