TestContainers and microservices with Spring Boot

I have 2 microservices:

Service A has an endpoint to create Article entities. This entity has a property Supplier among others. When creating an Article, the corresponding method calls (using Feign) an endpoint from Service B which returns the Supplier if it exists.

@Getter
@Setter
@NoArgsConstructor
@Entity
@EqualsAndHashCode
@Table(name = "article")
public class ArticleDAO {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Integer id;

    @Column(name = "name")
    private String name;

    ...

    @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "supplier_id", referencedColumnName = "id")
    private SupplierDAO supplier;
}

Code to create an Article:

@Override
    public Article createArticle(final Article article, final String usuario) {
        final List<ArticleDAO> articleDAOS;
        
        if(this.suppliersFeignClient.getSupplier(article.getSupplier().getId().getBody() == null)
                // do something
        this.checkArticleDontExistByName(article);
        articles.forEach(article -> article.setUser(usuario));
        articleDAOS = this.modelMapper.map(articles, new TypeToken<List<ArticleDAO>>(){}.getType());
        this.articleRepository.saveAll(articleDAOS);
        return this.modelMapper.map(articleDAOS, new TypeToken<List<Article>>(){}.getType());
    }

Here, I am not finding a way to connect Service A with Service B whith both running a database for integration tests since both use mysql. I would need Service A to run a mysql container using TestContainers and also to run Service B which also needs its own mysql container.

I am learning about Integration Tests with microservices and on my journey I found the TestContainers library which I managed to write tests using a mysql image but without having interaction with other microservices. Now that I have 2 microservices I have no idea at all about how to write the tests for this since Service B also uses mysql.

Can anyone give me any guidance on how to achieve this? Is TestContainers not good for integration tests when there’s more than one service?

I know this question could be a bit tangly, I will add more info or code if needed but so far I just have this in my integration test which works perfectly if I comment this.suppliersFeignClient.getSupplier(article.getSupplier().getId().getBody() == null:

    @ServiceConnection
    @Container
    private static final MySQLContainer<?> mySQLContainer = new MySQLContainer<>(ContainersConstants.MYSQL_CONTAINER_TAG);
    @Autowired
    private TestRestTemplate restTemplate;
    @Autowired
    private ArticlesService articlesService;
    @Autowired
    private ModelMapper modelMapper;
    @Autowired
    private ArticleRepository articleRepository;

    @BeforeAll
    static void beforeAll() {
        mySQLContainer.start();
    }



    @AfterAll
        static void afterAll() {
            mySQLContainer.stop();
        }

    @Test
    @DisplayName("Create articles /articles")
    void WHEN_calling_create_articles_THEN_status_is_200() {
        final List<ArticleDTO> articleDTOS = Instancio.ofList(ArticleDTO.class).size(3)
                .ignore(field(ArticleDTO::getId))
                .ignore(field(ArticleDTO::getCategory))
                .ignore(field(ArticleDTO::getSupplier))
                .create();
        final CreateArticlesRequest createArticlesRequest = CreateArticlesRequest.builder()
                .articles(articleDTOS)
                .user(Instancio.create(String.class))
                .build();
        final ResponseEntity<CreateArticlesResponse> response = restTemplate.exchange(restTemplate.getRootUri() + URIConstants.ARTICLES_URI,
                HttpMethod.POST, new HttpEntity<>(createArticlesRequest), new ParameterizedTypeReference<>() {});
        final List<ArticleDTO> articles = Objects.requireNonNull(response.getBody()).getArticles();

        articles.forEach(article -> article.setId(null));

        assertEquals(articles.size(), articleDTOS.size() , "articles.size() should be " + articleDTOS.size());
        assertTrue(articles.containsAll(articleDTOS), "articles should contain the same elements as articulosDTOS");
        assertEquals(HttpStatus.OK, response.getStatusCode(), "Status Code should be " + HttpStatus.OK);
    }

Thanks

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật