Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ protected void innerJobLogic() throws Exception {
// Validate and check for blocking issues in the feed version to deploy.
if (latestFeedVersion.hasExpired()) {
status.fail("Could not publish this feed version because it has expired.");
} else if (latestFeedVersion.isFuture()) {
status.fail("Could not publish this feed version because it is in the future.");
} else if (latestFeedVersion.hasBlockingIssuesForPublishing()) {
status.fail("Could not publish this feed version because it contains blocking errors.");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,21 @@ public static boolean hasExpired(ValidationResult validationResult) {
getNowAsLocalDate().isAfter(validationResult.lastCalendarDate);
}

/**
* Whether the Has this feed expired?
* @return If the validation result last calendar date is null or has expired return true, else return false.
*/
@JsonIgnore
@BsonIgnore
public boolean isFuture() {
return isFuture(validationResult);
}

public static boolean isFuture(ValidationResult validationResult) {
return validationResult.firstCalendarDate != null &&
getNowAsLocalDate().isBefore(validationResult.firstCalendarDate);
}

private static LocalDate getNowAsLocalDate() {
return dateOverrideForTesting == null ? LocalDate.now() : dateOverrideForTesting;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ private boolean isPublishBlocked() {
!gtfsPlusValidation.issues.isEmpty() ||
!gtfsPlusValidation.published ||
FeedVersion.hasExpired(validationResult) ||
FeedVersion.isFuture(validationResult) ||
hasBlockingIssuesForPublishing();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.conveyal.datatools.manager.models.FeedSourceSummary;
import com.conveyal.datatools.manager.models.FeedValidationResultSummary;
import com.conveyal.datatools.manager.models.FeedVersion;
import com.conveyal.datatools.manager.models.FeedVersionSummary;
import com.conveyal.datatools.manager.models.FetchFrequency;
import com.conveyal.datatools.manager.models.Label;
import com.conveyal.datatools.manager.models.Note;
Expand All @@ -27,21 +26,16 @@
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.LocalDate;
import java.time.Month;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.stream.Stream;

import static com.conveyal.datatools.TestUtils.createFeedVersionFromGtfsZip;
import static com.mongodb.client.model.Filters.eq;
Expand All @@ -51,7 +45,7 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

public class FeedSourceControllerTest extends DatatoolsTest {
class FeedSourceControllerTest extends DatatoolsTest {
private static Project project = null;
private static Project projectToBeDeleted = null;
private static FeedSource feedSourceWithUrl = null;
Expand All @@ -70,7 +64,7 @@ public class FeedSourceControllerTest extends DatatoolsTest {
private static FeedVersion feedVersionFromPinnedDeployment = null;

@BeforeAll
public static void setUp() throws IOException {
static void settingUp() throws IOException {
DatatoolsTest.setUp();
Auth0Connection.setAuthDisabled(true);
ProcessSingleFeedJob.ENABLE_ADDITIONAL_VALIDATION = false;
Expand Down Expand Up @@ -206,7 +200,7 @@ private static void setUpFeedVersionFromPinnedDeployment() throws MalformedURLEx
}

@AfterAll
public static void tearDown() {
static void tearDown() {
Auth0Connection.setAuthDisabled(Auth0Connection.getDefaultAuthDisabled());
if (project != null) {
project.delete();
Expand Down Expand Up @@ -243,7 +237,7 @@ private static void tearDownDeployedFeedVersion() {
* 3. Update the same feed source turning auth fetch back on and confirm it is scheduled once more.
*/
@Test
public void createFeedSourceWithUrlTest() {
void createFeedSourceWithUrlTest() {
// create a feed source.
SimpleHttpResponse createFeedSourceResponse = TestUtils.makeRequest("/api/manager/secure/feedsource",
JsonUtil.toJson(feedSourceWithUrl),
Expand Down Expand Up @@ -278,7 +272,7 @@ public void createFeedSourceWithUrlTest() {
* Create a feed source without defining the feed source url. Confirm that the feed source is not scheduled.
*/
@Test
public void createFeedSourceWithNoUrlTest() {
void createFeedSourceWithNoUrlTest() {
SimpleHttpResponse createFeedSourceResponse = TestUtils.makeRequest("/api/manager/secure/feedsource",
JsonUtil.toJson(feedSourceWithNoUrl),
HttpUtils.REQUEST_METHOD.POST
Expand All @@ -292,7 +286,7 @@ public void createFeedSourceWithNoUrlTest() {
* Create some labels, add them to the feed source make them admin only, and check that they don't appear if not an admin
*/
@Test
public void createFeedSourceWithLabels() {
void createFeedSourceWithLabels() {
// Create labels
SimpleHttpResponse createFirstLabelResponse = TestUtils.makeRequest("/api/manager/secure/label",
JsonUtil.toJson(publicLabel),
Expand Down Expand Up @@ -439,72 +433,6 @@ void canRetrieveDeployedFeedVersionFromPinnedDeployment() throws IOException {
assertEquals(feedSourceWithPinnedDeploymentFeedVersion.publishedVersionId, firstSummary.publishedVersionId);
}

@ParameterizedTest
@MethodSource("createPublishStates")
void canDeterminePublishState(
boolean isPublished,
boolean isPublishing,
boolean isPublishBlocked,
boolean isFeedLoading,
PublishState expectedPublishState
) {
FeedSourceSummary feedSourceSummary = new FeedSourceSummary();
FeedVersionSummary feedVersionSummary = new FeedVersionSummary();
FeedVersion.setDateOverrideForTesting(LocalDate.now());

if (isPublished) {
feedVersionSummary.namespace = feedVersionSummary.feedSourcePublishedVersionId = "namespace";
}
if (isPublishing) {
feedVersionSummary.sentToExternalPublisher = new Date();
feedVersionSummary.processedByExternalPublisher = null;
}
if (isPublishBlocked) {
feedVersionSummary.gtfsPlusValidation = null;
}
if (!isPublished && !isPublishing && !isPublishBlocked && !isFeedLoading) {
// Ready to publish case.
FeedVersionSummary.setHasBlockingIssueForPublishingOverrideForTesting(false);
passPublishBlockedCheck(feedVersionSummary);

feedVersionSummary.validationResult.errorCount = 1;
feedVersionSummary.id = "feed-version-id";
feedSourceSummary.id = "feed-source-id";
}
PublishState publishState = feedVersionSummary.getPublishState();
assertEquals(expectedPublishState, publishState);
FeedVersionSummary.setHasBlockingIssueForPublishingOverrideForTesting(null);
}

/**
* Set up a feed version summary to pass the publish blocked check.
*/
private static void passPublishBlockedCheck(FeedVersionSummary feedVersionSummary) {
feedVersionSummary.gtfsPlusValidation = new GtfsPlusValidation();
feedVersionSummary.gtfsPlusValidation.issues = new ArrayList<>();
feedVersionSummary.gtfsPlusValidation.published = true;
feedVersionSummary.validationResult = new ValidationResult();
feedVersionSummary.validationResult.lastCalendarDate = LocalDate.now().plusDays(1);
FeedVersion.setDateOverrideForTesting(LocalDate.now());
}

private static Stream<Arguments> createPublishStates() {
return Stream.of(
Arguments.of(
true, false, false, false, PublishState.PUBLISHED
),
Arguments.of(
false, true, false, false, PublishState.PUBLISHING
),
Arguments.of(
false, false, true, false, PublishState.PUBLISH_BLOCKED
),
Arguments.of(
false, false, false, false, PublishState.READY_TO_PUBLISH
)
);
}

private static Project createProject(String name, boolean autoFetchFeeds) {
Project project = new Project();
project.name = name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
/**
* Tests for the various {@link AutoPublishJob} cases.
*/
public class AutoPublishJobTest extends UnitTest {
class AutoPublishJobTest extends UnitTest {
private static final String TEST_COMPLETED_FOLDER = "test-completed";
private static final Auth0UserProfile user = Auth0UserProfile.createTestAdminUser();
private static Project project;
Expand All @@ -52,7 +52,7 @@ public class AutoPublishJobTest extends UnitTest {
* Prepare and start a testing-specific web server
*/
@BeforeAll
public static void setUp() throws IOException {
static void setUp() throws IOException {
// start server if it isn't already running
DatatoolsTest.setUp();

Expand Down Expand Up @@ -92,7 +92,7 @@ void afterEach() {
}

@AfterAll
public static void tearDown() {
static void tearDown() {
Auth0Connection.setAuthDisabled(Auth0Connection.getDefaultAuthDisabled());
if (project != null) {
project.delete();
Expand Down Expand Up @@ -140,6 +140,7 @@ void shouldProcessFeed(String resourceName, LocalDate nowDate, boolean isError,

private static Stream<Arguments> createPublishFeedCases() {
LocalDate feedValidDate = LocalDate.of(2019, 3, 1);
LocalDate feedBeforeValidDate = LocalDate.of(2010, 3, 1);
return Stream.of(
Arguments.of(
"fake-agency-with-only-calendar-expire-in-2099-with-failed-referential-integrity",
Expand All @@ -164,6 +165,12 @@ private static Stream<Arguments> createPublishFeedCases() {
null,
true,
"Could not publish this feed version because it has expired."
),
Arguments.of(
"bart_new_lite.zip",
feedBeforeValidDate,
true,
"Could not publish this feed version because it is in the future."
)
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package com.conveyal.datatools.manager.models;

import com.conveyal.datatools.DatatoolsTest;
import com.conveyal.datatools.manager.gtfsplus.GtfsPlusValidation;
import com.conveyal.gtfs.validator.ValidationResult;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import java.io.IOException;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Date;
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.assertEquals;

class FeedVersionSummaryTest extends DatatoolsTest {
@BeforeAll
static void settingUp() throws IOException {
DatatoolsTest.setUp();
}

@AfterEach
void afterEach() {
FeedVersionSummary.setHasBlockingIssueForPublishingOverrideForTesting(null);
}

@ParameterizedTest
@MethodSource("createPublishStates")
void canDeterminePublishState(
boolean isPublished,
boolean isPublishing,
boolean isPublishBlocked,
boolean isFeedLoading,
PublishState expectedPublishState
) {
FeedSourceSummary feedSourceSummary = new FeedSourceSummary();
FeedVersionSummary feedVersionSummary = new FeedVersionSummary();
FeedVersion.setDateOverrideForTesting(LocalDate.now());

if (isPublished) {
feedVersionSummary.namespace = feedVersionSummary.feedSourcePublishedVersionId = "namespace";
}
if (isPublishing) {
feedVersionSummary.sentToExternalPublisher = new Date();
feedVersionSummary.processedByExternalPublisher = null;
}
if (isPublishBlocked) {
feedVersionSummary.gtfsPlusValidation = null;
}
if (!isPublished && !isPublishing && !isPublishBlocked && !isFeedLoading) {
// Ignore blocking issues.
FeedVersionSummary.setHasBlockingIssueForPublishingOverrideForTesting(false);
passPublishBlockedCheck(feedVersionSummary);

feedVersionSummary.validationResult.errorCount = 1;
feedVersionSummary.id = "feed-version-id";
feedSourceSummary.id = "feed-source-id";
}
PublishState publishState = feedVersionSummary.getPublishState();
assertEquals(expectedPublishState, publishState);
}

/**
* Set up a feed version summary to pass the publish blocked check.
*/
private static void passPublishBlockedCheck(FeedVersionSummary feedVersionSummary) {
feedVersionSummary.gtfsPlusValidation = new GtfsPlusValidation();
feedVersionSummary.gtfsPlusValidation.issues = new ArrayList<>();
feedVersionSummary.gtfsPlusValidation.published = true;
feedVersionSummary.validationResult = new ValidationResult();
feedVersionSummary.validationResult.lastCalendarDate = LocalDate.now().plusDays(1);
FeedVersion.setDateOverrideForTesting(LocalDate.now());
}

private static Stream<Arguments> createPublishStates() {
return Stream.of(
Arguments.of(true, false, false, false, PublishState.PUBLISHED),
Arguments.of(false, true, false, false, PublishState.PUBLISHING),
Arguments.of(false, false, true, false, PublishState.PUBLISH_BLOCKED),
Arguments.of(false, false, false, false, PublishState.READY_TO_PUBLISH)
);
}

/**
* Additional cases for future and expired feeds.
*/
@ParameterizedTest
@MethodSource("publishStateTimeCases")
void canGetPublishState(int daysOffsetFromToday, PublishState expectedState, String caseName) {
FeedVersionSummary feedVersionSummary = new FeedVersionSummary();
passPublishBlockedCheck(feedVersionSummary);
LocalDate date = LocalDate.now().plusDays(daysOffsetFromToday);
feedVersionSummary.validationResult.firstCalendarDate = date;
feedVersionSummary.validationResult.lastCalendarDate = date.plusDays(3);

// Ignore blocking issues.
FeedVersionSummary.setHasBlockingIssueForPublishingOverrideForTesting(false);
assertEquals(expectedState, feedVersionSummary.getPublishState(), caseName);
}

private static Stream<Arguments> publishStateTimeCases() {
return Stream.of(
Arguments.of(1, PublishState.PUBLISH_BLOCKED, "future feed"),
Arguments.of(0, PublishState.READY_TO_PUBLISH, "present feed"),
Arguments.of(-5, PublishState.PUBLISH_BLOCKED, "expired feed")
);
}
}
Loading
Loading