Search in sources :

Example 71 with JSONObject

use of net.minidev.json.JSONObject in project scheduler by btrplace.

the class ConstraintConverterTest method testBadCheckIdBadId.

@Test(expectedExceptions = { JSONConverterException.class })
public void testBadCheckIdBadId() throws JSONConverterException {
    ConstraintConverter<?> c = new Mock<>("foo");
    JSONObject o = new JSONObject();
    o.put("id", "bar");
    c.checkId(o);
}
Also used : JSONObject(net.minidev.json.JSONObject) Test(org.testng.annotations.Test)

Example 72 with JSONObject

use of net.minidev.json.JSONObject in project scheduler by btrplace.

the class ReconfigurationPlanConverter method fromJSON.

@Override
public ReconfigurationPlan fromJSON(JSONObject ob) throws JSONConverterException {
    JSONs.checkKeys(ob, ORIGIN_LABEL, ACTIONS_LABEL);
    final Model m = mc.fromJSON((JSONObject) ob.get(ORIGIN_LABEL));
    final ReconfigurationPlan plan = new DefaultReconfigurationPlan(m);
    for (final JSONObject json : (List<JSONObject>) ob.get(ACTIONS_LABEL)) {
        final String id = json.getAsString(ActionConverter.ID_LABEL);
        ActionConverter<? extends Action> ac = json3java.get(id);
        if (ac == null) {
            throw new JSONConverterException("No converter for action '" + id + "'");
        }
        final Action action = ac.fromJSON(m, json);
        eventsFromJSON(json, m, action);
        plan.add(action);
    }
    return plan;
}
Also used : DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) Action(org.btrplace.plan.event.Action) JSONObject(net.minidev.json.JSONObject) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Model(org.btrplace.model.Model) List(java.util.List) JSONConverterException(org.btrplace.json.JSONConverterException)

Example 73 with JSONObject

use of net.minidev.json.JSONObject in project scheduler by btrplace.

the class ReconfigurationPlanConverter method eventFromJSON.

private Event eventFromJSON(final Model mo, final Object o) throws JSONConverterException {
    final JSONObject json = (JSONObject) o;
    JSONs.checkKeys(json, ActionConverter.ID_LABEL);
    final String id = json.get(ActionConverter.ID_LABEL).toString();
    final EventConverter<? extends Event> ec = json2java.get(id);
    if (ec == null) {
        throw new JSONConverterException("No converter available for a event having id '" + id + "'");
    }
    return ec.fromJSON(mo, json);
}
Also used : JSONObject(net.minidev.json.JSONObject) JSONConverterException(org.btrplace.json.JSONConverterException)

Example 74 with JSONObject

use of net.minidev.json.JSONObject in project scheduler by btrplace.

the class ShareableResourceConverter method parseVMs.

private static void parseVMs(Model mo, ShareableResource rc, Object o) throws JSONConverterException {
    if (o != null) {
        try {
            JSONObject values = (JSONObject) o;
            for (Map.Entry<String, Object> e : values.entrySet()) {
                String k = e.getKey();
                VM u = getVM(mo, Integer.parseInt(k));
                int v = Integer.parseInt(e.getValue().toString());
                rc.setConsumption(u, v);
            }
        } catch (ClassCastException cc) {
            throw new JSONConverterException("Unable to read the VMs at key 'vms'. Expect a JSONObject but got a '" + o.getClass().getName() + "'", cc);
        }
    }
}
Also used : JSONObject(net.minidev.json.JSONObject) VM(org.btrplace.model.VM) JSONObject(net.minidev.json.JSONObject) Map(java.util.Map) JSONConverterException(org.btrplace.json.JSONConverterException)

Example 75 with JSONObject

use of net.minidev.json.JSONObject in project scheduler by btrplace.

the class NetworkConverter method physicalElementToJSON.

/**
 * Convert a PhysicalElement to a JSON object.
 *
 * @param pe the physical element to convert
 * @return  the JSON object
 * @throws IllegalArgumentException if the physical element is not supported
 */
public JSONObject physicalElementToJSON(PhysicalElement pe) {
    JSONObject o = new JSONObject();
    if (pe instanceof Node) {
        o.put("type", NODE_LABEL);
        o.put("id", ((Node) pe).id());
    } else if (pe instanceof Switch) {
        o.put("type", SWITCH_LABEL);
        o.put("id", ((Switch) pe).id());
    } else {
        throw new IllegalArgumentException("Unsupported physical element '" + pe.getClass().toString() + "'");
    }
    return o;
}
Also used : JSONObject(net.minidev.json.JSONObject) Switch(org.btrplace.model.view.network.Switch) Node(org.btrplace.model.Node) JSONs.requiredNode(org.btrplace.json.JSONs.requiredNode)

Aggregations

JSONObject (net.minidev.json.JSONObject)257 JSONArray (net.minidev.json.JSONArray)51 Test (org.junit.Test)39 Test (org.testng.annotations.Test)38 JSONParser (net.minidev.json.parser.JSONParser)26 HashMap (java.util.HashMap)22 MockFlowFile (org.apache.nifi.util.MockFlowFile)16 JWTClaimsSet (com.nimbusds.jwt.JWTClaimsSet)14 ParseException (net.minidev.json.parser.ParseException)14 Test (org.junit.jupiter.api.Test)14 Map (java.util.Map)13 JSONConverterException (org.btrplace.json.JSONConverterException)13 SignedJWT (com.nimbusds.jwt.SignedJWT)12 Node (org.btrplace.model.Node)12 VM (org.btrplace.model.VM)12 JWSHeader (com.nimbusds.jose.JWSHeader)10 RSASSASigner (com.nimbusds.jose.crypto.RSASSASigner)10 ArrayList (java.util.ArrayList)10 AuthenticationContext (org.wso2.carbon.apimgt.gateway.handlers.security.AuthenticationContext)10 OpenAPI (io.swagger.v3.oas.models.OpenAPI)9