View Javadoc
1   package com.srv4pos.server.api.auth;
2   
3   import com.srv4pos.server.api.Registry;
4   import com.srv4pos.server.api.ServiceFactory;
5   import com.srv4pos.server.api.exceptions.NotImplementedJsonException;
6   import com.srv4pos.server.api.exceptions.OutdatedVersionJsonException;
7   import com.srv4pos.server.api.infrastructure.http.Transport;
8   import org.junit.Assert;
9   
10  import java.net.URL;
11  
12  /**
13   * <p>User: Kirill, Date: 11.09.13 16:16</p>.
14   */
15  public class AuthServiceSample {
16      private final AuthService authService;
17  
18      public AuthServiceSample(URL url, Transport transport) {
19          ServiceFactory serviceFactory = new ServiceFactory(url, null, transport);
20          authService = serviceFactory.getAuthService();
21      }
22  
23      public void test() {
24          // Try noauth/handshake first to know is current version supported. If this method says outdated=true, then you are still able to use the api,
25          // but you have to recommend user to update his application ASAP.
26          // Try auth/handshake to know is there any Seller registered on server
27  
28          // STEP 1. Make sure the version we use is the latest
29          try {
30              authService.handshake();
31              Assert.assertTrue(String.format("Checking version '%s' is still supportable by the server", Registry.VERSION), true);
32          } catch (OutdatedVersionJsonException e) {
33              Assert.assertTrue("Current version is out date!", false);
34              // Note: we are not able to use the api!
35          } catch (NotImplementedJsonException e) {
36              Assert.assertTrue("Current version is not yet supported!", false);
37              // Note: warn user he must wait until local server is up to date
38              // or go to support@srv4pos.com if this message continues showing too long
39          }
40      }
41  
42  }