package com.agilex.healthcare.schedulingmanager.linkbuilder;

import com.agilex.healthcare.mobilehealthplatform.domain.PatientIdentifier;
import com.agilex.healthcare.schedulingmanager.domain.BookedAppointment;
import com.agilex.healthcare.schedulingmanager.domain.BookedAppointments;
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.net.URI;
import java.net.URISyntaxException;

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

    public static final String    TEST_URI = "http://localhost:8080/MobileHealthcare";
    public static final String    TEST_FACILITY = "777";
    public static final String    PROVIDER_ID = "987654321";

    public static final String      RESULT_URL = TEST_URI + "/scheduling-service/site/"
                                                + TEST_FACILITY + "/patient/" + TEST_FACILITY + "/"
                                                + PROVIDER_ID + "/cancel-appointment";

    @Before
    public void setup() {

    }

    @After
    public void teardown() {

    }

    @Test
    public void  testFillLinks()
            throws URISyntaxException {
        SchedulingLinkBuilder linkBuilder = new SchedulingLinkBuilder(new URI(TEST_URI));
        BookedAppointments appointments = new BookedAppointments();
        BookedAppointment appointment = new BookedAppointment();
        BookedAppointments returnedAppointments;
        PatientIdentifier patientIdentifier = new PatientIdentifier(TEST_FACILITY, PROVIDER_ID);

        appointment.setPatientId(patientIdentifier.toString());
        appointments.add(appointment);

        returnedAppointments = linkBuilder.fillLinks(appointments, patientIdentifier, TEST_FACILITY);

        assertEquals("The URL was not built correctly", RESULT_URL, returnedAppointments.get(0).getLink().get(0).getHref().toString());
    }
}
