`

使用pax.exam对osgi(基于maven)进行集成测试

    博客分类:
  • OSGI
 
阅读更多

xml配置文件

就下列依赖加入xml的配置文件

<!-- test start -->
  <dependency>
   <groupId>junit</groupId>
   <artifactId>junit</artifactId>
   <version>4.10</version>
   <scope>test</scope>
  </dependency>

  <dependency>
   <groupId>org.ops4j.pax.exam</groupId>
   <artifactId>pax-exam-container-native</artifactId>
   <version>3.5.0</version>
   <scope>test</scope>
  </dependency>
  <dependency>
   <groupId>org.ops4j.pax.exam</groupId>
   <artifactId>pax-exam-junit4</artifactId>
   <version>3.5.0</version>
   <scope>test</scope>
  </dependency>
  <dependency>
   <groupId>org.ops4j.pax.exam</groupId>
   <artifactId>pax-exam-link-mvn</artifactId>
   <version>3.5.0</version>
   <scope>test</scope>
  </dependency>
  <dependency>
   <groupId>org.ops4j.pax.url</groupId>
   <artifactId>pax-url-aether</artifactId>
   <version>2.0.0</version>
   <scope>test</scope>
  </dependency>
  <dependency>
   <groupId>org.apache.felix</groupId>
   <artifactId>org.apache.felix.framework</artifactId>
   <version>3.2.2</version>
   <scope>test</scope>
  </dependency>
  <dependency>
   <groupId>ch.qos.logback</groupId>
   <artifactId>logback-core</artifactId>
   <version>1.1.2</version>
   <scope>test</scope>
  </dependency>
  <dependency>
   <groupId>ch.qos.logback</groupId>
   <artifactId>logback-classic</artifactId>
   <version>1.1.2</version>
   <scope>test</scope>
  </dependency>
  <dependency>
   <groupId>org.ops4j.pax.exam</groupId>
   <artifactId>pax-exam-inject</artifactId>
   <version>3.5.0</version>
  </dependency>

  <!-- test end -->

 

  <dependency>
   <groupId>org.ow2.spec.ee</groupId>
   <artifactId>ow2-atinject-1.0-spec</artifactId>
   <version>1.0.12</version>
   <scope>test</scope>
  </dependency>
 </dependencies>

 

java 调用实例

/**
* longload
* 2014年5月20日 上午10:25:08
* version 1.0
*/
package com.sj.workflow.persistence.test;
import static org.junit.Assert.*;
import static org.ops4j.pax.exam.CoreOptions.junitBundles;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
import static org.ops4j.pax.exam.CoreOptions.options;
import static org.ops4j.pax.exam.CoreOptions.systemProperty;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import javax.inject.Inject;
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 com.sj.common.vars.CommonVars;
import com.sj.workflow.persistence.api.WorkflowPersistence;

@RunWith(PaxExam.class)
public class WorkflowPersistenceTest {
     //@Inject
     //BundleContext bc;
     @Inject
    private WorkflowPersistence workflowPersistence;
     Logger logger= Logger.getLogger(this.getClass().getName());
    @Configuration
    public Option[] config() {

 

        return options(
           // mavenBundle("com.sj", "com.sj.mongodb.api", "0.0.1"),
           // 从网络下载
           //bundle("http://www.example.com/repository/foo-1.2.3.jar"),
                systemProperty("pax.exam.logging").value("debug"),
               
                mavenBundle("org.mongodb", "mongo-java-driver").version("2.11.4"),
                // common
                mavenBundle("com.sj", "com.sj.common.vars").version("0.0.1"),
                mavenBundle("com.sj", "com.sj.common.utils").version("0.0.1"),
                // api
                mavenBundle("com.sj", "com.sj.mongodb.api").version("0.0.1"),
                mavenBundle("com.sj","com.sj.workflow.persistence.api").version("0.0.1"),
                // impl
                mavenBundle("com.sj", "com.sj.mongodb.impl").version("0.0.1"),
                mavenBundle("com.sj", "com.sj.workflow.persistence").version("0.0.1"),
                junitBundles()

            );

    }

 

   //@Test
    public void revisionWFDefinitions() {
    try {
     logger.info("----------");
  workflowPersistence.revisionWFDefinitions("5379bf04d09bd5136c74d40f");
 } catch (Exception e) {
  
  e.printStackTrace();
 }
    }

}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics