1212*/
1313package io .kubernetes .client .util ;
1414
15- import static org .junit .Assert .*;
16-
15+ import io .kubernetes .client .custom .IntOrString ;
1716import io .kubernetes .client .models .V1ObjectMeta ;
17+ import io .kubernetes .client .models .V1Service ;
18+ import io .kubernetes .client .models .V1ServicePort ;
19+ import org .junit .Test ;
20+
1821import java .io .StringReader ;
1922import java .lang .reflect .Method ;
20- import org .junit .Test ;
23+
24+ import static org .junit .Assert .*;
2125
2226public class YamlTest {
2327 @ Test
2428 public void testLoad () {
25- String [] kinds = new String [] {"Pod" , "Deployment" , "ClusterRole" , "APIService" , "Scale" };
29+ String [] kinds = new String []{"Pod" , "Deployment" , "ClusterRole" , "APIService" , "Scale" };
2630 String [] apiVersions =
27- new String [] {"v1" , "v1beta2" , "v1alpha1" , "v1beta1" , "extensions/v1beta1" };
31+ new String []{"v1" , "v1beta2" , "v1alpha1" , "v1beta1" , "extensions/v1beta1" };
2832 String [] classNames =
29- new String [] {
30- "V1Pod" ,
31- "V1beta2Deployment" ,
32- "V1alpha1ClusterRole" ,
33- "V1beta1APIService" ,
34- "ExtensionsV1beta1Scale"
35- };
33+ new String []{
34+ "V1Pod" ,
35+ "V1beta2Deployment" ,
36+ "V1alpha1ClusterRole" ,
37+ "V1beta1APIService" ,
38+ "ExtensionsV1beta1Scale"
39+ };
3640 for (int i = 0 ; i < kinds .length ; i ++) {
3741 String kind = kinds [i ];
3842 String className = classNames [i ];
3943 try {
4044 String input =
41- "kind: "
42- + kind
43- + "\n "
44- + "apiVersion: "
45- + apiVersions [i ]
46- + "\n "
47- + "metadata:\n "
48- + " name: foo" ;
45+ "kind: "
46+ + kind
47+ + "\n "
48+ + "apiVersion: "
49+ + apiVersions [i ]
50+ + "\n "
51+ + "metadata:\n "
52+ + " name: foo" ;
4953 Object obj = Yaml .load (new StringReader (input ));
5054 Method m = obj .getClass ().getMethod ("getMetadata" );
5155 V1ObjectMeta metadata = (V1ObjectMeta ) m .invoke (obj );
@@ -57,4 +61,21 @@ public void testLoad() {
5761 }
5862 }
5963 }
64+
65+ @ Test
66+ public void testLoadIntOrString () {
67+ try {
68+ String strInput = "targetPort: test" ;
69+ String intInput = "targetPort: 1" ;
70+
71+ V1ServicePort stringPort = Yaml .loadAs (strInput , V1ServicePort .class );
72+ V1ServicePort intPort = Yaml .loadAs (intInput , V1ServicePort .class );
73+
74+ assertFalse ("Target port for 'stringPort' was parsed to an integer, string expected." , stringPort .getTargetPort ().isInteger ());
75+ assertTrue ("Target port for 'intPort' was parsed to a string, integer expected." , intPort .getTargetPort ().isInteger ());
76+
77+ } catch (Exception ex ) {
78+ assertNull ("Unexpected exception: " + ex .toString (), ex );
79+ }
80+ }
6081}
0 commit comments