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;
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);
}
}
......@@ -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;
}
......
/*
* 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;
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 = "")
......
......@@ -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;
......
/*
* 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 @@
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);
}
}
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