Skip to content

Commit

Permalink
Merge pull request #1790 from vil02/4923_make_some_java_classes_prope…
Browse files Browse the repository at this point in the history
…r_utilities

Make some Java classes proper utilities
  • Loading branch information
TharmiganK authored Oct 17, 2023
2 parents 72832c3 + ca80dac commit 7d7bae9
Show file tree
Hide file tree
Showing 28 changed files with 82 additions and 26 deletions.
1 change: 1 addition & 0 deletions ballerina-tests/http-service-tests/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ graalvmCompatible = true
[[platform.java17.dependency]]
scope = "testOnly"
path = "../../test-utils/build/libs/http-test-utils-2.10.3.jar"

5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ This file contains all the notable changes done to the Ballerina HTTP package th
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed
- [Make some of the Java classes proper utility classes](https://github.com/ballerina-platform/ballerina-standard-library/issues/4923)

## [2.10.3] - 2023-10-13

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
/**
* Constants related to compiler plugin tests.
*/
public class CompilerPluginTestConstants {
public final class CompilerPluginTestConstants {
private CompilerPluginTestConstants() {}

public static final String HTTP_101 = "HTTP_101";
public static final String HTTP_102 = "HTTP_102";
public static final String HTTP_103 = "HTTP_103";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
/**
* Constants related to compiler plugin implementation.
*/
public class Constants {
public final class Constants {
private Constants() {}

public static final String BALLERINA = "ballerina";
public static final String HTTP = "http";
public static final String SERVICE_KEYWORD = "service";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@
/**
* Utility class providing http compiler plugin utility methods.
*/
public class HttpCompilerPluginUtil {
public final class HttpCompilerPluginUtil {

private HttpCompilerPluginUtil() {}

public static void updateDiagnostic(SyntaxNodeAnalysisContext ctx, Location location,
HttpDiagnosticCodes httpDiagnosticCodes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
/**
* Validates a ballerina http interceptor resource.
*/
public class HttpInterceptorResourceValidator {
public final class HttpInterceptorResourceValidator {
private HttpInterceptorResourceValidator() {}

public static void validateResource(SyntaxNodeAnalysisContext ctx, FunctionDefinitionNode member, String type,
Map<String, TypeSymbol> typeSymbols) {
checkResourceAnnotation(ctx, member);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@
/**
* Validates a ballerina http resource.
*/
public class HttpResourceValidator {
public final class HttpResourceValidator {

private HttpResourceValidator() {}

static void validateResource(SyntaxNodeAnalysisContext ctx, FunctionDefinitionNode member,
LinksMetaData linksMetaData, Map<String, TypeSymbol> typeSymbols) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
/**
* Constants related to compiler plugin code-action implementation.
*/
public class Constants {
public final class Constants {
private Constants () {}

public static final String NODE_LOCATION_KEY = "node.location";
public static final String IS_ERROR_INTERCEPTOR_TYPE = "node.errorInterceptor";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
/**
* Constants related to compiler plugin completion implementation.
*/
public class Constants {
public final class Constants {
private Constants() {}

public static final String GET = "get";
public static final String POST = "post";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*
* @since 0.8.0
*/
public class HttpConstants {
public final class HttpConstants {

public static final String HTTPS_ENDPOINT_STARTED = "[ballerina/http] started HTTPS/WSS listener ";
public static final String HTTP_ENDPOINT_STARTED = "[ballerina/http] started HTTP/WS listener ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
*
* @since 0.89
*/
public class LogLevelMapper {
public final class LogLevelMapper {

private LogLevelMapper() {}

public static String getBallerinaLogLevel(Level level) {
switch (level.getName()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
/**
* Utilities related to HTTP request context.
*/
public class ExternRequestContext {
public final class ExternRequestContext {

private ExternRequestContext() {}

public static Object getWithType(BObject requestCtx, BString key, BTypedesc targetType) {
BMap members = requestCtx.getMapValue(HttpConstants.REQUEST_CTX_MEMBERS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
/**
* Contains external utility functions.
*/
public class ExternUtils {
public final class ExternUtils {

private ExternUtils() {}

/**
* Provides the relevant reason phrase for a given status code.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@
*
* @since 6.0.241
*/
public class Http2StateUtil {
public final class Http2StateUtil {

private Http2StateUtil() {}

private static final Logger LOG = LoggerFactory.getLogger(Http2StateUtil.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
/**
* Utilities related to dispatcher processing.
*/
public class DispatcherUtil {
public final class DispatcherUtil {

private DispatcherUtil() {}

private static String[] allMethods = new String[]{HttpConstants.HTTP_METHOD_GET, HttpConstants.HTTP_METHOD_HEAD
, HttpConstants.HTTP_METHOD_POST, HttpConstants.HTTP_METHOD_DELETE, HttpConstants.HTTP_METHOD_PATCH
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
/**
* A test utils for http unit test classes.
*/
public class TestUtils {
public final class TestUtils {

private TestUtils() {}

public static final int SOCKET_SERVER_PORT = 8001;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@

import static io.ballerina.stdlib.http.transport.contract.Constants.HTTP_2_0;

class Continue100Util {
public final class Continue100Util {
private Continue100Util() {}

static ListenerConfiguration getListenerConfigs() {
ListenerConfiguration listenerConfiguration = new ListenerConfiguration();
listenerConfiguration.setPort(TestUtil.SERVER_CONNECTOR_PORT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@
/**
* A util class to use in both http and https proxy scenarios.
*/
public class ProxyServerUtil {
public final class ProxyServerUtil {
private ProxyServerUtil() {}

private static HttpClientConnector httpClientConnector;
private static ServerConnector serverConnector;
private static HttpWsConnectorFactory httpWsConnectorFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
*
* @since 6.0.273
*/
public class Http2Util {
public final class Http2Util {

private Http2Util() {}

public static final String HTTP2_RESPONSE_PAYLOAD = "Final Response";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@
/**
* A util class to be used for tests.
*/
public class TestUtil {
public final class TestUtil {

private TestUtil() {}

private static final Logger LOG = LoggerFactory.getLogger(TestUtil.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@
/**
* A utility class which generates HTTP/2.0 requests.
*/
public class MessageGenerator {
public final class MessageGenerator {
private MessageGenerator() {}

public static HttpCarbonMessage generateRequest(HttpMethod httpMethod, String payload) {
HttpCarbonMessage httpCarbonMessage = new HttpCarbonRequest(new DefaultHttpRequest(
new HttpVersion(Constants.DEFAULT_VERSION_HTTP_1_1, true), httpMethod,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
/**
* WebSocket constants for testing purposes.
*/
public class WebSocketTestConstants {
public final class WebSocketTestConstants {
private WebSocketTestConstants() {}

public static final String PAYLOAD_NEW_CLIENT_CONNECTED = "NEW_CLIENT_CONNECTED";
public static final String PAYLOAD_CLIENT_LEFT = "CLIENT_LEFT";
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
/**
* Contains assert functions used by mime test cases.
*/
public class Assert {
public final class Assert {

private Assert() {}

public static void assertEquals(Object actual, Object expected) {
if (!areEqual(actual, expected)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
*
* @since 0.982.0
*/
public class ExternPipeliningTestUtil {
public final class ExternPipeliningTestUtil {

private ExternPipeliningTestUtil() {}

private static final Logger log = LoggerFactory.getLogger(ExternPipeliningTestUtil.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
/**
* Contains utility functions used for the retry test.
*/
public class ExternRetryMultipartTestutil {
public final class ExternRetryMultipartTestutil {

private ExternRetryMultipartTestutil() {}

private static final Logger log = LoggerFactory.getLogger(ExternRetryMultipartTestutil.class);
private static final String RETRY_HEADER = "x-retry";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
/**
* Constants used in test cases.
*/
public class TestConstant {
public final class TestConstant {
private TestConstant() {}

public static final String CONTENT_TYPE_JSON = "application/json";
public static final String CONTENT_TYPE_XML = "application/xml";
public static final String CONTENT_TYPE_TEXT_PLAIN = "text/plain";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
/**
* A utility class for keep payloads.
*/
public class Utils {
public final class Utils {

private Utils() {}

public static String getEntityBodyFrom(FullHttpResponse httpResponse) {
ByteBuffer content = httpResponse.content().nioBuffer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
/**
* A simple URL connection HTTP client to be used in test cases.
*/
public class HttpUrlClient {
public final class HttpUrlClient {

private HttpUrlClient() {}

private static final Logger log = LoggerFactory.getLogger(HttpUrlClient.class);
private static final int DEFAULT_READ_TIMEOUT = 30000;
Expand Down

0 comments on commit 7d7bae9

Please sign in to comment.