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

TestNG dataprovider with custom object return null values and duplicate output

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Major
    • None
    • 1.1.0.Final
    • JBoss AS Containers
    • None
    • 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

      Attachments

        Activity

          People

            Unassigned Unassigned
            claudinei_jira Claudinei Sartori (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: