Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jun 13 03:21

    finaglehelper on develop

    finatra: Support for injecting … (compare)

  • Jun 12 22:21

    finaglehelper on develop

    finatra-thrift: Reduce complexi… (compare)

  • Jun 12 02:44

    finaglehelper on develop

    finatra-thrift: Use correct dat… (compare)

  • Jun 11 07:32

    finaglehelper on develop

    finatra-thrift: CommonThriftLog… (compare)

  • Jun 10 19:31

    finaglehelper on develop

    finagle, finatra, ts: Keep `inc… (compare)

  • Jun 10 19:05
    ihasfrozen commented #522
  • Jun 09 00:46

    finaglehelper on develop

    finatra: Add comments for optim… (compare)

  • Jun 08 18:23

    finaglehelper on develop

    finatra-doc: Add missing import… (compare)

  • Jun 05 03:18

    finaglehelper on develop

    inject-core: Remove finagle-cor… (compare)

  • Jun 04 22:33

    finaglehelper on develop

    finatra: Use permanent links fo… (compare)

  • May 29 21:31
    cacoco closed #511
  • May 29 21:31
    cacoco commented #511
  • May 29 21:31
    cacoco closed #524
  • May 29 21:31
    cacoco commented #524
  • May 28 22:31

    finaglehelper on develop

    util|scrooge|finagle|twitter-se… (compare)

  • May 28 00:41

    finaglehelper on develop

    finatra: Update testing docs P… (compare)

  • May 28 00:11

    enbnt on gh-pages

    site push by ibennett (compare)

  • May 27 22:22

    finaglehelper on finatra-20.5.0

    (compare)

  • May 27 18:20

    finaglehelper on develop

    finatra: Fix Finatra examples J… (compare)

  • May 27 04:26
    cacoco commented #524
Deenar Toraskar
@deenar
thanks will try this out (i knew about option 1, but thought java.util.Date s would be supported out of the box.)
Christopher Coco
@cacoco
LocalDate is newer
java.util.Date is supported
Christopher Coco
@cacoco
FWIW, when we remove the Joda support, we’ll likely add Jackson’s support for Java 8 date/time constructs to the base configuration of the Finatra mapper.
Deenar Toraskar
@deenar
Thanks, just using @JsonSerialize(using = LocalDateSerializer.class), does not work, i think I still need to register the new serializers in ScalaObjectMapperModule objectMapper.registerModule(new JavaTimeModule())
Christopher Coco
@cacoco
@JsonSerialize should work, curious what you’re running into. We don’t have any special thing in the way for serialization (we have a custom deserializer) other than we add some default serializers for you.
Deenar Toraskar
@deenar
@cacoco many thanks, it did work, i was annotating the wrong class
Deenar Toraskar
@deenar
another question, I cannot get JsonIgnore to work or JsonIgnoreProperties, do you expect this to work out of the box
or will i need a custom serializer
Deenar Toraskar
@deenar
It turns out you need to annotate the member as a property first, in the jackson version finatra is using @JsonIgnoreProperties(Array("b"))
case class Message(a: String, @JsonProperty("b") b: String)
Later Jackson versions apparently dont need this
Thank you for your help @cacoco
Christopher Coco
@cacoco
Ok glad you got it figured out, @deenar
Deenar Toraskar
@deenar
@cacoco Hi Chris, I was wondering how does one go about serialing Option[LocalDateTime] or Option[LocalDate]?
Christopher Coco
@cacoco
@deenar we include the DefaultScalaModule which should allow for serializing Options which should then proxy to the right serializer for LocalDate LocalDateTime if you have one
The Scala Module supports serialization and limited deserialization of Scala Case Classes, Sequences, Maps, Tuples, Options, and Enumerations.
Deenar Toraskar
@deenar
@cacoco thanks I have a couple of other question 1) i would like to return HTML via moustache if Accept header contained text/html or JSON otherwise, what is the idiomatic way of doing this
is there an Oauth2 filter implementation available somewhere?
Christopher Coco
@cacoco
@deenar we don’t have an OAuth2 Filter anywhere though I believe there is a finagle-oauth2 project here: https://github.com/finagle/finagle-oauth2 which should work. For your first question, if you want to content-negotiation like this you have several choices. Most simply is to switch on the accept header — we have a utility that may help here: https://github.com/twitter/finatra/blob/develop/http/src/main/scala/com/twitter/finatra/http/request/RequestUtils.scala#L31
Deenar Toraskar
@deenar
Thank you
Deenar Toraskar
@deenar
Hi All, I wanted to write some test on Finatra Request parsing and Response writing for some of the application classes we have, but am stuck. I saw com.twitter.finatra.http.tests.marshalling.MessageBodyManagerTest, but it only seems to test overwritten read and write behaviour not the default one.
Christopher Coco
@cacoco
@deenar not sure what you mean.
Do you have example of what you’re trying to do or what you’re running into?
Deenar Toraskar
@deenar
''' test("Test PaymentRuleTest writer ") {
val testCase = ParseRules.getSampleTestCase()
val writerResponse = defaultMessageBodyWriter.write(testCase.inputMessage)
writerResponse.contentType should equal(MediaType.JsonUtf8)
mapper.parsePaymentRuleTest should equal(testCase)
}'''
something along the lines of given a case class wanted to assert it's JSON encoding on the way out is as expected and a given JSON request is mapped correctly on the way in
Christopher Coco
@cacoco
@deenar its not intended that you need to interact with the message body manager at all to test this
you would issue a request to the server and expect the returned JSON is as expected
Deenar Toraskar
@deenar
so I should just use FeatureTests
for what you’re describing: "something along the lines of given a case class wanted to assert it's JSON encoding on the way out is as expected and a given JSON request is mapped correctly on the way in”, yes a FeatureTest
I mean you are free to test the message body writer directly…if you really want to but you’re just testing our machinery and not your logic (and you should assume we test our machinery)
Deenar Toraskar
@deenar
I do have FeatureTests, but was wondering if there was a way just to check the serialisation and deserialisation of individual case classe
Christopher Coco
@cacoco
meaning what exactly
test what mechanism
testing serialization an deserialization of a case class is effectively writing tests of the framework which is again, great, but ultimately useless for testing anything related to your logic.
ok
Christopher Coco
@cacoco
right you are free to right more tests for our object mapper — but does that help you test anything for your code?
Christopher Coco
@cacoco

If you just want to test json mapping, then yeah you can follow what happens in the Jackson tests:
https://github.com/twitter/finatra/blob/develop/jackson/src/test/scala/com/twitter/finatra/jackson/ScalaObjectMapperTest.scala

https://github.com/twitter/finatra/blob/develop/jackson/src/test/scala/com/twitter/finatra/jackson/ScalaObjectMapperFromInjectorTest.scala

https://github.com/twitter/finatra/blob/develop/jackson/src/test/scala/com/twitter/finatra/jackson/AbstractScalaObjectMapperTest.scala

Or if you want to test how object mapping interacts with HTTP requests, then you can build a minimal injector like in the MessageBodyManagerTest (https://github.com/twitter/finatra/blob/develop/http/src/test/scala/com/twitter/finatra/http/tests/marshalling/MessageBodyManagerTest.scala#L72) and get references to the DefaultMessageBodyReader and DefaultMessageBodyWriter (which are supersets of logic and end up deferring to the ScalaObjectMapper for JSON serialization): https://github.com/twitter/finatra/blob/develop/http/src/main/scala/com/twitter/finatra/http/internal/marshalling/DefaultMessageBodyWriterImpl.scala#L68

But I’m not sure that tells you anything about your code built on top of this.

that it, this is what I was after, I can test all kinds of expected inputs quicker
the feature test covers the logic, but is expensive to do the same for fields which are just pass through
thanks
Hamdi Allam
@hamdiallam
Hey folks, the 20.9.0 release is out! https://finagle.github.io/blog/2020/09/25/release-notes/
Christopher Coco
@cacoco
@deenar I wanted to add that I was not speaking only about FeatureTests earlier (there are several types of testing concepts that we espouse in Finatra: https://twitter.github.io/finatra/user-guide/testing/index.html#types-of-tests). If a use case is “expensive” to add into your tests it is possible that your system isn’t modularized well enough to allow easy testing of various components. Yes, you can always add some simple unit tests of the direct features provided by the framework (as mentioned before) especially if you’re trying to use them as regression tests against your specific data (in this case you want to always know that your case classes can be serialized/deserialized as they are perhaps unique) — but I would argue these are somewhat secondary tests and should not replace testing your higher-level logic on top of the framework of which, there are several ways to do so. Hope that helps. Thanks.
Deenar Toraskar
@deenar
@cacoco thanks for this, i was more using it as a stub during development to see how new model classes would serialize/deserialise out of the box