Skip to content

Commit

Permalink
Merge pull request #93 from bwsw/CSEN-88
Browse files Browse the repository at this point in the history
CSEN-88 Test entities were moved from 'it' to 'main' package
  • Loading branch information
MedvedevBW authored Feb 6, 2018
2 parents 4a8b7a4 + b8a6dce commit 4df5f5d
Show file tree
Hide file tree
Showing 78 changed files with 975 additions and 422 deletions.
10 changes: 7 additions & 3 deletions src/it/scala/com/bwsw/cloudstack/entities/TestEntities.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ import com.bwsw.cloudstack.PasswordAuthenticationClientCreator
import com.bwsw.cloudstack.entities.common.JsonMapper
import com.bwsw.cloudstack.entities.dao.AccountDao
import com.bwsw.cloudstack.entities.requests.account.AccountFindRequest
import com.bwsw.cloudstack.entities.requests.domain.DomainFindRequest
import com.bwsw.cloudstack.entities.requests.serviceoffering.ServiceOfferingFindRequest
import com.bwsw.cloudstack.entities.requests.template.TemplateFindRequest
import com.bwsw.cloudstack.entities.requests.template.filters.Featured
import com.bwsw.cloudstack.entities.requests.zone.ZoneFindRequest
import com.bwsw.cloudstack.entities.util.dao.{DomainDao, ServiceOfferingDao, TemplateDao, ZoneDao}
import com.bwsw.cloudstack.entities.util.requests.{DomainFindRequest, ServiceOfferingFindRequest, TemplateFindRequest, ZoneFindRequest}

