Uploaded image for project: 'Arquillian'
  1. Arquillian
  2. ARQ-1438

TestNG dataprovider with custom object return null values and duplicate output

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 1.1.0.Final
    • Fix Version/s: None
    • Component/s: JBoss AS Containers
    • Labels:
      None
    • Steps to Reproduce:
      Hide
      Country.java
      public class Country implements Serializable {
      
      
      	@Id
      	@GeneratedValue(strategy = GenerationType.IDENTITY)
      	@Column
      	private Long id;
      
      	@NotNull
      	@Size(min = ConstantsNumeric.TWO, max = ConstantsNumeric.FIVE)
      	@Column(length = ConstantsNumeric.FIVE, nullable = false, unique = true)
      	private String sigla;
      
      	@NotNull
      	@Size(min = ConstantsNumeric.TWO, max = ConstantsNumeric.FIFTY)
      	@Column(length = ConstantsNumeric.FIFTY, nullable = false)
      	private String name;
      
      //getters and setters
      
      CountryDAOTest.java
      public class CountryDAOTest extends Arquillian {
      
      
      	@Deployment
      	public static Archive<?> createDeployment() {
      		File[] files = Maven.resolver().loadPomFromFile("pom.xml").importRuntimeDependencies().resolve()
      				.withTransitivity().asFile();
      
      		final JavaArchive jar = ShrinkWrap.create(JavaArchive.class).addClass(Country.class)
      				.addAsResource("test-persistence.xml", "META-INF/persistence.xml")
      				.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
      
      		final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class).addAsLibraries(files).addAsModule(jar);
      
      		return ear;
      	}
      
      
      	@Test(dataProvider = "dataListObject")
      	public void testDataProviderObject(Country country) {
      		Assert.assertNotNull(country); 
      		Assert.assertNotNull(country.getName()); 
      	}
      
      	@DataProvider
      	public Object[][] dataListObject() {
      		final Country country1 = new Country();
      		country1.setName("Portugal");
      		country1.setSigla("pt");
      
      		final Country country2 = new Country();
      		country2.setName("Brasil");
      		country2.setSigla("br");
      
      		final Country country3 = new Country();
      		country3.setName("França");
      		country3.setSigla("fr");
      
      		final Object[][] data = new Object[][] { 
      			{ country1 }, 
      			{ country2 },
      			{ country3 } 
      		};
      
      		return data;
      	}
      
      }
      
      Show
      Country.java public class Country implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column private Long id; @NotNull @Size(min = ConstantsNumeric.TWO, max = ConstantsNumeric.FIVE) @Column(length = ConstantsNumeric.FIVE, nullable = false , unique = true ) private String sigla; @NotNull @Size(min = ConstantsNumeric.TWO, max = ConstantsNumeric.FIFTY) @Column(length = ConstantsNumeric.FIFTY, nullable = false ) private String name; //getters and setters CountryDAOTest.java public class CountryDAOTest extends Arquillian { @Deployment public static Archive<?> createDeployment() { File[] files = Maven.resolver().loadPomFromFile( "pom.xml" ).importRuntimeDependencies().resolve() .withTransitivity().asFile(); final JavaArchive jar = ShrinkWrap.create(JavaArchive.class).addClass(Country.class) .addAsResource( "test-persistence.xml" , "META-INF/persistence.xml" ) .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml" ); final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class).addAsLibraries(files).addAsModule(jar); return ear; } @Test(dataProvider = "dataListObject" ) public void testDataProviderObject(Country country) { Assert.assertNotNull(country); Assert.assertNotNull(country.getName()); } @DataProvider public Object [][] dataListObject() { final Country country1 = new Country(); country1.setName( "Portugal" ); country1.setSigla( "pt" ); final Country country2 = new Country(); country2.setName( "Brasil" ); country2.setSigla( "br" ); final Country country3 = new Country(); country3.setName( "França" ); country3.setSigla( "fr" ); final Object [][] data = new Object [][] { { country1 }, { country2 }, { country3 } }; return data; } }

      Description

      Expected
      Use dataprovider with Arquillian with custom objects like using String, Integer, etc.

      Actual behavior
      When using a custom object with TestNG dataprovider and Arquillian the
      attributes of object return "null" and output is duplicated.

      Actual output

      [stdout] (http-localhost-127.0.0.1-8080-1) Count: br.com.xxx.ejb.entity.domain.Country@1e62801
      [stdout] (http-localhost-127.0.0.1-8080-1) Count: br.com.xxx.ejb.entity.domain.Country@1e62801
      [stdout] (http-localhost-127.0.0.1-8080-1) Count: br.com.xxx.ejb.entity.domain.Country@1e62801
      [stdout] (http-localhost-127.0.0.1-8080-1) Count: br.com.xxx.ejb.entity.domain.Country@1e62801
      [stdout] (http-localhost-127.0.0.1-8080-1) Count: br.com.xxx.ejb.entity.domain.Country@1e62801
      [stdout] (http-localhost-127.0.0.1-8080-1) Count: br.com.xxx.ejb.entity.domain.Country@1e62801
      [stdout] (http-localhost-127.0.0.1-8080-1) Count: br.com.xxx.ejb.entity.domain.Country@1e62801
      [stdout] (http-localhost-127.0.0.1-8080-1) Count: br.com.xxx.ejb.entity.domain.Country@1e62801
      [stdout] (http-localhost-127.0.0.1-8080-1) Count: br.com.xxx.ejb.entity.domain.Country@1e62801

      Expected output

      [stdout] (http-localhost-127.0.0.1-8080-1) Count: br.com.xxx.ejb.entity.domain.Country@1e62801
      [stdout] (http-localhost-127.0.0.1-8080-1) Count: br.com.xxx.ejb.entity.domain.Country@1e62801
      [stdout] (http-localhost-127.0.0.1-8080-1) Count: br.com.xxx.ejb.entity.domain.Country@1e62801

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                claudinei Claudinei Sartori
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated: