java-tutorials/hibernate5/src/test/java/com/baeldung/hibernate/MultiTenantDaoHibernateIntegrationTest.java
Parth Joshi 5b0302524f Added DAO for Supplier (#1950)
* First commit for Hibernate 5 Multitenancy tutorial

* Changes to fix the code.

* Added hibernate begin transaction code.

* Changes to solve the multitenancy issue.

* Changes to integrate h2

* Changing configs to solve the error

* Changes to solve h2 error...

* Changes to fix H2 error.

* Cleaned POM.xml and changed entity name

* Changes table name to supplier

* Removed MySql Dep from pom.xml.

* Changes as per comment in the PR...

* Removed try-catch from test functions.

* Removing the hibernate xml config.

* Changed the formatting as per the formatter.

* Clean up after merge.

* # WARNING: head commit changed in the meantime

Merge remote-tracking branch 'upstream/master' into
hibernate5-multitenancy

Conflicts:
	hibernate5/pom.xml
	pom.xml

* Introduced Supplier DAO

* shifting hibernate properties to src/test/resouces

* removed the old test.

* Filled up the stubs in the DAO.
2017-06-02 22:18:15 -05:00

31 lines
1.0 KiB
Java

package com.baeldung.hibernate;
import java.io.IOException;
import org.hibernate.SessionFactory;
import org.junit.Test;
import com.baeldung.hibernate.dao.SupplierDao;
import com.baeldung.hibernate.pojo.Supplier;
import static org.junit.Assert.assertNull;;
public class MultiTenantDaoHibernateIntegrationTest {
@Test
public void givenDBMode_whenFetchingSuppliersByName_thenChecking() throws UnsupportedTenancyException, IOException {
SessionFactory sessionFactory = HibernateMultiTenantUtil.getSessionFactory();
SupplierDao myDb1Dao = new SupplierDao(sessionFactory, "mydb1");
Supplier db1SupplierName = myDb1Dao.findByName("John");
// finding the same supplier name in another tenant
// and we should not be able to find in there and both dbs are different.
SupplierDao myDb2Dao = new SupplierDao(sessionFactory, "mydb2");
Supplier db2SupplierName = myDb2Dao.findByName(db1SupplierName.getName());
assertNull(db2SupplierName);
}
}