add unit test 73/173/2
authorSerban Jora <sj2381@att.com>
Tue, 12 Dec 2017 19:27:00 +0000 (14:27 -0500)
committerSerban Jora <sj2381@att.com>
Tue, 12 Dec 2017 19:52:09 +0000 (14:52 -0500)
Also do not fail on initial operator check on gateway startup

Change-Id: Iae2b662ab44ab106d8d19c1f6fc03aab28380990
Signed-off-by: Serban Jora <sj2381@att.com>
14 files changed:
.mvn/jvm.config [new file with mode: 0644]
gateway/pom.xml
gateway/src/main/java/org/acumos/federation/gateway/adapter/PeerGateway.java
gateway/src/main/java/org/acumos/federation/gateway/common/HttpClientConfiguration.java
gateway/src/main/java/org/acumos/federation/gateway/common/HttpClientConfigurationBuilder.java [new file with mode: 0644]
gateway/src/main/java/org/acumos/federation/gateway/service/impl/AbstractServiceLocalImpl.java [new file with mode: 0644]
gateway/src/main/java/org/acumos/federation/gateway/service/impl/FederationServiceLocalImpl.java
gateway/src/main/java/org/acumos/federation/gateway/service/impl/PeerServiceLocalImpl.java
gateway/src/main/java/org/acumos/federation/gateway/util/LocalWatchService.java
gateway/src/test/java/org/acumos/federation/gateway/test/PeerGatewayTest.java [new file with mode: 0644]
gateway/src/test/java/org/federated/gateway/AppTest.java [deleted file]
gateway/src/test/resources/acumosa-catalog.json
gateway/src/test/resources/test-catalog.json [new file with mode: 0644]
gateway/src/test/resources/test-peers.json [new file with mode: 0644]

diff --git a/.mvn/jvm.config b/.mvn/jvm.config
new file mode 100644 (file)
index 0000000..3311ef1
--- /dev/null
@@ -0,0 +1 @@
+ -Djavax.net.ssl.trustStore=gateway/src/test/resources/acumosTrustStore.jks -Djavax.net.ssl.trustStorePassword=acumos -Djava.security.egd=file:/dev/./urandom
index 57afc0a..d512992 100644 (file)
@@ -30,7 +30,7 @@
                <build.number>0</build.number>
                <eelf.version>1.0.0</eelf.version>
                <!-- tests require database to be running -->
-               <skipTests>true</skipTests>
+               <skipTests>false</skipTests>
                <!-- Docker daemon -->
                <docker.host.url>unix:/var/run/docker.sock</docker.host.url>
                <!-- Docker image registry -->
                <artifactId>commons-lang3</artifactId>
                <version>3.6</version>
                </dependency>
+
+               <dependency>
+                       <groupId>junit</groupId>
+                       <artifactId>junit</artifactId>
+                       <version>4.12</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.assertj</groupId>
+                       <artifactId>assertj-core</artifactId>
+                       <version>3.8.0</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.springframework.boot</groupId>
+                       <artifactId>spring-boot-starter-test</artifactId>
+                       <version>1.5.3.RELEASE</version>
+                       <scope>test</scope>
+               </dependency>
        </dependencies>
        
        <build>
                                                </manifestEntries>
                                        </archive>
                                </configuration>
+                               <executions>
+                                       <execution>
+                                               <goals>
+                                                       <goal>test-jar</goal>
+                                               </goals>
+                                       </execution>
+                               </executions>
                        </plugin>
                        <plugin>
                                <groupId>org.springframework.boot</groupId>
