Skip to content

Commit

Permalink
Added tests for Tag service
Browse files Browse the repository at this point in the history
Added tests for creating, deleting and editing tags, and assigning tags to devices.

Signed-off-by: zanpizmoht <zan.pizmoht@comtrade.com>
  • Loading branch information
zanpizmoht committed Jan 31, 2020
1 parent 959bee4 commit 215637c
Show file tree
Hide file tree
Showing 7 changed files with 1,172 additions and 88 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*******************************************************************************
* Copyright (c) 2020 Eurotech and/or its affiliates 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
*
* Contributors:
* Eurotech - initial API and implementation
*******************************************************************************/
package org.eclipse.kapua.integration.service.tag;

import cucumber.api.CucumberOptions;
import org.eclipse.kapua.qa.common.cucumber.CucumberWithProperties;
import org.junit.runner.RunWith;

@RunWith(CucumberWithProperties.class)
@CucumberOptions(
features = { "classpath:features/tag/TagService.feature"
},
glue = {"org.eclipse.kapua.service.tag.steps",
"org.eclipse.kapua.service.user.steps",
"org.eclipse.kapua.service.device.registry.steps",
"org.eclipse.kapua.service.account.steps",
"org.eclipse.kapua.qa.common"
},
plugin = { "pretty",
"html:target/cucumber",
"json:target/cucumber.json" },
strict = true,
monochrome = true)

public class RunTagServiceI9nTest {
}
854 changes: 822 additions & 32 deletions qa/integration/src/test/resources/features/tag/TagService.feature

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ Feature: User Permission tests
| tag | delete |
Then I logout
When I login as user with name "kapua-a" and password "ToManySecrets123#"
Given I create a tag with name "tag_a"
Given I create tag with name "tag_a" without description
When Tag with name "tag_a" is searched
Then I find a tag with name "tag_a"
Then I find and delete tag with name "tag_a"
Expand Down Expand Up @@ -1441,7 +1441,7 @@ Feature: User Permission tests
| account | delete |
And A device named "test_device"
And I create a job with the name "test_job"
And I create a tag with name "test_tag"
And I create tag with name "test_tag" without description
And I create the group with name "test_group"
And I create the following role
| scopeId | name |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,8 @@ Feature: User role service integration tests
And I add access role "test_role" to user "user1"
And I logout
Then I login as user with name "user1" and password "User@10031995"
And I create a tag with name "tag1"
And I find a tag with name "tag1"
And I try to edit tag to name "tag2"
And I create tag with name "tag1" without description
And Name of tag "tag1" is changed into "tag2"
And I delete the tag with name "tag2"
Then No exception was thrown
And I logout
Expand Down Expand Up @@ -799,9 +798,9 @@ Feature: User role service integration tests
And I find a job with name "TestJob"
And I try to edit job to name "TestJob1"
And I try to delete the job with name "TestJob1"
And I create a tag with name "Tag"
And I create tag with name "Tag" without description
And I find a tag with name "Tag"
And I try to edit tag to name "Tag1"
And Name of tag "Tag" is changed into "Tag1"
And I delete the tag with name "Tag1"
And I create the following role
| scopeId | name |
Expand Down Expand Up @@ -1457,9 +1456,9 @@ Feature: User role service integration tests
And I add access role "Role1" to user "SubUser" in account "SubAccount"
And I logout
And I login as user with name "SubUser" and password "User@10031995"
And I create a tag with name "TestTag"
And I create tag with name "TestTag" without description
And I find a tag with name "TestTag"
And I try to edit tag to name "TestTag1"
And Name of tag "TestTag" is changed into "TestTag1"
And I delete the tag with name "TestTag1"
And No exception was thrown
And I logout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,10 @@

/**
* Implementation of Gherkin steps used in DeviceRegistry.feature scenarios.
*
* <p>
* MockedLocator is used for Location Service. Mockito is used to mock other
* services that the Device Registry services dependent on. Dependent services are: -
* Authorization Service -
*
*
*/
@ScenarioScoped
public class DeviceRegistrySteps extends TestBase {
Expand Down Expand Up @@ -2544,16 +2542,16 @@ public void iCreateADeviceWithName(String clientId) throws Exception {

@Then("^I try to edit device to clientId \"([^\"]*)\"$")
public void iTryToEditDeviceToName(String clientId) throws Exception {
Device device = (Device) stepData.get("Device");
device.setClientId(clientId);
Device device = (Device) stepData.get("Device");
device.setClientId(clientId);

try {
primeException();
Device newDevice = deviceRegistryService.update(device);
stepData.put("Device", newDevice);
} catch (KapuaException ex) {
verifyException(ex);
}
try {
primeException();
Device newDevice = deviceRegistryService.update(device);
stepData.put("Device", newDevice);
} catch (KapuaException ex) {
verifyException(ex);
}
}

@Then("^I find device with clientId \"([^\"]*)\"$")
Expand All @@ -2562,4 +2560,122 @@ public void iFindDeviceWithClientId(String deviceName) {

assertEquals(device.getClientId(), deviceName);
}

@And("^I asign tag to device$")
public void iAsignTagToDevice() throws Exception {
Tag tag = (Tag) stepData.get("tag");
Device device = (Device) stepData.get("Device");
try {
Set<KapuaId> tags = device.getTagIds();
tags.add(tag.getId());
device.setTagIds(tags);
Device newDevice = deviceRegistryService.update(device);
stepData.put("tags", tags);
stepData.put("Device", newDevice);
} catch (Exception e) {
verifyException(e);
}
}

@And("^I asign tag \"([^\"]*)\" to device \"([^\"]*)\"$")
public void iAsignTagNamedToDevice(String tagName, String deviceName) throws Exception {
try {
DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId());
tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, deviceName, AttributePredicate.Operator.EQUAL));
DeviceListResult deviceList = deviceRegistryService.query(tmpQuery);
Device device = deviceList.getFirstItem();

TagQuery tagQuery = tagFactory.newQuery(getCurrentScopeId());
tagQuery.setPredicate(tagQuery.attributePredicate(TagAttributes.NAME, tagName, AttributePredicate.Operator.EQUAL));
TagListResult tagList = tagService.query(tagQuery);
Tag tag = tagList.getFirstItem();

Set<KapuaId> tags = device.getTagIds();
tags.add(tag.getId());
device.setTagIds(tags);
Device newDevice = deviceRegistryService.update(device);
stepData.put("tags", tags);
stepData.put("Device", newDevice);
} catch (Exception e) {
verifyException(e);
}
}

@Given("^Tag \"([^\"]*)\" is assigned to device \"([^\"]*)\"$")
public void tagIsAsignedToDevice(String tagName, String deviceName) throws Throwable {
try {
DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId());
tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, deviceName, AttributePredicate.Operator.EQUAL));
DeviceListResult deviceList = deviceRegistryService.query(tmpQuery);
Device device = deviceList.getFirstItem();

TagQuery tagQuery = tagFactory.newQuery(getCurrentScopeId());
tagQuery.setPredicate(tagQuery.attributePredicate(TagAttributes.NAME, tagName, AttributePredicate.Operator.EQUAL));
TagListResult tagList = tagService.query(tagQuery);
Tag tag = tagList.getFirstItem();

Set<KapuaId> tagIds = device.getTagIds();
assertTrue(tagIds.contains(tag.getId()));
} catch (Exception e) {
verifyException(e);
}
}

@Given("^I unassign tag from device$")
public void iUnassignTagFromDevice() throws Exception {
Tag tag = (Tag) stepData.get("tag");
Device device = (Device) stepData.get("Device");
try {
Set<KapuaId> tagIds = device.getTagIds();
tagIds.remove(tag.getId());
device.setTagIds(tagIds);
Device newDevice = deviceRegistryService.update(device);
stepData.put("Device", newDevice);
} catch (Exception e) {
verifyException(e);
}
}

@Given("^I unassign tag \"([^\"]*)\" from device \"([^\"]*)\"$")
public void iUnassignTagNamedFromDevice(String tagName, String deviceName) throws Exception {
try {
DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId());
tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, deviceName, AttributePredicate.Operator.EQUAL));
DeviceListResult deviceList = deviceRegistryService.query(tmpQuery);
Device device = deviceList.getFirstItem();

TagQuery tagQuery = tagFactory.newQuery(getCurrentScopeId());
tagQuery.setPredicate(tagQuery.attributePredicate(TagAttributes.NAME, tagName, AttributePredicate.Operator.EQUAL));
TagListResult tagList = tagService.query(tagQuery);
Tag tag = tagList.getFirstItem();

Set<KapuaId> tagIds = device.getTagIds();
tagIds.remove(tag.getId());
device.setTagIds(tagIds);
Device newDevice = deviceRegistryService.update(device);
stepData.put("Device", newDevice);
} catch (Exception e) {
verifyException(e);
}
}

@Given("^Tag \"([^\"]*)\" is not assigned to device \"([^\"]*)\"$")
public void tagWithNameIsNotAsignedToDevice(String tagName, String deviceName) throws Throwable {
try {
DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId());
tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, deviceName, AttributePredicate.Operator.EQUAL));
DeviceListResult deviceList = deviceRegistryService.query(tmpQuery);
Device device = deviceList.getFirstItem();

TagQuery tagQuery = tagFactory.newQuery(getCurrentScopeId());
tagQuery.setPredicate(tagQuery.attributePredicate(TagAttributes.NAME, tagName, AttributePredicate.Operator.EQUAL));
TagListResult tagList = tagService.query(tagQuery);
Tag tag = tagList.getFirstItem();

Set<KapuaId> tagIds = device.getTagIds();
assertFalse(tagIds.contains(tag.getId()));
} catch (Exception e) {
verifyException(e);
}
}
}
Loading

0 comments on commit 215637c

Please sign in to comment.