Class CommonTestSupportUtils


  • public final class CommonTestSupportUtils
    extends java.lang.Object
    TODO Add javadoc
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String adjustURLPathValue​(java.lang.String path)  
      static java.lang.String adjustURLPathValue​(java.net.URL url)  
      static org.apache.sshd.common.keyprovider.KeyPairProvider createTestHostKeyProvider​(java.lang.Class<?> anchor)  
      static org.apache.sshd.common.keyprovider.KeyPairProvider createTestHostKeyProvider​(java.nio.file.Path path)  
      static org.apache.sshd.common.keyprovider.FileKeyPairProvider createTestKeyPairProvider​(java.lang.String resource)  
      static java.nio.file.Path detectTargetFolder​(java.lang.Class<?> anchor)  
      static java.nio.file.Path detectTargetFolder​(java.nio.file.Path anchorFile)  
      static java.security.KeyPair generateKeyPair​(java.lang.String algorithm, int keySize)  
      static java.lang.String getClassBytesResourceName​(java.lang.Class<?> clazz)  
      static java.lang.String getClassBytesResourceName​(java.lang.String name)  
      static java.net.URL getClassBytesURL​(java.lang.Class<?> clazz)  
      static java.nio.file.Path getClassContainerLocationPath​(java.lang.Class<?> clazz)  
      static java.net.URI getClassContainerLocationURI​(java.lang.Class<?> clazz)  
      static java.net.URL getClassContainerLocationURL​(java.lang.Class<?> clazz)  
      private static java.nio.file.Path getFile​(java.lang.String resource)  
      static java.security.KeyPair getFirstKeyPair​(org.apache.sshd.common.keyprovider.KeyIdentityProvider provider)  
      static java.security.KeyPair getFirstKeyPair​(org.apache.sshd.common.keyprovider.KeyPairProviderHolder holder)  
      static java.lang.String getURLSource​(java.lang.String externalForm)  
      static java.lang.String getURLSource​(java.net.URI uri)  
      static java.lang.String getURLSource​(java.net.URL url)  
      static java.nio.file.Path resolve​(java.nio.file.Path root, java.lang.String... children)  
      static java.nio.file.Path resolve​(java.nio.file.Path root, java.util.Collection<java.lang.String> children)  
      static java.lang.String stripJarURLPrefix​(java.lang.String externalForm)  
      static java.nio.file.Path toPathSource​(java.net.URI uri)
      Converts a URI that may refer to an internal resource to a Path representing is "source" container (e.g., if it is a resource in a JAR, then the result is the JAR's path)
      static java.nio.file.Path toPathSource​(java.net.URL url)
      Converts a URL that may refer to an internal resource to a Path representing is "source" container (e.g., if it is a resource in a JAR, then the result is the JAR's path)
      static <P extends org.apache.sshd.common.keyprovider.KeyIdentityProvider>
      P
      validateKeyPairProvider​(P provider)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • FILE_URL_SCHEME

        public static final java.lang.String FILE_URL_SCHEME
        URL/URI scheme that refers to a file
        See Also:
        Constant Field Values
      • FILE_URL_PREFIX

        public static final java.lang.String FILE_URL_PREFIX
        Prefix used in URL(s) that reference a file resource
        See Also:
        Constant Field Values
      • RESOURCE_SUBPATH_SEPARATOR

        public static final char RESOURCE_SUBPATH_SEPARATOR
        Separator used in URL(s) that reference a resource inside a JAR to denote the sub-path inside the JAR
        See Also:
        Constant Field Values
      • JAR_FILE_SUFFIX

        public static final java.lang.String JAR_FILE_SUFFIX
        Suffix of JAR files
        See Also:
        Constant Field Values
      • JAR_URL_SCHEME

        public static final java.lang.String JAR_URL_SCHEME
        URL/URI scheme that refers to a JAR
        See Also:
        Constant Field Values
      • JAR_URL_PREFIX

        public static final java.lang.String JAR_URL_PREFIX
        Prefix used in URL(s) that reference a resource inside a JAR
        See Also:
        Constant Field Values
      • CLASS_FILE_SUFFIX

        public static final java.lang.String CLASS_FILE_SUFFIX
        Suffix of compile Java class files
        See Also:
        Constant Field Values
      • TARGET_FOLDER_NAMES

        public static final java.util.List<java.lang.String> TARGET_FOLDER_NAMES
      • DEFAULT_TEST_HOST_KEY_PROVIDER_ALGORITHM

        public static final java.lang.String DEFAULT_TEST_HOST_KEY_PROVIDER_ALGORITHM
        See Also:
        Constant Field Values
      • DEFAULT_TEST_HOST_KEY_SIZE

        public static final int DEFAULT_TEST_HOST_KEY_SIZE
        See Also:
        Constant Field Values
      • DEFAULT_TEST_HOST_KEY_TYPE

        public static final java.lang.String DEFAULT_TEST_HOST_KEY_TYPE
      • KEYPAIR_PROVIDER_HOLDER

        private static final java.util.concurrent.atomic.AtomicReference<org.apache.sshd.common.keyprovider.KeyPairProvider> KEYPAIR_PROVIDER_HOLDER
      • PROVIDERS_MAP

        private static final java.util.Map<java.lang.String,​org.apache.sshd.common.keyprovider.FileKeyPairProvider> PROVIDERS_MAP
    • Constructor Detail

      • CommonTestSupportUtils

        private CommonTestSupportUtils()
    • Method Detail

      • getClassContainerLocationURI

        public static java.net.URI getClassContainerLocationURI​(java.lang.Class<?> clazz)
                                                         throws java.net.URISyntaxException
        Parameters:
        clazz - A Class object
        Returns:
        A URI to the location of the class bytes container - e.g., the root folder, the containing JAR, etc.. Returns null if location could not be resolved
        Throws:
        java.net.URISyntaxException - if location is not a valid URI
        See Also:
        getClassContainerLocationURL(Class)
      • getClassContainerLocationURL

        public static java.net.URL getClassContainerLocationURL​(java.lang.Class<?> clazz)
        Parameters:
        clazz - A Class object
        Returns:
        A URL to the location of the class bytes container - e.g., the root folder, the containing JAR, etc.. Returns null if location could not be resolved
      • getURLSource

        public static java.lang.String getURLSource​(java.net.URI uri)
        Parameters:
        uri - The URI value - ignored if null
        Returns:
        The URI(s) source path where JAR_URL_PREFIX and any sub-resource are stripped
        See Also:
        getURLSource(String)
      • getURLSource

        public static java.lang.String getURLSource​(java.net.URL url)
        Parameters:
        url - The URL value - ignored if null
        Returns:
        The URL(s) source path where JAR_URL_PREFIX and any sub-resource are stripped
        See Also:
        getURLSource(String)
      • getURLSource

        public static java.lang.String getURLSource​(java.lang.String externalForm)
        Parameters:
        externalForm - The URL.toExternalForm() string - ignored if null/empty
        Returns:
        The URL(s) source path where JAR_URL_PREFIX and any sub-resource are stripped
      • adjustURLPathValue

        public static java.lang.String adjustURLPathValue​(java.net.URL url)
        Parameters:
        url - A URL - ignored if null
        Returns:
        The path after stripping any trailing '/' provided the path is not '/' itself
        See Also:
        adjustURLPathValue(String)
      • adjustURLPathValue

        public static java.lang.String adjustURLPathValue​(java.lang.String path)
        Parameters:
        path - A URL path value - ignored if null/empty
        Returns:
        The path after stripping any trailing '/' provided the path is not '/' itself
      • stripJarURLPrefix

        public static java.lang.String stripJarURLPrefix​(java.lang.String externalForm)
      • getClassBytesURL

        public static java.net.URL getClassBytesURL​(java.lang.Class<?> clazz)
        Parameters:
        clazz - The request Class
        Returns:
        A URL to the location of the .class file - null if location could not be resolved
      • getClassBytesResourceName

        public static java.lang.String getClassBytesResourceName​(java.lang.Class<?> clazz)
      • getClassBytesResourceName

        public static java.lang.String getClassBytesResourceName​(java.lang.String name)
        Parameters:
        name - The fully qualified class name - ignored if null/empty
        Returns:
        The relative path of the class file byte-code resource
      • resolve

        public static java.nio.file.Path resolve​(java.nio.file.Path root,
                                                 java.lang.String... children)
      • resolve

        public static java.nio.file.Path resolve​(java.nio.file.Path root,
                                                 java.util.Collection<java.lang.String> children)
      • detectTargetFolder

        public static java.nio.file.Path detectTargetFolder​(java.lang.Class<?> anchor)
        Parameters:
        anchor - An anchor Class whose container we want to use as the starting point for the "target" folder lookup up the hierarchy
        Returns:
        The "target" folder - null if not found
        See Also:
        detectTargetFolder(Path)
      • getClassContainerLocationPath

        public static java.nio.file.Path getClassContainerLocationPath​(java.lang.Class<?> clazz)
                                                                throws java.lang.IllegalArgumentException
        Parameters:
        clazz - A Class object
        Returns:
        A Path of the location of the class bytes container - e.g., the root folder, the containing JAR, etc.. Returns null if location could not be resolved
        Throws:
        java.lang.IllegalArgumentException - If location is not a valid Path location
        See Also:
        getClassContainerLocationURI(Class), toPathSource(URI)
      • toPathSource

        public static java.nio.file.Path toPathSource​(java.net.URL url)
                                               throws java.net.MalformedURLException
        Converts a URL that may refer to an internal resource to a Path representing is "source" container (e.g., if it is a resource in a JAR, then the result is the JAR's path)
        Parameters:
        url - The URL - ignored if null
        Returns:
        The matching Path
        Throws:
        java.net.MalformedURLException - If source URL does not refer to a file location
        See Also:
        toPathSource(URI)
      • toPathSource

        public static java.nio.file.Path toPathSource​(java.net.URI uri)
                                               throws java.net.MalformedURLException
        Converts a URI that may refer to an internal resource to a Path representing is "source" container (e.g., if it is a resource in a JAR, then the result is the JAR's path)
        Parameters:
        uri - The URI - ignored if null
        Returns:
        The matching Path
        Throws:
        java.net.MalformedURLException - If source URI does not refer to a file location
        See Also:
        getURLSource(URI)
      • detectTargetFolder

        public static java.nio.file.Path detectTargetFolder​(java.nio.file.Path anchorFile)
        Parameters:
        anchorFile - An anchor Path we want to use as the starting point for the "target" or "build" folder lookup up the hierarchy
        Returns:
        The "target" folder - null if not found
      • generateKeyPair

        public static java.security.KeyPair generateKeyPair​(java.lang.String algorithm,
                                                            int keySize)
                                                     throws java.security.GeneralSecurityException
        Throws:
        java.security.GeneralSecurityException
      • createTestHostKeyProvider

        public static org.apache.sshd.common.keyprovider.KeyPairProvider createTestHostKeyProvider​(java.lang.Class<?> anchor)
      • createTestHostKeyProvider

        public static org.apache.sshd.common.keyprovider.KeyPairProvider createTestHostKeyProvider​(java.nio.file.Path path)
      • getFirstKeyPair

        public static java.security.KeyPair getFirstKeyPair​(org.apache.sshd.common.keyprovider.KeyPairProviderHolder holder)
      • getFirstKeyPair

        public static java.security.KeyPair getFirstKeyPair​(org.apache.sshd.common.keyprovider.KeyIdentityProvider provider)
      • getFile

        private static java.nio.file.Path getFile​(java.lang.String resource)
      • createTestKeyPairProvider

        public static org.apache.sshd.common.keyprovider.FileKeyPairProvider createTestKeyPairProvider​(java.lang.String resource)
      • validateKeyPairProvider

        public static <P extends org.apache.sshd.common.keyprovider.KeyIdentityProvider> P validateKeyPairProvider​(P provider)