7
7
8
8
import java .io .IOException ;
9
9
import java .util .ArrayList ;
10
- import java .util .Calendar ;
11
10
import java .util .Date ;
12
11
import java .util .List ;
13
- import java .util .Locale ;
14
- import java .util .TimeZone ;
15
12
16
13
import fi .cosky .sdk .*;
17
14
import fi .cosky .sdk .CoordinateData .CoordinateSystem ;
15
+ import fi .cosky .sdk .tests .TestHelper .Location ;
18
16
19
17
import org .junit .*;
20
18
@@ -24,11 +22,11 @@ public class SdkTests {
24
22
25
23
@ Test
26
24
public void T00RootLinkTest () {
27
- String clientKey = null , clientSecret = null ;
25
+ String clientKey = TestHelper . clientKey , clientSecret = TestHelper . clientSecret ;
28
26
ApiData data2 = null ;
29
27
try {
30
28
//##BEGIN EXAMPLE accessingapi##
31
- API api = new API ("http ://test. api.co-sky.fi" );
29
+ API api = new API ("https ://api.co-sky.fi" );
32
30
api .authenticate (clientKey , clientSecret );
33
31
ApiData data = api .navigate (ApiData .class , api .getRoot ());
34
32
//##END EXAMPLE##
@@ -386,18 +384,17 @@ public void T14GetProgressTest() {
386
384
387
385
RoutingProblemUpdateRequest update = problem .toRequest ();
388
386
update .setState ("Running" );
387
+
389
388
try {
390
389
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
+
397
393
//##BEGIN EXAMPLE getprogress
398
394
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 );
401
398
problem = api .navigate (RoutingProblemData .class , problem .getLink ("self" ));
402
399
}
403
400
//##END EXAMPLE
@@ -414,6 +411,7 @@ public void T15UpdatingVehicleTest() {
414
411
UserData user = TestHelper .getOrCreateUser (api );
415
412
RoutingProblemData problem = TestHelper .createProblemWithDemoData (api , user );
416
413
VehicleData vehicle = TestHelper .getVehicle (api , user , problem );
414
+ ArrayList <TimeWindowData > akkuna = vehicle .getTimeWindows ();
417
415
String updatedName = null ;
418
416
try {
419
417
VehicleUpdateRequest updatedVehicle = vehicle .toRequest ();
@@ -425,7 +423,7 @@ public void T15UpdatingVehicleTest() {
425
423
} catch (IOException e ) {
426
424
427
425
}
428
-
426
+ assertEquals ( vehicle . getTimeWindows (). get ( 0 ). getStart (), akkuna . get ( 0 ). getStart ());
429
427
assertEquals (vehicle .getName (), updatedName );
430
428
}
431
429
@@ -482,12 +480,12 @@ public void T17StartingAFinishedOptimization() {
482
480
}
483
481
assertEquals (problem .getState (), "Stopped" );
484
482
}
485
- /*
483
+
486
484
@ Test
487
485
public void T18CheckingHowMuchFasterIsImport () {
488
486
API api = TestHelper .authenticate ();
489
487
UserData user = TestHelper .getOrCreateUser (api );
490
- int taskCount = 1000 ;
488
+ int taskCount = 10 ;
491
489
RoutingProblemUpdateRequest request = new RoutingProblemUpdateRequest ("testProblem" );
492
490
try {
493
491
ResponseData result = api .navigate (ResponseData .class , user .getLink ("create-problem" ), request );
@@ -513,7 +511,7 @@ public void T18CheckingHowMuchFasterIsImport() {
513
511
}
514
512
assertNotNull (request );
515
513
}
516
- */
514
+
517
515
518
516
@ Test
519
517
public void T19TestingConcatLink () {
@@ -564,20 +562,17 @@ public void T21VehicleMassImport() {
564
562
CapacityData capa = new CapacityData ("Weight" , 10 );
565
563
ArrayList <CapacityData > list = new ArrayList <CapacityData >();
566
564
list .add (capa );
567
- CoordinateData startc = new CoordinateData ();
568
- CoordinateData endc = new CoordinateData ();
569
- LocationData start = new LocationData ();
570
- LocationData end = new LocationData ();
571
565
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
+
574
569
ResponseData a = null ;
575
570
try {
576
571
//##BEGIN EXAMPLE importvehicleset##
577
572
VehicleSetImportRequest set = new VehicleSetImportRequest ();
578
573
List <VehicleUpdateRequest > vehicles = new ArrayList <VehicleUpdateRequest >();
579
574
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 );
581
576
vehicles .add (vehicle );
582
577
}
583
578
set .setItems (vehicles );
@@ -599,15 +594,10 @@ public void T22TaskMassImport() {
599
594
CapacityData capa = new CapacityData ("Weight" , 10 );
600
595
ArrayList <CapacityData > list = new ArrayList <CapacityData >();
601
596
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 ;
611
601
try {
612
602
//##BEGIN EXAMPLE importtaskset##
613
603
List <TaskUpdateRequest > tasks = new ArrayList <TaskUpdateRequest >();
@@ -616,16 +606,21 @@ public void T22TaskMassImport() {
616
606
List <TaskEventUpdateRequest > taskEvents = new ArrayList <TaskEventUpdateRequest >();
617
607
TaskEventUpdateRequest pickup = new TaskEventUpdateRequest (Type .Pickup , pickupLocation , list );
618
608
TaskEventUpdateRequest delivery = new TaskEventUpdateRequest (Type .Delivery , deliveryLocation , list );
609
+ taskEvents .add (pickup ); taskEvents .add (delivery );
619
610
TaskUpdateRequest task = new TaskUpdateRequest (taskEvents );
611
+ task .setName ("kivikasat" + i );
620
612
tasks .add (task );
621
613
}
622
614
TaskSetImportRequest set = new TaskSetImportRequest ();
623
615
set .setItems (tasks );
624
616
ResponseData result = api .navigate (ResponseData .class , problem .getLink ("import-tasks" ), set );
617
+ System .out .println (result .toString ());
625
618
//##END EXAMPLE##
619
+ r = result ;
626
620
} catch (Exception e ) {
627
621
628
622
}
629
-
623
+ assertNotNull ( r . getLocation ());
630
624
}
625
+
631
626
}
0 commit comments