当前位置: 首页>>代码示例>>Java>>正文


Java Runtime.getModule方法代码示例

本文整理汇总了Java中org.jboss.gravia.runtime.Runtime.getModule方法的典型用法代码示例。如果您正苦于以下问题:Java Runtime.getModule方法的具体用法?Java Runtime.getModule怎么用?Java Runtime.getModule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jboss.gravia.runtime.Runtime的用法示例。


在下文中一共展示了Runtime.getModule方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testServletAccess

import org.jboss.gravia.runtime.Runtime; //导入方法依赖的package包/类
@Test
public void testServletAccess() throws Exception {

    Runtime runtime = RuntimeLocator.getRequiredRuntime();
    Module module = runtime.getModule(getClass().getClassLoader());
    HttpService httpService = ServiceLocator.getRequiredService(HttpService.class);

    // Verify that the alias is not yet available
    String reqspec = "/fabric8/service?test=param&param=Kermit";
    assertNotAvailable(reqspec);

    // Register the test servlet and make a call
    httpService.registerServlet("/service", new HttpServiceServlet(module), null, null);
    Assert.assertEquals("Hello: Kermit", performCall(reqspec));

    // Unregister the servlet alias
    httpService.unregister("/service");
    assertNotAvailable(reqspec);

    // Verify that the alias is not available any more
    assertNotAvailable(reqspec);
}
 
开发者ID:tdiesler,项目名称:fabric8poc,代码行数:23,代码来源:HttpServiceTestBase.java

示例2: testStreamResource

import org.jboss.gravia.runtime.Runtime; //导入方法依赖的package包/类
/**
 * Provision a resource from an input stream.
 *
 * The client controlls the resource identity
 * The installed resource is self sufficient - no additional dependency mapping needed.
 */
@Test
public void testStreamResource() throws Exception {

    Provisioner provisioner = ServiceLocator.getRequiredService(Provisioner.class);

    ResourceIdentity identityA = ResourceIdentity.fromString(RESOURCE_A);
    ResourceBuilder builderA = provisioner.getContentResourceBuilder(identityA, deployer.getDeployment(RESOURCE_A));
    Resource resourceA = builderA.getResource();

    ResourceHandle handle = provisioner.installResource(resourceA);
    try {
        // Verify that the module got installed
        Runtime runtime = RuntimeLocator.getRequiredRuntime();
        Module module = runtime.getModule(identityA);
        Assert.assertNotNull("Module not null", module);
        Assert.assertEquals("ACTIVE " + module, State.ACTIVE, module.getState());

        // Verify that the module activator was called
        MBeanServer server = ServiceLocator.getRequiredService(MBeanServer.class);
        Assert.assertTrue("MBean registered", server.isRegistered(getObjectName(module)));
        Assert.assertEquals("ACTIVE", server.getAttribute(getObjectName(module), "ModuleState"));
    } finally {
        handle.uninstall();
    }
}
 
开发者ID:tdiesler,项目名称:fabric8poc,代码行数:32,代码来源:ProvisionerTest.java

示例3: testModuleLifecycle

import org.jboss.gravia.runtime.Runtime; //导入方法依赖的package包/类
@Test
public void testModuleLifecycle() throws Exception {

    Runtime runtime = RuntimeLocator.getRequiredRuntime();
    Module modA = runtime.getModule(getClass().getClassLoader());
    Assert.assertEquals(Module.State.ACTIVE, modA.getState());

    ModuleContext context = modA.getModuleContext();
    ServiceRegistration<String> sreg = context.registerService(String.class, new String("Hello"), null);
    Assert.assertNotNull("Null sreg", sreg);

    String service = context.getService(sreg.getReference());
    Assert.assertEquals("Hello", service);

    modA.stop();
    Assert.assertEquals(Module.State.INSTALLED, modA.getState());

    modA.uninstall();
    Assert.assertEquals(Module.State.UNINSTALLED, modA.getState());
}
 
开发者ID:tdiesler,项目名称:gravia,代码行数:21,代码来源:WebappBundleModuleLifecycleTest.java

