more functional tests and cleanup 71/571/1
authorSerban Jora <sj2381@att.com>
Thu, 18 Jan 2018 21:02:22 +0000 (16:02 -0500)
committerSerban Jora <sj2381@att.com>
Thu, 18 Jan 2018 21:03:27 +0000 (16:03 -0500)
Add mock based tests for federation task and gateway. Remove old CDS helpers. Minor cleanups.

Change-Id: I85234b4dd110b230aa187cbdbae617645dc5a924
Signed-off-by: Serban Jora <sj2381@att.com>
19 files changed:
gateway/src/main/java/org/acumos/federation/gateway/adapter/PeerGateway.java
gateway/src/main/java/org/acumos/federation/gateway/common/FederationDataClientConfiguration.java [deleted file]
gateway/src/main/java/org/acumos/federation/gateway/common/GatewayConfiguration.java
gateway/src/main/java/org/acumos/federation/gateway/service/impl/AbstractServiceImpl.java
gateway/src/main/java/org/acumos/federation/gateway/service/impl/CatalogServiceImpl.java
gateway/src/main/java/org/acumos/federation/gateway/service/impl/Clients.java
gateway/src/main/java/org/acumos/federation/gateway/service/impl/FederationDataClient.java [deleted file]
gateway/src/main/java/org/acumos/federation/gateway/service/impl/PeerServiceImpl.java
gateway/src/main/java/org/acumos/federation/gateway/service/impl/PeerSubscriptionServiceImpl.java
gateway/src/main/java/org/acumos/federation/gateway/task/PeerCommunicationTask.java
gateway/src/main/java/org/acumos/federation/gateway/task/PeerCommunicationTaskScheduler.java [moved from gateway/src/main/java/org/acumos/federation/gateway/controller/PeerCommunicationTaskScheduler.java with 98% similarity]
gateway/src/test/java/org/acumos/federation/gateway/test/ControllerTest.java [new file with mode: 0644]
gateway/src/test/java/org/acumos/federation/gateway/test/PeerGatewayTest.java
gateway/src/test/java/org/acumos/federation/gateway/test/TaskTest.java
gateway/src/test/resources/mockPeerSolutionRevisionArtifactsResponse.json [new file with mode: 0644]
gateway/src/test/resources/mockPeerSolutionRevisionsResponse.json [new file with mode: 0644]
gateway/src/test/resources/mockPeerSolutionsResponse.json [new file with mode: 0644]
gateway/src/test/resources/task-test-catalog.json [new file with mode: 0644]
gateway/src/test/resources/task-test-peers.json [new file with mode: 0644]

index c8c81ab..f9564d7 100644 (file)
@@ -153,33 +153,35 @@ public class PeerGateway {
                        
                        logger.info(EELFLoggerDelegate.debugLogger, "Received peer " + this.peer + " solutions: " + this.solutions);
 
-                       for (MLPSolution acumosSolution: this.solutions) {
+                       for (MLPSolution peerSolution: this.solutions) {
                                try {
                                        //Check if the Model already exists in the Local Acumos
-                                       MLPSolution mlpSolution  = null;
+                                       MLPSolution localSolution  = null;
                                        try {
-                                               mlpSolution = cdsClient.getSolution(acumosSolution.getSolutionId());
-                                       } catch (Exception e) {
-                                               logger.info(EELFLoggerDelegate.debugLogger, "Solution Id : " + acumosSolution.getSolutionId() + " does not exists locally, Adding it to local catalog ");
+                                               localSolution = cdsClient.getSolution(peerSolution.getSolutionId());
                                        }
-                                       
+                                       catch (Exception e) {
+                                               logger.info(EELFLoggerDelegate.debugLogger, "Solution Id : " + peerSolution.getSolutionId() + " does not exists locally, Adding it to local catalog ");
+                                       }
+                       
                                        //Verify if MLPSolution is not same
-                                       if(mlpSolution != null &&
-                                                isSameMLPSolution(acumosSolution, mlpSolution)) {
+                                       if(localSolution != null &&
+                                                isSameMLPSolution(peerSolution, localSolution)) {
                                                //if already exists locally then loop through next
-                                               mlpSolution = updateMLPSolution(acumosSolution, mlpSolution, cdsClient);
+                                               localSolution = updateMLPSolution(peerSolution, localSolution, cdsClient);
                                                
                                        } 
                                        else {
-                                               mlpSolution = createMLPSolution(acumosSolution, cdsClient);
+                                               localSolution = createMLPSolution(peerSolution, cdsClient);
                                        }
 
-                                       if (mlpSolution != null) {      
-                                               updateMLPSolution(mlpSolution, cdsClient);
+                                       if (localSolution != null) {    
+                                               updateMLPSolution(localSolution, cdsClient);
                                        }
                                }
                                catch (Exception x) {
-                                       logger.warn(EELFLoggerDelegate.debugLogger, "Mapping of acumos solution failed for: " + acumosSolution, x);
+                                       x.printStackTrace();
+                                       logger.warn(EELFLoggerDelegate.debugLogger, "Mapping of acumos solution failed for: " + peerSolution, x);
                                }
                        }
                }
@@ -367,6 +369,13 @@ public class PeerGateway {
                                throw x;
                        }
 
+                       //this should not happen as any solution should have at least one
+                       //revision (but that's an assumption on how on-boarding works)
+                       if (peerRevisions == null || peerRevisions.size() == 0) {
+                               logger.warn(EELFLoggerDelegate.debugLogger, "No revisions were retrieved");
+                               return;
+                       } 
+
                        //check if we have locally the latest revision available on the peer
                        //TODO: this is just one possible policy regarding the handling of
                        //such a mismatch
@@ -434,7 +443,7 @@ public class PeerGateway {
                                                        localArtifact = updateMLPArtifact(peerArtifact, localArtifact, cdsClient);
                                                }
                                                else {
-                                                       //mark the fact that loca artifact does not need an update
+                                                       //mark the fact that local artifact does not need an update
                                                        localArtifact = null;
                                                }
                                        }
@@ -443,11 +452,19 @@ public class PeerGateway {
 
                                        if (localArtifact == null) {
                                                //the artifact does not need an update
+                                               logger.info(EELFLoggerDelegate.debugLogger, "Artifact does not need an update");
+                                               continue;
+                                       }
+
+                                       if (localArtifact.getUri() == null) {
+                                               //the peer does not want us to gain access to the artifact content      
+                                               logger.info(EELFLoggerDelegate.debugLogger, "Artifact uri not available");
                                                continue;
                                        }
 
-                                       //artifacts file download and push it to nexus: we continue here 
-                                       //as we persisted the peer URI 
+                                       //TODO: we are trying to access the artifact by its identifier which
+                                       //is fine in the common case but the uri specified in the artifact
+                                       //data is a more flexible approach.
                                        Resource artifactContent = null;
                                        try {
                                                artifactContent = fedClient.downloadArtifact(peerArtifact.getArtifactId());
diff --git a/gateway/src/main/java/org/acumos/federation/gateway/common/FederationDataClientConfiguration.java b/gateway/src/main/java/org/acumos/federation/gateway/common/FederationDataClientConfiguration.java
deleted file mode 100644 (file)
index f0d953e..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*-
- * ===============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.common;
-
-import org.apache.http.client.HttpClient;
-
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Scope;
-import org.springframework.beans.factory.config.ConfigurableBeanFactory;
-
-
-@Configuration
-//@PropertySource("classpath:configprops.properties")
-@ConfigurationProperties(prefix = "cdms.client")
-public class FederationDataClientConfiguration extends HttpClientConfiguration {
-
-
-       @Bean
-       @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
-       public HttpClient federationDataClient() {
-               return buildClient();
-       }
-}
-
index 2abe105..0489974 100644 (file)
@@ -26,8 +26,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
 import org.springframework.context.annotation.Configuration;
 
 @Configuration
-@EnableConfigurationProperties({FederationClientConfiguration.class,
-                               FederationDataClientConfiguration.class})
+@EnableConfigurationProperties({FederationClientConfiguration.class})
 public class GatewayConfiguration {
 
 }
index c17cf45..47469bc 100644 (file)
@@ -42,7 +42,4 @@ public abstract class AbstractServiceImpl {
                return clients.getClient();
        }
        
-       public FederationDataClient getCommonDataClient() {
-               return clients.getCommonDataClient();
-       }
 }
index ec2e2a1..cecce8e 100644 (file)
@@ -80,7 +80,7 @@ public class CatalogServiceImpl
                baseSelector.put("active", true); //Fetch all active solutions
                baseSelector.put("accessTypeCode", AccessTypeCode.PB.toString()); // Fetch allowed only for Public models
                baseSelector.put("validationStatusCode", ValidationStatusCode.PS.toString()); // Validation status should be Passed locally
-//             baseSelector.put("provider", env.getProperty("federated.instance.name"));
+//             baseSelector.put("source", "");
        
        }
 
@@ -149,9 +149,9 @@ public class CatalogServiceImpl
                String theSolutionId, ServiceContext theContext) {
 
                log.debug(EELFLoggerDelegate.debugLogger, "getSolutionRevisions");
-               ICommonDataServiceRestClient dataServiceRestClient = getClient();
+               ICommonDataServiceRestClient cdsClient = getClient();
                List<MLPSolutionRevision> mlpSolutionRevisions =
-                       dataServiceRestClient.getSolutionRevisions(theSolutionId);
+                       cdsClient.getSolutionRevisions(theSolutionId);
                return mlpSolutionRevisions;
        }
 
@@ -160,9 +160,9 @@ public class CatalogServiceImpl
                String theSolutionId, String theRevisionId, ServiceContext theContext) {
 
                log.debug(EELFLoggerDelegate.debugLogger, "getSolutionRevision");
-               ICommonDataServiceRestClient dataServiceRestClient = getClient();
+               ICommonDataServiceRestClient cdsClient = getClient();
                MLPSolutionRevision mlpSolutionRevision =
-                       dataServiceRestClient.getSolutionRevision(theSolutionId, theRevisionId);
+                       cdsClient.getSolutionRevision(theSolutionId, theRevisionId);
                return mlpSolutionRevision;
        }
 
