GcsStorageServiceImpl.java

1
package com.edtech.service;
2
3
import com.google.cloud.storage.BlobId;
4
import com.google.cloud.storage.BlobInfo;
5
import com.google.cloud.storage.Storage;
6
import java.net.URL;
7
import java.util.concurrent.TimeUnit;
8
import org.springframework.beans.factory.annotation.Value;
9
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
10
import org.springframework.stereotype.Service;
11
import org.springframework.web.multipart.MultipartFile;
12
13
/** Documentação para GcsStorageServiceImpl. */
14
@Service
15
@ConditionalOnProperty(name = "storage.provider", havingValue = "gcs", matchIfMissing = true)
16
public class GcsStorageServiceImpl implements StorageService {
17
18
  private final Storage storage;
19
20
  @Value("${gcp.bucket}")
21
  private String bucketName;
22
23
  /** Documentação para o método GcsStorageServiceImpl. */
24
  public GcsStorageServiceImpl(Storage storage) {
25
    this.storage = storage;
26
  }
27
28
  @Override
29
  public void uploadFile(MultipartFile file, String fileKey, String contentType) throws Exception {
30
    BlobId blobId = BlobId.of(bucketName, fileKey);
31
    BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setContentType(contentType).build();
32
    storage.create(blobInfo, file.getBytes());
33
  }
34
35
  @Override
36
  public String getPresignedUrl(String fileKey) throws Exception {
37
    BlobId blobId = BlobId.of(bucketName, fileKey);
38
    URL signedUrl =
39
        storage.signUrl(
40
            blobInfoForPresigned(blobId),
41
            15,
42
            TimeUnit.MINUTES,
43
            Storage.SignUrlOption.withV4Signature());
44 1 1. getPresignedUrl : replaced return value with "" for com/edtech/service/GcsStorageServiceImpl::getPresignedUrl → KILLED
    return signedUrl.toString();
45
  }
46
47
  private BlobInfo blobInfoForPresigned(BlobId blobId) {
48 1 1. blobInfoForPresigned : replaced return value with null for com/edtech/service/GcsStorageServiceImpl::blobInfoForPresigned → KILLED
    return BlobInfo.newBuilder(blobId).build();
49
  }
50
51
  @Override
52
  public void deleteFile(String fileKey) throws Exception {
53
    BlobId blobId = BlobId.of(bucketName, fileKey);
54
    storage.delete(blobId);
55
  }
56
}

Mutations

44

1.1
Location : getPresignedUrl
Killed by : com.edtech.service.GcsStorageServiceImplTest.[engine:junit-jupiter]/[class:com.edtech.service.GcsStorageServiceImplTest]/[method:testGetPresignedUrl()]
replaced return value with "" for com/edtech/service/GcsStorageServiceImpl::getPresignedUrl → KILLED

48

1.1
Location : blobInfoForPresigned
Killed by : com.edtech.service.GcsStorageServiceImplTest.[engine:junit-jupiter]/[class:com.edtech.service.GcsStorageServiceImplTest]/[method:testGetPresignedUrl()]
replaced return value with null for com/edtech/service/GcsStorageServiceImpl::blobInfoForPresigned → KILLED

Active mutators

Tests examined


Report generated by PIT 1.16.1