Chaincode for hyperledger Fabric using JAVA - 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.

Related

Integration testing running HTTP server instance without mocking?

I have been implementing CI on a legacy project that has very little junit test coverage. I have explained that given where we are that the quickest bang for buck is to deploy and run up the code as part of the weekly build and then hit the running Tomcat instance with a number of HTTP requests. Planning on doing this via JUnit.
Tests will be basic, but cover.
Has server started and can it process HTTP requests.
Are we getting the expected data back from the server.
...
I appreciate that this isn't ideal, but at present there are no tests which enable the dev team to deduce whether the weekly build is good and actually runs.
All of the examples I have found to date seem to mock the actual HTTP request. Is there a framework out there that will provide the functionality to handle http requests and the blocking async results checking?
you can automate a browser with various tools.
A common one is selenium web browser. We couple this with BDD testing/cucumber/specflow for regression and CI.
Others include robot
For tools rather than a framework, you could use badboy, jmeter or grinder
Jmeter could be used with some validations, though it's really a performance testing tool. Why not curl or wget?
Decided that using SpringJunit4ClassRunner and autowiring the required dependencies in each of the test cases makes it simple to create isolated integration tests.

Creation of multiple test cases in JIRA using java

How to create multiple test cases in Jira using Zephyr(in Java)
On the Atlassian marketplace you can find the ZAPI add-on which makes REST API calls available for Zephyr. The add-on is not free though.
From your java app (or groovy scripts or whatever), you can use your favorite REST client library to call the ZAPI resources to create tests, but you'll have to check the docs here.

Does ci.gitlab.com support hosted Java builds?

I'm trying to understand what is provided by ci.gitlab.com. I would like to create a build using Gradle for my Java project and have it all run on ci.gitlab.com servers.
The process for adding a runner seems to involve leveraging a localized installation of GitLab CI. There are shared runners available, but they seem to be geared toward Ruby, Node, etc.
Is it possible to use ci.gitlab.com for a fully hosted CI solution?
Its not important if there are only Ruby, Node or other Runners. If they are shared runners, you can specify the image in your .gitlab-ci.yml which the runners use to run you tests. See here (i wrote a example .gitlab-ci.yml):
The runners will pull the right image and will run your tests in the specified image.
More information here.

JMeter predefined JMX execution from java code

After searching for a long time I was not able to find a proper solution or documentation on how to run predefined JDBC JMeter Test Suites from java code. The tests have been defined in the JMX format.
I know that you can run it with the jmeter-n.cmd, but I need to execute the test from within my code.
Also, the Runtime.exec solution (as described in the link) is not feasable, as I cannot go out of my JVM.
How to create and run Apache JMeter Test Scripts from a Java program?
Using the JMeter API or GUI, I was able to create some http and JDBC tests - but not run predefined ones.
Creating JDBC tests in the API did not work at all.
There is some basic documentation around, but I can only find solutions on how its done in the GUI.
Thanks and best regards
Refer to 5 Ways To Launch a JMeter Test without Using the JMeter GUI guide, it provides walkthrough on how to launch existing .jmx file from Java code and additionally clarifies how to build a JMeter test plan via API.

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

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.

Categories

Resources