Search in sources :

Example 6 with ServiceRegistryInMemoryImpl

use of org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl in project opencast by opencast.

the class WorkflowStatisticsTest method setUp.

@Before
public void setUp() throws Exception {
    // always start with a fresh solr root directory
    sRoot = new File(getStorageRoot());
    try {
        FileUtils.forceMkdir(sRoot);
    } catch (IOException e) {
        Assert.fail(e.getMessage());
    }
    workflowDefinitions = new ArrayList<WorkflowDefinition>();
    workflowHandlers = new HashSet<HandlerRegistration>();
    String opId = "op";
    WorkflowOperationDefinition op = new WorkflowOperationDefinitionImpl(opId, "Pausing operation", null, true);
    WorkflowOperationHandler opHandler = new ResumableTestWorkflowOperationHandler(opId, Action.PAUSE, Action.CONTINUE);
    HandlerRegistration handler = new HandlerRegistration(opId, opHandler);
    workflowHandlers.add(handler);
    // create operation handlers for our workflows
    for (int i = 1; i <= WORKFLOW_DEFINITION_COUNT; i++) {
        WorkflowDefinition workflowDef = new WorkflowDefinitionImpl();
        workflowDef.setId("def-" + i);
        for (int opCount = 1; opCount <= OPERATION_COUNT; opCount++) {
            workflowDef.add(op);
        }
        workflowDefinitions.add(workflowDef);
    }
    // instantiate a service implementation and its DAO, overriding the methods that depend on the osgi runtime
    service = new WorkflowServiceImpl() {

        @Override
        public Set<HandlerRegistration> getRegisteredHandlers() {
            return workflowHandlers;
        }
    };
    scanner = new WorkflowDefinitionScanner();
    service.addWorkflowDefinitionScanner(scanner);
    // security service
    securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getUser()).andReturn(SecurityServiceStub.DEFAULT_ORG_ADMIN).anyTimes();
    EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
    EasyMock.replay(securityService);
    service.setSecurityService(securityService);
    AuthorizationService authzService = EasyMock.createNiceMock(AuthorizationService.class);
    EasyMock.expect(authzService.getActiveAcl((MediaPackage) EasyMock.anyObject())).andReturn(Tuple.tuple(acl, AclScope.Series)).anyTimes();
    EasyMock.replay(authzService);
    service.setAuthorizationService(authzService);
    UserDirectoryService userDirectoryService = EasyMock.createMock(UserDirectoryService.class);
    EasyMock.expect(userDirectoryService.loadUser((String) EasyMock.anyObject())).andReturn(DEFAULT_ORG_ADMIN).anyTimes();
    EasyMock.replay(userDirectoryService);
    service.setUserDirectoryService(userDirectoryService);
    Organization organization = new DefaultOrganization();
    List<Organization> organizationList = new ArrayList<Organization>();
    organizationList.add(organization);
    OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
    EasyMock.expect(organizationDirectoryService.getOrganizations()).andReturn(organizationList).anyTimes();
    EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
    EasyMock.replay(organizationDirectoryService);
    service.setOrganizationDirectoryService(organizationDirectoryService);
    MessageSender messageSender = EasyMock.createNiceMock(MessageSender.class);
    EasyMock.replay(messageSender);
    service.setMessageSender(messageSender);
    MediaPackageMetadataService mds = EasyMock.createNiceMock(MediaPackageMetadataService.class);
    EasyMock.replay(mds);
    service.addMetadataService(mds);
    // Register the workflow definitions
    for (WorkflowDefinition workflowDefinition : workflowDefinitions) {
        service.registerWorkflowDefinition(workflowDefinition);
    }
    // Mock the workspace
    workspace = EasyMock.createNiceMock(Workspace.class);
    EasyMock.expect(workspace.getCollectionContents((String) EasyMock.anyObject())).andReturn(new URI[0]);
    EasyMock.replay(workspace);
    // Mock the service registry
    ServiceRegistryInMemoryImpl serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectoryService, organizationDirectoryService, EasyMock.createNiceMock(IncidentService.class));
    // Create the workflow database (solr)
    dao = new WorkflowServiceSolrIndex();
    dao.solrRoot = sRoot + File.separator + "solr." + System.currentTimeMillis();
    dao.setSecurityService(securityService);
    dao.setServiceRegistry(serviceRegistry);
    dao.setAuthorizationService(authzService);
    dao.setOrgDirectory(organizationDirectoryService);
    dao.activate("System Admin");
    service.setDao(dao);
    service.setServiceRegistry(serviceRegistry);
    service.setSecurityService(securityService);
    service.activate(null);
    // Crate a media package
    InputStream is = null;
    try {
        MediaPackageBuilder mediaPackageBuilder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
        mediaPackageBuilder.setSerializer(new DefaultMediaPackageSerializerImpl(new File("target/test-classes")));
        is = WorkflowStatisticsTest.class.getResourceAsStream("/mediapackage-1.xml");
        mediaPackage = mediaPackageBuilder.loadFromXml(is);
        IOUtils.closeQuietly(is);
        Assert.assertNotNull(mediaPackage.getIdentifier());
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
    // Register the workflow service with the service registry
    serviceRegistry.registerService(service);
}
Also used : IncidentService(org.opencastproject.serviceregistry.api.IncidentService) Set(java.util.Set) HashSet(java.util.HashSet) Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) MessageSender(org.opencastproject.message.broker.api.MessageSender) ArrayList(java.util.ArrayList) MediaPackageMetadataService(org.opencastproject.metadata.api.MediaPackageMetadataService) DefaultMediaPackageSerializerImpl(org.opencastproject.mediapackage.DefaultMediaPackageSerializerImpl) MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) SecurityService(org.opencastproject.security.api.SecurityService) WorkflowOperationHandler(org.opencastproject.workflow.api.WorkflowOperationHandler) ServiceRegistryInMemoryImpl(org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl) HandlerRegistration(org.opencastproject.workflow.impl.WorkflowServiceImpl.HandlerRegistration) WorkflowDefinitionImpl(org.opencastproject.workflow.api.WorkflowDefinitionImpl) InputStream(java.io.InputStream) WorkflowDefinition(org.opencastproject.workflow.api.WorkflowDefinition) WorkflowOperationDefinition(org.opencastproject.workflow.api.WorkflowOperationDefinition) IOException(java.io.IOException) IOException(java.io.IOException) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) WorkflowOperationDefinitionImpl(org.opencastproject.workflow.api.WorkflowOperationDefinitionImpl) AuthorizationService(org.opencastproject.security.api.AuthorizationService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) File(java.io.File) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 7 with ServiceRegistryInMemoryImpl

