Fix test response decoding, add logging 93/193/1
authorSerban Jora <sj2381@att.com>
Thu, 14 Dec 2017 17:32:10 +0000 (12:32 -0500)
committerSerban Jora <sj2381@att.com>
Thu, 14 Dec 2017 17:34:34 +0000 (12:34 -0500)
Change-Id: I8f2bd14a9dc50d8ce5f85708b444aa78f91eb4c1
Signed-off-by: Serban Jora <sj2381@att.com>
.gitreview
gateway/src/main/java/org/acumos/federation/gateway/common/JsonResponse.java
gateway/src/main/java/org/acumos/federation/gateway/controller/FederationController.java
gateway/src/main/java/org/acumos/federation/gateway/security/X509AuthenticationFilter.java
gateway/src/main/java/org/acumos/federation/gateway/service/impl/FederationServiceLocalImpl.java
gateway/src/test/java/org/acumos/federation/gateway/test/PeerGatewayTest.java
gateway/src/test/resources/test-catalog.json

index 13eb8a8..4082064 100644 (file)
@@ -1,4 +1,4 @@
 [gerrit]
 host=gerrit.acumos.org
 port=29418
-project=federated-cognita.git
+project=federation.git
index 1adbc51..47e13ee 100644 (file)
@@ -91,4 +91,17 @@ public class JsonResponse<T> implements Serializable {
        public void setResponseBody(T responseBody) {
                this.responseBody = responseBody;
        }
+
+       public String toString() {
+               return new StringBuilder("JsonResponse")
+                                                               .append(System.identityHashCode(this))
+                                                               .append('(')
+                                                               .append(this.responseCode)
+                                                               .append(' ')
+                                                               .append(this.responseDetail)
+                                                               .append(", ")
+                                                               .append(this.responseBody == null ? "null" : this.responseBody)
+                                                               .append(')')
+                                                               .toString();
+       }
 }
