1 package com.srv4pos.server.api.customization;
2
3 import com.srv4pos.server.api.ServiceFactory;
4 import com.srv4pos.server.api.infrastructure.IdentifierInfo;
5 import com.srv4pos.server.api.infrastructure.credentials.Credentials;
6 import com.srv4pos.server.api.infrastructure.http.Transport;
7 import com.srv4pos.server.api.seller.SellerService;
8
9 import java.net.URL;
10 import java.util.List;
11
12 import static org.junit.Assert.assertEquals;
13
14 public class CustomizationServiceSample {
15
16 private final SellerService sellerService;
17 private final CustomizationGroupService customizationGroupService;
18 private final CustomizationItemService customizationItemService;
19
20 public CustomizationServiceSample(URL url, Credentials credentials, Transport transport) {
21 ServiceFactory serviceFactory = new ServiceFactory(url, credentials, transport);
22 sellerService = serviceFactory.getSellerService();
23 customizationGroupService = serviceFactory.getCustomizationGroupService();
24 customizationItemService = serviceFactory.getCustomizationItemService();
25 }
26
27 public void test() throws Exception {
28
29
30
31 int currentSellerVersion = sellerService.getThisVersion().getVersion();
32
33 final CustomizationGroupInfo customizationGroup = createAndSaveCustomizationGroup(currentSellerVersion, "Beverages");
34 currentSellerVersion++;
35
36 final CustomizationGroupInfo groupFromServer = customizationGroupService.get(null, customizationGroup.getIdentifier());
37
38 assertEquals("Name mismatch for customization group. Make sure server return right data", customizationGroup.getName(), groupFromServer.getName());
39
40
41
42
43
44 final CustomizationItemInfo firstItem = createAndSaveCustomizationItem(currentSellerVersion, "Sugar", customizationGroup.getIdentifier());
45 currentSellerVersion++;
46
47 final CustomizationItemInfo secondItem = createAndSaveCustomizationItem(currentSellerVersion, "Salt", customizationGroup.getIdentifier());
48
49
50 List<CustomizationItemInfo> items = customizationItemService.list(null);
51
52 assertEquals("Make sure server returns right amount of items", 2, items.size());
53
54 assertEquals("Name mismatch for first item. Make sure server return right data", firstItem.getName(), items.get(0).getName());
55 assertEquals("Name mismatch for second item. Make sure server return right data", secondItem.getName(), items.get(1).getName());
56
57 }
58
59 private CustomizationGroupInfo createAndSaveCustomizationGroup(final int sellerVersion, final String name) {
60 CustomizationGroupInfo customizationGroupInfo = new CustomizationGroupInfo();
61 customizationGroupInfo.setName(name);
62
63 IdentifierInfo identifierInfo = customizationGroupService.create(sellerVersion, customizationGroupInfo);
64 customizationGroupInfo.setIdentifier(identifierInfo.getIdentifier());
65
66 return customizationGroupInfo;
67 }
68
69 private CustomizationItemInfo createAndSaveCustomizationItem(final int sellerVersion, final String name, final String groupIdentifier) {
70 CustomizationItemInfo customizationItemInfo = new CustomizationItemInfo();
71 customizationItemInfo.setName(name);
72 customizationItemInfo.setCustomizationGroup(groupIdentifier);
73
74 IdentifierInfo identifierInfo = customizationItemService.create(sellerVersion, customizationItemInfo);
75 customizationItemInfo.setIdentifier(identifierInfo.getIdentifier());
76 return customizationItemInfo;
77 }
78 }