// Path: graphql-test/src/main/java/org/objectstyle/graphql/test/TestFactory.java
// public class TestFactory {
// 
//     private ServerRuntime serverRuntime;
//     private ObjectContext objectContext;
// 
//     public TestFactory(){
//         createServerRuntime();
//     }
// 
//     private void createServerRuntime() {
//         removeDerbyDirectory();
// 
//         serverRuntime = ServerRuntimeBuilder.builder().addConfig("cayenne-tests.xml")
//                 .url("jdbc:derby:target/derby;create=true").jdbcDriver("org.apache.derby.jdbc.EmbeddedDriver")
//                 .addModule(cayenneExtensions()).build();
// 
//         objectContext = serverRuntime.newContext();
// 
//         insertTestData();
//     }
// 
//     public void stopServerRuntime() {
//         serverRuntime.shutdown();
//         serverRuntime = null;
// 
//         stopDerby();
//     }
// 
//     private static org.apache.cayenne.di.Module cayenneExtensions() {
//         return (b) -> b.bind(SchemaUpdateStrategy.class).to(CreateIfNoSchemaStrategy.class);
//     }
// 
//     private void insertTestData() {
//         insert("e1", "id, name", "1, 'a'");
//         insert("e1", "id, name", "2, 'b'");
// 
//         insert("e2", "id, name, e1_id", "3, 'c', 1");
//         insert("e2", "id, name, e1_id", "4, 'd', 2");
//         insert("e2", "id, name, e1_id", "5, 'e', 2");
// 
//         insert("e3", "id, name, e2_id", "6, 'f', 4");
//         insert("e3", "id, name, e2_id", "7, 'g', 4");
//         insert("e3", "id, name, e2_id", "8, 'h', 5");
//     }
// 
//     private void insert(String table, String columns, String values) {
//         String insertSql = "INSERT INTO utest." + table + " (" + columns + ") VALUES (" + values + ")";
//         objectContext.performGenericQuery(new SQLTemplate(table, insertSql));
//     }
// 
//     private void removeDerbyDirectory() {
// 
//         File derbyDir = new File("target/derby");
//         if (derbyDir.isDirectory()) {
//             try {
//                 FileUtils.deleteDirectory(derbyDir);
//             } catch (IOException e) {
//                 throw new RuntimeException(e);
//             }
//         }
//     }
// 
//     private void stopDerby() {
//         try {
//             DriverManager.getConnection("jdbc:derby:;shutdown=true");
//         } catch (SQLException ignored) {
//         }
//     }
// 
//     public ObjectContext getObjectContext() {
//         return objectContext;
//     }
// 
//     public ServerRuntime getServerRuntime() {
//         return serverRuntime;
//     }
// }
// 
// Path: graphql-test/src/main/java/org/objectstyle/graphql/test/cayenne/E1.java
// public class E1 extends _E1 {
// 
//     private static final long serialVersionUID = 1L; 
// 
// }
// 
// Path: graphql-test/src/main/java/org/objectstyle/graphql/test/cayenne/E2.java
// public class E2 extends _E2 {
// 
//     private static final long serialVersionUID = 1L; 
// 
// }
// 
// Path: graphql-test/src/main/java/org/objectstyle/graphql/test/cayenne/E3.java
// public class E3 extends _E3 {
// 
//     private static final long serialVersionUID = 1L; 
// 
// }


import graphql.ExecutionResult;
import graphql.GraphQL;
import graphql.schema.GraphQLSchema;
import org.apache.cayenne.exp.Expression;
import org.apache.cayenne.exp.ExpressionFactory;
import org.apache.cayenne.query.*;
import org.junit.Test;
import org.objectstyle.graphql.cayenne.orm.*;
import org.objectstyle.graphql.test.TestFactory;
import org.objectstyle.graphql.test.cayenne.E1;
import org.objectstyle.graphql.test.cayenne.E2;
import org.objectstyle.graphql.test.cayenne.E3;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.Map;
import static graphql.ErrorType.ValidationError;
import static org.junit.Assert.assertEquals;
package org.objectstyle.graphql.cayenne;









public class GraphQLTest {
    private static TestFactory testFactory = new TestFactory();
    private static final Logger LOGGER = LoggerFactory.getLogger(GraphQLTest.class);

    private void incudeOneEntityTest(GraphQL graphQL) {
        ExecutionResult r = graphQL.execute("query { E1 (id:1) { id name}}");
        LOGGER.info(r.getData().toString());
        assertEquals("{E1=[{id=1, name=a}]}", r.getData().toString());

        r = graphQL.execute("query { E2 (id:3) { id name}}");
        assertEquals(null, r.getData());
        assertEquals(ValidationError, r.getErrors().get(0).getErrorType());
        assertEquals("Validation error of type FieldUndefined: Field E2 is undefined", r.getErrors().get(0).getMessage());


        r = graphQL.execute("query { E3 (id:6) { id name}}");
        assertEquals(null, r.getData());
        assertEquals(ValidationError, r.getErrors().get(0).getErrorType());
        assertEquals("Validation error of type FieldUndefined: Field E3 is undefined", r.getErrors().get(0).getMessage());
    }

