1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package example.localservice;
17
18 import org.fourthline.cling.binding.LocalServiceBinder;
19 import org.fourthline.cling.binding.annotations.AnnotationLocalServiceBinder;
20 import org.fourthline.cling.model.DefaultServiceManager;
21 import org.fourthline.cling.model.meta.DeviceDetails;
22 import org.fourthline.cling.model.meta.LocalDevice;
23 import org.fourthline.cling.model.meta.LocalService;
24 import org.fourthline.cling.model.types.Datatype;
25 import org.fourthline.cling.model.types.DeviceType;
26 import org.fourthline.cling.test.data.SampleData;
27 import org.testng.annotations.DataProvider;
28 import org.testng.annotations.Test;
29
30 import static org.testng.Assert.assertEquals;
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 public class AllowedValueTest {
56
57 public LocalDevice createTestDevice(Class serviceClass) throws Exception {
58
59 LocalServiceBinder binder = new AnnotationLocalServiceBinder();
60 LocalService svc = binder.read(serviceClass);
61 svc.setManager(new DefaultServiceManager(svc, serviceClass));
62
63 return new LocalDevice(
64 SampleData.createLocalDeviceIdentity(),
65 new DeviceType("mydomain", "CustomDevice", 1),
66 new DeviceDetails("A Custom Device"),
67 svc
68 );
69 }
70
71 @DataProvider(name = "devices")
72 public Object[][] getDevices() {
73 try {
74 return new LocalDevice[][]{
75 {createTestDevice(MyServiceWithAllowedValues.class)},
76 {createTestDevice(MyServiceWithAllowedValueProvider.class)},
77 };
78 } catch (Exception ex) {
79 ex.printStackTrace(System.err);
80
81 throw new RuntimeException(ex);
82 }
83 }
84
85 @Test(dataProvider = "devices")
86 public void validateBinding(LocalDevice device) {
87 LocalService svc = device.getServices()[0];
88 assertEquals(svc.getStateVariables().length, 1);
89 assertEquals(svc.getStateVariables()[0].getTypeDetails().getDatatype().getBuiltin(), Datatype.Builtin.STRING);
90 assertEquals(svc.getStateVariables()[0].getTypeDetails().getAllowedValues().length, 3);
91 assertEquals(svc.getStateVariables()[0].getTypeDetails().getAllowedValues()[0], "Foo");
92 assertEquals(svc.getStateVariables()[0].getTypeDetails().getAllowedValues()[1], "Bar");
93 assertEquals(svc.getStateVariables()[0].getTypeDetails().getAllowedValues()[2], "Baz");
94 }
95
96 }