Search in sources :

Example 1 with BundleValidationServiceImpl

use of org.onebusaway.admin.service.bundle.impl.BundleValidationServiceImpl in project onebusaway-application-modules by camsys.

the class BundleValidationServiceImplTest method testGetServiceDateRange.

@Test
public void testGetServiceDateRange() throws Exception {
    BundleValidationServiceImpl impl = new BundleValidationServiceImpl();
    // load zip file
    InputStream input = this.getClass().getResourceAsStream("google_transit_staten_island.zip");
    assertNotNull(input);
    List<ServiceDateRange> ranges = impl.getServiceDateRanges(input);
    assertNotNull(ranges);
    assertTrue(ranges.size() == 4);
    ServiceDateRange sdr0 = ranges.get(0);
    assertEquals("MTA NYCT", sdr0.getAgencyId());
    assertEquals(2012, sdr0.getStartDate().getYear());
    assertEquals(4, sdr0.getStartDate().getMonth());
    assertEquals(8, sdr0.getStartDate().getDay());
    assertEquals(2012, sdr0.getEndDate().getYear());
    assertEquals(7, sdr0.getEndDate().getMonth());
    assertEquals(7, sdr0.getEndDate().getDay());
}
Also used : ServiceDateRange(org.onebusaway.admin.model.ServiceDateRange) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BundleValidationServiceImpl(org.onebusaway.admin.service.bundle.impl.BundleValidationServiceImpl) Test(org.junit.Test)

Example 2 with BundleValidationServiceImpl

use of org.onebusaway.admin.service.bundle.impl.BundleValidationServiceImpl in project onebusaway-application-modules by camsys.

the class BundleValidationServiceImplTest method testCommonServiceDateRangeAcrossGTFS.

@Test
public void testCommonServiceDateRangeAcrossGTFS() throws Exception {
    BundleValidationServiceImpl impl = new BundleValidationServiceImpl();
    // load zip file
    ArrayList<InputStream> inputs = new ArrayList<InputStream>();
    inputs.add(this.getClass().getResourceAsStream("google_transit_staten_island.zip"));
    inputs.add(this.getClass().getResourceAsStream("google_transit_manhattan.zip"));
    Map<String, List<ServiceDateRange>> map = impl.getServiceDateRangesAcrossAllGtfs(inputs);
    ServiceDateRange sdr0 = map.get("MTA NYCT").get(0);
    assertEquals(2012, sdr0.getStartDate().getYear());
    assertEquals(4, sdr0.getStartDate().getMonth());
    assertEquals(8, sdr0.getStartDate().getDay());
    assertEquals(2012, sdr0.getEndDate().getYear());
    assertEquals(7, sdr0.getEndDate().getMonth());
    assertEquals(7, sdr0.getEndDate().getDay());
}
Also used : ServiceDateRange(org.onebusaway.admin.model.ServiceDateRange) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BundleValidationServiceImpl(org.onebusaway.admin.service.bundle.impl.BundleValidationServiceImpl) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 3 with BundleValidationServiceImpl

use of org.onebusaway.admin.service.bundle.impl.BundleValidationServiceImpl in project onebusaway-application-modules by camsys.

the class BundleRequestServiceImplTest method setup.

