View Javadoc
1   package com.srv4pos.server.api.hairdresser;
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  
12  import java.net.URL;
13  
14  import static com.srv4pos.server.api.infrastructure.DiagnosticsUtil.assertExceptionThrown;
15  
16  /**
17   * @author pavel.tsarev
18   */
19  public class HairdresserServiceSample {
20  
21      private final SellerService sellerService;
22      private final HairdresserService hairdresserService;
23  
24      public HairdresserServiceSample(URL url, Credentials credentials, Transport transport) {
25          ServiceFactory serviceFactory = new ServiceFactory(url, credentials, transport);
26          sellerService = serviceFactory.getSellerService();
27          hairdresserService = serviceFactory.getHairdresserService();
28      }
29  
30      public void test() throws Exception {
31  
32          final SellerInfo sellerInfo = sellerService.get(null);
33          final int currentSellerVersion = sellerService.getThisVersion().getVersion();
34  
35          final String sellerId = HttpHelper.getSellerId(sellerInfo.getCountry(), sellerInfo.getCorporateId());
36          final HairdresserInfo hairdresserInfo = new HairdresserInfo();
37          hairdresserInfo.setCountry(HttpHelper.getSellerCountry(sellerId));
38          hairdresserInfo.setCorporateId(HttpHelper.getSellerCorporateId(sellerId));
39  
40          assertExceptionThrown("HairdresserService.put is forbidden!", ForbiddenJsonException.class, new Runnable() {
41              public void run() {
42                  hairdresserService.put(currentSellerVersion, sellerId, hairdresserInfo);
43              }
44          });
45  
46          //Test get hairdresser by seller id. Just check access.
47          assertExceptionThrown("Server must return 404!", NotFoundJsonException.class, new Runnable() {
48              public void run() {
49                  hairdresserService.get(sellerId, null);
50              }
51          });
52      }
53  }