Improve fed gateway test code coverage 60/3160/3
authorLott, Christopher (cl778h) <cl778h@att.com>
Fri, 12 Oct 2018 09:59:08 +0000 (05:59 -0400)
committerLott, Christopher (cl778h) <cl778h@att.com>
Fri, 12 Oct 2018 14:18:12 +0000 (10:18 -0400)
Drop some unused methods instead of covering them.
Address a few minor Sonar complaints.

Change-Id: Id27eba1798261e77298028310cb0532fc93ecf71
Signed-off-by: Lott, Christopher (cl778h) <cl778h@att.com>
gateway/.gitignore
gateway/src/main/java/org/acumos/federation/gateway/Application.java
gateway/src/main/java/org/acumos/federation/gateway/adapter/PeerGateway.java
gateway/src/main/java/org/acumos/federation/gateway/adapter/onap/ToscaLab.java
gateway/src/main/java/org/acumos/federation/gateway/common/AbstractClient.java
gateway/src/main/java/org/acumos/federation/gateway/task/PeerSubscriptionTask.java
gateway/src/main/java/org/acumos/federation/gateway/util/Utils.java
gateway/src/test/java/org/acumos/federation/gateway/test/AsdcTest.java [new file with mode: 0644]
gateway/src/test/java/org/acumos/federation/gateway/test/CdsTest.java [new file with mode: 0644]
gateway/src/test/java/org/acumos/federation/gateway/test/UtilsTest.java [new file with mode: 0644]
gateway/src/test/resources/logback.xml [new file with mode: 0644]

index fbdf7eb..c3faa9b 100644 (file)
@@ -1,3 +1,4 @@
 /.classpath
 /.project
 /.settings/
