Sonar Fixes (5) (#2211)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -14,7 +14,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.util.Collections;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
@@ -68,7 +67,7 @@ class DdiActionFeedbackTest {
|
||||
|
||||
@Test
|
||||
@Description("Verify that deserialization fails for known properties with a wrong datatype")
|
||||
void shouldFailForObjectWithWrongDataTypes() throws IOException {
|
||||
void shouldFailForObjectWithWrongDataTypes() {
|
||||
// Setup
|
||||
final String serializedDdiActionFeedback = """
|
||||
{
|
||||
|
||||
@@ -29,13 +29,13 @@ import org.junit.jupiter.api.Test;
|
||||
*/
|
||||
@Feature("Unit Tests - Direct Device Integration API")
|
||||
@Story("Serializability of DDI api Models")
|
||||
public class DdiActionHistoryTest {
|
||||
class DdiActionHistoryTest {
|
||||
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct serialization and deserialization of the model")
|
||||
public void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
// Setup
|
||||
final String actionStatus = "TestAction";
|
||||
final List<String> messages = Arrays.asList("Action status message 1", "Action status message 2");
|
||||
@@ -50,7 +50,7 @@ public class DdiActionHistoryTest {
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct deserialization of a model with a additional unknown property")
|
||||
public void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
// Setup
|
||||
final String serializedDdiActionHistory = """
|
||||
{
|
||||
@@ -66,7 +66,7 @@ public class DdiActionHistoryTest {
|
||||
|
||||
@Test
|
||||
@Description("Verify that deserialization fails for known properties with a wrong datatype")
|
||||
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
|
||||
void shouldFailForObjectWithWrongDataTypes() {
|
||||
// Setup
|
||||
final String serializedDdiActionFeedback = """
|
||||
{
|
||||
|
||||
@@ -27,13 +27,13 @@ import org.junit.jupiter.api.Test;
|
||||
*/
|
||||
@Feature("Unit Tests - Direct Device Integration API")
|
||||
@Story("Serializability of DDI api Models")
|
||||
public class DdiArtifactHashTest {
|
||||
class DdiArtifactHashTest {
|
||||
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct serialization and deserialization of the model")
|
||||
public void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
// Setup
|
||||
final String sha1Hash = "11111";
|
||||
final String md5Hash = "22222";
|
||||
@@ -51,7 +51,7 @@ public class DdiArtifactHashTest {
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct deserialization of a model with a additional unknown property")
|
||||
public void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
// Setup
|
||||
final String serializedDdiArtifact = "{\"sha1\": \"123\", \"md5\": \"456\", \"sha256\": \"789\", \"unknownProperty\": \"test\"}";
|
||||
|
||||
@@ -64,7 +64,7 @@ public class DdiArtifactHashTest {
|
||||
|
||||
@Test
|
||||
@Description("Verify that deserialization fails for known properties with a wrong datatype")
|
||||
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
|
||||
void shouldFailForObjectWithWrongDataTypes() {
|
||||
// Setup
|
||||
final String serializedDdiArtifact = "{\"sha1\": [123], \"md5\": 456, \"sha256\": \"789\"";
|
||||
|
||||
|
||||
@@ -27,13 +27,13 @@ import org.junit.jupiter.api.Test;
|
||||
*/
|
||||
@Feature("Unit Tests - Direct Device Integration API")
|
||||
@Story("Serializability of DDI api Models")
|
||||
public class DdiArtifactTest {
|
||||
class DdiArtifactTest {
|
||||
|
||||
private final static ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct serialization and deserialization of the model")
|
||||
public void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
// Setup
|
||||
final String filename = "testfile.txt";
|
||||
final DdiArtifactHash hashes = new DdiArtifactHash("123", "456", "789");
|
||||
@@ -57,7 +57,7 @@ public class DdiArtifactTest {
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct deserialization of a model with a additional unknown property")
|
||||
public void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
// Setup
|
||||
final String serializedDdiArtifact = "{\"filename\":\"test.file\",\"hashes\":{\"sha1\":\"123\",\"md5\":\"456\",\"sha256\":\"789\"},\"size\":111,\"links\":[],\"unknownProperty\": \"test\"}";
|
||||
|
||||
@@ -72,7 +72,7 @@ public class DdiArtifactTest {
|
||||
|
||||
@Test
|
||||
@Description("Verify that deserialization fails for known properties with a wrong datatype")
|
||||
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
|
||||
void shouldFailForObjectWithWrongDataTypes() {
|
||||
// Setup
|
||||
final String serializedDdiArtifact = "{\"filename\": [\"test.file\"],\"hashes\":{\"sha1\":\"123\",\"md5\":\"456\",\"sha256\":\"789\"},\"size\":111,\"links\":[]}";
|
||||
|
||||
|
||||
@@ -27,13 +27,13 @@ import org.junit.jupiter.api.Test;
|
||||
*/
|
||||
@Feature("Unit Tests - Direct Device Integration API")
|
||||
@Story("Serializability of DDI api Models")
|
||||
public class DdiCancelActionToStopTest {
|
||||
class DdiCancelActionToStopTest {
|
||||
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct serialization and deserialization of the model")
|
||||
public void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
// Setup
|
||||
final String stopId = "1234";
|
||||
final DdiCancelActionToStop ddiCancelActionToStop = new DdiCancelActionToStop(stopId);
|
||||
@@ -48,7 +48,7 @@ public class DdiCancelActionToStopTest {
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct deserialization of a model with a additional unknown property")
|
||||
public void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
// Setup
|
||||
final String serializedDdiCancelActionToStop = "{\"stopId\":\"12345\",\"unknownProperty\":\"test\"}";
|
||||
|
||||
@@ -60,7 +60,7 @@ public class DdiCancelActionToStopTest {
|
||||
|
||||
@Test
|
||||
@Description("Verify that deserialization fails for known properties with a wrong datatype")
|
||||
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
|
||||
void shouldFailForObjectWithWrongDataTypes() {
|
||||
// Setup
|
||||
final String serializedDdiCancelActionToStop = "{\"stopId\": [\"12345\"]}";
|
||||
|
||||
|
||||
@@ -27,13 +27,13 @@ import org.junit.jupiter.api.Test;
|
||||
*/
|
||||
@Feature("Unit Tests - Direct Device Integration API")
|
||||
@Story("Serializability of DDI api Models")
|
||||
public class DdiCancelTest {
|
||||
class DdiCancelTest {
|
||||
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct serialization and deserialization of the model")
|
||||
public void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
// Setup
|
||||
final String ddiCancelId = "1234";
|
||||
final DdiCancelActionToStop ddiCancelActionToStop = new DdiCancelActionToStop("1234");
|
||||
@@ -49,7 +49,7 @@ public class DdiCancelTest {
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct deserialization of a model with a additional unknown property")
|
||||
public void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
// Setup
|
||||
final String serializedDdiCancel = "{\"id\":\"1234\",\"cancelAction\":{\"stopId\":\"1234\"}, \"unknownProperty\": \"test\"}";
|
||||
|
||||
@@ -61,7 +61,7 @@ public class DdiCancelTest {
|
||||
|
||||
@Test
|
||||
@Description("Verify that deserialization fails for known properties with a wrong datatype")
|
||||
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
|
||||
void shouldFailForObjectWithWrongDataTypes() {
|
||||
// Setup
|
||||
final String serializedDdiCancel = "{\"id\":[\"1234\"],\"cancelAction\":{\"stopId\":\"1234\"}}";
|
||||
|
||||
|
||||
@@ -29,13 +29,13 @@ import org.junit.jupiter.api.Test;
|
||||
*/
|
||||
@Feature("Unit Tests - Direct Device Integration API")
|
||||
@Story("Serializability of DDI api Models")
|
||||
public class DdiChunkTest {
|
||||
class DdiChunkTest {
|
||||
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct serialization and deserialization of the model")
|
||||
public void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
// Setup
|
||||
final String part = "1234";
|
||||
final String version = "1.0";
|
||||
@@ -50,12 +50,12 @@ public class DdiChunkTest {
|
||||
assertThat(deserializedDdiChunk.getPart()).isEqualTo(part);
|
||||
assertThat(deserializedDdiChunk.getVersion()).isEqualTo(version);
|
||||
assertThat(deserializedDdiChunk.getName()).isEqualTo(name);
|
||||
assertThat(deserializedDdiChunk.getArtifacts().size()).isEqualTo(0);
|
||||
assertThat(deserializedDdiChunk.getArtifacts()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct deserialization of a model with a additional unknown property")
|
||||
public void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
// Setup
|
||||
final String serializedDdiChunk = "{\"part\":\"1234\",\"version\":\"1.0\",\"name\":\"Dummy-Artifact\",\"artifacts\":[],\"unknownProperty\":\"test\"}";
|
||||
|
||||
@@ -64,12 +64,12 @@ public class DdiChunkTest {
|
||||
assertThat(ddiChunk.getPart()).isEqualTo("1234");
|
||||
assertThat(ddiChunk.getVersion()).isEqualTo("1.0");
|
||||
assertThat(ddiChunk.getName()).isEqualTo("Dummy-Artifact");
|
||||
assertThat(ddiChunk.getArtifacts().size()).isEqualTo(0);
|
||||
assertThat(ddiChunk.getArtifacts()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verify that deserialization fails for known properties with a wrong datatype")
|
||||
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
|
||||
void shouldFailForObjectWithWrongDataTypes() {
|
||||
// Setup
|
||||
final String serializedDdiChunk = "{\"part\":[\"1234\"],\"version\":\"1.0\",\"name\":\"Dummy-Artifact\",\"artifacts\":[]}";
|
||||
|
||||
|
||||
@@ -29,13 +29,13 @@ import org.junit.jupiter.api.Test;
|
||||
*/
|
||||
@Feature("Unit Tests - Direct Device Integration API")
|
||||
@Story("Serializability of DDI api Models")
|
||||
public class DdiConfigDataTest {
|
||||
class DdiConfigDataTest {
|
||||
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct serialization and deserialization of the model")
|
||||
public void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
// Setup
|
||||
final Map<String, String> data = new HashMap<>();
|
||||
data.put("test", "data");
|
||||
@@ -50,7 +50,7 @@ public class DdiConfigDataTest {
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct deserialization of a model with an additional unknown property")
|
||||
public void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
// Setup
|
||||
final String serializedDdiConfigData = "{\"data\":{\"test\":\"data\"},\"mode\":\"replace\",\"unknownProperty\":\"test\"}";
|
||||
|
||||
@@ -61,7 +61,7 @@ public class DdiConfigDataTest {
|
||||
|
||||
@Test
|
||||
@Description("Verify that deserialization fails for known properties with a wrong datatype")
|
||||
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
|
||||
void shouldFailForObjectWithWrongDataTypes() {
|
||||
// Setup
|
||||
final String serializedDdiConfigData = "{\"data\":{\"test\":\"data\"},\"mode\":[\"replace\"],\"unknownProperty\":\"test\"}";
|
||||
|
||||
@@ -72,7 +72,7 @@ public class DdiConfigDataTest {
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct deserialization of a model with removed unused status property")
|
||||
public void shouldDeserializeObjectWithStatusProperty() throws IOException {
|
||||
void shouldDeserializeObjectWithStatusProperty() throws IOException {
|
||||
// We formerly falsely required a 'status' property object when using the
|
||||
// configData endpoint. It was removed as a requirement from code and
|
||||
// documentation, as it was unused. This test ensures we still behave correctly
|
||||
|
||||
@@ -27,13 +27,13 @@ import org.junit.jupiter.api.Test;
|
||||
*/
|
||||
@Feature("Unit Tests - Direct Device Integration API")
|
||||
@Story("Serializability of DDI api Models")
|
||||
public class DdiConfigTest {
|
||||
class DdiConfigTest {
|
||||
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct serialization and deserialization of the model")
|
||||
public void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
// Setup
|
||||
final DdiPolling ddiPolling = new DdiPolling("10");
|
||||
final DdiConfig ddiConfig = new DdiConfig(ddiPolling);
|
||||
@@ -47,7 +47,7 @@ public class DdiConfigTest {
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct deserialization of a model with a additional unknown property")
|
||||
public void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
// Setup
|
||||
final String serializedDdiConfig = "{\"polling\":{\"sleep\":\"123\"},\"unknownProperty\":\"test\"}";
|
||||
|
||||
@@ -58,7 +58,7 @@ public class DdiConfigTest {
|
||||
|
||||
@Test
|
||||
@Description("Verify that deserialization fails for known properties with a wrong datatype")
|
||||
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
|
||||
void shouldFailForObjectWithWrongDataTypes() {
|
||||
// Setup
|
||||
final String serializedDdiConfig = "{\"polling\":{\"sleep\":[\"10\"]}}";
|
||||
|
||||
|
||||
@@ -59,8 +59,8 @@ class DdiConfirmationBaseTest {
|
||||
assertThat(deserializedDdiConfigurationBase.getConfirmation().getUpdate()).isEqualTo(ddiDeployment.getUpdate());
|
||||
assertThat(deserializedDdiConfigurationBase.getConfirmation().getMaintenanceWindow())
|
||||
.isEqualTo(ddiDeployment.getMaintenanceWindow());
|
||||
assertThat(deserializedDdiConfigurationBase.getActionHistory().toString())
|
||||
.isEqualTo(ddiActionHistory.toString());
|
||||
assertThat(deserializedDdiConfigurationBase.getActionHistory())
|
||||
.hasToString(ddiActionHistory.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -86,7 +86,7 @@ class DdiConfirmationBaseTest {
|
||||
|
||||
@Test
|
||||
@Description("Verify that deserialization fails for known properties with a wrong datatype")
|
||||
void shouldFailForObjectWithWrongDataTypes() throws IOException {
|
||||
void shouldFailForObjectWithWrongDataTypes() {
|
||||
// Setup
|
||||
final String serializedDdiConfirmationBase = "{" +
|
||||
"\"id\":[\"1234\"],\"confirmation\":{\"download\":\"forced\"," +
|
||||
|
||||
@@ -27,13 +27,13 @@ import org.junit.jupiter.api.Test;
|
||||
*/
|
||||
@Feature("Unit Tests - Direct Device Integration API")
|
||||
@Story("Serializability of DDI api Models")
|
||||
public class DdiControllerBaseTest {
|
||||
class DdiControllerBaseTest {
|
||||
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct serialization and deserialization of the model")
|
||||
public void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
// Setup
|
||||
final DdiPolling ddiPolling = new DdiPolling("10");
|
||||
final DdiConfig ddiConfig = new DdiConfig(ddiPolling);
|
||||
@@ -48,7 +48,7 @@ public class DdiControllerBaseTest {
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct deserialization of a model with a additional unknown property")
|
||||
public void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
// Setup
|
||||
final String serializedDdiControllerBase = "{\"config\":{\"polling\":{\"sleep\":\"123\"}},\"links\":[],\"unknownProperty\":\"test\"}";
|
||||
|
||||
@@ -59,7 +59,7 @@ public class DdiControllerBaseTest {
|
||||
|
||||
@Test
|
||||
@Description("Verify that deserialization fails for known properties with a wrong datatype")
|
||||
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
|
||||
void shouldFailForObjectWithWrongDataTypes() {
|
||||
// Setup
|
||||
final String serializedDdiControllerBase = "{\"config\":{\"polling\":{\"sleep\":[\"123\"]}},\"links\":[],\"unknownProperty\":\"test\"}";
|
||||
|
||||
|
||||
@@ -32,13 +32,13 @@ import org.junit.jupiter.api.Test;
|
||||
*/
|
||||
@Feature("Unit Tests - Direct Device Integration API")
|
||||
@Story("Serializability of DDI api Models")
|
||||
public class DdiDeploymentBaseTest {
|
||||
class DdiDeploymentBaseTest {
|
||||
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct serialization and deserialization of the model")
|
||||
public void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
// Setup
|
||||
final String id = "1234";
|
||||
final DdiDeployment ddiDeployment = new DdiDeployment(FORCED, ATTEMPT, Collections.emptyList(), AVAILABLE);
|
||||
@@ -54,12 +54,12 @@ public class DdiDeploymentBaseTest {
|
||||
assertThat(deserializedDdiDeploymentBase.getDeployment().getDownload()).isEqualTo(ddiDeployment.getDownload());
|
||||
assertThat(deserializedDdiDeploymentBase.getDeployment().getUpdate()).isEqualTo(ddiDeployment.getUpdate());
|
||||
assertThat(deserializedDdiDeploymentBase.getDeployment().getMaintenanceWindow()).isEqualTo(ddiDeployment.getMaintenanceWindow());
|
||||
assertThat(deserializedDdiDeploymentBase.getActionHistory().toString()).isEqualTo(ddiActionHistory.toString());
|
||||
assertThat(deserializedDdiDeploymentBase.getActionHistory()).hasToString(ddiActionHistory.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct deserialization of a model with a additional unknown property")
|
||||
public void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
// Setup
|
||||
final String serializedDdiDeploymentBase = "{\"id\":\"1234\",\"deployment\":{\"download\":\"forced\"," +
|
||||
"\"update\":\"attempt\",\"maintenanceWindow\":\"available\",\"chunks\":[]}," +
|
||||
@@ -75,7 +75,7 @@ public class DdiDeploymentBaseTest {
|
||||
|
||||
@Test
|
||||
@Description("Verify that deserialization fails for known properties with a wrong datatype")
|
||||
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
|
||||
void shouldFailForObjectWithWrongDataTypes() {
|
||||
// Setup
|
||||
final String serializedDdiDeploymentBase = "{\"id\":[\"1234\"],\"deployment\":{\"download\":\"forced\"," +
|
||||
"\"update\":\"attempt\",\"maintenanceWindow\":\"available\",\"chunks\":[]}," +
|
||||
|
||||
@@ -31,13 +31,13 @@ import org.junit.jupiter.api.Test;
|
||||
*/
|
||||
@Feature("Unit Tests - Direct Device Integration API")
|
||||
@Story("Serializability of DDI api Models")
|
||||
public class DdiDeploymentTest {
|
||||
class DdiDeploymentTest {
|
||||
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct serialization and deserialization of the model")
|
||||
public void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
// Setup
|
||||
final DdiDeployment ddiDeployment = new DdiDeployment(FORCED, ATTEMPT, Collections.emptyList(), AVAILABLE);
|
||||
|
||||
@@ -53,7 +53,7 @@ public class DdiDeploymentTest {
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct deserialization of a model with a additional unknown property")
|
||||
public void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
// Setup
|
||||
final String serializedDdiDeployment = "{\"download\":\"forced\",\"update\":\"attempt\", " +
|
||||
"\"maintenanceWindow\":\"available\",\"chunks\":[],\"unknownProperty\":\"test\"}";
|
||||
@@ -67,7 +67,7 @@ public class DdiDeploymentTest {
|
||||
|
||||
@Test
|
||||
@Description("Verify that deserialization fails for known properties with a wrong datatype")
|
||||
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
|
||||
void shouldFailForObjectWithWrongDataTypes() {
|
||||
// Setup
|
||||
final String serializedDdiDeployment = "{\"download\":[\"forced\"],\"update\":\"attempt\", " +
|
||||
"\"maintenanceWindow\":\"available\",\"chunks\":[]}";
|
||||
|
||||
@@ -27,13 +27,13 @@ import org.junit.jupiter.api.Test;
|
||||
*/
|
||||
@Feature("Unit Tests - Direct Device Integration API")
|
||||
@Story("Serializability of DDI api Models")
|
||||
public class DdiMetadataTest {
|
||||
class DdiMetadataTest {
|
||||
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct serialization and deserialization of the model")
|
||||
public void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
// Setup
|
||||
final String key = "testKey";
|
||||
final String value = "testValue";
|
||||
@@ -49,7 +49,7 @@ public class DdiMetadataTest {
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct deserialization of a model with a additional unknown property")
|
||||
public void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
// Setup
|
||||
final String serializedDdiMetadata = "{\"key\":\"testKey\",\"value\":\"testValue\",\"unknownProperty\":\"test\"}";
|
||||
|
||||
@@ -61,7 +61,7 @@ public class DdiMetadataTest {
|
||||
|
||||
@Test
|
||||
@Description("Verify that deserialization fails for known properties with a wrong datatype")
|
||||
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
|
||||
void shouldFailForObjectWithWrongDataTypes() {
|
||||
// Setup
|
||||
final String serializedDdiMetadata = "{\"key\":[\"testKey\"],\"value\":\"testValue\"}";
|
||||
|
||||
|
||||
@@ -27,13 +27,13 @@ import org.junit.jupiter.api.Test;
|
||||
*/
|
||||
@Feature("Unit Tests - Direct Device Integration API")
|
||||
@Story("Serializability of DDI api Models")
|
||||
public class DdiPollingTest {
|
||||
class DdiPollingTest {
|
||||
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct serialization and deserialization of the model")
|
||||
public void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
// Setup
|
||||
final DdiPolling ddiPolling = new DdiPolling("10");
|
||||
|
||||
@@ -46,7 +46,7 @@ public class DdiPollingTest {
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct deserialization of a model with a additional unknown property")
|
||||
public void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
// Setup
|
||||
final String serializedDdiPolling = "{\"sleep\":\"10\",\"unknownProperty\":\"test\"}";
|
||||
|
||||
@@ -57,7 +57,7 @@ public class DdiPollingTest {
|
||||
|
||||
@Test
|
||||
@Description("Verify that deserialization fails for known properties with a wrong datatype")
|
||||
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
|
||||
void shouldFailForObjectWithWrongDataTypes() {
|
||||
// Setup
|
||||
final String serializedDdiPolling = "{\"sleep\":[\"10\"]}";
|
||||
|
||||
|
||||
@@ -27,13 +27,13 @@ import org.junit.jupiter.api.Test;
|
||||
*/
|
||||
@Feature("Unit Tests - Direct Device Integration API")
|
||||
@Story("Serializability of DDI api Models")
|
||||
public class DdiProgressTest {
|
||||
class DdiProgressTest {
|
||||
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct serialization and deserialization of the model")
|
||||
public void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
// Setup
|
||||
final DdiProgress ddiProgress = new DdiProgress(30, 100);
|
||||
|
||||
@@ -47,7 +47,7 @@ public class DdiProgressTest {
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct deserialization of a model with a additional unknown property")
|
||||
public void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
// Setup
|
||||
final String serializedDdiProgress = "{\"cnt\":30,\"of\":100,\"unknownProperty\":\"test\"}";
|
||||
|
||||
@@ -59,7 +59,7 @@ public class DdiProgressTest {
|
||||
|
||||
@Test
|
||||
@Description("Verify that deserialization fails for known properties with a wrong datatype")
|
||||
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
|
||||
void shouldFailForObjectWithWrongDataTypes() {
|
||||
// Setup
|
||||
final String serializedDdiProgress = "{\"cnt\":[30],\"of\":100}";
|
||||
|
||||
|
||||
@@ -28,13 +28,13 @@ import org.junit.jupiter.api.Test;
|
||||
*/
|
||||
@Feature("Unit Tests - Direct Device Integration API")
|
||||
@Story("Serializability of DDI api Models")
|
||||
public class DdiResultTest {
|
||||
class DdiResultTest {
|
||||
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct serialization and deserialization of the model")
|
||||
public void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
// Setup
|
||||
final DdiProgress ddiProgress = new DdiProgress(30, 100);
|
||||
final DdiResult ddiResult = new DdiResult(NONE, ddiProgress);
|
||||
@@ -50,7 +50,7 @@ public class DdiResultTest {
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct deserialization of a model with a additional unknown property")
|
||||
public void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
// Setup
|
||||
final String serializedDdiResult = "{\"finished\":\"none\",\"progress\":{\"cnt\":30,\"of\":100},\"unknownProperty\":\"test\"}";
|
||||
|
||||
@@ -63,7 +63,7 @@ public class DdiResultTest {
|
||||
|
||||
@Test
|
||||
@Description("Verify that deserialization fails for known properties with a wrong datatype")
|
||||
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
|
||||
void shouldFailForObjectWithWrongDataTypes() {
|
||||
// Setup
|
||||
final String serializedDdiResult = "{\"finished\":[\"none\"],\"progress\":{\"cnt\":30,\"of\":100}}";
|
||||
|
||||
|
||||
@@ -34,14 +34,14 @@ import org.junit.jupiter.params.provider.MethodSource;
|
||||
*/
|
||||
@Feature("Unit Tests - Direct Device Integration API")
|
||||
@Story("Serializability of DDI api Models")
|
||||
public class DdiStatusTest {
|
||||
class DdiStatusTest {
|
||||
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("ddiStatusPossibilities")
|
||||
@Description("Verify the correct serialization and deserialization of the model")
|
||||
public void shouldSerializeAndDeserializeObject(final DdiResult ddiResult, final DdiStatus ddiStatus) throws IOException {
|
||||
void shouldSerializeAndDeserializeObject(final DdiResult ddiResult, final DdiStatus ddiStatus) throws IOException {
|
||||
// Test
|
||||
final String serializedDdiStatus = OBJECT_MAPPER.writeValueAsString(ddiStatus);
|
||||
final DdiStatus deserializedDdiStatus = OBJECT_MAPPER.readValue(serializedDdiStatus, DdiStatus.class);
|
||||
@@ -56,7 +56,7 @@ public class DdiStatusTest {
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct deserialization of a model with a additional unknown property")
|
||||
public void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
// Setup
|
||||
final String serializedDdiStatus = "{\"execution\":\"proceeding\",\"result\":{\"finished\":\"none\"," +
|
||||
"\"progress\":{\"cnt\":30,\"of\":100}},\"details\":[],\"unknownProperty\":\"test\"}";
|
||||
@@ -72,7 +72,7 @@ public class DdiStatusTest {
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct deserialization of a model with a provided code (optional)")
|
||||
public void shouldDeserializeObjectWithOptionalCode() throws IOException {
|
||||
void shouldDeserializeObjectWithOptionalCode() throws IOException {
|
||||
// Setup
|
||||
final String serializedDdiStatus = "{\"execution\":\"proceeding\",\"result\":{\"finished\":\"none\"," +
|
||||
"\"progress\":{\"cnt\":30,\"of\":100}},\"code\": 12,\"details\":[]}";
|
||||
@@ -88,7 +88,7 @@ public class DdiStatusTest {
|
||||
|
||||
@Test
|
||||
@Description("Verify that deserialization fails for known properties with a wrong datatype")
|
||||
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
|
||||
void shouldFailForObjectWithWrongDataTypes() {
|
||||
// Setup
|
||||
final String serializedDdiStatus = "{\"execution\":[\"proceeding\"],\"result\":{\"finished\":\"none\"," +
|
||||
"\"progress\":{\"cnt\":30,\"of\":100}},\"details\":[]}";
|
||||
|
||||
@@ -136,14 +136,14 @@ public final class DataConversionHelper {
|
||||
final HttpRequest request, final ControllerManagement controllerManagement) {
|
||||
final Map<Long, List<SoftwareModuleMetadata>> metadata = controllerManagement
|
||||
.findTargetVisibleMetaDataBySoftwareModuleId(uAction.getDistributionSet().getModules().stream()
|
||||
.map(SoftwareModule::getId).collect(Collectors.toList()));
|
||||
.map(SoftwareModule::getId).toList());
|
||||
|
||||
return new ResponseList<>(uAction.getDistributionSet().getModules().stream()
|
||||
.map(module -> new DdiChunk(mapChunkLegacyKeys(module.getType().getKey()), module.getVersion(),
|
||||
module.getName(), module.isEncrypted() ? Boolean.TRUE : null,
|
||||
createArtifacts(target, module, artifactUrlHandler, systemManagement, request),
|
||||
mapMetadata(metadata.get(module.getId()))))
|
||||
.collect(Collectors.toList()));
|
||||
.toList());
|
||||
|
||||
}
|
||||
|
||||
@@ -153,13 +153,13 @@ public final class DataConversionHelper {
|
||||
|
||||
return new ResponseList<>(module.getArtifacts().stream()
|
||||
.map(artifact -> createArtifact(target, artifactUrlHandler, artifact, systemManagement, request))
|
||||
.collect(Collectors.toList()));
|
||||
.toList());
|
||||
}
|
||||
|
||||
private static List<DdiMetadata> mapMetadata(final List<SoftwareModuleMetadata> metadata) {
|
||||
return CollectionUtils.isEmpty(metadata)
|
||||
? null
|
||||
: metadata.stream().map(md -> new DdiMetadata(md.getKey(), md.getValue())).collect(Collectors.toList());
|
||||
: metadata.stream().map(md -> new DdiMetadata(md.getKey(), md.getValue())).toList();
|
||||
}
|
||||
|
||||
private static String mapChunkLegacyKeys(final String key) {
|
||||
|
||||
@@ -163,7 +163,7 @@ public class DdiArtifactDownloadTest extends AbstractDDiApiIntegrationTest {
|
||||
public void downloadArtifactThroughFileName() throws Exception {
|
||||
downLoadProgress = 1;
|
||||
shippedBytes = 0;
|
||||
assertThat(softwareModuleManagement.findAll(PAGE)).hasSize(0);
|
||||
assertThat(softwareModuleManagement.findAll(PAGE)).isEmpty();
|
||||
|
||||
// create target
|
||||
final Target target = testdataFactory.createTarget();
|
||||
@@ -251,7 +251,7 @@ public class DdiArtifactDownloadTest extends AbstractDDiApiIntegrationTest {
|
||||
final Artifact artifact = artifactManagement.create(
|
||||
new ArtifactUpload(new ByteArrayInputStream(random), getOsModule(ds), "file1", false, resultLength));
|
||||
|
||||
assertThat(random.length).isEqualTo(resultLength);
|
||||
assertThat(random).hasSize(resultLength);
|
||||
|
||||
// now assign and download successful
|
||||
assignDistributionSet(ds, targets);
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.springframework.amqp.support.converter.MessageConversionException;
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@Feature("Component Tests - Device Management Federation API")
|
||||
@Story("Base Amqp Service Test")
|
||||
public class BaseAmqpServiceTest {
|
||||
class BaseAmqpServiceTest {
|
||||
|
||||
@Mock
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
@@ -43,13 +43,13 @@ public class BaseAmqpServiceTest {
|
||||
private BaseAmqpService baseAmqpService;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
void setup() {
|
||||
baseAmqpService = new BaseAmqpService(rabbitTemplate);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verify that the message conversion works")
|
||||
public void convertMessageTest() {
|
||||
void convertMessageTest() {
|
||||
final DmfActionUpdateStatus actionUpdateStatus = createActionStatus();
|
||||
when(rabbitTemplate.getMessageConverter()).thenReturn(new Jackson2JsonMessageConverter());
|
||||
|
||||
@@ -64,7 +64,7 @@ public class BaseAmqpServiceTest {
|
||||
@Test
|
||||
@Description("Tests invalid null message content")
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
||||
public void convertMessageWithNullContent() {
|
||||
void convertMessageWithNullContent() {
|
||||
final Message message = createMessage("".getBytes());
|
||||
assertThatExceptionOfType(MessageConversionException.class)
|
||||
.as("Expected MessageConversionException for invalid JSON")
|
||||
@@ -74,7 +74,7 @@ public class BaseAmqpServiceTest {
|
||||
@Test
|
||||
@Description("Tests invalid empty message content")
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
||||
public void updateActionStatusWithEmptyContent() {
|
||||
void updateActionStatusWithEmptyContent() {
|
||||
final Message message = createMessage("".getBytes());
|
||||
assertThatExceptionOfType(MessageConversionException.class)
|
||||
.as("Expected MessageConversionException for invalid JSON")
|
||||
@@ -84,7 +84,7 @@ public class BaseAmqpServiceTest {
|
||||
@Test
|
||||
@Description("Tests invalid json message content")
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
||||
public void updateActionStatusWithInvalidJsonContent() {
|
||||
void updateActionStatusWithInvalidJsonContent() {
|
||||
final Message message = createMessage("Invalid Json".getBytes());
|
||||
when(rabbitTemplate.getMessageConverter()).thenReturn(new Jackson2JsonMessageConverter());
|
||||
|
||||
|
||||
@@ -22,11 +22,11 @@ import org.springframework.util.ErrorHandler;
|
||||
|
||||
@Feature("Unit Tests - Delegating Conditional Error Handler")
|
||||
@Story("Delegating Conditional Error Handler")
|
||||
public class DelegatingAmqpErrorHandlerTest {
|
||||
class DelegatingAmqpErrorHandlerTest {
|
||||
|
||||
@Test
|
||||
@Description("Verifies that with a list of conditional error handlers, the error is delegated to specific handler.")
|
||||
public void verifyDelegationHandling() {
|
||||
void verifyDelegationHandling() {
|
||||
List<AmqpErrorHandler> handlers = new ArrayList<>();
|
||||
handlers.add(new IllegalArgumentExceptionHandler());
|
||||
handlers.add(new IndexOutOfBoundsExceptionHandler());
|
||||
@@ -38,7 +38,7 @@ public class DelegatingAmqpErrorHandlerTest {
|
||||
|
||||
@Test
|
||||
@Description("Verifies that default handler is used if no handlers are defined for the specific exception.")
|
||||
public void verifyDefaultDelegationHandling() {
|
||||
void verifyDefaultDelegationHandling() {
|
||||
List<AmqpErrorHandler> handlers = new ArrayList<>();
|
||||
handlers.add(new IllegalArgumentExceptionHandler());
|
||||
handlers.add(new IndexOutOfBoundsExceptionHandler());
|
||||
@@ -49,7 +49,7 @@ public class DelegatingAmqpErrorHandlerTest {
|
||||
}
|
||||
|
||||
// Test class
|
||||
public class IllegalArgumentExceptionHandler implements AmqpErrorHandler {
|
||||
static class IllegalArgumentExceptionHandler implements AmqpErrorHandler {
|
||||
|
||||
@Override
|
||||
public void doHandle(final Throwable t, final AmqpErrorHandlerChain chain) {
|
||||
@@ -62,7 +62,7 @@ public class DelegatingAmqpErrorHandlerTest {
|
||||
}
|
||||
|
||||
// Test class
|
||||
public class IndexOutOfBoundsExceptionHandler implements AmqpErrorHandler {
|
||||
static class IndexOutOfBoundsExceptionHandler implements AmqpErrorHandler {
|
||||
|
||||
@Override
|
||||
public void doHandle(final Throwable t, final AmqpErrorHandlerChain chain) {
|
||||
@@ -75,11 +75,10 @@ public class DelegatingAmqpErrorHandlerTest {
|
||||
}
|
||||
|
||||
// Test class
|
||||
public class DefaultErrorHandler implements ErrorHandler {
|
||||
static class DefaultErrorHandler implements ErrorHandler {
|
||||
|
||||
@Override
|
||||
public void
|
||||
handleError(Throwable t) {
|
||||
public void handleError(final Throwable t) {
|
||||
throw new RuntimeException(t);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -661,8 +661,9 @@ class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpServiceInt
|
||||
|
||||
final Message message = replyToListener.getLatestEventMessage(topic);
|
||||
final Map<String, Object> headers = message.getMessageProperties().getHeaders();
|
||||
assertThat(headers).containsEntry("type", EVENT.toString());
|
||||
assertThat(headers).containsEntry("topic", topic.toString());
|
||||
assertThat(headers)
|
||||
.containsEntry("type", EVENT.toString())
|
||||
.containsEntry("topic", topic.toString());
|
||||
|
||||
final DmfBatchDownloadAndUpdateRequest batchRequest = (DmfBatchDownloadAndUpdateRequest) getDmfClient()
|
||||
.getMessageConverter().fromMessage(message);
|
||||
@@ -711,10 +712,8 @@ class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpServiceInt
|
||||
|
||||
private List<DmfMultiActionElement> getLatestMultiActionMessages(final String expectedControllerId) {
|
||||
final Message multiactionMessage = replyToListener.getLatestEventMessage(EventTopic.MULTI_ACTION);
|
||||
assertThat(multiactionMessage.getMessageProperties().getHeaders().get(MessageHeaderKey.THING_ID))
|
||||
.isEqualTo(expectedControllerId);
|
||||
return ((DmfMultiActionRequest) getDmfClient().getMessageConverter().fromMessage(multiactionMessage))
|
||||
.getElements();
|
||||
assertThat(multiactionMessage.getMessageProperties().getHeaders()).containsEntry(MessageHeaderKey.THING_ID, expectedControllerId);
|
||||
return ((DmfMultiActionRequest) getDmfClient().getMessageConverter().fromMessage(multiactionMessage)).getElements();
|
||||
}
|
||||
|
||||
private void updateActionViaDmfClient(final String controllerId, final long actionId,
|
||||
@@ -762,10 +761,9 @@ class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpServiceInt
|
||||
private void assertLatestMultiActionMessageContainsInstallMessages(final String controllerId,
|
||||
final List<Set<Long>> smIdsOfActionsExpected) {
|
||||
final Message multiactionMessage = replyToListener.getLatestEventMessage(EventTopic.MULTI_ACTION);
|
||||
assertThat(multiactionMessage.getMessageProperties().getHeaders().get(MessageHeaderKey.THING_ID))
|
||||
.isEqualTo(controllerId);
|
||||
final DmfMultiActionRequest multiActionRequest = (DmfMultiActionRequest) getDmfClient().getMessageConverter()
|
||||
.fromMessage(multiactionMessage);
|
||||
assertThat(multiactionMessage.getMessageProperties().getHeaders()).containsEntry(MessageHeaderKey.THING_ID, controllerId);
|
||||
final DmfMultiActionRequest multiActionRequest =
|
||||
(DmfMultiActionRequest) getDmfClient().getMessageConverter().fromMessage(multiactionMessage);
|
||||
|
||||
final List<Set<Long>> smIdsOfActionsFound = getDownloadAndUpdateRequests(multiActionRequest).stream()
|
||||
.map(AmqpMessageDispatcherServiceIntegrationTest::getSmIds).toList();
|
||||
|
||||
@@ -17,12 +17,14 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* JSON representation of confirm request.
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@JsonInclude(Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class DmfConfirmRequest extends DmfActionRequest {
|
||||
|
||||
@@ -17,15 +17,19 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* JSON representation of download and update request.
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@JsonInclude(Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class DmfDownloadAndUpdateRequest extends DmfActionRequest {
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@JsonProperty
|
||||
private String targetSecurityToken;
|
||||
@@ -33,10 +37,6 @@ public class DmfDownloadAndUpdateRequest extends DmfActionRequest {
|
||||
@JsonProperty
|
||||
private List<DmfSoftwareModule> softwareModules;
|
||||
|
||||
public void setTargetSecurityToken(final String targetSecurityToken) {
|
||||
this.targetSecurityToken = targetSecurityToken;
|
||||
}
|
||||
|
||||
public List<DmfSoftwareModule> getSoftwareModules() {
|
||||
if (softwareModules == null) {
|
||||
return Collections.emptyList();
|
||||
@@ -45,17 +45,11 @@ public class DmfDownloadAndUpdateRequest extends DmfActionRequest {
|
||||
return Collections.unmodifiableList(softwareModules);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Software module.
|
||||
*
|
||||
* @param createSoftwareModule the module
|
||||
*/
|
||||
public void addSoftwareModule(final DmfSoftwareModule createSoftwareModule) {
|
||||
if (softwareModules == null) {
|
||||
softwareModules = new ArrayList<>();
|
||||
}
|
||||
|
||||
softwareModules.add(createSoftwareModule);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -36,18 +36,18 @@ import org.springframework.test.web.servlet.ResultActions;
|
||||
HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN })
|
||||
@Feature("Integration Test - Security")
|
||||
@Story("CORS")
|
||||
public class CorsTest extends AbstractSecurityTest {
|
||||
class CorsTest extends AbstractSecurityTest {
|
||||
|
||||
final static String ALLOWED_ORIGIN_FIRST = "http://test.first.origin";
|
||||
final static String ALLOWED_ORIGIN_SECOND = "http://test.second.origin";
|
||||
static final String ALLOWED_ORIGIN_FIRST = "http://test.first.origin";
|
||||
static final String ALLOWED_ORIGIN_SECOND = "http://test.second.origin";
|
||||
|
||||
private final static String INVALID_ORIGIN = "http://test.invalid.origin";
|
||||
private final static String INVALID_CORS_REQUEST = "Invalid CORS request";
|
||||
private static final String INVALID_ORIGIN = "http://test.invalid.origin";
|
||||
private static final String INVALID_CORS_REQUEST = "Invalid CORS request";
|
||||
|
||||
@Test
|
||||
@Description("Ensures that Cors is working.")
|
||||
@WithUser(authorities = SpRole.TENANT_ADMIN, autoCreateTenant = false)
|
||||
public void validateCorsRequest() throws Exception {
|
||||
void validateCorsRequest() throws Exception {
|
||||
performOptionsRequestToRestWithOrigin(ALLOWED_ORIGIN_FIRST).andExpect(status().isOk())
|
||||
.andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, ALLOWED_ORIGIN_FIRST));
|
||||
performOptionsRequestToRestWithOrigin(ALLOWED_ORIGIN_SECOND).andExpect(status().isOk())
|
||||
|
||||
@@ -36,18 +36,18 @@ import org.springframework.test.web.servlet.ResultActions;
|
||||
HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN })
|
||||
@Feature("Integration Test - Security")
|
||||
@Story("CORS")
|
||||
public class CorsTest extends AbstractSecurityTest {
|
||||
class CorsTest extends AbstractSecurityTest {
|
||||
|
||||
final static String ALLOWED_ORIGIN_FIRST = "http://test.first.origin";
|
||||
final static String ALLOWED_ORIGIN_SECOND = "http://test.second.origin";
|
||||
static final String ALLOWED_ORIGIN_FIRST = "http://test.first.origin";
|
||||
static final String ALLOWED_ORIGIN_SECOND = "http://test.second.origin";
|
||||
|
||||
private final static String INVALID_ORIGIN = "http://test.invalid.origin";
|
||||
private final static String INVALID_CORS_REQUEST = "Invalid CORS request";
|
||||
private static final String INVALID_ORIGIN = "http://test.invalid.origin";
|
||||
private static final String INVALID_CORS_REQUEST = "Invalid CORS request";
|
||||
|
||||
@Test
|
||||
@Description("Ensures that Cors is working.")
|
||||
@WithUser(authorities = SpRole.TENANT_ADMIN, autoCreateTenant = false)
|
||||
public void validateCorsRequest() throws Exception {
|
||||
void validateCorsRequest() throws Exception {
|
||||
performOptionsRequestToRestWithOrigin(ALLOWED_ORIGIN_FIRST).andExpect(status().isOk())
|
||||
.andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, ALLOWED_ORIGIN_FIRST));
|
||||
performOptionsRequestToRestWithOrigin(ALLOWED_ORIGIN_SECOND).andExpect(status().isOk())
|
||||
|
||||
@@ -11,6 +11,7 @@ package org.eclipse.hawkbit.repository.event.remote;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
|
||||
@@ -18,6 +19,7 @@ import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
* TenantAwareEvent that contains an updated download progress for a given
|
||||
* ActionStatus that was written for a download request.
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@NoArgsConstructor // for serialization libs like jackson
|
||||
public class DownloadProgressEvent extends RemoteTenantAwareEvent {
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ package org.eclipse.hawkbit.repository.event.remote.entity;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.eclipse.hawkbit.repository.event.entity.EntityUpdatedEvent;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
@@ -19,6 +20,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
* Defines the remote event for updating a {@link DistributionSet}.
|
||||
*/
|
||||
@NoArgsConstructor // for serialization libs like jackson
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class DistributionSetUpdatedEvent extends RemoteEntityEvent<DistributionSet> implements EntityUpdatedEvent {
|
||||
|
||||
@Serial
|
||||
|
||||
@@ -12,7 +12,6 @@ package org.eclipse.hawkbit.repository.builder;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.hawkbit.repository.ValidString;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Create and update builder DTO.
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.messaging.converter.MessageConversionException;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class BusProtoStuffMessageConverterTest {
|
||||
class BusProtoStuffMessageConverterTest {
|
||||
|
||||
private final BusProtoStuffMessageConverter underTest = new BusProtoStuffMessageConverter();
|
||||
|
||||
@@ -41,13 +41,13 @@ public class BusProtoStuffMessageConverterTest {
|
||||
private Message<Object> messageMock;
|
||||
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
void before() {
|
||||
when(targetMock.getId()).thenReturn(1L);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that the TargetCreatedEvent can be successfully serialized and deserialized")
|
||||
public void successfullySerializeAndDeserializeEvent() {
|
||||
void successfullySerializeAndDeserializeEvent() {
|
||||
final TargetCreatedEvent targetCreatedEvent = new TargetCreatedEvent(targetMock, "1");
|
||||
// serialize
|
||||
final Object serializedEvent = underTest.convertToInternal(targetCreatedEvent,
|
||||
@@ -63,7 +63,7 @@ public class BusProtoStuffMessageConverterTest {
|
||||
|
||||
@Test
|
||||
@Description("Verifies that a MessageConversationException is thrown on missing event-type information encoding")
|
||||
public void missingEventTypeMappingThrowsMessageConversationException() {
|
||||
void missingEventTypeMappingThrowsMessageConversationException() {
|
||||
final DummyRemoteEntityEvent dummyEvent = new DummyRemoteEntityEvent(targetMock, "applicationId");
|
||||
final MessageHeaders messageHeaders = new MessageHeaders(new HashMap<>());
|
||||
|
||||
|
||||
@@ -26,15 +26,13 @@ import org.springframework.data.repository.core.support.RepositoryFactorySupport
|
||||
* @param <S>
|
||||
* @param <ID>
|
||||
*/
|
||||
public class CustomBaseRepositoryFactoryBean<T extends Repository<S, ID>, S, ID>
|
||||
extends JpaRepositoryFactoryBean<T, S, ID> {
|
||||
public class CustomBaseRepositoryFactoryBean<T extends Repository<S, ID>, S, ID> extends JpaRepositoryFactoryBean<T, S, ID> {
|
||||
|
||||
@Autowired
|
||||
BaseRepositoryTypeProvider baseRepoProvider;
|
||||
|
||||
/**
|
||||
* Creates a new {@link JpaRepositoryFactoryBean} for the given repository
|
||||
* interface.
|
||||
* Creates a new {@link JpaRepositoryFactoryBean} for the given repository interface.
|
||||
*
|
||||
* @param repositoryInterface must not be {@literal null}.
|
||||
*/
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* Default implementation of {@link RolloutApprovalStrategy}. Decides whether
|
||||
@@ -93,7 +93,7 @@ public class DefaultRolloutApprovalStrategy implements RolloutApprovalStrategy {
|
||||
if (RolloutStatus.CREATING == rollout.getStatus()) {
|
||||
final String actor = rollout.getLastModifiedBy() != null ? rollout.getLastModifiedBy()
|
||||
: rollout.getCreatedBy();
|
||||
if (!StringUtils.isEmpty(actor)) {
|
||||
if (!ObjectUtils.isEmpty(actor)) {
|
||||
return systemSecurityContext.runAsSystem(
|
||||
() -> userAuthoritiesResolver.getUserAuthorities(rollout.getTenant(), actor));
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ import jakarta.persistence.Column;
|
||||
import jakarta.persistence.ConstraintMode;
|
||||
import jakarta.persistence.EmbeddedId;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.ForeignKey;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
|
||||
@@ -124,8 +124,8 @@ public interface BaseEntityRepository<T extends AbstractJpaTenantAwareBaseEntity
|
||||
|
||||
default <T extends AbstractJpaTenantAwareBaseEntity> Specification<T> byIdsSpec(final Iterable<Long> ids) {
|
||||
final Collection<Long> collection;
|
||||
if (ids instanceof Collection<Long>) {
|
||||
collection = (Collection<Long>) ids;
|
||||
if (ids instanceof Collection<Long> idCollection) {
|
||||
collection = idCollection;
|
||||
} else {
|
||||
collection = new LinkedList<>();
|
||||
ids.forEach(collection::add);
|
||||
|
||||
@@ -326,8 +326,7 @@ public class BaseEntityRepositoryACM<T extends AbstractJpaTenantAwareBaseEntity>
|
||||
try {
|
||||
// TODO - cache mapping so to speed things
|
||||
final Method delegateMethod =
|
||||
BaseEntityRepositoryACM.class.getDeclaredMethod(
|
||||
method.getName(), method.getParameterTypes());
|
||||
BaseEntityRepositoryACM.class.getDeclaredMethod(method.getName(), method.getParameterTypes());
|
||||
return delegateMethod.invoke(repositoryACM, args);
|
||||
} catch (final NoSuchMethodException e) {
|
||||
// call to repository itself
|
||||
@@ -369,7 +368,7 @@ public class BaseEntityRepositoryACM<T extends AbstractJpaTenantAwareBaseEntity>
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
private static <T extends Long> Set<Long> toSetDistinct(final Iterable<T> i) {
|
||||
private static Set<Long> toSetDistinct(final Iterable<? extends Long> i) {
|
||||
final Set<Long> set = new HashSet<>();
|
||||
i.forEach(set::add);
|
||||
return set;
|
||||
|
||||
@@ -20,11 +20,11 @@ import org.junit.jupiter.api.Test;
|
||||
*/
|
||||
@Feature("Component Tests - Repository")
|
||||
@Story("Test DistributionSetCreatedEvent")
|
||||
public class DistributionSetCreatedEventTest extends AbstractRemoteEntityEventTest<DistributionSet> {
|
||||
class DistributionSetCreatedEventTest extends AbstractRemoteEntityEventTest<DistributionSet> {
|
||||
|
||||
@Test
|
||||
@Description("Verifies that the distribution set entity reloading by remote created event works")
|
||||
public void testDistributionSetCreatedEvent() {
|
||||
void testDistributionSetCreatedEvent() {
|
||||
assertAndCreateRemoteEvent(DistributionSetCreatedEvent.class);
|
||||
}
|
||||
|
||||
@@ -33,5 +33,4 @@ public class DistributionSetCreatedEventTest extends AbstractRemoteEntityEventTe
|
||||
return distributionSetManagement.create(entityFactory.distributionSet().create()
|
||||
.name("incomplete").version("2").description("incomplete").type("os"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,17 +20,17 @@ import org.junit.jupiter.api.Test;
|
||||
*/
|
||||
@Feature("Component Tests - Repository")
|
||||
@Story("Test DistributionSetTagCreatedEvent and DistributionSetTagUpdateEvent")
|
||||
public class DistributionSetTagEventTest extends AbstractRemoteEntityEventTest<DistributionSetTag> {
|
||||
class DistributionSetTagEventTest extends AbstractRemoteEntityEventTest<DistributionSetTag> {
|
||||
|
||||
@Test
|
||||
@Description("Verifies that the distribution set tag entity reloading by remote created event works")
|
||||
public void testDistributionSetTagCreatedEvent() {
|
||||
void testDistributionSetTagCreatedEvent() {
|
||||
assertAndCreateRemoteEvent(DistributionSetTagCreatedEvent.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that the distribution set tag entity reloading by remote updated event works")
|
||||
public void testDistributionSetTagUpdateEvent() {
|
||||
void testDistributionSetTagUpdateEvent() {
|
||||
assertAndCreateRemoteEvent(DistributionSetTagUpdatedEvent.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,11 +20,11 @@ import org.junit.jupiter.api.Test;
|
||||
*/
|
||||
@Feature("Component Tests - Repository")
|
||||
@Story("Test DistributionSetUpdateEvent")
|
||||
public class DistributionSetUpdatedEventTest extends AbstractRemoteEntityEventTest<DistributionSet> {
|
||||
class DistributionSetUpdatedEventTest extends AbstractRemoteEntityEventTest<DistributionSet> {
|
||||
|
||||
@Test
|
||||
@Description("Verifies that the distribution set entity reloading by remote updated event works")
|
||||
public void testDistributionSetUpdateEvent() {
|
||||
void testDistributionSetUpdateEvent() {
|
||||
assertAndCreateRemoteEvent(DistributionSetUpdatedEvent.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,17 +20,17 @@ import org.junit.jupiter.api.Test;
|
||||
*/
|
||||
@Feature("Component Tests - Repository")
|
||||
@Story("Test SoftwareModuleCreatedEvent, SoftwareModuleUpdatedEvent")
|
||||
public class SoftwareModuleEventTest extends AbstractRemoteEntityEventTest<SoftwareModule> {
|
||||
class SoftwareModuleEventTest extends AbstractRemoteEntityEventTest<SoftwareModule> {
|
||||
|
||||
@Test
|
||||
@Description("Verifies that the software module entity reloading by remote created event works")
|
||||
public void testTargetCreatedEvent() {
|
||||
void testTargetCreatedEvent() {
|
||||
assertAndCreateRemoteEvent(SoftwareModuleCreatedEvent.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that the software module entity reloading by remote updated event works")
|
||||
public void testTargetUpdatedEvent() {
|
||||
void testTargetUpdatedEvent() {
|
||||
assertAndCreateRemoteEvent(SoftwareModuleUpdatedEvent.class);
|
||||
}
|
||||
|
||||
@@ -38,5 +38,4 @@ public class SoftwareModuleEventTest extends AbstractRemoteEntityEventTest<Softw
|
||||
protected SoftwareModule createEntity() {
|
||||
return testdataFactory.createSoftwareModuleApp();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -51,11 +51,11 @@ import org.springframework.test.context.TestPropertySource;
|
||||
@Story("Concurrent Distribution Set invalidation")
|
||||
@ContextConfiguration(classes = ConcurrentDistributionSetInvalidationTest.Config.class)
|
||||
@TestPropertySource(properties = { "hawkbit.server.repository.dsInvalidationLockTimeout=1" })
|
||||
public class ConcurrentDistributionSetInvalidationTest extends AbstractJpaIntegrationTest {
|
||||
class ConcurrentDistributionSetInvalidationTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Description("Verify that a large rollout causes a timeout when trying to invalidate a distribution set")
|
||||
public void verifyInvalidateDistributionSetWithLargeRolloutThrowsException() throws Exception {
|
||||
void verifyInvalidateDistributionSetWithLargeRolloutThrowsException() {
|
||||
final DistributionSet distributionSet = testdataFactory.createDistributionSet();
|
||||
final Rollout rollout = createRollout(distributionSet);
|
||||
final String tenant = tenantAware.getCurrentTenant();
|
||||
|
||||
@@ -195,7 +195,7 @@ class ConfirmationManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
final List<Action> actions = assignDistributionSets(
|
||||
Arrays.asList(toDeploymentRequest(controllerId, dsId), toDeploymentRequest(controllerId, dsId2)))
|
||||
.stream().flatMap(s -> s.getAssignedEntity().stream()).collect(Collectors.toList());
|
||||
.stream().flatMap(s -> s.getAssignedEntity().stream()).toList();
|
||||
assertThat(actions).hasSize(2);
|
||||
|
||||
assertThat(confirmationManagement.findActiveActionsWaitingConfirmation(controllerId)).hasSize(2)
|
||||
|
||||
@@ -23,7 +23,6 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@@ -39,7 +38,6 @@ import io.qameta.allure.Description;
|
||||
import io.qameta.allure.Feature;
|
||||
import io.qameta.allure.Step;
|
||||
import io.qameta.allure.Story;
|
||||
import org.apache.commons.lang3.RandomUtils;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission;
|
||||
import org.eclipse.hawkbit.repository.RepositoryProperties;
|
||||
@@ -199,7 +197,6 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
.status(Action.Status.RUNNING).occurredAt(System.currentTimeMillis())
|
||||
.messages(List.of("proceeding message 1")));
|
||||
|
||||
final long createTime = System.currentTimeMillis();
|
||||
waitNextMillis();
|
||||
controllerManagement.addUpdateActionStatus(entityFactory.actionStatus().create(actionId)
|
||||
.status(Action.Status.RUNNING).occurredAt(System.currentTimeMillis())
|
||||
@@ -307,7 +304,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
assertThat(actionStatusRepository.count()).isEqualTo(2);
|
||||
assertThat(controllerManagement.findActionStatusByAction(PAGE, actionId).getNumberOfElements()).isEqualTo(2);
|
||||
assertThat(activeActionExistsForControllerId(DEFAULT_CONTROLLER_ID)).isEqualTo(true);
|
||||
assertThat(activeActionExistsForControllerId(DEFAULT_CONTROLLER_ID)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -338,7 +335,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
@ExpectEvents({
|
||||
@Expect(type = TargetCreatedEvent.class, count = 1),
|
||||
@Expect(type = SoftwareModuleCreatedEvent.class, count = 1) })
|
||||
void entityQueriesReferringToNotExistingEntitiesThrowsException() throws URISyntaxException {
|
||||
void entityQueriesReferringToNotExistingEntitiesThrowsException() {
|
||||
final Target target = testdataFactory.createTarget();
|
||||
final SoftwareModule module = testdataFactory.createSoftwareModuleOs();
|
||||
|
||||
@@ -622,7 +619,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Expect(type = TargetAssignDistributionSetEvent.class, count = 1) })
|
||||
void hasTargetArtifactAssignedIsTrueWithMultipleArtifacts() {
|
||||
final int artifactSize = 5 * 1024;
|
||||
final byte[] random = RandomUtils.nextBytes(artifactSize);
|
||||
final byte[] random = randomBytes(artifactSize);
|
||||
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("");
|
||||
final DistributionSet ds2 = testdataFactory.createDistributionSet("2");
|
||||
@@ -1164,7 +1161,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
assertThat(actionStatusRepository.count()).isEqualTo(2);
|
||||
assertThat(controllerManagement.findActionStatusByAction(PAGE, actionId).getNumberOfElements()).isEqualTo(2);
|
||||
assertThat(activeActionExistsForControllerId(DEFAULT_CONTROLLER_ID)).isEqualTo(false);
|
||||
assertThat(activeActionExistsForControllerId(DEFAULT_CONTROLLER_ID)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1191,7 +1188,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
assertThat(actionStatusRepository.count()).isEqualTo(3);
|
||||
assertThat(controllerManagement.findActionStatusByAction(PAGE, actionId).getNumberOfElements()).isEqualTo(3);
|
||||
assertThat(activeActionExistsForControllerId(DEFAULT_CONTROLLER_ID)).isEqualTo(false);
|
||||
assertThat(activeActionExistsForControllerId(DEFAULT_CONTROLLER_ID)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1219,7 +1216,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
assertThat(actionStatusRepository.count()).isEqualTo(4);
|
||||
assertThat(controllerManagement.findActionStatusByAction(PAGE, actionId).getNumberOfElements()).isEqualTo(4);
|
||||
assertThat(activeActionExistsForControllerId(DEFAULT_CONTROLLER_ID)).isEqualTo(false);
|
||||
assertThat(activeActionExistsForControllerId(DEFAULT_CONTROLLER_ID)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1564,7 +1561,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
controllerManagement.deleteExistingTarget(target.getControllerId());
|
||||
|
||||
assertThat(targetRepository.count()).as("target should not exist anymore").isEqualTo(0L);
|
||||
assertThat(targetRepository.count()).as("target should not exist anymore").isZero();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1574,7 +1571,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThatExceptionOfType(EntityNotFoundException.class)
|
||||
.as("No EntityNotFoundException thrown when deleting a non-existing target")
|
||||
.isThrownBy(() -> controllerManagement.deleteExistingTarget("BB"));
|
||||
assertThat(targetRepository.count()).as("target should not exist").isEqualTo(0L);
|
||||
assertThat(targetRepository.count()).as("target should not exist").isZero();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1589,7 +1586,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(targetRepository.count()).as("target exists and is ready for deletion").isEqualTo(1L);
|
||||
|
||||
controllerManagement.deleteExistingTarget(target.getControllerId());
|
||||
assertThat(targetRepository.count()).as("target should not exist anymore").isEqualTo(0L);
|
||||
assertThat(targetRepository.count()).as("target should not exist anymore").isZero();
|
||||
|
||||
assertThatExceptionOfType(EntityNotFoundException.class)
|
||||
.as("No EntityNotFoundException thrown when deleting a non-existing target")
|
||||
@@ -1769,7 +1766,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// verify attribute removal
|
||||
final Map<String, String> updatedAttributes = targetManagement.getControllerAttributes(controllerId);
|
||||
assertThat(updatedAttributes.size()).isEqualTo(previousSize - 2);
|
||||
assertThat(updatedAttributes).hasSize(previousSize - 2);
|
||||
assertThat(updatedAttributes).doesNotContainKeys("k1", "k3");
|
||||
}
|
||||
|
||||
@@ -1786,9 +1783,9 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// verify attribute merge
|
||||
final Map<String, String> updatedAttributes = targetManagement.getControllerAttributes(controllerId);
|
||||
assertThat(updatedAttributes.size()).isEqualTo(4);
|
||||
assertThat(updatedAttributes).hasSize(4);
|
||||
assertThat(updatedAttributes).containsAllEntriesOf(mergeAttributes);
|
||||
assertThat(updatedAttributes.get("k1")).isEqualTo("v1_modified_again");
|
||||
assertThat(updatedAttributes).containsEntry("k1", "v1_modified_again");
|
||||
attributes.keySet().forEach(assertThat(updatedAttributes)::containsKey);
|
||||
}
|
||||
|
||||
@@ -1806,9 +1803,9 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// verify attribute replacement
|
||||
final Map<String, String> updatedAttributes = targetManagement.getControllerAttributes(controllerId);
|
||||
assertThat(updatedAttributes.size()).isEqualTo(replacementAttributes.size());
|
||||
assertThat(updatedAttributes).hasSameSizeAs(replacementAttributes);
|
||||
assertThat(updatedAttributes).containsAllEntriesOf(replacementAttributes);
|
||||
assertThat(updatedAttributes.get("k1")).isEqualTo("v1_modified");
|
||||
assertThat(updatedAttributes).containsEntry("k1", "v1_modified");
|
||||
attributes.entrySet().forEach(assertThat(updatedAttributes)::doesNotContain);
|
||||
}
|
||||
|
||||
@@ -1822,7 +1819,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// verify initial attributes
|
||||
final Map<String, String> updatedAttributes = targetManagement.getControllerAttributes(controllerId);
|
||||
assertThat(updatedAttributes.size()).isEqualTo(attributes.size());
|
||||
assertThat(updatedAttributes).hasSameSizeAs(attributes);
|
||||
assertThat(updatedAttributes).containsAllEntriesOf(attributes);
|
||||
}
|
||||
|
||||
@@ -1849,7 +1846,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
.addUpdateActionStatus(entityFactory.actionStatus().create(actionId).status(Status.DOWNLOADED));
|
||||
|
||||
controllerManagement.addUpdateActionStatus(entityFactory.actionStatus().create(actionId).status(status));
|
||||
assertThat(activeActionExistsForControllerId(DEFAULT_CONTROLLER_ID)).isEqualTo(false);
|
||||
assertThat(activeActionExistsForControllerId(DEFAULT_CONTROLLER_ID)).isFalse();
|
||||
}
|
||||
|
||||
@Step
|
||||
@@ -1883,7 +1880,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
private void assertNoActiveActionsExistsForControllerId(final String controllerId) {
|
||||
assertThat(activeActionExistsForControllerId(controllerId)).isEqualTo(false);
|
||||
assertThat(activeActionExistsForControllerId(controllerId)).isFalse();
|
||||
}
|
||||
|
||||
private boolean activeActionExistsForControllerId(final String controllerId) {
|
||||
|
||||
@@ -23,9 +23,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import jakarta.validation.ConstraintViolationException;
|
||||
@@ -108,7 +106,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Description("Tests that an exception is thrown when a target is assigned to an incomplete distribution set")
|
||||
public void verifyAssignTargetsToIncompleteDistribution() {
|
||||
void verifyAssignTargetsToIncompleteDistribution() {
|
||||
final DistributionSet distributionSet = testdataFactory.createIncompleteDistributionSet();
|
||||
final Target target = testdataFactory.createTarget();
|
||||
|
||||
@@ -119,7 +117,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Description("Tests that an exception is thrown when a target is assigned to an invalidated distribution set")
|
||||
public void verifyAssignTargetsToInvalidDistribution() {
|
||||
void verifyAssignTargetsToInvalidDistribution() {
|
||||
final DistributionSet distributionSet = testdataFactory.createAndInvalidateDistributionSet();
|
||||
final Target target = testdataFactory.createTarget();
|
||||
|
||||
@@ -484,7 +482,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
void assignedDistributionSet() {
|
||||
|
||||
final List<String> controllerIds = testdataFactory.createTargets(10).stream().map(Target::getControllerId)
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
final List<Target> onlineAssignedTargets = testdataFactory.createTargets(10, "2");
|
||||
controllerIds.addAll(onlineAssignedTargets.stream().map(Target::getControllerId).toList());
|
||||
|
||||
@@ -494,12 +492,12 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
final long current = System.currentTimeMillis();
|
||||
|
||||
final List<Entry<String, Long>> offlineAssignments = controllerIds.stream()
|
||||
.map(targetId -> new SimpleEntry<>(targetId, ds.getId())).collect(Collectors.toList());
|
||||
.map(targetId -> (Entry<String, Long>)new SimpleEntry<>(targetId, ds.getId())).toList();
|
||||
final List<DistributionSetAssignmentResult> assignmentResults = deploymentManagement
|
||||
.offlineAssignedDistributionSets(offlineAssignments);
|
||||
assertThat(assignmentResults).hasSize(1);
|
||||
final List<Target> targets = assignmentResults.get(0).getAssignedEntity().stream().map(Action::getTarget)
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
|
||||
assertThat(actionRepository.count()).isEqualTo(20);
|
||||
assertThat(findActionsByDistributionSet(PAGE, ds.getId())).as("Offline actions are not active")
|
||||
@@ -547,7 +545,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
.isEqualTo(tenantAware.getCurrentUsername());
|
||||
return a;
|
||||
})
|
||||
.map(action -> action.getDistributionSet().getId()).collect(Collectors.toList());
|
||||
.map(action -> action.getDistributionSet().getId()).toList();
|
||||
assertThat(assignedDsIds).containsExactlyInAnyOrderElementsOf(dsIds);
|
||||
});
|
||||
}
|
||||
@@ -610,7 +608,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
void previousAssignmentsAreNotCanceledInMultiAssignMode() {
|
||||
enableMultiAssignments();
|
||||
final List<Target> targets = testdataFactory.createTargets(10);
|
||||
final List<String> targetIds = targets.stream().map(Target::getControllerId).collect(Collectors.toList());
|
||||
final List<String> targetIds = targets.stream().map(Target::getControllerId).toList();
|
||||
|
||||
// First assignment
|
||||
final DistributionSet ds1 = testdataFactory.createDistributionSet("Multi-assign-1");
|
||||
@@ -648,7 +646,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
.assignDistributionSets(deploymentRequests);
|
||||
|
||||
assertThat(getResultingActionCount(results)).isEqualTo(deploymentRequests.size());
|
||||
final List<Long> dsIds = distributionSets.stream().map(DistributionSet::getId).collect(Collectors.toList());
|
||||
final List<Long> dsIds = distributionSets.stream().map(DistributionSet::getId).toList();
|
||||
targets.forEach(target -> {
|
||||
final List<Long> assignedDsIds = deploymentManagement.findActionsByTarget(target.getControllerId(), PAGE)
|
||||
.stream()
|
||||
@@ -658,7 +656,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
.isEqualTo(tenantAware.getCurrentUsername());
|
||||
return a;
|
||||
})
|
||||
.map(action -> action.getDistributionSet().getId()).collect(Collectors.toList());
|
||||
.map(action -> action.getDistributionSet().getId()).toList();
|
||||
assertThat(assignedDsIds).containsExactlyInAnyOrderElementsOf(dsIds);
|
||||
});
|
||||
}
|
||||
@@ -689,7 +687,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
assertThat(getResultingActionCount(results)).isEqualTo(deploymentRequests.size());
|
||||
|
||||
final List<Long> dsIds = distributionSets.stream().map(DistributionSet::getId).collect(Collectors.toList());
|
||||
final List<Long> dsIds = distributionSets.stream().map(DistributionSet::getId).toList();
|
||||
targets.forEach(target ->
|
||||
deploymentManagement.findActionsByTarget(target.getControllerId(), PAGE).forEach(action -> {
|
||||
assertThat(action.getDistributionSet().getId()).isIn(dsIds);
|
||||
@@ -748,8 +746,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
@ValueSource(booleans = { true, false })
|
||||
@Description("Assignments with confirmation flow active will result in actions in 'WAIT_FOR_CONFIRMATION' state")
|
||||
void assignmentWithConfirmationFlowActive(final boolean confirmationRequired) {
|
||||
final List<String> controllerIds = testdataFactory.createTargets(1).stream().map(Target::getControllerId)
|
||||
.collect(Collectors.toList());
|
||||
final List<String> controllerIds = testdataFactory.createTargets(1).stream().map(Target::getControllerId).toList();
|
||||
final DistributionSet distributionSet = testdataFactory.createDistributionSet();
|
||||
|
||||
enableConfirmationFlow();
|
||||
@@ -859,16 +856,14 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Assignments with confirmation flow deactivated will result in actions in only in 'RUNNING' state")
|
||||
void verifyConfirmationRequiredFlagHaveNoInfluenceIfFlowIsDeactivated() {
|
||||
final List<String> targets1 = testdataFactory.createTargets("group1", 1).stream().map(Target::getControllerId)
|
||||
.collect(Collectors.toList());
|
||||
final List<String> targets2 = testdataFactory.createTargets("group2", 1).stream().map(Target::getControllerId)
|
||||
.collect(Collectors.toList());
|
||||
final List<String> targets1 = testdataFactory.createTargets("group1", 1).stream().map(Target::getControllerId).toList();
|
||||
final List<String> targets2 = testdataFactory.createTargets("group2", 1).stream().map(Target::getControllerId).toList();
|
||||
final DistributionSet distributionSet = testdataFactory.createDistributionSet();
|
||||
|
||||
final List<DistributionSetAssignmentResult> results = Stream
|
||||
.concat(assignDistributionSetToTargets(distributionSet, targets1, true).stream(), //
|
||||
assignDistributionSetToTargets(distributionSet, targets2, false).stream()) //
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
|
||||
final List<String> controllerIds = Stream.concat(targets1.stream(), targets2.stream()).toList();
|
||||
|
||||
@@ -1073,7 +1068,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Expect(type = TargetCreatedEvent.class, count = 10),
|
||||
@Expect(type = ActionCreatedEvent.class, count = 10),
|
||||
@Expect(type = TargetUpdatedEvent.class, count = 10) })
|
||||
void failDistributionSetAssigmentThatIsNotComplete() throws InterruptedException {
|
||||
void failDistributionSetAssigmentThatIsNotComplete() {
|
||||
final List<Target> targets = testdataFactory.createTargets(10);
|
||||
|
||||
final SoftwareModule ah = testdataFactory.createSoftwareModuleApp();
|
||||
@@ -1131,7 +1126,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(page.getTotalElements()).as("wrong size of actions")
|
||||
.isEqualTo(noOfDeployedTargets * noOfDistributionSets);
|
||||
|
||||
// only records retrieved from the DB can be evaluated to be sure that all fields are populated;
|
||||
// only records retrieved from the DB can be evaluated to be sure that all fields are populated
|
||||
final List<JpaTarget> allFoundTargets = targetRepository.findAll();
|
||||
|
||||
final List<JpaTarget> deployedTargetsFromDB = targetRepository.findAllById(deployedTargetIDs);
|
||||
@@ -1203,7 +1198,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
final List<Target> updatedTsDsA = testdataFactory
|
||||
.sendUpdateActionStatusToTargets(deployResWithDsA.getDeployedTargets(), Status.FINISHED,
|
||||
Collections.singletonList("alles gut"))
|
||||
.stream().map(Action::getTarget).collect(Collectors.toList());
|
||||
.stream().map(Action::getTarget).toList();
|
||||
|
||||
// verify, that dsA is deployed correctly
|
||||
for (final Target t_ : updatedTsDsA) {
|
||||
@@ -1223,12 +1218,12 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
// activeActions, add a corresponding cancelAction and another
|
||||
// UpdateAction for dsA
|
||||
final List<Target> deployed2DS = assignDistributionSet(dsA, deployResWithDsB.getDeployedTargets())
|
||||
.getAssignedEntity().stream().map(Action::getTarget).collect(Collectors.toList());
|
||||
.getAssignedEntity().stream().map(Action::getTarget).toList();
|
||||
findActionsByDistributionSet(pageRequest, dsA.getId()).getContent().get(1);
|
||||
|
||||
// get final updated version of targets
|
||||
final List<Target> deployResWithDsBTargets = targetManagement.getByControllerID(deployResWithDsB
|
||||
.getDeployedTargets().stream().map(Target::getControllerId).collect(Collectors.toList()));
|
||||
.getDeployedTargets().stream().map(Target::getControllerId).toList());
|
||||
|
||||
assertThat(deployed2DS).as("deployed ds is wrong").usingElementComparator(controllerIdComparator())
|
||||
.containsAll(deployResWithDsBTargets);
|
||||
@@ -1285,7 +1280,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// verify that deleted attribute is used correctly
|
||||
List<DistributionSet> allFoundDS = distributionSetManagement.findByCompleted(PAGE, true).getContent();
|
||||
assertThat(allFoundDS.size()).as("no ds should be founded").isZero();
|
||||
assertThat(allFoundDS).as("no ds should be founded").isEmpty();
|
||||
|
||||
assertThat(distributionSetRepository.findAll(SpecificationsBuilder.combineWithAnd(Arrays
|
||||
.asList(DistributionSetSpecification.isDeleted(true), DistributionSetSpecification.isCompleted(true))),
|
||||
@@ -1302,7 +1297,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
// successfully and no activeAction is referring to created distribution
|
||||
// sets
|
||||
allFoundDS = distributionSetManagement.findByCompleted(pageRequest, true).getContent();
|
||||
assertThat(allFoundDS.size()).as("no ds should be founded").isZero();
|
||||
assertThat(allFoundDS).as("no ds should be founded").isEmpty();
|
||||
assertThat(distributionSetRepository.findAll(SpecificationsBuilder.combineWithAnd(Arrays
|
||||
.asList(DistributionSetSpecification.isDeleted(true), DistributionSetSpecification.isCompleted(true))),
|
||||
PAGE).getContent()).as("wrong size of founded ds").hasSize(noOfDistributionSets);
|
||||
@@ -1349,7 +1344,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// doing the assignment
|
||||
targs = assignDistributionSet(dsA, targs).getAssignedEntity().stream().map(Action::getTarget)
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
implicitLock(dsA);
|
||||
Target targ = targetManagement.getByControllerID(targs.iterator().next().getControllerId()).get();
|
||||
|
||||
@@ -1392,7 +1387,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
"wrong installed ds");
|
||||
|
||||
targs = assignDistributionSet(dsB.getId(), "target-id-A").getAssignedEntity().stream().map(Action::getTarget)
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
implicitLock(dsB);
|
||||
|
||||
targ = targs.iterator().next();
|
||||
@@ -1696,7 +1691,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
// deployedTargets
|
||||
for (final DistributionSet ds : dsList) {
|
||||
deployedTargets = assignDistributionSet(ds, deployedTargets).getAssignedEntity().stream()
|
||||
.map(Action::getTarget).collect(Collectors.toList());
|
||||
.map(Action::getTarget).toList();
|
||||
implicitLock(ds);
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ class DistributionSetInvalidationManagementTest extends AbstractJpaIntegrationTe
|
||||
// if status is pending, the assignment has not been canceled
|
||||
assertThat(targetRepository.findById(target.getId()).get().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(findActionsByTarget(target).size()).isEqualTo(1);
|
||||
assertThat(findActionsByTarget(target)).hasSize(1);
|
||||
assertThat(findActionsByTarget(target).get(0).getStatus()).isEqualTo(Status.RUNNING);
|
||||
}
|
||||
}
|
||||
@@ -101,7 +101,7 @@ class DistributionSetInvalidationManagementTest extends AbstractJpaIntegrationTe
|
||||
assertThat(
|
||||
targetRepository.findById(invalidationTestData.getTargets().get(0).getId()).get().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(findActionsByTarget(target).size()).isEqualTo(1);
|
||||
assertThat(findActionsByTarget(target)).hasSize(1);
|
||||
assertThat(findActionsByTarget(target).get(0).getStatus()).isEqualTo(Status.RUNNING);
|
||||
}
|
||||
}
|
||||
@@ -131,7 +131,7 @@ class DistributionSetInvalidationManagementTest extends AbstractJpaIntegrationTe
|
||||
for (final Target target : invalidationTestData.getTargets()) {
|
||||
assertThat(targetRepository.findById(target.getId()).get().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
assertThat(findActionsByTarget(target).size()).isEqualTo(1);
|
||||
assertThat(findActionsByTarget(target)).hasSize(1);
|
||||
assertThat(findActionsByTarget(target).get(0).getStatus()).isEqualTo(Status.CANCELED);
|
||||
}
|
||||
}
|
||||
@@ -158,7 +158,7 @@ class DistributionSetInvalidationManagementTest extends AbstractJpaIntegrationTe
|
||||
for (final Target target : invalidationTestData.getTargets()) {
|
||||
assertThat(targetRepository.findById(target.getId()).get().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(findActionsByTarget(target).size()).isEqualTo(1);
|
||||
assertThat(findActionsByTarget(target)).hasSize(1);
|
||||
assertThat(findActionsByTarget(target).get(0).getStatus()).isEqualTo(Status.CANCELING);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ class DistributionSetManagementSecurityTest
|
||||
|
||||
@Test
|
||||
@Description("Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.")
|
||||
public void assignSoftwareModulesPermissionsCheck() {
|
||||
void assignSoftwareModulesPermissionsCheck() {
|
||||
assertPermissions(() -> distributionSetManagement.assignSoftwareModules(1L, List.of(1L)), List.of(SpPermission.UPDATE_REPOSITORY));
|
||||
}
|
||||
|
||||
|
||||
@@ -320,20 +320,21 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSetTag tag = distributionSetTagManagement.create(entityFactory.tag().create().name(TAG1_NAME));
|
||||
|
||||
final List<DistributionSet> assignedDS = distributionSetManagement.assignTag(assignDS, tag.getId());
|
||||
assertThat(assignedDS.size()).as("assigned ds has wrong size").isEqualTo(4);
|
||||
assignedDS.stream().map(JpaDistributionSet.class::cast).forEach(ds -> assertThat(ds.getTags().size())
|
||||
assertThat(assignedDS).as("assigned ds has wrong size").hasSize(4);
|
||||
assignedDS.stream().map(JpaDistributionSet.class::cast).forEach(ds -> assertThat(ds.getTags())
|
||||
.as("ds has wrong tag size")
|
||||
.isEqualTo(1));
|
||||
.hasSize(1));
|
||||
|
||||
final DistributionSetTag findDistributionSetTag = getOrThrow(distributionSetTagManagement.findByName(TAG1_NAME));
|
||||
|
||||
assertThat(assignedDS.size()).as("assigned ds has wrong size")
|
||||
.isEqualTo(distributionSetManagement.findByTag(tag.getId(), PAGE).getNumberOfElements());
|
||||
assertThat(assignedDS)
|
||||
.as("assigned ds has wrong size")
|
||||
.hasSize(distributionSetManagement.findByTag(tag.getId(), PAGE).getNumberOfElements());
|
||||
|
||||
final JpaDistributionSet unAssignDS = (JpaDistributionSet) distributionSetManagement
|
||||
.unassignTag(List.of(assignDS.get(0)), findDistributionSetTag.getId()).get(0);
|
||||
assertThat(unAssignDS.getId()).as("unassigned ds is wrong").isEqualTo(assignDS.get(0));
|
||||
assertThat(unAssignDS.getTags().size()).as("unassigned ds has wrong tag size").isZero();
|
||||
assertThat(unAssignDS.getTags()).as("unassigned ds has wrong tag size").isEmpty();
|
||||
assertThat(distributionSetTagManagement.findByName(TAG1_NAME)).isPresent();
|
||||
assertThat(distributionSetManagement.findByTag(tag.getId(), PAGE).getNumberOfElements())
|
||||
.as("ds tag ds has wrong ds size").isEqualTo(3);
|
||||
@@ -559,7 +560,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
final DistributionSet dsNewType = distributionSetManagement.create(
|
||||
entityFactory.distributionSet().create().name("newtype").version("1").type(newType.getKey()).modules(
|
||||
dsDeleted.getModules().stream().map(SoftwareModule::getId).collect(Collectors.toList())));
|
||||
dsDeleted.getModules().stream().map(SoftwareModule::getId).toList()));
|
||||
|
||||
assignDistributionSet(dsDeleted, testdataFactory.createTargets(5));
|
||||
distributionSetManagement.delete(dsDeleted.getId());
|
||||
@@ -616,7 +617,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::isLocked).orElse(false))
|
||||
.isTrue();
|
||||
// assert software modules are locked
|
||||
assertThat(distributionSet.getModules().size()).isNotEqualTo(0);
|
||||
assertThat(distributionSet.getModules().size()).isNotZero();
|
||||
distributionSetManagement.getWithDetails(distributionSet.getId()).map(DistributionSet::getModules)
|
||||
.orElseThrow().forEach(module -> assertThat(module.isLocked()).isTrue());
|
||||
}
|
||||
@@ -667,7 +668,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
.orElse(true))
|
||||
.isFalse();
|
||||
// assert software modules are not unlocked
|
||||
assertThat(distributionSet.getModules().size()).isNotEqualTo(0);
|
||||
assertThat(distributionSet.getModules().size()).isNotZero();
|
||||
distributionSetManagement.getWithDetails(distributionSet.getId()).map(DistributionSet::getModules)
|
||||
.orElseThrow().forEach(module -> assertThat(module.isLocked()).isTrue());
|
||||
}
|
||||
@@ -677,7 +678,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
void lockDistributionSetApplied() {
|
||||
final DistributionSet distributionSet = testdataFactory.createDistributionSet("ds-1");
|
||||
final int softwareModuleCount = distributionSet.getModules().size();
|
||||
assertThat(softwareModuleCount).isNotEqualTo(0);
|
||||
assertThat(softwareModuleCount).isNotZero();
|
||||
distributionSetManagement.lock(distributionSet.getId());
|
||||
assertThat(
|
||||
distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::isLocked).orElse(false))
|
||||
@@ -688,18 +689,18 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
.as("Attempt to modify a locked DS software modules should throw an exception")
|
||||
.isThrownBy(() -> distributionSetManagement.assignSoftwareModules(
|
||||
distributionSet.getId(), List.of(testdataFactory.createSoftwareModule("sm-1").getId())));
|
||||
assertThat(distributionSetManagement.getWithDetails(distributionSet.getId()).get().getModules().size())
|
||||
assertThat(distributionSetManagement.getWithDetails(distributionSet.getId()).get().getModules())
|
||||
.as("Software module shall not be added to a locked DS.")
|
||||
.isEqualTo(softwareModuleCount);
|
||||
.hasSize(softwareModuleCount);
|
||||
|
||||
// try remove
|
||||
assertThatExceptionOfType(LockedException.class)
|
||||
.as("Attempt to modify a locked DS software modules should throw an exception")
|
||||
.isThrownBy(() -> distributionSetManagement.unassignSoftwareModule(
|
||||
distributionSet.getId(), distributionSet.getModules().stream().findFirst().get().getId()));
|
||||
assertThat(distributionSetManagement.getWithDetails(distributionSet.getId()).get().getModules().size())
|
||||
assertThat(distributionSetManagement.getWithDetails(distributionSet.getId()).get().getModules())
|
||||
.as("Software module shall not be removed from a locked DS.")
|
||||
.isEqualTo(softwareModuleCount);
|
||||
.hasSize(softwareModuleCount);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -853,7 +854,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
assertThat(foundDs).hasSize(3);
|
||||
|
||||
final List<Long> collect = foundDs.stream().map(DistributionSet::getId).collect(Collectors.toList());
|
||||
final List<Long> collect = foundDs.stream().map(DistributionSet::getId).toList();
|
||||
assertThat(collect).containsAll(searchIds);
|
||||
}
|
||||
|
||||
@@ -1029,7 +1030,6 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Step
|
||||
private void createAndUpdateDistributionSetWithInvalidVersion(final DistributionSet set) {
|
||||
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("entity with too long version should not be created")
|
||||
.isThrownBy(() -> distributionSetManagement.create(entityFactory.distributionSet().create().name("a")
|
||||
|
||||
@@ -26,8 +26,7 @@ import org.springframework.data.domain.Pageable;
|
||||
|
||||
@Feature("SecurityTests - DistributionSetTagManagement")
|
||||
@Story("SecurityTests DistributionSetTagManagement")
|
||||
public class DistributionSetTagManagementSecurityTest
|
||||
extends AbstractRepositoryManagementSecurityTest<DistributionSetTag, TagCreate, TagUpdate> {
|
||||
class DistributionSetTagManagementSecurityTest extends AbstractRepositoryManagementSecurityTest<DistributionSetTag, TagCreate, TagUpdate> {
|
||||
|
||||
@Override
|
||||
protected RepositoryManagement<DistributionSetTag, TagCreate, TagUpdate> getRepositoryManagement() {
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
@Feature("SecurityTests - DistributionSetTypeManagement")
|
||||
@Story("SecurityTests DistributionSetTypeManagement")
|
||||
public class DistributionSetTypeManagementSecurityTest
|
||||
class DistributionSetTypeManagementSecurityTest
|
||||
extends AbstractRepositoryManagementSecurityTest<DistributionSetType, DistributionSetTypeCreate, DistributionSetTypeUpdate> {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -156,8 +156,7 @@ class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTest {
|
||||
distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(dsType2.getId(),
|
||||
moduleTypeIds.subList(0, quota));
|
||||
assertThat(distributionSetTypeManagement.get(dsType2.getId())).isNotEmpty();
|
||||
assertThat(distributionSetTypeManagement.get(dsType2.getId()).get().getMandatoryModuleTypes().size())
|
||||
.isEqualTo(quota);
|
||||
assertThat(distributionSetTypeManagement.get(dsType2.getId()).get().getMandatoryModuleTypes()).hasSize(quota);
|
||||
// assign one more to trigger the quota exceeded error
|
||||
assertThatExceptionOfType(AssignmentQuotaExceededException.class)
|
||||
.isThrownBy(() -> distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(dsType2.getId(),
|
||||
@@ -168,8 +167,7 @@ class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTest {
|
||||
.create(entityFactory.distributionSetType().create().key("dst3").name("dst3"));
|
||||
distributionSetTypeManagement.assignOptionalSoftwareModuleTypes(dsType3.getId(), moduleTypeIds.subList(0, quota));
|
||||
assertThat(distributionSetTypeManagement.get(dsType3.getId())).isNotEmpty();
|
||||
assertThat(distributionSetTypeManagement.get(dsType3.getId()).get().getOptionalModuleTypes().size())
|
||||
.isEqualTo(quota);
|
||||
assertThat(distributionSetTypeManagement.get(dsType3.getId()).get().getOptionalModuleTypes()).hasSize(quota);
|
||||
// assign one more to trigger the quota exceeded error
|
||||
assertThatExceptionOfType(AssignmentQuotaExceededException.class)
|
||||
.isThrownBy(() -> distributionSetTypeManagement.assignOptionalSoftwareModuleTypes(dsType3.getId(),
|
||||
|
||||
@@ -346,9 +346,8 @@ public abstract class AbstractIntegrationTest {
|
||||
return distributionSetAssignmentResults;
|
||||
}
|
||||
|
||||
protected DistributionSetAssignmentResult assignDistributionSet(final DistributionSet ds,
|
||||
final List<Target> targets) {
|
||||
final List<String> targetIds = targets.stream().map(Target::getControllerId).collect(Collectors.toList());
|
||||
protected DistributionSetAssignmentResult assignDistributionSet(final DistributionSet ds, final List<Target> targets) {
|
||||
final List<String> targetIds = targets.stream().map(Target::getControllerId).toList();
|
||||
return assignDistributionSet(ds.getId(), targetIds, ActionType.FORCED);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,9 +33,6 @@ public class DatasourceContext {
|
||||
private final String password;
|
||||
private final String randomSchemaName = RANDOM_DB_PREFIX + TestdataFactory.randomString(10);
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public DatasourceContext(final String database, final String datasourceUrl, final String username, final String password) {
|
||||
this.database = database;
|
||||
this.datasourceUrl = datasourceUrl;
|
||||
|
||||
@@ -93,6 +93,8 @@ public class TestdataFactory {
|
||||
public static final String INVISIBLE_SM_MD_KEY = "invisibleMetdataKey";
|
||||
public static final String INVISIBLE_SM_MD_VALUE = "invisibleMetdataValue";
|
||||
|
||||
public static final RandomStringUtils RANDOM_STRING_UTILS = RandomStringUtils.secure();
|
||||
|
||||
/**
|
||||
* default {@link Target#getControllerId()}.
|
||||
*/
|
||||
@@ -119,27 +121,22 @@ public class TestdataFactory {
|
||||
public static final String DS_TYPE_DEFAULT = "test_default_ds_type";
|
||||
|
||||
/**
|
||||
* Key of test "os" {@link SoftwareModuleType} : mandatory firmware in
|
||||
* {@link #DS_TYPE_DEFAULT}.
|
||||
* Key of test "os" {@link SoftwareModuleType} : mandatory firmware in {@link #DS_TYPE_DEFAULT}.
|
||||
*/
|
||||
public static final String SM_TYPE_OS = "os";
|
||||
|
||||
/**
|
||||
* Key of test "runtime" {@link SoftwareModuleType} : optional firmware in
|
||||
* {@link #DS_TYPE_DEFAULT}.
|
||||
* Key of test "runtime" {@link SoftwareModuleType} : optional firmware in {@link #DS_TYPE_DEFAULT}.
|
||||
*/
|
||||
public static final String SM_TYPE_RT = "runtime";
|
||||
|
||||
/**
|
||||
* Key of test "application" {@link SoftwareModuleType} : optional software in
|
||||
* {@link #DS_TYPE_DEFAULT}.
|
||||
* Key of test "application" {@link SoftwareModuleType} : optional software in {@link #DS_TYPE_DEFAULT}.
|
||||
*/
|
||||
public static final String SM_TYPE_APP = "application";
|
||||
|
||||
public static final String DEFAULT_COLOUR = "#000000";
|
||||
|
||||
public static final RandomStringUtils RANDOM_STRING_UTILS = RandomStringUtils.secure();
|
||||
|
||||
private static final String SPACE_AND_DESCRIPTION = " description";
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -133,7 +133,7 @@ public class DosFilter extends OncePerRequestFilter {
|
||||
}
|
||||
|
||||
private static boolean checkIpFails(final String ip) {
|
||||
return ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip);
|
||||
return ip == null || ip.isEmpty() || "unknown".equalsIgnoreCase(ip);
|
||||
}
|
||||
|
||||
private static boolean handleMissingIpAddress(final HttpServletResponse response) {
|
||||
|
||||
@@ -189,11 +189,8 @@ public class DdiController {
|
||||
executor.schedule(this::poll, getPollMillis(controllerBase), TimeUnit.MILLISECONDS);
|
||||
}
|
||||
},
|
||||
() -> {
|
||||
// error has occurred or no controller base hasn't been acquired
|
||||
executor.schedule(this::poll, DEFAULT_POLL_MS, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
));
|
||||
() -> // error has occurred or no controller base hasn't been acquired
|
||||
executor.schedule(this::poll, DEFAULT_POLL_MS, TimeUnit.MILLISECONDS)));
|
||||
}
|
||||
|
||||
private Optional<DdiControllerBase> getControllerBase() {
|
||||
|
||||
@@ -78,8 +78,8 @@ public class ControllerPreAuthenticateSecurityTokenFilter extends AbstractContro
|
||||
return controllerManagement.getByControllerId(securityToken.getControllerId());
|
||||
}, securityToken.getTenant());
|
||||
|
||||
return target.map(t -> new HeaderAuthentication(t.getControllerId(),
|
||||
systemSecurityContext.runAsSystemAsTenant(() -> t.getSecurityToken(), securityToken.getTenant())))
|
||||
return target.map(t -> new HeaderAuthentication(
|
||||
t.getControllerId(), systemSecurityContext.runAsSystemAsTenant(t::getSecurityToken, securityToken.getTenant())))
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
|
||||
@@ -105,8 +105,7 @@ public class ControllerPreAuthenticatedSecurityHeaderFilter extends AbstractCont
|
||||
: securityToken.getControllerId());
|
||||
|
||||
final List<String> knownHashes = splitMultiHashBySemicolon(authorityNameConfigurationValue);
|
||||
return knownHashes.stream().map(hashItem -> new HeaderAuthentication(controllerId, hashItem))
|
||||
.collect(Collectors.toSet());
|
||||
return knownHashes.stream().map(hashItem -> new HeaderAuthentication(controllerId, hashItem)).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -115,7 +114,7 @@ public class ControllerPreAuthenticatedSecurityHeaderFilter extends AbstractCont
|
||||
}
|
||||
|
||||
private static List<String> splitMultiHashBySemicolon(final String knownIssuerHashes) {
|
||||
return Arrays.stream(knownIssuerHashes.split("[;,]")).map(String::toLowerCase).collect(Collectors.toList());
|
||||
return Arrays.stream(knownIssuerHashes.split("[;,]")).map(String::toLowerCase).toList();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,13 +24,10 @@ import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Feature("Unit Tests - Security")
|
||||
@Story("Exclude path aware shallow ETag filter")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class ControllerPreAuthenticatedAnonymousDownloadTest {
|
||||
class ControllerPreAuthenticatedAnonymousDownloadTest {
|
||||
|
||||
private ControllerPreAuthenticatedAnonymousDownload underTest;
|
||||
|
||||
@@ -41,19 +38,19 @@ public class ControllerPreAuthenticatedAnonymousDownloadTest {
|
||||
private TenantAware tenantAwareMock;
|
||||
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
void before() {
|
||||
underTest = new ControllerPreAuthenticatedAnonymousDownload(tenantConfigurationManagementMock, tenantAwareMock,
|
||||
new SystemSecurityContext(tenantAwareMock));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void useCorrectTenantConfiguationKey() {
|
||||
void useCorrectTenantConfiguationKey() {
|
||||
assertThat(underTest.getTenantConfigurationKey()).as("Should be using the correct tenant configuration key")
|
||||
.isEqualTo(underTest.getTenantConfigurationKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void successfulAuthenticationAdditionalAuthoritiesForDownload() {
|
||||
void successfulAuthenticationAdditionalAuthoritiesForDownload() {
|
||||
assertThat(underTest.getSuccessfulAuthenticationAuthorities())
|
||||
.as("Additional authorities should be containing the download anonymous role")
|
||||
.contains(new SimpleGrantedAuthority(SpringEvalExpressions.CONTROLLER_ROLE));
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
||||
@Feature("Unit Tests - Security")
|
||||
@Story("Issuer hash based authentication")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class ControllerPreAuthenticatedSecurityHeaderFilterTest {
|
||||
class ControllerPreAuthenticatedSecurityHeaderFilterTest {
|
||||
|
||||
private static final String CA_COMMON_NAME = "ca-cn";
|
||||
private static final String CA_COMMON_NAME_VALUE = "box1";
|
||||
@@ -63,7 +63,7 @@ public class ControllerPreAuthenticatedSecurityHeaderFilterTest {
|
||||
private SecurityContextSerializer securityContextSerializer;
|
||||
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
void before() {
|
||||
final SecurityContextTenantAware tenantAware = new SecurityContextTenantAware(authoritiesResolver, securityContextSerializer);
|
||||
underTest = new ControllerPreAuthenticatedSecurityHeaderFilter(
|
||||
CA_COMMON_NAME, "X-Ssl-Issuer-Hash-%d",
|
||||
@@ -72,7 +72,7 @@ public class ControllerPreAuthenticatedSecurityHeaderFilterTest {
|
||||
|
||||
@Test
|
||||
@Description("Tests the filter for issuer hash based authentication with a single known hash")
|
||||
public void testIssuerHashBasedAuthenticationWithSingleKnownHash() {
|
||||
void testIssuerHashBasedAuthenticationWithSingleKnownHash() {
|
||||
final ControllerSecurityToken securityToken = prepareSecurityToken(SINGLE_HASH);
|
||||
// use single known hash
|
||||
when(tenantConfigurationManagementMock.getConfigurationValue(
|
||||
@@ -83,7 +83,7 @@ public class ControllerPreAuthenticatedSecurityHeaderFilterTest {
|
||||
|
||||
@Test
|
||||
@Description("Tests the filter for issuer hash based authentication with multiple known hashes")
|
||||
public void testIssuerHashBasedAuthenticationWithMultipleKnownHashes() {
|
||||
void testIssuerHashBasedAuthenticationWithMultipleKnownHashes() {
|
||||
// use multiple known hashes
|
||||
when(tenantConfigurationManagementMock.getConfigurationValue(
|
||||
TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME, String.class))
|
||||
@@ -95,7 +95,7 @@ public class ControllerPreAuthenticatedSecurityHeaderFilterTest {
|
||||
|
||||
@Test
|
||||
@Description("Tests the filter for issuer hash based authentication with unknown hash")
|
||||
public void testIssuerHashBasedAuthenticationWithUnknownHash() {
|
||||
void testIssuerHashBasedAuthenticationWithUnknownHash() {
|
||||
final ControllerSecurityToken securityToken = prepareSecurityToken(UNKNOWN_HASH);
|
||||
// use single known hash
|
||||
when(tenantConfigurationManagementMock.getConfigurationValue(
|
||||
@@ -106,7 +106,7 @@ public class ControllerPreAuthenticatedSecurityHeaderFilterTest {
|
||||
|
||||
@Test
|
||||
@Description("Tests different values for issuer hash header and inspects the credentials")
|
||||
public void useDifferentValuesForIssuerHashHeader() {
|
||||
void useDifferentValuesForIssuerHashHeader() {
|
||||
final ControllerSecurityToken securityToken1 = prepareSecurityToken(SINGLE_HASH);
|
||||
final ControllerSecurityToken securityToken2 = prepareSecurityToken(SECOND_HASH);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user