Ashwin Ganesh

Greenhorn
+ Follow
since Mar 20, 2015
Merit badge: grant badges
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ashwin Ganesh

Is the way, I am trying to mock in my test, is in a wrong way?
4 years ago
Hi,

I have an issue in mocking my rest web service's, one of the private methods.

So the flow, goes something like this,

JobController --> JobService --> createJob()

So here, in createJob() of my JobService, I will do another rest call to create a job, because job creation is hosted by someother team and I want to use the API exposed by them.
Before making a call to the API, I will create my payload, by calling prepareJobEntity(), which is a private method.




So, in my test case, this is the way I am trying to mock.



My TestDataProvider looks something like this.



The issue I am facing is,
Argument(s) are different! Wanted:
schedulerManager.create(
   com.scheduler.client.entity.Job@4a1a412e
);
-> at com.JobControllerTest.testCreateJob_whenJobDoesNotExist(JobControllerTest.java:90)
Actual invocation has different arguments:
schedulerManager.create(
   com.entity.Job@c568f91
);
-> at com.JobService.createProcessingJob(JobService.java:61)

I understand both the job instances are different, and that is the reason I am getting this issue. But, kind of confused on how to solve this. Can anyone please throw some light on this?
4 years ago
Hi,

I will have to validate my JSON, before persisting it to the database as JSON(clob). To serve this purpose, I have used javax annotations and also custom annotations on my model class. The validation is happening as expected and it works just fine.
But, if I have to retrieve the JSON and map it to my model class, javax validation will jump in again. As it does not make sense to validate a JSON, which I already did while persisting it, I want to know, if there is a way to by-pass the validation while mapping the JSON to model class.

One alternative I can think of is, to have a similar model class, without any annotations and use this to map my JSON, while retrieving it. But, its a lame alternative.

Suggestions are welcome.

Thanks,
Ashwin
4 years ago
Yes. I agree with that. We can make use of Jackson library and transform the JSON to a Java object. And by doing so, we can have a check for the values mapped for a variables in the Java object.
But, is there any way, so that, while binding the values of JSON to Java object, we can force this validation step.
4 years ago
Hi,

I have to validate a JSON posted to an API endpoint. Before, the business logic of the service executes, I wanted to check whether the JSON is valid, and only if it is valid, I want to execute the service.

Requirement:

JSON structure:
{
  "id": "1",
  "name": "ABC",
  "events": [
     {
         "id": "event1",
         "name": "Event 1"
         "props": .......
     },
    {
         "id": "event2",
         "name": "Event 2"
         "props": .......
     },
    {
         "id": "event3",
         "name": "Event 3"
         "props": ........
    }
  ],
  "PI": [
      {
          "pi_id": "123",
          "pi_name": "ABC",
          "event_id": "event1"
      },
     {
          "pi_id": "456",
          "pi_name": "DEF",
          "event_id": "event2"
      },
     {
          "pi_id": "789",
          "pi_name": "XYZ",
          "event_id": "event4"
      }
   ]
}


In the above JSON, we have specified, event4 as event_id as part of the key "PI", which is invalid because, in the "events" array, we don't have an entry for "event4". My requirement is to validate this and throw an error, when the value of "event_id" in "PI" array, does not match with that of the ID's in "events" array.

Can someone please guide me on how we will be able to achieve it?
I tried to use JSON-Schema, for validating this, but with that we can decide on the keys, which should be mandatory, but no where we will be able to check for the value in references.
One approach I thought of is, after transforming the JSON to a Java object, I need to check for the invalid entries, but felt that it will be cumbersome process, if in case the array of objects in "PI" and/or "events" get changed/increased.

Thanks,
Ashwin
4 years ago
I am basically having, 3 modules in my application.

1. opint-core-data
2. opint-odata-service
3. opint-proc-service

I'd like to have a Singleton class(to use for caching mechanism). I have created ScenarioDataProvider.java in opint-core-data module, which is a dependency in both opint-odata-service and opint-proc-service modules.

Below is the code snippet of my Singleton class.


Code snippet, where I try to get the instance of Singleton from opint-proc-service module:



Code snippet, where I try to get the instance of Singleton from opint-proc-service module:




Whenever I try to get the instance of Singleton, from opint-odata-service and opint-proc-service, two instances are getting created. One for each module.
But I would like to have only one instance available, through out the application, between multiple modules.

Can someone please assist me on how I can have one singleton instance of ScenarioDataProvider through out the application, and between multiple modules?
5 years ago
When verify method of Mockito class gets called, I am getting wanted but not invoked error in jUnit?
I understand that the  REST API call is not happening. But I would like to know the reason, of where I have slipped out.
Can anyone please assist me on this?






How do we achieve fast access when we implement RandomAccess interface?
Knowing that, Random Access interface is a marker interface(which does not have any abstract methods defined in it)

So just by implementing a marker interface, how are we achieving faster access on an ArrayList or Vector?

Please through me some light on this topic. Thanks in advance.
5 years ago
Hi All,

When we modify the structure of an ArrayList while iterating, we will get ConcurrentModificationException. To avoid it, we can perform, say remove() on an iterator object.
But how does it impact the list, at the end of an iteration/

I went throw the Java internals as well, but am clueless on how it happens.

Please throw some light on this section.
5 years ago
Hi,

The issue is now resolved. In place of comm.jar file, i used RXTXcomm.jar which resolved the issue.

Now am able to stop and start the gateway without getting PortInUseException.

Ya Henry. You are right. I have even tried that. Still jumping to the same exception.

Even after calling serialPort.close(), the port is not getting released.
I am making the thread to sleep for a minute and then starting the gateway again. Still it fails.
javax.comm.PortInUseException: Port currently owned by Unknown Windows Application

I am trying to do a program to send sms using a GSM modem.but i get the above error while try to run.
that com port is not using by any program as in my knowledge.

Please help me resolve the issue.

I have replicated the issue, by stopping the gateway and starting it back.

What i have identified is, even after stopGateway() is called, the connection is not released.