Camel: junit-test of processor via intercept - process

Sorry, if I miss the forest for the trees...
We would like to junit-test some Java-DSL. We found some way to do this on our original routes and not with copied ones.
Using i.e. expectedMessageCount() and assertIsSatisfied() works well for endpoints 'made with to()'.
Now I am searching for a way to intercept a processor (DSL process(new Processor() {...}) using intercept or better interceptSendToEndpoint, but that one has no URI. Is there a way to do this.

See the Camel testing documentation at
http://camel.apache.org/testing
In the bottom there is links about testing existing routes, for example you can use advice with to intercept / replace parts of your routes before testing. For example if you assign an id to your processor, you can replace/remove the processor by the id, using advice with.
See the documentation and examples http://camel.apache.org/advicewith.html and you can look into the unit test source code of camel-core to find more examples.

Related

How to organize endpoints when using FeathersJS's seemingly restrictive api methods?

I'm trying to figure out if FeathersJS suits my needs. I have looked at several examples and use cases. FeathersJS uses a set of request methods : find, get, create, update, patch and delete. No other methods let alone custom methods can be implemented and used, as confirmed on this other SO post..
Let's imagine this application where users can save their app settings. Careless of following method conventions, I would create an endpoint describing the action that is performed by the user. In this case, we could have, for instance: /saveSettings. Knowing there won't be any setting-finding, -creation, -updating (only some -patching) or -deleting. I might also need a /getSettings route.
My question is: can every action be reduced down to these request methods? To me, these actions are strongly bound to a specific collection/model. Sometimes, we need to create actions that are not bound to a single collection and could potentially interact with more than one collection/model.
For this example, I'm guessing it would be translated in FeathersJS with a service named Setting which would hold two methods: get() and a patch().
If that is the correct approach, it looks to me as if this solution is more server-oriented than client-oriented in the sense that we have to know, client-side, what underlying collection is going to get changed or affected. It feels like we are losing some level of freedom by not having some kind of routing between endpoints and services (like we have in vanilla ExpressJS).
Here's another example: I have a game character that can skill-up. When the user decides to skill-up a particular skill, a request is sent to the server. This endpoint can look like POST: /skillUp What would it be in FeathersJS? by implementing SkillUpService#create?
I hope you get the issue I'm trying to highlight here. Do you have some ideas to share or recommendations on how to organize the API in this particular framework?
I'm not an expert of featherJs, but if you build your database and models with a good logic,
these methods are all you need :
for the settings example, saveSettings corresponds to setting.patch({options}) so to the route settings/:id?options (method PATCH) since the user already has some default settings (created whith the user). getSetting would correspond to setting.find(query)
To create the user AND the settings, I guess you have a method to call setting.create({defaultOptions}) when the user CREATE route is called. This would be the right way.
for the skillUp route, depends on the conception of your database, but I guess it would be something like a table that gives you the level/skills/character, so you need a service for this specific table and to call skillLevel.patch({character, level})
In addition to the correct answer that #gui3 has already given, it is probably worth pointing out that Feathers is intentionally restricting in order to help you create RESTful APIs which focus on resources (data) and a known set of methods you can execute on them.
Aside from the answer you linked, this is also explained in more detail in the FAQ and an introduction to REST API design and why Feathers does what it does can be found in this article: Design patterns for modern web APIs. These are best practises that helped scale the internet (specifically the HTTP protocol) to what it is today and can work really well for creating APIs. If you still want to use the routes you are suggesting (which a not RESTful) then Feathers is not the right tool for the job.
One strategy you may want to consider is using a request parameter in a POST body such as { "action": "type" } and use a switch statement to conditionally perform the desired action. An example of this strategy is discussed in this tutorial.

GTest `--gtest_stream_result_to` how does it work?

Looking through the --help on any gtest unittest, I see the --gtest_stream_result_to option.
Presumably, I can stream my test results, yeah!
But the more I look at it, there is absolutely no documentation on the format of the streaming endpoints or the protocol. I setup the fake server to see what it does, and now I'm making slow progress with seeing things like this:
code 400, message Bad request syntax ('gtest_streaming_protocol_version=1.0')
How do I use this feature? Is the spec for gtest_streaming_protocol_version something that is published? Any help would be awesome!
This feature was put in to facilitate communicating test results to Eclipse. You can reverse engineer the protocol from the source code. If you need more info on event listeners in general in order to better understand StreamingListener, the documentation has a section on it.

How do I use Confluence's servlet-filter module?

I have recently become aware of Confluence's servlet-filter module. However, after trying to get it to work, I have run into a dead end. I am getting my information here:
https://developer.atlassian.com/confdev/confluence-plugin-guide/confluence-plugin-module-types/servlet-filter-module
Here is what I tried. I annotated my atlassian-plugin.xml file like so:
<servlet-filter name="My Test Filter" key="OURAPP" class="com.test.filters.HelloWorldFilter" location="after-encoding" weight="100">
<description>Forwards you to a test "Hello, world!" page.</description>
<url-pattern>/helloworld</url-pattern>
<dispatcher>REQUEST</dispatcher>
</servlet-filter>
Then, I created a standard Java servlet (extends HttpServlet, etc.) at com/test/filters called HelloWorldFilter.java. In the "doGet()" method, I simply have a System.out.println() line that reads "IN THE FILTER". However, when I go to the following URLs, I always get the "Page Not Found" error page:
http://127.0.0.1:8090/helloworld
http://127.0.0.1:8090/OURAPP/helloworld
http://127.0.0.1:8090/plugins/OURAPP/helloworld
http://127.0.0.1:8090/rest/helloworld
http://127.0.0.1:8090/rest/OURAPP/helloworld
http://127.0.0.1:8090/OURAPP/rest/helloworld
We have a custom Confluence plugin, lets call it OURAPP, that is serving up data not only through the browser GUI, but also through Confluence's REST capabilities. I am trying to create a filter that manages valid and invalid requests alike. We can access the REST at:
http://127.0.0.1:8090/rest/reststuff/v1/some_function_here
Like I said in the beginning, I have run into a dead end here, and cannot figure out how to get this to work. Can anybody offer up any suggestions or example code of how to get this working?
After a couple of days messing around with this, I FINALLY figured out what was wrong. I was extending javax.servlet.http.HttpServlet instead of implementing javax.servlet.Filter. After I changed to implementing Filter, and implemented all the proper methods, my servlet filter started to work at 127.0.0.1:8090/helloworld. There are a number of examples out there that use a standard Java Servlet (i.e., extending HttpServlet) but that [apparently] does not work with Confluence. I hope this helps somebody else out there struggling with Confluence's confusion. Thanks to all who took the time to read.
Your dispatcher tag is missing the closing ">":
<dispatcher>REQUEST</dispatcher
Regards,
Gorka

Need example of putting filter in Restlet Component

I have a Restlet (v2.1.1) component that is using a ServerResource to process HTTP GET requests.
I would like to put filters and/or routers into the component so that they can do some processing before the request gets to the ServerResource.
I have been searching the Internet for an example of doing this, as well as reading the "Restlet in Action" book. I have discovered something interesting:
There are plenty of examples of how to set up a ServerResource within a component.
There are plenty of examples of how to create and set up filters and routers.
Unfortunately, search as I might, through the book and on the Internet, I cannot find an example of using both!
According to the book and the tutorials on the Internet, we should be able to create a component, set up a ServerResource in the component, and use a filter to preprocess requests that go to the ServerResource. None of the documentation anywhere seems to tell us exactly how to do this.
Am I misreading everything? Is there really no way to put filters or routers in components with ServerResources? Or have I missed some document somewhere that provides a real example of how to do this?
Could someone please either provide a simple example or provide a link to an example of doing this?
Thanks...
You need to attach the filter to the router and then attach the ServerResource to the filter using the method setNext(Class<? extends ServerResource> targetClass):
Filter myFilter = new MyFilter(getContext());
myFilter.setNext(MyServerResource.class);
router.attach("/test", myFilter);
Now you can preprocess using the filter's beforeHandle(Request request, Response response) method. If you return CONTINUE in this method, the filter will pass the request to the ServerResource.

Benchmarking/Performance testing of the API - REST/SOAP

I'm trying to benchmark/ do performance testing of API's at my work. So the client facing is REST format while the backend data is retrieved by SOAP messages. So my question is can some of you share your thoughts on how you implement it (if you have done so in the past/doing it now), am basically interested in avg response time it takes for API to return results for the client
Please let me know if you need any additional information to answer the question
Could not say it any better than Mark, really: http://www.mnot.net/blog/2011/05/18/http_benchmark_rules
Maybe you should give JMeter a try.
You can try using Apache Benchmark.This is simple and quick
Jmeter gives you additional flexibility like adding functional cases along with performance details. Results will be almost similar to Apache Benchmark tool.
The detailed one which gives Functional Test Result, performance counters settings, Call response time details, CPU and Memory changes along with Load/Stress results, with different bandwidth and browser settings - Visual Studio Team system
I used VSTS2010 for performance testing. Also GET and POST are straight forward. PUT and DELETE need coded version of webtest.
Thanks,
Madhusudanan
Tesco
If you are trying to test the REST -> SOAP calls. One more thing you can consider is to have some stubs created (for backend). This way you can perf test REST -> Stub performance followed by Stub -> SOAP perfomance. This will help in analyzing the individual components.