/*
* #%L
* Gravia :: Integration Tests :: WildFly
* %%
* Copyright (C) 2010 - 2014 JBoss by Red Hat
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package org.jboss.test.gravia.itests.wildfly;
import java.io.InputStream;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.gravia.resource.ManifestBuilder;
import org.jboss.gravia.runtime.Module;
import org.jboss.gravia.runtime.ModuleContext;
import org.jboss.gravia.runtime.RuntimeLocator;
import org.jboss.gravia.runtime.ServiceRegistration;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.Asset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Test simple module lifecycle
*
* @author thomas.diesler@jboss.com
* @since 01-Oct-2013
*/
@RunWith(Arquillian.class)
public class WebappModuleLifecycleTest {
@Deployment
public static Archive<?> deployment() {
final WebArchive archive = ShrinkWrap.create(WebArchive.class, "simple.war");
archive.setManifest(new Asset() {
@Override
public InputStream openStream() {
ManifestBuilder builder = new ManifestBuilder();
builder.addIdentityCapability(archive.getName(), "1.0.0");
return builder.openStream();
}
});
return archive;
}
@Test
public void testModuleLifecycle() throws Exception {
Module modA = RuntimeLocator.getRequiredRuntime().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());
}
}