Replace deprecated methods in model-loader
[aai/model-loader.git] / src / test / java / org / onap / aai / modelloader / restclient / TestBabelServiceClient.java
index 4f99bfc..51c5642 100644 (file)
@@ -24,19 +24,21 @@ import static javax.servlet.http.HttpServletResponse.SC_OK;
 import static org.apache.commons.io.IOUtils.write;
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
+import static org.hamcrest.MatcherAssert.assertThat;
 
-import com.google.gson.Gson;
 import java.io.IOException;
 import java.net.URISyntaxException;
+import java.nio.charset.Charset;
 import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Properties;
+
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+
 import org.eclipse.jetty.server.Handler;
 import org.eclipse.jetty.server.Request;
 import org.eclipse.jetty.server.Server;
@@ -48,6 +50,8 @@ import org.onap.aai.babel.service.data.BabelArtifact;
 import org.onap.aai.modelloader.config.ModelLoaderConfig;
 import org.onap.aai.modelloader.service.HttpsBabelServiceClientFactory;
 
+import com.google.gson.Gson;
+
 /**
  * Local testing of the Babel service client.
  *
@@ -93,6 +97,21 @@ public class TestBabelServiceClient {
         assertThat(result.size(), is(equalTo(3)));
     }
 
+    @Test
+    public void testRestClientHttp() throws BabelServiceClientException, IOException, URISyntaxException {
+        Properties configProperties = new Properties();
+        configProperties.put("ml.babel.USE_HTTPS", "false");
+        configProperties.put("ml.babel.BASE_URL", "http://localhost:8080/");
+        configProperties.put("ml.babel.GENERATE_ARTIFACTS_URL", "generate");
+        BabelServiceClient client =
+                new HttpsBabelServiceClientFactory().create(new ModelLoaderConfig(configProperties, "."));
+        List<BabelArtifact> result =
+                client.postArtifact(readBytesFromFile("compressedArtifacts/service-VscpaasTest-csar.csar"),
+                        "service-Vscpass-Test", "1.0", "Test-Transaction-ID-BabelClient");
+        assertThat(result.size(), is(equalTo(3)));
+    }
+
+
     private byte[] readBytesFromFile(String resourceFile) throws IOException, URISyntaxException {
         return Files.readAllBytes(Paths.get(ClassLoader.getSystemResource(resourceFile).toURI()));
     }
@@ -109,7 +128,7 @@ public class TestBabelServiceClient {
                     HttpServletResponse response) throws IOException, ServletException {
                 response.setStatus(SC_OK);
                 response.setContentType("text/xml;charset=utf-8");
-                write(responseBody, response.getOutputStream());
+                write(responseBody, response.getOutputStream(), Charset.defaultCharset());
                 request.setHandled(true);
             }
         };