001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hbase.shaded;
019
020import static org.junit.jupiter.api.Assertions.assertNotNull;
021import static org.junit.jupiter.api.Assertions.assertNull;
022
023import java.io.File;
024import java.util.jar.JarEntry;
025import java.util.jar.JarFile;
026import org.apache.hadoop.hbase.HBaseTestingUtil;
027import org.apache.hadoop.hbase.testclassification.ClientTests;
028import org.apache.hadoop.hbase.testclassification.SmallTests;
029import org.junit.jupiter.api.Tag;
030import org.junit.jupiter.api.Test;
031
032@Tag(ClientTests.TAG)
033@Tag(SmallTests.TAG)
034public class TestShadedTestingUtilJarContents {
035
036  @Test
037  public void testNoBundledJUnitLibraries() throws Exception {
038    File path =
039      new File(HBaseTestingUtil.class.getProtectionDomain().getCodeSource().getLocation().toURI());
040    try (JarFile jar = new JarFile(path)) {
041      JarEntry unexpectedEntry = jar.stream().filter(entry -> {
042        String name = entry.getName();
043        return name.startsWith("META-INF/services/org.junit.platform.") || name.endsWith(".class")
044          && (name.startsWith("org/junit/") && !name.equals("org/junit/Assert.class")
045            || name.startsWith("org/opentest4j/") || name.startsWith("org/apiguardian/")
046            || name.matches("META-INF/versions/[0-9]+/org/junit/.*"));
047      }).findFirst().orElse(null);
048      assertNull(unexpectedEntry, () -> "Unexpected bundled entry: " + unexpectedEntry);
049      // HBase's JUnit 4 shim is needed by bundled Hadoop test utilities.
050      assertNotNull(jar.getEntry("org/junit/Assert.class"));
051      assertNotNull(jar.getEntry("META-INF/services/org.junit.jupiter.api.extension.Extension"));
052    }
053  }
054}