Commit 5f66fae5 authored by Spiros Koulouzis's avatar Spiros Koulouzis

Moved commons to api

Added documentation
Renamed api to add version 
parent f2c80f09
<?xml version="1.0" encoding="UTF-8"?>
<enunciate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://enunciate.webcohesion.com/schemas/enunciate-1.30.xsd">
<facets>
<exclude name="internal_api" />
</facets>
<api-classes>
<include pattern="nl.uva.sne.drip.api.rest.*" />
<include pattern="nl.uva.sne.drip.commons.types.*" />
</api-classes>
<modules>
<swagger disabled="true" />
</modules>
</enunciate>
......@@ -21,11 +21,6 @@
</properties>
<dependencies>
<dependency>
<groupId>nl.uva.sne.drip</groupId>
<artifactId>drip-commons</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
......@@ -100,7 +95,18 @@
<scope>test</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.webcohesion.enunciate</groupId>
<artifactId>enunciate-core-annotations</artifactId>
<version>2.8.1</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
......@@ -179,15 +185,15 @@
<plugin>
<groupId>com.webcohesion.enunciate</groupId>
<artifactId>enunciate-maven-plugin</artifactId>
<version>2.8.0</version>
<version>2.8.1</version>
<executions>
<execution>
<goals>
<goal>docs</goal>
</goals>
<configuration>
<!-- the directory where to put the docs -->
<docsDir>${project.build.directory}/docs</docsDir>
<configFile>enunciate.xml</configFile>
</configuration>
</execution>
</executions>
......
......@@ -13,8 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.api.rest;
package nl.uva.sne.drip.api.v1.rest;
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
......@@ -67,6 +69,9 @@ public class CloudConfigurationController {
*/
@RequestMapping(method = RequestMethod.POST)
@RolesAllowed({UserService.USER, UserService.ADMIN})
@StatusCodes({
@ResponseCode(code = 400, condition = "Key or KeyIdAlias can't be empty")
})
public @ResponseBody
String postConf(@RequestBody CloudCredentials cloudCredentials) {
if (cloudCredentials.getKey() == null) {
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.api.rest;
package nl.uva.sne.drip.api.v1.rest;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.ObjectMapper;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.api.rest;
package nl.uva.sne.drip.api.v1.rest;
import java.io.IOException;
import java.util.ArrayList;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.api.rest;
package nl.uva.sne.drip.api.v1.rest;
import com.fasterxml.jackson.core.JsonParser;
import nl.uva.sne.drip.commons.types.ProvisionInfo;
......@@ -36,7 +36,6 @@ import nl.uva.sne.drip.api.dao.CloudCredentialsDao;
import nl.uva.sne.drip.commons.types.Message;
import nl.uva.sne.drip.commons.types.MessageParameter;
import nl.uva.sne.drip.commons.utils.Converter;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
......@@ -63,6 +62,7 @@ import nl.uva.sne.drip.commons.types.Plan;
import nl.uva.sne.drip.commons.types.UserScript;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.json.JSONException;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.api.rest;
package nl.uva.sne.drip.api.v1.rest;
import nl.uva.sne.drip.commons.types.ToscaRepresentation;
import java.io.IOException;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.api.rest;
package nl.uva.sne.drip.api.v1.rest;
import java.util.ArrayList;
import java.util.List;
......
......@@ -13,8 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.api.rest;
package nl.uva.sne.drip.api.v1.rest;
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
import nl.uva.sne.drip.commons.types.LoginKey;
import java.io.IOException;
import java.util.ArrayList;
......@@ -97,12 +99,15 @@ public class UserPublicKeysController {
*/
@RequestMapping(method = RequestMethod.POST)
@RolesAllowed({UserService.USER, UserService.ADMIN})
@StatusCodes({
@ResponseCode(code = 400, condition = "Key can't be empty")
})
public @ResponseBody
String postKey(@RequestBody LoginKey key) {
LoginKey.Type type = key.getType();
if (type != null && type.equals(LoginKey.Type.PRIVATE)) {
throw new BadRequestException("Key can't be private");
}
// if (type != null && type.equals(LoginKey.Type.PRIVATE)) {
// throw new BadRequestException("Key can't be private");
// }
if (key.getKey() == null) {
throw new BadRequestException("Key can't be empty");
}
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.api.rest;
package nl.uva.sne.drip.api.v1.rest;
import java.io.IOException;
import java.util.ArrayList;
......
......@@ -15,11 +15,14 @@
*/
package nl.uva.sne.drip.commons.types;
import com.webcohesion.enunciate.metadata.DocumentationExample;
import java.util.List;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* This class represents the cloud credentials for a cloud. They are used by the
* provisoner to request for resources.
*
* @author S. Koulouzis
*/
......@@ -28,27 +31,34 @@ public class CloudCredentials {
@Id
private String id;
private String key;
private String key;
private String keyIdAlias;
/**
* A list of login keys that can be used to log in to the deployed VMs. All
* new lines in the 'key' field have to be replaced with the '\n'
*/
private List<LoginKey> loginKeys;
private String cloudProviderName;
public final String getId() {
return id;
}
public final void setId(final String id) {
this.id = id;
}
/**
* The key for the cloud provider.
* @return the key
*/
@DocumentationExample("6J7uo99ifrff45126Gsy5vgb3bmrtwY6hBxtYt9y")
public String getKey() {
return key;
}
......@@ -61,8 +71,10 @@ public class CloudCredentials {
}
/**
* The key id for the cloud provider or the key alias.
* @return the keyIdAlias
*/
@DocumentationExample("AKIAITY3K5ZUQ6M7YBSQ")
public String getKeyIdAlias() {
return keyIdAlias;
}
......@@ -75,6 +87,7 @@ public class CloudCredentials {
}
/**
* The login keys
* @return the loginKeys
*/
public List<LoginKey> getLoginKeys() {
......@@ -89,8 +102,10 @@ public class CloudCredentials {
}
/**
* The name of the cloud provider
* @return the cloudProviderName
*/
@DocumentationExample("ec2")
public String getCloudProviderName() {
return cloudProviderName;
}
......
......@@ -15,10 +15,13 @@
*/
package nl.uva.sne.drip.commons.types;
import com.webcohesion.enunciate.metadata.DocumentationExample;
import org.springframework.data.annotation.Id;
/**
*
This class represents the cluster credentials for a cloud. They can used to
* login to the cluster created by the deployer
*
* @author S. Koulouzis
*/
public class ClusterCredentials {
......@@ -27,10 +30,7 @@ public class ClusterCredentials {
private String id;
private String contents;
/**
* @return the id
*/
public String getId() {
return id;
}
......@@ -43,8 +43,10 @@ public class ClusterCredentials {
}
/**
* The contents of the login key.
* @return the contents
*/
@DocumentationExample("BEGINRSAPRIVATEKEY-----\\nMIIEogIBAAKCAQEAm6AALYxkJFNzD3fVJ4+hMY5j0/kqM9CURLKXMlYuAysnvoG8wZKx9Bedefm\\neNSse4zTg798ZA2kDMZFIrwp1AseTwtj8DDu5fhG5DjyI3g6iJltS5zFQdMXneDlHXBX8cncSzNY\\nRx0NdjEMAe7YttvI8FNlxL0VnMFli/HB/ftzYMe5+AmkSROncVGHiwoiUpj+vtobCFOYtXsCf6ri\\nd4lgWA5wv6DZT/JKCYymiBqgSXu3ueFcEzw5SAukARWVjn1xccjZkokFfBbO/FpYY00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p4wjfHrzkTDVztKvmbWdvSXorDwKrZ7SC7tZpVFSfly\\nxuuLjadpUZT9YFmbAfY1X5oSccOMYqORjRbxEB3svb4BAoGAGTgFuq9Zojh/KIqY8b4HpEfmh6CQ\\nhLVfD98Nqd6GDbxgvIM0v4mFXE92x2jn35Ia0JdFyh3B8Vkl7sqQZfxDFXI9O9pte2mPJxY9ICaY\\n55+X/SN1pd53BH+gaPZJy/R+Vpvs5MN48howjUKy5UKpoFeUWrS5QArjtvNCm4SGlXw=\\n-----ENDRSAPRIVATEKEY-----\\n")
public String getContents() {
return contents;
}
......
......@@ -15,11 +15,15 @@
*/
package nl.uva.sne.drip.commons.types;
import com.webcohesion.enunciate.metadata.DocumentationExample;
import java.util.Map;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* This class represents a login key. This key can be used to either login to a
* VM created by the provisiner or by the VM to allow the user to login to the
* VMs from the machine the keys correspond to.
*
* @author S. Koulouzis
*/
......@@ -36,6 +40,12 @@ public class LoginKey {
private Type type;
private String name;
/**
* The name of the key.
*
* @return
*/
@DocumentationExample("id_dsa.pub")
public String getName() {
return this.name;
}
......@@ -64,8 +74,11 @@ public class LoginKey {
}
/**
* The type of key
*
* @return the type
*/
@DocumentationExample("PRIVATE")
public Type getType() {
return type;
}
......@@ -78,8 +91,12 @@ public class LoginKey {
}
/**
* A general use key,value. In the case of the cloud credentials it's used
* to specify the domain name for ec2
*
* @return the attributes
*/
@DocumentationExample("domain_name:Virginia")
public Map<String, String> getAttributes() {
return attributes;
}
......@@ -92,8 +109,11 @@ public class LoginKey {
}
/**
* The contents of the key.
*
* @return the key
*/
@DocumentationExample("-----BEGIN RSA PRIVATE KEY-----\\nMIIEogIBAAKCAQEAm6AALYxkJFNzD3bfVJ4+hMY5j0/kqM9CURLKXMlYuAysnvoG8wZKx9Bedefm\\neNSse4zTg798ZA2kDMZFIrwp1AseTwtj8DDu5fhG5DjyI3g6iJltS5zFQdMXneDlHXBX8cncSzN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JbufRmba8iQF1srN577mF+Z7ha4V\\nJ1duCTzvWF1KFX6sk/uhKQKBgAcDFai7rgNjJ8YcCRKxyFcMM9LKPl6hr4XFtWKzTAQPEABUkkuN\\n9gVClsg9f+VRKRECOIf0Ae1UWeCFEwxUXp4wjfHrzkTDVztKvmbWdvSXorDwKrZ7SC7tZpVFSfly\\nxuuLjadpUZT9YFmbAfY1X5oSccOMYqORjRbxEB3svb4BAoGAGTgFuq9Zojh/KIqY8b4HpEfmh6CQ\\nhLVfD98Nqd6GDbxgvIM0v4mFXE92x2jn35Ia0JdFyh3B8Vkl7sqQZfxDFXI9O9pte2mxY9ICaY\\n55+X/SN1pd53BH+gaPZJy/R+Vpvs5MN48hoUKy5UKpoFeUWrS5QArjtvNCm4SGlXw=\\n-----END RSA PRIVATE KEY-----\\n")
public String getKey() {
return key;
}
......
......@@ -22,6 +22,8 @@ import org.springframework.data.mongodb.core.mapping.Document;
/**
*
* This class represents a plan generated by the planner.
*
* @author S. Koulouzis
*/
@Document
......@@ -49,6 +51,7 @@ public class Plan {
}
/**
*
* @return the kvMap
*/
public Map<String, Object> getKvMap() {
......
......@@ -16,7 +16,6 @@
package nl.uva.sne.drip.commons.types;
import java.util.Map;
import java.util.Set;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
......
......@@ -18,6 +18,7 @@ package nl.uva.sne.drip.commons.types;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonProperty.Access;
import com.webcohesion.enunciate.metadata.DocumentationExample;
import java.util.Collection;
import java.util.HashSet;
import org.springframework.data.annotation.Id;
......@@ -28,6 +29,7 @@ import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
/**
* This class represents a user.
*
* @author S. Koulouzis
*/
......@@ -83,27 +85,57 @@ public class User implements UserDetails {
return this.password;
}
/**
* The username
*
* @return
*/
@Override
@DocumentationExample("user")
public String getUsername() {
return this.username;
}
/**
* If the account is not expired
*
* @return
*/
@Override
@DocumentationExample("true")
public boolean isAccountNonExpired() {
return this.accountNonExpired;
}
/**
* If the account is not locked
*
* @return
*/
@Override
@DocumentationExample("true")
public boolean isAccountNonLocked() {
return this.accountNonLocked;
}
/**
* If the credentials are not expired
*
* @return
*/
@Override
@DocumentationExample("true")
public boolean isCredentialsNonExpired() {
return this.credentialsNonExpired;
}
/**
* If the account is enabled
*
* @return
*/
@Override
@DocumentationExample("true")
public boolean isEnabled() {
return this.enabled;
}
......@@ -151,8 +183,11 @@ public class User implements UserDetails {
}
/**
* The roles assigned to this user.
*
* @return the roles
*/
@DocumentationExample("[\"ADMIN\",\"USER\"]")
public Collection<String> getRoles() {
return roles;
}
......
@ResponseBody/*
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* Licensed under the Apache License, Version 2.0 (the "License");
......@@ -15,10 +15,12 @@
*/
package nl.uva.sne.drip.commons.types;
import com.webcohesion.enunciate.metadata.DocumentationExample;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* This class represents a simple script that can run on a provisioned VM.
*
* @author S. Koulouzis
*/
......@@ -47,8 +49,11 @@ public class UserScript {
}
/**
* The name of the script
*
* @return the name
*/
@DocumentationExample("client.py")
public String getName() {
return name;
}
......@@ -61,8 +66,11 @@ public class UserScript {
}
/**
* The contents of the script
*
* @return the contents
*/
@DocumentationExample("config.sh")
public String getContents() {
return contents;
}
......@@ -70,6 +78,13 @@ public class UserScript {
/**
* @param contents the contents to set
*/
@DocumentationExample(" #!/bin/bash\n"
+ "echo \"Reading system-wide config....\" >&2\\n"
+ ". /etc/cool.cfg\n"
+ "if [ -r ~/.coolrc ]; then\n"
+ " echo \"Reading user config....\" >&2\\n"
+ " . ~/.coolrc\\n"
+ "fi")
public void setContents(String contents) {
this.contents = contents;
}
......
<?xml version="1.0" encoding="UTF-8"?>
<project-shared-configuration>
<!--
This file contains additional configuration written by modules in the NetBeans IDE.
The configuration is intended to be shared among all the users of project and
therefore it is assumed to be part of version control checkout.
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
-->
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
<!--
Properties that influence various parts of the IDE, especially code formatting and the like.
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
That way multiple projects can share the same settings (useful for formatting rules for example).
Any value defined here will override the pom.xml file value but is only applicable to the current project.
-->
<netbeans.hint.licensePath>${project.basedir}/../licenseheader.txt</netbeans.hint.licensePath>
</properties>
</project-shared-configuration>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>nl.uva.sne.drip</groupId>
<artifactId>drip</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>drip-commons</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.8.0</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.6</version>
</dependency>
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
<version>4.0.2</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.17</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>1.10.0.RELEASE</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>4.2.1.RELEASE</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>nl.uva.sne.drip</groupId>
<artifactId>drip-planner2provisioner</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
\ No newline at end of file
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.commons.types;
import org.springframework.data.mongodb.core.mapping.Document;
/**
*
* @author S. Koulouzis
*/
@Document
public class UserRole {
private Integer userRoleId;
private String role;
/**
* @return the userRoleId
*/
public Integer getUserRoleId() {
return userRoleId;
}
/**
* @param userRoleId the userRoleId to set
*/
public void setUserRoleId(Integer userRoleId) {
this.userRoleId = userRoleId;
}
/**
* @return the role
*/
public String getRole() {
return role;
}
/**
* @param role the role to set
*/
public void setRole(String role) {
this.role = role;
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.commons.types;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import nl.uva.sne.drip.commons.utils.FileHash;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/**
*
* @author alogo
*/
public class TypesJUnitTest {
private static File tempFile1;
private static String tempFile1Hash;
private static Message message1;
private static String fileParamContentsName;
private static File tempFile2;
private static String tempFile2Hash;
private static List<File> files;
@BeforeClass
public static void setUpClass() throws IOException, NoSuchAlgorithmException {
files = new ArrayList<>();
initTmpRandomFiles();
initMessages();
}
@AfterClass
public static void tearDownClass() {
if (tempFile1 != null) {
tempFile1.delete();
}
}
private static void initTmpRandomFiles() throws IOException, NoSuchAlgorithmException {
tempFile1 = File.createTempFile("temp-", Long.toString(System.nanoTime()));
try (PrintWriter writer = new PrintWriter(new BufferedWriter(
new OutputStreamWriter(new FileOutputStream(tempFile1), "UTF-8")), false)) {
Random random = new Random();
String sep = "";
for (int i = 0; i < 100; i++) {
int number = random.nextInt(1000) + 1;
writer.print(sep);
writer.print(number / 1e3);
sep = " ";
writer.println();
}
writer.println();
}
tempFile1Hash = FileHash.getSHA256(tempFile1.getAbsolutePath());
files.add(tempFile1);
tempFile2 = File.createTempFile("temp-", Long.toString(System.nanoTime()));
try (PrintWriter writer = new PrintWriter(new BufferedWriter(
new OutputStreamWriter(new FileOutputStream(tempFile2), "UTF-8")), false)) {
Random random = new Random();
String sep = "";
for (int i = 0; i < 100; i++) {
int number = random.nextInt(1000) + 1;
writer.print(sep);
writer.print(number / 1e3);
sep = " ";
writer.println();
}
writer.println();
}
tempFile2Hash = FileHash.getSHA256(tempFile2.getAbsolutePath());
files.add(tempFile2);
}
private static void initMessages() throws IOException {
message1 = new Message();
message1.setCreationDate((System.currentTimeMillis()));
List<MessageParameter> parameters = new ArrayList();
MessageParameter numParam = new MessageParameter();
String numParamName = "input";
numParam.setName(numParamName);
numParam.setValue("33000");
parameters.add(numParam);
MessageParameter fileParamContents = new MessageParameter();
fileParamContentsName = "someInputFile";
fileParamContents.setName(fileParamContentsName);
byte[] bytes = Files.readAllBytes(Paths.get(tempFile1.getAbsolutePath()));
String charset = "UTF-8";
fileParamContents.setValue(new String(bytes, charset));
fileParamContents.setEncoding(charset);
parameters.add(fileParamContents);
MessageParameter fileParamRef = new MessageParameter();
fileParamRef.setName("theNameOfTheParamater");
fileParamRef.setURL("http://www.gutenberg.org/cache/epub/3160/pg3160.txt");
parameters.add(fileParamRef);
message1.setParameters(parameters);
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
@Test
public void testMarshallUnmarshalJackson() throws IOException, NoSuchAlgorithmException {
File fileParam = null;
try {
ObjectMapper mapper = new ObjectMapper();
String jsonInString = mapper.writeValueAsString(message1);
// System.err.println(jsonInString);
assertTrue("JSON should contain " + IMessage.CREATION_DATE, jsonInString.contains(IMessage.CREATION_DATE));
assertTrue("JSON should contain parameters", jsonInString.contains("parameters"));
// System.err.println(jsonInString);
Message request = mapper.readValue(jsonInString, Message.class);
List<MessageParameter> params = request.getParameters();
assertEquals(message1.getParameters().size(), params.size());
fileParam = new File(fileParamContentsName);
for (MessageParameter param : params) {
if (param.getName().equals(fileParamContentsName)) {
String value = param.getValue();
try (PrintWriter out = new PrintWriter(fileParam)) {
out.print(value);
}
break;
}
}
assertNotNull(fileParam);
assertEquals(tempFile1.length(), fileParam.length());
String fileParamHash = FileHash.getSHA256(fileParam.getAbsolutePath());
assertEquals(tempFile1Hash, fileParamHash);
} finally {
if (fileParam != null) {
fileParam.delete();
}
}
}
@Test
public void testMarshallUnmarshalSimpleJson() throws IOException, NoSuchAlgorithmException, JSONException {
File fileParam = null;
try {
ObjectMapper mapper = new ObjectMapper();
String jsonInString = mapper.writeValueAsString(message1);
JSONObject jo = new JSONObject(jsonInString);
JSONArray parameters = jo.getJSONArray("parameters");
fileParam = new File(fileParamContentsName);
for (int i = 0; i < parameters.length(); i++) {
JSONObject param = (JSONObject) parameters.get(i);
String name = (String) param.get(MessageParameter.NAME);
if (name.equals(fileParamContentsName)) {
String value = (String) param.get(MessageParameter.VALUE);
try (PrintWriter out = new PrintWriter(fileParam)) {
out.print(value);
}
break;
}
}
assertNotNull(fileParam);
assertEquals(tempFile1.length(), fileParam.length());
String fileParamHash = FileHash.getSHA256(fileParam.getAbsolutePath());
assertEquals(tempFile1Hash, fileParamHash);
} finally {
if (fileParam != null) {
fileParam.delete();
}
}
}
@Test
public void testJacksonMarshal() throws UnsupportedEncodingException, IOException {
Message responseMessage = new Message();
List parameters = new ArrayList();
String charset = "UTF-8";
for (File f : files) {
MessageParameter fileParam = new MessageParameter();
byte[] bytes = Files.readAllBytes(Paths.get(f.getAbsolutePath()));
fileParam.setValue(new String(bytes, charset));
fileParam.setEncoding(charset);
fileParam.setName(f.getName());
parameters.add(fileParam);
}
responseMessage.setParameters(parameters);
responseMessage.setCreationDate((System.currentTimeMillis()));
ObjectMapper mapper = new ObjectMapper();
String jsonString = mapper.writeValueAsString(responseMessage);
}
@Test
public void testsimpleJsonMarshal() throws JSONException, IOException {
JSONObject jo = new JSONObject();
jo.put("creationDate", (System.currentTimeMillis()));
List parameters = new ArrayList();
String charset = "UTF-8";
for (File f : files) {
Map<String, String> fileArguments = new HashMap<>();
fileArguments.put("encoding", charset);
fileArguments.put("name", f.getName());
byte[] bytes = Files.readAllBytes(Paths.get(f.getAbsolutePath()));
fileArguments.put("value", new String(bytes, charset));
parameters.add(fileArguments);
}
jo.put("parameters", parameters);
ObjectMapper mapper = new ObjectMapper();
Message request = mapper.readValue(jo.toString(), Message.class);
Date cDate = new Date(request.getCreationDate());
}
}
......@@ -11,7 +11,6 @@
</properties>
<modules>
<module>drip-api</module>
<module>drip-commons</module>
<module>drip-simple_planner</module>
<module>drip-provisioner</module>
<module>drip-planner2provisioner</module>
......
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