1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.fourthline.cling.test.data;
17
18 import org.fourthline.cling.model.meta.Device;
19 import org.fourthline.cling.model.meta.DeviceDetails;
20 import org.fourthline.cling.model.meta.DeviceIdentity;
21 import org.fourthline.cling.model.meta.Icon;
22 import org.fourthline.cling.model.meta.ManufacturerDetails;
23 import org.fourthline.cling.model.meta.ModelDetails;
24 import org.fourthline.cling.model.meta.RemoteDevice;
25 import org.fourthline.cling.model.meta.RemoteService;
26 import org.fourthline.cling.model.meta.Service;
27 import org.fourthline.cling.model.profile.RemoteClientInfo;
28 import org.fourthline.cling.model.profile.DeviceDetailsProvider;
29 import org.fourthline.cling.model.resource.Resource;
30 import org.fourthline.cling.model.resource.ServiceEventCallbackResource;
31 import org.fourthline.cling.model.types.DLNACaps;
32 import org.fourthline.cling.model.types.DLNADoc;
33 import org.fourthline.cling.model.types.DeviceType;
34 import org.fourthline.cling.model.types.UDADeviceType;
35 import org.fourthline.cling.model.types.UDN;
36 import org.seamless.util.URIUtil;
37
38 import java.net.URI;
39 import java.net.URL;
40
41 import static org.testng.Assert.assertEquals;
42 import static org.testng.Assert.assertTrue;
43
44
45
46
47 public class SampleDeviceRoot extends SampleDevice {
48
49 public SampleDeviceRoot(DeviceIdentity identity, Service service, Device embeddedDevice) {
50 super(identity, service, embeddedDevice);
51 }
52
53 @Override
54 public DeviceType getDeviceType() {
55 return new UDADeviceType("MY-DEVICE-TYPE", 1);
56 }
57
58 @Override
59 public DeviceDetails getDeviceDetails() {
60 return new DeviceDetails(
61 "My Testdevice",
62 new ManufacturerDetails("4th Line", "http://www.4thline.org/"),
63 new ModelDetails("MYMODEL", "TEST Device", "ONE", "http://www.4thline.org/foo"),
64 "000da201238c",
65 "100000000001",
66 "http://www.4thline.org/some_user_interface/",
67 new DLNADoc[]{
68 new DLNADoc("DMS", DLNADoc.Version.V1_5),
69 new DLNADoc("M-DMS", DLNADoc.Version.V1_5)
70 },
71 new DLNACaps(new String[] {
72 "av-upload", "image-upload", "audio-upload"
73 })
74 );
75 }
76
77 public DeviceDetailsProvider getDeviceDetailsProvider() {
78 return new DeviceDetailsProvider() {
79 public DeviceDetails provide(RemoteClientInfo info) {
80 return getDeviceDetails();
81 }
82 };
83 }
84
85 @Override
86 public Icon[] getIcons() {
87 return new Icon[]{
88 new Icon("image/png", 32, 32, 8, URI.create("icon.png")),
89 new Icon("image/png", 32, 32, 8, URI.create("icon2.png"))
90 };
91 }
92
93 public static UDN getRootUDN() {
94 return new UDN("MY-DEVICE-123");
95 }
96
97 public static URI getDeviceDescriptorURI() {
98 return URI.create("/dev/MY-DEVICE-123/desc");
99 }
100
101 public static URL getDeviceDescriptorURL() {
102 return URIUtil.createAbsoluteURL(SampleData.getLocalBaseURL(), getDeviceDescriptorURI());
103 }
104
105 public static void assertMatch(Device a, Device b) {
106 assertMatch(a, b, true);
107 }
108
109 public static void assertMatch(Device a, Device b, boolean checkType) {
110 assertTrue(a.isRoot());
111 assertDeviceMatch(a, b, checkType);
112 }
113
114 public static void assertLocalResourcesMatch(Resource[] resources){
115 assertEquals(
116 getLocalResource(resources, URI.create("/dev/MY-DEVICE-123/svc/upnp-org/MY-SERVICE-123/event/cb")).getClass(),
117 ServiceEventCallbackResource.class
118 );
119
120 assertEquals(
121 getLocalResource(resources, URI.create("/dev/MY-DEVICE-456/svc/upnp-org/MY-SERVICE-456/event/cb")).getClass(),
122 ServiceEventCallbackResource.class
123 );
124 assertEquals(
125 getLocalResource(resources, URI.create("/dev/MY-DEVICE-789/svc/upnp-org/MY-SERVICE-789/event/cb")).getClass(),
126 ServiceEventCallbackResource.class
127 );
128 }
129
130 protected static Resource getLocalResource(Resource[] resources, URI localPathQuery) {
131 for (Resource localResource : resources) {
132 if (localResource.matches(localPathQuery))
133 return localResource;
134 }
135 return null;
136 }
137
138 protected static void assertDeviceMatch(Device a, Device b) {
139 assertDeviceMatch(a,b,true);
140 }
141 protected static void assertDeviceMatch(Device a, Device b, boolean checkType) {
142
143 assert (a.validate().size() == 0);
144 assert (b.validate().size() == 0);
145
146 if (checkType)
147 assertEquals(a, b);
148 assertEquals(a.getIdentity().getUdn(), b.getIdentity().getUdn());
149 assertEquals(a.getVersion().getMajor(), b.getVersion().getMajor());
150 assertEquals(a.getVersion().getMinor(), b.getVersion().getMinor());
151 assertEquals(a.getType(), b.getType());
152 assertEquals(a.getDetails().getFriendlyName(), b.getDetails().getFriendlyName());
153 assertEquals(a.getDetails().getManufacturerDetails().getManufacturer(), b.getDetails().getManufacturerDetails().getManufacturer());
154 assertEquals(a.getDetails().getManufacturerDetails().getManufacturerURI(), b.getDetails().getManufacturerDetails().getManufacturerURI());
155 assertEquals(a.getDetails().getModelDetails().getModelDescription(), b.getDetails().getModelDetails().getModelDescription());
156 assertEquals(a.getDetails().getModelDetails().getModelName(), b.getDetails().getModelDetails().getModelName());
157 assertEquals(a.getDetails().getModelDetails().getModelNumber(), b.getDetails().getModelDetails().getModelNumber());
158 assertEquals(a.getDetails().getModelDetails().getModelURI(), b.getDetails().getModelDetails().getModelURI());
159 assertEquals(a.getDetails().getSerialNumber(), b.getDetails().getSerialNumber());
160 assertEquals(a.getDetails().getUpc(), b.getDetails().getUpc());
161 assertEquals(a.getDetails().getPresentationURI(), b.getDetails().getPresentationURI());
162
163 assertEquals(a.getDetails().getDlnaDocs().length, b.getDetails().getDlnaDocs().length);
164 for (int i = 0; i < a.getDetails().getDlnaDocs().length; i++) {
165 DLNADoc aDoc = a.getDetails().getDlnaDocs()[i];
166 DLNADoc bDoc = b.getDetails().getDlnaDocs()[i];
167 assertEquals(aDoc, bDoc);
168 }
169 assertEquals(a.getDetails().getDlnaCaps(), b.getDetails().getDlnaCaps());
170
171 assertEquals(a.getIcons() != null, b.getIcons() != null);
172 if (a.getIcons() != null) {
173 assertEquals(a.getIcons().length, b.getIcons().length);
174 for (int i = 0; i < a.getIcons().length; i++) {
175 assertEquals(a.getIcons()[i].getDevice(), a);
176 assertEquals(b.getIcons()[i].getDevice(), b);
177 assertEquals(a.getIcons()[i].getUri(), b.getIcons()[i].getUri());
178 assertEquals(a.getIcons()[i].getMimeType(), b.getIcons()[i].getMimeType());
179 assertEquals(a.getIcons()[i].getWidth(), b.getIcons()[i].getWidth());
180 assertEquals(a.getIcons()[i].getHeight(), b.getIcons()[i].getHeight());
181 assertEquals(a.getIcons()[i].getDepth(), b.getIcons()[i].getDepth());
182 }
183 }
184
185 assertEquals(a.hasServices(), b.hasServices());
186 if (a.getServices() != null) {
187 assertEquals(a.getServices().length, b.getServices().length);
188 for (int i = 0; i < a.getServices().length; i++) {
189 Service service = a.getServices()[i];
190 assertEquals(service.getServiceType(), b.getServices()[i].getServiceType());
191 assertEquals(service.getServiceId(), b.getServices()[i].getServiceId());
192 if (a instanceof RemoteDevice && b instanceof RemoteDevice) {
193 RemoteService remoteServiceA = (RemoteService) service;
194 RemoteService remoteServiceB = (RemoteService) b.getServices()[i];
195
196 assertEquals(
197 remoteServiceA.getEventSubscriptionURI(),
198 remoteServiceB.getEventSubscriptionURI()
199 );
200 assertEquals(
201 remoteServiceA.getControlURI(),
202 remoteServiceB.getControlURI()
203 );
204 assertEquals(
205 remoteServiceA.getDescriptorURI(),
206 remoteServiceB.getDescriptorURI()
207 );
208 }
209 }
210 }
211
212 assertEquals(a.hasEmbeddedDevices(), b.hasEmbeddedDevices());
213 if (a.getEmbeddedDevices() != null) {
214 assertEquals(a.getEmbeddedDevices().length, b.getEmbeddedDevices().length);
215 for (int i = 0; i < a.getEmbeddedDevices().length; i++) {
216 Device aEmbedded = a.getEmbeddedDevices()[i];
217 assertDeviceMatch(aEmbedded, b.getEmbeddedDevices()[i],checkType);
218
219 }
220 }
221
222 }
223
224
225 }