-
Notifications
You must be signed in to change notification settings - Fork 13
chore: cleanup erpadapterrequest #578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tom-rm-meyer-ISST
merged 3 commits into
eclipse-tractusx:main
from
FraunhoferISST:chore/erpadapterrequesttypevalidation
Sep 20, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
101 changes: 101 additions & 0 deletions
101
...ipse/tractusx/puris/backend/erpadapter/logic/service/ErpAdapterRequestValidationTest.java
This file contains hidden or 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,101 @@ | ||
/* | ||
* Copyright (c) 2024 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. | ||
* (represented by Fraunhofer ISST) | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* 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. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.eclipse.tractusx.puris.backend.erpadapter.logic.service; | ||
|
||
import jakarta.validation.Validation; | ||
import jakarta.validation.Validator; | ||
import jakarta.validation.ValidatorFactory; | ||
import org.eclipse.tractusx.puris.backend.common.edc.domain.model.AssetType; | ||
import org.eclipse.tractusx.puris.backend.erpadapter.domain.model.ErpAdapterRequest; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.EnumSource; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import java.util.Date; | ||
import java.util.UUID; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class ErpAdapterRequestValidationTest { | ||
|
||
private static final String matNbrCustomer = "MNR-7307-AU340474.002"; | ||
|
||
private static final String supplierPartnerBpnl = "BPNL1234567890ZZ"; | ||
|
||
private static Validator validator; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); | ||
validator = factory.getValidator(); | ||
} | ||
|
||
@ParameterizedTest | ||
@EnumSource(AssetType.class) | ||
public void testRequestTypeValidation(AssetType type) { | ||
// given | ||
ErpAdapterRequest erpAdapterRequest = ErpAdapterRequest.builder() | ||
.id(UUID.randomUUID()) | ||
.requestDate(new Date()) | ||
.partnerBpnl(supplierPartnerBpnl) | ||
.ownMaterialNumber(matNbrCustomer) | ||
.requestType(type) | ||
.sammVersion(type.ERP_SAMMVERSION) | ||
.build(); | ||
|
||
// when | ||
var violations = validator.validate(erpAdapterRequest); | ||
|
||
// then | ||
if (!ErpAdapterRequest.SUPPORTED_TYPES.contains(type)) { | ||
assertEquals(1, violations.size(), "Expected validation errors for unsupported type: " + type); | ||
} else { | ||
assertTrue(violations.isEmpty(), "No validation errors expected for supported type: " + type); | ||
} | ||
} | ||
|
||
@Test | ||
public void testRequestTypeValidation() { | ||
// given | ||
ErpAdapterRequest erpAdapterRequest = ErpAdapterRequest.builder() | ||
.id(UUID.randomUUID()) | ||
.requestDate(null) // must not be null | ||
.partnerBpnl("wrong-bpnl") // should fail regex check | ||
.ownMaterialNumber("illegal-material-number\n") // should fail regex check | ||
.requestType(AssetType.ITEM_STOCK_SUBMODEL) | ||
.sammVersion(AssetType.ITEM_STOCK_SUBMODEL.ERP_SAMMVERSION) | ||
.build(); | ||
|
||
// when | ||
var violations = validator.validate(erpAdapterRequest); | ||
|
||
// then | ||
assertEquals(3, violations.size()); | ||
} | ||
|
||
|
||
} |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.