View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   https://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.commons.compress.osgi;
20  
21  import static org.ops4j.pax.exam.CoreOptions.bundle;
22  import static org.ops4j.pax.exam.CoreOptions.composite;
23  import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
24  import static org.ops4j.pax.exam.CoreOptions.systemProperty;
25  
26  import java.util.Arrays;
27  
28  import org.junit.jupiter.api.Assertions;
29  import org.ops4j.pax.exam.Option;
30  import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
31  
32  final class Configurations {
33  
34      /**
35       * @return The maven bundle for Apache commons-codec
36       */
37      private static MavenArtifactProvisionOption getCommonsCodec() {
38          return mavenBundle().groupId("commons-codec").artifactId("commons-codec").version("1.16.0");
39      }
40  
41      /**
42       * @return The maven bundle for Apache commons-io
43       */
44      private static MavenArtifactProvisionOption getCommonsIO() {
45          return mavenBundle().groupId("commons-io").artifactId("commons-io").version("2.15.1");
46      }
47  
48      public static Option[] getConfigWithoutOptionals() {
49          final Option[] defaultConfig = getDefaultConfig();
50          // @formatter:off
51          final Option[] result = Arrays.stream(defaultConfig)
52                  .filter(o -> !getCommonsCodec().equals(o))
53                  .filter(o -> !getCommonsIO().equals(o))
54                  .toArray(Option[]::new);
55          // @formatter:on
56          Assertions.assertTrue(result.length < defaultConfig.length, "Expected to have removed options.");
57          return result;
58      }
59  
60      public static Option[] getDefaultConfig() {
61          // @formatter:off
62          return new Option[]{systemProperty("pax.exam.osgi.unresolved.fail").value("true"),
63                  systemProperty("org.ops4j.pax.url.mvn.useFallbackRepositories").value("false"),
64                  systemProperty("org.ops4j.pax.url.mvn.repositories").value("https://repo.maven.apache.org/maven2"),
65                  mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.scr").version("2.0.14"),
66                  mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.configadmin").version("1.8.16"),
67                  getCommonsCodec(),
68                  getCommonsIO(),
69                  composite(systemProperty("pax.exam.invoker").value("junit"),
70                          bundle("link:classpath:META-INF/links/org.ops4j.pax.tipi.junit.link"),
71                          bundle("link:classpath:META-INF/links/org.ops4j.pax.exam.invoker.junit.link"),
72                          mavenBundle().groupId("org.apache.servicemix.bundles").artifactId("org.apache.servicemix.bundles.hamcrest").version("1.3_1")),
73                  bundle("reference:file:target/classes/").start()};
74          // @formatter:on
75      }
76  
77      private Configurations() {
78          // noop
79      }
80  }