package be.iminds.ilabt.jfed.rspec.parser.extensions;

import be.iminds.ilabt.jfed.lowlevel.api.user_spec.UserSpec;
import be.iminds.ilabt.jfed.rspec.model.StringRspec;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * User: twalcari
 * Date: 3/9/2015
 * Time: 15:12
 */
public class UserSpecTest {

    private static final String userSpecList =   "<jfed-ssh-keys:user-list xmlns:jfed-ssh-keys=\"http://jfed.iminds.be/rspec/ext/jfed-ssh-keys/1\">\n" +
            "    <jfed-ssh-keys:user-ssh-keys user=\"urn:publicid:IDN+example.com+user+tester\">\n" +
            "        <jfed-ssh-keys:sshkey>ssh-rsa key1</jfed-ssh-keys:sshkey>\n" +
            "        <jfed-ssh-keys:sshkey>ssh-rsa-key2</jfed-ssh-keys:sshkey>\n" +
            "    </jfed-ssh-keys:user-ssh-keys>\n" +
            "</jfed-ssh-keys:user-list>";

    @Test
    public void testUserSpecWriter() throws Exception {
        List<String> keys = new ArrayList<String>();
        keys.add("ssh-rsa key1");
        keys.add("ssh-rsa-key2");
        UserSpec userSpec = new UserSpec("urn:publicid:IDN+example.com+user+tester", keys);

        UserSpecWriter writer = new UserSpecWriter(Collections.singletonList(userSpec));

        String output = writer.call();

        StringRspec.isSimilarXml(userSpecList, output);
    }

    @Test
    public void testUserSpecParser() throws Exception {

        UserSpecParser parser = new UserSpecParser(userSpecList);

        List<UserSpec> parseResult = parser.call();
        Assert.assertEquals(parseResult.size(), 1);

        UserSpec spec1 = parseResult.get(0);

        Assert.assertEquals(spec1.getUrn(),"urn:publicid:IDN+example.com+user+tester" );
        Assert.assertEquals(spec1.getSshKey().size(), 2);




    }



}
