I have read some articles regarding how we can implement BDD with cuuumber but i am not able to understand fully.
Lets say i have a service
/v1/picture?viewer=1&viewed=2&flag=1
For these 3 input i am looking for output as "1.jpg"
I am looking for
How can we implement above ? -- i.e output based on input
How can we build data ? -- mysql data basically stubs
Please help with examples and good links.
Thanks
It's hard to answer your question as there's not a lot of detail about what you're trying to achieve, but I'll give it a go.
You've got 3 different inputs there:
- The viewer
- Whether it's been viewed or not
- A flag.
So those inputs provide different contexts (Givens) for the scenarios.
Given a .jpg viewer
Given I have already viewed the image twice
Given the image has been flagged
How you set up the data for these givens is entirely up to you. You can hard-code it, use mysql data or input real data using an admin console, etc.. It shouldn't matter. The behaviour you're interested in is what happens when you apply the event (When):
When I retrieve the v1 picture
Presumably, the input provided in your contexts is relevant, and will provide different outcomes (Thens) depending on that input.
Then I should see a .jpg file
Then I should see the "Image flagged" banner
Then I should see the message "Viewed 2 times"
So I might have scenarios like:
Given a .jpg viewer
And an image that's been viewed 3 times
When I retrieve the v1 picture
Then the service should give me 1.jpg
And I should see the message "Viewed 3 times"
Given a .png viewer
When I retrieve the v1 picture
Then the service should give me 1.png
etc.
I don't know what your real service is doing, but hopefully this helps you see the pattern. Try to keep different aspects of the behaviour separated in the scenarios (more like the 2nd than the 1st) unless there are combinations you need to exemplify.
Related
Good day to all. I am currently building a program that covers the review of product warranty applications. I'm doing it in javaFX using Netbeans. The program has the following scenes:
a screen where the information of each guarantee request is entered. all the information is stored in a table in a database. The interaction between the program and the database is done, in effect, through JDBC.
a screen where you can see a table that shows all the requests that have been saved. if a row is selected, a button that carries the third scene all the data of the request that was selected is enabled.
a screen where all the data of the tests that are made to the selected guarantee application are entered. The results are also stored in another table in the database.
After the application is evaluated, a warranty review report must be generated. Currently this format is generated in pdf from excel. What I want to do is that from the data results of the tests stored in the database I can dynamically generate the pdf formats from the program in javaFX. Is there a plugin to write these documents automatically? I'm good at writing texts in LaTEX, so if there is a way to generate the latex format from the program and call the necessary information from the database, it would be perfect. Thanks in advance for the help. Any indication or idea is welcome.
It seems like you have two core requirements:
Fetch data from the database suitable for reporting
Generate the report(s) in PDF from JavaFX but can fall back to LaTEX
What you really need seems like a PDF library for Java. I can suggest iText and Docmosis as good options (please note I work for Docmosis) - both are commercial for commercial products so you would have to buy.
Assuming you are using one of these libraries, the process for each report is:
execute the query to fetch the appropriate data for the report
manipulate the data if required to make the reporting stage simple
generate the report
Using iText you would write the query, the manipulation code and then the code to layout the report including the data.
Using Docmosis you would write the query, possibly some manipulation code (Docmosis can also work directly with your ResultSet) and the code to execute the report. The layout is designed in the template (Word or Libre Office Writer).
When you mention writing "these documents automatically" I assume you mean creating the PDF file format, which iText and Docmosis can do. If you mean creating the report layout itself, then you always need to design/write something to make the report do what you require.
I hope that helps.
Thank you very much for your response Paul! I had found something related to the libraries you mentioned, and indeed something like what I'm looking for. I notice that you are more in the subject. then, you do not know bookstore, preferably free, that gives me the possibility of doing the following (pseudo code):
take the row from the database
Save the information of that row in the attributes of a created class.
create text1: "the guarantee with reference" + object.attribute1 + "was not approved in view of the physical revision test indicated that" + object.attribute2 + "
create text2: "..."
...
create the text n: "..."
take text 1 and place it in the header of the pdf document
Take text 2, put it in bold and place it in the subtitle
Generate a table and fill it with the content of text 3, 4 ...
compile all information as a pdf, (word file, xls or others if possible)
I am clear that with the libraries that you recommend you can easily make items from
1 to 8, but I do not know if it is possible to enter the texts within a template created, so that the library accommodates all the texts in the respective zones of the template file. I imagine that this can easily be done with Latex, since everything is written in plain text.
I found a library called Java LaTeX Report (JLR) that allows me to do what I want. This information may be useful to someone. Thank you again for your answer Paul, if you consider the libraries that you mention do the job more easily than JLR please let me know!
I want to develop an application in Java which takes data (ex.name of person, Amount) from excel-sheet and print it on cheque. I can able to access data from excel-sheet but don't know how to print that data on cheque. Data must get print on appropriate location on cheque (ex. name should get print where blank space is given for name). please give me a guideline for this. Thank you in advance. I am not native English speaker so kindly ignore my mistakes.
You can use a reporting tool. You can see examples here: http://www.dynamicreports.org/
I would create a PNG image for each record, with a transparent background and data at the right place. Then I would launch the printing of these images .
That sounds hacky and someone might have a better idea.
I had used the GUI to train a classifier for some sample arff files . After training I saved the obtained model .
Now that I need to use this model file in my java code to classify some text , could you please tell me how should I proceed ? I dont want to do an evaluation but would like to classify the input text given .
I had gone thru the http://weka.wikispaces.com/Serialization & http://weka.wikispaces.com/Use+Weka+in+your+Java+code .
But still couldn't find code for it .I just got an way to load a model file .But didn't get any clue on classifying text directly to classes . Any help on this regard would be helpfull .
Although the previously suggested post is very nice, I believe that the one I produced some time ago better fits your needs, as it specifically deals with text, and it is generic regarding the classifier. Please check "A Simple Text Classifier in Java with WEKA".
See here, similar tutorial by Hidalgo - Java code with slides and textual dataset. It trains a machine, loads the model and classify real time unseen textual data. Very easy to follow
https://github.com/drelhaj/MachineLearning
I'm starting to do anything like this, so I need a little bit of help to start with.
I want to print some data and give it a format to print it as an establishment ticket, so what would be the best way?
Using the java api and create the service by myself?
http://docs.oracle.com/javase/tutorial/2d/printing/index.html
Or does it exist any free library to this purpose?
Maybe better creating a PDF with the data before printing?
I've been messing around with PDFbox API but I don't like it very much.
I don't know what printer will be used so, do ticket printers use a standard size or exists differents ticket sizes?
I also need to show a preview before printing it (I'm using Swing).
There's no need to store the formatted data.
Thanks in advance.
If You decide to generate pdf file and then print it, I propose to use Apache FOP. I always use this library to generate PDF. This library is not easy but offers many options.
Second option - You could generate HTML page and then print it.
From a real live example: we're running a project that prints despatch labels to send a package with a parcel service. The label contains barcodes and other textual information as well as a logo.
Usually a ticket printer understands a special printer control language, i.e. if it's a Zebra printer it understands EPL or ZPL-code. To produce a ticket we simply send the whole control code over a simple socket connection to the printer. The control code itself is created through a template engine (Velocity in our case).
Of course there are different printers for different requirements - it may depend on what actually should be printed. So depending on the printer you may need to create a different set of template to produce your label:
https://en.wikipedia.org/wiki/Printer_control_language
By the way:
Usually the printer comes with software to let you design the layout of the paper label (which makes life really easy). We used this software to create the initial layout. The control code itself contains all commands used to configure the printer (label size, etc - no doubt there are plenty of different formats and sizes, as said: it really depends on the use case).
when printing with Java, one can select the media tray (within PrintRequestAttributeSet). Then one can pass this setting to a printjob and have one's document printed to the given tray.
My question is now: can I somehow specify that the first page is printed to one tray and the second one to another tray within one print job?
I'm reluctant to creating two separate print jobs, because my usage scenario is a mass-print, of say 1000 documents. Each document has some pages going to tray 1 and some pages going to tray 2.
If I have to create a new print job on each switch of trays, I would end up with several thousands of separate print jobs and I'm afraid of all sorts of print-spooler overruns and system crashes. Thus my preference to somehow sneak those "switches of tray" into one print job.
I'm pretty sure that it can be sone somehow, but didn't succeed so far.
I thought about creating those thousands of PrinterJobs, but having them print to a StreamPrintService (instead of an actual print service), thus capturing the switches of tray along with the actual printing data. Then I was planning to concatenate the results of those single "virtual" prints and send it all to a real printer in one real print job.
However, with java 1.6 there seems to be only one StreamPrintService, which can only output postscript.
So: is there a way to capture the raw, native output from a native printer driver (using java)? Does it seem practical to you to concatenate that output and send it to the printer, in order to solve my problem?
I would be glad, also about comments regarding only parts of the problem..
By adding a "Destination" attribute to one's print attribute set, the print can be redirected to a local file. That file contains the printjob in whatever language the actual printer's driver uses to talk in.
In my case, I ended up with postscript files.
I created two postscript files, each printing from a different tray and then send their concatenation to the printer. And it worked :-) ! I switched of the printer to verify that there is only one printjob and I wrote some numbers on the paper in the those trays. So I guess I can be sure that it's not only wishful thinking ;-).
However, I think I won't pursue this topic in depth, because
I'm not a printing guru and have my doubts that this approach works every case.
For our customer, the whole thing is a nice-to-have at this time, so there won't be a budget to reasearch further on the circumstances under which this little idea works