Create Unit Test for all filter enum field
Signed-off-by: SirWayne <dennis.melzer@bosch-si.com>
This commit is contained in:
@@ -209,7 +209,7 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
*
|
||||
* @see org.springframework.context.EnvironmentAware#setEnvironment(org.
|
||||
* springframework.core.env. Environment)
|
||||
*/
|
||||
@@ -220,12 +220,15 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware {
|
||||
|
||||
@Before
|
||||
public void before() throws Exception {
|
||||
mvc = MockMvcBuilders.webAppContextSetup(context)
|
||||
.addFilter(new DosFilter(100, 10, "127\\.0\\.0\\.1|\\[0:0:0:0:0:0:0:1\\]", "(^192\\.168\\.)",
|
||||
"X-Forwarded-For"))
|
||||
.addFilter(new ExcludePathAwareShallowETagFilter(
|
||||
"/rest/v1/softwaremodules/{smId}/artifacts/{artId}/download", "/*/controller/artifacts/**"))
|
||||
.build();
|
||||
mvc = MockMvcBuilders
|
||||
.webAppContextSetup(context)
|
||||
.addFilter(
|
||||
new DosFilter(100, 10, "127\\.0\\.0\\.1|\\[0:0:0:0:0:0:0:1\\]", "(^192\\.168\\.)",
|
||||
"X-Forwarded-For"))
|
||||
.addFilter(
|
||||
new ExcludePathAwareShallowETagFilter(
|
||||
"/rest/v1/softwaremodules/{smId}/artifacts/{artId}/download",
|
||||
"/*/controller/artifacts/**")).build();
|
||||
|
||||
standardDsType = securityRule.runAsPrivileged(() -> systemManagement.getTenantMetadata().getDefaultDsType());
|
||||
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.rsql;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.eclipse.hawkbit.AbstractIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.ActionFields;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.ActionType;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Slice;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@Features("Component Tests - RSQL filtering")
|
||||
@Stories("RSQL filter actions")
|
||||
public class RSQLActionFieldsTest extends AbstractIntegrationTest {
|
||||
|
||||
private Target target;
|
||||
private Action action;
|
||||
|
||||
@Before
|
||||
public void setupBeforeTest() {
|
||||
target = new Target("targetId123");
|
||||
target.setDescription("targetId123");
|
||||
targetManagement.createTarget(target);
|
||||
action = new Action();
|
||||
action.setActionType(ActionType.SOFT);
|
||||
target.getActions().add(action);
|
||||
action.setTarget(target);
|
||||
actionRepository.save(action);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
final Action newAction = new Action();
|
||||
newAction.setActionType(ActionType.SOFT);
|
||||
newAction.setActive(i % 2 == 0);
|
||||
newAction.setTarget(target);
|
||||
actionRepository.save(newAction);
|
||||
target.getActions().add(newAction);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test filter action by id")
|
||||
public void testFilterByParameterId() {
|
||||
assertRSQLQuery(ActionFields.ID.name() + "==" + action.getId(), 1);
|
||||
assertRSQLQuery(ActionFields.ID.name() + "==noExist*", 0);
|
||||
assertRSQLQuery(ActionFields.ID.name() + "=in=(" + action.getId() + ",1000000)", 1);
|
||||
assertRSQLQuery(ActionFields.ID.name() + "=out=(" + action.getId() + ",1000000)", 10);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test action by status")
|
||||
public void testFilterByParameterStatus() {
|
||||
assertRSQLQuery(ActionFields.STATUS.name() + "==pending", 5);
|
||||
assertRSQLQuery(ActionFields.STATUS.name() + "=in=(pending)", 5);
|
||||
assertRSQLQuery(ActionFields.STATUS.name() + "=out=(pending)", 6);
|
||||
|
||||
try {
|
||||
assertRSQLQuery(ActionFields.STATUS.name() + "==true", 5);
|
||||
fail();
|
||||
} catch (final RSQLParameterUnsupportedFieldException e) {
|
||||
}
|
||||
}
|
||||
|
||||
private void assertRSQLQuery(final String rsqlParam, final long expectedEntities) {
|
||||
|
||||
final Specification<Action> parse = RSQLUtility.parse(rsqlParam, ActionFields.class);
|
||||
final Slice<Action> findEnitity = deploymentManagement.findActionsByTarget(parse, target, new PageRequest(0,
|
||||
100));
|
||||
final long countAllEntities = deploymentManagement.countActionsByTarget(parse, target);
|
||||
assertThat(findEnitity).isNotNull();
|
||||
assertThat(countAllEntities).isEqualTo(expectedEntities);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.rsql;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.eclipse.hawkbit.AbstractIntegrationTest;
|
||||
import org.eclipse.hawkbit.TestDataUtil;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetFields;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetMetadata;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@Features("Component Tests - RSQL filtering")
|
||||
@Stories("RSQL filter distribution set")
|
||||
public class RSQLDistributionSetFieldTest extends AbstractIntegrationTest {
|
||||
|
||||
@Before
|
||||
public void seuptBeforeTest() {
|
||||
|
||||
final DistributionSet ds = TestDataUtil.generateDistributionSet("DS", softwareManagement,
|
||||
distributionSetManagement);
|
||||
ds.setDescription("DS");
|
||||
ds.getMetadata().add(new DistributionSetMetadata("metaKey", ds, "metaValue"));
|
||||
distributionSetManagement.updateDistributionSet(ds);
|
||||
|
||||
final DistributionSet ds2 = TestDataUtil.generateDistributionSets("NewDS", 3, softwareManagement,
|
||||
distributionSetManagement).get(0);
|
||||
|
||||
ds2.setDescription("DS2");
|
||||
ds2.getMetadata().add(new DistributionSetMetadata("metaKey", ds2, "value"));
|
||||
distributionSetManagement.updateDistributionSet(ds2);
|
||||
|
||||
final DistributionSetTag targetTag = tagManagement.createDistributionSetTag(new DistributionSetTag("Tag1"));
|
||||
tagManagement.createDistributionSetTag(new DistributionSetTag("Tag2"));
|
||||
tagManagement.createDistributionSetTag(new DistributionSetTag("Tag3"));
|
||||
tagManagement.createDistributionSetTag(new DistributionSetTag("Tag4"));
|
||||
|
||||
distributionSetManagement.assignTag(Arrays.asList(ds.getId(), ds2.getId()), targetTag);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test filter distribution set by id")
|
||||
public void testFilterByParameterId() {
|
||||
assertRSQLQuery(DistributionSetFields.ID.name() + "==*", 4);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test filter distribution set by name")
|
||||
public void testFilterByParameterName() {
|
||||
assertRSQLQuery(DistributionSetFields.NAME.name() + "==DS", 1);
|
||||
assertRSQLQuery(DistributionSetFields.NAME.name() + "==*DS", 4);
|
||||
assertRSQLQuery(DistributionSetFields.NAME.name() + "==noExist*", 0);
|
||||
assertRSQLQuery(DistributionSetFields.NAME.name() + "=in=(DS,notexist)", 1);
|
||||
assertRSQLQuery(DistributionSetFields.NAME.name() + "=out=(DS,notexist)", 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test filter distribution set by description")
|
||||
public void testFilterByParameterDescription() {
|
||||
assertRSQLQuery(DistributionSetFields.DESCRIPTION.name() + "==DS", 1);
|
||||
assertRSQLQuery(DistributionSetFields.DESCRIPTION.name() + "==DS*", 2);
|
||||
assertRSQLQuery(DistributionSetFields.DESCRIPTION.name() + "==noExist*", 0);
|
||||
assertRSQLQuery(DistributionSetFields.DESCRIPTION.name() + "=in=(DS,notexist)", 1);
|
||||
assertRSQLQuery(DistributionSetFields.DESCRIPTION.name() + "=out=(DS,notexist)", 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test filter distribution set by version")
|
||||
public void testFilterByParameterVersion() {
|
||||
assertRSQLQuery(DistributionSetFields.VERSION.name() + "==v1.0", 2);
|
||||
assertRSQLQuery(DistributionSetFields.VERSION.name() + "!=v1.0", 2);
|
||||
assertRSQLQuery(DistributionSetFields.VERSION.name() + "=in=(v1.0,v1.1)", 3);
|
||||
assertRSQLQuery(DistributionSetFields.VERSION.name() + "=out=(v1.0,error)", 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test filter distribution set by complete property")
|
||||
public void testFilterByAttribute() {
|
||||
assertRSQLQuery(DistributionSetFields.COMPLETE.name() + "==true", 4);
|
||||
assertRSQLQuery(DistributionSetFields.COMPLETE.name() + "==noExist*", 0);
|
||||
assertRSQLQuery(DistributionSetFields.COMPLETE.name() + "=in=(true)", 4);
|
||||
assertRSQLQuery(DistributionSetFields.COMPLETE.name() + "=out=(true)", 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test filter distribution set by tag")
|
||||
public void testFilterByTag() {
|
||||
assertRSQLQuery(DistributionSetFields.TAG.name() + "==Tag1", 2);
|
||||
assertRSQLQuery(DistributionSetFields.TAG.name() + "==T*", 2);
|
||||
assertRSQLQuery(DistributionSetFields.TAG.name() + "==noExist*", 0);
|
||||
assertRSQLQuery(DistributionSetFields.TAG.name() + "=in=(Tag1,notexist)", 2);
|
||||
assertRSQLQuery(DistributionSetFields.TAG.name() + "=out=(Tag1,notexist)", 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test filter distribution set by type")
|
||||
public void testFilterByType() {
|
||||
assertRSQLQuery(DistributionSetFields.TYPE.name() + "==ecl_os_app_jvm", 4);
|
||||
assertRSQLQuery(DistributionSetFields.TYPE.name() + "==noExist*", 0);
|
||||
assertRSQLQuery(DistributionSetFields.TYPE.name() + "=in=(ecl_os_app_jvm,ecl)", 4);
|
||||
assertRSQLQuery(DistributionSetFields.TYPE.name() + "=out=(ecl_os_app_jvm)", 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("")
|
||||
public void testFilterByMetadata() {
|
||||
assertRSQLQuery(DistributionSetFields.METADATA.name() + ".metaKey==metaValue", 1);
|
||||
assertRSQLQuery(DistributionSetFields.METADATA.name() + ".metaKey==*v*", 2);
|
||||
assertRSQLQuery(DistributionSetFields.METADATA.name() + ".metaKey==noExist*", 0);
|
||||
assertRSQLQuery(DistributionSetFields.METADATA.name() + ".metaKey=in=(metaValue,notexist)", 1);
|
||||
assertRSQLQuery(DistributionSetFields.METADATA.name() + ".metaKey=out=(metaValue,notexist)", 1);
|
||||
assertRSQLQuery(DistributionSetFields.METADATA.name() + ".notExist==metaValue", 0);
|
||||
|
||||
}
|
||||
|
||||
private void assertRSQLQuery(final String rsqlParam, final long excpectedEntity) {
|
||||
final Page<DistributionSet> find = distributionSetManagement.findDistributionSetsAll(
|
||||
RSQLUtility.parse(rsqlParam, DistributionSetFields.class), new PageRequest(0, 100), false);
|
||||
final long countAll = find.getTotalElements();
|
||||
assertThat(find).isNotNull();
|
||||
assertThat(countAll).isEqualTo(excpectedEntity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.rsql;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import org.eclipse.hawkbit.AbstractIntegrationTest;
|
||||
import org.eclipse.hawkbit.TestDataUtil;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetMetadataFields;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetMetadata;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@Features("Component Tests - RSQL filtering")
|
||||
@Stories("RSQL filter distribution set metadata")
|
||||
public class RSQLDistributionSetMetadataFieldsTest extends AbstractIntegrationTest {
|
||||
|
||||
private Long distributionSetId;
|
||||
|
||||
@Before
|
||||
public void setupBeforeTest() {
|
||||
final DistributionSet distributionSet = TestDataUtil.generateDistributionSet("DS", softwareManagement,
|
||||
distributionSetManagement);
|
||||
distributionSetId = distributionSet.getId();
|
||||
for (int i = 0; i < 5; i++) {
|
||||
final DistributionSetMetadata distributionSetMetadata = new DistributionSetMetadata("" + i,
|
||||
distributionSet, "" + i);
|
||||
distributionSet.getMetadata().add(distributionSetMetadata);
|
||||
}
|
||||
|
||||
distributionSetManagement.updateDistributionSet(distributionSet);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test filter distribution set metadata by key")
|
||||
public void testFilterByParameterKey() {
|
||||
assertRSQLQuery(DistributionSetMetadataFields.KEY.name() + "==1", 1);
|
||||
assertRSQLQuery(DistributionSetMetadataFields.KEY.name() + "!=1", 4);
|
||||
assertRSQLQuery(DistributionSetMetadataFields.KEY.name() + "=in=(1,2)", 2);
|
||||
assertRSQLQuery(DistributionSetMetadataFields.KEY.name() + "=out=(1,2)", 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test filter distribution set metadata by value")
|
||||
public void testFilterByParameterValue() {
|
||||
assertRSQLQuery(DistributionSetMetadataFields.VALUE.name() + "==1", 1);
|
||||
assertRSQLQuery(DistributionSetMetadataFields.VALUE.name() + "!=1", 4);
|
||||
assertRSQLQuery(DistributionSetMetadataFields.VALUE.name() + "=in=(1,2)", 2);
|
||||
assertRSQLQuery(DistributionSetMetadataFields.VALUE.name() + "=out=(1,2)", 3);
|
||||
}
|
||||
|
||||
private void assertRSQLQuery(final String rsqlParam, final long expectedEntities) {
|
||||
|
||||
final Page<DistributionSetMetadata> findEnitity = distributionSetManagement
|
||||
.findDistributionSetMetadataByDistributionSetId(distributionSetId,
|
||||
RSQLUtility.parse(rsqlParam, DistributionSetMetadataFields.class), new PageRequest(0, 100));
|
||||
final long countAllEntities = findEnitity.getTotalElements();
|
||||
assertThat(findEnitity).isNotNull();
|
||||
assertThat(countAllEntities).isEqualTo(expectedEntities);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.rsql;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import org.eclipse.hawkbit.AbstractIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleFields;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@Features("Component Tests - RSQL filtering")
|
||||
@Stories("RSQL filter software module")
|
||||
public class RSQLSoftwareModuleFieldTest extends AbstractIntegrationTest {
|
||||
|
||||
@Before
|
||||
public void seuptBeforeTest() {
|
||||
|
||||
final SoftwareModule ah = softwareManagement.createSoftwareModule(new SoftwareModule(appType, "agent-hub",
|
||||
"1.0.1", "agent-hub", ""));
|
||||
softwareManagement.createSoftwareModule(new SoftwareModule(runtimeType, "oracle-jre", "1.7.2", "aa", ""));
|
||||
softwareManagement.createSoftwareModule(new SoftwareModule(osType, "poky", "3.0.2", "aa", ""));
|
||||
|
||||
final SoftwareModule ah2 = softwareManagement.createSoftwareModule(new SoftwareModule(appType, "agent-hub2",
|
||||
"1.0.1", "agent-hub2", ""));
|
||||
|
||||
final SoftwareModuleMetadata softwareModuleMetadata = new SoftwareModuleMetadata("metaKey", ah, "metaValue");
|
||||
softwareManagement.createSoftwareModuleMetadata(softwareModuleMetadata);
|
||||
ah.getMetadata().add(softwareModuleMetadata);
|
||||
softwareManagement.updateSoftwareModule(ah);
|
||||
|
||||
final SoftwareModuleMetadata softwareModuleMetadata2 = new SoftwareModuleMetadata("metaKey", ah2, "value");
|
||||
softwareManagement.createSoftwareModuleMetadata(softwareModuleMetadata2);
|
||||
ah2.getMetadata().add(softwareModuleMetadata2);
|
||||
softwareManagement.updateSoftwareModule(ah2);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test filter software module by id")
|
||||
public void testFilterByParameterId() {
|
||||
assertRSQLQuery(SoftwareModuleFields.ID.name() + "==*", 4);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test filter software module by name")
|
||||
public void testFilterByParameterName() {
|
||||
assertRSQLQuery(SoftwareModuleFields.NAME.name() + "==agent-hub", 1);
|
||||
assertRSQLQuery(SoftwareModuleFields.NAME.name() + "==agent-hub*", 2);
|
||||
assertRSQLQuery(SoftwareModuleFields.NAME.name() + "==noExist*", 0);
|
||||
assertRSQLQuery(SoftwareModuleFields.NAME.name() + "=in=(agent-hub,notexist)", 1);
|
||||
assertRSQLQuery(SoftwareModuleFields.NAME.name() + "=out=(agent-hub,notexist)", 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test filter software module by description")
|
||||
public void testFilterByParameterDescription() {
|
||||
assertRSQLQuery(SoftwareModuleFields.DESCRIPTION.name() + "==agent-hub", 1);
|
||||
assertRSQLQuery(SoftwareModuleFields.DESCRIPTION.name() + "==noExist*", 0);
|
||||
assertRSQLQuery(SoftwareModuleFields.DESCRIPTION.name() + "=in=(agent-hub,notexist)", 1);
|
||||
assertRSQLQuery(SoftwareModuleFields.DESCRIPTION.name() + "=out=(agent-hub,notexist)", 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test filter software module by version")
|
||||
public void testFilterByParameterVersion() {
|
||||
assertRSQLQuery(SoftwareModuleFields.VERSION.name() + "==1.0.1", 2);
|
||||
assertRSQLQuery(SoftwareModuleFields.VERSION.name() + "!=v1.0", 4);
|
||||
assertRSQLQuery(SoftwareModuleFields.VERSION.name() + "=in=(1.0.1,1.0.2)", 2);
|
||||
assertRSQLQuery(SoftwareModuleFields.VERSION.name() + "=out=(1.0.1)", 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test filter software module by type")
|
||||
public void testFilterByType() {
|
||||
assertRSQLQuery(SoftwareModuleFields.TYPE.name() + "==application", 2);
|
||||
assertRSQLQuery(SoftwareModuleFields.TYPE.name() + "==noExist*", 0);
|
||||
assertRSQLQuery(SoftwareModuleFields.TYPE.name() + "=in=(application)", 2);
|
||||
assertRSQLQuery(SoftwareModuleFields.TYPE.name() + "=out=(application)", 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("")
|
||||
public void testFilterByMetadata() {
|
||||
assertRSQLQuery(SoftwareModuleFields.METADATA.name() + ".metaKey==metaValue", 1);
|
||||
assertRSQLQuery(SoftwareModuleFields.METADATA.name() + ".metaKey==*v*", 2);
|
||||
assertRSQLQuery(SoftwareModuleFields.METADATA.name() + ".metaKey==noExist*", 0);
|
||||
assertRSQLQuery(SoftwareModuleFields.METADATA.name() + ".metaKey=in=(metaValue,notexist)", 1);
|
||||
assertRSQLQuery(SoftwareModuleFields.METADATA.name() + ".metaKey=out=(metaValue,notexist)", 1);
|
||||
assertRSQLQuery(SoftwareModuleFields.METADATA.name() + ".notExist==metaValue", 0);
|
||||
|
||||
}
|
||||
|
||||
private void assertRSQLQuery(final String rsqlParam, final long excpectedEntity) {
|
||||
final Page<SoftwareModule> find = softwareManagement.findSoftwareModulesByPredicate(
|
||||
RSQLUtility.parse(rsqlParam, SoftwareModuleFields.class), new PageRequest(0, 100));
|
||||
final long countAll = find.getTotalElements();
|
||||
assertThat(find).isNotNull();
|
||||
assertThat(countAll).isEqualTo(excpectedEntity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.rsql;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import org.eclipse.hawkbit.AbstractIntegrationTest;
|
||||
import org.eclipse.hawkbit.TestDataUtil;
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleMetadataFields;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@Features("Component Tests - RSQL filtering")
|
||||
@Stories("RSQL filter software module metadata")
|
||||
public class RSQLSoftwareModuleMetadataFieldsTest extends AbstractIntegrationTest {
|
||||
|
||||
private Long softwareModuleId;
|
||||
|
||||
@Before
|
||||
public void setupBeforeTest() {
|
||||
final SoftwareModule softwareModule = softwareManagement.createSoftwareModule(new SoftwareModule(TestDataUtil
|
||||
.findOrCreateSoftwareModuleType(softwareManagement, "application"), "application", "1.0.0", "Desc",
|
||||
"vendor Limited, California"));
|
||||
softwareModuleId = softwareModule.getId();
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
final SoftwareModuleMetadata metadata = new SoftwareModuleMetadata("" + i, softwareModule, "" + i);
|
||||
softwareModule.getMetadata().add(metadata);
|
||||
softwareModuleMetadataRepository.save(metadata);
|
||||
}
|
||||
|
||||
softwareManagement.updateSoftwareModule(softwareModule);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test filter software module metadata by key")
|
||||
public void testFilterByParameterKey() {
|
||||
assertRSQLQuery(SoftwareModuleMetadataFields.KEY.name() + "==1", 1);
|
||||
assertRSQLQuery(SoftwareModuleMetadataFields.KEY.name() + "!=1", 4);
|
||||
assertRSQLQuery(SoftwareModuleMetadataFields.KEY.name() + "=in=(1,2)", 2);
|
||||
assertRSQLQuery(SoftwareModuleMetadataFields.KEY.name() + "=out=(1,2)", 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test fitler software module metadata status by value")
|
||||
public void testFilterByParameterValue() {
|
||||
assertRSQLQuery(SoftwareModuleMetadataFields.VALUE.name() + "==1", 1);
|
||||
assertRSQLQuery(SoftwareModuleMetadataFields.VALUE.name() + "!=1", 4);
|
||||
assertRSQLQuery(SoftwareModuleMetadataFields.VALUE.name() + "=in=(1,2)", 2);
|
||||
assertRSQLQuery(SoftwareModuleMetadataFields.VALUE.name() + "=out=(1,2)", 3);
|
||||
}
|
||||
|
||||
private void assertRSQLQuery(final String rsqlParam, final long expectedEntities) {
|
||||
|
||||
final Page<SoftwareModuleMetadata> findEnitity = softwareManagement
|
||||
.findSoftwareModuleMetadataBySoftwareModuleId(softwareModuleId,
|
||||
RSQLUtility.parse(rsqlParam, SoftwareModuleMetadataFields.class), new PageRequest(0, 100));
|
||||
final long countAllEntities = findEnitity.getTotalElements();
|
||||
assertThat(findEnitity).isNotNull();
|
||||
assertThat(countAllEntities).isEqualTo(expectedEntities);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.rsql;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import org.eclipse.hawkbit.AbstractIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleTypeFields;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@Features("Component Tests - RSQL filtering")
|
||||
@Stories("RSQL filter software module test type")
|
||||
public class RSQLSoftwareModuleTypeFieldsTest extends AbstractIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Description("Test filter software module test type by id")
|
||||
public void testFilterByParameterId() {
|
||||
assertRSQLQuery(SoftwareModuleTypeFields.ID.name() + "==*", 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test filter software module test type by name")
|
||||
public void testFilterByParameterName() {
|
||||
assertRSQLQuery(SoftwareModuleTypeFields.NAME.name() + "==ECL*", 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test filter software module test type by description")
|
||||
public void testFilterByParameterDescription() {
|
||||
assertRSQLQuery(SoftwareModuleTypeFields.DESCRIPTION.name() + "==Updated*", 3);
|
||||
assertRSQLQuery(SoftwareModuleTypeFields.DESCRIPTION.name() + "==noExist*", 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test filter software module test type by key")
|
||||
public void testFilterByParameterKey() {
|
||||
assertRSQLQuery(SoftwareModuleTypeFields.KEY.name() + "==os", 1);
|
||||
assertRSQLQuery(SoftwareModuleTypeFields.KEY.name() + "=in=(os)", 1);
|
||||
assertRSQLQuery(SoftwareModuleTypeFields.KEY.name() + "=out=(os)", 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test filter software module test type by max")
|
||||
public void testFilterByMaxAssignment() {
|
||||
assertRSQLQuery(SoftwareModuleTypeFields.MAX.name() + "==1", 3);
|
||||
}
|
||||
|
||||
private void assertRSQLQuery(final String rsqlParam, final long excpectedEntity) {
|
||||
final Page<SoftwareModuleType> find = softwareManagement.findSoftwareModuleTypesByPredicate(
|
||||
RSQLUtility.parse(rsqlParam, SoftwareModuleTypeFields.class), new PageRequest(0, 100));
|
||||
final long countAll = find.getTotalElements();
|
||||
assertThat(find).isNotNull();
|
||||
assertThat(countAll).isEqualTo(excpectedEntity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.rsql;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import org.eclipse.hawkbit.AbstractIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.TagFields;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@Features("Component Tests - RSQL filtering")
|
||||
@Stories("RSQL filter target and distribution set tags")
|
||||
public class RSQLTagFieldsTest extends AbstractIntegrationTest {
|
||||
|
||||
@Before
|
||||
public void seuptBeforeTest() {
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
final TargetTag targetTag = new TargetTag("" + i, "" + i, i % 2 == 0 ? "red" : "blue");
|
||||
tagManagement.createTargetTag(targetTag);
|
||||
final DistributionSetTag distributionSetTag = new DistributionSetTag("" + i, "" + i, i % 2 == 0 ? "red"
|
||||
: "blue");
|
||||
tagManagement.createDistributionSetTag(distributionSetTag);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test filter target tag by name")
|
||||
public void testFilterTargetTagByParameterName() {
|
||||
assertRSQLQueryTarget(TagFields.NAME.name() + "==1", 1);
|
||||
assertRSQLQueryTarget(TagFields.NAME.name() + "==*", 5);
|
||||
assertRSQLQueryTarget(TagFields.NAME.name() + "==noExist*", 0);
|
||||
assertRSQLQueryTarget(TagFields.NAME.name() + "=in=(1,notexist)", 1);
|
||||
assertRSQLQueryTarget(TagFields.NAME.name() + "=out=(1,notexist)", 4);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test filter target tag by description")
|
||||
public void testFilterTargetTagByParameterDescription() {
|
||||
assertRSQLQueryTarget(TagFields.DESCRIPTION.name() + "==1", 1);
|
||||
assertRSQLQueryTarget(TagFields.DESCRIPTION.name() + "==*", 5);
|
||||
assertRSQLQueryTarget(TagFields.DESCRIPTION.name() + "==noExist*", 0);
|
||||
assertRSQLQueryTarget(TagFields.DESCRIPTION.name() + "=in=(1,notexist)", 1);
|
||||
assertRSQLQueryTarget(TagFields.DESCRIPTION.name() + "=out=(1,notexist)", 4);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test filter target tag by colour")
|
||||
public void testFilterTargetTagByParameterColour() {
|
||||
assertRSQLQueryTarget(TagFields.COLOUR.name() + "==red", 3);
|
||||
assertRSQLQueryTarget(TagFields.COLOUR.name() + "==r*", 3);
|
||||
assertRSQLQueryTarget(TagFields.COLOUR.name() + "==noExist*", 0);
|
||||
assertRSQLQueryTarget(TagFields.COLOUR.name() + "=in=(red,notexist)", 3);
|
||||
assertRSQLQueryTarget(TagFields.COLOUR.name() + "=out=(red,notexist)", 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test filter distribution set tag by name")
|
||||
public void testFilterDistributionSetTagByParameterName() {
|
||||
assertRSQLQueryDistributionSet(TagFields.NAME.name() + "==1", 1);
|
||||
assertRSQLQueryDistributionSet(TagFields.NAME.name() + "==*", 5);
|
||||
assertRSQLQueryDistributionSet(TagFields.NAME.name() + "==noExist*", 0);
|
||||
assertRSQLQueryDistributionSet(TagFields.NAME.name() + "=in=(1,2)", 2);
|
||||
assertRSQLQueryDistributionSet(TagFields.NAME.name() + "=out=(1,2)", 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test filter distribution set by description")
|
||||
public void testFilterDistributionSetTagByParameterDescription() {
|
||||
assertRSQLQueryDistributionSet(TagFields.DESCRIPTION.name() + "==1", 1);
|
||||
assertRSQLQueryDistributionSet(TagFields.DESCRIPTION.name() + "==*", 5);
|
||||
assertRSQLQueryDistributionSet(TagFields.DESCRIPTION.name() + "==noExist*", 0);
|
||||
assertRSQLQueryDistributionSet(TagFields.DESCRIPTION.name() + "=in=(1,2)", 2);
|
||||
assertRSQLQueryDistributionSet(TagFields.DESCRIPTION.name() + "=out=(1,2)", 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test filter distribution set by colour")
|
||||
public void testFilterDistributionSetTagByParameterColour() {
|
||||
assertRSQLQueryDistributionSet(TagFields.COLOUR.name() + "==red", 3);
|
||||
assertRSQLQueryDistributionSet(TagFields.COLOUR.name() + "==r*", 3);
|
||||
assertRSQLQueryDistributionSet(TagFields.COLOUR.name() + "==noExist*", 0);
|
||||
assertRSQLQueryDistributionSet(TagFields.COLOUR.name() + "=in=(red,notexist)", 3);
|
||||
assertRSQLQueryDistributionSet(TagFields.COLOUR.name() + "=out=(red,notexist)", 2);
|
||||
}
|
||||
|
||||
private void assertRSQLQueryDistributionSet(final String rsqlParam, final long expectedEntities) {
|
||||
|
||||
final Page<DistributionSetTag> findEnitity = tagManagement.findAllDistributionSetTags(
|
||||
RSQLUtility.parse(rsqlParam, TagFields.class), new PageRequest(0, 100));
|
||||
final long countAllEntities = findEnitity.getTotalElements();
|
||||
assertThat(findEnitity).isNotNull();
|
||||
assertThat(countAllEntities).isEqualTo(expectedEntities);
|
||||
}
|
||||
|
||||
private void assertRSQLQueryTarget(final String rsqlParam, final long expectedEntities) {
|
||||
|
||||
final Page<TargetTag> findEnitity = tagManagement.findAllTargetTags(
|
||||
RSQLUtility.parse(rsqlParam, TagFields.class), new PageRequest(0, 100));
|
||||
final long countAllEntities = findEnitity.getTotalElements();
|
||||
assertThat(findEnitity).isNotNull();
|
||||
assertThat(countAllEntities).isEqualTo(expectedEntities);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.rsql;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.eclipse.hawkbit.AbstractIntegrationTest;
|
||||
import org.eclipse.hawkbit.TestDataUtil;
|
||||
import org.eclipse.hawkbit.repository.TargetFields;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetInfo;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@Features("Component Tests - RSQL filtering")
|
||||
@Stories("RSQL filter target")
|
||||
public class RSQLTargetFieldTest extends AbstractIntegrationTest {
|
||||
|
||||
@Before
|
||||
public void seuptBeforeTest() {
|
||||
|
||||
final DistributionSet ds = TestDataUtil.generateDistributionSet("AssignedDs", softwareManagement,
|
||||
distributionSetManagement);
|
||||
|
||||
final Target target = new Target("targetId123");
|
||||
target.setDescription("targetId123");
|
||||
final TargetInfo targetInfo = new TargetInfo(target);
|
||||
targetInfo.getControllerAttributes().put("revision", "1.1");
|
||||
target.setTargetInfo(targetInfo);
|
||||
target.getTargetInfo().setUpdateStatus(TargetUpdateStatus.PENDING);
|
||||
|
||||
targetManagement.createTarget(target);
|
||||
final Target target2 = new Target("targetId1234");
|
||||
target2.setDescription("targetId1234");
|
||||
final TargetInfo targetInfo2 = new TargetInfo(target2);
|
||||
targetInfo2.getControllerAttributes().put("revision", "1.2");
|
||||
target2.setTargetInfo(targetInfo2);
|
||||
targetManagement.createTarget(target2);
|
||||
targetManagement.createTarget(new Target("targetId1235"));
|
||||
targetManagement.createTarget(new Target("targetId1236"));
|
||||
|
||||
final TargetTag targetTag = tagManagement.createTargetTag(new TargetTag("Tag1"));
|
||||
tagManagement.createTargetTag(new TargetTag("Tag2"));
|
||||
tagManagement.createTargetTag(new TargetTag("Tag3"));
|
||||
tagManagement.createTargetTag(new TargetTag("Tag4"));
|
||||
|
||||
targetManagement.assignTag(Arrays.asList(target.getControllerId(), target2.getControllerId()), targetTag);
|
||||
|
||||
deploymentManagement.assignDistributionSet(ds.getId(), target.getControllerId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test filter target by (controller) id")
|
||||
public void testFilterByParameterId() {
|
||||
assertRSQLQuery(TargetFields.ID.name() + "==targetId123", 1);
|
||||
assertRSQLQuery(TargetFields.ID.name() + "==target*", 4);
|
||||
assertRSQLQuery(TargetFields.ID.name() + "==noExist*", 0);
|
||||
assertRSQLQuery(TargetFields.ID.name() + "=in=(targetId123,notexist)", 1);
|
||||
assertRSQLQuery(TargetFields.ID.name() + "=out=(targetId123,notexist)", 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test filter target by name")
|
||||
public void testFilterByParameterName() {
|
||||
assertRSQLQuery(TargetFields.NAME.name() + "==targetId123", 1);
|
||||
assertRSQLQuery(TargetFields.NAME.name() + "==target*", 4);
|
||||
assertRSQLQuery(TargetFields.NAME.name() + "==noExist*", 0);
|
||||
assertRSQLQuery(TargetFields.NAME.name() + "=in=(targetId123,notexist)", 1);
|
||||
assertRSQLQuery(TargetFields.NAME.name() + "=out=(targetId123,notexist)", 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test filter target by description")
|
||||
public void testFilterByParameterDescription() {
|
||||
assertRSQLQuery(TargetFields.DESCRIPTION.name() + "==targetId123", 1);
|
||||
assertRSQLQuery(TargetFields.DESCRIPTION.name() + "==target*", 2);
|
||||
assertRSQLQuery(TargetFields.DESCRIPTION.name() + "==noExist*", 0);
|
||||
assertRSQLQuery(TargetFields.DESCRIPTION.name() + "=in=(targetId123,notexist)", 1);
|
||||
assertRSQLQuery(TargetFields.DESCRIPTION.name() + "=out=(targetId123,notexist)", 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test filter target by controller id")
|
||||
public void testFilterByParameterControllerId() {
|
||||
assertRSQLQuery(TargetFields.CONTROLLERID.name() + "==targetId123", 1);
|
||||
assertRSQLQuery(TargetFields.CONTROLLERID.name() + "==target*", 4);
|
||||
assertRSQLQuery(TargetFields.CONTROLLERID.name() + "==noExist*", 0);
|
||||
assertRSQLQuery(TargetFields.CONTROLLERID.name() + "=in=(targetId123,notexist)", 1);
|
||||
assertRSQLQuery(TargetFields.CONTROLLERID.name() + "=out=(targetId123,notexist)", 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test filter target by status")
|
||||
public void testFilterByParameterUpdateStatus() {
|
||||
assertRSQLQuery(TargetFields.UPDATESTATUS.name() + "==pending", 1);
|
||||
assertRSQLQuery(TargetFields.UPDATESTATUS.name() + "!=pending", 3);
|
||||
try {
|
||||
assertRSQLQuery(TargetFields.UPDATESTATUS.name() + "==noExist*", 0);
|
||||
fail();
|
||||
} catch (final RSQLParameterUnsupportedFieldException e) {
|
||||
}
|
||||
assertRSQLQuery(TargetFields.UPDATESTATUS.name() + "=in=(pending,error)", 1);
|
||||
assertRSQLQuery(TargetFields.UPDATESTATUS.name() + "=out=(pending,error)", 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test filter target by attribute")
|
||||
public void testFilterByAttribute() {
|
||||
assertRSQLQuery(TargetFields.ATTRIBUTE.name() + ".revision==1.1", 1);
|
||||
assertRSQLQuery(TargetFields.ATTRIBUTE.name() + ".revision==1*", 2);
|
||||
assertRSQLQuery(TargetFields.ATTRIBUTE.name() + ".revision==noExist*", 0);
|
||||
assertRSQLQuery(TargetFields.ATTRIBUTE.name() + ".revision=in=(1.1,notexist)", 1);
|
||||
assertRSQLQuery(TargetFields.ATTRIBUTE.name() + ".revision=out=(1.1)", 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test filter target by assigned ds name")
|
||||
public void testFilterByAssignedDsName() {
|
||||
assertRSQLQuery(TargetFields.ASSIGNEDDS.name() + ".name==AssignedDs", 1);
|
||||
assertRSQLQuery(TargetFields.ASSIGNEDDS.name() + ".name==A*", 1);
|
||||
assertRSQLQuery(TargetFields.ASSIGNEDDS.name() + ".name==noExist*", 0);
|
||||
assertRSQLQuery(TargetFields.ASSIGNEDDS.name() + ".name=in=(AssignedDs,notexist)", 1);
|
||||
assertRSQLQuery(TargetFields.ASSIGNEDDS.name() + ".name=out=(AssignedDs,notexist)", 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test filter target by assigned ds version")
|
||||
public void testFilterByAssignedDsVersion() {
|
||||
assertRSQLQuery(TargetFields.ASSIGNEDDS.name() + ".version==v1.0", 1);
|
||||
assertRSQLQuery(TargetFields.ASSIGNEDDS.name() + ".version==*1*", 1);
|
||||
assertRSQLQuery(TargetFields.ASSIGNEDDS.name() + ".version==noExist*", 0);
|
||||
assertRSQLQuery(TargetFields.ASSIGNEDDS.name() + ".version=in=(v1.0,notexist)", 1);
|
||||
assertRSQLQuery(TargetFields.ASSIGNEDDS.name() + ".version=out=(v1.0,notexist)", 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test filter target by tag")
|
||||
public void testFilterByTag() {
|
||||
assertRSQLQuery(TargetFields.TAG.name() + "==Tag1", 2);
|
||||
assertRSQLQuery(TargetFields.TAG.name() + "==T*", 2);
|
||||
assertRSQLQuery(TargetFields.TAG.name() + "==noExist*", 0);
|
||||
assertRSQLQuery(TargetFields.TAG.name() + "=in=(Tag1,notexist)", 2);
|
||||
assertRSQLQuery(TargetFields.TAG.name() + "=out=(Tag1,notexist)", 0);
|
||||
}
|
||||
|
||||
private void assertRSQLQuery(final String rsqlParam, final long expcetedTargets) {
|
||||
final Page<Target> findTargetPage = targetManagement.findTargetsAll(
|
||||
RSQLUtility.parse(rsqlParam, TargetFields.class), new PageRequest(0, 100));
|
||||
final long countTargetsAll = findTargetPage.getTotalElements();
|
||||
assertThat(findTargetPage).isNotNull();
|
||||
assertThat(countTargetsAll).isEqualTo(expcetedTargets);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,275 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.rsql;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.reset;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Expression;
|
||||
import javax.persistence.criteria.Path;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import javax.persistence.criteria.Root;
|
||||
import javax.persistence.metamodel.Attribute;
|
||||
|
||||
import org.eclipse.hawkbit.repository.DistributionSetFields;
|
||||
import org.eclipse.hawkbit.repository.FieldNameProvider;
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleFields;
|
||||
import org.eclipse.hawkbit.repository.TargetFields;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@Features("Component Tests - RSQL filtering")
|
||||
@Stories("RSQL search utility")
|
||||
// TODO: fully document tests -> @Description for long text and reasonable
|
||||
// method name as short text
|
||||
public class RSQLUtilityTest {
|
||||
|
||||
@Mock
|
||||
private Root<Object> baseSoftwareModuleRootMock;
|
||||
|
||||
@Mock
|
||||
private CriteriaQuery<SoftwareModule> criteriaQueryMock;
|
||||
@Mock
|
||||
private CriteriaBuilder criteriaBuilderMock;
|
||||
|
||||
@Mock
|
||||
private Attribute attribute;
|
||||
|
||||
@Test
|
||||
public void wrongRsqlSyntaxThrowSyntaxException() {
|
||||
final String wrongRSQL = "name==abc;d";
|
||||
try {
|
||||
RSQLUtility.parse(wrongRSQL, SoftwareModuleFields.class).toPredicate(baseSoftwareModuleRootMock,
|
||||
criteriaQueryMock, criteriaBuilderMock);
|
||||
fail();
|
||||
} catch (final RSQLParameterSyntaxException e) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wrongFieldThrowUnsupportedFieldException() {
|
||||
final String wrongRSQL = "unknownField==abc";
|
||||
when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) SoftwareModule.class);
|
||||
try {
|
||||
RSQLUtility.parse(wrongRSQL, SoftwareModuleFields.class).toPredicate(baseSoftwareModuleRootMock,
|
||||
criteriaQueryMock, criteriaBuilderMock);
|
||||
fail();
|
||||
} catch (final RSQLParameterUnsupportedFieldException e) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wrongRsqlMapSyntaxThrowSyntaxException() {
|
||||
String wrongRSQL = TargetFields.ATTRIBUTE + "==abc";
|
||||
try {
|
||||
RSQLUtility.parse(wrongRSQL, TargetFields.class).toPredicate(baseSoftwareModuleRootMock, criteriaQueryMock,
|
||||
criteriaBuilderMock);
|
||||
fail();
|
||||
} catch (final RSQLParameterUnsupportedFieldException e) {
|
||||
}
|
||||
|
||||
wrongRSQL = TargetFields.ATTRIBUTE + ".unkwon.wrong==abc";
|
||||
try {
|
||||
RSQLUtility.parse(wrongRSQL, TargetFields.class).toPredicate(baseSoftwareModuleRootMock, criteriaQueryMock,
|
||||
criteriaBuilderMock);
|
||||
fail();
|
||||
} catch (final RSQLParameterUnsupportedFieldException e) {
|
||||
}
|
||||
|
||||
wrongRSQL = DistributionSetFields.METADATA + "==abc";
|
||||
try {
|
||||
RSQLUtility.parse(wrongRSQL, DistributionSetFields.class).toPredicate(baseSoftwareModuleRootMock,
|
||||
criteriaQueryMock, criteriaBuilderMock);
|
||||
fail();
|
||||
} catch (final RSQLParameterUnsupportedFieldException e) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wrongRsqlSubEntitySyntaxThrowSyntaxException() {
|
||||
String wrongRSQL = TargetFields.ASSIGNEDDS + "==abc";
|
||||
try {
|
||||
RSQLUtility.parse(wrongRSQL, TargetFields.class).toPredicate(baseSoftwareModuleRootMock, criteriaQueryMock,
|
||||
criteriaBuilderMock);
|
||||
fail();
|
||||
} catch (final RSQLParameterUnsupportedFieldException e) {
|
||||
}
|
||||
|
||||
wrongRSQL = TargetFields.ASSIGNEDDS + ".unknownField==abc";
|
||||
try {
|
||||
RSQLUtility.parse(wrongRSQL, TargetFields.class).toPredicate(baseSoftwareModuleRootMock, criteriaQueryMock,
|
||||
criteriaBuilderMock);
|
||||
fail();
|
||||
} catch (final RSQLParameterUnsupportedFieldException e) {
|
||||
}
|
||||
|
||||
wrongRSQL = TargetFields.ASSIGNEDDS + ".unknownField.ToMuch==abc";
|
||||
try {
|
||||
RSQLUtility.parse(wrongRSQL, TargetFields.class).toPredicate(baseSoftwareModuleRootMock, criteriaQueryMock,
|
||||
criteriaBuilderMock);
|
||||
fail();
|
||||
} catch (final RSQLParameterUnsupportedFieldException e) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public <T> void correctRsqlBuildsPredicate() {
|
||||
reset(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock);
|
||||
final String correctRsql = "name==abc;version==1.2";
|
||||
when(baseSoftwareModuleRootMock.get("name")).thenReturn(baseSoftwareModuleRootMock);
|
||||
when(baseSoftwareModuleRootMock.get("version")).thenReturn(baseSoftwareModuleRootMock);
|
||||
when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) SoftwareModule.class);
|
||||
when(criteriaBuilderMock.equal(any(Root.class), anyString())).thenReturn(mock(Predicate.class));
|
||||
when(criteriaBuilderMock.<String> greaterThanOrEqualTo(any(Expression.class), any(String.class))).thenReturn(
|
||||
mock(Predicate.class));
|
||||
|
||||
// test
|
||||
RSQLUtility.parse(correctRsql, SoftwareModuleFields.class).toPredicate(baseSoftwareModuleRootMock,
|
||||
criteriaQueryMock, criteriaBuilderMock);
|
||||
|
||||
// verfication
|
||||
verify(criteriaBuilderMock, times(1)).and(any(Predicate.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void correctRsqlBuildsNotEqualPredicate() {
|
||||
reset(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock);
|
||||
final String correctRsql = "name!=abc";
|
||||
when(baseSoftwareModuleRootMock.get("name")).thenReturn(baseSoftwareModuleRootMock);
|
||||
when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) SoftwareModule.class);
|
||||
when(criteriaBuilderMock.equal(any(Root.class), anyString())).thenReturn(mock(Predicate.class));
|
||||
when(criteriaBuilderMock.<String> greaterThanOrEqualTo(any(Expression.class), any(String.class))).thenReturn(
|
||||
mock(Predicate.class));
|
||||
// test
|
||||
RSQLUtility.parse(correctRsql, SoftwareModuleFields.class).toPredicate(baseSoftwareModuleRootMock,
|
||||
criteriaQueryMock, criteriaBuilderMock);
|
||||
|
||||
// verfication
|
||||
verify(criteriaBuilderMock, times(1)).and(any(Predicate.class));
|
||||
verify(criteriaBuilderMock, times(1)).notEqual(eq(baseSoftwareModuleRootMock), eq("abc"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void correctRsqlBuildsLessThanPredicate() {
|
||||
reset(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock);
|
||||
final String correctRsql = "name=lt=abc";
|
||||
when(baseSoftwareModuleRootMock.get("name")).thenReturn(baseSoftwareModuleRootMock);
|
||||
when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) SoftwareModule.class);
|
||||
when(criteriaBuilderMock.equal(any(Root.class), anyString())).thenReturn(mock(Predicate.class));
|
||||
when(criteriaBuilderMock.<String> greaterThanOrEqualTo(any(Expression.class), any(String.class))).thenReturn(
|
||||
mock(Predicate.class));
|
||||
// test
|
||||
RSQLUtility.parse(correctRsql, SoftwareModuleFields.class).toPredicate(baseSoftwareModuleRootMock,
|
||||
criteriaQueryMock, criteriaBuilderMock);
|
||||
|
||||
// verfication
|
||||
verify(criteriaBuilderMock, times(1)).and(any(Predicate.class));
|
||||
verify(criteriaBuilderMock, times(1)).lessThan(eq(pathOfString(baseSoftwareModuleRootMock)), eq("abc"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void correctRsqlBuildsLikePredicate() {
|
||||
reset(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock);
|
||||
final String correctRsql = "name=li=abc";
|
||||
when(baseSoftwareModuleRootMock.get("name")).thenReturn(baseSoftwareModuleRootMock);
|
||||
when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) SoftwareModule.class);
|
||||
when(criteriaBuilderMock.equal(any(Root.class), anyString())).thenReturn(mock(Predicate.class));
|
||||
when(criteriaBuilderMock.<String> greaterThanOrEqualTo(any(Expression.class), any(String.class))).thenReturn(
|
||||
mock(Predicate.class));
|
||||
when(criteriaBuilderMock.upper(eq(pathOfString(baseSoftwareModuleRootMock)))).thenReturn(
|
||||
pathOfString(baseSoftwareModuleRootMock));
|
||||
// test
|
||||
RSQLUtility.parse(correctRsql, SoftwareModuleFields.class).toPredicate(baseSoftwareModuleRootMock,
|
||||
criteriaQueryMock, criteriaBuilderMock);
|
||||
|
||||
// verfication
|
||||
verify(criteriaBuilderMock, times(1)).and(any(Predicate.class));
|
||||
verify(criteriaBuilderMock, times(1)).like(eq(pathOfString(baseSoftwareModuleRootMock)),
|
||||
eq("abc".toUpperCase()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void correctRsqlWithEnumValue() {
|
||||
reset(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock);
|
||||
final String correctRsql = "testfield==bumlux";
|
||||
when(baseSoftwareModuleRootMock.get("testfield")).thenReturn(baseSoftwareModuleRootMock);
|
||||
when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) TestValueEnum.class);
|
||||
when(criteriaBuilderMock.equal(any(Root.class), anyString())).thenReturn(mock(Predicate.class));
|
||||
|
||||
// test
|
||||
RSQLUtility.parse(correctRsql, TestFieldEnum.class).toPredicate(baseSoftwareModuleRootMock, criteriaQueryMock,
|
||||
criteriaBuilderMock);
|
||||
|
||||
// verfication
|
||||
verify(criteriaBuilderMock, times(1)).and(any(Predicate.class));
|
||||
verify(criteriaBuilderMock, times(1)).equal(eq(baseSoftwareModuleRootMock), eq(TestValueEnum.BUMLUX));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wrongRsqlWithWrongEnumValue() {
|
||||
reset(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock);
|
||||
final String correctRsql = "testfield==unknownValue";
|
||||
when(baseSoftwareModuleRootMock.get("testfield")).thenReturn(baseSoftwareModuleRootMock);
|
||||
when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) TestValueEnum.class);
|
||||
when(criteriaBuilderMock.equal(any(Root.class), anyString())).thenReturn(mock(Predicate.class));
|
||||
|
||||
try {
|
||||
// test
|
||||
RSQLUtility.parse(correctRsql, TestFieldEnum.class).toPredicate(baseSoftwareModuleRootMock,
|
||||
criteriaQueryMock, criteriaBuilderMock);
|
||||
fail("missing RSQLParameterUnsupportedFieldException for wrong enum value");
|
||||
} catch (final RSQLParameterUnsupportedFieldException e) {
|
||||
// nope expected
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <Y> Path<Y> pathOfString(final Path<?> path) {
|
||||
return (Path<Y>) path;
|
||||
}
|
||||
|
||||
private enum TestFieldEnum implements FieldNameProvider {
|
||||
TESTFIELD;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.eclipse.hawkbit.server.rest.resource.model.FieldNameProvider#
|
||||
* getFieldName()
|
||||
*/
|
||||
@Override
|
||||
public String getFieldName() {
|
||||
return "testfield";
|
||||
}
|
||||
}
|
||||
|
||||
private enum TestValueEnum {
|
||||
BUMLUX;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user