Skip to content

Commit

Permalink
Merge pull request #30 from indigo-dc/spring-boot
Browse files Browse the repository at this point in the history
test coverage + fix
  • Loading branch information
bertl4398 authored Jun 24, 2016
2 parents e2cbe12 + a81a8cc commit cfddd4e
Show file tree
Hide file tree
Showing 7 changed files with 276 additions and 45 deletions.
2 changes: 1 addition & 1 deletion debian/DEBIAN/control
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Section: web
Priority: optional
Architecture: all
Maintainer: INDIGO DataCloud
Depends: default-jre | java8-runtime
Depends: java8-runtime
Description: SNIA CDMI server reference implementation.
.
Standalone Spring Boot application version.
Expand Down
28 changes: 15 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@
<checkstyle.config.location>google_checks.xml</checkstyle.config.location>
</properties>

<repositories>
<repository>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</releases>
<id>SCC-KIT</id>
<name>SCC</name>
<url>http://cdmi-qos.data.kit.edu/maven/</url>
<layout>default</layout>
</repository>
</repositories>
<repositories>
<repository>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</releases>
<id>SCC-KIT</id>
<name>SCC</name>
<url>http://cdmi-qos.data.kit.edu/maven/</url>
<layout>default</layout>
</repository>
</repositories>

<parent>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -91,6 +91,8 @@
<includes>
<include>edu.kit.scc.cdmi.filesystem.FileSystemTestSuite.java</include>
<include>edu.kit.scc.cdmi.rest.RestTestSuite.java</include>
<include>edu.kit.scc.TestSuite.java</include>
<include>edu.kit.scc.http.client.HttpTestSuite.java</include>
</includes>
</configuration>
</plugin>
Expand Down
59 changes: 28 additions & 31 deletions src/main/java/edu/kit/scc/FilesystemConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,55 +69,52 @@ public void init() throws IOException {
if (!Files.exists(path)) {
Files.createDirectories(Paths.get(baseDirectory, "cdmi_objectid"));
log.debug("root directory {} created", path.toString());

Container rootContainer = new Container("/", "/", rootObject.getObjectId());
rootContainer.setObjectId(rootObject.getObjectId());

cdmiObjectDao.createCdmiObject(rootContainer, baseDirectory);
}
Container rootContainer = new Container("/", "/", rootObject.getObjectId());
rootContainer.setObjectId(rootObject.getObjectId());

cdmiObjectDao.createCdmiObject(rootContainer, baseDirectory);

path = Paths.get(baseDirectory, "cdmi_capabilities");
if (!Files.exists(path)) {
Files.createDirectory(Paths.get(baseDirectory, "cdmi_capabilities"));
log.debug("capabilities directory {} created", path.toString());
}

rootObject = cdmiObjectDao.getCdmiObjectByPath(baseDirectory);
rootObject = cdmiObjectDao.getCdmiObjectByPath(baseDirectory);

Capability rootCapability =
new Capability("cdmi_capabilities", "/", rootObject.getObjectId());
cdmiObjectDao.createCdmiObject(rootCapability,
Paths.get(baseDirectory, "cdmi_capabilities").toString());
Capability rootCapability = new Capability("cdmi_capabilities", "/", rootObject.getObjectId());
cdmiObjectDao.createCdmiObject(rootCapability,
Paths.get(baseDirectory, "cdmi_capabilities").toString());

Capability containerCapability =
new Capability("container", "/cdmi_capabilities", rootCapability.getObjectId());
capabilityDao.createByPath(Paths.get("cdmi_capabilities", "container").toString(),
containerCapability);
Capability containerCapability =
new Capability("container", "/cdmi_capabilities", rootCapability.getObjectId());
capabilityDao.createByPath(Paths.get("cdmi_capabilities", "container").toString(),
containerCapability);

Capability dataObjectCapability =
new Capability("dataobject", "/cdmi_capabilities", rootCapability.getObjectId());
capabilityDao.createByPath(Paths.get("cdmi_capabilities", "dataobject").toString(),
dataObjectCapability);
}
Capability dataObjectCapability =
new Capability("dataobject", "/cdmi_capabilities", rootCapability.getObjectId());
capabilityDao.createByPath(Paths.get("cdmi_capabilities", "dataobject").toString(),
dataObjectCapability);

