Skip to content

Commit

Permalink
Remove spring REST doc
Browse files Browse the repository at this point in the history
Since now hawkBit support Swagger and OpenAPI the documentation is built
using redoc based on OpenAPI definitions. Spring REST documentation is
not needed anymore.

Since this Spring REST doc is not needed and it duplicates API
documentation (no single source of truth and hard to maintain) with this
commit it is removed.

Some tests from the Spring REST doc that seems are not covered by the
JUnit of the resource modules are moved in the resource JUnit tests.

Signed-off-by: Marinov Avgustin <[email protected]>
  • Loading branch information
avgustinmm committed Oct 4, 2023
1 parent f632bdd commit 57cdfca
Show file tree
Hide file tree
Showing 66 changed files with 580 additions and 14,434 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,28 @@ void getActionsWithEmptyResult() throws Exception {
.andExpect(jsonPath("content", hasSize(0))).andExpect(jsonPath("total", equalTo(0)));
}

@Test
@Description("Handles the GET request of retrieving a specific action.")
public void getAction() throws Exception {
final String knownTargetId = "targetId";
// prepare ds
final DistributionSet ds = testdataFactory.createDistributionSet();
// rollout
final Target target = testdataFactory.createTarget(knownTargetId);
final Rollout rollout = testdataFactory.createRolloutByVariables("TestRollout", "TestDesc", 1,
"name==" + target.getName(), ds, "50", "5");
rolloutManagement.start(rollout.getId());
rolloutHandler.handleAll();

final List<Action> actions = deploymentManagement.findActionsByTarget(target.getControllerId(), PAGE)
.getContent();
assertThat(actions).hasSize(1);

mvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING + "/{actionId}", actions.get(0).getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
}

@Test
@Description("Verifies paging is respected as expected.")
void getMultipleActionsWithPagingLimitRequestParameter() throws Exception {
Expand Down Expand Up @@ -484,5 +506,4 @@ private static String generateDistributionSetLink(final Action action) {
return "http://localhost" + MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/"
+ action.getDistributionSet().getId();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.springframework.data.domain.PageRequest;
import org.springframework.hateoas.MediaTypes;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MvcResult;

Expand All @@ -84,15 +85,27 @@
public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTest {

@Test
@Description("This test verifies the call of all Software Modules that are assiged to a Distribution Set through the RESTful API.")
public void getSoftwaremodules() throws Exception {
@Description("This test verifies the call of all Software Modules that are assigned to a Distribution Set through the RESTful API.")
public void getSoftwareModules() throws Exception {
// Create DistributionSet with three software modules
final DistributionSet set = testdataFactory.createDistributionSet("SMTest");
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + set.getId() + "/assignedSM"))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(jsonPath("$.size", equalTo(set.getModules().size())));
}

@Test
@Description("Handles the GET request of retrieving assigned software modules of a single distribution set within SP with given page size and offset including sorting by version descending and filter down to all sets which name starts with 'one'.")
public void getSoftwareModulesWithParameters() throws Exception {
final DistributionSet set = testdataFactory.createUpdatedDistributionSet();

// post assignment
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + set.getId() + "/assignedSM")
.param("offset", "1").param("limit", "2").param("sort", "version:DESC").param("q", "name==one*")
.accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON));
}

