Код: Выделить всё
@RequiredArgsConstructor
@Service
public class S3StorageService implements StorageService {
private final S3Client client;
// ...
}
Код: Выделить всё
@RequiredArgsConstructor
@Service
public class SongServiceImpl implements SongService {
private final StorageService storageService;
@Transactional
@Override
public Song uploadSong(UploadSongDTO dto) {
// ...
storageService.upload(dto.file());
}
}
Код: Выделить всё
@RequiredArgsConstructor
@RequestMapping("/song")
@RestController
public class SongController {
private final SongService songService;
@PostMapping("/upload")
public ResponseEntity upload(@Valid UploadSongDTO dto) {
return ResponseEntity.ok(songService.uploadSong(dto));
}
}
Код: Выделить всё
static S3MockContainer s3Mock = new S3MockContainer("latest");
@BeforeEach
void setUp() {
final String endpoint = s3Mock.getHttpsEndpoint();
final S3Configuration serviceConfig = S3Configuration.builder()
.pathStyleAccessEnabled(true)
.build();
final SdkHttpClient httpClient = UrlConnectionHttpClient.builder()
.buildWithDefaults(AttributeMap.builder()
.put(TRUST_ALL_CERTIFICATES, Boolean.TRUE)
.build());
final S3Client s3Client = S3Client.builder() // somehow inject this into S3StorageService
.region(Region.of("auto"))
.endpointOverride(URI.create(endpoint))
.serviceConfiguration(serviceConfig)
.httpClient(httpClient)
.build();
applicationContext.registerBean(S3Client.class, () -> s3Client); // does not work. `Parameter 0 of constructor in me.approximations.music.services.storage.impl.S3StorageService required a bean of type 'software.amazon.awssdk.services.s3.S3Client' that could not be found.`
}
Подробнее здесь: https://stackoverflow.com/questions/786 ... tion-tests