Skip to content

Commit

Permalink
Merge pull request #375 from chamil321/codecov-improve
Browse files Browse the repository at this point in the history
Improve test coverage
  • Loading branch information
chamil321 authored May 10, 2021
2 parents 90a14b0 + a9a4260 commit eb954d1
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 108 deletions.
6 changes: 4 additions & 2 deletions http-ballerina-tests/tests/http_client_data_binding.bal
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ service /passthrough on clientDBProxyListener {
var res = clientDBBackendClient->post("/backend/get5XX", "want 500", targetType = json);
if res is http:RemoteServerError {
http:Response resp = new;
resp.statusCode = res.detail()?.statusCode ?: 500;
http:Detail? details = res.detail();
resp.statusCode = details?.statusCode ?: 560;
resp.setPayload(<@untainted>res.message());
error? responseToCaller = caller->respond(<@untainted>resp);
} else {
Expand All @@ -143,7 +144,8 @@ service /passthrough on clientDBProxyListener {
var res = clientDBBackendClient->post("/backend/" + <@untainted>path, "want 500", targetType = json);
if res is http:ClientRequestError {
http:Response resp = new;
resp.statusCode = res.detail()?.statusCode ?: 400;
http:Detail? details = res.detail();
resp.statusCode = details?.statusCode ?: 420;
resp.setPayload(<@untainted>res.message());
error? responseToCaller = caller->respond(<@untainted>resp);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,6 @@ public static void createSimpleHttpClient(BObject httpClient, BMap globalPoolCon
.createHttpClientConnector(properties, senderConfiguration, poolManager);
httpClient.addNativeData(HttpConstants.CLIENT, httpClientConnector);
}

private CreateSimpleHttpClient() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ public static void initGlobalPool(BMap globalPoolConfig) {
ConnectionManager connectionManager = new ConnectionManager(globalPool);
globalPoolConfig.addNativeData(CONNECTION_MANAGER, connectionManager);
}

private InitGlobalPool() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,6 @@ public static void setPipeliningListener(HttpCarbonMessage httpResponse) {
pipeliningFuture.setPipeliningListener(pipeliningListener);
httpResponse.setPipeliningFuture(pipeliningFuture);
}

private PipeliningHandler() {}
}
10 changes: 2 additions & 8 deletions http-native/src/main/java/org/ballerinalang/net/uri/URIUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@ public class URIUtil {

public static final String URI_PATH_DELIMITER = "/";
public static final char DOT_SEGMENT = '.';
private static final BString[] EMPTY_STRING_ARRAY = new BString[0];

public static String[] getPathSegments(String path) {
if (path.startsWith(URI_PATH_DELIMITER)) {
path = path.substring(1);
}
return path.split(URI_PATH_DELIMITER);
}

public static String getSubPath(String path, String basePath) {
if (path.length() == basePath.length()) {
Expand Down Expand Up @@ -138,4 +130,6 @@ public static String extractMatrixParams(String path, Map<String, Map<String, St
}
return pathToMatrixParam;
}

private URIUtil() {}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,11 @@ private void setUriPostFix(HttpResourceArguments variables, String subUriFragmen

private Node<DataType, InboundMsgType> getMatchingChildNode(Node<DataType, InboundMsgType> prospectiveChild,
List<Node<DataType, InboundMsgType>> existingChildren) throws URITemplateException {
boolean dotSuffixExpression = prospectiveChild instanceof DotSuffixExpression;
boolean simpleStringExpression = prospectiveChild instanceof SimpleStringExpression;
String prospectiveChildToken = prospectiveChild.getToken();

for (Node<DataType, InboundMsgType> existingChild : existingChildren) {
if (dotSuffixExpression) {
if (existingChild instanceof DotSuffixExpression) {
return getExistingChildNode(prospectiveChild, existingChild);
} else {
continue;
}
}
if (simpleStringExpression && existingChild instanceof Expression
&& !(existingChild instanceof DotSuffixExpression)) {
if (simpleStringExpression && existingChild instanceof Expression) {
return getExistingChildNode(prospectiveChild, existingChild);
}
if (existingChild.getToken().equals(prospectiveChildToken)) {
Expand All @@ -166,8 +157,6 @@ private int getIntValue(Node node) {
return 0;
}
return node.getToken().length() + 5;
} else if (node instanceof DotSuffixExpression) {
return 2;
} else {
return 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package org.ballerinalang.net.uri.parser;

import org.ballerinalang.net.uri.URITemplateException;
import org.ballerinalang.net.uri.URIUtil;

import java.io.UnsupportedEncodingException;

Expand Down Expand Up @@ -128,8 +127,6 @@ private void createExpressionNode(String expression, String segment, int maxInde
Node<DataType, InboundMgsType> node;
if (maxIndex == pointerIndex) {
node = new SimpleStringExpression<>(createElement(), expression);
} else if (maxIndex > pointerIndex && segment.charAt(pointerIndex + 1) == URIUtil.DOT_SEGMENT) {
node = new DotSuffixExpression<>(createElement(), expression);
} else {
throw new URITemplateException("Template expression: " + segment + " is not implemented");
}
Expand Down

0 comments on commit eb954d1

Please sign in to comment.