index ce2070d..44dc972 100644 (file)
@@ -80,12 +80,11 @@ public class PeerGateway {
                }
                else {
                        try {
-                               if (null == this.clients.getClient().getUser(
-                                                                                       this.env.getProperty("federation.operator"))) {
+                               if (null == this.clients.getClient().getUser(this.env.getProperty("federation.operator"))) {
                                        logger.warn(EELFLoggerDelegate.errorLogger, "'federation.operator' does not point to an existing user");
                                }
                        }
-                       catch (HttpStatusCodeException dx) {
+                       catch (/*HttpStatusCode*/Exception dx) {
                                logger.warn(EELFLoggerDelegate.errorLogger, "failed to verify 'federation.operator' value", dx);
                        }
                }
index 2dfc85c..cce4499 100644 (file)
@@ -28,6 +28,7 @@ import org.springframework.context.annotation.Scope;
 import org.springframework.beans.factory.config.ConfigurableBeanFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.core.io.ResourceLoader;
+import org.springframework.core.io.DefaultResourceLoader;
 
 import java.net.URI;
 
@@ -173,6 +174,9 @@ public class HttpClientConfiguration {
                SSLContext sslContext = null;
                log.info(EELFLoggerDelegate.debugLogger, "Build HttpClient with " + this);
 
+               if (this.resourceLoader == null)
+                       this.resourceLoader = new DefaultResourceLoader();
+
                if (this.ssl == null) {
                        log.info(EELFLoggerDelegate.debugLogger, "No ssl config was provided");
                }
@@ -189,7 +193,7 @@ public class HttpClientConfiguration {
                                }
                                catch (Exception x) {
                                        throw new IllegalStateException(
-                                                                               "Error loading key material", x);
+                                                                               "Error loading key material: " + x, x);
                                }
                        }
 
@@ -205,7 +209,7 @@ public class HttpClientConfiguration {
                                }
                                catch (Exception x) {
                                        throw new IllegalStateException(
-                                                                               "Error loading trust material", x);
+                                                                               "Error loading trust material: " + x, x);
                                }
                        }
 
