Skip to content

Commit

Permalink
Parse NeTEx Resource frame without organisation
Browse files Browse the repository at this point in the history
  • Loading branch information
vpaturet committed Aug 30, 2023
1 parent 36edab0 commit 3321053
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ void setResultOnIndex(NetexEntityIndex netexIndex) {
/* private methods */

private void parseOrganization(OrganisationsInFrame_RelStructure elements) {
for (JAXBElement<?> e : elements.getOrganisation_()) {
parseOrganization((Organisation_VersionStructure) e.getValue());
if (elements != null) {
for (JAXBElement<?> e : elements.getOrganisation_()) {
parseOrganization((Organisation_VersionStructure) e.getValue());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.opentripplanner.netex.loader.parser;

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

import jakarta.xml.bind.JAXBElement;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.opentripplanner.netex.index.NetexEntityIndex;
import org.rutebanken.netex.model.Authority;
import org.rutebanken.netex.model.DataManagedObjectStructure;
import org.rutebanken.netex.model.ObjectFactory;
import org.rutebanken.netex.model.ResourceFrame;

class ResourceFrameParserTest {

private ResourceFrameParser resourceFrameParser;
private ResourceFrame resourceFrame;
private ObjectFactory objectFactory;
private NetexEntityIndex netexEntityIndex;

@BeforeEach
void setUp() {
resourceFrameParser = new ResourceFrameParser();
resourceFrame = new ResourceFrame();
objectFactory = new ObjectFactory();
netexEntityIndex = new NetexEntityIndex();
}

@Test
void testResourceFrameWithOrganization() {
JAXBElement<? extends DataManagedObjectStructure> organisation = objectFactory.createAuthority(
new Authority()
);
resourceFrame.setOrganisations(objectFactory.createOrganisationsInFrame_RelStructure());
resourceFrame.getOrganisations().getOrganisation_().add(organisation);
resourceFrameParser.parse(resourceFrame);
resourceFrameParser.setResultOnIndex(netexEntityIndex);
assertEquals(1, netexEntityIndex.authoritiesById.size());
}

@Test
void testResourceFrameWithoutOrganization() {
resourceFrameParser.parse(resourceFrame);
resourceFrameParser.setResultOnIndex(netexEntityIndex);
assertEquals(0, netexEntityIndex.authoritiesById.size());
}
}

0 comments on commit 3321053

Please sign in to comment.