Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions osgi/integrationtest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.karaf.features</groupId>
<artifactId>org.apache.karaf.features.core</artifactId>
<version>${apache.karaf.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-junit4</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* Hibernate Validator, declare and validate application constraints
*
* License: Apache License, Version 2.0
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
*/
package org.hibernate.validator.osgi.integrationtest;

import java.io.File;
import java.net.URI;
import java.util.Locale;
import javax.inject.Inject;
import org.apache.karaf.features.Feature;
import org.apache.karaf.features.FeaturesService;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.karaf.options.LogLevelOption;
import org.ops4j.pax.exam.options.MavenArtifactUrlReference;
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
import org.ops4j.pax.exam.spi.reactors.PerClass;

import static org.junit.Assert.assertTrue;
import static org.ops4j.pax.exam.CoreOptions.maven;
import static org.ops4j.pax.exam.CoreOptions.options;
import static org.ops4j.pax.exam.CoreOptions.systemProperty;
import static org.ops4j.pax.exam.CoreOptions.when;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.configureConsole;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.debugConfiguration;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.logLevel;

/**
* Integration test for Bean Validation and Hibernate Validator under OSGi.
* <p>
* This test makes sure that the karaf features provided by this project are installable.
*
* @author Toni Menzel (toni@rebaze.com)
*/
@RunWith(PaxExam.class)
@ExamReactorStrategy(PerClass.class)
public class KarafFeaturesAreInstallableTest {

@Inject
protected FeaturesService featuresService;

private static final boolean DEBUG = false;

@Configuration
public Option[] config() {
MavenArtifactUrlReference hibernateValidatorFeature = maven()
.groupId( "org.hibernate.validator" )
.artifactId( "hibernate-validator-osgi-karaf-features" )
.classifier( "features" )
.type( "xml" )
.versionAsInProject();

return options(
when( DEBUG ).useOptions( debugConfiguration( "5005", true ) ),
karafDistributionConfiguration()
.frameworkUrl(
maven()
.groupId( "org.apache.karaf" )
.artifactId( "apache-karaf" )
.type( "tar.gz" )
.versionAsInProject()
)
.unpackDirectory( new File( "target/exam" ) )
.useDeployFolder( false ),
configureConsole()
.ignoreLocalConsole()
.ignoreRemoteShell(),
when( DEBUG ).useOptions( keepRuntimeFolder() ),
logLevel( LogLevelOption.LogLevel.INFO ),
// avoiding additional boot features; specifically "enterprise" which already comes with a HV feature
// "system" is the absolute minimum, but enough for our purposes
editConfigurationFilePut(
"etc/org.apache.karaf.features.cfg",
"featuresBoot",
"system"
),
systemProperty( "validatorRepositoryUrl" ).value( hibernateValidatorFeature.getURL() )
);
}

@BeforeClass
public static void setLocaleToEnglish() {
Locale.setDefault( Locale.ENGLISH );
}

@Test
public void canInstallFeatureHibernateValidator() throws Exception {
featuresService.addRepository( new URI( System.getProperty( "validatorRepositoryUrl" ) ) );
canInstallFeature( "hibernate-validator" );
}

@Test
public void canInstallFeatureHibernateValidatorParanamer() throws Exception {
featuresService.addRepository( new URI( System.getProperty( "validatorRepositoryUrl" ) ) );
canInstallFeature( "hibernate-validator-paranamer" );
}

public void canInstallFeature(String featureName) throws Exception {
Feature feature = featuresService.getFeature( featureName );
assertTrue( featureName + " feature is not available from features list", feature != null );
featuresService.installFeature( featureName );
assertTrue( featureName + " feature isn't installed, though available from features list", featuresService.isInstalled( feature ) );
}
}
2 changes: 1 addition & 1 deletion osgi/karaf-features/src/main/features/features.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
<feature name="hibernate-validator-paranamer" version="${project.version}">
<feature prerequisite="true">wrap</feature>
<feature>hibernate-validator</feature>
<bundle>wrap:mvn:com.thoughtworks.paranamer:paranamer:${paranamer.version}</bundle>
<bundle>wrap:mvn:com.thoughtworks.paranamer/paranamer/${paranamer.version}</bundle>
</feature>
</features>