diff --git a/gateway/src/main/java/org/acumos/federation/gateway/common/HttpClientConfigurationBuilder.java b/gateway/src/main/java/org/acumos/federation/gateway/common/HttpClientConfigurationBuilder.java
new file mode 100644 (file)
index 0000000..ff26bb6
--- /dev/null
@@ -0,0 +1,109 @@
+/*-
+ * ===============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;
+
+
+
+public class HttpClientConfigurationBuilder
+//                                                      <A extends HttpClientConfigurationBuilder<A,T>,
+//                                                             T extends HttpClientConfiguration>
+                                                                                                                                                                               {
+
+       private /*T*/HttpClientConfiguration    config = newConfig();
+
+       protected /*A*/HttpClientConfigurationBuilder builder() {
+               return this;
+       }
+
+       protected /*T*/HttpClientConfiguration newConfig() {
+               return new HttpClientConfiguration();
+       }
+
+       public /*T*/HttpClientConfiguration buildConfig() {
+               return this.config;     
+       }
+  
+       public HttpClientConfigurationBuilder/*A*/ withUsername(String theUsername) {
+               this.config.setUsername(theUsername);
+               return builder();
+       }
+       
+       public HttpClientConfigurationBuilder/*A*/ withPassword(String thePassword) {
+               this.config.setPassword(thePassword);
+               return builder();
+       }
+       
+       public HttpClientConfigurationBuilder/*A*/ withPoolSize(int thePoolSize) {
+               this.config.setPoolSize(thePoolSize);
+               return builder();
+       }
+       
+       public HttpClientConfigurationBuilder/*A*/ withSSL(HttpClientConfiguration.SSL theSSL) {
+               this.config.setSSL(theSSL);
+               return builder();
+       }
+
+
+       public static class SSLBuilder {
+
+               private HttpClientConfiguration.SSL ssl =
+                                                                                                                       new HttpClientConfiguration.SSL();
+
+       public SSLBuilder withKeyStore(String theKeyStore) { 
+                       this.ssl.setKeyStore(theKeyStore); 
+                       return this;
+               }
+         
+       public SSLBuilder withKeyStoreType(String theKeyStoreType) {
+                       this.ssl.setKeyStoreType(theKeyStoreType);
+                       return this;
+               }
+
+       public SSLBuilder withKeyStorePassword(String theKeyStorePassword) {
+                       this.ssl.setKeyStorePassword(theKeyStorePassword);
+                       return this;
+               }
+         
+       public SSLBuilder withKeyAlias(String theKeyAlias) {
+                       this.ssl.setKeyAlias(theKeyAlias);
+                       return this;
+               }
+               
+       public SSLBuilder withTrustStore(String theTrustStore) {
+                       this.ssl.setTrustStore(theTrustStore);
+                       return this;
+               }
+               
+       public SSLBuilder withTrustStoreType(String theTrustStoreType) {
+                       this.ssl.setTrustStoreType(theTrustStoreType);
+                       return this;
+               }
+
+       public SSLBuilder withTrustStorePassword(String theTrustStorePassword) {
+                       this.ssl.setTrustStorePassword(theTrustStorePassword);
+                       return this;
+               }
+
+               public HttpClientConfiguration.SSL build() {
+                       return this.ssl;
+               }
+       }
+}
diff --git a/gateway/src/main/java/org/acumos/federation/gateway/service/impl/AbstractServiceLocalImpl.java b/gateway/src/main/java/org/acumos/federation/gateway/service/impl/AbstractServiceLocalImpl.java
new file mode 100644 (file)
index 0000000..b644b9d
--- /dev/null
@@ -0,0 +1,67 @@
+/*-
+ * ===============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 org.springframework.core.io.Resource;
+import org.springframework.core.env.Environment;
+import org.springframework.stereotype.Service;
+import org.springframework.beans.factory.BeanInitializationException;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Conditional;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import org.acumos.federation.gateway.util.LocalWatchService;
+import org.acumos.federation.gateway.config.EELFLoggerDelegate;
+
+import org.apache.commons.io.IOUtils;
+
+
+public class AbstractServiceLocalImpl {
+
+
+       protected EELFLoggerDelegate log = EELFLoggerDelegate.getLogger(getClass().getName());
+       protected Resource                              resource;
+
+       @Autowired 
+       protected ApplicationContext appCtx;
+
+       @Autowired
+       protected LocalWatchService     watcher;
+               
+
+       public void setSource(String theSource) {
+               this.resource = this.appCtx.getResource(theSource);
+       }
+
+       protected void checkResource() {
+
+               if (this.resource == null) {
+                       throw new BeanInitializationException("No source was configured");
+               }
+
+               if (!this.resource.exists()) {
+                       throw new BeanInitializationException("Source " + this.resource + " does not exist");
+               }
+       }
+
+}
index 0a504d4..59ce738 100644 (file)
 package org.acumos.federation.gateway.service.impl;
 
 import java.net.URI;
+import java.net.URISyntaxException;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.InputStream;
+import java.io.IOException;
 import java.util.Arrays;
 import java.util.ArrayList;
 import java.util.LinkedList;
@@ -74,30 +76,29 @@ import org.acumos.cds.transport.RestPageResponse;
 @Service
 @ConfigurationProperties(prefix="catalogLocal")
 @Conditional(AdapterCondition.class)
-public class FederationServiceLocalImpl extends AbstractServiceImpl
+public class FederationServiceLocalImpl extends AbstractServiceLocalImpl
                                                                                                                                                                 implements FederationService {
 
-       private URI                                                                                             catalogUri;
        private List<FLPSolution>                                       solutions;
 
-       @Autowired
-       private LocalWatchService       watcher;
-
-  public void setCatalogUri(URI theUri) {
-    this.catalogUri = theUri;
-  }
-
 
        @PostConstruct
        public void initService() {
-    if (this.catalogUri == null) {
-      throw new BeanInitializationException("No catalog uri was configured");
-    }
 
-    watcher.watchOn(this.catalogUri,
-                    (uri) -> { loadSolutionsCatalogInfo(); });
+               checkResource();
+               try {
+           watcher.watchOn(this.resource.getURL().toURI(),
+                         (uri) -> { loadSolutionsCatalogInfo(); });
+
+    }
+    catch (IOException | URISyntaxException iox) {
+      log.info(EELFLoggerDelegate.errorLogger, "Catalog watcher registration failed for " + this.resource, iox);
+    }
 
                loadSolutionsCatalogInfo();
+
+    // Done
+    log.debug(EELFLoggerDelegate.debugLogger, "Local FederationService available");
        }
 
        @PreDestroy
@@ -111,12 +112,12 @@ public class FederationServiceLocalImpl extends AbstractServiceImpl
                                ObjectReader objectReader = 
                                                                                                                new ObjectMapper().reader(FLPSolution.class);
                                MappingIterator objectIterator =
-                                                                                                               objectReader.readValues(this.catalogUri.toURL());
+                                                                                                               objectReader.readValues(this.resource.getURL());
                                this.solutions = objectIterator.readAll();
                                log.info(EELFLoggerDelegate.debugLogger, "loaded " + this.solutions.size() + " solutions");
                        }
                        catch (Exception x) {
-                               throw new BeanInitializationException("Failed to load solutions catalog from " + this.catalogUri, x);
+                               throw new BeanInitializationException("Failed to load solutions catalog from " + this.resource, x);
                        }
                }
        }
index 1511846..53abc8c 100644 (file)
@@ -25,13 +25,6 @@ import java.io.InputStreamReader;
 import java.io.BufferedReader;
 import java.io.IOException;
 
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.nio.file.StandardWatchEventKinds;
-import java.nio.file.WatchEvent;
-import java.nio.file.WatchKey;
-import java.nio.file.WatchService;
-
 import java.net.URI;
 import java.net.URISyntaxException;
 
@@ -57,6 +50,7 @@ import org.springframework.core.env.Environment;
 import org.springframework.stereotype.Service;
 import org.springframework.beans.factory.BeanInitializationException;
 import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.ApplicationContext;
 import org.springframework.context.annotation.Conditional;
 import org.springframework.beans.factory.annotation.Autowired;
 
@@ -75,64 +69,51 @@ import org.apache.commons.io.IOUtils;
 @ConfigurationProperties(prefix="peersLocal")
 @Conditional(AdapterCondition.class)
 public class PeerServiceLocalImpl
+                                                                                               extends AbstractServiceLocalImpl
                                                                                                implements PeerService,
                                                                                                                                         PeerSubscriptionService {
 
        private List<FLPPeer>           peers;
-       private URI                                                     sourceUri;
-       private WatchService            sourceWatcher = null;
 
-       private final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(PeerServiceLocalImpl.class);
-
-       @Autowired
-       private LocalWatchService       watcher;
-               
-       public void setSourceUri(String theUri) {
-               try {
-                       this.sourceUri = new URI(theUri);
-               }
-               catch(URISyntaxException urisx) {
-                       throw new IllegalArgumentException("Cannot set uri", urisx);
-               }
-       }
 
        @PostConstruct
        public void initPeerService() {
-               logger.debug(EELFLoggerDelegate.debugLogger, "init local peer info service");
-
-               if (this.sourceUri == null) {
-                       throw new BeanInitializationException("No source uri was configured");
+               log.debug(EELFLoggerDelegate.debugLogger, "init local peer info service");
+               checkResource();
+               try {
+                       watcher.watchOn(this.resource.getURL().toURI(),
+                                                                                       (uri) -> { loadPeersSubscriptionsInfo(); });
+               }
+               catch (IOException | URISyntaxException iox) {
+                       log.info(EELFLoggerDelegate.errorLogger, "Peers subscriptions watcher registration failed for " + this.resource, iox);
                }
-
-               watcher.watchOn(this.sourceUri,
-                                                                               (uri) -> { loadPeersSubscriptionsInfo(); });
 
                loadPeersSubscriptionsInfo();
 
                // Done
-               logger.debug(EELFLoggerDelegate.debugLogger, "Onap available");
+               log.debug(EELFLoggerDelegate.debugLogger, "Local PeerService available");
        }
 
        private void loadPeersSubscriptionsInfo() {
-               logger.info(EELFLoggerDelegate.debugLogger, "Loading peers subscriptions from " + this.sourceUri);
+               log.info(EELFLoggerDelegate.debugLogger, "Loading peers subscriptions from " + this.resource);
                synchronized (this) {
            try {
                                ObjectReader objectReader =
                                new ObjectMapper().reader(FLPPeer.class);
        MappingIterator objectIterator =
-                                   objectReader.readValues(this.sourceUri.toURL());
+                                   objectReader.readValues(this.resource.getURL());
                                this.peers = objectIterator.readAll();
-                               logger.info(EELFLoggerDelegate.debugLogger, "loaded " + this.peers.size() + " peers");
+                               log.info(EELFLoggerDelegate.debugLogger, "loaded " + this.peers.size() + " peers");
                        }
                        catch (Exception x) {
-       throw new BeanInitializationException("Failed to load solutions catalog from " + this.sourceUri, x);
+       throw new BeanInitializationException("Failed to load solutions catalog from " + this.resource, x);
                        }
                }
        }
 
        @PreDestroy
        public void cleanupPeerService() {
-               logger.debug(EELFLoggerDelegate.debugLogger, "Local peer info service destroyed");
+               log.debug(EELFLoggerDelegate.debugLogger, "Local peer info service destroyed");
        }
 
 
@@ -148,12 +129,12 @@ public class PeerServiceLocalImpl
        
        /** */
        public List<MLPPeer> getPeer(final String theSubjectName) {
-               logger.info(EELFLoggerDelegate.debugLogger, "Looking for peer " + theSubjectName);
+               log.info(EELFLoggerDelegate.debugLogger, "Looking for peer " + theSubjectName);
                return 
                        this.peers
                                                .stream()
                                                .filter(peer -> { 
-               logger.info(EELFLoggerDelegate.debugLogger, "Found peer " + peer.getSubjectName());
+               log.info(EELFLoggerDelegate.debugLogger, "Found peer " + peer.getSubjectName());
                                                                                                                        return theSubjectName.equals(peer.getSubjectName()); })
                                                .collect(Collectors.toList());
        }