use of org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl in project opencast by opencast.

the class WorkflowOperationSkippingTest method setUp.

@Before
public void setUp() throws Exception {
    sRoot = new File(getStorageRoot());
    try {
        FileUtils.forceMkdir(sRoot);
    } catch (IOException e) {
        Assert.fail(e.getMessage());
    }
    // create operation handlers for our workflows
    succeedingOperationHandler = new SucceedingWorkflowOperationHandler(mediapackage1);
    handlerRegistrations = new HashSet<HandlerRegistration>();
    handlerRegistrations.add(new HandlerRegistration("op1", succeedingOperationHandler));
    handlerRegistrations.add(new HandlerRegistration("op2", succeedingOperationHandler));
    // instantiate a service implementation and its DAO, overriding the methods that depend on the osgi runtime
    service = new WorkflowServiceImpl() {

        @Override
        public Set<HandlerRegistration> getRegisteredHandlers() {
            return handlerRegistrations;
        }
    };
    scanner = new WorkflowDefinitionScanner();
    service.addWorkflowDefinitionScanner(scanner);
    MediaPackageMetadataService mds = EasyMock.createNiceMock(MediaPackageMetadataService.class);
    EasyMock.replay(mds);
    service.addMetadataService(mds);
    workspace = EasyMock.createNiceMock(Workspace.class);
    EasyMock.expect(workspace.getCollectionContents((String) EasyMock.anyObject())).andReturn(new URI[0]);
    EasyMock.replay(workspace);
    // security service
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getUser()).andReturn(SecurityServiceStub.DEFAULT_ORG_ADMIN).anyTimes();
    EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
    EasyMock.replay(securityService);
    service.setSecurityService(securityService);
    UserDirectoryService userDirectoryService = EasyMock.createMock(UserDirectoryService.class);
    EasyMock.expect(userDirectoryService.loadUser((String) EasyMock.anyObject())).andReturn(DEFAULT_ORG_ADMIN).anyTimes();
    EasyMock.replay(userDirectoryService);
    service.setUserDirectoryService(userDirectoryService);
    Organization organization = new DefaultOrganization();
    List<Organization> organizationList = new ArrayList<Organization>();
    organizationList.add(organization);
    OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
    EasyMock.expect(organizationDirectoryService.getOrganizations()).andReturn(organizationList).anyTimes();
    EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
    EasyMock.replay(organizationDirectoryService);
    service.setOrganizationDirectoryService(organizationDirectoryService);
    ServiceRegistryInMemoryImpl serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectoryService, organizationDirectoryService, EasyMock.createNiceMock(IncidentService.class));
    dao = new WorkflowServiceSolrIndex();
    dao.solrRoot = sRoot + File.separator + "solr." + System.currentTimeMillis();
    MessageSender messageSender = EasyMock.createNiceMock(MessageSender.class);
    EasyMock.replay(messageSender);
    AuthorizationService authzService = EasyMock.createNiceMock(AuthorizationService.class);
    EasyMock.expect(authzService.getActiveAcl((MediaPackage) EasyMock.anyObject())).andReturn(Tuple.tuple(acl, AclScope.Series)).anyTimes();
    EasyMock.replay(authzService);
    service.setAuthorizationService(authzService);
    dao.setServiceRegistry(serviceRegistry);
    dao.setSecurityService(securityService);
    dao.setAuthorizationService(authzService);
    dao.setOrgDirectory(organizationDirectoryService);
    dao.activate("System Admin");
    service.setDao(dao);
    service.setServiceRegistry(serviceRegistry);
    service.setMessageSender(messageSender);
    service.setUserDirectoryService(userDirectoryService);
    service.activate(null);
    InputStream is = null;
    try {
        is = WorkflowOperationSkippingTest.class.getResourceAsStream("/workflow-definition-skipping.xml");
        workingDefinition = WorkflowParser.parseWorkflowDefinition(is);
        service.registerWorkflowDefinition(workingDefinition);
        IOUtils.closeQuietly(is);
        MediaPackageBuilder mediaPackageBuilder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
        mediaPackageBuilder.setSerializer(new DefaultMediaPackageSerializerImpl(new File("target/test-classes")));
        is = WorkflowOperationSkippingTest.class.getResourceAsStream("/mediapackage-1.xml");
        mediapackage1 = mediaPackageBuilder.loadFromXml(is);
        IOUtils.closeQuietly(is);
        Assert.assertNotNull(mediapackage1.getIdentifier());
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}
Also used : IncidentService(org.opencastproject.serviceregistry.api.IncidentService) Set(java.util.Set) HashSet(java.util.HashSet) Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) MessageSender(org.opencastproject.message.broker.api.MessageSender) MediaPackageMetadataService(org.opencastproject.metadata.api.MediaPackageMetadataService) ArrayList(java.util.ArrayList) DefaultMediaPackageSerializerImpl(org.opencastproject.mediapackage.DefaultMediaPackageSerializerImpl) MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) SecurityService(org.opencastproject.security.api.SecurityService) ServiceRegistryInMemoryImpl(org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl) HandlerRegistration(org.opencastproject.workflow.impl.WorkflowServiceImpl.HandlerRegistration) InputStream(java.io.InputStream) IOException(java.io.IOException) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) IOException(java.io.IOException) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) AuthorizationService(org.opencastproject.security.api.AuthorizationService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) File(java.io.File) Workspace(org.opencastproject.workspace.api.Workspace) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) Before(org.junit.Before)

