Package org.jboss.forge.addon.parser.java.resources

Examples of org.jboss.forge.addon.parser.java.resources.JavaResource


   }

   @Test
   public void testNewField() throws Exception
   {
      JavaResource entity = projectHelper.createJPAEntity(project, "Customer");
      try (WizardCommandController controller = uiTestHarness.createWizardController(NewFieldWizard.class,
               project.getRoot()))
      {
         controller.initialize();
         Assert.assertTrue(controller.isEnabled());
         controller.setValueFor("targetEntity", entity);
         Assert.assertFalse(controller.canExecute());
         controller.setValueFor("named", "firstName");
         controller.setValueFor("columnName", "FIRST_NAME_COLUMN");
         Assert.assertFalse(controller.canMoveToNextStep());
         Assert.assertTrue(controller.canExecute());
         Result result = controller.execute();
         Assert.assertFalse(result instanceof Failed);
         Assert.assertEquals("Field firstName created", result.getMessage());
      }
      JavaClass<?> javaClass = entity.getJavaType();
      Assert.assertTrue(javaClass.hasField("firstName"));
      final Field<?> field = javaClass.getField("firstName");
      Assert.assertTrue(field.hasAnnotation(Column.class));
      Assert.assertEquals("String", field.getType().getName());
      Assert.assertEquals("FIRST_NAME_COLUMN", field.getAnnotation(Column.class).getStringValue("name"));
View Full Code Here


   }

   @Test
   public void testNewFieldWithNotNullableInsertableUpdatableTrue() throws Exception
   {
      JavaResource entity = projectHelper.createJPAEntity(project, "Customer");
      try (WizardCommandController controller = uiTestHarness.createWizardController(NewFieldWizard.class,
               project.getRoot()))
      {
         controller.initialize();
         Assert.assertTrue(controller.isEnabled());
         controller.setValueFor("targetEntity", entity);
         Assert.assertFalse(controller.canExecute());
         controller.setValueFor("named", "firstName");
         controller.setValueFor("columnName", "FIRST_NAME_COLUMN");
         controller.setValueFor("not-nullable", "true");
         controller.setValueFor("not-insertable", "true");
         controller.setValueFor("not-updatable", "true");
         Assert.assertFalse(controller.canMoveToNextStep());
         Assert.assertTrue(controller.canExecute());
         Result result = controller.execute();
         Assert.assertFalse(result instanceof Failed);
         Assert.assertEquals("Field firstName created", result.getMessage());
      }
      JavaClass<?> javaClass = entity.getJavaType();
      Assert.assertTrue(javaClass.hasField("firstName"));
      final Field<?> field = javaClass.getField("firstName");
      Assert.assertTrue(field.hasAnnotation(Column.class));
      Assert.assertEquals("String", field.getType().getName());
      Assert.assertEquals("FIRST_NAME_COLUMN", field.getAnnotation(Column.class).getStringValue("name"));
View Full Code Here


   @Test
   public void testNewFieldWithNotNullableInsertableUpdatableFalse() throws Exception
   {
      JavaResource entity = projectHelper.createJPAEntity(project, "Customer");
      try (WizardCommandController controller = uiTestHarness.createWizardController(NewFieldWizard.class,
               project.getRoot()))
      {
         controller.initialize();
         Assert.assertTrue(controller.isEnabled());
         controller.setValueFor("targetEntity", entity);
         Assert.assertFalse(controller.canExecute());
         controller.setValueFor("named", "firstName");
         controller.setValueFor("columnName", "FIRST_NAME_COLUMN");
         controller.setValueFor("not-nullable", "false");
         controller.setValueFor("not-insertable", "false");
         controller.setValueFor("not-updatable", "false");
         Assert.assertFalse(controller.canMoveToNextStep());
         Assert.assertTrue(controller.canExecute());
         Result result = controller.execute();
         Assert.assertFalse(result instanceof Failed);
         Assert.assertEquals("Field firstName created", result.getMessage());
      }
      JavaClass<?> javaClass = entity.getJavaType();
      Assert.assertTrue(javaClass.hasField("firstName"));
      final Field<?> field = javaClass.getField("firstName");
      Assert.assertTrue(field.hasAnnotation(Column.class));
      Assert.assertEquals("String", field.getType().getName());
      Assert.assertEquals("FIRST_NAME_COLUMN", field.getAnnotation(Column.class).getStringValue("name"));
View Full Code Here

   }

   @Test
   public void testNewTransientField() throws Exception
   {
      JavaResource entity = projectHelper.createJPAEntity(project, "Customer");
      try (WizardCommandController controller = uiTestHarness.createWizardController(NewFieldWizard.class,
               project.getRoot()))
      {
         controller.initialize();
         Assert.assertTrue(controller.isEnabled());
         controller.setValueFor("targetEntity", entity);
         Assert.assertFalse(controller.canExecute());
         controller.setValueFor("named", "firstName");
         controller.setValueFor("transient", Boolean.TRUE);
         Assert.assertFalse(controller.canMoveToNextStep());
         Assert.assertTrue(controller.canExecute());
         Result result = controller.execute();
         Assert.assertFalse(result instanceof Failed);
         Assert.assertEquals("Transient Field firstName created", result.getMessage());
      }
      JavaClass<?> javaClass = entity.getJavaType();
      Assert.assertTrue(javaClass.hasField("firstName"));
      final Field<?> field = javaClass.getField("firstName");
      Assert.assertFalse(field.hasAnnotation(Column.class));
      Assert.assertTrue(field.hasAnnotation(Transient.class));
      Assert.assertEquals("String", field.getType().getName());
View Full Code Here

   }

   @Test
   public void testUpdateExistingField() throws Exception
   {
      JavaResource entity = projectHelper.createJPAEntity(project, "Customer");
      JavaClassSource javaSource = entity.getJavaType();
      beanOperations.addFieldTo(javaSource, "String", "firstName");
      entity.setContents(javaSource.toString());
      try (WizardCommandController controller = uiTestHarness.createWizardController(NewFieldWizard.class,
               project.getRoot()))
      {
         controller.initialize();
         Assert.assertTrue(controller.isEnabled());
         controller.setValueFor("targetEntity", entity);
         Assert.assertFalse(controller.canExecute());
         controller.setValueFor("named", "firstName");
         controller.setValueFor("length", "100");
         Assert.assertFalse(controller.canMoveToNextStep());
         Assert.assertTrue(controller.canExecute());
         Result result = controller.execute();
         Assert.assertFalse(result instanceof Failed);
         Assert.assertEquals("Field firstName updated", result.getMessage());
      }
      JavaClass<?> javaClass = entity.getJavaType();
      Assert.assertTrue(javaClass.hasField("firstName"));
      final Field<?> field = javaClass.getField("firstName");
      Assert.assertTrue(field.hasAnnotation(Column.class));
      Assert.assertEquals("String", field.getType().getName());
      Assert.assertEquals("100", field.getAnnotation(Column.class).getStringValue("length"));
View Full Code Here

   }

   @Test
   public void testNewOneToManyField() throws Exception
   {
      JavaResource entity = projectHelper.createJPAEntity(project, "Customer");
      JavaResource otherEntity = projectHelper.createJPAEntity(project, "Account");
      try (WizardCommandController controller = uiTestHarness.createWizardController(NewFieldWizard.class,
               project.getRoot()))
      {
         controller.initialize();
         Assert.assertTrue(controller.isEnabled());
         controller.setValueFor("targetEntity", entity);
         Assert.assertFalse(controller.canExecute());
         controller.setValueFor("named", "accounts");
         controller.setValueFor("type", otherEntity.getJavaType().getCanonicalName());
         controller.setValueFor("relationshipType", RelationshipType.ONE_TO_MANY);
         Assert.assertTrue(controller.canMoveToNextStep());
         Assert.assertTrue(controller.canExecute());
         Result result = controller.execute();
         Assert.assertFalse(result instanceof Failed);
View Full Code Here

   }
  
   @Test
   public void testEmbeddedRelationship() throws Exception
   {
      JavaResource entity = projectHelper.createJPAEntity(project, "Customer");
      JavaResource otherEntity = projectHelper.createJPAEmbeddable(project, "Account");
      try (WizardCommandController controller = uiTestHarness.createWizardController(NewFieldWizard.class,
               project.getRoot()))
      {
         controller.initialize();
         Assert.assertTrue(controller.isEnabled());
         controller.setValueFor("targetEntity", entity);
         Assert.assertFalse(controller.canExecute());
         controller.setValueFor("named", "accounts");
         controller.setValueFor("type", otherEntity.getJavaType().getCanonicalName());
         controller.setValueFor("relationshipType", RelationshipType.EMBEDDED);
         Assert.assertTrue(controller.canMoveToNextStep());
         Assert.assertTrue(controller.canExecute());
         Result result = controller.execute();
         Assert.assertFalse(result instanceof Failed);
View Full Code Here

   }

   @Test
   public void testNewOneToManyEagerFetchField() throws Exception
   {
      JavaResource entity = projectHelper.createJPAEntity(project, "Customer");
      JavaResource otherEntity = projectHelper.createJPAEntity(project, "Account");
      try (WizardCommandController controller = uiTestHarness.createWizardController(NewFieldWizard.class,
               project.getRoot()))
      {
         controller.initialize();
         Assert.assertTrue(controller.isEnabled());
         controller.setValueFor("targetEntity", entity);
         Assert.assertFalse(controller.canExecute());
         controller.setValueFor("named", "accounts");
         controller.setValueFor("type", otherEntity.getJavaType().getCanonicalName());
         controller.setValueFor("relationshipType", RelationshipType.ONE_TO_MANY);
         Assert.assertTrue(controller.canMoveToNextStep());
         controller.next();
         controller.setValueFor("fetchType", FetchType.EAGER);
         Assert.assertTrue(controller.canExecute());
View Full Code Here

   }

   @Test
   public void testNewEnumField() throws Exception
   {
      JavaResource entity = projectHelper.createJPAEntity(project, "Customer");
      JavaResource enumEntity = projectHelper.createEmptyEnum(project, "CustomerType");

      try (WizardCommandController controller = uiTestHarness.createWizardController(NewFieldWizard.class,
               project.getRoot()))
      {
         controller.initialize();
         Assert.assertTrue(controller.isEnabled());
         controller.setValueFor("targetEntity", entity);
         Assert.assertFalse(controller.canExecute());
         controller.setValueFor("named", "customerType");
         controller.setValueFor("type", enumEntity.getJavaType().getCanonicalName());
         Assert.assertFalse(controller.canMoveToNextStep());
         Assert.assertTrue(controller.canExecute());
         Result result = controller.execute();
         Assert.assertFalse(result instanceof Failed);
         Assert.assertEquals("Field customerType created", result.getMessage());
View Full Code Here

   }

   @Test
   public void testNewEnumFieldWithColumnName() throws Exception
   {
      JavaResource entity = projectHelper.createJPAEntity(project, "Customer");
      JavaResource enumEntity = projectHelper.createEmptyEnum(project, "CustomerType");

      try (WizardCommandController controller = uiTestHarness.createWizardController(NewFieldWizard.class,
               project.getRoot()))
      {
         controller.initialize();
         Assert.assertTrue(controller.isEnabled());
         controller.setValueFor("targetEntity", entity);
         Assert.assertFalse(controller.canExecute());
         controller.setValueFor("named", "customerType");
         controller.setValueFor("type", enumEntity.getJavaType().getCanonicalName());
         controller.setValueFor("columnName", "CUSTOMER_TYPE_COLUMN");
         Assert.assertFalse(controller.canMoveToNextStep());
         Assert.assertTrue(controller.canExecute());
         Result result = controller.execute();
         Assert.assertFalse(result instanceof Failed);
View Full Code Here

TOP

Related Classes of org.jboss.forge.addon.parser.java.resources.JavaResource

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.