0 Replies Latest reply on Feb 10, 2009 8:44 PM by rob tirserio

    Integration test and setValue

    rob tirserio Newbie

      I am trying to use setValue in an integration test to set a value of an injected object that comes from the selection in a drop down menu, but when I debug the test, the value is always null.


      Here is my component


      @Name("directoryHome")
      public class DirectoryHome extends EntityHome<Directory> {
          
          /* Persistence Accounting Fields */
          /** @see java.io.Serializable */
          private static final long serialVersionUID = -7944607543874301481L;
          
          /* DirectoryHome Fields */
          /** Unique identifier for Directory. */
          @RequestParameter 
          private Long directoryId;
          /** Directory to which this Directory should move all its contents to before being removed. */
          @In(required = false)
          @Out(required = false)
          private Directory directoryToMoveTo;
          /* Java/Seam Persistence API Method Overrides */
          /** @return Directory */
          @Override
          @Factory("directory")
          public Directory getInstance() {
              return super.getInstance();
          }
          /** @return list of Directory objects that the contents of a directory can be moved to before being removed. */
          @DataModel(value = "directories")
          public List<Directory> getDirectories() {
              return getEntityManager().createQuery("from Directory directory where directory.id != #{directory.id}").getResultList();
          }
          /**
           * @see org.jboss.seam.framework.Home.getId()
           * @return Id of Directory
           */
          @Override
          public Object getId() { 
              if (directoryId == null) {
                  return super.getId();
              } else {
                  return directoryId;
              }
          }
          /** 
           * Remove the directory after removing it from the repository.
           * @return Result String
           */
          @Override
          public String remove() {
              String result = "error";
              Directory directory = getInstance();
              if (directoryToMoveTo != null) {
                  for (Document d : getInstance().getDocuments()) {
                      d.setComments(d.getComments() + "\nMoved to " + directoryToMoveTo.getName() + " on " + new Date().toString());
                  }
                  directoryToMoveTo.addAllDocumentsFromDirectory(directory);
              }
              result = super.remove();
              return result;
          }
      



      and the test method


          @Test
          public void testRemoveWithCopyDirectory() throws Exception {
              login();
              new SmartFacesRequest("/directoryRemove.xhtml") {
                  @Override
                  protected void applyRequestValues() throws Exception {
                      super.applyRequestValues();
                      setParameter("directoryId", "1");
                  }
                  protected void updateModelValues() throws Exception {
                      super.updateModelValues();
                      DirectoryHome directoryHome = (DirectoryHome) getValue("#{directoryHome}");
                      assert directoryHome != null;
                      EntityManager em = (EntityManager) getValue("#{entityManager}");
                      Directory dir = em.find(Directory.class, 2L);
                      setValue("#{directoryToMoveTo}", dir);
                  }
                  @Override
                  protected void invokeApplication() throws Exception {
                      super.invokeApplication();
                      assert invokeMethod("#{directoryHome.remove}").equals("removed");
                  }
              }
              .run();
      


      and finally the xhtml


      <h:selectOneMenu id="directoryToMoveTo" value="#{directoryToMoveTo}">
         <s:selectItems var="_directory" value="#{directories}" label="#{_directory.name}" noSelectionLabel="None"/>
         <s:convertEntity />
      </h:selectOneMenu>
      



      any help is appreciated.