@Override
  public void initSelf(OrchidContext oc) throws OrchidException {
    callSuperInitSelf(oc);

    cssPath = lookupContentFile(FILES, CSS, oc);

    try {
      ContentPolicy policy = getContentPolicy();
      icon = getOContentIcon();
      icon.initContent((Policy) policy, getContentSession().getPolicyCMServer());
      addAndInitChild(oc, icon);

      videoPolicy = getBrightcoveVideoPolicy();

      name = videoPolicy.getName();
      name =
          (name == null || "".equals(name))
              ? videoPolicy.getContentId().getContentId().getContentIdString()
              : abbreviate(name, 30);

      thumbnail = videoPolicy.getImagePath();

    } catch (CMException e) {
      LOG.log(Level.WARNING, e.getMessage(), e);
    }
  }
  @Before
  public void before()
      throws OrchidException, IOException, CMException, BrightcoveException, ImageFormatException,
          ImageTooBigException, URISyntaxException {
    MockitoAnnotations.initMocks(this);

    when(contentSession.getMode()).thenReturn(2);
    when(contentSession.getTopWidget()).thenReturn(policyWidget);
    when(contentSession.findPolicyWidget(OBrightcoveSyncWidget.NAME)).thenReturn(name);
    when(contentSession.findPolicyWidget(OBrightcoveSyncWidget.SHORT_DESCRIPTION))
        .thenReturn(shortDescription);
    when(contentSession.findPolicyWidget(OBrightcoveSyncWidget.LONG_DESCIPTION))
        .thenReturn(longDescription);
    when(contentSession.findPolicyWidget(OBrightcoveSyncWidget.IMAGE_TYPE))
        .thenReturn(selectableSubFieldPolicyWidget);
    when(contentSession.getTopWidget()).thenReturn(policyWidget);
    when(name.getChildWidget()).thenReturn(nameWidget);
    when(shortDescription.getChildWidget()).thenReturn(shortDescriptionWidget);
    when(longDescription.getChildWidget()).thenReturn(longDescriptionWidget);
    when(nameWidget.getCompoundId()).thenReturn("name_id");
    when(shortDescriptionWidget.getCompoundId()).thenReturn("short_id");
    when(longDescriptionWidget.getCompoundId()).thenReturn("long_id");
    when(video.getName()).thenReturn("video name");
    when(video.getShortDescription()).thenReturn("video short description");
    when(video.getLongDescription()).thenReturn("video long description");
    when(video.getThumbnailUrl())
        .thenReturn(
            getClass().getClassLoader().getResource("small.jpg").toURI().toURL().toString());
    when(brightcoveService.findByVideoID(1)).thenReturn(video);
    when(policy.getId()).thenReturn("1");
    when(policy.getChildPolicy("categorization")).thenReturn(categorizationProvider);
    when(policy.getSubFieldPolicy()).thenReturn(selectableSubFieldPolicy);
    when(selectableSubFieldPolicy.getChildPolicy(BrightcoveVideoPolicy.IMAGE))
        .thenReturn(imageManagerPolicy);
    when(policyCMServer.getPolicy(BrightcoveConfigPolicy.CONTENT_ID)).thenReturn(configPolicy);

    doNothing().when(javaScript).render(oc);
    doNothing().when(syncButton).render(oc);

    target = spy(new OBrightcoveSyncWidget());
    doReturn(brightcoveService).when(target).getBrightcoveService();
    doReturn(policy).when(target).getPolicy();
    doReturn(javaScript).when(target).getOJavaScript();
    doReturn(syncButton).when(target).getOButton();
    doReturn(contentSession).when(target).getContentSession();
    target.initSelf(oc);
    target.localRender(oc);
  }
 @Test
 public void shouldNotSuccessPreviewVideoIfBrightcoveIdIsEmpty() throws OrchidException {
   when(policy.getId()).thenReturn("");
   PreviewEventListener preview = target.new PreviewEventListener();
   preview.processEvent(oc, oe);
   verify(target, times(1)).getString(eq("com.atex.plugins.brightcove.brightcove.id.required"));
 }
 protected void renderContentBody(Device device, OrchidContext oc)
     throws OrchidException, IOException {
   if (thumbnail != null) {
     device.println("<img src='" + thumbnail + "' class='brightcoveVideoImage'/>");
   }
   device.println(
       "<span class='lead'>" + abbreviate(videoPolicy.getShortDescription(), 200) + "</span>");
 }
 @Test
 public void shouldNotCallBrightcoveServiceIfBrightcoveIdIsEmpty()
     throws OrchidException, CMException, BrightcoveException {
   when(policy.getId()).thenReturn("");
   SyncEventListener sync = target.new SyncEventListener();
   sync.processEvent(oc, oe);
   verify(brightcoveService, never()).findByVideoID(anyLong());
 }