package com.agilex.healthcare.schedulingmanager.linkbuilder;

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

import junit.framework.TestCase;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.agilex.healthcare.mobilehealthplatform.domain.AtomLinks;
import com.agilex.healthcare.mobilehealthplatform.domain.Patient;
import com.agilex.healthcare.mobilehealthplatform.domain.PatientIdentifier;
import com.agilex.healthcare.schedulingmanager.domain.SMAppointmentRequest;

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

    public static final String      TEST_URI = "http://localhost:8080/MobileHealthcare";
    public static final String      TEST_FACILITY = "777";
    public static final String      ASSIGNING_ID = "assigning-id";
    public static final String      PATIENT_ID = "patient-id";
    public static final String      APPOINTMENT_REQUEST_ID = "appointment-request-id";

    public static final String      RESULT_URL_1 = TEST_URI + "/appointment-service/patient/"
                                    + ASSIGNING_ID + "/" + PATIENT_ID + "/appointment-requests/system/"
                                    + TEST_FACILITY + "/id/" + APPOINTMENT_REQUEST_ID + "/messages";

    public static final String      RESULT_URL_2 = TEST_URI + "/appointment-service/patient/"
                                    + ASSIGNING_ID + "/" + PATIENT_ID + "/appointment-requests/system/"
                                    + TEST_FACILITY + "/id/" + APPOINTMENT_REQUEST_ID + "/messages/read";

    public static final String      RESULT_URL_3 = TEST_URI + "/appointment-service/patient/"
                                    + ASSIGNING_ID + "/" + PATIENT_ID + "/appointment-requests/system/"
                                    + TEST_FACILITY + "/id/" + APPOINTMENT_REQUEST_ID + "/appointment/provider-read";

    @Before
    public void setup() {

    }

    @After
    public void teardown() {

    }

    @Test
    public void  testFillCustomRelatedLinks()
            throws URISyntaxException {
        AppointmentRequestLinkBuilder     linkBuilder = new AppointmentRequestLinkBuilder(new URI(TEST_URI));
        SMAppointmentRequest              appointmentRequest = new SMAppointmentRequest();
        Patient                           patient;
        AtomLinks                         links;

        patient = new Patient();
        patient.setPatientIdentifier(new PatientIdentifier(ASSIGNING_ID, PATIENT_ID));
        appointmentRequest.setPatient(patient);
        appointmentRequest.setPatientIdentifier(patient.getPatientIdentifier());
        appointmentRequest.setAppointmentRequestId(APPOINTMENT_REQUEST_ID);
        appointmentRequest.setSystemId(TEST_FACILITY);

        linkBuilder.fillCustomRelatedLinks(appointmentRequest);

        links = appointmentRequest.getLink();

        assertEquals("The URL was not built correctly", RESULT_URL_1, links.get(0).getHref().toString());
        assertEquals("The URL was not built correctly", RESULT_URL_2, links.get(1).getHref().toString());
        assertEquals("The URL was not built correctly", RESULT_URL_3, links.get(2).getHref().toString());
    }
}
