Code format hawkbit-rest-core (#1944)

Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2024-11-05 11:32:28 +02:00
committed by GitHub
parent b863fdb337
commit 4b460d8e68
24 changed files with 315 additions and 398 deletions

View File

@@ -9,7 +9,7 @@
SPDX-License-Identifier: EPL-2.0 SPDX-License-Identifier: EPL-2.0
--> -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>

View File

@@ -20,7 +20,7 @@ import org.springframework.context.annotation.Configuration;
@Configuration @Configuration
@ConditionalOnProperty( @ConditionalOnProperty(
value="hawkbit.server.swagger.enabled", value = "hawkbit.server.swagger.enabled",
havingValue = "true", havingValue = "true",
matchIfMissing = true) matchIfMissing = true)
public class OpenApiConfiguration { public class OpenApiConfiguration {
@@ -42,7 +42,7 @@ public class OpenApiConfiguration {
@Bean @Bean
@ConditionalOnProperty( @ConditionalOnProperty(
value="hawkbit.server.swagger.mgmt.api.group.enabled", value = "hawkbit.server.swagger.mgmt.api.group.enabled",
havingValue = "true", havingValue = "true",
matchIfMissing = true) matchIfMissing = true)
public GroupedOpenApi mgmtApi() { public GroupedOpenApi mgmtApi() {
@@ -74,9 +74,10 @@ public class OpenApiConfiguration {
}) })
.build(); .build();
} }
@Bean @Bean
@ConditionalOnProperty( @ConditionalOnProperty(
value="hawkbit.server.swagger.ddi.api.group.enabled", value = "hawkbit.server.swagger.ddi.api.group.enabled",
havingValue = "true", havingValue = "true",
matchIfMissing = true) matchIfMissing = true)
public GroupedOpenApi ddiApi() { public GroupedOpenApi ddiApi() {

View File

@@ -9,8 +9,6 @@
*/ */
package org.eclipse.hawkbit.rest; package org.eclipse.hawkbit.rest;
import jakarta.servlet.http.HttpServletResponse;
import org.eclipse.hawkbit.rest.exception.ResponseExceptionHandler; import org.eclipse.hawkbit.rest.exception.ResponseExceptionHandler;
import org.eclipse.hawkbit.rest.filter.ExcludePathAwareShallowETagFilter; import org.eclipse.hawkbit.rest.filter.ExcludePathAwareShallowETagFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.boot.web.servlet.FilterRegistrationBean;
@@ -20,7 +18,6 @@ import org.springframework.hateoas.config.EnableHypermediaSupport;
import org.springframework.hateoas.config.EnableHypermediaSupport.HypermediaType; import org.springframework.hateoas.config.EnableHypermediaSupport.HypermediaType;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.context.WebApplicationContext;
/** /**
* Configuration for Rest api. * Configuration for Rest api.

View File

@@ -26,8 +26,7 @@ public class ResponseList<T> extends RepresentationModel<ResponseList<T>> implem
private final List<T> content; private final List<T> content;
/** /**
* @param content * @param content to delegate
* to delegate
*/ */
public ResponseList(final List<T> content) { public ResponseList(final List<T> content) {
this.content = content; this.content = content;
@@ -103,16 +102,6 @@ public class ResponseList<T> extends RepresentationModel<ResponseList<T>> implem
content.clear(); content.clear();
} }
@Override
public boolean equals(final Object o) {
return content.equals(o);
}
@Override
public int hashCode() {
return content.hashCode();
}
@Override @Override
public T get(final int index) { public T get(final int index) {
return content.get(index); return content.get(index);
@@ -163,4 +152,14 @@ public class ResponseList<T> extends RepresentationModel<ResponseList<T>> implem
return "ResponseList [content=" + content + "]"; return "ResponseList [content=" + content + "]";
} }
@Override
public boolean equals(final Object o) {
return content.equals(o);
}
@Override
public int hashCode() {
return content.hashCode();
}
} }

View File

@@ -27,11 +27,9 @@ public enum SortDirection {
/** /**
* Returns the sort direction for the given name. * Returns the sort direction for the given name.
* *
* @param name * @param name the name of the enum
* the name of the enum
* @return the corresponding enum * @return the corresponding enum
* @throws SortParameterUnsupportedDirectionException * @throws SortParameterUnsupportedDirectionException if there is no matching enum for the specified name
* if there is no matching enum for the specified name
*/ */
public static SortDirection getByName(final String name) { public static SortDirection getByName(final String name) {
try { try {

View File

@@ -9,11 +9,11 @@
*/ */
package org.eclipse.hawkbit.rest.exception; package org.eclipse.hawkbit.rest.exception;
import java.io.Serial;
import org.eclipse.hawkbit.exception.AbstractServerRtException; import org.eclipse.hawkbit.exception.AbstractServerRtException;
import org.eclipse.hawkbit.exception.SpServerError; import org.eclipse.hawkbit.exception.SpServerError;
import java.io.Serial;
/** /**
* Exception which is thrown in case an request body is not well formatted and * Exception which is thrown in case an request body is not well formatted and
* cannot be parsed. * cannot be parsed.

View File

@@ -14,15 +14,13 @@ import org.eclipse.hawkbit.exception.SpServerError;
/** /**
* Thrown if a multi part exception occurred. * Thrown if a multi part exception occurred.
*
*/ */
public final class MultiPartFileUploadException extends AbstractServerRtException { public final class MultiPartFileUploadException extends AbstractServerRtException {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** /**
* @param cause * @param cause for the exception
* for the exception
*/ */
public MultiPartFileUploadException(final Throwable cause) { public MultiPartFileUploadException(final Throwable cause) {
super(cause.getMessage(), SpServerError.SP_ARTIFACT_UPLOAD_FAILED, cause); super(cause.getMessage(), SpServerError.SP_ARTIFACT_UPLOAD_FAILED, cause);

View File

@@ -99,19 +99,12 @@ public class ResponseExceptionHandler {
ERROR_TO_HTTP_STATUS.put(SpServerError.SP_STOP_ROLLOUT_FAILED, HttpStatus.LOCKED); ERROR_TO_HTTP_STATUS.put(SpServerError.SP_STOP_ROLLOUT_FAILED, HttpStatus.LOCKED);
} }
private static HttpStatus getStatusOrDefault(final SpServerError error) {
return ERROR_TO_HTTP_STATUS.getOrDefault(error, DEFAULT_RESPONSE_STATUS);
}
/** /**
* method for handling exception of type AbstractServerRtException. Called * method for handling exception of type AbstractServerRtException. Called
* by the Spring-Framework for exception handling. * by the Spring-Framework for exception handling.
* *
* @param request * @param request the Http request
* the Http request * @param ex the exception which occurred
* @param ex
* the exception which occurred
*
* @return the entity to be responded containing the exception information * @return the entity to be responded containing the exception information
* as entity. * as entity.
*/ */
@@ -137,10 +130,8 @@ public class ResponseExceptionHandler {
* ResponseStatus 500 is returned. Called by the Spring-Framework for * ResponseStatus 500 is returned. Called by the Spring-Framework for
* exception handling. * exception handling.
* *
* @param request * @param request the Http request
* the Http request * @param ex the exception which occurred
* @param ex
* the exception which occurred
* @return the entity to be responded containing the response status 500 * @return the entity to be responded containing the response status 500
*/ */
@ExceptionHandler(FileStreamingFailedException.class) @ExceptionHandler(FileStreamingFailedException.class)
@@ -158,10 +149,8 @@ public class ResponseExceptionHandler {
* cannot be deserialized. Called by the Spring-Framework for exception * cannot be deserialized. Called by the Spring-Framework for exception
* handling. * handling.
* *
* @param request * @param request the Http request
* the Http request * @param ex the exception which occurred
* @param ex
* the exception which occurred
* @return the entity to be responded containing the exception information * @return the entity to be responded containing the exception information
* as entity. * as entity.
*/ */
@@ -181,10 +170,8 @@ public class ResponseExceptionHandler {
* is thrown in case the request is rejected due to a constraint violation. * is thrown in case the request is rejected due to a constraint violation.
* Called by the Spring-Framework for exception handling. * Called by the Spring-Framework for exception handling.
* *
* @param request * @param request the Http request
* the Http request * @param ex the exception which occurred
* @param ex
* the exception which occurred
* @return the entity to be responded containing the exception information * @return the entity to be responded containing the exception information
* as entity. * as entity.
*/ */
@@ -208,10 +195,8 @@ public class ResponseExceptionHandler {
* in case the request is rejected due to invalid requests. Called by the * in case the request is rejected due to invalid requests. Called by the
* Spring-Framework for exception handling. * Spring-Framework for exception handling.
* *
* @param request * @param request the Http request
* the Http request * @param ex the exception which occurred
* @param ex
* the exception which occurred
* @return the entity to be responded containing the exception information * @return the entity to be responded containing the exception information
* as entity. * as entity.
*/ */
@@ -233,10 +218,8 @@ public class ResponseExceptionHandler {
* thrown in case the request body is not well formed and cannot be * thrown in case the request body is not well formed and cannot be
* deserialized. Called by the Spring-Framework for exception handling. * deserialized. Called by the Spring-Framework for exception handling.
* *
* @param request * @param request the Http request
* the Http request * @param ex the exception which occurred
* @param ex
* the exception which occurred
* @return the entity to be responded containing the exception information * @return the entity to be responded containing the exception information
* as entity. * as entity.
*/ */
@@ -258,6 +241,10 @@ public class ResponseExceptionHandler {
return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST); return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
} }
private static HttpStatus getStatusOrDefault(final SpServerError error) {
return ERROR_TO_HTTP_STATUS.getOrDefault(error, DEFAULT_RESPONSE_STATUS);
}
private void logRequest(final HttpServletRequest request, final Exception ex) { private void logRequest(final HttpServletRequest request, final Exception ex) {
log.debug("Handling exception {} of request {}", ex.getClass().getName(), request.getRequestURL()); log.debug("Handling exception {} of request {}", ex.getClass().getName(), request.getRequestURL());
} }

View File

@@ -14,10 +14,6 @@ import org.eclipse.hawkbit.exception.SpServerError;
/** /**
* Exception used by the REST API in case of invalid sort parameter syntax. * Exception used by the REST API in case of invalid sort parameter syntax.
*
*
*
*
*/ */
public class SortParameterSyntaxErrorException extends AbstractServerRtException { public class SortParameterSyntaxErrorException extends AbstractServerRtException {

View File

@@ -15,10 +15,6 @@ import org.eclipse.hawkbit.exception.SpServerError;
/** /**
* Exception used by the REST API in case of invalid sort parameter direction * Exception used by the REST API in case of invalid sort parameter direction
* name. * name.
*
*
*
*
*/ */
public class SortParameterUnsupportedDirectionException extends AbstractServerRtException { public class SortParameterUnsupportedDirectionException extends AbstractServerRtException {
@@ -38,8 +34,7 @@ public class SortParameterUnsupportedDirectionException extends AbstractServerRt
* Creates a new SortParameterSyntaxErrorException with * Creates a new SortParameterSyntaxErrorException with
* {@link SpServerError#SP_REST_SORT_PARAM_INVALID_DIRECTION} error. * {@link SpServerError#SP_REST_SORT_PARAM_INVALID_DIRECTION} error.
* *
* @param cause * @param cause the cause (which is saved for later retrieval by the
* the cause (which is saved for later retrieval by the
* getCause() method). (A null value is permitted, and indicates * getCause() method). (A null value is permitted, and indicates
* that the cause is nonexistent or unknown.) * that the cause is nonexistent or unknown.)
*/ */

View File

@@ -15,10 +15,6 @@ import org.eclipse.hawkbit.exception.SpServerError;
/** /**
* Exception used by the REST API in case of invalid field name in the sort * Exception used by the REST API in case of invalid field name in the sort
* parameter. * parameter.
*
*
*
*
*/ */
public class SortParameterUnsupportedFieldException extends AbstractServerRtException { public class SortParameterUnsupportedFieldException extends AbstractServerRtException {
@@ -39,8 +35,7 @@ public class SortParameterUnsupportedFieldException extends AbstractServerRtExce
* Creates a new SortParameterSyntaxErrorException with * Creates a new SortParameterSyntaxErrorException with
* {@link SpServerError#SP_REST_SORT_PARAM_INVALID_FIELD} error. * {@link SpServerError#SP_REST_SORT_PARAM_INVALID_FIELD} error.
* *
* @param cause * @param cause the cause (which is saved for later retrieval by the
* the cause (which is saved for later retrieval by the
* getCause() method). (A null value is permitted, and indicates * getCause() method). (A null value is permitted, and indicates
* that the cause is nonexistent or unknown.) * that the cause is nonexistent or unknown.)
*/ */

View File

@@ -30,8 +30,7 @@ public final class FileStreamingFailedException extends AbstractServerRtExceptio
/** /**
* Constructor with Throwable. * Constructor with Throwable.
* *
* @param cause * @param cause for the exception
* for the exception
*/ */
public FileStreamingFailedException(final Throwable cause) { public FileStreamingFailedException(final Throwable cause) {
super(SpServerError.SP_ARTIFACT_LOAD_FAILED, cause); super(SpServerError.SP_ARTIFACT_LOAD_FAILED, cause);
@@ -40,8 +39,7 @@ public final class FileStreamingFailedException extends AbstractServerRtExceptio
/** /**
* Constructor with error string. * Constructor with error string.
* *
* @param message * @param message of the error
* of the error
*/ */
public FileStreamingFailedException(final String message) { public FileStreamingFailedException(final String message) {
super(message, SpServerError.SP_ARTIFACT_LOAD_FAILED); super(message, SpServerError.SP_ARTIFACT_LOAD_FAILED);
@@ -50,10 +48,8 @@ public final class FileStreamingFailedException extends AbstractServerRtExceptio
/** /**
* Constructor with error string and cause. * Constructor with error string and cause.
* *
* @param message * @param message of the error
* of the error * @param cause for the exception
* @param cause
* for the exception
*/ */
public FileStreamingFailedException(final String message, final Throwable cause) { public FileStreamingFailedException(final String message, final Throwable cause) {
super(message, SpServerError.SP_ARTIFACT_LOAD_FAILED, cause); super(message, SpServerError.SP_ARTIFACT_LOAD_FAILED, cause);

View File

@@ -11,7 +11,6 @@ package org.eclipse.hawkbit.rest.util;
/** /**
* Listener for progress on artifact file streaming. * Listener for progress on artifact file streaming.
*
*/ */
@FunctionalInterface @FunctionalInterface
public interface FileStreamingProgressListener { public interface FileStreamingProgressListener {
@@ -19,12 +18,9 @@ public interface FileStreamingProgressListener {
/** /**
* Called multiple times during streaming. * Called multiple times during streaming.
* *
* @param requestedBytes * @param requestedBytes requested bytes of the request
* requested bytes of the request * @param shippedBytesSinceLast since the last report
* @param shippedBytesSinceLast * @param shippedBytesOverall during the request
* since the last report
* @param shippedBytesOverall
* during the request
*/ */
void progress(long requestedBytes, long shippedBytesSinceLast, long shippedBytesOverall); void progress(long requestedBytes, long shippedBytesSinceLast, long shippedBytesOverall);
} }

View File

@@ -12,7 +12,6 @@ package org.eclipse.hawkbit.rest.util;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.math.RoundingMode;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@@ -50,15 +49,11 @@ public final class FileStreamingUtil {
/** /**
* Write a md5 file response. * Write a md5 file response.
* *
* @param response * @param response the response
* the response * @param md5Hash of the artifact
* @param md5Hash * @param filename as provided by the client
* of the artifact
* @param filename
* as provided by the client
* @return the response * @return the response
* @throws IOException * @throws IOException cannot write output stream
* cannot write output stream
*/ */
public static ResponseEntity<Void> writeMD5FileResponse(final HttpServletResponse response, final String md5Hash, public static ResponseEntity<Void> writeMD5FileResponse(final HttpServletResponse response, final String md5Hash,
final String filename) throws IOException { final String filename) throws IOException {
@@ -94,26 +89,16 @@ public final class FileStreamingUtil {
* The request supports RFC7233 range requests. * The request supports RFC7233 range requests.
* </p> * </p>
* *
* @param artifact * @param artifact the artifact
* the artifact * @param filename to be written to the client response
* @param filename * @param lastModified unix timestamp of the artifact
* to be written to the client response * @param response to be sent back to the requesting client
* @param lastModified * @param request from the client
* unix timestamp of the artifact * @param progressListener to write progress updates to
* @param response
* to be sent back to the requesting client
* @param request
* from the client
* @param progressListener
* to write progress updates to
*
* @return http response * @return http response
* * @throws FileStreamingFailedException if streaming fails
* @see <a href="https://tools.ietf.org/html/rfc7233">https://tools.ietf.org * @see <a href="https://tools.ietf.org/html/rfc7233">https://tools.ietf.org
* /html/rfc7233</a> * /html/rfc7233</a>
*
* @throws FileStreamingFailedException
* if streaming fails
*/ */
public static ResponseEntity<InputStream> writeFileResponse(final DbArtifact artifact, final String filename, public static ResponseEntity<InputStream> writeFileResponse(final DbArtifact artifact, final String filename,
final long lastModified, final HttpServletResponse response, final HttpServletRequest request, final long lastModified, final HttpServletResponse response, final HttpServletRequest request,
@@ -187,7 +172,7 @@ public final class FileStreamingUtil {
return result; return result;
} }
private static void resetResponseExceptHeaders(final HttpServletResponse response){ private static void resetResponseExceptHeaders(final HttpServletResponse response) {
// do backup the current headers (like CORS related) // do backup the current headers (like CORS related)
final Map<String, String> storedHeaders = new HashMap<>(); final Map<String, String> storedHeaders = new HashMap<>();
for (final String header : response.getHeaderNames()) { for (final String header : response.getHeaderNames()) {
@@ -359,7 +344,7 @@ public final class FileStreamingUtil {
} }
if (progressListener != null) { if (progressListener != null) {
final int newPercent = (int)Math.floor(total * 100.0 / length); final int newPercent = (int) Math.floor(total * 100.0 / length);
// every 10 percent an event // every 10 percent an event
if (newPercent == 100 || newPercent > progressPercent + 10) { if (newPercent == 100 || newPercent > progressPercent + 10) {
@@ -383,6 +368,7 @@ public final class FileStreamingUtil {
} }
private static final class ByteRange { private static final class ByteRange {
private static final String MULTIPART_BOUNDARY = "THIS_STRING_SEPARATES_MULTIPART"; private static final String MULTIPART_BOUNDARY = "THIS_STRING_SEPARATES_MULTIPART";
private final long start; private final long start;
@@ -397,22 +383,6 @@ public final class FileStreamingUtil {
this.total = total; this.total = total;
} }
private long getStart() {
return start;
}
private long getEnd() {
return end;
}
private long getLength() {
return length;
}
private long getTotal() {
return total;
}
@Override @Override
// Generated code // Generated code
@SuppressWarnings("squid:S864") @SuppressWarnings("squid:S864")
@@ -455,6 +425,22 @@ public final class FileStreamingUtil {
return true; return true;
} }
private long getStart() {
return start;
}
private long getEnd() {
return end;
}
private long getLength() {
return length;
}
private long getTotal() {
return total;
}
} }
} }

View File

@@ -23,11 +23,8 @@ public final class HttpUtil {
/** /**
* Checks given CSV string for defined match value or wildcard. * Checks given CSV string for defined match value or wildcard.
* *
* @param matchHeader * @param matchHeader to search through
* to search through * @param toMatch to search for
* @param toMatch
* to search for
*
* @return <code>true</code> if string matches. * @return <code>true</code> if string matches.
*/ */
public static boolean matchesHttpHeader(final String matchHeader, final String toMatch) { public static boolean matchesHttpHeader(final String matchHeader, final String toMatch) {

View File

@@ -9,6 +9,8 @@
*/ */
package org.eclipse.hawkbit.rest.util; package org.eclipse.hawkbit.rest.util;
import java.util.Objects;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
@@ -16,8 +18,6 @@ import lombok.NoArgsConstructor;
import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.context.request.ServletRequestAttributes;
import java.util.Objects;
/** /**
* Gives access to the request and response for the rest resources. * Gives access to the request and response for the rest resources.
*/ */

View File

@@ -23,9 +23,6 @@ import org.springframework.data.domain.Sort.Order;
/** /**
* A utility class for parsing query parameters which define the sorting of * A utility class for parsing query parameters which define the sorting of
* elements. * elements.
*
*
*
*/ */
public final class SortUtility { public final class SortUtility {
@@ -48,24 +45,18 @@ public final class SortUtility {
* will be split into the keys of the returned map. The direction of the * will be split into the keys of the returned map. The direction of the
* sorting will be mapped into the {@link Direction} enum. * sorting will be mapped into the {@link Direction} enum.
* *
* @param enumType * @param enumType the class of the enum which the fields in the sort string
* the class of the enum which the fields in the sort string
* should be related to. * should be related to.
* @param <T> * @param <T> the type of the enumeration which must be derived from
* the type of the enumeration which must be derived from
* {@link RsqlQueryField} * {@link RsqlQueryField}
* @param sortString * @param sortString the string representation of the query parameters. Might be
* the string representation of the query parameters. Might be
* {@code null} or an empty string. * {@code null} or an empty string.
* @return a list which holds the {@link RsqlQueryField} and the specific * @return a list which holds the {@link RsqlQueryField} and the specific
* {@link Direction} for them as a tuple. Never {@code null}. In * {@link Direction} for them as a tuple. Never {@code null}. In
* case of no sorting parameters an empty map will be returned. * case of no sorting parameters an empty map will be returned.
* @throws SortParameterSyntaxErrorException * @throws SortParameterSyntaxErrorException if the sorting query parameter is not well-formed
* if the sorting query parameter is not well-formed * @throws SortParameterUnsupportedFieldException if a field name cannot be mapped to the enum type
* @throws SortParameterUnsupportedFieldException * @throws SortParameterUnsupportedDirectionException if the given direction is not "ASC" or "DESC"
* if a field name cannot be mapped to the enum type
* @throws SortParameterUnsupportedDirectionException
* if the given direction is not "ASC" or "DESC"
*/ */
public static <T extends Enum<T> & RsqlQueryField> List<Order> parse(final Class<T> enumType, public static <T extends Enum<T> & RsqlQueryField> List<Order> parse(final Class<T> enumType,
final String sortString) throws SortParameterSyntaxErrorException { final String sortString) throws SortParameterSyntaxErrorException {
@@ -96,17 +87,13 @@ public final class SortUtility {
/** /**
* Returns the attribute identifier for the given name. * Returns the attribute identifier for the given name.
* *
* @param enumType * @param enumType the class of the enum which the fields in the sort string
* the class of the enum which the fields in the sort string
* should be related to. * should be related to.
* @param name * @param name the name of the enum
* the name of the enum * @param <T> the type of the enumeration which must be derived from
* @param <T>
* the type of the enumeration which must be derived from
* {@link RsqlQueryField} * {@link RsqlQueryField}
* @return the corresponding enum * @return the corresponding enum
* @throws SortParameterUnsupportedFieldException * @throws SortParameterUnsupportedFieldException if there is no matching enum for the specified name
* if there is no matching enum for the specified name
*/ */
private static <T extends Enum<T> & RsqlQueryField> T getAttributeIdentifierByName(final Class<T> enumType, private static <T extends Enum<T> & RsqlQueryField> T getAttributeIdentifierByName(final Class<T> enumType,
final String name) { final String name) {

View File

@@ -32,19 +32,17 @@ import org.springframework.web.filter.CharacterEncodingFilter;
*/ */
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK)
@ContextConfiguration(classes = { @ContextConfiguration(classes = {
RestConfiguration.class, RepositoryApplicationConfiguration.class, TestConfiguration.class}) RestConfiguration.class, RepositoryApplicationConfiguration.class, TestConfiguration.class })
@Import(TestChannelBinderConfiguration.class) @Import(TestChannelBinderConfiguration.class)
@WebAppConfiguration @WebAppConfiguration
@AutoConfigureMockMvc @AutoConfigureMockMvc
public abstract class AbstractRestIntegrationTest extends AbstractIntegrationTest { public abstract class AbstractRestIntegrationTest extends AbstractIntegrationTest {
protected MockMvc mvc; protected MockMvc mvc;
@Autowired
private CharacterEncodingFilter characterEncodingFilter;
@Autowired @Autowired
protected WebApplicationContext webApplicationContext; protected WebApplicationContext webApplicationContext;
@Autowired
private CharacterEncodingFilter characterEncodingFilter;
@BeforeEach @BeforeEach
public void before() throws Exception { public void before() throws Exception {

View File

@@ -22,6 +22,8 @@ import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
@@ -29,9 +31,6 @@ import org.mockito.Mock;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
@Feature("Unit Tests - Security") @Feature("Unit Tests - Security")
@Story("Exclude path aware shallow ETag filter") @Story("Exclude path aware shallow ETag filter")
@ExtendWith(MockitoExtension.class) @ExtendWith(MockitoExtension.class)

View File

@@ -14,11 +14,10 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.junit.jupiter.api.Test;
import io.qameta.allure.Description; import io.qameta.allure.Description;
import io.qameta.allure.Feature; import io.qameta.allure.Feature;
import io.qameta.allure.Story; import io.qameta.allure.Story;
import org.junit.jupiter.api.Test;
@Feature("Unit Tests - Management API") @Feature("Unit Tests - Management API")
@Story("Error Handling") @Story("Error Handling")

View File

@@ -25,6 +25,8 @@ import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
import org.eclipse.hawkbit.artifact.repository.model.DbArtifact; import org.eclipse.hawkbit.artifact.repository.model.DbArtifact;
import org.eclipse.hawkbit.artifact.repository.model.DbArtifactHash; import org.eclipse.hawkbit.artifact.repository.model.DbArtifactHash;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@@ -34,12 +36,10 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
@Feature("Component Tests - Management API") @Feature("Component Tests - Management API")
@Story("File streaming") @Story("File streaming")
class FileStreamingUtilTest { class FileStreamingUtilTest {
private final static String CONTENT = "This is some very long string which is intended to test"; private final static String CONTENT = "This is some very long string which is intended to test";
private final static byte[] CONTENT_BYTES = CONTENT.getBytes(StandardCharsets.UTF_8); private final static byte[] CONTENT_BYTES = CONTENT.getBytes(StandardCharsets.UTF_8);

View File

@@ -9,6 +9,8 @@
*/ */
package org.eclipse.hawkbit.rest.util; package org.eclipse.hawkbit.rest.util;
import static org.junit.jupiter.api.Assertions.fail;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -30,8 +32,6 @@ import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import static org.junit.jupiter.api.Assertions.fail;
/** /**
* Builder class for building certain json strings. * Builder class for building certain json strings.
*/ */
@@ -73,12 +73,6 @@ public abstract class JsonBuilder {
} }
private static void createTagLine(final StringBuilder builder, final Tag tag) throws JSONException {
builder.append(new JSONObject().put("name", tag.getName()).put("description", tag.getDescription())
.put("colour", tag.getColour()).put("createdAt", "0").put("updatedAt", "0")
.put("createdBy", "fghdfkjghdfkjh").put("updatedBy", "fghdfkjghdfkjh").toString());
}
public static String tag(final Tag tag) throws JSONException { public static String tag(final Tag tag) throws JSONException {
final StringBuilder builder = new StringBuilder(); final StringBuilder builder = new StringBuilder();
@@ -189,12 +183,9 @@ public abstract class JsonBuilder {
/** /**
* Build an invalid request body with missing result for feedback message. * Build an invalid request body with missing result for feedback message.
* *
* @param id * @param id id of the action
* id of the action * @param execution the execution
* @param execution * @param message the message
* the execution
* @param message
* the message
* @return a invalid request body * @return a invalid request body
* @throws JSONException * @throws JSONException
*/ */
@@ -210,12 +201,9 @@ public abstract class JsonBuilder {
* Build an invalid request body with missing finished result for feedback * Build an invalid request body with missing finished result for feedback
* message. * message.
* *
* @param id * @param id id of the action
* id of the action * @param execution the execution
* @param execution * @param message the message
* the execution
* @param message
* the message
* @return a invalid request body * @return a invalid request body
* @throws JSONException * @throws JSONException
*/ */
@@ -576,7 +564,8 @@ public abstract class JsonBuilder {
final JSONObject dynamicGroupTemplate = new JSONObject(); final JSONObject dynamicGroupTemplate = new JSONObject();
json.put("dynamicGroupTemplate", dynamicGroupTemplate); json.put("dynamicGroupTemplate", dynamicGroupTemplate);
dynamicGroupTemplate.put("nameSuffix", (dynamicGroupSuffix == null || dynamicGroupSuffix.isEmpty()) ? "-dynamic" : dynamicGroupSuffix); dynamicGroupTemplate.put("nameSuffix",
(dynamicGroupSuffix == null || dynamicGroupSuffix.isEmpty()) ? "-dynamic" : dynamicGroupSuffix);
dynamicGroupTemplate.put("targetCount", dynamicGroupTargetsCount < 0 ? 1 : dynamicGroupTargetsCount); dynamicGroupTemplate.put("targetCount", dynamicGroupTargetsCount < 0 ? 1 : dynamicGroupTargetsCount);
} }
@@ -602,14 +591,6 @@ public abstract class JsonBuilder {
} }
private static RolloutGroupConditions getConditions(final RolloutGroup rolloutGroup) {
return new RolloutGroupConditionBuilder()
.errorCondition(rolloutGroup.getErrorCondition(), rolloutGroup.getErrorConditionExp())
.errorAction(rolloutGroup.getErrorAction(), rolloutGroup.getErrorActionExp())
.successAction(rolloutGroup.getSuccessAction(), rolloutGroup.getSuccessActionExp())
.successCondition(rolloutGroup.getSuccessCondition(), rolloutGroup.getSuccessConditionExp()).build();
}
public static String rolloutGroup(final String name, final String description, final String targetFilterQuery, public static String rolloutGroup(final String name, final String description, final String targetFilterQuery,
final Float targetPercentage, final Boolean confirmationRequired, final Float targetPercentage, final Boolean confirmationRequired,
final RolloutGroupConditions rolloutGroupConditions) { final RolloutGroupConditions rolloutGroupConditions) {
@@ -705,4 +686,18 @@ public abstract class JsonBuilder {
} }
return json; return json;
} }
private static void createTagLine(final StringBuilder builder, final Tag tag) throws JSONException {
builder.append(new JSONObject().put("name", tag.getName()).put("description", tag.getDescription())
.put("colour", tag.getColour()).put("createdAt", "0").put("updatedAt", "0")
.put("createdBy", "fghdfkjghdfkjh").put("updatedBy", "fghdfkjghdfkjh").toString());
}
private static RolloutGroupConditions getConditions(final RolloutGroup rolloutGroup) {
return new RolloutGroupConditionBuilder()
.errorCondition(rolloutGroup.getErrorCondition(), rolloutGroup.getErrorConditionExp())
.errorAction(rolloutGroup.getErrorAction(), rolloutGroup.getErrorActionExp())
.successAction(rolloutGroup.getSuccessAction(), rolloutGroup.getSuccessActionExp())
.successCondition(rolloutGroup.getSuccessCondition(), rolloutGroup.getSuccessConditionExp()).build();
}
} }

View File

@@ -14,6 +14,9 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.List; import java.util.List;
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
import org.eclipse.hawkbit.repository.TargetFields; import org.eclipse.hawkbit.repository.TargetFields;
import org.eclipse.hawkbit.rest.exception.SortParameterSyntaxErrorException; import org.eclipse.hawkbit.rest.exception.SortParameterSyntaxErrorException;
import org.eclipse.hawkbit.rest.exception.SortParameterUnsupportedDirectionException; import org.eclipse.hawkbit.rest.exception.SortParameterUnsupportedDirectionException;
@@ -21,16 +24,13 @@ import org.eclipse.hawkbit.rest.exception.SortParameterUnsupportedFieldException
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.data.domain.Sort.Order; import org.springframework.data.domain.Sort.Order;
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
/** /**
* *
*/ */
@Feature("Component Tests - Management API") @Feature("Component Tests - Management API")
@Story("Sorting parameter") @Story("Sorting parameter")
public class SortUtilityTest { public class SortUtilityTest {
private static final String SORT_PARAM_1 = "NAME:ASC"; private static final String SORT_PARAM_1 = "NAME:ASC";
private static final String SORT_PARAM_2 = "NAME:ASC, DESCRIPTION:DESC"; private static final String SORT_PARAM_2 = "NAME:ASC, DESCRIPTION:DESC";
private static final String SYNTAX_FAILURE_SORT_PARAM = "NAME:ASC DESCRIPTION:DESC"; private static final String SYNTAX_FAILURE_SORT_PARAM = "NAME:ASC DESCRIPTION:DESC";

View File

@@ -10,13 +10,11 @@
package org.eclipse.hawkbit.rest.util; package org.eclipse.hawkbit.rest.util;
/** /**
*
* @param <T> * @param <T>
*/ */
public interface SuccessCondition<T> { public interface SuccessCondition<T> {
/** /**
*
* @param result * @param result
* @return * @return
*/ */