path = Paths.get(baseDirectory, "cdmi_domains");
if (!Files.exists(path)) {
Files.createDirectory(path);
log.debug("domain directory {} created", path.toString());
}
rootObject = cdmiObjectDao.getCdmiObjectByPath(baseDirectory);

rootObject = cdmiObjectDao.getCdmiObjectByPath(baseDirectory);

Domain rootDomain = new Domain("cdmi_domains", "/", rootObject.getObjectId());
Domain rootDomain = new Domain("cdmi_domains", "/", rootObject.getObjectId());

cdmiObjectDao.createCdmiObject(rootDomain,
Paths.get(baseDirectory, "cdmi_domains").toString());
}
cdmiObjectDao.createCdmiObject(rootDomain, Paths.get(baseDirectory, "cdmi_domains").toString());

Capability containerCapability =
Capability defaultContainerCapability =
capabilityDao.findByPath(Paths.get("cdmi_capabilities", "container").toString());
log.debug(containerCapability.toString());
log.debug(defaultContainerCapability.toString());

Capability dataObjectCapability =
Capability defaultDataObjectCapability =
capabilityDao.findByPath(Paths.get("cdmi_capabilities", "dataobject").toString());
log.debug(dataObjectCapability.toString());
log.debug(defaultDataObjectCapability.toString());

