View | Details | Raw Unified | Return to bug 57857
Collapse All | Expand All

(-)osgi/src/test/java/org/apache/poi/osgi/TestOSGiBundle.java (-84 lines)
Lines 1-84 Link Here
1
/* ====================================================================
2
   Licensed to the Apache Software Foundation (ASF) under one or more
3
   contributor license agreements.  See the NOTICE file distributed with
4
   this work for additional information regarding copyright ownership.
5
   The ASF licenses this file to You under the Apache License, Version 2.0
6
   (the "License"); you may not use this file except in compliance with
7
   the License.  You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
18
package org.apache.poi.osgi;
19
20
import static org.junit.Assert.assertEquals;
21
import static org.junit.Assert.assertTrue;
22
import static org.ops4j.pax.exam.CoreOptions.bundle;
23
import static org.ops4j.pax.exam.CoreOptions.junitBundles;
24
import static org.ops4j.pax.exam.CoreOptions.options;
25
26
import javax.inject.Inject;
27
import java.io.ByteArrayInputStream;
28
import java.io.ByteArrayOutputStream;
29
import java.io.File;
30
import java.io.IOException;
31
import java.net.URISyntaxException;
32
33
import org.apache.poi.hssf.usermodel.HSSFSheet;
34
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
35
36
import org.junit.Test;
37
import org.junit.runner.RunWith;
38
import org.ops4j.pax.exam.Configuration;
39
import org.ops4j.pax.exam.Option;
40
import org.ops4j.pax.exam.junit.PaxExam;
41
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
42
import org.ops4j.pax.exam.spi.reactors.PerMethod;
43
import org.osgi.framework.Bundle;
44
import org.osgi.framework.BundleContext;
45
import org.osgi.framework.ServiceReference;
46
47
/**
48
 * Test to ensure that all our main formats can create, write
49
 *  and read back in, when running under OSGi
50
 */
