Skip to content

Commit e2972bd

Browse files
author
Jarkko Laitinen
committed
Fixed mass-import tests and added a location generator to testhelper.
1 parent d72c6f8 commit e2972bd

File tree

2 files changed

+64
-37
lines changed

2 files changed

+64
-37
lines changed

fi/cosky/sdk/tests/SdkTests.java

+29-34
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@
77

88
import java.io.IOException;
99
import java.util.ArrayList;
10-
import java.util.Calendar;
1110
import java.util.Date;
1211
import java.util.List;
13-
import java.util.Locale;
14-
import java.util.TimeZone;
1512

1613
import fi.cosky.sdk.*;
1714
import fi.cosky.sdk.CoordinateData.CoordinateSystem;
15+
import fi.cosky.sdk.tests.TestHelper.Location;
1816

1917
import org.junit.*;
2018

@@ -24,11 +22,11 @@ public class SdkTests {
2422

2523
@Test
2624
public void T00RootLinkTest() {
27-
String clientKey = null, clientSecret = null;
25+
String clientKey = TestHelper.clientKey, clientSecret = TestHelper.clientSecret;
2826
ApiData data2 = null;
2927
try {
3028
//##BEGIN EXAMPLE accessingapi##
31-
API api = new API("http://test.api.co-sky.fi");
29+
API api = new API("https://api.co-sky.fi");
3230
api.authenticate(clientKey, clientSecret);
3331
ApiData data = api.navigate(ApiData.class, api.getRoot());
3432
//##END EXAMPLE##
@@ -386,18 +384,17 @@ public void T14GetProgressTest() {
386384

387385
RoutingProblemUpdateRequest update = problem.toRequest();
388386
update.setState("Running");
387+
389388
try {
390389
ResponseData response = api.navigate(ResponseData.class, problem.getLink("toggle-optimization"), update);
391-
try {
392-
Thread.sleep(5000);
393-
} catch (InterruptedException e) {
394-
// TODO Auto-generated catch block
395-
e.printStackTrace();
396-
}
390+
391+
Thread.sleep(5000);
392+
397393
//##BEGIN EXAMPLE getprogress
398394
problem = api.navigate(RoutingProblemData.class, response.getLocation());
399-
while(problem.getProgress() < 100) {
400-
Thread.sleep(100);
395+
396+
while ( problem.getProgress() < 100 ) {
397+
Thread.sleep(1000);
401398
problem = api.navigate(RoutingProblemData.class, problem.getLink("self"));
402399
}
403400
//##END EXAMPLE
@@ -414,6 +411,7 @@ public void T15UpdatingVehicleTest() {
414411
UserData user = TestHelper.getOrCreateUser(api);
415412
RoutingProblemData problem = TestHelper.createProblemWithDemoData(api, user);
416413
VehicleData vehicle = TestHelper.getVehicle(api, user, problem);
414+
ArrayList<TimeWindowData> akkuna = vehicle.getTimeWindows();
417415
String updatedName = null;
418416
try {
419417
VehicleUpdateRequest updatedVehicle = vehicle.toRequest();
@@ -425,7 +423,7 @@ public void T15UpdatingVehicleTest() {
425423
} catch (IOException e) {
426424

427425
}
428-
426+
assertEquals(vehicle.getTimeWindows().get(0).getStart(), akkuna.get(0).getStart());
429427
assertEquals(vehicle.getName(), updatedName);
430428
}
431429

@@ -482,12 +480,12 @@ public void T17StartingAFinishedOptimization() {
482480
}
483481
assertEquals(problem.getState(), "Stopped");
484482
}
485-
/*
483+
486484
@Test
487485
public void T18CheckingHowMuchFasterIsImport() {
488486
API api = TestHelper.authenticate();
489487
UserData user = TestHelper.getOrCreateUser(api);
490-
int taskCount = 1000;
488+
int taskCount = 10;
491489
RoutingProblemUpdateRequest request = new RoutingProblemUpdateRequest("testProblem");
492490
try {
493491
ResponseData result = api.navigate(ResponseData.class, user.getLink("create-problem"), request);
@@ -513,7 +511,7 @@ public void T18CheckingHowMuchFasterIsImport() {
513511
}
514512
assertNotNull(request);
515513
}
516-
*/
514+
517515

518516
@Test
519517
public void T19TestingConcatLink() {
@@ -564,20 +562,17 @@ public void T21VehicleMassImport() {
564562
CapacityData capa = new CapacityData("Weight", 10);
565563
ArrayList<CapacityData> list = new ArrayList<CapacityData>();
566564
list.add(capa);
567-
CoordinateData startc = new CoordinateData();
568-
CoordinateData endc = new CoordinateData();
569-
LocationData start = new LocationData();
570-
LocationData end = new LocationData();
571565

572-
start.setCoordinatesData(startc);
573-
end.setCoordinatesData(endc);
566+
LocationData start = TestHelper.createLocation(Location.VEHICLE_START);
567+
LocationData end = TestHelper.createLocation(Location.VEHICLE_START);
568+
574569
ResponseData a = null;
575570
try {
576571
//##BEGIN EXAMPLE importvehicleset##
577572
VehicleSetImportRequest set = new VehicleSetImportRequest();
578573
List<VehicleUpdateRequest> vehicles = new ArrayList<VehicleUpdateRequest>();
579574
for (int i = 0; i < 10; i++) {
580-
VehicleUpdateRequest vehicle = new VehicleUpdateRequest("vehicle", list, start, end);
575+
VehicleUpdateRequest vehicle = new VehicleUpdateRequest("vehicle" + i, list, start, end);
581576
vehicles.add(vehicle);
582577
}
583578
set.setItems(vehicles);
@@ -599,15 +594,10 @@ public void T22TaskMassImport() {
599594
CapacityData capa = new CapacityData("Weight", 10);
600595
ArrayList<CapacityData> list = new ArrayList<CapacityData>();
601596
list.add(capa);
602-
CoordinateData startc = new CoordinateData();
603-
CoordinateData endc = new CoordinateData();
604-
LocationData start = new LocationData();
605-
LocationData end = new LocationData();
606-
607-
start.setCoordinatesData(startc);
608-
end.setCoordinatesData(endc);
609-
LocationData pickupLocation = new LocationData();
610-
LocationData deliveryLocation = new LocationData();
597+
598+
LocationData pickupLocation = TestHelper.createLocation(Location.TASK_PICKUP);
599+
LocationData deliveryLocation = TestHelper.createLocation(Location.TASK_DELIVERY);
600+
ResponseData r = null;
611601
try {
612602
//##BEGIN EXAMPLE importtaskset##
613603
List<TaskUpdateRequest> tasks = new ArrayList<TaskUpdateRequest>();
@@ -616,16 +606,21 @@ public void T22TaskMassImport() {
616606
List<TaskEventUpdateRequest> taskEvents = new ArrayList<TaskEventUpdateRequest>();
617607
TaskEventUpdateRequest pickup = new TaskEventUpdateRequest(Type.Pickup, pickupLocation, list);
618608
TaskEventUpdateRequest delivery = new TaskEventUpdateRequest(Type.Delivery, deliveryLocation, list);
609+
taskEvents.add(pickup); taskEvents.add(delivery);
619610
TaskUpdateRequest task = new TaskUpdateRequest(taskEvents);
611+
task.setName("kivikasat" + i);
620612
tasks.add(task);
621613
}
622614
TaskSetImportRequest set = new TaskSetImportRequest();
623615
set.setItems(tasks);
624616
ResponseData result = api.navigate(ResponseData.class, problem.getLink("import-tasks"), set);
617+
System.out.println(result.toString());
625618
//##END EXAMPLE##
619+
r = result;
626620
} catch (Exception e) {
627621

628622
}
629-
623+
assertNotNull(r.getLocation());
630624
}
625+
631626
}

fi/cosky/sdk/tests/TestHelper.java

+35-3
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,19 @@
1414

1515
public class TestHelper {
1616
private static API apis = null;
17+
static String clientKey = "";
18+
static String clientSecret = "";
19+
1720
static API authenticate() {
18-
String url = "";
19-
String clientKey = "";
20-
String clientSecret = "";
21+
String url = "https://api.co-sky.fi";
2122
if (apis == null) {
2223
API api = new API(url);
2324
api.setTimed(true);
2425
if (api.authenticate(clientKey, clientSecret)) {
2526
apis = api;
27+
} else {
28+
System.out.println("Could not authenticate, please check service and credentials");
29+
return null;
2630
}
2731
}
2832
return apis;
@@ -160,4 +164,32 @@ static List<TaskUpdateRequest> createListOfTasks(int howMany) {
160164
return tasks;
161165
}
162166

167+
static LocationData createLocation(Location name) {
168+
CoordinateData coordinates = new CoordinateData();
169+
switch (name){
170+
case TASK_PICKUP: {
171+
coordinates.setLatitude(62.244958);
172+
coordinates.setLongitude(25.747143);
173+
break;
174+
}
175+
case TASK_DELIVERY: {
176+
coordinates.setLatitude(62.244589);
177+
coordinates.setLongitude(25.74892);
178+
break;
179+
}
180+
case VEHICLE_START:
181+
default: {
182+
coordinates.setLatitude(62.247906);
183+
coordinates.setLongitude(25.867395);
184+
break;
185+
}
186+
}
187+
coordinates.setSystem(CoordinateSystem.Euclidian);
188+
LocationData data = new LocationData();
189+
data.setCoordinatesData(coordinates);
190+
return data;
191+
}
192+
193+
enum Location{ VEHICLE_START, TASK_PICKUP, TASK_DELIVERY};
194+
163195
}

0 commit comments

Comments
 (0)