1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.fourthline.cling.test.model;
17
18 import org.fourthline.cling.binding.LocalServiceBinder;
19 import org.fourthline.cling.binding.annotations.AnnotationLocalServiceBinder;
20 import org.fourthline.cling.binding.annotations.UpnpAction;
21 import org.fourthline.cling.binding.annotations.UpnpOutputArgument;
22 import org.fourthline.cling.binding.annotations.UpnpService;
23 import org.fourthline.cling.binding.annotations.UpnpServiceId;
24 import org.fourthline.cling.binding.annotations.UpnpServiceType;
25 import org.fourthline.cling.binding.annotations.UpnpStateVariable;
26 import org.fourthline.cling.model.meta.ActionArgument;
27 import org.fourthline.cling.model.meta.DeviceDetails;
28 import org.fourthline.cling.model.meta.LocalDevice;
29 import org.fourthline.cling.model.meta.LocalService;
30 import org.fourthline.cling.model.types.Datatype;
31 import org.fourthline.cling.model.types.UDADeviceType;
32 import org.fourthline.cling.test.data.SampleData;
33 import org.seamless.util.ByteArray;
34 import org.testng.annotations.DataProvider;
35 import org.testng.annotations.Test;
36
37 import java.util.Random;
38
39 import static org.testng.Assert.assertEquals;
40
41
42
43
44 public class LocalServiceBindingDatatypesTest {
45
46 public LocalDevice createTestDevice(LocalService service) throws Exception {
47 return new LocalDevice(
48 SampleData.createLocalDeviceIdentity(),
49 new UDADeviceType("TestDevice", 1),
50 new DeviceDetails("Test Device"),
51 service
52 );
53 }
54
55 @DataProvider(name = "devices")
56 public Object[][] getDevices() throws Exception {
57
58
59 LocalServiceBinder binder = new AnnotationLocalServiceBinder();
60
61 return new LocalDevice[][]{
62 {createTestDevice(binder.read(TestServiceOne.class))},
63 };
64 }
65
66 @Test(dataProvider = "devices")
67 public void validateBinding(LocalDevice device) {
68
69 LocalService svc = SampleData.getFirstService(device);
70
71
72
73
74
75
76 assertEquals(svc.getStateVariables().length, 1);
77 assertEquals(svc.getStateVariable("Data").getTypeDetails().getDatatype().getBuiltin(), Datatype.Builtin.BIN_BASE64);
78 assertEquals(svc.getStateVariable("Data").getEventDetails().isSendEvents(), false);
79
80 assertEquals(svc.getActions().length, 1);
81
82 assertEquals(svc.getAction("GetData").getName(), "GetData");
83 assertEquals(svc.getAction("GetData").getArguments().length, 1);
84 assertEquals(svc.getAction("GetData").getArguments()[0].getName(), "RandomData");
85 assertEquals(svc.getAction("GetData").getArguments()[0].getDirection(), ActionArgument.Direction.OUT);
86 assertEquals(svc.getAction("GetData").getArguments()[0].getRelatedStateVariableName(), "Data");
87 assertEquals(svc.getAction("GetData").getArguments()[0].isReturnValue(), true);
88
89 }
90
91
92
93 @UpnpService(
94 serviceId = @UpnpServiceId("SomeService"),
95 serviceType = @UpnpServiceType(value = "SomeService", version = 1),
96 supportsQueryStateVariables = false
97 )
98 public static class TestServiceOne {
99
100 public TestServiceOne() {
101 data = new byte[8];
102 new Random().nextBytes(data);
103 }
104
105 @UpnpStateVariable(sendEvents = false)
106 private byte[] data;
107
108 @UpnpAction(out = @UpnpOutputArgument(name = "RandomData"))
109 public byte[] getData() {
110 return data;
111 }
112 }
113
114
115 }