51
@RunWith(PaxExam.class)
52
@ExamReactorStrategy(PerMethod.class)
53
public class TestOSGiBundle {
54
55
    private final File TARGET = new File("target");
56
57
    @Inject
58
    private BundleContext bc;
59
60
    @Configuration
61
    public Option[] configuration() throws IOException, URISyntaxException {
62
        File base = new File(TARGET, "test-bundles");
63
        return options(
64
                junitBundles(),
65
                bundle(new File(base, "poi-bundle.jar").toURI().toURL().toString()));
66
    }
67
68
    @Test
69
    public void testHSSF() throws Exception {
70
        HSSFWorkbook wb = new HSSFWorkbook();
71
        HSSFSheet s = wb.createSheet("OSGi");
72
        s.createRow(0).createCell(0).setCellValue("With OSGi");
73
74
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
75
        wb.write(baos);
76
        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
77
78
        wb = new HSSFWorkbook(bais);
79
        assertEquals(1, wb.getNumberOfSheets());
80
81
        s = wb.getSheet("OSGi");
82
        assertEquals("With OSGi", s.getRow(0).getCell(0).toString());
83
    }
84
}
(-)osgi/src/test/java/org/apache/test/poi/osgi/BundleIT.java (+107 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Licensed to the Apache Software Foundation (ASF) under one or more
3
   contributor license agreements.  See the NOTICE file distributed with
4
   this work for additional information regarding copyright ownership.
5
   The ASF licenses this file to You under the Apache License, Version 2.0
6
   (the "License"); you may not use this file except in compliance with
7
   the License.  You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
18
package org.apache.test.poi.osgi;
19
20
import static org.junit.Assert.assertEquals;
21
import static org.junit.Assert.assertTrue;
22
import static org.ops4j.pax.exam.CoreOptions.bundle;
23
import static org.ops4j.pax.exam.CoreOptions.junitBundles;
24
import static org.ops4j.pax.exam.CoreOptions.options;
25
import static org.ops4j.pax.exam.CoreOptions.frameworkProperty;
26
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
27
import static org.ops4j.pax.exam.CoreOptions.vmOption;
28
29
import javax.inject.Inject;
30
31
import java.io.ByteArrayInputStream;
32
import java.io.ByteArrayOutputStream;
33
import java.io.File;
34
import java.io.IOException;
35
import java.net.URISyntaxException;
36
37
import org.apache.poi.hssf.usermodel.HSSFSheet;
38
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
39
import org.junit.Test;
40
import org.junit.runner.RunWith;
41
import org.ops4j.pax.exam.Configuration;
42
import org.ops4j.pax.exam.Option;
43
import org.ops4j.pax.exam.ProbeBuilder;
44
import org.ops4j.pax.exam.TestProbeBuilder;
45
import org.ops4j.pax.exam.junit.PaxExam;
46
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
47
import org.ops4j.pax.exam.spi.reactors.PerMethod;
48
import org.osgi.framework.Bundle;
49
import org.osgi.framework.BundleContext;
50
import org.osgi.framework.ServiceReference;
51
52
import aQute.bnd.osgi.Constants;
53
54
/**
55
 * Test to ensure that all our main formats can create, write
56
 *  and read back in, when running under OSGi
57
 */
58
@RunWith(PaxExam.class)
59
@ExamReactorStrategy(PerMethod.class)
60
public class BundleIT {
61
62
    private final File TARGET = new File("target");
63
    
64
    private static final String POI_VERSION_PROP = "poiVersion";
65
    
66
    private static final String PAX_EXAM_VERSION_PROP = "paxExamVersion";
67
68
    @Inject
69
    private BundleContext bc;
70
71
    @Configuration
72
    public Option[] configuration() throws IOException, URISyntaxException {
73
        final String poiVersion = System.getProperty( POI_VERSION_PROP, "3.12-beta2" );
74
        final String paxExamVersion = System.getProperty( PAX_EXAM_VERSION_PROP, "4.5.0" );
75
        return options(
76
                junitBundles(),
77
                frameworkProperty("org.osgi.framework.system.packages.extra").value("org.ops4j.pax.exam;version=" + 
78
                    paxExamVersion +",org.ops4j.pax.exam.options;version=" +
79
                    paxExamVersion + ",org.ops4j.pax.exam.util;version=" + 
80
                    paxExamVersion + ",org.w3c.dom,org.w3c.dom.html,org.w3c.dom.traversal,org.w3c.dom.ranges,org.w3c.dom.views,javax.xml.crypto"),
81
                bundle(new File(TARGET, "poi-bundle-" + poiVersion +".jar").toURI().toURL().toString()),
82
                mavenBundle("commons-codec", "commons-codec", "1.9"),
83
                mavenBundle("org.apache.servicemix.bundles", "org.apache.servicemix.bundles.bcel", "5.2_4"),
84
                mavenBundle("org.apache.servicemix.bundles", "org.apache.servicemix.bundles.xalan", "2.7.1_4"),
85
                mavenBundle("org.apache.servicemix.bundles", "org.apache.servicemix.bundles.xerces", "2.9.1_4"),
86
                mavenBundle("org.apache.servicemix.bundles", "org.apache.servicemix.bundles.xmlresolver", "1.2_5"),
87
                mavenBundle("org.apache.santuario", "xmlsec", "2.0.1")
88
                );
89
    }
90
91
    @Test
92
    public void testHSSF() throws Exception {
93
        HSSFWorkbook wb = new HSSFWorkbook();
94
        HSSFSheet s = wb.createSheet("OSGi");
95
        s.createRow(0).createCell(0).setCellValue("With OSGi");
96
97
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
98
        wb.write(baos);
99
        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
100
101
        wb = new HSSFWorkbook(bais);
102
        assertEquals(1, wb.getNumberOfSheets());
103
104
        s = wb.getSheet("OSGi");
105
        assertEquals("With OSGi", s.getRow(0).getCell(0).toString());
106
    }
107
}
(-)osgi/pom.xml (-43 / +32 lines)
Lines 36-42 Link Here
36
    OSGi bundle that contains Apache POI, and the dependencies.
36
    OSGi bundle that contains Apache POI, and the dependencies.
37
  </description>
37
  </description>
38
  <url>http://poi.apache.org/</url>
38
  <url>http://poi.apache.org/</url>
39
  <version>${poi.version}</version>
39
  <version>3.12-beta2</version>
40
<!--
40
<!--
41
  <version>3.12-beta2</version>
41
  <version>3.12-beta2</version>
42
  <version>@VERSION@</version>
42
  <version>@VERSION@</version>
Lines 45-51 Link Here
45
  <properties>
45
  <properties>
46
    <maven.compiler.source>1.6</maven.compiler.source>
46
    <maven.compiler.source>1.6</maven.compiler.source>
47
    <maven.compiler.target>1.6</maven.compiler.target>
47
    <maven.compiler.target>1.6</maven.compiler.target>
48
    <pax.exam.version>4.4.0</pax.exam.version>
48
    <pax.exam.version>4.5.0</pax.exam.version>
49
    <poi.version>${version}</poi.version>
49
  </properties>
50
  </properties>
50
51
51
  <dependencies>
52
  <dependencies>
Lines 70-75 Link Here
70
      <groupId>junit</groupId>
71
      <groupId>junit</groupId>
71
      <artifactId>junit</artifactId>
72
      <artifactId>junit</artifactId>
72
      <version>4.12</version>
73
      <version>4.12</version>
74
      <scope>test</scope>
73
    </dependency>
75
    </dependency>
74
    <dependency>
76
    <dependency>
75
      <groupId>org.ops4j.pax.exam</groupId>
77
      <groupId>org.ops4j.pax.exam</groupId>
Lines 102-107 Link Here
102
      <scope>test</scope>
104
      <scope>test</scope>
103
    </dependency>
105
    </dependency>
104
    <dependency>
106
    <dependency>
107
      <groupId>org.slf4j</groupId>
108
      <artifactId>slf4j-simple</artifactId>
109
      <version>1.7.12</version>
110
      <scope>test</scope>
111
    </dependency>
112
    <dependency>
105
      <groupId>javax.inject</groupId>
113
      <groupId>javax.inject</groupId>
106
      <artifactId>javax.inject</artifactId>
114
      <artifactId>javax.inject</artifactId>
107
      <version>1</version>
115
      <version>1</version>
Lines 118-123 Link Here
118
  <build>
126
  <build>
119
    <plugins>
127
    <plugins>
120
      <plugin>
128
      <plugin>
129
         <artifactId>maven-compiler-plugin</artifactId>
130
         <version>3.2</version>
131
         <configuration>
132
            <source>${maven.compiler.source}</source>
133
            <target>${maven.compiler.target}</target>
134
         </configuration>
135
      </plugin>
136
      <plugin>
121
        <groupId>org.apache.felix</groupId>
137
        <groupId>org.apache.felix</groupId>
122
        <artifactId>maven-bundle-plugin</artifactId>
138
        <artifactId>maven-bundle-plugin</artifactId>
123
        <extensions>true</extensions>
139
        <extensions>true</extensions>
Lines 139-174 Link Here
139
              org.apache.poi.*
155
              org.apache.poi.*
140
            </Export-Package>
156
            </Export-Package>
141
            <Import-Package>
157
            <Import-Package>
142
              !org.junit,
158
              com.sun.javadoc;resolution:=optional,
143
              *,
159
              com.sun.tools.javadoc;resolution:=optional,
144
              org.apache.xmlbeans.impl.xpath.saxon;resolution:=optional,
160
              junit.framework;resolution:=optional,
145
              org.apache.xmlbeans.impl.xquery.saxon;resolution:=optional,
161
              org.apache.crimson.*;resolution:=optional,
146
              org.bouncycastle.cert;resolution:=optional,
162
              org.apache.tools.ant*;resolution:=optional,
147
              org.bouncycastle.cert.ocsp;resolution:=optional,
163
              org.bouncycastle.*;resolution:=optional,
148
              org.bouncycastle.cms.bc;resolution:=optional,
164
              org.junit.*;resolution:=optional,
149
              org.bouncycastle.cert.jcajce;resolution:=optional,
165
              org.openxmlformats*;resolution:=optional,
150
              org.bouncycastle.operator;resolution:=optional,
166
              repackage;resolution:=optional,
151
              org.bouncycastle.operator.bc;resolution:=optional,
167
              schemasMicrosoftCom*;resolution:=optional,
152
              org.bouncycastle.tsp;resolution:=optional,
168
              *
153
              org.openxmlformats.schemas.officeDocument.x2006.math;resolution:=optional,
154
              org.openxmlformats.schemas.schemaLibrary.x2006.main;resolution:=optional,
155
              schemasMicrosoftComOfficePowerpoint;resolution:=optional,
156
              schemasMicrosoftComOfficeWord;resolution:=optional,
157
            </Import-Package>
169
            </Import-Package>
158
          </instructions>
170
          </instructions>
159
        </configuration>
171
        </configuration>
160
      </plugin>
172
      </plugin>
161
      <plugin>
162
         <artifactId>maven-compiler-plugin</artifactId>
163
         <version>3.2</version>
164
         <configuration>
165
            <source>${maven.compiler.source}</source>
166
            <target>${maven.compiler.target}</target>
167
         </configuration>
168
      </plugin>
169
    </plugins>
173
    </plugins>
170
  </build>
174
  </build>
171
172
  <profiles>
175
  <profiles>
173
    <profile>
176
    <profile>
174
      <id>java6</id>
177
      <id>java6</id>
Lines 178-201 Link Here
178
      <build>
181
      <build>
179
        <plugins>
182
        <plugins>
180
          <plugin>
183
          <plugin>
181
            <artifactId>maven-assembly-plugin</artifactId>
182
            <executions>
183
              <execution>
184
                <phase>pre-integration-test</phase>
185
                <goals>
186
                  <goal>single</goal>
187
                </goals>
188
                <configuration>
189
                  <descriptor>test-bundles.xml</descriptor>
190
                  <finalName>test</finalName>
191
                  <attach>false</attach>
192
                </configuration>
193
              </execution>
194
            </executions>
195
          </plugin>
196
          <plugin>
197
            <artifactId>maven-failsafe-plugin</artifactId>
184
            <artifactId>maven-failsafe-plugin</artifactId>
198
            <version>2.10</version>
185
            <version>2.18</version>
199
            <executions>
186
            <executions>
200
              <execution>
187
              <execution>
201
                <goals>
188
                <goals>
Lines 206-211 Link Here
206
            </executions>
193
            </executions>
207
            <configuration>
194
            <configuration>
208
              <systemPropertyVariables>
195
              <systemPropertyVariables>
196
                <poiVersion>${version}</poiVersion>
197
                <paxExamVersion>${pax.exam.version}</paxExamVersion>
209
                <org.ops4j.pax.logging.DefaultServiceLog.level>
198
                <org.ops4j.pax.logging.DefaultServiceLog.level>
210
                  WARN
199
                  WARN
211
                </org.ops4j.pax.logging.DefaultServiceLog.level>
200
                </org.ops4j.pax.logging.DefaultServiceLog.level>
(-)osgi/test-bundles.xml (-34 lines)
Lines 1-34 Link Here
1
<!--
2
   Licensed to the Apache Software Foundation (ASF) under one or more
3
   contributor license agreements.  See the NOTICE file distributed with
4
   this work for additional information regarding copyright ownership.
5
   The ASF licenses this file to You under the Apache License, Version 2.0
6
   (the "License"); you may not use this file except in compliance with
7
   the License.  You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
  -->
17
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
18
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19
          xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
20
  <id>bundles</id>
21
  <formats>
22
    <format>dir</format>
23
  </formats>
24
  <includeBaseDirectory>false</includeBaseDirectory>
25
  <dependencySets>
26
    <dependencySet>
27
      <outputDirectory/>
28
      <outputFileNameMapping>${artifact.artifactId}.jar</outputFileNameMapping>
29
      <includes>
30
        <include>org.apache.poi:poi-bundle</include>
31
      </includes>
32
    </dependencySet>
33
  </dependencySets>
34
</assembly>

Return to bug 57857