You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2019/10/13 16:58:02 UTC

[GitHub] [camel-quarkus] ppalaga commented on a change in pull request #266: Fixes #265 - Add tarfile extension

ppalaga commented on a change in pull request #266: Fixes #265 - Add tarfile extension
URL: https://github.com/apache/camel-quarkus/pull/266#discussion_r334286181
 
 

 ##########
 File path: integration-tests/tarfile/src/test/java/org/apache/camel/quarkus/component/tarfile/it/TarfileTest.java
 ##########
 @@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License 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.
+ */
+package org.apache.camel.quarkus.component.tarfile.it;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
+import io.restassured.http.ContentType;
+import io.restassured.response.ExtractableResponse;
+import org.apache.camel.util.IOHelper;
+import org.apache.commons.compress.archivers.ArchiveStreamFactory;
+import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
+import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+@QuarkusTest
+class TarfileTest {
+
+    @Test
+    public void test() throws Exception {
+        byte[] body;
+
+        ExtractableResponse response = RestAssured.given() //
+            .contentType(ContentType.TEXT).body("Hello World").post("/tarfile/post") //
+            .then().extract();
+
+        body = response.body().asByteArray();
+        Assertions.assertNotNull(body);
+
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        ByteArrayInputStream bis = new ByteArrayInputStream(body);
+        TarArchiveInputStream tis = (TarArchiveInputStream) new ArchiveStreamFactory().createArchiveInputStream(ArchiveStreamFactory.TAR, bis);
+
+        TarArchiveEntry entry = tis.getNextTarEntry();
+        if (entry != null) {
+            IOHelper.copy(tis, bos);
+        }
+
+        String str = bos.toString();
 
 Review comment:
   bos.toString() is using given platforms default encoding. This might be fine if RestAssured would post also using given platforms default encoding. I do not have enough time to investigate which exact encoding RestAssured uses, but quick and dirty googling seems to suggest that has some hard coded platform independent defaults (like latin 1 or utf-8). If that's really the case, this test can fail on platforms that use some incompatible encoding, say UTF-16.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services