package be.iminds.ilabt.jfed.lowlevel.api;

import be.iminds.ilabt.jfed.util.GeniUrn;
import org.testng.annotations.Test;

import static org.hamcrest.Matchers.*;
import static org.testng.Assert.*;

import static org.hamcrest.MatcherAssert.assertThat;

public class PlanetlabSfaRegistryInterfaceTest {

    @Test
    public void testSfaHrnToUserUrn() throws Exception {
        assertThat(PlanetlabSfaRegistryInterface.sfaHrnToUserUrn("test.user1"), equalTo(GeniUrn.parse("urn:publicid:IDN+test+user+user1")));
        assertThat(PlanetlabSfaRegistryInterface.sfaHrnToUserUrn("test.a.user1"), equalTo(GeniUrn.parse("urn:publicid:IDN+test:a+user+user1")));
        assertThat(PlanetlabSfaRegistryInterface.sfaHrnToUserUrn("test.a.b.user1"), equalTo(GeniUrn.parse("urn:publicid:IDN+test:a:b+user+user1")));
        assertThat(PlanetlabSfaRegistryInterface.sfaHrnToUserUrn("test.aa.bb.cc.user1"), equalTo(GeniUrn.parse("urn:publicid:IDN+test:aa:bb:cc+user+user1")));

        assertThat(PlanetlabSfaRegistryInterface.sfaHrnToUserUrn("user1"), is(nullValue()));

        assertThat(PlanetlabSfaRegistryInterface.sfaHrnToUserUrn(null), is(nullValue()));
    }

    @Test
    public void testUrnToSfaHrn() throws Exception {
        assertThat(PlanetlabSfaRegistryInterface.urnToSfaHrn(GeniUrn.parse("urn:publicid:IDN+test+user+user1")), equalTo("test.user1"));
        assertThat(PlanetlabSfaRegistryInterface.urnToSfaHrn(GeniUrn.parse("urn:publicid:IDN+test:a+user+user1")), equalTo("test.a.user1"));
        assertThat(PlanetlabSfaRegistryInterface.urnToSfaHrn(GeniUrn.parse("urn:publicid:IDN+test:b:c+user+user1")), equalTo("test.b.c.user1"));
        assertThat(PlanetlabSfaRegistryInterface.urnToSfaHrn(GeniUrn.parse("urn:publicid:IDN+test:aa:bb:cc+user+user1")), equalTo("test.aa.bb.cc.user1"));

        assertThat(PlanetlabSfaRegistryInterface.urnToSfaHrn(null), is(nullValue()));

    }
}