Example 8 with ServiceRegistryInMemoryImpl

use of org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl in project opencast by opencast.

the class DownloadDistributionServiceImplTest method setUp.

@Before
public void setUp() throws Exception {
    final File mediaPackageRoot = new File(getClass().getResource("/mediapackage.xml").toURI()).getParentFile();
    mp = MediaPackageParser.getFromXml(IOUtils.toString(getClass().getResourceAsStream("/mediapackage.xml"), "UTF-8"));
    distributionRoot = new File(mediaPackageRoot, "static");
    service = new DownloadDistributionServiceImpl();
    StatusLine statusLine = EasyMock.createNiceMock(StatusLine.class);
    EasyMock.expect(statusLine.getStatusCode()).andReturn(HttpServletResponse.SC_OK).anyTimes();
    EasyMock.replay(statusLine);
    HttpResponse response = EasyMock.createNiceMock(HttpResponse.class);
    EasyMock.expect(response.getStatusLine()).andReturn(statusLine).anyTimes();
    EasyMock.replay(response);
    final TrustedHttpClient httpClient = EasyMock.createNiceMock(TrustedHttpClient.class);
    EasyMock.expect(httpClient.execute((HttpUriRequest) EasyMock.anyObject())).andReturn(response).anyTimes();
    EasyMock.expect(httpClient.run((HttpUriRequest) EasyMock.anyObject())).andAnswer(new IAnswer<Function<Function<HttpResponse, Object>, Either<Exception, Object>>>() {

        @Override
        public Function<Function<HttpResponse, Object>, Either<Exception, Object>> answer() throws Throwable {
            HttpUriRequest req = (HttpUriRequest) EasyMock.getCurrentArguments()[0];
            return StandAloneTrustedHttpClientImpl.run(httpClient, req);
        }
    }).anyTimes();
    EasyMock.replay(httpClient);
    defaultOrganization = new DefaultOrganization();
    User anonymous = new JaxbUser("anonymous", "test", defaultOrganization, new JaxbRole(DefaultOrganization.DEFAULT_ORGANIZATION_ANONYMOUS, defaultOrganization));
    UserDirectoryService userDirectoryService = EasyMock.createMock(UserDirectoryService.class);
    EasyMock.expect(userDirectoryService.loadUser((String) EasyMock.anyObject())).andReturn(anonymous).anyTimes();
    EasyMock.replay(userDirectoryService);
    service.setUserDirectoryService(userDirectoryService);
    Organization organization = new DefaultOrganization();
    OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
    EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
    EasyMock.replay(organizationDirectoryService);
    service.setOrganizationDirectoryService(organizationDirectoryService);
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getUser()).andReturn(anonymous).anyTimes();
    EasyMock.expect(securityService.getOrganization()).andReturn(organization).anyTimes();
    EasyMock.replay(securityService);
    service.setSecurityService(securityService);
    serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectoryService, organizationDirectoryService, EasyMock.createNiceMock(IncidentService.class));
    service.setServiceRegistry(serviceRegistry);
    service.setTrustedHttpClient(httpClient);
    final Workspace workspace = EasyMock.createNiceMock(Workspace.class);
    service.setWorkspace(workspace);
    EasyMock.expect(workspace.get((URI) EasyMock.anyObject())).andAnswer(new IAnswer<File>() {

        @Override
        public File answer() throws Throwable {
            final URI uri = (URI) EasyMock.getCurrentArguments()[0];
            final String[] pathElems = uri.getPath().split("/");
            final String file = pathElems[pathElems.length - 1];
            return new File(mediaPackageRoot, file);
        }
    }).anyTimes();
    EasyMock.replay(workspace);
    BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
    EasyMock.expect(bc.getProperty("org.opencastproject.download.directory")).andReturn(distributionRoot.toString()).anyTimes();
    EasyMock.expect(bc.getProperty("org.opencastproject.download.url")).andReturn(UrlSupport.DEFAULT_BASE_URL).anyTimes();
    ComponentContext cc = EasyMock.createNiceMock(ComponentContext.class);
    Dictionary<String, Object> p = new Hashtable<String, Object>();
    p.put(DistributionService.CONFIG_KEY_STORE_TYPE, "download");
    EasyMock.expect(cc.getProperties()).andReturn(p).anyTimes();
    EasyMock.expect(cc.getBundleContext()).andReturn(bc).anyTimes();
    EasyMock.replay(bc, cc);
    service.activate(cc);
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) JaxbUser(org.opencastproject.security.api.JaxbUser) URI(java.net.URI) Function(org.opencastproject.util.data.Function) SecurityService(org.opencastproject.security.api.SecurityService) Either(org.opencastproject.util.data.Either) ServiceRegistryInMemoryImpl(org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl) TrustedHttpClient(org.opencastproject.security.api.TrustedHttpClient) ComponentContext(org.osgi.service.component.ComponentContext) Hashtable(java.util.Hashtable) HttpResponse(org.apache.http.HttpResponse) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) StatusLine(org.apache.http.StatusLine) IAnswer(org.easymock.IAnswer) JaxbRole(org.opencastproject.security.api.JaxbRole) File(java.io.File) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) Workspace(org.opencastproject.workspace.api.Workspace) BundleContext(org.osgi.framework.BundleContext) Before(org.junit.Before)

