Added range type to subject-feature-definition/parameter
[groupbasedpolicy.git] / renderers / opflex / src / test / java / org / opendaylight / groupbasedpolicy / renderer / opflex / lib / messages / OpflexMessageTest.java
1 /*
2  * Copyright (C) 2014 Cisco Systems, Inc.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  *
8  *  Authors : Thomas Bachman
9  */
10
11 package org.opendaylight.groupbasedpolicy.renderer.opflex.lib.messages;
12
13 import static org.junit.Assert.assertTrue;
14
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.opendaylight.groupbasedpolicy.jsonrpc.RpcMessage;
18 import org.opendaylight.groupbasedpolicy.renderer.opflex.lib.Role;
19 import org.opendaylight.groupbasedpolicy.renderer.opflex.lib.messages.EndpointDeclareRequest;
20 import org.opendaylight.groupbasedpolicy.renderer.opflex.lib.messages.EndpointDeclareResponse;
21 import org.opendaylight.groupbasedpolicy.renderer.opflex.lib.messages.EndpointUndeclareRequest;
22 import org.opendaylight.groupbasedpolicy.renderer.opflex.lib.messages.EndpointUndeclareResponse;
23 import org.opendaylight.groupbasedpolicy.renderer.opflex.lib.messages.EndpointUnresolveRequest;
24 import org.opendaylight.groupbasedpolicy.renderer.opflex.lib.messages.EndpointUnresolveResponse;
25 import org.opendaylight.groupbasedpolicy.renderer.opflex.lib.messages.EndpointUpdateRequest;
26 import org.opendaylight.groupbasedpolicy.renderer.opflex.lib.messages.EndpointUpdateResponse;
27 import org.opendaylight.groupbasedpolicy.renderer.opflex.lib.messages.EndpointResolveRequest;
28 import org.opendaylight.groupbasedpolicy.renderer.opflex.lib.messages.EndpointResolveResponse;
29 import org.opendaylight.groupbasedpolicy.renderer.opflex.lib.messages.IdentityRequest;
30 import org.opendaylight.groupbasedpolicy.renderer.opflex.lib.messages.IdentityResponse;
31 import org.opendaylight.groupbasedpolicy.renderer.opflex.lib.messages.PolicyResolveRequest;
32 import org.opendaylight.groupbasedpolicy.renderer.opflex.lib.messages.PolicyResolveResponse;
33 import org.opendaylight.groupbasedpolicy.renderer.opflex.lib.messages.PolicyUnresolveRequest;
34 import org.opendaylight.groupbasedpolicy.renderer.opflex.lib.messages.PolicyUnresolveResponse;
35 import org.opendaylight.groupbasedpolicy.renderer.opflex.lib.messages.PolicyUpdateRequest;
36 import org.opendaylight.groupbasedpolicy.renderer.opflex.lib.messages.PolicyUpdateResponse;
37 import org.opendaylight.groupbasedpolicy.renderer.opflex.lib.messages.StateReportRequest;
38 import org.opendaylight.groupbasedpolicy.renderer.opflex.lib.messages.StateReportResponse;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
42
43 import com.fasterxml.jackson.databind.DeserializationFeature;
44 import com.fasterxml.jackson.databind.ObjectMapper;
45
46 /**
47  *
48  * Test the serialization and deserialization of RPC Messages,
49  * and check against expected structure and values.
50  */
51 public class OpflexMessageTest {
52     protected static final Logger logger = LoggerFactory.getLogger(OpflexMessageTest.class);
53
54 //    private enum Role {
55 //        POLICY_REPOSITORY("policy_repository"),
56 //        ENDPOINT_REGISTRY("endpoint_registry"),
57 //        OBSERVER("observer"),
58 //        POLICY_ELEMENT("policy_element");
59 //
60 //        private String role;
61 //        Role(String role) {
62 //            this.role = role;
63 //        }
64 //        @Override
65 //        public String toString() {
66 //            return this.role;
67 //        }
68 //    }
69
70     // TODO: should just import these from somewhere?
71     /*
72      * common JSON definitions
73      */
74     private static final String JSON_OBJECT_OPEN = "{";
75     private static final String JSON_OBJECT_CLOSE = "}";
76     private static final String JSON_ARRAY_OPEN = "[";
77     private static final String JSON_ARRAY_CLOSE = "]";
78
79     /*
80      * common JSON-RPC definitions
81      */
82     // Just use the same UUID for all IDs
83     private static final String ID_UUID = "2da9e3d7-0bbe-4099-b343-12783777452f";
84     private static final String JSONRPC_ID = "\"id\": [\"send_itentity\", \"" + ID_UUID + "\"],";
85     private static final String JSONRPC_METHOD = "  \"method\":";
86     private static final String JSONRPC_PARAMS_OPEN = "\"params\": " + JSON_ARRAY_OPEN;
87     private static final String JSONRPC_PARAMS_CLOSE = JSON_ARRAY_CLOSE;
88     private static final String JSONRPC_RESULT_OPEN = "\"result\": " + JSON_OBJECT_OPEN;
89     private static final String JSONRPC_RESULT_CLOSE = JSON_OBJECT_CLOSE;
90     private static final String JSONRPC_ERROR_OPEN = "\"error\":  " + JSON_OBJECT_OPEN;
91     private static final String JSONRPC_ERROR_CLOSE = JSON_OBJECT_CLOSE;
92
93     /*
94      * Common OpFlex message definitions
95      */
96     public static final String SUBJECT = "\"subject\":";
97
98     /*
99      * Identity message-specific definitions
100      */
101     private static final String DOMAIN_UUID = "75caaff2-cb4f-4509-b45e-47b447cb35a9";
102     private static final String TEST_NAME = "vm1";
103     private static final String IDENTITY = "192.168.0.1:56732";
104     // Use the same protocol version for all test messages
105     private static final String OPFLEX_PROTO_VERSION = "1.0";
106     private static final String PROTO_VERSION = "\"proto_version\": \"" + OPFLEX_PROTO_VERSION + "\",";
107     private static final String MY_ROLE_OPEN = "\"my_role\": " + JSON_ARRAY_OPEN;
108     private static final String MY_ROLE_CLOSE = JSON_ARRAY_CLOSE;
109     private static final String PEERS_OPEN = "\"peers\":" + JSON_ARRAY_OPEN + JSON_OBJECT_OPEN;
110     private static final String PEERS_CLOSE = JSON_OBJECT_CLOSE + JSON_ARRAY_CLOSE;
111     private static final String OPFLEX_ROLE_OPEN = "\"role\":" + JSON_ARRAY_OPEN;
112     private static final String OPFLEX_ROLE_CLOSE = JSON_ARRAY_CLOSE;
113     // Use the same test name for all OpFlex name fields
114     private static final String OPFLEX_NAME = "\"name\": \"" + TEST_NAME + "\",";
115     // Use the same Domain for all test messages
116     private static final String OPFLEX_DOMAIN = "\"domain\":  \"" + DOMAIN_UUID + "\",";
117
118     /*
119      * Identity messages
120      */
121     private static final String opflexIdentityRequest =
122             JSON_OBJECT_OPEN +
123             JSONRPC_ID +
124             JSONRPC_METHOD + "\"" + IdentityRequest.IDENTITY_MESSAGE + "\"," +
125             JSONRPC_PARAMS_OPEN + JSON_OBJECT_OPEN +
126             PROTO_VERSION +
127             OPFLEX_NAME +
128             OPFLEX_DOMAIN +
129             MY_ROLE_OPEN +
130             "\"" + Role.POLICY_ELEMENT.toString() + "\"" +
131             MY_ROLE_CLOSE +
132             JSON_OBJECT_CLOSE + JSONRPC_PARAMS_CLOSE +
133             JSON_OBJECT_CLOSE;
134
135     private static final String opflexIdentityResponse =
136             JSON_OBJECT_OPEN +
137             JSONRPC_ID +
138             JSONRPC_ERROR_OPEN +
139             JSONRPC_ERROR_CLOSE + "," +
140             JSONRPC_RESULT_OPEN +
141             OPFLEX_NAME +
142             OPFLEX_DOMAIN +
143             MY_ROLE_OPEN +
144             "\"" + Role.POLICY_REPOSITORY.toString() + "\"" +
145             MY_ROLE_CLOSE + "," +
146             PEERS_OPEN +
147             OPFLEX_ROLE_OPEN +
148             "\"" + Role.ENDPOINT_REGISTRY.toString() + "\"," +
149             "\"" + Role.OBSERVER.toString() + "\"" +
150             OPFLEX_ROLE_CLOSE + "," +
151             "\"connectivity_info\": \"" + IDENTITY  + "\"" +
152             PEERS_CLOSE +
153             JSONRPC_RESULT_CLOSE +
154             JSON_OBJECT_CLOSE;
155
156     /*
157      * Policy message-specific definitions
158      */
159     public static final String POLICY_URI = "\"policy_uri\":";
160     public static final String DATA = "\"data\":";
161     public static final String PRR = "\"prr\":";
162     public static final String POLICY_IDENT_OPEN = "\"policy_ident\":" + JSON_OBJECT_OPEN;
163     public static final String POLICY_IDENT_CLOSE = JSON_OBJECT_CLOSE;
164     public static final String POLICY_IDENT_CONTEXT = "\"context\":";
165     public static final String POLICY_IDENT_NAME = "\"name\":";
166
167     public static final Uri POLICY_IDENT_CONTEXT_VALUE =
168                 new Uri("/PolicyUniverse/PolicySpace/f4d908bd-2911-43d4-9f22-a09f36ed3ddb");
169     public static final Uri POLICY_URI_VALUE =
170                 new Uri("/PolicyUniverse/PolicySpace/f4d908bd-2911-43d4-9f22-a09f36ed3ddb" +
171                                 "/GbpContract/b3506f37-b324-4092-80dd-f8a63bd193db");
172     public static final String POLICY_CONTEXT = "Contract";
173     public static final String PROP_NAME = "subject";
174     public static final String PROP_DATA = "http";
175     public static final Uri URI_NAME = new Uri("/foo/bar/t/robot");
176     public static final Uri PARENT_URI_NAME = new Uri("/foo/bar/t");
177     public static final String SUBJECT_NAME = "webFarmContract";
178     public static final String PARENT_RELATION_NAME = "fooboo";
179     public static final String PARENT_SUBJECT_NAME = "webFarmContractParent";
180     public static final String POLICY_IDENT_URI = "ef130684-ac17-4118-ad36-8dea0babc7b2";
181     public static final String DATA_NAME = "condition:notAuthorized";
182     public static final String PRR_VALUE = "100";
183
184     /*
185      * Policy Request using URI
186      */
187     private static final String opflexPolicyResolve1 =
188             JSON_OBJECT_OPEN +
189             JSONRPC_ID +
190             JSONRPC_METHOD + "\"" + PolicyResolveRequest.RESOLVE_MESSAGE + "\"," +
191             JSONRPC_PARAMS_OPEN + JSON_OBJECT_OPEN +
192             SUBJECT + "\"" + SUBJECT_NAME + "\"," +
193             POLICY_URI + "\"" + POLICY_URI_VALUE.getValue() + "\"," +
194             POLICY_IDENT_OPEN +
195             POLICY_IDENT_NAME + "\"\"," +
196             POLICY_IDENT_CONTEXT + "\"\"" +
197             POLICY_IDENT_CLOSE + "," +
198             DATA +  "\"" + DATA_NAME + "\"," +
199             PRR + "\"" + PRR_VALUE + "\"" +
200             JSON_OBJECT_CLOSE + JSONRPC_PARAMS_CLOSE +
201             JSON_OBJECT_CLOSE;
202
203     /*
204      * Policy Request using policy identity
205      */
206     private static final String opflexPolicyResolve2 =
207             JSON_OBJECT_OPEN +
208             JSONRPC_ID +
209             JSONRPC_METHOD + "\"" + PolicyResolveRequest.RESOLVE_MESSAGE + "\"," +
210             JSONRPC_PARAMS_OPEN + JSON_OBJECT_OPEN +
211             SUBJECT + "\"" + SUBJECT_NAME + "\"," +
212             POLICY_URI + "\"\"," +
213             POLICY_IDENT_OPEN +
214             POLICY_IDENT_NAME + "\"" + POLICY_IDENT_URI + "\"," +
215             POLICY_IDENT_CONTEXT + "\"" + POLICY_IDENT_CONTEXT_VALUE.getValue() + "\"" +
216             POLICY_IDENT_CLOSE + "," +
217             DATA +  "\"" + DATA_NAME + "\"," +
218             PRR + "\"" + PRR_VALUE + "\"" +
219             JSON_OBJECT_CLOSE + JSONRPC_PARAMS_CLOSE +
220             JSON_OBJECT_CLOSE;
221
222     /*
223      * Managed Object definitions
224      */
225     private static final String URI = "          \"uri\":";
226     private static final String PROPERTIES_OPEN = "\"properties\":" + JSON_ARRAY_OPEN;
227     private static final String PROPERTIES_CLOSE = JSON_ARRAY_CLOSE;
228     private static final String PROPERTY_NAME = "\"name\":";
229     private static final String PROPERTY_DATA = "\"data\":";
230     private static final String PARENT_SUBJECT = "\"parent_subject\":";
231     private static final String PARENT_URI = "\"parent_uri\":";
232     private static final String PARENT_RELATION = "\"parent_relation\":";
233     private static final String CHILDREN = "\"children\":";
234     private static final String POLICY_OPEN = "\"policy\":" + JSON_ARRAY_OPEN;
235     private static final String POLICY_CLOSE = JSON_ARRAY_CLOSE;
236
237     private static final String managedObject =
238             SUBJECT + "\"" + SUBJECT_NAME + "\"," +
239             URI + "\"" + URI_NAME.getValue() + "\"," +
240             PROPERTIES_OPEN +
241             JSON_OBJECT_OPEN +
242             PROPERTY_NAME + "\"" + PROP_NAME + "\", " +
243             PROPERTY_DATA + "\"" + PROP_DATA + "\"" +
244             JSON_OBJECT_CLOSE +
245             PROPERTIES_CLOSE + ", " +
246             PARENT_SUBJECT + "\"" + PARENT_SUBJECT_NAME + "\"," +
247             PARENT_URI + "\"" + PARENT_URI_NAME.getValue() + "\"," +
248             PARENT_RELATION + "\"" + PARENT_RELATION_NAME + "\"," +
249             CHILDREN + JSON_ARRAY_OPEN + JSON_ARRAY_CLOSE;
250
251     private static final String opflexPolicyResponse =
252             JSON_OBJECT_OPEN +
253             JSONRPC_ID +
254             JSONRPC_ERROR_OPEN +
255             JSONRPC_ERROR_CLOSE + "," +
256             JSONRPC_RESULT_OPEN +
257             POLICY_OPEN +
258             JSON_OBJECT_OPEN + managedObject + JSON_OBJECT_CLOSE +
259             POLICY_CLOSE +
260             JSONRPC_RESULT_CLOSE +
261             JSON_OBJECT_CLOSE;
262
263     /*
264      * Policy Unresolve message-specific definitions
265      */
266     private static final String opflexPolicyUnresolveRequest =
267             JSON_OBJECT_OPEN + JSONRPC_ID +
268             JSONRPC_METHOD + "\"" + PolicyUnresolveRequest.UNRESOLVE_MESSAGE + "\"," +
269             JSONRPC_PARAMS_OPEN + JSON_OBJECT_OPEN +
270             SUBJECT + "\"" + SUBJECT_NAME + "\"," +
271             POLICY_URI + "\"\"," +
272             POLICY_IDENT_OPEN +
273             POLICY_IDENT_NAME + "\"" + POLICY_IDENT_URI + "\"," +
274             POLICY_IDENT_CONTEXT + "\"" + POLICY_IDENT_CONTEXT_VALUE.getValue() + "\"" +
275             POLICY_IDENT_CLOSE +
276             JSON_OBJECT_CLOSE + JSONRPC_PARAMS_CLOSE +
277             JSON_OBJECT_CLOSE;
278
279     private static final String opflexPolicyUnresolveResponse =
280             JSON_OBJECT_OPEN +
281             JSONRPC_ID +
282             JSONRPC_ERROR_OPEN +
283             JSONRPC_ERROR_CLOSE + "," +
284             JSONRPC_RESULT_OPEN +
285             JSONRPC_RESULT_CLOSE +
286             JSON_OBJECT_CLOSE;
287
288     /*
289      * Pollicy Update message-specific definitions
290      */
291     private static final String REPLACE_OPEN = "\"replace\":" + JSON_ARRAY_OPEN;
292     private static final String REPLACE_CLOSE = JSON_ARRAY_CLOSE;
293     private static final String MERGE_CHILDREN_OPEN = "\"merge_children\":" + JSON_ARRAY_OPEN;
294     private static final String MERGE_CHILDREN_CLOSE = JSON_ARRAY_CLOSE;
295     private static final String DELETE_URI_OPEN = "\"delete_uri\":" + JSON_ARRAY_OPEN;
296     private static final String DELETE_URI_CLOSE = JSON_ARRAY_CLOSE;
297
298     private static final String opflexUpdateRequest =
299             JSON_OBJECT_OPEN +
300             JSONRPC_ID +
301             JSONRPC_METHOD + "\"" + PolicyUpdateRequest.UPDATE_MESSAGE + "\"," +
302             JSONRPC_PARAMS_OPEN +
303             JSON_OBJECT_OPEN +
304             REPLACE_OPEN +
305             JSON_OBJECT_OPEN + managedObject + JSON_OBJECT_CLOSE +
306             REPLACE_CLOSE + "," +
307             MERGE_CHILDREN_OPEN +
308             JSON_OBJECT_OPEN + managedObject + JSON_OBJECT_CLOSE  +
309             MERGE_CHILDREN_CLOSE + "," +
310             DELETE_URI_OPEN + "\"" + POLICY_URI_VALUE.getValue() + "\"" + DELETE_URI_CLOSE +
311             JSON_OBJECT_CLOSE +
312             JSONRPC_PARAMS_CLOSE +
313             JSON_OBJECT_CLOSE;
314
315     private static final String opflexUpdateResponse =
316             JSON_OBJECT_OPEN +
317             JSONRPC_ID +
318             JSONRPC_ERROR_OPEN +
319             JSONRPC_ERROR_CLOSE + "," +
320             JSONRPC_RESULT_OPEN +
321             JSONRPC_RESULT_CLOSE +
322             JSON_OBJECT_CLOSE;
323
324
325     /*
326      * Endoint Declare message-specific definitions
327      */
328     private static final String ENDPOINT_OPEN = "\"endpoint\":" + JSON_ARRAY_OPEN;
329     private static final String ENDPOINT_CLOSE = JSON_ARRAY_CLOSE;
330
331
332     private static final String opflexEpDeclareRequest =
333             JSON_OBJECT_OPEN +
334             JSONRPC_ID +
335             JSONRPC_METHOD + "\"" + EndpointDeclareRequest.DECLARE_MESSAGE + "\"," +
336             JSONRPC_PARAMS_OPEN +
337             JSON_OBJECT_OPEN +
338             ENDPOINT_OPEN +
339             JSON_OBJECT_OPEN + managedObject + JSON_OBJECT_CLOSE  +
340             ENDPOINT_CLOSE + "," +
341             PRR + "\"" + PRR_VALUE + "\"" +
342             JSON_OBJECT_CLOSE +
343             JSONRPC_PARAMS_CLOSE +
344             JSON_OBJECT_CLOSE;
345
346     private static final String opflexEpDeclareResponse =
347             JSON_OBJECT_OPEN +
348             JSONRPC_ID +
349             JSONRPC_ERROR_OPEN +
350             JSONRPC_ERROR_CLOSE + "," +
351             JSONRPC_RESULT_OPEN +
352             JSONRPC_RESULT_CLOSE +
353             JSON_OBJECT_CLOSE;
354
355     /*
356      * Endpoint Resolve message-specific definitions
357      */
358     public static final String ENDPOINT_IDENT_OPEN = "\"endpoint_ident\":" + JSON_OBJECT_OPEN;
359     public static final String ENDPOINT_IDENT_CLOSE = JSON_OBJECT_CLOSE;
360     public static final String ENDPOINT_IDENT_CONTEXT = "\"context\":";
361     public static final String ENDPOINT_IDENT_NAME = "\"identifier\":";
362     public static final Uri ENDPOINT_IDENT_CONTEXT_VALUE =
363                 new Uri("/EprL2Universe/EprL2Ep/f4d908bd-2911-43d4-9f22-a09f36ed3ddb");
364     public static final Uri ENDPOINT_URI_VALUE =
365                 new Uri("/EprL2Universe/EprL2Ep/f4d908bd-2911-43d4-9f22-a09f36ed3ddb/b3506f37-b324-4092-80dd-f8a63bd193db");
366     public static final String ENDPOINT_IDENT_URI = "ef130684-ac17-4118-ad36-8dea0babc7b2";
367     public static final String ENDPOINT = "\"endpoint\":";
368
369
370     /*
371      * Endpoint Undeclare message-specific definitions
372      */
373     private static final String ENDPOINT_URI = "\"endpoint_uri\":";
374     private static final String opflexEpUndeclareRequest =
375             JSON_OBJECT_OPEN +
376             JSONRPC_ID +
377             JSONRPC_METHOD + "\"" + EndpointUndeclareRequest.UNDECLARE_MESSAGE + "\"," +
378             JSONRPC_PARAMS_OPEN +
379             JSON_OBJECT_OPEN +
380             SUBJECT + "\"" + SUBJECT_NAME + "\"," +
381             ENDPOINT_URI + "\"" + ENDPOINT_URI_VALUE.getValue() + "\"" +
382             JSON_OBJECT_CLOSE +
383             JSONRPC_PARAMS_CLOSE +
384             JSON_OBJECT_CLOSE;
385
386     private static final String opflexEpUndeclareResponse =
387             JSON_OBJECT_OPEN +
388             JSONRPC_ID +
389             JSONRPC_ERROR_OPEN +
390             JSONRPC_ERROR_CLOSE + "," +
391             JSONRPC_RESULT_OPEN +
392             JSONRPC_RESULT_CLOSE +
393             JSON_OBJECT_CLOSE;
394
395     /*
396      * Endpoint Resolve using URI
397      */
398     private static final String opflexEpResolveRequest1 =
399             JSON_OBJECT_OPEN +
400             JSONRPC_ID +
401             JSONRPC_METHOD + "\"" +  EndpointResolveRequest.EP_RESOLVE_REQUEST_MESSAGE + "\"," +
402             JSONRPC_PARAMS_OPEN +
403             JSON_OBJECT_OPEN +
404             SUBJECT + "\"" + SUBJECT_NAME + "\"," +
405             ENDPOINT_URI + "\"" + ENDPOINT_URI_VALUE.getValue() + "\"," +
406             ENDPOINT_IDENT_OPEN +
407             ENDPOINT_IDENT_CLOSE + "," +
408             PRR + "\"" + PRR_VALUE + "\"" +
409             JSON_OBJECT_CLOSE + JSONRPC_PARAMS_CLOSE +
410             JSON_OBJECT_CLOSE;
411
412     /*
413      * Endpoint Resolve using Identity
414      */
415     private static final String opflexEpResolveRequest2 =
416             JSON_OBJECT_OPEN +
417             JSONRPC_ID +
418             JSONRPC_METHOD + "\"" +  EndpointResolveRequest.EP_RESOLVE_REQUEST_MESSAGE + "\"," +
419             JSONRPC_PARAMS_OPEN +
420             JSON_OBJECT_OPEN +
421             SUBJECT + "\"" + SUBJECT_NAME + "\"," +
422             ENDPOINT_URI + "\"\"," +
423             ENDPOINT_IDENT_OPEN +
424             ENDPOINT_IDENT_NAME + "\"" + ENDPOINT_IDENT_URI + "\"," +
425             ENDPOINT_IDENT_CONTEXT + "\"" + ENDPOINT_IDENT_CONTEXT_VALUE.getValue() + "\"" +
426             ENDPOINT_IDENT_CLOSE + "," +
427             PRR + "\"" + PRR_VALUE + "\"" +
428             JSON_OBJECT_CLOSE + JSONRPC_PARAMS_CLOSE +
429             JSON_OBJECT_CLOSE;
430
431     private static final String opflexEpResponse =
432             JSON_OBJECT_OPEN +
433             JSONRPC_ID +
434             JSONRPC_ERROR_OPEN +
435             JSONRPC_ERROR_CLOSE + "," +
436             JSONRPC_RESULT_OPEN +
437             ENDPOINT +
438             JSON_ARRAY_OPEN + JSON_OBJECT_OPEN + managedObject + JSON_OBJECT_CLOSE + JSON_ARRAY_CLOSE +
439             JSONRPC_RESULT_CLOSE +
440             JSON_OBJECT_CLOSE;
441
442     /*
443      * Endpoint Unresolve message-specific defines
444      */
445
446     /*
447      * Endpoint Unresolve using URI
448      */
449     private static final String opflexEpUnresolveRequest1 =
450             JSON_OBJECT_OPEN +
451             JSONRPC_ID +
452             JSONRPC_METHOD + "\"" +  EndpointUnresolveRequest.EP_UNRESOLVE_REQUEST_MESSAGE + "\"," +
453             JSONRPC_PARAMS_OPEN +
454             JSON_OBJECT_OPEN +
455             SUBJECT + "\"" + SUBJECT_NAME + "\"," +
456             ENDPOINT_URI + "\"" + ENDPOINT_URI_VALUE.getValue() + "\"," +
457             ENDPOINT_IDENT_OPEN +
458             ENDPOINT_IDENT_CLOSE +
459             JSON_OBJECT_CLOSE + JSONRPC_PARAMS_CLOSE +
460             JSON_OBJECT_CLOSE;
461
462     /*
463      * Endpoint Unresolve using Identity
464      */
465     private static final String opflexEpUnresolveRequest2 =
466             JSON_OBJECT_OPEN +
467             JSONRPC_ID +
468             JSONRPC_METHOD + "\"" +  EndpointUnresolveRequest.EP_UNRESOLVE_REQUEST_MESSAGE+ "\"," +
469             JSONRPC_PARAMS_OPEN +
470             JSON_OBJECT_OPEN +
471             SUBJECT + "\"" + SUBJECT_NAME + "\"," +
472             ENDPOINT_URI + "\"\"," +
473             ENDPOINT_IDENT_OPEN +
474             ENDPOINT_IDENT_NAME + "\"" + ENDPOINT_IDENT_URI + "\"," +
475             ENDPOINT_IDENT_CONTEXT + "\"" + ENDPOINT_IDENT_CONTEXT_VALUE.getValue() + "\"" +
476             ENDPOINT_IDENT_CLOSE +
477             JSON_OBJECT_CLOSE + JSONRPC_PARAMS_CLOSE +
478             JSON_OBJECT_CLOSE;
479
480     private static final String opflexEpUnresolveResponse =
481             JSON_OBJECT_OPEN +
482             JSONRPC_ID +
483             JSONRPC_ERROR_OPEN +
484             JSONRPC_ERROR_CLOSE + "," +
485             JSONRPC_RESULT_OPEN +
486             JSONRPC_RESULT_CLOSE +
487             JSON_OBJECT_CLOSE;
488
489     /*
490      * Endpoint Update message-specific definitions
491      */
492
493
494     private static final String opflexEpUpdateRequest =
495             JSON_OBJECT_OPEN +
496             JSONRPC_ID +
497             JSONRPC_METHOD + "\"" + EndpointUpdateRequest.EP_UPDATE_MESSAGE + "\"," +
498             JSONRPC_PARAMS_OPEN +
499             JSON_OBJECT_OPEN +
500             REPLACE_OPEN +
501             JSON_OBJECT_OPEN + managedObject + JSON_OBJECT_CLOSE +
502             REPLACE_CLOSE + "," +
503             DELETE_URI_OPEN + "\"" + POLICY_URI_VALUE.getValue() + "\"" + DELETE_URI_CLOSE +
504             JSON_OBJECT_CLOSE +
505             JSONRPC_PARAMS_CLOSE +
506             JSON_OBJECT_CLOSE;
507
508     private static final String opflexEpUpdateResponse =
509             JSON_OBJECT_OPEN +
510             JSONRPC_ID +
511             JSONRPC_ERROR_OPEN +
512             JSONRPC_ERROR_CLOSE + "," +
513             JSONRPC_RESULT_OPEN +
514             JSONRPC_RESULT_CLOSE +
515             JSON_OBJECT_CLOSE;
516
517     /*
518      * State Report message-specific definitions
519      */
520     private static final String OBJECT = "\"object\":";
521     private static final Uri OBJECT_VALUE =
522                 new Uri("/EprL2Universe/EprL2Ep/f4d908bd-2911-43d4-9f22-a09f36ed3ddb");
523     private static final String OBSERVABLE = "\"observable\":";
524     private static final String opflexStateRequest =
525             JSON_OBJECT_OPEN +
526             JSONRPC_ID +
527             JSONRPC_METHOD + "\"" + StateReportRequest.STATE_MESSAGE + "\"," +
528             JSONRPC_PARAMS_OPEN +
529             JSON_OBJECT_OPEN +
530             OBJECT + "\"" + OBJECT_VALUE.getValue() + "\"," +
531             OBSERVABLE +
532             JSON_ARRAY_OPEN + JSON_OBJECT_OPEN + managedObject + JSON_OBJECT_CLOSE + JSON_ARRAY_CLOSE +
533             JSON_OBJECT_CLOSE +
534             JSONRPC_PARAMS_CLOSE +
535             JSON_OBJECT_CLOSE;
536
537
538
539     private static final String opflexStateResponse =
540             JSON_OBJECT_OPEN +
541             JSONRPC_ID +
542             JSONRPC_ERROR_OPEN +
543             JSONRPC_ERROR_CLOSE + "," +
544             JSONRPC_RESULT_OPEN +
545             JSONRPC_RESULT_CLOSE +
546             JSON_OBJECT_CLOSE;
547
548     @Before
549     public void setUp() throws Exception {
550         ObjectMapper objectMapper = new ObjectMapper();
551         objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
552     }
553
554
555     @Test
556     public void testIdentityRequest() throws Exception {
557         ObjectMapper objectMapper = new ObjectMapper();
558         RpcMessage rpcMsg = objectMapper.
559                 readValue(opflexIdentityRequest, IdentityRequest.class);
560         String foo = objectMapper.writeValueAsString(rpcMsg);
561         System.out.println(foo);
562         assertTrue(rpcMsg instanceof IdentityRequest);
563         IdentityRequest opflexRequest = (IdentityRequest)rpcMsg;
564         assertTrue(opflexRequest.getId().toString().contains(ID_UUID));
565         assertTrue(opflexRequest.getMethod().equals(IdentityRequest.IDENTITY_MESSAGE));
566         assertTrue(opflexRequest.getParams()
567                         .get(0).getProto_version().equals(OPFLEX_PROTO_VERSION));
568         assertTrue(opflexRequest.getParams()
569                 .get(0).getDomain().equals(DOMAIN_UUID));
570         assertTrue(opflexRequest.getParams()
571                 .get(0).getName().equals(TEST_NAME));
572         assertTrue(opflexRequest.getParams()
573                 .get(0).getMy_role().get(0).equals(Role.POLICY_ELEMENT.toString()));
574         assertTrue(opflexRequest.getParams()
575                 .get(0).getName().equals(TEST_NAME));
576     }
577
578     @Test
579     public void testIdentityResponse() throws Exception {
580         ObjectMapper objectMapper = new ObjectMapper();
581         RpcMessage rpcMsg = objectMapper.
582                 readValue(opflexIdentityResponse, IdentityResponse.class);
583         assertTrue(rpcMsg instanceof IdentityResponse);
584         IdentityResponse opflexResponse = (IdentityResponse)rpcMsg;
585         assertTrue(opflexResponse.getId().toString().contains(ID_UUID));
586         assertTrue(opflexResponse.getResult()
587                 .getDomain().equals(DOMAIN_UUID));
588         assertTrue(opflexResponse.getResult()
589                 .getName().equals(TEST_NAME));
590         assertTrue(opflexResponse.getResult()
591                 .getMy_role().get(0).equals(Role.POLICY_REPOSITORY.toString()));
592         assertTrue(opflexResponse.getResult()
593                 .getPeers().get(0).getRole().get(0).equals(Role.ENDPOINT_REGISTRY.toString()));
594         assertTrue(opflexResponse.getResult()
595                 .getPeers().get(0).getRole().get(1).equals(Role.OBSERVER.toString()));
596     }
597
598     /**
599      * Test a policy resolve message that uses the URI instead of the
600      * policy identity for passing the policy requested.
601      *
602      * @throws Exception
603      */
604     @Test
605     public void testPolicyResolve1() throws Exception {
606         ObjectMapper objectMapper = new ObjectMapper();
607         RpcMessage rpcMsg = objectMapper.
608                 readValue(opflexPolicyResolve1, PolicyResolveRequest.class);
609         assertTrue(rpcMsg instanceof PolicyResolveRequest);
610         PolicyResolveRequest opflexRequest = (PolicyResolveRequest)rpcMsg;
611         assertTrue(opflexRequest.getId().toString().contains(ID_UUID));
612         assertTrue(opflexRequest.getMethod().equals(PolicyResolveRequest.RESOLVE_MESSAGE));
613         assertTrue(opflexRequest.getParams()
614                         .get(0).getPolicy_uri().getValue().equals(POLICY_URI_VALUE.getValue()));
615         assertTrue(opflexRequest.getParams()
616                         .get(0).getPolicy_ident().getContext().getValue() == "");
617         assertTrue(opflexRequest.getParams()
618                         .get(0).getPolicy_ident().getName() == "");
619         assertTrue(opflexRequest.getParams()
620                         .get(0).getPrr() == Integer.parseInt(PRR_VALUE));
621         assertTrue(opflexRequest.getParams()
622                 .get(0).getSubject().equals(SUBJECT_NAME));
623         assertTrue(opflexRequest.getParams()
624                 .get(0).getData().equals(DATA_NAME));
625
626     }
627
628     /**
629      * Test a policy resolve message that uses he policy identity instead
630      * of the URI for passing the policy requested.
631      *
632      * @throws Exception
633      */
634     @Test
635     public void testPolicyResolve2() throws Exception {
636         ObjectMapper objectMapper = new ObjectMapper();
637         RpcMessage rpcMsg = objectMapper.
638                 readValue(opflexPolicyResolve2, PolicyResolveRequest.class);
639         assertTrue(rpcMsg instanceof PolicyResolveRequest);
640         PolicyResolveRequest opflexRequest = (PolicyResolveRequest)rpcMsg;
641         assertTrue(opflexRequest.getId().toString().contains(ID_UUID));
642         assertTrue(opflexRequest.getMethod().equals(PolicyResolveRequest.RESOLVE_MESSAGE));
643         assertTrue(opflexRequest.getParams()
644                         .get(0).getPolicy_uri().getValue() == "");
645         assertTrue(opflexRequest.getParams()
646                         .get(0).getPolicy_ident().getName().equals(POLICY_IDENT_URI));
647         assertTrue(opflexRequest.getParams()
648                         .get(0).getPolicy_ident().getContext().getValue()
649                         .equals(POLICY_IDENT_CONTEXT_VALUE.getValue()));
650         assertTrue(opflexRequest.getParams()
651                         .get(0).getPrr() == Integer.parseInt(PRR_VALUE));
652         assertTrue(opflexRequest.getParams()
653                 .get(0).getSubject().equals(SUBJECT_NAME));
654         assertTrue(opflexRequest.getParams()
655                 .get(0).getData().equals(DATA_NAME));
656
657     }
658
659     /**
660      * Test the response to the policy resolve message
661      *
662      * @throws Exception
663      */
664     @Test
665     public void testPolicyResolveResponse() throws Exception {
666         ObjectMapper objectMapper = new ObjectMapper();
667         RpcMessage rpcMsg = objectMapper.
668                 readValue(opflexPolicyResponse, PolicyResolveResponse.class);
669         assertTrue(rpcMsg instanceof PolicyResolveResponse);
670         PolicyResolveResponse opflexResponse = (PolicyResolveResponse)rpcMsg;
671         assertTrue(opflexResponse.getId().toString().contains(ID_UUID));
672         // TODO: add support for testing children?
673         assertTrue(opflexResponse.getResult()
674                         .getPolicy().get(0).getChildren().size() == 0);
675         assertTrue(opflexResponse.getResult()
676                         .getPolicy().get(0).getParent_relation().equals(PARENT_RELATION_NAME));
677         assertTrue(opflexResponse.getResult()
678                         .getPolicy().get(0).getParent_subject().equals(PARENT_SUBJECT_NAME));
679         assertTrue(opflexResponse.getResult()
680                         .getPolicy().get(0).getParent_uri().getValue().equals(PARENT_URI_NAME.getValue()));
681         assertTrue(opflexResponse.getResult()
682                         .getPolicy().get(0).getUri().getValue().equals(URI_NAME.getValue()));
683         assertTrue(opflexResponse.getResult()
684                 .getPolicy().get(0).getProperties().get(0).getName().equals(PROP_NAME));
685         assertTrue(opflexResponse.getResult()
686                 .getPolicy().get(0).getProperties().get(0).getData().asText().equals(PROP_DATA));
687         assertTrue(opflexResponse.getResult()
688                 .getPolicy().get(0).getSubject().equals(SUBJECT_NAME));
689     }
690
691     /**
692      * Test a policy unresolve message that uses the URI instead of the
693      * policy identity for passing the policy requested.
694      *
695      * @throws Exception
696      */
697     @Test
698     public void testPolicyUnresolveRequest() throws Exception {
699         ObjectMapper objectMapper = new ObjectMapper();
700         System.out.println(opflexPolicyUnresolveRequest);
701         RpcMessage rpcMsg = objectMapper.
702                 readValue(opflexPolicyUnresolveRequest, PolicyResolveRequest.class);
703         assertTrue(rpcMsg instanceof PolicyResolveRequest);
704         PolicyResolveRequest opflexRequest = (PolicyResolveRequest)rpcMsg;
705         assertTrue(opflexRequest.getId().toString().contains(ID_UUID));
706         assertTrue(opflexRequest.getMethod().equals(PolicyUnresolveRequest.UNRESOLVE_MESSAGE));
707         System.out.println(POLICY_URI_VALUE.getValue());
708         assertTrue(opflexRequest.getParams()
709                         .get(0).getPolicy_ident().getContext().getValue().equals(POLICY_IDENT_CONTEXT_VALUE.getValue()));
710         assertTrue(opflexRequest.getParams()
711                         .get(0).getPolicy_uri().getValue() == "");
712         assertTrue(opflexRequest.getParams()
713                 .get(0).getSubject().equals(SUBJECT_NAME));
714
715     }
716
717
718     @Test
719     public void testPolicyUnresolveResponse() throws Exception {
720         ObjectMapper objectMapper = new ObjectMapper();
721         RpcMessage rpcMsg = objectMapper.
722                 readValue(opflexPolicyUnresolveResponse, PolicyUnresolveResponse.class);
723         assertTrue(rpcMsg instanceof PolicyUnresolveResponse);
724         PolicyUnresolveResponse opflexResponse = (PolicyUnresolveResponse)rpcMsg;
725         assertTrue(opflexResponse.getId().toString().contains(ID_UUID));
726     }
727
728     @Test
729     public void testPolicyUpdateRequest() throws Exception {
730         ObjectMapper objectMapper = new ObjectMapper();
731         System.out.println(opflexUpdateRequest);
732         RpcMessage rpcMsg = objectMapper.
733                 readValue(opflexUpdateRequest, PolicyUpdateRequest.class);
734         assertTrue(rpcMsg instanceof PolicyUpdateRequest);
735         PolicyUpdateRequest opflexResponse = (PolicyUpdateRequest)rpcMsg;
736         assertTrue(opflexResponse.getId().toString().contains(ID_UUID));
737         assertTrue(opflexResponse.getParams().get(0)
738                         .getDelete_uri().get(0).getValue().equals(POLICY_URI_VALUE.getValue()));
739         assertTrue(opflexResponse.getParams().get(0)
740                         .getMerge_children().get(0).getParent_relation().equals(PARENT_RELATION_NAME));
741         assertTrue(opflexResponse.getParams().get(0)
742                         .getMerge_children().get(0).getParent_subject().equals(PARENT_SUBJECT_NAME));
743         assertTrue(opflexResponse.getParams().get(0)
744                         .getMerge_children().get(0).getParent_uri().getValue().equals(PARENT_URI_NAME.getValue()));
745         assertTrue(opflexResponse.getParams().get(0)
746                         .getMerge_children().get(0).getUri().getValue().equals(URI_NAME.getValue()));
747         assertTrue(opflexResponse.getParams().get(0)
748                 .getMerge_children().get(0).getProperties().get(0).getName().equals(PROP_NAME));
749         assertTrue(opflexResponse.getParams().get(0)
750                 .getMerge_children().get(0).getProperties().get(0).getData().asText().equals(PROP_DATA));
751         assertTrue(opflexResponse.getParams().get(0)
752                 .getMerge_children().get(0).getSubject().equals(SUBJECT_NAME));
753         // TODO: add support for testing children?
754         assertTrue(opflexResponse.getParams().get(0)
755                         .getMerge_children().get(0).getChildren().size() == 0);
756         assertTrue(opflexResponse.getParams().get(0)
757                         .getReplace().get(0).getParent_relation().equals(PARENT_RELATION_NAME));
758         assertTrue(opflexResponse.getParams().get(0)
759                         .getReplace().get(0).getParent_subject().equals(PARENT_SUBJECT_NAME));
760         assertTrue(opflexResponse.getParams().get(0)
761                         .getReplace().get(0).getParent_uri().getValue().equals(PARENT_URI_NAME.getValue()));
762         assertTrue(opflexResponse.getParams().get(0)
763                         .getReplace().get(0).getUri().getValue().equals(URI_NAME.getValue()));
764         assertTrue(opflexResponse.getParams().get(0)
765                 .getReplace().get(0).getProperties().get(0).getName().equals(PROP_NAME));
766         assertTrue(opflexResponse.getParams().get(0)
767                 .getReplace().get(0).getProperties().get(0).getData().asText().equals(PROP_DATA));
768         assertTrue(opflexResponse.getParams().get(0)
769                 .getReplace().get(0).getSubject().equals(SUBJECT_NAME));
770         // TODO: add support for testing children?
771         assertTrue(opflexResponse.getParams().get(0)
772                         .getReplace().get(0).getChildren().size() == 0);
773     }
774
775     @Test
776     public void testUpdateResponse() throws Exception {
777         ObjectMapper objectMapper = new ObjectMapper();
778         RpcMessage rpcMsg = objectMapper.
779                 readValue(opflexUpdateResponse, PolicyUpdateResponse.class);
780         assertTrue(rpcMsg instanceof PolicyUpdateResponse);
781         PolicyUpdateResponse opflexResponse = (PolicyUpdateResponse)rpcMsg;
782         assertTrue(opflexResponse.getId().toString().contains(ID_UUID));
783
784     }
785
786
787     @Test
788     public void testEpDeclareRequest() throws Exception {
789         ObjectMapper objectMapper = new ObjectMapper();
790         RpcMessage rpcMsg = objectMapper.
791                 readValue(opflexEpDeclareRequest, EndpointDeclareRequest.class);
792         assertTrue(rpcMsg instanceof EndpointDeclareRequest);
793         EndpointDeclareRequest opflexResponse = (EndpointDeclareRequest)rpcMsg;
794         assertTrue(opflexResponse.getId().toString().contains(ID_UUID));
795         assertTrue(opflexResponse.getParams().get(0)
796                         .getEndpoint().get(0).getParent_relation().equals(PARENT_RELATION_NAME));
797         assertTrue(opflexResponse.getParams().get(0)
798                         .getEndpoint().get(0).getParent_subject().equals(PARENT_SUBJECT_NAME));
799         assertTrue(opflexResponse.getParams().get(0)
800                         .getEndpoint().get(0).getParent_uri().getValue().equals(PARENT_URI_NAME.getValue()));
801         assertTrue(opflexResponse.getParams().get(0)
802                         .getEndpoint().get(0).getUri().getValue().equals(URI_NAME.getValue()));
803         assertTrue(opflexResponse.getParams().get(0)
804                 .getEndpoint().get(0).getProperties().get(0).getName().equals(PROP_NAME));
805         assertTrue(opflexResponse.getParams().get(0)
806                 .getEndpoint().get(0).getProperties().get(0).getData().asText().equals(PROP_DATA));
807         assertTrue(opflexResponse.getParams().get(0)
808                 .getEndpoint().get(0).getSubject().equals(SUBJECT_NAME));
809         // TODO: add support for testing children?
810         assertTrue(opflexResponse.getParams().get(0)
811                         .getEndpoint().get(0).getChildren().size() == 0);
812         assertTrue(opflexResponse.getParams().get(0)
813                         .getPrr() == Integer.parseInt(PRR_VALUE));
814     }
815
816     @Test
817     public void testEpDeclareResponse() throws Exception {
818         ObjectMapper objectMapper = new ObjectMapper();
819         RpcMessage rpcMsg = objectMapper.
820                 readValue(opflexEpDeclareResponse, EndpointDeclareResponse.class);
821         assertTrue(rpcMsg instanceof EndpointDeclareResponse);
822         EndpointDeclareResponse opflexResponse = (EndpointDeclareResponse)rpcMsg;
823         assertTrue(opflexResponse.getId().toString().contains(ID_UUID));
824     }
825
826     @Test
827     public void testEndpointUndeclareRequest() throws Exception {
828         ObjectMapper objectMapper = new ObjectMapper();
829         RpcMessage rpcMsg = objectMapper.
830                 readValue(opflexEpUndeclareRequest, EndpointUndeclareRequest.class);
831         assertTrue(rpcMsg instanceof EndpointUndeclareRequest);
832         EndpointUndeclareRequest opflexRequest = (EndpointUndeclareRequest)rpcMsg;
833         assertTrue(opflexRequest.getId().toString().contains(ID_UUID));
834         assertTrue(opflexRequest.getMethod().equals(EndpointUndeclareRequest.UNDECLARE_MESSAGE));
835         assertTrue(opflexRequest.getParams()
836                         .get(0).getEndpoint_uri().getValue().equals(ENDPOINT_URI_VALUE.getValue()));
837         assertTrue(opflexRequest.getParams()
838                 .get(0).getSubject().equals(SUBJECT_NAME));
839
840     }
841
842
843     @Test
844     public void testEpUndeclareResponse() throws Exception {
845         ObjectMapper objectMapper = new ObjectMapper();
846         RpcMessage rpcMsg = objectMapper.
847                 readValue(opflexEpUndeclareResponse, EndpointUndeclareResponse.class);
848         assertTrue(rpcMsg instanceof EndpointUndeclareResponse);
849         EndpointUndeclareResponse opflexResponse = (EndpointUndeclareResponse)rpcMsg;
850         assertTrue(opflexResponse.getId().toString().contains(ID_UUID));
851     }
852
853     @Test
854     public void testEpResolveRequest1() throws Exception {
855         ObjectMapper objectMapper = new ObjectMapper();
856         RpcMessage rpcMsg = objectMapper.
857                 readValue(opflexEpResolveRequest1, EndpointResolveRequest.class);
858         assertTrue(rpcMsg instanceof EndpointResolveRequest);
859         EndpointResolveRequest opflexResponse = (EndpointResolveRequest)rpcMsg;
860         assertTrue(opflexResponse.getId().toString().contains(ID_UUID));
861         assertTrue(opflexResponse.getParams()
862                 .get(0).getSubject().equals(SUBJECT_NAME));
863         assertTrue(opflexResponse.getParams()
864                         .get(0).getEndpoint_uri().getValue().equals(ENDPOINT_URI_VALUE.getValue()));
865         assertTrue(opflexResponse.getParams()
866                         .get(0).getEndpoint_ident().getContext() == null);
867         assertTrue(opflexResponse.getParams()
868                         .get(0).getEndpoint_ident().getIdentifier() == null);
869     }
870
871
872     @Test
873     public void testEpResolveRequest2() throws Exception {
874         ObjectMapper objectMapper = new ObjectMapper();
875         System.out.println(opflexEpResolveRequest2);
876         RpcMessage rpcMsg = objectMapper.
877                 readValue(opflexEpResolveRequest2, EndpointResolveRequest.class);
878         assertTrue(rpcMsg instanceof EndpointResolveRequest);
879         EndpointResolveRequest opflexResponse = (EndpointResolveRequest)rpcMsg;
880         assertTrue(opflexResponse.getId().toString().contains(ID_UUID));
881         assertTrue(opflexResponse.getParams()
882                 .get(0).getSubject().equals(SUBJECT_NAME));
883         assertTrue(opflexResponse.getParams()
884                         .get(0).getEndpoint_uri().getValue() == "");
885         assertTrue(opflexResponse.getParams()
886                         .get(0).getEndpoint_ident().getIdentifier().equals(ENDPOINT_IDENT_URI));
887         assertTrue(opflexResponse.getParams()
888                         .get(0).getEndpoint_ident().getContext()
889                         .getValue().equals(ENDPOINT_IDENT_CONTEXT_VALUE.getValue()));
890     }
891
892     @Test
893     public void testEpResolveResponse() throws Exception {
894         ObjectMapper objectMapper = new ObjectMapper();
895         RpcMessage rpcMsg = objectMapper.
896                 readValue(opflexEpResponse, EndpointResolveResponse.class);
897         assertTrue(rpcMsg instanceof EndpointResolveResponse);
898         EndpointResolveResponse opflexResponse = (EndpointResolveResponse)rpcMsg;
899         assertTrue(opflexResponse.getId().toString().contains(ID_UUID));
900         assertTrue(opflexResponse.getResult()
901                         .getEndpoint().get(0).getParent_relation().equals(PARENT_RELATION_NAME));
902         assertTrue(opflexResponse.getResult()
903                         .getEndpoint().get(0).getParent_subject().equals(PARENT_SUBJECT_NAME));
904         assertTrue(opflexResponse.getResult()
905                         .getEndpoint().get(0).getParent_uri().getValue().equals(PARENT_URI_NAME.getValue()));
906         assertTrue(opflexResponse.getResult()
907                         .getEndpoint().get(0).getUri().getValue().equals(URI_NAME.getValue()));
908         assertTrue(opflexResponse.getResult()
909                 .getEndpoint().get(0).getProperties().get(0).getName().equals(PROP_NAME));
910         assertTrue(opflexResponse.getResult()
911                 .getEndpoint().get(0).getProperties().get(0).getData().asText().equals(PROP_DATA));
912         assertTrue(opflexResponse.getResult()
913                 .getEndpoint().get(0).getSubject().equals(SUBJECT_NAME));
914         // TODO: add support for testing children?
915         assertTrue(opflexResponse.getResult()
916                         .getEndpoint().get(0).getChildren().size() == 0);
917     }
918
919     @Test
920     public void testEpUnresolveRequest1() throws Exception {
921         ObjectMapper objectMapper = new ObjectMapper();
922         RpcMessage rpcMsg = objectMapper.
923                 readValue(opflexEpUnresolveRequest1, EndpointUnresolveRequest.class);
924         assertTrue(rpcMsg instanceof EndpointUnresolveRequest);
925         EndpointUnresolveRequest opflexResponse = (EndpointUnresolveRequest)rpcMsg;
926         assertTrue(opflexResponse.getId().toString().contains(ID_UUID));
927         assertTrue(opflexResponse.getParams()
928                 .get(0).getSubject().equals(SUBJECT_NAME));
929         assertTrue(opflexResponse.getParams()
930                         .get(0).getEndpoint_uri().getValue().equals(ENDPOINT_URI_VALUE.getValue()));
931         assertTrue(opflexResponse.getParams()
932                         .get(0).getEndpoint_ident().getContext() == null);
933         assertTrue(opflexResponse.getParams()
934                         .get(0).getEndpoint_ident().getIdentifier() == null);
935     }
936
937     @Test
938     public void testEpUnresolveRequest2() throws Exception {
939         ObjectMapper objectMapper = new ObjectMapper();
940         RpcMessage rpcMsg = objectMapper.
941                 readValue(opflexEpUnresolveRequest2, EndpointUnresolveRequest.class);
942         assertTrue(rpcMsg instanceof EndpointUnresolveRequest);
943         EndpointUnresolveRequest opflexResponse = (EndpointUnresolveRequest)rpcMsg;
944         assertTrue(opflexResponse.getId().toString().contains(ID_UUID));
945         assertTrue(opflexResponse.getParams()
946                 .get(0).getSubject().equals(SUBJECT_NAME));
947         assertTrue(opflexResponse.getParams()
948                         .get(0).getEndpoint_uri().getValue() == "");
949         assertTrue(opflexResponse.getParams()
950                         .get(0).getEndpoint_ident().getIdentifier().equals(ENDPOINT_IDENT_URI));
951         assertTrue(opflexResponse.getParams()
952                         .get(0).getEndpoint_ident().getContext()
953                         .getValue().equals(ENDPOINT_IDENT_CONTEXT_VALUE.getValue()));
954     }
955
956     @Test
957     public void testEpUnresolveResponse() throws Exception {
958         ObjectMapper objectMapper = new ObjectMapper();
959         RpcMessage rpcMsg = objectMapper.
960                 readValue(opflexEpUnresolveResponse, EndpointUnresolveResponse.class);
961         assertTrue(rpcMsg instanceof EndpointUnresolveResponse);
962         EndpointUnresolveResponse opflexResponse = (EndpointUnresolveResponse)rpcMsg;
963         assertTrue(opflexResponse.getId().toString().contains(ID_UUID));
964     }
965
966     @Test
967     public void testEpUpdateRequest() throws Exception {
968         ObjectMapper objectMapper = new ObjectMapper();
969         RpcMessage rpcMsg = objectMapper.
970                 readValue(opflexEpUpdateRequest, EndpointUpdateRequest.class);
971         assertTrue(rpcMsg instanceof EndpointUpdateRequest);
972         EndpointUpdateRequest opflexResponse = (EndpointUpdateRequest)rpcMsg;
973         assertTrue(opflexResponse.getId().toString().contains(ID_UUID));
974         assertTrue(opflexResponse.getParams().get(0)
975                         .getReplace().get(0).getParent_relation().equals(PARENT_RELATION_NAME));
976         assertTrue(opflexResponse.getParams().get(0)
977                         .getReplace().get(0).getParent_subject().equals(PARENT_SUBJECT_NAME));
978         assertTrue(opflexResponse.getParams().get(0)
979                         .getReplace().get(0).getParent_uri().getValue().equals(PARENT_URI_NAME.getValue()));
980         assertTrue(opflexResponse.getParams().get(0)
981                         .getReplace().get(0).getUri().getValue().equals(URI_NAME.getValue()));
982         assertTrue(opflexResponse.getParams().get(0)
983                 .getReplace().get(0).getProperties().get(0).getName().equals(PROP_NAME));
984         assertTrue(opflexResponse.getParams().get(0)
985                 .getReplace().get(0).getProperties().get(0).getData().asText().equals(PROP_DATA));
986         assertTrue(opflexResponse.getParams().get(0)
987                 .getReplace().get(0).getSubject().equals(SUBJECT_NAME));
988         // TODO: add support for testing children?
989         assertTrue(opflexResponse.getParams().get(0)
990                         .getReplace().get(0).getChildren().size() == 0);
991         assertTrue(opflexResponse.getParams().get(0)
992                         .getDelete_uri().get(0).getValue().equals(POLICY_URI_VALUE.getValue()));
993     }
994
995
996     @Test
997     public void testEpUpdateResponse() throws Exception {
998         ObjectMapper objectMapper = new ObjectMapper();
999         RpcMessage rpcMsg = objectMapper.
1000                 readValue(opflexEpUpdateResponse, EndpointUpdateResponse.class);
1001         assertTrue(rpcMsg instanceof EndpointUpdateResponse);
1002         EndpointUpdateResponse opflexResponse = (EndpointUpdateResponse)rpcMsg;
1003         assertTrue(opflexResponse.getId().toString().contains(ID_UUID));
1004     }
1005
1006
1007     //@Test
1008     public void testStateRequest() throws Exception {
1009         ObjectMapper objectMapper = new ObjectMapper();
1010         RpcMessage rpcMsg = objectMapper.
1011                 readValue(opflexStateRequest, StateReportRequest.class);
1012         assertTrue(rpcMsg instanceof StateReportRequest);
1013         StateReportRequest opflexResponse = (StateReportRequest)rpcMsg;
1014         assertTrue(opflexResponse.getId().toString().contains(ID_UUID));
1015         assertTrue(opflexResponse.getParams().get(0)
1016                         .getObservable().get(0).getParent_relation().equals(PARENT_RELATION_NAME));
1017         assertTrue(opflexResponse.getParams().get(0)
1018                         .getObservable().get(0).getParent_subject().equals(PARENT_SUBJECT_NAME));
1019         assertTrue(opflexResponse.getParams().get(0)
1020                         .getObservable().get(0).getParent_uri().equals(PARENT_URI_NAME.getValue()));
1021         assertTrue(opflexResponse.getParams().get(0)
1022                         .getObservable().get(0).getUri().equals(URI_NAME.getValue()));
1023         assertTrue(opflexResponse.getParams().get(0)
1024                 .getObservable().get(0).getProperties().get(0).getName().equals(PROP_NAME));
1025         assertTrue(opflexResponse.getParams().get(0)
1026                 .getObservable().get(0).getProperties().get(0).getData().asText().equals(PROP_DATA));
1027         assertTrue(opflexResponse.getParams().get(0)
1028                 .getObservable().get(0).getSubject().equals(SUBJECT_NAME));
1029         // TODO: add support for testing children?
1030         assertTrue(opflexResponse.getParams().get(0)
1031                         .getObservable().get(0).getChildren() == null);
1032         assertTrue(opflexResponse.getParams().get(0)
1033                         .getObject().getValue().equals(OBJECT_VALUE.getValue()));
1034     }
1035
1036     //@Test
1037     public void testStateResponse() throws Exception {
1038         ObjectMapper objectMapper = new ObjectMapper();
1039         RpcMessage rpcMsg = objectMapper.
1040                 readValue(opflexStateResponse, StateReportResponse.class);
1041         assertTrue(rpcMsg instanceof StateReportResponse);
1042         StateReportResponse opflexResponse = (StateReportResponse)rpcMsg;
1043         assertTrue(opflexResponse.getId().toString().contains(ID_UUID));
1044     }
1045
1046
1047
1048 }