@Test void testServiceDifferenceFromClusterAndAsObject() { Service serviceFromCluster = new ServiceBuilder() .withNewMetadata() .withCreationTimestamp("2020-07-27T10:36:33Z") .withName("my-service") .withNamespace("default") .withResourceVersion("202998") .withSelfLink("/api/v1/namespaces/default/services/my-service") .withUid("99fe3964-b53b-473f-b1d8-bdb0390d1634") .endMetadata() .withNewSpec() .withClusterIP("10.110.153.70") .addNewPort() .withPort(80) .withProtocol("TCP") .withTargetPort(new IntOrString("9376")) .endPort() .addToSelector(Collections.singletonMap("app", "MyApp")) .withType("ClusterIP") .endSpec() .build(); Service serviceAsObj = new ServiceBuilder() .withNewMetadata().withName("my-service").endMetadata() .withNewSpec() .addToSelector(Collections.singletonMap("app", "MyApp")) .addNewPort() .withPort(80) .withProtocol("TCP") .withTargetPort(new IntOrString("9376")) .endPort() .endSpec() .build(); boolean result = ResourceCompare.equals(serviceFromCluster, serviceAsObj); assertTrue(result); }
public static <T> boolean equals(T left, T right) { ObjectMapper jsonMapper = Serialization.jsonMapper(); if (left == null && right == null) { return true; } else if (left == null) { return false; } else if (right == null) { return false; } Map<String, Object> leftJson = jsonMapper.convertValue(left, TYPE_REF); Map<String, Object> rightJson = jsonMapper.convertValue(right, TYPE_REF); if (left instanceof KubernetesList) { return compareKubernetesList(leftJson, rightJson); } else { return compareKubernetesResource(leftJson, rightJson); } }
ResourceCompare { public static <T> boolean equals(T left, T right) { ObjectMapper jsonMapper = Serialization.jsonMapper(); if (left == null && right == null) { return true; } else if (left == null) { return false; } else if (right == null) { return false; } Map<String, Object> leftJson = jsonMapper.convertValue(left, TYPE_REF); Map<String, Object> rightJson = jsonMapper.convertValue(right, TYPE_REF); if (left instanceof KubernetesList) { return compareKubernetesList(leftJson, rightJson); } else { return compareKubernetesResource(leftJson, rightJson); } } }
ResourceCompare { public static <T> boolean equals(T left, T right) { ObjectMapper jsonMapper = Serialization.jsonMapper(); if (left == null && right == null) { return true; } else if (left == null) { return false; } else if (right == null) { return false; } Map<String, Object> leftJson = jsonMapper.convertValue(left, TYPE_REF); Map<String, Object> rightJson = jsonMapper.convertValue(right, TYPE_REF); if (left instanceof KubernetesList) { return compareKubernetesList(leftJson, rightJson); } else { return compareKubernetesResource(leftJson, rightJson); } } private  ResourceCompare(); }
ResourceCompare { public static <T> boolean equals(T left, T right) { ObjectMapper jsonMapper = Serialization.jsonMapper(); if (left == null && right == null) { return true; } else if (left == null) { return false; } else if (right == null) { return false; } Map<String, Object> leftJson = jsonMapper.convertValue(left, TYPE_REF); Map<String, Object> rightJson = jsonMapper.convertValue(right, TYPE_REF); if (left instanceof KubernetesList) { return compareKubernetesList(leftJson, rightJson); } else { return compareKubernetesResource(leftJson, rightJson); } } private  ResourceCompare(); static boolean equals(T left, T right); static boolean compareKubernetesList(Map<String, Object> leftJson, Map<String, Object> rightJson); static boolean compareKubernetesResource(Map<String, Object> leftJson, Map<String, Object> rightJson); }
ResourceCompare { public static <T> boolean equals(T left, T right) { ObjectMapper jsonMapper = Serialization.jsonMapper(); if (left == null && right == null) { return true; } else if (left == null) { return false; } else if (right == null) { return false; } Map<String, Object> leftJson = jsonMapper.convertValue(left, TYPE_REF); Map<String, Object> rightJson = jsonMapper.convertValue(right, TYPE_REF); if (left instanceof KubernetesList) { return compareKubernetesList(leftJson, rightJson); } else { return compareKubernetesResource(leftJson, rightJson); } } private  ResourceCompare(); static boolean equals(T left, T right); static boolean compareKubernetesList(Map<String, Object> leftJson, Map<String, Object> rightJson); static boolean compareKubernetesResource(Map<String, Object> leftJson, Map<String, Object> rightJson);  }