package cz.encircled.joiner.eclipse;

import cz.encircled.joiner.TestDataListener;
import cz.encircled.joiner.TestWithLogging;
import cz.encircled.joiner.core.Joiner;
import cz.encircled.joiner.model.AbstractEntity;
import cz.encircled.joiner.query.join.JoinGraphRegistry;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

/**
 * @author Kisel on 11.01.2016.
 */
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = {TestConfig.class})
@Transactional
@TestExecutionListeners(listeners = {TestDataListener.class, DependencyInjectionTestExecutionListener.class, TransactionalTestExecutionListener.class})
public abstract class AbstractEclipseTest extends TestWithLogging {

    @Autowired
    protected Joiner joiner;

    @Autowired
    protected JoinGraphRegistry joinGraphRegistry;

    @PersistenceContext
    protected EntityManager entityManager;

    @Autowired
    private Environment environment;

    @BeforeEach
    public void before() {
        assumeTrue(isEclipse());

        entityManager.clear();
        entityManager.getEntityManagerFactory().getCache().evictAll();
    }

    protected void assertHasName(AbstractEntity entity, String name) {
        assertNotNull(entity);
        assertEquals(name, entity.getName());
    }

    protected boolean isEclipse() {
        return environment.acceptsProfiles(Profiles.of("eclipse"));
    }

    protected boolean isLoaded(Object entity, String attribute) {
        return isLoaded(entity, attribute);
    }

}

@@ -474,54 +474,8 @@
 nt;%0A
-import org.springframework.core.env.Profiles;%0A
 impo
@@ -528,24 +528,24 @@
 figuration;%0A
+
 import org.s
@@ -596,16 +596,76 @@
 teners;%0A
+import org.springframework.test.context.TestPropertySource;%0A
 import o
@@ -1007,24 +1007,62 @@
 ityManager;%0A
+import javax.persistence.Persistence;%0A
 import javax
@@ -1573,16 +1573,64 @@
 class%7D)%0A
+@TestPropertySource(properties = %22orm=eclipse%22)%0A
 public a
@@ -2315,16 +2315,23 @@
  return 
+true;//
 environm
@@ -2444,24 +2444,24 @@
 ttribute) %7B%0A
-
         retu
@@ -2463,16 +2463,49 @@
  return 
+Persistence.getPersistenceUtil().
 isLoaded

Fix eclipse tests