示例4: testBasicModule

import org.jboss.gravia.runtime.Runtime; //导入方法依赖的package包/类
@Test
public void testBasicModule() throws Exception {

    Runtime runtime = RuntimeLocator.getRequiredRuntime();
    Module module = runtime.getModule(getClass().getClassLoader());

    ModuleContext ctxA = module.getModuleContext();
    ServiceReference<ServiceD> srefD = ctxA.getServiceReference(ServiceD.class);
    Assert.assertNotNull("ServiceReference not null", srefD);

    ServiceD srvD = ctxA.getService(srefD);
    Assert.assertEquals("ServiceD#1:ServiceD1#1:null:Hello", srvD.doStuff("Hello"));

    ConfigurationAdmin configAdmin = getConfigurationAdmin(module);
    Configuration config = configAdmin.getConfiguration(ServiceD1.class.getName());
    Assert.assertNotNull("Config not null", config);
    Assert.assertNull("Config is empty, but was: " + config.getProperties(), config.getProperties());

    Dictionary<String, String> configProps = new Hashtable<String, String>();
    configProps.put("foo", "bar");
    config.update(configProps);

    ServiceD1 srvD1 = srvD.getServiceD1();
    Assert.assertTrue(srvD1.awaitModified(4000, TimeUnit.MILLISECONDS));

    Assert.assertEquals("ServiceD#1:ServiceD1#1:bar:Hello", srvD.doStuff("Hello"));
}
 
开发者ID:tdiesler,项目名称:gravia,代码行数:28,代码来源:ConfigurationAdminTest.java

示例5: testModuleLifecycle

import org.jboss.gravia.runtime.Runtime; //导入方法依赖的package包/类
@Test
public void testModuleLifecycle() throws Exception {

    Runtime runtime = RuntimeLocator.getRequiredRuntime();
    Module modA = runtime.getModule(getClass().getClassLoader());
    Assert.assertEquals(Module.State.ACTIVE, modA.getState());

    String symbolicName = modA.getHeaders().get("Bundle-SymbolicName");
    Assert.assertEquals("simple-bundle", symbolicName);

    ModuleContext context = modA.getModuleContext();
    Module sysmodule = runtime.getModule(0);
    symbolicName = sysmodule.getHeaders().get("Bundle-SymbolicName");
    Assert.assertNotNull("System bundle symbolic name not null", symbolicName);

    ServiceReference<String> sref = context.getServiceReference(String.class);
    String service = context.getService(sref);
    Assert.assertEquals("Hello", service);

    modA.stop();
    Assert.assertEquals(Module.State.INSTALLED, modA.getState());

    modA.uninstall();
    Assert.assertEquals(Module.State.UNINSTALLED, modA.getState());

    try {
        modA.start();
        Assert.fail("IllegalStateException expected");
    } catch (IllegalStateException ex) {
        // expected
    }
}
 
开发者ID:tdiesler,项目名称:gravia,代码行数:33,代码来源:BundleLifecycleTest.java

示例6: testLogService

import org.jboss.gravia.runtime.Runtime; //导入方法依赖的package包/类
@Test
public void testLogService() throws Exception {
    Runtime runtime = RuntimeLocator.getRequiredRuntime();
    Module module = runtime.getModule(getClass().getClassLoader());

    LogService log = getLogService(module.getModuleContext());
    String msg = "LogServiceTest LogService ";
    log.log(LogService.LOG_ERROR, msg + " ERROR");
    log.log(LogService.LOG_WARNING, msg + " WARNING");
    log.log(LogService.LOG_INFO, msg + " INFO");
    log.log(LogService.LOG_DEBUG, msg + " DEBUG");
}
 
开发者ID:tdiesler,项目名称:gravia,代码行数:13,代码来源:LogServiceTest.java

示例7: testModuleLifecycle