Example 9 with ServiceRegistryInMemoryImpl

use of org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl in project opencast by opencast.

the class OaiPmhPublicationServiceImplTest method setUp.

@Before
public void setUp() throws Exception {
    mp = MediaPackageSupport.loadFromClassPath("/mediapackage.xml");
    mp2 = MediaPackageSupport.loadFromClassPath("/mediapackage2.xml");
    validOaiPmhRepositories = Collections.list("default");
    OaiPmhServerInfo oaiPmhServerInfo = EasyMock.createNiceMock(OaiPmhServerInfo.class);
    EasyMock.expect(oaiPmhServerInfo.hasRepo(anyString())).andAnswer(() -> validOaiPmhRepositories.contains((String) EasyMock.getCurrentArguments()[0])).anyTimes();
    EasyMock.expect(oaiPmhServerInfo.getMountPoint()).andReturn(OAI_PMH_SERVER_MOUNT_POINT).anyTimes();
    DefaultOrganization org = new DefaultOrganization() {

        @Override
        public Map<String, String> getProperties() {
            HashMap<String, String> props = new HashMap<>();
            props.putAll(DEFAULT_PROPERTIES);
            props.put(ORG_CFG_OAIPMH_SERVER_HOSTURL, OAI_PMH_SERVER_URL);
            return props;
        }
    };
    HashSet<JaxbRole> roles = new HashSet<JaxbRole>();
    roles.add(new JaxbRole(DefaultOrganization.DEFAULT_ORGANIZATION_ADMIN, org, ""));
    User user = new JaxbUser("admin", "test", org, roles);
    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();
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getOrganization()).andReturn(org).anyTimes();
    EasyMock.expect(securityService.getUser()).andReturn(user).anyTimes();
    serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectory, orgDirectory, EasyMock.createNiceMock(IncidentService.class));
    // Finish setting up the mocks
    EasyMock.replay(oaiPmhServerInfo, orgDirectory, userDirectory, securityService);
    service = new OaiPmhPublicationServiceImpl();
    service.setOaiPmhServerInfo(oaiPmhServerInfo);
    service.setSecurityService(securityService);
    service.setServiceRegistry(serviceRegistry);
    // mock streaming/download distribution jobs dispatching
    AbstractJobProducer distributionJobProducerMock = new AbstractJobProducer("distribute") {

        @Override
        protected ServiceRegistry getServiceRegistry() {
            return serviceRegistry;
        }

        @Override
        protected SecurityService getSecurityService() {
            return securityService;
        }

        @Override
        protected UserDirectoryService getUserDirectoryService() {
            return userDirectory;
        }

        @Override
        protected OrganizationDirectoryService getOrganizationDirectoryService() {
            return orgDirectory;
        }

        @Override
        protected String process(Job job) throws Exception {
            return job.getPayload();
        }

        @Override
        public boolean isReadyToAccept(Job job) throws ServiceRegistryException, UndispatchableJobException {
            return true;
        }
    };
    serviceRegistry.registerService(distributionJobProducerMock);
}
Also used : User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) HashMap(java.util.HashMap) JaxbUser(org.opencastproject.security.api.JaxbUser) EasyMock.anyString(org.easymock.EasyMock.anyString) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) OaiPmhServerInfo(org.opencastproject.oaipmh.server.OaiPmhServerInfo) JaxbRole(org.opencastproject.security.api.JaxbRole) AbstractJobProducer(org.opencastproject.job.api.AbstractJobProducer) SecurityService(org.opencastproject.security.api.SecurityService) Job(org.opencastproject.job.api.Job) ServiceRegistryInMemoryImpl(org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) HashSet(java.util.HashSet) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) Before(org.junit.Before)

Example 10 with ServiceRegistryInMemoryImpl

use of org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl 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)

Aggregations

ServiceRegistryInMemoryImpl (org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl)19 Before (org.junit.Before)18 OrganizationDirectoryService (org.opencastproject.security.api.OrganizationDirectoryService)18 SecurityService (org.opencastproject.security.api.SecurityService)18 UserDirectoryService (org.opencastproject.security.api.UserDirectoryService)18 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)17 File (java.io.File)15 Organization (org.opencastproject.security.api.Organization)14 Workspace (org.opencastproject.workspace.api.Workspace)14 JaxbRole (org.opencastproject.security.api.JaxbRole)11 JaxbUser (org.opencastproject.security.api.JaxbUser)11 User (org.opencastproject.security.api.User)11 MediaPackageBuilder (org.opencastproject.mediapackage.MediaPackageBuilder)10 AuthorizationService (org.opencastproject.security.api.AuthorizationService)10 IncidentService (org.opencastproject.serviceregistry.api.IncidentService)10 InputStream (java.io.InputStream)9 HashSet (java.util.HashSet)9 MediaPackage (org.opencastproject.mediapackage.MediaPackage)9 URI (java.net.URI)8 ArrayList (java.util.ArrayList)8