Skip to content

Package: DeviceRegistrySteps

DeviceRegistrySteps

nameinstructionbranchcomplexitylinemethod
DeviceRegistrySteps(StepData, DBHelper)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
afterScenario()
M: 26 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
beforeScenario(Scenario)
M: 181 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 31 C: 0
0%
M: 1 C: 0
0%
changeConnectionClientId(String)
M: 34 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
changeConnectionIdRandomly()
M: 23 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
checkCaseSensitivnessOfRegistrySearches()
M: 40 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
checkConnectionDetails(List)
M: 70 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
checkConnectionDomainInitialization()
M: 30 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
checkConnectionObject()
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
checkConnectionObjectAgainstCreator()
M: 64 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 14 C: 0
0%
M: 1 C: 0
0%
checkCreatedDeviceAgainstCreatorParameters()
M: 145 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 29 C: 0
0%
M: 1 C: 0
0%
checkCreatedDeviceId()
M: 26 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
checkCreatedEventAgainstCreatorParameters()
M: 63 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 14 C: 0
0%
M: 1 C: 0
0%
checkDeviceClientIdForChanges()
M: 38 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
checkDeviceClientName(String)
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
checkDeviceConnectionDomainUpdate()
M: 44 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
checkDeviceConnectionStatus(String)
M: 26 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
checkDeviceConnectionUser(String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
checkDeviceEventDomainUpdate()
M: 44 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
checkEventList(int)
M: 15 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
checkEventListForNumberOfItems(int)
M: 13 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
checkLastEventType(String)
M: 35 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
checkListForNumberOfItems(int)
M: 13 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
checkResultListLength(int)
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
checkThatClientIdHasNotChanged()
M: 17 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
checkThatConnectionIsNull()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
checkUpdatedDeviceAgainstOriginal()
M: 152 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 32 C: 0
0%
M: 1 C: 0
0%
checkUserForExistingConnection(String, String, String)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
checkWhetherNamedDeviceStillExists(String)
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
countConnectioncInScope(int, int)
M: 25 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
countDevicesInScope(int)
M: 31 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
countDevicesWithBIOSVersion(String)
M: 37 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
countEventsInScope(int)
M: 31 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
countForDevices()
M: 29 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
createABirthMessage(String)
M: 93 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 26 C: 0
0%
M: 1 C: 0
0%
createADeathMessage(String)
M: 90 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 26 C: 0
0%
M: 1 C: 0
0%
createADevicesAsSpecified(List)
M: 42 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%
createAMissingMessage(String)
M: 87 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 25 C: 0
0%
M: 1 C: 0
0%
createANullDevice()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
createANullDeviceCreator()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
createANumberOfEvents(int, String, String)
M: 45 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 14 C: 0
0%
M: 1 C: 0
0%
createAnApplicationMessage(String)
M: 87 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 25 C: 0
0%
M: 1 C: 0
0%
createConnectionForDevice(List)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
createConnectionFromExistingCreator()
M: 29 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
createConnectionInScope(int)
M: 31 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
createConnections(List)
M: 118 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 32 C: 0
0%
M: 1 C: 0
0%
createDeviceFromExistingCreator()
M: 39 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
createDeviceWithInvalidSymbolsInName()
M: 46 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
createDeviceWithName(String)
M: 25 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
createEventFromCreator()
M: 39 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
createNamedDevice(String)
M: 44 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
createNamedDeviceWithBiosVersion(String, String)
M: 47 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%
createNullQuery()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
createPrivilegedUsers(String, List)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
createQueryWithNullScopeId()
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
createRegularCreator()
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
createRegularDevice()
M: 13 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
createRegularEvent(String, String)
M: 56 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 15 C: 0
0%
M: 1 C: 0
0%
createRegularQuery()
M: 13 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
cueryForConnections(String, String)
M: 38 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
deleteDeviceWithClientId(String)
M: 38 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
deleteDeviceWithRandomIds()
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
deleteDeviceWithRememberedId()
M: 20 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
deleteEvent()
M: 24 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
deleteEventWithRandomId()
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
deleteExistingConnection()
M: 25 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
deleteRandomConnection()
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
deviceIsInGroupsAssignedDevices(String, String)
M: 55 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
deviceIsNotInGroupsAssignedDevices(String, String)
M: 55 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
deviceIsNotNull()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
eventIsNull()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
exerciseAllConnectionFactoryFunctions()
M: 21 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
exerciseAllDeviceFactoryFunctions()
M: 32 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
exerciseAllEventFactoryFunctions()
M: 45 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%
findConnectionByClientId(String)
M: 24 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
findConnectionByScopeAndConnectionId()
M: 33 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
findDevice()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
findDeviceByRememberedClientId(String)
M: 26 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
findDeviceByRememberedId()
M: 28 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
findDeviceWithClientId(String)
M: 35 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
findDeviceWithRandomClientId()
M: 27 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
findDeviceWithRandomId()
M: 26 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
findDeviceWithRememberedId()
M: 31 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
findEventById()
M: 31 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
findEventByRandomId()
M: 26 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
generateABunchOfTestDevices(int, String)
M: 40 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
generateABunchOfTestDevicesInScope(int, int)
M: 45 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
getDefaultPosition()
M: 43 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
getDeviceWithClientId(String)
M: 23 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getFirstDeviceFromList()
M: 18 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getMethodFromString(String)
M: 33 C: 0
0%
M: 7 C: 0
0%
M: 7 C: 0
0%
M: 15 C: 0
0%
M: 1 C: 0
0%
iAddDeviceToGroup(String, String)
M: 65 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 14 C: 0
0%
M: 1 C: 0
0%
iAsignTagToDevice()
M: 45 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
iAssignTagNamedToDevice(String, String)
M: 74 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 17 C: 0
0%
M: 1 C: 0
0%
iChangeDeviceStatusTo(String)
M: 42 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
iChangeDevicesGroupToNoGroup(String)
M: 41 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
iCreateADeviceWithName(String)
M: 38 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
iCreateADeviceWithNullClientID()
M: 38 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
iCreateDevicesAndAddThemToGroup(int, String)
M: 47 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
iDeleteTag(String)
M: 50 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
iFilterDevices(List)
M: 809 C: 0
0%
M: 120 C: 0
0%
M: 61 C: 0
0%
M: 95 C: 0
0%
M: 1 C: 0
0%
iFindDeviceWithClientId(String)
M: 16 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
iFindDeviceWithTag(String)
M: 17 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
iSearchForADeviceWithName(String)
M: 44 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
iSearchForDeviceWithTag(String)
M: 66 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 15 C: 0
0%
M: 1 C: 0
0%
iSearchForEventsFromDevicesInAccount(String, int)
M: 88 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 20 C: 0
0%
M: 1 C: 0
0%
iTagDeviceWithTag(String)
M: 68 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 17 C: 0
0%
M: 1 C: 0
0%
iTryToCreateDevicesWithInvalidSymbolsInName(String)
M: 54 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
iTryToEditDeviceToName(String)
M: 32 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
iTryToEditDevicesDisplayNameTo(String)
M: 26 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
iUnassignTagFromDevice()
M: 40 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
iUnassignTagNamedFromDevice(String, String)
M: 74 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 17 C: 0
0%
M: 1 C: 0
0%
iUpdateTheDeviceClientIDToNewClientId(String, String)
M: 32 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
iVerifyTagIsDeleted(String)
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
lambda$checkDeviceConnectionUser$5(String)
M: 28 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
lambda$checkUserForExistingConnection$10(String, String, String)
M: 28 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
lambda$createConnectionForDevice$3(List)
M: 56 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%
lambda$createPrivilegedUsers$0(String, List)
M: 50 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
lambda$modifyDeviceConnectionCouplingMode$7(String, String, String)
M: 30 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
lambda$modifyDeviceConnectionReservedUser$9(String, String, String)
M: 59 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 16 C: 0
0%
M: 1 C: 0
0%
lambda$modifyDeviceConnectionStatus$6(String, String, String)
M: 30 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
lambda$modifyDeviceConnectionUserChangeFlag$8(String, String, String)
M: 26 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
lambda$searchForConnectionFromDeviceWithClientID$4(String, String)
M: 53 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%
lambda$setAccountDevicePrivileges$1(String)
M: 31 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
lambda$setDeviceConnectionCouplingMode$2(String, String)
M: 24 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
modifyDeviceConnectionCouplingMode(String, String, String)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
modifyDeviceConnectionReservedUser(String, String, String)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
modifyDeviceConnectionStatus(String, String, String)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
modifyDeviceConnectionUserChangeFlag(String, String, String)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
noSuchDevice()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
parseBooleanFromString(String)
M: 16 C: 0
0%
M: 3 C: 0
0%
M: 3 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
parseConnectionCouplingString(String)
M: 18 C: 0
0%
M: 4 C: 0
0%
M: 4 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
parseConnectionStatusString(String)
M: 18 C: 0
0%
M: 4 C: 0
0%
M: 4 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
prepareCreatorWithNullAction()
M: 16 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
prepareDefaultApplicationPayload()
M: 93 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 31 C: 0
0%
M: 1 C: 0
0%
prepareDefaultBirthPayload()
M: 93 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 31 C: 0
0%
M: 1 C: 0
0%
prepareDefaultDeathPayload()
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
prepareDefaultDeviceCreator()
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
prepareDefaultMissingPayload()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
prepareDeviceCreatorFromCucDevice(CucDevice)
M: 157 C: 0
0%
M: 36 C: 0
0%
M: 19 C: 0
0%
M: 44 C: 0
0%
M: 1 C: 0
0%
prepareRegularConnectionCreator(KapuaId, KapuaId)
M: 32 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
prepareRegularDevice(KapuaId, KapuaId)
M: 74 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 23 C: 0
0%
M: 1 C: 0
0%
prepareRegularDeviceCreator(KapuaId, String)
M: 71 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 22 C: 0
0%
M: 1 C: 0
0%
prepareRegularDeviceEventCreator(KapuaId, KapuaId)
M: 82 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 22 C: 0
0%
M: 1 C: 0
0%
queryForDevices()
M: 28 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
queryForDevicesBasedOnBiosVersion(String)
M: 36 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
queryForDevicesBasedOnClientId(String)
M: 36 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
queryForDevicesWithDifferentBiosVersion(String)
M: 36 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
queryForSpecificEvents(String)
M: 44 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%
searchForARandomConnectionId()
M: 26 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
searchForConnectionFromDeviceWithClientID(String, String)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
searchForDeviceWithClientID(String, String)
M: 57 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 16 C: 0
0%
M: 1 C: 0
0%
searchForEventsFromDeviceWithClientID(String, String)
M: 62 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 16 C: 0
0%
M: 1 C: 0
0%
setAccountDevicePrivileges(String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setDeviceClientId(String)
M: 17 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
setDeviceConnectionConfigurationValue(List)
M: 56 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 16 C: 0
0%
M: 1 C: 0
0%
setDeviceConnectionCouplingMode(String, String)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setDeviceCreatorClientToNull()
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
setDeviceCreatorScopeToNull()
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
setDeviceId(String)
M: 19 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
setDeviceIdToNull()
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
setDeviceRegistryConfigurationValue(List)
M: 56 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 16 C: 0
0%
M: 1 C: 0
0%
setDeviceScopeToNull()
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
tagIsAssignedToDevice(String, String)
M: 60 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 14 C: 0
0%
M: 1 C: 0
0%
tagWithNameIsNotAsignedToDevice(String, String)
M: 60 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 14 C: 0
0%
M: 1 C: 0
0%
theDevicesDisplayNameIs(String)
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
updateConnectionDetails(List)
M: 131 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 26 C: 0
0%
M: 1 C: 0
0%
updateDeviceClientId(String)
M: 28 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
updateDeviceParameters()
M: 43 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
updateDeviceWithInvalidId()
M: 23 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
waitForSpecifiedTime(int)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2020, 2022 Eurotech and/or its affiliates and others
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Eurotech - initial API and implementation
12: *******************************************************************************/
13: package org.eclipse.kapua.service.device.registry.steps;
14:
15: import com.google.common.collect.Lists;
16: import cucumber.api.Scenario;
17: import cucumber.api.java.After;
18: import cucumber.api.java.Before;
19: import cucumber.api.java.en.And;
20: import cucumber.api.java.en.Given;
21: import cucumber.api.java.en.Then;
22: import cucumber.api.java.en.When;
23: import cucumber.runtime.java.guice.ScenarioScoped;
24: import org.apache.shiro.SecurityUtils;
25: import org.eclipse.kapua.KapuaException;
26: import org.eclipse.kapua.commons.model.id.KapuaEid;
27: import org.eclipse.kapua.commons.security.KapuaSecurityUtils;
28: import org.eclipse.kapua.commons.security.KapuaSession;
29: import org.eclipse.kapua.commons.util.xml.XmlUtil;
30: import org.eclipse.kapua.locator.KapuaLocator;
31: import org.eclipse.kapua.message.KapuaMessageFactory;
32: import org.eclipse.kapua.message.KapuaPosition;
33: import org.eclipse.kapua.message.device.lifecycle.KapuaAppsChannel;
34: import org.eclipse.kapua.message.device.lifecycle.KapuaAppsMessage;
35: import org.eclipse.kapua.message.device.lifecycle.KapuaAppsPayload;
36: import org.eclipse.kapua.message.device.lifecycle.KapuaBirthChannel;
37: import org.eclipse.kapua.message.device.lifecycle.KapuaBirthMessage;
38: import org.eclipse.kapua.message.device.lifecycle.KapuaBirthPayload;
39: import org.eclipse.kapua.message.device.lifecycle.KapuaDisconnectChannel;
40: import org.eclipse.kapua.message.device.lifecycle.KapuaDisconnectMessage;
41: import org.eclipse.kapua.message.device.lifecycle.KapuaDisconnectPayload;
42: import org.eclipse.kapua.message.device.lifecycle.KapuaLifecycleMessageFactory;
43: import org.eclipse.kapua.message.device.lifecycle.KapuaMissingChannel;
44: import org.eclipse.kapua.message.device.lifecycle.KapuaMissingMessage;
45: import org.eclipse.kapua.message.device.lifecycle.KapuaMissingPayload;
46: import org.eclipse.kapua.model.domain.Actions;
47: import org.eclipse.kapua.model.id.KapuaId;
48: import org.eclipse.kapua.model.query.SortOrder;
49: import org.eclipse.kapua.model.query.predicate.AttributePredicate;
50: import org.eclipse.kapua.qa.common.DBHelper;
51: import org.eclipse.kapua.qa.common.StepData;
52: import org.eclipse.kapua.qa.common.TestBase;
53: import org.eclipse.kapua.qa.common.TestDomain;
54: import org.eclipse.kapua.qa.common.TestJAXBContextProvider;
55: import org.eclipse.kapua.qa.common.cucumber.CucConfig;
56: import org.eclipse.kapua.qa.common.cucumber.CucConnection;
57: import org.eclipse.kapua.qa.common.cucumber.CucDevice;
58: import org.eclipse.kapua.qa.common.cucumber.CucUser;
59: import org.eclipse.kapua.service.account.Account;
60: import org.eclipse.kapua.service.account.AccountFactory;
61: import org.eclipse.kapua.service.account.AccountService;
62: import org.eclipse.kapua.service.authentication.AuthenticationService;
63: import org.eclipse.kapua.service.authentication.credential.CredentialService;
64: import org.eclipse.kapua.service.authorization.access.AccessInfoService;
65: import org.eclipse.kapua.service.authorization.domain.Domain;
66: import org.eclipse.kapua.service.authorization.domain.DomainFactory;
67: import org.eclipse.kapua.service.authorization.group.Group;
68: import org.eclipse.kapua.service.authorization.group.GroupAttributes;
69: import org.eclipse.kapua.service.authorization.group.GroupFactory;
70: import org.eclipse.kapua.service.authorization.group.GroupQuery;
71: import org.eclipse.kapua.service.authorization.group.GroupService;
72: import org.eclipse.kapua.service.device.management.message.KapuaMethod;
73: import org.eclipse.kapua.service.device.management.message.response.KapuaResponseCode;
74: import org.eclipse.kapua.service.device.registry.ConnectionUserCouplingMode;
75: import org.eclipse.kapua.service.device.registry.Device;
76: import org.eclipse.kapua.service.device.registry.DeviceAttributes;
77: import org.eclipse.kapua.service.device.registry.DeviceCreator;
78: import org.eclipse.kapua.service.device.registry.DeviceFactory;
79: import org.eclipse.kapua.service.device.registry.DeviceListResult;
80: import org.eclipse.kapua.service.device.registry.DeviceQuery;
81: import org.eclipse.kapua.service.device.registry.DeviceRegistryService;
82: import org.eclipse.kapua.service.device.registry.DeviceStatus;
83: import org.eclipse.kapua.service.device.registry.connection.DeviceConnection;
84: import org.eclipse.kapua.service.device.registry.connection.DeviceConnectionCreator;
85: import org.eclipse.kapua.service.device.registry.connection.DeviceConnectionDomain;
86: import org.eclipse.kapua.service.device.registry.connection.DeviceConnectionFactory;
87: import org.eclipse.kapua.service.device.registry.connection.DeviceConnectionListResult;
88: import org.eclipse.kapua.service.device.registry.connection.DeviceConnectionQuery;
89: import org.eclipse.kapua.service.device.registry.connection.DeviceConnectionService;
90: import org.eclipse.kapua.service.device.registry.connection.DeviceConnectionStatus;
91: import org.eclipse.kapua.service.device.registry.event.DeviceEvent;
92: import org.eclipse.kapua.service.device.registry.event.DeviceEventAttributes;
93: import org.eclipse.kapua.service.device.registry.event.DeviceEventCreator;
94: import org.eclipse.kapua.service.device.registry.event.DeviceEventFactory;
95: import org.eclipse.kapua.service.device.registry.event.DeviceEventListResult;
96: import org.eclipse.kapua.service.device.registry.event.DeviceEventQuery;
97: import org.eclipse.kapua.service.device.registry.event.DeviceEventService;
98: import org.eclipse.kapua.service.device.registry.lifecycle.DeviceLifeCycleService;
99: import org.eclipse.kapua.service.tag.Tag;
100: import org.eclipse.kapua.service.tag.TagAttributes;
101: import org.eclipse.kapua.service.tag.TagCreator;
102: import org.eclipse.kapua.service.tag.TagFactory;
103: import org.eclipse.kapua.service.tag.TagListResult;
104: import org.eclipse.kapua.service.tag.TagQuery;
105: import org.eclipse.kapua.service.tag.TagService;
106: import org.eclipse.kapua.service.user.User;
107: import org.eclipse.kapua.service.user.UserFactory;
108: import org.eclipse.kapua.service.user.UserService;
109: import org.junit.Assert;
110: import org.slf4j.Logger;
111: import org.slf4j.LoggerFactory;
112:
113: import javax.inject.Inject;
114: import java.math.BigInteger;
115: import java.util.ArrayList;
116: import java.util.Date;
117: import java.util.HashMap;
118: import java.util.HashSet;
119: import java.util.List;
120: import java.util.Map;
121: import java.util.Set;
122: import java.util.UUID;
123: import java.util.Vector;
124:
125: /**
126: * Implementation of Gherkin steps used in DeviceRegistry.feature scenarios.
127: * <p>
128: * MockedLocator is used for Location Service. Mockito is used to mock other
129: * services that the Device Registry services dependent on. Dependent services are: -
130: * Authorization Service -
131: */
132: @ScenarioScoped
133: public class DeviceRegistrySteps extends TestBase {
134:
135: private static final Logger LOGGER = LoggerFactory.getLogger(DeviceRegistrySteps.class);
136:
137: private static final String TEST_DEVICE_NAME = "test_name";
138: private static final String TEST_BIOS_VERSION_1 = "bios_version_1";
139: private static final String TEST_BIOS_VERSION_2 = "bios_version_2";
140: private static final String TEST_BIOS_VERSION_3 = "bios_version_3";
141:
142: // Strings for client ID character set and length checks
143: private static String simpleClientId = "simpleClientIdWith64Chars_12345678901234567890123456789012345678";
144: private static String fullClientId = "fullClientIdWith64Chars_✁✂✃✄✅✆✇✈✉✊✋✌✍✎✏✐✑✒✓✔✕✁✂✃✄✅✆✇✈✉✊✋✌✍✎✏✐✑✒✓";
145: private static String simpleClientIdTooLong = "simpleClientIdWith65Chars_123456789012345678901234567890123456789";
146: private static String fullClientIdTooLong = "fullClientIdWith65Chars_✁✂✃✄✅✆✇✈✉✊✋✌✍✎✏✐✑✒✓✔✕✁✂✃✄✅✆✇✈✉✊✋✌✍✎✏✐✑✒✓✔";
147:
148: // Various device connection details
149: private static final String CLIENT_NAME = "test_client";
150: private static final String CLIENT_IP = "127.1.1.10";
151: private static final String SERVER_IP = "127.1.1.100";
152:
153: private static final String DEVICE_CREATOR = "DeviceCreator";
154: private static final String DEVICE_ID = "DeviceId";
155: private static final String DEVICE = "Device";
156: private static final String LAST_DEVICE = "LastDevice";
157: private static final String LAST_ACCOUNT = "LastAccount";
158: private static final String DEVICE_QUERY = "DeviceQuery";
159: private static final String DEVICE_LIST = "DeviceList";
160: private static final String COUNT = "Count";
161: private static final String DEVICE_CONNECTION_CREATOR = "DeviceConnectionCreator";
162: private static final String DEVICE_CONNECTION = "DeviceConnection";
163: private static final String DEVICE_CONNECTION_ID = "DeviceConnectionId";
164: private static final String DEVICE_CONNECTION_LIST = "DeviceConnectionList";
165: private static final String DEVICE_EVENT_CREATOR = "DeviceEventCreator";
166: private static final String DEVICE_EVENT = "DeviceEvent";
167: private static final String DEVICE_EVENT_ID = "DeviceEventId";
168: private static final String DEVICE_EVENT_LIST = "DeviceEventList";
169: private static final String PART1 = "part1";
170: private static final String PART2 = "part2";
171: private static final String RELIAGATE_10_20 = "ReliaGate 10-20";
172: private static final String VERSION_NUMBER = "1.2.3";
173: private static final String LINUX = "linux";
174:
175: // Various device registry service related references
176: private DeviceRegistryService deviceRegistryService;
177: private DeviceFactory deviceFactory;
178:
179: // Various device connection service related references
180: private DeviceConnectionService deviceConnectionService;
181: private DeviceConnectionFactory deviceConnectionFactory;
182:
183: // Various device event service related references
184: private DeviceEventService eventService;
185: private DeviceEventFactory eventFactory;
186:
187:
188: // Additional service references for integration testing
189: private DeviceLifeCycleService deviceLifeCycleService;
190: private AuthenticationService authenticationService;
191: private DomainFactory domainFactory;
192: private AccountService accountService;
193: private AccountFactory accountFactory;
194: private UserService userService;
195: private UserFactory userFactory;
196: private CredentialService credentialService;
197: private AccessInfoService accessInfoService;
198: private TagService tagService;
199: private TagFactory tagFactory;
200: private KapuaMessageFactory messageFactory;
201: private KapuaLifecycleMessageFactory lifecycleMessageFactory;
202: private GroupService groupService;
203: private GroupFactory groupFactory;
204:
205: private AclCreator aclCreator;
206:
207: // Default constructor
208: @Inject
209: public DeviceRegistrySteps(StepData stepData, DBHelper dbHelper) {
210:
211: this.stepData = stepData;
212: this.database = dbHelper;
213: }
214:
215: // ************************************************************************************
216: // ************************************************************************************
217: // * Definition of Cucumber scenario steps *
218: // ************************************************************************************
219: // ************************************************************************************
220:
221: // ************************************************************************************
222: // * Setup and tear-down steps *
223: // ************************************************************************************
224:
225: @Before
226: public void beforeScenario(Scenario scenario) {
227:
228: this.scenario = scenario;
229: database.setup();
230: stepData.clear();
231:
232: locator = KapuaLocator.getInstance();
233: deviceRegistryService = locator.getService(DeviceRegistryService.class);
234: deviceFactory = locator.getFactory(DeviceFactory.class);
235:
236: deviceConnectionService = locator.getService(DeviceConnectionService.class);
237: deviceConnectionFactory = locator.getFactory(DeviceConnectionFactory.class);
238:
239: eventService = locator.getService(DeviceEventService.class);
240: eventFactory = locator.getFactory(DeviceEventFactory.class);
241:
242: messageFactory = locator.getFactory(KapuaMessageFactory.class);
243: lifecycleMessageFactory = locator.getFactory(KapuaLifecycleMessageFactory.class);
244:
245: deviceLifeCycleService = locator.getService(DeviceLifeCycleService.class);
246: authenticationService = locator.getService(AuthenticationService.class);
247: domainFactory = locator.getFactory(DomainFactory.class);
248: accountService = locator.getService(AccountService.class);
249: accountFactory = locator.getFactory(AccountFactory.class);
250: userService = locator.getService(UserService.class);
251: userFactory = locator.getFactory(UserFactory.class);
252: credentialService = locator.getService(CredentialService.class);
253: accessInfoService = locator.getService(AccessInfoService.class);
254: tagService = locator.getService(TagService.class);
255: tagFactory = locator.getFactory(TagFactory.class);
256: groupService = locator.getService(GroupService.class);
257: groupFactory = locator.getFactory(GroupFactory.class);
258:
259: aclCreator = new AclCreator();
260:
261:• if (isUnitTest()) {
262: // Create KapuaSession using KapuaSecurtiyUtils and kapua-sys user as logged in user.
263: // All operations on database are performed using system user.
264: // Only for unit tests. Integration tests assume that a real logon is performed.
265: KapuaSession kapuaSession = new KapuaSession(null, SYS_SCOPE_ID, SYS_USER_ID);
266: KapuaSecurityUtils.setSession(kapuaSession);
267: }
268:
269: // Setup JAXB context
270: XmlUtil.setContextProvider(new TestJAXBContextProvider());
271: }
272:
273: @After
274: public void afterScenario() {
275:
276: // Clean up the database
277: try {
278: LOGGER.info("Logging out in cleanup");
279:• if (isIntegrationTest()) {
280: database.deleteAll();
281: SecurityUtils.getSubject().logout();
282: } else {
283: database.dropAll();
284: database.close();
285: }
286: KapuaSecurityUtils.clearSession();
287: } catch (Exception e) {
288: LOGGER.error("Failed to log out in @After", e);
289: }
290: }
291:
292: // ************************************************************************************
293: // * Cucumber Test steps *
294: // ************************************************************************************
295:
296: // ************************************************************************************
297: // * Device Registry steps *
298: // ************************************************************************************
299:
300: @When("^I configure the device registry service$")
301: public void setDeviceRegistryConfigurationValue(List<CucConfig> cucConfigs) throws Exception {
302:
303: Map<String, Object> valueMap = new HashMap<>();
304: KapuaId accId = getCurrentScopeId();
305: KapuaId scopeId = getCurrentParentId();
306:
307:• for (CucConfig config : cucConfigs) {
308: config.addConfigToMap(valueMap);
309:• if (config.getParentId() != null) {
310: scopeId = getKapuaId(config.getParentId());
311: }
312:• if (config.getScopeId() != null) {
313: accId = getKapuaId(config.getScopeId());
314: }
315: }
316:
317: primeException();
318: try {
319: deviceRegistryService.setConfigValues(accId, scopeId, valueMap);
320: } catch (KapuaException ke) {
321: verifyException(ke);
322: }
323: }
324:
325: @Given("^A regular device creator$")
326: public void prepareDefaultDeviceCreator() {
327:
328: DeviceCreator deviceCreator = prepareRegularDeviceCreator(getCurrentScopeId(), "device_1");
329: stepData.put(DEVICE_CREATOR, deviceCreator);
330: }
331:
332: @Given("^A null device creator$")
333: public void createANullDeviceCreator() {
334:
335: stepData.put(DEVICE_CREATOR, null);
336: }
337:
338: @When("^I set the creator scope ID to null$")
339: public void setDeviceCreatorScopeToNull() {
340:
341: DeviceCreator deviceCreator = (DeviceCreator) stepData.get(DEVICE_CREATOR);
342: deviceCreator.setScopeId(null);
343: stepData.put(DEVICE_CREATOR, deviceCreator);
344: }
345:
346: @When("^I set the creator client ID to null$")
347: public void setDeviceCreatorClientToNull() {
348:
349: DeviceCreator deviceCreator = (DeviceCreator) stepData.get(DEVICE_CREATOR);
350: deviceCreator.setClientId(null);
351: stepData.put(DEVICE_CREATOR, deviceCreator);
352: }
353:
354: @Given("^The device ID (.+)$")
355: public void setDeviceId(String deviceId) {
356:
357: KapuaId dev;
358:
359:• if (deviceId.trim().toLowerCase().equals("null")) {
360: dev = null;
361: } else {
362: dev = getKapuaId(deviceId);
363: }
364:
365: stepData.put(DEVICE_ID, dev);
366: }
367:
368: @Given("^The device client ID \"(.+)\"$")
369: public void setDeviceClientId(String clientId) {
370:
371: String id;
372:
373:• if (clientId.trim().toLowerCase().equals("null")) {
374: id = null;
375: } else {
376: id = clientId;
377: }
378:
379: stepData.put("ClientId", id);
380: }
381:
382: @Given("^A regular device$")
383: public void createRegularDevice() {
384:
385: Device device = prepareRegularDevice(getCurrentParentId(), getKapuaId());
386: stepData.put(DEVICE, device);
387: }
388:
389: @Given("^(?:(?:A d|D)evices? such as|I create (?:a device|devices) with parameters)$")
390: public void createADevicesAsSpecified(List<CucDevice> devLst)
391: throws Exception {
392:
393: primeException();
394: try {
395: stepData.remove(LAST_DEVICE);
396: Device tmpDevice = null;
397:• for (CucDevice tmpCDev : devLst) {
398: tmpCDev.parse();
399: DeviceCreator devCr = prepareDeviceCreatorFromCucDevice(tmpCDev);
400: tmpDevice = deviceRegistryService.create(devCr);
401: }
402: stepData.put(LAST_DEVICE, tmpDevice);
403: } catch (Exception ex) {
404: verifyException(ex);
405: }
406: }
407:
408: @Given("^The device \"(.*)\"$")
409: public void createDeviceWithName(String clientId) throws KapuaException {
410:
411: Account tmpAcc = (Account) stepData.get(LAST_ACCOUNT);
412: DeviceCreator tmpDevCr = deviceFactory.newCreator(tmpAcc.getId(), clientId);
413: Device tmpDev = deviceRegistryService.create(tmpDevCr);
414: stepData.put(LAST_DEVICE, tmpDev);
415: }
416:
417: @Given("^I try to create devices with invalid symbols in name$")
418: public void createDeviceWithInvalidSymbolsInName() throws Exception {
419:
420: String invalidSymbols = "!\"#$%&'()=Ȃ" +
421: ">:;<-.,⁄@‹›€" +
422: "*ı–°·‚_±Œ„‰" +
423: "?“‘”’ÉØ∏{}|Æ" +
424: "æÒ\uF8FFÔÓÌÏÎÍÅ«" +
425: "◊ш¯Èˇ¿";
426: Account tmpAcc = (Account) stepData.get("LastAccount");
427:• for (int i = 0; i < invalidSymbols.length(); i++) {
428: String clientId = "Device" + invalidSymbols.charAt(i);
429: try {
430:
431: DeviceCreator tmpDevCr = deviceFactory.newCreator(tmpAcc.getId(), clientId);
432: Device tmpDev = deviceRegistryService.create(tmpDevCr);
433: } catch (KapuaException e) {
434: verifyException(e);
435: }
436: }
437: }
438:
439: @Given("^A null device$")
440: public void createANullDevice() {
441:
442: stepData.put(DEVICE, null);
443: }
444:
445: @When("^I set the device scope ID to null$")
446: public void setDeviceScopeToNull() {
447:
448: Device device = (Device) stepData.get(DEVICE);
449: device.setScopeId(null);
450: stepData.put(DEVICE, device);
451: }
452:
453: @When("^I set the device ID to null$")
454: public void setDeviceIdToNull() {
455:
456: Device device = (Device) stepData.get(DEVICE);
457: device.setId(null);
458: stepData.put(DEVICE, device);
459: }
460:
461: @Given("^A regular query$")
462: public void createRegularQuery() {
463:
464: DeviceQuery query = deviceFactory.newQuery(getCurrentScopeId());
465: stepData.put(DEVICE_QUERY, query);
466: }
467:
468: @Given("^A query with a null Scope ID$")
469: public void createQueryWithNullScopeId() {
470:
471: DeviceQuery query = deviceFactory.newQuery(null);
472: stepData.put(DEVICE_QUERY, query);
473: }
474:
475: @Given("^A null query$")
476: public void createNullQuery() {
477:
478: stepData.put(DEVICE_QUERY, null);
479: }
480:
481: @Given("^A device named \"(.*)\"$")
482: public void createNamedDevice(String name)
483: throws Exception {
484:
485: DeviceCreator deviceCreator = prepareRegularDeviceCreator(getCurrentScopeId(), name);
486: stepData.put(DEVICE_CREATOR, deviceCreator);
487:
488: primeException();
489: try {
490: stepData.remove(DEVICE);
491: stepData.remove(DEVICE_ID);
492: Device device = deviceRegistryService.create(deviceCreator);
493: stepData.put(DEVICE, device);
494: stepData.put(DEVICE_ID, device.getId());
495: } catch (KapuaException ex) {
496: verifyException(ex);
497: }
498: }
499:
500: @Given("^A device with BIOS version \"(.*)\" named \"(.*)\"$")
501: public void createNamedDeviceWithBiosVersion(String version, String name)
502: throws Exception {
503:
504: DeviceCreator deviceCreator = prepareRegularDeviceCreator(getCurrentScopeId(), name);
505: deviceCreator.setBiosVersion(version);
506: stepData.put(DEVICE_CREATOR, deviceCreator);
507:
508: primeException();
509: try {
510: stepData.remove(DEVICE);
511: stepData.remove(DEVICE_ID);
512: Device device = deviceRegistryService.create(deviceCreator);
513: stepData.put(DEVICE, device);
514: stepData.put(DEVICE_ID, device.getId());
515: } catch (KapuaException ex) {
516: verifyException(ex);
517: }
518: }
519:
520: @Given("^I create (\\d+) randomly named devices with BIOS version \"(.*)\"$")
521: public void generateABunchOfTestDevices(int number, String version)
522: throws Exception {
523:
524: DeviceCreator tmpDevCr;
525:
526: primeException();
527: try {
528:• for (int i = 0; i < number; i++) {
529: tmpDevCr = deviceFactory.newCreator(getCurrentScopeId(), "test_" + String.valueOf(random.nextInt()));
530: tmpDevCr.setBiosVersion(version);
531: deviceRegistryService.create(tmpDevCr);
532: }
533: } catch (KapuaException ex) {
534: verifyException(ex);
535: }
536: }
537:
538: @Given("^I create (\\d+) randomly named devices in scope (\\d+)$")
539: public void generateABunchOfTestDevicesInScope(int number, int scope)
540: throws Exception {
541:
542: DeviceCreator tmpDevCr;
543: KapuaId tmpId;
544: String tmpClient;
545:
546: primeException();
547: try {
548:• for (int i = 0; i < number; i++) {
549: tmpId = new KapuaEid(BigInteger.valueOf(scope));
550: tmpClient = "test_" + String.valueOf(random.nextInt());
551: tmpDevCr = deviceFactory.newCreator(tmpId, tmpClient);
552: deviceRegistryService.create(tmpDevCr);
553: }
554: } catch (KapuaException ex) {
555: verifyException(ex);
556: }
557: }
558:
559: @When("^I create a device from the existing creator$")
560: public void createDeviceFromExistingCreator()
561: throws Exception {
562:
563: DeviceCreator deviceCreator = (DeviceCreator) stepData.get(DEVICE_CREATOR);
564:
565: primeException();
566: try {
567: stepData.remove(DEVICE);
568: stepData.remove(DEVICE_ID);
569: Device device = deviceRegistryService.create(deviceCreator);
570: stepData.put(DEVICE, device);
571: stepData.put(DEVICE_ID, device.getId());
572: } catch (KapuaException ex) {
573: verifyException(ex);
574: }
575: }
576:
577: @When("^I search for a device with the remembered ID$")
578: public void findDeviceWithRememberedId()
579: throws Exception {
580:
581: KapuaId deviceId = (KapuaId) stepData.get(DEVICE_ID);
582:
583: primeException();
584: try {
585: stepData.remove(DEVICE);
586: Device device = deviceRegistryService.find(getCurrentScopeId(), deviceId);
587: stepData.put(DEVICE, device);
588: } catch (KapuaException ex) {
589: verifyException(ex);
590: }
591: }
592:
593: @When("^I search for a device with the client ID \"(.*)\"$")
594: public void findDeviceWithClientId(String clientId)
595: throws Exception {
596:
597: String client;
598:
599:• if (clientId.trim().toLowerCase().equals("null")) {
600: client = null;
601: } else {
602: client = clientId;
603: }
604:
605: primeException();
606: try {
607: stepData.remove(DEVICE);
608: Device device = deviceRegistryService.findByClientId(getCurrentScopeId(), client);
609: stepData.put(DEVICE, device);
610: } catch (KapuaException ex) {
611: verifyException(ex);
612: }
613: }
614:
615: @When("^I find searched device$")
616: public void findDevice() throws Exception {
617:
618: assertNotNull(stepData.get("Device"));
619:
620: }
621:
622: @When("^I search for a device with a nonexisting registry ID$")
623: public void findDeviceWithRandomId()
624: throws Exception {
625:
626: primeException();
627: try {
628: stepData.remove(DEVICE);
629: Device device = deviceRegistryService.find(getCurrentScopeId(), getKapuaId());
630: stepData.put(DEVICE, device);
631: } catch (KapuaException ex) {
632: verifyException(ex);
633: }
634: }
635:
636: @When("^I search for a device with a random client ID$")
637: public void findDeviceWithRandomClientId()
638: throws Exception {
639:
640: primeException();
641: try {
642: stepData.remove(DEVICE);
643: Device device = deviceRegistryService.findByClientId(getCurrentScopeId(), String.valueOf(random.nextLong()));
644: stepData.put(DEVICE, device);
645: } catch (KapuaException ex) {
646: verifyException(ex);
647: }
648: }
649:
650: @When("^I perform the remembered query$")
651: public void queryForDevices()
652: throws Exception {
653:
654: DeviceQuery tmpQuery = (DeviceQuery) stepData.get(DEVICE_QUERY);
655:
656: primeException();
657: try {
658: stepData.remove(DEVICE_LIST);
659: DeviceListResult deviceList = deviceRegistryService.query(tmpQuery);
660: stepData.put(DEVICE_LIST, deviceList);
661: } catch (KapuaException ex) {
662: verifyException(ex);
663: }
664: }
665:
666: @When("^I query for devices with BIOS version \"(.*)\"$")
667: public void queryForDevicesBasedOnBiosVersion(String version)
668: throws Exception {
669:
670: DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId());
671: // Search for the known bios version string
672: tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.BIOS_VERSION, version, AttributePredicate.Operator.EQUAL));
673:
674: primeException();
675: try {
676: stepData.remove(DEVICE_LIST);
677: DeviceListResult deviceList = deviceRegistryService.query(tmpQuery);
678: stepData.put(DEVICE_LIST, deviceList);
679: } catch (KapuaException ex) {
680: verifyException(ex);
681: }
682: }
683:
684: @When("^I query for devices with BIOS different from \"(.*)\"$")
685: public void queryForDevicesWithDifferentBiosVersion(String version)
686: throws Exception {
687:
688: DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId());
689: // Search for the known bios version string
690: tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.BIOS_VERSION, version, AttributePredicate.Operator.EQUAL));
691:
692: primeException();
693: try {
694: stepData.remove(DEVICE_LIST);
695: DeviceListResult deviceList = deviceRegistryService.query(tmpQuery);
696: stepData.put(DEVICE_LIST, deviceList);
697: } catch (KapuaException ex) {
698: verifyException(ex);
699: }
700: }
701:
702: @When("^I query for devices with Client Id \"(.*)\"$")
703: public void queryForDevicesBasedOnClientId(String id)
704: throws Exception {
705:
706: DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId());
707: // Search for the known bios version string
708: tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, id, AttributePredicate.Operator.EQUAL));
709:
710: primeException();
711: try {
712: stepData.remove(DEVICE_LIST);
713: DeviceListResult deviceList = deviceRegistryService.query(tmpQuery);
714: stepData.put(DEVICE_LIST, deviceList);
715: } catch (KapuaException ex) {
716: verifyException(ex);
717: }
718: }
719:
720: @And("^I extract the device with correct BIOS version$")
721: public void getFirstDeviceFromList() {
722:
723: DeviceListResult deviceList = (DeviceListResult) stepData.get(DEVICE_LIST);
724:
725: // A device should have been found
726: assertNotEquals(0, deviceList.getSize());
727: stepData.put(DEVICE, deviceList.getFirstItem());
728: }
729:
730: @When("^I count the devices based on the remembered query$")
731: public void countForDevices()
732: throws Exception {
733:
734: DeviceQuery tmpQuery = (DeviceQuery) stepData.get(DEVICE_QUERY);
735:
736: primeException();
737: try {
738: stepData.remove(COUNT);
739: Long deviceCount = deviceRegistryService.count(tmpQuery);
740: stepData.put(COUNT, deviceCount);
741: } catch (KapuaException ex) {
742: verifyException(ex);
743: }
744: }
745:
746: @When("^I count the devices in scope (\\d+)$")
747: public void countDevicesInScope(int scope)
748: throws Exception {
749:
750: DeviceQuery tmpQuery = deviceFactory.newQuery(getKapuaId(scope));
751:
752: primeException();
753: try {
754: stepData.remove(COUNT);
755: Long count = deviceRegistryService.count(tmpQuery);
756: stepData.put(COUNT, count);
757: } catch (KapuaException ex) {
758: verifyException(ex);
759: }
760: }
761:
762: @When("^I count devices with BIOS version \"(.*)\"$")
763: public void countDevicesWithBIOSVersion(String version)
764: throws Exception {
765:
766: DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId());
767: tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.BIOS_VERSION, version, AttributePredicate.Operator.EQUAL));
768:
769: primeException();
770: try {
771: stepData.remove(COUNT);
772: Long count = deviceRegistryService.count(tmpQuery);
773: stepData.put(COUNT, count);
774: } catch (KapuaException ex) {
775: verifyException(ex);
776: }
777: }
778:
779: @When("^I update some device parameters$")
780: public void updateDeviceParameters()
781: throws Exception {
782:
783: Device device = (Device) stepData.get(DEVICE);
784:• if (device != null) {
785: device.setBiosVersion(device.getBiosVersion() + "_upd");
786: device.setCustomAttribute1(device.getCustomAttribute1() + "_upd");
787: }
788:
789: primeException();
790: try {
791: deviceRegistryService.update(device);
792: } catch (KapuaException ex) {
793: verifyException(ex);
794: }
795: }
796:
797: @When("^I update the device cleint ID to \"(.+)\"$")
798: public void updateDeviceClientId(String newId)
799: throws Exception {
800:
801: Device device = (Device) stepData.get(DEVICE);
802: stepData.put("Text", device.getClientId());
803: device.setClientId(newId);
804:
805: primeException();
806: try {
807: deviceRegistryService.update(device);
808: } catch (KapuaException ex) {
809: verifyException(ex);
810: }
811: }
812:
813: @When("^I update a device with an invalid ID$")
814: public void updateDeviceWithInvalidId()
815: throws Exception {
816:
817: Device device = (Device) stepData.get(DEVICE);
818: device.setId(getKapuaId());
819:
820: primeException();
821: try {
822: deviceRegistryService.update(device);
823: } catch (KapuaException ex) {
824: verifyException(ex);
825: }
826: }
827:
828: @When("^I delete the device with the remembered ID$")
829: public void deleteDeviceWithRememberedId()
830: throws Exception {
831:
832: KapuaId deviceId = (KapuaId) stepData.get(DEVICE_ID);
833:
834: primeException();
835: try {
836: deviceRegistryService.delete(getCurrentScopeId(), deviceId);
837: } catch (KapuaException ex) {
838: verifyException(ex);
839: }
840: }
841:
842: @When("^I delete the device with the clientId \"(.+)\"$")
843: public void deleteDeviceWithClientId(String clientId)
844: throws Exception {
845:
846: try {
847: primeException();
848: DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId());
849: tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, clientId, AttributePredicate.Operator.EQUAL));
850: DeviceListResult deviceList = deviceRegistryService.query(tmpQuery);
851: Device device = deviceList.getFirstItem();
852: deviceRegistryService.delete(getCurrentScopeId(), device.getId());
853:
854: } catch (KapuaException ex) {
855: verifyException(ex);
856: }
857: }
858:
859: @When("^When I delete a device with nonexisting ID$")
860: public void deleteDeviceWithRandomIds()
861: throws Exception {
862:
863: primeException();
864: try {
865: deviceRegistryService.delete(getKapuaId(), getKapuaId());
866: } catch (KapuaException ex) {
867: verifyException(ex);
868: }
869: }
870:
871: @Then("^The device has a non-null ID$")
872: public void checkCreatedDeviceId() {
873:
874: DeviceCreator deviceCreator = (DeviceCreator) stepData.get(DEVICE_CREATOR);
875: Device device = (Device) stepData.get(DEVICE);
876:
877: assertNotNull(device.getId());
878: assertEquals(deviceCreator.getScopeId(), device.getScopeId());
879: assertEquals(deviceCreator.getClientId(), device.getClientId());
880: }
881:
882: @Then("^It is possible to find the device based on its registry ID$")
883: public void findDeviceByRememberedId()
884: throws Exception {
885:
886: Device device = (Device) stepData.get(DEVICE);
887:
888: primeException();
889: try {
890: Device tmpDev = deviceRegistryService.find(getCurrentScopeId(), device.getId());
891: assertEquals(device.getClientId(), tmpDev.getClientId());
892: } catch (KapuaException ex) {
893: verifyException(ex);
894: }
895: }
896:
897: @Then("^I find the device based on clientID \"([^\"]*)\"$")
898: public void findDeviceByRememberedClientId(String clientID)
899: throws Exception {
900:
901: Device device = (Device) stepData.get(DEVICE);
902:
903: primeException();
904: try {
905: Device tmpDev = deviceRegistryService.findByClientId(getCurrentScopeId(), clientID);
906: assertEquals(device.getId(), tmpDev.getId());
907: } catch (KapuaException ex) {
908: verifyException(ex);
909: }
910: }
911:
912: @Then("^Named device registry searches are case sensitive$")
913: public void checkCaseSensitivnessOfRegistrySearches()
914: throws Exception {
915:
916: DeviceCreator deviceCreator = (DeviceCreator) stepData.get(DEVICE_CREATOR);
917:
918: primeException();
919: try {
920: assertNull(deviceRegistryService.findByClientId(getCurrentScopeId(), deviceCreator.getClientId().toLowerCase()));
921: assertNull(deviceRegistryService.findByClientId(getCurrentScopeId(), deviceCreator.getClientId().toUpperCase()));
922: assertNotNull(deviceRegistryService.findByClientId(getCurrentScopeId(), deviceCreator.getClientId()));
923: } catch (KapuaException ex) {
924: verifyException(ex);
925: }
926: }
927:
928: @Then("^The device matches the creator parameters$")
929: public void checkCreatedDeviceAgainstCreatorParameters() {
930:
931: DeviceCreator deviceCreator = (DeviceCreator) stepData.get(DEVICE_CREATOR);
932: Device device = (Device) stepData.get(DEVICE);
933:
934: assertNotNull(device.getId());
935: assertEquals(deviceCreator.getScopeId(), device.getScopeId());
936: assertEquals(deviceCreator.getClientId().length(), device.getClientId().length());
937: assertEquals(deviceCreator.getClientId(), device.getClientId());
938: assertEquals(deviceCreator.getConnectionId(), device.getConnectionId());
939: assertEquals(deviceCreator.getDisplayName(), device.getDisplayName());
940: assertEquals(deviceCreator.getSerialNumber(), device.getSerialNumber());
941: assertEquals(deviceCreator.getModelId(), device.getModelId());
942: assertEquals(deviceCreator.getModelName(), device.getModelName());
943: assertEquals(deviceCreator.getImei(), device.getImei());
944: assertEquals(deviceCreator.getImsi(), device.getImsi());
945: assertEquals(deviceCreator.getIccid(), device.getIccid());
946: assertEquals(deviceCreator.getBiosVersion(), device.getBiosVersion());
947: assertEquals(deviceCreator.getFirmwareVersion(), device.getFirmwareVersion());
948: assertEquals(deviceCreator.getOsVersion(), device.getOsVersion());
949: assertEquals(deviceCreator.getJvmVersion(), device.getJvmVersion());
950: assertEquals(deviceCreator.getOsgiFrameworkVersion(), device.getOsgiFrameworkVersion());
951: assertEquals(deviceCreator.getApplicationFrameworkVersion(), device.getApplicationFrameworkVersion());
952: assertEquals(deviceCreator.getApplicationIdentifiers(), device.getApplicationIdentifiers());
953: assertEquals(deviceCreator.getAcceptEncoding(), device.getAcceptEncoding());
954: assertEquals(deviceCreator.getCustomAttribute1(), device.getCustomAttribute1());
955: assertEquals(deviceCreator.getCustomAttribute2(), device.getCustomAttribute2());
956: assertEquals(deviceCreator.getCustomAttribute3(), device.getCustomAttribute3());
957: assertEquals(deviceCreator.getCustomAttribute4(), device.getCustomAttribute4());
958: assertEquals(deviceCreator.getCustomAttribute5(), device.getCustomAttribute5());
959: assertEquals(deviceCreator.getStatus(), device.getStatus());
960: }
961:
962: @Then("^The device was correctly updated$")
963: public void checkUpdatedDeviceAgainstOriginal()
964: throws Exception {
965:
966: Device device = (Device) stepData.get(DEVICE);
967: Device tmpDevice;
968:
969: primeException();
970: try {
971: tmpDevice = deviceRegistryService.find(device.getScopeId(), device.getId());
972: assertEquals(tmpDevice.getScopeId(), device.getScopeId());
973: assertEquals(tmpDevice.getClientId().length(), device.getClientId().length());
974: assertEquals(tmpDevice.getClientId(), device.getClientId());
975: assertEquals(tmpDevice.getConnectionId(), device.getConnectionId());
976: assertEquals(tmpDevice.getDisplayName(), device.getDisplayName());
977: assertEquals(tmpDevice.getSerialNumber(), device.getSerialNumber());
978: assertEquals(tmpDevice.getModelId(), device.getModelId());
979: assertEquals(tmpDevice.getModelName(), device.getModelName());
980: assertEquals(tmpDevice.getImei(), device.getImei());
981: assertEquals(tmpDevice.getImsi(), device.getImsi());
982: assertEquals(tmpDevice.getIccid(), device.getIccid());
983: assertEquals(tmpDevice.getBiosVersion(), device.getBiosVersion());
984: assertEquals(tmpDevice.getFirmwareVersion(), device.getFirmwareVersion());
985: assertEquals(tmpDevice.getOsVersion(), device.getOsVersion());
986: assertEquals(tmpDevice.getJvmVersion(), device.getJvmVersion());
987: assertEquals(tmpDevice.getOsgiFrameworkVersion(), device.getOsgiFrameworkVersion());
988: assertEquals(tmpDevice.getApplicationFrameworkVersion(), device.getApplicationFrameworkVersion());
989: assertEquals(tmpDevice.getApplicationIdentifiers(), device.getApplicationIdentifiers());
990: assertEquals(tmpDevice.getAcceptEncoding(), device.getAcceptEncoding());
991: assertEquals(tmpDevice.getCustomAttribute1(), device.getCustomAttribute1());
992: assertEquals(tmpDevice.getCustomAttribute2(), device.getCustomAttribute2());
993: assertEquals(tmpDevice.getCustomAttribute3(), device.getCustomAttribute3());
994: assertEquals(tmpDevice.getCustomAttribute4(), device.getCustomAttribute4());
995: assertEquals(tmpDevice.getCustomAttribute5(), device.getCustomAttribute5());
996: assertEquals(tmpDevice.getStatus(), device.getStatus());
997: } catch (KapuaException ex) {
998: verifyException(ex);
999: }
1000: }
1001:
1002: @Then("^The device client id is \"(.*)\"$")
1003: public void checkDeviceClientName(String name) {
1004:
1005: Device device = (Device) stepData.get(DEVICE);
1006: assertEquals(name, device.getClientId());
1007: }
1008:
1009: @Then("^I find (\\d+) devices?$")
1010: public void checkListForNumberOfItems(int number) {
1011:
1012: DeviceListResult deviceList = (DeviceListResult) stepData.get(DEVICE_LIST);
1013: assertEquals(number, deviceList.getSize());
1014: }
1015:
1016: @Then("^I find device \"([^\"]*)\"$")
1017: public void iFindDeviceWithTag(String deviceName) {
1018:
1019: DeviceListResult deviceList = (DeviceListResult) stepData.get(DEVICE_LIST);
1020: Device device = deviceList.getFirstItem();
1021:
1022: Assert.assertNotNull(device);
1023: Assert.assertEquals(deviceName, device.getClientId());
1024: }
1025:
1026: @Then("^The client ID was not changed$")
1027: public void checkDeviceClientIdForChanges()
1028: throws Exception {
1029:
1030: Device device = (Device) stepData.get(DEVICE);
1031: String stringValue = (String) stepData.get("Text");
1032:
1033: primeException();
1034: try {
1035: Device tmpDevice = deviceRegistryService.find(getCurrentScopeId(), device.getId());
1036: assertNotEquals(device.getClientId(), tmpDevice.getClientId());
1037: assertEquals(stringValue, tmpDevice.getClientId());
1038: } catch (KapuaException ex) {
1039: verifyException(ex);
1040: }
1041: }
1042:
1043: @Then("^There is no device with the client ID \"(.+)\"$")
1044: public void checkWhetherNamedDeviceStillExists(String clientId)
1045: throws KapuaException {
1046: Device tmpDevice = deviceRegistryService.findByClientId(getCurrentScopeId(), clientId);
1047: assertNull(tmpDevice);
1048: }
1049:
1050: @Then("^There is no such device$")
1051: public void noSuchDevice() {
1052:
1053: assertNull(stepData.get(DEVICE));
1054: }
1055:
1056: @Then("^I find the device$")
1057: public void deviceIsNotNull() {
1058:
1059: assertNotNull(stepData.get(DEVICE));
1060: }
1061:
1062: @Then("^All device factory functions must return non null values$")
1063: public void exerciseAllDeviceFactoryFunctions() {
1064: Device tmpDevice;
1065: DeviceCreator tmpCreator;
1066: DeviceQuery tmpQuery;
1067: DeviceListResult tmpListRes;
1068:
1069: tmpDevice = deviceFactory.newEntity(SYS_SCOPE_ID);
1070: tmpCreator = deviceFactory.newCreator(SYS_SCOPE_ID, "TestDevice");
1071: tmpQuery = deviceFactory.newQuery(SYS_SCOPE_ID);
1072: tmpListRes = deviceFactory.newListResult();
1073:
1074: assertNotNull(tmpDevice);
1075: assertNotNull(tmpCreator);
1076: assertNotNull(tmpQuery);
1077: assertNotNull(tmpListRes);
1078: }
1079:
1080: // ************************************************************************************
1081: // * Device Connection steps *
1082: // ************************************************************************************
1083:
1084: @When("^I configure the device connection service$")
1085: public void setDeviceConnectionConfigurationValue(List<CucConfig> cucConfigs) throws Exception {
1086:
1087: Map<String, Object> valueMap = new HashMap<>();
1088: KapuaId accId = getCurrentScopeId();
1089: KapuaId scopeId = getCurrentParentId();
1090:
1091:• for (CucConfig config : cucConfigs) {
1092: config.addConfigToMap(valueMap);
1093:• if (config.getParentId() != null) {
1094: scopeId = getKapuaId(config.getParentId());
1095: }
1096:• if (config.getScopeId() != null) {
1097: accId = getKapuaId(config.getScopeId());
1098: }
1099: }
1100:
1101: primeException();
1102: try {
1103: deviceConnectionService.setConfigValues(accId, scopeId, valueMap);
1104: } catch (KapuaException ke) {
1105: verifyException(ke);
1106: }
1107: }
1108:
1109: @Given("^A regular connection creator$")
1110: public void createRegularCreator() {
1111:
1112: DeviceConnectionCreator connectionCreator = prepareRegularConnectionCreator(SYS_SCOPE_ID, getKapuaId());
1113: stepData.put(DEVICE_CONNECTION_CREATOR, connectionCreator);
1114: }
1115:
1116: @Given("^A connection for scope (d+)$")
1117: public void createConnectionInScope(int scope)
1118: throws Exception {
1119:
1120: DeviceConnectionCreator tmpCreator = prepareRegularConnectionCreator(getKapuaId(scope), getKapuaId());
1121:
1122: primeException();
1123: try {
1124: stepData.remove(DEVICE_CONNECTION);
1125: DeviceConnection connection = deviceConnectionService.create(tmpCreator);
1126: stepData.put(DEVICE_CONNECTION, connection);
1127: } catch (KapuaException ke) {
1128: verifyException(ke);
1129: }
1130: }
1131:
1132: @Given("^I have the following connection(?:|s)$")
1133: public void createConnections(List<CucConnection> connections)
1134: throws Exception {
1135:
1136: KapuaId scopeId = getCurrentScopeId();
1137: KapuaId userId = getCurrentUserId();
1138:
1139: primeException();
1140: try {
1141: DeviceConnectionCreator connectionCreator = null;
1142: DeviceConnection connection = null;
1143: stepData.remove(DEVICE_CONNECTION);
1144: stepData.remove(DEVICE_CONNECTION_ID);
1145: stepData.remove(DEVICE_CONNECTION_LIST);
1146:
1147:• for (CucConnection connItem : connections) {
1148: connectionCreator = deviceConnectionFactory.newCreator(scopeId);
1149: connectionCreator.setStatus(DeviceConnectionStatus.CONNECTED);
1150: connectionCreator.setUserId(userId);
1151: connectionCreator.setUserCouplingMode(ConnectionUserCouplingMode.LOOSE);
1152: connectionCreator.setClientId(connItem.getClientId());
1153: connectionCreator.setClientIp(connItem.getClientIp());
1154: connectionCreator.setServerIp(connItem.getServerIp());
1155: connectionCreator.setProtocol(connItem.getProtocol());
1156: connectionCreator.setAllowUserChange(false);
1157: connection = deviceConnectionService.create(connectionCreator);
1158: }
1159:
1160: stepData.put(DEVICE_CONNECTION_CREATOR, connectionCreator);
1161: stepData.put(DEVICE_CONNECTION, connection);
1162: stepData.put(DEVICE_CONNECTION_ID, connection.getId());
1163: DeviceConnectionListResult connList = deviceConnectionFactory.newListResult();
1164: Vector<DeviceConnection> vec = new Vector<>();
1165: vec.add(connection);
1166: connList.addItems(vec);
1167: stepData.put(DEVICE_CONNECTION_LIST, connList);
1168: } catch (KapuaException ex) {
1169: verifyException(ex);
1170: }
1171: }
1172:
1173: @Given("^I modify the connection details to$")
1174: public void updateConnectionDetails(List<CucConnection> connections)
1175: throws Exception {
1176:
1177: // Only a single connection must be specified for this test!
1178: assertNotNull(connections);
1179: assertEquals(1, connections.size());
1180:
1181: DeviceConnection connection = (DeviceConnection) stepData.get(DEVICE_CONNECTION);
1182: DeviceConnectionCreator connectionCreator = (DeviceConnectionCreator) stepData.get(DEVICE_CONNECTION_CREATOR);
1183:
1184: primeException();
1185: try {
1186: stepData.remove(DEVICE_CONNECTION);
1187: stepData.remove(DEVICE_CONNECTION_CREATOR);
1188:
1189: // try to modify the existing connection
1190: // Slight workaround for cucumber limitations: Remember the desired
1191: // connection settings via the global connectionCreator variable
1192:• if (connections.get(0).getClientId() != null) {
1193: connection.setClientId(connections.get(0).getClientId());
1194: connectionCreator.setClientId(connections.get(0).getClientId());
1195: }
1196:• if (connections.get(0).getClientIp() != null) {
1197: connection.setClientIp(connections.get(0).getClientIp());
1198: connectionCreator.setClientIp(connections.get(0).getClientIp());
1199: }
1200:• if (connections.get(0).getServerIp() != null) {
1201: connection.setServerIp(connections.get(0).getServerIp());
1202: connectionCreator.setServerIp(connections.get(0).getServerIp());
1203: }
1204:• if (connections.get(0).getProtocol() != null) {
1205: connection.setProtocol(connections.get(0).getProtocol());
1206: connectionCreator.setProtocol(connections.get(0).getProtocol());
1207: }
1208: DeviceConnection newConnection = deviceConnectionService.update(connection);
1209:
1210: stepData.put(DEVICE_CONNECTION, newConnection);
1211: stepData.put(DEVICE_CONNECTION_CREATOR, connectionCreator);
1212: } catch (KapuaException ex) {
1213: verifyException(ex);
1214: }
1215: }
1216:
1217: @When("^I try to modify the connection client Id to \"(.+)\"$")
1218: public void changeConnectionClientId(String client)
1219: throws Exception {
1220:
1221: DeviceConnection connection = (DeviceConnection) stepData.get(DEVICE_CONNECTION);
1222: // Remember the old client ID for later checking
1223: stepData.put("Text", connection.getClientId());
1224: // Update the connection client ID
1225: connection.setClientId(client);
1226:
1227: primeException();
1228: try {
1229: DeviceConnection newConnection = deviceConnectionService.update(connection);
1230: stepData.put(DEVICE_CONNECTION, newConnection);
1231: } catch (KapuaException ex) {
1232: verifyException(ex);
1233: }
1234: }
1235:
1236: @When("^I try to modify the connection Id$")
1237: public void changeConnectionIdRandomly()
1238: throws Exception {
1239:
1240: DeviceConnection connection = (DeviceConnection) stepData.get(DEVICE_CONNECTION);
1241: // Try to update the connection ID
1242: connection.setId(getKapuaId());
1243:
1244: primeException();
1245: try {
1246: deviceConnectionService.update(connection);
1247: } catch (KapuaException ex) {
1248: // Since the ID is not updatable there should be an exception
1249: verifyException(ex);
1250: }
1251: }
1252:
1253: @When("^I create a new connection from the existing creator$")
1254: public void createConnectionFromExistingCreator()
1255: throws Exception {
1256:
1257: DeviceConnectionCreator connectionCreator = (DeviceConnectionCreator) stepData.get(DEVICE_CONNECTION_CREATOR);
1258:
1259: primeException();
1260: try {
1261: stepData.remove(DEVICE_CONNECTION);
1262: DeviceConnection connection = deviceConnectionService.create(connectionCreator);
1263: stepData.put(DEVICE_CONNECTION, connection);
1264: } catch (KapuaException ex) {
1265: verifyException(ex);
1266: }
1267: }
1268:
1269: @Then("^The connection object is regular$")
1270: public void checkConnectionObject() {
1271:
1272: DeviceConnection connection = (DeviceConnection) stepData.get(DEVICE_CONNECTION);
1273: assertNotNull(connection);
1274: assertNotNull(connection.getId());
1275: }
1276:
1277: @Then("^The connection object matches the creator$")
1278: public void checkConnectionObjectAgainstCreator() {
1279:
1280: DeviceConnection connection = (DeviceConnection) stepData.get(DEVICE_CONNECTION);
1281: DeviceConnectionCreator connectionCreator = (DeviceConnectionCreator) stepData.get(DEVICE_CONNECTION_CREATOR);
1282:
1283: assertNotNull(connection);
1284: assertNotNull(connectionCreator);
1285: assertEquals(connectionCreator.getScopeId(), connection.getScopeId());
1286: assertEquals(connectionCreator.getClientId(), connection.getClientId());
1287: assertEquals(connectionCreator.getUserId(), connection.getUserId());
1288: assertEquals(connectionCreator.getUserCouplingMode(), connection.getUserCouplingMode());
1289: assertEquals(connectionCreator.getReservedUserId(), connection.getReservedUserId());
1290: assertEquals(connectionCreator.getAllowUserChange(), connection.getAllowUserChange());
1291: assertEquals(connectionCreator.getClientIp(), connection.getClientIp());
1292: assertEquals(connectionCreator.getServerIp(), connection.getServerIp());
1293: assertEquals(connectionCreator.getProtocol(), connection.getProtocol());
1294: }
1295:
1296: @Then("^The connection status is \"(.+)\"$")
1297: public void checkDeviceConnectionStatus(String status) {
1298:
1299: DeviceConnectionStatus tmpStat = parseConnectionStatusString(status);
1300: DeviceConnectionListResult tmpConnLst = (DeviceConnectionListResult) stepData.get(DEVICE_CONNECTION_LIST);
1301:
1302: Assert.assertNotNull(tmpConnLst);
1303: Assert.assertNotEquals(0, tmpConnLst.getSize());
1304:
1305: DeviceConnection tmpConnection = tmpConnLst.getFirstItem();
1306: Assert.assertEquals(tmpStat, tmpConnection.getStatus());
1307: }
1308:
1309: @Then("^I count (\\d+) connections in scope (-?\\d+)$")
1310: public void countConnectioncInScope(int target, int scope)
1311: throws Exception {
1312:
1313: DeviceConnectionQuery query = deviceConnectionFactory.newQuery(getKapuaId(scope));
1314:
1315: primeException();
1316: try {
1317: long tmpCount = deviceConnectionService.count(query);
1318: assertEquals(target, tmpCount);
1319: } catch (KapuaException ex) {
1320: verifyException(ex);
1321: }
1322: }
1323:
1324: @When("^I search for a connection by scope and connection IDs$")
1325: public void findConnectionByScopeAndConnectionId()
1326: throws Exception {
1327:
1328: KapuaId scopeId = getCurrentScopeId();
1329: KapuaId connectionId = (KapuaId) stepData.get(DEVICE_CONNECTION_ID);
1330:
1331: primeException();
1332: try {
1333: stepData.remove(DEVICE_CONNECTION);
1334: DeviceConnection connection = deviceConnectionService.find(scopeId, connectionId);
1335: stepData.put(DEVICE_CONNECTION, connection);
1336: } catch (KapuaException ex) {
1337: verifyException(ex);
1338: }
1339: }
1340:
1341: @When("^I search for a random connection ID$")
1342: public void searchForARandomConnectionId()
1343: throws Exception {
1344:
1345: primeException();
1346: try {
1347: stepData.remove(DEVICE_CONNECTION);
1348: DeviceConnection connection = deviceConnectionService.find(getCurrentScopeId(), getKapuaId());
1349: stepData.put(DEVICE_CONNECTION, connection);
1350: } catch (KapuaException ex) {
1351: verifyException(ex);
1352: }
1353: }
1354:
1355: @When("^I search for a connection with the client ID \"(.+)\"$")
1356: public void findConnectionByClientId(String client)
1357: throws Exception {
1358:
1359: primeException();
1360: try {
1361: stepData.remove(DEVICE_CONNECTION);
1362: DeviceConnection connection = deviceConnectionService.findByClientId(getCurrentScopeId(), client);
1363: stepData.put(DEVICE_CONNECTION, connection);
1364: } catch (KapuaException ex) {
1365: verifyException(ex);
1366: }
1367: }
1368:
1369: @When("^I delete the existing connection$")
1370: public void deleteExistingConnection()
1371: throws Exception {
1372:
1373: DeviceConnection connection = (DeviceConnection) stepData.get(DEVICE_CONNECTION);
1374:
1375: primeException();
1376: try {
1377: deviceConnectionService.delete(connection.getScopeId(), connection.getId());
1378: stepData.remove(DEVICE_CONNECTION);
1379: } catch (KapuaException ex) {
1380: verifyException(ex);
1381: }
1382:
1383: }
1384:
1385: @When("^I try to delete a random connection ID$")
1386: public void deleteRandomConnection()
1387: throws Exception {
1388:
1389: primeException();
1390: try {
1391: deviceConnectionService.delete(getCurrentScopeId(), getKapuaId());
1392: } catch (KapuaException ex) {
1393: verifyException(ex);
1394: }
1395: }
1396:
1397: @When("^I query for all connections with the parameter \"(.+)\" set to \"(.+)\"$")
1398: public void cueryForConnections(String parameter, String value)
1399: throws Exception {
1400:
1401: DeviceConnectionQuery query = deviceConnectionFactory.newQuery(getCurrentScopeId());
1402: query.setPredicate(query.attributePredicate(parameter, value, AttributePredicate.Operator.EQUAL));
1403:
1404: primeException();
1405: try {
1406: stepData.remove(DEVICE_CONNECTION_LIST);
1407: DeviceConnectionListResult connectionList = deviceConnectionService.query(query);
1408: assertNotNull(connectionList);
1409: stepData.put(DEVICE_CONNECTION_LIST, connectionList);
1410: } catch (KapuaException ex) {
1411: verifyException(ex);
1412: }
1413: }
1414:
1415: @Then("^I find (\\d+) connections?$")
1416: public void checkResultListLength(int num) {
1417:
1418: DeviceConnectionListResult connectionList = (DeviceConnectionListResult) stepData.get(DEVICE_CONNECTION_LIST);
1419: assertNotNull(connectionList);
1420: assertEquals(num, connectionList.getSize());
1421: }
1422:
1423: @Then("^The connection details match$")
1424: public void checkConnectionDetails(List<CucConnection> connections) {
1425:
1426: DeviceConnection connection = (DeviceConnection) stepData.get(DEVICE_CONNECTION);
1427: // Only a single connection must be specified for this test!
1428: assertNotNull(connections);
1429: assertEquals(1, connections.size());
1430: // Slight workaround for cucumber limitations: The connection settings are
1431: // remembered via the global connection variable
1432:• if (connections.get(0).getClientId() != null) {
1433: assertEquals(connections.get(0).getClientId(), connection.getClientId());
1434: }
1435:• if (connections.get(0).getClientIp() != null) {
1436: assertEquals(connections.get(0).getClientIp(), connection.getClientIp());
1437: }
1438:• if (connections.get(0).getServerIp() != null) {
1439: assertEquals(connections.get(0).getServerIp(), connection.getServerIp());
1440: }
1441:• if (connections.get(0).getProtocol() != null) {
1442: assertEquals(connections.get(0).getProtocol(), connection.getProtocol());
1443: }
1444: }
1445:
1446: @Then("^The connection client ID remains unchanged$")
1447: public void checkThatClientIdHasNotChanged() {
1448:
1449: DeviceConnection connection = (DeviceConnection) stepData.get(DEVICE_CONNECTION);
1450: String text = (String) stepData.get("Text");
1451:
1452: assertEquals(text, connection.getClientId());
1453: }
1454:
1455: @Then("^No connection was found$")
1456: public void checkThatConnectionIsNull() {
1457:
1458: assertNull(stepData.get(DEVICE_CONNECTION));
1459: }
1460:
1461: @Then("^All connection factory functions must return non null values$")
1462: public void exerciseAllConnectionFactoryFunctions() {
1463: DeviceConnectionCreator tmpCreator = null;
1464: DeviceConnectionQuery tmpQuery = null;
1465:
1466: tmpCreator = deviceConnectionFactory.newCreator(SYS_SCOPE_ID);
1467: tmpQuery = deviceConnectionFactory.newQuery(SYS_SCOPE_ID);
1468:
1469: assertNotNull(tmpCreator);
1470: assertNotNull(tmpQuery);
1471: }
1472:
1473: @Then("^The device connection domain defaults are correctly initialized$")
1474: public void checkConnectionDomainInitialization() {
1475: DeviceConnectionDomain tmpDomain = new DeviceConnectionDomain();
1476:
1477: assertEquals("device_connection", tmpDomain.getName());
1478: assertEquals(3, tmpDomain.getActions().size());
1479: assertTrue(tmpDomain.getActions().contains(Actions.read));
1480: assertTrue(tmpDomain.getActions().contains(Actions.write));
1481: assertTrue(tmpDomain.getActions().contains(Actions.delete));
1482: }
1483:
1484: @Then("^The device connection domain data can be updated$")
1485: public void checkDeviceConnectionDomainUpdate() {
1486:
1487: Domain tmpDomain = new TestDomain();
1488: tmpDomain.setName(TEST_DEVICE_NAME);
1489: tmpDomain.setActions(new HashSet<>(Lists.newArrayList(Actions.connect, Actions.execute)));
1490:
1491: assertEquals(TEST_DEVICE_NAME, tmpDomain.getName());
1492: assertEquals(2, tmpDomain.getActions().size());
1493: assertTrue(tmpDomain.getActions().contains(Actions.connect));
1494: assertTrue(tmpDomain.getActions().contains(Actions.execute));
1495: }
1496:
1497: // ************************************************************************************
1498: // * Device Event steps *
1499: // ************************************************************************************
1500:
1501: @Given("^An event creator with null action$")
1502: public void prepareCreatorWithNullAction() {
1503:
1504: DeviceEventCreator eventCreator = prepareRegularDeviceEventCreator(getCurrentScopeId(), getKapuaId());
1505: eventCreator.setAction(null);
1506:
1507: stepData.put(DEVICE_EVENT_CREATOR, eventCreator);
1508: }
1509:
1510: @Given("^A \"(.+)\" event from device \"(.+)\"$")
1511: public void createRegularEvent(String eventType, String clientId)
1512: throws Exception {
1513:
1514: primeException();
1515: try {
1516: Device tmpDev = getDeviceWithClientId(clientId);
1517: DeviceEventCreator eventCreator = prepareRegularDeviceEventCreator(getCurrentScopeId(), tmpDev.getId());
1518: KapuaMethod tmpMeth = getMethodFromString(eventType);
1519: eventCreator.setAction(tmpMeth);
1520: stepData.put(DEVICE_EVENT_CREATOR, eventCreator);
1521:
1522: stepData.remove(DEVICE_EVENT);
1523: stepData.remove(DEVICE_EVENT_ID);
1524: DeviceEvent event = eventService.create(eventCreator);
1525: stepData.put(DEVICE_EVENT, event);
1526: stepData.put(DEVICE_EVENT_ID, event.getId());
1527: } catch (KapuaException ex) {
1528: verifyException(ex);
1529: }
1530: }
1531:
1532: @Given("^I have (\\d+) \"(.+)\" events? from device \"(.+)\"$")
1533: public void createANumberOfEvents(int num, String eventType, String clientId)
1534: throws Exception {
1535:
1536: primeException();
1537: try {
1538: KapuaId currScopeId = getCurrentScopeId();
1539: KapuaId tmpDevId = getDeviceWithClientId(clientId).getId();
1540: KapuaMethod tmpMeth = getMethodFromString(eventType);
1541: DeviceEventCreator tmpCreator;
1542: DeviceEvent tmpEvent;
1543:
1544:• for (int i = 0; i < num; i++) {
1545: tmpCreator = prepareRegularDeviceEventCreator(currScopeId, tmpDevId);
1546: assertNotNull(tmpCreator);
1547: tmpCreator.setAction(tmpMeth);
1548: tmpEvent = eventService.create(tmpCreator);
1549: assertNotNull(tmpEvent);
1550: }
1551: } catch (KapuaException ex) {
1552: verifyException(ex);
1553: }
1554: }
1555:
1556: @When("^I create an event from the existing creator$")
1557: public void createEventFromCreator()
1558: throws Exception {
1559:
1560: DeviceEventCreator eventCreator = (DeviceEventCreator) stepData.get(DEVICE_EVENT_CREATOR);
1561:
1562: primeException();
1563: try {
1564: stepData.remove(DEVICE_EVENT);
1565: stepData.remove(DEVICE_EVENT_ID);
1566: DeviceEvent event = eventService.create(eventCreator);
1567: stepData.put(DEVICE_EVENT, event);
1568: stepData.put(DEVICE_EVENT_ID, event.getId());
1569: } catch (KapuaException ex) {
1570: verifyException(ex);
1571: }
1572: }
1573:
1574: @When("^I search for an event with the remembered ID$")
1575: public void findEventById()
1576: throws Exception {
1577:
1578: KapuaId eventId = (KapuaId) stepData.get(DEVICE_EVENT_ID);
1579:
1580: primeException();
1581: try {
1582: stepData.remove(DEVICE_EVENT);
1583: DeviceEvent event = eventService.find(getCurrentScopeId(), eventId);
1584: stepData.put(DEVICE_EVENT, event);
1585: } catch (KapuaException ex) {
1586: verifyException(ex);
1587: }
1588: }
1589:
1590: @When("^I search for an event with a random ID$")
1591: public void findEventByRandomId()
1592: throws Exception {
1593:
1594: primeException();
1595: try {
1596: stepData.remove(DEVICE_EVENT);
1597: DeviceEvent event = eventService.find(getCurrentScopeId(), getKapuaId());
1598: stepData.put(DEVICE_EVENT, event);
1599: } catch (KapuaException ex) {
1600: verifyException(ex);
1601: }
1602: }
1603:
1604: @When("^I delete the event with the remembered ID$")
1605: public void deleteEvent()
1606: throws Exception {
1607:
1608: KapuaId eventId = (KapuaId) stepData.get(DEVICE_EVENT_ID);
1609:
1610: primeException();
1611: try {
1612: eventService.delete(getCurrentScopeId(), eventId);
1613: stepData.remove(DEVICE_EVENT);
1614: } catch (KapuaException ex) {
1615: verifyException(ex);
1616: }
1617: }
1618:
1619: @When("^I delete an event with a random ID$")
1620: public void deleteEventWithRandomId()
1621: throws Exception {
1622:
1623: primeException();
1624: try {
1625: eventService.delete(getCurrentScopeId(), getKapuaId());
1626: } catch (KapuaException ex) {
1627: verifyException(ex);
1628: }
1629: }
1630:
1631: @When("^I count events for scope (\\d+)$")
1632: public void countEventsInScope(int scpId)
1633: throws Exception {
1634:
1635: DeviceEventQuery tmpQuery = eventFactory.newQuery(getKapuaId(scpId));
1636:
1637: primeException();
1638: try {
1639: stepData.remove(COUNT);
1640: Long count = eventService.count(tmpQuery);
1641: stepData.put(COUNT, count);
1642: } catch (KapuaException ex) {
1643: verifyException(ex);
1644: }
1645: }
1646:
1647: @When("^I query for \"(.+)\" events$")
1648: public void queryForSpecificEvents(String eventType)
1649: throws Exception {
1650:
1651: DeviceEventQuery tmpQuery = eventFactory.newQuery(getCurrentScopeId());
1652: assertNotNull(tmpQuery);
1653: KapuaMethod tmpMeth = getMethodFromString(eventType);
1654: assertNotNull(tmpMeth);
1655: tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceEventAttributes.ACTION, tmpMeth, AttributePredicate.Operator.EQUAL));
1656:
1657: primeException();
1658: try {
1659: stepData.remove(DEVICE_EVENT_LIST);
1660: DeviceEventListResult eventList = eventService.query(tmpQuery);
1661: stepData.put(DEVICE_EVENT_LIST, eventList);
1662: } catch (KapuaException ex) {
1663: verifyException(ex);
1664: }
1665: }
1666:
1667: @And("^I untag device with \"([^\"]*)\" tag$")
1668: public void iDeleteTag(String deviceTagName) throws Throwable {
1669:
1670: Tag foundTag = (Tag) stepData.get("tag");
1671: Assert.assertEquals(deviceTagName, foundTag.getName());
1672: Device device = (Device) stepData.get(DEVICE);
1673: stepData.remove("tag");
1674: stepData.remove("tags");
1675: Set<KapuaId> tags = new HashSet<>();
1676: device.setTagIds(tags);
1677: Device updatedDevice = deviceRegistryService.update(device);
1678: stepData.put(DEVICE, updatedDevice);
1679: Assert.assertEquals(device.getTagIds().isEmpty(), true);
1680: }
1681:
1682: @And("^I verify that tag \"([^\"]*)\" is deleted$")
1683: public void iVerifyTagIsDeleted(String deviceTagName) throws Throwable {
1684:
1685: Tag foundTag = (Tag) stepData.get("tag");
1686: Assert.assertEquals(null, foundTag);
1687: }
1688:
1689: @When("^I search for events from device \"(.+)\" in account \"(.+)\"$")
1690: public void searchForEventsFromDeviceWithClientID(String clientId, String account)
1691: throws Exception {
1692:
1693: DeviceEventQuery tmpQuery;
1694: Device tmpDev;
1695: DeviceEventListResult tmpList;
1696: Account tmpAcc;
1697:
1698: try {
1699: tmpAcc = accountService.findByName(account);
1700: Assert.assertNotNull(tmpAcc);
1701: Assert.assertNotNull(tmpAcc.getId());
1702:
1703: tmpDev = deviceRegistryService.findByClientId(tmpAcc.getId(), clientId);
1704: Assert.assertNotNull(tmpDev);
1705: Assert.assertNotNull(tmpDev.getId());
1706:
1707: tmpQuery = eventFactory.newQuery(tmpAcc.getId());
1708: tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceEventAttributes.DEVICE_ID, tmpDev.getId(), AttributePredicate.Operator.EQUAL));
1709: tmpQuery.setSortCriteria(tmpQuery.fieldSortCriteria(DeviceEventAttributes.RECEIVED_ON, SortOrder.ASCENDING));
1710: tmpList = eventService.query(tmpQuery);
1711:
1712: Assert.assertNotNull(tmpList);
1713: stepData.put(DEVICE_EVENT_LIST, tmpList);
1714: } catch (KapuaException ex) {
1715: verifyException(ex);
1716: }
1717: }
1718:
1719: @Then("^The event matches the creator parameters$")
1720: public void checkCreatedEventAgainstCreatorParameters() {
1721:
1722: DeviceEventCreator eventCreator = (DeviceEventCreator) stepData.get(DEVICE_EVENT_CREATOR);
1723: DeviceEvent event = (DeviceEvent) stepData.get(DEVICE_EVENT);
1724:
1725: assertNotNull(event.getId());
1726: assertEquals(eventCreator.getScopeId(), event.getScopeId());
1727: assertEquals(eventCreator.getDeviceId(), event.getDeviceId());
1728: assertEquals(eventCreator.getSentOn(), event.getSentOn());
1729: assertEquals(eventCreator.getReceivedOn(), event.getReceivedOn());
1730: assertEquals(eventCreator.getResource(), event.getResource());
1731: assertEquals(eventCreator.getResponseCode(), event.getResponseCode());
1732: assertEquals(eventCreator.getEventMessage(), event.getEventMessage());
1733: assertEquals(eventCreator.getAction(), event.getAction());
1734: assertEquals(eventCreator.getPosition().toDisplayString(),
1735: event.getPosition().toDisplayString());
1736: }
1737:
1738: @Then("^The type of the last event is \"(.+)\"$")
1739: public void checkLastEventType(String type) {
1740:
1741: DeviceEventListResult tmpList;
1742:
1743: Assert.assertNotNull(stepData.get(DEVICE_EVENT_LIST));
1744: Assert.assertNotEquals(0, ((DeviceEventListResult) stepData.get(DEVICE_EVENT_LIST)).getSize());
1745: tmpList = (DeviceEventListResult) stepData.get(DEVICE_EVENT_LIST);
1746: Assert.assertEquals(type.trim().toUpperCase(), tmpList.getItem(tmpList.getSize() - 1).getResource().trim().toUpperCase());
1747: }
1748:
1749: @Then("^I find (\\d+) device event(?:|s)?$")
1750: public void checkEventListForNumberOfItems(int numberOfEvents) {
1751:
1752: DeviceEventListResult eventList = (DeviceEventListResult) stepData.get(DEVICE_EVENT_LIST);
1753: assertEquals(numberOfEvents, eventList.getSize());
1754: }
1755:
1756: @Then("^I find (\\d+) or more device event(?:|s)?$")
1757: public void checkEventList(int number) {
1758:
1759: DeviceEventListResult eventList = (DeviceEventListResult) stepData.get(DEVICE_EVENT_LIST);
1760:• assertTrue(eventList.getSize() >= number);
1761: }
1762:
1763: @Then("^There is no such event$")
1764: public void eventIsNull() {
1765:
1766: assertNull(stepData.get(DEVICE_EVENT));
1767: }
1768:
1769: @Then("^All device event factory functions must return non null objects$")
1770: public void exerciseAllEventFactoryFunctions() {
1771: DeviceEvent tmpEvent = null;
1772: DeviceEventCreator tmpCreator = null;
1773: DeviceEventQuery tmpQuery = null;
1774: DeviceEventListResult tmpList = null;
1775:
1776: tmpEvent = eventFactory.newEntity(SYS_SCOPE_ID);
1777: tmpCreator = eventFactory.newCreator(SYS_SCOPE_ID, getKapuaId(), new Date(), "");
1778: tmpQuery = eventFactory.newQuery(SYS_SCOPE_ID);
1779: tmpList = eventFactory.newListResult();
1780:
1781: assertNotNull(tmpEvent);
1782: assertNotNull(tmpCreator);
1783: assertNotNull(tmpQuery);
1784: assertNotNull(tmpList);
1785: }
1786:
1787: @Then("^The device event domain data can be updated$")
1788: public void checkDeviceEventDomainUpdate() {
1789: Domain tmpDomain = new TestDomain();
1790:
1791: tmpDomain.setName(TEST_DEVICE_NAME);
1792: tmpDomain.setActions(new HashSet<>(Lists.newArrayList(Actions.connect, Actions.execute)));
1793:
1794: assertEquals(TEST_DEVICE_NAME, tmpDomain.getName());
1795: assertEquals(2, tmpDomain.getActions().size());
1796: assertTrue(tmpDomain.getActions().contains(Actions.connect));
1797: assertTrue(tmpDomain.getActions().contains(Actions.execute));
1798: }
1799:
1800: // ************************************************************************************
1801: // * Device integration steps *
1802: // ************************************************************************************
1803:
1804: @When("^I search for the device \"(.+)\" in account \"(.+)\"$")
1805: public void searchForDeviceWithClientID(String clientId, String account)
1806: throws Exception {
1807:
1808: DeviceListResult tmpList = deviceFactory.newListResult();
1809:
1810: primeException();
1811: try {
1812: stepData.remove(DEVICE);
1813: stepData.remove(DEVICE_LIST);
1814: Account tmpAcc = accountService.findByName(account);
1815: Device tmpDev = deviceRegistryService.findByClientId(tmpAcc.getId(), clientId);
1816:• if (tmpDev != null) {
1817: Vector<Device> dv = new Vector<>();
1818: dv.add(tmpDev);
1819: tmpList.addItems(dv);
1820: }
1821: stepData.put(DEVICE, tmpDev);
1822: stepData.put(DEVICE_LIST, tmpList);
1823: } catch (KapuaException ex) {
1824: verifyException(ex);
1825: }
1826: }
1827:
1828: @And("^I tag device with \"([^\"]*)\" tag$")
1829: public void iTagDeviceWithTag(String deviceTagName)
1830: throws Exception {
1831:
1832: Account account = (Account) stepData.get(LAST_ACCOUNT);
1833: Device device = (Device) stepData.get(DEVICE);
1834:
1835: primeException();
1836: try {
1837: TagCreator tagCreator = tagFactory.newCreator(account.getId());
1838: tagCreator.setName(deviceTagName);
1839: Tag tag = tagService.create(tagCreator);
1840: Set<KapuaId> tags = new HashSet<>();
1841: tags.add(tag.getId());
1842: device.setTagIds(tags);
1843: Device updatedDevice = deviceRegistryService.update(device);
1844: stepData.put("tag", tag);
1845: stepData.put("tags", tags);
1846: stepData.put(DEVICE, updatedDevice);
1847: } catch (KapuaException ex) {
1848: verifyException(ex);
1849: }
1850: }
1851:
1852: @When("^I search for device with tag \"([^\"]*)\"$")
1853: public void iSearchForDeviceWithTag(String deviceTagName)
1854: throws Exception {
1855:
1856: Account lastAcc = (Account) stepData.get(LAST_ACCOUNT);
1857: DeviceQuery deviceQuery = deviceFactory.newQuery(lastAcc.getId());
1858: TagQuery tagQuery = tagFactory.newQuery(lastAcc.getId());
1859: tagQuery.setPredicate(tagQuery.attributePredicate(TagAttributes.NAME, deviceTagName, AttributePredicate.Operator.EQUAL));
1860:
1861: primeException();
1862: try {
1863: stepData.remove(DEVICE_LIST);
1864: TagListResult tagQueryResult = tagService.query(tagQuery);
1865: Tag tag = tagQueryResult.getFirstItem();
1866: deviceQuery.setPredicate(deviceQuery.attributePredicate(DeviceAttributes.TAG_IDS, tag.getId(), AttributePredicate.Operator.EQUAL));
1867: DeviceListResult deviceList = deviceRegistryService.query(deviceQuery);
1868: stepData.put(DEVICE_LIST, deviceList);
1869: } catch (KapuaException ex) {
1870: verifyException(ex);
1871: }
1872: }
1873:
1874: @Given("^A birth message from device \"(.+)\"$")
1875: public void createABirthMessage(String clientId)
1876: throws KapuaException {
1877:
1878: Account tmpAccount = (Account) stepData.get(LAST_ACCOUNT);
1879:
1880: Assert.assertNotNull(clientId);
1881: Assert.assertFalse(clientId.isEmpty());
1882: Assert.assertNotNull(tmpAccount);
1883: Assert.assertNotNull(tmpAccount.getId());
1884:
1885: Device tmpDev;
1886: List<String> tmpSemParts = new ArrayList<>();
1887: KapuaBirthMessage tmpMsg = lifecycleMessageFactory.newKapuaBirthMessage();
1888: KapuaBirthChannel tmpChan = lifecycleMessageFactory.newKapuaBirthChannel();
1889: KapuaBirthPayload tmpPayload = prepareDefaultBirthPayload();
1890:
1891: tmpChan.setClientId(clientId);
1892: tmpSemParts.add(PART1);
1893: tmpSemParts.add(PART2);
1894: tmpChan.setSemanticParts(tmpSemParts);
1895:
1896: tmpMsg.setChannel(tmpChan);
1897: tmpMsg.setPayload(tmpPayload);
1898: tmpMsg.setScopeId(tmpAccount.getId());
1899: tmpMsg.setClientId(clientId);
1900: tmpMsg.setId(UUID.randomUUID());
1901: tmpMsg.setReceivedOn(new Date());
1902: tmpMsg.setPosition(getDefaultPosition());
1903:
1904: tmpDev = deviceRegistryService.findByClientId(tmpAccount.getId(), clientId);
1905:• if (tmpDev != null) {
1906: tmpMsg.setDeviceId(tmpDev.getId());
1907: } else {
1908: tmpMsg.setDeviceId(null);
1909: }
1910:
1911: deviceLifeCycleService.birth(null, tmpMsg);
1912: }
1913:
1914: @Given("^A disconnect message from device \"(.+)\"$")
1915: public void createADeathMessage(String clientId)
1916: throws Exception {
1917:
1918: Account tmpAccount = (Account) stepData.get(LAST_ACCOUNT);
1919: Device tmpDev;
1920: List<String> tmpSemParts = new ArrayList<>();
1921: KapuaDisconnectMessage tmpMsg = lifecycleMessageFactory.newKapuaDisconnectMessage();
1922: KapuaDisconnectChannel tmpChan = lifecycleMessageFactory.newKapuaDisconnectChannel();
1923: KapuaDisconnectPayload tmpPayload = prepareDefaultDeathPayload();
1924:
1925: tmpChan.setClientId(clientId);
1926: tmpSemParts.add(PART1);
1927: tmpSemParts.add(PART2);
1928: tmpChan.setSemanticParts(tmpSemParts);
1929:
1930: tmpMsg.setChannel(tmpChan);
1931: tmpMsg.setPayload(tmpPayload);
1932: tmpMsg.setScopeId(tmpAccount.getId());
1933: tmpMsg.setClientId(clientId);
1934: tmpMsg.setId(UUID.randomUUID());
1935: tmpMsg.setReceivedOn(new Date());
1936: tmpMsg.setPosition(getDefaultPosition());
1937:
1938: tmpDev = deviceRegistryService.findByClientId(tmpAccount.getId(), clientId);
1939:• if (tmpDev != null) {
1940: tmpMsg.setDeviceId(tmpDev.getId());
1941: } else {
1942: tmpMsg.setDeviceId(null);
1943: }
1944:
1945: try {
1946: primeException();
1947: deviceLifeCycleService.death(null, tmpMsg);
1948: } catch (KapuaException ex) {
1949: verifyException(ex);
1950: }
1951: }
1952:
1953: @Given("^A missing message from device \"(.+)\"$")
1954: public void createAMissingMessage(String clientId)
1955: throws Exception {
1956:
1957: Account tmpAccount = (Account) stepData.get(LAST_ACCOUNT);
1958: Device tmpDev;
1959: List<String> tmpSemParts = new ArrayList<>();
1960: KapuaMissingMessage tmpMsg = lifecycleMessageFactory.newKapuaMissingMessage();
1961: KapuaMissingChannel tmpChan = lifecycleMessageFactory.newKapuaMissingChannel();
1962: KapuaMissingPayload tmpPayload = prepareDefaultMissingPayload();
1963:
1964: tmpChan.setClientId(clientId);
1965: tmpSemParts.add(PART1);
1966: tmpSemParts.add(PART2);
1967: tmpChan.setSemanticParts(tmpSemParts);
1968:
1969: tmpMsg.setChannel(tmpChan);
1970: tmpMsg.setPayload(tmpPayload);
1971: tmpMsg.setScopeId(tmpAccount.getId());
1972: tmpMsg.setId(UUID.randomUUID());
1973: tmpMsg.setReceivedOn(new Date());
1974: tmpMsg.setPosition(getDefaultPosition());
1975:
1976: tmpDev = deviceRegistryService.findByClientId(tmpAccount.getId(), clientId);
1977:• if (tmpDev != null) {
1978: tmpMsg.setDeviceId(tmpDev.getId());
1979: } else {
1980: tmpMsg.setDeviceId(null);
1981: }
1982:
1983: try {
1984: primeException();
1985: deviceLifeCycleService.missing(null, tmpMsg);
1986: } catch (KapuaException ex) {
1987: verifyException(ex);
1988: }
1989: }
1990:
1991: @Given("^An application message from device \"(.+)\"$")
1992: public void createAnApplicationMessage(String clientId)
1993: throws Exception {
1994:
1995: Account tmpAccount = (Account) stepData.get(LAST_ACCOUNT);
1996: Device tmpDev;
1997: List<String> tmpSemParts = new ArrayList<>();
1998: KapuaAppsMessage tmpMsg = lifecycleMessageFactory.newKapuaAppsMessage();
1999: KapuaAppsChannel tmpChan = lifecycleMessageFactory.newKapuaAppsChannel();
2000: KapuaAppsPayload tmpPayload = prepareDefaultApplicationPayload();
2001:
2002: tmpChan.setClientId(clientId);
2003: tmpSemParts.add(PART1);
2004: tmpSemParts.add(PART2);
2005: tmpChan.setSemanticParts(tmpSemParts);
2006:
2007: tmpMsg.setChannel(tmpChan);
2008: tmpMsg.setPayload(tmpPayload);
2009: tmpMsg.setScopeId(tmpAccount.getId());
2010: tmpMsg.setId(UUID.randomUUID());
2011: tmpMsg.setReceivedOn(new Date());
2012: tmpMsg.setPosition(getDefaultPosition());
2013:
2014: tmpDev = deviceRegistryService.findByClientId(tmpAccount.getId(), clientId);
2015:• if (tmpDev != null) {
2016: tmpMsg.setDeviceId(tmpDev.getId());
2017: } else {
2018: tmpMsg.setDeviceId(null);
2019: }
2020:
2021: try {
2022: primeException();
2023: deviceLifeCycleService.applications(null, tmpMsg);
2024: } catch (KapuaException ex) {
2025: verifyException(ex);
2026: }
2027: }
2028:
2029:
2030: @Given("^Such a set of privileged users for account \"(.+)\"$")
2031: public void createPrivilegedUsers(String accName, List<CucUser> users) throws Throwable {
2032:
2033: KapuaSecurityUtils.doPrivileged(() -> {
2034: Account account = accountService.findByName(accName);
2035:
2036:• for (CucUser tmpTestUsr : users) {
2037: User tmpUser = aclCreator.createUser(account, tmpTestUsr.getName());
2038:• if ((tmpTestUsr.getPassword() != null) && !tmpTestUsr.getPassword().isEmpty()) {
2039: aclCreator.attachUserCredentials(account, tmpUser, tmpTestUsr.getPassword());
2040: } else {
2041: aclCreator.attachUserCredentials(account, tmpUser);
2042: }
2043: aclCreator.attachFullPermissions(account, tmpUser);
2044: }
2045: });
2046: }
2047:
2048: @Given("^A full set of device privileges for account \"(.+)\"$")
2049: public void setAccountDevicePrivileges(String name) throws KapuaException {
2050:
2051: KapuaSecurityUtils.doPrivileged(() -> {
2052: Account account = accountService.findByName(name);
2053:
2054: Map<String, Object> valueMap = new HashMap<>();
2055: valueMap.put("infiniteChildEntities", true);
2056: valueMap.put("maxNumberChildEntities", 1000);
2057:
2058: deviceRegistryService.setConfigValues(account.getId(), account.getScopeId(), valueMap);
2059: });
2060: }
2061:
2062: @Given("^The default connection coupling mode for account \"(.+)\" is set to \"(.+)\"$")
2063: public void setDeviceConnectionCouplingMode(String name, String mode) throws KapuaException {
2064:
2065: KapuaSecurityUtils.doPrivileged(() -> {
2066: Account account = accountService.findByName(name);
2067:
2068: Map<String, Object> valueMap = new HashMap<>();
2069: // valueMap.put("infiniteChildEntities", true);
2070: // valueMap.put("maxNumberChildEntities", 1000);
2071: valueMap.put("deviceConnectionUserCouplingDefaultMode", mode);
2072:
2073: deviceConnectionService.setConfigValues(account.getId(), account.getScopeId(), valueMap);
2074: });
2075: }
2076:
2077: @Given("^The following device connections?$")
2078: public void createConnectionForDevice(List<CucConnection> connections) throws KapuaException {
2079:
2080: KapuaSecurityUtils.doPrivileged(() -> {
2081:• for (CucConnection tmpConn : connections) {
2082: DeviceConnectionCreator tmpCreator = deviceConnectionFactory.newCreator(tmpConn.getScopeId());
2083: tmpCreator.setStatus(DeviceConnectionStatus.CONNECTED);
2084: tmpCreator.setClientId(tmpConn.getClientId());
2085: tmpCreator.setUserId(tmpConn.getUserId());
2086: tmpCreator.setReservedUserId(tmpConn.getReservedUserId());
2087: tmpCreator.setAllowUserChange(tmpConn.getAllowUserChange());
2088: tmpCreator.setUserCouplingMode(tmpConn.getUserCouplingMode());
2089:
2090: DeviceConnection tmpDevConn = deviceConnectionService.create(tmpCreator);
2091:
2092: tmpDevConn.setStatus(DeviceConnectionStatus.DISCONNECTED);
2093: deviceConnectionService.update(tmpDevConn);
2094: }
2095: });
2096: }
2097:
2098: @Given("^I wait for (\\d+) seconds?$")
2099: public void waitForSpecifiedTime(int delay) throws InterruptedException {
2100:
2101: Thread.sleep(delay * 1000);
2102: }
2103:
2104: @When("^I search for a connection from the device \"(.+)\" in account \"(.+)\"$")
2105: public void searchForConnectionFromDeviceWithClientID(String clientId, String account)
2106: throws KapuaException {
2107:
2108: KapuaSecurityUtils.doPrivileged(() -> {
2109: Account tmpAcc;
2110: DeviceConnection tmpConn;
2111: DeviceConnectionListResult tmpConnLst = deviceConnectionFactory.newListResult();
2112:
2113: tmpAcc = accountService.findByName(account);
2114: Assert.assertNotNull(tmpAcc);
2115: Assert.assertNotNull(tmpAcc.getId());
2116:
2117: tmpConn = deviceConnectionService.findByClientId(tmpAcc.getId(), clientId);
2118: Map<String, Object> props = deviceRegistryService.getConfigValues(tmpAcc.getId());
2119: stepData.put(DEVICE_CONNECTION, tmpConn);
2120:• if (tmpConn != null) {
2121: Vector<DeviceConnection> dcv = new Vector<>();
2122: dcv.add(tmpConn);
2123: tmpConnLst.addItems(dcv);
2124: }
2125: stepData.put(DEVICE_CONNECTION_LIST, tmpConnLst);
2126: });
2127: }
2128:
2129: @Then("^The connection user is \"(.+)\"$")
2130: public void checkDeviceConnectionUser(String user) throws KapuaException {
2131:
2132: KapuaSecurityUtils.doPrivileged(() -> {
2133: DeviceConnectionListResult tmpConnLst = (DeviceConnectionListResult) stepData.get(DEVICE_CONNECTION_LIST);
2134: User tmpUsr = userService.findByName(user);
2135:
2136: Assert.assertNotNull(tmpConnLst);
2137: Assert.assertNotEquals(0, tmpConnLst.getSize());
2138:
2139: DeviceConnection tmpConnection = tmpConnLst.getFirstItem();
2140: Assert.assertEquals(tmpUsr.getId(), tmpConnection.getUserId());
2141: });
2142: }
2143:
2144: @When("^I set the connection status from the device \"(.+)\" in account \"(.+)\" to \"(.+)\"$")
2145: public void modifyDeviceConnectionStatus(String device, String account, String status) throws KapuaException {
2146:
2147: KapuaSecurityUtils.doPrivileged(() -> {
2148: Account tmpAcc = accountService.findByName(account);
2149: DeviceConnection tmpConn = deviceConnectionService.findByClientId(tmpAcc.getId(), device);
2150: DeviceConnectionStatus tmpStat = parseConnectionStatusString(status);
2151:
2152: Assert.assertNotNull(tmpStat);
2153: Assert.assertNotNull(tmpConn);
2154:
2155: tmpConn.setStatus(tmpStat);
2156: deviceConnectionService.update(tmpConn);
2157: });
2158: }
2159:
2160: @When("^I set the user coupling mode for the connection from device \"(.+)\" in account \"(.+)\" to \"(.+)\"$")
2161: public void modifyDeviceConnectionCouplingMode(String device, String account, String mode) throws KapuaException {
2162:
2163: KapuaSecurityUtils.doPrivileged(() -> {
2164: ConnectionUserCouplingMode tmpMode = parseConnectionCouplingString(mode);
2165: Assert.assertNotNull(tmpMode);
2166:
2167: Account tmpAcc = accountService.findByName(account);
2168: DeviceConnection tmpConn = deviceConnectionService.findByClientId(tmpAcc.getId(), device);
2169:
2170: Assert.assertNotNull(tmpConn);
2171:
2172: tmpConn.setUserCouplingMode(tmpMode);
2173: deviceConnectionService.update(tmpConn);
2174: });
2175: }
2176:
2177: @When("^I set the user change flag for the connection from device \"(.+)\" in account \"(.+)\" to \"(.+)\"$")
2178: public void modifyDeviceConnectionUserChangeFlag(String device, String account, String flag) throws KapuaException {
2179:
2180: KapuaSecurityUtils.doPrivileged(() -> {
2181: Account tmpAcc = accountService.findByName(account);
2182: DeviceConnection tmpConn = deviceConnectionService.findByClientId(tmpAcc.getId(), device);
2183:
2184: Assert.assertNotNull(tmpConn);
2185:
2186: tmpConn.setAllowUserChange(parseBooleanFromString(flag));
2187: deviceConnectionService.update(tmpConn);
2188: });
2189: }
2190:
2191: @When("^I set the reserved user for the connection from device \"(.+)\" in account \"(.+)\" to \"(.*)\"$")
2192: public void modifyDeviceConnectionReservedUser(String device, String scope, String resUser) throws KapuaException {
2193:
2194: KapuaSecurityUtils.doPrivileged(() -> {
2195: Account tmpAcc = accountService.findByName(scope);
2196: DeviceConnection tmpConn = deviceConnectionService.findByClientId(tmpAcc.getId(), device);
2197: KapuaId userId;
2198:
2199: Assert.assertNotNull(tmpConn);
2200:
2201:• if (resUser.isEmpty() || resUser.trim().toLowerCase().contains("null")) {
2202: userId = null;
2203: } else {
2204: userId = userService.findByName(resUser).getId();
2205: }
2206:
2207: tmpConn.setReservedUserId(userId);
2208: stepData.put("ExceptionCaught", false);
2209: try {
2210: primeException();
2211: deviceConnectionService.update(tmpConn);
2212: } catch (KapuaException ex) {
2213: verifyException(ex);
2214: } catch (Exception e) {
2215: int a = 10;
2216: }
2217: });
2218: }
2219:
2220: @Then("^The user for the connection from device \"(.+)\" in scope \"(.+)\" is \"(.+)\"$")
2221: public void checkUserForExistingConnection(String device, String scope, String name) throws KapuaException {
2222:
2223: KapuaSecurityUtils.doPrivileged(() -> {
2224: Account account = accountService.findByName(scope);
2225: DeviceConnection connection = deviceConnectionService.findByClientId(account.getId(), device);
2226: User user = userService.findByName(name);
2227:
2228: Assert.assertNotNull(connection);
2229: Assert.assertNotNull(user);
2230: Assert.assertEquals(user.getId(), connection.getUserId());
2231: });
2232: }
2233:
2234: // *******************
2235: // * Private Helpers *
2236: // *******************
2237:
2238: // Create a device creator object. The creator is pre-filled with default data.
2239: private DeviceCreator prepareRegularDeviceCreator(KapuaId accountId, String client) {
2240:
2241: DeviceCreator tmpDeviceCreator = deviceFactory.newCreator(accountId, client);
2242:
2243: // tmpDeviceCreator.setConnectionId(getKapuaId());
2244: tmpDeviceCreator.setDisplayName(TEST_DEVICE_NAME);
2245: tmpDeviceCreator.setSerialNumber("serialNumber");
2246: tmpDeviceCreator.setModelId("modelId");
2247: tmpDeviceCreator.setImei(getRandomString());
2248: tmpDeviceCreator.setImsi(getRandomString());
2249: tmpDeviceCreator.setIccid(getRandomString());
2250: tmpDeviceCreator.setBiosVersion("biosVersion");
2251: tmpDeviceCreator.setFirmwareVersion("firmwareVersion");
2252: tmpDeviceCreator.setOsVersion("osVersion");
2253: tmpDeviceCreator.setJvmVersion("jvmVersion");
2254: tmpDeviceCreator.setOsgiFrameworkVersion("osgiFrameworkVersion");
2255: tmpDeviceCreator.setApplicationFrameworkVersion("kapuaVersion");
2256: tmpDeviceCreator.setApplicationIdentifiers("applicationIdentifiers");
2257: tmpDeviceCreator.setAcceptEncoding("acceptEncoding");
2258: tmpDeviceCreator.setCustomAttribute1("customAttribute1");
2259: tmpDeviceCreator.setCustomAttribute2("customAttribute2");
2260: tmpDeviceCreator.setCustomAttribute3("customAttribute3");
2261: tmpDeviceCreator.setCustomAttribute4("customAttribute4");
2262: tmpDeviceCreator.setCustomAttribute5("customAttribute5");
2263: tmpDeviceCreator.setStatus(DeviceStatus.ENABLED);
2264:
2265: return tmpDeviceCreator;
2266: }
2267:
2268: // Create a device object. The device is pre-filled with default data.
2269: private Device prepareRegularDevice(KapuaId accountId, KapuaId deviceId) {
2270:
2271: Device tmpDevice = deviceFactory.newEntity(accountId);
2272:
2273: tmpDevice.setId(deviceId);
2274: // tmpDevice.setConnectionId(getKapuaId());
2275: tmpDevice.setDisplayName(TEST_DEVICE_NAME);
2276: tmpDevice.setSerialNumber("serialNumber");
2277: tmpDevice.setModelId("modelId");
2278: tmpDevice.setImei(getRandomString());
2279: tmpDevice.setImsi(getRandomString());
2280: tmpDevice.setIccid(getRandomString());
2281: tmpDevice.setBiosVersion("biosVersion");
2282: tmpDevice.setFirmwareVersion("firmwareVersion");
2283: tmpDevice.setOsVersion("osVersion");
2284: tmpDevice.setJvmVersion("jvmVersion");
2285: tmpDevice.setOsgiFrameworkVersion("osgiFrameworkVersion");
2286: tmpDevice.setApplicationFrameworkVersion("kapuaVersion");
2287: tmpDevice.setApplicationIdentifiers("applicationIdentifiers");
2288: tmpDevice.setAcceptEncoding("acceptEncoding");
2289: tmpDevice.setCustomAttribute1("customAttribute1");
2290: tmpDevice.setCustomAttribute2("customAttribute2");
2291: tmpDevice.setCustomAttribute3("customAttribute3");
2292: tmpDevice.setCustomAttribute4("customAttribute4");
2293: tmpDevice.setCustomAttribute5("customAttribute5");
2294: tmpDevice.setStatus(DeviceStatus.ENABLED);
2295:
2296: return tmpDevice;
2297: }
2298:
2299: // Create a connection creator object. The creator is pre-filled with default data.
2300: private DeviceConnectionCreator prepareRegularConnectionCreator(KapuaId scopeId, KapuaId userId) {
2301:
2302: DeviceConnectionCreator creator = deviceConnectionFactory.newCreator(scopeId);
2303:
2304: creator.setUserId(userId);
2305: creator.setUserCouplingMode(ConnectionUserCouplingMode.LOOSE);
2306: creator.setReservedUserId(userId);
2307: creator.setClientId(CLIENT_NAME);
2308: creator.setClientIp(CLIENT_IP);
2309: creator.setServerIp(SERVER_IP);
2310: creator.setProtocol("tcp");
2311: creator.setAllowUserChange(false);
2312:
2313: return creator;
2314: }
2315:
2316: // Create a event creator object. The creator is pre-filled with default data.
2317: private DeviceEventCreator prepareRegularDeviceEventCreator(KapuaId accountId, KapuaId deviceId) {
2318:
2319: DeviceEventCreator tmpCreator = eventFactory.newCreator(accountId);
2320: KapuaPosition tmpPosition = messageFactory.newPosition();
2321: Date timeReceived = new Date();
2322: Date timeSent = new Date(System.currentTimeMillis() - 5 * 60 * 1000);
2323:
2324: tmpCreator.setDeviceId(deviceId);
2325: tmpCreator.setSentOn(timeSent);
2326: tmpCreator.setReceivedOn(timeReceived);
2327: tmpCreator.setAction(KapuaMethod.CREATE);
2328: tmpCreator.setResource("resource");
2329: tmpCreator.setResponseCode(KapuaResponseCode.ACCEPTED);
2330: tmpCreator.setEventMessage("test_message_hello_world");
2331:
2332: tmpPosition.setLatitude(46.4);
2333: tmpPosition.setLongitude(13.02);
2334: tmpPosition.setAltitude(323.0);
2335: tmpPosition.setSpeed(50.0);
2336: tmpPosition.setHeading(0.0);
2337: tmpPosition.setPrecision(0.15);
2338: tmpPosition.setSatellites(16);
2339: tmpPosition.setStatus(7);
2340: tmpPosition.setTimestamp(timeSent);
2341:
2342: tmpCreator.setPosition(tmpPosition);
2343:
2344: return tmpCreator;
2345: }
2346:
2347: private KapuaMethod getMethodFromString(String name) {
2348: KapuaMethod tmpMeth = null;
2349:
2350:• switch (name.trim().toUpperCase()) {
2351: case "READ":
2352: tmpMeth = KapuaMethod.READ;
2353: break;
2354: case "CREATE":
2355: tmpMeth = KapuaMethod.CREATE;
2356: break;
2357: case "WRITE":
2358: tmpMeth = KapuaMethod.WRITE;
2359: break;
2360: case "DELETE":
2361: tmpMeth = KapuaMethod.DELETE;
2362: break;
2363: case "OPTIONS":
2364: tmpMeth = KapuaMethod.OPTIONS;
2365: break;
2366: case "EXECUTE":
2367: tmpMeth = KapuaMethod.EXECUTE;
2368: break;
2369: }
2370: assertNotNull(tmpMeth);
2371:
2372: return tmpMeth;
2373: }
2374:
2375: private Device getDeviceWithClientId(String clientId) throws KapuaException {
2376:
2377: DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId());
2378: // Search for the known bios version string
2379: tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, clientId, AttributePredicate.Operator.EQUAL));
2380:
2381: DeviceListResult deviceList = deviceRegistryService.query(tmpQuery);
2382:
2383: return deviceList.getFirstItem();
2384: }
2385:
2386: private KapuaPosition getDefaultPosition() {
2387: KapuaPosition tmpPos = messageFactory.newPosition();
2388:
2389: tmpPos.setAltitude(250.0);
2390: tmpPos.setHeading(90.0);
2391: tmpPos.setLatitude(45.5);
2392: tmpPos.setLongitude(13.6);
2393: tmpPos.setPrecision(0.3);
2394: tmpPos.setSatellites(12);
2395: tmpPos.setSpeed(120.0);
2396: tmpPos.setStatus(2);
2397: tmpPos.setTimestamp(new Date());
2398:
2399: return tmpPos;
2400: }
2401:
2402: private KapuaBirthPayload prepareDefaultBirthPayload() {
2403:
2404: KapuaBirthPayload payload = lifecycleMessageFactory.newKapuaBirthPayload();
2405: payload.setUptime("500");
2406: payload.setDisplayName(RELIAGATE_10_20);
2407: payload.setModelName("ReliaGate");
2408: payload.setModelId(RELIAGATE_10_20);
2409: payload.setPartNumber("ABC123456");
2410: payload.setSerialNumber("12312312312");
2411: payload.setFirmware("Kura");
2412: payload.setFirmwareVersion("2.0");
2413: payload.setBios("BIOStm");
2414: payload.setBiosVersion(VERSION_NUMBER);
2415: payload.setOs(LINUX);
2416: payload.setOsVersion("4.9.18");
2417: payload.setJvm("J9");
2418: payload.setJvmVersion("2.4");
2419: payload.setJvmProfile("J8SE");
2420: payload.setContainerFramework("OSGi");
2421: payload.setContainerFrameworkVersion(VERSION_NUMBER);
2422: payload.setApplicationFramework("Kura");
2423: payload.setApplicationFrameworkVersion("2.0");
2424: payload.setConnectionInterface("eth0");
2425: payload.setConnectionIp("192.168.1.2");
2426: payload.setAcceptEncoding("gzip");
2427: payload.setApplicationIdentifiers("CLOUD-V1");
2428: payload.setAvailableProcessors("1");
2429: payload.setTotalMemory("1024");
2430: payload.setOsArch(LINUX);
2431: payload.setModemImei("123456789ABCDEF");
2432: payload.setModemImsi("123456789");
2433: payload.setModemIccid("ABCDEF");
2434:
2435: return payload;
2436: }
2437:
2438: private KapuaDisconnectPayload prepareDefaultDeathPayload() {
2439:
2440: KapuaDisconnectPayload payload = lifecycleMessageFactory.newKapuaDisconnectPayload();
2441: payload.setUptime("1000");
2442: payload.setDisplayName(RELIAGATE_10_20);
2443:
2444: return payload;
2445: }
2446:
2447: private KapuaMissingPayload prepareDefaultMissingPayload() {
2448:
2449: KapuaMissingPayload tmpPayload = lifecycleMessageFactory.newKapuaMissingPayload();
2450: return tmpPayload;
2451: }
2452:
2453: private KapuaAppsPayload prepareDefaultApplicationPayload() {
2454:
2455: KapuaAppsPayload payload = lifecycleMessageFactory.newKapuaAppsPayload();
2456: payload.setUptime("500");
2457: payload.setDisplayName(RELIAGATE_10_20);
2458: payload.setModelName("ReliaGate");
2459: payload.setModelId(RELIAGATE_10_20);
2460: payload.setPartNumber("ABC123456");
2461: payload.setSerialNumber("12312312312");
2462: payload.setFirmware("Kura");
2463: payload.setFirmwareVersion("2.0");
2464: payload.setBios("BIOStm");
2465: payload.setBiosVersion(VERSION_NUMBER);
2466: payload.setOs(LINUX);
2467: payload.setOsVersion("4.9.18");
2468: payload.setJvm("J9");
2469: payload.setJvmVersion("2.4");
2470: payload.setJvmProfile("J8SE");
2471: payload.setContainerFramework("OSGi");
2472: payload.setContainerFrameworkVersion(VERSION_NUMBER);
2473: payload.setApplicationFramework("Kura");
2474: payload.setApplicationFrameworkVersion("2.0");
2475: payload.setConnectionInterface("eth0");
2476: payload.setConnectionIp("192.168.1.2");
2477: payload.setAcceptEncoding("gzip");
2478: payload.setApplicationIdentifiers("CLOUD-V1");
2479: payload.setAvailableProcessors("1");
2480: payload.setTotalMemory("1024");
2481: payload.setOsArch(LINUX);
2482: payload.setModemImei("123456789ABCDEF");
2483: payload.setModemImsi("123456789");
2484: payload.setModemIccid("ABCDEF");
2485:
2486: return payload;
2487: }
2488:
2489: private DeviceCreator prepareDeviceCreatorFromCucDevice(CucDevice dev) {
2490: Account tmpAccount = (Account) stepData.get(LAST_ACCOUNT);
2491: DeviceCreator tmpCr;
2492: KapuaId tmpScope;
2493:
2494:• if (dev.getScopeId() != null) {
2495: tmpScope = dev.getScopeId();
2496: } else {
2497: Assert.assertNotNull(tmpAccount);
2498: Assert.assertNotNull(tmpAccount.getId());
2499: tmpScope = tmpAccount.getId();
2500: }
2501:
2502: Assert.assertNotNull(dev.getClientId());
2503: Assert.assertNotEquals(0, dev.getClientId().length());
2504:
2505: tmpCr = prepareRegularDeviceCreator(tmpScope, dev.getClientId());
2506:
2507:• if (dev.getGroupId() != null) {
2508: tmpCr.setGroupId(dev.getGroupId());
2509: }
2510:• if (dev.getConnectionId() != null) {
2511: tmpCr.setConnectionId(dev.getConnectionId());
2512: }
2513:• if (dev.getDisplayName() != null) {
2514: tmpCr.setDisplayName(dev.getDisplayName());
2515: }
2516:• if (dev.getStatus() != null) {
2517: tmpCr.setStatus(dev.getStatus());
2518: }
2519:• if (dev.getModelId() != null) {
2520: tmpCr.setModelId(dev.getModelId());
2521: }
2522:• if (dev.getSerialNumber() != null) {
2523: tmpCr.setSerialNumber(dev.getSerialNumber());
2524: }
2525:• if (dev.getImei() != null) {
2526: tmpCr.setImei(dev.getImei());
2527: }
2528:• if (dev.getImsi() != null) {
2529: tmpCr.setImsi(dev.getImsi());
2530: }
2531:• if (dev.getIccid() != null) {
2532: tmpCr.setIccid(dev.getIccid());
2533: }
2534:• if (dev.getBiosVersion() != null) {
2535: tmpCr.setBiosVersion(dev.getBiosVersion());
2536: }
2537:• if (dev.getFirmwareVersion() != null) {
2538: tmpCr.setFirmwareVersion(dev.getFirmwareVersion());
2539: }
2540:• if (dev.getOsVersion() != null) {
2541: tmpCr.setOsVersion(dev.getOsVersion());
2542: }
2543:• if (dev.getJvmVersion() != null) {
2544: tmpCr.setJvmVersion(dev.getJvmVersion());
2545: }
2546:• if (dev.getOsgiFrameworkVersion() != null) {
2547: tmpCr.setOsgiFrameworkVersion(dev.getOsgiFrameworkVersion());
2548: }
2549:• if (dev.getApplicationFrameworkVersion() != null) {
2550: tmpCr.setApplicationFrameworkVersion(dev.getApplicationFrameworkVersion());
2551: }
2552:• if (dev.getApplicationIdentifiers() != null) {
2553: tmpCr.setApplicationIdentifiers(dev.getApplicationIdentifiers());
2554: }
2555:• if (dev.getAcceptEncoding() != null) {
2556: tmpCr.setAcceptEncoding(dev.getAcceptEncoding());
2557: }
2558:
2559: return tmpCr;
2560: }
2561:
2562: DeviceConnectionStatus parseConnectionStatusString(String stat) {
2563:• switch (stat.trim().toUpperCase()) {
2564: case "CONNECTED":
2565: return DeviceConnectionStatus.CONNECTED;
2566: case "DISCONNECTED":
2567: return DeviceConnectionStatus.DISCONNECTED;
2568: case "MISSING":
2569: return DeviceConnectionStatus.MISSING;
2570: }
2571: return null;
2572: }
2573:
2574: ConnectionUserCouplingMode parseConnectionCouplingString(String mode) {
2575:• switch (mode.trim().toUpperCase()) {
2576: case "INHERITED":
2577: return ConnectionUserCouplingMode.INHERITED;
2578: case "LOOSE":
2579: return ConnectionUserCouplingMode.LOOSE;
2580: case "STRICT":
2581: return ConnectionUserCouplingMode.STRICT;
2582: }
2583: return null;
2584: }
2585:
2586: boolean parseBooleanFromString(String value) {
2587:• switch (value.trim().toLowerCase()) {
2588: case "true":
2589: return true;
2590: case "false":
2591: return false;
2592: }
2593: return false;
2594: }
2595:
2596: @Then("^I create a device with name \"([^\"]*)\"$")
2597: public void iCreateADeviceWithName(String clientId) throws Exception {
2598: DeviceCreator deviceCreator = deviceFactory.newCreator(getCurrentScopeId());
2599: deviceCreator.setClientId(clientId);
2600: stepData.put(DEVICE_CREATOR, deviceCreator);
2601:
2602: try {
2603: primeException();
2604: stepData.remove(DEVICE);
2605: Device device = deviceRegistryService.create(deviceCreator);
2606: stepData.put(DEVICE, device);
2607: } catch (Exception ex) {
2608: verifyException(ex);
2609: }
2610: }
2611:
2612: @Then("^I try to edit device to clientId \"([^\"]*)\"$")
2613: public void iTryToEditDeviceToName(String clientId) throws Exception {
2614: Device oldDevice = (Device) stepData.get(DEVICE);
2615:
2616: primeException();
2617: try {
2618: oldDevice.setClientId(clientId);
2619: stepData.remove("Device");
2620: Device newDevice = deviceRegistryService.update(oldDevice);
2621: stepData.put(DEVICE, newDevice);
2622: } catch (KapuaException ex) {
2623: verifyException(ex);
2624: }
2625: }
2626:
2627: @Then("^I find device with clientId \"([^\"]*)\"$")
2628: public void iFindDeviceWithClientId(String clientId) throws KapuaException {
2629: Device device = (Device) stepData.get(DEVICE);
2630: Device tmpDevice = deviceRegistryService.findByClientId(getCurrentScopeId(), clientId);
2631: assertNotNull(tmpDevice);
2632: }
2633:
2634: @When("^I search events from devices in account \"([^\"]*)\" and (\\d+) (?:event(?:|s)?|or more event(?:|s)?) (?:is|are) found$")
2635: public void iSearchForEventsFromDevicesInAccount(String account, int eventsNum) throws Exception {
2636: ArrayList<Device> devices = (ArrayList<Device>) stepData.get(DEVICE_LIST);
2637: DeviceEventQuery tmpQuery;
2638: Device tmpDev;
2639: DeviceEventListResult tmpList;
2640: Account tmpAcc;
2641:
2642: try {
2643:• for (Device device : devices) {
2644: tmpAcc = accountService.findByName(account);
2645: Assert.assertNotNull(tmpAcc);
2646: Assert.assertNotNull(tmpAcc.getId());
2647:
2648: tmpDev = deviceRegistryService.findByClientId(tmpAcc.getId(), device.getClientId());
2649: Assert.assertNotNull(tmpDev);
2650: Assert.assertNotNull(tmpDev.getId());
2651:
2652: tmpQuery = eventFactory.newQuery(tmpAcc.getId());
2653: tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceEventAttributes.DEVICE_ID, tmpDev.getId(), AttributePredicate.Operator.EQUAL));
2654: tmpQuery.setSortCriteria(tmpQuery.fieldSortCriteria(DeviceEventAttributes.RECEIVED_ON, SortOrder.ASCENDING));
2655: tmpList = eventService.query(tmpQuery);
2656:
2657: Assert.assertNotNull(tmpList);
2658: stepData.put(DEVICE_EVENT_LIST, tmpList);
2659:
2660:• assertTrue(tmpList.getSize() >= eventsNum);
2661: }
2662: } catch (KapuaException ex) {
2663: verifyException(ex);
2664: }
2665: }
2666:
2667: @And("^I asign tag to device$")
2668: public void iAsignTagToDevice() throws Exception {
2669: Tag tag = (Tag) stepData.get("tag");
2670: Device device = (Device) stepData.get("Device");
2671: try {
2672: Set<KapuaId> tags = device.getTagIds();
2673: tags.add(tag.getId());
2674: device.setTagIds(tags);
2675: Device newDevice = deviceRegistryService.update(device);
2676: stepData.put("tags", tags);
2677: stepData.put("Device", newDevice);
2678: } catch (Exception e) {
2679: verifyException(e);
2680: }
2681: }
2682:
2683: @And("^I assign tag \"([^\"]*)\" to device \"([^\"]*)\"$")
2684: public void iAssignTagNamedToDevice(String tagName, String deviceName) throws Exception {
2685: try {
2686: DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId());
2687: tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, deviceName, AttributePredicate.Operator.EQUAL));
2688: DeviceListResult deviceList = deviceRegistryService.query(tmpQuery);
2689: Device device = deviceList.getFirstItem();
2690:
2691: TagQuery tagQuery = tagFactory.newQuery(getCurrentScopeId());
2692: tagQuery.setPredicate(tagQuery.attributePredicate(TagAttributes.NAME, tagName, AttributePredicate.Operator.EQUAL));
2693: TagListResult tagList = tagService.query(tagQuery);
2694: Tag tag = tagList.getFirstItem();
2695:
2696: Set<KapuaId> tags = device.getTagIds();
2697: tags.add(tag.getId());
2698: device.setTagIds(tags);
2699: Device newDevice = deviceRegistryService.update(device);
2700: stepData.put("tags", tags);
2701: } catch (Exception e) {
2702: verifyException(e);
2703: }
2704: }
2705:
2706: @And("^I add device \"([^\"]*)\" to group \"([^\"]*)\"$")
2707: public void iAddDeviceToGroup(String deviceName, String groupName) throws Exception {
2708:
2709: try {
2710: GroupQuery query = groupFactory.newQuery(getCurrentScopeId());
2711: query.setPredicate(query.attributePredicate(GroupAttributes.NAME, groupName, AttributePredicate.Operator.EQUAL));
2712: Group foundGroup = groupService.query(query).getFirstItem();
2713:
2714: DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId());
2715: tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, deviceName, AttributePredicate.Operator.EQUAL));
2716: Device device = deviceRegistryService.query(tmpQuery).getFirstItem();
2717:
2718: KapuaId groupId = foundGroup.getId();
2719: device.setGroupId(groupId);
2720: Device newDevice = deviceRegistryService.update(device);
2721: stepData.put("Device", newDevice);
2722: } catch (Exception e) {
2723: verifyException(e);
2724: }
2725: }
2726:
2727: @When("^I try to edit devices display name to \"([^\"]*)\"$")
2728: public void iTryToEditDevicesDisplayNameTo(String displayName) throws Exception {
2729: Device device = (Device) stepData.get("Device");
2730:
2731: try {
2732: device.setDisplayName(displayName);
2733: device = deviceRegistryService.update(device);
2734: stepData.put("Device", device);
2735: } catch (Exception e) {
2736: verifyException(e);
2737: }
2738: }
2739:
2740: @Given("^Tag \"([^\"]*)\" is assigned to device \"([^\"]*)\"$")
2741: public void tagIsAssignedToDevice(String tagName, String deviceName) throws Throwable {
2742: try {
2743: DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId());
2744: tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, deviceName, AttributePredicate.Operator.EQUAL));
2745: DeviceListResult deviceList = deviceRegistryService.query(tmpQuery);
2746: Device device = deviceList.getFirstItem();
2747:
2748: TagQuery tagQuery = tagFactory.newQuery(getCurrentScopeId());
2749: tagQuery.setPredicate(tagQuery.attributePredicate(TagAttributes.NAME, tagName, AttributePredicate.Operator.EQUAL));
2750: TagListResult tagList = tagService.query(tagQuery);
2751: Tag tag = tagList.getFirstItem();
2752:
2753: Set<KapuaId> tagIds = device.getTagIds();
2754: assertTrue(tagIds.contains(tag.getId()));
2755: } catch (Exception e) {
2756: verifyException(e);
2757: }
2758: }
2759:
2760: @When("^I remove device \"([^\"]*)\" from all groups$")
2761: public void iChangeDevicesGroupToNoGroup(String deviceName) throws Exception {
2762:
2763: try {
2764: DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId());
2765: tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, deviceName, AttributePredicate.Operator.EQUAL));
2766: Device device = deviceRegistryService.query(tmpQuery).getFirstItem();
2767:
2768: device.setGroupId(null);
2769: device = deviceRegistryService.update(device);
2770: stepData.put("Device", device);
2771: } catch (Exception e) {
2772: verifyException(e);
2773: }
2774: }
2775:
2776: @Given("^I unassign tag from device$")
2777: public void iUnassignTagFromDevice() throws Exception {
2778: Tag tag = (Tag) stepData.get("tag");
2779: Device device = (Device) stepData.get("Device");
2780: try {
2781: Set<KapuaId> tagIds = device.getTagIds();
2782: tagIds.remove(tag.getId());
2783: device.setTagIds(tagIds);
2784: Device newDevice = deviceRegistryService.update(device);
2785: stepData.put("Device", newDevice);
2786: } catch (Exception e) {
2787: verifyException(e);
2788: }
2789: }
2790:
2791: @And("^I create (\\d+) devices and add them to group \"([^\"]*)\"$")
2792: public void iCreateDevicesAndAddThemToGroup(int numberOfDevices, String groupName) throws Exception {
2793: Group group = (Group) stepData.get("Group");
2794: assertEquals(group.getName(), groupName);
2795:
2796: try {
2797:• for (int i = 0; i < numberOfDevices; i++) {
2798: iCreateADeviceWithName(String.format("Device%02d", i));
2799: iAddDeviceToGroup(String.format("Device%02d", i), group.getName());
2800: }
2801: } catch (Exception e) {
2802: verifyException(e);
2803: }
2804: }
2805:
2806: @Given("^I unassign tag \"([^\"]*)\" from device \"([^\"]*)\"$")
2807: public void iUnassignTagNamedFromDevice(String tagName, String deviceName) throws Exception {
2808: try {
2809: DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId());
2810: tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, deviceName, AttributePredicate.Operator.EQUAL));
2811: DeviceListResult deviceList = deviceRegistryService.query(tmpQuery);
2812: Device device = deviceList.getFirstItem();
2813:
2814: TagQuery tagQuery = tagFactory.newQuery(getCurrentScopeId());
2815: tagQuery.setPredicate(tagQuery.attributePredicate(TagAttributes.NAME, tagName, AttributePredicate.Operator.EQUAL));
2816: TagListResult tagList = tagService.query(tagQuery);
2817: Tag tag = tagList.getFirstItem();
2818:
2819: Set<KapuaId> tagIds = device.getTagIds();
2820: tagIds.remove(tag.getId());
2821: device.setTagIds(tagIds);
2822: Device newDevice = deviceRegistryService.update(device);
2823: stepData.put("Device", newDevice);
2824: } catch (Exception e) {
2825: verifyException(e);
2826: }
2827: }
2828:
2829: @Then("^Device \"([^\"]*)\" is in Assigned Devices of group \"([^\"]*)\"$")
2830: public void deviceIsInGroupsAssignedDevices(String deviceName, String groupName) throws Exception {
2831:
2832: try {
2833: GroupQuery query = groupFactory.newQuery(getCurrentScopeId());
2834: query.setPredicate(query.attributePredicate(GroupAttributes.NAME, groupName, AttributePredicate.Operator.EQUAL));
2835: Group foundGroup = groupService.query(query).getFirstItem();
2836:
2837: DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId());
2838: tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, deviceName, AttributePredicate.Operator.EQUAL));
2839: Device device = deviceRegistryService.query(tmpQuery).getFirstItem();
2840:
2841: KapuaId expectedGroupId = foundGroup.getId();
2842: assertEquals(device.getGroupId(), expectedGroupId);
2843: } catch (Exception e) {
2844: verifyException(e);
2845: }
2846: }
2847:
2848: @And("^The devices display name is \"([^\"]*)\"$")
2849: public void theDevicesDisplayNameIs(String displayName) throws Throwable {
2850: Device device = (Device) stepData.get("Device");
2851: assertEquals(device.getDisplayName(), displayName);
2852: }
2853:
2854: @And("^I change device status to \"([^\"]*)\"$")
2855: public void iChangeDeviceStatusTo(String deviceStatus) throws Throwable {
2856: Device device = (Device) stepData.get("Device");
2857:
2858: try {
2859:• if (deviceStatus.trim().toLowerCase().equals("enabled")) {
2860: device.setStatus(DeviceStatus.ENABLED);
2861:• } else if (deviceStatus.trim().toLowerCase().equals("disabled")) {
2862: device.setStatus(DeviceStatus.DISABLED);
2863: }
2864: device = deviceRegistryService.update(device);
2865: stepData.put("Device", device);
2866: } catch (Exception e) {
2867: verifyException(e);
2868: }
2869: }
2870:
2871: @Given("^Tag \"([^\"]*)\" is not assigned to device \"([^\"]*)\"$")
2872: public void tagWithNameIsNotAsignedToDevice(String tagName, String deviceName) throws Throwable {
2873: try {
2874: DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId());
2875: tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, deviceName, AttributePredicate.Operator.EQUAL));
2876: DeviceListResult deviceList = deviceRegistryService.query(tmpQuery);
2877: Device device = deviceList.getFirstItem();
2878:
2879: TagQuery tagQuery = tagFactory.newQuery(getCurrentScopeId());
2880: tagQuery.setPredicate(tagQuery.attributePredicate(TagAttributes.NAME, tagName, AttributePredicate.Operator.EQUAL));
2881: TagListResult tagList = tagService.query(tagQuery);
2882: Tag tag = tagList.getFirstItem();
2883:
2884: Set<KapuaId> tagIds = device.getTagIds();
2885: assertFalse(tagIds.contains(tag.getId()));
2886: } catch (Exception e) {
2887: verifyException(e);
2888: }
2889: }
2890:
2891: @Then("^Device \"([^\"]*)\" is not in Assigned Devices of group \"([^\"]*)\"$")
2892: public void deviceIsNotInGroupsAssignedDevices(String deviceName, String groupName) throws Exception {
2893:
2894: try {
2895: GroupQuery query = groupFactory.newQuery(getCurrentScopeId());
2896: query.setPredicate(query.attributePredicate(GroupAttributes.NAME, groupName, AttributePredicate.Operator.EQUAL));
2897: Group foundGroup = groupService.query(query).getFirstItem();
2898:
2899: DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId());
2900: tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, deviceName, AttributePredicate.Operator.EQUAL));
2901: Device device = deviceRegistryService.query(tmpQuery).getFirstItem();
2902:
2903: KapuaId expectedGroupId = foundGroup.getId();
2904: assertNotEquals(device.getGroupId(), expectedGroupId);
2905: } catch (Exception e) {
2906: verifyException(e);
2907: }
2908: }
2909:
2910: @And("^I filter devices by$")
2911: public void iFilterDevices(List<CucDevice> parameters) throws Exception {
2912: CucDevice deviceParams = parameters.get(0);
2913: DeviceListResult devices;
2914: stepData.remove("DeviceList");
2915:• if (deviceParams.getClientId() != null && deviceParams.getDisplayName() == null && deviceParams.getSerialNumber() == null && deviceParams.getStatus() == null) {
2916: DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId());
2917: tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, deviceParams.getClientId(), AttributePredicate.Operator.LIKE));
2918: devices = deviceRegistryService.query(tmpQuery);
2919: stepData.put("DeviceList", devices);
2920:• } else if (deviceParams.getClientId() == null && deviceParams.getDisplayName() != null && deviceParams.getSerialNumber() == null && deviceParams.getStatus() == null) {
2921: DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId());
2922: tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.DISPLAY_NAME, deviceParams.getDisplayName(), AttributePredicate.Operator.LIKE));
2923: devices = deviceRegistryService.query(tmpQuery);
2924: stepData.put("DeviceList", devices);
2925:• } else if (deviceParams.getClientId() == null && deviceParams.getDisplayName() == null && deviceParams.getSerialNumber() != null && deviceParams.getStatus() == null) {
2926: DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId());
2927: tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.SERIAL_NUMBER, deviceParams.getSerialNumber(), AttributePredicate.Operator.LIKE));
2928: devices = deviceRegistryService.query(tmpQuery);
2929: stepData.put("DeviceList", devices);
2930:• } else if (deviceParams.getClientId() == null && deviceParams.getDisplayName() == null && deviceParams.getSerialNumber() == null && deviceParams.getStatus() != null) {
2931: DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId());
2932: tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.STATUS, deviceParams.getStatus(), AttributePredicate.Operator.LIKE));
2933: devices = deviceRegistryService.query(tmpQuery);
2934: stepData.put("DeviceList", devices);
2935:• } else if (deviceParams.getClientId() != null && deviceParams.getDisplayName() != null && deviceParams.getSerialNumber() == null && deviceParams.getStatus() == null) {
2936: DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId());
2937: tmpQuery.setPredicate(tmpQuery.andPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, deviceParams.getClientId(), AttributePredicate.Operator.LIKE),
2938: tmpQuery.attributePredicate(DeviceAttributes.DISPLAY_NAME, deviceParams.getDisplayName(), AttributePredicate.Operator.LIKE)));
2939: devices = deviceRegistryService.query(tmpQuery);
2940: stepData.put("DeviceList", devices);
2941:• } else if (deviceParams.getClientId() != null && deviceParams.getDisplayName() == null && deviceParams.getSerialNumber() != null && deviceParams.getStatus() == null) {
2942: DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId());
2943: tmpQuery.setPredicate(tmpQuery.andPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, deviceParams.getClientId(), AttributePredicate.Operator.LIKE),
2944: tmpQuery.attributePredicate(DeviceAttributes.SERIAL_NUMBER, deviceParams.getSerialNumber(), AttributePredicate.Operator.LIKE)));
2945: devices = deviceRegistryService.query(tmpQuery);
2946: stepData.put("DeviceList", devices);
2947:• } else if (deviceParams.getClientId() != null && deviceParams.getDisplayName() == null && deviceParams.getSerialNumber() == null && deviceParams.getStatus() != null) {
2948: DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId());
2949: tmpQuery.setPredicate(tmpQuery.andPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, deviceParams.getClientId(), AttributePredicate.Operator.LIKE),
2950: tmpQuery.attributePredicate(DeviceAttributes.STATUS, deviceParams.getStatus(), AttributePredicate.Operator.LIKE)));
2951: devices = deviceRegistryService.query(tmpQuery);
2952: stepData.put("DeviceList", devices);
2953:• } else if (deviceParams.getClientId() == null && deviceParams.getDisplayName() != null && deviceParams.getSerialNumber() != null && deviceParams.getStatus() == null) {
2954: DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId());
2955: tmpQuery.setPredicate(tmpQuery.andPredicate(tmpQuery.attributePredicate(DeviceAttributes.SERIAL_NUMBER, deviceParams.getSerialNumber(), AttributePredicate.Operator.LIKE),
2956: tmpQuery.attributePredicate(DeviceAttributes.DISPLAY_NAME, deviceParams.getDisplayName(), AttributePredicate.Operator.LIKE)));
2957: devices = deviceRegistryService.query(tmpQuery);
2958: stepData.put("DeviceList", devices);
2959:• } else if (deviceParams.getClientId() == null && deviceParams.getDisplayName() != null && deviceParams.getSerialNumber() == null && deviceParams.getStatus() != null) {
2960: DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId());
2961: tmpQuery.setPredicate(tmpQuery.andPredicate(tmpQuery.attributePredicate(DeviceAttributes.STATUS, deviceParams.getStatus(), AttributePredicate.Operator.LIKE),
2962: tmpQuery.attributePredicate(DeviceAttributes.DISPLAY_NAME, deviceParams.getDisplayName(), AttributePredicate.Operator.LIKE)));
2963: devices = deviceRegistryService.query(tmpQuery);
2964: stepData.put("DeviceList", devices);
2965:• } else if (deviceParams.getClientId() == null && deviceParams.getDisplayName() == null && deviceParams.getSerialNumber() != null && deviceParams.getStatus() != null) {
2966: DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId());
2967: tmpQuery.setPredicate(tmpQuery.andPredicate(tmpQuery.attributePredicate(DeviceAttributes.SERIAL_NUMBER, deviceParams.getSerialNumber(), AttributePredicate.Operator.LIKE),
2968: tmpQuery.attributePredicate(DeviceAttributes.STATUS, deviceParams.getStatus(), AttributePredicate.Operator.LIKE)));
2969: devices = deviceRegistryService.query(tmpQuery);
2970: stepData.put("DeviceList", devices);
2971:• } else if (deviceParams.getClientId() != null && deviceParams.getDisplayName() != null && deviceParams.getSerialNumber() != null && deviceParams.getStatus() == null) {
2972: DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId());
2973: tmpQuery.setPredicate(tmpQuery.andPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, deviceParams.getClientId(), AttributePredicate.Operator.LIKE),
2974: tmpQuery.attributePredicate(DeviceAttributes.DISPLAY_NAME, deviceParams.getDisplayName(), AttributePredicate.Operator.LIKE),
2975: tmpQuery.attributePredicate(DeviceAttributes.SERIAL_NUMBER, deviceParams.getSerialNumber(), AttributePredicate.Operator.LIKE)));
2976: devices = deviceRegistryService.query(tmpQuery);
2977: stepData.put("DeviceList", devices);
2978:• } else if (deviceParams.getClientId() != null && deviceParams.getDisplayName() != null && deviceParams.getSerialNumber() == null && deviceParams.getStatus() != null) {
2979: DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId());
2980: tmpQuery.setPredicate(tmpQuery.andPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, deviceParams.getClientId(), AttributePredicate.Operator.LIKE),
2981: tmpQuery.attributePredicate(DeviceAttributes.DISPLAY_NAME, deviceParams.getDisplayName(), AttributePredicate.Operator.LIKE),
2982: tmpQuery.attributePredicate(DeviceAttributes.STATUS, deviceParams.getStatus(), AttributePredicate.Operator.LIKE)));
2983: devices = deviceRegistryService.query(tmpQuery);
2984: stepData.put("DeviceList", devices);
2985:• } else if (deviceParams.getClientId() != null && deviceParams.getDisplayName() == null && deviceParams.getSerialNumber() != null && deviceParams.getStatus() != null) {
2986: DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId());
2987: tmpQuery.setPredicate(tmpQuery.andPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, deviceParams.getClientId(), AttributePredicate.Operator.LIKE),
2988: tmpQuery.attributePredicate(DeviceAttributes.SERIAL_NUMBER, deviceParams.getSerialNumber(), AttributePredicate.Operator.LIKE),
2989: tmpQuery.attributePredicate(DeviceAttributes.STATUS, deviceParams.getStatus(), AttributePredicate.Operator.LIKE)));
2990: devices = deviceRegistryService.query(tmpQuery);
2991: stepData.put("DeviceList", devices);
2992:• } else if (deviceParams.getClientId() == null && deviceParams.getDisplayName() != null && deviceParams.getSerialNumber() != null && deviceParams.getStatus() != null) {
2993: DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId());
2994: tmpQuery.setPredicate(tmpQuery.andPredicate(tmpQuery.attributePredicate(DeviceAttributes.SERIAL_NUMBER, deviceParams.getSerialNumber(), AttributePredicate.Operator.LIKE),
2995: tmpQuery.attributePredicate(DeviceAttributes.DISPLAY_NAME, deviceParams.getDisplayName(), AttributePredicate.Operator.LIKE),
2996: tmpQuery.attributePredicate(DeviceAttributes.STATUS, deviceParams.getStatus(), AttributePredicate.Operator.LIKE)));
2997: devices = deviceRegistryService.query(tmpQuery);
2998: stepData.put("DeviceList", devices);
2999:• } else if (deviceParams.getClientId() != null && deviceParams.getDisplayName() != null && deviceParams.getSerialNumber() != null && deviceParams.getStatus() != null) {
3000: DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId());
3001: tmpQuery.setPredicate(tmpQuery.andPredicate(tmpQuery.attributePredicate(DeviceAttributes.SERIAL_NUMBER, deviceParams.getSerialNumber(), AttributePredicate.Operator.LIKE),
3002: tmpQuery.attributePredicate(DeviceAttributes.DISPLAY_NAME, deviceParams.getDisplayName(), AttributePredicate.Operator.LIKE),
3003: tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, deviceParams.getClientId(), AttributePredicate.Operator.LIKE),
3004: tmpQuery.attributePredicate(DeviceAttributes.STATUS, deviceParams.getStatus(), AttributePredicate.Operator.LIKE)));
3005: devices = deviceRegistryService.query(tmpQuery);
3006: stepData.put("DeviceList", devices);
3007: }
3008: }
3009:
3010: @When("^I search for a device with name \"([^\"]*)\"$")
3011: public void iSearchForADeviceWithName(String clientID) throws Throwable {
3012: try {
3013: stepData.remove("Device");
3014: primeException();
3015: DeviceQuery query = deviceFactory.newQuery(SYS_SCOPE_ID);
3016: query.setPredicate(query.attributePredicate(DeviceAttributes.CLIENT_ID, clientID, AttributePredicate.Operator.EQUAL));
3017: DeviceListResult queryResult = deviceRegistryService.query(query);
3018: Device foundDevice = queryResult.getFirstItem();
3019: stepData.put("Device", foundDevice);
3020: stepData.put("queryResult", queryResult);
3021: } catch (KapuaException ex) {
3022: verifyException(ex);
3023: }
3024: }
3025:
3026: @Given("^I create a device with null clientID$")
3027: public void iCreateADeviceWithNullClientID() throws Throwable {
3028: DeviceCreator deviceCreator = deviceFactory.newCreator(getCurrentScopeId());
3029: deviceCreator.setClientId(null);
3030: stepData.put("DeviceCreator", deviceCreator);
3031:
3032: try {
3033: primeException();
3034: stepData.remove("Device");
3035: Device device = deviceRegistryService.create(deviceCreator);
3036: stepData.put("Device", device);
3037: } catch (Exception ex) {
3038: verifyException(ex);
3039: }
3040: }
3041:
3042: @Given("^I try to create devices with invalid symbols \"([^\"]*)\" in name$")
3043: public void iTryToCreateDevicesWithInvalidSymbolsInName(String invalidCharacters) throws Exception {
3044: DeviceCreator deviceCreator = deviceFactory.newCreator(getCurrentScopeId());
3045:• for (int i = 0; i < invalidCharacters.length(); i++) {
3046: String deviceName = "deviceName" + invalidCharacters.charAt(i);
3047: deviceCreator.setClientId(deviceName);
3048: primeException();
3049: try {
3050: Device device = deviceRegistryService.create(deviceCreator);
3051: stepData.put("Device", device);
3052: stepData.put("CurrentDeviceId", device.getId());
3053: } catch (KapuaException ex) {
3054: verifyException(ex);
3055: }
3056: }
3057: }
3058:
3059: @When("^I update the device clientID from \"([^\"]*)\" to \"([^\"]*)\"$")
3060: public void iUpdateTheDeviceClientIDToNewClientId(String oldClientId, String newClientId) throws Exception {
3061: Device device = (Device) stepData.get("Device");
3062: assertEquals(oldClientId, device.getClientId());
3063: stepData.put("Text", device.getClientId());
3064: device.setClientId(newClientId);
3065:
3066: primeException();
3067: try {
3068: deviceRegistryService.update(device);
3069: } catch (KapuaException ex) {
3070: verifyException(ex);
3071: }
3072: }
3073: }