7 Replies Latest reply: Apr 30, 2012 3:07 PM by gonzalad RSS

    arq-persistence : dataset duplication in dataset.yml and in java

    gonzalad Apprentice

      Hello,

       

      I've just began using arquillian persistence.

       

      When using datasets, I'm ending duplicating [1] my datasets in the yml file and in my unit test in order to verify the test result.

       

      Is there a way to avoid code duplication (perhaps reading myself YamlDataSet but this approach doesn't seem clean) ?

       

      Thanks very much !

       

      [1] sample code - I'm duplicating my charge-clientele.yml inside my UT class:

       

      @RunWith(Arquillian.class)
      @Transactional(TransactionMode.ROLLBACK)
      @Cleanup(strategy=CleanupStrategy.USED_ROWS_ONLY)
      @UsingDataSet("charge-clientele.yml")
      public class ChargeClienteleManagerTest {
      
        private List<ChargeClientele> dataset = new ArrayList<ChargeClientele>();
      
        @Test
        public void testFindById() {
          ChargeClientele chargeClientele = chargeClienteleManager
              .findById(dataset.get(0).getId());
          assertNotNull(chargeClientele);
          assertEquals("id invalide", dataset.get(0).getId(),
              chargeClientele.getId());
          assertEquals("nom invalide", dataset.get(0).getNom(),
              chargeClientele.getNom());
          assertEquals("prenom invalide", dataset.get(0).getPrenom(),
              chargeClientele.getPrenom());
          assertEquals("code etab invalide", dataset.get(0)
              .getCompanyCode(), chargeClientele.getCompanyCode());
          assertEquals("racf invalide", dataset.get(0).getUserRACF(),
              chargeClientele.getUserRACF());
        }
      
      
        @Before
        public void setUp() throws Exception {
          ChargeClientele chargeClientele = new ChargeClientele();
          chargeClientele.setId(160L);
          chargeClientele.setCompanyCode("000");
          chargeClientele.setNom("JUNITNOM1");
          chargeClientele.setPrenom("JUNITPRENOM1");
          chargeClientele.setUserRACF("junit1");
          dataset.add(chargeClientele);
      
      
          chargeClientele = new ChargeClientele();
          chargeClientele.setId(161L);
          chargeClientele.setCompanyCode("000");
          chargeClientele.setNom("JUNITNOM2");
          chargeClientele.setPrenom("JUNITPRENOM2");
          chargeClientele.setUserRACF("junit2");
          dataset.add(chargeClientele);
      
      
          chargeClientele = new ChargeClientele();
          chargeClientele.setId(162L);
          chargeClientele.setCompanyCode("000");
          chargeClientele.setNom("JUNITNOM3");
          chargeClientele.setPrenom("JUNITPRENOM3");
          chargeClientele.setUserRACF("junit3");
          dataset.add(chargeClientele);
        }
      }
      

       

      Sample yml :

      ChargeClientele:
        - id: 160
          companyCode: 000
          nom: JUNITNOM1
          prenom: JUNITPRENOM1
          userRACF: junit1
        - id: 161
          companyCode: 000
          nom: JUNITNOM2
          prenom: JUNITPRENOM2
          userRACF: junit2
        - id: 162
          companyCode: 000
          nom: JUNITNOM3
          prenom: JUNITPRENOM3
          userRACF: junit3