/*
* #%L
* Gravia :: Integration Tests :: Common
* %%
* Copyright (C) 2010 - 2013 JBoss by Red Hat
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
package org.jboss.test.gravia.itests;
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.junit.Assert;
import org.junit.Test;
/**
* Test webapp deployemnts
*
* @author thomas.diesler@jboss.com
* @since 01-Oct-2013
*/
public abstract class ModuleLifecycleTest {
@Test
public void testModuleLifecycle() throws Exception {
Module modA = RuntimeLocator.getRuntime().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.RESOLVED, modA.getState());
modA.uninstall();
Assert.assertEquals(Module.State.UNINSTALLED, modA.getState());
try {
modA.start();
Assert.fail("IllegalStateException expected");
} catch (IllegalStateException ex) {
// expected
}
}
}