Skip to content

Commit

Permalink
removed no more legit test cases;
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Maute <stefan.maute@bosch.io>
  • Loading branch information
Stefan Maute committed Jun 29, 2022
1 parent 3aa1446 commit 7b81d05
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 96 deletions.
Expand Up @@ -391,33 +391,6 @@ public void putHeadersContainingValidMetadata() {
assertThat(dittoHeaders.asCaseSensitiveMap()).isEqualTo(headerMap);
}

@Test
public void putHeadersContainingInvalidMetadataKey() {
final String metadataKey = "*/*/issuedAt";
final JsonValue metadataValue = JsonValue.of(String.valueOf(Instant.now()));
final JsonArray metadataHeaderEntries = JsonArray.of(JsonObject.newBuilder()
.set(MetadataHeader.JsonFields.METADATA_KEY, metadataKey)
.set(MetadataHeader.JsonFields.METADATA_VALUE, metadataValue)
.build());
final Map<String, String> headerMap = new HashMap<>();
headerMap.put("foo", "bar");
headerMap.put(DittoHeaderDefinition.PUT_METADATA.getKey(), metadataHeaderEntries.toString());
headerMap.put(DittoHeaderDefinition.CORRELATION_ID.getKey(), String.valueOf(UUID.randomUUID()));

assertThatExceptionOfType(DittoHeaderInvalidException.class)
.isThrownBy(() -> underTest.putHeaders(headerMap))
.withMessage("The value '%s' of the header 'put-metadata' is not a valid MetadataHeaders.",
metadataHeaderEntries)
.satisfies(dittoHeaderInvalidException -> assertThat(
dittoHeaderInvalidException.getDescription())
.contains("The metadata header key <" +
metadataKey +
"> is invalid!" +
" A wildcard path of a metadata header key must have exactly two levels but it had" +
" <3>!"))
.withCauseInstanceOf(JsonParseException.class);
}

