Skip to content

Commit

Permalink
removes producer side code
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadileepkolli committed May 12, 2023
1 parent 0f726d6 commit 2b99035
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringBootKafkaAvroApplication {
public class SpringBootKafkaAvroConsumerApplication {

public static void main(String[] args) {
SpringApplication.run(SpringBootKafkaAvroApplication.class, args);
SpringApplication.run(SpringBootKafkaAvroConsumerApplication.class, args);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.example.springbootkafkaavro.service;
package com.example.springbootkafkaavro;

import com.example.springbootkafkaavro.model.Person;
import com.example.springbootkafkaavro.util.ApplicationConstants;

import lombok.RequiredArgsConstructor;

import org.springframework.boot.test.context.TestComponent;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

@Component
@TestComponent
@RequiredArgsConstructor
public class KafkaProducer {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import static java.util.concurrent.TimeUnit.SECONDS;

import com.example.springbootkafkaavro.model.Person;
import com.example.springbootkafkaavro.repository.PersonRepository;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.springframework.test.web.servlet.MockMvc;
Expand All @@ -26,10 +26,12 @@

@SpringBootTest
@AutoConfigureMockMvc
class SpringBootKafkaAvroApplicationTests {
@Import(KafkaProducer.class)
class SpringBootKafkaAvroConsumerApplicationTests {

@Autowired MockMvc mockMvc;
@Autowired PersonRepository personRepository;
@Autowired KafkaProducer kafkaProducer;

private static final Network KAFKA_NETWORK = Network.newNetwork();
private static final String CONFLUENT_PLATFORM_VERSION = "7.4.0";
Expand Down Expand Up @@ -99,9 +101,10 @@ public String getSchemaUrl() {

@Test
void contextLoads() throws Exception {
this.mockMvc
.perform(post("/person/publish").param("name", "junit").param("age", "33"))
.andExpect(status().isOk());
Person person = new Person();
person.setAge(33);
person.setName("junit");
this.kafkaProducer.sendMessage(person);
await().atMost(10, SECONDS)
.untilAsserted(() -> assertThat(personRepository.count()).isEqualTo(1));
}
Expand Down

0 comments on commit 2b99035

Please sign in to comment.