Added MO object serialization and deserialization. 76/9176/1
authorThomas Bachman <tbachman@yahoo.com>
Fri, 18 Jul 2014 16:48:43 +0000 (16:48 +0000)
committerThomas Bachman <tbachman@yahoo.com>
Sat, 19 Jul 2014 00:56:09 +0000 (00:56 +0000)
This adds the ManagedObject POJO to the relevant OpFlex RpcMessage
objects, along with unit tests for them.

This commit also addresses some compiler warnings, and adds back
in the OpflexConnectionService unit tests (added code to select
available server socket within a range).

Change-Id: I1a664fa0aec700554691b7dcc49aa65828721f5c
Signed-off-by: Thomas Bachman <tbachman@yahoo.com>
14 files changed:
groupbasedpolicy/src/main/java/org/opendaylight/controller/config/yang/config/opflex_provider/impl/OpflexProviderModule.java
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/jsonrpc/JsonRpcDecoder.java
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/jsonrpc/JsonRpcEndpoint.java
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/jsonrpc/RpcServer.java
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/renderer/opflex/OpflexConnectionService.java
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/renderer/opflex/OpflexRpcServer.java
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/renderer/opflex/messages/ManagedObject.java [new file with mode: 0644]
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/renderer/opflex/messages/PolicyResolutionResponse.java
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/renderer/opflex/messages/PolicyUpdateRequest.java
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/renderer/opflex/messages/StateReportRequest.java
groupbasedpolicy/src/test/java/org/opendaylight/groupbasedpolicy/jsonrpc/JsonRpcEndpointTest.java
groupbasedpolicy/src/test/java/org/opendaylight/groupbasedpolicy/jsonrpc/RpcServerTest.java
groupbasedpolicy/src/test/java/org/opendaylight/groupbasedpolicy/renderer/opflex/OpflexConnectionServiceTest.java
groupbasedpolicy/src/test/java/org/opendaylight/groupbasedpolicy/renderer/opflex/OpflexMessageTest.java

index 5ce3532970d113df099951135d13e28ccf830719..4d4c0913f9a12318d5aaff33d8004c2f3ddbe490 100644 (file)
@@ -21,6 +21,7 @@ public class OpflexProviderModule extends org.opendaylight.controller.config.yan
         // add custom validation form module attributes here.
     }
 
+    @SuppressWarnings("resource")
     @Override
     public java.lang.AutoCloseable createInstance() {
         final OpflexConnectionService connectionService = new OpflexConnectionService();
index 8da13ed80b49866246120d81a90ddf4c0ffb4a25..fa701b168163410763c40ecce275e6011387fa87 100644 (file)
@@ -134,9 +134,8 @@ public class JsonRpcDecoder extends ByteToMessageDecoder {
             int ch = b.getByte(b.readerIndex()) & 0xFF;
             if (!(ch == ' ' || ch == '\r' || ch == '\n' || ch == '\t')) {
                 return;
-            } else {
-                b.readByte(); //move the read index
             }
+            b.readByte(); //move the read index
         }
     }
 
