From bb393ee2f520254b6fa47d282108790eeda95725 Mon Sep 17 00:00:00 2001 From: xg353y Date: Fri, 22 Mar 2019 15:43:15 +0100 Subject: Rework deploy/undeploy UI Rework the deploy/undeploy Ui based on the new data model. Issue-ID: CLAMP-334 Change-Id: I03d591bea81cb050e12031782dfa383656f1a32c Signed-off-by: xg353y --- .../clds/client/DcaeDispatcherServicesTest.java | 27 ++-- .../clds/it/DcaeHttpConnectionManagerItCase.java | 148 --------------------- .../clamp/clds/it/HttpConnectionManagerItCase.java | 148 +++++++++++++++++++++ src/test/javascript/propertyController.test.js | 4 +- 4 files changed, 164 insertions(+), 163 deletions(-) delete mode 100644 src/test/java/org/onap/clamp/clds/it/DcaeHttpConnectionManagerItCase.java create mode 100644 src/test/java/org/onap/clamp/clds/it/HttpConnectionManagerItCase.java (limited to 'src/test') diff --git a/src/test/java/org/onap/clamp/clds/client/DcaeDispatcherServicesTest.java b/src/test/java/org/onap/clamp/clds/client/DcaeDispatcherServicesTest.java index 1b01f544b..caab61f18 100644 --- a/src/test/java/org/onap/clamp/clds/client/DcaeDispatcherServicesTest.java +++ b/src/test/java/org/onap/clamp/clds/client/DcaeDispatcherServicesTest.java @@ -36,6 +36,7 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.runners.MockitoJUnitRunner; import org.onap.clamp.clds.config.ClampProperties; +import org.onap.clamp.util.HttpConnectionManager; @@ -55,7 +56,7 @@ public class DcaeDispatcherServicesTest { private ClampProperties clampProperties; @Mock - DcaeHttpConnectionManager dcaeHttpConnectionManager; + HttpConnectionManager httpConnectionManager; @InjectMocks DcaeDispatcherServices dcaeDispatcherServices; @@ -84,7 +85,7 @@ public class DcaeDispatcherServicesTest { @Test public void shouldReturnDcaeOperationSataus() throws IOException { //given - Mockito.when(dcaeHttpConnectionManager.doDcaeHttpQuery(DEPLOYMENT_STATUS_URL, "GET", null, null)) + Mockito.when(httpConnectionManager.doGeneralHttpQuery(DEPLOYMENT_STATUS_URL, "GET", null, null, "DCAE")) .thenReturn(STATUS_RESPONSE_PROCESSING); //when String operationStatus = dcaeDispatcherServices.getOperationStatus(DEPLOYMENT_STATUS_URL); @@ -96,24 +97,24 @@ public class DcaeDispatcherServicesTest { @Test public void shouldTryMultipleTimesWhenProcessing() throws IOException, InterruptedException { //given - Mockito.when(dcaeHttpConnectionManager.doDcaeHttpQuery(DEPLOYMENT_STATUS_URL, "GET", - null, null)) + Mockito.when(httpConnectionManager.doGeneralHttpQuery(DEPLOYMENT_STATUS_URL, "GET", + null, null, "DCAE")) .thenReturn(STATUS_RESPONSE_PROCESSING, STATUS_RESPONSE_PROCESSING, STATUS_RESPONSE_ACTIVE); //when String operationStatus = dcaeDispatcherServices.getOperationStatusWithRetry(DEPLOYMENT_STATUS_URL); //then Assertions.assertThat(operationStatus).isEqualTo("succeeded"); - Mockito.verify(dcaeHttpConnectionManager, Mockito.times(3)) - .doDcaeHttpQuery(DEPLOYMENT_STATUS_URL, "GET", null, null); + Mockito.verify(httpConnectionManager, Mockito.times(3)) + .doGeneralHttpQuery(DEPLOYMENT_STATUS_URL, "GET", null, null, "DCAE"); } @Test public void shouldTryOnlyAsManyTimesAsConfigured() throws IOException, InterruptedException { //given - Mockito.when(dcaeHttpConnectionManager - .doDcaeHttpQuery(DEPLOYMENT_STATUS_URL, "GET", null, null)) + Mockito.when(httpConnectionManager + .doGeneralHttpQuery(DEPLOYMENT_STATUS_URL, "GET", null, null, "DCAE")) .thenReturn(STATUS_RESPONSE_PROCESSING, STATUS_RESPONSE_PROCESSING, STATUS_RESPONSE_PROCESSING, STATUS_RESPONSE_PROCESSING, STATUS_RESPONSE_PROCESSING); //when @@ -121,8 +122,8 @@ public class DcaeDispatcherServicesTest { //then Assertions.assertThat(operationStatus).isEqualTo("processing"); - Mockito.verify(dcaeHttpConnectionManager, Mockito.times(3)) - .doDcaeHttpQuery(DEPLOYMENT_STATUS_URL, "GET", null, null); + Mockito.verify(httpConnectionManager, Mockito.times(3)) + .doGeneralHttpQuery(DEPLOYMENT_STATUS_URL, "GET", null, null, "DCAE"); } @@ -134,12 +135,12 @@ public class DcaeDispatcherServicesTest { Mockito.when(clampProperties.getJsonTemplate("dcae.deployment.template")) .thenReturn(new JsonObject()); - Mockito.when(dcaeHttpConnectionManager - .doDcaeHttpQuery(DCAE_URL + Mockito.when(httpConnectionManager + .doGeneralHttpQuery(DCAE_URL + "/dcae-deployments/closedLoop_152367c8-b172-47b3-9e58-c53add75d869_deploymentId", "PUT", "{\"serviceTypeId\":\"e2ba40f7-bf42-41e7-acd7-48fd07586d90\",\"inputs\":{}}", - "application/json")) + "application/json", "DCAE")) .thenReturn(DEPLOY_RESPONSE_STRING); JsonObject blueprintInputJson = new JsonObject(); diff --git a/src/test/java/org/onap/clamp/clds/it/DcaeHttpConnectionManagerItCase.java b/src/test/java/org/onap/clamp/clds/it/DcaeHttpConnectionManagerItCase.java deleted file mode 100644 index 8e03153a2..000000000 --- a/src/test/java/org/onap/clamp/clds/it/DcaeHttpConnectionManagerItCase.java +++ /dev/null @@ -1,148 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2017-2018 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============================================ - * Modifications copyright (c) 2018 Nokia - * =================================================================== - * - */ - -package org.onap.clamp.clds.it; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.IOException; -import java.security.KeyManagementException; -import java.security.NoSuchAlgorithmException; -import java.security.cert.CertificateException; -import java.security.cert.X509Certificate; - -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSession; -import javax.net.ssl.TrustManager; -import javax.net.ssl.X509TrustManager; -import javax.ws.rs.BadRequestException; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.onap.clamp.clds.client.DcaeHttpConnectionManager; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; - -/** - * Test HTTP and HTTPS settings + redirection of HTTP to HTTPS. - */ -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT) -@TestPropertySource(locations = "classpath:https/https-test.properties") -public class DcaeHttpConnectionManagerItCase { - - @Value("${server.port}") - private String httpsPort; - @Value("${server.http-to-https-redirection.port}") - private String httpPort; - - @Autowired - DcaeHttpConnectionManager dcaeHttpConnectionManager; - - private static TrustManager[] trustAllCerts = new TrustManager[]{ - new X509TrustManager() { - - @Override - public java.security.cert.X509Certificate[] getAcceptedIssuers() { - return null; - } - - @Override - public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { - } - - @Override - public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { - } - } - }; - - private void enableSslNoCheck() throws NoSuchAlgorithmException, KeyManagementException { - SSLContext sc = SSLContext.getInstance("SSL"); - sc.init(null, trustAllCerts, new java.security.SecureRandom()); - HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); - HostnameVerifier allHostsValid = new HostnameVerifier() { - - @Override - public boolean verify(String hostname, SSLSession session) { - return true; - } - }; - // set the allTrusting verifier - HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid); - } - - @Before - public void setupEnvBeforeTest() throws KeyManagementException, NoSuchAlgorithmException { - enableSslNoCheck(); - } - - @Test - public void testHttpGet() throws Exception { - String response = dcaeHttpConnectionManager - .doDcaeHttpQuery("http://localhost:" + this.httpPort + "/designer/index.html", "GET", null, null); - assertNotNull(response); - // Should be a redirection so 302, so empty - assertTrue(response.isEmpty()); - } - - @Test - public void testHttpsGet() throws Exception { - String response = dcaeHttpConnectionManager - .doDcaeHttpQuery("https://localhost:" + this.httpsPort + "/designer/index.html", "GET", null, null); - assertNotNull(response); - // Should contain something - assertTrue(!response.isEmpty()); - } - - @Test(expected = BadRequestException.class) - public void testHttpsGet404() throws IOException { - dcaeHttpConnectionManager.doDcaeHttpQuery("https://localhost:" + this.httpsPort + "/designer/index1.html", - "GET", null, null); - fail("Should have raised an BadRequestException"); - } - - @Test(expected = BadRequestException.class) - public void testHttpsPost404() throws IOException { - dcaeHttpConnectionManager.doDcaeHttpQuery("https://localhost:" + this.httpsPort + "/designer/index1.html", - "POST", "", "application/json"); - fail("Should have raised an BadRequestException"); - } - - @Test(expected = BadRequestException.class) - public void testHttpException() throws IOException { - dcaeHttpConnectionManager.doDcaeHttpQuery("http://localhost:" + this.httpsPort + "/designer/index.html", "GET", - null, null); - fail("Should have raised an BadRequestException"); - } -} diff --git a/src/test/java/org/onap/clamp/clds/it/HttpConnectionManagerItCase.java b/src/test/java/org/onap/clamp/clds/it/HttpConnectionManagerItCase.java new file mode 100644 index 000000000..42e9c7f63 --- /dev/null +++ b/src/test/java/org/onap/clamp/clds/it/HttpConnectionManagerItCase.java @@ -0,0 +1,148 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2017-2018 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============================================ + * Modifications copyright (c) 2018 Nokia + * =================================================================== + * + */ + +package org.onap.clamp.clds.it; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.IOException; +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSession; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; +import javax.ws.rs.BadRequestException; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.clamp.util.HttpConnectionManager; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * Test HTTP and HTTPS settings + redirection of HTTP to HTTPS. + */ +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT) +@TestPropertySource(locations = "classpath:https/https-test.properties") +public class HttpConnectionManagerItCase { + + @Value("${server.port}") + private String httpsPort; + @Value("${server.http-to-https-redirection.port}") + private String httpPort; + + @Autowired + HttpConnectionManager httpConnectionManager; + + private static TrustManager[] trustAllCerts = new TrustManager[]{ + new X509TrustManager() { + + @Override + public java.security.cert.X509Certificate[] getAcceptedIssuers() { + return null; + } + + @Override + public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { + } + + @Override + public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { + } + } + }; + + private void enableSslNoCheck() throws NoSuchAlgorithmException, KeyManagementException { + SSLContext sc = SSLContext.getInstance("SSL"); + sc.init(null, trustAllCerts, new java.security.SecureRandom()); + HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); + HostnameVerifier allHostsValid = new HostnameVerifier() { + + @Override + public boolean verify(String hostname, SSLSession session) { + return true; + } + }; + // set the allTrusting verifier + HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid); + } + + @Before + public void setupEnvBeforeTest() throws KeyManagementException, NoSuchAlgorithmException { + enableSslNoCheck(); + } + + @Test + public void testHttpGet() throws Exception { + String response = httpConnectionManager + .doGeneralHttpQuery("http://localhost:" + this.httpPort + "/designer/index.html", "GET", null, null, "DCAE"); + assertNotNull(response); + // Should be a redirection so 302, so empty + assertTrue(response.isEmpty()); + } + + @Test + public void testHttpsGet() throws Exception { + String response = httpConnectionManager + .doGeneralHttpQuery("https://localhost:" + this.httpsPort + "/designer/index.html", "GET", null, null, "DCAE"); + assertNotNull(response); + // Should contain something + assertTrue(!response.isEmpty()); + } + + @Test(expected = BadRequestException.class) + public void testHttpsGet404() throws IOException { + httpConnectionManager.doGeneralHttpQuery("https://localhost:" + this.httpsPort + "/designer/index1.html", + "GET", null, null, "DCAE"); + fail("Should have raised an BadRequestException"); + } + + @Test(expected = BadRequestException.class) + public void testHttpsPost404() throws IOException { + httpConnectionManager.doGeneralHttpQuery("https://localhost:" + this.httpsPort + "/designer/index1.html", + "POST", "", "application/json", "DCAE"); + fail("Should have raised an BadRequestException"); + } + + @Test(expected = BadRequestException.class) + public void testHttpException() throws IOException { + httpConnectionManager.doGeneralHttpQuery("http://localhost:" + this.httpsPort + "/designer/index.html", "GET", + null, null, "DCAE"); + fail("Should have raised an BadRequestException"); + } +} diff --git a/src/test/javascript/propertyController.test.js b/src/test/javascript/propertyController.test.js index 6cb779145..fbbc6beca 100644 --- a/src/test/javascript/propertyController.test.js +++ b/src/test/javascript/propertyController.test.js @@ -31,8 +31,8 @@ describe('Property controller tests', function() { expect(propertyController.getMsUI("test")).toEqual(null); }); - test('getStatus', () => { - expect(propertyController.getStatus()).toEqual('DESIGN'); + test('getLastUpdatedStatus', () => { + expect(propertyController.getLastUpdatedStatus()).toEqual('DESIGN'); }); test('getDeploymentID', () => { -- cgit 1.2.3-korg