Skip to content

Commit

Permalink
feature(irs-edc-client): #412 fix asset creation in irs lib
Browse files Browse the repository at this point in the history
  • Loading branch information
ds-ext-sceronik committed Feb 23, 2024
1 parent 282c692 commit a0bc4d4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private String sendRequest(final Asset request) throws CreateEdcAssetException {
final ResponseEntity<String> createEdcDataAssetResponse;
try {
createEdcDataAssetResponse = restTemplate.postForEntity(config.getControlplane().getEndpoint().getAsset(),
transformedPayload, String.class);
transformedPayload.toString(), String.class);
final HttpStatusCode responseCode = createEdcDataAssetResponse.getStatusCode();

if (responseCode.value() == HttpStatus.CONFLICT.value()) {
Expand All @@ -98,7 +98,7 @@ private String sendRequest(final Asset request) throws CreateEdcAssetException {
throw new CreateEdcAssetException("Failed to create asset %s".formatted(request.getId()));
}

public void deleteAsset(final String assetId, final RestTemplate restTemplate) throws DeleteEdcAssetException {
public void deleteAsset(final String assetId) throws DeleteEdcAssetException {
final String deleteUri = UriComponentsBuilder.fromPath(config.getControlplane().getEndpoint().getAsset())
.pathSegment("{notificationAssetId}")
.buildAndExpand(assetId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public EdcCreatePolicyDefinitionRequest createPolicyDefinition(final String poli
.build();
}

public void deleteAccessPolicy(final String accessPolicyId, final RestTemplate restTemplate)
public void deleteAccessPolicy(final String accessPolicyId)
throws DeleteEdcPolicyDefinitionException {
final String deleteUri = UriComponentsBuilder.fromPath(
config.getControlplane().getEndpoint().getPolicyDefinition())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void givenCreateNotificationAsset_whenOk_ThenReturnCreatedAssetId() throws Creat
String assetName = "asset1";
NotificationMethod notificationMethod = NotificationMethod.RECEIVE;
NotificationType notificationType = NotificationType.QUALITY_ALERT;
when(restTemplate.postForEntity(any(String.class), any(JsonObject.class), any())).thenReturn(
when(restTemplate.postForEntity(any(String.class), any(String.class), any())).thenReturn(
ResponseEntity.ok("test"));

// when
Expand All @@ -175,7 +175,7 @@ void givenCreateDtrAsset_whenOk_ThenReturnCreatedAssetId() throws CreateEdcAsset
when(endpointConfig.getAsset()).thenReturn("/management/v2/assets");
String baseUrl = "http://test.test";
String assetName = "asset1";
when(restTemplate.postForEntity(any(String.class), any(JsonObject.class), any())).thenReturn(
when(restTemplate.postForEntity(any(String.class), any(String.class), any())).thenReturn(
ResponseEntity.ok("test"));

// when
Expand All @@ -194,7 +194,7 @@ void givenDeleteAsset_whenOk_ThenReturnCreatedAssetId() throws DeleteEdcAssetExc
String assetId = "id";

// when
service.deleteAsset(assetId, restTemplate);
service.deleteAsset(assetId);

// then
verify(restTemplate).delete(any(String.class));
Expand All @@ -209,7 +209,7 @@ void givenCreateDtrAsset_whenOK_ThenThrowException() {
String baseUrl = "http://test.test";
String assetName = "asset1";
doThrow(new RestClientException("Surprise")).when(restTemplate)
.postForEntity(any(String.class), any(JsonObject.class), any());
.postForEntity(any(String.class), any(String.class), any());

// when/then
assertThrows(CreateEdcAssetException.class, () -> service.createDtrAsset(baseUrl, assetName));
Expand All @@ -224,7 +224,7 @@ void givenCreateDtrAsset_whenTemplateException_ThenThrowException() {
String baseUrl = "http://test.test";
String assetName = "asset1";
doThrow(new RestClientException("Surprise")).when(restTemplate)
.postForEntity(any(String.class), any(JsonObject.class), any());
.postForEntity(any(String.class), any(String.class), any());

// when/then
assertThrows(CreateEdcAssetException.class, () -> service.createDtrAsset(baseUrl, assetName));
Expand All @@ -240,7 +240,7 @@ void givenDeleteAsset_whenTemplateException_ThenThrowException() {
doThrow(new RestClientException("Surprise")).when(restTemplate).delete(any(String.class));

// when/then
assertThrows(DeleteEdcAssetException.class, () -> service.deleteAsset(assetId, restTemplate));
assertThrows(DeleteEdcAssetException.class, () -> service.deleteAsset(assetId));
}

ObjectMapper objectMapper() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void givenDeletePolicy_whenRestClientException_thenThrowException() {

// when/then
assertThrows(DeleteEdcPolicyDefinitionException.class,
() -> service.deleteAccessPolicy(policyName, restTemplate));
() -> service.deleteAccessPolicy(policyName));
}

@Test
Expand All @@ -187,7 +187,7 @@ void givenDeletePolicy_whenOk_thenCallRestTemplate() throws DeleteEdcPolicyDefin
String policyName = "policyName";

// when
service.deleteAccessPolicy(policyName, restTemplate);
service.deleteAccessPolicy(policyName);

// then
verify(restTemplate, times(1)).delete(any(String.class));
Expand Down

0 comments on commit a0bc4d4

Please sign in to comment.