/*
 * matrix-java-sdk - Matrix Client SDK for Java
 * Copyright (C) 2017 Maxime Dor
 *
 * https://max.kamax.io/
 *
 * 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 <http://www.gnu.org/licenses/>.
 */

package io.kamax.matrix.sign;

import org.junit.BeforeClass;
import org.junit.Test;

import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.*;
import static org.junit.Assert.assertThat;

public class SignatureManagerTest {

    private static SignatureManager signMgr;

    @BeforeClass
    public static void beforeClass() {
        signMgr = new SignatureManager(
                new KeyManager(new KeyMemoryStore("YJDBA9Xnr2sVqXD9Vj7XVUnmFZcZrlw8Md7kMW+3XA1")), "domain");
    }

    @Test
    public void emptyObject() {
        assertThat(signMgr.sign("{}"),
                is(equalTo("K8280/U9SSy9IVtjBuVeLr+HpOB4BQFWbg+UZaADMtTdGYI7Geitb76LTrr5QV/7Xg4ahLwYGYZzuHGZKM5ZAQ")));
    }

    @Test
    public void simpleObject() {
        assertThat(signMgr.sign("{\"one\":1,\"two\":\"Two\"}"),
                is(equalTo("KqmLSbO39/Bzb0QIYE82zqLwsA+PDzYIpIRA2sRQ4sL53+sN6/fpNSoqE7BP7vBZhG6kYdD13EIMJpvhJI+6Bw")));
    }

}

@@ -809,16 +809,52 @@
 .sign;%0A%0A
+import com.google.gson.JsonObject;%0A%0A
 import o
@@ -1763,10 +1763,762 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void test() %7B%0A        SignatureManager mgr = new SignatureManager(%0A                new KeyManager(new KeyMemoryStore(%221QblgjFeL3IxoY4DKOR7p5mL5sQTC0ChmeMJlqb4d5M%22)),%0A                %22synapse.local.kamax.io%22);%0A        JsonObject o = new JsonObject();%0A        o.addProperty(%22method%22, %22GET%22);%0A        o.addProperty(%22uri%22, %22/_matrix/federation/v1/query/directory?room_alias=%2523a%253Amxhsd.local.kamax.io%253A8447%22);%0A        o.addProperty(%22origin%22, %22synapse.local.kamax.io%22);%0A        o.addProperty(%22destination%22, %22mxhsd.local.kamax.io:8447%22);%0A        String signature = mgr.sign(o);%0A        assertThat(signature,%0A                is(equalTo(%22SEMGSOJEsoalrBfHqPO2QrSlbLaUYLHLk4e3q4IJ2JbgvCynT1onp7QF1U4Sl3G3NzybrgdnVvpqcaEgV0WPCw%22)));%0A    %7D%0A%0A
 %7D%0A

Add unit test for federation/Json object signing support