diff options
Diffstat (limited to 'common/src')
5 files changed, 161 insertions, 3 deletions
diff --git a/common/src/main/java/org/onap/so/beans/nsmf/ServiceInfo.java b/common/src/main/java/org/onap/so/beans/nsmf/ServiceInfo.java index 5146685058..df137d0c01 100644 --- a/common/src/main/java/org/onap/so/beans/nsmf/ServiceInfo.java +++ b/common/src/main/java/org/onap/so/beans/nsmf/ServiceInfo.java @@ -56,4 +56,7 @@ public class ServiceInfo implements Serializable { private String pLMNIdList; private String actionType; + + private String resourceSharingLevel; + } diff --git a/common/src/main/java/org/onap/so/beans/nsmf/SliceProfileAdapter.java b/common/src/main/java/org/onap/so/beans/nsmf/SliceProfileAdapter.java index 7cc940ddde..2b315611ad 100644 --- a/common/src/main/java/org/onap/so/beans/nsmf/SliceProfileAdapter.java +++ b/common/src/main/java/org/onap/so/beans/nsmf/SliceProfileAdapter.java @@ -176,6 +176,7 @@ public class SliceProfileAdapter implements Serializable { BeanUtils.copyProperties(this, tnSliceProfile); tnSliceProfile.setSNSSAIList(Arrays.asList(this.sNSSAIList.split("\\|"))); tnSliceProfile.setPLMNIdList(Arrays.asList(this.pLMNIdList.split("\\|"))); + tnSliceProfile.setResourceSharingLevel(ResourceSharingLevel.fromString(this.resourceSharingLevel)); return tnSliceProfile; } } diff --git a/common/src/main/java/org/onap/so/serviceinstancebeans/Service.java b/common/src/main/java/org/onap/so/serviceinstancebeans/Service.java index 14b1ab5974..90df220b52 100644 --- a/common/src/main/java/org/onap/so/serviceinstancebeans/Service.java +++ b/common/src/main/java/org/onap/so/serviceinstancebeans/Service.java @@ -42,7 +42,7 @@ public class Service implements Serializable { @JsonProperty("instanceName") protected String instanceName; @JsonProperty("instanceParams") - private List<Map<String, String>> instanceParams = new ArrayList<>(); + private List<Map<String, Object>> instanceParams = new ArrayList<>(); @JsonProperty("resources") protected Resources resources; @JsonProperty("processingPriority") @@ -73,11 +73,11 @@ public class Service implements Serializable { this.instanceName = instanceName; } - public List<Map<String, String>> getInstanceParams() { + public List<Map<String, Object>> getInstanceParams() { return instanceParams; } - public void setInstanceParams(List<Map<String, String>> instanceParams) { + public void setInstanceParams(List<Map<String, Object>> instanceParams) { this.instanceParams = instanceParams; } 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; + } + + +} |