/*
 * Copyright (C) 2020 Grakn Labs
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 */

package grakn.core.test.behaviour.resolution.framework.test;

import grakn.core.concept.answer.ConceptMap;
import grakn.core.kb.server.Session;
import grakn.core.kb.server.Transaction;
import grakn.core.test.behaviour.resolution.framework.common.GraqlHelpers;
import grakn.core.test.rule.GraknTestServer;
import graql.lang.Graql;
import graql.lang.query.GraqlGet;
import graql.lang.statement.Statement;
import org.junit.ClassRule;
import org.junit.Test;

import java.util.Set;

import static grakn.core.test.behaviour.resolution.framework.common.Utils.getStatements;
import static grakn.core.test.behaviour.resolution.framework.test.LoadTest.loadTestStub;
import static org.junit.Assert.assertEquals;

public class ResolutionQueryBuilderIT {

    @ClassRule
    public static final GraknTestServer graknTestServer = new GraknTestServer();

    @Test
    public void testKeysStatementsAreGeneratedCorrectly() {
        GraqlGet inferenceQuery = Graql.parse("match $transaction isa transaction, has currency $currency; get;");

        Set<Statement> keyStatements;

        try (Session session = graknTestServer.sessionWithNewKeyspace()) {

            loadTestStub(session, "complex_recursion");

            try (Transaction tx = session.transaction(Transaction.Type.READ)) {
                ConceptMap answer = tx.execute(inferenceQuery).get(0);
                keyStatements = GraqlHelpers.generateKeyStatements(answer.map());
            }
        }

        Set<Statement> expectedStatements = getStatements(Graql.parsePatternList(
                "$transaction has transaction-id 0;\n" +
                "$currency \"GBP\" isa currency;\n"
        ));

        assertEquals(expectedStatements, keyStatements);
    }
}
@@ -2268,40 +2268,37 @@
   %22$
-transaction has transaction-id 0
+currency %5C%22GBP%5C%22 isa currency
 ;%5Cn%22
@@ -2310,32 +2310,48 @@
               %22$
+transaction has 
 currency %5C%22GBP%5C%22
@@ -2354,26 +2354,14 @@
 BP%5C%22
- isa currency
 ;%5Cn%22%0A
+%0A
     

Fix failing integration test in ResolutionQueryBuilderIT (#5828)