    @Test
    public void incudeOneEntityClassTest() {
        QueryType.Builder queryType = QueryType.builder(testFactory.getObjectContext());

// Path: graphql-test/src/main/java/org/objectstyle/graphql/test/TestFactory.java
// public class TestFactory {
// 
//     private ServerRuntime serverRuntime;
//     private ObjectContext objectContext;
// 
//     public TestFactory(){
//         createServerRuntime();
//     }
// 
//     private void createServerRuntime() {
//         removeDerbyDirectory();
// 
//         serverRuntime = ServerRuntimeBuilder.builder().addConfig("cayenne-tests.xml")
//                 .url("jdbc:derby:target/derby;create=true").jdbcDriver("org.apache.derby.jdbc.EmbeddedDriver")
//                 .addModule(cayenneExtensions()).build();
// 
//         objectContext = serverRuntime.newContext();
// 
//         insertTestData();
//     }
// 
//     public void stopServerRuntime() {
//         serverRuntime.shutdown();
//         serverRuntime = null;
// 
//         stopDerby();
//     }
// 
//     private static org.apache.cayenne.di.Module cayenneExtensions() {
//         return (b) -> b.bind(SchemaUpdateStrategy.class).to(CreateIfNoSchemaStrategy.class);
//     }
// 
//     private void insertTestData() {
//         insert("e1", "id, name", "1, 'a'");
//         insert("e1", "id, name", "2, 'b'");
// 
//         insert("e2", "id, name, e1_id", "3, 'c', 1");
//         insert("e2", "id, name, e1_id", "4, 'd', 2");
//         insert("e2", "id, name, e1_id", "5, 'e', 2");
// 
//         insert("e3", "id, name, e2_id", "6, 'f', 4");
//         insert("e3", "id, name, e2_id", "7, 'g', 4");
//         insert("e3", "id, name, e2_id", "8, 'h', 5");
//     }
// 
//     private void insert(String table, String columns, String values) {
//         String insertSql = "INSERT INTO utest." + table + " (" + columns + ") VALUES (" + values + ")";
//         objectContext.performGenericQuery(new SQLTemplate(table, insertSql));
//     }
// 
//     private void removeDerbyDirectory() {
// 
//         File derbyDir = new File("target/derby");
//         if (derbyDir.isDirectory()) {
//             try {
//                 FileUtils.deleteDirectory(derbyDir);
//             } catch (IOException e) {
//                 throw new RuntimeException(e);
//             }
//         }
//     }
// 
//     private void stopDerby() {
//         try {
//             DriverManager.getConnection("jdbc:derby:;shutdown=true");
//         } catch (SQLException ignored) {
//         }
//     }
// 
//     public ObjectContext getObjectContext() {
//         return objectContext;
//     }
// 
//     public ServerRuntime getServerRuntime() {
//         return serverRuntime;
//     }
// }
// 
// Path: graphql-test/src/main/java/org/objectstyle/graphql/test/cayenne/E1.java
// public class E1 extends _E1 {
// 
//     private static final long serialVersionUID = 1L; 
// 
// }
// 
// Path: graphql-test/src/main/java/org/objectstyle/graphql/test/cayenne/E2.java
// public class E2 extends _E2 {
// 
//     private static final long serialVersionUID = 1L; 
// 
// }
// 
// Path: graphql-test/src/main/java/org/objectstyle/graphql/test/cayenne/E3.java
// public class E3 extends _E3 {
// 
//     private static final long serialVersionUID = 1L; 
// 
// }


// Path: graphql-cayenne/src/test/java/org/objectstyle/graphql/cayenne/GraphQLTest.java
import graphql.ExecutionResult;
import graphql.GraphQL;
import graphql.schema.GraphQLSchema;
import org.apache.cayenne.exp.Expression;
import org.apache.cayenne.exp.ExpressionFactory;
import org.apache.cayenne.query.*;
import org.junit.Test;
import org.objectstyle.graphql.cayenne.orm.*;
import org.objectstyle.graphql.test.TestFactory;
import org.objectstyle.graphql.test.cayenne.E1;
import org.objectstyle.graphql.test.cayenne.E2;
import org.objectstyle.graphql.test.cayenne.E3;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.Map;
import static graphql.ErrorType.ValidationError;
import static org.junit.Assert.assertEquals;

package org.objectstyle.graphql.cayenne;









public class GraphQLTest {
    private static TestFactory testFactory = new TestFactory();
    private static final Logger LOGGER = LoggerFactory.getLogger(GraphQLTest.class);

    private void incudeOneEntityTest(GraphQL graphQL) {
        ExecutionResult r = graphQL.execute("query { E1 (id:1) { id name}}");
        LOGGER.info(r.getData().toString());
        assertEquals("{E1=[{id=1, name=a}]}", r.getData().toString());

        r = graphQL.execute("query { E2 (id:3) { id name}}");
        assertEquals(null, r.getData());
        assertEquals(ValidationError, r.getErrors().get(0).getErrorType());
        assertEquals("Validation error of type FieldUndefined: Field E2 is undefined", r.getErrors().get(0).getMessage());


        r = graphQL.execute("query { E3 (id:6) { id name}}");
        assertEquals(null, r.getData());
        assertEquals(ValidationError, r.getErrors().get(0).getErrorType());
        assertEquals("Validation error of type FieldUndefined: Field E3 is undefined", r.getErrors().get(0).getMessage());
    }

    @Test
    public void incudeOneEntityClassTest() {
        QueryType.Builder queryType = QueryType.builder(testFactory.getObjectContext());

        queryType.configureEntities(EntityBuilder.ConfigureType.INCLUDE_OBJECT, E1.class);