@Test
public void shouldCreateModelSource() throws Exception {

    final String vdbName = "blah";
    { // create VDB
        final Properties settings = _uriBuilder.createSettings(SettingNames.VDB_NAME, vdbName);
        _uriBuilder.addSetting(settings, SettingNames.VDB_PARENT_PATH, _uriBuilder.workspaceVdbsUri());
        final URI uri = _uriBuilder.vdbUri(LinkType.SELF, settings);
        final RestVdb vdb = new RestVdb();
        vdb.setName(vdbName);
        vdb.setDescription("blah VDB description");
        vdb.setOriginalFilePath("/Users/elvis/vdbs/blah.vdb");
        vdb.setPreview(false);
        vdb.setConnectionType("connType");
        vdb.setVersion(1);
        vdb.setId(vdbName);
        vdb.setkType(KomodoType.VDB);
        vdb.setDataPath("/tko:komodo/tko:workspace/user/blah");
        final String json = KomodoJsonMarshaller.marshall(vdb);
        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 modelName = "elvis";
    { // create model
        final RestVdbModel model = new RestVdbModel();
        model.setDataPath("/tko:komodo/tko:workspace/user/blah/elvis");
        model.setDdl("CREATE VIEW Tweet AS select * FROM twitterview.getTweets;");
        model.setDescription("model description goes here");
        model.setId(modelName);
        model.setkType(KomodoType.MODEL);
        model.setMetadataType("DDL");
        model.setModelType(Type.VIRTUAL);
        model.setVisible(true);
        final Properties settings = _uriBuilder.createSettings(SettingNames.VDB_NAME, vdbName);
        _uriBuilder.addSetting(settings, SettingNames.VDB_PARENT_PATH, _uriBuilder.workspaceVdbsUri());
        _uriBuilder.addSetting(settings, SettingNames.MODEL_NAME, modelName);
        final URI uri = _uriBuilder.vdbModelUri(LinkType.SELF, settings);
        final String json = KomodoJsonMarshaller.marshall(model);
        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 modelSourceName = "sledge";
    final String id = modelSourceName;
    final String dataPath = "/tko:komodo/tko:workspace/user/blah/elvis/vdb:sources/sledge";
    final KomodoType kType = KomodoType.VDB_MODEL_SOURCE;
    final String jndiName = "myJndiName";
    final String translator = "myTranslator";
    final Properties settings = _uriBuilder.createSettings(SettingNames.VDB_NAME, vdbName);
    _uriBuilder.addSetting(settings, SettingNames.VDB_PARENT_PATH, _uriBuilder.workspaceVdbsUri());
    _uriBuilder.addSetting(settings, SettingNames.MODEL_NAME, modelName);
    _uriBuilder.addSetting(settings, SettingNames.SOURCE_NAME, modelSourceName);
    final URI uri = _uriBuilder.vdbModelSourceUri(LinkType.SELF, settings);
    { // create model source
        final RestVdbModelSource inModelSource = new RestVdbModelSource();
        inModelSource.setDataPath(dataPath);
        inModelSource.setId(id);
        inModelSource.setkType(kType);
        inModelSource.setJndiName(jndiName);
        inModelSource.setTranslator(translator);
        final String json = KomodoJsonMarshaller.marshall(inModelSource);
        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 RestVdbModelSource outModelSource = KomodoJsonMarshaller.unmarshall(entity, RestVdbModelSource.class);
        assertNotNull(outModelSource);
        assertThat(outModelSource.getDataPath(), is(dataPath));
        assertThat(outModelSource.getId(), is(id));
        assertThat(outModelSource.getkType(), is(kType));
        assertThat(outModelSource.getJndiName(), is(jndiName));
        assertThat(outModelSource.getTranslator(), is(translator));
    }
    { // get new model source
        final ClientRequest request = request(uri, MediaType.APPLICATION_JSON_TYPE);
        final ClientResponse<String> response = request.get(String.class);
        assertThat(response.getStatus(), is(Status.OK.getStatusCode()));
        final String entity = response.getEntity();
        assertThat(entity, is(notNullValue()));
        final RestVdbModelSource newModelSource = KomodoJsonMarshaller.unmarshall(entity, RestVdbModelSource.class);
        assertNotNull(newModelSource);
        assertThat(newModelSource.getDataPath(), is(dataPath));
        assertThat(newModelSource.getId(), is(id));
        assertThat(newModelSource.getkType(), is(kType));
        assertThat(newModelSource.getJndiName(), is(jndiName));
        assertThat(newModelSource.getTranslator(), is(translator));
    }
}