// Connect to a specific file system storage back-end implementation.
//
Expand All @@ -132,7 +129,7 @@ public void init() throws IOException {

if (capability.getType().equals(CapabilityType.CONTAINER)) {
Capability providedCapability = new Capability(capability.getName(),
"/cdmi_capabilities/container", containerCapability.getObjectId());
"/cdmi_capabilities/container", defaultContainerCapability.getObjectId());
providedCapability.setCapabilities(new JSONObject(capability.getCapabilities()));
providedCapability.setMetadata(new JSONObject(capability.getMetadata()));
capabilityDao.createByPath(
Expand All @@ -141,7 +138,7 @@ public void init() throws IOException {
}
if (capability.getType().equals(CapabilityType.DATAOBJECT)) {
Capability providedCapability = new Capability(capability.getName(),
"/cdmi_capabilities/dataobject", dataObjectCapability.getObjectId());
"/cdmi_capabilities/dataobject", defaultContainerCapability.getObjectId());
providedCapability.setCapabilities(new JSONObject(capability.getCapabilities()));
providedCapability.setMetadata(new JSONObject(capability.getMetadata()));
capabilityDao.createByPath(
Expand Down
19 changes: 19 additions & 0 deletions src/test/java/edu/kit/scc/TestSuite.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2016 Karlsruhe Institute of Technology (KIT)
*
* 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
*/

package edu.kit.scc;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;

@RunWith(Suite.class)
@Suite.SuiteClasses({UtilsTest.class})
public class TestSuite {

}
46 changes: 46 additions & 0 deletions src/test/java/edu/kit/scc/UtilsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2016 Karlsruhe Institute of Technology (KIT)
*
* 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
*/

package edu.kit.scc;

import static org.junit.Assert.assertTrue;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = CdmiServerApplication.class)
public class UtilsTest {

@Test
public void testCrc16() {
byte[] bytes1 = {0};

int checksum1 = Utils.crc16(bytes1);

assertTrue(checksum1 == 0);

byte[] bytes2 = {127};

int checksum2 = Utils.crc16(bytes2);

assertTrue(checksum2 == 57409);
}

@Test
public void testBytesToHex() {
byte[] bytes = {0};

String str = Utils.bytesToHex(bytes);

assertTrue(str.equals("00"));
}
}
148 changes: 148 additions & 0 deletions src/test/java/edu/kit/scc/http/client/HttpClientTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/*
* Copyright 2016 Karlsruhe Institute of Technology (KIT)
*
* 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
*/

package edu.kit.scc.http.client;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import edu.kit.scc.CdmiServerApplication;
import edu.kit.scc.http.HttpClient;
import edu.kit.scc.http.HttpResponse;

import org.apache.commons.codec.binary.Base64;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.nio.charset.StandardCharsets;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = CdmiServerApplication.class)
public class HttpClientTest {

@Autowired
HttpClient client;

@Test
public void testMakeHttpGetRequestWrongUrl() {
String url = "invalid";

HttpResponse response = client.makeHttpGetRequest(url);

assertNull(response);
}

@Test
public void testMakeHttpGetRequest() {
String url = "http://www.kit.edu";

HttpResponse response = client.makeHttpGetRequest(url);

assertNotNull(response);
assertTrue(response.getStatusCode() == 200);
}

@Test
public void testMakeHttpGetRequestWithAuthorization() {
String url = "http://www.kit.edu";
String restUser = "test";
String restPassword = "test";
String auth = restUser + ":" + restPassword;
byte[] authZheader = auth.getBytes();
String authorizationHeader =
"Basic " + new String(Base64.encodeBase64(authZheader), StandardCharsets.UTF_8);

HttpResponse response = client.makeHttpGetRequest(restUser, restPassword, url);

assertNotNull(response);
assertTrue(response.getStatusCode() == 200);
}

@Test
public void testMakeHttpsGetRequest() {
String url = "https://api.duckduckgo.com/?q=KIT&format=json&pretty=1";

HttpResponse response = client.makeHttpsGetRequest(url);

// assertNotNull(response);
// assertTrue(response.getStatusCode() == 200);
}

@Test
public void testMakeHttpsGetRequestWithAuthorization() {
String url = "https://api.duckduckgo.com/?q=KIT&format=json&pretty=1";
String restUser = "test";
String restPassword = "test";
String auth = restUser + ":" + restPassword;
byte[] authZheader = auth.getBytes();
String authorizationHeader =
"Basic " + new String(Base64.encodeBase64(authZheader), StandardCharsets.UTF_8);

HttpResponse response = client.makeHttpsGetRequest(restUser, restPassword, url);

// assertNotNull(response);
// assertTrue(response.getStatusCode() == 200);
}

@Test
public void testMakeHttpPostRequest() {
String url = "http://www.kit.edu";

HttpResponse response = client.makeHttpPostRequest(null, url);

assertNotNull(response);
// assertTrue(response.getStatusCode() == 200);
}

@Test
public void testMakeHttpPostRequestWithAuthorization() {
String url = "http://www.kit.edu";
String restUser = "test";
String restPassword = "test";
String auth = restUser + ":" + restPassword;
byte[] authZheader = auth.getBytes();
String authorizationHeader =
"Basic " + new String(Base64.encodeBase64(authZheader), StandardCharsets.UTF_8);

HttpResponse response = client.makeHttpPostRequest(restUser, restPassword, null, url);

assertNotNull(response);
assertTrue(response.getStatusCode() == 200);
}

@Test
public void testMakeHttpsPostRequest() {
String url = "https://api.duckduckgo.com/?q=KIT&format=json&pretty=1";

HttpResponse response = client.makeHttpPostRequest(null, url);

// assertNotNull(response);
// assertTrue(response.getStatusCode() == 200);
}

@Test
public void testMakeHttpsPostRequestWithAuthorization() {
String url = "https://api.duckduckgo.com/?q=KIT&format=json&pretty=1";
String restUser = "test";
String restPassword = "test";
String auth = restUser + ":" + restPassword;
byte[] authZheader = auth.getBytes();
String authorizationHeader =
"Basic " + new String(Base64.encodeBase64(authZheader), StandardCharsets.UTF_8);

HttpResponse response = client.makeHttpsPostRequest(restUser, restPassword, null, url);

// assertNotNull(response);
// assertTrue(response.getStatusCode() == 200);
}
}
19 changes: 19 additions & 0 deletions src/test/java/edu/kit/scc/http/client/HttpTestSuite.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2016 Karlsruhe Institute of Technology (KIT)
*
* 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
*/

package edu.kit.scc.http.client;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;

@RunWith(Suite.class)
@Suite.SuiteClasses({HttpClientTest.class})
public class HttpTestSuite {

}

0 comments on commit cfddd4e

Please sign in to comment.