I have added testcontainer in spring boot app
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@SpringBootTest
@Testcontainers
@AutoConfigureMockMvc
class ProductServiceApplicationTests {
@Container
static MongoDBContainer mongoDBContainer = new MongoDBContainer("mongo:4.4.2");
@Autowired
private MockMvc mockMvc;
@Autowired
private ObjectMapper objectMapper;
@DynamicPropertySource
static void setProperties(DynamicPropertyRegistry dynamicPropertyRegistry) {
dynamicPropertyRegistry.add("spring.data.mongodb.uri",mongoDBContainer::getReplicaSetUrl);
}
@Test
void shouldCreateProduct() throws Exception {
ProductRequest productRequest = getProductRequest();
String productRequestString = objectMapper.writeValueAsString(productRequest);
mockMvc.perform(MockMvcRequestBuilders.post("/api/product")
.contentType(MediaType.APPLICATION_JSON)
.content(productRequestString)
).andExpect(status().isCreated()) ;
}
private ProductRequest getProductRequest() {
return ProductRequest.builder()
.name("Iphone 13")
.description("Iphone 13")
.price(BigDecimal.valueOf(1200))
.build();
}
}
When Running it Getting the below error
com.github.dockerjava.api.exception.InternalServerErrorException: Status 500: {"message":"Head "https://registry-1.docker.io/v2/testcontainers/ryuk/manifests/0.3.0": unauthorized: incorrect username or password"}
at org.testcontainers.shaded.com.github.dockerjava.core.DefaultInvocationBuilder.execute(DefaultInvocationBuilder.java:247)
at org.testcontainers.shaded.com.github.dockerjava.core.DefaultInvocationBuilder.lambda$executeAndStream$1(DefaultInvocationBuilder.java:269)
at java.lang.Thread.run(Thread.java:748)
This helped me:
$ docker logout
$ docker login --username your_username_here
Found it here - https://forums.docker.com/t/unauthorized-incorrect-username-or-password/35677/4
netcfg -d
in Command Prompt then restart your PC.
This worked for meReference
https://github.com/testcontainers/testcontainers-java/issues/3422
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With