diff --git a/debian/DEBIAN/control b/debian/DEBIAN/control index 52077b6..0716448 100644 --- a/debian/DEBIAN/control +++ b/debian/DEBIAN/control @@ -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. diff --git a/pom.xml b/pom.xml index b577369..2ff083b 100644 --- a/pom.xml +++ b/pom.xml @@ -40,19 +40,19 @@ google_checks.xml - - - - true - always - fail - - SCC-KIT - SCC - http://cdmi-qos.data.kit.edu/maven/ - default - - + + + + true + always + fail + + SCC-KIT + SCC + http://cdmi-qos.data.kit.edu/maven/ + default + + org.springframework.boot @@ -91,6 +91,8 @@ edu.kit.scc.cdmi.filesystem.FileSystemTestSuite.java edu.kit.scc.cdmi.rest.RestTestSuite.java + edu.kit.scc.TestSuite.java + edu.kit.scc.http.client.HttpTestSuite.java diff --git a/src/main/java/edu/kit/scc/FilesystemConfiguration.java b/src/main/java/edu/kit/scc/FilesystemConfiguration.java index 66e7de2..5ccfbea 100644 --- a/src/main/java/edu/kit/scc/FilesystemConfiguration.java +++ b/src/main/java/edu/kit/scc/FilesystemConfiguration.java @@ -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. // @@ -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( @@ -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( diff --git a/src/test/java/edu/kit/scc/TestSuite.java b/src/test/java/edu/kit/scc/TestSuite.java new file mode 100644 index 0000000..e39c049 --- /dev/null +++ b/src/test/java/edu/kit/scc/TestSuite.java @@ -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 { + +} diff --git a/src/test/java/edu/kit/scc/UtilsTest.java b/src/test/java/edu/kit/scc/UtilsTest.java new file mode 100644 index 0000000..c1b9aba --- /dev/null +++ b/src/test/java/edu/kit/scc/UtilsTest.java @@ -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")); + } +} diff --git a/src/test/java/edu/kit/scc/http/client/HttpClientTest.java b/src/test/java/edu/kit/scc/http/client/HttpClientTest.java new file mode 100644 index 0000000..6ee9a20 --- /dev/null +++ b/src/test/java/edu/kit/scc/http/client/HttpClientTest.java @@ -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); + } +} diff --git a/src/test/java/edu/kit/scc/http/client/HttpTestSuite.java b/src/test/java/edu/kit/scc/http/client/HttpTestSuite.java new file mode 100644 index 0000000..0909326 --- /dev/null +++ b/src/test/java/edu/kit/scc/http/client/HttpTestSuite.java @@ -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 { + +}