mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-04 03:13:49 +00:00
implemented more structured SwissTiming service connector pieces
This commit is contained in:
1 parent
1379341980
commit
d67f64facf
4 files changed
+177
-11
No files matched your search
+78
@@ -5,15 +5,20 @@ import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.sap.sailing.domain.swisstimingadapter.Competitor;
|
||||
import com.sap.sailing.domain.swisstimingadapter.Course;
|
||||
import com.sap.sailing.domain.swisstimingadapter.Mark;
|
||||
import com.sap.sailing.domain.swisstimingadapter.Race;
|
||||
import com.sap.sailing.domain.swisstimingadapter.SailMasterConnector;
|
||||
import com.sap.sailing.domain.swisstimingadapter.SailMasterMessage;
|
||||
import com.sap.sailing.domain.swisstimingadapter.StartList;
|
||||
import com.sap.sailing.domain.swisstimingadapter.SwissTimingFactory;
|
||||
import com.sap.sailing.util.Util;
|
||||
|
||||
@@ -62,4 +67,77 @@ public class SailMasterConnectivityTest {
|
||||
assertEquals("4712", r2.getRaceID());
|
||||
assertEquals("Not such a wonderful race", r2.getDescription());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCourseConfig() throws UnknownHostException, IOException {
|
||||
Iterable<Race> races = connector.getRaces();
|
||||
Iterator<Race> i = races.iterator();
|
||||
Race r1 = i.next();
|
||||
Course course1 = connector.getCourse(r1.getRaceID());
|
||||
assertEquals(r1.getRaceID(), course1.getRaceID());
|
||||
assertEquals(2, Util.size(course1.getMarks()));
|
||||
Iterator<Mark> mi = course1.getMarks().iterator();
|
||||
Mark m11 = mi.next();
|
||||
assertEquals("Lee Gate", m11.getDescription());
|
||||
assertEquals(Arrays.asList(new String[] { "LG1", "LG2" }), m11.getDevices());
|
||||
assertEquals(1, m11.getIndex());
|
||||
Mark m12 = mi.next();
|
||||
assertEquals("Windward", m12.getDescription());
|
||||
assertEquals(Arrays.asList(new String[] { "WW1" }), m12.getDevices());
|
||||
assertEquals(2, m12.getIndex());
|
||||
|
||||
Race r2 = i.next();
|
||||
Course course2 = connector.getCourse(r2.getRaceID());
|
||||
assertEquals(r2.getRaceID(), course2.getRaceID());
|
||||
assertEquals(3, Util.size(course2.getMarks()));
|
||||
mi = course2.getMarks().iterator();
|
||||
Mark m21 = mi.next();
|
||||
assertEquals("Lee Gate", m21.getDescription());
|
||||
assertEquals(Arrays.asList(new String[] { "LG1", "LG2" }), m21.getDevices());
|
||||
assertEquals(1, m21.getIndex());
|
||||
Mark m22 = mi.next();
|
||||
assertEquals("Windward", m22.getDescription());
|
||||
assertEquals(Arrays.asList(new String[] { "WW1" }), m22.getDevices());
|
||||
assertEquals(2, m22.getIndex());
|
||||
Mark m23 = mi.next();
|
||||
assertEquals("Offset", m23.getDescription());
|
||||
assertEquals(Arrays.asList(new String[] { "OS1" }), m23.getDevices());
|
||||
assertEquals(3, m23.getIndex());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartList() throws UnknownHostException, IOException {
|
||||
Iterable<Race> races = connector.getRaces();
|
||||
Iterator<Race> i = races.iterator();
|
||||
Race r1 = i.next();
|
||||
StartList sl1 = connector.getStartList(r1.getRaceID());
|
||||
assertEquals(r1.getRaceID(), sl1.getRaceID());
|
||||
assertEquals(2, Util.size(sl1.getCompetitors()));
|
||||
Iterator<Competitor> ci = sl1.getCompetitors().iterator();
|
||||
Competitor polgarKoy = ci.next();
|
||||
assertEquals("GER 8414", polgarKoy.getBoatID());
|
||||
assertEquals("GER", polgarKoy.getThreeLetterIOCCode());
|
||||
assertEquals("Polgar/Koy", polgarKoy.getName());
|
||||
Competitor schlonskiBohn = ci.next();
|
||||
assertEquals("GER 8140", schlonskiBohn.getBoatID());
|
||||
assertEquals("GER", schlonskiBohn.getThreeLetterIOCCode());
|
||||
assertEquals("Schlonski/Bohn", schlonskiBohn.getName());
|
||||
Race r2 = i.next();
|
||||
StartList sl2 = connector.getStartList(r2.getRaceID());
|
||||
assertEquals(r2.getRaceID(), sl2.getRaceID());
|
||||
assertEquals(3, Util.size(sl2.getCompetitors()));
|
||||
ci = sl2.getCompetitors().iterator();
|
||||
Competitor stanjekKleen = ci.next();
|
||||
assertEquals("GER 8340", stanjekKleen.getBoatID());
|
||||
assertEquals("GER", stanjekKleen.getThreeLetterIOCCode());
|
||||
assertEquals("Stanjek/Kleen", stanjekKleen.getName());
|
||||
Competitor babendererdeJacobs = ci.next();
|
||||
assertEquals("GER 8433", babendererdeJacobs.getBoatID());
|
||||
assertEquals("GER", babendererdeJacobs.getThreeLetterIOCCode());
|
||||
assertEquals("Babendererde/Jacobs", babendererdeJacobs.getName());
|
||||
Competitor elsnerSchulz = ci.next();
|
||||
assertEquals("GER 8299", elsnerSchulz.getBoatID());
|
||||
assertEquals("GER", elsnerSchulz.getThreeLetterIOCCode());
|
||||
assertEquals("Elsner/Schulz", elsnerSchulz.getName());
|
||||
}
|
||||
}
|
||||
+29
-2
@@ -6,6 +6,7 @@ import java.io.OutputStream;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
|
||||
import com.sap.sailing.domain.swisstimingadapter.impl.SailMasterMessageImpl;
|
||||
import com.sap.sailing.domain.swisstimingadapter.impl.SailMasterTransceiver;
|
||||
|
||||
public class SailMasterDummy implements Runnable {
|
||||
@@ -54,9 +55,35 @@ public class SailMasterDummy implements Runnable {
|
||||
}
|
||||
|
||||
private void respondToMessage(String message, OutputStream os) throws IOException {
|
||||
if ("RaceId".equals(message)) {
|
||||
SailMasterMessageImpl smMessage = new SailMasterMessageImpl(message);
|
||||
String[] sections = smMessage.getSections();
|
||||
if ("RaceId".equals(sections[0])) {
|
||||
transceiver.sendMessage("RaceId|4711,A wonderful test race|4712,Not such a wonderful race", os);
|
||||
} else if ("StopServer".equals(message)) {
|
||||
} else if ("CourseConfig".equals(sections[0])) {
|
||||
if (sections[1].equals("4711")) {
|
||||
transceiver.sendMessage("CourseConfig|"+sections[1]+"|1,Lee Gate,LG1,LG2|2,Windward,WW1", os);
|
||||
} else if (sections[1].equals("4712")) {
|
||||
transceiver.sendMessage("CourseConfig|"+sections[1]+"|1,Lee Gate,LG1,LG2|2,Windward,WW1|3,Offset,OS1", os);
|
||||
}
|
||||
} else if ("StartList".equals(sections[0])) {
|
||||
if (sections[1].equals("4711")) {
|
||||
transceiver.sendMessage("StartList|"+sections[1]+"|GER 8414,GER,Polgar/Koy|GER 8140,GER,Schlonski/Bohn", os);
|
||||
} else if (sections[1].equals("4712")) {
|
||||
transceiver.sendMessage("StartList|"+sections[1]+"|GER 8340,GER,Stanjek/Kleen|GER 8433,GER,Babendererde/Jacobs|GER 8299,GER,Elsner/Schulz", os);
|
||||
}
|
||||
} else if ("RaceTime".equals(sections[0])) {
|
||||
|
||||
} else if ("ClockAtMark".equals(sections[0])) {
|
||||
|
||||
} else if ("DistToMark".equals(sections[0])) {
|
||||
|
||||
} else if ("CurrentBoatSpeed".equals(sections[0])) {
|
||||
|
||||
} else if ("AverageBoatSpeed".equals(sections[0])) {
|
||||
|
||||
} else if ("DistBetweenBoats".equals(sections[0])) {
|
||||
|
||||
} else if ("StopServer".equals(sections[0])) {
|
||||
stopped = true;
|
||||
transceiver.sendMessage("Server stopped", os);
|
||||
} else {
|
||||
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package com.sap.sailing.domain.swisstimingadapter.impl;
|
||||
|
||||
import com.sap.sailing.domain.swisstimingadapter.Competitor;
|
||||
|
||||
public class CompetitorImpl implements Competitor {
|
||||
private final String boatID;
|
||||
private final String threeLetterIOCCode;
|
||||
private final String name;
|
||||
|
||||
public CompetitorImpl(String boatID, String threeLetterIOCCode, String name) {
|
||||
super();
|
||||
this.boatID = boatID;
|
||||
this.threeLetterIOCCode = threeLetterIOCCode;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBoatID() {
|
||||
return boatID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getThreeLetterIOCCode() {
|
||||
return threeLetterIOCCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
+38
-9
@@ -5,10 +5,12 @@ import java.io.OutputStream;
|
||||
import java.net.Socket;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.sap.sailing.domain.base.TimePoint;
|
||||
import com.sap.sailing.domain.swisstimingadapter.Competitor;
|
||||
import com.sap.sailing.domain.swisstimingadapter.Course;
|
||||
import com.sap.sailing.domain.swisstimingadapter.Mark;
|
||||
import com.sap.sailing.domain.swisstimingadapter.Race;
|
||||
@@ -45,9 +47,7 @@ public class SailMasterConnectorImpl extends SailMasterTransceiver implements Sa
|
||||
public Iterable<Race> getRaces() throws UnknownHostException, IOException {
|
||||
SailMasterMessage response = sendRequestAndGetResponse("RaceId");
|
||||
String[] sections = response.getSections();
|
||||
if (!sections[0].equals("RaceId")) {
|
||||
throw new RuntimeException("Expected a RaceId response for a RaceId request but got "+sections[0]);
|
||||
}
|
||||
assertResponseType("RaceId", sections);
|
||||
List<Race> result = new ArrayList<Race>();
|
||||
for (int i=1; i<sections.length; i++) {
|
||||
String[] idAndDescription = sections[i].split(",");
|
||||
@@ -57,15 +57,44 @@ public class SailMasterConnectorImpl extends SailMasterTransceiver implements Sa
|
||||
}
|
||||
|
||||
@Override
|
||||
public Course getCourse(String raceID) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
public Course getCourse(String raceID) throws UnknownHostException, IOException {
|
||||
SailMasterMessage response = sendRequestAndGetResponse("CourseConfig|"+raceID);
|
||||
String[] sections = response.getSections();
|
||||
assertResponseType("CourseConfig", sections);
|
||||
assertRaceID(raceID, sections);
|
||||
List<Mark> marks = new ArrayList<Mark>();
|
||||
for (int i=2; i<sections.length; i++) {
|
||||
String[] markDetails = sections[i].split(",");
|
||||
marks.add(new MarkImpl(markDetails[1], Integer.valueOf(markDetails[0]), Arrays.asList(markDetails).subList(2, markDetails.length)));
|
||||
}
|
||||
return new CourseImpl(raceID, marks);
|
||||
}
|
||||
|
||||
private void assertRaceID(String raceID, String[] sections) {
|
||||
if (!sections[1].equals(raceID)) {
|
||||
throw new RuntimeException("Expected a "+sections[0]+" response for race ID "+raceID+
|
||||
" but received one for "+sections[1]);
|
||||
}
|
||||
}
|
||||
|
||||
private void assertResponseType(String responseType, String[] sections) {
|
||||
if (!sections[0].equals(responseType)) {
|
||||
throw new RuntimeException("Expected a "+responseType+" response for a "+responseType+" request but got "+sections[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public StartList getStartList(String raceID) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
public StartList getStartList(String raceID) throws UnknownHostException, IOException {
|
||||
SailMasterMessage response = sendRequestAndGetResponse("StartList|"+raceID);
|
||||
String[] sections = response.getSections();
|
||||
assertResponseType("StartList", sections);
|
||||
assertRaceID(raceID, sections);
|
||||
ArrayList<Competitor> competitors = new ArrayList<Competitor>();
|
||||
for (int i=2; i<sections.length; i++) {
|
||||
String[] competitorDetails = sections[i].split(",");
|
||||
competitors.add(new CompetitorImpl(competitorDetails[0], competitorDetails[1], competitorDetails[2]));
|
||||
}
|
||||
return new StartListImpl(raceID, competitors);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user