0

While running mvn clean install I am getting these errors:

java.lang.ExceptionInInitializerError
        at abcConverterTest.setup(abcConverterTest.java:33)
Caused by: org.apache.kafka.common.KafkaException: Failed to construct kafka producer
        at abcConverterTest.setup(abcConverterTest.java:33)
Caused by: org.apache.kafka.common.config.ConfigException: Invalid url in bootstrap.servers:     ${env:GRAYLOG_BOOTSTRAP_SERVER} at abcConverterTest.setup(abcConverterTest.java:33)
class abcConverterTest {

    private abcConverter abcConverter;
    @Mock private ObjectMapper objectMapper;
    private static final String value = "xyz";
    List<Object> detailsList = new ArrayList<>();
    Map<String, Object> details = new HashMap<>();
    Map<String, Object> details2 = new HashMap<>();
    Map<String, Object> details3 = new HashMap<>();

    @BeforeEach
    public void setup() {
        MockitoAnnotations.initMocks(this);
        this.abcConverter = new abcConverter(objectMapper); // this is line 33

        details.put("key", "abcd");
        details.put("value", "pqrs");

        details2.put("key", "abcd1");
        details2.put("value", "pqrs1");

        details3.put("key", "abcd2");
        details3.put("value", "pqrs2");

        detailsList.add(details);
        detailsList.add(details2);
        detailsList.add(details3);
    }

    @Test
    void testConvertArguements() {
        String result = abcConverter.convertToColumn(null);
        Assertions.assertNull(result);
    }
}
@Slf4j
@Component
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class abcConverter implements AttributeConverter<List<Object>, String> {

    private final ObjectMapper objectMapper;
    ......
    ......

}

I was trying to run test cases, its working fine when I am running test cases individually (adding GRAYLOG_BOOTSTRAP_SERVER=some_value in config) . but failing when running mvn clean install

Abhi
  • 1
  • is your test case running without providing the value for GRAYLOG_BOOTSTRAP_SERVER ? or are you getting the same error when you don't provide the value when running the test case individually. If you are getting the same error it means that you are not setting the value for GRAYLOG_BOOTSTRAP_SERVER correctly while running the test case. why do you have to set the value manually ? you need to provide the value for that variable to your testcase. go through below URL : https://stackoverflow.com/questions/29669393/override-default-spring-boot-application-properties-settings-in-junit-test – Ashish Kathait Dec 30 '22 at 07:26
  • Also add the code in your class abcConverter – Ashish Kathait Dec 30 '22 at 07:28
  • no, test cases are throwing the same errors if ran without providing the config value. sure let me try this out. – Abhi Dec 30 '22 at 07:32
  • no, still getting same error. – Abhi Dec 30 '22 at 07:41

0 Answers0