@Test
 public void testHandleEmprofMissingMedia() throws TransitionException {
   Assert.assertEquals(
       "Expecting 3 media found in MediaState table before test",
       3,
       mediaStateManager.findMediaStateByAdStateID((long) 1).size());
   String xmlString =
       getStringFromFile.retrieveStringFromFile("emprof/testFiles/testMedia.xml", "ISO-8859-1");
   XmlBeanDriverIniValue iniValue = new XmlBeanDriverIniValue();
   iniValue.setFormat(CustomerFormat.EMPROF);
   iniValue.setXml(xmlString);
   iniValue.setXmlFileLocation(transitionProperties.getFtpPath() + "/emprof/emprof/testMedia.xml");
   iniValue.setIncomingTime(new DateTime().getMillis());
   AMediaHandlerDriver mediaHandler = TransitionDriverManager.getMediaHandler(iniValue);
   boolean result = mediaHandler.run();
   List<MediaStateModel> mediaStates =
       mediaStateManager.findMediaStateByClientIdClientRef(21912, "2011068");
   for (MediaStateModel media : mediaStates) {
     log.debug(media.toString());
   }
   log.debug("result = " + result);
   List<MediaStateModel> mediaStateModelList =
       mediaStateManager.findMediaStateByAdStateID((long) 1);
   Assert.assertEquals(
       "Expecting 19 media saved into MediaState table...", 3, mediaStateModelList.size());
   Assert.assertEquals(
       "Expecting 19 media found in MediaState table...",
       3,
       mediaStateManager.findMediaStateByAdStateID((long) 1).size());
 }
  @Before
  public void initialData() throws Exception {
    initialTestDatabaseCreator.dropDatabaseForJunit().checkDatabase();
    // save fileState
    fileStateModel = new FileStateModel();
    fileStateModel.setClientName("emprofMediaHandleTest");
    fileStateModel.setCustomerFormat("emprof");
    fileStateModel.setFileName("502833__49963125_urlescaped_49963171.xml.xml");
    fileStateModel.setFileSize(1L);
    // new column
    fileStateModel.setFileType(FileType.XML);
    fileStateModel.setFilePath("/a/b/c/d");
    fileStateModel.setParentFileState(null);
    fileStateModel = fileStateManager.save(fileStateModel);
    // save adstate
    adStateModel = new AdStateModel();
    adStateModel.setFileStateModel(fileStateModel);
    adStateModel.setZadObjectId(1);
    adStateModel.setzClientId(21912);
    adStateModel.setAdExternalRef("2011068");
    adStateModel = adStateManager.save(adStateModel);

    // save mediaStateModel
    mediaStateModel = new MediaStateModel();
    mediaStateModel.setAdStateModel(adStateModel);
    mediaStateModel.setContentType(MediaStateContentType.IMAGE);
    mediaStateModel.setMd5hash("730A1E3FEE8ACA06F14A4D9B1D9C0241");
    mediaStateModel.setSequenceNum(1);
    mediaStateModel.setTitle("Front Moslingsvei 44");
    mediaStateModel.setMediaStatus(MediaStatus.PRODUCTION);
    mediaStateModel.setProdref("73/0A/730A1E3FEE8ACA06F14A4D9B1D9C0241");
    // Media is not used:
    mediaStateModel.setExtref(
        "http://att.emprof.no/images/Megler-Forum/Megler%20Forum/Pictures/1024/20110681.JPG");
    mediaStateModel = mediaStateManager.save(mediaStateModel);

    mediaStateModel = new MediaStateModel();
    mediaStateModel.setAdStateModel(adStateModel);
    mediaStateModel.setContentType(MediaStateContentType.IMAGE);
    mediaStateModel.setMd5hash("md5hash1");
    mediaStateModel.setSequenceNum(99);
    mediaStateModel.setTitle("title2");
    mediaStateModel.setMediaStatus(MediaStatus.MISSING);
    mediaStateModel.setProdref("prodef");
    mediaStateModel.setExtref("pic2.jpg");
    mediaStateModel = mediaStateManager.save(mediaStateModel);

    mediaStateModel = new MediaStateModel();
    mediaStateModel.setAdStateModel(adStateModel);
    mediaStateModel.setContentType(MediaStateContentType.IMAGE);
    mediaStateModel.setMd5hash("md5hash1");
    mediaStateModel.setSequenceNum(99);
    mediaStateModel.setTitle("title3");
    mediaStateModel.setMediaStatus(MediaStatus.MISSING);
    mediaStateModel.setProdref("prodef");
    mediaStateModel.setExtref("pic3.jpg");
    mediaStateModel = mediaStateManager.save(mediaStateModel);
  }
  @Override
  public void retrieveMediaStateList() {
    log.debug("********************");

    AdStateModel adStateModel = getAdStateModel();
    if (adStateModel != null) {
      log.debug("************* " + adStateModel.getId());
    } else {
      log.debug("************* adstate model is null");
    }

    BildeDocument.Bilde[] bildeArray = eneiendom.getBilder().getBildeArray();
    for (BildeDocument.Bilde bilde : bildeArray) {
      MediaStateModel mediaStateModel = new MediaStateModel();
      mediaStateModel.setMediaStatus(MediaStatus.MISSING);
      mediaStateModel.setContentType(MediaStateContentType.IMAGE);
      mediaStateModel.setSequenceNum(bilde.getNr().intValue());
      mediaStateModel.setAdStateModel(adStateModel);

      FeltDocument.Felt externalRef =
          extractByNavnFromFields("urloriginalbilde", bilde.getFeltArray());
      if (externalRef != null) {
        log.debug("externalRef ###############" + externalRef.getStringValue().trim());
        mediaStateModel.setMediaFileName(
            externalRef
                .getStringValue()
                .trim()
                .substring(externalRef.getStringValue().trim().lastIndexOf('\\') + 1));
        mediaStateModel.setExtref(externalRef.getStringValue());
      } else {
        mediaStateModel.setExtref("Not Found");
      }
      getMediaStateModelList().add(mediaStateModel);
      log.debug("MediaStateModel Added :: " + mediaStateModel.toString());
    }

    DokumentDocument.Dokument[] dokumentArray = eneiendom.getDokumenter().getDokumentArray();
    for (DokumentDocument.Dokument dokument : dokumentArray) {
      MediaStateModel mediaStateModel = new MediaStateModel();
      mediaStateModel.setMediaStatus(MediaStatus.MISSING);
      mediaStateModel.setContentType(MediaStateContentType.PDF);
      mediaStateModel.setSequenceNum(dokument.getNr().intValue());
      mediaStateModel.setAdStateModel(adStateModel);

      FeltDocument.Felt pdfFileName = extractByNavnFromFields("navn", dokument.getFeltArray());
      FeltDocument.Felt pdfFileUrl =
          extractByNavnFromFields("urldokument", dokument.getFeltArray());
      if (pdfFileName != null && pdfFileUrl != null) {
        log.debug("PDF File Name ===== > " + pdfFileName.getStringValue());
        log.debug("PDF URL ====> " + pdfFileUrl.getStringValue());
        mediaStateModel.setMediaFileName(pdfFileName.getStringValue() + ".pdf");
        mediaStateModel.setExtref(pdfFileUrl.getStringValue());
      } else {
        mediaStateModel.setMediaFileName("NOT FOUND");
        mediaStateModel.setExtref("NOT FOUND");
      }

      getMediaStateModelList().add(mediaStateModel);
      log.debug("MediaStateModel Added :: " + mediaStateModel.toString());
    }

    if (getMediaStateModelList() != null && getMediaStateModelList().size() > 0) {
      log.debug("Found " + getMediaStateModelList().size() + " media in the ad");
    }
  }