public void testNewBeansXMLWizard() throws CoreException {
    NewBeansXMLWizardContext context = new NewBeansXMLWizardContext();
    context.init("org.jboss.tools.cdi.ui.wizard.NewBeansXMLCreationWizard");

    try {

      WizardNewFileCreationPage page =
          (WizardNewFileCreationPage) context.wizard.getPage("newFilePage1");
      String s = page.getFileName();
      assertEquals("beans.xml", s);
      assertFalse(context.wizard.canFinish());
      page.setFileName("beans2.xml");
      assertTrue(context.wizard.canFinish());
      String c = page.getContainerFullPath().toString();
      assertEquals("/tck/WebContent/WEB-INF", c);

      context.wizard.performFinish();

      IFile f =
          context.tck.getParent().getFile(page.getContainerFullPath().append(page.getFileName()));
      assertTrue(f.exists());

      String text = FileUtil.readStream(f.getContents());
      assertTrue(text.indexOf("http://java.sun.com/xml/ns/javaee") > 0);

    } finally {
      context.close();
    }
  }
Ejemplo n.º 2
0
 void assertTextSourceReference(ITextSourceReference ref, String expectedContent) {
   try {
     String text = FileUtil.readStream((IFile) ref.getResource());
     String content =
         text.substring(ref.getStartPosition(), ref.getStartPosition() + ref.getLength());
     assertEquals(expectedContent, content);
   } catch (CoreException e) {
     fail(e.getMessage());
   }
 }
    public String getNewTypeContent() {
      IType type = findType();

      IFile file = (IFile) type.getResource();
      assertNotNull(file);
      String text = null;
      try {
        text = FileUtil.readStream(file.getContents());
      } catch (CoreException e) {
        JUnitUtils.fail("Cannot read from " + file, e);
      }
      return text;
    }
    public String getNewTypeContent() {
      IType type = null;
      try {
        String tn = typeName;
        int q = tn.indexOf("<");
        if (q >= 0) tn = tn.substring(0, q);
        type = jp.findType(packName + "." + tn);
      } catch (JavaModelException e) {
        JUnitUtils.fail("Cannot find type " + typeName, e);
      }

      IFile file = (IFile) type.getResource();
      assertNotNull(file);
      String text = null;
      try {
        text = FileUtil.readStream(file.getContents());
      } catch (CoreException e) {
        JUnitUtils.fail("Cannot read from " + file, e);
      }
      return text;
    }
  public void testNewBeansXMLWizard() throws CoreException {
    NewBeansXMLWizardContext context = new NewBeansXMLWizardContext();
    context.init(NewJobXMLCreationWizard.WIZARD_ID);

    try {

      WizardNewFileCreationPage page =
          (WizardNewFileCreationPage) context.wizard.getPage(NewJobXMLCreationWizard.PAGE_NAME);
      String s = page.getFileName();
      assertEquals("job.xml", s);
      assertFalse(context.wizard.canFinish());
      page.setFileName("job222.xml");
      assertTrue(context.wizard.canFinish());
      String c = page.getContainerFullPath().toString();
      assertEquals("/BatchTestProject/src/META-INF/batch-jobs", c);

      assertEquals("1.0", context.wizard.getVersion());

      context.wizard.setID("myNewJob");

      context.wizard.performFinish();

      IFile f =
          context
              .project
              .getParent()
              .getFile(page.getContainerFullPath().append(page.getFileName()));
      assertTrue(f.exists());

      String text = FileUtil.readStream(f.getContents());
      assertTrue(text.indexOf("http://xmlns.jcp.org/xml/ns/javaee") > 0);
      assertTrue(text.indexOf("id=\"myNewJob\"") > 0);

    } finally {
      context.close();
    }
  }