@@ -171,12 +171,8 @@ public class CatalogServiceImpl
                String theSolutionId, String theRevisionId, ServiceContext theContext) {
                
                log.debug(EELFLoggerDelegate.debugLogger, "getSolutionRevisionArtifacts");
-               List<MLPArtifact> mlpArtifacts = new ArrayList<>();
-               FederationDataClient commonDataClient = getCommonDataClient();
-               Iterable<MLPArtifact> artifacts = commonDataClient.getSolutionRevisionArtifacts(theSolutionId, theRevisionId);
-               for (MLPArtifact mlpArtifact : artifacts) {
-                       mlpArtifacts.add(mlpArtifact);
-               }
+               ICommonDataServiceRestClient cdsClient = getClient();
+               List<MLPArtifact> mlpArtifacts = cdsClient.getSolutionRevisionArtifacts(theSolutionId, theRevisionId);
                return mlpArtifacts;
        }
 
index 652a151..b81ceb5 100644 (file)
@@ -37,7 +37,6 @@ import org.acumos.cds.client.ICommonDataServiceRestClient;
 import org.acumos.nexus.client.NexusArtifactClient;
 import org.acumos.nexus.client.RepositoryLocation;
 
-
 /**
  * Unique entry point for building clients: peer access clients, cds clients
  */
@@ -62,13 +61,6 @@ public class Clients implements ApplicationContextAware {
                                                                env.getProperty("cdms.client.password"));
        }
        
