-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from indigo-dc/spring-boot
test coverage + fix
- Loading branch information
Showing
7 changed files
with
276 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
148
src/test/java/edu/kit/scc/http/client/HttpClientTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
||
} |