View Javadoc
1   package com.srv4pos.server.api.restaurant;
2   
3   import com.srv4pos.server.api.ServiceFactory;
4   import com.srv4pos.server.api.exceptions.ForbiddenJsonException;
5   import com.srv4pos.server.api.exceptions.NotFoundJsonException;
6   import com.srv4pos.server.api.infrastructure.credentials.Credentials;
7   import com.srv4pos.server.api.infrastructure.http.HttpHelper;
8   import com.srv4pos.server.api.infrastructure.http.Transport;
9   import com.srv4pos.server.api.seller.SellerInfo;
10  import com.srv4pos.server.api.seller.SellerService;
11  import org.junit.Assert;
12  
13  import java.net.URL;
14  
15  import static com.srv4pos.server.api.infrastructure.DiagnosticsUtil.assertExceptionThrown;
16  
17  /**
18   * @author pavel.tsarev
19   */
20  public class RestaurantServiceSample {
21  
22      private static final String RESTAURANT_CUSTOM_DATA =
23              "{\"type\":\"spot\", \"payCard\": true, \"wifi\":true, \"deliveryTime\": \"20min\", \"deliveryCost\": 20000}";
24  
25      private final SellerService sellerService;
26      private final RestaurantService restaurantService;
27  
28      public RestaurantServiceSample(URL url, Credentials credentials, Transport transport) {
29          ServiceFactory serviceFactory = new ServiceFactory(url, credentials, transport);
30          sellerService = serviceFactory.getSellerService();
31          restaurantService = serviceFactory.getRestaurantService();
32      }
33  
34      public void test() throws Exception {
35  
36          final SellerInfo sellerInfo = sellerService.get(null);
37          final int currentSellerVersion = sellerService.getThisVersion().getVersion();
38  
39          final String sellerId = HttpHelper.getSellerId(sellerInfo.getCountry(), sellerInfo.getCorporateId());
40          final RestaurantInfo restaurantInfo = new RestaurantInfo();
41          restaurantInfo.setAverageBill(100500L);
42          restaurantInfo.setCountry(HttpHelper.getSellerCountry(sellerId));
43          restaurantInfo.setCorporateId(HttpHelper.getSellerCorporateId(sellerId));
44  
45  
46          assertExceptionThrown("RestaurantService.put is forbidden!", ForbiddenJsonException.class, new Runnable() {
47              public void run() {
48                  restaurantService.put(currentSellerVersion, sellerId, restaurantInfo);
49              }
50          });
51  
52          //Test get all restaurants. Just check access.
53          Assert.assertNotNull(restaurantService.list());
54  
55          //Test get restaurant by seller id. Just check access.
56          assertExceptionThrown("Server must return 404!", NotFoundJsonException.class, new Runnable() {
57              public void run() {
58                  restaurantService.get(sellerId, null);
59              }
60          });
61      }
62  }