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);
} }
} }
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