Skip to content

Commit

Permalink
Refactored tests and added a test for importing tasks and vehicles on…
Browse files Browse the repository at this point in the history
… one request. This is not yet implemented on the production server so atm if importing import tasks and vehicels separately.
  • Loading branch information
Jarkko Laitinen committed Jan 24, 2014
1 parent e2972bd commit 05d63ba
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 51 deletions.
36 changes: 36 additions & 0 deletions fi/cosky/sdk/tests/SdkTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -623,4 +623,40 @@ public void T22TaskMassImport() {
assertNotNull(r.getLocation());
}

@Test
public void T23ImportVehiclesAndTasks() {
API api = TestHelper.authenticate();
UserData user = TestHelper.getOrCreateUser(api);
RoutingProblemData problem = TestHelper.createProblem(api, user);

VehicleSetImportRequest vehicles = new VehicleSetImportRequest();
List<VehicleUpdateRequest> vehicleList = new ArrayList<VehicleUpdateRequest>();

for (int i = 0; i < 3; i++) {
vehicleList.add(TestHelper.createVehicleUpdateRequest("vehicle"+i));
}
vehicles.setItems(vehicleList);

TaskSetImportRequest tasks = new TaskSetImportRequest();
List<TaskUpdateRequest> taskList = TestHelper.createListOfTasks(10);
tasks.setItems(taskList);
ImportData r = null;
try {
//##BEGIN EXAMPLE importtasksandvehicles##
ImportRequest importRequest = new ImportRequest();
importRequest.setVehicles(vehicles);
importRequest.setTasks(tasks);

ResponseData response = api.navigate(ResponseData.class, problem.getLink("import"), importRequest);
ImportData result = api.navigate(ImportData.class, response.getLocation());
//##END EXAMPLE##
r = result;

} catch (Exception e){
System.out.println(e.getMessage());
}
assertNotNull(r.getVehicles());
}


}
24 changes: 4 additions & 20 deletions fi/cosky/sdk/tests/TestData.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,17 @@
* This file is subject to the terms and conditions defined in
* file 'LICENSE.txt', which is part of this source code package.
*/
import fi.cosky.sdk.tests.TestHelper.Location;