index 93580ba..b0081cb 100644 (file)
@@ -110,6 +110,7 @@ public class FederationController extends AbstractController {
                        @RequestParam(value = "modelTypeCode", required = false) String mlpModelTypes) {
                JsonResponse<List<MLPSolution>> data = null;
                List<MLPSolution> peerCatalogSolutions = null;
+               logger.debug(EELFLoggerDelegate.debugLogger, APINames.PEER_SOLUTIONS);
                try {
                        data = new JsonResponse<List<MLPSolution>>();
                        logger.debug(EELFLoggerDelegate.debugLogger, "getSolutionsListFromPeer: model types " + mlpModelTypes);
@@ -148,6 +149,7 @@ public class FederationController extends AbstractController {
                        @PathVariable("solutionId") String solutionId) {
                JsonResponse<List<MLPSolutionRevision>> data = null;
                List<MLPSolutionRevision> peerCatalogSolutionRevisions= null;
+               logger.debug(EELFLoggerDelegate.debugLogger, APINames.PEER_SOLUTIONS_REVISIONS);
                try {
                        data = new JsonResponse<List<MLPSolutionRevision>>();
                        peerCatalogSolutionRevisions = federationService.getPeerCatalogSolutionRevision(solutionId);
@@ -185,6 +187,7 @@ public class FederationController extends AbstractController {
                        @PathVariable("solutionId") String solutionId, @PathVariable("revisionId") String revisionId) {
                JsonResponse<List<MLPArtifact>> data = null;
                List<MLPArtifact> peerSolutionArtifacts= null;
+               logger.debug(EELFLoggerDelegate.debugLogger, APINames.PEER_SOLUTIONS_REVISIONS_ARTIFACTS);
                try {
                        data = new JsonResponse<List<MLPArtifact>>();
                        peerSolutionArtifacts = federationService.getPeerSolutionArtifacts(solutionId, revisionId);
index 1edef20..efbfbcb 100644 (file)
@@ -29,7 +29,10 @@ import org.acumos.federation.gateway.service.PeerService;
 import org.acumos.federation.gateway.util.Utils;
 
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
 import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
 import org.springframework.security.config.annotation.web.builders.HttpSecurity;
 import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
@@ -44,14 +47,19 @@ import org.springframework.security.core.userdetails.UserDetailsService;
  * X.509 certificate authentication :  verifying the identity of a communication peer when using the HTTPS (HTTP over SSL) protocol.
  *
  */
+
+@Configuration
 @EnableWebSecurity
 //@EnableGlobalMethodSecurity(prePostEnabled = true)
 public class X509AuthenticationFilter extends WebSecurityConfigurerAdapter {
+       
+       private final EELFLoggerDelegate log = EELFLoggerDelegate.getLogger(getClass().getName());
 
        @Autowired
        private PeerService peerService;
 
-       private final EELFLoggerDelegate log = EELFLoggerDelegate.getLogger(getClass().getName());
+       @Value("${federation.enablePeerAuthentication:true}")
+       private boolean securityEnabled;
 
        public X509AuthenticationFilter() {
                // TODO Auto-generated constructor stub
@@ -68,7 +76,7 @@ public class X509AuthenticationFilter extends WebSecurityConfigurerAdapter {
      */
        @Override
        protected void configure(HttpSecurity http) throws Exception {
-               
+
                http
                .authorizeRequests()
                        .anyRequest().authenticated()
index 59ce738..adb8546 100644 (file)
@@ -133,11 +133,13 @@ public class FederationServiceLocalImpl extends AbstractServiceLocalImpl
        @Override
        public List<MLPSolution> getPeerCatalogSolutionsList(String mlpModelTypes) {
                log.debug(EELFLoggerDelegate.debugLogger, "getPeerCatalogSolutionsList");
-               final List<String> modelTypes = Arrays.asList(mlpModelTypes.split(","));
+               final List<String> modelTypes =
+                       mlpModelTypes == null ? null : Arrays.asList(mlpModelTypes.split(","));
                return solutions.stream()
                                                        .filter(solution -> {
                log.debug(EELFLoggerDelegate.debugLogger, "getPeerCatalogSolutionsList: looking for " + modelTypes + ", has " + solution.getModelTypeCode());
-                                                                                               return modelTypes.contains(solution.getModelTypeCode());
+                                                                                               return modelTypes == null ||
+                                                                                                                        modelTypes.contains(solution.getModelTypeCode());
                                                                                        })
                                                        .collect(Collectors.toList());
        }
index e195a4a..c10fc46 100644 (file)
@@ -43,13 +43,21 @@ 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.MLPSolution;
+import org.acumos.cds.domain.MLPSolutionRevision;
+import org.acumos.cds.domain.MLPArtifact;
+
+
+
 /**
  */
 
@@ -67,7 +75,8 @@ import static org.acumos.federation.gateway.common.HttpClientConfigurationBuilde
                                                                        "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.trust-store-password=acumos",
+                                                                       "server.ssl.client-auth=need"
                                                                })
 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
 public class PeerGatewayTest {
@@ -82,12 +91,20 @@ public class PeerGatewayTest {
                        this.restTemplate.getRestTemplate().getRequestFactory())
                                .setHttpClient(prepareHttpClient());
                
-               ResponseEntity<List> response =
-                       this.restTemplate.exchange("/solutions", HttpMethod.GET, prepareRequest(), List.class);
+               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() {
 
@@ -95,13 +112,19 @@ public class PeerGatewayTest {
                        this.restTemplate.getRestTemplate().getRequestFactory())
                                .setHttpClient(prepareHttpClient());
 
-               ResponseEntity<List> response =
-                       this.restTemplate.exchange("/solution/00000000-0000-0000-0000-000000000000", HttpMethod.GET, prepareRequest(), List.class);
-               
+               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().size() == 0); //no errors
+               assertTrue(response.getBody().getResponseBody().getModelTypeCode().equals("CL")); //no errors
        }
-       
+*/
        @Test
        public void testSolutionRevisionsSuccess() {
     
@@ -109,13 +132,39 @@ public class PeerGatewayTest {
                        this.restTemplate.getRestTemplate().getRequestFactory())
                                .setHttpClient(prepareHttpClient());
 
-               ResponseEntity<List> response =
-                       this.restTemplate.exchange("/solution/00000000-0000-0000-0000-000000000000/revisions", HttpMethod.GET, prepareRequest(), List.class);
+               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().size() == 0); //no errors
+               assertTrue(response.getBody().getResponseBody().size() == 1); //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", 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
+       }
+
        private HttpEntity prepareRequest(String theResourceName) {
                String content = new Scanner(
                                                                           Thread.currentThread().getContextClassLoader().getResourceAsStream(theResourceName), "UTF-8")
index d38dcb6..62388a1 100644 (file)
@@ -24,7 +24,7 @@
      {
       "artifactId":"a0a0a0a0-a0a0-a0a0-a0a0-a0a0a0a0a0a0",
       "name":"configuration",
-      "uri":"/home/src/acumos/federation/gateway/application-acumosa.properties",
+      "uri":"classpath:/application-acumosa.properties",
       "metadata":"acumosa",
          "created":"2017-08-10",
          "modified":"2017-08-11"