1
+ package com .provectus .kafka .ui .service ;
2
+
3
+ import static org .assertj .core .api .Assertions .assertThatThrownBy ;
4
+
5
+ import com .provectus .kafka .ui .AbstractBaseTest ;
6
+ import com .provectus .kafka .ui .mapper .ClusterMapperImpl ;
7
+ import com .provectus .kafka .ui .mapper .DescribeLogDirsMapper ;
8
+ import com .provectus .kafka .ui .model .BrokerDTO ;
9
+ import com .provectus .kafka .ui .model .KafkaCluster ;
10
+ import java .util .Properties ;
11
+ import org .junit .jupiter .api .BeforeEach ;
12
+ import org .junit .jupiter .api .Test ;
13
+ import org .springframework .test .context .ContextConfiguration ;
14
+ import reactor .test .StepVerifier ;
15
+
16
+ @ ContextConfiguration (initializers = {AbstractBaseTest .Initializer .class })
17
+ class BrokerServiceTest extends AbstractBaseTest {
18
+ private final KafkaCluster kafkaCluster =
19
+ KafkaCluster .builder ()
20
+ .name (LOCAL )
21
+ .bootstrapServers (kafka .getBootstrapServers ())
22
+ .properties (new Properties ())
23
+ .build ();
24
+
25
+ private BrokerService brokerService ;
26
+
27
+ @ BeforeEach
28
+ void init () {
29
+ AdminClientServiceImpl adminClientService = new AdminClientServiceImpl ();
30
+ adminClientService .setClientTimeout (5_000 );
31
+ brokerService =
32
+ new BrokerService (new MetricsCache (), adminClientService , new DescribeLogDirsMapper (), new ClusterMapperImpl ());
33
+ }
34
+
35
+ @ Test
36
+ void getBrokersNominal () {
37
+ BrokerDTO brokerdto = new BrokerDTO ();
38
+ brokerdto .setId (1 );
39
+ brokerdto .setHost ("localhost" );
40
+ String port = kafka .getBootstrapServers ().substring (kafka .getBootstrapServers ().lastIndexOf (":" ) + 1 );
41
+ brokerdto .setPort (Integer .parseInt (port ));
42
+
43
+ StepVerifier .create (brokerService .getBrokers (kafkaCluster ))
44
+ .expectNext (brokerdto )
45
+ .verifyComplete ();
46
+ }
47
+
48
+ @ Test
49
+ void getBrokersNull () {
50
+ assertThatThrownBy (() -> brokerService .getBrokers (null )).isInstanceOf (NullPointerException .class );
51
+ }
52
+
53
+ @ Test
54
+ void getBrokersEmpty () {
55
+ assertThatThrownBy (() -> brokerService .getBrokers (KafkaCluster .builder ().build ())).isInstanceOf (
56
+ NullPointerException .class );
57
+ }
58
+
59
+ }
0 commit comments