import org.jboss.gravia.runtime.Runtime; //导入方法依赖的package包/类
@Test
public void testModuleLifecycle() throws Exception {

    // Verify that the Runtime service is registered
    Runtime runtime = ServiceLocator.getRequiredService(Runtime.class);

    Module modA = runtime.getModule(getClass().getClassLoader());
    Assert.assertEquals(Module.State.ACTIVE, modA.getState());

    String symbolicName = modA.getHeaders().get("Bundle-SymbolicName");
    Assert.assertEquals("simple-module", symbolicName);

    ModuleContext context = modA.getModuleContext();
    Module sysmodule = runtime.getModule(0);
    symbolicName = sysmodule.getHeaders().get("Bundle-SymbolicName");
    Assert.assertNotNull("System bundle symbolic name not null", symbolicName);

    ServiceReference<String> sref = context.getServiceReference(String.class);
    String service = context.getService(sref);
    Assert.assertEquals("Hello", service);

    modA.stop();
    Assert.assertEquals(Module.State.INSTALLED, modA.getState());

    modA.uninstall();
    Assert.assertEquals(Module.State.UNINSTALLED, modA.getState());

    try {
        modA.start();
        Assert.fail("IllegalStateException expected");
    } catch (IllegalStateException ex) {
        // expected
    }
}
 
开发者ID:tdiesler,项目名称:gravia,代码行数:35,代码来源:ModuleLifecycleTest.java

示例8: testServiceAvailability

import org.jboss.gravia.runtime.Runtime; //导入方法依赖的package包/类
@Test
public void testServiceAvailability() throws Exception {

    Runtime runtime = RuntimeLocator.getRequiredRuntime();
    Module modA = runtime.getModule(getClass().getClassLoader());

    ModuleContext ctxA = modA.getModuleContext();
    ServiceReference<ServiceA> srefA = ctxA.getServiceReference(ServiceA.class);
    Assert.assertNotNull("ServiceReference not null", srefA);

    ServiceA srvA = ctxA.getService(srefA);
    Assert.assertEquals("ServiceA#1:ServiceA1#1:Hello", srvA.doStuff("Hello"));

    assertDisableComponent(ctxA, srvA);
}
 
开发者ID:tdiesler,项目名称:gravia,代码行数:16,代码来源:ServiceComponentTest.java

示例9: mappedModule

import org.jboss.gravia.runtime.Runtime; //导入方法依赖的package包/类
private Module mappedModule(Bundle bundle) {
    Module result = null;
    if (bundle != null) {
        Runtime runtime = RuntimeLocator.getRequiredRuntime();
        result = runtime.getModule(bundle.getBundleId());
    }
    return result;
}
 
开发者ID:tdiesler,项目名称:gravia,代码行数:9,代码来源:BundleContextAdaptor.java

示例10: testBasicModule

import org.jboss.gravia.runtime.Runtime; //导入方法依赖的package包/类
@Test
public void testBasicModule() throws Exception {

    Bundle bundleD = bundleContext.installBundle(BUNDLE_D, deployer.getDeployment(BUNDLE_D));
    Bundle bundleD1 = bundleContext.installBundle(BUNDLE_D1, deployer.getDeployment(BUNDLE_D1));

    bundleD.start();
    bundleD1.start();

    Runtime runtime = RuntimeLocator.getRequiredRuntime();
    Module modD = runtime.getModule(bundleD.getBundleId());
    Module modD1 = runtime.getModule(bundleD1.getBundleId());

    ModuleContext ctxD = modD.getModuleContext();
    ServiceReference<ServiceD> srefA = ctxD.getServiceReference(ServiceD.class);
    Assert.assertNotNull("ServiceReference not null", srefA);

    ServiceD srvD = ctxD.getService(srefA);
    Assert.assertEquals("ServiceD#1:ServiceD1#1:null:Hello", srvD.doStuff("Hello"));

    ConfigurationAdmin configAdmin = getConfigurationAdmin(modD1);
    Configuration config = configAdmin.getConfiguration(ServiceD1.class.getName());
    Assert.assertNotNull("Config not null", config);
    Assert.assertNull("Config is empty, but was: " + config.getProperties(), config.getProperties());

    Dictionary<String, String> configProps = new Hashtable<String, String>();
    configProps.put("foo", "bar");
    config.update(configProps);

    ServiceD1 srvD1 = srvD.getServiceD1();
    Assert.assertTrue(srvD1.awaitModified(4000, TimeUnit.MILLISECONDS));

    Assert.assertEquals("ServiceD#1:ServiceD1#1:bar:Hello", srvD.doStuff("Hello"));
}
 
