package com.atlassian.bitbucket.mesh.repository;

import org.junit.Test;
import java.util.Optional;

import static org.junit.Assert.*;

public class ManagedRepositoryTest {

    @Test
    public void testParseIdPartitionValid() throws Exception {
        Optional<ManagedRepository.Id> maybeId = ManagedRepository.Id.parseId("p/0001/h/1234567890abcdef1234/r/a");
        assertNotEquals(Optional.empty(), maybeId);

        ManagedRepository.Id id = maybeId.get();
        assertEquals("0001", id.getPartition());

        maybeId = ManagedRepository.Id.parseId("p/fffffffffffffff/h/1234567890abcdef1234/r/a");
        assertNotEquals(Optional.empty(), maybeId);

        id = maybeId.get();
        assertEquals("fffffffffffffff", id.getPartition());
    }

    @Test
    public void testParseIdPartitionTooShort() throws Exception {
        Optional<ManagedRepository.Id> maybeId = ManagedRepository.Id.parseId("p/001/h/1234567890abcdef1234/r/a");
        assertEquals(Optional.empty(), maybeId);
    }

    @Test
    public void testParseIdPartitionInvalidCharacters() throws Exception {
        Optional<ManagedRepository.Id> maybeId = ManagedRepository.Id.parseId("p/000z/h/1234567890abcdef1234/r/a");
        assertEquals(Optional.empty(), maybeId);
    }

    @Test
    public void testParseIdPartitionTooLong() throws Exception {
        Optional<ManagedRepository.Id> maybeId = ManagedRepository.Id.parseId("p/1234567812345678/h/1234567890abcdef1234/r/a");
        assertEquals(Optional.empty(), maybeId);
    }
}
