-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement
TransferProcess
api controller validation (#3217)
feat: implement TransferProcess api controller validation
- Loading branch information
Showing
31 changed files
with
810 additions
and
677 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...on/api/api-core/src/main/java/org/eclipse/edc/api/validation/DataAddressDtoValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Contributors: | ||
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.edc.api.validation; | ||
|
||
import jakarta.json.JsonObject; | ||
import org.eclipse.edc.validator.jsonobject.JsonObjectValidator; | ||
import org.eclipse.edc.validator.jsonobject.validators.MandatoryValue; | ||
import org.eclipse.edc.validator.spi.Validator; | ||
|
||
import static org.eclipse.edc.spi.types.domain.DataAddress.EDC_DATA_ADDRESS_TYPE_PROPERTY; | ||
|
||
public class DataAddressDtoValidator { | ||
public static Validator<JsonObject> instance() { | ||
return instance(JsonObjectValidator.newValidator()).build(); | ||
} | ||
|
||
public static JsonObjectValidator.Builder instance(JsonObjectValidator.Builder builder) { | ||
return builder | ||
.verify(EDC_DATA_ADDRESS_TYPE_PROPERTY, MandatoryValue::new); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...pi/api-core/src/test/java/org/eclipse/edc/api/validation/DataAddressDtoValidatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Contributors: | ||
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.edc.api.validation; | ||
|
||
import jakarta.json.JsonArrayBuilder; | ||
import jakarta.json.JsonObject; | ||
import org.eclipse.edc.validator.spi.ValidationFailure; | ||
import org.eclipse.edc.validator.spi.Validator; | ||
import org.eclipse.edc.validator.spi.Violation; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static jakarta.json.Json.createArrayBuilder; | ||
import static jakarta.json.Json.createObjectBuilder; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.InstanceOfAssertFactories.list; | ||
import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.VALUE; | ||
import static org.eclipse.edc.junit.assertions.AbstractResultAssert.assertThat; | ||
import static org.eclipse.edc.spi.types.domain.DataAddress.EDC_DATA_ADDRESS_TYPE_PROPERTY; | ||
|
||
class DataAddressDtoValidatorTest { | ||
|
||
private final Validator<JsonObject> validator = DataAddressDtoValidator.instance(); | ||
|
||
@Test | ||
void shouldSucceed_whenObjectIsValid() { | ||
var contractDefinition = createObjectBuilder() | ||
.add(EDC_DATA_ADDRESS_TYPE_PROPERTY, value("value")) | ||
.build(); | ||
|
||
var result = validator.validate(contractDefinition); | ||
|
||
assertThat(result).isSucceeded(); | ||
} | ||
|
||
@Test | ||
void shouldFail_whenMandatoryFieldsAreMissing() { | ||
var contractDefinition = createObjectBuilder().build(); | ||
|
||
var result = validator.validate(contractDefinition); | ||
|
||
assertThat(result).isFailed().extracting(ValidationFailure::getViolations).asInstanceOf(list(Violation.class)) | ||
.isNotEmpty() | ||
.anySatisfy(violation -> assertThat(violation.path()).isEqualTo(EDC_DATA_ADDRESS_TYPE_PROPERTY)); | ||
} | ||
|
||
private JsonArrayBuilder value(String value) { | ||
return createArrayBuilder().add(createObjectBuilder().add(VALUE, value)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.