package org.motechproject.appointments.api.osgi;

import org.motechproject.appointments.api.service.AppointmentService;
import org.motechproject.appointments.api.service.contract.CreateVisitRequest;
import org.motechproject.appointments.api.service.contract.VisitResponse;
import org.motechproject.testing.osgi.BaseOsgiIT;
import org.osgi.framework.ServiceReference;

import java.util.List;
import java.util.UUID;

import static java.util.Arrays.asList;

public class AppointmentsApiBundleIT extends BaseOsgiIT {

    public void testAppointmentService() {
        ServiceReference serviceReference = bundleContext.getServiceReference(AppointmentService.class.getName());
        assertNotNull(serviceReference);
        AppointmentService appointmentService = (AppointmentService) bundleContext.getService(serviceReference);
        assertNotNull(appointmentService);

        final String externalId = "AppointmentsApiBundleIT-" + UUID.randomUUID();
        String visitName = "Visit-" + externalId;
        CreateVisitRequest request = new CreateVisitRequest().setVisitName(visitName);
        appointmentService.addVisit(externalId, request);
        VisitResponse response = appointmentService.findVisit(externalId, visitName);
        assertNotNull(response);
        assertEquals(visitName, response.getName());
        // Delete the doc in the post-integration phase
    }

    @Override
    protected List<String> getImports() {
        return asList(
                "org.motechproject.appointments.api.service.contract",
                "org.motechproject.appointments.api.service"
        );
    }
}

@@ -319,52 +319,8 @@
 iIT;
-%0Aimport org.osgi.framework.ServiceReference;
 %0A%0Aim
@@ -518,165 +518,28 @@
     
-ServiceReference serviceReference = bundleContext.getServiceReference(AppointmentService.class.getName());%0A        assertNotNull(serviceReference);%0A        A
+AppointmentService a
 ppoi
@@ -552,34 +552,28 @@
 Service 
-appointmen
+= ge
 tService
  = (Appo
@@ -564,19 +564,16 @@
 tService
- = 
 (Appoint
@@ -587,94 +587,14 @@
 vice
-) bundleContext.getService(serviceReference);%0A        assertNotNull(appointmentService
+.class
 );%0A%0A

Remove redundant code from bundle ITs