Fix the tests 09/33609/1
authorDeterme, Sebastien (sd378r) <sd378r@intl.att.com>
Thu, 1 Mar 2018 14:10:35 +0000 (15:10 +0100)
committerDeterme, Sebastien (sd378r) <sd378r@intl.att.com>
Thu, 1 Mar 2018 14:10:35 +0000 (15:10 +0100)
Fix the Integration tests that were broken due to refactoring.

Issue-ID: CLAMP-85
Change-Id: I75cd5327ff40a3cf831b42d98febef1af120e975
Signed-off-by: Determe, Sebastien (sd378r) <sd378r@intl.att.com>
13 files changed:
src/test/java/org/onap/clamp/clds/AbstractItCase.java [deleted file]
src/test/java/org/onap/clamp/clds/it/CldsDaoItCase.java
src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java
src/test/java/org/onap/clamp/clds/it/CldsTemplateServiceItCase.java
src/test/java/org/onap/clamp/clds/it/DcaeHttpConnectionManagerItCase.java
src/test/java/org/onap/clamp/clds/it/HolmesPolicyDelegateItCase.java
src/test/java/org/onap/clamp/clds/it/HttpsItCase.java
src/test/java/org/onap/clamp/clds/it/OperationPolicyReqItCase.java
src/test/java/org/onap/clamp/clds/it/PolicyClientItCase.java
src/test/java/org/onap/clamp/clds/it/SdcCatalogServicesItCase.java
src/test/java/org/onap/clamp/clds/it/SdcReqItCase.java
src/test/java/org/onap/clamp/clds/it/TcaRequestFormatterItCase.java
src/test/java/org/onap/clamp/clds/it/config/CldsReferencePropertiesItCase.java [moved from src/test/java/org/onap/clamp/clds/it/CldsReferencePropertiesItCase.java with 55% similarity]

diff --git a/src/test/java/org/onap/clamp/clds/AbstractItCase.java b/src/test/java/org/onap/clamp/clds/AbstractItCase.java
deleted file mode 100644 (file)
index 7e29088..0000000
+++ /dev/null
@@ -1,44 +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============================================
- * ===================================================================
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- */
-
-package org.onap.clamp.clds;
-
-import org.junit.BeforeClass;
-import org.onap.clamp.clds.client.req.policy.PolicyClient;
-import org.onap.clamp.clds.config.CldsReferenceProperties;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.test.context.ActiveProfiles;
-
-@ActiveProfiles("clamp-default")
-public abstract class AbstractItCase {
-
-    @Autowired
-    protected CldsReferenceProperties refProp;
-    @Autowired
-    protected PolicyClient policyClient;
-
-    @BeforeClass
-    public static void oneTimeSetUp() {
-        System.setProperty("CLDS_DCAE_URL", "http://localhost:13786/cl-dcae-services");
-    }
-}
index 1e9a9ed..861921c 100644 (file)
@@ -42,7 +42,6 @@ import org.apache.commons.codec.DecoderException;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.onap.clamp.clds.AbstractItCase;
 import org.onap.clamp.clds.client.req.sdc.SdcCatalogServices;
 import org.onap.clamp.clds.dao.CldsDao;
 import org.onap.clamp.clds.model.CLDSMonitoringDetails;
@@ -62,7 +61,7 @@ import org.springframework.test.context.junit4.SpringRunner;
  */
 @RunWith(SpringRunner.class)
 @SpringBootTest
