Skip to content

Commit

Permalink
DependencyTrack#3470: corrects unit tests following changes in analys…
Browse files Browse the repository at this point in the history
…is comments modifications

Signed-off-by: Sebastien Delcoigne <[email protected]>
  • Loading branch information
sebD committed Mar 14, 2024
1 parent a0efd46 commit 60d749e
Showing 1 changed file with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import alpine.server.filters.AuthorizationFilter;
import net.jcip.annotations.NotThreadSafe;
import org.apache.http.HttpStatus;
import org.assertj.core.api.Condition;
import org.dependencytrack.ResourceTest;
import org.dependencytrack.auth.Permissions;
import org.dependencytrack.model.Analysis;
Expand All @@ -54,13 +55,15 @@
import javax.json.Json;
import javax.json.JsonArray;
import javax.json.JsonObject;
import javax.json.JsonValue;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.time.Duration;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.function.Consumer;

import static org.assertj.core.api.Assertions.assertThat;
import static org.dependencytrack.assertion.Assertions.assertConditionWithTimeout;
Expand Down Expand Up @@ -346,17 +349,32 @@ public void updateAnalysisCreateNewTest() throws Exception {
assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
assertThat(response.getHeaderString(TOTAL_COUNT_HEADER)).isNull();

Condition<String> elfBearer = new Condition<String>() {
public boolean matches(String value) {
return value.contains("toto");
}
};

final JsonObject responseJson = parseJsonObject(response);
assertThat(responseJson).isNotNull();
assertThat(responseJson.getString("analysisState")).isEqualTo(AnalysisState.NOT_AFFECTED.name());
assertThat(responseJson.getString("analysisJustification")).isEqualTo(AnalysisJustification.CODE_NOT_REACHABLE.name());
assertThat(responseJson.getString("analysisResponse")).isEqualTo(AnalysisResponse.WILL_NOT_FIX.name());
assertThat(responseJson.getString("analysisDetails")).isEqualTo("Analysis details here");
assertThat(responseJson.getJsonArray("analysisComments")).hasSize(2);
assertThat(responseJson.getJsonArray("analysisComments")).hasSize(5);
assertThat(responseJson.getJsonArray("analysisComments").getJsonObject(0))
.hasFieldOrPropertyWithValue("comment", Json.createValue("Analysis: NOT_SET → NOT_AFFECTED"))
.hasFieldOrPropertyWithValue("comment", Json.createValue("Analysis: null → NOT_AFFECTED"))
.doesNotContainKey("commenter"); // Not set when authenticating via API key
assertThat(responseJson.getJsonArray("analysisComments").getJsonObject(1))
.hasFieldOrPropertyWithValue("comment", Json.createValue("Justification: null → CODE_NOT_REACHABLE"))
.doesNotContainKey("commenter"); // Not set when authenticating via API key
assertThat(responseJson.getJsonArray("analysisComments").getJsonObject(2))
.hasFieldOrPropertyWithValue("comment", Json.createValue("Vendor Response: null → WILL_NOT_FIX"))
.doesNotContainKey("commenter"); // Not set when authenticating via API key
assertThat(responseJson.getJsonArray("analysisComments").getJsonObject(3))
.hasFieldOrPropertyWithValue("comment", Json.createValue("Details: Analysis details here"))
.doesNotContainKey("commenter"); // Not set when authenticating via API key
assertThat(responseJson.getJsonArray("analysisComments").getJsonObject(4))
.hasFieldOrPropertyWithValue("comment", Json.createValue("Analysis comment here"))
.doesNotContainKey("commenter"); // Not set when authenticating via API key
assertThat(responseJson.getBoolean("isSuppressed")).isTrue();
Expand Down Expand Up @@ -408,7 +426,7 @@ public void updateAnalysisCreateNewWithEmptyRequestTest() throws Exception {
assertThat(responseJson.getString("analysisJustification")).isEqualTo(AnalysisJustification.NOT_SET.name());
assertThat(responseJson.getString("analysisResponse")).isEqualTo(AnalysisResponse.NOT_SET.name());
assertThat(responseJson.getJsonString("analysisDetails")).isNull();
assertThat(responseJson.getJsonArray("analysisComments")).isEmpty();
assertThat(responseJson.getJsonArray("analysisComments")).isNotEmpty();
assertThat(responseJson.getBoolean("isSuppressed")).isFalse();

assertConditionWithTimeout(() -> NOTIFICATIONS.size() == 2, Duration.ofSeconds(5));
Expand Down

0 comments on commit 60d749e

Please sign in to comment.