1
+ package io .microsphere .spring .cloud .client .event ;
2
+
3
+ import org .junit .jupiter .api .BeforeEach ;
4
+ import org .junit .jupiter .api .Test ;
5
+ import org .springframework .cloud .client .DefaultServiceInstance ;
6
+ import org .springframework .cloud .client .ServiceInstance ;
7
+
8
+ import java .net .URI ;
9
+ import java .util .Arrays ;
10
+ import java .util .UUID ;
11
+
12
+
13
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
14
+ import static org .junit .jupiter .api .Assertions .assertFalse ;
15
+ import static org .junit .jupiter .api .Assertions .assertSame ;
16
+ import static org .junit .jupiter .api .Assertions .assertTrue ;
17
+
18
+ /**
19
+ * {@link ServiceInstancesChangedEvent} Test
20
+ *
21
+ * @author <a href="mailto:[email protected] ">Mercy<a/>
22
+ * @see ServiceInstancesChangedEvent
23
+ * @since 1.0.0
24
+ */
25
+ public class ServiceInstancesChangedEventTest {
26
+
27
+ private String serviceName = "testService" ;
28
+
29
+ private ServiceInstancesChangedEvent event ;
30
+
31
+ private ServiceInstance instance ;
32
+
33
+ @ BeforeEach
34
+ public void init () {
35
+ this .instance = createInstance (serviceName );
36
+ this .event = new ServiceInstancesChangedEvent (serviceName , Arrays .asList (instance ));
37
+ }
38
+
39
+ private ServiceInstance createInstance (String serviceName ) {
40
+ DefaultServiceInstance instance = new DefaultServiceInstance ();
41
+ instance .setServiceId (serviceName );
42
+ instance .setServiceId (UUID .randomUUID ().toString ());
43
+ instance .setHost ("127.0.0.1" );
44
+ instance .setPort (8080 );
45
+ instance .setUri (URI .create ("http://127.0.0.1:8080/info" ));
46
+ return instance ;
47
+ }
48
+
49
+ @ Test
50
+ public void testGetServiceName () {
51
+ assertEquals (this .serviceName , this .event .getServiceName ());
52
+ assertEquals (this .serviceName , this .event .getSource ());
53
+ }
54
+
55
+ @ Test
56
+ public void testGetServiceInstances () {
57
+ assertEquals (Arrays .asList (this .instance ), this .event .getServiceInstances ());
58
+ assertEquals (this .instance , this .event .getServiceInstances ().get (0 ));
59
+ assertSame (this .instance , this .event .getServiceInstances ().get (0 ));
60
+ }
61
+
62
+ @ Test
63
+ public void testProcessed () {
64
+ assertFalse (this .event .isProcessed ());
65
+ this .event .processed ();
66
+ assertTrue (this .event .isProcessed ());
67
+ }
68
+ }
0 commit comments