开发者ID:tdiesler,项目名称:gravia,代码行数:35,代码来源:ConfigurationAdminTest.java

示例11: contextInitialized

import org.jboss.gravia.runtime.Runtime; //导入方法依赖的package包/类
/**
 * Installs/starts the webapp as a module.
 */
@Override
public void contextInitialized(ServletContextEvent event) {

    Runtime runtime = RuntimeLocator.getRequiredRuntime();
    ServletContext servletContext = event.getServletContext();
    Module module = runtime.getModule(servletContext.getClassLoader());

    // Install the module
    if (module == null) {
        module = installWebappModule(servletContext);
    }

    // Start the module
    if (module != null) {
        servletContext.setAttribute(Module.class.getName(), module);

        try {
            module.start();
        } catch (ModuleException ex) {
            throw new IllegalStateException(ex);
        }

        // HttpService integration
        BundleContext bundleContext = module.adapt(Bundle.class).getBundleContext();
        servletContext.setAttribute(BundleContext.class.getName(), bundleContext);
    }
}
 
开发者ID:tdiesler,项目名称:gravia,代码行数:31,代码来源:WebAppContextListener.java

示例12: testStreamResource

import org.jboss.gravia.runtime.Runtime; //导入方法依赖的package包/类
/**
 * @see ProvisionerTest#testStreamResource()
 */
@Test
public void testStreamResource() throws Exception {

    ContainerManager cntManager = ContainerManagerLocator.getContainerManager();
    ProfileManager prfManager = ProfileManagerLocator.getProfileManager();
    Provisioner provisioner = ServiceLocator.getRequiredService(Provisioner.class);

    // Build the resitem
    ResourceIdentity identityA = ResourceIdentity.fromString(RESOURCE_A);
    ResourceBuilder builderA = provisioner.getContentResourceBuilder(identityA, getDeployment(RESOURCE_A));
    Resource resourceA = builderA.getResource();

    // Build a profile
    ProfileIdentity idFoo = ProfileIdentity.createFrom("foo");
    Profile prfFoo = ProfileBuilder.Factory.create(idFoo)
            .profileVersion(DEFAULT_PROFILE_VERSION)
            .addResourceItem(resourceA)
            .getProfile();

    // Add the profile and verify the item URL
    prfFoo = prfManager.addProfile(DEFAULT_PROFILE_VERSION, prfFoo);
    Assert.assertEquals(1, prfFoo.getProfileItems(ResourceItem.class).size());
    ResourceItem itemA = prfFoo.getProfileItem(identityA);
    Assert.assertEquals("profile://1.0.0/foo/resitemA?version=0.0.0", getItemURL(itemA, 0).toExternalForm());
    Assert.assertNotNull("URL stream not null", new URL("profile://1.0.0/foo/resitemA").openStream());
    Assert.assertNotNull("URL stream not null", getItemURL(itemA, 0).openStream());

    // Add the profile to the current coontainer
    Container cnt = cntManager.getCurrentContainer();
    cntManager.addProfiles(cnt.getIdentity(), Collections.singletonList(idFoo), null);

    // Verify that the module got installed
    Runtime runtime = RuntimeLocator.getRequiredRuntime();
    Module moduleA = runtime.getModule(identityA);
    Assert.assertNotNull("Module not null", moduleA);
    Assert.assertEquals(State.ACTIVE, moduleA.getState());

    // Verify that the module activator was called
    MBeanServer server = ServiceLocator.getRequiredService(MBeanServer.class);
    Assert.assertTrue("MBean registered", server.isRegistered(getObjectName(moduleA)));
    Assert.assertEquals("ACTIVE" + moduleA, "ACTIVE", server.getAttribute(getObjectName(moduleA), "ModuleState"));

    cntManager.removeProfiles(cnt.getIdentity(), Collections.singletonList(idFoo), null);
    prfManager.removeProfile(DEFAULT_PROFILE_VERSION, idFoo);
}
 
