Search in sources :

Example 81 with EntityManagerFactory

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);
}
Also used : EntityManagerFactory(javax.persistence.EntityManagerFactory) Test(org.junit.Test)

Example 82 with EntityManagerFactory

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);
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) EntityManagerFactory(javax.persistence.EntityManagerFactory) UserSettingDto(org.opencastproject.adminui.usersettings.persistence.UserSettingDto) Capture(org.easymock.Capture) Test(org.junit.Test)

Example 83 with EntityManagerFactory

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);
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) EntityManagerFactory(javax.persistence.EntityManagerFactory) UserSettingDto(org.opencastproject.adminui.usersettings.persistence.UserSettingDto) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 84 with EntityManagerFactory

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);
    }
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) AbstractOaiPmhDatabase(org.opencastproject.oaipmh.persistence.impl.AbstractOaiPmhDatabase) Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) User(org.opencastproject.security.api.User) SecurityUtil.createSystemUser(org.opencastproject.security.util.SecurityUtil.createSystemUser) FileInputStream(java.io.FileInputStream) Date(java.util.Date) EncodingSchemeUtils.encodeDate(org.opencastproject.metadata.dublincore.EncodingSchemeUtils.encodeDate) TransformerException(javax.xml.transform.TransformerException) SeriesService(org.opencastproject.series.api.SeriesService) SecurityService(org.opencastproject.security.api.SecurityService) EntityManagerFactory(javax.persistence.EntityManagerFactory) MediaPackage(org.opencastproject.mediapackage.MediaPackage) File(java.io.File) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Workspace(org.opencastproject.workspace.api.Workspace)

Example 85 with EntityManagerFactory

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;
}
Also used : EntityManagerFactoryProxy(org.hotswap.agent.plugin.hibernate3.jpa.proxy.EntityManagerFactoryProxy) EntityManagerFactory(javax.persistence.EntityManagerFactory)

Aggregations

EntityManagerFactory (javax.persistence.EntityManagerFactory)302 EntityManager (javax.persistence.EntityManager)103 Test (org.junit.Test)90 HashMap (java.util.HashMap)48 EntityTransaction (javax.persistence.EntityTransaction)30 EJBException (javax.ejb.EJBException)22 Map (java.util.Map)17 AssertionFailedError (junit.framework.AssertionFailedError)17 TestFailureException (org.apache.openejb.test.TestFailureException)17 ArrayList (java.util.ArrayList)15 JMSException (javax.jms.JMSException)15 KieSession (org.kie.api.runtime.KieSession)14 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)14 Properties (java.util.Properties)13 InitialContext (javax.naming.InitialContext)13 List (java.util.List)12 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)12 RemoteException (java.rmi.RemoteException)11 Query (javax.persistence.Query)11 PrintWriter (java.io.PrintWriter)10