Archived
0

implement EDDN shipyard parser

This commit is contained in:
iMoHax
2016-10-05 17:24:07 +03:00
parent 4170d5d4e7
commit 0ac740bff2
8 changed files with 348 additions and 2 deletions

View File

@@ -255,4 +255,107 @@ public class ParserTest extends Assert {
}
@Test
public void testParseShipV1() throws Exception {
EMDNParser parser = new EMDNParser();
try (InputStream is = getClass().getResourceAsStream("/emdn/ship_v1.json")) {
String json = TestUtils.read(is);
Message message = parser.parse(json);
assertNotNull(message);
assertEquals("http://schemas.elite-markets.net/eddn/shipyard/1", message.getSchemaRef());
Header header = message.getHeader();
assertNotNull(header);
assertEquals("Marek Ce'ex", header.getUploaderId());
assertEquals("E:D Market Connector [Mac OS]", header.getSoftwareName());
assertEquals("2.1.6.1", header.getSoftwareVersion());
assertEquals(LocalDateTime.of(2016, 10, 5, 13, 53, 33, 930428000), header.getGatewayTimestamp());
Body body = message.getBody();
assertNotNull(body);
assertEquals(LocalDateTime.of(2016, 10, 5, 13, 53, 25), body.getTimestamp());
StarSystem system = body.getSystem();
assertNotNull(system);
assertEquals("Venegana", system.getName());
assertNull(system.getId());
assertNull(system.getAddress());
Station station = body.getStation();
assertNotNull(station);
assertEquals("Shull Ring", station.getName());
assertNull(station.getId());
Collection<Item> items = body.getCommodities();
assertNotNull(items);
assertEquals(0, items.size());
Collection<Ship> ships = body.getShips();
assertNotNull(ships);
assertEquals(8, ships.size());
int found = 0;
for (Ship ship : ships) {
assertNotNull(ship);
if ("Sidewinder".equals(ship.getName())){
found++;
assertNull(ship.getId());
assertNull(ship.getPrice());
} else
if ("Type-7 Transporter".equals(ship.getName())){
found++;
assertNull(ship.getId());
assertNull(ship.getPrice());
}
}
assertEquals("Expected ships not found", 2, found);
}
}
@Test
public void testParseShipV2() throws Exception {
EMDNParser parser = new EMDNParser();
try (InputStream is = getClass().getResourceAsStream("/emdn/ship_v2.json")) {
String json = TestUtils.read(is);
Message message = parser.parse(json);
assertNotNull(message);
assertEquals("http://schemas.elite-markets.net/eddn/shipyard/2", message.getSchemaRef());
Header header = message.getHeader();
assertNotNull(header);
assertEquals("Amadeus Sheperd", header.getUploaderId());
assertEquals("E:D Market Connector [Windows]", header.getSoftwareName());
assertEquals("2.1.7.2", header.getSoftwareVersion());
assertEquals(LocalDateTime.of(2016, 10, 5, 13, 16, 12, 490637000), header.getGatewayTimestamp());
Body body = message.getBody();
assertNotNull(body);
assertEquals(LocalDateTime.of(2016, 10, 5, 13, 15, 51), body.getTimestamp());
StarSystem system = body.getSystem();
assertNotNull(system);
assertEquals("Sothis", system.getName());
assertNull(system.getId());
assertNull(system.getAddress());
Station station = body.getStation();
assertNotNull(station);
assertEquals("Newholm Station", station.getName());
assertNull(station.getId());
Collection<Item> items = body.getCommodities();
assertNotNull(items);
assertEquals(0, items.size());
Collection<Ship> ships = body.getShips();
assertNotNull(ships);
assertEquals(5, ships.size());
int found = 0;
for (Ship ship : ships) {
assertNotNull(ship);
if ("SideWinder".equals(ship.getName())){
found++;
assertNull(ship.getId());
assertNull(ship.getPrice());
} else
if ("Type7".equals(ship.getName())){
found++;
assertNull(ship.getId());
assertNull(ship.getPrice());
}
}
assertEquals("Expected ships not found", 2, found);
}
}
}

View File

@@ -0,0 +1,24 @@
{
"header": {
"softwareVersion": "2.1.6.1",
"gatewayTimestamp": "2016-10-05T13:53:33.930428Z",
"softwareName": "E:D Market Connector [Mac OS]",
"uploaderID": "Marek Ce'ex"
},
"$schemaRef": "http://schemas.elite-markets.net/eddn/shipyard/1",
"message": {
"systemName": "Venegana",
"ships": [
"Sidewinder",
"Eagle",
"Asp",
"Asp Scout",
"Adder",
"Anaconda",
"Type-7 Transporter",
"Federal Gunship"
],
"stationName": "Shull Ring",
"timestamp": "2016-10-05T13:53:25Z"
}
}

