2

I want to test my Rest Application that uses SpringBoot to test with Arquillian but none of the online examples work i am not able to test a GET call and facing difficulties deploying to Jboss EAP-6.4. Can anyone guide me on how to achieve this. Any simple Examples ???

Vikram
  • 635
  • 1
  • 9
  • 29
  • I'm just curious - why would you deploy SpringBoot app in EAP? That sounds like an odd match. – bartosz.majsak Jul 07 '17 at 08:12
  • I like to do it in Jboss Container which arquillian supports and btw that does not answer my question !!! – Vikram Jul 07 '17 at 08:14
  • That's why I'm commenting on the question, not answering it. That's what comments are for, I believe. I know it doesn't answer your question, but this seems like a wrong approach. So maybe instead of solving the "problem" you could rather eliminate it by using different solution? – bartosz.majsak Jul 07 '17 at 08:16
  • I need to deploy it to EAP that is installed in my company's server and i cannot dictate my company what container to use. If its a wrong approach can you please let me know with a example that works ??? I believe jboss container deploys war files and Arquillian can test war files in jboss container as well.. correct me if am wrong.. please provide a working example if possible... – Vikram Jul 07 '17 at 08:21
  • 1
    The whole idea of Spring Boot is to have one, fat jar with the entire Spring runtime so that you can run it as single Java process. You don't benefit anything from this concept nor from what EAP is offering. It's also interesting from the deployment point of view, as you deploy jar which comes with bundled Servlet container into EAP which has it's own. Sounds a bit like inception :) Are you able to actually deploy it and do manual testing? – bartosz.majsak Jul 07 '17 at 08:25
  • @bartosz.majsak See i am not using fat jar instead a war file and you check the war here : github.com/Vikrammsc/ArquillianSample/blob/ArquillianTest/… and the contents of war are in : github.com/Vikrammsc/ArquillianSample/blob/ArquillianTest/…. I could not find /WEB-INF/lib folder and files inside that anywhere in my SOP Statements. Can you tell me what am doing wrong ???? Manual Deployment works though – Vikram Jul 07 '17 at 09:00
  • I would just ask myself if JAX-RS and Java EE stack available in EAP, which is your environment, is not sufficient to implement your solution. – bartosz.majsak Jul 07 '17 at 12:37

2 Answers2

1

I think that here there are a lot of things to check, so I would say 1) have you tried to deploy the spring boot app to EAP 6.4 to check that it works (not using Arquillian)? and 2) is it possible to share a simple github project so we can check?

lordofthejars
  • 713
  • 1
  • 6
  • 14
  • I have a method like this in the controller : @Autowired private Service service; @RequestMapping(method = RequestMethod.GET, value = "/works") public void get(@PathVariable("Value") String Value) { logger.info("*************" + service); // Prints null logger.info("\n\n^^^^^^^^^^" + service.retrieveAll(Value)); } – Vikram Jun 29 '17 at 14:37
  • If you can provide us a github project would be better, with this information I am not sure what might be happening. – lordofthejars Jul 03 '17 at 07:26
  • Due to company technicals i am not able to push the code. When i manually deploy the application to jboss it works without tests. But when i try to deploy with the tests then the tests are failing and deployment fails. – Vikram Jul 03 '17 at 13:41
  • Yes I understand this, but maybe you can try with a Hello World app reproducing the problem? This might be a good exercise to see if the problem is on code or in Arquillan – lordofthejars Jul 04 '17 at 13:41
  • Thanks for your continued support. i have been breaking my head for the past two days with this. As you mentioned i created a basic project and uploaded it here https://github.com/Vikrammsc/ArquillianSample/tree/ArquillianTest. Can you take a look at the readme file too as i mentioned the issue and please help me to overcome this. Please let me know what am missing and doing wrong, Once again thanks for your help and support. – Vikram Jul 04 '17 at 17:54
  • Ok, I need to have a deeper look, but look if you open the war file you'll see that there are in WEB-INF/lib all dependencies of Spring Boot, so when you create the WAR file with ShrinkWrap, you still need to add these dependencies as well, you need to think about ShrinkWrap a a process for creating a war file, so you need to add dependencies as well check: https://github.com/shrinkwrap/resolver and https://dzone.com/articles/using-shrinkwrap-maven – lordofthejars Jul 06 '17 at 10:26
  • Yes reviewing code I am pretty sure this is what is happening, look in test you can do: WebArchive wa = ShrinkWrap........; and then System.out.println(wa.toString(true)); and you'll print the content of the war you are deploying to EAP. Then you can see the missing parts and add them. – lordofthejars Jul 06 '17 at 12:20
  • Hey man thanks a ton but still am not able to find what is misssing in my war file and how to add it to make it work ?? Can you put a test file code to make it work... Arquillianis new and am finding it difficult to know what is missing in the war file. – Vikram Jul 06 '17 at 13:11
  • i have uploaded the war file here in https://github.com/Vikrammsc/ArquillianSample/blob/ArquillianTest/FileUploadIssue.war and the contents that prints in SOP in https://github.com/Vikrammsc/ArquillianSample/blob/ArquillianTest/War_Contents. I could not find /WEB-INF/lib folder and files inside that anywhere in my SOP Statements. Can you tell me what am doing wrong ???? – Vikram Jul 06 '17 at 17:22
  • You need to add your libs manually using MAven resolver as explained here https://dzone.com/articles/using-shrinkwrap-maven – lordofthejars Jul 07 '17 at 07:56
  • So for my jar files to be included do we need to add 26 entries to be packaged for arquillian to work sir ??? Can you show me for one so that i can do it for other 25 jar files, and thanks for your continuous support sir ! – Vikram Jul 07 '17 at 08:16
0

This link helped me to solve the issue : Adding all Maven dependencies to Arquillian.

The code that works :

@Deployment
public static Archive<?> createTestArchive() {

        File[] files = Maven.resolver()
                        .loadPomFromFile("pom.xml")
                        .importRuntimeDependencies()
                        .resolve().withTransitivity()
                        .asFile(); 

    return ShrinkWrap.create(WebArchive.class, "FileUploadIssue.war")
                     .addPackages(true,"com.example")
                     .addAsLibraries(files); 
}


@Test
@RunAsClient
public void shouldGetFileContents() {

    String result = restTemplate.getForObject(contextPath + "upload/sayhello", String.class);

    System.out.println( "Test : " + result);
}

Is there any way to refactor this code even more ??

Vikram
  • 635
  • 1
  • 9
  • 29