@Test
public void shouldCreateDataRole() throws Exception {

    loadVdbs();
    final String dataRoleName = "MyDataRole";
    final Properties settings = _uriBuilder.createSettings( SettingNames.VDB_NAME, TestUtilities.PORTFOLIO_VDB_NAME );
    _uriBuilder.addSetting( settings, SettingNames.VDB_PARENT_PATH, _uriBuilder.workspaceVdbsUri() );
    _uriBuilder.addSetting( settings, SettingNames.DATA_ROLE_ID, dataRoleName );
    final URI uri = _uriBuilder.vdbDataRoleUri( LinkType.SELF, settings );
    final boolean allowCreateTempTables = true;
    final boolean anyAuthenticated = true;
    final String dataPath = "/tko:komodo/tko:workspace/user/"
                            + TestUtilities.PORTFOLIO_VDB_NAME
                            + '/'
                            + VdbLexicon.Vdb.DATA_ROLES
                            + '/'
                            + dataRoleName;
    final String description = "My data role description";
    final boolean grantAll = true;
    final String[] mappedRoles = new String[] { "a", "b", "c", "d", "e" };
    final KomodoType type = KomodoType.VDB_DATA_ROLE;
    final String id = dataRoleName;
    final String permissionName = "MyPermission";
    final String permissionId = permissionName;
    final KomodoType permissionType = KomodoType.VDB_PERMISSION;
    final String permissionDataPath = dataPath + '/' + VdbLexicon.DataRole.PERMISSIONS + '/' + permissionName;
    final boolean allowAlter = true;
    final boolean allowCreate = false;
    final boolean allowDelete = true;
    final boolean allowExecute = false;
    final boolean allowLanguage = true;
    final boolean allowRead = false;
    final boolean allowUpdate = true;
    
    { // create data role
        final RestVdbDataRole inDataRole = new RestVdbDataRole();
        inDataRole.setAllowCreateTempTables( allowCreateTempTables );
        inDataRole.setAnyAuthenticated( anyAuthenticated );
        inDataRole.setDataPath( dataPath );
        inDataRole.setDescription( description );
        inDataRole.setGrantAll( grantAll );
        inDataRole.setId( id );
        inDataRole.setkType( type );
        inDataRole.setMappedRoles( mappedRoles );
        inDataRole.setName( dataRoleName );
        
        // add permission
        final RestVdbPermission permission = new RestVdbPermission();
        permission.setName( permissionName );
        permission.setAllowAlter( allowAlter );
        permission.setAllowCreate( allowCreate );
        permission.setAllowDelete( allowDelete );
        permission.setAllowExecute( allowExecute );
        permission.setAllowLanguage( allowLanguage );
        permission.setAllowRead( allowRead );
        permission.setAllowUpdate( allowUpdate );
        permission.setId( permissionId );
        permission.setkType( permissionType );
        permission.setDataPath( permissionDataPath );
        inDataRole.setPermissions( new RestVdbPermission[] { permission } );
        final String json = KomodoJsonMarshaller.marshall( inDataRole );
        final ClientRequest request = request( uri, MediaType.APPLICATION_JSON_TYPE );
        addBody( request, json );
        final ClientResponse< String > response = request.post( String.class );
        assertThat( response, is( notNullValue() ) );
        assertThat( response.getStatus(), is( Response.Status.OK.getStatusCode() ) );
        final String entity = response.getEntity();
        assertThat( entity, is( notNullValue() ) );
        final RestVdbDataRole outDataRole = KomodoJsonMarshaller.unmarshall( entity, RestVdbDataRole.class );
        assertNotNull( outDataRole );
        assertThat( outDataRole.isAllowCreateTempTables(), is( allowCreateTempTables ) );
        assertThat( outDataRole.isAnyAuthenticated(), is( anyAuthenticated ) );
        assertThat( outDataRole.getDataPath(), is( dataPath ) );
        assertThat( outDataRole.getDescription(), is( description ) );
        assertThat( outDataRole.isGrantAll(), is( grantAll ) );
        assertThat( outDataRole.getId(), is( id ) );
        assertThat( outDataRole.getkType(), is( type ) );
        assertThat( Arrays.equals( outDataRole.getMappedRoles(), mappedRoles ), is( true ) );
        assertThat( outDataRole.getName(), is( dataRoleName ) );
        
        assertThat( outDataRole.getPermissions().length, is( 1 ) );
        final RestVdbPermission outPermission = outDataRole.getPermissions()[0];
        assertThat( outPermission.getName(), is( permissionName ) );
        assertThat( outPermission.isAllowAlter(), is( allowAlter ) );
        assertThat( outPermission.isAllowCreate(), is( allowCreate ) );
        assertThat( outPermission.isAllowDelete(), is( allowDelete ) );
        assertThat( outPermission.isAllowExecute(), is( allowExecute ) );
        assertThat( outPermission.isAllowLanguage(), is( allowLanguage ) );
        assertThat( outPermission.isAllowRead(), is( allowRead ) );
        assertThat( outPermission.isAllowUpdate(), is( allowUpdate ) );
    }
    
    { // verify new data role exists
        final ClientRequest request = request( uri, MediaType.APPLICATION_JSON_TYPE );
        final ClientResponse< String > response = request.get( String.class );
        final String entity = response.getEntity();
        assertThat( entity, is( notNullValue() ) );
        final RestVdbDataRole dataRole = KomodoJsonMarshaller.unmarshall( entity, RestVdbDataRole.class );
        assertNotNull( dataRole );
        assertThat( dataRole.isAllowCreateTempTables(), is( allowCreateTempTables ) );
        assertThat( dataRole.isAnyAuthenticated(), is( anyAuthenticated ) );
        assertThat( dataRole.getDataPath(), is( dataPath ) );
        assertThat( dataRole.getDescription(), is( description ) );
        assertThat( dataRole.isGrantAll(), is( grantAll ) );
        assertThat( dataRole.getId(), is( id ) );
        assertThat( dataRole.getkType(), is( type ) );
        assertThat( Arrays.equals( dataRole.getMappedRoles(), mappedRoles ), is( true ) );
        assertThat( dataRole.getName(), is( dataRoleName ) );
        assertThat( dataRole.getPermissions().length, is( 1 ) );
        final Collection< RestLink > links = dataRole.getLinks();
        assertEquals( 4, links.size() );
    }
}