-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a test for single file skipped validators.
Reformatted the output
- Loading branch information
Showing
10 changed files
with
303 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
core/src/test/java/org/mobilitydata/gtfsvalidator/testgtfs/GtfsTestMultiFileValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2021 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.mobilitydata.gtfsvalidator.testgtfs; | ||
|
||
import javax.inject.Inject; | ||
import org.mobilitydata.gtfsvalidator.notice.NoticeContainer; | ||
import org.mobilitydata.gtfsvalidator.validator.FileValidator; | ||
|
||
public class GtfsTestMultiFileValidator extends FileValidator { | ||
|
||
private final GtfsTestTableContainer table; | ||
private final GtfsTestTableContainer2 unparsableTable; | ||
|
||
@Inject | ||
public GtfsTestMultiFileValidator(GtfsTestTableContainer table, GtfsTestTableContainer2 table2) { | ||
this.table = table; | ||
this.unparsableTable = table2; | ||
} | ||
|
||
@Override | ||
public void validate(NoticeContainer noticeContainer) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
core/src/test/java/org/mobilitydata/gtfsvalidator/testgtfs/GtfsTestTableContainer2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright 2021 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.mobilitydata.gtfsvalidator.testgtfs; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import org.mobilitydata.gtfsvalidator.notice.NoticeContainer; | ||
import org.mobilitydata.gtfsvalidator.parsing.CsvHeader; | ||
import org.mobilitydata.gtfsvalidator.table.GtfsTableContainer; | ||
|
||
// We need a second test table class to test multi file validators. | ||
public class GtfsTestTableContainer2 extends GtfsTableContainer<GtfsTestEntity> { | ||
private static final ImmutableList<String> KEY_COLUMN_NAMES = | ||
ImmutableList.of(GtfsTestEntity.ID_FIELD_NAME); | ||
|
||
private List<GtfsTestEntity> entities; | ||
|
||
private GtfsTestTableContainer2( | ||
GtfsTestTableDescriptor2 descriptor, CsvHeader header, List<GtfsTestEntity> entities) { | ||
super(descriptor, TableStatus.PARSABLE_HEADERS_AND_ROWS, header); | ||
this.entities = entities; | ||
} | ||
|
||
public GtfsTestTableContainer2(TableStatus tableStatus) { | ||
super(new GtfsTestTableDescriptor2(), tableStatus, CsvHeader.EMPTY); | ||
this.entities = new ArrayList<>(); | ||
} | ||
|
||
@Override | ||
public Class<GtfsTestEntity> getEntityClass() { | ||
return GtfsTestEntity.class; | ||
} | ||
|
||
@Override | ||
public String gtfsFilename() { | ||
return GtfsTestEntity.FILENAME + "2"; | ||
} | ||
|
||
@Override | ||
public List<GtfsTestEntity> getEntities() { | ||
return entities; | ||
} | ||
|
||
/** Creates a table with given header and entities */ | ||
public static GtfsTestTableContainer2 forHeaderAndEntities( | ||
GtfsTestTableDescriptor2 descriptor, | ||
CsvHeader header, | ||
List<GtfsTestEntity> entities, | ||
NoticeContainer noticeContainer) { | ||
GtfsTestTableContainer2 table = new GtfsTestTableContainer2(descriptor, header, entities); | ||
return table; | ||
} | ||
|
||
@Override | ||
public ImmutableList<String> getKeyColumnNames() { | ||
return KEY_COLUMN_NAMES; | ||
} | ||
|
||
@Override | ||
public Optional<GtfsTestEntity> byTranslationKey(String recordId, String recordSubId) { | ||
return Optional.empty(); | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
core/src/test/java/org/mobilitydata/gtfsvalidator/testgtfs/GtfsTestTableDescriptor2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package org.mobilitydata.gtfsvalidator.testgtfs; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableMap; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import org.mobilitydata.gtfsvalidator.annotation.FieldLevelEnum; | ||
import org.mobilitydata.gtfsvalidator.notice.NoticeContainer; | ||
import org.mobilitydata.gtfsvalidator.parsing.CsvHeader; | ||
import org.mobilitydata.gtfsvalidator.parsing.FieldCache; | ||
import org.mobilitydata.gtfsvalidator.parsing.RowParser; | ||
import org.mobilitydata.gtfsvalidator.table.*; | ||
|
||
// We need a second test table descriptor to test multi file contaioners | ||
public class GtfsTestTableDescriptor2 extends GtfsTableDescriptor<GtfsTestEntity> { | ||
@Override | ||
public GtfsTableContainer createContainerForInvalidStatus( | ||
GtfsTableContainer.TableStatus tableStatus) { | ||
return new GtfsTestTableContainer2(tableStatus); | ||
} | ||
|
||
@Override | ||
public GtfsTableContainer createContainerForHeaderAndEntities( | ||
CsvHeader header, List<GtfsTestEntity> entities, NoticeContainer noticeContainer) { | ||
return GtfsTestTableContainer2.forHeaderAndEntities(this, header, entities, noticeContainer); | ||
} | ||
|
||
@Override | ||
public GtfsEntityBuilder createEntityBuilder() { | ||
return new GtfsTestEntity.Builder(); | ||
} | ||
|
||
@Override | ||
public Class getEntityClass() { | ||
return GtfsTestEntity.class; | ||
} | ||
|
||
@Override | ||
public ImmutableList<GtfsColumnDescriptor> getColumns() { | ||
ImmutableList.Builder<GtfsColumnDescriptor> builder = ImmutableList.builder(); | ||
builder.add( | ||
GtfsColumnDescriptor.builder() | ||
.setColumnName(GtfsTestEntity.ID_FIELD_NAME) | ||
.setHeaderRequired(true) | ||
.setHeaderRecommended(false) | ||
.setFieldLevel(FieldLevelEnum.REQUIRED) | ||
.setIsMixedCase(false) | ||
.setIsCached(false) | ||
.build()); | ||
builder.add( | ||
GtfsColumnDescriptor.builder() | ||
.setColumnName(GtfsTestEntity.CODE_FIELD_NAME) | ||
.setHeaderRequired(false) | ||
.setHeaderRecommended(false) | ||
.setFieldLevel(FieldLevelEnum.OPTIONAL) | ||
.setIsMixedCase(false) | ||
.setIsCached(false) | ||
.build()); | ||
return builder.build(); | ||
} | ||
|
||
@Override | ||
public ImmutableMap<String, GtfsFieldLoader> getFieldLoaders() { | ||
ImmutableMap.Builder<String, GtfsFieldLoader> builder = ImmutableMap.builder(); | ||
builder.put( | ||
GtfsTestEntity.ID_FIELD_NAME, | ||
new GtfsFieldLoader<GtfsTestEntity.Builder, String>() { | ||
@Override | ||
public void load( | ||
RowParser rowParser, | ||
int columnIndex, | ||
GtfsColumnDescriptor columnDescriptor, | ||
FieldCache<String> fieldCache, | ||
GtfsTestEntity.Builder builder) { | ||
builder.setId( | ||
addToCacheIfPresent(rowParser.asId(columnIndex, columnDescriptor), fieldCache)); | ||
} | ||
}); | ||
builder.put( | ||
GtfsTestEntity.CODE_FIELD_NAME, | ||
new GtfsFieldLoader<GtfsTestEntity.Builder, String>() { | ||
@Override | ||
public void load( | ||
RowParser rowParser, | ||
int columnIndex, | ||
GtfsColumnDescriptor columnDescriptor, | ||
FieldCache<String> fieldCache, | ||
GtfsTestEntity.Builder builder) { | ||
builder.setCode( | ||
addToCacheIfPresent(rowParser.asText(columnIndex, columnDescriptor), fieldCache)); | ||
} | ||
}); | ||
return builder.build(); | ||
} | ||
|
||
@Override | ||
public String gtfsFilename() { | ||
return GtfsTestEntity.FILENAME + "2"; | ||
} | ||
|
||
@Override | ||
public boolean isRecommended() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean isRequired() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public Optional<Integer> maxCharsPerColumn() { | ||
return Optional.empty(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.