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/09/07 14:25:35 UTC

[GitHub] [camel-quarkus] ppalaga commented on a change in pull request #1715: Weather native support fixes #1631

ppalaga commented on a change in pull request #1715:
URL: https://github.com/apache/camel-quarkus/pull/1715#discussion_r484452788



##########
File path: integration-tests/weather/src/main/java/org/apache/camel/quarkus/component/weather/it/WeatherResource.java
##########
@@ -0,0 +1,152 @@
+/*
+ * 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.weather.it;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ConsumerTemplate;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.weather.WeatherConstants;
+import org.jboss.logging.Logger;
+
+@Path("/weather")
+@ApplicationScoped
+public class WeatherResource {
+
+    private static final Logger LOG = Logger.getLogger(WeatherResource.class);
+
+    private static final String COMPONENT_WEATHER = "weather";
+    @Inject
+    CamelContext context;
+
+    @Inject
+    ProducerTemplate producerTemplate;
+
+    @Inject
+    ConsumerTemplate consumerTemplate;
+
+    @Path("load/component/weather")
+    @GET
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response loadComponentWeather() throws Exception {
+        /* This is an autogenerated test */
+        if (context.getComponent(COMPONENT_WEATHER) != null) {
+            return Response.ok().build();
+        }
+        LOG.warnf("Could not load [%s] from the Camel context", COMPONENT_WEATHER);
+        return Response.status(500, COMPONENT_WEATHER + " could not be loaded from the Camel context").build();
+    }

Review comment:
       This can be removed as long as we have other proper tests.

##########
File path: integration-tests/weather/src/main/java/org/apache/camel/quarkus/component/weather/it/WeatherResource.java
##########
@@ -0,0 +1,152 @@
+/*
+ * 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.weather.it;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ConsumerTemplate;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.weather.WeatherConstants;
+import org.jboss.logging.Logger;
+
+@Path("/weather")
+@ApplicationScoped
+public class WeatherResource {
+
+    private static final Logger LOG = Logger.getLogger(WeatherResource.class);
+
+    private static final String COMPONENT_WEATHER = "weather";
+    @Inject
+    CamelContext context;
+
+    @Inject
+    ProducerTemplate producerTemplate;
+
+    @Inject
+    ConsumerTemplate consumerTemplate;
+
+    @Path("load/component/weather")
+    @GET
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response loadComponentWeather() throws Exception {
+        /* This is an autogenerated test */
+        if (context.getComponent(COMPONENT_WEATHER) != null) {
+            return Response.ok().build();
+        }
+        LOG.warnf("Could not load [%s] from the Camel context", COMPONENT_WEATHER);
+        return Response.status(500, COMPONENT_WEATHER + " could not be loaded from the Camel context").build();
+    }
+
+    @Path("location/{location}")
+    @GET
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response getWeatherByLocation(@PathParam("location") String location) {
+        LOG.infof("Retrieve weather with location : %s", location);
+        final String response = producerTemplate.requestBodyAndHeader(
+                "weather:foo?location=random&appid=9162755b2efa555823cfe0451d7fff38&geolocationAccessKey=test&geolocationRequestHostIP=test",

Review comment:
       (As lazy as I am to look myself, sorry) are the constants in `appid=9162755b2efa555823cfe0451d7fff38&geolocationAccessKey=test&geolocationRequestHostIP=test` really necessary? Aren't those supposed to be secrets?

##########
File path: integration-tests/weather/src/test/java/org/apache/camel/quarkus/component/weather/it/WeatherTest.java
##########
@@ -0,0 +1,111 @@
+/*
+ * 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.weather.it;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.Matchers.containsString;
+
+@QuarkusTest
+class WeatherTest {
+
+    @Test
+    public void loadComponentWeather() {
+        /* A simple autogenerated test */
+        RestAssured.get("/weather/load/component/weather")
+                .then()
+                .statusCode(200);
+    }
+
+    @Test
+    public void loadByLocationName() {
+        RestAssured.given()
+                .get("/weather/location/London,uk")
+                .then()
+                .statusCode(200)
+                .body(containsString("name\":\"London\""), containsString("\"country\":\"GB\""), containsString("weather"),

Review comment:
       BTW, restassured allows for matching JSON payload attribs against Matchers https://github.com/rest-assured/rest-assured/wiki/Usage#example-1---json It would perhaps suit here too.




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