View File

@@ -0,0 +1,21 @@
{
"header": {
"softwareVersion": "2.1.7.2",
"gatewayTimestamp": "2016-10-05T13:16:12.490637Z",
"softwareName": "E:D Market Connector [Windows]",
"uploaderID": "Amadeus Sheperd"
},
"$schemaRef": "http://schemas.elite-markets.net/eddn/shipyard/2",
"message": {
"systemName": "Sothis",
"ships": [
"Adder",
"Eagle",
"Hauler",
"SideWinder",
"Type7"
],
"stationName": "Newholm Station",
"timestamp": "2016-10-05T13:15:51Z"
}
}

View File

@@ -0,0 +1,62 @@
{
"$schema" : "http://json-schema.org/draft-04/schema#",
"id" : "http://schemas.elite-markets.net/eddn/shipyard/1#",
"type" : "object",
"additionalProperties" : false,
"required" : [ "$schemaRef", "header", "message" ],
"properties" : {
"$schemaRef": {
"type" : "string"
},
"header": {
"type" : "object",
"additionalProperties" : true,
"required" : [ "uploaderID", "softwareName", "softwareVersion" ],
"properties" : {
"uploaderID": {
"type" : "string"
},
"softwareName": {
"type" : "string"
},
"softwareVersion": {
"type" : "string"
},
"gatewayTimestamp": {
"type" : "string",
"format" : "date-time",
"description" : "Timestamp upon receipt at the gateway. If present, this property will be overwritten by the gateway; submitters are not intended to populate this property."
}
}
},
"message": {
"type" : "object",
"additionalProperties" : false,
"required" : [ "systemName", "stationName", "timestamp", "ships" ],
"properties" : {
"systemName": {
"type" : "string",
"minLength" : 1
},
"stationName": {
"type" : "string",
"minLength" : 1
},
"timestamp": {
"type" : "string",
"format" : "date-time"
},
"ships": {
"type" : "array",
"uniqueItems" : true,
"items" : {
"type" : "string",
"minLength" : 1,
"description" : "Ship name in English as displayed in-game. i.e. one of: Adder, Anaconda, Asp, Asp Scout, Cobra Mk III, Cobra MkIV, DiamondBack Scout, Diamondback Explorer, Eagle, Federal Assault Ship, Federal Corvette, Federal Dropship, Federal Gunship, Fer-de-Lance, Hauler, Imperial Clipper, Imperial Courier, Imperial Cutter, Imperial Eagle, Keelback, Orca, Python, Sidewinder, Type-6 Transporter, Type-7 Transporter, Type-9 Heavy, Viper, Viper MkIV, Vulture"
}
}
}
}
}
}

View File

@@ -0,0 +1,62 @@
{
"$schema" : "http://json-schema.org/draft-04/schema#",
"id" : "http://schemas.elite-markets.net/eddn/shipyard/2#",
"type" : "object",
"additionalProperties" : false,
"required" : [ "$schemaRef", "header", "message" ],
"properties" : {
"$schemaRef": {
"type" : "string"
},
"header": {
"type" : "object",
"additionalProperties" : true,
"required" : [ "uploaderID", "softwareName", "softwareVersion" ],
"properties" : {
"uploaderID": {
"type" : "string"
},
"softwareName": {
"type" : "string"
},
"softwareVersion": {
"type" : "string"
},
"gatewayTimestamp": {
"type" : "string",
"format" : "date-time",
"description" : "Timestamp upon receipt at the gateway. If present, this property will be overwritten by the gateway; submitters are not intended to populate this property."
}
}
},
"message": {
"type" : "object",
"additionalProperties" : false,
"required" : [ "systemName", "stationName", "timestamp", "ships" ],
"properties" : {
"systemName": {
"type" : "string",
"minLength" : 1
},
"stationName": {
"type" : "string",
"minLength" : 1
},
"timestamp": {
"type" : "string",
"format" : "date-time"
},
"ships": {
"type" : "array",
"minItems" : 1,
"uniqueItems" : true,
"items" : {
"type" : "string",
"minLength" : 1,
"description" : "Ship symbolic name. i.e. one of: SideWinder, Adder, Anaconda, Asp, Asp_Scout CobraMkIII, CobraMkIV, Cutter, DiamondBack, DiamondBackXL, Eagle, Empire_Courier, Empire_Eagle, Empire_Trader, Federation_Corvette, Federation_Dropship, Federation_Dropship_MkII, Federation_Gunship, FerDeLance, Hauler, Independant_Trader, Orca, Python, Type6, Type7, Type9, Viper, Viper_MkIV, Vulture"
}
}
}
}
}
}