trait TestEntities {
private val csHost = ApplicationConfig.getRequiredString("app.cloudstack.host")
Expand All @@ -50,13 +54,13 @@ trait TestEntities {

val retrievedTemplateId: UUID = {
val templateDao = new TemplateDao(executor, mapper)
val templateFindRequest = new TemplateFindRequest
val templateFindRequest = new TemplateFindRequest(Featured)
templateDao.find(templateFindRequest).head.id
}

val retrievedZoneId: UUID = {
val zoneDao = new ZoneDao(executor, mapper)
val zoneFindRequest = new ZoneFindRequest
val zoneFindRequest = new ZoneFindRequest().withAvailableFlag(true)
zoneDao.find(zoneFindRequest).head.id
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import com.bwsw.cloudstack.entities.requests.tag.types.{AccountTagType, TagType,
import com.bwsw.cloudstack.entities.requests.tag.{TagCreateRequest, TagFindRequest}
import com.bwsw.cloudstack.entities.requests.user.UserCreateRequest
import com.bwsw.cloudstack.entities.requests.vm.{VmCreateRequest, VmFindRequest}
import com.bwsw.cloudstack.entities.responses.Tag
import com.bwsw.cloudstack.entities.responses.tag.Tag
import org.scalatest.FlatSpec

class TagDaoIntegrationTestSuite extends FlatSpec with TestEntities {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ import java.util.UUID

import com.bwsw.cloudstack.entities.TestEntities
import com.bwsw.cloudstack.entities.events.account.{AccountCreateEvent, AccountDeleteEvent}
import com.bwsw.cloudstack.entities.requests.account.AccountCreateRequest
import com.bwsw.cloudstack.entities.requests.account.{AccountCreateRequest, AccountDeleteRequest}
import com.bwsw.cloudstack.entities.requests.account.AccountCreateRequest.RootAdmin
import com.bwsw.cloudstack.entities.util.events.RecordToEventDeserializer
import com.bwsw.cloudstack.entities.util.kafka.Consumer
import com.bwsw.cloudstack.entities.util.requests.AccountDeleteRequest
import org.scalatest.{BeforeAndAfterAll, FlatSpec}

class AccountEventsRetrievingTest extends FlatSpec with TestEntities with BeforeAndAfterAll {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ package com.bwsw.cloudstack.entities.events

import com.bwsw.cloudstack.entities.TestEntities
import com.bwsw.cloudstack.entities.events.vm.{VirtualMachineCreateEvent, VirtualMachineDestroyEvent}
import com.bwsw.cloudstack.entities.requests.vm.VmCreateRequest
import com.bwsw.cloudstack.entities.requests.vm.{VmCreateRequest, VmDeleteRequest}
import com.bwsw.cloudstack.entities.responses.vm.VirtualMachineCreateResponse
import com.bwsw.cloudstack.entities.util.events.RecordToEventDeserializer
import com.bwsw.cloudstack.entities.util.kafka.Consumer
import com.bwsw.cloudstack.entities.util.requests.VmDeleteRequest
import com.bwsw.cloudstack.entities.util.responses.vm.VmCreateResponse
import org.scalatest.{BeforeAndAfterAll, FlatSpec}

class VmEventsRetrievingTest extends FlatSpec with TestEntities with BeforeAndAfterAll {
Expand All @@ -40,7 +39,7 @@ class VmEventsRetrievingTest extends FlatSpec with TestEntities with BeforeAndAf
val consumer = new Consumer(kafkaEndpoint, kafkaTopic)
consumer.assignToEnd()

val vmId = mapper.deserialize[VmCreateResponse](executor.executeRequest(vmCreateRequest.getRequest)).vmId.id
val vmId = mapper.deserialize[VirtualMachineCreateResponse](executor.executeRequest(vmCreateRequest.getRequest)).vm.id
val vmDeleteRequest = new VmDeleteRequest(vmId)
executor.executeRequest(vmDeleteRequest.getRequest)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ import java.util.{TimeZone, UUID}

import br.com.autonomiccs.apacheCloudStack.client.ApacheCloudStackRequest
import com.bwsw.cloudstack.PasswordAuthenticationClientCreator
import com.bwsw.cloudstack.entities.requests.account.AccountCreateRequest.User
import com.bwsw.cloudstack.entities.util.requests.DomainCreateRequest
import com.bwsw.cloudstack.entities.util.requests.TestConstants.ParameterValues
import com.bwsw.cloudstack.entities.util.responses.account._
import com.bwsw.cloudstack.entities.util.responses.domain.DomainCreateResponse
import com.bwsw.cloudstack.entities.util.responses.user.TestUser
import com.bwsw.cloudstack.entities.requests.domain.DomainCreateRequest
import com.bwsw.cloudstack.entities.responses.account.{Account, AccountCreateResponse}
import com.bwsw.cloudstack.entities.responses.domain.DomainCreateResponse
import com.bwsw.cloudstack.entities.responses.user
import com.bwsw.cloudstack.entities.util.requests.IntegrationTestConstants.ParameterValues
import com.bwsw.cloudstack.entities.{Executor, TestEntities}
import org.scalatest.FlatSpec

Expand All @@ -38,7 +37,7 @@ class AccountCreateRequestIntegrationTestSuite extends FlatSpec with TestEntitie
val password = UUID.randomUUID().toString

val settings = AccountCreateRequest.Settings(
_type = User,
_type = AccountCreateRequest.User,
email = "e@e",
firstName = "fn",
lastName = "ln",
Expand All @@ -62,10 +61,10 @@ class AccountCreateRequestIntegrationTestSuite extends FlatSpec with TestEntitie
val accountRole = (4, "User")

val domainCreateRequest = new DomainCreateRequest(domainName).getRequest
val newDomainId = mapper.deserialize[DomainCreateResponse](executor.executeRequest(domainCreateRequest)).domainEntity.domainId.id
val newDomainId = mapper.deserialize[DomainCreateResponse](executor.executeRequest(domainCreateRequest)).domainEntity.domain.id

val accountCreateSettings = Settings(
_type = User,
_type = AccountCreateRequest.User,
email = "e@e",
firstName = "fn",
lastName = "ln",
Expand All @@ -84,19 +83,22 @@ class AccountCreateRequestIntegrationTestSuite extends FlatSpec with TestEntitie

val actualAccount = mapper.deserialize[AccountCreateResponse](executor.executeRequest(accountCreateRequest.getRequest)).accountEntity.account

val expectedAccount = TestAccount(
val expectedAccount = Account(
id = accountId,
name = accountName,
accountType = accountCreateSettings._type.numericValue,
user = Set(TestUser(id = userId,
domainId = newDomainId,
networkDomain = networkDomain,
users = List(user.User(id = userId,
accountId = accountId,
account = accountName,
email = accountCreateSettings.email,
firstname = accountCreateSettings.firstName,
lastname = accountCreateSettings.lastName,
username = accountCreateSettings.username,
domainId = newDomainId,
timezone = Some(timeZone.getID),
account = accountName)),
domainId = newDomainId,
networkDomain = networkDomain,
timezone = Some(timeZone.getID)
)),
roleType = accountRole._2
)

Expand All @@ -114,7 +116,7 @@ class AccountCreateRequestIntegrationTestSuite extends FlatSpec with TestEntitie
val incorrectParameter = UUID.randomUUID().toString

val settings = AccountCreateRequest.Settings(
_type = User,
_type = AccountCreateRequest.User,
email = "e@e",
firstName = "fn",
lastName = "ln",
Expand All @@ -132,10 +134,10 @@ class AccountCreateRequestIntegrationTestSuite extends FlatSpec with TestEntitie

assert(
testAccount.accountType == settings._type.numericValue &&
testAccount.user.head.email == settings.email &&
testAccount.user.head.firstname == settings.firstName &&
testAccount.user.head.lastname == settings.lastName &&
testAccount.user.head.username == settings.username
testAccount.users.head.email == settings.email &&
testAccount.users.head.firstname == settings.firstName &&
testAccount.users.head.lastname == settings.lastName &&
testAccount.users.head.username == settings.username
)

val testRequest = new AccountFindRequest().getRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ import java.util.UUID
import br.com.autonomiccs.apacheCloudStack.exceptions.ApacheCloudStackClientRequestRuntimeException
import com.bwsw.cloudstack.entities.TestEntities
import com.bwsw.cloudstack.entities.requests.Request
import com.bwsw.cloudstack.entities.responses.AccountResponse
import com.bwsw.cloudstack.entities.util.requests.TestConstants.ParameterValues
import com.bwsw.cloudstack.entities.responses.account.AccountFindResponse
import com.bwsw.cloudstack.entities.util.requests.IntegrationTestConstants.ParameterValues
import org.scalatest.FlatSpec

import scala.util.{Failure, Success, Try}

class AccountFindRequestIntegrationTestSuite extends FlatSpec with TestEntities {
it should "retrieve json string if request contains only default parameters" in {
val accountFindRequest = new AccountFindRequest
val response = mapper.deserialize[AccountResponse](executor.executeRequest(accountFindRequest.getRequest))
val response = mapper.deserialize[AccountFindResponse](executor.executeRequest(accountFindRequest.getRequest))

assert(response.isInstanceOf[AccountResponse])
assert(response.isInstanceOf[AccountFindResponse])
}

it should "throw ApacheCloudStackClientRequestRuntimeException with status code 431" +
Expand All @@ -56,17 +56,17 @@ class AccountFindRequestIntegrationTestSuite extends FlatSpec with TestEntities
it should "return an empty list of accounts if entity with a specified value of name parameter does not exist" in {
val name = UUID.randomUUID().toString
val accountFindRequest = new AccountFindRequest().withName(name)
val response = mapper.deserialize[AccountResponse](executor.executeRequest(accountFindRequest.getRequest))
val response = mapper.deserialize[AccountFindResponse](executor.executeRequest(accountFindRequest.getRequest))

assert(response.entityList.entities.isEmpty)
}

it should "retrieve json string if request contains default parameters and parameter with incorrect key" in {
val incorrectParameterKey = UUID.randomUUID().toString
val request = new AccountFindRequest().getRequest.addParameter(incorrectParameterKey, ParameterValues.DUMMY_VALUE)
val response = mapper.deserialize[AccountResponse](executor.executeRequest(request))
val response = mapper.deserialize[AccountFindResponse](executor.executeRequest(request))

assert(response.isInstanceOf[AccountResponse])
assert(response.isInstanceOf[AccountFindResponse])
}

private def tryExecuteRequest(request: Request): Boolean = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import java.util.UUID

import com.bwsw.cloudstack.entities.requests.tag.types.{TagType, UserTagType}
import com.bwsw.cloudstack.entities.requests.user.UserCreateRequest
import com.bwsw.cloudstack.entities.responses
import com.bwsw.cloudstack.entities.util.requests.TestConstants.ParameterValues.{DUMMY_KEY, DUMMY_VALUE}
import com.bwsw.cloudstack.entities.util.responses.{Tag, TagFindResponse}
import com.bwsw.cloudstack.entities.util.responses.user.UserCreateResponse
import com.bwsw.cloudstack.entities.util.requests.IntegrationTestConstants.ParameterValues.{DUMMY_KEY, DUMMY_VALUE}
import com.bwsw.cloudstack.entities.util.responses.{TagTestFindResponse, TestTag}
import com.bwsw.cloudstack.entities.TestEntities
import com.bwsw.cloudstack.entities.responses.tag.Tag
import com.bwsw.cloudstack.entities.responses.user.UserCreateResponse
import org.scalatest.{Outcome, fixture}

class TagCreateRequestIntegrationTestSuite extends fixture.FlatSpec with TestEntities {
Expand Down Expand Up @@ -56,7 +56,7 @@ class TagCreateRequestIntegrationTestSuite extends fixture.FlatSpec with TestEnt

it should s"create $tagNumber tags using a request which contains only required parameters" in { fixture =>

val expectedTags = (0 until tagNumber).map(x => responses.Tag(DUMMY_KEY + x, DUMMY_VALUE)).toList
val expectedTags = (0 until tagNumber).map(x => Tag(DUMMY_KEY + x, DUMMY_VALUE)).toList

val settings = TagCreateRequest.Settings(
resourceType = fixture.resourceType,
Expand All @@ -71,7 +71,7 @@ class TagCreateRequestIntegrationTestSuite extends fixture.FlatSpec with TestEnt

it should s"create $tagNumber tags using a request which contains only required parameters and a parameter with incorrect key" in { fixture =>
val incorrectParameter = UUID.randomUUID().toString
val expectedTags = (0 until tagNumber).map(x => responses.Tag(DUMMY_KEY + x, DUMMY_VALUE)).toList
val expectedTags = (0 until tagNumber).map(x => Tag(DUMMY_KEY + x, DUMMY_VALUE)).toList

val settings = TagCreateRequest.Settings(
resourceType = fixture.resourceType,
Expand All @@ -84,9 +84,9 @@ class TagCreateRequestIntegrationTestSuite extends fixture.FlatSpec with TestEnt
checkTagCreation(settings, expectedTags)
}

private def checkTagCreation(settings: TagCreateRequest.Settings, expectedTags: List[responses.Tag]): Unit = {
private def checkTagCreation(settings: TagCreateRequest.Settings, expectedTags: List[Tag]): Unit = {
val tagFindRequest = new TagFindRequest().withResource(settings.resourceIds.head).getRequest
val tags = mapper.deserialize[TagFindResponse](executor.executeRequest(tagFindRequest)).tags.maybeTags
val tags = mapper.deserialize[TagTestFindResponse](executor.executeRequest(tagFindRequest)).tags.maybeTags

assert(
tags.isDefined &&
Expand All @@ -95,8 +95,8 @@ class TagCreateRequestIntegrationTestSuite extends fixture.FlatSpec with TestEnt
}

private def checkTagEquality(settings: TagCreateRequest.Settings,
expectedTag: responses.Tag,
retrievedTag: Tag): Boolean = {
expectedTag: Tag,
retrievedTag: TestTag): Boolean = {
expectedTag.key == retrievedTag.key &&
expectedTag.value == retrievedTag.value &&
settings.resourceType.name == retrievedTag.resourceType &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ import br.com.autonomiccs.apacheCloudStack.exceptions.ApacheCloudStackClientRequ
import com.bwsw.cloudstack.entities.TestEntities
import com.bwsw.cloudstack.entities.requests.Request
import com.bwsw.cloudstack.entities.requests.tag.types.TagType
import com.bwsw.cloudstack.entities.responses.TagResponse
import com.bwsw.cloudstack.entities.util.requests.TestConstants.ParameterValues
import com.bwsw.cloudstack.entities.responses.tag.TagFindResponse
import com.bwsw.cloudstack.entities.util.requests.IntegrationTestConstants.ParameterValues
import org.scalatest.FlatSpec

import scala.util.{Failure, Success, Try}

class TagFindRequestIntegrationTestSuite extends FlatSpec with TestEntities {
it should "retrieve json string if request contains only default parameters" in {
val tagFindRequest = new TagFindRequest
val response = mapper.deserialize[TagResponse](executor.executeRequest(tagFindRequest.getRequest))
val response = mapper.deserialize[TagFindResponse](executor.executeRequest(tagFindRequest.getRequest))

assert(response.isInstanceOf[TagResponse])
assert(response.isInstanceOf[TagFindResponse])
}

it should "return an empty list of tags if entity with a specified value of resource parameter does not exist" in {
Expand Down Expand Up @@ -86,13 +86,13 @@ class TagFindRequestIntegrationTestSuite extends FlatSpec with TestEntities {
it should "retrieve json string if request contains default parameters and parameter with incorrect key" in {
val incorrectParameterKey = UUID.randomUUID().toString
val request = new TagFindRequest().getRequest.addParameter(incorrectParameterKey, ParameterValues.DUMMY_VALUE)
val response = mapper.deserialize[TagResponse](executor.executeRequest(request))
val response = mapper.deserialize[TagFindResponse](executor.executeRequest(request))

assert(response.isInstanceOf[TagResponse])
assert(response.isInstanceOf[TagFindResponse])
}

private def checkEmptyResponse(request: Request) = {
val response = mapper.deserialize[TagResponse](executor.executeRequest(request.getRequest))
val response = mapper.deserialize[TagFindResponse](executor.executeRequest(request.getRequest))

assert(response.entityList.entities.isEmpty)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ import java.util.{TimeZone, UUID}
import br.com.autonomiccs.apacheCloudStack.client.ApacheCloudStackRequest
import com.bwsw.cloudstack.PasswordAuthenticationClientCreator
import com.bwsw.cloudstack.entities.requests.account.AccountCreateRequest
import com.bwsw.cloudstack.entities.requests.account.AccountCreateRequest.User
import com.bwsw.cloudstack.entities.util.requests.TestConstants.ParameterValues
import com.bwsw.cloudstack.entities.util.requests.DomainCreateRequest
import com.bwsw.cloudstack.entities.util.responses.domain.DomainCreateResponse
import com.bwsw.cloudstack.entities.requests.domain.DomainCreateRequest
import com.bwsw.cloudstack.entities.responses.domain.DomainCreateResponse
import com.bwsw.cloudstack.entities.responses.user._
import com.bwsw.cloudstack.entities.util.requests.IntegrationTestConstants.ParameterValues
import com.bwsw.cloudstack.entities.{Executor, TestEntities}
import com.bwsw.cloudstack.entities.util.responses.user.{TestUser, UserCreateResponse}
import org.scalatest.FlatSpec

class UserCreateRequestIntegrationTestSuite extends FlatSpec with TestEntities {
Expand All @@ -53,6 +52,7 @@ class UserCreateRequestIntegrationTestSuite extends FlatSpec with TestEntities {
it should "create a user using a request which contains the required and optional parameters" in {
import AccountCreateRequest.Settings

val accountId = UUID.randomUUID()
val userId = UUID.randomUUID()
val accountName = UUID.randomUUID().toString
val domainName = UUID.randomUUID().toString
Expand All @@ -61,18 +61,18 @@ class UserCreateRequestIntegrationTestSuite extends FlatSpec with TestEntities {
val timeZone = TimeZone.getTimeZone("GMT+7:00")

val domainCreateRequest = new DomainCreateRequest(domainName).getRequest
val newDomainId = mapper.deserialize[DomainCreateResponse](executor.executeRequest(domainCreateRequest)).domainEntity.domainId.id
val newDomainId = mapper.deserialize[DomainCreateResponse](executor.executeRequest(domainCreateRequest)).domainEntity.domain.id

val accountCreateRequest = new AccountCreateRequest(
Settings(
_type = User,
_type = AccountCreateRequest.User,
email = "e@e",
firstName = "fn",
lastName = "ln",
password = "password",
username = "username"
)
).withName(accountName).withDomain(newDomainId)
).withName(accountName).withDomain(newDomainId).withId(accountId)

executor.executeRequest(accountCreateRequest.getRequest)

Expand All @@ -86,8 +86,9 @@ class UserCreateRequestIntegrationTestSuite extends FlatSpec with TestEntities {
)
val userCreateRequest = new UserCreateRequest(settings).withId(userId).withDomain(newDomainId).withTimeZone(timeZone)

val expectedUser = TestUser(
val expectedUser = User(
id = userId,
accountId,
account = accountName,
email = settings.email,
firstname = settings.firstName,
Expand Down
Loading

0 comments on commit 4df5f5d

Please sign in to comment.