private Sensor buildSensor(SensorType type) throws Exception {

    Element ele = null;

    switch (type) {
      case RANGE:
        ele = deployer.queryElementById(1008);
        break;

      case LEVEL:
        ele = deployer.queryElementById(1010);
        break;

      case SWITCH:
        ele = deployer.queryElementById(1001);
        break;

      case CUSTOM:
        ele = deployer.queryElementById(1009);
        break;

      default:
        break;
    }

    return sensorBuilder.build(ele);
  }
  /**
   * Setup the service dependencies of deployer and other required services.
   *
   * @throws Exception if setup fails
   */
  @Before
  public void setUp() throws Exception {
    AllTests.initServiceContext();

    URI deploymentURI = AllTests.getAbsoluteFixturePath().resolve("builder/sensor");

    CommandFactory cf = DeployerTest.createCommandFactory();
    sensorBuilder = new Version20SensorBuilder();
    cache = new StatusCache();

    deployer = DeployerTest.createDeployer(deploymentURI, cf, sensorBuilder, cache);

    ButtonBuilder bb = new ButtonBuilder();
    bb.setDeployer(deployer);
    bb.setCommandFactory(cf);

    Map<String, ComponentBuilder> cb = new HashMap<String, ComponentBuilder>();
    cb.put("button", bb);

    ComponentFactory cof = new ComponentFactory();
    cof.setComponentBuilders(cb);

    commandService = new ControlCommandServiceImpl(deployer, cof);

    deployer.softRestart();
  }
  @Override
  public String readFromCache(String unParsedSensorIDs) {
    if (deployer.isPaused()) {
      throw new ControllerXMLChangedException("The content of controller.xml had changed.");
    }

    Set<Integer> statusSensorIDs = parseStatusSensorIDsStrToSet(unParsedSensorIDs);
    Map<Integer, String> latestStatuses = statusCache.queryStatus(statusSensorIDs);

    StringBuffer sb = new StringBuffer();
    sb.append(Constants.STATUS_XML_HEADER);
    Set<Integer> sensorIDs = latestStatuses.keySet();

    for (Integer sensorID : sensorIDs) {
      sb.append("<")
          .append(Constants.STATUS_XML_STATUS_RESULT_ELEMENT_NAME)
          .append(" ")
          .append(Constants.STATUS_XML_STATUS_RESULT_ELEMENT_SENSOR_IDENTITY)
          .append("=\"")
          .append(sensorID)
          .append("\">");

      sb.append(latestStatuses.get(sensorID));
      sb.append("</");
      sb.append(Constants.STATUS_XML_STATUS_RESULT_ELEMENT_NAME + ">\n");
      sb.append("\n");
    }

    sb.append(Constants.STATUS_XML_TAIL);

    return sb.toString();
  }
  @Before
  public void setUp() throws Exception {
    URI deploymentURI = AllTests.getAbsoluteFixturePath().resolve("builder/slider");

    CommandFactory cf = DeployerTest.createCommandFactory();

    deployer = DeployerTest.createDeployer(deploymentURI, cf);
    deployer.startController();

    sliderBuilder = new SliderBuilder();
    sliderBuilder.setDeployer(deployer);
    sliderBuilder.setCommandFactory(cf);
  }
  private Sensor buildSensorWithID(int id) throws Exception {
    Element el = deployer.queryElementById(id);

    return sensorBuilder.build(el);
  }
 private Sensor buildSensor(int id) throws Exception {
   return sensorBuilder.build(deployer.queryElementById(id));
 }
  private Slider getSliderByID(String sliderID) throws Exception {
    Element controlElement = deployer.queryElementById(Integer.parseInt(sliderID));

    return (Slider) sliderBuilder.build(controlElement, "20");
  }