Skip to content

Commit

Permalink
deps: remove unneeded net.javacrumbs.json-unit:json-unit-fluent depen…
Browse files Browse the repository at this point in the history
…dency

Signed-off-by: Marc Nuri <[email protected]>
  • Loading branch information
manusa authored Nov 4, 2024
1 parent 9dbc604 commit 4c37d54
Show file tree
Hide file tree
Showing 24 changed files with 190 additions and 308 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ openapi-generate-schema:

.PHONY: openapi-generate-java-classes
openapi-generate-java-classes:
# Test dependency needed for model de/serialization validation
mvn $(MAVEN_ARGS) clean install -pl . -pl zjsonpatch
cd kubernetes-model-generator && mvn $(MAVEN_ARGS) -Pgenerate clean install
# TODO: run generate from extensions module root once all extensions are migrated
cd extensions && mvn $(MAVEN_ARGS) -N clean install
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class KubernetesResourceDiff {
private final String source1;
private final String source2;

private ObjectMapper yamlMapper = new ObjectMapper(
private final ObjectMapper yamlMapper = new ObjectMapper(
new YAMLFactory().disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER));

public KubernetesResourceDiff(String source1, String source2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,24 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import io.fabric8.kubernetes.model.util.Helper;
import io.fabric8.zjsonpatch.JsonDiff;
import org.junit.jupiter.api.Test;

import static net.javacrumbs.jsonunit.core.Option.IGNORING_ARRAY_ORDER;
import static net.javacrumbs.jsonunit.core.Option.IGNORING_EXTRA_FIELDS;
import static net.javacrumbs.jsonunit.core.Option.TREATING_NULL_AS_ABSENT;
import static net.javacrumbs.jsonunit.fluent.JsonFluentAssert.assertThatJson;
import static org.assertj.core.api.Assertions.assertThat;

class ConversionReviewTest {

private final ObjectMapper objectMapper = new ObjectMapper();
private final ObjectMapper mapper = new ObjectMapper();

@Test
void testDeserializationAndSerialization() throws Exception {
// Given
final String originalJson = Helper.loadJson("/valid-conversionreview.json");

// when
final ConversionReview conversionReview = objectMapper.readValue(originalJson, ConversionReview.class);
final String serializedJson = objectMapper.writeValueAsString(conversionReview);

// then
assertThatJson(serializedJson).when(IGNORING_ARRAY_ORDER, TREATING_NULL_AS_ABSENT, IGNORING_EXTRA_FIELDS)
.isEqualTo(originalJson);
final ConversionReview conversionReview = mapper.readValue(originalJson, ConversionReview.class);
// When
final var diff = JsonDiff.asJson(mapper.readTree(originalJson),
mapper.readTree(mapper.writeValueAsString(conversionReview)));
// Then
assertThat(diff).isEmpty();
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,18 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.fabric8.kubernetes.model.util.Helper;
import io.fabric8.zjsonpatch.JsonDiff;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.junit.jupiter.api.Test;

import java.util.Map;

import static net.javacrumbs.jsonunit.core.Option.IGNORING_ARRAY_ORDER;
import static net.javacrumbs.jsonunit.core.Option.IGNORING_EXTRA_FIELDS;
import static net.javacrumbs.jsonunit.core.Option.TREATING_NULL_AS_ABSENT;
import static net.javacrumbs.jsonunit.fluent.JsonFluentAssert.assertThatJson;
import static org.assertj.core.api.Assertions.as;
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

class CustomResourceDefinitionTest {
private final ObjectMapper objectMapper = new ObjectMapper();
private final ObjectMapper mapper = new ObjectMapper();

@Test
void testBuilder() {
Expand Down Expand Up @@ -69,65 +65,51 @@ void testBuilder() {
void testLoadFromJsonSchemaPropsOrBool() throws JsonProcessingException {
// Given
final String originalJson = Helper.loadJson("/valid-v1-crd.json");

// when
final CustomResourceDefinition customResourceDefinition = objectMapper.readValue(originalJson,
final CustomResourceDefinition customResourceDefinition = mapper.readValue(originalJson,
CustomResourceDefinition.class);
final String serializedJson = objectMapper.writeValueAsString(customResourceDefinition);

// then
assertThatJson(serializedJson).when(IGNORING_ARRAY_ORDER, TREATING_NULL_AS_ABSENT, IGNORING_EXTRA_FIELDS)
.isEqualTo(originalJson);
// When
final var diff = JsonDiff.asJson(mapper.readTree(originalJson),
mapper.readTree(mapper.writeValueAsString(customResourceDefinition)));
// Then
assertThat(diff).isEmpty();
}

@Test
void testLoadFromJsonSchemaPropsOrArray() throws JsonProcessingException {
// Given
String jsonString = Helper.loadJson("/valid-crd-jsonschemapropsorarray.json");

final String originalJson = Helper.loadJson("/valid-crd-jsonschemapropsorarray.json");
final CustomResourceDefinition result = mapper.readValue(originalJson, CustomResourceDefinition.class);
// When
CustomResourceDefinition result = objectMapper.readValue(jsonString, CustomResourceDefinition.class);
final String serializedJson = objectMapper.writeValueAsString(result);

final var diff = JsonDiff.asJson(mapper.readTree(originalJson), mapper.readTree(mapper.writeValueAsString(result)));
// Then
assertNotNull(result);

// then
assertThatJson(serializedJson).when(IGNORING_ARRAY_ORDER, TREATING_NULL_AS_ABSENT, IGNORING_EXTRA_FIELDS)
.isEqualTo(jsonString);
assertThat(diff).isEmpty();
}

@Test
void testLoadFromJsonSchemaPropsOrStringArray() throws JsonProcessingException {
// Given
String jsonString = Helper.loadJson("/valid-crd-jsonschemapropsorstringarray.json");

final String originalJson = Helper.loadJson("/valid-crd-jsonschemapropsorstringarray.json");
final CustomResourceDefinition result = mapper.readValue(originalJson, CustomResourceDefinition.class);
// When
CustomResourceDefinition result = objectMapper.readValue(jsonString, CustomResourceDefinition.class);
final String serializedJson = objectMapper.writeValueAsString(result);

final var diff = JsonDiff.asJson(mapper.readTree(originalJson), mapper.readTree(mapper.writeValueAsString(result)));
// Then
assertNotNull(result);

// then
assertThatJson(serializedJson).when(IGNORING_ARRAY_ORDER, TREATING_NULL_AS_ABSENT, IGNORING_EXTRA_FIELDS)
.isEqualTo(jsonString);
assertThat(diff).isEmpty();
}

@Test
void testLoadFromCrdWithValidationExpressionLanguage() throws JsonProcessingException {
// Given
String jsonString = Helper.loadJson("/valid-v1-crd-validation-expression.json");

final String originalJson = Helper.loadJson("/valid-v1-crd-validation-expression.json");
final CustomResourceDefinition result = mapper.readValue(originalJson, CustomResourceDefinition.class);
// When
CustomResourceDefinition result = objectMapper.readValue(jsonString, CustomResourceDefinition.class);

final var diff = JsonDiff.asJson(mapper.readTree(originalJson), mapper.readTree(mapper.writeValueAsString(result)));
// Then
assertThat(diff).isEmpty();
assertThat(result)
.extracting(CustomResourceDefinition::getSpec)
.extracting(CustomResourceDefinitionSpec::getVersions)
.asList()
.singleElement(InstanceOfAssertFactories.type(CustomResourceDefinitionVersion.class))
.asInstanceOf(InstanceOfAssertFactories.list(CustomResourceDefinitionVersion.class))
.singleElement()
.extracting(CustomResourceDefinitionVersion::getSchema)
.extracting(CustomResourceValidation::getOpenAPIV3Schema)
.extracting(JSONSchemaProps::getProperties, as(InstanceOfAssertFactories.type(Map.class)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,16 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.fabric8.kubernetes.model.util.Helper;
import io.fabric8.zjsonpatch.JsonDiff;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.Collections;

import static net.javacrumbs.jsonunit.core.Option.IGNORING_ARRAY_ORDER;
import static net.javacrumbs.jsonunit.core.Option.IGNORING_EXTRA_FIELDS;
import static net.javacrumbs.jsonunit.core.Option.TREATING_NULL_AS_ABSENT;
import static net.javacrumbs.jsonunit.fluent.JsonFluentAssert.assertThatJson;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

class CustomResourceDefinitionTest {
private final ObjectMapper objectMapper = new ObjectMapper();
private final ObjectMapper mapper = new ObjectMapper();

@Test
public void testBuilder() {
Expand Down Expand Up @@ -68,48 +65,34 @@ public void testBuilder() {
void testLoadFromJsonSchemaPropsOrBool() throws JsonProcessingException {
// Given
final String originalJson = Helper.loadJson("/valid-crd.json");

// when
final CustomResourceDefinition customResourceDefinition = objectMapper.readValue(originalJson,
final CustomResourceDefinition customResourceDefinition = mapper.readValue(originalJson,
CustomResourceDefinition.class);
final String serializedJson = objectMapper.writeValueAsString(customResourceDefinition);

// then
assertThatJson(serializedJson).when(IGNORING_ARRAY_ORDER, TREATING_NULL_AS_ABSENT, IGNORING_EXTRA_FIELDS)
.isEqualTo(originalJson);
// When
final var diff = JsonDiff.asJson(mapper.readTree(originalJson),
mapper.readTree(mapper.writeValueAsString(customResourceDefinition)));
// Then
Assertions.assertThat(diff).isEmpty();
}

@Test
void testLoadFromJsonSchemaPropsOrArray() throws JsonProcessingException {
// Given
String jsonString = Helper.loadJson("/valid-crd-jsonschemapropsorarray.json");

final String originalJson = Helper.loadJson("/valid-crd-jsonschemapropsorarray.json");
final CustomResourceDefinition result = mapper.readValue(originalJson, CustomResourceDefinition.class);
// When
CustomResourceDefinition result = objectMapper.readValue(jsonString, CustomResourceDefinition.class);
final String serializedJson = objectMapper.writeValueAsString(result);

final var diff = JsonDiff.asJson(mapper.readTree(originalJson), mapper.readTree(mapper.writeValueAsString(result)));
// Then
assertNotNull(result);

// then
assertThatJson(serializedJson).when(IGNORING_ARRAY_ORDER, TREATING_NULL_AS_ABSENT, IGNORING_EXTRA_FIELDS)
.isEqualTo(jsonString);
Assertions.assertThat(diff).isEmpty();
}

@Test
void testLoadFromJsonSchemaPropsOrStringArray() throws JsonProcessingException {
// Given
String jsonString = Helper.loadJson("/valid-crd-jsonschemapropsorstringarray.json");

String originalJson = Helper.loadJson("/valid-crd-jsonschemapropsorstringarray.json");
CustomResourceDefinition result = mapper.readValue(originalJson, CustomResourceDefinition.class);
// When
CustomResourceDefinition result = objectMapper.readValue(jsonString, CustomResourceDefinition.class);
final String serializedJson = objectMapper.writeValueAsString(result);

final var diff = JsonDiff.asJson(mapper.readTree(originalJson), mapper.readTree(mapper.writeValueAsString(result)));
// Then
assertNotNull(result);

// then
assertThatJson(serializedJson).when(IGNORING_ARRAY_ORDER, TREATING_NULL_AS_ABSENT, IGNORING_EXTRA_FIELDS)
.isEqualTo(jsonString);
Assertions.assertThat(diff).isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@
import io.fabric8.kubernetes.api.model.Quantity;
import io.fabric8.kubernetes.api.model.VolumeMount;
import io.fabric8.kubernetes.model.util.Helper;
import io.fabric8.zjsonpatch.JsonDiff;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.Collections;

import static net.javacrumbs.jsonunit.core.Option.IGNORING_ARRAY_ORDER;
import static net.javacrumbs.jsonunit.core.Option.IGNORING_EXTRA_FIELDS;
import static net.javacrumbs.jsonunit.core.Option.TREATING_NULL_AS_ABSENT;
import static net.javacrumbs.jsonunit.fluent.JsonFluentAssert.assertThatJson;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand All @@ -42,16 +40,13 @@ class DeploymentTest {

@Test
void kubernetesDeploymentTest() throws Exception {
// given
// Given
final String originalJson = Helper.loadJson("/valid-deployment.json");

// when
final Deployment deployment = mapper.readValue(originalJson, Deployment.class);
final String serializedJson = mapper.writeValueAsString(deployment);

// then
assertThatJson(serializedJson).when(IGNORING_ARRAY_ORDER, TREATING_NULL_AS_ABSENT, IGNORING_EXTRA_FIELDS)
.isEqualTo(originalJson);
// When
final var diff = JsonDiff.asJson(mapper.readTree(originalJson), mapper.readTree(mapper.writeValueAsString(deployment)));
// Then
assertThat(diff).isEmpty();
}

@Test
Expand Down
5 changes: 0 additions & 5 deletions kubernetes-model-generator/kubernetes-model-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,6 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import io.fabric8.kubernetes.model.util.Helper;
import io.fabric8.zjsonpatch.JsonDiff;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.HashMap;

import static net.javacrumbs.jsonunit.core.Option.IGNORING_ARRAY_ORDER;
import static net.javacrumbs.jsonunit.core.Option.IGNORING_EXTRA_FIELDS;
import static net.javacrumbs.jsonunit.core.Option.TREATING_NULL_AS_ABSENT;
import static net.javacrumbs.jsonunit.fluent.JsonFluentAssert.assertThatJson;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

Expand All @@ -40,16 +38,13 @@ void setUp() {

@Test
void configMapTest() throws Exception {
// given
// Given
final String originalJson = Helper.loadJson("/valid-configMap.json");

// when
final ConfigMap configMap = mapper.readValue(originalJson, ConfigMap.class);
final String serializedJson = mapper.writeValueAsString(configMap);

// then
assertThatJson(serializedJson).when(IGNORING_ARRAY_ORDER, TREATING_NULL_AS_ABSENT, IGNORING_EXTRA_FIELDS)
.isEqualTo(originalJson);
// When
final var diff = JsonDiff.asJson(mapper.readTree(originalJson), mapper.readTree(mapper.writeValueAsString(configMap)));
// Then
assertThat(diff).isEmpty();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.fabric8.kubernetes.model.util.Helper;
import io.fabric8.zjsonpatch.JsonDiff;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static net.javacrumbs.jsonunit.core.Option.IGNORING_ARRAY_ORDER;
import static net.javacrumbs.jsonunit.core.Option.IGNORING_EXTRA_FIELDS;
import static net.javacrumbs.jsonunit.core.Option.TREATING_NULL_AS_ABSENT;
import static net.javacrumbs.jsonunit.fluent.JsonFluentAssert.assertThatJson;
import static org.assertj.core.api.Assertions.assertThat;

class EventTest {

Expand All @@ -37,15 +35,12 @@ void setUp() {

@Test
void testEventSerializationDeserialization() throws JsonProcessingException {
// given
// Given
final String originalJson = Helper.loadJson("/valid-event.json");

// when
final Event event = mapper.readValue(originalJson, Event.class);
final String serializedJson = mapper.writeValueAsString(event);

// then
assertThatJson(serializedJson).when(IGNORING_ARRAY_ORDER, TREATING_NULL_AS_ABSENT, IGNORING_EXTRA_FIELDS)
.isEqualTo(originalJson);
// When
final var diff = JsonDiff.asJson(mapper.readTree(originalJson), mapper.readTree(mapper.writeValueAsString(event)));
// Then
assertThat(diff).isEmpty();
}
}
Loading

0 comments on commit 4c37d54

Please sign in to comment.