+/debug-logs
index d62060c..893f36c 100644 (file)
@@ -54,13 +54,18 @@ import com.fasterxml.jackson.databind.ObjectMapper;
                                                                                                                                                                                         org.acumos.federation.gateway.config.AdapterConfiguration.class}))
 public class Application {
 
-       private final static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(Application.class);
+       private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(Application.class);
 
        /**
         * We should be able to swap the LocalConfiguration in the case of adapters.
+        * 
+        * @param args
+        *            Ignored
+        * @throws IOException
+        *             if environment config cannot be parsed
         */
-       public static void main(String[] args) throws Exception {
-    
+       public static void main(String[] args) throws IOException {
+               checkEnvironmentConfig();
                SpringApplicationBuilder gatewayBuilder =
                        new SpringApplicationBuilder(Application.class)
                                                                                        .bannerMode(Banner.Mode.OFF)
@@ -76,7 +81,7 @@ public class Application {
 
        }
 
-       public static final String CONFIG_ENV_VAR_NAME = "SPRING_APPLICATION_JSON";
+       private static final String CONFIG_ENV_VAR_NAME = "SPRING_APPLICATION_JSON";
 
        private static void checkEnvironmentConfig() throws IOException {
                final String springApplicationJson = System.getenv(CONFIG_ENV_VAR_NAME);
index d05b69d..483b462 100644 (file)
 
 package org.acumos.federation.gateway.adapter;
 
-import java.lang.invoke.MethodHandles;
-
 import java.io.Closeable;
-
+import java.lang.invoke.MethodHandles;
 import java.util.Collections;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Date;
 
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
 
 import org.acumos.cds.AccessTypeCode;
-//to go away 
 import org.acumos.cds.client.ICommonDataServiceRestClient;
-import org.acumos.cds.domain.MLPArtifact;
-import org.acumos.cds.domain.MLPDocument;
 import org.acumos.cds.domain.MLPPeer;
 import org.acumos.cds.domain.MLPPeerSubscription;
 import org.acumos.cds.domain.MLPRevisionDescription;
@@ -45,10 +40,10 @@ import org.acumos.cds.domain.MLPSolution;
 import org.acumos.cds.domain.MLPSolutionRevision;
 import org.acumos.federation.gateway.cds.Artifact;
 import org.acumos.federation.gateway.cds.Document;
+import org.acumos.federation.gateway.cds.PeerSubscription;
 import org.acumos.federation.gateway.cds.Solution;
 import org.acumos.federation.gateway.cds.SolutionRevision;
 import org.acumos.federation.gateway.cds.SubscriptionScope;
-import org.acumos.federation.gateway.cds.PeerSubscription;
 import org.acumos.federation.gateway.cds.TimestampedEntity;
 import org.acumos.federation.gateway.common.Clients;
 import org.acumos.federation.gateway.common.FederationClient;
@@ -60,7 +55,6 @@ import org.acumos.federation.gateway.service.ContentService;
 import org.acumos.federation.gateway.service.PeerSubscriptionService;
 import org.acumos.federation.gateway.service.ServiceContext;
 import org.acumos.federation.gateway.service.ServiceException;
-import org.acumos.federation.gateway.service.impl.AbstractServiceImpl;
 import org.springframework.beans.factory.BeanInitializationException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Conditional;
@@ -92,6 +86,7 @@ public class PeerGateway {
        @Autowired
        private PeerSubscriptionService peerSubscriptionService;
 
+       private static final String federationDotOperator = "federation.operator";
 
        public PeerGateway() {
                log.trace(EELFLoggerDelegate.debugLogger, "PeerGateway::new");
@@ -102,18 +97,18 @@ public class PeerGateway {
                log.trace(EELFLoggerDelegate.debugLogger, "initPeerGateway");
 
                /* make sure an operator was specified and that it is a declared user */
-               if (null == this.env.getProperty("federation.operator")) {
-                       throw new BeanInitializationException("Missing 'federation.operator' configuration");
+               if (null == this.env.getProperty(federationDotOperator)) {
+                       throw new BeanInitializationException("Missing configuration key " + federationDotOperator);
                } 
                else {
                        try {
-                               if (null == this.clients.getCDSClient().getUser(this.env.getProperty("federation.operator"))) {
-                                       log.warn(EELFLoggerDelegate.errorLogger,
-                                                       "'federation.operator' does not point to an existing user");
+                               if (null == this.clients.getCDSClient().getUser(this.env.getProperty(federationDotOperator))) {
+                                       log.warn(EELFLoggerDelegate.errorLogger, federationDotOperator + 
+                                                       " does not point to an existing user");
                                }
                        }
                        catch (/* HttpStatusCode */Exception dx) {
-                               log.warn(EELFLoggerDelegate.errorLogger, "failed to verify 'federation.operator' value", dx);
+                               log.warn(EELFLoggerDelegate.errorLogger, "failed to verify value " + federationDotOperator, dx);
                        }
                }
 
@@ -130,7 +125,7 @@ public class PeerGateway {
                                                                                                                                         * , MLPSolution theSolution
                                                                                                                                         */) {
                String userId = theSubscription.getUserId();
-               return userId != null ? userId : this.env.getProperty("federation.operator");
+               return userId != null ? userId : this.env.getProperty(federationDotOperator);
        }
 
        @EventListener
@@ -195,7 +190,6 @@ public class PeerGateway {
                //as ugly as they come
                private ICommonDataServiceRestClient getCDSClient(ServiceContext theContext) {
                        return PeerGateway.this.clients.getCDSClient();
-                       //return (ICommonDataServiceRestClient)theContext.getAttribute(AbstractServiceImpl.Attributes.cdsClient);
                }
 
                private Artifact copyArtifact(Artifact peerArtifact) {
index 641cea8..6eeabff 100644 (file)
@@ -38,10 +38,6 @@ public class ToscaLab {
                                lab.create_model(new FileInputStream(spec)));
        }
 
-
-       //private PythonInterpreter create_model_interpreter = null;
-       //private PyCode create_model = null;
-
        public ToscaLab() {
                //the problem here is that if we use jython anywhere else this static initialization will be reflected
                Properties props = new Properties();
@@ -53,22 +49,18 @@ public class ToscaLab {
        }
 
        public String create_model(InputStream theSpec) throws Exception {
-
-               //if (this.create_model_interpreter == null) {
-                       PythonInterpreter python = new PythonInterpreter();
+               try (PythonInterpreter python = new PythonInterpreter()) {
                        python.setIn(theSpec);
                        ByteArrayOutputStream out = new ByteArrayOutputStream();
                        python.setOut(out);
-
                        InputStream script = ClassLoader.getSystemResourceAsStream("model_create.py");
                        if (script == null)
                                throw new Exception("Failed to load 'model_create.py' script");
                        else
                                python.execfile(script);
-
                        return out.toString();
-               //}
-       } 
+               }
+       }
 }
 
 
index f03f938..9143b90 100644 (file)
 package org.acumos.federation.gateway.common;
 
 import java.net.MalformedURLException;
-import java.net.URI;
 import java.net.URL;
-import java.util.Date;
-import java.util.Map;
 import java.util.Collections;
 
-import org.acumos.cds.transport.RestPageRequest;
 import org.apache.http.client.HttpClient;
 import org.springframework.boot.web.client.RestTemplateBuilder;
 import org.springframework.http.MediaType;
 import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
-import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
 import org.springframework.http.converter.ResourceHttpMessageConverter;
+import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
 import org.springframework.web.client.RestTemplate;
-import org.springframework.web.util.UriComponentsBuilder;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
 
@@ -97,47 +92,4 @@ public abstract class AbstractClient {
                }
        }       
 
-       /**
-        * Builds URI by adding specified path segments and query parameters to the base
-        * URL.
-        * 
-        * @param path
-        *            Array of path segments
-        * @param queryParams
-        *            key-value pairs; ignored if null or empty. Gives special treatment
-        *            to Date-type values.
-        * @param pageRequest
-        *            page, size and sort specification; ignored if null.
-        * @return URI
-        */
-       protected URI buildUri(final String[] path, final Map<String, Object> queryParams, RestPageRequest pageRequest) {
-               UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(this.baseUrl);
-               for (int p = 0; p < path.length; ++p)
-                       builder.pathSegment(path[p]);
-               if (queryParams != null && queryParams.size() > 0) {
-                       for (Map.Entry<String, ? extends Object> entry : queryParams.entrySet()) {
-                               Object value = null;
-                               // Server expect Date as Long.
-                               if (entry.getValue() instanceof Date)
-                                       value = ((Date) entry.getValue()).getTime();
-                               else
-                                       value = entry.getValue().toString();
-                               builder.queryParam(entry.getKey(), value);
-                       }
-               }
-               if (pageRequest != null) {
-                       if (pageRequest.getSize() != null)
-                               builder.queryParam("page", Integer.toString(pageRequest.getPage()));
-                       if (pageRequest.getPage() != null)
-                               builder.queryParam("size", Integer.toString(pageRequest.getSize()));
-                       if (pageRequest.getFieldToDirectionMap() != null && pageRequest.getFieldToDirectionMap().size() > 0) {
-                               for (Map.Entry<String, String> entry : pageRequest.getFieldToDirectionMap().entrySet()) {
-                                       String value = entry.getKey() + (entry.getValue() == null ? "" : ("," + entry.getValue()));
-                                       builder.queryParam("sort", value);
-                               }
-                       }
-               }
-               return builder.build().encode().toUri();
-       }
-
 }
index d7601d0..543131c 100644 (file)
@@ -96,6 +96,8 @@ public class PeerSubscriptionTask implements Runnable {
                try {
                        log.info(EELFLoggerDelegate.debugLogger, "Peer task for peer {}, subscription {}", this.peer.getName(), this.subscription.getSubId());
                        FederationClient fedClient = clients.getFederationClient(this.peer.getApiUrl());
+                       if (fedClient == null)
+                               throw new IllegalArgumentException("run: failed to get client for peer URL " + this.peer.getApiUrl());
                        JsonResponse<List<MLPSolution>> response = fedClient.getSolutions(selector);
                        log.info(EELFLoggerDelegate.debugLogger, "Peer task for peer {}, subscription {} got response {}", this.peer.getName(), this.subscription.getSubId(), response);
                        if (response != null) {
index 9285418..f53fd07 100644 (file)
@@ -20,7 +20,6 @@
 
 package org.acumos.federation.gateway.util;
 
-import java.io.File;
 import java.io.IOException;
 import java.lang.invoke.MethodHandles;
 import java.util.HashMap;
@@ -39,9 +38,6 @@ public class Utils {
 
        private static ObjectMapper objectMapper = new ObjectMapper();
 
-       public Utils() {
-       }
-
        public static boolean isEmptyOrNullString(String input) {
                boolean isEmpty = false;
                if (null == input || 0 == input.trim().length()) {
@@ -66,6 +62,7 @@ public class Utils {
                                map = objectMapper.readValue(jsonString, new TypeReference<Map<String, Object>>() {
                                });
                        } catch (IOException x) {
+                               log.error("jsongStringToMap failed", x);
                                throw new IllegalArgumentException("Argument not a map", x);
                        }
                }
@@ -77,93 +74,9 @@ public class Utils {
                try {
                        return objectMapper.writeValueAsString(theMap);
                } catch (JsonProcessingException x) {
+                       log.error("mapToJsonString failed", x);
                        throw new IllegalArgumentException("Failed to convert", x);
                }
        }
 
-       public static String getTempFolderPath(String artifactName, String version, String nexusTempPath) {
-               log.debug("--------------- getTempFolderPath() started --------------");
-               if (!isEmptyOrNullString(nexusTempPath)) {
-                       nexusTempPath = nexusTempPath + "/" + artifactName + "/" + version;
-                       // create the directory for the solution and version specified
-                       File dir = new File(nexusTempPath);
-                       log.debug("------------ Directory for artifactName and Version : -------------" + dir);
-                       if (!dir.exists()) {
-                               log.debug("------------ Directory not exists for artifactName and Version : --------------------");
-                               dir.mkdir();
-                               log.debug("----------- New Directory created for artifactName and Version : ----------------" + dir);
-                       }
-               }
-               log.debug("-------------  getTempFolderPath() ended ---------------");
-               return nexusTempPath;
-       }
-
-       public static void deletetTempFiles(String tempFolder) throws Exception {
-               log.info("--------  deletetTempFiles() Started ------------");
-
-               File directory = new File(tempFolder);
-
-               // make sure directory exists
-               if (!directory.exists()) {
-                       log.debug("----------- Directory does not exist. ----------");
-
-               } else {
-
-                       try {
-
-                               delete(directory);
-                               log.info("----------- deletetTempFiles() Ended ----------------");
-                       } catch (Exception e) {
-                               log.error("--------- Exception deletetTempFiles() -------------", e);
-                               throw e;
-                       }
-               }
-
-       }
-
-       public static void delete(File file) throws IOException {
-               log.debug("------------  delete() started ------------");
-               try {
-                       if (file.isDirectory()) {
-
-                               // directory is empty, then delete it
-                               if (file.list().length == 0) {
-
-                                       file.delete();
-                                       log.debug("--------- Directory is deleted : ----------- " + file.getAbsolutePath());
-
-                               } else {
-
-                                       // list all the directory contents
-                                       String files[] = file.list();
-
-                                       if (files != null && files.length != 0) {
-                                               for (String temp : files) {
-                                                       // construct the file structure
-                                                       File fileDelete = new File(file, temp);
-
-                                                       // recursive delete
-                                                       delete(fileDelete);
-                                               }
-                                       }
-
-                                       // check the directory again, if empty then delete it
-                                       if (file.list().length == 0) {
-                                               file.delete();
-                                               log.debug(" -------Directory is deleted :------------- " + file.getAbsolutePath());
-                                       }
-                               }
-
-                       } else {
-                               // if file, then delete it
-                               file.delete();
-                               log.debug("---------File is deleted :----------- " + file.getAbsolutePath());
-                       }
-                       log.debug("------------- delete() ended ---------------");
-               } catch (Exception ex) {
-                       log.error("----------- Exceptoin Occured delete() ---------------", ex);
-
-               }
-       }
-
 }
diff --git a/gateway/src/test/java/org/acumos/federation/gateway/test/AsdcTest.java b/gateway/src/test/java/org/acumos/federation/gateway/test/AsdcTest.java
new file mode 100644 (file)
index 0000000..924b3a8
--- /dev/null
@@ -0,0 +1,57 @@
+/*-
+ * ===============LICENSE_START=======================================================
+ * Acumos
+ * ===================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property & Tech Mahindra. All rights reserved.
+ * ===================================================================================
+ * This Acumos software file is distributed by AT&T and Tech Mahindra
+ * 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
+ *
+ * This file 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.acumos.federation.gateway.test;
+
+import java.lang.invoke.MethodHandles;
+import java.net.URI;
+
+import org.acumos.federation.gateway.adapter.onap.sdc.ASDC;
+import org.acumos.federation.gateway.config.EELFLoggerDelegate;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class AsdcTest {
+
+       private static final EELFLoggerDelegate log = EELFLoggerDelegate.getLogger(MethodHandles.lookup().lookupClass());
+
+       @Test
+       public void testASDC() throws Exception {
+               for (ASDC.AssetType e : ASDC.AssetType.values())
+                       log.info("assest type {}, code {}", e);
+               for (ASDC.ArtifactType e : ASDC.ArtifactType.values())
+                       log.info("artifact type {}, code {}", e);
+               for (ASDC.ArtifactGroupType e : ASDC.ArtifactGroupType.values())
+                       log.info("artifact group type {}, code {}", e);
+               for (ASDC.LifecycleState e : ASDC.LifecycleState.values())
+                       log.info("lifecycle state {}, code {}", e);
+               ASDC asdc = new ASDC();
+               URI uriNoFrag = new URI("http://user:pass@host:443/context/path");
+               try {
+                       asdc.setUri(uriNoFrag);
+                       Assert.assertTrue(false);
+               } catch (Exception ex) {
+                       log.info("Caught exception as expected");
+               }
+               URI uri = new URI("http://user:pass@host:443/context/path#fragment");
+               asdc.setUri(uri);
+               Assert.assertNotNull(asdc.getUri());
+       }
+
+}
diff --git a/gateway/src/test/java/org/acumos/federation/gateway/test/CdsTest.java b/gateway/src/test/java/org/acumos/federation/gateway/test/CdsTest.java
new file mode 100644 (file)
index 0000000..f8d01a2
--- /dev/null
@@ -0,0 +1,182 @@
+/*-
+ * ===============LICENSE_START=======================================================
+ * Acumos
+ * ===================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property & Tech Mahindra. All rights reserved.
+ * ===================================================================================
+ * This Acumos software file is distributed by AT&T and Tech Mahindra
+ * 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
+ *
+ * This file 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.acumos.federation.gateway.test;
+
+import java.lang.invoke.MethodHandles;
+import java.util.Date;
+import java.util.Set;
+
+import org.acumos.cds.domain.MLPSolutionWeb;
+import org.acumos.cds.domain.MLPTag;
+import org.acumos.federation.gateway.cds.AccessType;
+import org.acumos.federation.gateway.cds.Artifact;
+import org.acumos.federation.gateway.cds.ArtifactBuilder;
+import org.acumos.federation.gateway.cds.ArtifactType;
+import org.acumos.federation.gateway.cds.Document;
+import org.acumos.federation.gateway.cds.DocumentBuilder;
+import org.acumos.federation.gateway.cds.Solution;
+import org.acumos.federation.gateway.cds.SolutionBuilder;
+import org.acumos.federation.gateway.cds.SolutionRevision;
+import org.acumos.federation.gateway.cds.SolutionRevisionBuilder;
+import org.acumos.federation.gateway.cds.Updater;
+import org.acumos.federation.gateway.config.EELFLoggerDelegate;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class CdsTest {
+
+       private static final EELFLoggerDelegate log = EELFLoggerDelegate.getLogger(MethodHandles.lookup().lookupClass());
+
+       private final boolean active = true;
+       private final String atc = "PR";
+       private final Date date1 = new Date();
+       private final Date date2 = new Date();
+       private final String desc = "desc";
+       private final String id1 = "id1";
+       private final String id2 = "id2";
+       private final String meta = "meta";
+       private final String mtc = "MT";
+       private final String name = "name";
+       private final String origin = "origin";
+       private final String source = "source";
+       private final String ttc = "TK";
+       private final String uri = "uri";
+       private final String user = "user";
+       private final String version = "ver";
+       private final Integer size = 42;
+       private final String vsc = "YZ";
+
+       // Trivial implementation just returns first argument
+       private final Updater<String, Object> theUpdater = new Updater<String, Object>() {
+               @Override
+               public String update(Object... theArgs) {
+                       return theArgs[0].toString();
+               }
+       };
+
+       @Test
+       public void testAccessType() throws Exception {
+               for (AccessType e : AccessType.values()) {
+                       log.info("access type {}, code {}", e, e.code());
+                       AccessType.forCode(e.code());
+               }
+       }
+       
+       @Test
+       public void testArtifactType() throws Exception {
+               for (ArtifactType e : ArtifactType.values()) {
+                       log.info("artifact type {}, code {}", e, e.code());
+                       ArtifactType.forCode(e.code());
+               }
+       }
+
+       @Test
+       public void testArtifactBuilder() throws Exception {
+               ArtifactBuilder bldr = Artifact.build();
+               bldr.withCreated(date1.getTime()).withCreatedDate(date1).withDescription(desc).withId(id1).withMetadata(meta)
+                               .withModifiedDate(date2).withName(name).withSize(size).withTypeCode(mtc).withVersion(version)
+                               .withUri(uri).withUser(user);
+               Artifact a = bldr.build();
+               Assert.assertNotNull(a);
+               Assert.assertEquals(date1, a.getCreated());
+               Assert.assertEquals(desc, a.getDescription());
+               Assert.assertEquals(id1, a.getArtifactId());
+               Assert.assertEquals(meta, a.getMetadata());
+               Assert.assertEquals(date2, a.getModified());
+               Assert.assertEquals(name, a.getName());
+               Assert.assertEquals(size, a.getSize());
+               Assert.assertEquals(mtc, a.getArtifactTypeCode());
+               Assert.assertEquals(version, a.getVersion());
+               Assert.assertEquals(uri, a.getUri());
+               Assert.assertEquals(user, a.getUserId());
+       }
+
+       @Test
+       public void testDocumentBuilder() throws Exception {
+               DocumentBuilder bldr = Document.build();
+               bldr.withCreated(date1.getTime()).withCreatedDate(date1).withId(id1).withModified(date2.getTime())
+                               .withModifiedDate(date2).withName(name).withSize(size).withUri(uri).withUser(user).withVersion(version);
+               Document d = bldr.build();
+               Assert.assertNotNull(d);
+               Assert.assertEquals(date1, d.getCreated());
+               Assert.assertEquals(id1, d.getDocumentId());
+               Assert.assertEquals(date2, d.getModified());
+               Assert.assertEquals(name, d.getName());
+               Assert.assertEquals(size, d.getSize());
+               Assert.assertEquals(uri, d.getUri());
+               Assert.assertEquals(user, d.getUserId());
+               Assert.assertEquals(version, d.getVersion());
+       }
+
+       @SuppressWarnings("deprecation")
+       @Test
+       public void testSolutionBuilder() throws Exception {
+               final Set<MLPTag> tags = null;
+               final MLPSolutionWeb theStats = null;
+               SolutionBuilder bldr = Solution.build();
+               bldr.withActive(active).withCreatedDate(date1).withDescription(desc).withId(id1).withMetadata(meta)
+                               .withModelTypeCode(mtc).withModifiedDate(date2).withName(name).withOrigin(origin).withSource(source)
+                               .withToolkitTypeCode(ttc).withUser(user);
+               bldr.withSource(theUpdater, source);
+               bldr.withTags(tags);
+               bldr.withUser(theUpdater, user);
+               bldr.withWebStats(theStats);
+               Solution s = bldr.build();
+               Assert.assertNotNull(s);
+               Assert.assertEquals(active, s.isActive());
+               Assert.assertEquals(date1, s.getCreated());
+               Assert.assertEquals(desc, s.getDescription());
+               Assert.assertEquals(id1, s.getSolutionId());
+               Assert.assertEquals(meta, s.getMetadata());
+               Assert.assertEquals(mtc, s.getModelTypeCode());
+               Assert.assertEquals(date2, s.getModified());
+               Assert.assertEquals(name, s.getName());
+               Assert.assertEquals(origin, s.getOrigin());
+               Assert.assertEquals(source, s.getSourceId());
+               Assert.assertEquals(ttc, s.getToolkitTypeCode());
+               Assert.assertEquals(user, s.getUserId());
+               Assert.assertNull(s.getTags());
+               Assert.assertNull(s.getWebStats());
+       }
+
+       @SuppressWarnings("deprecation")
+       @Test
+       public void testSolutionRevisionBuilder() throws Exception {
+               SolutionRevisionBuilder bldr = SolutionRevision.build();
+               bldr.forSolution(id1).withAccessTypeCode(atc).withCreatedDate(date1).withDescription(desc).withMetadata(meta)
+                               .withModifiedDate(date2).withOrigin(origin).withRevisionId(id2).withSource(source).withVersion(version)
+                               .withUser(user).withValidationStatusCode(vsc);
+               SolutionRevision r = bldr.build();
+               Assert.assertNotNull(r);
+               Assert.assertEquals(id1, r.getSolutionId());
+               Assert.assertEquals(atc, r.getAccessTypeCode());
+               Assert.assertEquals(date1, r.getCreated());
+               Assert.assertEquals(desc, r.getDescription());
+               Assert.assertEquals(meta, r.getMetadata());
+               Assert.assertEquals(date2, r.getModified());
+               Assert.assertEquals(origin, r.getOrigin());
+               Assert.assertEquals(id2, r.getRevisionId());
+               Assert.assertEquals(source, r.getSourceId());
+               Assert.assertEquals(version, r.getVersion());
+               Assert.assertEquals(user, r.getUserId());
+               Assert.assertEquals(vsc, r.getValidationStatusCode());
+       }
+
+}
diff --git a/gateway/src/test/java/org/acumos/federation/gateway/test/UtilsTest.java b/gateway/src/test/java/org/acumos/federation/gateway/test/UtilsTest.java
new file mode 100644 (file)
index 0000000..52d4783
--- /dev/null
@@ -0,0 +1,73 @@
+/*-
+ * ===============LICENSE_START=======================================================
+ * Acumos
+ * ===================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property & Tech Mahindra. All rights reserved.
+ * ===================================================================================
+ * This Acumos software file is distributed by AT&T and Tech Mahindra
+ * 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
+ *
+ * This file 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.acumos.federation.gateway.test;
+
+import java.lang.invoke.MethodHandles;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.acumos.federation.gateway.util.Utils;
+import org.junit.Assert;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class UtilsTest {
+       private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+       @Test
+       public void coverUtilMethods() throws Exception {
+               Utils utils = new Utils();
+               Assert.assertNotNull(utils);
+
+               Assert.assertTrue(Utils.isEmptyOrNullString(null));
+               Assert.assertFalse(Utils.isEmptyOrNullString("hello"));
+               
+               List<String> list = new ArrayList<>();
+               Assert.assertTrue(Utils.isEmptyList(list));
+               list.add("abc");
+               Assert.assertFalse(Utils.isEmptyList(list));
+
+               final String json = "{\"a\":\"b\"}";
+               Map<String,Object> map = Utils.jsonStringToMap(json);
+               Assert.assertFalse(map.isEmpty());
+               String s = Utils.mapToJsonString(map);
+               Assert.assertEquals(json, s);
+
+               try {
+                       Utils.jsonStringToMap("bogus");
+                       Assert.assertTrue(false);
+               } catch (Exception ex) {
+                       logger.info("jsonStringToMap failed as expected: {}", ex.toString());
+               }
+
+               try {
+                       map.clear();
+                       map.put("nonsense", new Object());
+                       Utils.mapToJsonString(map);
+                       Assert.assertTrue(false);
+               } catch (Exception ex) {
+                       logger.info("mapToJsonString failed as expected: {}", ex.toString());
+               }
+               
+       }
+
+}
diff --git a/gateway/src/test/resources/logback.xml b/gateway/src/test/resources/logback.xml
new file mode 100644 (file)
index 0000000..c80b6b8
--- /dev/null
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ===============LICENSE_START=======================================================
+  Acumos
+  ===================================================================================
+  Copyright (C) 2017 AT&T Intellectual Property & Tech Mahindra. All rights reserved.
+  ===================================================================================
+  This Acumos software file is distributed by AT&T and Tech Mahindra
+  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
+   
+  This file 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=========================================================
+  -->
+
+<configuration>
+
+       <!-- Basic logback configuration for the Common Data Service client
+               ONLY FOR DEV AND TEST - this file is not packaged with the jar. -->
+
+       <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
+               <!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder 
+                       by default -->
+               <encoder>
+                       <pattern>%d{&quot;yyyy-MM-dd'T'HH:mm:ss.SSSXXX&quot;, UTC} [%thread] %-5level %logger{36} - %msg%n
+                       </pattern>
+               </encoder>
+       </appender>
+
+       <root level="INFO">
+               <appender-ref ref="console" />
+       </root>
+
+       <!-- Apache HttpClient has verbose debug output; silence it -->
+       <logger name="org.apache.http" level="INFO" />
+
+       <!-- Spring client has verbose debug output; silence it -->
+       <logger name="org.springframework.web.client" level="INFO" />
+
+</configuration>