index 1faef8a6019b79bf98168594c33592f117595c60..92667d01314cbbeccd95af054f863420bec3dda7 100644 (file)
@@ -46,12 +46,10 @@ public class JsonRpcEndpoint implements ChannelFutureListener {
 
     private static class CallContext {
         private String method;
-        private RpcMessage request;
         private SettableFuture<Object> future;
 
-        public CallContext(RpcMessage request, String method, SettableFuture<Object> future) {
+        public CallContext(String method, SettableFuture<Object> future) {
             this.method = method;
-            this.request = request;
             this.future = future;
         }
 
@@ -59,10 +57,6 @@ public class JsonRpcEndpoint implements ChannelFutureListener {
             return method;
         }
 
-        public RpcMessage getRequest() {
-            return request;
-        }
-
         public SettableFuture<Object> getFuture() {
             return future;
         }
@@ -134,7 +128,7 @@ public class JsonRpcEndpoint implements ChannelFutureListener {
         logger.trace("invoke: {}", s);
 
         SettableFuture<Object> sf = SettableFuture.create();
-        methodContext.put(message.getId(), new CallContext(message, message.getName(), sf));
+        methodContext.put(message.getId(), new CallContext(message.getName(), sf));
 
         nettyChannel.writeAndFlush(s);
 
@@ -165,7 +159,7 @@ public class JsonRpcEndpoint implements ChannelFutureListener {
      */
     public void processResult(JsonNode response) throws NoSuchMethodException {
 
-        logger.trace("Response : {}", response.toString());
+        logger.warn("Response : {}", response.toString());
         CallContext returnCtxt = methodContext.get(response.get("id").asText());
         if (returnCtxt == null) return;
         RpcMessage message = messageMap.get(returnCtxt.getMethod());
index 853512fba0e499c343d7ce19473fdbe07c86e837..06442a6c1c4e4a0791beef7229cafcb396e2c874 100644 (file)
@@ -98,7 +98,7 @@ public class RpcServer {
         return this.channel;
     }
 
-    private void handleNewConnection(String identifier, Channel channel)
+    void handleNewConnection(String identifier, Channel newChannel)
             throws InterruptedException, ExecutionException {
 
         ObjectMapper objectMapper = new ObjectMapper();
@@ -106,15 +106,15 @@ public class RpcServer {
                 DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 
         JsonRpcEndpoint endpoint = new JsonRpcEndpoint(identifier, connectionService,
-                objectMapper, channel, messageMap, broker);
+                objectMapper, newChannel, messageMap, broker);
         endpoint.setContext(context);
         JsonRpcServiceBinderHandler binderHandler =
                 new JsonRpcServiceBinderHandler(endpoint);
-        channel.pipeline().addLast(binderHandler);
+        newChannel.pipeline().addLast(binderHandler);
 
         connectionService.addConnection(endpoint);
 
-        ChannelFuture closeFuture = channel.closeFuture();
+        ChannelFuture closeFuture = newChannel.closeFuture();
         closeFuture.addListener(endpoint);
     }
 
@@ -129,21 +129,21 @@ public class RpcServer {
                     .handler(new LoggingHandler(LogLevel.INFO))
                     .childHandler(new ChannelInitializer<SocketChannel>() {
                         @Override
-                        public void initChannel(SocketChannel channel)
+                        public void initChannel(SocketChannel ch)
                                 throws Exception {
                             logger.debug("New Passive channel created : "
-                                    + channel.toString());
-                            InetAddress address = channel.remoteAddress()
+                                    + ch.toString());
+                            InetAddress address = ch.remoteAddress()
                                     .getAddress();
-                            int port = channel.remoteAddress().getPort();
+                            int port = ch.remoteAddress().getPort();
                             String identifier = address.getHostAddress() + ":"
                                     + port;
-                            channel.pipeline().addLast(
+                            ch.pipeline().addLast(
                                     new LoggingHandler(LogLevel.INFO),
                                     new JsonRpcDecoder(100000),
                                     new StringEncoder(CharsetUtil.UTF_8));
 
-                            handleNewConnection(identifier, channel);
+                            handleNewConnection(identifier, ch);
                             logger.warn("Connected Node : " + identifier);
                         }
                     });
index e3d6afe09927542f1a48ab360906e83bed263c16..44094bcb983df5814fc4e729017bd0d95119102f 100644 (file)
@@ -23,7 +23,6 @@ import java.util.concurrent.ScheduledExecutorService;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.groupbasedpolicy.jsonrpc.ConnectionService;
@@ -34,16 +33,13 @@ import org.opendaylight.groupbasedpolicy.jsonrpc.RpcServer;
 import org.opendaylight.groupbasedpolicy.renderer.opflex.messages.IdentityRequest;
 import org.opendaylight.groupbasedpolicy.renderer.opflex.messages.IdentityResponse;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.opflex.rev140528.Domains;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.opflex.rev140528.DomainsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.opflex.rev140528.domains.Domain;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.opflex.rev140528.domains.DomainKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.opflex.rev140528.domains.domain.DiscoveryDefinitions;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.opflex.rev140528.domains.domain.discovery.definitions.EndpointRegistry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.opflex.rev140528.domains.domain.discovery.definitions.Observer;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.opflex.rev140528.domains.domain.discovery.definitions.PolicyRepository;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -97,11 +93,6 @@ public class OpflexConnectionService
     public static final InstanceIdentifier<Domains> DOMAINS_IID =
             InstanceIdentifier.builder(Domains.class).build();
 
-    public InstanceIdentifier<Domain> domainIid(DomainKey domainKey) {
-        return InstanceIdentifier.builder(Domains.class).child(Domain.class, domainKey)
-                .build();
-    }
-
     public OpflexConnectionService() {
         int numCPU = Runtime.getRuntime().availableProcessors();
         executor = Executors.newScheduledThreadPool(numCPU * 2);
@@ -120,7 +111,7 @@ public class OpflexConnectionService
         start();
     }
 
-    private List<OpflexRpcServer> setDefaultIdentities(OpflexDomain domain) {
+    private List<OpflexRpcServer> setDefaultIdentities(OpflexDomain od) {
 
         /*
          * Create a single server, filling all roles
@@ -132,8 +123,6 @@ public class OpflexConnectionService
         roles.add(Role.ENDPOINT_REGISTRY);
         roles.add(Role.OBSERVER);
 
-        OpflexDomain od = new OpflexDomain();
-        od.setDomain(OPFLEX_DOMAIN);
         OpflexRpcServer srv = new OpflexRpcServer(od, identity, roles);
         srv.setConnectionService(this);
         srv.setRpcBroker(this);
@@ -159,32 +148,10 @@ public class OpflexConnectionService
         return null;
     }
 
-    private void initializeConfig() {
-        // XXX - This is a hack to avoid a bug in the data broker
-        // API where you have to write all the parents before you can write
-        // a child
-        WriteTransaction t = dataProvider.newWriteOnlyTransaction();
-        t.put(LogicalDatastoreType.CONFIGURATION, DOMAINS_IID, new DomainsBuilder().build());
-        ListenableFuture<RpcResult<TransactionStatus>> f = t.commit();
-        Futures.addCallback(f, new FutureCallback<RpcResult<TransactionStatus>>() {
-
-            @Override
-            public void onSuccess(RpcResult<TransactionStatus> result) {
-
-            }
-
-            @Override
-            public void onFailure(Throwable t) {
-                logger.error("Could not write domain base container", t);
-            }
-        });
-    }
-
     private void initializeServers() {
 
         OpflexDomain od;
 
-        //initializeConfig();
         readConfig();
         /*
          * Get the configured identities, if any. If lists are empty,
@@ -201,7 +168,7 @@ public class OpflexConnectionService
         }
         else {
             // TODO: should also write into config store?
-            logger.warn("Setting default identities");
+            logger.info("Setting default identities");
             od = new OpflexDomain();
             od.setDomain(OPFLEX_DOMAIN);
             od.addServers(setDefaultIdentities(od));
@@ -320,6 +287,9 @@ public class OpflexConnectionService
     }
 
 
+    /**
+     * Start the {@link OpflexConnectionService}
+     */
     public void start() {
         opflexDomains = new ConcurrentHashMap<String, OpflexDomain>();
         brokerMap = new ConcurrentHashMap<String, List<RpcCallback>>();
@@ -362,29 +332,12 @@ public class OpflexConnectionService
 
 
     private void deleteDomain(String domain) {
-
         OpflexDomain od = opflexDomains.remove(domain);
         if (od != null) {
             od.cleanup();
         }
     }
 
-    /**
-     * Close the connection service. Implemented from the
-     * AutoCloseable interface.
-     */
-     @Override
-     public void close() throws ExecutionException, InterruptedException {
-
-         executor.shutdownNow();
-
-         if (dataProvider != null) {
-             WriteTransaction t = dataProvider.newWriteOnlyTransaction();
-             t.delete(LogicalDatastoreType.CONFIGURATION, DOMAINS_IID);
-             t.commit().get();
-         }
-     }
-
      private void readConfig() {
          ListenableFuture<Optional<Domains>> dao =
                  dataProvider.newReadOnlyTransaction()
@@ -393,7 +346,6 @@ public class OpflexConnectionService
              @Override
              public void onSuccess(final Optional<Domains> result) {
                  if (!result.isPresent()) {
-                     logger.warn("No result!!!");
                      return;
                  }
                  getNewConfig(result);
@@ -406,89 +358,99 @@ public class OpflexConnectionService
          }, executor);
      }
 
-     private void getNewConfig(final Optional<Domains> result) {
+     void getNewConfig(final Optional<Domains> result) {
 
          List<String> currentDomains = new ArrayList<String>(opflexDomains.keySet());
          List<String> newDomains = new ArrayList<String>();
-         List<String> addList = new ArrayList<String>();
-         List <String> dropList = new ArrayList<String>();
-         List <String> updateList = new ArrayList<String>();
 
-         if (result.get() instanceof Domains) {
 
-             /*
-              * Get the new list of domains from the
-              * configuration store, and convert to a
-              * list of the actual domain names for list
-              * manipulation
-              */
-             Domains domains = (Domains)result.get();
+         /*
+          * Get the new list of domains from the
+          * configuration store, and convert to a
+          * list of the actual domain names for list
+          * manipulation
+          */
+         Domains domains = result.get();
 
-             domainList = domains.getDomain();
-             for (Domain domainObj : domainList) {
-                 newDomains.add(domainObj.getId());
-             }
+         domainList = domains.getDomain();
+         for (Domain domainObj : domainList) {
+             newDomains.add(domainObj.getId());
+         }
 
-             logger.warn("Current domains {}", currentDomains);
-             /*
-              * Find out what's changed at the domain level.
-              * Classify as additions, deletions, and updates
-              */
-             addList = new ArrayList<String>(newDomains);
-             dropList = new ArrayList<String>(currentDomains);
-             updateList = new ArrayList<String>(newDomains);
-             addList.removeAll(currentDomains);
-             dropList.removeAll(newDomains);
-             updateList.removeAll(addList);
-
-             /*
-              * Drop domains that were removed, along with all
-              * of their servers and connections
-              */
-             for (String d : dropList) {
-                 deleteDomain(d);
-             }
+         /*
+          * Find out what's changed at the domain level.
+          * Classify as additions, deletions, and updates
+          */
+         List<String> addList = new ArrayList<String>(newDomains);
+         List <String> dropList = new ArrayList<String>(currentDomains);
+         List <String> updateList = new ArrayList<String>(newDomains);
+         addList.removeAll(currentDomains);
+         dropList.removeAll(newDomains);
+         updateList.removeAll(addList);
+
+         /*
+          * Drop domains that were removed, along with all
+          * of their servers and connections
+          */
+         for (String d : dropList) {
+             deleteDomain(d);
+         }
 
-             /*
-              * These are entirely new domains -- get the
-              * information for each new domain and configure
-              */
-             for (String d : addList) {
-                 OpflexDomain od = new OpflexDomain();
-                 od.setDomain(d);
-                 opflexDomains.put(od.getDomain(), od );
-
-                 /* Spawn the servers for this domain */
-                 for (Domain dl : domainList) {
-                     if (dl.getId().equals(d)) {
-                         od.addServers(createServerList(od, dl));
-                         break;
-                     }
+         /*
+          * These are entirely new domains -- get the
+          * information for each new domain and configure
+          */
+         for (String d : addList) {
+             OpflexDomain od = new OpflexDomain();
+             od.setDomain(d);
+             opflexDomains.put(od.getDomain(), od );
+
+             /* Spawn the servers for this domain */
+             for (Domain dl : domainList) {
+                 if (dl.getId().equals(d)) {
+                     od.addServers(createServerList(od, dl));
+                     break;
                  }
              }
+         }
 
-             /*
-              * These are domains with updates
-              */
-             for (String d : updateList) {
-                 OpflexDomain od = opflexDomains.get(d);
-                 for (Domain domainObj : domainList) {
-                     if (domainObj.getId().equals(d)) {
-                         logger.warn("updateServers");
-                         od.updateServers(createServerList(od, domainObj));
-                         break;
-                     }
+         /*
+          * These are domains with updates
+          */
+         for (String d : updateList) {
+             OpflexDomain od = opflexDomains.get(d);
+             for (Domain domainObj : domainList) {
+                 if (domainObj.getId().equals(d)) {
+                     od.updateServers(createServerList(od, domainObj));
+                     break;
                  }
              }
          }
      }
 
-     @Override
+    @Override
     public void onDataChanged( final AsyncDataChangeEvent<InstanceIdentifier<?>,
             DataObject>change) {
 
         readConfig();
     }
+    
+    /**
+     * Close the connection service. Implemented from the
+     * AutoCloseable interface.
+     */
+     @Override
+     public void close() throws ExecutionException, InterruptedException {
+
+         executor.shutdownNow();
+
+         if (dataProvider != null) {
+             WriteTransaction t = dataProvider.newWriteOnlyTransaction();
+             t.delete(LogicalDatastoreType.CONFIGURATION, DOMAINS_IID);
+             t.commit().get();
+         }
+     }
+
 
     @Override
     public void subscribe(RpcMessage message, RpcCallback callback) {
@@ -522,6 +484,11 @@ public class OpflexConnectionService
         }
     }
 
+    /**
+     * This notification handles the OpFlex Identity request messages.
+     * 
+     * TODO: implement Identity Response messages
+     */
     @Override
     public void callback(JsonRpcEndpoint endpoint, RpcMessage message) {
 
@@ -600,13 +567,21 @@ public class OpflexConnectionService
         }
     }
 
+    /**
+     * This is the notification when a new endpoint
+     * has been created. Since the endpoint is new,
+     * we don't have a OpflexConnection for it yet. We
+     * create the OpflexConnection, then retrieve the
+     * OpflexRpcServer that created this connections
+     * to inherit some of the fields we need (domain, server).
+     */
     @Override
     public void addConnection(JsonRpcEndpoint endpoint) {
 
         /*
-         * When the connection is added, we don't have a context
-         * other than the JsonRpcEndpoint. We use the context
-         * field to store the server object that created this
+         * When the connection is added, we only have the 
+         * JsonRpcEndpoint. We use the JsonRpcEndpoint's 
+         * context field to store the server object that created this
          * connection, and can look up things like the domain,
          * etc. to create the containing connection object.
          */
@@ -620,24 +595,8 @@ public class OpflexConnectionService
         OpflexRpcServer server = (OpflexRpcServer)endpoint.getContext();
         OpflexDomain domain = server.getDomain();
 
-
-        /*
-         * This is the notification when a new endpoint
-         * has been created. Since the endpoint is new,
-         * we don't have a OpflexConnection for it yet. We
-         * create the OpflexConnection, then get the
-         * OpflexRpcServer to set some of the fields
-         * we need (domain, server).
-         */
-        OpflexAgent oc = new OpflexAgent();
-        oc.setEndpoint(endpoint);
-        oc.setIdentity(endpoint.getIdentifier());
-        oc.setDomain(domain.getDomain());
-        oc.setOpflexServer(server);
-        oc.setRoles(server.getRoles());
-
         /*
-         * The OpFlex domain is determined by the server socket
+         * The OpFlex domain is the same as the server 
          * that the agent connected to. Look up the OpFlex RPC
          * server using the server socket.
          *
@@ -646,10 +605,25 @@ public class OpflexConnectionService
          * condition). Treat that as a failure, closing the
          * connection.
          */
-        logger.warn("Adding agent {}", endpoint.getIdentifier());
+        OpflexAgent oc = new OpflexAgent();
+        oc.setEndpoint(endpoint);
+        oc.setIdentity(endpoint.getIdentifier());
+        oc.setDomain(domain.getDomain());
+        oc.setOpflexServer(server);
+        oc.setRoles(server.getRoles());
+
+        logger.info("Adding agent {}", endpoint.getIdentifier());
         domain.addOpflexAgent(oc);
     }
 
+    /**
+     * This is the notification we receive when a connection 
+     * is closed. Retrieve the domain from the {@link JsonRpcEndpoint}'s
+     * context field to get the {@link OpflexRpcServer}, which contains
+     * the OpFlex domain for this connection, then use the identity from 
+     * the {@link JsonRpcEndpoint} and domain to remove the {@link OpflexAgent} 
+     * from the domain
+     */
     @Override
     public void channelClosed(JsonRpcEndpoint endpoint) throws Exception {
         logger.info("Connection to Node : {} closed", endpoint.getIdentifier());
index a2e62bb3d3e75ed4b6a3f9ae7a3b61c4b5545b79..ce1d4683143e9674aabe511d2cc1432508ce2dbf 100644 (file)
@@ -37,11 +37,11 @@ public class OpflexRpcServer {
     private String address;
     private int port;
 
-    private void parseAndSetIdentity(String identity) {
-        if (identity.split(":").length == 2) {
-            this.identity = identity;
-            this.address = identity.split(":")[0];
-            this.port =  Integer.parseInt(identity.split(":")[1]);
+    private void parseAndSetIdentity(String id) {
+        if (id.split(":").length == 2) {
+            this.identity = id;
+            this.address = id.split(":")[0];
+            this.port =  Integer.parseInt(id.split(":")[1]);
         }
     }
 
@@ -105,8 +105,8 @@ public class OpflexRpcServer {
         new Thread() {
             private RpcServer server;
 
-            public Thread initializeServerParams(RpcServer server) {
-                this.server = server;
+            public Thread initializeServerParams(RpcServer srv) {
+                this.server = srv;
                 return this;
             }
             @Override
diff --git a/groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/renderer/opflex/messages/ManagedObject.java b/groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/renderer/opflex/messages/ManagedObject.java
new file mode 100644 (file)
index 0000000..d8d5738
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2014 Cisco Systems, Inc.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Authors : Thomas Bachman
+ */
+package org.opendaylight.groupbasedpolicy.renderer.opflex.messages;
+
+import java.util.List;
+
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+
+@JsonSerialize
+@JsonDeserialize
+public class ManagedObject {
+
+    public static class Properties {
+        private String name;
+        public String getName() {
+            return name;
+        }
+        public void setName(String name) {
+            this.name = name;
+        }
+        public String getData() {
+            return data;
+        }
+        public void setData(String data) {
+            this.data = data;
+        }
+        private String data;
+    }
+    
+    public String getName() {
+        return name;
+    }
+    public void setName(String name) {
+        this.name = name;
+    }
+    public List<Properties> getProperties() {
+        return properties;
+    }
+    public void setProperties(List<Properties> properties) {
+        this.properties = properties;
+    }
+    public List<ManagedObject> getChildren() {
+        return children;
+    }
+    public void setChildren(List<ManagedObject> children) {
+        this.children = children;
+    }
+    public List<ManagedObject> getStatistics() {
+        return statistics;
+    }
+    public void setStatistics(List<ManagedObject> statistics) {
+        this.statistics = statistics;
+    }
+    public List<ManagedObject> getFrom_relations() {
+        return from_relations;
+    }
+    public void setFrom_relations(List<ManagedObject> from_relations) {
+        this.from_relations = from_relations;
+    }
+    public List<ManagedObject> getTo_relations() {
+        return to_relations;
+    }
+    public void setTo_relations(List<ManagedObject> to_relations) {
+        this.to_relations = to_relations;
+    }
+    public List<ManagedObject> getFaults() {
+        return faults;
+    }
+    public void setFaults(List<ManagedObject> faults) {
+        this.faults = faults;
+    }
+    public List<ManagedObject> getHealth() {
+        return health;
+    }
+    public void setHealth(List<ManagedObject> health) {
+        this.health = health;
+    }
+    private String name;
+    private List<Properties> properties;
+    private List<ManagedObject> children;
+    private List<ManagedObject> statistics;
+    private List<ManagedObject> from_relations;
+    private List<ManagedObject> to_relations;
+    private List<ManagedObject> faults;
+    private List<ManagedObject> health;
+    
+}
index ebb5a5b0baed070225699cf7559e6a53ea051c64..6c2e9f825d225aa303014e448bb785bf07e0b05c 100644 (file)
@@ -24,12 +24,12 @@ public class PolicyResolutionResponse extends RpcMessage {
     public static final String POLICY_MESSAGE_RESPONSE = "resolve_policy_response";
 
     static public class Result {
-        private List<String> policy;   // TODO: replace with MOs
+        private List<ManagedObject> policy;
         private int prr;
-        public List<String> getPolicy() {
+        public List<ManagedObject> getPolicy() {
             return policy;
         }
-        public void setPolicy(List<String> policy) {
+        public void setPolicy(List<ManagedObject> policy) {
             this.policy = policy;
         }
         public int getPrr() {
index bb40d39c1c9af126cd44d9874461eb260ea40cef..e2245542b476b1db94133deefa569f2f50babdb1 100644 (file)
@@ -25,7 +25,7 @@ public class PolicyUpdateRequest extends RpcMessage {
 
     static public class Params {
         private String context;
-        private List<String> subtree;
+        private List<ManagedObject> subtree;
         private int prr;
         public String getContext() {
             return context;
@@ -33,10 +33,10 @@ public class PolicyUpdateRequest extends RpcMessage {
         public void setContext(String context) {
             this.context = context;
         }
-        public List<String> getSubtree() {
+        public List<ManagedObject> getSubtree() {
             return subtree;
         }
-        public void setSubtree(List<String> subtree) {
+        public void setSubtree(List<ManagedObject> subtree) {
             this.subtree = subtree;
         }
         public int getPrr() {
index 76d4ec5a6c7a7f241fbc65a6a53972e35192a58c..5de2a2eaf57eacc2c5368fd948bc1bbfa57bf9dd 100644 (file)
@@ -26,11 +26,11 @@ public class StateReportRequest extends RpcMessage {
     static public class Params {
         private String subject;
         private String context;
-        private String object;   // TODO: change to MOs
-        private List<String> fault;
-        private List<String> event;
-        private List<String> statistics;
-        private List<String> health;
+        private ManagedObject object;
+        private List<ManagedObject> fault;
+        private List<ManagedObject> event;
+        private List<ManagedObject> statistics;
+        private List<ManagedObject> health;
         public String getSubject() {
             return subject;
         }
@@ -43,34 +43,34 @@ public class StateReportRequest extends RpcMessage {
         public void setContext(String context) {
             this.context = context;
         }
-        public String getObject() {
+        public ManagedObject getObject() {
             return object;
         }
-        public void setObject(String object) {
+        public void setObject(ManagedObject object) {
             this.object = object;
         }
-        public List<String> getFault() {
+        public List<ManagedObject> getFault() {
             return fault;
         }
-        public void setFault(List<String> fault) {
+        public void setFault(List<ManagedObject> fault) {
             this.fault = fault;
         }
-        public List<String> getEvent() {
+        public List<ManagedObject> getEvent() {
             return event;
         }
-        public void setEvent(List<String> event) {
+        public void setEvent(List<ManagedObject> event) {
             this.event = event;
         }
-        public List<String> getStatistics() {
+        public List<ManagedObject> getStatistics() {
             return statistics;
         }
-        public void setStatistics(List<String> statistics) {
+        public void setStatistics(List<ManagedObject> statistics) {
             this.statistics = statistics;
         }
-        public List<String> getHealth() {
+        public List<ManagedObject> getHealth() {
             return health;
         }
-        public void setHealth(List<String> health) {
+        public void setHealth(List<ManagedObject> health) {
             this.health = health;
         }
     }
index d5fd3c6cb7e4761714ce7a95a42d4ffc3e150c11..9133bb365329055f01467f5895fbb44c8bfd915b 100644 (file)
@@ -72,9 +72,9 @@ public class JsonRpcEndpointTest implements RpcBroker, RpcBroker.RpcCallback {
     }
 
     @Override
-    public void publish(JsonRpcEndpoint endpoint, RpcMessage message) {
+    public void publish(JsonRpcEndpoint ep, RpcMessage message) {
         testTriggerFlag = true;
-        callback(endpoint, message);
+        callback(ep, message);
     }
 
     @JsonDeserialize
@@ -167,14 +167,13 @@ public class JsonRpcEndpointTest implements RpcBroker, RpcBroker.RpcCallback {
     }
 
     @Override
-    public void callback(JsonRpcEndpoint endpoint, RpcMessage message) {
+    public void callback(JsonRpcEndpoint ep, RpcMessage message) {
 
         if (message != null && message instanceof JsonRpcEndpointTest.OpflexTest) {
             JsonRpcEndpointTest.OpflexTest msg = (JsonRpcEndpointTest.OpflexTest)message;
             if ( msg.getParams() == null) {
                 return;
             }
-            List<String> roles = msg.params.get(0).getMy_role();
         }
     }
 
index 106f48a0597ad49faf7a432a329691514a25fabe..bed7e0f95781d58c14e3ba6038c299b81d05f3d8 100644 (file)
@@ -20,8 +20,7 @@ public class RpcServerTest implements ConnectionService, RpcBroker {
 
     private static final String TEST_IP = "127.0.0.1";
     private static final int TEST_PORT = 53670;
-    private static boolean newConnection = false;
-    private static boolean serverClosed = false;
+
 
     @Override
     public void addConnection(JsonRpcEndpoint endpoint) {
index 28046062da50cf7acf2fbf6d5254e0f774d02dca..4a8561f7bad66bb77909786fb14c7287cec706b4 100644 (file)
@@ -18,10 +18,13 @@ import static org.mockito.Mockito.when;
 import io.netty.channel.embedded.EmbeddedChannel;
 import io.netty.util.CharsetUtil;
 
+import java.io.IOException;
+import java.net.ServerSocket;
 import java.util.ArrayList;
 import java.util.List;
 
 import org.junit.Before;
+import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.mockito.MockitoAnnotations;
@@ -64,7 +67,6 @@ public class OpflexConnectionServiceTest {
 
     static private final String TEST_EP_UUID = "85d53c32-47af-4eaf-82fd-ced653ff74da";
     static public final String TEST_IP = "127.0.0.1";
-    static public final String TEST_PORT = "57563";
 
     static private final String ID_UUID = "2da9e3d7-0bbe-4099-b343-12783777452f";
     static private final String SEND_IDENTITY = "send_identity";
@@ -108,14 +110,39 @@ public class OpflexConnectionServiceTest {
     private Optional<Domains> mockDao;
     @Mock
     private Domains mockDomains;
-    @Mock
-    private Domain mockDomain;
+    @Mock Domain mockDomain;
     @Mock
     private OpflexDomain mockOpflexDomain;
     @Mock
     private OpflexRpcServer mockOpflexServer;
     @Mock
     private OpflexAgent mockAgent;
+    
+    private ServerSocket create(int[] ports) throws IOException {
+        for (int port : ports) {
+            try {
+                return new ServerSocket(port);
+            } catch (IOException ex) {
+                continue; // try next port
+            }
+        }
+
+        // if the program gets here, no port in the range was found
+        throw new IOException("no free port found");
+    }
+    
+    private int getAvailableServerPort() {
+        try {
+            int freePort;
+            ServerSocket s = create(new int[] 
+                    { 6670, 6671, 6672, 6673, 6674, 6675, 6676, 6677, 6678 });
+            freePort = s.getLocalPort();
+            s.close();
+            return freePort;
+        } catch (IOException ex) {
+            return 0;
+        }
+    }
 
     @Before
     public void setUp() throws Exception {
@@ -132,7 +159,10 @@ public class OpflexConnectionServiceTest {
         when(mockOption.get()).thenReturn(mockDao);
         when(mockDao.get()).thenReturn(mockDomains);
         when(mockDomains.getDomain())
-        .thenReturn(new ArrayList<Domain>() {{ add(mockDomain); }});
+        .thenReturn(new ArrayList<Domain>() {          
+            private static final long serialVersionUID = 6302503537798173568L;
+            { add(mockDomain); }});
+        
         when(mockDomain.getDiscoveryDefinitions()).thenReturn(dummyDefinitions);
 
         /*
@@ -143,13 +173,15 @@ public class OpflexConnectionServiceTest {
         prBuilder = new PolicyRepositoryBuilder();
         oBuilder = new ObserverBuilder();
 
-
-        // TODO: needs deterministic way of finding available socket
-        System.setProperty(OpflexConnectionService.OPFLEX_LISTENPORT, TEST_PORT);
+        int testPort = getAvailableServerPort();
+        if ( testPort == 0) {
+            assertTrue(1==0);
+        }
+        System.setProperty(OpflexConnectionService.OPFLEX_LISTENPORT, Integer.toString(testPort));
         System.setProperty(OpflexConnectionService.OPFLEX_LISTENIP, TEST_IP);
     }
 
-    //@Test
+    @Test
     public void testNoDefinitions() throws Exception {
 
         opflexService = new OpflexConnectionService();
@@ -157,17 +189,18 @@ public class OpflexConnectionServiceTest {
         verify(mockDataBroker).newReadOnlyTransaction();
     }
 
-    //@Test
+    @Test
     public void testInitialSet() throws Exception {
         registries = new ArrayList<EndpointRegistry>();
         repositories = new ArrayList<PolicyRepository>();
         observers = new ArrayList<Observer>();
+        int serverPort = getAvailableServerPort();
         EndpointRegistry epr = eprBuilder.setId(TEST_IP)
-                .setPort(Integer.valueOf(TEST_PORT)).build();
+                .setPort(serverPort).build();
         PolicyRepository pr = prBuilder.setId(TEST_IP)
-                .setPort(Integer.valueOf(TEST_PORT)).build();
+                .setPort(serverPort).build();
         Observer o = oBuilder.setId(TEST_IP)
-                .setPort(Integer.valueOf(TEST_PORT)).build();
+                .setPort(serverPort).build();
         registries.add(epr);
         repositories.add(pr);
         observers.add(o);
@@ -180,7 +213,7 @@ public class OpflexConnectionServiceTest {
 
     }
 
-    //@Test
+    @Test
     public void testAddConnection() throws Exception {
         when(mockEp.getIdentifier()).thenReturn(TEST_EP_UUID);
         when(mockEp.getContext()).thenReturn(mockOpflexServer);
@@ -194,7 +227,7 @@ public class OpflexConnectionServiceTest {
         verify(mockOpflexDomain, Mockito.times(1)).addOpflexAgent((OpflexAgent)anyObject());
     }
 
-    //@Test
+    @Test
     public void testChannelClosed() throws Exception {
         when(mockEp.getIdentifier()).thenReturn(TEST_EP_UUID);
         when(mockEp.getContext()).thenReturn(mockOpflexServer);
@@ -218,7 +251,7 @@ public class OpflexConnectionServiceTest {
         verify(mockAgent).getIdentity();
     }
 
-    //@Test
+    @Test
     public void testPublishSubscribeCallback() throws Exception {
 
         List<Role> testRoles = new ArrayList<Role>();
index 25a4c7dd5654d91548c2b4151f0eafafca5da59a..b545801ff7d41b58823493179bc8c459e29043ad 100644 (file)
@@ -94,6 +94,9 @@ public class OpflexMessageTest {
     public static final String SUBJECT = "webContract";
     public static final String CONTEXT = "353786fd-7327-41dd-b7de-5d672e303730";
     public static final String POLICY_NAME = "webFarmEpg";
+    public static final String PROP_NAME = "subject";
+    public static final String PROP_DATA = "http";
+    public static final String MO_NAME = "webFarmContract";
     public static final String URI = "ef130684-ac17-4118-ad36-8dea0babc7b2";
     public static final String DATA = "condition:notAuthorized";
     public static final String PRR = "100";
@@ -109,11 +112,33 @@ public class OpflexMessageTest {
             "      \"data\":  \"" + DATA + "\"" +
             "   }] }";
 
+    private static final String emptyMo = 
+            "{         \"name\": \"" + MO_NAME + "\"," +
+            "          \"properties\": [ {\"name\": \"" + PROP_NAME + "\", " +
+            "                             \"data\": \"" + PROP_DATA + "\" }]," +
+            "          \"children\": []," +
+            "          \"statistics\": []," +
+            "          \"from_relations\": []," +
+            "          \"to_relations\": []," +
+            "          \"faults\": []," +
+            "          \"health\": [] }";
+            
+    private static final String managedObject = 
+            "{ \"name\": \"" + MO_NAME + "\", " +
+            "  \"properties\": [ { \"name\": \"" + PROP_NAME + "\", " +
+            "                      \"data\": \"" + PROP_DATA + "\" }]," +                    
+            "  \"children\":   [ " + emptyMo + " ], " +
+            "  \"statistics\":   [ " + emptyMo + " ], " +
+            "  \"from_relations\":   [ " + emptyMo + " ], " +
+            "  \"to_relations\":   [ " + emptyMo + " ], " +
+            "  \"faults\":   [ " + emptyMo + " ], " +
+            "  \"health\":   [ " + emptyMo + " ]}";
+            
     private static final String opflexPolicyResponse =
             "{ \"id\":     \"" + ID_UUID + "\"," +
             "  \"error\":  {}," +
             "  \"result\": {" +
-            "      \"policy\": [ \"" + POLICY_NAME + "\"]," +
+            "      \"policy\": [ " + managedObject + "], " +
             "      \"prr\":  \"" + PRR + "\"" +
             "   }}";
 
@@ -122,7 +147,7 @@ public class OpflexMessageTest {
             "  \"method\": \"" + POLICY_REQUEST + "\"," +
             "  \"params\": [ {" +
             "      \"context\":  \"" + CONTEXT + "\"," +
-            "      \"subtree\":  [\"" + POLICY_NAME + "\"]," +
+            "      \"subtree\":  [" + managedObject + "]," +
             "      \"prr\":  \"" + PRR + "\"" +
             "   }] }";
 
@@ -222,22 +247,17 @@ public class OpflexMessageTest {
             "  \"result\": {} }";
 
     private static final String STATE_REQUEST = "report_state";
-    private static final String OBJECT = "ep101";
-    private static final String FAULT = "ep102";
-    private static final String EVENT = "infected";
-    private static final String STATISTICS = "rxPackets: 20";
-    private static final String HEALTH = ".98";
     private static final String opflexStateRequest =
             "{ \"id\":     \"" + ID_UUID + "\"," +
             "  \"method\": \"" + STATE_REQUEST + "\"," +
             "  \"params\": [ {" +
             "      \"subject\":    \"" + SUBJECT + "\"," +
             "      \"context\":  \"" + CONTEXT + "\"," +
-            "      \"object\":  \"" + OBJECT + "\"," +
-            "      \"fault\":  [\"" + FAULT + "\"]," +
-            "      \"event\":  [\"" + EVENT + "\"]," +
-            "      \"statistics\":  [\"" + STATISTICS + "\"]," +
-            "      \"health\":  [\"" + HEALTH + "\"]" +
+            "      \"object\":  " + managedObject + "," +
+            "      \"fault\":  [" + managedObject + "]," +
+            "      \"event\":  [" + managedObject + "]," +
+            "      \"statistics\":  [" + managedObject + "]," +
+            "      \"health\":  [" + managedObject + "]" +
             "   }] }";
 
 
@@ -324,7 +344,21 @@ public class OpflexMessageTest {
         PolicyResolutionResponse opflexResponse = (PolicyResolutionResponse)rpcMsg;
         assertTrue(opflexResponse.getId().equals(ID_UUID));
         assertTrue(opflexResponse.getResult()
-                .getPolicy().get(0).equals(POLICY_NAME));
+                .getPolicy().get(0).getProperties().get(0).getName().equals(PROP_NAME));
+        assertTrue(opflexResponse.getResult()
+                .getPolicy().get(0).getProperties().get(0).getData().equals(PROP_DATA));
+        assertTrue(opflexResponse.getResult()
+                .getPolicy().get(0).getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getResult()
+                .getPolicy().get(0).getFaults().get(0).getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getResult()
+                .getPolicy().get(0).getFrom_relations().get(0).getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getResult()
+                .getPolicy().get(0).getHealth().get(0).getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getResult()
+                .getPolicy().get(0).getStatistics().get(0).getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getResult()
+                .getPolicy().get(0).getTo_relations().get(0).getName().equals(MO_NAME));
         assertTrue(opflexResponse.getResult()
                 .getPrr() == Integer.parseInt(PRR));
     }
@@ -337,8 +371,22 @@ public class OpflexMessageTest {
         assertTrue(rpcMsg instanceof PolicyUpdateRequest);
         PolicyUpdateRequest opflexResponse = (PolicyUpdateRequest)rpcMsg;
         assertTrue(opflexResponse.getId().equals(ID_UUID));
-        assertTrue(opflexResponse.getParams()
-                .get(0).getSubtree().get(0).equals(POLICY_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getSubtree().get(0).getProperties().get(0).getName().equals(PROP_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getSubtree().get(0).getProperties().get(0).getData().equals(PROP_DATA));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getSubtree().get(0).getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getSubtree().get(0).getFaults().get(0).getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getSubtree().get(0).getFrom_relations().get(0).getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getSubtree().get(0).getHealth().get(0).getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getSubtree().get(0).getStatistics().get(0).getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getSubtree().get(0).getTo_relations().get(0).getName().equals(MO_NAME));
         assertTrue(opflexResponse.getParams()
                 .get(0).getPrr() == Integer.parseInt(PRR));
     }
@@ -351,7 +399,7 @@ public class OpflexMessageTest {
         assertTrue(rpcMsg instanceof PolicyUpdateResponse);
         PolicyUpdateResponse opflexResponse = (PolicyUpdateResponse)rpcMsg;
         assertTrue(opflexResponse.getId().equals(ID_UUID));
-        logger.warn("Result is {}", opflexResponse.getResult().toString());
+        
     }
 
     @Test
@@ -518,22 +566,107 @@ public class OpflexMessageTest {
         assertTrue(opflexResponse.getParams()
                 .get(0).getContext().equals(CONTEXT));
         assertTrue(opflexResponse.getParams()
-                .get(0).getObject().equals(OBJECT));
-        assertTrue(opflexResponse.getParams()
-                .get(0).getFault().get(0).equals(FAULT));
-        assertTrue(opflexResponse.getParams()
-                .get(0).getEvent().get(0).equals(EVENT));
-        assertTrue(opflexResponse.getParams()
-                .get(0).getStatistics().get(0).equals(STATISTICS));
-        assertTrue(opflexResponse.getParams()
-                .get(0).getHealth().get(0).equals(HEALTH));
+                .get(0).getObject().getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getObject().getProperties().get(0).getName().equals(PROP_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getObject().getProperties().get(0).getData().equals(PROP_DATA));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getObject().getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getObject().getFaults().get(0).getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getObject().getFrom_relations().get(0).getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getObject().getHealth().get(0).getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getObject().getStatistics().get(0).getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getObject().getTo_relations().get(0).getName().equals(MO_NAME));           
+        
+        assertTrue(opflexResponse.getParams()
+                .get(0).getFault().get(0).getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getFault().get(0).getProperties().get(0).getName().equals(PROP_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getFault().get(0).getProperties().get(0).getData().equals(PROP_DATA));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getFault().get(0).getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getFault().get(0).getFaults().get(0).getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getFault().get(0).getFrom_relations().get(0).getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getFault().get(0).getHealth().get(0).getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getFault().get(0).getStatistics().get(0).getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getFault().get(0).getTo_relations().get(0).getName().equals(MO_NAME));   
+
+        assertTrue(opflexResponse.getParams()
+                .get(0).getEvent().get(0).getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getEvent().get(0).getProperties().get(0).getName().equals(PROP_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getEvent().get(0).getProperties().get(0).getData().equals(PROP_DATA));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getEvent().get(0).getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getEvent().get(0).getFaults().get(0).getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getEvent().get(0).getFrom_relations().get(0).getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getEvent().get(0).getHealth().get(0).getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getEvent().get(0).getStatistics().get(0).getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getEvent().get(0).getTo_relations().get(0).getName().equals(MO_NAME));          
+        
+        
+        assertTrue(opflexResponse.getParams()
+                .get(0).getStatistics().get(0).getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getStatistics().get(0).getProperties().get(0).getName().equals(PROP_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getStatistics().get(0).getProperties().get(0).getData().equals(PROP_DATA));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getStatistics().get(0).getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getStatistics().get(0).getFaults().get(0).getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getStatistics().get(0).getFrom_relations().get(0).getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getStatistics().get(0).getHealth().get(0).getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getStatistics().get(0).getStatistics().get(0).getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getStatistics().get(0).getTo_relations().get(0).getName().equals(MO_NAME));           
+        
+        assertTrue(opflexResponse.getParams()
+                .get(0).getHealth().get(0).getName().equals(MO_NAME));        
+        assertTrue(opflexResponse.getParams().get(0)
+                .getHealth().get(0).getProperties().get(0).getName().equals(PROP_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getHealth().get(0).getProperties().get(0).getData().equals(PROP_DATA));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getHealth().get(0).getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getHealth().get(0).getFaults().get(0).getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getHealth().get(0).getFrom_relations().get(0).getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getHealth().get(0).getHealth().get(0).getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getHealth().get(0).getStatistics().get(0).getName().equals(MO_NAME));
+        assertTrue(opflexResponse.getParams().get(0)
+                .getHealth().get(0).getTo_relations().get(0).getName().equals(MO_NAME));   
     }
 
     @Test
     public void testStateResponse() throws Exception {
         ObjectMapper objectMapper = new ObjectMapper();
         RpcMessage rpcMsg = objectMapper.
-                readValue(opflexEpPolicyUpdateResponse, StateReportResponse.class);
+                readValue(opflexStateResponse, StateReportResponse.class);
         assertTrue(rpcMsg instanceof StateReportResponse);
         StateReportResponse opflexResponse = (StateReportResponse)rpcMsg;
         assertTrue(opflexResponse.getId().equals(ID_UUID));