@Before
public void setup() {
    BundleValidationServiceImpl validationService = new BundleValidationServiceImpl();
    service = new BundleRequestServiceImpl();
    service.setInstanceId("localhost");
    service.setup();
    FileService fileService = new S3FileServiceImpl() {

        @Override
        public void setup() {
        }

        @Override
        public boolean bundleDirectoryExists(String filename) {
            return !"noSuchDirectory".equals(filename);
        }

        @Override
        public boolean createBundleDirectory(String filename) {
            return true;
        }

        @Override
        public List<String[]> listBundleDirectories(int maxResults) {
            ArrayList<String[]> list = new ArrayList<String[]>();
            String[] columns = { "2012April/", "", "" + System.currentTimeMillis() };
            list.add(columns);
            return list;
        }

        @Override
        public List<String> list(String directory, int maxResults) {
            ArrayList<String> list = new ArrayList<String>();
            list.add("google_transit_brooklyn.zip");
            list.add("google_transit_staten_island.zip");
            return list;
        }

        @Override
        public String get(String key, String tmpDir) {
            InputStream input = this.getClass().getResourceAsStream("empty_feed.zip");
            String destination = "/tmp/empty_feed.zip.html";
            new NYCFileUtils().copy(input, destination);
            return destination;
        }

        @Override
        public String put(String key, String tmpDir) {
            // no op
            return null;
        }
    };
    fileService.setup();
    fileService.setBucketName("obanyc-bundle-data-test");
    BundleServerServiceImpl bundleServer = new BundleServerServiceImpl() {

        @Override
        public void setup() {
        // no op
        }

        @Override
        public String start(String instanceId) {
            return instanceId;
        }

        @Override
        public String pollPublicDns(String instanceId, int maxWaitSeconds) {
            return "localhost";
        }

        @Override
        public String findPublicDns(String instanceId) {
            return "localhost";
        }

        @Override
        public String findPublicIp(String instanceId) {
            return "127.0.0.1";
        }

        @Override
        public String stop(String instanceId) {
            return instanceId;
        }

        @Override
        public boolean ping(String instanceId) {
            return true;
        }

        @SuppressWarnings("unchecked")
        @Override
        public <T> T makeRequest(String instanceId, String apiCall, Object payload, Class<T> returnType, int waitTimeInSeconds, Map params, String sessionId) {
            _log.debug("makeRequest called with apiCall=" + apiCall + " and payload=" + payload);
            if (apiCall.equals("/validate/remote/2012Jan/test_0/1/create")) {
                BundleResponse br = new BundleResponse("1");
                return (T) br;
            } else if (apiCall.equals("/build/remote/2012Jan/test_0/null/1/2012-04-08/2012-07-07/create") || apiCall.equals("/build/remote/create")) {
                BundleBuildResponse br = new BundleBuildResponse("1");
                return (T) br;
            } else if (apiCall.equals("/ping/remote")) {
                return (T) "{1}";
            } else if (apiCall.equals("/validate/remote/1/list")) {
                BundleResponse br = new BundleResponse("1");
                br.addValidationFile("file1");
                br.addValidationFile("file2");
                br.setComplete(true);
                return (T) br;
            } else if (apiCall.equals("/build/remote/1/list")) {
                BundleBuildResponse br = new BundleBuildResponse("1");
                br.addGtfsFile("file1");
                br.addGtfsFile("file2");
                br.setComplete(true);
                return (T) br;
            } else {
                _log.error("unmatched apiCall=|" + apiCall + "|");
            }
            return null;
        }
    };
    bundleServer.setEc2User("user");
    bundleServer.setEc2Password("password");
    bundleServer.setup();
    service.setBundleServerService(bundleServer);
    validationService.setFileService(fileService);
}
Also used : FileService(org.onebusaway.admin.service.FileService) BundleResponse(org.onebusaway.admin.model.BundleResponse) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) BundleServerServiceImpl(org.onebusaway.admin.service.server.impl.BundleServerServiceImpl) S3FileServiceImpl(org.onebusaway.admin.service.impl.S3FileServiceImpl) NYCFileUtils(org.onebusaway.admin.util.NYCFileUtils) BundleValidationServiceImpl(org.onebusaway.admin.service.bundle.impl.BundleValidationServiceImpl) BundleRequestServiceImpl(org.onebusaway.admin.service.impl.BundleRequestServiceImpl) BundleBuildResponse(org.onebusaway.admin.model.BundleBuildResponse) Map(java.util.Map) Before(org.junit.Before)

Example 4 with BundleValidationServiceImpl

use of org.onebusaway.admin.service.bundle.impl.BundleValidationServiceImpl in project onebusaway-application-modules by camsys.

