Fix sub entity attribute formatting (#1326)
* Fix formatting of the sub entity attribute by verifying the formatting against the sub entity attributes list of the related parent property enum. * Verify action API by target property filter
This commit is contained in:
@@ -60,7 +60,7 @@ public abstract class AbstractFieldNameRSQLVisitor<A extends Enum<A> & FieldName
|
||||
|
||||
for (int i = 1; i < graph.length; i++) {
|
||||
|
||||
final String propertyField = graph[i];
|
||||
final String propertyField = getFormattedSubEntityAttribute(propertyEnum ,graph[i]);
|
||||
fieldNameBuilder.append(FieldNameProvider.SUB_ATTRIBUTE_SEPARATOR).append(propertyField);
|
||||
|
||||
// the key of map is not in the graph
|
||||
@@ -110,6 +110,11 @@ public abstract class AbstractFieldNameRSQLVisitor<A extends Enum<A> & FieldName
|
||||
node.getSelector(), getExpectedFieldList()), rootException);
|
||||
}
|
||||
|
||||
private String getFormattedSubEntityAttribute(final A propertyEnum, final String propertyField) {
|
||||
return propertyEnum.getSubEntityAttributes().stream().filter(attr -> attr.equalsIgnoreCase(propertyField))
|
||||
.findFirst().orElse(propertyField);
|
||||
}
|
||||
|
||||
private List<String> getExpectedFieldList() {
|
||||
final List<String> expectedFieldList = Arrays.stream(fieldNameProvider.getEnumConstants())
|
||||
.filter(enumField -> enumField.getSubEntityAttributes().isEmpty()).map(enumField -> {
|
||||
|
||||
@@ -647,7 +647,14 @@ public class TestdataFactory {
|
||||
*/
|
||||
public Target createTarget(final String controllerId, final String targetName) {
|
||||
final Target target = targetManagement
|
||||
.create(entityFactory.target().create().controllerId(controllerId).name(targetName));
|
||||
.create(entityFactory.target().create().controllerId(controllerId).name(targetName));
|
||||
assertTargetProperlyCreated(target);
|
||||
return target;
|
||||
}
|
||||
|
||||
public Target createTarget(final String controllerId, final String targetName, final String address) {
|
||||
final Target target = targetManagement
|
||||
.create(entityFactory.target().create().controllerId(controllerId).name(targetName).address(address));
|
||||
assertTargetProperlyCreated(target);
|
||||
return target;
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import io.qameta.allure.Description;
|
||||
import io.qameta.allure.Feature;
|
||||
import io.qameta.allure.Step;
|
||||
import io.qameta.allure.Story;
|
||||
|
||||
/**
|
||||
@@ -228,17 +229,29 @@ class MgmtActionResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Description("Verifies that actions can be filtered based on target fields.")
|
||||
void filterActionsByTarget() throws Exception {
|
||||
void filterActionsByTargetProperties() throws Exception {
|
||||
|
||||
// prepare test
|
||||
final Target target = testdataFactory.createTarget("knownTargetId");
|
||||
final Target target = testdataFactory.createTarget("knownTargetId", "knownTargetName", "http://0.0.0.0");
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("");
|
||||
assignDistributionSet(ds, Collections.singletonList(target));
|
||||
|
||||
final String rsqlTargetName = "target.name==knownTargetId";
|
||||
final String rsqlTargetControllerId = "target.controllerId==knownTargetId";
|
||||
final String rsqlTargetName = "target.name==knownTargetName";
|
||||
final String rsqlTargetUpdateStatus = "target.updateStatus==pending";
|
||||
final String rsqlTargetAddress = "target.address==http://0.0.0.0";
|
||||
|
||||
verifyResultsByTargetPropertyFilter(target, ds, rsqlTargetControllerId);
|
||||
verifyResultsByTargetPropertyFilter(target, ds, rsqlTargetName);
|
||||
verifyResultsByTargetPropertyFilter(target, ds, rsqlTargetUpdateStatus);
|
||||
verifyResultsByTargetPropertyFilter(target, ds, rsqlTargetAddress);
|
||||
}
|
||||
|
||||
@Step
|
||||
private void verifyResultsByTargetPropertyFilter(final Target target, final DistributionSet ds,
|
||||
final String rsqlTargetFilter) throws Exception {
|
||||
// pending status one result
|
||||
mvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING + "?q=" + rsqlTargetName)
|
||||
mvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING + "?q=" + rsqlTargetFilter)
|
||||
.param(MgmtRestConstants.REQUEST_PARAMETER_REPRESENTATION_MODE, MgmtRepresentationMode.FULL.toString()))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()).andExpect(jsonPath("total", equalTo(1)))
|
||||
.andExpect(jsonPath("size", equalTo(1)))
|
||||
@@ -403,17 +416,15 @@ class MgmtActionResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
final Long actionId = actions.get(0).getId();
|
||||
|
||||
mvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING + "/" + actionId))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath(JSON_PATH_ACTION_ID, equalTo(actionId.intValue())));
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath(JSON_PATH_ACTION_ID, equalTo(actionId.intValue())));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that NOT_FOUND is returned when there is no such action.")
|
||||
void requestActionThatDoesNotExistsLeadsToNotFound() throws Exception {
|
||||
mvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING + "/" + 101))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isNotFound());
|
||||
mvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING + "/" + 101)).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isNotFound());
|
||||
}
|
||||
|
||||
private List<Action> generateTargetWithTwoUpdatesWithOneOverride(final String knownTargetId) {
|
||||
|
||||
Reference in New Issue
Block a user