@Test
@Description("This test verifies the deletion of a assigned Software Module of a Distribution Set can not be achieved when that Distribution Set has been assigned or installed to a target.")
public void deleteFailureWhenDistributionSetInUse() throws Exception {
Expand Down Expand Up @@ -179,7 +192,7 @@ public void assignmentFailureWhenAssigningToUsedDistributionSet() throws Excepti

@Test
@Description("This test verifies the assignment of Software Modules to a Distribution Set through the RESTful API.")
public void assignSoftwaremoduleToDistributionSet() throws Exception {
public void assignSoftwareModuleToDistributionSet() throws Exception {

// create DisSet
final DistributionSet disSet = testdataFactory.createDistributionSetWithNoSoftwareModules("Jupiter", "398,88");
Expand Down Expand Up @@ -242,7 +255,7 @@ public void assignSoftwaremoduleToDistributionSet() throws Exception {

@Test
@Description("This test verifies the removal of Software Modules of a Distribution Set through the RESTful API.")
public void unassignSoftwaremoduleFromDistributionSet() throws Exception {
public void unassignSoftwareModuleFromDistributionSet() throws Exception {

// Create DistributionSet with three software modules
final DistributionSet set = testdataFactory.createDistributionSet("Venus");
Expand Down Expand Up @@ -578,12 +591,28 @@ public void getAssignedTargetsOfDistributionSet() throws Exception {
testdataFactory.createTarget(knownTargetId);
assignDistributionSet(createdDs.getId(), knownTargetId);

mvc.perform(get(
MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/assignedTargets"))
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/assignedTargets"))
.andExpect(status().isOk()).andExpect(jsonPath("$.size", equalTo(1)))
.andExpect(jsonPath("$.content[0].controllerId", equalTo(knownTargetId)));
}

@Test
@Description("Handles the GET request for retrieving assigned targets of a single distribution set with a defined page size and offset, sorted by name in descending order and filtered down to all targets which controllerID starts with 'target'.")
public void getAssignedTargetsOfDistributionSetWithParameters() throws Exception {
final DistributionSet set = testdataFactory.createUpdatedDistributionSet();

assignDistributionSet(set, testdataFactory.createTargets(5, "targetMisc", "Test targets for query"))
.getAssignedEntity();

mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + set.getId() + "/assignedTargets")
.param("offset", "1").param("limit", "2").param("sort", "name:DESC")
.param("q", "controllerId==target*").accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON));

}

@Test
@Description("Ensures that assigned targets of DS are returned as persisted in the repository.")
public void getAssignedTargetsOfDistributionSetIsEmpty() throws Exception {
Expand Down Expand Up @@ -616,6 +645,24 @@ public void getInstalledTargetsOfDistributionSet() throws Exception {
.andExpect(jsonPath("$.content[0].controllerId", equalTo(knownTargetId)));
}

@Test
@Description("Handles the GET request for retrieving installed targets of a single distribution set with a defined page size and offset, sortet by name in descending order and filtered down to all targets which controllerID starts with 'target'.")
public void getInstalledTargetsOfDistributionSetWithParameters() throws Exception {
final DistributionSet set = testdataFactory.createUpdatedDistributionSet();

final List<Target> targets = assignDistributionSet(set,
testdataFactory.createTargets(5, "targetMisc", "Test targets for query")).getAssignedEntity().stream()
.map(Action::getTarget).collect(Collectors.toList());
testdataFactory.sendUpdateActionStatusToTargets(targets, Status.FINISHED, "some message");

mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + set.getId() + "/installedTargets")
.param("offset", "1").param("limit", "2").param("sort", "name:DESC")
.param("q", "controllerId==target*").accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON));
}

@Test
@Description("Ensures that target filters with auto assign DS are returned as persisted in the repository.")
public void getAutoAssignTargetFiltersOfDistributionSet() throws Exception {
Expand All @@ -635,6 +682,22 @@ public void getAutoAssignTargetFiltersOfDistributionSet() throws Exception {
.andExpect(jsonPath("$.content[0].name", equalTo(knownFilterName)));
}

@Test
@Description("Handles the GET request for retrieving assigned target filter queries of a single distribution set with a defined page size and offset, sorted by name in descending order and filtered down to all targets with a name that ends with '1'.")
public void ggetAutoAssignTargetFiltersOfDistributionSetWithParameters() throws Exception {
final DistributionSet set = testdataFactory.createUpdatedDistributionSet();
targetFilterQueryManagement.create(entityFactory.targetFilterQuery().create().name("filter1").query("name==a")
.autoAssignDistributionSet(set));

mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + set.getId() + "/autoAssignTargetFilters")
.param("offset", "1").param("limit", "2").param("sort", "name:DESC").param("q", "name==*1")
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON));

}

@Test
@Description("Ensures that an error is returned when the query is invalid.")
public void getAutoAssignTargetFiltersOfDSWithInvalidFilter() throws Exception {
Expand Down Expand Up @@ -692,7 +755,7 @@ private void prepareTestFilters(final String filterNamePrefix, final Distributio

@Test
@Description("Ensures that DS in repository are listed with proper paging properties.")
public void getDistributionSetsWithoutAddtionalRequestParameters() throws Exception {
public void getDistributionSetsWithoutAdditionalRequestParameters() throws Exception {
final int sets = 5;
createDistributionSetsAlphabetical(sets);
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING)).andDo(MockMvcResultPrinter.print())
Expand Down Expand Up @@ -1184,8 +1247,8 @@ public void deleteMetadataThatDoesNotExistLeadsToNotFound() throws Exception {
}

@Test
@Description("Ensures that a metadata entry selection through API reflectes the repository content.")
public void getSingleMetadata() throws Exception {
@Description("Ensures that a metadata entry selection through API reflects the repository content.")
public void geteMetadataKey() throws Exception {
// prepare and create metadata
final String knownKey = "knownKey";
final String knownValue = "knownValue";
Expand All @@ -1197,9 +1260,28 @@ public void getSingleMetadata() throws Exception {
.andExpect(jsonPath("key", equalTo(knownKey))).andExpect(jsonPath("value", equalTo(knownValue)));
}

@Test
@Description("Get a paged list of meta data for a distribution set with standard page size.")
public void getMetadata() throws Exception {
final int totalMetadata = 4;
final String knownKeyPrefix = "knownKey";
final String knownValuePrefix = "knownValue";
final DistributionSet testDS = testdataFactory.createDistributionSet("one");
for (int index = 0; index < totalMetadata; index++) {
distributionSetManagement.createMetaData(testDS.getId(), Lists
.newArrayList(entityFactory.generateDsMetadata(knownKeyPrefix + index, knownValuePrefix + index)));
}

mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{distributionSetId}/metadata",
testDS.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaTypes.HAL_JSON));
}

@Test
@Description("Ensures that a metadata entry paged list selection through API reflectes the repository content.")
public void getPagedListofMetadata() throws Exception {
public void getPagedListOfMetadata() throws Exception {

final int totalMetadata = 10;
final int limitParam = 5;
Expand Down Expand Up @@ -1366,7 +1448,7 @@ private static Stream<Arguments> confirmationOptions() {

@Test
@Description("A request for assigning a target multiple times results in a Bad Request when multiassignment is disabled.")
public void multiassignmentRequestNotAllowedIfDisabled() throws Exception {
public void multiAssignmentRequestNotAllowedIfDisabled() throws Exception {
final String targetId = testdataFactory.createTarget().getControllerId();
final Long dsId = testdataFactory.createDistributionSet().getId();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,19 @@ public void getDistributionSetTags() throws Exception {
}

@Test
@Description("Verfies that a paged result list of DS tags reflects the content on the repository side when filtered by distribution set id.")
@Description("Handles the GET request of retrieving all distribution set tags based by parameter")
public void getDistributionSetTagsWithParameters() throws Exception {
final List<DistributionSetTag> tags = testdataFactory.createDistributionSetTags(2);
final DistributionSetTag assigned = tags.get(0);
final DistributionSetTag unassigned = tags.get(1);
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING
+ "?limit=10&sort=name:ASC&offset=0&q=name==DsTag"))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
}

@Test
@Description("Verifies that a paged result list of DS tags reflects the content on the repository side when filtered by distribution set id.")
public void getDistributionSetTagsByDistributionSetId() throws Exception {
final List<DistributionSetTag> tags = testdataFactory.createDistributionSetTags(2);
final DistributionSetTag tag1 = tags.get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,15 @@ public void getDistributionSetType() throws Exception {
.andExpect(jsonPath("$.deleted", equalTo(testType.isDeleted())));
}

@Test
@Description("Handles the GET request of retrieving all distribution set types within SP based on parameter.")
public void getDistributionSetTypesWithParameter() throws Exception {
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_REQUEST_MAPPING
+ "?limit=10&sort=name:ASC&offset=0&q=name==a"))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
}

@Test
@WithUser(principal = "uploadTester", allSpPermissions = true)
@Description("Checks the correct behaviour of /rest/v1/DistributionSetTypes/{ID} DELETE requests (hard delete scenario).")
Expand Down Expand Up @@ -498,6 +507,22 @@ public void updateDistributionSetTypeColourDescriptionAndNameUntouched() throws
.andExpect(jsonPath("$.name", equalTo("TestName123"))).andReturn();
}

@Test
@Description("Handles the PUT request for a single distribution set type within SP.")
public void updateDistributionSetTypeDescriptionAndColor() throws Exception {
final DistributionSetType testType = distributionSetTypeManagement.update(entityFactory.distributionSetType()
.update(testdataFactory.createDistributionSet().getType().getId()).description("Desc1234"));
final String body = new JSONObject()
.put("description", "an updated description")
.put("colour", "rgb(106,178,83)").toString();

mvc
.perform(put(MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_REQUEST_MAPPING + "/{distributionSetTypeId}",
testType.getId()).content(body).contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print());

}

@Test
@Description("Tests the update of the deletion flag. It is verfied that the distribution set type can't be marked as deleted through update operation.")
public void updateDistributionSetTypeDeletedFlag() throws Exception {
Expand Down
Loading

0 comments on commit 57cdfca

Please sign in to comment.