-       /** Federation oriented CDS layer */    
-       public FederationDataClient getCommonDataClient() {
-    return new FederationDataClient(
-                                                                       this.env.getProperty("cdms.client.url"),
-                  (HttpClient)this.appCtx.getBean("federationDataClient"));
-       }
-
        public FederationClient getFederationClient(String thePeerURI) {
     return new FederationClient(
                                                                        thePeerURI,
@@ -76,15 +68,14 @@ public class Clients implements ApplicationContextAware {
        }
 
        public NexusArtifactClient getNexusClient() {
-
                RepositoryLocation repositoryLocation = new RepositoryLocation();
+      
                repositoryLocation.setId("1");
-               repositoryLocation.setUrl(this.env.getProperty("nexus.url"));
-               repositoryLocation.setUsername(this.env.getProperty("nexus.username"));
-               repositoryLocation.setPassword(this.env.getProperty("nexus.password"));
-               repositoryLocation.setProxy(this.env.getProperty("nexus.proxy"));
-                       
-               // if you need a proxy to access the Nexus
+               repositoryLocation.setUrl(env.getProperty("nexus.url"));
+               repositoryLocation.setUsername(env.getProperty("nexus.username"));
+               repositoryLocation.setPassword(env.getProperty("nexus.password"));
+               repositoryLocation.setProxy(env.getProperty("nexus.proxy"));
+
                return new NexusArtifactClient(repositoryLocation);
        }
 }
diff --git a/gateway/src/main/java/org/acumos/federation/gateway/service/impl/FederationDataClient.java b/gateway/src/main/java/org/acumos/federation/gateway/service/impl/FederationDataClient.java
deleted file mode 100644 (file)
index 4dc25b2..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-/*-
- * ===============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.service.impl;
-
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URL;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.http.client.HttpClient;
-
-import org.acumos.federation.gateway.common.JsonResponse;
-import org.acumos.federation.gateway.config.EELFLoggerDelegate;
-import org.springframework.core.ParameterizedTypeReference;
-import org.springframework.http.HttpMethod;
-import org.springframework.http.ResponseEntity;
-import org.springframework.web.client.HttpStatusCodeException;
-import org.springframework.web.client.RestTemplate;
-import org.springframework.boot.web.client.RestTemplateBuilder;
-import org.springframework.web.util.UriComponentsBuilder;
-
-import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
-
-import org.springframework.beans.factory.annotation.Autowired;
-
-import org.acumos.cds.CCDSConstants;
-import org.acumos.cds.client.HttpComponentsClientHttpRequestFactoryBasicAuth;
-import org.acumos.cds.domain.MLPArtifact;
-import org.acumos.cds.domain.MLPPeerSubscription;
-import org.acumos.cds.domain.MLPSolution;
-import org.acumos.cds.domain.MLPSolutionRevision;
-import org.acumos.cds.domain.MLPUser;
-import org.acumos.cds.transport.LoginTransport;
-import org.acumos.cds.transport.RestPageRequest;
-import org.acumos.cds.transport.RestPageResponse;
-
-
-/**
- * 
- * 
- *
- * Enhance the CDS API with federation specific api
- */
-public class FederationDataClient extends AbstractClient {
-
-
-       /**
-        */
-       public FederationDataClient(String theTarget,
-                                                                                                       HttpClient theClient) {
-               super(theTarget, theClient);
-       }
-
-
-       public List<MLPPeerSubscription> getPeerSubscriptions(String peerId) throws HttpStatusCodeException {
-               URI uri = buildUri(new String[] { CCDSConstants.PEER_PATH, peerId, CCDSConstants.SUBSCRIPTION_PATH }, null,
-                               null);
-
-               logger.info(EELFLoggerDelegate.debugLogger, "getPeerSubscriptions: uri " + uri);
-               /*ResponseEntity<RestPageResponse<MLPPeerSubscription>> response =
-                       this.restTemplate.exchange(
-                               uri, HttpMethod.GET, null, new ParameterizedTypeReference<RestPageResponse<MLPPeerSubscription>>() {});*/
-               ResponseEntity<List<MLPPeerSubscription>> response = restTemplate.exchange(uri, HttpMethod.GET, null,
-                               new ParameterizedTypeReference<List<MLPPeerSubscription>>() {
-                               });
-               return response.getBody();
-       }
-
-       public Iterable<MLPArtifact> getSolutionRevisionArtifacts(String solutionId, String revisionId)
-                       throws HttpStatusCodeException {
-               URI uri = buildUri(new String[] { CCDSConstants.SOLUTION_PATH, solutionId, CCDSConstants.REVISION_PATH,
-                               revisionId, CCDSConstants.ARTIFACT_PATH }, null, null);
-               logger.debug("getSolutionRevisionArtifacts: uri {}", uri);
-               ResponseEntity<Iterable<MLPArtifact>> response = 
-                       this.restTemplate.exchange(
-                               uri, HttpMethod.GET, null, new ParameterizedTypeReference<Iterable<MLPArtifact>>() {});
-               return response.getBody();
-       }
-
-}
index edd8394..2a12b83 100644 (file)
@@ -59,8 +59,8 @@ public class PeerServiceImpl extends AbstractServiceImpl implements PeerService
        @Override
        public List<MLPPeer> getPeers() {
                log.debug(EELFLoggerDelegate.debugLogger, "getPeers");
-               ICommonDataServiceRestClient dataServiceRestClient = getClient();
-               List<MLPPeer> mlpPeers = dataServiceRestClient.searchPeers(Collections.EMPTY_MAP, false);
+               ICommonDataServiceRestClient cdsClient = getClient();
+               List<MLPPeer> mlpPeers = cdsClient.searchPeers(Collections.EMPTY_MAP,false);
                if(mlpPeers !=null) {
                        log.debug(EELFLoggerDelegate.debugLogger, "getPeers size:{}", mlpPeers.size());
                }
@@ -76,11 +76,11 @@ public class PeerServiceImpl extends AbstractServiceImpl implements PeerService
        @Override
        public List<MLPPeer> getPeer(String subjectName) {
                log.debug(EELFLoggerDelegate.debugLogger, "savePeer");
-               ICommonDataServiceRestClient dataServiceRestClient = getClient();
+               ICommonDataServiceRestClient cdsClient = getClient();
                Map<String, Object> queryParameters = new HashMap<String, Object>();
                queryParameters.put("subjectName", subjectName); //I believe it should be unique
                List<MLPPeer> existingMLPPeers = null;
-               existingMLPPeers = dataServiceRestClient.searchPeers(queryParameters, false);
+               existingMLPPeers = cdsClient.searchPeers(queryParameters, false);
                if(existingMLPPeers != null && existingMLPPeers.size() > 0) {
                        log.debug(EELFLoggerDelegate.debugLogger, "getPeer size:{}", existingMLPPeers.size());
                }
@@ -90,8 +90,8 @@ public class PeerServiceImpl extends AbstractServiceImpl implements PeerService
        @Override
        public MLPPeer getOnePeer(String peerId) {
                log.debug(EELFLoggerDelegate.debugLogger, "getPeer: {}", peerId);
-               ICommonDataServiceRestClient dataServiceRestClient = getClient();
-               MLPPeer mlpPeer = dataServiceRestClient.getPeer(peerId);
+               ICommonDataServiceRestClient cdsClient = getClient();
+               MLPPeer mlpPeer = cdsClient.getPeer(peerId);
                if(mlpPeer !=null) {
                        log.error(EELFLoggerDelegate.debugLogger, "getOnePeer: {}", mlpPeer.toString());
                }
@@ -101,7 +101,7 @@ public class PeerServiceImpl extends AbstractServiceImpl implements PeerService
        @Override
        public MLPPeer savePeer(MLPPeer mlpPeer) {
                log.debug(EELFLoggerDelegate.debugLogger, "savePeer");
-               ICommonDataServiceRestClient dataServiceRestClient = getClient();
+               ICommonDataServiceRestClient cdsClient = getClient();
                Map<String, Object> queryParameters = new HashMap<String, Object>();
                queryParameters.put("subjectName", mlpPeer.getSubjectName()); //I believe it should be unique
                boolean isPeerExists = false;
@@ -119,7 +119,7 @@ public class PeerServiceImpl extends AbstractServiceImpl implements PeerService
                }
                
                if(!isPeerExists) {
-                       mlpPeerCreated = dataServiceRestClient.createPeer(mlpPeer);
+                       mlpPeerCreated = cdsClient.createPeer(mlpPeer);
                        if(mlpPeerCreated !=null) {
                                log.debug(EELFLoggerDelegate.debugLogger, "savePeer :{}", mlpPeer.toString());
                        }
@@ -130,13 +130,13 @@ public class PeerServiceImpl extends AbstractServiceImpl implements PeerService
        @Override
        public boolean updatePeer(MLPPeer mlpPeer) {
                log.debug(EELFLoggerDelegate.debugLogger, "updatePeer");
-               ICommonDataServiceRestClient dataServiceRestClient = getClient();
+               ICommonDataServiceRestClient cdsClient = getClient();
                boolean isUpdatedSuccessfully = false;
                List<MLPPeer> existingMLPPeers = null;
                try{
                        existingMLPPeers = getPeer(mlpPeer.getSubjectName());
                        if(existingMLPPeers != null && existingMLPPeers.size() > 0) {
-                               dataServiceRestClient.updatePeer(mlpPeer);
+                               cdsClient.updatePeer(mlpPeer);
                                isUpdatedSuccessfully = true;
                        }
                } catch (Exception e) {
@@ -150,9 +150,9 @@ public class PeerServiceImpl extends AbstractServiceImpl implements PeerService
        public boolean deletePeer(MLPPeer mlpPeer) {
                log.debug(EELFLoggerDelegate.debugLogger, "deletePeer");
                boolean isDeletedSuccessfully = false;
-               ICommonDataServiceRestClient dataServiceRestClient = getClient();
+               ICommonDataServiceRestClient cdsClient = getClient();
                try {
-                       dataServiceRestClient.deletePeer(mlpPeer.getPeerId());
+                       cdsClient.deletePeer(mlpPeer.getPeerId());
                        isDeletedSuccessfully = true;
                } catch (Exception e) {
                        isDeletedSuccessfully = false;
index 05b474c..a2b5b51 100644 (file)
@@ -62,21 +62,22 @@ public class PeerSubscriptionServiceImpl extends AbstractServiceImpl implements
                log.debug(EELFLoggerDelegate.debugLogger, "getPeerSubscriptions:{}", peerId);
                List<MLPPeerSubscription> mlpPeerSubscriptions  = null;
                //Temporary Fix as COmmon Data Service does not handle proper Serialization
-               mlpPeerSubscriptions =  getCommonDataClient().getPeerSubscriptions(peerId);
+               mlpPeerSubscriptions =  getClient().getPeerSubscriptions(peerId);
+/*
                if(!Utils.isEmptyList(mlpPeerSubscriptions)) {
                        //mlpPeerSubscriptions = mlpPeerSubscriptionPaged.getContent();
                        mlpPeerSubscriptions = mlpPeerSubscriptions.stream().filter(mlpPeerSubscription -> (mlpPeerSubscription.getPeerId().contains(peerId))).collect(Collectors.toList());
-                       log.debug(EELFLoggerDelegate.debugLogger, "getPeers size:{}", mlpPeerSubscriptions.size());
-               }
+               }*/
+               log.debug(EELFLoggerDelegate.debugLogger, "getPeers size:{}", mlpPeerSubscriptions.size());
                return mlpPeerSubscriptions;
        }
 
        @Override
        public MLPPeerSubscription getPeerSubscription(Long subId) {
                log.debug(EELFLoggerDelegate.debugLogger, "getPeerSubscription:{}", subId);
-               ICommonDataServiceRestClient dataServiceRestClient = getClient();
+               ICommonDataServiceRestClient cdsClient = getClient();
                MLPPeerSubscription existingMLPPeerSubscription = null;
-               existingMLPPeerSubscription = dataServiceRestClient.getPeerSubscription(subId);
+               existingMLPPeerSubscription = cdsClient.getPeerSubscription(subId);
                if(existingMLPPeerSubscription != null) {
                        log.debug(EELFLoggerDelegate.debugLogger, "getPeerSubscription :{}", existingMLPPeerSubscription.toString());
                }
@@ -86,9 +87,9 @@ public class PeerSubscriptionServiceImpl extends AbstractServiceImpl implements
        @Override
        public MLPPeerSubscription savePeerSubscription(MLPPeerSubscription mlpPeerSubscription) {
                log.debug(EELFLoggerDelegate.debugLogger, "savePeerSubscription");
-               ICommonDataServiceRestClient dataServiceRestClient = getClient();
+               ICommonDataServiceRestClient cdsClient = getClient();
                MLPPeerSubscription mlPeerSubscriptionCreated = null;
-               mlPeerSubscriptionCreated = dataServiceRestClient.createPeerSubscription(mlpPeerSubscription);
+               mlPeerSubscriptionCreated = cdsClient.createPeerSubscription(mlpPeerSubscription);
                if(mlPeerSubscriptionCreated !=null) {
                        log.debug(EELFLoggerDelegate.debugLogger, "savePeerSubscription :{}", mlPeerSubscriptionCreated.toString());
                }
@@ -98,14 +99,14 @@ public class PeerSubscriptionServiceImpl extends AbstractServiceImpl implements
        @Override
        public boolean updatePeerSubscription(MLPPeerSubscription mlpPeerSubscription) {
                log.debug(EELFLoggerDelegate.debugLogger, "updatePeerSubscription");
-               ICommonDataServiceRestClient dataServiceRestClient = getClient();
+               ICommonDataServiceRestClient cdsClient = getClient();
                boolean isUpdatedSuccessfully = false;
                MLPPeerSubscription existingMLPPeerSubscription = null;
                try{
                        existingMLPPeerSubscription = getPeerSubscription(mlpPeerSubscription.getSubId());
                        if(existingMLPPeerSubscription != null) {
                                if(mlpPeerSubscription.getPeerId().equalsIgnoreCase(existingMLPPeerSubscription.getPeerId()))
-                                       dataServiceRestClient.updatePeerSubscription(mlpPeerSubscription);
+                                       cdsClient.updatePeerSubscription(mlpPeerSubscription);
                                        isUpdatedSuccessfully = true;
                        }
                } catch (Exception e) {
@@ -119,9 +120,9 @@ public class PeerSubscriptionServiceImpl extends AbstractServiceImpl implements
        public boolean deletePeerSubscription(MLPPeerSubscription mlpPeerSubscription) {
                log.debug(EELFLoggerDelegate.debugLogger, "deletePeerSubscription");
                boolean isDeletedSuccessfully = false;
-               ICommonDataServiceRestClient dataServiceRestClient = getClient();
+               ICommonDataServiceRestClient cdsClient = getClient();
                try {
-                       dataServiceRestClient.deletePeerSubscription(mlpPeerSubscription.getSubId());
+                       cdsClient.deletePeerSubscription(mlpPeerSubscription.getSubId());
                        isDeletedSuccessfully = true;
                } catch (Exception e) {
                        isDeletedSuccessfully = false;
index c44bc47..1faa3af 100644 (file)
@@ -95,7 +95,6 @@ public class PeerCommunicationTask implements Runnable {
                try {
                        logger.info(EELFLoggerDelegate.debugLogger, "Peer task: " + mlpPeer);
                
-                               
       logger.info(EELFLoggerDelegate.debugLogger, "Peer task: invoking getSolutions from Remote instance " + mlpPeer.getApiUrl());
       FederationClient fedClient =
           clients.getFederationClient(this.mlpPeer.getApiUrl());      
@@ -117,7 +116,6 @@ public class PeerCommunicationTask implements Runnable {
                        }
     }
                catch (Exception x) {
-                       // TODO: handle exception
                        logger.info(EELFLoggerDelegate.errorLogger, "Peer task for " + this.mlpPeer + " failed", x);
                }
     // System.out.println(mlpPeer.getName() + " : Runnable Task with " + message + " on thread " + Thread.currentThread().getName() + ", id:"+ Thread.currentThread().getId());
@@ -18,7 +18,7 @@
  * ===============LICENSE_END=========================================================
  */
 
-package org.acumos.federation.gateway.controller;
+package org.acumos.federation.gateway.task;
 
 import java.util.Calendar;
 
@@ -134,7 +134,7 @@ public class PeerCommunicationTaskScheduler implements      ApplicationContextAware
                                         );
        }
 
-       @Scheduled(fixedRateString = "${peer.jobchecker.interval:400}000")
+       @Scheduled(initialDelay = 1000,fixedRateString = "${peer.jobchecker.interval:400}000")
        public void checkPeerJobs() {
 
                //Get the List of MLP Peers
diff --git a/gateway/src/test/java/org/acumos/federation/gateway/test/ControllerTest.java b/gateway/src/test/java/org/acumos/federation/gateway/test/ControllerTest.java
new file mode 100644 (file)
index 0000000..9680cdf
--- /dev/null
@@ -0,0 +1,237 @@
+/*-
+ * ===============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.util.List;
+import java.util.Scanner;
+
+import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat; 
+
+import org.junit.FixMethodOrder;
+import org.junit.runners.MethodSorters;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+import org.springframework.boot.test.web.client.TestRestTemplate;
+
+import org.springframework.http.HttpMethod;
+import org.springframework.http.MediaType;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.ResponseEntity;
+import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
+import org.springframework.core.ParameterizedTypeReference;
+
+import org.apache.http.client.HttpClient;
+
+/* this is not good for unit testing .. */
+import org.acumos.federation.gateway.common.JsonResponse;
+import org.acumos.federation.gateway.common.HttpClientConfigurationBuilder;
+import static org.acumos.federation.gateway.common.HttpClientConfigurationBuilder.SSLBuilder;
+
+import org.acumos.cds.domain.MLPPeer;
+import org.acumos.cds.domain.MLPSolution;
+import org.acumos.cds.domain.MLPSolutionRevision;
+import org.acumos.cds.domain.MLPArtifact;
+
+
+
+/**
+ */
+
+//@RunWith(SpringJUnit4ClassRunner.class)
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = org.acumos.federation.gateway.Application.class,
+                                                               webEnvironment = WebEnvironment.RANDOM_PORT,
+                                                               properties = {
+                                                                       "federation.instance=adapter",
+                                                                       "federation.instance.name=ghost",
+                                                                       "peersLocal.source=classpath:/test-peers.json",
+                                                                       "catalogLocal.source=classpath:/test-catalog.json",
+                                                                       "server.ssl.key-store=classpath:acumosa.pkcs12",
+                                                                       "server.ssl.key-store-password=acumosa",
+                                                                       "server.ssl.key-store-type=PKCS12",
+                                                                       "server.ssl.key-password = acumosa",
+                                                                       "server.ssl.trust-store=classpath:acumosTrustStore.jks",
+                                                                       "server.ssl.trust-store-password=acumos",
+                                                                       "server.ssl.client-auth=need"
+                                                               })
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class ControllerTest {
+
+       @Autowired
+       private TestRestTemplate restTemplate;
+
+       @Test
+       public void testSolutions() {
+
+    ((HttpComponentsClientHttpRequestFactory)
+                       this.restTemplate.getRestTemplate().getRequestFactory())
+                               .setHttpClient(prepareHttpClient());
+               
+               ResponseEntity<JsonResponse<List<MLPSolution>>> response =
+                       this.restTemplate.exchange("/solutions", HttpMethod.GET, prepareRequest(), new ParameterizedTypeReference<JsonResponse<List<MLPSolution>>>() {});
+               
+               if (response != null)   {
+                       System.out.println("testSolutions: " + response.getBody());
+                       System.out.println("testSolutions: " + response);
+               }
+               
+               assertTrue(response != null);
+               assertTrue(response.getStatusCodeValue() == 200);
+               assertTrue(response.getBody().getResponseBody().size() == 1);
+       }
+
+
+       @Test
+       public void testSolutionSuccess() {
+
+    ((HttpComponentsClientHttpRequestFactory)
+                       this.restTemplate.getRestTemplate().getRequestFactory())
+                               .setHttpClient(prepareHttpClient());
+
+               ResponseEntity<JsonResponse<MLPSolution>> response =
+                       this.restTemplate.exchange("/solutions/00000000-0000-0000-0000-000000000000", HttpMethod.GET, prepareRequest(), new ParameterizedTypeReference<JsonResponse<MLPSolution>>() {} );
+       
+               if (response != null)   {
+                       System.out.println("testSolution: " + response.getBody());
+                       System.out.println("testSolution: " + response);
+               }
+
+               assertTrue(response != null);
+               assertTrue(response.getStatusCodeValue() == 200);
+               assertTrue(response.getBody().getResponseBody().getModelTypeCode().equals("CL")); //no errors
+       }
+
+       @Test
+       public void testSolutionRevisionsSuccess() {
+    
+               ((HttpComponentsClientHttpRequestFactory)
+                       this.restTemplate.getRestTemplate().getRequestFactory())
+                               .setHttpClient(prepareHttpClient());
+
+               ResponseEntity<JsonResponse<List<MLPSolutionRevision>>> response =
+                       this.restTemplate.exchange("/solutions/00000000-0000-0000-0000-000000000000/revisions", HttpMethod.GET, prepareRequest(), new ParameterizedTypeReference<JsonResponse<List<MLPSolutionRevision>>>() {});
+               
+               if (response != null)   {
+                       System.out.println("testSolutionRevisions: " + response.getBody());
+                       System.out.println("testSolutionRevisions: " + response);
+               }
+
+               assertTrue(response != null);
+               assertTrue(response.getStatusCodeValue() == 200);
+               assertTrue(response.getBody().getResponseBody().size() == 1); //no errors
+       }
+
+       @Test
+       public void testSolutionRevisionSuccess() {
+
+    ((HttpComponentsClientHttpRequestFactory)
+                       this.restTemplate.getRestTemplate().getRequestFactory())
+                               .setHttpClient(prepareHttpClient());
+
+               ResponseEntity<JsonResponse<MLPSolution>> response =
+                       this.restTemplate.exchange("/solutions/00000000-0000-0000-0000-000000000000/revisions/01010101-0101-0101-0101-010101010101", HttpMethod.GET, prepareRequest(), new ParameterizedTypeReference<JsonResponse<MLPSolution>>() {} );
+       
+               if (response != null)   {
+                       System.out.println("testSolution: " + response.getBody());
+                       System.out.println("testSolution: " + response);
+               }
+
+               assertTrue(response != null);
+               assertTrue(response.getStatusCodeValue() == 200);
+               assertTrue(response.getBody().getResponseBody().getOwnerId().equals("admin")); //no errors
+       }
+
+       @Test
+       public void testSolutionRevisionArtifactsSuccess() {
+    
+               ((HttpComponentsClientHttpRequestFactory)
+                       this.restTemplate.getRestTemplate().getRequestFactory())
+                               .setHttpClient(prepareHttpClient());
+
+               ResponseEntity<JsonResponse<List<MLPArtifact>>> response =
+                       this.restTemplate.exchange("/solutions/00000000-0000-0000-0000-000000000000/revisions/01010101-0101-0101-0101-010101010101/artifacts", HttpMethod.GET, prepareRequest(), new ParameterizedTypeReference<JsonResponse<List<MLPArtifact>>>() {});
+               
+               if (response != null)   {
+                       System.out.println("testSolutionRevisionsArtifacts: " + response.getBody());
+                       System.out.println("testSolutionRevisionsArtifacts: " + response);
+               }
+
+               assertTrue(response != null);
+               assertTrue(response.getStatusCodeValue() == 200);
+               assertTrue(response.getBody().getResponseBody().size() == 1); //no errors
+       }
+
+       @Test
+       public void testPeersForbidden() {
+
+    ((HttpComponentsClientHttpRequestFactory)
+                       this.restTemplate.getRestTemplate().getRequestFactory())
+                               .setHttpClient(prepareHttpClient());
+
+               ResponseEntity<JsonResponse<List<MLPPeer>>> response =
+                       this.restTemplate.exchange("/peers", HttpMethod.GET, prepareRequest(), new ParameterizedTypeReference<JsonResponse<List<MLPPeer>>>() {} );
+       
+               if (response != null)   {
+                       System.out.println("testPeers: " + response.getBody());
+                       System.out.println("testPeers: " + response);
+               }
+
+               assertTrue(response.getStatusCodeValue() == 403);
+       }
+
+       private HttpEntity prepareRequest(String theResourceName) {
+               String content = new Scanner(
+                                                                          Thread.currentThread().getContextClassLoader().getResourceAsStream(theResourceName), "UTF-8")
+                                                                                       .useDelimiter("\\Z").next();
+
+               HttpHeaders headers = new HttpHeaders();
+               headers.setContentType(MediaType.APPLICATION_JSON);
+               return new HttpEntity<String>(content, headers);
+       }
+       
+       private HttpEntity prepareRequest() {
+               HttpHeaders headers = new HttpHeaders();
+               headers.setContentType(MediaType.APPLICATION_JSON);
+               return new HttpEntity<String>(headers);
+       }
+
+       private HttpClient prepareHttpClient() {
+               return new HttpClientConfigurationBuilder()
+                                                               .withSSL(new SSLBuilder()
+                                                                                                                       .withKeyStore("classpath:/acumosb.pkcs12")
+                                                                                                                       .withKeyStorePassword("acumosb")
+                                                                                                                       //.withKeyPassword("acumosb")
+                                                                                                                       .withTrustStore("classpath:/acumosTrustStore.jks")
+                                                                                                                       .withTrustStoreType("JKS")
+                                                                                                                       .withTrustStorePassword("acumos")
+                                                                                                                       .build())
+                                                               .buildConfig()
+                                                               .buildClient();
+       }
+}
+
index cafbbaf..cd114ee 100644 (file)
  */
 package org.acumos.federation.gateway.test;
 
+import java.io.InputStream;
+
+import java.util.Map;
 import java.util.List;
 import java.util.Scanner;
+import java.util.Collections;
+
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.CountDownLatch;
 
+import org.junit.Before;
 import static org.junit.Assert.assertTrue;
 import static org.assertj.core.api.Assertions.assertThat; 
 
@@ -32,11 +40,20 @@ import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
+import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.SpringRunner;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 import org.springframework.test.context.web.WebAppConfiguration;
 import org.springframework.boot.test.web.client.TestRestTemplate;
 
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.event.EventListener;
+import org.springframework.context.annotation.Bean;
+
+import org.springframework.boot.test.mock.mockito.MockBean;
+
 import org.springframework.http.HttpMethod;
 import org.springframework.http.MediaType;
 import org.springframework.http.HttpHeaders;
@@ -44,19 +61,46 @@ import org.springframework.http.HttpEntity;
 import org.springframework.http.ResponseEntity;
 import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
 import org.springframework.core.ParameterizedTypeReference;
-
+import org.springframework.core.io.ClassPathResource;
+
+import static org.mockito.Mockito.*;
+import static org.mockito.Matchers.*;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.mockito.stubbing.Answer;
+import org.mockito.invocation.InvocationOnMock;
+
+import org.apache.http.ProtocolVersion;
+import org.apache.http.HttpHost;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
 import org.apache.http.client.HttpClient;
+import org.apache.http.client.ResponseHandler;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.message.BasicHttpResponse;
+import org.apache.http.message.BasicStatusLine;
+import org.apache.http.entity.InputStreamEntity;
+import org.apache.http.entity.ByteArrayEntity;
+import org.apache.http.entity.ContentType;
 
 /* this is not good for unit testing .. */
 import org.acumos.federation.gateway.common.JsonResponse;
 import org.acumos.federation.gateway.common.HttpClientConfigurationBuilder;
+import org.acumos.federation.gateway.event.PeerSubscriptionEvent;
+import org.acumos.federation.gateway.service.impl.Clients;
+import org.acumos.federation.gateway.service.impl.FederationClient;
 import static org.acumos.federation.gateway.common.HttpClientConfigurationBuilder.SSLBuilder;
 
 import org.acumos.cds.domain.MLPPeer;
+import org.acumos.cds.domain.MLPPeerSubscription;
 import org.acumos.cds.domain.MLPSolution;
 import org.acumos.cds.domain.MLPSolutionRevision;
 import org.acumos.cds.domain.MLPArtifact;
+import org.acumos.cds.client.ICommonDataServiceRestClient;
 
+import org.acumos.nexus.client.NexusArtifactClient;
+import org.acumos.nexus.client.data.UploadArtifactInfo;
 
 
 /**
@@ -67,10 +111,9 @@ import org.acumos.cds.domain.MLPArtifact;
 @SpringBootTest(classes = org.acumos.federation.gateway.Application.class,
                                                                webEnvironment = WebEnvironment.RANDOM_PORT,
                                                                properties = {
-                                                                       "federation.instance=adapter",
-                                                                       "federation.instance.name=Ghost",
-                                                                       "peersLocal.source=classpath:/test-peers.json",
-                                                                       "catalogLocal.source=classpath:/test-catalog.json",
+                                                                       "federation.instance=gateway",
+                                                                       "federation.instance.name=test",
+                                                                       "federation.operator=admin",
                                                                        "server.ssl.key-store=classpath:acumosa.pkcs12",
                                                                        "server.ssl.key-store-password=acumosa",
                                                                        "server.ssl.key-store-type=PKCS12",
@@ -78,160 +121,322 @@ import org.acumos.cds.domain.MLPArtifact;
                                                                        "server.ssl.trust-store=classpath:acumosTrustStore.jks",
                                                                        "server.ssl.trust-store-password=acumos",
                                                                        "server.ssl.client-auth=need"
+                                                                       //no actual cds info needed as we mock the cds client
                                                                })
+@ContextConfiguration(classes = {TaskTest.TaskTestConfiguration.class})
 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
 public class PeerGatewayTest {
 
-       @Autowired
-       private TestRestTemplate restTemplate;
+       @Mock
+       private ICommonDataServiceRestClient cdsClient;
 
-       @Test
-       public void testSolutions() {
-
-    ((HttpComponentsClientHttpRequestFactory)
-                       this.restTemplate.getRestTemplate().getRequestFactory())
-                               .setHttpClient(prepareHttpClient());
-               
-               ResponseEntity<JsonResponse<List<MLPSolution>>> response =
-                       this.restTemplate.exchange("/solutions", HttpMethod.GET, prepareRequest(), new ParameterizedTypeReference<JsonResponse<List<MLPSolution>>>() {});
-               
-               if (response != null)   {
-                       System.out.println("testSolutions: " + response.getBody());
-                       System.out.println("testSolutions: " + response);
-               }
-               
-               assertTrue(response != null);
-               assertTrue(response.getStatusCodeValue() == 200);
-               assertTrue(response.getBody().getResponseBody().size() == 1);
-       }
+       @Mock
+       private NexusArtifactClient nexusClient;
 
+       @MockBean(name = "federationClient")
+       private HttpClient      federationClient;
 
-       @Test
-       public void testSolutionSuccess() {
+       @MockBean(name = "clients")
+       private Clients clients;
 
-    ((HttpComponentsClientHttpRequestFactory)
-                       this.restTemplate.getRestTemplate().getRequestFactory())
-                               .setHttpClient(prepareHttpClient());
+       @Autowired
+       private ApplicationContext context;
 
-               ResponseEntity<JsonResponse<MLPSolution>> response =
-                       this.restTemplate.exchange("/solutions/00000000-0000-0000-0000-000000000000", HttpMethod.GET, prepareRequest(), new ParameterizedTypeReference<JsonResponse<MLPSolution>>() {} );
-       
-               if (response != null)   {
-                       System.out.println("testSolution: " + response.getBody());
-                       System.out.println("testSolution: " + response);
-               }
+       //initialize with the number of checkpoints
+       private CountDownLatch stepLatch = new CountDownLatch(4);
 
-               assertTrue(response != null);
-               assertTrue(response.getStatusCodeValue() == 200);
-               assertTrue(response.getBody().getResponseBody().getModelTypeCode().equals("CL")); //no errors
+       @Before
+       public void initTest() {
+               MockitoAnnotations.initMocks(this);
        }
 
+       /**
+        * The gateway behaviour is triggered by the availability of other solutions
+        * in a peer, as provided by the federation client.  
+        */
        @Test
-       public void testSolutionRevisionsSuccess() {
-    
-               ((HttpComponentsClientHttpRequestFactory)
-                       this.restTemplate.getRestTemplate().getRequestFactory())
-                               .setHttpClient(prepareHttpClient());
-
-               ResponseEntity<JsonResponse<List<MLPSolutionRevision>>> response =
-                       this.restTemplate.exchange("/solutions/00000000-0000-0000-0000-000000000000/revisions", HttpMethod.GET, prepareRequest(), new ParameterizedTypeReference<JsonResponse<List<MLPSolutionRevision>>>() {});
+       public void testGateway() {
+
+               try {
+                       BasicHttpResponse mockSolutionsResponse = 
+                               new BasicHttpResponse(
+                                       new BasicStatusLine(
+                                               new ProtocolVersion("HTTP",1,1), 200, "Success"));
+
+                       ClassPathResource mockSolutions =
+                               new ClassPathResource("mockPeerSolutionsResponse.json");
+
+                       mockSolutionsResponse.setEntity(
+                               new InputStreamEntity(mockSolutions.getInputStream()));
+                       mockSolutionsResponse
+                               .addHeader("Content-Type", ContentType.APPLICATION_JSON.toString());
+                       mockSolutionsResponse
+                               .addHeader("Content-Length", String.valueOf(mockSolutions.contentLength()));
+
+                       BasicHttpResponse mockSolutionRevisionsResponse = 
+                               new BasicHttpResponse(
+                                       new BasicStatusLine(
+                                               new ProtocolVersion("HTTP",1,1), 200, "Success"));
+
+                       ClassPathResource mockSolutionRevisions =
+                               new ClassPathResource("mockPeerSolutionRevisionsResponse.json");
+
+                       mockSolutionRevisionsResponse.setEntity(
+                               new InputStreamEntity(mockSolutionRevisions.getInputStream()));
+                       mockSolutionRevisionsResponse
+                               .addHeader("Content-Type", ContentType.APPLICATION_JSON.toString());
+                       mockSolutionRevisionsResponse
+                               .addHeader("Content-Length", String.valueOf(mockSolutionRevisions.contentLength()));
+
+                       BasicHttpResponse mockSolutionRevisionArtifactsResponse = 
+                               new BasicHttpResponse(
+                                       new BasicStatusLine(
+                                               new ProtocolVersion("HTTP",1,1), 200, "Success"));
+
+                       ClassPathResource mockSolutionRevisionArtifacts =
+                               new ClassPathResource("mockPeerSolutionRevisionArtifactsResponse.json");
+
+                       mockSolutionRevisionArtifactsResponse.setEntity(
+                               new InputStreamEntity(mockSolutionRevisionArtifacts.getInputStream()));
+                       mockSolutionRevisionArtifactsResponse
+                               .addHeader("Content-Type", ContentType.APPLICATION_JSON.toString());
+                       mockSolutionRevisionArtifactsResponse
+                               .addHeader("Content-Length", String.valueOf(mockSolutionRevisionArtifacts.contentLength()));
+
+                       BasicHttpResponse mockDownloadResponse = 
+                               new BasicHttpResponse(
+                                       new BasicStatusLine(
+                                               new ProtocolVersion("HTTP",1,1), 200, "Success"));
+
+                       mockDownloadResponse.setEntity(
+                               new ByteArrayEntity(new byte[] {}));
+                       mockDownloadResponse
+                               .addHeader("Content-Type", ContentType.APPLICATION_OCTET_STREAM.toString());
+                       mockDownloadResponse
+                               .addHeader("Content-Length", String.valueOf(0));
+
+                       //prepare the clients
+                       when(
+                               this.clients.getClient()
+                       )
+                       //.thenReturn(cdsClient);
+                       .thenAnswer(new Answer<ICommonDataServiceRestClient>() {
+                                       public ICommonDataServiceRestClient answer(InvocationOnMock theInvocation) {
+                                               return cdsClient;
+                                       }
+                               });
+
+                       when(
+                               this.clients.getFederationClient(
+                                       any(String.class)
+                               )
+                       )
+                       .thenAnswer(new Answer<FederationClient>() {
+                                       public FederationClient answer(InvocationOnMock theInvocation) {
+                                               //this should end up providing a client based on the mocked http
+                                               //client
+                                         return new FederationClient(
+                  (String)theInvocation.getArguments()[0]/*the URI*/,
+                  federationClient);
+                                       /* not working as real method relies on the application context
+                                                which is not set because we work on a  mock
+                                               try {
+                                                       return (FederationClient)theInvocation.callRealMethod();
+                                               }
+                                               catch (Throwable t) {
+                                                       t.printStackTrace();
+                                                       return null;
+                                               }
+                                       */
+                                       }
+                               });
+
+                       when(
+                               this.clients.getNexusClient()
+                       )
+                       .thenReturn(nexusClient);
+
+                       when(
+                               this.nexusClient.uploadArtifact(
+                                       any(String.class),any(String.class),any(String.class),any(String.class),any(Long.class),any(InputStream.class)
+                               )
+                       )
+                       .thenReturn(new UploadArtifactInfo("","","","","",0));
+
+                       when(
+                               this.cdsClient.searchPeers(
+                                       any(Map.class), any(Boolean.class)
+                               )
+                       )
+                       .thenAnswer(new Answer<List<MLPPeer>>() {
+                                       public List<MLPPeer> answer(InvocationOnMock theInvocation) {
+                                               MLPPeer peer = new MLPPeer();
+                                               peer.setPeerId("1");
+                                               peer.setName("testPeer");
+                                               peer.setSubjectName("test.org");
+                                               peer.setActive(true);
+                                               peer.setSelf(false);
+                                               peer.setApiUrl("https://localhost:1111");
+
+                                               return Collections.singletonList(peer);
+                                       }
+                               });
                
-               if (response != null)   {
-                       System.out.println("testSolutionRevisions: " + response.getBody());
-                       System.out.println("testSolutionRevisions: " + response);
-               }
-
-               assertTrue(response != null);
-               assertTrue(response.getStatusCodeValue() == 200);
-               assertTrue(response.getBody().getResponseBody().size() == 1); //no errors
-       }
-
-       @Test
-       public void testSolutionRevisionSuccess() {
-
-    ((HttpComponentsClientHttpRequestFactory)
-                       this.restTemplate.getRestTemplate().getRequestFactory())
-                               .setHttpClient(prepareHttpClient());
-
-               ResponseEntity<JsonResponse<MLPSolution>> response =
-                       this.restTemplate.exchange("/solutions/00000000-0000-0000-0000-000000000000/revisions/01010101-0101-0101-0101-010101010101", HttpMethod.GET, prepareRequest(), new ParameterizedTypeReference<JsonResponse<MLPSolution>>() {} );
+                       when(
+                               this.cdsClient.getPeerSubscriptions(
+                                       any(String.class)
+                               )
+                       )
+                       .thenAnswer(new Answer<List<MLPPeerSubscription>>() {
+                                       public List<MLPPeerSubscription> answer(InvocationOnMock theInvocation) {
+                                               MLPPeerSubscription sub = new MLPPeerSubscription();
+                                               sub.setSubId(Long.valueOf(12));
+                                               sub.setPeerId("1");
+                                               sub.setSelector("");
+                                               sub.setRefreshInterval(Long.valueOf(300));
+
+                                               return Collections.singletonList(sub);
+                                       }
+                               });
        
-               if (response != null)   {
-                       System.out.println("testSolution: " + response.getBody());
-                       System.out.println("testSolution: " + response);
+                       //pretend the solution does not exist locally .. 
+                       when(
+                               this.cdsClient.getSolution(
+                                       any(String.class)
+                               )
+                       ) 
+                       .thenReturn(null);
+
+                       //as a result the gateway should attempt to create a local solution
+                       //with the information it got from the 'peer' (see the mock response)
+                       when(
+                               this.cdsClient.createSolution(
+                                       any(MLPSolution.class)
+                               )
+                       )
+                       //.thenReturn(mockSolution);
+                       .thenAnswer(new Answer<MLPSolution>() {
+                                       public MLPSolution answer(InvocationOnMock theInvocation) {
+                                               stepLatch.countDown();
+                                               return (MLPSolution)theInvocation.getArguments()[0];
+                                       }
+                               });
+
+                       //the gateway should attempt to get the revisions from the peer and
+                       //compare them against locally available ones (based on the last one)
+                       when(
+                               this.cdsClient.getSolutionRevision(
+                                       any(String.class), any(String.class)
+                               )
+                       ) 
+                       .thenAnswer(new Answer<MLPSolutionRevision>() {
+                                       public MLPSolutionRevision answer(InvocationOnMock theInvocation) {
+                                               stepLatch.countDown();
+                                               //pretend we do not have a local match so that we trigger
+                                               //an insert
+                                               return null; //Collections.EMPTY_LIST;
+                                       }
+                               });
+
+                       when(
+                               this.cdsClient.createSolutionRevision(
+                                       any(MLPSolutionRevision.class)
+                               )
+                       )
+                       .thenAnswer(new Answer<MLPSolutionRevision>() {
+                                       public MLPSolutionRevision answer(InvocationOnMock theInvocation) {
+                                               stepLatch.countDown();
+                                               return (MLPSolutionRevision)theInvocation.getArguments()[0];
+                                       }
+                               });
+
+                       //pretend artifact is not available locally
+                       when(
+                               this.cdsClient.getArtifact(
+                                       any(String.class)
+                               )
+                       ) 
+                       .thenReturn(null);
+
+                       when(
+                               this.cdsClient.createArtifact(
+                                       any(MLPArtifact.class)
+                               )
+                       ) 
+                       .thenAnswer(new Answer<MLPArtifact>() {
+                                       public MLPArtifact answer(InvocationOnMock theInvocation) {
+                                               stepLatch.countDown();
+                                               return (MLPArtifact)theInvocation.getArguments()[0];
+                                       }
+                               });
+
+                       doAnswer(new Answer<Void>() {
+                                       public Void answer(InvocationOnMock theInvocation) {
+                                               //enable this when download mocking is complete
+                                               //stepLatch.countDown();
+                                               return null;
+                                       }
+                               }).when(this.cdsClient).updateArtifact(any(MLPArtifact.class));
+
+                       doAnswer(new Answer<Void>() {
+                                       public Void answer(InvocationOnMock theInvocation) {
+                                               //stepLatch.countDown();
+                                               return null;
+                                       }
+                               }).when(this.cdsClient)
+                               .addSolutionRevisionArtifact(
+                                       any(String.class),any(String.class),any(String.class));
+
+
+                       //see TaskTest for full mocking of the http client. this is thte method
+                       //that gets used by the RestTemplate so we'll keep it short here
+                       //we need to 
+                       when(
+                               this.federationClient.execute(
+                                       any(HttpUriRequest.class), any(HttpContext.class)
+                               )
+                       //).thenReturn(mockResponse);
+                       ).thenAnswer(new Answer<HttpResponse>() {
+                                       public HttpResponse answer(InvocationOnMock theInvocation) {
+                                               HttpUriRequest req = (HttpUriRequest)
+                                                       theInvocation.getArguments()[0];
+                                               String path = req.getURI().getPath();
+                                               if (path.equals("/solutions"))
+                                                       return mockSolutionsResponse;
+                                               if (path.endsWith("/revisions"))
+                                                       return mockSolutionRevisionsResponse;
+                                               if (path.endsWith("/artifacts"))
+                                                       return mockSolutionRevisionArtifactsResponse;
+                                               if (path.endsWith("/download"))
+                                                       return mockDownloadResponse;
+
+       System.out.println(" *** Mock unhandled path " + path);
+                                               return null;
+                                       }
+                               });
+                                       
                }
-
-               assertTrue(response != null);
-               assertTrue(response.getStatusCodeValue() == 200);
-               assertTrue(response.getBody().getResponseBody().getOwnerId().equals("admin")); //no errors
-       }
-
-       @Test
-       public void testSolutionRevisionArtifactsSuccess() {
-    
-               ((HttpComponentsClientHttpRequestFactory)
-                       this.restTemplate.getRestTemplate().getRequestFactory())
-                               .setHttpClient(prepareHttpClient());
-
-               ResponseEntity<JsonResponse<List<MLPArtifact>>> response =
-                       this.restTemplate.exchange("/solutions/00000000-0000-0000-0000-000000000000/revisions/01010101-0101-0101-0101-010101010101/artifacts", HttpMethod.GET, prepareRequest(), new ParameterizedTypeReference<JsonResponse<List<MLPArtifact>>>() {});
-               
-               if (response != null)   {
-                       System.out.println("testSolutionRevisionsArtifacts: " + response.getBody());
-                       System.out.println("testSolutionRevisionsArtifacts: " + response);
+               catch(Exception x) {
+                       System.out.println(" *** Failed to setup mock : " + x);
+                       x.printStackTrace();
+                       assertTrue(1 == 0);
                }
 
-               assertTrue(response != null);
-               assertTrue(response.getStatusCodeValue() == 200);
-               assertTrue(response.getBody().getResponseBody().size() == 1); //no errors
-       }
-
-       @Test
-       public void testPeersForbidden() {
-
-    ((HttpComponentsClientHttpRequestFactory)
-                       this.restTemplate.getRestTemplate().getRequestFactory())
-                               .setHttpClient(prepareHttpClient());
-
-               ResponseEntity<JsonResponse<List<MLPPeer>>> response =
-                       this.restTemplate.exchange("/peers", HttpMethod.GET, prepareRequest(), new ParameterizedTypeReference<JsonResponse<List<MLPPeer>>>() {} );
-       
-               if (response != null)   {
-                       System.out.println("testPeers: " + response.getBody());
-                       System.out.println("testPeers: " + response);
+               //let the test wait for a few seconds so that the expected
+               //behaviour kicks in
+               boolean completed = false;
+               try {
+                       completed = stepLatch.await(10, TimeUnit.SECONDS);
                }
-
-               assertTrue(response.getStatusCodeValue() == 403);
-       }
-
-       private HttpEntity prepareRequest(String theResourceName) {
-               String content = new Scanner(
-                                                                          Thread.currentThread().getContextClassLoader().getResourceAsStream(theResourceName), "UTF-8")
-                                                                                       .useDelimiter("\\Z").next();
-
-               HttpHeaders headers = new HttpHeaders();
-               headers.setContentType(MediaType.APPLICATION_JSON);
-               return new HttpEntity<String>(content, headers);
-       }
-       
-       private HttpEntity prepareRequest() {
-               HttpHeaders headers = new HttpHeaders();
-               headers.setContentType(MediaType.APPLICATION_JSON);
-               return new HttpEntity<String>(headers);
+               catch (InterruptedException ix) {
+                       assertTrue(1 == 0);
+               }
+               if (!completed)
+                       System.out.println(" *** Failed to complete,  " + stepLatch.getCount() + " steps left");
+                       
+               //if we are here is that all steps that we expected took place
+               assertTrue(completed);
        }
 
-       private HttpClient prepareHttpClient() {
-               return new HttpClientConfigurationBuilder()
-                                                               .withSSL(new SSLBuilder()
-                                                                                                                       .withKeyStore("classpath:/acumosb.pkcs12")
-                                                                                                                       .withKeyStorePassword("acumosb")
-                                                                                                                       //.withKeyPassword("acumosb")
-                                                                                                                       .withTrustStore("classpath:/acumosTrustStore.jks")
-                                                                                                                       .withTrustStoreType("JKS")
-                                                                                                                       .withTrustStorePassword("acumos")
-                                                                                                                       .build())
-                                                               .buildConfig()
-                                                               .buildClient();
-       }
 }
-
index 9a215df..90ec388 100644 (file)
@@ -21,6 +21,10 @@ package org.acumos.federation.gateway.test;
 
 import java.util.List;
 import java.util.Scanner;
+import java.util.Collections;
+
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.CountDownLatch;
 
 import static org.junit.Assert.assertTrue;
 import static org.assertj.core.api.Assertions.assertThat; 
@@ -32,11 +36,20 @@ import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
+import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.SpringRunner;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 import org.springframework.test.context.web.WebAppConfiguration;
 import org.springframework.boot.test.web.client.TestRestTemplate;
 
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.event.EventListener;
+import org.springframework.context.annotation.Bean;
+
+import org.springframework.boot.test.mock.mockito.MockBean;
+
 import org.springframework.http.HttpMethod;
 import org.springframework.http.MediaType;
 import org.springframework.http.HttpHeaders;
@@ -44,12 +57,31 @@ import org.springframework.http.HttpEntity;
 import org.springframework.http.ResponseEntity;
 import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
 import org.springframework.core.ParameterizedTypeReference;
+import org.springframework.core.io.ClassPathResource;
 
+import static org.mockito.Mockito.*;
+import static org.mockito.Matchers.*;
+import org.mockito.stubbing.Answer;
+import org.mockito.invocation.InvocationOnMock;
+
+import org.apache.http.ProtocolVersion;
+import org.apache.http.HttpHost;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
 import org.apache.http.client.HttpClient;
+import org.apache.http.client.ResponseHandler;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.message.BasicHttpResponse;
+import org.apache.http.message.BasicStatusLine;
+import org.apache.http.entity.InputStreamEntity;
+import org.apache.http.entity.ByteArrayEntity;
+import org.apache.http.entity.ContentType;
 
 /* this is not good for unit testing .. */
 import org.acumos.federation.gateway.common.JsonResponse;
 import org.acumos.federation.gateway.common.HttpClientConfigurationBuilder;
+import org.acumos.federation.gateway.event.PeerSubscriptionEvent;
 import static org.acumos.federation.gateway.common.HttpClientConfigurationBuilder.SSLBuilder;
 
 import org.acumos.cds.domain.MLPPeer;
@@ -68,9 +100,9 @@ import org.acumos.cds.domain.MLPArtifact;
                                                                webEnvironment = WebEnvironment.RANDOM_PORT,
                                                                properties = {
                                                                        "federation.instance=adapter",
-                                                                       "federation.instance.name=Ghost",
-                                                                       "peersLocal.source=classpath:/test-peers.json",
-                                                                       "catalogLocal.source=classpath:/test-catalog.json",
+                                                                       "federation.instance.name=ghost",
+                                                                       "peersLocal.source=classpath:/task-test-peers.json",
+                                                                       "catalogLocal.source=classpath:/task-test-catalog.json",
                                                                        "server.ssl.key-store=classpath:acumosa.pkcs12",
                                                                        "server.ssl.key-store-password=acumosa",
                                                                        "server.ssl.key-store-type=PKCS12",
@@ -79,12 +111,168 @@ import org.acumos.cds.domain.MLPArtifact;
                                                                        "server.ssl.trust-store-password=acumos",
                                                                        "server.ssl.client-auth=need"
                                                                })
+@ContextConfiguration(classes = {TaskTest.TaskTestConfiguration.class})
 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
 public class TaskTest {
 
+
+       @MockBean(name = "federationClient")
+       private HttpClient      federationClient;
+
+       @Autowired
+       private ApplicationContext context;
+
+       /**
+        * Called by the test framework and hanging until the event that
+        * we are expecting is coming.
+        * The test config sets up a short check interval.
+        */
        @Test
        public void testPeerTask() {
 
+               PeerSubscriptionListener listener =
+                       (PeerSubscriptionListener)this.context.getBean("testListener");
+
+               try {
+                       BasicHttpResponse mockResponse = 
+                               new BasicHttpResponse(
+                                       new BasicStatusLine(
+                                               new ProtocolVersion("HTTP",1,1), 200, "Success"));
+/*
+                       String mockContent = "{" +
+                                       "\"status\": true," +
+                                       "\"response_code\": 200," +
+                                       "\"response_detail\": \"Success\"," +
+                                       "\"response_body\": [{" +
+                                       "\"solutionId\":\"6793411f-c7a1-4e93-85bc-f91d267541d8\"," +
+                                       "\"name\":\"mock model\"," +
+                               "\"description\":\"Test mock model\"," +
+                               "\"ownerId\":\"admin\"," +
+                               "\"active\":\"true\"," +
+                               "\"modelTypeCode\":\"CL\"," +
+                               "\"toolkitTypeCode\":\"\"," +
+                               "\"validationStatusCode\":\"\"," +
+                               "\"metadata\":\"acumosa\"," +
+                               "\"created\":\"2017-08-10\"," +
+                               "\"modified\":\"2017-08-11\"" +
+                               "}]}";
+
+                       byte[] mockContentBytes = mockContent.getBytes("UTF-8");
+
+                       mockResponse.setEntity(
+                               new ByteArrayEntity(mockContentBytes));
+                       mockResponse.addHeader("Content-Type", ContentType.APPLICATION_JSON.toString());
+                       mockResponse.addHeader("Content-Length", String.valueOf(mockContentBytes.length));
+*/
+                       ClassPathResource mockResource = new ClassPathResource("mockPeerSolutionsResponse.json");
+
+                       mockResponse.setEntity(
+                               new InputStreamEntity(mockResource.getInputStream()));
+                       mockResponse.addHeader("Content-Type", ContentType.APPLICATION_JSON.toString());
+                       mockResponse.addHeader("Content-Length", String.valueOf(mockResource.contentLength()));
+
+                       MLPSolution mockSolution = new MLPSolution();
+                       mockSolution.setSolutionId("1");
+                       mockSolution.setName("mock model");
+                       mockSolution.setDescription("mock model test");
+                       mockSolution.setActive(true);
+
+                       JsonResponse<List<MLPSolution>> mockPayload = new JsonResponse();
+                       mockPayload.setStatus(Boolean.TRUE);
+                       mockPayload.setResponseCode("200");
+                       mockPayload.setResponseDetail("Success");
+                       mockPayload.setResponseBody(Collections.singletonList(mockSolution));
+
+                       when(
+                               this.federationClient.execute(
+                                       any(HttpHost.class), any(HttpRequest.class)
+                               )
+                       ).thenReturn(mockResponse);
+
+                       when(
+                               this.federationClient.execute(
+                                       any(HttpHost.class), any(HttpRequest.class), any(HttpContext.class)
+                               )
+                       ).thenReturn(mockResponse);
+                       
+                       when(
+                               this.federationClient.execute(
+                                       any(HttpUriRequest.class)
+                               )
+                       ).thenReturn(mockResponse);
+
+//this one gets called!
+                       when(
+                               this.federationClient.execute(
+                                       any(HttpUriRequest.class), any(HttpContext.class)
+                               )
+                       //).thenReturn(mockResponse);
+                       ).thenAnswer(new Answer<HttpResponse>() {
+                                       public HttpResponse answer(InvocationOnMock theInvocation) {
+                                               return mockResponse;
+                                       }
+                               });
+
+                       when(
+                               this.federationClient.execute(
+                                       any(HttpHost.class), any(HttpRequest.class), any(ResponseHandler.class)
+                               )
+                       ).thenReturn(mockPayload);
+                                               
+                       when(
+                               this.federationClient.execute(
+                                       any(HttpHost.class), any(HttpRequest.class), any(ResponseHandler.class), any(HttpContext.class)
+                               )
+                       ).thenReturn(mockPayload);
+                       
+                       when(
+                               this.federationClient.execute(
+                                       any(HttpUriRequest.class), any(ResponseHandler.class)
+                               )
+                       ).thenReturn(mockPayload);
+                                               
+                       when(
+                               this.federationClient.execute(
+                                       any(HttpUriRequest.class), any(ResponseHandler.class), any(HttpContext.class)
+                               )
+                       ).thenReturn(mockPayload);
+
+               }
+               catch(Exception x) {
+                       System.out.println(" *** Failed to setup mock : " + x);
+                       x.printStackTrace();
+                       assertTrue(1 == 0);
+               }
+
+               try {
+                       assertTrue(listener.peerEventLatch.await(10, TimeUnit.SECONDS));
+               }
+               catch (InterruptedException ix) {
+                       assertTrue(1 == 0);
+               }
+               //
+               assertTrue(listener.event != null);
+               assertTrue(listener.event.getSolutions().size() == 1);
+               assertTrue(listener.event.getSolutions().get(0).getName().equals("mock model"));
+       }
+
+       public static class TaskTestConfiguration {
+
+               @Bean({"testListener"})
+               public PeerSubscriptionListener testListener() {
+                       return new PeerSubscriptionListener();
+               }
        }
 
+       public static class PeerSubscriptionListener {
+       
+               CountDownLatch                          peerEventLatch = new CountDownLatch(1);
+               PeerSubscriptionEvent event;
+
+               @EventListener
+               public void onApplicationEvent(PeerSubscriptionEvent theEvent) {
+                       this.event = theEvent;
+                       this.peerEventLatch.countDown();
+               }
+       }
 }
diff --git a/gateway/src/test/resources/mockPeerSolutionRevisionArtifactsResponse.json b/gateway/src/test/resources/mockPeerSolutionRevisionArtifactsResponse.json
new file mode 100644 (file)
index 0000000..2c64008
--- /dev/null
@@ -0,0 +1,14 @@
+{
+ "status": true,
+ "response_code": 200,
+ "response_detail": "Success",
+ "response_body": [{
+  "artifactId":"2c2c2c2c-6e6f-47d9-b7a4-c4e674d2b341",
+  "artifactTypeCode":"dk",
+  "description":"First attempt",
+  "size":0,
+  "metadata":"mock artifact",
+  "created":"2017-09-10",
+  "modified":"2017-09-11"
+ }]
+}
diff --git a/gateway/src/test/resources/mockPeerSolutionRevisionsResponse.json b/gateway/src/test/resources/mockPeerSolutionRevisionsResponse.json
new file mode 100644 (file)
index 0000000..e5f6ee9
--- /dev/null
@@ -0,0 +1,15 @@
+{
+ "status": true,
+ "response_code": 200,
+ "response_detail": "Success",
+ "response_body": [{
+  "revisionId":"2c7e4481-6e6f-47d9-b7a4-c4e674d2b341",
+  "solutionId":"6793411f-c7a1-4e93-85bc-f91d267541d8",
+  "description":"First attempt",
+  "version":"1.0",
+  "metadata":"acumosa",
+  "ownerId":"admin",
+  "created":"2017-08-10",
+  "modified":"2017-08-11"
+ }]
+}
diff --git a/gateway/src/test/resources/mockPeerSolutionsResponse.json b/gateway/src/test/resources/mockPeerSolutionsResponse.json
new file mode 100644 (file)
index 0000000..689f45f
--- /dev/null
@@ -0,0 +1,18 @@
+{
+ "status": true,
+ "response_code": 200,
+ "response_detail": "Success",
+ "response_body": [{
+  "solutionId":"6793411f-c7a1-4e93-85bc-f91d267541d8",
+  "name":"mock model",
+  "description":"Test mock model",
+  "ownerId":"admin",
+  "active":"true",
+  "modelTypeCode":"CL",
+  "toolkitTypeCode":"",
+  "validationStatusCode":"",
+  "metadata":"acumosa",
+  "created":"2017-08-10",
+  "modified":"2017-08-11"
+ }]
+}
diff --git a/gateway/src/test/resources/task-test-catalog.json b/gateway/src/test/resources/task-test-catalog.json
new file mode 100644 (file)
index 0000000..62388a1
--- /dev/null
@@ -0,0 +1,36 @@
+[{
+  "solutionId":"00000000-0000-0000-0000-000000000000",
+  "name":"traffic-ram",
+  "description":"Round about traffic model",
+  "ownerId":"admin",
+  "active":"true",
+  "modelTypeCode":"CL",
+  "toolkitTypeCode":"",
+  "validationStatusCode":"",
+  "metadata":"acumosa",
+  "created":"2017-08-10",
+  "modified":"2017-08-11",
+  "revisions":[
+   {
+    "revisionId":"01010101-0101-0101-0101-010101010101",
+    "solutionId":"00000000-0000-0000-0000-000000000000",
+    "description":"First attempt",
+    "version":"1.0",
+    "metadata":"acumosa",
+    "ownerId":"admin",
+       "created":"2017-08-10",
+       "modified":"2017-08-11",
+    "artifacts":[
+     {
+      "artifactId":"a0a0a0a0-a0a0-a0a0-a0a0-a0a0a0a0a0a0",
+      "name":"configuration",
+      "uri":"classpath:/application-acumosa.properties",
+      "metadata":"acumosa",
+         "created":"2017-08-10",
+         "modified":"2017-08-11"
+     }
+    ]
+   }
+  ]
+ }
+]
diff --git a/gateway/src/test/resources/task-test-peers.json b/gateway/src/test/resources/task-test-peers.json
new file mode 100644 (file)
index 0000000..54786a8
--- /dev/null
@@ -0,0 +1,33 @@
+[      
+       {
+               "peerId":"00000000-0000-0000-0000-000000000000",
+               "name":"acumosa",
+               "subjectName":"gateway.acumosa.org",
+               "description":"acumosa",
+    "active": "true",
+    "self": "true",
+               "apiUrl":"",
+               "subscriptions":[]
+       },
+       {
+               "peerId":"11111111-1111-1111-1111-111111111111",
+               "name":"acumosb",
+               "subjectName":"gateway.acumosb.org",
+               "description":"acumosb",
+    "active": "true",
+    "self": "false",
+               "apiUrl":"http://localhost:9003",
+               "subscriptions":[
+                       {
+        "subId":1,
+                               "peerId":"5d2f3b51-3d38-46cd-b171-7e0f3718087a",
+                               "selector":"{\"modelTypeCode\":\"CL,PR\"}",
+                               "refreshInterval":"2000",
+                               "maxArtifactSize":"2048",
+                               "created":"2017-08-12",
+                               "modified":"2017-08-12"
+                       }
+               ]
+       }
+]
+