1+ /*
2+ * Copyright Kroxylicious Authors.
3+ *
4+ * Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5+ */
6+
7+ package io .kroxylicious .kubernetes .operator .assertj ;
8+
9+ import java .time .Instant ;
10+ import java .util .List ;
11+ import java .util .Map ;
12+ import java .util .Optional ;
13+
14+ import org .assertj .core .api .Assert ;
15+ import org .junit .jupiter .api .Test ;
16+
17+ import io .kroxylicious .kubernetes .api .common .Condition ;
18+ import io .kroxylicious .kubernetes .api .common .ConditionBuilder ;
19+ import io .kroxylicious .kubernetes .api .v1alpha1 .KafkaProxyIngressBuilder ;
20+ import io .kroxylicious .kubernetes .api .v1alpha1 .KafkaProxyStatusBuilder ;
21+ import io .kroxylicious .kubernetes .api .v1alpha1 .KafkaServiceStatusBuilder ;
22+ import io .kroxylicious .kubernetes .api .v1alpha1 .kafkaproxystatus .ClustersBuilder ;
23+ import io .kroxylicious .proxy .config .Configuration ;
24+ import io .kroxylicious .proxy .config .PortIdentifiesNodeIdentificationStrategy ;
25+ import io .kroxylicious .proxy .config .TargetCluster ;
26+ import io .kroxylicious .proxy .config .VirtualCluster ;
27+ import io .kroxylicious .proxy .config .VirtualClusterGateway ;
28+ import io .kroxylicious .proxy .service .HostPort ;
29+
30+ import static org .assertj .core .api .BDDAssertions .then ;
31+
32+ class OperatorAssertionsTest {
33+
34+ public static final String ANNOTATION_A = "AnnotationA" ;
35+ public static final long OBSERVED_GENERATION = 2L ;
36+
37+ @ Test
38+ void shouldReturnKafkaProxyStatusAssert () {
39+ // Given
40+ var kafkaProxyStatus = new KafkaProxyStatusBuilder ().withObservedGeneration (OBSERVED_GENERATION ).build ();
41+
42+ // When
43+ Assert <?, ?> actualAssertion = OperatorAssertions .assertThat (kafkaProxyStatus );
44+
45+ // Then
46+ then (actualAssertion ).isInstanceOf (KafkaProxyStatusAssert .class );
47+ }
48+
49+ @ Test
50+ void shouldReturnKafkaServiceStatusAssert () {
51+ // Given
52+ var kafkaProxyStatus = new KafkaServiceStatusBuilder ().withObservedGeneration (OBSERVED_GENERATION ).build ();
53+
54+ // When
55+ Assert <?, ?> actualAssertion = OperatorAssertions .assertThat (kafkaProxyStatus );
56+
57+ // Then
58+ then (actualAssertion ).isInstanceOf (KafkaServiceStatusAssert .class );
59+ }
60+
61+ @ Test
62+ void shouldReturnClusterAssert () {
63+ // Given
64+ var clusters = new ClustersBuilder ().withName ("wibble" ).build ();
65+
66+ // When
67+ Assert <?, ?> actualAssertion = OperatorAssertions .assertThat (clusters );
68+
69+ // Then
70+ then (actualAssertion ).isInstanceOf (ClusterAssert .class );
71+ }
72+
73+ @ Test
74+ void shouldReturnConditionAssert () {
75+ // Given
76+ var conditions = new ConditionBuilder ()
77+ .withType (Condition .Type .Ready )
78+ .withObservedGeneration (OBSERVED_GENERATION )
79+ .withLastTransitionTime (Instant .now ())
80+ .withMessage ("message" )
81+ .withReason ("Reason" )
82+ .build ();
83+
84+ // When
85+ Assert <?, ?> actualAssertion = OperatorAssertions .assertThat (conditions );
86+
87+ // Then
88+ then (actualAssertion ).isInstanceOf (ConditionAssert .class );
89+ }
90+
91+ @ Test
92+ void shouldReturnConfigurationAssert () {
93+ // Given
94+ var configurations = new Configuration (null ,
95+ List .of (),
96+ List .of (),
97+ List .of (new VirtualCluster ("Bob" ,
98+ new TargetCluster ("" , Optional .empty ()),
99+ null ,
100+ Optional .empty (),
101+ List .of (new VirtualClusterGateway ("gateway" ,
102+ new PortIdentifiesNodeIdentificationStrategy (new HostPort ("localhost" , 9090 ), null , null , List .of ()),
103+ null ,
104+ Optional .empty ())),
105+ false ,
106+ false ,
107+ List .of ())),
108+ List .of (),
109+ false ,
110+ Optional .empty ());
111+
112+ // When
113+ Assert <?, ?> actualAssertion = OperatorAssertions .assertThat (configurations );
114+
115+ // Then
116+ then (actualAssertion ).isInstanceOf (ProxyConfigAssert .class );
117+ }
118+
119+ @ Test
120+ void shouldReturnMetadataAssert () {
121+ // Given
122+ var thingWithMetadata = new KafkaProxyIngressBuilder ()
123+ .withNewMetadata ()
124+ .withName ("thing" )
125+ .withAnnotations (Map .of (ANNOTATION_A , "VALUE_1" ))
126+ .endMetadata ()
127+ .build ();
128+
129+ // When
130+ Assert <?, ?> actualAssertion = OperatorAssertions .assertThat (thingWithMetadata );
131+
132+ // Then
133+ then (actualAssertion ).isInstanceOf (MetadataAssert .class );
134+ }
135+ }
0 commit comments