skip to Main Content

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();
    }


}

  • I have installed docker desktop and logged it using docker desktop And then try using cli.

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)
Error message in the terminal

2

Answers


  1. Chosen as BEST ANSWER
    1. Run the command netcfg -d in Command Prompt then restart your PC. This worked for me

    Reference
    https://github.com/testcontainers/testcontainers-java/issues/3422


  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search