-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
def7b58
commit 9d3c761
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
...est/java/com/consoleconnect/kraken/operator/gateway/service/RenderRequestServiceTest.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,57 @@ | ||
package com.consoleconnect.kraken.operator.gateway.service; | ||
|
||
import com.consoleconnect.kraken.operator.core.dto.StateValueMappingDto; | ||
import com.consoleconnect.kraken.operator.core.model.UnifiedAsset; | ||
import com.consoleconnect.kraken.operator.core.model.facet.ComponentAPITargetFacets; | ||
import com.consoleconnect.kraken.operator.core.service.UnifiedAssetService; | ||
import com.consoleconnect.kraken.operator.core.toolkit.JsonToolkit; | ||
import com.consoleconnect.kraken.operator.gateway.CustomConfig; | ||
import com.consoleconnect.kraken.operator.gateway.helper.AssetConfigReader; | ||
import com.consoleconnect.kraken.operator.test.MockIntegrationTest; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import lombok.SneakyThrows; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.MethodOrderer; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestMethodOrder; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.mock.mockito.SpyBean; | ||
import org.springframework.test.context.ContextConfiguration; | ||
|
||
@Slf4j | ||
@MockIntegrationTest | ||
@ContextConfiguration(classes = CustomConfig.class) | ||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class) | ||
class RenderRequestServiceTest extends AssetConfigReader { | ||
|
||
@Autowired private UnifiedAssetService unifiedAssetService; | ||
|
||
@SpyBean RenderRequestService renderRequestService; | ||
|
||
@SneakyThrows | ||
@Test | ||
void givenArrayItems_whenHandleBody_thenReturnOK() { | ||
Map<String, Object> map = | ||
JsonToolkit.fromJson( | ||
readFileToString("mockData/quoteArrayRequest.json"), | ||
new TypeReference<Map<String, Object>>() {}); | ||
Map<String, Object> inputs = new HashMap<>(); | ||
inputs.put("body", map); | ||
StateValueMappingDto stateValueMappingDto = new StateValueMappingDto(); | ||
UnifiedAsset targetAsset = | ||
getTarget( | ||
"deployment-config/components/api-targets/api-target.quote.uni.add.sync.yaml", | ||
"deployment-config/components/api-targets-mappers/api-target-mapper.quote.uni.add.sync.yaml"); | ||
ComponentAPITargetFacets facets = | ||
UnifiedAsset.getFacets(targetAsset, ComponentAPITargetFacets.class); | ||
renderRequestService.handleBody(facets, stateValueMappingDto, inputs); | ||
String transformedRequest = | ||
com.consoleconnect.kraken.operator.core.toolkit.StringUtils.compact( | ||
facets.getEndpoints().get(0).getRequestBody()); | ||
String expectedResult = readCompactedFile("mockData/expected-quote-array-request.json"); | ||
Assertions.assertEquals(expectedResult, transformedRequest); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...sdk/kraken-java-sdk-gateway/src/test/resources/mockData/expected-quote-array-request.json
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,15 @@ | ||
{ | ||
"ports" : [ { | ||
"durationUnit" : "${body.quoteItem[0].requestedQuoteItemTerm.duration.units}", | ||
"dcf" : "${body.quoteItem[0].product.place[0].id}", | ||
"speed" : "${body.quoteItem[0].product.productConfiguration.bandwidth}" | ||
}, { | ||
"durationUnit" : "${body.quoteItem[1].requestedQuoteItemTerm.duration.units}", | ||
"dcf" : "${body.quoteItem[1].product.place[0].id}", | ||
"speed" : "${body.quoteItem[1].product.productConfiguration.bandwidth}" | ||
}, { | ||
"durationUnit" : "${body.quoteItem[2].requestedQuoteItemTerm.duration.units}", | ||
"dcf" : "${body.quoteItem[2].product.place[0].id}", | ||
"speed" : "${body.quoteItem[2].product.productConfiguration.bandwidth}" | ||
} ] | ||
} |