jeudi 1 septembre 2016

karma + jasmine - promise.then inside code not getting excuted

Using karma with Jasmine 2. when my tests run, the piece of code where i have the following promise.then does not get executed.

doScan(issue) {
        let packet = this.getPacket();
        this.setPacket(packet, function() {
            archiverService.scanIssue(packet.packetNumber, issue).then(response => {
                if (response.ok) {
                    let body = response.body;
                    this.processScanResponse(issue, body);
                } else {
                    this.onBadResponse(issue, response);
                }
            }).catch(error => {
                this.onException(issue, error);
            });
        }.bind(this));
    }

this will eventually end up updating my component state ( i am using react) and that's what i want to test, not the promise. so far all the examples i saw online deal with testing the promise itself. Is there a way i can make it work?

unit testing for spring mvc controller

I have the following controller which accept input as @RequestParam

@RequestMapping(value = "/fetchstatus", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public Response fetchStatus(
        @RequestParam(value = "userId", required = true) Integer userId) {
    Response response = new Response();
    try {
        response.setResponse(service.fetchStatus(userId));
        response = (Response) Util.getResponse(
                response, ResponseCode.SUCCESS, FETCH_STATUS_SUCCESS,
                Message.SUCCESS);
    } catch (NullValueException e) {
        e.printStackTrace();
        responseDTO = (Response) Util.getResponse(
                response, ResponseCode.FAILED, e.getMessage(), Message.ERROR);
    } catch (Exception e) {
        e.printStackTrace();
        response = (Response) Util.getResponse(
                response, ResponseCode.FAILED, e.getMessage(), Message.ERROR);
    }
    return response;
}

I need a unit test class for this and I am beginner with spring mvc. I don't know writing test classes with @RequestParam as input.

Any help will be appreciated ..

Make the JDBC call throw a SQLException for a test case

I am writing test cases for my program and to maximize the code coverage I have to raise a SQLException, that exception will then be checked in my test case.

public double getTotalAmount(String form,String name) {
    DbManager manager = new DbManager();
    double amount = 0;
    ResultSet executeQuery = manager.findAll("select amount From "+form+" where employee_name='"+name+"'");
    try {
        while (executeQuery.next()) {
            String tempAmount = executeQuery.getString("amount");
            amount += Double.valueOf(tempAmount);
        }
        return amount;
    } catch (SQLException e) {

        e.printStackTrace();
    }
    manager.closeConnection();
    return -1;

Now I am unable to raise the SQLException in my code, can you suggest me how can I raise this exception in my code.

How to mock An Interface Java PowerMockito

I m trying to mock an interface.

public interface FlowCopyParamsBusinessManager {
List<FlowCopyParams> findByAppli(String application, String sourcePattern)
        throws FlowCopyParamsBusinessException;

}

In my code, when i call this method findByAppli, i would like to return a list of FlowCopyParams.

List<FlowCopyParams> lstFlowCopyParams = flowCopyParamsBusinessManager.findByAppli(
                    "TOTO","TATA);

Here my try in the class test:

@BeforeClass
public static void mockBeanIn() throws Exception {
List<FlowCopyParams> flowCopyParamsList = new ArrayList<>();

PowerMockito.spy(FlowCopyParamsBusinessManager.class);
PowerMockito.when(FlowCopyParamsBusinessManager.class, "findByAppli",  Mockito.anyString(), Mockito.anyString()).thenReturn(flowCopyParamsList);
}  

I have this error :

java.lang.IllegalArgumentException: object is not an instance of declaring class

I don't know why because the method findByAppli must have two string parameters, and i put Mockito.anyString() and i still have IllegalArgumentException.

Any clue ?

Thxs.

Unit testing laravel package using jenkins

I have created a package in Laravel 4 and uploaded it to github. How can I automate the unit testing using Jenkins CI as laravel package doesn't have vendor folder uploaded in github.

Android Auto App Testing

I have created android auto app, the issue is I am able to test it on Emulator but when I try it to test it on Head Unit my app is not listed. I have gone through different reference here , here and come to conclusion that I have to upload my app on play store for alpha and beta testing and then it is available on Head unit (HMI) but it will slow my testing and development process.

Is there any another way?

Any help will be appreciated.

Jenkins + TortoiseSVN - Can't connect/integrate

I can't connect Jenkins with TortoiseSVN. I try to connect my Jenkins with my local tortoise, so have no online server.

I used file:///C:/Users/a.simon/SVN/MyRepository to access my local repository, but it doesn't work. And why does Jenkins need Credentials, I don't have any Login in Tortoise: enter image description here

And if I run that, I get this error:

ERROR: Failed to check out file:///C:/Users/a.simon/SVN/MyRepository
svn: E180001: Unable to open an ra_local session to URL
svn: E180001: Unable to open repository 'file:///C:/Users/a.simon/SVN/MyRepository'

enter image description here

Setup - Tortoise: So this is my SVN-Folder

enter image description here

MyCannonAttack contains the Project

enter image description here

And the repository the repository-stuff

enter image description here