Reputation: 71
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)
Upvotes: 4
Views: 5648
Reputation: 1
The following solution worked for me on Win11:
docker login index.docker.io
Upvotes: 0
Reputation: 41
The fix that worked for me on an M1 Mac was:
credsStore:desktop
from ~/.docker/config.jsondocker login
in terminalUpvotes: 0
Reputation: 61
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
Upvotes: 4
Reputation: 71
netcfg -d
in Command Prompt then restart your PC.
This worked for meReference
https://github.com/testcontainers/testcontainers-java/issues/3422
Upvotes: 1