private String getRuntimeAwareAlias(String alias) { String context = RuntimeType.getRuntimeType() == RuntimeType.KARAF ? "/gravia" : ""; return context + alias; }
private String getRuntimeAwareAlias(String alias) { String context = RuntimeType.getRuntimeType() == RuntimeType.KARAF ? "/gravia" : ""; return context + alias; }
public static RuntimeType getTargetContainer () { return RuntimeType.getRuntimeType(System.getProperty("target.container")); }
private static Set<RuntimeType> getRuntimeTypes(String directive) { Set<RuntimeType> types = new HashSet<>(); if (directive != null) { for (String typespec : directive.split(",\\s*")) { types.add(RuntimeType.getRuntimeType(typespec)); } } return types; } }
public static RuntimeType getRuntimeType() { Runtime runtime = RuntimeLocator.getRequiredRuntime(); return RuntimeType.getRuntimeType(runtime); }
public static boolean isRuntimeRelevant(String includedTypes, String excludedTypes) { return isRuntimeRelevant(getRuntimeType(), includedTypes, excludedTypes); }
@Test public void testHttpServiceClassLoading() throws Exception { Assume.assumeTrue(RuntimeType.getRuntimeType() == RuntimeType.WILDFLY); // Get the org.jboss.gravia class loader ClassLoader classLoader = RuntimeType.class.getClassLoader(); Assert.assertTrue("Unexpected: " + classLoader, classLoader.toString().contains("org.jboss.gravia")); // Load the HttpService through module org.jboss.gravia Class<?> serviceClass = classLoader.loadClass(HttpService.class.getName()); String loaderName = serviceClass.getClassLoader().toString(); // Assert that the loaded class comes from org.osgi.enterprise Assert.assertTrue("Unexpected: " + loaderName, loaderName.contains("org.osgi.enterprise")); }
public static RuntimeType getRuntimeType(Runtime runtime) { IllegalArgumentAssertion.assertNotNull(runtime, "runtime"); Object type = runtime.getProperty(Constants.RUNTIME_TYPE); return RuntimeType.getRuntimeType((String) type); }
@Test public void testSystemService() throws Exception { Assume.assumeTrue(RuntimeType.getRuntimeType() != RuntimeType.KARAF); Assert.assertEquals("gravia-system", performCall("/gravia/system")); }
private static CommandSession getCommandSession(PrintStream printStream) { CommandSession commandSession; if (RuntimeType.getRuntimeType() == RuntimeType.KARAF) { ModuleContext moduleContext = RuntimeLocator.getRequiredRuntime().getModuleContext(); CommandProcessor commandProcessor = ServiceLocator.awaitService(moduleContext, CommandProcessor.class); commandSession = commandProcessor.createSession(System.in, printStream, printStream); commandSession.put("APPLICATION", System.getProperty("karaf.name")); commandSession.put("USER", "karaf"); } else { commandSession = new SessionSupport(System.in, printStream) { @Override public Object execute(CharSequence cmdstr) throws Exception { List<String> tokens = Arrays.asList(cmdstr.toString().split("\\s")); List<Object> args = new ArrayList<Object>(tokens); args.remove(0); AbstractCommand command = (AbstractCommand) get(AbstractCommand.class.getName()); command.execute(this, args); return null; } }; } return commandSession; }
@Test public void testContainerLifecycle() throws Exception { RuntimeType runtimeType = RuntimeType.getRuntimeType(System.getProperty("target.container")); ContainerConfigurationBuilder builder = ContainerConfigurationBuilder.create(runtimeType); ContainerConfiguration configuration = builder.setTargetDirectory("target/managed-container").getConfiguration(); ManagedContainer<?> container = ManagedContainer.Factory.create(configuration); Assert.assertNotNull("ManagedContainer not null", container); try { Assert.assertNotNull("Container home not null", container.getContainerHome()); container.start(); } finally { container.destroy(); } } }
/** * Provision a resource from maven coordinates. * * The client controlls the resource identity * The installed resource is self sufficient - no additional dependency mapping needed. */ @Test public void testMavenResource() throws Exception { Provisioner provisioner = ServiceLocator.getRequiredService(Provisioner.class); Runtime runtime = RuntimeLocator.getRequiredRuntime(); // Tomcat does not support jar deployments Assume.assumeFalse(RuntimeType.TOMCAT == RuntimeType.getRuntimeType()); ResourceIdentity identityA = ResourceIdentity.fromString("camel.core.unshared"); MavenCoordinates mavenid = MavenCoordinates.parse("org.apache.camel:camel-core:jar:2.11.0"); ResourceBuilder builderA = provisioner.getMavenResourceBuilder(identityA, mavenid); ResourceHandle handleA = provisioner.installResource(builderA.getResource()); try { Assert.assertSame(handleA.getModule(), runtime.getModule(identityA)); Assert.assertEquals("ACTIVE " + identityA, State.ACTIVE, handleA.getModule().getState()); } finally { handleA.uninstall(); } }