|
| 1 | +/* |
| 2 | + * Hibernate Validator, declare and validate application constraints |
| 3 | + * |
| 4 | + * License: Apache License, Version 2.0 |
| 5 | + * See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>. |
| 6 | + */ |
| 7 | +package org.hibernate.validator.osgi.integrationtest; |
| 8 | + |
| 9 | +import java.io.File; |
| 10 | +import java.net.URI; |
| 11 | +import java.util.Locale; |
| 12 | +import javax.inject.Inject; |
| 13 | +import org.apache.karaf.features.Feature; |
| 14 | +import org.apache.karaf.features.FeaturesService; |
| 15 | +import org.junit.BeforeClass; |
| 16 | +import org.junit.Test; |
| 17 | +import org.junit.runner.RunWith; |
| 18 | +import org.ops4j.pax.exam.Configuration; |
| 19 | +import org.ops4j.pax.exam.Option; |
| 20 | +import org.ops4j.pax.exam.junit.PaxExam; |
| 21 | +import org.ops4j.pax.exam.karaf.options.LogLevelOption; |
| 22 | +import org.ops4j.pax.exam.options.MavenArtifactUrlReference; |
| 23 | +import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; |
| 24 | +import org.ops4j.pax.exam.spi.reactors.PerClass; |
| 25 | + |
| 26 | +import static org.junit.Assert.assertTrue; |
| 27 | +import static org.ops4j.pax.exam.CoreOptions.maven; |
| 28 | +import static org.ops4j.pax.exam.CoreOptions.options; |
| 29 | +import static org.ops4j.pax.exam.CoreOptions.systemProperty; |
| 30 | +import static org.ops4j.pax.exam.CoreOptions.when; |
| 31 | +import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.configureConsole; |
| 32 | +import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.debugConfiguration; |
| 33 | +import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut; |
| 34 | +import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration; |
| 35 | +import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder; |
| 36 | +import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.logLevel; |
| 37 | + |
| 38 | +/** |
| 39 | + * Integration test for Bean Validation and Hibernate Validator under OSGi. |
| 40 | + * <p> |
| 41 | + * This test makes sure that the karaf features provided by this project are installable. |
| 42 | + * |
| 43 | + * @author Toni Menzel ([email protected]) |
| 44 | + */ |
| 45 | +@RunWith(PaxExam.class) |
| 46 | +@ExamReactorStrategy(PerClass.class) |
| 47 | +public class KarafFeaturesAreInstallableTest { |
| 48 | + |
| 49 | + @Inject |
| 50 | + protected FeaturesService featuresService; |
| 51 | + |
| 52 | + private static final boolean DEBUG = false; |
| 53 | + |
| 54 | + @Configuration |
| 55 | + public Option[] config() { |
| 56 | + MavenArtifactUrlReference hibernateValidatorFeature = maven() |
| 57 | + .groupId( "org.hibernate" ) |
| 58 | + .artifactId( "hibernate-validator-osgi-karaf-features" ) |
| 59 | + .classifier( "features" ) |
| 60 | + .type( "xml" ) |
| 61 | + .versionAsInProject(); |
| 62 | + |
| 63 | + return options( |
| 64 | + when( DEBUG ).useOptions( debugConfiguration( "5005", true ) ), |
| 65 | + karafDistributionConfiguration() |
| 66 | + .frameworkUrl( |
| 67 | + maven() |
| 68 | + .groupId( "org.apache.karaf" ) |
| 69 | + .artifactId( "apache-karaf" ) |
| 70 | + .type( "tar.gz" ) |
| 71 | + .versionAsInProject() |
| 72 | + ) |
| 73 | + .unpackDirectory( new File( "target/exam" ) ) |
| 74 | + .useDeployFolder( false ), |
| 75 | + configureConsole() |
| 76 | + .ignoreLocalConsole() |
| 77 | + .ignoreRemoteShell(), |
| 78 | + when( DEBUG ).useOptions( keepRuntimeFolder() ), |
| 79 | + logLevel( LogLevelOption.LogLevel.INFO ), |
| 80 | + // avoiding additional boot features; specifically "enterprise" which already comes with a HV feature |
| 81 | + // "system" is the absolute minimum, but enough for our purposes |
| 82 | + editConfigurationFilePut( |
| 83 | + "etc/org.apache.karaf.features.cfg", |
| 84 | + "featuresBoot", |
| 85 | + "system" |
| 86 | + ), |
| 87 | + systemProperty( "validatorRepositoryUrl" ).value( hibernateValidatorFeature.getURL() ) |
| 88 | + ); |
| 89 | + } |
| 90 | + |
| 91 | + @BeforeClass |
| 92 | + public static void setLocaleToEnglish() { |
| 93 | + Locale.setDefault( Locale.ENGLISH ); |
| 94 | + } |
| 95 | + |
| 96 | + @Test |
| 97 | + public void canInstallFeatureHibernateValidator() throws Exception { |
| 98 | + featuresService.addRepository( new URI( System.getProperty( "validatorRepositoryUrl" ) ) ); |
| 99 | + canInstallFeature( "hibernate-validator" ); |
| 100 | + } |
| 101 | + |
| 102 | + @Test |
| 103 | + public void canInstallFeatureHibernateValidatorParanamer() throws Exception { |
| 104 | + featuresService.addRepository( new URI( System.getProperty( "validatorRepositoryUrl" ) ) ); |
| 105 | + canInstallFeature( "hibernate-validator-paranamer" ); |
| 106 | + } |
| 107 | + |
| 108 | + public void canInstallFeature(String featureName) throws Exception { |
| 109 | + Feature feature = featuresService.getFeature( featureName ); |
| 110 | + assertTrue( featureName + " feature is not available from features list", feature != null ); |
| 111 | + featuresService.installFeature( featureName ); |
| 112 | + assertTrue( featureName + " feature isn't installed, though available from features list", featuresService.isInstalled( feature ) ); |
| 113 | + } |
| 114 | +} |
0 commit comments