@Transactional @Override public void removeAll(User user, List<Company> companies, boolean propagate) throws ChouetteException { for (Company company : companies) { INeptuneManager<Line> lineManager = (INeptuneManager<Line>) getManager(Line.class); INeptuneManager<VehicleJourney> vjManager = (INeptuneManager<VehicleJourney>) getManager(VehicleJourney.class); Filter filter = Filter.getNewEqualsFilter("company.id", company.getId()); List<Line> lines = lineManager.getAll(user, filter); List<VehicleJourney> vehicleJourneys = vjManager.getAll(user, filter); if (propagate) { lineManager.removeAll(user, lines, propagate); vjManager.removeAll(user, vehicleJourneys, propagate); } else { for (Line line : lines) { line.setCompany(null); lineManager.update(user, line); } for (VehicleJourney vehicleJourney : vehicleJourneys) { vehicleJourney.setCompany(null); vjManager.update(user, vehicleJourney); } } } super.removeAll(user, companies, propagate); }
@Test( groups = {"ExportLine"}, description = "Export Plugin should export file", dependsOnMethods = {"getBean", "getNeptuneFile"}) public void verifyExportLine() throws ChouetteException { List<Line> lines = importLines(); // export data { List<ParameterValue> parameters = new ArrayList<ParameterValue>(); SimpleParameterValue simpleParameterValue = new SimpleParameterValue("outputFile"); simpleParameterValue.setFilepathValue(targetPath + "/" + neptuneFile); parameters.add(simpleParameterValue); ReportHolder report = new ReportHolder(); exportLine.doExport(lines, parameters, report); } List<ParameterValue> parameters = new ArrayList<ParameterValue>(); SimpleParameterValue simpleParameterValue = new SimpleParameterValue("inputFile"); simpleParameterValue.setFilepathValue(targetPath + "/" + neptuneFile); parameters.add(simpleParameterValue); ReportHolder report = new ReportHolder(); lines = importLine.doImport(parameters, report); printReport(report.getReport()); Assert.assertNotNull(lines, "lines can't be null"); Assert.assertEquals(lines.size(), 1, "lines size must equals 1"); for (Line line : lines) { Set<Facility> facilities = new HashSet<Facility>(); // comptage des objets : Assert.assertNotNull(line.getPtNetwork(), "line must have a network"); Assert.assertNotNull(line.getGroupOfLines(), "line must have groupOfLines"); Assert.assertEquals(line.getGroupOfLines().size(), 1, "line must have 1 groupOfLine"); Assert.assertNotNull(line.getCompany(), "line must have a company"); Assert.assertNotNull(line.getRoutes(), "line must have routes"); Assert.assertEquals(line.getRoutes().size(), 4, "line must have 4 routes"); Set<StopArea> bps = new HashSet<StopArea>(); Set<StopArea> comms = new HashSet<StopArea>(); if (line.getFacilities() != null) facilities.addAll(line.getFacilities()); for (Route route : line.getRoutes()) { Assert.assertNotNull(route.getJourneyPatterns(), "line routes must have journeyPattens"); for (JourneyPattern jp : route.getJourneyPatterns()) { Assert.assertNotNull(jp.getStopPoints(), "line journeyPattens must have stoppoints"); for (StopPoint point : jp.getStopPoints()) { if (point.getFacilities() != null) facilities.addAll(point.getFacilities()); Assert.assertNotNull(point.getContainedInStopArea(), "stoppoints must have StopAreas"); bps.add(point.getContainedInStopArea()); Assert.assertNotNull( point.getContainedInStopArea().getParent(), "StopAreas must have parent : " + point.getContainedInStopArea().getObjectId()); comms.add(point.getContainedInStopArea().getParent()); } } } Assert.assertEquals(bps.size(), 18, "line must have 18 boarding positions"); Assert.assertEquals(comms.size(), 9, "line must have 9 commercial stop points"); Set<ConnectionLink> clinks = new HashSet<ConnectionLink>(); Set<AccessLink> alinks = new HashSet<AccessLink>(); for (StopArea bp : bps) { if (bp.getFacilities() != null) facilities.addAll(bp.getFacilities()); } for (StopArea comm : comms) { if (comm.getFacilities() != null) facilities.addAll(comm.getFacilities()); if (comm.getConnectionLinks() != null) { clinks.addAll(comm.getConnectionLinks()); } if (comm.getAccessLinks() != null) { alinks.addAll(comm.getAccessLinks()); } } Assert.assertEquals(clinks.size(), 2, "line must have 2 connection link"); Calendar c = Calendar.getInstance(); for (ConnectionLink connectionLink : clinks) { if (connectionLink.getFacilities() != null) facilities.addAll(connectionLink.getFacilities()); c.setTimeInMillis(connectionLink.getDefaultDuration().getTime()); int minutes = c.get(Calendar.MINUTE); int hours = c.get(Calendar.HOUR_OF_DAY); int seconds = c.get(Calendar.SECOND) + minutes * 60 + hours * 3600; Assert.assertEquals(seconds, 600, "line must have links duration of 10 minutes"); Reporter.log(connectionLink.toString("\t", 1)); } Assert.assertEquals(alinks.size(), 1, "line must have 1 access link"); Set<AccessPoint> apoints = new HashSet<AccessPoint>(); for (AccessLink accessLink : alinks) { c.setTimeInMillis(accessLink.getDefaultDuration().getTime()); int minutes = c.get(Calendar.MINUTE); int hours = c.get(Calendar.HOUR_OF_DAY); int seconds = c.get(Calendar.SECOND) + minutes * 60 + hours * 3600; Assert.assertEquals(seconds, 600, "line must have links duration of 10 minutes"); Reporter.log(accessLink.toString("\t", 1)); apoints.add(accessLink.getAccessPoint()); } Assert.assertEquals(apoints.size(), 1, "line must have 1 access point"); for (AccessPoint accessPoint : apoints) { c.setTimeInMillis(accessPoint.getOpeningTime().getTime()); int minutes = c.get(Calendar.MINUTE); int hours = c.get(Calendar.HOUR_OF_DAY); int seconds = c.get(Calendar.SECOND) + minutes * 60 + hours * 3600; Assert.assertEquals(seconds, 6 * 3600, "line must have opening time of 6 hours"); c.setTimeInMillis(accessPoint.getClosingTime().getTime()); minutes = c.get(Calendar.MINUTE); hours = c.get(Calendar.HOUR_OF_DAY); seconds = c.get(Calendar.SECOND) + minutes * 60 + hours * 3600; Assert.assertEquals(seconds, 23 * 3600, "line must have opening time of 23 hours"); } // Assert.assertEquals(facilities.size(),1,"line must have 1 facility"); // for (Facility facility : facilities) // { // Assert.assertNotNull(facility.getFacilityFeatures(),"Facility must have features // : "+facility.getObjectId()); // Assert.assertEquals(facility.getFacilityFeatures().size(),1,"Facility must have // 1 feature : "+facility.getObjectId()); // for (FacilityFeature feature : facility.getFacilityFeatures()) // { // Assert.assertNotNull(feature.getChoiceValue(),"feature must have choice"); // Assert.assertEquals(feature.getAccessFacility(), // AccessFacilityEnumeration.BARRIER,"feature must be BARRIER"); // } // } } }