diff options
7 files changed, 156 insertions, 20 deletions
diff --git a/bpmn/MSOCommonBPMN/pom.xml b/bpmn/MSOCommonBPMN/pom.xml index 317413556c..1d255c4eb4 100644 --- a/bpmn/MSOCommonBPMN/pom.xml +++ b/bpmn/MSOCommonBPMN/pom.xml @@ -416,12 +416,12 @@ <dependency> <groupId>org.onap.appc.client</groupId> <artifactId>client-lib</artifactId> - <version>1.3.0-SNAPSHOT</version> + <version>1.3.0</version> </dependency> <dependency> <groupId>org.onap.appc.client</groupId> <artifactId>client-kit</artifactId> - <version>1.3.0-SNAPSHOT</version> + <version>1.3.0</version> </dependency> <dependency> <groupId>org.aspectj</groupId> diff --git a/common/pom.xml b/common/pom.xml index aa3b09597a..86b9f36e50 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -123,12 +123,12 @@ <dependency> <groupId>org.onap.appc.client</groupId> <artifactId>client-kit</artifactId> - <version>1.3.0-SNAPSHOT</version> + <version>1.3.0</version> </dependency> <dependency> <groupId>org.onap.appc.client</groupId> <artifactId>client-lib</artifactId> - <version>1.3.0-SNAPSHOT</version> + <version>1.3.0</version> </dependency> <dependency> <groupId>org.springframework</groupId> diff --git a/mso-api-handlers/mso-api-handler-common/pom.xml b/mso-api-handlers/mso-api-handler-common/pom.xml index 5b15c5f0d4..6ca1f3de28 100644 --- a/mso-api-handlers/mso-api-handler-common/pom.xml +++ b/mso-api-handlers/mso-api-handler-common/pom.xml @@ -50,6 +50,12 @@ <artifactId>mso-requests-db</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <version>3.10.0</version> + <scope>test</scope> + </dependency> </dependencies> <build> diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/openecomp/mso/apihandler/common/CamundaTaskClient.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/openecomp/mso/apihandler/common/CamundaTaskClient.java index 845b140348..cbbbff3dff 100644 --- a/mso-api-handlers/mso-api-handler-common/src/main/java/org/openecomp/mso/apihandler/common/CamundaTaskClient.java +++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/openecomp/mso/apihandler/common/CamundaTaskClient.java @@ -64,19 +64,18 @@ public class CamundaTaskClient extends RequestClient{ @Override
public HttpResponse post(String camundaReqXML, String requestId,
String requestTimeout, String schemaVersion, String serviceInstanceId, String action) {
- msoLogger.debug("Method not supported");
- return null;
+ throw new UnsupportedOperationException("Method not supported.");
}
@Override
public HttpResponse post(RequestClientParamater params) {
- return null;
+ throw new UnsupportedOperationException("Method not supported.");
}
@Override
- public HttpResponse get() throws IOException{
+ public HttpResponse get() throws IOException {
HttpGet get = new HttpGet(url);
- msoLogger.debug("Camunda Task url is: "+ url);
+ msoLogger.debug("Camunda Task url is: "+ url);
String encryptedCredentials;
if(props!=null){
encryptedCredentials = props.getProperty(CommonConstants.CAMUNDA_AUTH,null);
diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/openecomp/mso/apihandler/common/RequestClient.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/openecomp/mso/apihandler/common/RequestClient.java index ed5d076d8c..66369a8b69 100644 --- a/mso-api-handlers/mso-api-handler-common/src/main/java/org/openecomp/mso/apihandler/common/RequestClient.java +++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/openecomp/mso/apihandler/common/RequestClient.java @@ -24,7 +24,6 @@ import java.io.IOException; import java.security.GeneralSecurityException; import org.apache.http.HttpResponse; -import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.openecomp.mso.logger.MsoLogger; import org.openecomp.mso.properties.MsoJavaProperties; @@ -65,7 +64,7 @@ public abstract class RequestClient { this.client = client; } - public abstract HttpResponse post(String request, String requestId, String requestTimeout, String schemaVersion, String serviceInstanceId, String action) throws ClientProtocolException, IOException; + public abstract HttpResponse post(String request, String requestId, String requestTimeout, String schemaVersion, String serviceInstanceId, String action) throws IOException; public abstract HttpResponse post(String request) throws IOException; diff --git a/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/apihandler/common/CamundaTaskClientTest.java b/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/apihandler/common/CamundaTaskClientTest.java new file mode 100644 index 0000000000..f892d13599 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/apihandler/common/CamundaTaskClientTest.java @@ -0,0 +1,132 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.apihandler.common; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import org.apache.http.HttpEntity; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpRequestBase; +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.openecomp.mso.properties.MsoJavaProperties; + +public class CamundaTaskClientTest { + + private CamundaTaskClient testedObject = new CamundaTaskClient(); + private HttpClient httpClientMock; + private static final String JSON_REQUEST = "{\"value1\": \"aaa\",\"value2\": \"bbb\"}"; + private static final String URL_SCHEMA = "http"; + private static final String HOST = "testhost"; + private static final int PORT = 1234; + private static final String URL_PATH = "/requestMethodSuccessful"; + private static final String URL = URL_SCHEMA + "://" + HOST + ":" + PORT + URL_PATH; + private static final String AUTHORIZATION_HEADER_NAME = "Authorization"; + + @Before + public void init() { + testedObject = new CamundaTaskClient(); + httpClientMock = mock(HttpClient.class); + testedObject.setClient(httpClientMock); + testedObject.setUrl(URL); + } + + @Test + public void postMethodSuccessful() throws IOException { + ArgumentCaptor<HttpPost> httpPostCaptor = ArgumentCaptor.forClass(HttpPost.class); + testedObject.post(JSON_REQUEST); + verify(httpClientMock).execute(httpPostCaptor.capture()); + checkUri(httpPostCaptor.getValue()); + assertThat(httpPostCaptor.getValue().getEntity().getContentType().getValue()). + isEqualTo(CommonConstants.CONTENT_TYPE_JSON); + assertThat(getJsonFromEntity(httpPostCaptor.getValue().getEntity())).isEqualTo(JSON_REQUEST); + } + + @Test + public void postMethodSuccessfulWithCredentials() throws IOException { + ArgumentCaptor<HttpPost> httpPostCaptor = ArgumentCaptor.forClass(HttpPost.class); + testedObject.setProps(createMsoJavaProperties()); + testedObject.post(JSON_REQUEST); + verify(httpClientMock).execute(httpPostCaptor.capture()); + assertThat(httpPostCaptor.getValue().getHeaders(AUTHORIZATION_HEADER_NAME)).isNotEmpty(); + } + + @Test + public void getMethodSuccessful() throws IOException { + ArgumentCaptor<HttpGet> httpGetCaptor = ArgumentCaptor.forClass(HttpGet.class); + testedObject.get(); + verify(httpClientMock).execute(httpGetCaptor.capture()); + checkUri(httpGetCaptor.getValue()); + } + + @Test + public void getMethodSuccessfulWithCredentials() throws IOException { + ArgumentCaptor<HttpGet> httpGetCaptor = ArgumentCaptor.forClass(HttpGet.class); + testedObject.setUrl(URL); + testedObject.setProps(createMsoJavaProperties()); + testedObject.get(); + verify(httpClientMock).execute(httpGetCaptor.capture()); + assertThat(httpGetCaptor.getValue().getHeaders(AUTHORIZATION_HEADER_NAME)).isNotEmpty(); + } + + @Test(expected = UnsupportedOperationException.class) + public void postMethodUnsupported() { + testedObject.post("", "", "", "", "", ""); + } + + @Test(expected = UnsupportedOperationException.class) + public void postMethodUnsupported2() { + testedObject.post(new RequestClientParamater.Builder().build()); + } + + private void checkUri(HttpRequestBase httpRequestBase) { + assertThat(httpRequestBase.getURI().getScheme()).isEqualTo(URL_SCHEMA); + assertThat(httpRequestBase.getURI().getHost()).isEqualTo(HOST); + assertThat(httpRequestBase.getURI().getPort()).isEqualTo(PORT); + assertThat(httpRequestBase.getURI().getPath()).isEqualTo(URL_PATH); + } + + private MsoJavaProperties createMsoJavaProperties() { + MsoJavaProperties msoJavaProperties = new MsoJavaProperties(); + msoJavaProperties.setProperty(CommonConstants.CAMUNDA_AUTH, ""); + return msoJavaProperties; + } + + private String getJsonFromEntity(HttpEntity httpEntity) throws IOException { + BufferedReader rd = new BufferedReader( + new InputStreamReader(httpEntity.getContent())); + StringBuilder result = new StringBuilder(); + String line; + while ((line = rd.readLine()) != null) { + result.append(line); + } + return result.toString(); + } + +}
\ No newline at end of file diff --git a/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java b/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java index 1ef1313158..af0ea101f4 100644 --- a/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java +++ b/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java @@ -234,8 +234,8 @@ public class CatalogDatabase implements Closeable { String hql = "FROM HeatTemplate WHERE templateName = :template_name AND version = :version"; Query query = getSession().createQuery(hql); - query.setParameter(TEMPLATE_NAME,templateName); - query.setParameter("version", version); + query.setParameter(TEMPLATE_NAME, templateName); + query.setParameter(MODEL_VERSION, version); @SuppressWarnings("unchecked") List <HeatTemplate> resultList = query.list(); @@ -1345,7 +1345,7 @@ public class CatalogDatabase implements Closeable { String hql = "FROM VfModule WHERE type = :type and version = :version"; Query query = getSession().createQuery(hql); query.setParameter ("type", type); - query.setParameter ("version", version); + query.setParameter (MODEL_VERSION, version); VfModule module = null; try { module = (VfModule) query.uniqueResult (); @@ -2870,7 +2870,7 @@ public class CatalogDatabase implements Closeable { query = getSession ().createQuery (hql.toString ()); query.setParameter ("modelCustomizationUuid", modelCustomizationUuid); - query.setParameter ("version", asdcServiceModelVersion); + query.setParameter (MODEL_VERSION, asdcServiceModelVersion); }else{ hql = new StringBuilder ("FROM VfModule WHERE type = :type AND version = :version AND modelVersion = :modelVersion"); @@ -2878,7 +2878,7 @@ public class CatalogDatabase implements Closeable { query = getSession ().createQuery (hql.toString ()); query.setParameter (TYPE, vfModuleType); - query.setParameter ("version", asdcServiceModelVersion); + query.setParameter (MODEL_VERSION, asdcServiceModelVersion); query.setParameter ("modelVersion", modelVersion); } @@ -3494,7 +3494,7 @@ public class CatalogDatabase implements Closeable { String hql = "FROM HeatTemplate WHERE templateName = :template_name AND version = :version AND asdcResourceName = :asdcResourceName"; Query query = getSession ().createQuery (hql); query.setParameter (TEMPLATE_NAME, templateName); - query.setParameter ("version", version); + query.setParameter (MODEL_VERSION, version); query.setParameter ("asdcResourceName", asdcResourceName); @SuppressWarnings("unchecked") @@ -3606,7 +3606,7 @@ public class CatalogDatabase implements Closeable { String hql = "FROM HeatEnvironment WHERE name=:name AND version=:version AND asdcResourceName=:asdcResourceName"; Query query = getSession ().createQuery (hql); query.setParameter ("name", name); - query.setParameter ("version", version); + query.setParameter (MODEL_VERSION, version); query.setParameter ("asdcResourceName", asdcResourceName); HeatEnvironment env = null; try { @@ -3648,7 +3648,7 @@ public class CatalogDatabase implements Closeable { String hql = "FROM HeatEnvironment WHERE artifactUuid=:artifactUuid AND version=:version"; Query query = getSession ().createQuery (hql); query.setParameter ("artifactUuid", artifactUuid); - query.setParameter ("version", version); + query.setParameter (MODEL_VERSION, version); HeatEnvironment env = null; try { env = (HeatEnvironment) query.uniqueResult (); @@ -4286,7 +4286,7 @@ public class CatalogDatabase implements Closeable { query.setParameter ("fileName", fileName); query.setParameter ("vnfResourceId", vnfResourceId); query.setParameter ("asdcResourceName", asdcResourceName); - query.setParameter ("version", version); + query.setParameter (MODEL_VERSION, version); @SuppressWarnings("unchecked") |