Search in sources :

Example 1 with TranscriptionDatabase

use of org.opencastproject.transcription.ibmwatson.persistence.TranscriptionDatabase in project opencast by opencast.

the class IBMWatsonTranscriptionServiceTest method setUp.

@Before
public void setUp() throws Exception {
    MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
    URI mediaPackageURI = IBMWatsonTranscriptionServiceTest.class.getResource("/mp.xml").toURI();
    mediaPackage = builder.loadFromXml(mediaPackageURI.toURL().openStream());
    URI audioUrl = IBMWatsonTranscriptionServiceTest.class.getResource("/audio.ogg").toURI();
    audioFile = new File(audioUrl);
    Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put(IBMWatsonTranscriptionService.ENABLED_CONFIG, "true");
    props.put(IBMWatsonTranscriptionService.IBM_WATSON_USER_CONFIG, "user");
    props.put(IBMWatsonTranscriptionService.IBM_WATSON_PSW_CONFIG, "psw");
    props.put(IBMWatsonTranscriptionService.COMPLETION_CHECK_BUFFER_CONFIG, 0);
    props.put(IBMWatsonTranscriptionService.MAX_PROCESSING_TIME_CONFIG, 0);
    props.put(IBMWatsonTranscriptionService.NOTIFICATION_EMAIL_CONFIG, "anyone@opencast.org");
    ComponentContext cc = EasyMock.createNiceMock(ComponentContext.class);
    EasyMock.expect(cc.getProperties()).andReturn(props).anyTimes();
    BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
    EasyMock.expect(bc.getProperty(OpencastConstants.SERVER_URL_PROPERTY)).andReturn("http://THIS_SERVER");
    EasyMock.expect(bc.getProperty("org.opencastproject.security.digest.user")).andReturn("matterhorn_system_account");
    EasyMock.expect(cc.getBundleContext()).andReturn(bc).anyTimes();
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    Map<String, String> orgProps = new HashMap<String, String>();
    orgProps.put(IBMWatsonTranscriptionService.ADMIN_URL_PROPERTY, "http://ADMIN_SERVER");
    org = new JaxbOrganization(DefaultOrganization.DEFAULT_ORGANIZATION_ID, DefaultOrganization.DEFAULT_ORGANIZATION_NAME, null, DefaultOrganization.DEFAULT_ORGANIZATION_ADMIN, DefaultOrganization.DEFAULT_ORGANIZATION_ANONYMOUS, orgProps);
    User user = new JaxbUser("admin", null, "test", org, new JaxbRole(SecurityConstants.GLOBAL_ADMIN_ROLE, org));
    EasyMock.expect(securityService.getOrganization()).andReturn(org).anyTimes();
    EasyMock.expect(securityService.getUser()).andReturn(user).anyTimes();
    OrganizationDirectoryService orgDirectory = EasyMock.createNiceMock(OrganizationDirectoryService.class);
    EasyMock.expect(orgDirectory.getOrganization((String) EasyMock.anyObject())).andReturn(org).anyTimes();
    UserDirectoryService userDirectory = EasyMock.createNiceMock(UserDirectoryService.class);
    EasyMock.expect(userDirectory.loadUser("admin")).andReturn(user).anyTimes();
    IncidentService incident = EasyMock.createNiceMock(IncidentService.class);
    smtpService = EasyMock.createNiceMock(SmtpService.class);
    smtpService.send((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject());
    EasyMock.expectLastCall().once();
    EasyMock.replay(bc, cc, securityService, orgDirectory, userDirectory, incident, smtpService);
    // Mocks for WorkflowDispatcher test
    assetManager = EasyMock.createNiceMock(AssetManager.class);
    wfService = EasyMock.createNiceMock(WorkflowService.class);
    workspace = EasyMock.createNiceMock(Workspace.class);
    // Database
    database = new TranscriptionDatabase();
    database.setEntityManagerFactory(PersistenceUtil.newTestEntityManagerFactory("org.opencastproject.transcription.ibmwatson.persistence"));
    database.activate(null);
    httpClient = EasyMock.createNiceMock(CloseableHttpClient.class);
    service = new IBMWatsonTranscriptionService() {

        @Override
        protected CloseableHttpClient makeHttpClient() {
            return httpClient;
        }
    };
    ServiceRegistry serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectory, orgDirectory, incident);
    service.setOrganizationDirectoryService(orgDirectory);
    service.setSecurityService(securityService);
    service.setServiceRegistry(serviceRegistry);
    service.setUserDirectoryService(userDirectory);
    service.setWorkspace(workspace);
    service.setDatabase(database);
    service.setAssetManager(assetManager);
    service.setWorkflowService(wfService);
    service.setSmtpService(smtpService);
    service.activate(cc);
}
Also used : IncidentService(org.opencastproject.serviceregistry.api.IncidentService) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) HashMap(java.util.HashMap) JaxbUser(org.opencastproject.security.api.JaxbUser) TranscriptionDatabase(org.opencastproject.transcription.ibmwatson.persistence.TranscriptionDatabase) URI(java.net.URI) MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) WorkflowService(org.opencastproject.workflow.api.WorkflowService) SecurityService(org.opencastproject.security.api.SecurityService) ServiceRegistryInMemoryImpl(org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) AssetManager(org.opencastproject.assetmanager.api.AssetManager) ComponentContext(org.osgi.service.component.ComponentContext) Hashtable(java.util.Hashtable) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) SmtpService(org.opencastproject.kernel.mail.SmtpService) JaxbRole(org.opencastproject.security.api.JaxbRole) JSONObject(org.json.simple.JSONObject) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) File(java.io.File) BundleContext(org.osgi.framework.BundleContext) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 2 with TranscriptionDatabase

use of org.opencastproject.transcription.ibmwatson.persistence.TranscriptionDatabase in project opencast by opencast.

the class TranscriptionDatabaseTest method setUp.

@Before
public void setUp() throws Exception {
    database = new TranscriptionDatabase();
    database.setEntityManagerFactory(newTestEntityManagerFactory("org.opencastproject.transcription.ibmwatson.persistence"));
    database.activate(null);
}
Also used : TranscriptionDatabase(org.opencastproject.transcription.ibmwatson.persistence.TranscriptionDatabase) Before(org.junit.Before)

Aggregations

Before (org.junit.Before)2 TranscriptionDatabase (org.opencastproject.transcription.ibmwatson.persistence.TranscriptionDatabase)2 File (java.io.File)1 URI (java.net.URI)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 JSONObject (org.json.simple.JSONObject)1 AssetManager (org.opencastproject.assetmanager.api.AssetManager)1 SmtpService (org.opencastproject.kernel.mail.SmtpService)1 MediaPackageBuilder (org.opencastproject.mediapackage.MediaPackageBuilder)1 JaxbOrganization (org.opencastproject.security.api.JaxbOrganization)1 JaxbRole (org.opencastproject.security.api.JaxbRole)1 JaxbUser (org.opencastproject.security.api.JaxbUser)1 OrganizationDirectoryService (org.opencastproject.security.api.OrganizationDirectoryService)1 SecurityService (org.opencastproject.security.api.SecurityService)1 User (org.opencastproject.security.api.User)1 UserDirectoryService (org.opencastproject.security.api.UserDirectoryService)1 IncidentService (org.opencastproject.serviceregistry.api.IncidentService)1 ServiceRegistry (org.opencastproject.serviceregistry.api.ServiceRegistry)1