Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CONF
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UvA
CONF
Commits
a772559e
Commit
a772559e
authored
Oct 11, 2019
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added test in one because we have only one mongDB. Need to create testcases
parent
3657f0f4
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
460 additions
and
42 deletions
+460
-42
CredentialApiController.java
...ain/java/nl/uva/sne/drip/api/CredentialApiController.java
+19
-17
ToscaTemplateApiController.java
.../java/nl/uva/sne/drip/api/ToscaTemplateApiController.java
+0
-3
CredentialDAO.java
...ager/src/main/java/nl/uva/sne/drip/dao/CredentialDAO.java
+19
-0
Credentials.java
...ager/src/main/java/nl/uva/sne/drip/model/Credentials.java
+21
-6
ToscaTemplate.java
...er/src/main/java/nl/uva/sne/drip/model/ToscaTemplate.java
+12
-12
CredentialService.java
.../main/java/nl/uva/sne/drip/service/CredentialService.java
+57
-0
MongoConfig.java
.../test/java/nl/uva/sne/drip/configuration/MongoConfig.java
+5
-4
ServiceTests.java
...r/src/test/java/nl/uva/sne/drip/service/ServiceTests.java
+327
-0
No files found.
drip-manager/src/main/java/nl/uva/sne/drip/api/CredentialApiController.java
View file @
a772559e
...
...
@@ -8,18 +8,14 @@ import org.slf4j.LoggerFactory;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestHeader
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RequestPart
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.validation.constraints.*
;
import
javax.validation.Valid
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.IOException
;
import
java.util.List
;
import
nl.uva.sne.drip.service.CredentialService
;
import
nl.uva.sne.drip.service.ToscaTemplateService
;
import
org.springframework.beans.factory.annotation.Autowired
;
@javax
.
annotation
.
Generated
(
value
=
"io.swagger.codegen.languages.SpringCodegen"
,
date
=
"2019-10-10T17:15:46.465Z"
)
...
...
@@ -32,29 +28,35 @@ public class CredentialApiController implements CredentialApi {
private
final
HttpServletRequest
request
;
@Autowired
private
CredentialService
credentialService
;
@org
.
springframework
.
beans
.
factory
.
annotation
.
Autowired
public
CredentialApiController
(
ObjectMapper
objectMapper
,
HttpServletRequest
request
)
{
this
.
objectMapper
=
objectMapper
;
this
.
request
=
request
;
}
public
ResponseEntity
<
String
>
createCredentials
(
@ApiParam
(
value
=
"Created user object"
,
required
=
true
)
@Valid
@RequestBody
Credentials
body
)
{
@Override
public
ResponseEntity
<
String
>
createCredentials
(
@ApiParam
(
value
=
"Created user object"
,
required
=
true
)
@Valid
@RequestBody
Credentials
body
)
{
String
accept
=
request
.
getHeader
(
"Accept"
);
if
(
accept
!=
null
&&
accept
.
contains
(
"application/json"
))
{
try
{
return
new
ResponseEntity
<
String
>(
objectMapper
.
readValue
(
"\"\""
,
String
.
class
),
HttpStatus
.
NOT_IMPLEMENTED
);
}
catch
(
IOException
e
)
{
log
.
error
(
"Couldn't serialize response for content type application/json"
,
e
);
return
new
ResponseEntity
<
String
>(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
}
String
id
=
credentialService
.
save
(
body
);
return
new
ResponseEntity
<>(
id
,
HttpStatus
.
OK
);
}
return
new
ResponseEntity
<
String
>(
HttpStatus
.
NOT_IMPLEMENTED
);
return
new
ResponseEntity
<>(
HttpStatus
.
NOT_IMPLEMENTED
);
}
@Override
public
ResponseEntity
<
List
<
String
>>
getCredentialIDs
()
{
throw
new
UnsupportedOperationException
(
"Not supported yet."
);
//To change body of generated methods, choose Tools | Templates.
String
accept
=
request
.
getHeader
(
"Accept"
);
if
(
accept
!=
null
&&
accept
.
contains
(
"application/json"
))
{
List
<
String
>
ids
=
credentialService
.
getAllIds
();
return
new
ResponseEntity
<>(
ids
,
HttpStatus
.
OK
);
}
return
new
ResponseEntity
<>(
HttpStatus
.
NOT_IMPLEMENTED
);
}
}
drip-manager/src/main/java/nl/uva/sne/drip/api/ToscaTemplateApiController.java
View file @
a772559e
...
...
@@ -25,8 +25,6 @@ public class ToscaTemplateApiController implements ToscaTemplateApi {
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
ToscaTemplateApiController
.
class
);
private
final
ObjectMapper
objectMapper
;
private
final
HttpServletRequest
request
;
@Autowired
...
...
@@ -34,7 +32,6 @@ public class ToscaTemplateApiController implements ToscaTemplateApi {
@org
.
springframework
.
beans
.
factory
.
annotation
.
Autowired
public
ToscaTemplateApiController
(
ObjectMapper
objectMapper
,
HttpServletRequest
request
)
{
this
.
objectMapper
=
objectMapper
;
this
.
request
=
request
;
}
...
...
drip-manager/src/main/java/nl/uva/sne/drip/dao/CredentialDAO.java
0 → 100644
View file @
a772559e
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package
nl
.
uva
.
sne
.
drip
.
dao
;
import
nl.uva.sne.drip.model.Credentials
;
import
org.springframework.data.mongodb.repository.MongoRepository
;
import
org.springframework.stereotype.Repository
;
/**
*
* @author S. Koulouzis
*/
@Repository
public
interface
CredentialDAO
extends
MongoRepository
<
Credentials
,
String
>
{
}
drip-manager/src/main/java/nl/uva/sne/drip/model/Credentials.java
View file @
a772559e
package
nl
.
uva
.
sne
.
drip
.
model
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
com.fasterxml.jackson.annotation.JsonInclude.Include
;
import
java.util.Objects
;
...
...
@@ -9,6 +10,7 @@ import java.util.HashMap;
import
java.util.Map
;
import
org.springframework.validation.annotation.Validated
;
import
javax.validation.Valid
;
import
org.springframework.data.annotation.Id
;
/**
* Credentials
...
...
@@ -17,6 +19,10 @@ import javax.validation.Valid;
@JsonInclude
(
Include
.
NON_NULL
)
public
class
Credentials
{
@Id
@JsonIgnore
private
String
id
;
@JsonProperty
(
"protocol"
)
private
String
protocol
=
null
;
...
...
@@ -41,11 +47,20 @@ public class Credentials {
return
this
;
}
@JsonIgnore
public
String
getId
()
{
return
id
;
}
public
void
setID
(
String
id
)
{
this
.
id
=
id
;
}
/**
* Get protocol
*
* @return protocol
*
*
*/
@ApiModelProperty
(
value
=
""
)
...
...
@@ -66,7 +81,7 @@ public class Credentials {
* Get tokenType
*
* @return tokenType
*
*
*/
@ApiModelProperty
(
value
=
""
)
...
...
@@ -87,7 +102,7 @@ public class Credentials {
* Get token
*
* @return token
*
*
*/
@ApiModelProperty
(
value
=
""
)
...
...
@@ -116,7 +131,7 @@ public class Credentials {
* Get keys
*
* @return keys
*
*
*/
@ApiModelProperty
(
value
=
""
)
...
...
@@ -137,7 +152,7 @@ public class Credentials {
* Get user
*
* @return user
*
*
*/
@ApiModelProperty
(
value
=
""
)
...
...
@@ -158,7 +173,7 @@ public class Credentials {
* Get cloudProviderName
*
* @return cloudProviderName
*
*
*/
@ApiModelProperty
(
value
=
""
)
...
...
drip-manager/src/main/java/nl/uva/sne/drip/model/ToscaTemplate.java
View file @
a772559e
...
...
@@ -170,7 +170,7 @@ public class ToscaTemplate {
public
ToscaTemplate
addImportsItem
(
Map
<
String
,
String
>
importsItem
)
{
if
(
this
.
imports
==
null
)
{
this
.
imports
=
new
ArrayList
<
Map
<
String
,
String
>
>();
this
.
imports
=
new
ArrayList
<>();
}
this
.
imports
.
add
(
importsItem
);
return
this
;
...
...
@@ -201,7 +201,7 @@ public class ToscaTemplate {
public
ToscaTemplate
putRepositoriesItem
(
String
key
,
String
repositoriesItem
)
{
if
(
this
.
repositories
==
null
)
{
this
.
repositories
=
new
HashMap
<
String
,
String
>();
this
.
repositories
=
new
HashMap
<>();
}
this
.
repositories
.
put
(
key
,
repositoriesItem
);
return
this
;
...
...
@@ -230,7 +230,7 @@ public class ToscaTemplate {
public
ToscaTemplate
putDslDefinitionsItem
(
String
key
,
String
dslDefinitionsItem
)
{
if
(
this
.
dslDefinitions
==
null
)
{
this
.
dslDefinitions
=
new
HashMap
<
String
,
String
>();
this
.
dslDefinitions
=
new
HashMap
<>();
}
this
.
dslDefinitions
.
put
(
key
,
dslDefinitionsItem
);
return
this
;
...
...
@@ -259,7 +259,7 @@ public class ToscaTemplate {
public
ToscaTemplate
putNodeTypesItem
(
String
key
,
Object
nodeTypesItem
)
{
if
(
this
.
nodeTypes
==
null
)
{
this
.
nodeTypes
=
new
HashMap
<
String
,
Object
>();
this
.
nodeTypes
=
new
HashMap
<>();
}
this
.
nodeTypes
.
put
(
key
,
nodeTypesItem
);
return
this
;
...
...
@@ -311,7 +311,7 @@ public class ToscaTemplate {
public
ToscaTemplate
putRelationshipTypesItem
(
String
key
,
Object
relationshipTypesItem
)
{
if
(
this
.
relationshipTypes
==
null
)
{
this
.
relationshipTypes
=
new
HashMap
<
String
,
Object
>();
this
.
relationshipTypes
=
new
HashMap
<>();
}
this
.
relationshipTypes
.
put
(
key
,
relationshipTypesItem
);
return
this
;
...
...
@@ -340,7 +340,7 @@ public class ToscaTemplate {
public
ToscaTemplate
putRelationshipTemplatesItem
(
String
key
,
Object
relationshipTemplatesItem
)
{
if
(
this
.
relationshipTemplates
==
null
)
{
this
.
relationshipTemplates
=
new
HashMap
<
String
,
Object
>();
this
.
relationshipTemplates
=
new
HashMap
<>();
}
this
.
relationshipTemplates
.
put
(
key
,
relationshipTemplatesItem
);
return
this
;
...
...
@@ -369,7 +369,7 @@ public class ToscaTemplate {
public
ToscaTemplate
putCapabilityTypesItem
(
String
key
,
Object
capabilityTypesItem
)
{
if
(
this
.
capabilityTypes
==
null
)
{
this
.
capabilityTypes
=
new
HashMap
<
String
,
Object
>();
this
.
capabilityTypes
=
new
HashMap
<>();
}
this
.
capabilityTypes
.
put
(
key
,
capabilityTypesItem
);
return
this
;
...
...
@@ -398,7 +398,7 @@ public class ToscaTemplate {
public
ToscaTemplate
putArtifactTypesItem
(
String
key
,
Object
artifactTypesItem
)
{
if
(
this
.
artifactTypes
==
null
)
{
this
.
artifactTypes
=
new
HashMap
<
String
,
Object
>();
this
.
artifactTypes
=
new
HashMap
<>();
}
this
.
artifactTypes
.
put
(
key
,
artifactTypesItem
);
return
this
;
...
...
@@ -427,7 +427,7 @@ public class ToscaTemplate {
public
ToscaTemplate
putDataTypesItem
(
String
key
,
Object
dataTypesItem
)
{
if
(
this
.
dataTypes
==
null
)
{
this
.
dataTypes
=
new
HashMap
<
String
,
Object
>();
this
.
dataTypes
=
new
HashMap
<>();
}
this
.
dataTypes
.
put
(
key
,
dataTypesItem
);
return
this
;
...
...
@@ -456,7 +456,7 @@ public class ToscaTemplate {
public
ToscaTemplate
putInterfaceTypesItem
(
String
key
,
Object
interfaceTypesItem
)
{
if
(
this
.
interfaceTypes
==
null
)
{
this
.
interfaceTypes
=
new
HashMap
<
String
,
Object
>();
this
.
interfaceTypes
=
new
HashMap
<>();
}
this
.
interfaceTypes
.
put
(
key
,
interfaceTypesItem
);
return
this
;
...
...
@@ -485,7 +485,7 @@ public class ToscaTemplate {
public
ToscaTemplate
putPolicyTypesItem
(
String
key
,
String
policyTypesItem
)
{
if
(
this
.
policyTypes
==
null
)
{
this
.
policyTypes
=
new
HashMap
<
String
,
String
>();
this
.
policyTypes
=
new
HashMap
<>();
}
this
.
policyTypes
.
put
(
key
,
policyTypesItem
);
return
this
;
...
...
@@ -514,7 +514,7 @@ public class ToscaTemplate {
public
ToscaTemplate
putGroupTypesItem
(
String
key
,
Object
groupTypesItem
)
{
if
(
this
.
groupTypes
==
null
)
{
this
.
groupTypes
=
new
HashMap
<
String
,
Object
>();
this
.
groupTypes
=
new
HashMap
<>();
}
this
.
groupTypes
.
put
(
key
,
groupTypesItem
);
return
this
;
...
...
drip-manager/src/main/java/nl/uva/sne/drip/service/CredentialService.java
0 → 100644
View file @
a772559e
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package
nl
.
uva
.
sne
.
drip
.
service
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.SerializationFeature
;
import
com.fasterxml.jackson.dataformat.yaml.YAMLFactory
;
import
com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
nl.uva.sne.drip.dao.CredentialDAO
;
import
nl.uva.sne.drip.model.Credentials
;
/**
*
* @author S. Koulouzis
*/
@Service
public
class
CredentialService
{
@Autowired
private
CredentialDAO
dao
;
public
String
save
(
Credentials
document
)
{
dao
.
save
(
document
);
return
document
.
getId
();
}
public
Credentials
findByID
(
String
id
)
throws
JsonProcessingException
{
Credentials
credentials
=
dao
.
findById
(
id
).
get
();
return
credentials
;
}
public
void
deleteByID
(
String
id
)
{
dao
.
deleteById
(
id
);
}
public
List
<
String
>
getAllIds
()
{
List
<
String
>
allIds
=
new
ArrayList
<>();
List
<
Credentials
>
all
=
dao
.
findAll
();
for
(
Credentials
tt
:
all
)
{
allIds
.
add
(
tt
.
getId
());
}
return
allIds
;
}
void
deleteAll
()
{
dao
.
deleteAll
();
}
}
drip-manager/src/test/java/nl/uva/sne/drip/configuration/MongoConfig.java
View file @
a772559e
...
...
@@ -16,6 +16,7 @@
package
nl
.
uva
.
sne
.
drip
.
configuration
;
import
com.mongodb.MongoClient
;
import
com.mongodb.MongoClientOptions
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.mongodb.config.AbstractMongoConfiguration
;
...
...
@@ -28,6 +29,9 @@ import org.springframework.data.mongodb.config.AbstractMongoConfiguration;
@ComponentScan
(
basePackages
=
{
"nl.uva.sne.drip"
,
"nl.uva.sne.drip.api"
,
"nl.uva.sne.drip.configuration"
,
"nl.uva.sne.drip.dao"
,
"nl.uva.sne.drip.model"
,
"nl.uva.sne.drip.service"
})
public
class
MongoConfig
extends
AbstractMongoConfiguration
{
public
static
int
MONGO_TEST_PORT
=
12345
;
public
static
String
MONGO_TEST_HOST
=
"localhost"
;
@Override
protected
String
getDatabaseName
()
{
return
"test-db"
;
...
...
@@ -40,9 +44,6 @@ public class MongoConfig extends AbstractMongoConfiguration {
@Override
public
MongoClient
mongoClient
()
{
String
bindIp
=
"localhost"
;
int
port
=
12345
;
return
new
MongoClient
(
bindIp
,
port
);
return
new
MongoClient
(
MONGO_TEST_HOST
,
MONGO_TEST_PORT
);
}
}
drip-manager/src/test/java/nl/uva/sne/drip/service/
ToscaTemplateServiceTest
.java
→
drip-manager/src/test/java/nl/uva/sne/drip/service/
ServiceTests
.java
View file @
a772559e
...
...
@@ -6,6 +6,13 @@
package
nl
.
uva
.
sne
.
drip
.
service
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
de.flapdoodle.embed.mongo.MongodExecutable
;
import
de.flapdoodle.embed.mongo.MongodProcess
;
import
de.flapdoodle.embed.mongo.MongodStarter
;
import
de.flapdoodle.embed.mongo.config.MongodConfigBuilder
;
import
de.flapdoodle.embed.mongo.config.Net
;
import
de.flapdoodle.embed.mongo.distribution.Version
;
import
de.flapdoodle.embed.process.runtime.Network
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -17,25 +24,22 @@ import org.junit.AfterClass;
import
org.junit.Before
;
import
org.junit.BeforeClass
;
import
de.flapdoodle.embed.mongo.MongodExecutable
;
import
de.flapdoodle.embed.mongo.MongodProcess
;
import
de.flapdoodle.embed.mongo.MongodStarter
;
import
de.flapdoodle.embed.mongo.config.MongodConfigBuilder
;
import
de.flapdoodle.embed.mongo.config.Net
;
import
de.flapdoodle.embed.mongo.distribution.Version
;
import
de.flapdoodle.embed.process.runtime.Network
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.NoSuchElementException
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
nl.uva.sne.drip.Swagger2SpringBoot
;
import
nl.uva.sne.drip.model.ToscaTemplate
;
import
nl.uva.sne.drip.configuration.MongoConfig
;
import
nl.uva.sne.drip.model.Credentials
;
import
org.junit.Assert
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
fail
;
import
org.springframework.mock.web.MockMultipartFile
;
import
org.springframework.test.context.web.WebAppConfiguration
;
...
...
@@ -48,10 +52,19 @@ import org.springframework.web.multipart.MultipartFile;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@WebAppConfiguration
@ContextConfiguration
(
classes
=
{
Swagger2SpringBoot
.
class
})
public
class
ToscaTemplateServiceTest
{
public
class
ServiceTests
{
@Autowired
ToscaTemplateService
toscaTemplateService
;
private
String
toscaTemplateID
;
private
String
testApplicationExampleToscaContents
;
private
static
final
String
testApplicationExampleToscaFilePath
=
".."
+
File
.
separator
+
"TOSCA"
+
File
.
separator
+
"application_example.yaml"
;
private
static
final
String
testUpdatedApplicationExampleToscaFilePath
=
".."
+
File
.
separator
+
"TOSCA"
+
File
.
separator
+
"application_example_updated.yaml"
;
@Autowired
ToscaTemplateService
instance
;
CredentialService
credentialService
;
private
String
credentialID
;
@Autowired
private
WebApplicationContext
wac
;
...
...
@@ -60,20 +73,18 @@ public class ToscaTemplateServiceTest {
private
static
final
MongodStarter
starter
=
MongodStarter
.
getDefaultInstance
();
private
static
MongodExecutable
_mongodExe
;
private
static
MongodProcess
_mongod
;
private
static
final
String
testApplicationExampleToscaFilePath
=
".."
+
File
.
separator
+
"TOSCA"
+
File
.
separator
+
"application_example.yaml"
;
private
static
final
String
testUpdatedApplicationExampleToscaFilePath
=
".."
+
File
.
separator
+
"TOSCA"
+
File
.
separator
+
"application_example_updated.yaml"
;
@BeforeClass
public
static
void
setUpClass
()
{
try
{
_mongodExe
=
starter
.
prepare
(
new
MongodConfigBuilder
()
.
version
(
Version
.
Main
.
PRODUCTION
)
.
net
(
new
Net
(
"localhost"
,
12345
,
Network
.
localhostIsIPv6
()))
.
net
(
new
Net
(
MongoConfig
.
MONGO_TEST_HOST
,
MongoConfig
.
MONGO_TEST_PORT
,
Network
.
localhostIsIPv6
()))
.
build
());
_mongod
=
_mongodExe
.
start
();
}
catch
(
IOException
ex
)
{
Logger
.
getLogger
(
ToscaTemplateServiceTest
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
Logger
.
getLogger
(
ServiceTests
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
}
...
...
@@ -83,8 +94,6 @@ public class ToscaTemplateServiceTest {
_mongodExe
.
stop
();
}
private
String
toscaTemplateID
;
private
String
testApplicationExampleToscaContents
;
@Before
public
void
setUp
()
{
...
...
@@ -94,19 +103,22 @@ public class ToscaTemplateServiceTest {
@After
public
void
tearDown
()
{
}
/**
* Test of saveFile method, of class ToscaTemplateService.
*
* @throws java.lang.Exception
*/
@Test
public
void
testSaveFile
()
throws
Exception
{
Logger
.
getLogger
(
ToscaTemplateServiceTest
.
class
.
getName
()).
log
(
Level
.
INFO
,
"saveFile"
);
public
void
test
ToscaTemplateService
SaveFile
()
throws
Exception
{
Logger
.
getLogger
(
ServiceTests
.
class
.
getName
()).
log
(
Level
.
INFO
,
"saveFile"
);
FileInputStream
in
=
new
FileInputStream
(
testApplicationExampleToscaFilePath
);
MultipartFile
file
=
new
MockMultipartFile
(
"file"
,
in
);
toscaTemplateID
=
instan
ce
.
saveFile
(
file
);
toscaTemplateID
=
toscaTemplateServi
ce
.
saveFile
(
file
);
Assert
.
assertNotNull
(
toscaTemplateID
);
testApplicationExampleToscaContents
=
instan
ce
.
findByID
(
toscaTemplateID
);
testApplicationExampleToscaContents
=
toscaTemplateServi
ce
.
findByID
(
toscaTemplateID
);
Assert
.
assertNotNull
(
testApplicationExampleToscaContents
);
}
...
...
@@ -114,31 +126,33 @@ public class ToscaTemplateServiceTest {
* Test of updateToscaTemplateByID method, of class ToscaTemplateService.
*/
@Test
public
void
testUpdateToscaTemplateByID_String_MultipartFile
()
{
public
void
test
ToscaTemplateService
UpdateToscaTemplateByID_String_MultipartFile
()
{
FileInputStream
in
=
null
;
try
{
Logger
.
getLogger
(
ToscaTemplateServiceTest
.
class
.
getName
()).
log
(
Level
.
INFO
,
"updateToscaTemplateByID"
);
Logger
.
getLogger
(
ServiceTests
.
class
.
getName
()).
log
(
Level
.
INFO
,
"updateToscaTemplateByID"
);
if
(
toscaTemplateID
==
null
)
{
testSaveFile
();
test
ToscaTemplateService
SaveFile
();
}
in
=
new
FileInputStream
(
testUpdatedApplicationExampleToscaFilePath
);
MultipartFile
file
=
new
MockMultipartFile
(
"file"
,
in
);
String
expResult
=
toscaTemplateID
;
String
result
=
instan
ce
.
updateToscaTemplateByID
(
toscaTemplateID
,
file
);
String
result
=
toscaTemplateServi
ce
.
updateToscaTemplateByID
(
toscaTemplateID
,
file
);
assertEquals
(
expResult
,
result
);
String
updatedTemplate
=
instan
ce
.
findByID
(
result
);
String
updatedTemplate
=
toscaTemplateServi
ce
.
findByID
(
result
);
Assert
.
assertNotNull
(
updatedTemplate
);
Assert
.
assertNotEquals
(
result
,
testApplicationExampleToscaContents
);
}
catch
(
FileNotFoundException
ex
)
{
Logger
.
getLogger
(
ToscaTemplateServiceTest
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
Logger
.
getLogger
(
ServiceTests
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
catch
(
Exception
ex
)
{
Logger
.
getLogger
(
ToscaTemplateServiceTest
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
Logger
.
getLogger
(
ServiceTests
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
finally
{
try
{
in
.
close
();
if
(
in
!=
null
)
{
in
.
close
();
}
}
catch
(
IOException
ex
)
{
fail
(
ex
.
getMessage
());
Logger
.
getLogger
(
ToscaTemplateServiceTest
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
Logger
.
getLogger
(
ServiceTests
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
}
}
...
...
@@ -149,11 +163,11 @@ public class ToscaTemplateServiceTest {
* @throws java.io.FileNotFoundException
*/
@Test
public
void
testUpdateToscaTemplateByID_Exception_MultipartFile
()
throws
FileNotFoundException
,
IOException
{
public
void
test
ToscaTemplateService
UpdateToscaTemplateByID_Exception_MultipartFile
()
throws
FileNotFoundException
,
IOException
{
FileInputStream
in
=
new
FileInputStream
(
testUpdatedApplicationExampleToscaFilePath
);
MultipartFile
file
=
new
MockMultipartFile
(
"file"
,
in
);
try
{
String
result
=
instan
ce
.
updateToscaTemplateByID
(
"0"
,
file
);
toscaTemplateServi
ce
.
updateToscaTemplateByID
(
"0"
,
file
);
}
catch
(
Exception
ex
)
{
if
(!(
ex
instanceof
NoSuchElementException
))
{
fail
(
ex
.
getMessage
());
...
...
@@ -165,21 +179,21 @@ public class ToscaTemplateServiceTest {
* Test of findByID method, of class ToscaTemplateService.
*/
@Test
public
void
testFindByID
()
{
public
void
test
ToscaTemplateService
FindByID
()
{
try
{
Logger
.
getLogger
(
ToscaTemplateServiceTest
.
class
.
getName
()).
log
(
Level
.
INFO
,
"findByID"
);
Logger
.
getLogger
(
ServiceTests
.
class
.
getName
()).
log
(
Level
.
INFO
,
"findByID"
);
if
(
toscaTemplateID
==
null
)
{
testSaveFile
();
test
ToscaTemplateService
SaveFile
();
}
String
result
=
instan
ce
.
findByID
(
toscaTemplateID
);
String
result
=
toscaTemplateServi
ce
.
findByID
(
toscaTemplateID
);
Assert
.
assertNotNull
(
result
);
assertEquals
(
testApplicationExampleToscaContents
,
result
);
}
catch
(
JsonProcessingException
ex
)
{
fail
(
ex
.
getMessage
());
Logger
.
getLogger
(
ToscaTemplateServiceTest
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
Logger
.
getLogger
(
ServiceTests
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
catch
(
Exception
ex
)
{
fail
(
ex
.
getMessage
());
Logger
.
getLogger
(
ToscaTemplateServiceTest
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
Logger
.
getLogger
(
ServiceTests
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
}
...
...
@@ -187,26 +201,26 @@ public class ToscaTemplateServiceTest {
* Test of deleteByID method, of class ToscaTemplateService.
*/
@Test
public
void
testDeleteByID
()
{
public
void
test
ToscaTemplateService
DeleteByID
()
{
try
{
Logger
.
getLogger
(
ToscaTemplateServiceTest
.
class
.
getName
()).
log
(
Level
.
INFO
,
"deleteByID"
);
Logger
.
getLogger
(
ServiceTests
.
class
.
getName
()).
log
(
Level
.
INFO
,
"deleteByID"
);
if
(
toscaTemplateID
==
null
)
{
testSaveFile
();
test
ToscaTemplateService
SaveFile
();
}
instan
ce
.
deleteByID
(
toscaTemplateID
);
String
id
=
instan
ce
.
findByID
(
toscaTemplateID
);
toscaTemplateServi
ce
.
deleteByID
(
toscaTemplateID
);
String
id
=
toscaTemplateServi
ce
.
findByID
(
toscaTemplateID
);
}
catch
(
Exception
ex
)
{
if
(!(
ex
instanceof
NoSuchElementException
))
{
fail
(
ex
.
getMessage
());
Logger
.
getLogger
(
ToscaTemplateServiceTest
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
Logger
.
getLogger
(
ServiceTests
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
}
finally
{
try
{
testSaveFile
();
test
ToscaTemplateService
SaveFile
();
}
catch
(
Exception
ex
)
{
fail
(
ex
.
getMessage
());
Logger
.
getLogger
(
ToscaTemplateServiceTest
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
Logger
.
getLogger
(
ServiceTests
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
}
}
...
...
@@ -215,21 +229,99 @@ public class ToscaTemplateServiceTest {
* Test of getAllIds method, of class ToscaTemplateService.
*/
@Test
public
void
testGetAllIds
()
throws
Exception
{
Logger
.
getLogger
(
ToscaTemplateServiceTest
.
class
.
getName
()).
log
(
Level
.
INFO
,
"getAllIds"
);
testDeleteAll
();
public
void
test
ToscaTemplateService
GetAllIds
()
throws
Exception
{
Logger
.
getLogger
(
ServiceTests
.
class
.
getName
()).
log
(
Level
.
INFO
,
"getAllIds"
);
test
ToscaTemplateService
DeleteAll
();
int
numOfINst
=
3
;
for
(
int
i
=
1
;
i
<=
numOfINst
;
i
++)
{
testSaveFile
();
test
ToscaTemplateService
SaveFile
();
}
List
<
String
>
result
=
instan
ce
.
getAllIds
();
List
<
String
>
result
=
toscaTemplateServi
ce
.
getAllIds
();
assertEquals
(
numOfINst
,
result
.
size
());
}
@Test
public
void
testDeleteAll
()
{
instance
.
deleteAll
();
int
size
=
instance
.
getAllIds
().
size
();
public
void
testToscaTemplateServiceDeleteAll
()
{
toscaTemplateService
.
deleteAll
();
int
size
=
toscaTemplateService
.
getAllIds
().
size
();
assertEquals
(
0
,
size
);
}
/**
* Test of save method, of class CredentialService.
*/
@Test
public
void
testCredentialServiceSave
()
{
Logger
.
getLogger
(
ServiceTests
.
class
.
getName
()).
log
(
Level
.
INFO
,
"save"
);
Credentials
document
=
new
Credentials
();
document
.
setCloudProviderName
(
"exogeni"
);
Map
<
String
,
String
>
keys
=
new
HashMap
<>();
keys
.
put
(
"keystore"
,
"/qTlqams0Ppq2rnaOgL5am7ExGO2nMsOZYM61kiAnsvkOixUuoPy9r4d4OfhwQXXg3lZmeRITjNz4ps+hIDKuxodIQXgBtfMy9Kx8Syb9bIl/MQQls5hWyp9yHAl6vAampoxYu0170lceT1sds4OCz3tM9eF7/UoBQwXBPo94QhO1/vSbtICyVsm3Z2HeGKcBWobT3opZV2w30GqX/7OBmNeIG7RBMPuxLsUxJ9Alahi1zXOUjLkd2bmmVFREngmeubgCzPFxxCQQrZK6WratTzJKc1sRVNK5GJzTwi9BlcZSQSgprum9yVHUgQc6Ylmvdrkhn2g9SlluY2JAZyCZvHYaRBKE4o5bXBDumTy1YAPMNPTfpeeLz+YmH0GMfVwKkxtIBpjb045QseoIWcqxke60WWfJguaTqymXknmcqcLNz+UzUdfVfyurOy9X8xmTGCW5V4N"
);
document
.
setKeys
(
keys
);
document
.
setToken
(
"secret"
);
document
.
setTokenType
(
"password"
);
credentialID
=
credentialService
.
save
(
document
);
assertNotNull
(
credentialID
);
}
/**
* Test of findByID method, of class CredentialService.
*
* @throws java.lang.Exception
*/
@Test
public
void
testCredentialServiceFindByID
()
throws
Exception
{
Logger
.
getLogger
(
ServiceTests
.
class
.
getName
()).
log
(
Level
.
INFO
,
"findByID"
);
if
(
credentialID
==
null
)
{
testCredentialServiceSave
();
}
String
id
=
credentialID
;
Credentials
result
=
credentialService
.
findByID
(
id
);
assertNotNull
(
result
);
}
/**
* Test of deleteByID method, of class CredentialService.
*/
@Test
public
void
testCredentialServiceDeleteByID
()
throws
JsonProcessingException
{
Logger
.
getLogger
(
ServiceTests
.
class
.
getName
()).
log
(
Level
.
INFO
,
"deleteByID"
);
if
(
credentialID
==
null
)
{
testCredentialServiceSave
();
}
credentialService
.
deleteByID
(
credentialID
);
try
{
Credentials
res
=
credentialService
.
findByID
(
credentialID
);
}
catch
(
Exception
ex
)
{
if
(!(
ex
instanceof
NoSuchElementException
))
{
fail
(
ex
.
getMessage
());
}
}
}
/**
* Test of getAllIds method, of class CredentialService.
*/
@Test
public
void
testCredentialServiceGetAllIds
()
{
Logger
.
getLogger
(
ServiceTests
.
class
.
getName
()).
log
(
Level
.
INFO
,
"getAllIds"
);
testCredentialServiceDeleteAll
();
int
numOfINst
=
3
;
for
(
int
i
=
1
;
i
<=
numOfINst
;
i
++)
{
testCredentialServiceSave
();
}
List
<
String
>
result
=
credentialService
.
getAllIds
();
assertEquals
(
numOfINst
,
result
.
size
());
}
/**
* Test of deleteAll method, of class CredentialService.
*/
@Test
public
void
testCredentialServiceDeleteAll
()
{
credentialService
.
deleteAll
();
int
size
=
credentialService
.
getAllIds
().
size
();
assertEquals
(
0
,
size
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment