Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public interface MtxSidecarClient {

String getOrdDocument();
byte[] getOrdDocument();
Comment thread
mlakov marked this conversation as resolved.

String getOrdResourceDefinition(String resource);
byte[] getOrdResourceDefinition(String resource);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import static com.sap.cds.services.request.RequestContext.getCurrent;
import static com.sap.cloud.sdk.cloudplatform.connectivity.ApacheHttpClient5Accessor.getHttpClient;
import static com.sap.cloud.sdk.cloudplatform.connectivity.DestinationAccessor.getDestination;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Collections.emptySet;
import static java.util.stream.Collectors.toSet;
import static org.apache.commons.io.IOUtils.toByteArray;
import static org.apache.hc.core5.http.ContentType.APPLICATION_JSON;

import com.sap.cds.CdsData;
Expand All @@ -22,7 +22,6 @@
import java.io.IOException;
import java.util.Set;
import lombok.RequiredArgsConstructor;
import org.apache.commons.io.IOUtils;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.io.entity.StringEntity;
import org.apache.hc.core5.http.io.support.ClassicRequestBuilder;
Expand All @@ -38,24 +37,24 @@ public class MtxSidecarClientImpl implements MtxSidecarClient {
private final CdsRuntime cdsRuntime;

@Override
public String getOrdDocument() {
public byte[] getOrdDocument() {
return doPost(API_PATH_GET_ORD_DOCUMENT, asGetOrdDocumentRequestEntity(getCurrent(cdsRuntime)));
}

@Override
public String getOrdResourceDefinition(String resource) {
public byte[] getOrdResourceDefinition(String resource) {
return doPost(
API_PATH_GET_ORD_RESOURCE_DEFINITION,
asGetOrdResourceDefinitionRequestEntity(getCurrent(cdsRuntime), resource));
}

private String doPost(String path, HttpEntity entity) {
private byte[] doPost(String path, HttpEntity entity) {
try {
return getHttpClient(getDestination(MTX_PROVISIONING_SERVICE_DESTINATION))
.execute(
ClassicRequestBuilder.post(path).setEntity(entity).build(),
response -> IOUtils.toString(
assertSuccessful(response).getEntity().getContent(), UTF_8));
response -> toByteArray(
assertSuccessful(response).getEntity().getContent()));
} catch (IOException exception) {
throw new ServiceException("Request to sidecar failed", exception);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import static com.sap.cds.feature.ord.common.Constants.PERSPECTIVE_SYSTEM_INSTANCE;
import static com.sap.cds.feature.ord.common.Utils.Resources.asOrdJsonInputStream;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.apache.commons.io.FilenameUtils.getBaseName;
import static org.apache.commons.io.FilenameUtils.getExtension;

Expand Down Expand Up @@ -57,10 +56,7 @@ private InputStream loadResource(String resource) {
private InputStream loadFromMTXSidecar(String resource) {
return Objects.equals(ORD_DOCUMENT_PATH, resource)
? asOrdJsonInputStream(
new ByteArrayInputStream(
mtxSidecarClient.getOrdDocument().getBytes(UTF_8)),
cdsOrdNodeProcessors)
: new ByteArrayInputStream(
mtxSidecarClient.getOrdResourceDefinition(resource).getBytes(UTF_8));
new ByteArrayInputStream(mtxSidecarClient.getOrdDocument()), cdsOrdNodeProcessors)
: new ByteArrayInputStream(mtxSidecarClient.getOrdResourceDefinition(resource));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import static com.sap.cds.services.ErrorStatuses.SERVER_ERROR;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.argThat;
Expand Down Expand Up @@ -105,8 +105,8 @@ void whenGetOrdDocumentIsCalled_thenCorrectResultIsReturned() throws Throwable {
.thenAnswer(
in -> in.getArgument(1, HttpClientResponseHandler.class).handleResponse(classicHttpResponse));

withMockedDestinationAccessor(
() -> withMockedApacheHttpClient5Accessor(() -> assertEquals("{}", classUnderTest.getOrdDocument())));
withMockedDestinationAccessor(() -> withMockedApacheHttpClient5Accessor(
() -> assertArrayEquals("{}".getBytes(UTF_8), classUnderTest.getOrdDocument())));

verifyNoOtherMockInteractions(() -> {
verify(provider).isToggles();
Expand Down Expand Up @@ -196,8 +196,8 @@ void givenThatExtensibilityIsEnabled_whenGetOrdDocumentIsCalled_thenCorrectResul
.thenAnswer(
in -> in.getArgument(1, HttpClientResponseHandler.class).handleResponse(classicHttpResponse));

withMockedRequestContext(() -> withMockedDestinationAccessor(
() -> withMockedApacheHttpClient5Accessor(() -> assertEquals("{}", classUnderTest.getOrdDocument()))));
withMockedRequestContext(() -> withMockedDestinationAccessor(() -> withMockedApacheHttpClient5Accessor(
() -> assertArrayEquals("{}".getBytes(UTF_8), classUnderTest.getOrdDocument()))));

verifyNoOtherMockInteractions(() -> {
verify(provider).isToggles();
Expand Down Expand Up @@ -233,8 +233,8 @@ void givenThatTogglesAreEnabled_whenGetOrdDocumentIsCalled_thenCorrectResultIsRe
.thenAnswer(
in -> in.getArgument(1, HttpClientResponseHandler.class).handleResponse(classicHttpResponse));

withMockedRequestContext(() -> withMockedDestinationAccessor(
() -> withMockedApacheHttpClient5Accessor(() -> assertEquals("{}", classUnderTest.getOrdDocument()))));
withMockedRequestContext(() -> withMockedDestinationAccessor(() -> withMockedApacheHttpClient5Accessor(
() -> assertArrayEquals("{}".getBytes(UTF_8), classUnderTest.getOrdDocument()))));

verifyNoOtherMockInteractions(() -> {
verify(provider).isToggles();
Expand Down Expand Up @@ -270,8 +270,8 @@ void givenThatTogglesAreEnabled_and_extensibilityIsEnabled_whenGetOrdDocumentIsC
.thenAnswer(
in -> in.getArgument(1, HttpClientResponseHandler.class).handleResponse(classicHttpResponse));

withMockedRequestContext(() -> withMockedDestinationAccessor(
() -> withMockedApacheHttpClient5Accessor(() -> assertEquals("{}", classUnderTest.getOrdDocument()))));
withMockedRequestContext(() -> withMockedDestinationAccessor(() -> withMockedApacheHttpClient5Accessor(
() -> assertArrayEquals("{}".getBytes(UTF_8), classUnderTest.getOrdDocument()))));

verifyNoOtherMockInteractions(() -> {
verify(userInfo).getTenant();
Expand Down Expand Up @@ -308,8 +308,9 @@ void whenGetOrdResourceDefinitionIsCalled_thenCorrectResultIsReturned() throws T
.thenAnswer(
in -> in.getArgument(1, HttpClientResponseHandler.class).handleResponse(classicHttpResponse));

withMockedDestinationAccessor(() -> withMockedApacheHttpClient5Accessor(() ->
assertEquals("{}", classUnderTest.getOrdResourceDefinition("dummy:ord:definition/Dummy.oas3.json"))));
withMockedDestinationAccessor(() -> withMockedApacheHttpClient5Accessor(() -> assertArrayEquals(
"{}".getBytes(UTF_8),
classUnderTest.getOrdResourceDefinition("dummy:ord:definition/Dummy.oas3.json"))));

verifyNoOtherMockInteractions(() -> {
verify(provider).isToggles();
Expand Down Expand Up @@ -408,8 +409,10 @@ void givenThatExtensibilityIsEnabled_whenGetOrdResourceDefinitionIsCalled_thenCo
.thenAnswer(
in -> in.getArgument(1, HttpClientResponseHandler.class).handleResponse(classicHttpResponse));

withMockedRequestContext(() -> withMockedDestinationAccessor(() -> withMockedApacheHttpClient5Accessor(() ->
assertEquals("{}", classUnderTest.getOrdResourceDefinition("dummy:ord:definition/Dummy.oas3.json")))));
withMockedRequestContext(() ->
withMockedDestinationAccessor(() -> withMockedApacheHttpClient5Accessor(() -> assertArrayEquals(
"{}".getBytes(UTF_8),
classUnderTest.getOrdResourceDefinition("dummy:ord:definition/Dummy.oas3.json")))));

verifyNoOtherMockInteractions(() -> {
verify(provider).isToggles();
Expand Down Expand Up @@ -447,8 +450,10 @@ void givenThatTogglesAreEnabled_whenGetOrdResourceDefinitionIsCalled_thenCorrect
.thenAnswer(
in -> in.getArgument(1, HttpClientResponseHandler.class).handleResponse(classicHttpResponse));

withMockedRequestContext(() -> withMockedDestinationAccessor(() -> withMockedApacheHttpClient5Accessor(() ->
assertEquals("{}", classUnderTest.getOrdResourceDefinition("dummy:ord:definition/Dummy.oas3.json")))));
withMockedRequestContext(() ->
withMockedDestinationAccessor(() -> withMockedApacheHttpClient5Accessor(() -> assertArrayEquals(
"{}".getBytes(UTF_8),
classUnderTest.getOrdResourceDefinition("dummy:ord:definition/Dummy.oas3.json")))));

verifyNoOtherMockInteractions(() -> {
verify(provider).isToggles();
Expand Down Expand Up @@ -486,8 +491,10 @@ void givenThatTogglesAreEnabled_whenGetOrdResourceDefinitionIsCalled_thenCorrect
.thenAnswer(
in -> in.getArgument(1, HttpClientResponseHandler.class).handleResponse(classicHttpResponse));

withMockedRequestContext(() -> withMockedDestinationAccessor(() -> withMockedApacheHttpClient5Accessor(() ->
assertEquals("{}", classUnderTest.getOrdResourceDefinition("dummy:ord:definition/Dummy.oas3.json")))));
withMockedRequestContext(() ->
withMockedDestinationAccessor(() -> withMockedApacheHttpClient5Accessor(() -> assertArrayEquals(
"{}".getBytes(UTF_8),
classUnderTest.getOrdResourceDefinition("dummy:ord:definition/Dummy.oas3.json")))));

verifyNoOtherMockInteractions(() -> {
verify(provider).isToggles();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void givenThatStaticModelShouldBeUsed_and_perspectiveIsSystemInstance_whenReadIs
givenThatDynamicModelShouldBeUsed_and_perspectiveIsSystemInstance_and_ordDocumentIsRequested_whenReadIsCalled_thenCorrectResultIsReturned()
throws IOException {
doReturn(false).when(dynamicModelUtils).useStaticModel();
doReturn("{}").when(mtxSidecarClient).getOrdDocument();
doReturn("{}".getBytes(UTF_8)).when(mtxSidecarClient).getOrdDocument();

assertEquals(
"{}",
Expand Down Expand Up @@ -223,7 +223,9 @@ void givenThatStaticModelShouldBeUsed_and_perspectiveIsSystemInstance_whenReadIs
throws IOException {
doReturn("ord/").when(openResourceDiscovery).getOrdResourcesRoot();
doReturn(false).when(dynamicModelUtils).useStaticModel();
doReturn("{}").when(mtxSidecarClient).getOrdResourceDefinition("test:ord:service/test.oas3.json");
doReturn("{}".getBytes(UTF_8))
.when(mtxSidecarClient)
.getOrdResourceDefinition("test:ord:service/test.oas3.json");

assertEquals(
"{}",
Expand Down
Loading