use of javax.persistence.EntityManagerFactory in project opencast by opencast.
the class UserSettingsServiceTest method findUserSettingsInputOneSettingsOneSignaturesExpectsProperUserSettings.
@Test
public void findUserSettingsInputOneSettingsOneSignaturesExpectsProperUserSettings() throws UserSettingsServiceException {
int offset = 0;
int limit = 1;
EntityManagerFactory emf = setupEntityManagerFactory(limit, limit, limit, limit, offset, limit);
UserSettingsService userSettingsService = setupUserSettingsService(emf);
userSettingsService.findUserSettings(limit, offset);
}
use of javax.persistence.EntityManagerFactory in project opencast by opencast.
the class UserSettingsServiceTest method addUserSettingInputNormalValuesExpectsSavedSetting.
@Test
public void addUserSettingInputNormalValuesExpectsSavedSetting() throws UserSettingsServiceException {
String key = "newKey";
String value = "newValue";
Capture<UserSettingDto> userSettingDto = new Capture<UserSettingDto>();
EntityTransaction tx = EasyMock.createNiceMock(EntityTransaction.class);
EasyMock.replay(tx);
EntityManager em = EasyMock.createNiceMock(EntityManager.class);
EasyMock.expect(em.getTransaction()).andReturn(tx);
em.persist(EasyMock.capture(userSettingDto));
EasyMock.expectLastCall();
EasyMock.replay(em);
EntityManagerFactory emf = EasyMock.createNiceMock(EntityManagerFactory.class);
EasyMock.expect(emf.createEntityManager()).andReturn(em);
EasyMock.replay(emf);
UserSettingsService userSettingsService = new UserSettingsService();
userSettingsService.setSecurityService(securityService);
userSettingsService.setEntityManagerFactory(emf);
userSettingsService.setUserDirectoryService(userDirectoryService);
userSettingsService.addUserSetting(key, value);
assertEquals(userSettingDto.getValues().get(0).getKey(), key);
assertEquals(userSettingDto.getValues().get(0).getValue(), value);
}
use of javax.persistence.EntityManagerFactory in project opencast by opencast.
the class UserSettingsServiceTest method deleteUserSettingInputNoIdExpectsSavedSetting.
@Test
public void deleteUserSettingInputNoIdExpectsSavedSetting() throws UserSettingsServiceException {
long id = 8L;
String key = "newKey";
String oldValue = "oldValue";
UserSettingDto userSettingDto = new UserSettingDto(id, key, oldValue, securityService.getUser().getUsername(), securityService.getOrganization().getId());
LinkedList<UserSettingDto> userSettingDtos = new LinkedList<UserSettingDto>();
userSettingDtos.add(userSettingDto);
EntityTransaction tx = EasyMock.createNiceMock(EntityTransaction.class);
EasyMock.replay(tx);
Query query = EasyMock.createNiceMock(Query.class);
EasyMock.expect(query.setParameter("key", key)).andReturn(query);
EasyMock.expect(query.setParameter("username", securityService.getUser().getUsername())).andReturn(query);
EasyMock.expect(query.setParameter("org", securityService.getOrganization().getId())).andReturn(query);
EasyMock.expect(query.getResultList()).andReturn(userSettingDtos);
EasyMock.replay(query);
EntityManager em = EasyMock.createNiceMock(EntityManager.class);
EasyMock.expect(em.getTransaction()).andReturn(tx);
EasyMock.expect(em.find(UserSettingDto.class, id)).andReturn(userSettingDto);
em.remove(userSettingDto);
EasyMock.expectLastCall();
EasyMock.replay(em);
EntityManagerFactory emf = EasyMock.createNiceMock(EntityManagerFactory.class);
EasyMock.expect(emf.createEntityManager()).andReturn(em).anyTimes();
EasyMock.replay(emf);
UserSettingsService userSettingsService = new UserSettingsService();
userSettingsService.setSecurityService(securityService);
userSettingsService.setEntityManagerFactory(emf);
userSettingsService.setUserDirectoryService(userDirectoryService);
userSettingsService.deleteUserSetting(id);
}
use of javax.persistence.EntityManagerFactory in project opencast by opencast.
the class OaiPmhRepositoryPersistenceTest method oaiPmhDatabase.
private static AbstractOaiPmhDatabase oaiPmhDatabase(MediaPackage... mps) {
try {
final Organization org = new DefaultOrganization();
final SecurityService secSvc = EasyMock.createNiceMock(SecurityService.class);
// security service
final User user = createSystemUser("admin", org);
expect(secSvc.getOrganization()).andReturn(org).anyTimes();
expect(secSvc.getUser()).andReturn(user).anyTimes();
EasyMock.replay(secSvc);
// series service
final SeriesService seriesService = EasyMock.createNiceMock(SeriesService.class);
final String xacml = IOUtils.toString(OaiPmhRepositoryPersistenceTest.class.getResource("/xacml.xml").toURI());
final AccessControlList securityACL = AccessControlParser.parseAcl(xacml);
EasyMock.expect(seriesService.getSeriesAccessControl("10.0000/1")).andReturn(securityACL).anyTimes();
EasyMock.replay(seriesService);
// workspace
final Workspace workspace = EasyMock.createNiceMock(Workspace.class);
final File episodeDublinCore = new File(OaiPmhRepositoryPersistenceTest.class.getResource("/episode-dublincore.xml").toURI());
final File seriesDublinCore = new File(OaiPmhRepositoryPersistenceTest.class.getResource("/series-dublincore.xml").toURI());
expect(workspace.read(EasyMock.anyObject())).andAnswer(() -> {
final String uri = getCurrentArguments()[0].toString();
if ("dublincore.xml".equals(uri))
return new FileInputStream(episodeDublinCore);
if ("series-dublincore.xml".equals(uri))
return new FileInputStream(seriesDublinCore);
throw new Error("Workspace mock does not know about file " + uri);
}).anyTimes();
EasyMock.replay(workspace);
// oai-pmh database
final EntityManagerFactory emf = PersistenceUtil.newTestEntityManagerFactory(OaiPmhDatabaseImpl.PERSISTENCE_UNIT_NAME);
final AbstractOaiPmhDatabase db = new AbstractOaiPmhDatabase() {
@Override
public EntityManagerFactory getEmf() {
return emf;
}
@Override
public SecurityService getSecurityService() {
return secSvc;
}
@Override
public Workspace getWorkspace() {
return workspace;
}
@Override
public Date currentDate() {
return new Date();
}
};
for (MediaPackage mp : mps) db.store(mp, REPOSITORY_ID);
return db;
} catch (Exception e) {
return chuck(e);
}
}
use of javax.persistence.EntityManagerFactory in project HotswapAgent by HotswapProjects.
the class Hibernate3JPAHelper method createEntityManagerFactoryProxy.
/**
* Creates the entity manager factory proxy.
*
* @param persistenceUnitName persistent unit name
* @param properties properties to create entity manager factory
* @param original entity manager factory
* @return proxy of entity manager
*/
public static EntityManagerFactory createEntityManagerFactoryProxy(String persistenceUnitName, Map<?, ?> properties, EntityManagerFactory original) {
// ensure only once
if (wrappedPersistenceUnitNames.contains(persistenceUnitName)) {
return original;
}
wrappedPersistenceUnitNames.add(persistenceUnitName);
EntityManagerFactoryProxy wrapper = EntityManagerFactoryProxy.getWrapper(persistenceUnitName);
EntityManagerFactory proxy = wrapper.proxy(original, persistenceUnitName, null, properties);
initPlugin(original);
LOGGER.debug("Returning EntityManager proxy {} instead of EntityManager {}", proxy.getClass(), original);
return proxy;
}
Aggregations