/** 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 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);
  }