Added subscriber as root for the service chain
diff --git a/gui/ngXosViews/serviceTopology/spec/sample.test.js b/gui/ngXosViews/serviceTopology/spec/sample.test.js
index 4ffec78..8b490e7 100644
--- a/gui/ngXosViews/serviceTopology/spec/sample.test.js
+++ b/gui/ngXosViews/serviceTopology/spec/sample.test.js
@@ -1,37 +1,126 @@
 'use strict';
 
-describe('The User List', () => {
+describe('The Service Relation Service', () => {
   
-  var scope, element, isolatedScope, httpBackend;
+  var Service;
 
   beforeEach(module('xos.serviceTopology'));
   beforeEach(module('templates'));
 
-  beforeEach(inject(function($httpBackend, $compile, $rootScope){
-    
-    httpBackend = $httpBackend;
-    // Setting up mock request
-    $httpBackend.expectGET('/xos/users/?no_hyperlinks=1').respond([
-      {
-        email: 'teo@onlab.us',
-        firstname: 'Matteo',
-        lastname: 'Scandolo' 
-      }
-    ]);
-  
-    scope = $rootScope.$new();
-    element = angular.element('<users-list></users-list>');
-    $compile(element)(scope);
-    scope.$digest();
-    isolatedScope = element.isolateScope().vm;
+  // inject the cartService
+  beforeEach(inject(function (_ServiceRelation_) {
+    // The injector unwraps the underscores (_) from around the parameter names when matching
+    Service = _ServiceRelation_;
   }));
 
-  it('should load 1 users', () => {
-    httpBackend.flush();
-    expect(isolatedScope.users.length).toBe(1);
-    expect(isolatedScope.users[0].email).toEqual('teo@onlab.us');
-    expect(isolatedScope.users[0].firstname).toEqual('Matteo');
-    expect(isolatedScope.users[0].lastname).toEqual('Scandolo');
+  describe('given a service', () => {
+
+    const levelRelations = [
+      {
+        subscriber_service: 1
+      },
+      {
+        subscriber_service: 1
+      },
+      {
+        subscriber_service: 2
+      }
+    ];
+
+    it('should find all involved relations', () => {
+      expect(typeof Service.findLevelRelation).toBe('function');
+      let levelRelation = Service.findLevelRelation(levelRelations, 1);
+      expect(levelRelation.length).toBe(2);
+    });
   });
 
+  describe('given a set of relation', () => {
+
+    const levelRelations = [
+      {
+        provider_service: 1
+      },
+      {
+        provider_service: 2
+      }
+    ];
+
+    const services = [
+      {
+        id: 1
+      },
+      {
+        id: 2
+      },
+      {
+        id: 3
+      }
+    ];
+
+    it('should find all the provider service', () => {
+      expect(typeof Service.findLevelServices).toBe('function');
+      let levelServices = Service.findLevelServices(levelRelations, services);
+      expect(levelServices.length).toBe(2);
+    });
+  });
+
+  describe('given a list of services and a list of relations', () => {
+
+    const services = [
+      {
+        id: 1,
+        humanReadableName: 'service-1'
+      },
+      {
+        id: 2,
+        humanReadableName: 'service-2'
+      },
+      {
+        id: 3,
+        humanReadableName: 'service-3'
+      },
+      {
+        id: 4,
+        humanReadableName: 'service-4'
+      }
+    ];
+
+    const relations = [
+      {
+        provider_service: 2,
+        subscriber_service: 1,
+      },
+      {
+        provider_service: 3,
+        subscriber_service: 2
+      },
+      {
+        provider_service: 4,
+        subscriber_service: 1
+      },
+      {
+        subscriber_root: 1,
+        provider_service: 1
+      }
+    ];
+
+    it('should return a tree ordered by relations', () => {
+      let tree = Service.buildServiceTree(services, relations);
+
+      expect(tree.name).toBe('fakeSubs');
+      expect(tree.parent).toBeNull();
+      expect(tree.children.length).toBe(1);
+
+      expect(tree.children[0].name).toBe('service-1');
+      expect(tree.children[0].parent).toBeNull();
+      expect(tree.children[0].children.length).toBe(2);
+
+      expect(tree.children[0].children[0].name).toBe('service-2');
+      expect(tree.children[0].children[0].children[0].name).toBe('service-3');
+
+      expect(tree.children[0].children[1].name).toBe('service-4');
+    });
+  });
+
+
 });
\ No newline at end of file
diff --git a/gui/ngXosViews/serviceTopology/src/js/services.js b/gui/ngXosViews/serviceTopology/src/js/services.js
index a39a1a6..d6d2fa8 100644
--- a/gui/ngXosViews/serviceTopology/src/js/services.js
+++ b/gui/ngXosViews/serviceTopology/src/js/services.js
@@ -14,6 +14,9 @@
   .service('Instances', function($resource){
     return $resource('/xos/instances', {id: '@id'});
   })
+  .service('Subscribers', function($resource){
+    return $resource('/xos/subscribers', {id: '@id'});
+  })
   .service('ServiceRelation', function($q, _, lodash, Services, Tenant){
 
     // find all the relation defined for a given root
@@ -35,8 +38,6 @@
 
     const buildLevel = (tenants, services, rootService, parentName = null) => {
 
-      console.log(rootService);
-
       const tree = {
         name: rootService.humanReadableName,
         parent: parentName,
@@ -64,20 +65,26 @@
       return tree;
     };
 
-    const buildServiceTree = (services, tenants) => {
+    const buildServiceTree = (services, tenants, subscriber = {id:1, name: 'fakeSubs'}) => {
 
       // find the root service
       // it is the one attached to subsriber_root
       // as now we have only one root so this can work
-      const rootServiceId = lodash.find(tenants, {subscriber_root: 1}).provider_service;
+      const rootServiceId = lodash.find(tenants, {subscriber_root: subscriber.id}).provider_service;
       const rootService = lodash.find(services, {id: rootServiceId});
 
       const serviceTree = buildLevel(tenants, services, rootService);
 
-      return serviceTree;
+      return {
+        name: subscriber.name,
+        parent: null,
+        children: [serviceTree]
+      };
+
+      //return serviceTree;
     };
 
-    this.get = () => {
+    const get = (subscriber) => {
       var deferred = $q.defer();
       var services, tenants;
       Services.query().$promise
@@ -87,7 +94,7 @@
       })
       .then((res) => {
         tenants = res;
-        deferred.resolve(buildServiceTree(services, tenants));
+        deferred.resolve(buildServiceTree(services, tenants, subscriber));
       })
       .catch((e) => {
         throw new Error(e);
@@ -95,6 +102,12 @@
 
       return deferred.promise;
     }
+
+    this.get = get;
+    this.buildLevel = buildLevel;
+    this.buildServiceTree = buildServiceTree;
+    this.findLevelRelation = findLevelRelation;
+    this.findLevelServices = findLevelServices;
   });
 
 }());
\ No newline at end of file
diff --git a/gui/ngXosViews/serviceTopology/src/js/topologyCanvas.js b/gui/ngXosViews/serviceTopology/src/js/topologyCanvas.js
index 0df7bd6..a333adf 100644
--- a/gui/ngXosViews/serviceTopology/src/js/topologyCanvas.js
+++ b/gui/ngXosViews/serviceTopology/src/js/topologyCanvas.js
@@ -9,7 +9,7 @@
       bindToController: true,
       controllerAs: 'vm',
       templateUrl: 'templates/topology_canvas.tpl.html',
-      controller: function($element, $window, d3, serviceTopologyConfig, ServiceRelation, Slice, Instances){
+      controller: function($element, $window, d3, serviceTopologyConfig, ServiceRelation, Slice, Instances, Subscribers){
 
         this.instances = [];
         this.slices = [];
@@ -200,6 +200,10 @@
             .duration(duration)
             .attr('r', 30);
 
+          if(!d.service){
+            return;
+          }
+
           _this.selectedService = {
             id: d.id,
             name: d.name
@@ -248,7 +252,11 @@
           })
         };
 
-        ServiceRelation.get()
+        Subscribers.query().$promise
+        .then((subscribers) => {
+          this.subscribers = subscribers;
+          return ServiceRelation.get(subscribers[0])
+        })
         .then((tree) => {
           draw(tree);
         });
diff --git a/gui/ngXosViews/serviceTopology/src/templates/users-list.tpl.html b/gui/ngXosViews/serviceTopology/src/templates/users-list.tpl.html
deleted file mode 100644
index 2983ad0..0000000
--- a/gui/ngXosViews/serviceTopology/src/templates/users-list.tpl.html
+++ /dev/null
@@ -1,14 +0,0 @@
-<div class="row">
-  <h1>Users List</h1>
-  <p>This is only an example view.</p>
-</div>
-<div class="row">
-  <div class="span4">Email</div>
-  <div class="span4">First Name</div>
-  <div class="span4">Last Name</div>
-</div>  
-<div class="row" ng-repeat="user in vm.users">
-  <div class="span4">{{user.email}}</div>
-  <div class="span4">{{user.firstname}}</div>
-  <div class="span4">{{user.lastname}}</div>
-</div>  
\ No newline at end of file