package com.agilex.healthcare.schedulingmanager.linkbuilder;

import com.agilex.healthcare.mobilehealthplatform.domain.ResourceDirectory;
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

/**
 * Created by
 * User: ralph
 * Date: 11/5/13
 * Time: 5:28 PM
 */
public class SchedulingServiceResourceDirectoryBuilderTest extends TestCase {

    public static final String      TEST_BASE_URI = "http://localhost:8080/MobileHealthcare";
    public static final String      TEST_RESOURCE_URI = "http://localhost:8181/MobileHealthcare";
    public static final String      TEST_FACILITY = "777";

    public static final String[]    RESULT_URL = {
            TEST_RESOURCE_URI,
            TEST_BASE_URI + "/scheduling-service/site/" + TEST_FACILITY + "/waitlist/ewl",
            TEST_BASE_URI + "/scheduling-service/site/" + TEST_FACILITY + "/waitlist/near",
            TEST_BASE_URI + "/scheduling-service/site/" + TEST_FACILITY + "/waitlist/recall",
            TEST_BASE_URI + "/scheduling-service/site/" + TEST_FACILITY + "/purpose-list",
            TEST_BASE_URI + "/scheduling-service/site/" + TEST_FACILITY + "/waitlist/recall",
            TEST_BASE_URI + "/scheduling-service/site/" + TEST_FACILITY + "/cancel-reasons-list",
            TEST_BASE_URI + "/location-service/site/"   + TEST_FACILITY + "/resource-directory",
            TEST_BASE_URI + "/appointment-service/metadata",
            TEST_BASE_URI + "/appointment-service/appointment-requests",
            TEST_BASE_URI + "/scheduling-service/site/" + TEST_FACILITY + "/consult/services",
            TEST_BASE_URI + "/scheduling-service/site/" + TEST_FACILITY + "/consults"
    };


    @Before
    public void setup() {

    }

    @After
    public void teardown() {

    }

    @Test
    public void  testGetResourceDirectory()
            throws URISyntaxException, IOException {
        SchedulingServiceResourceDirectoryBuilder     linkBuilder = new SchedulingServiceResourceDirectoryBuilder();
        ResourceDirectory                             directory;

        directory = linkBuilder.getResourceDirectory(new URI(TEST_BASE_URI),
                                                     new URI(TEST_RESOURCE_URI), TEST_FACILITY);

        assertEquals("The wrong number of links were built", RESULT_URL.length, directory.getLink().size());

        for(int  x = 0; x < RESULT_URL.length; x++) {
            assertEquals("The URL was not built correctly (x = " + x + ")", RESULT_URL[x], directory.getLink().get(x).getHref().toString());

        }
    }
}
