aboutsummaryrefslogtreecommitdiffstats
path: root/common/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'common/src/test')
-rw-r--r--common/src/test/java/org/onap/so/client/HttpClientTest.java109
-rw-r--r--common/src/test/java/org/onap/so/security/UserDetailsServiceImplTest.java45
2 files changed, 154 insertions, 0 deletions
diff --git a/common/src/test/java/org/onap/so/client/HttpClientTest.java b/common/src/test/java/org/onap/so/client/HttpClientTest.java
index e9e8fe7853..3966d183f7 100644
--- a/common/src/test/java/org/onap/so/client/HttpClientTest.java
+++ b/common/src/test/java/org/onap/so/client/HttpClientTest.java
@@ -97,4 +97,113 @@ public class HttpClientTest {
postRequestedFor(urlEqualTo("/services/sdnc/post")).withHeader("Accept", equalTo("application/json")));
}
+ @Test
+ public void testPostUsingXmlClient_success() throws MalformedURLException {
+
+ wireMockRule.stubFor(post(urlEqualTo("/services/sdnc/post"))
+ .willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/xml").withBody("")));
+
+ URL url = new URL("http://localhost:" + wireMockRule.port() + "/services/sdnc/post");
+ HttpClient client = httpClientFactory.newXmlClient(url, ONAPComponents.BPMN);
+
+ client.addBasicAuthHeader(
+ "97FF88AB352DA16E00DDD81E3876431DEF8744465DACA489EB3B3BE1F10F63EDA1715E626D0A4827A3E19CD88421BF",
+ "123");
+ client.addAdditionalHeader("Accept", "application/xml");
+
+ client.post("{}");
+
+ verify(exactly(1), postRequestedFor(urlEqualTo("/services/sdnc/post")));
+ }
+
+ @Test
+ public void testPostUsingXmlClient_nullHeader() throws MalformedURLException {
+
+ wireMockRule.stubFor(post(urlEqualTo("/services/sdnc/post"))
+ .willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/xml").withBody("")));
+
+ URL url = new URL("http://localhost:" + wireMockRule.port() + "/services/sdnc/post");
+ HttpClient client = httpClientFactory.newXmlClient(url, ONAPComponents.BPMN);
+
+ client.accept = "application/xml";
+ client.addAdditionalHeader("id", null);
+
+ client.post("{}");
+
+ verify(exactly(1),
+ postRequestedFor(urlEqualTo("/services/sdnc/post")).withHeader("Accept", equalTo("application/xml")));
+ }
+
+ @Test
+ public void testPostUsingXmlClient_nullBasicAuth() throws MalformedURLException {
+
+ wireMockRule.stubFor(post(urlEqualTo("/services/sdnc/post"))
+ .willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/xml").withBody("")));
+
+ URL url = new URL("http://localhost:" + wireMockRule.port() + "/services/sdnc/post");
+ HttpClient client = httpClientFactory.newXmlClient(url, ONAPComponents.BPMN);
+
+ client.accept = "application/xml";
+ client.addBasicAuthHeader("", "12345");
+
+ client.post("{}");
+
+ verify(exactly(1),
+ postRequestedFor(urlEqualTo("/services/sdnc/post")).withHeader("Accept", equalTo("application/xml")));
+ }
+
+ @Test
+ public void testPostUsingTextXmlClient_success() throws MalformedURLException {
+
+ wireMockRule.stubFor(post(urlEqualTo("/services/sdnc/post"))
+ .willReturn(aResponse().withStatus(200).withHeader("Content-Type", "text/xml").withBody("")));
+
+ URL url = new URL("http://localhost:" + wireMockRule.port() + "/services/sdnc/post");
+ HttpClient client = httpClientFactory.newTextXmlClient(url, ONAPComponents.BPMN);
+
+ client.addBasicAuthHeader(
+ "97FF88AB352DA16E00DDD81E3876431DEF8744465DACA489EB3B3BE1F10F63EDA1715E626D0A4827A3E19CD88421BF",
+ "123");
+ client.addAdditionalHeader("Accept", "text/xml");
+
+ client.post("{}");
+
+ verify(exactly(1), postRequestedFor(urlEqualTo("/services/sdnc/post")));
+ }
+
+ @Test
+ public void testPostUsingTextXmlClient_nullHeader() throws MalformedURLException {
+
+ wireMockRule.stubFor(post(urlEqualTo("/services/sdnc/post"))
+ .willReturn(aResponse().withStatus(200).withHeader("Content-Type", "text/xml").withBody("")));
+
+ URL url = new URL("http://localhost:" + wireMockRule.port() + "/services/sdnc/post");
+ HttpClient client = httpClientFactory.newTextXmlClient(url, ONAPComponents.BPMN);
+
+ client.addAdditionalHeader("Accept", "text/xml");
+ client.addAdditionalHeader("id", null);
+
+ client.post("{}");
+
+ verify(exactly(1),
+ postRequestedFor(urlEqualTo("/services/sdnc/post")).withHeader("Accept", equalTo("text/xml")));
+ }
+
+ @Test
+ public void testPostUsingTextXmlClient_nullBasicAuth() throws MalformedURLException {
+
+ wireMockRule.stubFor(post(urlEqualTo("/services/sdnc/post"))
+ .willReturn(aResponse().withStatus(200).withHeader("Content-Type", "text/xml").withBody("")));
+
+ URL url = new URL("http://localhost:" + wireMockRule.port() + "/services/sdnc/post");
+ HttpClient client = httpClientFactory.newTextXmlClient(url, ONAPComponents.BPMN);
+
+ client.addBasicAuthHeader("", "12345");
+ client.addAdditionalHeader("Accept", "text/xml");
+
+ client.post("{}");
+
+ verify(exactly(1),
+ postRequestedFor(urlEqualTo("/services/sdnc/post")).withHeader("Accept", equalTo("text/xml")));
+ }
}
diff --git a/common/src/test/java/org/onap/so/security/UserDetailsServiceImplTest.java b/common/src/test/java/org/onap/so/security/UserDetailsServiceImplTest.java
new file mode 100644
index 0000000000..51de61a66a
--- /dev/null
+++ b/common/src/test/java/org/onap/so/security/UserDetailsServiceImplTest.java
@@ -0,0 +1,45 @@
+package org.onap.so.security;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import java.util.ArrayList;
+import org.junit.Test;
+import java.util.List;
+import org.springframework.security.core.userdetails.UserDetails;
+import org.springframework.security.core.userdetails.UsernameNotFoundException;
+
+public class UserDetailsServiceImplTest {
+
+ private static final String USERNAME = "usernameTest";
+ private static final String PASSWORD = "passTest";
+ private static final String ROLE = "roleTest";
+
+ @Test
+ public void loadUserByUsername_Success() {
+ UserDetailsServiceImpl testedObject = new UserDetailsServiceImpl();
+ testedObject.setUsercredentials(prepareUserCredentials());
+ UserDetails result = testedObject.loadUserByUsername(USERNAME);
+ assertThat(result.getUsername()).isEqualTo(USERNAME);
+ assertThat(result.getPassword()).isEqualTo(PASSWORD);
+ }
+
+ @Test
+ public void loadUserByUsername_userNotFoundEx() {
+ UserDetailsServiceImpl testedObject = new UserDetailsServiceImpl();
+ testedObject.setUsercredentials(prepareUserCredentials());
+ assertThatThrownBy(() -> testedObject.loadUserByUsername("notExistingUser"))
+ .isInstanceOf(UsernameNotFoundException.class);
+ }
+
+ private List<UserCredentials> prepareUserCredentials() {
+ UserCredentials userCredentials = new UserCredentials();
+ userCredentials.setUsername(USERNAME);
+ userCredentials.setPassword(PASSWORD);
+ userCredentials.setRole(ROLE);
+ List<UserCredentials> list = new ArrayList<>();
+ list.add(userCredentials);
+ return list;
+ }
+
+
+}