Package org.apache.wicket.util.file

Examples of org.apache.wicket.util.file.File


  public void testFileUploadCanBeValidated() throws IOException
  {
    final Set<IValidatable> validatedComponents = new HashSet<IValidatable>();

    final File tmpFile = writeTestFile(1);
    tmpFile.deleteOnExit();

    final IValidator testValidator = new IValidator()
    {
      private static final long serialVersionUID = 1L;

      public void validate(IValidatable validatable)
      {
        validatedComponents.add(validatable);
        assertEquals(ArrayList.class, validatable.getValue().getClass());
        List<FileUpload> uploads = (List<FileUpload>)validatable.getValue();
        FileUpload upload = uploads.get(0);
        assertEquals(tmpFile.getName(), upload.getClientFileName());
        assertEquals(new String(read(tmpFile)), new String(upload.getBytes()));
      }
    };
    final MockPageWithFormAndUploadField page = new MockPageWithFormAndUploadField();
    page.getForm().visitChildren(FileUploadField.class, new IVisitor<FileUploadField, Void>()
View Full Code Here


    assertEquals(validatedComponents.size(), 1);
  }

  private File writeTestFile(int numberOfowsToCreate) throws IOException
  {
    File tmp = new File(java.io.File.createTempFile(getClass().getName(), ".txt"));
    OutputStream os = new BufferedOutputStream(new FileOutputStream(tmp));
    for (int i = 0; i < numberOfowsToCreate; i++)
    {
      os.write("test test test test test\n".getBytes());
    }
View Full Code Here

    } else { // when the glossary is on
      Resource glossaryResource;
      if (davServer != null) {
        glossaryResource = new DavResource(davServer, getContentDir() + "/" + glossaryFileName);
      } else {
        glossaryResource = new FileResource(new File(getContentDir(), glossaryFileName));
      }
      final XmlDocument glossaryDoc = xmlService.loadXmlDocument("glossary", glossaryResource, new DtbookParser(), null);
     
      // Set up Glossary
      Databinder.ensureSession(new SessionUnit() {
        public Object run(Session sess) {
          glossary = GlossaryService.get().parseXmlGlossaryDocument(glossaryDoc);
          return null;
        }
      });
    }
       
    // Load student content files
    String fileList = appProperties.getProperty("isi.studentContentFiles", DEFAULT_STUDENT_CONTENT_FILE_NAMES).trim();
    studentContentFiles = fileList.split("\\s*,\\s*");   
    documentObservers.add(new XmlDocumentObserver(getSectionElement(), getPageElement())); // Use set so sub-classed applications can add to it as well
    for (String file : studentContentFiles) {
      Resource resource;
      if (davServer != null) {
        log.debug("attempting to load DavResource file = {}", getContentDir() + "/" + file);
        log.debug("loading the DavResource on the Server = {}", davServer);
        resource = new DavResource(davServer, getContentDir() + "/" + file);
      } else {
        log.debug("attempting to load Resource file = {}", getContentDir() + "/" + file);
        resource = new FileResource(new File(getContentDir(), file));
      }
      XmlDocument doc = xmlService.loadXmlDocument(file, resource, new DtbookParser(), documentObservers);
      studentContent.add(doc);
    }
   
    // Load email content files
    if (emailOn) {
      String emailFileName = EMAIL_FILE_NAME;         
      Resource emailResource;
      if (davServer != null) {
        emailResource = new DavResource(davServer, getContentDir() + "/" + emailFileName);
      } else {
        emailResource = new FileResource(new File(getContentDir(), emailFileName));
      }
      emailContent = xmlService.loadXmlDocument("email", emailResource, new DtbookParser(), null);         
    }
    log.debug("Finished loading ISI XML Files");
  }
View Full Code Here

    // Transformers
    xmlService.loadXSLTransformer("glossary", getGlossaryTransformationFile(), true);
    xmlService.loadXSLTransformer("toc", getTocTransformationFile(), true);
   
    // check for the student transformation file in the custom dir first then base dir
    File studentXslFile = new File(getCustomTransformationDir(), getStudentTransformationFile());
    if (!studentXslFile.exists())
      studentXslFile = new File(getTransformationDir(), getStudentTransformationFile());
   
    // For comparing responses, need to filter down to a single response area and invoke custom XSL
    TransformChain compareChain = new TransformChain(
        new FilterElements(),
        new XslTransformer(xmlService.findXslResource("compare-responses.xsl")),
View Full Code Here

    assertNotNull(domainObject);
    assertNull(domainObject.getText());


    FormTester formTester = tester.newFormTester("form");
    formTester.setFile("file", new File("pom.xml"), "text/xml");
    formTester.setValue("text", "Mock value");
    formTester.submit();


    assertNotNull(domainObject);
View Full Code Here

    assertNotNull(domainObject);
    assertNull(domainObject.getText());


    FormTester formTester = tester.newFormTester("form");
    formTester.setFile("file", new File(getBasedir() +
      "src/test/java/org/apache/wicket/util/tester/bg.jpg"), "image/jpeg");
    formTester.setValue("text", "Mock value");
    formTester.submit();

View Full Code Here

        tester.assertRenderedPage(DataAccessEditPage.class);
        tester.assertNoErrorMessage();

        tester.assertLabel("dataStoreForm:storeType", "Properties");
        tester.assertModelValue("dataStoreForm:dataStoreNamePanel:border:paramValue", "cite");
        String expectedPath = new File(getTestData().getDataDirectoryRoot(), "cite").getPath();
        tester.assertModelValue(
                "dataStoreForm:parametersPanel:parameters:0:parameterPanel:border:paramValue",
                expectedPath);
    }
View Full Code Here

        tester.assertModelValue("form:name", null);
    }
   
    public void testUpload() throws Exception {
        FormTester upload = tester.newFormTester("uploadForm");
        File styleFile = new File(new java.io.File(getClass().getResource("default_point.sld").toURI()));
        String sld = IOUtils.toString(new FileReader(styleFile));
       
        upload.setFile("filename", styleFile, "application/xml");
        upload.submit();
       
View Full Code Here

        tester.assertModelValue("form:editor", sld);
    }
   
    public void testMissingName() throws Exception {
        FormTester form = tester.newFormTester("form");
        File styleFile = new File(new java.io.File(getClass().getResource("default_point.sld").toURI()));
        String sld = IOUtils.toString(new FileReader(styleFile));
        form.setValue("form:sld:editor", sld);
        form.submit();
       
        tester.assertRenderedPage(StyleNewPage.class);
View Full Code Here

    assertNotNull(domainObject);
    assertNull(domainObject.getText());


    FormTester formTester = tester.newFormTester("form");
    formTester.setFile("file", new File("pom.xml"), "text/xml");
    formTester.setValue("text", "Mock value");
    formTester.submit();


    assertNotNull(domainObject);
View Full Code Here

TOP

Related Classes of org.apache.wicket.util.file.File

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.