Search in sources :

Example 36 with JSONObject

use of net.minidev.json.JSONObject in project molgenis by molgenis.

the class RestControllerV2IT method batchDelete.

@Test(dependsOnMethods = { "batchCreate", "batchCreateTypeTest", "batchUpdate" }, priority = 10)
public void batchDelete() {
    JSONObject jsonObject = new JSONObject();
    JSONArray entityIds = new JSONArray();
    entityIds.add("55");
    entityIds.add("57");
    jsonObject.put("entityIds", entityIds);
    given().log().all().header(X_MOLGENIS_TOKEN, testUserToken).contentType(APPLICATION_JSON).body(jsonObject.toJSONString()).when().delete(API_V2 + "it_emx_datatypes_TypeTestv2").then().statusCode(NO_CONTENT).log().all();
}
Also used : JSONObject(net.minidev.json.JSONObject) JSONArray(net.minidev.json.JSONArray) Test(org.testng.annotations.Test)

Example 37 with JSONObject

use of net.minidev.json.JSONObject in project molgenis by molgenis.

the class RestControllerV2IT method batchCreateLocation.

@Test
public void batchCreateLocation() {
    JSONObject jsonObject = new JSONObject();
    JSONArray entities = new JSONArray();
    JSONObject entity = new JSONObject();
    entity.put("Chromosome", "42");
    entity.put("Position", 42);
    entities.add(entity);
    jsonObject.put("entities", entities);
    String expectedLocation = "/api/v2/it_emx_datatypes_Locationv2?q=Position=in=(\"42\")";
    String expectedHref = "/api/v2/it_emx_datatypes_Locationv2/42";
    given().log().all().header(X_MOLGENIS_TOKEN, testUserToken).contentType(APPLICATION_JSON).body(jsonObject.toJSONString()).when().post(API_V2 + "it_emx_datatypes_Locationv2").then().statusCode(RestTestUtils.CREATED).log().all().body("location", Matchers.equalTo(expectedLocation), "resources[0].href", Matchers.equalTo(expectedHref));
}
Also used : JSONObject(net.minidev.json.JSONObject) JSONArray(net.minidev.json.JSONArray) Test(org.testng.annotations.Test)

Example 38 with JSONObject

use of net.minidev.json.JSONObject in project molgenis by molgenis.

the class RestTestUtils method addToAllUsersGroup.

private static void addToAllUsersGroup(String adminToken, String userName) {
    JSONObject groupMembership = new JSONObject();
    groupMembership.put(USER, getUserId(adminToken, userName));
    groupMembership.put(GroupMemberMetaData.GROUP, getEntityId(adminToken, GroupMetaData.NAME, ALL_USER_GROUP, GroupMetaData.GROUP));
    given().header(X_MOLGENIS_TOKEN, adminToken).contentType(APPLICATION_JSON).body(groupMembership.toJSONString()).when().post("api/v1/" + GROUP_MEMBER);
}
Also used : JSONObject(net.minidev.json.JSONObject)

Example 39 with JSONObject

use of net.minidev.json.JSONObject in project molgenis by molgenis.

the class RestTestUtils method createUser.

/**
 * Create a user with userName and password as admin using given token.
 *
 * @param adminToken the token to use for login
 * @param userName   the name of the user to create
 * @param password   the password of the user to create
 */
public static void createUser(String adminToken, String userName, String password) {
    if (adminToken != null) {
        JSONObject createTestUserBody = new JSONObject();
        createTestUserBody.put("active", true);
        createTestUserBody.put("username", userName);
        createTestUserBody.put("password_", password);
        createTestUserBody.put("superuser", false);
        createTestUserBody.put("changePassword", false);
        createTestUserBody.put("Email", userName + "@example.com");
        given().header(X_MOLGENIS_TOKEN, adminToken).contentType(APPLICATION_JSON).body(createTestUserBody.toJSONString()).when().post("api/v1/sys_sec_User");
        addToAllUsersGroup(adminToken, userName);
    }
}
Also used : JSONObject(net.minidev.json.JSONObject)

Example 40 with JSONObject

use of net.minidev.json.JSONObject in project spring-security by spring-projects.

the class OAuth2ResourceServerBeanDefinitionParserTests method jwtFromIssuer.

private String jwtFromIssuer(String issuer) throws Exception {
    Map<String, Object> claims = new HashMap<>();
    claims.put(JwtClaimNames.ISS, issuer);
    claims.put(JwtClaimNames.SUB, "test-subject");
    claims.put("scope", "message:read");
    JWSObject jws = new JWSObject(new JWSHeader.Builder(JWSAlgorithm.RS256).keyID("1").build(), new Payload(new JSONObject(claims)));
    jws.sign(new RSASSASigner(TestKeys.DEFAULT_PRIVATE_KEY));
    return jws.serialize();
}
Also used : JSONObject(net.minidev.json.JSONObject) HashMap(java.util.HashMap) RSASSASigner(com.nimbusds.jose.crypto.RSASSASigner) JWSObject(com.nimbusds.jose.JWSObject) JSONObject(net.minidev.json.JSONObject) Payload(com.nimbusds.jose.Payload) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) JWSObject(com.nimbusds.jose.JWSObject) JWSHeader(com.nimbusds.jose.JWSHeader)

Aggregations

JSONObject (net.minidev.json.JSONObject)254 JSONArray (net.minidev.json.JSONArray)49 Test (org.junit.Test)39 Test (org.testng.annotations.Test)38 JSONParser (net.minidev.json.parser.JSONParser)23 HashMap (java.util.HashMap)22 MockFlowFile (org.apache.nifi.util.MockFlowFile)16 JWTClaimsSet (com.nimbusds.jwt.JWTClaimsSet)14 Test (org.junit.jupiter.api.Test)14 Map (java.util.Map)13 ParseException (net.minidev.json.parser.ParseException)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 AuthenticationContext (org.wso2.carbon.apimgt.gateway.handlers.security.AuthenticationContext)10 OpenAPI (io.swagger.v3.oas.models.OpenAPI)9 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)9