-public class CldsDaoItCase extends AbstractItCase {
+public class CldsDaoItCase {
 
     protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsDao.class);
     @Autowired
index 932434d..c2b6fb1 100644 (file)
@@ -45,7 +45,6 @@ import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mockito;
-import org.onap.clamp.clds.AbstractItCase;
 import org.onap.clamp.clds.dao.CldsDao;
 import org.onap.clamp.clds.model.CldsHealthCheck;
 import org.onap.clamp.clds.model.CldsInfo;
@@ -65,7 +64,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  */
 @RunWith(SpringJUnit4ClassRunner.class)
 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
-public class CldsServiceItCase extends AbstractItCase {
+public class CldsServiceItCase {
 
     @Autowired
     private CldsService cldsService;
index 626cf95..1caa637 100644 (file)
@@ -41,7 +41,6 @@ import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mockito;
-import org.onap.clamp.clds.AbstractItCase;
 import org.onap.clamp.clds.dao.CldsDao;
 import org.onap.clamp.clds.model.CldsTemplate;
 import org.onap.clamp.clds.model.ValueItem;
@@ -57,7 +56,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  */
 @RunWith(SpringJUnit4ClassRunner.class)
 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
-public class CldsTemplateServiceItCase extends AbstractItCase {
+public class CldsTemplateServiceItCase {
 
     protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsTemplateServiceItCase.class);
     @Autowired
index 2bdef97..7c4f46d 100644 (file)
@@ -44,7 +44,6 @@ import javax.ws.rs.BadRequestException;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.onap.clamp.clds.AbstractItCase;
 import org.onap.clamp.clds.client.DcaeHttpConnectionManager;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.test.context.SpringBootTest;
@@ -58,7 +57,7 @@ import org.springframework.test.context.junit4.SpringRunner;
 @RunWith(SpringRunner.class)
 @SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT)
 @TestPropertySource(locations = "classpath:https/https-test.properties")
-public class DcaeHttpConnectionManagerItCase extends AbstractItCase {
+public class DcaeHttpConnectionManagerItCase {
 
     @Value("${server.port}")
     private String httpsPort;
index c530a05..29b28a8 100644 (file)
@@ -29,7 +29,6 @@ import java.io.IOException;
 
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.onap.clamp.clds.AbstractItCase;
 import org.onap.clamp.clds.client.HolmesPolicyDelegate;
 import org.onap.clamp.clds.model.properties.Holmes;
 import org.onap.clamp.clds.model.properties.ModelProperties;
@@ -42,7 +41,7 @@ import org.springframework.test.context.junit4.SpringRunner;
  */
 @RunWith(SpringRunner.class)
 @SpringBootTest
-public class HolmesPolicyDelegateItCase extends AbstractItCase {
+public class HolmesPolicyDelegateItCase {
 
     @Test
     public void testCreatePolicyJson() throws IOException {
index 9befc40..73c447b 100644 (file)
@@ -38,7 +38,6 @@ import javax.net.ssl.X509TrustManager;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.onap.clamp.clds.AbstractItCase;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
@@ -55,11 +54,10 @@ import org.springframework.web.client.RestTemplate;
 @RunWith(SpringRunner.class)
 @SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT)
 @TestPropertySource(locations = "classpath:https/https-test.properties")
-public class HttpsItCase extends AbstractItCase {
+public class HttpsItCase {
 
     @Value("${server.port}")
     private String httpsPort;
-
     @Value("${server.http-to-https-redirection.port}")
     private String httpPort;
 
@@ -68,7 +66,6 @@ public class HttpsItCase extends AbstractItCase {
      */
     @BeforeClass
     public static void setUp() {
-
         try {
             // setup ssl context to ignore certificate errors
             SSLContext ctx = SSLContext.getInstance("TLS");
@@ -89,12 +86,13 @@ public class HttpsItCase extends AbstractItCase {
                     return null;
                 }
             };
-            ctx.init(null, new TrustManager[] { tm }, null);
+            ctx.init(null, new TrustManager[] {
+                    tm
+            }, null);
             SSLContext.setDefault(ctx);
         } catch (Exception ex) {
             ex.printStackTrace();
         }
-
     }
 
     @Test
@@ -108,16 +106,13 @@ public class HttpsItCase extends AbstractItCase {
             }
         });
         template.setRequestFactory(factory);
-
         ResponseEntity<String> entity = template
                 .getForEntity("http://localhost:" + this.httpPort + "/designer/index.html", String.class);
         assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
-
         ResponseEntity<String> httpsEntity = template
                 .getForEntity("https://localhost:" + this.httpsPort + "/designer/index.html", String.class);
         assertThat(httpsEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
         assertThat(httpsEntity.getBody()).contains("CLDS");
-
     }
 
     /**
@@ -141,5 +136,4 @@ public class HttpsItCase extends AbstractItCase {
             super.prepareConnection(connection, httpMethod);
         }
     }
-
 }
index 873b019..04bc959 100644 (file)
@@ -35,8 +35,8 @@ import java.util.Map;
 
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.onap.clamp.clds.AbstractItCase;
 import org.onap.clamp.clds.client.req.policy.OperationalPolicyReq;
+import org.onap.clamp.clds.config.CldsReferenceProperties;
 import org.onap.clamp.clds.model.CldsEvent;
 import org.onap.clamp.clds.model.properties.ModelProperties;
 import org.onap.clamp.clds.model.properties.Policy;
@@ -44,12 +44,16 @@ import org.onap.clamp.clds.model.properties.PolicyChain;
 import org.onap.clamp.clds.util.ResourceFileUtil;
 import org.onap.policy.api.AttributeType;
 import org.onap.policy.controlloop.policy.builder.BuilderException;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
 
 @RunWith(SpringRunner.class)
 @SpringBootTest
-public class OperationPolicyReqItCase extends AbstractItCase {
+public class OperationPolicyReqItCase {
+
+    @Autowired
+    private CldsReferenceProperties refProp;
 
     @Test
     public void formatAttributesTest() throws IOException, BuilderException {
index 0e8a217..eb17c22 100644 (file)
@@ -33,9 +33,10 @@ import java.util.concurrent.TimeUnit;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.onap.clamp.clds.AbstractItCase;
 import org.onap.clamp.clds.client.req.policy.OperationalPolicyReq;
+import org.onap.clamp.clds.client.req.policy.PolicyClient;
 import org.onap.clamp.clds.client.req.tca.TcaRequestFormatter;
+import org.onap.clamp.clds.config.CldsReferenceProperties;
 import org.onap.clamp.clds.model.CldsEvent;
 import org.onap.clamp.clds.model.properties.ModelProperties;
 import org.onap.clamp.clds.model.properties.Policy;
@@ -43,6 +44,7 @@ import org.onap.clamp.clds.model.properties.PolicyChain;
 import org.onap.clamp.clds.model.properties.Tca;
 import org.onap.clamp.clds.util.ResourceFileUtil;
 import org.onap.policy.api.AttributeType;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
 
@@ -52,8 +54,12 @@ import org.springframework.test.context.junit4.SpringRunner;
  */
 @RunWith(SpringRunner.class)
 @SpringBootTest
-public class PolicyClientItCase extends AbstractItCase {
+public class PolicyClientItCase {
 
+    @Autowired
+    private CldsReferenceProperties refProp;
+    @Autowired
+    protected PolicyClient policyClient;
     String modelProp;
     String modelBpmnProp;
     String modelName;
index 7f96221..d873aa4 100644 (file)
@@ -32,8 +32,8 @@ import org.apache.commons.io.IOUtils;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mockito;
-import org.onap.clamp.clds.AbstractItCase;
 import org.onap.clamp.clds.client.req.sdc.SdcCatalogServices;
+import org.onap.clamp.clds.config.CldsReferenceProperties;
 import org.onap.clamp.clds.model.CldsAlarmCondition;
 import org.onap.clamp.clds.model.CldsServiceData;
 import org.onap.clamp.clds.model.sdc.SdcResource;
@@ -48,8 +48,10 @@ import org.springframework.test.context.junit4.SpringRunner;
  */
 @RunWith(SpringRunner.class)
 @SpringBootTest
-public class SdcCatalogServicesItCase extends AbstractItCase {
+public class SdcCatalogServicesItCase {
 
+    @Autowired
+    private CldsReferenceProperties refProp;
     @Autowired
     private SdcCatalogServices sdcCatalogWired = new SdcCatalogServices();
 
index 2efc528..ce9c15c 100644 (file)
@@ -35,7 +35,6 @@ import org.apache.commons.codec.DecoderException;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.onap.clamp.clds.AbstractItCase;
 import org.onap.clamp.clds.client.req.sdc.SdcRequests;
 import org.onap.clamp.clds.model.CldsEvent;
 import org.onap.clamp.clds.model.properties.ModelProperties;
@@ -47,7 +46,7 @@ import org.springframework.test.context.junit4.SpringRunner;
 
 @RunWith(SpringRunner.class)
 @SpringBootTest
-public class SdcReqItCase extends AbstractItCase {
+public class SdcReqItCase {
 
     @Autowired
     private SdcRequests sdcReq;
index c290a38..24f127c 100644 (file)
@@ -32,12 +32,13 @@ import org.json.JSONException;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.onap.clamp.clds.AbstractItCase;
 import org.onap.clamp.clds.client.req.tca.TcaRequestFormatter;
+import org.onap.clamp.clds.config.CldsReferenceProperties;
 import org.onap.clamp.clds.model.CldsEvent;
 import org.onap.clamp.clds.model.properties.ModelProperties;
 import org.onap.clamp.clds.util.ResourceFileUtil;
 import org.skyscreamer.jsonassert.JSONAssert;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
 
@@ -46,8 +47,10 @@ import org.springframework.test.context.junit4.SpringRunner;
  */
 @RunWith(SpringRunner.class)
 @SpringBootTest
-public class TcaRequestFormatterItCase extends AbstractItCase {
+public class TcaRequestFormatterItCase {
 
+    @Autowired
+    private CldsReferenceProperties refProp;
     private String modelProp;
     private String modelBpmn;
     private String modelName;
  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
  */
 
-package org.onap.clamp.clds.it;
+package org.onap.clamp.clds.it.config;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 
 import java.io.IOException;
 
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.onap.clamp.clds.AbstractItCase;
+import org.onap.clamp.clds.config.CldsReferenceProperties;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
 
@@ -41,9 +43,23 @@ import org.springframework.test.context.junit4.SpringRunner;
  */
 @RunWith(SpringRunner.class)
 @SpringBootTest
-public class CldsReferencePropertiesItCase extends AbstractItCase {
+public class CldsReferencePropertiesItCase {
+
+    @Autowired
+    private CldsReferenceProperties refProp;
 
-    protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsReferencePropertiesItCase.class);
+    /**
+     * Test getting a value the properties in string.
+     * 
+     * @throws IOException
+     */
+    @Test
+    public void testGetStringValue() throws IOException {
+        assertEquals(refProp.getStringValue("policy.onap.name"), "DCAE");
+        assertEquals(refProp.getStringValue("policy.ms.policyNamePrefix", ""), "Config_MS_");
+        assertEquals(refProp.getStringValue("policy.ms.policyNamePrefix", "testos"), "Config_MS_");
+        assertEquals(refProp.getStringValue("policy.ms", "policyNamePrefix"), "Config_MS_");
+    }
 
     /**
      * Test getting prop value as a JSON Node / template.
@@ -53,11 +69,16 @@ public class CldsReferencePropertiesItCase extends AbstractItCase {
      */
     @Test
     public void testJsonTemplate() throws IOException {
-        ObjectNode root = (ObjectNode) refProp.getJsonTemplate("tca.template");
-        root.put("closedLoopControlName", "ClosedLoop-FRWL-SIG-1582f840-2881-11e6-b4ec-005056a9d756");
-        ObjectMapper mapper = new ObjectMapper();
-        String jsonText = mapper.writeValueAsString(root);
-        logger.error("Exception caught IllegalArgumentException as expected");
-        // assertEquals(topicsJson, ref.getTopicsToJson());
+        // ui.location.default={"DC1":"Data Center 1","DC2":"Data Center
+        // 2","DC3":"Data Center 3"}
+        ObjectNode root = (ObjectNode) refProp.getJsonTemplate("ui.location.default");
+        assertNotNull(root);
+        assertEquals(root.get("DC1").asText(), "Data Center 1");
+        // Test composite key
+        root = (ObjectNode) refProp.getJsonTemplate("ui.location", "default");
+        assertNotNull(root);
+        assertEquals(root.get("DC1").asText(), "Data Center 1");
+        root = (ObjectNode) refProp.getJsonTemplate("ui.location", "");
+        assertNull(root);
     }
 }