Package org.dbunit.database

Examples of org.dbunit.database.DatabaseConnection


    @DatabaseSetup(value = EMPTY_DATASET)
    @DatabaseTearDown(value = CREATE_DATASET, type = DatabaseOperation.DELETE_ALL)
    @Override
    public void testSave() throws Exception {
        try {
            DatabaseConnection connection = new DatabaseConnection(dataSource.getConnection());
            IDataSet expectedDataSet = new FlatXmlDataSetBuilder().build(this.getClass()
                    .getResource("/dbunit/dao/admin/businesspartner-create_no-id.xml").openStream());
            BusinessPartner bp = new BusinessPartner();
            BusinessPartner nbp;

            bp.setId(null);
            bp.setName(DEFAULT_BUSINESSPARTNER_NAME);
            bp.setVersion(1);
            nbp = bpDAO.save(bp);
            assertEquals(bp.getName(), nbp.getName());
            entityManager.getTransaction().commit();
            DatabaseAssertionMode.NON_STRICT.getDatabaseAssertion().assertEquals(expectedDataSet,
                    connection.createDataSet(expectedDataSet.getTableNames()));
            connection.close();
        } catch (DatabaseUnitException e) {
            e.printStackTrace();
            fail(e.getLocalizedMessage());
        } catch (SQLException e) {
            e.printStackTrace();
View Full Code Here


    @Test
    @DatabaseSetup(value = CREATE_DATASET)
    @DatabaseTearDown(value = UPDATE_DATASET, type = DatabaseOperation.DELETE_ALL)
    public void testSave2() throws Exception {
        try {
            DatabaseConnection connection = new DatabaseConnection(dataSource.getConnection());
            IDataSet expectedDataSet = new FlatXmlDataSetBuilder().build(this.getClass().getResource(UPDATE_DATASET).openStream());
            BusinessPartner bp = new BusinessPartner();
            BusinessPartner nbp;

            bp.setId(1L);
            bp.setName(UPDATED_BUSINESSPARTNER_NAME);
            bp.setVersion(1);
            nbp = bpDAO.save(bp);
            assertEquals(bp.getName(), nbp.getName());
            entityManager.getTransaction().commit();
            DatabaseAssertionMode.NON_STRICT.getDatabaseAssertion().assertEquals(expectedDataSet,
                    connection.createDataSet(expectedDataSet.getTableNames()));
            connection.close();
        } catch (DatabaseUnitException e) {
            e.printStackTrace();
            fail(e.getLocalizedMessage());
        } catch (SQLException e) {
            e.printStackTrace();
View Full Code Here

    @DatabaseTearDown(value = CREATEGENERIC_DATASET, type = DatabaseOperation.DELETE_ALL)
    @Ignore("Seems to have 2 TAAs instead of 1")
    @Override
    public void testSave() throws Exception {
        try {
            DatabaseConnection connection = new DatabaseConnection(dataSource.getConnection());
            IDataSet expectedDataSet = new FlatXmlDataSetBuilder().build(this.getClass().getResource("/dbunit/dao/admin/taa-create1_no-id.xml")
                    .openStream());
            GenericTAA taa = new GenericTAA();
            AbstractTAA ntaa;

            taa.setId(null);
            taa.setLicenseNumber(DEFAULT_LICENSENUMBER);
            taa.setVersion(1);
            ntaa = taaDAO.save(taa);
            assertEquals(ntaa.getLicenseNumber(), taa.getLicenseNumber());
            entityManager.getTransaction().commit();
            DatabaseAssertionMode.NON_STRICT.getDatabaseAssertion().assertEquals(expectedDataSet,
                    connection.createDataSet(expectedDataSet.getTableNames()));
            connection.close();
        } catch (DatabaseUnitException e) {
            e.printStackTrace();
            fail(e.getLocalizedMessage());
        } catch (SQLException e) {
            e.printStackTrace();
View Full Code Here

    @Test
    @DatabaseSetup(value = CREATEGENERIC_DATASET)
    @DatabaseTearDown(value = UPDATEGENERIC_DATASET, type = DatabaseOperation.DELETE_ALL)
    public void testSave2() throws Exception {
        try {
            DatabaseConnection connection = new DatabaseConnection(dataSource.getConnection());
            IDataSet expectedDataSet = new FlatXmlDataSetBuilder().build(this.getClass().getResource(UPDATEGENERIC_DATASET).openStream());
            GenericTAA taa = new GenericTAA();
            AbstractTAA ntaa;

            taa.setId(1L);
            taa.setLicenseNumber(UPDATED_LICENSENUMBER);
            taa.setVersion(1);
            ntaa = taaDAO.save(taa);
            assertEquals(ntaa.getLicenseNumber(), taa.getLicenseNumber());
            entityManager.getTransaction().commit();
            DatabaseAssertionMode.NON_STRICT.getDatabaseAssertion().assertEquals(expectedDataSet,
                    connection.createDataSet(expectedDataSet.getTableNames()));
            connection.close();
        } catch (DatabaseUnitException e) {
            e.printStackTrace();
            fail(e.getLocalizedMessage());
        } catch (SQLException e) {
            e.printStackTrace();
View Full Code Here

    @Test
    @DatabaseSetup(value = EMPTY_DATASET)
    @DatabaseTearDown(value = CREATESPECIFIC_DATASET, type = DatabaseOperation.DELETE_ALL)
    public void testSaveSpecific() throws Exception {
        try {
            DatabaseConnection connection = new DatabaseConnection(dataSource.getConnection());
            IDataSet expectedDataSet = new FlatXmlDataSetBuilder().build(this.getClass().getResource("/dbunit/dao/admin/taa-create2_no-id.xml")
                    .openStream());
            SpecificTAA taa = new SpecificTAA();
            AbstractTAA ntaa;

            taa.setId(null);
            taa.setLicenseNumber(DEFAULT_LICENSENUMBER);
            taa.setVersion(1);
            ntaa = taaDAO.save(taa);
            assertEquals(ntaa.getLicenseNumber(), taa.getLicenseNumber());
            entityManager.getTransaction().commit();
            DatabaseAssertionMode.NON_STRICT.getDatabaseAssertion().assertEquals(expectedDataSet,
                    connection.createDataSet(expectedDataSet.getTableNames()));
            connection.close();
        } catch (DatabaseUnitException e) {
            e.printStackTrace();
            fail(e.getLocalizedMessage());
        } catch (SQLException e) {
            e.printStackTrace();
View Full Code Here

    @Test
    @DatabaseSetup(value = CREATESPECIFIC_DATASET)
    @DatabaseTearDown(value = UPDATESPECIFIC_DATASET, type = DatabaseOperation.DELETE_ALL)
    public void testSaveSpecific2() throws Exception {
        try {
            DatabaseConnection connection = new DatabaseConnection(dataSource.getConnection());
            IDataSet expectedDataSet = new FlatXmlDataSetBuilder().build(this.getClass().getResource(UPDATESPECIFIC_DATASET).openStream());
            SpecificTAA taa = new SpecificTAA();
            AbstractTAA ntaa;

            taa.setId(1L);
            taa.setLicenseNumber(UPDATED_LICENSENUMBER);
            taa.setVersion(1);
            ntaa = taaDAO.save(taa);
            assertEquals(ntaa.getLicenseNumber(), taa.getLicenseNumber());
            entityManager.getTransaction().commit();
            DatabaseAssertionMode.NON_STRICT.getDatabaseAssertion().assertEquals(expectedDataSet,
                    connection.createDataSet(expectedDataSet.getTableNames()));
            connection.close();
        } catch (DatabaseUnitException e) {
            e.printStackTrace();
            fail(e.getLocalizedMessage());
        } catch (SQLException e) {
            e.printStackTrace();
View Full Code Here

    @DatabaseTearDown(value = "/dbunit/dao/admin/profile-create_no-id.xml", type = DatabaseOperation.DELETE_ALL)
    @Ignore("May fail because of a conflict with the admin uzer (the account created on setUp)")
    @Override
    public void testSave() throws Exception {
        try {
            DatabaseConnection connection = new DatabaseConnection(dataSource.getConnection());
            IDataSet expectedDataSet = new FlatXmlDataSetBuilder().build(this.getClass().getResource("/dbunit/dao/admin/profile-create_no-id.xml")
                    .openStream());
            Profile profile = new Profile();
            Profile nprofile;

            profile.setAdministrator(false);
            profile.setLicensesConsultation(false);
            profile.setLicensesEdition(false);
            profile.setProgramsConsultation(false);
            profile.setProgramsEdition(false);
            profile.setName(DEFAULT_PROFILE_NAME);
            profile.setVersion(1);
            nprofile = profileDAO.save(profile);
            assertNotNull(nprofile);
            assertEquals(nprofile.getName(), profile.getName());
            assertEquals(nprofile.getAdministrator(), profile.getAdministrator());
            assertEquals(nprofile.getLicensesConsultation(), profile.getLicensesConsultation());
            assertEquals(nprofile.getLicensesEdition(), profile.getLicensesEdition());
            assertEquals(nprofile.getProgramsConsultation(), profile.getProgramsConsultation());
            assertEquals(nprofile.getProgramsEdition(), profile.getProgramsEdition());
            entityManager.getTransaction().commit();
            DatabaseAssertionMode.NON_STRICT.getDatabaseAssertion().assertEquals(expectedDataSet,
                    connection.createDataSet(expectedDataSet.getTableNames()));
            connection.close();
        } catch (DatabaseUnitException e) {
            e.printStackTrace();
            fail(e.getLocalizedMessage());
        } catch (SQLException e) {
            e.printStackTrace();
View Full Code Here

    @Test
    @DatabaseSetup(value = CREATE_DATASET)
    @DatabaseTearDown(value = UPDATE_DATASET, type = DatabaseOperation.DELETE_ALL)
    public void testSave2() throws Exception {
        try {
            DatabaseConnection connection = new DatabaseConnection(dataSource.getConnection());
            IDataSet expectedDataSet = new FlatXmlDataSetBuilder().build(this.getClass()
                    .getResource("/dbunit/dao/admin/profile-update_aftersave.xml").openStream());
            Profile profile = new Profile();
            Profile nprofile;

            profile.setId(1L);
            profile.setAdministrator(true);
            profile.setLicensesConsultation(true);
            profile.setLicensesEdition(true);
            profile.setProgramsConsultation(true);
            profile.setProgramsEdition(true);
            profile.setName(ADMINISTRATOR_PROFILE_NAME);
            profile.setVersion(1);
            nprofile = profileDAO.save(profile);
            assertNotNull(nprofile);
            assertEquals(nprofile.getName(), profile.getName());
            assertEquals(nprofile.getAdministrator(), profile.getAdministrator());
            assertEquals(nprofile.getLicensesConsultation(), profile.getLicensesConsultation());
            assertEquals(nprofile.getLicensesEdition(), profile.getLicensesEdition());
            assertEquals(nprofile.getProgramsConsultation(), profile.getProgramsConsultation());
            assertEquals(nprofile.getProgramsEdition(), profile.getProgramsEdition());
            entityManager.getTransaction().commit();
            DatabaseAssertionMode.NON_STRICT.getDatabaseAssertion().assertEquals(expectedDataSet,
                    connection.createDataSet(expectedDataSet.getTableNames()));
            connection.close();
        } catch (DatabaseUnitException e) {
            e.printStackTrace();
            fail(e.getLocalizedMessage());
        } catch (SQLException e) {
            e.printStackTrace();
View Full Code Here

    @DatabaseSetup(value = "/dbunit/dao/admin/dsp5-empty_beforesave.xml")
    @DatabaseTearDown(value = CREATE_DATASET, type = DatabaseOperation.DELETE_ALL)
    @Override
    public void testSave() throws Exception {
        try {
            DatabaseConnection connection = new DatabaseConnection(dataSource.getConnection());
            IDataSet expectedDataSet = new FlatXmlDataSetBuilder().build(this.getClass().getResource("/dbunit/dao/admin/dsp5-create_no-id.xml")
                    .openStream());
            DSP5 dsp5 = new DSP5();
            DSP5 ndsp5;
            ConcreteBusinessPartner cbp = new ConcreteBusinessPartner();
            BusinessPartner bp = new BusinessPartner();

            bp.setId(1L);
            bp.setName(BUSINESSPARTNER_NAME);
            bp.setVersion(1);
            cbp.setId(1L);
            cbp.setCountry(CONCRETEBUSINESSPARTNER_COUNTRY);
            cbp.setBusinessPartner(bp);
            cbp.setVersion(1);
            dsp5.setId(null);
            dsp5.setLicenseNumber(DEFAULT_LICENSE_NUMBER);
            dsp5.setApplicant(cbp);
            dsp5.setEndUser(cbp);
            dsp5.setManufacturer(cbp);
            dsp5.setSeller(cbp);
            dsp5.setSourceOfCommodity(cbp);
            dsp5.setApproval(APPROVAL_TYPE);
            dsp5.setVersion(1);
            ndsp5 = dsp5DAO.save(dsp5);
            assertNotNull(ndsp5);
            assertNotNull(ndsp5.getLicenseNumber());
            assertNotNull(ndsp5.getApproval());
            assertEquals(ndsp5.getLicenseNumber(), dsp5.getLicenseNumber());
            assertEquals(ndsp5.getApproval(), dsp5.getApproval());
            entityManager.getTransaction().commit();
            DatabaseAssertionMode.NON_STRICT.getDatabaseAssertion().assertEquals(expectedDataSet,
                    connection.createDataSet(expectedDataSet.getTableNames()));
            connection.close();
        } catch (DatabaseUnitException e) {
            e.printStackTrace();
            fail(e.getLocalizedMessage());
        } catch (SQLException e) {
            e.printStackTrace();
View Full Code Here

    @Test
    @DatabaseSetup(value = CREATE_DATASET)
    @DatabaseTearDown(value = UPDATE_DATASET, type = DatabaseOperation.DELETE_ALL)
    public void testSave2() throws Exception {
        try {
            DatabaseConnection connection = new DatabaseConnection(dataSource.getConnection());
            IDataSet expectedDataSet = new FlatXmlDataSetBuilder().build(this.getClass().getResource(UPDATE_DATASET).openStream());
            DSP5 dsp5 = new DSP5();
            DSP5 ndsp5;
            ConcreteBusinessPartner cbp = new ConcreteBusinessPartner();
            BusinessPartner bp = new BusinessPartner();
            Set<ConcreteBusinessPartner> consignees = new HashSet<ConcreteBusinessPartner>();

            bp.setId(1L);
            bp.setName(BUSINESSPARTNER_NAME);
            bp.setVersion(1);
            cbp.setId(1L);
            cbp.setCountry(CONCRETEBUSINESSPARTNER_COUNTRY);
            cbp.setBusinessPartner(bp);
            cbp.setVersion(1);
            consignees.add(cbp);
            dsp5.setId(1L);
            dsp5.setLicenseNumber(UPDATED_LICENSE_NUMBER);
            dsp5.setApplicant(cbp);
            dsp5.setEndUser(cbp);
            dsp5.setManufacturer(cbp);
            dsp5.setSeller(cbp);
            dsp5.setSourceOfCommodity(cbp);
            dsp5.setApproval(APPROVAL_TYPE);
            dsp5.getConsignees().addAll(consignees);
            dsp5.setVersion(1);
            ndsp5 = dsp5DAO.save(dsp5);
            assertNotNull(ndsp5);
            assertNotNull(dsp5.getLicenseNumber());
            assertNotNull(dsp5.getApproval());
            assertEquals(ndsp5.getLicenseNumber(), dsp5.getLicenseNumber());
            assertEquals(ndsp5.getApproval(), dsp5.getApproval());
            entityManager.getTransaction().commit();
            DatabaseAssertionMode.NON_STRICT.getDatabaseAssertion().assertEquals(expectedDataSet,
                    connection.createDataSet(expectedDataSet.getTableNames()));
            connection.close();
        } catch (DatabaseUnitException e) {
            e.printStackTrace();
            fail(e.getLocalizedMessage());
        } catch (SQLException e) {
            e.printStackTrace();
View Full Code Here

TOP

Related Classes of org.dbunit.database.DatabaseConnection

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.