MockAttachmentStorage
Keywords: net.corda.testing.services.MockAttachmentStorage class
Date: 2023-09-18

net.corda.testing.services

## Class MockAttachmentStorage

- net.corda.core.serialization.SingletonSerializeAsToken
- - net.corda.testing.services.MockAttachmentStorage

- All Implemented Interfaces:
    AttachmentStorage, SerializeAsToken

      public class MockAttachmentStorage
      extends SingletonSerializeAsToken
      implements AttachmentStorage

  A mock implementation of `interface AttachmentStorage` for use within tests

  See Also:
    `interface AttachmentStorage`

- - ### Constructor Detail

    - #### MockAttachmentStorage

          public MockAttachmentStorage()

      A mock implementation of `interface AttachmentStorage` for use within tests

      See Also:
        `interface AttachmentStorage`

  - ### Method Detail

    - #### getFiles

          @NotNull
          public java.util.Map<net.corda.core.crypto.SecureHash,kotlin.Pair> getFiles()

      A map of the currently stored files by their `class SecureHash`

      See Also:
        `class SecureHash`

    - #### importAttachment

          @NotNull
          public SecureHash importAttachment(@NotNull
                                                      java.io.InputStream jar)

      Inserts the given attachment into the store, does not close the input stream. This can be an intensive operation due to the need to copy the bytes to disk and hash them along the way.

      Note that you should not pass a java.util.jar.JarInputStream into this method and it will throw if you do, because access to the raw byte stream is required.

      Throws:
        `FileAlreadyExistsException` - if the given byte stream has already been inserted.
        `IllegalArgumentException` - if the given byte stream is empty or a java.util.jar.JarInputStream.
        `IOException` - if something went wrong.
      See Also:
        java.util.jar.JarInputStream

    - #### importAttachment

          @NotNull
          public SecureHash importAttachment(@NotNull
                                                      java.io.InputStream jar,
                                                      @NotNull
                                                      java.lang.String uploader,
                                                      @Nullable
                                                      java.lang.String filename)

      Inserts the given attachment with additional metadata, see `importAttachment` for input stream handling Extra parameters:

      Parameters:
        `uploader` - Uploader name
        `filename` - Name of the file
      See Also:
        `importAttachment`

    - #### openAttachment

          @Nullable
          public Attachment openAttachment(@NotNull
                                                     SecureHash id)

      Returns a handle to a locally stored attachment, or null if it's not known. The handle can be used to open a stream for the data, which will be a zip/jar file.

    - #### queryAttachments

          @NotNull
          public java.util.List<net.corda.core.crypto.SecureHash> queryAttachments(@NotNull
                                                                                            AttachmentQueryCriteria criteria,
                                                                                            @Nullable
                                                                                            AttachmentSort sorting)

      Searches attachment using given criteria and optional sort rules

      Parameters:
        `criteria` - Query criteria to use as a filter
        `sorting` - Sorting definition, if not given, order is undefined
      Returns:
        List of AttachmentId of attachment matching criteria, sorted according to given sorting parameter

    - #### hasAttachment

          public boolean hasAttachment(@NotNull
                                       SecureHash attachmentId)

      Searches for an attachment already in the store

      Parameters:
        `attachmentId` - The attachment Id
      Returns:
        true if it's in there

    - #### importOrGetAttachment

          @NotNull
          public SecureHash importOrGetAttachment(@NotNull
                                                           java.io.InputStream jar)

      Inserts or returns Attachment Id of attachment. Does not throw an exception if already uploaded.

      Parameters:
        `jar` - InputStream of Jar file
      Returns:
        AttachmentId of uploaded attachment

    - #### importContractAttachment

          @JvmOverloads
           @NotNull
          public SecureHash importContractAttachment(@NotNull
                                                                             java.util.List<java.lang.String> contractClassNames,
                                                                             @NotNull
                                                                             java.lang.String uploader,
                                                                             @NotNull
                                                                             java.io.InputStream jar,
                                                                             @Nullable
                                                                             SecureHash attachmentId,
                                                                             @NotNull
                                                                             java.util.List<? extends java.security.PublicKey> signers)

    - #### importContractAttachment

          @JvmOverloads
           @NotNull
          public SecureHash importContractAttachment(@NotNull
                                                                             java.util.List<java.lang.String> contractClassNames,
                                                                             @NotNull
                                                                             java.lang.String uploader,
                                                                             @NotNull
                                                                             java.io.InputStream jar,
                                                                             @Nullable
                                                                             SecureHash attachmentId)

    - #### importContractAttachment

          @JvmOverloads
           @NotNull
          public SecureHash importContractAttachment(@NotNull
                                                                             java.util.List<java.lang.String> contractClassNames,
                                                                             @NotNull
                                                                             java.lang.String uploader,
                                                                             @NotNull
                                                                             java.io.InputStream jar)

    - #### importContractAttachment

          public void importContractAttachment(@NotNull
                                               SecureHash attachmentId,
                                               @NotNull
                                               ContractAttachment contractAttachment)

    - #### getAttachmentIdAndBytes

          @NotNull
          public kotlin.Pair<net.corda.core.crypto.SecureHash,kotlin.Array[]> getAttachmentIdAndBytes(@NotNull
                                                                                                               java.io.InputStream jar)

    - #### getLatestContractAttachments

          @NotNull
          public java.util.List<net.corda.core.crypto.SecureHash> getLatestContractAttachments(@NotNull
                                                                                                        java.lang.String contractClassName,
                                                                                                        int minContractVersion)

      Find the Attachment Id(s) of the contract attachments with the highest version for a given contract class name from trusted upload sources. Return highest version of both signed and unsigned attachment ids (signed first, unsigned second), otherwise return a single signed or unsigned version id, or an empty list if none meet the criteria.

      Parameters:
        `contractClassName` - The fully qualified name of the contract class.
        `minContractVersion` - The minimum contract version that should be returned.
      Returns:
        the AttachmentIds of the contract attachments (signed always first in list), or an empty list if none meet the criteria.