20
20
import com .cloud .service .ServiceOfferingVO ;
21
21
import com .cloud .template .VirtualMachineTemplate ;
22
22
import com .cloud .vm .VirtualMachine ;
23
+ import org .junit .Before ;
24
+ import org .junit .Test ;
25
+ import org .mockito .Mockito ;
26
+
23
27
import java .util .Arrays ;
28
+ import java .util .Collections ;
24
29
import java .util .List ;
30
+ import java .util .Set ;
25
31
32
+ import static org .junit .Assert .assertEquals ;
26
33
import static org .junit .Assert .assertFalse ;
27
34
import static org .junit .Assert .assertTrue ;
28
- import org .junit .Test ;
29
- import org .junit .Before ;
30
- import org .mockito .Mockito ;
31
35
32
36
public class HostVOTest {
33
37
HostVO host ;
@@ -37,7 +41,7 @@ public class HostVOTest {
37
41
public void setUp () throws Exception {
38
42
host = new HostVO ();
39
43
offering = new ServiceOfferingVO ("TestSO" , 0 , 0 , 0 , 0 , 0 ,
40
- false , "TestSO" , false ,VirtualMachine .Type .User ,false );
44
+ false , "TestSO" , false , VirtualMachine .Type .User , false );
41
45
}
42
46
43
47
@ Test
@@ -52,14 +56,14 @@ public void testNoTag() {
52
56
53
57
@ Test
54
58
public void testRightTag () {
55
- host .setHostTags (Arrays .asList ("tag1" ,"tag2" ), false );
59
+ host .setHostTags (Arrays .asList ("tag1" , "tag2" ), false );
56
60
offering .setHostTag ("tag2,tag1" );
57
61
assertTrue (host .checkHostServiceOfferingTags (offering ));
58
62
}
59
63
60
64
@ Test
61
65
public void testWrongTag () {
62
- host .setHostTags (Arrays .asList ("tag1" ,"tag2" ), false );
66
+ host .setHostTags (Arrays .asList ("tag1" , "tag2" ), false );
63
67
offering .setHostTag ("tag2,tag4" );
64
68
assertFalse (host .checkHostServiceOfferingTags (offering ));
65
69
}
@@ -87,40 +91,59 @@ public void checkHostServiceOfferingTagsTestRuleTagWithNullServiceTag() {
87
91
88
92
@ Test
89
93
public void testEitherNoSOOrTemplate () {
90
- assertFalse (host .checkHostServiceOfferingAndTemplateTags (null , Mockito .mock (VirtualMachineTemplate .class )));
91
- assertFalse (host .checkHostServiceOfferingAndTemplateTags (Mockito .mock (ServiceOffering .class ), null ));
94
+ assertFalse (host .checkHostServiceOfferingAndTemplateTags (null , Mockito .mock (VirtualMachineTemplate .class ), null ));
95
+ assertFalse (host .checkHostServiceOfferingAndTemplateTags (Mockito .mock (ServiceOffering .class ), null , null ));
92
96
}
93
97
94
98
@ Test
95
99
public void testNoTagOfferingTemplate () {
96
- assertTrue (host .checkHostServiceOfferingAndTemplateTags (offering , Mockito .mock (VirtualMachineTemplate .class )));
100
+ assertTrue (host .checkHostServiceOfferingAndTemplateTags (offering , Mockito .mock (VirtualMachineTemplate .class ), Collections .emptySet ()));
101
+ assertTrue (host .getHostServiceOfferingAndTemplateMissingTags (offering , Mockito .mock (VirtualMachineTemplate .class ), Collections .emptySet ()).isEmpty ());
102
+ assertTrue (host .checkHostServiceOfferingAndTemplateTags (offering , Mockito .mock (VirtualMachineTemplate .class ), Set .of ("tag1" , "tag2" )));
103
+ assertTrue (host .getHostServiceOfferingAndTemplateMissingTags (offering , Mockito .mock (VirtualMachineTemplate .class ), Set .of ("tag1" , "tag2" )).isEmpty ());
97
104
}
98
105
99
106
@ Test
100
107
public void testRightTagOfferingTemplate () {
101
108
host .setHostTags (Arrays .asList ("tag1" , "tag2" ), false );
102
109
offering .setHostTag ("tag2,tag1" );
103
- assertTrue (host .checkHostServiceOfferingAndTemplateTags (offering , Mockito .mock (VirtualMachineTemplate .class )));
110
+ assertTrue (host .checkHostServiceOfferingAndTemplateTags (offering , Mockito .mock (VirtualMachineTemplate .class ), Set .of ("tag1" )));
111
+ Set <String > actualMissingTags = host .getHostServiceOfferingAndTemplateMissingTags (offering , Mockito .mock (VirtualMachineTemplate .class ), Set .of ("tag1" ));
112
+ assertTrue (actualMissingTags .isEmpty ());
113
+
104
114
host .setHostTags (Arrays .asList ("tag1" , "tag2" , "tag3" ), false );
105
115
offering .setHostTag ("tag2,tag1" );
106
116
VirtualMachineTemplate template = Mockito .mock (VirtualMachineTemplate .class );
107
117
Mockito .when (template .getTemplateTag ()).thenReturn ("tag3" );
108
- assertTrue (host .checkHostServiceOfferingAndTemplateTags (offering , template ));
118
+ assertTrue (host .checkHostServiceOfferingAndTemplateTags (offering , template , Set .of ("tag2" , "tag3" )));
119
+ actualMissingTags = host .getHostServiceOfferingAndTemplateMissingTags (offering , template , Set .of ("tag2" , "tag3" ));
120
+ assertTrue (actualMissingTags .isEmpty ());
109
121
host .setHostTags (List .of ("tag3" ), false );
110
122
offering .setHostTag (null );
111
- assertTrue (host .checkHostServiceOfferingAndTemplateTags (offering , template ));
123
+ assertTrue (host .checkHostServiceOfferingAndTemplateTags (offering , template , Set .of ("tag3" )));
124
+ actualMissingTags = host .getHostServiceOfferingAndTemplateMissingTags (offering , template , Set .of ("tag3" ));
125
+ assertTrue (actualMissingTags .isEmpty ());
126
+
127
+ assertTrue (host .checkHostServiceOfferingAndTemplateTags (offering , template , Set .of ("tag2" , "tag1" )));
128
+ actualMissingTags = host .getHostServiceOfferingAndTemplateMissingTags (offering , template , Set .of ("tag2" , "tag1" ));
129
+ assertTrue (actualMissingTags .isEmpty ());
112
130
}
113
131
114
132
@ Test
115
133
public void testWrongOfferingTag () {
116
- host .setHostTags (Arrays .asList ("tag1" ,"tag2" ), false );
134
+ host .setHostTags (Arrays .asList ("tag1" , "tag2" ), false );
117
135
offering .setHostTag ("tag2,tag4" );
118
136
VirtualMachineTemplate template = Mockito .mock (VirtualMachineTemplate .class );
119
137
Mockito .when (template .getTemplateTag ()).thenReturn ("tag1" );
120
- assertFalse (host .checkHostServiceOfferingAndTemplateTags (offering , template ));
138
+ assertFalse (host .checkHostServiceOfferingAndTemplateTags (offering , template , Set .of ("tag1" , "tag2" , "tag3" , "tag4" )));
139
+ Set <String > actualMissingTags = host .getHostServiceOfferingAndTemplateMissingTags (offering , template , Set .of ("tag1" , "tag2" , "tag3" , "tag4" ));
140
+ assertEquals (Set .of ("tag4" ), actualMissingTags );
141
+
121
142
offering .setHostTag ("tag1,tag2" );
122
143
template = Mockito .mock (VirtualMachineTemplate .class );
123
144
Mockito .when (template .getTemplateTag ()).thenReturn ("tag3" );
124
- assertFalse (host .checkHostServiceOfferingAndTemplateTags (offering , template ));
145
+ actualMissingTags = host .getHostServiceOfferingAndTemplateMissingTags (offering , template , Set .of ("tag1" , "tag2" , "tag3" , "tag4" ));
146
+ assertFalse (host .checkHostServiceOfferingAndTemplateTags (offering , template , Set .of ("tag1" , "tag2" , "tag3" , "tag4" )));
147
+ assertEquals (Set .of ("tag3" ), actualMissingTags );
125
148
}
126
149
}
0 commit comments