private VCPENetworkModel createEmptyModel(Resource resource) {
   VCPENetworkModel model = new VCPENetworkModel();
   model.setVcpeNetworkId(resource.getResourceIdentifier().getId());
   model.setVcpeNetworkName(resource.getResourceDescriptor().getInformation().getName());
   model.setCreated(false);
   return model;
 }
 @Override
 public void resetModel(Resource resource) throws ResourceException {
   resource.setModel(new ComputerSystem());
   ((ComputerSystem) resource.getModel())
       .setName(resource.getResourceDescriptor().getInformation().getName());
   if (isALogicalRouter(resource))
     ((ComputerSystem) resource.getModel())
         .setElementName(resource.getResourceDescriptor().getInformation().getName());
 }
  @Override
  public void revertBootstrap(Resource resource) throws ResourceException {
    // persist model into descriptor
    storeModelIntoDescriptor(
        (VCPENetworkModel) resource.getModel(),
        (VCPENetworkDescriptor) resource.getResourceDescriptor());

    // reset the model
    resetModel(resource);
  }
  @Override
  public void bootstrap(Resource resource) throws ResourceException {

    VCPENetworkModel model = createEmptyModel(resource);

    if (((VCPENetworkDescriptor) resource.getResourceDescriptor()).getvCPEModel() != null) {
      // load model from the one persisted in the descriptor
      model = loadModelFromDescriptor((VCPENetworkDescriptor) resource.getResourceDescriptor());
    }
    resource.setModel(model);
  }
  @Override
  public void bootstrap(Resource resource) throws ResourceException {
    log.info("Loading bootstrap to start resource...");
    oldModel = resource.getModel();
    resetModel(resource);

    /* start its capabilities */
    for (ICapability capab : resource.getCapabilities()) {
      /* abstract capabilities have to be initialized */
      log.debug("Found a capability in the resource.");
      /* abstract capabilities have to be initialized */
      if (capab instanceof AbstractCapability) {
        log.debug("Executing capabilities startup...");
        ((AbstractCapability) capab).sendRefreshActions();
      }
    }

    IQueueManagerCapability queueCapab =
        (IQueueManagerCapability) resource.getCapabilityByInterface(IQueueManagerCapability.class);
    QueueResponse response;
    try {
      response = queueCapab.execute();
      if (!response.isOk()) {
        // TODO IMPROVE ERROR REPORTING
        throw new ResourceException(
            "Error during capabilities startup. Failed to execute startUp actions.");
      }
    } catch (ProtocolException e) {
      throw new ResourceException(
          "Error during capabilities startup. Failed to execute startUp actions.", e);
    } catch (ActionException e) {
      throw new ResourceException(
          "Error during capabilities startup. Failed to execute startUp actions.", e);
    } catch (CapabilityException e) {
      throw new ResourceException(
          "Error during capabilities startup. Failed to execute startUp actions.", e);
    }

    if (resource.getProfile() != null) {
      log.debug("Executing initModel from profile...");
      resource.getProfile().initModel(resource.getModel());
    }

    if (ModelHelper.getInterfaces(((ComputerSystem) resource.getModel())).isEmpty()) {
      log.warn("Router has no interfaces");
    }

    // FIXME This should be part of refresh action
    initVirtualResources(resource);
  }
  /** tests ConnectionsCapability.getActionSet().getStartupRefreshAction() != null */
  @Test
  public void getStartUpRefreshActionTest() throws Exception {

    ((Resource) mockResource)
        .setResourceDescriptor(ResourceHelper.newResourceDescriptorProteus("roadm"));

    // Test elements not null
    log.info("Checking connections factory");
    Assert.assertNotNull(connectionFactory);
    log.info("Checking capability descriptor");
    Assert.assertNotNull(
        mockResource.getResourceDescriptor().getCapabilityDescriptor("connections"));
    log.info("Creating connection capability");
    connectionsCapability = (AbstractCapability) connectionFactory.create(mockResource);
    Assert.assertNotNull(connectionsCapability);
    connectionsCapability.initialize();

    Assert.assertFalse(connectionsCapability.getActionSet().getRefreshActionName().isEmpty());
    startupActionNames = connectionsCapability.getActionSet().getRefreshActionName();
  }
 @Override
 public void resetModel(Resource resource) throws ResourceException {
   resource.setModel(createEmptyModel(resource));
 }
 @Override
 public void revertBootstrap(Resource resource) throws ResourceException {
   resource.setModel(oldModel);
 }
  @Test
  public void MakeRemoveConnectionsResourceTest() throws Exception {

    ResourceDescriptor resourceDescriptor = ResourceHelper.newResourceDescriptorProteus("roadm");

    /* create resource */
    Resource resource = (Resource) repository.createResource(resourceDescriptor);

    Assert.assertNotNull(resource.getResourceIdentifier());
    Assert.assertNotNull(resource.getResourceDescriptor());
    Assert.assertTrue(resource.getCapabilities().isEmpty());
    Assert.assertNull(resource.getModel());
    Assert.assertNull(resource.getProfile());

    Assert.assertFalse(repository.listResources().isEmpty());

    // add protocol for resource
    createProtocolForResource(resource.getResourceIdentifier().getId());

    /* start resource */
    repository.startResource(resource.getResourceIdentifier().getId());
    Assert.assertFalse(resource.getCapabilities().isEmpty());
    Assert.assertNotNull(resource.getModel());
    // Assert.assertNotNull(resource.getProfile());

    IConnectionsCapability connections =
        (IConnectionsCapability) resource.getCapabilityByInterface(IConnectionsCapability.class);
    if (connections == null) Assert.fail("Capability not found");
    IQueueManagerCapability queueCapability =
        (IQueueManagerCapability) resource.getCapabilityByInterface(IQueueManagerCapability.class);
    if (queueCapability == null) Assert.fail("Capability not found");

    /* checking model */
    // TODO CHECK NEW MODEL CONFIG

    /* refresh connection */
    // Response resp = (Response) connections.sendMessage(ActionConstants.REFRESHCONNECTIONS, null);
    // List<ActionResponse> responses = (List<ActionResponse>)
    // queueCapability.sendMessage(QueueManagerConstants.EXECUTE, null);
    //
    // Assert.assertTrue(responses.size() == 2);
    // ActionResponse actionResponse = responses.get(0);
    // Assert.assertEquals(ActionConstants.REFRESHCONNECTIONS, actionResponse.getActionID());
    // for (Response response : actionResponse.getResponses()) {
    // Assert.assertTrue(response.getStatus() == Response.Status.OK);
    // }
    //
    // List<IAction> queue = (List<IAction>)
    // queueCapability.sendMessage(QueueManagerConstants.GETQUEUE, null);
    // Assert.assertTrue(queue.size() == 0);

    OpticalSwitchFactory opticalSwitchFactory = new OpticalSwitchFactory();
    resource.setModel(opticalSwitchFactory.newPedrosaProteusOpticalSwitch());

    /* make connection */
    FiberConnection connectionRequest =
        newMakeConnectionParams((ProteusOpticalSwitch) resource.getModel());
    connections.makeConnection(connectionRequest);
    QueueResponse queueResponse = queueCapability.execute();

    Assert.assertTrue(queueResponse.isOk());

    boolean foundAndOk = false;
    for (ActionResponse response : queueResponse.getResponses()) {
      if (response.getActionID().equals(ActionConstants.MAKECONNECTION)) {
        if (response.getStatus() == STATUS.OK) {
          foundAndOk = true;
          for (Response subresponse : response.getResponses()) {
            Assert.assertTrue(subresponse.getStatus() == Response.Status.OK);
          }
        }
      }
    }
    Assert.assertTrue(foundAndOk);

    List<IAction> queue = (List<IAction>) queueCapability.getActions();
    Assert.assertTrue(queue.size() == 0);

    /* checking model */
    Assert.assertNotNull(
        getFiberConnection(connectionRequest, (ProteusOpticalSwitch) resource.getModel()));
    // checking for model intern details is in action tests

    /* remove connection */
    connections.removeConnection(connectionRequest);
    queueResponse = (QueueResponse) queueCapability.execute();

    Assert.assertTrue(queueResponse.isOk());

    foundAndOk = false;
    for (ActionResponse response : queueResponse.getResponses()) {
      if (response.getActionID().equals(ActionConstants.REMOVECONNECTION)) {
        if (response.getStatus() == STATUS.OK) {
          foundAndOk = true;
          for (Response subresponse : response.getResponses()) {
            Assert.assertTrue(subresponse.getStatus() == Response.Status.OK);
          }
        }
      }
    }
    Assert.assertTrue(foundAndOk);

    queue = (List<IAction>) queueCapability.getActions();
    Assert.assertTrue(queue.size() == 0);

    /* checking model */
    Assert.assertNull(
        getFiberConnection(connectionRequest, (ProteusOpticalSwitch) resource.getModel()));

    /* stop resource */
    repository.stopResource(resource.getResourceIdentifier().getId());

    Assert.assertNotNull(resource.getResourceIdentifier());
    Assert.assertNotNull(resource.getResourceDescriptor());
    Assert.assertTrue(resource.getCapabilities().isEmpty());
    Assert.assertNull(resource.getModel());
    // Assert.assertNull(resource.getProfile());
    Assert.assertFalse(repository.listResources().isEmpty());

    /* remove resource */

    createProtocolForResource(resource.getResourceIdentifier().getId());
    repository.removeResource(resource.getResourceIdentifier().getId());

    Assert.assertTrue(resource.getCapabilities().isEmpty());
    Assert.assertNull(resource.getModel());
    Assert.assertNull(resource.getProfile());
    // Assert.assertTrue(repository.listResources().isEmpty());
  }
  @Test
  public void StartAndStopResource() throws Exception {

    ResourceDescriptor resourceDescriptor = ResourceHelper.newResourceDescriptorProteus("roadm");

    /* create resource */
    Resource resource = (Resource) repository.createResource(resourceDescriptor);

    Assert.assertNotNull(resource.getResourceIdentifier());
    Assert.assertNotNull(resource.getResourceDescriptor());
    Assert.assertTrue(resource.getCapabilities().isEmpty());
    Assert.assertNull(resource.getModel());
    Assert.assertNull(resource.getProfile());

    Assert.assertFalse(repository.listResources().isEmpty());

    createProtocolForResource(resource.getResourceIdentifier().getId());

    /* start resource */
    repository.startResource(resource.getResourceIdentifier().getId());
    Assert.assertFalse(resource.getCapabilities().isEmpty());
    Assert.assertNotNull(resource.getModel());
    // Assert.assertNotNull(resource.getProfile());

    /* stop resource */
    repository.stopResource(resource.getResourceIdentifier().getId());

    Assert.assertNotNull(resource.getResourceIdentifier());
    Assert.assertNotNull(resource.getResourceDescriptor());
    Assert.assertTrue(resource.getCapabilities().isEmpty());
    Assert.assertNull(resource.getModel());
    // Assert.assertNull(resource.getProfile());
    Assert.assertFalse(repository.listResources().isEmpty());

    /* remove resource */

    repository.removeResource(resource.getResourceIdentifier().getId());

    Assert.assertTrue(resource.getCapabilities().isEmpty());
    Assert.assertNull(resource.getModel());
    Assert.assertNull(resource.getProfile());
    // Assert.assertTrue(repository.listResources().isEmpty());
  }