/** Test delete smart point from tag. */
  @Test
  public void testDeleteLightFromTag() {
    // Validation situation
    TagRequest tagRequest = new TagRequest(new UserContext(1));
    Tag tag = new Tag();
    TagResponse response = getTagBCF().deleteLightFromTag(tagRequest);
    assertFalse(response.isOperationSuccess());
    assertMessages(
        response,
        SENSUS_MLC_VALIDATOR_ID_REQUIRED,
        SENSUS_MLC_VALIDATOR_REQUIRED,
        SENSUS_MLC_VALIDATOR_ID_REQUIRED);

    // Success situation
    tagRequest = TestBaseUtil.createTagRequest();
    Light light = TestBaseUtil.createLight();
    List<Integer> lightIdsList = new ArrayList<Integer>();
    lightIdsList.add(1);
    tag.getLights().add(light);
    List<Tag> tagList = new ArrayList<Tag>();
    tagList.add(TestBaseUtil.createTag());
    tagRequest.setTags(tagList);
    tagRequest.setPaginationAllSelected(true);
    tagRequest.setSelectionPaginationIds(lightIdsList);
    response = getTagBCF().deleteLightFromTag(tagRequest);
    assertTrue(response.isOperationSuccess());

    // Exception situation
    resetMocksToTagArea();
    setSituation(getTagBCF(), SituationsEnum.EXCEPTION, ITagBCL.class, DELETE_LIGHT_FROM_TAG);
    response = getTagBCF().deleteLightFromTag(tagRequest);
    assertFalse(response.isOperationSuccess());
    assertMessages(response, DEFAULT_TAG_BCF_EXCEPTION_MSG);

    // Error situation
    resetMocksToTagArea();
    setSituation(getTagBCF(), SituationsEnum.ERROR, ITagBCL.class, DELETE_LIGHT_FROM_TAG);
    response = getTagBCF().deleteLightFromTag(tagRequest);
    assertFalse(response.isOperationSuccess());
    assertMessages(response, ERROR_CODE);

    // Error situation
    tagRequest = TestBaseUtil.createTagRequest();
    response = getTagBCF().deleteLightFromTag(tagRequest);
    assertFalse(response.isOperationSuccess());

    // Error situation
    tagRequest = TestBaseUtil.createTagRequest();
    tag = TestBaseUtil.createTag();
    tag.setId(null);
    lightIdsList = new ArrayList<Integer>();
    lightIdsList.add(1);
    tagRequest.setTag(tag);
    tagRequest.setPaginationAllSelected(true);
    tagRequest.setSelectionPaginationIds(lightIdsList);
    response = getTagBCF().deleteLightFromTag(tagRequest);
    assertFalse(response.isOperationSuccess());
  }
  /** Test insert tag. */
  @Test
  public void testInsertTag() {
    // Validation situation
    TagRequest tagRequest = new TagRequest();
    TagResponse response = getTagBCF().insertTag(tagRequest);
    assertFalse(response.isOperationSuccess());
    assertMessages(
        response,
        SENSUS_MLC_VALIDATOR_ID_REQUIRED,
        SENSUS_MLC_VALIDATOR_REQUIRED,
        SENSUS_MLC_VALIDATOR_ID_REQUIRED);

    // Success situation
    tagRequest = TestBaseUtil.createTagRequest();
    Tag tag = TestBaseUtil.createTag();
    tag.setLights(Arrays.asList(TestBaseUtil.createLight()));
    tagRequest.setTag(tag);
    response = getTagBCF().insertTag(tagRequest);
    assertTrue(response.isOperationSuccess());
    assertEquals(0, response.getMessageInfoList().size());

    // Error situation
    resetMocksToTagArea();
    setSituation(getTagBCF(), SituationsEnum.ERROR, ITagBCL.class);
    tagRequest = TestBaseUtil.createTagRequest();
    tag = TestBaseUtil.createTag();
    tag.setLights(Arrays.asList(TestBaseUtil.createLight()));
    tagRequest.setTag(tag);
    response = getTagBCF().insertTag(tagRequest);
    assertFalse(response.isOperationSuccess());
    assertMessages(response, ERROR_CODE);

    // Exception situation
    resetMocksToTagArea();
    setSituation(getTagBCF(), SituationsEnum.EXCEPTION, ITagBCL.class);
    tagRequest = TestBaseUtil.createTagRequest();
    tag = TestBaseUtil.createTag();
    tag.setLights(Arrays.asList(TestBaseUtil.createLight()));
    tagRequest.setTag(tag);
    response = getTagBCF().insertTag(tagRequest);
    assertFalse(response.isOperationSuccess());
    assertMessages(response, DEFAULT_TAG_BCF_EXCEPTION_MSG);

    // Error situation - Name length invalid
    tagRequest = TestBaseUtil.createTagRequest();
    tag = TestBaseUtil.createTag();
    tag.setName(StringUtils.repeat("n", ONE_HUNDRED_ONE));
    tagRequest.setTag(tag);
    response = getTagBCF().insertTag(tagRequest);
    assertFalse(response.isOperationSuccess());
    assertMessages(response, SENSUS_MLC_VALIDATOR_LENGTH_INVALID);
  }
  /** Test fetch tags by light. */
  @Test
  public void testFetchTagsByLight() {
    // Validation situation
    LightRequest lightRequest = new LightRequest();
    lightRequest.setUserContext(new UserContext(1));

    TagResponse response = getTagBCF().fetchTagsByLight(lightRequest);
    assertFalse(response.isOperationSuccess());
    assertMessages(response, SENSUS_MLC_VALIDATOR_REQUIRED);

    // Success situation
    lightRequest = setLightRequest();
    lightRequest.setUserContext(TestBaseUtil.createUserContext());
    LightCriteria lightCriteria = new LightCriteria();
    Light light = TestBaseUtil.createLight();
    lightCriteria.setLightIdList(Arrays.asList(light.getId()));
    lightRequest.setLightCriteria(lightCriteria);
    response = getTagBCF().fetchTagsByLight(lightRequest);
    assertTrue(response.isOperationSuccess());
    assertEquals(0, response.getMessageInfoList().size());

    // Error situation
    resetMocksToTagArea();
    setSituation(getTagBCF(), SituationsEnum.ERROR, ITagBCL.class, FETCH_TAGS_BY_LIGHT);
    lightRequest = setLightRequest();
    response = getTagBCF().fetchTagsByLight(lightRequest);
    assertFalse(response.isOperationSuccess());
    assertMessages(response, ERROR_CODE);

    // Error situation
    lightRequest = setLightRequest();
    response = getTagBCF().fetchTagsByLight(lightRequest);
    assertFalse(response.isOperationSuccess());

    // Exception situation
    resetMocksToTagArea();
    setSituation(getTagBCF(), SituationsEnum.EXCEPTION, ITagBCL.class, FETCH_TAGS_BY_LIGHT);
    lightRequest = setLightRequest();
    response = getTagBCF().fetchTagsByLight(lightRequest);
    assertFalse(response.isOperationSuccess());
    assertMessages(response, DEFAULT_TAG_BCF_EXCEPTION_MSG);
  }
  /** Test delete tag. */
  @Test
  public void testDeleteTag() {
    // Validation situation
    TagRequest tagRequest = new TagRequest(new UserContext(1));
    Tag tag = new Tag();
    tagRequest.setTag(tag);
    TagResponse response = getTagBCF().deleteTag(tagRequest);
    assertFalse(response.isOperationSuccess());
    assertMessages(
        response,
        SENSUS_MLC_VALIDATOR_ID_REQUIRED,
        SENSUS_MLC_VALIDATOR_REQUIRED,
        SENSUS_MLC_VALIDATOR_ID_REQUIRED);

    // Success situation
    tagRequest = TestBaseUtil.createTagRequest();
    tag = TestBaseUtil.createTag();
    tagRequest.setTag(tag);
    response = getTagBCF().deleteTag(tagRequest);
    assertTrue(response.isOperationSuccess());

    // Error situation
    resetMocksToTagArea();
    setSituation(getTagBCF(), SituationsEnum.ERROR, ITagBCL.class, DELETE_TAG);
    tagRequest = TestBaseUtil.createTagRequest();
    tag = TestBaseUtil.createTag();
    tagRequest.setTag(tag);
    response = getTagBCF().deleteTag(tagRequest);
    assertFalse(response.isOperationSuccess());
    assertMessages(response, ERROR_CODE);

    // Error situation
    tagRequest = TestBaseUtil.createTagRequest();
    response = getTagBCF().deleteTag(tagRequest);
    assertFalse(response.isOperationSuccess());

    // Exception situation
    resetMocksToTagArea();
    setSituation(getTagBCF(), SituationsEnum.EXCEPTION, ITagBCL.class, DELETE_TAG);
    tagRequest = TestBaseUtil.createTagRequest();
    tag = TestBaseUtil.createTag();
    tagRequest.setTag(tag);
    response = getTagBCF().deleteTag(tagRequest);
    assertFalse(response.isOperationSuccess());
    assertMessages(response, DEFAULT_TAG_BCF_EXCEPTION_MSG);
  }
  /** Test update auto group tag. */
  @Test
  public void testUpdateAutoGroupTag() {
    // Validation situation
    TagRequest tagRequest = new TagRequest(new UserContext(1));
    Tag tag = new Tag();
    tagRequest.setTag(tag);
    TagResponse response = getTagBCF().updateAutoGroupTag(tagRequest);
    assertFalse(response.isOperationSuccess());
    assertMessages(
        response,
        SENSUS_MLC_VALIDATOR_ID_REQUIRED,
        SENSUS_MLC_VALIDATOR_REQUIRED,
        SENSUS_MLC_VALIDATOR_ID_REQUIRED);

    // Success situation
    tagRequest = TestBaseUtil.createTagRequest();
    tag = TestBaseUtil.createTag();
    tag.setAutoGroup(true);
    tagRequest.setTag(tag);
    tagRequest.setIncludeLightsToGroup(true);
    response = getTagBCF().updateAutoGroupTag(tagRequest);
    assertTrue(response.isOperationSuccess());
    assertEquals(0, response.getMessageInfoList().size());

    // Error situation
    resetMocksToTagArea();
    setSituation(getTagBCF(), SituationsEnum.ERROR, ITagBCL.class, UPDATE_AUTO_GROUP_TAG);
    tagRequest = TestBaseUtil.createTagRequest();
    tag = TestBaseUtil.createTag();
    tag.setAutoGroup(true);
    tagRequest.setTag(tag);
    tagRequest.setIncludeLightsToGroup(true);
    response = getTagBCF().updateAutoGroupTag(tagRequest);
    assertFalse(response.isOperationSuccess());
    assertMessages(response, ERROR_CODE);

    // Error situation
    tagRequest = TestBaseUtil.createTagRequest();
    tag = TestBaseUtil.createTag();
    tag.setId(null);
    tagRequest.setTag(tag);
    tagRequest.setIncludeLightsToGroup(true);
    response = getTagBCF().updateAutoGroupTag(tagRequest);
    assertFalse(response.isOperationSuccess());

    // Error situation
    tagRequest = TestBaseUtil.createTagRequest();
    response = getTagBCF().updateAutoGroupTag(tagRequest);
    assertFalse(response.isOperationSuccess());

    // Exception situation
    resetMocksToTagArea();
    setSituation(getTagBCF(), SituationsEnum.EXCEPTION, ITagBCL.class, UPDATE_AUTO_GROUP_TAG);
    tagRequest = TestBaseUtil.createTagRequest();
    tag = TestBaseUtil.createTag();
    tag.setAutoGroup(true);
    tagRequest.setTag(tag);
    tagRequest.setIncludeLightsToGroup(true);
    response = getTagBCF().updateAutoGroupTag(tagRequest);
    assertFalse(response.isOperationSuccess());
    assertMessages(response, DEFAULT_TAG_BCF_EXCEPTION_MSG);
  }