-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: get rid of DspHttpDispatcherDelegate (#3771)
- Loading branch information
Showing
41 changed files
with
385 additions
and
1,516 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
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
39 changes: 39 additions & 0 deletions
39
...java/org/eclipse/edc/protocol/dsp/catalog/dispatcher/delegate/ByteArrayBodyExtractor.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,39 @@ | ||
/* | ||
* Copyright (c) 2024 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.protocol.dsp.catalog.dispatcher.delegate; | ||
|
||
import okhttp3.ResponseBody; | ||
import org.eclipse.edc.protocol.dsp.spi.dispatcher.response.DspHttpResponseBodyExtractor; | ||
import org.eclipse.edc.spi.EdcException; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Extract the body as a byte[] | ||
*/ | ||
public class ByteArrayBodyExtractor implements DspHttpResponseBodyExtractor<byte[]> { | ||
@Override | ||
public byte[] extractBody(ResponseBody responseBody) { | ||
try { | ||
if (responseBody == null) { | ||
return null; | ||
} | ||
return responseBody.bytes(); | ||
|
||
} catch (IOException e) { | ||
throw new EdcException("Failed to read response body", e); | ||
} | ||
} | ||
} |
54 changes: 0 additions & 54 deletions
54
...g/eclipse/edc/protocol/dsp/catalog/dispatcher/delegate/CatalogRequestHttpRawDelegate.java
This file was deleted.
Oops, something went wrong.
55 changes: 0 additions & 55 deletions
55
...g/eclipse/edc/protocol/dsp/catalog/dispatcher/delegate/DatasetRequestHttpRawDelegate.java
This file was deleted.
Oops, something went wrong.
58 changes: 58 additions & 0 deletions
58
.../org/eclipse/edc/protocol/dsp/catalog/dispatcher/delegate/ByteArrayBodyExtractorTest.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,58 @@ | ||
/* | ||
* 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.protocol.dsp.catalog.dispatcher.delegate; | ||
|
||
import okhttp3.ResponseBody; | ||
import org.eclipse.edc.spi.EdcException; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
class ByteArrayBodyExtractorTest { | ||
|
||
private final ByteArrayBodyExtractor extractor = new ByteArrayBodyExtractor(); | ||
|
||
@Test | ||
void shouldReturnBodyAsBytes() throws IOException { | ||
var responseBody = mock(ResponseBody.class); | ||
var bytes = "test".getBytes(); | ||
when(responseBody.bytes()).thenReturn(bytes); | ||
|
||
var result = extractor.extractBody(responseBody); | ||
|
||
assertThat(result).isEqualTo(bytes); | ||
} | ||
|
||
@Test | ||
void shouldReturnNull_whenBodyIsNull() { | ||
var result = extractor.extractBody(null); | ||
|
||
assertThat(result).isNull(); | ||
} | ||
|
||
@Test | ||
void shouldThrowException_whenCannotExtractBytes() throws IOException { | ||
var responseBody = mock(ResponseBody.class); | ||
when(responseBody.bytes()).thenThrow(new IOException()); | ||
|
||
assertThatThrownBy(() -> extractor.extractBody(responseBody)).isInstanceOf(EdcException.class); | ||
} | ||
|
||
} |
64 changes: 0 additions & 64 deletions
64
...lipse/edc/protocol/dsp/catalog/dispatcher/delegate/CatalogRequestHttpRawDelegateTest.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.