Commit a772559e authored by Spiros Koulouzis's avatar Spiros Koulouzis

added test in one because we have only one mongDB. Need to create testcases

parent 3657f0f4
...@@ -8,18 +8,14 @@ import org.slf4j.LoggerFactory; ...@@ -8,18 +8,14 @@ import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller; 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.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.validation.Valid;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.io.IOException; import java.io.IOException;
import java.util.List; 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") @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 { ...@@ -32,29 +28,35 @@ public class CredentialApiController implements CredentialApi {
private final HttpServletRequest request; private final HttpServletRequest request;
@Autowired
private CredentialService credentialService;
@org.springframework.beans.factory.annotation.Autowired @org.springframework.beans.factory.annotation.Autowired
public CredentialApiController(ObjectMapper objectMapper, HttpServletRequest request) { public CredentialApiController(ObjectMapper objectMapper, HttpServletRequest request) {
this.objectMapper = objectMapper; this.objectMapper = objectMapper;
this.request = request; 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"); String accept = request.getHeader("Accept");
if (accept != null && accept.contains("application/json")) { if (accept != null && accept.contains("application/json")) {
try { String id = credentialService.save(body);
return new ResponseEntity<String>(objectMapper.readValue("\"\"", String.class), HttpStatus.NOT_IMPLEMENTED); return new ResponseEntity<>(id, HttpStatus.OK);
} catch (IOException e) {
log.error("Couldn't serialize response for content type application/json", e);
return new ResponseEntity<String>(HttpStatus.INTERNAL_SERVER_ERROR);
}
} }
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
return new ResponseEntity<String>(HttpStatus.NOT_IMPLEMENTED);
} }
@Override @Override
public ResponseEntity<List<String>> getCredentialIDs() { 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);
} }
} }
...@@ -25,8 +25,6 @@ public class ToscaTemplateApiController implements ToscaTemplateApi { ...@@ -25,8 +25,6 @@ public class ToscaTemplateApiController implements ToscaTemplateApi {
private static final Logger log = LoggerFactory.getLogger(ToscaTemplateApiController.class); private static final Logger log = LoggerFactory.getLogger(ToscaTemplateApiController.class);
private final ObjectMapper objectMapper;
private final HttpServletRequest request; private final HttpServletRequest request;
@Autowired @Autowired
...@@ -34,7 +32,6 @@ public class ToscaTemplateApiController implements ToscaTemplateApi { ...@@ -34,7 +32,6 @@ public class ToscaTemplateApiController implements ToscaTemplateApi {
@org.springframework.beans.factory.annotation.Autowired @org.springframework.beans.factory.annotation.Autowired
public ToscaTemplateApiController(ObjectMapper objectMapper, HttpServletRequest request) { public ToscaTemplateApiController(ObjectMapper objectMapper, HttpServletRequest request) {
this.objectMapper = objectMapper;
this.request = request; this.request = request;
} }
......
/*
* 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> {
}
package nl.uva.sne.drip.model; package nl.uva.sne.drip.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonInclude.Include;
import java.util.Objects; import java.util.Objects;
...@@ -9,6 +10,7 @@ import java.util.HashMap; ...@@ -9,6 +10,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import javax.validation.Valid; import javax.validation.Valid;
import org.springframework.data.annotation.Id;
/** /**
* Credentials * Credentials
...@@ -17,6 +19,10 @@ import javax.validation.Valid; ...@@ -17,6 +19,10 @@ import javax.validation.Valid;
@JsonInclude(Include.NON_NULL) @JsonInclude(Include.NON_NULL)
public class Credentials { public class Credentials {
@Id
@JsonIgnore
private String id;
@JsonProperty("protocol") @JsonProperty("protocol")
private String protocol = null; private String protocol = null;
...@@ -41,11 +47,20 @@ public class Credentials { ...@@ -41,11 +47,20 @@ public class Credentials {
return this; return this;
} }
@JsonIgnore
public String getId() {
return id;
}
public void setID(String id) {
this.id = id;
}
/** /**
* Get protocol * Get protocol
* *
* @return protocol * @return protocol
* *
*/ */
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
...@@ -66,7 +81,7 @@ public class Credentials { ...@@ -66,7 +81,7 @@ public class Credentials {
* Get tokenType * Get tokenType
* *
* @return tokenType * @return tokenType
* *
*/ */
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
...@@ -87,7 +102,7 @@ public class Credentials { ...@@ -87,7 +102,7 @@ public class Credentials {
* Get token * Get token
* *
* @return token * @return token
* *
*/ */
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
...@@ -116,7 +131,7 @@ public class Credentials { ...@@ -116,7 +131,7 @@ public class Credentials {
* Get keys * Get keys
* *
* @return keys * @return keys
* *
*/ */
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
...@@ -137,7 +152,7 @@ public class Credentials { ...@@ -137,7 +152,7 @@ public class Credentials {
* Get user * Get user
* *
* @return user * @return user
* *
*/ */
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
...@@ -158,7 +173,7 @@ public class Credentials { ...@@ -158,7 +173,7 @@ public class Credentials {
* Get cloudProviderName * Get cloudProviderName
* *
* @return cloudProviderName * @return cloudProviderName
* *
*/ */
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
......
...@@ -170,7 +170,7 @@ public class ToscaTemplate { ...@@ -170,7 +170,7 @@ public class ToscaTemplate {
public ToscaTemplate addImportsItem(Map<String, String> importsItem) { public ToscaTemplate addImportsItem(Map<String, String> importsItem) {
if (this.imports == null) { if (this.imports == null) {
this.imports = new ArrayList<Map<String, String>>(); this.imports = new ArrayList<>();
} }
this.imports.add(importsItem); this.imports.add(importsItem);
return this; return this;
...@@ -201,7 +201,7 @@ public class ToscaTemplate { ...@@ -201,7 +201,7 @@ public class ToscaTemplate {
public ToscaTemplate putRepositoriesItem(String key, String repositoriesItem) { public ToscaTemplate putRepositoriesItem(String key, String repositoriesItem) {
if (this.repositories == null) { if (this.repositories == null) {
this.repositories = new HashMap<String, String>(); this.repositories = new HashMap<>();
} }
this.repositories.put(key, repositoriesItem); this.repositories.put(key, repositoriesItem);
return this; return this;
...@@ -230,7 +230,7 @@ public class ToscaTemplate { ...@@ -230,7 +230,7 @@ public class ToscaTemplate {
public ToscaTemplate putDslDefinitionsItem(String key, String dslDefinitionsItem) { public ToscaTemplate putDslDefinitionsItem(String key, String dslDefinitionsItem) {
if (this.dslDefinitions == null) { if (this.dslDefinitions == null) {
this.dslDefinitions = new HashMap<String, String>(); this.dslDefinitions = new HashMap<>();
} }
this.dslDefinitions.put(key, dslDefinitionsItem); this.dslDefinitions.put(key, dslDefinitionsItem);
return this; return this;
...@@ -259,7 +259,7 @@ public class ToscaTemplate { ...@@ -259,7 +259,7 @@ public class ToscaTemplate {
public ToscaTemplate putNodeTypesItem(String key, Object nodeTypesItem) { public ToscaTemplate putNodeTypesItem(String key, Object nodeTypesItem) {
if (this.nodeTypes == null) { if (this.nodeTypes == null) {
this.nodeTypes = new HashMap<String, Object>(); this.nodeTypes = new HashMap<>();
} }
this.nodeTypes.put(key, nodeTypesItem); this.nodeTypes.put(key, nodeTypesItem);
return this; return this;
...@@ -311,7 +311,7 @@ public class ToscaTemplate { ...@@ -311,7 +311,7 @@ public class ToscaTemplate {
public ToscaTemplate putRelationshipTypesItem(String key, Object relationshipTypesItem) { public ToscaTemplate putRelationshipTypesItem(String key, Object relationshipTypesItem) {
if (this.relationshipTypes == null) { if (this.relationshipTypes == null) {
this.relationshipTypes = new HashMap<String, Object>(); this.relationshipTypes = new HashMap<>();
} }
this.relationshipTypes.put(key, relationshipTypesItem); this.relationshipTypes.put(key, relationshipTypesItem);
return this; return this;
...@@ -340,7 +340,7 @@ public class ToscaTemplate { ...@@ -340,7 +340,7 @@ public class ToscaTemplate {
public ToscaTemplate putRelationshipTemplatesItem(String key, Object relationshipTemplatesItem) { public ToscaTemplate putRelationshipTemplatesItem(String key, Object relationshipTemplatesItem) {
if (this.relationshipTemplates == null) { if (this.relationshipTemplates == null) {
this.relationshipTemplates = new HashMap<String, Object>(); this.relationshipTemplates = new HashMap<>();
} }
this.relationshipTemplates.put(key, relationshipTemplatesItem); this.relationshipTemplates.put(key, relationshipTemplatesItem);
return this; return this;
...@@ -369,7 +369,7 @@ public class ToscaTemplate { ...@@ -369,7 +369,7 @@ public class ToscaTemplate {
public ToscaTemplate putCapabilityTypesItem(String key, Object capabilityTypesItem) { public ToscaTemplate putCapabilityTypesItem(String key, Object capabilityTypesItem) {
if (this.capabilityTypes == null) { if (this.capabilityTypes == null) {
this.capabilityTypes = new HashMap<String, Object>(); this.capabilityTypes = new HashMap<>();
} }
this.capabilityTypes.put(key, capabilityTypesItem); this.capabilityTypes.put(key, capabilityTypesItem);
return this; return this;
...@@ -398,7 +398,7 @@ public class ToscaTemplate { ...@@ -398,7 +398,7 @@ public class ToscaTemplate {
public ToscaTemplate putArtifactTypesItem(String key, Object artifactTypesItem) { public ToscaTemplate putArtifactTypesItem(String key, Object artifactTypesItem) {
if (this.artifactTypes == null) { if (this.artifactTypes == null) {
this.artifactTypes = new HashMap<String, Object>(); this.artifactTypes = new HashMap<>();
} }
this.artifactTypes.put(key, artifactTypesItem); this.artifactTypes.put(key, artifactTypesItem);
return this; return this;
...@@ -427,7 +427,7 @@ public class ToscaTemplate { ...@@ -427,7 +427,7 @@ public class ToscaTemplate {
public ToscaTemplate putDataTypesItem(String key, Object dataTypesItem) { public ToscaTemplate putDataTypesItem(String key, Object dataTypesItem) {
if (this.dataTypes == null) { if (this.dataTypes == null) {
this.dataTypes = new HashMap<String, Object>(); this.dataTypes = new HashMap<>();
} }
this.dataTypes.put(key, dataTypesItem); this.dataTypes.put(key, dataTypesItem);
return this; return this;
...@@ -456,7 +456,7 @@ public class ToscaTemplate { ...@@ -456,7 +456,7 @@ public class ToscaTemplate {
public ToscaTemplate putInterfaceTypesItem(String key, Object interfaceTypesItem) { public ToscaTemplate putInterfaceTypesItem(String key, Object interfaceTypesItem) {
if (this.interfaceTypes == null) { if (this.interfaceTypes == null) {
this.interfaceTypes = new HashMap<String, Object>(); this.interfaceTypes = new HashMap<>();
} }
this.interfaceTypes.put(key, interfaceTypesItem); this.interfaceTypes.put(key, interfaceTypesItem);
return this; return this;
...@@ -485,7 +485,7 @@ public class ToscaTemplate { ...@@ -485,7 +485,7 @@ public class ToscaTemplate {
public ToscaTemplate putPolicyTypesItem(String key, String policyTypesItem) { public ToscaTemplate putPolicyTypesItem(String key, String policyTypesItem) {
if (this.policyTypes == null) { if (this.policyTypes == null) {
this.policyTypes = new HashMap<String, String>(); this.policyTypes = new HashMap<>();
} }
this.policyTypes.put(key, policyTypesItem); this.policyTypes.put(key, policyTypesItem);
return this; return this;
...@@ -514,7 +514,7 @@ public class ToscaTemplate { ...@@ -514,7 +514,7 @@ public class ToscaTemplate {
public ToscaTemplate putGroupTypesItem(String key, Object groupTypesItem) { public ToscaTemplate putGroupTypesItem(String key, Object groupTypesItem) {
if (this.groupTypes == null) { if (this.groupTypes == null) {
this.groupTypes = new HashMap<String, Object>(); this.groupTypes = new HashMap<>();
} }
this.groupTypes.put(key, groupTypesItem); this.groupTypes.put(key, groupTypesItem);
return this; return this;
......
/*
* 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();
}
}
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
package nl.uva.sne.drip.configuration; package nl.uva.sne.drip.configuration;
import com.mongodb.MongoClient; import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.config.AbstractMongoConfiguration; import org.springframework.data.mongodb.config.AbstractMongoConfiguration;
...@@ -28,6 +29,9 @@ 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"}) @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 class MongoConfig extends AbstractMongoConfiguration {
public static int MONGO_TEST_PORT = 12345;
public static String MONGO_TEST_HOST = "localhost";
@Override @Override
protected String getDatabaseName() { protected String getDatabaseName() {
return "test-db"; return "test-db";
...@@ -40,9 +44,6 @@ public class MongoConfig extends AbstractMongoConfiguration { ...@@ -40,9 +44,6 @@ public class MongoConfig extends AbstractMongoConfiguration {
@Override @Override
public MongoClient mongoClient() { public MongoClient mongoClient() {
return new MongoClient(MONGO_TEST_HOST, MONGO_TEST_PORT);
String bindIp = "localhost";
int port = 12345;
return new MongoClient(bindIp, port);
} }
} }
...@@ -6,6 +6,13 @@ ...@@ -6,6 +6,13 @@
package nl.uva.sne.drip.service; package nl.uva.sne.drip.service;
import com.fasterxml.jackson.core.JsonProcessingException; 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.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -17,25 +24,22 @@ import org.junit.AfterClass; ...@@ -17,25 +24,22 @@ import org.junit.AfterClass;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; 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.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import nl.uva.sne.drip.Swagger2SpringBoot; 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 org.junit.Assert;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import org.springframework.mock.web.MockMultipartFile; import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.context.web.WebAppConfiguration;
...@@ -48,10 +52,19 @@ import org.springframework.web.multipart.MultipartFile; ...@@ -48,10 +52,19 @@ import org.springframework.web.multipart.MultipartFile;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration @WebAppConfiguration
@ContextConfiguration(classes = {Swagger2SpringBoot.class}) @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 @Autowired
ToscaTemplateService instance; CredentialService credentialService;
private String credentialID;
@Autowired @Autowired
private WebApplicationContext wac; private WebApplicationContext wac;
...@@ -60,20 +73,18 @@ public class ToscaTemplateServiceTest { ...@@ -60,20 +73,18 @@ public class ToscaTemplateServiceTest {
private static final MongodStarter starter = MongodStarter.getDefaultInstance(); private static final MongodStarter starter = MongodStarter.getDefaultInstance();
private static MongodExecutable _mongodExe; private static MongodExecutable _mongodExe;
private static MongodProcess _mongod; 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 @BeforeClass
public static void setUpClass() { public static void setUpClass() {
try { try {
_mongodExe = starter.prepare(new MongodConfigBuilder() _mongodExe = starter.prepare(new MongodConfigBuilder()
.version(Version.Main.PRODUCTION) .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()); .build());
_mongod = _mongodExe.start(); _mongod = _mongodExe.start();
} catch (IOException ex) { } 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 { ...@@ -83,8 +94,6 @@ public class ToscaTemplateServiceTest {
_mongodExe.stop(); _mongodExe.stop();
} }
private String toscaTemplateID;
private String testApplicationExampleToscaContents;
@Before @Before
public void setUp() { public void setUp() {
...@@ -94,19 +103,22 @@ public class ToscaTemplateServiceTest { ...@@ -94,19 +103,22 @@ public class ToscaTemplateServiceTest {
@After @After
public void tearDown() { public void tearDown() {
} }
/** /**
* Test of saveFile method, of class ToscaTemplateService. * Test of saveFile method, of class ToscaTemplateService.
*
* @throws java.lang.Exception
*/ */
@Test @Test
public void testSaveFile() throws Exception { public void testToscaTemplateServiceSaveFile() throws Exception {
Logger.getLogger(ToscaTemplateServiceTest.class.getName()).log(Level.INFO, "saveFile"); Logger.getLogger(ServiceTests.class.getName()).log(Level.INFO, "saveFile");
FileInputStream in = new FileInputStream(testApplicationExampleToscaFilePath); FileInputStream in = new FileInputStream(testApplicationExampleToscaFilePath);
MultipartFile file = new MockMultipartFile("file", in); MultipartFile file = new MockMultipartFile("file", in);
toscaTemplateID = instance.saveFile(file); toscaTemplateID = toscaTemplateService.saveFile(file);
Assert.assertNotNull(toscaTemplateID); Assert.assertNotNull(toscaTemplateID);
testApplicationExampleToscaContents = instance.findByID(toscaTemplateID); testApplicationExampleToscaContents = toscaTemplateService.findByID(toscaTemplateID);
Assert.assertNotNull(testApplicationExampleToscaContents); Assert.assertNotNull(testApplicationExampleToscaContents);
} }
...@@ -114,31 +126,33 @@ public class ToscaTemplateServiceTest { ...@@ -114,31 +126,33 @@ public class ToscaTemplateServiceTest {
* Test of updateToscaTemplateByID method, of class ToscaTemplateService. * Test of updateToscaTemplateByID method, of class ToscaTemplateService.
*/ */
@Test @Test
public void testUpdateToscaTemplateByID_String_MultipartFile() { public void testToscaTemplateServiceUpdateToscaTemplateByID_String_MultipartFile() {
FileInputStream in = null; FileInputStream in = null;
try { try {
Logger.getLogger(ToscaTemplateServiceTest.class.getName()).log(Level.INFO, "updateToscaTemplateByID"); Logger.getLogger(ServiceTests.class.getName()).log(Level.INFO, "updateToscaTemplateByID");
if (toscaTemplateID == null) { if (toscaTemplateID == null) {
testSaveFile(); testToscaTemplateServiceSaveFile();
} }
in = new FileInputStream(testUpdatedApplicationExampleToscaFilePath); in = new FileInputStream(testUpdatedApplicationExampleToscaFilePath);
MultipartFile file = new MockMultipartFile("file", in); MultipartFile file = new MockMultipartFile("file", in);
String expResult = toscaTemplateID; String expResult = toscaTemplateID;
String result = instance.updateToscaTemplateByID(toscaTemplateID, file); String result = toscaTemplateService.updateToscaTemplateByID(toscaTemplateID, file);
assertEquals(expResult, result); assertEquals(expResult, result);
String updatedTemplate = instance.findByID(result); String updatedTemplate = toscaTemplateService.findByID(result);
Assert.assertNotNull(updatedTemplate); Assert.assertNotNull(updatedTemplate);
Assert.assertNotEquals(result, testApplicationExampleToscaContents); Assert.assertNotEquals(result, testApplicationExampleToscaContents);
} catch (FileNotFoundException ex) { } 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) { } catch (Exception ex) {
Logger.getLogger(ToscaTemplateServiceTest.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(ServiceTests.class.getName()).log(Level.SEVERE, null, ex);
} finally { } finally {
try { try {
in.close(); if (in != null) {
in.close();
}
} catch (IOException ex) { } catch (IOException ex) {
fail(ex.getMessage()); 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 { ...@@ -149,11 +163,11 @@ public class ToscaTemplateServiceTest {
* @throws java.io.FileNotFoundException * @throws java.io.FileNotFoundException
*/ */
@Test @Test
public void testUpdateToscaTemplateByID_Exception_MultipartFile() throws FileNotFoundException, IOException { public void testToscaTemplateServiceUpdateToscaTemplateByID_Exception_MultipartFile() throws FileNotFoundException, IOException {
FileInputStream in = new FileInputStream(testUpdatedApplicationExampleToscaFilePath); FileInputStream in = new FileInputStream(testUpdatedApplicationExampleToscaFilePath);
MultipartFile file = new MockMultipartFile("file", in); MultipartFile file = new MockMultipartFile("file", in);
try { try {
String result = instance.updateToscaTemplateByID("0", file); toscaTemplateService.updateToscaTemplateByID("0", file);
} catch (Exception ex) { } catch (Exception ex) {
if (!(ex instanceof NoSuchElementException)) { if (!(ex instanceof NoSuchElementException)) {
fail(ex.getMessage()); fail(ex.getMessage());
...@@ -165,21 +179,21 @@ public class ToscaTemplateServiceTest { ...@@ -165,21 +179,21 @@ public class ToscaTemplateServiceTest {
* Test of findByID method, of class ToscaTemplateService. * Test of findByID method, of class ToscaTemplateService.
*/ */
@Test @Test
public void testFindByID() { public void testToscaTemplateServiceFindByID() {
try { try {
Logger.getLogger(ToscaTemplateServiceTest.class.getName()).log(Level.INFO, "findByID"); Logger.getLogger(ServiceTests.class.getName()).log(Level.INFO, "findByID");
if (toscaTemplateID == null) { if (toscaTemplateID == null) {
testSaveFile(); testToscaTemplateServiceSaveFile();
} }
String result = instance.findByID(toscaTemplateID); String result = toscaTemplateService.findByID(toscaTemplateID);
Assert.assertNotNull(result); Assert.assertNotNull(result);
assertEquals(testApplicationExampleToscaContents, result); assertEquals(testApplicationExampleToscaContents, result);
} catch (JsonProcessingException ex) { } catch (JsonProcessingException ex) {
fail(ex.getMessage()); 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) { } catch (Exception ex) {
fail(ex.getMessage()); 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 { ...@@ -187,26 +201,26 @@ public class ToscaTemplateServiceTest {
* Test of deleteByID method, of class ToscaTemplateService. * Test of deleteByID method, of class ToscaTemplateService.
*/ */
@Test @Test
public void testDeleteByID() { public void testToscaTemplateServiceDeleteByID() {
try { try {
Logger.getLogger(ToscaTemplateServiceTest.class.getName()).log(Level.INFO, "deleteByID"); Logger.getLogger(ServiceTests.class.getName()).log(Level.INFO, "deleteByID");
if (toscaTemplateID == null) { if (toscaTemplateID == null) {
testSaveFile(); testToscaTemplateServiceSaveFile();
} }
instance.deleteByID(toscaTemplateID); toscaTemplateService.deleteByID(toscaTemplateID);
String id = instance.findByID(toscaTemplateID); String id = toscaTemplateService.findByID(toscaTemplateID);
} catch (Exception ex) { } catch (Exception ex) {
if (!(ex instanceof NoSuchElementException)) { if (!(ex instanceof NoSuchElementException)) {
fail(ex.getMessage()); fail(ex.getMessage());
Logger.getLogger(ToscaTemplateServiceTest.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(ServiceTests.class.getName()).log(Level.SEVERE, null, ex);
} }
} finally { } finally {
try { try {
testSaveFile(); testToscaTemplateServiceSaveFile();
} catch (Exception ex) { } catch (Exception ex) {
fail(ex.getMessage()); 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 { ...@@ -215,21 +229,99 @@ public class ToscaTemplateServiceTest {
* Test of getAllIds method, of class ToscaTemplateService. * Test of getAllIds method, of class ToscaTemplateService.
*/ */
@Test @Test
public void testGetAllIds() throws Exception { public void testToscaTemplateServiceGetAllIds() throws Exception {
Logger.getLogger(ToscaTemplateServiceTest.class.getName()).log(Level.INFO, "getAllIds"); Logger.getLogger(ServiceTests.class.getName()).log(Level.INFO, "getAllIds");
testDeleteAll(); testToscaTemplateServiceDeleteAll();
int numOfINst = 3; int numOfINst = 3;
for (int i = 1; i <= numOfINst; i++) { for (int i = 1; i <= numOfINst; i++) {
testSaveFile(); testToscaTemplateServiceSaveFile();
} }
List<String> result = instance.getAllIds(); List<String> result = toscaTemplateService.getAllIds();
assertEquals(numOfINst, result.size()); assertEquals(numOfINst, result.size());
} }
@Test @Test
public void testDeleteAll() { public void testToscaTemplateServiceDeleteAll() {
instance.deleteAll(); toscaTemplateService.deleteAll();
int size = instance.getAllIds().size(); 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); assertEquals(0, size);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment