public void testNewDecoratorWizard() {
    WizardContext context = new WizardContext();
    context.init(
        "org.jboss.tools.cdi.ui.wizard.NewDecoratorCreationWizard", PACK_NAME, DECORATOR_NAME);

    ICDIProject cdi = CDICorePlugin.getCDIProject(context.tck, true);

    try {
      NewDecoratorWizardPage page = (NewDecoratorWizardPage) context.page;

      List<String> interfacesNames = new ArrayList<String>();
      interfacesNames.add("java.util.Map<K,V>");
      page.setSuperInterfaces(interfacesNames, true);

      context.wizard.performFinish();

      String text = context.getNewTypeContent();
      //			System.out.println(text);

      assertTrue(text.contains("@Decorator"));
      assertTrue(text.contains("@Delegate"));
    } finally {
      context.close();
    }
  }
  public void testNewAnnotationLiteralWizardWithMembers() {
    WizardContext context = new WizardContext();
    context.init(
        "org.jboss.tools.cdi.ui.wizard.NewAnnotationLiteralCreationWizard",
        PACK_NAME,
        "NewLiteral");

    ICDIProject cdi = CDICorePlugin.getCDIProject(context.tck, true);

    try {
      NewAnnotationLiteralWizardPage page = (NewAnnotationLiteralWizardPage) context.page;

      page.setQualifier("javax.enterprise.inject.New");

      context.wizard.performFinish();

      String text = context.getNewTypeContent();
      //			System.out.println(text);

      assertTrue(text.contains("AnnotationLiteral<New>"));
      assertTrue(text.contains("private final Class<?> value;"));
    } finally {
      context.close();
    }
  }
  private IClassBean findClassBean() {
    CDICoreNature cdiNature = CDICorePlugin.getCDI(file.getProject(), true);
    if (cdiNature == null) return null;

    ICDIProject cdiProject = cdiNature.getDelegate();

    if (cdiProject == null) return null;

    for (IBean bean : cdiProject.getBeans(file.getFullPath())) {
      if (bean instanceof IClassBean) return (IClassBean) bean;
    }

    return null;
  }
  public void testExact() throws CoreException, IOException {
    ICDIProject cdi = CDICorePlugin.getCDIProject(getTestProject(), true);

    Collection<IBean> bs =
        cdi.getBeans(new Path("/CDISolderTest/src/org/jboss/exact/FishFactory.java"));
    assertEquals(2, bs.size());
    IClassBean cls = null;
    IProducerMethod mtd = null;
    for (IBean b : bs) {
      if (b instanceof IClassBean) {
        cls = (IClassBean) b;
      } else if (b instanceof IProducerMethod) {
        mtd = (IProducerMethod) b;
      }
    }
    assertNotNull(cls);
    assertNotNull(mtd);
    Collection<IInjectionPoint> points = cls.getInjectionPoints();
    int count = 0;
    for (IInjectionPoint p : points) {
      Collection<IBean> injected = cdi.getBeans(false, p);
      IMember member = p.getSourceMember();
      if (member.getElementName().equals("peacefulFish")) {
        assertEquals(1, injected.size());
        IBean ib = injected.iterator().next();
        assertEquals("org.jboss.exact.Salmon", ib.getBeanClass().getFullyQualifiedName());
        count++;
      } else if (member.getElementName().equals("dangerousFish")) {
        assertEquals(1, injected.size());
        IBean ib = injected.iterator().next();
        assertEquals("org.jboss.exact.Shark", ib.getBeanClass().getFullyQualifiedName());
        count++;
      } else if (member.getElementName().equals("getTastyFish")) {
        assertEquals(1, injected.size());
        IBean ib = injected.iterator().next();
        assertEquals("org.jboss.exact.Salmon", ib.getBeanClass().getFullyQualifiedName());
        count++;
      } else {
      }
    }
    assertEquals(3, count);
  }
  /**
   * Existing interceptor binding, taken from TCK, is annotated @Inherited @Target({TYPE}) If this
   * test fails, first check that the existing interceptor binding has not been moved or modified.
   * In the previous version, the result of testNewInterceptorBindingWizard() was used, but that
   * turned to be not safe, since the order of tests is not guaranteed.
   *
   * @throws CoreException
   */
  public void testNewInterceptorBindingWizardWithBinding() throws CoreException {
    IProject tck = ResourcesPlugin.getWorkspace().getRoot().getProject("tck");
    tck.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());

    WizardContext context = new WizardContext();
    context.init(
        "org.jboss.tools.cdi.ui.wizard.NewInterceptorBindingCreationWizard",
        PACK_NAME,
        INTERCEPTOR_BINDING2_NAME);

    try {
      NewInterceptorBindingWizardPage page = (NewInterceptorBindingWizardPage) context.page;
      ICDIProject cdi = CDICorePlugin.getCDIProject(context.tck, true);
      IInterceptorBinding s =
          cdi.getInterceptorBinding(EXISTING_PACK_NAME + "." + EXISTING_INTERCEPTOR_BINDING_NAME);
      assertNotNull(s);

      page.addInterceptorBinding(s);
      String message = page.getErrorMessage();
      assertNull(message);
      message = page.getMessage();
      assertNotNull(message);
      int messageType = page.getMessageType();
      assertEquals(IMessageProvider.WARNING, messageType);
      String testmessage =
          NLS.bind(
              CDIUIMessages.MESSAGE_INTERCEPTOR_BINDING_IS_NOT_COMPATIBLE,
              s.getSourceType().getElementName());
      assertEquals(testmessage, message);

      page.setTarget("TYPE");

      message = page.getErrorMessage();
      assertNull(message);
      message = page.getMessage();
      assertNull(message);

    } finally {
      context.close();
    }
  }
  public void testNewBeanWizard() throws Exception {
    WizardContext context = new WizardContext();
    context.init("org.jboss.tools.cdi.ui.wizard.NewBeanCreationWizard", PACK_NAME, BEAN_NAME);

    ICDIProject cdi = CDICorePlugin.getCDIProject(context.tck, true);

    try {
      NewBeanWizardPage page = (NewBeanWizardPage) context.page;

      page.setBeanName("myNewBean");

      page.setScope(CDIConstants.SESSION_SCOPED_ANNOTATION_TYPE_NAME);
      String message = page.getMessage();
      assertEquals(CDIUIMessages.MESSAGE_BEAN_SHOULD_BE_SERIALIZABLE, message);
      assertEquals(IMessageProvider.WARNING, page.getMessageType());

      page.setScope(CDIConstants.APPLICATION_SCOPED_ANNOTATION_TYPE_NAME);
      assertEquals(IMessageProvider.NONE, page.getMessageType());

      context.wizard.performFinish();

      String text = context.getNewTypeContent();
      //			System.out.println(text);

      assertTrue(text.contains("@Named"));
      assertTrue(text.contains("\"myNewBean\""));

      IType type = (IType) context.wizard.getCreatedElement();
      int f = type.getFlags();
      assertTrue(Modifier.isPublic(f));
      assertFalse(Modifier.isAbstract(f));
      //			String[] is = type.getSuperInterfaceNames();
      //			assertEquals(1, is.length);
      //			assertEquals("Serializable", is[0]);
    } finally {
      context.close();
    }
  }
  /**
   * Existing interceptor binding, taken from TCK, is annotated @Inherited @Target({TYPE}) If this
   * test fails, first check that the existing interceptor binding has not been moved or modified.
   * In the previous version, the result of testNewInterceptorBindingWizard() was used, but that
   * turned to be not safe, since the order of tests is not guaranteed.
   *
   * @throws CoreException
   */
  public void testNewInterceptorWizard() throws CoreException {
    WizardContext context = new WizardContext();
    context.init(
        "org.jboss.tools.cdi.ui.wizard.NewInterceptorCreationWizard", PACK_NAME, INTERCEPTOR_NAME);

    ICDIProject cdi = CDICorePlugin.getCDIProject(context.tck, true);
    ICDIAnnotation a =
        cdi.getInterceptorBinding(EXISTING_PACK_NAME + "." + EXISTING_INTERCEPTOR_BINDING_NAME);
    assertNotNull(a);

    try {
      NewInterceptorWizardPage page = (NewInterceptorWizardPage) context.page;

      page.addInterceptorBinding(a);

      assertTrue(page.isToBeRegisteredInBeansXML());
      context.setTypeName("com.acme", "Foo");
      assertFalse(page.isToBeRegisteredInBeansXML());
      context.setTypeName(PACK_NAME, INTERCEPTOR_NAME);
      assertTrue(page.isToBeRegisteredInBeansXML());

      context.wizard.performFinish();

      String text = context.getNewTypeContent();

      assertTrue(text.contains("@Interceptor"));
      assertTrue(text.contains("@" + EXISTING_INTERCEPTOR_BINDING_NAME));

      IProject tck = ResourcesPlugin.getWorkspace().getRoot().getProject("tck");
      IFile f = tck.getFile("WebContent/WEB-INF/beans.xml");
      XModelObject o = EclipseResourceUtil.createObjectForResource(f);
      XModelObject c = o.getChildByPath("Interceptors/" + PACK_NAME + "." + INTERCEPTOR_NAME);
      assertNotNull(c);
    } finally {
      context.close();
    }
  }
  public void testNewAnnotationLiteralWizard() {
    WizardContext context = new WizardContext();
    context.init(
        "org.jboss.tools.cdi.ui.wizard.NewAnnotationLiteralCreationWizard",
        PACK_NAME,
        HAIRY_QUALIFIER + "Literal");

    ICDIProject cdi = CDICorePlugin.getCDIProject(context.tck, true);

    try {
      NewAnnotationLiteralWizardPage page = (NewAnnotationLiteralWizardPage) context.page;

      page.setQualifier(HAIRY_PACK_NAME + "." + HAIRY_QUALIFIER);

      context.wizard.performFinish();

      String text = context.getNewTypeContent();
      //			System.out.println(text);

      assertTrue(text.contains("AnnotationLiteral<" + HAIRY_QUALIFIER + ">"));
    } finally {
      context.close();
    }
  }
  public void testNewStereotypeWizard() {
    WizardContext context = new WizardContext();
    context.init(
        "org.jboss.tools.cdi.ui.wizard.NewStereotypeCreationWizard", PACK_NAME, STEREOTYPE_NAME);

    try {
      NewStereotypeWizardPage page = (NewStereotypeWizardPage) context.page;
      page.setInherited(true);
      page.setTarget("METHOD,FIELD");
      page.setNamed(true);
      page.setAlternative(true);
      page.setToBeRegisteredInBeansXML(true);

      assertTrue(page.isToBeRegisteredInBeansXML());

      context.wizard.performFinish();

      String text = context.getNewTypeContent();

      assertTrue(text.contains("@Stereotype"));
      assertTrue(text.contains("@Inherited"));
      assertTrue(text.contains("@Named"));
      assertTrue(text.contains("@Target({ METHOD, FIELD })"));
      assertTrue(text.contains("@Retention(RUNTIME)"));

      IProject tck = ResourcesPlugin.getWorkspace().getRoot().getProject("tck");
      IFile f = tck.getFile("WebContent/WEB-INF/beans.xml");
      XModelObject o = EclipseResourceUtil.createObjectForResource(f);
      XModelObject c = o.getChildByPath("Alternatives/" + PACK_NAME + "." + STEREOTYPE_NAME);
      assertNotNull(c);

    } finally {
      context.close();
    }

    // testNewStereotypeWizardWithStereotype()
    context = new WizardContext();
    context.init(
        "org.jboss.tools.cdi.ui.wizard.NewStereotypeCreationWizard", PACK_NAME, STEREOTYPE2_NAME);
    try {
      context.tck.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
    } catch (CoreException e) {
      e.printStackTrace();
    }
    ICDIProject cdi = CDICorePlugin.getCDIProject(context.tck, true);
    IStereotype s = cdi.getStereotype(PACK_NAME + "." + STEREOTYPE_NAME);
    IStereotype d = cdi.getStereotype(CDIConstants.DECORATOR_STEREOTYPE_TYPE_NAME);
    assertNotNull(s);
    assertNotNull(d);

    try {
      NewStereotypeWizardPage page = (NewStereotypeWizardPage) context.page;
      page.setInherited(true);
      page.setTarget("METHOD,FIELD");
      page.setNamed(true);

      page.addStereotype(d);
      String message = page.getErrorMessage();
      assertNull(message);
      message = page.getMessage();
      assertNotNull(message);
      int messageType = page.getMessageType();
      assertEquals(IMessageProvider.WARNING, messageType);
      String testmessage =
          NLS.bind(
              CDIUIMessages.MESSAGE_STEREOTYPE_IS_NOT_COMPATIBLE,
              d.getSourceType().getElementName());
      assertEquals(testmessage, message);

      page.addStereotype(s);
      message = page.getErrorMessage();
      testmessage =
          NLS.bind(
              CDIUIMessages.MESSAGE_STEREOTYPE_CANNOT_BE_APPLIED_TO_TYPE,
              s.getSourceType().getElementName());
      assertEquals(testmessage, message);
    } finally {
      context.close();
    }
  }