org.apache.sling.api.resource.Resource from Image File

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

org.apache.sling.api.resource.Resource from Image File

John Kramer
Hi guys,

I need to build an org.apache.sling.api.resource.Resource obect from a file (specifically a .png file) for the purpose of unit testing.

How do I do that?

Thanks!

John Kramer
Java Software Engineer
E-Commerce Web Team
e: [hidden email]<mailto:[hidden email]>
m: 314-435-2370
Reply | Threaded
Open this post in threaded view
|

Re: org.apache.sling.api.resource.Resource from Image File

klcodanr
Assuming you are using Sling Mocks, you can load the file in as a resource
into the Sling Context, see:
https://github.com/apache/sling-org-apache-sling-app-cms/blob/master/transformer/src/test/java/org/apache/sling/cms/transformer/helpers/SlingCMSContextHelper.java

https://sling.apache.org/documentation/development/sling-mock.html

On Wed, Jan 22, 2020 at 1:44 PM John Kramer <[hidden email]>
wrote:

> Hi guys,
>
> I need to build an org.apache.sling.api.resource.Resource obect from a
> file (specifically a .png file) for the purpose of unit testing.
>
> How do I do that?
>
> Thanks!
>
> John Kramer
> Java Software Engineer
> E-Commerce Web Team
> e: [hidden email]<mailto:[hidden email]>
> m: 314-435-2370
>
Reply | Threaded
Open this post in threaded view
|

Re: org.apache.sling.api.resource.Resource from Image File

John Kramer
Looking at the maven repo, it looks like there is no test-jar built:

https://github.com/apache/sling-org-apache-sling-app-cms/blob/master/transformer/pom.xml

I can pull down the source and push a test-jar to our local repo, but if this is really the best way to implement this, this project should probably build a test jar itself.

John Kramer
Java Software Engineer
E-Commerce Web Team
e: [hidden email] <mailto:[hidden email]>
m: 314-435-2370

On 1/22/20, 13:02, "Daniel Klco" <[hidden email]> wrote:

    Warning:  This email originated from outside of Panera. Beware of clicking links and attachments.
     
   
    Assuming you are using Sling Mocks, you can load the file in as a resource
    into the Sling Context, see:
    https://github.com/apache/sling-org-apache-sling-app-cms/blob/master/transformer/src/test/java/org/apache/sling/cms/transformer/helpers/SlingCMSContextHelper.java
   
    https://sling.apache.org/documentation/development/sling-mock.html
   
    On Wed, Jan 22, 2020 at 1:44 PM John Kramer <[hidden email]>
    wrote:
   
    > Hi guys,
    >
    > I need to build an org.apache.sling.api.resource.Resource obect from a
    > file (specifically a .png file) for the purpose of unit testing.
    >
    > How do I do that?
    >
    > Thanks!
    >
    > John Kramer
    > Java Software Engineer
    > E-Commerce Web Team
    > e: [hidden email]<mailto:[hidden email]>
    > m: 314-435-2370
    >
   

Reply | Threaded
Open this post in threaded view
|

Re: org.apache.sling.api.resource.Resource from Image File

klcodanr
John, to clarify, the provided link was just an example of how one might
import files into a mock Sling repository for Unit testing with Sling
Mocks. I would not expect you to import it as a dependency in your project.

On Wed, Jan 22, 2020 at 2:31 PM John Kramer <[hidden email]>
wrote:

> Looking at the maven repo, it looks like there is no test-jar built:
>
>
> https://github.com/apache/sling-org-apache-sling-app-cms/blob/master/transformer/pom.xml
>
> I can pull down the source and push a test-jar to our local repo, but if
> this is really the best way to implement this, this project should probably
> build a test jar itself.
>
> John Kramer
> Java Software Engineer
> E-Commerce Web Team
> e: [hidden email] <mailto:[hidden email]>
> m: 314-435-2370
>
> On 1/22/20, 13:02, "Daniel Klco" <[hidden email]> wrote:
>
>     Warning:  This email originated from outside of Panera. Beware of
> clicking links and attachments.
>
>
>     Assuming you are using Sling Mocks, you can load the file in as a
> resource
>     into the Sling Context, see:
>
> https://github.com/apache/sling-org-apache-sling-app-cms/blob/master/transformer/src/test/java/org/apache/sling/cms/transformer/helpers/SlingCMSContextHelper.java
>
>     https://sling.apache.org/documentation/development/sling-mock.html
>
>     On Wed, Jan 22, 2020 at 1:44 PM John Kramer <
> [hidden email]>
>     wrote:
>
>     > Hi guys,
>     >
>     > I need to build an org.apache.sling.api.resource.Resource obect from
> a
>     > file (specifically a .png file) for the purpose of unit testing.
>     >
>     > How do I do that?
>     >
>     > Thanks!
>     >
>     > John Kramer
>     > Java Software Engineer
>     > E-Commerce Web Team
>     > e: [hidden email]<mailto:[hidden email]>
>     > m: 314-435-2370
>     >
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: org.apache.sling.api.resource.Resource from Image File

John Kramer
I understand. That makes sense.

Your example was quite useful.

Thanks!

John Kramer
Java Software Engineer
E-Commerce Web Team
e: [hidden email] <mailto:[hidden email]>
m: 314-435-2370

On 1/22/20, 13:35, "Daniel Klco" <[hidden email]> wrote:

    John, to clarify, the provided link was just an example of how one might
    import files into a mock Sling repository for Unit testing with Sling
    Mocks. I would not expect you to import it as a dependency in your project.
   
    On Wed, Jan 22, 2020 at 2:31 PM John Kramer <[hidden email]>
    wrote:
   
    > Looking at the maven repo, it looks like there is no test-jar built:
    >
    >
    > https://github.com/apache/sling-org-apache-sling-app-cms/blob/master/transformer/pom.xml
    >
    > I can pull down the source and push a test-jar to our local repo, but if
    > this is really the best way to implement this, this project should probably
    > build a test jar itself.
    >
    > John Kramer
    > Java Software Engineer
    > E-Commerce Web Team
    > e: [hidden email] <mailto:[hidden email]>
    > m: 314-435-2370
    >
    > On 1/22/20, 13:02, "Daniel Klco" <[hidden email]> wrote:
    >
    >     Warning:  This email originated from outside of Panera. Beware of
    > clicking links and attachments.
    >
    >
    >     Assuming you are using Sling Mocks, you can load the file in as a
    > resource
    >     into the Sling Context, see:
    >
    > https://github.com/apache/sling-org-apache-sling-app-cms/blob/master/transformer/src/test/java/org/apache/sling/cms/transformer/helpers/SlingCMSContextHelper.java
    >
    >     https://sling.apache.org/documentation/development/sling-mock.html
    >
    >     On Wed, Jan 22, 2020 at 1:44 PM John Kramer <
    > [hidden email]>
    >     wrote:
    >
    >     > Hi guys,
    >     >
    >     > I need to build an org.apache.sling.api.resource.Resource obect from
    > a
    >     > file (specifically a .png file) for the purpose of unit testing.
    >     >
    >     > How do I do that?
    >     >
    >     > Thanks!
    >     >
    >     > John Kramer
    >     > Java Software Engineer
    >     > E-Commerce Web Team
    >     > e: [hidden email]<mailto:[hidden email]>
    >     > m: 314-435-2370
    >     >
    >
    >
    >