How do you test code written against AWS API [closed] - java

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I'm writing an application in Java that will upload a file up to AWS S3. The file will be given to the application in an argument, not hardcoded. I'd like to write tests to ensure that the file actually gets uploaded to S3. The test will be written before the code for TDD. (I have actually already written the code, but I'd like to ingrain TDD practices into all of my work as a habit)
How exactly would I go about doing this? I will be using JUnit as that's what I'm most familiar with.
Thanks in advance for any help.

The actual uploading and the tests that are doing it are part of your integration testing, not the unit testing. If you wrap the S3 API in a very thin class, you will mock that class for unit testing of your business classes, and you will use the real implementation for integration testing.
If you have decided, your business classes to take directly the AmazonS3 interface, then for unit testing you have to mock that one.
The actual exploratory testing (learning and verifying) if and how amazon s3 works is what you actually do in separate experimental setup.
P.S. I do not recommend using the AmazonS3 interface directly in your business classes, rather, wrap it in a thin interface of yours, so that if you decide to change the 'back-end storage' you can easily change it.

I'm not a Java programmer but you probably want to look into mocking. There is a SoapUI tool called MockService that appears to allow mocking of an external service like those provided by AWS.

Op De Cirkel answer is good in unit testing scope but if you are writing framework support or simply need to run the AWS S3 calls during your tests, you can run any service that offer AWS compatible APIs. OpenStack is one of them and can be run in a virtual machine (see DevStack).
Or you can choose from a variety of test-oriented tools that provide AWS compatible APIs.
Here are some that expose S3 service:
S3Ninja (actually written in Java)
FakeS3 (ruby)
s3mock (Scala with Java API)

You could take a look at LocalStack, a framework that spins up a fully functional local cloud environment for integration testing.
LocalStack provides a subset of the AWS cloud services, including S3, Kinesis, Lambda, DynamoDB, and more.

As suggested in above answer better approach be mock AWS API response. Another alternative to get the illusion of API action is, to invoke AWS SDK or API with dry run mode/parameter.
But you may require internet access while executing the tests.
http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/ec2/model/DryRunResult.html

The question was answered long time ago but I would like to comment another approach.
During my testing in different Python projects I've been using this library. I've found it very useful, even if you're developing with other languages like Java or Scala because you can setup a background server and mock all the AWS calls.
You can find more information about "Stand-alone Server Mode" at the end of the README.

Related

How to run Azure Data Factory pipeline on Java Eclipse

I am doing a project to integrate ADF pipeline with Java project. Is there any possible way to run the ADF pipeline remotely using Java?
I am a newcomer to this field and I didn't find any valuable articles regarding the question. Pls let me know if there is any possible solution to do so.
You may use the REST API to trigger pipeline runs from external applications, including Java. It is a POST request, and you may find details here:
https://learn.microsoft.com/en-us/rest/api/datafactory/pipelines/create-run?tabs=HTTP
Alternatively, there is a Data Factory client library for Java. It appears to be in beta, but provides the functionality you are looking for:
https://learn.microsoft.com/en-us/java/api/overview/azure/resourcemanager-datafactory-readme?view=azure-java-preview

Chaincode for hyperledger Fabric using JAVA

I want to write a chaincode in JAVA. Can I use eclipse? How can I write and test the chain code? It is my first time to learn how to develop chaincodes for Fabric. I know JAVA and I know how to write smart contracts for Ethereum where I use Remix.
Any help is appreciated. Is there a way to write and test the chaincode in JAVA without creating a network? as in just like in Remix..
Can I use eclipse?
You can use your favorite editor, is just Java what you are writing.
How can I write and test the chain code?
Follow the examples on the java chaincode repo, depending on what version of fabric you are using checkout to a branch or another. Take on account that there is a big difference between the version 1.X and 2.X . The examples that they provide are very good and you can use maven or gradle. To test the chaincode you can write unit testing with Junit and mock the shim.
Take on account that the chaincode is going to be embeded on a docker container, debugging is done by logging, so you will need to log a lot.
Is there a way to write and test the chaincode in JAVA without creating a network
Use unit testing before deploying the chaincode, unit testing here is the most important thing. The shim what it does is going to write and read so the logic that goes inside is the most important part. To testing on "real" mode you will need a network, it does not need to be big, with any example networks that are provided with the examples repo will be more than enough.

Writing test case for scala akka webservice

My application is in scala using akka and consume web services. I want to write test case for same but not exactly understanding which tools and technique to use. I am new to scala.I am told to mock webservice calls using (mockito), pls guide any working example or some hint.
I will request to look Resito - Inspired by Mockito. It will pretty easy to mocking web service read more
You can create simple web Serivce that already consuming by scala application and point scala application to mock service and check how it behave.
here is all example : https://github.com/mkotsur/restito/tree/master/examples
Please let me know if you have any question.
Mockito is also good but it is more easy to use Resito as it will create stub server and other thing easily.

DB population for Integration test server

I am dealing with quite an interesting challenge, we have an integration project that needs to interconnect the "in development" application with legacy applications. We developed a proxy that calls the legacy application from the new application and now we need to test or development against the code of a third company. I order to do that we setup a server with the same setup as the productive server and we will connect the client application to this server for testing purposes.
Application rough involved technologies: Java EE 6, Postgresql, java 7, JPA 2, Hibernate, Jboss 7
My issue is that we need to populate the DB with pseudo-real data. Meaning data that can be generated and is appropriate from the point of view of the application. The data must be somehow real as it reacts to different notifications sent by the legacy applications suite via JMS. The concerns are that it should be simple, quick to implement and somehow to create a mechanism for easy reusage - whenever I need new data, just run it once (maybe with parameters?!) and the magic is done.
Currently I try to find the best approach, I considered the following up to know:
plain SQL script
java application that inserts the needed things in DB
somehow exciting idea - use a scripting language to have the job done (which one - python, groovy)
Any idea, suggestion, question would be more than welcomed.
Maybe you should use DBUnit it has an XLSImporter. So you can maintain your test data in an Excel file.
I order to populate the DB I built a tool on top of the application's public API that creates the needed entities. To make it easier for our customer to add the needed data I exposed appropriate methods as WS that can be called as wanted by the client.
I wrote the application in java, for subjective reasons, even if I consider that a scripting language - I suppose groovy - would've been the best choice.

groovy web service client

I need to write a web service client in Groovy. The author of the web service has proposed various unappealing blobs of Java code that I could use to call the service from my Grails application.
At this point, I think it might be better if I just ask them to give me the WSDL and I'll take care of the client code myself. I'm looking for suggestions about the best way to go about writing a Groovy web service client using only a WSDL document?
I expect most suggestions will involve using some tool to generate a client-side API that I'll call from my Grails app. If so, then it's important that I can integrate generation of this API into a Grails build, because the WSDL document will probably change frequently.
I've looked at using GroovyWS which provides a very simple way of calling web services. However, it seems to lack any concept of a contract which concerns me from the point-of-view of testing. I would like to define a contract (interface) for the web service, for which I provide a real implementation that the app will use and a mock implementation that my unit tests will use.
Given your desire for more stability than the very dynamic GroovyWS, I'd suggest the easy way:
Use JAX-WS to generate a Java client, compile that and use it from Groovy. It's all statically typed and the generate Java source is reasonably clean (definitely much better than older WS client frameworks such as Axis 1).
Of course that would require that you have access to the WSDL.

Categories

Resources