/**
* Licensed to the Austrian Association for Software Tool Integration (AASTI)
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership. The AASTI licenses this file to you 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.
*/
package org.openengsb.itests.exam;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.util.Collection;
import javax.inject.Inject;
import org.apache.karaf.features.FeaturesService;
import org.eclipse.osgi.framework.internal.core.Constants;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openengsb.core.api.DomainProvider;
import org.openengsb.core.api.model.OpenEngSBModel;
import org.openengsb.domain.example.ExampleDomainEvents;
import org.openengsb.domain.example.model.ExampleRequestModel;
import org.openengsb.itests.util.AbstractExamTestHelper;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
import org.ops4j.pax.exam.spi.reactors.PerMethod;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.ServiceTracker;
@RunWith(PaxExam.class)
@ExamReactorStrategy(PerMethod.class)
public class DomainInstallIT extends AbstractExamTestHelper {
@Configuration
public Option[] configuration() throws Exception {
return baseConfiguration();
}
@Inject
private FeaturesService featuresService;
@After
public void cleanUp() throws Exception {
featuresService.uninstallFeature("openengsb-domain-example");
}
@Test
public void testIfModelIsWeaved_shouldWeaveModel() throws Exception {
featuresService.installFeature("openengsb-domain-example");
Class<?> loadClass =
this.getClass().getClassLoader().loadClass(ExampleRequestModel.class.getName());
assertTrue("ExampleRequestModel has not been woven correctly",
OpenEngSBModel.class.isAssignableFrom(loadClass));
}
@Test
public void testInstallDomain_shouldRegisterDomainEvents() throws Exception {
ServiceReference<?> serviceReference =
getBundleContext().getServiceReference("org.openengsb.domain.example.ExampleDomainEvents");
assertThat(serviceReference, is(nullValue()));
featuresService.installFeature("openengsb-domain-example");
ServiceTracker<ExampleDomainEvents, Object> tracker =
new ServiceTracker<ExampleDomainEvents, Object>(getBundleContext(),
ExampleDomainEvents.class, null);
tracker.open();
Object service = tracker.waitForService(10000);
assertThat(service, not(nullValue()));
}
@Test
public void testInstallDomain_shouldRegisterDomainProvider() throws Exception {
Collection<ServiceReference<DomainProvider>> serviceReferences =
getBundleContext().getServiceReferences(DomainProvider.class, "(domain=example)");
assertThat(serviceReferences.size(), is(0));
featuresService.installFeature("openengsb-domain-example");
String filter =
String.format("(&(%s=%s)(domain=example))", Constants.OBJECTCLASS, DomainProvider.class.getName());
ServiceTracker<DomainProvider, Object> tracker =
new ServiceTracker<>(getBundleContext(), FrameworkUtil.createFilter(filter), null);
tracker.open();
DomainProvider service = (DomainProvider) tracker.waitForService(10000);
assertThat(service, not(nullValue()));
assertThat(service.getId(), is("example"));
assertThat(service.getDomainInterface().getName(), is("org.openengsb.domain.example.ExampleDomain"));
assertThat(service.getDomainEventInterface().getName(), is("org.openengsb.domain.example.ExampleDomainEvents"));
}
}