Commit c20d5eb2 authored by Spiros Koulouzis's avatar Spiros Koulouzis

Added test module with jar generated from documentation

parent 661d57f7
......@@ -31,7 +31,13 @@
<scope>test</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
<scope>test</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
......
access.key.id=lferpoiewp
secret.key=erfiru
cloud.provider.name=ec2
cloud.private.key.paths=/home/alogo/Virginia.pem,/home/alogo/California.pem
\ No newline at end of file
......@@ -15,27 +15,54 @@
*/
package nl.uva.sne.drip.test.manager;
import javax.net.ssl.SSLContext;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
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.*;
/**
*
* @author alogo
* @author S. Koulouzis
*/
public class DRIPTest {
private static List<String> PROPERTIES_FILE_PATHS;
public static List<Properties> propertiesList = new ArrayList<>();
public static final String ACCESS_KEY_ID_PROPPERTY_NAME = "access.key.id";
static String CLOUD_PROPVIDER_PROPPERTY_NAME = "cloud.provider.name";
static String SECRET_KEY_PROPERTY_NAME = "secret.key";
static String CLOUD_PRIVATE_KEY_PATHS_PROPERTY_NAME = "cloud.private.key.paths";
public DRIPTest() {
PROPERTIES_FILE_PATHS = new ArrayList<>();
}
@BeforeClass
public static void setUpClass() {
for (String propFile : PROPERTIES_FILE_PATHS) {
try (Reader inStream = new FileReader(new File(propFile))) {
Properties prop = new Properties();
prop.load(inStream);
propertiesList.add(prop);
} catch (FileNotFoundException ex) {
Logger.getLogger(TestCloudCredentialsController.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(TestCloudCredentialsController.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
@AfterClass
......@@ -76,7 +103,7 @@ public class DRIPTest {
// LOGGER.warn("Null SSL context, skipping client SSL configuration", npe);
// }
// return builder.build();
return null;
return null;
}
}
......@@ -15,6 +15,16 @@
*/
package nl.uva.sne.drip.test.manager;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.junit.After;
import org.junit.AfterClass;
import static org.junit.Assert.assertEquals;
......@@ -25,13 +35,21 @@ import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.core.Response;
import nl.uva.sne.drip.data.v1.external.CloudCredentials;
import nl.uva.sne.drip.data.v1.external.Key;
import nl.uva.sne.drip.data.v1.external.KeyPair;
import nl.uva.sne.drip.data.v1.external.KeyType;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
/**
*
* @author S. Koulouzis.
*/
public class TestCloudCredentialsController {
public class TestCloudCredentialsController extends DRIPTest {
@BeforeClass
public static void setUpClass() {
......@@ -41,23 +59,36 @@ public class TestCloudCredentialsController {
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
@Test
public void hello() {
System.err.println("");
CloudCredentials cc = new CloudCredentials();
cc.setAccessKeyId("");
public void testPOST_GETCloudCredentials() {
for (Properties p : DRIPTest.propertiesList) {
String[] paths = DRIPTest.CLOUD_PRIVATE_KEY_PATHS_PROPERTY_NAME.split(",");
for (String cloudPrivateKeyPath : paths) {
try {
KeyPair keyPair = new KeyPair();
Key privateKey = new Key();
privateKey.setName(FileUtils.readFileToString(new File(cloudPrivateKeyPath), "UTF-8"));
privateKey.setKey(FilenameUtils.getBaseName(cloudPrivateKeyPath));
privateKey.setType(KeyType.PRIVATE);
Map<String, String> map = new HashMap<>();
map.put(cloudPrivateKeyPath, cloudPrivateKeyPath);
privateKey.setAttributes(map);
keyPair.setPrivateKey(privateKey);
} catch (IOException ex) {
Logger.getLogger(TestCloudCredentialsController.class.getName()).log(Level.SEVERE, null, ex);
}
}
CloudCredentials cc = new CloudCredentials();
cc.setAccessKeyId(p.getProperty(ACCESS_KEY_ID_PROPPERTY_NAME));
cc.setCloudProviderName(p.getProperty(CLOUD_PROPVIDER_PROPPERTY_NAME));
cc.setSecretKey(p.getProperty(DRIPTest.SECRET_KEY_PROPERTY_NAME));
cc.setKeyPairIDs(keyPairIDs);
}
}
private void post(String lcmId, String metadataId, String storageId, int expected) {
private void post(int expected) {
// String payload = "{\"local-storage-id\" : \"" + storageId + "\"}";
// Entity<String> entity = Entity.entity(payload, "application/json");
// Response resp = getWebTarget().path(TRIGGER_PATH).path(lcmId).path("metadata").path(metadataId)
......
/*
* 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.test.manager;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import nl.uva.sne.drip.data.v1.external.Key;
import nl.uva.sne.drip.data.v1.external.KeyPair;
import nl.uva.sne.drip.data.v1.external.KeyType;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
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.*;
/**
*
* @author alogo
*/
public class TestKeysController extends DRIPTest {
public TestKeysController() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
// TODO add test methods here.
// The methods must be annotated with annotation @Test. For example:
//
@Test
public void test_POST_GETCoudKeys() {
String[] paths = DRIPTest.CLOUD_PRIVATE_KEY_PATHS_PROPERTY_NAME.split(",");
for (String cloudPrivateKeyPath : paths) {
try {
KeyPair keyPair = new KeyPair();
Key privateKey = createPrivateCloudKey(cloudPrivateKeyPath);
keyPair.setPrivateKey(privateKey);
post(keyPair, 200);
} catch (IOException ex) {
Logger.getLogger(TestCloudCredentialsController.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
private void post(KeyPair keyPair, int expected) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
private Key createPrivateCloudKey(String cloudPrivateKeyPath) throws IOException {
Key privateKey = new Key();
privateKey.setName(FileUtils.readFileToString(new File(cloudPrivateKeyPath), "UTF-8"));
privateKey.setKey(FilenameUtils.getBaseName(cloudPrivateKeyPath));
privateKey.setType(KeyType.PRIVATE);
Map<String, String> map = new HashMap<>();
map.put("attribute", "value");
privateKey.setAttributes(map);
return privateKey;
}
}
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