the class BundleValidationServiceImplTest method testCommonServiceDateRange.

@Test
public void testCommonServiceDateRange() throws Exception {
    BundleValidationServiceImpl impl = new BundleValidationServiceImpl();
    // load zip file
    InputStream input = this.getClass().getResourceAsStream("google_transit_staten_island.zip");
    assertNotNull(input);
    List<ServiceDateRange> ranges = impl.getServiceDateRanges(input);
    Map<String, List<ServiceDateRange>> map = impl.getServiceDateRangesByAgencyId(ranges);
    ServiceDateRange sdr0 = map.get("MTA NYCT").get(0);
    assertEquals("MTA NYCT", sdr0.getAgencyId());
    assertEquals(2012, sdr0.getStartDate().getYear());
    assertEquals(4, sdr0.getStartDate().getMonth());
    assertEquals(8, sdr0.getStartDate().getDay());
    assertEquals(2012, sdr0.getEndDate().getYear());
    assertEquals(7, sdr0.getEndDate().getMonth());
    assertEquals(7, sdr0.getEndDate().getDay());
}
Also used : ServiceDateRange(org.onebusaway.admin.model.ServiceDateRange) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BundleValidationServiceImpl(org.onebusaway.admin.service.bundle.impl.BundleValidationServiceImpl) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 5 with BundleValidationServiceImpl

use of org.onebusaway.admin.service.bundle.impl.BundleValidationServiceImpl in project onebusaway-application-modules by camsys.

the class BundleValidationServiceImplTest method testValidateGtfs.

// @Test
public void testValidateGtfs() throws Exception {
    BundleValidationServiceImpl impl = new BundleValidationServiceImpl();
    InputStream source = this.getClass().getResourceAsStream("gtfs-m34.zip");
    assertNotNull(source);
    String goodFeedFilename = getTmpDir() + File.separatorChar + "good_feed.zip";
    new NYCFileUtils().copy(source, goodFeedFilename);
    assertTrue(new File(goodFeedFilename).exists());
    String emptyFeedFilename = getTmpDir() + File.separatorChar + "good_feed.zip";
    assertTrue(new File(emptyFeedFilename).exists());
    String feedFilename = getTmpDir() + File.separatorChar + "feed.html";
    int rc = impl.installAndValidateGtfs(emptyFeedFilename, feedFilename);
    // feedValidator exits with returnCode 1
    if (rc == 2) {
        throw new RuntimeException("please execute this command: 'sudo ln -s /usr/bin/python /usr/bin/python2.5'");
    }
    assertEquals(1, rc);
    File output = new File(feedFilename);
    assertTrue(output.exists());
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) NYCFileUtils(org.onebusaway.admin.util.NYCFileUtils) BundleValidationServiceImpl(org.onebusaway.admin.service.bundle.impl.BundleValidationServiceImpl) File(java.io.File)

Aggregations

InputStream (java.io.InputStream)5 BundleValidationServiceImpl (org.onebusaway.admin.service.bundle.impl.BundleValidationServiceImpl)5 FileInputStream (java.io.FileInputStream)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 ServiceDateRange (org.onebusaway.admin.model.ServiceDateRange)3 List (java.util.List)2 NYCFileUtils (org.onebusaway.admin.util.NYCFileUtils)2 File (java.io.File)1 Map (java.util.Map)1 Before (org.junit.Before)1 BundleBuildResponse (org.onebusaway.admin.model.BundleBuildResponse)1 BundleResponse (org.onebusaway.admin.model.BundleResponse)1 FileService (org.onebusaway.admin.service.FileService)1 BundleRequestServiceImpl (org.onebusaway.admin.service.impl.BundleRequestServiceImpl)1 S3FileServiceImpl (org.onebusaway.admin.service.impl.S3FileServiceImpl)1 BundleServerServiceImpl (org.onebusaway.admin.service.server.impl.BundleServerServiceImpl)1