aboutsummaryrefslogtreecommitdiff
path: root/src/cz/crcs/ectester/reader/test/CommandTestable.java
blob: 4025c61ab0a81af32f6a579ef956208867f895eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package cz.crcs.ectester.reader.test;

import cz.crcs.ectester.common.test.BaseTestable;
import cz.crcs.ectester.common.test.TestException;
import cz.crcs.ectester.reader.command.Command;
import cz.crcs.ectester.reader.response.Response;

import javax.smartcardio.CardException;

/**
 * @author Jan Jancar johny@neuromancer.sk
 */
public class CommandTestable extends BaseTestable {
    private Command command;
    private Response response;

    public CommandTestable(Command command) {
        this.command = command;
    }

    public Command getCommand() {
        return command;
    }

    public Response getResponse() {
        return response;
    }

    @Override
    public void run() throws TestException {
        try {
            response = command.send();
        } catch (CardException e) {
            throw new TestException(e);
        }

        hasRun = true;
        if (response.error()) {
            error = true;
        } else if (response.successful()) {
            ok = true;
        }
        meta.clear();
        meta.put("natural-sw", response.getNaturalSW());
        meta.put("sws", response.getSWs());
    }
}