开发者ID:tdiesler,项目名称:fabric8poc,代码行数:49,代码来源:ResourceItemTestBase.java

示例13: testSharedStreamResource

import org.jboss.gravia.runtime.Runtime; //导入方法依赖的package包/类
/**
 * @see ProvisionerTest#testSharedStreamResource()
 */
@Test
public void testSharedStreamResource() throws Exception {

    ContainerManager cntManager = ContainerManagerLocator.getContainerManager();
    ProfileManager prfManager = ProfileManagerLocator.getProfileManager();
    Provisioner provisioner = ServiceLocator.getRequiredService(Provisioner.class);

    // Build the resources
    ResourceIdentity identityB = ResourceIdentity.fromString(RESOURCE_B);
    ResourceBuilder builderB = provisioner.getContentResourceBuilder(identityB, getDeployment(RESOURCE_B));
    Resource resourceB = builderB.getResource();

    ResourceIdentity identityB1 = ResourceIdentity.fromString(RESOURCE_B1);
    ResourceBuilder builderB1 = provisioner.getContentResourceBuilder(identityB1, getDeployment(RESOURCE_B1));
    Resource resourceB1 = builderB1.getResource();

    // Build a profile
    ProfileIdentity idFoo = ProfileIdentity.createFrom("foo");
    Profile prfFoo = ProfileBuilder.Factory.create(idFoo)
            .profileVersion(DEFAULT_PROFILE_VERSION)
            .addSharedResourceItem(resourceB)
            .addResourceItem(resourceB1)
            .getProfile();

    // Add the profile and verify the item URL
    prfFoo = prfManager.addProfile(DEFAULT_PROFILE_VERSION, prfFoo);
    Assert.assertEquals(2, prfFoo.getProfileItems(ResourceItem.class).size());
    ResourceItem itemB = prfFoo.getProfileItem(identityB);
    Assert.assertEquals("profile://1.0.0/foo/resitemB?version=0.0.0", getItemURL(itemB, 0).toExternalForm());
    Assert.assertNotNull("URL stream not null", new URL("profile://1.0.0/foo/resitemB").openStream());
    Assert.assertNotNull("URL stream not null", getItemURL(itemB, 0).openStream());
    ResourceItem itemB1 = prfFoo.getProfileItem(identityB1);
    Assert.assertNotNull("URL stream not null", new URL("profile://1.0.0/foo/resitemB1").openStream());
    Assert.assertEquals("profile://1.0.0/foo/resitemB1?version=0.0.0", getItemURL(itemB1, 0).toExternalForm());
    Assert.assertNotNull("URL stream not null", getItemURL(itemB1, 0).openStream());

    // Add the profile to the current coontainer
    Container cnt = cntManager.getCurrentContainer();
    cntManager.addProfiles(cnt.getIdentity(), Collections.singletonList(idFoo), null);

    // Verify that the module got installed
    Runtime runtime = RuntimeLocator.getRequiredRuntime();
    Module moduleB = runtime.getModule(identityB);
    Assert.assertNotNull("Module not null", moduleB);
    Assert.assertEquals(State.ACTIVE, moduleB.getState());
    Module moduleB1 = runtime.getModule(identityB1);
    Assert.assertNotNull("Module not null", moduleB1);
    Assert.assertEquals(State.ACTIVE, moduleB1.getState());

    // Verify that the module activator was called
    MBeanServer server = ServiceLocator.getRequiredService(MBeanServer.class);
    Assert.assertTrue("MBean registered", server.isRegistered(getObjectName(moduleB1)));
    Assert.assertEquals("ACTIVE" + moduleB, "ACTIVE", server.getAttribute(getObjectName(moduleB1), "ModuleState"));

    cntManager.removeProfiles(cnt.getIdentity(), Collections.singletonList(idFoo), null);
    prfManager.removeProfile(DEFAULT_PROFILE_VERSION, idFoo);
}
 
