Search in sources :

Example 1 with FileService

use of org.onebusaway.admin.service.FileService in project onebusaway-application-modules by camsys.

the class BundleBuildingServiceImplTest method setup.

public void setup() {
    _service = new BundleBuildingServiceImpl() {

        @Override
        public String getDefaultAgencyId() {
            return null;
        }
    };
    _service.setDebug(true);
    FileService 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[] columns0 = { "2012April", "", "" + System.currentTimeMillis() };
            list.add(columns0);
            String[] columns1 = { "2012Jan", "", "" + System.currentTimeMillis() };
            list.add(columns1);
            String[] columns2 = { "2011April", "", "" + System.currentTimeMillis() };
            list.add(columns2);
            String[] columns3 = { "2011Jan", "", "" + System.currentTimeMillis() };
            list.add(columns3);
            String[] columns4 = { "2010April", "", "" + System.currentTimeMillis() };
            list.add(columns4);
            String[] columns5 = { "2010Jan", "", "" + System.currentTimeMillis() };
            list.add(columns5);
            return list;
        }

        @Override
        public List<String> list(String directory, int maxResults) {
            _log.debug("list called with " + directory);
            ArrayList<String> list = new ArrayList<String>();
            if (directory.equals("test/gtfs_latest")) {
                list.add("gtfs-m34.zip");
            } else if (directory.equals("test/aux_latest")) {
                if ("true".equals(_service.getAuxConfig())) {
                    list.add(CT_GIS_ZIP);
                    list.add(CT_SCHEDULE_ZIP);
                } else {
                    list.add("stif-m34.zip");
                }
            } else if (directory.equals("test/config")) {
            // do nothing
            } else {
                throw new RuntimeException("file not found for dir=" + directory);
            }
            return list;
        }

        @Override
        public String get(String key, String tmpDir) {
            _log.debug("get called with " + key);
            InputStream source = null;
            if (key.equals("gtfs-m34.zip")) {
                source = this.getClass().getResourceAsStream("gtfs-m34.zip");
            } else if (key.equals("stif-m34.zip")) {
                source = this.getClass().getResourceAsStream("stif-m34.zip");
            } else if (key.equals(CT_GIS_ZIP)) {
                source = this.getClass().getResourceAsStream(CT_GIS_ZIP);
            } else if (key.equals(CT_SCHEDULE_ZIP)) {
                source = this.getClass().getResourceAsStream(CT_SCHEDULE_ZIP);
            } else {
                throw new RuntimeException("unmatched key=" + key + " for tmpDir=" + tmpDir);
            }
            String filename = tmpDir + File.separator + key;
            _log.info("copying " + source + " to " + filename);
            new NYCFileUtils().copy(source, filename);
            return filename;
        }

        @Override
        public String put(String key, String file) {
            // do nothing
            return null;
        }
    };
    fileService.setBucketName("obanyc-bundle-data");
    fileService.setGtfsPath("gtfs_latest");
    fileService.setAuxPath("aux_latest");
    fileService.setBuildPath("builds");
    fileService.setConfigPath("config");
    fileService.setup();
    // uncomment for s3
    // fileService = new FileServiceImpl();
    // fileService.setBucketName("obanyc-bundle-data");
    // fileService.setGtfsPath("gtfs_latest");
    // fileService.setStifPath("stif_latest");
    // fileService.setBuildPath("builds");
    // fileService.setConfigPath("config");
    // fileService.setup();
    _service.setFileService(fileService);
    _service.setup();
}
Also used : FileService(org.onebusaway.admin.service.FileService) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) S3FileServiceImpl(org.onebusaway.admin.service.impl.S3FileServiceImpl) BundleBuildingServiceImpl(org.onebusaway.admin.service.bundle.impl.BundleBuildingServiceImpl) NYCFileUtils(org.onebusaway.admin.util.NYCFileUtils) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with FileService

use of org.onebusaway.admin.service.FileService 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)

Aggregations

InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 FileService (org.onebusaway.admin.service.FileService)2 S3FileServiceImpl (org.onebusaway.admin.service.impl.S3FileServiceImpl)2 NYCFileUtils (org.onebusaway.admin.util.NYCFileUtils)2 List (java.util.List)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 BundleBuildingServiceImpl (org.onebusaway.admin.service.bundle.impl.BundleBuildingServiceImpl)1 BundleValidationServiceImpl (org.onebusaway.admin.service.bundle.impl.BundleValidationServiceImpl)1 BundleRequestServiceImpl (org.onebusaway.admin.service.impl.BundleRequestServiceImpl)1 BundleServerServiceImpl (org.onebusaway.admin.service.server.impl.BundleServerServiceImpl)1