@Test
public void createBuilderFromMapContainingValidMetadata() {
final MetadataHeaderKey metadataKey = MetadataHeaderKey.parse("*/issuedAt");
Expand All @@ -432,28 +405,6 @@ public void createBuilderFromMapContainingValidMetadata() {
assertThat(underTest.build().asCaseSensitiveMap()).isEqualTo(headerMap);
}

@Test
public void createBuilderFromMapContainingInvalidMetadataKey() {
final String metadataKey = "*/*/issuedAt";
final JsonObject metadataHeaderEntry = JsonObject.newBuilder()
.set(MetadataHeader.JsonFields.METADATA_KEY, metadataKey)
.set(MetadataHeader.JsonFields.METADATA_VALUE, JsonValue.of(String.valueOf(Instant.now())))
.build();
final JsonArray metadataHeaderEntries = JsonArray.of(metadataHeaderEntry);
final Map<String, String> headerMap = new HashMap<>();
headerMap.put("foo", "bar");
headerMap.put(DittoHeaderDefinition.PUT_METADATA.getKey(), metadataHeaderEntries.toString());
headerMap.put(DittoHeaderDefinition.CORRELATION_ID.getKey(), String.valueOf(UUID.randomUUID()));

assertThatExceptionOfType(DittoHeaderInvalidException.class)
.isThrownBy(() -> DefaultDittoHeadersBuilder.of(headerMap))
.satisfies(dittoHeaderInvalidException -> assertThat(dittoHeaderInvalidException.getDescription())
.contains("The metadata header key <" + metadataKey + "> is invalid!" +
" A wildcard path of a metadata header key must have exactly two levels but it had" +
" <3>!"))
.withCauseInstanceOf(JsonParseException.class);
}

@Test
public void createBuilderFromMapContainingInvalidMetadataValue() {
final String invalidValue = String.valueOf(Instant.now());
Expand Down
Expand Up @@ -18,16 +18,14 @@
import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf;
import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable;

import org.eclipse.ditto.json.JsonArray;
import org.eclipse.ditto.json.JsonMissingFieldException;
import org.eclipse.ditto.json.JsonObject;
import org.eclipse.ditto.json.JsonParseException;
import org.eclipse.ditto.json.JsonValue;
import org.eclipse.ditto.base.model.exceptions.DittoHeaderInvalidException;
import org.eclipse.ditto.base.model.headers.metadata.MetadataHeader;
import org.eclipse.ditto.base.model.headers.metadata.MetadataHeaderKey;
import org.eclipse.ditto.base.model.headers.metadata.MetadataHeaders;
import org.junit.Ignore;
import org.eclipse.ditto.json.JsonArray;
import org.eclipse.ditto.json.JsonMissingFieldException;
import org.eclipse.ditto.json.JsonObject;
import org.eclipse.ditto.json.JsonValue;
import org.junit.Test;

/**
Expand Down Expand Up @@ -73,27 +71,4 @@ public void validateInvalidMetadataHeadersCharSequence1() {
.withCauseInstanceOf(JsonMissingFieldException.class);
}

@Test
public void validateInvalidMetadataHeadersCharSequence2() {
final JsonArray invalidMetadataHeaderEntries = JsonArray.newBuilder()
.add(JsonObject.newBuilder()
.set(MetadataHeader.JsonFields.METADATA_KEY, "/*/*/foo")
.set(MetadataHeader.JsonFields.METADATA_VALUE, JsonValue.of("bar"))
.build())
.build();
final String invalidMetadataHeadersCharSequence = invalidMetadataHeaderEntries.toString();

final MetadataHeadersValueValidator underTest = MetadataHeadersValueValidator.getInstance();

assertThatExceptionOfType(DittoHeaderInvalidException.class)
.isThrownBy(() -> underTest.accept(DittoHeaderDefinition.PUT_METADATA, invalidMetadataHeadersCharSequence))
.withMessage("The value '%s' of the header '%s' is not a valid MetadataHeaders.",
invalidMetadataHeadersCharSequence, DittoHeaderDefinition.PUT_METADATA.getKey())
.satisfies(dittoHeaderInvalidException -> assertThat(dittoHeaderInvalidException.getDescription())
.contains("The metadata header key </*/*/foo> is invalid!" +
" A wildcard path of a metadata header key must have exactly two levels but it had" +
" <3>!"))
.withCauseInstanceOf(JsonParseException.class);
}

}
Expand Up @@ -19,13 +19,11 @@
import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf;
import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable;

import java.time.Instant;
import java.util.Arrays;
import java.util.Collection;

import org.eclipse.ditto.json.JsonMissingFieldException;
import org.eclipse.ditto.json.JsonObject;
import org.eclipse.ditto.json.JsonParseException;
import org.eclipse.ditto.json.JsonPointer;
import org.eclipse.ditto.json.JsonValue;
import org.junit.Ignore;
Expand Down Expand Up @@ -134,22 +132,6 @@ public void getInstanceFromJsonObjectWithoutMetadataValue() {
.withNoCause();
}

@Test
public void getInstanceFromJsonWithInvalidMetadataEntryKey() {
final String metadataKey = "*/*/issuedAt";
final JsonObject jsonObject = JsonObject.newBuilder()
.set(MetadataHeader.JsonFields.METADATA_KEY, metadataKey)
.set(MetadataHeader.JsonFields.METADATA_VALUE, JsonValue.of(String.valueOf(Instant.now())))
.build();

assertThatExceptionOfType(JsonParseException.class)
.isThrownBy(() -> DefaultMetadataHeader.fromJson(jsonObject))
.withMessage("The metadata header key <%s> is invalid!", metadataKey)
.satisfies(jsonParseException -> assertThat(jsonParseException.getDescription()).contains(
"A wildcard path of a metadata header key must have exactly two levels but it had <3>!"))
.withCauseInstanceOf(IllegalArgumentException.class);
}

}

@RunWith(Parameterized.class)
Expand Down

0 comments on commit 7b81d05

Please sign in to comment.