-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: yushuwang <[email protected]>
- Loading branch information
Showing
2 changed files
with
92 additions
and
1 deletion.
There are no files selected for viewing
3 changes: 2 additions & 1 deletion
3
...rces/META-INF/services/com.arextest.web.core.business.filesystem.pincase.MockerConversion
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
com.arextest.web.core.business.filesystem.pincase.ServletMockerConversionImpl | ||
com.arextest.web.core.business.filesystem.pincase.ServletMockerConversionImpl | ||
com.arextest.web.core.business.filesystem.pincase.DubboProviderMockerConversionImpl |
90 changes: 90 additions & 0 deletions
90
.../com/arextest/web/core/business/filesystem/pincase/DubboProviderMockerConversionImpl.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,90 @@ | ||
package com.arextest.web.core.business.filesystem.pincase; | ||
|
||
import com.arextest.model.mock.AREXMocker; | ||
import com.arextest.model.mock.Mocker; | ||
import com.arextest.web.common.LogUtils; | ||
import com.arextest.web.core.business.constants.NetworkConstants; | ||
import com.arextest.web.model.dto.KeyValuePairDto; | ||
import com.arextest.web.model.dto.filesystem.AddressDto; | ||
import com.arextest.web.model.dto.filesystem.BodyDto; | ||
import com.arextest.web.model.dto.filesystem.FSCaseDto; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Base64; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author wildeslam. | ||
* @create 2023/12/6 16:46 | ||
*/ | ||
@Slf4j | ||
public class DubboProviderMockerConversionImpl implements MockerConversion { | ||
private static final String DUBBO = "Dubbo"; | ||
|
||
@Override | ||
public String getCategoryName() { | ||
return "DubboProvider"; | ||
} | ||
|
||
@Override | ||
public FSCaseDto mockerConvertToFsCase(AREXMocker mocker) { | ||
if (mocker == null) { | ||
return null; | ||
} | ||
FSCaseDto caseDto = new FSCaseDto(); | ||
|
||
Mocker.Target targetRequest = mocker.getTargetRequest(); | ||
if (targetRequest == null) { | ||
return null; | ||
} | ||
|
||
try { | ||
AddressDto addressDto = new AddressDto(); | ||
addressDto.setMethod(DUBBO); | ||
addressDto.setEndpoint(mocker.getOperationName()); | ||
caseDto.setAddress(addressDto); | ||
|
||
String contentType = StringUtils.EMPTY; | ||
|
||
Map<String, String> headers = (Map<String, String>) targetRequest.getAttribute("Headers"); | ||
if (headers != null) { | ||
List<KeyValuePairDto> kvPair = new ArrayList<>(headers.size()); | ||
for (Map.Entry<String, String> header : headers.entrySet()) { | ||
if (StringUtils.equalsIgnoreCase(header.getKey(), NetworkConstants.CONTENT_TYPE)) { | ||
contentType = header.getValue(); | ||
} | ||
KeyValuePairDto kv = new KeyValuePairDto(); | ||
kv.setKey(header.getKey()); | ||
kv.setValue(header.getValue()); | ||
kv.setActive(true); | ||
kvPair.add(kv); | ||
} | ||
caseDto.setHeaders(kvPair); | ||
} | ||
|
||
if (StringUtils.isNotBlank(targetRequest.getBody())) { | ||
BodyDto bodyDto = new BodyDto(); | ||
bodyDto.setContentType(contentType); | ||
if (contentType.toLowerCase().contains(NetworkConstants.APPLICATION_JSON)) { | ||
try { | ||
bodyDto.setBody(new String(Base64.getDecoder().decode(targetRequest.getBody()))); | ||
} catch (Exception e) { | ||
bodyDto.setBody(targetRequest.getBody()); | ||
} | ||
} else { | ||
bodyDto.setBody(targetRequest.getBody()); | ||
} | ||
caseDto.setBody(bodyDto); | ||
|
||
} | ||
|
||
return caseDto; | ||
} catch (Exception e) { | ||
LogUtils.error(LOGGER, "Failed to convert AREXMocker to FSCaseDto", e); | ||
return null; | ||
} | ||
} | ||
} |