public class TestData {

@SuppressWarnings("deprecation")
public static void CreateDemoData(RoutingProblemData problem, API api) {

CoordinateData coordinateData = new CoordinateData();
coordinateData.setLatitude(54.130888);
coordinateData.setLongitude(12.00938);
coordinateData.setSystem(CoordinateData.CoordinateSystem.WGS84);
LocationData locationData = new LocationData();
locationData.setCoordinatesData(coordinateData);
LocationData locationData = TestHelper.createLocation(Location.VEHICLE_START);
LocationData pickupLocation = TestHelper.createLocation(Location.TASK_PICKUP);
LocationData deliveryLocation = TestHelper.createLocation(Location.TASK_DELIVERY);

CoordinateData pickup = new CoordinateData();
pickup.setLatitude(54.14454);
pickup.setLongitude(12.108808);
pickup.setSystem(CoordinateData.CoordinateSystem.WGS84);
LocationData pickupLocation = new LocationData();
pickupLocation.setCoordinatesData(pickup);

CoordinateData delivery = new CoordinateData();
delivery.setLatitude(53.545867);
delivery.setLongitude(10.276409);
delivery.setSystem(CoordinateData.CoordinateSystem.WGS84);
LocationData deliveryLocation = new LocationData();
deliveryLocation.setCoordinatesData(delivery);

ArrayList<CapacityData> capacities = new ArrayList<CapacityData>();
capacities.add(new CapacityData("Weight", 100000));
ArrayList<TimeWindowData> timeWindows = new ArrayList<TimeWindowData>();
Expand Down
66 changes: 35 additions & 31 deletions fi/cosky/sdk/tests/TestHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import fi.cosky.sdk.*;
Expand Down Expand Up @@ -90,21 +91,9 @@ static VehicleData getVehicle(API api, UserData user, RoutingProblemData problem
}

static TaskData getTask(API api, RoutingProblemData problem) {
CoordinateData pickup = new CoordinateData();
pickup.setLatitude(62.244958);
pickup.setLongitude(25.747143);
pickup.setSystem(CoordinateSystem.Euclidian);
LocationData pi = new LocationData();
pi.setCoordinatesData(pickup);


CoordinateData delivery = new CoordinateData();
delivery.setLatitude(62.244589);
delivery.setLongitude(25.74892);
delivery.setSystem(CoordinateSystem.Euclidian);
LocationData de = new LocationData();
de.setCoordinatesData(delivery);

LocationData pi = createLocation(Location.TASK_PICKUP);
LocationData de = createLocation(Location.TASK_DELIVERY);

CapacityData capacity = new CapacityData("Weight", 20);
List<CapacityData> capacities = new ArrayList<CapacityData>();
capacities.add(capacity);
Expand Down Expand Up @@ -132,25 +121,12 @@ static TaskData getTask(API api, RoutingProblemData problem) {
static List<TaskUpdateRequest> createListOfTasks(int howMany) {
List<TaskUpdateRequest> tasks = new ArrayList<TaskUpdateRequest>();
for (int i = 0; i < howMany; i++) {
CoordinateData pickup = new CoordinateData();
pickup.setLatitude(62.244958);
pickup.setLongitude(25.747143);
pickup.setSystem(CoordinateSystem.Euclidian);
LocationData pi = new LocationData();
pi.setCoordinatesData(pickup);


CoordinateData delivery = new CoordinateData();
delivery.setLatitude(62.244589);
delivery.setLongitude(25.74892);
delivery.setSystem(CoordinateSystem.Euclidian);
LocationData de = new LocationData();
de.setCoordinatesData(delivery);

LocationData pi = createLocation(Location.TASK_PICKUP);
LocationData de = createLocation(Location.TASK_DELIVERY);

CapacityData capacity = new CapacityData("Weight", 20);
List<CapacityData> capacities = new ArrayList<CapacityData>();
capacities.add(capacity);

TaskEventUpdateRequest task1 = new TaskEventUpdateRequest(Type.Pickup, pi, capacities);
TaskEventUpdateRequest task2 = new TaskEventUpdateRequest(Type.Delivery, de, capacities);

Expand All @@ -164,6 +140,22 @@ static List<TaskUpdateRequest> createListOfTasks(int howMany) {
return tasks;
}

static VehicleUpdateRequest createVehicleUpdateRequest(String name) {
ArrayList<CapacityData> capacities = new ArrayList<CapacityData>();
capacities.add(new CapacityData("Weight", 100000));
ArrayList<TimeWindowData> timeWindows = new ArrayList<TimeWindowData>();
Date morning = new Date();
morning.setHours(7);
Date evening = new Date();
evening.setHours(16);
timeWindows.add(new TimeWindowData(morning, evening));

LocationData startLocation = createLocation(Location.VEHICLE_START);
VehicleUpdateRequest vehicleRequest = new VehicleUpdateRequest(name, capacities, startLocation, startLocation);
vehicleRequest.setTimeWindows(timeWindows);
return vehicleRequest;
}

static LocationData createLocation(Location name) {
CoordinateData coordinates = new CoordinateData();
switch (name){
Expand All @@ -190,6 +182,18 @@ static LocationData createLocation(Location name) {
return data;
}

static LocationData createLocationWithAddress() {
AddressData address = new AddressData();
address.setCity("Jyväskylä");
address.setCountry("Finland");
address.setPostalCode("40100");
address.setStreet("Mattilanniemi 2");

LocationData data = new LocationData();
data.setAddress(address);
return data;
}

enum Location{ VEHICLE_START, TASK_PICKUP, TASK_DELIVERY};

}

0 comments on commit 05d63ba

Please sign in to comment.