@@ -167,7 +148,7 @@ public class PeerServiceLocalImpl
                                                .findFirst()
                                                .orElse(null);
 
-               logger.debug(EELFLoggerDelegate.errorLogger, "Local peer info, one peer: " + apeer);
+               log.debug(EELFLoggerDelegate.errorLogger, "Local peer info, one peer: " + apeer);
 
                return apeer;
        }
@@ -194,7 +175,7 @@ public class PeerServiceLocalImpl
                                                        .filter(entry -> thePeerId.equals(entry.getPeerId()))
                                                        .findFirst()
                                                        .orElse(null);
-               logger.info(EELFLoggerDelegate.errorLogger, "Peer " + thePeerId + " subs:" + (peer == null ? "none" : peer.getSubscriptions()));
+               log.info(EELFLoggerDelegate.errorLogger, "Peer " + thePeerId + " subs:" + (peer == null ? "none" : peer.getSubscriptions()));
                return peer == Collections.EMPTY_LIST ? null : peer.getSubscriptions();
        }
 
index 303f0df..fba989b 100644 (file)
@@ -83,7 +83,7 @@ public class LocalWatchService {
        protected void setupSourceWatcher(URI theSource) {
 
                if (this.sourceWatcher == null)
-                       logger.warn(EELFLoggerDelegate.debugLogger, "source watcher not available ");
+                       logger.warn(EELFLoggerDelegate.errorLogger, "source watcher not available ");
                        
                if ("file".equals(theSource.getScheme())) {
                        //we can only watch directories ..
@@ -92,7 +92,7 @@ public class LocalWatchService {
                                sourcePath.register(this.sourceWatcher, StandardWatchEventKinds.ENTRY_MODIFY);
                        }
                        catch (IOException iox) {
-                               logger.warn(EELFLoggerDelegate.debugLogger, "Failed to setup source watcher for " + theSource + ". Cause: " + iox);
+                               logger.warn(EELFLoggerDelegate.errorLogger, "Failed to setup source watcher for " + theSource, iox);
                        }
                } 
        }
diff --git a/gateway/src/test/java/org/acumos/federation/gateway/test/PeerGatewayTest.java b/gateway/src/test/java/org/acumos/federation/gateway/test/PeerGatewayTest.java
new file mode 100644 (file)
index 0000000..e195a4a
--- /dev/null
@@ -0,0 +1,149 @@
+/*-
+ * ===============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.apache.http.client.HttpClient;
+
+/* this is not good for unit testing .. */
+import org.acumos.federation.gateway.common.HttpClientConfigurationBuilder;
+import static org.acumos.federation.gateway.common.HttpClientConfigurationBuilder.SSLBuilder;
+
+/**
+ */
+
+//@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"
+                                                               })
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class PeerGatewayTest {
+
+       @Autowired
+       private TestRestTemplate restTemplate;
+
+       @Test
+       public void testSolutions() {
+
+    ((HttpComponentsClientHttpRequestFactory)
+                       this.restTemplate.getRestTemplate().getRequestFactory())
+                               .setHttpClient(prepareHttpClient());
+               
+               ResponseEntity<List> response =
+                       this.restTemplate.exchange("/solutions", HttpMethod.GET, prepareRequest(), List.class);
+               
+               assertTrue(response.getStatusCodeValue() == 200);
+       }
+
+       @Test
+       public void testSolutionSuccess() {
+
+    ((HttpComponentsClientHttpRequestFactory)
+                       this.restTemplate.getRestTemplate().getRequestFactory())
+                               .setHttpClient(prepareHttpClient());
+
+               ResponseEntity<List> response =
+                       this.restTemplate.exchange("/solution/00000000-0000-0000-0000-000000000000", HttpMethod.GET, prepareRequest(), List.class);
+               
+               assertTrue(response.getStatusCodeValue() == 200);
+               //assertTrue(response.getBody().size() == 0); //no errors
+       }
+       
+       @Test
+       public void testSolutionRevisionsSuccess() {
+    
+               ((HttpComponentsClientHttpRequestFactory)
+                       this.restTemplate.getRestTemplate().getRequestFactory())
+                               .setHttpClient(prepareHttpClient());
+
+               ResponseEntity<List> response =
+                       this.restTemplate.exchange("/solution/00000000-0000-0000-0000-000000000000/revisions", HttpMethod.GET, prepareRequest(), List.class);
+               
+               assertTrue(response.getStatusCodeValue() == 200);
+               //assertTrue(response.getBody().size() == 0); //no errors
+       }
+       
+       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();
+       }
+}
+
diff --git a/gateway/src/test/java/org/federated/gateway/AppTest.java b/gateway/src/test/java/org/federated/gateway/AppTest.java
deleted file mode 100644 (file)
index 58de7c5..0000000
+++ /dev/null
@@ -1,58 +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.federated.gateway;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- * Unit test for simple App.
- */
-public class AppTest 
-    extends TestCase
-{
-    /**
-     * Create the test case
-     *
-     * @param testName name of the test case
-     */
-    public AppTest( String testName )
-    {
-        super( testName );
-    }
-
-    /**
-     * @return the suite of tests being tested
-     */
-    public static Test suite()
-    {
-        return new TestSuite( AppTest.class );
-    }
-
-    /**
-     * Rigourous Test :-)
-     */
-    public void testApp()
-    {
-        assertTrue( true );
-    }
-}
index b2ca7c4..0022122 100644 (file)
@@ -12,7 +12,7 @@
   "modified":"2017-08-11",
   "revisions":[
    {
-    "revisionId":"2c7e4481-6e6f-47d9-b7a4-c4e674d2b3412c7e4481-6e6f-47d9-b7a4-c4e674d2b3412c7e4481-6e6f-47d9-b7a4-c4e674d2b3412c7e4481-6e6f-47d9-b7a4-c4e674d2b3412c7e4481-6e6f-47d9-b7a4-c4e674d2b341",
+    "revisionId":"2c7e4481-6e6f-47d9-b7a4-c4e674d2b341",
     "solutionId":"6793411f-c7a1-4e93-85bc-f91d267541d8",
     "description":"First attempt",
     "version":"1.0",
diff --git a/gateway/src/test/resources/test-catalog.json b/gateway/src/test/resources/test-catalog.json
new file mode 100644 (file)
index 0000000..d38dcb6
--- /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":"/home/src/acumos/federation/gateway/application-acumosa.properties",
+      "metadata":"acumosa",
+         "created":"2017-08-10",
+         "modified":"2017-08-11"
+     }
+    ]
+   }
+  ]
+ }
+]
diff --git a/gateway/src/test/resources/test-peers.json b/gateway/src/test/resources/test-peers.json
new file mode 100644 (file)
index 0000000..d158e1d
--- /dev/null
@@ -0,0 +1,23 @@
+[      
+       {
+               "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":"https://localhost:9002",
+               "subscriptions":[]
+       }
+]
+