开发者ID:tdiesler,项目名称:fabric8poc,代码行数:61,代码来源:ResourceItemTestBase.java

示例14: testMavenResource

import org.jboss.gravia.runtime.Runtime; //导入方法依赖的package包/类
/**
 * @see ProvisionerTest#testMavenResource()
 */
@Test
public void testMavenResource() throws Exception {

    ContainerManager cntManager = ContainerManagerLocator.getContainerManager();
    ProfileManager prfManager = ProfileManagerLocator.getProfileManager();
    Provisioner provisioner = ServiceLocator.getRequiredService(Provisioner.class);

    // Tomcat does not support jar deployments
    Assume.assumeFalse(RuntimeType.TOMCAT == RuntimeType.getRuntimeType());

    // Build the resource
    ResourceIdentity identityA = ResourceIdentity.fromString("resitem.camel.core");
    MavenCoordinates mavenid = MavenCoordinates.parse("org.apache.camel:camel-core:jar:2.11.0");
    ResourceBuilder builderA = provisioner.getMavenResourceBuilder(identityA, mavenid);
    Resource resourceA = builderA.getResource();

    // Build a profile
    ProfileIdentity idFoo = ProfileIdentity.createFrom("foo");
    Profile prfFoo = ProfileBuilder.Factory.create(idFoo)
            .profileVersion(DEFAULT_PROFILE_VERSION)
            .addResourceItem(resourceA)
            .getProfile();

    // Add the profile and verify the item URL
    prfFoo = prfManager.addProfile(DEFAULT_PROFILE_VERSION, prfFoo);
    Assert.assertEquals(1, prfFoo.getProfileItems(ResourceItem.class).size());
    ResourceItem itemA = prfFoo.getProfileItem(identityA);
    Assert.assertEquals("profile://1.0.0/foo/resitem.camel.core?version=0.0.0", getItemURL(itemA, 0).toExternalForm());
    Assert.assertNotNull("URL stream not null", new URL("profile://1.0.0/foo/resitem.camel.core").openStream());
    Assert.assertNotNull("URL stream not null", getItemURL(itemA, 0).openStream());

    // Add the profile to the current coontainer
    Container cnt = cntManager.getCurrentContainer();
    cntManager.addProfiles(cnt.getIdentity(), Collections.singletonList(idFoo), null);

    // Verify that the module got installed
    Runtime runtime = RuntimeLocator.getRequiredRuntime();
    Module moduleA = runtime.getModule(identityA);
    Assert.assertNotNull("Module not null", moduleA);
    Assert.assertEquals(State.ACTIVE, moduleA.getState());

    cntManager.removeProfiles(cnt.getIdentity(), Collections.singletonList(idFoo), null);
    prfManager.removeProfile(DEFAULT_PROFILE_VERSION, idFoo);
}
 
开发者ID:tdiesler,项目名称:fabric8poc,代码行数:48,代码来源:ResourceItemTestBase.java

示例15: testProvisionMultipleContentCapabilities

import org.jboss.gravia.runtime.Runtime; //导入方法依赖的package包/类
/**
 * Provision a resource with multiple content capabilities to the container shared location.
 * Provision another resource with multiple content capabilities that has a class loader dependency on the first.
 *
 * The client controlls the resource identities
 * The installed resources are self sufficient - no additional dependency mapping needed.
 */
