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 2020/04/25 06:58:30 UTC

[GitHub] [camel] dmvolod commented on a change in pull request #3777: CAMEL-2933 - resteasy component

dmvolod commented on a change in pull request #3777:
URL: https://github.com/apache/camel/pull/3777#discussion_r414999677



##########
File path: components/camel-resteasy/src/test/java/org/apache/camel/component/resteasy/test/ResteasyConsumerTest.java
##########
@@ -0,0 +1,222 @@
+/*
+ * 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.component.resteasy.test;
+
+import java.io.File;
+import java.net.URI;
+import java.nio.file.Files;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.apache.camel.component.resteasy.test.beans.Customer;
+import org.apache.camel.component.resteasy.test.beans.CustomerList;
+import org.apache.camel.component.resteasy.test.beans.CustomerService;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.container.test.api.RunAsClient;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.junit.InSequence;
+import org.jboss.arquillian.test.api.ArquillianResource;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.jboss.shrinkwrap.resolver.api.maven.Maven;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(Arquillian.class)
+@RunAsClient
+public class ResteasyConsumerTest {
+
+    @ArquillianResource
+    URI baseUri;
+
+    @Deployment
+    public static Archive<?> createTestArchive() {
+        
+        return ShrinkWrap.create(WebArchive.class, "test.war")
+                .addClasses(Customer.class, CustomerService.class, CustomerList.class)
+                .addPackage("org.apache.camel.component.resteasy")
+                .addPackage("org.apache.camel.component.resteasy.servlet")
+                .addAsLibraries(Maven.resolver().loadPomFromFile("pom.xml")
+                        .importRuntimeAndTestDependencies().resolve().withTransitivity().asFile())
+                .addAsWebInfResource(new File("src/test/resources/contexts/basicConsumer.xml"), "applicationContext.xml")
+                .addAsWebInfResource("web.xml");
+
+    }
+
+    private Response createCustomer(Customer customer) {
+        Client client = ClientBuilder.newBuilder().build();
+        WebTarget target = client.target(baseUri.toString() + "customer/createCustomer");
+        Response response = target.request(MediaType.APPLICATION_JSON)
+                .post(Entity.entity(customer, MediaType.APPLICATION_JSON_TYPE));
+
+        Assert.assertEquals(200, response.getStatus());
+        return response;
+    }
+
+    private Response deleteCustomer(int id) {
+        Client client = ClientBuilder.newBuilder().build();
+        WebTarget target = client.target(baseUri.toString() + "customer/deleteCustomer?id=" + id);
+        Response response = target.request().delete();
+
+        Assert.assertEquals(200, response.getStatus());
+
+        return response;
+    }
+
+    private Customer getCustomer(int id) {
+        Client client = ClientBuilder.newBuilder().build();
+        WebTarget target = client.target(baseUri.toString() + "customer/getCustomer?id=" + id);
+        Response response = target.request().get();
+
+        Assert.assertEquals(200, response.getStatus());
+
+        return response.readEntity(Customer.class);
+    }
+
+    @Test
+    @InSequence(1)
+    public void testGetAll() throws Exception {
+        String expectedUser1 = "{\"name\":\"Roman\",\"surname\":\"Jakubco\",\"id\":1}";
+        String expectedUser2 = "{\"name\":\"Camel\",\"surname\":\"Rider\",\"id\":2}";
+
+        Client client = ClientBuilder.newBuilder().build();
+        WebTarget target = client.target(baseUri.toString() + "customer/getAll");
+        Response response = target.request().get();
+
+        Assert.assertEquals(200, response.getStatus());
+
+        String users = response.readEntity(String.class);
+        Assert.assertTrue(users.contains(expectedUser1));
+        Assert.assertTrue(users.contains(expectedUser2));
+
+        File file = new File("target/test/consumerTest/all.txt");
+        byte[] encoded = Files.readAllBytes(file.toPath());
+        String responseBody = new String(encoded);
+
+        Assert.assertTrue(responseBody.contains(expectedUser1));
+        Assert.assertTrue(responseBody.contains(expectedUser2));
+    }
+
+    @Test
+    public void testGet() throws Exception {
+        Customer customer = getCustomer(2);
+
+        Assert.assertEquals(new Customer("Camel", "Rider", 2), customer);
+
+        File file = new File("target/test/consumerTest/get.txt");
+        byte[] encoded = Files.readAllBytes(file.toPath());
+        String responseBody = new String(encoded);
+
+        Assert.assertEquals("{\"name\":\"Camel\",\"surname\":\"Rider\",\"id\":2}", responseBody);
+    }
+
+    @Test
+    public void testPost() throws Exception {
+
+        String expectedResponse = "Customer added : Customer{name='TestCreate', surname='TestCreate', id=3}";
+        int customerId = 3;
+
+        Customer customer = new Customer("TestCreate", "TestCreate", customerId);
+        Response response = createCustomer(customer);
+        System.out.println(response.readEntity(String.class));

Review comment:
       Looks like this is from test period debug :)




----------------------------------------------------------------
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