Skip to content

Commit

Permalink
Merge pull request #3691 from aravindparappil46/feature/844-version-d…
Browse files Browse the repository at this point in the history
…ropdown-inactives

Add active Field To Project Versions
  • Loading branch information
nscuro authored May 12, 2024
2 parents e6999fd + 14fa2eb commit 2b9a0a8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 35 deletions.
35 changes: 1 addition & 34 deletions src/main/java/org/dependencytrack/model/ProjectVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,5 @@
* Value object holding UUID and version for a project
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ProjectVersion implements Serializable {

private static final long serialVersionUID = 1L;

private UUID uuid;

private String version;

public ProjectVersion() {
this.uuid = null;
this.version = null;
}

public ProjectVersion(UUID uuid, String version) {
this.uuid = uuid;
this.version = version;

}

public void setUuid(UUID uuid) {
this.uuid = uuid;
}

public UUID getUuid() {
return uuid;
}

public void setVersion(String version) {
this.version = version;
}

public String getVersion() {
return version;
}
public record ProjectVersion(UUID uuid, String version, Boolean active) implements Serializable {
}
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ private List<ProjectVersion> getProjectVersions(Project project) {
final Query<Project> query = pm.newQuery(Project.class);
query.setFilter("name == :name");
query.setParameters(project.getName());
query.setResult("uuid, version");
query.setResult("uuid, version, active");
return query.executeResultList(ProjectVersion.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,36 @@ public void getProjectByUuidTest() {
Assert.assertEquals("1.0", json.getJsonArray("versions").getJsonObject(0).getJsonString("version").getString());
}

@Test
public void validateProjectVersionsActiveInactiveTest() {
Project project = qm.createProject("ABC", null, "1.0", null, null, null, true, false);
qm.createProject("ABC", null, "2.0", null, null, null, false, false);
qm.createProject("ABC", null, "3.0", null, null, null, true, false);

Response response = jersey.target(V1_PROJECT + "/" + project.getUuid())
.request()
.header(X_API_KEY, apiKey)
.get(Response.class);

Assert.assertEquals(200, response.getStatus(), 0);
JsonObject json = parseJsonObject(response);
Assert.assertNotNull(json);
Assert.assertEquals("ABC", json.getString("name"));
Assert.assertEquals(3, json.getJsonArray("versions").size());

Assert.assertNotNull(json.getJsonArray("versions").getJsonObject(0).getJsonString("uuid").getString());
Assert.assertEquals("1.0", json.getJsonArray("versions").getJsonObject(0).getJsonString("version").getString());
Assert.assertTrue(json.getJsonArray("versions").getJsonObject(0).getBoolean("active"));

Assert.assertNotNull(json.getJsonArray("versions").getJsonObject(1).getJsonString("uuid").getString());
Assert.assertEquals("2.0", json.getJsonArray("versions").getJsonObject(1).getJsonString("version").getString());
Assert.assertFalse(json.getJsonArray("versions").getJsonObject(1).getBoolean("active"));

Assert.assertNotNull(json.getJsonArray("versions").getJsonObject(2).getJsonString("uuid").getString());
Assert.assertEquals("3.0", json.getJsonArray("versions").getJsonObject(2).getJsonString("version").getString());
Assert.assertTrue(json.getJsonArray("versions").getJsonObject(2).getBoolean("active"));
}

@Test
public void getProjectByInvalidUuidTest() {
qm.createProject("ABC", null, "1.0", null, null, null, true, false);
Expand Down

0 comments on commit 2b9a0a8

Please sign in to comment.