@Test
public void testProvisionMultipleContentCapabilities() throws Exception {

    ContainerManager cntManager = ContainerManagerLocator.getContainerManager();
    ProfileManager prfManager = ProfileManagerLocator.getProfileManager();

    // Build the resources
    ResourceBuilder builderF = new DefaultResourceBuilder();
    ResourceIdentity identityF = ResourceIdentity.create(RESOURCE_F, Version.emptyVersion);
    builderF.addIdentityCapability(identityF);
    builderF.addContentCapability(getDeployment(CONTENT_F1), null, Collections.singletonMap(CAPABILITY_INCLUDE_RUNTIME_TYPE_DIRECTIVE, "tomcat"));
    builderF.addContentCapability(getDeployment(CONTENT_F2), null, Collections.singletonMap(CAPABILITY_INCLUDE_RUNTIME_TYPE_DIRECTIVE, "wildfly"));
    builderF.addContentCapability(getDeployment(CONTENT_F3), null, Collections.singletonMap(CAPABILITY_INCLUDE_RUNTIME_TYPE_DIRECTIVE, "karaf,other"));
    Resource resourceF = builderF.getResource();

    ResourceBuilder builderG = new DefaultResourceBuilder();
    ResourceIdentity identityG = ResourceIdentity.create(RESOURCE_G, Version.emptyVersion);
    builderG.addIdentityCapability(identityG);
    builderG.addContentCapability(getDeployment(CONTENT_G1), null, Collections.singletonMap(CAPABILITY_INCLUDE_RUNTIME_TYPE_DIRECTIVE, "tomcat"));
    builderG.addContentCapability(getDeployment(CONTENT_G2), null, Collections.singletonMap(CAPABILITY_INCLUDE_RUNTIME_TYPE_DIRECTIVE, "wildfly"));
    builderG.addContentCapability(getDeployment(CONTENT_G3), null, Collections.singletonMap(CAPABILITY_INCLUDE_RUNTIME_TYPE_DIRECTIVE, "karaf,other"));
    Resource resourceG = builderG.getResource();

    // Build a profile
    ProfileIdentity idFoo = ProfileIdentity.createFrom("foo");
    Profile profile = ProfileBuilder.Factory.create(idFoo)
            .profileVersion(DEFAULT_PROFILE_VERSION)
            .addSharedResourceItem(resourceF)
            .addResourceItem(resourceG)
            .getProfile();

    // Add the profile and verify the item URL
    profile = prfManager.addProfile(DEFAULT_PROFILE_VERSION, profile);
    Assert.assertEquals(2, profile.getProfileItems(ResourceItem.class).size());
    ResourceItem itemF = profile.getProfileItem(identityF);
    ResourceItem itemG = profile.getProfileItem(identityG);
    for (int i = 0; i < 3; i++) {
        Assert.assertEquals("profile://1.0.0/foo/resitemF?version=0.0.0&cntindex=" + i, getItemURL(itemF, i).toExternalForm());
        Assert.assertNotNull("URL stream not null", new URL("profile://1.0.0/foo/resitemF?cntindex=" + i).openStream());
        Assert.assertNotNull("URL stream not null", getItemURL(itemF, i).openStream());
        Assert.assertEquals("profile://1.0.0/foo/resitemG?version=0.0.0&cntindex=" + i, getItemURL(itemG, i).toExternalForm());
        Assert.assertNotNull("URL stream not null", new URL("profile://1.0.0/foo/resitemG?cntindex=" + i).openStream());
        Assert.assertNotNull("URL stream not null", getItemURL(itemG, i).openStream());
    }

    // Add the profile to the current coontainer
    Container cnt = cntManager.getCurrentContainer();
    cntManager.addProfiles(cnt.getIdentity(), Collections.singletonList(idFoo), null);

    // Verify that the module got installed
    Runtime runtime = RuntimeLocator.getRequiredRuntime();
    Module moduleG = runtime.getModule(identityG);
    Assert.assertNotNull("Module not null", moduleG);
    Assert.assertEquals(State.ACTIVE, moduleG.getState());

    // Verify that the module activator was called
    MBeanServer server = ServiceLocator.getRequiredService(MBeanServer.class);
    Assert.assertTrue("MBean registered", server.isRegistered(getObjectName(moduleG)));
    Assert.assertEquals("ACTIVE" + moduleG, "ACTIVE", server.getAttribute(getObjectName(moduleG), "ModuleState"));

    cntManager.removeProfiles(cnt.getIdentity(), Collections.singletonList(idFoo), null);
    prfManager.removeProfile(DEFAULT_PROFILE_VERSION, idFoo);
}
 
开发者ID:tdiesler,项目名称:fabric8poc,代码行数:71,代码来源:ResourceItemTestBase.java


注:本文中的org.jboss.gravia.runtime.Runtime.getModule方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。